@ai-sdk/anthropic 2.0.61 → 2.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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 2.0.63
4
+
5
+ ### Patch Changes
6
+
7
+ - e551c84: fix(anthropic): map proper context management tools for anthropic
8
+
9
+ ## 2.0.62
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [20565b8]
14
+ - @ai-sdk/provider-utils@3.0.21
15
+
3
16
  ## 2.0.61
4
17
 
5
18
  ### 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
+ {
80
+ /**
81
+ * The type of context management edit applied.
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
88
+ */
89
+ clearedToolUses: number;
90
+ /**
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
+ | {
75
100
  /**
76
101
  * The type of context management edit applied.
77
- * Possible value: 'clear_01'
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
78
108
  */
79
- type: 'clear_01';
109
+ clearedThinkingTurns: number;
80
110
  /**
81
- * The number of input tokens that were cleared.
111
+ * Number of input tokens cleared by this edit.
112
+ * Minimum: 0
82
113
  */
83
114
  clearedInputTokens: number;
84
115
  }
@@ -133,11 +164,26 @@ declare const anthropicProviderOptions: z.ZodObject<{
133
164
  speed: z.ZodOptional<z.ZodLiteral<"fast">>;
134
165
  contextManagement: z.ZodOptional<z.ZodObject<{
135
166
  edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
136
- type: z.ZodLiteral<"clear_01">;
137
- trigger: z.ZodOptional<z.ZodObject<{
167
+ type: z.ZodLiteral<"clear_tool_uses_20250919">;
168
+ trigger: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
169
+ type: z.ZodLiteral<"input_tokens">;
170
+ value: z.ZodNumber;
171
+ }, z.core.$strip>, z.ZodObject<{
172
+ type: z.ZodLiteral<"tool_uses">;
173
+ value: z.ZodNumber;
174
+ }, z.core.$strip>]>>;
175
+ keep: z.ZodOptional<z.ZodObject<{
176
+ type: z.ZodLiteral<"tool_uses">;
177
+ value: z.ZodNumber;
178
+ }, z.core.$strip>>;
179
+ clearAtLeast: z.ZodOptional<z.ZodObject<{
138
180
  type: z.ZodLiteral<"input_tokens">;
139
181
  value: z.ZodNumber;
140
182
  }, z.core.$strip>>;
183
+ clearToolInputs: z.ZodOptional<z.ZodBoolean>;
184
+ excludeTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
185
+ }, z.core.$strip>, z.ZodObject<{
186
+ type: z.ZodLiteral<"clear_thinking_20251015">;
141
187
  keep: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodObject<{
142
188
  type: z.ZodLiteral<"thinking_turns">;
143
189
  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
+ {
80
+ /**
81
+ * The type of context management edit applied.
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
88
+ */
89
+ clearedToolUses: number;
90
+ /**
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
+ | {
75
100
  /**
76
101
  * The type of context management edit applied.
77
- * Possible value: 'clear_01'
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
78
108
  */
79
- type: 'clear_01';
109
+ clearedThinkingTurns: number;
80
110
  /**
81
- * The number of input tokens that were cleared.
111
+ * Number of input tokens cleared by this edit.
112
+ * Minimum: 0
82
113
  */
83
114
  clearedInputTokens: number;
84
115
  }
@@ -133,11 +164,26 @@ declare const anthropicProviderOptions: z.ZodObject<{
133
164
  speed: z.ZodOptional<z.ZodLiteral<"fast">>;
134
165
  contextManagement: z.ZodOptional<z.ZodObject<{
135
166
  edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
136
- type: z.ZodLiteral<"clear_01">;
137
- trigger: z.ZodOptional<z.ZodObject<{
167
+ type: z.ZodLiteral<"clear_tool_uses_20250919">;
168
+ trigger: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
169
+ type: z.ZodLiteral<"input_tokens">;
170
+ value: z.ZodNumber;
171
+ }, z.core.$strip>, z.ZodObject<{
172
+ type: z.ZodLiteral<"tool_uses">;
173
+ value: z.ZodNumber;
174
+ }, z.core.$strip>]>>;
175
+ keep: z.ZodOptional<z.ZodObject<{
176
+ type: z.ZodLiteral<"tool_uses">;
177
+ value: z.ZodNumber;
178
+ }, z.core.$strip>>;
179
+ clearAtLeast: z.ZodOptional<z.ZodObject<{
138
180
  type: z.ZodLiteral<"input_tokens">;
139
181
  value: z.ZodNumber;
140
182
  }, z.core.$strip>>;
183
+ clearToolInputs: z.ZodOptional<z.ZodBoolean>;
184
+ excludeTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
185
+ }, z.core.$strip>, z.ZodObject<{
186
+ type: z.ZodLiteral<"clear_thinking_20251015">;
141
187
  keep: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodObject<{
142
188
  type: z.ZodLiteral<"thinking_turns">;
143
189
  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.61" : "0.0.0-test";
34
+ var VERSION = true ? "2.0.63" : "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("clear_01"),
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("clear_01"),
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({
@@ -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("clear_01"),
697
- trigger: import_v43.z.object({
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 convertTrigger = (trigger) => trigger ? {
2038
- type: trigger.type,
2039
- value: trigger.value
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: convertTrigger(edit.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.keep !== void 0 && {
2049
- keep: edit.keep
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: convertTrigger(edit.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 edit type: ${edit.type}`
2108
+ message: `Unknown context management strategy: ${strategy}`
2069
2109
  });
2070
- return edit;
2110
+ return void 0;
2071
2111
  }
2072
- })
2112
+ }).filter((edit) => edit !== void 0)
2073
2113
  }
2074
2114
  },
2075
2115
  // prompt:
@@ -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
- switch (edit.type) {
2535
- case "clear_01":
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
- switch (edit.type) {
3034
- case "clear_01":
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 = {