@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.
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.105" : "0.0.0-test";
14
+ var VERSION = true ? "2.0.106" : "0.0.0-test";
15
15
 
16
16
  // src/anthropic-messages-language-model.ts
17
17
  import {
@@ -676,9 +676,10 @@ var anthropicSystemMessageProviderOptions = z3.object({
676
676
  */
677
677
  clearAt: z3.literal("next_user_message").optional(),
678
678
  /**
679
- * Overrides the effort for the turn following this mid-conversation system
680
- * message. The required `mid-conversation-output-config-2026-07-01` beta is added
681
- * automatically.
679
+ * Sets the model effort from the next user turn until a later message
680
+ * changes it. An effort-only system message with empty content can appear
681
+ * first. The required `mid-conversation-output-config-2026-07-01` beta is
682
+ * added automatically.
682
683
  */
683
684
  effort: z3.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
684
685
  /**
@@ -1674,7 +1675,7 @@ async function convertToAnthropicMessagesPrompt({
1674
1675
  cacheControlValidator,
1675
1676
  toolsetNames = {}
1676
1677
  }) {
1677
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1678
+ var _a, _b, _c, _d, _e, _f, _g;
1678
1679
  const betas = /* @__PURE__ */ new Set();
1679
1680
  const blocks = groupIntoBlocks(prompt);
1680
1681
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -1706,10 +1707,9 @@ async function convertToAnthropicMessagesPrompt({
1706
1707
  const type = block.type;
1707
1708
  switch (type) {
1708
1709
  case "system": {
1709
- const content = [];
1710
+ const systemMessages = [];
1710
1711
  let toolChangeCount = 0;
1711
- let clearAt = void 0;
1712
- let effort = void 0;
1712
+ let hasMidConversationOptions = false;
1713
1713
  for (const { content: text, providerOptions } of block.messages) {
1714
1714
  const systemMessageOptions = await parseProviderOptions({
1715
1715
  provider: "anthropic",
@@ -1717,8 +1717,9 @@ async function convertToAnthropicMessagesPrompt({
1717
1717
  schema: anthropicSystemMessageProviderOptions
1718
1718
  });
1719
1719
  const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
1720
- clearAt = (_b = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) != null ? _b : clearAt;
1721
- effort = (_c = systemMessageOptions == null ? void 0 : systemMessageOptions.effort) != null ? _c : effort;
1720
+ const clearAt = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt;
1721
+ const effort = systemMessageOptions == null ? void 0 : systemMessageOptions.effort;
1722
+ const content = [];
1722
1723
  if (text !== "" || toolChanges.length === 0 && (systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) == null && (systemMessageOptions == null ? void 0 : systemMessageOptions.effort) == null) {
1723
1724
  content.push({
1724
1725
  type: "text",
@@ -1739,33 +1740,47 @@ async function convertToAnthropicMessagesPrompt({
1739
1740
  }
1740
1741
  });
1741
1742
  }
1743
+ hasMidConversationOptions || (hasMidConversationOptions = clearAt != null || effort != null);
1744
+ systemMessages.push({
1745
+ role: "system",
1746
+ content,
1747
+ ...clearAt != null && { clear_at: clearAt },
1748
+ ...effort != null && { output_config: { effort } }
1749
+ });
1742
1750
  }
1743
- const hasMidConversationOptions = toolChangeCount > 0 || clearAt != null || effort != null;
1744
- if (i === 0 || system == null && !hasMidConversationOptions) {
1745
- if (hasMidConversationOptions) {
1751
+ if (i === 0 || system == null && toolChangeCount === 0 && !hasMidConversationOptions) {
1752
+ if (toolChangeCount > 0) {
1746
1753
  warnings.push({
1747
1754
  type: "other",
1748
- message: "mid-conversation Anthropic system message options on the initial system message are not supported. The options have been ignored."
1755
+ 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."
1749
1756
  });
1750
1757
  }
1751
- system = content.filter(
1752
- (part) => part.type === "text"
1758
+ for (const message of systemMessages) {
1759
+ if (message.content.length === 0 && message.clear_at == null && message.output_config != null) {
1760
+ messages.push(message);
1761
+ betas.add("mid-conversation-output-config-2026-07-01");
1762
+ } else if (message.clear_at != null || message.output_config != null) {
1763
+ warnings.push({
1764
+ type: "other",
1765
+ 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."
1766
+ });
1767
+ }
1768
+ }
1769
+ system = systemMessages.flatMap(
1770
+ (message) => message.content.filter(
1771
+ (part) => part.type === "text"
1772
+ )
1753
1773
  );
1754
1774
  } else {
1755
- messages.push({
1756
- role: "system",
1757
- content,
1758
- ...clearAt != null && { clear_at: clearAt },
1759
- ...effort != null && { output_config: { effort } }
1760
- });
1775
+ messages.push(...systemMessages);
1761
1776
  betas.add("mid-conversation-system-2026-04-07");
1762
1777
  if (toolChangeCount > 0) {
1763
1778
  betas.add("mid-conversation-tool-changes-2026-07-01");
1764
1779
  }
1765
- if (clearAt != null) {
1780
+ if (systemMessages.some((message) => message.clear_at != null)) {
1766
1781
  betas.add("mid-conversation-system-clear-at-2026-08-21");
1767
1782
  }
1768
- if (effort != null) {
1783
+ if (systemMessages.some((message) => message.output_config != null)) {
1769
1784
  betas.add("mid-conversation-output-config-2026-07-01");
1770
1785
  }
1771
1786
  }
@@ -1780,10 +1795,10 @@ async function convertToAnthropicMessagesPrompt({
1780
1795
  for (let j = 0; j < content.length; j++) {
1781
1796
  const part = content[j];
1782
1797
  const isLastPart = j === content.length - 1;
1783
- const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
1798
+ const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
1784
1799
  type: "user message part",
1785
1800
  canCache: true
1786
- })) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
1801
+ })) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
1787
1802
  type: "user message",
1788
1803
  canCache: true
1789
1804
  }) : void 0;
@@ -1828,7 +1843,7 @@ async function convertToAnthropicMessagesPrompt({
1828
1843
  media_type: "application/pdf",
1829
1844
  data: convertToBase64(part.data)
1830
1845
  },
1831
- title: (_e = metadata.title) != null ? _e : part.filename,
1846
+ title: (_c = metadata.title) != null ? _c : part.filename,
1832
1847
  ...metadata.context && { context: metadata.context },
1833
1848
  ...enableCitations && {
1834
1849
  citations: { enabled: true }
@@ -1852,7 +1867,7 @@ async function convertToAnthropicMessagesPrompt({
1852
1867
  media_type: "text/plain",
1853
1868
  data: convertToString(part.data)
1854
1869
  },
1855
- title: (_f = metadata.title) != null ? _f : part.filename,
1870
+ title: (_d = metadata.title) != null ? _d : part.filename,
1856
1871
  ...metadata.context && { context: metadata.context },
1857
1872
  ...enableCitations && {
1858
1873
  citations: { enabled: true }
@@ -1874,10 +1889,10 @@ async function convertToAnthropicMessagesPrompt({
1874
1889
  for (let i2 = 0; i2 < content.length; i2++) {
1875
1890
  const part = content[i2];
1876
1891
  const isLastPart = i2 === content.length - 1;
1877
- const cacheControl = (_g = validator.getCacheControl(part.providerOptions, {
1892
+ const cacheControl = (_e = validator.getCacheControl(part.providerOptions, {
1878
1893
  type: "tool result part",
1879
1894
  canCache: true
1880
- })) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
1895
+ })) != null ? _e : isLastPart ? validator.getCacheControl(message.providerOptions, {
1881
1896
  type: "tool result message",
1882
1897
  canCache: true
1883
1898
  }) : void 0;
@@ -1965,16 +1980,16 @@ async function convertToAnthropicMessagesPrompt({
1965
1980
  for (let k = 0; k < content.length; k++) {
1966
1981
  const part = content[k];
1967
1982
  const isLastContentPart = k === content.length - 1;
1968
- const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
1983
+ const cacheControl = (_f = validator.getCacheControl(part.providerOptions, {
1969
1984
  type: "assistant message part",
1970
1985
  canCache: true
1971
- })) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1986
+ })) != null ? _f : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1972
1987
  type: "assistant message",
1973
1988
  canCache: true
1974
1989
  }) : void 0;
1975
1990
  switch (part.type) {
1976
1991
  case "text": {
1977
- const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
1992
+ const textMetadata = (_g = part.providerOptions) == null ? void 0 : _g.anthropic;
1978
1993
  if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
1979
1994
  anthropicContent.push({
1980
1995
  type: "compaction",