@ai-sdk/anthropic 2.0.0-canary.9 → 2.0.0

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