@ai-sdk/anthropic 2.0.0-alpha.9 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +91 -0
- package/dist/index.d.mts +104 -457
- package/dist/index.d.ts +104 -457
- package/dist/index.js +759 -340
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +865 -457
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +105 -364
- package/dist/internal/index.d.ts +105 -364
- package/dist/internal/index.js +755 -336
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +865 -457
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
|
|
11
11
|
// src/anthropic-messages-language-model.ts
|
|
12
12
|
import {
|
|
13
|
-
APICallError,
|
|
14
13
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
15
14
|
} from "@ai-sdk/provider";
|
|
16
15
|
import {
|
|
@@ -22,7 +21,7 @@ import {
|
|
|
22
21
|
postJsonToApi,
|
|
23
22
|
resolve
|
|
24
23
|
} from "@ai-sdk/provider-utils";
|
|
25
|
-
import { z as
|
|
24
|
+
import { z as z4 } from "zod";
|
|
26
25
|
|
|
27
26
|
// src/anthropic-error.ts
|
|
28
27
|
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
@@ -41,48 +40,34 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
41
40
|
|
|
42
41
|
// src/anthropic-messages-options.ts
|
|
43
42
|
import { z as z2 } from "zod";
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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(),
|
|
59
|
+
/**
|
|
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()
|
|
50
65
|
});
|
|
51
66
|
var anthropicProviderOptions = z2.object({
|
|
52
|
-
/**
|
|
53
|
-
Include reasoning content in requests sent to the model. Defaults to `true`.
|
|
54
|
-
|
|
55
|
-
If you are experiencing issues with the model handling requests involving
|
|
56
|
-
*/
|
|
57
67
|
sendReasoning: z2.boolean().optional(),
|
|
58
68
|
thinking: z2.object({
|
|
59
69
|
type: z2.union([z2.literal("enabled"), z2.literal("disabled")]),
|
|
60
70
|
budgetTokens: z2.number().optional()
|
|
61
|
-
}).optional(),
|
|
62
|
-
/**
|
|
63
|
-
* Web search tool configuration for Claude models that support it.
|
|
64
|
-
* When provided, automatically adds the web search tool to the request.
|
|
65
|
-
*/
|
|
66
|
-
webSearch: z2.object({
|
|
67
|
-
/**
|
|
68
|
-
* Limit the number of searches per request (optional)
|
|
69
|
-
* Defaults to 5 if not specified
|
|
70
|
-
*/
|
|
71
|
-
maxUses: z2.number().min(1).max(20).optional(),
|
|
72
|
-
/**
|
|
73
|
-
* Only include results from these domains (optional)
|
|
74
|
-
* Cannot be used with blockedDomains
|
|
75
|
-
*/
|
|
76
|
-
allowedDomains: z2.array(z2.string()).optional(),
|
|
77
|
-
/**
|
|
78
|
-
* Never include results from these domains (optional)
|
|
79
|
-
* Cannot be used with allowedDomains
|
|
80
|
-
*/
|
|
81
|
-
blockedDomains: z2.array(z2.string()).optional(),
|
|
82
|
-
/**
|
|
83
|
-
* Localize search results based on user location (optional)
|
|
84
|
-
*/
|
|
85
|
-
userLocation: webSearchLocationSchema.optional()
|
|
86
71
|
}).optional()
|
|
87
72
|
});
|
|
88
73
|
|
|
@@ -90,6 +75,56 @@ var anthropicProviderOptions = z2.object({
|
|
|
90
75
|
import {
|
|
91
76
|
UnsupportedFunctionalityError
|
|
92
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
|
|
93
128
|
function isWebSearchTool(tool) {
|
|
94
129
|
return typeof tool === "object" && tool !== null && "type" in tool && tool.type === "web_search_20250305";
|
|
95
130
|
}
|
|
@@ -114,7 +149,7 @@ function prepareTools({
|
|
|
114
149
|
anthropicTools2.push({
|
|
115
150
|
name: tool.name,
|
|
116
151
|
description: tool.description,
|
|
117
|
-
input_schema: tool.
|
|
152
|
+
input_schema: tool.inputSchema
|
|
118
153
|
});
|
|
119
154
|
break;
|
|
120
155
|
case "provider-defined":
|
|
@@ -122,7 +157,7 @@ function prepareTools({
|
|
|
122
157
|
case "anthropic.computer_20250124":
|
|
123
158
|
betas.add("computer-use-2025-01-24");
|
|
124
159
|
anthropicTools2.push({
|
|
125
|
-
name:
|
|
160
|
+
name: "computer",
|
|
126
161
|
type: "computer_20250124",
|
|
127
162
|
display_width_px: tool.args.displayWidthPx,
|
|
128
163
|
display_height_px: tool.args.displayHeightPx,
|
|
@@ -132,7 +167,7 @@ function prepareTools({
|
|
|
132
167
|
case "anthropic.computer_20241022":
|
|
133
168
|
betas.add("computer-use-2024-10-22");
|
|
134
169
|
anthropicTools2.push({
|
|
135
|
-
name:
|
|
170
|
+
name: "computer",
|
|
136
171
|
type: "computer_20241022",
|
|
137
172
|
display_width_px: tool.args.displayWidthPx,
|
|
138
173
|
display_height_px: tool.args.displayHeightPx,
|
|
@@ -142,31 +177,43 @@ function prepareTools({
|
|
|
142
177
|
case "anthropic.text_editor_20250124":
|
|
143
178
|
betas.add("computer-use-2025-01-24");
|
|
144
179
|
anthropicTools2.push({
|
|
145
|
-
name:
|
|
180
|
+
name: "str_replace_editor",
|
|
146
181
|
type: "text_editor_20250124"
|
|
147
182
|
});
|
|
148
183
|
break;
|
|
149
184
|
case "anthropic.text_editor_20241022":
|
|
150
185
|
betas.add("computer-use-2024-10-22");
|
|
151
186
|
anthropicTools2.push({
|
|
152
|
-
name:
|
|
187
|
+
name: "str_replace_editor",
|
|
153
188
|
type: "text_editor_20241022"
|
|
154
189
|
});
|
|
155
190
|
break;
|
|
156
191
|
case "anthropic.bash_20250124":
|
|
157
192
|
betas.add("computer-use-2025-01-24");
|
|
158
193
|
anthropicTools2.push({
|
|
159
|
-
name:
|
|
194
|
+
name: "bash",
|
|
160
195
|
type: "bash_20250124"
|
|
161
196
|
});
|
|
162
197
|
break;
|
|
163
198
|
case "anthropic.bash_20241022":
|
|
164
199
|
betas.add("computer-use-2024-10-22");
|
|
165
200
|
anthropicTools2.push({
|
|
166
|
-
name:
|
|
201
|
+
name: "bash",
|
|
167
202
|
type: "bash_20241022"
|
|
168
203
|
});
|
|
169
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
|
+
}
|
|
170
217
|
default:
|
|
171
218
|
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
172
219
|
break;
|
|
@@ -224,12 +271,28 @@ import {
|
|
|
224
271
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
225
272
|
} from "@ai-sdk/provider";
|
|
226
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
|
+
}
|
|
227
290
|
async function convertToAnthropicMessagesPrompt({
|
|
228
291
|
prompt,
|
|
229
292
|
sendReasoning,
|
|
230
293
|
warnings
|
|
231
294
|
}) {
|
|
232
|
-
var _a, _b, _c;
|
|
295
|
+
var _a, _b, _c, _d, _e;
|
|
233
296
|
const betas = /* @__PURE__ */ new Set();
|
|
234
297
|
const blocks = groupIntoBlocks(prompt);
|
|
235
298
|
let system = void 0;
|
|
@@ -240,6 +303,26 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
240
303
|
const cacheControlValue = (_a2 = anthropic2 == null ? void 0 : anthropic2.cacheControl) != null ? _a2 : anthropic2 == null ? void 0 : anthropic2.cache_control;
|
|
241
304
|
return cacheControlValue;
|
|
242
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
|
+
}
|
|
243
326
|
for (let i = 0; i < blocks.length; i++) {
|
|
244
327
|
const block = blocks[i];
|
|
245
328
|
const isLastBlock = i === blocks.length - 1;
|
|
@@ -293,6 +376,12 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
293
376
|
});
|
|
294
377
|
} else if (part.mediaType === "application/pdf") {
|
|
295
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
|
+
);
|
|
296
385
|
anthropicContent.push({
|
|
297
386
|
type: "document",
|
|
298
387
|
source: part.data instanceof URL ? {
|
|
@@ -303,6 +392,35 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
303
392
|
media_type: "application/pdf",
|
|
304
393
|
data: convertToBase64(part.data)
|
|
305
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
|
+
},
|
|
306
424
|
cache_control: cacheControl
|
|
307
425
|
});
|
|
308
426
|
} else {
|
|
@@ -320,33 +438,53 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
320
438
|
for (let i2 = 0; i2 < content.length; i2++) {
|
|
321
439
|
const part = content[i2];
|
|
322
440
|
const isLastPart = i2 === content.length - 1;
|
|
323
|
-
const cacheControl = (
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
text:
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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
|
+
}
|
|
345
483
|
anthropicContent.push({
|
|
346
484
|
type: "tool_result",
|
|
347
485
|
tool_use_id: part.toolCallId,
|
|
348
|
-
content:
|
|
349
|
-
is_error:
|
|
486
|
+
content: contentValue,
|
|
487
|
+
is_error: output.type === "error-text" || output.type === "error-json" ? true : void 0,
|
|
350
488
|
cache_control: cacheControl
|
|
351
489
|
});
|
|
352
490
|
}
|
|
@@ -370,7 +508,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
370
508
|
for (let k = 0; k < content.length; k++) {
|
|
371
509
|
const part = content[k];
|
|
372
510
|
const isLastContentPart = k === content.length - 1;
|
|
373
|
-
const cacheControl = (
|
|
511
|
+
const cacheControl = (_e = getCacheControl(part.providerOptions)) != null ? _e : isLastContentPart ? getCacheControl(message.providerOptions) : void 0;
|
|
374
512
|
switch (part.type) {
|
|
375
513
|
case "text": {
|
|
376
514
|
anthropicContent.push({
|
|
@@ -427,15 +565,65 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
427
565
|
break;
|
|
428
566
|
}
|
|
429
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
|
+
}
|
|
430
585
|
anthropicContent.push({
|
|
431
586
|
type: "tool_use",
|
|
432
587
|
id: part.toolCallId,
|
|
433
588
|
name: part.toolName,
|
|
434
|
-
input: part.
|
|
589
|
+
input: part.input,
|
|
435
590
|
cache_control: cacheControl
|
|
436
591
|
});
|
|
437
592
|
break;
|
|
438
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
|
+
}
|
|
439
627
|
}
|
|
440
628
|
}
|
|
441
629
|
}
|
|
@@ -519,6 +707,79 @@ function mapAnthropicStopReason({
|
|
|
519
707
|
}
|
|
520
708
|
|
|
521
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
|
+
}
|
|
522
783
|
var AnthropicMessagesLanguageModel = class {
|
|
523
784
|
constructor(modelId, config) {
|
|
524
785
|
this.specificationVersion = "v2";
|
|
@@ -592,7 +853,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
592
853
|
type: "function",
|
|
593
854
|
name: "json",
|
|
594
855
|
description: "Respond with a JSON object.",
|
|
595
|
-
|
|
856
|
+
inputSchema: responseFormat.schema
|
|
596
857
|
} : void 0;
|
|
597
858
|
const anthropicOptions = await parseProviderOptions2({
|
|
598
859
|
provider: "anthropic",
|
|
@@ -655,27 +916,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
655
916
|
}
|
|
656
917
|
baseArgs.max_tokens = maxOutputTokens + thinkingBudget;
|
|
657
918
|
}
|
|
658
|
-
let modifiedTools = tools;
|
|
659
|
-
let modifiedToolChoice = toolChoice;
|
|
660
|
-
if (anthropicOptions == null ? void 0 : anthropicOptions.webSearch) {
|
|
661
|
-
const webSearchTool = {
|
|
662
|
-
type: "web_search_20250305",
|
|
663
|
-
name: "web_search",
|
|
664
|
-
max_uses: anthropicOptions.webSearch.maxUses,
|
|
665
|
-
allowed_domains: anthropicOptions.webSearch.allowedDomains,
|
|
666
|
-
blocked_domains: anthropicOptions.webSearch.blockedDomains,
|
|
667
|
-
...anthropicOptions.webSearch.userLocation && {
|
|
668
|
-
user_location: {
|
|
669
|
-
type: anthropicOptions.webSearch.userLocation.type,
|
|
670
|
-
country: anthropicOptions.webSearch.userLocation.country,
|
|
671
|
-
city: anthropicOptions.webSearch.userLocation.city,
|
|
672
|
-
region: anthropicOptions.webSearch.userLocation.region,
|
|
673
|
-
timezone: anthropicOptions.webSearch.userLocation.timezone
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
};
|
|
677
|
-
modifiedTools = tools ? [...tools, webSearchTool] : [webSearchTool];
|
|
678
|
-
}
|
|
679
919
|
const {
|
|
680
920
|
tools: anthropicTools2,
|
|
681
921
|
toolChoice: anthropicToolChoice,
|
|
@@ -685,7 +925,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
685
925
|
jsonResponseTool != null ? {
|
|
686
926
|
tools: [jsonResponseTool],
|
|
687
927
|
toolChoice: { type: "tool", toolName: jsonResponseTool.name }
|
|
688
|
-
} : { tools:
|
|
928
|
+
} : { tools: tools != null ? tools : [], toolChoice }
|
|
689
929
|
);
|
|
690
930
|
return {
|
|
691
931
|
args: {
|
|
@@ -716,9 +956,33 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
716
956
|
var _a, _b, _c;
|
|
717
957
|
return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args)) != null ? _c : args;
|
|
718
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
|
+
}
|
|
719
982
|
async doGenerate(options) {
|
|
720
983
|
var _a, _b, _c, _d, _e;
|
|
721
984
|
const { args, warnings, betas, jsonResponseTool } = await this.getArgs(options);
|
|
985
|
+
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
722
986
|
const {
|
|
723
987
|
responseHeaders,
|
|
724
988
|
value: response,
|
|
@@ -740,6 +1004,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
740
1004
|
case "text": {
|
|
741
1005
|
if (jsonResponseTool == null) {
|
|
742
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
|
+
}
|
|
743
1017
|
}
|
|
744
1018
|
break;
|
|
745
1019
|
}
|
|
@@ -775,42 +1049,68 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
775
1049
|
text: JSON.stringify(part.input)
|
|
776
1050
|
} : {
|
|
777
1051
|
type: "tool-call",
|
|
778
|
-
toolCallType: "function",
|
|
779
1052
|
toolCallId: part.id,
|
|
780
1053
|
toolName: part.name,
|
|
781
|
-
|
|
1054
|
+
input: JSON.stringify(part.input)
|
|
782
1055
|
}
|
|
783
1056
|
);
|
|
784
1057
|
break;
|
|
785
1058
|
}
|
|
786
1059
|
case "server_tool_use": {
|
|
787
|
-
|
|
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;
|
|
788
1070
|
}
|
|
789
1071
|
case "web_search_tool_result": {
|
|
790
1072
|
if (Array.isArray(part.content)) {
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
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 {
|
|
797
1080
|
url: result.url,
|
|
798
1081
|
title: result.title,
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
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
|
|
804
1099
|
}
|
|
805
|
-
}
|
|
806
|
-
}
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
807
1102
|
}
|
|
808
|
-
} else
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
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
|
|
814
1114
|
});
|
|
815
1115
|
}
|
|
816
1116
|
break;
|
|
@@ -846,6 +1146,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
846
1146
|
}
|
|
847
1147
|
async doStream(options) {
|
|
848
1148
|
const { args, warnings, betas, jsonResponseTool } = await this.getArgs(options);
|
|
1149
|
+
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
849
1150
|
const body = { ...args, stream: true };
|
|
850
1151
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
851
1152
|
url: this.buildRequestUrl(true),
|
|
@@ -864,10 +1165,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
864
1165
|
outputTokens: void 0,
|
|
865
1166
|
totalTokens: void 0
|
|
866
1167
|
};
|
|
867
|
-
const
|
|
1168
|
+
const contentBlocks = {};
|
|
868
1169
|
let providerMetadata = void 0;
|
|
869
1170
|
let blockType = void 0;
|
|
870
|
-
const config = this.config;
|
|
871
1171
|
const generateId3 = this.generateId;
|
|
872
1172
|
return {
|
|
873
1173
|
stream: response.pipeThrough(
|
|
@@ -877,6 +1177,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
877
1177
|
},
|
|
878
1178
|
transform(chunk, controller) {
|
|
879
1179
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
1180
|
+
if (options.includeRawChunks) {
|
|
1181
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1182
|
+
}
|
|
880
1183
|
if (!chunk.success) {
|
|
881
1184
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
882
1185
|
return;
|
|
@@ -890,61 +1193,113 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
890
1193
|
const contentBlockType = value.content_block.type;
|
|
891
1194
|
blockType = contentBlockType;
|
|
892
1195
|
switch (contentBlockType) {
|
|
893
|
-
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
|
+
}
|
|
894
1204
|
case "thinking": {
|
|
1205
|
+
contentBlocks[value.index] = { type: "reasoning" };
|
|
1206
|
+
controller.enqueue({
|
|
1207
|
+
type: "reasoning-start",
|
|
1208
|
+
id: String(value.index)
|
|
1209
|
+
});
|
|
895
1210
|
return;
|
|
896
1211
|
}
|
|
897
1212
|
case "redacted_thinking": {
|
|
1213
|
+
contentBlocks[value.index] = { type: "reasoning" };
|
|
898
1214
|
controller.enqueue({
|
|
899
|
-
type: "reasoning",
|
|
900
|
-
|
|
1215
|
+
type: "reasoning-start",
|
|
1216
|
+
id: String(value.index),
|
|
901
1217
|
providerMetadata: {
|
|
902
1218
|
anthropic: {
|
|
903
1219
|
redactedData: value.content_block.data
|
|
904
1220
|
}
|
|
905
1221
|
}
|
|
906
1222
|
});
|
|
907
|
-
controller.enqueue({ type: "reasoning-part-finish" });
|
|
908
1223
|
return;
|
|
909
1224
|
}
|
|
910
1225
|
case "tool_use": {
|
|
911
|
-
|
|
1226
|
+
contentBlocks[value.index] = jsonResponseTool != null ? { type: "text" } : {
|
|
1227
|
+
type: "tool-call",
|
|
912
1228
|
toolCallId: value.content_block.id,
|
|
913
1229
|
toolName: value.content_block.name,
|
|
914
|
-
|
|
1230
|
+
input: ""
|
|
915
1231
|
};
|
|
1232
|
+
controller.enqueue(
|
|
1233
|
+
jsonResponseTool != null ? { type: "text-start", id: String(value.index) } : {
|
|
1234
|
+
type: "tool-input-start",
|
|
1235
|
+
id: value.content_block.id,
|
|
1236
|
+
toolName: value.content_block.name
|
|
1237
|
+
}
|
|
1238
|
+
);
|
|
916
1239
|
return;
|
|
917
1240
|
}
|
|
918
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
|
+
}
|
|
919
1257
|
return;
|
|
920
1258
|
}
|
|
921
1259
|
case "web_search_tool_result": {
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
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 {
|
|
929
1269
|
url: result.url,
|
|
930
1270
|
title: result.title,
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
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
|
|
936
1288
|
}
|
|
937
|
-
}
|
|
938
|
-
}
|
|
1289
|
+
}
|
|
1290
|
+
});
|
|
939
1291
|
}
|
|
940
|
-
} else
|
|
1292
|
+
} else {
|
|
941
1293
|
controller.enqueue({
|
|
942
|
-
type: "
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
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
|
|
948
1303
|
});
|
|
949
1304
|
}
|
|
950
1305
|
return;
|
|
@@ -958,18 +1313,34 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
958
1313
|
}
|
|
959
1314
|
}
|
|
960
1315
|
case "content_block_stop": {
|
|
961
|
-
if (
|
|
962
|
-
const contentBlock =
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
}
|
|
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;
|
|
971
1342
|
}
|
|
972
|
-
delete
|
|
1343
|
+
delete contentBlocks[value.index];
|
|
973
1344
|
}
|
|
974
1345
|
blockType = void 0;
|
|
975
1346
|
return;
|
|
@@ -982,54 +1353,68 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
982
1353
|
return;
|
|
983
1354
|
}
|
|
984
1355
|
controller.enqueue({
|
|
985
|
-
type: "text",
|
|
986
|
-
|
|
1356
|
+
type: "text-delta",
|
|
1357
|
+
id: String(value.index),
|
|
1358
|
+
delta: value.delta.text
|
|
987
1359
|
});
|
|
988
1360
|
return;
|
|
989
1361
|
}
|
|
990
1362
|
case "thinking_delta": {
|
|
991
1363
|
controller.enqueue({
|
|
992
|
-
type: "reasoning",
|
|
993
|
-
|
|
1364
|
+
type: "reasoning-delta",
|
|
1365
|
+
id: String(value.index),
|
|
1366
|
+
delta: value.delta.thinking
|
|
994
1367
|
});
|
|
995
1368
|
return;
|
|
996
1369
|
}
|
|
997
1370
|
case "signature_delta": {
|
|
998
1371
|
if (blockType === "thinking") {
|
|
999
1372
|
controller.enqueue({
|
|
1000
|
-
type: "reasoning",
|
|
1001
|
-
|
|
1373
|
+
type: "reasoning-delta",
|
|
1374
|
+
id: String(value.index),
|
|
1375
|
+
delta: "",
|
|
1002
1376
|
providerMetadata: {
|
|
1003
1377
|
anthropic: {
|
|
1004
1378
|
signature: value.delta.signature
|
|
1005
1379
|
}
|
|
1006
1380
|
}
|
|
1007
1381
|
});
|
|
1008
|
-
controller.enqueue({ type: "reasoning-part-finish" });
|
|
1009
1382
|
}
|
|
1010
1383
|
return;
|
|
1011
1384
|
}
|
|
1012
1385
|
case "input_json_delta": {
|
|
1013
|
-
const contentBlock =
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
jsonResponseTool != null ? {
|
|
1019
|
-
type: "text",
|
|
1020
|
-
text: value.delta.partial_json
|
|
1021
|
-
} : {
|
|
1022
|
-
type: "tool-call-delta",
|
|
1023
|
-
toolCallType: "function",
|
|
1024
|
-
toolCallId: contentBlock.toolCallId,
|
|
1025
|
-
toolName: contentBlock.toolName,
|
|
1026
|
-
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;
|
|
1027
1391
|
}
|
|
1028
|
-
|
|
1029
|
-
|
|
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
|
+
}
|
|
1030
1408
|
return;
|
|
1031
1409
|
}
|
|
1032
1410
|
case "citations_delta": {
|
|
1411
|
+
const citation = value.delta.citation;
|
|
1412
|
+
processCitation(
|
|
1413
|
+
citation,
|
|
1414
|
+
citationDocuments,
|
|
1415
|
+
generateId3,
|
|
1416
|
+
(source) => controller.enqueue(source)
|
|
1417
|
+
);
|
|
1033
1418
|
return;
|
|
1034
1419
|
}
|
|
1035
1420
|
default: {
|
|
@@ -1090,336 +1475,359 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1090
1475
|
};
|
|
1091
1476
|
}
|
|
1092
1477
|
};
|
|
1093
|
-
var anthropicMessagesResponseSchema =
|
|
1094
|
-
type:
|
|
1095
|
-
id:
|
|
1096
|
-
model:
|
|
1097
|
-
content:
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
type:
|
|
1101
|
-
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()
|
|
1102
1488
|
}),
|
|
1103
|
-
|
|
1104
|
-
type:
|
|
1105
|
-
thinking:
|
|
1106
|
-
signature:
|
|
1489
|
+
z4.object({
|
|
1490
|
+
type: z4.literal("thinking"),
|
|
1491
|
+
thinking: z4.string(),
|
|
1492
|
+
signature: z4.string()
|
|
1107
1493
|
}),
|
|
1108
|
-
|
|
1109
|
-
type:
|
|
1110
|
-
data:
|
|
1494
|
+
z4.object({
|
|
1495
|
+
type: z4.literal("redacted_thinking"),
|
|
1496
|
+
data: z4.string()
|
|
1111
1497
|
}),
|
|
1112
|
-
|
|
1113
|
-
type:
|
|
1114
|
-
id:
|
|
1115
|
-
name:
|
|
1116
|
-
input:
|
|
1498
|
+
z4.object({
|
|
1499
|
+
type: z4.literal("tool_use"),
|
|
1500
|
+
id: z4.string(),
|
|
1501
|
+
name: z4.string(),
|
|
1502
|
+
input: z4.unknown()
|
|
1117
1503
|
}),
|
|
1118
|
-
|
|
1119
|
-
type:
|
|
1120
|
-
id:
|
|
1121
|
-
name:
|
|
1122
|
-
input:
|
|
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()
|
|
1123
1509
|
}),
|
|
1124
|
-
|
|
1125
|
-
type:
|
|
1126
|
-
tool_use_id:
|
|
1127
|
-
content:
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
type:
|
|
1131
|
-
url:
|
|
1132
|
-
title:
|
|
1133
|
-
encrypted_content:
|
|
1134
|
-
page_age:
|
|
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()
|
|
1135
1521
|
})
|
|
1136
1522
|
),
|
|
1137
|
-
|
|
1138
|
-
type:
|
|
1139
|
-
error_code:
|
|
1523
|
+
z4.object({
|
|
1524
|
+
type: z4.literal("web_search_tool_result_error"),
|
|
1525
|
+
error_code: z4.string()
|
|
1140
1526
|
})
|
|
1141
1527
|
])
|
|
1142
1528
|
})
|
|
1143
1529
|
])
|
|
1144
1530
|
),
|
|
1145
|
-
stop_reason:
|
|
1146
|
-
usage:
|
|
1147
|
-
input_tokens:
|
|
1148
|
-
output_tokens:
|
|
1149
|
-
cache_creation_input_tokens:
|
|
1150
|
-
cache_read_input_tokens:
|
|
1151
|
-
server_tool_use:
|
|
1152
|
-
web_search_requests:
|
|
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()
|
|
1153
1539
|
}).nullish()
|
|
1154
1540
|
})
|
|
1155
1541
|
});
|
|
1156
|
-
var anthropicMessagesChunkSchema =
|
|
1157
|
-
|
|
1158
|
-
type:
|
|
1159
|
-
message:
|
|
1160
|
-
id:
|
|
1161
|
-
model:
|
|
1162
|
-
usage:
|
|
1163
|
-
input_tokens:
|
|
1164
|
-
output_tokens:
|
|
1165
|
-
cache_creation_input_tokens:
|
|
1166
|
-
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()
|
|
1167
1553
|
})
|
|
1168
1554
|
})
|
|
1169
1555
|
}),
|
|
1170
|
-
|
|
1171
|
-
type:
|
|
1172
|
-
index:
|
|
1173
|
-
content_block:
|
|
1174
|
-
|
|
1175
|
-
type:
|
|
1176
|
-
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()
|
|
1177
1563
|
}),
|
|
1178
|
-
|
|
1179
|
-
type:
|
|
1180
|
-
thinking:
|
|
1564
|
+
z4.object({
|
|
1565
|
+
type: z4.literal("thinking"),
|
|
1566
|
+
thinking: z4.string()
|
|
1181
1567
|
}),
|
|
1182
|
-
|
|
1183
|
-
type:
|
|
1184
|
-
id:
|
|
1185
|
-
name:
|
|
1568
|
+
z4.object({
|
|
1569
|
+
type: z4.literal("tool_use"),
|
|
1570
|
+
id: z4.string(),
|
|
1571
|
+
name: z4.string()
|
|
1186
1572
|
}),
|
|
1187
|
-
|
|
1188
|
-
type:
|
|
1189
|
-
data:
|
|
1573
|
+
z4.object({
|
|
1574
|
+
type: z4.literal("redacted_thinking"),
|
|
1575
|
+
data: z4.string()
|
|
1190
1576
|
}),
|
|
1191
|
-
|
|
1192
|
-
type:
|
|
1193
|
-
id:
|
|
1194
|
-
name:
|
|
1195
|
-
input:
|
|
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()
|
|
1196
1582
|
}),
|
|
1197
|
-
|
|
1198
|
-
type:
|
|
1199
|
-
tool_use_id:
|
|
1200
|
-
content:
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
type:
|
|
1204
|
-
url:
|
|
1205
|
-
title:
|
|
1206
|
-
encrypted_content:
|
|
1207
|
-
page_age:
|
|
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()
|
|
1208
1594
|
})
|
|
1209
1595
|
),
|
|
1210
|
-
|
|
1211
|
-
type:
|
|
1212
|
-
error_code:
|
|
1596
|
+
z4.object({
|
|
1597
|
+
type: z4.literal("web_search_tool_result_error"),
|
|
1598
|
+
error_code: z4.string()
|
|
1213
1599
|
})
|
|
1214
1600
|
])
|
|
1215
1601
|
})
|
|
1216
1602
|
])
|
|
1217
1603
|
}),
|
|
1218
|
-
|
|
1219
|
-
type:
|
|
1220
|
-
index:
|
|
1221
|
-
delta:
|
|
1222
|
-
|
|
1223
|
-
type:
|
|
1224
|
-
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()
|
|
1225
1611
|
}),
|
|
1226
|
-
|
|
1227
|
-
type:
|
|
1228
|
-
text:
|
|
1612
|
+
z4.object({
|
|
1613
|
+
type: z4.literal("text_delta"),
|
|
1614
|
+
text: z4.string()
|
|
1229
1615
|
}),
|
|
1230
|
-
|
|
1231
|
-
type:
|
|
1232
|
-
thinking:
|
|
1616
|
+
z4.object({
|
|
1617
|
+
type: z4.literal("thinking_delta"),
|
|
1618
|
+
thinking: z4.string()
|
|
1233
1619
|
}),
|
|
1234
|
-
|
|
1235
|
-
type:
|
|
1236
|
-
signature:
|
|
1620
|
+
z4.object({
|
|
1621
|
+
type: z4.literal("signature_delta"),
|
|
1622
|
+
signature: z4.string()
|
|
1237
1623
|
}),
|
|
1238
|
-
|
|
1239
|
-
type:
|
|
1240
|
-
citation:
|
|
1241
|
-
type: z3.literal("web_search_result_location"),
|
|
1242
|
-
cited_text: z3.string(),
|
|
1243
|
-
url: z3.string(),
|
|
1244
|
-
title: z3.string(),
|
|
1245
|
-
encrypted_index: z3.string()
|
|
1246
|
-
})
|
|
1624
|
+
z4.object({
|
|
1625
|
+
type: z4.literal("citations_delta"),
|
|
1626
|
+
citation: citationSchema
|
|
1247
1627
|
})
|
|
1248
1628
|
])
|
|
1249
1629
|
}),
|
|
1250
|
-
|
|
1251
|
-
type:
|
|
1252
|
-
index:
|
|
1630
|
+
z4.object({
|
|
1631
|
+
type: z4.literal("content_block_stop"),
|
|
1632
|
+
index: z4.number()
|
|
1253
1633
|
}),
|
|
1254
|
-
|
|
1255
|
-
type:
|
|
1256
|
-
error:
|
|
1257
|
-
type:
|
|
1258
|
-
message:
|
|
1634
|
+
z4.object({
|
|
1635
|
+
type: z4.literal("error"),
|
|
1636
|
+
error: z4.object({
|
|
1637
|
+
type: z4.string(),
|
|
1638
|
+
message: z4.string()
|
|
1259
1639
|
})
|
|
1260
1640
|
}),
|
|
1261
|
-
|
|
1262
|
-
type:
|
|
1263
|
-
delta:
|
|
1264
|
-
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() })
|
|
1265
1645
|
}),
|
|
1266
|
-
|
|
1267
|
-
type:
|
|
1646
|
+
z4.object({
|
|
1647
|
+
type: z4.literal("message_stop")
|
|
1268
1648
|
}),
|
|
1269
|
-
|
|
1270
|
-
type:
|
|
1649
|
+
z4.object({
|
|
1650
|
+
type: z4.literal("ping")
|
|
1271
1651
|
})
|
|
1272
1652
|
]);
|
|
1273
|
-
var anthropicReasoningMetadataSchema =
|
|
1274
|
-
signature:
|
|
1275
|
-
redactedData:
|
|
1653
|
+
var anthropicReasoningMetadataSchema = z4.object({
|
|
1654
|
+
signature: z4.string().optional(),
|
|
1655
|
+
redactedData: z4.string().optional()
|
|
1276
1656
|
});
|
|
1277
1657
|
|
|
1278
|
-
// src/
|
|
1279
|
-
import {
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
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
|
+
})
|
|
1283
1668
|
});
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
command: z4.string(),
|
|
1296
|
-
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
|
+
})
|
|
1297
1680
|
});
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
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
|
+
})
|
|
1316
1704
|
});
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
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
|
+
})
|
|
1335
1738
|
});
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
"left_click_drag",
|
|
1353
|
-
"right_click",
|
|
1354
|
-
"middle_click",
|
|
1355
|
-
"double_click",
|
|
1356
|
-
"screenshot",
|
|
1357
|
-
"cursor_position"
|
|
1358
|
-
]),
|
|
1359
|
-
coordinate: z4.array(z4.number().int()).optional(),
|
|
1360
|
-
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
|
+
})
|
|
1361
1755
|
});
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
"key",
|
|
1379
|
-
"hold_key",
|
|
1380
|
-
"type",
|
|
1381
|
-
"cursor_position",
|
|
1382
|
-
"mouse_move",
|
|
1383
|
-
"left_mouse_down",
|
|
1384
|
-
"left_mouse_up",
|
|
1385
|
-
"left_click",
|
|
1386
|
-
"left_click_drag",
|
|
1387
|
-
"right_click",
|
|
1388
|
-
"middle_click",
|
|
1389
|
-
"double_click",
|
|
1390
|
-
"triple_click",
|
|
1391
|
-
"scroll",
|
|
1392
|
-
"wait",
|
|
1393
|
-
"screenshot"
|
|
1394
|
-
]),
|
|
1395
|
-
coordinate: z4.tuple([z4.number().int(), z4.number().int()]).optional(),
|
|
1396
|
-
duration: z4.number().optional(),
|
|
1397
|
-
scroll_amount: z4.number().optional(),
|
|
1398
|
-
scroll_direction: z4.enum(["up", "down", "left", "right"]).optional(),
|
|
1399
|
-
start_coordinate: z4.tuple([z4.number().int(), z4.number().int()]).optional(),
|
|
1400
|
-
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
|
+
})
|
|
1401
1772
|
});
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
type: "provider-defined",
|
|
1405
|
-
id: "anthropic.computer_20250124",
|
|
1406
|
-
args: {
|
|
1407
|
-
displayWidthPx: options.displayWidthPx,
|
|
1408
|
-
displayHeightPx: options.displayHeightPx,
|
|
1409
|
-
displayNumber: options.displayNumber
|
|
1410
|
-
},
|
|
1411
|
-
parameters: Computer20250124Parameters,
|
|
1412
|
-
execute: options.execute,
|
|
1413
|
-
experimental_toToolResultContent: options.experimental_toToolResultContent
|
|
1414
|
-
};
|
|
1415
|
-
}
|
|
1773
|
+
|
|
1774
|
+
// src/anthropic-tools.ts
|
|
1416
1775
|
var anthropicTools = {
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
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
|
|
1423
1831
|
};
|
|
1424
1832
|
|
|
1425
1833
|
// src/anthropic-provider.ts
|