fix: flush remaining thinking blocks after stream ends
This commit is contained in:
@@ -373,10 +373,21 @@ function streamCommandCode(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// End any lingering text block
|
||||||
if (textBlock) {
|
if (textBlock) {
|
||||||
stream.push({ type: "text_end", contentIndex: currentTextIdx, content: textBlock.text, partial: output });
|
stream.push({ type: "text_end", contentIndex: currentTextIdx, content: textBlock.text, partial: output });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Emit remaining thinking (may arrive after finish without reasoning-end)
|
||||||
|
if (thinkingBlock.length > 0) {
|
||||||
|
const thinkingText = thinkingBlock.join("");
|
||||||
|
output.content.push({ type: "thinking", thinking: thinkingText });
|
||||||
|
const idx = output.content.length - 1;
|
||||||
|
stream.push({ type: "thinking_start", contentIndex: idx, partial: output });
|
||||||
|
stream.push({ type: "thinking_delta", contentIndex: idx, delta: thinkingText, partial: output });
|
||||||
|
stream.push({ type: "thinking_end", contentIndex: idx, content: thinkingText, partial: output });
|
||||||
|
}
|
||||||
|
|
||||||
stream.push({ type: "done", reason: output.stopReason as "stop" | "length" | "toolUse", message: output });
|
stream.push({ type: "done", reason: output.stopReason as "stop" | "length" | "toolUse", message: output });
|
||||||
stream.end();
|
stream.end();
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|||||||
Reference in New Issue
Block a user