@@ -1111,7 +1111,7 @@ describe("Tool search beta auto-append", () => {
11111111
11121112 expect (
11131113 paramsWithoutToolSearch . betas === undefined ||
1114- ! paramsWithoutToolSearch . betas . includes ( "advanced-tool-use-2025-11-20" )
1114+ ! paramsWithoutToolSearch . betas . includes ( "advanced-tool-use-2025-11-20" )
11151115 ) . toBe ( true ) ;
11161116 } ) ;
11171117} ) ;
@@ -1285,6 +1285,52 @@ describe("Streaming tool call consolidation (input_json_delta handling)", () =>
12851285 input : { prompt : "hello" } ,
12861286 } ) ;
12871287 } ) ;
1288+
1289+ test ( "should successfully aggregate tool_use and input_json_delta chunks via .concat()" , async ( ) => {
1290+ // 1. Replicate the exact asymmetric sequence Anthropic emits during an active stream
1291+ const chunk1 = new AIMessageChunk ( {
1292+ content : [
1293+ {
1294+ type : "tool_use" ,
1295+ index : 0 ,
1296+ id : "toolu_01Xyz" ,
1297+ name : "my_tool" ,
1298+ }
1299+ ]
1300+ } ) ;
1301+
1302+ const chunk2 = new AIMessageChunk ( {
1303+ content : [
1304+ {
1305+ type : "input_json_delta" ,
1306+ index : 0 ,
1307+ partial_json : '{"prompt":' ,
1308+ }
1309+ ]
1310+ } ) ;
1311+
1312+ const chunk3 = new AIMessageChunk ( {
1313+ content : [
1314+ {
1315+ type : "input_json_delta" ,
1316+ index : 0 ,
1317+ partial_json : '"hello"}' ,
1318+ }
1319+ ]
1320+ } ) ;
1321+
1322+ // 2. Execute the concatenation (this is what threw OUTPUT_PARSING_FAILURE before your fix)
1323+ const merged = chunk1 . concat ( chunk2 ) . concat ( chunk3 ) ;
1324+
1325+ // 3. Assert that types map correctly and accumulate into a single valid tool call structure
1326+ expect ( merged . content [ 0 ] ) . toEqual ( {
1327+ type : "tool_use" ,
1328+ index : 0 ,
1329+ id : "toolu_01Xyz" ,
1330+ name : "my_tool" ,
1331+ partial_json : '{"prompt":"hello"}'
1332+ } ) ;
1333+ } ) ;
12881334} ) ;
12891335
12901336describe ( "ContentBlock.Multimodal.Image format support" , ( ) => {
@@ -1959,7 +2005,7 @@ describe("Opus 4.6", () => {
19592005
19602006 expect (
19612007 params . betas === undefined ||
1962- ! params . betas . includes ( "compact-2026-01-12" )
2008+ ! params . betas . includes ( "compact-2026-01-12" )
19632009 ) . toBe ( true ) ;
19642010 } ) ;
19652011
0 commit comments