@@ -435,9 +435,9 @@ export const BedrockMessagesResponseTransform = (
435435 _gatewayRequestUrl : string ,
436436 gatewayRequest : Params
437437) : MessagesResponse | ErrorResponse => {
438- if ( responseStatus !== 200 && 'error' in response ) {
438+ if ( responseStatus !== 200 ) {
439439 return (
440- BedrockErrorResponseTransform ( response ) ||
440+ BedrockErrorResponseTransform ( response as BedrockErrorResponse ) ||
441441 generateInvalidProviderResponseError ( response , BEDROCK )
442442 ) ;
443443 }
@@ -513,6 +513,36 @@ const transformContentBlock = (
513513 return undefined ;
514514} ;
515515
516+ function createContentBlockStartEvent (
517+ parsedChunk : BedrockChatCompleteStreamChunk
518+ ) : RawContentBlockStartEvent {
519+ const contentBlockStartEvent : RawContentBlockStartEvent = JSON . parse (
520+ ANTHROPIC_CONTENT_BLOCK_START_EVENT
521+ ) ;
522+
523+ if ( parsedChunk . start ?. toolUse && parsedChunk . start . toolUse . toolUseId ) {
524+ contentBlockStartEvent . content_block = {
525+ type : 'tool_use' ,
526+ id : parsedChunk . start . toolUse . toolUseId ,
527+ name : parsedChunk . start . toolUse . name ,
528+ input : { } ,
529+ } ;
530+ } else if ( parsedChunk . delta ?. reasoningContent ?. text ) {
531+ contentBlockStartEvent . content_block = {
532+ type : 'thinking' ,
533+ thinking : '' ,
534+ signature : '' ,
535+ } ;
536+ } else if ( parsedChunk . delta ?. reasoningContent ?. redactedContent ) {
537+ contentBlockStartEvent . content_block = {
538+ type : 'redacted_thinking' ,
539+ data : parsedChunk . delta . reasoningContent . redactedContent ,
540+ } ;
541+ }
542+
543+ return contentBlockStartEvent ;
544+ }
545+
516546export const BedrockConverseMessagesStreamChunkTransform = (
517547 responseChunk : string ,
518548 fallbackId : string ,
@@ -545,9 +575,8 @@ export const BedrockConverseMessagesStreamChunkTransform = (
545575 returnChunk += `event: content_block_stop\ndata: ${ JSON . stringify ( previousBlockStopEvent ) } \n\n` ;
546576 }
547577 streamState . currentContentBlockIndex = parsedChunk . contentBlockIndex ;
548- const contentBlockStartEvent : RawContentBlockStartEvent = JSON . parse (
549- ANTHROPIC_CONTENT_BLOCK_START_EVENT
550- ) ;
578+ const contentBlockStartEvent : RawContentBlockStartEvent =
579+ createContentBlockStartEvent ( parsedChunk ) ;
551580 contentBlockStartEvent . index = parsedChunk . contentBlockIndex ;
552581 returnChunk += `event: content_block_start\ndata: ${ JSON . stringify ( contentBlockStartEvent ) } \n\n` ;
553582 const contentBlockDeltaEvent = transformContentBlock ( parsedChunk ) ;
0 commit comments