@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.
- package/CHANGELOG.md +15 -0
- package/dist/index.d.mts +25 -5
- package/dist/index.d.ts +25 -5
- package/dist/index.js +52 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -33
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +25 -5
- package/dist/internal/index.d.ts +25 -5
- package/dist/internal/index.js +51 -32
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +51 -32
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 3.0.0-beta.80
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 05d5b9a: fix(anthropic): make title field nullable in web_fetch and web_search tool output schemas
|
|
8
|
+
|
|
9
|
+
## 3.0.0-beta.79
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 3bd2689: feat: extended token usage
|
|
14
|
+
- Updated dependencies [3bd2689]
|
|
15
|
+
- @ai-sdk/provider@3.0.0-beta.26
|
|
16
|
+
- @ai-sdk/provider-utils@4.0.0-beta.45
|
|
17
|
+
|
|
3
18
|
## 3.0.0-beta.78
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -497,7 +497,7 @@ declare const anthropicTools: {
|
|
|
497
497
|
url: string;
|
|
498
498
|
content: {
|
|
499
499
|
type: "document";
|
|
500
|
-
title: string;
|
|
500
|
+
title: string | null;
|
|
501
501
|
citations?: {
|
|
502
502
|
enabled: boolean;
|
|
503
503
|
};
|
|
@@ -527,7 +527,7 @@ declare const anthropicTools: {
|
|
|
527
527
|
url: string;
|
|
528
528
|
content: {
|
|
529
529
|
type: "document";
|
|
530
|
-
title: string;
|
|
530
|
+
title: string | null;
|
|
531
531
|
citations?: {
|
|
532
532
|
enabled: boolean;
|
|
533
533
|
};
|
|
@@ -556,7 +556,7 @@ declare const anthropicTools: {
|
|
|
556
556
|
}, {
|
|
557
557
|
type: "web_search_result";
|
|
558
558
|
url: string;
|
|
559
|
-
title: string;
|
|
559
|
+
title: string | null;
|
|
560
560
|
pageAge: string | null;
|
|
561
561
|
encryptedContent: string;
|
|
562
562
|
}[], {
|
|
@@ -566,7 +566,27 @@ declare const anthropicTools: {
|
|
|
566
566
|
userLocation?: {
|
|
567
567
|
type: "approximate";
|
|
568
568
|
city?: string;
|
|
569
|
-
region
|
|
569
|
+
region
|
|
570
|
+
/**
|
|
571
|
+
* Claude can interact with computer environments through the computer use tool, which
|
|
572
|
+
* provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.
|
|
573
|
+
*
|
|
574
|
+
* Image results are supported.
|
|
575
|
+
*
|
|
576
|
+
* @param displayWidthPx - The width of the display being controlled by the model in pixels.
|
|
577
|
+
* @param displayHeightPx - The height of the display being controlled by the model in pixels.
|
|
578
|
+
* @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.
|
|
579
|
+
*/
|
|
580
|
+
? /**
|
|
581
|
+
* Claude can interact with computer environments through the computer use tool, which
|
|
582
|
+
* provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.
|
|
583
|
+
*
|
|
584
|
+
* Image results are supported.
|
|
585
|
+
*
|
|
586
|
+
* @param displayWidthPx - The width of the display being controlled by the model in pixels.
|
|
587
|
+
* @param displayHeightPx - The height of the display being controlled by the model in pixels.
|
|
588
|
+
* @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.
|
|
589
|
+
*/: string;
|
|
570
590
|
country?: string;
|
|
571
591
|
timezone?: string;
|
|
572
592
|
};
|
|
@@ -575,7 +595,7 @@ declare const anthropicTools: {
|
|
|
575
595
|
}, {
|
|
576
596
|
type: "web_search_result";
|
|
577
597
|
url: string;
|
|
578
|
-
title: string;
|
|
598
|
+
title: string | null;
|
|
579
599
|
pageAge: string | null;
|
|
580
600
|
encryptedContent: string;
|
|
581
601
|
}[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -497,7 +497,7 @@ declare const anthropicTools: {
|
|
|
497
497
|
url: string;
|
|
498
498
|
content: {
|
|
499
499
|
type: "document";
|
|
500
|
-
title: string;
|
|
500
|
+
title: string | null;
|
|
501
501
|
citations?: {
|
|
502
502
|
enabled: boolean;
|
|
503
503
|
};
|
|
@@ -527,7 +527,7 @@ declare const anthropicTools: {
|
|
|
527
527
|
url: string;
|
|
528
528
|
content: {
|
|
529
529
|
type: "document";
|
|
530
|
-
title: string;
|
|
530
|
+
title: string | null;
|
|
531
531
|
citations?: {
|
|
532
532
|
enabled: boolean;
|
|
533
533
|
};
|
|
@@ -556,7 +556,7 @@ declare const anthropicTools: {
|
|
|
556
556
|
}, {
|
|
557
557
|
type: "web_search_result";
|
|
558
558
|
url: string;
|
|
559
|
-
title: string;
|
|
559
|
+
title: string | null;
|
|
560
560
|
pageAge: string | null;
|
|
561
561
|
encryptedContent: string;
|
|
562
562
|
}[], {
|
|
@@ -566,7 +566,27 @@ declare const anthropicTools: {
|
|
|
566
566
|
userLocation?: {
|
|
567
567
|
type: "approximate";
|
|
568
568
|
city?: string;
|
|
569
|
-
region
|
|
569
|
+
region
|
|
570
|
+
/**
|
|
571
|
+
* Claude can interact with computer environments through the computer use tool, which
|
|
572
|
+
* provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.
|
|
573
|
+
*
|
|
574
|
+
* Image results are supported.
|
|
575
|
+
*
|
|
576
|
+
* @param displayWidthPx - The width of the display being controlled by the model in pixels.
|
|
577
|
+
* @param displayHeightPx - The height of the display being controlled by the model in pixels.
|
|
578
|
+
* @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.
|
|
579
|
+
*/
|
|
580
|
+
? /**
|
|
581
|
+
* Claude can interact with computer environments through the computer use tool, which
|
|
582
|
+
* provides screenshot capabilities and mouse/keyboard control for autonomous desktop interaction.
|
|
583
|
+
*
|
|
584
|
+
* Image results are supported.
|
|
585
|
+
*
|
|
586
|
+
* @param displayWidthPx - The width of the display being controlled by the model in pixels.
|
|
587
|
+
* @param displayHeightPx - The height of the display being controlled by the model in pixels.
|
|
588
|
+
* @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.
|
|
589
|
+
*/: string;
|
|
570
590
|
country?: string;
|
|
571
591
|
timezone?: string;
|
|
572
592
|
};
|
|
@@ -575,7 +595,7 @@ declare const anthropicTools: {
|
|
|
575
595
|
}, {
|
|
576
596
|
type: "web_search_result";
|
|
577
597
|
url: string;
|
|
578
|
-
title: string;
|
|
598
|
+
title: string | null;
|
|
579
599
|
pageAge: string | null;
|
|
580
600
|
encryptedContent: string;
|
|
581
601
|
}[]>;
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
31
31
|
var import_provider_utils22 = require("@ai-sdk/provider-utils");
|
|
32
32
|
|
|
33
33
|
// src/version.ts
|
|
34
|
-
var VERSION = true ? "3.0.0-beta.
|
|
34
|
+
var VERSION = true ? "3.0.0-beta.80" : "0.0.0-test";
|
|
35
35
|
|
|
36
36
|
// src/anthropic-messages-language-model.ts
|
|
37
37
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -56,6 +56,29 @@ var anthropicFailedResponseHandler = (0, import_provider_utils.createJsonErrorRe
|
|
|
56
56
|
errorToMessage: (data) => data.error.message
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
+
// src/convert-anthropic-messages-usage.ts
|
|
60
|
+
function convertAnthropicMessagesUsage(usage) {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
const inputTokens = usage.input_tokens;
|
|
63
|
+
const outputTokens = usage.output_tokens;
|
|
64
|
+
const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
|
|
65
|
+
const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
|
|
66
|
+
return {
|
|
67
|
+
inputTokens: {
|
|
68
|
+
total: inputTokens + cacheCreationTokens + cacheReadTokens,
|
|
69
|
+
noCache: inputTokens,
|
|
70
|
+
cacheRead: cacheReadTokens,
|
|
71
|
+
cacheWrite: cacheCreationTokens
|
|
72
|
+
},
|
|
73
|
+
outputTokens: {
|
|
74
|
+
total: outputTokens,
|
|
75
|
+
text: void 0,
|
|
76
|
+
reasoning: void 0
|
|
77
|
+
},
|
|
78
|
+
raw: usage
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
59
82
|
// src/anthropic-messages-api.ts
|
|
60
83
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
61
84
|
var import_v42 = require("zod/v4");
|
|
@@ -881,7 +904,7 @@ var webSearch_20250305OutputSchema = (0, import_provider_utils5.lazySchema)(
|
|
|
881
904
|
import_v45.z.array(
|
|
882
905
|
import_v45.z.object({
|
|
883
906
|
url: import_v45.z.string(),
|
|
884
|
-
title: import_v45.z.string(),
|
|
907
|
+
title: import_v45.z.string().nullable(),
|
|
885
908
|
pageAge: import_v45.z.string().nullable(),
|
|
886
909
|
encryptedContent: import_v45.z.string(),
|
|
887
910
|
type: import_v45.z.literal("web_search_result")
|
|
@@ -926,7 +949,7 @@ var webFetch_20250910OutputSchema = (0, import_provider_utils6.lazySchema)(
|
|
|
926
949
|
url: import_v46.z.string(),
|
|
927
950
|
content: import_v46.z.object({
|
|
928
951
|
type: import_v46.z.literal("document"),
|
|
929
|
-
title: import_v46.z.string(),
|
|
952
|
+
title: import_v46.z.string().nullable(),
|
|
930
953
|
citations: import_v46.z.object({ enabled: import_v46.z.boolean() }).optional(),
|
|
931
954
|
source: import_v46.z.union([
|
|
932
955
|
import_v46.z.object({
|
|
@@ -2490,7 +2513,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2490
2513
|
});
|
|
2491
2514
|
}
|
|
2492
2515
|
async doGenerate(options) {
|
|
2493
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
2516
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2494
2517
|
const { args, warnings, betas, usesJsonResponseTool, toolNameMapping } = await this.getArgs({
|
|
2495
2518
|
...options,
|
|
2496
2519
|
stream: false,
|
|
@@ -2789,16 +2812,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2789
2812
|
finishReason: response.stop_reason,
|
|
2790
2813
|
isJsonResponseFromTool
|
|
2791
2814
|
}),
|
|
2792
|
-
usage:
|
|
2793
|
-
inputTokens: response.usage.input_tokens,
|
|
2794
|
-
outputTokens: response.usage.output_tokens,
|
|
2795
|
-
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
2796
|
-
cachedInputTokens: (_b = response.usage.cache_read_input_tokens) != null ? _b : void 0
|
|
2797
|
-
},
|
|
2815
|
+
usage: convertAnthropicMessagesUsage(response.usage),
|
|
2798
2816
|
request: { body: args },
|
|
2799
2817
|
response: {
|
|
2800
|
-
id: (
|
|
2801
|
-
modelId: (
|
|
2818
|
+
id: (_b = response.id) != null ? _b : void 0,
|
|
2819
|
+
modelId: (_c = response.model) != null ? _c : void 0,
|
|
2802
2820
|
headers: responseHeaders,
|
|
2803
2821
|
body: rawResponse
|
|
2804
2822
|
},
|
|
@@ -2806,20 +2824,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2806
2824
|
providerMetadata: {
|
|
2807
2825
|
anthropic: {
|
|
2808
2826
|
usage: response.usage,
|
|
2809
|
-
cacheCreationInputTokens: (
|
|
2810
|
-
stopSequence: (
|
|
2827
|
+
cacheCreationInputTokens: (_d = response.usage.cache_creation_input_tokens) != null ? _d : null,
|
|
2828
|
+
stopSequence: (_e = response.stop_sequence) != null ? _e : null,
|
|
2811
2829
|
container: response.container ? {
|
|
2812
2830
|
expiresAt: response.container.expires_at,
|
|
2813
2831
|
id: response.container.id,
|
|
2814
|
-
skills: (
|
|
2832
|
+
skills: (_g = (_f = response.container.skills) == null ? void 0 : _f.map((skill) => ({
|
|
2815
2833
|
type: skill.type,
|
|
2816
2834
|
skillId: skill.skill_id,
|
|
2817
2835
|
version: skill.version
|
|
2818
|
-
}))) != null ?
|
|
2836
|
+
}))) != null ? _g : null
|
|
2819
2837
|
} : null,
|
|
2820
|
-
contextManagement: (
|
|
2838
|
+
contextManagement: (_h = mapAnthropicResponseContextManagement(
|
|
2821
2839
|
response.context_management
|
|
2822
|
-
)) != null ?
|
|
2840
|
+
)) != null ? _h : null
|
|
2823
2841
|
}
|
|
2824
2842
|
}
|
|
2825
2843
|
};
|
|
@@ -2852,9 +2870,10 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2852
2870
|
});
|
|
2853
2871
|
let finishReason = "unknown";
|
|
2854
2872
|
const usage = {
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2873
|
+
input_tokens: 0,
|
|
2874
|
+
output_tokens: 0,
|
|
2875
|
+
cache_creation_input_tokens: 0,
|
|
2876
|
+
cache_read_input_tokens: 0
|
|
2858
2877
|
};
|
|
2859
2878
|
const contentBlocks = {};
|
|
2860
2879
|
const mcpToolCalls = {};
|
|
@@ -2872,7 +2891,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2872
2891
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2873
2892
|
},
|
|
2874
2893
|
transform(chunk, controller) {
|
|
2875
|
-
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i
|
|
2894
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
|
|
2876
2895
|
if (options.includeRawChunks) {
|
|
2877
2896
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2878
2897
|
}
|
|
@@ -3311,35 +3330,35 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3311
3330
|
}
|
|
3312
3331
|
}
|
|
3313
3332
|
case "message_start": {
|
|
3314
|
-
usage.
|
|
3315
|
-
usage.
|
|
3333
|
+
usage.input_tokens = value.message.usage.input_tokens;
|
|
3334
|
+
usage.cache_read_input_tokens = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : 0;
|
|
3335
|
+
usage.cache_creation_input_tokens = (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : 0;
|
|
3316
3336
|
rawUsage = {
|
|
3317
3337
|
...value.message.usage
|
|
3318
3338
|
};
|
|
3319
|
-
cacheCreationInputTokens = (
|
|
3339
|
+
cacheCreationInputTokens = (_d = value.message.usage.cache_creation_input_tokens) != null ? _d : null;
|
|
3320
3340
|
controller.enqueue({
|
|
3321
3341
|
type: "response-metadata",
|
|
3322
|
-
id: (
|
|
3323
|
-
modelId: (
|
|
3342
|
+
id: (_e = value.message.id) != null ? _e : void 0,
|
|
3343
|
+
modelId: (_f = value.message.model) != null ? _f : void 0
|
|
3324
3344
|
});
|
|
3325
3345
|
return;
|
|
3326
3346
|
}
|
|
3327
3347
|
case "message_delta": {
|
|
3328
|
-
usage.
|
|
3329
|
-
usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
|
|
3348
|
+
usage.output_tokens = value.usage.output_tokens;
|
|
3330
3349
|
finishReason = mapAnthropicStopReason({
|
|
3331
3350
|
finishReason: value.delta.stop_reason,
|
|
3332
3351
|
isJsonResponseFromTool
|
|
3333
3352
|
});
|
|
3334
|
-
stopSequence = (
|
|
3353
|
+
stopSequence = (_g = value.delta.stop_sequence) != null ? _g : null;
|
|
3335
3354
|
container = value.delta.container != null ? {
|
|
3336
3355
|
expiresAt: value.delta.container.expires_at,
|
|
3337
3356
|
id: value.delta.container.id,
|
|
3338
|
-
skills: (
|
|
3357
|
+
skills: (_i = (_h = value.delta.container.skills) == null ? void 0 : _h.map((skill) => ({
|
|
3339
3358
|
type: skill.type,
|
|
3340
3359
|
skillId: skill.skill_id,
|
|
3341
3360
|
version: skill.version
|
|
3342
|
-
}))) != null ?
|
|
3361
|
+
}))) != null ? _i : null
|
|
3343
3362
|
} : null;
|
|
3344
3363
|
if (value.delta.context_management) {
|
|
3345
3364
|
contextManagement = mapAnthropicResponseContextManagement(
|
|
@@ -3356,7 +3375,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3356
3375
|
controller.enqueue({
|
|
3357
3376
|
type: "finish",
|
|
3358
3377
|
finishReason,
|
|
3359
|
-
usage,
|
|
3378
|
+
usage: convertAnthropicMessagesUsage(usage),
|
|
3360
3379
|
providerMetadata: {
|
|
3361
3380
|
anthropic: {
|
|
3362
3381
|
usage: rawUsage != null ? rawUsage : null,
|