@ai-sdk/anthropic 2.0.79 → 2.0.81

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
+ ## 2.0.81
4
+
5
+ ### Patch Changes
6
+
7
+ - 518f0c3: feat(provider/anthropic): add support for `claude-fable-5` and the `fallbacks` API parameter
8
+
9
+ ## 2.0.80
10
+
11
+ ### Patch Changes
12
+
13
+ - 0e2aaaa: feat(provider/anthropic): add support for `claude-opus-4-8`
14
+
3
15
  ## 2.0.79
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -5,11 +5,22 @@ import { FetchFunction } from '@ai-sdk/provider-utils';
5
5
 
6
6
  /**
7
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).
8
+ *
9
+ * - `compaction`: a context compaction step.
10
+ * - `message`: an executor sampling iteration.
11
+ * - `advisor_message`: an advisor sub-inference.
12
+ * - `fallback_message`: a server-side fallback attempt that served the turn.
13
+ * Inspect this array for exact per-model attribution on a turn that fell
14
+ * back.
10
15
  */
11
16
  interface AnthropicUsageIteration {
12
- type: 'compaction' | 'message';
17
+ type: 'compaction' | 'message' | 'advisor_message' | 'fallback_message';
18
+ /**
19
+ * The model that produced this iteration. Populated for the per-model
20
+ * attribution cases (the fallback chain and advisor sub-inferences) and
21
+ * absent otherwise.
22
+ */
23
+ model?: string;
13
24
  /**
14
25
  * Number of input tokens consumed in this iteration.
15
26
  */
@@ -23,6 +34,38 @@ interface AnthropicMessageMetadata {
23
34
  usage: JSONObject;
24
35
  cacheCreationInputTokens: number | null;
25
36
  stopSequence: string | null;
37
+ /**
38
+ * Details about why the request stopped. Present only when the API returns
39
+ * a `refusal` stop reason together with a `stop_details` object (a
40
+ * classifier block or a model refusal).
41
+ *
42
+ * Branch on the finish reason (`content-filter`), not on this object: the
43
+ * API may return a refusal with no details at all, so this field can be
44
+ * absent even on a refusal and should not be relied upon being present.
45
+ */
46
+ stopDetails?: {
47
+ /**
48
+ * The kind of stop detail. `'refusal'` for classifier blocks and model
49
+ * refusals.
50
+ */
51
+ type: string;
52
+ /**
53
+ * The classifier category that triggered the block, e.g. `'cyber'` or
54
+ * `'bio'`. Absent for model refusals and other cases.
55
+ */
56
+ category?: string;
57
+ /**
58
+ * Human-readable explanation of why the request was blocked. May be
59
+ * absent even on a refusal.
60
+ */
61
+ explanation?: string;
62
+ /**
63
+ * The canonical id of a model to retry directly. Populated only when the
64
+ * request included fallbacks and the fallback attempt could not be made
65
+ * (e.g. the fallback model was rate limited or overloaded).
66
+ */
67
+ recommendedModel?: string;
68
+ };
26
69
  /**
27
70
  * Usage breakdown by iteration when compaction is triggered.
28
71
  *
@@ -126,7 +169,7 @@ interface AnthropicMessageMetadata {
126
169
  } | null;
127
170
  }
128
171
 
129
- 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-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | (string & {});
172
+ 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-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-fable-5' | (string & {});
130
173
  declare const anthropicProviderOptions: z.ZodObject<{
131
174
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
132
175
  structuredOutputMode: z.ZodOptional<z.ZodEnum<{
@@ -182,6 +225,16 @@ declare const anthropicProviderOptions: z.ZodObject<{
182
225
  us: "us";
183
226
  global: "global";
184
227
  }>>;
228
+ fallbacks: z.ZodOptional<z.ZodArray<z.ZodObject<{
229
+ model: z.ZodString;
230
+ max_tokens: z.ZodOptional<z.ZodNumber>;
231
+ thinking: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
232
+ output_config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
233
+ speed: z.ZodOptional<z.ZodEnum<{
234
+ fast: "fast";
235
+ standard: "standard";
236
+ }>>;
237
+ }, z.core.$strip>>>;
185
238
  contextManagement: z.ZodOptional<z.ZodObject<{
186
239
  edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
187
240
  type: z.ZodLiteral<"clear_tool_uses_20250919">;
package/dist/index.d.ts CHANGED
@@ -5,11 +5,22 @@ import { FetchFunction } from '@ai-sdk/provider-utils';
5
5
 
6
6
  /**
7
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).
8
+ *
9
+ * - `compaction`: a context compaction step.
10
+ * - `message`: an executor sampling iteration.
11
+ * - `advisor_message`: an advisor sub-inference.
12
+ * - `fallback_message`: a server-side fallback attempt that served the turn.
13
+ * Inspect this array for exact per-model attribution on a turn that fell
14
+ * back.
10
15
  */
11
16
  interface AnthropicUsageIteration {
12
- type: 'compaction' | 'message';
17
+ type: 'compaction' | 'message' | 'advisor_message' | 'fallback_message';
18
+ /**
19
+ * The model that produced this iteration. Populated for the per-model
20
+ * attribution cases (the fallback chain and advisor sub-inferences) and
21
+ * absent otherwise.
22
+ */
23
+ model?: string;
13
24
  /**
14
25
  * Number of input tokens consumed in this iteration.
15
26
  */
@@ -23,6 +34,38 @@ interface AnthropicMessageMetadata {
23
34
  usage: JSONObject;
24
35
  cacheCreationInputTokens: number | null;
25
36
  stopSequence: string | null;
37
+ /**
38
+ * Details about why the request stopped. Present only when the API returns
39
+ * a `refusal` stop reason together with a `stop_details` object (a
40
+ * classifier block or a model refusal).
41
+ *
42
+ * Branch on the finish reason (`content-filter`), not on this object: the
43
+ * API may return a refusal with no details at all, so this field can be
44
+ * absent even on a refusal and should not be relied upon being present.
45
+ */
46
+ stopDetails?: {
47
+ /**
48
+ * The kind of stop detail. `'refusal'` for classifier blocks and model
49
+ * refusals.
50
+ */
51
+ type: string;
52
+ /**
53
+ * The classifier category that triggered the block, e.g. `'cyber'` or
54
+ * `'bio'`. Absent for model refusals and other cases.
55
+ */
56
+ category?: string;
57
+ /**
58
+ * Human-readable explanation of why the request was blocked. May be
59
+ * absent even on a refusal.
60
+ */
61
+ explanation?: string;
62
+ /**
63
+ * The canonical id of a model to retry directly. Populated only when the
64
+ * request included fallbacks and the fallback attempt could not be made
65
+ * (e.g. the fallback model was rate limited or overloaded).
66
+ */
67
+ recommendedModel?: string;
68
+ };
26
69
  /**
27
70
  * Usage breakdown by iteration when compaction is triggered.
28
71
  *
@@ -126,7 +169,7 @@ interface AnthropicMessageMetadata {
126
169
  } | null;
127
170
  }
128
171
 
129
- 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-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | (string & {});
172
+ 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-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-fable-5' | (string & {});
130
173
  declare const anthropicProviderOptions: z.ZodObject<{
131
174
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
132
175
  structuredOutputMode: z.ZodOptional<z.ZodEnum<{
@@ -182,6 +225,16 @@ declare const anthropicProviderOptions: z.ZodObject<{
182
225
  us: "us";
183
226
  global: "global";
184
227
  }>>;
228
+ fallbacks: z.ZodOptional<z.ZodArray<z.ZodObject<{
229
+ model: z.ZodString;
230
+ max_tokens: z.ZodOptional<z.ZodNumber>;
231
+ thinking: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
232
+ output_config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
233
+ speed: z.ZodOptional<z.ZodEnum<{
234
+ fast: "fast";
235
+ standard: "standard";
236
+ }>>;
237
+ }, z.core.$strip>>>;
185
238
  contextManagement: z.ZodOptional<z.ZodObject<{
186
239
  edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
187
240
  type: z.ZodLiteral<"clear_tool_uses_20250919">;
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.79" : "0.0.0-test";
34
+ var VERSION = true ? "2.0.81" : "0.0.0-test";
35
35
 
36
36
  // src/anthropic-messages-language-model.ts
37
37
  var import_provider3 = require("@ai-sdk/provider");
@@ -59,6 +59,12 @@ var anthropicFailedResponseHandler = (0, import_provider_utils.createJsonErrorRe
59
59
  // src/anthropic-messages-api.ts
60
60
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
61
61
  var import_v42 = require("zod/v4");
62
+ var anthropicStopDetailsSchema = import_v42.z.object({
63
+ type: import_v42.z.string(),
64
+ category: import_v42.z.string().nullish(),
65
+ explanation: import_v42.z.string().nullish(),
66
+ recommended_model: import_v42.z.string().nullish()
67
+ });
62
68
  var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
63
69
  () => (0, import_provider_utils2.zodSchema)(
64
70
  import_v42.z.object({
@@ -246,11 +252,18 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
246
252
  old_start: import_v42.z.number().nullable()
247
253
  })
248
254
  ])
255
+ }),
256
+ // Server-side fallback marker. Parsed so the response validates, but
257
+ // dropped from the content output (the AI SDK has no model-hop
258
+ // primitive). The hop remains observable via usage.iterations.
259
+ import_v42.z.object({
260
+ type: import_v42.z.literal("fallback")
249
261
  })
250
262
  ])
251
263
  ),
252
264
  stop_reason: import_v42.z.string().nullish(),
253
265
  stop_sequence: import_v42.z.string().nullish(),
266
+ stop_details: anthropicStopDetailsSchema.nullish(),
254
267
  usage: import_v42.z.looseObject({
255
268
  input_tokens: import_v42.z.number(),
256
269
  output_tokens: import_v42.z.number(),
@@ -258,9 +271,17 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
258
271
  cache_read_input_tokens: import_v42.z.number().nullish(),
259
272
  iterations: import_v42.z.array(
260
273
  import_v42.z.object({
261
- type: import_v42.z.union([import_v42.z.literal("compaction"), import_v42.z.literal("message")]),
274
+ type: import_v42.z.union([
275
+ import_v42.z.literal("compaction"),
276
+ import_v42.z.literal("message"),
277
+ import_v42.z.literal("advisor_message"),
278
+ import_v42.z.literal("fallback_message")
279
+ ]),
280
+ model: import_v42.z.string().nullish(),
262
281
  input_tokens: import_v42.z.number(),
263
- output_tokens: import_v42.z.number()
282
+ output_tokens: import_v42.z.number(),
283
+ cache_creation_input_tokens: import_v42.z.number().nullish(),
284
+ cache_read_input_tokens: import_v42.z.number().nullish()
264
285
  })
265
286
  ).nullish()
266
287
  }),
@@ -466,6 +487,11 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
466
487
  old_start: import_v42.z.number().nullable()
467
488
  })
468
489
  ])
490
+ }),
491
+ // Server-side fallback marker; dropped from content output (see the
492
+ // response schema). The hop remains observable via usage.iterations.
493
+ import_v42.z.object({
494
+ type: import_v42.z.literal("fallback")
469
495
  })
470
496
  ])
471
497
  }),
@@ -539,6 +565,7 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
539
565
  delta: import_v42.z.object({
540
566
  stop_reason: import_v42.z.string().nullish(),
541
567
  stop_sequence: import_v42.z.string().nullish(),
568
+ stop_details: anthropicStopDetailsSchema.nullish(),
542
569
  container: import_v42.z.object({
543
570
  expires_at: import_v42.z.string(),
544
571
  id: import_v42.z.string(),
@@ -561,9 +588,17 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
561
588
  cache_read_input_tokens: import_v42.z.number().nullish(),
562
589
  iterations: import_v42.z.array(
563
590
  import_v42.z.object({
564
- type: import_v42.z.union([import_v42.z.literal("compaction"), import_v42.z.literal("message")]),
591
+ type: import_v42.z.union([
592
+ import_v42.z.literal("compaction"),
593
+ import_v42.z.literal("message"),
594
+ import_v42.z.literal("advisor_message"),
595
+ import_v42.z.literal("fallback_message")
596
+ ]),
597
+ model: import_v42.z.string().nullish(),
565
598
  input_tokens: import_v42.z.number(),
566
- output_tokens: import_v42.z.number()
599
+ output_tokens: import_v42.z.number(),
600
+ cache_creation_input_tokens: import_v42.z.number().nullish(),
601
+ cache_read_input_tokens: import_v42.z.number().nullish()
567
602
  })
568
603
  ).nullish()
569
604
  }),
@@ -738,6 +773,31 @@ var anthropicProviderOptions = import_v43.z.object({
738
773
  * See https://platform.claude.com/docs/en/build-with-claude/data-residency
739
774
  */
740
775
  inferenceGeo: import_v43.z.enum(["us", "global"]).optional(),
776
+ /**
777
+ * Server-side fallback chain.
778
+ *
779
+ * When the primary model's safety classifiers block a turn, the API
780
+ * automatically retries it on the next model in the chain, server-side. A
781
+ * `content-filter` finish reason means the entire chain refused.
782
+ *
783
+ * Each entry is merged into the request as a direct request to that entry's
784
+ * model, so it must be formatted accordingly: `model` is required, and an
785
+ * entry may additionally override `max_tokens`, `thinking`, `output_config`,
786
+ * and `speed` for that attempt only (`speed` additionally requires the speed
787
+ * beta). The value is passed through to the API as-is.
788
+ *
789
+ * The required `server-side-fallback-2026-06-01` beta is added automatically
790
+ * when this option is set.
791
+ */
792
+ fallbacks: import_v43.z.array(
793
+ import_v43.z.object({
794
+ model: import_v43.z.string(),
795
+ max_tokens: import_v43.z.number().int().optional(),
796
+ thinking: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).optional(),
797
+ output_config: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).optional(),
798
+ speed: import_v43.z.enum(["fast", "standard"]).optional()
799
+ })
800
+ ).optional(),
741
801
  /**
742
802
  * Context management configuration for automatic context window management.
743
803
  * Enables features like automatic compaction and clearing of tool uses/thinking blocks.
@@ -1408,19 +1468,20 @@ async function convertToAnthropicMessagesPrompt({
1408
1468
  const type = block.type;
1409
1469
  switch (type) {
1410
1470
  case "system": {
1411
- if (system != null) {
1412
- throw new import_provider2.UnsupportedFunctionalityError({
1413
- functionality: "Multiple system messages that are separated by user/assistant messages"
1414
- });
1415
- }
1416
- system = block.messages.map(({ content, providerOptions }) => ({
1471
+ const content = block.messages.map(({ content: content2, providerOptions }) => ({
1417
1472
  type: "text",
1418
- text: content,
1473
+ text: content2,
1419
1474
  cache_control: validator.getCacheControl(providerOptions, {
1420
1475
  type: "system message",
1421
1476
  canCache: true
1422
1477
  })
1423
1478
  }));
1479
+ if (system == null) {
1480
+ system = content;
1481
+ } else {
1482
+ messages.push({ role: "system", content });
1483
+ betas.add("mid-conversation-system-2026-04-07");
1484
+ }
1424
1485
  break;
1425
1486
  }
1426
1487
  case "user": {
@@ -2297,6 +2358,9 @@ var AnthropicMessagesLanguageModel = class {
2297
2358
  ...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
2298
2359
  inference_geo: anthropicOptions.inferenceGeo
2299
2360
  },
2361
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0 && {
2362
+ fallbacks: anthropicOptions.fallbacks
2363
+ },
2300
2364
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
2301
2365
  cache_control: anthropicOptions.cacheControl
2302
2366
  },
@@ -2439,6 +2503,9 @@ var AnthropicMessagesLanguageModel = class {
2439
2503
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
2440
2504
  betas.add("fast-mode-2026-02-01");
2441
2505
  }
2506
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
2507
+ betas.add("server-side-fallback-2026-06-01");
2508
+ }
2442
2509
  if (useStructuredOutput) {
2443
2510
  betas.add("structured-outputs-2025-11-13");
2444
2511
  }
@@ -2538,7 +2605,7 @@ var AnthropicMessagesLanguageModel = class {
2538
2605
  });
2539
2606
  }
2540
2607
  async doGenerate(options) {
2541
- var _a, _b, _c, _d, _e, _f, _g, _h;
2608
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2542
2609
  const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
2543
2610
  ...options,
2544
2611
  userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
@@ -2778,11 +2845,20 @@ var AnthropicMessagesLanguageModel = class {
2778
2845
  });
2779
2846
  break;
2780
2847
  }
2848
+ // Server-side fallback marker: the AI SDK has no content primitive for
2849
+ // a model hop, so drop it. The hop is still observable via
2850
+ // usage.iterations.
2851
+ case "fallback": {
2852
+ break;
2853
+ }
2781
2854
  }
2782
2855
  }
2783
2856
  let inputTokens;
2784
2857
  let outputTokens;
2785
- if (response.usage.iterations && response.usage.iterations.length > 0) {
2858
+ const servedByFallback = (_b = response.usage.iterations) == null ? void 0 : _b.some(
2859
+ (iter) => iter.type === "fallback_message"
2860
+ );
2861
+ if (response.usage.iterations && response.usage.iterations.length > 0 && !servedByFallback) {
2786
2862
  const totals = response.usage.iterations.reduce(
2787
2863
  (acc, iter) => ({
2788
2864
  input: acc.input + iter.input_tokens,
@@ -2796,6 +2872,7 @@ var AnthropicMessagesLanguageModel = class {
2796
2872
  inputTokens = response.usage.input_tokens;
2797
2873
  outputTokens = response.usage.output_tokens;
2798
2874
  }
2875
+ const stopDetails = mapAnthropicStopDetails(response.stop_details);
2799
2876
  return {
2800
2877
  content,
2801
2878
  finishReason: mapAnthropicStopReason({
@@ -2806,12 +2883,12 @@ var AnthropicMessagesLanguageModel = class {
2806
2883
  inputTokens,
2807
2884
  outputTokens,
2808
2885
  totalTokens: inputTokens + outputTokens,
2809
- cachedInputTokens: (_b = response.usage.cache_read_input_tokens) != null ? _b : void 0
2886
+ cachedInputTokens: (_c = response.usage.cache_read_input_tokens) != null ? _c : void 0
2810
2887
  },
2811
2888
  request: { body: args },
2812
2889
  response: {
2813
- id: (_c = response.id) != null ? _c : void 0,
2814
- modelId: (_d = response.model) != null ? _d : void 0,
2890
+ id: (_d = response.id) != null ? _d : void 0,
2891
+ modelId: (_e = response.model) != null ? _e : void 0,
2815
2892
  headers: responseHeaders,
2816
2893
  body: rawResponse
2817
2894
  },
@@ -2819,21 +2896,23 @@ var AnthropicMessagesLanguageModel = class {
2819
2896
  providerMetadata: {
2820
2897
  anthropic: {
2821
2898
  usage: response.usage,
2822
- cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null,
2823
- stopSequence: (_f = response.stop_sequence) != null ? _f : null,
2899
+ cacheCreationInputTokens: (_f = response.usage.cache_creation_input_tokens) != null ? _f : null,
2900
+ stopSequence: (_g = response.stop_sequence) != null ? _g : null,
2901
+ ...stopDetails != null ? { stopDetails } : {},
2824
2902
  iterations: response.usage.iterations ? response.usage.iterations.map((iter) => ({
2825
2903
  type: iter.type,
2904
+ ...iter.model != null ? { model: iter.model } : {},
2826
2905
  inputTokens: iter.input_tokens,
2827
2906
  outputTokens: iter.output_tokens
2828
2907
  })) : null,
2829
2908
  container: response.container ? {
2830
2909
  expiresAt: response.container.expires_at,
2831
2910
  id: response.container.id,
2832
- skills: (_h = (_g = response.container.skills) == null ? void 0 : _g.map((skill) => ({
2911
+ skills: (_i = (_h = response.container.skills) == null ? void 0 : _h.map((skill) => ({
2833
2912
  type: skill.type,
2834
2913
  skillId: skill.skill_id,
2835
2914
  version: skill.version
2836
- }))) != null ? _h : null
2915
+ }))) != null ? _i : null
2837
2916
  } : null,
2838
2917
  contextManagement: response.context_management ? {
2839
2918
  appliedEdits: response.context_management.applied_edits.map(
@@ -2894,6 +2973,7 @@ var AnthropicMessagesLanguageModel = class {
2894
2973
  let rawUsage = void 0;
2895
2974
  let cacheCreationInputTokens = null;
2896
2975
  let stopSequence = null;
2976
+ let stopDetails = void 0;
2897
2977
  let container = null;
2898
2978
  let iterations = null;
2899
2979
  let contextManagement = null;
@@ -2905,7 +2985,7 @@ var AnthropicMessagesLanguageModel = class {
2905
2985
  controller.enqueue({ type: "stream-start", warnings });
2906
2986
  },
2907
2987
  transform(chunk, controller) {
2908
- var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
2988
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2909
2989
  if (options.includeRawChunks) {
2910
2990
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2911
2991
  }
@@ -2920,6 +3000,9 @@ var AnthropicMessagesLanguageModel = class {
2920
3000
  }
2921
3001
  case "content_block_start": {
2922
3002
  const contentBlockType = value.content_block.type;
3003
+ if (contentBlockType === "fallback") {
3004
+ return;
3005
+ }
2923
3006
  blockType = contentBlockType;
2924
3007
  switch (contentBlockType) {
2925
3008
  case "text": {
@@ -3312,7 +3395,10 @@ var AnthropicMessagesLanguageModel = class {
3312
3395
  if (value.usage.iterations != null) {
3313
3396
  iterations = value.usage.iterations;
3314
3397
  }
3315
- if (value.usage.iterations && value.usage.iterations.length > 0) {
3398
+ const servedByFallback = (_f = value.usage.iterations) == null ? void 0 : _f.some(
3399
+ (iter) => iter.type === "fallback_message"
3400
+ );
3401
+ if (value.usage.iterations && value.usage.iterations.length > 0 && !servedByFallback) {
3316
3402
  const totals = value.usage.iterations.reduce(
3317
3403
  (acc, iter) => ({
3318
3404
  input: acc.input + iter.input_tokens,
@@ -3328,20 +3414,21 @@ var AnthropicMessagesLanguageModel = class {
3328
3414
  }
3329
3415
  usage.outputTokens = value.usage.output_tokens;
3330
3416
  }
3331
- usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = usage.outputTokens) != null ? _g : 0);
3417
+ usage.totalTokens = ((_g = usage.inputTokens) != null ? _g : 0) + ((_h = usage.outputTokens) != null ? _h : 0);
3332
3418
  finishReason = mapAnthropicStopReason({
3333
3419
  finishReason: value.delta.stop_reason,
3334
3420
  isJsonResponseFromTool: usesJsonResponseTool
3335
3421
  });
3336
- stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
3422
+ stopDetails = mapAnthropicStopDetails(value.delta.stop_details);
3423
+ stopSequence = (_i = value.delta.stop_sequence) != null ? _i : null;
3337
3424
  container = value.delta.container != null ? {
3338
3425
  expiresAt: value.delta.container.expires_at,
3339
3426
  id: value.delta.container.id,
3340
- skills: (_j = (_i = value.delta.container.skills) == null ? void 0 : _i.map((skill) => ({
3427
+ skills: (_k = (_j = value.delta.container.skills) == null ? void 0 : _j.map((skill) => ({
3341
3428
  type: skill.type,
3342
3429
  skillId: skill.skill_id,
3343
3430
  version: skill.version
3344
- }))) != null ? _j : null
3431
+ }))) != null ? _k : null
3345
3432
  } : null;
3346
3433
  if (value.context_management != null) {
3347
3434
  contextManagement = {
@@ -3386,8 +3473,10 @@ var AnthropicMessagesLanguageModel = class {
3386
3473
  usage: rawUsage != null ? rawUsage : null,
3387
3474
  cacheCreationInputTokens,
3388
3475
  stopSequence,
3476
+ ...stopDetails != null ? { stopDetails } : {},
3389
3477
  iterations: iterations ? iterations.map((iter) => ({
3390
3478
  type: iter.type,
3479
+ ...iter.model != null ? { model: iter.model } : {},
3391
3480
  inputTokens: iter.input_tokens,
3392
3481
  outputTokens: iter.output_tokens
3393
3482
  })) : null,
@@ -3443,7 +3532,7 @@ var AnthropicMessagesLanguageModel = class {
3443
3532
  }
3444
3533
  };
3445
3534
  function getModelCapabilities(modelId) {
3446
- if (modelId.includes("claude-opus-4-7")) {
3535
+ if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5")) {
3447
3536
  return {
3448
3537
  maxOutputTokens: 128e3,
3449
3538
  supportsStructuredOutput: true,
@@ -3508,6 +3597,17 @@ function getModelCapabilities(modelId) {
3508
3597
  };
3509
3598
  }
3510
3599
  }
3600
+ function mapAnthropicStopDetails(stopDetails) {
3601
+ if (stopDetails == null) {
3602
+ return void 0;
3603
+ }
3604
+ return {
3605
+ type: stopDetails.type,
3606
+ ...stopDetails.category != null ? { category: stopDetails.category } : {},
3607
+ ...stopDetails.explanation != null ? { explanation: stopDetails.explanation } : {},
3608
+ ...stopDetails.recommended_model != null ? { recommendedModel: stopDetails.recommended_model } : {}
3609
+ };
3610
+ }
3511
3611
 
3512
3612
  // src/tool/bash_20241022.ts
3513
3613
  var import_provider_utils11 = require("@ai-sdk/provider-utils");