@ai-sdk/anthropic 3.0.40 → 3.0.42

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,17 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 3.0.42
4
+
5
+ ### Patch Changes
6
+
7
+ - 99fbed8: feat: normalize provider specific model options type names and ensure they are exported
8
+
9
+ ## 3.0.41
10
+
11
+ ### Patch Changes
12
+
13
+ - c60b393: feat(anthropic): add the new compaction feature
14
+
3
15
  ## 3.0.40
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -3,10 +3,34 @@ import { z } from 'zod/v4';
3
3
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
4
4
  import { FetchFunction } from '@ai-sdk/provider-utils';
5
5
 
6
+ /**
7
+ * Represents a single iteration in the usage breakdown.
8
+ * When compaction occurs, the API returns an iterations array showing
9
+ * usage for each sampling iteration (compaction + message).
10
+ */
11
+ interface AnthropicUsageIteration {
12
+ type: 'compaction' | 'message';
13
+ /**
14
+ * Number of input tokens consumed in this iteration.
15
+ */
16
+ inputTokens: number;
17
+ /**
18
+ * Number of output tokens generated in this iteration.
19
+ */
20
+ outputTokens: number;
21
+ }
6
22
  interface AnthropicMessageMetadata {
7
23
  usage: JSONObject;
8
24
  cacheCreationInputTokens: number | null;
9
25
  stopSequence: string | null;
26
+ /**
27
+ * Usage breakdown by iteration when compaction is triggered.
28
+ *
29
+ * When compaction occurs, this array contains usage for each sampling iteration.
30
+ * The first iteration is typically the compaction step, followed by the main
31
+ * message iteration.
32
+ */
33
+ iterations: AnthropicUsageIteration[] | null;
10
34
  /**
11
35
  * Information about the container used in this request.
12
36
  *
@@ -90,12 +114,22 @@ interface AnthropicMessageMetadata {
90
114
  * Minimum: 0
91
115
  */
92
116
  clearedInputTokens: number;
117
+ }
118
+ /**
119
+ * Represents a compaction edit where the conversation context was summarized.
120
+ */
121
+ | {
122
+ /**
123
+ * The type of context management edit applied.
124
+ * Possible value: 'compact_20260112'
125
+ */
126
+ type: 'compact_20260112';
93
127
  }>;
94
128
  } | null;
95
129
  }
96
130
 
97
131
  type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-opus-4-6' | (string & {});
98
- declare const anthropicProviderOptions: z.ZodObject<{
132
+ declare const anthropicLanguageModelOptions: z.ZodObject<{
99
133
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
100
134
  structuredOutputMode: z.ZodOptional<z.ZodEnum<{
101
135
  outputFormat: "outputFormat";
@@ -167,10 +201,18 @@ declare const anthropicProviderOptions: z.ZodObject<{
167
201
  type: z.ZodLiteral<"thinking_turns">;
168
202
  value: z.ZodNumber;
169
203
  }, z.core.$strip>]>>;
204
+ }, z.core.$strip>, z.ZodObject<{
205
+ type: z.ZodLiteral<"compact_20260112">;
206
+ trigger: z.ZodOptional<z.ZodObject<{
207
+ type: z.ZodLiteral<"input_tokens">;
208
+ value: z.ZodNumber;
209
+ }, z.core.$strip>>;
210
+ pauseAfterCompaction: z.ZodOptional<z.ZodBoolean>;
211
+ instructions: z.ZodOptional<z.ZodString>;
170
212
  }, z.core.$strip>]>>;
171
213
  }, z.core.$strip>>;
172
214
  }, z.core.$strip>;
173
- type AnthropicProviderOptions = z.infer<typeof anthropicProviderOptions>;
215
+ type AnthropicLanguageModelOptions = z.infer<typeof anthropicLanguageModelOptions>;
174
216
 
175
217
  interface AnthropicToolOptions {
176
218
  deferLoading?: boolean;
@@ -787,4 +829,4 @@ declare function forwardAnthropicContainerIdFromLastStep({ steps, }: {
787
829
 
788
830
  declare const VERSION: string;
789
831
 
790
- export { type AnthropicMessageMetadata, type AnthropicProvider, type AnthropicProviderOptions, type AnthropicProviderSettings, type AnthropicToolOptions, VERSION, anthropic, createAnthropic, forwardAnthropicContainerIdFromLastStep };
832
+ export { type AnthropicLanguageModelOptions, type AnthropicMessageMetadata, type AnthropicProvider, type AnthropicLanguageModelOptions as AnthropicProviderOptions, type AnthropicProviderSettings, type AnthropicToolOptions, type AnthropicUsageIteration, VERSION, anthropic, createAnthropic, forwardAnthropicContainerIdFromLastStep };
package/dist/index.d.ts CHANGED
@@ -3,10 +3,34 @@ import { z } from 'zod/v4';
3
3
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
4
4
  import { FetchFunction } from '@ai-sdk/provider-utils';
5
5
 
6
+ /**
7
+ * Represents a single iteration in the usage breakdown.
8
+ * When compaction occurs, the API returns an iterations array showing
9
+ * usage for each sampling iteration (compaction + message).
10
+ */
11
+ interface AnthropicUsageIteration {
12
+ type: 'compaction' | 'message';
13
+ /**
14
+ * Number of input tokens consumed in this iteration.
15
+ */
16
+ inputTokens: number;
17
+ /**
18
+ * Number of output tokens generated in this iteration.
19
+ */
20
+ outputTokens: number;
21
+ }
6
22
  interface AnthropicMessageMetadata {
7
23
  usage: JSONObject;
8
24
  cacheCreationInputTokens: number | null;
9
25
  stopSequence: string | null;
26
+ /**
27
+ * Usage breakdown by iteration when compaction is triggered.
28
+ *
29
+ * When compaction occurs, this array contains usage for each sampling iteration.
30
+ * The first iteration is typically the compaction step, followed by the main
31
+ * message iteration.
32
+ */
33
+ iterations: AnthropicUsageIteration[] | null;
10
34
  /**
11
35
  * Information about the container used in this request.
12
36
  *
@@ -90,12 +114,22 @@ interface AnthropicMessageMetadata {
90
114
  * Minimum: 0
91
115
  */
92
116
  clearedInputTokens: number;
117
+ }
118
+ /**
119
+ * Represents a compaction edit where the conversation context was summarized.
120
+ */
121
+ | {
122
+ /**
123
+ * The type of context management edit applied.
124
+ * Possible value: 'compact_20260112'
125
+ */
126
+ type: 'compact_20260112';
93
127
  }>;
94
128
  } | null;
95
129
  }
96
130
 
97
131
  type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-opus-4-6' | (string & {});
98
- declare const anthropicProviderOptions: z.ZodObject<{
132
+ declare const anthropicLanguageModelOptions: z.ZodObject<{
99
133
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
100
134
  structuredOutputMode: z.ZodOptional<z.ZodEnum<{
101
135
  outputFormat: "outputFormat";
@@ -167,10 +201,18 @@ declare const anthropicProviderOptions: z.ZodObject<{
167
201
  type: z.ZodLiteral<"thinking_turns">;
168
202
  value: z.ZodNumber;
169
203
  }, z.core.$strip>]>>;
204
+ }, z.core.$strip>, z.ZodObject<{
205
+ type: z.ZodLiteral<"compact_20260112">;
206
+ trigger: z.ZodOptional<z.ZodObject<{
207
+ type: z.ZodLiteral<"input_tokens">;
208
+ value: z.ZodNumber;
209
+ }, z.core.$strip>>;
210
+ pauseAfterCompaction: z.ZodOptional<z.ZodBoolean>;
211
+ instructions: z.ZodOptional<z.ZodString>;
170
212
  }, z.core.$strip>]>>;
171
213
  }, z.core.$strip>>;
172
214
  }, z.core.$strip>;
173
- type AnthropicProviderOptions = z.infer<typeof anthropicProviderOptions>;
215
+ type AnthropicLanguageModelOptions = z.infer<typeof anthropicLanguageModelOptions>;
174
216
 
175
217
  interface AnthropicToolOptions {
176
218
  deferLoading?: boolean;
@@ -787,4 +829,4 @@ declare function forwardAnthropicContainerIdFromLastStep({ steps, }: {
787
829
 
788
830
  declare const VERSION: string;
789
831
 
790
- export { type AnthropicMessageMetadata, type AnthropicProvider, type AnthropicProviderOptions, type AnthropicProviderSettings, type AnthropicToolOptions, VERSION, anthropic, createAnthropic, forwardAnthropicContainerIdFromLastStep };
832
+ export { type AnthropicLanguageModelOptions, type AnthropicMessageMetadata, type AnthropicProvider, type AnthropicLanguageModelOptions as AnthropicProviderOptions, type AnthropicProviderSettings, type AnthropicToolOptions, type AnthropicUsageIteration, VERSION, anthropic, createAnthropic, forwardAnthropicContainerIdFromLastStep };
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
32
32
  var import_provider_utils23 = require("@ai-sdk/provider-utils");
33
33
 
34
34
  // src/version.ts
35
- var VERSION = true ? "3.0.40" : "0.0.0-test";
35
+ var VERSION = true ? "3.0.42" : "0.0.0-test";
36
36
 
37
37
  // src/anthropic-messages-language-model.ts
38
38
  var import_provider3 = require("@ai-sdk/provider");
@@ -108,6 +108,10 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
108
108
  type: import_v42.z.literal("redacted_thinking"),
109
109
  data: import_v42.z.string()
110
110
  }),
111
+ import_v42.z.object({
112
+ type: import_v42.z.literal("compaction"),
113
+ content: import_v42.z.string()
114
+ }),
111
115
  import_v42.z.object({
112
116
  type: import_v42.z.literal("tool_use"),
113
117
  id: import_v42.z.string(),
@@ -306,7 +310,14 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
306
310
  input_tokens: import_v42.z.number(),
307
311
  output_tokens: import_v42.z.number(),
308
312
  cache_creation_input_tokens: import_v42.z.number().nullish(),
309
- cache_read_input_tokens: import_v42.z.number().nullish()
313
+ cache_read_input_tokens: import_v42.z.number().nullish(),
314
+ iterations: import_v42.z.array(
315
+ import_v42.z.object({
316
+ type: import_v42.z.union([import_v42.z.literal("compaction"), import_v42.z.literal("message")]),
317
+ input_tokens: import_v42.z.number(),
318
+ output_tokens: import_v42.z.number()
319
+ })
320
+ ).nullish()
310
321
  }),
311
322
  container: import_v42.z.object({
312
323
  expires_at: import_v42.z.string(),
@@ -331,6 +342,9 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
331
342
  type: import_v42.z.literal("clear_thinking_20251015"),
332
343
  cleared_thinking_turns: import_v42.z.number(),
333
344
  cleared_input_tokens: import_v42.z.number()
345
+ }),
346
+ import_v42.z.object({
347
+ type: import_v42.z.literal("compact_20260112")
334
348
  })
335
349
  ])
336
350
  )
@@ -412,6 +426,10 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
412
426
  type: import_v42.z.literal("redacted_thinking"),
413
427
  data: import_v42.z.string()
414
428
  }),
429
+ import_v42.z.object({
430
+ type: import_v42.z.literal("compaction"),
431
+ content: import_v42.z.string().nullish()
432
+ }),
415
433
  import_v42.z.object({
416
434
  type: import_v42.z.literal("server_tool_use"),
417
435
  id: import_v42.z.string(),
@@ -608,6 +626,10 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
608
626
  type: import_v42.z.literal("signature_delta"),
609
627
  signature: import_v42.z.string()
610
628
  }),
629
+ import_v42.z.object({
630
+ type: import_v42.z.literal("compaction_delta"),
631
+ content: import_v42.z.string()
632
+ }),
611
633
  import_v42.z.object({
612
634
  type: import_v42.z.literal("citations_delta"),
613
635
  citation: import_v42.z.discriminatedUnion("type", [
@@ -673,7 +695,14 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
673
695
  input_tokens: import_v42.z.number().nullish(),
674
696
  output_tokens: import_v42.z.number(),
675
697
  cache_creation_input_tokens: import_v42.z.number().nullish(),
676
- cache_read_input_tokens: import_v42.z.number().nullish()
698
+ cache_read_input_tokens: import_v42.z.number().nullish(),
699
+ iterations: import_v42.z.array(
700
+ import_v42.z.object({
701
+ type: import_v42.z.union([import_v42.z.literal("compaction"), import_v42.z.literal("message")]),
702
+ input_tokens: import_v42.z.number(),
703
+ output_tokens: import_v42.z.number()
704
+ })
705
+ ).nullish()
677
706
  }),
678
707
  context_management: import_v42.z.object({
679
708
  applied_edits: import_v42.z.array(
@@ -687,6 +716,9 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
687
716
  type: import_v42.z.literal("clear_thinking_20251015"),
688
717
  cleared_thinking_turns: import_v42.z.number(),
689
718
  cleared_input_tokens: import_v42.z.number()
719
+ }),
720
+ import_v42.z.object({
721
+ type: import_v42.z.literal("compact_20260112")
690
722
  })
691
723
  ])
692
724
  )
@@ -735,7 +767,7 @@ var anthropicFilePartProviderOptions = import_v43.z.object({
735
767
  */
736
768
  context: import_v43.z.string().optional()
737
769
  });
738
- var anthropicProviderOptions = import_v43.z.object({
770
+ var anthropicLanguageModelOptions = import_v43.z.object({
739
771
  /**
740
772
  * Whether to send reasoning to the model.
741
773
  *
@@ -866,6 +898,15 @@ var anthropicProviderOptions = import_v43.z.object({
866
898
  value: import_v43.z.number()
867
899
  })
868
900
  ]).optional()
901
+ }),
902
+ import_v43.z.object({
903
+ type: import_v43.z.literal("compact_20260112"),
904
+ trigger: import_v43.z.object({
905
+ type: import_v43.z.literal("input_tokens"),
906
+ value: import_v43.z.number()
907
+ }).optional(),
908
+ pauseAfterCompaction: import_v43.z.boolean().optional(),
909
+ instructions: import_v43.z.string().optional()
869
910
  })
870
911
  ])
871
912
  )
@@ -1355,10 +1396,24 @@ function convertAnthropicMessagesUsage({
1355
1396
  rawUsage
1356
1397
  }) {
1357
1398
  var _a, _b;
1358
- const inputTokens = usage.input_tokens;
1359
- const outputTokens = usage.output_tokens;
1360
1399
  const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
1361
1400
  const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
1401
+ let inputTokens;
1402
+ let outputTokens;
1403
+ if (usage.iterations && usage.iterations.length > 0) {
1404
+ const totals = usage.iterations.reduce(
1405
+ (acc, iter) => ({
1406
+ input: acc.input + iter.input_tokens,
1407
+ output: acc.output + iter.output_tokens
1408
+ }),
1409
+ { input: 0, output: 0 }
1410
+ );
1411
+ inputTokens = totals.input;
1412
+ outputTokens = totals.output;
1413
+ } else {
1414
+ inputTokens = usage.input_tokens;
1415
+ outputTokens = usage.output_tokens;
1416
+ }
1362
1417
  return {
1363
1418
  inputTokens: {
1364
1419
  total: inputTokens + cacheCreationTokens + cacheReadTokens,
@@ -1600,7 +1655,7 @@ async function convertToAnthropicMessagesPrompt({
1600
1655
  cacheControlValidator,
1601
1656
  toolNameMapping
1602
1657
  }) {
1603
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1658
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
1604
1659
  const betas = /* @__PURE__ */ new Set();
1605
1660
  const blocks = groupIntoBlocks(prompt);
1606
1661
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -1893,16 +1948,25 @@ async function convertToAnthropicMessagesPrompt({
1893
1948
  }) : void 0;
1894
1949
  switch (part.type) {
1895
1950
  case "text": {
1896
- anthropicContent.push({
1897
- type: "text",
1898
- text: (
1899
- // trim the last text part if it's the last message in the block
1900
- // because Anthropic does not allow trailing whitespace
1901
- // in pre-filled assistant responses
1902
- isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
1903
- ),
1904
- cache_control: cacheControl
1905
- });
1951
+ const textMetadata = (_g = part.providerOptions) == null ? void 0 : _g.anthropic;
1952
+ if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
1953
+ anthropicContent.push({
1954
+ type: "compaction",
1955
+ content: part.text,
1956
+ cache_control: cacheControl
1957
+ });
1958
+ } else {
1959
+ anthropicContent.push({
1960
+ type: "text",
1961
+ text: (
1962
+ // trim the last text part if it's the last message in the block
1963
+ // because Anthropic does not allow trailing whitespace
1964
+ // in pre-filled assistant responses
1965
+ isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
1966
+ ),
1967
+ cache_control: cacheControl
1968
+ });
1969
+ }
1906
1970
  break;
1907
1971
  }
1908
1972
  case "reasoning": {
@@ -1957,10 +2021,10 @@ async function convertToAnthropicMessagesPrompt({
1957
2021
  const providerToolName = toolNameMapping.toProviderToolName(
1958
2022
  part.toolName
1959
2023
  );
1960
- const isMcpToolUse = ((_h = (_g = part.providerOptions) == null ? void 0 : _g.anthropic) == null ? void 0 : _h.type) === "mcp-tool-use";
2024
+ const isMcpToolUse = ((_i = (_h = part.providerOptions) == null ? void 0 : _h.anthropic) == null ? void 0 : _i.type) === "mcp-tool-use";
1961
2025
  if (isMcpToolUse) {
1962
2026
  mcpToolUseIds.add(part.toolCallId);
1963
- const serverName = (_j = (_i = part.providerOptions) == null ? void 0 : _i.anthropic) == null ? void 0 : _j.serverName;
2027
+ const serverName = (_k = (_j = part.providerOptions) == null ? void 0 : _j.anthropic) == null ? void 0 : _k.serverName;
1964
2028
  if (serverName == null || typeof serverName !== "string") {
1965
2029
  warnings.push({
1966
2030
  type: "other",
@@ -2028,7 +2092,7 @@ async function convertToAnthropicMessagesPrompt({
2028
2092
  }
2029
2093
  break;
2030
2094
  }
2031
- const callerOptions = (_k = part.providerOptions) == null ? void 0 : _k.anthropic;
2095
+ const callerOptions = (_l = part.providerOptions) == null ? void 0 : _l.anthropic;
2032
2096
  const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? callerOptions.caller.type === "code_execution_20250825" && callerOptions.caller.toolId ? {
2033
2097
  type: "code_execution_20250825",
2034
2098
  tool_id: callerOptions.caller.toolId
@@ -2081,7 +2145,7 @@ async function convertToAnthropicMessagesPrompt({
2081
2145
  tool_use_id: part.toolCallId,
2082
2146
  content: {
2083
2147
  type: "code_execution_tool_result_error",
2084
- error_code: (_l = errorInfo.errorCode) != null ? _l : "unknown"
2148
+ error_code: (_m = errorInfo.errorCode) != null ? _m : "unknown"
2085
2149
  },
2086
2150
  cache_control: cacheControl
2087
2151
  });
@@ -2092,7 +2156,7 @@ async function convertToAnthropicMessagesPrompt({
2092
2156
  cache_control: cacheControl,
2093
2157
  content: {
2094
2158
  type: "bash_code_execution_tool_result_error",
2095
- error_code: (_m = errorInfo.errorCode) != null ? _m : "unknown"
2159
+ error_code: (_n = errorInfo.errorCode) != null ? _n : "unknown"
2096
2160
  }
2097
2161
  });
2098
2162
  }
@@ -2125,7 +2189,7 @@ async function convertToAnthropicMessagesPrompt({
2125
2189
  stdout: codeExecutionOutput.stdout,
2126
2190
  stderr: codeExecutionOutput.stderr,
2127
2191
  return_code: codeExecutionOutput.return_code,
2128
- content: (_n = codeExecutionOutput.content) != null ? _n : []
2192
+ content: (_o = codeExecutionOutput.content) != null ? _o : []
2129
2193
  },
2130
2194
  cache_control: cacheControl
2131
2195
  });
@@ -2143,7 +2207,7 @@ async function convertToAnthropicMessagesPrompt({
2143
2207
  stdout: codeExecutionOutput.stdout,
2144
2208
  stderr: codeExecutionOutput.stderr,
2145
2209
  return_code: codeExecutionOutput.return_code,
2146
- content: (_o = codeExecutionOutput.content) != null ? _o : []
2210
+ content: (_p = codeExecutionOutput.content) != null ? _p : []
2147
2211
  },
2148
2212
  cache_control: cacheControl
2149
2213
  });
@@ -2176,7 +2240,7 @@ async function convertToAnthropicMessagesPrompt({
2176
2240
  errorValue = output.value;
2177
2241
  }
2178
2242
  } catch (e) {
2179
- const extractedErrorCode = (_p = output.value) == null ? void 0 : _p.errorCode;
2243
+ const extractedErrorCode = (_q = output.value) == null ? void 0 : _q.errorCode;
2180
2244
  errorValue = {
2181
2245
  errorCode: typeof extractedErrorCode === "string" ? extractedErrorCode : "unknown"
2182
2246
  };
@@ -2186,7 +2250,7 @@ async function convertToAnthropicMessagesPrompt({
2186
2250
  tool_use_id: part.toolCallId,
2187
2251
  content: {
2188
2252
  type: "web_fetch_tool_result_error",
2189
- error_code: (_q = errorValue.errorCode) != null ? _q : "unknown"
2253
+ error_code: (_r = errorValue.errorCode) != null ? _r : "unknown"
2190
2254
  },
2191
2255
  cache_control: cacheControl
2192
2256
  });
@@ -2367,6 +2431,8 @@ function mapAnthropicStopReason({
2367
2431
  case "max_tokens":
2368
2432
  case "model_context_window_exceeded":
2369
2433
  return "length";
2434
+ case "compaction":
2435
+ return "other";
2370
2436
  default:
2371
2437
  return "other";
2372
2438
  }
@@ -2500,12 +2566,12 @@ var AnthropicMessagesLanguageModel = class {
2500
2566
  const canonicalOptions = await (0, import_provider_utils12.parseProviderOptions)({
2501
2567
  provider: "anthropic",
2502
2568
  providerOptions,
2503
- schema: anthropicProviderOptions
2569
+ schema: anthropicLanguageModelOptions
2504
2570
  });
2505
2571
  const customProviderOptions = providerOptionsName !== "anthropic" ? await (0, import_provider_utils12.parseProviderOptions)({
2506
2572
  provider: providerOptionsName,
2507
2573
  providerOptions,
2508
- schema: anthropicProviderOptions
2574
+ schema: anthropicLanguageModelOptions
2509
2575
  }) : null;
2510
2576
  const usedCustomProviderKey = customProviderOptions != null;
2511
2577
  const anthropicOptions = Object.assign(
@@ -2649,6 +2715,19 @@ var AnthropicMessagesLanguageModel = class {
2649
2715
  type: edit.type,
2650
2716
  ...edit.keep !== void 0 && { keep: edit.keep }
2651
2717
  };
2718
+ case "compact_20260112":
2719
+ return {
2720
+ type: edit.type,
2721
+ ...edit.trigger !== void 0 && {
2722
+ trigger: edit.trigger
2723
+ },
2724
+ ...edit.pauseAfterCompaction !== void 0 && {
2725
+ pause_after_compaction: edit.pauseAfterCompaction
2726
+ },
2727
+ ...edit.instructions !== void 0 && {
2728
+ instructions: edit.instructions
2729
+ }
2730
+ };
2652
2731
  default:
2653
2732
  warnings.push({
2654
2733
  type: "other",
@@ -2723,6 +2802,9 @@ var AnthropicMessagesLanguageModel = class {
2723
2802
  }
2724
2803
  if (contextManagement) {
2725
2804
  betas.add("context-management-2025-06-27");
2805
+ if (contextManagement.edits.some((e) => e.type === "compact_20260112")) {
2806
+ betas.add("compact-2026-01-12");
2807
+ }
2726
2808
  }
2727
2809
  if ((anthropicOptions == null ? void 0 : anthropicOptions.container) && anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0) {
2728
2810
  betas.add("code-execution-2025-08-25");
@@ -2921,6 +3003,18 @@ var AnthropicMessagesLanguageModel = class {
2921
3003
  });
2922
3004
  break;
2923
3005
  }
3006
+ case "compaction": {
3007
+ content.push({
3008
+ type: "text",
3009
+ text: part.content,
3010
+ providerMetadata: {
3011
+ anthropic: {
3012
+ type: "compaction"
3013
+ }
3014
+ }
3015
+ });
3016
+ break;
3017
+ }
2924
3018
  case "tool_use": {
2925
3019
  const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
2926
3020
  if (isJsonResponseTool) {
@@ -3204,6 +3298,11 @@ var AnthropicMessagesLanguageModel = class {
3204
3298
  usage: response.usage,
3205
3299
  cacheCreationInputTokens: (_a2 = response.usage.cache_creation_input_tokens) != null ? _a2 : null,
3206
3300
  stopSequence: (_b2 = response.stop_sequence) != null ? _b2 : null,
3301
+ iterations: response.usage.iterations ? response.usage.iterations.map((iter) => ({
3302
+ type: iter.type,
3303
+ inputTokens: iter.input_tokens,
3304
+ outputTokens: iter.output_tokens
3305
+ })) : null,
3207
3306
  container: response.container ? {
3208
3307
  expiresAt: response.container.expires_at,
3209
3308
  id: response.container.id,
@@ -3265,7 +3364,8 @@ var AnthropicMessagesLanguageModel = class {
3265
3364
  input_tokens: 0,
3266
3365
  output_tokens: 0,
3267
3366
  cache_creation_input_tokens: 0,
3268
- cache_read_input_tokens: 0
3367
+ cache_read_input_tokens: 0,
3368
+ iterations: null
3269
3369
  };
3270
3370
  const contentBlocks = {};
3271
3371
  const mcpToolCalls = {};
@@ -3334,6 +3434,19 @@ var AnthropicMessagesLanguageModel = class {
3334
3434
  });
3335
3435
  return;
3336
3436
  }
3437
+ case "compaction": {
3438
+ contentBlocks[value.index] = { type: "text" };
3439
+ controller.enqueue({
3440
+ type: "text-start",
3441
+ id: String(value.index),
3442
+ providerMetadata: {
3443
+ anthropic: {
3444
+ type: "compaction"
3445
+ }
3446
+ }
3447
+ });
3448
+ return;
3449
+ }
3337
3450
  case "tool_use": {
3338
3451
  const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
3339
3452
  if (isJsonResponseTool) {
@@ -3720,6 +3833,14 @@ var AnthropicMessagesLanguageModel = class {
3720
3833
  }
3721
3834
  return;
3722
3835
  }
3836
+ case "compaction_delta": {
3837
+ controller.enqueue({
3838
+ type: "text-delta",
3839
+ id: String(value.index),
3840
+ delta: value.delta.content
3841
+ });
3842
+ return;
3843
+ }
3723
3844
  case "input_json_delta": {
3724
3845
  const contentBlock = contentBlocks[value.index];
3725
3846
  let delta = value.delta.partial_json;
@@ -3855,6 +3976,9 @@ var AnthropicMessagesLanguageModel = class {
3855
3976
  usage.cache_creation_input_tokens = value.usage.cache_creation_input_tokens;
3856
3977
  cacheCreationInputTokens = value.usage.cache_creation_input_tokens;
3857
3978
  }
3979
+ if (value.usage.iterations != null) {
3980
+ usage.iterations = value.usage.iterations;
3981
+ }
3858
3982
  finishReason = {
3859
3983
  unified: mapAnthropicStopReason({
3860
3984
  finishReason: value.delta.stop_reason,
@@ -3888,6 +4012,11 @@ var AnthropicMessagesLanguageModel = class {
3888
4012
  usage: rawUsage != null ? rawUsage : null,
3889
4013
  cacheCreationInputTokens,
3890
4014
  stopSequence,
4015
+ iterations: usage.iterations ? usage.iterations.map((iter) => ({
4016
+ type: iter.type,
4017
+ inputTokens: iter.input_tokens,
4018
+ outputTokens: iter.output_tokens
4019
+ })) : null,
3891
4020
  container,
3892
4021
  contextManagement
3893
4022
  };
@@ -4017,6 +4146,10 @@ function mapAnthropicResponseContextManagement(contextManagement) {
4017
4146
  clearedThinkingTurns: edit.cleared_thinking_turns,
4018
4147
  clearedInputTokens: edit.cleared_input_tokens
4019
4148
  };
4149
+ case "compact_20260112":
4150
+ return {
4151
+ type: edit.type
4152
+ };
4020
4153
  }
4021
4154
  }).filter((edit) => edit !== void 0)
4022
4155
  } : null;