@@ -170,9 +170,9 @@ export const extractSpawnAgentResultContent = (
170170 return { content : String ( ( obj . value as any ) . errorMessage ) , hasError : true }
171171 }
172172
173- // Handle lastMessage output mode : { type: "lastMessage", value: [Message array] }
173+ // Handle lastMessage and allMessages output modes : { type: "lastMessage"|"allMessages ", value: [Message array] }
174174 // This is common for agents like researcher-web
175- if ( obj . type === 'lastMessage' && Array . isArray ( obj . value ) ) {
175+ if ( ( obj . type === 'lastMessage' || obj . type === 'allMessages' ) && Array . isArray ( obj . value ) ) {
176176 const messages = obj . value as Array < { role ?: string ; content ?: unknown } >
177177 const textContent = messages
178178 . filter ( ( msg ) => msg ?. role === 'assistant' )
@@ -182,6 +182,30 @@ export const extractSpawnAgentResultContent = (
182182 return { content : textContent , hasError : false }
183183 }
184184
185+ // Handle structuredOutput mode: { type: "structuredOutput", value: any }
186+ if ( obj . type === 'structuredOutput' ) {
187+ const value = obj . value
188+ // Check for message field in structured output
189+ if ( value && typeof value === 'object' ) {
190+ const valueObj = value as Record < string , unknown >
191+ if ( typeof valueObj . message === 'string' ) {
192+ return { content : valueObj . message , hasError : false }
193+ }
194+ // Check for data.message pattern
195+ if ( valueObj . data && typeof valueObj . data === 'object' ) {
196+ const dataObj = valueObj . data as Record < string , unknown >
197+ if ( typeof dataObj . message === 'string' ) {
198+ return { content : dataObj . message , hasError : false }
199+ }
200+ }
201+ }
202+ // Fall through to format as JSON
203+ return {
204+ content : formatToolOutput ( [ { type : 'json' , value : obj . value } ] ) ,
205+ hasError : false ,
206+ }
207+ }
208+
185209 // Handle nested string value: { value: "..." }
186210 if ( typeof obj . value === 'string' ) {
187211 return { content : obj . value , hasError : false }
0 commit comments