@ai-sdk/anthropic 2.0.47 → 2.0.48
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.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +74 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -22
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +73 -21
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +73 -21
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/internal/index.js
CHANGED
|
@@ -545,6 +545,20 @@ var anthropicFilePartProviderOptions = import_v43.z.object({
|
|
|
545
545
|
});
|
|
546
546
|
var anthropicProviderOptions = import_v43.z.object({
|
|
547
547
|
sendReasoning: import_v43.z.boolean().optional(),
|
|
548
|
+
/**
|
|
549
|
+
* Determines how structured outputs are generated.
|
|
550
|
+
*
|
|
551
|
+
* - `outputFormat`: Use the `output_format` parameter to specify the structured output format.
|
|
552
|
+
* - `jsonTool`: Use a special 'json' tool to specify the structured output format (default).
|
|
553
|
+
* - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool'.
|
|
554
|
+
*/
|
|
555
|
+
structuredOutputMode: import_v43.z.enum(["outputFormat", "jsonTool", "auto"]).optional(),
|
|
556
|
+
/**
|
|
557
|
+
* Configuration for enabling Claude's extended thinking.
|
|
558
|
+
*
|
|
559
|
+
* When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
|
|
560
|
+
* Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
|
|
561
|
+
*/
|
|
548
562
|
thinking: import_v43.z.object({
|
|
549
563
|
type: import_v43.z.union([import_v43.z.literal("enabled"), import_v43.z.literal("disabled")]),
|
|
550
564
|
budgetTokens: import_v43.z.number().optional()
|
|
@@ -1762,7 +1776,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1762
1776
|
toolChoice,
|
|
1763
1777
|
providerOptions
|
|
1764
1778
|
}) {
|
|
1765
|
-
var _a, _b, _c, _d;
|
|
1779
|
+
var _a, _b, _c, _d, _e;
|
|
1766
1780
|
const warnings = [];
|
|
1767
1781
|
if (frequencyPenalty != null) {
|
|
1768
1782
|
warnings.push({
|
|
@@ -1812,27 +1826,33 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1812
1826
|
});
|
|
1813
1827
|
}
|
|
1814
1828
|
}
|
|
1815
|
-
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
|
|
1816
|
-
type: "function",
|
|
1817
|
-
name: "json",
|
|
1818
|
-
description: "Respond with a JSON object.",
|
|
1819
|
-
inputSchema: responseFormat.schema
|
|
1820
|
-
} : void 0;
|
|
1821
1829
|
const anthropicOptions = await (0, import_provider_utils11.parseProviderOptions)({
|
|
1822
1830
|
provider: "anthropic",
|
|
1823
1831
|
providerOptions,
|
|
1824
1832
|
schema: anthropicProviderOptions
|
|
1825
1833
|
});
|
|
1834
|
+
const {
|
|
1835
|
+
maxOutputTokens: maxOutputTokensForModel,
|
|
1836
|
+
supportsStructuredOutput,
|
|
1837
|
+
isKnownModel
|
|
1838
|
+
} = getModelCapabilities(this.modelId);
|
|
1839
|
+
const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : "jsonTool";
|
|
1840
|
+
const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
1841
|
+
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
|
|
1842
|
+
type: "function",
|
|
1843
|
+
name: "json",
|
|
1844
|
+
description: "Respond with a JSON object.",
|
|
1845
|
+
inputSchema: responseFormat.schema
|
|
1846
|
+
} : void 0;
|
|
1826
1847
|
const cacheControlValidator = new CacheControlValidator();
|
|
1827
1848
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
1828
1849
|
prompt,
|
|
1829
|
-
sendReasoning: (
|
|
1850
|
+
sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
|
|
1830
1851
|
warnings,
|
|
1831
1852
|
cacheControlValidator
|
|
1832
1853
|
});
|
|
1833
|
-
const isThinking = ((
|
|
1834
|
-
const thinkingBudget = (
|
|
1835
|
-
const { maxOutputTokens: maxOutputTokensForModel, knownModel } = getMaxOutputTokensForModel(this.modelId);
|
|
1854
|
+
const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
|
|
1855
|
+
const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
|
|
1836
1856
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
1837
1857
|
const baseArgs = {
|
|
1838
1858
|
// model id:
|
|
@@ -1850,11 +1870,18 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1850
1870
|
...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
|
|
1851
1871
|
output_config: { effort: anthropicOptions.effort }
|
|
1852
1872
|
},
|
|
1873
|
+
// structured output:
|
|
1874
|
+
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
1875
|
+
output_format: {
|
|
1876
|
+
type: "json_schema",
|
|
1877
|
+
schema: responseFormat.schema
|
|
1878
|
+
}
|
|
1879
|
+
},
|
|
1853
1880
|
// container with agent skills:
|
|
1854
1881
|
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
1855
1882
|
container: {
|
|
1856
1883
|
id: anthropicOptions.container.id,
|
|
1857
|
-
skills: (
|
|
1884
|
+
skills: (_e = anthropicOptions.container.skills) == null ? void 0 : _e.map((skill) => ({
|
|
1858
1885
|
type: skill.type,
|
|
1859
1886
|
skill_id: skill.skillId,
|
|
1860
1887
|
version: skill.version
|
|
@@ -1897,7 +1924,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1897
1924
|
}
|
|
1898
1925
|
baseArgs.max_tokens = maxTokens + thinkingBudget;
|
|
1899
1926
|
}
|
|
1900
|
-
if (
|
|
1927
|
+
if (isKnownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
|
|
1901
1928
|
if (maxOutputTokens != null) {
|
|
1902
1929
|
warnings.push({
|
|
1903
1930
|
type: "unsupported-setting",
|
|
@@ -1923,6 +1950,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1923
1950
|
if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
|
|
1924
1951
|
betas.add("effort-2025-11-24");
|
|
1925
1952
|
}
|
|
1953
|
+
if (useStructuredOutput) {
|
|
1954
|
+
betas.add("structured-outputs-2025-11-13");
|
|
1955
|
+
}
|
|
1926
1956
|
const {
|
|
1927
1957
|
tools: anthropicTools2,
|
|
1928
1958
|
toolChoice: anthropicToolChoice,
|
|
@@ -2725,27 +2755,49 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2725
2755
|
};
|
|
2726
2756
|
}
|
|
2727
2757
|
};
|
|
2728
|
-
function
|
|
2758
|
+
function getModelCapabilities(modelId) {
|
|
2729
2759
|
if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5")) {
|
|
2730
2760
|
return {
|
|
2731
2761
|
maxOutputTokens: 64e3,
|
|
2732
|
-
|
|
2762
|
+
supportsStructuredOutput: true,
|
|
2763
|
+
isKnownModel: true
|
|
2733
2764
|
};
|
|
2734
2765
|
} else if (modelId.includes("claude-opus-4-1")) {
|
|
2735
2766
|
return {
|
|
2736
2767
|
maxOutputTokens: 32e3,
|
|
2737
|
-
|
|
2768
|
+
supportsStructuredOutput: true,
|
|
2769
|
+
isKnownModel: true
|
|
2738
2770
|
};
|
|
2739
2771
|
} else if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet") || modelId.includes("claude-haiku-4-5")) {
|
|
2740
|
-
return {
|
|
2772
|
+
return {
|
|
2773
|
+
maxOutputTokens: 64e3,
|
|
2774
|
+
supportsStructuredOutput: false,
|
|
2775
|
+
isKnownModel: true
|
|
2776
|
+
};
|
|
2741
2777
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
2742
|
-
return {
|
|
2778
|
+
return {
|
|
2779
|
+
maxOutputTokens: 32e3,
|
|
2780
|
+
supportsStructuredOutput: false,
|
|
2781
|
+
isKnownModel: true
|
|
2782
|
+
};
|
|
2743
2783
|
} else if (modelId.includes("claude-3-5-haiku")) {
|
|
2744
|
-
return {
|
|
2784
|
+
return {
|
|
2785
|
+
maxOutputTokens: 8192,
|
|
2786
|
+
supportsStructuredOutput: false,
|
|
2787
|
+
isKnownModel: true
|
|
2788
|
+
};
|
|
2745
2789
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
2746
|
-
return {
|
|
2790
|
+
return {
|
|
2791
|
+
maxOutputTokens: 4096,
|
|
2792
|
+
supportsStructuredOutput: false,
|
|
2793
|
+
isKnownModel: true
|
|
2794
|
+
};
|
|
2747
2795
|
} else {
|
|
2748
|
-
return {
|
|
2796
|
+
return {
|
|
2797
|
+
maxOutputTokens: 4096,
|
|
2798
|
+
supportsStructuredOutput: false,
|
|
2799
|
+
isKnownModel: false
|
|
2800
|
+
};
|
|
2749
2801
|
}
|
|
2750
2802
|
}
|
|
2751
2803
|
|