@ai-sdk/anthropic 3.0.0-beta.21 → 3.0.0-beta.23

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.
@@ -28,7 +28,7 @@ module.exports = __toCommonJS(internal_exports);
28
28
 
29
29
  // src/anthropic-messages-language-model.ts
30
30
  var import_provider3 = require("@ai-sdk/provider");
31
- var import_provider_utils10 = require("@ai-sdk/provider-utils");
31
+ var import_provider_utils11 = require("@ai-sdk/provider-utils");
32
32
 
33
33
  // src/anthropic-error.ts
34
34
  var import_provider_utils = require("@ai-sdk/provider-utils");
@@ -156,6 +156,7 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
156
156
  })
157
157
  ])
158
158
  }),
159
+ // code execution results for code_execution_20250522 tool:
159
160
  import_v42.z.object({
160
161
  type: import_v42.z.literal("code_execution_tool_result"),
161
162
  tool_use_id: import_v42.z.string(),
@@ -171,6 +172,62 @@ var anthropicMessagesResponseSchema = (0, import_provider_utils2.lazySchema)(
171
172
  error_code: import_v42.z.string()
172
173
  })
173
174
  ])
175
+ }),
176
+ // bash code execution results for code_execution_20250825 tool:
177
+ import_v42.z.object({
178
+ type: import_v42.z.literal("bash_code_execution_tool_result"),
179
+ tool_use_id: import_v42.z.string(),
180
+ content: import_v42.z.discriminatedUnion("type", [
181
+ import_v42.z.object({
182
+ type: import_v42.z.literal("bash_code_execution_result"),
183
+ content: import_v42.z.array(
184
+ import_v42.z.object({
185
+ type: import_v42.z.literal("bash_code_execution_output"),
186
+ file_id: import_v42.z.string()
187
+ })
188
+ ),
189
+ stdout: import_v42.z.string(),
190
+ stderr: import_v42.z.string(),
191
+ return_code: import_v42.z.number()
192
+ }),
193
+ import_v42.z.object({
194
+ type: import_v42.z.literal("bash_code_execution_tool_result_error"),
195
+ error_code: import_v42.z.string()
196
+ })
197
+ ])
198
+ }),
199
+ // text editor code execution results for code_execution_20250825 tool:
200
+ import_v42.z.object({
201
+ type: import_v42.z.literal("text_editor_code_execution_tool_result"),
202
+ tool_use_id: import_v42.z.string(),
203
+ content: import_v42.z.discriminatedUnion("type", [
204
+ import_v42.z.object({
205
+ type: import_v42.z.literal("text_editor_code_execution_tool_result_error"),
206
+ error_code: import_v42.z.string()
207
+ }),
208
+ import_v42.z.object({
209
+ type: import_v42.z.literal("text_editor_code_execution_view_result"),
210
+ content: import_v42.z.string(),
211
+ file_type: import_v42.z.string(),
212
+ num_lines: import_v42.z.number().nullable(),
213
+ start_line: import_v42.z.number().nullable(),
214
+ total_lines: import_v42.z.number().nullable()
215
+ }),
216
+ import_v42.z.object({
217
+ type: import_v42.z.literal("text_editor_code_execution_create_result"),
218
+ is_file_update: import_v42.z.boolean()
219
+ }),
220
+ import_v42.z.object({
221
+ type: import_v42.z.literal(
222
+ "text_editor_code_execution_str_replace_result"
223
+ ),
224
+ lines: import_v42.z.array(import_v42.z.string()).nullable(),
225
+ new_lines: import_v42.z.number().nullable(),
226
+ new_start: import_v42.z.number().nullable(),
227
+ old_lines: import_v42.z.number().nullable(),
228
+ old_start: import_v42.z.number().nullable()
229
+ })
230
+ ])
174
231
  })
175
232
  ])
176
233
  ),
@@ -271,6 +328,7 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
271
328
  })
272
329
  ])
273
330
  }),
331
+ // code execution results for code_execution_20250522 tool:
274
332
  import_v42.z.object({
275
333
  type: import_v42.z.literal("code_execution_tool_result"),
276
334
  tool_use_id: import_v42.z.string(),
@@ -286,6 +344,62 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
286
344
  error_code: import_v42.z.string()
287
345
  })
288
346
  ])
347
+ }),
348
+ // bash code execution results for code_execution_20250825 tool:
349
+ import_v42.z.object({
350
+ type: import_v42.z.literal("bash_code_execution_tool_result"),
351
+ tool_use_id: import_v42.z.string(),
352
+ content: import_v42.z.discriminatedUnion("type", [
353
+ import_v42.z.object({
354
+ type: import_v42.z.literal("bash_code_execution_result"),
355
+ content: import_v42.z.array(
356
+ import_v42.z.object({
357
+ type: import_v42.z.literal("bash_code_execution_output"),
358
+ file_id: import_v42.z.string()
359
+ })
360
+ ),
361
+ stdout: import_v42.z.string(),
362
+ stderr: import_v42.z.string(),
363
+ return_code: import_v42.z.number()
364
+ }),
365
+ import_v42.z.object({
366
+ type: import_v42.z.literal("bash_code_execution_tool_result_error"),
367
+ error_code: import_v42.z.string()
368
+ })
369
+ ])
370
+ }),
371
+ // text editor code execution results for code_execution_20250825 tool:
372
+ import_v42.z.object({
373
+ type: import_v42.z.literal("text_editor_code_execution_tool_result"),
374
+ tool_use_id: import_v42.z.string(),
375
+ content: import_v42.z.discriminatedUnion("type", [
376
+ import_v42.z.object({
377
+ type: import_v42.z.literal("text_editor_code_execution_tool_result_error"),
378
+ error_code: import_v42.z.string()
379
+ }),
380
+ import_v42.z.object({
381
+ type: import_v42.z.literal("text_editor_code_execution_view_result"),
382
+ content: import_v42.z.string(),
383
+ file_type: import_v42.z.string(),
384
+ num_lines: import_v42.z.number().nullable(),
385
+ start_line: import_v42.z.number().nullable(),
386
+ total_lines: import_v42.z.number().nullable()
387
+ }),
388
+ import_v42.z.object({
389
+ type: import_v42.z.literal("text_editor_code_execution_create_result"),
390
+ is_file_update: import_v42.z.boolean()
391
+ }),
392
+ import_v42.z.object({
393
+ type: import_v42.z.literal(
394
+ "text_editor_code_execution_str_replace_result"
395
+ ),
396
+ lines: import_v42.z.array(import_v42.z.string()).nullable(),
397
+ new_lines: import_v42.z.number().nullable(),
398
+ new_start: import_v42.z.number().nullable(),
399
+ old_lines: import_v42.z.number().nullable(),
400
+ old_start: import_v42.z.number().nullable()
401
+ })
402
+ ])
289
403
  })
290
404
  ])
291
405
  }),
@@ -611,6 +725,14 @@ async function prepareTools({
611
725
  });
612
726
  break;
613
727
  }
728
+ case "anthropic.code_execution_20250825": {
729
+ betas.add("code-execution-2025-08-25");
730
+ anthropicTools2.push({
731
+ type: "code_execution_20250825",
732
+ name: "code_execution"
733
+ });
734
+ break;
735
+ }
614
736
  case "anthropic.computer_20250124": {
615
737
  betas.add("computer-use-2025-01-24");
616
738
  anthropicTools2.push({
@@ -784,7 +906,7 @@ async function prepareTools({
784
906
 
785
907
  // src/convert-to-anthropic-messages-prompt.ts
786
908
  var import_provider2 = require("@ai-sdk/provider");
787
- var import_provider_utils9 = require("@ai-sdk/provider-utils");
909
+ var import_provider_utils10 = require("@ai-sdk/provider-utils");
788
910
 
789
911
  // src/tool/code-execution_20250522.ts
790
912
  var import_provider_utils8 = require("@ai-sdk/provider-utils");
@@ -816,6 +938,95 @@ var codeExecution_20250522 = (args = {}) => {
816
938
  return factory4(args);
817
939
  };
818
940
 
941
+ // src/tool/code-execution_20250825.ts
942
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
943
+ var import_v48 = require("zod/v4");
944
+ var codeExecution_20250825OutputSchema = (0, import_provider_utils9.lazySchema)(
945
+ () => (0, import_provider_utils9.zodSchema)(
946
+ import_v48.z.discriminatedUnion("type", [
947
+ import_v48.z.object({
948
+ type: import_v48.z.literal("bash_code_execution_result"),
949
+ content: import_v48.z.array(
950
+ import_v48.z.object({
951
+ type: import_v48.z.literal("bash_code_execution_output"),
952
+ file_id: import_v48.z.string()
953
+ })
954
+ ),
955
+ stdout: import_v48.z.string(),
956
+ stderr: import_v48.z.string(),
957
+ return_code: import_v48.z.number()
958
+ }),
959
+ import_v48.z.object({
960
+ type: import_v48.z.literal("bash_code_execution_tool_result_error"),
961
+ error_code: import_v48.z.string()
962
+ }),
963
+ import_v48.z.object({
964
+ type: import_v48.z.literal("text_editor_code_execution_tool_result_error"),
965
+ error_code: import_v48.z.string()
966
+ }),
967
+ import_v48.z.object({
968
+ type: import_v48.z.literal("text_editor_code_execution_view_result"),
969
+ content: import_v48.z.string(),
970
+ file_type: import_v48.z.string(),
971
+ num_lines: import_v48.z.number().nullable(),
972
+ start_line: import_v48.z.number().nullable(),
973
+ total_lines: import_v48.z.number().nullable()
974
+ }),
975
+ import_v48.z.object({
976
+ type: import_v48.z.literal("text_editor_code_execution_create_result"),
977
+ is_file_update: import_v48.z.boolean()
978
+ }),
979
+ import_v48.z.object({
980
+ type: import_v48.z.literal("text_editor_code_execution_str_replace_result"),
981
+ lines: import_v48.z.array(import_v48.z.string()).nullable(),
982
+ new_lines: import_v48.z.number().nullable(),
983
+ new_start: import_v48.z.number().nullable(),
984
+ old_lines: import_v48.z.number().nullable(),
985
+ old_start: import_v48.z.number().nullable()
986
+ })
987
+ ])
988
+ )
989
+ );
990
+ var codeExecution_20250825InputSchema = (0, import_provider_utils9.lazySchema)(
991
+ () => (0, import_provider_utils9.zodSchema)(
992
+ import_v48.z.discriminatedUnion("type", [
993
+ import_v48.z.object({
994
+ type: import_v48.z.literal("bash_code_execution"),
995
+ command: import_v48.z.string()
996
+ }),
997
+ import_v48.z.discriminatedUnion("command", [
998
+ import_v48.z.object({
999
+ type: import_v48.z.literal("text_editor_code_execution"),
1000
+ command: import_v48.z.literal("view"),
1001
+ path: import_v48.z.string()
1002
+ }),
1003
+ import_v48.z.object({
1004
+ type: import_v48.z.literal("text_editor_code_execution"),
1005
+ command: import_v48.z.literal("create"),
1006
+ path: import_v48.z.string(),
1007
+ file_text: import_v48.z.string().nullish()
1008
+ }),
1009
+ import_v48.z.object({
1010
+ type: import_v48.z.literal("text_editor_code_execution"),
1011
+ command: import_v48.z.literal("str_replace"),
1012
+ path: import_v48.z.string(),
1013
+ old_str: import_v48.z.string(),
1014
+ new_str: import_v48.z.string()
1015
+ })
1016
+ ])
1017
+ ])
1018
+ )
1019
+ );
1020
+ var factory5 = (0, import_provider_utils9.createProviderDefinedToolFactoryWithOutputSchema)({
1021
+ id: "anthropic.code_execution_20250825",
1022
+ name: "code_execution",
1023
+ inputSchema: codeExecution_20250825InputSchema,
1024
+ outputSchema: codeExecution_20250825OutputSchema
1025
+ });
1026
+ var codeExecution_20250825 = (args = {}) => {
1027
+ return factory5(args);
1028
+ };
1029
+
819
1030
  // src/convert-to-anthropic-messages-prompt.ts
820
1031
  function convertToString(data) {
821
1032
  if (typeof data === "string") {
@@ -845,7 +1056,7 @@ async function convertToAnthropicMessagesPrompt({
845
1056
  const messages = [];
846
1057
  async function shouldEnableCitations(providerMetadata) {
847
1058
  var _a2, _b2;
848
- const anthropicOptions = await (0, import_provider_utils9.parseProviderOptions)({
1059
+ const anthropicOptions = await (0, import_provider_utils10.parseProviderOptions)({
849
1060
  provider: "anthropic",
850
1061
  providerOptions: providerMetadata,
851
1062
  schema: anthropicFilePartProviderOptions
@@ -853,7 +1064,7 @@ async function convertToAnthropicMessagesPrompt({
853
1064
  return (_b2 = (_a2 = anthropicOptions == null ? void 0 : anthropicOptions.citations) == null ? void 0 : _a2.enabled) != null ? _b2 : false;
854
1065
  }
855
1066
  async function getDocumentMetadata(providerMetadata) {
856
- const anthropicOptions = await (0, import_provider_utils9.parseProviderOptions)({
1067
+ const anthropicOptions = await (0, import_provider_utils10.parseProviderOptions)({
857
1068
  provider: "anthropic",
858
1069
  providerOptions: providerMetadata,
859
1070
  schema: anthropicFilePartProviderOptions
@@ -910,7 +1121,7 @@ async function convertToAnthropicMessagesPrompt({
910
1121
  } : {
911
1122
  type: "base64",
912
1123
  media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
913
- data: (0, import_provider_utils9.convertToBase64)(part.data)
1124
+ data: (0, import_provider_utils10.convertToBase64)(part.data)
914
1125
  },
915
1126
  cache_control: cacheControl
916
1127
  });
@@ -930,7 +1141,7 @@ async function convertToAnthropicMessagesPrompt({
930
1141
  } : {
931
1142
  type: "base64",
932
1143
  media_type: "application/pdf",
933
- data: (0, import_provider_utils9.convertToBase64)(part.data)
1144
+ data: (0, import_provider_utils10.convertToBase64)(part.data)
934
1145
  },
935
1146
  title: (_b = metadata.title) != null ? _b : part.filename,
936
1147
  ...metadata.context && { context: metadata.context },
@@ -1003,6 +1214,18 @@ async function convertToAnthropicMessagesPrompt({
1003
1214
  cache_control: void 0
1004
1215
  };
1005
1216
  }
1217
+ if (contentPart.mediaType === "application/pdf") {
1218
+ betas.add("pdfs-2024-09-25");
1219
+ return {
1220
+ type: "document",
1221
+ source: {
1222
+ type: "base64",
1223
+ media_type: contentPart.mediaType,
1224
+ data: contentPart.data
1225
+ },
1226
+ cache_control: void 0
1227
+ };
1228
+ }
1006
1229
  throw new import_provider2.UnsupportedFunctionalityError({
1007
1230
  functionality: `media type: ${contentPart.mediaType}`
1008
1231
  });
@@ -1068,7 +1291,7 @@ async function convertToAnthropicMessagesPrompt({
1068
1291
  }
1069
1292
  case "reasoning": {
1070
1293
  if (sendReasoning) {
1071
- const reasoningMetadata = await (0, import_provider_utils9.parseProviderOptions)({
1294
+ const reasoningMetadata = await (0, import_provider_utils10.parseProviderOptions)({
1072
1295
  provider: "anthropic",
1073
1296
  providerOptions: part.providerOptions,
1074
1297
  schema: anthropicReasoningMetadataSchema
@@ -1109,7 +1332,17 @@ async function convertToAnthropicMessagesPrompt({
1109
1332
  }
1110
1333
  case "tool-call": {
1111
1334
  if (part.providerExecuted) {
1112
- if (part.toolName === "code_execution" || part.toolName === "web_fetch" || part.toolName === "web_search") {
1335
+ if (part.toolName === "code_execution" && part.input != null && typeof part.input === "object" && "type" in part.input && typeof part.input.type === "string" && (part.input.type === "bash_code_execution" || part.input.type === "text_editor_code_execution")) {
1336
+ anthropicContent.push({
1337
+ type: "server_tool_use",
1338
+ id: part.toolCallId,
1339
+ name: part.input.type,
1340
+ // map back to subtool name
1341
+ input: part.input,
1342
+ cache_control: cacheControl
1343
+ });
1344
+ } else if (part.toolName === "code_execution" || // code execution 20250522
1345
+ part.toolName === "web_fetch" || part.toolName === "web_search") {
1113
1346
  anthropicContent.push({
1114
1347
  type: "server_tool_use",
1115
1348
  id: part.toolCallId,
@@ -1144,21 +1377,48 @@ async function convertToAnthropicMessagesPrompt({
1144
1377
  });
1145
1378
  break;
1146
1379
  }
1147
- const codeExecutionOutput = await (0, import_provider_utils9.validateTypes)({
1148
- value: output.value,
1149
- schema: codeExecution_20250522OutputSchema
1150
- });
1151
- anthropicContent.push({
1152
- type: "code_execution_tool_result",
1153
- tool_use_id: part.toolCallId,
1154
- content: {
1155
- type: codeExecutionOutput.type,
1156
- stdout: codeExecutionOutput.stdout,
1157
- stderr: codeExecutionOutput.stderr,
1158
- return_code: codeExecutionOutput.return_code
1159
- },
1160
- cache_control: cacheControl
1161
- });
1380
+ if (output.value == null || typeof output.value !== "object" || !("type" in output.value) || typeof output.value.type !== "string") {
1381
+ warnings.push({
1382
+ type: "other",
1383
+ message: `provider executed tool result output value is not a valid code execution result for tool ${part.toolName}`
1384
+ });
1385
+ break;
1386
+ }
1387
+ if (output.value.type === "code_execution_result") {
1388
+ const codeExecutionOutput = await (0, import_provider_utils10.validateTypes)({
1389
+ value: output.value,
1390
+ schema: codeExecution_20250522OutputSchema
1391
+ });
1392
+ anthropicContent.push({
1393
+ type: "code_execution_tool_result",
1394
+ tool_use_id: part.toolCallId,
1395
+ content: {
1396
+ type: codeExecutionOutput.type,
1397
+ stdout: codeExecutionOutput.stdout,
1398
+ stderr: codeExecutionOutput.stderr,
1399
+ return_code: codeExecutionOutput.return_code
1400
+ },
1401
+ cache_control: cacheControl
1402
+ });
1403
+ } else {
1404
+ const codeExecutionOutput = await (0, import_provider_utils10.validateTypes)({
1405
+ value: output.value,
1406
+ schema: codeExecution_20250825OutputSchema
1407
+ });
1408
+ anthropicContent.push(
1409
+ codeExecutionOutput.type === "bash_code_execution_result" || codeExecutionOutput.type === "bash_code_execution_tool_result_error" ? {
1410
+ type: "bash_code_execution_tool_result",
1411
+ tool_use_id: part.toolCallId,
1412
+ cache_control: cacheControl,
1413
+ content: codeExecutionOutput
1414
+ } : {
1415
+ type: "text_editor_code_execution_tool_result",
1416
+ tool_use_id: part.toolCallId,
1417
+ cache_control: cacheControl,
1418
+ content: codeExecutionOutput
1419
+ }
1420
+ );
1421
+ }
1162
1422
  break;
1163
1423
  }
1164
1424
  if (part.toolName === "web_fetch") {
@@ -1170,7 +1430,7 @@ async function convertToAnthropicMessagesPrompt({
1170
1430
  });
1171
1431
  break;
1172
1432
  }
1173
- const webFetchOutput = await (0, import_provider_utils9.validateTypes)({
1433
+ const webFetchOutput = await (0, import_provider_utils10.validateTypes)({
1174
1434
  value: output.value,
1175
1435
  schema: webFetch_20250910OutputSchema
1176
1436
  });
@@ -1205,7 +1465,7 @@ async function convertToAnthropicMessagesPrompt({
1205
1465
  });
1206
1466
  break;
1207
1467
  }
1208
- const webSearchOutput = await (0, import_provider_utils9.validateTypes)({
1468
+ const webSearchOutput = await (0, import_provider_utils10.validateTypes)({
1209
1469
  value: output.value,
1210
1470
  schema: webSearch_20250305OutputSchema
1211
1471
  });
@@ -1350,7 +1610,7 @@ var AnthropicMessagesLanguageModel = class {
1350
1610
  var _a;
1351
1611
  this.modelId = modelId;
1352
1612
  this.config = config;
1353
- this.generateId = (_a = config.generateId) != null ? _a : import_provider_utils10.generateId;
1613
+ this.generateId = (_a = config.generateId) != null ? _a : import_provider_utils11.generateId;
1354
1614
  }
1355
1615
  supportsUrl(url) {
1356
1616
  return url.protocol === "https:";
@@ -1419,7 +1679,7 @@ var AnthropicMessagesLanguageModel = class {
1419
1679
  description: "Respond with a JSON object.",
1420
1680
  inputSchema: responseFormat.schema
1421
1681
  } : void 0;
1422
- const anthropicOptions = await (0, import_provider_utils10.parseProviderOptions)({
1682
+ const anthropicOptions = await (0, import_provider_utils11.parseProviderOptions)({
1423
1683
  provider: "anthropic",
1424
1684
  providerOptions,
1425
1685
  schema: anthropicProviderOptions
@@ -1511,8 +1771,8 @@ var AnthropicMessagesLanguageModel = class {
1511
1771
  betas,
1512
1772
  headers
1513
1773
  }) {
1514
- return (0, import_provider_utils10.combineHeaders)(
1515
- await (0, import_provider_utils10.resolve)(this.config.headers),
1774
+ return (0, import_provider_utils11.combineHeaders)(
1775
+ await (0, import_provider_utils11.resolve)(this.config.headers),
1516
1776
  betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {},
1517
1777
  headers
1518
1778
  );
@@ -1556,12 +1816,12 @@ var AnthropicMessagesLanguageModel = class {
1556
1816
  responseHeaders,
1557
1817
  value: response,
1558
1818
  rawValue: rawResponse
1559
- } = await (0, import_provider_utils10.postJsonToApi)({
1819
+ } = await (0, import_provider_utils11.postJsonToApi)({
1560
1820
  url: this.buildRequestUrl(false),
1561
1821
  headers: await this.getHeaders({ betas, headers: options.headers }),
1562
1822
  body: this.transformRequestBody(args),
1563
1823
  failedResponseHandler: anthropicFailedResponseHandler,
1564
- successfulResponseHandler: (0, import_provider_utils10.createJsonResponseHandler)(
1824
+ successfulResponseHandler: (0, import_provider_utils11.createJsonResponseHandler)(
1565
1825
  anthropicMessagesResponseSchema
1566
1826
  ),
1567
1827
  abortSignal: options.abortSignal,
@@ -1628,7 +1888,15 @@ var AnthropicMessagesLanguageModel = class {
1628
1888
  break;
1629
1889
  }
1630
1890
  case "server_tool_use": {
1631
- if (part.name === "web_search" || part.name === "code_execution" || part.name === "web_fetch") {
1891
+ if (part.name === "text_editor_code_execution" || part.name === "bash_code_execution") {
1892
+ content.push({
1893
+ type: "tool-call",
1894
+ toolCallId: part.id,
1895
+ toolName: "code_execution",
1896
+ input: JSON.stringify({ type: part.name, ...part.input }),
1897
+ providerExecuted: true
1898
+ });
1899
+ } else if (part.name === "web_search" || part.name === "code_execution" || part.name === "web_fetch") {
1632
1900
  content.push({
1633
1901
  type: "tool-call",
1634
1902
  toolCallId: part.id,
@@ -1724,6 +1992,7 @@ var AnthropicMessagesLanguageModel = class {
1724
1992
  }
1725
1993
  break;
1726
1994
  }
1995
+ // code execution 20250522:
1727
1996
  case "code_execution_tool_result": {
1728
1997
  if (part.content.type === "code_execution_result") {
1729
1998
  content.push({
@@ -1753,6 +2022,18 @@ var AnthropicMessagesLanguageModel = class {
1753
2022
  }
1754
2023
  break;
1755
2024
  }
2025
+ // code execution 20250825:
2026
+ case "bash_code_execution_tool_result":
2027
+ case "text_editor_code_execution_tool_result": {
2028
+ content.push({
2029
+ type: "tool-result",
2030
+ toolCallId: part.tool_use_id,
2031
+ toolName: "code_execution",
2032
+ result: part.content,
2033
+ providerExecuted: true
2034
+ });
2035
+ break;
2036
+ }
1756
2037
  }
1757
2038
  }
1758
2039
  return {
@@ -1788,12 +2069,12 @@ var AnthropicMessagesLanguageModel = class {
1788
2069
  const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs(options);
1789
2070
  const citationDocuments = this.extractCitationDocuments(options.prompt);
1790
2071
  const body = { ...args, stream: true };
1791
- const { responseHeaders, value: response } = await (0, import_provider_utils10.postJsonToApi)({
2072
+ const { responseHeaders, value: response } = await (0, import_provider_utils11.postJsonToApi)({
1792
2073
  url: this.buildRequestUrl(true),
1793
2074
  headers: await this.getHeaders({ betas, headers: options.headers }),
1794
2075
  body: this.transformRequestBody(body),
1795
2076
  failedResponseHandler: anthropicFailedResponseHandler,
1796
- successfulResponseHandler: (0, import_provider_utils10.createEventSourceResponseHandler)(
2077
+ successfulResponseHandler: (0, import_provider_utils11.createEventSourceResponseHandler)(
1797
2078
  anthropicMessagesChunkSchema
1798
2079
  ),
1799
2080
  abortSignal: options.abortSignal,
@@ -1869,7 +2150,8 @@ var AnthropicMessagesLanguageModel = class {
1869
2150
  type: "tool-call",
1870
2151
  toolCallId: value.content_block.id,
1871
2152
  toolName: value.content_block.name,
1872
- input: ""
2153
+ input: "",
2154
+ firstDelta: true
1873
2155
  };
1874
2156
  controller.enqueue(
1875
2157
  usesJsonResponseTool ? { type: "text-start", id: String(value.index) } : {
@@ -1881,18 +2163,29 @@ var AnthropicMessagesLanguageModel = class {
1881
2163
  return;
1882
2164
  }
1883
2165
  case "server_tool_use": {
1884
- if (value.content_block.name === "web_fetch" || value.content_block.name === "web_search" || value.content_block.name === "code_execution") {
2166
+ if ([
2167
+ "web_fetch",
2168
+ "web_search",
2169
+ // code execution 20250825:
2170
+ "code_execution",
2171
+ // code execution 20250825 text editor:
2172
+ "text_editor_code_execution",
2173
+ // code execution 20250825 bash:
2174
+ "bash_code_execution"
2175
+ ].includes(value.content_block.name)) {
1885
2176
  contentBlocks[value.index] = {
1886
2177
  type: "tool-call",
1887
2178
  toolCallId: value.content_block.id,
1888
2179
  toolName: value.content_block.name,
1889
2180
  input: "",
1890
- providerExecuted: true
2181
+ providerExecuted: true,
2182
+ firstDelta: true
1891
2183
  };
2184
+ const mappedToolName = value.content_block.name === "text_editor_code_execution" || value.content_block.name === "bash_code_execution" ? "code_execution" : value.content_block.name;
1892
2185
  controller.enqueue({
1893
2186
  type: "tool-input-start",
1894
2187
  id: value.content_block.id,
1895
- toolName: value.content_block.name,
2188
+ toolName: mappedToolName,
1896
2189
  providerExecuted: true
1897
2190
  });
1898
2191
  }
@@ -1984,6 +2277,7 @@ var AnthropicMessagesLanguageModel = class {
1984
2277
  }
1985
2278
  return;
1986
2279
  }
2280
+ // code execution 20250522:
1987
2281
  case "code_execution_tool_result": {
1988
2282
  const part = value.content_block;
1989
2283
  if (part.content.type === "code_execution_result") {
@@ -2014,6 +2308,19 @@ var AnthropicMessagesLanguageModel = class {
2014
2308
  }
2015
2309
  return;
2016
2310
  }
2311
+ // code execution 20250825:
2312
+ case "bash_code_execution_tool_result":
2313
+ case "text_editor_code_execution_tool_result": {
2314
+ const part = value.content_block;
2315
+ controller.enqueue({
2316
+ type: "tool-result",
2317
+ toolCallId: part.tool_use_id,
2318
+ toolName: "code_execution",
2319
+ result: part.content,
2320
+ providerExecuted: true
2321
+ });
2322
+ return;
2323
+ }
2017
2324
  default: {
2018
2325
  const _exhaustiveCheck = contentBlockType;
2019
2326
  throw new Error(
@@ -2046,7 +2353,14 @@ var AnthropicMessagesLanguageModel = class {
2046
2353
  type: "tool-input-end",
2047
2354
  id: contentBlock.toolCallId
2048
2355
  });
2049
- controller.enqueue(contentBlock);
2356
+ const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
2357
+ controller.enqueue({
2358
+ type: "tool-call",
2359
+ toolCallId: contentBlock.toolCallId,
2360
+ toolName,
2361
+ input: contentBlock.input,
2362
+ providerExecuted: contentBlock.providerExecuted
2363
+ });
2050
2364
  }
2051
2365
  break;
2052
2366
  }
@@ -2094,7 +2408,10 @@ var AnthropicMessagesLanguageModel = class {
2094
2408
  }
2095
2409
  case "input_json_delta": {
2096
2410
  const contentBlock = contentBlocks[value.index];
2097
- const delta = value.delta.partial_json;
2411
+ let delta = value.delta.partial_json;
2412
+ if (delta.length === 0) {
2413
+ return;
2414
+ }
2098
2415
  if (usesJsonResponseTool) {
2099
2416
  if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
2100
2417
  return;
@@ -2108,12 +2425,16 @@ var AnthropicMessagesLanguageModel = class {
2108
2425
  if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
2109
2426
  return;
2110
2427
  }
2428
+ if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
2429
+ delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
2430
+ }
2111
2431
  controller.enqueue({
2112
2432
  type: "tool-input-delta",
2113
2433
  id: contentBlock.toolCallId,
2114
2434
  delta
2115
2435
  });
2116
2436
  contentBlock.input += delta;
2437
+ contentBlock.firstDelta = false;
2117
2438
  }
2118
2439
  return;
2119
2440
  }
@@ -2199,46 +2520,46 @@ var AnthropicMessagesLanguageModel = class {
2199
2520
  };
2200
2521
 
2201
2522
  // src/tool/bash_20241022.ts
2202
- var import_provider_utils11 = require("@ai-sdk/provider-utils");
2203
- var import_v48 = require("zod/v4");
2204
- var bash_20241022InputSchema = (0, import_provider_utils11.lazySchema)(
2205
- () => (0, import_provider_utils11.zodSchema)(
2206
- import_v48.z.object({
2207
- command: import_v48.z.string(),
2208
- restart: import_v48.z.boolean().optional()
2523
+ var import_provider_utils12 = require("@ai-sdk/provider-utils");
2524
+ var import_v49 = require("zod/v4");
2525
+ var bash_20241022InputSchema = (0, import_provider_utils12.lazySchema)(
2526
+ () => (0, import_provider_utils12.zodSchema)(
2527
+ import_v49.z.object({
2528
+ command: import_v49.z.string(),
2529
+ restart: import_v49.z.boolean().optional()
2209
2530
  })
2210
2531
  )
2211
2532
  );
2212
- var bash_20241022 = (0, import_provider_utils11.createProviderDefinedToolFactory)({
2533
+ var bash_20241022 = (0, import_provider_utils12.createProviderDefinedToolFactory)({
2213
2534
  id: "anthropic.bash_20241022",
2214
2535
  name: "bash",
2215
2536
  inputSchema: bash_20241022InputSchema
2216
2537
  });
2217
2538
 
2218
2539
  // src/tool/bash_20250124.ts
2219
- var import_provider_utils12 = require("@ai-sdk/provider-utils");
2220
- var import_v49 = require("zod/v4");
2221
- var bash_20250124InputSchema = (0, import_provider_utils12.lazySchema)(
2222
- () => (0, import_provider_utils12.zodSchema)(
2223
- import_v49.z.object({
2224
- command: import_v49.z.string(),
2225
- restart: import_v49.z.boolean().optional()
2540
+ var import_provider_utils13 = require("@ai-sdk/provider-utils");
2541
+ var import_v410 = require("zod/v4");
2542
+ var bash_20250124InputSchema = (0, import_provider_utils13.lazySchema)(
2543
+ () => (0, import_provider_utils13.zodSchema)(
2544
+ import_v410.z.object({
2545
+ command: import_v410.z.string(),
2546
+ restart: import_v410.z.boolean().optional()
2226
2547
  })
2227
2548
  )
2228
2549
  );
2229
- var bash_20250124 = (0, import_provider_utils12.createProviderDefinedToolFactory)({
2550
+ var bash_20250124 = (0, import_provider_utils13.createProviderDefinedToolFactory)({
2230
2551
  id: "anthropic.bash_20250124",
2231
2552
  name: "bash",
2232
2553
  inputSchema: bash_20250124InputSchema
2233
2554
  });
2234
2555
 
2235
2556
  // src/tool/computer_20241022.ts
2236
- var import_provider_utils13 = require("@ai-sdk/provider-utils");
2237
- var import_v410 = require("zod/v4");
2238
- var computer_20241022InputSchema = (0, import_provider_utils13.lazySchema)(
2239
- () => (0, import_provider_utils13.zodSchema)(
2240
- import_v410.z.object({
2241
- action: import_v410.z.enum([
2557
+ var import_provider_utils14 = require("@ai-sdk/provider-utils");
2558
+ var import_v411 = require("zod/v4");
2559
+ var computer_20241022InputSchema = (0, import_provider_utils14.lazySchema)(
2560
+ () => (0, import_provider_utils14.zodSchema)(
2561
+ import_v411.z.object({
2562
+ action: import_v411.z.enum([
2242
2563
  "key",
2243
2564
  "type",
2244
2565
  "mouse_move",
@@ -2250,24 +2571,24 @@ var computer_20241022InputSchema = (0, import_provider_utils13.lazySchema)(
2250
2571
  "screenshot",
2251
2572
  "cursor_position"
2252
2573
  ]),
2253
- coordinate: import_v410.z.array(import_v410.z.number().int()).optional(),
2254
- text: import_v410.z.string().optional()
2574
+ coordinate: import_v411.z.array(import_v411.z.number().int()).optional(),
2575
+ text: import_v411.z.string().optional()
2255
2576
  })
2256
2577
  )
2257
2578
  );
2258
- var computer_20241022 = (0, import_provider_utils13.createProviderDefinedToolFactory)({
2579
+ var computer_20241022 = (0, import_provider_utils14.createProviderDefinedToolFactory)({
2259
2580
  id: "anthropic.computer_20241022",
2260
2581
  name: "computer",
2261
2582
  inputSchema: computer_20241022InputSchema
2262
2583
  });
2263
2584
 
2264
2585
  // src/tool/computer_20250124.ts
2265
- var import_provider_utils14 = require("@ai-sdk/provider-utils");
2266
- var import_v411 = require("zod/v4");
2267
- var computer_20250124InputSchema = (0, import_provider_utils14.lazySchema)(
2268
- () => (0, import_provider_utils14.zodSchema)(
2269
- import_v411.z.object({
2270
- action: import_v411.z.enum([
2586
+ var import_provider_utils15 = require("@ai-sdk/provider-utils");
2587
+ var import_v412 = require("zod/v4");
2588
+ var computer_20250124InputSchema = (0, import_provider_utils15.lazySchema)(
2589
+ () => (0, import_provider_utils15.zodSchema)(
2590
+ import_v412.z.object({
2591
+ action: import_v412.z.enum([
2271
2592
  "key",
2272
2593
  "hold_key",
2273
2594
  "type",
@@ -2285,47 +2606,25 @@ var computer_20250124InputSchema = (0, import_provider_utils14.lazySchema)(
2285
2606
  "wait",
2286
2607
  "screenshot"
2287
2608
  ]),
2288
- coordinate: import_v411.z.tuple([import_v411.z.number().int(), import_v411.z.number().int()]).optional(),
2289
- duration: import_v411.z.number().optional(),
2290
- scroll_amount: import_v411.z.number().optional(),
2291
- scroll_direction: import_v411.z.enum(["up", "down", "left", "right"]).optional(),
2292
- start_coordinate: import_v411.z.tuple([import_v411.z.number().int(), import_v411.z.number().int()]).optional(),
2293
- text: import_v411.z.string().optional()
2609
+ coordinate: import_v412.z.tuple([import_v412.z.number().int(), import_v412.z.number().int()]).optional(),
2610
+ duration: import_v412.z.number().optional(),
2611
+ scroll_amount: import_v412.z.number().optional(),
2612
+ scroll_direction: import_v412.z.enum(["up", "down", "left", "right"]).optional(),
2613
+ start_coordinate: import_v412.z.tuple([import_v412.z.number().int(), import_v412.z.number().int()]).optional(),
2614
+ text: import_v412.z.string().optional()
2294
2615
  })
2295
2616
  )
2296
2617
  );
2297
- var computer_20250124 = (0, import_provider_utils14.createProviderDefinedToolFactory)({
2618
+ var computer_20250124 = (0, import_provider_utils15.createProviderDefinedToolFactory)({
2298
2619
  id: "anthropic.computer_20250124",
2299
2620
  name: "computer",
2300
2621
  inputSchema: computer_20250124InputSchema
2301
2622
  });
2302
2623
 
2303
2624
  // src/tool/text-editor_20241022.ts
2304
- var import_provider_utils15 = require("@ai-sdk/provider-utils");
2305
- var import_v412 = require("zod/v4");
2306
- var textEditor_20241022InputSchema = (0, import_provider_utils15.lazySchema)(
2307
- () => (0, import_provider_utils15.zodSchema)(
2308
- import_v412.z.object({
2309
- command: import_v412.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
2310
- path: import_v412.z.string(),
2311
- file_text: import_v412.z.string().optional(),
2312
- insert_line: import_v412.z.number().int().optional(),
2313
- new_str: import_v412.z.string().optional(),
2314
- old_str: import_v412.z.string().optional(),
2315
- view_range: import_v412.z.array(import_v412.z.number().int()).optional()
2316
- })
2317
- )
2318
- );
2319
- var textEditor_20241022 = (0, import_provider_utils15.createProviderDefinedToolFactory)({
2320
- id: "anthropic.text_editor_20241022",
2321
- name: "str_replace_editor",
2322
- inputSchema: textEditor_20241022InputSchema
2323
- });
2324
-
2325
- // src/tool/text-editor_20250124.ts
2326
2625
  var import_provider_utils16 = require("@ai-sdk/provider-utils");
2327
2626
  var import_v413 = require("zod/v4");
2328
- var textEditor_20250124InputSchema = (0, import_provider_utils16.lazySchema)(
2627
+ var textEditor_20241022InputSchema = (0, import_provider_utils16.lazySchema)(
2329
2628
  () => (0, import_provider_utils16.zodSchema)(
2330
2629
  import_v413.z.object({
2331
2630
  command: import_v413.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
@@ -2338,19 +2637,19 @@ var textEditor_20250124InputSchema = (0, import_provider_utils16.lazySchema)(
2338
2637
  })
2339
2638
  )
2340
2639
  );
2341
- var textEditor_20250124 = (0, import_provider_utils16.createProviderDefinedToolFactory)({
2342
- id: "anthropic.text_editor_20250124",
2640
+ var textEditor_20241022 = (0, import_provider_utils16.createProviderDefinedToolFactory)({
2641
+ id: "anthropic.text_editor_20241022",
2343
2642
  name: "str_replace_editor",
2344
- inputSchema: textEditor_20250124InputSchema
2643
+ inputSchema: textEditor_20241022InputSchema
2345
2644
  });
2346
2645
 
2347
- // src/tool/text-editor_20250429.ts
2646
+ // src/tool/text-editor_20250124.ts
2348
2647
  var import_provider_utils17 = require("@ai-sdk/provider-utils");
2349
2648
  var import_v414 = require("zod/v4");
2350
- var textEditor_20250429InputSchema = (0, import_provider_utils17.lazySchema)(
2649
+ var textEditor_20250124InputSchema = (0, import_provider_utils17.lazySchema)(
2351
2650
  () => (0, import_provider_utils17.zodSchema)(
2352
2651
  import_v414.z.object({
2353
- command: import_v414.z.enum(["view", "create", "str_replace", "insert"]),
2652
+ command: import_v414.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
2354
2653
  path: import_v414.z.string(),
2355
2654
  file_text: import_v414.z.string().optional(),
2356
2655
  insert_line: import_v414.z.number().int().optional(),
@@ -2360,7 +2659,29 @@ var textEditor_20250429InputSchema = (0, import_provider_utils17.lazySchema)(
2360
2659
  })
2361
2660
  )
2362
2661
  );
2363
- var textEditor_20250429 = (0, import_provider_utils17.createProviderDefinedToolFactory)({
2662
+ var textEditor_20250124 = (0, import_provider_utils17.createProviderDefinedToolFactory)({
2663
+ id: "anthropic.text_editor_20250124",
2664
+ name: "str_replace_editor",
2665
+ inputSchema: textEditor_20250124InputSchema
2666
+ });
2667
+
2668
+ // src/tool/text-editor_20250429.ts
2669
+ var import_provider_utils18 = require("@ai-sdk/provider-utils");
2670
+ var import_v415 = require("zod/v4");
2671
+ var textEditor_20250429InputSchema = (0, import_provider_utils18.lazySchema)(
2672
+ () => (0, import_provider_utils18.zodSchema)(
2673
+ import_v415.z.object({
2674
+ command: import_v415.z.enum(["view", "create", "str_replace", "insert"]),
2675
+ path: import_v415.z.string(),
2676
+ file_text: import_v415.z.string().optional(),
2677
+ insert_line: import_v415.z.number().int().optional(),
2678
+ new_str: import_v415.z.string().optional(),
2679
+ old_str: import_v415.z.string().optional(),
2680
+ view_range: import_v415.z.array(import_v415.z.number().int()).optional()
2681
+ })
2682
+ )
2683
+ );
2684
+ var textEditor_20250429 = (0, import_provider_utils18.createProviderDefinedToolFactory)({
2364
2685
  id: "anthropic.text_editor_20250429",
2365
2686
  name: "str_replace_based_edit_tool",
2366
2687
  inputSchema: textEditor_20250429InputSchema
@@ -2397,6 +2718,19 @@ var anthropicTools = {
2397
2718
  * Tool name must be `code_execution`.
2398
2719
  */
2399
2720
  codeExecution_20250522,
2721
+ /**
2722
+ * Claude can analyze data, create visualizations, perform complex calculations,
2723
+ * run system commands, create and edit files, and process uploaded files directly within
2724
+ * the API conversation.
2725
+ *
2726
+ * The code execution tool allows Claude to run both Python and Bash commands and manipulate files,
2727
+ * including writing code, in a secure, sandboxed environment.
2728
+ *
2729
+ * This is the latest version with enhanced Bash support and file operations.
2730
+ *
2731
+ * Tool name must be `code_execution`.
2732
+ */
2733
+ codeExecution_20250825,
2400
2734
  /**
2401
2735
  * Claude can interact with computer environments through the computer use tool, which
2402
2736
  * provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.