@ai-sdk/anthropic 2.0.70 → 2.0.72

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.
@@ -18,13 +18,13 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/internal/index.ts
21
- var internal_exports = {};
22
- __export(internal_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  AnthropicMessagesLanguageModel: () => AnthropicMessagesLanguageModel,
24
24
  anthropicTools: () => anthropicTools,
25
25
  prepareTools: () => prepareTools
26
26
  });
27
- module.exports = __toCommonJS(internal_exports);
27
+ module.exports = __toCommonJS(index_exports);
28
28
 
29
29
  // src/anthropic-messages-language-model.ts
30
30
  var import_provider3 = require("@ai-sdk/provider");
@@ -666,6 +666,20 @@ var anthropicProviderOptions = import_v43.z.object({
666
666
  type: import_v43.z.literal("ephemeral"),
667
667
  ttl: import_v43.z.union([import_v43.z.literal("5m"), import_v43.z.literal("1h")]).optional()
668
668
  }).optional(),
669
+ /**
670
+ * Metadata to include with the request.
671
+ *
672
+ * See https://platform.claude.com/docs/en/api/messages/create for details.
673
+ */
674
+ metadata: import_v43.z.object({
675
+ /**
676
+ * An external identifier for the user associated with the request.
677
+ *
678
+ * Should be a UUID, hash value, or other opaque identifier.
679
+ * Must not contain PII (name, email, phone number, etc.).
680
+ */
681
+ userId: import_v43.z.string().optional()
682
+ }).optional(),
669
683
  /**
670
684
  * Agent Skills configuration. Skills enable Claude to perform specialized tasks
671
685
  * like document processing (PPTX, DOCX, PDF, XLSX) and data analysis.
@@ -987,6 +1001,13 @@ async function prepareTools({
987
1001
  });
988
1002
  break;
989
1003
  }
1004
+ case "anthropic.code_execution_20260120": {
1005
+ anthropicTools2.push({
1006
+ type: "code_execution_20260120",
1007
+ name: "code_execution"
1008
+ });
1009
+ break;
1010
+ }
990
1011
  case "anthropic.computer_20250124": {
991
1012
  betas.add("computer-use-2025-01-24");
992
1013
  anthropicTools2.push({
@@ -1944,7 +1965,7 @@ var AnthropicMessagesLanguageModel = class {
1944
1965
  toolChoice,
1945
1966
  providerOptions
1946
1967
  }) {
1947
- var _a, _b, _c, _d, _e, _f;
1968
+ var _a, _b, _c, _d, _e, _f, _g;
1948
1969
  const warnings = [];
1949
1970
  if (frequencyPenalty != null) {
1950
1971
  warnings.push({
@@ -2048,6 +2069,9 @@ var AnthropicMessagesLanguageModel = class {
2048
2069
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
2049
2070
  cache_control: anthropicOptions.cacheControl
2050
2071
  },
2072
+ ...((_e = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _e.userId) != null && {
2073
+ metadata: { user_id: anthropicOptions.metadata.userId }
2074
+ },
2051
2075
  // structured output:
2052
2076
  ...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
2053
2077
  output_format: {
@@ -2059,7 +2083,7 @@ var AnthropicMessagesLanguageModel = class {
2059
2083
  ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
2060
2084
  container: {
2061
2085
  id: anthropicOptions.container.id,
2062
- skills: (_e = anthropicOptions.container.skills) == null ? void 0 : _e.map((skill) => ({
2086
+ skills: (_f = anthropicOptions.container.skills) == null ? void 0 : _f.map((skill) => ({
2063
2087
  type: skill.type,
2064
2088
  skill_id: skill.skillId,
2065
2089
  version: skill.version
@@ -2168,7 +2192,7 @@ var AnthropicMessagesLanguageModel = class {
2168
2192
  betas.add("skills-2025-10-02");
2169
2193
  betas.add("files-api-2025-04-14");
2170
2194
  if (!(tools == null ? void 0 : tools.some(
2171
- (tool) => tool.type === "provider-defined" && tool.id === "anthropic.code_execution_20250825"
2195
+ (tool) => tool.type === "provider-defined" && (tool.id === "anthropic.code_execution_20250825" || tool.id === "anthropic.code_execution_20260120")
2172
2196
  ))) {
2173
2197
  warnings.push({
2174
2198
  type: "other",
@@ -2222,7 +2246,7 @@ var AnthropicMessagesLanguageModel = class {
2222
2246
  ...betas,
2223
2247
  ...toolsBetas,
2224
2248
  ...userSuppliedBetas,
2225
- ...(_f = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _f : []
2249
+ ...(_g = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _g : []
2226
2250
  ]),
2227
2251
  usesJsonResponseTool: jsonResponseTool != null
2228
2252
  };
@@ -3271,13 +3295,118 @@ var bash_20250124 = (0, import_provider_utils13.createProviderDefinedToolFactory
3271
3295
  inputSchema: bash_20250124InputSchema
3272
3296
  });
3273
3297
 
3274
- // src/tool/computer_20241022.ts
3298
+ // src/tool/code-execution_20260120.ts
3275
3299
  var import_provider_utils14 = require("@ai-sdk/provider-utils");
3276
3300
  var import_v411 = require("zod/v4");
3277
- var computer_20241022InputSchema = (0, import_provider_utils14.lazySchema)(
3301
+ var codeExecution_20260120OutputSchema = (0, import_provider_utils14.lazySchema)(
3302
+ () => (0, import_provider_utils14.zodSchema)(
3303
+ import_v411.z.discriminatedUnion("type", [
3304
+ import_v411.z.object({
3305
+ type: import_v411.z.literal("code_execution_result"),
3306
+ stdout: import_v411.z.string(),
3307
+ stderr: import_v411.z.string(),
3308
+ return_code: import_v411.z.number(),
3309
+ content: import_v411.z.array(
3310
+ import_v411.z.object({
3311
+ type: import_v411.z.literal("code_execution_output"),
3312
+ file_id: import_v411.z.string()
3313
+ })
3314
+ ).optional().default([])
3315
+ }),
3316
+ import_v411.z.object({
3317
+ type: import_v411.z.literal("bash_code_execution_result"),
3318
+ content: import_v411.z.array(
3319
+ import_v411.z.object({
3320
+ type: import_v411.z.literal("bash_code_execution_output"),
3321
+ file_id: import_v411.z.string()
3322
+ })
3323
+ ),
3324
+ stdout: import_v411.z.string(),
3325
+ stderr: import_v411.z.string(),
3326
+ return_code: import_v411.z.number()
3327
+ }),
3328
+ import_v411.z.object({
3329
+ type: import_v411.z.literal("bash_code_execution_tool_result_error"),
3330
+ error_code: import_v411.z.string()
3331
+ }),
3332
+ import_v411.z.object({
3333
+ type: import_v411.z.literal("text_editor_code_execution_tool_result_error"),
3334
+ error_code: import_v411.z.string()
3335
+ }),
3336
+ import_v411.z.object({
3337
+ type: import_v411.z.literal("text_editor_code_execution_view_result"),
3338
+ content: import_v411.z.string(),
3339
+ file_type: import_v411.z.string(),
3340
+ num_lines: import_v411.z.number().nullable(),
3341
+ start_line: import_v411.z.number().nullable(),
3342
+ total_lines: import_v411.z.number().nullable()
3343
+ }),
3344
+ import_v411.z.object({
3345
+ type: import_v411.z.literal("text_editor_code_execution_create_result"),
3346
+ is_file_update: import_v411.z.boolean()
3347
+ }),
3348
+ import_v411.z.object({
3349
+ type: import_v411.z.literal("text_editor_code_execution_str_replace_result"),
3350
+ lines: import_v411.z.array(import_v411.z.string()).nullable(),
3351
+ new_lines: import_v411.z.number().nullable(),
3352
+ new_start: import_v411.z.number().nullable(),
3353
+ old_lines: import_v411.z.number().nullable(),
3354
+ old_start: import_v411.z.number().nullable()
3355
+ })
3356
+ ])
3357
+ )
3358
+ );
3359
+ var codeExecution_20260120InputSchema = (0, import_provider_utils14.lazySchema)(
3278
3360
  () => (0, import_provider_utils14.zodSchema)(
3279
- import_v411.z.object({
3280
- action: import_v411.z.enum([
3361
+ import_v411.z.discriminatedUnion("type", [
3362
+ import_v411.z.object({
3363
+ type: import_v411.z.literal("programmatic-tool-call"),
3364
+ code: import_v411.z.string()
3365
+ }),
3366
+ import_v411.z.object({
3367
+ type: import_v411.z.literal("bash_code_execution"),
3368
+ command: import_v411.z.string()
3369
+ }),
3370
+ import_v411.z.discriminatedUnion("command", [
3371
+ import_v411.z.object({
3372
+ type: import_v411.z.literal("text_editor_code_execution"),
3373
+ command: import_v411.z.literal("view"),
3374
+ path: import_v411.z.string()
3375
+ }),
3376
+ import_v411.z.object({
3377
+ type: import_v411.z.literal("text_editor_code_execution"),
3378
+ command: import_v411.z.literal("create"),
3379
+ path: import_v411.z.string(),
3380
+ file_text: import_v411.z.string().nullish()
3381
+ }),
3382
+ import_v411.z.object({
3383
+ type: import_v411.z.literal("text_editor_code_execution"),
3384
+ command: import_v411.z.literal("str_replace"),
3385
+ path: import_v411.z.string(),
3386
+ old_str: import_v411.z.string(),
3387
+ new_str: import_v411.z.string()
3388
+ })
3389
+ ])
3390
+ ])
3391
+ )
3392
+ );
3393
+ var factory6 = (0, import_provider_utils14.createProviderDefinedToolFactoryWithOutputSchema)({
3394
+ id: "anthropic.code_execution_20260120",
3395
+ name: "code_execution",
3396
+ inputSchema: codeExecution_20260120InputSchema,
3397
+ outputSchema: codeExecution_20260120OutputSchema
3398
+ });
3399
+ var codeExecution_20260120 = (args = {}) => {
3400
+ return factory6(args);
3401
+ };
3402
+
3403
+ // src/tool/computer_20241022.ts
3404
+ var import_provider_utils15 = require("@ai-sdk/provider-utils");
3405
+ var import_v412 = require("zod/v4");
3406
+ var computer_20241022InputSchema = (0, import_provider_utils15.lazySchema)(
3407
+ () => (0, import_provider_utils15.zodSchema)(
3408
+ import_v412.z.object({
3409
+ action: import_v412.z.enum([
3281
3410
  "key",
3282
3411
  "type",
3283
3412
  "mouse_move",
@@ -3289,24 +3418,24 @@ var computer_20241022InputSchema = (0, import_provider_utils14.lazySchema)(
3289
3418
  "screenshot",
3290
3419
  "cursor_position"
3291
3420
  ]),
3292
- coordinate: import_v411.z.array(import_v411.z.number().int()).optional(),
3293
- text: import_v411.z.string().optional()
3421
+ coordinate: import_v412.z.array(import_v412.z.number().int()).optional(),
3422
+ text: import_v412.z.string().optional()
3294
3423
  })
3295
3424
  )
3296
3425
  );
3297
- var computer_20241022 = (0, import_provider_utils14.createProviderDefinedToolFactory)({
3426
+ var computer_20241022 = (0, import_provider_utils15.createProviderDefinedToolFactory)({
3298
3427
  id: "anthropic.computer_20241022",
3299
3428
  name: "computer",
3300
3429
  inputSchema: computer_20241022InputSchema
3301
3430
  });
3302
3431
 
3303
3432
  // src/tool/computer_20250124.ts
3304
- var import_provider_utils15 = require("@ai-sdk/provider-utils");
3305
- var import_v412 = require("zod/v4");
3306
- var computer_20250124InputSchema = (0, import_provider_utils15.lazySchema)(
3307
- () => (0, import_provider_utils15.zodSchema)(
3308
- import_v412.z.object({
3309
- action: import_v412.z.enum([
3433
+ var import_provider_utils16 = require("@ai-sdk/provider-utils");
3434
+ var import_v413 = require("zod/v4");
3435
+ var computer_20250124InputSchema = (0, import_provider_utils16.lazySchema)(
3436
+ () => (0, import_provider_utils16.zodSchema)(
3437
+ import_v413.z.object({
3438
+ action: import_v413.z.enum([
3310
3439
  "key",
3311
3440
  "hold_key",
3312
3441
  "type",
@@ -3324,93 +3453,71 @@ var computer_20250124InputSchema = (0, import_provider_utils15.lazySchema)(
3324
3453
  "wait",
3325
3454
  "screenshot"
3326
3455
  ]),
3327
- coordinate: import_v412.z.tuple([import_v412.z.number().int(), import_v412.z.number().int()]).optional(),
3328
- duration: import_v412.z.number().optional(),
3329
- scroll_amount: import_v412.z.number().optional(),
3330
- scroll_direction: import_v412.z.enum(["up", "down", "left", "right"]).optional(),
3331
- start_coordinate: import_v412.z.tuple([import_v412.z.number().int(), import_v412.z.number().int()]).optional(),
3332
- text: import_v412.z.string().optional()
3456
+ coordinate: import_v413.z.tuple([import_v413.z.number().int(), import_v413.z.number().int()]).optional(),
3457
+ duration: import_v413.z.number().optional(),
3458
+ scroll_amount: import_v413.z.number().optional(),
3459
+ scroll_direction: import_v413.z.enum(["up", "down", "left", "right"]).optional(),
3460
+ start_coordinate: import_v413.z.tuple([import_v413.z.number().int(), import_v413.z.number().int()]).optional(),
3461
+ text: import_v413.z.string().optional()
3333
3462
  })
3334
3463
  )
3335
3464
  );
3336
- var computer_20250124 = (0, import_provider_utils15.createProviderDefinedToolFactory)({
3465
+ var computer_20250124 = (0, import_provider_utils16.createProviderDefinedToolFactory)({
3337
3466
  id: "anthropic.computer_20250124",
3338
3467
  name: "computer",
3339
3468
  inputSchema: computer_20250124InputSchema
3340
3469
  });
3341
3470
 
3342
3471
  // src/tool/memory_20250818.ts
3343
- var import_provider_utils16 = require("@ai-sdk/provider-utils");
3344
- var import_v413 = require("zod/v4");
3345
- var memory_20250818InputSchema = (0, import_provider_utils16.lazySchema)(
3346
- () => (0, import_provider_utils16.zodSchema)(
3347
- import_v413.z.discriminatedUnion("command", [
3348
- import_v413.z.object({
3349
- command: import_v413.z.literal("view"),
3350
- path: import_v413.z.string(),
3351
- view_range: import_v413.z.tuple([import_v413.z.number(), import_v413.z.number()]).optional()
3472
+ var import_provider_utils17 = require("@ai-sdk/provider-utils");
3473
+ var import_v414 = require("zod/v4");
3474
+ var memory_20250818InputSchema = (0, import_provider_utils17.lazySchema)(
3475
+ () => (0, import_provider_utils17.zodSchema)(
3476
+ import_v414.z.discriminatedUnion("command", [
3477
+ import_v414.z.object({
3478
+ command: import_v414.z.literal("view"),
3479
+ path: import_v414.z.string(),
3480
+ view_range: import_v414.z.tuple([import_v414.z.number(), import_v414.z.number()]).optional()
3352
3481
  }),
3353
- import_v413.z.object({
3354
- command: import_v413.z.literal("create"),
3355
- path: import_v413.z.string(),
3356
- file_text: import_v413.z.string()
3482
+ import_v414.z.object({
3483
+ command: import_v414.z.literal("create"),
3484
+ path: import_v414.z.string(),
3485
+ file_text: import_v414.z.string()
3357
3486
  }),
3358
- import_v413.z.object({
3359
- command: import_v413.z.literal("str_replace"),
3360
- path: import_v413.z.string(),
3361
- old_str: import_v413.z.string(),
3362
- new_str: import_v413.z.string()
3487
+ import_v414.z.object({
3488
+ command: import_v414.z.literal("str_replace"),
3489
+ path: import_v414.z.string(),
3490
+ old_str: import_v414.z.string(),
3491
+ new_str: import_v414.z.string()
3363
3492
  }),
3364
- import_v413.z.object({
3365
- command: import_v413.z.literal("insert"),
3366
- path: import_v413.z.string(),
3367
- insert_line: import_v413.z.number(),
3368
- insert_text: import_v413.z.string()
3493
+ import_v414.z.object({
3494
+ command: import_v414.z.literal("insert"),
3495
+ path: import_v414.z.string(),
3496
+ insert_line: import_v414.z.number(),
3497
+ insert_text: import_v414.z.string()
3369
3498
  }),
3370
- import_v413.z.object({
3371
- command: import_v413.z.literal("delete"),
3372
- path: import_v413.z.string()
3499
+ import_v414.z.object({
3500
+ command: import_v414.z.literal("delete"),
3501
+ path: import_v414.z.string()
3373
3502
  }),
3374
- import_v413.z.object({
3375
- command: import_v413.z.literal("rename"),
3376
- old_path: import_v413.z.string(),
3377
- new_path: import_v413.z.string()
3503
+ import_v414.z.object({
3504
+ command: import_v414.z.literal("rename"),
3505
+ old_path: import_v414.z.string(),
3506
+ new_path: import_v414.z.string()
3378
3507
  })
3379
3508
  ])
3380
3509
  )
3381
3510
  );
3382
- var memory_20250818 = (0, import_provider_utils16.createProviderDefinedToolFactory)({
3511
+ var memory_20250818 = (0, import_provider_utils17.createProviderDefinedToolFactory)({
3383
3512
  id: "anthropic.memory_20250818",
3384
3513
  name: "memory",
3385
3514
  inputSchema: memory_20250818InputSchema
3386
3515
  });
3387
3516
 
3388
3517
  // src/tool/text-editor_20241022.ts
3389
- var import_provider_utils17 = require("@ai-sdk/provider-utils");
3390
- var import_v414 = require("zod/v4");
3391
- var textEditor_20241022InputSchema = (0, import_provider_utils17.lazySchema)(
3392
- () => (0, import_provider_utils17.zodSchema)(
3393
- import_v414.z.object({
3394
- command: import_v414.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
3395
- path: import_v414.z.string(),
3396
- file_text: import_v414.z.string().optional(),
3397
- insert_line: import_v414.z.number().int().optional(),
3398
- new_str: import_v414.z.string().optional(),
3399
- old_str: import_v414.z.string().optional(),
3400
- view_range: import_v414.z.array(import_v414.z.number().int()).optional()
3401
- })
3402
- )
3403
- );
3404
- var textEditor_20241022 = (0, import_provider_utils17.createProviderDefinedToolFactory)({
3405
- id: "anthropic.text_editor_20241022",
3406
- name: "str_replace_editor",
3407
- inputSchema: textEditor_20241022InputSchema
3408
- });
3409
-
3410
- // src/tool/text-editor_20250124.ts
3411
3518
  var import_provider_utils18 = require("@ai-sdk/provider-utils");
3412
3519
  var import_v415 = require("zod/v4");
3413
- var textEditor_20250124InputSchema = (0, import_provider_utils18.lazySchema)(
3520
+ var textEditor_20241022InputSchema = (0, import_provider_utils18.lazySchema)(
3414
3521
  () => (0, import_provider_utils18.zodSchema)(
3415
3522
  import_v415.z.object({
3416
3523
  command: import_v415.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
@@ -3423,19 +3530,19 @@ var textEditor_20250124InputSchema = (0, import_provider_utils18.lazySchema)(
3423
3530
  })
3424
3531
  )
3425
3532
  );
3426
- var textEditor_20250124 = (0, import_provider_utils18.createProviderDefinedToolFactory)({
3427
- id: "anthropic.text_editor_20250124",
3533
+ var textEditor_20241022 = (0, import_provider_utils18.createProviderDefinedToolFactory)({
3534
+ id: "anthropic.text_editor_20241022",
3428
3535
  name: "str_replace_editor",
3429
- inputSchema: textEditor_20250124InputSchema
3536
+ inputSchema: textEditor_20241022InputSchema
3430
3537
  });
3431
3538
 
3432
- // src/tool/text-editor_20250429.ts
3539
+ // src/tool/text-editor_20250124.ts
3433
3540
  var import_provider_utils19 = require("@ai-sdk/provider-utils");
3434
3541
  var import_v416 = require("zod/v4");
3435
- var textEditor_20250429InputSchema = (0, import_provider_utils19.lazySchema)(
3542
+ var textEditor_20250124InputSchema = (0, import_provider_utils19.lazySchema)(
3436
3543
  () => (0, import_provider_utils19.zodSchema)(
3437
3544
  import_v416.z.object({
3438
- command: import_v416.z.enum(["view", "create", "str_replace", "insert"]),
3545
+ command: import_v416.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
3439
3546
  path: import_v416.z.string(),
3440
3547
  file_text: import_v416.z.string().optional(),
3441
3548
  insert_line: import_v416.z.number().int().optional(),
@@ -3445,7 +3552,29 @@ var textEditor_20250429InputSchema = (0, import_provider_utils19.lazySchema)(
3445
3552
  })
3446
3553
  )
3447
3554
  );
3448
- var textEditor_20250429 = (0, import_provider_utils19.createProviderDefinedToolFactory)({
3555
+ var textEditor_20250124 = (0, import_provider_utils19.createProviderDefinedToolFactory)({
3556
+ id: "anthropic.text_editor_20250124",
3557
+ name: "str_replace_editor",
3558
+ inputSchema: textEditor_20250124InputSchema
3559
+ });
3560
+
3561
+ // src/tool/text-editor_20250429.ts
3562
+ var import_provider_utils20 = require("@ai-sdk/provider-utils");
3563
+ var import_v417 = require("zod/v4");
3564
+ var textEditor_20250429InputSchema = (0, import_provider_utils20.lazySchema)(
3565
+ () => (0, import_provider_utils20.zodSchema)(
3566
+ import_v417.z.object({
3567
+ command: import_v417.z.enum(["view", "create", "str_replace", "insert"]),
3568
+ path: import_v417.z.string(),
3569
+ file_text: import_v417.z.string().optional(),
3570
+ insert_line: import_v417.z.number().int().optional(),
3571
+ new_str: import_v417.z.string().optional(),
3572
+ old_str: import_v417.z.string().optional(),
3573
+ view_range: import_v417.z.array(import_v417.z.number().int()).optional()
3574
+ })
3575
+ )
3576
+ );
3577
+ var textEditor_20250429 = (0, import_provider_utils20.createProviderDefinedToolFactory)({
3449
3578
  id: "anthropic.text_editor_20250429",
3450
3579
  name: "str_replace_based_edit_tool",
3451
3580
  inputSchema: textEditor_20250429InputSchema
@@ -3495,6 +3624,19 @@ var anthropicTools = {
3495
3624
  * Tool name must be `code_execution`.
3496
3625
  */
3497
3626
  codeExecution_20250825,
3627
+ /**
3628
+ * Claude can analyze data, create visualizations, perform complex calculations,
3629
+ * run system commands, create and edit files, and process uploaded files directly within
3630
+ * the API conversation.
3631
+ *
3632
+ * The code execution tool allows Claude to run both Python and Bash commands and manipulate files,
3633
+ * including writing code, in a secure, sandboxed environment.
3634
+ *
3635
+ * This is the recommended version. Does not require a beta header.
3636
+ *
3637
+ * Supported models: Claude Opus 4.6, Sonnet 4.6, Sonnet 4.5, Opus 4.5
3638
+ */
3639
+ codeExecution_20260120,
3498
3640
  /**
3499
3641
  * Claude can interact with computer environments through the computer use tool, which
3500
3642
  * provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.