@@ -16,7 +16,6 @@ import {
1616 createEmptyTransportUsage ,
1717 createWritableTransportEventStream ,
1818 describeToolResultMediaPlaceholder ,
19- extractToolResultImageBlocks ,
2019 extractToolResultText ,
2120 failTransportStream ,
2221 finalizeTransportStream ,
@@ -84,6 +83,37 @@ type GoogleGenerateContentRequest = {
8483 toolConfig ?: Record < string , unknown > ;
8584} ;
8685
86+ type GoogleToolResultImageBlock = {
87+ type : "image" ;
88+ mimeType : string ;
89+ data : string ;
90+ } ;
91+
92+ function normalizeGoogleToolResultBlocks ( blocks : unknown ) : readonly unknown [ ] {
93+ if ( Array . isArray ( blocks ) ) {
94+ return blocks ;
95+ }
96+ if ( blocks === null || blocks === undefined ) {
97+ return [ ] ;
98+ }
99+ return [ blocks ] ;
100+ }
101+
102+ function isGoogleToolResultImageBlock ( block : unknown ) : block is GoogleToolResultImageBlock {
103+ return (
104+ block !== null &&
105+ typeof block === "object" &&
106+ ! Array . isArray ( block ) &&
107+ ( block as Record < string , unknown > ) . type === "image" &&
108+ typeof ( block as Record < string , unknown > ) . mimeType === "string" &&
109+ typeof ( block as Record < string , unknown > ) . data === "string"
110+ ) ;
111+ }
112+
113+ function extractGoogleToolResultImageBlocks ( blocks : unknown ) : GoogleToolResultImageBlock [ ] {
114+ return normalizeGoogleToolResultBlocks ( blocks ) . filter ( isGoogleToolResultImageBlock ) ;
115+ }
116+
87117const GOOGLE_GEMINI3_FIRST_RESPONSE_RETRY_DEFAULT_MS = 45_000 ;
88118const GOOGLE_GEMINI3_FIRST_RESPONSE_RETRY_ENV = "OPENCLAW_GOOGLE_GEMINI_FIRST_RESPONSE_RETRY_MS" ;
89119
@@ -652,7 +682,7 @@ function convertGoogleMessages(model: GoogleTransportModel, context: Context) {
652682 if ( msg . role === "toolResult" ) {
653683 const textResult = extractToolResultText ( msg . content ) ;
654684 const imageContent = model . input . includes ( "image" )
655- ? extractToolResultImageBlocks ( msg . content )
685+ ? extractGoogleToolResultImageBlocks ( msg . content )
656686 : [ ] ;
657687 const mediaPlaceholder = describeToolResultMediaPlaceholder ( msg . content ) ;
658688 const responseValue = textResult
0 commit comments