@ai-sdk/anthropic 3.0.101 → 3.0.102
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 +8 -0
- package/dist/index.d.mts +17 -4
- package/dist/index.d.ts +17 -4
- package/dist/index.js +160 -65
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +160 -65
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -1
- package/dist/internal/index.d.ts +2 -1
- package/dist/internal/index.js +159 -64
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +159 -64
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +79 -2
- package/package.json +1 -1
- package/src/anthropic-messages-api.ts +14 -1
- package/src/anthropic-messages-language-model.ts +51 -4
- package/src/anthropic-messages-options.ts +64 -20
- package/src/convert-to-anthropic-messages-prompt.ts +64 -12
- package/src/index.ts +1 -0
|
@@ -2,7 +2,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
|
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
5
|
-
type AnthropicMessagesModelId = '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 & {});
|
|
5
|
+
type AnthropicMessagesModelId = '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 & {});
|
|
6
6
|
|
|
7
7
|
type AnthropicMessagesConfig = {
|
|
8
8
|
provider: string;
|
|
@@ -56,6 +56,7 @@ declare function getModelCapabilities(modelId: string): {
|
|
|
56
56
|
maxOutputTokens: number;
|
|
57
57
|
supportsStructuredOutput: boolean;
|
|
58
58
|
rejectsSamplingParameters: boolean;
|
|
59
|
+
rejectsThinkingDisabledAboveHighEffort: boolean;
|
|
59
60
|
isKnownModel: boolean;
|
|
60
61
|
};
|
|
61
62
|
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
|
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
5
|
-
type AnthropicMessagesModelId = '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 & {});
|
|
5
|
+
type AnthropicMessagesModelId = '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 & {});
|
|
6
6
|
|
|
7
7
|
type AnthropicMessagesConfig = {
|
|
8
8
|
provider: string;
|
|
@@ -56,6 +56,7 @@ declare function getModelCapabilities(modelId: string): {
|
|
|
56
56
|
maxOutputTokens: number;
|
|
57
57
|
supportsStructuredOutput: boolean;
|
|
58
58
|
rejectsSamplingParameters: boolean;
|
|
59
|
+
rejectsThinkingDisabledAboveHighEffort: boolean;
|
|
59
60
|
isKnownModel: boolean;
|
|
60
61
|
};
|
|
61
62
|
|
package/dist/internal/index.js
CHANGED
|
@@ -888,6 +888,34 @@ var anthropicFilePartProviderOptions = import_v43.z.object({
|
|
|
888
888
|
*/
|
|
889
889
|
context: import_v43.z.string().optional()
|
|
890
890
|
});
|
|
891
|
+
var anthropicSystemMessageProviderOptions = import_v43.z.object({
|
|
892
|
+
/**
|
|
893
|
+
* Mid-conversation tool changes. Adds or removes tools from the
|
|
894
|
+
* conversation's tool set between turns without invalidating the prompt
|
|
895
|
+
* cache.
|
|
896
|
+
*
|
|
897
|
+
* Only supported on system messages that appear mid-conversation (not the
|
|
898
|
+
* initial system prompt). A system message carrying tool changes must come
|
|
899
|
+
* right before an assistant message or at the end of the messages.
|
|
900
|
+
*
|
|
901
|
+
* Tools referenced by a `tool_addition` must be declared in the `tools`
|
|
902
|
+
* option (typically with `deferLoading: true` so they are not loaded until
|
|
903
|
+
* the addition surfaces them). The required
|
|
904
|
+
* `mid-conversation-tool-changes-2026-07-01` beta is added automatically.
|
|
905
|
+
*/
|
|
906
|
+
toolChanges: import_v43.z.array(
|
|
907
|
+
import_v43.z.discriminatedUnion("type", [
|
|
908
|
+
import_v43.z.object({
|
|
909
|
+
type: import_v43.z.literal("tool_addition"),
|
|
910
|
+
toolName: import_v43.z.string()
|
|
911
|
+
}),
|
|
912
|
+
import_v43.z.object({
|
|
913
|
+
type: import_v43.z.literal("tool_removal"),
|
|
914
|
+
toolName: import_v43.z.string()
|
|
915
|
+
})
|
|
916
|
+
])
|
|
917
|
+
).optional()
|
|
918
|
+
});
|
|
891
919
|
var anthropicLanguageModelOptions = import_v43.z.object({
|
|
892
920
|
/**
|
|
893
921
|
* Whether to send reasoning to the model.
|
|
@@ -1027,30 +1055,35 @@ var anthropicLanguageModelOptions = import_v43.z.object({
|
|
|
1027
1055
|
*/
|
|
1028
1056
|
inferenceGeo: import_v43.z.enum(["us", "global"]).optional(),
|
|
1029
1057
|
/**
|
|
1030
|
-
* Server-side fallback
|
|
1058
|
+
* Server-side fallback configuration.
|
|
1031
1059
|
*
|
|
1032
1060
|
* When the primary model's safety classifiers block a turn, the API
|
|
1033
|
-
* automatically retries it on
|
|
1034
|
-
* `content-filter` finish reason means the
|
|
1061
|
+
* automatically retries it server-side on a fallback model. A
|
|
1062
|
+
* `content-filter` finish reason means the fallback(s) refused as well.
|
|
1035
1063
|
*
|
|
1036
|
-
*
|
|
1037
|
-
* model
|
|
1038
|
-
*
|
|
1039
|
-
*
|
|
1040
|
-
*
|
|
1041
|
-
*
|
|
1042
|
-
*
|
|
1043
|
-
*
|
|
1064
|
+
* - `'default'` (recommended): the API routes the retry to Anthropic's
|
|
1065
|
+
* recommended fallback model based on the refusal category. Requires the
|
|
1066
|
+
* `server-side-fallback-2026-07-01` beta, which is added automatically.
|
|
1067
|
+
* - Array form: an explicit fallback chain. Each entry is merged into the
|
|
1068
|
+
* request as a direct request to that entry's model, so it must be
|
|
1069
|
+
* formatted accordingly: `model` is required, and an entry may
|
|
1070
|
+
* additionally override `max_tokens`, `thinking`, `output_config`, and
|
|
1071
|
+
* `speed` for that attempt only (`speed` additionally requires the speed
|
|
1072
|
+
* beta). The value is passed through to the API as-is, and the
|
|
1073
|
+
* `server-side-fallback-2026-06-01` beta is added automatically.
|
|
1044
1074
|
*/
|
|
1045
|
-
fallbacks: import_v43.z.
|
|
1046
|
-
import_v43.z.
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1075
|
+
fallbacks: import_v43.z.union([
|
|
1076
|
+
import_v43.z.literal("default"),
|
|
1077
|
+
import_v43.z.array(
|
|
1078
|
+
import_v43.z.object({
|
|
1079
|
+
model: import_v43.z.string(),
|
|
1080
|
+
max_tokens: import_v43.z.number().int().optional(),
|
|
1081
|
+
thinking: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).optional(),
|
|
1082
|
+
output_config: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).optional(),
|
|
1083
|
+
speed: import_v43.z.enum(["fast", "standard"]).optional()
|
|
1084
|
+
})
|
|
1085
|
+
)
|
|
1086
|
+
]).optional(),
|
|
1054
1087
|
/**
|
|
1055
1088
|
* A set of beta features to enable.
|
|
1056
1089
|
* Allow a provider to receive the full `betas` set if it needs it.
|
|
@@ -2208,7 +2241,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2208
2241
|
cacheControlValidator,
|
|
2209
2242
|
toolNameMapping
|
|
2210
2243
|
}) {
|
|
2211
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
2244
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
2212
2245
|
const betas = /* @__PURE__ */ new Set();
|
|
2213
2246
|
const blocks = groupIntoBlocks(prompt);
|
|
2214
2247
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -2240,19 +2273,52 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2240
2273
|
const type = block.type;
|
|
2241
2274
|
switch (type) {
|
|
2242
2275
|
case "system": {
|
|
2243
|
-
const content =
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2276
|
+
const content = [];
|
|
2277
|
+
let toolChangeCount = 0;
|
|
2278
|
+
for (const { content: text, providerOptions } of block.messages) {
|
|
2279
|
+
const systemMessageOptions = await (0, import_provider_utils14.parseProviderOptions)({
|
|
2280
|
+
provider: "anthropic",
|
|
2281
|
+
providerOptions,
|
|
2282
|
+
schema: anthropicSystemMessageProviderOptions
|
|
2283
|
+
});
|
|
2284
|
+
const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
|
|
2285
|
+
if (text !== "" || toolChanges.length === 0) {
|
|
2286
|
+
content.push({
|
|
2287
|
+
type: "text",
|
|
2288
|
+
text,
|
|
2289
|
+
cache_control: validator.getCacheControl(providerOptions, {
|
|
2290
|
+
type: "system message",
|
|
2291
|
+
canCache: true
|
|
2292
|
+
})
|
|
2293
|
+
});
|
|
2294
|
+
}
|
|
2295
|
+
for (const toolChange of toolChanges) {
|
|
2296
|
+
toolChangeCount++;
|
|
2297
|
+
content.push({
|
|
2298
|
+
type: toolChange.type,
|
|
2299
|
+
tool: {
|
|
2300
|
+
type: "tool_reference",
|
|
2301
|
+
name: toolNameMapping.toProviderToolName(toolChange.toolName)
|
|
2302
|
+
}
|
|
2303
|
+
});
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
if (i === 0 || system == null && toolChangeCount === 0) {
|
|
2307
|
+
if (toolChangeCount > 0) {
|
|
2308
|
+
warnings.push({
|
|
2309
|
+
type: "other",
|
|
2310
|
+
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."
|
|
2311
|
+
});
|
|
2312
|
+
}
|
|
2313
|
+
system = content.filter(
|
|
2314
|
+
(part) => part.type === "text"
|
|
2315
|
+
);
|
|
2253
2316
|
} else {
|
|
2254
2317
|
messages.push({ role: "system", content });
|
|
2255
2318
|
betas.add("mid-conversation-system-2026-04-07");
|
|
2319
|
+
if (toolChangeCount > 0) {
|
|
2320
|
+
betas.add("mid-conversation-tool-changes-2026-07-01");
|
|
2321
|
+
}
|
|
2256
2322
|
}
|
|
2257
2323
|
break;
|
|
2258
2324
|
}
|
|
@@ -2265,10 +2331,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2265
2331
|
for (let j = 0; j < content.length; j++) {
|
|
2266
2332
|
const part = content[j];
|
|
2267
2333
|
const isLastPart = j === content.length - 1;
|
|
2268
|
-
const cacheControl = (
|
|
2334
|
+
const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
|
|
2269
2335
|
type: "user message part",
|
|
2270
2336
|
canCache: true
|
|
2271
|
-
})) != null ?
|
|
2337
|
+
})) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
2272
2338
|
type: "user message",
|
|
2273
2339
|
canCache: true
|
|
2274
2340
|
}) : void 0;
|
|
@@ -2313,7 +2379,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2313
2379
|
media_type: "application/pdf",
|
|
2314
2380
|
data: (0, import_provider_utils14.convertToBase64)(part.data)
|
|
2315
2381
|
},
|
|
2316
|
-
title: (
|
|
2382
|
+
title: (_c = metadata.title) != null ? _c : part.filename,
|
|
2317
2383
|
...metadata.context && { context: metadata.context },
|
|
2318
2384
|
...enableCitations && {
|
|
2319
2385
|
citations: { enabled: true }
|
|
@@ -2337,7 +2403,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2337
2403
|
media_type: "text/plain",
|
|
2338
2404
|
data: convertToString(part.data)
|
|
2339
2405
|
},
|
|
2340
|
-
title: (
|
|
2406
|
+
title: (_d = metadata.title) != null ? _d : part.filename,
|
|
2341
2407
|
...metadata.context && { context: metadata.context },
|
|
2342
2408
|
...enableCitations && {
|
|
2343
2409
|
citations: { enabled: true }
|
|
@@ -2362,17 +2428,17 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2362
2428
|
continue;
|
|
2363
2429
|
}
|
|
2364
2430
|
const output = part.output;
|
|
2365
|
-
const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (
|
|
2431
|
+
const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (_e = output.value.find(
|
|
2366
2432
|
(contentPart) => contentPart.providerOptions != null
|
|
2367
|
-
)) == null ? void 0 :
|
|
2433
|
+
)) == null ? void 0 : _e.providerOptions : void 0;
|
|
2368
2434
|
const isLastPart = i2 === content.length - 1;
|
|
2369
|
-
const cacheControl = (
|
|
2435
|
+
const cacheControl = (_g = (_f = validator.getCacheControl(part.providerOptions, {
|
|
2370
2436
|
type: "tool result part",
|
|
2371
2437
|
canCache: true
|
|
2372
|
-
})) != null ?
|
|
2438
|
+
})) != null ? _f : validator.getCacheControl(outputProviderOptions, {
|
|
2373
2439
|
type: "tool result output",
|
|
2374
2440
|
canCache: true
|
|
2375
|
-
})) != null ?
|
|
2441
|
+
})) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
2376
2442
|
type: "tool result message",
|
|
2377
2443
|
canCache: true
|
|
2378
2444
|
}) : void 0;
|
|
@@ -2462,7 +2528,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2462
2528
|
contentValue = output.value;
|
|
2463
2529
|
break;
|
|
2464
2530
|
case "execution-denied":
|
|
2465
|
-
contentValue = (
|
|
2531
|
+
contentValue = (_h = output.reason) != null ? _h : "Tool call execution denied.";
|
|
2466
2532
|
break;
|
|
2467
2533
|
case "json":
|
|
2468
2534
|
case "error-json":
|
|
@@ -2499,16 +2565,16 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2499
2565
|
for (let k = 0; k < content.length; k++) {
|
|
2500
2566
|
const part = content[k];
|
|
2501
2567
|
const isLastContentPart = k === content.length - 1;
|
|
2502
|
-
const cacheControl = (
|
|
2568
|
+
const cacheControl = (_i = validator.getCacheControl(part.providerOptions, {
|
|
2503
2569
|
type: "assistant message part",
|
|
2504
2570
|
canCache: true
|
|
2505
|
-
})) != null ?
|
|
2571
|
+
})) != null ? _i : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
|
|
2506
2572
|
type: "assistant message",
|
|
2507
2573
|
canCache: true
|
|
2508
2574
|
}) : void 0;
|
|
2509
2575
|
switch (part.type) {
|
|
2510
2576
|
case "text": {
|
|
2511
|
-
const textMetadata = (
|
|
2577
|
+
const textMetadata = (_j = part.providerOptions) == null ? void 0 : _j.anthropic;
|
|
2512
2578
|
if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
|
|
2513
2579
|
anthropicContent.push({
|
|
2514
2580
|
type: "compaction",
|
|
@@ -2584,10 +2650,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2584
2650
|
const providerToolName = toolNameMapping.toProviderToolName(
|
|
2585
2651
|
part.toolName
|
|
2586
2652
|
);
|
|
2587
|
-
const isMcpToolUse = ((
|
|
2653
|
+
const isMcpToolUse = ((_l = (_k = part.providerOptions) == null ? void 0 : _k.anthropic) == null ? void 0 : _l.type) === "mcp-tool-use";
|
|
2588
2654
|
if (isMcpToolUse) {
|
|
2589
2655
|
mcpToolUseIds.add(part.toolCallId);
|
|
2590
|
-
const serverName = (
|
|
2656
|
+
const serverName = (_n = (_m = part.providerOptions) == null ? void 0 : _m.anthropic) == null ? void 0 : _n.serverName;
|
|
2591
2657
|
if (serverName == null || typeof serverName !== "string") {
|
|
2592
2658
|
warnings.push({
|
|
2593
2659
|
type: "other",
|
|
@@ -2663,7 +2729,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2663
2729
|
}
|
|
2664
2730
|
break;
|
|
2665
2731
|
}
|
|
2666
|
-
const callerOptions = (
|
|
2732
|
+
const callerOptions = (_o = part.providerOptions) == null ? void 0 : _o.anthropic;
|
|
2667
2733
|
const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? (callerOptions.caller.type === "code_execution_20250825" || callerOptions.caller.type === "code_execution_20260120") && callerOptions.caller.toolId ? {
|
|
2668
2734
|
type: callerOptions.caller.type,
|
|
2669
2735
|
tool_id: callerOptions.caller.toolId
|
|
@@ -2716,7 +2782,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2716
2782
|
tool_use_id: part.toolCallId,
|
|
2717
2783
|
content: {
|
|
2718
2784
|
type: "code_execution_tool_result_error",
|
|
2719
|
-
error_code: (
|
|
2785
|
+
error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
|
|
2720
2786
|
},
|
|
2721
2787
|
cache_control: cacheControl
|
|
2722
2788
|
});
|
|
@@ -2727,7 +2793,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2727
2793
|
cache_control: cacheControl,
|
|
2728
2794
|
content: {
|
|
2729
2795
|
type: "bash_code_execution_tool_result_error",
|
|
2730
|
-
error_code: (
|
|
2796
|
+
error_code: (_q = errorInfo.errorCode) != null ? _q : "unknown"
|
|
2731
2797
|
}
|
|
2732
2798
|
});
|
|
2733
2799
|
}
|
|
@@ -2760,7 +2826,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2760
2826
|
stdout: codeExecutionOutput.stdout,
|
|
2761
2827
|
stderr: codeExecutionOutput.stderr,
|
|
2762
2828
|
return_code: codeExecutionOutput.return_code,
|
|
2763
|
-
content: (
|
|
2829
|
+
content: (_r = codeExecutionOutput.content) != null ? _r : []
|
|
2764
2830
|
},
|
|
2765
2831
|
cache_control: cacheControl
|
|
2766
2832
|
});
|
|
@@ -2778,7 +2844,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2778
2844
|
encrypted_stdout: codeExecutionOutput.encrypted_stdout,
|
|
2779
2845
|
stderr: codeExecutionOutput.stderr,
|
|
2780
2846
|
return_code: codeExecutionOutput.return_code,
|
|
2781
|
-
content: (
|
|
2847
|
+
content: (_s = codeExecutionOutput.content) != null ? _s : []
|
|
2782
2848
|
},
|
|
2783
2849
|
cache_control: cacheControl
|
|
2784
2850
|
});
|
|
@@ -2797,7 +2863,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2797
2863
|
stdout: codeExecutionOutput.stdout,
|
|
2798
2864
|
stderr: codeExecutionOutput.stderr,
|
|
2799
2865
|
return_code: codeExecutionOutput.return_code,
|
|
2800
|
-
content: (
|
|
2866
|
+
content: (_t = codeExecutionOutput.content) != null ? _t : []
|
|
2801
2867
|
},
|
|
2802
2868
|
cache_control: cacheControl
|
|
2803
2869
|
});
|
|
@@ -2827,7 +2893,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2827
2893
|
tool_use_id: part.toolCallId,
|
|
2828
2894
|
content: {
|
|
2829
2895
|
type: "web_fetch_tool_result_error",
|
|
2830
|
-
error_code: (
|
|
2896
|
+
error_code: (_u = (await extractErrorValue(output.value)).errorCode) != null ? _u : "unavailable"
|
|
2831
2897
|
},
|
|
2832
2898
|
cache_control: cacheControl
|
|
2833
2899
|
});
|
|
@@ -2874,7 +2940,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2874
2940
|
tool_use_id: part.toolCallId,
|
|
2875
2941
|
content: {
|
|
2876
2942
|
type: "web_search_tool_result_error",
|
|
2877
|
-
error_code: (
|
|
2943
|
+
error_code: (_v = (await extractErrorValue(output.value)).errorCode) != null ? _v : "unavailable"
|
|
2878
2944
|
},
|
|
2879
2945
|
cache_control: cacheControl
|
|
2880
2946
|
});
|
|
@@ -3332,7 +3398,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3332
3398
|
providerOptions,
|
|
3333
3399
|
stream
|
|
3334
3400
|
}) {
|
|
3335
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3401
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3336
3402
|
const warnings = [];
|
|
3337
3403
|
if (frequencyPenalty != null) {
|
|
3338
3404
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -3388,6 +3454,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3388
3454
|
maxOutputTokens: maxOutputTokensForModel,
|
|
3389
3455
|
supportsStructuredOutput: modelSupportsStructuredOutput,
|
|
3390
3456
|
rejectsSamplingParameters,
|
|
3457
|
+
rejectsThinkingDisabledAboveHighEffort,
|
|
3391
3458
|
isKnownModel
|
|
3392
3459
|
} = getModelCapabilities(this.modelId);
|
|
3393
3460
|
if (!isKnownModel && maxOutputTokens == null) {
|
|
@@ -3474,11 +3541,19 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3474
3541
|
cacheControlValidator,
|
|
3475
3542
|
toolNameMapping
|
|
3476
3543
|
});
|
|
3477
|
-
|
|
3544
|
+
if (rejectsThinkingDisabledAboveHighEffort && ((_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type) === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
|
|
3545
|
+
warnings.push({
|
|
3546
|
+
type: "unsupported",
|
|
3547
|
+
feature: "providerOptions.anthropic.effort",
|
|
3548
|
+
details: `effort '${anthropicOptions.effort}' is not supported by ${this.modelId} when thinking is disabled. The effort has been lowered to 'high'.`
|
|
3549
|
+
});
|
|
3550
|
+
anthropicOptions.effort = "high";
|
|
3551
|
+
}
|
|
3552
|
+
const thinkingType = (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.type;
|
|
3478
3553
|
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
3479
3554
|
const sendThinking = isThinking || thinkingType === "disabled";
|
|
3480
|
-
let thinkingBudget = thinkingType === "enabled" ? (
|
|
3481
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
3555
|
+
let thinkingBudget = thinkingType === "enabled" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.budgetTokens : void 0;
|
|
3556
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.display : void 0;
|
|
3482
3557
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
3483
3558
|
const baseArgs = {
|
|
3484
3559
|
// model id:
|
|
@@ -3525,13 +3600,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3525
3600
|
...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
|
|
3526
3601
|
inference_geo: anthropicOptions.inferenceGeo
|
|
3527
3602
|
},
|
|
3528
|
-
...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0 && {
|
|
3603
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) != null && (anthropicOptions.fallbacks === "default" || anthropicOptions.fallbacks.length > 0) && {
|
|
3529
3604
|
fallbacks: anthropicOptions.fallbacks
|
|
3530
3605
|
},
|
|
3531
3606
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
3532
3607
|
cache_control: anthropicOptions.cacheControl
|
|
3533
3608
|
},
|
|
3534
|
-
...((
|
|
3609
|
+
...((_i = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _i.userId) != null && {
|
|
3535
3610
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
3536
3611
|
},
|
|
3537
3612
|
// mcp servers:
|
|
@@ -3704,10 +3779,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3704
3779
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
|
|
3705
3780
|
betas.add("fast-mode-2026-02-01");
|
|
3706
3781
|
}
|
|
3707
|
-
if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks)
|
|
3782
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) === "default") {
|
|
3783
|
+
betas.add("server-side-fallback-2026-07-01");
|
|
3784
|
+
} else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
|
|
3708
3785
|
betas.add("server-side-fallback-2026-06-01");
|
|
3709
3786
|
}
|
|
3710
|
-
const defaultEagerInputStreaming = stream && ((
|
|
3787
|
+
const defaultEagerInputStreaming = stream && ((_j = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _j : true);
|
|
3711
3788
|
const {
|
|
3712
3789
|
tools: anthropicTools2,
|
|
3713
3790
|
toolChoice: anthropicToolChoice,
|
|
@@ -3746,7 +3823,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3746
3823
|
...betas,
|
|
3747
3824
|
...toolsBetas,
|
|
3748
3825
|
...userSuppliedBetas,
|
|
3749
|
-
...(
|
|
3826
|
+
...(_k = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _k : []
|
|
3750
3827
|
]),
|
|
3751
3828
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
3752
3829
|
toolNameMapping,
|
|
@@ -5192,11 +5269,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5192
5269
|
}
|
|
5193
5270
|
};
|
|
5194
5271
|
function getModelCapabilities(modelId) {
|
|
5195
|
-
if (modelId.includes("claude-opus-
|
|
5272
|
+
if (modelId.includes("claude-opus-5")) {
|
|
5273
|
+
return {
|
|
5274
|
+
maxOutputTokens: 128e3,
|
|
5275
|
+
supportsStructuredOutput: true,
|
|
5276
|
+
rejectsSamplingParameters: true,
|
|
5277
|
+
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5278
|
+
isKnownModel: true
|
|
5279
|
+
};
|
|
5280
|
+
} else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
|
|
5196
5281
|
return {
|
|
5197
5282
|
maxOutputTokens: 128e3,
|
|
5198
5283
|
supportsStructuredOutput: true,
|
|
5199
5284
|
rejectsSamplingParameters: true,
|
|
5285
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5200
5286
|
isKnownModel: true
|
|
5201
5287
|
};
|
|
5202
5288
|
} else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
|
|
@@ -5204,6 +5290,7 @@ function getModelCapabilities(modelId) {
|
|
|
5204
5290
|
maxOutputTokens: 128e3,
|
|
5205
5291
|
supportsStructuredOutput: true,
|
|
5206
5292
|
rejectsSamplingParameters: false,
|
|
5293
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5207
5294
|
isKnownModel: true
|
|
5208
5295
|
};
|
|
5209
5296
|
} else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
|
|
@@ -5211,6 +5298,7 @@ function getModelCapabilities(modelId) {
|
|
|
5211
5298
|
maxOutputTokens: 64e3,
|
|
5212
5299
|
supportsStructuredOutput: true,
|
|
5213
5300
|
rejectsSamplingParameters: false,
|
|
5301
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5214
5302
|
isKnownModel: true
|
|
5215
5303
|
};
|
|
5216
5304
|
} else if (modelId.includes("claude-opus-4-1")) {
|
|
@@ -5218,6 +5306,7 @@ function getModelCapabilities(modelId) {
|
|
|
5218
5306
|
maxOutputTokens: 32e3,
|
|
5219
5307
|
supportsStructuredOutput: true,
|
|
5220
5308
|
rejectsSamplingParameters: false,
|
|
5309
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5221
5310
|
isKnownModel: true
|
|
5222
5311
|
};
|
|
5223
5312
|
} else if (modelId.includes("claude-sonnet-4-")) {
|
|
@@ -5225,6 +5314,7 @@ function getModelCapabilities(modelId) {
|
|
|
5225
5314
|
maxOutputTokens: 64e3,
|
|
5226
5315
|
supportsStructuredOutput: false,
|
|
5227
5316
|
rejectsSamplingParameters: false,
|
|
5317
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5228
5318
|
isKnownModel: true
|
|
5229
5319
|
};
|
|
5230
5320
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
@@ -5232,6 +5322,7 @@ function getModelCapabilities(modelId) {
|
|
|
5232
5322
|
maxOutputTokens: 32e3,
|
|
5233
5323
|
supportsStructuredOutput: false,
|
|
5234
5324
|
rejectsSamplingParameters: false,
|
|
5325
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5235
5326
|
isKnownModel: true
|
|
5236
5327
|
};
|
|
5237
5328
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
@@ -5239,6 +5330,7 @@ function getModelCapabilities(modelId) {
|
|
|
5239
5330
|
maxOutputTokens: 4096,
|
|
5240
5331
|
supportsStructuredOutput: false,
|
|
5241
5332
|
rejectsSamplingParameters: false,
|
|
5333
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5242
5334
|
isKnownModel: true
|
|
5243
5335
|
};
|
|
5244
5336
|
} else if (/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(modelId)) {
|
|
@@ -5246,6 +5338,7 @@ function getModelCapabilities(modelId) {
|
|
|
5246
5338
|
maxOutputTokens: 4096,
|
|
5247
5339
|
supportsStructuredOutput: false,
|
|
5248
5340
|
rejectsSamplingParameters: false,
|
|
5341
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5249
5342
|
isKnownModel: false
|
|
5250
5343
|
};
|
|
5251
5344
|
} else if (modelId.includes("claude-")) {
|
|
@@ -5253,6 +5346,7 @@ function getModelCapabilities(modelId) {
|
|
|
5253
5346
|
maxOutputTokens: 128e3,
|
|
5254
5347
|
supportsStructuredOutput: true,
|
|
5255
5348
|
rejectsSamplingParameters: true,
|
|
5349
|
+
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5256
5350
|
isKnownModel: false
|
|
5257
5351
|
};
|
|
5258
5352
|
} else {
|
|
@@ -5260,6 +5354,7 @@ function getModelCapabilities(modelId) {
|
|
|
5260
5354
|
maxOutputTokens: 4096,
|
|
5261
5355
|
supportsStructuredOutput: false,
|
|
5262
5356
|
rejectsSamplingParameters: false,
|
|
5357
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5263
5358
|
isKnownModel: false
|
|
5264
5359
|
};
|
|
5265
5360
|
}
|