@ai-sdk/anthropic 2.1.0-beta.1 → 2.1.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
+ VERSION: () => VERSION,
33
34
  anthropic: () => anthropic,
34
35
  createAnthropic: () => createAnthropic
35
36
  });
@@ -37,12 +38,15 @@ module.exports = __toCommonJS(src_exports);
37
38
 
38
39
  // src/anthropic-provider.ts
39
40
  var import_provider4 = require("@ai-sdk/provider");
40
- var import_provider_utils13 = require("@ai-sdk/provider-utils");
41
+ var import_provider_utils15 = require("@ai-sdk/provider-utils");
42
+
43
+ // src/version.ts
44
+ var VERSION = true ? "2.1.0-beta.10" : "0.0.0-test";
41
45
 
42
46
  // src/anthropic-messages-language-model.ts
43
47
  var import_provider3 = require("@ai-sdk/provider");
44
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
45
- var import_v45 = require("zod/v4");
48
+ var import_provider_utils7 = require("@ai-sdk/provider-utils");
49
+ var import_v47 = require("zod/v4");
46
50
 
47
51
  // src/anthropic-error.ts
48
52
  var import_provider_utils = require("@ai-sdk/provider-utils");
@@ -116,58 +120,110 @@ function getCacheControl(providerMetadata) {
116
120
  return cacheControlValue;
117
121
  }
118
122
 
119
- // src/tool/web-search_20250305.ts
123
+ // src/tool/text-editor_20250728.ts
120
124
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
121
125
  var import_v43 = require("zod/v4");
122
- var webSearch_20250305ArgsSchema = import_v43.z.object({
123
- /**
124
- * Maximum number of web searches Claude can perform during the conversation.
125
- */
126
- maxUses: import_v43.z.number().optional(),
127
- /**
128
- * Optional list of domains that Claude is allowed to search.
129
- */
130
- allowedDomains: import_v43.z.array(import_v43.z.string()).optional(),
131
- /**
132
- * Optional list of domains that Claude should avoid when searching.
133
- */
134
- blockedDomains: import_v43.z.array(import_v43.z.string()).optional(),
135
- /**
136
- * Optional user location information to provide geographically relevant search results.
137
- */
138
- userLocation: import_v43.z.object({
139
- type: import_v43.z.literal("approximate"),
140
- city: import_v43.z.string().optional(),
141
- region: import_v43.z.string().optional(),
142
- country: import_v43.z.string().optional(),
143
- timezone: import_v43.z.string().optional()
126
+ var textEditor_20250728ArgsSchema = import_v43.z.object({
127
+ maxCharacters: import_v43.z.number().optional()
128
+ });
129
+ var factory = (0, import_provider_utils2.createProviderDefinedToolFactory)({
130
+ id: "anthropic.text_editor_20250728",
131
+ name: "str_replace_based_edit_tool",
132
+ inputSchema: import_v43.z.object({
133
+ command: import_v43.z.enum(["view", "create", "str_replace", "insert"]),
134
+ path: import_v43.z.string(),
135
+ file_text: import_v43.z.string().optional(),
136
+ insert_line: import_v43.z.number().int().optional(),
137
+ new_str: import_v43.z.string().optional(),
138
+ old_str: import_v43.z.string().optional(),
139
+ view_range: import_v43.z.array(import_v43.z.number().int()).optional()
140
+ })
141
+ });
142
+ var textEditor_20250728 = (args = {}) => {
143
+ return factory(args);
144
+ };
145
+
146
+ // src/tool/web-search_20250305.ts
147
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
148
+ var import_v44 = require("zod/v4");
149
+ var webSearch_20250305ArgsSchema = import_v44.z.object({
150
+ maxUses: import_v44.z.number().optional(),
151
+ allowedDomains: import_v44.z.array(import_v44.z.string()).optional(),
152
+ blockedDomains: import_v44.z.array(import_v44.z.string()).optional(),
153
+ userLocation: import_v44.z.object({
154
+ type: import_v44.z.literal("approximate"),
155
+ city: import_v44.z.string().optional(),
156
+ region: import_v44.z.string().optional(),
157
+ country: import_v44.z.string().optional(),
158
+ timezone: import_v44.z.string().optional()
144
159
  }).optional()
145
160
  });
146
- var webSearch_20250305OutputSchema = import_v43.z.array(
147
- import_v43.z.object({
148
- url: import_v43.z.string(),
149
- title: import_v43.z.string(),
150
- pageAge: import_v43.z.string().nullable(),
151
- encryptedContent: import_v43.z.string(),
152
- type: import_v43.z.string()
161
+ var webSearch_20250305OutputSchema = import_v44.z.array(
162
+ import_v44.z.object({
163
+ url: import_v44.z.string(),
164
+ title: import_v44.z.string(),
165
+ pageAge: import_v44.z.string().nullable(),
166
+ encryptedContent: import_v44.z.string(),
167
+ type: import_v44.z.literal("web_search_result")
153
168
  })
154
169
  );
155
- var factory = (0, import_provider_utils2.createProviderDefinedToolFactoryWithOutputSchema)({
170
+ var factory2 = (0, import_provider_utils3.createProviderDefinedToolFactoryWithOutputSchema)({
156
171
  id: "anthropic.web_search_20250305",
157
172
  name: "web_search",
158
- inputSchema: import_v43.z.object({
159
- query: import_v43.z.string()
173
+ inputSchema: import_v44.z.object({
174
+ query: import_v44.z.string()
160
175
  }),
161
176
  outputSchema: webSearch_20250305OutputSchema
162
177
  });
163
178
  var webSearch_20250305 = (args = {}) => {
164
- return factory(args);
179
+ return factory2(args);
180
+ };
181
+
182
+ // src/tool/web-fetch-20250910.ts
183
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
184
+ var import_v45 = require("zod/v4");
185
+ var webFetch_20250910ArgsSchema = import_v45.z.object({
186
+ maxUses: import_v45.z.number().optional(),
187
+ allowedDomains: import_v45.z.array(import_v45.z.string()).optional(),
188
+ blockedDomains: import_v45.z.array(import_v45.z.string()).optional(),
189
+ citations: import_v45.z.object({ enabled: import_v45.z.boolean() }).optional(),
190
+ maxContentTokens: import_v45.z.number().optional()
191
+ });
192
+ var webFetch_20250910OutputSchema = import_v45.z.object({
193
+ type: import_v45.z.literal("web_fetch_result"),
194
+ url: import_v45.z.string(),
195
+ content: import_v45.z.object({
196
+ type: import_v45.z.literal("document"),
197
+ title: import_v45.z.string(),
198
+ citations: import_v45.z.object({ enabled: import_v45.z.boolean() }).optional(),
199
+ source: import_v45.z.union([
200
+ import_v45.z.object({
201
+ type: import_v45.z.literal("base64"),
202
+ mediaType: import_v45.z.literal("application/pdf"),
203
+ data: import_v45.z.string()
204
+ }),
205
+ import_v45.z.object({
206
+ type: import_v45.z.literal("text"),
207
+ mediaType: import_v45.z.literal("text/plain"),
208
+ data: import_v45.z.string()
209
+ })
210
+ ])
211
+ }),
212
+ retrievedAt: import_v45.z.string().nullable()
213
+ });
214
+ var factory3 = (0, import_provider_utils4.createProviderDefinedToolFactoryWithOutputSchema)({
215
+ id: "anthropic.web_fetch_20250910",
216
+ name: "web_fetch",
217
+ inputSchema: import_v45.z.object({
218
+ url: import_v45.z.string()
219
+ }),
220
+ outputSchema: webFetch_20250910OutputSchema
221
+ });
222
+ var webFetch_20250910 = (args = {}) => {
223
+ return factory3(args);
165
224
  };
166
225
 
167
226
  // src/anthropic-prepare-tools.ts
168
- function isWebSearchTool(tool) {
169
- return typeof tool === "object" && tool !== null && "type" in tool && tool.type === "web_search_20250305";
170
- }
171
227
  function prepareTools({
172
228
  tools,
173
229
  toolChoice,
@@ -181,12 +237,8 @@ function prepareTools({
181
237
  }
182
238
  const anthropicTools2 = [];
183
239
  for (const tool of tools) {
184
- if (isWebSearchTool(tool)) {
185
- anthropicTools2.push(tool);
186
- continue;
187
- }
188
240
  switch (tool.type) {
189
- case "function":
241
+ case "function": {
190
242
  const cacheControl = getCacheControl(tool.providerOptions);
191
243
  anthropicTools2.push({
192
244
  name: tool.name,
@@ -195,9 +247,18 @@ function prepareTools({
195
247
  cache_control: cacheControl
196
248
  });
197
249
  break;
198
- case "provider-defined":
250
+ }
251
+ case "provider-defined": {
199
252
  switch (tool.id) {
200
- case "anthropic.computer_20250124":
253
+ case "anthropic.code_execution_20250522": {
254
+ betas.add("code-execution-2025-05-22");
255
+ anthropicTools2.push({
256
+ type: "code_execution_20250522",
257
+ name: "code_execution"
258
+ });
259
+ break;
260
+ }
261
+ case "anthropic.computer_20250124": {
201
262
  betas.add("computer-use-2025-01-24");
202
263
  anthropicTools2.push({
203
264
  name: "computer",
@@ -207,7 +268,8 @@ function prepareTools({
207
268
  display_number: tool.args.displayNumber
208
269
  });
209
270
  break;
210
- case "anthropic.computer_20241022":
271
+ }
272
+ case "anthropic.computer_20241022": {
211
273
  betas.add("computer-use-2024-10-22");
212
274
  anthropicTools2.push({
213
275
  name: "computer",
@@ -217,41 +279,70 @@ function prepareTools({
217
279
  display_number: tool.args.displayNumber
218
280
  });
219
281
  break;
220
- case "anthropic.text_editor_20250124":
282
+ }
283
+ case "anthropic.text_editor_20250124": {
221
284
  betas.add("computer-use-2025-01-24");
222
285
  anthropicTools2.push({
223
286
  name: "str_replace_editor",
224
287
  type: "text_editor_20250124"
225
288
  });
226
289
  break;
227
- case "anthropic.text_editor_20241022":
290
+ }
291
+ case "anthropic.text_editor_20241022": {
228
292
  betas.add("computer-use-2024-10-22");
229
293
  anthropicTools2.push({
230
294
  name: "str_replace_editor",
231
295
  type: "text_editor_20241022"
232
296
  });
233
297
  break;
234
- case "anthropic.text_editor_20250429":
298
+ }
299
+ case "anthropic.text_editor_20250429": {
235
300
  betas.add("computer-use-2025-01-24");
236
301
  anthropicTools2.push({
237
302
  name: "str_replace_based_edit_tool",
238
303
  type: "text_editor_20250429"
239
304
  });
240
305
  break;
241
- case "anthropic.bash_20250124":
306
+ }
307
+ case "anthropic.text_editor_20250728": {
308
+ const args = textEditor_20250728ArgsSchema.parse(tool.args);
309
+ anthropicTools2.push({
310
+ name: "str_replace_based_edit_tool",
311
+ type: "text_editor_20250728",
312
+ max_characters: args.maxCharacters
313
+ });
314
+ break;
315
+ }
316
+ case "anthropic.bash_20250124": {
242
317
  betas.add("computer-use-2025-01-24");
243
318
  anthropicTools2.push({
244
319
  name: "bash",
245
320
  type: "bash_20250124"
246
321
  });
247
322
  break;
248
- case "anthropic.bash_20241022":
323
+ }
324
+ case "anthropic.bash_20241022": {
249
325
  betas.add("computer-use-2024-10-22");
250
326
  anthropicTools2.push({
251
327
  name: "bash",
252
328
  type: "bash_20241022"
253
329
  });
254
330
  break;
331
+ }
332
+ case "anthropic.web_fetch_20250910": {
333
+ betas.add("web-fetch-2025-09-10");
334
+ const args = webFetch_20250910ArgsSchema.parse(tool.args);
335
+ anthropicTools2.push({
336
+ type: "web_fetch_20250910",
337
+ name: "web_fetch",
338
+ max_uses: args.maxUses,
339
+ allowed_domains: args.allowedDomains,
340
+ blocked_domains: args.blockedDomains,
341
+ citations: args.citations,
342
+ max_content_tokens: args.maxContentTokens
343
+ });
344
+ break;
345
+ }
255
346
  case "anthropic.web_search_20250305": {
256
347
  const args = webSearch_20250305ArgsSchema.parse(tool.args);
257
348
  anthropicTools2.push({
@@ -264,22 +355,17 @@ function prepareTools({
264
355
  });
265
356
  break;
266
357
  }
267
- case "anthropic.code_execution_20250522": {
268
- betas.add("code-execution-2025-05-22");
269
- anthropicTools2.push({
270
- type: "code_execution_20250522",
271
- name: "code_execution"
272
- });
273
- break;
274
- }
275
- default:
358
+ default: {
276
359
  toolWarnings.push({ type: "unsupported-tool", tool });
277
360
  break;
361
+ }
278
362
  }
279
363
  break;
280
- default:
364
+ }
365
+ default: {
281
366
  toolWarnings.push({ type: "unsupported-tool", tool });
282
367
  break;
368
+ }
283
369
  }
284
370
  }
285
371
  if (toolChoice == null) {
@@ -336,27 +422,27 @@ function prepareTools({
336
422
 
337
423
  // src/convert-to-anthropic-messages-prompt.ts
338
424
  var import_provider2 = require("@ai-sdk/provider");
339
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
425
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
340
426
 
341
427
  // src/tool/code-execution_20250522.ts
342
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
343
- var import_v44 = require("zod/v4");
344
- var codeExecution_20250522OutputSchema = import_v44.z.object({
345
- type: import_v44.z.literal("code_execution_result"),
346
- stdout: import_v44.z.string(),
347
- stderr: import_v44.z.string(),
348
- return_code: import_v44.z.number()
428
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
429
+ var import_v46 = require("zod/v4");
430
+ var codeExecution_20250522OutputSchema = import_v46.z.object({
431
+ type: import_v46.z.literal("code_execution_result"),
432
+ stdout: import_v46.z.string(),
433
+ stderr: import_v46.z.string(),
434
+ return_code: import_v46.z.number()
349
435
  });
350
- var factory2 = (0, import_provider_utils3.createProviderDefinedToolFactoryWithOutputSchema)({
436
+ var factory4 = (0, import_provider_utils5.createProviderDefinedToolFactoryWithOutputSchema)({
351
437
  id: "anthropic.code_execution_20250522",
352
438
  name: "code_execution",
353
- inputSchema: import_v44.z.object({
354
- code: import_v44.z.string()
439
+ inputSchema: import_v46.z.object({
440
+ code: import_v46.z.string()
355
441
  }),
356
442
  outputSchema: codeExecution_20250522OutputSchema
357
443
  });
358
444
  var codeExecution_20250522 = (args = {}) => {
359
- return factory2(args);
445
+ return factory4(args);
360
446
  };
361
447
 
362
448
  // src/convert-to-anthropic-messages-prompt.ts
@@ -388,7 +474,7 @@ async function convertToAnthropicMessagesPrompt({
388
474
  const messages = [];
389
475
  async function shouldEnableCitations(providerMetadata) {
390
476
  var _a2, _b2;
391
- const anthropicOptions = await (0, import_provider_utils4.parseProviderOptions)({
477
+ const anthropicOptions = await (0, import_provider_utils6.parseProviderOptions)({
392
478
  provider: "anthropic",
393
479
  providerOptions: providerMetadata,
394
480
  schema: anthropicFilePartProviderOptions
@@ -396,7 +482,7 @@ async function convertToAnthropicMessagesPrompt({
396
482
  return (_b2 = (_a2 = anthropicOptions == null ? void 0 : anthropicOptions.citations) == null ? void 0 : _a2.enabled) != null ? _b2 : false;
397
483
  }
398
484
  async function getDocumentMetadata(providerMetadata) {
399
- const anthropicOptions = await (0, import_provider_utils4.parseProviderOptions)({
485
+ const anthropicOptions = await (0, import_provider_utils6.parseProviderOptions)({
400
486
  provider: "anthropic",
401
487
  providerOptions: providerMetadata,
402
488
  schema: anthropicFilePartProviderOptions
@@ -453,7 +539,7 @@ async function convertToAnthropicMessagesPrompt({
453
539
  } : {
454
540
  type: "base64",
455
541
  media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
456
- data: (0, import_provider_utils4.convertToBase64)(part.data)
542
+ data: (0, import_provider_utils6.convertToBase64)(part.data)
457
543
  },
458
544
  cache_control: cacheControl
459
545
  });
@@ -473,7 +559,7 @@ async function convertToAnthropicMessagesPrompt({
473
559
  } : {
474
560
  type: "base64",
475
561
  media_type: "application/pdf",
476
- data: (0, import_provider_utils4.convertToBase64)(part.data)
562
+ data: (0, import_provider_utils6.convertToBase64)(part.data)
477
563
  },
478
564
  title: (_b = metadata.title) != null ? _b : part.filename,
479
565
  ...metadata.context && { context: metadata.context },
@@ -608,7 +694,7 @@ async function convertToAnthropicMessagesPrompt({
608
694
  }
609
695
  case "reasoning": {
610
696
  if (sendReasoning) {
611
- const reasoningMetadata = await (0, import_provider_utils4.parseProviderOptions)({
697
+ const reasoningMetadata = await (0, import_provider_utils6.parseProviderOptions)({
612
698
  provider: "anthropic",
613
699
  providerOptions: part.providerOptions,
614
700
  schema: anthropicReasoningMetadataSchema
@@ -649,30 +735,20 @@ async function convertToAnthropicMessagesPrompt({
649
735
  }
650
736
  case "tool-call": {
651
737
  if (part.providerExecuted) {
652
- if (part.toolName === "web_search") {
738
+ if (part.toolName === "code_execution" || part.toolName === "web_fetch" || part.toolName === "web_search") {
653
739
  anthropicContent.push({
654
740
  type: "server_tool_use",
655
741
  id: part.toolCallId,
656
- name: "web_search",
742
+ name: part.toolName,
657
743
  input: part.input,
658
744
  cache_control: cacheControl
659
745
  });
660
- break;
661
- }
662
- if (part.toolName === "code_execution") {
663
- anthropicContent.push({
664
- type: "server_tool_use",
665
- id: part.toolCallId,
666
- name: "code_execution",
667
- input: part.input,
668
- cache_control: cacheControl
746
+ } else {
747
+ warnings.push({
748
+ type: "other",
749
+ message: `provider executed tool call for tool ${part.toolName} is not supported`
669
750
  });
670
- break;
671
751
  }
672
- warnings.push({
673
- type: "other",
674
- message: `provider executed tool call for tool ${part.toolName} is not supported`
675
- });
676
752
  break;
677
753
  }
678
754
  anthropicContent.push({
@@ -685,7 +761,7 @@ async function convertToAnthropicMessagesPrompt({
685
761
  break;
686
762
  }
687
763
  case "tool-result": {
688
- if (part.toolName === "web_search") {
764
+ if (part.toolName === "code_execution") {
689
765
  const output = part.output;
690
766
  if (output.type !== "json") {
691
767
  warnings.push({
@@ -694,24 +770,21 @@ async function convertToAnthropicMessagesPrompt({
694
770
  });
695
771
  break;
696
772
  }
697
- const webSearchOutput = webSearch_20250305OutputSchema.parse(
698
- output.value
699
- );
773
+ const codeExecutionOutput = codeExecution_20250522OutputSchema.parse(output.value);
700
774
  anthropicContent.push({
701
- type: "web_search_tool_result",
775
+ type: "code_execution_tool_result",
702
776
  tool_use_id: part.toolCallId,
703
- content: webSearchOutput.map((result) => ({
704
- url: result.url,
705
- title: result.title,
706
- page_age: result.pageAge,
707
- encrypted_content: result.encryptedContent,
708
- type: result.type
709
- })),
777
+ content: {
778
+ type: codeExecutionOutput.type,
779
+ stdout: codeExecutionOutput.stdout,
780
+ stderr: codeExecutionOutput.stderr,
781
+ return_code: codeExecutionOutput.return_code
782
+ },
710
783
  cache_control: cacheControl
711
784
  });
712
785
  break;
713
786
  }
714
- if (part.toolName === "code_execution") {
787
+ if (part.toolName === "web_fetch") {
715
788
  const output = part.output;
716
789
  if (output.type !== "json") {
717
790
  warnings.push({
@@ -720,20 +793,57 @@ async function convertToAnthropicMessagesPrompt({
720
793
  });
721
794
  break;
722
795
  }
723
- const codeExecutionOutput = codeExecution_20250522OutputSchema.parse(output.value);
796
+ const webFetchOutput = webFetch_20250910OutputSchema.parse(
797
+ output.value
798
+ );
724
799
  anthropicContent.push({
725
- type: "code_execution_tool_result",
800
+ type: "web_fetch_tool_result",
726
801
  tool_use_id: part.toolCallId,
727
802
  content: {
728
- type: codeExecutionOutput.type,
729
- stdout: codeExecutionOutput.stdout,
730
- stderr: codeExecutionOutput.stderr,
731
- return_code: codeExecutionOutput.return_code
803
+ type: "web_fetch_result",
804
+ url: webFetchOutput.url,
805
+ retrieved_at: webFetchOutput.retrievedAt,
806
+ content: {
807
+ type: "document",
808
+ title: webFetchOutput.content.title,
809
+ citations: webFetchOutput.content.citations,
810
+ source: {
811
+ type: webFetchOutput.content.source.type,
812
+ media_type: webFetchOutput.content.source.mediaType,
813
+ data: webFetchOutput.content.source.data
814
+ }
815
+ }
732
816
  },
733
817
  cache_control: cacheControl
734
818
  });
735
819
  break;
736
820
  }
821
+ if (part.toolName === "web_search") {
822
+ const output = part.output;
823
+ if (output.type !== "json") {
824
+ warnings.push({
825
+ type: "other",
826
+ message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
827
+ });
828
+ break;
829
+ }
830
+ const webSearchOutput = webSearch_20250305OutputSchema.parse(
831
+ output.value
832
+ );
833
+ anthropicContent.push({
834
+ type: "web_search_tool_result",
835
+ tool_use_id: part.toolCallId,
836
+ content: webSearchOutput.map((result) => ({
837
+ url: result.url,
838
+ title: result.title,
839
+ page_age: result.pageAge,
840
+ encrypted_content: result.encryptedContent,
841
+ type: result.type
842
+ })),
843
+ cache_control: cacheControl
844
+ });
845
+ break;
846
+ }
737
847
  warnings.push({
738
848
  type: "other",
739
849
  message: `provider executed tool result for tool ${part.toolName} is not supported`
@@ -827,36 +937,36 @@ function mapAnthropicStopReason({
827
937
 
828
938
  // src/anthropic-messages-language-model.ts
829
939
  var citationSchemas = {
830
- webSearchResult: import_v45.z.object({
831
- type: import_v45.z.literal("web_search_result_location"),
832
- cited_text: import_v45.z.string(),
833
- url: import_v45.z.string(),
834
- title: import_v45.z.string(),
835
- encrypted_index: import_v45.z.string()
940
+ webSearchResult: import_v47.z.object({
941
+ type: import_v47.z.literal("web_search_result_location"),
942
+ cited_text: import_v47.z.string(),
943
+ url: import_v47.z.string(),
944
+ title: import_v47.z.string(),
945
+ encrypted_index: import_v47.z.string()
836
946
  }),
837
- pageLocation: import_v45.z.object({
838
- type: import_v45.z.literal("page_location"),
839
- cited_text: import_v45.z.string(),
840
- document_index: import_v45.z.number(),
841
- document_title: import_v45.z.string().nullable(),
842
- start_page_number: import_v45.z.number(),
843
- end_page_number: import_v45.z.number()
947
+ pageLocation: import_v47.z.object({
948
+ type: import_v47.z.literal("page_location"),
949
+ cited_text: import_v47.z.string(),
950
+ document_index: import_v47.z.number(),
951
+ document_title: import_v47.z.string().nullable(),
952
+ start_page_number: import_v47.z.number(),
953
+ end_page_number: import_v47.z.number()
844
954
  }),
845
- charLocation: import_v45.z.object({
846
- type: import_v45.z.literal("char_location"),
847
- cited_text: import_v45.z.string(),
848
- document_index: import_v45.z.number(),
849
- document_title: import_v45.z.string().nullable(),
850
- start_char_index: import_v45.z.number(),
851
- end_char_index: import_v45.z.number()
955
+ charLocation: import_v47.z.object({
956
+ type: import_v47.z.literal("char_location"),
957
+ cited_text: import_v47.z.string(),
958
+ document_index: import_v47.z.number(),
959
+ document_title: import_v47.z.string().nullable(),
960
+ start_char_index: import_v47.z.number(),
961
+ end_char_index: import_v47.z.number()
852
962
  })
853
963
  };
854
- var citationSchema = import_v45.z.discriminatedUnion("type", [
964
+ var citationSchema = import_v47.z.discriminatedUnion("type", [
855
965
  citationSchemas.webSearchResult,
856
966
  citationSchemas.pageLocation,
857
967
  citationSchemas.charLocation
858
968
  ]);
859
- var documentCitationSchema = import_v45.z.discriminatedUnion("type", [
969
+ var documentCitationSchema = import_v47.z.discriminatedUnion("type", [
860
970
  citationSchemas.pageLocation,
861
971
  citationSchemas.charLocation
862
972
  ]);
@@ -901,11 +1011,11 @@ function createCitationSource(citation, citationDocuments, generateId3) {
901
1011
  }
902
1012
  var AnthropicMessagesLanguageModel = class {
903
1013
  constructor(modelId, config) {
904
- this.specificationVersion = "v2";
1014
+ this.specificationVersion = "v3";
905
1015
  var _a;
906
1016
  this.modelId = modelId;
907
1017
  this.config = config;
908
- this.generateId = (_a = config.generateId) != null ? _a : import_provider_utils5.generateId;
1018
+ this.generateId = (_a = config.generateId) != null ? _a : import_provider_utils7.generateId;
909
1019
  }
910
1020
  supportsUrl(url) {
911
1021
  return url.protocol === "https:";
@@ -974,7 +1084,7 @@ var AnthropicMessagesLanguageModel = class {
974
1084
  description: "Respond with a JSON object.",
975
1085
  inputSchema: responseFormat.schema
976
1086
  } : void 0;
977
- const anthropicOptions = await (0, import_provider_utils5.parseProviderOptions)({
1087
+ const anthropicOptions = await (0, import_provider_utils7.parseProviderOptions)({
978
1088
  provider: "anthropic",
979
1089
  providerOptions,
980
1090
  schema: anthropicProviderOptions
@@ -1066,8 +1176,8 @@ var AnthropicMessagesLanguageModel = class {
1066
1176
  betas,
1067
1177
  headers
1068
1178
  }) {
1069
- return (0, import_provider_utils5.combineHeaders)(
1070
- await (0, import_provider_utils5.resolve)(this.config.headers),
1179
+ return (0, import_provider_utils7.combineHeaders)(
1180
+ await (0, import_provider_utils7.resolve)(this.config.headers),
1071
1181
  betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {},
1072
1182
  headers
1073
1183
  );
@@ -1104,19 +1214,19 @@ var AnthropicMessagesLanguageModel = class {
1104
1214
  });
1105
1215
  }
1106
1216
  async doGenerate(options) {
1107
- var _a, _b, _c, _d, _e;
1217
+ var _a, _b, _c, _d, _e, _f;
1108
1218
  const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
1109
1219
  const citationDocuments = this.extractCitationDocuments(options.prompt);
1110
1220
  const {
1111
1221
  responseHeaders,
1112
1222
  value: response,
1113
1223
  rawValue: rawResponse
1114
- } = await (0, import_provider_utils5.postJsonToApi)({
1224
+ } = await (0, import_provider_utils7.postJsonToApi)({
1115
1225
  url: this.buildRequestUrl(false),
1116
1226
  headers: await this.getHeaders({ betas, headers: options.headers }),
1117
1227
  body: this.transformRequestBody(args),
1118
1228
  failedResponseHandler: anthropicFailedResponseHandler,
1119
- successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
1229
+ successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
1120
1230
  anthropicMessagesResponseSchema
1121
1231
  ),
1122
1232
  abortSignal: options.abortSignal,
@@ -1181,7 +1291,7 @@ var AnthropicMessagesLanguageModel = class {
1181
1291
  break;
1182
1292
  }
1183
1293
  case "server_tool_use": {
1184
- if (part.name === "web_search" || part.name === "code_execution") {
1294
+ if (part.name === "web_search" || part.name === "code_execution" || part.name === "web_fetch") {
1185
1295
  content.push({
1186
1296
  type: "tool-call",
1187
1297
  toolCallId: part.id,
@@ -1192,6 +1302,44 @@ var AnthropicMessagesLanguageModel = class {
1192
1302
  }
1193
1303
  break;
1194
1304
  }
1305
+ case "web_fetch_tool_result": {
1306
+ if (part.content.type === "web_fetch_result") {
1307
+ content.push({
1308
+ type: "tool-result",
1309
+ toolCallId: part.tool_use_id,
1310
+ toolName: "web_fetch",
1311
+ result: {
1312
+ type: "web_fetch_result",
1313
+ url: part.content.url,
1314
+ retrievedAt: part.content.retrieved_at,
1315
+ content: {
1316
+ type: part.content.content.type,
1317
+ title: part.content.content.title,
1318
+ citations: part.content.content.citations,
1319
+ source: {
1320
+ type: part.content.content.source.type,
1321
+ mediaType: part.content.content.source.media_type,
1322
+ data: part.content.content.source.data
1323
+ }
1324
+ }
1325
+ },
1326
+ providerExecuted: true
1327
+ });
1328
+ } else if (part.content.type === "web_fetch_tool_result_error") {
1329
+ content.push({
1330
+ type: "tool-result",
1331
+ toolCallId: part.tool_use_id,
1332
+ toolName: "web_fetch",
1333
+ isError: true,
1334
+ result: {
1335
+ type: "web_fetch_tool_result_error",
1336
+ errorCode: part.content.error_code
1337
+ },
1338
+ providerExecuted: true
1339
+ });
1340
+ }
1341
+ break;
1342
+ }
1195
1343
  case "web_search_tool_result": {
1196
1344
  if (Array.isArray(part.content)) {
1197
1345
  content.push({
@@ -1293,7 +1441,8 @@ var AnthropicMessagesLanguageModel = class {
1293
1441
  providerMetadata: {
1294
1442
  anthropic: {
1295
1443
  usage: response.usage,
1296
- cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null
1444
+ cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null,
1445
+ stopSequence: (_f = response.stop_sequence) != null ? _f : null
1297
1446
  }
1298
1447
  }
1299
1448
  };
@@ -1302,12 +1451,12 @@ var AnthropicMessagesLanguageModel = class {
1302
1451
  const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
1303
1452
  const citationDocuments = this.extractCitationDocuments(options.prompt);
1304
1453
  const body = { ...args, stream: true };
1305
- const { responseHeaders, value: response } = await (0, import_provider_utils5.postJsonToApi)({
1454
+ const { responseHeaders, value: response } = await (0, import_provider_utils7.postJsonToApi)({
1306
1455
  url: this.buildRequestUrl(true),
1307
1456
  headers: await this.getHeaders({ betas, headers: options.headers }),
1308
1457
  body: this.transformRequestBody(body),
1309
1458
  failedResponseHandler: anthropicFailedResponseHandler,
1310
- successfulResponseHandler: (0, import_provider_utils5.createEventSourceResponseHandler)(
1459
+ successfulResponseHandler: (0, import_provider_utils7.createEventSourceResponseHandler)(
1311
1460
  anthropicMessagesChunkSchema
1312
1461
  ),
1313
1462
  abortSignal: options.abortSignal,
@@ -1320,7 +1469,9 @@ var AnthropicMessagesLanguageModel = class {
1320
1469
  totalTokens: void 0
1321
1470
  };
1322
1471
  const contentBlocks = {};
1323
- let providerMetadata = void 0;
1472
+ let rawUsage = void 0;
1473
+ let cacheCreationInputTokens = null;
1474
+ let stopSequence = null;
1324
1475
  let blockType = void 0;
1325
1476
  const generateId3 = this.generateId;
1326
1477
  return {
@@ -1330,7 +1481,7 @@ var AnthropicMessagesLanguageModel = class {
1330
1481
  controller.enqueue({ type: "stream-start", warnings });
1331
1482
  },
1332
1483
  transform(chunk, controller) {
1333
- var _a, _b, _c, _d, _e, _f, _g;
1484
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1334
1485
  if (options.includeRawChunks) {
1335
1486
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1336
1487
  }
@@ -1393,7 +1544,7 @@ var AnthropicMessagesLanguageModel = class {
1393
1544
  return;
1394
1545
  }
1395
1546
  case "server_tool_use": {
1396
- if (value.content_block.name === "web_search" || value.content_block.name === "code_execution") {
1547
+ if (value.content_block.name === "web_fetch" || value.content_block.name === "web_search" || value.content_block.name === "code_execution") {
1397
1548
  contentBlocks[value.index] = {
1398
1549
  type: "tool-call",
1399
1550
  toolCallId: value.content_block.id,
@@ -1410,6 +1561,44 @@ var AnthropicMessagesLanguageModel = class {
1410
1561
  }
1411
1562
  return;
1412
1563
  }
1564
+ case "web_fetch_tool_result": {
1565
+ const part = value.content_block;
1566
+ if (part.content.type === "web_fetch_result") {
1567
+ controller.enqueue({
1568
+ type: "tool-result",
1569
+ toolCallId: part.tool_use_id,
1570
+ toolName: "web_fetch",
1571
+ result: {
1572
+ type: "web_fetch_result",
1573
+ url: part.content.url,
1574
+ retrievedAt: part.content.retrieved_at,
1575
+ content: {
1576
+ type: part.content.content.type,
1577
+ title: part.content.content.title,
1578
+ citations: part.content.content.citations,
1579
+ source: {
1580
+ type: part.content.content.source.type,
1581
+ mediaType: part.content.content.source.media_type,
1582
+ data: part.content.content.source.data
1583
+ }
1584
+ }
1585
+ }
1586
+ });
1587
+ } else if (part.content.type === "web_fetch_tool_result_error") {
1588
+ controller.enqueue({
1589
+ type: "tool-result",
1590
+ toolCallId: part.tool_use_id,
1591
+ toolName: "web_fetch",
1592
+ isError: true,
1593
+ result: {
1594
+ type: "web_fetch_tool_result_error",
1595
+ errorCode: part.content.error_code
1596
+ },
1597
+ providerExecuted: true
1598
+ });
1599
+ }
1600
+ return;
1601
+ }
1413
1602
  case "web_search_tool_result": {
1414
1603
  const part = value.content_block;
1415
1604
  if (Array.isArray(part.content)) {
@@ -1612,12 +1801,10 @@ var AnthropicMessagesLanguageModel = class {
1612
1801
  case "message_start": {
1613
1802
  usage.inputTokens = value.message.usage.input_tokens;
1614
1803
  usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
1615
- providerMetadata = {
1616
- anthropic: {
1617
- usage: value.message.usage,
1618
- cacheCreationInputTokens: (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null
1619
- }
1804
+ rawUsage = {
1805
+ ...value.message.usage
1620
1806
  };
1807
+ cacheCreationInputTokens = (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null;
1621
1808
  controller.enqueue({
1622
1809
  type: "response-metadata",
1623
1810
  id: (_d = value.message.id) != null ? _d : void 0,
@@ -1632,6 +1819,11 @@ var AnthropicMessagesLanguageModel = class {
1632
1819
  finishReason: value.delta.stop_reason,
1633
1820
  isJsonResponseFromTool: usesJsonResponseTool
1634
1821
  });
1822
+ stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
1823
+ rawUsage = {
1824
+ ...rawUsage,
1825
+ ...value.usage
1826
+ };
1635
1827
  return;
1636
1828
  }
1637
1829
  case "message_stop": {
@@ -1639,7 +1831,13 @@ var AnthropicMessagesLanguageModel = class {
1639
1831
  type: "finish",
1640
1832
  finishReason,
1641
1833
  usage,
1642
- providerMetadata
1834
+ providerMetadata: {
1835
+ anthropic: {
1836
+ usage: rawUsage != null ? rawUsage : null,
1837
+ cacheCreationInputTokens,
1838
+ stopSequence
1839
+ }
1840
+ }
1643
1841
  });
1644
1842
  return;
1645
1843
  }
@@ -1660,247 +1858,303 @@ var AnthropicMessagesLanguageModel = class {
1660
1858
  };
1661
1859
  }
1662
1860
  };
1663
- var anthropicMessagesResponseSchema = import_v45.z.object({
1664
- type: import_v45.z.literal("message"),
1665
- id: import_v45.z.string().nullish(),
1666
- model: import_v45.z.string().nullish(),
1667
- content: import_v45.z.array(
1668
- import_v45.z.discriminatedUnion("type", [
1669
- import_v45.z.object({
1670
- type: import_v45.z.literal("text"),
1671
- text: import_v45.z.string(),
1672
- citations: import_v45.z.array(citationSchema).optional()
1861
+ var anthropicMessagesResponseSchema = import_v47.z.object({
1862
+ type: import_v47.z.literal("message"),
1863
+ id: import_v47.z.string().nullish(),
1864
+ model: import_v47.z.string().nullish(),
1865
+ content: import_v47.z.array(
1866
+ import_v47.z.discriminatedUnion("type", [
1867
+ import_v47.z.object({
1868
+ type: import_v47.z.literal("text"),
1869
+ text: import_v47.z.string(),
1870
+ citations: import_v47.z.array(citationSchema).optional()
1673
1871
  }),
1674
- import_v45.z.object({
1675
- type: import_v45.z.literal("thinking"),
1676
- thinking: import_v45.z.string(),
1677
- signature: import_v45.z.string()
1872
+ import_v47.z.object({
1873
+ type: import_v47.z.literal("thinking"),
1874
+ thinking: import_v47.z.string(),
1875
+ signature: import_v47.z.string()
1678
1876
  }),
1679
- import_v45.z.object({
1680
- type: import_v45.z.literal("redacted_thinking"),
1681
- data: import_v45.z.string()
1877
+ import_v47.z.object({
1878
+ type: import_v47.z.literal("redacted_thinking"),
1879
+ data: import_v47.z.string()
1682
1880
  }),
1683
- import_v45.z.object({
1684
- type: import_v45.z.literal("tool_use"),
1685
- id: import_v45.z.string(),
1686
- name: import_v45.z.string(),
1687
- input: import_v45.z.unknown()
1881
+ import_v47.z.object({
1882
+ type: import_v47.z.literal("tool_use"),
1883
+ id: import_v47.z.string(),
1884
+ name: import_v47.z.string(),
1885
+ input: import_v47.z.unknown()
1688
1886
  }),
1689
- import_v45.z.object({
1690
- type: import_v45.z.literal("server_tool_use"),
1691
- id: import_v45.z.string(),
1692
- name: import_v45.z.string(),
1693
- input: import_v45.z.record(import_v45.z.string(), import_v45.z.unknown()).nullish()
1887
+ import_v47.z.object({
1888
+ type: import_v47.z.literal("server_tool_use"),
1889
+ id: import_v47.z.string(),
1890
+ name: import_v47.z.string(),
1891
+ input: import_v47.z.record(import_v47.z.string(), import_v47.z.unknown()).nullish()
1694
1892
  }),
1695
- import_v45.z.object({
1696
- type: import_v45.z.literal("web_search_tool_result"),
1697
- tool_use_id: import_v45.z.string(),
1698
- content: import_v45.z.union([
1699
- import_v45.z.array(
1700
- import_v45.z.object({
1701
- type: import_v45.z.literal("web_search_result"),
1702
- url: import_v45.z.string(),
1703
- title: import_v45.z.string(),
1704
- encrypted_content: import_v45.z.string(),
1705
- page_age: import_v45.z.string().nullish()
1893
+ import_v47.z.object({
1894
+ type: import_v47.z.literal("web_fetch_tool_result"),
1895
+ tool_use_id: import_v47.z.string(),
1896
+ content: import_v47.z.union([
1897
+ import_v47.z.object({
1898
+ type: import_v47.z.literal("web_fetch_result"),
1899
+ url: import_v47.z.string(),
1900
+ retrieved_at: import_v47.z.string(),
1901
+ content: import_v47.z.object({
1902
+ type: import_v47.z.literal("document"),
1903
+ title: import_v47.z.string().nullable(),
1904
+ citations: import_v47.z.object({ enabled: import_v47.z.boolean() }).optional(),
1905
+ source: import_v47.z.object({
1906
+ type: import_v47.z.literal("text"),
1907
+ media_type: import_v47.z.string(),
1908
+ data: import_v47.z.string()
1909
+ })
1910
+ })
1911
+ }),
1912
+ import_v47.z.object({
1913
+ type: import_v47.z.literal("web_fetch_tool_result_error"),
1914
+ error_code: import_v47.z.string()
1915
+ })
1916
+ ])
1917
+ }),
1918
+ import_v47.z.object({
1919
+ type: import_v47.z.literal("web_search_tool_result"),
1920
+ tool_use_id: import_v47.z.string(),
1921
+ content: import_v47.z.union([
1922
+ import_v47.z.array(
1923
+ import_v47.z.object({
1924
+ type: import_v47.z.literal("web_search_result"),
1925
+ url: import_v47.z.string(),
1926
+ title: import_v47.z.string(),
1927
+ encrypted_content: import_v47.z.string(),
1928
+ page_age: import_v47.z.string().nullish()
1706
1929
  })
1707
1930
  ),
1708
- import_v45.z.object({
1709
- type: import_v45.z.literal("web_search_tool_result_error"),
1710
- error_code: import_v45.z.string()
1931
+ import_v47.z.object({
1932
+ type: import_v47.z.literal("web_search_tool_result_error"),
1933
+ error_code: import_v47.z.string()
1711
1934
  })
1712
1935
  ])
1713
1936
  }),
1714
- import_v45.z.object({
1715
- type: import_v45.z.literal("code_execution_tool_result"),
1716
- tool_use_id: import_v45.z.string(),
1717
- content: import_v45.z.union([
1718
- import_v45.z.object({
1719
- type: import_v45.z.literal("code_execution_result"),
1720
- stdout: import_v45.z.string(),
1721
- stderr: import_v45.z.string(),
1722
- return_code: import_v45.z.number()
1937
+ import_v47.z.object({
1938
+ type: import_v47.z.literal("code_execution_tool_result"),
1939
+ tool_use_id: import_v47.z.string(),
1940
+ content: import_v47.z.union([
1941
+ import_v47.z.object({
1942
+ type: import_v47.z.literal("code_execution_result"),
1943
+ stdout: import_v47.z.string(),
1944
+ stderr: import_v47.z.string(),
1945
+ return_code: import_v47.z.number()
1723
1946
  }),
1724
- import_v45.z.object({
1725
- type: import_v45.z.literal("code_execution_tool_result_error"),
1726
- error_code: import_v45.z.string()
1947
+ import_v47.z.object({
1948
+ type: import_v47.z.literal("code_execution_tool_result_error"),
1949
+ error_code: import_v47.z.string()
1727
1950
  })
1728
1951
  ])
1729
1952
  })
1730
1953
  ])
1731
1954
  ),
1732
- stop_reason: import_v45.z.string().nullish(),
1733
- usage: import_v45.z.looseObject({
1734
- input_tokens: import_v45.z.number(),
1735
- output_tokens: import_v45.z.number(),
1736
- cache_creation_input_tokens: import_v45.z.number().nullish(),
1737
- cache_read_input_tokens: import_v45.z.number().nullish()
1955
+ stop_reason: import_v47.z.string().nullish(),
1956
+ stop_sequence: import_v47.z.string().nullish(),
1957
+ usage: import_v47.z.looseObject({
1958
+ input_tokens: import_v47.z.number(),
1959
+ output_tokens: import_v47.z.number(),
1960
+ cache_creation_input_tokens: import_v47.z.number().nullish(),
1961
+ cache_read_input_tokens: import_v47.z.number().nullish()
1738
1962
  })
1739
1963
  });
1740
- var anthropicMessagesChunkSchema = import_v45.z.discriminatedUnion("type", [
1741
- import_v45.z.object({
1742
- type: import_v45.z.literal("message_start"),
1743
- message: import_v45.z.object({
1744
- id: import_v45.z.string().nullish(),
1745
- model: import_v45.z.string().nullish(),
1746
- usage: import_v45.z.looseObject({
1747
- input_tokens: import_v45.z.number(),
1748
- output_tokens: import_v45.z.number(),
1749
- cache_creation_input_tokens: import_v45.z.number().nullish(),
1750
- cache_read_input_tokens: import_v45.z.number().nullish()
1964
+ var anthropicMessagesChunkSchema = import_v47.z.discriminatedUnion("type", [
1965
+ import_v47.z.object({
1966
+ type: import_v47.z.literal("message_start"),
1967
+ message: import_v47.z.object({
1968
+ id: import_v47.z.string().nullish(),
1969
+ model: import_v47.z.string().nullish(),
1970
+ usage: import_v47.z.looseObject({
1971
+ input_tokens: import_v47.z.number(),
1972
+ cache_creation_input_tokens: import_v47.z.number().nullish(),
1973
+ cache_read_input_tokens: import_v47.z.number().nullish()
1751
1974
  })
1752
1975
  })
1753
1976
  }),
1754
- import_v45.z.object({
1755
- type: import_v45.z.literal("content_block_start"),
1756
- index: import_v45.z.number(),
1757
- content_block: import_v45.z.discriminatedUnion("type", [
1758
- import_v45.z.object({
1759
- type: import_v45.z.literal("text"),
1760
- text: import_v45.z.string()
1977
+ import_v47.z.object({
1978
+ type: import_v47.z.literal("content_block_start"),
1979
+ index: import_v47.z.number(),
1980
+ content_block: import_v47.z.discriminatedUnion("type", [
1981
+ import_v47.z.object({
1982
+ type: import_v47.z.literal("text"),
1983
+ text: import_v47.z.string()
1761
1984
  }),
1762
- import_v45.z.object({
1763
- type: import_v45.z.literal("thinking"),
1764
- thinking: import_v45.z.string()
1985
+ import_v47.z.object({
1986
+ type: import_v47.z.literal("thinking"),
1987
+ thinking: import_v47.z.string()
1765
1988
  }),
1766
- import_v45.z.object({
1767
- type: import_v45.z.literal("tool_use"),
1768
- id: import_v45.z.string(),
1769
- name: import_v45.z.string()
1989
+ import_v47.z.object({
1990
+ type: import_v47.z.literal("tool_use"),
1991
+ id: import_v47.z.string(),
1992
+ name: import_v47.z.string()
1770
1993
  }),
1771
- import_v45.z.object({
1772
- type: import_v45.z.literal("redacted_thinking"),
1773
- data: import_v45.z.string()
1994
+ import_v47.z.object({
1995
+ type: import_v47.z.literal("redacted_thinking"),
1996
+ data: import_v47.z.string()
1774
1997
  }),
1775
- import_v45.z.object({
1776
- type: import_v45.z.literal("server_tool_use"),
1777
- id: import_v45.z.string(),
1778
- name: import_v45.z.string(),
1779
- input: import_v45.z.record(import_v45.z.string(), import_v45.z.unknown()).nullish()
1998
+ import_v47.z.object({
1999
+ type: import_v47.z.literal("server_tool_use"),
2000
+ id: import_v47.z.string(),
2001
+ name: import_v47.z.string(),
2002
+ input: import_v47.z.record(import_v47.z.string(), import_v47.z.unknown()).nullish()
1780
2003
  }),
1781
- import_v45.z.object({
1782
- type: import_v45.z.literal("web_search_tool_result"),
1783
- tool_use_id: import_v45.z.string(),
1784
- content: import_v45.z.union([
1785
- import_v45.z.array(
1786
- import_v45.z.object({
1787
- type: import_v45.z.literal("web_search_result"),
1788
- url: import_v45.z.string(),
1789
- title: import_v45.z.string(),
1790
- encrypted_content: import_v45.z.string(),
1791
- page_age: import_v45.z.string().nullish()
2004
+ import_v47.z.object({
2005
+ type: import_v47.z.literal("web_fetch_tool_result"),
2006
+ tool_use_id: import_v47.z.string(),
2007
+ content: import_v47.z.union([
2008
+ import_v47.z.object({
2009
+ type: import_v47.z.literal("web_fetch_result"),
2010
+ url: import_v47.z.string(),
2011
+ retrieved_at: import_v47.z.string(),
2012
+ content: import_v47.z.object({
2013
+ type: import_v47.z.literal("document"),
2014
+ title: import_v47.z.string().nullable(),
2015
+ citations: import_v47.z.object({ enabled: import_v47.z.boolean() }).optional(),
2016
+ source: import_v47.z.object({
2017
+ type: import_v47.z.literal("text"),
2018
+ media_type: import_v47.z.string(),
2019
+ data: import_v47.z.string()
2020
+ })
2021
+ })
2022
+ }),
2023
+ import_v47.z.object({
2024
+ type: import_v47.z.literal("web_fetch_tool_result_error"),
2025
+ error_code: import_v47.z.string()
2026
+ })
2027
+ ])
2028
+ }),
2029
+ import_v47.z.object({
2030
+ type: import_v47.z.literal("web_search_tool_result"),
2031
+ tool_use_id: import_v47.z.string(),
2032
+ content: import_v47.z.union([
2033
+ import_v47.z.array(
2034
+ import_v47.z.object({
2035
+ type: import_v47.z.literal("web_search_result"),
2036
+ url: import_v47.z.string(),
2037
+ title: import_v47.z.string(),
2038
+ encrypted_content: import_v47.z.string(),
2039
+ page_age: import_v47.z.string().nullish()
1792
2040
  })
1793
2041
  ),
1794
- import_v45.z.object({
1795
- type: import_v45.z.literal("web_search_tool_result_error"),
1796
- error_code: import_v45.z.string()
2042
+ import_v47.z.object({
2043
+ type: import_v47.z.literal("web_search_tool_result_error"),
2044
+ error_code: import_v47.z.string()
1797
2045
  })
1798
2046
  ])
1799
2047
  }),
1800
- import_v45.z.object({
1801
- type: import_v45.z.literal("code_execution_tool_result"),
1802
- tool_use_id: import_v45.z.string(),
1803
- content: import_v45.z.union([
1804
- import_v45.z.object({
1805
- type: import_v45.z.literal("code_execution_result"),
1806
- stdout: import_v45.z.string(),
1807
- stderr: import_v45.z.string(),
1808
- return_code: import_v45.z.number()
2048
+ import_v47.z.object({
2049
+ type: import_v47.z.literal("code_execution_tool_result"),
2050
+ tool_use_id: import_v47.z.string(),
2051
+ content: import_v47.z.union([
2052
+ import_v47.z.object({
2053
+ type: import_v47.z.literal("code_execution_result"),
2054
+ stdout: import_v47.z.string(),
2055
+ stderr: import_v47.z.string(),
2056
+ return_code: import_v47.z.number()
1809
2057
  }),
1810
- import_v45.z.object({
1811
- type: import_v45.z.literal("code_execution_tool_result_error"),
1812
- error_code: import_v45.z.string()
2058
+ import_v47.z.object({
2059
+ type: import_v47.z.literal("code_execution_tool_result_error"),
2060
+ error_code: import_v47.z.string()
1813
2061
  })
1814
2062
  ])
1815
2063
  })
1816
2064
  ])
1817
2065
  }),
1818
- import_v45.z.object({
1819
- type: import_v45.z.literal("content_block_delta"),
1820
- index: import_v45.z.number(),
1821
- delta: import_v45.z.discriminatedUnion("type", [
1822
- import_v45.z.object({
1823
- type: import_v45.z.literal("input_json_delta"),
1824
- partial_json: import_v45.z.string()
2066
+ import_v47.z.object({
2067
+ type: import_v47.z.literal("content_block_delta"),
2068
+ index: import_v47.z.number(),
2069
+ delta: import_v47.z.discriminatedUnion("type", [
2070
+ import_v47.z.object({
2071
+ type: import_v47.z.literal("input_json_delta"),
2072
+ partial_json: import_v47.z.string()
1825
2073
  }),
1826
- import_v45.z.object({
1827
- type: import_v45.z.literal("text_delta"),
1828
- text: import_v45.z.string()
2074
+ import_v47.z.object({
2075
+ type: import_v47.z.literal("text_delta"),
2076
+ text: import_v47.z.string()
1829
2077
  }),
1830
- import_v45.z.object({
1831
- type: import_v45.z.literal("thinking_delta"),
1832
- thinking: import_v45.z.string()
2078
+ import_v47.z.object({
2079
+ type: import_v47.z.literal("thinking_delta"),
2080
+ thinking: import_v47.z.string()
1833
2081
  }),
1834
- import_v45.z.object({
1835
- type: import_v45.z.literal("signature_delta"),
1836
- signature: import_v45.z.string()
2082
+ import_v47.z.object({
2083
+ type: import_v47.z.literal("signature_delta"),
2084
+ signature: import_v47.z.string()
1837
2085
  }),
1838
- import_v45.z.object({
1839
- type: import_v45.z.literal("citations_delta"),
2086
+ import_v47.z.object({
2087
+ type: import_v47.z.literal("citations_delta"),
1840
2088
  citation: citationSchema
1841
2089
  })
1842
2090
  ])
1843
2091
  }),
1844
- import_v45.z.object({
1845
- type: import_v45.z.literal("content_block_stop"),
1846
- index: import_v45.z.number()
2092
+ import_v47.z.object({
2093
+ type: import_v47.z.literal("content_block_stop"),
2094
+ index: import_v47.z.number()
1847
2095
  }),
1848
- import_v45.z.object({
1849
- type: import_v45.z.literal("error"),
1850
- error: import_v45.z.object({
1851
- type: import_v45.z.string(),
1852
- message: import_v45.z.string()
2096
+ import_v47.z.object({
2097
+ type: import_v47.z.literal("error"),
2098
+ error: import_v47.z.object({
2099
+ type: import_v47.z.string(),
2100
+ message: import_v47.z.string()
1853
2101
  })
1854
2102
  }),
1855
- import_v45.z.object({
1856
- type: import_v45.z.literal("message_delta"),
1857
- delta: import_v45.z.object({ stop_reason: import_v45.z.string().nullish() }),
1858
- usage: import_v45.z.object({ output_tokens: import_v45.z.number() })
2103
+ import_v47.z.object({
2104
+ type: import_v47.z.literal("message_delta"),
2105
+ delta: import_v47.z.object({
2106
+ stop_reason: import_v47.z.string().nullish(),
2107
+ stop_sequence: import_v47.z.string().nullish()
2108
+ }),
2109
+ usage: import_v47.z.looseObject({
2110
+ output_tokens: import_v47.z.number(),
2111
+ cache_creation_input_tokens: import_v47.z.number().nullish()
2112
+ })
1859
2113
  }),
1860
- import_v45.z.object({
1861
- type: import_v45.z.literal("message_stop")
2114
+ import_v47.z.object({
2115
+ type: import_v47.z.literal("message_stop")
1862
2116
  }),
1863
- import_v45.z.object({
1864
- type: import_v45.z.literal("ping")
2117
+ import_v47.z.object({
2118
+ type: import_v47.z.literal("ping")
1865
2119
  })
1866
2120
  ]);
1867
- var anthropicReasoningMetadataSchema = import_v45.z.object({
1868
- signature: import_v45.z.string().optional(),
1869
- redactedData: import_v45.z.string().optional()
2121
+ var anthropicReasoningMetadataSchema = import_v47.z.object({
2122
+ signature: import_v47.z.string().optional(),
2123
+ redactedData: import_v47.z.string().optional()
1870
2124
  });
1871
2125
 
1872
2126
  // src/tool/bash_20241022.ts
1873
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
1874
- var import_v46 = __toESM(require("zod/v4"));
1875
- var bash_20241022 = (0, import_provider_utils6.createProviderDefinedToolFactory)({
2127
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
2128
+ var import_v48 = __toESM(require("zod/v4"));
2129
+ var bash_20241022 = (0, import_provider_utils8.createProviderDefinedToolFactory)({
1876
2130
  id: "anthropic.bash_20241022",
1877
2131
  name: "bash",
1878
- inputSchema: import_v46.default.object({
1879
- command: import_v46.default.string(),
1880
- restart: import_v46.default.boolean().optional()
2132
+ inputSchema: import_v48.default.object({
2133
+ command: import_v48.default.string(),
2134
+ restart: import_v48.default.boolean().optional()
1881
2135
  })
1882
2136
  });
1883
2137
 
1884
2138
  // src/tool/bash_20250124.ts
1885
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
1886
- var import_v47 = __toESM(require("zod/v4"));
1887
- var bash_20250124 = (0, import_provider_utils7.createProviderDefinedToolFactory)({
2139
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
2140
+ var import_v49 = __toESM(require("zod/v4"));
2141
+ var bash_20250124 = (0, import_provider_utils9.createProviderDefinedToolFactory)({
1888
2142
  id: "anthropic.bash_20250124",
1889
2143
  name: "bash",
1890
- inputSchema: import_v47.default.object({
1891
- command: import_v47.default.string(),
1892
- restart: import_v47.default.boolean().optional()
2144
+ inputSchema: import_v49.default.object({
2145
+ command: import_v49.default.string(),
2146
+ restart: import_v49.default.boolean().optional()
1893
2147
  })
1894
2148
  });
1895
2149
 
1896
2150
  // src/tool/computer_20241022.ts
1897
- var import_provider_utils8 = require("@ai-sdk/provider-utils");
1898
- var import_v48 = require("zod/v4");
1899
- var computer_20241022 = (0, import_provider_utils8.createProviderDefinedToolFactory)({
2151
+ var import_provider_utils10 = require("@ai-sdk/provider-utils");
2152
+ var import_v410 = require("zod/v4");
2153
+ var computer_20241022 = (0, import_provider_utils10.createProviderDefinedToolFactory)({
1900
2154
  id: "anthropic.computer_20241022",
1901
2155
  name: "computer",
1902
- inputSchema: import_v48.z.object({
1903
- action: import_v48.z.enum([
2156
+ inputSchema: import_v410.z.object({
2157
+ action: import_v410.z.enum([
1904
2158
  "key",
1905
2159
  "type",
1906
2160
  "mouse_move",
@@ -1912,19 +2166,19 @@ var computer_20241022 = (0, import_provider_utils8.createProviderDefinedToolFact
1912
2166
  "screenshot",
1913
2167
  "cursor_position"
1914
2168
  ]),
1915
- coordinate: import_v48.z.array(import_v48.z.number().int()).optional(),
1916
- text: import_v48.z.string().optional()
2169
+ coordinate: import_v410.z.array(import_v410.z.number().int()).optional(),
2170
+ text: import_v410.z.string().optional()
1917
2171
  })
1918
2172
  });
1919
2173
 
1920
2174
  // src/tool/computer_20250124.ts
1921
- var import_provider_utils9 = require("@ai-sdk/provider-utils");
1922
- var import_v49 = require("zod/v4");
1923
- var computer_20250124 = (0, import_provider_utils9.createProviderDefinedToolFactory)({
2175
+ var import_provider_utils11 = require("@ai-sdk/provider-utils");
2176
+ var import_v411 = require("zod/v4");
2177
+ var computer_20250124 = (0, import_provider_utils11.createProviderDefinedToolFactory)({
1924
2178
  id: "anthropic.computer_20250124",
1925
2179
  name: "computer",
1926
- inputSchema: import_v49.z.object({
1927
- action: import_v49.z.enum([
2180
+ inputSchema: import_v411.z.object({
2181
+ action: import_v411.z.enum([
1928
2182
  "key",
1929
2183
  "hold_key",
1930
2184
  "type",
@@ -1942,63 +2196,63 @@ var computer_20250124 = (0, import_provider_utils9.createProviderDefinedToolFact
1942
2196
  "wait",
1943
2197
  "screenshot"
1944
2198
  ]),
1945
- coordinate: import_v49.z.tuple([import_v49.z.number().int(), import_v49.z.number().int()]).optional(),
1946
- duration: import_v49.z.number().optional(),
1947
- scroll_amount: import_v49.z.number().optional(),
1948
- scroll_direction: import_v49.z.enum(["up", "down", "left", "right"]).optional(),
1949
- start_coordinate: import_v49.z.tuple([import_v49.z.number().int(), import_v49.z.number().int()]).optional(),
1950
- text: import_v49.z.string().optional()
2199
+ coordinate: import_v411.z.tuple([import_v411.z.number().int(), import_v411.z.number().int()]).optional(),
2200
+ duration: import_v411.z.number().optional(),
2201
+ scroll_amount: import_v411.z.number().optional(),
2202
+ scroll_direction: import_v411.z.enum(["up", "down", "left", "right"]).optional(),
2203
+ start_coordinate: import_v411.z.tuple([import_v411.z.number().int(), import_v411.z.number().int()]).optional(),
2204
+ text: import_v411.z.string().optional()
1951
2205
  })
1952
2206
  });
1953
2207
 
1954
2208
  // src/tool/text-editor_20241022.ts
1955
- var import_provider_utils10 = require("@ai-sdk/provider-utils");
1956
- var import_v410 = require("zod/v4");
1957
- var textEditor_20241022 = (0, import_provider_utils10.createProviderDefinedToolFactory)({
2209
+ var import_provider_utils12 = require("@ai-sdk/provider-utils");
2210
+ var import_v412 = require("zod/v4");
2211
+ var textEditor_20241022 = (0, import_provider_utils12.createProviderDefinedToolFactory)({
1958
2212
  id: "anthropic.text_editor_20241022",
1959
2213
  name: "str_replace_editor",
1960
- inputSchema: import_v410.z.object({
1961
- command: import_v410.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1962
- path: import_v410.z.string(),
1963
- file_text: import_v410.z.string().optional(),
1964
- insert_line: import_v410.z.number().int().optional(),
1965
- new_str: import_v410.z.string().optional(),
1966
- old_str: import_v410.z.string().optional(),
1967
- view_range: import_v410.z.array(import_v410.z.number().int()).optional()
2214
+ inputSchema: import_v412.z.object({
2215
+ command: import_v412.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
2216
+ path: import_v412.z.string(),
2217
+ file_text: import_v412.z.string().optional(),
2218
+ insert_line: import_v412.z.number().int().optional(),
2219
+ new_str: import_v412.z.string().optional(),
2220
+ old_str: import_v412.z.string().optional(),
2221
+ view_range: import_v412.z.array(import_v412.z.number().int()).optional()
1968
2222
  })
1969
2223
  });
1970
2224
 
1971
2225
  // src/tool/text-editor_20250124.ts
1972
- var import_provider_utils11 = require("@ai-sdk/provider-utils");
1973
- var import_v411 = require("zod/v4");
1974
- var textEditor_20250124 = (0, import_provider_utils11.createProviderDefinedToolFactory)({
2226
+ var import_provider_utils13 = require("@ai-sdk/provider-utils");
2227
+ var import_v413 = require("zod/v4");
2228
+ var textEditor_20250124 = (0, import_provider_utils13.createProviderDefinedToolFactory)({
1975
2229
  id: "anthropic.text_editor_20250124",
1976
2230
  name: "str_replace_editor",
1977
- inputSchema: import_v411.z.object({
1978
- command: import_v411.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1979
- path: import_v411.z.string(),
1980
- file_text: import_v411.z.string().optional(),
1981
- insert_line: import_v411.z.number().int().optional(),
1982
- new_str: import_v411.z.string().optional(),
1983
- old_str: import_v411.z.string().optional(),
1984
- view_range: import_v411.z.array(import_v411.z.number().int()).optional()
2231
+ inputSchema: import_v413.z.object({
2232
+ command: import_v413.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
2233
+ path: import_v413.z.string(),
2234
+ file_text: import_v413.z.string().optional(),
2235
+ insert_line: import_v413.z.number().int().optional(),
2236
+ new_str: import_v413.z.string().optional(),
2237
+ old_str: import_v413.z.string().optional(),
2238
+ view_range: import_v413.z.array(import_v413.z.number().int()).optional()
1985
2239
  })
1986
2240
  });
1987
2241
 
1988
2242
  // src/tool/text-editor_20250429.ts
1989
- var import_provider_utils12 = require("@ai-sdk/provider-utils");
1990
- var import_v412 = require("zod/v4");
1991
- var textEditor_20250429 = (0, import_provider_utils12.createProviderDefinedToolFactory)({
2243
+ var import_provider_utils14 = require("@ai-sdk/provider-utils");
2244
+ var import_v414 = require("zod/v4");
2245
+ var textEditor_20250429 = (0, import_provider_utils14.createProviderDefinedToolFactory)({
1992
2246
  id: "anthropic.text_editor_20250429",
1993
2247
  name: "str_replace_based_edit_tool",
1994
- inputSchema: import_v412.z.object({
1995
- command: import_v412.z.enum(["view", "create", "str_replace", "insert"]),
1996
- path: import_v412.z.string(),
1997
- file_text: import_v412.z.string().optional(),
1998
- insert_line: import_v412.z.number().int().optional(),
1999
- new_str: import_v412.z.string().optional(),
2000
- old_str: import_v412.z.string().optional(),
2001
- view_range: import_v412.z.array(import_v412.z.number().int()).optional()
2248
+ inputSchema: import_v414.z.object({
2249
+ command: import_v414.z.enum(["view", "create", "str_replace", "insert"]),
2250
+ path: import_v414.z.string(),
2251
+ file_text: import_v414.z.string().optional(),
2252
+ insert_line: import_v414.z.number().int().optional(),
2253
+ new_str: import_v414.z.string().optional(),
2254
+ old_str: import_v414.z.string().optional(),
2255
+ view_range: import_v414.z.array(import_v414.z.number().int()).optional()
2002
2256
  })
2003
2257
  });
2004
2258
 
@@ -2064,6 +2318,8 @@ var anthropicTools = {
2064
2318
  * helping you debug, fix, and improve your code or other text documents. This allows Claude
2065
2319
  * to directly interact with your files, providing hands-on assistance rather than just suggesting changes.
2066
2320
  *
2321
+ * Supported models: Claude Sonnet 3.5
2322
+ *
2067
2323
  * Tool name must be `str_replace_editor`.
2068
2324
  */
2069
2325
  textEditor_20241022,
@@ -2072,6 +2328,8 @@ var anthropicTools = {
2072
2328
  * helping you debug, fix, and improve your code or other text documents. This allows Claude
2073
2329
  * to directly interact with your files, providing hands-on assistance rather than just suggesting changes.
2074
2330
  *
2331
+ * Supported models: Claude Sonnet 3.7
2332
+ *
2075
2333
  * Tool name must be `str_replace_editor`.
2076
2334
  */
2077
2335
  textEditor_20250124,
@@ -2083,8 +2341,36 @@ var anthropicTools = {
2083
2341
  * Note: This version does not support the "undo_edit" command.
2084
2342
  *
2085
2343
  * Tool name must be `str_replace_based_edit_tool`.
2344
+ *
2345
+ * @deprecated Use textEditor_20250728 instead
2086
2346
  */
2087
2347
  textEditor_20250429,
2348
+ /**
2349
+ * Claude can use an Anthropic-defined text editor tool to view and modify text files,
2350
+ * helping you debug, fix, and improve your code or other text documents. This allows Claude
2351
+ * to directly interact with your files, providing hands-on assistance rather than just suggesting changes.
2352
+ *
2353
+ * Note: This version does not support the "undo_edit" command and adds optional max_characters parameter.
2354
+ *
2355
+ * Supported models: Claude Sonnet 4, Opus 4, and Opus 4.1
2356
+ *
2357
+ * Tool name must be `str_replace_based_edit_tool`.
2358
+ *
2359
+ * @param maxCharacters - Optional maximum number of characters to view in the file
2360
+ */
2361
+ textEditor_20250728,
2362
+ /**
2363
+ * Creates a web fetch tool that gives Claude direct access to real-time web content.
2364
+ *
2365
+ * Tool name must be `web_fetch`.
2366
+ *
2367
+ * @param maxUses - The max_uses parameter limits the number of web fetches performed
2368
+ * @param allowedDomains - Only fetch from these domains
2369
+ * @param blockedDomains - Never fetch from these domains
2370
+ * @param citations - Unlike web search where citations are always enabled, citations are optional for web fetch. Set "citations": {"enabled": true} to enable Claude to cite specific passages from fetched documents.
2371
+ * @param maxContentTokens - The max_content_tokens parameter limits the amount of content that will be included in the context.
2372
+ */
2373
+ webFetch_20250910,
2088
2374
  /**
2089
2375
  * Creates a web search tool that gives Claude direct access to real-time web content.
2090
2376
  *
@@ -2101,16 +2387,19 @@ var anthropicTools = {
2101
2387
  // src/anthropic-provider.ts
2102
2388
  function createAnthropic(options = {}) {
2103
2389
  var _a;
2104
- const baseURL = (_a = (0, import_provider_utils13.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.anthropic.com/v1";
2105
- const getHeaders = () => ({
2106
- "anthropic-version": "2023-06-01",
2107
- "x-api-key": (0, import_provider_utils13.loadApiKey)({
2108
- apiKey: options.apiKey,
2109
- environmentVariableName: "ANTHROPIC_API_KEY",
2110
- description: "Anthropic"
2111
- }),
2112
- ...options.headers
2113
- });
2390
+ const baseURL = (_a = (0, import_provider_utils15.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.anthropic.com/v1";
2391
+ const getHeaders = () => (0, import_provider_utils15.withUserAgentSuffix)(
2392
+ {
2393
+ "anthropic-version": "2023-06-01",
2394
+ "x-api-key": (0, import_provider_utils15.loadApiKey)({
2395
+ apiKey: options.apiKey,
2396
+ environmentVariableName: "ANTHROPIC_API_KEY",
2397
+ description: "Anthropic"
2398
+ }),
2399
+ ...options.headers
2400
+ },
2401
+ `ai-sdk/anthropic/${VERSION}`
2402
+ );
2114
2403
  const createChatModel = (modelId) => {
2115
2404
  var _a2;
2116
2405
  return new AnthropicMessagesLanguageModel(modelId, {
@@ -2118,7 +2407,7 @@ function createAnthropic(options = {}) {
2118
2407
  baseURL,
2119
2408
  headers: getHeaders,
2120
2409
  fetch: options.fetch,
2121
- generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils13.generateId,
2410
+ generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils15.generateId,
2122
2411
  supportedUrls: () => ({
2123
2412
  "image/*": [/^https?:\/\/.*$/]
2124
2413
  })
@@ -2147,6 +2436,7 @@ function createAnthropic(options = {}) {
2147
2436
  var anthropic = createAnthropic();
2148
2437
  // Annotate the CommonJS export names for ESM import in node:
2149
2438
  0 && (module.exports = {
2439
+ VERSION,
2150
2440
  anthropic,
2151
2441
  createAnthropic
2152
2442
  });