@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.
package/dist/index.mjs CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  } from "@ai-sdk/provider-utils";
12
12
 
13
13
  // src/version.ts
14
- var VERSION = true ? "3.0.0-beta.69" : "0.0.0-test";
14
+ var VERSION = true ? "3.0.0-beta.70" : "0.0.0-test";
15
15
 
16
16
  // src/anthropic-messages-language-model.ts
17
17
  import {
@@ -22,6 +22,7 @@ import {
22
22
  combineHeaders,
23
23
  createEventSourceResponseHandler,
24
24
  createJsonResponseHandler,
25
+ createToolNameMapping,
25
26
  generateId,
26
27
  parseProviderOptions as parseProviderOptions2,
27
28
  postJsonToApi,
@@ -1257,7 +1258,8 @@ async function convertToAnthropicMessagesPrompt({
1257
1258
  prompt,
1258
1259
  sendReasoning,
1259
1260
  warnings,
1260
- cacheControlValidator
1261
+ cacheControlValidator,
1262
+ toolNameMapping
1261
1263
  }) {
1262
1264
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1263
1265
  const betas = /* @__PURE__ */ new Set();
@@ -1595,6 +1597,9 @@ async function convertToAnthropicMessagesPrompt({
1595
1597
  }
1596
1598
  case "tool-call": {
1597
1599
  if (part.providerExecuted) {
1600
+ const providerToolName = toolNameMapping.toProviderToolName(
1601
+ part.toolName
1602
+ );
1598
1603
  const isMcpToolUse = ((_h = (_g = part.providerOptions) == null ? void 0 : _g.anthropic) == null ? void 0 : _h.type) === "mcp-tool-use";
1599
1604
  if (isMcpToolUse) {
1600
1605
  mcpToolUseIds.add(part.toolCallId);
@@ -1616,7 +1621,7 @@ async function convertToAnthropicMessagesPrompt({
1616
1621
  });
1617
1622
  } else if (
1618
1623
  // code execution 20250825:
1619
- 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")
1624
+ 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")
1620
1625
  ) {
1621
1626
  anthropicContent.push({
1622
1627
  type: "server_tool_use",
@@ -1626,20 +1631,22 @@ async function convertToAnthropicMessagesPrompt({
1626
1631
  input: part.input,
1627
1632
  cache_control: cacheControl
1628
1633
  });
1629
- } else if (part.toolName === "code_execution" || // code execution 20250522
1630
- part.toolName === "web_fetch" || part.toolName === "web_search") {
1631
- anthropicContent.push({
1632
- type: "server_tool_use",
1633
- id: part.toolCallId,
1634
- name: part.toolName,
1635
- input: part.input,
1636
- cache_control: cacheControl
1637
- });
1638
1634
  } else {
1639
- warnings.push({
1640
- type: "other",
1641
- message: `provider executed tool call for tool ${part.toolName} is not supported`
1642
- });
1635
+ if (providerToolName === "code_execution" || // code execution 20250522
1636
+ providerToolName === "web_fetch" || providerToolName === "web_search") {
1637
+ anthropicContent.push({
1638
+ type: "server_tool_use",
1639
+ id: part.toolCallId,
1640
+ name: providerToolName,
1641
+ input: part.input,
1642
+ cache_control: cacheControl
1643
+ });
1644
+ } else {
1645
+ warnings.push({
1646
+ type: "other",
1647
+ message: `provider executed tool call for tool ${part.toolName} is not supported`
1648
+ });
1649
+ }
1643
1650
  }
1644
1651
  break;
1645
1652
  }
@@ -1653,6 +1660,9 @@ async function convertToAnthropicMessagesPrompt({
1653
1660
  break;
1654
1661
  }
1655
1662
  case "tool-result": {
1663
+ const providerToolName = toolNameMapping.toProviderToolName(
1664
+ part.toolName
1665
+ );
1656
1666
  if (mcpToolUseIds.has(part.toolCallId)) {
1657
1667
  const output = part.output;
1658
1668
  if (output.type !== "json" && output.type !== "error-json") {
@@ -1669,7 +1679,7 @@ async function convertToAnthropicMessagesPrompt({
1669
1679
  content: output.value,
1670
1680
  cache_control: cacheControl
1671
1681
  });
1672
- } else if (part.toolName === "code_execution") {
1682
+ } else if (providerToolName === "code_execution") {
1673
1683
  const output = part.output;
1674
1684
  if (output.type !== "json") {
1675
1685
  warnings.push({
@@ -1722,7 +1732,7 @@ async function convertToAnthropicMessagesPrompt({
1722
1732
  }
1723
1733
  break;
1724
1734
  }
1725
- if (part.toolName === "web_fetch") {
1735
+ if (providerToolName === "web_fetch") {
1726
1736
  const output = part.output;
1727
1737
  if (output.type !== "json") {
1728
1738
  warnings.push({
@@ -1757,7 +1767,7 @@ async function convertToAnthropicMessagesPrompt({
1757
1767
  });
1758
1768
  break;
1759
1769
  }
1760
- if (part.toolName === "web_search") {
1770
+ if (providerToolName === "web_search") {
1761
1771
  const output = part.output;
1762
1772
  if (output.type !== "json") {
1763
1773
  warnings.push({
@@ -1994,11 +2004,30 @@ var AnthropicMessagesLanguageModel = class {
1994
2004
  inputSchema: responseFormat.schema
1995
2005
  } : void 0;
1996
2006
  const cacheControlValidator = new CacheControlValidator();
2007
+ const toolNameMapping = createToolNameMapping({
2008
+ tools,
2009
+ providerToolNames: {
2010
+ "anthropic.code_execution_20250522": "code_execution",
2011
+ "anthropic.code_execution_20250825": "code_execution",
2012
+ "anthropic.computer_20241022": "computer",
2013
+ "anthropic.computer_20250124": "computer",
2014
+ "anthropic.text_editor_20241022": "str_replace_editor",
2015
+ "anthropic.text_editor_20250124": "str_replace_editor",
2016
+ "anthropic.text_editor_20250429": "str_replace_based_edit_tool",
2017
+ "anthropic.text_editor_20250728": "str_replace_based_edit_tool",
2018
+ "anthropic.bash_20241022": "bash",
2019
+ "anthropic.bash_20250124": "bash",
2020
+ "anthropic.memory_20250818": "memory",
2021
+ "anthropic.web_search_20250305": "web_search",
2022
+ "anthropic.web_fetch_20250910": "web_fetch"
2023
+ }
2024
+ });
1997
2025
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
1998
2026
  prompt,
1999
2027
  sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
2000
2028
  warnings,
2001
- cacheControlValidator
2029
+ cacheControlValidator,
2030
+ toolNameMapping
2002
2031
  });
2003
2032
  const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
2004
2033
  const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
@@ -2150,7 +2179,8 @@ var AnthropicMessagesLanguageModel = class {
2150
2179
  },
2151
2180
  warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
2152
2181
  betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas]),
2153
- usesJsonResponseTool: jsonResponseTool != null
2182
+ usesJsonResponseTool: jsonResponseTool != null,
2183
+ toolNameMapping
2154
2184
  };
2155
2185
  }
2156
2186
  async getHeaders({
@@ -2208,7 +2238,7 @@ var AnthropicMessagesLanguageModel = class {
2208
2238
  }
2209
2239
  async doGenerate(options) {
2210
2240
  var _a, _b, _c, _d, _e, _f, _g, _h;
2211
- const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2241
+ const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
2212
2242
  ...options,
2213
2243
  stream: false,
2214
2244
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
@@ -2299,7 +2329,7 @@ var AnthropicMessagesLanguageModel = class {
2299
2329
  content.push({
2300
2330
  type: "tool-call",
2301
2331
  toolCallId: part.id,
2302
- toolName: "code_execution",
2332
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2303
2333
  input: JSON.stringify({ type: part.name, ...part.input }),
2304
2334
  providerExecuted: true
2305
2335
  });
@@ -2307,7 +2337,7 @@ var AnthropicMessagesLanguageModel = class {
2307
2337
  content.push({
2308
2338
  type: "tool-call",
2309
2339
  toolCallId: part.id,
2310
- toolName: part.name,
2340
+ toolName: toolNameMapping.toCustomToolName(part.name),
2311
2341
  input: JSON.stringify(part.input),
2312
2342
  providerExecuted: true
2313
2343
  });
@@ -2349,7 +2379,7 @@ var AnthropicMessagesLanguageModel = class {
2349
2379
  content.push({
2350
2380
  type: "tool-result",
2351
2381
  toolCallId: part.tool_use_id,
2352
- toolName: "web_fetch",
2382
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2353
2383
  result: {
2354
2384
  type: "web_fetch_result",
2355
2385
  url: part.content.url,
@@ -2370,7 +2400,7 @@ var AnthropicMessagesLanguageModel = class {
2370
2400
  content.push({
2371
2401
  type: "tool-result",
2372
2402
  toolCallId: part.tool_use_id,
2373
- toolName: "web_fetch",
2403
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2374
2404
  isError: true,
2375
2405
  result: {
2376
2406
  type: "web_fetch_tool_result_error",
@@ -2385,7 +2415,7 @@ var AnthropicMessagesLanguageModel = class {
2385
2415
  content.push({
2386
2416
  type: "tool-result",
2387
2417
  toolCallId: part.tool_use_id,
2388
- toolName: "web_search",
2418
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2389
2419
  result: part.content.map((result) => {
2390
2420
  var _a2;
2391
2421
  return {
@@ -2415,7 +2445,7 @@ var AnthropicMessagesLanguageModel = class {
2415
2445
  content.push({
2416
2446
  type: "tool-result",
2417
2447
  toolCallId: part.tool_use_id,
2418
- toolName: "web_search",
2448
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2419
2449
  isError: true,
2420
2450
  result: {
2421
2451
  type: "web_search_tool_result_error",
@@ -2431,7 +2461,7 @@ var AnthropicMessagesLanguageModel = class {
2431
2461
  content.push({
2432
2462
  type: "tool-result",
2433
2463
  toolCallId: part.tool_use_id,
2434
- toolName: "code_execution",
2464
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2435
2465
  result: {
2436
2466
  type: part.content.type,
2437
2467
  stdout: part.content.stdout,
@@ -2443,7 +2473,7 @@ var AnthropicMessagesLanguageModel = class {
2443
2473
  content.push({
2444
2474
  type: "tool-result",
2445
2475
  toolCallId: part.tool_use_id,
2446
- toolName: "code_execution",
2476
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2447
2477
  isError: true,
2448
2478
  result: {
2449
2479
  type: "code_execution_tool_result_error",
@@ -2459,7 +2489,7 @@ var AnthropicMessagesLanguageModel = class {
2459
2489
  content.push({
2460
2490
  type: "tool-result",
2461
2491
  toolCallId: part.tool_use_id,
2462
- toolName: "code_execution",
2492
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2463
2493
  result: part.content
2464
2494
  });
2465
2495
  break;
@@ -2510,7 +2540,8 @@ var AnthropicMessagesLanguageModel = class {
2510
2540
  args: body,
2511
2541
  warnings,
2512
2542
  betas,
2513
- usesJsonResponseTool
2543
+ usesJsonResponseTool,
2544
+ toolNameMapping
2514
2545
  } = await this.getArgs({
2515
2546
  ...options,
2516
2547
  stream: true,
@@ -2636,19 +2667,21 @@ var AnthropicMessagesLanguageModel = class {
2636
2667
  // code execution 20250825 bash:
2637
2668
  "bash_code_execution"
2638
2669
  ].includes(part.name)) {
2670
+ const providerToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2671
+ const customToolName = toolNameMapping.toCustomToolName(providerToolName);
2639
2672
  contentBlocks[value.index] = {
2640
2673
  type: "tool-call",
2641
2674
  toolCallId: part.id,
2642
- toolName: part.name,
2675
+ toolName: customToolName,
2643
2676
  input: "",
2644
2677
  providerExecuted: true,
2645
- firstDelta: true
2678
+ firstDelta: true,
2679
+ providerToolName: part.name
2646
2680
  };
2647
- const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2648
2681
  controller.enqueue({
2649
2682
  type: "tool-input-start",
2650
2683
  id: part.id,
2651
- toolName: mappedToolName,
2684
+ toolName: customToolName,
2652
2685
  providerExecuted: true
2653
2686
  });
2654
2687
  }
@@ -2659,7 +2692,7 @@ var AnthropicMessagesLanguageModel = class {
2659
2692
  controller.enqueue({
2660
2693
  type: "tool-result",
2661
2694
  toolCallId: part.tool_use_id,
2662
- toolName: "web_fetch",
2695
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2663
2696
  result: {
2664
2697
  type: "web_fetch_result",
2665
2698
  url: part.content.url,
@@ -2680,7 +2713,7 @@ var AnthropicMessagesLanguageModel = class {
2680
2713
  controller.enqueue({
2681
2714
  type: "tool-result",
2682
2715
  toolCallId: part.tool_use_id,
2683
- toolName: "web_fetch",
2716
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2684
2717
  isError: true,
2685
2718
  result: {
2686
2719
  type: "web_fetch_tool_result_error",
@@ -2695,7 +2728,7 @@ var AnthropicMessagesLanguageModel = class {
2695
2728
  controller.enqueue({
2696
2729
  type: "tool-result",
2697
2730
  toolCallId: part.tool_use_id,
2698
- toolName: "web_search",
2731
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2699
2732
  result: part.content.map((result) => {
2700
2733
  var _a3;
2701
2734
  return {
@@ -2725,7 +2758,7 @@ var AnthropicMessagesLanguageModel = class {
2725
2758
  controller.enqueue({
2726
2759
  type: "tool-result",
2727
2760
  toolCallId: part.tool_use_id,
2728
- toolName: "web_search",
2761
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2729
2762
  isError: true,
2730
2763
  result: {
2731
2764
  type: "web_search_tool_result_error",
@@ -2741,7 +2774,7 @@ var AnthropicMessagesLanguageModel = class {
2741
2774
  controller.enqueue({
2742
2775
  type: "tool-result",
2743
2776
  toolCallId: part.tool_use_id,
2744
- toolName: "code_execution",
2777
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2745
2778
  result: {
2746
2779
  type: part.content.type,
2747
2780
  stdout: part.content.stdout,
@@ -2753,7 +2786,7 @@ var AnthropicMessagesLanguageModel = class {
2753
2786
  controller.enqueue({
2754
2787
  type: "tool-result",
2755
2788
  toolCallId: part.tool_use_id,
2756
- toolName: "code_execution",
2789
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2757
2790
  isError: true,
2758
2791
  result: {
2759
2792
  type: "code_execution_tool_result_error",
@@ -2769,7 +2802,7 @@ var AnthropicMessagesLanguageModel = class {
2769
2802
  controller.enqueue({
2770
2803
  type: "tool-result",
2771
2804
  toolCallId: part.tool_use_id,
2772
- toolName: "code_execution",
2805
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2773
2806
  result: part.content
2774
2807
  });
2775
2808
  return;
@@ -2837,11 +2870,10 @@ var AnthropicMessagesLanguageModel = class {
2837
2870
  type: "tool-input-end",
2838
2871
  id: contentBlock.toolCallId
2839
2872
  });
2840
- const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
2841
2873
  controller.enqueue({
2842
2874
  type: "tool-call",
2843
2875
  toolCallId: contentBlock.toolCallId,
2844
- toolName,
2876
+ toolName: contentBlock.toolName,
2845
2877
  input: contentBlock.input === "" ? "{}" : contentBlock.input,
2846
2878
  providerExecuted: contentBlock.providerExecuted
2847
2879
  });
@@ -2909,8 +2941,8 @@ var AnthropicMessagesLanguageModel = class {
2909
2941
  if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
2910
2942
  return;
2911
2943
  }
2912
- if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
2913
- delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
2944
+ if (contentBlock.firstDelta && (contentBlock.providerToolName === "bash_code_execution" || contentBlock.providerToolName === "text_editor_code_execution")) {
2945
+ delta = `{"type": "${contentBlock.providerToolName}",${delta.substring(1)}`;
2914
2946
  }
2915
2947
  controller.enqueue({
2916
2948
  type: "tool-input-delta",