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