From 5a8787dbeab188895ce2855620742e2e3e679760 Mon Sep 17 00:00:00 2001 From: mawkone Date: Mon, 1 Jun 2026 14:46:45 -0700 Subject: [PATCH] fix: parse thoughtSignature correctly to support reasoning-to-text promotion --- vibn-frontend/lib/ai/gemini-chat.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vibn-frontend/lib/ai/gemini-chat.ts b/vibn-frontend/lib/ai/gemini-chat.ts index 71b578b6..b8f7f615 100644 --- a/vibn-frontend/lib/ai/gemini-chat.ts +++ b/vibn-frontend/lib/ai/gemini-chat.ts @@ -151,10 +151,13 @@ export async function callGeminiChat(opts: { const toolCalls: ToolCall[] = []; const parts = response.candidates?.[0]?.content?.parts ?? []; + const isPartThought = (p: Record) => + Boolean(p.thought || p.thoughtSignature); for (const part of parts) { if (part.text) { - if ((part as { thought?: unknown }).thought) thoughts += part.text; + if (isPartThought(part as Record)) + thoughts += part.text; else text += part.text; } if (part.functionCall) { @@ -219,12 +222,14 @@ export async function* streamGeminiChat(opts: { }); console.log("[GeminiChat] Stream request initiated"); + const isPartThought = (p: Record) => + Boolean(p.thought || p.thoughtSignature); for await (const chunk of streamResult) { const parts = chunk.candidates?.[0]?.content?.parts ?? []; for (const part of parts) { if (part.text) { - yield (part as { thought?: unknown }).thought + yield isPartThought(part as Record) ? { type: "thinking", text: part.text } : { type: "text", text: part.text }; }