@@ -506,11 +506,12 @@ const sessionIdOf = (providerThread: OrchestrationV2ProviderThread) => {
506506const textOf = ( content : ReadonlyArray < { readonly type : string ; readonly text ?: string } > ) =>
507507 content . flatMap ( ( part ) => ( part . type === "text" && part . text ? [ part . text ] : [ ] ) ) . join ( "\n" ) ;
508508
509- const BASE64_DATA_URI = / ^ d a t a : [ ^ , ] * ; b a s e 6 4 , ( .+ ) $ / s;
509+ const BASE64_DATA_URI = / ^ d a t a : ( [ ^ ; , ] * ) [ ^ , ] * ; b a s e 6 4 , ( .+ ) $ / s;
510510
511511/**
512512 * An image tool such as `image_generation` answers with a file block, not text.
513513 * Only raster images inlined as base64 are kept; anything else can't be served.
514+ * The data URI's media type must match the block's mime, so a conflicting file isn't relabeled.
514515 * Blocks keep the provider's order so text and images stay interleaved.
515516 */
516517const toolContentOf = (
@@ -523,9 +524,11 @@ const toolContentOf = (
523524) =>
524525 content . flatMap ( ( part ) : ReadonlyArray < OpenCodeToolContentBlock > => {
525526 if ( part . type === "text" ) return part . text ? [ { type : "text" , text : part . text } ] : [ ] ;
526- const data = part . type === "file" ? BASE64_DATA_URI . exec ( part . uri ?? "" ) ?. [ 1 ] : undefined ;
527+ const match = part . type === "file" ? BASE64_DATA_URI . exec ( part . uri ?? "" ) : null ;
527528 const image =
528- data === undefined ? null : readToolOutputImage ( { type : "image" , mimeType : part . mime , data } ) ;
529+ match == null || match [ 1 ] ! . toLowerCase ( ) !== part . mime ?. toLowerCase ( )
530+ ? null
531+ : readToolOutputImage ( { type : "image" , mimeType : part . mime , data : match [ 2 ] } ) ;
529532 return image ?. data === undefined
530533 ? [ ]
531534 : [ { type : "image" , mimeType : image . mimeType , data : image . data } ] ;
0 commit comments