@@ -269,13 +269,31 @@ describe("OpenAiHandler", () => {
269269 chunks . push ( chunk )
270270 }
271271
272- const toolCallChunks = chunks . filter ( ( chunk ) => chunk . type === "tool_call" )
273- expect ( toolCallChunks ) . toHaveLength ( 1 )
274- expect ( toolCallChunks [ 0 ] ) . toEqual ( {
275- type : "tool_call" ,
272+ // Provider now yields tool_call_partial chunks, NativeToolCallParser handles reassembly
273+ const toolCallPartialChunks = chunks . filter ( ( chunk ) => chunk . type === "tool_call_partial" )
274+ expect ( toolCallPartialChunks ) . toHaveLength ( 3 )
275+ // First chunk has id and name
276+ expect ( toolCallPartialChunks [ 0 ] ) . toEqual ( {
277+ type : "tool_call_partial" ,
278+ index : 0 ,
276279 id : "call_1" ,
277280 name : "test_tool" ,
278- arguments : '{"arg":"value"}' ,
281+ arguments : "" ,
282+ } )
283+ // Subsequent chunks have arguments
284+ expect ( toolCallPartialChunks [ 1 ] ) . toEqual ( {
285+ type : "tool_call_partial" ,
286+ index : 0 ,
287+ id : undefined ,
288+ name : undefined ,
289+ arguments : '{"arg":' ,
290+ } )
291+ expect ( toolCallPartialChunks [ 2 ] ) . toEqual ( {
292+ type : "tool_call_partial" ,
293+ index : 0 ,
294+ id : undefined ,
295+ name : undefined ,
296+ arguments : '"value"}' ,
279297 } )
280298 } )
281299
@@ -318,11 +336,12 @@ describe("OpenAiHandler", () => {
318336 chunks . push ( chunk )
319337 }
320338
321- // Tool calls should still be yielded via the fallback mechanism
322- const toolCallChunks = chunks . filter ( ( chunk ) => chunk . type === "tool_call" )
323- expect ( toolCallChunks ) . toHaveLength ( 1 )
324- expect ( toolCallChunks [ 0 ] ) . toEqual ( {
325- type : "tool_call" ,
339+ // Provider now yields tool_call_partial chunks, NativeToolCallParser handles reassembly
340+ const toolCallPartialChunks = chunks . filter ( ( chunk ) => chunk . type === "tool_call_partial" )
341+ expect ( toolCallPartialChunks ) . toHaveLength ( 1 )
342+ expect ( toolCallPartialChunks [ 0 ] ) . toEqual ( {
343+ type : "tool_call_partial" ,
344+ index : 0 ,
326345 id : "call_fallback" ,
327346 name : "fallback_tool" ,
328347 arguments : '{"test":"fallback"}' ,
@@ -819,12 +838,21 @@ describe("OpenAiHandler", () => {
819838 chunks . push ( chunk )
820839 }
821840
822- const toolCallChunks = chunks . filter ( ( chunk ) => chunk . type === "tool_call" )
823- expect ( toolCallChunks ) . toHaveLength ( 1 )
824- expect ( toolCallChunks [ 0 ] ) . toEqual ( {
825- type : "tool_call" ,
841+ // Provider now yields tool_call_partial chunks, NativeToolCallParser handles reassembly
842+ const toolCallPartialChunks = chunks . filter ( ( chunk ) => chunk . type === "tool_call_partial" )
843+ expect ( toolCallPartialChunks ) . toHaveLength ( 2 )
844+ expect ( toolCallPartialChunks [ 0 ] ) . toEqual ( {
845+ type : "tool_call_partial" ,
846+ index : 0 ,
826847 id : "call_1" ,
827848 name : "test_tool" ,
849+ arguments : "" ,
850+ } )
851+ expect ( toolCallPartialChunks [ 1 ] ) . toEqual ( {
852+ type : "tool_call_partial" ,
853+ index : 0 ,
854+ id : undefined ,
855+ name : undefined ,
828856 arguments : "{}" ,
829857 } )
830858 } )
@@ -870,11 +898,12 @@ describe("OpenAiHandler", () => {
870898 chunks . push ( chunk )
871899 }
872900
873- // Tool calls should still be yielded via the fallback mechanism
874- const toolCallChunks = chunks . filter ( ( chunk ) => chunk . type === "tool_call" )
875- expect ( toolCallChunks ) . toHaveLength ( 1 )
876- expect ( toolCallChunks [ 0 ] ) . toEqual ( {
877- type : "tool_call" ,
901+ // Provider now yields tool_call_partial chunks, NativeToolCallParser handles reassembly
902+ const toolCallPartialChunks = chunks . filter ( ( chunk ) => chunk . type === "tool_call_partial" )
903+ expect ( toolCallPartialChunks ) . toHaveLength ( 1 )
904+ expect ( toolCallPartialChunks [ 0 ] ) . toEqual ( {
905+ type : "tool_call_partial" ,
906+ index : 0 ,
878907 id : "call_o3_fallback" ,
879908 name : "o3_fallback_tool" ,
880909 arguments : '{"o3":"test"}' ,
0 commit comments