fix(stream): close thinking block before text or tool output

If upstream omits reasoning-end and starts emitting text-delta or
tool-call events, the thinking block remained open causing
thinking_start -> thinking_delta -> text_start -> ... -> thinking_end
ordering. Now endThinking() is called at the start of text-delta and
tool-call handlers so thinking_end always precedes text_start or
toolcall_start.

Adds 2 regression tests for the missing reasoning-end edge case.
This commit is contained in:
Patrick Wozniak
2026-05-28 22:05:01 +02:00
parent 52ed72aa37
commit 3fba807abf
2 changed files with 62 additions and 0 deletions
+2
View File
@@ -223,6 +223,7 @@ export function createStreamCommandCode(deps: CoreDependencies) {
switch (event.type) {
case "text-delta": {
endThinking()
if (!textBlock) {
textBlock = { type: "text", text: "" }
output.content.push(textBlock)
@@ -286,6 +287,7 @@ export function createStreamCommandCode(deps: CoreDependencies) {
case "tool-call": {
endTextBlock()
endThinking()
const toolCall: ToolCallContent = {
type: "toolCall",
id: stringValue(event.toolCallId) ?? "",