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