@@ -3,7 +3,6 @@ import type {
33 MuxMetadata ,
44 MuxImagePart ,
55 DisplayedMessage ,
6- MuxFrontendMetadata ,
76} from "@/common/types/message" ;
87import { createMuxMessage } from "@/common/types/message" ;
98import type {
@@ -17,7 +16,7 @@ import type {
1716 ReasoningDeltaEvent ,
1817 ReasoningEndEvent ,
1918} from "@/common/types/stream" ;
20- import type { TodoItem , StatusSetToolResult , BashToolResult } from "@/common/types/tools" ;
19+ import type { TodoItem , StatusSetToolResult } from "@/common/types/tools" ;
2120
2221import type { WorkspaceChatMessage , StreamErrorMessage , DeleteMessage } from "@/common/types/ipc" ;
2322import { isInitStart , isInitOutput , isInitEnd , isMuxMessage } from "@/common/types/ipc" ;
@@ -208,7 +207,7 @@ export class StreamingMessageAggregator {
208207 return ;
209208 }
210209 }
211-
210+
212211 // Special handling for script execution messages to ensure correct type identification
213212 // If we receive a user message that has script metadata, we treat it as a script execution
214213 // This is redundant with getDisplayedMessages logic but good for consistency
@@ -735,14 +734,31 @@ export class StreamingMessageAggregator {
735734 */
736735 getDisplayedMessages ( ) : DisplayedMessage [ ] {
737736 if ( ! this . cachedDisplayedMessages ) {
738- let displayedMessages : DisplayedMessage [ ] = [ ] ;
737+ const displayedMessages : DisplayedMessage [ ] = [ ] ;
739738
740739 for ( const message of this . getAllMessages ( ) ) {
741740 const baseTimestamp = message . metadata ?. timestamp ;
742741 // Get historySequence from backend (required field)
743742 const historySequence = message . metadata ?. historySequence ?? 0 ;
744743
745- if ( message . role === "user" ) {
744+ if (
745+ message . metadata ?. muxMetadata ?. type === "script-execution" &&
746+ ( message . role as string ) === "user"
747+ ) {
748+ // Script Execution Message
749+ // Type assertion: we know the metadata shape from the check above
750+ const scriptMeta = message . metadata . muxMetadata ;
751+ displayedMessages . push ( {
752+ type : "script-execution" ,
753+ id : message . id ,
754+ historySequence,
755+ timestamp : baseTimestamp ?? message . metadata . timestamp ?? Date . now ( ) ,
756+ command : scriptMeta . command ,
757+ scriptName : scriptMeta . scriptName ,
758+ args : scriptMeta . args ,
759+ result : scriptMeta . result ,
760+ } ) ;
761+ } else if ( message . role === "user" ) {
746762 // User messages: combine all text parts into single block, extract images
747763 const content = message . parts
748764 . filter ( ( p ) => p . type === "text" )
@@ -780,23 +796,6 @@ export class StreamingMessageAggregator {
780796 timestamp : baseTimestamp ,
781797 compactionRequest,
782798 } ) ;
783- } else if (
784- message . metadata ?. muxMetadata ?. type === "script-execution" &&
785- ( message . role as string ) === "user"
786- ) {
787- // Script Execution Message
788- // Type assertion: we know the metadata shape from the check above
789- const scriptMeta = message . metadata . muxMetadata as Extract < MuxFrontendMetadata , { type : "script-execution" } > ;
790- displayedMessages . push ( {
791- type : "script-execution" ,
792- id : message . id ,
793- historySequence,
794- timestamp : baseTimestamp ?? message . metadata . timestamp ?? Date . now ( ) ,
795- command : scriptMeta . command ,
796- scriptName : scriptMeta . scriptName ,
797- args : scriptMeta . args ,
798- result : scriptMeta . result ,
799- } ) ;
800799 } else if ( message . role === "assistant" ) {
801800 // Assistant messages: each part becomes a separate DisplayedMessage
802801 // Use streamSequence to order parts within this message
@@ -947,7 +946,6 @@ export class StreamingMessageAggregator {
947946 displayedMessages . unshift ( initMessage ) ;
948947 }
949948
950-
951949 // Limit to last N messages for DOM performance
952950 // Full history is still maintained internally for token counting
953951 if ( displayedMessages . length > MAX_DISPLAYED_MESSAGES ) {
0 commit comments