@ai-sdk/anthropic 2.0.100 → 2.0.102

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/dist/index.mjs CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  } from "@ai-sdk/provider-utils";
12
12
 
13
13
  // src/version.ts
14
- var VERSION = true ? "2.0.100" : "0.0.0-test";
14
+ var VERSION = true ? "2.0.102" : "0.0.0-test";
15
15
 
16
16
  // src/anthropic-messages-language-model.ts
17
17
  import {
@@ -664,6 +664,19 @@ var anthropicFilePartProviderOptions = z3.object({
664
664
  context: z3.string().optional()
665
665
  });
666
666
  var anthropicSystemMessageProviderOptions = z3.object({
667
+ /**
668
+ * Controls when a mid-conversation system message is cleared.
669
+ *
670
+ * The value is forwarded to Anthropic as `clear_at`. The required
671
+ * `mid-conversation-system-clear-at-2026-08-21` beta is added automatically.
672
+ */
673
+ clearAt: z3.literal("next_user_message").optional(),
674
+ /**
675
+ * Overrides the effort for the turn following this mid-conversation system
676
+ * message. The required `mid-conversation-effort-2026-08-01` beta is added
677
+ * automatically.
678
+ */
679
+ effort: z3.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
667
680
  /**
668
681
  * Mid-conversation tool changes. Adds or removes tools from the
669
682
  * conversation's tool set between turns without invalidating the prompt
@@ -691,6 +704,14 @@ var anthropicSystemMessageProviderOptions = z3.object({
691
704
  ])
692
705
  ).optional()
693
706
  });
707
+ var anthropicThinkingBlockBinding = z3.object({
708
+ /**
709
+ * Controls behavior when a replayed thinking block does not match its
710
+ * conversation prefix. The `drop_block` behavior drops the mismatched block
711
+ * instead of returning an invalid signature error.
712
+ */
713
+ prefixMismatchBehavior: z3.literal("drop_block")
714
+ });
694
715
  var anthropicProviderOptions = z3.object({
695
716
  /**
696
717
  * Whether to send reasoning to the model.
@@ -702,8 +723,8 @@ var anthropicProviderOptions = z3.object({
702
723
  * Determines how structured outputs are generated.
703
724
  *
704
725
  * - `outputFormat`: Use the `output_format` parameter to specify the structured output format.
705
- * - `jsonTool`: Use a special JSON response tool to specify the structured output format (default).
706
- * - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool'.
726
+ * - `jsonTool`: Use a special JSON response tool to specify the structured output format (default for most models).
727
+ * - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool' (default for Fable 5.1).
707
728
  */
708
729
  structuredOutputMode: z3.enum(["outputFormat", "jsonTool", "auto"]).optional(),
709
730
  /**
@@ -712,7 +733,7 @@ var anthropicProviderOptions = z3.object({
712
733
  * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
713
734
  * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
714
735
  */
715
- thinking: z3.discriminatedUnion("type", [
736
+ thinking: z3.union([
716
737
  z3.object({
717
738
  /** for Sonnet 4.6, Opus 4.6, and newer models */
718
739
  type: z3.literal("adaptive"),
@@ -720,16 +741,34 @@ var anthropicProviderOptions = z3.object({
720
741
  * Controls whether thinking content is included in the response.
721
742
  * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
722
743
  * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
744
+ * - `"updates"`: Thinking summaries are emitted between tool calls.
745
+ */
746
+ display: z3.enum(["omitted", "summarized", "updates"]).optional(),
747
+ /**
748
+ * Controls handling for thinking blocks whose conversation prefix no
749
+ * longer matches. Forwarded as `block_binding`.
723
750
  */
724
- display: z3.enum(["omitted", "summarized"]).optional()
751
+ blockBinding: anthropicThinkingBlockBinding.optional()
725
752
  }),
726
753
  z3.object({
727
754
  /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
728
755
  type: z3.literal("enabled"),
729
- budgetTokens: z3.number().optional()
756
+ budgetTokens: z3.number().optional(),
757
+ /**
758
+ * Controls handling for thinking blocks whose conversation prefix no
759
+ * longer matches. Forwarded as `block_binding`.
760
+ */
761
+ blockBinding: anthropicThinkingBlockBinding.optional()
730
762
  }),
731
763
  z3.object({
732
764
  type: z3.literal("disabled")
765
+ }),
766
+ z3.object({
767
+ /**
768
+ * Configure prefix mismatch handling without changing the model's
769
+ * default thinking mode.
770
+ */
771
+ blockBinding: anthropicThinkingBlockBinding
733
772
  })
734
773
  ]).optional(),
735
774
  /**
@@ -1500,7 +1539,7 @@ async function convertToAnthropicMessagesPrompt({
1500
1539
  warnings,
1501
1540
  cacheControlValidator
1502
1541
  }) {
1503
- var _a, _b, _c, _d, _e, _f, _g;
1542
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1504
1543
  const betas = /* @__PURE__ */ new Set();
1505
1544
  const blocks = groupIntoBlocks(prompt);
1506
1545
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -1534,6 +1573,8 @@ async function convertToAnthropicMessagesPrompt({
1534
1573
  case "system": {
1535
1574
  const content = [];
1536
1575
  let toolChangeCount = 0;
1576
+ let clearAt = void 0;
1577
+ let effort = void 0;
1537
1578
  for (const { content: text, providerOptions } of block.messages) {
1538
1579
  const systemMessageOptions = await parseProviderOptions({
1539
1580
  provider: "anthropic",
@@ -1541,7 +1582,9 @@ async function convertToAnthropicMessagesPrompt({
1541
1582
  schema: anthropicSystemMessageProviderOptions
1542
1583
  });
1543
1584
  const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
1544
- if (text !== "" || toolChanges.length === 0) {
1585
+ clearAt = (_b = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) != null ? _b : clearAt;
1586
+ effort = (_c = systemMessageOptions == null ? void 0 : systemMessageOptions.effort) != null ? _c : effort;
1587
+ if (text !== "" || toolChanges.length === 0 && (systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) == null && (systemMessageOptions == null ? void 0 : systemMessageOptions.effort) == null) {
1545
1588
  content.push({
1546
1589
  type: "text",
1547
1590
  text,
@@ -1562,22 +1605,34 @@ async function convertToAnthropicMessagesPrompt({
1562
1605
  });
1563
1606
  }
1564
1607
  }
1565
- if (i === 0 || system == null && toolChangeCount === 0) {
1566
- if (toolChangeCount > 0) {
1608
+ const hasMidConversationOptions = toolChangeCount > 0 || clearAt != null || effort != null;
1609
+ if (i === 0 || system == null && !hasMidConversationOptions) {
1610
+ if (hasMidConversationOptions) {
1567
1611
  warnings.push({
1568
1612
  type: "other",
1569
- message: "tool changes on the initial system message are not supported by Anthropic. Configure the initial tool set via the tools option instead. The tool changes have been ignored."
1613
+ message: "mid-conversation Anthropic system message options on the initial system message are not supported. The options have been ignored."
1570
1614
  });
1571
1615
  }
1572
1616
  system = content.filter(
1573
1617
  (part) => part.type === "text"
1574
1618
  );
1575
1619
  } else {
1576
- messages.push({ role: "system", content });
1620
+ messages.push({
1621
+ role: "system",
1622
+ content,
1623
+ ...clearAt != null && { clear_at: clearAt },
1624
+ ...effort != null && { output_config: { effort } }
1625
+ });
1577
1626
  betas.add("mid-conversation-system-2026-04-07");
1578
1627
  if (toolChangeCount > 0) {
1579
1628
  betas.add("mid-conversation-tool-changes-2026-07-01");
1580
1629
  }
1630
+ if (clearAt != null) {
1631
+ betas.add("mid-conversation-system-clear-at-2026-08-21");
1632
+ }
1633
+ if (effort != null) {
1634
+ betas.add("mid-conversation-effort-2026-08-01");
1635
+ }
1581
1636
  }
1582
1637
  break;
1583
1638
  }
@@ -1590,10 +1645,10 @@ async function convertToAnthropicMessagesPrompt({
1590
1645
  for (let j = 0; j < content.length; j++) {
1591
1646
  const part = content[j];
1592
1647
  const isLastPart = j === content.length - 1;
1593
- const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
1648
+ const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
1594
1649
  type: "user message part",
1595
1650
  canCache: true
1596
- })) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
1651
+ })) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
1597
1652
  type: "user message",
1598
1653
  canCache: true
1599
1654
  }) : void 0;
@@ -1638,7 +1693,7 @@ async function convertToAnthropicMessagesPrompt({
1638
1693
  media_type: "application/pdf",
1639
1694
  data: convertToBase64(part.data)
1640
1695
  },
1641
- title: (_c = metadata.title) != null ? _c : part.filename,
1696
+ title: (_e = metadata.title) != null ? _e : part.filename,
1642
1697
  ...metadata.context && { context: metadata.context },
1643
1698
  ...enableCitations && {
1644
1699
  citations: { enabled: true }
@@ -1662,7 +1717,7 @@ async function convertToAnthropicMessagesPrompt({
1662
1717
  media_type: "text/plain",
1663
1718
  data: convertToString(part.data)
1664
1719
  },
1665
- title: (_d = metadata.title) != null ? _d : part.filename,
1720
+ title: (_f = metadata.title) != null ? _f : part.filename,
1666
1721
  ...metadata.context && { context: metadata.context },
1667
1722
  ...enableCitations && {
1668
1723
  citations: { enabled: true }
@@ -1684,10 +1739,10 @@ async function convertToAnthropicMessagesPrompt({
1684
1739
  for (let i2 = 0; i2 < content.length; i2++) {
1685
1740
  const part = content[i2];
1686
1741
  const isLastPart = i2 === content.length - 1;
1687
- const cacheControl = (_e = validator.getCacheControl(part.providerOptions, {
1742
+ const cacheControl = (_g = validator.getCacheControl(part.providerOptions, {
1688
1743
  type: "tool result part",
1689
1744
  canCache: true
1690
- })) != null ? _e : isLastPart ? validator.getCacheControl(message.providerOptions, {
1745
+ })) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
1691
1746
  type: "tool result message",
1692
1747
  canCache: true
1693
1748
  }) : void 0;
@@ -1769,16 +1824,16 @@ async function convertToAnthropicMessagesPrompt({
1769
1824
  for (let k = 0; k < content.length; k++) {
1770
1825
  const part = content[k];
1771
1826
  const isLastContentPart = k === content.length - 1;
1772
- const cacheControl = (_f = validator.getCacheControl(part.providerOptions, {
1827
+ const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
1773
1828
  type: "assistant message part",
1774
1829
  canCache: true
1775
- })) != null ? _f : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1830
+ })) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1776
1831
  type: "assistant message",
1777
1832
  canCache: true
1778
1833
  }) : void 0;
1779
1834
  switch (part.type) {
1780
1835
  case "text": {
1781
- const textMetadata = (_g = part.providerOptions) == null ? void 0 : _g.anthropic;
1836
+ const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
1782
1837
  if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
1783
1838
  anthropicContent.push({
1784
1839
  type: "compaction",
@@ -2347,7 +2402,7 @@ var AnthropicMessagesLanguageModel = class {
2347
2402
  toolChoice,
2348
2403
  providerOptions
2349
2404
  }) {
2350
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2405
+ var _a, _b, _c, _d, _e;
2351
2406
  const warnings = [];
2352
2407
  if (frequencyPenalty != null) {
2353
2408
  warnings.push({
@@ -2436,7 +2491,7 @@ var AnthropicMessagesLanguageModel = class {
2436
2491
  }
2437
2492
  }
2438
2493
  const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
2439
- const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : "jsonTool";
2494
+ const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : this.modelId.includes("claude-fable-5-1") ? "auto" : "jsonTool";
2440
2495
  const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
2441
2496
  const jsonResponseToolName = getJsonResponseToolName(tools);
2442
2497
  const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
@@ -2459,7 +2514,9 @@ var AnthropicMessagesLanguageModel = class {
2459
2514
  warnings,
2460
2515
  cacheControlValidator
2461
2516
  });
2462
- if (rejectsThinkingDisabledAboveHighEffort && ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
2517
+ const thinkingOptions = anthropicOptions == null ? void 0 : anthropicOptions.thinking;
2518
+ const thinkingType = thinkingOptions != null && "type" in thinkingOptions ? thinkingOptions.type : void 0;
2519
+ if (rejectsThinkingDisabledAboveHighEffort && thinkingType === "disabled" && anthropicOptions != null && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
2463
2520
  warnings.push({
2464
2521
  type: "unsupported-setting",
2465
2522
  setting: "providerOptions.anthropic.effort",
@@ -2467,10 +2524,10 @@ var AnthropicMessagesLanguageModel = class {
2467
2524
  });
2468
2525
  anthropicOptions.effort = "high";
2469
2526
  }
2470
- const thinkingType = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.type;
2471
2527
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
2472
- let thinkingBudget = thinkingType === "enabled" ? (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.budgetTokens : void 0;
2473
- const thinkingDisplay = thinkingType === "adaptive" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.display : void 0;
2528
+ let thinkingBudget = thinkingOptions != null && "budgetTokens" in thinkingOptions ? thinkingOptions.budgetTokens : void 0;
2529
+ const thinkingDisplay = thinkingOptions != null && "display" in thinkingOptions ? thinkingOptions.display : void 0;
2530
+ const thinkingBlockBinding = thinkingOptions != null && "blockBinding" in thinkingOptions ? thinkingOptions.blockBinding : void 0;
2474
2531
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
2475
2532
  const baseArgs = {
2476
2533
  // model id:
@@ -2482,11 +2539,16 @@ var AnthropicMessagesLanguageModel = class {
2482
2539
  top_p: topP,
2483
2540
  stop_sequences: stopSequences,
2484
2541
  // provider specific settings:
2485
- ...isThinking && {
2542
+ ...(isThinking || thinkingBlockBinding != null) && {
2486
2543
  thinking: {
2487
- type: thinkingType,
2544
+ ...thinkingType != null && { type: thinkingType },
2488
2545
  ...thinkingBudget != null && { budget_tokens: thinkingBudget },
2489
- ...thinkingDisplay != null && { display: thinkingDisplay }
2546
+ ...thinkingDisplay != null && { display: thinkingDisplay },
2547
+ ...thinkingBlockBinding != null && {
2548
+ block_binding: {
2549
+ prefix_mismatch_behavior: thinkingBlockBinding.prefixMismatchBehavior
2550
+ }
2551
+ }
2490
2552
  }
2491
2553
  },
2492
2554
  ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
@@ -2523,14 +2585,14 @@ var AnthropicMessagesLanguageModel = class {
2523
2585
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
2524
2586
  cache_control: anthropicOptions.cacheControl
2525
2587
  },
2526
- ...((_g = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _g.userId) != null && {
2588
+ ...((_c = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _c.userId) != null && {
2527
2589
  metadata: { user_id: anthropicOptions.metadata.userId }
2528
2590
  },
2529
2591
  // container with agent skills:
2530
2592
  ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
2531
2593
  container: {
2532
2594
  id: anthropicOptions.container.id,
2533
- skills: (_h = anthropicOptions.container.skills) == null ? void 0 : _h.map((skill) => ({
2595
+ skills: (_d = anthropicOptions.container.skills) == null ? void 0 : _d.map((skill) => ({
2534
2596
  type: skill.type,
2535
2597
  skill_id: skill.skillId,
2536
2598
  version: skill.version
@@ -2656,6 +2718,12 @@ var AnthropicMessagesLanguageModel = class {
2656
2718
  if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
2657
2719
  betas.add("effort-2025-11-24");
2658
2720
  }
2721
+ if (thinkingDisplay === "updates") {
2722
+ betas.add("thinking-display-updates-2026-08-18");
2723
+ }
2724
+ if (thinkingBlockBinding != null) {
2725
+ betas.add("thinking-binding-controls-2026-08-01");
2726
+ }
2659
2727
  if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
2660
2728
  betas.add("task-budgets-2026-03-13");
2661
2729
  }
@@ -2667,7 +2735,7 @@ var AnthropicMessagesLanguageModel = class {
2667
2735
  } else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
2668
2736
  betas.add("server-side-fallback-2026-06-01");
2669
2737
  }
2670
- if (useStructuredOutput) {
2738
+ if (useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
2671
2739
  betas.add("structured-outputs-2025-11-13");
2672
2740
  }
2673
2741
  const contextManagement = anthropicOptions == null ? void 0 : anthropicOptions.contextManagement;
@@ -2707,7 +2775,7 @@ var AnthropicMessagesLanguageModel = class {
2707
2775
  ...betas,
2708
2776
  ...toolsBetas,
2709
2777
  ...userSuppliedBetas,
2710
- ...(_i = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _i : []
2778
+ ...(_e = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _e : []
2711
2779
  ]),
2712
2780
  jsonResponseToolName: jsonResponseTool != null ? jsonResponseToolName : void 0
2713
2781
  };
@@ -3767,7 +3835,7 @@ function getModelCapabilities(modelId) {
3767
3835
  rejectsThinkingDisabledAboveHighEffort: true,
3768
3836
  isKnownModel: true
3769
3837
  };
3770
- } else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
3838
+ } else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5-1") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
3771
3839
  return {
3772
3840
  maxOutputTokens: 128e3,
3773
3841
  supportsStructuredOutput: true,