@ai-sdk/anthropic 2.1.0-beta.1 → 2.1.0-beta.11
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 +88 -0
- package/dist/index.d.mts +114 -10
- package/dist/index.d.ts +114 -10
- package/dist/index.js +682 -389
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +665 -372
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +131 -15
- package/dist/internal/index.d.ts +131 -15
- package/dist/internal/index.js +662 -377
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +647 -362
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/internal/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
postJsonToApi,
|
|
12
12
|
resolve
|
|
13
13
|
} from "@ai-sdk/provider-utils";
|
|
14
|
-
import { z as
|
|
14
|
+
import { z as z7 } from "zod/v4";
|
|
15
15
|
|
|
16
16
|
// src/anthropic-error.ts
|
|
17
17
|
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
@@ -87,58 +87,110 @@ function getCacheControl(providerMetadata) {
|
|
|
87
87
|
return cacheControlValue;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
// src/tool/text-editor_20250728.ts
|
|
91
|
+
import { createProviderDefinedToolFactory } from "@ai-sdk/provider-utils";
|
|
92
|
+
import { z as z3 } from "zod/v4";
|
|
93
|
+
var textEditor_20250728ArgsSchema = z3.object({
|
|
94
|
+
maxCharacters: z3.number().optional()
|
|
95
|
+
});
|
|
96
|
+
var factory = createProviderDefinedToolFactory({
|
|
97
|
+
id: "anthropic.text_editor_20250728",
|
|
98
|
+
name: "str_replace_based_edit_tool",
|
|
99
|
+
inputSchema: z3.object({
|
|
100
|
+
command: z3.enum(["view", "create", "str_replace", "insert"]),
|
|
101
|
+
path: z3.string(),
|
|
102
|
+
file_text: z3.string().optional(),
|
|
103
|
+
insert_line: z3.number().int().optional(),
|
|
104
|
+
new_str: z3.string().optional(),
|
|
105
|
+
old_str: z3.string().optional(),
|
|
106
|
+
view_range: z3.array(z3.number().int()).optional()
|
|
107
|
+
})
|
|
108
|
+
});
|
|
109
|
+
var textEditor_20250728 = (args = {}) => {
|
|
110
|
+
return factory(args);
|
|
111
|
+
};
|
|
112
|
+
|
|
90
113
|
// src/tool/web-search_20250305.ts
|
|
91
114
|
import { createProviderDefinedToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils";
|
|
92
|
-
import { z as
|
|
93
|
-
var webSearch_20250305ArgsSchema =
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
* Optional list of domains that Claude should avoid when searching.
|
|
104
|
-
*/
|
|
105
|
-
blockedDomains: z3.array(z3.string()).optional(),
|
|
106
|
-
/**
|
|
107
|
-
* Optional user location information to provide geographically relevant search results.
|
|
108
|
-
*/
|
|
109
|
-
userLocation: z3.object({
|
|
110
|
-
type: z3.literal("approximate"),
|
|
111
|
-
city: z3.string().optional(),
|
|
112
|
-
region: z3.string().optional(),
|
|
113
|
-
country: z3.string().optional(),
|
|
114
|
-
timezone: z3.string().optional()
|
|
115
|
+
import { z as z4 } from "zod/v4";
|
|
116
|
+
var webSearch_20250305ArgsSchema = z4.object({
|
|
117
|
+
maxUses: z4.number().optional(),
|
|
118
|
+
allowedDomains: z4.array(z4.string()).optional(),
|
|
119
|
+
blockedDomains: z4.array(z4.string()).optional(),
|
|
120
|
+
userLocation: z4.object({
|
|
121
|
+
type: z4.literal("approximate"),
|
|
122
|
+
city: z4.string().optional(),
|
|
123
|
+
region: z4.string().optional(),
|
|
124
|
+
country: z4.string().optional(),
|
|
125
|
+
timezone: z4.string().optional()
|
|
115
126
|
}).optional()
|
|
116
127
|
});
|
|
117
|
-
var webSearch_20250305OutputSchema =
|
|
118
|
-
|
|
119
|
-
url:
|
|
120
|
-
title:
|
|
121
|
-
pageAge:
|
|
122
|
-
encryptedContent:
|
|
123
|
-
type:
|
|
128
|
+
var webSearch_20250305OutputSchema = z4.array(
|
|
129
|
+
z4.object({
|
|
130
|
+
url: z4.string(),
|
|
131
|
+
title: z4.string(),
|
|
132
|
+
pageAge: z4.string().nullable(),
|
|
133
|
+
encryptedContent: z4.string(),
|
|
134
|
+
type: z4.literal("web_search_result")
|
|
124
135
|
})
|
|
125
136
|
);
|
|
126
|
-
var
|
|
137
|
+
var factory2 = createProviderDefinedToolFactoryWithOutputSchema({
|
|
127
138
|
id: "anthropic.web_search_20250305",
|
|
128
139
|
name: "web_search",
|
|
129
|
-
inputSchema:
|
|
130
|
-
query:
|
|
140
|
+
inputSchema: z4.object({
|
|
141
|
+
query: z4.string()
|
|
131
142
|
}),
|
|
132
143
|
outputSchema: webSearch_20250305OutputSchema
|
|
133
144
|
});
|
|
134
145
|
var webSearch_20250305 = (args = {}) => {
|
|
135
|
-
return
|
|
146
|
+
return factory2(args);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// src/tool/web-fetch-20250910.ts
|
|
150
|
+
import { createProviderDefinedToolFactoryWithOutputSchema as createProviderDefinedToolFactoryWithOutputSchema2 } from "@ai-sdk/provider-utils";
|
|
151
|
+
import { z as z5 } from "zod/v4";
|
|
152
|
+
var webFetch_20250910ArgsSchema = z5.object({
|
|
153
|
+
maxUses: z5.number().optional(),
|
|
154
|
+
allowedDomains: z5.array(z5.string()).optional(),
|
|
155
|
+
blockedDomains: z5.array(z5.string()).optional(),
|
|
156
|
+
citations: z5.object({ enabled: z5.boolean() }).optional(),
|
|
157
|
+
maxContentTokens: z5.number().optional()
|
|
158
|
+
});
|
|
159
|
+
var webFetch_20250910OutputSchema = z5.object({
|
|
160
|
+
type: z5.literal("web_fetch_result"),
|
|
161
|
+
url: z5.string(),
|
|
162
|
+
content: z5.object({
|
|
163
|
+
type: z5.literal("document"),
|
|
164
|
+
title: z5.string(),
|
|
165
|
+
citations: z5.object({ enabled: z5.boolean() }).optional(),
|
|
166
|
+
source: z5.union([
|
|
167
|
+
z5.object({
|
|
168
|
+
type: z5.literal("base64"),
|
|
169
|
+
mediaType: z5.literal("application/pdf"),
|
|
170
|
+
data: z5.string()
|
|
171
|
+
}),
|
|
172
|
+
z5.object({
|
|
173
|
+
type: z5.literal("text"),
|
|
174
|
+
mediaType: z5.literal("text/plain"),
|
|
175
|
+
data: z5.string()
|
|
176
|
+
})
|
|
177
|
+
])
|
|
178
|
+
}),
|
|
179
|
+
retrievedAt: z5.string().nullable()
|
|
180
|
+
});
|
|
181
|
+
var factory3 = createProviderDefinedToolFactoryWithOutputSchema2({
|
|
182
|
+
id: "anthropic.web_fetch_20250910",
|
|
183
|
+
name: "web_fetch",
|
|
184
|
+
inputSchema: z5.object({
|
|
185
|
+
url: z5.string()
|
|
186
|
+
}),
|
|
187
|
+
outputSchema: webFetch_20250910OutputSchema
|
|
188
|
+
});
|
|
189
|
+
var webFetch_20250910 = (args = {}) => {
|
|
190
|
+
return factory3(args);
|
|
136
191
|
};
|
|
137
192
|
|
|
138
193
|
// src/anthropic-prepare-tools.ts
|
|
139
|
-
function isWebSearchTool(tool) {
|
|
140
|
-
return typeof tool === "object" && tool !== null && "type" in tool && tool.type === "web_search_20250305";
|
|
141
|
-
}
|
|
142
194
|
function prepareTools({
|
|
143
195
|
tools,
|
|
144
196
|
toolChoice,
|
|
@@ -152,12 +204,8 @@ function prepareTools({
|
|
|
152
204
|
}
|
|
153
205
|
const anthropicTools2 = [];
|
|
154
206
|
for (const tool of tools) {
|
|
155
|
-
if (isWebSearchTool(tool)) {
|
|
156
|
-
anthropicTools2.push(tool);
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
207
|
switch (tool.type) {
|
|
160
|
-
case "function":
|
|
208
|
+
case "function": {
|
|
161
209
|
const cacheControl = getCacheControl(tool.providerOptions);
|
|
162
210
|
anthropicTools2.push({
|
|
163
211
|
name: tool.name,
|
|
@@ -166,9 +214,18 @@ function prepareTools({
|
|
|
166
214
|
cache_control: cacheControl
|
|
167
215
|
});
|
|
168
216
|
break;
|
|
169
|
-
|
|
217
|
+
}
|
|
218
|
+
case "provider-defined": {
|
|
170
219
|
switch (tool.id) {
|
|
171
|
-
case "anthropic.
|
|
220
|
+
case "anthropic.code_execution_20250522": {
|
|
221
|
+
betas.add("code-execution-2025-05-22");
|
|
222
|
+
anthropicTools2.push({
|
|
223
|
+
type: "code_execution_20250522",
|
|
224
|
+
name: "code_execution"
|
|
225
|
+
});
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
case "anthropic.computer_20250124": {
|
|
172
229
|
betas.add("computer-use-2025-01-24");
|
|
173
230
|
anthropicTools2.push({
|
|
174
231
|
name: "computer",
|
|
@@ -178,7 +235,8 @@ function prepareTools({
|
|
|
178
235
|
display_number: tool.args.displayNumber
|
|
179
236
|
});
|
|
180
237
|
break;
|
|
181
|
-
|
|
238
|
+
}
|
|
239
|
+
case "anthropic.computer_20241022": {
|
|
182
240
|
betas.add("computer-use-2024-10-22");
|
|
183
241
|
anthropicTools2.push({
|
|
184
242
|
name: "computer",
|
|
@@ -188,41 +246,70 @@ function prepareTools({
|
|
|
188
246
|
display_number: tool.args.displayNumber
|
|
189
247
|
});
|
|
190
248
|
break;
|
|
191
|
-
|
|
249
|
+
}
|
|
250
|
+
case "anthropic.text_editor_20250124": {
|
|
192
251
|
betas.add("computer-use-2025-01-24");
|
|
193
252
|
anthropicTools2.push({
|
|
194
253
|
name: "str_replace_editor",
|
|
195
254
|
type: "text_editor_20250124"
|
|
196
255
|
});
|
|
197
256
|
break;
|
|
198
|
-
|
|
257
|
+
}
|
|
258
|
+
case "anthropic.text_editor_20241022": {
|
|
199
259
|
betas.add("computer-use-2024-10-22");
|
|
200
260
|
anthropicTools2.push({
|
|
201
261
|
name: "str_replace_editor",
|
|
202
262
|
type: "text_editor_20241022"
|
|
203
263
|
});
|
|
204
264
|
break;
|
|
205
|
-
|
|
265
|
+
}
|
|
266
|
+
case "anthropic.text_editor_20250429": {
|
|
206
267
|
betas.add("computer-use-2025-01-24");
|
|
207
268
|
anthropicTools2.push({
|
|
208
269
|
name: "str_replace_based_edit_tool",
|
|
209
270
|
type: "text_editor_20250429"
|
|
210
271
|
});
|
|
211
272
|
break;
|
|
212
|
-
|
|
273
|
+
}
|
|
274
|
+
case "anthropic.text_editor_20250728": {
|
|
275
|
+
const args = textEditor_20250728ArgsSchema.parse(tool.args);
|
|
276
|
+
anthropicTools2.push({
|
|
277
|
+
name: "str_replace_based_edit_tool",
|
|
278
|
+
type: "text_editor_20250728",
|
|
279
|
+
max_characters: args.maxCharacters
|
|
280
|
+
});
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
case "anthropic.bash_20250124": {
|
|
213
284
|
betas.add("computer-use-2025-01-24");
|
|
214
285
|
anthropicTools2.push({
|
|
215
286
|
name: "bash",
|
|
216
287
|
type: "bash_20250124"
|
|
217
288
|
});
|
|
218
289
|
break;
|
|
219
|
-
|
|
290
|
+
}
|
|
291
|
+
case "anthropic.bash_20241022": {
|
|
220
292
|
betas.add("computer-use-2024-10-22");
|
|
221
293
|
anthropicTools2.push({
|
|
222
294
|
name: "bash",
|
|
223
295
|
type: "bash_20241022"
|
|
224
296
|
});
|
|
225
297
|
break;
|
|
298
|
+
}
|
|
299
|
+
case "anthropic.web_fetch_20250910": {
|
|
300
|
+
betas.add("web-fetch-2025-09-10");
|
|
301
|
+
const args = webFetch_20250910ArgsSchema.parse(tool.args);
|
|
302
|
+
anthropicTools2.push({
|
|
303
|
+
type: "web_fetch_20250910",
|
|
304
|
+
name: "web_fetch",
|
|
305
|
+
max_uses: args.maxUses,
|
|
306
|
+
allowed_domains: args.allowedDomains,
|
|
307
|
+
blocked_domains: args.blockedDomains,
|
|
308
|
+
citations: args.citations,
|
|
309
|
+
max_content_tokens: args.maxContentTokens
|
|
310
|
+
});
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
226
313
|
case "anthropic.web_search_20250305": {
|
|
227
314
|
const args = webSearch_20250305ArgsSchema.parse(tool.args);
|
|
228
315
|
anthropicTools2.push({
|
|
@@ -235,22 +322,17 @@ function prepareTools({
|
|
|
235
322
|
});
|
|
236
323
|
break;
|
|
237
324
|
}
|
|
238
|
-
|
|
239
|
-
betas.add("code-execution-2025-05-22");
|
|
240
|
-
anthropicTools2.push({
|
|
241
|
-
type: "code_execution_20250522",
|
|
242
|
-
name: "code_execution"
|
|
243
|
-
});
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
default:
|
|
325
|
+
default: {
|
|
247
326
|
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
248
327
|
break;
|
|
328
|
+
}
|
|
249
329
|
}
|
|
250
330
|
break;
|
|
251
|
-
|
|
331
|
+
}
|
|
332
|
+
default: {
|
|
252
333
|
toolWarnings.push({ type: "unsupported-tool", tool });
|
|
253
334
|
break;
|
|
335
|
+
}
|
|
254
336
|
}
|
|
255
337
|
}
|
|
256
338
|
if (toolChoice == null) {
|
|
@@ -312,24 +394,24 @@ import {
|
|
|
312
394
|
import { convertToBase64, parseProviderOptions } from "@ai-sdk/provider-utils";
|
|
313
395
|
|
|
314
396
|
// src/tool/code-execution_20250522.ts
|
|
315
|
-
import { createProviderDefinedToolFactoryWithOutputSchema as
|
|
316
|
-
import { z as
|
|
317
|
-
var codeExecution_20250522OutputSchema =
|
|
318
|
-
type:
|
|
319
|
-
stdout:
|
|
320
|
-
stderr:
|
|
321
|
-
return_code:
|
|
397
|
+
import { createProviderDefinedToolFactoryWithOutputSchema as createProviderDefinedToolFactoryWithOutputSchema3 } from "@ai-sdk/provider-utils";
|
|
398
|
+
import { z as z6 } from "zod/v4";
|
|
399
|
+
var codeExecution_20250522OutputSchema = z6.object({
|
|
400
|
+
type: z6.literal("code_execution_result"),
|
|
401
|
+
stdout: z6.string(),
|
|
402
|
+
stderr: z6.string(),
|
|
403
|
+
return_code: z6.number()
|
|
322
404
|
});
|
|
323
|
-
var
|
|
405
|
+
var factory4 = createProviderDefinedToolFactoryWithOutputSchema3({
|
|
324
406
|
id: "anthropic.code_execution_20250522",
|
|
325
407
|
name: "code_execution",
|
|
326
|
-
inputSchema:
|
|
327
|
-
code:
|
|
408
|
+
inputSchema: z6.object({
|
|
409
|
+
code: z6.string()
|
|
328
410
|
}),
|
|
329
411
|
outputSchema: codeExecution_20250522OutputSchema
|
|
330
412
|
});
|
|
331
413
|
var codeExecution_20250522 = (args = {}) => {
|
|
332
|
-
return
|
|
414
|
+
return factory4(args);
|
|
333
415
|
};
|
|
334
416
|
|
|
335
417
|
// src/convert-to-anthropic-messages-prompt.ts
|
|
@@ -354,7 +436,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
354
436
|
sendReasoning,
|
|
355
437
|
warnings
|
|
356
438
|
}) {
|
|
357
|
-
var _a, _b, _c, _d, _e;
|
|
439
|
+
var _a, _b, _c, _d, _e, _f;
|
|
358
440
|
const betas = /* @__PURE__ */ new Set();
|
|
359
441
|
const blocks = groupIntoBlocks(prompt);
|
|
360
442
|
let system = void 0;
|
|
@@ -530,6 +612,9 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
530
612
|
case "error-text":
|
|
531
613
|
contentValue = output.value;
|
|
532
614
|
break;
|
|
615
|
+
case "execution-denied":
|
|
616
|
+
contentValue = (_e = output.reason) != null ? _e : "Tool execution denied.";
|
|
617
|
+
break;
|
|
533
618
|
case "json":
|
|
534
619
|
case "error-json":
|
|
535
620
|
default:
|
|
@@ -564,7 +649,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
564
649
|
for (let k = 0; k < content.length; k++) {
|
|
565
650
|
const part = content[k];
|
|
566
651
|
const isLastContentPart = k === content.length - 1;
|
|
567
|
-
const cacheControl = (
|
|
652
|
+
const cacheControl = (_f = getCacheControl(part.providerOptions)) != null ? _f : isLastContentPart ? getCacheControl(message.providerOptions) : void 0;
|
|
568
653
|
switch (part.type) {
|
|
569
654
|
case "text": {
|
|
570
655
|
anthropicContent.push({
|
|
@@ -622,30 +707,20 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
622
707
|
}
|
|
623
708
|
case "tool-call": {
|
|
624
709
|
if (part.providerExecuted) {
|
|
625
|
-
if (part.toolName === "web_search") {
|
|
710
|
+
if (part.toolName === "code_execution" || part.toolName === "web_fetch" || part.toolName === "web_search") {
|
|
626
711
|
anthropicContent.push({
|
|
627
712
|
type: "server_tool_use",
|
|
628
713
|
id: part.toolCallId,
|
|
629
|
-
name:
|
|
714
|
+
name: part.toolName,
|
|
630
715
|
input: part.input,
|
|
631
716
|
cache_control: cacheControl
|
|
632
717
|
});
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
type: "server_tool_use",
|
|
638
|
-
id: part.toolCallId,
|
|
639
|
-
name: "code_execution",
|
|
640
|
-
input: part.input,
|
|
641
|
-
cache_control: cacheControl
|
|
718
|
+
} else {
|
|
719
|
+
warnings.push({
|
|
720
|
+
type: "other",
|
|
721
|
+
message: `provider executed tool call for tool ${part.toolName} is not supported`
|
|
642
722
|
});
|
|
643
|
-
break;
|
|
644
723
|
}
|
|
645
|
-
warnings.push({
|
|
646
|
-
type: "other",
|
|
647
|
-
message: `provider executed tool call for tool ${part.toolName} is not supported`
|
|
648
|
-
});
|
|
649
724
|
break;
|
|
650
725
|
}
|
|
651
726
|
anthropicContent.push({
|
|
@@ -658,7 +733,7 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
658
733
|
break;
|
|
659
734
|
}
|
|
660
735
|
case "tool-result": {
|
|
661
|
-
if (part.toolName === "
|
|
736
|
+
if (part.toolName === "code_execution") {
|
|
662
737
|
const output = part.output;
|
|
663
738
|
if (output.type !== "json") {
|
|
664
739
|
warnings.push({
|
|
@@ -667,24 +742,21 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
667
742
|
});
|
|
668
743
|
break;
|
|
669
744
|
}
|
|
670
|
-
const
|
|
671
|
-
output.value
|
|
672
|
-
);
|
|
745
|
+
const codeExecutionOutput = codeExecution_20250522OutputSchema.parse(output.value);
|
|
673
746
|
anthropicContent.push({
|
|
674
|
-
type: "
|
|
747
|
+
type: "code_execution_tool_result",
|
|
675
748
|
tool_use_id: part.toolCallId,
|
|
676
|
-
content:
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
})),
|
|
749
|
+
content: {
|
|
750
|
+
type: codeExecutionOutput.type,
|
|
751
|
+
stdout: codeExecutionOutput.stdout,
|
|
752
|
+
stderr: codeExecutionOutput.stderr,
|
|
753
|
+
return_code: codeExecutionOutput.return_code
|
|
754
|
+
},
|
|
683
755
|
cache_control: cacheControl
|
|
684
756
|
});
|
|
685
757
|
break;
|
|
686
758
|
}
|
|
687
|
-
if (part.toolName === "
|
|
759
|
+
if (part.toolName === "web_fetch") {
|
|
688
760
|
const output = part.output;
|
|
689
761
|
if (output.type !== "json") {
|
|
690
762
|
warnings.push({
|
|
@@ -693,20 +765,57 @@ async function convertToAnthropicMessagesPrompt({
|
|
|
693
765
|
});
|
|
694
766
|
break;
|
|
695
767
|
}
|
|
696
|
-
const
|
|
768
|
+
const webFetchOutput = webFetch_20250910OutputSchema.parse(
|
|
769
|
+
output.value
|
|
770
|
+
);
|
|
697
771
|
anthropicContent.push({
|
|
698
|
-
type: "
|
|
772
|
+
type: "web_fetch_tool_result",
|
|
699
773
|
tool_use_id: part.toolCallId,
|
|
700
774
|
content: {
|
|
701
|
-
type:
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
775
|
+
type: "web_fetch_result",
|
|
776
|
+
url: webFetchOutput.url,
|
|
777
|
+
retrieved_at: webFetchOutput.retrievedAt,
|
|
778
|
+
content: {
|
|
779
|
+
type: "document",
|
|
780
|
+
title: webFetchOutput.content.title,
|
|
781
|
+
citations: webFetchOutput.content.citations,
|
|
782
|
+
source: {
|
|
783
|
+
type: webFetchOutput.content.source.type,
|
|
784
|
+
media_type: webFetchOutput.content.source.mediaType,
|
|
785
|
+
data: webFetchOutput.content.source.data
|
|
786
|
+
}
|
|
787
|
+
}
|
|
705
788
|
},
|
|
706
789
|
cache_control: cacheControl
|
|
707
790
|
});
|
|
708
791
|
break;
|
|
709
792
|
}
|
|
793
|
+
if (part.toolName === "web_search") {
|
|
794
|
+
const output = part.output;
|
|
795
|
+
if (output.type !== "json") {
|
|
796
|
+
warnings.push({
|
|
797
|
+
type: "other",
|
|
798
|
+
message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
|
|
799
|
+
});
|
|
800
|
+
break;
|
|
801
|
+
}
|
|
802
|
+
const webSearchOutput = webSearch_20250305OutputSchema.parse(
|
|
803
|
+
output.value
|
|
804
|
+
);
|
|
805
|
+
anthropicContent.push({
|
|
806
|
+
type: "web_search_tool_result",
|
|
807
|
+
tool_use_id: part.toolCallId,
|
|
808
|
+
content: webSearchOutput.map((result) => ({
|
|
809
|
+
url: result.url,
|
|
810
|
+
title: result.title,
|
|
811
|
+
page_age: result.pageAge,
|
|
812
|
+
encrypted_content: result.encryptedContent,
|
|
813
|
+
type: result.type
|
|
814
|
+
})),
|
|
815
|
+
cache_control: cacheControl
|
|
816
|
+
});
|
|
817
|
+
break;
|
|
818
|
+
}
|
|
710
819
|
warnings.push({
|
|
711
820
|
type: "other",
|
|
712
821
|
message: `provider executed tool result for tool ${part.toolName} is not supported`
|
|
@@ -800,36 +909,36 @@ function mapAnthropicStopReason({
|
|
|
800
909
|
|
|
801
910
|
// src/anthropic-messages-language-model.ts
|
|
802
911
|
var citationSchemas = {
|
|
803
|
-
webSearchResult:
|
|
804
|
-
type:
|
|
805
|
-
cited_text:
|
|
806
|
-
url:
|
|
807
|
-
title:
|
|
808
|
-
encrypted_index:
|
|
912
|
+
webSearchResult: z7.object({
|
|
913
|
+
type: z7.literal("web_search_result_location"),
|
|
914
|
+
cited_text: z7.string(),
|
|
915
|
+
url: z7.string(),
|
|
916
|
+
title: z7.string(),
|
|
917
|
+
encrypted_index: z7.string()
|
|
809
918
|
}),
|
|
810
|
-
pageLocation:
|
|
811
|
-
type:
|
|
812
|
-
cited_text:
|
|
813
|
-
document_index:
|
|
814
|
-
document_title:
|
|
815
|
-
start_page_number:
|
|
816
|
-
end_page_number:
|
|
919
|
+
pageLocation: z7.object({
|
|
920
|
+
type: z7.literal("page_location"),
|
|
921
|
+
cited_text: z7.string(),
|
|
922
|
+
document_index: z7.number(),
|
|
923
|
+
document_title: z7.string().nullable(),
|
|
924
|
+
start_page_number: z7.number(),
|
|
925
|
+
end_page_number: z7.number()
|
|
817
926
|
}),
|
|
818
|
-
charLocation:
|
|
819
|
-
type:
|
|
820
|
-
cited_text:
|
|
821
|
-
document_index:
|
|
822
|
-
document_title:
|
|
823
|
-
start_char_index:
|
|
824
|
-
end_char_index:
|
|
927
|
+
charLocation: z7.object({
|
|
928
|
+
type: z7.literal("char_location"),
|
|
929
|
+
cited_text: z7.string(),
|
|
930
|
+
document_index: z7.number(),
|
|
931
|
+
document_title: z7.string().nullable(),
|
|
932
|
+
start_char_index: z7.number(),
|
|
933
|
+
end_char_index: z7.number()
|
|
825
934
|
})
|
|
826
935
|
};
|
|
827
|
-
var citationSchema =
|
|
936
|
+
var citationSchema = z7.discriminatedUnion("type", [
|
|
828
937
|
citationSchemas.webSearchResult,
|
|
829
938
|
citationSchemas.pageLocation,
|
|
830
939
|
citationSchemas.charLocation
|
|
831
940
|
]);
|
|
832
|
-
var documentCitationSchema =
|
|
941
|
+
var documentCitationSchema = z7.discriminatedUnion("type", [
|
|
833
942
|
citationSchemas.pageLocation,
|
|
834
943
|
citationSchemas.charLocation
|
|
835
944
|
]);
|
|
@@ -874,7 +983,7 @@ function createCitationSource(citation, citationDocuments, generateId2) {
|
|
|
874
983
|
}
|
|
875
984
|
var AnthropicMessagesLanguageModel = class {
|
|
876
985
|
constructor(modelId, config) {
|
|
877
|
-
this.specificationVersion = "
|
|
986
|
+
this.specificationVersion = "v3";
|
|
878
987
|
var _a;
|
|
879
988
|
this.modelId = modelId;
|
|
880
989
|
this.config = config;
|
|
@@ -1077,7 +1186,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1077
1186
|
});
|
|
1078
1187
|
}
|
|
1079
1188
|
async doGenerate(options) {
|
|
1080
|
-
var _a, _b, _c, _d, _e;
|
|
1189
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1081
1190
|
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
|
|
1082
1191
|
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
1083
1192
|
const {
|
|
@@ -1154,7 +1263,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1154
1263
|
break;
|
|
1155
1264
|
}
|
|
1156
1265
|
case "server_tool_use": {
|
|
1157
|
-
if (part.name === "web_search" || part.name === "code_execution") {
|
|
1266
|
+
if (part.name === "web_search" || part.name === "code_execution" || part.name === "web_fetch") {
|
|
1158
1267
|
content.push({
|
|
1159
1268
|
type: "tool-call",
|
|
1160
1269
|
toolCallId: part.id,
|
|
@@ -1165,6 +1274,44 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1165
1274
|
}
|
|
1166
1275
|
break;
|
|
1167
1276
|
}
|
|
1277
|
+
case "web_fetch_tool_result": {
|
|
1278
|
+
if (part.content.type === "web_fetch_result") {
|
|
1279
|
+
content.push({
|
|
1280
|
+
type: "tool-result",
|
|
1281
|
+
toolCallId: part.tool_use_id,
|
|
1282
|
+
toolName: "web_fetch",
|
|
1283
|
+
result: {
|
|
1284
|
+
type: "web_fetch_result",
|
|
1285
|
+
url: part.content.url,
|
|
1286
|
+
retrievedAt: part.content.retrieved_at,
|
|
1287
|
+
content: {
|
|
1288
|
+
type: part.content.content.type,
|
|
1289
|
+
title: part.content.content.title,
|
|
1290
|
+
citations: part.content.content.citations,
|
|
1291
|
+
source: {
|
|
1292
|
+
type: part.content.content.source.type,
|
|
1293
|
+
mediaType: part.content.content.source.media_type,
|
|
1294
|
+
data: part.content.content.source.data
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
},
|
|
1298
|
+
providerExecuted: true
|
|
1299
|
+
});
|
|
1300
|
+
} else if (part.content.type === "web_fetch_tool_result_error") {
|
|
1301
|
+
content.push({
|
|
1302
|
+
type: "tool-result",
|
|
1303
|
+
toolCallId: part.tool_use_id,
|
|
1304
|
+
toolName: "web_fetch",
|
|
1305
|
+
isError: true,
|
|
1306
|
+
result: {
|
|
1307
|
+
type: "web_fetch_tool_result_error",
|
|
1308
|
+
errorCode: part.content.error_code
|
|
1309
|
+
},
|
|
1310
|
+
providerExecuted: true
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
break;
|
|
1314
|
+
}
|
|
1168
1315
|
case "web_search_tool_result": {
|
|
1169
1316
|
if (Array.isArray(part.content)) {
|
|
1170
1317
|
content.push({
|
|
@@ -1266,7 +1413,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1266
1413
|
providerMetadata: {
|
|
1267
1414
|
anthropic: {
|
|
1268
1415
|
usage: response.usage,
|
|
1269
|
-
cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null
|
|
1416
|
+
cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null,
|
|
1417
|
+
stopSequence: (_f = response.stop_sequence) != null ? _f : null
|
|
1270
1418
|
}
|
|
1271
1419
|
}
|
|
1272
1420
|
};
|
|
@@ -1293,7 +1441,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1293
1441
|
totalTokens: void 0
|
|
1294
1442
|
};
|
|
1295
1443
|
const contentBlocks = {};
|
|
1296
|
-
let
|
|
1444
|
+
let rawUsage = void 0;
|
|
1445
|
+
let cacheCreationInputTokens = null;
|
|
1446
|
+
let stopSequence = null;
|
|
1297
1447
|
let blockType = void 0;
|
|
1298
1448
|
const generateId2 = this.generateId;
|
|
1299
1449
|
return {
|
|
@@ -1303,7 +1453,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1303
1453
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1304
1454
|
},
|
|
1305
1455
|
transform(chunk, controller) {
|
|
1306
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1456
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1307
1457
|
if (options.includeRawChunks) {
|
|
1308
1458
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1309
1459
|
}
|
|
@@ -1366,7 +1516,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1366
1516
|
return;
|
|
1367
1517
|
}
|
|
1368
1518
|
case "server_tool_use": {
|
|
1369
|
-
if (value.content_block.name === "web_search" || value.content_block.name === "code_execution") {
|
|
1519
|
+
if (value.content_block.name === "web_fetch" || value.content_block.name === "web_search" || value.content_block.name === "code_execution") {
|
|
1370
1520
|
contentBlocks[value.index] = {
|
|
1371
1521
|
type: "tool-call",
|
|
1372
1522
|
toolCallId: value.content_block.id,
|
|
@@ -1383,6 +1533,44 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1383
1533
|
}
|
|
1384
1534
|
return;
|
|
1385
1535
|
}
|
|
1536
|
+
case "web_fetch_tool_result": {
|
|
1537
|
+
const part = value.content_block;
|
|
1538
|
+
if (part.content.type === "web_fetch_result") {
|
|
1539
|
+
controller.enqueue({
|
|
1540
|
+
type: "tool-result",
|
|
1541
|
+
toolCallId: part.tool_use_id,
|
|
1542
|
+
toolName: "web_fetch",
|
|
1543
|
+
result: {
|
|
1544
|
+
type: "web_fetch_result",
|
|
1545
|
+
url: part.content.url,
|
|
1546
|
+
retrievedAt: part.content.retrieved_at,
|
|
1547
|
+
content: {
|
|
1548
|
+
type: part.content.content.type,
|
|
1549
|
+
title: part.content.content.title,
|
|
1550
|
+
citations: part.content.content.citations,
|
|
1551
|
+
source: {
|
|
1552
|
+
type: part.content.content.source.type,
|
|
1553
|
+
mediaType: part.content.content.source.media_type,
|
|
1554
|
+
data: part.content.content.source.data
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
});
|
|
1559
|
+
} else if (part.content.type === "web_fetch_tool_result_error") {
|
|
1560
|
+
controller.enqueue({
|
|
1561
|
+
type: "tool-result",
|
|
1562
|
+
toolCallId: part.tool_use_id,
|
|
1563
|
+
toolName: "web_fetch",
|
|
1564
|
+
isError: true,
|
|
1565
|
+
result: {
|
|
1566
|
+
type: "web_fetch_tool_result_error",
|
|
1567
|
+
errorCode: part.content.error_code
|
|
1568
|
+
},
|
|
1569
|
+
providerExecuted: true
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
return;
|
|
1573
|
+
}
|
|
1386
1574
|
case "web_search_tool_result": {
|
|
1387
1575
|
const part = value.content_block;
|
|
1388
1576
|
if (Array.isArray(part.content)) {
|
|
@@ -1585,12 +1773,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1585
1773
|
case "message_start": {
|
|
1586
1774
|
usage.inputTokens = value.message.usage.input_tokens;
|
|
1587
1775
|
usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
usage: value.message.usage,
|
|
1591
|
-
cacheCreationInputTokens: (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null
|
|
1592
|
-
}
|
|
1776
|
+
rawUsage = {
|
|
1777
|
+
...value.message.usage
|
|
1593
1778
|
};
|
|
1779
|
+
cacheCreationInputTokens = (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null;
|
|
1594
1780
|
controller.enqueue({
|
|
1595
1781
|
type: "response-metadata",
|
|
1596
1782
|
id: (_d = value.message.id) != null ? _d : void 0,
|
|
@@ -1605,6 +1791,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1605
1791
|
finishReason: value.delta.stop_reason,
|
|
1606
1792
|
isJsonResponseFromTool: usesJsonResponseTool
|
|
1607
1793
|
});
|
|
1794
|
+
stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
|
|
1795
|
+
rawUsage = {
|
|
1796
|
+
...rawUsage,
|
|
1797
|
+
...value.usage
|
|
1798
|
+
};
|
|
1608
1799
|
return;
|
|
1609
1800
|
}
|
|
1610
1801
|
case "message_stop": {
|
|
@@ -1612,7 +1803,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1612
1803
|
type: "finish",
|
|
1613
1804
|
finishReason,
|
|
1614
1805
|
usage,
|
|
1615
|
-
providerMetadata
|
|
1806
|
+
providerMetadata: {
|
|
1807
|
+
anthropic: {
|
|
1808
|
+
usage: rawUsage != null ? rawUsage : null,
|
|
1809
|
+
cacheCreationInputTokens,
|
|
1810
|
+
stopSequence
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1616
1813
|
});
|
|
1617
1814
|
return;
|
|
1618
1815
|
}
|
|
@@ -1633,247 +1830,303 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1633
1830
|
};
|
|
1634
1831
|
}
|
|
1635
1832
|
};
|
|
1636
|
-
var anthropicMessagesResponseSchema =
|
|
1637
|
-
type:
|
|
1638
|
-
id:
|
|
1639
|
-
model:
|
|
1640
|
-
content:
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
type:
|
|
1644
|
-
text:
|
|
1645
|
-
citations:
|
|
1833
|
+
var anthropicMessagesResponseSchema = z7.object({
|
|
1834
|
+
type: z7.literal("message"),
|
|
1835
|
+
id: z7.string().nullish(),
|
|
1836
|
+
model: z7.string().nullish(),
|
|
1837
|
+
content: z7.array(
|
|
1838
|
+
z7.discriminatedUnion("type", [
|
|
1839
|
+
z7.object({
|
|
1840
|
+
type: z7.literal("text"),
|
|
1841
|
+
text: z7.string(),
|
|
1842
|
+
citations: z7.array(citationSchema).optional()
|
|
1646
1843
|
}),
|
|
1647
|
-
|
|
1648
|
-
type:
|
|
1649
|
-
thinking:
|
|
1650
|
-
signature:
|
|
1844
|
+
z7.object({
|
|
1845
|
+
type: z7.literal("thinking"),
|
|
1846
|
+
thinking: z7.string(),
|
|
1847
|
+
signature: z7.string()
|
|
1651
1848
|
}),
|
|
1652
|
-
|
|
1653
|
-
type:
|
|
1654
|
-
data:
|
|
1849
|
+
z7.object({
|
|
1850
|
+
type: z7.literal("redacted_thinking"),
|
|
1851
|
+
data: z7.string()
|
|
1655
1852
|
}),
|
|
1656
|
-
|
|
1657
|
-
type:
|
|
1658
|
-
id:
|
|
1659
|
-
name:
|
|
1660
|
-
input:
|
|
1853
|
+
z7.object({
|
|
1854
|
+
type: z7.literal("tool_use"),
|
|
1855
|
+
id: z7.string(),
|
|
1856
|
+
name: z7.string(),
|
|
1857
|
+
input: z7.unknown()
|
|
1661
1858
|
}),
|
|
1662
|
-
|
|
1663
|
-
type:
|
|
1664
|
-
id:
|
|
1665
|
-
name:
|
|
1666
|
-
input:
|
|
1859
|
+
z7.object({
|
|
1860
|
+
type: z7.literal("server_tool_use"),
|
|
1861
|
+
id: z7.string(),
|
|
1862
|
+
name: z7.string(),
|
|
1863
|
+
input: z7.record(z7.string(), z7.unknown()).nullish()
|
|
1667
1864
|
}),
|
|
1668
|
-
|
|
1669
|
-
type:
|
|
1670
|
-
tool_use_id:
|
|
1671
|
-
content:
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1865
|
+
z7.object({
|
|
1866
|
+
type: z7.literal("web_fetch_tool_result"),
|
|
1867
|
+
tool_use_id: z7.string(),
|
|
1868
|
+
content: z7.union([
|
|
1869
|
+
z7.object({
|
|
1870
|
+
type: z7.literal("web_fetch_result"),
|
|
1871
|
+
url: z7.string(),
|
|
1872
|
+
retrieved_at: z7.string(),
|
|
1873
|
+
content: z7.object({
|
|
1874
|
+
type: z7.literal("document"),
|
|
1875
|
+
title: z7.string().nullable(),
|
|
1876
|
+
citations: z7.object({ enabled: z7.boolean() }).optional(),
|
|
1877
|
+
source: z7.object({
|
|
1878
|
+
type: z7.literal("text"),
|
|
1879
|
+
media_type: z7.string(),
|
|
1880
|
+
data: z7.string()
|
|
1881
|
+
})
|
|
1882
|
+
})
|
|
1883
|
+
}),
|
|
1884
|
+
z7.object({
|
|
1885
|
+
type: z7.literal("web_fetch_tool_result_error"),
|
|
1886
|
+
error_code: z7.string()
|
|
1887
|
+
})
|
|
1888
|
+
])
|
|
1889
|
+
}),
|
|
1890
|
+
z7.object({
|
|
1891
|
+
type: z7.literal("web_search_tool_result"),
|
|
1892
|
+
tool_use_id: z7.string(),
|
|
1893
|
+
content: z7.union([
|
|
1894
|
+
z7.array(
|
|
1895
|
+
z7.object({
|
|
1896
|
+
type: z7.literal("web_search_result"),
|
|
1897
|
+
url: z7.string(),
|
|
1898
|
+
title: z7.string(),
|
|
1899
|
+
encrypted_content: z7.string(),
|
|
1900
|
+
page_age: z7.string().nullish()
|
|
1679
1901
|
})
|
|
1680
1902
|
),
|
|
1681
|
-
|
|
1682
|
-
type:
|
|
1683
|
-
error_code:
|
|
1903
|
+
z7.object({
|
|
1904
|
+
type: z7.literal("web_search_tool_result_error"),
|
|
1905
|
+
error_code: z7.string()
|
|
1684
1906
|
})
|
|
1685
1907
|
])
|
|
1686
1908
|
}),
|
|
1687
|
-
|
|
1688
|
-
type:
|
|
1689
|
-
tool_use_id:
|
|
1690
|
-
content:
|
|
1691
|
-
|
|
1692
|
-
type:
|
|
1693
|
-
stdout:
|
|
1694
|
-
stderr:
|
|
1695
|
-
return_code:
|
|
1909
|
+
z7.object({
|
|
1910
|
+
type: z7.literal("code_execution_tool_result"),
|
|
1911
|
+
tool_use_id: z7.string(),
|
|
1912
|
+
content: z7.union([
|
|
1913
|
+
z7.object({
|
|
1914
|
+
type: z7.literal("code_execution_result"),
|
|
1915
|
+
stdout: z7.string(),
|
|
1916
|
+
stderr: z7.string(),
|
|
1917
|
+
return_code: z7.number()
|
|
1696
1918
|
}),
|
|
1697
|
-
|
|
1698
|
-
type:
|
|
1699
|
-
error_code:
|
|
1919
|
+
z7.object({
|
|
1920
|
+
type: z7.literal("code_execution_tool_result_error"),
|
|
1921
|
+
error_code: z7.string()
|
|
1700
1922
|
})
|
|
1701
1923
|
])
|
|
1702
1924
|
})
|
|
1703
1925
|
])
|
|
1704
1926
|
),
|
|
1705
|
-
stop_reason:
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1927
|
+
stop_reason: z7.string().nullish(),
|
|
1928
|
+
stop_sequence: z7.string().nullish(),
|
|
1929
|
+
usage: z7.looseObject({
|
|
1930
|
+
input_tokens: z7.number(),
|
|
1931
|
+
output_tokens: z7.number(),
|
|
1932
|
+
cache_creation_input_tokens: z7.number().nullish(),
|
|
1933
|
+
cache_read_input_tokens: z7.number().nullish()
|
|
1711
1934
|
})
|
|
1712
1935
|
});
|
|
1713
|
-
var anthropicMessagesChunkSchema =
|
|
1714
|
-
|
|
1715
|
-
type:
|
|
1716
|
-
message:
|
|
1717
|
-
id:
|
|
1718
|
-
model:
|
|
1719
|
-
usage:
|
|
1720
|
-
input_tokens:
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
cache_read_input_tokens: z5.number().nullish()
|
|
1936
|
+
var anthropicMessagesChunkSchema = z7.discriminatedUnion("type", [
|
|
1937
|
+
z7.object({
|
|
1938
|
+
type: z7.literal("message_start"),
|
|
1939
|
+
message: z7.object({
|
|
1940
|
+
id: z7.string().nullish(),
|
|
1941
|
+
model: z7.string().nullish(),
|
|
1942
|
+
usage: z7.looseObject({
|
|
1943
|
+
input_tokens: z7.number(),
|
|
1944
|
+
cache_creation_input_tokens: z7.number().nullish(),
|
|
1945
|
+
cache_read_input_tokens: z7.number().nullish()
|
|
1724
1946
|
})
|
|
1725
1947
|
})
|
|
1726
1948
|
}),
|
|
1727
|
-
|
|
1728
|
-
type:
|
|
1729
|
-
index:
|
|
1730
|
-
content_block:
|
|
1731
|
-
|
|
1732
|
-
type:
|
|
1733
|
-
text:
|
|
1949
|
+
z7.object({
|
|
1950
|
+
type: z7.literal("content_block_start"),
|
|
1951
|
+
index: z7.number(),
|
|
1952
|
+
content_block: z7.discriminatedUnion("type", [
|
|
1953
|
+
z7.object({
|
|
1954
|
+
type: z7.literal("text"),
|
|
1955
|
+
text: z7.string()
|
|
1734
1956
|
}),
|
|
1735
|
-
|
|
1736
|
-
type:
|
|
1737
|
-
thinking:
|
|
1957
|
+
z7.object({
|
|
1958
|
+
type: z7.literal("thinking"),
|
|
1959
|
+
thinking: z7.string()
|
|
1738
1960
|
}),
|
|
1739
|
-
|
|
1740
|
-
type:
|
|
1741
|
-
id:
|
|
1742
|
-
name:
|
|
1961
|
+
z7.object({
|
|
1962
|
+
type: z7.literal("tool_use"),
|
|
1963
|
+
id: z7.string(),
|
|
1964
|
+
name: z7.string()
|
|
1743
1965
|
}),
|
|
1744
|
-
|
|
1745
|
-
type:
|
|
1746
|
-
data:
|
|
1966
|
+
z7.object({
|
|
1967
|
+
type: z7.literal("redacted_thinking"),
|
|
1968
|
+
data: z7.string()
|
|
1747
1969
|
}),
|
|
1748
|
-
|
|
1749
|
-
type:
|
|
1750
|
-
id:
|
|
1751
|
-
name:
|
|
1752
|
-
input:
|
|
1970
|
+
z7.object({
|
|
1971
|
+
type: z7.literal("server_tool_use"),
|
|
1972
|
+
id: z7.string(),
|
|
1973
|
+
name: z7.string(),
|
|
1974
|
+
input: z7.record(z7.string(), z7.unknown()).nullish()
|
|
1753
1975
|
}),
|
|
1754
|
-
|
|
1755
|
-
type:
|
|
1756
|
-
tool_use_id:
|
|
1757
|
-
content:
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1976
|
+
z7.object({
|
|
1977
|
+
type: z7.literal("web_fetch_tool_result"),
|
|
1978
|
+
tool_use_id: z7.string(),
|
|
1979
|
+
content: z7.union([
|
|
1980
|
+
z7.object({
|
|
1981
|
+
type: z7.literal("web_fetch_result"),
|
|
1982
|
+
url: z7.string(),
|
|
1983
|
+
retrieved_at: z7.string(),
|
|
1984
|
+
content: z7.object({
|
|
1985
|
+
type: z7.literal("document"),
|
|
1986
|
+
title: z7.string().nullable(),
|
|
1987
|
+
citations: z7.object({ enabled: z7.boolean() }).optional(),
|
|
1988
|
+
source: z7.object({
|
|
1989
|
+
type: z7.literal("text"),
|
|
1990
|
+
media_type: z7.string(),
|
|
1991
|
+
data: z7.string()
|
|
1992
|
+
})
|
|
1993
|
+
})
|
|
1994
|
+
}),
|
|
1995
|
+
z7.object({
|
|
1996
|
+
type: z7.literal("web_fetch_tool_result_error"),
|
|
1997
|
+
error_code: z7.string()
|
|
1998
|
+
})
|
|
1999
|
+
])
|
|
2000
|
+
}),
|
|
2001
|
+
z7.object({
|
|
2002
|
+
type: z7.literal("web_search_tool_result"),
|
|
2003
|
+
tool_use_id: z7.string(),
|
|
2004
|
+
content: z7.union([
|
|
2005
|
+
z7.array(
|
|
2006
|
+
z7.object({
|
|
2007
|
+
type: z7.literal("web_search_result"),
|
|
2008
|
+
url: z7.string(),
|
|
2009
|
+
title: z7.string(),
|
|
2010
|
+
encrypted_content: z7.string(),
|
|
2011
|
+
page_age: z7.string().nullish()
|
|
1765
2012
|
})
|
|
1766
2013
|
),
|
|
1767
|
-
|
|
1768
|
-
type:
|
|
1769
|
-
error_code:
|
|
2014
|
+
z7.object({
|
|
2015
|
+
type: z7.literal("web_search_tool_result_error"),
|
|
2016
|
+
error_code: z7.string()
|
|
1770
2017
|
})
|
|
1771
2018
|
])
|
|
1772
2019
|
}),
|
|
1773
|
-
|
|
1774
|
-
type:
|
|
1775
|
-
tool_use_id:
|
|
1776
|
-
content:
|
|
1777
|
-
|
|
1778
|
-
type:
|
|
1779
|
-
stdout:
|
|
1780
|
-
stderr:
|
|
1781
|
-
return_code:
|
|
2020
|
+
z7.object({
|
|
2021
|
+
type: z7.literal("code_execution_tool_result"),
|
|
2022
|
+
tool_use_id: z7.string(),
|
|
2023
|
+
content: z7.union([
|
|
2024
|
+
z7.object({
|
|
2025
|
+
type: z7.literal("code_execution_result"),
|
|
2026
|
+
stdout: z7.string(),
|
|
2027
|
+
stderr: z7.string(),
|
|
2028
|
+
return_code: z7.number()
|
|
1782
2029
|
}),
|
|
1783
|
-
|
|
1784
|
-
type:
|
|
1785
|
-
error_code:
|
|
2030
|
+
z7.object({
|
|
2031
|
+
type: z7.literal("code_execution_tool_result_error"),
|
|
2032
|
+
error_code: z7.string()
|
|
1786
2033
|
})
|
|
1787
2034
|
])
|
|
1788
2035
|
})
|
|
1789
2036
|
])
|
|
1790
2037
|
}),
|
|
1791
|
-
|
|
1792
|
-
type:
|
|
1793
|
-
index:
|
|
1794
|
-
delta:
|
|
1795
|
-
|
|
1796
|
-
type:
|
|
1797
|
-
partial_json:
|
|
2038
|
+
z7.object({
|
|
2039
|
+
type: z7.literal("content_block_delta"),
|
|
2040
|
+
index: z7.number(),
|
|
2041
|
+
delta: z7.discriminatedUnion("type", [
|
|
2042
|
+
z7.object({
|
|
2043
|
+
type: z7.literal("input_json_delta"),
|
|
2044
|
+
partial_json: z7.string()
|
|
1798
2045
|
}),
|
|
1799
|
-
|
|
1800
|
-
type:
|
|
1801
|
-
text:
|
|
2046
|
+
z7.object({
|
|
2047
|
+
type: z7.literal("text_delta"),
|
|
2048
|
+
text: z7.string()
|
|
1802
2049
|
}),
|
|
1803
|
-
|
|
1804
|
-
type:
|
|
1805
|
-
thinking:
|
|
2050
|
+
z7.object({
|
|
2051
|
+
type: z7.literal("thinking_delta"),
|
|
2052
|
+
thinking: z7.string()
|
|
1806
2053
|
}),
|
|
1807
|
-
|
|
1808
|
-
type:
|
|
1809
|
-
signature:
|
|
2054
|
+
z7.object({
|
|
2055
|
+
type: z7.literal("signature_delta"),
|
|
2056
|
+
signature: z7.string()
|
|
1810
2057
|
}),
|
|
1811
|
-
|
|
1812
|
-
type:
|
|
2058
|
+
z7.object({
|
|
2059
|
+
type: z7.literal("citations_delta"),
|
|
1813
2060
|
citation: citationSchema
|
|
1814
2061
|
})
|
|
1815
2062
|
])
|
|
1816
2063
|
}),
|
|
1817
|
-
|
|
1818
|
-
type:
|
|
1819
|
-
index:
|
|
2064
|
+
z7.object({
|
|
2065
|
+
type: z7.literal("content_block_stop"),
|
|
2066
|
+
index: z7.number()
|
|
1820
2067
|
}),
|
|
1821
|
-
|
|
1822
|
-
type:
|
|
1823
|
-
error:
|
|
1824
|
-
type:
|
|
1825
|
-
message:
|
|
2068
|
+
z7.object({
|
|
2069
|
+
type: z7.literal("error"),
|
|
2070
|
+
error: z7.object({
|
|
2071
|
+
type: z7.string(),
|
|
2072
|
+
message: z7.string()
|
|
1826
2073
|
})
|
|
1827
2074
|
}),
|
|
1828
|
-
|
|
1829
|
-
type:
|
|
1830
|
-
delta:
|
|
1831
|
-
|
|
2075
|
+
z7.object({
|
|
2076
|
+
type: z7.literal("message_delta"),
|
|
2077
|
+
delta: z7.object({
|
|
2078
|
+
stop_reason: z7.string().nullish(),
|
|
2079
|
+
stop_sequence: z7.string().nullish()
|
|
2080
|
+
}),
|
|
2081
|
+
usage: z7.looseObject({
|
|
2082
|
+
output_tokens: z7.number(),
|
|
2083
|
+
cache_creation_input_tokens: z7.number().nullish()
|
|
2084
|
+
})
|
|
1832
2085
|
}),
|
|
1833
|
-
|
|
1834
|
-
type:
|
|
2086
|
+
z7.object({
|
|
2087
|
+
type: z7.literal("message_stop")
|
|
1835
2088
|
}),
|
|
1836
|
-
|
|
1837
|
-
type:
|
|
2089
|
+
z7.object({
|
|
2090
|
+
type: z7.literal("ping")
|
|
1838
2091
|
})
|
|
1839
2092
|
]);
|
|
1840
|
-
var anthropicReasoningMetadataSchema =
|
|
1841
|
-
signature:
|
|
1842
|
-
redactedData:
|
|
2093
|
+
var anthropicReasoningMetadataSchema = z7.object({
|
|
2094
|
+
signature: z7.string().optional(),
|
|
2095
|
+
redactedData: z7.string().optional()
|
|
1843
2096
|
});
|
|
1844
2097
|
|
|
1845
2098
|
// src/tool/bash_20241022.ts
|
|
1846
|
-
import { createProviderDefinedToolFactory } from "@ai-sdk/provider-utils";
|
|
1847
|
-
import
|
|
1848
|
-
var bash_20241022 =
|
|
2099
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory2 } from "@ai-sdk/provider-utils";
|
|
2100
|
+
import z8 from "zod/v4";
|
|
2101
|
+
var bash_20241022 = createProviderDefinedToolFactory2({
|
|
1849
2102
|
id: "anthropic.bash_20241022",
|
|
1850
2103
|
name: "bash",
|
|
1851
|
-
inputSchema:
|
|
1852
|
-
command:
|
|
1853
|
-
restart:
|
|
2104
|
+
inputSchema: z8.object({
|
|
2105
|
+
command: z8.string(),
|
|
2106
|
+
restart: z8.boolean().optional()
|
|
1854
2107
|
})
|
|
1855
2108
|
});
|
|
1856
2109
|
|
|
1857
2110
|
// src/tool/bash_20250124.ts
|
|
1858
|
-
import { createProviderDefinedToolFactory as
|
|
1859
|
-
import
|
|
1860
|
-
var bash_20250124 =
|
|
2111
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory3 } from "@ai-sdk/provider-utils";
|
|
2112
|
+
import z9 from "zod/v4";
|
|
2113
|
+
var bash_20250124 = createProviderDefinedToolFactory3({
|
|
1861
2114
|
id: "anthropic.bash_20250124",
|
|
1862
2115
|
name: "bash",
|
|
1863
|
-
inputSchema:
|
|
1864
|
-
command:
|
|
1865
|
-
restart:
|
|
2116
|
+
inputSchema: z9.object({
|
|
2117
|
+
command: z9.string(),
|
|
2118
|
+
restart: z9.boolean().optional()
|
|
1866
2119
|
})
|
|
1867
2120
|
});
|
|
1868
2121
|
|
|
1869
2122
|
// src/tool/computer_20241022.ts
|
|
1870
|
-
import { createProviderDefinedToolFactory as
|
|
1871
|
-
import { z as
|
|
1872
|
-
var computer_20241022 =
|
|
2123
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory4 } from "@ai-sdk/provider-utils";
|
|
2124
|
+
import { z as z10 } from "zod/v4";
|
|
2125
|
+
var computer_20241022 = createProviderDefinedToolFactory4({
|
|
1873
2126
|
id: "anthropic.computer_20241022",
|
|
1874
2127
|
name: "computer",
|
|
1875
|
-
inputSchema:
|
|
1876
|
-
action:
|
|
2128
|
+
inputSchema: z10.object({
|
|
2129
|
+
action: z10.enum([
|
|
1877
2130
|
"key",
|
|
1878
2131
|
"type",
|
|
1879
2132
|
"mouse_move",
|
|
@@ -1885,19 +2138,19 @@ var computer_20241022 = createProviderDefinedToolFactory3({
|
|
|
1885
2138
|
"screenshot",
|
|
1886
2139
|
"cursor_position"
|
|
1887
2140
|
]),
|
|
1888
|
-
coordinate:
|
|
1889
|
-
text:
|
|
2141
|
+
coordinate: z10.array(z10.number().int()).optional(),
|
|
2142
|
+
text: z10.string().optional()
|
|
1890
2143
|
})
|
|
1891
2144
|
});
|
|
1892
2145
|
|
|
1893
2146
|
// src/tool/computer_20250124.ts
|
|
1894
|
-
import { createProviderDefinedToolFactory as
|
|
1895
|
-
import { z as
|
|
1896
|
-
var computer_20250124 =
|
|
2147
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory5 } from "@ai-sdk/provider-utils";
|
|
2148
|
+
import { z as z11 } from "zod/v4";
|
|
2149
|
+
var computer_20250124 = createProviderDefinedToolFactory5({
|
|
1897
2150
|
id: "anthropic.computer_20250124",
|
|
1898
2151
|
name: "computer",
|
|
1899
|
-
inputSchema:
|
|
1900
|
-
action:
|
|
2152
|
+
inputSchema: z11.object({
|
|
2153
|
+
action: z11.enum([
|
|
1901
2154
|
"key",
|
|
1902
2155
|
"hold_key",
|
|
1903
2156
|
"type",
|
|
@@ -1915,63 +2168,63 @@ var computer_20250124 = createProviderDefinedToolFactory4({
|
|
|
1915
2168
|
"wait",
|
|
1916
2169
|
"screenshot"
|
|
1917
2170
|
]),
|
|
1918
|
-
coordinate:
|
|
1919
|
-
duration:
|
|
1920
|
-
scroll_amount:
|
|
1921
|
-
scroll_direction:
|
|
1922
|
-
start_coordinate:
|
|
1923
|
-
text:
|
|
2171
|
+
coordinate: z11.tuple([z11.number().int(), z11.number().int()]).optional(),
|
|
2172
|
+
duration: z11.number().optional(),
|
|
2173
|
+
scroll_amount: z11.number().optional(),
|
|
2174
|
+
scroll_direction: z11.enum(["up", "down", "left", "right"]).optional(),
|
|
2175
|
+
start_coordinate: z11.tuple([z11.number().int(), z11.number().int()]).optional(),
|
|
2176
|
+
text: z11.string().optional()
|
|
1924
2177
|
})
|
|
1925
2178
|
});
|
|
1926
2179
|
|
|
1927
2180
|
// src/tool/text-editor_20241022.ts
|
|
1928
|
-
import { createProviderDefinedToolFactory as
|
|
1929
|
-
import { z as
|
|
1930
|
-
var textEditor_20241022 =
|
|
2181
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory6 } from "@ai-sdk/provider-utils";
|
|
2182
|
+
import { z as z12 } from "zod/v4";
|
|
2183
|
+
var textEditor_20241022 = createProviderDefinedToolFactory6({
|
|
1931
2184
|
id: "anthropic.text_editor_20241022",
|
|
1932
2185
|
name: "str_replace_editor",
|
|
1933
|
-
inputSchema:
|
|
1934
|
-
command:
|
|
1935
|
-
path:
|
|
1936
|
-
file_text:
|
|
1937
|
-
insert_line:
|
|
1938
|
-
new_str:
|
|
1939
|
-
old_str:
|
|
1940
|
-
view_range:
|
|
2186
|
+
inputSchema: z12.object({
|
|
2187
|
+
command: z12.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
2188
|
+
path: z12.string(),
|
|
2189
|
+
file_text: z12.string().optional(),
|
|
2190
|
+
insert_line: z12.number().int().optional(),
|
|
2191
|
+
new_str: z12.string().optional(),
|
|
2192
|
+
old_str: z12.string().optional(),
|
|
2193
|
+
view_range: z12.array(z12.number().int()).optional()
|
|
1941
2194
|
})
|
|
1942
2195
|
});
|
|
1943
2196
|
|
|
1944
2197
|
// src/tool/text-editor_20250124.ts
|
|
1945
|
-
import { createProviderDefinedToolFactory as
|
|
1946
|
-
import { z as
|
|
1947
|
-
var textEditor_20250124 =
|
|
2198
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory7 } from "@ai-sdk/provider-utils";
|
|
2199
|
+
import { z as z13 } from "zod/v4";
|
|
2200
|
+
var textEditor_20250124 = createProviderDefinedToolFactory7({
|
|
1948
2201
|
id: "anthropic.text_editor_20250124",
|
|
1949
2202
|
name: "str_replace_editor",
|
|
1950
|
-
inputSchema:
|
|
1951
|
-
command:
|
|
1952
|
-
path:
|
|
1953
|
-
file_text:
|
|
1954
|
-
insert_line:
|
|
1955
|
-
new_str:
|
|
1956
|
-
old_str:
|
|
1957
|
-
view_range:
|
|
2203
|
+
inputSchema: z13.object({
|
|
2204
|
+
command: z13.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
2205
|
+
path: z13.string(),
|
|
2206
|
+
file_text: z13.string().optional(),
|
|
2207
|
+
insert_line: z13.number().int().optional(),
|
|
2208
|
+
new_str: z13.string().optional(),
|
|
2209
|
+
old_str: z13.string().optional(),
|
|
2210
|
+
view_range: z13.array(z13.number().int()).optional()
|
|
1958
2211
|
})
|
|
1959
2212
|
});
|
|
1960
2213
|
|
|
1961
2214
|
// src/tool/text-editor_20250429.ts
|
|
1962
|
-
import { createProviderDefinedToolFactory as
|
|
1963
|
-
import { z as
|
|
1964
|
-
var textEditor_20250429 =
|
|
2215
|
+
import { createProviderDefinedToolFactory as createProviderDefinedToolFactory8 } from "@ai-sdk/provider-utils";
|
|
2216
|
+
import { z as z14 } from "zod/v4";
|
|
2217
|
+
var textEditor_20250429 = createProviderDefinedToolFactory8({
|
|
1965
2218
|
id: "anthropic.text_editor_20250429",
|
|
1966
2219
|
name: "str_replace_based_edit_tool",
|
|
1967
|
-
inputSchema:
|
|
1968
|
-
command:
|
|
1969
|
-
path:
|
|
1970
|
-
file_text:
|
|
1971
|
-
insert_line:
|
|
1972
|
-
new_str:
|
|
1973
|
-
old_str:
|
|
1974
|
-
view_range:
|
|
2220
|
+
inputSchema: z14.object({
|
|
2221
|
+
command: z14.enum(["view", "create", "str_replace", "insert"]),
|
|
2222
|
+
path: z14.string(),
|
|
2223
|
+
file_text: z14.string().optional(),
|
|
2224
|
+
insert_line: z14.number().int().optional(),
|
|
2225
|
+
new_str: z14.string().optional(),
|
|
2226
|
+
old_str: z14.string().optional(),
|
|
2227
|
+
view_range: z14.array(z14.number().int()).optional()
|
|
1975
2228
|
})
|
|
1976
2229
|
});
|
|
1977
2230
|
|
|
@@ -2037,6 +2290,8 @@ var anthropicTools = {
|
|
|
2037
2290
|
* helping you debug, fix, and improve your code or other text documents. This allows Claude
|
|
2038
2291
|
* to directly interact with your files, providing hands-on assistance rather than just suggesting changes.
|
|
2039
2292
|
*
|
|
2293
|
+
* Supported models: Claude Sonnet 3.5
|
|
2294
|
+
*
|
|
2040
2295
|
* Tool name must be `str_replace_editor`.
|
|
2041
2296
|
*/
|
|
2042
2297
|
textEditor_20241022,
|
|
@@ -2045,6 +2300,8 @@ var anthropicTools = {
|
|
|
2045
2300
|
* helping you debug, fix, and improve your code or other text documents. This allows Claude
|
|
2046
2301
|
* to directly interact with your files, providing hands-on assistance rather than just suggesting changes.
|
|
2047
2302
|
*
|
|
2303
|
+
* Supported models: Claude Sonnet 3.7
|
|
2304
|
+
*
|
|
2048
2305
|
* Tool name must be `str_replace_editor`.
|
|
2049
2306
|
*/
|
|
2050
2307
|
textEditor_20250124,
|
|
@@ -2056,8 +2313,36 @@ var anthropicTools = {
|
|
|
2056
2313
|
* Note: This version does not support the "undo_edit" command.
|
|
2057
2314
|
*
|
|
2058
2315
|
* Tool name must be `str_replace_based_edit_tool`.
|
|
2316
|
+
*
|
|
2317
|
+
* @deprecated Use textEditor_20250728 instead
|
|
2059
2318
|
*/
|
|
2060
2319
|
textEditor_20250429,
|
|
2320
|
+
/**
|
|
2321
|
+
* Claude can use an Anthropic-defined text editor tool to view and modify text files,
|
|
2322
|
+
* helping you debug, fix, and improve your code or other text documents. This allows Claude
|
|
2323
|
+
* to directly interact with your files, providing hands-on assistance rather than just suggesting changes.
|
|
2324
|
+
*
|
|
2325
|
+
* Note: This version does not support the "undo_edit" command and adds optional max_characters parameter.
|
|
2326
|
+
*
|
|
2327
|
+
* Supported models: Claude Sonnet 4, Opus 4, and Opus 4.1
|
|
2328
|
+
*
|
|
2329
|
+
* Tool name must be `str_replace_based_edit_tool`.
|
|
2330
|
+
*
|
|
2331
|
+
* @param maxCharacters - Optional maximum number of characters to view in the file
|
|
2332
|
+
*/
|
|
2333
|
+
textEditor_20250728,
|
|
2334
|
+
/**
|
|
2335
|
+
* Creates a web fetch tool that gives Claude direct access to real-time web content.
|
|
2336
|
+
*
|
|
2337
|
+
* Tool name must be `web_fetch`.
|
|
2338
|
+
*
|
|
2339
|
+
* @param maxUses - The max_uses parameter limits the number of web fetches performed
|
|
2340
|
+
* @param allowedDomains - Only fetch from these domains
|
|
2341
|
+
* @param blockedDomains - Never fetch from these domains
|
|
2342
|
+
* @param citations - Unlike web search where citations are always enabled, citations are optional for web fetch. Set "citations": {"enabled": true} to enable Claude to cite specific passages from fetched documents.
|
|
2343
|
+
* @param maxContentTokens - The max_content_tokens parameter limits the amount of content that will be included in the context.
|
|
2344
|
+
*/
|
|
2345
|
+
webFetch_20250910,
|
|
2061
2346
|
/**
|
|
2062
2347
|
* Creates a web search tool that gives Claude direct access to real-time web content.
|
|
2063
2348
|
*
|