@ai-sdk/anthropic 3.0.80 → 3.0.82
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 +12 -0
- package/dist/index.d.mts +57 -32
- package/dist/index.d.ts +57 -32
- package/dist/index.js +123 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +123 -75
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -2
- package/dist/internal/index.d.ts +2 -2
- package/dist/internal/index.js +122 -74
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +122 -74
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +63 -4
- package/package.json +1 -1
- package/src/anthropic-message-metadata.ts +67 -54
- package/src/anthropic-messages-api.ts +57 -38
- package/src/anthropic-messages-language-model.ts +93 -73
- package/src/anthropic-messages-options.ts +30 -0
- package/src/anthropic-tools.ts +1 -1
- package/src/convert-anthropic-messages-usage.ts +28 -20
- package/src/convert-to-anthropic-messages-prompt.ts +9 -9
- package/src/tool/advisor_20260301.ts +1 -1
package/dist/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "@ai-sdk/provider-utils";
|
|
13
13
|
|
|
14
14
|
// src/version.ts
|
|
15
|
-
var VERSION = true ? "3.0.
|
|
15
|
+
var VERSION = true ? "3.0.82" : "0.0.0-test";
|
|
16
16
|
|
|
17
17
|
// src/anthropic-messages-language-model.ts
|
|
18
18
|
import {
|
|
@@ -58,6 +58,12 @@ import {
|
|
|
58
58
|
zodSchema as zodSchema2
|
|
59
59
|
} from "@ai-sdk/provider-utils";
|
|
60
60
|
import { z as z2 } from "zod/v4";
|
|
61
|
+
var anthropicStopDetailsSchema = z2.object({
|
|
62
|
+
type: z2.string(),
|
|
63
|
+
category: z2.string().nullish(),
|
|
64
|
+
explanation: z2.string().nullish(),
|
|
65
|
+
recommended_model: z2.string().nullish()
|
|
66
|
+
});
|
|
61
67
|
var anthropicMessagesResponseSchema = lazySchema2(
|
|
62
68
|
() => zodSchema2(
|
|
63
69
|
z2.object({
|
|
@@ -343,34 +349,37 @@ var anthropicMessagesResponseSchema = lazySchema2(
|
|
|
343
349
|
error_code: z2.string()
|
|
344
350
|
})
|
|
345
351
|
])
|
|
352
|
+
}),
|
|
353
|
+
// Server-side fallback marker. Parsed so the response validates, but
|
|
354
|
+
// dropped from the content output (the AI SDK has no model-hop
|
|
355
|
+
// primitive). The hop remains observable via usage.iterations.
|
|
356
|
+
z2.object({
|
|
357
|
+
type: z2.literal("fallback")
|
|
346
358
|
})
|
|
347
359
|
])
|
|
348
360
|
),
|
|
349
361
|
stop_reason: z2.string().nullish(),
|
|
350
362
|
stop_sequence: z2.string().nullish(),
|
|
363
|
+
stop_details: anthropicStopDetailsSchema.nullish(),
|
|
351
364
|
usage: z2.looseObject({
|
|
352
365
|
input_tokens: z2.number(),
|
|
353
366
|
output_tokens: z2.number(),
|
|
354
367
|
cache_creation_input_tokens: z2.number().nullish(),
|
|
355
368
|
cache_read_input_tokens: z2.number().nullish(),
|
|
356
369
|
iterations: z2.array(
|
|
357
|
-
z2.
|
|
358
|
-
z2.
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
z2.
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
cache_creation_input_tokens: z2.number().nullish(),
|
|
371
|
-
cache_read_input_tokens: z2.number().nullish()
|
|
372
|
-
})
|
|
373
|
-
])
|
|
370
|
+
z2.object({
|
|
371
|
+
type: z2.union([
|
|
372
|
+
z2.literal("compaction"),
|
|
373
|
+
z2.literal("message"),
|
|
374
|
+
z2.literal("advisor_message"),
|
|
375
|
+
z2.literal("fallback_message")
|
|
376
|
+
]),
|
|
377
|
+
model: z2.string().nullish(),
|
|
378
|
+
input_tokens: z2.number(),
|
|
379
|
+
output_tokens: z2.number(),
|
|
380
|
+
cache_creation_input_tokens: z2.number().nullish(),
|
|
381
|
+
cache_read_input_tokens: z2.number().nullish()
|
|
382
|
+
})
|
|
374
383
|
).nullish()
|
|
375
384
|
}),
|
|
376
385
|
container: z2.object({
|
|
@@ -705,6 +714,11 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
705
714
|
error_code: z2.string()
|
|
706
715
|
})
|
|
707
716
|
])
|
|
717
|
+
}),
|
|
718
|
+
// Server-side fallback marker; dropped from content output (see the
|
|
719
|
+
// response schema). The hop remains observable via usage.iterations.
|
|
720
|
+
z2.object({
|
|
721
|
+
type: z2.literal("fallback")
|
|
708
722
|
})
|
|
709
723
|
])
|
|
710
724
|
}),
|
|
@@ -778,6 +792,7 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
778
792
|
delta: z2.object({
|
|
779
793
|
stop_reason: z2.string().nullish(),
|
|
780
794
|
stop_sequence: z2.string().nullish(),
|
|
795
|
+
stop_details: anthropicStopDetailsSchema.nullish(),
|
|
781
796
|
container: z2.object({
|
|
782
797
|
expires_at: z2.string(),
|
|
783
798
|
id: z2.string(),
|
|
@@ -799,26 +814,19 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
799
814
|
cache_creation_input_tokens: z2.number().nullish(),
|
|
800
815
|
cache_read_input_tokens: z2.number().nullish(),
|
|
801
816
|
iterations: z2.array(
|
|
802
|
-
z2.
|
|
803
|
-
z2.
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
z2.
|
|
814
|
-
|
|
815
|
-
model: z2.string(),
|
|
816
|
-
input_tokens: z2.number(),
|
|
817
|
-
output_tokens: z2.number(),
|
|
818
|
-
cache_creation_input_tokens: z2.number().nullish(),
|
|
819
|
-
cache_read_input_tokens: z2.number().nullish()
|
|
820
|
-
})
|
|
821
|
-
])
|
|
817
|
+
z2.object({
|
|
818
|
+
type: z2.union([
|
|
819
|
+
z2.literal("compaction"),
|
|
820
|
+
z2.literal("message"),
|
|
821
|
+
z2.literal("advisor_message"),
|
|
822
|
+
z2.literal("fallback_message")
|
|
823
|
+
]),
|
|
824
|
+
model: z2.string().nullish(),
|
|
825
|
+
input_tokens: z2.number(),
|
|
826
|
+
output_tokens: z2.number(),
|
|
827
|
+
cache_creation_input_tokens: z2.number().nullish(),
|
|
828
|
+
cache_read_input_tokens: z2.number().nullish()
|
|
829
|
+
})
|
|
822
830
|
).nullish()
|
|
823
831
|
}),
|
|
824
832
|
context_management: z2.object({
|
|
@@ -1022,6 +1030,31 @@ var anthropicLanguageModelOptions = z3.object({
|
|
|
1022
1030
|
* See https://platform.claude.com/docs/en/build-with-claude/data-residency
|
|
1023
1031
|
*/
|
|
1024
1032
|
inferenceGeo: z3.enum(["us", "global"]).optional(),
|
|
1033
|
+
/**
|
|
1034
|
+
* Server-side fallback chain.
|
|
1035
|
+
*
|
|
1036
|
+
* When the primary model's safety classifiers block a turn, the API
|
|
1037
|
+
* automatically retries it on the next model in the chain, server-side. A
|
|
1038
|
+
* `content-filter` finish reason means the entire chain refused.
|
|
1039
|
+
*
|
|
1040
|
+
* Each entry is merged into the request as a direct request to that entry's
|
|
1041
|
+
* model, so it must be formatted accordingly: `model` is required, and an
|
|
1042
|
+
* entry may additionally override `max_tokens`, `thinking`, `output_config`,
|
|
1043
|
+
* and `speed` for that attempt only (`speed` additionally requires the speed
|
|
1044
|
+
* beta). The value is passed through to the API as-is.
|
|
1045
|
+
*
|
|
1046
|
+
* The required `server-side-fallback-2026-06-01` beta is added automatically
|
|
1047
|
+
* when this option is set.
|
|
1048
|
+
*/
|
|
1049
|
+
fallbacks: z3.array(
|
|
1050
|
+
z3.object({
|
|
1051
|
+
model: z3.string(),
|
|
1052
|
+
max_tokens: z3.number().int().optional(),
|
|
1053
|
+
thinking: z3.record(z3.string(), z3.unknown()).optional(),
|
|
1054
|
+
output_config: z3.record(z3.string(), z3.unknown()).optional(),
|
|
1055
|
+
speed: z3.enum(["fast", "standard"]).optional()
|
|
1056
|
+
})
|
|
1057
|
+
).optional(),
|
|
1025
1058
|
/**
|
|
1026
1059
|
* A set of beta features to enable.
|
|
1027
1060
|
* Allow a provider to receive the full `betas` set if it needs it.
|
|
@@ -1802,12 +1835,15 @@ function convertAnthropicMessagesUsage({
|
|
|
1802
1835
|
usage,
|
|
1803
1836
|
rawUsage
|
|
1804
1837
|
}) {
|
|
1805
|
-
var _a, _b;
|
|
1838
|
+
var _a, _b, _c;
|
|
1806
1839
|
const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
|
|
1807
1840
|
const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
|
|
1808
1841
|
let inputTokens;
|
|
1809
1842
|
let outputTokens;
|
|
1810
|
-
|
|
1843
|
+
const servedByFallback = (_c = usage.iterations) == null ? void 0 : _c.some(
|
|
1844
|
+
(iter) => iter.type === "fallback_message"
|
|
1845
|
+
);
|
|
1846
|
+
if (usage.iterations && usage.iterations.length > 0 && !servedByFallback) {
|
|
1811
1847
|
const executorIterations = usage.iterations.filter(
|
|
1812
1848
|
(iter) => iter.type === "compaction" || iter.type === "message"
|
|
1813
1849
|
);
|
|
@@ -2259,19 +2295,20 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2259
2295
|
const type = block.type;
|
|
2260
2296
|
switch (type) {
|
|
2261
2297
|
case "system": {
|
|
2262
|
-
|
|
2263
|
-
throw new UnsupportedFunctionalityError2({
|
|
2264
|
-
functionality: "Multiple system messages that are separated by user/assistant messages"
|
|
2265
|
-
});
|
|
2266
|
-
}
|
|
2267
|
-
system = block.messages.map(({ content, providerOptions }) => ({
|
|
2298
|
+
const content = block.messages.map(({ content: content2, providerOptions }) => ({
|
|
2268
2299
|
type: "text",
|
|
2269
|
-
text:
|
|
2300
|
+
text: content2,
|
|
2270
2301
|
cache_control: validator.getCacheControl(providerOptions, {
|
|
2271
2302
|
type: "system message",
|
|
2272
2303
|
canCache: true
|
|
2273
2304
|
})
|
|
2274
2305
|
}));
|
|
2306
|
+
if (system == null) {
|
|
2307
|
+
system = content;
|
|
2308
|
+
} else {
|
|
2309
|
+
messages.push({ role: "system", content });
|
|
2310
|
+
betas.add("mid-conversation-system-2026-04-07");
|
|
2311
|
+
}
|
|
2275
2312
|
break;
|
|
2276
2313
|
}
|
|
2277
2314
|
case "user": {
|
|
@@ -3501,6 +3538,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3501
3538
|
...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
|
|
3502
3539
|
inference_geo: anthropicOptions.inferenceGeo
|
|
3503
3540
|
},
|
|
3541
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0 && {
|
|
3542
|
+
fallbacks: anthropicOptions.fallbacks
|
|
3543
|
+
},
|
|
3504
3544
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
3505
3545
|
cache_control: anthropicOptions.cacheControl
|
|
3506
3546
|
},
|
|
@@ -3677,6 +3717,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3677
3717
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
|
|
3678
3718
|
betas.add("fast-mode-2026-02-01");
|
|
3679
3719
|
}
|
|
3720
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
|
|
3721
|
+
betas.add("server-side-fallback-2026-06-01");
|
|
3722
|
+
}
|
|
3680
3723
|
const defaultEagerInputStreaming = stream && ((_i = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _i : true);
|
|
3681
3724
|
const {
|
|
3682
3725
|
tools: anthropicTools2,
|
|
@@ -4199,6 +4242,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4199
4242
|
}
|
|
4200
4243
|
break;
|
|
4201
4244
|
}
|
|
4245
|
+
// Server-side fallback marker: the AI SDK has no content primitive for
|
|
4246
|
+
// a model hop, so drop it. The hop is still observable via
|
|
4247
|
+
// usage.iterations.
|
|
4248
|
+
case "fallback": {
|
|
4249
|
+
break;
|
|
4250
|
+
}
|
|
4202
4251
|
}
|
|
4203
4252
|
}
|
|
4204
4253
|
return {
|
|
@@ -4221,14 +4270,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4221
4270
|
warnings,
|
|
4222
4271
|
providerMetadata: (() => {
|
|
4223
4272
|
var _a2, _b2, _c2, _d2, _e2;
|
|
4273
|
+
const stopDetails = mapAnthropicStopDetails(response.stop_details);
|
|
4224
4274
|
const anthropicMetadata = {
|
|
4225
4275
|
usage: response.usage,
|
|
4226
4276
|
cacheCreationInputTokens: (_a2 = response.usage.cache_creation_input_tokens) != null ? _a2 : null,
|
|
4227
4277
|
stopSequence: (_b2 = response.stop_sequence) != null ? _b2 : null,
|
|
4278
|
+
...stopDetails != null ? { stopDetails } : {},
|
|
4228
4279
|
iterations: response.usage.iterations ? response.usage.iterations.map(
|
|
4229
|
-
(iter) =>
|
|
4280
|
+
(iter) => ({
|
|
4230
4281
|
type: iter.type,
|
|
4231
|
-
model: iter.model,
|
|
4282
|
+
...iter.model != null ? { model: iter.model } : {},
|
|
4232
4283
|
inputTokens: iter.input_tokens,
|
|
4233
4284
|
outputTokens: iter.output_tokens,
|
|
4234
4285
|
...iter.cache_creation_input_tokens ? {
|
|
@@ -4237,17 +4288,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4237
4288
|
...iter.cache_read_input_tokens ? {
|
|
4238
4289
|
cacheReadInputTokens: iter.cache_read_input_tokens
|
|
4239
4290
|
} : {}
|
|
4240
|
-
}
|
|
4241
|
-
type: iter.type,
|
|
4242
|
-
inputTokens: iter.input_tokens,
|
|
4243
|
-
outputTokens: iter.output_tokens,
|
|
4244
|
-
...iter.cache_creation_input_tokens ? {
|
|
4245
|
-
cacheCreationInputTokens: iter.cache_creation_input_tokens
|
|
4246
|
-
} : {},
|
|
4247
|
-
...iter.cache_read_input_tokens ? {
|
|
4248
|
-
cacheReadInputTokens: iter.cache_read_input_tokens
|
|
4249
|
-
} : {}
|
|
4250
|
-
}
|
|
4291
|
+
})
|
|
4251
4292
|
) : null,
|
|
4252
4293
|
container: response.container ? {
|
|
4253
4294
|
expiresAt: response.container.expires_at,
|
|
@@ -4323,6 +4364,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4323
4364
|
let rawUsage = void 0;
|
|
4324
4365
|
let cacheCreationInputTokens = null;
|
|
4325
4366
|
let stopSequence = null;
|
|
4367
|
+
let stopDetails = void 0;
|
|
4326
4368
|
let container = null;
|
|
4327
4369
|
let isJsonResponseFromTool = false;
|
|
4328
4370
|
let blockType = void 0;
|
|
@@ -4349,6 +4391,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4349
4391
|
case "content_block_start": {
|
|
4350
4392
|
const part = value.content_block;
|
|
4351
4393
|
const contentBlockType = part.type;
|
|
4394
|
+
if (contentBlockType === "fallback") {
|
|
4395
|
+
return;
|
|
4396
|
+
}
|
|
4352
4397
|
blockType = contentBlockType;
|
|
4353
4398
|
switch (contentBlockType) {
|
|
4354
4399
|
case "text": {
|
|
@@ -5022,6 +5067,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5022
5067
|
raw: (_k = value.delta.stop_reason) != null ? _k : void 0
|
|
5023
5068
|
};
|
|
5024
5069
|
stopSequence = (_l = value.delta.stop_sequence) != null ? _l : null;
|
|
5070
|
+
stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
|
|
5025
5071
|
container = value.delta.container != null ? {
|
|
5026
5072
|
expiresAt: value.delta.container.expires_at,
|
|
5027
5073
|
id: value.delta.container.id,
|
|
@@ -5047,20 +5093,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5047
5093
|
usage: rawUsage != null ? rawUsage : null,
|
|
5048
5094
|
cacheCreationInputTokens,
|
|
5049
5095
|
stopSequence,
|
|
5096
|
+
...stopDetails != null ? { stopDetails } : {},
|
|
5050
5097
|
iterations: usage.iterations ? usage.iterations.map(
|
|
5051
|
-
(iter) =>
|
|
5052
|
-
type: iter.type,
|
|
5053
|
-
model: iter.model,
|
|
5054
|
-
inputTokens: iter.input_tokens,
|
|
5055
|
-
outputTokens: iter.output_tokens,
|
|
5056
|
-
...iter.cache_creation_input_tokens ? {
|
|
5057
|
-
cacheCreationInputTokens: iter.cache_creation_input_tokens
|
|
5058
|
-
} : {},
|
|
5059
|
-
...iter.cache_read_input_tokens ? {
|
|
5060
|
-
cacheReadInputTokens: iter.cache_read_input_tokens
|
|
5061
|
-
} : {}
|
|
5062
|
-
} : {
|
|
5098
|
+
(iter) => ({
|
|
5063
5099
|
type: iter.type,
|
|
5100
|
+
...iter.model != null ? { model: iter.model } : {},
|
|
5064
5101
|
inputTokens: iter.input_tokens,
|
|
5065
5102
|
outputTokens: iter.output_tokens,
|
|
5066
5103
|
...iter.cache_creation_input_tokens ? {
|
|
@@ -5069,7 +5106,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5069
5106
|
...iter.cache_read_input_tokens ? {
|
|
5070
5107
|
cacheReadInputTokens: iter.cache_read_input_tokens
|
|
5071
5108
|
} : {}
|
|
5072
|
-
}
|
|
5109
|
+
})
|
|
5073
5110
|
) : null,
|
|
5074
5111
|
container,
|
|
5075
5112
|
contextManagement
|
|
@@ -5133,7 +5170,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5133
5170
|
}
|
|
5134
5171
|
};
|
|
5135
5172
|
function getModelCapabilities(modelId) {
|
|
5136
|
-
if (modelId.includes("claude-opus-4-7")) {
|
|
5173
|
+
if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5")) {
|
|
5137
5174
|
return {
|
|
5138
5175
|
maxOutputTokens: 128e3,
|
|
5139
5176
|
supportsStructuredOutput: true,
|
|
@@ -5234,6 +5271,17 @@ function mapAnthropicResponseContextManagement(contextManagement) {
|
|
|
5234
5271
|
}).filter((edit) => edit !== void 0)
|
|
5235
5272
|
} : null;
|
|
5236
5273
|
}
|
|
5274
|
+
function mapAnthropicStopDetails(stopDetails) {
|
|
5275
|
+
if (stopDetails == null) {
|
|
5276
|
+
return void 0;
|
|
5277
|
+
}
|
|
5278
|
+
return {
|
|
5279
|
+
type: stopDetails.type,
|
|
5280
|
+
...stopDetails.category != null ? { category: stopDetails.category } : {},
|
|
5281
|
+
...stopDetails.explanation != null ? { explanation: stopDetails.explanation } : {},
|
|
5282
|
+
...stopDetails.recommended_model != null ? { recommendedModel: stopDetails.recommended_model } : {}
|
|
5283
|
+
};
|
|
5284
|
+
}
|
|
5237
5285
|
|
|
5238
5286
|
// src/tool/bash_20241022.ts
|
|
5239
5287
|
import {
|
|
@@ -5591,7 +5639,7 @@ var anthropicTools = {
|
|
|
5591
5639
|
* Supported executor models: Claude Haiku 4.5, Sonnet 4.6, Opus 4.6,
|
|
5592
5640
|
* Opus 4.7. The advisor must be at least as capable as the executor.
|
|
5593
5641
|
*
|
|
5594
|
-
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-
|
|
5642
|
+
* @param model - The advisor model ID (required), e.g. `"claude-opus-4-8"`.
|
|
5595
5643
|
* @param maxUses - Maximum advisor calls per request (per-request cap).
|
|
5596
5644
|
* @param caching - Enables prompt caching for the advisor's transcript
|
|
5597
5645
|
* across calls within a conversation. Worthwhile from ~3 advisor calls
|