@@ -510,11 +510,12 @@ const sessionIdOf = (providerThread: OrchestrationV2ProviderThread) => {
510510const textOf = ( content : ReadonlyArray < { readonly type : string ; readonly text ?: string } > ) =>
511511 content . flatMap ( ( part ) => ( part . type === "text" && part . text ? [ part . text ] : [ ] ) ) . join ( "\n" ) ;
512512
513- const BASE64_DATA_URI = / ^ d a t a : [ ^ , ] * ; b a s e 6 4 , ( .+ ) $ / s;
513+ const BASE64_DATA_URI = / ^ d a t a : ( [ ^ ; , ] * ) [ ^ , ] * ; b a s e 6 4 , ( .+ ) $ / s;
514514
515515/**
516516 * An image tool such as `image_generation` answers with a file block, not text.
517517 * Only raster images inlined as base64 are kept; anything else can't be served.
518+ * The data URI's media type must match the block's mime, so a conflicting file isn't relabeled.
518519 * Blocks keep the provider's order so text and images stay interleaved.
519520 */
520521const toolContentOf = (
@@ -527,9 +528,11 @@ const toolContentOf = (
527528) =>
528529 content . flatMap ( ( part ) : ReadonlyArray < OpenCodeToolContentBlock > => {
529530 if ( part . type === "text" ) return part . text ? [ { type : "text" , text : part . text } ] : [ ] ;
530- const data = part . type === "file" ? BASE64_DATA_URI . exec ( part . uri ?? "" ) ?. [ 1 ] : undefined ;
531+ const match = part . type === "file" ? BASE64_DATA_URI . exec ( part . uri ?? "" ) : null ;
531532 const image =
532- data === undefined ? null : readToolOutputImage ( { type : "image" , mimeType : part . mime , data } ) ;
533+ match == null || match [ 1 ] ! . toLowerCase ( ) !== part . mime ?. toLowerCase ( )
534+ ? null
535+ : readToolOutputImage ( { type : "image" , mimeType : part . mime , data : match [ 2 ] } ) ;
533536 return image ?. data === undefined
534537 ? [ ]
535538 : [ { type : "image" , mimeType : image . mimeType , data : image . data } ] ;
0 commit comments