@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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 3.0.0-beta.70
4
+
5
+ ### Patch Changes
6
+
7
+ - f13958c: chore(antropic): allow custom names for provider-defined tools
8
+
3
9
  ## 3.0.0-beta.69
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
31
31
  var import_provider_utils20 = require("@ai-sdk/provider-utils");
32
32
 
33
33
  // src/version.ts
34
- var VERSION = true ? "3.0.0-beta.69" : "0.0.0-test";
34
+ var VERSION = true ? "3.0.0-beta.70" : "0.0.0-test";
35
35
 
36
36
  // src/anthropic-messages-language-model.ts
37
37
  var import_provider3 = require("@ai-sdk/provider");
@@ -1237,7 +1237,8 @@ async function convertToAnthropicMessagesPrompt({
1237
1237
  prompt,
1238
1238
  sendReasoning,
1239
1239
  warnings,
1240
- cacheControlValidator
1240
+ cacheControlValidator,
1241
+ toolNameMapping
1241
1242
  }) {
1242
1243
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1243
1244
  const betas = /* @__PURE__ */ new Set();
@@ -1575,6 +1576,9 @@ async function convertToAnthropicMessagesPrompt({
1575
1576
  }
1576
1577
  case "tool-call": {
1577
1578
  if (part.providerExecuted) {
1579
+ const providerToolName = toolNameMapping.toProviderToolName(
1580
+ part.toolName
1581
+ );
1578
1582
  const isMcpToolUse = ((_h = (_g = part.providerOptions) == null ? void 0 : _g.anthropic) == null ? void 0 : _h.type) === "mcp-tool-use";
1579
1583
  if (isMcpToolUse) {
1580
1584
  mcpToolUseIds.add(part.toolCallId);
@@ -1596,7 +1600,7 @@ async function convertToAnthropicMessagesPrompt({
1596
1600
  });
1597
1601
  } else if (
1598
1602
  // code execution 20250825:
1599
- 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")
1603
+ 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")
1600
1604
  ) {
1601
1605
  anthropicContent.push({
1602
1606
  type: "server_tool_use",
@@ -1606,20 +1610,22 @@ async function convertToAnthropicMessagesPrompt({
1606
1610
  input: part.input,
1607
1611
  cache_control: cacheControl
1608
1612
  });
1609
- } else if (part.toolName === "code_execution" || // code execution 20250522
1610
- part.toolName === "web_fetch" || part.toolName === "web_search") {
1611
- anthropicContent.push({
1612
- type: "server_tool_use",
1613
- id: part.toolCallId,
1614
- name: part.toolName,
1615
- input: part.input,
1616
- cache_control: cacheControl
1617
- });
1618
1613
  } else {
1619
- warnings.push({
1620
- type: "other",
1621
- message: `provider executed tool call for tool ${part.toolName} is not supported`
1622
- });
1614
+ if (providerToolName === "code_execution" || // code execution 20250522
1615
+ providerToolName === "web_fetch" || providerToolName === "web_search") {
1616
+ anthropicContent.push({
1617
+ type: "server_tool_use",
1618
+ id: part.toolCallId,
1619
+ name: providerToolName,
1620
+ input: part.input,
1621
+ cache_control: cacheControl
1622
+ });
1623
+ } else {
1624
+ warnings.push({
1625
+ type: "other",
1626
+ message: `provider executed tool call for tool ${part.toolName} is not supported`
1627
+ });
1628
+ }
1623
1629
  }
1624
1630
  break;
1625
1631
  }
@@ -1633,6 +1639,9 @@ async function convertToAnthropicMessagesPrompt({
1633
1639
  break;
1634
1640
  }
1635
1641
  case "tool-result": {
1642
+ const providerToolName = toolNameMapping.toProviderToolName(
1643
+ part.toolName
1644
+ );
1636
1645
  if (mcpToolUseIds.has(part.toolCallId)) {
1637
1646
  const output = part.output;
1638
1647
  if (output.type !== "json" && output.type !== "error-json") {
@@ -1649,7 +1658,7 @@ async function convertToAnthropicMessagesPrompt({
1649
1658
  content: output.value,
1650
1659
  cache_control: cacheControl
1651
1660
  });
1652
- } else if (part.toolName === "code_execution") {
1661
+ } else if (providerToolName === "code_execution") {
1653
1662
  const output = part.output;
1654
1663
  if (output.type !== "json") {
1655
1664
  warnings.push({
@@ -1702,7 +1711,7 @@ async function convertToAnthropicMessagesPrompt({
1702
1711
  }
1703
1712
  break;
1704
1713
  }
1705
- if (part.toolName === "web_fetch") {
1714
+ if (providerToolName === "web_fetch") {
1706
1715
  const output = part.output;
1707
1716
  if (output.type !== "json") {
1708
1717
  warnings.push({
@@ -1737,7 +1746,7 @@ async function convertToAnthropicMessagesPrompt({
1737
1746
  });
1738
1747
  break;
1739
1748
  }
1740
- if (part.toolName === "web_search") {
1749
+ if (providerToolName === "web_search") {
1741
1750
  const output = part.output;
1742
1751
  if (output.type !== "json") {
1743
1752
  warnings.push({
@@ -1974,11 +1983,30 @@ var AnthropicMessagesLanguageModel = class {
1974
1983
  inputSchema: responseFormat.schema
1975
1984
  } : void 0;
1976
1985
  const cacheControlValidator = new CacheControlValidator();
1986
+ const toolNameMapping = (0, import_provider_utils11.createToolNameMapping)({
1987
+ tools,
1988
+ providerToolNames: {
1989
+ "anthropic.code_execution_20250522": "code_execution",
1990
+ "anthropic.code_execution_20250825": "code_execution",
1991
+ "anthropic.computer_20241022": "computer",
1992
+ "anthropic.computer_20250124": "computer",
1993
+ "anthropic.text_editor_20241022": "str_replace_editor",
1994
+ "anthropic.text_editor_20250124": "str_replace_editor",
1995
+ "anthropic.text_editor_20250429": "str_replace_based_edit_tool",
1996
+ "anthropic.text_editor_20250728": "str_replace_based_edit_tool",
1997
+ "anthropic.bash_20241022": "bash",
1998
+ "anthropic.bash_20250124": "bash",
1999
+ "anthropic.memory_20250818": "memory",
2000
+ "anthropic.web_search_20250305": "web_search",
2001
+ "anthropic.web_fetch_20250910": "web_fetch"
2002
+ }
2003
+ });
1977
2004
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
1978
2005
  prompt,
1979
2006
  sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
1980
2007
  warnings,
1981
- cacheControlValidator
2008
+ cacheControlValidator,
2009
+ toolNameMapping
1982
2010
  });
1983
2011
  const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
1984
2012
  const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
@@ -2130,7 +2158,8 @@ var AnthropicMessagesLanguageModel = class {
2130
2158
  },
2131
2159
  warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
2132
2160
  betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas]),
2133
- usesJsonResponseTool: jsonResponseTool != null
2161
+ usesJsonResponseTool: jsonResponseTool != null,
2162
+ toolNameMapping
2134
2163
  };
2135
2164
  }
2136
2165
  async getHeaders({
@@ -2188,7 +2217,7 @@ var AnthropicMessagesLanguageModel = class {
2188
2217
  }
2189
2218
  async doGenerate(options) {
2190
2219
  var _a, _b, _c, _d, _e, _f, _g, _h;
2191
- const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2220
+ const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
2192
2221
  ...options,
2193
2222
  stream: false,
2194
2223
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
@@ -2279,7 +2308,7 @@ var AnthropicMessagesLanguageModel = class {
2279
2308
  content.push({
2280
2309
  type: "tool-call",
2281
2310
  toolCallId: part.id,
2282
- toolName: "code_execution",
2311
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2283
2312
  input: JSON.stringify({ type: part.name, ...part.input }),
2284
2313
  providerExecuted: true
2285
2314
  });
@@ -2287,7 +2316,7 @@ var AnthropicMessagesLanguageModel = class {
2287
2316
  content.push({
2288
2317
  type: "tool-call",
2289
2318
  toolCallId: part.id,
2290
- toolName: part.name,
2319
+ toolName: toolNameMapping.toCustomToolName(part.name),
2291
2320
  input: JSON.stringify(part.input),
2292
2321
  providerExecuted: true
2293
2322
  });
@@ -2329,7 +2358,7 @@ var AnthropicMessagesLanguageModel = class {
2329
2358
  content.push({
2330
2359
  type: "tool-result",
2331
2360
  toolCallId: part.tool_use_id,
2332
- toolName: "web_fetch",
2361
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2333
2362
  result: {
2334
2363
  type: "web_fetch_result",
2335
2364
  url: part.content.url,
@@ -2350,7 +2379,7 @@ var AnthropicMessagesLanguageModel = class {
2350
2379
  content.push({
2351
2380
  type: "tool-result",
2352
2381
  toolCallId: part.tool_use_id,
2353
- toolName: "web_fetch",
2382
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2354
2383
  isError: true,
2355
2384
  result: {
2356
2385
  type: "web_fetch_tool_result_error",
@@ -2365,7 +2394,7 @@ var AnthropicMessagesLanguageModel = class {
2365
2394
  content.push({
2366
2395
  type: "tool-result",
2367
2396
  toolCallId: part.tool_use_id,
2368
- toolName: "web_search",
2397
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2369
2398
  result: part.content.map((result) => {
2370
2399
  var _a2;
2371
2400
  return {
@@ -2395,7 +2424,7 @@ var AnthropicMessagesLanguageModel = class {
2395
2424
  content.push({
2396
2425
  type: "tool-result",
2397
2426
  toolCallId: part.tool_use_id,
2398
- toolName: "web_search",
2427
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2399
2428
  isError: true,
2400
2429
  result: {
2401
2430
  type: "web_search_tool_result_error",
@@ -2411,7 +2440,7 @@ var AnthropicMessagesLanguageModel = class {
2411
2440
  content.push({
2412
2441
  type: "tool-result",
2413
2442
  toolCallId: part.tool_use_id,
2414
- toolName: "code_execution",
2443
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2415
2444
  result: {
2416
2445
  type: part.content.type,
2417
2446
  stdout: part.content.stdout,
@@ -2423,7 +2452,7 @@ var AnthropicMessagesLanguageModel = class {
2423
2452
  content.push({
2424
2453
  type: "tool-result",
2425
2454
  toolCallId: part.tool_use_id,
2426
- toolName: "code_execution",
2455
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2427
2456
  isError: true,
2428
2457
  result: {
2429
2458
  type: "code_execution_tool_result_error",
@@ -2439,7 +2468,7 @@ var AnthropicMessagesLanguageModel = class {
2439
2468
  content.push({
2440
2469
  type: "tool-result",
2441
2470
  toolCallId: part.tool_use_id,
2442
- toolName: "code_execution",
2471
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2443
2472
  result: part.content
2444
2473
  });
2445
2474
  break;
@@ -2490,7 +2519,8 @@ var AnthropicMessagesLanguageModel = class {
2490
2519
  args: body,
2491
2520
  warnings,
2492
2521
  betas,
2493
- usesJsonResponseTool
2522
+ usesJsonResponseTool,
2523
+ toolNameMapping
2494
2524
  } = await this.getArgs({
2495
2525
  ...options,
2496
2526
  stream: true,
@@ -2616,19 +2646,21 @@ var AnthropicMessagesLanguageModel = class {
2616
2646
  // code execution 20250825 bash:
2617
2647
  "bash_code_execution"
2618
2648
  ].includes(part.name)) {
2649
+ const providerToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2650
+ const customToolName = toolNameMapping.toCustomToolName(providerToolName);
2619
2651
  contentBlocks[value.index] = {
2620
2652
  type: "tool-call",
2621
2653
  toolCallId: part.id,
2622
- toolName: part.name,
2654
+ toolName: customToolName,
2623
2655
  input: "",
2624
2656
  providerExecuted: true,
2625
- firstDelta: true
2657
+ firstDelta: true,
2658
+ providerToolName: part.name
2626
2659
  };
2627
- const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2628
2660
  controller.enqueue({
2629
2661
  type: "tool-input-start",
2630
2662
  id: part.id,
2631
- toolName: mappedToolName,
2663
+ toolName: customToolName,
2632
2664
  providerExecuted: true
2633
2665
  });
2634
2666
  }
@@ -2639,7 +2671,7 @@ var AnthropicMessagesLanguageModel = class {
2639
2671
  controller.enqueue({
2640
2672
  type: "tool-result",
2641
2673
  toolCallId: part.tool_use_id,
2642
- toolName: "web_fetch",
2674
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2643
2675
  result: {
2644
2676
  type: "web_fetch_result",
2645
2677
  url: part.content.url,
@@ -2660,7 +2692,7 @@ var AnthropicMessagesLanguageModel = class {
2660
2692
  controller.enqueue({
2661
2693
  type: "tool-result",
2662
2694
  toolCallId: part.tool_use_id,
2663
- toolName: "web_fetch",
2695
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2664
2696
  isError: true,
2665
2697
  result: {
2666
2698
  type: "web_fetch_tool_result_error",
@@ -2675,7 +2707,7 @@ var AnthropicMessagesLanguageModel = class {
2675
2707
  controller.enqueue({
2676
2708
  type: "tool-result",
2677
2709
  toolCallId: part.tool_use_id,
2678
- toolName: "web_search",
2710
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2679
2711
  result: part.content.map((result) => {
2680
2712
  var _a3;
2681
2713
  return {
@@ -2705,7 +2737,7 @@ var AnthropicMessagesLanguageModel = class {
2705
2737
  controller.enqueue({
2706
2738
  type: "tool-result",
2707
2739
  toolCallId: part.tool_use_id,
2708
- toolName: "web_search",
2740
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2709
2741
  isError: true,
2710
2742
  result: {
2711
2743
  type: "web_search_tool_result_error",
@@ -2721,7 +2753,7 @@ var AnthropicMessagesLanguageModel = class {
2721
2753
  controller.enqueue({
2722
2754
  type: "tool-result",
2723
2755
  toolCallId: part.tool_use_id,
2724
- toolName: "code_execution",
2756
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2725
2757
  result: {
2726
2758
  type: part.content.type,
2727
2759
  stdout: part.content.stdout,
@@ -2733,7 +2765,7 @@ var AnthropicMessagesLanguageModel = class {
2733
2765
  controller.enqueue({
2734
2766
  type: "tool-result",
2735
2767
  toolCallId: part.tool_use_id,
2736
- toolName: "code_execution",
2768
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2737
2769
  isError: true,
2738
2770
  result: {
2739
2771
  type: "code_execution_tool_result_error",
@@ -2749,7 +2781,7 @@ var AnthropicMessagesLanguageModel = class {
2749
2781
  controller.enqueue({
2750
2782
  type: "tool-result",
2751
2783
  toolCallId: part.tool_use_id,
2752
- toolName: "code_execution",
2784
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2753
2785
  result: part.content
2754
2786
  });
2755
2787
  return;
@@ -2817,11 +2849,10 @@ var AnthropicMessagesLanguageModel = class {
2817
2849
  type: "tool-input-end",
2818
2850
  id: contentBlock.toolCallId
2819
2851
  });
2820
- const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
2821
2852
  controller.enqueue({
2822
2853
  type: "tool-call",
2823
2854
  toolCallId: contentBlock.toolCallId,
2824
- toolName,
2855
+ toolName: contentBlock.toolName,
2825
2856
  input: contentBlock.input === "" ? "{}" : contentBlock.input,
2826
2857
  providerExecuted: contentBlock.providerExecuted
2827
2858
  });
@@ -2889,8 +2920,8 @@ var AnthropicMessagesLanguageModel = class {
2889
2920
  if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
2890
2921
  return;
2891
2922
  }
2892
- if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
2893
- delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
2923
+ if (contentBlock.firstDelta && (contentBlock.providerToolName === "bash_code_execution" || contentBlock.providerToolName === "text_editor_code_execution")) {
2924
+ delta = `{"type": "${contentBlock.providerToolName}",${delta.substring(1)}`;
2894
2925
  }
2895
2926
  controller.enqueue({
2896
2927
  type: "tool-input-delta",