@ai-sdk/anthropic 3.0.0-beta.55 → 3.0.0-beta.57
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 +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +92 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +92 -22
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +91 -21
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +91 -21
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 3.0.0-beta.57
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b8ea36e: feat(provider/anthropic): Anthropic-native structured outputs
|
|
8
|
+
|
|
9
|
+
## 3.0.0-beta.56
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 983e394: chore(provider/anthropic): add missing provider options jsdoc
|
|
14
|
+
|
|
3
15
|
## 3.0.0-beta.55
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -45,6 +45,11 @@ interface AnthropicMessageMetadata {
|
|
|
45
45
|
type AnthropicMessagesModelId = 'claude-haiku-4-5' | 'claude-haiku-4-5-20251001' | 'claude-sonnet-4-5' | 'claude-sonnet-4-5-20250929' | 'claude-opus-4-1' | 'claude-opus-4-0' | 'claude-sonnet-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-20250514' | 'claude-sonnet-4-20250514' | 'claude-3-7-sonnet-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-5-haiku-latest' | 'claude-3-5-haiku-20241022' | 'claude-3-haiku-20240307' | (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>;
|
package/dist/index.d.ts
CHANGED
|
@@ -45,6 +45,11 @@ interface AnthropicMessageMetadata {
|
|
|
45
45
|
type AnthropicMessagesModelId = 'claude-haiku-4-5' | 'claude-haiku-4-5-20251001' | 'claude-sonnet-4-5' | 'claude-sonnet-4-5-20250929' | 'claude-opus-4-1' | 'claude-opus-4-0' | 'claude-sonnet-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-20250514' | 'claude-sonnet-4-20250514' | 'claude-3-7-sonnet-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-5-haiku-latest' | 'claude-3-5-haiku-20241022' | 'claude-3-haiku-20240307' | (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>;
|
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.57" : "0.0.0-test";
|
|
35
35
|
|
|
36
36
|
// src/anthropic-messages-language-model.ts
|
|
37
37
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -587,7 +587,26 @@ var anthropicFilePartProviderOptions = import_v43.z.object({
|
|
|
587
587
|
context: import_v43.z.string().optional()
|
|
588
588
|
});
|
|
589
589
|
var anthropicProviderOptions = import_v43.z.object({
|
|
590
|
+
/**
|
|
591
|
+
* Whether to send reasoning to the model.
|
|
592
|
+
*
|
|
593
|
+
* This allows you to deactivate reasoning inputs for models that do not support them.
|
|
594
|
+
*/
|
|
590
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(),
|
|
604
|
+
/**
|
|
605
|
+
* Configuration for enabling Claude's extended thinking.
|
|
606
|
+
*
|
|
607
|
+
* When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
|
|
608
|
+
* Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
|
|
609
|
+
*/
|
|
591
610
|
thinking: import_v43.z.object({
|
|
592
611
|
type: import_v43.z.union([import_v43.z.literal("enabled"), import_v43.z.literal("disabled")]),
|
|
593
612
|
budgetTokens: import_v43.z.number().optional()
|
|
@@ -605,6 +624,9 @@ var anthropicProviderOptions = import_v43.z.object({
|
|
|
605
624
|
type: import_v43.z.literal("ephemeral"),
|
|
606
625
|
ttl: import_v43.z.union([import_v43.z.literal("5m"), import_v43.z.literal("1h")]).optional()
|
|
607
626
|
}).optional(),
|
|
627
|
+
/**
|
|
628
|
+
* MCP servers to be utilized in this request.
|
|
629
|
+
*/
|
|
608
630
|
mcpServers: import_v43.z.array(
|
|
609
631
|
import_v43.z.object({
|
|
610
632
|
type: import_v43.z.literal("url"),
|
|
@@ -1892,7 +1914,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1892
1914
|
providerOptions,
|
|
1893
1915
|
stream
|
|
1894
1916
|
}) {
|
|
1895
|
-
var _a, _b, _c, _d, _e;
|
|
1917
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1896
1918
|
const warnings = [];
|
|
1897
1919
|
if (frequencyPenalty != null) {
|
|
1898
1920
|
warnings.push({
|
|
@@ -1936,27 +1958,33 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1936
1958
|
});
|
|
1937
1959
|
}
|
|
1938
1960
|
}
|
|
1939
|
-
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
|
|
1940
|
-
type: "function",
|
|
1941
|
-
name: "json",
|
|
1942
|
-
description: "Respond with a JSON object.",
|
|
1943
|
-
inputSchema: responseFormat.schema
|
|
1944
|
-
} : void 0;
|
|
1945
1961
|
const anthropicOptions = await (0, import_provider_utils11.parseProviderOptions)({
|
|
1946
1962
|
provider: "anthropic",
|
|
1947
1963
|
providerOptions,
|
|
1948
1964
|
schema: anthropicProviderOptions
|
|
1949
1965
|
});
|
|
1966
|
+
const {
|
|
1967
|
+
maxOutputTokens: maxOutputTokensForModel,
|
|
1968
|
+
supportsStructuredOutput,
|
|
1969
|
+
isKnownModel
|
|
1970
|
+
} = getModelCapabilities(this.modelId);
|
|
1971
|
+
const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : "auto";
|
|
1972
|
+
const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
1973
|
+
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
|
|
1974
|
+
type: "function",
|
|
1975
|
+
name: "json",
|
|
1976
|
+
description: "Respond with a JSON object.",
|
|
1977
|
+
inputSchema: responseFormat.schema
|
|
1978
|
+
} : void 0;
|
|
1950
1979
|
const cacheControlValidator = new CacheControlValidator();
|
|
1951
1980
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
1952
1981
|
prompt,
|
|
1953
|
-
sendReasoning: (
|
|
1982
|
+
sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
|
|
1954
1983
|
warnings,
|
|
1955
1984
|
cacheControlValidator
|
|
1956
1985
|
});
|
|
1957
|
-
const isThinking = ((
|
|
1958
|
-
const thinkingBudget = (
|
|
1959
|
-
const { maxOutputTokens: maxOutputTokensForModel, knownModel } = getMaxOutputTokensForModel(this.modelId);
|
|
1986
|
+
const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
|
|
1987
|
+
const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
|
|
1960
1988
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
1961
1989
|
const baseArgs = {
|
|
1962
1990
|
// model id:
|
|
@@ -1971,6 +1999,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1971
1999
|
...isThinking && {
|
|
1972
2000
|
thinking: { type: "enabled", budget_tokens: thinkingBudget }
|
|
1973
2001
|
},
|
|
2002
|
+
// structured output:
|
|
2003
|
+
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
2004
|
+
output_format: {
|
|
2005
|
+
type: "json_schema",
|
|
2006
|
+
schema: responseFormat.schema
|
|
2007
|
+
}
|
|
2008
|
+
},
|
|
1974
2009
|
// mcp servers:
|
|
1975
2010
|
...(anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0 && {
|
|
1976
2011
|
mcp_servers: anthropicOptions.mcpServers.map((server) => ({
|
|
@@ -1988,7 +2023,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1988
2023
|
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
1989
2024
|
container: {
|
|
1990
2025
|
id: anthropicOptions.container.id,
|
|
1991
|
-
skills: (
|
|
2026
|
+
skills: (_e = anthropicOptions.container.skills) == null ? void 0 : _e.map((skill) => ({
|
|
1992
2027
|
type: skill.type,
|
|
1993
2028
|
skill_id: skill.skillId,
|
|
1994
2029
|
version: skill.version
|
|
@@ -2031,7 +2066,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2031
2066
|
}
|
|
2032
2067
|
baseArgs.max_tokens = maxTokens + thinkingBudget;
|
|
2033
2068
|
}
|
|
2034
|
-
if (
|
|
2069
|
+
if (isKnownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
|
|
2035
2070
|
if (maxOutputTokens != null) {
|
|
2036
2071
|
warnings.push({
|
|
2037
2072
|
type: "unsupported-setting",
|
|
@@ -2057,9 +2092,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2057
2092
|
});
|
|
2058
2093
|
}
|
|
2059
2094
|
}
|
|
2060
|
-
if (stream && ((
|
|
2095
|
+
if (stream && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _f : true)) {
|
|
2061
2096
|
betas.add("fine-grained-tool-streaming-2025-05-14");
|
|
2062
2097
|
}
|
|
2098
|
+
if (useStructuredOutput) {
|
|
2099
|
+
betas.add("structured-outputs-2025-11-13");
|
|
2100
|
+
}
|
|
2063
2101
|
const {
|
|
2064
2102
|
tools: anthropicTools2,
|
|
2065
2103
|
toolChoice: anthropicToolChoice,
|
|
@@ -2936,17 +2974,49 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2936
2974
|
};
|
|
2937
2975
|
}
|
|
2938
2976
|
};
|
|
2939
|
-
function
|
|
2940
|
-
if (modelId.includes("claude-sonnet-4-
|
|
2941
|
-
return {
|
|
2977
|
+
function getModelCapabilities(modelId) {
|
|
2978
|
+
if (modelId.includes("claude-sonnet-4-5")) {
|
|
2979
|
+
return {
|
|
2980
|
+
maxOutputTokens: 64e3,
|
|
2981
|
+
supportsStructuredOutput: true,
|
|
2982
|
+
isKnownModel: true
|
|
2983
|
+
};
|
|
2984
|
+
} else if (modelId.includes("claude-opus-4-1")) {
|
|
2985
|
+
return {
|
|
2986
|
+
maxOutputTokens: 32e3,
|
|
2987
|
+
supportsStructuredOutput: true,
|
|
2988
|
+
isKnownModel: true
|
|
2989
|
+
};
|
|
2990
|
+
} else if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet") || modelId.includes("claude-haiku-4-5")) {
|
|
2991
|
+
return {
|
|
2992
|
+
maxOutputTokens: 64e3,
|
|
2993
|
+
supportsStructuredOutput: false,
|
|
2994
|
+
isKnownModel: true
|
|
2995
|
+
};
|
|
2942
2996
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
2943
|
-
return {
|
|
2997
|
+
return {
|
|
2998
|
+
maxOutputTokens: 32e3,
|
|
2999
|
+
supportsStructuredOutput: false,
|
|
3000
|
+
isKnownModel: true
|
|
3001
|
+
};
|
|
2944
3002
|
} else if (modelId.includes("claude-3-5-haiku")) {
|
|
2945
|
-
return {
|
|
3003
|
+
return {
|
|
3004
|
+
maxOutputTokens: 8192,
|
|
3005
|
+
supportsStructuredOutput: false,
|
|
3006
|
+
isKnownModel: true
|
|
3007
|
+
};
|
|
2946
3008
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
2947
|
-
return {
|
|
3009
|
+
return {
|
|
3010
|
+
maxOutputTokens: 4096,
|
|
3011
|
+
supportsStructuredOutput: false,
|
|
3012
|
+
isKnownModel: true
|
|
3013
|
+
};
|
|
2948
3014
|
} else {
|
|
2949
|
-
return {
|
|
3015
|
+
return {
|
|
3016
|
+
maxOutputTokens: 4096,
|
|
3017
|
+
supportsStructuredOutput: false,
|
|
3018
|
+
isKnownModel: false
|
|
3019
|
+
};
|
|
2950
3020
|
}
|
|
2951
3021
|
}
|
|
2952
3022
|
|