@@ -264,49 +264,51 @@ export function mapOpenAIContentBlock(block: any): object {
264264// tool_result → ToolCallResponsePart
265265// <unknown> → GenericPart
266266
267+ /** Bedrock SDK content block type strings. */
268+ const BedrockBlockType = {
269+ TEXT : "text" ,
270+ TOOL_USE : "tool_use" ,
271+ TOOL_RESULT : "tool_result" ,
272+ } as const ;
273+
274+ /** OTel gen_ai part type strings used by the Bedrock mapper. */
275+ const BedrockOtelPartType = {
276+ TEXT : "text" ,
277+ TOOL_CALL : "tool_call" ,
278+ TOOL_CALL_RESPONSE : "tool_call_response" ,
279+ } as const ;
280+
267281/**
268282 * Maps a single Bedrock content block to its OTel-compliant part object.
269283 * Used by formatInputMessages and formatOutputMessage for all Bedrock providers.
270284 */
271285export const mapBedrockContentBlock = ( block : any ) : object => {
272286 if ( typeof block === "string" ) {
273- return { type : "text" , content : block } ;
287+ return { type : BedrockOtelPartType . TEXT , content : block } ;
274288 }
275289
276290 switch ( block . type ) {
277- // -------------------------------------------------------------------------
278- // Text
279- // -------------------------------------------------------------------------
280- case "text" :
281- return { type : "text" , content : block . text } ;
291+ case BedrockBlockType . TEXT :
292+ return { type : BedrockOtelPartType . TEXT , content : block . text } ;
282293
283- // -------------------------------------------------------------------------
284- // Tool use (model requests a function call)
285- // -------------------------------------------------------------------------
286- case "tool_use" :
294+ case BedrockBlockType . TOOL_USE :
287295 return {
288- type : "tool_call" ,
296+ type : BedrockOtelPartType . TOOL_CALL ,
289297 id : block . id ,
290298 name : block . name ,
291299 arguments : block . input ,
292300 } ;
293301
294- // -------------------------------------------------------------------------
295- // Tool result (client returns function result to model)
296- // -------------------------------------------------------------------------
297- case "tool_result" :
302+ case BedrockBlockType . TOOL_RESULT :
298303 return {
299- type : "tool_call_response" ,
304+ type : BedrockOtelPartType . TOOL_CALL_RESPONSE ,
300305 id : block . tool_use_id ,
301306 response : block . content ,
302307 } ;
303308
304- // -------------------------------------------------------------------------
305- // Amazon Nova format: { text: "..." } without explicit type
306- // -------------------------------------------------------------------------
307309 default :
308310 if ( ! block . type && block . text !== undefined ) {
309- return { type : "text" , content : block . text } ;
311+ return { type : BedrockOtelPartType . TEXT , content : block . text } ;
310312 }
311313 return { type : block . type , ...block } ;
312314 }
0 commit comments