@ai-sdk/anthropic 4.0.96 → 4.0.98
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 +35 -0
- package/dist/index.d.ts +26 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +332 -65
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +287 -11
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +326 -66
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +292 -1
- package/package.json +3 -3
- package/src/anthropic-api.ts +24 -6
- package/src/anthropic-batch.ts +8 -0
- package/src/anthropic-error.ts +7 -0
- package/src/anthropic-language-model-options.ts +57 -7
- package/src/anthropic-language-model.ts +143 -15
- package/src/anthropic-message-metadata.ts +3 -0
- package/src/anthropic-model-catalog.ts +6 -0
- package/src/anthropic-prepare-tools.ts +24 -10
- package/src/anthropic-provider.ts +2 -1
- package/src/convert-to-anthropic-prompt.ts +141 -3
- package/src/files/anthropic-files-api.ts +26 -0
- package/src/files/anthropic-files.ts +217 -0
- package/src/get-cache-control.ts +6 -1
- package/src/internal/index.ts +7 -1
- package/src/anthropic-files.ts +0 -104
package/dist/internal/index.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertBase64ToUint8Array, convertInlineFileDataToUint8Array, convertToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, encodePathSegment, experimental_toolCaller, generateId, getFromApi, getTopLevelMediaType, isCustomReasoning, isNonNullable, isProviderStreamError, isRecord, lazySchema, mapReasoningToProviderBudget, mapReasoningToProviderEffort, parseProviderOptions, postFormDataToApi, postJsonToApi, resolve, resolveFullMediaType, resolveProviderReference, safeValidateTypes, secureJsonParse, serializeModelOptions, stringifyWithBigIntAndCycles, validateTypes, zodSchema } from "@ai-sdk/provider-utils";
|
|
2
|
-
import { z } from "zod/v4";
|
|
3
1
|
import { APICallError, InvalidArgumentError, InvalidResponseDataError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
|
|
2
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertBase64ToUint8Array, convertInlineFileDataToUint8Array, convertToBase64, createBinaryStreamResponseHandler, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createProviderDefinedToolFactory, createProviderExecutedToolFactory, createProviderStreamError, createToolNameMapping, deleteFromApi, encodePathSegment, experimental_toolCaller, generateId, getFromApi, getTopLevelMediaType, isCustomReasoning, isNonNullable, isProviderStreamError, isRecord, lazySchema, mapReasoningToProviderBudget, mapReasoningToProviderEffort, parseProviderOptions, postFormDataToApi, postJsonToApi, resolve, resolveFullMediaType, resolveProviderReference, safeValidateTypes, secureJsonParse, serializeModelOptions, stringifyWithBigIntAndCycles, validateTypes, zodSchema } from "@ai-sdk/provider-utils";
|
|
3
|
+
import { z } from "zod/v4";
|
|
4
4
|
//#region src/anthropic-error.ts
|
|
5
5
|
const anthropicErrorDataSchema = lazySchema(() => zodSchema(z.object({
|
|
6
6
|
type: z.literal("error"),
|
|
7
7
|
error: z.object({
|
|
8
8
|
type: z.string(),
|
|
9
|
-
message: z.string()
|
|
9
|
+
message: z.string(),
|
|
10
|
+
details: z.object({
|
|
11
|
+
error_code: z.string().nullish().catch(void 0),
|
|
12
|
+
unsupported: z.array(z.string()).nullish().catch(void 0)
|
|
13
|
+
}).nullish().catch(void 0)
|
|
10
14
|
})
|
|
11
15
|
})));
|
|
12
16
|
const anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
@@ -14,16 +18,23 @@ const anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
14
18
|
errorToMessage: (data) => data.error.message
|
|
15
19
|
});
|
|
16
20
|
//#endregion
|
|
17
|
-
//#region src/anthropic-files.ts
|
|
21
|
+
//#region src/files/anthropic-files-api.ts
|
|
18
22
|
const anthropicUploadFileResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
19
23
|
id: z.string(),
|
|
20
|
-
type: z.literal("file"),
|
|
21
|
-
filename: z.string(),
|
|
22
|
-
mime_type: z.string(),
|
|
23
|
-
size_bytes: z.number(),
|
|
24
|
-
created_at: z.string(),
|
|
25
|
-
downloadable: z.boolean().nullish()
|
|
24
|
+
type: z.literal("file").nullish(),
|
|
25
|
+
filename: z.string().nullish(),
|
|
26
|
+
mime_type: z.string().nullish(),
|
|
27
|
+
size_bytes: z.number().nullish(),
|
|
28
|
+
created_at: z.string().nullish(),
|
|
29
|
+
downloadable: z.boolean().nullish(),
|
|
30
|
+
expires_at: z.string().nullish()
|
|
26
31
|
})));
|
|
32
|
+
const anthropicDeleteFileResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
33
|
+
type: z.literal("file_deleted").nullish(),
|
|
34
|
+
id: z.string()
|
|
35
|
+
})));
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/files/anthropic-files.ts
|
|
27
38
|
var AnthropicFiles = class {
|
|
28
39
|
get provider() {
|
|
29
40
|
return this.config.provider;
|
|
@@ -32,6 +43,17 @@ var AnthropicFiles = class {
|
|
|
32
43
|
this.config = config;
|
|
33
44
|
this.specificationVersion = "v4";
|
|
34
45
|
}
|
|
46
|
+
getFileId(file) {
|
|
47
|
+
const fileId = file.anthropic;
|
|
48
|
+
if (fileId == null || fileId.trim() === "") throw new InvalidArgumentError({
|
|
49
|
+
argument: "file",
|
|
50
|
+
message: "file reference is missing an 'anthropic' file id."
|
|
51
|
+
});
|
|
52
|
+
return fileId;
|
|
53
|
+
}
|
|
54
|
+
async getHeaders(headers) {
|
|
55
|
+
return combineHeaders(await resolve(this.config.headers), { "anthropic-beta": "files-api-2025-04-14" }, headers);
|
|
56
|
+
}
|
|
35
57
|
async uploadFile({ data, mediaType, filename, abortSignal, headers }) {
|
|
36
58
|
const fileBytes = convertInlineFileDataToUint8Array(data);
|
|
37
59
|
const blob = new Blob([fileBytes], { type: mediaType });
|
|
@@ -40,7 +62,7 @@ var AnthropicFiles = class {
|
|
|
40
62
|
else formData.append("file", blob);
|
|
41
63
|
const { value: response } = await postFormDataToApi({
|
|
42
64
|
url: `${this.config.baseURL}/files`,
|
|
43
|
-
headers:
|
|
65
|
+
headers: await this.getHeaders(headers),
|
|
44
66
|
formData,
|
|
45
67
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
46
68
|
successfulResponseHandler: createJsonResponseHandler(anthropicUploadFileResponseSchema),
|
|
@@ -52,13 +74,76 @@ var AnthropicFiles = class {
|
|
|
52
74
|
providerReference: { anthropic: response.id },
|
|
53
75
|
mediaType: response.mime_type ?? mediaType,
|
|
54
76
|
filename: response.filename ?? filename,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
77
|
+
byteSize: response.size_bytes ?? void 0,
|
|
78
|
+
createdAt: response.created_at != null ? new Date(response.created_at) : void 0,
|
|
79
|
+
expiresAt: response.expires_at != null ? new Date(response.expires_at) : void 0,
|
|
80
|
+
providerMetadata: { anthropic: this.toFileMetadata(response) }
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
async deleteFile({ file, abortSignal, headers }) {
|
|
84
|
+
const fileId = this.getFileId(file);
|
|
85
|
+
const { value: response } = await deleteFromApi({
|
|
86
|
+
url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}`,
|
|
87
|
+
headers: await this.getHeaders(headers),
|
|
88
|
+
abortSignal,
|
|
89
|
+
fetch: this.config.fetch,
|
|
90
|
+
failedResponseHandler: anthropicFailedResponseHandler,
|
|
91
|
+
successfulResponseHandler: createJsonResponseHandler(anthropicDeleteFileResponseSchema)
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
warnings: [],
|
|
95
|
+
providerReference: { anthropic: response.id },
|
|
96
|
+
deleted: true
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
async getFileMetadata({ file, abortSignal, headers }) {
|
|
100
|
+
const fileId = this.getFileId(file);
|
|
101
|
+
const { value: response } = await getFromApi({
|
|
102
|
+
url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}`,
|
|
103
|
+
headers: await this.getHeaders(headers),
|
|
104
|
+
abortSignal,
|
|
105
|
+
fetch: this.config.fetch,
|
|
106
|
+
failedResponseHandler: anthropicFailedResponseHandler,
|
|
107
|
+
successfulResponseHandler: createJsonResponseHandler(anthropicUploadFileResponseSchema),
|
|
108
|
+
validateUrl: false
|
|
109
|
+
});
|
|
110
|
+
return {
|
|
111
|
+
warnings: [],
|
|
112
|
+
providerReference: { anthropic: response.id },
|
|
113
|
+
filename: response.filename ?? void 0,
|
|
114
|
+
mediaType: response.mime_type ?? void 0,
|
|
115
|
+
byteSize: response.size_bytes ?? void 0,
|
|
116
|
+
createdAt: response.created_at != null ? new Date(response.created_at) : void 0,
|
|
117
|
+
expiresAt: response.expires_at != null ? new Date(response.expires_at) : void 0,
|
|
118
|
+
providerMetadata: { anthropic: this.toFileMetadata(response) }
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
toFileMetadata(response) {
|
|
122
|
+
return {
|
|
123
|
+
...response.filename != null ? { filename: response.filename } : {},
|
|
124
|
+
...response.mime_type != null ? { mimeType: response.mime_type } : {},
|
|
125
|
+
...response.size_bytes != null ? { sizeBytes: response.size_bytes } : {},
|
|
126
|
+
...response.created_at != null ? { createdAt: response.created_at } : {},
|
|
127
|
+
...response.downloadable != null ? { downloadable: response.downloadable } : {},
|
|
128
|
+
...response.expires_at != null ? { expiresAt: response.expires_at } : {}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
async downloadFile({ file, abortSignal, headers }) {
|
|
132
|
+
const fileId = this.getFileId(file);
|
|
133
|
+
const { value: content, responseHeaders } = await getFromApi({
|
|
134
|
+
url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}/content`,
|
|
135
|
+
headers: await this.getHeaders(headers),
|
|
136
|
+
abortSignal,
|
|
137
|
+
fetch: this.config.fetch,
|
|
138
|
+
failedResponseHandler: anthropicFailedResponseHandler,
|
|
139
|
+
successfulResponseHandler: createBinaryStreamResponseHandler(),
|
|
140
|
+
validateUrl: false
|
|
141
|
+
});
|
|
142
|
+
const mediaType = responseHeaders?.["content-type"]?.split(";")[0].trim();
|
|
143
|
+
return {
|
|
144
|
+
warnings: [],
|
|
145
|
+
content,
|
|
146
|
+
...mediaType ? { mediaType } : {}
|
|
62
147
|
};
|
|
63
148
|
}
|
|
64
149
|
};
|
|
@@ -69,7 +154,9 @@ var AnthropicFiles = class {
|
|
|
69
154
|
* keeps this list in sync with the option schema.
|
|
70
155
|
*/
|
|
71
156
|
const anthropicProviderOptions = { language: {
|
|
157
|
+
thread: { description: "Create or continue a short-lived message thread." },
|
|
72
158
|
sendReasoning: { description: "Whether to send reasoning to the model." },
|
|
159
|
+
includePings: { description: "Include transient ping events in streams." },
|
|
73
160
|
structuredOutputMode: { description: "How structured outputs are generated." },
|
|
74
161
|
thinking: { description: "Extended thinking configuration." },
|
|
75
162
|
disableParallelToolUse: { description: "Use at most one tool per response." },
|
|
@@ -345,6 +432,7 @@ function createAnthropicLanguageModelEntry(modelId, documented) {
|
|
|
345
432
|
compaction: documented?.compaction ?? "unknown"
|
|
346
433
|
} },
|
|
347
434
|
providerOptions: { language: declareProviderOptions(anthropicProviderOptions.language, declared ? true : "unknown", {
|
|
435
|
+
includePings: true,
|
|
348
436
|
thinking: reasoningSupport,
|
|
349
437
|
effort: documented?.effort ?? "unknown",
|
|
350
438
|
speed: declared ? modelId === "claude-opus-4-6" : "unknown",
|
|
@@ -721,10 +809,12 @@ const anthropicResponseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
721
809
|
])),
|
|
722
810
|
stop_reason: z.string().nullish(),
|
|
723
811
|
stop_sequence: z.string().nullish(),
|
|
812
|
+
service_tier: z.string().nullish(),
|
|
724
813
|
stop_details: anthropicStopDetailsSchema().nullish(),
|
|
725
814
|
input_transformations: z.array(anthropicInputTransformationSchema()).nullish(),
|
|
726
815
|
safeguard_results: z.array(anthropicSafeguardResultSchema()).nullish(),
|
|
727
816
|
usage: z.looseObject({
|
|
817
|
+
service_tier: z.string().nullish(),
|
|
728
818
|
input_tokens: z.number(),
|
|
729
819
|
output_tokens: z.number(),
|
|
730
820
|
output_tokens_details: z.object({ thinking_tokens: z.number().nullish() }).nullish(),
|
|
@@ -774,7 +864,9 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
|
|
|
774
864
|
id: z.string().nullish(),
|
|
775
865
|
model: z.string().nullish(),
|
|
776
866
|
role: z.string().nullish(),
|
|
867
|
+
service_tier: z.string().nullish(),
|
|
777
868
|
usage: z.looseObject({
|
|
869
|
+
service_tier: z.string().nullish(),
|
|
778
870
|
input_tokens: z.number(),
|
|
779
871
|
cache_creation_input_tokens: z.number().nullish(),
|
|
780
872
|
cache_read_input_tokens: z.number().nullish()
|
|
@@ -1063,6 +1155,7 @@ const anthropicChunkSchema = lazySchema(() => zodSchema(z.discriminatedUnion("ty
|
|
|
1063
1155
|
}).nullish()
|
|
1064
1156
|
}),
|
|
1065
1157
|
usage: z.looseObject({
|
|
1158
|
+
service_tier: z.string().nullish(),
|
|
1066
1159
|
input_tokens: z.number().nullish(),
|
|
1067
1160
|
output_tokens: z.number(),
|
|
1068
1161
|
output_tokens_details: z.object({ thinking_tokens: z.number().nullish() }).nullish(),
|
|
@@ -1171,20 +1264,55 @@ const anthropicSystemMessageProviderOptions = lazySchema(() => zodSchema(z.objec
|
|
|
1171
1264
|
* initial system prompt). A system message carrying tool changes must come
|
|
1172
1265
|
* right before an assistant message or at the end of the messages.
|
|
1173
1266
|
*
|
|
1174
|
-
*
|
|
1175
|
-
*
|
|
1176
|
-
* the
|
|
1177
|
-
* `
|
|
1267
|
+
* A `tool_addition` either references a tool by `toolName` or defines it
|
|
1268
|
+
* by value with `tool`:
|
|
1269
|
+
* - By reference: the tool must be declared in the `tools` option
|
|
1270
|
+
* (typically with `deferLoading: true` so it is not loaded until the
|
|
1271
|
+
* addition surfaces it). The required
|
|
1272
|
+
* `mid-conversation-tool-changes-2026-07-01` beta is added
|
|
1273
|
+
* automatically.
|
|
1274
|
+
* - By value: `tool` is a function or provider tool, in the same shape as
|
|
1275
|
+
* an entry of the `tools` option. The tool does not need to be declared
|
|
1276
|
+
* in `tools`, and defining a tool under an existing name replaces it
|
|
1277
|
+
* from that point on. The required `inline-tools-2026-09-15` beta is
|
|
1278
|
+
* added automatically.
|
|
1279
|
+
*
|
|
1280
|
+
* A `tool_removal` always references the tool by `toolName`.
|
|
1178
1281
|
*/
|
|
1179
|
-
toolChanges: z.array(z.
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1282
|
+
toolChanges: z.array(z.union([
|
|
1283
|
+
z.object({
|
|
1284
|
+
type: z.literal("tool_addition"),
|
|
1285
|
+
toolName: z.string()
|
|
1286
|
+
}),
|
|
1287
|
+
z.object({
|
|
1288
|
+
type: z.literal("tool_addition"),
|
|
1289
|
+
tool: z.union([z.looseObject({
|
|
1290
|
+
type: z.literal("function"),
|
|
1291
|
+
name: z.string(),
|
|
1292
|
+
inputSchema: z.record(z.string(), z.unknown())
|
|
1293
|
+
}), z.looseObject({
|
|
1294
|
+
type: z.literal("provider"),
|
|
1295
|
+
id: z.string(),
|
|
1296
|
+
name: z.string(),
|
|
1297
|
+
args: z.record(z.string(), z.unknown())
|
|
1298
|
+
})])
|
|
1299
|
+
}),
|
|
1300
|
+
z.object({
|
|
1301
|
+
type: z.literal("tool_removal"),
|
|
1302
|
+
toolName: z.string()
|
|
1303
|
+
})
|
|
1304
|
+
])).optional()
|
|
1186
1305
|
})));
|
|
1187
1306
|
const anthropicLanguageModelOptions = lazySchema(() => zodSchema(z.object({
|
|
1307
|
+
/**
|
|
1308
|
+
* Create or continue a short-lived server-side message thread.
|
|
1309
|
+
* On continuation, messages must contain only new messages. Keep the full
|
|
1310
|
+
* conversation locally so it can be replayed when the thread expires.
|
|
1311
|
+
*/
|
|
1312
|
+
thread: z.discriminatedUnion("type", [z.object({ type: z.literal("create") }), z.object({
|
|
1313
|
+
type: z.literal("continue"),
|
|
1314
|
+
previousMessageId: z.string().min(1)
|
|
1315
|
+
})]).optional(),
|
|
1188
1316
|
/**
|
|
1189
1317
|
* Whether to send reasoning to the model.
|
|
1190
1318
|
*
|
|
@@ -1203,6 +1331,8 @@ const anthropicLanguageModelOptions = lazySchema(() => zodSchema(z.object({
|
|
|
1203
1331
|
"jsonTool",
|
|
1204
1332
|
"auto"
|
|
1205
1333
|
]).optional(),
|
|
1334
|
+
/** Emit typed streaming heartbeat parts. Disabled by default. */
|
|
1335
|
+
includePings: z.boolean().optional(),
|
|
1206
1336
|
/**
|
|
1207
1337
|
* Configuration for enabling Claude's extended thinking.
|
|
1208
1338
|
*
|
|
@@ -1352,8 +1482,17 @@ userId: z.string().optional() }).optional(),
|
|
|
1352
1482
|
* Only supported with claude-opus-4-6.
|
|
1353
1483
|
*/
|
|
1354
1484
|
speed: z.enum(["fast", "standard"]).optional(),
|
|
1355
|
-
/**
|
|
1356
|
-
|
|
1485
|
+
/**
|
|
1486
|
+
* Request admission tier. Anthropic accepts `auto` and `standard_only`;
|
|
1487
|
+
* MiniMax accepts `standard` and `priority`. Values for another known
|
|
1488
|
+
* provider are omitted with an unsupported-setting warning.
|
|
1489
|
+
*/
|
|
1490
|
+
serviceTier: z.enum([
|
|
1491
|
+
"auto",
|
|
1492
|
+
"standard_only",
|
|
1493
|
+
"standard",
|
|
1494
|
+
"priority"
|
|
1495
|
+
]).optional(),
|
|
1357
1496
|
/**
|
|
1358
1497
|
* Controls where model inference runs for this request.
|
|
1359
1498
|
*
|
|
@@ -1465,10 +1604,11 @@ function getCacheControl(providerMetadata, providerOptionsName) {
|
|
|
1465
1604
|
return custom?.cacheControl ?? custom?.cache_control ?? anthropic?.cacheControl ?? anthropic?.cache_control;
|
|
1466
1605
|
}
|
|
1467
1606
|
var CacheControlValidator = class {
|
|
1468
|
-
constructor(providerOptionsName = "anthropic") {
|
|
1607
|
+
constructor(providerOptionsName = "anthropic", initialBreakpointCount = 0) {
|
|
1469
1608
|
this.providerOptionsName = providerOptionsName;
|
|
1470
1609
|
this.breakpointCount = 0;
|
|
1471
1610
|
this.warnings = [];
|
|
1611
|
+
this.breakpointCount = initialBreakpointCount;
|
|
1472
1612
|
}
|
|
1473
1613
|
getCacheControl(providerMetadata, context) {
|
|
1474
1614
|
const cacheControlValue = getCacheControl(providerMetadata, this.providerOptionsName);
|
|
@@ -1825,19 +1965,19 @@ const webFetch_20250910 = (args = {}) => {
|
|
|
1825
1965
|
};
|
|
1826
1966
|
//#endregion
|
|
1827
1967
|
//#region src/anthropic-prepare-tools.ts
|
|
1828
|
-
async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, defaultEagerInputStreaming = false, rejectsForcedToolUse = false }) {
|
|
1968
|
+
async function prepareTools({ tools, toolChoice, hasInlineTools = false, disableParallelToolUse, cacheControlValidator, supportsStructuredOutput, supportsStrictTools, defaultEagerInputStreaming = false, rejectsForcedToolUse = false }) {
|
|
1829
1969
|
tools = tools?.length ? tools : void 0;
|
|
1830
1970
|
const toolWarnings = [];
|
|
1831
1971
|
const betas = /* @__PURE__ */ new Set();
|
|
1832
1972
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
1833
|
-
if (tools == null) return {
|
|
1973
|
+
if (tools == null && !hasInlineTools) return {
|
|
1834
1974
|
tools: void 0,
|
|
1835
1975
|
toolChoice: void 0,
|
|
1836
1976
|
toolWarnings,
|
|
1837
1977
|
betas
|
|
1838
1978
|
};
|
|
1839
1979
|
const anthropicTools = [];
|
|
1840
|
-
for (const tool of tools) switch (tool.type) {
|
|
1980
|
+
for (const tool of tools ?? []) switch (tool.type) {
|
|
1841
1981
|
case "function": {
|
|
1842
1982
|
const cacheControl = validator.getCacheControl(tool.providerOptions, {
|
|
1843
1983
|
type: "tool definition",
|
|
@@ -1863,7 +2003,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
1863
2003
|
...allowedCallers != null ? { allowed_callers: allowedCallers } : {},
|
|
1864
2004
|
...tool.inputExamples != null ? { input_examples: tool.inputExamples.map((example) => example.input) } : {}
|
|
1865
2005
|
});
|
|
1866
|
-
if (supportsStructuredOutput === true) betas.add("structured-outputs-2025-11-13");
|
|
2006
|
+
if (supportsStructuredOutput === true && supportsStrictTools === true) betas.add("structured-outputs-2025-11-13");
|
|
1867
2007
|
if (tool.inputExamples != null || allowedCallers != null) betas.add("advanced-tool-use-2025-11-20");
|
|
1868
2008
|
break;
|
|
1869
2009
|
}
|
|
@@ -2144,8 +2284,9 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2144
2284
|
feature: `tool ${tool}`
|
|
2145
2285
|
});
|
|
2146
2286
|
}
|
|
2287
|
+
const declaredTools = tools == null ? void 0 : anthropicTools;
|
|
2147
2288
|
if (toolChoice == null) return {
|
|
2148
|
-
tools:
|
|
2289
|
+
tools: declaredTools,
|
|
2149
2290
|
toolChoice: disableParallelToolUse ? {
|
|
2150
2291
|
type: "auto",
|
|
2151
2292
|
disable_parallel_tool_use: disableParallelToolUse
|
|
@@ -2156,7 +2297,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2156
2297
|
const type = toolChoice.type;
|
|
2157
2298
|
switch (type) {
|
|
2158
2299
|
case "auto": return {
|
|
2159
|
-
tools:
|
|
2300
|
+
tools: declaredTools,
|
|
2160
2301
|
toolChoice: {
|
|
2161
2302
|
type: "auto",
|
|
2162
2303
|
disable_parallel_tool_use: disableParallelToolUse
|
|
@@ -2172,7 +2313,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2172
2313
|
details: "toolChoice 'required' is not supported with this model or thinking configuration. Using 'auto' instead. Instruct the model to use a tool in the prompt and verify that a tool call was made."
|
|
2173
2314
|
});
|
|
2174
2315
|
return {
|
|
2175
|
-
tools:
|
|
2316
|
+
tools: declaredTools,
|
|
2176
2317
|
toolChoice: {
|
|
2177
2318
|
type: "auto",
|
|
2178
2319
|
disable_parallel_tool_use: disableParallelToolUse
|
|
@@ -2182,7 +2323,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2182
2323
|
};
|
|
2183
2324
|
}
|
|
2184
2325
|
return {
|
|
2185
|
-
tools:
|
|
2326
|
+
tools: declaredTools,
|
|
2186
2327
|
toolChoice: {
|
|
2187
2328
|
type: "any",
|
|
2188
2329
|
disable_parallel_tool_use: disableParallelToolUse
|
|
@@ -2191,7 +2332,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2191
2332
|
betas
|
|
2192
2333
|
};
|
|
2193
2334
|
case "none": return {
|
|
2194
|
-
tools:
|
|
2335
|
+
tools: declaredTools,
|
|
2195
2336
|
toolChoice: { type: "none" },
|
|
2196
2337
|
toolWarnings,
|
|
2197
2338
|
betas
|
|
@@ -2204,7 +2345,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2204
2345
|
details: `toolChoice 'tool' is not supported with this model or thinking configuration. Only the '${toolChoice.toolName}' tool is sent with 'auto' tool choice. Instruct the model to use the tool in the prompt and verify that a tool call was made.`
|
|
2205
2346
|
});
|
|
2206
2347
|
return {
|
|
2207
|
-
tools:
|
|
2348
|
+
tools: declaredTools?.filter((tool) => "name" in tool && tool.name === toolChoice.toolName),
|
|
2208
2349
|
toolChoice: {
|
|
2209
2350
|
type: "auto",
|
|
2210
2351
|
disable_parallel_tool_use: disableParallelToolUse
|
|
@@ -2214,7 +2355,7 @@ async function prepareTools({ tools, toolChoice, disableParallelToolUse, cacheCo
|
|
|
2214
2355
|
};
|
|
2215
2356
|
}
|
|
2216
2357
|
return {
|
|
2217
|
-
tools:
|
|
2358
|
+
tools: declaredTools,
|
|
2218
2359
|
toolChoice: {
|
|
2219
2360
|
type: "tool",
|
|
2220
2361
|
name: toolChoice.toolName,
|
|
@@ -2592,7 +2733,31 @@ function extractErrorValue(value) {
|
|
|
2592
2733
|
}
|
|
2593
2734
|
return {};
|
|
2594
2735
|
}
|
|
2595
|
-
|
|
2736
|
+
function isComputerTool(tool) {
|
|
2737
|
+
return tool.type === "provider" && tool.id.startsWith("anthropic.computer_");
|
|
2738
|
+
}
|
|
2739
|
+
/**
|
|
2740
|
+
* Collects the tools that mid-conversation tool changes add by value, so they
|
|
2741
|
+
* can take part in tool name mapping like the tools of the `tools` option.
|
|
2742
|
+
* Tools that cannot be added by value are left out because they are ignored.
|
|
2743
|
+
*/
|
|
2744
|
+
async function getInlineToolsFromPrompt(prompt) {
|
|
2745
|
+
const inlineTools = [];
|
|
2746
|
+
for (const message of prompt) {
|
|
2747
|
+
if (message.role !== "system" || message.providerOptions == null) continue;
|
|
2748
|
+
const options = await parseProviderOptions({
|
|
2749
|
+
provider: "anthropic",
|
|
2750
|
+
providerOptions: message.providerOptions,
|
|
2751
|
+
schema: anthropicSystemMessageProviderOptions
|
|
2752
|
+
});
|
|
2753
|
+
for (const toolChange of options?.toolChanges ?? []) if ("tool" in toolChange) {
|
|
2754
|
+
const tool = toolChange.tool;
|
|
2755
|
+
if (!isComputerTool(tool)) inlineTools.push(tool);
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
return inlineTools;
|
|
2759
|
+
}
|
|
2760
|
+
async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cacheControlValidator, toolNameMapping, toolsetNames = {}, convertMediaPart, convertInlineTool }) {
|
|
2596
2761
|
const betas = /* @__PURE__ */ new Set();
|
|
2597
2762
|
const blocks = groupIntoBlocks(prompt);
|
|
2598
2763
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -2647,18 +2812,50 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
|
|
|
2647
2812
|
canCache: true
|
|
2648
2813
|
})
|
|
2649
2814
|
});
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2815
|
+
let toolChangeCount = 0;
|
|
2816
|
+
let hasInlineToolDefinition = false;
|
|
2817
|
+
for (const toolChange of toolChanges) {
|
|
2818
|
+
if ("tool" in toolChange) {
|
|
2819
|
+
if (convertInlineTool == null) throw new UnsupportedFunctionalityError({ functionality: "tool additions by value in mid-conversation tool changes" });
|
|
2820
|
+
const tool = toolChange.tool;
|
|
2821
|
+
if (isComputerTool(tool)) {
|
|
2822
|
+
warnings.push({
|
|
2823
|
+
type: "other",
|
|
2824
|
+
message: `The tool '${tool.name}' cannot be added by value in a tool change. Declare it in the tools option and add it by reference with toolName. The tool change has been ignored.`
|
|
2825
|
+
});
|
|
2826
|
+
continue;
|
|
2827
|
+
}
|
|
2828
|
+
const { definition, warnings: toolWarnings, betas: toolBetas } = await convertInlineTool(tool);
|
|
2829
|
+
warnings.push(...toolWarnings);
|
|
2830
|
+
for (const beta of toolBetas) betas.add(beta);
|
|
2831
|
+
if (definition == null) continue;
|
|
2832
|
+
content.push({
|
|
2833
|
+
type: "tool_addition",
|
|
2834
|
+
tool: {
|
|
2835
|
+
type: "tool_definition",
|
|
2836
|
+
definition
|
|
2837
|
+
}
|
|
2838
|
+
});
|
|
2839
|
+
toolChangeCount++;
|
|
2840
|
+
hasInlineToolDefinition = true;
|
|
2841
|
+
continue;
|
|
2655
2842
|
}
|
|
2656
|
-
|
|
2843
|
+
content.push({
|
|
2844
|
+
type: toolChange.type,
|
|
2845
|
+
tool: {
|
|
2846
|
+
type: "tool_reference",
|
|
2847
|
+
name: toolNameMapping.toProviderToolName(toolChange.toolName)
|
|
2848
|
+
}
|
|
2849
|
+
});
|
|
2850
|
+
toolChangeCount++;
|
|
2851
|
+
}
|
|
2852
|
+
if (content.length === 0 && systemMessageOptions?.clearAt == null && systemMessageOptions?.effort == null) continue;
|
|
2657
2853
|
convertedMessages.push({
|
|
2658
2854
|
content,
|
|
2659
2855
|
clearAt: systemMessageOptions?.clearAt,
|
|
2660
2856
|
effort: systemMessageOptions?.effort,
|
|
2661
|
-
toolChangeCount
|
|
2857
|
+
toolChangeCount,
|
|
2858
|
+
hasInlineToolDefinition
|
|
2662
2859
|
});
|
|
2663
2860
|
}
|
|
2664
2861
|
const toolChangeCount = convertedMessages.reduce((count, message) => count + message.toolChangeCount, 0);
|
|
@@ -2689,7 +2886,8 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
|
|
|
2689
2886
|
...message.clearAt != null && { clear_at: message.clearAt },
|
|
2690
2887
|
...message.effort != null && { output_config: { effort: message.effort } }
|
|
2691
2888
|
});
|
|
2692
|
-
if (message.
|
|
2889
|
+
if (message.hasInlineToolDefinition) betas.add("inline-tools-2026-09-15");
|
|
2890
|
+
else if (message.toolChangeCount > 0) betas.add("mid-conversation-tool-changes-2026-07-01");
|
|
2693
2891
|
if (message.clearAt != null) betas.add("mid-conversation-system-clear-at-2026-08-21");
|
|
2694
2892
|
if (message.effort != null) betas.add("mid-conversation-output-config-2026-07-01");
|
|
2695
2893
|
}
|
|
@@ -2994,7 +3192,7 @@ async function convertToAnthropicPrompt({ prompt, sendReasoning, warnings, cache
|
|
|
2994
3192
|
for (let j = 0; j < block.messages.length; j++) {
|
|
2995
3193
|
const message = block.messages[j];
|
|
2996
3194
|
const isLastMessage = j === block.messages.length - 1;
|
|
2997
|
-
const
|
|
3195
|
+
const content = message.content.filter((part) => part.type !== "text" || part.text.length > 0);
|
|
2998
3196
|
for (let k = 0; k < content.length; k++) {
|
|
2999
3197
|
const part = content[k];
|
|
3000
3198
|
const isLastContentPart = k === content.length - 1;
|
|
@@ -4120,6 +4318,17 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4120
4318
|
}) : null;
|
|
4121
4319
|
const usedCustomProviderKey = customProviderOptions != null;
|
|
4122
4320
|
const anthropicOptions = Object.assign({}, canonicalOptions ?? {}, customProviderOptions ?? {});
|
|
4321
|
+
if (anthropicOptions.serviceTier != null) {
|
|
4322
|
+
const supportedTiers = providerOptionsName === "anthropic" ? ["auto", "standard_only"] : providerOptionsName === "minimax" ? ["standard", "priority"] : void 0;
|
|
4323
|
+
if (supportedTiers != null && !supportedTiers.includes(anthropicOptions.serviceTier)) {
|
|
4324
|
+
warnings.push({
|
|
4325
|
+
type: "unsupported",
|
|
4326
|
+
feature: "serviceTier",
|
|
4327
|
+
details: `serviceTier "${anthropicOptions.serviceTier}" is not supported by ${providerOptionsName}. Use ${supportedTiers.map((tier) => `"${tier}"`).join(" or ")}.`
|
|
4328
|
+
});
|
|
4329
|
+
anthropicOptions.serviceTier = void 0;
|
|
4330
|
+
}
|
|
4331
|
+
}
|
|
4123
4332
|
const { maxOutputTokens: maxOutputTokensForModel, supportsStructuredOutput: modelSupportsStructuredOutput, supportsAdaptiveThinking, rejectsSamplingParameters, supportsXhighEffort, rejectsThinkingDisabledAboveHighEffort, rejectsThinkingDisabled, rejectsBudgetThinking, rejectsForcedToolUse, supportsBetweenToolsThinking, isKnownModel } = getAnthropicModelCapabilities(modelId);
|
|
4124
4333
|
if (!isKnownModel && maxOutputTokens == null) warnings.push({
|
|
4125
4334
|
type: "compatibility",
|
|
@@ -4183,9 +4392,20 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4183
4392
|
argument: "providerOptions",
|
|
4184
4393
|
message: "Anthropic provider options `compaction` and `contextManagement` cannot be used together."
|
|
4185
4394
|
});
|
|
4186
|
-
const
|
|
4395
|
+
const thread = anthropicOptions?.thread;
|
|
4396
|
+
if (thread != null && config.supportsMessageThreads !== true) throw new UnsupportedFunctionalityError({
|
|
4397
|
+
functionality: "Anthropic message threads",
|
|
4398
|
+
message: `${config.provider} does not support Anthropic message threads.`
|
|
4399
|
+
});
|
|
4400
|
+
if (thread != null && (compaction != null || contextManagement?.edits.some((edit) => edit.type !== "clear_thinking_20251015" || edit.keep !== "all"))) throw new InvalidArgumentError({
|
|
4401
|
+
argument: "providerOptions.anthropic.thread",
|
|
4402
|
+
message: "Anthropic message threads do not support compaction or context editing, except clear_thinking_20251015 with keep: \"all\"."
|
|
4403
|
+
});
|
|
4404
|
+
const cacheControlValidator = new CacheControlValidator(config.cacheControlProviderOptionsName, thread != null && anthropicOptions?.cacheControl != null ? 1 : 0);
|
|
4405
|
+
const defaultEagerInputStreaming = stream && (anthropicOptions?.toolStreaming ?? true);
|
|
4406
|
+
const inlineTools = await getInlineToolsFromPrompt(prompt);
|
|
4187
4407
|
const toolNameMapping = createToolNameMapping({
|
|
4188
|
-
tools,
|
|
4408
|
+
tools: [...inlineTools, ...tools ?? []],
|
|
4189
4409
|
providerToolNames: {
|
|
4190
4410
|
"anthropic.code_execution_20250522": "code_execution",
|
|
4191
4411
|
"anthropic.code_execution_20250825": "code_execution",
|
|
@@ -4220,8 +4440,35 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4220
4440
|
cacheControlValidator,
|
|
4221
4441
|
toolNameMapping,
|
|
4222
4442
|
toolsetNames,
|
|
4223
|
-
convertMediaPart: config.convertMediaPart
|
|
4443
|
+
convertMediaPart: config.convertMediaPart,
|
|
4444
|
+
convertInlineTool: async (tool) => {
|
|
4445
|
+
const { tools: definitions, toolWarnings, betas } = await prepareTools({
|
|
4446
|
+
tools: [tool],
|
|
4447
|
+
toolChoice: void 0,
|
|
4448
|
+
cacheControlValidator,
|
|
4449
|
+
supportsStructuredOutput,
|
|
4450
|
+
supportsStrictTools
|
|
4451
|
+
});
|
|
4452
|
+
return {
|
|
4453
|
+
definition: definitions?.[0],
|
|
4454
|
+
warnings: toolWarnings,
|
|
4455
|
+
betas
|
|
4456
|
+
};
|
|
4457
|
+
}
|
|
4224
4458
|
});
|
|
4459
|
+
if (thread != null) {
|
|
4460
|
+
const unpinnedBetas = [...betas].filter((beta) => !userSuppliedBetas.has(beta) && !anthropicOptions?.anthropicBeta?.includes(beta));
|
|
4461
|
+
if (unpinnedBetas.length > 0) warnings.push({
|
|
4462
|
+
type: "compatibility",
|
|
4463
|
+
feature: "providerOptions.anthropic.thread",
|
|
4464
|
+
details: `Message content enabled beta headers: ${unpinnedBetas.join(", ")}. Thread requests require the same beta set on every turn. Pin these values with anthropicBeta on every request, or start a new thread when the set changes.`
|
|
4465
|
+
});
|
|
4466
|
+
if (thread.type === "continue" && (messagesPrompt.system != null || (tools?.length ?? 0) > 0)) warnings.push({
|
|
4467
|
+
type: "compatibility",
|
|
4468
|
+
feature: "providerOptions.anthropic.thread",
|
|
4469
|
+
details: "Continuation uses the system prompt and tool definitions stored by the create request; supplied definitions are omitted from the wire request. Supply identical tools for local tool handling and fixed request settings. To change system instructions or tools, start a new thread."
|
|
4470
|
+
});
|
|
4471
|
+
}
|
|
4225
4472
|
if (isCustomReasoning(reasoning) && anthropicOptions?.effort == null) {
|
|
4226
4473
|
const reasoningConfig = resolveAnthropicReasoningConfig({
|
|
4227
4474
|
reasoning,
|
|
@@ -4339,7 +4586,11 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4339
4586
|
version: skill.version
|
|
4340
4587
|
}))
|
|
4341
4588
|
} : anthropicOptions.container.id },
|
|
4342
|
-
system: messagesPrompt.system,
|
|
4589
|
+
system: thread?.type === "continue" ? void 0 : messagesPrompt.system,
|
|
4590
|
+
...thread != null && { thread: thread.type === "create" ? { type: "create" } : {
|
|
4591
|
+
type: "continue",
|
|
4592
|
+
previous_message_id: thread.previousMessageId
|
|
4593
|
+
} },
|
|
4343
4594
|
messages: messagesPrompt.messages,
|
|
4344
4595
|
...anthropicOptions?.safeguards && anthropicOptions.safeguards.length > 0 && { safeguards: anthropicOptions.safeguards.map((safeguard) => ({
|
|
4345
4596
|
type: safeguard.type,
|
|
@@ -4455,7 +4706,6 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4455
4706
|
if (thinkingBlockBinding != null) betas.add("thinking-binding-controls-2026-08-01");
|
|
4456
4707
|
if (anthropicOptions?.fallbacks === "default") betas.add("server-side-fallback-2026-07-01");
|
|
4457
4708
|
else if (anthropicOptions?.fallbacks && anthropicOptions.fallbacks.length > 0) betas.add("server-side-fallback-2026-06-01");
|
|
4458
|
-
const defaultEagerInputStreaming = stream && (anthropicOptions?.toolStreaming ?? true);
|
|
4459
4709
|
const { tools: anthropicTools, toolChoice: anthropicToolChoice, toolWarnings, betas: toolsBetas } = await prepareTools(jsonResponseTool != null ? {
|
|
4460
4710
|
tools: [...(tools ?? []).filter((tool) => toolChoice?.type !== "none" && (toolChoice?.type !== "tool" || tool.name === toolChoice.toolName)), jsonResponseTool],
|
|
4461
4711
|
toolChoice: { type: "required" },
|
|
@@ -4468,6 +4718,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4468
4718
|
} : {
|
|
4469
4719
|
tools: tools ?? [],
|
|
4470
4720
|
toolChoice,
|
|
4721
|
+
hasInlineTools: inlineTools.length > 0,
|
|
4471
4722
|
disableParallelToolUse: anthropicOptions?.disableParallelToolUse,
|
|
4472
4723
|
cacheControlValidator,
|
|
4473
4724
|
supportsStructuredOutput,
|
|
@@ -4479,7 +4730,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4479
4730
|
return {
|
|
4480
4731
|
args: {
|
|
4481
4732
|
...baseArgs,
|
|
4482
|
-
tools: anthropicTools,
|
|
4733
|
+
tools: thread?.type === "continue" ? void 0 : anthropicTools,
|
|
4483
4734
|
tool_choice: anthropicToolChoice,
|
|
4484
4735
|
stream: stream === true ? true : void 0
|
|
4485
4736
|
},
|
|
@@ -4489,12 +4740,15 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4489
4740
|
...cacheWarnings
|
|
4490
4741
|
],
|
|
4491
4742
|
betas: /* @__PURE__ */ new Set([
|
|
4743
|
+
...thread != null ? ["message-threads-2026-08-12"] : [],
|
|
4492
4744
|
...betas,
|
|
4493
4745
|
...toolsBetas,
|
|
4494
4746
|
...userSuppliedBetas,
|
|
4495
4747
|
...anthropicOptions?.anthropicBeta ?? []
|
|
4496
4748
|
]),
|
|
4749
|
+
markCodeExecutionDynamic: hasDynamicFilteringWebToolWithoutCodeExecution(anthropicTools),
|
|
4497
4750
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
4751
|
+
includePings: stream === true && anthropicOptions?.includePings === true,
|
|
4498
4752
|
toolNameMapping,
|
|
4499
4753
|
providerOptionsName,
|
|
4500
4754
|
usedCustomProviderKey
|
|
@@ -4539,13 +4793,12 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4539
4793
|
}
|
|
4540
4794
|
async doGenerate(options) {
|
|
4541
4795
|
const configHeaders = this.config.headers ? await resolve(this.config.headers) : void 0;
|
|
4542
|
-
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping, providerOptionsName, usedCustomProviderKey } = await this.getArgs({
|
|
4796
|
+
const { args, warnings, betas, usesJsonResponseTool, markCodeExecutionDynamic, toolNameMapping, providerOptionsName, usedCustomProviderKey } = await this.getArgs({
|
|
4543
4797
|
...options,
|
|
4544
4798
|
stream: false,
|
|
4545
4799
|
userSuppliedBetas: this.getBetasFromHeaders(configHeaders, options.headers)
|
|
4546
4800
|
});
|
|
4547
4801
|
const citationDocuments = [...this.extractCitationDocuments(options.prompt)];
|
|
4548
|
-
const markCodeExecutionDynamic = hasDynamicFilteringWebToolWithoutCodeExecution(args.tools);
|
|
4549
4802
|
const { responseHeaders, value: response, rawValue: rawResponse } = await postJsonToApi({
|
|
4550
4803
|
url: this.buildRequestUrl(false),
|
|
4551
4804
|
headers: await this.getHeaders({
|
|
@@ -4928,9 +5181,11 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4928
5181
|
warnings,
|
|
4929
5182
|
providerMetadata: (() => {
|
|
4930
5183
|
const stopDetails = mapAnthropicStopDetails(response.stop_details);
|
|
5184
|
+
const serviceTier = response.usage.service_tier ?? response.service_tier;
|
|
4931
5185
|
const anthropicMetadata = {
|
|
4932
5186
|
usage: response.usage,
|
|
4933
5187
|
stopSequence: response.stop_sequence ?? null,
|
|
5188
|
+
...serviceTier != null ? { serviceTier } : {},
|
|
4934
5189
|
...stopDetails != null ? { stopDetails } : {},
|
|
4935
5190
|
...response.input_transformations != null ? { inputTransformations: response.input_transformations } : {},
|
|
4936
5191
|
...response.safeguard_results != null ? { safeguardResults: response.safeguard_results } : {},
|
|
@@ -4962,13 +5217,12 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
4962
5217
|
async doStream(options) {
|
|
4963
5218
|
"use step";
|
|
4964
5219
|
const configHeaders = this.config.headers ? await resolve(this.config.headers) : void 0;
|
|
4965
|
-
const { args: body, warnings, betas, usesJsonResponseTool, toolNameMapping, providerOptionsName, usedCustomProviderKey } = await this.getArgs({
|
|
5220
|
+
const { args: body, warnings, betas, usesJsonResponseTool, markCodeExecutionDynamic, includePings, toolNameMapping, providerOptionsName, usedCustomProviderKey } = await this.getArgs({
|
|
4966
5221
|
...options,
|
|
4967
5222
|
stream: true,
|
|
4968
5223
|
userSuppliedBetas: this.getBetasFromHeaders(configHeaders, options.headers)
|
|
4969
5224
|
});
|
|
4970
5225
|
const citationDocuments = [...this.extractCitationDocuments(options.prompt)];
|
|
4971
|
-
const markCodeExecutionDynamic = hasDynamicFilteringWebToolWithoutCodeExecution(body.tools);
|
|
4972
5226
|
const url = this.buildRequestUrl(true);
|
|
4973
5227
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
4974
5228
|
url,
|
|
@@ -5001,6 +5255,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5001
5255
|
let contextManagement = null;
|
|
5002
5256
|
let rawUsage = void 0;
|
|
5003
5257
|
let stopSequence = null;
|
|
5258
|
+
let serviceTier = null;
|
|
5004
5259
|
let stopDetails = void 0;
|
|
5005
5260
|
let inputTransformations;
|
|
5006
5261
|
let safeguardResults;
|
|
@@ -5045,7 +5300,9 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5045
5300
|
}
|
|
5046
5301
|
const value = chunk.value;
|
|
5047
5302
|
switch (value.type) {
|
|
5048
|
-
case "ping":
|
|
5303
|
+
case "ping":
|
|
5304
|
+
if (includePings) controller.enqueue({ type: "ping" });
|
|
5305
|
+
return;
|
|
5049
5306
|
case "content_block_start": {
|
|
5050
5307
|
const part = value.content_block;
|
|
5051
5308
|
const contentBlockType = part.type;
|
|
@@ -5609,6 +5866,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5609
5866
|
});
|
|
5610
5867
|
return;
|
|
5611
5868
|
}
|
|
5869
|
+
serviceTier = value.message.usage.service_tier ?? value.message.service_tier ?? null;
|
|
5612
5870
|
isMessageOpen = true;
|
|
5613
5871
|
activeMessageId = value.message.id;
|
|
5614
5872
|
heldBackTextByIndex.clear();
|
|
@@ -5700,6 +5958,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5700
5958
|
if (value.context_management) contextManagement = mapAnthropicResponseContextManagement(value.context_management);
|
|
5701
5959
|
if (value.input_transformations != null) inputTransformations = value.input_transformations;
|
|
5702
5960
|
if (value.delta.safeguard_results != null) safeguardResults = value.delta.safeguard_results;
|
|
5961
|
+
serviceTier = value.usage.service_tier ?? serviceTier;
|
|
5703
5962
|
rawUsage = {
|
|
5704
5963
|
...rawUsage,
|
|
5705
5964
|
...value.usage
|
|
@@ -5711,6 +5970,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5711
5970
|
const anthropicMetadata = {
|
|
5712
5971
|
usage: rawUsage ?? null,
|
|
5713
5972
|
stopSequence,
|
|
5973
|
+
...serviceTier != null ? { serviceTier } : {},
|
|
5714
5974
|
...stopDetails != null ? { stopDetails } : {},
|
|
5715
5975
|
...inputTransformations != null ? { inputTransformations } : {},
|
|
5716
5976
|
...safeguardResults != null ? { safeguardResults } : {},
|
|
@@ -5820,7 +6080,7 @@ var AnthropicLanguageModel = class AnthropicLanguageModel {
|
|
|
5820
6080
|
try {
|
|
5821
6081
|
await firstChunkReader.read();
|
|
5822
6082
|
let result = await firstChunkReader.read();
|
|
5823
|
-
|
|
6083
|
+
while (result.value?.type === "raw" || result.value?.type === "ping") result = await firstChunkReader.read();
|
|
5824
6084
|
if (result.value?.type === "error") {
|
|
5825
6085
|
const error = result.value.error;
|
|
5826
6086
|
if (!isProviderStreamError(error)) throw new Error("Expected a normalized Anthropic stream error");
|
|
@@ -6617,6 +6877,6 @@ var AnthropicSkills = class {
|
|
|
6617
6877
|
}
|
|
6618
6878
|
};
|
|
6619
6879
|
//#endregion
|
|
6620
|
-
export { AnthropicFiles, AnthropicLanguageModel, AnthropicLanguageModel as AnthropicMessagesLanguageModel, AnthropicSkills, anthropicTools, getAnthropicModelCapabilities as getModelCapabilities, prepareTools, sanitizeJsonSchema, supportsNativeStructuredOutputSchema };
|
|
6880
|
+
export { AnthropicFiles, AnthropicLanguageModel, AnthropicLanguageModel as AnthropicMessagesLanguageModel, AnthropicSkills, anthropicModelCatalog, anthropicProviderOptions, anthropicTools, getAnthropicLanguageModelEntry, getAnthropicModelCapabilities as getModelCapabilities, prepareTools, sanitizeJsonSchema, supportsNativeStructuredOutputSchema };
|
|
6621
6881
|
|
|
6622
6882
|
//# sourceMappingURL=index.js.map
|