@ai-sdk/anthropic 2.0.105 → 2.0.106

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.
@@ -661,9 +661,10 @@ var anthropicSystemMessageProviderOptions = z3.object({
661
661
  */
662
662
  clearAt: z3.literal("next_user_message").optional(),
663
663
  /**
664
- * Overrides the effort for the turn following this mid-conversation system
665
- * message. The required `mid-conversation-output-config-2026-07-01` beta is added
666
- * automatically.
664
+ * Sets the model effort from the next user turn until a later message
665
+ * changes it. An effort-only system message with empty content can appear
666
+ * first. The required `mid-conversation-output-config-2026-07-01` beta is
667
+ * added automatically.
667
668
  */
668
669
  effort: z3.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
669
670
  /**
@@ -1659,7 +1660,7 @@ async function convertToAnthropicMessagesPrompt({
1659
1660
  cacheControlValidator,
1660
1661
  toolsetNames = {}
1661
1662
  }) {
1662
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1663
+ var _a, _b, _c, _d, _e, _f, _g;
1663
1664
  const betas = /* @__PURE__ */ new Set();
1664
1665
  const blocks = groupIntoBlocks(prompt);
1665
1666
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -1691,10 +1692,9 @@ async function convertToAnthropicMessagesPrompt({
1691
1692
  const type = block.type;
1692
1693
  switch (type) {
1693
1694
  case "system": {
1694
- const content = [];
1695
+ const systemMessages = [];
1695
1696
  let toolChangeCount = 0;
1696
- let clearAt = void 0;
1697
- let effort = void 0;
1697
+ let hasMidConversationOptions = false;
1698
1698
  for (const { content: text, providerOptions } of block.messages) {
1699
1699
  const systemMessageOptions = await parseProviderOptions({
1700
1700
  provider: "anthropic",
@@ -1702,8 +1702,9 @@ async function convertToAnthropicMessagesPrompt({
1702
1702
  schema: anthropicSystemMessageProviderOptions
1703
1703
  });
1704
1704
  const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
1705
- clearAt = (_b = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) != null ? _b : clearAt;
1706
- effort = (_c = systemMessageOptions == null ? void 0 : systemMessageOptions.effort) != null ? _c : effort;
1705
+ const clearAt = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt;
1706
+ const effort = systemMessageOptions == null ? void 0 : systemMessageOptions.effort;
1707
+ const content = [];
1707
1708
  if (text !== "" || toolChanges.length === 0 && (systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) == null && (systemMessageOptions == null ? void 0 : systemMessageOptions.effort) == null) {
1708
1709
  content.push({
1709
1710
  type: "text",
@@ -1724,33 +1725,47 @@ async function convertToAnthropicMessagesPrompt({
1724
1725
  }
1725
1726
  });
1726
1727
  }
1728
+ hasMidConversationOptions || (hasMidConversationOptions = clearAt != null || effort != null);
1729
+ systemMessages.push({
1730
+ role: "system",
1731
+ content,
1732
+ ...clearAt != null && { clear_at: clearAt },
1733
+ ...effort != null && { output_config: { effort } }
1734
+ });
1727
1735
  }
1728
- const hasMidConversationOptions = toolChangeCount > 0 || clearAt != null || effort != null;
1729
- if (i === 0 || system == null && !hasMidConversationOptions) {
1730
- if (hasMidConversationOptions) {
1736
+ if (i === 0 || system == null && toolChangeCount === 0 && !hasMidConversationOptions) {
1737
+ if (toolChangeCount > 0) {
1731
1738
  warnings.push({
1732
1739
  type: "other",
1733
- message: "mid-conversation Anthropic system message options on the initial system message are not supported. The options have been ignored."
1740
+ 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."
1734
1741
  });
1735
1742
  }
1736
- system = content.filter(
1737
- (part) => part.type === "text"
1743
+ for (const message of systemMessages) {
1744
+ if (message.content.length === 0 && message.clear_at == null && message.output_config != null) {
1745
+ messages.push(message);
1746
+ betas.add("mid-conversation-output-config-2026-07-01");
1747
+ } else if (message.clear_at != null || message.output_config != null) {
1748
+ warnings.push({
1749
+ type: "other",
1750
+ message: "clearAt and effort on this initial system message are not supported by Anthropic. Use a separate effort-only system message with empty content to set effort. These options have been ignored."
1751
+ });
1752
+ }
1753
+ }
1754
+ system = systemMessages.flatMap(
1755
+ (message) => message.content.filter(
1756
+ (part) => part.type === "text"
1757
+ )
1738
1758
  );
1739
1759
  } else {
1740
- messages.push({
1741
- role: "system",
1742
- content,
1743
- ...clearAt != null && { clear_at: clearAt },
1744
- ...effort != null && { output_config: { effort } }
1745
- });
1760
+ messages.push(...systemMessages);
1746
1761
  betas.add("mid-conversation-system-2026-04-07");
1747
1762
  if (toolChangeCount > 0) {
1748
1763
  betas.add("mid-conversation-tool-changes-2026-07-01");
1749
1764
  }
1750
- if (clearAt != null) {
1765
+ if (systemMessages.some((message) => message.clear_at != null)) {
1751
1766
  betas.add("mid-conversation-system-clear-at-2026-08-21");
1752
1767
  }
1753
- if (effort != null) {
1768
+ if (systemMessages.some((message) => message.output_config != null)) {
1754
1769
  betas.add("mid-conversation-output-config-2026-07-01");
1755
1770
  }
1756
1771
  }
@@ -1765,10 +1780,10 @@ async function convertToAnthropicMessagesPrompt({
1765
1780
  for (let j = 0; j < content.length; j++) {
1766
1781
  const part = content[j];
1767
1782
  const isLastPart = j === content.length - 1;
1768
- const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
1783
+ const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
1769
1784
  type: "user message part",
1770
1785
  canCache: true
1771
- })) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
1786
+ })) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
1772
1787
  type: "user message",
1773
1788
  canCache: true
1774
1789
  }) : void 0;
@@ -1813,7 +1828,7 @@ async function convertToAnthropicMessagesPrompt({
1813
1828
  media_type: "application/pdf",
1814
1829
  data: convertToBase64(part.data)
1815
1830
  },
1816
- title: (_e = metadata.title) != null ? _e : part.filename,
1831
+ title: (_c = metadata.title) != null ? _c : part.filename,
1817
1832
  ...metadata.context && { context: metadata.context },
1818
1833
  ...enableCitations && {
1819
1834
  citations: { enabled: true }
@@ -1837,7 +1852,7 @@ async function convertToAnthropicMessagesPrompt({
1837
1852
  media_type: "text/plain",
1838
1853
  data: convertToString(part.data)
1839
1854
  },
1840
- title: (_f = metadata.title) != null ? _f : part.filename,
1855
+ title: (_d = metadata.title) != null ? _d : part.filename,
1841
1856
  ...metadata.context && { context: metadata.context },
1842
1857
  ...enableCitations && {
1843
1858
  citations: { enabled: true }
@@ -1859,10 +1874,10 @@ async function convertToAnthropicMessagesPrompt({
1859
1874
  for (let i2 = 0; i2 < content.length; i2++) {
1860
1875
  const part = content[i2];
1861
1876
  const isLastPart = i2 === content.length - 1;
1862
- const cacheControl = (_g = validator.getCacheControl(part.providerOptions, {
1877
+ const cacheControl = (_e = validator.getCacheControl(part.providerOptions, {
1863
1878
  type: "tool result part",
1864
1879
  canCache: true
1865
- })) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
1880
+ })) != null ? _e : isLastPart ? validator.getCacheControl(message.providerOptions, {
1866
1881
  type: "tool result message",
1867
1882
  canCache: true
1868
1883
  }) : void 0;
@@ -1950,16 +1965,16 @@ async function convertToAnthropicMessagesPrompt({
1950
1965
  for (let k = 0; k < content.length; k++) {
1951
1966
  const part = content[k];
1952
1967
  const isLastContentPart = k === content.length - 1;
1953
- const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
1968
+ const cacheControl = (_f = validator.getCacheControl(part.providerOptions, {
1954
1969
  type: "assistant message part",
1955
1970
  canCache: true
1956
- })) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1971
+ })) != null ? _f : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1957
1972
  type: "assistant message",
1958
1973
  canCache: true
1959
1974
  }) : void 0;
1960
1975
  switch (part.type) {
1961
1976
  case "text": {
1962
- const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
1977
+ const textMetadata = (_g = part.providerOptions) == null ? void 0 : _g.anthropic;
1963
1978
  if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
1964
1979
  anthropicContent.push({
1965
1980
  type: "compaction",