codebuddy-stats 1.4.2 → 1.4.4

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.
@@ -225,8 +225,10 @@ function finalizeAnalysis(defaultModelId, dailyData, modelTotals, projectTotals,
225
225
  const daySummary = { cost: 0, tokens: 0, requests: 0 };
226
226
  let topModelId = '-';
227
227
  let topModelCost = 0;
228
+ let topModelTokens = 0;
228
229
  let topProjectName = '-';
229
230
  let topProjectCost = 0;
231
+ let topProjectTokens = 0;
230
232
  const month = date.slice(0, 7);
231
233
  if (month) {
232
234
  monthlyAgg[month] ??= {
@@ -242,6 +244,7 @@ function finalizeAnalysis(defaultModelId, dailyData, modelTotals, projectTotals,
242
244
  }
243
245
  for (const [projectName, models] of Object.entries(dayData ?? {})) {
244
246
  let projectCost = 0;
247
+ let projectTokens = 0;
245
248
  if (month) {
246
249
  monthlyByProject[month][projectName] ??= { cost: 0, tokens: 0, requests: 0, modelCost: {} };
247
250
  }
@@ -253,8 +256,10 @@ function finalizeAnalysis(defaultModelId, dailyData, modelTotals, projectTotals,
253
256
  daySummary.tokens += tokens;
254
257
  daySummary.requests += requests;
255
258
  projectCost += cost;
256
- if (cost > topModelCost) {
259
+ projectTokens += tokens;
260
+ if (cost > topModelCost || (cost === topModelCost && tokens > topModelTokens)) {
257
261
  topModelCost = cost;
262
+ topModelTokens = tokens;
258
263
  topModelId = modelId;
259
264
  }
260
265
  if (month) {
@@ -264,22 +269,29 @@ function finalizeAnalysis(defaultModelId, dailyData, modelTotals, projectTotals,
264
269
  mAgg.requests += requests;
265
270
  mAgg.cacheHitTokens += stats.cacheHitTokens;
266
271
  mAgg.cacheMissTokens += stats.cacheMissTokens;
267
- mAgg.modelCost[modelId] = (mAgg.modelCost[modelId] ?? 0) + cost;
268
- mAgg.projectCost[projectName] = (mAgg.projectCost[projectName] ?? 0) + cost;
272
+ mAgg.modelCost[modelId] ??= { cost: 0, tokens: 0 };
273
+ mAgg.modelCost[modelId].cost += cost;
274
+ mAgg.modelCost[modelId].tokens += tokens;
275
+ mAgg.projectCost[projectName] ??= { cost: 0, tokens: 0 };
276
+ mAgg.projectCost[projectName].cost += cost;
277
+ mAgg.projectCost[projectName].tokens += tokens;
269
278
  const pAgg = monthlyByProject[month][projectName];
270
279
  pAgg.cost += cost;
271
280
  pAgg.tokens += tokens;
272
281
  pAgg.requests += requests;
273
- pAgg.modelCost[modelId] = (pAgg.modelCost[modelId] ?? 0) + cost;
282
+ pAgg.modelCost[modelId] ??= { cost: 0, tokens: 0 };
283
+ pAgg.modelCost[modelId].cost += cost;
284
+ pAgg.modelCost[modelId].tokens += tokens;
274
285
  }
275
286
  }
276
- if (projectCost > topProjectCost) {
287
+ if (projectCost > topProjectCost || (projectCost === topProjectCost && projectTokens > topProjectTokens)) {
277
288
  topProjectCost = projectCost;
289
+ topProjectTokens = projectTokens;
278
290
  topProjectName = projectName;
279
291
  }
280
292
  }
281
293
  dailySummary[date] = daySummary;
282
- dailyTops[date] = { topModelId, topModelCost, topProjectName, topProjectCost };
294
+ dailyTops[date] = { topModelId, topModelCost, topModelTokens, topProjectName, topProjectCost, topProjectTokens };
283
295
  }
284
296
  const projectDisplayNames = {};
285
297
  for (const projectName of Object.keys(projectTotals)) {
@@ -106,7 +106,7 @@ export const MODEL_PRICING = {
106
106
  cacheWrite: [
107
107
  { limit: 200_000, pricePerMTok: 0.2 },
108
108
  { limit: Number.POSITIVE_INFINITY, pricePerMTok: 0.4 },
109
- ]
109
+ ],
110
110
  },
111
111
  "gemini-3.0-pro": {
112
112
  prompt: [
@@ -126,6 +126,7 @@ export const MODEL_PRICING = {
126
126
  { limit: Number.POSITIVE_INFINITY, pricePerMTok: 0.4 },
127
127
  ],
128
128
  },
129
+ "gemini-3.1-flash-lite": createPricing(0.25, 0.03, 1.5),
129
130
  "gemini-3.0-flash": createPricing(0.5, 0.05, 3.0),
130
131
  "gemini-2.5-pro": {
131
132
  prompt: [
@@ -146,6 +147,7 @@ export const MODEL_PRICING = {
146
147
  ],
147
148
  },
148
149
  // MiniMax
150
+ "minimax-m2.7": createPricing(0.3, 0.03, 1.2),
149
151
  "minimax-m2.5": createPricing(0.3, 0.03, 1.2),
150
152
  // GLM 系列 (价格从人民币转换: 1 USD = 7 CNY)
151
153
  // 按上下文长度分段定价:[0,32K), [32K,200K)
@@ -42,16 +42,19 @@ export function renderDaily(box, data, scrollOffset = 0, selectedIndex = 0, widt
42
42
  else {
43
43
  for (const [project, models] of Object.entries(dayData)) {
44
44
  let projectCost = 0;
45
+ let projectTokens = 0;
45
46
  for (const [model, stats] of Object.entries(models)) {
46
47
  const modelStats = stats;
47
48
  const c = Number(modelStats.cost ?? 0);
49
+ const t = Number(modelStats.totalTokens ?? 0);
48
50
  projectCost += c;
49
- if (c > topModel.cost) {
50
- topModel = { id: model, cost: c };
51
+ projectTokens += t;
52
+ if (c > topModel.cost || (c === topModel.cost && t > (topModel.tokens ?? 0))) {
53
+ topModel = { id: model, cost: c, tokens: t };
51
54
  }
52
55
  }
53
- if (projectCost > topProject.cost) {
54
- topProject = { name: project, cost: projectCost };
56
+ if (projectCost > topProject.cost || (projectCost === topProject.cost && projectTokens > (topProject.tokens ?? 0))) {
57
+ topProject = { name: project, cost: projectCost, tokens: projectTokens };
55
58
  }
56
59
  }
57
60
  }
@@ -20,9 +20,13 @@ export function renderMonthlyDetail(box, data, month, scrollOffset = 0, width, p
20
20
  .map(([projectName, agg]) => {
21
21
  let topModelId = '-';
22
22
  let topModelCost = 0;
23
- for (const [modelId, c] of Object.entries(agg.modelCost)) {
24
- if (c > topModelCost) {
25
- topModelCost = c;
23
+ let topModelTokens = 0;
24
+ for (const [modelId, modelStats] of Object.entries(agg.modelCost)) {
25
+ const cost = modelStats.cost;
26
+ const tokens = modelStats.tokens;
27
+ if (cost > topModelCost || (cost === topModelCost && tokens > topModelTokens)) {
28
+ topModelCost = cost;
29
+ topModelTokens = tokens;
26
30
  topModelId = modelId;
27
31
  }
28
32
  }
@@ -66,7 +70,9 @@ export function renderMonthlyDetail(box, data, month, scrollOffset = 0, width, p
66
70
  p.cost += cost;
67
71
  p.tokens += tokens;
68
72
  p.requests += requests;
69
- p.modelCost[modelId] = (p.modelCost[modelId] ?? 0) + cost;
73
+ p.modelCost[modelId] ??= { cost: 0, tokens: 0 };
74
+ p.modelCost[modelId].cost += cost;
75
+ p.modelCost[modelId].tokens += tokens;
70
76
  totalCost += cost;
71
77
  totalTokens += tokens;
72
78
  totalRequests += requests;
@@ -79,9 +85,13 @@ export function renderMonthlyDetail(box, data, month, scrollOffset = 0, width, p
79
85
  .map(p => {
80
86
  let topModelId = '-';
81
87
  let topModelCost = 0;
82
- for (const [modelId, c] of Object.entries(p.modelCost)) {
83
- if (c > topModelCost) {
84
- topModelCost = c;
88
+ let topModelTokens = 0;
89
+ for (const [modelId, modelStats] of Object.entries(p.modelCost)) {
90
+ const cost = modelStats.cost;
91
+ const tokens = modelStats.tokens;
92
+ if (cost > topModelCost || (cost === topModelCost && tokens > topModelTokens)) {
93
+ topModelCost = cost;
94
+ topModelTokens = tokens;
85
95
  topModelId = modelId;
86
96
  }
87
97
  }
@@ -30,8 +30,12 @@ export function renderMonthly(box, data, scrollOffset = 0, selectedIndex = 0, wi
30
30
  monthAgg.requests += requests;
31
31
  monthAgg.cacheHitTokens += cacheHit;
32
32
  monthAgg.cacheMissTokens += cacheMiss;
33
- monthAgg.modelCost[modelId] = (monthAgg.modelCost[modelId] ?? 0) + cost;
34
- monthAgg.projectCost[projectName] = (monthAgg.projectCost[projectName] ?? 0) + cost;
33
+ monthAgg.modelCost[modelId] ??= { cost: 0, tokens: 0 };
34
+ monthAgg.modelCost[modelId].cost += cost;
35
+ monthAgg.modelCost[modelId].tokens += tokens;
36
+ monthAgg.projectCost[projectName] ??= { cost: 0, tokens: 0 };
37
+ monthAgg.projectCost[projectName].cost += cost;
38
+ monthAgg.projectCost[projectName].tokens += tokens;
35
39
  }
36
40
  }
37
41
  }
@@ -64,16 +68,22 @@ export function renderMonthly(box, data, scrollOffset = 0, selectedIndex = 0, wi
64
68
  const m = aggByMonth[month];
65
69
  if (!m)
66
70
  continue;
67
- // top model / project by cost
68
- let topModel = { id: '-', cost: 0 };
69
- let topProject = { name: '-', cost: 0 };
70
- for (const [modelId, c] of Object.entries(m.modelCost)) {
71
- if (c > topModel.cost)
72
- topModel = { id: modelId, cost: c };
71
+ // top model / project by cost (cost 相等时比较 tokens)
72
+ let topModel = { id: '-', cost: 0, tokens: 0 };
73
+ let topProject = { name: '-', cost: 0, tokens: 0 };
74
+ for (const [modelId, modelStats] of Object.entries(m.modelCost)) {
75
+ const cost = modelStats.cost;
76
+ const tokens = modelStats.tokens;
77
+ if (cost > topModel.cost || (cost === topModel.cost && tokens > topModel.tokens)) {
78
+ topModel = { id: modelId, cost, tokens };
79
+ }
73
80
  }
74
- for (const [projectName, c] of Object.entries(m.projectCost)) {
75
- if (c > topProject.cost)
76
- topProject = { name: projectName, cost: c };
81
+ for (const [projectName, projectStats] of Object.entries(m.projectCost)) {
82
+ const cost = projectStats.cost;
83
+ const tokens = projectStats.tokens;
84
+ if (cost > topProject.cost || (cost === topProject.cost && tokens > topProject.tokens)) {
85
+ topProject = { name: projectName, cost, tokens };
86
+ }
77
87
  }
78
88
  const shortProject = data.projectDisplayNames?.[topProject.name] ?? resolveProjectName(topProject.name, data.workspaceMappings);
79
89
  const isSelected = scrollOffset + i === selectedIndex;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codebuddy-stats",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "files": [