fix(providers): restore one-connection guard for compatible/embedding nodes

OpenAI/Anthropic Compatible and Custom Embedding nodes allow exactly one
connection each. The guards were dropped during the bun:sqlite refactor
(v0.4.28), so duplicate POSTs were accepted (201) instead of rejected (400).

Restore the per-node existing-connection check in the POST handler.
Test: tests/unit/compatible-provider-connections.test.js now passes.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Delcado19
2026-06-06 10:06:09 +07:00
committed by decolua
parent 8671468360
commit 44d8de288d

View File

@@ -122,11 +122,18 @@ export async function POST(request) {
let providerSpecificData = normalizeProviderSpecificData(provider, body, body.providerSpecificData);
// Compatible/embedding nodes allow exactly one connection each. These guards were
// dropped accidentally during the bun:sqlite refactor (v0.4.28); restored to honor
// the contract locked in by tests/unit/compatible-provider-connections.test.js (#925).
if (isOpenAICompatibleProvider(provider)) {
const node = await getProviderNodeById(provider);
if (!node) {
return NextResponse.json({ error: "OpenAI Compatible node not found" }, { status: 404 });
}
const existingConnections = await getProviderConnections({ provider });
if (existingConnections.length > 0) {
return NextResponse.json({ error: "Only one connection is allowed for this OpenAI Compatible node" }, { status: 400 });
}
providerSpecificData = {
prefix: node.prefix,
apiType: node.apiType,
@@ -138,6 +145,10 @@ export async function POST(request) {
if (!node) {
return NextResponse.json({ error: "Anthropic Compatible node not found" }, { status: 404 });
}
const existingConnections = await getProviderConnections({ provider });
if (existingConnections.length > 0) {
return NextResponse.json({ error: "Only one connection is allowed for this Anthropic Compatible node" }, { status: 400 });
}
providerSpecificData = {
prefix: node.prefix,
baseUrl: node.baseUrl,
@@ -148,6 +159,10 @@ export async function POST(request) {
if (!node) {
return NextResponse.json({ error: "Custom Embedding node not found" }, { status: 404 });
}
const existingConnections = await getProviderConnections({ provider });
if (existingConnections.length > 0) {
return NextResponse.json({ error: "Only one connection is allowed for this Custom Embedding node" }, { status: 400 });
}
providerSpecificData = {
prefix: node.prefix,
baseUrl: node.baseUrl,