@ai-sdk/anthropic 3.0.126 → 3.0.128
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 +17 -0
- package/dist/index.d.mts +31 -2
- package/dist/index.d.ts +31 -2
- package/dist/index.js +86 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +86 -8
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +6 -1
- package/dist/internal/index.d.ts +6 -1
- package/dist/internal/index.js +85 -7
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +85 -7
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +65 -2
- package/package.json +1 -1
- package/src/anthropic-message-metadata.ts +14 -0
- package/src/anthropic-messages-api.ts +23 -0
- package/src/anthropic-messages-language-model.ts +86 -12
- package/src/anthropic-messages-options.ts +20 -0
package/dist/internal/index.mjs
CHANGED
|
@@ -50,6 +50,20 @@ var anthropicStopDetailsSchema = z2.object({
|
|
|
50
50
|
explanation: z2.string().nullish(),
|
|
51
51
|
recommended_model: z2.string().nullish()
|
|
52
52
|
});
|
|
53
|
+
var anthropicSafeguardResultSchema = z2.object({
|
|
54
|
+
type: z2.string(),
|
|
55
|
+
status: z2.object({
|
|
56
|
+
type: z2.string(),
|
|
57
|
+
tool_uses: z2.record(
|
|
58
|
+
z2.string(),
|
|
59
|
+
z2.object({
|
|
60
|
+
type: z2.string(),
|
|
61
|
+
outcome: z2.string().nullish(),
|
|
62
|
+
explanation: z2.string().nullish()
|
|
63
|
+
})
|
|
64
|
+
).nullish()
|
|
65
|
+
})
|
|
66
|
+
});
|
|
53
67
|
var anthropicToolCallCallerSchema = z2.union([
|
|
54
68
|
z2.object({
|
|
55
69
|
type: z2.literal("code_execution_20250825"),
|
|
@@ -350,6 +364,7 @@ var anthropicMessagesResponseSchema = lazySchema2(
|
|
|
350
364
|
stop_sequence: z2.string().nullish(),
|
|
351
365
|
stop_details: anthropicStopDetailsSchema.nullish(),
|
|
352
366
|
input_transformations: z2.array(anthropicInputTransformationSchema).nullish(),
|
|
367
|
+
safeguard_results: z2.array(anthropicSafeguardResultSchema).nullish(),
|
|
353
368
|
usage: z2.looseObject({
|
|
354
369
|
input_tokens: z2.number(),
|
|
355
370
|
output_tokens: z2.number(),
|
|
@@ -759,6 +774,7 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
759
774
|
stop_reason: z2.string().nullish(),
|
|
760
775
|
stop_sequence: z2.string().nullish(),
|
|
761
776
|
stop_details: anthropicStopDetailsSchema.nullish(),
|
|
777
|
+
safeguard_results: z2.array(anthropicSafeguardResultSchema).nullish(),
|
|
762
778
|
container: z2.object({
|
|
763
779
|
expires_at: z2.string(),
|
|
764
780
|
id: z2.string(),
|
|
@@ -1117,6 +1133,22 @@ var anthropicLanguageModelOptions = z3.object({
|
|
|
1117
1133
|
* Allow a provider to receive the full `betas` set if it needs it.
|
|
1118
1134
|
*/
|
|
1119
1135
|
anthropicBeta: z3.array(z3.string()).optional(),
|
|
1136
|
+
/**
|
|
1137
|
+
* Server-side safeguards to run as part of the request.
|
|
1138
|
+
*
|
|
1139
|
+
* `dangerous_tool_use` asks the API to classify every `tool_use` block in
|
|
1140
|
+
* the response for dangerous actions (the check Claude Code's auto mode
|
|
1141
|
+
* relies on). The per-call verdicts are returned in
|
|
1142
|
+
* `providerMetadata.anthropic.safeguardResults`, keyed by tool call id.
|
|
1143
|
+
* `classifierContext` is passed through to the API as `classifier_context`.
|
|
1144
|
+
* The `dangerous-tool-use-2026-09-03` beta is added automatically.
|
|
1145
|
+
*/
|
|
1146
|
+
safeguards: z3.array(
|
|
1147
|
+
z3.object({
|
|
1148
|
+
type: z3.literal("dangerous_tool_use"),
|
|
1149
|
+
classifierContext: z3.record(z3.string(), z3.unknown()).optional()
|
|
1150
|
+
})
|
|
1151
|
+
).optional(),
|
|
1120
1152
|
contextManagement: z3.object({
|
|
1121
1153
|
edits: z3.array(
|
|
1122
1154
|
z3.discriminatedUnion("type", [
|
|
@@ -3830,6 +3862,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3830
3862
|
rejectsSamplingParameters,
|
|
3831
3863
|
rejectsThinkingDisabledAboveHighEffort,
|
|
3832
3864
|
rejectsThinkingDisabled,
|
|
3865
|
+
rejectsBudgetThinking,
|
|
3833
3866
|
rejectsForcedToolUse,
|
|
3834
3867
|
supportsBetweenToolsThinking,
|
|
3835
3868
|
isKnownModel
|
|
@@ -3947,15 +3980,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3947
3980
|
details: `thinking cannot be disabled for ${this.modelId}; it always uses adaptive thinking. The thinking setting has been removed. Lower 'effort' to reduce thinking.`
|
|
3948
3981
|
});
|
|
3949
3982
|
anthropicOptions.thinking = void 0;
|
|
3950
|
-
} else if (requestedType === "enabled") {
|
|
3951
|
-
warnings.push({
|
|
3952
|
-
type: "unsupported",
|
|
3953
|
-
feature: "providerOptions.anthropic.thinking",
|
|
3954
|
-
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.`
|
|
3955
|
-
});
|
|
3956
|
-
anthropicOptions.thinking = { type: "adaptive" };
|
|
3957
3983
|
}
|
|
3958
3984
|
}
|
|
3985
|
+
if (rejectsBudgetThinking && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null && "type" in anthropicOptions.thinking && anthropicOptions.thinking.type === "enabled") {
|
|
3986
|
+
warnings.push({
|
|
3987
|
+
type: "unsupported",
|
|
3988
|
+
feature: "providerOptions.anthropic.thinking",
|
|
3989
|
+
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.`
|
|
3990
|
+
});
|
|
3991
|
+
anthropicOptions.thinking = { type: "adaptive" };
|
|
3992
|
+
}
|
|
3959
3993
|
const thinking = anthropicOptions == null ? void 0 : anthropicOptions.thinking;
|
|
3960
3994
|
const thinkingType = thinking != null && "type" in thinking ? thinking.type : void 0;
|
|
3961
3995
|
if (rejectsThinkingDisabledAboveHighEffort && thinkingType === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
|
|
@@ -4073,6 +4107,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4073
4107
|
// prompt:
|
|
4074
4108
|
system: messagesPrompt.system,
|
|
4075
4109
|
messages: messagesPrompt.messages,
|
|
4110
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0 && {
|
|
4111
|
+
safeguards: anthropicOptions.safeguards.map((safeguard) => ({
|
|
4112
|
+
type: safeguard.type,
|
|
4113
|
+
...safeguard.classifierContext !== void 0 && {
|
|
4114
|
+
classifier_context: safeguard.classifierContext
|
|
4115
|
+
}
|
|
4116
|
+
}))
|
|
4117
|
+
},
|
|
4076
4118
|
...contextManagement && {
|
|
4077
4119
|
context_management: {
|
|
4078
4120
|
edits: contextManagement.edits.map((edit) => {
|
|
@@ -4185,6 +4227,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4185
4227
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
|
|
4186
4228
|
betas.add("mcp-client-2025-04-04");
|
|
4187
4229
|
}
|
|
4230
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0) {
|
|
4231
|
+
betas.add("dangerous-tool-use-2026-09-03");
|
|
4232
|
+
}
|
|
4188
4233
|
if (contextManagement) {
|
|
4189
4234
|
betas.add("context-management-2025-06-27");
|
|
4190
4235
|
if (contextManagement.edits.some((e) => e.type === "compact_20260112")) {
|
|
@@ -4808,6 +4853,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4808
4853
|
stopSequence: (_b2 = response.stop_sequence) != null ? _b2 : null,
|
|
4809
4854
|
...stopDetails != null ? { stopDetails } : {},
|
|
4810
4855
|
...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
|
|
4856
|
+
...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
|
|
4811
4857
|
iterations: response.usage.iterations ? response.usage.iterations.map(
|
|
4812
4858
|
(iter) => ({
|
|
4813
4859
|
type: iter.type,
|
|
@@ -4898,6 +4944,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4898
4944
|
let stopSequence = null;
|
|
4899
4945
|
let stopDetails = void 0;
|
|
4900
4946
|
let inputTransformations;
|
|
4947
|
+
let safeguardResults;
|
|
4901
4948
|
let container = null;
|
|
4902
4949
|
let isJsonResponseFromTool = false;
|
|
4903
4950
|
let isMessageOpen = false;
|
|
@@ -5719,6 +5766,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5719
5766
|
if (value.input_transformations != null) {
|
|
5720
5767
|
inputTransformations = value.input_transformations;
|
|
5721
5768
|
}
|
|
5769
|
+
if (value.delta.safeguard_results != null) {
|
|
5770
|
+
safeguardResults = value.delta.safeguard_results;
|
|
5771
|
+
}
|
|
5722
5772
|
rawUsage = {
|
|
5723
5773
|
...rawUsage,
|
|
5724
5774
|
...value.usage
|
|
@@ -5734,6 +5784,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5734
5784
|
stopSequence,
|
|
5735
5785
|
...stopDetails != null ? { stopDetails } : {},
|
|
5736
5786
|
...inputTransformations != null ? { inputTransformations } : {},
|
|
5787
|
+
...safeguardResults != null ? { safeguardResults } : {},
|
|
5737
5788
|
iterations: usage.iterations ? usage.iterations.map(
|
|
5738
5789
|
(iter) => ({
|
|
5739
5790
|
type: iter.type,
|
|
@@ -5817,6 +5868,7 @@ function getModelCapabilities(modelId) {
|
|
|
5817
5868
|
rejectsSamplingParameters: true,
|
|
5818
5869
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5819
5870
|
rejectsThinkingDisabled: true,
|
|
5871
|
+
rejectsBudgetThinking: true,
|
|
5820
5872
|
rejectsForcedToolUse: true,
|
|
5821
5873
|
supportsBetweenToolsThinking: true,
|
|
5822
5874
|
isKnownModel: true
|
|
@@ -5828,10 +5880,23 @@ function getModelCapabilities(modelId) {
|
|
|
5828
5880
|
rejectsSamplingParameters: true,
|
|
5829
5881
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5830
5882
|
rejectsThinkingDisabled: true,
|
|
5883
|
+
rejectsBudgetThinking: true,
|
|
5831
5884
|
rejectsForcedToolUse: true,
|
|
5832
5885
|
supportsBetweenToolsThinking: false,
|
|
5833
5886
|
isKnownModel: true
|
|
5834
5887
|
};
|
|
5888
|
+
} else if (modelId.includes("claude-haiku-5-5")) {
|
|
5889
|
+
return {
|
|
5890
|
+
maxOutputTokens: 128e3,
|
|
5891
|
+
supportsStructuredOutput: true,
|
|
5892
|
+
rejectsSamplingParameters: true,
|
|
5893
|
+
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5894
|
+
rejectsThinkingDisabled: false,
|
|
5895
|
+
rejectsBudgetThinking: true,
|
|
5896
|
+
rejectsForcedToolUse: false,
|
|
5897
|
+
supportsBetweenToolsThinking: false,
|
|
5898
|
+
isKnownModel: true
|
|
5899
|
+
};
|
|
5835
5900
|
} else if (modelId.includes("claude-opus-5")) {
|
|
5836
5901
|
return {
|
|
5837
5902
|
maxOutputTokens: 128e3,
|
|
@@ -5839,6 +5904,7 @@ function getModelCapabilities(modelId) {
|
|
|
5839
5904
|
rejectsSamplingParameters: true,
|
|
5840
5905
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5841
5906
|
rejectsThinkingDisabled: false,
|
|
5907
|
+
rejectsBudgetThinking: false,
|
|
5842
5908
|
rejectsForcedToolUse: false,
|
|
5843
5909
|
supportsBetweenToolsThinking: false,
|
|
5844
5910
|
isKnownModel: true
|
|
@@ -5850,6 +5916,7 @@ function getModelCapabilities(modelId) {
|
|
|
5850
5916
|
rejectsSamplingParameters: true,
|
|
5851
5917
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5852
5918
|
rejectsThinkingDisabled: true,
|
|
5919
|
+
rejectsBudgetThinking: true,
|
|
5853
5920
|
rejectsForcedToolUse: true,
|
|
5854
5921
|
supportsBetweenToolsThinking: false,
|
|
5855
5922
|
isKnownModel: true
|
|
@@ -5861,6 +5928,7 @@ function getModelCapabilities(modelId) {
|
|
|
5861
5928
|
rejectsSamplingParameters: true,
|
|
5862
5929
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5863
5930
|
rejectsThinkingDisabled: true,
|
|
5931
|
+
rejectsBudgetThinking: true,
|
|
5864
5932
|
rejectsForcedToolUse: false,
|
|
5865
5933
|
supportsBetweenToolsThinking: false,
|
|
5866
5934
|
isKnownModel: true
|
|
@@ -5872,6 +5940,7 @@ function getModelCapabilities(modelId) {
|
|
|
5872
5940
|
rejectsSamplingParameters: true,
|
|
5873
5941
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5874
5942
|
rejectsThinkingDisabled: false,
|
|
5943
|
+
rejectsBudgetThinking: false,
|
|
5875
5944
|
rejectsForcedToolUse: false,
|
|
5876
5945
|
supportsBetweenToolsThinking: false,
|
|
5877
5946
|
isKnownModel: true
|
|
@@ -5883,6 +5952,7 @@ function getModelCapabilities(modelId) {
|
|
|
5883
5952
|
rejectsSamplingParameters: false,
|
|
5884
5953
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5885
5954
|
rejectsThinkingDisabled: false,
|
|
5955
|
+
rejectsBudgetThinking: false,
|
|
5886
5956
|
rejectsForcedToolUse: false,
|
|
5887
5957
|
supportsBetweenToolsThinking: false,
|
|
5888
5958
|
isKnownModel: true
|
|
@@ -5894,6 +5964,7 @@ function getModelCapabilities(modelId) {
|
|
|
5894
5964
|
rejectsSamplingParameters: false,
|
|
5895
5965
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5896
5966
|
rejectsThinkingDisabled: false,
|
|
5967
|
+
rejectsBudgetThinking: false,
|
|
5897
5968
|
rejectsForcedToolUse: false,
|
|
5898
5969
|
supportsBetweenToolsThinking: false,
|
|
5899
5970
|
isKnownModel: true
|
|
@@ -5905,6 +5976,7 @@ function getModelCapabilities(modelId) {
|
|
|
5905
5976
|
rejectsSamplingParameters: false,
|
|
5906
5977
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5907
5978
|
rejectsThinkingDisabled: false,
|
|
5979
|
+
rejectsBudgetThinking: false,
|
|
5908
5980
|
rejectsForcedToolUse: false,
|
|
5909
5981
|
supportsBetweenToolsThinking: false,
|
|
5910
5982
|
isKnownModel: true
|
|
@@ -5916,6 +5988,7 @@ function getModelCapabilities(modelId) {
|
|
|
5916
5988
|
rejectsSamplingParameters: false,
|
|
5917
5989
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5918
5990
|
rejectsThinkingDisabled: false,
|
|
5991
|
+
rejectsBudgetThinking: false,
|
|
5919
5992
|
rejectsForcedToolUse: false,
|
|
5920
5993
|
supportsBetweenToolsThinking: false,
|
|
5921
5994
|
isKnownModel: true
|
|
@@ -5927,6 +6000,7 @@ function getModelCapabilities(modelId) {
|
|
|
5927
6000
|
rejectsSamplingParameters: false,
|
|
5928
6001
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5929
6002
|
rejectsThinkingDisabled: false,
|
|
6003
|
+
rejectsBudgetThinking: false,
|
|
5930
6004
|
rejectsForcedToolUse: false,
|
|
5931
6005
|
supportsBetweenToolsThinking: false,
|
|
5932
6006
|
isKnownModel: true
|
|
@@ -5938,6 +6012,7 @@ function getModelCapabilities(modelId) {
|
|
|
5938
6012
|
rejectsSamplingParameters: false,
|
|
5939
6013
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5940
6014
|
rejectsThinkingDisabled: false,
|
|
6015
|
+
rejectsBudgetThinking: false,
|
|
5941
6016
|
rejectsForcedToolUse: false,
|
|
5942
6017
|
supportsBetweenToolsThinking: false,
|
|
5943
6018
|
isKnownModel: true
|
|
@@ -5949,6 +6024,7 @@ function getModelCapabilities(modelId) {
|
|
|
5949
6024
|
rejectsSamplingParameters: false,
|
|
5950
6025
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5951
6026
|
rejectsThinkingDisabled: false,
|
|
6027
|
+
rejectsBudgetThinking: false,
|
|
5952
6028
|
rejectsForcedToolUse: false,
|
|
5953
6029
|
supportsBetweenToolsThinking: false,
|
|
5954
6030
|
isKnownModel: false
|
|
@@ -5960,6 +6036,7 @@ function getModelCapabilities(modelId) {
|
|
|
5960
6036
|
rejectsSamplingParameters: true,
|
|
5961
6037
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5962
6038
|
rejectsThinkingDisabled: false,
|
|
6039
|
+
rejectsBudgetThinking: false,
|
|
5963
6040
|
rejectsForcedToolUse: false,
|
|
5964
6041
|
supportsBetweenToolsThinking: false,
|
|
5965
6042
|
isKnownModel: false
|
|
@@ -5971,6 +6048,7 @@ function getModelCapabilities(modelId) {
|
|
|
5971
6048
|
rejectsSamplingParameters: false,
|
|
5972
6049
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5973
6050
|
rejectsThinkingDisabled: false,
|
|
6051
|
+
rejectsBudgetThinking: false,
|
|
5974
6052
|
rejectsForcedToolUse: false,
|
|
5975
6053
|
supportsBetweenToolsThinking: false,
|
|
5976
6054
|
isKnownModel: false
|