@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codehz/ai",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "module": "dist/index.mjs",
6
6
  "exports": {
@@ -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 inputTokens = num(raw.input_tokens);
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 = [inputTokens, cacheWriteInputTokens, cachedInputTokens].filter(
110
+ const inputParts = [uncachedInputTokens, cacheWriteInputTokens, cachedInputTokens].filter(
111
111
  (n): n is number => n !== undefined,
112
112
  );
113
- const summedInput = inputParts.length > 0 ? inputParts.reduce((sum, n) => sum + n, 0) : undefined;
113
+ const inputTokens = inputParts.length > 0 ? inputParts.reduce((sum, n) => sum + n, 0) : undefined;
114
114
  const totalTokens =
115
- summedInput !== undefined && outputTokens !== undefined ? summedInput + outputTokens : undefined;
115
+ inputTokens !== undefined && outputTokens !== undefined ? inputTokens + outputTokens : undefined;
116
116
 
117
117
  let billableInputTokens: number | undefined;
118
- if (inputTokens !== undefined || cacheWriteInputTokens !== undefined) {
119
- billableInputTokens = (inputTokens ?? 0) + (cacheWriteInputTokens ?? 0);
118
+ if (uncachedInputTokens !== undefined || cacheWriteInputTokens !== undefined) {
119
+ billableInputTokens = (uncachedInputTokens ?? 0) + (cacheWriteInputTokens ?? 0);
120
120
  }
121
121
 
122
122
  return record({