@@ -123,6 +123,74 @@ describe("Bedrock inbound image base64", () => {
123123} ) ;
124124
125125describe ( "Bedrock tool-result replay" , ( ) => {
126+ it ( "replays unsupported audio attachments as their canonical text placeholder" , ( ) => {
127+ const messages = testing . convertMessages (
128+ {
129+ messages : [
130+ {
131+ role : "toolResult" ,
132+ toolCallId : "call_audio" ,
133+ toolName : "listen" ,
134+ content : [ { type : "audio" , mimeType : "audio/wav" , data : "YXVkaW8=" } ] ,
135+ isError : false ,
136+ } ,
137+ ] ,
138+ } as never ,
139+ bedrockModel ( { input : [ "text" , "image" ] } ) ,
140+ "none" ,
141+ ) ;
142+
143+ expect ( messages ) . toHaveLength ( 1 ) ;
144+ expect ( messages [ 0 ] ) . toMatchObject ( {
145+ role : ConversationRole . USER ,
146+ content : [
147+ {
148+ toolResult : {
149+ toolUseId : "call_audio" ,
150+ content : [ { text : "(see attached audio)" } ] ,
151+ } ,
152+ } ,
153+ ] ,
154+ } ) ;
155+ } ) ;
156+
157+ it ( "preserves valid text and image attachments alongside unsupported audio" , ( ) => {
158+ const messages = testing . convertMessages (
159+ {
160+ messages : [
161+ {
162+ role : "toolResult" ,
163+ toolCallId : "call_media" ,
164+ toolName : "inspect" ,
165+ content : [
166+ { type : "audio" , mimeType : "audio/wav" , data : "YXVkaW8=" } ,
167+ { type : "text" , text : "actual tool output" } ,
168+ { type : "image" , mimeType : "image/png" , data : "aW1hZ2U=" } ,
169+ ] ,
170+ isError : false ,
171+ } ,
172+ ] ,
173+ } as never ,
174+ bedrockModel ( { input : [ "text" , "image" ] } ) ,
175+ "none" ,
176+ ) ;
177+
178+ expect ( messages [ 0 ] ) . toMatchObject ( {
179+ role : ConversationRole . USER ,
180+ content : [
181+ {
182+ toolResult : {
183+ toolUseId : "call_media" ,
184+ content : [
185+ { text : "actual tool output" } ,
186+ { image : { format : "png" , source : { bytes : expect . any ( Uint8Array ) } } } ,
187+ ] ,
188+ } ,
189+ } ,
190+ ] ,
191+ } ) ;
192+ } ) ;
193+
126194 it ( "drops payload-less image husks from consecutive tool results" , ( ) => {
127195 const messages = testing . convertMessages (
128196 {
@@ -335,6 +403,61 @@ describe("Bedrock profile endpoint resolution", () => {
335403} ) ;
336404
337405describe ( "Bedrock stop reasons" , ( ) => {
406+ it . each ( [
407+ {
408+ name : "text" ,
409+ events : [
410+ { contentBlockDelta : { contentBlockIndex : 0 , delta : { text : "truncated response" } } } ,
411+ { contentBlockStop : { contentBlockIndex : 0 } } ,
412+ ] ,
413+ contentType : "text" ,
414+ } ,
415+ {
416+ name : "tool call" ,
417+ events : [
418+ {
419+ contentBlockStart : {
420+ contentBlockIndex : 0 ,
421+ start : { toolUse : { toolUseId : "call_lookup" , name : "lookup" } } ,
422+ } ,
423+ } ,
424+ {
425+ contentBlockDelta : {
426+ contentBlockIndex : 0 ,
427+ delta : { toolUse : { input : '{"query":"partial"}' } } ,
428+ } ,
429+ } ,
430+ { contentBlockStop : { contentBlockIndex : 0 } } ,
431+ ] ,
432+ contentType : "toolCall" ,
433+ } ,
434+ ] ) (
435+ "reports truncated $name streams without a terminal messageStop" ,
436+ async ( { events, contentType } ) => {
437+ vi . spyOn ( BedrockRuntimeClient . prototype , "send" ) . mockResolvedValue ( {
438+ $metadata : { httpStatusCode : 200 } ,
439+ stream : streamEvents ( [ { messageStart : { role : ConversationRole . ASSISTANT } } , ...events ] ) ,
440+ } as never ) ;
441+
442+ const stream = streamBedrockForTest ( bedrockModel ( { } ) , {
443+ messages : [ { role : "user" , content : "Hello" , timestamp : 0 } ] ,
444+ } as never ) ;
445+ const eventTypes : string [ ] = [ ] ;
446+ for await ( const event of stream ) {
447+ eventTypes . push ( event . type ) ;
448+ }
449+ const result = await stream . result ( ) ;
450+
451+ expect ( eventTypes . at ( - 1 ) ) . toBe ( "error" ) ;
452+ expect ( eventTypes ) . not . toContain ( "done" ) ;
453+ expect ( result . stopReason ) . toBe ( "error" ) ;
454+ expect ( result . errorMessage ) . toBe ( "Bedrock stream ended before messageStop" ) ;
455+ expect ( result . content ) . toEqual ( [ expect . objectContaining ( { type : contentType } ) ] ) ;
456+ expect ( result . content [ 0 ] ) . not . toHaveProperty ( "index" ) ;
457+ expect ( result . content [ 0 ] ) . not . toHaveProperty ( "partialJson" ) ;
458+ } ,
459+ ) ;
460+
338461 it . each ( [
339462 BedrockStopReason . CONTENT_FILTERED ,
340463 BedrockStopReason . GUARDRAIL_INTERVENED ,
0 commit comments