@ai-sdk/anthropic 3.0.138 → 3.0.140
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 +15 -0
- package/dist/index.d.mts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +195 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +198 -26
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +7 -1
- package/dist/internal/index.d.ts +7 -1
- package/dist/internal/index.js +194 -23
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +195 -23
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +67 -2
- package/package.json +2 -2
- package/src/anthropic-messages-api.ts +19 -6
- package/src/anthropic-messages-language-model.ts +132 -4
- package/src/anthropic-messages-options.ts +31 -5
- package/src/anthropic-prepare-tools.ts +21 -9
- package/src/convert-to-anthropic-messages-prompt.ts +126 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 3.0.140
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c8feb7c: Disable MCP connector tools when structured output falls back to the JSON response tool and the caller selects no tools or a named application tool, and when a named application tool choice falls back to automatic tool selection.
|
|
8
|
+
- Updated dependencies [f0dee4b]
|
|
9
|
+
- @ai-sdk/provider-utils@4.0.65
|
|
10
|
+
|
|
11
|
+
## 3.0.139
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 25c71b9: feat(anthropic): support adding tools by value in mid-conversation `toolChanges` (`inline-tools-2026-09-15`)
|
|
16
|
+
- 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.
|
|
17
|
+
|
|
3
18
|
## 3.0.138
|
|
4
19
|
|
|
5
20
|
### 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.
|
|
35
|
+
var VERSION = true ? "3.0.140" : "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
|
-
*
|
|
929
|
-
*
|
|
930
|
-
* the
|
|
931
|
-
* `
|
|
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.
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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 (
|
|
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)) {
|
|
@@ -4024,7 +4119,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4024
4119
|
providerOptions,
|
|
4025
4120
|
stream
|
|
4026
4121
|
}) {
|
|
4027
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
4122
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
4028
4123
|
const warnings = [];
|
|
4029
4124
|
if (frequencyPenalty != null) {
|
|
4030
4125
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -4153,8 +4248,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4153
4248
|
const cacheControlValidator = new CacheControlValidator(
|
|
4154
4249
|
this.config.cacheControlProviderOptionsName
|
|
4155
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
|
+
);
|
|
4156
4258
|
const toolNameMapping = (0, import_provider_utils17.createToolNameMapping)({
|
|
4157
|
-
|
|
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
|
+
],
|
|
4158
4267
|
providerToolNames: {
|
|
4159
4268
|
"anthropic.code_execution_20250522": "code_execution",
|
|
4160
4269
|
"anthropic.code_execution_20250825": "code_execution",
|
|
@@ -4180,14 +4289,43 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4180
4289
|
}
|
|
4181
4290
|
});
|
|
4182
4291
|
const toolsetNames = getAnthropicToolsetNames(tools);
|
|
4292
|
+
const inlineToolDefinitions = [];
|
|
4183
4293
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
4184
4294
|
prompt,
|
|
4185
|
-
sendReasoning: (
|
|
4295
|
+
sendReasoning: (_f = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _f : true,
|
|
4186
4296
|
warnings,
|
|
4187
4297
|
cacheControlValidator,
|
|
4188
4298
|
toolNameMapping,
|
|
4189
4299
|
toolsetNames,
|
|
4190
|
-
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
|
+
}
|
|
4191
4329
|
});
|
|
4192
4330
|
if (rejectsThinkingDisabled && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null) {
|
|
4193
4331
|
const requestedThinking = anthropicOptions.thinking;
|
|
@@ -4297,7 +4435,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4297
4435
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
4298
4436
|
cache_control: anthropicOptions.cacheControl
|
|
4299
4437
|
},
|
|
4300
|
-
...((
|
|
4438
|
+
...((_g = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _g.userId) != null && {
|
|
4301
4439
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
4302
4440
|
},
|
|
4303
4441
|
// mcp servers:
|
|
@@ -4492,7 +4630,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4492
4630
|
} else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
|
|
4493
4631
|
betas.add("server-side-fallback-2026-06-01");
|
|
4494
4632
|
}
|
|
4495
|
-
const defaultEagerInputStreaming = stream && ((_g = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _g : true);
|
|
4496
4633
|
const {
|
|
4497
4634
|
tools: anthropicTools2,
|
|
4498
4635
|
toolChoice: anthropicToolChoice,
|
|
@@ -4516,6 +4653,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4516
4653
|
} : {
|
|
4517
4654
|
tools: tools != null ? tools : [],
|
|
4518
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,
|
|
4519
4659
|
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
|
|
4520
4660
|
cacheControlValidator,
|
|
4521
4661
|
supportsStructuredOutput,
|
|
@@ -4524,6 +4664,37 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4524
4664
|
rejectsForcedToolUse: rejectsForcedToolUse || thinkingType === "enabled"
|
|
4525
4665
|
}
|
|
4526
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
|
+
for (const server of (_h = baseArgs.mcp_servers) != null ? _h : []) {
|
|
4669
|
+
server.tool_configuration = {
|
|
4670
|
+
allowed_tools: (_i = server.tool_configuration) == null ? void 0 : _i.allowed_tools,
|
|
4671
|
+
enabled: false
|
|
4672
|
+
};
|
|
4673
|
+
}
|
|
4674
|
+
const emittedInlineDefinitions = new Set(
|
|
4675
|
+
messagesPrompt.messages.flatMap(
|
|
4676
|
+
(message) => message.role === "system" ? message.content.flatMap(
|
|
4677
|
+
(part) => part.type === "tool_addition" && part.tool.type === "tool_definition" ? [part.tool.definition] : []
|
|
4678
|
+
) : []
|
|
4679
|
+
)
|
|
4680
|
+
);
|
|
4681
|
+
const selectedSdkName = toolChoice.type === "tool" ? toolChoice.toolName : void 0;
|
|
4682
|
+
const selectedTool = tools == null ? void 0 : tools.find((tool) => tool.name === selectedSdkName);
|
|
4683
|
+
const selectedProviderName = jsonResponseTool != null && selectedSdkName != null && (selectedTool == null ? void 0 : selectedTool.type) !== "function" ? toolNameMapping.toProviderToolName(selectedSdkName) : selectedSdkName;
|
|
4684
|
+
const conflictingTool = inlineToolDefinitions.find(
|
|
4685
|
+
({ sdkName, definition }) => emittedInlineDefinitions.has(definition) && (toolChoice.type === "none" || // The JSON-tool path filters application tools by SDK name before
|
|
4686
|
+
// conversion; the forced-choice fallback filters by provider name.
|
|
4687
|
+
jsonResponseTool != null && sdkName !== selectedSdkName || !("name" in definition) || definition.name !== selectedProviderName)
|
|
4688
|
+
);
|
|
4689
|
+
if (conflictingTool != null) {
|
|
4690
|
+
const toolName = "name" in conflictingTool.definition ? conflictingTool.definition.name : conflictingTool.definition.type;
|
|
4691
|
+
const choice = toolChoice.type === "tool" ? `named tool choice '${toolChoice.toolName}'` : `tool choice 'none'`;
|
|
4692
|
+
throw new import_provider3.InvalidArgumentError({
|
|
4693
|
+
argument: "toolChoice",
|
|
4694
|
+
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.`
|
|
4695
|
+
});
|
|
4696
|
+
}
|
|
4697
|
+
}
|
|
4527
4698
|
const cacheWarnings = cacheControlValidator.getWarnings();
|
|
4528
4699
|
return {
|
|
4529
4700
|
args: {
|
|
@@ -4538,7 +4709,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4538
4709
|
...betas,
|
|
4539
4710
|
...toolsBetas,
|
|
4540
4711
|
...userSuppliedBetas,
|
|
4541
|
-
...(
|
|
4712
|
+
...(_j = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _j : []
|
|
4542
4713
|
]),
|
|
4543
4714
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
4544
4715
|
toolNameMapping,
|