From a0e23644813c1e255beb0f11d3185f08d3d11bb2 Mon Sep 17 00:00:00 2001 From: mawkone Date: Mon, 15 Jun 2026 11:50:35 -0700 Subject: [PATCH] Store thinking events in message timeline --- vibn-frontend/app/api/chat/route.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/vibn-frontend/app/api/chat/route.ts b/vibn-frontend/app/api/chat/route.ts index 271491b..ece1aab 100644 --- a/vibn-frontend/app/api/chat/route.ts +++ b/vibn-frontend/app/api/chat/route.ts @@ -1212,10 +1212,20 @@ export async function POST(request: Request) { return; } + // Stream the model's reasoning narration as a separate SSE + // event type. We pay for thinking tokens whether or not we + // ask for them, so making them visible is free transparency + // — and it cures the "tool tray with no narrative" feel. + if (resp.thoughts) { + assistantTimeline.push({ kind: "thought", text: resp.thoughts }); + emit({ type: "thinking", text: resp.thoughts }); + } + // Stream user-facing text to client. if (resp.text) { assistantText += (assistantText ? "\n\n" : "") + resp.text; assistantTextSegments.push(resp.text); + assistantTimeline.push({ kind: "text", text: resp.text }); emit({ type: "text", text: resp.text }); roundsSinceText = 0; toolCallsSinceText = 0; @@ -1224,14 +1234,6 @@ export async function POST(request: Request) { toolCallsSinceText += resp.toolCalls.length; } - // Stream the model's reasoning narration as a separate SSE - // event type. We pay for thinking tokens whether or not we - // ask for them, so making them visible is free transparency - // — and it cures the "tool tray with no narrative" feel. - if (resp.thoughts) { - emit({ type: "thinking", text: resp.thoughts }); - } - // Announce tool calls for (const tc of resp.toolCalls) { assistantToolCalls.push(tc); @@ -1568,6 +1570,10 @@ export async function POST(request: Request) { emit({ type: "text", text: fallback }); } if (summary.thoughts) { + assistantTimeline.push({ + kind: "thought", + text: summary.thoughts, + }); emit({ type: "thinking", text: summary.thoughts }); } } catch {