File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments