@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.
@@ -924,7 +924,8 @@ var anthropicSystemMessageProviderOptions = lazySchema3(
924
924
  * an entry of the `tools` option. The tool does not need to be declared
925
925
  * in `tools`, and defining a tool under an existing name replaces it
926
926
  * from that point on. The required `inline-tools-2026-09-15` beta is
927
- * added automatically.
927
+ * added automatically. Requires the request-level
928
+ * `allowInlineToolDefinitions` option to be true.
928
929
  *
929
930
  * A `tool_removal` always references the tool by `toolName`.
930
931
  */
@@ -971,6 +972,13 @@ var anthropicLanguageModelOptions = lazySchema3(() => {
971
972
  * This allows you to deactivate reasoning inputs for models that do not support them.
972
973
  */
973
974
  sendReasoning: z3.boolean().optional(),
975
+ /**
976
+ * Allow tool definitions supplied by value in system-message tool changes.
977
+ * Defaults to false. Enable only for server-controlled messages: inline
978
+ * definitions can add tools or replace their configured restrictions.
979
+ * This request-level option cannot be enabled through message metadata.
980
+ */
981
+ allowInlineToolDefinitions: z3.boolean().optional(),
974
982
  /**
975
983
  * Determines how structured outputs are generated.
976
984
  *
@@ -986,7 +994,7 @@ var anthropicLanguageModelOptions = lazySchema3(() => {
986
994
  * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
987
995
  *
988
996
  * Models that always use adaptive thinking (e.g. `claude-opus-5-5`,
989
- * `claude-fable-5-1`) reject `enabled` and `disabled`. For those models the
997
+ * `claude-fable-5-1`, `claude-fable-5-2`) reject `enabled` and `disabled`. For those models the
990
998
  * provider drops the unsupported setting, emits a warning, and sends an
991
999
  * adaptive thinking request. Use `effort` to control how much they think.
992
1000
  *
@@ -1370,10 +1378,17 @@ var computerToolset_20260801Members = [
1370
1378
  "hold_key",
1371
1379
  "wait"
1372
1380
  ];
1373
- var computerToolset_20260801InputSchema = lazySchema5(
1381
+ var computerToolset_20260801InputSchema = (configs) => lazySchema5(
1374
1382
  () => zodSchema5(
1375
1383
  z5.object({
1376
- action: z5.enum(computerToolset_20260801Members),
1384
+ action: z5.enum(
1385
+ computerToolset_20260801Members.filter(
1386
+ (member) => {
1387
+ var _a;
1388
+ return ((_a = configs == null ? void 0 : configs[member]) == null ? void 0 : _a.enabled) !== false;
1389
+ }
1390
+ )
1391
+ ),
1377
1392
  coordinate: z5.tuple([z5.number().int(), z5.number().int()]).optional(),
1378
1393
  duration: z5.number().optional(),
1379
1394
  region: z5.tuple([
@@ -1403,9 +1418,13 @@ var computerToolset_20260801ArgsSchema = lazySchema5(
1403
1418
  })
1404
1419
  )
1405
1420
  );
1406
- var computerToolset_20260801 = createProviderToolFactory({
1421
+ var factory2 = createProviderToolFactory({
1407
1422
  id: "anthropic.computer_toolset_20260801",
1408
- inputSchema: computerToolset_20260801InputSchema
1423
+ inputSchema: computerToolset_20260801InputSchema()
1424
+ });
1425
+ var computerToolset_20260801 = (args) => ({
1426
+ ...factory2(args),
1427
+ inputSchema: computerToolset_20260801InputSchema(args.configs)
1409
1428
  });
1410
1429
 
1411
1430
  // src/tool/text-editor_20250728.ts
@@ -1436,12 +1455,12 @@ var textEditor_20250728InputSchema = lazySchema6(
1436
1455
  })
1437
1456
  )
1438
1457
  );
1439
- var factory2 = createProviderToolFactory2({
1458
+ var factory3 = createProviderToolFactory2({
1440
1459
  id: "anthropic.text_editor_20250728",
1441
1460
  inputSchema: textEditor_20250728InputSchema
1442
1461
  });
1443
1462
  var textEditor_20250728 = (args = {}) => {
1444
- return factory2(args);
1463
+ return factory3(args);
1445
1464
  };
1446
1465
 
1447
1466
  // src/tool/web-search_20260209.ts
@@ -1487,14 +1506,14 @@ var webSearch_20260209InputSchema = lazySchema7(
1487
1506
  })
1488
1507
  )
1489
1508
  );
1490
- var factory3 = createProviderToolFactoryWithOutputSchema2({
1509
+ var factory4 = createProviderToolFactoryWithOutputSchema2({
1491
1510
  id: "anthropic.web_search_20260209",
1492
1511
  inputSchema: webSearch_20260209InputSchema,
1493
1512
  outputSchema: webSearch_20260209OutputSchema,
1494
1513
  supportsDeferredResults: true
1495
1514
  });
1496
1515
  var webSearch_20260209 = (args = {}) => {
1497
- return factory3(args);
1516
+ return factory4(args);
1498
1517
  };
1499
1518
 
1500
1519
  // src/tool/web-search_20250305.ts
@@ -1540,14 +1559,14 @@ var webSearch_20250305InputSchema = lazySchema8(
1540
1559
  })
1541
1560
  )
1542
1561
  );
1543
- var factory4 = createProviderToolFactoryWithOutputSchema3({
1562
+ var factory5 = createProviderToolFactoryWithOutputSchema3({
1544
1563
  id: "anthropic.web_search_20250305",
1545
1564
  inputSchema: webSearch_20250305InputSchema,
1546
1565
  outputSchema: webSearch_20250305OutputSchema,
1547
1566
  supportsDeferredResults: true
1548
1567
  });
1549
1568
  var webSearch_20250305 = (args = {}) => {
1550
- return factory4(args);
1569
+ return factory5(args);
1551
1570
  };
1552
1571
 
1553
1572
  // src/tool/web-fetch-20260209.ts
@@ -1601,14 +1620,14 @@ var webFetch_20260209InputSchema = lazySchema9(
1601
1620
  })
1602
1621
  )
1603
1622
  );
1604
- var factory5 = createProviderToolFactoryWithOutputSchema4({
1623
+ var factory6 = createProviderToolFactoryWithOutputSchema4({
1605
1624
  id: "anthropic.web_fetch_20260209",
1606
1625
  inputSchema: webFetch_20260209InputSchema,
1607
1626
  outputSchema: webFetch_20260209OutputSchema,
1608
1627
  supportsDeferredResults: true
1609
1628
  });
1610
1629
  var webFetch_20260209 = (args = {}) => {
1611
- return factory5(args);
1630
+ return factory6(args);
1612
1631
  };
1613
1632
 
1614
1633
  // src/tool/web-fetch-20250910.ts
@@ -1662,14 +1681,14 @@ var webFetch_20250910InputSchema = lazySchema10(
1662
1681
  })
1663
1682
  )
1664
1683
  );
1665
- var factory6 = createProviderToolFactoryWithOutputSchema5({
1684
+ var factory7 = createProviderToolFactoryWithOutputSchema5({
1666
1685
  id: "anthropic.web_fetch_20250910",
1667
1686
  inputSchema: webFetch_20250910InputSchema,
1668
1687
  outputSchema: webFetch_20250910OutputSchema,
1669
1688
  supportsDeferredResults: true
1670
1689
  });
1671
1690
  var webFetch_20250910 = (args = {}) => {
1672
- return factory6(args);
1691
+ return factory7(args);
1673
1692
  };
1674
1693
 
1675
1694
  // src/anthropic-prepare-tools.ts
@@ -2195,13 +2214,13 @@ var codeExecution_20250522InputSchema = lazySchema11(
2195
2214
  })
2196
2215
  )
2197
2216
  );
2198
- var factory7 = createProviderToolFactoryWithOutputSchema6({
2217
+ var factory8 = createProviderToolFactoryWithOutputSchema6({
2199
2218
  id: "anthropic.code_execution_20250522",
2200
2219
  inputSchema: codeExecution_20250522InputSchema,
2201
2220
  outputSchema: codeExecution_20250522OutputSchema
2202
2221
  });
2203
2222
  var codeExecution_20250522 = (args = {}) => {
2204
- return factory7(args);
2223
+ return factory8(args);
2205
2224
  };
2206
2225
 
2207
2226
  // src/tool/code-execution_20250825.ts
@@ -2304,7 +2323,7 @@ var codeExecution_20250825InputSchema = lazySchema12(
2304
2323
  ])
2305
2324
  )
2306
2325
  );
2307
- var factory8 = createProviderToolFactoryWithOutputSchema7({
2326
+ var factory9 = createProviderToolFactoryWithOutputSchema7({
2308
2327
  id: "anthropic.code_execution_20250825",
2309
2328
  inputSchema: codeExecution_20250825InputSchema,
2310
2329
  outputSchema: codeExecution_20250825OutputSchema,
@@ -2314,7 +2333,7 @@ var factory8 = createProviderToolFactoryWithOutputSchema7({
2314
2333
  supportsDeferredResults: true
2315
2334
  });
2316
2335
  var codeExecution_20250825 = (args = {}) => {
2317
- return factory8(args);
2336
+ return factory9(args);
2318
2337
  };
2319
2338
 
2320
2339
  // src/tool/code-execution_20260120.ts
@@ -2428,14 +2447,14 @@ var codeExecution_20260120InputSchema = lazySchema13(
2428
2447
  ])
2429
2448
  )
2430
2449
  );
2431
- var factory9 = createProviderToolFactoryWithOutputSchema8({
2450
+ var factory10 = createProviderToolFactoryWithOutputSchema8({
2432
2451
  id: "anthropic.code_execution_20260120",
2433
2452
  inputSchema: codeExecution_20260120InputSchema,
2434
2453
  outputSchema: codeExecution_20260120OutputSchema,
2435
2454
  supportsDeferredResults: true
2436
2455
  });
2437
2456
  var codeExecution_20260120 = (args = {}) => {
2438
- return factory9(args);
2457
+ return factory10(args);
2439
2458
  };
2440
2459
 
2441
2460
  // src/tool/tool-search-regex_20251119.ts
@@ -2476,14 +2495,14 @@ var toolSearchRegex_20251119InputSchema = lazySchema14(
2476
2495
  })
2477
2496
  )
2478
2497
  );
2479
- var factory10 = createProviderToolFactoryWithOutputSchema9({
2498
+ var factory11 = createProviderToolFactoryWithOutputSchema9({
2480
2499
  id: "anthropic.tool_search_regex_20251119",
2481
2500
  inputSchema: toolSearchRegex_20251119InputSchema,
2482
2501
  outputSchema: toolSearchRegex_20251119OutputSchema,
2483
2502
  supportsDeferredResults: true
2484
2503
  });
2485
2504
  var toolSearchRegex_20251119 = (args = {}) => {
2486
- return factory10(args);
2505
+ return factory11(args);
2487
2506
  };
2488
2507
 
2489
2508
  // src/convert-to-anthropic-messages-prompt.ts
@@ -4023,6 +4042,22 @@ function isOpenObject(node) {
4023
4042
  }
4024
4043
 
4025
4044
  // src/anthropic-messages-language-model.ts
4045
+ function validateToolsetMember({
4046
+ toolsetName,
4047
+ memberName,
4048
+ tools
4049
+ }) {
4050
+ var _a, _b;
4051
+ const toolset = tools == null ? void 0 : tools.find(
4052
+ (tool) => "type" in tool && tool.type === "computer_toolset_20260801"
4053
+ );
4054
+ 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) {
4055
+ throw new InvalidResponseDataError({
4056
+ data: { toolsetName, memberName },
4057
+ message: `Received an unavailable toolset member: ${toolsetName}.${memberName}.`
4058
+ });
4059
+ }
4060
+ }
4026
4061
  function createCitationSource(citation, citationDocuments, generateId2) {
4027
4062
  var _a;
4028
4063
  if (citation.type === "web_search_result_location") {
@@ -4090,9 +4125,15 @@ function toToolsetMemberInput({
4090
4125
  memberName,
4091
4126
  input
4092
4127
  }) {
4128
+ if (typeof input !== "object" || input === null || Array.isArray(input)) {
4129
+ throw new InvalidResponseDataError({
4130
+ data: input,
4131
+ message: "Invalid toolset member input: expected an object."
4132
+ });
4133
+ }
4093
4134
  return {
4094
- action: memberName,
4095
- ...typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
4135
+ ...input,
4136
+ action: memberName
4096
4137
  };
4097
4138
  }
4098
4139
  var TEXT_OR_THINKING_BLOCK_TYPES = /* @__PURE__ */ new Set([
@@ -4164,7 +4205,7 @@ var AnthropicMessagesLanguageModel = class {
4164
4205
  providerOptions,
4165
4206
  stream
4166
4207
  }) {
4167
- var _a, _b, _c, _d, _e, _f, _g, _h;
4208
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
4168
4209
  const warnings = [];
4169
4210
  if (frequencyPenalty != null) {
4170
4211
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -4372,6 +4413,19 @@ var AnthropicMessagesLanguageModel = class {
4372
4413
  };
4373
4414
  }
4374
4415
  });
4416
+ const emittedInlineDefinitions = new Set(
4417
+ messagesPrompt.messages.flatMap(
4418
+ (message) => message.role === "system" ? message.content.flatMap(
4419
+ (part) => part.type === "tool_addition" && part.tool.type === "tool_definition" ? [part.tool.definition] : []
4420
+ ) : []
4421
+ )
4422
+ );
4423
+ if (emittedInlineDefinitions.size > 0 && (anthropicOptions == null ? void 0 : anthropicOptions.allowInlineToolDefinitions) !== true) {
4424
+ throw new InvalidArgumentError({
4425
+ argument: "providerOptions.anthropic.allowInlineToolDefinitions",
4426
+ 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."
4427
+ });
4428
+ }
4375
4429
  if (rejectsThinkingDisabled && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null) {
4376
4430
  const requestedThinking = anthropicOptions.thinking;
4377
4431
  const requestedType = "type" in requestedThinking ? requestedThinking.type : void 0;
@@ -4710,13 +4764,12 @@ var AnthropicMessagesLanguageModel = class {
4710
4764
  }
4711
4765
  );
4712
4766
  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) {
4713
- const emittedInlineDefinitions = new Set(
4714
- messagesPrompt.messages.flatMap(
4715
- (message) => message.role === "system" ? message.content.flatMap(
4716
- (part) => part.type === "tool_addition" && part.tool.type === "tool_definition" ? [part.tool.definition] : []
4717
- ) : []
4718
- )
4719
- );
4767
+ for (const server of (_h = baseArgs.mcp_servers) != null ? _h : []) {
4768
+ server.tool_configuration = {
4769
+ allowed_tools: (_i = server.tool_configuration) == null ? void 0 : _i.allowed_tools,
4770
+ enabled: false
4771
+ };
4772
+ }
4720
4773
  const selectedSdkName = toolChoice.type === "tool" ? toolChoice.toolName : void 0;
4721
4774
  const selectedTool = tools == null ? void 0 : tools.find((tool) => tool.name === selectedSdkName);
4722
4775
  const selectedProviderName = jsonResponseTool != null && selectedSdkName != null && (selectedTool == null ? void 0 : selectedTool.type) !== "function" ? toolNameMapping.toProviderToolName(selectedSdkName) : selectedSdkName;
@@ -4748,7 +4801,7 @@ var AnthropicMessagesLanguageModel = class {
4748
4801
  ...betas,
4749
4802
  ...toolsBetas,
4750
4803
  ...userSuppliedBetas,
4751
- ...(_h = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _h : []
4804
+ ...(_j = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _j : []
4752
4805
  ]),
4753
4806
  usesJsonResponseTool: jsonResponseTool != null,
4754
4807
  toolNameMapping,
@@ -4928,6 +4981,11 @@ var AnthropicMessagesLanguageModel = class {
4928
4981
  text: JSON.stringify(part.input)
4929
4982
  });
4930
4983
  } else if (part.toolset_name != null) {
4984
+ validateToolsetMember({
4985
+ toolsetName: part.toolset_name,
4986
+ memberName: part.name,
4987
+ tools: args.tools
4988
+ });
4931
4989
  content.push({
4932
4990
  type: "tool-call",
4933
4991
  toolCallId: part.id,
@@ -5507,6 +5565,11 @@ var AnthropicMessagesLanguageModel = class {
5507
5565
  id: String(value.index)
5508
5566
  });
5509
5567
  } else if (part.toolset_name != null) {
5568
+ validateToolsetMember({
5569
+ toolsetName: part.toolset_name,
5570
+ memberName: part.name,
5571
+ tools: body.tools
5572
+ });
5510
5573
  const callerInfo = getAnthropicCallerInfo(part.caller);
5511
5574
  const customToolName = toolNameMapping.toCustomToolName(
5512
5575
  part.toolset_name
@@ -5922,9 +5985,12 @@ var AnthropicMessagesLanguageModel = class {
5922
5985
  try {
5923
5986
  memberInput = contentBlock.input === "" ? {} : secureJsonParse2(contentBlock.input);
5924
5987
  } catch (e) {
5925
- memberInput = void 0;
5988
+ throw new InvalidResponseDataError({
5989
+ data: contentBlock.input,
5990
+ message: "Invalid toolset member input JSON."
5991
+ });
5926
5992
  }
5927
- contentBlock.input = memberInput === void 0 ? contentBlock.input : JSON.stringify(
5993
+ contentBlock.input = JSON.stringify(
5928
5994
  toToolsetMemberInput({
5929
5995
  memberName: contentBlock.toolset.memberName,
5930
5996
  input: memberInput
@@ -6382,7 +6448,7 @@ function getModelCapabilities(modelId) {
6382
6448
  supportsBetweenToolsThinking: false,
6383
6449
  isKnownModel: true
6384
6450
  };
6385
- } else if (modelId.includes("claude-fable-5-1")) {
6451
+ } else if (modelId.includes("claude-fable-5-2") || modelId.includes("claude-fable-5-1")) {
6386
6452
  return {
6387
6453
  maxOutputTokens: 128e3,
6388
6454
  supportsStructuredOutput: true,
@@ -6905,14 +6971,14 @@ var toolSearchBm25_20251119InputSchema = lazySchema24(
6905
6971
  })
6906
6972
  )
6907
6973
  );
6908
- var factory11 = createProviderToolFactoryWithOutputSchema10({
6974
+ var factory12 = createProviderToolFactoryWithOutputSchema10({
6909
6975
  id: "anthropic.tool_search_bm25_20251119",
6910
6976
  inputSchema: toolSearchBm25_20251119InputSchema,
6911
6977
  outputSchema: toolSearchBm25_20251119OutputSchema,
6912
6978
  supportsDeferredResults: true
6913
6979
  });
6914
6980
  var toolSearchBm25_20251119 = (args = {}) => {
6915
- return factory11(args);
6981
+ return factory12(args);
6916
6982
  };
6917
6983
 
6918
6984
  // src/anthropic-tools.ts