From 3dcdfc05f354be84a399c09f239ad1244c3878a4 Mon Sep 17 00:00:00 2001 From: Yash Dewasthale Date: Wed, 8 Jul 2026 17:04:00 +0530 Subject: [PATCH] fix error -gpt and claude issues on prod --- apps/supercode-cli/server/package.json | 2 +- apps/supercode-cli/server/src/index.ts | 43 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/apps/supercode-cli/server/package.json b/apps/supercode-cli/server/package.json index 349b112..ecc5b5e 100644 --- a/apps/supercode-cli/server/package.json +++ b/apps/supercode-cli/server/package.json @@ -1,6 +1,6 @@ { "name": "supercode-cli", - "version": "0.1.52", + "version": "0.1.53", "description": "AI-powered coding agent CLI", "main": "dist/main.js", "bin": { diff --git a/apps/supercode-cli/server/src/index.ts b/apps/supercode-cli/server/src/index.ts index 72c821b..17675fd 100644 --- a/apps/supercode-cli/server/src/index.ts +++ b/apps/supercode-cli/server/src/index.ts @@ -557,6 +557,8 @@ app.post("/api/ai/chat", async (req, res) => { let buffer = "" let inputTokens = 0 let outputTokens = 0 + let fullContent = "" + let sawToolCalls = false let pendingToolCalls: Record = {} while (true) { const { done, value } = await reader.read() @@ -573,9 +575,11 @@ app.post("/api/ai/chat", async (req, res) => { const data = JSON.parse(jsonStr) const delta = data.choices?.[0]?.delta if (delta?.content) { + fullContent += delta.content res.write(JSON.stringify({ type: "text", content: delta.content }) + "\n") } if (delta?.tool_calls) { + sawToolCalls = true for (const tc of delta.tool_calls) { const index = tc.index ?? 0 if (!pendingToolCalls[index]) { @@ -605,6 +609,45 @@ app.post("/api/ai/chat", async (req, res) => { } catch { /* skip malformed */ } } } + + // Fallback: if streaming returned no text and no tool calls, + // retry as non-streaming (ConcentrateAI's upstream intermittently + // drops content on streaming requests). + if (!fullContent.trim() && !sawToolCalls) { + const fbBody: any = { + model: modelName, + messages: nonSystemMessages.map((m: any) => { + const msg: any = { + role: m.role, + content: m.content !== null && m.content !== undefined ? String(m.content) : "", + } + if (m.tool_calls) msg.tool_calls = m.tool_calls + if (m.tool_call_id) msg.tool_call_id = m.tool_call_id + return msg + }), + max_tokens: getModelMaxTokens(modelName), + temperature: 0.7, + stream: false, + } + if (system && nonSystemMessages.length > 0) { + fbBody.messages = [{ role: "system", content: system }, ...fbBody.messages] + } + const fbRes = await fetch("https://api.concentrate.ai/v1/chat/completions", { + method: "POST", + headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" }, + body: JSON.stringify(fbBody), + }) + if (fbRes.ok) { + const fbData: any = await fbRes.json() + const fbContent = fbData?.choices?.[0]?.message?.content ?? "" + if (fbContent) { + res.write(JSON.stringify({ type: "text", content: fbContent }) + "\n") + } + inputTokens = fbData?.usage?.prompt_tokens ?? 0 + outputTokens = fbData?.usage?.completion_tokens ?? 0 + } + } + recordUsage({ provider: "concentrateai", model: modelName, inputTokens, outputTokens, cachedInputTokens: 0,