@ai-sdk/anthropic 2.0.0-alpha.8 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +94 -0
- package/dist/index.d.mts +104 -368
- package/dist/index.d.ts +104 -368
- package/dist/index.js +877 -255
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +943 -329
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +107 -364
- package/dist/internal/index.d.ts +107 -364
- package/dist/internal/index.js +861 -243
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +929 -320
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
NoSuchModelError
|
|
4
4
|
} from "@ai-sdk/provider";
|
|
5
5
|
import {
|
|
6
|
+
generateId as generateId2,
|
|
6
7
|
loadApiKey,
|
|
7
8
|
withoutTrailingSlash
|
|
8
9
|
} from "@ai-sdk/provider-utils";
|
|
@@ -15,11 +16,12 @@ import {
|
|
|
15
16
|
combineHeaders,
|
|
16
17
|
createEventSourceResponseHandler,
|
|
17
18
|
createJsonResponseHandler,
|
|
19
|
+
generateId,
|
|
18
20
|
parseProviderOptions as parseProviderOptions2,
|
|
19
21
|
postJsonToApi,
|
|
20
22
|
resolve
|
|
21
23
|
} from "@ai-sdk/provider-utils";
|
|
22
|
-
import { z as
|
|
24
|
+
import { z as z4 } from "zod";
|
|
23
25
|
|
|
24
26
|
// src/anthropic-error.ts
|
|
25
27
|
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
@@ -38,12 +40,30 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
38
40
|
|
|
39
41
|
// src/anthropic-messages-options.ts
|
|
40
42
|
import { z as z2 } from "zod";
|
|
41
|
-
var
|
|
43
|
+
var anthropicFilePartProviderOptions = z2.object({
|
|
44
|
+
/**
|
|
45
|
+
* Citation configuration for this document.
|
|
46
|
+
* When enabled, this document will generate citations in the response.
|
|
47
|
+
*/
|
|
48
|
+
citations: z2.object({
|
|
49
|
+
/**
|
|
50
|
+
* Enable citations for this document
|
|
51
|
+
*/
|
|
52
|
+
enabled: z2.boolean()
|
|
53
|
+
}).optional(),
|
|
54
|
+
/**
|
|
55
|
+
* Custom title for the document.
|
|
56
|
+
* If not provided, the filename will be used.
|
|
57
|
+
*/
|
|
58
|
+
title: z2.string().optional(),
|
|
42
59
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
60
|
+
* Context about the document that will be passed to the model
|
|
61
|
+
* but not used towards cited content.
|
|
62
|
+
* Useful for storing document metadata as text or stringified JSON.
|
|
63
|
+
*/
|
|
64
|
+
context: z2.string().optional()
|
|
65
|
+
});
|
|
66
|
+
var anthropicProviderOptions = z2.object({
|
|
47
67
|
sendReasoning: z2.boolean().optional(),
|
|
48
68
|
thinking: z2.object({
|
|
49
69
|
type: z2.union([z2.literal("enabled"), z2.literal("disabled")]),
|
|
@@ -55,6 +75,59 @@ var anthropicProviderOptions = z2.object({
|
|
|
55
75
|
import {
|
|
56
76
|
UnsupportedFunctionalityError
|
|
57
77
|
} from "@ai-sdk/provider";
|
|
78
|
+
|
|
79
|
+
// src/tool/web-search_20250305.ts
|
|
80
|
+
import { createProviderDefinedToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils";
|
|
81
|
+
import { z as z3 } from "zod/v4";
|
|
82
|
+
var webSearch_20250305ArgsSchema = z3.object({
|
|
83
|
+
/**
|
|
84
|
+
* Maximum number of web searches Claude can perform during the conversation.
|
|
85
|
+
*/
|
|
86
|
+
maxUses: z3.number().optional(),
|
|
87
|
+
/**
|
|
88
|
+
* Optional list of domains that Claude is allowed to search.
|
|
89
|
+
*/
|
|
90
|
+
allowedDomains: z3.array(z3.string()).optional(),
|
|
91
|
+
/**
|
|
92
|
+
* Optional list of domains that Claude should avoid when searching.
|
|
93
|
+
*/
|
|
94
|
+
blockedDomains: z3.array(z3.string()).optional(),
|
|
95
|
+
/**
|
|
96
|
+
* Optional user location information to provide geographically relevant search results.
|
|
97
|
+
*/
|
|
98
|
+
userLocation: z3.object({
|
|
99
|
+
type: z3.literal("approximate"),
|
|
100
|
+
city: z3.string().optional(),
|
|
101
|
+
region: z3.string().optional(),
|
|
102
|
+
country: z3.string().optional(),
|
|
103
|
+
timezone: z3.string().optional()
|
|
104
|
+
}).optional()
|
|
105
|
+
});
|
|
106
|
+
var webSearch_20250305OutputSchema = z3.array(
|
|
107
|
+
z3.object({
|
|
108
|
+
url: z3.string(),
|
|
109
|
+
title: z3.string(),
|
|
110
|
+
pageAge: z3.string().nullable(),
|
|
111
|
+
encryptedContent: z3.string(),
|
|
112
|
+
type: z3.string()
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
var factory = createProviderDefinedToolFactoryWithOutputSchema({
|
|
116
|
+
id: "anthropic.web_search_20250305",
|
|
117
|
+
name: "web_search",
|
|
118
|
+
inputSchema: z3.object({
|
|
119
|
+
query: z3.string()
|
|
120
|
+
}),
|
|
121
|
+
outputSchema: webSearch_20250305OutputSchema
|
|
122
|
+
});
|
|
123
|
+
var webSearch_20250305 = (args = {}) => {
|
|
124
|
+
return factory(args);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/anthropic-prepare-tools.ts
|
|
128
|
+
function isWebSearchTool(tool) {
|
|
129
|
+
return typeof tool === "object" && tool !== null && "type" in tool && tool.type === "web_search_20250305";
|
|
130
|
+
}
|
|
58
131
|
function prepareTools({
|
|
59
132
|
tools,
|
|
60
133
|
toolChoice
|
|
@@ -67,12 +140,16 @@ function prepareTools({
|
|
|
67
140
|
}
|
|
68
141
|
const anthropicTools2 = [];
|
|
69
142
|
for (const tool of tools) {
|
|
143
|
+
if (isWebSearchTool(tool)) {
|
|
144
|
+
anthropicTools2.push(tool);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
70
147
|
switch (tool.type) {
|
|
71
148
|
case "function":
|
|
72
149
|
anthropicTools2.push({
|
|
73
150
|
name: tool.name,
|
|
74
151
|
description: tool.description,
|
|
75
|
-
input_schema: tool.
|
|
152
|
+
input_schema: tool.inputSchema
|
|
76
153
|
});
|
|
77
154
|
break;
|
|
78
155
|
case "provider-defined":
|
|
@@ -80,7 +157,7 @@ function prepareTools({
|
|
|
80
157
|
case "anthropic.computer_20250124":
|
|
81
158
|
betas.add("computer-use-2025-01-24");
|
|
82
159
|
anthropicTools2.push({
|
|
83
|
-
name:
|
|
160
|
+
name: "computer",
|
|
84
161
|
type: "computer_20250124",
|
|
85
162
|
display_width_px: tool.args.displayWidthPx,
|
|
86
163
|
display_height_px: tool.args.displayHeightPx,
|
|
@@ -90,7 +167,7 @@ function prepareTools({
|
|
|
90
167
|
case "anthropic.computer_20241022":
|
|
91
168
|
betas.add("computer-use-2024-10-22");
|
|
92
169
|
anthropicTools2.push({
|
|
93
|
-
name:
|
|
170
|
+
name: "computer",
|
|
94
171
|
type: "computer_20241022",
|
|
95
172
|
display_width_px: tool.args.displayWidthPx,
|
|
96
173
|
display_height_px: tool.args.displayHeightPx,
|
|
@@ -100,31 +177,43 @@ function prepareTools({
|
|
|
100
177
|
case "anthropic.text_editor_20250124":
|
|
101
178
|
betas.add("computer-use-2025-01-24");
|
|
102
179
|
anthropicTools2.push({
|
|
103
|
-
name:
|
|
180
|
+
name: "str_replace_editor",
|
|
104
181
|
type: "text_editor_20250124"
|
|
105
182
|
});
|
|
106
183
|
break;
|
|
107
184
|
case "anthropic.text_editor_20241022":
|
|
108
185
|
betas.add("computer-use-2024-10-22");
|
|
109
186
|
anthropicTools2.push({
|
|
110
|
-
name:
|
|
187
|
+
name: "str_replace_editor",
|
|
111
188
|
type: "text_editor_20241022"
|
|
112
189
|
});
|
|
113
190
|
break;
|
|
114
191
|
case "anthropic.bash_20250124":
|
|
115
192
|
betas.add("computer-use-2025-01-24");
|
|
116
193
|
anthropicTools2.push({
|
|
117
|
-
name:
|
|
194
|
+
name: "bash",
|
|
118
195
|
type: "bash_20250124"
|
|
119
196
|
});
|
|
120
197
|
break;
|
|
121
198
|
case "anthropic.bash_20241022":
|
|
122
199
|
betas.add("computer-use-2024-10-22");
|
|
123
200
|
anthropicTools2.push({
|
|
124
|
-
name:
|
|
201
|
+
name: "bash",
|
|
125
202
|
type: "bash_20241022"
|
|
126
203
|
});
|
|
127
204
|
break;
|
|
205
|
+
case "anthropic.web_search_20250305": {
|
|
206
|
+
const args = webSearch_20250305ArgsSchema.parse(tool.args);
|
|
207
|
+
anthropicTools2.push({
|
|
208
|
+
type: "web_search_20250305",
|
|
209
|
+
name: "web_search",
|
|
210
|
+
max_uses: args.maxUses,
|
|
211
|
+
allowed_domains: args.allowedDomains,
|
|
212
|
+
blocked_domains: args.blockedDomains,
|
|
213
|
+
user_location: args.userLocation
|
|
214
|
+
});
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
128
217
|
default:
|
|
129
218
|
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
130
219
|
break;
|
|
@@ -182,12 +271,28 @@ import {
|
|
|
182
271
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
183
272
|
} from "@ai-sdk/provider";
|
|
184
273
|
import { convertToBase64, parseProviderOptions } from "@ai-sdk/provider-utils";
|
|
274
|
+
function convertToString(data) {
|
|
275
|
+
if (typeof data === "string") {
|
|
276
|
+
return Buffer.from(data, "base64").toString("utf-8");
|
|
277
|
+
}
|
|
278
|
+
if (data instanceof Uint8Array) {
|
|
279
|
+
return new TextDecoder().decode(data);
|
|
280
|
+
}
|
|
281
|
+
if (data instanceof URL) {
|
|
282
|
+
throw new UnsupportedFunctionalityError2({
|
|
283
|
+
functionality: "URL-based text documents are not supported for citations"
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
throw new UnsupportedFunctionalityError2({
|
|
287
|
+
functionality: `unsupported data type for text documents: ${typeof data}`
|
|
288
|
+
});
|
|
289
|
+
}
|
|
185
290
|
async function convertToAnthropicMessagesPrompt({
|
|
186
291
|
prompt,
|
|
187
292
|
sendReasoning,
|
|
188
293
|
warnings
|
|
189
294
|
}) {
|
|
190
|
-
var _a, _b, _c;
|
|
295
|
+
var _a, _b, _c, _d, _e;
|
|
191
296
|
const betas = /* @__PURE__ */ new Set();
|
|
192
297
|
const blocks = groupIntoBlocks(prompt);
|
|
193
298
|
let system = void 0;
|
|
@@ -198,6 +303,26 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
198
303
|
const cacheControlValue = (_a2 = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ? _a2 : anthropic2 == null ? void 0 : anthropic2.cache_control;
|
|
199
304
|
return cacheControlValue;
|
|
200
305
|
}
|
|
306
|
+
async function shouldEnableCitations(providerMetadata) {
|
|
307
|
+
var _a2, _b2;
|
|
308
|
+
const anthropicOptions = await parseProviderOptions({
|
|
309
|
+
provider: "anthropic",
|
|
310
|
+
providerOptions: providerMetadata,
|
|
311
|
+
schema: anthropicFilePartProviderOptions
|
|
312
|
+
});
|
|
313
|
+
return (_b2 = (_a2 = anthropicOptions == null ? void 0 : anthropicOptions.citations) == null ? void 0 : _a2.enabled) != null ? _b2 : false;
|
|
314
|
+
}
|
|
315
|
+
async function getDocumentMetadata(providerMetadata) {
|
|
316
|
+
const anthropicOptions = await parseProviderOptions({
|
|
317
|
+
provider: "anthropic",
|
|
318
|
+
providerOptions: providerMetadata,
|
|
319
|
+
schema: anthropicFilePartProviderOptions
|
|
320
|
+
});
|
|
321
|
+
return {
|
|
322
|
+
title: anthropicOptions == null ? void 0 : anthropicOptions.title,
|
|
323
|
+
context: anthropicOptions == null ? void 0 : anthropicOptions.context
|
|
324
|
+
};
|
|
325
|
+
}
|
|
201
326
|
for (let i = 0; i < blocks.length; i++) {
|
|
202
327
|
const block = blocks[i];
|
|
203
328
|
const isLastBlock = i === blocks.length - 1;
|
|
@@ -251,6 +376,12 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
251
376
|
});
|
|
252
377
|
} else if (part.mediaType === "application/pdf") {
|
|
253
378
|
betas.add("pdfs-2024-09-25");
|
|
379
|
+
const enableCitations = await shouldEnableCitations(
|
|
380
|
+
part.providerOptions
|
|
381
|
+
);
|
|
382
|
+
const metadata = await getDocumentMetadata(
|
|
383
|
+
part.providerOptions
|
|
384
|
+
);
|
|
254
385
|
anthropicContent.push({
|
|
255
386
|
type: "document",
|
|
256
387
|
source: part.data instanceof URL ? {
|
|
@@ -261,6 +392,35 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
261
392
|
media_type: "application/pdf",
|
|
262
393
|
data: convertToBase64(part.data)
|
|
263
394
|
},
|
|
395
|
+
title: (_b = metadata.title) != null ? _b : part.filename,
|
|
396
|
+
...metadata.context && { context: metadata.context },
|
|
397
|
+
...enableCitations && {
|
|
398
|
+
citations: { enabled: true }
|
|
399
|
+
},
|
|
400
|
+
cache_control: cacheControl
|
|
401
|
+
});
|
|
402
|
+
} else if (part.mediaType === "text/plain") {
|
|
403
|
+
const enableCitations = await shouldEnableCitations(
|
|
404
|
+
part.providerOptions
|
|
405
|
+
);
|
|
406
|
+
const metadata = await getDocumentMetadata(
|
|
407
|
+
part.providerOptions
|
|
408
|
+
);
|
|
409
|
+
anthropicContent.push({
|
|
410
|
+
type: "document",
|
|
411
|
+
source: part.data instanceof URL ? {
|
|
412
|
+
type: "url",
|
|
413
|
+
url: part.data.toString()
|
|
414
|
+
} : {
|
|
415
|
+
type: "text",
|
|
416
|
+
media_type: "text/plain",
|
|
417
|
+
data: convertToString(part.data)
|
|
418
|
+
},
|
|
419
|
+
title: (_c = metadata.title) != null ? _c : part.filename,
|
|
420
|
+
...metadata.context && { context: metadata.context },
|
|
421
|
+
...enableCitations && {
|
|
422
|
+
citations: { enabled: true }
|
|
423
|
+
},
|
|
264
424
|
cache_control: cacheControl
|
|
265
425
|
});
|
|
266
426
|
} else {
|
|
@@ -278,33 +438,53 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
278
438
|
for (let i2 = 0; i2 < content.length; i2++) {
|
|
279
439
|
const part = content[i2];
|
|
280
440
|
const isLastPart = i2 === content.length - 1;
|
|
281
|
-
const cacheControl = (
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
text:
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
441
|
+
const cacheControl = (_d = getCacheControl(part.providerOptions)) != null ? _d : isLastPart ? getCacheControl(message.providerOptions) : void 0;
|
|
442
|
+
const output = part.output;
|
|
443
|
+
let contentValue;
|
|
444
|
+
switch (output.type) {
|
|
445
|
+
case "content":
|
|
446
|
+
contentValue = output.value.map((contentPart) => {
|
|
447
|
+
switch (contentPart.type) {
|
|
448
|
+
case "text":
|
|
449
|
+
return {
|
|
450
|
+
type: "text",
|
|
451
|
+
text: contentPart.text,
|
|
452
|
+
cache_control: void 0
|
|
453
|
+
};
|
|
454
|
+
case "media": {
|
|
455
|
+
if (contentPart.mediaType.startsWith("image/")) {
|
|
456
|
+
return {
|
|
457
|
+
type: "image",
|
|
458
|
+
source: {
|
|
459
|
+
type: "base64",
|
|
460
|
+
media_type: contentPart.mediaType,
|
|
461
|
+
data: contentPart.data
|
|
462
|
+
},
|
|
463
|
+
cache_control: void 0
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
throw new UnsupportedFunctionalityError2({
|
|
467
|
+
functionality: `media type: ${contentPart.mediaType}`
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
break;
|
|
473
|
+
case "text":
|
|
474
|
+
case "error-text":
|
|
475
|
+
contentValue = output.value;
|
|
476
|
+
break;
|
|
477
|
+
case "json":
|
|
478
|
+
case "error-json":
|
|
479
|
+
default:
|
|
480
|
+
contentValue = JSON.stringify(output.value);
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
303
483
|
anthropicContent.push({
|
|
304
484
|
type: "tool_result",
|
|
305
485
|
tool_use_id: part.toolCallId,
|
|
306
|
-
content:
|
|
307
|
-
is_error:
|
|
486
|
+
content: contentValue,
|
|
487
|
+
is_error: output.type === "error-text" || output.type === "error-json" ? true : void 0,
|
|
308
488
|
cache_control: cacheControl
|
|
309
489
|
});
|
|
310
490
|
}
|
|
@@ -328,7 +508,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
328
508
|
for (let k = 0; k < content.length; k++) {
|
|
329
509
|
const part = content[k];
|
|
330
510
|
const isLastContentPart = k === content.length - 1;
|
|
331
|
-
const cacheControl = (
|
|
511
|
+
const cacheControl = (_e = getCacheControl(part.providerOptions)) != null ? _e : isLastContentPart ? getCacheControl(message.providerOptions) : void 0;
|
|
332
512
|
switch (part.type) {
|
|
333
513
|
case "text": {
|
|
334
514
|
anthropicContent.push({
|
|
@@ -385,15 +565,65 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
385
565
|
break;
|
|
386
566
|
}
|
|
387
567
|
case "tool-call": {
|
|
568
|
+
if (part.providerExecuted) {
|
|
569
|
+
if (part.toolName === "web_search") {
|
|
570
|
+
anthropicContent.push({
|
|
571
|
+
type: "server_tool_use",
|
|
572
|
+
id: part.toolCallId,
|
|
573
|
+
name: "web_search",
|
|
574
|
+
input: part.input,
|
|
575
|
+
cache_control: cacheControl
|
|
576
|
+
});
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
warnings.push({
|
|
580
|
+
type: "other",
|
|
581
|
+
message: `provider executed tool call for tool ${part.toolName} is not supported`
|
|
582
|
+
});
|
|
583
|
+
break;
|
|
584
|
+
}
|
|
388
585
|
anthropicContent.push({
|
|
389
586
|
type: "tool_use",
|
|
390
587
|
id: part.toolCallId,
|
|
391
588
|
name: part.toolName,
|
|
392
|
-
input: part.
|
|
589
|
+
input: part.input,
|
|
393
590
|
cache_control: cacheControl
|
|
394
591
|
});
|
|
395
592
|
break;
|
|
396
593
|
}
|
|
594
|
+
case "tool-result": {
|
|
595
|
+
if (part.toolName === "web_search") {
|
|
596
|
+
const output = part.output;
|
|
597
|
+
if (output.type !== "json") {
|
|
598
|
+
warnings.push({
|
|
599
|
+
type: "other",
|
|
600
|
+
message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
|
|
601
|
+
});
|
|
602
|
+
break;
|
|
603
|
+
}
|
|
604
|
+
const webSearchOutput = webSearch_20250305OutputSchema.parse(
|
|
605
|
+
output.value
|
|
606
|
+
);
|
|
607
|
+
anthropicContent.push({
|
|
608
|
+
type: "web_search_tool_result",
|
|
609
|
+
tool_use_id: part.toolCallId,
|
|
610
|
+
content: webSearchOutput.map((result) => ({
|
|
611
|
+
url: result.url,
|
|
612
|
+
title: result.title,
|
|
613
|
+
page_age: result.pageAge,
|
|
614
|
+
encrypted_content: result.encryptedContent,
|
|
615
|
+
type: result.type
|
|
616
|
+
})),
|
|
617
|
+
cache_control: cacheControl
|
|
618
|
+
});
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
warnings.push({
|
|
622
|
+
type: "other",
|
|
623
|
+
message: `provider executed tool result for tool ${part.toolName} is not supported`
|
|
624
|
+
});
|
|
625
|
+
break;
|
|
626
|
+
}
|
|
397
627
|
}
|
|
398
628
|
}
|
|
399
629
|
}
|
|
@@ -477,11 +707,86 @@ function mapAnthropicStopReason({
|
|
|
477
707
|
}
|
|
478
708
|
|
|
479
709
|
// src/anthropic-messages-language-model.ts
|
|
710
|
+
var citationSchemas = {
|
|
711
|
+
webSearchResult: z4.object({
|
|
712
|
+
type: z4.literal("web_search_result_location"),
|
|
713
|
+
cited_text: z4.string(),
|
|
714
|
+
url: z4.string(),
|
|
715
|
+
title: z4.string(),
|
|
716
|
+
encrypted_index: z4.string()
|
|
717
|
+
}),
|
|
718
|
+
pageLocation: z4.object({
|
|
719
|
+
type: z4.literal("page_location"),
|
|
720
|
+
cited_text: z4.string(),
|
|
721
|
+
document_index: z4.number(),
|
|
722
|
+
document_title: z4.string().nullable(),
|
|
723
|
+
start_page_number: z4.number(),
|
|
724
|
+
end_page_number: z4.number()
|
|
725
|
+
}),
|
|
726
|
+
charLocation: z4.object({
|
|
727
|
+
type: z4.literal("char_location"),
|
|
728
|
+
cited_text: z4.string(),
|
|
729
|
+
document_index: z4.number(),
|
|
730
|
+
document_title: z4.string().nullable(),
|
|
731
|
+
start_char_index: z4.number(),
|
|
732
|
+
end_char_index: z4.number()
|
|
733
|
+
})
|
|
734
|
+
};
|
|
735
|
+
var citationSchema = z4.discriminatedUnion("type", [
|
|
736
|
+
citationSchemas.webSearchResult,
|
|
737
|
+
citationSchemas.pageLocation,
|
|
738
|
+
citationSchemas.charLocation
|
|
739
|
+
]);
|
|
740
|
+
var documentCitationSchema = z4.discriminatedUnion("type", [
|
|
741
|
+
citationSchemas.pageLocation,
|
|
742
|
+
citationSchemas.charLocation
|
|
743
|
+
]);
|
|
744
|
+
function processCitation(citation, citationDocuments, generateId3, onSource) {
|
|
745
|
+
if (citation.type === "page_location" || citation.type === "char_location") {
|
|
746
|
+
const source = createCitationSource(
|
|
747
|
+
citation,
|
|
748
|
+
citationDocuments,
|
|
749
|
+
generateId3
|
|
750
|
+
);
|
|
751
|
+
if (source) {
|
|
752
|
+
onSource(source);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
function createCitationSource(citation, citationDocuments, generateId3) {
|
|
757
|
+
var _a;
|
|
758
|
+
const documentInfo = citationDocuments[citation.document_index];
|
|
759
|
+
if (!documentInfo) {
|
|
760
|
+
return null;
|
|
761
|
+
}
|
|
762
|
+
const providerMetadata = citation.type === "page_location" ? {
|
|
763
|
+
citedText: citation.cited_text,
|
|
764
|
+
startPageNumber: citation.start_page_number,
|
|
765
|
+
endPageNumber: citation.end_page_number
|
|
766
|
+
} : {
|
|
767
|
+
citedText: citation.cited_text,
|
|
768
|
+
startCharIndex: citation.start_char_index,
|
|
769
|
+
endCharIndex: citation.end_char_index
|
|
770
|
+
};
|
|
771
|
+
return {
|
|
772
|
+
type: "source",
|
|
773
|
+
sourceType: "document",
|
|
774
|
+
id: generateId3(),
|
|
775
|
+
mediaType: documentInfo.mediaType,
|
|
776
|
+
title: (_a = citation.document_title) != null ? _a : documentInfo.title,
|
|
777
|
+
filename: documentInfo.filename,
|
|
778
|
+
providerMetadata: {
|
|
779
|
+
anthropic: providerMetadata
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
}
|
|
480
783
|
var AnthropicMessagesLanguageModel = class {
|
|
481
784
|
constructor(modelId, config) {
|
|
482
785
|
this.specificationVersion = "v2";
|
|
786
|
+
var _a;
|
|
483
787
|
this.modelId = modelId;
|
|
484
788
|
this.config = config;
|
|
789
|
+
this.generateId = (_a = config.generateId) != null ? _a : generateId;
|
|
485
790
|
}
|
|
486
791
|
supportsUrl(url) {
|
|
487
792
|
return url.protocol === "https:";
|
|
@@ -548,7 +853,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
548
853
|
type: "function",
|
|
549
854
|
name: "json",
|
|
550
855
|
description: "Respond with a JSON object.",
|
|
551
|
-
|
|
856
|
+
inputSchema: responseFormat.schema
|
|
552
857
|
} : void 0;
|
|
553
858
|
const anthropicOptions = await parseProviderOptions2({
|
|
554
859
|
provider: "anthropic",
|
|
@@ -620,7 +925,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
620
925
|
jsonResponseTool != null ? {
|
|
621
926
|
tools: [jsonResponseTool],
|
|
622
927
|
toolChoice: { type: "tool", toolName: jsonResponseTool.name }
|
|
623
|
-
} : { tools, toolChoice }
|
|
928
|
+
} : { tools: tools != null ? tools : [], toolChoice }
|
|
624
929
|
);
|
|
625
930
|
return {
|
|
626
931
|
args: {
|
|
@@ -651,9 +956,33 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
651
956
|
var _a, _b, _c;
|
|
652
957
|
return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args)) != null ? _c : args;
|
|
653
958
|
}
|
|
959
|
+
extractCitationDocuments(prompt) {
|
|
960
|
+
const isCitationPart = (part) => {
|
|
961
|
+
var _a, _b;
|
|
962
|
+
if (part.type !== "file") {
|
|
963
|
+
return false;
|
|
964
|
+
}
|
|
965
|
+
if (part.mediaType !== "application/pdf" && part.mediaType !== "text/plain") {
|
|
966
|
+
return false;
|
|
967
|
+
}
|
|
968
|
+
const anthropic2 = (_a = part.providerOptions) == null ? void 0 : _a.anthropic;
|
|
969
|
+
const citationsConfig = anthropic2 == null ? void 0 : anthropic2.citations;
|
|
970
|
+
return (_b = citationsConfig == null ? void 0 : citationsConfig.enabled) != null ? _b : false;
|
|
971
|
+
};
|
|
972
|
+
return prompt.filter((message) => message.role === "user").flatMap((message) => message.content).filter(isCitationPart).map((part) => {
|
|
973
|
+
var _a;
|
|
974
|
+
const filePart = part;
|
|
975
|
+
return {
|
|
976
|
+
title: (_a = filePart.filename) != null ? _a : "Untitled Document",
|
|
977
|
+
filename: filePart.filename,
|
|
978
|
+
mediaType: filePart.mediaType
|
|
979
|
+
};
|
|
980
|
+
});
|
|
981
|
+
}
|
|
654
982
|
async doGenerate(options) {
|
|
655
|
-
var _a, _b, _c, _d;
|
|
983
|
+
var _a, _b, _c, _d, _e;
|
|
656
984
|
const { args, warnings, betas, jsonResponseTool } = await this.getArgs(options);
|
|
985
|
+
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
657
986
|
const {
|
|
658
987
|
responseHeaders,
|
|
659
988
|
value: response,
|
|
@@ -675,6 +1004,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
675
1004
|
case "text": {
|
|
676
1005
|
if (jsonResponseTool == null) {
|
|
677
1006
|
content.push({ type: "text", text: part.text });
|
|
1007
|
+
if (part.citations) {
|
|
1008
|
+
for (const citation of part.citations) {
|
|
1009
|
+
processCitation(
|
|
1010
|
+
citation,
|
|
1011
|
+
citationDocuments,
|
|
1012
|
+
this.generateId,
|
|
1013
|
+
(source) => content.push(source)
|
|
1014
|
+
);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
678
1017
|
}
|
|
679
1018
|
break;
|
|
680
1019
|
}
|
|
@@ -710,14 +1049,72 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
710
1049
|
text: JSON.stringify(part.input)
|
|
711
1050
|
} : {
|
|
712
1051
|
type: "tool-call",
|
|
713
|
-
toolCallType: "function",
|
|
714
1052
|
toolCallId: part.id,
|
|
715
1053
|
toolName: part.name,
|
|
716
|
-
|
|
1054
|
+
input: JSON.stringify(part.input)
|
|
717
1055
|
}
|
|
718
1056
|
);
|
|
719
1057
|
break;
|
|
720
1058
|
}
|
|
1059
|
+
case "server_tool_use": {
|
|
1060
|
+
if (part.name === "web_search") {
|
|
1061
|
+
content.push({
|
|
1062
|
+
type: "tool-call",
|
|
1063
|
+
toolCallId: part.id,
|
|
1064
|
+
toolName: part.name,
|
|
1065
|
+
input: JSON.stringify(part.input),
|
|
1066
|
+
providerExecuted: true
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
break;
|
|
1070
|
+
}
|
|
1071
|
+
case "web_search_tool_result": {
|
|
1072
|
+
if (Array.isArray(part.content)) {
|
|
1073
|
+
content.push({
|
|
1074
|
+
type: "tool-result",
|
|
1075
|
+
toolCallId: part.tool_use_id,
|
|
1076
|
+
toolName: "web_search",
|
|
1077
|
+
result: part.content.map((result) => {
|
|
1078
|
+
var _a2;
|
|
1079
|
+
return {
|
|
1080
|
+
url: result.url,
|
|
1081
|
+
title: result.title,
|
|
1082
|
+
pageAge: (_a2 = result.page_age) != null ? _a2 : null,
|
|
1083
|
+
encryptedContent: result.encrypted_content,
|
|
1084
|
+
type: result.type
|
|
1085
|
+
};
|
|
1086
|
+
}),
|
|
1087
|
+
providerExecuted: true
|
|
1088
|
+
});
|
|
1089
|
+
for (const result of part.content) {
|
|
1090
|
+
content.push({
|
|
1091
|
+
type: "source",
|
|
1092
|
+
sourceType: "url",
|
|
1093
|
+
id: this.generateId(),
|
|
1094
|
+
url: result.url,
|
|
1095
|
+
title: result.title,
|
|
1096
|
+
providerMetadata: {
|
|
1097
|
+
anthropic: {
|
|
1098
|
+
pageAge: (_a = result.page_age) != null ? _a : null
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
} else {
|
|
1104
|
+
content.push({
|
|
1105
|
+
type: "tool-result",
|
|
1106
|
+
toolCallId: part.tool_use_id,
|
|
1107
|
+
toolName: "web_search",
|
|
1108
|
+
isError: true,
|
|
1109
|
+
result: {
|
|
1110
|
+
type: "web_search_tool_result_error",
|
|
1111
|
+
errorCode: part.content.error_code
|
|
1112
|
+
},
|
|
1113
|
+
providerExecuted: true
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
break;
|
|
1117
|
+
}
|
|
721
1118
|
}
|
|
722
1119
|
}
|
|
723
1120
|
return {
|
|
@@ -730,25 +1127,26 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
730
1127
|
inputTokens: response.usage.input_tokens,
|
|
731
1128
|
outputTokens: response.usage.output_tokens,
|
|
732
1129
|
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
733
|
-
cachedInputTokens: (
|
|
1130
|
+
cachedInputTokens: (_b = response.usage.cache_read_input_tokens) != null ? _b : void 0
|
|
734
1131
|
},
|
|
735
1132
|
request: { body: args },
|
|
736
1133
|
response: {
|
|
737
|
-
id: (
|
|
738
|
-
modelId: (
|
|
1134
|
+
id: (_c = response.id) != null ? _c : void 0,
|
|
1135
|
+
modelId: (_d = response.model) != null ? _d : void 0,
|
|
739
1136
|
headers: responseHeaders,
|
|
740
1137
|
body: rawResponse
|
|
741
1138
|
},
|
|
742
1139
|
warnings,
|
|
743
1140
|
providerMetadata: {
|
|
744
1141
|
anthropic: {
|
|
745
|
-
cacheCreationInputTokens: (
|
|
1142
|
+
cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null
|
|
746
1143
|
}
|
|
747
1144
|
}
|
|
748
1145
|
};
|
|
749
1146
|
}
|
|
750
1147
|
async doStream(options) {
|
|
751
1148
|
const { args, warnings, betas, jsonResponseTool } = await this.getArgs(options);
|
|
1149
|
+
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
752
1150
|
const body = { ...args, stream: true };
|
|
753
1151
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
754
1152
|
url: this.buildRequestUrl(true),
|
|
@@ -767,9 +1165,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
767
1165
|
outputTokens: void 0,
|
|
768
1166
|
totalTokens: void 0
|
|
769
1167
|
};
|
|
770
|
-
const
|
|
1168
|
+
const contentBlocks = {};
|
|
771
1169
|
let providerMetadata = void 0;
|
|
772
1170
|
let blockType = void 0;
|
|
1171
|
+
const generateId3 = this.generateId;
|
|
773
1172
|
return {
|
|
774
1173
|
stream: response.pipeThrough(
|
|
775
1174
|
new TransformStream({
|
|
@@ -777,7 +1176,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
777
1176
|
controller.enqueue({ type: "stream-start", warnings });
|
|
778
1177
|
},
|
|
779
1178
|
transform(chunk, controller) {
|
|
780
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1179
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1180
|
+
if (options.includeRawChunks) {
|
|
1181
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1182
|
+
}
|
|
781
1183
|
if (!chunk.success) {
|
|
782
1184
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
783
1185
|
return;
|
|
@@ -791,29 +1193,115 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
791
1193
|
const contentBlockType = value.content_block.type;
|
|
792
1194
|
blockType = contentBlockType;
|
|
793
1195
|
switch (contentBlockType) {
|
|
794
|
-
case "text":
|
|
1196
|
+
case "text": {
|
|
1197
|
+
contentBlocks[value.index] = { type: "text" };
|
|
1198
|
+
controller.enqueue({
|
|
1199
|
+
type: "text-start",
|
|
1200
|
+
id: String(value.index)
|
|
1201
|
+
});
|
|
1202
|
+
return;
|
|
1203
|
+
}
|
|
795
1204
|
case "thinking": {
|
|
1205
|
+
contentBlocks[value.index] = { type: "reasoning" };
|
|
1206
|
+
controller.enqueue({
|
|
1207
|
+
type: "reasoning-start",
|
|
1208
|
+
id: String(value.index)
|
|
1209
|
+
});
|
|
796
1210
|
return;
|
|
797
1211
|
}
|
|
798
1212
|
case "redacted_thinking": {
|
|
1213
|
+
contentBlocks[value.index] = { type: "reasoning" };
|
|
799
1214
|
controller.enqueue({
|
|
800
|
-
type: "reasoning",
|
|
801
|
-
|
|
1215
|
+
type: "reasoning-start",
|
|
1216
|
+
id: String(value.index),
|
|
802
1217
|
providerMetadata: {
|
|
803
1218
|
anthropic: {
|
|
804
1219
|
redactedData: value.content_block.data
|
|
805
1220
|
}
|
|
806
1221
|
}
|
|
807
1222
|
});
|
|
808
|
-
controller.enqueue({ type: "reasoning-part-finish" });
|
|
809
1223
|
return;
|
|
810
1224
|
}
|
|
811
1225
|
case "tool_use": {
|
|
812
|
-
|
|
1226
|
+
contentBlocks[value.index] = jsonResponseTool != null ? { type: "text" } : {
|
|
1227
|
+
type: "tool-call",
|
|
813
1228
|
toolCallId: value.content_block.id,
|
|
814
1229
|
toolName: value.content_block.name,
|
|
815
|
-
|
|
1230
|
+
input: ""
|
|
816
1231
|
};
|
|
1232
|
+
controller.enqueue(
|
|
1233
|
+
jsonResponseTool != null ? { type: "text-start", id: String(value.index) } : {
|
|
1234
|
+
type: "tool-input-start",
|
|
1235
|
+
id: String(value.index),
|
|
1236
|
+
toolName: value.content_block.name
|
|
1237
|
+
}
|
|
1238
|
+
);
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
case "server_tool_use": {
|
|
1242
|
+
if (value.content_block.name === "web_search") {
|
|
1243
|
+
contentBlocks[value.index] = {
|
|
1244
|
+
type: "tool-call",
|
|
1245
|
+
toolCallId: value.content_block.id,
|
|
1246
|
+
toolName: value.content_block.name,
|
|
1247
|
+
input: "",
|
|
1248
|
+
providerExecuted: true
|
|
1249
|
+
};
|
|
1250
|
+
controller.enqueue({
|
|
1251
|
+
type: "tool-input-start",
|
|
1252
|
+
id: value.content_block.id,
|
|
1253
|
+
toolName: value.content_block.name,
|
|
1254
|
+
providerExecuted: true
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1259
|
+
case "web_search_tool_result": {
|
|
1260
|
+
const part = value.content_block;
|
|
1261
|
+
if (Array.isArray(part.content)) {
|
|
1262
|
+
controller.enqueue({
|
|
1263
|
+
type: "tool-result",
|
|
1264
|
+
toolCallId: part.tool_use_id,
|
|
1265
|
+
toolName: "web_search",
|
|
1266
|
+
result: part.content.map((result) => {
|
|
1267
|
+
var _a2;
|
|
1268
|
+
return {
|
|
1269
|
+
url: result.url,
|
|
1270
|
+
title: result.title,
|
|
1271
|
+
pageAge: (_a2 = result.page_age) != null ? _a2 : null,
|
|
1272
|
+
encryptedContent: result.encrypted_content,
|
|
1273
|
+
type: result.type
|
|
1274
|
+
};
|
|
1275
|
+
}),
|
|
1276
|
+
providerExecuted: true
|
|
1277
|
+
});
|
|
1278
|
+
for (const result of part.content) {
|
|
1279
|
+
controller.enqueue({
|
|
1280
|
+
type: "source",
|
|
1281
|
+
sourceType: "url",
|
|
1282
|
+
id: generateId3(),
|
|
1283
|
+
url: result.url,
|
|
1284
|
+
title: result.title,
|
|
1285
|
+
providerMetadata: {
|
|
1286
|
+
anthropic: {
|
|
1287
|
+
pageAge: (_a = result.page_age) != null ? _a : null
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
} else {
|
|
1293
|
+
controller.enqueue({
|
|
1294
|
+
type: "tool-result",
|
|
1295
|
+
toolCallId: part.tool_use_id,
|
|
1296
|
+
toolName: "web_search",
|
|
1297
|
+
isError: true,
|
|
1298
|
+
result: {
|
|
1299
|
+
type: "web_search_tool_result_error",
|
|
1300
|
+
errorCode: part.content.error_code
|
|
1301
|
+
},
|
|
1302
|
+
providerExecuted: true
|
|
1303
|
+
});
|
|
1304
|
+
}
|
|
817
1305
|
return;
|
|
818
1306
|
}
|
|
819
1307
|
default: {
|
|
@@ -825,18 +1313,34 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
825
1313
|
}
|
|
826
1314
|
}
|
|
827
1315
|
case "content_block_stop": {
|
|
828
|
-
if (
|
|
829
|
-
const contentBlock =
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
}
|
|
1316
|
+
if (contentBlocks[value.index] != null) {
|
|
1317
|
+
const contentBlock = contentBlocks[value.index];
|
|
1318
|
+
switch (contentBlock.type) {
|
|
1319
|
+
case "text": {
|
|
1320
|
+
controller.enqueue({
|
|
1321
|
+
type: "text-end",
|
|
1322
|
+
id: String(value.index)
|
|
1323
|
+
});
|
|
1324
|
+
break;
|
|
1325
|
+
}
|
|
1326
|
+
case "reasoning": {
|
|
1327
|
+
controller.enqueue({
|
|
1328
|
+
type: "reasoning-end",
|
|
1329
|
+
id: String(value.index)
|
|
1330
|
+
});
|
|
1331
|
+
break;
|
|
1332
|
+
}
|
|
1333
|
+
case "tool-call":
|
|
1334
|
+
if (jsonResponseTool == null) {
|
|
1335
|
+
controller.enqueue({
|
|
1336
|
+
type: "tool-input-end",
|
|
1337
|
+
id: contentBlock.toolCallId
|
|
1338
|
+
});
|
|
1339
|
+
controller.enqueue(contentBlock);
|
|
1340
|
+
}
|
|
1341
|
+
break;
|
|
838
1342
|
}
|
|
839
|
-
delete
|
|
1343
|
+
delete contentBlocks[value.index];
|
|
840
1344
|
}
|
|
841
1345
|
blockType = void 0;
|
|
842
1346
|
return;
|
|
@@ -849,48 +1353,68 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
849
1353
|
return;
|
|
850
1354
|
}
|
|
851
1355
|
controller.enqueue({
|
|
852
|
-
type: "text",
|
|
853
|
-
|
|
1356
|
+
type: "text-delta",
|
|
1357
|
+
id: String(value.index),
|
|
1358
|
+
delta: value.delta.text
|
|
854
1359
|
});
|
|
855
1360
|
return;
|
|
856
1361
|
}
|
|
857
1362
|
case "thinking_delta": {
|
|
858
1363
|
controller.enqueue({
|
|
859
|
-
type: "reasoning",
|
|
860
|
-
|
|
1364
|
+
type: "reasoning-delta",
|
|
1365
|
+
id: String(value.index),
|
|
1366
|
+
delta: value.delta.thinking
|
|
861
1367
|
});
|
|
862
1368
|
return;
|
|
863
1369
|
}
|
|
864
1370
|
case "signature_delta": {
|
|
865
1371
|
if (blockType === "thinking") {
|
|
866
1372
|
controller.enqueue({
|
|
867
|
-
type: "reasoning",
|
|
868
|
-
|
|
1373
|
+
type: "reasoning-delta",
|
|
1374
|
+
id: String(value.index),
|
|
1375
|
+
delta: "",
|
|
869
1376
|
providerMetadata: {
|
|
870
1377
|
anthropic: {
|
|
871
1378
|
signature: value.delta.signature
|
|
872
1379
|
}
|
|
873
1380
|
}
|
|
874
1381
|
});
|
|
875
|
-
controller.enqueue({ type: "reasoning-part-finish" });
|
|
876
1382
|
}
|
|
877
1383
|
return;
|
|
878
1384
|
}
|
|
879
1385
|
case "input_json_delta": {
|
|
880
|
-
const contentBlock =
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
} : {
|
|
886
|
-
type: "tool-call-delta",
|
|
887
|
-
toolCallType: "function",
|
|
888
|
-
toolCallId: contentBlock.toolCallId,
|
|
889
|
-
toolName: contentBlock.toolName,
|
|
890
|
-
argsTextDelta: value.delta.partial_json
|
|
1386
|
+
const contentBlock = contentBlocks[value.index];
|
|
1387
|
+
const delta = value.delta.partial_json;
|
|
1388
|
+
if (jsonResponseTool == null) {
|
|
1389
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
|
|
1390
|
+
return;
|
|
891
1391
|
}
|
|
1392
|
+
controller.enqueue({
|
|
1393
|
+
type: "tool-input-delta",
|
|
1394
|
+
id: contentBlock.toolCallId,
|
|
1395
|
+
delta
|
|
1396
|
+
});
|
|
1397
|
+
contentBlock.input += delta;
|
|
1398
|
+
} else {
|
|
1399
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1402
|
+
controller.enqueue({
|
|
1403
|
+
type: "tool-input-delta",
|
|
1404
|
+
id: contentBlock.toolCallId,
|
|
1405
|
+
delta
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1410
|
+
case "citations_delta": {
|
|
1411
|
+
const citation = value.delta.citation;
|
|
1412
|
+
processCitation(
|
|
1413
|
+
citation,
|
|
1414
|
+
citationDocuments,
|
|
1415
|
+
generateId3,
|
|
1416
|
+
(source) => controller.enqueue(source)
|
|
892
1417
|
);
|
|
893
|
-
contentBlock.jsonText += value.delta.partial_json;
|
|
894
1418
|
return;
|
|
895
1419
|
}
|
|
896
1420
|
default: {
|
|
@@ -903,22 +1427,22 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
903
1427
|
}
|
|
904
1428
|
case "message_start": {
|
|
905
1429
|
usage.inputTokens = value.message.usage.input_tokens;
|
|
906
|
-
usage.cachedInputTokens = (
|
|
1430
|
+
usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
|
|
907
1431
|
providerMetadata = {
|
|
908
1432
|
anthropic: {
|
|
909
|
-
cacheCreationInputTokens: (
|
|
1433
|
+
cacheCreationInputTokens: (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null
|
|
910
1434
|
}
|
|
911
1435
|
};
|
|
912
1436
|
controller.enqueue({
|
|
913
1437
|
type: "response-metadata",
|
|
914
|
-
id: (
|
|
915
|
-
modelId: (
|
|
1438
|
+
id: (_d = value.message.id) != null ? _d : void 0,
|
|
1439
|
+
modelId: (_e = value.message.model) != null ? _e : void 0
|
|
916
1440
|
});
|
|
917
1441
|
return;
|
|
918
1442
|
}
|
|
919
1443
|
case "message_delta": {
|
|
920
1444
|
usage.outputTokens = value.usage.output_tokens;
|
|
921
|
-
usage.totalTokens = ((
|
|
1445
|
+
usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
|
|
922
1446
|
finishReason = mapAnthropicStopReason({
|
|
923
1447
|
finishReason: value.delta.stop_reason,
|
|
924
1448
|
isJsonResponseFromTool: jsonResponseTool != null
|
|
@@ -951,273 +1475,359 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
951
1475
|
};
|
|
952
1476
|
}
|
|
953
1477
|
};
|
|
954
|
-
var anthropicMessagesResponseSchema =
|
|
955
|
-
type:
|
|
956
|
-
id:
|
|
957
|
-
model:
|
|
958
|
-
content:
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
type:
|
|
962
|
-
text:
|
|
1478
|
+
var anthropicMessagesResponseSchema = z4.object({
|
|
1479
|
+
type: z4.literal("message"),
|
|
1480
|
+
id: z4.string().nullish(),
|
|
1481
|
+
model: z4.string().nullish(),
|
|
1482
|
+
content: z4.array(
|
|
1483
|
+
z4.discriminatedUnion("type", [
|
|
1484
|
+
z4.object({
|
|
1485
|
+
type: z4.literal("text"),
|
|
1486
|
+
text: z4.string(),
|
|
1487
|
+
citations: z4.array(citationSchema).optional()
|
|
963
1488
|
}),
|
|
964
|
-
|
|
965
|
-
type:
|
|
966
|
-
thinking:
|
|
967
|
-
signature:
|
|
1489
|
+
z4.object({
|
|
1490
|
+
type: z4.literal("thinking"),
|
|
1491
|
+
thinking: z4.string(),
|
|
1492
|
+
signature: z4.string()
|
|
968
1493
|
}),
|
|
969
|
-
|
|
970
|
-
type:
|
|
971
|
-
data:
|
|
1494
|
+
z4.object({
|
|
1495
|
+
type: z4.literal("redacted_thinking"),
|
|
1496
|
+
data: z4.string()
|
|
972
1497
|
}),
|
|
973
|
-
|
|
974
|
-
type:
|
|
975
|
-
id:
|
|
976
|
-
name:
|
|
977
|
-
input:
|
|
1498
|
+
z4.object({
|
|
1499
|
+
type: z4.literal("tool_use"),
|
|
1500
|
+
id: z4.string(),
|
|
1501
|
+
name: z4.string(),
|
|
1502
|
+
input: z4.unknown()
|
|
1503
|
+
}),
|
|
1504
|
+
z4.object({
|
|
1505
|
+
type: z4.literal("server_tool_use"),
|
|
1506
|
+
id: z4.string(),
|
|
1507
|
+
name: z4.string(),
|
|
1508
|
+
input: z4.record(z4.unknown()).nullish()
|
|
1509
|
+
}),
|
|
1510
|
+
z4.object({
|
|
1511
|
+
type: z4.literal("web_search_tool_result"),
|
|
1512
|
+
tool_use_id: z4.string(),
|
|
1513
|
+
content: z4.union([
|
|
1514
|
+
z4.array(
|
|
1515
|
+
z4.object({
|
|
1516
|
+
type: z4.literal("web_search_result"),
|
|
1517
|
+
url: z4.string(),
|
|
1518
|
+
title: z4.string(),
|
|
1519
|
+
encrypted_content: z4.string(),
|
|
1520
|
+
page_age: z4.string().nullish()
|
|
1521
|
+
})
|
|
1522
|
+
),
|
|
1523
|
+
z4.object({
|
|
1524
|
+
type: z4.literal("web_search_tool_result_error"),
|
|
1525
|
+
error_code: z4.string()
|
|
1526
|
+
})
|
|
1527
|
+
])
|
|
978
1528
|
})
|
|
979
1529
|
])
|
|
980
1530
|
),
|
|
981
|
-
stop_reason:
|
|
982
|
-
usage:
|
|
983
|
-
input_tokens:
|
|
984
|
-
output_tokens:
|
|
985
|
-
cache_creation_input_tokens:
|
|
986
|
-
cache_read_input_tokens:
|
|
1531
|
+
stop_reason: z4.string().nullish(),
|
|
1532
|
+
usage: z4.object({
|
|
1533
|
+
input_tokens: z4.number(),
|
|
1534
|
+
output_tokens: z4.number(),
|
|
1535
|
+
cache_creation_input_tokens: z4.number().nullish(),
|
|
1536
|
+
cache_read_input_tokens: z4.number().nullish(),
|
|
1537
|
+
server_tool_use: z4.object({
|
|
1538
|
+
web_search_requests: z4.number()
|
|
1539
|
+
}).nullish()
|
|
987
1540
|
})
|
|
988
1541
|
});
|
|
989
|
-
var anthropicMessagesChunkSchema =
|
|
990
|
-
|
|
991
|
-
type:
|
|
992
|
-
message:
|
|
993
|
-
id:
|
|
994
|
-
model:
|
|
995
|
-
usage:
|
|
996
|
-
input_tokens:
|
|
997
|
-
output_tokens:
|
|
998
|
-
cache_creation_input_tokens:
|
|
999
|
-
cache_read_input_tokens:
|
|
1542
|
+
var anthropicMessagesChunkSchema = z4.discriminatedUnion("type", [
|
|
1543
|
+
z4.object({
|
|
1544
|
+
type: z4.literal("message_start"),
|
|
1545
|
+
message: z4.object({
|
|
1546
|
+
id: z4.string().nullish(),
|
|
1547
|
+
model: z4.string().nullish(),
|
|
1548
|
+
usage: z4.object({
|
|
1549
|
+
input_tokens: z4.number(),
|
|
1550
|
+
output_tokens: z4.number(),
|
|
1551
|
+
cache_creation_input_tokens: z4.number().nullish(),
|
|
1552
|
+
cache_read_input_tokens: z4.number().nullish()
|
|
1000
1553
|
})
|
|
1001
1554
|
})
|
|
1002
1555
|
}),
|
|
1003
|
-
|
|
1004
|
-
type:
|
|
1005
|
-
index:
|
|
1006
|
-
content_block:
|
|
1007
|
-
|
|
1008
|
-
type:
|
|
1009
|
-
text:
|
|
1556
|
+
z4.object({
|
|
1557
|
+
type: z4.literal("content_block_start"),
|
|
1558
|
+
index: z4.number(),
|
|
1559
|
+
content_block: z4.discriminatedUnion("type", [
|
|
1560
|
+
z4.object({
|
|
1561
|
+
type: z4.literal("text"),
|
|
1562
|
+
text: z4.string()
|
|
1010
1563
|
}),
|
|
1011
|
-
|
|
1012
|
-
type:
|
|
1013
|
-
thinking:
|
|
1564
|
+
z4.object({
|
|
1565
|
+
type: z4.literal("thinking"),
|
|
1566
|
+
thinking: z4.string()
|
|
1014
1567
|
}),
|
|
1015
|
-
|
|
1016
|
-
type:
|
|
1017
|
-
id:
|
|
1018
|
-
name:
|
|
1568
|
+
z4.object({
|
|
1569
|
+
type: z4.literal("tool_use"),
|
|
1570
|
+
id: z4.string(),
|
|
1571
|
+
name: z4.string()
|
|
1019
1572
|
}),
|
|
1020
|
-
|
|
1021
|
-
type:
|
|
1022
|
-
data:
|
|
1573
|
+
z4.object({
|
|
1574
|
+
type: z4.literal("redacted_thinking"),
|
|
1575
|
+
data: z4.string()
|
|
1576
|
+
}),
|
|
1577
|
+
z4.object({
|
|
1578
|
+
type: z4.literal("server_tool_use"),
|
|
1579
|
+
id: z4.string(),
|
|
1580
|
+
name: z4.string(),
|
|
1581
|
+
input: z4.record(z4.unknown()).nullish()
|
|
1582
|
+
}),
|
|
1583
|
+
z4.object({
|
|
1584
|
+
type: z4.literal("web_search_tool_result"),
|
|
1585
|
+
tool_use_id: z4.string(),
|
|
1586
|
+
content: z4.union([
|
|
1587
|
+
z4.array(
|
|
1588
|
+
z4.object({
|
|
1589
|
+
type: z4.literal("web_search_result"),
|
|
1590
|
+
url: z4.string(),
|
|
1591
|
+
title: z4.string(),
|
|
1592
|
+
encrypted_content: z4.string(),
|
|
1593
|
+
page_age: z4.string().nullish()
|
|
1594
|
+
})
|
|
1595
|
+
),
|
|
1596
|
+
z4.object({
|
|
1597
|
+
type: z4.literal("web_search_tool_result_error"),
|
|
1598
|
+
error_code: z4.string()
|
|
1599
|
+
})
|
|
1600
|
+
])
|
|
1023
1601
|
})
|
|
1024
1602
|
])
|
|
1025
1603
|
}),
|
|
1026
|
-
|
|
1027
|
-
type:
|
|
1028
|
-
index:
|
|
1029
|
-
delta:
|
|
1030
|
-
|
|
1031
|
-
type:
|
|
1032
|
-
partial_json:
|
|
1604
|
+
z4.object({
|
|
1605
|
+
type: z4.literal("content_block_delta"),
|
|
1606
|
+
index: z4.number(),
|
|
1607
|
+
delta: z4.discriminatedUnion("type", [
|
|
1608
|
+
z4.object({
|
|
1609
|
+
type: z4.literal("input_json_delta"),
|
|
1610
|
+
partial_json: z4.string()
|
|
1611
|
+
}),
|
|
1612
|
+
z4.object({
|
|
1613
|
+
type: z4.literal("text_delta"),
|
|
1614
|
+
text: z4.string()
|
|
1033
1615
|
}),
|
|
1034
|
-
|
|
1035
|
-
type:
|
|
1036
|
-
|
|
1616
|
+
z4.object({
|
|
1617
|
+
type: z4.literal("thinking_delta"),
|
|
1618
|
+
thinking: z4.string()
|
|
1037
1619
|
}),
|
|
1038
|
-
|
|
1039
|
-
type:
|
|
1040
|
-
|
|
1620
|
+
z4.object({
|
|
1621
|
+
type: z4.literal("signature_delta"),
|
|
1622
|
+
signature: z4.string()
|
|
1041
1623
|
}),
|
|
1042
|
-
|
|
1043
|
-
type:
|
|
1044
|
-
|
|
1624
|
+
z4.object({
|
|
1625
|
+
type: z4.literal("citations_delta"),
|
|
1626
|
+
citation: citationSchema
|
|
1045
1627
|
})
|
|
1046
1628
|
])
|
|
1047
1629
|
}),
|
|
1048
|
-
|
|
1049
|
-
type:
|
|
1050
|
-
index:
|
|
1630
|
+
z4.object({
|
|
1631
|
+
type: z4.literal("content_block_stop"),
|
|
1632
|
+
index: z4.number()
|
|
1051
1633
|
}),
|
|
1052
|
-
|
|
1053
|
-
type:
|
|
1054
|
-
error:
|
|
1055
|
-
type:
|
|
1056
|
-
message:
|
|
1634
|
+
z4.object({
|
|
1635
|
+
type: z4.literal("error"),
|
|
1636
|
+
error: z4.object({
|
|
1637
|
+
type: z4.string(),
|
|
1638
|
+
message: z4.string()
|
|
1057
1639
|
})
|
|
1058
1640
|
}),
|
|
1059
|
-
|
|
1060
|
-
type:
|
|
1061
|
-
delta:
|
|
1062
|
-
usage:
|
|
1641
|
+
z4.object({
|
|
1642
|
+
type: z4.literal("message_delta"),
|
|
1643
|
+
delta: z4.object({ stop_reason: z4.string().nullish() }),
|
|
1644
|
+
usage: z4.object({ output_tokens: z4.number() })
|
|
1063
1645
|
}),
|
|
1064
|
-
|
|
1065
|
-
type:
|
|
1646
|
+
z4.object({
|
|
1647
|
+
type: z4.literal("message_stop")
|
|
1066
1648
|
}),
|
|
1067
|
-
|
|
1068
|
-
type:
|
|
1649
|
+
z4.object({
|
|
1650
|
+
type: z4.literal("ping")
|
|
1069
1651
|
})
|
|
1070
1652
|
]);
|
|
1071
|
-
var anthropicReasoningMetadataSchema =
|
|
1072
|
-
signature:
|
|
1073
|
-
redactedData:
|
|
1653
|
+
var anthropicReasoningMetadataSchema = z4.object({
|
|
1654
|
+
signature: z4.string().optional(),
|
|
1655
|
+
redactedData: z4.string().optional()
|
|
1074
1656
|
});
|
|
1075
1657
|
|
|
1076
|
-
// src/
|
|
1077
|
-
import {
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1658
|
+
// src/tool/bash_20241022.ts
|
|
1659
|
+
import { createProviderDefinedToolFactory } from "@ai-sdk/provider-utils";
|
|
1660
|
+
import z5 from "zod/v4";
|
|
1661
|
+
var bash_20241022 = createProviderDefinedToolFactory({
|
|
1662
|
+
id: "anthropic.bash_20241022",
|
|
1663
|
+
name: "bash",
|
|
1664
|
+
inputSchema: z5.object({
|
|
1665
|
+
command: z5.string(),
|
|
1666
|
+
restart: z5.boolean().optional()
|
|
1667
|
+
})
|
|
1081
1668
|
});
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
command: z4.string(),
|
|
1094
|
-
restart: z4.boolean().optional()
|
|
1669
|
+
|
|
1670
|
+
// src/tool/bash_20250124.ts
|
|
1671
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory2 } from "@ai-sdk/provider-utils";
|
|
1672
|
+
import z6 from "zod/v4";
|
|
1673
|
+
var bash_20250124 = createProviderDefinedToolFactory2({
|
|
1674
|
+
id: "anthropic.bashTool_20250124",
|
|
1675
|
+
name: "bash",
|
|
1676
|
+
inputSchema: z6.object({
|
|
1677
|
+
command: z6.string(),
|
|
1678
|
+
restart: z6.boolean().optional()
|
|
1679
|
+
})
|
|
1095
1680
|
});
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1681
|
+
|
|
1682
|
+
// src/tool/computer_20241022.ts
|
|
1683
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory3 } from "@ai-sdk/provider-utils";
|
|
1684
|
+
import { z as z7 } from "zod/v4";
|
|
1685
|
+
var computer_20241022 = createProviderDefinedToolFactory3({
|
|
1686
|
+
id: "anthropic.computer_20241022",
|
|
1687
|
+
name: "computer",
|
|
1688
|
+
inputSchema: z7.object({
|
|
1689
|
+
action: z7.enum([
|
|
1690
|
+
"key",
|
|
1691
|
+
"type",
|
|
1692
|
+
"mouse_move",
|
|
1693
|
+
"left_click",
|
|
1694
|
+
"left_click_drag",
|
|
1695
|
+
"right_click",
|
|
1696
|
+
"middle_click",
|
|
1697
|
+
"double_click",
|
|
1698
|
+
"screenshot",
|
|
1699
|
+
"cursor_position"
|
|
1700
|
+
]),
|
|
1701
|
+
coordinate: z7.array(z7.number().int()).optional(),
|
|
1702
|
+
text: z7.string().optional()
|
|
1703
|
+
})
|
|
1114
1704
|
});
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1705
|
+
|
|
1706
|
+
// src/tool/computer_20250124.ts
|
|
1707
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory4 } from "@ai-sdk/provider-utils";
|
|
1708
|
+
import { z as z8 } from "zod/v4";
|
|
1709
|
+
var computer_20250124 = createProviderDefinedToolFactory4({
|
|
1710
|
+
id: "anthropic.computer_20250124",
|
|
1711
|
+
name: "computer",
|
|
1712
|
+
inputSchema: z8.object({
|
|
1713
|
+
action: z8.enum([
|
|
1714
|
+
"key",
|
|
1715
|
+
"hold_key",
|
|
1716
|
+
"type",
|
|
1717
|
+
"cursor_position",
|
|
1718
|
+
"mouse_move",
|
|
1719
|
+
"left_mouse_down",
|
|
1720
|
+
"left_mouse_up",
|
|
1721
|
+
"left_click",
|
|
1722
|
+
"left_click_drag",
|
|
1723
|
+
"right_click",
|
|
1724
|
+
"middle_click",
|
|
1725
|
+
"double_click",
|
|
1726
|
+
"triple_click",
|
|
1727
|
+
"scroll",
|
|
1728
|
+
"wait",
|
|
1729
|
+
"screenshot"
|
|
1730
|
+
]),
|
|
1731
|
+
coordinate: z8.tuple([z8.number().int(), z8.number().int()]).optional(),
|
|
1732
|
+
duration: z8.number().optional(),
|
|
1733
|
+
scroll_amount: z8.number().optional(),
|
|
1734
|
+
scroll_direction: z8.enum(["up", "down", "left", "right"]).optional(),
|
|
1735
|
+
start_coordinate: z8.tuple([z8.number().int(), z8.number().int()]).optional(),
|
|
1736
|
+
text: z8.string().optional()
|
|
1737
|
+
})
|
|
1133
1738
|
});
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
"left_click_drag",
|
|
1151
|
-
"right_click",
|
|
1152
|
-
"middle_click",
|
|
1153
|
-
"double_click",
|
|
1154
|
-
"screenshot",
|
|
1155
|
-
"cursor_position"
|
|
1156
|
-
]),
|
|
1157
|
-
coordinate: z4.array(z4.number().int()).optional(),
|
|
1158
|
-
text: z4.string().optional()
|
|
1739
|
+
|
|
1740
|
+
// src/tool/text-editor_20241022.ts
|
|
1741
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory5 } from "@ai-sdk/provider-utils";
|
|
1742
|
+
import { z as z9 } from "zod/v4";
|
|
1743
|
+
var textEditor_20241022 = createProviderDefinedToolFactory5({
|
|
1744
|
+
id: "anthropic.text_editor_20241022",
|
|
1745
|
+
name: "str_replace_editor",
|
|
1746
|
+
inputSchema: z9.object({
|
|
1747
|
+
command: z9.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
1748
|
+
path: z9.string(),
|
|
1749
|
+
file_text: z9.string().optional(),
|
|
1750
|
+
insert_line: z9.number().int().optional(),
|
|
1751
|
+
new_str: z9.string().optional(),
|
|
1752
|
+
old_str: z9.string().optional(),
|
|
1753
|
+
view_range: z9.array(z9.number().int()).optional()
|
|
1754
|
+
})
|
|
1159
1755
|
});
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
"key",
|
|
1177
|
-
"hold_key",
|
|
1178
|
-
"type",
|
|
1179
|
-
"cursor_position",
|
|
1180
|
-
"mouse_move",
|
|
1181
|
-
"left_mouse_down",
|
|
1182
|
-
"left_mouse_up",
|
|
1183
|
-
"left_click",
|
|
1184
|
-
"left_click_drag",
|
|
1185
|
-
"right_click",
|
|
1186
|
-
"middle_click",
|
|
1187
|
-
"double_click",
|
|
1188
|
-
"triple_click",
|
|
1189
|
-
"scroll",
|
|
1190
|
-
"wait",
|
|
1191
|
-
"screenshot"
|
|
1192
|
-
]),
|
|
1193
|
-
coordinate: z4.tuple([z4.number().int(), z4.number().int()]).optional(),
|
|
1194
|
-
duration: z4.number().optional(),
|
|
1195
|
-
scroll_amount: z4.number().optional(),
|
|
1196
|
-
scroll_direction: z4.enum(["up", "down", "left", "right"]).optional(),
|
|
1197
|
-
start_coordinate: z4.tuple([z4.number().int(), z4.number().int()]).optional(),
|
|
1198
|
-
text: z4.string().optional()
|
|
1756
|
+
|
|
1757
|
+
// src/tool/text-editor_20250124.ts
|
|
1758
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory6 } from "@ai-sdk/provider-utils";
|
|
1759
|
+
import { z as z10 } from "zod/v4";
|
|
1760
|
+
var textEditor_20250124 = createProviderDefinedToolFactory6({
|
|
1761
|
+
id: "anthropic.text_editor_20250124",
|
|
1762
|
+
name: "str_replace_editor",
|
|
1763
|
+
inputSchema: z10.object({
|
|
1764
|
+
command: z10.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
1765
|
+
path: z10.string(),
|
|
1766
|
+
file_text: z10.string().optional(),
|
|
1767
|
+
insert_line: z10.number().int().optional(),
|
|
1768
|
+
new_str: z10.string().optional(),
|
|
1769
|
+
old_str: z10.string().optional(),
|
|
1770
|
+
view_range: z10.array(z10.number().int()).optional()
|
|
1771
|
+
})
|
|
1199
1772
|
});
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
type: "provider-defined",
|
|
1203
|
-
id: "anthropic.computer_20250124",
|
|
1204
|
-
args: {
|
|
1205
|
-
displayWidthPx: options.displayWidthPx,
|
|
1206
|
-
displayHeightPx: options.displayHeightPx,
|
|
1207
|
-
displayNumber: options.displayNumber
|
|
1208
|
-
},
|
|
1209
|
-
parameters: Computer20250124Parameters,
|
|
1210
|
-
execute: options.execute,
|
|
1211
|
-
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1212
|
-
};
|
|
1213
|
-
}
|
|
1773
|
+
|
|
1774
|
+
// src/anthropic-tools.ts
|
|
1214
1775
|
var anthropicTools = {
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1776
|
+
/**
|
|
1777
|
+
* Creates a tool for running a bash command. Must have name "bash".
|
|
1778
|
+
*
|
|
1779
|
+
* Image results are supported.
|
|
1780
|
+
*
|
|
1781
|
+
* @param execute - The function to execute the tool. Optional.
|
|
1782
|
+
*/
|
|
1783
|
+
bash_20241022,
|
|
1784
|
+
/**
|
|
1785
|
+
* Creates a tool for running a bash command. Must have name "bash".
|
|
1786
|
+
*
|
|
1787
|
+
* Image results are supported.
|
|
1788
|
+
*
|
|
1789
|
+
* @param execute - The function to execute the tool. Optional.
|
|
1790
|
+
*/
|
|
1791
|
+
bash_20250124,
|
|
1792
|
+
/**
|
|
1793
|
+
* Creates a tool for editing text. Must have name "str_replace_editor".
|
|
1794
|
+
*/
|
|
1795
|
+
textEditor_20241022,
|
|
1796
|
+
/**
|
|
1797
|
+
* Creates a tool for editing text. Must have name "str_replace_editor".
|
|
1798
|
+
*/
|
|
1799
|
+
textEditor_20250124,
|
|
1800
|
+
/**
|
|
1801
|
+
* Creates a tool for executing actions on a computer. Must have name "computer".
|
|
1802
|
+
*
|
|
1803
|
+
* Image results are supported.
|
|
1804
|
+
*
|
|
1805
|
+
* @param displayWidthPx - The width of the display being controlled by the model in pixels.
|
|
1806
|
+
* @param displayHeightPx - The height of the display being controlled by the model in pixels.
|
|
1807
|
+
* @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.
|
|
1808
|
+
*/
|
|
1809
|
+
computer_20241022,
|
|
1810
|
+
/**
|
|
1811
|
+
* Creates a tool for executing actions on a computer. Must have name "computer".
|
|
1812
|
+
*
|
|
1813
|
+
* Image results are supported.
|
|
1814
|
+
*
|
|
1815
|
+
* @param displayWidthPx - The width of the display being controlled by the model in pixels.
|
|
1816
|
+
* @param displayHeightPx - The height of the display being controlled by the model in pixels.
|
|
1817
|
+
* @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.
|
|
1818
|
+
* @param execute - The function to execute the tool. Optional.
|
|
1819
|
+
*/
|
|
1820
|
+
computer_20250124,
|
|
1821
|
+
/**
|
|
1822
|
+
* Creates a web search tool that gives Claude direct access to real-time web content.
|
|
1823
|
+
* Must have name "web_search".
|
|
1824
|
+
*
|
|
1825
|
+
* @param maxUses - Maximum number of web searches Claude can perform during the conversation.
|
|
1826
|
+
* @param allowedDomains - Optional list of domains that Claude is allowed to search.
|
|
1827
|
+
* @param blockedDomains - Optional list of domains that Claude should avoid when searching.
|
|
1828
|
+
* @param userLocation - Optional user location information to provide geographically relevant search results.
|
|
1829
|
+
*/
|
|
1830
|
+
webSearch_20250305
|
|
1221
1831
|
};
|
|
1222
1832
|
|
|
1223
1833
|
// src/anthropic-provider.ts
|
|
@@ -1233,15 +1843,19 @@ function createAnthropic(options = {}) {
|
|
|
1233
1843
|
}),
|
|
1234
1844
|
...options.headers
|
|
1235
1845
|
});
|
|
1236
|
-
const createChatModel = (modelId) =>
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1846
|
+
const createChatModel = (modelId) => {
|
|
1847
|
+
var _a2;
|
|
1848
|
+
return new AnthropicMessagesLanguageModel(modelId, {
|
|
1849
|
+
provider: "anthropic.messages",
|
|
1850
|
+
baseURL,
|
|
1851
|
+
headers: getHeaders,
|
|
1852
|
+
fetch: options.fetch,
|
|
1853
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : generateId2,
|
|
1854
|
+
supportedUrls: () => ({
|
|
1855
|
+
"image/*": [/^https?:\/\/.*$/]
|
|
1856
|
+
})
|
|
1857
|
+
});
|
|
1858
|
+
};
|
|
1245
1859
|
const provider = function(modelId) {
|
|
1246
1860
|
if (new.target) {
|
|
1247
1861
|
throw new Error(
|