@ai-sdk/anthropic 3.0.137 → 3.0.139

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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 3.0.139
4
+
5
+ ### Patch Changes
6
+
7
+ - 25c71b9: feat(anthropic): support adding tools by value in mid-conversation `toolChanges` (`inline-tools-2026-09-15`)
8
+ - 95af5ce: Reject conflicting inline tool additions when a named tool choice falls back to auto or the internal JSON response tool limits available application tools, including definitions replayed from conversation history. Only validate definitions emitted in the request, preserving warning-only handling of ignored additions on the initial system message.
9
+
10
+ ## 3.0.138
11
+
12
+ ### Patch Changes
13
+
14
+ - d900e58: Enable native structured output and strict tools for supported Claude 5 models on Bedrock. In automatic mode, Bedrock and Anthropic now fall back for schemas that native structured output cannot represent: recursive references, open objects, or more than ten optional properties. Anthropic uses the JSON response tool; Bedrock Converse uses the JSON tool or JSON instructions for models that reject forced tool use. The JSON-tool fallback excludes disabled and unselected application tools. Explicit `outputFormat` selection remains unchanged.
15
+ - d900e58: fix(anthropic): parse valid JSON string tool input and safely serialize BigInt and cycles in tool results
16
+ - Updated dependencies [d900e58]
17
+ - Updated dependencies [d900e58]
18
+ - Updated dependencies [d900e58]
19
+ - @ai-sdk/provider-utils@4.0.64
20
+
3
21
  ## 3.0.137
4
22
 
5
23
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -230,6 +230,20 @@ declare const anthropicSystemMessageProviderOptions: _ai_sdk_provider_utils.Lazy
230
230
  toolChanges?: ({
231
231
  type: "tool_addition";
232
232
  toolName: string;
233
+ } | {
234
+ type: "tool_addition";
235
+ tool: {
236
+ [x: string]: unknown;
237
+ type: "function";
238
+ name: string;
239
+ inputSchema: Record<string, unknown>;
240
+ } | {
241
+ [x: string]: unknown;
242
+ type: "provider";
243
+ id: string;
244
+ name: string;
245
+ args: Record<string, unknown>;
246
+ };
233
247
  } | {
234
248
  type: "tool_removal";
235
249
  toolName: string;
package/dist/index.d.ts CHANGED
@@ -230,6 +230,20 @@ declare const anthropicSystemMessageProviderOptions: _ai_sdk_provider_utils.Lazy
230
230
  toolChanges?: ({
231
231
  type: "tool_addition";
232
232
  toolName: string;
233
+ } | {
234
+ type: "tool_addition";
235
+ tool: {
236
+ [x: string]: unknown;
237
+ type: "function";
238
+ name: string;
239
+ inputSchema: Record<string, unknown>;
240
+ } | {
241
+ [x: string]: unknown;
242
+ type: "provider";
243
+ id: string;
244
+ name: string;
245
+ args: Record<string, unknown>;
246
+ };
233
247
  } | {
234
248
  type: "tool_removal";
235
249
  toolName: string;
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
32
32
  var import_provider_utils28 = require("@ai-sdk/provider-utils");
33
33
 
34
34
  // src/version.ts
35
- var VERSION = true ? "3.0.137" : "0.0.0-test";
35
+ var VERSION = true ? "3.0.139" : "0.0.0-test";
36
36
 
37
37
  // src/anthropic-messages-language-model.ts
38
38
  var import_provider3 = require("@ai-sdk/provider");
@@ -925,17 +925,43 @@ var anthropicSystemMessageProviderOptions = (0, import_provider_utils3.lazySchem
925
925
  * initial system prompt). A system message carrying tool changes must come
926
926
  * right before an assistant message or at the end of the messages.
927
927
  *
928
- * Tools referenced by a `tool_addition` must be declared in the `tools`
929
- * option (typically with `deferLoading: true` so they are not loaded until
930
- * the addition surfaces them). The required
931
- * `mid-conversation-tool-changes-2026-07-01` beta is added automatically.
928
+ * A `tool_addition` either references a tool by `toolName` or defines it
929
+ * by value with `tool`:
930
+ * - By reference: the tool must be declared in the `tools` option
931
+ * (typically with `deferLoading: true` so it is not loaded until the
932
+ * addition surfaces it). The required
933
+ * `mid-conversation-tool-changes-2026-07-01` beta is added
934
+ * automatically.
935
+ * - By value: `tool` is a function or provider tool, in the same shape as
936
+ * an entry of the `tools` option. The tool does not need to be declared
937
+ * in `tools`, and defining a tool under an existing name replaces it
938
+ * from that point on. The required `inline-tools-2026-09-15` beta is
939
+ * added automatically.
940
+ *
941
+ * A `tool_removal` always references the tool by `toolName`.
932
942
  */
933
943
  toolChanges: import_v43.z.array(
934
- import_v43.z.discriminatedUnion("type", [
944
+ import_v43.z.union([
935
945
  import_v43.z.object({
936
946
  type: import_v43.z.literal("tool_addition"),
937
947
  toolName: import_v43.z.string()
938
948
  }),
949
+ import_v43.z.object({
950
+ type: import_v43.z.literal("tool_addition"),
951
+ tool: import_v43.z.union([
952
+ import_v43.z.looseObject({
953
+ type: import_v43.z.literal("function"),
954
+ name: import_v43.z.string(),
955
+ inputSchema: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown())
956
+ }),
957
+ import_v43.z.looseObject({
958
+ type: import_v43.z.literal("provider"),
959
+ id: import_v43.z.string(),
960
+ name: import_v43.z.string(),
961
+ args: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown())
962
+ })
963
+ ])
964
+ }),
939
965
  import_v43.z.object({
940
966
  type: import_v43.z.literal("tool_removal"),
941
967
  toolName: import_v43.z.string()
@@ -1633,6 +1659,7 @@ var import_provider_utils11 = require("@ai-sdk/provider-utils");
1633
1659
  async function prepareTools({
1634
1660
  tools,
1635
1661
  toolChoice,
1662
+ hasInlineTools = false,
1636
1663
  disableParallelToolUse,
1637
1664
  cacheControlValidator,
1638
1665
  supportsStructuredOutput,
@@ -1645,11 +1672,11 @@ async function prepareTools({
1645
1672
  const toolWarnings = [];
1646
1673
  const betas = /* @__PURE__ */ new Set();
1647
1674
  const validator = cacheControlValidator || new CacheControlValidator();
1648
- if (tools == null) {
1675
+ if (tools == null && !hasInlineTools) {
1649
1676
  return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
1650
1677
  }
1651
1678
  const anthropicTools2 = [];
1652
- for (const tool of tools) {
1679
+ for (const tool of tools != null ? tools : []) {
1653
1680
  switch (tool.type) {
1654
1681
  case "function": {
1655
1682
  const cacheControl = validator.getCacheControl(tool.providerOptions, {
@@ -1961,9 +1988,10 @@ async function prepareTools({
1961
1988
  }
1962
1989
  }
1963
1990
  }
1991
+ const declaredTools = tools == null ? void 0 : anthropicTools2;
1964
1992
  if (toolChoice == null) {
1965
1993
  return {
1966
- tools: anthropicTools2,
1994
+ tools: declaredTools,
1967
1995
  toolChoice: disableParallelToolUse ? { type: "auto", disable_parallel_tool_use: disableParallelToolUse } : void 0,
1968
1996
  toolWarnings,
1969
1997
  betas
@@ -1973,7 +2001,7 @@ async function prepareTools({
1973
2001
  switch (type) {
1974
2002
  case "auto":
1975
2003
  return {
1976
- tools: anthropicTools2,
2004
+ tools: declaredTools,
1977
2005
  toolChoice: {
1978
2006
  type: "auto",
1979
2007
  disable_parallel_tool_use: disableParallelToolUse
@@ -1989,7 +2017,7 @@ async function prepareTools({
1989
2017
  details: `toolChoice 'required' is not supported with this model or thinking configuration. Using 'auto' instead. Instruct the model to use a tool in the prompt and verify that a tool call was made.`
1990
2018
  });
1991
2019
  return {
1992
- tools: anthropicTools2,
2020
+ tools: declaredTools,
1993
2021
  toolChoice: {
1994
2022
  type: "auto",
1995
2023
  disable_parallel_tool_use: disableParallelToolUse
@@ -1999,7 +2027,7 @@ async function prepareTools({
1999
2027
  };
2000
2028
  }
2001
2029
  return {
2002
- tools: anthropicTools2,
2030
+ tools: declaredTools,
2003
2031
  toolChoice: {
2004
2032
  type: "any",
2005
2033
  disable_parallel_tool_use: disableParallelToolUse
@@ -2009,7 +2037,7 @@ async function prepareTools({
2009
2037
  };
2010
2038
  case "none":
2011
2039
  return {
2012
- tools: anthropicTools2,
2040
+ tools: declaredTools,
2013
2041
  toolChoice: { type: "none" },
2014
2042
  toolWarnings,
2015
2043
  betas
@@ -2022,7 +2050,7 @@ async function prepareTools({
2022
2050
  details: `toolChoice 'tool' is not supported with this model or thinking configuration. Only the '${toolChoice.toolName}' tool is sent with 'auto' tool choice. Instruct the model to use the tool in the prompt and verify that a tool call was made.`
2023
2051
  });
2024
2052
  return {
2025
- tools: anthropicTools2.filter(
2053
+ tools: declaredTools == null ? void 0 : declaredTools.filter(
2026
2054
  (tool) => "name" in tool && tool.name === toolChoice.toolName
2027
2055
  ),
2028
2056
  toolChoice: {
@@ -2034,7 +2062,7 @@ async function prepareTools({
2034
2062
  };
2035
2063
  }
2036
2064
  return {
2037
- tools: anthropicTools2,
2065
+ tools: declaredTools,
2038
2066
  toolChoice: {
2039
2067
  type: "tool",
2040
2068
  name: toolChoice.toolName,
@@ -2454,6 +2482,32 @@ async function extractErrorValue(value) {
2454
2482
  }
2455
2483
  return {};
2456
2484
  }
2485
+ function isComputerTool(tool) {
2486
+ return tool.type === "provider" && tool.id.startsWith("anthropic.computer_");
2487
+ }
2488
+ async function getInlineToolsFromPrompt(prompt) {
2489
+ var _a;
2490
+ const inlineTools = [];
2491
+ for (const message of prompt) {
2492
+ if (message.role !== "system" || message.providerOptions == null) {
2493
+ continue;
2494
+ }
2495
+ const options = await (0, import_provider_utils16.parseProviderOptions)({
2496
+ provider: "anthropic",
2497
+ providerOptions: message.providerOptions,
2498
+ schema: anthropicSystemMessageProviderOptions
2499
+ });
2500
+ for (const toolChange of (_a = options == null ? void 0 : options.toolChanges) != null ? _a : []) {
2501
+ if ("tool" in toolChange) {
2502
+ const tool = toolChange.tool;
2503
+ if (!isComputerTool(tool)) {
2504
+ inlineTools.push(tool);
2505
+ }
2506
+ }
2507
+ }
2508
+ }
2509
+ return inlineTools;
2510
+ }
2457
2511
  async function convertToAnthropicMessagesPrompt({
2458
2512
  prompt,
2459
2513
  sendReasoning,
@@ -2461,7 +2515,8 @@ async function convertToAnthropicMessagesPrompt({
2461
2515
  cacheControlValidator,
2462
2516
  toolNameMapping,
2463
2517
  toolsetNames = {},
2464
- convertMediaPart
2518
+ convertMediaPart,
2519
+ convertInlineTool
2465
2520
  }) {
2466
2521
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
2467
2522
  const betas = /* @__PURE__ */ new Set();
@@ -2498,6 +2553,7 @@ async function convertToAnthropicMessagesPrompt({
2498
2553
  case "system": {
2499
2554
  const systemMessages = [];
2500
2555
  let toolChangeCount = 0;
2556
+ let hasInlineToolDefinition = false;
2501
2557
  let hasMidConversationOptions = false;
2502
2558
  for (const { content: text, providerOptions } of block.messages) {
2503
2559
  const systemMessageOptions = await (0, import_provider_utils16.parseProviderOptions)({
@@ -2520,6 +2576,40 @@ async function convertToAnthropicMessagesPrompt({
2520
2576
  });
2521
2577
  }
2522
2578
  for (const toolChange of toolChanges) {
2579
+ if ("tool" in toolChange) {
2580
+ if (convertInlineTool == null) {
2581
+ throw new import_provider2.UnsupportedFunctionalityError({
2582
+ functionality: "tool additions by value in mid-conversation tool changes"
2583
+ });
2584
+ }
2585
+ const tool = toolChange.tool;
2586
+ if (isComputerTool(tool)) {
2587
+ warnings.push({
2588
+ type: "other",
2589
+ message: `The tool '${tool.name}' cannot be added by value in a tool change. Declare it in the tools option and add it by reference with toolName. The tool change has been ignored.`
2590
+ });
2591
+ continue;
2592
+ }
2593
+ const {
2594
+ definition,
2595
+ warnings: toolWarnings,
2596
+ betas: toolBetas
2597
+ } = await convertInlineTool(tool);
2598
+ warnings.push(...toolWarnings);
2599
+ for (const beta of toolBetas) {
2600
+ betas.add(beta);
2601
+ }
2602
+ if (definition == null) {
2603
+ continue;
2604
+ }
2605
+ content.push({
2606
+ type: "tool_addition",
2607
+ tool: { type: "tool_definition", definition }
2608
+ });
2609
+ toolChangeCount++;
2610
+ hasInlineToolDefinition = true;
2611
+ continue;
2612
+ }
2523
2613
  toolChangeCount++;
2524
2614
  content.push({
2525
2615
  type: toolChange.type,
@@ -2529,6 +2619,9 @@ async function convertToAnthropicMessagesPrompt({
2529
2619
  }
2530
2620
  });
2531
2621
  }
2622
+ if (content.length === 0 && clearAt == null && effort == null) {
2623
+ continue;
2624
+ }
2532
2625
  hasMidConversationOptions || (hasMidConversationOptions = clearAt != null || effort != null);
2533
2626
  systemMessages.push({
2534
2627
  role: "system",
@@ -2563,7 +2656,9 @@ async function convertToAnthropicMessagesPrompt({
2563
2656
  } else {
2564
2657
  messages.push(...systemMessages);
2565
2658
  betas.add("mid-conversation-system-2026-04-07");
2566
- if (toolChangeCount > 0) {
2659
+ if (hasInlineToolDefinition) {
2660
+ betas.add("inline-tools-2026-09-15");
2661
+ } else if (toolChangeCount > 0) {
2567
2662
  betas.add("mid-conversation-tool-changes-2026-07-01");
2568
2663
  }
2569
2664
  if (systemMessages.some((message) => message.clear_at != null)) {
@@ -2797,7 +2892,7 @@ async function convertToAnthropicMessagesPrompt({
2797
2892
  case "json":
2798
2893
  case "error-json":
2799
2894
  default:
2800
- contentValue = JSON.stringify(output.value);
2895
+ contentValue = (0, import_provider_utils16.stringifyWithBigIntAndCycles)(output.value);
2801
2896
  break;
2802
2897
  }
2803
2898
  const toolsetName = getAnthropicToolsetName({
@@ -3035,7 +3130,7 @@ async function convertToAnthropicMessagesPrompt({
3035
3130
  type: "tool_use",
3036
3131
  id: part.toolCallId,
3037
3132
  name: part.toolName,
3038
- input: part.input,
3133
+ input: parseToolCallInput(part.input),
3039
3134
  ...caller && { caller },
3040
3135
  cache_control: cacheControl
3041
3136
  });
@@ -3520,6 +3615,18 @@ function getAnthropicCaller(providerOptions) {
3520
3615
  }
3521
3616
  return (caller == null ? void 0 : caller.type) === "direct" ? { type: "direct" } : void 0;
3522
3617
  }
3618
+ function parseToolCallInput(input) {
3619
+ if (typeof input === "string") {
3620
+ try {
3621
+ const parsed = (0, import_provider_utils16.secureJsonParse)(input);
3622
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
3623
+ return parsed;
3624
+ }
3625
+ } catch (e) {
3626
+ }
3627
+ }
3628
+ return input;
3629
+ }
3523
3630
 
3524
3631
  // src/map-anthropic-stop-reason.ts
3525
3632
  function mapAnthropicStopReason({
@@ -4112,9 +4219,10 @@ var AnthropicMessagesLanguageModel = class {
4112
4219
  }
4113
4220
  const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
4114
4221
  const supportsStructuredOutput = ((_b = this.config.supportsNativeStructuredOutput) != null ? _b : true) && modelSupportsStructuredOutput;
4222
+ const supportsResponseSchema = (responseFormat == null ? void 0 : responseFormat.type) !== "json" || responseFormat.schema == null || supportsNativeStructuredOutputSchema(responseFormat.schema);
4115
4223
  const supportsStrictTools = ((_c = this.config.supportsStrictTools) != null ? _c : true) && modelSupportsStructuredOutput;
4116
4224
  const structureOutputMode = (_d = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _d : "auto";
4117
- let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
4225
+ let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput && supportsResponseSchema;
4118
4226
  if (!useStructuredOutput && rejectsForcedToolUse && modelSupportsStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && supportsNativeStructuredOutputSchema(responseFormat.schema)) {
4119
4227
  warnings.push({
4120
4228
  type: "unsupported",
@@ -4140,8 +4248,22 @@ var AnthropicMessagesLanguageModel = class {
4140
4248
  const cacheControlValidator = new CacheControlValidator(
4141
4249
  this.config.cacheControlProviderOptionsName
4142
4250
  );
4251
+ const defaultEagerInputStreaming = stream && ((_e = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _e : true);
4252
+ const inlineTools = await getInlineToolsFromPrompt(prompt);
4253
+ const declaredFunctionToolNames = new Set(
4254
+ (tools != null ? tools : []).flatMap(
4255
+ (tool) => tool.type === "function" ? [tool.name] : []
4256
+ )
4257
+ );
4143
4258
  const toolNameMapping = (0, import_provider_utils17.createToolNameMapping)({
4144
- tools,
4259
+ // later entries win when provider tool names collide, so the declared
4260
+ // tools go last and an inline tool cannot take over their mapping:
4261
+ tools: [
4262
+ ...inlineTools.filter(
4263
+ (tool) => !(tool.type === "provider" && declaredFunctionToolNames.has(tool.name))
4264
+ ),
4265
+ ...tools != null ? tools : []
4266
+ ],
4145
4267
  providerToolNames: {
4146
4268
  "anthropic.code_execution_20250522": "code_execution",
4147
4269
  "anthropic.code_execution_20250825": "code_execution",
@@ -4167,14 +4289,43 @@ var AnthropicMessagesLanguageModel = class {
4167
4289
  }
4168
4290
  });
4169
4291
  const toolsetNames = getAnthropicToolsetNames(tools);
4292
+ const inlineToolDefinitions = [];
4170
4293
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
4171
4294
  prompt,
4172
- sendReasoning: (_e = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _e : true,
4295
+ sendReasoning: (_f = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _f : true,
4173
4296
  warnings,
4174
4297
  cacheControlValidator,
4175
4298
  toolNameMapping,
4176
4299
  toolsetNames,
4177
- convertMediaPart: this.config.convertMediaPart
4300
+ convertMediaPart: this.config.convertMediaPart,
4301
+ convertInlineTool: async (tool) => {
4302
+ const {
4303
+ tools: definitions,
4304
+ toolWarnings: toolWarnings2,
4305
+ betas: betas2
4306
+ } = await prepareTools({
4307
+ tools: [tool],
4308
+ toolChoice: void 0,
4309
+ cacheControlValidator,
4310
+ supportsStructuredOutput,
4311
+ supportsStrictTools
4312
+ // no stream-dependent defaults (eager input streaming): the
4313
+ // definition is replayed on every request and has to stay
4314
+ // identical between streaming and non-streaming calls to keep
4315
+ // the cache.
4316
+ });
4317
+ if ((definitions == null ? void 0 : definitions[0]) != null) {
4318
+ inlineToolDefinitions.push({
4319
+ sdkName: tool.name,
4320
+ definition: definitions[0]
4321
+ });
4322
+ }
4323
+ return {
4324
+ definition: definitions == null ? void 0 : definitions[0],
4325
+ warnings: toolWarnings2,
4326
+ betas: betas2
4327
+ };
4328
+ }
4178
4329
  });
4179
4330
  if (rejectsThinkingDisabled && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null) {
4180
4331
  const requestedThinking = anthropicOptions.thinking;
@@ -4284,7 +4435,7 @@ var AnthropicMessagesLanguageModel = class {
4284
4435
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
4285
4436
  cache_control: anthropicOptions.cacheControl
4286
4437
  },
4287
- ...((_f = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _f.userId) != null && {
4438
+ ...((_g = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _g.userId) != null && {
4288
4439
  metadata: { user_id: anthropicOptions.metadata.userId }
4289
4440
  },
4290
4441
  // mcp servers:
@@ -4479,7 +4630,6 @@ var AnthropicMessagesLanguageModel = class {
4479
4630
  } else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
4480
4631
  betas.add("server-side-fallback-2026-06-01");
4481
4632
  }
4482
- const defaultEagerInputStreaming = stream && ((_g = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _g : true);
4483
4633
  const {
4484
4634
  tools: anthropicTools2,
4485
4635
  toolChoice: anthropicToolChoice,
@@ -4487,7 +4637,12 @@ var AnthropicMessagesLanguageModel = class {
4487
4637
  betas: toolsBetas
4488
4638
  } = await prepareTools(
4489
4639
  jsonResponseTool != null ? {
4490
- tools: [...tools != null ? tools : [], jsonResponseTool],
4640
+ tools: [
4641
+ ...(tools != null ? tools : []).filter(
4642
+ (tool) => (toolChoice == null ? void 0 : toolChoice.type) !== "none" && ((toolChoice == null ? void 0 : toolChoice.type) !== "tool" || tool.name === toolChoice.toolName)
4643
+ ),
4644
+ jsonResponseTool
4645
+ ],
4491
4646
  toolChoice: { type: "required" },
4492
4647
  disableParallelToolUse: true,
4493
4648
  cacheControlValidator,
@@ -4498,6 +4653,9 @@ var AnthropicMessagesLanguageModel = class {
4498
4653
  } : {
4499
4654
  tools: tools != null ? tools : [],
4500
4655
  toolChoice,
4656
+ // tool changes can add tools when `tools` is empty, so the tool
4657
+ // choice and parallel tool use settings still apply:
4658
+ hasInlineTools: inlineTools.length > 0,
4501
4659
  disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
4502
4660
  cacheControlValidator,
4503
4661
  supportsStructuredOutput,
@@ -4506,6 +4664,31 @@ var AnthropicMessagesLanguageModel = class {
4506
4664
  rejectsForcedToolUse: rejectsForcedToolUse || thinkingType === "enabled"
4507
4665
  }
4508
4666
  );
4667
+ 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) {
4668
+ const emittedInlineDefinitions = new Set(
4669
+ messagesPrompt.messages.flatMap(
4670
+ (message) => message.role === "system" ? message.content.flatMap(
4671
+ (part) => part.type === "tool_addition" && part.tool.type === "tool_definition" ? [part.tool.definition] : []
4672
+ ) : []
4673
+ )
4674
+ );
4675
+ const selectedSdkName = toolChoice.type === "tool" ? toolChoice.toolName : void 0;
4676
+ const selectedTool = tools == null ? void 0 : tools.find((tool) => tool.name === selectedSdkName);
4677
+ const selectedProviderName = jsonResponseTool != null && selectedSdkName != null && (selectedTool == null ? void 0 : selectedTool.type) !== "function" ? toolNameMapping.toProviderToolName(selectedSdkName) : selectedSdkName;
4678
+ const conflictingTool = inlineToolDefinitions.find(
4679
+ ({ sdkName, definition }) => emittedInlineDefinitions.has(definition) && (toolChoice.type === "none" || // The JSON-tool path filters application tools by SDK name before
4680
+ // conversion; the forced-choice fallback filters by provider name.
4681
+ jsonResponseTool != null && sdkName !== selectedSdkName || !("name" in definition) || definition.name !== selectedProviderName)
4682
+ );
4683
+ if (conflictingTool != null) {
4684
+ const toolName = "name" in conflictingTool.definition ? conflictingTool.definition.name : conflictingTool.definition.type;
4685
+ const choice = toolChoice.type === "tool" ? `named tool choice '${toolChoice.toolName}'` : `tool choice 'none'`;
4686
+ throw new import_provider3.InvalidArgumentError({
4687
+ argument: "toolChoice",
4688
+ message: `Inline tool '${toolName}' conflicts with ${choice}. Inline definitions must respect the tool choice when forced tool use falls back or the JSON response tool is used.`
4689
+ });
4690
+ }
4691
+ }
4509
4692
  const cacheWarnings = cacheControlValidator.getWarnings();
4510
4693
  return {
4511
4694
  args: {