@@ -35,7 +35,6 @@ import type {
3535 AssistantMessage ,
3636 CacheRetention ,
3737 Context ,
38- ImageContent ,
3938 Message ,
4039 Model ,
4140 OpenAICompletionsCompat ,
@@ -58,7 +57,11 @@ import { buildCopilotDynamicHeaders, hasCopilotVisionInput } from "./github-copi
5857import { clampOpenAIPromptCacheKey } from "./openai-prompt-cache.js" ;
5958import { mapOpenAIStopReason } from "./openai-stop-reason.js" ;
6059import { buildBaseOptions } from "./simple-options.js" ;
61- import { describeToolResultMediaPlaceholder , extractToolResultText } from "./tool-result-text.js" ;
60+ import {
61+ describeToolResultMediaPlaceholder ,
62+ extractToolResultImageBlocks ,
63+ extractToolResultText ,
64+ } from "./tool-result-text.js" ;
6265import { transformMessages } from "./transform-messages.js" ;
6366
6467/**
@@ -94,10 +97,6 @@ function isToolCallBlock(block: { type: string }): block is ToolCall {
9497 return block . type === "toolCall" ;
9598}
9699
97- function isImageContentBlock ( block : { type : string } ) : block is ImageContent {
98- return block . type === "image" ;
99- }
100-
101100const EMPTY_TOOL_RESULT_TEXT = "(no output)" ;
102101
103102function sanitizeToolResultText ( text : string , fallback : string ) : string {
@@ -1161,7 +1160,8 @@ export function convertMessages(
11611160 // Extract text and image content
11621161 const textResult = extractToolResultText ( toolMsg . content ) ;
11631162 const mediaPlaceholder = describeToolResultMediaPlaceholder ( toolMsg . content ) ;
1164- const hasImages = toolMsg . content . some ( ( c ) => c . type === "image" ) ;
1163+ const toolImageBlocks = extractToolResultImageBlocks ( toolMsg . content ) ;
1164+ const hasImages = toolImageBlocks . length > 0 ;
11651165
11661166 // Always send tool result with text (or placeholder if only images)
11671167 const content = sanitizeToolResultText (
@@ -1180,15 +1180,13 @@ export function convertMessages(
11801180 params . push ( toolResultMsg ) ;
11811181
11821182 if ( hasImages && model . input . includes ( "image" ) ) {
1183- for ( const block of toolMsg . content ) {
1184- if ( isImageContentBlock ( block ) ) {
1185- imageBlocks . push ( {
1186- type : "image_url" ,
1187- image_url : {
1188- url : `data:${ block . mimeType } ;base64,${ block . data } ` ,
1189- } ,
1190- } ) ;
1191- }
1183+ for ( const block of toolImageBlocks ) {
1184+ imageBlocks . push ( {
1185+ type : "image_url" ,
1186+ image_url : {
1187+ url : `data:${ block . mimeType } ;base64,${ block . data } ` ,
1188+ } ,
1189+ } ) ;
11921190 }
11931191 }
11941192 }
0 commit comments