@ai-sdk/anthropic 4.0.68 → 4.0.69
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 +10 -0
- package/dist/index.d.ts +1435 -1425
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6800 -8384
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +1960 -1932
- package/dist/internal/index.d.ts.map +1 -0
- package/dist/internal/index.js +5987 -7371
- package/dist/internal/index.js.map +1 -1
- package/package.json +8 -8
- package/src/anthropic-api.ts +15 -11
- package/src/anthropic-batch.ts +11 -0
- package/src/anthropic-language-model.ts +22 -6
- package/src/convert-to-anthropic-prompt.ts +34 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/anthropic",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.69",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ai-sdk/provider": "4.0.
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
38
|
+
"@ai-sdk/provider": "4.0.20",
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.52"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@ai-sdk/test-server": "2.0.
|
|
42
|
+
"@ai-sdk/test-server": "2.0.3",
|
|
43
43
|
"@types/node": "22.19.19",
|
|
44
44
|
"@vercel/ai-tsconfig": "0.0.0",
|
|
45
|
-
"
|
|
45
|
+
"tsdown": "^0.23.0",
|
|
46
46
|
"typescript": "5.8.3",
|
|
47
47
|
"zod": "3.25.76"
|
|
48
48
|
},
|
|
@@ -69,9 +69,9 @@
|
|
|
69
69
|
"ai"
|
|
70
70
|
],
|
|
71
71
|
"scripts": {
|
|
72
|
-
"build": "pnpm clean &&
|
|
73
|
-
"build:watch": "pnpm clean &&
|
|
74
|
-
"clean": "del-cli
|
|
72
|
+
"build": "pnpm clean && tsdown",
|
|
73
|
+
"build:watch": "pnpm clean && tsdown --watch",
|
|
74
|
+
"clean": "del-cli docs *.tsbuildinfo",
|
|
75
75
|
"type-check": "tsc --build",
|
|
76
76
|
"test": "pnpm test:node && pnpm test:edge",
|
|
77
77
|
"test:update": "pnpm test:node -u",
|
package/src/anthropic-api.ts
CHANGED
|
@@ -60,6 +60,7 @@ export interface AnthropicAssistantMessage {
|
|
|
60
60
|
| AnthropicTextContent
|
|
61
61
|
| AnthropicThinkingContent
|
|
62
62
|
| AnthropicRedactedThinkingContent
|
|
63
|
+
| AnthropicFallbackContent
|
|
63
64
|
| AnthropicToolCallContent
|
|
64
65
|
| AnthropicServerToolUseContent
|
|
65
66
|
| AnthropicCodeExecutionToolResultContent
|
|
@@ -75,6 +76,18 @@ export interface AnthropicAssistantMessage {
|
|
|
75
76
|
>;
|
|
76
77
|
}
|
|
77
78
|
|
|
79
|
+
export const anthropicFallbackContentSchema = z.object({
|
|
80
|
+
type: z.literal('fallback'),
|
|
81
|
+
from: z.object({ model: z.string() }),
|
|
82
|
+
to: z.object({ model: z.string() }),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export type AnthropicFallbackContent = InferSchema<
|
|
86
|
+
typeof anthropicFallbackContentSchema
|
|
87
|
+
> & {
|
|
88
|
+
cache_control?: never;
|
|
89
|
+
};
|
|
90
|
+
|
|
78
91
|
export interface AnthropicCompactionContent {
|
|
79
92
|
type: 'compaction';
|
|
80
93
|
content: string;
|
|
@@ -1033,12 +1046,7 @@ export const anthropicResponseSchema = lazySchema(() =>
|
|
|
1033
1046
|
}),
|
|
1034
1047
|
]),
|
|
1035
1048
|
}),
|
|
1036
|
-
|
|
1037
|
-
// dropped from the content output (the AI SDK has no model-hop
|
|
1038
|
-
// primitive). The hop remains observable via usage.iterations.
|
|
1039
|
-
z.object({
|
|
1040
|
-
type: z.literal('fallback'),
|
|
1041
|
-
}),
|
|
1049
|
+
anthropicFallbackContentSchema,
|
|
1042
1050
|
]),
|
|
1043
1051
|
),
|
|
1044
1052
|
stop_reason: z.string().nullish(),
|
|
@@ -1402,11 +1410,7 @@ export const anthropicChunkSchema = lazySchema(() =>
|
|
|
1402
1410
|
}),
|
|
1403
1411
|
]),
|
|
1404
1412
|
}),
|
|
1405
|
-
|
|
1406
|
-
// response schema). The hop remains observable via usage.iterations.
|
|
1407
|
-
z.object({
|
|
1408
|
-
type: z.literal('fallback'),
|
|
1409
|
-
}),
|
|
1413
|
+
anthropicFallbackContentSchema,
|
|
1410
1414
|
]),
|
|
1411
1415
|
}),
|
|
1412
1416
|
z.object({
|
package/src/anthropic-batch.ts
CHANGED
|
@@ -1056,6 +1056,17 @@ function convertAnthropicBatchResponse(
|
|
|
1056
1056
|
}
|
|
1057
1057
|
break;
|
|
1058
1058
|
case 'fallback':
|
|
1059
|
+
content.push({
|
|
1060
|
+
type: 'custom',
|
|
1061
|
+
kind: 'anthropic.fallback',
|
|
1062
|
+
providerMetadata: {
|
|
1063
|
+
anthropic: {
|
|
1064
|
+
type: 'fallback',
|
|
1065
|
+
from: part.from,
|
|
1066
|
+
to: part.to,
|
|
1067
|
+
},
|
|
1068
|
+
},
|
|
1069
|
+
});
|
|
1059
1070
|
break;
|
|
1060
1071
|
}
|
|
1061
1072
|
}
|
|
@@ -1721,10 +1721,18 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
1721
1721
|
break;
|
|
1722
1722
|
}
|
|
1723
1723
|
|
|
1724
|
-
// Server-side fallback marker: the AI SDK has no content primitive for
|
|
1725
|
-
// a model hop, so drop it. The hop is still observable via
|
|
1726
|
-
// usage.iterations.
|
|
1727
1724
|
case 'fallback': {
|
|
1725
|
+
content.push({
|
|
1726
|
+
type: 'custom',
|
|
1727
|
+
kind: 'anthropic.fallback',
|
|
1728
|
+
providerMetadata: {
|
|
1729
|
+
anthropic: {
|
|
1730
|
+
type: 'fallback',
|
|
1731
|
+
from: part.from,
|
|
1732
|
+
to: part.to,
|
|
1733
|
+
},
|
|
1734
|
+
},
|
|
1735
|
+
});
|
|
1728
1736
|
break;
|
|
1729
1737
|
}
|
|
1730
1738
|
}
|
|
@@ -1965,10 +1973,18 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
1965
1973
|
const part = value.content_block;
|
|
1966
1974
|
const contentBlockType = part.type;
|
|
1967
1975
|
|
|
1968
|
-
// Server-side fallback marker: the AI SDK has no content
|
|
1969
|
-
// primitive for a model hop, so drop it. The hop is still
|
|
1970
|
-
// observable via usage.iterations.
|
|
1971
1976
|
if (contentBlockType === 'fallback') {
|
|
1977
|
+
controller.enqueue({
|
|
1978
|
+
type: 'custom',
|
|
1979
|
+
kind: 'anthropic.fallback',
|
|
1980
|
+
providerMetadata: {
|
|
1981
|
+
anthropic: {
|
|
1982
|
+
type: 'fallback',
|
|
1983
|
+
from: part.from,
|
|
1984
|
+
to: part.to,
|
|
1985
|
+
},
|
|
1986
|
+
},
|
|
1987
|
+
});
|
|
1972
1988
|
return;
|
|
1973
1989
|
}
|
|
1974
1990
|
|
|
@@ -15,11 +15,13 @@ import {
|
|
|
15
15
|
parseProviderOptions,
|
|
16
16
|
resolveFullMediaType,
|
|
17
17
|
resolveProviderReference,
|
|
18
|
+
safeValidateTypes,
|
|
18
19
|
secureJsonParse,
|
|
19
20
|
validateTypes,
|
|
20
21
|
type ToolNameMapping,
|
|
21
22
|
} from '@ai-sdk/provider-utils';
|
|
22
23
|
import {
|
|
24
|
+
anthropicFallbackContentSchema,
|
|
23
25
|
anthropicReasoningMetadataSchema,
|
|
24
26
|
type AnthropicAssistantMessage,
|
|
25
27
|
type AnthropicPrompt,
|
|
@@ -824,6 +826,33 @@ export async function convertToAnthropicPrompt({
|
|
|
824
826
|
break;
|
|
825
827
|
}
|
|
826
828
|
|
|
829
|
+
case 'custom': {
|
|
830
|
+
if (part.kind !== 'anthropic.fallback') {
|
|
831
|
+
break;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
const fallbackMetadata = await safeValidateTypes({
|
|
835
|
+
value: part.providerOptions?.anthropic,
|
|
836
|
+
schema: anthropicFallbackContentSchema,
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
if (!fallbackMetadata.success) {
|
|
840
|
+
warnings.push({
|
|
841
|
+
type: 'other',
|
|
842
|
+
message:
|
|
843
|
+
'anthropic fallback metadata must include from.model and to.model',
|
|
844
|
+
});
|
|
845
|
+
break;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
anthropicContent.push({
|
|
849
|
+
type: 'fallback',
|
|
850
|
+
from: fallbackMetadata.value.from,
|
|
851
|
+
to: fallbackMetadata.value.to,
|
|
852
|
+
});
|
|
853
|
+
break;
|
|
854
|
+
}
|
|
855
|
+
|
|
827
856
|
case 'tool-call': {
|
|
828
857
|
const caller = getAnthropicCaller(part.providerOptions);
|
|
829
858
|
|
|
@@ -1571,7 +1600,11 @@ function moveToolUseBlocksToEnd(
|
|
|
1571
1600
|
}
|
|
1572
1601
|
|
|
1573
1602
|
for (const part of content) {
|
|
1574
|
-
if (
|
|
1603
|
+
if (
|
|
1604
|
+
part.type === 'thinking' ||
|
|
1605
|
+
part.type === 'redacted_thinking' ||
|
|
1606
|
+
part.type === 'fallback'
|
|
1607
|
+
) {
|
|
1575
1608
|
flushSegment();
|
|
1576
1609
|
result.push(part);
|
|
1577
1610
|
} else {
|