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

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.71" : "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,
@@ -861,7 +862,8 @@ async function prepareTools({
861
862
  tools,
862
863
  toolChoice,
863
864
  disableParallelToolUse,
864
- cacheControlValidator
865
+ cacheControlValidator,
866
+ supportsStructuredOutput
865
867
  }) {
866
868
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
867
869
  const toolWarnings = [];
@@ -882,7 +884,8 @@ async function prepareTools({
882
884
  name: tool.name,
883
885
  description: tool.description,
884
886
  input_schema: tool.inputSchema,
885
- cache_control: cacheControl
887
+ cache_control: cacheControl,
888
+ ...supportsStructuredOutput === true && tool.strict != null ? { strict: tool.strict } : {}
886
889
  });
887
890
  break;
888
891
  }
@@ -1257,7 +1260,8 @@ async function convertToAnthropicMessagesPrompt({
1257
1260
  prompt,
1258
1261
  sendReasoning,
1259
1262
  warnings,
1260
- cacheControlValidator
1263
+ cacheControlValidator,
1264
+ toolNameMapping
1261
1265
  }) {
1262
1266
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1263
1267
  const betas = /* @__PURE__ */ new Set();
@@ -1595,6 +1599,9 @@ async function convertToAnthropicMessagesPrompt({
1595
1599
  }
1596
1600
  case "tool-call": {
1597
1601
  if (part.providerExecuted) {
1602
+ const providerToolName = toolNameMapping.toProviderToolName(
1603
+ part.toolName
1604
+ );
1598
1605
  const isMcpToolUse = ((_h = (_g = part.providerOptions) == null ? void 0 : _g.anthropic) == null ? void 0 : _h.type) === "mcp-tool-use";
1599
1606
  if (isMcpToolUse) {
1600
1607
  mcpToolUseIds.add(part.toolCallId);
@@ -1616,7 +1623,7 @@ async function convertToAnthropicMessagesPrompt({
1616
1623
  });
1617
1624
  } else if (
1618
1625
  // 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")
1626
+ 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
1627
  ) {
1621
1628
  anthropicContent.push({
1622
1629
  type: "server_tool_use",
@@ -1626,20 +1633,22 @@ async function convertToAnthropicMessagesPrompt({
1626
1633
  input: part.input,
1627
1634
  cache_control: cacheControl
1628
1635
  });
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
1636
  } else {
1639
- warnings.push({
1640
- type: "other",
1641
- message: `provider executed tool call for tool ${part.toolName} is not supported`
1642
- });
1637
+ if (providerToolName === "code_execution" || // code execution 20250522
1638
+ providerToolName === "web_fetch" || providerToolName === "web_search") {
1639
+ anthropicContent.push({
1640
+ type: "server_tool_use",
1641
+ id: part.toolCallId,
1642
+ name: providerToolName,
1643
+ input: part.input,
1644
+ cache_control: cacheControl
1645
+ });
1646
+ } else {
1647
+ warnings.push({
1648
+ type: "other",
1649
+ message: `provider executed tool call for tool ${part.toolName} is not supported`
1650
+ });
1651
+ }
1643
1652
  }
1644
1653
  break;
1645
1654
  }
@@ -1653,6 +1662,9 @@ async function convertToAnthropicMessagesPrompt({
1653
1662
  break;
1654
1663
  }
1655
1664
  case "tool-result": {
1665
+ const providerToolName = toolNameMapping.toProviderToolName(
1666
+ part.toolName
1667
+ );
1656
1668
  if (mcpToolUseIds.has(part.toolCallId)) {
1657
1669
  const output = part.output;
1658
1670
  if (output.type !== "json" && output.type !== "error-json") {
@@ -1669,7 +1681,7 @@ async function convertToAnthropicMessagesPrompt({
1669
1681
  content: output.value,
1670
1682
  cache_control: cacheControl
1671
1683
  });
1672
- } else if (part.toolName === "code_execution") {
1684
+ } else if (providerToolName === "code_execution") {
1673
1685
  const output = part.output;
1674
1686
  if (output.type !== "json") {
1675
1687
  warnings.push({
@@ -1722,7 +1734,7 @@ async function convertToAnthropicMessagesPrompt({
1722
1734
  }
1723
1735
  break;
1724
1736
  }
1725
- if (part.toolName === "web_fetch") {
1737
+ if (providerToolName === "web_fetch") {
1726
1738
  const output = part.output;
1727
1739
  if (output.type !== "json") {
1728
1740
  warnings.push({
@@ -1757,7 +1769,7 @@ async function convertToAnthropicMessagesPrompt({
1757
1769
  });
1758
1770
  break;
1759
1771
  }
1760
- if (part.toolName === "web_search") {
1772
+ if (providerToolName === "web_search") {
1761
1773
  const output = part.output;
1762
1774
  if (output.type !== "json") {
1763
1775
  warnings.push({
@@ -1994,11 +2006,30 @@ var AnthropicMessagesLanguageModel = class {
1994
2006
  inputSchema: responseFormat.schema
1995
2007
  } : void 0;
1996
2008
  const cacheControlValidator = new CacheControlValidator();
2009
+ const toolNameMapping = createToolNameMapping({
2010
+ tools,
2011
+ providerToolNames: {
2012
+ "anthropic.code_execution_20250522": "code_execution",
2013
+ "anthropic.code_execution_20250825": "code_execution",
2014
+ "anthropic.computer_20241022": "computer",
2015
+ "anthropic.computer_20250124": "computer",
2016
+ "anthropic.text_editor_20241022": "str_replace_editor",
2017
+ "anthropic.text_editor_20250124": "str_replace_editor",
2018
+ "anthropic.text_editor_20250429": "str_replace_based_edit_tool",
2019
+ "anthropic.text_editor_20250728": "str_replace_based_edit_tool",
2020
+ "anthropic.bash_20241022": "bash",
2021
+ "anthropic.bash_20250124": "bash",
2022
+ "anthropic.memory_20250818": "memory",
2023
+ "anthropic.web_search_20250305": "web_search",
2024
+ "anthropic.web_fetch_20250910": "web_fetch"
2025
+ }
2026
+ });
1997
2027
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
1998
2028
  prompt,
1999
2029
  sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
2000
2030
  warnings,
2001
- cacheControlValidator
2031
+ cacheControlValidator,
2032
+ toolNameMapping
2002
2033
  });
2003
2034
  const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
2004
2035
  const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
@@ -2131,12 +2162,14 @@ var AnthropicMessagesLanguageModel = class {
2131
2162
  tools: [...tools != null ? tools : [], jsonResponseTool],
2132
2163
  toolChoice: { type: "required" },
2133
2164
  disableParallelToolUse: true,
2134
- cacheControlValidator
2165
+ cacheControlValidator,
2166
+ supportsStructuredOutput
2135
2167
  } : {
2136
2168
  tools: tools != null ? tools : [],
2137
2169
  toolChoice,
2138
2170
  disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
2139
- cacheControlValidator
2171
+ cacheControlValidator,
2172
+ supportsStructuredOutput
2140
2173
  }
2141
2174
  );
2142
2175
  const cacheWarnings = cacheControlValidator.getWarnings();
@@ -2150,7 +2183,8 @@ var AnthropicMessagesLanguageModel = class {
2150
2183
  },
2151
2184
  warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
2152
2185
  betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas]),
2153
- usesJsonResponseTool: jsonResponseTool != null
2186
+ usesJsonResponseTool: jsonResponseTool != null,
2187
+ toolNameMapping
2154
2188
  };
2155
2189
  }
2156
2190
  async getHeaders({
@@ -2208,7 +2242,7 @@ var AnthropicMessagesLanguageModel = class {
2208
2242
  }
2209
2243
  async doGenerate(options) {
2210
2244
  var _a, _b, _c, _d, _e, _f, _g, _h;
2211
- const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2245
+ const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
2212
2246
  ...options,
2213
2247
  stream: false,
2214
2248
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
@@ -2299,7 +2333,7 @@ var AnthropicMessagesLanguageModel = class {
2299
2333
  content.push({
2300
2334
  type: "tool-call",
2301
2335
  toolCallId: part.id,
2302
- toolName: "code_execution",
2336
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2303
2337
  input: JSON.stringify({ type: part.name, ...part.input }),
2304
2338
  providerExecuted: true
2305
2339
  });
@@ -2307,7 +2341,7 @@ var AnthropicMessagesLanguageModel = class {
2307
2341
  content.push({
2308
2342
  type: "tool-call",
2309
2343
  toolCallId: part.id,
2310
- toolName: part.name,
2344
+ toolName: toolNameMapping.toCustomToolName(part.name),
2311
2345
  input: JSON.stringify(part.input),
2312
2346
  providerExecuted: true
2313
2347
  });
@@ -2349,7 +2383,7 @@ var AnthropicMessagesLanguageModel = class {
2349
2383
  content.push({
2350
2384
  type: "tool-result",
2351
2385
  toolCallId: part.tool_use_id,
2352
- toolName: "web_fetch",
2386
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2353
2387
  result: {
2354
2388
  type: "web_fetch_result",
2355
2389
  url: part.content.url,
@@ -2370,7 +2404,7 @@ var AnthropicMessagesLanguageModel = class {
2370
2404
  content.push({
2371
2405
  type: "tool-result",
2372
2406
  toolCallId: part.tool_use_id,
2373
- toolName: "web_fetch",
2407
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2374
2408
  isError: true,
2375
2409
  result: {
2376
2410
  type: "web_fetch_tool_result_error",
@@ -2385,7 +2419,7 @@ var AnthropicMessagesLanguageModel = class {
2385
2419
  content.push({
2386
2420
  type: "tool-result",
2387
2421
  toolCallId: part.tool_use_id,
2388
- toolName: "web_search",
2422
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2389
2423
  result: part.content.map((result) => {
2390
2424
  var _a2;
2391
2425
  return {
@@ -2415,7 +2449,7 @@ var AnthropicMessagesLanguageModel = class {
2415
2449
  content.push({
2416
2450
  type: "tool-result",
2417
2451
  toolCallId: part.tool_use_id,
2418
- toolName: "web_search",
2452
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2419
2453
  isError: true,
2420
2454
  result: {
2421
2455
  type: "web_search_tool_result_error",
@@ -2431,7 +2465,7 @@ var AnthropicMessagesLanguageModel = class {
2431
2465
  content.push({
2432
2466
  type: "tool-result",
2433
2467
  toolCallId: part.tool_use_id,
2434
- toolName: "code_execution",
2468
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2435
2469
  result: {
2436
2470
  type: part.content.type,
2437
2471
  stdout: part.content.stdout,
@@ -2443,7 +2477,7 @@ var AnthropicMessagesLanguageModel = class {
2443
2477
  content.push({
2444
2478
  type: "tool-result",
2445
2479
  toolCallId: part.tool_use_id,
2446
- toolName: "code_execution",
2480
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2447
2481
  isError: true,
2448
2482
  result: {
2449
2483
  type: "code_execution_tool_result_error",
@@ -2459,7 +2493,7 @@ var AnthropicMessagesLanguageModel = class {
2459
2493
  content.push({
2460
2494
  type: "tool-result",
2461
2495
  toolCallId: part.tool_use_id,
2462
- toolName: "code_execution",
2496
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2463
2497
  result: part.content
2464
2498
  });
2465
2499
  break;
@@ -2510,7 +2544,8 @@ var AnthropicMessagesLanguageModel = class {
2510
2544
  args: body,
2511
2545
  warnings,
2512
2546
  betas,
2513
- usesJsonResponseTool
2547
+ usesJsonResponseTool,
2548
+ toolNameMapping
2514
2549
  } = await this.getArgs({
2515
2550
  ...options,
2516
2551
  stream: true,
@@ -2636,19 +2671,21 @@ var AnthropicMessagesLanguageModel = class {
2636
2671
  // code execution 20250825 bash:
2637
2672
  "bash_code_execution"
2638
2673
  ].includes(part.name)) {
2674
+ const providerToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2675
+ const customToolName = toolNameMapping.toCustomToolName(providerToolName);
2639
2676
  contentBlocks[value.index] = {
2640
2677
  type: "tool-call",
2641
2678
  toolCallId: part.id,
2642
- toolName: part.name,
2679
+ toolName: customToolName,
2643
2680
  input: "",
2644
2681
  providerExecuted: true,
2645
- firstDelta: true
2682
+ firstDelta: true,
2683
+ providerToolName: part.name
2646
2684
  };
2647
- const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2648
2685
  controller.enqueue({
2649
2686
  type: "tool-input-start",
2650
2687
  id: part.id,
2651
- toolName: mappedToolName,
2688
+ toolName: customToolName,
2652
2689
  providerExecuted: true
2653
2690
  });
2654
2691
  }
@@ -2659,7 +2696,7 @@ var AnthropicMessagesLanguageModel = class {
2659
2696
  controller.enqueue({
2660
2697
  type: "tool-result",
2661
2698
  toolCallId: part.tool_use_id,
2662
- toolName: "web_fetch",
2699
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2663
2700
  result: {
2664
2701
  type: "web_fetch_result",
2665
2702
  url: part.content.url,
@@ -2680,7 +2717,7 @@ var AnthropicMessagesLanguageModel = class {
2680
2717
  controller.enqueue({
2681
2718
  type: "tool-result",
2682
2719
  toolCallId: part.tool_use_id,
2683
- toolName: "web_fetch",
2720
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2684
2721
  isError: true,
2685
2722
  result: {
2686
2723
  type: "web_fetch_tool_result_error",
@@ -2695,7 +2732,7 @@ var AnthropicMessagesLanguageModel = class {
2695
2732
  controller.enqueue({
2696
2733
  type: "tool-result",
2697
2734
  toolCallId: part.tool_use_id,
2698
- toolName: "web_search",
2735
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2699
2736
  result: part.content.map((result) => {
2700
2737
  var _a3;
2701
2738
  return {
@@ -2725,7 +2762,7 @@ var AnthropicMessagesLanguageModel = class {
2725
2762
  controller.enqueue({
2726
2763
  type: "tool-result",
2727
2764
  toolCallId: part.tool_use_id,
2728
- toolName: "web_search",
2765
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2729
2766
  isError: true,
2730
2767
  result: {
2731
2768
  type: "web_search_tool_result_error",
@@ -2741,7 +2778,7 @@ var AnthropicMessagesLanguageModel = class {
2741
2778
  controller.enqueue({
2742
2779
  type: "tool-result",
2743
2780
  toolCallId: part.tool_use_id,
2744
- toolName: "code_execution",
2781
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2745
2782
  result: {
2746
2783
  type: part.content.type,
2747
2784
  stdout: part.content.stdout,
@@ -2753,7 +2790,7 @@ var AnthropicMessagesLanguageModel = class {
2753
2790
  controller.enqueue({
2754
2791
  type: "tool-result",
2755
2792
  toolCallId: part.tool_use_id,
2756
- toolName: "code_execution",
2793
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2757
2794
  isError: true,
2758
2795
  result: {
2759
2796
  type: "code_execution_tool_result_error",
@@ -2769,7 +2806,7 @@ var AnthropicMessagesLanguageModel = class {
2769
2806
  controller.enqueue({
2770
2807
  type: "tool-result",
2771
2808
  toolCallId: part.tool_use_id,
2772
- toolName: "code_execution",
2809
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2773
2810
  result: part.content
2774
2811
  });
2775
2812
  return;
@@ -2837,11 +2874,10 @@ var AnthropicMessagesLanguageModel = class {
2837
2874
  type: "tool-input-end",
2838
2875
  id: contentBlock.toolCallId
2839
2876
  });
2840
- const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
2841
2877
  controller.enqueue({
2842
2878
  type: "tool-call",
2843
2879
  toolCallId: contentBlock.toolCallId,
2844
- toolName,
2880
+ toolName: contentBlock.toolName,
2845
2881
  input: contentBlock.input === "" ? "{}" : contentBlock.input,
2846
2882
  providerExecuted: contentBlock.providerExecuted
2847
2883
  });
@@ -2909,8 +2945,8 @@ var AnthropicMessagesLanguageModel = class {
2909
2945
  if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
2910
2946
  return;
2911
2947
  }
2912
- if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
2913
- delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
2948
+ if (contentBlock.firstDelta && (contentBlock.providerToolName === "bash_code_execution" || contentBlock.providerToolName === "text_editor_code_execution")) {
2949
+ delta = `{"type": "${contentBlock.providerToolName}",${delta.substring(1)}`;
2914
2950
  }
2915
2951
  controller.enqueue({
2916
2952
  type: "tool-input-delta",