@ai-sdk/anthropic 2.0.80 → 2.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 +14 -0
- package/dist/index.d.mts +57 -4
- package/dist/index.d.ts +57 -4
- package/dist/index.js +120 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +120 -21
- 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 +119 -20
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +119 -20
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "@ai-sdk/provider-utils";
|
|
12
12
|
|
|
13
13
|
// src/version.ts
|
|
14
|
-
var VERSION = true ? "2.0.
|
|
14
|
+
var VERSION = true ? "2.0.82" : "0.0.0-test";
|
|
15
15
|
|
|
16
16
|
// src/anthropic-messages-language-model.ts
|
|
17
17
|
import {
|
|
@@ -56,6 +56,12 @@ import {
|
|
|
56
56
|
zodSchema as zodSchema2
|
|
57
57
|
} from "@ai-sdk/provider-utils";
|
|
58
58
|
import { z as z2 } from "zod/v4";
|
|
59
|
+
var anthropicStopDetailsSchema = z2.object({
|
|
60
|
+
type: z2.string(),
|
|
61
|
+
category: z2.string().nullish(),
|
|
62
|
+
explanation: z2.string().nullish(),
|
|
63
|
+
recommended_model: z2.string().nullish()
|
|
64
|
+
});
|
|
59
65
|
var anthropicMessagesResponseSchema = lazySchema2(
|
|
60
66
|
() => zodSchema2(
|
|
61
67
|
z2.object({
|
|
@@ -243,11 +249,18 @@ var anthropicMessagesResponseSchema = lazySchema2(
|
|
|
243
249
|
old_start: z2.number().nullable()
|
|
244
250
|
})
|
|
245
251
|
])
|
|
252
|
+
}),
|
|
253
|
+
// Server-side fallback marker. Parsed so the response validates, but
|
|
254
|
+
// dropped from the content output (the AI SDK has no model-hop
|
|
255
|
+
// primitive). The hop remains observable via usage.iterations.
|
|
256
|
+
z2.object({
|
|
257
|
+
type: z2.literal("fallback")
|
|
246
258
|
})
|
|
247
259
|
])
|
|
248
260
|
),
|
|
249
261
|
stop_reason: z2.string().nullish(),
|
|
250
262
|
stop_sequence: z2.string().nullish(),
|
|
263
|
+
stop_details: anthropicStopDetailsSchema.nullish(),
|
|
251
264
|
usage: z2.looseObject({
|
|
252
265
|
input_tokens: z2.number(),
|
|
253
266
|
output_tokens: z2.number(),
|
|
@@ -255,9 +268,17 @@ var anthropicMessagesResponseSchema = lazySchema2(
|
|
|
255
268
|
cache_read_input_tokens: z2.number().nullish(),
|
|
256
269
|
iterations: z2.array(
|
|
257
270
|
z2.object({
|
|
258
|
-
type: z2.union([
|
|
271
|
+
type: z2.union([
|
|
272
|
+
z2.literal("compaction"),
|
|
273
|
+
z2.literal("message"),
|
|
274
|
+
z2.literal("advisor_message"),
|
|
275
|
+
z2.literal("fallback_message")
|
|
276
|
+
]),
|
|
277
|
+
model: z2.string().nullish(),
|
|
259
278
|
input_tokens: z2.number(),
|
|
260
|
-
output_tokens: z2.number()
|
|
279
|
+
output_tokens: z2.number(),
|
|
280
|
+
cache_creation_input_tokens: z2.number().nullish(),
|
|
281
|
+
cache_read_input_tokens: z2.number().nullish()
|
|
261
282
|
})
|
|
262
283
|
).nullish()
|
|
263
284
|
}),
|
|
@@ -463,6 +484,11 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
463
484
|
old_start: z2.number().nullable()
|
|
464
485
|
})
|
|
465
486
|
])
|
|
487
|
+
}),
|
|
488
|
+
// Server-side fallback marker; dropped from content output (see the
|
|
489
|
+
// response schema). The hop remains observable via usage.iterations.
|
|
490
|
+
z2.object({
|
|
491
|
+
type: z2.literal("fallback")
|
|
466
492
|
})
|
|
467
493
|
])
|
|
468
494
|
}),
|
|
@@ -536,6 +562,7 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
536
562
|
delta: z2.object({
|
|
537
563
|
stop_reason: z2.string().nullish(),
|
|
538
564
|
stop_sequence: z2.string().nullish(),
|
|
565
|
+
stop_details: anthropicStopDetailsSchema.nullish(),
|
|
539
566
|
container: z2.object({
|
|
540
567
|
expires_at: z2.string(),
|
|
541
568
|
id: z2.string(),
|
|
@@ -558,9 +585,17 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
558
585
|
cache_read_input_tokens: z2.number().nullish(),
|
|
559
586
|
iterations: z2.array(
|
|
560
587
|
z2.object({
|
|
561
|
-
type: z2.union([
|
|
588
|
+
type: z2.union([
|
|
589
|
+
z2.literal("compaction"),
|
|
590
|
+
z2.literal("message"),
|
|
591
|
+
z2.literal("advisor_message"),
|
|
592
|
+
z2.literal("fallback_message")
|
|
593
|
+
]),
|
|
594
|
+
model: z2.string().nullish(),
|
|
562
595
|
input_tokens: z2.number(),
|
|
563
|
-
output_tokens: z2.number()
|
|
596
|
+
output_tokens: z2.number(),
|
|
597
|
+
cache_creation_input_tokens: z2.number().nullish(),
|
|
598
|
+
cache_read_input_tokens: z2.number().nullish()
|
|
564
599
|
})
|
|
565
600
|
).nullish()
|
|
566
601
|
}),
|
|
@@ -735,6 +770,31 @@ var anthropicProviderOptions = z3.object({
|
|
|
735
770
|
* See https://platform.claude.com/docs/en/build-with-claude/data-residency
|
|
736
771
|
*/
|
|
737
772
|
inferenceGeo: z3.enum(["us", "global"]).optional(),
|
|
773
|
+
/**
|
|
774
|
+
* Server-side fallback chain.
|
|
775
|
+
*
|
|
776
|
+
* When the primary model's safety classifiers block a turn, the API
|
|
777
|
+
* automatically retries it on the next model in the chain, server-side. A
|
|
778
|
+
* `content-filter` finish reason means the entire chain refused.
|
|
779
|
+
*
|
|
780
|
+
* Each entry is merged into the request as a direct request to that entry's
|
|
781
|
+
* model, so it must be formatted accordingly: `model` is required, and an
|
|
782
|
+
* entry may additionally override `max_tokens`, `thinking`, `output_config`,
|
|
783
|
+
* and `speed` for that attempt only (`speed` additionally requires the speed
|
|
784
|
+
* beta). The value is passed through to the API as-is.
|
|
785
|
+
*
|
|
786
|
+
* The required `server-side-fallback-2026-06-01` beta is added automatically
|
|
787
|
+
* when this option is set.
|
|
788
|
+
*/
|
|
789
|
+
fallbacks: z3.array(
|
|
790
|
+
z3.object({
|
|
791
|
+
model: z3.string(),
|
|
792
|
+
max_tokens: z3.number().int().optional(),
|
|
793
|
+
thinking: z3.record(z3.string(), z3.unknown()).optional(),
|
|
794
|
+
output_config: z3.record(z3.string(), z3.unknown()).optional(),
|
|
795
|
+
speed: z3.enum(["fast", "standard"]).optional()
|
|
796
|
+
})
|
|
797
|
+
).optional(),
|
|
738
798
|
/**
|
|
739
799
|
* Context management configuration for automatic context window management.
|
|
740
800
|
* Enables features like automatic compaction and clearing of tool uses/thinking blocks.
|
|
@@ -2323,6 +2383,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2323
2383
|
...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
|
|
2324
2384
|
inference_geo: anthropicOptions.inferenceGeo
|
|
2325
2385
|
},
|
|
2386
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0 && {
|
|
2387
|
+
fallbacks: anthropicOptions.fallbacks
|
|
2388
|
+
},
|
|
2326
2389
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
2327
2390
|
cache_control: anthropicOptions.cacheControl
|
|
2328
2391
|
},
|
|
@@ -2465,6 +2528,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2465
2528
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
|
|
2466
2529
|
betas.add("fast-mode-2026-02-01");
|
|
2467
2530
|
}
|
|
2531
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
|
|
2532
|
+
betas.add("server-side-fallback-2026-06-01");
|
|
2533
|
+
}
|
|
2468
2534
|
if (useStructuredOutput) {
|
|
2469
2535
|
betas.add("structured-outputs-2025-11-13");
|
|
2470
2536
|
}
|
|
@@ -2564,7 +2630,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2564
2630
|
});
|
|
2565
2631
|
}
|
|
2566
2632
|
async doGenerate(options) {
|
|
2567
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2633
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2568
2634
|
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
|
|
2569
2635
|
...options,
|
|
2570
2636
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
@@ -2804,11 +2870,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2804
2870
|
});
|
|
2805
2871
|
break;
|
|
2806
2872
|
}
|
|
2873
|
+
// Server-side fallback marker: the AI SDK has no content primitive for
|
|
2874
|
+
// a model hop, so drop it. The hop is still observable via
|
|
2875
|
+
// usage.iterations.
|
|
2876
|
+
case "fallback": {
|
|
2877
|
+
break;
|
|
2878
|
+
}
|
|
2807
2879
|
}
|
|
2808
2880
|
}
|
|
2809
2881
|
let inputTokens;
|
|
2810
2882
|
let outputTokens;
|
|
2811
|
-
|
|
2883
|
+
const servedByFallback = (_b = response.usage.iterations) == null ? void 0 : _b.some(
|
|
2884
|
+
(iter) => iter.type === "fallback_message"
|
|
2885
|
+
);
|
|
2886
|
+
if (response.usage.iterations && response.usage.iterations.length > 0 && !servedByFallback) {
|
|
2812
2887
|
const totals = response.usage.iterations.reduce(
|
|
2813
2888
|
(acc, iter) => ({
|
|
2814
2889
|
input: acc.input + iter.input_tokens,
|
|
@@ -2822,6 +2897,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2822
2897
|
inputTokens = response.usage.input_tokens;
|
|
2823
2898
|
outputTokens = response.usage.output_tokens;
|
|
2824
2899
|
}
|
|
2900
|
+
const stopDetails = mapAnthropicStopDetails(response.stop_details);
|
|
2825
2901
|
return {
|
|
2826
2902
|
content,
|
|
2827
2903
|
finishReason: mapAnthropicStopReason({
|
|
@@ -2832,12 +2908,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2832
2908
|
inputTokens,
|
|
2833
2909
|
outputTokens,
|
|
2834
2910
|
totalTokens: inputTokens + outputTokens,
|
|
2835
|
-
cachedInputTokens: (
|
|
2911
|
+
cachedInputTokens: (_c = response.usage.cache_read_input_tokens) != null ? _c : void 0
|
|
2836
2912
|
},
|
|
2837
2913
|
request: { body: args },
|
|
2838
2914
|
response: {
|
|
2839
|
-
id: (
|
|
2840
|
-
modelId: (
|
|
2915
|
+
id: (_d = response.id) != null ? _d : void 0,
|
|
2916
|
+
modelId: (_e = response.model) != null ? _e : void 0,
|
|
2841
2917
|
headers: responseHeaders,
|
|
2842
2918
|
body: rawResponse
|
|
2843
2919
|
},
|
|
@@ -2845,21 +2921,23 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2845
2921
|
providerMetadata: {
|
|
2846
2922
|
anthropic: {
|
|
2847
2923
|
usage: response.usage,
|
|
2848
|
-
cacheCreationInputTokens: (
|
|
2849
|
-
stopSequence: (
|
|
2924
|
+
cacheCreationInputTokens: (_f = response.usage.cache_creation_input_tokens) != null ? _f : null,
|
|
2925
|
+
stopSequence: (_g = response.stop_sequence) != null ? _g : null,
|
|
2926
|
+
...stopDetails != null ? { stopDetails } : {},
|
|
2850
2927
|
iterations: response.usage.iterations ? response.usage.iterations.map((iter) => ({
|
|
2851
2928
|
type: iter.type,
|
|
2929
|
+
...iter.model != null ? { model: iter.model } : {},
|
|
2852
2930
|
inputTokens: iter.input_tokens,
|
|
2853
2931
|
outputTokens: iter.output_tokens
|
|
2854
2932
|
})) : null,
|
|
2855
2933
|
container: response.container ? {
|
|
2856
2934
|
expiresAt: response.container.expires_at,
|
|
2857
2935
|
id: response.container.id,
|
|
2858
|
-
skills: (
|
|
2936
|
+
skills: (_i = (_h = response.container.skills) == null ? void 0 : _h.map((skill) => ({
|
|
2859
2937
|
type: skill.type,
|
|
2860
2938
|
skillId: skill.skill_id,
|
|
2861
2939
|
version: skill.version
|
|
2862
|
-
}))) != null ?
|
|
2940
|
+
}))) != null ? _i : null
|
|
2863
2941
|
} : null,
|
|
2864
2942
|
contextManagement: response.context_management ? {
|
|
2865
2943
|
appliedEdits: response.context_management.applied_edits.map(
|
|
@@ -2920,6 +2998,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2920
2998
|
let rawUsage = void 0;
|
|
2921
2999
|
let cacheCreationInputTokens = null;
|
|
2922
3000
|
let stopSequence = null;
|
|
3001
|
+
let stopDetails = void 0;
|
|
2923
3002
|
let container = null;
|
|
2924
3003
|
let iterations = null;
|
|
2925
3004
|
let contextManagement = null;
|
|
@@ -2931,7 +3010,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2931
3010
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2932
3011
|
},
|
|
2933
3012
|
transform(chunk, controller) {
|
|
2934
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3013
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2935
3014
|
if (options.includeRawChunks) {
|
|
2936
3015
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2937
3016
|
}
|
|
@@ -2946,6 +3025,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2946
3025
|
}
|
|
2947
3026
|
case "content_block_start": {
|
|
2948
3027
|
const contentBlockType = value.content_block.type;
|
|
3028
|
+
if (contentBlockType === "fallback") {
|
|
3029
|
+
return;
|
|
3030
|
+
}
|
|
2949
3031
|
blockType = contentBlockType;
|
|
2950
3032
|
switch (contentBlockType) {
|
|
2951
3033
|
case "text": {
|
|
@@ -3338,7 +3420,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3338
3420
|
if (value.usage.iterations != null) {
|
|
3339
3421
|
iterations = value.usage.iterations;
|
|
3340
3422
|
}
|
|
3341
|
-
|
|
3423
|
+
const servedByFallback = (_f = value.usage.iterations) == null ? void 0 : _f.some(
|
|
3424
|
+
(iter) => iter.type === "fallback_message"
|
|
3425
|
+
);
|
|
3426
|
+
if (value.usage.iterations && value.usage.iterations.length > 0 && !servedByFallback) {
|
|
3342
3427
|
const totals = value.usage.iterations.reduce(
|
|
3343
3428
|
(acc, iter) => ({
|
|
3344
3429
|
input: acc.input + iter.input_tokens,
|
|
@@ -3354,20 +3439,21 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3354
3439
|
}
|
|
3355
3440
|
usage.outputTokens = value.usage.output_tokens;
|
|
3356
3441
|
}
|
|
3357
|
-
usage.totalTokens = ((
|
|
3442
|
+
usage.totalTokens = ((_g = usage.inputTokens) != null ? _g : 0) + ((_h = usage.outputTokens) != null ? _h : 0);
|
|
3358
3443
|
finishReason = mapAnthropicStopReason({
|
|
3359
3444
|
finishReason: value.delta.stop_reason,
|
|
3360
3445
|
isJsonResponseFromTool: usesJsonResponseTool
|
|
3361
3446
|
});
|
|
3362
|
-
|
|
3447
|
+
stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
|
|
3448
|
+
stopSequence = (_i = value.delta.stop_sequence) != null ? _i : null;
|
|
3363
3449
|
container = value.delta.container != null ? {
|
|
3364
3450
|
expiresAt: value.delta.container.expires_at,
|
|
3365
3451
|
id: value.delta.container.id,
|
|
3366
|
-
skills: (
|
|
3452
|
+
skills: (_k = (_j = value.delta.container.skills) == null ? void 0 : _j.map((skill) => ({
|
|
3367
3453
|
type: skill.type,
|
|
3368
3454
|
skillId: skill.skill_id,
|
|
3369
3455
|
version: skill.version
|
|
3370
|
-
}))) != null ?
|
|
3456
|
+
}))) != null ? _k : null
|
|
3371
3457
|
} : null;
|
|
3372
3458
|
if (value.context_management != null) {
|
|
3373
3459
|
contextManagement = {
|
|
@@ -3412,8 +3498,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3412
3498
|
usage: rawUsage != null ? rawUsage : null,
|
|
3413
3499
|
cacheCreationInputTokens,
|
|
3414
3500
|
stopSequence,
|
|
3501
|
+
...stopDetails != null ? { stopDetails } : {},
|
|
3415
3502
|
iterations: iterations ? iterations.map((iter) => ({
|
|
3416
3503
|
type: iter.type,
|
|
3504
|
+
...iter.model != null ? { model: iter.model } : {},
|
|
3417
3505
|
inputTokens: iter.input_tokens,
|
|
3418
3506
|
outputTokens: iter.output_tokens
|
|
3419
3507
|
})) : null,
|
|
@@ -3469,7 +3557,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3469
3557
|
}
|
|
3470
3558
|
};
|
|
3471
3559
|
function getModelCapabilities(modelId) {
|
|
3472
|
-
if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7")) {
|
|
3560
|
+
if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5")) {
|
|
3473
3561
|
return {
|
|
3474
3562
|
maxOutputTokens: 128e3,
|
|
3475
3563
|
supportsStructuredOutput: true,
|
|
@@ -3534,6 +3622,17 @@ function getModelCapabilities(modelId) {
|
|
|
3534
3622
|
};
|
|
3535
3623
|
}
|
|
3536
3624
|
}
|
|
3625
|
+
function mapAnthropicStopDetails(stopDetails) {
|
|
3626
|
+
if (stopDetails == null) {
|
|
3627
|
+
return void 0;
|
|
3628
|
+
}
|
|
3629
|
+
return {
|
|
3630
|
+
type: stopDetails.type,
|
|
3631
|
+
...stopDetails.category != null ? { category: stopDetails.category } : {},
|
|
3632
|
+
...stopDetails.explanation != null ? { explanation: stopDetails.explanation } : {},
|
|
3633
|
+
...stopDetails.recommended_model != null ? { recommendedModel: stopDetails.recommended_model } : {}
|
|
3634
|
+
};
|
|
3635
|
+
}
|
|
3537
3636
|
|
|
3538
3637
|
// src/tool/bash_20241022.ts
|
|
3539
3638
|
import {
|