@ai-sdk/anthropic 3.0.139 → 3.0.142

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
@@ -12,7 +12,7 @@ import {
12
12
  } from "@ai-sdk/provider-utils";
13
13
 
14
14
  // src/version.ts
15
- var VERSION = true ? "3.0.139" : "0.0.0-test";
15
+ var VERSION = true ? "3.0.142" : "0.0.0-test";
16
16
 
17
17
  // src/anthropic-messages-language-model.ts
18
18
  import {
@@ -940,7 +940,8 @@ var anthropicSystemMessageProviderOptions = lazySchema3(
940
940
  * an entry of the `tools` option. The tool does not need to be declared
941
941
  * in `tools`, and defining a tool under an existing name replaces it
942
942
  * from that point on. The required `inline-tools-2026-09-15` beta is
943
- * added automatically.
943
+ * added automatically. Requires the request-level
944
+ * `allowInlineToolDefinitions` option to be true.
944
945
  *
945
946
  * A `tool_removal` always references the tool by `toolName`.
946
947
  */
@@ -987,6 +988,13 @@ var anthropicLanguageModelOptions = lazySchema3(() => {
987
988
  * This allows you to deactivate reasoning inputs for models that do not support them.
988
989
  */
989
990
  sendReasoning: z3.boolean().optional(),
991
+ /**
992
+ * Allow tool definitions supplied by value in system-message tool changes.
993
+ * Defaults to false. Enable only for server-controlled messages: inline
994
+ * definitions can add tools or replace their configured restrictions.
995
+ * This request-level option cannot be enabled through message metadata.
996
+ */
997
+ allowInlineToolDefinitions: z3.boolean().optional(),
990
998
  /**
991
999
  * Determines how structured outputs are generated.
992
1000
  *
@@ -1002,7 +1010,7 @@ var anthropicLanguageModelOptions = lazySchema3(() => {
1002
1010
  * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
1003
1011
  *
1004
1012
  * Models that always use adaptive thinking (e.g. `claude-opus-5-5`,
1005
- * `claude-fable-5-1`) reject `enabled` and `disabled`. For those models the
1013
+ * `claude-fable-5-1`, `claude-fable-5-2`) reject `enabled` and `disabled`. For those models the
1006
1014
  * provider drops the unsupported setting, emits a warning, and sends an
1007
1015
  * adaptive thinking request. Use `effort` to control how much they think.
1008
1016
  *
@@ -1386,10 +1394,17 @@ var computerToolset_20260801Members = [
1386
1394
  "hold_key",
1387
1395
  "wait"
1388
1396
  ];
1389
- var computerToolset_20260801InputSchema = lazySchema5(
1397
+ var computerToolset_20260801InputSchema = (configs) => lazySchema5(
1390
1398
  () => zodSchema5(
1391
1399
  z5.object({
1392
- action: z5.enum(computerToolset_20260801Members),
1400
+ action: z5.enum(
1401
+ computerToolset_20260801Members.filter(
1402
+ (member) => {
1403
+ var _a;
1404
+ return ((_a = configs == null ? void 0 : configs[member]) == null ? void 0 : _a.enabled) !== false;
1405
+ }
1406
+ )
1407
+ ),
1393
1408
  coordinate: z5.tuple([z5.number().int(), z5.number().int()]).optional(),
1394
1409
  duration: z5.number().optional(),
1395
1410
  region: z5.tuple([
@@ -1419,9 +1434,13 @@ var computerToolset_20260801ArgsSchema = lazySchema5(
1419
1434
  })
1420
1435
  )
1421
1436
  );
1422
- var computerToolset_20260801 = createProviderToolFactory({
1437
+ var factory2 = createProviderToolFactory({
1423
1438
  id: "anthropic.computer_toolset_20260801",
1424
- inputSchema: computerToolset_20260801InputSchema
1439
+ inputSchema: computerToolset_20260801InputSchema()
1440
+ });
1441
+ var computerToolset_20260801 = (args) => ({
1442
+ ...factory2(args),
1443
+ inputSchema: computerToolset_20260801InputSchema(args.configs)
1425
1444
  });
1426
1445
 
1427
1446
  // src/tool/text-editor_20250728.ts
@@ -1452,12 +1471,12 @@ var textEditor_20250728InputSchema = lazySchema6(
1452
1471
  })
1453
1472
  )
1454
1473
  );
1455
- var factory2 = createProviderToolFactory2({
1474
+ var factory3 = createProviderToolFactory2({
1456
1475
  id: "anthropic.text_editor_20250728",
1457
1476
  inputSchema: textEditor_20250728InputSchema
1458
1477
  });
1459
1478
  var textEditor_20250728 = (args = {}) => {
1460
- return factory2(args);
1479
+ return factory3(args);
1461
1480
  };
1462
1481
 
1463
1482
  // src/tool/web-search_20260209.ts
@@ -1503,14 +1522,14 @@ var webSearch_20260209InputSchema = lazySchema7(
1503
1522
  })
1504
1523
  )
1505
1524
  );
1506
- var factory3 = createProviderToolFactoryWithOutputSchema2({
1525
+ var factory4 = createProviderToolFactoryWithOutputSchema2({
1507
1526
  id: "anthropic.web_search_20260209",
1508
1527
  inputSchema: webSearch_20260209InputSchema,
1509
1528
  outputSchema: webSearch_20260209OutputSchema,
1510
1529
  supportsDeferredResults: true
1511
1530
  });
1512
1531
  var webSearch_20260209 = (args = {}) => {
1513
- return factory3(args);
1532
+ return factory4(args);
1514
1533
  };
1515
1534
 
1516
1535
  // src/tool/web-search_20250305.ts
@@ -1556,14 +1575,14 @@ var webSearch_20250305InputSchema = lazySchema8(
1556
1575
  })
1557
1576
  )
1558
1577
  );
1559
- var factory4 = createProviderToolFactoryWithOutputSchema3({
1578
+ var factory5 = createProviderToolFactoryWithOutputSchema3({
1560
1579
  id: "anthropic.web_search_20250305",
1561
1580
  inputSchema: webSearch_20250305InputSchema,
1562
1581
  outputSchema: webSearch_20250305OutputSchema,
1563
1582
  supportsDeferredResults: true
1564
1583
  });
1565
1584
  var webSearch_20250305 = (args = {}) => {
1566
- return factory4(args);
1585
+ return factory5(args);
1567
1586
  };
1568
1587
 
1569
1588
  // src/tool/web-fetch-20260209.ts
@@ -1617,14 +1636,14 @@ var webFetch_20260209InputSchema = lazySchema9(
1617
1636
  })
1618
1637
  )
1619
1638
  );
1620
- var factory5 = createProviderToolFactoryWithOutputSchema4({
1639
+ var factory6 = createProviderToolFactoryWithOutputSchema4({
1621
1640
  id: "anthropic.web_fetch_20260209",
1622
1641
  inputSchema: webFetch_20260209InputSchema,
1623
1642
  outputSchema: webFetch_20260209OutputSchema,
1624
1643
  supportsDeferredResults: true
1625
1644
  });
1626
1645
  var webFetch_20260209 = (args = {}) => {
1627
- return factory5(args);
1646
+ return factory6(args);
1628
1647
  };
1629
1648
 
1630
1649
  // src/tool/web-fetch-20250910.ts
@@ -1678,14 +1697,14 @@ var webFetch_20250910InputSchema = lazySchema10(
1678
1697
  })
1679
1698
  )
1680
1699
  );
1681
- var factory6 = createProviderToolFactoryWithOutputSchema5({
1700
+ var factory7 = createProviderToolFactoryWithOutputSchema5({
1682
1701
  id: "anthropic.web_fetch_20250910",
1683
1702
  inputSchema: webFetch_20250910InputSchema,
1684
1703
  outputSchema: webFetch_20250910OutputSchema,
1685
1704
  supportsDeferredResults: true
1686
1705
  });
1687
1706
  var webFetch_20250910 = (args = {}) => {
1688
- return factory6(args);
1707
+ return factory7(args);
1689
1708
  };
1690
1709
 
1691
1710
  // src/anthropic-prepare-tools.ts
@@ -2211,13 +2230,13 @@ var codeExecution_20250522InputSchema = lazySchema11(
2211
2230
  })
2212
2231
  )
2213
2232
  );
2214
- var factory7 = createProviderToolFactoryWithOutputSchema6({
2233
+ var factory8 = createProviderToolFactoryWithOutputSchema6({
2215
2234
  id: "anthropic.code_execution_20250522",
2216
2235
  inputSchema: codeExecution_20250522InputSchema,
2217
2236
  outputSchema: codeExecution_20250522OutputSchema
2218
2237
  });
2219
2238
  var codeExecution_20250522 = (args = {}) => {
2220
- return factory7(args);
2239
+ return factory8(args);
2221
2240
  };
2222
2241
 
2223
2242
  // src/tool/code-execution_20250825.ts
@@ -2320,7 +2339,7 @@ var codeExecution_20250825InputSchema = lazySchema12(
2320
2339
  ])
2321
2340
  )
2322
2341
  );
2323
- var factory8 = createProviderToolFactoryWithOutputSchema7({
2342
+ var factory9 = createProviderToolFactoryWithOutputSchema7({
2324
2343
  id: "anthropic.code_execution_20250825",
2325
2344
  inputSchema: codeExecution_20250825InputSchema,
2326
2345
  outputSchema: codeExecution_20250825OutputSchema,
@@ -2330,7 +2349,7 @@ var factory8 = createProviderToolFactoryWithOutputSchema7({
2330
2349
  supportsDeferredResults: true
2331
2350
  });
2332
2351
  var codeExecution_20250825 = (args = {}) => {
2333
- return factory8(args);
2352
+ return factory9(args);
2334
2353
  };
2335
2354
 
2336
2355
  // src/tool/code-execution_20260120.ts
@@ -2444,14 +2463,14 @@ var codeExecution_20260120InputSchema = lazySchema13(
2444
2463
  ])
2445
2464
  )
2446
2465
  );
2447
- var factory9 = createProviderToolFactoryWithOutputSchema8({
2466
+ var factory10 = createProviderToolFactoryWithOutputSchema8({
2448
2467
  id: "anthropic.code_execution_20260120",
2449
2468
  inputSchema: codeExecution_20260120InputSchema,
2450
2469
  outputSchema: codeExecution_20260120OutputSchema,
2451
2470
  supportsDeferredResults: true
2452
2471
  });
2453
2472
  var codeExecution_20260120 = (args = {}) => {
2454
- return factory9(args);
2473
+ return factory10(args);
2455
2474
  };
2456
2475
 
2457
2476
  // src/tool/tool-search-regex_20251119.ts
@@ -2492,14 +2511,14 @@ var toolSearchRegex_20251119InputSchema = lazySchema14(
2492
2511
  })
2493
2512
  )
2494
2513
  );
2495
- var factory10 = createProviderToolFactoryWithOutputSchema9({
2514
+ var factory11 = createProviderToolFactoryWithOutputSchema9({
2496
2515
  id: "anthropic.tool_search_regex_20251119",
2497
2516
  inputSchema: toolSearchRegex_20251119InputSchema,
2498
2517
  outputSchema: toolSearchRegex_20251119OutputSchema,
2499
2518
  supportsDeferredResults: true
2500
2519
  });
2501
2520
  var toolSearchRegex_20251119 = (args = {}) => {
2502
- return factory10(args);
2521
+ return factory11(args);
2503
2522
  };
2504
2523
 
2505
2524
  // src/convert-to-anthropic-messages-prompt.ts
@@ -4039,6 +4058,22 @@ function isOpenObject(node) {
4039
4058
  }
4040
4059
 
4041
4060
  // src/anthropic-messages-language-model.ts
4061
+ function validateToolsetMember({
4062
+ toolsetName,
4063
+ memberName,
4064
+ tools
4065
+ }) {
4066
+ var _a, _b;
4067
+ const toolset = tools == null ? void 0 : tools.find(
4068
+ (tool) => "type" in tool && tool.type === "computer_toolset_20260801"
4069
+ );
4070
+ if (toolsetName !== "computer" || toolset == null || !computerToolset_20260801Members.some((member) => member === memberName) || ((_b = (_a = toolset.configs) == null ? void 0 : _a[memberName]) == null ? void 0 : _b.enabled) === false) {
4071
+ throw new InvalidResponseDataError({
4072
+ data: { toolsetName, memberName },
4073
+ message: `Received an unavailable toolset member: ${toolsetName}.${memberName}.`
4074
+ });
4075
+ }
4076
+ }
4042
4077
  function createCitationSource(citation, citationDocuments, generateId3) {
4043
4078
  var _a;
4044
4079
  if (citation.type === "web_search_result_location") {
@@ -4106,9 +4141,15 @@ function toToolsetMemberInput({
4106
4141
  memberName,
4107
4142
  input
4108
4143
  }) {
4144
+ if (typeof input !== "object" || input === null || Array.isArray(input)) {
4145
+ throw new InvalidResponseDataError({
4146
+ data: input,
4147
+ message: "Invalid toolset member input: expected an object."
4148
+ });
4149
+ }
4109
4150
  return {
4110
- action: memberName,
4111
- ...typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
4151
+ ...input,
4152
+ action: memberName
4112
4153
  };
4113
4154
  }
4114
4155
  var TEXT_OR_THINKING_BLOCK_TYPES = /* @__PURE__ */ new Set([
@@ -4180,7 +4221,7 @@ var AnthropicMessagesLanguageModel = class {
4180
4221
  providerOptions,
4181
4222
  stream
4182
4223
  }) {
4183
- var _a, _b, _c, _d, _e, _f, _g, _h;
4224
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
4184
4225
  const warnings = [];
4185
4226
  if (frequencyPenalty != null) {
4186
4227
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -4388,6 +4429,19 @@ var AnthropicMessagesLanguageModel = class {
4388
4429
  };
4389
4430
  }
4390
4431
  });
4432
+ const emittedInlineDefinitions = new Set(
4433
+ messagesPrompt.messages.flatMap(
4434
+ (message) => message.role === "system" ? message.content.flatMap(
4435
+ (part) => part.type === "tool_addition" && part.tool.type === "tool_definition" ? [part.tool.definition] : []
4436
+ ) : []
4437
+ )
4438
+ );
4439
+ if (emittedInlineDefinitions.size > 0 && (anthropicOptions == null ? void 0 : anthropicOptions.allowInlineToolDefinitions) !== true) {
4440
+ throw new InvalidArgumentError({
4441
+ argument: "providerOptions.anthropic.allowInlineToolDefinitions",
4442
+ message: "Inline tool definitions require providerOptions.anthropic.allowInlineToolDefinitions to be true. Enable this option only for server-controlled messages, or declare tools in the tools option and add them by reference with toolName."
4443
+ });
4444
+ }
4391
4445
  if (rejectsThinkingDisabled && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null) {
4392
4446
  const requestedThinking = anthropicOptions.thinking;
4393
4447
  const requestedType = "type" in requestedThinking ? requestedThinking.type : void 0;
@@ -4726,13 +4780,12 @@ var AnthropicMessagesLanguageModel = class {
4726
4780
  }
4727
4781
  );
4728
4782
  if ((toolChoice == null ? void 0 : toolChoice.type) === "tool" && ((anthropicToolChoice == null ? void 0 : anthropicToolChoice.type) === "auto" || jsonResponseTool != null) || (toolChoice == null ? void 0 : toolChoice.type) === "none" && jsonResponseTool != null) {
4729
- const emittedInlineDefinitions = new Set(
4730
- messagesPrompt.messages.flatMap(
4731
- (message) => message.role === "system" ? message.content.flatMap(
4732
- (part) => part.type === "tool_addition" && part.tool.type === "tool_definition" ? [part.tool.definition] : []
4733
- ) : []
4734
- )
4735
- );
4783
+ for (const server of (_h = baseArgs.mcp_servers) != null ? _h : []) {
4784
+ server.tool_configuration = {
4785
+ allowed_tools: (_i = server.tool_configuration) == null ? void 0 : _i.allowed_tools,
4786
+ enabled: false
4787
+ };
4788
+ }
4736
4789
  const selectedSdkName = toolChoice.type === "tool" ? toolChoice.toolName : void 0;
4737
4790
  const selectedTool = tools == null ? void 0 : tools.find((tool) => tool.name === selectedSdkName);
4738
4791
  const selectedProviderName = jsonResponseTool != null && selectedSdkName != null && (selectedTool == null ? void 0 : selectedTool.type) !== "function" ? toolNameMapping.toProviderToolName(selectedSdkName) : selectedSdkName;
@@ -4764,7 +4817,7 @@ var AnthropicMessagesLanguageModel = class {
4764
4817
  ...betas,
4765
4818
  ...toolsBetas,
4766
4819
  ...userSuppliedBetas,
4767
- ...(_h = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _h : []
4820
+ ...(_j = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _j : []
4768
4821
  ]),
4769
4822
  usesJsonResponseTool: jsonResponseTool != null,
4770
4823
  toolNameMapping,
@@ -4944,6 +4997,11 @@ var AnthropicMessagesLanguageModel = class {
4944
4997
  text: JSON.stringify(part.input)
4945
4998
  });
4946
4999
  } else if (part.toolset_name != null) {
5000
+ validateToolsetMember({
5001
+ toolsetName: part.toolset_name,
5002
+ memberName: part.name,
5003
+ tools: args.tools
5004
+ });
4947
5005
  content.push({
4948
5006
  type: "tool-call",
4949
5007
  toolCallId: part.id,
@@ -5523,6 +5581,11 @@ var AnthropicMessagesLanguageModel = class {
5523
5581
  id: String(value.index)
5524
5582
  });
5525
5583
  } else if (part.toolset_name != null) {
5584
+ validateToolsetMember({
5585
+ toolsetName: part.toolset_name,
5586
+ memberName: part.name,
5587
+ tools: body.tools
5588
+ });
5526
5589
  const callerInfo = getAnthropicCallerInfo(part.caller);
5527
5590
  const customToolName = toolNameMapping.toCustomToolName(
5528
5591
  part.toolset_name
@@ -5938,9 +6001,12 @@ var AnthropicMessagesLanguageModel = class {
5938
6001
  try {
5939
6002
  memberInput = contentBlock.input === "" ? {} : secureJsonParse2(contentBlock.input);
5940
6003
  } catch (e) {
5941
- memberInput = void 0;
6004
+ throw new InvalidResponseDataError({
6005
+ data: contentBlock.input,
6006
+ message: "Invalid toolset member input JSON."
6007
+ });
5942
6008
  }
5943
- contentBlock.input = memberInput === void 0 ? contentBlock.input : JSON.stringify(
6009
+ contentBlock.input = JSON.stringify(
5944
6010
  toToolsetMemberInput({
5945
6011
  memberName: contentBlock.toolset.memberName,
5946
6012
  input: memberInput
@@ -6398,7 +6464,7 @@ function getModelCapabilities(modelId) {
6398
6464
  supportsBetweenToolsThinking: false,
6399
6465
  isKnownModel: true
6400
6466
  };
6401
- } else if (modelId.includes("claude-fable-5-1")) {
6467
+ } else if (modelId.includes("claude-fable-5-2") || modelId.includes("claude-fable-5-1")) {
6402
6468
  return {
6403
6469
  maxOutputTokens: 128e3,
6404
6470
  supportsStructuredOutput: true,
@@ -6921,14 +6987,14 @@ var toolSearchBm25_20251119InputSchema = lazySchema24(
6921
6987
  })
6922
6988
  )
6923
6989
  );
6924
- var factory11 = createProviderToolFactoryWithOutputSchema10({
6990
+ var factory12 = createProviderToolFactoryWithOutputSchema10({
6925
6991
  id: "anthropic.tool_search_bm25_20251119",
6926
6992
  inputSchema: toolSearchBm25_20251119InputSchema,
6927
6993
  outputSchema: toolSearchBm25_20251119OutputSchema,
6928
6994
  supportsDeferredResults: true
6929
6995
  });
6930
6996
  var toolSearchBm25_20251119 = (args = {}) => {
6931
- return factory11(args);
6997
+ return factory12(args);
6932
6998
  };
6933
6999
 
6934
7000
  // src/anthropic-tools.ts