@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.
@@ -479,6 +479,7 @@ type AnthropicTool = {
479
479
  description: string | undefined;
480
480
  input_schema: JSONSchema7;
481
481
  cache_control: AnthropicCacheControl | undefined;
482
+ strict?: boolean;
482
483
  } | {
483
484
  type: 'code_execution_20250522';
484
485
  name: string;
@@ -554,11 +555,15 @@ declare class CacheControlValidator {
554
555
  getWarnings(): SharedV3Warning[];
555
556
  }
556
557
 
557
- declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, }: {
558
+ declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, }: {
558
559
  tools: LanguageModelV3CallOptions['tools'];
559
- toolChoice?: LanguageModelV3CallOptions['toolChoice'];
560
+ toolChoice: LanguageModelV3CallOptions['toolChoice'] | undefined;
560
561
  disableParallelToolUse?: boolean;
561
562
  cacheControlValidator?: CacheControlValidator;
563
+ /**
564
+ * Whether the model supports structured output.
565
+ */
566
+ supportsStructuredOutput: boolean;
562
567
  }): Promise<{
563
568
  tools: Array<AnthropicTool> | undefined;
564
569
  toolChoice: AnthropicToolChoice | undefined;
@@ -479,6 +479,7 @@ type AnthropicTool = {
479
479
  description: string | undefined;
480
480
  input_schema: JSONSchema7;
481
481
  cache_control: AnthropicCacheControl | undefined;
482
+ strict?: boolean;
482
483
  } | {
483
484
  type: 'code_execution_20250522';
484
485
  name: string;
@@ -554,11 +555,15 @@ declare class CacheControlValidator {
554
555
  getWarnings(): SharedV3Warning[];
555
556
  }
556
557
 
557
- declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, }: {
558
+ declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, }: {
558
559
  tools: LanguageModelV3CallOptions['tools'];
559
- toolChoice?: LanguageModelV3CallOptions['toolChoice'];
560
+ toolChoice: LanguageModelV3CallOptions['toolChoice'] | undefined;
560
561
  disableParallelToolUse?: boolean;
561
562
  cacheControlValidator?: CacheControlValidator;
563
+ /**
564
+ * Whether the model supports structured output.
565
+ */
566
+ supportsStructuredOutput: boolean;
562
567
  }): Promise<{
563
568
  tools: Array<AnthropicTool> | undefined;
564
569
  toolChoice: AnthropicToolChoice | undefined;
@@ -849,7 +849,8 @@ async function prepareTools({
849
849
  tools,
850
850
  toolChoice,
851
851
  disableParallelToolUse,
852
- cacheControlValidator
852
+ cacheControlValidator,
853
+ supportsStructuredOutput
853
854
  }) {
854
855
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
855
856
  const toolWarnings = [];
@@ -870,7 +871,8 @@ async function prepareTools({
870
871
  name: tool.name,
871
872
  description: tool.description,
872
873
  input_schema: tool.inputSchema,
873
- cache_control: cacheControl
874
+ cache_control: cacheControl,
875
+ ...supportsStructuredOutput === true && tool.strict != null ? { strict: tool.strict } : {}
874
876
  });
875
877
  break;
876
878
  }
@@ -1230,7 +1232,8 @@ async function convertToAnthropicMessagesPrompt({
1230
1232
  prompt,
1231
1233
  sendReasoning,
1232
1234
  warnings,
1233
- cacheControlValidator
1235
+ cacheControlValidator,
1236
+ toolNameMapping
1234
1237
  }) {
1235
1238
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1236
1239
  const betas = /* @__PURE__ */ new Set();
@@ -1568,6 +1571,9 @@ async function convertToAnthropicMessagesPrompt({
1568
1571
  }
1569
1572
  case "tool-call": {
1570
1573
  if (part.providerExecuted) {
1574
+ const providerToolName = toolNameMapping.toProviderToolName(
1575
+ part.toolName
1576
+ );
1571
1577
  const isMcpToolUse = ((_h = (_g = part.providerOptions) == null ? void 0 : _g.anthropic) == null ? void 0 : _h.type) === "mcp-tool-use";
1572
1578
  if (isMcpToolUse) {
1573
1579
  mcpToolUseIds.add(part.toolCallId);
@@ -1589,7 +1595,7 @@ async function convertToAnthropicMessagesPrompt({
1589
1595
  });
1590
1596
  } else if (
1591
1597
  // 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")
1598
+ 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
1599
  ) {
1594
1600
  anthropicContent.push({
1595
1601
  type: "server_tool_use",
@@ -1599,20 +1605,22 @@ async function convertToAnthropicMessagesPrompt({
1599
1605
  input: part.input,
1600
1606
  cache_control: cacheControl
1601
1607
  });
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
1608
  } else {
1612
- warnings.push({
1613
- type: "other",
1614
- message: `provider executed tool call for tool ${part.toolName} is not supported`
1615
- });
1609
+ if (providerToolName === "code_execution" || // code execution 20250522
1610
+ providerToolName === "web_fetch" || providerToolName === "web_search") {
1611
+ anthropicContent.push({
1612
+ type: "server_tool_use",
1613
+ id: part.toolCallId,
1614
+ name: providerToolName,
1615
+ input: part.input,
1616
+ cache_control: cacheControl
1617
+ });
1618
+ } else {
1619
+ warnings.push({
1620
+ type: "other",
1621
+ message: `provider executed tool call for tool ${part.toolName} is not supported`
1622
+ });
1623
+ }
1616
1624
  }
1617
1625
  break;
1618
1626
  }
@@ -1626,6 +1634,9 @@ async function convertToAnthropicMessagesPrompt({
1626
1634
  break;
1627
1635
  }
1628
1636
  case "tool-result": {
1637
+ const providerToolName = toolNameMapping.toProviderToolName(
1638
+ part.toolName
1639
+ );
1629
1640
  if (mcpToolUseIds.has(part.toolCallId)) {
1630
1641
  const output = part.output;
1631
1642
  if (output.type !== "json" && output.type !== "error-json") {
@@ -1642,7 +1653,7 @@ async function convertToAnthropicMessagesPrompt({
1642
1653
  content: output.value,
1643
1654
  cache_control: cacheControl
1644
1655
  });
1645
- } else if (part.toolName === "code_execution") {
1656
+ } else if (providerToolName === "code_execution") {
1646
1657
  const output = part.output;
1647
1658
  if (output.type !== "json") {
1648
1659
  warnings.push({
@@ -1695,7 +1706,7 @@ async function convertToAnthropicMessagesPrompt({
1695
1706
  }
1696
1707
  break;
1697
1708
  }
1698
- if (part.toolName === "web_fetch") {
1709
+ if (providerToolName === "web_fetch") {
1699
1710
  const output = part.output;
1700
1711
  if (output.type !== "json") {
1701
1712
  warnings.push({
@@ -1730,7 +1741,7 @@ async function convertToAnthropicMessagesPrompt({
1730
1741
  });
1731
1742
  break;
1732
1743
  }
1733
- if (part.toolName === "web_search") {
1744
+ if (providerToolName === "web_search") {
1734
1745
  const output = part.output;
1735
1746
  if (output.type !== "json") {
1736
1747
  warnings.push({
@@ -1967,11 +1978,30 @@ var AnthropicMessagesLanguageModel = class {
1967
1978
  inputSchema: responseFormat.schema
1968
1979
  } : void 0;
1969
1980
  const cacheControlValidator = new CacheControlValidator();
1981
+ const toolNameMapping = (0, import_provider_utils11.createToolNameMapping)({
1982
+ tools,
1983
+ providerToolNames: {
1984
+ "anthropic.code_execution_20250522": "code_execution",
1985
+ "anthropic.code_execution_20250825": "code_execution",
1986
+ "anthropic.computer_20241022": "computer",
1987
+ "anthropic.computer_20250124": "computer",
1988
+ "anthropic.text_editor_20241022": "str_replace_editor",
1989
+ "anthropic.text_editor_20250124": "str_replace_editor",
1990
+ "anthropic.text_editor_20250429": "str_replace_based_edit_tool",
1991
+ "anthropic.text_editor_20250728": "str_replace_based_edit_tool",
1992
+ "anthropic.bash_20241022": "bash",
1993
+ "anthropic.bash_20250124": "bash",
1994
+ "anthropic.memory_20250818": "memory",
1995
+ "anthropic.web_search_20250305": "web_search",
1996
+ "anthropic.web_fetch_20250910": "web_fetch"
1997
+ }
1998
+ });
1970
1999
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
1971
2000
  prompt,
1972
2001
  sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
1973
2002
  warnings,
1974
- cacheControlValidator
2003
+ cacheControlValidator,
2004
+ toolNameMapping
1975
2005
  });
1976
2006
  const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
1977
2007
  const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
@@ -2104,12 +2134,14 @@ var AnthropicMessagesLanguageModel = class {
2104
2134
  tools: [...tools != null ? tools : [], jsonResponseTool],
2105
2135
  toolChoice: { type: "required" },
2106
2136
  disableParallelToolUse: true,
2107
- cacheControlValidator
2137
+ cacheControlValidator,
2138
+ supportsStructuredOutput
2108
2139
  } : {
2109
2140
  tools: tools != null ? tools : [],
2110
2141
  toolChoice,
2111
2142
  disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
2112
- cacheControlValidator
2143
+ cacheControlValidator,
2144
+ supportsStructuredOutput
2113
2145
  }
2114
2146
  );
2115
2147
  const cacheWarnings = cacheControlValidator.getWarnings();
@@ -2123,7 +2155,8 @@ var AnthropicMessagesLanguageModel = class {
2123
2155
  },
2124
2156
  warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
2125
2157
  betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas]),
2126
- usesJsonResponseTool: jsonResponseTool != null
2158
+ usesJsonResponseTool: jsonResponseTool != null,
2159
+ toolNameMapping
2127
2160
  };
2128
2161
  }
2129
2162
  async getHeaders({
@@ -2181,7 +2214,7 @@ var AnthropicMessagesLanguageModel = class {
2181
2214
  }
2182
2215
  async doGenerate(options) {
2183
2216
  var _a, _b, _c, _d, _e, _f, _g, _h;
2184
- const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2217
+ const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
2185
2218
  ...options,
2186
2219
  stream: false,
2187
2220
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
@@ -2272,7 +2305,7 @@ var AnthropicMessagesLanguageModel = class {
2272
2305
  content.push({
2273
2306
  type: "tool-call",
2274
2307
  toolCallId: part.id,
2275
- toolName: "code_execution",
2308
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2276
2309
  input: JSON.stringify({ type: part.name, ...part.input }),
2277
2310
  providerExecuted: true
2278
2311
  });
@@ -2280,7 +2313,7 @@ var AnthropicMessagesLanguageModel = class {
2280
2313
  content.push({
2281
2314
  type: "tool-call",
2282
2315
  toolCallId: part.id,
2283
- toolName: part.name,
2316
+ toolName: toolNameMapping.toCustomToolName(part.name),
2284
2317
  input: JSON.stringify(part.input),
2285
2318
  providerExecuted: true
2286
2319
  });
@@ -2322,7 +2355,7 @@ var AnthropicMessagesLanguageModel = class {
2322
2355
  content.push({
2323
2356
  type: "tool-result",
2324
2357
  toolCallId: part.tool_use_id,
2325
- toolName: "web_fetch",
2358
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2326
2359
  result: {
2327
2360
  type: "web_fetch_result",
2328
2361
  url: part.content.url,
@@ -2343,7 +2376,7 @@ var AnthropicMessagesLanguageModel = class {
2343
2376
  content.push({
2344
2377
  type: "tool-result",
2345
2378
  toolCallId: part.tool_use_id,
2346
- toolName: "web_fetch",
2379
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2347
2380
  isError: true,
2348
2381
  result: {
2349
2382
  type: "web_fetch_tool_result_error",
@@ -2358,7 +2391,7 @@ var AnthropicMessagesLanguageModel = class {
2358
2391
  content.push({
2359
2392
  type: "tool-result",
2360
2393
  toolCallId: part.tool_use_id,
2361
- toolName: "web_search",
2394
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2362
2395
  result: part.content.map((result) => {
2363
2396
  var _a2;
2364
2397
  return {
@@ -2388,7 +2421,7 @@ var AnthropicMessagesLanguageModel = class {
2388
2421
  content.push({
2389
2422
  type: "tool-result",
2390
2423
  toolCallId: part.tool_use_id,
2391
- toolName: "web_search",
2424
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2392
2425
  isError: true,
2393
2426
  result: {
2394
2427
  type: "web_search_tool_result_error",
@@ -2404,7 +2437,7 @@ var AnthropicMessagesLanguageModel = class {
2404
2437
  content.push({
2405
2438
  type: "tool-result",
2406
2439
  toolCallId: part.tool_use_id,
2407
- toolName: "code_execution",
2440
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2408
2441
  result: {
2409
2442
  type: part.content.type,
2410
2443
  stdout: part.content.stdout,
@@ -2416,7 +2449,7 @@ var AnthropicMessagesLanguageModel = class {
2416
2449
  content.push({
2417
2450
  type: "tool-result",
2418
2451
  toolCallId: part.tool_use_id,
2419
- toolName: "code_execution",
2452
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2420
2453
  isError: true,
2421
2454
  result: {
2422
2455
  type: "code_execution_tool_result_error",
@@ -2432,7 +2465,7 @@ var AnthropicMessagesLanguageModel = class {
2432
2465
  content.push({
2433
2466
  type: "tool-result",
2434
2467
  toolCallId: part.tool_use_id,
2435
- toolName: "code_execution",
2468
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2436
2469
  result: part.content
2437
2470
  });
2438
2471
  break;
@@ -2483,7 +2516,8 @@ var AnthropicMessagesLanguageModel = class {
2483
2516
  args: body,
2484
2517
  warnings,
2485
2518
  betas,
2486
- usesJsonResponseTool
2519
+ usesJsonResponseTool,
2520
+ toolNameMapping
2487
2521
  } = await this.getArgs({
2488
2522
  ...options,
2489
2523
  stream: true,
@@ -2609,19 +2643,21 @@ var AnthropicMessagesLanguageModel = class {
2609
2643
  // code execution 20250825 bash:
2610
2644
  "bash_code_execution"
2611
2645
  ].includes(part.name)) {
2646
+ const providerToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2647
+ const customToolName = toolNameMapping.toCustomToolName(providerToolName);
2612
2648
  contentBlocks[value.index] = {
2613
2649
  type: "tool-call",
2614
2650
  toolCallId: part.id,
2615
- toolName: part.name,
2651
+ toolName: customToolName,
2616
2652
  input: "",
2617
2653
  providerExecuted: true,
2618
- firstDelta: true
2654
+ firstDelta: true,
2655
+ providerToolName: part.name
2619
2656
  };
2620
- const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
2621
2657
  controller.enqueue({
2622
2658
  type: "tool-input-start",
2623
2659
  id: part.id,
2624
- toolName: mappedToolName,
2660
+ toolName: customToolName,
2625
2661
  providerExecuted: true
2626
2662
  });
2627
2663
  }
@@ -2632,7 +2668,7 @@ var AnthropicMessagesLanguageModel = class {
2632
2668
  controller.enqueue({
2633
2669
  type: "tool-result",
2634
2670
  toolCallId: part.tool_use_id,
2635
- toolName: "web_fetch",
2671
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2636
2672
  result: {
2637
2673
  type: "web_fetch_result",
2638
2674
  url: part.content.url,
@@ -2653,7 +2689,7 @@ var AnthropicMessagesLanguageModel = class {
2653
2689
  controller.enqueue({
2654
2690
  type: "tool-result",
2655
2691
  toolCallId: part.tool_use_id,
2656
- toolName: "web_fetch",
2692
+ toolName: toolNameMapping.toCustomToolName("web_fetch"),
2657
2693
  isError: true,
2658
2694
  result: {
2659
2695
  type: "web_fetch_tool_result_error",
@@ -2668,7 +2704,7 @@ var AnthropicMessagesLanguageModel = class {
2668
2704
  controller.enqueue({
2669
2705
  type: "tool-result",
2670
2706
  toolCallId: part.tool_use_id,
2671
- toolName: "web_search",
2707
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2672
2708
  result: part.content.map((result) => {
2673
2709
  var _a3;
2674
2710
  return {
@@ -2698,7 +2734,7 @@ var AnthropicMessagesLanguageModel = class {
2698
2734
  controller.enqueue({
2699
2735
  type: "tool-result",
2700
2736
  toolCallId: part.tool_use_id,
2701
- toolName: "web_search",
2737
+ toolName: toolNameMapping.toCustomToolName("web_search"),
2702
2738
  isError: true,
2703
2739
  result: {
2704
2740
  type: "web_search_tool_result_error",
@@ -2714,7 +2750,7 @@ var AnthropicMessagesLanguageModel = class {
2714
2750
  controller.enqueue({
2715
2751
  type: "tool-result",
2716
2752
  toolCallId: part.tool_use_id,
2717
- toolName: "code_execution",
2753
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2718
2754
  result: {
2719
2755
  type: part.content.type,
2720
2756
  stdout: part.content.stdout,
@@ -2726,7 +2762,7 @@ var AnthropicMessagesLanguageModel = class {
2726
2762
  controller.enqueue({
2727
2763
  type: "tool-result",
2728
2764
  toolCallId: part.tool_use_id,
2729
- toolName: "code_execution",
2765
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2730
2766
  isError: true,
2731
2767
  result: {
2732
2768
  type: "code_execution_tool_result_error",
@@ -2742,7 +2778,7 @@ var AnthropicMessagesLanguageModel = class {
2742
2778
  controller.enqueue({
2743
2779
  type: "tool-result",
2744
2780
  toolCallId: part.tool_use_id,
2745
- toolName: "code_execution",
2781
+ toolName: toolNameMapping.toCustomToolName("code_execution"),
2746
2782
  result: part.content
2747
2783
  });
2748
2784
  return;
@@ -2810,11 +2846,10 @@ var AnthropicMessagesLanguageModel = class {
2810
2846
  type: "tool-input-end",
2811
2847
  id: contentBlock.toolCallId
2812
2848
  });
2813
- const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
2814
2849
  controller.enqueue({
2815
2850
  type: "tool-call",
2816
2851
  toolCallId: contentBlock.toolCallId,
2817
- toolName,
2852
+ toolName: contentBlock.toolName,
2818
2853
  input: contentBlock.input === "" ? "{}" : contentBlock.input,
2819
2854
  providerExecuted: contentBlock.providerExecuted
2820
2855
  });
@@ -2882,8 +2917,8 @@ var AnthropicMessagesLanguageModel = class {
2882
2917
  if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
2883
2918
  return;
2884
2919
  }
2885
- if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
2886
- delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
2920
+ if (contentBlock.firstDelta && (contentBlock.providerToolName === "bash_code_execution" || contentBlock.providerToolName === "text_editor_code_execution")) {
2921
+ delta = `{"type": "${contentBlock.providerToolName}",${delta.substring(1)}`;
2887
2922
  }
2888
2923
  controller.enqueue({
2889
2924
  type: "tool-input-delta",