@ai-sdk/anthropic 3.0.127 → 3.0.129
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +56 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -10
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +8 -1
- package/dist/internal/index.d.ts +8 -1
- package/dist/internal/index.js +55 -9
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +55 -9
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +14 -2
- package/package.json +1 -1
- package/src/anthropic-messages-api.ts +1 -0
- package/src/anthropic-messages-language-model.ts +58 -12
- package/src/anthropic-messages-options.ts +1 -0
- package/src/anthropic-prepare-tools.ts +6 -2
- package/src/convert-to-anthropic-messages-prompt.ts +24 -0
|
@@ -2,7 +2,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
|
|
|
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-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | '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' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | 'claude-sonnet-5-5' | (string & {});
|
|
5
|
+
type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-haiku-5-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | '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' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | 'claude-sonnet-5-5' | (string & {});
|
|
6
6
|
|
|
7
7
|
type AnthropicMessagesConfig = {
|
|
8
8
|
provider: string;
|
|
@@ -62,6 +62,11 @@ declare function getModelCapabilities(modelId: string): {
|
|
|
62
62
|
* are rejected with a 400.
|
|
63
63
|
*/
|
|
64
64
|
rejectsThinkingDisabled: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Budget-based thinking (`thinking.type` `enabled` with `budget_tokens`) is
|
|
67
|
+
* rejected with a 400. Only adaptive thinking is supported.
|
|
68
|
+
*/
|
|
69
|
+
rejectsBudgetThinking: boolean;
|
|
65
70
|
/**
|
|
66
71
|
* Forced tool use (`tool_choice` `any` or a named tool) is rejected with a 400.
|
|
67
72
|
*/
|
|
@@ -1077,6 +1082,8 @@ type AnthropicTool = {
|
|
|
1077
1082
|
type AnthropicToolChoice = {
|
|
1078
1083
|
type: 'auto' | 'any';
|
|
1079
1084
|
disable_parallel_tool_use?: boolean;
|
|
1085
|
+
} | {
|
|
1086
|
+
type: 'none';
|
|
1080
1087
|
} | {
|
|
1081
1088
|
type: 'tool';
|
|
1082
1089
|
name: string;
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
|
|
|
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-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | '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' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | 'claude-sonnet-5-5' | (string & {});
|
|
5
|
+
type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-haiku-5-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | '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' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | 'claude-sonnet-5-5' | (string & {});
|
|
6
6
|
|
|
7
7
|
type AnthropicMessagesConfig = {
|
|
8
8
|
provider: string;
|
|
@@ -62,6 +62,11 @@ declare function getModelCapabilities(modelId: string): {
|
|
|
62
62
|
* are rejected with a 400.
|
|
63
63
|
*/
|
|
64
64
|
rejectsThinkingDisabled: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Budget-based thinking (`thinking.type` `enabled` with `budget_tokens`) is
|
|
67
|
+
* rejected with a 400. Only adaptive thinking is supported.
|
|
68
|
+
*/
|
|
69
|
+
rejectsBudgetThinking: boolean;
|
|
65
70
|
/**
|
|
66
71
|
* Forced tool use (`tool_choice` `any` or a named tool) is rejected with a 400.
|
|
67
72
|
*/
|
|
@@ -1077,6 +1082,8 @@ type AnthropicTool = {
|
|
|
1077
1082
|
type AnthropicToolChoice = {
|
|
1078
1083
|
type: 'auto' | 'any';
|
|
1079
1084
|
disable_parallel_tool_use?: boolean;
|
|
1085
|
+
} | {
|
|
1086
|
+
type: 'none';
|
|
1080
1087
|
} | {
|
|
1081
1088
|
type: 'tool';
|
|
1082
1089
|
name: string;
|
package/dist/internal/index.js
CHANGED
|
@@ -1984,7 +1984,12 @@ async function prepareTools({
|
|
|
1984
1984
|
betas
|
|
1985
1985
|
};
|
|
1986
1986
|
case "none":
|
|
1987
|
-
return {
|
|
1987
|
+
return {
|
|
1988
|
+
tools: anthropicTools2,
|
|
1989
|
+
toolChoice: { type: "none" },
|
|
1990
|
+
toolWarnings,
|
|
1991
|
+
betas
|
|
1992
|
+
};
|
|
1988
1993
|
case "tool":
|
|
1989
1994
|
if (rejectsForcedToolUse) {
|
|
1990
1995
|
toolWarnings.push({
|
|
@@ -2433,7 +2438,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
2433
2438
|
toolNameMapping,
|
|
2434
2439
|
toolsetNames = {}
|
|
2435
2440
|
}) {
|
|
2436
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
2441
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
2437
2442
|
const betas = /* @__PURE__ */ new Set();
|
|
2438
2443
|
const blocks = groupIntoBlocks(prompt);
|
|
2439
2444
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -3245,6 +3250,18 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
3245
3250
|
}
|
|
3246
3251
|
if (providerToolName === "tool_search_tool_regex" || providerToolName === "tool_search_tool_bm25") {
|
|
3247
3252
|
const output = part.output;
|
|
3253
|
+
if (output.type === "error-json" || output.type === "json" && output.value != null && typeof output.value === "object" && !Array.isArray(output.value) && "type" in output.value && output.value.type === "tool_search_tool_result_error") {
|
|
3254
|
+
anthropicContent.push({
|
|
3255
|
+
type: "tool_search_tool_result",
|
|
3256
|
+
tool_use_id: part.toolCallId,
|
|
3257
|
+
content: {
|
|
3258
|
+
type: "tool_search_tool_result_error",
|
|
3259
|
+
error_code: (_v = (await extractErrorValue(output.value)).errorCode) != null ? _v : "unavailable"
|
|
3260
|
+
},
|
|
3261
|
+
cache_control: cacheControl
|
|
3262
|
+
});
|
|
3263
|
+
break;
|
|
3264
|
+
}
|
|
3248
3265
|
if (output.type !== "json") {
|
|
3249
3266
|
warnings.push({
|
|
3250
3267
|
type: "other",
|
|
@@ -3816,6 +3833,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3816
3833
|
rejectsSamplingParameters,
|
|
3817
3834
|
rejectsThinkingDisabledAboveHighEffort,
|
|
3818
3835
|
rejectsThinkingDisabled,
|
|
3836
|
+
rejectsBudgetThinking,
|
|
3819
3837
|
rejectsForcedToolUse,
|
|
3820
3838
|
supportsBetweenToolsThinking,
|
|
3821
3839
|
isKnownModel
|
|
@@ -3933,15 +3951,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3933
3951
|
details: `thinking cannot be disabled for ${this.modelId}; it always uses adaptive thinking. The thinking setting has been removed. Lower 'effort' to reduce thinking.`
|
|
3934
3952
|
});
|
|
3935
3953
|
anthropicOptions.thinking = void 0;
|
|
3936
|
-
} else if (requestedType === "enabled") {
|
|
3937
|
-
warnings.push({
|
|
3938
|
-
type: "unsupported",
|
|
3939
|
-
feature: "providerOptions.anthropic.thinking",
|
|
3940
|
-
details: `budget-based thinking is not supported by ${this.modelId}; it always uses adaptive thinking. Using adaptive thinking instead. Use 'effort' to control how much the model thinks.`
|
|
3941
|
-
});
|
|
3942
|
-
anthropicOptions.thinking = { type: "adaptive" };
|
|
3943
3954
|
}
|
|
3944
3955
|
}
|
|
3956
|
+
if (rejectsBudgetThinking && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null && "type" in anthropicOptions.thinking && anthropicOptions.thinking.type === "enabled") {
|
|
3957
|
+
warnings.push({
|
|
3958
|
+
type: "unsupported",
|
|
3959
|
+
feature: "providerOptions.anthropic.thinking",
|
|
3960
|
+
details: rejectsThinkingDisabled ? `budget-based thinking is not supported by ${this.modelId}; it always uses adaptive thinking. Using adaptive thinking instead. Use 'effort' to control how much the model thinks.` : `budget-based thinking is not supported by ${this.modelId}. Using adaptive thinking instead. Use 'effort' to control how much the model thinks.`
|
|
3961
|
+
});
|
|
3962
|
+
anthropicOptions.thinking = { type: "adaptive" };
|
|
3963
|
+
}
|
|
3945
3964
|
const thinking = anthropicOptions == null ? void 0 : anthropicOptions.thinking;
|
|
3946
3965
|
const thinkingType = thinking != null && "type" in thinking ? thinking.type : void 0;
|
|
3947
3966
|
if (rejectsThinkingDisabledAboveHighEffort && thinkingType === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
|
|
@@ -5820,6 +5839,7 @@ function getModelCapabilities(modelId) {
|
|
|
5820
5839
|
rejectsSamplingParameters: true,
|
|
5821
5840
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5822
5841
|
rejectsThinkingDisabled: true,
|
|
5842
|
+
rejectsBudgetThinking: true,
|
|
5823
5843
|
rejectsForcedToolUse: true,
|
|
5824
5844
|
supportsBetweenToolsThinking: true,
|
|
5825
5845
|
isKnownModel: true
|
|
@@ -5831,10 +5851,23 @@ function getModelCapabilities(modelId) {
|
|
|
5831
5851
|
rejectsSamplingParameters: true,
|
|
5832
5852
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5833
5853
|
rejectsThinkingDisabled: true,
|
|
5854
|
+
rejectsBudgetThinking: true,
|
|
5834
5855
|
rejectsForcedToolUse: true,
|
|
5835
5856
|
supportsBetweenToolsThinking: false,
|
|
5836
5857
|
isKnownModel: true
|
|
5837
5858
|
};
|
|
5859
|
+
} else if (modelId.includes("claude-haiku-5-5")) {
|
|
5860
|
+
return {
|
|
5861
|
+
maxOutputTokens: 128e3,
|
|
5862
|
+
supportsStructuredOutput: true,
|
|
5863
|
+
rejectsSamplingParameters: true,
|
|
5864
|
+
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5865
|
+
rejectsThinkingDisabled: false,
|
|
5866
|
+
rejectsBudgetThinking: true,
|
|
5867
|
+
rejectsForcedToolUse: false,
|
|
5868
|
+
supportsBetweenToolsThinking: false,
|
|
5869
|
+
isKnownModel: true
|
|
5870
|
+
};
|
|
5838
5871
|
} else if (modelId.includes("claude-opus-5")) {
|
|
5839
5872
|
return {
|
|
5840
5873
|
maxOutputTokens: 128e3,
|
|
@@ -5842,6 +5875,7 @@ function getModelCapabilities(modelId) {
|
|
|
5842
5875
|
rejectsSamplingParameters: true,
|
|
5843
5876
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5844
5877
|
rejectsThinkingDisabled: false,
|
|
5878
|
+
rejectsBudgetThinking: false,
|
|
5845
5879
|
rejectsForcedToolUse: false,
|
|
5846
5880
|
supportsBetweenToolsThinking: false,
|
|
5847
5881
|
isKnownModel: true
|
|
@@ -5853,6 +5887,7 @@ function getModelCapabilities(modelId) {
|
|
|
5853
5887
|
rejectsSamplingParameters: true,
|
|
5854
5888
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5855
5889
|
rejectsThinkingDisabled: true,
|
|
5890
|
+
rejectsBudgetThinking: true,
|
|
5856
5891
|
rejectsForcedToolUse: true,
|
|
5857
5892
|
supportsBetweenToolsThinking: false,
|
|
5858
5893
|
isKnownModel: true
|
|
@@ -5864,6 +5899,7 @@ function getModelCapabilities(modelId) {
|
|
|
5864
5899
|
rejectsSamplingParameters: true,
|
|
5865
5900
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5866
5901
|
rejectsThinkingDisabled: true,
|
|
5902
|
+
rejectsBudgetThinking: true,
|
|
5867
5903
|
rejectsForcedToolUse: false,
|
|
5868
5904
|
supportsBetweenToolsThinking: false,
|
|
5869
5905
|
isKnownModel: true
|
|
@@ -5875,6 +5911,7 @@ function getModelCapabilities(modelId) {
|
|
|
5875
5911
|
rejectsSamplingParameters: true,
|
|
5876
5912
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5877
5913
|
rejectsThinkingDisabled: false,
|
|
5914
|
+
rejectsBudgetThinking: false,
|
|
5878
5915
|
rejectsForcedToolUse: false,
|
|
5879
5916
|
supportsBetweenToolsThinking: false,
|
|
5880
5917
|
isKnownModel: true
|
|
@@ -5886,6 +5923,7 @@ function getModelCapabilities(modelId) {
|
|
|
5886
5923
|
rejectsSamplingParameters: false,
|
|
5887
5924
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5888
5925
|
rejectsThinkingDisabled: false,
|
|
5926
|
+
rejectsBudgetThinking: false,
|
|
5889
5927
|
rejectsForcedToolUse: false,
|
|
5890
5928
|
supportsBetweenToolsThinking: false,
|
|
5891
5929
|
isKnownModel: true
|
|
@@ -5897,6 +5935,7 @@ function getModelCapabilities(modelId) {
|
|
|
5897
5935
|
rejectsSamplingParameters: false,
|
|
5898
5936
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5899
5937
|
rejectsThinkingDisabled: false,
|
|
5938
|
+
rejectsBudgetThinking: false,
|
|
5900
5939
|
rejectsForcedToolUse: false,
|
|
5901
5940
|
supportsBetweenToolsThinking: false,
|
|
5902
5941
|
isKnownModel: true
|
|
@@ -5908,6 +5947,7 @@ function getModelCapabilities(modelId) {
|
|
|
5908
5947
|
rejectsSamplingParameters: false,
|
|
5909
5948
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5910
5949
|
rejectsThinkingDisabled: false,
|
|
5950
|
+
rejectsBudgetThinking: false,
|
|
5911
5951
|
rejectsForcedToolUse: false,
|
|
5912
5952
|
supportsBetweenToolsThinking: false,
|
|
5913
5953
|
isKnownModel: true
|
|
@@ -5919,6 +5959,7 @@ function getModelCapabilities(modelId) {
|
|
|
5919
5959
|
rejectsSamplingParameters: false,
|
|
5920
5960
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5921
5961
|
rejectsThinkingDisabled: false,
|
|
5962
|
+
rejectsBudgetThinking: false,
|
|
5922
5963
|
rejectsForcedToolUse: false,
|
|
5923
5964
|
supportsBetweenToolsThinking: false,
|
|
5924
5965
|
isKnownModel: true
|
|
@@ -5930,6 +5971,7 @@ function getModelCapabilities(modelId) {
|
|
|
5930
5971
|
rejectsSamplingParameters: false,
|
|
5931
5972
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5932
5973
|
rejectsThinkingDisabled: false,
|
|
5974
|
+
rejectsBudgetThinking: false,
|
|
5933
5975
|
rejectsForcedToolUse: false,
|
|
5934
5976
|
supportsBetweenToolsThinking: false,
|
|
5935
5977
|
isKnownModel: true
|
|
@@ -5941,6 +5983,7 @@ function getModelCapabilities(modelId) {
|
|
|
5941
5983
|
rejectsSamplingParameters: false,
|
|
5942
5984
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5943
5985
|
rejectsThinkingDisabled: false,
|
|
5986
|
+
rejectsBudgetThinking: false,
|
|
5944
5987
|
rejectsForcedToolUse: false,
|
|
5945
5988
|
supportsBetweenToolsThinking: false,
|
|
5946
5989
|
isKnownModel: true
|
|
@@ -5952,6 +5995,7 @@ function getModelCapabilities(modelId) {
|
|
|
5952
5995
|
rejectsSamplingParameters: false,
|
|
5953
5996
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5954
5997
|
rejectsThinkingDisabled: false,
|
|
5998
|
+
rejectsBudgetThinking: false,
|
|
5955
5999
|
rejectsForcedToolUse: false,
|
|
5956
6000
|
supportsBetweenToolsThinking: false,
|
|
5957
6001
|
isKnownModel: false
|
|
@@ -5963,6 +6007,7 @@ function getModelCapabilities(modelId) {
|
|
|
5963
6007
|
rejectsSamplingParameters: true,
|
|
5964
6008
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5965
6009
|
rejectsThinkingDisabled: false,
|
|
6010
|
+
rejectsBudgetThinking: false,
|
|
5966
6011
|
rejectsForcedToolUse: false,
|
|
5967
6012
|
supportsBetweenToolsThinking: false,
|
|
5968
6013
|
isKnownModel: false
|
|
@@ -5974,6 +6019,7 @@ function getModelCapabilities(modelId) {
|
|
|
5974
6019
|
rejectsSamplingParameters: false,
|
|
5975
6020
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5976
6021
|
rejectsThinkingDisabled: false,
|
|
6022
|
+
rejectsBudgetThinking: false,
|
|
5977
6023
|
rejectsForcedToolUse: false,
|
|
5978
6024
|
supportsBetweenToolsThinking: false,
|
|
5979
6025
|
isKnownModel: false
|