@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 +6 -0
- package/dist/index.js +48 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -33
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +47 -32
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +47 -32
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
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.
|
|
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
|
-
*
|
|
682
|
-
*
|
|
683
|
-
*
|
|
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
|
|
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
|
|
1680
|
+
const systemMessages = [];
|
|
1680
1681
|
let toolChangeCount = 0;
|
|
1681
|
-
let
|
|
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 =
|
|
1691
|
-
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
|
-
|
|
1714
|
-
|
|
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: "
|
|
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
|
-
|
|
1722
|
-
(
|
|
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 (
|
|
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 (
|
|
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 = (
|
|
1768
|
+
const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
|
|
1754
1769
|
type: "user message part",
|
|
1755
1770
|
canCache: true
|
|
1756
|
-
})) != null ?
|
|
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: (
|
|
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: (
|
|
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 = (
|
|
1862
|
+
const cacheControl = (_e = validator.getCacheControl(part.providerOptions, {
|
|
1848
1863
|
type: "tool result part",
|
|
1849
1864
|
canCache: true
|
|
1850
|
-
})) != null ?
|
|
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 = (
|
|
1953
|
+
const cacheControl = (_f = validator.getCacheControl(part.providerOptions, {
|
|
1939
1954
|
type: "assistant message part",
|
|
1940
1955
|
canCache: true
|
|
1941
|
-
})) != null ?
|
|
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 = (
|
|
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",
|