@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.
- package/CHANGELOG.md +15 -0
- package/dist/index.d.mts +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +50 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -1
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +49 -0
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +49 -0
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +51 -0
- package/package.json +2 -2
- package/src/anthropic-message-metadata.ts +14 -0
- package/src/anthropic-messages-api.ts +23 -0
- package/src/anthropic-messages-language-model.ts +28 -0
- package/src/anthropic-messages-options.ts +19 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 3.0.127
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d5c12b2: feat(provider/anthropic): add `safeguards` provider option and `safeguardResults` provider metadata (dangerous tool use classifier)
|
|
8
|
+
|
|
9
|
+
## 3.0.126
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [a9cea74]
|
|
14
|
+
- Updated dependencies [a9cea74]
|
|
15
|
+
- Updated dependencies [a9cea74]
|
|
16
|
+
- @ai-sdk/provider-utils@4.0.57
|
|
17
|
+
|
|
3
18
|
## 3.0.125
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,19 @@ import { z } from 'zod/v4';
|
|
|
3
3
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
4
4
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
5
5
|
|
|
6
|
+
declare const anthropicSafeguardResultSchema: z.ZodObject<{
|
|
7
|
+
type: z.ZodString;
|
|
8
|
+
status: z.ZodObject<{
|
|
9
|
+
type: z.ZodString;
|
|
10
|
+
tool_uses: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
11
|
+
type: z.ZodString;
|
|
12
|
+
outcome: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
13
|
+
explanation: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
14
|
+
}, z.core.$strip>>>>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
type AnthropicSafeguardResult = z.infer<typeof anthropicSafeguardResultSchema>;
|
|
18
|
+
|
|
6
19
|
/**
|
|
7
20
|
* Represents a single iteration in the usage breakdown.
|
|
8
21
|
*
|
|
@@ -58,6 +71,18 @@ interface AnthropicMessageMetadata {
|
|
|
58
71
|
path: string;
|
|
59
72
|
reason: string;
|
|
60
73
|
}>;
|
|
74
|
+
/**
|
|
75
|
+
* Verdicts of the server-side safeguards requested with
|
|
76
|
+
* `providerOptions.anthropic.safeguards`, one entry per requested safeguard.
|
|
77
|
+
* For `dangerous_tool_use`, `status.type` is `'available'` when the
|
|
78
|
+
* classifier ran and `status.tool_uses` maps each tool call id to its
|
|
79
|
+
* verdict (`type: 'evaluated'` with an `outcome` of `'not_flagged'` or
|
|
80
|
+
* `'flagged'` plus an `explanation`, `'skipped'`, or `'unavailable'`).
|
|
81
|
+
*
|
|
82
|
+
* Kept in the API's wire shape (snake_case), since consumers such as Claude
|
|
83
|
+
* Code read the verdicts verbatim.
|
|
84
|
+
*/
|
|
85
|
+
safeguardResults?: AnthropicSafeguardResult[];
|
|
61
86
|
/**
|
|
62
87
|
* Details about why the request stopped. Present only when the API returns
|
|
63
88
|
* a `refusal` stop reason together with a `stop_details` object (a
|
|
@@ -220,9 +245,9 @@ type AnthropicSystemMessageProviderOptions = z.infer<typeof anthropicSystemMessa
|
|
|
220
245
|
declare const anthropicLanguageModelOptions: z.ZodObject<{
|
|
221
246
|
sendReasoning: z.ZodOptional<z.ZodBoolean>;
|
|
222
247
|
structuredOutputMode: z.ZodOptional<z.ZodEnum<{
|
|
248
|
+
auto: "auto";
|
|
223
249
|
outputFormat: "outputFormat";
|
|
224
250
|
jsonTool: "jsonTool";
|
|
225
|
-
auto: "auto";
|
|
226
251
|
}>>;
|
|
227
252
|
thinking: z.ZodOptional<z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
228
253
|
type: z.ZodLiteral<"adaptive">;
|
|
@@ -310,6 +335,10 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
|
|
|
310
335
|
}>>;
|
|
311
336
|
}, z.core.$strip>>]>>;
|
|
312
337
|
anthropicBeta: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
338
|
+
safeguards: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
339
|
+
type: z.ZodLiteral<"dangerous_tool_use">;
|
|
340
|
+
classifierContext: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
341
|
+
}, z.core.$strip>>>;
|
|
313
342
|
contextManagement: z.ZodOptional<z.ZodObject<{
|
|
314
343
|
edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
315
344
|
type: z.ZodLiteral<"clear_tool_uses_20250919">;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,19 @@ import { z } from 'zod/v4';
|
|
|
3
3
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
4
4
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
5
5
|
|
|
6
|
+
declare const anthropicSafeguardResultSchema: z.ZodObject<{
|
|
7
|
+
type: z.ZodString;
|
|
8
|
+
status: z.ZodObject<{
|
|
9
|
+
type: z.ZodString;
|
|
10
|
+
tool_uses: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
11
|
+
type: z.ZodString;
|
|
12
|
+
outcome: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
13
|
+
explanation: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
14
|
+
}, z.core.$strip>>>>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
type AnthropicSafeguardResult = z.infer<typeof anthropicSafeguardResultSchema>;
|
|
18
|
+
|
|
6
19
|
/**
|
|
7
20
|
* Represents a single iteration in the usage breakdown.
|
|
8
21
|
*
|
|
@@ -58,6 +71,18 @@ interface AnthropicMessageMetadata {
|
|
|
58
71
|
path: string;
|
|
59
72
|
reason: string;
|
|
60
73
|
}>;
|
|
74
|
+
/**
|
|
75
|
+
* Verdicts of the server-side safeguards requested with
|
|
76
|
+
* `providerOptions.anthropic.safeguards`, one entry per requested safeguard.
|
|
77
|
+
* For `dangerous_tool_use`, `status.type` is `'available'` when the
|
|
78
|
+
* classifier ran and `status.tool_uses` maps each tool call id to its
|
|
79
|
+
* verdict (`type: 'evaluated'` with an `outcome` of `'not_flagged'` or
|
|
80
|
+
* `'flagged'` plus an `explanation`, `'skipped'`, or `'unavailable'`).
|
|
81
|
+
*
|
|
82
|
+
* Kept in the API's wire shape (snake_case), since consumers such as Claude
|
|
83
|
+
* Code read the verdicts verbatim.
|
|
84
|
+
*/
|
|
85
|
+
safeguardResults?: AnthropicSafeguardResult[];
|
|
61
86
|
/**
|
|
62
87
|
* Details about why the request stopped. Present only when the API returns
|
|
63
88
|
* a `refusal` stop reason together with a `stop_details` object (a
|
|
@@ -220,9 +245,9 @@ type AnthropicSystemMessageProviderOptions = z.infer<typeof anthropicSystemMessa
|
|
|
220
245
|
declare const anthropicLanguageModelOptions: z.ZodObject<{
|
|
221
246
|
sendReasoning: z.ZodOptional<z.ZodBoolean>;
|
|
222
247
|
structuredOutputMode: z.ZodOptional<z.ZodEnum<{
|
|
248
|
+
auto: "auto";
|
|
223
249
|
outputFormat: "outputFormat";
|
|
224
250
|
jsonTool: "jsonTool";
|
|
225
|
-
auto: "auto";
|
|
226
251
|
}>>;
|
|
227
252
|
thinking: z.ZodOptional<z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
228
253
|
type: z.ZodLiteral<"adaptive">;
|
|
@@ -310,6 +335,10 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
|
|
|
310
335
|
}>>;
|
|
311
336
|
}, z.core.$strip>>]>>;
|
|
312
337
|
anthropicBeta: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
338
|
+
safeguards: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
339
|
+
type: z.ZodLiteral<"dangerous_tool_use">;
|
|
340
|
+
classifierContext: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
341
|
+
}, z.core.$strip>>>;
|
|
313
342
|
contextManagement: z.ZodOptional<z.ZodObject<{
|
|
314
343
|
edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
315
344
|
type: z.ZodLiteral<"clear_tool_uses_20250919">;
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
32
32
|
var import_provider_utils27 = require("@ai-sdk/provider-utils");
|
|
33
33
|
|
|
34
34
|
// src/version.ts
|
|
35
|
-
var VERSION = true ? "3.0.
|
|
35
|
+
var VERSION = true ? "3.0.127" : "0.0.0-test";
|
|
36
36
|
|
|
37
37
|
// src/anthropic-messages-language-model.ts
|
|
38
38
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -66,6 +66,20 @@ var anthropicStopDetailsSchema = import_v42.z.object({
|
|
|
66
66
|
explanation: import_v42.z.string().nullish(),
|
|
67
67
|
recommended_model: import_v42.z.string().nullish()
|
|
68
68
|
});
|
|
69
|
+
var anthropicSafeguardResultSchema = import_v42.z.object({
|
|
70
|
+
type: import_v42.z.string(),
|
|
71
|
+
status: import_v42.z.object({
|
|
72
|
+
type: import_v42.z.string(),
|
|
73
|
+
tool_uses: import_v42.z.record(
|
|
74
|
+
import_v42.z.string(),
|
|
75
|
+
import_v42.z.object({
|
|
76
|
+
type: import_v42.z.string(),
|
|
77
|
+
outcome: import_v42.z.string().nullish(),
|
|
78
|
+
explanation: import_v42.z.string().nullish()
|
|
79
|
+
})
|
|
80
|
+
).nullish()
|
|
81
|
+
})
|
|
82
|
+
});
|
|
69
83
|
var anthropicToolCallCallerSchema = import_v42.z.union([
|
|
70
84
|
import_v42.z.object({
|
|
71
85
|
type: import_v42.z.literal("code_execution_20250825"),
|
|
@@ -366,6 +380,7 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
366
380
|
stop_sequence: import_v42.z.string().nullish(),
|
|
367
381
|
stop_details: anthropicStopDetailsSchema.nullish(),
|
|
368
382
|
input_transformations: import_v42.z.array(anthropicInputTransformationSchema).nullish(),
|
|
383
|
+
safeguard_results: import_v42.z.array(anthropicSafeguardResultSchema).nullish(),
|
|
369
384
|
usage: import_v42.z.looseObject({
|
|
370
385
|
input_tokens: import_v42.z.number(),
|
|
371
386
|
output_tokens: import_v42.z.number(),
|
|
@@ -775,6 +790,7 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
775
790
|
stop_reason: import_v42.z.string().nullish(),
|
|
776
791
|
stop_sequence: import_v42.z.string().nullish(),
|
|
777
792
|
stop_details: anthropicStopDetailsSchema.nullish(),
|
|
793
|
+
safeguard_results: import_v42.z.array(anthropicSafeguardResultSchema).nullish(),
|
|
778
794
|
container: import_v42.z.object({
|
|
779
795
|
expires_at: import_v42.z.string(),
|
|
780
796
|
id: import_v42.z.string(),
|
|
@@ -1133,6 +1149,22 @@ var anthropicLanguageModelOptions = import_v43.z.object({
|
|
|
1133
1149
|
* Allow a provider to receive the full `betas` set if it needs it.
|
|
1134
1150
|
*/
|
|
1135
1151
|
anthropicBeta: import_v43.z.array(import_v43.z.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: import_v43.z.array(
|
|
1163
|
+
import_v43.z.object({
|
|
1164
|
+
type: import_v43.z.literal("dangerous_tool_use"),
|
|
1165
|
+
classifierContext: import_v43.z.record(import_v43.z.string(), import_v43.z.unknown()).optional()
|
|
1166
|
+
})
|
|
1167
|
+
).optional(),
|
|
1136
1168
|
contextManagement: import_v43.z.object({
|
|
1137
1169
|
edits: import_v43.z.array(
|
|
1138
1170
|
import_v43.z.discriminatedUnion("type", [
|
|
@@ -4033,6 +4065,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4033
4065
|
// prompt:
|
|
4034
4066
|
system: messagesPrompt.system,
|
|
4035
4067
|
messages: messagesPrompt.messages,
|
|
4068
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0 && {
|
|
4069
|
+
safeguards: anthropicOptions.safeguards.map((safeguard) => ({
|
|
4070
|
+
type: safeguard.type,
|
|
4071
|
+
...safeguard.classifierContext !== void 0 && {
|
|
4072
|
+
classifier_context: safeguard.classifierContext
|
|
4073
|
+
}
|
|
4074
|
+
}))
|
|
4075
|
+
},
|
|
4036
4076
|
...contextManagement && {
|
|
4037
4077
|
context_management: {
|
|
4038
4078
|
edits: contextManagement.edits.map((edit) => {
|
|
@@ -4145,6 +4185,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4145
4185
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
|
|
4146
4186
|
betas.add("mcp-client-2025-04-04");
|
|
4147
4187
|
}
|
|
4188
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0) {
|
|
4189
|
+
betas.add("dangerous-tool-use-2026-09-03");
|
|
4190
|
+
}
|
|
4148
4191
|
if (contextManagement) {
|
|
4149
4192
|
betas.add("context-management-2025-06-27");
|
|
4150
4193
|
if (contextManagement.edits.some((e) => e.type === "compact_20260112")) {
|
|
@@ -4768,6 +4811,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4768
4811
|
stopSequence: (_b2 = response.stop_sequence) != null ? _b2 : null,
|
|
4769
4812
|
...stopDetails != null ? { stopDetails } : {},
|
|
4770
4813
|
...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
|
|
4814
|
+
...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
|
|
4771
4815
|
iterations: response.usage.iterations ? response.usage.iterations.map(
|
|
4772
4816
|
(iter) => ({
|
|
4773
4817
|
type: iter.type,
|
|
@@ -4858,6 +4902,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4858
4902
|
let stopSequence = null;
|
|
4859
4903
|
let stopDetails = void 0;
|
|
4860
4904
|
let inputTransformations;
|
|
4905
|
+
let safeguardResults;
|
|
4861
4906
|
let container = null;
|
|
4862
4907
|
let isJsonResponseFromTool = false;
|
|
4863
4908
|
let isMessageOpen = false;
|
|
@@ -5679,6 +5724,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5679
5724
|
if (value.input_transformations != null) {
|
|
5680
5725
|
inputTransformations = value.input_transformations;
|
|
5681
5726
|
}
|
|
5727
|
+
if (value.delta.safeguard_results != null) {
|
|
5728
|
+
safeguardResults = value.delta.safeguard_results;
|
|
5729
|
+
}
|
|
5682
5730
|
rawUsage = {
|
|
5683
5731
|
...rawUsage,
|
|
5684
5732
|
...value.usage
|
|
@@ -5694,6 +5742,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5694
5742
|
stopSequence,
|
|
5695
5743
|
...stopDetails != null ? { stopDetails } : {},
|
|
5696
5744
|
...inputTransformations != null ? { inputTransformations } : {},
|
|
5745
|
+
...safeguardResults != null ? { safeguardResults } : {},
|
|
5697
5746
|
iterations: usage.iterations ? usage.iterations.map(
|
|
5698
5747
|
(iter) => ({
|
|
5699
5748
|
type: iter.type,
|