Store thinking events in message timeline
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user