@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.
- package/CHANGELOG.md +6 -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 +1 -1
- 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/dist/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "@ai-sdk/provider-utils";
|
|
13
13
|
|
|
14
14
|
// src/version.ts
|
|
15
|
-
var VERSION = true ? "3.0.
|
|
15
|
+
var VERSION = true ? "3.0.127" : "0.0.0-test";
|
|
16
16
|
|
|
17
17
|
// src/anthropic-messages-language-model.ts
|
|
18
18
|
import {
|
|
@@ -66,6 +66,20 @@ var anthropicStopDetailsSchema = z2.object({
|
|
|
66
66
|
explanation: z2.string().nullish(),
|
|
67
67
|
recommended_model: z2.string().nullish()
|
|
68
68
|
});
|
|
69
|
+
var anthropicSafeguardResultSchema = z2.object({
|
|
70
|
+
type: z2.string(),
|
|
71
|
+
status: z2.object({
|
|
72
|
+
type: z2.string(),
|
|
73
|
+
tool_uses: z2.record(
|
|
74
|
+
z2.string(),
|
|
75
|
+
z2.object({
|
|
76
|
+
type: z2.string(),
|
|
77
|
+
outcome: z2.string().nullish(),
|
|
78
|
+
explanation: z2.string().nullish()
|
|
79
|
+
})
|
|
80
|
+
).nullish()
|
|
81
|
+
})
|
|
82
|
+
});
|
|
69
83
|
var anthropicToolCallCallerSchema = z2.union([
|
|
70
84
|
z2.object({
|
|
71
85
|
type: z2.literal("code_execution_20250825"),
|
|
@@ -366,6 +380,7 @@ var anthropicMessagesResponseSchema = lazySchema2(
|
|
|
366
380
|
stop_sequence: z2.string().nullish(),
|
|
367
381
|
stop_details: anthropicStopDetailsSchema.nullish(),
|
|
368
382
|
input_transformations: z2.array(anthropicInputTransformationSchema).nullish(),
|
|
383
|
+
safeguard_results: z2.array(anthropicSafeguardResultSchema).nullish(),
|
|
369
384
|
usage: z2.looseObject({
|
|
370
385
|
input_tokens: z2.number(),
|
|
371
386
|
output_tokens: z2.number(),
|
|
@@ -775,6 +790,7 @@ var anthropicMessagesChunkSchema = lazySchema2(
|
|
|
775
790
|
stop_reason: z2.string().nullish(),
|
|
776
791
|
stop_sequence: z2.string().nullish(),
|
|
777
792
|
stop_details: anthropicStopDetailsSchema.nullish(),
|
|
793
|
+
safeguard_results: z2.array(anthropicSafeguardResultSchema).nullish(),
|
|
778
794
|
container: z2.object({
|
|
779
795
|
expires_at: z2.string(),
|
|
780
796
|
id: z2.string(),
|
|
@@ -1133,6 +1149,22 @@ var anthropicLanguageModelOptions = z3.object({
|
|
|
1133
1149
|
* Allow a provider to receive the full `betas` set if it needs it.
|
|
1134
1150
|
*/
|
|
1135
1151
|
anthropicBeta: z3.array(z3.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: z3.array(
|
|
1163
|
+
z3.object({
|
|
1164
|
+
type: z3.literal("dangerous_tool_use"),
|
|
1165
|
+
classifierContext: z3.record(z3.string(), z3.unknown()).optional()
|
|
1166
|
+
})
|
|
1167
|
+
).optional(),
|
|
1136
1168
|
contextManagement: z3.object({
|
|
1137
1169
|
edits: z3.array(
|
|
1138
1170
|
z3.discriminatedUnion("type", [
|
|
@@ -4089,6 +4121,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4089
4121
|
// prompt:
|
|
4090
4122
|
system: messagesPrompt.system,
|
|
4091
4123
|
messages: messagesPrompt.messages,
|
|
4124
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0 && {
|
|
4125
|
+
safeguards: anthropicOptions.safeguards.map((safeguard) => ({
|
|
4126
|
+
type: safeguard.type,
|
|
4127
|
+
...safeguard.classifierContext !== void 0 && {
|
|
4128
|
+
classifier_context: safeguard.classifierContext
|
|
4129
|
+
}
|
|
4130
|
+
}))
|
|
4131
|
+
},
|
|
4092
4132
|
...contextManagement && {
|
|
4093
4133
|
context_management: {
|
|
4094
4134
|
edits: contextManagement.edits.map((edit) => {
|
|
@@ -4201,6 +4241,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4201
4241
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.mcpServers) && anthropicOptions.mcpServers.length > 0) {
|
|
4202
4242
|
betas.add("mcp-client-2025-04-04");
|
|
4203
4243
|
}
|
|
4244
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.safeguards) && anthropicOptions.safeguards.length > 0) {
|
|
4245
|
+
betas.add("dangerous-tool-use-2026-09-03");
|
|
4246
|
+
}
|
|
4204
4247
|
if (contextManagement) {
|
|
4205
4248
|
betas.add("context-management-2025-06-27");
|
|
4206
4249
|
if (contextManagement.edits.some((e) => e.type === "compact_20260112")) {
|
|
@@ -4824,6 +4867,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4824
4867
|
stopSequence: (_b2 = response.stop_sequence) != null ? _b2 : null,
|
|
4825
4868
|
...stopDetails != null ? { stopDetails } : {},
|
|
4826
4869
|
...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
|
|
4870
|
+
...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
|
|
4827
4871
|
iterations: response.usage.iterations ? response.usage.iterations.map(
|
|
4828
4872
|
(iter) => ({
|
|
4829
4873
|
type: iter.type,
|
|
@@ -4914,6 +4958,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4914
4958
|
let stopSequence = null;
|
|
4915
4959
|
let stopDetails = void 0;
|
|
4916
4960
|
let inputTransformations;
|
|
4961
|
+
let safeguardResults;
|
|
4917
4962
|
let container = null;
|
|
4918
4963
|
let isJsonResponseFromTool = false;
|
|
4919
4964
|
let isMessageOpen = false;
|
|
@@ -5735,6 +5780,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5735
5780
|
if (value.input_transformations != null) {
|
|
5736
5781
|
inputTransformations = value.input_transformations;
|
|
5737
5782
|
}
|
|
5783
|
+
if (value.delta.safeguard_results != null) {
|
|
5784
|
+
safeguardResults = value.delta.safeguard_results;
|
|
5785
|
+
}
|
|
5738
5786
|
rawUsage = {
|
|
5739
5787
|
...rawUsage,
|
|
5740
5788
|
...value.usage
|
|
@@ -5750,6 +5798,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
5750
5798
|
stopSequence,
|
|
5751
5799
|
...stopDetails != null ? { stopDetails } : {},
|
|
5752
5800
|
...inputTransformations != null ? { inputTransformations } : {},
|
|
5801
|
+
...safeguardResults != null ? { safeguardResults } : {},
|
|
5753
5802
|
iterations: usage.iterations ? usage.iterations.map(
|
|
5754
5803
|
(iter) => ({
|
|
5755
5804
|
type: iter.type,
|