@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/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "@ai-sdk/provider-utils";
|
|
12
12
|
|
|
13
13
|
// src/version.ts
|
|
14
|
-
var VERSION = true ? "3.0.0-beta.
|
|
14
|
+
var VERSION = true ? "3.0.0-beta.57" : "0.0.0-test";
|
|
15
15
|
|
|
16
16
|
// src/anthropic-messages-language-model.ts
|
|
17
17
|
import {
|
|
@@ -581,7 +581,26 @@ var anthropicFilePartProviderOptions = z3.object({
|
|
|
581
581
|
context: z3.string().optional()
|
|
582
582
|
});
|
|
583
583
|
var anthropicProviderOptions = z3.object({
|
|
584
|
+
/**
|
|
585
|
+
* Whether to send reasoning to the model.
|
|
586
|
+
*
|
|
587
|
+
* This allows you to deactivate reasoning inputs for models that do not support them.
|
|
588
|
+
*/
|
|
584
589
|
sendReasoning: z3.boolean().optional(),
|
|
590
|
+
/**
|
|
591
|
+
* Determines how structured outputs are generated.
|
|
592
|
+
*
|
|
593
|
+
* - `outputFormat`: Use the `output_format` parameter to specify the structured output format.
|
|
594
|
+
* - `jsonTool`: Use a special 'json' tool to specify the structured output format.
|
|
595
|
+
* - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool' (default).
|
|
596
|
+
*/
|
|
597
|
+
structuredOutputMode: z3.enum(["outputFormat", "jsonTool", "auto"]).optional(),
|
|
598
|
+
/**
|
|
599
|
+
* Configuration for enabling Claude's extended thinking.
|
|
600
|
+
*
|
|
601
|
+
* When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
|
|
602
|
+
* Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
|
|
603
|
+
*/
|
|
585
604
|
thinking: z3.object({
|
|
586
605
|
type: z3.union([z3.literal("enabled"), z3.literal("disabled")]),
|
|
587
606
|
budgetTokens: z3.number().optional()
|
|
@@ -599,6 +618,9 @@ var anthropicProviderOptions = z3.object({
|
|
|
599
618
|
type: z3.literal("ephemeral"),
|
|
600
619
|
ttl: z3.union([z3.literal("5m"), z3.literal("1h")]).optional()
|
|
601
620
|
}).optional(),
|
|
621
|
+
/**
|
|
622
|
+
* MCP servers to be utilized in this request.
|
|
623
|
+
*/
|
|
602
624
|
mcpServers: z3.array(
|
|
603
625
|
z3.object({
|
|
604
626
|
type: z3.literal("url"),
|
|
@@ -1911,7 +1933,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1911
1933
|
providerOptions,
|
|
1912
1934
|
stream
|
|
1913
1935
|
}) {
|
|
1914
|
-
var _a, _b, _c, _d, _e;
|
|
1936
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1915
1937
|
const warnings = [];
|
|
1916
1938
|
if (frequencyPenalty != null) {
|
|
1917
1939
|
warnings.push({
|
|
@@ -1955,27 +1977,33 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1955
1977
|
});
|
|
1956
1978
|
}
|
|
1957
1979
|
}
|
|
1958
|
-
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
|
|
1959
|
-
type: "function",
|
|
1960
|
-
name: "json",
|
|
1961
|
-
description: "Respond with a JSON object.",
|
|
1962
|
-
inputSchema: responseFormat.schema
|
|
1963
|
-
} : void 0;
|
|
1964
1980
|
const anthropicOptions = await parseProviderOptions2({
|
|
1965
1981
|
provider: "anthropic",
|
|
1966
1982
|
providerOptions,
|
|
1967
1983
|
schema: anthropicProviderOptions
|
|
1968
1984
|
});
|
|
1985
|
+
const {
|
|
1986
|
+
maxOutputTokens: maxOutputTokensForModel,
|
|
1987
|
+
supportsStructuredOutput,
|
|
1988
|
+
isKnownModel
|
|
1989
|
+
} = getModelCapabilities(this.modelId);
|
|
1990
|
+
const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : "auto";
|
|
1991
|
+
const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
1992
|
+
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
|
|
1993
|
+
type: "function",
|
|
1994
|
+
name: "json",
|
|
1995
|
+
description: "Respond with a JSON object.",
|
|
1996
|
+
inputSchema: responseFormat.schema
|
|
1997
|
+
} : void 0;
|
|
1969
1998
|
const cacheControlValidator = new CacheControlValidator();
|
|
1970
1999
|
const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
|
|
1971
2000
|
prompt,
|
|
1972
|
-
sendReasoning: (
|
|
2001
|
+
sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
|
|
1973
2002
|
warnings,
|
|
1974
2003
|
cacheControlValidator
|
|
1975
2004
|
});
|
|
1976
|
-
const isThinking = ((
|
|
1977
|
-
const thinkingBudget = (
|
|
1978
|
-
const { maxOutputTokens: maxOutputTokensForModel, knownModel } = getMaxOutputTokensForModel(this.modelId);
|
|
2005
|
+
const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
|
|
2006
|
+
const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
|
|
1979
2007
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
1980
2008
|
const baseArgs = {
|
|
1981
2009
|
// model id:
|
|
@@ -1990,6 +2018,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1990
2018
|
...isThinking && {
|
|
1991
2019
|
thinking: { type: "enabled", budget_tokens: thinkingBudget }
|
|
1992
2020
|
},
|
|
2021
|
+
// structured output:
|
|
2022
|
+
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
2023
|
+
output_format: {
|
|
2024
|
+
type: "json_schema",
|
|
2025
|
+
schema: responseFormat.schema
|
|
2026
|
+
}
|
|
2027
|
+
},
|
|
1993
2028
|
// mcp servers:
|
|
1994
2029
|
...(anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0 && {
|
|
1995
2030
|
mcp_servers: anthropicOptions.mcpServers.map((server) => ({
|
|
@@ -2007,7 +2042,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2007
2042
|
...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
2008
2043
|
container: {
|
|
2009
2044
|
id: anthropicOptions.container.id,
|
|
2010
|
-
skills: (
|
|
2045
|
+
skills: (_e = anthropicOptions.container.skills) == null ? void 0 : _e.map((skill) => ({
|
|
2011
2046
|
type: skill.type,
|
|
2012
2047
|
skill_id: skill.skillId,
|
|
2013
2048
|
version: skill.version
|
|
@@ -2050,7 +2085,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2050
2085
|
}
|
|
2051
2086
|
baseArgs.max_tokens = maxTokens + thinkingBudget;
|
|
2052
2087
|
}
|
|
2053
|
-
if (
|
|
2088
|
+
if (isKnownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
|
|
2054
2089
|
if (maxOutputTokens != null) {
|
|
2055
2090
|
warnings.push({
|
|
2056
2091
|
type: "unsupported-setting",
|
|
@@ -2076,9 +2111,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2076
2111
|
});
|
|
2077
2112
|
}
|
|
2078
2113
|
}
|
|
2079
|
-
if (stream && ((
|
|
2114
|
+
if (stream && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _f : true)) {
|
|
2080
2115
|
betas.add("fine-grained-tool-streaming-2025-05-14");
|
|
2081
2116
|
}
|
|
2117
|
+
if (useStructuredOutput) {
|
|
2118
|
+
betas.add("structured-outputs-2025-11-13");
|
|
2119
|
+
}
|
|
2082
2120
|
const {
|
|
2083
2121
|
tools: anthropicTools2,
|
|
2084
2122
|
toolChoice: anthropicToolChoice,
|
|
@@ -2955,17 +2993,49 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2955
2993
|
};
|
|
2956
2994
|
}
|
|
2957
2995
|
};
|
|
2958
|
-
function
|
|
2959
|
-
if (modelId.includes("claude-sonnet-4-
|
|
2960
|
-
return {
|
|
2996
|
+
function getModelCapabilities(modelId) {
|
|
2997
|
+
if (modelId.includes("claude-sonnet-4-5")) {
|
|
2998
|
+
return {
|
|
2999
|
+
maxOutputTokens: 64e3,
|
|
3000
|
+
supportsStructuredOutput: true,
|
|
3001
|
+
isKnownModel: true
|
|
3002
|
+
};
|
|
3003
|
+
} else if (modelId.includes("claude-opus-4-1")) {
|
|
3004
|
+
return {
|
|
3005
|
+
maxOutputTokens: 32e3,
|
|
3006
|
+
supportsStructuredOutput: true,
|
|
3007
|
+
isKnownModel: true
|
|
3008
|
+
};
|
|
3009
|
+
} else if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet") || modelId.includes("claude-haiku-4-5")) {
|
|
3010
|
+
return {
|
|
3011
|
+
maxOutputTokens: 64e3,
|
|
3012
|
+
supportsStructuredOutput: false,
|
|
3013
|
+
isKnownModel: true
|
|
3014
|
+
};
|
|
2961
3015
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
2962
|
-
return {
|
|
3016
|
+
return {
|
|
3017
|
+
maxOutputTokens: 32e3,
|
|
3018
|
+
supportsStructuredOutput: false,
|
|
3019
|
+
isKnownModel: true
|
|
3020
|
+
};
|
|
2963
3021
|
} else if (modelId.includes("claude-3-5-haiku")) {
|
|
2964
|
-
return {
|
|
3022
|
+
return {
|
|
3023
|
+
maxOutputTokens: 8192,
|
|
3024
|
+
supportsStructuredOutput: false,
|
|
3025
|
+
isKnownModel: true
|
|
3026
|
+
};
|
|
2965
3027
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
2966
|
-
return {
|
|
3028
|
+
return {
|
|
3029
|
+
maxOutputTokens: 4096,
|
|
3030
|
+
supportsStructuredOutput: false,
|
|
3031
|
+
isKnownModel: true
|
|
3032
|
+
};
|
|
2967
3033
|
} else {
|
|
2968
|
-
return {
|
|
3034
|
+
return {
|
|
3035
|
+
maxOutputTokens: 4096,
|
|
3036
|
+
supportsStructuredOutput: false,
|
|
3037
|
+
isKnownModel: false
|
|
3038
|
+
};
|
|
2969
3039
|
}
|
|
2970
3040
|
}
|
|
2971
3041
|
|