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