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