@@ -70,27 +70,33 @@ export function AssistantMessage({
70
70
isLoading,
71
71
handleRegenerate,
72
72
} : {
73
- message : Message ;
73
+ message : Message | undefined ;
74
74
isLoading : boolean ;
75
75
handleRegenerate : ( parentCheckpoint : Checkpoint | null | undefined ) => void ;
76
76
} ) {
77
- const contentString = getContentString ( message . content ) ;
77
+ const content = message ?. content ?? [ ] ;
78
+ const contentString = getContentString ( content ) ;
78
79
const [ hideToolCalls ] = useQueryState (
79
80
"hideToolCalls" ,
80
81
parseAsBoolean . withDefault ( false ) ,
81
82
) ;
82
83
83
84
const thread = useStreamContext ( ) ;
84
85
const isLastMessage =
85
- thread . messages [ thread . messages . length - 1 ] . id === message . id ;
86
- const meta = thread . getMessagesMetadata ( message ) ;
87
- const interrupt = thread . interrupt ;
86
+ thread . messages [ thread . messages . length - 1 ] . id === message ?. id ;
87
+ const hasNoAIOrToolMessages = ! thread . messages . find (
88
+ ( m ) => m . type === "ai" || m . type === "tool" ,
89
+ ) ;
90
+ const meta = message ? thread . getMessagesMetadata ( message ) : undefined ;
91
+ const threadInterrupt = thread . interrupt ;
92
+
88
93
const parentCheckpoint = meta ?. firstSeenState ?. parent_checkpoint ;
89
- const anthropicStreamedToolCalls = Array . isArray ( message . content )
90
- ? parseAnthropicStreamedToolCalls ( message . content )
94
+ const anthropicStreamedToolCalls = Array . isArray ( content )
95
+ ? parseAnthropicStreamedToolCalls ( content )
91
96
: undefined ;
92
97
93
98
const hasToolCalls =
99
+ message &&
94
100
"tool_calls" in message &&
95
101
message . tool_calls &&
96
102
message . tool_calls . length > 0 ;
@@ -100,7 +106,7 @@ export function AssistantMessage({
100
106
( tc ) => tc . args && Object . keys ( tc . args ) . length > 0 ,
101
107
) ;
102
108
const hasAnthropicToolCalls = ! ! anthropicStreamedToolCalls ?. length ;
103
- const isToolResult = message . type === "tool" ;
109
+ const isToolResult = message ? .type === "tool" ;
104
110
105
111
if ( isToolResult && hideToolCalls ) {
106
112
return null ;
@@ -130,14 +136,15 @@ export function AssistantMessage({
130
136
</ >
131
137
) }
132
138
133
- < CustomComponent message = { message } thread = { thread } />
134
- { isAgentInboxInterruptSchema ( interrupt ?. value ) && isLastMessage && (
135
- < ThreadView interrupt = { interrupt . value } />
136
- ) }
137
- { interrupt ?. value &&
138
- ! isAgentInboxInterruptSchema ( interrupt . value ) &&
139
+ { message && < CustomComponent message = { message } thread = { thread } /> }
140
+ { isAgentInboxInterruptSchema ( threadInterrupt ?. value ) &&
141
+ ( isLastMessage || hasNoAIOrToolMessages ) && (
142
+ < ThreadView interrupt = { threadInterrupt . value } />
143
+ ) }
144
+ { threadInterrupt ?. value &&
145
+ ! isAgentInboxInterruptSchema ( threadInterrupt . value ) &&
139
146
isLastMessage ? (
140
- < GenericInterruptView interrupt = { interrupt . value } />
147
+ < GenericInterruptView interrupt = { threadInterrupt . value } />
141
148
) : null }
142
149
< div
143
150
className = { cn (
0 commit comments