@ai-sdk/anthropic 2.0.30 → 2.0.32
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 +12 -0
- package/README.md +1 -1
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +69 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -8
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +68 -7
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +68 -7
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 2.0.32
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 492b1ee: feat(provider/anthropic): add support for Agent Skills
|
|
8
|
+
|
|
9
|
+
## 2.0.31
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- b73ba90: feat(provider/anthropic): default and limit maxTokens based on model
|
|
14
|
+
|
|
3
15
|
## 2.0.30
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -15,6 +15,14 @@ declare const anthropicProviderOptions: z.ZodObject<{
|
|
|
15
15
|
type: z.ZodLiteral<"ephemeral">;
|
|
16
16
|
ttl: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
|
|
17
17
|
}, z.core.$strip>>;
|
|
18
|
+
container: z.ZodOptional<z.ZodObject<{
|
|
19
|
+
id: z.ZodOptional<z.ZodString>;
|
|
20
|
+
skills: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
21
|
+
type: z.ZodUnion<readonly [z.ZodLiteral<"anthropic">, z.ZodLiteral<"custom">]>;
|
|
22
|
+
skillId: z.ZodString;
|
|
23
|
+
version: z.ZodOptional<z.ZodString>;
|
|
24
|
+
}, z.core.$strip>>>;
|
|
25
|
+
}, z.core.$strip>>;
|
|
18
26
|
}, z.core.$strip>;
|
|
19
27
|
type AnthropicProviderOptions = z.infer<typeof anthropicProviderOptions>;
|
|
20
28
|
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,14 @@ declare const anthropicProviderOptions: z.ZodObject<{
|
|
|
15
15
|
type: z.ZodLiteral<"ephemeral">;
|
|
16
16
|
ttl: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"5m">, z.ZodLiteral<"1h">]>>;
|
|
17
17
|
}, z.core.$strip>>;
|
|
18
|
+
container: z.ZodOptional<z.ZodObject<{
|
|
19
|
+
id: z.ZodOptional<z.ZodString>;
|
|
20
|
+
skills: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
21
|
+
type: z.ZodUnion<readonly [z.ZodLiteral<"anthropic">, z.ZodLiteral<"custom">]>;
|
|
22
|
+
skillId: z.ZodString;
|
|
23
|
+
version: z.ZodOptional<z.ZodString>;
|
|
24
|
+
}, z.core.$strip>>>;
|
|
25
|
+
}, z.core.$strip>>;
|
|
18
26
|
}, z.core.$strip>;
|
|
19
27
|
type AnthropicProviderOptions = z.infer<typeof anthropicProviderOptions>;
|
|
20
28
|
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
31
31
|
var import_provider_utils20 = require("@ai-sdk/provider-utils");
|
|
32
32
|
|
|
33
33
|
// src/version.ts
|
|
34
|
-
var VERSION = true ? "2.0.
|
|
34
|
+
var VERSION = true ? "2.0.32" : "0.0.0-test";
|
|
35
35
|
|
|
36
36
|
// src/anthropic-messages-language-model.ts
|
|
37
37
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -543,6 +543,21 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
543
543
|
cacheControl: import_v43.z.object({
|
|
544
544
|
type: import_v43.z.literal("ephemeral"),
|
|
545
545
|
ttl: import_v43.z.union([import_v43.z.literal("5m"), import_v43.z.literal("1h")]).optional()
|
|
546
|
+
}).optional(),
|
|
547
|
+
/**
|
|
548
|
+
* Agent Skills configuration. Skills enable Claude to perform specialized tasks
|
|
549
|
+
* like document processing (PPTX, DOCX, PDF, XLSX) and data analysis.
|
|
550
|
+
* Requires code execution tool to be enabled.
|
|
551
|
+
*/
|
|
552
|
+
container: import_v43.z.object({
|
|
553
|
+
id: import_v43.z.string().optional(),
|
|
554
|
+
skills: import_v43.z.array(
|
|
555
|
+
import_v43.z.object({
|
|
556
|
+
type: import_v43.z.union([import_v43.z.literal("anthropic"), import_v43.z.literal("custom")]),
|
|
557
|
+
skillId: import_v43.z.string(),
|
|
558
|
+
version: import_v43.z.string().optional()
|
|
559
|
+
})
|
|
560
|
+
).optional()
|
|
546
561
|
}).optional()
|
|
547
562
|
});
|
|
548
563
|
|
|
@@ -1636,8 +1651,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1636
1651
|
}
|
|
1637
1652
|
async getArgs({
|
|
1638
1653
|
prompt,
|
|
1639
|
-
maxOutputTokens
|
|
1640
|
-
// 4096: max model output tokens TODO update default in v5
|
|
1654
|
+
maxOutputTokens,
|
|
1641
1655
|
temperature,
|
|
1642
1656
|
topP,
|
|
1643
1657
|
topK,
|
|
@@ -1650,7 +1664,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1650
1664
|
toolChoice,
|
|
1651
1665
|
providerOptions
|
|
1652
1666
|
}) {
|
|
1653
|
-
var _a, _b, _c;
|
|
1667
|
+
var _a, _b, _c, _d;
|
|
1654
1668
|
const warnings = [];
|
|
1655
1669
|
if (frequencyPenalty != null) {
|
|
1656
1670
|
warnings.push({
|
|
@@ -1696,18 +1710,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1696
1710
|
providerOptions,
|
|
1697
1711
|
schema: anthropicProviderOptions
|
|
1698
1712
|
});
|
|
1699
|
-
const { prompt: messagesPrompt, betas
|
|
1713
|
+
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
1700
1714
|
prompt,
|
|
1701
1715
|
sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
|
|
1702
1716
|
warnings
|
|
1703
1717
|
});
|
|
1704
1718
|
const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
|
|
1705
1719
|
const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
|
|
1720
|
+
const maxOutputTokensForModel = getMaxOutputTokensForModel(this.modelId);
|
|
1721
|
+
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
1706
1722
|
const baseArgs = {
|
|
1707
1723
|
// model id:
|
|
1708
1724
|
model: this.modelId,
|
|
1709
1725
|
// standardized settings:
|
|
1710
|
-
max_tokens:
|
|
1726
|
+
max_tokens: maxTokens,
|
|
1711
1727
|
temperature,
|
|
1712
1728
|
top_k: topK,
|
|
1713
1729
|
top_p: topP,
|
|
@@ -1716,6 +1732,17 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1716
1732
|
...isThinking && {
|
|
1717
1733
|
thinking: { type: "enabled", budget_tokens: thinkingBudget }
|
|
1718
1734
|
},
|
|
1735
|
+
// container with agent skills:
|
|
1736
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
1737
|
+
container: {
|
|
1738
|
+
id: anthropicOptions.container.id,
|
|
1739
|
+
skills: (_d = anthropicOptions.container.skills) == null ? void 0 : _d.map((skill) => ({
|
|
1740
|
+
type: skill.type,
|
|
1741
|
+
skill_id: skill.skillId,
|
|
1742
|
+
version: skill.version
|
|
1743
|
+
}))
|
|
1744
|
+
}
|
|
1745
|
+
},
|
|
1719
1746
|
// prompt:
|
|
1720
1747
|
system: messagesPrompt.system,
|
|
1721
1748
|
messages: messagesPrompt.messages
|
|
@@ -1750,7 +1777,30 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1750
1777
|
details: "topP is not supported when thinking is enabled"
|
|
1751
1778
|
});
|
|
1752
1779
|
}
|
|
1753
|
-
baseArgs.max_tokens =
|
|
1780
|
+
baseArgs.max_tokens = maxTokens + thinkingBudget;
|
|
1781
|
+
}
|
|
1782
|
+
if (baseArgs.max_tokens > maxOutputTokensForModel) {
|
|
1783
|
+
if (maxOutputTokens != null) {
|
|
1784
|
+
warnings.push({
|
|
1785
|
+
type: "unsupported-setting",
|
|
1786
|
+
setting: "maxOutputTokens",
|
|
1787
|
+
details: `${baseArgs.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${this.modelId} ${maxOutputTokensForModel} max output tokens. The max output tokens have been limited to ${maxOutputTokensForModel}.`
|
|
1788
|
+
});
|
|
1789
|
+
}
|
|
1790
|
+
baseArgs.max_tokens = maxOutputTokensForModel;
|
|
1791
|
+
}
|
|
1792
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.container) && anthropicOptions.container.skills && anthropicOptions.container.skills.length > 0) {
|
|
1793
|
+
betas.add("code-execution-2025-08-25");
|
|
1794
|
+
betas.add("skills-2025-10-02");
|
|
1795
|
+
betas.add("files-api-2025-04-14");
|
|
1796
|
+
if (!(tools == null ? void 0 : tools.some(
|
|
1797
|
+
(tool) => tool.type === "provider-defined" && tool.id === "anthropic.code_execution_20250825"
|
|
1798
|
+
))) {
|
|
1799
|
+
warnings.push({
|
|
1800
|
+
type: "other",
|
|
1801
|
+
message: "code execution tool is required when using skills"
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1754
1804
|
}
|
|
1755
1805
|
const {
|
|
1756
1806
|
tools: anthropicTools2,
|
|
@@ -1775,7 +1825,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1775
1825
|
tool_choice: anthropicToolChoice
|
|
1776
1826
|
},
|
|
1777
1827
|
warnings: [...warnings, ...toolWarnings],
|
|
1778
|
-
betas: /* @__PURE__ */ new Set([...
|
|
1828
|
+
betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas]),
|
|
1779
1829
|
usesJsonResponseTool: jsonResponseTool != null
|
|
1780
1830
|
};
|
|
1781
1831
|
}
|
|
@@ -2530,6 +2580,17 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2530
2580
|
};
|
|
2531
2581
|
}
|
|
2532
2582
|
};
|
|
2583
|
+
function getMaxOutputTokensForModel(modelId) {
|
|
2584
|
+
if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet") || modelId.includes("claude-haiku-4-5")) {
|
|
2585
|
+
return 64e3;
|
|
2586
|
+
} else if (modelId.includes("claude-opus-4-")) {
|
|
2587
|
+
return 32e3;
|
|
2588
|
+
} else if (modelId.includes("claude-3-5-haiku")) {
|
|
2589
|
+
return 8192;
|
|
2590
|
+
} else {
|
|
2591
|
+
return 4096;
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2533
2594
|
|
|
2534
2595
|
// src/tool/bash_20241022.ts
|
|
2535
2596
|
var import_provider_utils12 = require("@ai-sdk/provider-utils");
|