@ai-sdk/anthropic 4.0.20 → 4.0.21
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 +6 -0
- package/dist/index.js +15 -5
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +14 -4
- package/dist/internal/index.js.map +1 -1
- package/package.json +3 -3
- package/src/anthropic-api.ts +10 -0
- package/src/anthropic-language-model.ts +3 -0
- package/src/convert-anthropic-usage.ts +8 -2
package/dist/internal/index.js
CHANGED
|
@@ -433,6 +433,9 @@ var anthropicResponseSchema = lazySchema3(
|
|
|
433
433
|
usage: z3.looseObject({
|
|
434
434
|
input_tokens: z3.number(),
|
|
435
435
|
output_tokens: z3.number(),
|
|
436
|
+
output_tokens_details: z3.object({
|
|
437
|
+
thinking_tokens: z3.number().nullish()
|
|
438
|
+
}).nullish(),
|
|
436
439
|
cache_creation_input_tokens: z3.number().nullish(),
|
|
437
440
|
cache_read_input_tokens: z3.number().nullish(),
|
|
438
441
|
iterations: z3.array(
|
|
@@ -880,6 +883,9 @@ var anthropicChunkSchema = lazySchema3(
|
|
|
880
883
|
usage: z3.looseObject({
|
|
881
884
|
input_tokens: z3.number().nullish(),
|
|
882
885
|
output_tokens: z3.number(),
|
|
886
|
+
output_tokens_details: z3.object({
|
|
887
|
+
thinking_tokens: z3.number().nullish()
|
|
888
|
+
}).nullish(),
|
|
883
889
|
cache_creation_input_tokens: z3.number().nullish(),
|
|
884
890
|
cache_read_input_tokens: z3.number().nullish(),
|
|
885
891
|
iterations: z3.array(
|
|
@@ -1949,12 +1955,13 @@ function convertAnthropicUsage({
|
|
|
1949
1955
|
usage,
|
|
1950
1956
|
rawUsage
|
|
1951
1957
|
}) {
|
|
1952
|
-
var _a, _b, _c;
|
|
1958
|
+
var _a, _b, _c, _d, _e;
|
|
1953
1959
|
const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
|
|
1954
1960
|
const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
|
|
1961
|
+
const reasoningTokens = (_d = (_c = usage.output_tokens_details) == null ? void 0 : _c.thinking_tokens) != null ? _d : void 0;
|
|
1955
1962
|
let inputTokens;
|
|
1956
1963
|
let outputTokens;
|
|
1957
|
-
const servedByFallback = (
|
|
1964
|
+
const servedByFallback = (_e = usage.iterations) == null ? void 0 : _e.some(
|
|
1958
1965
|
(iter) => iter.type === "fallback_message"
|
|
1959
1966
|
);
|
|
1960
1967
|
if (usage.iterations && usage.iterations.length > 0 && !servedByFallback) {
|
|
@@ -1988,8 +1995,8 @@ function convertAnthropicUsage({
|
|
|
1988
1995
|
},
|
|
1989
1996
|
outputTokens: {
|
|
1990
1997
|
total: outputTokens,
|
|
1991
|
-
text: void 0,
|
|
1992
|
-
reasoning:
|
|
1998
|
+
text: reasoningTokens == null ? void 0 : outputTokens - reasoningTokens,
|
|
1999
|
+
reasoning: reasoningTokens
|
|
1993
2000
|
},
|
|
1994
2001
|
raw: rawUsage != null ? rawUsage : usage
|
|
1995
2002
|
};
|
|
@@ -5388,6 +5395,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5388
5395
|
usage.input_tokens = value.usage.input_tokens;
|
|
5389
5396
|
}
|
|
5390
5397
|
usage.output_tokens = value.usage.output_tokens;
|
|
5398
|
+
if (value.usage.output_tokens_details != null) {
|
|
5399
|
+
usage.output_tokens_details = value.usage.output_tokens_details;
|
|
5400
|
+
}
|
|
5391
5401
|
if (value.usage.cache_read_input_tokens != null) {
|
|
5392
5402
|
usage.cache_read_input_tokens = value.usage.cache_read_input_tokens;
|
|
5393
5403
|
}
|