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