@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.
@@ -1136,9 +1136,15 @@ declare const anthropicTools: {
1136
1136
  }[]>;
1137
1137
  };
1138
1138
 
1139
- declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, defaultEagerInputStreaming, rejectsForcedToolUse, }: {
1139
+ declare function prepareTools({ tools, toolChoice, hasInlineTools, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, defaultEagerInputStreaming, rejectsForcedToolUse, }: {
1140
1140
  tools: LanguageModelV3CallOptions['tools'];
1141
1141
  toolChoice: LanguageModelV3CallOptions['toolChoice'] | undefined;
1142
+ /**
1143
+ * Whether tools are added by value in the prompt (mid-conversation tool
1144
+ * changes). The model has tools even when `tools` is empty, so the tool
1145
+ * choice and parallel tool use settings still need to be sent.
1146
+ */
1147
+ hasInlineTools?: boolean;
1142
1148
  disableParallelToolUse?: boolean;
1143
1149
  cacheControlValidator?: CacheControlValidator;
1144
1150
  /**
@@ -1176,4 +1182,15 @@ declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cache
1176
1182
  */
1177
1183
  declare function sanitizeJsonSchema(schema: JSONSchema7): JSONSchema7;
1178
1184
 
1179
- export { AnthropicMessagesLanguageModel, type AnthropicMessagesModelId, anthropicTools, getModelCapabilities, prepareTools, sanitizeJsonSchema };
1185
+ /**
1186
+ * Whether Anthropic's native structured outputs (`output_config.format`) can
1187
+ * represent a schema without rejecting it or losing data.
1188
+ *
1189
+ * Rejected: self-referencing schemas, and schemas with too many optional
1190
+ * properties. Lossy: open objects (maps, free-form objects), which native
1191
+ * structured outputs close with `additionalProperties: false`, so the model
1192
+ * can only return `{}` for them.
1193
+ */
1194
+ declare function supportsNativeStructuredOutputSchema(schema: JSONSchema7): boolean;
1195
+
1196
+ export { AnthropicMessagesLanguageModel, type AnthropicMessagesModelId, anthropicTools, getModelCapabilities, prepareTools, sanitizeJsonSchema, supportsNativeStructuredOutputSchema };
@@ -1136,9 +1136,15 @@ declare const anthropicTools: {
1136
1136
  }[]>;
1137
1137
  };
1138
1138
 
1139
- declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, defaultEagerInputStreaming, rejectsForcedToolUse, }: {
1139
+ declare function prepareTools({ tools, toolChoice, hasInlineTools, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, defaultEagerInputStreaming, rejectsForcedToolUse, }: {
1140
1140
  tools: LanguageModelV3CallOptions['tools'];
1141
1141
  toolChoice: LanguageModelV3CallOptions['toolChoice'] | undefined;
1142
+ /**
1143
+ * Whether tools are added by value in the prompt (mid-conversation tool
1144
+ * changes). The model has tools even when `tools` is empty, so the tool
1145
+ * choice and parallel tool use settings still need to be sent.
1146
+ */
1147
+ hasInlineTools?: boolean;
1142
1148
  disableParallelToolUse?: boolean;
1143
1149
  cacheControlValidator?: CacheControlValidator;
1144
1150
  /**
@@ -1176,4 +1182,15 @@ declare function prepareTools({ tools, toolChoice, disableParallelToolUse, cache
1176
1182
  */
1177
1183
  declare function sanitizeJsonSchema(schema: JSONSchema7): JSONSchema7;
1178
1184
 
1179
- export { AnthropicMessagesLanguageModel, type AnthropicMessagesModelId, anthropicTools, getModelCapabilities, prepareTools, sanitizeJsonSchema };
1185
+ /**
1186
+ * Whether Anthropic's native structured outputs (`output_config.format`) can
1187
+ * represent a schema without rejecting it or losing data.
1188
+ *
1189
+ * Rejected: self-referencing schemas, and schemas with too many optional
1190
+ * properties. Lossy: open objects (maps, free-form objects), which native
1191
+ * structured outputs close with `additionalProperties: false`, so the model
1192
+ * can only return `{}` for them.
1193
+ */
1194
+ declare function supportsNativeStructuredOutputSchema(schema: JSONSchema7): boolean;
1195
+
1196
+ export { AnthropicMessagesLanguageModel, type AnthropicMessagesModelId, anthropicTools, getModelCapabilities, prepareTools, sanitizeJsonSchema, supportsNativeStructuredOutputSchema };
@@ -24,7 +24,8 @@ __export(index_exports, {
24
24
  anthropicTools: () => anthropicTools,
25
25
  getModelCapabilities: () => getModelCapabilities,
26
26
  prepareTools: () => prepareTools,
27
- sanitizeJsonSchema: () => sanitizeJsonSchema
27
+ sanitizeJsonSchema: () => sanitizeJsonSchema,
28
+ supportsNativeStructuredOutputSchema: () => supportsNativeStructuredOutputSchema
28
29
  });
29
30
  module.exports = __toCommonJS(index_exports);
30
31
 
@@ -919,17 +920,43 @@ var anthropicSystemMessageProviderOptions = (0, import_provider_utils3.lazySchem
919
920
  * initial system prompt). A system message carrying tool changes must come
920
921
  * right before an assistant message or at the end of the messages.
921
922
  *
922
- * Tools referenced by a `tool_addition` must be declared in the `tools`
923
- * option (typically with `deferLoading: true` so they are not loaded until
924
- * the addition surfaces them). The required
925
- * `mid-conversation-tool-changes-2026-07-01` beta is added automatically.
923
+ * A `tool_addition` either references a tool by `toolName` or defines it
924
+ * by value with `tool`:
925
+ * - By reference: the tool must be declared in the `tools` option
926
+ * (typically with `deferLoading: true` so it is not loaded until the
927
+ * addition surfaces it). The required
928
+ * `mid-conversation-tool-changes-2026-07-01` beta is added
929
+ * automatically.
930
+ * - By value: `tool` is a function or provider tool, in the same shape as
931
+ * an entry of the `tools` option. The tool does not need to be declared
932
+ * in `tools`, and defining a tool under an existing name replaces it
933
+ * from that point on. The required `inline-tools-2026-09-15` beta is
934
+ * added automatically.
935
+ *
936
+ * A `tool_removal` always references the tool by `toolName`.
926
937
  */
927
938
  toolChanges: import_v43.z.array(
928
- import_v43.z.discriminatedUnion("type", [
939
+ import_v43.z.union([
929
940
  import_v43.z.object({
930
941
  type: import_v43.z.literal("tool_addition"),
931
942
  toolName: import_v43.z.string()
932
943
  }),
944
+ import_v43.z.object({
945
+ type: import_v43.z.literal("tool_addition"),
946
+ tool: import_v43.z.union([
947
+ import_v43.z.looseObject({
948
+ type: import_v43.z.literal("function"),
949
+ name: import_v43.z.string(),
950
+ inputSchema: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown())
951
+ }),
952
+ import_v43.z.looseObject({
953
+ type: import_v43.z.literal("provider"),
954
+ id: import_v43.z.string(),
955
+ name: import_v43.z.string(),
956
+ args: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown())
957
+ })
958
+ ])
959
+ }),
933
960
  import_v43.z.object({
934
961
  type: import_v43.z.literal("tool_removal"),
935
962
  toolName: import_v43.z.string()
@@ -1627,6 +1654,7 @@ var import_provider_utils11 = require("@ai-sdk/provider-utils");
1627
1654
  async function prepareTools({
1628
1655
  tools,
1629
1656
  toolChoice,
1657
+ hasInlineTools = false,
1630
1658
  disableParallelToolUse,
1631
1659
  cacheControlValidator,
1632
1660
  supportsStructuredOutput,
@@ -1639,11 +1667,11 @@ async function prepareTools({
1639
1667
  const toolWarnings = [];
1640
1668
  const betas = /* @__PURE__ */ new Set();
1641
1669
  const validator = cacheControlValidator || new CacheControlValidator();
1642
- if (tools == null) {
1670
+ if (tools == null && !hasInlineTools) {
1643
1671
  return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
1644
1672
  }
1645
1673
  const anthropicTools2 = [];
1646
- for (const tool of tools) {
1674
+ for (const tool of tools != null ? tools : []) {
1647
1675
  switch (tool.type) {
1648
1676
  case "function": {
1649
1677
  const cacheControl = validator.getCacheControl(tool.providerOptions, {
@@ -1955,9 +1983,10 @@ async function prepareTools({
1955
1983
  }
1956
1984
  }
1957
1985
  }
1986
+ const declaredTools = tools == null ? void 0 : anthropicTools2;
1958
1987
  if (toolChoice == null) {
1959
1988
  return {
1960
- tools: anthropicTools2,
1989
+ tools: declaredTools,
1961
1990
  toolChoice: disableParallelToolUse ? { type: "auto", disable_parallel_tool_use: disableParallelToolUse } : void 0,
1962
1991
  toolWarnings,
1963
1992
  betas
@@ -1967,7 +1996,7 @@ async function prepareTools({
1967
1996
  switch (type) {
1968
1997
  case "auto":
1969
1998
  return {
1970
- tools: anthropicTools2,
1999
+ tools: declaredTools,
1971
2000
  toolChoice: {
1972
2001
  type: "auto",
1973
2002
  disable_parallel_tool_use: disableParallelToolUse
@@ -1983,7 +2012,7 @@ async function prepareTools({
1983
2012
  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.`
1984
2013
  });
1985
2014
  return {
1986
- tools: anthropicTools2,
2015
+ tools: declaredTools,
1987
2016
  toolChoice: {
1988
2017
  type: "auto",
1989
2018
  disable_parallel_tool_use: disableParallelToolUse
@@ -1993,7 +2022,7 @@ async function prepareTools({
1993
2022
  };
1994
2023
  }
1995
2024
  return {
1996
- tools: anthropicTools2,
2025
+ tools: declaredTools,
1997
2026
  toolChoice: {
1998
2027
  type: "any",
1999
2028
  disable_parallel_tool_use: disableParallelToolUse
@@ -2003,7 +2032,7 @@ async function prepareTools({
2003
2032
  };
2004
2033
  case "none":
2005
2034
  return {
2006
- tools: anthropicTools2,
2035
+ tools: declaredTools,
2007
2036
  toolChoice: { type: "none" },
2008
2037
  toolWarnings,
2009
2038
  betas
@@ -2016,7 +2045,7 @@ async function prepareTools({
2016
2045
  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.`
2017
2046
  });
2018
2047
  return {
2019
- tools: anthropicTools2.filter(
2048
+ tools: declaredTools == null ? void 0 : declaredTools.filter(
2020
2049
  (tool) => "name" in tool && tool.name === toolChoice.toolName
2021
2050
  ),
2022
2051
  toolChoice: {
@@ -2028,7 +2057,7 @@ async function prepareTools({
2028
2057
  };
2029
2058
  }
2030
2059
  return {
2031
- tools: anthropicTools2,
2060
+ tools: declaredTools,
2032
2061
  toolChoice: {
2033
2062
  type: "tool",
2034
2063
  name: toolChoice.toolName,
@@ -2448,6 +2477,32 @@ async function extractErrorValue(value) {
2448
2477
  }
2449
2478
  return {};
2450
2479
  }
2480
+ function isComputerTool(tool) {
2481
+ return tool.type === "provider" && tool.id.startsWith("anthropic.computer_");
2482
+ }
2483
+ async function getInlineToolsFromPrompt(prompt) {
2484
+ var _a;
2485
+ const inlineTools = [];
2486
+ for (const message of prompt) {
2487
+ if (message.role !== "system" || message.providerOptions == null) {
2488
+ continue;
2489
+ }
2490
+ const options = await (0, import_provider_utils16.parseProviderOptions)({
2491
+ provider: "anthropic",
2492
+ providerOptions: message.providerOptions,
2493
+ schema: anthropicSystemMessageProviderOptions
2494
+ });
2495
+ for (const toolChange of (_a = options == null ? void 0 : options.toolChanges) != null ? _a : []) {
2496
+ if ("tool" in toolChange) {
2497
+ const tool = toolChange.tool;
2498
+ if (!isComputerTool(tool)) {
2499
+ inlineTools.push(tool);
2500
+ }
2501
+ }
2502
+ }
2503
+ }
2504
+ return inlineTools;
2505
+ }
2451
2506
  async function convertToAnthropicMessagesPrompt({
2452
2507
  prompt,
2453
2508
  sendReasoning,
@@ -2455,7 +2510,8 @@ async function convertToAnthropicMessagesPrompt({
2455
2510
  cacheControlValidator,
2456
2511
  toolNameMapping,
2457
2512
  toolsetNames = {},
2458
- convertMediaPart
2513
+ convertMediaPart,
2514
+ convertInlineTool
2459
2515
  }) {
2460
2516
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
2461
2517
  const betas = /* @__PURE__ */ new Set();
@@ -2492,6 +2548,7 @@ async function convertToAnthropicMessagesPrompt({
2492
2548
  case "system": {
2493
2549
  const systemMessages = [];
2494
2550
  let toolChangeCount = 0;
2551
+ let hasInlineToolDefinition = false;
2495
2552
  let hasMidConversationOptions = false;
2496
2553
  for (const { content: text, providerOptions } of block.messages) {
2497
2554
  const systemMessageOptions = await (0, import_provider_utils16.parseProviderOptions)({
@@ -2514,6 +2571,40 @@ async function convertToAnthropicMessagesPrompt({
2514
2571
  });
2515
2572
  }
2516
2573
  for (const toolChange of toolChanges) {
2574
+ if ("tool" in toolChange) {
2575
+ if (convertInlineTool == null) {
2576
+ throw new import_provider2.UnsupportedFunctionalityError({
2577
+ functionality: "tool additions by value in mid-conversation tool changes"
2578
+ });
2579
+ }
2580
+ const tool = toolChange.tool;
2581
+ if (isComputerTool(tool)) {
2582
+ warnings.push({
2583
+ type: "other",
2584
+ 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.`
2585
+ });
2586
+ continue;
2587
+ }
2588
+ const {
2589
+ definition,
2590
+ warnings: toolWarnings,
2591
+ betas: toolBetas
2592
+ } = await convertInlineTool(tool);
2593
+ warnings.push(...toolWarnings);
2594
+ for (const beta of toolBetas) {
2595
+ betas.add(beta);
2596
+ }
2597
+ if (definition == null) {
2598
+ continue;
2599
+ }
2600
+ content.push({
2601
+ type: "tool_addition",
2602
+ tool: { type: "tool_definition", definition }
2603
+ });
2604
+ toolChangeCount++;
2605
+ hasInlineToolDefinition = true;
2606
+ continue;
2607
+ }
2517
2608
  toolChangeCount++;
2518
2609
  content.push({
2519
2610
  type: toolChange.type,
@@ -2523,6 +2614,9 @@ async function convertToAnthropicMessagesPrompt({
2523
2614
  }
2524
2615
  });
2525
2616
  }
2617
+ if (content.length === 0 && clearAt == null && effort == null) {
2618
+ continue;
2619
+ }
2526
2620
  hasMidConversationOptions || (hasMidConversationOptions = clearAt != null || effort != null);
2527
2621
  systemMessages.push({
2528
2622
  role: "system",
@@ -2557,7 +2651,9 @@ async function convertToAnthropicMessagesPrompt({
2557
2651
  } else {
2558
2652
  messages.push(...systemMessages);
2559
2653
  betas.add("mid-conversation-system-2026-04-07");
2560
- if (toolChangeCount > 0) {
2654
+ if (hasInlineToolDefinition) {
2655
+ betas.add("inline-tools-2026-09-15");
2656
+ } else if (toolChangeCount > 0) {
2561
2657
  betas.add("mid-conversation-tool-changes-2026-07-01");
2562
2658
  }
2563
2659
  if (systemMessages.some((message) => message.clear_at != null)) {
@@ -2791,7 +2887,7 @@ async function convertToAnthropicMessagesPrompt({
2791
2887
  case "json":
2792
2888
  case "error-json":
2793
2889
  default:
2794
- contentValue = JSON.stringify(output.value);
2890
+ contentValue = (0, import_provider_utils16.stringifyWithBigIntAndCycles)(output.value);
2795
2891
  break;
2796
2892
  }
2797
2893
  const toolsetName = getAnthropicToolsetName({
@@ -3029,7 +3125,7 @@ async function convertToAnthropicMessagesPrompt({
3029
3125
  type: "tool_use",
3030
3126
  id: part.toolCallId,
3031
3127
  name: part.toolName,
3032
- input: part.input,
3128
+ input: parseToolCallInput(part.input),
3033
3129
  ...caller && { caller },
3034
3130
  cache_control: cacheControl
3035
3131
  });
@@ -3514,6 +3610,18 @@ function getAnthropicCaller(providerOptions) {
3514
3610
  }
3515
3611
  return (caller == null ? void 0 : caller.type) === "direct" ? { type: "direct" } : void 0;
3516
3612
  }
3613
+ function parseToolCallInput(input) {
3614
+ if (typeof input === "string") {
3615
+ try {
3616
+ const parsed = (0, import_provider_utils16.secureJsonParse)(input);
3617
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
3618
+ return parsed;
3619
+ }
3620
+ } catch (e) {
3621
+ }
3622
+ }
3623
+ return input;
3624
+ }
3517
3625
 
3518
3626
  // src/map-anthropic-stop-reason.ts
3519
3627
  function mapAnthropicStopReason({
@@ -4106,9 +4214,10 @@ var AnthropicMessagesLanguageModel = class {
4106
4214
  }
4107
4215
  const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
4108
4216
  const supportsStructuredOutput = ((_b = this.config.supportsNativeStructuredOutput) != null ? _b : true) && modelSupportsStructuredOutput;
4217
+ const supportsResponseSchema = (responseFormat == null ? void 0 : responseFormat.type) !== "json" || responseFormat.schema == null || supportsNativeStructuredOutputSchema(responseFormat.schema);
4109
4218
  const supportsStrictTools = ((_c = this.config.supportsStrictTools) != null ? _c : true) && modelSupportsStructuredOutput;
4110
4219
  const structureOutputMode = (_d = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _d : "auto";
4111
- let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
4220
+ let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput && supportsResponseSchema;
4112
4221
  if (!useStructuredOutput && rejectsForcedToolUse && modelSupportsStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && supportsNativeStructuredOutputSchema(responseFormat.schema)) {
4113
4222
  warnings.push({
4114
4223
  type: "unsupported",
@@ -4134,8 +4243,22 @@ var AnthropicMessagesLanguageModel = class {
4134
4243
  const cacheControlValidator = new CacheControlValidator(
4135
4244
  this.config.cacheControlProviderOptionsName
4136
4245
  );
4246
+ const defaultEagerInputStreaming = stream && ((_e = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _e : true);
4247
+ const inlineTools = await getInlineToolsFromPrompt(prompt);
4248
+ const declaredFunctionToolNames = new Set(
4249
+ (tools != null ? tools : []).flatMap(
4250
+ (tool) => tool.type === "function" ? [tool.name] : []
4251
+ )
4252
+ );
4137
4253
  const toolNameMapping = (0, import_provider_utils17.createToolNameMapping)({
4138
- tools,
4254
+ // later entries win when provider tool names collide, so the declared
4255
+ // tools go last and an inline tool cannot take over their mapping:
4256
+ tools: [
4257
+ ...inlineTools.filter(
4258
+ (tool) => !(tool.type === "provider" && declaredFunctionToolNames.has(tool.name))
4259
+ ),
4260
+ ...tools != null ? tools : []
4261
+ ],
4139
4262
  providerToolNames: {
4140
4263
  "anthropic.code_execution_20250522": "code_execution",
4141
4264
  "anthropic.code_execution_20250825": "code_execution",
@@ -4161,14 +4284,43 @@ var AnthropicMessagesLanguageModel = class {
4161
4284
  }
4162
4285
  });
4163
4286
  const toolsetNames = getAnthropicToolsetNames(tools);
4287
+ const inlineToolDefinitions = [];
4164
4288
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
4165
4289
  prompt,
4166
- sendReasoning: (_e = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _e : true,
4290
+ sendReasoning: (_f = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _f : true,
4167
4291
  warnings,
4168
4292
  cacheControlValidator,
4169
4293
  toolNameMapping,
4170
4294
  toolsetNames,
4171
- convertMediaPart: this.config.convertMediaPart
4295
+ convertMediaPart: this.config.convertMediaPart,
4296
+ convertInlineTool: async (tool) => {
4297
+ const {
4298
+ tools: definitions,
4299
+ toolWarnings: toolWarnings2,
4300
+ betas: betas2
4301
+ } = await prepareTools({
4302
+ tools: [tool],
4303
+ toolChoice: void 0,
4304
+ cacheControlValidator,
4305
+ supportsStructuredOutput,
4306
+ supportsStrictTools
4307
+ // no stream-dependent defaults (eager input streaming): the
4308
+ // definition is replayed on every request and has to stay
4309
+ // identical between streaming and non-streaming calls to keep
4310
+ // the cache.
4311
+ });
4312
+ if ((definitions == null ? void 0 : definitions[0]) != null) {
4313
+ inlineToolDefinitions.push({
4314
+ sdkName: tool.name,
4315
+ definition: definitions[0]
4316
+ });
4317
+ }
4318
+ return {
4319
+ definition: definitions == null ? void 0 : definitions[0],
4320
+ warnings: toolWarnings2,
4321
+ betas: betas2
4322
+ };
4323
+ }
4172
4324
  });
4173
4325
  if (rejectsThinkingDisabled && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null) {
4174
4326
  const requestedThinking = anthropicOptions.thinking;
@@ -4278,7 +4430,7 @@ var AnthropicMessagesLanguageModel = class {
4278
4430
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
4279
4431
  cache_control: anthropicOptions.cacheControl
4280
4432
  },
4281
- ...((_f = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _f.userId) != null && {
4433
+ ...((_g = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _g.userId) != null && {
4282
4434
  metadata: { user_id: anthropicOptions.metadata.userId }
4283
4435
  },
4284
4436
  // mcp servers:
@@ -4473,7 +4625,6 @@ var AnthropicMessagesLanguageModel = class {
4473
4625
  } else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
4474
4626
  betas.add("server-side-fallback-2026-06-01");
4475
4627
  }
4476
- const defaultEagerInputStreaming = stream && ((_g = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _g : true);
4477
4628
  const {
4478
4629
  tools: anthropicTools2,
4479
4630
  toolChoice: anthropicToolChoice,
@@ -4481,7 +4632,12 @@ var AnthropicMessagesLanguageModel = class {
4481
4632
  betas: toolsBetas
4482
4633
  } = await prepareTools(
4483
4634
  jsonResponseTool != null ? {
4484
- tools: [...tools != null ? tools : [], jsonResponseTool],
4635
+ tools: [
4636
+ ...(tools != null ? tools : []).filter(
4637
+ (tool) => (toolChoice == null ? void 0 : toolChoice.type) !== "none" && ((toolChoice == null ? void 0 : toolChoice.type) !== "tool" || tool.name === toolChoice.toolName)
4638
+ ),
4639
+ jsonResponseTool
4640
+ ],
4485
4641
  toolChoice: { type: "required" },
4486
4642
  disableParallelToolUse: true,
4487
4643
  cacheControlValidator,
@@ -4492,6 +4648,9 @@ var AnthropicMessagesLanguageModel = class {
4492
4648
  } : {
4493
4649
  tools: tools != null ? tools : [],
4494
4650
  toolChoice,
4651
+ // tool changes can add tools when `tools` is empty, so the tool
4652
+ // choice and parallel tool use settings still apply:
4653
+ hasInlineTools: inlineTools.length > 0,
4495
4654
  disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
4496
4655
  cacheControlValidator,
4497
4656
  supportsStructuredOutput,
@@ -4500,6 +4659,31 @@ var AnthropicMessagesLanguageModel = class {
4500
4659
  rejectsForcedToolUse: rejectsForcedToolUse || thinkingType === "enabled"
4501
4660
  }
4502
4661
  );
4662
+ 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) {
4663
+ const emittedInlineDefinitions = new Set(
4664
+ messagesPrompt.messages.flatMap(
4665
+ (message) => message.role === "system" ? message.content.flatMap(
4666
+ (part) => part.type === "tool_addition" && part.tool.type === "tool_definition" ? [part.tool.definition] : []
4667
+ ) : []
4668
+ )
4669
+ );
4670
+ const selectedSdkName = toolChoice.type === "tool" ? toolChoice.toolName : void 0;
4671
+ const selectedTool = tools == null ? void 0 : tools.find((tool) => tool.name === selectedSdkName);
4672
+ const selectedProviderName = jsonResponseTool != null && selectedSdkName != null && (selectedTool == null ? void 0 : selectedTool.type) !== "function" ? toolNameMapping.toProviderToolName(selectedSdkName) : selectedSdkName;
4673
+ const conflictingTool = inlineToolDefinitions.find(
4674
+ ({ sdkName, definition }) => emittedInlineDefinitions.has(definition) && (toolChoice.type === "none" || // The JSON-tool path filters application tools by SDK name before
4675
+ // conversion; the forced-choice fallback filters by provider name.
4676
+ jsonResponseTool != null && sdkName !== selectedSdkName || !("name" in definition) || definition.name !== selectedProviderName)
4677
+ );
4678
+ if (conflictingTool != null) {
4679
+ const toolName = "name" in conflictingTool.definition ? conflictingTool.definition.name : conflictingTool.definition.type;
4680
+ const choice = toolChoice.type === "tool" ? `named tool choice '${toolChoice.toolName}'` : `tool choice 'none'`;
4681
+ throw new import_provider3.InvalidArgumentError({
4682
+ argument: "toolChoice",
4683
+ 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.`
4684
+ });
4685
+ }
4686
+ }
4503
4687
  const cacheWarnings = cacheControlValidator.getWarnings();
4504
4688
  return {
4505
4689
  args: {
@@ -6900,6 +7084,7 @@ var anthropicTools = {
6900
7084
  anthropicTools,
6901
7085
  getModelCapabilities,
6902
7086
  prepareTools,
6903
- sanitizeJsonSchema
7087
+ sanitizeJsonSchema,
7088
+ supportsNativeStructuredOutputSchema
6904
7089
  });
6905
7090
  //# sourceMappingURL=index.js.map