Skip to content

Commit b5a85ee

Browse files
steipetefluffyxenia
andcommitted
fix(tui): discard retracted streamed assistant rows
Co-authored-by: Foxy6670 <[email protected]>
1 parent e01410b commit b5a85ee

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎src/tui/components/chat-log.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,21 @@ describe("ChatLog", () => {
174174
]);
175175
});
176176

177+
it("removes an empty post-tool component when its final snapshot is retracted", () => {
178+
const chatLog = new ChatLog(40);
179+
180+
chatLog.updateAssistant("Before the tool.", "run-1");
181+
chatLog.startTool("tool-1", "read_file", { path: "a.txt" });
182+
chatLog.updateAssistant("Before the tool.\n\nRetracted answer.", "run-1");
183+
chatLog.finalizeAssistant("Before the tool.", "run-1");
184+
185+
expect(chatLog.children.map((component) => component.constructor.name)).toEqual([
186+
"AssistantMessageComponent",
187+
"ToolExecutionComponent",
188+
]);
189+
expect(normalizeTestText(chatLog.render(120).join("\n"))).not.toContain("Retracted answer.");
190+
});
191+
177192
it("preserves indentation in assistant text that follows a tool call", () => {
178193
const chatLog = new ChatLog(40);
179194

‎src/tui/components/chat-log.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,11 @@ export class ChatLog extends Container {
373373
this.committedAssistantText.delete(effectiveRunId);
374374
this.latestAssistantText.delete(effectiveRunId);
375375
if (existing) {
376-
existing.setText(segmentText);
376+
if (segmentText) {
377+
existing.setText(segmentText);
378+
} else {
379+
this.removeChild(existing);
380+
}
377381
this.streamingRuns.delete(effectiveRunId);
378382
return;
379383
}

0 commit comments

Comments
 (0)