@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.
- package/CHANGELOG.md +15 -0
- package/dist/index.d.ts +30 -1
- package/dist/index.js +51 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +15 -0
- package/dist/internal/index.js +49 -0
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +51 -0
- package/package.json +2 -2
- package/src/anthropic-api.ts +23 -0
- package/src/anthropic-batch.ts +3 -0
- package/src/anthropic-language-model-options.ts +19 -0
- package/src/anthropic-language-model.ts +28 -0
- package/src/anthropic-message-metadata.ts +14 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 4.0.59
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f7b7b2a: feat(provider/anthropic): add `safeguards` provider option and `safeguardResults` provider metadata (dangerous tool use classifier)
|
|
8
|
+
|
|
9
|
+
## 4.0.58
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [2973485]
|
|
14
|
+
- Updated dependencies [a4db5ea]
|
|
15
|
+
- Updated dependencies [2937ea2]
|
|
16
|
+
- @ai-sdk/provider-utils@5.0.45
|
|
17
|
+
|
|
3
18
|
## 4.0.57
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
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 { ToolExecuteFunction, Tool, Experimental_SandboxSession, ProviderDefinedTool, 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
|
*
|
|
@@ -57,6 +70,18 @@ interface AnthropicMessageMetadata {
|
|
|
57
70
|
path: string;
|
|
58
71
|
reason: string;
|
|
59
72
|
}>;
|
|
73
|
+
/**
|
|
74
|
+
* Verdicts of the server-side safeguards requested with
|
|
75
|
+
* `providerOptions.anthropic.safeguards`, one entry per requested safeguard.
|
|
76
|
+
* For `dangerous_tool_use`, `status.type` is `'available'` when the
|
|
77
|
+
* classifier ran and `status.tool_uses` maps each tool call id to its
|
|
78
|
+
* verdict (`type: 'evaluated'` with an `outcome` of `'not_flagged'` or
|
|
79
|
+
* `'flagged'` plus an `explanation`, `'skipped'`, or `'unavailable'`).
|
|
80
|
+
*
|
|
81
|
+
* Kept in the API's wire shape (snake_case), since consumers such as Claude
|
|
82
|
+
* Code read the verdicts verbatim.
|
|
83
|
+
*/
|
|
84
|
+
safeguardResults?: AnthropicSafeguardResult[];
|
|
60
85
|
/**
|
|
61
86
|
* Details about why the request stopped. Present only when the API returns
|
|
62
87
|
* a `refusal` stop reason together with a `stop_details` object (a
|
|
@@ -219,9 +244,9 @@ type AnthropicSystemMessageProviderOptions = z.infer<typeof anthropicSystemMessa
|
|
|
219
244
|
declare const anthropicLanguageModelOptions: z.ZodObject<{
|
|
220
245
|
sendReasoning: z.ZodOptional<z.ZodBoolean>;
|
|
221
246
|
structuredOutputMode: z.ZodOptional<z.ZodEnum<{
|
|
247
|
+
auto: "auto";
|
|
222
248
|
outputFormat: "outputFormat";
|
|
223
249
|
jsonTool: "jsonTool";
|
|
224
|
-
auto: "auto";
|
|
225
250
|
}>>;
|
|
226
251
|
thinking: z.ZodOptional<z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
227
252
|
type: z.ZodLiteral<"adaptive">;
|
|
@@ -316,6 +341,10 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
|
|
|
316
341
|
}>>;
|
|
317
342
|
}, z.core.$strip>>]>>;
|
|
318
343
|
anthropicBeta: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
344
|
+
safeguards: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
345
|
+
type: z.ZodLiteral<"dangerous_tool_use">;
|
|
346
|
+
classifierContext: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
347
|
+
}, z.core.$strip>>>;
|
|
319
348
|
contextManagement: z.ZodOptional<z.ZodObject<{
|
|
320
349
|
edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
321
350
|
type: z.ZodLiteral<"clear_tool_uses_20250919">;
|
package/dist/index.js
CHANGED
|
@@ -156,6 +156,20 @@ var anthropicStopDetailsSchema = z3.object({
|
|
|
156
156
|
explanation: z3.string().nullish(),
|
|
157
157
|
recommended_model: z3.string().nullish()
|
|
158
158
|
});
|
|
159
|
+
var anthropicSafeguardResultSchema = z3.object({
|
|
160
|
+
type: z3.string(),
|
|
161
|
+
status: z3.object({
|
|
162
|
+
type: z3.string(),
|
|
163
|
+
tool_uses: z3.record(
|
|
164
|
+
z3.string(),
|
|
165
|
+
z3.object({
|
|
166
|
+
type: z3.string(),
|
|
167
|
+
outcome: z3.string().nullish(),
|
|
168
|
+
explanation: z3.string().nullish()
|
|
169
|
+
})
|
|
170
|
+
).nullish()
|
|
171
|
+
})
|
|
172
|
+
});
|
|
159
173
|
var anthropicToolCallCallerSchema = z3.union([
|
|
160
174
|
z3.object({
|
|
161
175
|
type: z3.literal("code_execution_20250825"),
|
|
@@ -489,6 +503,7 @@ var anthropicResponseSchema = lazySchema3(
|
|
|
489
503
|
stop_sequence: z3.string().nullish(),
|
|
490
504
|
stop_details: anthropicStopDetailsSchema.nullish(),
|
|
491
505
|
input_transformations: z3.array(anthropicInputTransformationSchema).nullish(),
|
|
506
|
+
safeguard_results: z3.array(anthropicSafeguardResultSchema).nullish(),
|
|
492
507
|
usage: z3.looseObject({
|
|
493
508
|
input_tokens: z3.number(),
|
|
494
509
|
output_tokens: z3.number(),
|
|
@@ -872,6 +887,7 @@ var anthropicChunkSchema = lazySchema3(
|
|
|
872
887
|
stop_reason: z3.string().nullish(),
|
|
873
888
|
stop_sequence: z3.string().nullish(),
|
|
874
889
|
stop_details: anthropicStopDetailsSchema.nullish(),
|
|
890
|
+
safeguard_results: z3.array(anthropicSafeguardResultSchema).nullish(),
|
|
875
891
|
container: z3.object({
|
|
876
892
|
expires_at: z3.string(),
|
|
877
893
|
id: z3.string(),
|
|
@@ -1220,6 +1236,22 @@ var anthropicLanguageModelOptions = z4.object({
|
|
|
1220
1236
|
* Allow a provider to receive the full `betas` set if it needs it.
|
|
1221
1237
|
*/
|
|
1222
1238
|
anthropicBeta: z4.array(z4.string()).optional(),
|
|
1239
|
+
/**
|
|
1240
|
+
* Server-side safeguards to run as part of the request.
|
|
1241
|
+
*
|
|
1242
|
+
* `dangerous_tool_use` asks the API to classify every `tool_use` block in
|
|
1243
|
+
* the response for dangerous actions (the check Claude Code's auto mode
|
|
1244
|
+
* relies on). The per-call verdicts are returned in
|
|
1245
|
+
* `providerMetadata.anthropic.safeguardResults`, keyed by tool call id.
|
|
1246
|
+
* `classifierContext` is passed through to the API as `classifier_context`.
|
|
1247
|
+
* The `dangerous-tool-use-2026-09-03` beta is added automatically.
|
|
1248
|
+
*/
|
|
1249
|
+
safeguards: z4.array(
|
|
1250
|
+
z4.object({
|
|
1251
|
+
type: z4.literal("dangerous_tool_use"),
|
|
1252
|
+
classifierContext: z4.record(z4.string(), z4.unknown()).optional()
|
|
1253
|
+
})
|
|
1254
|
+
).optional(),
|
|
1223
1255
|
contextManagement: z4.object({
|
|
1224
1256
|
edits: z4.array(
|
|
1225
1257
|
z4.discriminatedUnion("type", [
|
|
@@ -4252,6 +4284,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4252
4284
|
// prompt:
|
|
4253
4285
|
system: messagesPrompt.system,
|
|
4254
4286
|
messages: messagesPrompt.messages,
|
|
4287
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0 && {
|
|
4288
|
+
safeguards: anthropicOptions.safeguards.map((safeguard) => ({
|
|
4289
|
+
type: safeguard.type,
|
|
4290
|
+
...safeguard.classifierContext !== void 0 && {
|
|
4291
|
+
classifier_context: safeguard.classifierContext
|
|
4292
|
+
}
|
|
4293
|
+
}))
|
|
4294
|
+
},
|
|
4255
4295
|
...contextManagement && {
|
|
4256
4296
|
context_management: {
|
|
4257
4297
|
edits: contextManagement.edits.map((edit) => {
|
|
@@ -4364,6 +4404,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4364
4404
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
|
|
4365
4405
|
betas.add("mcp-client-2025-04-04");
|
|
4366
4406
|
}
|
|
4407
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0) {
|
|
4408
|
+
betas.add("dangerous-tool-use-2026-09-03");
|
|
4409
|
+
}
|
|
4367
4410
|
if (contextManagement) {
|
|
4368
4411
|
betas.add("context-management-2025-06-27");
|
|
4369
4412
|
if (contextManagement.edits.some((e) => e.type === "compact_20260112")) {
|
|
@@ -4985,6 +5028,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4985
5028
|
stopSequence: (_a2 = response.stop_sequence) != null ? _a2 : null,
|
|
4986
5029
|
...stopDetails != null ? { stopDetails } : {},
|
|
4987
5030
|
...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
|
|
5031
|
+
...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
|
|
4988
5032
|
iterations: response.usage.iterations ? response.usage.iterations.map(
|
|
4989
5033
|
(iter) => ({
|
|
4990
5034
|
type: iter.type,
|
|
@@ -5071,6 +5115,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5071
5115
|
let stopSequence = null;
|
|
5072
5116
|
let stopDetails = void 0;
|
|
5073
5117
|
let inputTransformations;
|
|
5118
|
+
let safeguardResults;
|
|
5074
5119
|
let container = null;
|
|
5075
5120
|
let isJsonResponseFromTool = false;
|
|
5076
5121
|
let isMessageOpen = false;
|
|
@@ -5845,6 +5890,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5845
5890
|
if (value.input_transformations != null) {
|
|
5846
5891
|
inputTransformations = value.input_transformations;
|
|
5847
5892
|
}
|
|
5893
|
+
if (value.delta.safeguard_results != null) {
|
|
5894
|
+
safeguardResults = value.delta.safeguard_results;
|
|
5895
|
+
}
|
|
5848
5896
|
rawUsage = {
|
|
5849
5897
|
...rawUsage,
|
|
5850
5898
|
...value.usage
|
|
@@ -5859,6 +5907,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5859
5907
|
stopSequence,
|
|
5860
5908
|
...stopDetails != null ? { stopDetails } : {},
|
|
5861
5909
|
...inputTransformations != null ? { inputTransformations } : {},
|
|
5910
|
+
...safeguardResults != null ? { safeguardResults } : {},
|
|
5862
5911
|
iterations: usage.iterations ? usage.iterations.map(
|
|
5863
5912
|
(iter) => ({
|
|
5864
5913
|
type: iter.type,
|
|
@@ -7002,6 +7051,7 @@ function convertAnthropicMessageMetadata(response) {
|
|
|
7002
7051
|
stopSequence: (_a = response.stop_sequence) != null ? _a : null,
|
|
7003
7052
|
...stopDetails != null ? { stopDetails } : {},
|
|
7004
7053
|
...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
|
|
7054
|
+
...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
|
|
7005
7055
|
iterations: response.usage.iterations ? response.usage.iterations.map(
|
|
7006
7056
|
(iteration) => ({
|
|
7007
7057
|
type: iteration.type,
|
|
@@ -7826,7 +7876,7 @@ var AnthropicSkills = class {
|
|
|
7826
7876
|
};
|
|
7827
7877
|
|
|
7828
7878
|
// src/version.ts
|
|
7829
|
-
var VERSION = true ? "4.0.
|
|
7879
|
+
var VERSION = true ? "4.0.59" : "0.0.0-test";
|
|
7830
7880
|
|
|
7831
7881
|
// src/anthropic-provider.ts
|
|
7832
7882
|
var ANTHROPIC_API_URL = "https://api.anthropic.com";
|