@ai-sdk/anthropic 2.0.0-canary.8 → 2.0.0
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 +490 -0
- package/README.md +2 -2
- package/dist/index.d.mts +129 -421
- package/dist/index.d.ts +129 -421
- package/dist/index.js +1174 -407
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1150 -391
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +178 -395
- package/dist/internal/index.d.ts +178 -395
- package/dist/internal/index.js +1160 -397
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +1136 -383
- package/dist/internal/index.mjs.map +1 -1
- package/internal.d.ts +1 -0
- package/package.json +11 -8
package/dist/internal/index.mjs
CHANGED
|
@@ -6,15 +6,16 @@ import {
|
|
|
6
6
|
combineHeaders,
|
|
7
7
|
createEventSourceResponseHandler,
|
|
8
8
|
createJsonResponseHandler,
|
|
9
|
-
|
|
9
|
+
generateId,
|
|
10
|
+
parseProviderOptions as parseProviderOptions2,
|
|
10
11
|
postJsonToApi,
|
|
11
12
|
resolve
|
|
12
13
|
} from "@ai-sdk/provider-utils";
|
|
13
|
-
import { z as
|
|
14
|
+
import { z as z4 } from "zod/v4";
|
|
14
15
|
|
|
15
16
|
// src/anthropic-error.ts
|
|
16
17
|
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
17
|
-
import { z } from "zod";
|
|
18
|
+
import { z } from "zod/v4";
|
|
18
19
|
var anthropicErrorDataSchema = z.object({
|
|
19
20
|
type: z.literal("error"),
|
|
20
21
|
error: z.object({
|
|
@@ -27,13 +28,113 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
27
28
|
errorToMessage: (data) => data.error.message
|
|
28
29
|
});
|
|
29
30
|
|
|
31
|
+
// src/anthropic-messages-options.ts
|
|
32
|
+
import { z as z2 } from "zod/v4";
|
|
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()
|
|
55
|
+
});
|
|
56
|
+
var anthropicProviderOptions = z2.object({
|
|
57
|
+
sendReasoning: z2.boolean().optional(),
|
|
58
|
+
thinking: z2.object({
|
|
59
|
+
type: z2.union([z2.literal("enabled"), z2.literal("disabled")]),
|
|
60
|
+
budgetTokens: z2.number().optional()
|
|
61
|
+
}).optional(),
|
|
62
|
+
/**
|
|
63
|
+
* Whether to disable parallel function calling during tool use. Default is false.
|
|
64
|
+
* When set to true, Claude will use at most one tool per response.
|
|
65
|
+
*/
|
|
66
|
+
disableParallelToolUse: z2.boolean().optional()
|
|
67
|
+
});
|
|
68
|
+
|
|
30
69
|
// src/anthropic-prepare-tools.ts
|
|
31
70
|
import {
|
|
32
71
|
UnsupportedFunctionalityError
|
|
33
72
|
} from "@ai-sdk/provider";
|
|
73
|
+
|
|
74
|
+
// src/get-cache-control.ts
|
|
75
|
+
function getCacheControl(providerMetadata) {
|
|
76
|
+
var _a;
|
|
77
|
+
const anthropic = providerMetadata == null ? void 0 : providerMetadata.anthropic;
|
|
78
|
+
const cacheControlValue = (_a = anthropic == null ? void 0 : anthropic.cacheControl) != null ? _a : anthropic == null ? void 0 : anthropic.cache_control;
|
|
79
|
+
return cacheControlValue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/tool/web-search_20250305.ts
|
|
83
|
+
import { createProviderDefinedToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils";
|
|
84
|
+
import { z as z3 } from "zod/v4";
|
|
85
|
+
var webSearch_20250305ArgsSchema = z3.object({
|
|
86
|
+
/**
|
|
87
|
+
* Maximum number of web searches Claude can perform during the conversation.
|
|
88
|
+
*/
|
|
89
|
+
maxUses: z3.number().optional(),
|
|
90
|
+
/**
|
|
91
|
+
* Optional list of domains that Claude is allowed to search.
|
|
92
|
+
*/
|
|
93
|
+
allowedDomains: z3.array(z3.string()).optional(),
|
|
94
|
+
/**
|
|
95
|
+
* Optional list of domains that Claude should avoid when searching.
|
|
96
|
+
*/
|
|
97
|
+
blockedDomains: z3.array(z3.string()).optional(),
|
|
98
|
+
/**
|
|
99
|
+
* Optional user location information to provide geographically relevant search results.
|
|
100
|
+
*/
|
|
101
|
+
userLocation: z3.object({
|
|
102
|
+
type: z3.literal("approximate"),
|
|
103
|
+
city: z3.string().optional(),
|
|
104
|
+
region: z3.string().optional(),
|
|
105
|
+
country: z3.string().optional(),
|
|
106
|
+
timezone: z3.string().optional()
|
|
107
|
+
}).optional()
|
|
108
|
+
});
|
|
109
|
+
var webSearch_20250305OutputSchema = z3.array(
|
|
110
|
+
z3.object({
|
|
111
|
+
url: z3.string(),
|
|
112
|
+
title: z3.string(),
|
|
113
|
+
pageAge: z3.string().nullable(),
|
|
114
|
+
encryptedContent: z3.string(),
|
|
115
|
+
type: z3.string()
|
|
116
|
+
})
|
|
117
|
+
);
|
|
118
|
+
var factory = createProviderDefinedToolFactoryWithOutputSchema({
|
|
119
|
+
id: "anthropic.web_search_20250305",
|
|
120
|
+
name: "web_search",
|
|
121
|
+
inputSchema: z3.object({
|
|
122
|
+
query: z3.string()
|
|
123
|
+
}),
|
|
124
|
+
outputSchema: webSearch_20250305OutputSchema
|
|
125
|
+
});
|
|
126
|
+
var webSearch_20250305 = (args = {}) => {
|
|
127
|
+
return factory(args);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/anthropic-prepare-tools.ts
|
|
131
|
+
function isWebSearchTool(tool) {
|
|
132
|
+
return typeof tool === "object" && tool !== null && "type" in tool && tool.type === "web_search_20250305";
|
|
133
|
+
}
|
|
34
134
|
function prepareTools({
|
|
35
135
|
tools,
|
|
36
|
-
toolChoice
|
|
136
|
+
toolChoice,
|
|
137
|
+
disableParallelToolUse
|
|
37
138
|
}) {
|
|
38
139
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
39
140
|
const toolWarnings = [];
|
|
@@ -43,12 +144,18 @@ function prepareTools({
|
|
|
43
144
|
}
|
|
44
145
|
const anthropicTools2 = [];
|
|
45
146
|
for (const tool of tools) {
|
|
147
|
+
if (isWebSearchTool(tool)) {
|
|
148
|
+
anthropicTools2.push(tool);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
46
151
|
switch (tool.type) {
|
|
47
152
|
case "function":
|
|
153
|
+
const cacheControl = getCacheControl(tool.providerOptions);
|
|
48
154
|
anthropicTools2.push({
|
|
49
155
|
name: tool.name,
|
|
50
156
|
description: tool.description,
|
|
51
|
-
input_schema: tool.
|
|
157
|
+
input_schema: tool.inputSchema,
|
|
158
|
+
cache_control: cacheControl
|
|
52
159
|
});
|
|
53
160
|
break;
|
|
54
161
|
case "provider-defined":
|
|
@@ -56,7 +163,7 @@ function prepareTools({
|
|
|
56
163
|
case "anthropic.computer_20250124":
|
|
57
164
|
betas.add("computer-use-2025-01-24");
|
|
58
165
|
anthropicTools2.push({
|
|
59
|
-
name:
|
|
166
|
+
name: "computer",
|
|
60
167
|
type: "computer_20250124",
|
|
61
168
|
display_width_px: tool.args.displayWidthPx,
|
|
62
169
|
display_height_px: tool.args.displayHeightPx,
|
|
@@ -66,7 +173,7 @@ function prepareTools({
|
|
|
66
173
|
case "anthropic.computer_20241022":
|
|
67
174
|
betas.add("computer-use-2024-10-22");
|
|
68
175
|
anthropicTools2.push({
|
|
69
|
-
name:
|
|
176
|
+
name: "computer",
|
|
70
177
|
type: "computer_20241022",
|
|
71
178
|
display_width_px: tool.args.displayWidthPx,
|
|
72
179
|
display_height_px: tool.args.displayHeightPx,
|
|
@@ -76,31 +183,50 @@ function prepareTools({
|
|
|
76
183
|
case "anthropic.text_editor_20250124":
|
|
77
184
|
betas.add("computer-use-2025-01-24");
|
|
78
185
|
anthropicTools2.push({
|
|
79
|
-
name:
|
|
186
|
+
name: "str_replace_editor",
|
|
80
187
|
type: "text_editor_20250124"
|
|
81
188
|
});
|
|
82
189
|
break;
|
|
83
190
|
case "anthropic.text_editor_20241022":
|
|
84
191
|
betas.add("computer-use-2024-10-22");
|
|
85
192
|
anthropicTools2.push({
|
|
86
|
-
name:
|
|
193
|
+
name: "str_replace_editor",
|
|
87
194
|
type: "text_editor_20241022"
|
|
88
195
|
});
|
|
89
196
|
break;
|
|
197
|
+
case "anthropic.text_editor_20250429":
|
|
198
|
+
betas.add("computer-use-2025-01-24");
|
|
199
|
+
anthropicTools2.push({
|
|
200
|
+
name: "str_replace_based_edit_tool",
|
|
201
|
+
type: "text_editor_20250429"
|
|
202
|
+
});
|
|
203
|
+
break;
|
|
90
204
|
case "anthropic.bash_20250124":
|
|
91
205
|
betas.add("computer-use-2025-01-24");
|
|
92
206
|
anthropicTools2.push({
|
|
93
|
-
name:
|
|
207
|
+
name: "bash",
|
|
94
208
|
type: "bash_20250124"
|
|
95
209
|
});
|
|
96
210
|
break;
|
|
97
211
|
case "anthropic.bash_20241022":
|
|
98
212
|
betas.add("computer-use-2024-10-22");
|
|
99
213
|
anthropicTools2.push({
|
|
100
|
-
name:
|
|
214
|
+
name: "bash",
|
|
101
215
|
type: "bash_20241022"
|
|
102
216
|
});
|
|
103
217
|
break;
|
|
218
|
+
case "anthropic.web_search_20250305": {
|
|
219
|
+
const args = webSearch_20250305ArgsSchema.parse(tool.args);
|
|
220
|
+
anthropicTools2.push({
|
|
221
|
+
type: "web_search_20250305",
|
|
222
|
+
name: "web_search",
|
|
223
|
+
max_uses: args.maxUses,
|
|
224
|
+
allowed_domains: args.allowedDomains,
|
|
225
|
+
blocked_domains: args.blockedDomains,
|
|
226
|
+
user_location: args.userLocation
|
|
227
|
+
});
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
104
230
|
default:
|
|
105
231
|
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
106
232
|
break;
|
|
@@ -114,7 +240,7 @@ function prepareTools({
|
|
|
114
240
|
if (toolChoice == null) {
|
|
115
241
|
return {
|
|
116
242
|
tools: anthropicTools2,
|
|
117
|
-
toolChoice: void 0,
|
|
243
|
+
toolChoice: disableParallelToolUse ? { type: "auto", disable_parallel_tool_use: disableParallelToolUse } : void 0,
|
|
118
244
|
toolWarnings,
|
|
119
245
|
betas
|
|
120
246
|
};
|
|
@@ -124,14 +250,20 @@ function prepareTools({
|
|
|
124
250
|
case "auto":
|
|
125
251
|
return {
|
|
126
252
|
tools: anthropicTools2,
|
|
127
|
-
toolChoice: {
|
|
253
|
+
toolChoice: {
|
|
254
|
+
type: "auto",
|
|
255
|
+
disable_parallel_tool_use: disableParallelToolUse
|
|
256
|
+
},
|
|
128
257
|
toolWarnings,
|
|
129
258
|
betas
|
|
130
259
|
};
|
|
131
260
|
case "required":
|
|
132
261
|
return {
|
|
133
262
|
tools: anthropicTools2,
|
|
134
|
-
toolChoice: {
|
|
263
|
+
toolChoice: {
|
|
264
|
+
type: "any",
|
|
265
|
+
disable_parallel_tool_use: disableParallelToolUse
|
|
266
|
+
},
|
|
135
267
|
toolWarnings,
|
|
136
268
|
betas
|
|
137
269
|
};
|
|
@@ -140,7 +272,11 @@ function prepareTools({
|
|
|
140
272
|
case "tool":
|
|
141
273
|
return {
|
|
142
274
|
tools: anthropicTools2,
|
|
143
|
-
toolChoice: {
|
|
275
|
+
toolChoice: {
|
|
276
|
+
type: "tool",
|
|
277
|
+
name: toolChoice.toolName,
|
|
278
|
+
disable_parallel_tool_use: disableParallelToolUse
|
|
279
|
+
},
|
|
144
280
|
toolWarnings,
|
|
145
281
|
betas
|
|
146
282
|
};
|
|
@@ -157,22 +293,52 @@ function prepareTools({
|
|
|
157
293
|
import {
|
|
158
294
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
159
295
|
} from "@ai-sdk/provider";
|
|
160
|
-
import { convertToBase64 } from "@ai-sdk/provider-utils";
|
|
161
|
-
function
|
|
296
|
+
import { convertToBase64, parseProviderOptions } from "@ai-sdk/provider-utils";
|
|
297
|
+
function convertToString(data) {
|
|
298
|
+
if (typeof data === "string") {
|
|
299
|
+
return Buffer.from(data, "base64").toString("utf-8");
|
|
300
|
+
}
|
|
301
|
+
if (data instanceof Uint8Array) {
|
|
302
|
+
return new TextDecoder().decode(data);
|
|
303
|
+
}
|
|
304
|
+
if (data instanceof URL) {
|
|
305
|
+
throw new UnsupportedFunctionalityError2({
|
|
306
|
+
functionality: "URL-based text documents are not supported for citations"
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
throw new UnsupportedFunctionalityError2({
|
|
310
|
+
functionality: `unsupported data type for text documents: ${typeof data}`
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
async function convertToAnthropicMessagesPrompt({
|
|
162
314
|
prompt,
|
|
163
315
|
sendReasoning,
|
|
164
316
|
warnings
|
|
165
317
|
}) {
|
|
166
|
-
var _a, _b, _c;
|
|
318
|
+
var _a, _b, _c, _d, _e;
|
|
167
319
|
const betas = /* @__PURE__ */ new Set();
|
|
168
320
|
const blocks = groupIntoBlocks(prompt);
|
|
169
321
|
let system = void 0;
|
|
170
322
|
const messages = [];
|
|
171
|
-
function
|
|
172
|
-
var _a2;
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
323
|
+
async function shouldEnableCitations(providerMetadata) {
|
|
324
|
+
var _a2, _b2;
|
|
325
|
+
const anthropicOptions = await parseProviderOptions({
|
|
326
|
+
provider: "anthropic",
|
|
327
|
+
providerOptions: providerMetadata,
|
|
328
|
+
schema: anthropicFilePartProviderOptions
|
|
329
|
+
});
|
|
330
|
+
return (_b2 = (_a2 = anthropicOptions == null ? void 0 : anthropicOptions.citations) == null ? void 0 : _a2.enabled) != null ? _b2 : false;
|
|
331
|
+
}
|
|
332
|
+
async function getDocumentMetadata(providerMetadata) {
|
|
333
|
+
const anthropicOptions = await parseProviderOptions({
|
|
334
|
+
provider: "anthropic",
|
|
335
|
+
providerOptions: providerMetadata,
|
|
336
|
+
schema: anthropicFilePartProviderOptions
|
|
337
|
+
});
|
|
338
|
+
return {
|
|
339
|
+
title: anthropicOptions == null ? void 0 : anthropicOptions.title,
|
|
340
|
+
context: anthropicOptions == null ? void 0 : anthropicOptions.context
|
|
341
|
+
};
|
|
176
342
|
}
|
|
177
343
|
for (let i = 0; i < blocks.length; i++) {
|
|
178
344
|
const block = blocks[i];
|
|
@@ -227,6 +393,12 @@ function convertToAnthropicMessagesPrompt({
|
|
|
227
393
|
});
|
|
228
394
|
} else if (part.mediaType === "application/pdf") {
|
|
229
395
|
betas.add("pdfs-2024-09-25");
|
|
396
|
+
const enableCitations = await shouldEnableCitations(
|
|
397
|
+
part.providerOptions
|
|
398
|
+
);
|
|
399
|
+
const metadata = await getDocumentMetadata(
|
|
400
|
+
part.providerOptions
|
|
401
|
+
);
|
|
230
402
|
anthropicContent.push({
|
|
231
403
|
type: "document",
|
|
232
404
|
source: part.data instanceof URL ? {
|
|
@@ -237,6 +409,35 @@ function convertToAnthropicMessagesPrompt({
|
|
|
237
409
|
media_type: "application/pdf",
|
|
238
410
|
data: convertToBase64(part.data)
|
|
239
411
|
},
|
|
412
|
+
title: (_b = metadata.title) != null ? _b : part.filename,
|
|
413
|
+
...metadata.context && { context: metadata.context },
|
|
414
|
+
...enableCitations && {
|
|
415
|
+
citations: { enabled: true }
|
|
416
|
+
},
|
|
417
|
+
cache_control: cacheControl
|
|
418
|
+
});
|
|
419
|
+
} else if (part.mediaType === "text/plain") {
|
|
420
|
+
const enableCitations = await shouldEnableCitations(
|
|
421
|
+
part.providerOptions
|
|
422
|
+
);
|
|
423
|
+
const metadata = await getDocumentMetadata(
|
|
424
|
+
part.providerOptions
|
|
425
|
+
);
|
|
426
|
+
anthropicContent.push({
|
|
427
|
+
type: "document",
|
|
428
|
+
source: part.data instanceof URL ? {
|
|
429
|
+
type: "url",
|
|
430
|
+
url: part.data.toString()
|
|
431
|
+
} : {
|
|
432
|
+
type: "text",
|
|
433
|
+
media_type: "text/plain",
|
|
434
|
+
data: convertToString(part.data)
|
|
435
|
+
},
|
|
436
|
+
title: (_c = metadata.title) != null ? _c : part.filename,
|
|
437
|
+
...metadata.context && { context: metadata.context },
|
|
438
|
+
...enableCitations && {
|
|
439
|
+
citations: { enabled: true }
|
|
440
|
+
},
|
|
240
441
|
cache_control: cacheControl
|
|
241
442
|
});
|
|
242
443
|
} else {
|
|
@@ -254,33 +455,53 @@ function convertToAnthropicMessagesPrompt({
|
|
|
254
455
|
for (let i2 = 0; i2 < content.length; i2++) {
|
|
255
456
|
const part = content[i2];
|
|
256
457
|
const isLastPart = i2 === content.length - 1;
|
|
257
|
-
const cacheControl = (
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
text:
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
458
|
+
const cacheControl = (_d = getCacheControl(part.providerOptions)) != null ? _d : isLastPart ? getCacheControl(message.providerOptions) : void 0;
|
|
459
|
+
const output = part.output;
|
|
460
|
+
let contentValue;
|
|
461
|
+
switch (output.type) {
|
|
462
|
+
case "content":
|
|
463
|
+
contentValue = output.value.map((contentPart) => {
|
|
464
|
+
switch (contentPart.type) {
|
|
465
|
+
case "text":
|
|
466
|
+
return {
|
|
467
|
+
type: "text",
|
|
468
|
+
text: contentPart.text,
|
|
469
|
+
cache_control: void 0
|
|
470
|
+
};
|
|
471
|
+
case "media": {
|
|
472
|
+
if (contentPart.mediaType.startsWith("image/")) {
|
|
473
|
+
return {
|
|
474
|
+
type: "image",
|
|
475
|
+
source: {
|
|
476
|
+
type: "base64",
|
|
477
|
+
media_type: contentPart.mediaType,
|
|
478
|
+
data: contentPart.data
|
|
479
|
+
},
|
|
480
|
+
cache_control: void 0
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
throw new UnsupportedFunctionalityError2({
|
|
484
|
+
functionality: `media type: ${contentPart.mediaType}`
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
break;
|
|
490
|
+
case "text":
|
|
491
|
+
case "error-text":
|
|
492
|
+
contentValue = output.value;
|
|
493
|
+
break;
|
|
494
|
+
case "json":
|
|
495
|
+
case "error-json":
|
|
496
|
+
default:
|
|
497
|
+
contentValue = JSON.stringify(output.value);
|
|
498
|
+
break;
|
|
499
|
+
}
|
|
279
500
|
anthropicContent.push({
|
|
280
501
|
type: "tool_result",
|
|
281
502
|
tool_use_id: part.toolCallId,
|
|
282
|
-
content:
|
|
283
|
-
is_error:
|
|
503
|
+
content: contentValue,
|
|
504
|
+
is_error: output.type === "error-text" || output.type === "error-json" ? true : void 0,
|
|
284
505
|
cache_control: cacheControl
|
|
285
506
|
});
|
|
286
507
|
}
|
|
@@ -304,7 +525,7 @@ function convertToAnthropicMessagesPrompt({
|
|
|
304
525
|
for (let k = 0; k < content.length; k++) {
|
|
305
526
|
const part = content[k];
|
|
306
527
|
const isLastContentPart = k === content.length - 1;
|
|
307
|
-
const cacheControl = (
|
|
528
|
+
const cacheControl = (_e = getCacheControl(part.providerOptions)) != null ? _e : isLastContentPart ? getCacheControl(message.providerOptions) : void 0;
|
|
308
529
|
switch (part.type) {
|
|
309
530
|
case "text": {
|
|
310
531
|
anthropicContent.push({
|
|
@@ -321,12 +542,37 @@ function convertToAnthropicMessagesPrompt({
|
|
|
321
542
|
}
|
|
322
543
|
case "reasoning": {
|
|
323
544
|
if (sendReasoning) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
cache_control: cacheControl
|
|
545
|
+
const reasoningMetadata = await parseProviderOptions({
|
|
546
|
+
provider: "anthropic",
|
|
547
|
+
providerOptions: part.providerOptions,
|
|
548
|
+
schema: anthropicReasoningMetadataSchema
|
|
329
549
|
});
|
|
550
|
+
if (reasoningMetadata != null) {
|
|
551
|
+
if (reasoningMetadata.signature != null) {
|
|
552
|
+
anthropicContent.push({
|
|
553
|
+
type: "thinking",
|
|
554
|
+
thinking: part.text,
|
|
555
|
+
signature: reasoningMetadata.signature,
|
|
556
|
+
cache_control: cacheControl
|
|
557
|
+
});
|
|
558
|
+
} else if (reasoningMetadata.redactedData != null) {
|
|
559
|
+
anthropicContent.push({
|
|
560
|
+
type: "redacted_thinking",
|
|
561
|
+
data: reasoningMetadata.redactedData,
|
|
562
|
+
cache_control: cacheControl
|
|
563
|
+
});
|
|
564
|
+
} else {
|
|
565
|
+
warnings.push({
|
|
566
|
+
type: "other",
|
|
567
|
+
message: "unsupported reasoning metadata"
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
} else {
|
|
571
|
+
warnings.push({
|
|
572
|
+
type: "other",
|
|
573
|
+
message: "unsupported reasoning metadata"
|
|
574
|
+
});
|
|
575
|
+
}
|
|
330
576
|
} else {
|
|
331
577
|
warnings.push({
|
|
332
578
|
type: "other",
|
|
@@ -335,24 +581,66 @@ function convertToAnthropicMessagesPrompt({
|
|
|
335
581
|
}
|
|
336
582
|
break;
|
|
337
583
|
}
|
|
338
|
-
case "redacted-reasoning": {
|
|
339
|
-
anthropicContent.push({
|
|
340
|
-
type: "redacted_thinking",
|
|
341
|
-
data: part.data,
|
|
342
|
-
cache_control: cacheControl
|
|
343
|
-
});
|
|
344
|
-
break;
|
|
345
|
-
}
|
|
346
584
|
case "tool-call": {
|
|
585
|
+
if (part.providerExecuted) {
|
|
586
|
+
if (part.toolName === "web_search") {
|
|
587
|
+
anthropicContent.push({
|
|
588
|
+
type: "server_tool_use",
|
|
589
|
+
id: part.toolCallId,
|
|
590
|
+
name: "web_search",
|
|
591
|
+
input: part.input,
|
|
592
|
+
cache_control: cacheControl
|
|
593
|
+
});
|
|
594
|
+
break;
|
|
595
|
+
}
|
|
596
|
+
warnings.push({
|
|
597
|
+
type: "other",
|
|
598
|
+
message: `provider executed tool call for tool ${part.toolName} is not supported`
|
|
599
|
+
});
|
|
600
|
+
break;
|
|
601
|
+
}
|
|
347
602
|
anthropicContent.push({
|
|
348
603
|
type: "tool_use",
|
|
349
604
|
id: part.toolCallId,
|
|
350
605
|
name: part.toolName,
|
|
351
|
-
input: part.
|
|
606
|
+
input: part.input,
|
|
352
607
|
cache_control: cacheControl
|
|
353
608
|
});
|
|
354
609
|
break;
|
|
355
610
|
}
|
|
611
|
+
case "tool-result": {
|
|
612
|
+
if (part.toolName === "web_search") {
|
|
613
|
+
const output = part.output;
|
|
614
|
+
if (output.type !== "json") {
|
|
615
|
+
warnings.push({
|
|
616
|
+
type: "other",
|
|
617
|
+
message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
|
|
618
|
+
});
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
const webSearchOutput = webSearch_20250305OutputSchema.parse(
|
|
622
|
+
output.value
|
|
623
|
+
);
|
|
624
|
+
anthropicContent.push({
|
|
625
|
+
type: "web_search_tool_result",
|
|
626
|
+
tool_use_id: part.toolCallId,
|
|
627
|
+
content: webSearchOutput.map((result) => ({
|
|
628
|
+
url: result.url,
|
|
629
|
+
title: result.title,
|
|
630
|
+
page_age: result.pageAge,
|
|
631
|
+
encrypted_content: result.encryptedContent,
|
|
632
|
+
type: result.type
|
|
633
|
+
})),
|
|
634
|
+
cache_control: cacheControl
|
|
635
|
+
});
|
|
636
|
+
break;
|
|
637
|
+
}
|
|
638
|
+
warnings.push({
|
|
639
|
+
type: "other",
|
|
640
|
+
message: `provider executed tool result for tool ${part.toolName} is not supported`
|
|
641
|
+
});
|
|
642
|
+
break;
|
|
643
|
+
}
|
|
356
644
|
}
|
|
357
645
|
}
|
|
358
646
|
}
|
|
@@ -418,13 +706,16 @@ function groupIntoBlocks(prompt) {
|
|
|
418
706
|
}
|
|
419
707
|
|
|
420
708
|
// src/map-anthropic-stop-reason.ts
|
|
421
|
-
function mapAnthropicStopReason(
|
|
709
|
+
function mapAnthropicStopReason({
|
|
710
|
+
finishReason,
|
|
711
|
+
isJsonResponseFromTool
|
|
712
|
+
}) {
|
|
422
713
|
switch (finishReason) {
|
|
423
714
|
case "end_turn":
|
|
424
715
|
case "stop_sequence":
|
|
425
716
|
return "stop";
|
|
426
717
|
case "tool_use":
|
|
427
|
-
return "tool-calls";
|
|
718
|
+
return isJsonResponseFromTool ? "stop" : "tool-calls";
|
|
428
719
|
case "max_tokens":
|
|
429
720
|
return "length";
|
|
430
721
|
default:
|
|
@@ -433,13 +724,86 @@ function mapAnthropicStopReason(finishReason) {
|
|
|
433
724
|
}
|
|
434
725
|
|
|
435
726
|
// src/anthropic-messages-language-model.ts
|
|
727
|
+
var citationSchemas = {
|
|
728
|
+
webSearchResult: z4.object({
|
|
729
|
+
type: z4.literal("web_search_result_location"),
|
|
730
|
+
cited_text: z4.string(),
|
|
731
|
+
url: z4.string(),
|
|
732
|
+
title: z4.string(),
|
|
733
|
+
encrypted_index: z4.string()
|
|
734
|
+
}),
|
|
735
|
+
pageLocation: z4.object({
|
|
736
|
+
type: z4.literal("page_location"),
|
|
737
|
+
cited_text: z4.string(),
|
|
738
|
+
document_index: z4.number(),
|
|
739
|
+
document_title: z4.string().nullable(),
|
|
740
|
+
start_page_number: z4.number(),
|
|
741
|
+
end_page_number: z4.number()
|
|
742
|
+
}),
|
|
743
|
+
charLocation: z4.object({
|
|
744
|
+
type: z4.literal("char_location"),
|
|
745
|
+
cited_text: z4.string(),
|
|
746
|
+
document_index: z4.number(),
|
|
747
|
+
document_title: z4.string().nullable(),
|
|
748
|
+
start_char_index: z4.number(),
|
|
749
|
+
end_char_index: z4.number()
|
|
750
|
+
})
|
|
751
|
+
};
|
|
752
|
+
var citationSchema = z4.discriminatedUnion("type", [
|
|
753
|
+
citationSchemas.webSearchResult,
|
|
754
|
+
citationSchemas.pageLocation,
|
|
755
|
+
citationSchemas.charLocation
|
|
756
|
+
]);
|
|
757
|
+
var documentCitationSchema = z4.discriminatedUnion("type", [
|
|
758
|
+
citationSchemas.pageLocation,
|
|
759
|
+
citationSchemas.charLocation
|
|
760
|
+
]);
|
|
761
|
+
function processCitation(citation, citationDocuments, generateId2, onSource) {
|
|
762
|
+
if (citation.type === "page_location" || citation.type === "char_location") {
|
|
763
|
+
const source = createCitationSource(
|
|
764
|
+
citation,
|
|
765
|
+
citationDocuments,
|
|
766
|
+
generateId2
|
|
767
|
+
);
|
|
768
|
+
if (source) {
|
|
769
|
+
onSource(source);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
function createCitationSource(citation, citationDocuments, generateId2) {
|
|
774
|
+
var _a;
|
|
775
|
+
const documentInfo = citationDocuments[citation.document_index];
|
|
776
|
+
if (!documentInfo) {
|
|
777
|
+
return null;
|
|
778
|
+
}
|
|
779
|
+
const providerMetadata = citation.type === "page_location" ? {
|
|
780
|
+
citedText: citation.cited_text,
|
|
781
|
+
startPageNumber: citation.start_page_number,
|
|
782
|
+
endPageNumber: citation.end_page_number
|
|
783
|
+
} : {
|
|
784
|
+
citedText: citation.cited_text,
|
|
785
|
+
startCharIndex: citation.start_char_index,
|
|
786
|
+
endCharIndex: citation.end_char_index
|
|
787
|
+
};
|
|
788
|
+
return {
|
|
789
|
+
type: "source",
|
|
790
|
+
sourceType: "document",
|
|
791
|
+
id: generateId2(),
|
|
792
|
+
mediaType: documentInfo.mediaType,
|
|
793
|
+
title: (_a = citation.document_title) != null ? _a : documentInfo.title,
|
|
794
|
+
filename: documentInfo.filename,
|
|
795
|
+
providerMetadata: {
|
|
796
|
+
anthropic: providerMetadata
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
}
|
|
436
800
|
var AnthropicMessagesLanguageModel = class {
|
|
437
|
-
constructor(modelId,
|
|
801
|
+
constructor(modelId, config) {
|
|
438
802
|
this.specificationVersion = "v2";
|
|
439
|
-
|
|
803
|
+
var _a;
|
|
440
804
|
this.modelId = modelId;
|
|
441
|
-
this.settings = settings;
|
|
442
805
|
this.config = config;
|
|
806
|
+
this.generateId = (_a = config.generateId) != null ? _a : generateId;
|
|
443
807
|
}
|
|
444
808
|
supportsUrl(url) {
|
|
445
809
|
return url.protocol === "https:";
|
|
@@ -447,8 +811,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
447
811
|
get provider() {
|
|
448
812
|
return this.config.provider;
|
|
449
813
|
}
|
|
450
|
-
get
|
|
451
|
-
|
|
814
|
+
get supportedUrls() {
|
|
815
|
+
var _a, _b, _c;
|
|
816
|
+
return (_c = (_b = (_a = this.config).supportedUrls) == null ? void 0 : _b.call(_a)) != null ? _c : {};
|
|
452
817
|
}
|
|
453
818
|
async getArgs({
|
|
454
819
|
prompt,
|
|
@@ -486,22 +851,36 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
486
851
|
setting: "seed"
|
|
487
852
|
});
|
|
488
853
|
}
|
|
489
|
-
if (responseFormat
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
854
|
+
if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
|
|
855
|
+
if (responseFormat.schema == null) {
|
|
856
|
+
warnings.push({
|
|
857
|
+
type: "unsupported-setting",
|
|
858
|
+
setting: "responseFormat",
|
|
859
|
+
details: "JSON response format requires a schema. The response format is ignored."
|
|
860
|
+
});
|
|
861
|
+
} else if (tools != null) {
|
|
862
|
+
warnings.push({
|
|
863
|
+
type: "unsupported-setting",
|
|
864
|
+
setting: "tools",
|
|
865
|
+
details: "JSON response format does not support tools. The provided tools are ignored."
|
|
866
|
+
});
|
|
867
|
+
}
|
|
495
868
|
}
|
|
496
|
-
const
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
869
|
+
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
|
|
870
|
+
type: "function",
|
|
871
|
+
name: "json",
|
|
872
|
+
description: "Respond with a JSON object.",
|
|
873
|
+
inputSchema: responseFormat.schema
|
|
874
|
+
} : void 0;
|
|
875
|
+
const anthropicOptions = await parseProviderOptions2({
|
|
502
876
|
provider: "anthropic",
|
|
503
877
|
providerOptions,
|
|
504
|
-
schema:
|
|
878
|
+
schema: anthropicProviderOptions
|
|
879
|
+
});
|
|
880
|
+
const { prompt: messagesPrompt, betas: messagesBetas } = await convertToAnthropicMessagesPrompt({
|
|
881
|
+
prompt,
|
|
882
|
+
sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
|
|
883
|
+
warnings
|
|
505
884
|
});
|
|
506
885
|
const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
|
|
507
886
|
const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
|
|
@@ -559,7 +938,17 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
559
938
|
toolChoice: anthropicToolChoice,
|
|
560
939
|
toolWarnings,
|
|
561
940
|
betas: toolsBetas
|
|
562
|
-
} = prepareTools(
|
|
941
|
+
} = prepareTools(
|
|
942
|
+
jsonResponseTool != null ? {
|
|
943
|
+
tools: [jsonResponseTool],
|
|
944
|
+
toolChoice: { type: "tool", toolName: jsonResponseTool.name },
|
|
945
|
+
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
|
|
946
|
+
} : {
|
|
947
|
+
tools: tools != null ? tools : [],
|
|
948
|
+
toolChoice,
|
|
949
|
+
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse
|
|
950
|
+
}
|
|
951
|
+
);
|
|
563
952
|
return {
|
|
564
953
|
args: {
|
|
565
954
|
...baseArgs,
|
|
@@ -567,7 +956,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
567
956
|
tool_choice: anthropicToolChoice
|
|
568
957
|
},
|
|
569
958
|
warnings: [...warnings, ...toolWarnings],
|
|
570
|
-
betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas])
|
|
959
|
+
betas: /* @__PURE__ */ new Set([...messagesBetas, ...toolsBetas]),
|
|
960
|
+
usesJsonResponseTool: jsonResponseTool != null
|
|
571
961
|
};
|
|
572
962
|
}
|
|
573
963
|
async getHeaders({
|
|
@@ -588,9 +978,33 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
588
978
|
var _a, _b, _c;
|
|
589
979
|
return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args)) != null ? _c : args;
|
|
590
980
|
}
|
|
981
|
+
extractCitationDocuments(prompt) {
|
|
982
|
+
const isCitationPart = (part) => {
|
|
983
|
+
var _a, _b;
|
|
984
|
+
if (part.type !== "file") {
|
|
985
|
+
return false;
|
|
986
|
+
}
|
|
987
|
+
if (part.mediaType !== "application/pdf" && part.mediaType !== "text/plain") {
|
|
988
|
+
return false;
|
|
989
|
+
}
|
|
990
|
+
const anthropic = (_a = part.providerOptions) == null ? void 0 : _a.anthropic;
|
|
991
|
+
const citationsConfig = anthropic == null ? void 0 : anthropic.citations;
|
|
992
|
+
return (_b = citationsConfig == null ? void 0 : citationsConfig.enabled) != null ? _b : false;
|
|
993
|
+
};
|
|
994
|
+
return prompt.filter((message) => message.role === "user").flatMap((message) => message.content).filter(isCitationPart).map((part) => {
|
|
995
|
+
var _a;
|
|
996
|
+
const filePart = part;
|
|
997
|
+
return {
|
|
998
|
+
title: (_a = filePart.filename) != null ? _a : "Untitled Document",
|
|
999
|
+
filename: filePart.filename,
|
|
1000
|
+
mediaType: filePart.mediaType
|
|
1001
|
+
};
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
591
1004
|
async doGenerate(options) {
|
|
592
|
-
var _a, _b, _c, _d;
|
|
593
|
-
const { args, warnings, betas } = await this.getArgs(options);
|
|
1005
|
+
var _a, _b, _c, _d, _e;
|
|
1006
|
+
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
|
|
1007
|
+
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
594
1008
|
const {
|
|
595
1009
|
responseHeaders,
|
|
596
1010
|
value: response,
|
|
@@ -610,67 +1024,152 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
610
1024
|
for (const part of response.content) {
|
|
611
1025
|
switch (part.type) {
|
|
612
1026
|
case "text": {
|
|
613
|
-
|
|
1027
|
+
if (!usesJsonResponseTool) {
|
|
1028
|
+
content.push({ type: "text", text: part.text });
|
|
1029
|
+
if (part.citations) {
|
|
1030
|
+
for (const citation of part.citations) {
|
|
1031
|
+
processCitation(
|
|
1032
|
+
citation,
|
|
1033
|
+
citationDocuments,
|
|
1034
|
+
this.generateId,
|
|
1035
|
+
(source) => content.push(source)
|
|
1036
|
+
);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
614
1040
|
break;
|
|
615
1041
|
}
|
|
616
1042
|
case "thinking": {
|
|
617
1043
|
content.push({
|
|
618
1044
|
type: "reasoning",
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
signature: part.signature
|
|
1045
|
+
text: part.thinking,
|
|
1046
|
+
providerMetadata: {
|
|
1047
|
+
anthropic: {
|
|
1048
|
+
signature: part.signature
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
626
1051
|
});
|
|
627
1052
|
break;
|
|
628
1053
|
}
|
|
629
1054
|
case "redacted_thinking": {
|
|
630
1055
|
content.push({
|
|
631
1056
|
type: "reasoning",
|
|
632
|
-
|
|
633
|
-
|
|
1057
|
+
text: "",
|
|
1058
|
+
providerMetadata: {
|
|
1059
|
+
anthropic: {
|
|
1060
|
+
redactedData: part.data
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
634
1063
|
});
|
|
635
1064
|
break;
|
|
636
1065
|
}
|
|
637
1066
|
case "tool_use": {
|
|
638
|
-
content.push(
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
1067
|
+
content.push(
|
|
1068
|
+
// when a json response tool is used, the tool call becomes the text:
|
|
1069
|
+
usesJsonResponseTool ? {
|
|
1070
|
+
type: "text",
|
|
1071
|
+
text: JSON.stringify(part.input)
|
|
1072
|
+
} : {
|
|
1073
|
+
type: "tool-call",
|
|
1074
|
+
toolCallId: part.id,
|
|
1075
|
+
toolName: part.name,
|
|
1076
|
+
input: JSON.stringify(part.input)
|
|
1077
|
+
}
|
|
1078
|
+
);
|
|
1079
|
+
break;
|
|
1080
|
+
}
|
|
1081
|
+
case "server_tool_use": {
|
|
1082
|
+
if (part.name === "web_search") {
|
|
1083
|
+
content.push({
|
|
1084
|
+
type: "tool-call",
|
|
1085
|
+
toolCallId: part.id,
|
|
1086
|
+
toolName: part.name,
|
|
1087
|
+
input: JSON.stringify(part.input),
|
|
1088
|
+
providerExecuted: true
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
break;
|
|
1092
|
+
}
|
|
1093
|
+
case "web_search_tool_result": {
|
|
1094
|
+
if (Array.isArray(part.content)) {
|
|
1095
|
+
content.push({
|
|
1096
|
+
type: "tool-result",
|
|
1097
|
+
toolCallId: part.tool_use_id,
|
|
1098
|
+
toolName: "web_search",
|
|
1099
|
+
result: part.content.map((result) => {
|
|
1100
|
+
var _a2;
|
|
1101
|
+
return {
|
|
1102
|
+
url: result.url,
|
|
1103
|
+
title: result.title,
|
|
1104
|
+
pageAge: (_a2 = result.page_age) != null ? _a2 : null,
|
|
1105
|
+
encryptedContent: result.encrypted_content,
|
|
1106
|
+
type: result.type
|
|
1107
|
+
};
|
|
1108
|
+
}),
|
|
1109
|
+
providerExecuted: true
|
|
1110
|
+
});
|
|
1111
|
+
for (const result of part.content) {
|
|
1112
|
+
content.push({
|
|
1113
|
+
type: "source",
|
|
1114
|
+
sourceType: "url",
|
|
1115
|
+
id: this.generateId(),
|
|
1116
|
+
url: result.url,
|
|
1117
|
+
title: result.title,
|
|
1118
|
+
providerMetadata: {
|
|
1119
|
+
anthropic: {
|
|
1120
|
+
pageAge: (_a = result.page_age) != null ? _a : null
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
} else {
|
|
1126
|
+
content.push({
|
|
1127
|
+
type: "tool-result",
|
|
1128
|
+
toolCallId: part.tool_use_id,
|
|
1129
|
+
toolName: "web_search",
|
|
1130
|
+
isError: true,
|
|
1131
|
+
result: {
|
|
1132
|
+
type: "web_search_tool_result_error",
|
|
1133
|
+
errorCode: part.content.error_code
|
|
1134
|
+
},
|
|
1135
|
+
providerExecuted: true
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
645
1138
|
break;
|
|
646
1139
|
}
|
|
647
1140
|
}
|
|
648
1141
|
}
|
|
649
1142
|
return {
|
|
650
1143
|
content,
|
|
651
|
-
finishReason: mapAnthropicStopReason(
|
|
1144
|
+
finishReason: mapAnthropicStopReason({
|
|
1145
|
+
finishReason: response.stop_reason,
|
|
1146
|
+
isJsonResponseFromTool: usesJsonResponseTool
|
|
1147
|
+
}),
|
|
652
1148
|
usage: {
|
|
653
1149
|
inputTokens: response.usage.input_tokens,
|
|
654
|
-
outputTokens: response.usage.output_tokens
|
|
1150
|
+
outputTokens: response.usage.output_tokens,
|
|
1151
|
+
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
1152
|
+
cachedInputTokens: (_b = response.usage.cache_read_input_tokens) != null ? _b : void 0
|
|
655
1153
|
},
|
|
656
1154
|
request: { body: args },
|
|
657
1155
|
response: {
|
|
658
|
-
id: (
|
|
659
|
-
modelId: (
|
|
1156
|
+
id: (_c = response.id) != null ? _c : void 0,
|
|
1157
|
+
modelId: (_d = response.model) != null ? _d : void 0,
|
|
660
1158
|
headers: responseHeaders,
|
|
661
1159
|
body: rawResponse
|
|
662
1160
|
},
|
|
663
1161
|
warnings,
|
|
664
1162
|
providerMetadata: {
|
|
665
1163
|
anthropic: {
|
|
666
|
-
|
|
667
|
-
|
|
1164
|
+
usage: response.usage,
|
|
1165
|
+
cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null
|
|
668
1166
|
}
|
|
669
1167
|
}
|
|
670
1168
|
};
|
|
671
1169
|
}
|
|
672
1170
|
async doStream(options) {
|
|
673
|
-
const { args, warnings, betas } = await this.getArgs(options);
|
|
1171
|
+
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
|
|
1172
|
+
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
674
1173
|
const body = { ...args, stream: true };
|
|
675
1174
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
676
1175
|
url: this.buildRequestUrl(true),
|
|
@@ -686,11 +1185,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
686
1185
|
let finishReason = "unknown";
|
|
687
1186
|
const usage = {
|
|
688
1187
|
inputTokens: void 0,
|
|
689
|
-
outputTokens: void 0
|
|
1188
|
+
outputTokens: void 0,
|
|
1189
|
+
totalTokens: void 0
|
|
690
1190
|
};
|
|
691
|
-
const
|
|
1191
|
+
const contentBlocks = {};
|
|
692
1192
|
let providerMetadata = void 0;
|
|
693
1193
|
let blockType = void 0;
|
|
1194
|
+
const generateId2 = this.generateId;
|
|
694
1195
|
return {
|
|
695
1196
|
stream: response.pipeThrough(
|
|
696
1197
|
new TransformStream({
|
|
@@ -698,7 +1199,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
698
1199
|
controller.enqueue({ type: "stream-start", warnings });
|
|
699
1200
|
},
|
|
700
1201
|
transform(chunk, controller) {
|
|
701
|
-
var _a, _b, _c, _d;
|
|
1202
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1203
|
+
if (options.includeRawChunks) {
|
|
1204
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1205
|
+
}
|
|
702
1206
|
if (!chunk.success) {
|
|
703
1207
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
704
1208
|
return;
|
|
@@ -712,24 +1216,115 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
712
1216
|
const contentBlockType = value.content_block.type;
|
|
713
1217
|
blockType = contentBlockType;
|
|
714
1218
|
switch (contentBlockType) {
|
|
715
|
-
case "text":
|
|
1219
|
+
case "text": {
|
|
1220
|
+
contentBlocks[value.index] = { type: "text" };
|
|
1221
|
+
controller.enqueue({
|
|
1222
|
+
type: "text-start",
|
|
1223
|
+
id: String(value.index)
|
|
1224
|
+
});
|
|
1225
|
+
return;
|
|
1226
|
+
}
|
|
716
1227
|
case "thinking": {
|
|
1228
|
+
contentBlocks[value.index] = { type: "reasoning" };
|
|
1229
|
+
controller.enqueue({
|
|
1230
|
+
type: "reasoning-start",
|
|
1231
|
+
id: String(value.index)
|
|
1232
|
+
});
|
|
717
1233
|
return;
|
|
718
1234
|
}
|
|
719
1235
|
case "redacted_thinking": {
|
|
1236
|
+
contentBlocks[value.index] = { type: "reasoning" };
|
|
720
1237
|
controller.enqueue({
|
|
721
|
-
type: "reasoning",
|
|
722
|
-
|
|
723
|
-
|
|
1238
|
+
type: "reasoning-start",
|
|
1239
|
+
id: String(value.index),
|
|
1240
|
+
providerMetadata: {
|
|
1241
|
+
anthropic: {
|
|
1242
|
+
redactedData: value.content_block.data
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
724
1245
|
});
|
|
725
1246
|
return;
|
|
726
1247
|
}
|
|
727
1248
|
case "tool_use": {
|
|
728
|
-
|
|
1249
|
+
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
|
|
1250
|
+
type: "tool-call",
|
|
729
1251
|
toolCallId: value.content_block.id,
|
|
730
1252
|
toolName: value.content_block.name,
|
|
731
|
-
|
|
1253
|
+
input: ""
|
|
732
1254
|
};
|
|
1255
|
+
controller.enqueue(
|
|
1256
|
+
usesJsonResponseTool ? { type: "text-start", id: String(value.index) } : {
|
|
1257
|
+
type: "tool-input-start",
|
|
1258
|
+
id: value.content_block.id,
|
|
1259
|
+
toolName: value.content_block.name
|
|
1260
|
+
}
|
|
1261
|
+
);
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
case "server_tool_use": {
|
|
1265
|
+
if (value.content_block.name === "web_search") {
|
|
1266
|
+
contentBlocks[value.index] = {
|
|
1267
|
+
type: "tool-call",
|
|
1268
|
+
toolCallId: value.content_block.id,
|
|
1269
|
+
toolName: value.content_block.name,
|
|
1270
|
+
input: "",
|
|
1271
|
+
providerExecuted: true
|
|
1272
|
+
};
|
|
1273
|
+
controller.enqueue({
|
|
1274
|
+
type: "tool-input-start",
|
|
1275
|
+
id: value.content_block.id,
|
|
1276
|
+
toolName: value.content_block.name,
|
|
1277
|
+
providerExecuted: true
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
return;
|
|
1281
|
+
}
|
|
1282
|
+
case "web_search_tool_result": {
|
|
1283
|
+
const part = value.content_block;
|
|
1284
|
+
if (Array.isArray(part.content)) {
|
|
1285
|
+
controller.enqueue({
|
|
1286
|
+
type: "tool-result",
|
|
1287
|
+
toolCallId: part.tool_use_id,
|
|
1288
|
+
toolName: "web_search",
|
|
1289
|
+
result: part.content.map((result) => {
|
|
1290
|
+
var _a2;
|
|
1291
|
+
return {
|
|
1292
|
+
url: result.url,
|
|
1293
|
+
title: result.title,
|
|
1294
|
+
pageAge: (_a2 = result.page_age) != null ? _a2 : null,
|
|
1295
|
+
encryptedContent: result.encrypted_content,
|
|
1296
|
+
type: result.type
|
|
1297
|
+
};
|
|
1298
|
+
}),
|
|
1299
|
+
providerExecuted: true
|
|
1300
|
+
});
|
|
1301
|
+
for (const result of part.content) {
|
|
1302
|
+
controller.enqueue({
|
|
1303
|
+
type: "source",
|
|
1304
|
+
sourceType: "url",
|
|
1305
|
+
id: generateId2(),
|
|
1306
|
+
url: result.url,
|
|
1307
|
+
title: result.title,
|
|
1308
|
+
providerMetadata: {
|
|
1309
|
+
anthropic: {
|
|
1310
|
+
pageAge: (_a = result.page_age) != null ? _a : null
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
} else {
|
|
1316
|
+
controller.enqueue({
|
|
1317
|
+
type: "tool-result",
|
|
1318
|
+
toolCallId: part.tool_use_id,
|
|
1319
|
+
toolName: "web_search",
|
|
1320
|
+
isError: true,
|
|
1321
|
+
result: {
|
|
1322
|
+
type: "web_search_tool_result_error",
|
|
1323
|
+
errorCode: part.content.error_code
|
|
1324
|
+
},
|
|
1325
|
+
providerExecuted: true
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
733
1328
|
return;
|
|
734
1329
|
}
|
|
735
1330
|
default: {
|
|
@@ -741,16 +1336,34 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
741
1336
|
}
|
|
742
1337
|
}
|
|
743
1338
|
case "content_block_stop": {
|
|
744
|
-
if (
|
|
745
|
-
const contentBlock =
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
1339
|
+
if (contentBlocks[value.index] != null) {
|
|
1340
|
+
const contentBlock = contentBlocks[value.index];
|
|
1341
|
+
switch (contentBlock.type) {
|
|
1342
|
+
case "text": {
|
|
1343
|
+
controller.enqueue({
|
|
1344
|
+
type: "text-end",
|
|
1345
|
+
id: String(value.index)
|
|
1346
|
+
});
|
|
1347
|
+
break;
|
|
1348
|
+
}
|
|
1349
|
+
case "reasoning": {
|
|
1350
|
+
controller.enqueue({
|
|
1351
|
+
type: "reasoning-end",
|
|
1352
|
+
id: String(value.index)
|
|
1353
|
+
});
|
|
1354
|
+
break;
|
|
1355
|
+
}
|
|
1356
|
+
case "tool-call":
|
|
1357
|
+
if (!usesJsonResponseTool) {
|
|
1358
|
+
controller.enqueue({
|
|
1359
|
+
type: "tool-input-end",
|
|
1360
|
+
id: contentBlock.toolCallId
|
|
1361
|
+
});
|
|
1362
|
+
controller.enqueue(contentBlock);
|
|
1363
|
+
}
|
|
1364
|
+
break;
|
|
1365
|
+
}
|
|
1366
|
+
delete contentBlocks[value.index];
|
|
754
1367
|
}
|
|
755
1368
|
blockType = void 0;
|
|
756
1369
|
return;
|
|
@@ -759,40 +1372,72 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
759
1372
|
const deltaType = value.delta.type;
|
|
760
1373
|
switch (deltaType) {
|
|
761
1374
|
case "text_delta": {
|
|
1375
|
+
if (usesJsonResponseTool) {
|
|
1376
|
+
return;
|
|
1377
|
+
}
|
|
762
1378
|
controller.enqueue({
|
|
763
|
-
type: "text",
|
|
764
|
-
|
|
1379
|
+
type: "text-delta",
|
|
1380
|
+
id: String(value.index),
|
|
1381
|
+
delta: value.delta.text
|
|
765
1382
|
});
|
|
766
1383
|
return;
|
|
767
1384
|
}
|
|
768
1385
|
case "thinking_delta": {
|
|
769
1386
|
controller.enqueue({
|
|
770
|
-
type: "reasoning",
|
|
771
|
-
|
|
772
|
-
|
|
1387
|
+
type: "reasoning-delta",
|
|
1388
|
+
id: String(value.index),
|
|
1389
|
+
delta: value.delta.thinking
|
|
773
1390
|
});
|
|
774
1391
|
return;
|
|
775
1392
|
}
|
|
776
1393
|
case "signature_delta": {
|
|
777
1394
|
if (blockType === "thinking") {
|
|
778
1395
|
controller.enqueue({
|
|
779
|
-
type: "reasoning",
|
|
780
|
-
|
|
781
|
-
|
|
1396
|
+
type: "reasoning-delta",
|
|
1397
|
+
id: String(value.index),
|
|
1398
|
+
delta: "",
|
|
1399
|
+
providerMetadata: {
|
|
1400
|
+
anthropic: {
|
|
1401
|
+
signature: value.delta.signature
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
782
1404
|
});
|
|
783
1405
|
}
|
|
784
1406
|
return;
|
|
785
1407
|
}
|
|
786
1408
|
case "input_json_delta": {
|
|
787
|
-
const contentBlock =
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
1409
|
+
const contentBlock = contentBlocks[value.index];
|
|
1410
|
+
const delta = value.delta.partial_json;
|
|
1411
|
+
if (usesJsonResponseTool) {
|
|
1412
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
|
|
1413
|
+
return;
|
|
1414
|
+
}
|
|
1415
|
+
controller.enqueue({
|
|
1416
|
+
type: "text-delta",
|
|
1417
|
+
id: String(value.index),
|
|
1418
|
+
delta
|
|
1419
|
+
});
|
|
1420
|
+
} else {
|
|
1421
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
|
|
1422
|
+
return;
|
|
1423
|
+
}
|
|
1424
|
+
controller.enqueue({
|
|
1425
|
+
type: "tool-input-delta",
|
|
1426
|
+
id: contentBlock.toolCallId,
|
|
1427
|
+
delta
|
|
1428
|
+
});
|
|
1429
|
+
contentBlock.input += delta;
|
|
1430
|
+
}
|
|
1431
|
+
return;
|
|
1432
|
+
}
|
|
1433
|
+
case "citations_delta": {
|
|
1434
|
+
const citation = value.delta.citation;
|
|
1435
|
+
processCitation(
|
|
1436
|
+
citation,
|
|
1437
|
+
citationDocuments,
|
|
1438
|
+
generateId2,
|
|
1439
|
+
(source) => controller.enqueue(source)
|
|
1440
|
+
);
|
|
796
1441
|
return;
|
|
797
1442
|
}
|
|
798
1443
|
default: {
|
|
@@ -805,23 +1450,27 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
805
1450
|
}
|
|
806
1451
|
case "message_start": {
|
|
807
1452
|
usage.inputTokens = value.message.usage.input_tokens;
|
|
808
|
-
usage.
|
|
1453
|
+
usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
|
|
809
1454
|
providerMetadata = {
|
|
810
1455
|
anthropic: {
|
|
811
|
-
|
|
812
|
-
|
|
1456
|
+
usage: value.message.usage,
|
|
1457
|
+
cacheCreationInputTokens: (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null
|
|
813
1458
|
}
|
|
814
1459
|
};
|
|
815
1460
|
controller.enqueue({
|
|
816
1461
|
type: "response-metadata",
|
|
817
|
-
id: (
|
|
818
|
-
modelId: (
|
|
1462
|
+
id: (_d = value.message.id) != null ? _d : void 0,
|
|
1463
|
+
modelId: (_e = value.message.model) != null ? _e : void 0
|
|
819
1464
|
});
|
|
820
1465
|
return;
|
|
821
1466
|
}
|
|
822
1467
|
case "message_delta": {
|
|
823
1468
|
usage.outputTokens = value.usage.output_tokens;
|
|
824
|
-
|
|
1469
|
+
usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
|
|
1470
|
+
finishReason = mapAnthropicStopReason({
|
|
1471
|
+
finishReason: value.delta.stop_reason,
|
|
1472
|
+
isJsonResponseFromTool: usesJsonResponseTool
|
|
1473
|
+
});
|
|
825
1474
|
return;
|
|
826
1475
|
}
|
|
827
1476
|
case "message_stop": {
|
|
@@ -850,278 +1499,382 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
850
1499
|
};
|
|
851
1500
|
}
|
|
852
1501
|
};
|
|
853
|
-
var anthropicMessagesResponseSchema =
|
|
854
|
-
type:
|
|
855
|
-
id:
|
|
856
|
-
model:
|
|
857
|
-
content:
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
type:
|
|
861
|
-
text:
|
|
1502
|
+
var anthropicMessagesResponseSchema = z4.object({
|
|
1503
|
+
type: z4.literal("message"),
|
|
1504
|
+
id: z4.string().nullish(),
|
|
1505
|
+
model: z4.string().nullish(),
|
|
1506
|
+
content: z4.array(
|
|
1507
|
+
z4.discriminatedUnion("type", [
|
|
1508
|
+
z4.object({
|
|
1509
|
+
type: z4.literal("text"),
|
|
1510
|
+
text: z4.string(),
|
|
1511
|
+
citations: z4.array(citationSchema).optional()
|
|
862
1512
|
}),
|
|
863
|
-
|
|
864
|
-
type:
|
|
865
|
-
thinking:
|
|
866
|
-
signature:
|
|
1513
|
+
z4.object({
|
|
1514
|
+
type: z4.literal("thinking"),
|
|
1515
|
+
thinking: z4.string(),
|
|
1516
|
+
signature: z4.string()
|
|
867
1517
|
}),
|
|
868
|
-
|
|
869
|
-
type:
|
|
870
|
-
data:
|
|
1518
|
+
z4.object({
|
|
1519
|
+
type: z4.literal("redacted_thinking"),
|
|
1520
|
+
data: z4.string()
|
|
871
1521
|
}),
|
|
872
|
-
|
|
873
|
-
type:
|
|
874
|
-
id:
|
|
875
|
-
name:
|
|
876
|
-
input:
|
|
1522
|
+
z4.object({
|
|
1523
|
+
type: z4.literal("tool_use"),
|
|
1524
|
+
id: z4.string(),
|
|
1525
|
+
name: z4.string(),
|
|
1526
|
+
input: z4.unknown()
|
|
1527
|
+
}),
|
|
1528
|
+
z4.object({
|
|
1529
|
+
type: z4.literal("server_tool_use"),
|
|
1530
|
+
id: z4.string(),
|
|
1531
|
+
name: z4.string(),
|
|
1532
|
+
input: z4.record(z4.string(), z4.unknown()).nullish()
|
|
1533
|
+
}),
|
|
1534
|
+
z4.object({
|
|
1535
|
+
type: z4.literal("web_search_tool_result"),
|
|
1536
|
+
tool_use_id: z4.string(),
|
|
1537
|
+
content: z4.union([
|
|
1538
|
+
z4.array(
|
|
1539
|
+
z4.object({
|
|
1540
|
+
type: z4.literal("web_search_result"),
|
|
1541
|
+
url: z4.string(),
|
|
1542
|
+
title: z4.string(),
|
|
1543
|
+
encrypted_content: z4.string(),
|
|
1544
|
+
page_age: z4.string().nullish()
|
|
1545
|
+
})
|
|
1546
|
+
),
|
|
1547
|
+
z4.object({
|
|
1548
|
+
type: z4.literal("web_search_tool_result_error"),
|
|
1549
|
+
error_code: z4.string()
|
|
1550
|
+
})
|
|
1551
|
+
])
|
|
877
1552
|
})
|
|
878
1553
|
])
|
|
879
1554
|
),
|
|
880
|
-
stop_reason:
|
|
881
|
-
usage:
|
|
882
|
-
input_tokens:
|
|
883
|
-
output_tokens:
|
|
884
|
-
cache_creation_input_tokens:
|
|
885
|
-
cache_read_input_tokens:
|
|
1555
|
+
stop_reason: z4.string().nullish(),
|
|
1556
|
+
usage: z4.looseObject({
|
|
1557
|
+
input_tokens: z4.number(),
|
|
1558
|
+
output_tokens: z4.number(),
|
|
1559
|
+
cache_creation_input_tokens: z4.number().nullish(),
|
|
1560
|
+
cache_read_input_tokens: z4.number().nullish()
|
|
886
1561
|
})
|
|
887
1562
|
});
|
|
888
|
-
var anthropicMessagesChunkSchema =
|
|
889
|
-
|
|
890
|
-
type:
|
|
891
|
-
message:
|
|
892
|
-
id:
|
|
893
|
-
model:
|
|
894
|
-
usage:
|
|
895
|
-
input_tokens:
|
|
896
|
-
output_tokens:
|
|
897
|
-
cache_creation_input_tokens:
|
|
898
|
-
cache_read_input_tokens:
|
|
1563
|
+
var anthropicMessagesChunkSchema = z4.discriminatedUnion("type", [
|
|
1564
|
+
z4.object({
|
|
1565
|
+
type: z4.literal("message_start"),
|
|
1566
|
+
message: z4.object({
|
|
1567
|
+
id: z4.string().nullish(),
|
|
1568
|
+
model: z4.string().nullish(),
|
|
1569
|
+
usage: z4.looseObject({
|
|
1570
|
+
input_tokens: z4.number(),
|
|
1571
|
+
output_tokens: z4.number(),
|
|
1572
|
+
cache_creation_input_tokens: z4.number().nullish(),
|
|
1573
|
+
cache_read_input_tokens: z4.number().nullish()
|
|
899
1574
|
})
|
|
900
1575
|
})
|
|
901
1576
|
}),
|
|
902
|
-
|
|
903
|
-
type:
|
|
904
|
-
index:
|
|
905
|
-
content_block:
|
|
906
|
-
|
|
907
|
-
type:
|
|
908
|
-
text:
|
|
1577
|
+
z4.object({
|
|
1578
|
+
type: z4.literal("content_block_start"),
|
|
1579
|
+
index: z4.number(),
|
|
1580
|
+
content_block: z4.discriminatedUnion("type", [
|
|
1581
|
+
z4.object({
|
|
1582
|
+
type: z4.literal("text"),
|
|
1583
|
+
text: z4.string()
|
|
1584
|
+
}),
|
|
1585
|
+
z4.object({
|
|
1586
|
+
type: z4.literal("thinking"),
|
|
1587
|
+
thinking: z4.string()
|
|
1588
|
+
}),
|
|
1589
|
+
z4.object({
|
|
1590
|
+
type: z4.literal("tool_use"),
|
|
1591
|
+
id: z4.string(),
|
|
1592
|
+
name: z4.string()
|
|
909
1593
|
}),
|
|
910
|
-
|
|
911
|
-
type:
|
|
912
|
-
|
|
1594
|
+
z4.object({
|
|
1595
|
+
type: z4.literal("redacted_thinking"),
|
|
1596
|
+
data: z4.string()
|
|
913
1597
|
}),
|
|
914
|
-
|
|
915
|
-
type:
|
|
916
|
-
id:
|
|
917
|
-
name:
|
|
1598
|
+
z4.object({
|
|
1599
|
+
type: z4.literal("server_tool_use"),
|
|
1600
|
+
id: z4.string(),
|
|
1601
|
+
name: z4.string(),
|
|
1602
|
+
input: z4.record(z4.string(), z4.unknown()).nullish()
|
|
918
1603
|
}),
|
|
919
|
-
|
|
920
|
-
type:
|
|
921
|
-
|
|
1604
|
+
z4.object({
|
|
1605
|
+
type: z4.literal("web_search_tool_result"),
|
|
1606
|
+
tool_use_id: z4.string(),
|
|
1607
|
+
content: z4.union([
|
|
1608
|
+
z4.array(
|
|
1609
|
+
z4.object({
|
|
1610
|
+
type: z4.literal("web_search_result"),
|
|
1611
|
+
url: z4.string(),
|
|
1612
|
+
title: z4.string(),
|
|
1613
|
+
encrypted_content: z4.string(),
|
|
1614
|
+
page_age: z4.string().nullish()
|
|
1615
|
+
})
|
|
1616
|
+
),
|
|
1617
|
+
z4.object({
|
|
1618
|
+
type: z4.literal("web_search_tool_result_error"),
|
|
1619
|
+
error_code: z4.string()
|
|
1620
|
+
})
|
|
1621
|
+
])
|
|
922
1622
|
})
|
|
923
1623
|
])
|
|
924
1624
|
}),
|
|
925
|
-
|
|
926
|
-
type:
|
|
927
|
-
index:
|
|
928
|
-
delta:
|
|
929
|
-
|
|
930
|
-
type:
|
|
931
|
-
partial_json:
|
|
1625
|
+
z4.object({
|
|
1626
|
+
type: z4.literal("content_block_delta"),
|
|
1627
|
+
index: z4.number(),
|
|
1628
|
+
delta: z4.discriminatedUnion("type", [
|
|
1629
|
+
z4.object({
|
|
1630
|
+
type: z4.literal("input_json_delta"),
|
|
1631
|
+
partial_json: z4.string()
|
|
932
1632
|
}),
|
|
933
|
-
|
|
934
|
-
type:
|
|
935
|
-
text:
|
|
1633
|
+
z4.object({
|
|
1634
|
+
type: z4.literal("text_delta"),
|
|
1635
|
+
text: z4.string()
|
|
936
1636
|
}),
|
|
937
|
-
|
|
938
|
-
type:
|
|
939
|
-
thinking:
|
|
1637
|
+
z4.object({
|
|
1638
|
+
type: z4.literal("thinking_delta"),
|
|
1639
|
+
thinking: z4.string()
|
|
940
1640
|
}),
|
|
941
|
-
|
|
942
|
-
type:
|
|
943
|
-
signature:
|
|
1641
|
+
z4.object({
|
|
1642
|
+
type: z4.literal("signature_delta"),
|
|
1643
|
+
signature: z4.string()
|
|
1644
|
+
}),
|
|
1645
|
+
z4.object({
|
|
1646
|
+
type: z4.literal("citations_delta"),
|
|
1647
|
+
citation: citationSchema
|
|
944
1648
|
})
|
|
945
1649
|
])
|
|
946
1650
|
}),
|
|
947
|
-
|
|
948
|
-
type:
|
|
949
|
-
index:
|
|
1651
|
+
z4.object({
|
|
1652
|
+
type: z4.literal("content_block_stop"),
|
|
1653
|
+
index: z4.number()
|
|
950
1654
|
}),
|
|
951
|
-
|
|
952
|
-
type:
|
|
953
|
-
error:
|
|
954
|
-
type:
|
|
955
|
-
message:
|
|
1655
|
+
z4.object({
|
|
1656
|
+
type: z4.literal("error"),
|
|
1657
|
+
error: z4.object({
|
|
1658
|
+
type: z4.string(),
|
|
1659
|
+
message: z4.string()
|
|
956
1660
|
})
|
|
957
1661
|
}),
|
|
958
|
-
|
|
959
|
-
type:
|
|
960
|
-
delta:
|
|
961
|
-
usage:
|
|
1662
|
+
z4.object({
|
|
1663
|
+
type: z4.literal("message_delta"),
|
|
1664
|
+
delta: z4.object({ stop_reason: z4.string().nullish() }),
|
|
1665
|
+
usage: z4.object({ output_tokens: z4.number() })
|
|
962
1666
|
}),
|
|
963
|
-
|
|
964
|
-
type:
|
|
1667
|
+
z4.object({
|
|
1668
|
+
type: z4.literal("message_stop")
|
|
965
1669
|
}),
|
|
966
|
-
|
|
967
|
-
type:
|
|
1670
|
+
z4.object({
|
|
1671
|
+
type: z4.literal("ping")
|
|
968
1672
|
})
|
|
969
1673
|
]);
|
|
970
|
-
var
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
budgetTokens: z2.number().optional()
|
|
974
|
-
}).optional()
|
|
1674
|
+
var anthropicReasoningMetadataSchema = z4.object({
|
|
1675
|
+
signature: z4.string().optional(),
|
|
1676
|
+
redactedData: z4.string().optional()
|
|
975
1677
|
});
|
|
976
1678
|
|
|
977
|
-
// src/
|
|
978
|
-
import {
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
1679
|
+
// src/tool/bash_20241022.ts
|
|
1680
|
+
import { createProviderDefinedToolFactory } from "@ai-sdk/provider-utils";
|
|
1681
|
+
import z5 from "zod/v4";
|
|
1682
|
+
var bash_20241022 = createProviderDefinedToolFactory({
|
|
1683
|
+
id: "anthropic.bash_20241022",
|
|
1684
|
+
name: "bash",
|
|
1685
|
+
inputSchema: z5.object({
|
|
1686
|
+
command: z5.string(),
|
|
1687
|
+
restart: z5.boolean().optional()
|
|
1688
|
+
})
|
|
982
1689
|
});
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
command: z3.string(),
|
|
995
|
-
restart: z3.boolean().optional()
|
|
1690
|
+
|
|
1691
|
+
// src/tool/bash_20250124.ts
|
|
1692
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory2 } from "@ai-sdk/provider-utils";
|
|
1693
|
+
import z6 from "zod/v4";
|
|
1694
|
+
var bash_20250124 = createProviderDefinedToolFactory2({
|
|
1695
|
+
id: "anthropic.bash_20250124",
|
|
1696
|
+
name: "bash",
|
|
1697
|
+
inputSchema: z6.object({
|
|
1698
|
+
command: z6.string(),
|
|
1699
|
+
restart: z6.boolean().optional()
|
|
1700
|
+
})
|
|
996
1701
|
});
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1702
|
+
|
|
1703
|
+
// src/tool/computer_20241022.ts
|
|
1704
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory3 } from "@ai-sdk/provider-utils";
|
|
1705
|
+
import { z as z7 } from "zod/v4";
|
|
1706
|
+
var computer_20241022 = createProviderDefinedToolFactory3({
|
|
1707
|
+
id: "anthropic.computer_20241022",
|
|
1708
|
+
name: "computer",
|
|
1709
|
+
inputSchema: z7.object({
|
|
1710
|
+
action: z7.enum([
|
|
1711
|
+
"key",
|
|
1712
|
+
"type",
|
|
1713
|
+
"mouse_move",
|
|
1714
|
+
"left_click",
|
|
1715
|
+
"left_click_drag",
|
|
1716
|
+
"right_click",
|
|
1717
|
+
"middle_click",
|
|
1718
|
+
"double_click",
|
|
1719
|
+
"screenshot",
|
|
1720
|
+
"cursor_position"
|
|
1721
|
+
]),
|
|
1722
|
+
coordinate: z7.array(z7.number().int()).optional(),
|
|
1723
|
+
text: z7.string().optional()
|
|
1724
|
+
})
|
|
1015
1725
|
});
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1726
|
+
|
|
1727
|
+
// src/tool/computer_20250124.ts
|
|
1728
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory4 } from "@ai-sdk/provider-utils";
|
|
1729
|
+
import { z as z8 } from "zod/v4";
|
|
1730
|
+
var computer_20250124 = createProviderDefinedToolFactory4({
|
|
1731
|
+
id: "anthropic.computer_20250124",
|
|
1732
|
+
name: "computer",
|
|
1733
|
+
inputSchema: z8.object({
|
|
1734
|
+
action: z8.enum([
|
|
1735
|
+
"key",
|
|
1736
|
+
"hold_key",
|
|
1737
|
+
"type",
|
|
1738
|
+
"cursor_position",
|
|
1739
|
+
"mouse_move",
|
|
1740
|
+
"left_mouse_down",
|
|
1741
|
+
"left_mouse_up",
|
|
1742
|
+
"left_click",
|
|
1743
|
+
"left_click_drag",
|
|
1744
|
+
"right_click",
|
|
1745
|
+
"middle_click",
|
|
1746
|
+
"double_click",
|
|
1747
|
+
"triple_click",
|
|
1748
|
+
"scroll",
|
|
1749
|
+
"wait",
|
|
1750
|
+
"screenshot"
|
|
1751
|
+
]),
|
|
1752
|
+
coordinate: z8.tuple([z8.number().int(), z8.number().int()]).optional(),
|
|
1753
|
+
duration: z8.number().optional(),
|
|
1754
|
+
scroll_amount: z8.number().optional(),
|
|
1755
|
+
scroll_direction: z8.enum(["up", "down", "left", "right"]).optional(),
|
|
1756
|
+
start_coordinate: z8.tuple([z8.number().int(), z8.number().int()]).optional(),
|
|
1757
|
+
text: z8.string().optional()
|
|
1758
|
+
})
|
|
1034
1759
|
});
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
"left_click_drag",
|
|
1052
|
-
"right_click",
|
|
1053
|
-
"middle_click",
|
|
1054
|
-
"double_click",
|
|
1055
|
-
"screenshot",
|
|
1056
|
-
"cursor_position"
|
|
1057
|
-
]),
|
|
1058
|
-
coordinate: z3.array(z3.number().int()).optional(),
|
|
1059
|
-
text: z3.string().optional()
|
|
1760
|
+
|
|
1761
|
+
// src/tool/text-editor_20241022.ts
|
|
1762
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory5 } from "@ai-sdk/provider-utils";
|
|
1763
|
+
import { z as z9 } from "zod/v4";
|
|
1764
|
+
var textEditor_20241022 = createProviderDefinedToolFactory5({
|
|
1765
|
+
id: "anthropic.text_editor_20241022",
|
|
1766
|
+
name: "str_replace_editor",
|
|
1767
|
+
inputSchema: z9.object({
|
|
1768
|
+
command: z9.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
1769
|
+
path: z9.string(),
|
|
1770
|
+
file_text: z9.string().optional(),
|
|
1771
|
+
insert_line: z9.number().int().optional(),
|
|
1772
|
+
new_str: z9.string().optional(),
|
|
1773
|
+
old_str: z9.string().optional(),
|
|
1774
|
+
view_range: z9.array(z9.number().int()).optional()
|
|
1775
|
+
})
|
|
1060
1776
|
});
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
"key",
|
|
1078
|
-
"hold_key",
|
|
1079
|
-
"type",
|
|
1080
|
-
"cursor_position",
|
|
1081
|
-
"mouse_move",
|
|
1082
|
-
"left_mouse_down",
|
|
1083
|
-
"left_mouse_up",
|
|
1084
|
-
"left_click",
|
|
1085
|
-
"left_click_drag",
|
|
1086
|
-
"right_click",
|
|
1087
|
-
"middle_click",
|
|
1088
|
-
"double_click",
|
|
1089
|
-
"triple_click",
|
|
1090
|
-
"scroll",
|
|
1091
|
-
"wait",
|
|
1092
|
-
"screenshot"
|
|
1093
|
-
]),
|
|
1094
|
-
coordinate: z3.tuple([z3.number().int(), z3.number().int()]).optional(),
|
|
1095
|
-
duration: z3.number().optional(),
|
|
1096
|
-
scroll_amount: z3.number().optional(),
|
|
1097
|
-
scroll_direction: z3.enum(["up", "down", "left", "right"]).optional(),
|
|
1098
|
-
start_coordinate: z3.tuple([z3.number().int(), z3.number().int()]).optional(),
|
|
1099
|
-
text: z3.string().optional()
|
|
1777
|
+
|
|
1778
|
+
// src/tool/text-editor_20250124.ts
|
|
1779
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory6 } from "@ai-sdk/provider-utils";
|
|
1780
|
+
import { z as z10 } from "zod/v4";
|
|
1781
|
+
var textEditor_20250124 = createProviderDefinedToolFactory6({
|
|
1782
|
+
id: "anthropic.text_editor_20250124",
|
|
1783
|
+
name: "str_replace_editor",
|
|
1784
|
+
inputSchema: z10.object({
|
|
1785
|
+
command: z10.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
1786
|
+
path: z10.string(),
|
|
1787
|
+
file_text: z10.string().optional(),
|
|
1788
|
+
insert_line: z10.number().int().optional(),
|
|
1789
|
+
new_str: z10.string().optional(),
|
|
1790
|
+
old_str: z10.string().optional(),
|
|
1791
|
+
view_range: z10.array(z10.number().int()).optional()
|
|
1792
|
+
})
|
|
1100
1793
|
});
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1794
|
+
|
|
1795
|
+
// src/tool/text-editor_20250429.ts
|
|
1796
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory7 } from "@ai-sdk/provider-utils";
|
|
1797
|
+
import { z as z11 } from "zod/v4";
|
|
1798
|
+
var textEditor_20250429 = createProviderDefinedToolFactory7({
|
|
1799
|
+
id: "anthropic.text_editor_20250429",
|
|
1800
|
+
name: "str_replace_based_edit_tool",
|
|
1801
|
+
inputSchema: z11.object({
|
|
1802
|
+
command: z11.enum(["view", "create", "str_replace", "insert"]),
|
|
1803
|
+
path: z11.string(),
|
|
1804
|
+
file_text: z11.string().optional(),
|
|
1805
|
+
insert_line: z11.number().int().optional(),
|
|
1806
|
+
new_str: z11.string().optional(),
|
|
1807
|
+
old_str: z11.string().optional(),
|
|
1808
|
+
view_range: z11.array(z11.number().int()).optional()
|
|
1809
|
+
})
|
|
1810
|
+
});
|
|
1811
|
+
|
|
1812
|
+
// src/anthropic-tools.ts
|
|
1115
1813
|
var anthropicTools = {
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1814
|
+
/**
|
|
1815
|
+
* Creates a tool for running a bash command. Must have name "bash".
|
|
1816
|
+
*
|
|
1817
|
+
* Image results are supported.
|
|
1818
|
+
*
|
|
1819
|
+
* @param execute - The function to execute the tool. Optional.
|
|
1820
|
+
*/
|
|
1821
|
+
bash_20241022,
|
|
1822
|
+
/**
|
|
1823
|
+
* Creates a tool for running a bash command. Must have name "bash".
|
|
1824
|
+
*
|
|
1825
|
+
* Image results are supported.
|
|
1826
|
+
*
|
|
1827
|
+
* @param execute - The function to execute the tool. Optional.
|
|
1828
|
+
*/
|
|
1829
|
+
bash_20250124,
|
|
1830
|
+
/**
|
|
1831
|
+
* Creates a tool for editing text. Must have name "str_replace_editor".
|
|
1832
|
+
*/
|
|
1833
|
+
textEditor_20241022,
|
|
1834
|
+
/**
|
|
1835
|
+
* Creates a tool for editing text. Must have name "str_replace_editor".
|
|
1836
|
+
*/
|
|
1837
|
+
textEditor_20250124,
|
|
1838
|
+
/**
|
|
1839
|
+
* Creates a tool for editing text. Must have name "str_replace_based_edit_tool".
|
|
1840
|
+
* Note: This version does not support the "undo_edit" command.
|
|
1841
|
+
*/
|
|
1842
|
+
textEditor_20250429,
|
|
1843
|
+
/**
|
|
1844
|
+
* Creates a tool for executing actions on a computer. Must have name "computer".
|
|
1845
|
+
*
|
|
1846
|
+
* Image results are supported.
|
|
1847
|
+
*
|
|
1848
|
+
* @param displayWidthPx - The width of the display being controlled by the model in pixels.
|
|
1849
|
+
* @param displayHeightPx - The height of the display being controlled by the model in pixels.
|
|
1850
|
+
* @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.
|
|
1851
|
+
*/
|
|
1852
|
+
computer_20241022,
|
|
1853
|
+
/**
|
|
1854
|
+
* Creates a tool for executing actions on a computer. Must have name "computer".
|
|
1855
|
+
*
|
|
1856
|
+
* Image results are supported.
|
|
1857
|
+
*
|
|
1858
|
+
* @param displayWidthPx - The width of the display being controlled by the model in pixels.
|
|
1859
|
+
* @param displayHeightPx - The height of the display being controlled by the model in pixels.
|
|
1860
|
+
* @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.
|
|
1861
|
+
* @param execute - The function to execute the tool. Optional.
|
|
1862
|
+
*/
|
|
1863
|
+
computer_20250124,
|
|
1864
|
+
/**
|
|
1865
|
+
* Creates a web search tool that gives Claude direct access to real-time web content.
|
|
1866
|
+
* Must have name "web_search".
|
|
1867
|
+
*
|
|
1868
|
+
* @param maxUses - Maximum number of web searches Claude can perform during the conversation.
|
|
1869
|
+
* @param allowedDomains - Optional list of domains that Claude is allowed to search.
|
|
1870
|
+
* @param blockedDomains - Optional list of domains that Claude should avoid when searching.
|
|
1871
|
+
* @param userLocation - Optional user location information to provide geographically relevant search results.
|
|
1872
|
+
*/
|
|
1873
|
+
webSearch_20250305
|
|
1122
1874
|
};
|
|
1123
1875
|
export {
|
|
1124
1876
|
AnthropicMessagesLanguageModel,
|
|
1125
|
-
anthropicTools
|
|
1877
|
+
anthropicTools,
|
|
1878
|
+
prepareTools
|
|
1126
1879
|
};
|
|
1127
1880
|
//# sourceMappingURL=index.mjs.map
|