@ai-sdk/anthropic 1.2.12 → 2.0.0-alpha.10
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 +244 -24
- package/dist/index.d.mts +101 -30
- package/dist/index.d.ts +101 -30
- package/dist/index.js +629 -347
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +634 -349
- package/dist/index.mjs.map +1 -1
- package/{internal/dist → dist/internal}/index.d.mts +12 -37
- package/{internal/dist → dist/internal}/index.d.ts +12 -37
- package/{internal/dist → dist/internal}/index.js +611 -338
- package/dist/internal/index.js.map +1 -0
- package/{internal/dist → dist/internal}/index.mjs +615 -340
- package/dist/internal/index.mjs.map +1 -0
- package/internal.d.ts +1 -0
- package/package.json +18 -16
- package/internal/dist/index.js.map +0 -1
- package/internal/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
|
32
32
|
// src/anthropic-messages-language-model.ts
|
|
33
33
|
var import_provider3 = require("@ai-sdk/provider");
|
|
34
34
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
35
|
-
var
|
|
35
|
+
var import_zod3 = require("zod");
|
|
36
36
|
|
|
37
37
|
// src/anthropic-error.ts
|
|
38
38
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
@@ -49,18 +49,74 @@ var anthropicFailedResponseHandler = (0, import_provider_utils.createJsonErrorRe
|
|
|
49
49
|
errorToMessage: (data) => data.error.message
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
+
// src/anthropic-messages-options.ts
|
|
53
|
+
var import_zod2 = require("zod");
|
|
54
|
+
var webSearchLocationSchema = import_zod2.z.object({
|
|
55
|
+
type: import_zod2.z.literal("approximate"),
|
|
56
|
+
city: import_zod2.z.string().optional(),
|
|
57
|
+
region: import_zod2.z.string().optional(),
|
|
58
|
+
country: import_zod2.z.string(),
|
|
59
|
+
timezone: import_zod2.z.string().optional()
|
|
60
|
+
});
|
|
61
|
+
var anthropicProviderOptions = import_zod2.z.object({
|
|
62
|
+
/**
|
|
63
|
+
Include reasoning content in requests sent to the model. Defaults to `true`.
|
|
64
|
+
|
|
65
|
+
If you are experiencing issues with the model handling requests involving
|
|
66
|
+
*/
|
|
67
|
+
sendReasoning: import_zod2.z.boolean().optional(),
|
|
68
|
+
thinking: import_zod2.z.object({
|
|
69
|
+
type: import_zod2.z.union([import_zod2.z.literal("enabled"), import_zod2.z.literal("disabled")]),
|
|
70
|
+
budgetTokens: import_zod2.z.number().optional()
|
|
71
|
+
}).optional(),
|
|
72
|
+
/**
|
|
73
|
+
* Web search tool configuration for Claude models that support it.
|
|
74
|
+
* When provided, automatically adds the web search tool to the request.
|
|
75
|
+
*/
|
|
76
|
+
webSearch: import_zod2.z.object({
|
|
77
|
+
/**
|
|
78
|
+
* Limit the number of searches per request (optional)
|
|
79
|
+
* Defaults to 5 if not specified
|
|
80
|
+
*/
|
|
81
|
+
maxUses: import_zod2.z.number().min(1).max(20).optional(),
|
|
82
|
+
/**
|
|
83
|
+
* Only include results from these domains (optional)
|
|
84
|
+
* Cannot be used with blockedDomains
|
|
85
|
+
*/
|
|
86
|
+
allowedDomains: import_zod2.z.array(import_zod2.z.string()).optional(),
|
|
87
|
+
/**
|
|
88
|
+
* Never include results from these domains (optional)
|
|
89
|
+
* Cannot be used with allowedDomains
|
|
90
|
+
*/
|
|
91
|
+
blockedDomains: import_zod2.z.array(import_zod2.z.string()).optional(),
|
|
92
|
+
/**
|
|
93
|
+
* Localize search results based on user location (optional)
|
|
94
|
+
*/
|
|
95
|
+
userLocation: webSearchLocationSchema.optional()
|
|
96
|
+
}).optional()
|
|
97
|
+
});
|
|
98
|
+
|
|
52
99
|
// src/anthropic-prepare-tools.ts
|
|
53
100
|
var import_provider = require("@ai-sdk/provider");
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
|
|
101
|
+
function isWebSearchTool(tool) {
|
|
102
|
+
return typeof tool === "object" && tool !== null && "type" in tool && tool.type === "web_search_20250305";
|
|
103
|
+
}
|
|
104
|
+
function prepareTools({
|
|
105
|
+
tools,
|
|
106
|
+
toolChoice
|
|
107
|
+
}) {
|
|
108
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
57
109
|
const toolWarnings = [];
|
|
58
110
|
const betas = /* @__PURE__ */ new Set();
|
|
59
111
|
if (tools == null) {
|
|
60
|
-
return { tools: void 0,
|
|
112
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
|
|
61
113
|
}
|
|
62
114
|
const anthropicTools2 = [];
|
|
63
115
|
for (const tool of tools) {
|
|
116
|
+
if (isWebSearchTool(tool)) {
|
|
117
|
+
anthropicTools2.push(tool);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
64
120
|
switch (tool.type) {
|
|
65
121
|
case "function":
|
|
66
122
|
anthropicTools2.push({
|
|
@@ -129,11 +185,10 @@ function prepareTools(mode) {
|
|
|
129
185
|
break;
|
|
130
186
|
}
|
|
131
187
|
}
|
|
132
|
-
const toolChoice = mode.toolChoice;
|
|
133
188
|
if (toolChoice == null) {
|
|
134
189
|
return {
|
|
135
190
|
tools: anthropicTools2,
|
|
136
|
-
|
|
191
|
+
toolChoice: void 0,
|
|
137
192
|
toolWarnings,
|
|
138
193
|
betas
|
|
139
194
|
};
|
|
@@ -143,30 +198,30 @@ function prepareTools(mode) {
|
|
|
143
198
|
case "auto":
|
|
144
199
|
return {
|
|
145
200
|
tools: anthropicTools2,
|
|
146
|
-
|
|
201
|
+
toolChoice: { type: "auto" },
|
|
147
202
|
toolWarnings,
|
|
148
203
|
betas
|
|
149
204
|
};
|
|
150
205
|
case "required":
|
|
151
206
|
return {
|
|
152
207
|
tools: anthropicTools2,
|
|
153
|
-
|
|
208
|
+
toolChoice: { type: "any" },
|
|
154
209
|
toolWarnings,
|
|
155
210
|
betas
|
|
156
211
|
};
|
|
157
212
|
case "none":
|
|
158
|
-
return { tools: void 0,
|
|
213
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
|
|
159
214
|
case "tool":
|
|
160
215
|
return {
|
|
161
216
|
tools: anthropicTools2,
|
|
162
|
-
|
|
217
|
+
toolChoice: { type: "tool", name: toolChoice.toolName },
|
|
163
218
|
toolWarnings,
|
|
164
219
|
betas
|
|
165
220
|
};
|
|
166
221
|
default: {
|
|
167
222
|
const _exhaustiveCheck = type;
|
|
168
223
|
throw new import_provider.UnsupportedFunctionalityError({
|
|
169
|
-
functionality: `
|
|
224
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
170
225
|
});
|
|
171
226
|
}
|
|
172
227
|
}
|
|
@@ -175,12 +230,12 @@ function prepareTools(mode) {
|
|
|
175
230
|
// src/convert-to-anthropic-messages-prompt.ts
|
|
176
231
|
var import_provider2 = require("@ai-sdk/provider");
|
|
177
232
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
178
|
-
function convertToAnthropicMessagesPrompt({
|
|
233
|
+
async function convertToAnthropicMessagesPrompt({
|
|
179
234
|
prompt,
|
|
180
235
|
sendReasoning,
|
|
181
236
|
warnings
|
|
182
237
|
}) {
|
|
183
|
-
var _a, _b, _c
|
|
238
|
+
var _a, _b, _c;
|
|
184
239
|
const betas = /* @__PURE__ */ new Set();
|
|
185
240
|
const blocks = groupIntoBlocks(prompt);
|
|
186
241
|
let system = void 0;
|
|
@@ -202,10 +257,10 @@ function convertToAnthropicMessagesPrompt({
|
|
|
202
257
|
functionality: "Multiple system messages that are separated by user/assistant messages"
|
|
203
258
|
});
|
|
204
259
|
}
|
|
205
|
-
system = block.messages.map(({ content,
|
|
260
|
+
system = block.messages.map(({ content, providerOptions }) => ({
|
|
206
261
|
type: "text",
|
|
207
262
|
text: content,
|
|
208
|
-
cache_control: getCacheControl(
|
|
263
|
+
cache_control: getCacheControl(providerOptions)
|
|
209
264
|
}));
|
|
210
265
|
break;
|
|
211
266
|
}
|
|
@@ -218,7 +273,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
218
273
|
for (let j = 0; j < content.length; j++) {
|
|
219
274
|
const part = content[j];
|
|
220
275
|
const isLastPart = j === content.length - 1;
|
|
221
|
-
const cacheControl = (_a = getCacheControl(part.
|
|
276
|
+
const cacheControl = (_a = getCacheControl(part.providerOptions)) != null ? _a : isLastPart ? getCacheControl(message.providerOptions) : void 0;
|
|
222
277
|
switch (part.type) {
|
|
223
278
|
case "text": {
|
|
224
279
|
anthropicContent.push({
|
|
@@ -228,40 +283,39 @@ function convertToAnthropicMessagesPrompt({
|
|
|
228
283
|
});
|
|
229
284
|
break;
|
|
230
285
|
}
|
|
231
|
-
case "image": {
|
|
232
|
-
anthropicContent.push({
|
|
233
|
-
type: "image",
|
|
234
|
-
source: part.image instanceof URL ? {
|
|
235
|
-
type: "url",
|
|
236
|
-
url: part.image.toString()
|
|
237
|
-
} : {
|
|
238
|
-
type: "base64",
|
|
239
|
-
media_type: (_b = part.mimeType) != null ? _b : "image/jpeg",
|
|
240
|
-
data: (0, import_provider_utils2.convertUint8ArrayToBase64)(part.image)
|
|
241
|
-
},
|
|
242
|
-
cache_control: cacheControl
|
|
243
|
-
});
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
286
|
case "file": {
|
|
247
|
-
if (part.
|
|
287
|
+
if (part.mediaType.startsWith("image/")) {
|
|
288
|
+
anthropicContent.push({
|
|
289
|
+
type: "image",
|
|
290
|
+
source: part.data instanceof URL ? {
|
|
291
|
+
type: "url",
|
|
292
|
+
url: part.data.toString()
|
|
293
|
+
} : {
|
|
294
|
+
type: "base64",
|
|
295
|
+
media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
|
|
296
|
+
data: (0, import_provider_utils2.convertToBase64)(part.data)
|
|
297
|
+
},
|
|
298
|
+
cache_control: cacheControl
|
|
299
|
+
});
|
|
300
|
+
} else if (part.mediaType === "application/pdf") {
|
|
301
|
+
betas.add("pdfs-2024-09-25");
|
|
302
|
+
anthropicContent.push({
|
|
303
|
+
type: "document",
|
|
304
|
+
source: part.data instanceof URL ? {
|
|
305
|
+
type: "url",
|
|
306
|
+
url: part.data.toString()
|
|
307
|
+
} : {
|
|
308
|
+
type: "base64",
|
|
309
|
+
media_type: "application/pdf",
|
|
310
|
+
data: (0, import_provider_utils2.convertToBase64)(part.data)
|
|
311
|
+
},
|
|
312
|
+
cache_control: cacheControl
|
|
313
|
+
});
|
|
314
|
+
} else {
|
|
248
315
|
throw new import_provider2.UnsupportedFunctionalityError({
|
|
249
|
-
functionality:
|
|
316
|
+
functionality: `media type: ${part.mediaType}`
|
|
250
317
|
});
|
|
251
318
|
}
|
|
252
|
-
betas.add("pdfs-2024-09-25");
|
|
253
|
-
anthropicContent.push({
|
|
254
|
-
type: "document",
|
|
255
|
-
source: part.data instanceof URL ? {
|
|
256
|
-
type: "url",
|
|
257
|
-
url: part.data.toString()
|
|
258
|
-
} : {
|
|
259
|
-
type: "base64",
|
|
260
|
-
media_type: "application/pdf",
|
|
261
|
-
data: part.data
|
|
262
|
-
},
|
|
263
|
-
cache_control: cacheControl
|
|
264
|
-
});
|
|
265
319
|
break;
|
|
266
320
|
}
|
|
267
321
|
}
|
|
@@ -272,7 +326,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
272
326
|
for (let i2 = 0; i2 < content.length; i2++) {
|
|
273
327
|
const part = content[i2];
|
|
274
328
|
const isLastPart = i2 === content.length - 1;
|
|
275
|
-
const cacheControl = (
|
|
329
|
+
const cacheControl = (_b = getCacheControl(part.providerOptions)) != null ? _b : isLastPart ? getCacheControl(message.providerOptions) : void 0;
|
|
276
330
|
const toolResultContent = part.content != null ? part.content.map((part2) => {
|
|
277
331
|
var _a2;
|
|
278
332
|
switch (part2.type) {
|
|
@@ -287,7 +341,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
287
341
|
type: "image",
|
|
288
342
|
source: {
|
|
289
343
|
type: "base64",
|
|
290
|
-
media_type: (_a2 = part2.
|
|
344
|
+
media_type: (_a2 = part2.mediaType) != null ? _a2 : "image/jpeg",
|
|
291
345
|
data: part2.data
|
|
292
346
|
},
|
|
293
347
|
cache_control: void 0
|
|
@@ -322,7 +376,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
322
376
|
for (let k = 0; k < content.length; k++) {
|
|
323
377
|
const part = content[k];
|
|
324
378
|
const isLastContentPart = k === content.length - 1;
|
|
325
|
-
const cacheControl = (
|
|
379
|
+
const cacheControl = (_c = getCacheControl(part.providerOptions)) != null ? _c : isLastContentPart ? getCacheControl(message.providerOptions) : void 0;
|
|
326
380
|
switch (part.type) {
|
|
327
381
|
case "text": {
|
|
328
382
|
anthropicContent.push({
|
|
@@ -339,12 +393,37 @@ function convertToAnthropicMessagesPrompt({
|
|
|
339
393
|
}
|
|
340
394
|
case "reasoning": {
|
|
341
395
|
if (sendReasoning) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
cache_control: cacheControl
|
|
396
|
+
const reasoningMetadata = await (0, import_provider_utils2.parseProviderOptions)({
|
|
397
|
+
provider: "anthropic",
|
|
398
|
+
providerOptions: part.providerOptions,
|
|
399
|
+
schema: anthropicReasoningMetadataSchema
|
|
347
400
|
});
|
|
401
|
+
if (reasoningMetadata != null) {
|
|
402
|
+
if (reasoningMetadata.signature != null) {
|
|
403
|
+
anthropicContent.push({
|
|
404
|
+
type: "thinking",
|
|
405
|
+
thinking: part.text,
|
|
406
|
+
signature: reasoningMetadata.signature,
|
|
407
|
+
cache_control: cacheControl
|
|
408
|
+
});
|
|
409
|
+
} else if (reasoningMetadata.redactedData != null) {
|
|
410
|
+
anthropicContent.push({
|
|
411
|
+
type: "redacted_thinking",
|
|
412
|
+
data: reasoningMetadata.redactedData,
|
|
413
|
+
cache_control: cacheControl
|
|
414
|
+
});
|
|
415
|
+
} else {
|
|
416
|
+
warnings.push({
|
|
417
|
+
type: "other",
|
|
418
|
+
message: "unsupported reasoning metadata"
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
} else {
|
|
422
|
+
warnings.push({
|
|
423
|
+
type: "other",
|
|
424
|
+
message: "unsupported reasoning metadata"
|
|
425
|
+
});
|
|
426
|
+
}
|
|
348
427
|
} else {
|
|
349
428
|
warnings.push({
|
|
350
429
|
type: "other",
|
|
@@ -353,14 +432,6 @@ function convertToAnthropicMessagesPrompt({
|
|
|
353
432
|
}
|
|
354
433
|
break;
|
|
355
434
|
}
|
|
356
|
-
case "redacted-reasoning": {
|
|
357
|
-
anthropicContent.push({
|
|
358
|
-
type: "redacted_thinking",
|
|
359
|
-
data: part.data,
|
|
360
|
-
cache_control: cacheControl
|
|
361
|
-
});
|
|
362
|
-
break;
|
|
363
|
-
}
|
|
364
435
|
case "tool-call": {
|
|
365
436
|
anthropicContent.push({
|
|
366
437
|
type: "tool_use",
|
|
@@ -379,7 +450,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
379
450
|
}
|
|
380
451
|
default: {
|
|
381
452
|
const _exhaustiveCheck = type;
|
|
382
|
-
throw new Error(`
|
|
453
|
+
throw new Error(`content type: ${_exhaustiveCheck}`);
|
|
383
454
|
}
|
|
384
455
|
}
|
|
385
456
|
}
|
|
@@ -436,13 +507,16 @@ function groupIntoBlocks(prompt) {
|
|
|
436
507
|
}
|
|
437
508
|
|
|
438
509
|
// src/map-anthropic-stop-reason.ts
|
|
439
|
-
function mapAnthropicStopReason(
|
|
510
|
+
function mapAnthropicStopReason({
|
|
511
|
+
finishReason,
|
|
512
|
+
isJsonResponseFromTool
|
|
513
|
+
}) {
|
|
440
514
|
switch (finishReason) {
|
|
441
515
|
case "end_turn":
|
|
442
516
|
case "stop_sequence":
|
|
443
517
|
return "stop";
|
|
444
518
|
case "tool_use":
|
|
445
|
-
return "tool-calls";
|
|
519
|
+
return isJsonResponseFromTool ? "stop" : "tool-calls";
|
|
446
520
|
case "max_tokens":
|
|
447
521
|
return "length";
|
|
448
522
|
default:
|
|
@@ -452,12 +526,12 @@ function mapAnthropicStopReason(finishReason) {
|
|
|
452
526
|
|
|
453
527
|
// src/anthropic-messages-language-model.ts
|
|
454
528
|
var AnthropicMessagesLanguageModel = class {
|
|
455
|
-
constructor(modelId,
|
|
456
|
-
this.specificationVersion = "
|
|
457
|
-
|
|
529
|
+
constructor(modelId, config) {
|
|
530
|
+
this.specificationVersion = "v2";
|
|
531
|
+
var _a;
|
|
458
532
|
this.modelId = modelId;
|
|
459
|
-
this.settings = settings;
|
|
460
533
|
this.config = config;
|
|
534
|
+
this.generateId = (_a = config.generateId) != null ? _a : import_provider_utils3.generateId;
|
|
461
535
|
}
|
|
462
536
|
supportsUrl(url) {
|
|
463
537
|
return url.protocol === "https:";
|
|
@@ -465,13 +539,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
465
539
|
get provider() {
|
|
466
540
|
return this.config.provider;
|
|
467
541
|
}
|
|
468
|
-
get
|
|
469
|
-
|
|
542
|
+
get supportedUrls() {
|
|
543
|
+
var _a, _b, _c;
|
|
544
|
+
return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
|
|
470
545
|
}
|
|
471
546
|
async getArgs({
|
|
472
|
-
mode,
|
|
473
547
|
prompt,
|
|
474
|
-
|
|
548
|
+
maxOutputTokens = 4096,
|
|
475
549
|
// 4096: max model output tokens TODO update default in v5
|
|
476
550
|
temperature,
|
|
477
551
|
topP,
|
|
@@ -481,10 +555,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
481
555
|
stopSequences,
|
|
482
556
|
responseFormat,
|
|
483
557
|
seed,
|
|
484
|
-
|
|
558
|
+
tools,
|
|
559
|
+
toolChoice,
|
|
560
|
+
providerOptions
|
|
485
561
|
}) {
|
|
486
562
|
var _a, _b, _c;
|
|
487
|
-
const type = mode.type;
|
|
488
563
|
const warnings = [];
|
|
489
564
|
if (frequencyPenalty != null) {
|
|
490
565
|
warnings.push({
|
|
@@ -504,22 +579,36 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
504
579
|
setting: "seed"
|
|
505
580
|
});
|
|
506
581
|
}
|
|
507
|
-
if (responseFormat
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
582
|
+
if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
|
|
583
|
+
if (responseFormat.schema == null) {
|
|
584
|
+
warnings.push({
|
|
585
|
+
type: "unsupported-setting",
|
|
586
|
+
setting: "responseFormat",
|
|
587
|
+
details: "JSON response format requires a schema. The response format is ignored."
|
|
588
|
+
});
|
|
589
|
+
} else if (tools != null) {
|
|
590
|
+
warnings.push({
|
|
591
|
+
type: "unsupported-setting",
|
|
592
|
+
setting: "tools",
|
|
593
|
+
details: "JSON response format does not support tools. The provided tools are ignored."
|
|
594
|
+
});
|
|
595
|
+
}
|
|
513
596
|
}
|
|
514
|
-
const
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
597
|
+
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
|
|
598
|
+
type: "function",
|
|
599
|
+
name: "json",
|
|
600
|
+
description: "Respond with a JSON object.",
|
|
601
|
+
parameters: responseFormat.schema
|
|
602
|
+
} : void 0;
|
|
603
|
+
const anthropicOptions = await (0, import_provider_utils3.parseProviderOptions)({
|
|
520
604
|
provider: "anthropic",
|
|
521
605
|
providerOptions,
|
|
522
|
-
schema:
|
|
606
|
+
schema: anthropicProviderOptions
|
|
607
|
+
});
|
|
608
|
+
const { prompt: messagesPrompt, betas: messagesBetas } = await convertToAnthropicMessagesPrompt({
|
|
609
|
+
prompt,
|
|
610
|
+
sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
|
|
611
|
+
warnings
|
|
523
612
|
});
|
|
524
613
|
const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
|
|
525
614
|
const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
|
|
@@ -527,7 +616,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
527
616
|
// model id:
|
|
528
617
|
model: this.modelId,
|
|
529
618
|
// standardized settings:
|
|
530
|
-
max_tokens:
|
|
619
|
+
max_tokens: maxOutputTokens,
|
|
531
620
|
temperature,
|
|
532
621
|
top_k: topK,
|
|
533
622
|
top_p: topP,
|
|
@@ -570,44 +659,50 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
570
659
|
details: "topP is not supported when thinking is enabled"
|
|
571
660
|
});
|
|
572
661
|
}
|
|
573
|
-
baseArgs.max_tokens =
|
|
662
|
+
baseArgs.max_tokens = maxOutputTokens + thinkingBudget;
|
|
574
663
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
const { name, description, parameters } = mode.tool;
|
|
596
|
-
return {
|
|
597
|
-
args: {
|
|
598
|
-
...baseArgs,
|
|
599
|
-
tools: [{ name, description, input_schema: parameters }],
|
|
600
|
-
tool_choice: { type: "tool", name }
|
|
601
|
-
},
|
|
602
|
-
warnings,
|
|
603
|
-
betas: messagesBetas
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
default: {
|
|
607
|
-
const _exhaustiveCheck = type;
|
|
608
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
609
|
-
}
|
|
664
|
+
let modifiedTools = tools;
|
|
665
|
+
let modifiedToolChoice = toolChoice;
|
|
666
|
+
if (anthropicOptions == null ? void 0 : anthropicOptions.webSearch) {
|
|
667
|
+
const webSearchTool = {
|
|
668
|
+
type: "web_search_20250305",
|
|
669
|
+
name: "web_search",
|
|
670
|
+
max_uses: anthropicOptions.webSearch.maxUses,
|
|
671
|
+
allowed_domains: anthropicOptions.webSearch.allowedDomains,
|
|
672
|
+
blocked_domains: anthropicOptions.webSearch.blockedDomains,
|
|
673
|
+
...anthropicOptions.webSearch.userLocation && {
|
|
674
|
+
user_location: {
|
|
675
|
+
type: anthropicOptions.webSearch.userLocation.type,
|
|
676
|
+
country: anthropicOptions.webSearch.userLocation.country,
|
|
677
|
+
city: anthropicOptions.webSearch.userLocation.city,
|
|
678
|
+
region: anthropicOptions.webSearch.userLocation.region,
|
|
679
|
+
timezone: anthropicOptions.webSearch.userLocation.timezone
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
modifiedTools = tools ? [...tools, webSearchTool] : [webSearchTool];
|
|
610
684
|
}
|
|
685
|
+
const {
|
|
686
|
+
tools: anthropicTools2,
|
|
687
|
+
toolChoice: anthropicToolChoice,
|
|
688
|
+
toolWarnings,
|
|
689
|
+
betas: toolsBetas
|
|
690
|
+
} = prepareTools(
|
|
691
|
+
jsonResponseTool != null ? {
|
|
692
|
+
tools: [jsonResponseTool],
|
|
693
|
+
toolChoice: { type: "tool", toolName: jsonResponseTool.name }
|
|
694
|
+
} : { tools: modifiedTools, toolChoice: modifiedToolChoice }
|
|
695
|
+
);
|
|
696
|
+
return {
|
|
697
|
+
args: {
|
|
698
|
+
...baseArgs,
|
|
699
|
+
tools: anthropicTools2,
|
|
700
|
+
tool_choice: anthropicToolChoice
|
|
701
|
+
},
|
|
702
|
+
warnings: [...warnings, ...toolWarnings],
|
|
703
|
+
betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas]),
|
|
704
|
+
jsonResponseTool
|
|
705
|
+
};
|
|
611
706
|
}
|
|
612
707
|
async getHeaders({
|
|
613
708
|
betas,
|
|
@@ -628,8 +723,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
628
723
|
return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args)) != null ? _c : args;
|
|
629
724
|
}
|
|
630
725
|
async doGenerate(options) {
|
|
631
|
-
var _a, _b, _c, _d;
|
|
632
|
-
const { args, warnings, betas } = await this.getArgs(options);
|
|
726
|
+
var _a, _b, _c, _d, _e;
|
|
727
|
+
const { args, warnings, betas, jsonResponseTool } = await this.getArgs(options);
|
|
633
728
|
const {
|
|
634
729
|
responseHeaders,
|
|
635
730
|
value: response,
|
|
@@ -645,69 +740,118 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
645
740
|
abortSignal: options.abortSignal,
|
|
646
741
|
fetch: this.config.fetch
|
|
647
742
|
});
|
|
648
|
-
const
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
743
|
+
const content = [];
|
|
744
|
+
for (const part of response.content) {
|
|
745
|
+
switch (part.type) {
|
|
746
|
+
case "text": {
|
|
747
|
+
if (jsonResponseTool == null) {
|
|
748
|
+
content.push({ type: "text", text: part.text });
|
|
749
|
+
}
|
|
750
|
+
break;
|
|
751
|
+
}
|
|
752
|
+
case "thinking": {
|
|
753
|
+
content.push({
|
|
754
|
+
type: "reasoning",
|
|
755
|
+
text: part.thinking,
|
|
756
|
+
providerMetadata: {
|
|
757
|
+
anthropic: {
|
|
758
|
+
signature: part.signature
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
break;
|
|
763
|
+
}
|
|
764
|
+
case "redacted_thinking": {
|
|
765
|
+
content.push({
|
|
766
|
+
type: "reasoning",
|
|
767
|
+
text: "",
|
|
768
|
+
providerMetadata: {
|
|
769
|
+
anthropic: {
|
|
770
|
+
redactedData: part.data
|
|
771
|
+
}
|
|
772
|
+
}
|
|
665
773
|
});
|
|
774
|
+
break;
|
|
775
|
+
}
|
|
776
|
+
case "tool_use": {
|
|
777
|
+
content.push(
|
|
778
|
+
// when a json response tool is used, the tool call becomes the text:
|
|
779
|
+
jsonResponseTool != null ? {
|
|
780
|
+
type: "text",
|
|
781
|
+
text: JSON.stringify(part.input)
|
|
782
|
+
} : {
|
|
783
|
+
type: "tool-call",
|
|
784
|
+
toolCallType: "function",
|
|
785
|
+
toolCallId: part.id,
|
|
786
|
+
toolName: part.name,
|
|
787
|
+
args: JSON.stringify(part.input)
|
|
788
|
+
}
|
|
789
|
+
);
|
|
790
|
+
break;
|
|
791
|
+
}
|
|
792
|
+
case "server_tool_use": {
|
|
793
|
+
continue;
|
|
794
|
+
}
|
|
795
|
+
case "web_search_tool_result": {
|
|
796
|
+
if (Array.isArray(part.content)) {
|
|
797
|
+
for (const result of part.content) {
|
|
798
|
+
if (result.type === "web_search_result") {
|
|
799
|
+
content.push({
|
|
800
|
+
type: "source",
|
|
801
|
+
sourceType: "url",
|
|
802
|
+
id: this.generateId(),
|
|
803
|
+
url: result.url,
|
|
804
|
+
title: result.title,
|
|
805
|
+
providerMetadata: {
|
|
806
|
+
anthropic: {
|
|
807
|
+
encryptedContent: result.encrypted_content,
|
|
808
|
+
pageAge: (_a = result.page_age) != null ? _a : null
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
} else if (part.content.type === "web_search_tool_result_error") {
|
|
815
|
+
throw new import_provider3.APICallError({
|
|
816
|
+
message: `Web search failed: ${part.content.error_code}`,
|
|
817
|
+
url: "web_search_api",
|
|
818
|
+
requestBodyValues: { tool_use_id: part.tool_use_id },
|
|
819
|
+
data: { error_code: part.content.error_code }
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
break;
|
|
666
823
|
}
|
|
667
824
|
}
|
|
668
825
|
}
|
|
669
|
-
const reasoning = response.content.filter(
|
|
670
|
-
(content) => content.type === "redacted_thinking" || content.type === "thinking"
|
|
671
|
-
).map(
|
|
672
|
-
(content) => content.type === "thinking" ? {
|
|
673
|
-
type: "text",
|
|
674
|
-
text: content.thinking,
|
|
675
|
-
signature: content.signature
|
|
676
|
-
} : {
|
|
677
|
-
type: "redacted",
|
|
678
|
-
data: content.data
|
|
679
|
-
}
|
|
680
|
-
);
|
|
681
826
|
return {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
827
|
+
content,
|
|
828
|
+
finishReason: mapAnthropicStopReason({
|
|
829
|
+
finishReason: response.stop_reason,
|
|
830
|
+
isJsonResponseFromTool: jsonResponseTool != null
|
|
831
|
+
}),
|
|
686
832
|
usage: {
|
|
687
|
-
|
|
688
|
-
|
|
833
|
+
inputTokens: response.usage.input_tokens,
|
|
834
|
+
outputTokens: response.usage.output_tokens,
|
|
835
|
+
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
836
|
+
cachedInputTokens: (_b = response.usage.cache_read_input_tokens) != null ? _b : void 0
|
|
689
837
|
},
|
|
690
|
-
|
|
691
|
-
|
|
838
|
+
request: { body: args },
|
|
839
|
+
response: {
|
|
840
|
+
id: (_c = response.id) != null ? _c : void 0,
|
|
841
|
+
modelId: (_d = response.model) != null ? _d : void 0,
|
|
692
842
|
headers: responseHeaders,
|
|
693
843
|
body: rawResponse
|
|
694
844
|
},
|
|
695
|
-
response: {
|
|
696
|
-
id: (_a = response.id) != null ? _a : void 0,
|
|
697
|
-
modelId: (_b = response.model) != null ? _b : void 0
|
|
698
|
-
},
|
|
699
845
|
warnings,
|
|
700
846
|
providerMetadata: {
|
|
701
847
|
anthropic: {
|
|
702
|
-
cacheCreationInputTokens: (
|
|
703
|
-
cacheReadInputTokens: (_d = response.usage.cache_read_input_tokens) != null ? _d : null
|
|
848
|
+
cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null
|
|
704
849
|
}
|
|
705
|
-
}
|
|
706
|
-
request: { body: JSON.stringify(args) }
|
|
850
|
+
}
|
|
707
851
|
};
|
|
708
852
|
}
|
|
709
853
|
async doStream(options) {
|
|
710
|
-
const { args, warnings, betas } = await this.getArgs(options);
|
|
854
|
+
const { args, warnings, betas, jsonResponseTool } = await this.getArgs(options);
|
|
711
855
|
const body = { ...args, stream: true };
|
|
712
856
|
const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
|
|
713
857
|
url: this.buildRequestUrl(true),
|
|
@@ -720,20 +864,25 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
720
864
|
abortSignal: options.abortSignal,
|
|
721
865
|
fetch: this.config.fetch
|
|
722
866
|
});
|
|
723
|
-
const { messages: rawPrompt, ...rawSettings } = args;
|
|
724
867
|
let finishReason = "unknown";
|
|
725
868
|
const usage = {
|
|
726
|
-
|
|
727
|
-
|
|
869
|
+
inputTokens: void 0,
|
|
870
|
+
outputTokens: void 0,
|
|
871
|
+
totalTokens: void 0
|
|
728
872
|
};
|
|
729
873
|
const toolCallContentBlocks = {};
|
|
730
874
|
let providerMetadata = void 0;
|
|
731
875
|
let blockType = void 0;
|
|
876
|
+
const config = this.config;
|
|
877
|
+
const generateId3 = this.generateId;
|
|
732
878
|
return {
|
|
733
879
|
stream: response.pipeThrough(
|
|
734
880
|
new TransformStream({
|
|
881
|
+
start(controller) {
|
|
882
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
883
|
+
},
|
|
735
884
|
transform(chunk, controller) {
|
|
736
|
-
var _a, _b, _c, _d;
|
|
885
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
737
886
|
if (!chunk.success) {
|
|
738
887
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
739
888
|
return;
|
|
@@ -753,9 +902,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
753
902
|
}
|
|
754
903
|
case "redacted_thinking": {
|
|
755
904
|
controller.enqueue({
|
|
756
|
-
type: "
|
|
757
|
-
|
|
905
|
+
type: "reasoning",
|
|
906
|
+
text: "",
|
|
907
|
+
providerMetadata: {
|
|
908
|
+
anthropic: {
|
|
909
|
+
redactedData: value.content_block.data
|
|
910
|
+
}
|
|
911
|
+
}
|
|
758
912
|
});
|
|
913
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
|
759
914
|
return;
|
|
760
915
|
}
|
|
761
916
|
case "tool_use": {
|
|
@@ -766,6 +921,40 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
766
921
|
};
|
|
767
922
|
return;
|
|
768
923
|
}
|
|
924
|
+
case "server_tool_use": {
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
case "web_search_tool_result": {
|
|
928
|
+
if (Array.isArray(value.content_block.content)) {
|
|
929
|
+
for (const result of value.content_block.content) {
|
|
930
|
+
if (result.type === "web_search_result") {
|
|
931
|
+
controller.enqueue({
|
|
932
|
+
type: "source",
|
|
933
|
+
sourceType: "url",
|
|
934
|
+
id: generateId3(),
|
|
935
|
+
url: result.url,
|
|
936
|
+
title: result.title,
|
|
937
|
+
providerMetadata: {
|
|
938
|
+
anthropic: {
|
|
939
|
+
encryptedContent: result.encrypted_content,
|
|
940
|
+
pageAge: (_a = result.page_age) != null ? _a : null
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
} else if (value.content_block.content.type === "web_search_tool_result_error") {
|
|
947
|
+
controller.enqueue({
|
|
948
|
+
type: "error",
|
|
949
|
+
error: {
|
|
950
|
+
type: "web-search-error",
|
|
951
|
+
message: `Web search failed: ${value.content_block.content.error_code}`,
|
|
952
|
+
code: value.content_block.content.error_code
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
769
958
|
default: {
|
|
770
959
|
const _exhaustiveCheck = contentBlockType;
|
|
771
960
|
throw new Error(
|
|
@@ -777,13 +966,15 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
777
966
|
case "content_block_stop": {
|
|
778
967
|
if (toolCallContentBlocks[value.index] != null) {
|
|
779
968
|
const contentBlock = toolCallContentBlocks[value.index];
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
969
|
+
if (jsonResponseTool == null) {
|
|
970
|
+
controller.enqueue({
|
|
971
|
+
type: "tool-call",
|
|
972
|
+
toolCallType: "function",
|
|
973
|
+
toolCallId: contentBlock.toolCallId,
|
|
974
|
+
toolName: contentBlock.toolName,
|
|
975
|
+
args: contentBlock.jsonText
|
|
976
|
+
});
|
|
977
|
+
}
|
|
787
978
|
delete toolCallContentBlocks[value.index];
|
|
788
979
|
}
|
|
789
980
|
blockType = void 0;
|
|
@@ -793,40 +984,60 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
793
984
|
const deltaType = value.delta.type;
|
|
794
985
|
switch (deltaType) {
|
|
795
986
|
case "text_delta": {
|
|
987
|
+
if (jsonResponseTool != null) {
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
796
990
|
controller.enqueue({
|
|
797
|
-
type: "text
|
|
798
|
-
|
|
991
|
+
type: "text",
|
|
992
|
+
text: value.delta.text
|
|
799
993
|
});
|
|
800
994
|
return;
|
|
801
995
|
}
|
|
802
996
|
case "thinking_delta": {
|
|
803
997
|
controller.enqueue({
|
|
804
998
|
type: "reasoning",
|
|
805
|
-
|
|
999
|
+
text: value.delta.thinking
|
|
806
1000
|
});
|
|
807
1001
|
return;
|
|
808
1002
|
}
|
|
809
1003
|
case "signature_delta": {
|
|
810
1004
|
if (blockType === "thinking") {
|
|
811
1005
|
controller.enqueue({
|
|
812
|
-
type: "reasoning
|
|
813
|
-
|
|
1006
|
+
type: "reasoning",
|
|
1007
|
+
text: "",
|
|
1008
|
+
providerMetadata: {
|
|
1009
|
+
anthropic: {
|
|
1010
|
+
signature: value.delta.signature
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
814
1013
|
});
|
|
1014
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
|
815
1015
|
}
|
|
816
1016
|
return;
|
|
817
1017
|
}
|
|
818
1018
|
case "input_json_delta": {
|
|
819
1019
|
const contentBlock = toolCallContentBlocks[value.index];
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
1020
|
+
if (!contentBlock) {
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
controller.enqueue(
|
|
1024
|
+
jsonResponseTool != null ? {
|
|
1025
|
+
type: "text",
|
|
1026
|
+
text: value.delta.partial_json
|
|
1027
|
+
} : {
|
|
1028
|
+
type: "tool-call-delta",
|
|
1029
|
+
toolCallType: "function",
|
|
1030
|
+
toolCallId: contentBlock.toolCallId,
|
|
1031
|
+
toolName: contentBlock.toolName,
|
|
1032
|
+
argsTextDelta: value.delta.partial_json
|
|
1033
|
+
}
|
|
1034
|
+
);
|
|
827
1035
|
contentBlock.jsonText += value.delta.partial_json;
|
|
828
1036
|
return;
|
|
829
1037
|
}
|
|
1038
|
+
case "citations_delta": {
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
830
1041
|
default: {
|
|
831
1042
|
const _exhaustiveCheck = deltaType;
|
|
832
1043
|
throw new Error(
|
|
@@ -836,24 +1047,27 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
836
1047
|
}
|
|
837
1048
|
}
|
|
838
1049
|
case "message_start": {
|
|
839
|
-
usage.
|
|
840
|
-
usage.
|
|
1050
|
+
usage.inputTokens = value.message.usage.input_tokens;
|
|
1051
|
+
usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
|
|
841
1052
|
providerMetadata = {
|
|
842
1053
|
anthropic: {
|
|
843
|
-
cacheCreationInputTokens: (
|
|
844
|
-
cacheReadInputTokens: (_b = value.message.usage.cache_read_input_tokens) != null ? _b : null
|
|
1054
|
+
cacheCreationInputTokens: (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null
|
|
845
1055
|
}
|
|
846
1056
|
};
|
|
847
1057
|
controller.enqueue({
|
|
848
1058
|
type: "response-metadata",
|
|
849
|
-
id: (
|
|
850
|
-
modelId: (
|
|
1059
|
+
id: (_d = value.message.id) != null ? _d : void 0,
|
|
1060
|
+
modelId: (_e = value.message.model) != null ? _e : void 0
|
|
851
1061
|
});
|
|
852
1062
|
return;
|
|
853
1063
|
}
|
|
854
1064
|
case "message_delta": {
|
|
855
|
-
usage.
|
|
856
|
-
|
|
1065
|
+
usage.outputTokens = value.usage.output_tokens;
|
|
1066
|
+
usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
|
|
1067
|
+
finishReason = mapAnthropicStopReason({
|
|
1068
|
+
finishReason: value.delta.stop_reason,
|
|
1069
|
+
isJsonResponseFromTool: jsonResponseTool != null
|
|
1070
|
+
});
|
|
857
1071
|
return;
|
|
858
1072
|
}
|
|
859
1073
|
case "message_stop": {
|
|
@@ -877,142 +1091,201 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
877
1091
|
}
|
|
878
1092
|
})
|
|
879
1093
|
),
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
warnings,
|
|
883
|
-
request: { body: JSON.stringify(body) }
|
|
1094
|
+
request: { body },
|
|
1095
|
+
response: { headers: responseHeaders }
|
|
884
1096
|
};
|
|
885
1097
|
}
|
|
886
1098
|
};
|
|
887
|
-
var anthropicMessagesResponseSchema =
|
|
888
|
-
type:
|
|
889
|
-
id:
|
|
890
|
-
model:
|
|
891
|
-
content:
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
type:
|
|
895
|
-
text:
|
|
1099
|
+
var anthropicMessagesResponseSchema = import_zod3.z.object({
|
|
1100
|
+
type: import_zod3.z.literal("message"),
|
|
1101
|
+
id: import_zod3.z.string().nullish(),
|
|
1102
|
+
model: import_zod3.z.string().nullish(),
|
|
1103
|
+
content: import_zod3.z.array(
|
|
1104
|
+
import_zod3.z.discriminatedUnion("type", [
|
|
1105
|
+
import_zod3.z.object({
|
|
1106
|
+
type: import_zod3.z.literal("text"),
|
|
1107
|
+
text: import_zod3.z.string()
|
|
1108
|
+
}),
|
|
1109
|
+
import_zod3.z.object({
|
|
1110
|
+
type: import_zod3.z.literal("thinking"),
|
|
1111
|
+
thinking: import_zod3.z.string(),
|
|
1112
|
+
signature: import_zod3.z.string()
|
|
896
1113
|
}),
|
|
897
|
-
|
|
898
|
-
type:
|
|
899
|
-
|
|
900
|
-
signature: import_zod2.z.string()
|
|
1114
|
+
import_zod3.z.object({
|
|
1115
|
+
type: import_zod3.z.literal("redacted_thinking"),
|
|
1116
|
+
data: import_zod3.z.string()
|
|
901
1117
|
}),
|
|
902
|
-
|
|
903
|
-
type:
|
|
904
|
-
|
|
1118
|
+
import_zod3.z.object({
|
|
1119
|
+
type: import_zod3.z.literal("tool_use"),
|
|
1120
|
+
id: import_zod3.z.string(),
|
|
1121
|
+
name: import_zod3.z.string(),
|
|
1122
|
+
input: import_zod3.z.unknown()
|
|
905
1123
|
}),
|
|
906
|
-
|
|
907
|
-
type:
|
|
908
|
-
id:
|
|
909
|
-
name:
|
|
910
|
-
input:
|
|
1124
|
+
import_zod3.z.object({
|
|
1125
|
+
type: import_zod3.z.literal("server_tool_use"),
|
|
1126
|
+
id: import_zod3.z.string(),
|
|
1127
|
+
name: import_zod3.z.string(),
|
|
1128
|
+
input: import_zod3.z.record(import_zod3.z.unknown()).nullish()
|
|
1129
|
+
}),
|
|
1130
|
+
import_zod3.z.object({
|
|
1131
|
+
type: import_zod3.z.literal("web_search_tool_result"),
|
|
1132
|
+
tool_use_id: import_zod3.z.string(),
|
|
1133
|
+
content: import_zod3.z.union([
|
|
1134
|
+
import_zod3.z.array(
|
|
1135
|
+
import_zod3.z.object({
|
|
1136
|
+
type: import_zod3.z.literal("web_search_result"),
|
|
1137
|
+
url: import_zod3.z.string(),
|
|
1138
|
+
title: import_zod3.z.string(),
|
|
1139
|
+
encrypted_content: import_zod3.z.string(),
|
|
1140
|
+
page_age: import_zod3.z.string().nullish()
|
|
1141
|
+
})
|
|
1142
|
+
),
|
|
1143
|
+
import_zod3.z.object({
|
|
1144
|
+
type: import_zod3.z.literal("web_search_tool_result_error"),
|
|
1145
|
+
error_code: import_zod3.z.string()
|
|
1146
|
+
})
|
|
1147
|
+
])
|
|
911
1148
|
})
|
|
912
1149
|
])
|
|
913
1150
|
),
|
|
914
|
-
stop_reason:
|
|
915
|
-
usage:
|
|
916
|
-
input_tokens:
|
|
917
|
-
output_tokens:
|
|
918
|
-
cache_creation_input_tokens:
|
|
919
|
-
cache_read_input_tokens:
|
|
1151
|
+
stop_reason: import_zod3.z.string().nullish(),
|
|
1152
|
+
usage: import_zod3.z.object({
|
|
1153
|
+
input_tokens: import_zod3.z.number(),
|
|
1154
|
+
output_tokens: import_zod3.z.number(),
|
|
1155
|
+
cache_creation_input_tokens: import_zod3.z.number().nullish(),
|
|
1156
|
+
cache_read_input_tokens: import_zod3.z.number().nullish(),
|
|
1157
|
+
server_tool_use: import_zod3.z.object({
|
|
1158
|
+
web_search_requests: import_zod3.z.number()
|
|
1159
|
+
}).nullish()
|
|
920
1160
|
})
|
|
921
1161
|
});
|
|
922
|
-
var anthropicMessagesChunkSchema =
|
|
923
|
-
|
|
924
|
-
type:
|
|
925
|
-
message:
|
|
926
|
-
id:
|
|
927
|
-
model:
|
|
928
|
-
usage:
|
|
929
|
-
input_tokens:
|
|
930
|
-
output_tokens:
|
|
931
|
-
cache_creation_input_tokens:
|
|
932
|
-
cache_read_input_tokens:
|
|
1162
|
+
var anthropicMessagesChunkSchema = import_zod3.z.discriminatedUnion("type", [
|
|
1163
|
+
import_zod3.z.object({
|
|
1164
|
+
type: import_zod3.z.literal("message_start"),
|
|
1165
|
+
message: import_zod3.z.object({
|
|
1166
|
+
id: import_zod3.z.string().nullish(),
|
|
1167
|
+
model: import_zod3.z.string().nullish(),
|
|
1168
|
+
usage: import_zod3.z.object({
|
|
1169
|
+
input_tokens: import_zod3.z.number(),
|
|
1170
|
+
output_tokens: import_zod3.z.number(),
|
|
1171
|
+
cache_creation_input_tokens: import_zod3.z.number().nullish(),
|
|
1172
|
+
cache_read_input_tokens: import_zod3.z.number().nullish()
|
|
933
1173
|
})
|
|
934
1174
|
})
|
|
935
1175
|
}),
|
|
936
|
-
|
|
937
|
-
type:
|
|
938
|
-
index:
|
|
939
|
-
content_block:
|
|
940
|
-
|
|
941
|
-
type:
|
|
942
|
-
text:
|
|
1176
|
+
import_zod3.z.object({
|
|
1177
|
+
type: import_zod3.z.literal("content_block_start"),
|
|
1178
|
+
index: import_zod3.z.number(),
|
|
1179
|
+
content_block: import_zod3.z.discriminatedUnion("type", [
|
|
1180
|
+
import_zod3.z.object({
|
|
1181
|
+
type: import_zod3.z.literal("text"),
|
|
1182
|
+
text: import_zod3.z.string()
|
|
1183
|
+
}),
|
|
1184
|
+
import_zod3.z.object({
|
|
1185
|
+
type: import_zod3.z.literal("thinking"),
|
|
1186
|
+
thinking: import_zod3.z.string()
|
|
943
1187
|
}),
|
|
944
|
-
|
|
945
|
-
type:
|
|
946
|
-
|
|
1188
|
+
import_zod3.z.object({
|
|
1189
|
+
type: import_zod3.z.literal("tool_use"),
|
|
1190
|
+
id: import_zod3.z.string(),
|
|
1191
|
+
name: import_zod3.z.string()
|
|
947
1192
|
}),
|
|
948
|
-
|
|
949
|
-
type:
|
|
950
|
-
|
|
951
|
-
name: import_zod2.z.string()
|
|
1193
|
+
import_zod3.z.object({
|
|
1194
|
+
type: import_zod3.z.literal("redacted_thinking"),
|
|
1195
|
+
data: import_zod3.z.string()
|
|
952
1196
|
}),
|
|
953
|
-
|
|
954
|
-
type:
|
|
955
|
-
|
|
1197
|
+
import_zod3.z.object({
|
|
1198
|
+
type: import_zod3.z.literal("server_tool_use"),
|
|
1199
|
+
id: import_zod3.z.string(),
|
|
1200
|
+
name: import_zod3.z.string(),
|
|
1201
|
+
input: import_zod3.z.record(import_zod3.z.unknown()).nullish()
|
|
1202
|
+
}),
|
|
1203
|
+
import_zod3.z.object({
|
|
1204
|
+
type: import_zod3.z.literal("web_search_tool_result"),
|
|
1205
|
+
tool_use_id: import_zod3.z.string(),
|
|
1206
|
+
content: import_zod3.z.union([
|
|
1207
|
+
import_zod3.z.array(
|
|
1208
|
+
import_zod3.z.object({
|
|
1209
|
+
type: import_zod3.z.literal("web_search_result"),
|
|
1210
|
+
url: import_zod3.z.string(),
|
|
1211
|
+
title: import_zod3.z.string(),
|
|
1212
|
+
encrypted_content: import_zod3.z.string(),
|
|
1213
|
+
page_age: import_zod3.z.string().nullish()
|
|
1214
|
+
})
|
|
1215
|
+
),
|
|
1216
|
+
import_zod3.z.object({
|
|
1217
|
+
type: import_zod3.z.literal("web_search_tool_result_error"),
|
|
1218
|
+
error_code: import_zod3.z.string()
|
|
1219
|
+
})
|
|
1220
|
+
])
|
|
956
1221
|
})
|
|
957
1222
|
])
|
|
958
1223
|
}),
|
|
959
|
-
|
|
960
|
-
type:
|
|
961
|
-
index:
|
|
962
|
-
delta:
|
|
963
|
-
|
|
964
|
-
type:
|
|
965
|
-
partial_json:
|
|
1224
|
+
import_zod3.z.object({
|
|
1225
|
+
type: import_zod3.z.literal("content_block_delta"),
|
|
1226
|
+
index: import_zod3.z.number(),
|
|
1227
|
+
delta: import_zod3.z.discriminatedUnion("type", [
|
|
1228
|
+
import_zod3.z.object({
|
|
1229
|
+
type: import_zod3.z.literal("input_json_delta"),
|
|
1230
|
+
partial_json: import_zod3.z.string()
|
|
1231
|
+
}),
|
|
1232
|
+
import_zod3.z.object({
|
|
1233
|
+
type: import_zod3.z.literal("text_delta"),
|
|
1234
|
+
text: import_zod3.z.string()
|
|
966
1235
|
}),
|
|
967
|
-
|
|
968
|
-
type:
|
|
969
|
-
|
|
1236
|
+
import_zod3.z.object({
|
|
1237
|
+
type: import_zod3.z.literal("thinking_delta"),
|
|
1238
|
+
thinking: import_zod3.z.string()
|
|
970
1239
|
}),
|
|
971
|
-
|
|
972
|
-
type:
|
|
973
|
-
|
|
1240
|
+
import_zod3.z.object({
|
|
1241
|
+
type: import_zod3.z.literal("signature_delta"),
|
|
1242
|
+
signature: import_zod3.z.string()
|
|
974
1243
|
}),
|
|
975
|
-
|
|
976
|
-
type:
|
|
977
|
-
|
|
1244
|
+
import_zod3.z.object({
|
|
1245
|
+
type: import_zod3.z.literal("citations_delta"),
|
|
1246
|
+
citation: import_zod3.z.object({
|
|
1247
|
+
type: import_zod3.z.literal("web_search_result_location"),
|
|
1248
|
+
cited_text: import_zod3.z.string(),
|
|
1249
|
+
url: import_zod3.z.string(),
|
|
1250
|
+
title: import_zod3.z.string(),
|
|
1251
|
+
encrypted_index: import_zod3.z.string()
|
|
1252
|
+
})
|
|
978
1253
|
})
|
|
979
1254
|
])
|
|
980
1255
|
}),
|
|
981
|
-
|
|
982
|
-
type:
|
|
983
|
-
index:
|
|
1256
|
+
import_zod3.z.object({
|
|
1257
|
+
type: import_zod3.z.literal("content_block_stop"),
|
|
1258
|
+
index: import_zod3.z.number()
|
|
984
1259
|
}),
|
|
985
|
-
|
|
986
|
-
type:
|
|
987
|
-
error:
|
|
988
|
-
type:
|
|
989
|
-
message:
|
|
1260
|
+
import_zod3.z.object({
|
|
1261
|
+
type: import_zod3.z.literal("error"),
|
|
1262
|
+
error: import_zod3.z.object({
|
|
1263
|
+
type: import_zod3.z.string(),
|
|
1264
|
+
message: import_zod3.z.string()
|
|
990
1265
|
})
|
|
991
1266
|
}),
|
|
992
|
-
|
|
993
|
-
type:
|
|
994
|
-
delta:
|
|
995
|
-
usage:
|
|
1267
|
+
import_zod3.z.object({
|
|
1268
|
+
type: import_zod3.z.literal("message_delta"),
|
|
1269
|
+
delta: import_zod3.z.object({ stop_reason: import_zod3.z.string().nullish() }),
|
|
1270
|
+
usage: import_zod3.z.object({ output_tokens: import_zod3.z.number() })
|
|
996
1271
|
}),
|
|
997
|
-
|
|
998
|
-
type:
|
|
1272
|
+
import_zod3.z.object({
|
|
1273
|
+
type: import_zod3.z.literal("message_stop")
|
|
999
1274
|
}),
|
|
1000
|
-
|
|
1001
|
-
type:
|
|
1275
|
+
import_zod3.z.object({
|
|
1276
|
+
type: import_zod3.z.literal("ping")
|
|
1002
1277
|
})
|
|
1003
1278
|
]);
|
|
1004
|
-
var
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
budgetTokens: import_zod2.z.number().optional()
|
|
1008
|
-
}).optional()
|
|
1279
|
+
var anthropicReasoningMetadataSchema = import_zod3.z.object({
|
|
1280
|
+
signature: import_zod3.z.string().optional(),
|
|
1281
|
+
redactedData: import_zod3.z.string().optional()
|
|
1009
1282
|
});
|
|
1010
1283
|
|
|
1011
1284
|
// src/anthropic-tools.ts
|
|
1012
|
-
var
|
|
1013
|
-
var Bash20241022Parameters =
|
|
1014
|
-
command:
|
|
1015
|
-
restart:
|
|
1285
|
+
var import_zod4 = require("zod");
|
|
1286
|
+
var Bash20241022Parameters = import_zod4.z.object({
|
|
1287
|
+
command: import_zod4.z.string(),
|
|
1288
|
+
restart: import_zod4.z.boolean().optional()
|
|
1016
1289
|
});
|
|
1017
1290
|
function bashTool_20241022(options = {}) {
|
|
1018
1291
|
return {
|
|
@@ -1024,9 +1297,9 @@ function bashTool_20241022(options = {}) {
|
|
|
1024
1297
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1025
1298
|
};
|
|
1026
1299
|
}
|
|
1027
|
-
var Bash20250124Parameters =
|
|
1028
|
-
command:
|
|
1029
|
-
restart:
|
|
1300
|
+
var Bash20250124Parameters = import_zod4.z.object({
|
|
1301
|
+
command: import_zod4.z.string(),
|
|
1302
|
+
restart: import_zod4.z.boolean().optional()
|
|
1030
1303
|
});
|
|
1031
1304
|
function bashTool_20250124(options = {}) {
|
|
1032
1305
|
return {
|
|
@@ -1038,14 +1311,14 @@ function bashTool_20250124(options = {}) {
|
|
|
1038
1311
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1039
1312
|
};
|
|
1040
1313
|
}
|
|
1041
|
-
var TextEditor20241022Parameters =
|
|
1042
|
-
command:
|
|
1043
|
-
path:
|
|
1044
|
-
file_text:
|
|
1045
|
-
insert_line:
|
|
1046
|
-
new_str:
|
|
1047
|
-
old_str:
|
|
1048
|
-
view_range:
|
|
1314
|
+
var TextEditor20241022Parameters = import_zod4.z.object({
|
|
1315
|
+
command: import_zod4.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
1316
|
+
path: import_zod4.z.string(),
|
|
1317
|
+
file_text: import_zod4.z.string().optional(),
|
|
1318
|
+
insert_line: import_zod4.z.number().int().optional(),
|
|
1319
|
+
new_str: import_zod4.z.string().optional(),
|
|
1320
|
+
old_str: import_zod4.z.string().optional(),
|
|
1321
|
+
view_range: import_zod4.z.array(import_zod4.z.number().int()).optional()
|
|
1049
1322
|
});
|
|
1050
1323
|
function textEditorTool_20241022(options = {}) {
|
|
1051
1324
|
return {
|
|
@@ -1057,14 +1330,14 @@ function textEditorTool_20241022(options = {}) {
|
|
|
1057
1330
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1058
1331
|
};
|
|
1059
1332
|
}
|
|
1060
|
-
var TextEditor20250124Parameters =
|
|
1061
|
-
command:
|
|
1062
|
-
path:
|
|
1063
|
-
file_text:
|
|
1064
|
-
insert_line:
|
|
1065
|
-
new_str:
|
|
1066
|
-
old_str:
|
|
1067
|
-
view_range:
|
|
1333
|
+
var TextEditor20250124Parameters = import_zod4.z.object({
|
|
1334
|
+
command: import_zod4.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
1335
|
+
path: import_zod4.z.string(),
|
|
1336
|
+
file_text: import_zod4.z.string().optional(),
|
|
1337
|
+
insert_line: import_zod4.z.number().int().optional(),
|
|
1338
|
+
new_str: import_zod4.z.string().optional(),
|
|
1339
|
+
old_str: import_zod4.z.string().optional(),
|
|
1340
|
+
view_range: import_zod4.z.array(import_zod4.z.number().int()).optional()
|
|
1068
1341
|
});
|
|
1069
1342
|
function textEditorTool_20250124(options = {}) {
|
|
1070
1343
|
return {
|
|
@@ -1076,8 +1349,8 @@ function textEditorTool_20250124(options = {}) {
|
|
|
1076
1349
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1077
1350
|
};
|
|
1078
1351
|
}
|
|
1079
|
-
var Computer20241022Parameters =
|
|
1080
|
-
action:
|
|
1352
|
+
var Computer20241022Parameters = import_zod4.z.object({
|
|
1353
|
+
action: import_zod4.z.enum([
|
|
1081
1354
|
"key",
|
|
1082
1355
|
"type",
|
|
1083
1356
|
"mouse_move",
|
|
@@ -1089,8 +1362,8 @@ var Computer20241022Parameters = import_zod3.z.object({
|
|
|
1089
1362
|
"screenshot",
|
|
1090
1363
|
"cursor_position"
|
|
1091
1364
|
]),
|
|
1092
|
-
coordinate:
|
|
1093
|
-
text:
|
|
1365
|
+
coordinate: import_zod4.z.array(import_zod4.z.number().int()).optional(),
|
|
1366
|
+
text: import_zod4.z.string().optional()
|
|
1094
1367
|
});
|
|
1095
1368
|
function computerTool_20241022(options) {
|
|
1096
1369
|
return {
|
|
@@ -1106,8 +1379,8 @@ function computerTool_20241022(options) {
|
|
|
1106
1379
|
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1107
1380
|
};
|
|
1108
1381
|
}
|
|
1109
|
-
var Computer20250124Parameters =
|
|
1110
|
-
action:
|
|
1382
|
+
var Computer20250124Parameters = import_zod4.z.object({
|
|
1383
|
+
action: import_zod4.z.enum([
|
|
1111
1384
|
"key",
|
|
1112
1385
|
"hold_key",
|
|
1113
1386
|
"type",
|
|
@@ -1125,12 +1398,12 @@ var Computer20250124Parameters = import_zod3.z.object({
|
|
|
1125
1398
|
"wait",
|
|
1126
1399
|
"screenshot"
|
|
1127
1400
|
]),
|
|
1128
|
-
coordinate:
|
|
1129
|
-
duration:
|
|
1130
|
-
scroll_amount:
|
|
1131
|
-
scroll_direction:
|
|
1132
|
-
start_coordinate:
|
|
1133
|
-
text:
|
|
1401
|
+
coordinate: import_zod4.z.tuple([import_zod4.z.number().int(), import_zod4.z.number().int()]).optional(),
|
|
1402
|
+
duration: import_zod4.z.number().optional(),
|
|
1403
|
+
scroll_amount: import_zod4.z.number().optional(),
|
|
1404
|
+
scroll_direction: import_zod4.z.enum(["up", "down", "left", "right"]).optional(),
|
|
1405
|
+
start_coordinate: import_zod4.z.tuple([import_zod4.z.number().int(), import_zod4.z.number().int()]).optional(),
|
|
1406
|
+
text: import_zod4.z.string().optional()
|
|
1134
1407
|
});
|
|
1135
1408
|
function computerTool_20250124(options) {
|
|
1136
1409
|
return {
|
|
@@ -1168,20 +1441,26 @@ function createAnthropic(options = {}) {
|
|
|
1168
1441
|
}),
|
|
1169
1442
|
...options.headers
|
|
1170
1443
|
});
|
|
1171
|
-
const createChatModel = (modelId
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1444
|
+
const createChatModel = (modelId) => {
|
|
1445
|
+
var _a2;
|
|
1446
|
+
return new AnthropicMessagesLanguageModel(modelId, {
|
|
1447
|
+
provider: "anthropic.messages",
|
|
1448
|
+
baseURL,
|
|
1449
|
+
headers: getHeaders,
|
|
1450
|
+
fetch: options.fetch,
|
|
1451
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils4.generateId,
|
|
1452
|
+
supportedUrls: () => ({
|
|
1453
|
+
"image/*": [/^https?:\/\/.*$/]
|
|
1454
|
+
})
|
|
1455
|
+
});
|
|
1456
|
+
};
|
|
1457
|
+
const provider = function(modelId) {
|
|
1179
1458
|
if (new.target) {
|
|
1180
1459
|
throw new Error(
|
|
1181
1460
|
"The Anthropic model function cannot be called with the new keyword."
|
|
1182
1461
|
);
|
|
1183
1462
|
}
|
|
1184
|
-
return createChatModel(modelId
|
|
1463
|
+
return createChatModel(modelId);
|
|
1185
1464
|
};
|
|
1186
1465
|
provider.languageModel = createChatModel;
|
|
1187
1466
|
provider.chat = createChatModel;
|
|
@@ -1189,6 +1468,9 @@ function createAnthropic(options = {}) {
|
|
|
1189
1468
|
provider.textEmbeddingModel = (modelId) => {
|
|
1190
1469
|
throw new import_provider4.NoSuchModelError({ modelId, modelType: "textEmbeddingModel" });
|
|
1191
1470
|
};
|
|
1471
|
+
provider.imageModel = (modelId) => {
|
|
1472
|
+
throw new import_provider4.NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
1473
|
+
};
|
|
1192
1474
|
provider.tools = anthropicTools;
|
|
1193
1475
|
return provider;
|
|
1194
1476
|
}
|