@ai-sdk/anthropic 3.0.101 → 3.0.103
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.mts +17 -4
- package/dist/index.d.ts +17 -4
- package/dist/index.js +174 -69
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +174 -69
- 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 +173 -68
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +173 -68
- 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 +24 -1
- package/src/anthropic-messages-language-model.ts +54 -4
- package/src/anthropic-messages-options.ts +64 -20
- package/src/convert-anthropic-messages-usage.ts +8 -2
- 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
|
@@ -360,6 +360,9 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
360
360
|
usage: import_v42.z.looseObject({
|
|
361
361
|
input_tokens: import_v42.z.number(),
|
|
362
362
|
output_tokens: import_v42.z.number(),
|
|
363
|
+
output_tokens_details: import_v42.z.object({
|
|
364
|
+
thinking_tokens: import_v42.z.number().nullish()
|
|
365
|
+
}).nullish(),
|
|
363
366
|
cache_creation_input_tokens: import_v42.z.number().nullish(),
|
|
364
367
|
cache_read_input_tokens: import_v42.z.number().nullish(),
|
|
365
368
|
iterations: import_v42.z.array(
|
|
@@ -807,6 +810,9 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
807
810
|
usage: import_v42.z.looseObject({
|
|
808
811
|
input_tokens: import_v42.z.number().nullish(),
|
|
809
812
|
output_tokens: import_v42.z.number(),
|
|
813
|
+
output_tokens_details: import_v42.z.object({
|
|
814
|
+
thinking_tokens: import_v42.z.number().nullish()
|
|
815
|
+
}).nullish(),
|
|
810
816
|
cache_creation_input_tokens: import_v42.z.number().nullish(),
|
|
811
817
|
cache_read_input_tokens: import_v42.z.number().nullish(),
|
|
812
818
|
iterations: import_v42.z.array(
|
|
@@ -888,6 +894,34 @@ var anthropicFilePartProviderOptions = import_v43.z.object({
|
|
|
888
894
|
*/
|
|
889
895
|
context: import_v43.z.string().optional()
|
|
890
896
|
});
|
|
897
|
+
var anthropicSystemMessageProviderOptions = import_v43.z.object({
|
|
898
|
+
/**
|
|
899
|
+
* Mid-conversation tool changes. Adds or removes tools from the
|
|
900
|
+
* conversation's tool set between turns without invalidating the prompt
|
|
901
|
+
* cache.
|
|
902
|
+
*
|
|
903
|
+
* Only supported on system messages that appear mid-conversation (not the
|
|
904
|
+
* initial system prompt). A system message carrying tool changes must come
|
|
905
|
+
* right before an assistant message or at the end of the messages.
|
|
906
|
+
*
|
|
907
|
+
* Tools referenced by a `tool_addition` must be declared in the `tools`
|
|
908
|
+
* option (typically with `deferLoading: true` so they are not loaded until
|
|
909
|
+
* the addition surfaces them). The required
|
|
910
|
+
* `mid-conversation-tool-changes-2026-07-01` beta is added automatically.
|
|
911
|
+
*/
|
|
912
|
+
toolChanges: import_v43.z.array(
|
|
913
|
+
import_v43.z.discriminatedUnion("type", [
|
|
914
|
+
import_v43.z.object({
|
|
915
|
+
type: import_v43.z.literal("tool_addition"),
|
|
916
|
+
toolName: import_v43.z.string()
|
|
917
|
+
}),
|
|
918
|
+
import_v43.z.object({
|
|
919
|
+
type: import_v43.z.literal("tool_removal"),
|
|
920
|
+
toolName: import_v43.z.string()
|
|
921
|
+
})
|
|
922
|
+
])
|
|
923
|
+
).optional()
|
|
924
|
+
});
|
|
891
925
|
var anthropicLanguageModelOptions = import_v43.z.object({
|
|
892
926
|
/**
|
|
893
927
|
* Whether to send reasoning to the model.
|
|
@@ -1027,30 +1061,35 @@ var anthropicLanguageModelOptions = import_v43.z.object({
|
|
|
1027
1061
|
*/
|
|
1028
1062
|
inferenceGeo: import_v43.z.enum(["us", "global"]).optional(),
|
|
1029
1063
|
/**
|
|
1030
|
-
* Server-side fallback
|
|
1064
|
+
* Server-side fallback configuration.
|
|
1031
1065
|
*
|
|
1032
1066
|
* When the primary model's safety classifiers block a turn, the API
|
|
1033
|
-
* automatically retries it on
|
|
1034
|
-
* `content-filter` finish reason means the
|
|
1067
|
+
* automatically retries it server-side on a fallback model. A
|
|
1068
|
+
* `content-filter` finish reason means the fallback(s) refused as well.
|
|
1035
1069
|
*
|
|
1036
|
-
*
|
|
1037
|
-
* model
|
|
1038
|
-
*
|
|
1039
|
-
*
|
|
1040
|
-
*
|
|
1041
|
-
*
|
|
1042
|
-
*
|
|
1043
|
-
*
|
|
1070
|
+
* - `'default'` (recommended): the API routes the retry to Anthropic's
|
|
1071
|
+
* recommended fallback model based on the refusal category. Requires the
|
|
1072
|
+
* `server-side-fallback-2026-07-01` beta, which is added automatically.
|
|
1073
|
+
* - Array form: an explicit fallback chain. Each entry is merged into the
|
|
1074
|
+
* request as a direct request to that entry's model, so it must be
|
|
1075
|
+
* formatted accordingly: `model` is required, and an entry may
|
|
1076
|
+
* additionally override `max_tokens`, `thinking`, `output_config`, and
|
|
1077
|
+
* `speed` for that attempt only (`speed` additionally requires the speed
|
|
1078
|
+
* beta). The value is passed through to the API as-is, and the
|
|
1079
|
+
* `server-side-fallback-2026-06-01` beta is added automatically.
|
|
1044
1080
|
*/
|
|
1045
|
-
fallbacks: import_v43.z.
|
|
1046
|
-
import_v43.z.
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1081
|
+
fallbacks: import_v43.z.union([
|
|
1082
|
+
import_v43.z.literal("default"),
|
|
1083
|
+
import_v43.z.array(
|
|
1084
|
+
import_v43.z.object({
|
|
1085
|
+
model: import_v43.z.string(),
|
|
1086
|
+
max_tokens: import_v43.z.number().int().optional(),
|
|
1087
|
+
thinking: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).optional(),
|
|
1088
|
+
output_config: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).optional(),
|
|
1089
|
+
speed: import_v43.z.enum(["fast", "standard"]).optional()
|
|
1090
|
+
})
|
|
1091
|
+
)
|
|
1092
|
+
]).optional(),
|
|
1054
1093
|
/**
|
|
1055
1094
|
* A set of beta features to enable.
|
|
1056
1095
|
* Allow a provider to receive the full `betas` set if it needs it.
|
|
@@ -1805,12 +1844,13 @@ function convertAnthropicMessagesUsage({
|
|
|
1805
1844
|
usage,
|
|
1806
1845
|
rawUsage
|
|
1807
1846
|
}) {
|
|
1808
|
-
var _a, _b, _c;
|
|
1847
|
+
var _a, _b, _c, _d, _e;
|
|
1809
1848
|
const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
|
|
1810
1849
|
const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
|
|
1850
|
+
const reasoningTokens = (_d = (_c = usage.output_tokens_details) == null ? void 0 : _c.thinking_tokens) != null ? _d : void 0;
|
|
1811
1851
|
let inputTokens;
|
|
1812
1852
|
let outputTokens;
|
|
1813
|
-
const servedByFallback = (
|
|
1853
|
+
const servedByFallback = (_e = usage.iterations) == null ? void 0 : _e.some(
|
|
1814
1854
|
(iter) => iter.type === "fallback_message"
|
|
1815
1855
|
);
|
|
1816
1856
|
if (usage.iterations && usage.iterations.length > 0 && !servedByFallback) {
|
|
@@ -1844,8 +1884,8 @@ function convertAnthropicMessagesUsage({
|
|
|
1844
1884
|
},
|
|
1845
1885
|
outputTokens: {
|
|
1846
1886
|
total: outputTokens,
|
|
1847
|
-
text: void 0,
|
|
1848
|
-
reasoning:
|
|
1887
|
+
text: reasoningTokens == null ? void 0 : outputTokens - reasoningTokens,
|
|
1888
|
+
reasoning: reasoningTokens
|
|
1849
1889
|
},
|
|
1850
1890
|
raw: rawUsage != null ? rawUsage : usage
|
|
1851
1891
|
};
|
|
@@ -2208,7 +2248,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2208
2248
|
cacheControlValidator,
|
|
2209
2249
|
toolNameMapping
|
|
2210
2250
|
}) {
|
|
2211
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
2251
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
2212
2252
|
const betas = /* @__PURE__ */ new Set();
|
|
2213
2253
|
const blocks = groupIntoBlocks(prompt);
|
|
2214
2254
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -2240,19 +2280,52 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2240
2280
|
const type = block.type;
|
|
2241
2281
|
switch (type) {
|
|
2242
2282
|
case "system": {
|
|
2243
|
-
const content =
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2283
|
+
const content = [];
|
|
2284
|
+
let toolChangeCount = 0;
|
|
2285
|
+
for (const { content: text, providerOptions } of block.messages) {
|
|
2286
|
+
const systemMessageOptions = await (0, import_provider_utils14.parseProviderOptions)({
|
|
2287
|
+
provider: "anthropic",
|
|
2288
|
+
providerOptions,
|
|
2289
|
+
schema: anthropicSystemMessageProviderOptions
|
|
2290
|
+
});
|
|
2291
|
+
const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
|
|
2292
|
+
if (text !== "" || toolChanges.length === 0) {
|
|
2293
|
+
content.push({
|
|
2294
|
+
type: "text",
|
|
2295
|
+
text,
|
|
2296
|
+
cache_control: validator.getCacheControl(providerOptions, {
|
|
2297
|
+
type: "system message",
|
|
2298
|
+
canCache: true
|
|
2299
|
+
})
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
2302
|
+
for (const toolChange of toolChanges) {
|
|
2303
|
+
toolChangeCount++;
|
|
2304
|
+
content.push({
|
|
2305
|
+
type: toolChange.type,
|
|
2306
|
+
tool: {
|
|
2307
|
+
type: "tool_reference",
|
|
2308
|
+
name: toolNameMapping.toProviderToolName(toolChange.toolName)
|
|
2309
|
+
}
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
if (i === 0 || system == null && toolChangeCount === 0) {
|
|
2314
|
+
if (toolChangeCount > 0) {
|
|
2315
|
+
warnings.push({
|
|
2316
|
+
type: "other",
|
|
2317
|
+
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."
|
|
2318
|
+
});
|
|
2319
|
+
}
|
|
2320
|
+
system = content.filter(
|
|
2321
|
+
(part) => part.type === "text"
|
|
2322
|
+
);
|
|
2253
2323
|
} else {
|
|
2254
2324
|
messages.push({ role: "system", content });
|
|
2255
2325
|
betas.add("mid-conversation-system-2026-04-07");
|
|
2326
|
+
if (toolChangeCount > 0) {
|
|
2327
|
+
betas.add("mid-conversation-tool-changes-2026-07-01");
|
|
2328
|
+
}
|
|
2256
2329
|
}
|
|
2257
2330
|
break;
|
|
2258
2331
|
}
|
|
@@ -2265,10 +2338,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2265
2338
|
for (let j = 0; j < content.length; j++) {
|
|
2266
2339
|
const part = content[j];
|
|
2267
2340
|
const isLastPart = j === content.length - 1;
|
|
2268
|
-
const cacheControl = (
|
|
2341
|
+
const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
|
|
2269
2342
|
type: "user message part",
|
|
2270
2343
|
canCache: true
|
|
2271
|
-
})) != null ?
|
|
2344
|
+
})) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
2272
2345
|
type: "user message",
|
|
2273
2346
|
canCache: true
|
|
2274
2347
|
}) : void 0;
|
|
@@ -2313,7 +2386,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2313
2386
|
media_type: "application/pdf",
|
|
2314
2387
|
data: (0, import_provider_utils14.convertToBase64)(part.data)
|
|
2315
2388
|
},
|
|
2316
|
-
title: (
|
|
2389
|
+
title: (_c = metadata.title) != null ? _c : part.filename,
|
|
2317
2390
|
...metadata.context && { context: metadata.context },
|
|
2318
2391
|
...enableCitations && {
|
|
2319
2392
|
citations: { enabled: true }
|
|
@@ -2337,7 +2410,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2337
2410
|
media_type: "text/plain",
|
|
2338
2411
|
data: convertToString(part.data)
|
|
2339
2412
|
},
|
|
2340
|
-
title: (
|
|
2413
|
+
title: (_d = metadata.title) != null ? _d : part.filename,
|
|
2341
2414
|
...metadata.context && { context: metadata.context },
|
|
2342
2415
|
...enableCitations && {
|
|
2343
2416
|
citations: { enabled: true }
|
|
@@ -2362,17 +2435,17 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2362
2435
|
continue;
|
|
2363
2436
|
}
|
|
2364
2437
|
const output = part.output;
|
|
2365
|
-
const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (
|
|
2438
|
+
const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (_e = output.value.find(
|
|
2366
2439
|
(contentPart) => contentPart.providerOptions != null
|
|
2367
|
-
)) == null ? void 0 :
|
|
2440
|
+
)) == null ? void 0 : _e.providerOptions : void 0;
|
|
2368
2441
|
const isLastPart = i2 === content.length - 1;
|
|
2369
|
-
const cacheControl = (
|
|
2442
|
+
const cacheControl = (_g = (_f = validator.getCacheControl(part.providerOptions, {
|
|
2370
2443
|
type: "tool result part",
|
|
2371
2444
|
canCache: true
|
|
2372
|
-
})) != null ?
|
|
2445
|
+
})) != null ? _f : validator.getCacheControl(outputProviderOptions, {
|
|
2373
2446
|
type: "tool result output",
|
|
2374
2447
|
canCache: true
|
|
2375
|
-
})) != null ?
|
|
2448
|
+
})) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
2376
2449
|
type: "tool result message",
|
|
2377
2450
|
canCache: true
|
|
2378
2451
|
}) : void 0;
|
|
@@ -2462,7 +2535,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2462
2535
|
contentValue = output.value;
|
|
2463
2536
|
break;
|
|
2464
2537
|
case "execution-denied":
|
|
2465
|
-
contentValue = (
|
|
2538
|
+
contentValue = (_h = output.reason) != null ? _h : "Tool call execution denied.";
|
|
2466
2539
|
break;
|
|
2467
2540
|
case "json":
|
|
2468
2541
|
case "error-json":
|
|
@@ -2499,16 +2572,16 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2499
2572
|
for (let k = 0; k < content.length; k++) {
|
|
2500
2573
|
const part = content[k];
|
|
2501
2574
|
const isLastContentPart = k === content.length - 1;
|
|
2502
|
-
const cacheControl = (
|
|
2575
|
+
const cacheControl = (_i = validator.getCacheControl(part.providerOptions, {
|
|
2503
2576
|
type: "assistant message part",
|
|
2504
2577
|
canCache: true
|
|
2505
|
-
})) != null ?
|
|
2578
|
+
})) != null ? _i : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
|
|
2506
2579
|
type: "assistant message",
|
|
2507
2580
|
canCache: true
|
|
2508
2581
|
}) : void 0;
|
|
2509
2582
|
switch (part.type) {
|
|
2510
2583
|
case "text": {
|
|
2511
|
-
const textMetadata = (
|
|
2584
|
+
const textMetadata = (_j = part.providerOptions) == null ? void 0 : _j.anthropic;
|
|
2512
2585
|
if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
|
|
2513
2586
|
anthropicContent.push({
|
|
2514
2587
|
type: "compaction",
|
|
@@ -2584,10 +2657,10 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2584
2657
|
const providerToolName = toolNameMapping.toProviderToolName(
|
|
2585
2658
|
part.toolName
|
|
2586
2659
|
);
|
|
2587
|
-
const isMcpToolUse = ((
|
|
2660
|
+
const isMcpToolUse = ((_l = (_k = part.providerOptions) == null ? void 0 : _k.anthropic) == null ? void 0 : _l.type) === "mcp-tool-use";
|
|
2588
2661
|
if (isMcpToolUse) {
|
|
2589
2662
|
mcpToolUseIds.add(part.toolCallId);
|
|
2590
|
-
const serverName = (
|
|
2663
|
+
const serverName = (_n = (_m = part.providerOptions) == null ? void 0 : _m.anthropic) == null ? void 0 : _n.serverName;
|
|
2591
2664
|
if (serverName == null || typeof serverName !== "string") {
|
|
2592
2665
|
warnings.push({
|
|
2593
2666
|
type: "other",
|
|
@@ -2663,7 +2736,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2663
2736
|
}
|
|
2664
2737
|
break;
|
|
2665
2738
|
}
|
|
2666
|
-
const callerOptions = (
|
|
2739
|
+
const callerOptions = (_o = part.providerOptions) == null ? void 0 : _o.anthropic;
|
|
2667
2740
|
const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? (callerOptions.caller.type === "code_execution_20250825" || callerOptions.caller.type === "code_execution_20260120") && callerOptions.caller.toolId ? {
|
|
2668
2741
|
type: callerOptions.caller.type,
|
|
2669
2742
|
tool_id: callerOptions.caller.toolId
|
|
@@ -2716,7 +2789,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2716
2789
|
tool_use_id: part.toolCallId,
|
|
2717
2790
|
content: {
|
|
2718
2791
|
type: "code_execution_tool_result_error",
|
|
2719
|
-
error_code: (
|
|
2792
|
+
error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
|
|
2720
2793
|
},
|
|
2721
2794
|
cache_control: cacheControl
|
|
2722
2795
|
});
|
|
@@ -2727,7 +2800,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2727
2800
|
cache_control: cacheControl,
|
|
2728
2801
|
content: {
|
|
2729
2802
|
type: "bash_code_execution_tool_result_error",
|
|
2730
|
-
error_code: (
|
|
2803
|
+
error_code: (_q = errorInfo.errorCode) != null ? _q : "unknown"
|
|
2731
2804
|
}
|
|
2732
2805
|
});
|
|
2733
2806
|
}
|
|
@@ -2760,7 +2833,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2760
2833
|
stdout: codeExecutionOutput.stdout,
|
|
2761
2834
|
stderr: codeExecutionOutput.stderr,
|
|
2762
2835
|
return_code: codeExecutionOutput.return_code,
|
|
2763
|
-
content: (
|
|
2836
|
+
content: (_r = codeExecutionOutput.content) != null ? _r : []
|
|
2764
2837
|
},
|
|
2765
2838
|
cache_control: cacheControl
|
|
2766
2839
|
});
|
|
@@ -2778,7 +2851,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2778
2851
|
encrypted_stdout: codeExecutionOutput.encrypted_stdout,
|
|
2779
2852
|
stderr: codeExecutionOutput.stderr,
|
|
2780
2853
|
return_code: codeExecutionOutput.return_code,
|
|
2781
|
-
content: (
|
|
2854
|
+
content: (_s = codeExecutionOutput.content) != null ? _s : []
|
|
2782
2855
|
},
|
|
2783
2856
|
cache_control: cacheControl
|
|
2784
2857
|
});
|
|
@@ -2797,7 +2870,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2797
2870
|
stdout: codeExecutionOutput.stdout,
|
|
2798
2871
|
stderr: codeExecutionOutput.stderr,
|
|
2799
2872
|
return_code: codeExecutionOutput.return_code,
|
|
2800
|
-
content: (
|
|
2873
|
+
content: (_t = codeExecutionOutput.content) != null ? _t : []
|
|
2801
2874
|
},
|
|
2802
2875
|
cache_control: cacheControl
|
|
2803
2876
|
});
|
|
@@ -2827,7 +2900,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2827
2900
|
tool_use_id: part.toolCallId,
|
|
2828
2901
|
content: {
|
|
2829
2902
|
type: "web_fetch_tool_result_error",
|
|
2830
|
-
error_code: (
|
|
2903
|
+
error_code: (_u = (await extractErrorValue(output.value)).errorCode) != null ? _u : "unavailable"
|
|
2831
2904
|
},
|
|
2832
2905
|
cache_control: cacheControl
|
|
2833
2906
|
});
|
|
@@ -2874,7 +2947,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2874
2947
|
tool_use_id: part.toolCallId,
|
|
2875
2948
|
content: {
|
|
2876
2949
|
type: "web_search_tool_result_error",
|
|
2877
|
-
error_code: (
|
|
2950
|
+
error_code: (_v = (await extractErrorValue(output.value)).errorCode) != null ? _v : "unavailable"
|
|
2878
2951
|
},
|
|
2879
2952
|
cache_control: cacheControl
|
|
2880
2953
|
});
|
|
@@ -3332,7 +3405,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3332
3405
|
providerOptions,
|
|
3333
3406
|
stream
|
|
3334
3407
|
}) {
|
|
3335
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3408
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3336
3409
|
const warnings = [];
|
|
3337
3410
|
if (frequencyPenalty != null) {
|
|
3338
3411
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -3388,6 +3461,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3388
3461
|
maxOutputTokens: maxOutputTokensForModel,
|
|
3389
3462
|
supportsStructuredOutput: modelSupportsStructuredOutput,
|
|
3390
3463
|
rejectsSamplingParameters,
|
|
3464
|
+
rejectsThinkingDisabledAboveHighEffort,
|
|
3391
3465
|
isKnownModel
|
|
3392
3466
|
} = getModelCapabilities(this.modelId);
|
|
3393
3467
|
if (!isKnownModel && maxOutputTokens == null) {
|
|
@@ -3474,11 +3548,19 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3474
3548
|
cacheControlValidator,
|
|
3475
3549
|
toolNameMapping
|
|
3476
3550
|
});
|
|
3477
|
-
|
|
3551
|
+
if (rejectsThinkingDisabledAboveHighEffort && ((_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type) === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
|
|
3552
|
+
warnings.push({
|
|
3553
|
+
type: "unsupported",
|
|
3554
|
+
feature: "providerOptions.anthropic.effort",
|
|
3555
|
+
details: `effort '${anthropicOptions.effort}' is not supported by ${this.modelId} when thinking is disabled. The effort has been lowered to 'high'.`
|
|
3556
|
+
});
|
|
3557
|
+
anthropicOptions.effort = "high";
|
|
3558
|
+
}
|
|
3559
|
+
const thinkingType = (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.type;
|
|
3478
3560
|
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
3479
3561
|
const sendThinking = isThinking || thinkingType === "disabled";
|
|
3480
|
-
let thinkingBudget = thinkingType === "enabled" ? (
|
|
3481
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
3562
|
+
let thinkingBudget = thinkingType === "enabled" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.budgetTokens : void 0;
|
|
3563
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.display : void 0;
|
|
3482
3564
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
3483
3565
|
const baseArgs = {
|
|
3484
3566
|
// model id:
|
|
@@ -3525,13 +3607,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3525
3607
|
...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
|
|
3526
3608
|
inference_geo: anthropicOptions.inferenceGeo
|
|
3527
3609
|
},
|
|
3528
|
-
...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0 && {
|
|
3610
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) != null && (anthropicOptions.fallbacks === "default" || anthropicOptions.fallbacks.length > 0) && {
|
|
3529
3611
|
fallbacks: anthropicOptions.fallbacks
|
|
3530
3612
|
},
|
|
3531
3613
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
3532
3614
|
cache_control: anthropicOptions.cacheControl
|
|
3533
3615
|
},
|
|
3534
|
-
...((
|
|
3616
|
+
...((_i = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _i.userId) != null && {
|
|
3535
3617
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
3536
3618
|
},
|
|
3537
3619
|
// mcp servers:
|
|
@@ -3704,10 +3786,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3704
3786
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
|
|
3705
3787
|
betas.add("fast-mode-2026-02-01");
|
|
3706
3788
|
}
|
|
3707
|
-
if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks)
|
|
3789
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) === "default") {
|
|
3790
|
+
betas.add("server-side-fallback-2026-07-01");
|
|
3791
|
+
} else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
|
|
3708
3792
|
betas.add("server-side-fallback-2026-06-01");
|
|
3709
3793
|
}
|
|
3710
|
-
const defaultEagerInputStreaming = stream && ((
|
|
3794
|
+
const defaultEagerInputStreaming = stream && ((_j = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _j : true);
|
|
3711
3795
|
const {
|
|
3712
3796
|
tools: anthropicTools2,
|
|
3713
3797
|
toolChoice: anthropicToolChoice,
|
|
@@ -3746,7 +3830,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3746
3830
|
...betas,
|
|
3747
3831
|
...toolsBetas,
|
|
3748
3832
|
...userSuppliedBetas,
|
|
3749
|
-
...(
|
|
3833
|
+
...(_k = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _k : []
|
|
3750
3834
|
]),
|
|
3751
3835
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
3752
3836
|
toolNameMapping,
|
|
@@ -5071,6 +5155,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5071
5155
|
usage.input_tokens = value.usage.input_tokens;
|
|
5072
5156
|
}
|
|
5073
5157
|
usage.output_tokens = value.usage.output_tokens;
|
|
5158
|
+
if (value.usage.output_tokens_details != null) {
|
|
5159
|
+
usage.output_tokens_details = value.usage.output_tokens_details;
|
|
5160
|
+
}
|
|
5074
5161
|
if (value.usage.cache_read_input_tokens != null) {
|
|
5075
5162
|
usage.cache_read_input_tokens = value.usage.cache_read_input_tokens;
|
|
5076
5163
|
}
|
|
@@ -5192,11 +5279,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5192
5279
|
}
|
|
5193
5280
|
};
|
|
5194
5281
|
function getModelCapabilities(modelId) {
|
|
5195
|
-
if (modelId.includes("claude-opus-
|
|
5282
|
+
if (modelId.includes("claude-opus-5")) {
|
|
5283
|
+
return {
|
|
5284
|
+
maxOutputTokens: 128e3,
|
|
5285
|
+
supportsStructuredOutput: true,
|
|
5286
|
+
rejectsSamplingParameters: true,
|
|
5287
|
+
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5288
|
+
isKnownModel: true
|
|
5289
|
+
};
|
|
5290
|
+
} 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
5291
|
return {
|
|
5197
5292
|
maxOutputTokens: 128e3,
|
|
5198
5293
|
supportsStructuredOutput: true,
|
|
5199
5294
|
rejectsSamplingParameters: true,
|
|
5295
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5200
5296
|
isKnownModel: true
|
|
5201
5297
|
};
|
|
5202
5298
|
} else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
|
|
@@ -5204,6 +5300,7 @@ function getModelCapabilities(modelId) {
|
|
|
5204
5300
|
maxOutputTokens: 128e3,
|
|
5205
5301
|
supportsStructuredOutput: true,
|
|
5206
5302
|
rejectsSamplingParameters: false,
|
|
5303
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5207
5304
|
isKnownModel: true
|
|
5208
5305
|
};
|
|
5209
5306
|
} else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
|
|
@@ -5211,6 +5308,7 @@ function getModelCapabilities(modelId) {
|
|
|
5211
5308
|
maxOutputTokens: 64e3,
|
|
5212
5309
|
supportsStructuredOutput: true,
|
|
5213
5310
|
rejectsSamplingParameters: false,
|
|
5311
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5214
5312
|
isKnownModel: true
|
|
5215
5313
|
};
|
|
5216
5314
|
} else if (modelId.includes("claude-opus-4-1")) {
|
|
@@ -5218,6 +5316,7 @@ function getModelCapabilities(modelId) {
|
|
|
5218
5316
|
maxOutputTokens: 32e3,
|
|
5219
5317
|
supportsStructuredOutput: true,
|
|
5220
5318
|
rejectsSamplingParameters: false,
|
|
5319
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5221
5320
|
isKnownModel: true
|
|
5222
5321
|
};
|
|
5223
5322
|
} else if (modelId.includes("claude-sonnet-4-")) {
|
|
@@ -5225,6 +5324,7 @@ function getModelCapabilities(modelId) {
|
|
|
5225
5324
|
maxOutputTokens: 64e3,
|
|
5226
5325
|
supportsStructuredOutput: false,
|
|
5227
5326
|
rejectsSamplingParameters: false,
|
|
5327
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5228
5328
|
isKnownModel: true
|
|
5229
5329
|
};
|
|
5230
5330
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
@@ -5232,6 +5332,7 @@ function getModelCapabilities(modelId) {
|
|
|
5232
5332
|
maxOutputTokens: 32e3,
|
|
5233
5333
|
supportsStructuredOutput: false,
|
|
5234
5334
|
rejectsSamplingParameters: false,
|
|
5335
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5235
5336
|
isKnownModel: true
|
|
5236
5337
|
};
|
|
5237
5338
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
@@ -5239,6 +5340,7 @@ function getModelCapabilities(modelId) {
|
|
|
5239
5340
|
maxOutputTokens: 4096,
|
|
5240
5341
|
supportsStructuredOutput: false,
|
|
5241
5342
|
rejectsSamplingParameters: false,
|
|
5343
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5242
5344
|
isKnownModel: true
|
|
5243
5345
|
};
|
|
5244
5346
|
} else if (/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(modelId)) {
|
|
@@ -5246,6 +5348,7 @@ function getModelCapabilities(modelId) {
|
|
|
5246
5348
|
maxOutputTokens: 4096,
|
|
5247
5349
|
supportsStructuredOutput: false,
|
|
5248
5350
|
rejectsSamplingParameters: false,
|
|
5351
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5249
5352
|
isKnownModel: false
|
|
5250
5353
|
};
|
|
5251
5354
|
} else if (modelId.includes("claude-")) {
|
|
@@ -5253,6 +5356,7 @@ function getModelCapabilities(modelId) {
|
|
|
5253
5356
|
maxOutputTokens: 128e3,
|
|
5254
5357
|
supportsStructuredOutput: true,
|
|
5255
5358
|
rejectsSamplingParameters: true,
|
|
5359
|
+
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5256
5360
|
isKnownModel: false
|
|
5257
5361
|
};
|
|
5258
5362
|
} else {
|
|
@@ -5260,6 +5364,7 @@ function getModelCapabilities(modelId) {
|
|
|
5260
5364
|
maxOutputTokens: 4096,
|
|
5261
5365
|
supportsStructuredOutput: false,
|
|
5262
5366
|
rejectsSamplingParameters: false,
|
|
5367
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5263
5368
|
isKnownModel: false
|
|
5264
5369
|
};
|
|
5265
5370
|
}
|