@ai-sdk/anthropic 4.0.62 → 4.0.63
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/README.md +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +68 -13
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +6 -0
- package/dist/internal/index.js +54 -4
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +113 -31
- package/package.json +1 -1
- package/src/anthropic-api.ts +3 -0
- package/src/anthropic-batch.ts +6 -1
- package/src/anthropic-language-model-options.ts +13 -0
- package/src/anthropic-language-model.ts +44 -0
- package/src/convert-to-anthropic-prompt.ts +12 -1
package/dist/internal/index.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ interface AnthropicAssistantMessage {
|
|
|
57
57
|
interface AnthropicCompactionContent {
|
|
58
58
|
type: 'compaction';
|
|
59
59
|
content: string;
|
|
60
|
+
signature?: string;
|
|
60
61
|
cache_control?: AnthropicCacheControl;
|
|
61
62
|
}
|
|
62
63
|
interface AnthropicTextContent {
|
|
@@ -525,6 +526,7 @@ declare const anthropicResponseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
525
526
|
} | {
|
|
526
527
|
type: "compaction";
|
|
527
528
|
content?: string | null | undefined;
|
|
529
|
+
signature?: string | null | undefined;
|
|
528
530
|
} | {
|
|
529
531
|
type: "tool_use";
|
|
530
532
|
id: string;
|
|
@@ -876,6 +878,10 @@ declare class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
876
878
|
type: "compact_20260112";
|
|
877
879
|
})[];
|
|
878
880
|
} | undefined;
|
|
881
|
+
compaction?: {
|
|
882
|
+
instructions?: string | undefined;
|
|
883
|
+
type: "summarize";
|
|
884
|
+
} | undefined;
|
|
879
885
|
safeguards?: {
|
|
880
886
|
classifier_context?: Record<string, unknown> | undefined;
|
|
881
887
|
type: "dangerous_tool_use";
|
package/dist/internal/index.js
CHANGED
|
@@ -106,6 +106,7 @@ var AnthropicFiles = class {
|
|
|
106
106
|
// src/anthropic-language-model.ts
|
|
107
107
|
import {
|
|
108
108
|
APICallError,
|
|
109
|
+
InvalidArgumentError,
|
|
109
110
|
InvalidResponseDataError
|
|
110
111
|
} from "@ai-sdk/provider";
|
|
111
112
|
import {
|
|
@@ -257,7 +258,8 @@ var anthropicResponseSchema = lazySchema3(
|
|
|
257
258
|
}),
|
|
258
259
|
z3.object({
|
|
259
260
|
type: z3.literal("compaction"),
|
|
260
|
-
content: z3.string().nullish()
|
|
261
|
+
content: z3.string().nullish(),
|
|
262
|
+
signature: z3.string().nullish()
|
|
261
263
|
}),
|
|
262
264
|
z3.object({
|
|
263
265
|
type: z3.literal("tool_use"),
|
|
@@ -612,7 +614,8 @@ var anthropicChunkSchema = lazySchema3(
|
|
|
612
614
|
}),
|
|
613
615
|
z3.object({
|
|
614
616
|
type: z3.literal("compaction"),
|
|
615
|
-
content: z3.string().nullish()
|
|
617
|
+
content: z3.string().nullish(),
|
|
618
|
+
signature: z3.string().nullish()
|
|
616
619
|
}),
|
|
617
620
|
z3.object({
|
|
618
621
|
type: z3.literal("server_tool_use"),
|
|
@@ -1251,6 +1254,16 @@ var anthropicLanguageModelOptions = z4.object({
|
|
|
1251
1254
|
classifierContext: z4.record(z4.string(), z4.unknown()).optional()
|
|
1252
1255
|
})
|
|
1253
1256
|
).optional(),
|
|
1257
|
+
/**
|
|
1258
|
+
* Requests an on-demand summary of the supplied conversation.
|
|
1259
|
+
*
|
|
1260
|
+
* The required `compact-2026-09-04` beta is added automatically.
|
|
1261
|
+
* Cannot be combined with `contextManagement`.
|
|
1262
|
+
*/
|
|
1263
|
+
compaction: z4.object({
|
|
1264
|
+
type: z4.literal("summarize"),
|
|
1265
|
+
instructions: z4.string().optional()
|
|
1266
|
+
}).optional(),
|
|
1254
1267
|
contextManagement: z4.object({
|
|
1255
1268
|
edits: z4.array(
|
|
1256
1269
|
z4.discriminatedUnion("type", [
|
|
@@ -3231,9 +3244,15 @@ async function convertToAnthropicPrompt({
|
|
|
3231
3244
|
if (part.text === "") {
|
|
3232
3245
|
break;
|
|
3233
3246
|
}
|
|
3247
|
+
if (typeof textMetadata.signature === "string") {
|
|
3248
|
+
betas.add("compact-2026-09-04");
|
|
3249
|
+
}
|
|
3234
3250
|
anthropicContent.push({
|
|
3235
3251
|
type: "compaction",
|
|
3236
3252
|
content: part.text,
|
|
3253
|
+
...typeof textMetadata.signature === "string" && {
|
|
3254
|
+
signature: textMetadata.signature
|
|
3255
|
+
},
|
|
3237
3256
|
cache_control: cacheControl
|
|
3238
3257
|
});
|
|
3239
3258
|
} else {
|
|
@@ -4323,6 +4342,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4323
4342
|
});
|
|
4324
4343
|
}
|
|
4325
4344
|
const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
|
|
4345
|
+
const compaction = anthropicOptions == null ? void 0 : anthropicOptions.compaction;
|
|
4346
|
+
if (contextManagement != null && compaction != null) {
|
|
4347
|
+
throw new InvalidArgumentError({
|
|
4348
|
+
argument: "providerOptions",
|
|
4349
|
+
message: "Anthropic provider options `compaction` and `contextManagement` cannot be used together."
|
|
4350
|
+
});
|
|
4351
|
+
}
|
|
4326
4352
|
const cacheControlValidator = new CacheControlValidator();
|
|
4327
4353
|
const toolNameMapping = createToolNameMapping({
|
|
4328
4354
|
tools,
|
|
@@ -4519,6 +4545,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4519
4545
|
}
|
|
4520
4546
|
}))
|
|
4521
4547
|
},
|
|
4548
|
+
...compaction && {
|
|
4549
|
+
compaction: {
|
|
4550
|
+
type: compaction.type,
|
|
4551
|
+
...compaction.instructions !== void 0 && {
|
|
4552
|
+
instructions: compaction.instructions
|
|
4553
|
+
}
|
|
4554
|
+
}
|
|
4555
|
+
},
|
|
4522
4556
|
...contextManagement && {
|
|
4523
4557
|
context_management: {
|
|
4524
4558
|
edits: contextManagement.edits.map((edit) => {
|
|
@@ -4634,6 +4668,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4634
4668
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0) {
|
|
4635
4669
|
betas.add("dangerous-tool-use-2026-09-03");
|
|
4636
4670
|
}
|
|
4671
|
+
if (compaction) {
|
|
4672
|
+
betas.add("compact-2026-09-04");
|
|
4673
|
+
}
|
|
4637
4674
|
if (contextManagement) {
|
|
4638
4675
|
betas.add("context-management-2025-06-27");
|
|
4639
4676
|
if (contextManagement.edits.some((e) => e.type === "compact_20260112")) {
|
|
@@ -4891,7 +4928,10 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4891
4928
|
text: part.content,
|
|
4892
4929
|
providerMetadata: {
|
|
4893
4930
|
anthropic: {
|
|
4894
|
-
type: "compaction"
|
|
4931
|
+
type: "compaction",
|
|
4932
|
+
...part.signature != null && {
|
|
4933
|
+
signature: part.signature
|
|
4934
|
+
}
|
|
4895
4935
|
}
|
|
4896
4936
|
}
|
|
4897
4937
|
});
|
|
@@ -5448,10 +5488,20 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5448
5488
|
id: String(value.index),
|
|
5449
5489
|
providerMetadata: {
|
|
5450
5490
|
anthropic: {
|
|
5451
|
-
type: "compaction"
|
|
5491
|
+
type: "compaction",
|
|
5492
|
+
...part.signature != null && {
|
|
5493
|
+
signature: part.signature
|
|
5494
|
+
}
|
|
5452
5495
|
}
|
|
5453
5496
|
}
|
|
5454
5497
|
});
|
|
5498
|
+
if (part.signature != null && part.content != null && part.content !== "") {
|
|
5499
|
+
controller.enqueue({
|
|
5500
|
+
type: "text-delta",
|
|
5501
|
+
id: String(value.index),
|
|
5502
|
+
delta: part.content
|
|
5503
|
+
});
|
|
5504
|
+
}
|
|
5455
5505
|
return;
|
|
5456
5506
|
}
|
|
5457
5507
|
case "tool_use": {
|