@ai-sdk/anthropic 3.0.0-beta.69 → 3.0.0-beta.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -556,7 +556,7 @@ declare class CacheControlValidator {
556
556
 
557
557
  declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, }: {
558
558
  tools: LanguageModelV3CallOptions['tools'];
559
- toolChoice?: LanguageModelV3CallOptions['toolChoice'];
559
+ toolChoice: LanguageModelV3CallOptions['toolChoice'] | undefined;
560
560
  disableParallelToolUse?: boolean;
561
561
  cacheControlValidator?: CacheControlValidator;
562
562
  }): Promise<{
@@ -556,7 +556,7 @@ declare class CacheControlValidator {
556
556
 
557
557
  declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, }: {
558
558
  tools: LanguageModelV3CallOptions['tools'];
559
- toolChoice?: LanguageModelV3CallOptions['toolChoice'];
559
+ toolChoice: LanguageModelV3CallOptions['toolChoice'] | undefined;
560
560
  disableParallelToolUse?: boolean;
561
561
  cacheControlValidator?: CacheControlValidator;
562
562
  }): Promise<{
@@ -1230,7 +1230,8 @@ async function convertToAnthropicMessagesPrompt({
1230
1230
  prompt,
1231
1231
  sendReasoning,
1232
1232
  warnings,
1233
- cacheControlValidator
1233
+ cacheControlValidator,
1234
+ toolNameMapping
1234
1235
  }) {
1235
1236
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1236
1237
  const betas = /* @__PURE__ */ new Set();
@@ -1568,6 +1569,9 @@ async function convertToAnthropicMessagesPrompt({
1568
1569
  }
1569
1570
  case "tool-call": {
1570
1571
  if (part.providerExecuted) {
1572
+ const providerToolName = toolNameMapping.toProviderToolName(
1573
+ part.toolName
1574
+ );
1571
1575
  const isMcpToolUse = ((_h = (_g = part.providerOptions) == null ? void 0 : _g.anthropic) == null ? void 0 : _h.type) === "mcp-tool-use";
1572
1576
  if (isMcpToolUse) {
1573
1577
  mcpToolUseIds.add(part.toolCallId);
@@ -1589,7 +1593,7 @@ async function convertToAnthropicMessagesPrompt({
1589
1593
  });
1590
1594
  } else if (
1591
1595
  // code execution 20250825:
1592
- part.toolName === "code_execution" && part.input != null && typeof part.input === "object" && "type" in part.input && typeof part.input.type === "string" && (part.input.type === "bash_code_execution" || part.input.type === "text_editor_code_execution")
1596
+ providerToolName === "code_execution" && part.input != null && typeof part.input === "object" && "type" in part.input && typeof part.input.type === "string" && (part.input.type === "bash_code_execution" || part.input.type === "text_editor_code_execution")
1593
1597
  ) {
1594
1598
  anthropicContent.push({
1595
1599
  type: "server_tool_use",
@@ -1599,20 +1603,22 @@ async function convertToAnthropicMessagesPrompt({
1599
1603
  input: part.input,
1600
1604
  cache_control: cacheControl
1601
1605
  });
1602
- } else if (part.toolName === "code_execution" || // code execution 20250522
1603
- part.toolName === "web_fetch" || part.toolName === "web_search") {
1604
- anthropicContent.push({
1605
- type: "server_tool_use",
1606
- id: part.toolCallId,
1607
- name: part.toolName,
1608
- input: part.input,
1609
- cache_control: cacheControl
1610
- });
1611
1606
  } else {
1612
- warnings.push({
1613
- type: "other",
1614
- message: `provider executed tool call for tool ${part.toolName} is not supported`
1615
- });
1607
+ if (providerToolName === "code_execution" || // code execution 20250522
1608
+ providerToolName === "web_fetch" || providerToolName === "web_search") {
1609
+ anthropicContent.push({
1610
+ type: "server_tool_use",
1611
+ id: part.toolCallId,
1612
+ name: providerToolName,
1613
+ input: part.input,
1614
+ cache_control: cacheControl
1615
+ });
1616
+ } else {
1617
+ warnings.push({
1618
+ type: "other",
1619
+ message: `provider executed tool call for tool ${part.toolName} is not supported`
1620
+ });
1621
+ }
1616
1622
  }
1617
1623
  break;
1618
1624
  }
@@ -1626,6 +1632,9 @@ async function convertToAnthropicMessagesPrompt({
1626
1632
  break;
1627
1633
  }
1628
1634
  case "tool-result": {
1635
+ const providerToolName = toolNameMapping.toProviderToolName(
1636
+ part.toolName
1637
+ );
1629
1638
  if (mcpToolUseIds.has(part.toolCallId)) {
1630
1639
  const output = part.output;
1631
1640
  if (output.type !== "json" && output.type !== "error-json") {
@@ -1642,7 +1651,7 @@ async function convertToAnthropicMessagesPrompt({
1642
1651
  content: output.value,
1643
1652
  cache_control: cacheControl
1644
1653
  });
1645
- } else if (part.toolName === "code_execution") {
1654
+ } else if (providerToolName === "code_execution") {
1646
1655
  const output = part.output;
1647
1656
  if (output.type !== "json") {
1648
1657
  warnings.push({
@@ -1695,7 +1704,7 @@ async function convertToAnthropicMessagesPrompt({
1695
1704
  }
1696
1705
  break;
1697
1706
  }
1698
- if (part.toolName === "web_fetch") {
1707
+ if (providerToolName === "web_fetch") {
1699
1708
  const output = part.output;
1700
1709
  if (output.type !== "json") {
1701
1710
  warnings.push({
@@ -1730,7 +1739,7 @@ async function convertToAnthropicMessagesPrompt({
1730
1739
  });
1731
1740
  break;
1732
1741
  }
1733
- if (part.toolName === "web_search") {
1742
+ if (providerToolName === "web_search") {
1734
1743
  const output = part.output;
1735
1744
  if (output.type !== "json") {
1736
1745
  warnings.push({
@@ -1967,11 +1976,30 @@ var AnthropicMessagesLanguageModel = class {
1967
1976
  inputSchema: responseFormat.schema
1968
1977
  } : void 0;
1969
1978
  const cacheControlValidator = new CacheControlValidator();
1979
+ const toolNameMapping = (0, import_provider_utils11.createToolNameMapping)({
1980
+ tools,
1981
+ providerToolNames: {
1982
+ "anthropic.code_execution_20250522": "code_execution",
1983
+ "anthropic.code_execution_20250825": "code_execution",
1984
+ "anthropic.computer_20241022": "computer",
1985
+ "anthropic.computer_20250124": "computer",
1986
+ "anthropic.text_editor_20241022": "str_replace_editor",
1987
+ "anthropic.text_editor_20250124": "str_replace_editor",
1988
+ "anthropic.text_editor_20250429": "str_replace_based_edit_tool",
1989
+ "anthropic.text_editor_20250728": "str_replace_based_edit_tool",
1990
+ "anthropic.bash_20241022": "bash",
1991
+ "anthropic.bash_20250124": "bash",
1992
+ "anthropic.memory_20250818": "memory",
1993
+ "anthropic.web_search_20250305": "web_search",
1994
+ "anthropic.web_fetch_20250910": "web_fetch"
1995
+ }
1996
+ });
1970
1997
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
1971
1998
  prompt,
1972
1999
  sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
1973
2000
  warnings,
1974
- cacheControlValidator
2001
+ cacheControlValidator,
2002
+ toolNameMapping
1975
2003
  });
1976
2004
  const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
1977
2005
  const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
@@ -2123,7 +2151,8 @@ var AnthropicMessagesLanguageModel = class {
2123
2151
  },
2124
2152
  warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
2125
2153
  betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas]),
2126
- usesJsonResponseTool: jsonResponseTool != null
2154
+ usesJsonResponseTool: jsonResponseTool != null,
2155
+ toolNameMapping
2127
2156
  };
2128
2157
  }
2129
2158
  async getHeaders({
@@ -2181,7 +2210,7 @@ var AnthropicMessagesLanguageModel = class {
2181
2210
  }
2182
2211
  async doGenerate(options) {
2183
2212
  var _a, _b, _c, _d, _e, _f, _g, _h;
2184
- const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2213
+ const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
2185
2214
  ...options,
2186
2215
  stream: false,
2187
2216
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
@@ -2272,7 +2301,7 @@ var AnthropicMessagesLanguageModel = class {
2272
2301
  content.push({
2273
2302
  type: "tool-call",
2274
2303
  toolCallId: part.id,
2275
- toolName: "code_execution",
2304
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2276
2305
  input: JSON.stringify({ type: part.name, ...part.input }),
2277
2306
  providerExecuted: true
2278
2307
  });
@@ -2280,7 +2309,7 @@ var AnthropicMessagesLanguageModel = class {
2280
2309
  content.push({
2281
2310
  type: "tool-call",
2282
2311
  toolCallId: part.id,
2283
- toolName: part.name,
2312
+ toolName: toolNameMapping.toCustomToolName(part.name),
2284
2313
  input: JSON.stringify(part.input),
2285
2314
  providerExecuted: true
2286
2315
  });
@@ -2322,7 +2351,7 @@ var AnthropicMessagesLanguageModel = class {
2322
2351
  content.push({
2323
2352
  type: "tool-result",
2324
2353
  toolCallId: part.tool_use_id,
2325
- toolName: "web_fetch",
2354
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2326
2355
  result: {
2327
2356
  type: "web_fetch_result",
2328
2357
  url: part.content.url,
@@ -2343,7 +2372,7 @@ var AnthropicMessagesLanguageModel = class {
2343
2372
  content.push({
2344
2373
  type: "tool-result",
2345
2374
  toolCallId: part.tool_use_id,
2346
- toolName: "web_fetch",
2375
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2347
2376
  isError: true,
2348
2377
  result: {
2349
2378
  type: "web_fetch_tool_result_error",
@@ -2358,7 +2387,7 @@ var AnthropicMessagesLanguageModel = class {
2358
2387
  content.push({
2359
2388
  type: "tool-result",
2360
2389
  toolCallId: part.tool_use_id,
2361
- toolName: "web_search",
2390
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2362
2391
  result: part.content.map((result) => {
2363
2392
  var _a2;
2364
2393
  return {
@@ -2388,7 +2417,7 @@ var AnthropicMessagesLanguageModel = class {
2388
2417
  content.push({
2389
2418
  type: "tool-result",
2390
2419
  toolCallId: part.tool_use_id,
2391
- toolName: "web_search",
2420
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2392
2421
  isError: true,
2393
2422
  result: {
2394
2423
  type: "web_search_tool_result_error",
@@ -2404,7 +2433,7 @@ var AnthropicMessagesLanguageModel = class {
2404
2433
  content.push({
2405
2434
  type: "tool-result",
2406
2435
  toolCallId: part.tool_use_id,
2407
- toolName: "code_execution",
2436
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2408
2437
  result: {
2409
2438
  type: part.content.type,
2410
2439
  stdout: part.content.stdout,
@@ -2416,7 +2445,7 @@ var AnthropicMessagesLanguageModel = class {
2416
2445
  content.push({
2417
2446
  type: "tool-result",
2418
2447
  toolCallId: part.tool_use_id,
2419
- toolName: "code_execution",
2448
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2420
2449
  isError: true,
2421
2450
  result: {
2422
2451
  type: "code_execution_tool_result_error",
@@ -2432,7 +2461,7 @@ var AnthropicMessagesLanguageModel = class {
2432
2461
  content.push({
2433
2462
  type: "tool-result",
2434
2463
  toolCallId: part.tool_use_id,
2435
- toolName: "code_execution",
2464
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2436
2465
  result: part.content
2437
2466
  });
2438
2467
  break;
@@ -2483,7 +2512,8 @@ var AnthropicMessagesLanguageModel = class {
2483
2512
  args: body,
2484
2513
  warnings,
2485
2514
  betas,
2486
- usesJsonResponseTool
2515
+ usesJsonResponseTool,
2516
+ toolNameMapping
2487
2517
  } = await this.getArgs({
2488
2518
  ...options,
2489
2519
  stream: true,
@@ -2609,19 +2639,21 @@ var AnthropicMessagesLanguageModel = class {
2609
2639
  // code execution 20250825 bash:
2610
2640
  "bash_code_execution"
2611
2641
  ].includes(part.name)) {
2642
+ const providerToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2643
+ const customToolName = toolNameMapping.toCustomToolName(providerToolName);
2612
2644
  contentBlocks[value.index] = {
2613
2645
  type: "tool-call",
2614
2646
  toolCallId: part.id,
2615
- toolName: part.name,
2647
+ toolName: customToolName,
2616
2648
  input: "",
2617
2649
  providerExecuted: true,
2618
- firstDelta: true
2650
+ firstDelta: true,
2651
+ providerToolName: part.name
2619
2652
  };
2620
- const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2621
2653
  controller.enqueue({
2622
2654
  type: "tool-input-start",
2623
2655
  id: part.id,
2624
- toolName: mappedToolName,
2656
+ toolName: customToolName,
2625
2657
  providerExecuted: true
2626
2658
  });
2627
2659
  }
@@ -2632,7 +2664,7 @@ var AnthropicMessagesLanguageModel = class {
2632
2664
  controller.enqueue({
2633
2665
  type: "tool-result",
2634
2666
  toolCallId: part.tool_use_id,
2635
- toolName: "web_fetch",
2667
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2636
2668
  result: {
2637
2669
  type: "web_fetch_result",
2638
2670
  url: part.content.url,
@@ -2653,7 +2685,7 @@ var AnthropicMessagesLanguageModel = class {
2653
2685
  controller.enqueue({
2654
2686
  type: "tool-result",
2655
2687
  toolCallId: part.tool_use_id,
2656
- toolName: "web_fetch",
2688
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2657
2689
  isError: true,
2658
2690
  result: {
2659
2691
  type: "web_fetch_tool_result_error",
@@ -2668,7 +2700,7 @@ var AnthropicMessagesLanguageModel = class {
2668
2700
  controller.enqueue({
2669
2701
  type: "tool-result",
2670
2702
  toolCallId: part.tool_use_id,
2671
- toolName: "web_search",
2703
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2672
2704
  result: part.content.map((result) => {
2673
2705
  var _a3;
2674
2706
  return {
@@ -2698,7 +2730,7 @@ var AnthropicMessagesLanguageModel = class {
2698
2730
  controller.enqueue({
2699
2731
  type: "tool-result",
2700
2732
  toolCallId: part.tool_use_id,
2701
- toolName: "web_search",
2733
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2702
2734
  isError: true,
2703
2735
  result: {
2704
2736
  type: "web_search_tool_result_error",
@@ -2714,7 +2746,7 @@ var AnthropicMessagesLanguageModel = class {
2714
2746
  controller.enqueue({
2715
2747
  type: "tool-result",
2716
2748
  toolCallId: part.tool_use_id,
2717
- toolName: "code_execution",
2749
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2718
2750
  result: {
2719
2751
  type: part.content.type,
2720
2752
  stdout: part.content.stdout,
@@ -2726,7 +2758,7 @@ var AnthropicMessagesLanguageModel = class {
2726
2758
  controller.enqueue({
2727
2759
  type: "tool-result",
2728
2760
  toolCallId: part.tool_use_id,
2729
- toolName: "code_execution",
2761
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2730
2762
  isError: true,
2731
2763
  result: {
2732
2764
  type: "code_execution_tool_result_error",
@@ -2742,7 +2774,7 @@ var AnthropicMessagesLanguageModel = class {
2742
2774
  controller.enqueue({
2743
2775
  type: "tool-result",
2744
2776
  toolCallId: part.tool_use_id,
2745
- toolName: "code_execution",
2777
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2746
2778
  result: part.content
2747
2779
  });
2748
2780
  return;
@@ -2810,11 +2842,10 @@ var AnthropicMessagesLanguageModel = class {
2810
2842
  type: "tool-input-end",
2811
2843
  id: contentBlock.toolCallId
2812
2844
  });
2813
- const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
2814
2845
  controller.enqueue({
2815
2846
  type: "tool-call",
2816
2847
  toolCallId: contentBlock.toolCallId,
2817
- toolName,
2848
+ toolName: contentBlock.toolName,
2818
2849
  input: contentBlock.input === "" ? "{}" : contentBlock.input,
2819
2850
  providerExecuted: contentBlock.providerExecuted
2820
2851
  });
@@ -2882,8 +2913,8 @@ var AnthropicMessagesLanguageModel = class {
2882
2913
  if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
2883
2914
  return;
2884
2915
  }
2885
- if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
2886
- delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
2916
+ if (contentBlock.firstDelta && (contentBlock.providerToolName === "bash_code_execution" || contentBlock.providerToolName === "text_editor_code_execution")) {
2917
+ delta = `{"type": "${contentBlock.providerToolName}",${delta.substring(1)}`;
2887
2918
  }
2888
2919
  controller.enqueue({
2889
2920
  type: "tool-input-delta",