@ai-sdk/anthropic 3.0.126 → 3.0.127

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.
@@ -60,6 +60,20 @@ var anthropicStopDetailsSchema = import_v42.z.object({
60
60
  explanation: import_v42.z.string().nullish(),
61
61
  recommended_model: import_v42.z.string().nullish()
62
62
  });
63
+ var anthropicSafeguardResultSchema = import_v42.z.object({
64
+ type: import_v42.z.string(),
65
+ status: import_v42.z.object({
66
+ type: import_v42.z.string(),
67
+ tool_uses: import_v42.z.record(
68
+ import_v42.z.string(),
69
+ import_v42.z.object({
70
+ type: import_v42.z.string(),
71
+ outcome: import_v42.z.string().nullish(),
72
+ explanation: import_v42.z.string().nullish()
73
+ })
74
+ ).nullish()
75
+ })
76
+ });
63
77
  var anthropicToolCallCallerSchema = import_v42.z.union([
64
78
  import_v42.z.object({
65
79
  type: import_v42.z.literal("code_execution_20250825"),
@@ -360,6 +374,7 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
360
374
  stop_sequence: import_v42.z.string().nullish(),
361
375
  stop_details: anthropicStopDetailsSchema.nullish(),
362
376
  input_transformations: import_v42.z.array(anthropicInputTransformationSchema).nullish(),
377
+ safeguard_results: import_v42.z.array(anthropicSafeguardResultSchema).nullish(),
363
378
  usage: import_v42.z.looseObject({
364
379
  input_tokens: import_v42.z.number(),
365
380
  output_tokens: import_v42.z.number(),
@@ -769,6 +784,7 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
769
784
  stop_reason: import_v42.z.string().nullish(),
770
785
  stop_sequence: import_v42.z.string().nullish(),
771
786
  stop_details: anthropicStopDetailsSchema.nullish(),
787
+ safeguard_results: import_v42.z.array(anthropicSafeguardResultSchema).nullish(),
772
788
  container: import_v42.z.object({
773
789
  expires_at: import_v42.z.string(),
774
790
  id: import_v42.z.string(),
@@ -1127,6 +1143,22 @@ var anthropicLanguageModelOptions = import_v43.z.object({
1127
1143
  * Allow a provider to receive the full `betas` set if it needs it.
1128
1144
  */
1129
1145
  anthropicBeta: import_v43.z.array(import_v43.z.string()).optional(),
1146
+ /**
1147
+ * Server-side safeguards to run as part of the request.
1148
+ *
1149
+ * `dangerous_tool_use` asks the API to classify every `tool_use` block in
1150
+ * the response for dangerous actions (the check Claude Code's auto mode
1151
+ * relies on). The per-call verdicts are returned in
1152
+ * `providerMetadata.anthropic.safeguardResults`, keyed by tool call id.
1153
+ * `classifierContext` is passed through to the API as `classifier_context`.
1154
+ * The `dangerous-tool-use-2026-09-03` beta is added automatically.
1155
+ */
1156
+ safeguards: import_v43.z.array(
1157
+ import_v43.z.object({
1158
+ type: import_v43.z.literal("dangerous_tool_use"),
1159
+ classifierContext: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).optional()
1160
+ })
1161
+ ).optional(),
1130
1162
  contextManagement: import_v43.z.object({
1131
1163
  edits: import_v43.z.array(
1132
1164
  import_v43.z.discriminatedUnion("type", [
@@ -4027,6 +4059,14 @@ var AnthropicMessagesLanguageModel = class {
4027
4059
  // prompt:
4028
4060
  system: messagesPrompt.system,
4029
4061
  messages: messagesPrompt.messages,
4062
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0 && {
4063
+ safeguards: anthropicOptions.safeguards.map((safeguard) => ({
4064
+ type: safeguard.type,
4065
+ ...safeguard.classifierContext !== void 0 && {
4066
+ classifier_context: safeguard.classifierContext
4067
+ }
4068
+ }))
4069
+ },
4030
4070
  ...contextManagement && {
4031
4071
  context_management: {
4032
4072
  edits: contextManagement.edits.map((edit) => {
@@ -4139,6 +4179,9 @@ var AnthropicMessagesLanguageModel = class {
4139
4179
  if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
4140
4180
  betas.add("mcp-client-2025-04-04");
4141
4181
  }
4182
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0) {
4183
+ betas.add("dangerous-tool-use-2026-09-03");
4184
+ }
4142
4185
  if (contextManagement) {
4143
4186
  betas.add("context-management-2025-06-27");
4144
4187
  if (contextManagement.edits.some((e) => e.type === "compact_20260112")) {
@@ -4762,6 +4805,7 @@ var AnthropicMessagesLanguageModel = class {
4762
4805
  stopSequence: (_b2 = response.stop_sequence) != null ? _b2 : null,
4763
4806
  ...stopDetails != null ? { stopDetails } : {},
4764
4807
  ...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
4808
+ ...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
4765
4809
  iterations: response.usage.iterations ? response.usage.iterations.map(
4766
4810
  (iter) => ({
4767
4811
  type: iter.type,
@@ -4852,6 +4896,7 @@ var AnthropicMessagesLanguageModel = class {
4852
4896
  let stopSequence = null;
4853
4897
  let stopDetails = void 0;
4854
4898
  let inputTransformations;
4899
+ let safeguardResults;
4855
4900
  let container = null;
4856
4901
  let isJsonResponseFromTool = false;
4857
4902
  let isMessageOpen = false;
@@ -5673,6 +5718,9 @@ var AnthropicMessagesLanguageModel = class {
5673
5718
  if (value.input_transformations != null) {
5674
5719
  inputTransformations = value.input_transformations;
5675
5720
  }
5721
+ if (value.delta.safeguard_results != null) {
5722
+ safeguardResults = value.delta.safeguard_results;
5723
+ }
5676
5724
  rawUsage = {
5677
5725
  ...rawUsage,
5678
5726
  ...value.usage
@@ -5688,6 +5736,7 @@ var AnthropicMessagesLanguageModel = class {
5688
5736
  stopSequence,
5689
5737
  ...stopDetails != null ? { stopDetails } : {},
5690
5738
  ...inputTransformations != null ? { inputTransformations } : {},
5739
+ ...safeguardResults != null ? { safeguardResults } : {},
5691
5740
  iterations: usage.iterations ? usage.iterations.map(
5692
5741
  (iter) => ({
5693
5742
  type: iter.type,