@codehz/ai 0.1.7 → 0.1.8
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/dist/index.mjs +5 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/helpers/usage-mapping.ts +6 -6
package/package.json
CHANGED
|
@@ -102,21 +102,21 @@ export function usageFromAnthropicMessages(raw: {
|
|
|
102
102
|
cache_read_input_tokens?: number;
|
|
103
103
|
[key: string]: unknown;
|
|
104
104
|
}): Partial<Usage> {
|
|
105
|
-
const
|
|
105
|
+
const uncachedInputTokens = num(raw.input_tokens);
|
|
106
106
|
const outputTokens = num(raw.output_tokens);
|
|
107
107
|
const cacheWriteInputTokens = num(raw.cache_creation_input_tokens);
|
|
108
108
|
const cachedInputTokens = num(raw.cache_read_input_tokens);
|
|
109
109
|
|
|
110
|
-
const inputParts = [
|
|
110
|
+
const inputParts = [uncachedInputTokens, cacheWriteInputTokens, cachedInputTokens].filter(
|
|
111
111
|
(n): n is number => n !== undefined,
|
|
112
112
|
);
|
|
113
|
-
const
|
|
113
|
+
const inputTokens = inputParts.length > 0 ? inputParts.reduce((sum, n) => sum + n, 0) : undefined;
|
|
114
114
|
const totalTokens =
|
|
115
|
-
|
|
115
|
+
inputTokens !== undefined && outputTokens !== undefined ? inputTokens + outputTokens : undefined;
|
|
116
116
|
|
|
117
117
|
let billableInputTokens: number | undefined;
|
|
118
|
-
if (
|
|
119
|
-
billableInputTokens = (
|
|
118
|
+
if (uncachedInputTokens !== undefined || cacheWriteInputTokens !== undefined) {
|
|
119
|
+
billableInputTokens = (uncachedInputTokens ?? 0) + (cacheWriteInputTokens ?? 0);
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
return record({
|