@ai-sdk/anthropic 3.0.0-beta.56 → 3.0.0-beta.58
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/dist/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +89 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -23
- 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 +88 -22
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +88 -22
- 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
|
+
## 3.0.0-beta.58
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 83aaad8: Opus 4.5 and `effort` provider option
|
|
8
|
+
|
|
9
|
+
## 3.0.0-beta.57
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- b8ea36e: feat(provider/anthropic): Anthropic-native structured outputs
|
|
14
|
+
|
|
3
15
|
## 3.0.0-beta.56
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -42,9 +42,14 @@ interface AnthropicMessageMetadata {
|
|
|
42
42
|
} | null;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
type AnthropicMessagesModelId = 'claude-haiku-
|
|
45
|
+
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 & {});
|
|
46
46
|
declare const anthropicProviderOptions: z.ZodObject<{
|
|
47
47
|
sendReasoning: z.ZodOptional<z.ZodBoolean>;
|
|
48
|
+
structuredOutputMode: z.ZodOptional<z.ZodEnum<{
|
|
49
|
+
outputFormat: "outputFormat";
|
|
50
|
+
jsonTool: "jsonTool";
|
|
51
|
+
auto: "auto";
|
|
52
|
+
}>>;
|
|
48
53
|
thinking: z.ZodOptional<z.ZodObject<{
|
|
49
54
|
type: z.ZodUnion<readonly [z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>;
|
|
50
55
|
budgetTokens: z.ZodOptional<z.ZodNumber>;
|
|
@@ -73,6 +78,11 @@ declare const anthropicProviderOptions: z.ZodObject<{
|
|
|
73
78
|
}, z.core.$strip>>>;
|
|
74
79
|
}, z.core.$strip>>;
|
|
75
80
|
toolStreaming: z.ZodOptional<z.ZodBoolean>;
|
|
81
|
+
effort: z.ZodOptional<z.ZodEnum<{
|
|
82
|
+
low: "low";
|
|
83
|
+
medium: "medium";
|
|
84
|
+
high: "high";
|
|
85
|
+
}>>;
|
|
76
86
|
}, z.core.$strip>;
|
|
77
87
|
type AnthropicProviderOptions = z.infer<typeof anthropicProviderOptions>;
|
|
78
88
|
|
package/dist/index.d.ts
CHANGED
|
@@ -42,9 +42,14 @@ interface AnthropicMessageMetadata {
|
|
|
42
42
|
} | null;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
type AnthropicMessagesModelId = 'claude-haiku-
|
|
45
|
+
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 & {});
|
|
46
46
|
declare const anthropicProviderOptions: z.ZodObject<{
|
|
47
47
|
sendReasoning: z.ZodOptional<z.ZodBoolean>;
|
|
48
|
+
structuredOutputMode: z.ZodOptional<z.ZodEnum<{
|
|
49
|
+
outputFormat: "outputFormat";
|
|
50
|
+
jsonTool: "jsonTool";
|
|
51
|
+
auto: "auto";
|
|
52
|
+
}>>;
|
|
48
53
|
thinking: z.ZodOptional<z.ZodObject<{
|
|
49
54
|
type: z.ZodUnion<readonly [z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>;
|
|
50
55
|
budgetTokens: z.ZodOptional<z.ZodNumber>;
|
|
@@ -73,6 +78,11 @@ declare const anthropicProviderOptions: z.ZodObject<{
|
|
|
73
78
|
}, z.core.$strip>>>;
|
|
74
79
|
}, z.core.$strip>>;
|
|
75
80
|
toolStreaming: z.ZodOptional<z.ZodBoolean>;
|
|
81
|
+
effort: z.ZodOptional<z.ZodEnum<{
|
|
82
|
+
low: "low";
|
|
83
|
+
medium: "medium";
|
|
84
|
+
high: "high";
|
|
85
|
+
}>>;
|
|
76
86
|
}, z.core.$strip>;
|
|
77
87
|
type AnthropicProviderOptions = z.infer<typeof anthropicProviderOptions>;
|
|
78
88
|
|
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 ? "3.0.0-beta.
|
|
34
|
+
var VERSION = true ? "3.0.0-beta.58" : "0.0.0-test";
|
|
35
35
|
|
|
36
36
|
// src/anthropic-messages-language-model.ts
|
|
37
37
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -593,6 +593,14 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
593
593
|
* This allows you to deactivate reasoning inputs for models that do not support them.
|
|
594
594
|
*/
|
|
595
595
|
sendReasoning: import_v43.z.boolean().optional(),
|
|
596
|
+
/**
|
|
597
|
+
* Determines how structured outputs are generated.
|
|
598
|
+
*
|
|
599
|
+
* - `outputFormat`: Use the `output_format` parameter to specify the structured output format.
|
|
600
|
+
* - `jsonTool`: Use a special 'json' tool to specify the structured output format.
|
|
601
|
+
* - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool' (default).
|
|
602
|
+
*/
|
|
603
|
+
structuredOutputMode: import_v43.z.enum(["outputFormat", "jsonTool", "auto"]).optional(),
|
|
596
604
|
/**
|
|
597
605
|
* Configuration for enabling Claude's extended thinking.
|
|
598
606
|
*
|
|
@@ -654,7 +662,11 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
654
662
|
*
|
|
655
663
|
* @default true
|
|
656
664
|
*/
|
|
657
|
-
toolStreaming: import_v43.z.boolean().optional()
|
|
665
|
+
toolStreaming: import_v43.z.boolean().optional(),
|
|
666
|
+
/**
|
|
667
|
+
* @default 'high'
|
|
668
|
+
*/
|
|
669
|
+
effort: import_v43.z.enum(["low", "medium", "high"]).optional()
|
|
658
670
|
});
|
|
659
671
|
|
|
660
672
|
// src/anthropic-prepare-tools.ts
|
|
@@ -1906,7 +1918,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1906
1918
|
providerOptions,
|
|
1907
1919
|
stream
|
|
1908
1920
|
}) {
|
|
1909
|
-
var _a, _b, _c, _d, _e;
|
|
1921
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1910
1922
|
const warnings = [];
|
|
1911
1923
|
if (frequencyPenalty != null) {
|
|
1912
1924
|
warnings.push({
|
|
@@ -1950,27 +1962,33 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1950
1962
|
});
|
|
1951
1963
|
}
|
|
1952
1964
|
}
|
|
1953
|
-
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
|
|
1954
|
-
type: "function",
|
|
1955
|
-
name: "json",
|
|
1956
|
-
description: "Respond with a JSON object.",
|
|
1957
|
-
inputSchema: responseFormat.schema
|
|
1958
|
-
} : void 0;
|
|
1959
1965
|
const anthropicOptions = await (0, import_provider_utils11.parseProviderOptions)({
|
|
1960
1966
|
provider: "anthropic",
|
|
1961
1967
|
providerOptions,
|
|
1962
1968
|
schema: anthropicProviderOptions
|
|
1963
1969
|
});
|
|
1970
|
+
const {
|
|
1971
|
+
maxOutputTokens: maxOutputTokensForModel,
|
|
1972
|
+
supportsStructuredOutput,
|
|
1973
|
+
isKnownModel
|
|
1974
|
+
} = getModelCapabilities(this.modelId);
|
|
1975
|
+
const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : "auto";
|
|
1976
|
+
const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
1977
|
+
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
|
|
1978
|
+
type: "function",
|
|
1979
|
+
name: "json",
|
|
1980
|
+
description: "Respond with a JSON object.",
|
|
1981
|
+
inputSchema: responseFormat.schema
|
|
1982
|
+
} : void 0;
|
|
1964
1983
|
const cacheControlValidator = new CacheControlValidator();
|
|
1965
1984
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
1966
1985
|
prompt,
|
|
1967
|
-
sendReasoning: (
|
|
1986
|
+
sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
|
|
1968
1987
|
warnings,
|
|
1969
1988
|
cacheControlValidator
|
|
1970
1989
|
});
|
|
1971
|
-
const isThinking = ((
|
|
1972
|
-
const thinkingBudget = (
|
|
1973
|
-
const { maxOutputTokens: maxOutputTokensForModel, knownModel } = getMaxOutputTokensForModel(this.modelId);
|
|
1990
|
+
const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
|
|
1991
|
+
const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
|
|
1974
1992
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
1975
1993
|
const baseArgs = {
|
|
1976
1994
|
// model id:
|
|
@@ -1985,6 +2003,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1985
2003
|
...isThinking && {
|
|
1986
2004
|
thinking: { type: "enabled", budget_tokens: thinkingBudget }
|
|
1987
2005
|
},
|
|
2006
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
|
|
2007
|
+
output_config: { effort: anthropicOptions.effort }
|
|
2008
|
+
},
|
|
2009
|
+
// structured output:
|
|
2010
|
+
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
2011
|
+
output_format: {
|
|
2012
|
+
type: "json_schema",
|
|
2013
|
+
schema: responseFormat.schema
|
|
2014
|
+
}
|
|
2015
|
+
},
|
|
1988
2016
|
// mcp servers:
|
|
1989
2017
|
...(anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0 && {
|
|
1990
2018
|
mcp_servers: anthropicOptions.mcpServers.map((server) => ({
|
|
@@ -2002,7 +2030,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2002
2030
|
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
2003
2031
|
container: {
|
|
2004
2032
|
id: anthropicOptions.container.id,
|
|
2005
|
-
skills: (
|
|
2033
|
+
skills: (_e = anthropicOptions.container.skills) == null ? void 0 : _e.map((skill) => ({
|
|
2006
2034
|
type: skill.type,
|
|
2007
2035
|
skill_id: skill.skillId,
|
|
2008
2036
|
version: skill.version
|
|
@@ -2045,7 +2073,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2045
2073
|
}
|
|
2046
2074
|
baseArgs.max_tokens = maxTokens + thinkingBudget;
|
|
2047
2075
|
}
|
|
2048
|
-
if (
|
|
2076
|
+
if (isKnownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
|
|
2049
2077
|
if (maxOutputTokens != null) {
|
|
2050
2078
|
warnings.push({
|
|
2051
2079
|
type: "unsupported-setting",
|
|
@@ -2071,9 +2099,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2071
2099
|
});
|
|
2072
2100
|
}
|
|
2073
2101
|
}
|
|
2074
|
-
if (
|
|
2102
|
+
if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
|
|
2103
|
+
betas.add("effort-2025-11-24");
|
|
2104
|
+
}
|
|
2105
|
+
if (stream && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _f : true)) {
|
|
2075
2106
|
betas.add("fine-grained-tool-streaming-2025-05-14");
|
|
2076
2107
|
}
|
|
2108
|
+
if (useStructuredOutput) {
|
|
2109
|
+
betas.add("structured-outputs-2025-11-13");
|
|
2110
|
+
}
|
|
2077
2111
|
const {
|
|
2078
2112
|
tools: anthropicTools2,
|
|
2079
2113
|
toolChoice: anthropicToolChoice,
|
|
@@ -2950,17 +2984,49 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2950
2984
|
};
|
|
2951
2985
|
}
|
|
2952
2986
|
};
|
|
2953
|
-
function
|
|
2954
|
-
if (modelId.includes("claude-sonnet-4-
|
|
2955
|
-
return {
|
|
2987
|
+
function getModelCapabilities(modelId) {
|
|
2988
|
+
if (modelId.includes("claude-sonnet-4-5")) {
|
|
2989
|
+
return {
|
|
2990
|
+
maxOutputTokens: 64e3,
|
|
2991
|
+
supportsStructuredOutput: true,
|
|
2992
|
+
isKnownModel: true
|
|
2993
|
+
};
|
|
2994
|
+
} else if (modelId.includes("claude-opus-4-1") || modelId.includes("claude-opus-4-5")) {
|
|
2995
|
+
return {
|
|
2996
|
+
maxOutputTokens: 32e3,
|
|
2997
|
+
supportsStructuredOutput: true,
|
|
2998
|
+
isKnownModel: true
|
|
2999
|
+
};
|
|
3000
|
+
} else if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet") || modelId.includes("claude-haiku-4-5")) {
|
|
3001
|
+
return {
|
|
3002
|
+
maxOutputTokens: 64e3,
|
|
3003
|
+
supportsStructuredOutput: false,
|
|
3004
|
+
isKnownModel: true
|
|
3005
|
+
};
|
|
2956
3006
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
2957
|
-
return {
|
|
3007
|
+
return {
|
|
3008
|
+
maxOutputTokens: 32e3,
|
|
3009
|
+
supportsStructuredOutput: false,
|
|
3010
|
+
isKnownModel: true
|
|
3011
|
+
};
|
|
2958
3012
|
} else if (modelId.includes("claude-3-5-haiku")) {
|
|
2959
|
-
return {
|
|
3013
|
+
return {
|
|
3014
|
+
maxOutputTokens: 8192,
|
|
3015
|
+
supportsStructuredOutput: false,
|
|
3016
|
+
isKnownModel: true
|
|
3017
|
+
};
|
|
2960
3018
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
2961
|
-
return {
|
|
3019
|
+
return {
|
|
3020
|
+
maxOutputTokens: 4096,
|
|
3021
|
+
supportsStructuredOutput: false,
|
|
3022
|
+
isKnownModel: true
|
|
3023
|
+
};
|
|
2962
3024
|
} else {
|
|
2963
|
-
return {
|
|
3025
|
+
return {
|
|
3026
|
+
maxOutputTokens: 4096,
|
|
3027
|
+
supportsStructuredOutput: false,
|
|
3028
|
+
isKnownModel: false
|
|
3029
|
+
};
|
|
2964
3030
|
}
|
|
2965
3031
|
}
|
|
2966
3032
|
|