@ai-sdk/anthropic 4.0.18 → 4.0.20
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 +14 -0
- package/dist/index.d.ts +17 -4
- package/dist/index.js +182 -67
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +2 -1
- package/dist/internal/index.js +181 -66
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +79 -2
- package/package.json +3 -3
- package/src/anthropic-api.ts +14 -1
- package/src/anthropic-language-model-options.ts +64 -20
- package/src/anthropic-language-model.ts +77 -5
- package/src/convert-to-anthropic-prompt.ts +64 -12
- package/src/index.ts +1 -0
package/dist/internal/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ declare class AnthropicFiles implements FilesV4 {
|
|
|
16
16
|
uploadFile({ data, mediaType, filename, }: FilesV4UploadFileCallOptions): Promise<FilesV4UploadFileResult>;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
type AnthropicModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});
|
|
19
|
+
type AnthropicModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});
|
|
20
20
|
|
|
21
21
|
type AnthropicLanguageModelConfig = {
|
|
22
22
|
provider: string;
|
|
@@ -80,6 +80,7 @@ declare function getModelCapabilities(modelId: string): {
|
|
|
80
80
|
supportsAdaptiveThinking: boolean;
|
|
81
81
|
rejectsSamplingParameters: boolean;
|
|
82
82
|
supportsXhighEffort: boolean;
|
|
83
|
+
rejectsThinkingDisabledAboveHighEffort: boolean;
|
|
83
84
|
isKnownModel: boolean;
|
|
84
85
|
};
|
|
85
86
|
|
package/dist/internal/index.js
CHANGED
|
@@ -966,6 +966,34 @@ var anthropicFilePartProviderOptions = z4.object({
|
|
|
966
966
|
*/
|
|
967
967
|
context: z4.string().optional()
|
|
968
968
|
});
|
|
969
|
+
var anthropicSystemMessageProviderOptions = z4.object({
|
|
970
|
+
/**
|
|
971
|
+
* Mid-conversation tool changes. Adds or removes tools from the
|
|
972
|
+
* conversation's tool set between turns without invalidating the prompt
|
|
973
|
+
* cache.
|
|
974
|
+
*
|
|
975
|
+
* Only supported on system messages that appear mid-conversation (not the
|
|
976
|
+
* initial system prompt). A system message carrying tool changes must come
|
|
977
|
+
* right before an assistant message or at the end of the messages.
|
|
978
|
+
*
|
|
979
|
+
* Tools referenced by a `tool_addition` must be declared in the `tools`
|
|
980
|
+
* option (typically with `deferLoading: true` so they are not loaded until
|
|
981
|
+
* the addition surfaces them). The required
|
|
982
|
+
* `mid-conversation-tool-changes-2026-07-01` beta is added automatically.
|
|
983
|
+
*/
|
|
984
|
+
toolChanges: z4.array(
|
|
985
|
+
z4.discriminatedUnion("type", [
|
|
986
|
+
z4.object({
|
|
987
|
+
type: z4.literal("tool_addition"),
|
|
988
|
+
toolName: z4.string()
|
|
989
|
+
}),
|
|
990
|
+
z4.object({
|
|
991
|
+
type: z4.literal("tool_removal"),
|
|
992
|
+
toolName: z4.string()
|
|
993
|
+
})
|
|
994
|
+
])
|
|
995
|
+
).optional()
|
|
996
|
+
});
|
|
969
997
|
var anthropicLanguageModelOptions = z4.object({
|
|
970
998
|
/**
|
|
971
999
|
* Whether to send reasoning to the model.
|
|
@@ -1112,30 +1140,35 @@ var anthropicLanguageModelOptions = z4.object({
|
|
|
1112
1140
|
*/
|
|
1113
1141
|
inferenceGeo: z4.enum(["us", "global"]).optional(),
|
|
1114
1142
|
/**
|
|
1115
|
-
* Server-side fallback
|
|
1143
|
+
* Server-side fallback configuration.
|
|
1116
1144
|
*
|
|
1117
1145
|
* When the primary model's safety classifiers block a turn, the API
|
|
1118
|
-
* automatically retries it on
|
|
1119
|
-
* `content-filter` finish reason means the
|
|
1120
|
-
*
|
|
1121
|
-
* Each entry is merged into the request as a direct request to that entry's
|
|
1122
|
-
* model, so it must be formatted accordingly: `model` is required, and an
|
|
1123
|
-
* entry may additionally override `max_tokens`, `thinking`, `output_config`,
|
|
1124
|
-
* and `speed` for that attempt only (`speed` additionally requires the speed
|
|
1125
|
-
* beta). The value is passed through to the API as-is.
|
|
1146
|
+
* automatically retries it server-side on a fallback model. A
|
|
1147
|
+
* `content-filter` finish reason means the fallback(s) refused as well.
|
|
1126
1148
|
*
|
|
1127
|
-
*
|
|
1128
|
-
*
|
|
1149
|
+
* - `'default'` (recommended): the API routes the retry to Anthropic's
|
|
1150
|
+
* recommended fallback model based on the refusal category. Requires the
|
|
1151
|
+
* `server-side-fallback-2026-07-01` beta, which is added automatically.
|
|
1152
|
+
* - Array form: an explicit fallback chain. Each entry is merged into the
|
|
1153
|
+
* request as a direct request to that entry's model, so it must be
|
|
1154
|
+
* formatted accordingly: `model` is required, and an entry may
|
|
1155
|
+
* additionally override `max_tokens`, `thinking`, `output_config`, and
|
|
1156
|
+
* `speed` for that attempt only (`speed` additionally requires the speed
|
|
1157
|
+
* beta). The value is passed through to the API as-is, and the
|
|
1158
|
+
* `server-side-fallback-2026-06-01` beta is added automatically.
|
|
1129
1159
|
*/
|
|
1130
|
-
fallbacks: z4.
|
|
1131
|
-
z4.
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1160
|
+
fallbacks: z4.union([
|
|
1161
|
+
z4.literal("default"),
|
|
1162
|
+
z4.array(
|
|
1163
|
+
z4.object({
|
|
1164
|
+
model: z4.string(),
|
|
1165
|
+
max_tokens: z4.number().int().optional(),
|
|
1166
|
+
thinking: z4.record(z4.string(), z4.unknown()).optional(),
|
|
1167
|
+
output_config: z4.record(z4.string(), z4.unknown()).optional(),
|
|
1168
|
+
speed: z4.enum(["fast", "standard"]).optional()
|
|
1169
|
+
})
|
|
1170
|
+
)
|
|
1171
|
+
]).optional(),
|
|
1139
1172
|
/**
|
|
1140
1173
|
* A set of beta features to enable.
|
|
1141
1174
|
* Allow a provider to receive the full `betas` set if it needs it.
|
|
@@ -2328,7 +2361,7 @@ async function convertToAnthropicPrompt({
|
|
|
2328
2361
|
cacheControlValidator,
|
|
2329
2362
|
toolNameMapping
|
|
2330
2363
|
}) {
|
|
2331
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
2364
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
2332
2365
|
const betas = /* @__PURE__ */ new Set();
|
|
2333
2366
|
const blocks = groupIntoBlocks(prompt);
|
|
2334
2367
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -2369,19 +2402,52 @@ async function convertToAnthropicPrompt({
|
|
|
2369
2402
|
const type = block.type;
|
|
2370
2403
|
switch (type) {
|
|
2371
2404
|
case "system": {
|
|
2372
|
-
const content =
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2405
|
+
const content = [];
|
|
2406
|
+
let toolChangeCount = 0;
|
|
2407
|
+
for (const { content: text, providerOptions } of block.messages) {
|
|
2408
|
+
const systemMessageOptions = await parseProviderOptions({
|
|
2409
|
+
provider: "anthropic",
|
|
2410
|
+
providerOptions,
|
|
2411
|
+
schema: anthropicSystemMessageProviderOptions
|
|
2412
|
+
});
|
|
2413
|
+
const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
|
|
2414
|
+
if (text !== "" || toolChanges.length === 0) {
|
|
2415
|
+
content.push({
|
|
2416
|
+
type: "text",
|
|
2417
|
+
text,
|
|
2418
|
+
cache_control: validator.getCacheControl(providerOptions, {
|
|
2419
|
+
type: "system message",
|
|
2420
|
+
canCache: true
|
|
2421
|
+
})
|
|
2422
|
+
});
|
|
2423
|
+
}
|
|
2424
|
+
for (const toolChange of toolChanges) {
|
|
2425
|
+
toolChangeCount++;
|
|
2426
|
+
content.push({
|
|
2427
|
+
type: toolChange.type,
|
|
2428
|
+
tool: {
|
|
2429
|
+
type: "tool_reference",
|
|
2430
|
+
name: toolNameMapping.toProviderToolName(toolChange.toolName)
|
|
2431
|
+
}
|
|
2432
|
+
});
|
|
2433
|
+
}
|
|
2434
|
+
}
|
|
2435
|
+
if (i === 0 || system == null && toolChangeCount === 0) {
|
|
2436
|
+
if (toolChangeCount > 0) {
|
|
2437
|
+
warnings.push({
|
|
2438
|
+
type: "other",
|
|
2439
|
+
message: "tool changes on the initial system message are not supported by Anthropic. Configure the initial tool set via the tools option instead. The tool changes have been ignored."
|
|
2440
|
+
});
|
|
2441
|
+
}
|
|
2442
|
+
system = content.filter(
|
|
2443
|
+
(part) => part.type === "text"
|
|
2444
|
+
);
|
|
2382
2445
|
} else {
|
|
2383
2446
|
messages.push({ role: "system", content });
|
|
2384
2447
|
betas.add("mid-conversation-system-2026-04-07");
|
|
2448
|
+
if (toolChangeCount > 0) {
|
|
2449
|
+
betas.add("mid-conversation-tool-changes-2026-07-01");
|
|
2450
|
+
}
|
|
2385
2451
|
}
|
|
2386
2452
|
break;
|
|
2387
2453
|
}
|
|
@@ -2394,10 +2460,10 @@ async function convertToAnthropicPrompt({
|
|
|
2394
2460
|
for (let j = 0; j < content.length; j++) {
|
|
2395
2461
|
const part = content[j];
|
|
2396
2462
|
const isLastPart = j === content.length - 1;
|
|
2397
|
-
const cacheControl = (
|
|
2463
|
+
const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
|
|
2398
2464
|
type: "user message part",
|
|
2399
2465
|
canCache: true
|
|
2400
|
-
})) != null ?
|
|
2466
|
+
})) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
2401
2467
|
type: "user message",
|
|
2402
2468
|
canCache: true
|
|
2403
2469
|
}) : void 0;
|
|
@@ -2452,7 +2518,7 @@ async function convertToAnthropicPrompt({
|
|
|
2452
2518
|
media_type: "text/plain",
|
|
2453
2519
|
data: part.data.text
|
|
2454
2520
|
},
|
|
2455
|
-
title: (
|
|
2521
|
+
title: (_c = metadata.title) != null ? _c : part.filename,
|
|
2456
2522
|
...metadata.context && {
|
|
2457
2523
|
context: metadata.context
|
|
2458
2524
|
},
|
|
@@ -2497,7 +2563,7 @@ async function convertToAnthropicPrompt({
|
|
|
2497
2563
|
media_type: "application/pdf",
|
|
2498
2564
|
data: convertToBase64(part.data.data)
|
|
2499
2565
|
},
|
|
2500
|
-
title: (
|
|
2566
|
+
title: (_d = metadata.title) != null ? _d : part.filename,
|
|
2501
2567
|
...metadata.context && {
|
|
2502
2568
|
context: metadata.context
|
|
2503
2569
|
},
|
|
@@ -2525,7 +2591,7 @@ async function convertToAnthropicPrompt({
|
|
|
2525
2591
|
part.data.data
|
|
2526
2592
|
)
|
|
2527
2593
|
},
|
|
2528
|
-
title: (
|
|
2594
|
+
title: (_e = metadata.title) != null ? _e : part.filename,
|
|
2529
2595
|
...metadata.context && {
|
|
2530
2596
|
context: metadata.context
|
|
2531
2597
|
},
|
|
@@ -2555,17 +2621,17 @@ async function convertToAnthropicPrompt({
|
|
|
2555
2621
|
continue;
|
|
2556
2622
|
}
|
|
2557
2623
|
const output = part.output;
|
|
2558
|
-
const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (
|
|
2624
|
+
const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (_f = output.value.find(
|
|
2559
2625
|
(contentPart) => contentPart.providerOptions != null
|
|
2560
|
-
)) == null ? void 0 :
|
|
2626
|
+
)) == null ? void 0 : _f.providerOptions : void 0;
|
|
2561
2627
|
const isLastPart = i2 === content.length - 1;
|
|
2562
|
-
const cacheControl = (
|
|
2628
|
+
const cacheControl = (_h = (_g = validator.getCacheControl(part.providerOptions, {
|
|
2563
2629
|
type: "tool result part",
|
|
2564
2630
|
canCache: true
|
|
2565
|
-
})) != null ?
|
|
2631
|
+
})) != null ? _g : validator.getCacheControl(outputProviderOptions, {
|
|
2566
2632
|
type: "tool result output",
|
|
2567
2633
|
canCache: true
|
|
2568
|
-
})) != null ?
|
|
2634
|
+
})) != null ? _h : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
2569
2635
|
type: "tool result message",
|
|
2570
2636
|
canCache: true
|
|
2571
2637
|
}) : void 0;
|
|
@@ -2671,7 +2737,7 @@ async function convertToAnthropicPrompt({
|
|
|
2671
2737
|
contentValue = output.value;
|
|
2672
2738
|
break;
|
|
2673
2739
|
case "execution-denied":
|
|
2674
|
-
contentValue = (
|
|
2740
|
+
contentValue = (_i = output.reason) != null ? _i : "Tool call execution denied.";
|
|
2675
2741
|
break;
|
|
2676
2742
|
case "json":
|
|
2677
2743
|
case "error-json":
|
|
@@ -2708,16 +2774,16 @@ async function convertToAnthropicPrompt({
|
|
|
2708
2774
|
for (let k = 0; k < content.length; k++) {
|
|
2709
2775
|
const part = content[k];
|
|
2710
2776
|
const isLastContentPart = k === content.length - 1;
|
|
2711
|
-
const cacheControl = (
|
|
2777
|
+
const cacheControl = (_j = validator.getCacheControl(part.providerOptions, {
|
|
2712
2778
|
type: "assistant message part",
|
|
2713
2779
|
canCache: true
|
|
2714
|
-
})) != null ?
|
|
2780
|
+
})) != null ? _j : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
|
|
2715
2781
|
type: "assistant message",
|
|
2716
2782
|
canCache: true
|
|
2717
2783
|
}) : void 0;
|
|
2718
2784
|
switch (part.type) {
|
|
2719
2785
|
case "text": {
|
|
2720
|
-
const textMetadata = (
|
|
2786
|
+
const textMetadata = (_k = part.providerOptions) == null ? void 0 : _k.anthropic;
|
|
2721
2787
|
if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
|
|
2722
2788
|
anthropicContent.push({
|
|
2723
2789
|
type: "compaction",
|
|
@@ -2793,10 +2859,10 @@ async function convertToAnthropicPrompt({
|
|
|
2793
2859
|
const providerToolName = toolNameMapping.toProviderToolName(
|
|
2794
2860
|
part.toolName
|
|
2795
2861
|
);
|
|
2796
|
-
const isMcpToolUse = ((
|
|
2862
|
+
const isMcpToolUse = ((_m = (_l = part.providerOptions) == null ? void 0 : _l.anthropic) == null ? void 0 : _m.type) === "mcp-tool-use";
|
|
2797
2863
|
if (isMcpToolUse) {
|
|
2798
2864
|
mcpToolUseIds.add(part.toolCallId);
|
|
2799
|
-
const serverName = (
|
|
2865
|
+
const serverName = (_o = (_n = part.providerOptions) == null ? void 0 : _n.anthropic) == null ? void 0 : _o.serverName;
|
|
2800
2866
|
if (serverName == null || typeof serverName !== "string") {
|
|
2801
2867
|
warnings.push({
|
|
2802
2868
|
type: "other",
|
|
@@ -2872,7 +2938,7 @@ async function convertToAnthropicPrompt({
|
|
|
2872
2938
|
}
|
|
2873
2939
|
break;
|
|
2874
2940
|
}
|
|
2875
|
-
const callerOptions = (
|
|
2941
|
+
const callerOptions = (_p = part.providerOptions) == null ? void 0 : _p.anthropic;
|
|
2876
2942
|
const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? (callerOptions.caller.type === "code_execution_20250825" || callerOptions.caller.type === "code_execution_20260120") && callerOptions.caller.toolId ? {
|
|
2877
2943
|
type: callerOptions.caller.type,
|
|
2878
2944
|
tool_id: callerOptions.caller.toolId
|
|
@@ -2925,7 +2991,7 @@ async function convertToAnthropicPrompt({
|
|
|
2925
2991
|
tool_use_id: part.toolCallId,
|
|
2926
2992
|
content: {
|
|
2927
2993
|
type: "code_execution_tool_result_error",
|
|
2928
|
-
error_code: (
|
|
2994
|
+
error_code: (_q = errorInfo.errorCode) != null ? _q : "unknown"
|
|
2929
2995
|
},
|
|
2930
2996
|
cache_control: cacheControl
|
|
2931
2997
|
});
|
|
@@ -2936,7 +3002,7 @@ async function convertToAnthropicPrompt({
|
|
|
2936
3002
|
cache_control: cacheControl,
|
|
2937
3003
|
content: {
|
|
2938
3004
|
type: "bash_code_execution_tool_result_error",
|
|
2939
|
-
error_code: (
|
|
3005
|
+
error_code: (_r = errorInfo.errorCode) != null ? _r : "unknown"
|
|
2940
3006
|
}
|
|
2941
3007
|
});
|
|
2942
3008
|
}
|
|
@@ -2969,7 +3035,7 @@ async function convertToAnthropicPrompt({
|
|
|
2969
3035
|
stdout: codeExecutionOutput.stdout,
|
|
2970
3036
|
stderr: codeExecutionOutput.stderr,
|
|
2971
3037
|
return_code: codeExecutionOutput.return_code,
|
|
2972
|
-
content: (
|
|
3038
|
+
content: (_s = codeExecutionOutput.content) != null ? _s : []
|
|
2973
3039
|
},
|
|
2974
3040
|
cache_control: cacheControl
|
|
2975
3041
|
});
|
|
@@ -2987,7 +3053,7 @@ async function convertToAnthropicPrompt({
|
|
|
2987
3053
|
encrypted_stdout: codeExecutionOutput.encrypted_stdout,
|
|
2988
3054
|
stderr: codeExecutionOutput.stderr,
|
|
2989
3055
|
return_code: codeExecutionOutput.return_code,
|
|
2990
|
-
content: (
|
|
3056
|
+
content: (_t = codeExecutionOutput.content) != null ? _t : []
|
|
2991
3057
|
},
|
|
2992
3058
|
cache_control: cacheControl
|
|
2993
3059
|
});
|
|
@@ -3006,7 +3072,7 @@ async function convertToAnthropicPrompt({
|
|
|
3006
3072
|
stdout: codeExecutionOutput.stdout,
|
|
3007
3073
|
stderr: codeExecutionOutput.stderr,
|
|
3008
3074
|
return_code: codeExecutionOutput.return_code,
|
|
3009
|
-
content: (
|
|
3075
|
+
content: (_u = codeExecutionOutput.content) != null ? _u : []
|
|
3010
3076
|
},
|
|
3011
3077
|
cache_control: cacheControl
|
|
3012
3078
|
});
|
|
@@ -3036,7 +3102,7 @@ async function convertToAnthropicPrompt({
|
|
|
3036
3102
|
tool_use_id: part.toolCallId,
|
|
3037
3103
|
content: {
|
|
3038
3104
|
type: "web_fetch_tool_result_error",
|
|
3039
|
-
error_code: (
|
|
3105
|
+
error_code: (_v = extractErrorValue(output.value).errorCode) != null ? _v : "unavailable"
|
|
3040
3106
|
},
|
|
3041
3107
|
cache_control: cacheControl
|
|
3042
3108
|
});
|
|
@@ -3083,7 +3149,7 @@ async function convertToAnthropicPrompt({
|
|
|
3083
3149
|
tool_use_id: part.toolCallId,
|
|
3084
3150
|
content: {
|
|
3085
3151
|
type: "web_search_tool_result_error",
|
|
3086
|
-
error_code: (
|
|
3152
|
+
error_code: (_w = extractErrorValue(output.value).errorCode) != null ? _w : "unavailable"
|
|
3087
3153
|
},
|
|
3088
3154
|
cache_control: cacheControl
|
|
3089
3155
|
});
|
|
@@ -3554,7 +3620,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3554
3620
|
providerOptions,
|
|
3555
3621
|
stream
|
|
3556
3622
|
}) {
|
|
3557
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3623
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
3558
3624
|
const warnings = [];
|
|
3559
3625
|
if (frequencyPenalty != null) {
|
|
3560
3626
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -3612,6 +3678,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3612
3678
|
supportsAdaptiveThinking,
|
|
3613
3679
|
rejectsSamplingParameters,
|
|
3614
3680
|
supportsXhighEffort,
|
|
3681
|
+
rejectsThinkingDisabledAboveHighEffort,
|
|
3615
3682
|
isKnownModel
|
|
3616
3683
|
} = getModelCapabilities(this.modelId);
|
|
3617
3684
|
if (!isKnownModel && maxOutputTokens == null) {
|
|
@@ -3647,7 +3714,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3647
3714
|
topP = void 0;
|
|
3648
3715
|
}
|
|
3649
3716
|
}
|
|
3650
|
-
const isAnthropicModel = isKnownModel || this.modelId.
|
|
3717
|
+
const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
|
|
3651
3718
|
const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
|
|
3652
3719
|
const supportsStrictTools = ((_b = this.config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
|
|
3653
3720
|
const structureOutputMode = (_c = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _c : "auto";
|
|
@@ -3715,11 +3782,19 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3715
3782
|
}
|
|
3716
3783
|
}
|
|
3717
3784
|
}
|
|
3718
|
-
|
|
3785
|
+
if (rejectsThinkingDisabledAboveHighEffort && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.type) === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
|
|
3786
|
+
warnings.push({
|
|
3787
|
+
type: "unsupported",
|
|
3788
|
+
feature: "providerOptions.anthropic.effort",
|
|
3789
|
+
details: `effort '${anthropicOptions.effort}' is not supported by ${this.modelId} when thinking is disabled. The effort has been lowered to 'high'.`
|
|
3790
|
+
});
|
|
3791
|
+
anthropicOptions.effort = "high";
|
|
3792
|
+
}
|
|
3793
|
+
const thinkingType = (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.type;
|
|
3719
3794
|
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
3720
3795
|
const sendThinking = isThinking || thinkingType === "disabled";
|
|
3721
|
-
let thinkingBudget = thinkingType === "enabled" ? (
|
|
3722
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
3796
|
+
let thinkingBudget = thinkingType === "enabled" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.budgetTokens : void 0;
|
|
3797
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_i = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _i.display : void 0;
|
|
3723
3798
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
3724
3799
|
const baseArgs = {
|
|
3725
3800
|
// model id:
|
|
@@ -3766,13 +3841,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3766
3841
|
...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
|
|
3767
3842
|
inference_geo: anthropicOptions.inferenceGeo
|
|
3768
3843
|
},
|
|
3769
|
-
...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0 && {
|
|
3844
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) != null && (anthropicOptions.fallbacks === "default" || anthropicOptions.fallbacks.length > 0) && {
|
|
3770
3845
|
fallbacks: anthropicOptions.fallbacks
|
|
3771
3846
|
},
|
|
3772
3847
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
3773
3848
|
cache_control: anthropicOptions.cacheControl
|
|
3774
3849
|
},
|
|
3775
|
-
...((
|
|
3850
|
+
...((_j = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _j.userId) != null && {
|
|
3776
3851
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
3777
3852
|
},
|
|
3778
3853
|
// mcp servers:
|
|
@@ -3948,10 +4023,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3948
4023
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
|
|
3949
4024
|
betas.add("fast-mode-2026-02-01");
|
|
3950
4025
|
}
|
|
3951
|
-
if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks)
|
|
4026
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) === "default") {
|
|
4027
|
+
betas.add("server-side-fallback-2026-07-01");
|
|
4028
|
+
} else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
|
|
3952
4029
|
betas.add("server-side-fallback-2026-06-01");
|
|
3953
4030
|
}
|
|
3954
|
-
const defaultEagerInputStreaming = stream && ((
|
|
4031
|
+
const defaultEagerInputStreaming = stream && ((_k = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _k : true);
|
|
3955
4032
|
const {
|
|
3956
4033
|
tools: anthropicTools2,
|
|
3957
4034
|
toolChoice: anthropicToolChoice,
|
|
@@ -3990,7 +4067,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3990
4067
|
...betas,
|
|
3991
4068
|
...toolsBetas,
|
|
3992
4069
|
...userSuppliedBetas,
|
|
3993
|
-
...(
|
|
4070
|
+
...(_l = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _l : []
|
|
3994
4071
|
]),
|
|
3995
4072
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
3996
4073
|
toolNameMapping,
|
|
@@ -5430,13 +5507,24 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5430
5507
|
}
|
|
5431
5508
|
};
|
|
5432
5509
|
function getModelCapabilities(modelId) {
|
|
5433
|
-
if (modelId.includes("claude-opus-
|
|
5510
|
+
if (modelId.includes("claude-opus-5")) {
|
|
5511
|
+
return {
|
|
5512
|
+
maxOutputTokens: 128e3,
|
|
5513
|
+
supportsStructuredOutput: true,
|
|
5514
|
+
supportsAdaptiveThinking: true,
|
|
5515
|
+
rejectsSamplingParameters: true,
|
|
5516
|
+
supportsXhighEffort: true,
|
|
5517
|
+
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5518
|
+
isKnownModel: true
|
|
5519
|
+
};
|
|
5520
|
+
} else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
|
|
5434
5521
|
return {
|
|
5435
5522
|
maxOutputTokens: 128e3,
|
|
5436
5523
|
supportsStructuredOutput: true,
|
|
5437
5524
|
supportsAdaptiveThinking: true,
|
|
5438
5525
|
rejectsSamplingParameters: true,
|
|
5439
5526
|
supportsXhighEffort: true,
|
|
5527
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5440
5528
|
isKnownModel: true
|
|
5441
5529
|
};
|
|
5442
5530
|
} else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
|
|
@@ -5446,6 +5534,7 @@ function getModelCapabilities(modelId) {
|
|
|
5446
5534
|
supportsAdaptiveThinking: true,
|
|
5447
5535
|
rejectsSamplingParameters: false,
|
|
5448
5536
|
supportsXhighEffort: false,
|
|
5537
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5449
5538
|
isKnownModel: true
|
|
5450
5539
|
};
|
|
5451
5540
|
} else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
|
|
@@ -5455,6 +5544,7 @@ function getModelCapabilities(modelId) {
|
|
|
5455
5544
|
supportsAdaptiveThinking: false,
|
|
5456
5545
|
rejectsSamplingParameters: false,
|
|
5457
5546
|
supportsXhighEffort: false,
|
|
5547
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5458
5548
|
isKnownModel: true
|
|
5459
5549
|
};
|
|
5460
5550
|
} else if (modelId.includes("claude-opus-4-1")) {
|
|
@@ -5464,6 +5554,7 @@ function getModelCapabilities(modelId) {
|
|
|
5464
5554
|
supportsAdaptiveThinking: false,
|
|
5465
5555
|
rejectsSamplingParameters: false,
|
|
5466
5556
|
supportsXhighEffort: false,
|
|
5557
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5467
5558
|
isKnownModel: true
|
|
5468
5559
|
};
|
|
5469
5560
|
} else if (modelId.includes("claude-sonnet-4-")) {
|
|
@@ -5473,6 +5564,7 @@ function getModelCapabilities(modelId) {
|
|
|
5473
5564
|
supportsAdaptiveThinking: false,
|
|
5474
5565
|
rejectsSamplingParameters: false,
|
|
5475
5566
|
supportsXhighEffort: false,
|
|
5567
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5476
5568
|
isKnownModel: true
|
|
5477
5569
|
};
|
|
5478
5570
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
@@ -5482,6 +5574,7 @@ function getModelCapabilities(modelId) {
|
|
|
5482
5574
|
supportsAdaptiveThinking: false,
|
|
5483
5575
|
rejectsSamplingParameters: false,
|
|
5484
5576
|
supportsXhighEffort: false,
|
|
5577
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5485
5578
|
isKnownModel: true
|
|
5486
5579
|
};
|
|
5487
5580
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
@@ -5491,8 +5584,29 @@ function getModelCapabilities(modelId) {
|
|
|
5491
5584
|
supportsAdaptiveThinking: false,
|
|
5492
5585
|
rejectsSamplingParameters: false,
|
|
5493
5586
|
supportsXhighEffort: false,
|
|
5587
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5494
5588
|
isKnownModel: true
|
|
5495
5589
|
};
|
|
5590
|
+
} else if (/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(modelId)) {
|
|
5591
|
+
return {
|
|
5592
|
+
maxOutputTokens: 4096,
|
|
5593
|
+
supportsStructuredOutput: false,
|
|
5594
|
+
supportsAdaptiveThinking: false,
|
|
5595
|
+
rejectsSamplingParameters: false,
|
|
5596
|
+
supportsXhighEffort: false,
|
|
5597
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5598
|
+
isKnownModel: false
|
|
5599
|
+
};
|
|
5600
|
+
} else if (modelId.includes("claude-")) {
|
|
5601
|
+
return {
|
|
5602
|
+
maxOutputTokens: 128e3,
|
|
5603
|
+
supportsStructuredOutput: true,
|
|
5604
|
+
supportsAdaptiveThinking: true,
|
|
5605
|
+
rejectsSamplingParameters: true,
|
|
5606
|
+
supportsXhighEffort: true,
|
|
5607
|
+
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5608
|
+
isKnownModel: false
|
|
5609
|
+
};
|
|
5496
5610
|
} else {
|
|
5497
5611
|
return {
|
|
5498
5612
|
maxOutputTokens: 4096,
|
|
@@ -5500,6 +5614,7 @@ function getModelCapabilities(modelId) {
|
|
|
5500
5614
|
supportsAdaptiveThinking: false,
|
|
5501
5615
|
rejectsSamplingParameters: false,
|
|
5502
5616
|
supportsXhighEffort: false,
|
|
5617
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5503
5618
|
isKnownModel: false
|
|
5504
5619
|
};
|
|
5505
5620
|
}
|