@ai-sdk/anthropic 3.0.0-beta.78 → 3.0.0-beta.80

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.
@@ -360,7 +360,7 @@ declare const anthropicTools: {
360
360
  url: string;
361
361
  content: {
362
362
  type: "document";
363
- title: string;
363
+ title: string | null;
364
364
  citations?: {
365
365
  enabled: boolean;
366
366
  };
@@ -390,7 +390,7 @@ declare const anthropicTools: {
390
390
  url: string;
391
391
  content: {
392
392
  type: "document";
393
- title: string;
393
+ title: string | null;
394
394
  citations?: {
395
395
  enabled: boolean;
396
396
  };
@@ -419,7 +419,7 @@ declare const anthropicTools: {
419
419
  }, {
420
420
  type: "web_search_result";
421
421
  url: string;
422
- title: string;
422
+ title: string | null;
423
423
  pageAge: string | null;
424
424
  encryptedContent: string;
425
425
  }[], {
@@ -429,7 +429,27 @@ declare const anthropicTools: {
429
429
  userLocation?: {
430
430
  type: "approximate";
431
431
  city?: string;
432
- region?: string;
432
+ region
433
+ /**
434
+ * Claude can interact with computer environments through the computer use tool, which
435
+ * provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.
436
+ *
437
+ * Image results are supported.
438
+ *
439
+ * @param displayWidthPx - The width of the display being controlled by the model in pixels.
440
+ * @param displayHeightPx - The height of the display being controlled by the model in pixels.
441
+ * @param displayNumber - The display number to control (only relevant for X11 environments). If specified, the tool will be provided a display number in the tool definition.
442
+ */
443
+ ? /**
444
+ * Claude can interact with computer environments through the computer use tool, which
445
+ * provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.
446
+ *
447
+ * Image results are supported.
448
+ *
449
+ * @param displayWidthPx - The width of the display being controlled by the model in pixels.
450
+ * @param displayHeightPx - The height of the display being controlled by the model in pixels.
451
+ * @param displayNumber - The display number to control (only relevant for X11 environments). If specified, the tool will be provided a display number in the tool definition.
452
+ */: string;
433
453
  country?: string;
434
454
  timezone?: string;
435
455
  };
@@ -438,7 +458,7 @@ declare const anthropicTools: {
438
458
  }, {
439
459
  type: "web_search_result";
440
460
  url: string;
441
- title: string;
461
+ title: string | null;
442
462
  pageAge: string | null;
443
463
  encryptedContent: string;
444
464
  }[]>;
@@ -360,7 +360,7 @@ declare const anthropicTools: {
360
360
  url: string;
361
361
  content: {
362
362
  type: "document";
363
- title: string;
363
+ title: string | null;
364
364
  citations?: {
365
365
  enabled: boolean;
366
366
  };
@@ -390,7 +390,7 @@ declare const anthropicTools: {
390
390
  url: string;
391
391
  content: {
392
392
  type: "document";
393
- title: string;
393
+ title: string | null;
394
394
  citations?: {
395
395
  enabled: boolean;
396
396
  };
@@ -419,7 +419,7 @@ declare const anthropicTools: {
419
419
  }, {
420
420
  type: "web_search_result";
421
421
  url: string;
422
- title: string;
422
+ title: string | null;
423
423
  pageAge: string | null;
424
424
  encryptedContent: string;
425
425
  }[], {
@@ -429,7 +429,27 @@ declare const anthropicTools: {
429
429
  userLocation?: {
430
430
  type: "approximate";
431
431
  city?: string;
432
- region?: string;
432
+ region
433
+ /**
434
+ * Claude can interact with computer environments through the computer use tool, which
435
+ * provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.
436
+ *
437
+ * Image results are supported.
438
+ *
439
+ * @param displayWidthPx - The width of the display being controlled by the model in pixels.
440
+ * @param displayHeightPx - The height of the display being controlled by the model in pixels.
441
+ * @param displayNumber - The display number to control (only relevant for X11 environments). If specified, the tool will be provided a display number in the tool definition.
442
+ */
443
+ ? /**
444
+ * Claude can interact with computer environments through the computer use tool, which
445
+ * provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.
446
+ *
447
+ * Image results are supported.
448
+ *
449
+ * @param displayWidthPx - The width of the display being controlled by the model in pixels.
450
+ * @param displayHeightPx - The height of the display being controlled by the model in pixels.
451
+ * @param displayNumber - The display number to control (only relevant for X11 environments). If specified, the tool will be provided a display number in the tool definition.
452
+ */: string;
433
453
  country?: string;
434
454
  timezone?: string;
435
455
  };
@@ -438,7 +458,7 @@ declare const anthropicTools: {
438
458
  }, {
439
459
  type: "web_search_result";
440
460
  url: string;
441
- title: string;
461
+ title: string | null;
442
462
  pageAge: string | null;
443
463
  encryptedContent: string;
444
464
  }[]>;
@@ -49,6 +49,29 @@ var anthropicFailedResponseHandler = (0, import_provider_utils.createJsonErrorRe
49
49
  errorToMessage: (data) => data.error.message
50
50
  });
51
51
 
52
+ // src/convert-anthropic-messages-usage.ts
53
+ function convertAnthropicMessagesUsage(usage) {
54
+ var _a, _b;
55
+ const inputTokens = usage.input_tokens;
56
+ const outputTokens = usage.output_tokens;
57
+ const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
58
+ const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
59
+ return {
60
+ inputTokens: {
61
+ total: inputTokens + cacheCreationTokens + cacheReadTokens,
62
+ noCache: inputTokens,
63
+ cacheRead: cacheReadTokens,
64
+ cacheWrite: cacheCreationTokens
65
+ },
66
+ outputTokens: {
67
+ total: outputTokens,
68
+ text: void 0,
69
+ reasoning: void 0
70
+ },
71
+ raw: usage
72
+ };
73
+ }
74
+
52
75
  // src/anthropic-messages-api.ts
53
76
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
54
77
  var import_v42 = require("zod/v4");
@@ -874,7 +897,7 @@ var webSearch_20250305OutputSchema = (0, import_provider_utils5.lazySchema)(
874
897
  import_v45.z.array(
875
898
  import_v45.z.object({
876
899
  url: import_v45.z.string(),
877
- title: import_v45.z.string(),
900
+ title: import_v45.z.string().nullable(),
878
901
  pageAge: import_v45.z.string().nullable(),
879
902
  encryptedContent: import_v45.z.string(),
880
903
  type: import_v45.z.literal("web_search_result")
@@ -919,7 +942,7 @@ var webFetch_20250910OutputSchema = (0, import_provider_utils6.lazySchema)(
919
942
  url: import_v46.z.string(),
920
943
  content: import_v46.z.object({
921
944
  type: import_v46.z.literal("document"),
922
- title: import_v46.z.string(),
945
+ title: import_v46.z.string().nullable(),
923
946
  citations: import_v46.z.object({ enabled: import_v46.z.boolean() }).optional(),
924
947
  source: import_v46.z.union([
925
948
  import_v46.z.object({
@@ -2483,7 +2506,7 @@ var AnthropicMessagesLanguageModel = class {
2483
2506
  });
2484
2507
  }
2485
2508
  async doGenerate(options) {
2486
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2509
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2487
2510
  const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
2488
2511
  ...options,
2489
2512
  stream: false,
@@ -2782,16 +2805,11 @@ var AnthropicMessagesLanguageModel = class {
2782
2805
  finishReason: response.stop_reason,
2783
2806
  isJsonResponseFromTool
2784
2807
  }),
2785
- usage: {
2786
- inputTokens: response.usage.input_tokens,
2787
- outputTokens: response.usage.output_tokens,
2788
- totalTokens: response.usage.input_tokens + response.usage.output_tokens,
2789
- cachedInputTokens: (_b = response.usage.cache_read_input_tokens) != null ? _b : void 0
2790
- },
2808
+ usage: convertAnthropicMessagesUsage(response.usage),
2791
2809
  request: { body: args },
2792
2810
  response: {
2793
- id: (_c = response.id) != null ? _c : void 0,
2794
- modelId: (_d = response.model) != null ? _d : void 0,
2811
+ id: (_b = response.id) != null ? _b : void 0,
2812
+ modelId: (_c = response.model) != null ? _c : void 0,
2795
2813
  headers: responseHeaders,
2796
2814
  body: rawResponse
2797
2815
  },
@@ -2799,20 +2817,20 @@ var AnthropicMessagesLanguageModel = class {
2799
2817
  providerMetadata: {
2800
2818
  anthropic: {
2801
2819
  usage: response.usage,
2802
- cacheCreationInputTokens: (_e = response.usage.cache_creation_input_tokens) != null ? _e : null,
2803
- stopSequence: (_f = response.stop_sequence) != null ? _f : null,
2820
+ cacheCreationInputTokens: (_d = response.usage.cache_creation_input_tokens) != null ? _d : null,
2821
+ stopSequence: (_e = response.stop_sequence) != null ? _e : null,
2804
2822
  container: response.container ? {
2805
2823
  expiresAt: response.container.expires_at,
2806
2824
  id: response.container.id,
2807
- skills: (_h = (_g = response.container.skills) == null ? void 0 : _g.map((skill) => ({
2825
+ skills: (_g = (_f = response.container.skills) == null ? void 0 : _f.map((skill) => ({
2808
2826
  type: skill.type,
2809
2827
  skillId: skill.skill_id,
2810
2828
  version: skill.version
2811
- }))) != null ? _h : null
2829
+ }))) != null ? _g : null
2812
2830
  } : null,
2813
- contextManagement: (_i = mapAnthropicResponseContextManagement(
2831
+ contextManagement: (_h = mapAnthropicResponseContextManagement(
2814
2832
  response.context_management
2815
- )) != null ? _i : null
2833
+ )) != null ? _h : null
2816
2834
  }
2817
2835
  }
2818
2836
  };
@@ -2845,9 +2863,10 @@ var AnthropicMessagesLanguageModel = class {
2845
2863
  });
2846
2864
  let finishReason = "unknown";
2847
2865
  const usage = {
2848
- inputTokens: void 0,
2849
- outputTokens: void 0,
2850
- totalTokens: void 0
2866
+ input_tokens: 0,
2867
+ output_tokens: 0,
2868
+ cache_creation_input_tokens: 0,
2869
+ cache_read_input_tokens: 0
2851
2870
  };
2852
2871
  const contentBlocks = {};
2853
2872
  const mcpToolCalls = {};
@@ -2865,7 +2884,7 @@ var AnthropicMessagesLanguageModel = class {
2865
2884
  controller.enqueue({ type: "stream-start", warnings });
2866
2885
  },
2867
2886
  transform(chunk, controller) {
2868
- var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
2887
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
2869
2888
  if (options.includeRawChunks) {
2870
2889
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2871
2890
  }
@@ -3304,35 +3323,35 @@ var AnthropicMessagesLanguageModel = class {
3304
3323
  }
3305
3324
  }
3306
3325
  case "message_start": {
3307
- usage.inputTokens = value.message.usage.input_tokens;
3308
- usage.cachedInputTokens = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : void 0;
3326
+ usage.input_tokens = value.message.usage.input_tokens;
3327
+ usage.cache_read_input_tokens = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : 0;
3328
+ usage.cache_creation_input_tokens = (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : 0;
3309
3329
  rawUsage = {
3310
3330
  ...value.message.usage
3311
3331
  };
3312
- cacheCreationInputTokens = (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null;
3332
+ cacheCreationInputTokens = (_d = value.message.usage.cache_creation_input_tokens) != null ? _d : null;
3313
3333
  controller.enqueue({
3314
3334
  type: "response-metadata",
3315
- id: (_d = value.message.id) != null ? _d : void 0,
3316
- modelId: (_e = value.message.model) != null ? _e : void 0
3335
+ id: (_e = value.message.id) != null ? _e : void 0,
3336
+ modelId: (_f = value.message.model) != null ? _f : void 0
3317
3337
  });
3318
3338
  return;
3319
3339
  }
3320
3340
  case "message_delta": {
3321
- usage.outputTokens = value.usage.output_tokens;
3322
- usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
3341
+ usage.output_tokens = value.usage.output_tokens;
3323
3342
  finishReason = mapAnthropicStopReason({
3324
3343
  finishReason: value.delta.stop_reason,
3325
3344
  isJsonResponseFromTool
3326
3345
  });
3327
- stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
3346
+ stopSequence = (_g = value.delta.stop_sequence) != null ? _g : null;
3328
3347
  container = value.delta.container != null ? {
3329
3348
  expiresAt: value.delta.container.expires_at,
3330
3349
  id: value.delta.container.id,
3331
- skills: (_j = (_i = value.delta.container.skills) == null ? void 0 : _i.map((skill) => ({
3350
+ skills: (_i = (_h = value.delta.container.skills) == null ? void 0 : _h.map((skill) => ({
3332
3351
  type: skill.type,
3333
3352
  skillId: skill.skill_id,
3334
3353
  version: skill.version
3335
- }))) != null ? _j : null
3354
+ }))) != null ? _i : null
3336
3355
  } : null;
3337
3356
  if (value.delta.context_management) {
3338
3357
  contextManagement = mapAnthropicResponseContextManagement(
@@ -3349,7 +3368,7 @@ var AnthropicMessagesLanguageModel = class {
3349
3368
  controller.enqueue({
3350
3369
  type: "finish",
3351
3370
  finishReason,
3352
- usage,
3371
+ usage: convertAnthropicMessagesUsage(usage),
3353
3372
  providerMetadata: {
3354
3373
  anthropic: {
3355
3374
  usage: rawUsage != null ? rawUsage : null,