@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/dist/index.mjs CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  } from "@ai-sdk/provider-utils";
13
13
 
14
14
  // src/version.ts
15
- var VERSION = true ? "3.0.126" : "0.0.0-test";
15
+ var VERSION = true ? "3.0.128" : "0.0.0-test";
16
16
 
17
17
  // src/anthropic-messages-language-model.ts
18
18
  import {
@@ -66,6 +66,20 @@ var anthropicStopDetailsSchema = z2.object({
66
66
  explanation: z2.string().nullish(),
67
67
  recommended_model: z2.string().nullish()
68
68
  });
69
+ var anthropicSafeguardResultSchema = z2.object({
70
+ type: z2.string(),
71
+ status: z2.object({
72
+ type: z2.string(),
73
+ tool_uses: z2.record(
74
+ z2.string(),
75
+ z2.object({
76
+ type: z2.string(),
77
+ outcome: z2.string().nullish(),
78
+ explanation: z2.string().nullish()
79
+ })
80
+ ).nullish()
81
+ })
82
+ });
69
83
  var anthropicToolCallCallerSchema = z2.union([
70
84
  z2.object({
71
85
  type: z2.literal("code_execution_20250825"),
@@ -366,6 +380,7 @@ var anthropicMessagesResponseSchema = lazySchema2(
366
380
  stop_sequence: z2.string().nullish(),
367
381
  stop_details: anthropicStopDetailsSchema.nullish(),
368
382
  input_transformations: z2.array(anthropicInputTransformationSchema).nullish(),
383
+ safeguard_results: z2.array(anthropicSafeguardResultSchema).nullish(),
369
384
  usage: z2.looseObject({
370
385
  input_tokens: z2.number(),
371
386
  output_tokens: z2.number(),
@@ -775,6 +790,7 @@ var anthropicMessagesChunkSchema = lazySchema2(
775
790
  stop_reason: z2.string().nullish(),
776
791
  stop_sequence: z2.string().nullish(),
777
792
  stop_details: anthropicStopDetailsSchema.nullish(),
793
+ safeguard_results: z2.array(anthropicSafeguardResultSchema).nullish(),
778
794
  container: z2.object({
779
795
  expires_at: z2.string(),
780
796
  id: z2.string(),
@@ -1133,6 +1149,22 @@ var anthropicLanguageModelOptions = z3.object({
1133
1149
  * Allow a provider to receive the full `betas` set if it needs it.
1134
1150
  */
1135
1151
  anthropicBeta: z3.array(z3.string()).optional(),
1152
+ /**
1153
+ * Server-side safeguards to run as part of the request.
1154
+ *
1155
+ * `dangerous_tool_use` asks the API to classify every `tool_use` block in
1156
+ * the response for dangerous actions (the check Claude Code's auto mode
1157
+ * relies on). The per-call verdicts are returned in
1158
+ * `providerMetadata.anthropic.safeguardResults`, keyed by tool call id.
1159
+ * `classifierContext` is passed through to the API as `classifier_context`.
1160
+ * The `dangerous-tool-use-2026-09-03` beta is added automatically.
1161
+ */
1162
+ safeguards: z3.array(
1163
+ z3.object({
1164
+ type: z3.literal("dangerous_tool_use"),
1165
+ classifierContext: z3.record(z3.string(), z3.unknown()).optional()
1166
+ })
1167
+ ).optional(),
1136
1168
  contextManagement: z3.object({
1137
1169
  edits: z3.array(
1138
1170
  z3.discriminatedUnion("type", [
@@ -3846,6 +3878,7 @@ var AnthropicMessagesLanguageModel = class {
3846
3878
  rejectsSamplingParameters,
3847
3879
  rejectsThinkingDisabledAboveHighEffort,
3848
3880
  rejectsThinkingDisabled,
3881
+ rejectsBudgetThinking,
3849
3882
  rejectsForcedToolUse,
3850
3883
  supportsBetweenToolsThinking,
3851
3884
  isKnownModel
@@ -3963,15 +3996,16 @@ var AnthropicMessagesLanguageModel = class {
3963
3996
  details: `thinking cannot be disabled for ${this.modelId}; it always uses adaptive thinking. The thinking setting has been removed. Lower 'effort' to reduce thinking.`
3964
3997
  });
3965
3998
  anthropicOptions.thinking = void 0;
3966
- } else if (requestedType === "enabled") {
3967
- warnings.push({
3968
- type: "unsupported",
3969
- feature: "providerOptions.anthropic.thinking",
3970
- 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.`
3971
- });
3972
- anthropicOptions.thinking = { type: "adaptive" };
3973
3999
  }
3974
4000
  }
4001
+ if (rejectsBudgetThinking && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null && "type" in anthropicOptions.thinking && anthropicOptions.thinking.type === "enabled") {
4002
+ warnings.push({
4003
+ type: "unsupported",
4004
+ feature: "providerOptions.anthropic.thinking",
4005
+ 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.`
4006
+ });
4007
+ anthropicOptions.thinking = { type: "adaptive" };
4008
+ }
3975
4009
  const thinking = anthropicOptions == null ? void 0 : anthropicOptions.thinking;
3976
4010
  const thinkingType = thinking != null && "type" in thinking ? thinking.type : void 0;
3977
4011
  if (rejectsThinkingDisabledAboveHighEffort && thinkingType === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
@@ -4089,6 +4123,14 @@ var AnthropicMessagesLanguageModel = class {
4089
4123
  // prompt:
4090
4124
  system: messagesPrompt.system,
4091
4125
  messages: messagesPrompt.messages,
4126
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0 && {
4127
+ safeguards: anthropicOptions.safeguards.map((safeguard) => ({
4128
+ type: safeguard.type,
4129
+ ...safeguard.classifierContext !== void 0 && {
4130
+ classifier_context: safeguard.classifierContext
4131
+ }
4132
+ }))
4133
+ },
4092
4134
  ...contextManagement && {
4093
4135
  context_management: {
4094
4136
  edits: contextManagement.edits.map((edit) => {
@@ -4201,6 +4243,9 @@ var AnthropicMessagesLanguageModel = class {
4201
4243
  if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
4202
4244
  betas.add("mcp-client-2025-04-04");
4203
4245
  }
4246
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0) {
4247
+ betas.add("dangerous-tool-use-2026-09-03");
4248
+ }
4204
4249
  if (contextManagement) {
4205
4250
  betas.add("context-management-2025-06-27");
4206
4251
  if (contextManagement.edits.some((e) => e.type === "compact_20260112")) {
@@ -4824,6 +4869,7 @@ var AnthropicMessagesLanguageModel = class {
4824
4869
  stopSequence: (_b2 = response.stop_sequence) != null ? _b2 : null,
4825
4870
  ...stopDetails != null ? { stopDetails } : {},
4826
4871
  ...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
4872
+ ...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
4827
4873
  iterations: response.usage.iterations ? response.usage.iterations.map(
4828
4874
  (iter) => ({
4829
4875
  type: iter.type,
@@ -4914,6 +4960,7 @@ var AnthropicMessagesLanguageModel = class {
4914
4960
  let stopSequence = null;
4915
4961
  let stopDetails = void 0;
4916
4962
  let inputTransformations;
4963
+ let safeguardResults;
4917
4964
  let container = null;
4918
4965
  let isJsonResponseFromTool = false;
4919
4966
  let isMessageOpen = false;
@@ -5735,6 +5782,9 @@ var AnthropicMessagesLanguageModel = class {
5735
5782
  if (value.input_transformations != null) {
5736
5783
  inputTransformations = value.input_transformations;
5737
5784
  }
5785
+ if (value.delta.safeguard_results != null) {
5786
+ safeguardResults = value.delta.safeguard_results;
5787
+ }
5738
5788
  rawUsage = {
5739
5789
  ...rawUsage,
5740
5790
  ...value.usage
@@ -5750,6 +5800,7 @@ var AnthropicMessagesLanguageModel = class {
5750
5800
  stopSequence,
5751
5801
  ...stopDetails != null ? { stopDetails } : {},
5752
5802
  ...inputTransformations != null ? { inputTransformations } : {},
5803
+ ...safeguardResults != null ? { safeguardResults } : {},
5753
5804
  iterations: usage.iterations ? usage.iterations.map(
5754
5805
  (iter) => ({
5755
5806
  type: iter.type,
@@ -5833,6 +5884,7 @@ function getModelCapabilities(modelId) {
5833
5884
  rejectsSamplingParameters: true,
5834
5885
  rejectsThinkingDisabledAboveHighEffort: true,
5835
5886
  rejectsThinkingDisabled: true,
5887
+ rejectsBudgetThinking: true,
5836
5888
  rejectsForcedToolUse: true,
5837
5889
  supportsBetweenToolsThinking: true,
5838
5890
  isKnownModel: true
@@ -5844,10 +5896,23 @@ function getModelCapabilities(modelId) {
5844
5896
  rejectsSamplingParameters: true,
5845
5897
  rejectsThinkingDisabledAboveHighEffort: true,
5846
5898
  rejectsThinkingDisabled: true,
5899
+ rejectsBudgetThinking: true,
5847
5900
  rejectsForcedToolUse: true,
5848
5901
  supportsBetweenToolsThinking: false,
5849
5902
  isKnownModel: true
5850
5903
  };
5904
+ } else if (modelId.includes("claude-haiku-5-5")) {
5905
+ return {
5906
+ maxOutputTokens: 128e3,
5907
+ supportsStructuredOutput: true,
5908
+ rejectsSamplingParameters: true,
5909
+ rejectsThinkingDisabledAboveHighEffort: true,
5910
+ rejectsThinkingDisabled: false,
5911
+ rejectsBudgetThinking: true,
5912
+ rejectsForcedToolUse: false,
5913
+ supportsBetweenToolsThinking: false,
5914
+ isKnownModel: true
5915
+ };
5851
5916
  } else if (modelId.includes("claude-opus-5")) {
5852
5917
  return {
5853
5918
  maxOutputTokens: 128e3,
@@ -5855,6 +5920,7 @@ function getModelCapabilities(modelId) {
5855
5920
  rejectsSamplingParameters: true,
5856
5921
  rejectsThinkingDisabledAboveHighEffort: true,
5857
5922
  rejectsThinkingDisabled: false,
5923
+ rejectsBudgetThinking: false,
5858
5924
  rejectsForcedToolUse: false,
5859
5925
  supportsBetweenToolsThinking: false,
5860
5926
  isKnownModel: true
@@ -5866,6 +5932,7 @@ function getModelCapabilities(modelId) {
5866
5932
  rejectsSamplingParameters: true,
5867
5933
  rejectsThinkingDisabledAboveHighEffort: false,
5868
5934
  rejectsThinkingDisabled: true,
5935
+ rejectsBudgetThinking: true,
5869
5936
  rejectsForcedToolUse: true,
5870
5937
  supportsBetweenToolsThinking: false,
5871
5938
  isKnownModel: true
@@ -5877,6 +5944,7 @@ function getModelCapabilities(modelId) {
5877
5944
  rejectsSamplingParameters: true,
5878
5945
  rejectsThinkingDisabledAboveHighEffort: false,
5879
5946
  rejectsThinkingDisabled: true,
5947
+ rejectsBudgetThinking: true,
5880
5948
  rejectsForcedToolUse: false,
5881
5949
  supportsBetweenToolsThinking: false,
5882
5950
  isKnownModel: true
@@ -5888,6 +5956,7 @@ function getModelCapabilities(modelId) {
5888
5956
  rejectsSamplingParameters: true,
5889
5957
  rejectsThinkingDisabledAboveHighEffort: false,
5890
5958
  rejectsThinkingDisabled: false,
5959
+ rejectsBudgetThinking: false,
5891
5960
  rejectsForcedToolUse: false,
5892
5961
  supportsBetweenToolsThinking: false,
5893
5962
  isKnownModel: true
@@ -5899,6 +5968,7 @@ function getModelCapabilities(modelId) {
5899
5968
  rejectsSamplingParameters: false,
5900
5969
  rejectsThinkingDisabledAboveHighEffort: false,
5901
5970
  rejectsThinkingDisabled: false,
5971
+ rejectsBudgetThinking: false,
5902
5972
  rejectsForcedToolUse: false,
5903
5973
  supportsBetweenToolsThinking: false,
5904
5974
  isKnownModel: true
@@ -5910,6 +5980,7 @@ function getModelCapabilities(modelId) {
5910
5980
  rejectsSamplingParameters: false,
5911
5981
  rejectsThinkingDisabledAboveHighEffort: false,
5912
5982
  rejectsThinkingDisabled: false,
5983
+ rejectsBudgetThinking: false,
5913
5984
  rejectsForcedToolUse: false,
5914
5985
  supportsBetweenToolsThinking: false,
5915
5986
  isKnownModel: true
@@ -5921,6 +5992,7 @@ function getModelCapabilities(modelId) {
5921
5992
  rejectsSamplingParameters: false,
5922
5993
  rejectsThinkingDisabledAboveHighEffort: false,
5923
5994
  rejectsThinkingDisabled: false,
5995
+ rejectsBudgetThinking: false,
5924
5996
  rejectsForcedToolUse: false,
5925
5997
  supportsBetweenToolsThinking: false,
5926
5998
  isKnownModel: true
@@ -5932,6 +6004,7 @@ function getModelCapabilities(modelId) {
5932
6004
  rejectsSamplingParameters: false,
5933
6005
  rejectsThinkingDisabledAboveHighEffort: false,
5934
6006
  rejectsThinkingDisabled: false,
6007
+ rejectsBudgetThinking: false,
5935
6008
  rejectsForcedToolUse: false,
5936
6009
  supportsBetweenToolsThinking: false,
5937
6010
  isKnownModel: true
@@ -5943,6 +6016,7 @@ function getModelCapabilities(modelId) {
5943
6016
  rejectsSamplingParameters: false,
5944
6017
  rejectsThinkingDisabledAboveHighEffort: false,
5945
6018
  rejectsThinkingDisabled: false,
6019
+ rejectsBudgetThinking: false,
5946
6020
  rejectsForcedToolUse: false,
5947
6021
  supportsBetweenToolsThinking: false,
5948
6022
  isKnownModel: true
@@ -5954,6 +6028,7 @@ function getModelCapabilities(modelId) {
5954
6028
  rejectsSamplingParameters: false,
5955
6029
  rejectsThinkingDisabledAboveHighEffort: false,
5956
6030
  rejectsThinkingDisabled: false,
6031
+ rejectsBudgetThinking: false,
5957
6032
  rejectsForcedToolUse: false,
5958
6033
  supportsBetweenToolsThinking: false,
5959
6034
  isKnownModel: true
@@ -5965,6 +6040,7 @@ function getModelCapabilities(modelId) {
5965
6040
  rejectsSamplingParameters: false,
5966
6041
  rejectsThinkingDisabledAboveHighEffort: false,
5967
6042
  rejectsThinkingDisabled: false,
6043
+ rejectsBudgetThinking: false,
5968
6044
  rejectsForcedToolUse: false,
5969
6045
  supportsBetweenToolsThinking: false,
5970
6046
  isKnownModel: false
@@ -5976,6 +6052,7 @@ function getModelCapabilities(modelId) {
5976
6052
  rejectsSamplingParameters: true,
5977
6053
  rejectsThinkingDisabledAboveHighEffort: true,
5978
6054
  rejectsThinkingDisabled: false,
6055
+ rejectsBudgetThinking: false,
5979
6056
  rejectsForcedToolUse: false,
5980
6057
  supportsBetweenToolsThinking: false,
5981
6058
  isKnownModel: false
@@ -5987,6 +6064,7 @@ function getModelCapabilities(modelId) {
5987
6064
  rejectsSamplingParameters: false,
5988
6065
  rejectsThinkingDisabledAboveHighEffort: false,
5989
6066
  rejectsThinkingDisabled: false,
6067
+ rejectsBudgetThinking: false,
5990
6068
  rejectsForcedToolUse: false,
5991
6069
  supportsBetweenToolsThinking: false,
5992
6070
  isKnownModel: false