@@ -246,7 +246,7 @@ const createFunctionCallOutput = (
246246) : ResponseFunctionCallOutputItem => ( {
247247 type : "function_call_output" ,
248248 call_id : block . tool_use_id ,
249- output : block . content ,
249+ output : convertToolResultContent ( block . content ) ,
250250 status : block . is_error ? "incomplete" : "completed" ,
251251} )
252252
@@ -268,7 +268,7 @@ When using the BashOutput tool, follow these rules:
268268- Only Bash Tool run_in_background set to true, Use BashOutput to read the output later
269269### TodoWrite tool
270270When using the TodoWrite tool, follow these rules:
271- - Skip using the TodoWrite tool for straightforward tasks (roughly the easiest 25%).
271+ - Skip using the TodoWrite tool for simple or straightforward tasks (roughly the easiest 25%).
272272- Do not make single-step todo lists.
273273- When you made a todo, update it after having performed one of the sub-tasks that you shared on the todo list.`
274274
@@ -636,3 +636,27 @@ const parseUserId = (
636636
637637 return { safetyIdentifier, promptCacheKey }
638638}
639+
640+ const convertToolResultContent = (
641+ content : string | Array < AnthropicTextBlock > | Array < AnthropicImageBlock > ,
642+ ) : string | Array < ResponseInputContent > => {
643+ if ( typeof content === "string" ) {
644+ return content
645+ }
646+
647+ if ( Array . isArray ( content ) ) {
648+ if ( content . length > 0 && content [ 0 ] . type === "text" ) {
649+ return ( content as Array < AnthropicTextBlock > ) . map ( ( block ) =>
650+ createTextContent ( block . text ) ,
651+ )
652+ }
653+
654+ if ( content . length > 0 && content [ 0 ] . type === "image" ) {
655+ return ( content as Array < AnthropicImageBlock > ) . map ( ( block ) =>
656+ createImageContent ( block ) ,
657+ )
658+ }
659+ }
660+
661+ return ""
662+ }
0 commit comments