@ai-sdk/anthropic 2.0.0-alpha.9 → 2.0.0-beta.2
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 +91 -0
- package/dist/index.d.mts +104 -457
- package/dist/index.d.ts +104 -457
- package/dist/index.js +759 -340
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +865 -457
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +105 -364
- package/dist/internal/index.d.ts +105 -364
- package/dist/internal/index.js +755 -336
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +865 -457
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
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,53 +61,89 @@ 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
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
var anthropicFilePartProviderOptions = import_zod2.z.object({
|
|
65
|
+
/**
|
|
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()
|
|
60
86
|
});
|
|
61
87
|
var anthropicProviderOptions = import_zod2.z.object({
|
|
62
|
-
/**
|
|
63
|
-
Include reasoning content in requests sent to the model. Defaults to `true`.
|
|
64
|
-
|
|
65
|
-
If you are experiencing issues with the model handling requests involving
|
|
66
|
-
*/
|
|
67
88
|
sendReasoning: import_zod2.z.boolean().optional(),
|
|
68
89
|
thinking: import_zod2.z.object({
|
|
69
90
|
type: import_zod2.z.union([import_zod2.z.literal("enabled"), import_zod2.z.literal("disabled")]),
|
|
70
91
|
budgetTokens: import_zod2.z.number().optional()
|
|
71
|
-
}).optional()
|
|
92
|
+
}).optional()
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// src/anthropic-prepare-tools.ts
|
|
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({
|
|
72
102
|
/**
|
|
73
|
-
*
|
|
74
|
-
* When provided, automatically adds the web search tool to the request.
|
|
103
|
+
* Maximum number of web searches Claude can perform during the conversation.
|
|
75
104
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
*/
|
|
95
|
-
userLocation: webSearchLocationSchema.optional()
|
|
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()
|
|
96
123
|
}).optional()
|
|
97
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
|
+
};
|
|
98
145
|
|
|
99
146
|
// src/anthropic-prepare-tools.ts
|
|
100
|
-
var import_provider = require("@ai-sdk/provider");
|
|
101
147
|
function isWebSearchTool(tool) {
|
|
102
148
|
return typeof tool === "object" && tool !== null && "type" in tool && tool.type === "web_search_20250305";
|
|
103
149
|
}
|
|
@@ -122,7 +168,7 @@ function prepareTools({
|
|
|
122
168
|
anthropicTools2.push({
|
|
123
169
|
name: tool.name,
|
|
124
170
|
description: tool.description,
|
|
125
|
-
input_schema: tool.
|
|
171
|
+
input_schema: tool.inputSchema
|
|
126
172
|
});
|
|
127
173
|
break;
|
|
128
174
|
case "provider-defined":
|
|
@@ -130,7 +176,7 @@ function prepareTools({
|
|
|
130
176
|
case "anthropic.computer_20250124":
|
|
131
177
|
betas.add("computer-use-2025-01-24");
|
|
132
178
|
anthropicTools2.push({
|
|
133
|
-
name:
|
|
179
|
+
name: "computer",
|
|
134
180
|
type: "computer_20250124",
|
|
135
181
|
display_width_px: tool.args.displayWidthPx,
|
|
136
182
|
display_height_px: tool.args.displayHeightPx,
|
|
@@ -140,7 +186,7 @@ function prepareTools({
|
|
|
140
186
|
case "anthropic.computer_20241022":
|
|
141
187
|
betas.add("computer-use-2024-10-22");
|
|
142
188
|
anthropicTools2.push({
|
|
143
|
-
name:
|
|
189
|
+
name: "computer",
|
|
144
190
|
type: "computer_20241022",
|
|
145
191
|
display_width_px: tool.args.displayWidthPx,
|
|
146
192
|
display_height_px: tool.args.displayHeightPx,
|
|
@@ -150,31 +196,43 @@ function prepareTools({
|
|
|
150
196
|
case "anthropic.text_editor_20250124":
|
|
151
197
|
betas.add("computer-use-2025-01-24");
|
|
152
198
|
anthropicTools2.push({
|
|
153
|
-
name:
|
|
199
|
+
name: "str_replace_editor",
|
|
154
200
|
type: "text_editor_20250124"
|
|
155
201
|
});
|
|
156
202
|
break;
|
|
157
203
|
case "anthropic.text_editor_20241022":
|
|
158
204
|
betas.add("computer-use-2024-10-22");
|
|
159
205
|
anthropicTools2.push({
|
|
160
|
-
name:
|
|
206
|
+
name: "str_replace_editor",
|
|
161
207
|
type: "text_editor_20241022"
|
|
162
208
|
});
|
|
163
209
|
break;
|
|
164
210
|
case "anthropic.bash_20250124":
|
|
165
211
|
betas.add("computer-use-2025-01-24");
|
|
166
212
|
anthropicTools2.push({
|
|
167
|
-
name:
|
|
213
|
+
name: "bash",
|
|
168
214
|
type: "bash_20250124"
|
|
169
215
|
});
|
|
170
216
|
break;
|
|
171
217
|
case "anthropic.bash_20241022":
|
|
172
218
|
betas.add("computer-use-2024-10-22");
|
|
173
219
|
anthropicTools2.push({
|
|
174
|
-
name:
|
|
220
|
+
name: "bash",
|
|
175
221
|
type: "bash_20241022"
|
|
176
222
|
});
|
|
177
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
|
+
}
|
|
178
236
|
default:
|
|
179
237
|
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
180
238
|
break;
|
|
@@ -229,13 +287,29 @@ function prepareTools({
|
|
|
229
287
|
|
|
230
288
|
// src/convert-to-anthropic-messages-prompt.ts
|
|
231
289
|
var import_provider2 = require("@ai-sdk/provider");
|
|
232
|
-
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
|
+
}
|
|
233
307
|
async function convertToAnthropicMessagesPrompt({
|
|
234
308
|
prompt,
|
|
235
309
|
sendReasoning,
|
|
236
310
|
warnings
|
|
237
311
|
}) {
|
|
238
|
-
var _a, _b, _c;
|
|
312
|
+
var _a, _b, _c, _d, _e;
|
|
239
313
|
const betas = /* @__PURE__ */ new Set();
|
|
240
314
|
const blocks = groupIntoBlocks(prompt);
|
|
241
315
|
let system = void 0;
|
|
@@ -246,6 +320,26 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
246
320
|
const cacheControlValue = (_a2 = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ? _a2 : anthropic2 == null ? void 0 : anthropic2.cache_control;
|
|
247
321
|
return cacheControlValue;
|
|
248
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
|
+
}
|
|
249
343
|
for (let i = 0; i < blocks.length; i++) {
|
|
250
344
|
const block = blocks[i];
|
|
251
345
|
const isLastBlock = i === blocks.length - 1;
|
|
@@ -293,12 +387,18 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
293
387
|
} : {
|
|
294
388
|
type: "base64",
|
|
295
389
|
media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
|
|
296
|
-
data: (0,
|
|
390
|
+
data: (0, import_provider_utils3.convertToBase64)(part.data)
|
|
297
391
|
},
|
|
298
392
|
cache_control: cacheControl
|
|
299
393
|
});
|
|
300
394
|
} else if (part.mediaType === "application/pdf") {
|
|
301
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
|
+
);
|
|
302
402
|
anthropicContent.push({
|
|
303
403
|
type: "document",
|
|
304
404
|
source: part.data instanceof URL ? {
|
|
@@ -307,7 +407,36 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
307
407
|
} : {
|
|
308
408
|
type: "base64",
|
|
309
409
|
media_type: "application/pdf",
|
|
310
|
-
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 }
|
|
311
440
|
},
|
|
312
441
|
cache_control: cacheControl
|
|
313
442
|
});
|
|
@@ -326,33 +455,53 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
326
455
|
for (let i2 = 0; i2 < content.length; i2++) {
|
|
327
456
|
const part = content[i2];
|
|
328
457
|
const isLastPart = i2 === content.length - 1;
|
|
329
|
-
const cacheControl = (
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
text:
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
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
|
+
}
|
|
351
500
|
anthropicContent.push({
|
|
352
501
|
type: "tool_result",
|
|
353
502
|
tool_use_id: part.toolCallId,
|
|
354
|
-
content:
|
|
355
|
-
is_error:
|
|
503
|
+
content: contentValue,
|
|
504
|
+
is_error: output.type === "error-text" || output.type === "error-json" ? true : void 0,
|
|
356
505
|
cache_control: cacheControl
|
|
357
506
|
});
|
|
358
507
|
}
|
|
@@ -376,7 +525,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
376
525
|
for (let k = 0; k < content.length; k++) {
|
|
377
526
|
const part = content[k];
|
|
378
527
|
const isLastContentPart = k === content.length - 1;
|
|
379
|
-
const cacheControl = (
|
|
528
|
+
const cacheControl = (_e = getCacheControl(part.providerOptions)) != null ? _e : isLastContentPart ? getCacheControl(message.providerOptions) : void 0;
|
|
380
529
|
switch (part.type) {
|
|
381
530
|
case "text": {
|
|
382
531
|
anthropicContent.push({
|
|
@@ -393,7 +542,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
393
542
|
}
|
|
394
543
|
case "reasoning": {
|
|
395
544
|
if (sendReasoning) {
|
|
396
|
-
const reasoningMetadata = await (0,
|
|
545
|
+
const reasoningMetadata = await (0, import_provider_utils3.parseProviderOptions)({
|
|
397
546
|
provider: "anthropic",
|
|
398
547
|
providerOptions: part.providerOptions,
|
|
399
548
|
schema: anthropicReasoningMetadataSchema
|
|
@@ -433,15 +582,65 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
433
582
|
break;
|
|
434
583
|
}
|
|
435
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
|
+
}
|
|
436
602
|
anthropicContent.push({
|
|
437
603
|
type: "tool_use",
|
|
438
604
|
id: part.toolCallId,
|
|
439
605
|
name: part.toolName,
|
|
440
|
-
input: part.
|
|
606
|
+
input: part.input,
|
|
441
607
|
cache_control: cacheControl
|
|
442
608
|
});
|
|
443
609
|
break;
|
|
444
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
|
+
}
|
|
445
644
|
}
|
|
446
645
|
}
|
|
447
646
|
}
|
|
@@ -525,13 +724,86 @@ function mapAnthropicStopReason({
|
|
|
525
724
|
}
|
|
526
725
|
|
|
527
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
|
+
}
|
|
528
800
|
var AnthropicMessagesLanguageModel = class {
|
|
529
801
|
constructor(modelId, config) {
|
|
530
802
|
this.specificationVersion = "v2";
|
|
531
803
|
var _a;
|
|
532
804
|
this.modelId = modelId;
|
|
533
805
|
this.config = config;
|
|
534
|
-
this.generateId = (_a = config.generateId) != null ? _a :
|
|
806
|
+
this.generateId = (_a = config.generateId) != null ? _a : import_provider_utils4.generateId;
|
|
535
807
|
}
|
|
536
808
|
supportsUrl(url) {
|
|
537
809
|
return url.protocol === "https:";
|
|
@@ -598,9 +870,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
598
870
|
type: "function",
|
|
599
871
|
name: "json",
|
|
600
872
|
description: "Respond with a JSON object.",
|
|
601
|
-
|
|
873
|
+
inputSchema: responseFormat.schema
|
|
602
874
|
} : void 0;
|
|
603
|
-
const anthropicOptions = await (0,
|
|
875
|
+
const anthropicOptions = await (0, import_provider_utils4.parseProviderOptions)({
|
|
604
876
|
provider: "anthropic",
|
|
605
877
|
providerOptions,
|
|
606
878
|
schema: anthropicProviderOptions
|
|
@@ -661,27 +933,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
661
933
|
}
|
|
662
934
|
baseArgs.max_tokens = maxOutputTokens + thinkingBudget;
|
|
663
935
|
}
|
|
664
|
-
let modifiedTools = tools;
|
|
665
|
-
let modifiedToolChoice = toolChoice;
|
|
666
|
-
if (anthropicOptions == null ? void 0 : anthropicOptions.webSearch) {
|
|
667
|
-
const webSearchTool = {
|
|
668
|
-
type: "web_search_20250305",
|
|
669
|
-
name: "web_search",
|
|
670
|
-
max_uses: anthropicOptions.webSearch.maxUses,
|
|
671
|
-
allowed_domains: anthropicOptions.webSearch.allowedDomains,
|
|
672
|
-
blocked_domains: anthropicOptions.webSearch.blockedDomains,
|
|
673
|
-
...anthropicOptions.webSearch.userLocation && {
|
|
674
|
-
user_location: {
|
|
675
|
-
type: anthropicOptions.webSearch.userLocation.type,
|
|
676
|
-
country: anthropicOptions.webSearch.userLocation.country,
|
|
677
|
-
city: anthropicOptions.webSearch.userLocation.city,
|
|
678
|
-
region: anthropicOptions.webSearch.userLocation.region,
|
|
679
|
-
timezone: anthropicOptions.webSearch.userLocation.timezone
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
};
|
|
683
|
-
modifiedTools = tools ? [...tools, webSearchTool] : [webSearchTool];
|
|
684
|
-
}
|
|
685
936
|
const {
|
|
686
937
|
tools: anthropicTools2,
|
|
687
938
|
toolChoice: anthropicToolChoice,
|
|
@@ -691,7 +942,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
691
942
|
jsonResponseTool != null ? {
|
|
692
943
|
tools: [jsonResponseTool],
|
|
693
944
|
toolChoice: { type: "tool", toolName: jsonResponseTool.name }
|
|
694
|
-
} : { tools:
|
|
945
|
+
} : { tools: tools != null ? tools : [], toolChoice }
|
|
695
946
|
);
|
|
696
947
|
return {
|
|
697
948
|
args: {
|
|
@@ -708,8 +959,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
708
959
|
betas,
|
|
709
960
|
headers
|
|
710
961
|
}) {
|
|
711
|
-
return (0,
|
|
712
|
-
await (0,
|
|
962
|
+
return (0, import_provider_utils4.combineHeaders)(
|
|
963
|
+
await (0, import_provider_utils4.resolve)(this.config.headers),
|
|
713
964
|
betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {},
|
|
714
965
|
headers
|
|
715
966
|
);
|
|
@@ -722,19 +973,43 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
722
973
|
var _a, _b, _c;
|
|
723
974
|
return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args)) != null ? _c : args;
|
|
724
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
|
+
}
|
|
725
999
|
async doGenerate(options) {
|
|
726
1000
|
var _a, _b, _c, _d, _e;
|
|
727
1001
|
const { args, warnings, betas, jsonResponseTool } = await this.getArgs(options);
|
|
1002
|
+
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
728
1003
|
const {
|
|
729
1004
|
responseHeaders,
|
|
730
1005
|
value: response,
|
|
731
1006
|
rawValue: rawResponse
|
|
732
|
-
} = await (0,
|
|
1007
|
+
} = await (0, import_provider_utils4.postJsonToApi)({
|
|
733
1008
|
url: this.buildRequestUrl(false),
|
|
734
1009
|
headers: await this.getHeaders({ betas, headers: options.headers }),
|
|
735
1010
|
body: this.transformRequestBody(args),
|
|
736
1011
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
737
|
-
successfulResponseHandler: (0,
|
|
1012
|
+
successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
|
|
738
1013
|
anthropicMessagesResponseSchema
|
|
739
1014
|
),
|
|
740
1015
|
abortSignal: options.abortSignal,
|
|
@@ -746,6 +1021,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
746
1021
|
case "text": {
|
|
747
1022
|
if (jsonResponseTool == null) {
|
|
748
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
|
+
}
|
|
749
1034
|
}
|
|
750
1035
|
break;
|
|
751
1036
|
}
|
|
@@ -781,42 +1066,68 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
781
1066
|
text: JSON.stringify(part.input)
|
|
782
1067
|
} : {
|
|
783
1068
|
type: "tool-call",
|
|
784
|
-
toolCallType: "function",
|
|
785
1069
|
toolCallId: part.id,
|
|
786
1070
|
toolName: part.name,
|
|
787
|
-
|
|
1071
|
+
input: JSON.stringify(part.input)
|
|
788
1072
|
}
|
|
789
1073
|
);
|
|
790
1074
|
break;
|
|
791
1075
|
}
|
|
792
1076
|
case "server_tool_use": {
|
|
793
|
-
|
|
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;
|
|
794
1087
|
}
|
|
795
1088
|
case "web_search_tool_result": {
|
|
796
1089
|
if (Array.isArray(part.content)) {
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
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 {
|
|
803
1097
|
url: result.url,
|
|
804
1098
|
title: result.title,
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
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
|
|
810
1116
|
}
|
|
811
|
-
}
|
|
812
|
-
}
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
813
1119
|
}
|
|
814
|
-
} else
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
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
|
|
820
1131
|
});
|
|
821
1132
|
}
|
|
822
1133
|
break;
|
|
@@ -852,13 +1163,14 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
852
1163
|
}
|
|
853
1164
|
async doStream(options) {
|
|
854
1165
|
const { args, warnings, betas, jsonResponseTool } = await this.getArgs(options);
|
|
1166
|
+
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
855
1167
|
const body = { ...args, stream: true };
|
|
856
|
-
const { responseHeaders, value: response } = await (0,
|
|
1168
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
|
|
857
1169
|
url: this.buildRequestUrl(true),
|
|
858
1170
|
headers: await this.getHeaders({ betas, headers: options.headers }),
|
|
859
1171
|
body: this.transformRequestBody(body),
|
|
860
1172
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
861
|
-
successfulResponseHandler: (0,
|
|
1173
|
+
successfulResponseHandler: (0, import_provider_utils4.createEventSourceResponseHandler)(
|
|
862
1174
|
anthropicMessagesChunkSchema
|
|
863
1175
|
),
|
|
864
1176
|
abortSignal: options.abortSignal,
|
|
@@ -870,10 +1182,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
870
1182
|
outputTokens: void 0,
|
|
871
1183
|
totalTokens: void 0
|
|
872
1184
|
};
|
|
873
|
-
const
|
|
1185
|
+
const contentBlocks = {};
|
|
874
1186
|
let providerMetadata = void 0;
|
|
875
1187
|
let blockType = void 0;
|
|
876
|
-
const config = this.config;
|
|
877
1188
|
const generateId3 = this.generateId;
|
|
878
1189
|
return {
|
|
879
1190
|
stream: response.pipeThrough(
|
|
@@ -883,6 +1194,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
883
1194
|
},
|
|
884
1195
|
transform(chunk, controller) {
|
|
885
1196
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
1197
|
+
if (options.includeRawChunks) {
|
|
1198
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1199
|
+
}
|
|
886
1200
|
if (!chunk.success) {
|
|
887
1201
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
888
1202
|
return;
|
|
@@ -896,61 +1210,113 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
896
1210
|
const contentBlockType = value.content_block.type;
|
|
897
1211
|
blockType = contentBlockType;
|
|
898
1212
|
switch (contentBlockType) {
|
|
899
|
-
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
|
+
}
|
|
900
1221
|
case "thinking": {
|
|
1222
|
+
contentBlocks[value.index] = { type: "reasoning" };
|
|
1223
|
+
controller.enqueue({
|
|
1224
|
+
type: "reasoning-start",
|
|
1225
|
+
id: String(value.index)
|
|
1226
|
+
});
|
|
901
1227
|
return;
|
|
902
1228
|
}
|
|
903
1229
|
case "redacted_thinking": {
|
|
1230
|
+
contentBlocks[value.index] = { type: "reasoning" };
|
|
904
1231
|
controller.enqueue({
|
|
905
|
-
type: "reasoning",
|
|
906
|
-
|
|
1232
|
+
type: "reasoning-start",
|
|
1233
|
+
id: String(value.index),
|
|
907
1234
|
providerMetadata: {
|
|
908
1235
|
anthropic: {
|
|
909
1236
|
redactedData: value.content_block.data
|
|
910
1237
|
}
|
|
911
1238
|
}
|
|
912
1239
|
});
|
|
913
|
-
controller.enqueue({ type: "reasoning-part-finish" });
|
|
914
1240
|
return;
|
|
915
1241
|
}
|
|
916
1242
|
case "tool_use": {
|
|
917
|
-
|
|
1243
|
+
contentBlocks[value.index] = jsonResponseTool != null ? { type: "text" } : {
|
|
1244
|
+
type: "tool-call",
|
|
918
1245
|
toolCallId: value.content_block.id,
|
|
919
1246
|
toolName: value.content_block.name,
|
|
920
|
-
|
|
1247
|
+
input: ""
|
|
921
1248
|
};
|
|
1249
|
+
controller.enqueue(
|
|
1250
|
+
jsonResponseTool != null ? { type: "text-start", id: String(value.index) } : {
|
|
1251
|
+
type: "tool-input-start",
|
|
1252
|
+
id: value.content_block.id,
|
|
1253
|
+
toolName: value.content_block.name
|
|
1254
|
+
}
|
|
1255
|
+
);
|
|
922
1256
|
return;
|
|
923
1257
|
}
|
|
924
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
|
+
}
|
|
925
1274
|
return;
|
|
926
1275
|
}
|
|
927
1276
|
case "web_search_tool_result": {
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
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 {
|
|
935
1286
|
url: result.url,
|
|
936
1287
|
title: result.title,
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
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
|
|
942
1305
|
}
|
|
943
|
-
}
|
|
944
|
-
}
|
|
1306
|
+
}
|
|
1307
|
+
});
|
|
945
1308
|
}
|
|
946
|
-
} else
|
|
1309
|
+
} else {
|
|
947
1310
|
controller.enqueue({
|
|
948
|
-
type: "
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
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
|
|
954
1320
|
});
|
|
955
1321
|
}
|
|
956
1322
|
return;
|
|
@@ -964,18 +1330,34 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
964
1330
|
}
|
|
965
1331
|
}
|
|
966
1332
|
case "content_block_stop": {
|
|
967
|
-
if (
|
|
968
|
-
const contentBlock =
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
}
|
|
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;
|
|
977
1359
|
}
|
|
978
|
-
delete
|
|
1360
|
+
delete contentBlocks[value.index];
|
|
979
1361
|
}
|
|
980
1362
|
blockType = void 0;
|
|
981
1363
|
return;
|
|
@@ -988,54 +1370,68 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
988
1370
|
return;
|
|
989
1371
|
}
|
|
990
1372
|
controller.enqueue({
|
|
991
|
-
type: "text",
|
|
992
|
-
|
|
1373
|
+
type: "text-delta",
|
|
1374
|
+
id: String(value.index),
|
|
1375
|
+
delta: value.delta.text
|
|
993
1376
|
});
|
|
994
1377
|
return;
|
|
995
1378
|
}
|
|
996
1379
|
case "thinking_delta": {
|
|
997
1380
|
controller.enqueue({
|
|
998
|
-
type: "reasoning",
|
|
999
|
-
|
|
1381
|
+
type: "reasoning-delta",
|
|
1382
|
+
id: String(value.index),
|
|
1383
|
+
delta: value.delta.thinking
|
|
1000
1384
|
});
|
|
1001
1385
|
return;
|
|
1002
1386
|
}
|
|
1003
1387
|
case "signature_delta": {
|
|
1004
1388
|
if (blockType === "thinking") {
|
|
1005
1389
|
controller.enqueue({
|
|
1006
|
-
type: "reasoning",
|
|
1007
|
-
|
|
1390
|
+
type: "reasoning-delta",
|
|
1391
|
+
id: String(value.index),
|
|
1392
|
+
delta: "",
|
|
1008
1393
|
providerMetadata: {
|
|
1009
1394
|
anthropic: {
|
|
1010
1395
|
signature: value.delta.signature
|
|
1011
1396
|
}
|
|
1012
1397
|
}
|
|
1013
1398
|
});
|
|
1014
|
-
controller.enqueue({ type: "reasoning-part-finish" });
|
|
1015
1399
|
}
|
|
1016
1400
|
return;
|
|
1017
1401
|
}
|
|
1018
1402
|
case "input_json_delta": {
|
|
1019
|
-
const contentBlock =
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
jsonResponseTool != null ? {
|
|
1025
|
-
type: "text",
|
|
1026
|
-
text: value.delta.partial_json
|
|
1027
|
-
} : {
|
|
1028
|
-
type: "tool-call-delta",
|
|
1029
|
-
toolCallType: "function",
|
|
1030
|
-
toolCallId: contentBlock.toolCallId,
|
|
1031
|
-
toolName: contentBlock.toolName,
|
|
1032
|
-
argsTextDelta: value.delta.partial_json
|
|
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;
|
|
1033
1408
|
}
|
|
1034
|
-
|
|
1035
|
-
|
|
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
|
+
}
|
|
1036
1425
|
return;
|
|
1037
1426
|
}
|
|
1038
1427
|
case "citations_delta": {
|
|
1428
|
+
const citation = value.delta.citation;
|
|
1429
|
+
processCitation(
|
|
1430
|
+
citation,
|
|
1431
|
+
citationDocuments,
|
|
1432
|
+
generateId3,
|
|
1433
|
+
(source) => controller.enqueue(source)
|
|
1434
|
+
);
|
|
1039
1435
|
return;
|
|
1040
1436
|
}
|
|
1041
1437
|
default: {
|
|
@@ -1104,7 +1500,8 @@ var anthropicMessagesResponseSchema = import_zod3.z.object({
|
|
|
1104
1500
|
import_zod3.z.discriminatedUnion("type", [
|
|
1105
1501
|
import_zod3.z.object({
|
|
1106
1502
|
type: import_zod3.z.literal("text"),
|
|
1107
|
-
text: import_zod3.z.string()
|
|
1503
|
+
text: import_zod3.z.string(),
|
|
1504
|
+
citations: import_zod3.z.array(citationSchema).optional()
|
|
1108
1505
|
}),
|
|
1109
1506
|
import_zod3.z.object({
|
|
1110
1507
|
type: import_zod3.z.literal("thinking"),
|
|
@@ -1243,13 +1640,7 @@ var anthropicMessagesChunkSchema = import_zod3.z.discriminatedUnion("type", [
|
|
|
1243
1640
|
}),
|
|
1244
1641
|
import_zod3.z.object({
|
|
1245
1642
|
type: import_zod3.z.literal("citations_delta"),
|
|
1246
|
-
citation:
|
|
1247
|
-
type: import_zod3.z.literal("web_search_result_location"),
|
|
1248
|
-
cited_text: import_zod3.z.string(),
|
|
1249
|
-
url: import_zod3.z.string(),
|
|
1250
|
-
title: import_zod3.z.string(),
|
|
1251
|
-
encrypted_index: import_zod3.z.string()
|
|
1252
|
-
})
|
|
1643
|
+
citation: citationSchema
|
|
1253
1644
|
})
|
|
1254
1645
|
])
|
|
1255
1646
|
}),
|
|
@@ -1281,160 +1672,188 @@ var anthropicReasoningMetadataSchema = import_zod3.z.object({
|
|
|
1281
1672
|
redactedData: import_zod3.z.string().optional()
|
|
1282
1673
|
});
|
|
1283
1674
|
|
|
1284
|
-
// src/
|
|
1285
|
-
var
|
|
1286
|
-
var
|
|
1287
|
-
|
|
1288
|
-
|
|
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
|
+
})
|
|
1289
1685
|
});
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
command: import_zod4.z.string(),
|
|
1302
|
-
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
|
+
})
|
|
1303
1697
|
});
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
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
|
+
})
|
|
1322
1721
|
});
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
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
|
+
})
|
|
1341
1755
|
});
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
"left_click_drag",
|
|
1359
|
-
"right_click",
|
|
1360
|
-
"middle_click",
|
|
1361
|
-
"double_click",
|
|
1362
|
-
"screenshot",
|
|
1363
|
-
"cursor_position"
|
|
1364
|
-
]),
|
|
1365
|
-
coordinate: import_zod4.z.array(import_zod4.z.number().int()).optional(),
|
|
1366
|
-
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
|
+
})
|
|
1367
1772
|
});
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
"key",
|
|
1385
|
-
"hold_key",
|
|
1386
|
-
"type",
|
|
1387
|
-
"cursor_position",
|
|
1388
|
-
"mouse_move",
|
|
1389
|
-
"left_mouse_down",
|
|
1390
|
-
"left_mouse_up",
|
|
1391
|
-
"left_click",
|
|
1392
|
-
"left_click_drag",
|
|
1393
|
-
"right_click",
|
|
1394
|
-
"middle_click",
|
|
1395
|
-
"double_click",
|
|
1396
|
-
"triple_click",
|
|
1397
|
-
"scroll",
|
|
1398
|
-
"wait",
|
|
1399
|
-
"screenshot"
|
|
1400
|
-
]),
|
|
1401
|
-
coordinate: import_zod4.z.tuple([import_zod4.z.number().int(), import_zod4.z.number().int()]).optional(),
|
|
1402
|
-
duration: import_zod4.z.number().optional(),
|
|
1403
|
-
scroll_amount: import_zod4.z.number().optional(),
|
|
1404
|
-
scroll_direction: import_zod4.z.enum(["up", "down", "left", "right"]).optional(),
|
|
1405
|
-
start_coordinate: import_zod4.z.tuple([import_zod4.z.number().int(), import_zod4.z.number().int()]).optional(),
|
|
1406
|
-
text: import_zod4.z.string().optional()
|
|
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
|
+
})
|
|
1407
1789
|
});
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
type: "provider-defined",
|
|
1411
|
-
id: "anthropic.computer_20250124",
|
|
1412
|
-
args: {
|
|
1413
|
-
displayWidthPx: options.displayWidthPx,
|
|
1414
|
-
displayHeightPx: options.displayHeightPx,
|
|
1415
|
-
displayNumber: options.displayNumber
|
|
1416
|
-
},
|
|
1417
|
-
parameters: Computer20250124Parameters,
|
|
1418
|
-
execute: options.execute,
|
|
1419
|
-
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1420
|
-
};
|
|
1421
|
-
}
|
|
1790
|
+
|
|
1791
|
+
// src/anthropic-tools.ts
|
|
1422
1792
|
var anthropicTools = {
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
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
|
|
1429
1848
|
};
|
|
1430
1849
|
|
|
1431
1850
|
// src/anthropic-provider.ts
|
|
1432
1851
|
function createAnthropic(options = {}) {
|
|
1433
1852
|
var _a;
|
|
1434
|
-
const baseURL = (_a = (0,
|
|
1853
|
+
const baseURL = (_a = (0, import_provider_utils11.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.anthropic.com/v1";
|
|
1435
1854
|
const getHeaders = () => ({
|
|
1436
1855
|
"anthropic-version": "2023-06-01",
|
|
1437
|
-
"x-api-key": (0,
|
|
1856
|
+
"x-api-key": (0, import_provider_utils11.loadApiKey)({
|
|
1438
1857
|
apiKey: options.apiKey,
|
|
1439
1858
|
environmentVariableName: "ANTHROPIC_API_KEY",
|
|
1440
1859
|
description: "Anthropic"
|
|
@@ -1448,7 +1867,7 @@ function createAnthropic(options = {}) {
|
|
|
1448
1867
|
baseURL,
|
|
1449
1868
|
headers: getHeaders,
|
|
1450
1869
|
fetch: options.fetch,
|
|
1451
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
1870
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils11.generateId,
|
|
1452
1871
|
supportedUrls: () => ({
|
|
1453
1872
|
"image/*": [/^https?:\/\/.*$/]
|
|
1454
1873
|
})
|