@ai-sdk/anthropic 4.0.57 → 4.0.59

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.
@@ -738,6 +738,17 @@ declare const anthropicResponseSchema: _ai_sdk_provider_utils.LazySchema<{
738
738
  path: string;
739
739
  reason: string;
740
740
  }[] | null | undefined;
741
+ safeguard_results?: {
742
+ type: string;
743
+ status: {
744
+ type: string;
745
+ tool_uses?: Record<string, {
746
+ type: string;
747
+ outcome?: string | null | undefined;
748
+ explanation?: string | null | undefined;
749
+ }> | null | undefined;
750
+ };
751
+ }[] | null | undefined;
741
752
  container?: {
742
753
  expires_at: string;
743
754
  id: string;
@@ -844,6 +855,10 @@ declare class AnthropicLanguageModel implements LanguageModelV4 {
844
855
  type: "compact_20260112";
845
856
  })[];
846
857
  } | undefined;
858
+ safeguards?: {
859
+ classifier_context?: Record<string, unknown> | undefined;
860
+ type: "dangerous_tool_use";
861
+ }[] | undefined;
847
862
  system: AnthropicTextContent[] | undefined;
848
863
  messages: AnthropicMessage[];
849
864
  container?: string | {
@@ -141,6 +141,20 @@ var anthropicStopDetailsSchema = z3.object({
141
141
  explanation: z3.string().nullish(),
142
142
  recommended_model: z3.string().nullish()
143
143
  });
144
+ var anthropicSafeguardResultSchema = z3.object({
145
+ type: z3.string(),
146
+ status: z3.object({
147
+ type: z3.string(),
148
+ tool_uses: z3.record(
149
+ z3.string(),
150
+ z3.object({
151
+ type: z3.string(),
152
+ outcome: z3.string().nullish(),
153
+ explanation: z3.string().nullish()
154
+ })
155
+ ).nullish()
156
+ })
157
+ });
144
158
  var anthropicToolCallCallerSchema = z3.union([
145
159
  z3.object({
146
160
  type: z3.literal("code_execution_20250825"),
@@ -474,6 +488,7 @@ var anthropicResponseSchema = lazySchema3(
474
488
  stop_sequence: z3.string().nullish(),
475
489
  stop_details: anthropicStopDetailsSchema.nullish(),
476
490
  input_transformations: z3.array(anthropicInputTransformationSchema).nullish(),
491
+ safeguard_results: z3.array(anthropicSafeguardResultSchema).nullish(),
477
492
  usage: z3.looseObject({
478
493
  input_tokens: z3.number(),
479
494
  output_tokens: z3.number(),
@@ -857,6 +872,7 @@ var anthropicChunkSchema = lazySchema3(
857
872
  stop_reason: z3.string().nullish(),
858
873
  stop_sequence: z3.string().nullish(),
859
874
  stop_details: anthropicStopDetailsSchema.nullish(),
875
+ safeguard_results: z3.array(anthropicSafeguardResultSchema).nullish(),
860
876
  container: z3.object({
861
877
  expires_at: z3.string(),
862
878
  id: z3.string(),
@@ -1205,6 +1221,22 @@ var anthropicLanguageModelOptions = z4.object({
1205
1221
  * Allow a provider to receive the full `betas` set if it needs it.
1206
1222
  */
1207
1223
  anthropicBeta: z4.array(z4.string()).optional(),
1224
+ /**
1225
+ * Server-side safeguards to run as part of the request.
1226
+ *
1227
+ * `dangerous_tool_use` asks the API to classify every `tool_use` block in
1228
+ * the response for dangerous actions (the check Claude Code's auto mode
1229
+ * relies on). The per-call verdicts are returned in
1230
+ * `providerMetadata.anthropic.safeguardResults`, keyed by tool call id.
1231
+ * `classifierContext` is passed through to the API as `classifier_context`.
1232
+ * The `dangerous-tool-use-2026-09-03` beta is added automatically.
1233
+ */
1234
+ safeguards: z4.array(
1235
+ z4.object({
1236
+ type: z4.literal("dangerous_tool_use"),
1237
+ classifierContext: z4.record(z4.string(), z4.unknown()).optional()
1238
+ })
1239
+ ).optional(),
1208
1240
  contextManagement: z4.object({
1209
1241
  edits: z4.array(
1210
1242
  z4.discriminatedUnion("type", [
@@ -4237,6 +4269,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4237
4269
  // prompt:
4238
4270
  system: messagesPrompt.system,
4239
4271
  messages: messagesPrompt.messages,
4272
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0 && {
4273
+ safeguards: anthropicOptions.safeguards.map((safeguard) => ({
4274
+ type: safeguard.type,
4275
+ ...safeguard.classifierContext !== void 0 && {
4276
+ classifier_context: safeguard.classifierContext
4277
+ }
4278
+ }))
4279
+ },
4240
4280
  ...contextManagement && {
4241
4281
  context_management: {
4242
4282
  edits: contextManagement.edits.map((edit) => {
@@ -4349,6 +4389,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4349
4389
  if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
4350
4390
  betas.add("mcp-client-2025-04-04");
4351
4391
  }
4392
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0) {
4393
+ betas.add("dangerous-tool-use-2026-09-03");
4394
+ }
4352
4395
  if (contextManagement) {
4353
4396
  betas.add("context-management-2025-06-27");
4354
4397
  if (contextManagement.edits.some((e) => e.type === "compact_20260112")) {
@@ -4970,6 +5013,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4970
5013
  stopSequence: (_a2 = response.stop_sequence) != null ? _a2 : null,
4971
5014
  ...stopDetails != null ? { stopDetails } : {},
4972
5015
  ...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
5016
+ ...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
4973
5017
  iterations: response.usage.iterations ? response.usage.iterations.map(
4974
5018
  (iter) => ({
4975
5019
  type: iter.type,
@@ -5056,6 +5100,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5056
5100
  let stopSequence = null;
5057
5101
  let stopDetails = void 0;
5058
5102
  let inputTransformations;
5103
+ let safeguardResults;
5059
5104
  let container = null;
5060
5105
  let isJsonResponseFromTool = false;
5061
5106
  let isMessageOpen = false;
@@ -5830,6 +5875,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5830
5875
  if (value.input_transformations != null) {
5831
5876
  inputTransformations = value.input_transformations;
5832
5877
  }
5878
+ if (value.delta.safeguard_results != null) {
5879
+ safeguardResults = value.delta.safeguard_results;
5880
+ }
5833
5881
  rawUsage = {
5834
5882
  ...rawUsage,
5835
5883
  ...value.usage
@@ -5844,6 +5892,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5844
5892
  stopSequence,
5845
5893
  ...stopDetails != null ? { stopDetails } : {},
5846
5894
  ...inputTransformations != null ? { inputTransformations } : {},
5895
+ ...safeguardResults != null ? { safeguardResults } : {},
5847
5896
  iterations: usage.iterations ? usage.iterations.map(
5848
5897
  (iter) => ({
5849
5898
  type: iter.type,