@ai-sdk/anthropic 3.0.39 → 3.0.41

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.41
4
+
5
+ ### Patch Changes
6
+
7
+ - c60b393: feat(anthropic): add the new compaction feature
8
+
9
+ ## 3.0.40
10
+
11
+ ### Patch Changes
12
+
13
+ - 8c2b1e1: fix(provider/anthropic): include actual raw usage data for `response.usage.raw` when streaming
14
+
3
15
  ## 3.0.39
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,6 +114,16 @@ 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
  }
@@ -167,6 +201,14 @@ 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>;
@@ -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 AnthropicMessageMetadata, type AnthropicProvider, type 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,6 +114,16 @@ 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
  }
@@ -167,6 +201,14 @@ 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>;
@@ -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 AnthropicMessageMetadata, type AnthropicProvider, type 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.39" : "0.0.0-test";
35
+ var VERSION = true ? "3.0.41" : "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
  )
@@ -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
  )
@@ -1350,12 +1391,29 @@ async function prepareTools({
1350
1391
  }
1351
1392
 
1352
1393
  // src/convert-anthropic-messages-usage.ts
1353
- function convertAnthropicMessagesUsage(usage) {
1394
+ function convertAnthropicMessagesUsage({
1395
+ usage,
1396
+ rawUsage
1397
+ }) {
1354
1398
  var _a, _b;
1355
- const inputTokens = usage.input_tokens;
1356
- const outputTokens = usage.output_tokens;
1357
1399
  const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
1358
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
+ }
1359
1417
  return {
1360
1418
  inputTokens: {
1361
1419
  total: inputTokens + cacheCreationTokens + cacheReadTokens,
@@ -1368,7 +1426,7 @@ function convertAnthropicMessagesUsage(usage) {
1368
1426
  text: void 0,
1369
1427
  reasoning: void 0
1370
1428
  },
1371
- raw: usage
1429
+ raw: rawUsage != null ? rawUsage : usage
1372
1430
  };
1373
1431
  }
1374
1432
 
@@ -1597,7 +1655,7 @@ async function convertToAnthropicMessagesPrompt({
1597
1655
  cacheControlValidator,
1598
1656
  toolNameMapping
1599
1657
  }) {
1600
- 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;
1601
1659
  const betas = /* @__PURE__ */ new Set();
1602
1660
  const blocks = groupIntoBlocks(prompt);
1603
1661
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -1890,16 +1948,25 @@ async function convertToAnthropicMessagesPrompt({
1890
1948
  }) : void 0;
1891
1949
  switch (part.type) {
1892
1950
  case "text": {
1893
- anthropicContent.push({
1894
- type: "text",
1895
- text: (
1896
- // trim the last text part if it's the last message in the block
1897
- // because Anthropic does not allow trailing whitespace
1898
- // in pre-filled assistant responses
1899
- isLastBlock && isLastMessage && isLastContentPart ? part.text.trim() : part.text
1900
- ),
1901
- cache_control: cacheControl
1902
- });
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
+ }
1903
1970
  break;
1904
1971
  }
1905
1972
  case "reasoning": {
@@ -1954,10 +2021,10 @@ async function convertToAnthropicMessagesPrompt({
1954
2021
  const providerToolName = toolNameMapping.toProviderToolName(
1955
2022
  part.toolName
1956
2023
  );
1957
- 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";
1958
2025
  if (isMcpToolUse) {
1959
2026
  mcpToolUseIds.add(part.toolCallId);
1960
- 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;
1961
2028
  if (serverName == null || typeof serverName !== "string") {
1962
2029
  warnings.push({
1963
2030
  type: "other",
@@ -2025,7 +2092,7 @@ async function convertToAnthropicMessagesPrompt({
2025
2092
  }
2026
2093
  break;
2027
2094
  }
2028
- const callerOptions = (_k = part.providerOptions) == null ? void 0 : _k.anthropic;
2095
+ const callerOptions = (_l = part.providerOptions) == null ? void 0 : _l.anthropic;
2029
2096
  const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? callerOptions.caller.type === "code_execution_20250825" && callerOptions.caller.toolId ? {
2030
2097
  type: "code_execution_20250825",
2031
2098
  tool_id: callerOptions.caller.toolId
@@ -2078,7 +2145,7 @@ async function convertToAnthropicMessagesPrompt({
2078
2145
  tool_use_id: part.toolCallId,
2079
2146
  content: {
2080
2147
  type: "code_execution_tool_result_error",
2081
- error_code: (_l = errorInfo.errorCode) != null ? _l : "unknown"
2148
+ error_code: (_m = errorInfo.errorCode) != null ? _m : "unknown"
2082
2149
  },
2083
2150
  cache_control: cacheControl
2084
2151
  });
@@ -2089,7 +2156,7 @@ async function convertToAnthropicMessagesPrompt({
2089
2156
  cache_control: cacheControl,
2090
2157
  content: {
2091
2158
  type: "bash_code_execution_tool_result_error",
2092
- error_code: (_m = errorInfo.errorCode) != null ? _m : "unknown"
2159
+ error_code: (_n = errorInfo.errorCode) != null ? _n : "unknown"
2093
2160
  }
2094
2161
  });
2095
2162
  }
@@ -2122,7 +2189,7 @@ async function convertToAnthropicMessagesPrompt({
2122
2189
  stdout: codeExecutionOutput.stdout,
2123
2190
  stderr: codeExecutionOutput.stderr,
2124
2191
  return_code: codeExecutionOutput.return_code,
2125
- content: (_n = codeExecutionOutput.content) != null ? _n : []
2192
+ content: (_o = codeExecutionOutput.content) != null ? _o : []
2126
2193
  },
2127
2194
  cache_control: cacheControl
2128
2195
  });
@@ -2140,7 +2207,7 @@ async function convertToAnthropicMessagesPrompt({
2140
2207
  stdout: codeExecutionOutput.stdout,
2141
2208
  stderr: codeExecutionOutput.stderr,
2142
2209
  return_code: codeExecutionOutput.return_code,
2143
- content: (_o = codeExecutionOutput.content) != null ? _o : []
2210
+ content: (_p = codeExecutionOutput.content) != null ? _p : []
2144
2211
  },
2145
2212
  cache_control: cacheControl
2146
2213
  });
@@ -2173,7 +2240,7 @@ async function convertToAnthropicMessagesPrompt({
2173
2240
  errorValue = output.value;
2174
2241
  }
2175
2242
  } catch (e) {
2176
- const extractedErrorCode = (_p = output.value) == null ? void 0 : _p.errorCode;
2243
+ const extractedErrorCode = (_q = output.value) == null ? void 0 : _q.errorCode;
2177
2244
  errorValue = {
2178
2245
  errorCode: typeof extractedErrorCode === "string" ? extractedErrorCode : "unknown"
2179
2246
  };
@@ -2183,7 +2250,7 @@ async function convertToAnthropicMessagesPrompt({
2183
2250
  tool_use_id: part.toolCallId,
2184
2251
  content: {
2185
2252
  type: "web_fetch_tool_result_error",
2186
- error_code: (_q = errorValue.errorCode) != null ? _q : "unknown"
2253
+ error_code: (_r = errorValue.errorCode) != null ? _r : "unknown"
2187
2254
  },
2188
2255
  cache_control: cacheControl
2189
2256
  });
@@ -2364,6 +2431,8 @@ function mapAnthropicStopReason({
2364
2431
  case "max_tokens":
2365
2432
  case "model_context_window_exceeded":
2366
2433
  return "length";
2434
+ case "compaction":
2435
+ return "other";
2367
2436
  default:
2368
2437
  return "other";
2369
2438
  }
@@ -2646,6 +2715,19 @@ var AnthropicMessagesLanguageModel = class {
2646
2715
  type: edit.type,
2647
2716
  ...edit.keep !== void 0 && { keep: edit.keep }
2648
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
+ };
2649
2731
  default:
2650
2732
  warnings.push({
2651
2733
  type: "other",
@@ -2720,6 +2802,9 @@ var AnthropicMessagesLanguageModel = class {
2720
2802
  }
2721
2803
  if (contextManagement) {
2722
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
+ }
2723
2808
  }
2724
2809
  if ((anthropicOptions == null ? void 0 : anthropicOptions.container) && anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0) {
2725
2810
  betas.add("code-execution-2025-08-25");
@@ -2918,6 +3003,18 @@ var AnthropicMessagesLanguageModel = class {
2918
3003
  });
2919
3004
  break;
2920
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
+ }
2921
3018
  case "tool_use": {
2922
3019
  const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
2923
3020
  if (isJsonResponseTool) {
@@ -3186,7 +3283,7 @@ var AnthropicMessagesLanguageModel = class {
3186
3283
  }),
3187
3284
  raw: (_d = response.stop_reason) != null ? _d : void 0
3188
3285
  },
3189
- usage: convertAnthropicMessagesUsage(response.usage),
3286
+ usage: convertAnthropicMessagesUsage({ usage: response.usage }),
3190
3287
  request: { body: args },
3191
3288
  response: {
3192
3289
  id: (_e = response.id) != null ? _e : void 0,
@@ -3201,6 +3298,11 @@ var AnthropicMessagesLanguageModel = class {
3201
3298
  usage: response.usage,
3202
3299
  cacheCreationInputTokens: (_a2 = response.usage.cache_creation_input_tokens) != null ? _a2 : null,
3203
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,
3204
3306
  container: response.container ? {
3205
3307
  expiresAt: response.container.expires_at,
3206
3308
  id: response.container.id,
@@ -3262,7 +3364,8 @@ var AnthropicMessagesLanguageModel = class {
3262
3364
  input_tokens: 0,
3263
3365
  output_tokens: 0,
3264
3366
  cache_creation_input_tokens: 0,
3265
- cache_read_input_tokens: 0
3367
+ cache_read_input_tokens: 0,
3368
+ iterations: null
3266
3369
  };
3267
3370
  const contentBlocks = {};
3268
3371
  const mcpToolCalls = {};
@@ -3331,6 +3434,19 @@ var AnthropicMessagesLanguageModel = class {
3331
3434
  });
3332
3435
  return;
3333
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
+ }
3334
3450
  case "tool_use": {
3335
3451
  const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
3336
3452
  if (isJsonResponseTool) {
@@ -3717,6 +3833,14 @@ var AnthropicMessagesLanguageModel = class {
3717
3833
  }
3718
3834
  return;
3719
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
+ }
3720
3844
  case "input_json_delta": {
3721
3845
  const contentBlock = contentBlocks[value.index];
3722
3846
  let delta = value.delta.partial_json;
@@ -3852,6 +3976,9 @@ var AnthropicMessagesLanguageModel = class {
3852
3976
  usage.cache_creation_input_tokens = value.usage.cache_creation_input_tokens;
3853
3977
  cacheCreationInputTokens = value.usage.cache_creation_input_tokens;
3854
3978
  }
3979
+ if (value.usage.iterations != null) {
3980
+ usage.iterations = value.usage.iterations;
3981
+ }
3855
3982
  finishReason = {
3856
3983
  unified: mapAnthropicStopReason({
3857
3984
  finishReason: value.delta.stop_reason,
@@ -3885,6 +4012,11 @@ var AnthropicMessagesLanguageModel = class {
3885
4012
  usage: rawUsage != null ? rawUsage : null,
3886
4013
  cacheCreationInputTokens,
3887
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,
3888
4020
  container,
3889
4021
  contextManagement
3890
4022
  };
@@ -3897,7 +4029,7 @@ var AnthropicMessagesLanguageModel = class {
3897
4029
  controller.enqueue({
3898
4030
  type: "finish",
3899
4031
  finishReason,
3900
- usage: convertAnthropicMessagesUsage(usage),
4032
+ usage: convertAnthropicMessagesUsage({ usage, rawUsage }),
3901
4033
  providerMetadata
3902
4034
  });
3903
4035
  return;
@@ -4014,6 +4146,10 @@ function mapAnthropicResponseContextManagement(contextManagement) {
4014
4146
  clearedThinkingTurns: edit.cleared_thinking_turns,
4015
4147
  clearedInputTokens: edit.cleared_input_tokens
4016
4148
  };
4149
+ case "compact_20260112":
4150
+ return {
4151
+ type: edit.type
4152
+ };
4017
4153
  }
4018
4154
  }).filter((edit) => edit !== void 0)
4019
4155
  } : null;