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,