@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.mjs
CHANGED
|
@@ -531,6 +531,20 @@ var anthropicFilePartProviderOptions = z3.object({
|
|
|
531
531
|
});
|
|
532
532
|
var anthropicProviderOptions = z3.object({
|
|
533
533
|
sendReasoning: z3.boolean().optional(),
|
|
534
|
+
/**
|
|
535
|
+
* Determines how structured outputs are generated.
|
|
536
|
+
*
|
|
537
|
+
* - `outputFormat`: Use the `output_format` parameter to specify the structured output format.
|
|
538
|
+
* - `jsonTool`: Use a special 'json' tool to specify the structured output format (default).
|
|
539
|
+
* - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool'.
|
|
540
|
+
*/
|
|
541
|
+
structuredOutputMode: z3.enum(["outputFormat", "jsonTool", "auto"]).optional(),
|
|
542
|
+
/**
|
|
543
|
+
* Configuration for enabling Claude's extended thinking.
|
|
544
|
+
*
|
|
545
|
+
* When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
|
|
546
|
+
* Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
|
|
547
|
+
*/
|
|
534
548
|
thinking: z3.object({
|
|
535
549
|
type: z3.union([z3.literal("enabled"), z3.literal("disabled")]),
|
|
536
550
|
budgetTokens: z3.number().optional()
|
|
@@ -1772,7 +1786,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1772
1786
|
toolChoice,
|
|
1773
1787
|
providerOptions
|
|
1774
1788
|
}) {
|
|
1775
|
-
var _a, _b, _c, _d;
|
|
1789
|
+
var _a, _b, _c, _d, _e;
|
|
1776
1790
|
const warnings = [];
|
|
1777
1791
|
if (frequencyPenalty != null) {
|
|
1778
1792
|
warnings.push({
|
|
@@ -1822,27 +1836,33 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1822
1836
|
});
|
|
1823
1837
|
}
|
|
1824
1838
|
}
|
|
1825
|
-
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
|
|
1826
|
-
type: "function",
|
|
1827
|
-
name: "json",
|
|
1828
|
-
description: "Respond with a JSON object.",
|
|
1829
|
-
inputSchema: responseFormat.schema
|
|
1830
|
-
} : void 0;
|
|
1831
1839
|
const anthropicOptions = await parseProviderOptions2({
|
|
1832
1840
|
provider: "anthropic",
|
|
1833
1841
|
providerOptions,
|
|
1834
1842
|
schema: anthropicProviderOptions
|
|
1835
1843
|
});
|
|
1844
|
+
const {
|
|
1845
|
+
maxOutputTokens: maxOutputTokensForModel,
|
|
1846
|
+
supportsStructuredOutput,
|
|
1847
|
+
isKnownModel
|
|
1848
|
+
} = getModelCapabilities(this.modelId);
|
|
1849
|
+
const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : "jsonTool";
|
|
1850
|
+
const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
1851
|
+
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
|
|
1852
|
+
type: "function",
|
|
1853
|
+
name: "json",
|
|
1854
|
+
description: "Respond with a JSON object.",
|
|
1855
|
+
inputSchema: responseFormat.schema
|
|
1856
|
+
} : void 0;
|
|
1836
1857
|
const cacheControlValidator = new CacheControlValidator();
|
|
1837
1858
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
1838
1859
|
prompt,
|
|
1839
|
-
sendReasoning: (
|
|
1860
|
+
sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
|
|
1840
1861
|
warnings,
|
|
1841
1862
|
cacheControlValidator
|
|
1842
1863
|
});
|
|
1843
|
-
const isThinking = ((
|
|
1844
|
-
const thinkingBudget = (
|
|
1845
|
-
const { maxOutputTokens: maxOutputTokensForModel, knownModel } = getMaxOutputTokensForModel(this.modelId);
|
|
1864
|
+
const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
|
|
1865
|
+
const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
|
|
1846
1866
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
1847
1867
|
const baseArgs = {
|
|
1848
1868
|
// model id:
|
|
@@ -1860,11 +1880,18 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1860
1880
|
...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
|
|
1861
1881
|
output_config: { effort: anthropicOptions.effort }
|
|
1862
1882
|
},
|
|
1883
|
+
// structured output:
|
|
1884
|
+
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
1885
|
+
output_format: {
|
|
1886
|
+
type: "json_schema",
|
|
1887
|
+
schema: responseFormat.schema
|
|
1888
|
+
}
|
|
1889
|
+
},
|
|
1863
1890
|
// container with agent skills:
|
|
1864
1891
|
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
1865
1892
|
container: {
|
|
1866
1893
|
id: anthropicOptions.container.id,
|
|
1867
|
-
skills: (
|
|
1894
|
+
skills: (_e = anthropicOptions.container.skills) == null ? void 0 : _e.map((skill) => ({
|
|
1868
1895
|
type: skill.type,
|
|
1869
1896
|
skill_id: skill.skillId,
|
|
1870
1897
|
version: skill.version
|
|
@@ -1907,7 +1934,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1907
1934
|
}
|
|
1908
1935
|
baseArgs.max_tokens = maxTokens + thinkingBudget;
|
|
1909
1936
|
}
|
|
1910
|
-
if (
|
|
1937
|
+
if (isKnownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
|
|
1911
1938
|
if (maxOutputTokens != null) {
|
|
1912
1939
|
warnings.push({
|
|
1913
1940
|
type: "unsupported-setting",
|
|
@@ -1933,6 +1960,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1933
1960
|
if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
|
|
1934
1961
|
betas.add("effort-2025-11-24");
|
|
1935
1962
|
}
|
|
1963
|
+
if (useStructuredOutput) {
|
|
1964
|
+
betas.add("structured-outputs-2025-11-13");
|
|
1965
|
+
}
|
|
1936
1966
|
const {
|
|
1937
1967
|
tools: anthropicTools2,
|
|
1938
1968
|
toolChoice: anthropicToolChoice,
|
|
@@ -2735,27 +2765,49 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2735
2765
|
};
|
|
2736
2766
|
}
|
|
2737
2767
|
};
|
|
2738
|
-
function
|
|
2768
|
+
function getModelCapabilities(modelId) {
|
|
2739
2769
|
if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5")) {
|
|
2740
2770
|
return {
|
|
2741
2771
|
maxOutputTokens: 64e3,
|
|
2742
|
-
|
|
2772
|
+
supportsStructuredOutput: true,
|
|
2773
|
+
isKnownModel: true
|
|
2743
2774
|
};
|
|
2744
2775
|
} else if (modelId.includes("claude-opus-4-1")) {
|
|
2745
2776
|
return {
|
|
2746
2777
|
maxOutputTokens: 32e3,
|
|
2747
|
-
|
|
2778
|
+
supportsStructuredOutput: true,
|
|
2779
|
+
isKnownModel: true
|
|
2748
2780
|
};
|
|
2749
2781
|
} else if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet") || modelId.includes("claude-haiku-4-5")) {
|
|
2750
|
-
return {
|
|
2782
|
+
return {
|
|
2783
|
+
maxOutputTokens: 64e3,
|
|
2784
|
+
supportsStructuredOutput: false,
|
|
2785
|
+
isKnownModel: true
|
|
2786
|
+
};
|
|
2751
2787
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
2752
|
-
return {
|
|
2788
|
+
return {
|
|
2789
|
+
maxOutputTokens: 32e3,
|
|
2790
|
+
supportsStructuredOutput: false,
|
|
2791
|
+
isKnownModel: true
|
|
2792
|
+
};
|
|
2753
2793
|
} else if (modelId.includes("claude-3-5-haiku")) {
|
|
2754
|
-
return {
|
|
2794
|
+
return {
|
|
2795
|
+
maxOutputTokens: 8192,
|
|
2796
|
+
supportsStructuredOutput: false,
|
|
2797
|
+
isKnownModel: true
|
|
2798
|
+
};
|
|
2755
2799
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
2756
|
-
return {
|
|
2800
|
+
return {
|
|
2801
|
+
maxOutputTokens: 4096,
|
|
2802
|
+
supportsStructuredOutput: false,
|
|
2803
|
+
isKnownModel: true
|
|
2804
|
+
};
|
|
2757
2805
|
} else {
|
|
2758
|
-
return {
|
|
2806
|
+
return {
|
|
2807
|
+
maxOutputTokens: 4096,
|
|
2808
|
+
supportsStructuredOutput: false,
|
|
2809
|
+
isKnownModel: false
|
|
2810
|
+
};
|
|
2759
2811
|
}
|
|
2760
2812
|
}
|
|
2761
2813
|
|