@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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 2.0.106
4
+
5
+ ### Patch Changes
6
+
7
+ - 214d440: Preserve effort updates on empty system messages at the beginning of a conversation, including consecutive updates.
8
+
3
9
  ## 2.0.105
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
31
31
  var import_provider_utils21 = require("@ai-sdk/provider-utils");
32
32
 
33
33
  // src/version.ts
34
- var VERSION = true ? "2.0.105" : "0.0.0-test";
34
+ var VERSION = true ? "2.0.106" : "0.0.0-test";
35
35
 
36
36
  // src/anthropic-messages-language-model.ts
37
37
  var import_provider3 = require("@ai-sdk/provider");
@@ -678,9 +678,10 @@ var anthropicSystemMessageProviderOptions = import_v43.z.object({
678
678
  */
679
679
  clearAt: import_v43.z.literal("next_user_message").optional(),
680
680
  /**
681
- * Overrides the effort for the turn following this mid-conversation system
682
- * message. The required `mid-conversation-output-config-2026-07-01` beta is added
683
- * automatically.
681
+ * Sets the model effort from the next user turn until a later message
682
+ * changes it. An effort-only system message with empty content can appear
683
+ * first. The required `mid-conversation-output-config-2026-07-01` beta is
684
+ * added automatically.
684
685
  */
685
686
  effort: import_v43.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
686
687
  /**
@@ -1644,7 +1645,7 @@ async function convertToAnthropicMessagesPrompt({
1644
1645
  cacheControlValidator,
1645
1646
  toolsetNames = {}
1646
1647
  }) {
1647
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1648
+ var _a, _b, _c, _d, _e, _f, _g;
1648
1649
  const betas = /* @__PURE__ */ new Set();
1649
1650
  const blocks = groupIntoBlocks(prompt);
1650
1651
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -1676,10 +1677,9 @@ async function convertToAnthropicMessagesPrompt({
1676
1677
  const type = block.type;
1677
1678
  switch (type) {
1678
1679
  case "system": {
1679
- const content = [];
1680
+ const systemMessages = [];
1680
1681
  let toolChangeCount = 0;
1681
- let clearAt = void 0;
1682
- let effort = void 0;
1682
+ let hasMidConversationOptions = false;
1683
1683
  for (const { content: text, providerOptions } of block.messages) {
1684
1684
  const systemMessageOptions = await (0, import_provider_utils10.parseProviderOptions)({
1685
1685
  provider: "anthropic",
@@ -1687,8 +1687,9 @@ async function convertToAnthropicMessagesPrompt({
1687
1687
  schema: anthropicSystemMessageProviderOptions
1688
1688
  });
1689
1689
  const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
1690
- clearAt = (_b = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) != null ? _b : clearAt;
1691
- effort = (_c = systemMessageOptions == null ? void 0 : systemMessageOptions.effort) != null ? _c : effort;
1690
+ const clearAt = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt;
1691
+ const effort = systemMessageOptions == null ? void 0 : systemMessageOptions.effort;
1692
+ const content = [];
1692
1693
  if (text !== "" || toolChanges.length === 0 && (systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) == null && (systemMessageOptions == null ? void 0 : systemMessageOptions.effort) == null) {
1693
1694
  content.push({
1694
1695
  type: "text",
@@ -1709,33 +1710,47 @@ async function convertToAnthropicMessagesPrompt({
1709
1710
  }
1710
1711
  });
1711
1712
  }
1713
+ hasMidConversationOptions || (hasMidConversationOptions = clearAt != null || effort != null);
1714
+ systemMessages.push({
1715
+ role: "system",
1716
+ content,
1717
+ ...clearAt != null && { clear_at: clearAt },
1718
+ ...effort != null && { output_config: { effort } }
1719
+ });
1712
1720
  }
1713
- const hasMidConversationOptions = toolChangeCount > 0 || clearAt != null || effort != null;
1714
- if (i === 0 || system == null && !hasMidConversationOptions) {
1715
- if (hasMidConversationOptions) {
1721
+ if (i === 0 || system == null && toolChangeCount === 0 && !hasMidConversationOptions) {
1722
+ if (toolChangeCount > 0) {
1716
1723
  warnings.push({
1717
1724
  type: "other",
1718
- message: "mid-conversation Anthropic system message options on the initial system message are not supported. The options have been ignored."
1725
+ 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."
1719
1726
  });
1720
1727
  }
1721
- system = content.filter(
1722
- (part) => part.type === "text"
1728
+ for (const message of systemMessages) {
1729
+ if (message.content.length === 0 && message.clear_at == null && message.output_config != null) {
1730
+ messages.push(message);
1731
+ betas.add("mid-conversation-output-config-2026-07-01");
1732
+ } else if (message.clear_at != null || message.output_config != null) {
1733
+ warnings.push({
1734
+ type: "other",
1735
+ 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."
1736
+ });
1737
+ }
1738
+ }
1739
+ system = systemMessages.flatMap(
1740
+ (message) => message.content.filter(
1741
+ (part) => part.type === "text"
1742
+ )
1723
1743
  );
1724
1744
  } else {
1725
- messages.push({
1726
- role: "system",
1727
- content,
1728
- ...clearAt != null && { clear_at: clearAt },
1729
- ...effort != null && { output_config: { effort } }
1730
- });
1745
+ messages.push(...systemMessages);
1731
1746
  betas.add("mid-conversation-system-2026-04-07");
1732
1747
  if (toolChangeCount > 0) {
1733
1748
  betas.add("mid-conversation-tool-changes-2026-07-01");
1734
1749
  }
1735
- if (clearAt != null) {
1750
+ if (systemMessages.some((message) => message.clear_at != null)) {
1736
1751
  betas.add("mid-conversation-system-clear-at-2026-08-21");
1737
1752
  }
1738
- if (effort != null) {
1753
+ if (systemMessages.some((message) => message.output_config != null)) {
1739
1754
  betas.add("mid-conversation-output-config-2026-07-01");
1740
1755
  }
1741
1756
  }
@@ -1750,10 +1765,10 @@ async function convertToAnthropicMessagesPrompt({
1750
1765
  for (let j = 0; j < content.length; j++) {
1751
1766
  const part = content[j];
1752
1767
  const isLastPart = j === content.length - 1;
1753
- const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
1768
+ const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
1754
1769
  type: "user message part",
1755
1770
  canCache: true
1756
- })) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
1771
+ })) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
1757
1772
  type: "user message",
1758
1773
  canCache: true
1759
1774
  }) : void 0;
@@ -1798,7 +1813,7 @@ async function convertToAnthropicMessagesPrompt({
1798
1813
  media_type: "application/pdf",
1799
1814
  data: (0, import_provider_utils10.convertToBase64)(part.data)
1800
1815
  },
1801
- title: (_e = metadata.title) != null ? _e : part.filename,
1816
+ title: (_c = metadata.title) != null ? _c : part.filename,
1802
1817
  ...metadata.context && { context: metadata.context },
1803
1818
  ...enableCitations && {
1804
1819
  citations: { enabled: true }
@@ -1822,7 +1837,7 @@ async function convertToAnthropicMessagesPrompt({
1822
1837
  media_type: "text/plain",
1823
1838
  data: convertToString(part.data)
1824
1839
  },
1825
- title: (_f = metadata.title) != null ? _f : part.filename,
1840
+ title: (_d = metadata.title) != null ? _d : part.filename,
1826
1841
  ...metadata.context && { context: metadata.context },
1827
1842
  ...enableCitations && {
1828
1843
  citations: { enabled: true }
@@ -1844,10 +1859,10 @@ async function convertToAnthropicMessagesPrompt({
1844
1859
  for (let i2 = 0; i2 < content.length; i2++) {
1845
1860
  const part = content[i2];
1846
1861
  const isLastPart = i2 === content.length - 1;
1847
- const cacheControl = (_g = validator.getCacheControl(part.providerOptions, {
1862
+ const cacheControl = (_e = validator.getCacheControl(part.providerOptions, {
1848
1863
  type: "tool result part",
1849
1864
  canCache: true
1850
- })) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
1865
+ })) != null ? _e : isLastPart ? validator.getCacheControl(message.providerOptions, {
1851
1866
  type: "tool result message",
1852
1867
  canCache: true
1853
1868
  }) : void 0;
@@ -1935,16 +1950,16 @@ async function convertToAnthropicMessagesPrompt({
1935
1950
  for (let k = 0; k < content.length; k++) {
1936
1951
  const part = content[k];
1937
1952
  const isLastContentPart = k === content.length - 1;
1938
- const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
1953
+ const cacheControl = (_f = validator.getCacheControl(part.providerOptions, {
1939
1954
  type: "assistant message part",
1940
1955
  canCache: true
1941
- })) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1956
+ })) != null ? _f : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1942
1957
  type: "assistant message",
1943
1958
  canCache: true
1944
1959
  }) : void 0;
1945
1960
  switch (part.type) {
1946
1961
  case "text": {
1947
- const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
1962
+ const textMetadata = (_g = part.providerOptions) == null ? void 0 : _g.anthropic;
1948
1963
  if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
1949
1964
  anthropicContent.push({
1950
1965
  type: "compaction",