fix(tui): keep streaming transcript entries in order around tool calls#72
Conversation
a225d63 to
933c414
Compare
933c414 to
7142c9c
Compare
|
Rebased onto the latest |
|
Reset currentAssistantEntryId in onModelToolCall/onToolStart so text that arrives after a tool call within the same streaming response is rendered in a new assistant entry positioned after the tool entry. When currentAssistantEntryId is null at commitAssistantMessage time, find the last transient assistant entry for the current turn and apply the final message content there, avoiding a duplicate assistant entry. Fixes stepfun-ai#71
7142c9c to
fa1a001
Compare
Problem
During an agent run (before it finishes), the TUI transcript could display assistant text and tool-call entries in the wrong order. Specifically, if a model streamed text, emitted a tool call, and then streamed more text within the same response, the text after the tool call was appended to the assistant entry that appeared before the tool entry instead of creating a new entry after it.
Closes #71
Root cause
LocalOpenTuiTranscriptBridge.onModelToolCall(andonToolStart) calleddiscardEmptyAssistantEntry()but did not resetcurrentAssistantEntryId.discardEmptyAssistantEntryonly removes the entry when it is blank, so once text had streamed in, the ID stayed alive and pointed at the pre-tool entry.Additionally, when
currentAssistantEntryIdwas null atcommitAssistantMessagetime, it would create a duplicate assistant entry rather than updating the streaming entry with the final message content.Solution
currentAssistantEntryIdtonullafter appending/updating a tool entry inonModelToolCallandonToolStart.findLastStreamingAssistantEntryId()to locate the last transient assistant entry for the current turn.commitAssistantMessage, whencurrentAssistantEntryIdis null, update that last streaming entry with the final content instead of creating a duplicate.Verification
src/runtime/local-opentui-bridge.test.tswith 5 unit tests covering:commitAssistantMessagecorrectly updates the streaming entry after tool-call resetpnpm testpasses (1479 passed)pnpm checkpasses tests, lint (only pre-existing warnings), dep-guard, dead-code, and formatting.Related