@@ -608,6 +608,93 @@ describe("session.message-v2.toModelMessage", () => {
608608 ] )
609609 } )
610610
611+ describe ( "bedrock tool-result images" , ( ) => {
612+ const png = Buffer . from ( "png" ) . toString ( "base64" )
613+ const bedrock = ( apiID : string ) : Provider . Model => ( {
614+ ...model ,
615+ id : ModelID . make ( `amazon-bedrock/${ apiID } ` ) ,
616+ providerID : ProviderID . make ( "amazon-bedrock" ) ,
617+ api : { id : apiID , url : "https://bedrock-runtime.us-east-1.amazonaws.com" , npm : "@ai-sdk/amazon-bedrock" } ,
618+ capabilities : {
619+ ...model . capabilities ,
620+ attachment : true ,
621+ input : { ...model . capabilities . input , image : true } ,
622+ } ,
623+ } )
624+ const history = ( ) : SessionV1 . WithParts [ ] => [
625+ {
626+ info : userInfo ( "m-user-bedrock-png" ) ,
627+ parts : [ { ...basePart ( "m-user-bedrock-png" , "u1" ) , type : "text" , text : "read it" } ] as SessionV1 . Part [ ] ,
628+ } ,
629+ {
630+ info : assistantInfo ( "m-assistant-bedrock-png" , "m-user-bedrock-png" ) ,
631+ parts : [
632+ {
633+ ...basePart ( "m-assistant-bedrock-png" , "a1" ) ,
634+ type : "tool" ,
635+ callID : "call-bedrock-png-1" ,
636+ tool : "read" ,
637+ state : {
638+ status : "completed" ,
639+ input : { filePath : "/tmp/a.png" } ,
640+ output : "Image read successfully" ,
641+ title : "Read" ,
642+ metadata : { } ,
643+ time : { start : 0 , end : 1 } ,
644+ attachments : [
645+ {
646+ ...basePart ( "m-assistant-bedrock-png" , "f1" ) ,
647+ type : "file" ,
648+ mime : "image/png" ,
649+ filename : "a.png" ,
650+ url : `data:image/png;base64,${ png } ` ,
651+ } ,
652+ ] ,
653+ } ,
654+ } ,
655+ ] as SessionV1 . Part [ ] ,
656+ } ,
657+ ]
658+
659+ test . each ( [ "us.anthropic.claude-sonnet-4-6" , "amazon.nova-pro-v1:0" , "us.meta.llama4-maverick-17b-instruct-v1:0" ] ) (
660+ "keeps images in the tool result for %s" ,
661+ async ( apiID ) => {
662+ const result = await MessageV2 . toModelMessages ( history ( ) as unknown as MessageV2 . WithParts [ ] , bedrock ( apiID ) )
663+ expect ( result ) . toHaveLength ( 3 )
664+ expect ( result [ 2 ] ?. content ) . toMatchObject ( [
665+ {
666+ type : "tool-result" ,
667+ output : {
668+ type : "content" ,
669+ value : [
670+ { type : "text" , text : "Image read successfully" } ,
671+ { type : "media" , mediaType : "image/png" , data : png } ,
672+ ] ,
673+ } ,
674+ } ,
675+ ] )
676+ } ,
677+ )
678+
679+ test . each ( [ "openai.gpt-oss-120b-1:0" , "mistral.pixtral-large-2502-v1:0" ] ) (
680+ "hoists images into a user message for %s" ,
681+ async ( apiID ) => {
682+ const result = await MessageV2 . toModelMessages ( history ( ) as unknown as MessageV2 . WithParts [ ] , bedrock ( apiID ) )
683+ expect ( result ) . toHaveLength ( 4 )
684+ expect ( result [ 2 ] ?. content ) . toMatchObject ( [
685+ { type : "tool-result" , output : { type : "text" , value : "Image read successfully" } } ,
686+ ] )
687+ expect ( result [ 3 ] ) . toMatchObject ( {
688+ role : "user" ,
689+ content : [
690+ { type : "text" , text : MessageV2 . SYNTHETIC_ATTACHMENT_PROMPT } ,
691+ { type : "file" , mediaType : "image/png" } ,
692+ ] ,
693+ } )
694+ } ,
695+ )
696+ } )
697+
611698 test ( "omits provider metadata when assistant model differs" , async ( ) => {
612699 const userID = "m-user"
613700 const assistantID = "m-assistant"
0 commit comments