@ai-sdk/anthropic 2.0.104 → 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.
@@ -673,9 +673,10 @@ var anthropicSystemMessageProviderOptions = import_v43.z.object({
673
673
  */
674
674
  clearAt: import_v43.z.literal("next_user_message").optional(),
675
675
  /**
676
- * Overrides the effort for the turn following this mid-conversation system
677
- * message. The required `mid-conversation-output-config-2026-07-01` beta is added
678
- * automatically.
676
+ * Sets the model effort from the next user turn until a later message
677
+ * changes it. An effort-only system message with empty content can appear
678
+ * first. The required `mid-conversation-output-config-2026-07-01` beta is
679
+ * added automatically.
679
680
  */
680
681
  effort: import_v43.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
681
682
  /**
@@ -1639,7 +1640,7 @@ async function convertToAnthropicMessagesPrompt({
1639
1640
  cacheControlValidator,
1640
1641
  toolsetNames = {}
1641
1642
  }) {
1642
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1643
+ var _a, _b, _c, _d, _e, _f, _g;
1643
1644
  const betas = /* @__PURE__ */ new Set();
1644
1645
  const blocks = groupIntoBlocks(prompt);
1645
1646
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -1671,10 +1672,9 @@ async function convertToAnthropicMessagesPrompt({
1671
1672
  const type = block.type;
1672
1673
  switch (type) {
1673
1674
  case "system": {
1674
- const content = [];
1675
+ const systemMessages = [];
1675
1676
  let toolChangeCount = 0;
1676
- let clearAt = void 0;
1677
- let effort = void 0;
1677
+ let hasMidConversationOptions = false;
1678
1678
  for (const { content: text, providerOptions } of block.messages) {
1679
1679
  const systemMessageOptions = await (0, import_provider_utils10.parseProviderOptions)({
1680
1680
  provider: "anthropic",
@@ -1682,8 +1682,9 @@ async function convertToAnthropicMessagesPrompt({
1682
1682
  schema: anthropicSystemMessageProviderOptions
1683
1683
  });
1684
1684
  const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
1685
- clearAt = (_b = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) != null ? _b : clearAt;
1686
- effort = (_c = systemMessageOptions == null ? void 0 : systemMessageOptions.effort) != null ? _c : effort;
1685
+ const clearAt = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt;
1686
+ const effort = systemMessageOptions == null ? void 0 : systemMessageOptions.effort;
1687
+ const content = [];
1687
1688
  if (text !== "" || toolChanges.length === 0 && (systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) == null && (systemMessageOptions == null ? void 0 : systemMessageOptions.effort) == null) {
1688
1689
  content.push({
1689
1690
  type: "text",
@@ -1704,33 +1705,47 @@ async function convertToAnthropicMessagesPrompt({
1704
1705
  }
1705
1706
  });
1706
1707
  }
1708
+ hasMidConversationOptions || (hasMidConversationOptions = clearAt != null || effort != null);
1709
+ systemMessages.push({
1710
+ role: "system",
1711
+ content,
1712
+ ...clearAt != null && { clear_at: clearAt },
1713
+ ...effort != null && { output_config: { effort } }
1714
+ });
1707
1715
  }
1708
- const hasMidConversationOptions = toolChangeCount > 0 || clearAt != null || effort != null;
1709
- if (i === 0 || system == null && !hasMidConversationOptions) {
1710
- if (hasMidConversationOptions) {
1716
+ if (i === 0 || system == null && toolChangeCount === 0 && !hasMidConversationOptions) {
1717
+ if (toolChangeCount > 0) {
1711
1718
  warnings.push({
1712
1719
  type: "other",
1713
- message: "mid-conversation Anthropic system message options on the initial system message are not supported. The options have been ignored."
1720
+ 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."
1714
1721
  });
1715
1722
  }
1716
- system = content.filter(
1717
- (part) => part.type === "text"
1723
+ for (const message of systemMessages) {
1724
+ if (message.content.length === 0 && message.clear_at == null && message.output_config != null) {
1725
+ messages.push(message);
1726
+ betas.add("mid-conversation-output-config-2026-07-01");
1727
+ } else if (message.clear_at != null || message.output_config != null) {
1728
+ warnings.push({
1729
+ type: "other",
1730
+ 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."
1731
+ });
1732
+ }
1733
+ }
1734
+ system = systemMessages.flatMap(
1735
+ (message) => message.content.filter(
1736
+ (part) => part.type === "text"
1737
+ )
1718
1738
  );
1719
1739
  } else {
1720
- messages.push({
1721
- role: "system",
1722
- content,
1723
- ...clearAt != null && { clear_at: clearAt },
1724
- ...effort != null && { output_config: { effort } }
1725
- });
1740
+ messages.push(...systemMessages);
1726
1741
  betas.add("mid-conversation-system-2026-04-07");
1727
1742
  if (toolChangeCount > 0) {
1728
1743
  betas.add("mid-conversation-tool-changes-2026-07-01");
1729
1744
  }
1730
- if (clearAt != null) {
1745
+ if (systemMessages.some((message) => message.clear_at != null)) {
1731
1746
  betas.add("mid-conversation-system-clear-at-2026-08-21");
1732
1747
  }
1733
- if (effort != null) {
1748
+ if (systemMessages.some((message) => message.output_config != null)) {
1734
1749
  betas.add("mid-conversation-output-config-2026-07-01");
1735
1750
  }
1736
1751
  }
@@ -1745,10 +1760,10 @@ async function convertToAnthropicMessagesPrompt({
1745
1760
  for (let j = 0; j < content.length; j++) {
1746
1761
  const part = content[j];
1747
1762
  const isLastPart = j === content.length - 1;
1748
- const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
1763
+ const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
1749
1764
  type: "user message part",
1750
1765
  canCache: true
1751
- })) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
1766
+ })) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
1752
1767
  type: "user message",
1753
1768
  canCache: true
1754
1769
  }) : void 0;
@@ -1793,7 +1808,7 @@ async function convertToAnthropicMessagesPrompt({
1793
1808
  media_type: "application/pdf",
1794
1809
  data: (0, import_provider_utils10.convertToBase64)(part.data)
1795
1810
  },
1796
- title: (_e = metadata.title) != null ? _e : part.filename,
1811
+ title: (_c = metadata.title) != null ? _c : part.filename,
1797
1812
  ...metadata.context && { context: metadata.context },
1798
1813
  ...enableCitations && {
1799
1814
  citations: { enabled: true }
@@ -1817,7 +1832,7 @@ async function convertToAnthropicMessagesPrompt({
1817
1832
  media_type: "text/plain",
1818
1833
  data: convertToString(part.data)
1819
1834
  },
1820
- title: (_f = metadata.title) != null ? _f : part.filename,
1835
+ title: (_d = metadata.title) != null ? _d : part.filename,
1821
1836
  ...metadata.context && { context: metadata.context },
1822
1837
  ...enableCitations && {
1823
1838
  citations: { enabled: true }
@@ -1839,10 +1854,10 @@ async function convertToAnthropicMessagesPrompt({
1839
1854
  for (let i2 = 0; i2 < content.length; i2++) {
1840
1855
  const part = content[i2];
1841
1856
  const isLastPart = i2 === content.length - 1;
1842
- const cacheControl = (_g = validator.getCacheControl(part.providerOptions, {
1857
+ const cacheControl = (_e = validator.getCacheControl(part.providerOptions, {
1843
1858
  type: "tool result part",
1844
1859
  canCache: true
1845
- })) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
1860
+ })) != null ? _e : isLastPart ? validator.getCacheControl(message.providerOptions, {
1846
1861
  type: "tool result message",
1847
1862
  canCache: true
1848
1863
  }) : void 0;
@@ -1930,16 +1945,16 @@ async function convertToAnthropicMessagesPrompt({
1930
1945
  for (let k = 0; k < content.length; k++) {
1931
1946
  const part = content[k];
1932
1947
  const isLastContentPart = k === content.length - 1;
1933
- const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
1948
+ const cacheControl = (_f = validator.getCacheControl(part.providerOptions, {
1934
1949
  type: "assistant message part",
1935
1950
  canCache: true
1936
- })) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1951
+ })) != null ? _f : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1937
1952
  type: "assistant message",
1938
1953
  canCache: true
1939
1954
  }) : void 0;
1940
1955
  switch (part.type) {
1941
1956
  case "text": {
1942
- const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
1957
+ const textMetadata = (_g = part.providerOptions) == null ? void 0 : _g.anthropic;
1943
1958
  if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
1944
1959
  anthropicContent.push({
1945
1960
  type: "compaction",