@vibe-cafe/vibe-usage 0.5.0 → 0.5.1

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": "@vibe-cafe/vibe-usage",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Track your AI coding tool token usage and sync to vibecafe.ai",
5
5
  "type": "module",
6
6
  "bin": {
@@ -115,15 +115,19 @@ export async function parse() {
115
115
 
116
116
  const model = info.model || payload.model || turnContextModel || sessionModel;
117
117
 
118
+ // OpenAI API: input_tokens INCLUDES cached, output_tokens INCLUDES reasoning.
119
+ // Normalize to Anthropic-style semantics where each field is non-overlapping.
120
+ const cachedInput = usage.cached_input_tokens || usage.cache_read_input_tokens || 0;
121
+ const reasoningOutput = usage.reasoning_output_tokens || 0;
118
122
  entries.push({
119
123
  source: 'codex',
120
124
  model,
121
125
  project: sessionProject,
122
126
  timestamp,
123
- inputTokens: usage.input_tokens || 0,
124
- outputTokens: usage.output_tokens || 0,
125
- cachedInputTokens: usage.cached_input_tokens || usage.cache_read_input_tokens || 0,
126
- reasoningOutputTokens: usage.reasoning_output_tokens || 0,
127
+ inputTokens: (usage.input_tokens || 0) - cachedInput,
128
+ outputTokens: (usage.output_tokens || 0) - reasoningOutput,
129
+ cachedInputTokens: cachedInput,
130
+ reasoningOutputTokens: reasoningOutput,
127
131
  });
128
132
  } catch {
129
133
  continue;
@@ -59,28 +59,32 @@ export async function parse() {
59
59
  if (isNaN(ts.getTime())) continue;
60
60
 
61
61
  if (tokens) {
62
- // New format: { input, output, cached, thoughts, tool, total }
62
+ // Gemini API: input INCLUDES cached, output INCLUDES thoughts. Normalize to non-overlapping.
63
+ const cached = tokens.cached || 0;
64
+ const thoughts = tokens.thoughts || 0;
63
65
  entries.push({
64
66
  source: 'gemini-cli',
65
67
  model: msg.model || data.model || 'unknown',
66
68
  project: 'unknown',
67
69
  timestamp: ts,
68
- inputTokens: tokens.input || 0,
69
- outputTokens: tokens.output || 0,
70
- cachedInputTokens: tokens.cached || 0,
71
- reasoningOutputTokens: tokens.thoughts || 0,
70
+ inputTokens: (tokens.input || 0) - cached,
71
+ outputTokens: (tokens.output || 0) - thoughts,
72
+ cachedInputTokens: cached,
73
+ reasoningOutputTokens: thoughts,
72
74
  });
73
75
  } else {
74
- // Old format: { promptTokenCount, candidatesTokenCount, ... }
76
+ // Gemini API: promptTokenCount INCLUDES cachedContentTokenCount. Normalize to non-overlapping.
77
+ const cached = usage.cachedContentTokenCount || 0;
78
+ const thoughts = usage.thoughtsTokenCount || 0;
75
79
  entries.push({
76
80
  source: 'gemini-cli',
77
81
  model: msg.model || data.model || 'unknown',
78
82
  project: 'unknown',
79
83
  timestamp: ts,
80
- inputTokens: usage.promptTokenCount || usage.input_tokens || 0,
81
- outputTokens: usage.candidatesTokenCount || usage.output_tokens || 0,
82
- cachedInputTokens: usage.cachedContentTokenCount || 0,
83
- reasoningOutputTokens: usage.thoughtsTokenCount || 0,
84
+ inputTokens: (usage.promptTokenCount || usage.input_tokens || 0) - cached,
85
+ outputTokens: (usage.candidatesTokenCount || usage.output_tokens || 0) - thoughts,
86
+ cachedInputTokens: cached,
87
+ reasoningOutputTokens: thoughts,
84
88
  });
85
89
  }
86
90
  }
@@ -45,7 +45,7 @@ export function aggregateToBuckets(entries) {
45
45
  b.outputTokens += e.outputTokens || 0;
46
46
  b.cachedInputTokens += e.cachedInputTokens || 0;
47
47
  b.reasoningOutputTokens += e.reasoningOutputTokens || 0;
48
- b.totalTokens += (e.inputTokens || 0) + (e.outputTokens || 0);
48
+ b.totalTokens += (e.inputTokens || 0) + (e.outputTokens || 0) + (e.reasoningOutputTokens || 0);
49
49
  }
50
50
 
51
51
  return Array.from(map.values());