From 44d8de288dd02daa0f7fc3271840770469002192 Mon Sep 17 00:00:00 2001 From: Delcado19 <85063283+Delcado19@users.noreply.github.com> Date: Sat, 6 Jun 2026 10:06:09 +0700 Subject: [PATCH] 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 --- src/app/api/providers/route.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/app/api/providers/route.js b/src/app/api/providers/route.js index e4c7dc8f..f289cd25 100644 --- a/src/app/api/providers/route.js +++ b/src/app/api/providers/route.js @@ -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,