@ai-sdk/anthropic 2.0.45 → 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 +18 -0
- package/dist/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +94 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -22
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +93 -21
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +93 -21
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -2,7 +2,7 @@ import { LanguageModelV2, JSONSchema7, SharedV2ProviderMetadata, LanguageModelV2
|
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
5
|
-
type AnthropicMessagesModelId = 'claude-haiku-
|
|
5
|
+
type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | (string & {});
|
|
6
6
|
|
|
7
7
|
type AnthropicMessagesConfig = {
|
|
8
8
|
provider: string;
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { LanguageModelV2, JSONSchema7, SharedV2ProviderMetadata, LanguageModelV2
|
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
5
|
-
type AnthropicMessagesModelId = 'claude-haiku-
|
|
5
|
+
type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | (string & {});
|
|
6
6
|
|
|
7
7
|
type AnthropicMessagesConfig = {
|
|
8
8
|
provider: string;
|
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()
|
|
@@ -576,7 +590,11 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
576
590
|
version: import_v43.z.string().optional()
|
|
577
591
|
})
|
|
578
592
|
).optional()
|
|
579
|
-
}).optional()
|
|
593
|
+
}).optional(),
|
|
594
|
+
/**
|
|
595
|
+
* @default 'high'
|
|
596
|
+
*/
|
|
597
|
+
effort: import_v43.z.enum(["low", "medium", "high"]).optional()
|
|
580
598
|
});
|
|
581
599
|
|
|
582
600
|
// src/anthropic-prepare-tools.ts
|
|
@@ -1758,7 +1776,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1758
1776
|
toolChoice,
|
|
1759
1777
|
providerOptions
|
|
1760
1778
|
}) {
|
|
1761
|
-
var _a, _b, _c, _d;
|
|
1779
|
+
var _a, _b, _c, _d, _e;
|
|
1762
1780
|
const warnings = [];
|
|
1763
1781
|
if (frequencyPenalty != null) {
|
|
1764
1782
|
warnings.push({
|
|
@@ -1808,27 +1826,33 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1808
1826
|
});
|
|
1809
1827
|
}
|
|
1810
1828
|
}
|
|
1811
|
-
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
|
|
1812
|
-
type: "function",
|
|
1813
|
-
name: "json",
|
|
1814
|
-
description: "Respond with a JSON object.",
|
|
1815
|
-
inputSchema: responseFormat.schema
|
|
1816
|
-
} : void 0;
|
|
1817
1829
|
const anthropicOptions = await (0, import_provider_utils11.parseProviderOptions)({
|
|
1818
1830
|
provider: "anthropic",
|
|
1819
1831
|
providerOptions,
|
|
1820
1832
|
schema: anthropicProviderOptions
|
|
1821
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;
|
|
1822
1847
|
const cacheControlValidator = new CacheControlValidator();
|
|
1823
1848
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
1824
1849
|
prompt,
|
|
1825
|
-
sendReasoning: (
|
|
1850
|
+
sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
|
|
1826
1851
|
warnings,
|
|
1827
1852
|
cacheControlValidator
|
|
1828
1853
|
});
|
|
1829
|
-
const isThinking = ((
|
|
1830
|
-
const thinkingBudget = (
|
|
1831
|
-
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;
|
|
1832
1856
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
1833
1857
|
const baseArgs = {
|
|
1834
1858
|
// model id:
|
|
@@ -1843,11 +1867,21 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1843
1867
|
...isThinking && {
|
|
1844
1868
|
thinking: { type: "enabled", budget_tokens: thinkingBudget }
|
|
1845
1869
|
},
|
|
1870
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
|
|
1871
|
+
output_config: { effort: anthropicOptions.effort }
|
|
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
|
+
},
|
|
1846
1880
|
// container with agent skills:
|
|
1847
1881
|
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
1848
1882
|
container: {
|
|
1849
1883
|
id: anthropicOptions.container.id,
|
|
1850
|
-
skills: (
|
|
1884
|
+
skills: (_e = anthropicOptions.container.skills) == null ? void 0 : _e.map((skill) => ({
|
|
1851
1885
|
type: skill.type,
|
|
1852
1886
|
skill_id: skill.skillId,
|
|
1853
1887
|
version: skill.version
|
|
@@ -1890,7 +1924,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1890
1924
|
}
|
|
1891
1925
|
baseArgs.max_tokens = maxTokens + thinkingBudget;
|
|
1892
1926
|
}
|
|
1893
|
-
if (
|
|
1927
|
+
if (isKnownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
|
|
1894
1928
|
if (maxOutputTokens != null) {
|
|
1895
1929
|
warnings.push({
|
|
1896
1930
|
type: "unsupported-setting",
|
|
@@ -1913,6 +1947,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1913
1947
|
});
|
|
1914
1948
|
}
|
|
1915
1949
|
}
|
|
1950
|
+
if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
|
|
1951
|
+
betas.add("effort-2025-11-24");
|
|
1952
|
+
}
|
|
1953
|
+
if (useStructuredOutput) {
|
|
1954
|
+
betas.add("structured-outputs-2025-11-13");
|
|
1955
|
+
}
|
|
1916
1956
|
const {
|
|
1917
1957
|
tools: anthropicTools2,
|
|
1918
1958
|
toolChoice: anthropicToolChoice,
|
|
@@ -2715,17 +2755,49 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2715
2755
|
};
|
|
2716
2756
|
}
|
|
2717
2757
|
};
|
|
2718
|
-
function
|
|
2719
|
-
if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-
|
|
2720
|
-
return {
|
|
2758
|
+
function getModelCapabilities(modelId) {
|
|
2759
|
+
if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5")) {
|
|
2760
|
+
return {
|
|
2761
|
+
maxOutputTokens: 64e3,
|
|
2762
|
+
supportsStructuredOutput: true,
|
|
2763
|
+
isKnownModel: true
|
|
2764
|
+
};
|
|
2765
|
+
} else if (modelId.includes("claude-opus-4-1")) {
|
|
2766
|
+
return {
|
|
2767
|
+
maxOutputTokens: 32e3,
|
|
2768
|
+
supportsStructuredOutput: true,
|
|
2769
|
+
isKnownModel: true
|
|
2770
|
+
};
|
|
2771
|
+
} else if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet") || modelId.includes("claude-haiku-4-5")) {
|
|
2772
|
+
return {
|
|
2773
|
+
maxOutputTokens: 64e3,
|
|
2774
|
+
supportsStructuredOutput: false,
|
|
2775
|
+
isKnownModel: true
|
|
2776
|
+
};
|
|
2721
2777
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
2722
|
-
return {
|
|
2778
|
+
return {
|
|
2779
|
+
maxOutputTokens: 32e3,
|
|
2780
|
+
supportsStructuredOutput: false,
|
|
2781
|
+
isKnownModel: true
|
|
2782
|
+
};
|
|
2723
2783
|
} else if (modelId.includes("claude-3-5-haiku")) {
|
|
2724
|
-
return {
|
|
2784
|
+
return {
|
|
2785
|
+
maxOutputTokens: 8192,
|
|
2786
|
+
supportsStructuredOutput: false,
|
|
2787
|
+
isKnownModel: true
|
|
2788
|
+
};
|
|
2725
2789
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
2726
|
-
return {
|
|
2790
|
+
return {
|
|
2791
|
+
maxOutputTokens: 4096,
|
|
2792
|
+
supportsStructuredOutput: false,
|
|
2793
|
+
isKnownModel: true
|
|
2794
|
+
};
|
|
2727
2795
|
} else {
|
|
2728
|
-
return {
|
|
2796
|
+
return {
|
|
2797
|
+
maxOutputTokens: 4096,
|
|
2798
|
+
supportsStructuredOutput: false,
|
|
2799
|
+
isKnownModel: false
|
|
2800
|
+
};
|
|
2729
2801
|
}
|
|
2730
2802
|
}
|
|
2731
2803
|
|