@ai-sdk/anthropic 3.0.81 → 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 +6 -0
- package/dist/index.d.mts +56 -31
- package/dist/index.d.ts +56 -31
- package/dist/index.js +114 -67
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +114 -67
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +113 -66
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +113 -66
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +58 -0
- package/package.json +1 -1
- package/src/anthropic-message-metadata.ts +67 -54
- package/src/anthropic-messages-api.ts +48 -37
- package/src/anthropic-messages-language-model.ts +90 -73
- package/src/anthropic-messages-options.ts +29 -0
- package/src/convert-anthropic-messages-usage.ts +28 -20
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
|
);
|
|
@@ -3502,6 +3538,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3502
3538
|
...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
|
|
3503
3539
|
inference_geo: anthropicOptions.inferenceGeo
|
|
3504
3540
|
},
|
|
3541
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0 && {
|
|
3542
|
+
fallbacks: anthropicOptions.fallbacks
|
|
3543
|
+
},
|
|
3505
3544
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
3506
3545
|
cache_control: anthropicOptions.cacheControl
|
|
3507
3546
|
},
|
|
@@ -3678,6 +3717,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3678
3717
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
|
|
3679
3718
|
betas.add("fast-mode-2026-02-01");
|
|
3680
3719
|
}
|
|
3720
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
|
|
3721
|
+
betas.add("server-side-fallback-2026-06-01");
|
|
3722
|
+
}
|
|
3681
3723
|
const defaultEagerInputStreaming = stream && ((_i = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _i : true);
|
|
3682
3724
|
const {
|
|
3683
3725
|
tools: anthropicTools2,
|
|
@@ -4200,6 +4242,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4200
4242
|
}
|
|
4201
4243
|
break;
|
|
4202
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
|
+
}
|
|
4203
4251
|
}
|
|
4204
4252
|
}
|
|
4205
4253
|
return {
|
|
@@ -4222,14 +4270,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4222
4270
|
warnings,
|
|
4223
4271
|
providerMetadata: (() => {
|
|
4224
4272
|
var _a2, _b2, _c2, _d2, _e2;
|
|
4273
|
+
const stopDetails = mapAnthropicStopDetails(response.stop_details);
|
|
4225
4274
|
const anthropicMetadata = {
|
|
4226
4275
|
usage: response.usage,
|
|
4227
4276
|
cacheCreationInputTokens: (_a2 = response.usage.cache_creation_input_tokens) != null ? _a2 : null,
|
|
4228
4277
|
stopSequence: (_b2 = response.stop_sequence) != null ? _b2 : null,
|
|
4278
|
+
...stopDetails != null ? { stopDetails } : {},
|
|
4229
4279
|
iterations: response.usage.iterations ? response.usage.iterations.map(
|
|
4230
|
-
(iter) =>
|
|
4280
|
+
(iter) => ({
|
|
4231
4281
|
type: iter.type,
|
|
4232
|
-
model: iter.model,
|
|
4282
|
+
...iter.model != null ? { model: iter.model } : {},
|
|
4233
4283
|
inputTokens: iter.input_tokens,
|
|
4234
4284
|
outputTokens: iter.output_tokens,
|
|
4235
4285
|
...iter.cache_creation_input_tokens ? {
|
|
@@ -4238,17 +4288,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4238
4288
|
...iter.cache_read_input_tokens ? {
|
|
4239
4289
|
cacheReadInputTokens: iter.cache_read_input_tokens
|
|
4240
4290
|
} : {}
|
|
4241
|
-
}
|
|
4242
|
-
type: iter.type,
|
|
4243
|
-
inputTokens: iter.input_tokens,
|
|
4244
|
-
outputTokens: iter.output_tokens,
|
|
4245
|
-
...iter.cache_creation_input_tokens ? {
|
|
4246
|
-
cacheCreationInputTokens: iter.cache_creation_input_tokens
|
|
4247
|
-
} : {},
|
|
4248
|
-
...iter.cache_read_input_tokens ? {
|
|
4249
|
-
cacheReadInputTokens: iter.cache_read_input_tokens
|
|
4250
|
-
} : {}
|
|
4251
|
-
}
|
|
4291
|
+
})
|
|
4252
4292
|
) : null,
|
|
4253
4293
|
container: response.container ? {
|
|
4254
4294
|
expiresAt: response.container.expires_at,
|
|
@@ -4324,6 +4364,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4324
4364
|
let rawUsage = void 0;
|
|
4325
4365
|
let cacheCreationInputTokens = null;
|
|
4326
4366
|
let stopSequence = null;
|
|
4367
|
+
let stopDetails = void 0;
|
|
4327
4368
|
let container = null;
|
|
4328
4369
|
let isJsonResponseFromTool = false;
|
|
4329
4370
|
let blockType = void 0;
|
|
@@ -4350,6 +4391,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4350
4391
|
case "content_block_start": {
|
|
4351
4392
|
const part = value.content_block;
|
|
4352
4393
|
const contentBlockType = part.type;
|
|
4394
|
+
if (contentBlockType === "fallback") {
|
|
4395
|
+
return;
|
|
4396
|
+
}
|
|
4353
4397
|
blockType = contentBlockType;
|
|
4354
4398
|
switch (contentBlockType) {
|
|
4355
4399
|
case "text": {
|
|
@@ -5023,6 +5067,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5023
5067
|
raw: (_k = value.delta.stop_reason) != null ? _k : void 0
|
|
5024
5068
|
};
|
|
5025
5069
|
stopSequence = (_l = value.delta.stop_sequence) != null ? _l : null;
|
|
5070
|
+
stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
|
|
5026
5071
|
container = value.delta.container != null ? {
|
|
5027
5072
|
expiresAt: value.delta.container.expires_at,
|
|
5028
5073
|
id: value.delta.container.id,
|
|
@@ -5048,10 +5093,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5048
5093
|
usage: rawUsage != null ? rawUsage : null,
|
|
5049
5094
|
cacheCreationInputTokens,
|
|
5050
5095
|
stopSequence,
|
|
5096
|
+
...stopDetails != null ? { stopDetails } : {},
|
|
5051
5097
|
iterations: usage.iterations ? usage.iterations.map(
|
|
5052
|
-
(iter) =>
|
|
5098
|
+
(iter) => ({
|
|
5053
5099
|
type: iter.type,
|
|
5054
|
-
model: iter.model,
|
|
5100
|
+
...iter.model != null ? { model: iter.model } : {},
|
|
5055
5101
|
inputTokens: iter.input_tokens,
|
|
5056
5102
|
outputTokens: iter.output_tokens,
|
|
5057
5103
|
...iter.cache_creation_input_tokens ? {
|
|
@@ -5060,17 +5106,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5060
5106
|
...iter.cache_read_input_tokens ? {
|
|
5061
5107
|
cacheReadInputTokens: iter.cache_read_input_tokens
|
|
5062
5108
|
} : {}
|
|
5063
|
-
}
|
|
5064
|
-
type: iter.type,
|
|
5065
|
-
inputTokens: iter.input_tokens,
|
|
5066
|
-
outputTokens: iter.output_tokens,
|
|
5067
|
-
...iter.cache_creation_input_tokens ? {
|
|
5068
|
-
cacheCreationInputTokens: iter.cache_creation_input_tokens
|
|
5069
|
-
} : {},
|
|
5070
|
-
...iter.cache_read_input_tokens ? {
|
|
5071
|
-
cacheReadInputTokens: iter.cache_read_input_tokens
|
|
5072
|
-
} : {}
|
|
5073
|
-
}
|
|
5109
|
+
})
|
|
5074
5110
|
) : null,
|
|
5075
5111
|
container,
|
|
5076
5112
|
contextManagement
|
|
@@ -5134,7 +5170,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5134
5170
|
}
|
|
5135
5171
|
};
|
|
5136
5172
|
function getModelCapabilities(modelId) {
|
|
5137
|
-
if (modelId.includes("claude-opus-4-8") || 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")) {
|
|
5138
5174
|
return {
|
|
5139
5175
|
maxOutputTokens: 128e3,
|
|
5140
5176
|
supportsStructuredOutput: true,
|
|
@@ -5235,6 +5271,17 @@ function mapAnthropicResponseContextManagement(contextManagement) {
|
|
|
5235
5271
|
}).filter((edit) => edit !== void 0)
|
|
5236
5272
|
} : null;
|
|
5237
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
|
+
}
|
|
5238
5285
|
|
|
5239
5286
|
// src/tool/bash_20241022.ts
|
|
5240
5287
|
import {
|