@ai-sdk/anthropic 2.0.62 → 2.0.64
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 +56 -7
- package/dist/index.d.ts +56 -7
- package/dist/index.js +82 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +82 -26
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +81 -25
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +81 -25
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 2.0.64
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9d5c1b1: fix(provider/anthropic): minor follow up to support no-op speed standard
|
|
8
|
+
|
|
9
|
+
## 2.0.63
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- e551c84: fix(anthropic): map proper context management tools for anthropic
|
|
14
|
+
|
|
3
15
|
## 2.0.62
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -70,15 +70,46 @@ interface AnthropicMessageMetadata {
|
|
|
70
70
|
contextManagement: {
|
|
71
71
|
/**
|
|
72
72
|
* List of context management edits that were applied.
|
|
73
|
+
* Each item in the array is a specific type of context management edit.
|
|
73
74
|
*/
|
|
74
|
-
appliedEdits: Array<
|
|
75
|
+
appliedEdits: Array<
|
|
76
|
+
/**
|
|
77
|
+
* Represents an edit where a certain number of tool uses and input tokens were cleared.
|
|
78
|
+
*/
|
|
79
|
+
{
|
|
75
80
|
/**
|
|
76
81
|
* The type of context management edit applied.
|
|
77
|
-
* Possible value: '
|
|
82
|
+
* Possible value: 'clear_tool_uses_20250919'
|
|
83
|
+
*/
|
|
84
|
+
type: 'clear_tool_uses_20250919';
|
|
85
|
+
/**
|
|
86
|
+
* Number of tool uses that were cleared by this edit.
|
|
87
|
+
* Minimum: 0
|
|
78
88
|
*/
|
|
79
|
-
|
|
89
|
+
clearedToolUses: number;
|
|
80
90
|
/**
|
|
81
|
-
*
|
|
91
|
+
* Number of input tokens cleared by this edit.
|
|
92
|
+
* Minimum: 0
|
|
93
|
+
*/
|
|
94
|
+
clearedInputTokens: number;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Represents an edit where a certain number of thinking turns and input tokens were cleared.
|
|
98
|
+
*/
|
|
99
|
+
| {
|
|
100
|
+
/**
|
|
101
|
+
* The type of context management edit applied.
|
|
102
|
+
* Possible value: 'clear_thinking_20251015'
|
|
103
|
+
*/
|
|
104
|
+
type: 'clear_thinking_20251015';
|
|
105
|
+
/**
|
|
106
|
+
* Number of thinking turns that were cleared by this edit.
|
|
107
|
+
* Minimum: 0
|
|
108
|
+
*/
|
|
109
|
+
clearedThinkingTurns: number;
|
|
110
|
+
/**
|
|
111
|
+
* Number of input tokens cleared by this edit.
|
|
112
|
+
* Minimum: 0
|
|
82
113
|
*/
|
|
83
114
|
clearedInputTokens: number;
|
|
84
115
|
}
|
|
@@ -130,14 +161,32 @@ declare const anthropicProviderOptions: z.ZodObject<{
|
|
|
130
161
|
high: "high";
|
|
131
162
|
max: "max";
|
|
132
163
|
}>>;
|
|
133
|
-
speed: z.ZodOptional<z.
|
|
164
|
+
speed: z.ZodOptional<z.ZodEnum<{
|
|
165
|
+
fast: "fast";
|
|
166
|
+
standard: "standard";
|
|
167
|
+
}>>;
|
|
134
168
|
contextManagement: z.ZodOptional<z.ZodObject<{
|
|
135
169
|
edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
136
|
-
type: z.ZodLiteral<"
|
|
137
|
-
trigger: z.ZodOptional<z.ZodObject<{
|
|
170
|
+
type: z.ZodLiteral<"clear_tool_uses_20250919">;
|
|
171
|
+
trigger: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
172
|
+
type: z.ZodLiteral<"input_tokens">;
|
|
173
|
+
value: z.ZodNumber;
|
|
174
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
175
|
+
type: z.ZodLiteral<"tool_uses">;
|
|
176
|
+
value: z.ZodNumber;
|
|
177
|
+
}, z.core.$strip>]>>;
|
|
178
|
+
keep: z.ZodOptional<z.ZodObject<{
|
|
179
|
+
type: z.ZodLiteral<"tool_uses">;
|
|
180
|
+
value: z.ZodNumber;
|
|
181
|
+
}, z.core.$strip>>;
|
|
182
|
+
clearAtLeast: z.ZodOptional<z.ZodObject<{
|
|
138
183
|
type: z.ZodLiteral<"input_tokens">;
|
|
139
184
|
value: z.ZodNumber;
|
|
140
185
|
}, z.core.$strip>>;
|
|
186
|
+
clearToolInputs: z.ZodOptional<z.ZodBoolean>;
|
|
187
|
+
excludeTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
188
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
189
|
+
type: z.ZodLiteral<"clear_thinking_20251015">;
|
|
141
190
|
keep: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodObject<{
|
|
142
191
|
type: z.ZodLiteral<"thinking_turns">;
|
|
143
192
|
value: z.ZodNumber;
|
package/dist/index.d.ts
CHANGED
|
@@ -70,15 +70,46 @@ interface AnthropicMessageMetadata {
|
|
|
70
70
|
contextManagement: {
|
|
71
71
|
/**
|
|
72
72
|
* List of context management edits that were applied.
|
|
73
|
+
* Each item in the array is a specific type of context management edit.
|
|
73
74
|
*/
|
|
74
|
-
appliedEdits: Array<
|
|
75
|
+
appliedEdits: Array<
|
|
76
|
+
/**
|
|
77
|
+
* Represents an edit where a certain number of tool uses and input tokens were cleared.
|
|
78
|
+
*/
|
|
79
|
+
{
|
|
75
80
|
/**
|
|
76
81
|
* The type of context management edit applied.
|
|
77
|
-
* Possible value: '
|
|
82
|
+
* Possible value: 'clear_tool_uses_20250919'
|
|
83
|
+
*/
|
|
84
|
+
type: 'clear_tool_uses_20250919';
|
|
85
|
+
/**
|
|
86
|
+
* Number of tool uses that were cleared by this edit.
|
|
87
|
+
* Minimum: 0
|
|
78
88
|
*/
|
|
79
|
-
|
|
89
|
+
clearedToolUses: number;
|
|
80
90
|
/**
|
|
81
|
-
*
|
|
91
|
+
* Number of input tokens cleared by this edit.
|
|
92
|
+
* Minimum: 0
|
|
93
|
+
*/
|
|
94
|
+
clearedInputTokens: number;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Represents an edit where a certain number of thinking turns and input tokens were cleared.
|
|
98
|
+
*/
|
|
99
|
+
| {
|
|
100
|
+
/**
|
|
101
|
+
* The type of context management edit applied.
|
|
102
|
+
* Possible value: 'clear_thinking_20251015'
|
|
103
|
+
*/
|
|
104
|
+
type: 'clear_thinking_20251015';
|
|
105
|
+
/**
|
|
106
|
+
* Number of thinking turns that were cleared by this edit.
|
|
107
|
+
* Minimum: 0
|
|
108
|
+
*/
|
|
109
|
+
clearedThinkingTurns: number;
|
|
110
|
+
/**
|
|
111
|
+
* Number of input tokens cleared by this edit.
|
|
112
|
+
* Minimum: 0
|
|
82
113
|
*/
|
|
83
114
|
clearedInputTokens: number;
|
|
84
115
|
}
|
|
@@ -130,14 +161,32 @@ declare const anthropicProviderOptions: z.ZodObject<{
|
|
|
130
161
|
high: "high";
|
|
131
162
|
max: "max";
|
|
132
163
|
}>>;
|
|
133
|
-
speed: z.ZodOptional<z.
|
|
164
|
+
speed: z.ZodOptional<z.ZodEnum<{
|
|
165
|
+
fast: "fast";
|
|
166
|
+
standard: "standard";
|
|
167
|
+
}>>;
|
|
134
168
|
contextManagement: z.ZodOptional<z.ZodObject<{
|
|
135
169
|
edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
136
|
-
type: z.ZodLiteral<"
|
|
137
|
-
trigger: z.ZodOptional<z.ZodObject<{
|
|
170
|
+
type: z.ZodLiteral<"clear_tool_uses_20250919">;
|
|
171
|
+
trigger: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
172
|
+
type: z.ZodLiteral<"input_tokens">;
|
|
173
|
+
value: z.ZodNumber;
|
|
174
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
175
|
+
type: z.ZodLiteral<"tool_uses">;
|
|
176
|
+
value: z.ZodNumber;
|
|
177
|
+
}, z.core.$strip>]>>;
|
|
178
|
+
keep: z.ZodOptional<z.ZodObject<{
|
|
179
|
+
type: z.ZodLiteral<"tool_uses">;
|
|
180
|
+
value: z.ZodNumber;
|
|
181
|
+
}, z.core.$strip>>;
|
|
182
|
+
clearAtLeast: z.ZodOptional<z.ZodObject<{
|
|
138
183
|
type: z.ZodLiteral<"input_tokens">;
|
|
139
184
|
value: z.ZodNumber;
|
|
140
185
|
}, z.core.$strip>>;
|
|
186
|
+
clearToolInputs: z.ZodOptional<z.ZodBoolean>;
|
|
187
|
+
excludeTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
188
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
189
|
+
type: z.ZodLiteral<"clear_thinking_20251015">;
|
|
141
190
|
keep: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodObject<{
|
|
142
191
|
type: z.ZodLiteral<"thinking_turns">;
|
|
143
192
|
value: z.ZodNumber;
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
31
31
|
var import_provider_utils20 = require("@ai-sdk/provider-utils");
|
|
32
32
|
|
|
33
33
|
// src/version.ts
|
|
34
|
-
var VERSION = true ? "2.0.
|
|
34
|
+
var VERSION = true ? "2.0.64" : "0.0.0-test";
|
|
35
35
|
|
|
36
36
|
// src/anthropic-messages-language-model.ts
|
|
37
37
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -268,7 +268,13 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
268
268
|
applied_edits: import_v42.z.array(
|
|
269
269
|
import_v42.z.union([
|
|
270
270
|
import_v42.z.object({
|
|
271
|
-
type: import_v42.z.literal("
|
|
271
|
+
type: import_v42.z.literal("clear_tool_uses_20250919"),
|
|
272
|
+
cleared_tool_uses: import_v42.z.number(),
|
|
273
|
+
cleared_input_tokens: import_v42.z.number()
|
|
274
|
+
}),
|
|
275
|
+
import_v42.z.object({
|
|
276
|
+
type: import_v42.z.literal("clear_thinking_20251015"),
|
|
277
|
+
cleared_thinking_turns: import_v42.z.number(),
|
|
272
278
|
cleared_input_tokens: import_v42.z.number()
|
|
273
279
|
}),
|
|
274
280
|
import_v42.z.object({
|
|
@@ -565,7 +571,13 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
565
571
|
applied_edits: import_v42.z.array(
|
|
566
572
|
import_v42.z.union([
|
|
567
573
|
import_v42.z.object({
|
|
568
|
-
type: import_v42.z.literal("
|
|
574
|
+
type: import_v42.z.literal("clear_tool_uses_20250919"),
|
|
575
|
+
cleared_tool_uses: import_v42.z.number(),
|
|
576
|
+
cleared_input_tokens: import_v42.z.number()
|
|
577
|
+
}),
|
|
578
|
+
import_v42.z.object({
|
|
579
|
+
type: import_v42.z.literal("clear_thinking_20251015"),
|
|
580
|
+
cleared_thinking_turns: import_v42.z.number(),
|
|
569
581
|
cleared_input_tokens: import_v42.z.number()
|
|
570
582
|
}),
|
|
571
583
|
import_v42.z.object({
|
|
@@ -684,7 +696,7 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
684
696
|
* Enable fast mode for faster inference (2.5x faster output token speeds).
|
|
685
697
|
* Only supported with claude-opus-4-6.
|
|
686
698
|
*/
|
|
687
|
-
speed: import_v43.z.
|
|
699
|
+
speed: import_v43.z.enum(["fast", "standard"]).optional(),
|
|
688
700
|
/**
|
|
689
701
|
* Context management configuration for automatic context window management.
|
|
690
702
|
* Enables features like automatic compaction and clearing of tool uses/thinking blocks.
|
|
@@ -693,11 +705,30 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
693
705
|
edits: import_v43.z.array(
|
|
694
706
|
import_v43.z.discriminatedUnion("type", [
|
|
695
707
|
import_v43.z.object({
|
|
696
|
-
type: import_v43.z.literal("
|
|
697
|
-
trigger: import_v43.z.
|
|
708
|
+
type: import_v43.z.literal("clear_tool_uses_20250919"),
|
|
709
|
+
trigger: import_v43.z.discriminatedUnion("type", [
|
|
710
|
+
import_v43.z.object({
|
|
711
|
+
type: import_v43.z.literal("input_tokens"),
|
|
712
|
+
value: import_v43.z.number()
|
|
713
|
+
}),
|
|
714
|
+
import_v43.z.object({
|
|
715
|
+
type: import_v43.z.literal("tool_uses"),
|
|
716
|
+
value: import_v43.z.number()
|
|
717
|
+
})
|
|
718
|
+
]).optional(),
|
|
719
|
+
keep: import_v43.z.object({
|
|
720
|
+
type: import_v43.z.literal("tool_uses"),
|
|
721
|
+
value: import_v43.z.number()
|
|
722
|
+
}).optional(),
|
|
723
|
+
clearAtLeast: import_v43.z.object({
|
|
698
724
|
type: import_v43.z.literal("input_tokens"),
|
|
699
725
|
value: import_v43.z.number()
|
|
700
726
|
}).optional(),
|
|
727
|
+
clearToolInputs: import_v43.z.boolean().optional(),
|
|
728
|
+
excludeTools: import_v43.z.array(import_v43.z.string()).optional()
|
|
729
|
+
}),
|
|
730
|
+
import_v43.z.object({
|
|
731
|
+
type: import_v43.z.literal("clear_thinking_20251015"),
|
|
701
732
|
keep: import_v43.z.union([
|
|
702
733
|
import_v43.z.literal("all"),
|
|
703
734
|
import_v43.z.object({
|
|
@@ -2034,26 +2065,35 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2034
2065
|
...(anthropicOptions == null ? void 0 : anthropicOptions.contextManagement) && {
|
|
2035
2066
|
context_management: {
|
|
2036
2067
|
edits: anthropicOptions.contextManagement.edits.map((edit) => {
|
|
2037
|
-
const
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
} : void 0;
|
|
2041
|
-
switch (edit.type) {
|
|
2042
|
-
case "clear_01":
|
|
2068
|
+
const strategy = edit.type;
|
|
2069
|
+
switch (strategy) {
|
|
2070
|
+
case "clear_tool_uses_20250919":
|
|
2043
2071
|
return {
|
|
2044
2072
|
type: edit.type,
|
|
2045
2073
|
...edit.trigger !== void 0 && {
|
|
2046
|
-
trigger:
|
|
2074
|
+
trigger: edit.trigger
|
|
2075
|
+
},
|
|
2076
|
+
...edit.keep !== void 0 && { keep: edit.keep },
|
|
2077
|
+
...edit.clearAtLeast !== void 0 && {
|
|
2078
|
+
clear_at_least: edit.clearAtLeast
|
|
2047
2079
|
},
|
|
2048
|
-
...edit.
|
|
2049
|
-
|
|
2080
|
+
...edit.clearToolInputs !== void 0 && {
|
|
2081
|
+
clear_tool_inputs: edit.clearToolInputs
|
|
2082
|
+
},
|
|
2083
|
+
...edit.excludeTools !== void 0 && {
|
|
2084
|
+
exclude_tools: edit.excludeTools
|
|
2050
2085
|
}
|
|
2051
2086
|
};
|
|
2087
|
+
case "clear_thinking_20251015":
|
|
2088
|
+
return {
|
|
2089
|
+
type: edit.type,
|
|
2090
|
+
...edit.keep !== void 0 && { keep: edit.keep }
|
|
2091
|
+
};
|
|
2052
2092
|
case "compact_20260112":
|
|
2053
2093
|
return {
|
|
2054
2094
|
type: edit.type,
|
|
2055
2095
|
...edit.trigger !== void 0 && {
|
|
2056
|
-
trigger:
|
|
2096
|
+
trigger: edit.trigger
|
|
2057
2097
|
},
|
|
2058
2098
|
...edit.pauseAfterCompaction !== void 0 && {
|
|
2059
2099
|
pause_after_compaction: edit.pauseAfterCompaction
|
|
@@ -2065,11 +2105,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2065
2105
|
default:
|
|
2066
2106
|
warnings.push({
|
|
2067
2107
|
type: "other",
|
|
2068
|
-
message: `Unknown context management
|
|
2108
|
+
message: `Unknown context management strategy: ${strategy}`
|
|
2069
2109
|
});
|
|
2070
|
-
return
|
|
2110
|
+
return void 0;
|
|
2071
2111
|
}
|
|
2072
|
-
})
|
|
2112
|
+
}).filter((edit) => edit !== void 0)
|
|
2073
2113
|
}
|
|
2074
2114
|
},
|
|
2075
2115
|
// prompt:
|
|
@@ -2134,7 +2174,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2134
2174
|
if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
|
|
2135
2175
|
betas.add("effort-2025-11-24");
|
|
2136
2176
|
}
|
|
2137
|
-
if (anthropicOptions == null ? void 0 : anthropicOptions.speed) {
|
|
2177
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
|
|
2138
2178
|
betas.add("fast-mode-2026-02-01");
|
|
2139
2179
|
}
|
|
2140
2180
|
if (useStructuredOutput) {
|
|
@@ -2531,10 +2571,18 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2531
2571
|
contextManagement: response.context_management ? {
|
|
2532
2572
|
appliedEdits: response.context_management.applied_edits.map(
|
|
2533
2573
|
(edit) => {
|
|
2534
|
-
|
|
2535
|
-
|
|
2574
|
+
const strategy = edit.type;
|
|
2575
|
+
switch (strategy) {
|
|
2576
|
+
case "clear_tool_uses_20250919":
|
|
2536
2577
|
return {
|
|
2537
2578
|
type: edit.type,
|
|
2579
|
+
clearedToolUses: edit.cleared_tool_uses,
|
|
2580
|
+
clearedInputTokens: edit.cleared_input_tokens
|
|
2581
|
+
};
|
|
2582
|
+
case "clear_thinking_20251015":
|
|
2583
|
+
return {
|
|
2584
|
+
type: edit.type,
|
|
2585
|
+
clearedThinkingTurns: edit.cleared_thinking_turns,
|
|
2538
2586
|
clearedInputTokens: edit.cleared_input_tokens
|
|
2539
2587
|
};
|
|
2540
2588
|
case "compact_20260112":
|
|
@@ -2543,7 +2591,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2543
2591
|
};
|
|
2544
2592
|
}
|
|
2545
2593
|
}
|
|
2546
|
-
)
|
|
2594
|
+
).filter((edit) => edit !== void 0)
|
|
2547
2595
|
} : null
|
|
2548
2596
|
}
|
|
2549
2597
|
}
|
|
@@ -3030,10 +3078,18 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3030
3078
|
contextManagement = {
|
|
3031
3079
|
appliedEdits: value.context_management.applied_edits.map(
|
|
3032
3080
|
(edit) => {
|
|
3033
|
-
|
|
3034
|
-
|
|
3081
|
+
const strategy = edit.type;
|
|
3082
|
+
switch (strategy) {
|
|
3083
|
+
case "clear_tool_uses_20250919":
|
|
3084
|
+
return {
|
|
3085
|
+
type: edit.type,
|
|
3086
|
+
clearedToolUses: edit.cleared_tool_uses,
|
|
3087
|
+
clearedInputTokens: edit.cleared_input_tokens
|
|
3088
|
+
};
|
|
3089
|
+
case "clear_thinking_20251015":
|
|
3035
3090
|
return {
|
|
3036
3091
|
type: edit.type,
|
|
3092
|
+
clearedThinkingTurns: edit.cleared_thinking_turns,
|
|
3037
3093
|
clearedInputTokens: edit.cleared_input_tokens
|
|
3038
3094
|
};
|
|
3039
3095
|
case "compact_20260112":
|
|
@@ -3042,7 +3098,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3042
3098
|
};
|
|
3043
3099
|
}
|
|
3044
3100
|
}
|
|
3045
|
-
)
|
|
3101
|
+
).filter((edit) => edit !== void 0)
|
|
3046
3102
|
};
|
|
3047
3103
|
}
|
|
3048
3104
|
rawUsage = {
|