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