@@ -107,7 +107,7 @@ describe("convertToOpenAiMessages", () => {
107107 } )
108108 } )
109109
110- it ( "should handle assistant messages with tool use (no normalization without modelId )" , ( ) => {
110+ it ( "should handle assistant messages with tool use (no normalization without normalizeToolCallId )" , ( ) => {
111111 const anthropicMessages : Anthropic . Messages . MessageParam [ ] = [
112112 {
113113 role : "assistant" ,
@@ -134,7 +134,7 @@ describe("convertToOpenAiMessages", () => {
134134 expect ( assistantMessage . content ) . toBe ( "Let me check the weather." )
135135 expect ( assistantMessage . tool_calls ) . toHaveLength ( 1 )
136136 expect ( assistantMessage . tool_calls ! [ 0 ] ) . toEqual ( {
137- id : "weather-123" , // Not normalized without modelId
137+ id : "weather-123" , // Not normalized without normalizeToolCallId function
138138 type : "function" ,
139139 function : {
140140 name : "get_weather" ,
@@ -143,7 +143,7 @@ describe("convertToOpenAiMessages", () => {
143143 } )
144144 } )
145145
146- it ( "should handle user messages with tool results (no normalization without modelId )" , ( ) => {
146+ it ( "should handle user messages with tool results (no normalization without normalizeToolCallId )" , ( ) => {
147147 const anthropicMessages : Anthropic . Messages . MessageParam [ ] = [
148148 {
149149 role : "user" ,
@@ -162,11 +162,11 @@ describe("convertToOpenAiMessages", () => {
162162
163163 const toolMessage = openAiMessages [ 0 ] as OpenAI . Chat . ChatCompletionToolMessageParam
164164 expect ( toolMessage . role ) . toBe ( "tool" )
165- expect ( toolMessage . tool_call_id ) . toBe ( "weather-123" ) // Not normalized without modelId
165+ expect ( toolMessage . tool_call_id ) . toBe ( "weather-123" ) // Not normalized without normalizeToolCallId function
166166 expect ( toolMessage . content ) . toBe ( "Current temperature in London: 20°C" )
167167 } )
168168
169- it ( "should normalize tool call IDs when modelId contains 'mistral' " , ( ) => {
169+ it ( "should normalize tool call IDs when normalizeToolCallId function is provided " , ( ) => {
170170 const anthropicMessages : Anthropic . Messages . MessageParam [ ] = [
171171 {
172172 role : "assistant" ,
@@ -191,9 +191,9 @@ describe("convertToOpenAiMessages", () => {
191191 } ,
192192 ]
193193
194- // With Mistral model ID - should normalize
194+ // With normalizeToolCallId function - should normalize
195195 const openAiMessages = convertToOpenAiMessages ( anthropicMessages , {
196- modelId : "mistralai/mistral-large-latest" ,
196+ normalizeToolCallId ,
197197 } )
198198
199199 const assistantMessage = openAiMessages [ 0 ] as OpenAI . Chat . ChatCompletionAssistantMessageParam
@@ -203,7 +203,7 @@ describe("convertToOpenAiMessages", () => {
203203 expect ( toolMessage . tool_call_id ) . toBe ( normalizeToolCallId ( "call_5019f900a247472bacde0b82" ) )
204204 } )
205205
206- it ( "should not normalize tool call IDs when modelId does not contain 'mistral' " , ( ) => {
206+ it ( "should not normalize tool call IDs when normalizeToolCallId function is not provided " , ( ) => {
207207 const anthropicMessages : Anthropic . Messages . MessageParam [ ] = [
208208 {
209209 role : "assistant" ,
@@ -228,8 +228,8 @@ describe("convertToOpenAiMessages", () => {
228228 } ,
229229 ]
230230
231- // With non-Mistral model ID - should NOT normalize
232- const openAiMessages = convertToOpenAiMessages ( anthropicMessages , { modelId : "openai/gpt-4" } )
231+ // Without normalizeToolCallId function - should NOT normalize
232+ const openAiMessages = convertToOpenAiMessages ( anthropicMessages , { } )
233233
234234 const assistantMessage = openAiMessages [ 0 ] as OpenAI . Chat . ChatCompletionAssistantMessageParam
235235 expect ( assistantMessage . tool_calls ! [ 0 ] . id ) . toBe ( "call_5019f900a247472bacde0b82" )
@@ -238,7 +238,7 @@ describe("convertToOpenAiMessages", () => {
238238 expect ( toolMessage . tool_call_id ) . toBe ( "call_5019f900a247472bacde0b82" )
239239 } )
240240
241- it ( "should be case-insensitive when checking for mistral in modelId " , ( ) => {
241+ it ( "should use custom normalization function when provided " , ( ) => {
242242 const anthropicMessages : Anthropic . Messages . MessageParam [ ] = [
243243 {
244244 role : "assistant" ,
@@ -253,10 +253,11 @@ describe("convertToOpenAiMessages", () => {
253253 } ,
254254 ]
255255
256- // Uppercase MISTRAL should still trigger normalization
257- const openAiMessages = convertToOpenAiMessages ( anthropicMessages , { modelId : "MISTRAL-7B" } )
256+ // Custom normalization function that prefixes with "custom_"
257+ const customNormalizer = ( id : string ) => `custom_${ id } `
258+ const openAiMessages = convertToOpenAiMessages ( anthropicMessages , { normalizeToolCallId : customNormalizer } )
258259
259260 const assistantMessage = openAiMessages [ 0 ] as OpenAI . Chat . ChatCompletionAssistantMessageParam
260- expect ( assistantMessage . tool_calls ! [ 0 ] . id ) . toBe ( normalizeToolCallId ( "toolu_123" ) )
261+ expect ( assistantMessage . tool_calls ! [ 0 ] . id ) . toBe ( "custom_toolu_123" )
261262 } )
262263} )
0 commit comments