@ai-sdk/anthropic 3.0.125 → 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.
@@ -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", [
@@ -4073,6 +4105,14 @@ var AnthropicMessagesLanguageModel = class {
4073
4105
  // prompt:
4074
4106
  system: messagesPrompt.system,
4075
4107
  messages: messagesPrompt.messages,
4108
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0 && {
4109
+ safeguards: anthropicOptions.safeguards.map((safeguard) => ({
4110
+ type: safeguard.type,
4111
+ ...safeguard.classifierContext !== void 0 && {
4112
+ classifier_context: safeguard.classifierContext
4113
+ }
4114
+ }))
4115
+ },
4076
4116
  ...contextManagement && {
4077
4117
  context_management: {
4078
4118
  edits: contextManagement.edits.map((edit) => {
@@ -4185,6 +4225,9 @@ var AnthropicMessagesLanguageModel = class {
4185
4225
  if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
4186
4226
  betas.add("mcp-client-2025-04-04");
4187
4227
  }
4228
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0) {
4229
+ betas.add("dangerous-tool-use-2026-09-03");
4230
+ }
4188
4231
  if (contextManagement) {
4189
4232
  betas.add("context-management-2025-06-27");
4190
4233
  if (contextManagement.edits.some((e) => e.type === "compact_20260112")) {
@@ -4808,6 +4851,7 @@ var AnthropicMessagesLanguageModel = class {
4808
4851
  stopSequence: (_b2 = response.stop_sequence) != null ? _b2 : null,
4809
4852
  ...stopDetails != null ? { stopDetails } : {},
4810
4853
  ...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
4854
+ ...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
4811
4855
  iterations: response.usage.iterations ? response.usage.iterations.map(
4812
4856
  (iter) => ({
4813
4857
  type: iter.type,
@@ -4898,6 +4942,7 @@ var AnthropicMessagesLanguageModel = class {
4898
4942
  let stopSequence = null;
4899
4943
  let stopDetails = void 0;
4900
4944
  let inputTransformations;
4945
+ let safeguardResults;
4901
4946
  let container = null;
4902
4947
  let isJsonResponseFromTool = false;
4903
4948
  let isMessageOpen = false;
@@ -5719,6 +5764,9 @@ var AnthropicMessagesLanguageModel = class {
5719
5764
  if (value.input_transformations != null) {
5720
5765
  inputTransformations = value.input_transformations;
5721
5766
  }
5767
+ if (value.delta.safeguard_results != null) {
5768
+ safeguardResults = value.delta.safeguard_results;
5769
+ }
5722
5770
  rawUsage = {
5723
5771
  ...rawUsage,
5724
5772
  ...value.usage
@@ -5734,6 +5782,7 @@ var AnthropicMessagesLanguageModel = class {
5734
5782
  stopSequence,
5735
5783
  ...stopDetails != null ? { stopDetails } : {},
5736
5784
  ...inputTransformations != null ? { inputTransformations } : {},
5785
+ ...safeguardResults != null ? { safeguardResults } : {},
5737
5786
  iterations: usage.iterations ? usage.iterations.map(
5738
5787
  (iter) => ({
5739
5788
  type: iter.type,