@ai-sdk/anthropic 2.0.0-alpha.8 → 2.0.0-beta.1

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.
@@ -6,11 +6,12 @@ import {
6
6
  combineHeaders,
7
7
  createEventSourceResponseHandler,
8
8
  createJsonResponseHandler,
9
+ generateId,
9
10
  parseProviderOptions as parseProviderOptions2,
10
11
  postJsonToApi,
11
12
  resolve
12
13
  } from "@ai-sdk/provider-utils";
13
- import { z as z3 } from "zod";
14
+ import { z as z4 } from "zod";
14
15
 
15
16
  // src/anthropic-error.ts
16
17
  import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
@@ -29,12 +30,30 @@ var anthropicFailedResponseHandler = createJsonErrorResponseHandler({
29
30
 
30
31
  // src/anthropic-messages-options.ts
31
32
  import { z as z2 } from "zod";
32
- var anthropicProviderOptions = z2.object({
33
+ var anthropicFilePartProviderOptions = z2.object({
34
+ /**
35
+ * Citation configuration for this document.
36
+ * When enabled, this document will generate citations in the response.
37
+ */
38
+ citations: z2.object({
39
+ /**
40
+ * Enable citations for this document
41
+ */
42
+ enabled: z2.boolean()
43
+ }).optional(),
44
+ /**
45
+ * Custom title for the document.
46
+ * If not provided, the filename will be used.
47
+ */
48
+ title: z2.string().optional(),
33
49
  /**
34
- Include reasoning content in requests sent to the model. Defaults to `true`.
35
-
36
- If you are experiencing issues with the model handling requests involving
37
- */
50
+ * Context about the document that will be passed to the model
51
+ * but not used towards cited content.
52
+ * Useful for storing document metadata as text or stringified JSON.
53
+ */
54
+ context: z2.string().optional()
55
+ });
56
+ var anthropicProviderOptions = z2.object({
38
57
  sendReasoning: z2.boolean().optional(),
39
58
  thinking: z2.object({
40
59
  type: z2.union([z2.literal("enabled"), z2.literal("disabled")]),
@@ -46,6 +65,59 @@ var anthropicProviderOptions = z2.object({
46
65
  import {
47
66
  UnsupportedFunctionalityError
48
67
  } from "@ai-sdk/provider";
68
+
69
+ // src/tool/web-search_20250305.ts
70
+ import { createProviderDefinedToolFactoryWithOutputSchema } from "@ai-sdk/provider-utils";
71
+ import { z as z3 } from "zod/v4";
72
+ var webSearch_20250305ArgsSchema = z3.object({
73
+ /**
74
+ * Maximum number of web searches Claude can perform during the conversation.
75
+ */
76
+ maxUses: z3.number().optional(),
77
+ /**
78
+ * Optional list of domains that Claude is allowed to search.
79
+ */
80
+ allowedDomains: z3.array(z3.string()).optional(),
81
+ /**
82
+ * Optional list of domains that Claude should avoid when searching.
83
+ */
84
+ blockedDomains: z3.array(z3.string()).optional(),
85
+ /**
86
+ * Optional user location information to provide geographically relevant search results.
87
+ */
88
+ userLocation: z3.object({
89
+ type: z3.literal("approximate"),
90
+ city: z3.string().optional(),
91
+ region: z3.string().optional(),
92
+ country: z3.string().optional(),
93
+ timezone: z3.string().optional()
94
+ }).optional()
95
+ });
96
+ var webSearch_20250305OutputSchema = z3.array(
97
+ z3.object({
98
+ url: z3.string(),
99
+ title: z3.string(),
100
+ pageAge: z3.string().nullable(),
101
+ encryptedContent: z3.string(),
102
+ type: z3.string()
103
+ })
104
+ );
105
+ var factory = createProviderDefinedToolFactoryWithOutputSchema({
106
+ id: "anthropic.web_search_20250305",
107
+ name: "web_search",
108
+ inputSchema: z3.object({
109
+ query: z3.string()
110
+ }),
111
+ outputSchema: webSearch_20250305OutputSchema
112
+ });
113
+ var webSearch_20250305 = (args = {}) => {
114
+ return factory(args);
115
+ };
116
+
117
+ // src/anthropic-prepare-tools.ts
118
+ function isWebSearchTool(tool) {
119
+ return typeof tool === "object" && tool !== null && "type" in tool && tool.type === "web_search_20250305";
120
+ }
49
121
  function prepareTools({
50
122
  tools,
51
123
  toolChoice
@@ -58,12 +130,16 @@ function prepareTools({
58
130
  }
59
131
  const anthropicTools2 = [];
60
132
  for (const tool of tools) {
133
+ if (isWebSearchTool(tool)) {
134
+ anthropicTools2.push(tool);
135
+ continue;
136
+ }
61
137
  switch (tool.type) {
62
138
  case "function":
63
139
  anthropicTools2.push({
64
140
  name: tool.name,
65
141
  description: tool.description,
66
- input_schema: tool.parameters
142
+ input_schema: tool.inputSchema
67
143
  });
68
144
  break;
69
145
  case "provider-defined":
@@ -71,7 +147,7 @@ function prepareTools({
71
147
  case "anthropic.computer_20250124":
72
148
  betas.add("computer-use-2025-01-24");
73
149
  anthropicTools2.push({
74
- name: tool.name,
150
+ name: "computer",
75
151
  type: "computer_20250124",
76
152
  display_width_px: tool.args.displayWidthPx,
77
153
  display_height_px: tool.args.displayHeightPx,
@@ -81,7 +157,7 @@ function prepareTools({
81
157
  case "anthropic.computer_20241022":
82
158
  betas.add("computer-use-2024-10-22");
83
159
  anthropicTools2.push({
84
- name: tool.name,
160
+ name: "computer",
85
161
  type: "computer_20241022",
86
162
  display_width_px: tool.args.displayWidthPx,
87
163
  display_height_px: tool.args.displayHeightPx,
@@ -91,31 +167,43 @@ function prepareTools({
91
167
  case "anthropic.text_editor_20250124":
92
168
  betas.add("computer-use-2025-01-24");
93
169
  anthropicTools2.push({
94
- name: tool.name,
170
+ name: "str_replace_editor",
95
171
  type: "text_editor_20250124"
96
172
  });
97
173
  break;
98
174
  case "anthropic.text_editor_20241022":
99
175
  betas.add("computer-use-2024-10-22");
100
176
  anthropicTools2.push({
101
- name: tool.name,
177
+ name: "str_replace_editor",
102
178
  type: "text_editor_20241022"
103
179
  });
104
180
  break;
105
181
  case "anthropic.bash_20250124":
106
182
  betas.add("computer-use-2025-01-24");
107
183
  anthropicTools2.push({
108
- name: tool.name,
184
+ name: "bash",
109
185
  type: "bash_20250124"
110
186
  });
111
187
  break;
112
188
  case "anthropic.bash_20241022":
113
189
  betas.add("computer-use-2024-10-22");
114
190
  anthropicTools2.push({
115
- name: tool.name,
191
+ name: "bash",
116
192
  type: "bash_20241022"
117
193
  });
118
194
  break;
195
+ case "anthropic.web_search_20250305": {
196
+ const args = webSearch_20250305ArgsSchema.parse(tool.args);
197
+ anthropicTools2.push({
198
+ type: "web_search_20250305",
199
+ name: "web_search",
200
+ max_uses: args.maxUses,
201
+ allowed_domains: args.allowedDomains,
202
+ blocked_domains: args.blockedDomains,
203
+ user_location: args.userLocation
204
+ });
205
+ break;
206
+ }
119
207
  default:
120
208
  toolWarnings.push({ type: "unsupported-tool", tool });
121
209
  break;
@@ -173,12 +261,28 @@ import {
173
261
  UnsupportedFunctionalityError as UnsupportedFunctionalityError2
174
262
  } from "@ai-sdk/provider";
175
263
  import { convertToBase64, parseProviderOptions } from "@ai-sdk/provider-utils";
264
+ function convertToString(data) {
265
+ if (typeof data === "string") {
266
+ return Buffer.from(data, "base64").toString("utf-8");
267
+ }
268
+ if (data instanceof Uint8Array) {
269
+ return new TextDecoder().decode(data);
270
+ }
271
+ if (data instanceof URL) {
272
+ throw new UnsupportedFunctionalityError2({
273
+ functionality: "URL-based text documents are not supported for citations"
274
+ });
275
+ }
276
+ throw new UnsupportedFunctionalityError2({
277
+ functionality: `unsupported data type for text documents: ${typeof data}`
278
+ });
279
+ }
176
280
  async function convertToAnthropicMessagesPrompt({
177
281
  prompt,
178
282
  sendReasoning,
179
283
  warnings
180
284
  }) {
181
- var _a, _b, _c;
285
+ var _a, _b, _c, _d, _e;
182
286
  const betas = /* @__PURE__ */ new Set();
183
287
  const blocks = groupIntoBlocks(prompt);
184
288
  let system = void 0;
@@ -189,6 +293,26 @@ async function convertToAnthropicMessagesPrompt({
189
293
  const cacheControlValue = (_a2 = anthropic == null ? void 0 : anthropic.cacheControl) != null ? _a2 : anthropic == null ? void 0 : anthropic.cache_control;
190
294
  return cacheControlValue;
191
295
  }
296
+ async function shouldEnableCitations(providerMetadata) {
297
+ var _a2, _b2;
298
+ const anthropicOptions = await parseProviderOptions({
299
+ provider: "anthropic",
300
+ providerOptions: providerMetadata,
301
+ schema: anthropicFilePartProviderOptions
302
+ });
303
+ return (_b2 = (_a2 = anthropicOptions == null ? void 0 : anthropicOptions.citations) == null ? void 0 : _a2.enabled) != null ? _b2 : false;
304
+ }
305
+ async function getDocumentMetadata(providerMetadata) {
306
+ const anthropicOptions = await parseProviderOptions({
307
+ provider: "anthropic",
308
+ providerOptions: providerMetadata,
309
+ schema: anthropicFilePartProviderOptions
310
+ });
311
+ return {
312
+ title: anthropicOptions == null ? void 0 : anthropicOptions.title,
313
+ context: anthropicOptions == null ? void 0 : anthropicOptions.context
314
+ };
315
+ }
192
316
  for (let i = 0; i < blocks.length; i++) {
193
317
  const block = blocks[i];
194
318
  const isLastBlock = i === blocks.length - 1;
@@ -242,6 +366,12 @@ async function convertToAnthropicMessagesPrompt({
242
366
  });
243
367
  } else if (part.mediaType === "application/pdf") {
244
368
  betas.add("pdfs-2024-09-25");
369
+ const enableCitations = await shouldEnableCitations(
370
+ part.providerOptions
371
+ );
372
+ const metadata = await getDocumentMetadata(
373
+ part.providerOptions
374
+ );
245
375
  anthropicContent.push({
246
376
  type: "document",
247
377
  source: part.data instanceof URL ? {
@@ -252,6 +382,35 @@ async function convertToAnthropicMessagesPrompt({
252
382
  media_type: "application/pdf",
253
383
  data: convertToBase64(part.data)
254
384
  },
385
+ title: (_b = metadata.title) != null ? _b : part.filename,
386
+ ...metadata.context && { context: metadata.context },
387
+ ...enableCitations && {
388
+ citations: { enabled: true }
389
+ },
390
+ cache_control: cacheControl
391
+ });
392
+ } else if (part.mediaType === "text/plain") {
393
+ const enableCitations = await shouldEnableCitations(
394
+ part.providerOptions
395
+ );
396
+ const metadata = await getDocumentMetadata(
397
+ part.providerOptions
398
+ );
399
+ anthropicContent.push({
400
+ type: "document",
401
+ source: part.data instanceof URL ? {
402
+ type: "url",
403
+ url: part.data.toString()
404
+ } : {
405
+ type: "text",
406
+ media_type: "text/plain",
407
+ data: convertToString(part.data)
408
+ },
409
+ title: (_c = metadata.title) != null ? _c : part.filename,
410
+ ...metadata.context && { context: metadata.context },
411
+ ...enableCitations && {
412
+ citations: { enabled: true }
413
+ },
255
414
  cache_control: cacheControl
256
415
  });
257
416
  } else {
@@ -269,33 +428,53 @@ async function convertToAnthropicMessagesPrompt({
269
428
  for (let i2 = 0; i2 < content.length; i2++) {
270
429
  const part = content[i2];
271
430
  const isLastPart = i2 === content.length - 1;
272
- const cacheControl = (_b = getCacheControl(part.providerOptions)) != null ? _b : isLastPart ? getCacheControl(message.providerOptions) : void 0;
273
- const toolResultContent = part.content != null ? part.content.map((part2) => {
274
- var _a2;
275
- switch (part2.type) {
276
- case "text":
277
- return {
278
- type: "text",
279
- text: part2.text,
280
- cache_control: void 0
281
- };
282
- case "image":
283
- return {
284
- type: "image",
285
- source: {
286
- type: "base64",
287
- media_type: (_a2 = part2.mediaType) != null ? _a2 : "image/jpeg",
288
- data: part2.data
289
- },
290
- cache_control: void 0
291
- };
292
- }
293
- }) : JSON.stringify(part.result);
431
+ const cacheControl = (_d = getCacheControl(part.providerOptions)) != null ? _d : isLastPart ? getCacheControl(message.providerOptions) : void 0;
432
+ const output = part.output;
433
+ let contentValue;
434
+ switch (output.type) {
435
+ case "content":
436
+ contentValue = output.value.map((contentPart) => {
437
+ switch (contentPart.type) {
438
+ case "text":
439
+ return {
440
+ type: "text",
441
+ text: contentPart.text,
442
+ cache_control: void 0
443
+ };
444
+ case "media": {
445
+ if (contentPart.mediaType.startsWith("image/")) {
446
+ return {
447
+ type: "image",
448
+ source: {
449
+ type: "base64",
450
+ media_type: contentPart.mediaType,
451
+ data: contentPart.data
452
+ },
453
+ cache_control: void 0
454
+ };
455
+ }
456
+ throw new UnsupportedFunctionalityError2({
457
+ functionality: `media type: ${contentPart.mediaType}`
458
+ });
459
+ }
460
+ }
461
+ });
462
+ break;
463
+ case "text":
464
+ case "error-text":
465
+ contentValue = output.value;
466
+ break;
467
+ case "json":
468
+ case "error-json":
469
+ default:
470
+ contentValue = JSON.stringify(output.value);
471
+ break;
472
+ }
294
473
  anthropicContent.push({
295
474
  type: "tool_result",
296
475
  tool_use_id: part.toolCallId,
297
- content: toolResultContent,
298
- is_error: part.isError,
476
+ content: contentValue,
477
+ is_error: output.type === "error-text" || output.type === "error-json" ? true : void 0,
299
478
  cache_control: cacheControl
300
479
  });
301
480
  }
@@ -319,7 +498,7 @@ async function convertToAnthropicMessagesPrompt({
319
498
  for (let k = 0; k < content.length; k++) {
320
499
  const part = content[k];
321
500
  const isLastContentPart = k === content.length - 1;
322
- const cacheControl = (_c = getCacheControl(part.providerOptions)) != null ? _c : isLastContentPart ? getCacheControl(message.providerOptions) : void 0;
501
+ const cacheControl = (_e = getCacheControl(part.providerOptions)) != null ? _e : isLastContentPart ? getCacheControl(message.providerOptions) : void 0;
323
502
  switch (part.type) {
324
503
  case "text": {
325
504
  anthropicContent.push({
@@ -376,15 +555,65 @@ async function convertToAnthropicMessagesPrompt({
376
555
  break;
377
556
  }
378
557
  case "tool-call": {
558
+ if (part.providerExecuted) {
559
+ if (part.toolName === "web_search") {
560
+ anthropicContent.push({
561
+ type: "server_tool_use",
562
+ id: part.toolCallId,
563
+ name: "web_search",
564
+ input: part.input,
565
+ cache_control: cacheControl
566
+ });
567
+ break;
568
+ }
569
+ warnings.push({
570
+ type: "other",
571
+ message: `provider executed tool call for tool ${part.toolName} is not supported`
572
+ });
573
+ break;
574
+ }
379
575
  anthropicContent.push({
380
576
  type: "tool_use",
381
577
  id: part.toolCallId,
382
578
  name: part.toolName,
383
- input: part.args,
579
+ input: part.input,
384
580
  cache_control: cacheControl
385
581
  });
386
582
  break;
387
583
  }
584
+ case "tool-result": {
585
+ if (part.toolName === "web_search") {
586
+ const output = part.output;
587
+ if (output.type !== "json") {
588
+ warnings.push({
589
+ type: "other",
590
+ message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
591
+ });
592
+ break;
593
+ }
594
+ const webSearchOutput = webSearch_20250305OutputSchema.parse(
595
+ output.value
596
+ );
597
+ anthropicContent.push({
598
+ type: "web_search_tool_result",
599
+ tool_use_id: part.toolCallId,
600
+ content: webSearchOutput.map((result) => ({
601
+ url: result.url,
602
+ title: result.title,
603
+ page_age: result.pageAge,
604
+ encrypted_content: result.encryptedContent,
605
+ type: result.type
606
+ })),
607
+ cache_control: cacheControl
608
+ });
609
+ break;
610
+ }
611
+ warnings.push({
612
+ type: "other",
613
+ message: `provider executed tool result for tool ${part.toolName} is not supported`
614
+ });
615
+ break;
616
+ }
388
617
  }
389
618
  }
390
619
  }
@@ -468,11 +697,86 @@ function mapAnthropicStopReason({
468
697
  }
469
698
 
470
699
  // src/anthropic-messages-language-model.ts
700
+ var citationSchemas = {
701
+ webSearchResult: z4.object({
702
+ type: z4.literal("web_search_result_location"),
703
+ cited_text: z4.string(),
704
+ url: z4.string(),
705
+ title: z4.string(),
706
+ encrypted_index: z4.string()
707
+ }),
708
+ pageLocation: z4.object({
709
+ type: z4.literal("page_location"),
710
+ cited_text: z4.string(),
711
+ document_index: z4.number(),
712
+ document_title: z4.string().nullable(),
713
+ start_page_number: z4.number(),
714
+ end_page_number: z4.number()
715
+ }),
716
+ charLocation: z4.object({
717
+ type: z4.literal("char_location"),
718
+ cited_text: z4.string(),
719
+ document_index: z4.number(),
720
+ document_title: z4.string().nullable(),
721
+ start_char_index: z4.number(),
722
+ end_char_index: z4.number()
723
+ })
724
+ };
725
+ var citationSchema = z4.discriminatedUnion("type", [
726
+ citationSchemas.webSearchResult,
727
+ citationSchemas.pageLocation,
728
+ citationSchemas.charLocation
729
+ ]);
730
+ var documentCitationSchema = z4.discriminatedUnion("type", [
731
+ citationSchemas.pageLocation,
732
+ citationSchemas.charLocation
733
+ ]);
734
+ function processCitation(citation, citationDocuments, generateId2, onSource) {
735
+ if (citation.type === "page_location" || citation.type === "char_location") {
736
+ const source = createCitationSource(
737
+ citation,
738
+ citationDocuments,
739
+ generateId2
740
+ );
741
+ if (source) {
742
+ onSource(source);
743
+ }
744
+ }
745
+ }
746
+ function createCitationSource(citation, citationDocuments, generateId2) {
747
+ var _a;
748
+ const documentInfo = citationDocuments[citation.document_index];
749
+ if (!documentInfo) {
750
+ return null;
751
+ }
752
+ const providerMetadata = citation.type === "page_location" ? {
753
+ citedText: citation.cited_text,
754
+ startPageNumber: citation.start_page_number,
755
+ endPageNumber: citation.end_page_number
756
+ } : {
757
+ citedText: citation.cited_text,
758
+ startCharIndex: citation.start_char_index,
759
+ endCharIndex: citation.end_char_index
760
+ };
761
+ return {
762
+ type: "source",
763
+ sourceType: "document",
764
+ id: generateId2(),
765
+ mediaType: documentInfo.mediaType,
766
+ title: (_a = citation.document_title) != null ? _a : documentInfo.title,
767
+ filename: documentInfo.filename,
768
+ providerMetadata: {
769
+ anthropic: providerMetadata
770
+ }
771
+ };
772
+ }
471
773
  var AnthropicMessagesLanguageModel = class {
472
774
  constructor(modelId, config) {
473
775
  this.specificationVersion = "v2";
776
+ var _a;
474
777
  this.modelId = modelId;
475
778
  this.config = config;
779
+ this.generateId = (_a = config.generateId) != null ? _a : generateId;
476
780
  }
477
781
  supportsUrl(url) {
478
782
  return url.protocol === "https:";
@@ -539,7 +843,7 @@ var AnthropicMessagesLanguageModel = class {
539
843
  type: "function",
540
844
  name: "json",
541
845
  description: "Respond with a JSON object.",
542
- parameters: responseFormat.schema
846
+ inputSchema: responseFormat.schema
543
847
  } : void 0;
544
848
  const anthropicOptions = await parseProviderOptions2({
545
849
  provider: "anthropic",
@@ -611,7 +915,7 @@ var AnthropicMessagesLanguageModel = class {
611
915
  jsonResponseTool != null ? {
612
916
  tools: [jsonResponseTool],
613
917
  toolChoice: { type: "tool", toolName: jsonResponseTool.name }
614
- } : { tools, toolChoice }
918
+ } : { tools: tools != null ? tools : [], toolChoice }
615
919
  );
616
920
  return {
617
921
  args: {
@@ -642,9 +946,33 @@ var AnthropicMessagesLanguageModel = class {
642
946
  var _a, _b, _c;
643
947
  return (_c = (_b = (_a = this.config).transformRequestBody) == null ? void 0 : _b.call(_a, args)) != null ? _c : args;
644
948
  }
949
+ extractCitationDocuments(prompt) {
950
+ const isCitationPart = (part) => {
951
+ var _a, _b;
952
+ if (part.type !== "file") {
953
+ return false;
954
+ }
955
+ if (part.mediaType !== "application/pdf" && part.mediaType !== "text/plain") {
956
+ return false;
957
+ }
958
+ const anthropic = (_a = part.providerOptions) == null ? void 0 : _a.anthropic;
959
+ const citationsConfig = anthropic == null ? void 0 : anthropic.citations;
960
+ return (_b = citationsConfig == null ? void 0 : citationsConfig.enabled) != null ? _b : false;
961
+ };
962
+ return prompt.filter((message) => message.role === "user").flatMap((message) => message.content).filter(isCitationPart).map((part) => {
963
+ var _a;
964
+ const filePart = part;
965
+ return {
966
+ title: (_a = filePart.filename) != null ? _a : "Untitled Document",
967
+ filename: filePart.filename,
968
+ mediaType: filePart.mediaType
969
+ };
970
+ });
971
+ }
645
972
  async doGenerate(options) {
646
- var _a, _b, _c, _d;
973
+ var _a, _b, _c, _d, _e;
647
974
  const { args, warnings, betas, jsonResponseTool } = await this.getArgs(options);
975
+ const citationDocuments = this.extractCitationDocuments(options.prompt);
648
976
  const {
649
977
  responseHeaders,
650
978
  value: response,
@@ -666,6 +994,16 @@ var AnthropicMessagesLanguageModel = class {
666
994
  case "text": {
667
995
  if (jsonResponseTool == null) {
668
996
  content.push({ type: "text", text: part.text });
997
+ if (part.citations) {
998
+ for (const citation of part.citations) {
999
+ processCitation(
1000
+ citation,
1001
+ citationDocuments,
1002
+ this.generateId,
1003
+ (source) => content.push(source)
1004
+ );
1005
+ }
1006
+ }
669
1007
  }
670
1008
  break;
671
1009
  }
@@ -701,14 +1039,72 @@ var AnthropicMessagesLanguageModel = class {
701
1039
  text: JSON.stringify(part.input)
702
1040
  } : {
703
1041
  type: "tool-call",
704
- toolCallType: "function",
705
1042
  toolCallId: part.id,
706
1043
  toolName: part.name,
707
- args: JSON.stringify(part.input)
1044
+ input: JSON.stringify(part.input)
708
1045
  }
709
1046
  );
710
1047
  break;
711
1048
  }
1049
+ case "server_tool_use": {
1050
+ if (part.name === "web_search") {
1051
+ content.push({
1052
+ type: "tool-call",
1053
+ toolCallId: part.id,
1054
+ toolName: part.name,
1055
+ input: JSON.stringify(part.input),
1056
+ providerExecuted: true
1057
+ });
1058
+ }
1059
+ break;
1060
+ }
1061
+ case "web_search_tool_result": {
1062
+ if (Array.isArray(part.content)) {
1063
+ content.push({
1064
+ type: "tool-result",
1065
+ toolCallId: part.tool_use_id,
1066
+ toolName: "web_search",
1067
+ result: part.content.map((result) => {
1068
+ var _a2;
1069
+ return {
1070
+ url: result.url,
1071
+ title: result.title,
1072
+ pageAge: (_a2 = result.page_age) != null ? _a2 : null,
1073
+ encryptedContent: result.encrypted_content,
1074
+ type: result.type
1075
+ };
1076
+ }),
1077
+ providerExecuted: true
1078
+ });
1079
+ for (const result of part.content) {
1080
+ content.push({
1081
+ type: "source",
1082
+ sourceType: "url",
1083
+ id: this.generateId(),
1084
+ url: result.url,
1085
+ title: result.title,
1086
+ providerMetadata: {
1087
+ anthropic: {
1088
+ pageAge: (_a = result.page_age) != null ? _a : null
1089
+ }
1090
+ }
1091
+ });
1092
+ }
1093
+ } else {
1094
+ content.push({
1095
+ type: "tool-result",
1096
+ toolCallId: part.tool_use_id,
1097
+ toolName: "web_search",
1098
+ isError: true,
1099
+ result: {
1100
+ type: "web_search_tool_result_error",
1101
+ errorCode: part.content.error_code
1102
+ },
1103
+ providerExecuted: true
1104
+ });
1105
+ }
1106
+ break;
1107
+ }
712
1108
  }
713
1109
  }
714
1110
  return {
@@ -721,25 +1117,26 @@ var AnthropicMessagesLanguageModel = class {
721
1117
  inputTokens: response.usage.input_tokens,
722
1118
  outputTokens: response.usage.output_tokens,
723
1119
  totalTokens: response.usage.input_tokens + response.usage.output_tokens,
724
- cachedInputTokens: (_a = response.usage.cache_read_input_tokens) != null ? _a : void 0
1120
+ cachedInputTokens: (_b = response.usage.cache_read_input_tokens) != null ? _b : void 0
725
1121
  },
726
1122
  request: { body: args },
727
1123
  response: {
728
- id: (_b = response.id) != null ? _b : void 0,
729
- modelId: (_c = response.model) != null ? _c : void 0,
1124
+ id: (_c = response.id) != null ? _c : void 0,
1125
+ modelId: (_d = response.model) != null ? _d : void 0,
730
1126
  headers: responseHeaders,
731
1127
  body: rawResponse
732
1128
  },
733
1129
  warnings,
734
1130
  providerMetadata: {
735
1131
  anthropic: {
736
- cacheCreationInputTokens: (_d = response.usage.cache_creation_input_tokens) != null ? _d : null
1132
+ cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null
737
1133
  }
738
1134
  }
739
1135
  };
740
1136
  }
741
1137
  async doStream(options) {
742
1138
  const { args, warnings, betas, jsonResponseTool } = await this.getArgs(options);
1139
+ const citationDocuments = this.extractCitationDocuments(options.prompt);
743
1140
  const body = { ...args, stream: true };
744
1141
  const { responseHeaders, value: response } = await postJsonToApi({
745
1142
  url: this.buildRequestUrl(true),
@@ -758,9 +1155,10 @@ var AnthropicMessagesLanguageModel = class {
758
1155
  outputTokens: void 0,
759
1156
  totalTokens: void 0
760
1157
  };
761
- const toolCallContentBlocks = {};
1158
+ const contentBlocks = {};
762
1159
  let providerMetadata = void 0;
763
1160
  let blockType = void 0;
1161
+ const generateId2 = this.generateId;
764
1162
  return {
765
1163
  stream: response.pipeThrough(
766
1164
  new TransformStream({
@@ -768,7 +1166,10 @@ var AnthropicMessagesLanguageModel = class {
768
1166
  controller.enqueue({ type: "stream-start", warnings });
769
1167
  },
770
1168
  transform(chunk, controller) {
771
- var _a, _b, _c, _d, _e, _f;
1169
+ var _a, _b, _c, _d, _e, _f, _g;
1170
+ if (options.includeRawChunks) {
1171
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1172
+ }
772
1173
  if (!chunk.success) {
773
1174
  controller.enqueue({ type: "error", error: chunk.error });
774
1175
  return;
@@ -782,29 +1183,115 @@ var AnthropicMessagesLanguageModel = class {
782
1183
  const contentBlockType = value.content_block.type;
783
1184
  blockType = contentBlockType;
784
1185
  switch (contentBlockType) {
785
- case "text":
1186
+ case "text": {
1187
+ contentBlocks[value.index] = { type: "text" };
1188
+ controller.enqueue({
1189
+ type: "text-start",
1190
+ id: String(value.index)
1191
+ });
1192
+ return;
1193
+ }
786
1194
  case "thinking": {
1195
+ contentBlocks[value.index] = { type: "reasoning" };
1196
+ controller.enqueue({
1197
+ type: "reasoning-start",
1198
+ id: String(value.index)
1199
+ });
787
1200
  return;
788
1201
  }
789
1202
  case "redacted_thinking": {
1203
+ contentBlocks[value.index] = { type: "reasoning" };
790
1204
  controller.enqueue({
791
- type: "reasoning",
792
- text: "",
1205
+ type: "reasoning-start",
1206
+ id: String(value.index),
793
1207
  providerMetadata: {
794
1208
  anthropic: {
795
1209
  redactedData: value.content_block.data
796
1210
  }
797
1211
  }
798
1212
  });
799
- controller.enqueue({ type: "reasoning-part-finish" });
800
1213
  return;
801
1214
  }
802
1215
  case "tool_use": {
803
- toolCallContentBlocks[value.index] = {
1216
+ contentBlocks[value.index] = jsonResponseTool != null ? { type: "text" } : {
1217
+ type: "tool-call",
804
1218
  toolCallId: value.content_block.id,
805
1219
  toolName: value.content_block.name,
806
- jsonText: ""
1220
+ input: ""
807
1221
  };
1222
+ controller.enqueue(
1223
+ jsonResponseTool != null ? { type: "text-start", id: String(value.index) } : {
1224
+ type: "tool-input-start",
1225
+ id: String(value.index),
1226
+ toolName: value.content_block.name
1227
+ }
1228
+ );
1229
+ return;
1230
+ }
1231
+ case "server_tool_use": {
1232
+ if (value.content_block.name === "web_search") {
1233
+ contentBlocks[value.index] = {
1234
+ type: "tool-call",
1235
+ toolCallId: value.content_block.id,
1236
+ toolName: value.content_block.name,
1237
+ input: "",
1238
+ providerExecuted: true
1239
+ };
1240
+ controller.enqueue({
1241
+ type: "tool-input-start",
1242
+ id: value.content_block.id,
1243
+ toolName: value.content_block.name,
1244
+ providerExecuted: true
1245
+ });
1246
+ }
1247
+ return;
1248
+ }
1249
+ case "web_search_tool_result": {
1250
+ const part = value.content_block;
1251
+ if (Array.isArray(part.content)) {
1252
+ controller.enqueue({
1253
+ type: "tool-result",
1254
+ toolCallId: part.tool_use_id,
1255
+ toolName: "web_search",
1256
+ result: part.content.map((result) => {
1257
+ var _a2;
1258
+ return {
1259
+ url: result.url,
1260
+ title: result.title,
1261
+ pageAge: (_a2 = result.page_age) != null ? _a2 : null,
1262
+ encryptedContent: result.encrypted_content,
1263
+ type: result.type
1264
+ };
1265
+ }),
1266
+ providerExecuted: true
1267
+ });
1268
+ for (const result of part.content) {
1269
+ controller.enqueue({
1270
+ type: "source",
1271
+ sourceType: "url",
1272
+ id: generateId2(),
1273
+ url: result.url,
1274
+ title: result.title,
1275
+ providerMetadata: {
1276
+ anthropic: {
1277
+ pageAge: (_a = result.page_age) != null ? _a : null
1278
+ }
1279
+ }
1280
+ });
1281
+ }
1282
+ } else {
1283
+ controller.enqueue({
1284
+ type: "tool-result",
1285
+ toolCallId: part.tool_use_id,
1286
+ toolName: "web_search",
1287
+ isError: true,
1288
+ result: {
1289
+ type: "web_search_tool_result_error",
1290
+ errorCode: part.content.error_code
1291
+ },
1292
+ providerExecuted: true
1293
+ });
1294
+ }
808
1295
  return;
809
1296
  }
810
1297
  default: {
@@ -816,18 +1303,34 @@ var AnthropicMessagesLanguageModel = class {
816
1303
  }
817
1304
  }
818
1305
  case "content_block_stop": {
819
- if (toolCallContentBlocks[value.index] != null) {
820
- const contentBlock = toolCallContentBlocks[value.index];
821
- if (jsonResponseTool == null) {
822
- controller.enqueue({
823
- type: "tool-call",
824
- toolCallType: "function",
825
- toolCallId: contentBlock.toolCallId,
826
- toolName: contentBlock.toolName,
827
- args: contentBlock.jsonText
828
- });
1306
+ if (contentBlocks[value.index] != null) {
1307
+ const contentBlock = contentBlocks[value.index];
1308
+ switch (contentBlock.type) {
1309
+ case "text": {
1310
+ controller.enqueue({
1311
+ type: "text-end",
1312
+ id: String(value.index)
1313
+ });
1314
+ break;
1315
+ }
1316
+ case "reasoning": {
1317
+ controller.enqueue({
1318
+ type: "reasoning-end",
1319
+ id: String(value.index)
1320
+ });
1321
+ break;
1322
+ }
1323
+ case "tool-call":
1324
+ if (jsonResponseTool == null) {
1325
+ controller.enqueue({
1326
+ type: "tool-input-end",
1327
+ id: contentBlock.toolCallId
1328
+ });
1329
+ controller.enqueue(contentBlock);
1330
+ }
1331
+ break;
829
1332
  }
830
- delete toolCallContentBlocks[value.index];
1333
+ delete contentBlocks[value.index];
831
1334
  }
832
1335
  blockType = void 0;
833
1336
  return;
@@ -840,48 +1343,68 @@ var AnthropicMessagesLanguageModel = class {
840
1343
  return;
841
1344
  }
842
1345
  controller.enqueue({
843
- type: "text",
844
- text: value.delta.text
1346
+ type: "text-delta",
1347
+ id: String(value.index),
1348
+ delta: value.delta.text
845
1349
  });
846
1350
  return;
847
1351
  }
848
1352
  case "thinking_delta": {
849
1353
  controller.enqueue({
850
- type: "reasoning",
851
- text: value.delta.thinking
1354
+ type: "reasoning-delta",
1355
+ id: String(value.index),
1356
+ delta: value.delta.thinking
852
1357
  });
853
1358
  return;
854
1359
  }
855
1360
  case "signature_delta": {
856
1361
  if (blockType === "thinking") {
857
1362
  controller.enqueue({
858
- type: "reasoning",
859
- text: "",
1363
+ type: "reasoning-delta",
1364
+ id: String(value.index),
1365
+ delta: "",
860
1366
  providerMetadata: {
861
1367
  anthropic: {
862
1368
  signature: value.delta.signature
863
1369
  }
864
1370
  }
865
1371
  });
866
- controller.enqueue({ type: "reasoning-part-finish" });
867
1372
  }
868
1373
  return;
869
1374
  }
870
1375
  case "input_json_delta": {
871
- const contentBlock = toolCallContentBlocks[value.index];
872
- controller.enqueue(
873
- jsonResponseTool != null ? {
874
- type: "text",
875
- text: value.delta.partial_json
876
- } : {
877
- type: "tool-call-delta",
878
- toolCallType: "function",
879
- toolCallId: contentBlock.toolCallId,
880
- toolName: contentBlock.toolName,
881
- argsTextDelta: value.delta.partial_json
1376
+ const contentBlock = contentBlocks[value.index];
1377
+ const delta = value.delta.partial_json;
1378
+ if (jsonResponseTool == null) {
1379
+ if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
1380
+ return;
882
1381
  }
1382
+ controller.enqueue({
1383
+ type: "tool-input-delta",
1384
+ id: contentBlock.toolCallId,
1385
+ delta
1386
+ });
1387
+ contentBlock.input += delta;
1388
+ } else {
1389
+ if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
1390
+ return;
1391
+ }
1392
+ controller.enqueue({
1393
+ type: "tool-input-delta",
1394
+ id: contentBlock.toolCallId,
1395
+ delta
1396
+ });
1397
+ }
1398
+ return;
1399
+ }
1400
+ case "citations_delta": {
1401
+ const citation = value.delta.citation;
1402
+ processCitation(
1403
+ citation,
1404
+ citationDocuments,
1405
+ generateId2,
1406
+ (source) => controller.enqueue(source)
883
1407
  );
884
- contentBlock.jsonText += value.delta.partial_json;
885
1408
  return;
886
1409
  }
887
1410
  default: {
@@ -894,22 +1417,22 @@ var AnthropicMessagesLanguageModel = class {
894
1417
  }
895
1418
  case "message_start": {
896
1419
  usage.inputTokens = value.message.usage.input_tokens;
897
- usage.cachedInputTokens = (_a = value.message.usage.cache_read_input_tokens) != null ? _a : void 0;
1420
+ usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
898
1421
  providerMetadata = {
899
1422
  anthropic: {
900
- cacheCreationInputTokens: (_b = value.message.usage.cache_creation_input_tokens) != null ? _b : null
1423
+ cacheCreationInputTokens: (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null
901
1424
  }
902
1425
  };
903
1426
  controller.enqueue({
904
1427
  type: "response-metadata",
905
- id: (_c = value.message.id) != null ? _c : void 0,
906
- modelId: (_d = value.message.model) != null ? _d : void 0
1428
+ id: (_d = value.message.id) != null ? _d : void 0,
1429
+ modelId: (_e = value.message.model) != null ? _e : void 0
907
1430
  });
908
1431
  return;
909
1432
  }
910
1433
  case "message_delta": {
911
1434
  usage.outputTokens = value.usage.output_tokens;
912
- usage.totalTokens = ((_e = usage.inputTokens) != null ? _e : 0) + ((_f = value.usage.output_tokens) != null ? _f : 0);
1435
+ usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
913
1436
  finishReason = mapAnthropicStopReason({
914
1437
  finishReason: value.delta.stop_reason,
915
1438
  isJsonResponseFromTool: jsonResponseTool != null
@@ -942,273 +1465,359 @@ var AnthropicMessagesLanguageModel = class {
942
1465
  };
943
1466
  }
944
1467
  };
945
- var anthropicMessagesResponseSchema = z3.object({
946
- type: z3.literal("message"),
947
- id: z3.string().nullish(),
948
- model: z3.string().nullish(),
949
- content: z3.array(
950
- z3.discriminatedUnion("type", [
951
- z3.object({
952
- type: z3.literal("text"),
953
- text: z3.string()
1468
+ var anthropicMessagesResponseSchema = z4.object({
1469
+ type: z4.literal("message"),
1470
+ id: z4.string().nullish(),
1471
+ model: z4.string().nullish(),
1472
+ content: z4.array(
1473
+ z4.discriminatedUnion("type", [
1474
+ z4.object({
1475
+ type: z4.literal("text"),
1476
+ text: z4.string(),
1477
+ citations: z4.array(citationSchema).optional()
954
1478
  }),
955
- z3.object({
956
- type: z3.literal("thinking"),
957
- thinking: z3.string(),
958
- signature: z3.string()
1479
+ z4.object({
1480
+ type: z4.literal("thinking"),
1481
+ thinking: z4.string(),
1482
+ signature: z4.string()
959
1483
  }),
960
- z3.object({
961
- type: z3.literal("redacted_thinking"),
962
- data: z3.string()
1484
+ z4.object({
1485
+ type: z4.literal("redacted_thinking"),
1486
+ data: z4.string()
963
1487
  }),
964
- z3.object({
965
- type: z3.literal("tool_use"),
966
- id: z3.string(),
967
- name: z3.string(),
968
- input: z3.unknown()
1488
+ z4.object({
1489
+ type: z4.literal("tool_use"),
1490
+ id: z4.string(),
1491
+ name: z4.string(),
1492
+ input: z4.unknown()
1493
+ }),
1494
+ z4.object({
1495
+ type: z4.literal("server_tool_use"),
1496
+ id: z4.string(),
1497
+ name: z4.string(),
1498
+ input: z4.record(z4.unknown()).nullish()
1499
+ }),
1500
+ z4.object({
1501
+ type: z4.literal("web_search_tool_result"),
1502
+ tool_use_id: z4.string(),
1503
+ content: z4.union([
1504
+ z4.array(
1505
+ z4.object({
1506
+ type: z4.literal("web_search_result"),
1507
+ url: z4.string(),
1508
+ title: z4.string(),
1509
+ encrypted_content: z4.string(),
1510
+ page_age: z4.string().nullish()
1511
+ })
1512
+ ),
1513
+ z4.object({
1514
+ type: z4.literal("web_search_tool_result_error"),
1515
+ error_code: z4.string()
1516
+ })
1517
+ ])
969
1518
  })
970
1519
  ])
971
1520
  ),
972
- stop_reason: z3.string().nullish(),
973
- usage: z3.object({
974
- input_tokens: z3.number(),
975
- output_tokens: z3.number(),
976
- cache_creation_input_tokens: z3.number().nullish(),
977
- cache_read_input_tokens: z3.number().nullish()
1521
+ stop_reason: z4.string().nullish(),
1522
+ usage: z4.object({
1523
+ input_tokens: z4.number(),
1524
+ output_tokens: z4.number(),
1525
+ cache_creation_input_tokens: z4.number().nullish(),
1526
+ cache_read_input_tokens: z4.number().nullish(),
1527
+ server_tool_use: z4.object({
1528
+ web_search_requests: z4.number()
1529
+ }).nullish()
978
1530
  })
979
1531
  });
980
- var anthropicMessagesChunkSchema = z3.discriminatedUnion("type", [
981
- z3.object({
982
- type: z3.literal("message_start"),
983
- message: z3.object({
984
- id: z3.string().nullish(),
985
- model: z3.string().nullish(),
986
- usage: z3.object({
987
- input_tokens: z3.number(),
988
- output_tokens: z3.number(),
989
- cache_creation_input_tokens: z3.number().nullish(),
990
- cache_read_input_tokens: z3.number().nullish()
1532
+ var anthropicMessagesChunkSchema = z4.discriminatedUnion("type", [
1533
+ z4.object({
1534
+ type: z4.literal("message_start"),
1535
+ message: z4.object({
1536
+ id: z4.string().nullish(),
1537
+ model: z4.string().nullish(),
1538
+ usage: z4.object({
1539
+ input_tokens: z4.number(),
1540
+ output_tokens: z4.number(),
1541
+ cache_creation_input_tokens: z4.number().nullish(),
1542
+ cache_read_input_tokens: z4.number().nullish()
991
1543
  })
992
1544
  })
993
1545
  }),
994
- z3.object({
995
- type: z3.literal("content_block_start"),
996
- index: z3.number(),
997
- content_block: z3.discriminatedUnion("type", [
998
- z3.object({
999
- type: z3.literal("text"),
1000
- text: z3.string()
1546
+ z4.object({
1547
+ type: z4.literal("content_block_start"),
1548
+ index: z4.number(),
1549
+ content_block: z4.discriminatedUnion("type", [
1550
+ z4.object({
1551
+ type: z4.literal("text"),
1552
+ text: z4.string()
1001
1553
  }),
1002
- z3.object({
1003
- type: z3.literal("thinking"),
1004
- thinking: z3.string()
1554
+ z4.object({
1555
+ type: z4.literal("thinking"),
1556
+ thinking: z4.string()
1005
1557
  }),
1006
- z3.object({
1007
- type: z3.literal("tool_use"),
1008
- id: z3.string(),
1009
- name: z3.string()
1558
+ z4.object({
1559
+ type: z4.literal("tool_use"),
1560
+ id: z4.string(),
1561
+ name: z4.string()
1010
1562
  }),
1011
- z3.object({
1012
- type: z3.literal("redacted_thinking"),
1013
- data: z3.string()
1563
+ z4.object({
1564
+ type: z4.literal("redacted_thinking"),
1565
+ data: z4.string()
1566
+ }),
1567
+ z4.object({
1568
+ type: z4.literal("server_tool_use"),
1569
+ id: z4.string(),
1570
+ name: z4.string(),
1571
+ input: z4.record(z4.unknown()).nullish()
1572
+ }),
1573
+ z4.object({
1574
+ type: z4.literal("web_search_tool_result"),
1575
+ tool_use_id: z4.string(),
1576
+ content: z4.union([
1577
+ z4.array(
1578
+ z4.object({
1579
+ type: z4.literal("web_search_result"),
1580
+ url: z4.string(),
1581
+ title: z4.string(),
1582
+ encrypted_content: z4.string(),
1583
+ page_age: z4.string().nullish()
1584
+ })
1585
+ ),
1586
+ z4.object({
1587
+ type: z4.literal("web_search_tool_result_error"),
1588
+ error_code: z4.string()
1589
+ })
1590
+ ])
1014
1591
  })
1015
1592
  ])
1016
1593
  }),
1017
- z3.object({
1018
- type: z3.literal("content_block_delta"),
1019
- index: z3.number(),
1020
- delta: z3.discriminatedUnion("type", [
1021
- z3.object({
1022
- type: z3.literal("input_json_delta"),
1023
- partial_json: z3.string()
1594
+ z4.object({
1595
+ type: z4.literal("content_block_delta"),
1596
+ index: z4.number(),
1597
+ delta: z4.discriminatedUnion("type", [
1598
+ z4.object({
1599
+ type: z4.literal("input_json_delta"),
1600
+ partial_json: z4.string()
1601
+ }),
1602
+ z4.object({
1603
+ type: z4.literal("text_delta"),
1604
+ text: z4.string()
1024
1605
  }),
1025
- z3.object({
1026
- type: z3.literal("text_delta"),
1027
- text: z3.string()
1606
+ z4.object({
1607
+ type: z4.literal("thinking_delta"),
1608
+ thinking: z4.string()
1028
1609
  }),
1029
- z3.object({
1030
- type: z3.literal("thinking_delta"),
1031
- thinking: z3.string()
1610
+ z4.object({
1611
+ type: z4.literal("signature_delta"),
1612
+ signature: z4.string()
1032
1613
  }),
1033
- z3.object({
1034
- type: z3.literal("signature_delta"),
1035
- signature: z3.string()
1614
+ z4.object({
1615
+ type: z4.literal("citations_delta"),
1616
+ citation: citationSchema
1036
1617
  })
1037
1618
  ])
1038
1619
  }),
1039
- z3.object({
1040
- type: z3.literal("content_block_stop"),
1041
- index: z3.number()
1620
+ z4.object({
1621
+ type: z4.literal("content_block_stop"),
1622
+ index: z4.number()
1042
1623
  }),
1043
- z3.object({
1044
- type: z3.literal("error"),
1045
- error: z3.object({
1046
- type: z3.string(),
1047
- message: z3.string()
1624
+ z4.object({
1625
+ type: z4.literal("error"),
1626
+ error: z4.object({
1627
+ type: z4.string(),
1628
+ message: z4.string()
1048
1629
  })
1049
1630
  }),
1050
- z3.object({
1051
- type: z3.literal("message_delta"),
1052
- delta: z3.object({ stop_reason: z3.string().nullish() }),
1053
- usage: z3.object({ output_tokens: z3.number() })
1631
+ z4.object({
1632
+ type: z4.literal("message_delta"),
1633
+ delta: z4.object({ stop_reason: z4.string().nullish() }),
1634
+ usage: z4.object({ output_tokens: z4.number() })
1054
1635
  }),
1055
- z3.object({
1056
- type: z3.literal("message_stop")
1636
+ z4.object({
1637
+ type: z4.literal("message_stop")
1057
1638
  }),
1058
- z3.object({
1059
- type: z3.literal("ping")
1639
+ z4.object({
1640
+ type: z4.literal("ping")
1060
1641
  })
1061
1642
  ]);
1062
- var anthropicReasoningMetadataSchema = z3.object({
1063
- signature: z3.string().optional(),
1064
- redactedData: z3.string().optional()
1643
+ var anthropicReasoningMetadataSchema = z4.object({
1644
+ signature: z4.string().optional(),
1645
+ redactedData: z4.string().optional()
1065
1646
  });
1066
1647
 
1067
- // src/anthropic-tools.ts
1068
- import { z as z4 } from "zod";
1069
- var Bash20241022Parameters = z4.object({
1070
- command: z4.string(),
1071
- restart: z4.boolean().optional()
1648
+ // src/tool/bash_20241022.ts
1649
+ import { createProviderDefinedToolFactory } from "@ai-sdk/provider-utils";
1650
+ import z5 from "zod/v4";
1651
+ var bash_20241022 = createProviderDefinedToolFactory({
1652
+ id: "anthropic.bash_20241022",
1653
+ name: "bash",
1654
+ inputSchema: z5.object({
1655
+ command: z5.string(),
1656
+ restart: z5.boolean().optional()
1657
+ })
1072
1658
  });
1073
- function bashTool_20241022(options = {}) {
1074
- return {
1075
- type: "provider-defined",
1076
- id: "anthropic.bash_20241022",
1077
- args: {},
1078
- parameters: Bash20241022Parameters,
1079
- execute: options.execute,
1080
- experimental_toToolResultContent: options.experimental_toToolResultContent
1081
- };
1082
- }
1083
- var Bash20250124Parameters = z4.object({
1084
- command: z4.string(),
1085
- restart: z4.boolean().optional()
1659
+
1660
+ // src/tool/bash_20250124.ts
1661
+ import { createProviderDefinedToolFactory as createProviderDefinedToolFactory2 } from "@ai-sdk/provider-utils";
1662
+ import z6 from "zod/v4";
1663
+ var bash_20250124 = createProviderDefinedToolFactory2({
1664
+ id: "anthropic.bashTool_20250124",
1665
+ name: "bash",
1666
+ inputSchema: z6.object({
1667
+ command: z6.string(),
1668
+ restart: z6.boolean().optional()
1669
+ })
1086
1670
  });
1087
- function bashTool_20250124(options = {}) {
1088
- return {
1089
- type: "provider-defined",
1090
- id: "anthropic.bash_20250124",
1091
- args: {},
1092
- parameters: Bash20250124Parameters,
1093
- execute: options.execute,
1094
- experimental_toToolResultContent: options.experimental_toToolResultContent
1095
- };
1096
- }
1097
- var TextEditor20241022Parameters = z4.object({
1098
- command: z4.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1099
- path: z4.string(),
1100
- file_text: z4.string().optional(),
1101
- insert_line: z4.number().int().optional(),
1102
- new_str: z4.string().optional(),
1103
- old_str: z4.string().optional(),
1104
- view_range: z4.array(z4.number().int()).optional()
1671
+
1672
+ // src/tool/computer_20241022.ts
1673
+ import { createProviderDefinedToolFactory as createProviderDefinedToolFactory3 } from "@ai-sdk/provider-utils";
1674
+ import { z as z7 } from "zod/v4";
1675
+ var computer_20241022 = createProviderDefinedToolFactory3({
1676
+ id: "anthropic.computer_20241022",
1677
+ name: "computer",
1678
+ inputSchema: z7.object({
1679
+ action: z7.enum([
1680
+ "key",
1681
+ "type",
1682
+ "mouse_move",
1683
+ "left_click",
1684
+ "left_click_drag",
1685
+ "right_click",
1686
+ "middle_click",
1687
+ "double_click",
1688
+ "screenshot",
1689
+ "cursor_position"
1690
+ ]),
1691
+ coordinate: z7.array(z7.number().int()).optional(),
1692
+ text: z7.string().optional()
1693
+ })
1105
1694
  });
1106
- function textEditorTool_20241022(options = {}) {
1107
- return {
1108
- type: "provider-defined",
1109
- id: "anthropic.text_editor_20241022",
1110
- args: {},
1111
- parameters: TextEditor20241022Parameters,
1112
- execute: options.execute,
1113
- experimental_toToolResultContent: options.experimental_toToolResultContent
1114
- };
1115
- }
1116
- var TextEditor20250124Parameters = z4.object({
1117
- command: z4.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1118
- path: z4.string(),
1119
- file_text: z4.string().optional(),
1120
- insert_line: z4.number().int().optional(),
1121
- new_str: z4.string().optional(),
1122
- old_str: z4.string().optional(),
1123
- view_range: z4.array(z4.number().int()).optional()
1695
+
1696
+ // src/tool/computer_20250124.ts
1697
+ import { createProviderDefinedToolFactory as createProviderDefinedToolFactory4 } from "@ai-sdk/provider-utils";
1698
+ import { z as z8 } from "zod/v4";
1699
+ var computer_20250124 = createProviderDefinedToolFactory4({
1700
+ id: "anthropic.computer_20250124",
1701
+ name: "computer",
1702
+ inputSchema: z8.object({
1703
+ action: z8.enum([
1704
+ "key",
1705
+ "hold_key",
1706
+ "type",
1707
+ "cursor_position",
1708
+ "mouse_move",
1709
+ "left_mouse_down",
1710
+ "left_mouse_up",
1711
+ "left_click",
1712
+ "left_click_drag",
1713
+ "right_click",
1714
+ "middle_click",
1715
+ "double_click",
1716
+ "triple_click",
1717
+ "scroll",
1718
+ "wait",
1719
+ "screenshot"
1720
+ ]),
1721
+ coordinate: z8.tuple([z8.number().int(), z8.number().int()]).optional(),
1722
+ duration: z8.number().optional(),
1723
+ scroll_amount: z8.number().optional(),
1724
+ scroll_direction: z8.enum(["up", "down", "left", "right"]).optional(),
1725
+ start_coordinate: z8.tuple([z8.number().int(), z8.number().int()]).optional(),
1726
+ text: z8.string().optional()
1727
+ })
1124
1728
  });
1125
- function textEditorTool_20250124(options = {}) {
1126
- return {
1127
- type: "provider-defined",
1128
- id: "anthropic.text_editor_20250124",
1129
- args: {},
1130
- parameters: TextEditor20250124Parameters,
1131
- execute: options.execute,
1132
- experimental_toToolResultContent: options.experimental_toToolResultContent
1133
- };
1134
- }
1135
- var Computer20241022Parameters = z4.object({
1136
- action: z4.enum([
1137
- "key",
1138
- "type",
1139
- "mouse_move",
1140
- "left_click",
1141
- "left_click_drag",
1142
- "right_click",
1143
- "middle_click",
1144
- "double_click",
1145
- "screenshot",
1146
- "cursor_position"
1147
- ]),
1148
- coordinate: z4.array(z4.number().int()).optional(),
1149
- text: z4.string().optional()
1729
+
1730
+ // src/tool/text-editor_20241022.ts
1731
+ import { createProviderDefinedToolFactory as createProviderDefinedToolFactory5 } from "@ai-sdk/provider-utils";
1732
+ import { z as z9 } from "zod/v4";
1733
+ var textEditor_20241022 = createProviderDefinedToolFactory5({
1734
+ id: "anthropic.text_editor_20241022",
1735
+ name: "str_replace_editor",
1736
+ inputSchema: z9.object({
1737
+ command: z9.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1738
+ path: z9.string(),
1739
+ file_text: z9.string().optional(),
1740
+ insert_line: z9.number().int().optional(),
1741
+ new_str: z9.string().optional(),
1742
+ old_str: z9.string().optional(),
1743
+ view_range: z9.array(z9.number().int()).optional()
1744
+ })
1150
1745
  });
1151
- function computerTool_20241022(options) {
1152
- return {
1153
- type: "provider-defined",
1154
- id: "anthropic.computer_20241022",
1155
- args: {
1156
- displayWidthPx: options.displayWidthPx,
1157
- displayHeightPx: options.displayHeightPx,
1158
- displayNumber: options.displayNumber
1159
- },
1160
- parameters: Computer20241022Parameters,
1161
- execute: options.execute,
1162
- experimental_toToolResultContent: options.experimental_toToolResultContent
1163
- };
1164
- }
1165
- var Computer20250124Parameters = z4.object({
1166
- action: z4.enum([
1167
- "key",
1168
- "hold_key",
1169
- "type",
1170
- "cursor_position",
1171
- "mouse_move",
1172
- "left_mouse_down",
1173
- "left_mouse_up",
1174
- "left_click",
1175
- "left_click_drag",
1176
- "right_click",
1177
- "middle_click",
1178
- "double_click",
1179
- "triple_click",
1180
- "scroll",
1181
- "wait",
1182
- "screenshot"
1183
- ]),
1184
- coordinate: z4.tuple([z4.number().int(), z4.number().int()]).optional(),
1185
- duration: z4.number().optional(),
1186
- scroll_amount: z4.number().optional(),
1187
- scroll_direction: z4.enum(["up", "down", "left", "right"]).optional(),
1188
- start_coordinate: z4.tuple([z4.number().int(), z4.number().int()]).optional(),
1189
- text: z4.string().optional()
1746
+
1747
+ // src/tool/text-editor_20250124.ts
1748
+ import { createProviderDefinedToolFactory as createProviderDefinedToolFactory6 } from "@ai-sdk/provider-utils";
1749
+ import { z as z10 } from "zod/v4";
1750
+ var textEditor_20250124 = createProviderDefinedToolFactory6({
1751
+ id: "anthropic.text_editor_20250124",
1752
+ name: "str_replace_editor",
1753
+ inputSchema: z10.object({
1754
+ command: z10.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1755
+ path: z10.string(),
1756
+ file_text: z10.string().optional(),
1757
+ insert_line: z10.number().int().optional(),
1758
+ new_str: z10.string().optional(),
1759
+ old_str: z10.string().optional(),
1760
+ view_range: z10.array(z10.number().int()).optional()
1761
+ })
1190
1762
  });
1191
- function computerTool_20250124(options) {
1192
- return {
1193
- type: "provider-defined",
1194
- id: "anthropic.computer_20250124",
1195
- args: {
1196
- displayWidthPx: options.displayWidthPx,
1197
- displayHeightPx: options.displayHeightPx,
1198
- displayNumber: options.displayNumber
1199
- },
1200
- parameters: Computer20250124Parameters,
1201
- execute: options.execute,
1202
- experimental_toToolResultContent: options.experimental_toToolResultContent
1203
- };
1204
- }
1763
+
1764
+ // src/anthropic-tools.ts
1205
1765
  var anthropicTools = {
1206
- bash_20241022: bashTool_20241022,
1207
- bash_20250124: bashTool_20250124,
1208
- textEditor_20241022: textEditorTool_20241022,
1209
- textEditor_20250124: textEditorTool_20250124,
1210
- computer_20241022: computerTool_20241022,
1211
- computer_20250124: computerTool_20250124
1766
+ /**
1767
+ * Creates a tool for running a bash command. Must have name "bash".
1768
+ *
1769
+ * Image results are supported.
1770
+ *
1771
+ * @param execute - The function to execute the tool. Optional.
1772
+ */
1773
+ bash_20241022,
1774
+ /**
1775
+ * Creates a tool for running a bash command. Must have name "bash".
1776
+ *
1777
+ * Image results are supported.
1778
+ *
1779
+ * @param execute - The function to execute the tool. Optional.
1780
+ */
1781
+ bash_20250124,
1782
+ /**
1783
+ * Creates a tool for editing text. Must have name "str_replace_editor".
1784
+ */
1785
+ textEditor_20241022,
1786
+ /**
1787
+ * Creates a tool for editing text. Must have name "str_replace_editor".
1788
+ */
1789
+ textEditor_20250124,
1790
+ /**
1791
+ * Creates a tool for executing actions on a computer. Must have name "computer".
1792
+ *
1793
+ * Image results are supported.
1794
+ *
1795
+ * @param displayWidthPx - The width of the display being controlled by the model in pixels.
1796
+ * @param displayHeightPx - The height of the display being controlled by the model in pixels.
1797
+ * @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.
1798
+ */
1799
+ computer_20241022,
1800
+ /**
1801
+ * Creates a tool for executing actions on a computer. Must have name "computer".
1802
+ *
1803
+ * Image results are supported.
1804
+ *
1805
+ * @param displayWidthPx - The width of the display being controlled by the model in pixels.
1806
+ * @param displayHeightPx - The height of the display being controlled by the model in pixels.
1807
+ * @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.
1808
+ * @param execute - The function to execute the tool. Optional.
1809
+ */
1810
+ computer_20250124,
1811
+ /**
1812
+ * Creates a web search tool that gives Claude direct access to real-time web content.
1813
+ * Must have name "web_search".
1814
+ *
1815
+ * @param maxUses - Maximum number of web searches Claude can perform during the conversation.
1816
+ * @param allowedDomains - Optional list of domains that Claude is allowed to search.
1817
+ * @param blockedDomains - Optional list of domains that Claude should avoid when searching.
1818
+ * @param userLocation - Optional user location information to provide geographically relevant search results.
1819
+ */
1820
+ webSearch_20250305
1212
1821
  };
1213
1822
  export {
1214
1823
  AnthropicMessagesLanguageModel,