@ai-sdk/anthropic 2.0.0-alpha.8 → 2.0.0-beta.1
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 +94 -0
- package/dist/index.d.mts +104 -368
- package/dist/index.d.ts +104 -368
- package/dist/index.js +877 -255
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +943 -329
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +107 -364
- package/dist/internal/index.d.ts +107 -364
- package/dist/internal/index.js +861 -243
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +929 -320
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -27,11 +37,11 @@ module.exports = __toCommonJS(src_exports);
|
|
|
27
37
|
|
|
28
38
|
// src/anthropic-provider.ts
|
|
29
39
|
var import_provider4 = require("@ai-sdk/provider");
|
|
30
|
-
var
|
|
40
|
+
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
|
31
41
|
|
|
32
42
|
// src/anthropic-messages-language-model.ts
|
|
33
43
|
var import_provider3 = require("@ai-sdk/provider");
|
|
34
|
-
var
|
|
44
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
35
45
|
var import_zod3 = require("zod");
|
|
36
46
|
|
|
37
47
|
// src/anthropic-error.ts
|
|
@@ -51,12 +61,30 @@ var anthropicFailedResponseHandler = (0, import_provider_utils.createJsonErrorRe
|
|
|
51
61
|
|
|
52
62
|
// src/anthropic-messages-options.ts
|
|
53
63
|
var import_zod2 = require("zod");
|
|
54
|
-
var
|
|
64
|
+
var anthropicFilePartProviderOptions = import_zod2.z.object({
|
|
55
65
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
* Citation configuration for this document.
|
|
67
|
+
* When enabled, this document will generate citations in the response.
|
|
68
|
+
*/
|
|
69
|
+
citations: import_zod2.z.object({
|
|
70
|
+
/**
|
|
71
|
+
* Enable citations for this document
|
|
72
|
+
*/
|
|
73
|
+
enabled: import_zod2.z.boolean()
|
|
74
|
+
}).optional(),
|
|
75
|
+
/**
|
|
76
|
+
* Custom title for the document.
|
|
77
|
+
* If not provided, the filename will be used.
|
|
78
|
+
*/
|
|
79
|
+
title: import_zod2.z.string().optional(),
|
|
80
|
+
/**
|
|
81
|
+
* Context about the document that will be passed to the model
|
|
82
|
+
* but not used towards cited content.
|
|
83
|
+
* Useful for storing document metadata as text or stringified JSON.
|
|
84
|
+
*/
|
|
85
|
+
context: import_zod2.z.string().optional()
|
|
86
|
+
});
|
|
87
|
+
var anthropicProviderOptions = import_zod2.z.object({
|
|
60
88
|
sendReasoning: import_zod2.z.boolean().optional(),
|
|
61
89
|
thinking: import_zod2.z.object({
|
|
62
90
|
type: import_zod2.z.union([import_zod2.z.literal("enabled"), import_zod2.z.literal("disabled")]),
|
|
@@ -66,6 +94,59 @@ var anthropicProviderOptions = import_zod2.z.object({
|
|
|
66
94
|
|
|
67
95
|
// src/anthropic-prepare-tools.ts
|
|
68
96
|
var import_provider = require("@ai-sdk/provider");
|
|
97
|
+
|
|
98
|
+
// src/tool/web-search_20250305.ts
|
|
99
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
100
|
+
var import_v4 = require("zod/v4");
|
|
101
|
+
var webSearch_20250305ArgsSchema = import_v4.z.object({
|
|
102
|
+
/**
|
|
103
|
+
* Maximum number of web searches Claude can perform during the conversation.
|
|
104
|
+
*/
|
|
105
|
+
maxUses: import_v4.z.number().optional(),
|
|
106
|
+
/**
|
|
107
|
+
* Optional list of domains that Claude is allowed to search.
|
|
108
|
+
*/
|
|
109
|
+
allowedDomains: import_v4.z.array(import_v4.z.string()).optional(),
|
|
110
|
+
/**
|
|
111
|
+
* Optional list of domains that Claude should avoid when searching.
|
|
112
|
+
*/
|
|
113
|
+
blockedDomains: import_v4.z.array(import_v4.z.string()).optional(),
|
|
114
|
+
/**
|
|
115
|
+
* Optional user location information to provide geographically relevant search results.
|
|
116
|
+
*/
|
|
117
|
+
userLocation: import_v4.z.object({
|
|
118
|
+
type: import_v4.z.literal("approximate"),
|
|
119
|
+
city: import_v4.z.string().optional(),
|
|
120
|
+
region: import_v4.z.string().optional(),
|
|
121
|
+
country: import_v4.z.string().optional(),
|
|
122
|
+
timezone: import_v4.z.string().optional()
|
|
123
|
+
}).optional()
|
|
124
|
+
});
|
|
125
|
+
var webSearch_20250305OutputSchema = import_v4.z.array(
|
|
126
|
+
import_v4.z.object({
|
|
127
|
+
url: import_v4.z.string(),
|
|
128
|
+
title: import_v4.z.string(),
|
|
129
|
+
pageAge: import_v4.z.string().nullable(),
|
|
130
|
+
encryptedContent: import_v4.z.string(),
|
|
131
|
+
type: import_v4.z.string()
|
|
132
|
+
})
|
|
133
|
+
);
|
|
134
|
+
var factory = (0, import_provider_utils2.createProviderDefinedToolFactoryWithOutputSchema)({
|
|
135
|
+
id: "anthropic.web_search_20250305",
|
|
136
|
+
name: "web_search",
|
|
137
|
+
inputSchema: import_v4.z.object({
|
|
138
|
+
query: import_v4.z.string()
|
|
139
|
+
}),
|
|
140
|
+
outputSchema: webSearch_20250305OutputSchema
|
|
141
|
+
});
|
|
142
|
+
var webSearch_20250305 = (args = {}) => {
|
|
143
|
+
return factory(args);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// src/anthropic-prepare-tools.ts
|
|
147
|
+
function isWebSearchTool(tool) {
|
|
148
|
+
return typeof tool === "object" && tool !== null && "type" in tool && tool.type === "web_search_20250305";
|
|
149
|
+
}
|
|
69
150
|
function prepareTools({
|
|
70
151
|
tools,
|
|
71
152
|
toolChoice
|
|
@@ -78,12 +159,16 @@ function prepareTools({
|
|
|
78
159
|
}
|
|
79
160
|
const anthropicTools2 = [];
|
|
80
161
|
for (const tool of tools) {
|
|
162
|
+
if (isWebSearchTool(tool)) {
|
|
163
|
+
anthropicTools2.push(tool);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
81
166
|
switch (tool.type) {
|
|
82
167
|
case "function":
|
|
83
168
|
anthropicTools2.push({
|
|
84
169
|
name: tool.name,
|
|
85
170
|
description: tool.description,
|
|
86
|
-
input_schema: tool.
|
|
171
|
+
input_schema: tool.inputSchema
|
|
87
172
|
});
|
|
88
173
|
break;
|
|
89
174
|
case "provider-defined":
|
|
@@ -91,7 +176,7 @@ function prepareTools({
|
|
|
91
176
|
case "anthropic.computer_20250124":
|
|
92
177
|
betas.add("computer-use-2025-01-24");
|
|
93
178
|
anthropicTools2.push({
|
|
94
|
-
name:
|
|
179
|
+
name: "computer",
|
|
95
180
|
type: "computer_20250124",
|
|
96
181
|
display_width_px: tool.args.displayWidthPx,
|
|
97
182
|
display_height_px: tool.args.displayHeightPx,
|
|
@@ -101,7 +186,7 @@ function prepareTools({
|
|
|
101
186
|
case "anthropic.computer_20241022":
|
|
102
187
|
betas.add("computer-use-2024-10-22");
|
|
103
188
|
anthropicTools2.push({
|
|
104
|
-
name:
|
|
189
|
+
name: "computer",
|
|
105
190
|
type: "computer_20241022",
|
|
106
191
|
display_width_px: tool.args.displayWidthPx,
|
|
107
192
|
display_height_px: tool.args.displayHeightPx,
|
|
@@ -111,31 +196,43 @@ function prepareTools({
|
|
|
111
196
|
case "anthropic.text_editor_20250124":
|
|
112
197
|
betas.add("computer-use-2025-01-24");
|
|
113
198
|
anthropicTools2.push({
|
|
114
|
-
name:
|
|
199
|
+
name: "str_replace_editor",
|
|
115
200
|
type: "text_editor_20250124"
|
|
116
201
|
});
|
|
117
202
|
break;
|
|
118
203
|
case "anthropic.text_editor_20241022":
|
|
119
204
|
betas.add("computer-use-2024-10-22");
|
|
120
205
|
anthropicTools2.push({
|
|
121
|
-
name:
|
|
206
|
+
name: "str_replace_editor",
|
|
122
207
|
type: "text_editor_20241022"
|
|
123
208
|
});
|
|
124
209
|
break;
|
|
125
210
|
case "anthropic.bash_20250124":
|
|
126
211
|
betas.add("computer-use-2025-01-24");
|
|
127
212
|
anthropicTools2.push({
|
|
128
|
-
name:
|
|
213
|
+
name: "bash",
|
|
129
214
|
type: "bash_20250124"
|
|
130
215
|
});
|
|
131
216
|
break;
|
|
132
217
|
case "anthropic.bash_20241022":
|
|
133
218
|
betas.add("computer-use-2024-10-22");
|
|
134
219
|
anthropicTools2.push({
|
|
135
|
-
name:
|
|
220
|
+
name: "bash",
|
|
136
221
|
type: "bash_20241022"
|
|
137
222
|
});
|
|
138
223
|
break;
|
|
224
|
+
case "anthropic.web_search_20250305": {
|
|
225
|
+
const args = webSearch_20250305ArgsSchema.parse(tool.args);
|
|
226
|
+
anthropicTools2.push({
|
|
227
|
+
type: "web_search_20250305",
|
|
228
|
+
name: "web_search",
|
|
229
|
+
max_uses: args.maxUses,
|
|
230
|
+
allowed_domains: args.allowedDomains,
|
|
231
|
+
blocked_domains: args.blockedDomains,
|
|
232
|
+
user_location: args.userLocation
|
|
233
|
+
});
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
139
236
|
default:
|
|
140
237
|
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
141
238
|
break;
|
|
@@ -190,13 +287,29 @@ function prepareTools({
|
|
|
190
287
|
|
|
191
288
|
// src/convert-to-anthropic-messages-prompt.ts
|
|
192
289
|
var import_provider2 = require("@ai-sdk/provider");
|
|
193
|
-
var
|
|
290
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
291
|
+
function convertToString(data) {
|
|
292
|
+
if (typeof data === "string") {
|
|
293
|
+
return Buffer.from(data, "base64").toString("utf-8");
|
|
294
|
+
}
|
|
295
|
+
if (data instanceof Uint8Array) {
|
|
296
|
+
return new TextDecoder().decode(data);
|
|
297
|
+
}
|
|
298
|
+
if (data instanceof URL) {
|
|
299
|
+
throw new import_provider2.UnsupportedFunctionalityError({
|
|
300
|
+
functionality: "URL-based text documents are not supported for citations"
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
throw new import_provider2.UnsupportedFunctionalityError({
|
|
304
|
+
functionality: `unsupported data type for text documents: ${typeof data}`
|
|
305
|
+
});
|
|
306
|
+
}
|
|
194
307
|
async function convertToAnthropicMessagesPrompt({
|
|
195
308
|
prompt,
|
|
196
309
|
sendReasoning,
|
|
197
310
|
warnings
|
|
198
311
|
}) {
|
|
199
|
-
var _a, _b, _c;
|
|
312
|
+
var _a, _b, _c, _d, _e;
|
|
200
313
|
const betas = /* @__PURE__ */ new Set();
|
|
201
314
|
const blocks = groupIntoBlocks(prompt);
|
|
202
315
|
let system = void 0;
|
|
@@ -207,6 +320,26 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
207
320
|
const cacheControlValue = (_a2 = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ? _a2 : anthropic2 == null ? void 0 : anthropic2.cache_control;
|
|
208
321
|
return cacheControlValue;
|
|
209
322
|
}
|
|
323
|
+
async function shouldEnableCitations(providerMetadata) {
|
|
324
|
+
var _a2, _b2;
|
|
325
|
+
const anthropicOptions = await (0, import_provider_utils3.parseProviderOptions)({
|
|
326
|
+
provider: "anthropic",
|
|
327
|
+
providerOptions: providerMetadata,
|
|
328
|
+
schema: anthropicFilePartProviderOptions
|
|
329
|
+
});
|
|
330
|
+
return (_b2 = (_a2 = anthropicOptions == null ? void 0 : anthropicOptions.citations) == null ? void 0 : _a2.enabled) != null ? _b2 : false;
|
|
331
|
+
}
|
|
332
|
+
async function getDocumentMetadata(providerMetadata) {
|
|
333
|
+
const anthropicOptions = await (0, import_provider_utils3.parseProviderOptions)({
|
|
334
|
+
provider: "anthropic",
|
|
335
|
+
providerOptions: providerMetadata,
|
|
336
|
+
schema: anthropicFilePartProviderOptions
|
|
337
|
+
});
|
|
338
|
+
return {
|
|
339
|
+
title: anthropicOptions == null ? void 0 : anthropicOptions.title,
|
|
340
|
+
context: anthropicOptions == null ? void 0 : anthropicOptions.context
|
|
341
|
+
};
|
|
342
|
+
}
|
|
210
343
|
for (let i = 0; i < blocks.length; i++) {
|
|
211
344
|
const block = blocks[i];
|
|
212
345
|
const isLastBlock = i === blocks.length - 1;
|
|
@@ -254,12 +387,18 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
254
387
|
} : {
|
|
255
388
|
type: "base64",
|
|
256
389
|
media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
|
|
257
|
-
data: (0,
|
|
390
|
+
data: (0, import_provider_utils3.convertToBase64)(part.data)
|
|
258
391
|
},
|
|
259
392
|
cache_control: cacheControl
|
|
260
393
|
});
|
|
261
394
|
} else if (part.mediaType === "application/pdf") {
|
|
262
395
|
betas.add("pdfs-2024-09-25");
|
|
396
|
+
const enableCitations = await shouldEnableCitations(
|
|
397
|
+
part.providerOptions
|
|
398
|
+
);
|
|
399
|
+
const metadata = await getDocumentMetadata(
|
|
400
|
+
part.providerOptions
|
|
401
|
+
);
|
|
263
402
|
anthropicContent.push({
|
|
264
403
|
type: "document",
|
|
265
404
|
source: part.data instanceof URL ? {
|
|
@@ -268,7 +407,36 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
268
407
|
} : {
|
|
269
408
|
type: "base64",
|
|
270
409
|
media_type: "application/pdf",
|
|
271
|
-
data: (0,
|
|
410
|
+
data: (0, import_provider_utils3.convertToBase64)(part.data)
|
|
411
|
+
},
|
|
412
|
+
title: (_b = metadata.title) != null ? _b : part.filename,
|
|
413
|
+
...metadata.context && { context: metadata.context },
|
|
414
|
+
...enableCitations && {
|
|
415
|
+
citations: { enabled: true }
|
|
416
|
+
},
|
|
417
|
+
cache_control: cacheControl
|
|
418
|
+
});
|
|
419
|
+
} else if (part.mediaType === "text/plain") {
|
|
420
|
+
const enableCitations = await shouldEnableCitations(
|
|
421
|
+
part.providerOptions
|
|
422
|
+
);
|
|
423
|
+
const metadata = await getDocumentMetadata(
|
|
424
|
+
part.providerOptions
|
|
425
|
+
);
|
|
426
|
+
anthropicContent.push({
|
|
427
|
+
type: "document",
|
|
428
|
+
source: part.data instanceof URL ? {
|
|
429
|
+
type: "url",
|
|
430
|
+
url: part.data.toString()
|
|
431
|
+
} : {
|
|
432
|
+
type: "text",
|
|
433
|
+
media_type: "text/plain",
|
|
434
|
+
data: convertToString(part.data)
|
|
435
|
+
},
|
|
436
|
+
title: (_c = metadata.title) != null ? _c : part.filename,
|
|
437
|
+
...metadata.context && { context: metadata.context },
|
|
438
|
+
...enableCitations && {
|
|
439
|
+
citations: { enabled: true }
|
|
272
440
|
},
|
|
273
441
|
cache_control: cacheControl
|
|
274
442
|
});
|
|
@@ -287,33 +455,53 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
287
455
|
for (let i2 = 0; i2 < content.length; i2++) {
|
|
288
456
|
const part = content[i2];
|
|
289
457
|
const isLastPart = i2 === content.length - 1;
|
|
290
|
-
const cacheControl = (
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
text:
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
458
|
+
const cacheControl = (_d = getCacheControl(part.providerOptions)) != null ? _d : isLastPart ? getCacheControl(message.providerOptions) : void 0;
|
|
459
|
+
const output = part.output;
|
|
460
|
+
let contentValue;
|
|
461
|
+
switch (output.type) {
|
|
462
|
+
case "content":
|
|
463
|
+
contentValue = output.value.map((contentPart) => {
|
|
464
|
+
switch (contentPart.type) {
|
|
465
|
+
case "text":
|
|
466
|
+
return {
|
|
467
|
+
type: "text",
|
|
468
|
+
text: contentPart.text,
|
|
469
|
+
cache_control: void 0
|
|
470
|
+
};
|
|
471
|
+
case "media": {
|
|
472
|
+
if (contentPart.mediaType.startsWith("image/")) {
|
|
473
|
+
return {
|
|
474
|
+
type: "image",
|
|
475
|
+
source: {
|
|
476
|
+
type: "base64",
|
|
477
|
+
media_type: contentPart.mediaType,
|
|
478
|
+
data: contentPart.data
|
|
479
|
+
},
|
|
480
|
+
cache_control: void 0
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
throw new import_provider2.UnsupportedFunctionalityError({
|
|
484
|
+
functionality: `media type: ${contentPart.mediaType}`
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
break;
|
|
490
|
+
case "text":
|
|
491
|
+
case "error-text":
|
|
492
|
+
contentValue = output.value;
|
|
493
|
+
break;
|
|
494
|
+
case "json":
|
|
495
|
+
case "error-json":
|
|
496
|
+
default:
|
|
497
|
+
contentValue = JSON.stringify(output.value);
|
|
498
|
+
break;
|
|
499
|
+
}
|
|
312
500
|
anthropicContent.push({
|
|
313
501
|
type: "tool_result",
|
|
314
502
|
tool_use_id: part.toolCallId,
|
|
315
|
-
content:
|
|
316
|
-
is_error:
|
|
503
|
+
content: contentValue,
|
|
504
|
+
is_error: output.type === "error-text" || output.type === "error-json" ? true : void 0,
|
|
317
505
|
cache_control: cacheControl
|
|
318
506
|
});
|
|
319
507
|
}
|
|
@@ -337,7 +525,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
337
525
|
for (let k = 0; k < content.length; k++) {
|
|
338
526
|
const part = content[k];
|
|
339
527
|
const isLastContentPart = k === content.length - 1;
|
|
340
|
-
const cacheControl = (
|
|
528
|
+
const cacheControl = (_e = getCacheControl(part.providerOptions)) != null ? _e : isLastContentPart ? getCacheControl(message.providerOptions) : void 0;
|
|
341
529
|
switch (part.type) {
|
|
342
530
|
case "text": {
|
|
343
531
|
anthropicContent.push({
|
|
@@ -354,7 +542,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
354
542
|
}
|
|
355
543
|
case "reasoning": {
|
|
356
544
|
if (sendReasoning) {
|
|
357
|
-
const reasoningMetadata = await (0,
|
|
545
|
+
const reasoningMetadata = await (0, import_provider_utils3.parseProviderOptions)({
|
|
358
546
|
provider: "anthropic",
|
|
359
547
|
providerOptions: part.providerOptions,
|
|
360
548
|
schema: anthropicReasoningMetadataSchema
|
|
@@ -394,15 +582,65 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
394
582
|
break;
|
|
395
583
|
}
|
|
396
584
|
case "tool-call": {
|
|
585
|
+
if (part.providerExecuted) {
|
|
586
|
+
if (part.toolName === "web_search") {
|
|
587
|
+
anthropicContent.push({
|
|
588
|
+
type: "server_tool_use",
|
|
589
|
+
id: part.toolCallId,
|
|
590
|
+
name: "web_search",
|
|
591
|
+
input: part.input,
|
|
592
|
+
cache_control: cacheControl
|
|
593
|
+
});
|
|
594
|
+
break;
|
|
595
|
+
}
|
|
596
|
+
warnings.push({
|
|
597
|
+
type: "other",
|
|
598
|
+
message: `provider executed tool call for tool ${part.toolName} is not supported`
|
|
599
|
+
});
|
|
600
|
+
break;
|
|
601
|
+
}
|
|
397
602
|
anthropicContent.push({
|
|
398
603
|
type: "tool_use",
|
|
399
604
|
id: part.toolCallId,
|
|
400
605
|
name: part.toolName,
|
|
401
|
-
input: part.
|
|
606
|
+
input: part.input,
|
|
402
607
|
cache_control: cacheControl
|
|
403
608
|
});
|
|
404
609
|
break;
|
|
405
610
|
}
|
|
611
|
+
case "tool-result": {
|
|
612
|
+
if (part.toolName === "web_search") {
|
|
613
|
+
const output = part.output;
|
|
614
|
+
if (output.type !== "json") {
|
|
615
|
+
warnings.push({
|
|
616
|
+
type: "other",
|
|
617
|
+
message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
|
|
618
|
+
});
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
const webSearchOutput = webSearch_20250305OutputSchema.parse(
|
|
622
|
+
output.value
|
|
623
|
+
);
|
|
624
|
+
anthropicContent.push({
|
|
625
|
+
type: "web_search_tool_result",
|
|
626
|
+
tool_use_id: part.toolCallId,
|
|
627
|
+
content: webSearchOutput.map((result) => ({
|
|
628
|
+
url: result.url,
|
|
629
|
+
title: result.title,
|
|
630
|
+
page_age: result.pageAge,
|
|
631
|
+
encrypted_content: result.encryptedContent,
|
|
632
|
+
type: result.type
|
|
633
|
+
})),
|
|
634
|
+
cache_control: cacheControl
|
|
635
|
+
});
|
|
636
|
+
break;
|
|
637
|
+
}
|
|
638
|
+
warnings.push({
|
|
639
|
+
type: "other",
|
|
640
|
+
message: `provider executed tool result for tool ${part.toolName} is not supported`
|
|
641
|
+
});
|
|
642
|
+
break;
|
|
643
|
+
}
|
|
406
644
|
}
|
|
407
645
|
}
|
|
408
646
|
}
|
|
@@ -486,11 +724,86 @@ function mapAnthropicStopReason({
|
|
|
486
724
|
}
|
|
487
725
|
|
|
488
726
|
// src/anthropic-messages-language-model.ts
|
|
727
|
+
var citationSchemas = {
|
|
728
|
+
webSearchResult: import_zod3.z.object({
|
|
729
|
+
type: import_zod3.z.literal("web_search_result_location"),
|
|
730
|
+
cited_text: import_zod3.z.string(),
|
|
731
|
+
url: import_zod3.z.string(),
|
|
732
|
+
title: import_zod3.z.string(),
|
|
733
|
+
encrypted_index: import_zod3.z.string()
|
|
734
|
+
}),
|
|
735
|
+
pageLocation: import_zod3.z.object({
|
|
736
|
+
type: import_zod3.z.literal("page_location"),
|
|
737
|
+
cited_text: import_zod3.z.string(),
|
|
738
|
+
document_index: import_zod3.z.number(),
|
|
739
|
+
document_title: import_zod3.z.string().nullable(),
|
|
740
|
+
start_page_number: import_zod3.z.number(),
|
|
741
|
+
end_page_number: import_zod3.z.number()
|
|
742
|
+
}),
|
|
743
|
+
charLocation: import_zod3.z.object({
|
|
744
|
+
type: import_zod3.z.literal("char_location"),
|
|
745
|
+
cited_text: import_zod3.z.string(),
|
|
746
|
+
document_index: import_zod3.z.number(),
|
|
747
|
+
document_title: import_zod3.z.string().nullable(),
|
|
748
|
+
start_char_index: import_zod3.z.number(),
|
|
749
|
+
end_char_index: import_zod3.z.number()
|
|
750
|
+
})
|
|
751
|
+
};
|
|
752
|
+
var citationSchema = import_zod3.z.discriminatedUnion("type", [
|
|
753
|
+
citationSchemas.webSearchResult,
|
|
754
|
+
citationSchemas.pageLocation,
|
|
755
|
+
citationSchemas.charLocation
|
|
756
|
+
]);
|
|
757
|
+
var documentCitationSchema = import_zod3.z.discriminatedUnion("type", [
|
|
758
|
+
citationSchemas.pageLocation,
|
|
759
|
+
citationSchemas.charLocation
|
|
760
|
+
]);
|
|
761
|
+
function processCitation(citation, citationDocuments, generateId3, onSource) {
|
|
762
|
+
if (citation.type === "page_location" || citation.type === "char_location") {
|
|
763
|
+
const source = createCitationSource(
|
|
764
|
+
citation,
|
|
765
|
+
citationDocuments,
|
|
766
|
+
generateId3
|
|
767
|
+
);
|
|
768
|
+
if (source) {
|
|
769
|
+
onSource(source);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
function createCitationSource(citation, citationDocuments, generateId3) {
|
|
774
|
+
var _a;
|
|
775
|
+
const documentInfo = citationDocuments[citation.document_index];
|
|
776
|
+
if (!documentInfo) {
|
|
777
|
+
return null;
|
|
778
|
+
}
|
|
779
|
+
const providerMetadata = citation.type === "page_location" ? {
|
|
780
|
+
citedText: citation.cited_text,
|
|
781
|
+
startPageNumber: citation.start_page_number,
|
|
782
|
+
endPageNumber: citation.end_page_number
|
|
783
|
+
} : {
|
|
784
|
+
citedText: citation.cited_text,
|
|
785
|
+
startCharIndex: citation.start_char_index,
|
|
786
|
+
endCharIndex: citation.end_char_index
|
|
787
|
+
};
|
|
788
|
+
return {
|
|
789
|
+
type: "source",
|
|
790
|
+
sourceType: "document",
|
|
791
|
+
id: generateId3(),
|
|
792
|
+
mediaType: documentInfo.mediaType,
|
|
793
|
+
title: (_a = citation.document_title) != null ? _a : documentInfo.title,
|
|
794
|
+
filename: documentInfo.filename,
|
|
795
|
+
providerMetadata: {
|
|
796
|
+
anthropic: providerMetadata
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
}
|
|
489
800
|
var AnthropicMessagesLanguageModel = class {
|
|
490
801
|
constructor(modelId, config) {
|
|
491
802
|
this.specificationVersion = "v2";
|
|
803
|
+
var _a;
|
|
492
804
|
this.modelId = modelId;
|
|
493
805
|
this.config = config;
|
|
806
|
+
this.generateId = (_a = config.generateId) != null ? _a : import_provider_utils4.generateId;
|
|
494
807
|
}
|
|
495
808
|
supportsUrl(url) {
|
|
496
809
|
return url.protocol === "https:";
|
|
@@ -557,9 +870,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
557
870
|
type: "function",
|
|
558
871
|
name: "json",
|
|
559
872
|
description: "Respond with a JSON object.",
|
|
560
|
-
|
|
873
|
+
inputSchema: responseFormat.schema
|
|
561
874
|
} : void 0;
|
|
562
|
-
const anthropicOptions = await (0,
|
|
875
|
+
const anthropicOptions = await (0, import_provider_utils4.parseProviderOptions)({
|
|
563
876
|
provider: "anthropic",
|
|
564
877
|
providerOptions,
|
|
565
878
|
schema: anthropicProviderOptions
|
|
@@ -629,7 +942,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
629
942
|
jsonResponseTool != null ? {
|
|
630
943
|
tools: [jsonResponseTool],
|
|
631
944
|
toolChoice: { type: "tool", toolName: jsonResponseTool.name }
|
|
632
|
-
} : { tools, toolChoice }
|
|
945
|
+
} : { tools: tools != null ? tools : [], toolChoice }
|
|
633
946
|
);
|
|
634
947
|
return {
|
|
635
948
|
args: {
|
|
@@ -646,8 +959,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
646
959
|
betas,
|
|
647
960
|
headers
|
|
648
961
|
}) {
|
|
649
|
-
return (0,
|
|
650
|
-
await (0,
|
|
962
|
+
return (0, import_provider_utils4.combineHeaders)(
|
|
963
|
+
await (0, import_provider_utils4.resolve)(this.config.headers),
|
|
651
964
|
betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {},
|
|
652
965
|
headers
|
|
653
966
|
);
|
|
@@ -660,19 +973,43 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
660
973
|
var _a, _b, _c;
|
|
661
974
|
return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args)) != null ? _c : args;
|
|
662
975
|
}
|
|
976
|
+
extractCitationDocuments(prompt) {
|
|
977
|
+
const isCitationPart = (part) => {
|
|
978
|
+
var _a, _b;
|
|
979
|
+
if (part.type !== "file") {
|
|
980
|
+
return false;
|
|
981
|
+
}
|
|
982
|
+
if (part.mediaType !== "application/pdf" && part.mediaType !== "text/plain") {
|
|
983
|
+
return false;
|
|
984
|
+
}
|
|
985
|
+
const anthropic2 = (_a = part.providerOptions) == null ? void 0 : _a.anthropic;
|
|
986
|
+
const citationsConfig = anthropic2 == null ? void 0 : anthropic2.citations;
|
|
987
|
+
return (_b = citationsConfig == null ? void 0 : citationsConfig.enabled) != null ? _b : false;
|
|
988
|
+
};
|
|
989
|
+
return prompt.filter((message) => message.role === "user").flatMap((message) => message.content).filter(isCitationPart).map((part) => {
|
|
990
|
+
var _a;
|
|
991
|
+
const filePart = part;
|
|
992
|
+
return {
|
|
993
|
+
title: (_a = filePart.filename) != null ? _a : "Untitled Document",
|
|
994
|
+
filename: filePart.filename,
|
|
995
|
+
mediaType: filePart.mediaType
|
|
996
|
+
};
|
|
997
|
+
});
|
|
998
|
+
}
|
|
663
999
|
async doGenerate(options) {
|
|
664
|
-
var _a, _b, _c, _d;
|
|
1000
|
+
var _a, _b, _c, _d, _e;
|
|
665
1001
|
const { args, warnings, betas, jsonResponseTool } = await this.getArgs(options);
|
|
1002
|
+
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
666
1003
|
const {
|
|
667
1004
|
responseHeaders,
|
|
668
1005
|
value: response,
|
|
669
1006
|
rawValue: rawResponse
|
|
670
|
-
} = await (0,
|
|
1007
|
+
} = await (0, import_provider_utils4.postJsonToApi)({
|
|
671
1008
|
url: this.buildRequestUrl(false),
|
|
672
1009
|
headers: await this.getHeaders({ betas, headers: options.headers }),
|
|
673
1010
|
body: this.transformRequestBody(args),
|
|
674
1011
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
675
|
-
successfulResponseHandler: (0,
|
|
1012
|
+
successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
|
|
676
1013
|
anthropicMessagesResponseSchema
|
|
677
1014
|
),
|
|
678
1015
|
abortSignal: options.abortSignal,
|
|
@@ -684,6 +1021,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
684
1021
|
case "text": {
|
|
685
1022
|
if (jsonResponseTool == null) {
|
|
686
1023
|
content.push({ type: "text", text: part.text });
|
|
1024
|
+
if (part.citations) {
|
|
1025
|
+
for (const citation of part.citations) {
|
|
1026
|
+
processCitation(
|
|
1027
|
+
citation,
|
|
1028
|
+
citationDocuments,
|
|
1029
|
+
this.generateId,
|
|
1030
|
+
(source) => content.push(source)
|
|
1031
|
+
);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
687
1034
|
}
|
|
688
1035
|
break;
|
|
689
1036
|
}
|
|
@@ -719,14 +1066,72 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
719
1066
|
text: JSON.stringify(part.input)
|
|
720
1067
|
} : {
|
|
721
1068
|
type: "tool-call",
|
|
722
|
-
toolCallType: "function",
|
|
723
1069
|
toolCallId: part.id,
|
|
724
1070
|
toolName: part.name,
|
|
725
|
-
|
|
1071
|
+
input: JSON.stringify(part.input)
|
|
726
1072
|
}
|
|
727
1073
|
);
|
|
728
1074
|
break;
|
|
729
1075
|
}
|
|
1076
|
+
case "server_tool_use": {
|
|
1077
|
+
if (part.name === "web_search") {
|
|
1078
|
+
content.push({
|
|
1079
|
+
type: "tool-call",
|
|
1080
|
+
toolCallId: part.id,
|
|
1081
|
+
toolName: part.name,
|
|
1082
|
+
input: JSON.stringify(part.input),
|
|
1083
|
+
providerExecuted: true
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
break;
|
|
1087
|
+
}
|
|
1088
|
+
case "web_search_tool_result": {
|
|
1089
|
+
if (Array.isArray(part.content)) {
|
|
1090
|
+
content.push({
|
|
1091
|
+
type: "tool-result",
|
|
1092
|
+
toolCallId: part.tool_use_id,
|
|
1093
|
+
toolName: "web_search",
|
|
1094
|
+
result: part.content.map((result) => {
|
|
1095
|
+
var _a2;
|
|
1096
|
+
return {
|
|
1097
|
+
url: result.url,
|
|
1098
|
+
title: result.title,
|
|
1099
|
+
pageAge: (_a2 = result.page_age) != null ? _a2 : null,
|
|
1100
|
+
encryptedContent: result.encrypted_content,
|
|
1101
|
+
type: result.type
|
|
1102
|
+
};
|
|
1103
|
+
}),
|
|
1104
|
+
providerExecuted: true
|
|
1105
|
+
});
|
|
1106
|
+
for (const result of part.content) {
|
|
1107
|
+
content.push({
|
|
1108
|
+
type: "source",
|
|
1109
|
+
sourceType: "url",
|
|
1110
|
+
id: this.generateId(),
|
|
1111
|
+
url: result.url,
|
|
1112
|
+
title: result.title,
|
|
1113
|
+
providerMetadata: {
|
|
1114
|
+
anthropic: {
|
|
1115
|
+
pageAge: (_a = result.page_age) != null ? _a : null
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
} else {
|
|
1121
|
+
content.push({
|
|
1122
|
+
type: "tool-result",
|
|
1123
|
+
toolCallId: part.tool_use_id,
|
|
1124
|
+
toolName: "web_search",
|
|
1125
|
+
isError: true,
|
|
1126
|
+
result: {
|
|
1127
|
+
type: "web_search_tool_result_error",
|
|
1128
|
+
errorCode: part.content.error_code
|
|
1129
|
+
},
|
|
1130
|
+
providerExecuted: true
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
break;
|
|
1134
|
+
}
|
|
730
1135
|
}
|
|
731
1136
|
}
|
|
732
1137
|
return {
|
|
@@ -739,32 +1144,33 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
739
1144
|
inputTokens: response.usage.input_tokens,
|
|
740
1145
|
outputTokens: response.usage.output_tokens,
|
|
741
1146
|
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
742
|
-
cachedInputTokens: (
|
|
1147
|
+
cachedInputTokens: (_b = response.usage.cache_read_input_tokens) != null ? _b : void 0
|
|
743
1148
|
},
|
|
744
1149
|
request: { body: args },
|
|
745
1150
|
response: {
|
|
746
|
-
id: (
|
|
747
|
-
modelId: (
|
|
1151
|
+
id: (_c = response.id) != null ? _c : void 0,
|
|
1152
|
+
modelId: (_d = response.model) != null ? _d : void 0,
|
|
748
1153
|
headers: responseHeaders,
|
|
749
1154
|
body: rawResponse
|
|
750
1155
|
},
|
|
751
1156
|
warnings,
|
|
752
1157
|
providerMetadata: {
|
|
753
1158
|
anthropic: {
|
|
754
|
-
cacheCreationInputTokens: (
|
|
1159
|
+
cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null
|
|
755
1160
|
}
|
|
756
1161
|
}
|
|
757
1162
|
};
|
|
758
1163
|
}
|
|
759
1164
|
async doStream(options) {
|
|
760
1165
|
const { args, warnings, betas, jsonResponseTool } = await this.getArgs(options);
|
|
1166
|
+
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
761
1167
|
const body = { ...args, stream: true };
|
|
762
|
-
const { responseHeaders, value: response } = await (0,
|
|
1168
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
|
|
763
1169
|
url: this.buildRequestUrl(true),
|
|
764
1170
|
headers: await this.getHeaders({ betas, headers: options.headers }),
|
|
765
1171
|
body: this.transformRequestBody(body),
|
|
766
1172
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
767
|
-
successfulResponseHandler: (0,
|
|
1173
|
+
successfulResponseHandler: (0, import_provider_utils4.createEventSourceResponseHandler)(
|
|
768
1174
|
anthropicMessagesChunkSchema
|
|
769
1175
|
),
|
|
770
1176
|
abortSignal: options.abortSignal,
|
|
@@ -776,9 +1182,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
776
1182
|
outputTokens: void 0,
|
|
777
1183
|
totalTokens: void 0
|
|
778
1184
|
};
|
|
779
|
-
const
|
|
1185
|
+
const contentBlocks = {};
|
|
780
1186
|
let providerMetadata = void 0;
|
|
781
1187
|
let blockType = void 0;
|
|
1188
|
+
const generateId3 = this.generateId;
|
|
782
1189
|
return {
|
|
783
1190
|
stream: response.pipeThrough(
|
|
784
1191
|
new TransformStream({
|
|
@@ -786,7 +1193,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
786
1193
|
controller.enqueue({ type: "stream-start", warnings });
|
|
787
1194
|
},
|
|
788
1195
|
transform(chunk, controller) {
|
|
789
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1196
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1197
|
+
if (options.includeRawChunks) {
|
|
1198
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1199
|
+
}
|
|
790
1200
|
if (!chunk.success) {
|
|
791
1201
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
792
1202
|
return;
|
|
@@ -800,29 +1210,115 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
800
1210
|
const contentBlockType = value.content_block.type;
|
|
801
1211
|
blockType = contentBlockType;
|
|
802
1212
|
switch (contentBlockType) {
|
|
803
|
-
case "text":
|
|
1213
|
+
case "text": {
|
|
1214
|
+
contentBlocks[value.index] = { type: "text" };
|
|
1215
|
+
controller.enqueue({
|
|
1216
|
+
type: "text-start",
|
|
1217
|
+
id: String(value.index)
|
|
1218
|
+
});
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
804
1221
|
case "thinking": {
|
|
1222
|
+
contentBlocks[value.index] = { type: "reasoning" };
|
|
1223
|
+
controller.enqueue({
|
|
1224
|
+
type: "reasoning-start",
|
|
1225
|
+
id: String(value.index)
|
|
1226
|
+
});
|
|
805
1227
|
return;
|
|
806
1228
|
}
|
|
807
1229
|
case "redacted_thinking": {
|
|
1230
|
+
contentBlocks[value.index] = { type: "reasoning" };
|
|
808
1231
|
controller.enqueue({
|
|
809
|
-
type: "reasoning",
|
|
810
|
-
|
|
1232
|
+
type: "reasoning-start",
|
|
1233
|
+
id: String(value.index),
|
|
811
1234
|
providerMetadata: {
|
|
812
1235
|
anthropic: {
|
|
813
1236
|
redactedData: value.content_block.data
|
|
814
1237
|
}
|
|
815
1238
|
}
|
|
816
1239
|
});
|
|
817
|
-
controller.enqueue({ type: "reasoning-part-finish" });
|
|
818
1240
|
return;
|
|
819
1241
|
}
|
|
820
1242
|
case "tool_use": {
|
|
821
|
-
|
|
1243
|
+
contentBlocks[value.index] = jsonResponseTool != null ? { type: "text" } : {
|
|
1244
|
+
type: "tool-call",
|
|
822
1245
|
toolCallId: value.content_block.id,
|
|
823
1246
|
toolName: value.content_block.name,
|
|
824
|
-
|
|
1247
|
+
input: ""
|
|
825
1248
|
};
|
|
1249
|
+
controller.enqueue(
|
|
1250
|
+
jsonResponseTool != null ? { type: "text-start", id: String(value.index) } : {
|
|
1251
|
+
type: "tool-input-start",
|
|
1252
|
+
id: String(value.index),
|
|
1253
|
+
toolName: value.content_block.name
|
|
1254
|
+
}
|
|
1255
|
+
);
|
|
1256
|
+
return;
|
|
1257
|
+
}
|
|
1258
|
+
case "server_tool_use": {
|
|
1259
|
+
if (value.content_block.name === "web_search") {
|
|
1260
|
+
contentBlocks[value.index] = {
|
|
1261
|
+
type: "tool-call",
|
|
1262
|
+
toolCallId: value.content_block.id,
|
|
1263
|
+
toolName: value.content_block.name,
|
|
1264
|
+
input: "",
|
|
1265
|
+
providerExecuted: true
|
|
1266
|
+
};
|
|
1267
|
+
controller.enqueue({
|
|
1268
|
+
type: "tool-input-start",
|
|
1269
|
+
id: value.content_block.id,
|
|
1270
|
+
toolName: value.content_block.name,
|
|
1271
|
+
providerExecuted: true
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
case "web_search_tool_result": {
|
|
1277
|
+
const part = value.content_block;
|
|
1278
|
+
if (Array.isArray(part.content)) {
|
|
1279
|
+
controller.enqueue({
|
|
1280
|
+
type: "tool-result",
|
|
1281
|
+
toolCallId: part.tool_use_id,
|
|
1282
|
+
toolName: "web_search",
|
|
1283
|
+
result: part.content.map((result) => {
|
|
1284
|
+
var _a2;
|
|
1285
|
+
return {
|
|
1286
|
+
url: result.url,
|
|
1287
|
+
title: result.title,
|
|
1288
|
+
pageAge: (_a2 = result.page_age) != null ? _a2 : null,
|
|
1289
|
+
encryptedContent: result.encrypted_content,
|
|
1290
|
+
type: result.type
|
|
1291
|
+
};
|
|
1292
|
+
}),
|
|
1293
|
+
providerExecuted: true
|
|
1294
|
+
});
|
|
1295
|
+
for (const result of part.content) {
|
|
1296
|
+
controller.enqueue({
|
|
1297
|
+
type: "source",
|
|
1298
|
+
sourceType: "url",
|
|
1299
|
+
id: generateId3(),
|
|
1300
|
+
url: result.url,
|
|
1301
|
+
title: result.title,
|
|
1302
|
+
providerMetadata: {
|
|
1303
|
+
anthropic: {
|
|
1304
|
+
pageAge: (_a = result.page_age) != null ? _a : null
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
} else {
|
|
1310
|
+
controller.enqueue({
|
|
1311
|
+
type: "tool-result",
|
|
1312
|
+
toolCallId: part.tool_use_id,
|
|
1313
|
+
toolName: "web_search",
|
|
1314
|
+
isError: true,
|
|
1315
|
+
result: {
|
|
1316
|
+
type: "web_search_tool_result_error",
|
|
1317
|
+
errorCode: part.content.error_code
|
|
1318
|
+
},
|
|
1319
|
+
providerExecuted: true
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
826
1322
|
return;
|
|
827
1323
|
}
|
|
828
1324
|
default: {
|
|
@@ -834,18 +1330,34 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
834
1330
|
}
|
|
835
1331
|
}
|
|
836
1332
|
case "content_block_stop": {
|
|
837
|
-
if (
|
|
838
|
-
const contentBlock =
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
}
|
|
1333
|
+
if (contentBlocks[value.index] != null) {
|
|
1334
|
+
const contentBlock = contentBlocks[value.index];
|
|
1335
|
+
switch (contentBlock.type) {
|
|
1336
|
+
case "text": {
|
|
1337
|
+
controller.enqueue({
|
|
1338
|
+
type: "text-end",
|
|
1339
|
+
id: String(value.index)
|
|
1340
|
+
});
|
|
1341
|
+
break;
|
|
1342
|
+
}
|
|
1343
|
+
case "reasoning": {
|
|
1344
|
+
controller.enqueue({
|
|
1345
|
+
type: "reasoning-end",
|
|
1346
|
+
id: String(value.index)
|
|
1347
|
+
});
|
|
1348
|
+
break;
|
|
1349
|
+
}
|
|
1350
|
+
case "tool-call":
|
|
1351
|
+
if (jsonResponseTool == null) {
|
|
1352
|
+
controller.enqueue({
|
|
1353
|
+
type: "tool-input-end",
|
|
1354
|
+
id: contentBlock.toolCallId
|
|
1355
|
+
});
|
|
1356
|
+
controller.enqueue(contentBlock);
|
|
1357
|
+
}
|
|
1358
|
+
break;
|
|
847
1359
|
}
|
|
848
|
-
delete
|
|
1360
|
+
delete contentBlocks[value.index];
|
|
849
1361
|
}
|
|
850
1362
|
blockType = void 0;
|
|
851
1363
|
return;
|
|
@@ -858,48 +1370,68 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
858
1370
|
return;
|
|
859
1371
|
}
|
|
860
1372
|
controller.enqueue({
|
|
861
|
-
type: "text",
|
|
862
|
-
|
|
1373
|
+
type: "text-delta",
|
|
1374
|
+
id: String(value.index),
|
|
1375
|
+
delta: value.delta.text
|
|
863
1376
|
});
|
|
864
1377
|
return;
|
|
865
1378
|
}
|
|
866
1379
|
case "thinking_delta": {
|
|
867
1380
|
controller.enqueue({
|
|
868
|
-
type: "reasoning",
|
|
869
|
-
|
|
1381
|
+
type: "reasoning-delta",
|
|
1382
|
+
id: String(value.index),
|
|
1383
|
+
delta: value.delta.thinking
|
|
870
1384
|
});
|
|
871
1385
|
return;
|
|
872
1386
|
}
|
|
873
1387
|
case "signature_delta": {
|
|
874
1388
|
if (blockType === "thinking") {
|
|
875
1389
|
controller.enqueue({
|
|
876
|
-
type: "reasoning",
|
|
877
|
-
|
|
1390
|
+
type: "reasoning-delta",
|
|
1391
|
+
id: String(value.index),
|
|
1392
|
+
delta: "",
|
|
878
1393
|
providerMetadata: {
|
|
879
1394
|
anthropic: {
|
|
880
1395
|
signature: value.delta.signature
|
|
881
1396
|
}
|
|
882
1397
|
}
|
|
883
1398
|
});
|
|
884
|
-
controller.enqueue({ type: "reasoning-part-finish" });
|
|
885
1399
|
}
|
|
886
1400
|
return;
|
|
887
1401
|
}
|
|
888
1402
|
case "input_json_delta": {
|
|
889
|
-
const contentBlock =
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
} : {
|
|
895
|
-
type: "tool-call-delta",
|
|
896
|
-
toolCallType: "function",
|
|
897
|
-
toolCallId: contentBlock.toolCallId,
|
|
898
|
-
toolName: contentBlock.toolName,
|
|
899
|
-
argsTextDelta: value.delta.partial_json
|
|
1403
|
+
const contentBlock = contentBlocks[value.index];
|
|
1404
|
+
const delta = value.delta.partial_json;
|
|
1405
|
+
if (jsonResponseTool == null) {
|
|
1406
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
|
|
1407
|
+
return;
|
|
900
1408
|
}
|
|
1409
|
+
controller.enqueue({
|
|
1410
|
+
type: "tool-input-delta",
|
|
1411
|
+
id: contentBlock.toolCallId,
|
|
1412
|
+
delta
|
|
1413
|
+
});
|
|
1414
|
+
contentBlock.input += delta;
|
|
1415
|
+
} else {
|
|
1416
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
1419
|
+
controller.enqueue({
|
|
1420
|
+
type: "tool-input-delta",
|
|
1421
|
+
id: contentBlock.toolCallId,
|
|
1422
|
+
delta
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
case "citations_delta": {
|
|
1428
|
+
const citation = value.delta.citation;
|
|
1429
|
+
processCitation(
|
|
1430
|
+
citation,
|
|
1431
|
+
citationDocuments,
|
|
1432
|
+
generateId3,
|
|
1433
|
+
(source) => controller.enqueue(source)
|
|
901
1434
|
);
|
|
902
|
-
contentBlock.jsonText += value.delta.partial_json;
|
|
903
1435
|
return;
|
|
904
1436
|
}
|
|
905
1437
|
default: {
|
|
@@ -912,22 +1444,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
912
1444
|
}
|
|
913
1445
|
case "message_start": {
|
|
914
1446
|
usage.inputTokens = value.message.usage.input_tokens;
|
|
915
|
-
usage.cachedInputTokens = (
|
|
1447
|
+
usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
|
|
916
1448
|
providerMetadata = {
|
|
917
1449
|
anthropic: {
|
|
918
|
-
cacheCreationInputTokens: (
|
|
1450
|
+
cacheCreationInputTokens: (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null
|
|
919
1451
|
}
|
|
920
1452
|
};
|
|
921
1453
|
controller.enqueue({
|
|
922
1454
|
type: "response-metadata",
|
|
923
|
-
id: (
|
|
924
|
-
modelId: (
|
|
1455
|
+
id: (_d = value.message.id) != null ? _d : void 0,
|
|
1456
|
+
modelId: (_e = value.message.model) != null ? _e : void 0
|
|
925
1457
|
});
|
|
926
1458
|
return;
|
|
927
1459
|
}
|
|
928
1460
|
case "message_delta": {
|
|
929
1461
|
usage.outputTokens = value.usage.output_tokens;
|
|
930
|
-
usage.totalTokens = ((
|
|
1462
|
+
usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
|
|
931
1463
|
finishReason = mapAnthropicStopReason({
|
|
932
1464
|
finishReason: value.delta.stop_reason,
|
|
933
1465
|
isJsonResponseFromTool: jsonResponseTool != null
|
|
@@ -968,7 +1500,8 @@ var anthropicMessagesResponseSchema = import_zod3.z.object({
|
|
|
968
1500
|
import_zod3.z.discriminatedUnion("type", [
|
|
969
1501
|
import_zod3.z.object({
|
|
970
1502
|
type: import_zod3.z.literal("text"),
|
|
971
|
-
text: import_zod3.z.string()
|
|
1503
|
+
text: import_zod3.z.string(),
|
|
1504
|
+
citations: import_zod3.z.array(citationSchema).optional()
|
|
972
1505
|
}),
|
|
973
1506
|
import_zod3.z.object({
|
|
974
1507
|
type: import_zod3.z.literal("thinking"),
|
|
@@ -984,6 +1517,31 @@ var anthropicMessagesResponseSchema = import_zod3.z.object({
|
|
|
984
1517
|
id: import_zod3.z.string(),
|
|
985
1518
|
name: import_zod3.z.string(),
|
|
986
1519
|
input: import_zod3.z.unknown()
|
|
1520
|
+
}),
|
|
1521
|
+
import_zod3.z.object({
|
|
1522
|
+
type: import_zod3.z.literal("server_tool_use"),
|
|
1523
|
+
id: import_zod3.z.string(),
|
|
1524
|
+
name: import_zod3.z.string(),
|
|
1525
|
+
input: import_zod3.z.record(import_zod3.z.unknown()).nullish()
|
|
1526
|
+
}),
|
|
1527
|
+
import_zod3.z.object({
|
|
1528
|
+
type: import_zod3.z.literal("web_search_tool_result"),
|
|
1529
|
+
tool_use_id: import_zod3.z.string(),
|
|
1530
|
+
content: import_zod3.z.union([
|
|
1531
|
+
import_zod3.z.array(
|
|
1532
|
+
import_zod3.z.object({
|
|
1533
|
+
type: import_zod3.z.literal("web_search_result"),
|
|
1534
|
+
url: import_zod3.z.string(),
|
|
1535
|
+
title: import_zod3.z.string(),
|
|
1536
|
+
encrypted_content: import_zod3.z.string(),
|
|
1537
|
+
page_age: import_zod3.z.string().nullish()
|
|
1538
|
+
})
|
|
1539
|
+
),
|
|
1540
|
+
import_zod3.z.object({
|
|
1541
|
+
type: import_zod3.z.literal("web_search_tool_result_error"),
|
|
1542
|
+
error_code: import_zod3.z.string()
|
|
1543
|
+
})
|
|
1544
|
+
])
|
|
987
1545
|
})
|
|
988
1546
|
])
|
|
989
1547
|
),
|
|
@@ -992,7 +1550,10 @@ var anthropicMessagesResponseSchema = import_zod3.z.object({
|
|
|
992
1550
|
input_tokens: import_zod3.z.number(),
|
|
993
1551
|
output_tokens: import_zod3.z.number(),
|
|
994
1552
|
cache_creation_input_tokens: import_zod3.z.number().nullish(),
|
|
995
|
-
cache_read_input_tokens: import_zod3.z.number().nullish()
|
|
1553
|
+
cache_read_input_tokens: import_zod3.z.number().nullish(),
|
|
1554
|
+
server_tool_use: import_zod3.z.object({
|
|
1555
|
+
web_search_requests: import_zod3.z.number()
|
|
1556
|
+
}).nullish()
|
|
996
1557
|
})
|
|
997
1558
|
});
|
|
998
1559
|
var anthropicMessagesChunkSchema = import_zod3.z.discriminatedUnion("type", [
|
|
@@ -1029,6 +1590,31 @@ var anthropicMessagesChunkSchema = import_zod3.z.discriminatedUnion("type", [
|
|
|
1029
1590
|
import_zod3.z.object({
|
|
1030
1591
|
type: import_zod3.z.literal("redacted_thinking"),
|
|
1031
1592
|
data: import_zod3.z.string()
|
|
1593
|
+
}),
|
|
1594
|
+
import_zod3.z.object({
|
|
1595
|
+
type: import_zod3.z.literal("server_tool_use"),
|
|
1596
|
+
id: import_zod3.z.string(),
|
|
1597
|
+
name: import_zod3.z.string(),
|
|
1598
|
+
input: import_zod3.z.record(import_zod3.z.unknown()).nullish()
|
|
1599
|
+
}),
|
|
1600
|
+
import_zod3.z.object({
|
|
1601
|
+
type: import_zod3.z.literal("web_search_tool_result"),
|
|
1602
|
+
tool_use_id: import_zod3.z.string(),
|
|
1603
|
+
content: import_zod3.z.union([
|
|
1604
|
+
import_zod3.z.array(
|
|
1605
|
+
import_zod3.z.object({
|
|
1606
|
+
type: import_zod3.z.literal("web_search_result"),
|
|
1607
|
+
url: import_zod3.z.string(),
|
|
1608
|
+
title: import_zod3.z.string(),
|
|
1609
|
+
encrypted_content: import_zod3.z.string(),
|
|
1610
|
+
page_age: import_zod3.z.string().nullish()
|
|
1611
|
+
})
|
|
1612
|
+
),
|
|
1613
|
+
import_zod3.z.object({
|
|
1614
|
+
type: import_zod3.z.literal("web_search_tool_result_error"),
|
|
1615
|
+
error_code: import_zod3.z.string()
|
|
1616
|
+
})
|
|
1617
|
+
])
|
|
1032
1618
|
})
|
|
1033
1619
|
])
|
|
1034
1620
|
}),
|
|
@@ -1051,6 +1637,10 @@ var anthropicMessagesChunkSchema = import_zod3.z.discriminatedUnion("type", [
|
|
|
1051
1637
|
import_zod3.z.object({
|
|
1052
1638
|
type: import_zod3.z.literal("signature_delta"),
|
|
1053
1639
|
signature: import_zod3.z.string()
|
|
1640
|
+
}),
|
|
1641
|
+
import_zod3.z.object({
|
|
1642
|
+
type: import_zod3.z.literal("citations_delta"),
|
|
1643
|
+
citation: citationSchema
|
|
1054
1644
|
})
|
|
1055
1645
|
])
|
|
1056
1646
|
}),
|
|
@@ -1082,175 +1672,207 @@ var anthropicReasoningMetadataSchema = import_zod3.z.object({
|
|
|
1082
1672
|
redactedData: import_zod3.z.string().optional()
|
|
1083
1673
|
});
|
|
1084
1674
|
|
|
1085
|
-
// src/
|
|
1086
|
-
var
|
|
1087
|
-
var
|
|
1088
|
-
|
|
1089
|
-
|
|
1675
|
+
// src/tool/bash_20241022.ts
|
|
1676
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
1677
|
+
var import_v42 = __toESM(require("zod/v4"));
|
|
1678
|
+
var bash_20241022 = (0, import_provider_utils5.createProviderDefinedToolFactory)({
|
|
1679
|
+
id: "anthropic.bash_20241022",
|
|
1680
|
+
name: "bash",
|
|
1681
|
+
inputSchema: import_v42.default.object({
|
|
1682
|
+
command: import_v42.default.string(),
|
|
1683
|
+
restart: import_v42.default.boolean().optional()
|
|
1684
|
+
})
|
|
1090
1685
|
});
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
command: import_zod4.z.string(),
|
|
1103
|
-
restart: import_zod4.z.boolean().optional()
|
|
1686
|
+
|
|
1687
|
+
// src/tool/bash_20250124.ts
|
|
1688
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
1689
|
+
var import_v43 = __toESM(require("zod/v4"));
|
|
1690
|
+
var bash_20250124 = (0, import_provider_utils6.createProviderDefinedToolFactory)({
|
|
1691
|
+
id: "anthropic.bashTool_20250124",
|
|
1692
|
+
name: "bash",
|
|
1693
|
+
inputSchema: import_v43.default.object({
|
|
1694
|
+
command: import_v43.default.string(),
|
|
1695
|
+
restart: import_v43.default.boolean().optional()
|
|
1696
|
+
})
|
|
1104
1697
|
});
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1698
|
+
|
|
1699
|
+
// src/tool/computer_20241022.ts
|
|
1700
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1701
|
+
var import_v44 = require("zod/v4");
|
|
1702
|
+
var computer_20241022 = (0, import_provider_utils7.createProviderDefinedToolFactory)({
|
|
1703
|
+
id: "anthropic.computer_20241022",
|
|
1704
|
+
name: "computer",
|
|
1705
|
+
inputSchema: import_v44.z.object({
|
|
1706
|
+
action: import_v44.z.enum([
|
|
1707
|
+
"key",
|
|
1708
|
+
"type",
|
|
1709
|
+
"mouse_move",
|
|
1710
|
+
"left_click",
|
|
1711
|
+
"left_click_drag",
|
|
1712
|
+
"right_click",
|
|
1713
|
+
"middle_click",
|
|
1714
|
+
"double_click",
|
|
1715
|
+
"screenshot",
|
|
1716
|
+
"cursor_position"
|
|
1717
|
+
]),
|
|
1718
|
+
coordinate: import_v44.z.array(import_v44.z.number().int()).optional(),
|
|
1719
|
+
text: import_v44.z.string().optional()
|
|
1720
|
+
})
|
|
1123
1721
|
});
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1722
|
+
|
|
1723
|
+
// src/tool/computer_20250124.ts
|
|
1724
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
1725
|
+
var import_v45 = require("zod/v4");
|
|
1726
|
+
var computer_20250124 = (0, import_provider_utils8.createProviderDefinedToolFactory)({
|
|
1727
|
+
id: "anthropic.computer_20250124",
|
|
1728
|
+
name: "computer",
|
|
1729
|
+
inputSchema: import_v45.z.object({
|
|
1730
|
+
action: import_v45.z.enum([
|
|
1731
|
+
"key",
|
|
1732
|
+
"hold_key",
|
|
1733
|
+
"type",
|
|
1734
|
+
"cursor_position",
|
|
1735
|
+
"mouse_move",
|
|
1736
|
+
"left_mouse_down",
|
|
1737
|
+
"left_mouse_up",
|
|
1738
|
+
"left_click",
|
|
1739
|
+
"left_click_drag",
|
|
1740
|
+
"right_click",
|
|
1741
|
+
"middle_click",
|
|
1742
|
+
"double_click",
|
|
1743
|
+
"triple_click",
|
|
1744
|
+
"scroll",
|
|
1745
|
+
"wait",
|
|
1746
|
+
"screenshot"
|
|
1747
|
+
]),
|
|
1748
|
+
coordinate: import_v45.z.tuple([import_v45.z.number().int(), import_v45.z.number().int()]).optional(),
|
|
1749
|
+
duration: import_v45.z.number().optional(),
|
|
1750
|
+
scroll_amount: import_v45.z.number().optional(),
|
|
1751
|
+
scroll_direction: import_v45.z.enum(["up", "down", "left", "right"]).optional(),
|
|
1752
|
+
start_coordinate: import_v45.z.tuple([import_v45.z.number().int(), import_v45.z.number().int()]).optional(),
|
|
1753
|
+
text: import_v45.z.string().optional()
|
|
1754
|
+
})
|
|
1142
1755
|
});
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
"left_click_drag",
|
|
1160
|
-
"right_click",
|
|
1161
|
-
"middle_click",
|
|
1162
|
-
"double_click",
|
|
1163
|
-
"screenshot",
|
|
1164
|
-
"cursor_position"
|
|
1165
|
-
]),
|
|
1166
|
-
coordinate: import_zod4.z.array(import_zod4.z.number().int()).optional(),
|
|
1167
|
-
text: import_zod4.z.string().optional()
|
|
1756
|
+
|
|
1757
|
+
// src/tool/text-editor_20241022.ts
|
|
1758
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
|
1759
|
+
var import_v46 = require("zod/v4");
|
|
1760
|
+
var textEditor_20241022 = (0, import_provider_utils9.createProviderDefinedToolFactory)({
|
|
1761
|
+
id: "anthropic.text_editor_20241022",
|
|
1762
|
+
name: "str_replace_editor",
|
|
1763
|
+
inputSchema: import_v46.z.object({
|
|
1764
|
+
command: import_v46.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
1765
|
+
path: import_v46.z.string(),
|
|
1766
|
+
file_text: import_v46.z.string().optional(),
|
|
1767
|
+
insert_line: import_v46.z.number().int().optional(),
|
|
1768
|
+
new_str: import_v46.z.string().optional(),
|
|
1769
|
+
old_str: import_v46.z.string().optional(),
|
|
1770
|
+
view_range: import_v46.z.array(import_v46.z.number().int()).optional()
|
|
1771
|
+
})
|
|
1168
1772
|
});
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
"key",
|
|
1186
|
-
"hold_key",
|
|
1187
|
-
"type",
|
|
1188
|
-
"cursor_position",
|
|
1189
|
-
"mouse_move",
|
|
1190
|
-
"left_mouse_down",
|
|
1191
|
-
"left_mouse_up",
|
|
1192
|
-
"left_click",
|
|
1193
|
-
"left_click_drag",
|
|
1194
|
-
"right_click",
|
|
1195
|
-
"middle_click",
|
|
1196
|
-
"double_click",
|
|
1197
|
-
"triple_click",
|
|
1198
|
-
"scroll",
|
|
1199
|
-
"wait",
|
|
1200
|
-
"screenshot"
|
|
1201
|
-
]),
|
|
1202
|
-
coordinate: import_zod4.z.tuple([import_zod4.z.number().int(), import_zod4.z.number().int()]).optional(),
|
|
1203
|
-
duration: import_zod4.z.number().optional(),
|
|
1204
|
-
scroll_amount: import_zod4.z.number().optional(),
|
|
1205
|
-
scroll_direction: import_zod4.z.enum(["up", "down", "left", "right"]).optional(),
|
|
1206
|
-
start_coordinate: import_zod4.z.tuple([import_zod4.z.number().int(), import_zod4.z.number().int()]).optional(),
|
|
1207
|
-
text: import_zod4.z.string().optional()
|
|
1773
|
+
|
|
1774
|
+
// src/tool/text-editor_20250124.ts
|
|
1775
|
+
var import_provider_utils10 = require("@ai-sdk/provider-utils");
|
|
1776
|
+
var import_v47 = require("zod/v4");
|
|
1777
|
+
var textEditor_20250124 = (0, import_provider_utils10.createProviderDefinedToolFactory)({
|
|
1778
|
+
id: "anthropic.text_editor_20250124",
|
|
1779
|
+
name: "str_replace_editor",
|
|
1780
|
+
inputSchema: import_v47.z.object({
|
|
1781
|
+
command: import_v47.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
1782
|
+
path: import_v47.z.string(),
|
|
1783
|
+
file_text: import_v47.z.string().optional(),
|
|
1784
|
+
insert_line: import_v47.z.number().int().optional(),
|
|
1785
|
+
new_str: import_v47.z.string().optional(),
|
|
1786
|
+
old_str: import_v47.z.string().optional(),
|
|
1787
|
+
view_range: import_v47.z.array(import_v47.z.number().int()).optional()
|
|
1788
|
+
})
|
|
1208
1789
|
});
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
type: "provider-defined",
|
|
1212
|
-
id: "anthropic.computer_20250124",
|
|
1213
|
-
args: {
|
|
1214
|
-
displayWidthPx: options.displayWidthPx,
|
|
1215
|
-
displayHeightPx: options.displayHeightPx,
|
|
1216
|
-
displayNumber: options.displayNumber
|
|
1217
|
-
},
|
|
1218
|
-
parameters: Computer20250124Parameters,
|
|
1219
|
-
execute: options.execute,
|
|
1220
|
-
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1221
|
-
};
|
|
1222
|
-
}
|
|
1790
|
+
|
|
1791
|
+
// src/anthropic-tools.ts
|
|
1223
1792
|
var anthropicTools = {
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1793
|
+
/**
|
|
1794
|
+
* Creates a tool for running a bash command. Must have name "bash".
|
|
1795
|
+
*
|
|
1796
|
+
* Image results are supported.
|
|
1797
|
+
*
|
|
1798
|
+
* @param execute - The function to execute the tool. Optional.
|
|
1799
|
+
*/
|
|
1800
|
+
bash_20241022,
|
|
1801
|
+
/**
|
|
1802
|
+
* Creates a tool for running a bash command. Must have name "bash".
|
|
1803
|
+
*
|
|
1804
|
+
* Image results are supported.
|
|
1805
|
+
*
|
|
1806
|
+
* @param execute - The function to execute the tool. Optional.
|
|
1807
|
+
*/
|
|
1808
|
+
bash_20250124,
|
|
1809
|
+
/**
|
|
1810
|
+
* Creates a tool for editing text. Must have name "str_replace_editor".
|
|
1811
|
+
*/
|
|
1812
|
+
textEditor_20241022,
|
|
1813
|
+
/**
|
|
1814
|
+
* Creates a tool for editing text. Must have name "str_replace_editor".
|
|
1815
|
+
*/
|
|
1816
|
+
textEditor_20250124,
|
|
1817
|
+
/**
|
|
1818
|
+
* Creates a tool for executing actions on a computer. Must have name "computer".
|
|
1819
|
+
*
|
|
1820
|
+
* Image results are supported.
|
|
1821
|
+
*
|
|
1822
|
+
* @param displayWidthPx - The width of the display being controlled by the model in pixels.
|
|
1823
|
+
* @param displayHeightPx - The height of the display being controlled by the model in pixels.
|
|
1824
|
+
* @param displayNumber - The display number to control (only relevant for X11 environments). If specified, the tool will be provided a display number in the tool definition.
|
|
1825
|
+
*/
|
|
1826
|
+
computer_20241022,
|
|
1827
|
+
/**
|
|
1828
|
+
* Creates a tool for executing actions on a computer. Must have name "computer".
|
|
1829
|
+
*
|
|
1830
|
+
* Image results are supported.
|
|
1831
|
+
*
|
|
1832
|
+
* @param displayWidthPx - The width of the display being controlled by the model in pixels.
|
|
1833
|
+
* @param displayHeightPx - The height of the display being controlled by the model in pixels.
|
|
1834
|
+
* @param displayNumber - The display number to control (only relevant for X11 environments). If specified, the tool will be provided a display number in the tool definition.
|
|
1835
|
+
* @param execute - The function to execute the tool. Optional.
|
|
1836
|
+
*/
|
|
1837
|
+
computer_20250124,
|
|
1838
|
+
/**
|
|
1839
|
+
* Creates a web search tool that gives Claude direct access to real-time web content.
|
|
1840
|
+
* Must have name "web_search".
|
|
1841
|
+
*
|
|
1842
|
+
* @param maxUses - Maximum number of web searches Claude can perform during the conversation.
|
|
1843
|
+
* @param allowedDomains - Optional list of domains that Claude is allowed to search.
|
|
1844
|
+
* @param blockedDomains - Optional list of domains that Claude should avoid when searching.
|
|
1845
|
+
* @param userLocation - Optional user location information to provide geographically relevant search results.
|
|
1846
|
+
*/
|
|
1847
|
+
webSearch_20250305
|
|
1230
1848
|
};
|
|
1231
1849
|
|
|
1232
1850
|
// src/anthropic-provider.ts
|
|
1233
1851
|
function createAnthropic(options = {}) {
|
|
1234
1852
|
var _a;
|
|
1235
|
-
const baseURL = (_a = (0,
|
|
1853
|
+
const baseURL = (_a = (0, import_provider_utils11.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.anthropic.com/v1";
|
|
1236
1854
|
const getHeaders = () => ({
|
|
1237
1855
|
"anthropic-version": "2023-06-01",
|
|
1238
|
-
"x-api-key": (0,
|
|
1856
|
+
"x-api-key": (0, import_provider_utils11.loadApiKey)({
|
|
1239
1857
|
apiKey: options.apiKey,
|
|
1240
1858
|
environmentVariableName: "ANTHROPIC_API_KEY",
|
|
1241
1859
|
description: "Anthropic"
|
|
1242
1860
|
}),
|
|
1243
1861
|
...options.headers
|
|
1244
1862
|
});
|
|
1245
|
-
const createChatModel = (modelId) =>
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1863
|
+
const createChatModel = (modelId) => {
|
|
1864
|
+
var _a2;
|
|
1865
|
+
return new AnthropicMessagesLanguageModel(modelId, {
|
|
1866
|
+
provider: "anthropic.messages",
|
|
1867
|
+
baseURL,
|
|
1868
|
+
headers: getHeaders,
|
|
1869
|
+
fetch: options.fetch,
|
|
1870
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils11.generateId,
|
|
1871
|
+
supportedUrls: () => ({
|
|
1872
|
+
"image/*": [/^https?:\/\/.*$/]
|
|
1873
|
+
})
|
|
1874
|
+
});
|
|
1875
|
+
};
|
|
1254
1876
|
const provider = function(modelId) {
|
|
1255
1877
|
if (new.target) {
|
|
1256
1878
|
throw new Error(
|