@ai-sdk/anthropic 3.0.0-beta.78 → 3.0.0-beta.79
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 +9 -0
- package/dist/index.js +50 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -31
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +49 -30
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +49 -30
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 3.0.0-beta.79
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3bd2689: feat: extended token usage
|
|
8
|
+
- Updated dependencies [3bd2689]
|
|
9
|
+
- @ai-sdk/provider@3.0.0-beta.26
|
|
10
|
+
- @ai-sdk/provider-utils@4.0.0-beta.45
|
|
11
|
+
|
|
3
12
|
## 3.0.0-beta.78
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
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.79" : "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");
|
|
@@ -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,
|