@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.
@@ -7,6 +7,7 @@ import {
7
7
  combineHeaders,
8
8
  createEventSourceResponseHandler,
9
9
  createJsonResponseHandler,
10
+ createToolNameMapping,
10
11
  generateId,
11
12
  parseProviderOptions as parseProviderOptions2,
12
13
  postJsonToApi,
@@ -846,7 +847,8 @@ async function prepareTools({
846
847
  tools,
847
848
  toolChoice,
848
849
  disableParallelToolUse,
849
- cacheControlValidator
850
+ cacheControlValidator,
851
+ supportsStructuredOutput
850
852
  }) {
851
853
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
852
854
  const toolWarnings = [];
@@ -867,7 +869,8 @@ async function prepareTools({
867
869
  name: tool.name,
868
870
  description: tool.description,
869
871
  input_schema: tool.inputSchema,
870
- cache_control: cacheControl
872
+ cache_control: cacheControl,
873
+ ...supportsStructuredOutput === true && tool.strict != null ? { strict: tool.strict } : {}
871
874
  });
872
875
  break;
873
876
  }
@@ -1242,7 +1245,8 @@ async function convertToAnthropicMessagesPrompt({
1242
1245
  prompt,
1243
1246
  sendReasoning,
1244
1247
  warnings,
1245
- cacheControlValidator
1248
+ cacheControlValidator,
1249
+ toolNameMapping
1246
1250
  }) {
1247
1251
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1248
1252
  const betas = /* @__PURE__ */ new Set();
@@ -1580,6 +1584,9 @@ async function convertToAnthropicMessagesPrompt({
1580
1584
  }
1581
1585
  case "tool-call": {
1582
1586
  if (part.providerExecuted) {
1587
+ const providerToolName = toolNameMapping.toProviderToolName(
1588
+ part.toolName
1589
+ );
1583
1590
  const isMcpToolUse = ((_h = (_g = part.providerOptions) == null ? void 0 : _g.anthropic) == null ? void 0 : _h.type) === "mcp-tool-use";
1584
1591
  if (isMcpToolUse) {
1585
1592
  mcpToolUseIds.add(part.toolCallId);
@@ -1601,7 +1608,7 @@ async function convertToAnthropicMessagesPrompt({
1601
1608
  });
1602
1609
  } else if (
1603
1610
  // code execution 20250825:
1604
- 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")
1611
+ 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")
1605
1612
  ) {
1606
1613
  anthropicContent.push({
1607
1614
  type: "server_tool_use",
@@ -1611,20 +1618,22 @@ async function convertToAnthropicMessagesPrompt({
1611
1618
  input: part.input,
1612
1619
  cache_control: cacheControl
1613
1620
  });
1614
- } else if (part.toolName === "code_execution" || // code execution 20250522
1615
- part.toolName === "web_fetch" || part.toolName === "web_search") {
1616
- anthropicContent.push({
1617
- type: "server_tool_use",
1618
- id: part.toolCallId,
1619
- name: part.toolName,
1620
- input: part.input,
1621
- cache_control: cacheControl
1622
- });
1623
1621
  } else {
1624
- warnings.push({
1625
- type: "other",
1626
- message: `provider executed tool call for tool ${part.toolName} is not supported`
1627
- });
1622
+ if (providerToolName === "code_execution" || // code execution 20250522
1623
+ providerToolName === "web_fetch" || providerToolName === "web_search") {
1624
+ anthropicContent.push({
1625
+ type: "server_tool_use",
1626
+ id: part.toolCallId,
1627
+ name: providerToolName,
1628
+ input: part.input,
1629
+ cache_control: cacheControl
1630
+ });
1631
+ } else {
1632
+ warnings.push({
1633
+ type: "other",
1634
+ message: `provider executed tool call for tool ${part.toolName} is not supported`
1635
+ });
1636
+ }
1628
1637
  }
1629
1638
  break;
1630
1639
  }
@@ -1638,6 +1647,9 @@ async function convertToAnthropicMessagesPrompt({
1638
1647
  break;
1639
1648
  }
1640
1649
  case "tool-result": {
1650
+ const providerToolName = toolNameMapping.toProviderToolName(
1651
+ part.toolName
1652
+ );
1641
1653
  if (mcpToolUseIds.has(part.toolCallId)) {
1642
1654
  const output = part.output;
1643
1655
  if (output.type !== "json" && output.type !== "error-json") {
@@ -1654,7 +1666,7 @@ async function convertToAnthropicMessagesPrompt({
1654
1666
  content: output.value,
1655
1667
  cache_control: cacheControl
1656
1668
  });
1657
- } else if (part.toolName === "code_execution") {
1669
+ } else if (providerToolName === "code_execution") {
1658
1670
  const output = part.output;
1659
1671
  if (output.type !== "json") {
1660
1672
  warnings.push({
@@ -1707,7 +1719,7 @@ async function convertToAnthropicMessagesPrompt({
1707
1719
  }
1708
1720
  break;
1709
1721
  }
1710
- if (part.toolName === "web_fetch") {
1722
+ if (providerToolName === "web_fetch") {
1711
1723
  const output = part.output;
1712
1724
  if (output.type !== "json") {
1713
1725
  warnings.push({
@@ -1742,7 +1754,7 @@ async function convertToAnthropicMessagesPrompt({
1742
1754
  });
1743
1755
  break;
1744
1756
  }
1745
- if (part.toolName === "web_search") {
1757
+ if (providerToolName === "web_search") {
1746
1758
  const output = part.output;
1747
1759
  if (output.type !== "json") {
1748
1760
  warnings.push({
@@ -1979,11 +1991,30 @@ var AnthropicMessagesLanguageModel = class {
1979
1991
  inputSchema: responseFormat.schema
1980
1992
  } : void 0;
1981
1993
  const cacheControlValidator = new CacheControlValidator();
1994
+ const toolNameMapping = createToolNameMapping({
1995
+ tools,
1996
+ providerToolNames: {
1997
+ "anthropic.code_execution_20250522": "code_execution",
1998
+ "anthropic.code_execution_20250825": "code_execution",
1999
+ "anthropic.computer_20241022": "computer",
2000
+ "anthropic.computer_20250124": "computer",
2001
+ "anthropic.text_editor_20241022": "str_replace_editor",
2002
+ "anthropic.text_editor_20250124": "str_replace_editor",
2003
+ "anthropic.text_editor_20250429": "str_replace_based_edit_tool",
2004
+ "anthropic.text_editor_20250728": "str_replace_based_edit_tool",
2005
+ "anthropic.bash_20241022": "bash",
2006
+ "anthropic.bash_20250124": "bash",
2007
+ "anthropic.memory_20250818": "memory",
2008
+ "anthropic.web_search_20250305": "web_search",
2009
+ "anthropic.web_fetch_20250910": "web_fetch"
2010
+ }
2011
+ });
1982
2012
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
1983
2013
  prompt,
1984
2014
  sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
1985
2015
  warnings,
1986
- cacheControlValidator
2016
+ cacheControlValidator,
2017
+ toolNameMapping
1987
2018
  });
1988
2019
  const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
1989
2020
  const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
@@ -2116,12 +2147,14 @@ var AnthropicMessagesLanguageModel = class {
2116
2147
  tools: [...tools != null ? tools : [], jsonResponseTool],
2117
2148
  toolChoice: { type: "required" },
2118
2149
  disableParallelToolUse: true,
2119
- cacheControlValidator
2150
+ cacheControlValidator,
2151
+ supportsStructuredOutput
2120
2152
  } : {
2121
2153
  tools: tools != null ? tools : [],
2122
2154
  toolChoice,
2123
2155
  disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
2124
- cacheControlValidator
2156
+ cacheControlValidator,
2157
+ supportsStructuredOutput
2125
2158
  }
2126
2159
  );
2127
2160
  const cacheWarnings = cacheControlValidator.getWarnings();
@@ -2135,7 +2168,8 @@ var AnthropicMessagesLanguageModel = class {
2135
2168
  },
2136
2169
  warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
2137
2170
  betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas]),
2138
- usesJsonResponseTool: jsonResponseTool != null
2171
+ usesJsonResponseTool: jsonResponseTool != null,
2172
+ toolNameMapping
2139
2173
  };
2140
2174
  }
2141
2175
  async getHeaders({
@@ -2193,7 +2227,7 @@ var AnthropicMessagesLanguageModel = class {
2193
2227
  }
2194
2228
  async doGenerate(options) {
2195
2229
  var _a, _b, _c, _d, _e, _f, _g, _h;
2196
- const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2230
+ const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
2197
2231
  ...options,
2198
2232
  stream: false,
2199
2233
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
@@ -2284,7 +2318,7 @@ var AnthropicMessagesLanguageModel = class {
2284
2318
  content.push({
2285
2319
  type: "tool-call",
2286
2320
  toolCallId: part.id,
2287
- toolName: "code_execution",
2321
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2288
2322
  input: JSON.stringify({ type: part.name, ...part.input }),
2289
2323
  providerExecuted: true
2290
2324
  });
@@ -2292,7 +2326,7 @@ var AnthropicMessagesLanguageModel = class {
2292
2326
  content.push({
2293
2327
  type: "tool-call",
2294
2328
  toolCallId: part.id,
2295
- toolName: part.name,
2329
+ toolName: toolNameMapping.toCustomToolName(part.name),
2296
2330
  input: JSON.stringify(part.input),
2297
2331
  providerExecuted: true
2298
2332
  });
@@ -2334,7 +2368,7 @@ var AnthropicMessagesLanguageModel = class {
2334
2368
  content.push({
2335
2369
  type: "tool-result",
2336
2370
  toolCallId: part.tool_use_id,
2337
- toolName: "web_fetch",
2371
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2338
2372
  result: {
2339
2373
  type: "web_fetch_result",
2340
2374
  url: part.content.url,
@@ -2355,7 +2389,7 @@ var AnthropicMessagesLanguageModel = class {
2355
2389
  content.push({
2356
2390
  type: "tool-result",
2357
2391
  toolCallId: part.tool_use_id,
2358
- toolName: "web_fetch",
2392
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2359
2393
  isError: true,
2360
2394
  result: {
2361
2395
  type: "web_fetch_tool_result_error",
@@ -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_search",
2407
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2374
2408
  result: part.content.map((result) => {
2375
2409
  var _a2;
2376
2410
  return {
@@ -2400,7 +2434,7 @@ var AnthropicMessagesLanguageModel = class {
2400
2434
  content.push({
2401
2435
  type: "tool-result",
2402
2436
  toolCallId: part.tool_use_id,
2403
- toolName: "web_search",
2437
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2404
2438
  isError: true,
2405
2439
  result: {
2406
2440
  type: "web_search_tool_result_error",
@@ -2416,7 +2450,7 @@ var AnthropicMessagesLanguageModel = class {
2416
2450
  content.push({
2417
2451
  type: "tool-result",
2418
2452
  toolCallId: part.tool_use_id,
2419
- toolName: "code_execution",
2453
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2420
2454
  result: {
2421
2455
  type: part.content.type,
2422
2456
  stdout: part.content.stdout,
@@ -2428,7 +2462,7 @@ var AnthropicMessagesLanguageModel = class {
2428
2462
  content.push({
2429
2463
  type: "tool-result",
2430
2464
  toolCallId: part.tool_use_id,
2431
- toolName: "code_execution",
2465
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2432
2466
  isError: true,
2433
2467
  result: {
2434
2468
  type: "code_execution_tool_result_error",
@@ -2444,7 +2478,7 @@ var AnthropicMessagesLanguageModel = class {
2444
2478
  content.push({
2445
2479
  type: "tool-result",
2446
2480
  toolCallId: part.tool_use_id,
2447
- toolName: "code_execution",
2481
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2448
2482
  result: part.content
2449
2483
  });
2450
2484
  break;
@@ -2495,7 +2529,8 @@ var AnthropicMessagesLanguageModel = class {
2495
2529
  args: body,
2496
2530
  warnings,
2497
2531
  betas,
2498
- usesJsonResponseTool
2532
+ usesJsonResponseTool,
2533
+ toolNameMapping
2499
2534
  } = await this.getArgs({
2500
2535
  ...options,
2501
2536
  stream: true,
@@ -2621,19 +2656,21 @@ var AnthropicMessagesLanguageModel = class {
2621
2656
  // code execution 20250825 bash:
2622
2657
  "bash_code_execution"
2623
2658
  ].includes(part.name)) {
2659
+ const providerToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2660
+ const customToolName = toolNameMapping.toCustomToolName(providerToolName);
2624
2661
  contentBlocks[value.index] = {
2625
2662
  type: "tool-call",
2626
2663
  toolCallId: part.id,
2627
- toolName: part.name,
2664
+ toolName: customToolName,
2628
2665
  input: "",
2629
2666
  providerExecuted: true,
2630
- firstDelta: true
2667
+ firstDelta: true,
2668
+ providerToolName: part.name
2631
2669
  };
2632
- const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2633
2670
  controller.enqueue({
2634
2671
  type: "tool-input-start",
2635
2672
  id: part.id,
2636
- toolName: mappedToolName,
2673
+ toolName: customToolName,
2637
2674
  providerExecuted: true
2638
2675
  });
2639
2676
  }
@@ -2644,7 +2681,7 @@ var AnthropicMessagesLanguageModel = class {
2644
2681
  controller.enqueue({
2645
2682
  type: "tool-result",
2646
2683
  toolCallId: part.tool_use_id,
2647
- toolName: "web_fetch",
2684
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2648
2685
  result: {
2649
2686
  type: "web_fetch_result",
2650
2687
  url: part.content.url,
@@ -2665,7 +2702,7 @@ var AnthropicMessagesLanguageModel = class {
2665
2702
  controller.enqueue({
2666
2703
  type: "tool-result",
2667
2704
  toolCallId: part.tool_use_id,
2668
- toolName: "web_fetch",
2705
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2669
2706
  isError: true,
2670
2707
  result: {
2671
2708
  type: "web_fetch_tool_result_error",
@@ -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_search",
2720
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2684
2721
  result: part.content.map((result) => {
2685
2722
  var _a3;
2686
2723
  return {
@@ -2710,7 +2747,7 @@ var AnthropicMessagesLanguageModel = class {
2710
2747
  controller.enqueue({
2711
2748
  type: "tool-result",
2712
2749
  toolCallId: part.tool_use_id,
2713
- toolName: "web_search",
2750
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2714
2751
  isError: true,
2715
2752
  result: {
2716
2753
  type: "web_search_tool_result_error",
@@ -2726,7 +2763,7 @@ var AnthropicMessagesLanguageModel = class {
2726
2763
  controller.enqueue({
2727
2764
  type: "tool-result",
2728
2765
  toolCallId: part.tool_use_id,
2729
- toolName: "code_execution",
2766
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2730
2767
  result: {
2731
2768
  type: part.content.type,
2732
2769
  stdout: part.content.stdout,
@@ -2738,7 +2775,7 @@ var AnthropicMessagesLanguageModel = class {
2738
2775
  controller.enqueue({
2739
2776
  type: "tool-result",
2740
2777
  toolCallId: part.tool_use_id,
2741
- toolName: "code_execution",
2778
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2742
2779
  isError: true,
2743
2780
  result: {
2744
2781
  type: "code_execution_tool_result_error",
@@ -2754,7 +2791,7 @@ var AnthropicMessagesLanguageModel = class {
2754
2791
  controller.enqueue({
2755
2792
  type: "tool-result",
2756
2793
  toolCallId: part.tool_use_id,
2757
- toolName: "code_execution",
2794
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2758
2795
  result: part.content
2759
2796
  });
2760
2797
  return;
@@ -2822,11 +2859,10 @@ var AnthropicMessagesLanguageModel = class {
2822
2859
  type: "tool-input-end",
2823
2860
  id: contentBlock.toolCallId
2824
2861
  });
2825
- const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
2826
2862
  controller.enqueue({
2827
2863
  type: "tool-call",
2828
2864
  toolCallId: contentBlock.toolCallId,
2829
- toolName,
2865
+ toolName: contentBlock.toolName,
2830
2866
  input: contentBlock.input === "" ? "{}" : contentBlock.input,
2831
2867
  providerExecuted: contentBlock.providerExecuted
2832
2868
  });
@@ -2894,8 +2930,8 @@ var AnthropicMessagesLanguageModel = class {
2894
2930
  if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
2895
2931
  return;
2896
2932
  }
2897
- if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
2898
- delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
2933
+ if (contentBlock.firstDelta && (contentBlock.providerToolName === "bash_code_execution" || contentBlock.providerToolName === "text_editor_code_execution")) {
2934
+ delta = `{"type": "${contentBlock.providerToolName}",${delta.substring(1)}`;
2899
2935
  }
2900
2936
  controller.enqueue({
2901
2937
  type: "tool-input-delta",