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