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