@ai-sdk/anthropic 2.0.3 → 2.0.4

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
@@ -37,12 +37,12 @@ module.exports = __toCommonJS(src_exports);
37
37
 
38
38
  // src/anthropic-provider.ts
39
39
  var import_provider4 = require("@ai-sdk/provider");
40
- var import_provider_utils12 = require("@ai-sdk/provider-utils");
40
+ var import_provider_utils13 = require("@ai-sdk/provider-utils");
41
41
 
42
42
  // src/anthropic-messages-language-model.ts
43
43
  var import_provider3 = require("@ai-sdk/provider");
44
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
45
- var import_v44 = require("zod/v4");
44
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
45
+ var import_v45 = require("zod/v4");
46
46
 
47
47
  // src/anthropic-error.ts
48
48
  var import_provider_utils = require("@ai-sdk/provider-utils");
@@ -256,6 +256,14 @@ function prepareTools({
256
256
  });
257
257
  break;
258
258
  }
259
+ case "anthropic.code_execution_20250522": {
260
+ betas.add("code-execution-2025-05-22");
261
+ anthropicTools2.push({
262
+ type: "code_execution_20250522",
263
+ name: "code_execution"
264
+ });
265
+ break;
266
+ }
259
267
  default:
260
268
  toolWarnings.push({ type: "unsupported-tool", tool });
261
269
  break;
@@ -320,7 +328,30 @@ function prepareTools({
320
328
 
321
329
  // src/convert-to-anthropic-messages-prompt.ts
322
330
  var import_provider2 = require("@ai-sdk/provider");
331
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
332
+
333
+ // src/tool/code-execution_20250522.ts
323
334
  var import_provider_utils3 = require("@ai-sdk/provider-utils");
335
+ var import_v44 = require("zod/v4");
336
+ var codeExecution_20250522OutputSchema = import_v44.z.object({
337
+ type: import_v44.z.literal("code_execution_result"),
338
+ stdout: import_v44.z.string(),
339
+ stderr: import_v44.z.string(),
340
+ return_code: import_v44.z.number()
341
+ });
342
+ var factory2 = (0, import_provider_utils3.createProviderDefinedToolFactoryWithOutputSchema)({
343
+ id: "anthropic.code_execution_20250522",
344
+ name: "code_execution",
345
+ inputSchema: import_v44.z.object({
346
+ code: import_v44.z.string()
347
+ }),
348
+ outputSchema: codeExecution_20250522OutputSchema
349
+ });
350
+ var codeExecution_20250522 = (args = {}) => {
351
+ return factory2(args);
352
+ };
353
+
354
+ // src/convert-to-anthropic-messages-prompt.ts
324
355
  function convertToString(data) {
325
356
  if (typeof data === "string") {
326
357
  return Buffer.from(data, "base64").toString("utf-8");
@@ -349,7 +380,7 @@ async function convertToAnthropicMessagesPrompt({
349
380
  const messages = [];
350
381
  async function shouldEnableCitations(providerMetadata) {
351
382
  var _a2, _b2;
352
- const anthropicOptions = await (0, import_provider_utils3.parseProviderOptions)({
383
+ const anthropicOptions = await (0, import_provider_utils4.parseProviderOptions)({
353
384
  provider: "anthropic",
354
385
  providerOptions: providerMetadata,
355
386
  schema: anthropicFilePartProviderOptions
@@ -357,7 +388,7 @@ async function convertToAnthropicMessagesPrompt({
357
388
  return (_b2 = (_a2 = anthropicOptions == null ? void 0 : anthropicOptions.citations) == null ? void 0 : _a2.enabled) != null ? _b2 : false;
358
389
  }
359
390
  async function getDocumentMetadata(providerMetadata) {
360
- const anthropicOptions = await (0, import_provider_utils3.parseProviderOptions)({
391
+ const anthropicOptions = await (0, import_provider_utils4.parseProviderOptions)({
361
392
  provider: "anthropic",
362
393
  providerOptions: providerMetadata,
363
394
  schema: anthropicFilePartProviderOptions
@@ -414,7 +445,7 @@ async function convertToAnthropicMessagesPrompt({
414
445
  } : {
415
446
  type: "base64",
416
447
  media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
417
- data: (0, import_provider_utils3.convertToBase64)(part.data)
448
+ data: (0, import_provider_utils4.convertToBase64)(part.data)
418
449
  },
419
450
  cache_control: cacheControl
420
451
  });
@@ -434,7 +465,7 @@ async function convertToAnthropicMessagesPrompt({
434
465
  } : {
435
466
  type: "base64",
436
467
  media_type: "application/pdf",
437
- data: (0, import_provider_utils3.convertToBase64)(part.data)
468
+ data: (0, import_provider_utils4.convertToBase64)(part.data)
438
469
  },
439
470
  title: (_b = metadata.title) != null ? _b : part.filename,
440
471
  ...metadata.context && { context: metadata.context },
@@ -569,7 +600,7 @@ async function convertToAnthropicMessagesPrompt({
569
600
  }
570
601
  case "reasoning": {
571
602
  if (sendReasoning) {
572
- const reasoningMetadata = await (0, import_provider_utils3.parseProviderOptions)({
603
+ const reasoningMetadata = await (0, import_provider_utils4.parseProviderOptions)({
573
604
  provider: "anthropic",
574
605
  providerOptions: part.providerOptions,
575
606
  schema: anthropicReasoningMetadataSchema
@@ -620,6 +651,16 @@ async function convertToAnthropicMessagesPrompt({
620
651
  });
621
652
  break;
622
653
  }
654
+ if (part.toolName === "code_execution") {
655
+ anthropicContent.push({
656
+ type: "server_tool_use",
657
+ id: part.toolCallId,
658
+ name: "code_execution",
659
+ input: part.input,
660
+ cache_control: cacheControl
661
+ });
662
+ break;
663
+ }
623
664
  warnings.push({
624
665
  type: "other",
625
666
  message: `provider executed tool call for tool ${part.toolName} is not supported`
@@ -662,6 +703,29 @@ async function convertToAnthropicMessagesPrompt({
662
703
  });
663
704
  break;
664
705
  }
706
+ if (part.toolName === "code_execution") {
707
+ const output = part.output;
708
+ if (output.type !== "json") {
709
+ warnings.push({
710
+ type: "other",
711
+ message: `provider executed tool result output type ${output.type} for tool ${part.toolName} is not supported`
712
+ });
713
+ break;
714
+ }
715
+ const codeExecutionOutput = codeExecution_20250522OutputSchema.parse(output.value);
716
+ anthropicContent.push({
717
+ type: "code_execution_tool_result",
718
+ tool_use_id: part.toolCallId,
719
+ content: {
720
+ type: codeExecutionOutput.type,
721
+ stdout: codeExecutionOutput.stdout,
722
+ stderr: codeExecutionOutput.stderr,
723
+ return_code: codeExecutionOutput.return_code
724
+ },
725
+ cache_control: cacheControl
726
+ });
727
+ break;
728
+ }
665
729
  warnings.push({
666
730
  type: "other",
667
731
  message: `provider executed tool result for tool ${part.toolName} is not supported`
@@ -752,36 +816,36 @@ function mapAnthropicStopReason({
752
816
 
753
817
  // src/anthropic-messages-language-model.ts
754
818
  var citationSchemas = {
755
- webSearchResult: import_v44.z.object({
756
- type: import_v44.z.literal("web_search_result_location"),
757
- cited_text: import_v44.z.string(),
758
- url: import_v44.z.string(),
759
- title: import_v44.z.string(),
760
- encrypted_index: import_v44.z.string()
819
+ webSearchResult: import_v45.z.object({
820
+ type: import_v45.z.literal("web_search_result_location"),
821
+ cited_text: import_v45.z.string(),
822
+ url: import_v45.z.string(),
823
+ title: import_v45.z.string(),
824
+ encrypted_index: import_v45.z.string()
761
825
  }),
762
- pageLocation: import_v44.z.object({
763
- type: import_v44.z.literal("page_location"),
764
- cited_text: import_v44.z.string(),
765
- document_index: import_v44.z.number(),
766
- document_title: import_v44.z.string().nullable(),
767
- start_page_number: import_v44.z.number(),
768
- end_page_number: import_v44.z.number()
826
+ pageLocation: import_v45.z.object({
827
+ type: import_v45.z.literal("page_location"),
828
+ cited_text: import_v45.z.string(),
829
+ document_index: import_v45.z.number(),
830
+ document_title: import_v45.z.string().nullable(),
831
+ start_page_number: import_v45.z.number(),
832
+ end_page_number: import_v45.z.number()
769
833
  }),
770
- charLocation: import_v44.z.object({
771
- type: import_v44.z.literal("char_location"),
772
- cited_text: import_v44.z.string(),
773
- document_index: import_v44.z.number(),
774
- document_title: import_v44.z.string().nullable(),
775
- start_char_index: import_v44.z.number(),
776
- end_char_index: import_v44.z.number()
834
+ charLocation: import_v45.z.object({
835
+ type: import_v45.z.literal("char_location"),
836
+ cited_text: import_v45.z.string(),
837
+ document_index: import_v45.z.number(),
838
+ document_title: import_v45.z.string().nullable(),
839
+ start_char_index: import_v45.z.number(),
840
+ end_char_index: import_v45.z.number()
777
841
  })
778
842
  };
779
- var citationSchema = import_v44.z.discriminatedUnion("type", [
843
+ var citationSchema = import_v45.z.discriminatedUnion("type", [
780
844
  citationSchemas.webSearchResult,
781
845
  citationSchemas.pageLocation,
782
846
  citationSchemas.charLocation
783
847
  ]);
784
- var documentCitationSchema = import_v44.z.discriminatedUnion("type", [
848
+ var documentCitationSchema = import_v45.z.discriminatedUnion("type", [
785
849
  citationSchemas.pageLocation,
786
850
  citationSchemas.charLocation
787
851
  ]);
@@ -830,7 +894,7 @@ var AnthropicMessagesLanguageModel = class {
830
894
  var _a;
831
895
  this.modelId = modelId;
832
896
  this.config = config;
833
- this.generateId = (_a = config.generateId) != null ? _a : import_provider_utils4.generateId;
897
+ this.generateId = (_a = config.generateId) != null ? _a : import_provider_utils5.generateId;
834
898
  }
835
899
  supportsUrl(url) {
836
900
  return url.protocol === "https:";
@@ -899,7 +963,7 @@ var AnthropicMessagesLanguageModel = class {
899
963
  description: "Respond with a JSON object.",
900
964
  inputSchema: responseFormat.schema
901
965
  } : void 0;
902
- const anthropicOptions = await (0, import_provider_utils4.parseProviderOptions)({
966
+ const anthropicOptions = await (0, import_provider_utils5.parseProviderOptions)({
903
967
  provider: "anthropic",
904
968
  providerOptions,
905
969
  schema: anthropicProviderOptions
@@ -991,8 +1055,8 @@ var AnthropicMessagesLanguageModel = class {
991
1055
  betas,
992
1056
  headers
993
1057
  }) {
994
- return (0, import_provider_utils4.combineHeaders)(
995
- await (0, import_provider_utils4.resolve)(this.config.headers),
1058
+ return (0, import_provider_utils5.combineHeaders)(
1059
+ await (0, import_provider_utils5.resolve)(this.config.headers),
996
1060
  betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {},
997
1061
  headers
998
1062
  );
@@ -1036,12 +1100,12 @@ var AnthropicMessagesLanguageModel = class {
1036
1100
  responseHeaders,
1037
1101
  value: response,
1038
1102
  rawValue: rawResponse
1039
- } = await (0, import_provider_utils4.postJsonToApi)({
1103
+ } = await (0, import_provider_utils5.postJsonToApi)({
1040
1104
  url: this.buildRequestUrl(false),
1041
1105
  headers: await this.getHeaders({ betas, headers: options.headers }),
1042
1106
  body: this.transformRequestBody(args),
1043
1107
  failedResponseHandler: anthropicFailedResponseHandler,
1044
- successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
1108
+ successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
1045
1109
  anthropicMessagesResponseSchema
1046
1110
  ),
1047
1111
  abortSignal: options.abortSignal,
@@ -1106,7 +1170,7 @@ var AnthropicMessagesLanguageModel = class {
1106
1170
  break;
1107
1171
  }
1108
1172
  case "server_tool_use": {
1109
- if (part.name === "web_search") {
1173
+ if (part.name === "web_search" || part.name === "code_execution") {
1110
1174
  content.push({
1111
1175
  type: "tool-call",
1112
1176
  toolCallId: part.id,
@@ -1164,6 +1228,35 @@ var AnthropicMessagesLanguageModel = class {
1164
1228
  }
1165
1229
  break;
1166
1230
  }
1231
+ case "code_execution_tool_result": {
1232
+ if (part.content.type === "code_execution_result") {
1233
+ content.push({
1234
+ type: "tool-result",
1235
+ toolCallId: part.tool_use_id,
1236
+ toolName: "code_execution",
1237
+ result: {
1238
+ type: part.content.type,
1239
+ stdout: part.content.stdout,
1240
+ stderr: part.content.stderr,
1241
+ return_code: part.content.return_code
1242
+ },
1243
+ providerExecuted: true
1244
+ });
1245
+ } else if (part.content.type === "code_execution_tool_result_error") {
1246
+ content.push({
1247
+ type: "tool-result",
1248
+ toolCallId: part.tool_use_id,
1249
+ toolName: "code_execution",
1250
+ isError: true,
1251
+ result: {
1252
+ type: "code_execution_tool_result_error",
1253
+ errorCode: part.content.error_code
1254
+ },
1255
+ providerExecuted: true
1256
+ });
1257
+ }
1258
+ break;
1259
+ }
1167
1260
  }
1168
1261
  }
1169
1262
  return {
@@ -1198,12 +1291,12 @@ var AnthropicMessagesLanguageModel = class {
1198
1291
  const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
1199
1292
  const citationDocuments = this.extractCitationDocuments(options.prompt);
1200
1293
  const body = { ...args, stream: true };
1201
- const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
1294
+ const { responseHeaders, value: response } = await (0, import_provider_utils5.postJsonToApi)({
1202
1295
  url: this.buildRequestUrl(true),
1203
1296
  headers: await this.getHeaders({ betas, headers: options.headers }),
1204
1297
  body: this.transformRequestBody(body),
1205
1298
  failedResponseHandler: anthropicFailedResponseHandler,
1206
- successfulResponseHandler: (0, import_provider_utils4.createEventSourceResponseHandler)(
1299
+ successfulResponseHandler: (0, import_provider_utils5.createEventSourceResponseHandler)(
1207
1300
  anthropicMessagesChunkSchema
1208
1301
  ),
1209
1302
  abortSignal: options.abortSignal,
@@ -1289,7 +1382,7 @@ var AnthropicMessagesLanguageModel = class {
1289
1382
  return;
1290
1383
  }
1291
1384
  case "server_tool_use": {
1292
- if (value.content_block.name === "web_search") {
1385
+ if (value.content_block.name === "web_search" || value.content_block.name === "code_execution") {
1293
1386
  contentBlocks[value.index] = {
1294
1387
  type: "tool-call",
1295
1388
  toolCallId: value.content_block.id,
@@ -1354,6 +1447,36 @@ var AnthropicMessagesLanguageModel = class {
1354
1447
  }
1355
1448
  return;
1356
1449
  }
1450
+ case "code_execution_tool_result": {
1451
+ const part = value.content_block;
1452
+ if (part.content.type === "code_execution_result") {
1453
+ controller.enqueue({
1454
+ type: "tool-result",
1455
+ toolCallId: part.tool_use_id,
1456
+ toolName: "code_execution",
1457
+ result: {
1458
+ type: part.content.type,
1459
+ stdout: part.content.stdout,
1460
+ stderr: part.content.stderr,
1461
+ return_code: part.content.return_code
1462
+ },
1463
+ providerExecuted: true
1464
+ });
1465
+ } else if (part.content.type === "code_execution_tool_result_error") {
1466
+ controller.enqueue({
1467
+ type: "tool-result",
1468
+ toolCallId: part.tool_use_id,
1469
+ toolName: "code_execution",
1470
+ isError: true,
1471
+ result: {
1472
+ type: "code_execution_tool_result_error",
1473
+ errorCode: part.content.error_code
1474
+ },
1475
+ providerExecuted: true
1476
+ });
1477
+ }
1478
+ return;
1479
+ }
1357
1480
  default: {
1358
1481
  const _exhaustiveCheck = contentBlockType;
1359
1482
  throw new Error(
@@ -1526,215 +1649,247 @@ var AnthropicMessagesLanguageModel = class {
1526
1649
  };
1527
1650
  }
1528
1651
  };
1529
- var anthropicMessagesResponseSchema = import_v44.z.object({
1530
- type: import_v44.z.literal("message"),
1531
- id: import_v44.z.string().nullish(),
1532
- model: import_v44.z.string().nullish(),
1533
- content: import_v44.z.array(
1534
- import_v44.z.discriminatedUnion("type", [
1535
- import_v44.z.object({
1536
- type: import_v44.z.literal("text"),
1537
- text: import_v44.z.string(),
1538
- citations: import_v44.z.array(citationSchema).optional()
1652
+ var anthropicMessagesResponseSchema = import_v45.z.object({
1653
+ type: import_v45.z.literal("message"),
1654
+ id: import_v45.z.string().nullish(),
1655
+ model: import_v45.z.string().nullish(),
1656
+ content: import_v45.z.array(
1657
+ import_v45.z.discriminatedUnion("type", [
1658
+ import_v45.z.object({
1659
+ type: import_v45.z.literal("text"),
1660
+ text: import_v45.z.string(),
1661
+ citations: import_v45.z.array(citationSchema).optional()
1539
1662
  }),
1540
- import_v44.z.object({
1541
- type: import_v44.z.literal("thinking"),
1542
- thinking: import_v44.z.string(),
1543
- signature: import_v44.z.string()
1663
+ import_v45.z.object({
1664
+ type: import_v45.z.literal("thinking"),
1665
+ thinking: import_v45.z.string(),
1666
+ signature: import_v45.z.string()
1544
1667
  }),
1545
- import_v44.z.object({
1546
- type: import_v44.z.literal("redacted_thinking"),
1547
- data: import_v44.z.string()
1668
+ import_v45.z.object({
1669
+ type: import_v45.z.literal("redacted_thinking"),
1670
+ data: import_v45.z.string()
1548
1671
  }),
1549
- import_v44.z.object({
1550
- type: import_v44.z.literal("tool_use"),
1551
- id: import_v44.z.string(),
1552
- name: import_v44.z.string(),
1553
- input: import_v44.z.unknown()
1672
+ import_v45.z.object({
1673
+ type: import_v45.z.literal("tool_use"),
1674
+ id: import_v45.z.string(),
1675
+ name: import_v45.z.string(),
1676
+ input: import_v45.z.unknown()
1554
1677
  }),
1555
- import_v44.z.object({
1556
- type: import_v44.z.literal("server_tool_use"),
1557
- id: import_v44.z.string(),
1558
- name: import_v44.z.string(),
1559
- input: import_v44.z.record(import_v44.z.string(), import_v44.z.unknown()).nullish()
1678
+ import_v45.z.object({
1679
+ type: import_v45.z.literal("server_tool_use"),
1680
+ id: import_v45.z.string(),
1681
+ name: import_v45.z.string(),
1682
+ input: import_v45.z.record(import_v45.z.string(), import_v45.z.unknown()).nullish()
1560
1683
  }),
1561
- import_v44.z.object({
1562
- type: import_v44.z.literal("web_search_tool_result"),
1563
- tool_use_id: import_v44.z.string(),
1564
- content: import_v44.z.union([
1565
- import_v44.z.array(
1566
- import_v44.z.object({
1567
- type: import_v44.z.literal("web_search_result"),
1568
- url: import_v44.z.string(),
1569
- title: import_v44.z.string(),
1570
- encrypted_content: import_v44.z.string(),
1571
- page_age: import_v44.z.string().nullish()
1684
+ import_v45.z.object({
1685
+ type: import_v45.z.literal("web_search_tool_result"),
1686
+ tool_use_id: import_v45.z.string(),
1687
+ content: import_v45.z.union([
1688
+ import_v45.z.array(
1689
+ import_v45.z.object({
1690
+ type: import_v45.z.literal("web_search_result"),
1691
+ url: import_v45.z.string(),
1692
+ title: import_v45.z.string(),
1693
+ encrypted_content: import_v45.z.string(),
1694
+ page_age: import_v45.z.string().nullish()
1572
1695
  })
1573
1696
  ),
1574
- import_v44.z.object({
1575
- type: import_v44.z.literal("web_search_tool_result_error"),
1576
- error_code: import_v44.z.string()
1697
+ import_v45.z.object({
1698
+ type: import_v45.z.literal("web_search_tool_result_error"),
1699
+ error_code: import_v45.z.string()
1700
+ })
1701
+ ])
1702
+ }),
1703
+ import_v45.z.object({
1704
+ type: import_v45.z.literal("code_execution_tool_result"),
1705
+ tool_use_id: import_v45.z.string(),
1706
+ content: import_v45.z.union([
1707
+ import_v45.z.object({
1708
+ type: import_v45.z.literal("code_execution_result"),
1709
+ stdout: import_v45.z.string(),
1710
+ stderr: import_v45.z.string(),
1711
+ return_code: import_v45.z.number()
1712
+ }),
1713
+ import_v45.z.object({
1714
+ type: import_v45.z.literal("code_execution_tool_result_error"),
1715
+ error_code: import_v45.z.string()
1577
1716
  })
1578
1717
  ])
1579
1718
  })
1580
1719
  ])
1581
1720
  ),
1582
- stop_reason: import_v44.z.string().nullish(),
1583
- usage: import_v44.z.looseObject({
1584
- input_tokens: import_v44.z.number(),
1585
- output_tokens: import_v44.z.number(),
1586
- cache_creation_input_tokens: import_v44.z.number().nullish(),
1587
- cache_read_input_tokens: import_v44.z.number().nullish()
1721
+ stop_reason: import_v45.z.string().nullish(),
1722
+ usage: import_v45.z.looseObject({
1723
+ input_tokens: import_v45.z.number(),
1724
+ output_tokens: import_v45.z.number(),
1725
+ cache_creation_input_tokens: import_v45.z.number().nullish(),
1726
+ cache_read_input_tokens: import_v45.z.number().nullish()
1588
1727
  })
1589
1728
  });
1590
- var anthropicMessagesChunkSchema = import_v44.z.discriminatedUnion("type", [
1591
- import_v44.z.object({
1592
- type: import_v44.z.literal("message_start"),
1593
- message: import_v44.z.object({
1594
- id: import_v44.z.string().nullish(),
1595
- model: import_v44.z.string().nullish(),
1596
- usage: import_v44.z.looseObject({
1597
- input_tokens: import_v44.z.number(),
1598
- output_tokens: import_v44.z.number(),
1599
- cache_creation_input_tokens: import_v44.z.number().nullish(),
1600
- cache_read_input_tokens: import_v44.z.number().nullish()
1729
+ var anthropicMessagesChunkSchema = import_v45.z.discriminatedUnion("type", [
1730
+ import_v45.z.object({
1731
+ type: import_v45.z.literal("message_start"),
1732
+ message: import_v45.z.object({
1733
+ id: import_v45.z.string().nullish(),
1734
+ model: import_v45.z.string().nullish(),
1735
+ usage: import_v45.z.looseObject({
1736
+ input_tokens: import_v45.z.number(),
1737
+ output_tokens: import_v45.z.number(),
1738
+ cache_creation_input_tokens: import_v45.z.number().nullish(),
1739
+ cache_read_input_tokens: import_v45.z.number().nullish()
1601
1740
  })
1602
1741
  })
1603
1742
  }),
1604
- import_v44.z.object({
1605
- type: import_v44.z.literal("content_block_start"),
1606
- index: import_v44.z.number(),
1607
- content_block: import_v44.z.discriminatedUnion("type", [
1608
- import_v44.z.object({
1609
- type: import_v44.z.literal("text"),
1610
- text: import_v44.z.string()
1743
+ import_v45.z.object({
1744
+ type: import_v45.z.literal("content_block_start"),
1745
+ index: import_v45.z.number(),
1746
+ content_block: import_v45.z.discriminatedUnion("type", [
1747
+ import_v45.z.object({
1748
+ type: import_v45.z.literal("text"),
1749
+ text: import_v45.z.string()
1611
1750
  }),
1612
- import_v44.z.object({
1613
- type: import_v44.z.literal("thinking"),
1614
- thinking: import_v44.z.string()
1751
+ import_v45.z.object({
1752
+ type: import_v45.z.literal("thinking"),
1753
+ thinking: import_v45.z.string()
1615
1754
  }),
1616
- import_v44.z.object({
1617
- type: import_v44.z.literal("tool_use"),
1618
- id: import_v44.z.string(),
1619
- name: import_v44.z.string()
1755
+ import_v45.z.object({
1756
+ type: import_v45.z.literal("tool_use"),
1757
+ id: import_v45.z.string(),
1758
+ name: import_v45.z.string()
1620
1759
  }),
1621
- import_v44.z.object({
1622
- type: import_v44.z.literal("redacted_thinking"),
1623
- data: import_v44.z.string()
1760
+ import_v45.z.object({
1761
+ type: import_v45.z.literal("redacted_thinking"),
1762
+ data: import_v45.z.string()
1624
1763
  }),
1625
- import_v44.z.object({
1626
- type: import_v44.z.literal("server_tool_use"),
1627
- id: import_v44.z.string(),
1628
- name: import_v44.z.string(),
1629
- input: import_v44.z.record(import_v44.z.string(), import_v44.z.unknown()).nullish()
1764
+ import_v45.z.object({
1765
+ type: import_v45.z.literal("server_tool_use"),
1766
+ id: import_v45.z.string(),
1767
+ name: import_v45.z.string(),
1768
+ input: import_v45.z.record(import_v45.z.string(), import_v45.z.unknown()).nullish()
1630
1769
  }),
1631
- import_v44.z.object({
1632
- type: import_v44.z.literal("web_search_tool_result"),
1633
- tool_use_id: import_v44.z.string(),
1634
- content: import_v44.z.union([
1635
- import_v44.z.array(
1636
- import_v44.z.object({
1637
- type: import_v44.z.literal("web_search_result"),
1638
- url: import_v44.z.string(),
1639
- title: import_v44.z.string(),
1640
- encrypted_content: import_v44.z.string(),
1641
- page_age: import_v44.z.string().nullish()
1770
+ import_v45.z.object({
1771
+ type: import_v45.z.literal("web_search_tool_result"),
1772
+ tool_use_id: import_v45.z.string(),
1773
+ content: import_v45.z.union([
1774
+ import_v45.z.array(
1775
+ import_v45.z.object({
1776
+ type: import_v45.z.literal("web_search_result"),
1777
+ url: import_v45.z.string(),
1778
+ title: import_v45.z.string(),
1779
+ encrypted_content: import_v45.z.string(),
1780
+ page_age: import_v45.z.string().nullish()
1642
1781
  })
1643
1782
  ),
1644
- import_v44.z.object({
1645
- type: import_v44.z.literal("web_search_tool_result_error"),
1646
- error_code: import_v44.z.string()
1783
+ import_v45.z.object({
1784
+ type: import_v45.z.literal("web_search_tool_result_error"),
1785
+ error_code: import_v45.z.string()
1786
+ })
1787
+ ])
1788
+ }),
1789
+ import_v45.z.object({
1790
+ type: import_v45.z.literal("code_execution_tool_result"),
1791
+ tool_use_id: import_v45.z.string(),
1792
+ content: import_v45.z.union([
1793
+ import_v45.z.object({
1794
+ type: import_v45.z.literal("code_execution_result"),
1795
+ stdout: import_v45.z.string(),
1796
+ stderr: import_v45.z.string(),
1797
+ return_code: import_v45.z.number()
1798
+ }),
1799
+ import_v45.z.object({
1800
+ type: import_v45.z.literal("code_execution_tool_result_error"),
1801
+ error_code: import_v45.z.string()
1647
1802
  })
1648
1803
  ])
1649
1804
  })
1650
1805
  ])
1651
1806
  }),
1652
- import_v44.z.object({
1653
- type: import_v44.z.literal("content_block_delta"),
1654
- index: import_v44.z.number(),
1655
- delta: import_v44.z.discriminatedUnion("type", [
1656
- import_v44.z.object({
1657
- type: import_v44.z.literal("input_json_delta"),
1658
- partial_json: import_v44.z.string()
1807
+ import_v45.z.object({
1808
+ type: import_v45.z.literal("content_block_delta"),
1809
+ index: import_v45.z.number(),
1810
+ delta: import_v45.z.discriminatedUnion("type", [
1811
+ import_v45.z.object({
1812
+ type: import_v45.z.literal("input_json_delta"),
1813
+ partial_json: import_v45.z.string()
1659
1814
  }),
1660
- import_v44.z.object({
1661
- type: import_v44.z.literal("text_delta"),
1662
- text: import_v44.z.string()
1815
+ import_v45.z.object({
1816
+ type: import_v45.z.literal("text_delta"),
1817
+ text: import_v45.z.string()
1663
1818
  }),
1664
- import_v44.z.object({
1665
- type: import_v44.z.literal("thinking_delta"),
1666
- thinking: import_v44.z.string()
1819
+ import_v45.z.object({
1820
+ type: import_v45.z.literal("thinking_delta"),
1821
+ thinking: import_v45.z.string()
1667
1822
  }),
1668
- import_v44.z.object({
1669
- type: import_v44.z.literal("signature_delta"),
1670
- signature: import_v44.z.string()
1823
+ import_v45.z.object({
1824
+ type: import_v45.z.literal("signature_delta"),
1825
+ signature: import_v45.z.string()
1671
1826
  }),
1672
- import_v44.z.object({
1673
- type: import_v44.z.literal("citations_delta"),
1827
+ import_v45.z.object({
1828
+ type: import_v45.z.literal("citations_delta"),
1674
1829
  citation: citationSchema
1675
1830
  })
1676
1831
  ])
1677
1832
  }),
1678
- import_v44.z.object({
1679
- type: import_v44.z.literal("content_block_stop"),
1680
- index: import_v44.z.number()
1833
+ import_v45.z.object({
1834
+ type: import_v45.z.literal("content_block_stop"),
1835
+ index: import_v45.z.number()
1681
1836
  }),
1682
- import_v44.z.object({
1683
- type: import_v44.z.literal("error"),
1684
- error: import_v44.z.object({
1685
- type: import_v44.z.string(),
1686
- message: import_v44.z.string()
1837
+ import_v45.z.object({
1838
+ type: import_v45.z.literal("error"),
1839
+ error: import_v45.z.object({
1840
+ type: import_v45.z.string(),
1841
+ message: import_v45.z.string()
1687
1842
  })
1688
1843
  }),
1689
- import_v44.z.object({
1690
- type: import_v44.z.literal("message_delta"),
1691
- delta: import_v44.z.object({ stop_reason: import_v44.z.string().nullish() }),
1692
- usage: import_v44.z.object({ output_tokens: import_v44.z.number() })
1844
+ import_v45.z.object({
1845
+ type: import_v45.z.literal("message_delta"),
1846
+ delta: import_v45.z.object({ stop_reason: import_v45.z.string().nullish() }),
1847
+ usage: import_v45.z.object({ output_tokens: import_v45.z.number() })
1693
1848
  }),
1694
- import_v44.z.object({
1695
- type: import_v44.z.literal("message_stop")
1849
+ import_v45.z.object({
1850
+ type: import_v45.z.literal("message_stop")
1696
1851
  }),
1697
- import_v44.z.object({
1698
- type: import_v44.z.literal("ping")
1852
+ import_v45.z.object({
1853
+ type: import_v45.z.literal("ping")
1699
1854
  })
1700
1855
  ]);
1701
- var anthropicReasoningMetadataSchema = import_v44.z.object({
1702
- signature: import_v44.z.string().optional(),
1703
- redactedData: import_v44.z.string().optional()
1856
+ var anthropicReasoningMetadataSchema = import_v45.z.object({
1857
+ signature: import_v45.z.string().optional(),
1858
+ redactedData: import_v45.z.string().optional()
1704
1859
  });
1705
1860
 
1706
1861
  // src/tool/bash_20241022.ts
1707
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
1708
- var import_v45 = __toESM(require("zod/v4"));
1709
- var bash_20241022 = (0, import_provider_utils5.createProviderDefinedToolFactory)({
1862
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
1863
+ var import_v46 = __toESM(require("zod/v4"));
1864
+ var bash_20241022 = (0, import_provider_utils6.createProviderDefinedToolFactory)({
1710
1865
  id: "anthropic.bash_20241022",
1711
1866
  name: "bash",
1712
- inputSchema: import_v45.default.object({
1713
- command: import_v45.default.string(),
1714
- restart: import_v45.default.boolean().optional()
1867
+ inputSchema: import_v46.default.object({
1868
+ command: import_v46.default.string(),
1869
+ restart: import_v46.default.boolean().optional()
1715
1870
  })
1716
1871
  });
1717
1872
 
1718
1873
  // src/tool/bash_20250124.ts
1719
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
1720
- var import_v46 = __toESM(require("zod/v4"));
1721
- var bash_20250124 = (0, import_provider_utils6.createProviderDefinedToolFactory)({
1874
+ var import_provider_utils7 = require("@ai-sdk/provider-utils");
1875
+ var import_v47 = __toESM(require("zod/v4"));
1876
+ var bash_20250124 = (0, import_provider_utils7.createProviderDefinedToolFactory)({
1722
1877
  id: "anthropic.bash_20250124",
1723
1878
  name: "bash",
1724
- inputSchema: import_v46.default.object({
1725
- command: import_v46.default.string(),
1726
- restart: import_v46.default.boolean().optional()
1879
+ inputSchema: import_v47.default.object({
1880
+ command: import_v47.default.string(),
1881
+ restart: import_v47.default.boolean().optional()
1727
1882
  })
1728
1883
  });
1729
1884
 
1730
1885
  // src/tool/computer_20241022.ts
1731
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
1732
- var import_v47 = require("zod/v4");
1733
- var computer_20241022 = (0, import_provider_utils7.createProviderDefinedToolFactory)({
1886
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
1887
+ var import_v48 = require("zod/v4");
1888
+ var computer_20241022 = (0, import_provider_utils8.createProviderDefinedToolFactory)({
1734
1889
  id: "anthropic.computer_20241022",
1735
1890
  name: "computer",
1736
- inputSchema: import_v47.z.object({
1737
- action: import_v47.z.enum([
1891
+ inputSchema: import_v48.z.object({
1892
+ action: import_v48.z.enum([
1738
1893
  "key",
1739
1894
  "type",
1740
1895
  "mouse_move",
@@ -1746,19 +1901,19 @@ var computer_20241022 = (0, import_provider_utils7.createProviderDefinedToolFact
1746
1901
  "screenshot",
1747
1902
  "cursor_position"
1748
1903
  ]),
1749
- coordinate: import_v47.z.array(import_v47.z.number().int()).optional(),
1750
- text: import_v47.z.string().optional()
1904
+ coordinate: import_v48.z.array(import_v48.z.number().int()).optional(),
1905
+ text: import_v48.z.string().optional()
1751
1906
  })
1752
1907
  });
1753
1908
 
1754
1909
  // src/tool/computer_20250124.ts
1755
- var import_provider_utils8 = require("@ai-sdk/provider-utils");
1756
- var import_v48 = require("zod/v4");
1757
- var computer_20250124 = (0, import_provider_utils8.createProviderDefinedToolFactory)({
1910
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
1911
+ var import_v49 = require("zod/v4");
1912
+ var computer_20250124 = (0, import_provider_utils9.createProviderDefinedToolFactory)({
1758
1913
  id: "anthropic.computer_20250124",
1759
1914
  name: "computer",
1760
- inputSchema: import_v48.z.object({
1761
- action: import_v48.z.enum([
1915
+ inputSchema: import_v49.z.object({
1916
+ action: import_v49.z.enum([
1762
1917
  "key",
1763
1918
  "hold_key",
1764
1919
  "type",
@@ -1776,37 +1931,20 @@ var computer_20250124 = (0, import_provider_utils8.createProviderDefinedToolFact
1776
1931
  "wait",
1777
1932
  "screenshot"
1778
1933
  ]),
1779
- coordinate: import_v48.z.tuple([import_v48.z.number().int(), import_v48.z.number().int()]).optional(),
1780
- duration: import_v48.z.number().optional(),
1781
- scroll_amount: import_v48.z.number().optional(),
1782
- scroll_direction: import_v48.z.enum(["up", "down", "left", "right"]).optional(),
1783
- start_coordinate: import_v48.z.tuple([import_v48.z.number().int(), import_v48.z.number().int()]).optional(),
1784
- text: import_v48.z.string().optional()
1934
+ coordinate: import_v49.z.tuple([import_v49.z.number().int(), import_v49.z.number().int()]).optional(),
1935
+ duration: import_v49.z.number().optional(),
1936
+ scroll_amount: import_v49.z.number().optional(),
1937
+ scroll_direction: import_v49.z.enum(["up", "down", "left", "right"]).optional(),
1938
+ start_coordinate: import_v49.z.tuple([import_v49.z.number().int(), import_v49.z.number().int()]).optional(),
1939
+ text: import_v49.z.string().optional()
1785
1940
  })
1786
1941
  });
1787
1942
 
1788
1943
  // src/tool/text-editor_20241022.ts
1789
- var import_provider_utils9 = require("@ai-sdk/provider-utils");
1790
- var import_v49 = require("zod/v4");
1791
- var textEditor_20241022 = (0, import_provider_utils9.createProviderDefinedToolFactory)({
1792
- id: "anthropic.text_editor_20241022",
1793
- name: "str_replace_editor",
1794
- inputSchema: import_v49.z.object({
1795
- command: import_v49.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1796
- path: import_v49.z.string(),
1797
- file_text: import_v49.z.string().optional(),
1798
- insert_line: import_v49.z.number().int().optional(),
1799
- new_str: import_v49.z.string().optional(),
1800
- old_str: import_v49.z.string().optional(),
1801
- view_range: import_v49.z.array(import_v49.z.number().int()).optional()
1802
- })
1803
- });
1804
-
1805
- // src/tool/text-editor_20250124.ts
1806
1944
  var import_provider_utils10 = require("@ai-sdk/provider-utils");
1807
1945
  var import_v410 = require("zod/v4");
1808
- var textEditor_20250124 = (0, import_provider_utils10.createProviderDefinedToolFactory)({
1809
- id: "anthropic.text_editor_20250124",
1946
+ var textEditor_20241022 = (0, import_provider_utils10.createProviderDefinedToolFactory)({
1947
+ id: "anthropic.text_editor_20241022",
1810
1948
  name: "str_replace_editor",
1811
1949
  inputSchema: import_v410.z.object({
1812
1950
  command: import_v410.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
@@ -1819,14 +1957,14 @@ var textEditor_20250124 = (0, import_provider_utils10.createProviderDefinedToolF
1819
1957
  })
1820
1958
  });
1821
1959
 
1822
- // src/tool/text-editor_20250429.ts
1960
+ // src/tool/text-editor_20250124.ts
1823
1961
  var import_provider_utils11 = require("@ai-sdk/provider-utils");
1824
1962
  var import_v411 = require("zod/v4");
1825
- var textEditor_20250429 = (0, import_provider_utils11.createProviderDefinedToolFactory)({
1826
- id: "anthropic.text_editor_20250429",
1827
- name: "str_replace_based_edit_tool",
1963
+ var textEditor_20250124 = (0, import_provider_utils11.createProviderDefinedToolFactory)({
1964
+ id: "anthropic.text_editor_20250124",
1965
+ name: "str_replace_editor",
1828
1966
  inputSchema: import_v411.z.object({
1829
- command: import_v411.z.enum(["view", "create", "str_replace", "insert"]),
1967
+ command: import_v411.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
1830
1968
  path: import_v411.z.string(),
1831
1969
  file_text: import_v411.z.string().optional(),
1832
1970
  insert_line: import_v411.z.number().int().optional(),
@@ -1836,6 +1974,23 @@ var textEditor_20250429 = (0, import_provider_utils11.createProviderDefinedToolF
1836
1974
  })
1837
1975
  });
1838
1976
 
1977
+ // src/tool/text-editor_20250429.ts
1978
+ var import_provider_utils12 = require("@ai-sdk/provider-utils");
1979
+ var import_v412 = require("zod/v4");
1980
+ var textEditor_20250429 = (0, import_provider_utils12.createProviderDefinedToolFactory)({
1981
+ id: "anthropic.text_editor_20250429",
1982
+ name: "str_replace_based_edit_tool",
1983
+ inputSchema: import_v412.z.object({
1984
+ command: import_v412.z.enum(["view", "create", "str_replace", "insert"]),
1985
+ path: import_v412.z.string(),
1986
+ file_text: import_v412.z.string().optional(),
1987
+ insert_line: import_v412.z.number().int().optional(),
1988
+ new_str: import_v412.z.string().optional(),
1989
+ old_str: import_v412.z.string().optional(),
1990
+ view_range: import_v412.z.array(import_v412.z.number().int()).optional()
1991
+ })
1992
+ });
1993
+
1839
1994
  // src/anthropic-tools.ts
1840
1995
  var anthropicTools = {
1841
1996
  /**
@@ -1897,16 +2052,20 @@ var anthropicTools = {
1897
2052
  * @param blockedDomains - Optional list of domains that Claude should avoid when searching.
1898
2053
  * @param userLocation - Optional user location information to provide geographically relevant search results.
1899
2054
  */
1900
- webSearch_20250305
2055
+ webSearch_20250305,
2056
+ /**
2057
+ * Creates a tool for executing Python code. Must have name "code_execution".
2058
+ */
2059
+ codeExecution_20250522
1901
2060
  };
1902
2061
 
1903
2062
  // src/anthropic-provider.ts
1904
2063
  function createAnthropic(options = {}) {
1905
2064
  var _a;
1906
- const baseURL = (_a = (0, import_provider_utils12.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.anthropic.com/v1";
2065
+ const baseURL = (_a = (0, import_provider_utils13.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.anthropic.com/v1";
1907
2066
  const getHeaders = () => ({
1908
2067
  "anthropic-version": "2023-06-01",
1909
- "x-api-key": (0, import_provider_utils12.loadApiKey)({
2068
+ "x-api-key": (0, import_provider_utils13.loadApiKey)({
1910
2069
  apiKey: options.apiKey,
1911
2070
  environmentVariableName: "ANTHROPIC_API_KEY",
1912
2071
  description: "Anthropic"
@@ -1920,7 +2079,7 @@ function createAnthropic(options = {}) {
1920
2079
  baseURL,
1921
2080
  headers: getHeaders,
1922
2081
  fetch: options.fetch,
1923
- generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils12.generateId,
2082
+ generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils13.generateId,
1924
2083
  supportedUrls: () => ({
1925
2084
  "image/*": [/^https?:\/\/.*$/]
1926
2085
  })