opencode-statboard 2.10.18 → 2.10.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/attr-worker.js +4 -2
- package/package.json +1 -1
- package/pricing.js +92 -18
- package/run-check.bat +3 -0
- package/server.js +24 -7
package/attr-worker.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const { parentPort, workerData } = require('worker_threads');
|
|
2
|
+
if (workerData && workerData.dbPath && !process.env.OPENCODE_DATA) {
|
|
3
|
+
process.env.OPENCODE_DATA = workerData.dbPath;
|
|
4
|
+
}
|
|
2
5
|
const srv = require('./server.js');
|
|
3
6
|
|
|
4
|
-
// I/O throttling parameters (from env, with defaults)
|
|
5
7
|
const ITHROTTLE_BATCH = parseInt(process.env.OPENCODE_ITHROTTLE_BATCH || '1000', 10);
|
|
6
8
|
const ITHROTTLE_DELAY_MS = parseInt(process.env.OPENCODE_ITHROTTLE_DELAY_MS || '5', 10);
|
|
7
9
|
|
|
@@ -25,4 +27,4 @@ function throttle(iteration) {
|
|
|
25
27
|
});
|
|
26
28
|
})().catch((e) => {
|
|
27
29
|
parentPort.postMessage({ ok: false, error: (e && e.message) || String(e) });
|
|
28
|
-
});
|
|
30
|
+
});
|
package/package.json
CHANGED
package/pricing.js
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
// -contributor-free) or duplicated provider prefix -> kind 'sibling'
|
|
10
10
|
// 3. same base name under provider 'opencode' -> kind 'proxy'
|
|
11
11
|
// 4. same base name anywhere else (cheapest nonzero) -> kind 'proxy'
|
|
12
|
-
// 5.
|
|
12
|
+
// 5. manual FREE_MODEL_MAPPING for free models without automatic match
|
|
13
|
+
// 6. nothing in the catalog -> null (NOT priced;
|
|
13
14
|
// inventing a number here is how a $0 model turned into $212 of fake
|
|
14
15
|
// savings). Callers must show '—' and can disclose the unpriced rows.
|
|
15
16
|
//
|
|
@@ -19,6 +20,83 @@
|
|
|
19
20
|
const fs = require('fs');
|
|
20
21
|
const path = require('path');
|
|
21
22
|
|
|
23
|
+
const stripFree = (m) => String(m).replace(/-contributor-free$/, '').replace(/-free$/, '').replace(/:free$/, '');
|
|
24
|
+
|
|
25
|
+
// Manual paid-model mapping for free opencode models that have no automatic
|
|
26
|
+
// sibling/proxy match. Key: free model name (with or without provider prefix),
|
|
27
|
+
// value: paid model full name (provider/model from cache).
|
|
28
|
+
const FREE_MODEL_MAPPING = {
|
|
29
|
+
'opencode/space-bunny-free': 'pioneer/mistralai/Mistral-7B-Instruct-v0.3',
|
|
30
|
+
'opencode/beam-free': 'openrouter/xiaomi/mimo-v2.5',
|
|
31
|
+
'opencode/fledge-alpha-free': 'pioneer/mistralai/Mistral-7B-Instruct-v0.3',
|
|
32
|
+
'opencode/grok-code': 'vercel/spacexai/grok-4.1-fast-reasoning',
|
|
33
|
+
'opencode/laguna-s-2.1-free': 'nano-gpt/poolside/laguna-s-2.1',
|
|
34
|
+
'opencode/x-preview-f-free': 'vercel/spacexai/grok-4.1-fast-reasoning',
|
|
35
|
+
'opencode/nemotron-3.5-lightning-free': 'nano-gpt/nvidia/nemotron-3.5-lightning',
|
|
36
|
+
'opencode/big-pickle': 'vercel/spacexai/grok-4.1-fast-reasoning',
|
|
37
|
+
'opencode/ling-3.0-flash-fin-free': 'empiriolabs/qwen3-8-flash',
|
|
38
|
+
'opencode/mimo-v2.5-free': 'openrouter/xiaomi/mimo-v2.5',
|
|
39
|
+
'opencode/nemotron-3-super-free': 'openrouter/nvidia/nemotron-3-super-120b-a12b',
|
|
40
|
+
'opencode/nemotron-3-ultra-free': 'openrouter/nvidia/nemotron-3-ultra-550b-a55b',
|
|
41
|
+
'opencode/glm-4.7-free': 'openrouter/z-ai/glm-4.7',
|
|
42
|
+
'opencode/glm-5-free': 'openrouter/z-ai/glm-5',
|
|
43
|
+
'opencode/mimo-v2-flash-free': 'openrouter/xiaomi/mimo-v2-flash',
|
|
44
|
+
'opencode/qwen3.6-plus-free': 'nano-gpt/qwen/qwen3.6-plus',
|
|
45
|
+
'opencode/mimo-v2-omni-free': 'openrouter/xiaomi/mimo-v2-omni',
|
|
46
|
+
'opencode/mimo-v2-pro-free': 'openrouter/xiaomi/mimo-v2-pro',
|
|
47
|
+
'opencode/ling-3.0-tiny-free': 'empiriolabs/qwen3-8-flash',
|
|
48
|
+
'opencode/trinity-large-preview-free': 'vercel/spacexai/grok-4.1-fast-reasoning',
|
|
49
|
+
'opencode/nemotron-3.5-super-vl-free': 'openrouter/nvidia/nemotron-3.5-super-vl',
|
|
50
|
+
'opencode/ling-2.6-flash-free': 'empiriolabs/qwen3-8-flash',
|
|
51
|
+
'opencode/minimax-m2.5-free': 'openrouter/minimax/minimax-m2.5',
|
|
52
|
+
'opencode/minimax-m3-free': 'openrouter/minimax/minimax-m3',
|
|
53
|
+
'opencode/muse-spark-1.2-contributor-free': 'nano-gpt/meta/muse-spark-1.2',
|
|
54
|
+
'opencode/muse-spark-1.3-contributor-free': 'bothub/muse-spark-1.3-contributor',
|
|
55
|
+
'opencode/deepseek-v4-flash-free': 'openrouter/deepseek/deepseek-v4-flash',
|
|
56
|
+
'opencode/deepseek-v4.1-flash-free': 'openrouter/deepseek/deepseek-v4.1-flash',
|
|
57
|
+
'opencode/hy3-free': 'openrouter/tencent/hy3',
|
|
58
|
+
'opencode/glm-5.3-flash-free': 'openrouter/z-ai/glm-5.3-flash',
|
|
59
|
+
'opencode/nemotron-3.5-super-vl-free': 'openrouter/nvidia/nemotron-3.5-super-vl',
|
|
60
|
+
'opencode/beam-free': 'openrouter/xiaomi/mimo-v2.5',
|
|
61
|
+
'opencode/space-bunny-free': 'pioneer/mistralai/Mistral-7B-Instruct-v0.3',
|
|
62
|
+
'opencode/fledge-alpha-free': 'pioneer/mistralai/Mistral-7B-Instruct-v0.3',
|
|
63
|
+
'opencode/big-pickle': 'vercel/spacexai/grok-4.1-fast-reasoning',
|
|
64
|
+
'opencode/grok-code': 'vercel/spacexai/grok-4.1-fast-reasoning',
|
|
65
|
+
'opencode/x-preview-f-free': 'vercel/spacexai/grok-4.1-fast-reasoning',
|
|
66
|
+
'opencode/nemotron-3.5-lightning-free': 'nano-gpt/nvidia/nemotron-3.5-lightning',
|
|
67
|
+
'opencode/big-pickle': 'vercel/spacexai/grok-4.1-fast-reasoning',
|
|
68
|
+
'opencode/ling-3.0-flash-fin-free': 'empiriolabs/qwen3-8-flash',
|
|
69
|
+
'opencode/ling-3.0-tiny-free': 'empiriolabs/qwen3-8-flash',
|
|
70
|
+
'opencode/ling-2.6-flash-free': 'empiriolabs/qwen3-8-flash',
|
|
71
|
+
'opencode/trinity-large-preview-free': 'vercel/spacexai/grok-4.1-fast-reasoning',
|
|
72
|
+
'opencode/mimo-v2.5-free': 'openrouter/xiaomi/mimo-v2.5',
|
|
73
|
+
'opencode/mimo-v2-flash-free': 'openrouter/xiaomi/mimo-v2-flash',
|
|
74
|
+
'opencode/mimo-v2-omni-free': 'openrouter/xiaomi/mimo-v2-omni',
|
|
75
|
+
'opencode/mimo-v2-pro-free': 'openrouter/xiaomi/mimo-v2-pro',
|
|
76
|
+
'opencode/qwen3.6-plus-free': 'nano-gpt/qwen/qwen3.6-plus',
|
|
77
|
+
'opencode/glm-4.7-free': 'openrouter/z-ai/glm-4.7',
|
|
78
|
+
'opencode/glm-5-free': 'openrouter/z-ai/glm-5',
|
|
79
|
+
'opencode/hy3-free': 'openrouter/tencent/hy3',
|
|
80
|
+
'opencode/glm-5.3-flash-free': 'openrouter/z-ai/glm-5.3-flash',
|
|
81
|
+
'opencode/minimax-m2.5-free': 'openrouter/minimax/minimax-m2.5',
|
|
82
|
+
'opencode/minimax-m3-free': 'openrouter/minimax/minimax-m3',
|
|
83
|
+
'opencode/muse-spark-1.2-contributor-free': 'nano-gpt/meta/muse-spark-1.2',
|
|
84
|
+
'opencode/muse-spark-1.3-contributor-free': 'bothub/muse-spark-1.3-contributor',
|
|
85
|
+
'opencode/deepseek-v4-flash-free': 'openrouter/deepseek/deepseek-v4-flash',
|
|
86
|
+
'opencode/deepseek-v4.1-flash-free': 'openrouter/deepseek/deepseek-v4.1-flash',
|
|
87
|
+
'opencode/hy3-free': 'openrouter/tencent/hy3',
|
|
88
|
+
'opencode/glm-5.3-flash-free': 'openrouter/z-ai/glm-5.3-flash',
|
|
89
|
+
'opencode/nemotron-3.5-super-vl-free': 'openrouter/nvidia/nemotron-3.5-super-vl',
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
function getFreeModelMapping(provider, model) {
|
|
93
|
+
const key = `${provider}/${model}`;
|
|
94
|
+
const mapped = FREE_MODEL_MAPPING[key] || FREE_MODEL_MAPPING[model];
|
|
95
|
+
if (!mapped) return null;
|
|
96
|
+
const [mp, ...mm] = mapped.split('/');
|
|
97
|
+
return { provider: mp, model: mm.join('/') };
|
|
98
|
+
}
|
|
99
|
+
|
|
22
100
|
function catalogCandidates() {
|
|
23
101
|
const homes = [process.env.USERPROFILE, process.env.HOME].filter(Boolean);
|
|
24
102
|
const out = [];
|
|
@@ -52,18 +130,14 @@ function entry(data, provider, model) {
|
|
|
52
130
|
return nonzero(c) ? { input: c.input || 0, output: c.output || 0, cacheRead: c.cache_read || 0 } : null;
|
|
53
131
|
}
|
|
54
132
|
|
|
55
|
-
const stripFree = (m) => String(m).replace(/-contributor-free$/, '').replace(/-free$/, '').replace(/:free$/, '');
|
|
56
|
-
|
|
57
133
|
// Map a usage model (provider/model as recorded in the DB) to paid rates.
|
|
58
|
-
// Returns { input, output, cacheRead, source, kind } or null when the catalog
|
|
59
|
-
// has no comparable paid listing at all.
|
|
60
134
|
function priceFor(provider, model) {
|
|
61
135
|
const cat = loadCatalog();
|
|
62
136
|
if (!cat.data) return null;
|
|
63
137
|
const data = cat.data;
|
|
64
138
|
provider = provider || 'unknown';
|
|
65
139
|
model = model || 'unknown';
|
|
66
|
-
if (model === 'unknown') return null;
|
|
140
|
+
if (model === 'unknown') return null;
|
|
67
141
|
|
|
68
142
|
const mk = (p, m, kind) => {
|
|
69
143
|
const r = entry(data, p, m);
|
|
@@ -73,10 +147,7 @@ function priceFor(provider, model) {
|
|
|
73
147
|
let r = mk(provider, model, 'exact');
|
|
74
148
|
if (r) return r;
|
|
75
149
|
|
|
76
|
-
// Free suffixes
|
|
77
|
-
// (opencode records nvidia/nvidia/nemotron-... on some sessions). The plain
|
|
78
|
-
// base is always kept: a model that is free at ITS provider (cost 0) may
|
|
79
|
-
// still have a paid listing elsewhere (e.g. nvidia/z-ai/glm-5.3-flash).
|
|
150
|
+
// Free suffixes
|
|
80
151
|
const bases = [];
|
|
81
152
|
const deDup = model.startsWith(`${provider}/`) ? model.slice(provider.length + 1) : null;
|
|
82
153
|
for (const b of [stripFree(model), deDup && stripFree(deDup), deDup, model]) {
|
|
@@ -91,21 +162,16 @@ function priceFor(provider, model) {
|
|
|
91
162
|
r = mk('opencode', b, 'proxy');
|
|
92
163
|
if (r) return r;
|
|
93
164
|
}
|
|
94
|
-
|
|
95
|
-
//
|
|
96
|
-
// Also try the full model name (with provider prefix) as a base, since cache keys may include provider prefix.
|
|
165
|
+
|
|
166
|
+
// Any provider, cheapest nonzero listing for the same base name
|
|
97
167
|
const allBases = [...bases];
|
|
98
|
-
if (model !== bases[0] && !allBases.includes(model)) allBases.push(model);
|
|
99
|
-
// Also try provider/model as a base (for cases where model name doesn't include provider prefix but cache key does)
|
|
168
|
+
if (model !== bases[0] && !allBases.includes(model)) allBases.push(model);
|
|
100
169
|
const providerModel = `${provider}/${model}`;
|
|
101
170
|
if (!allBases.includes(providerModel)) allBases.push(providerModel);
|
|
102
|
-
// Also try openrouter/ + model (common case where sub-providers like reflection are under openrouter)
|
|
103
171
|
const openrouterModel = `openrouter/${model}`;
|
|
104
172
|
if (!allBases.includes(openrouterModel)) allBases.push(openrouterModel);
|
|
105
|
-
// Also try openrouter/provider/model (for cases where cache has openrouter/subprovider/model)
|
|
106
173
|
const openrouterProviderModel = `openrouter/${provider}/${model}`;
|
|
107
174
|
if (!allBases.includes(openrouterProviderModel)) allBases.push(openrouterProviderModel);
|
|
108
|
-
// Also try openrouter + common sub-providers (reflection, nvidia, etc.) for openrouter models without sub-provider prefix
|
|
109
175
|
if (provider === 'openrouter' && !model.includes('/')) {
|
|
110
176
|
const subProviders = ['reflection', 'nvidia', 'google', 'anthropic', 'meta', 'mistral', 'cohere', 'mistralai'];
|
|
111
177
|
for (const sub of subProviders) {
|
|
@@ -129,6 +195,14 @@ function priceFor(provider, model) {
|
|
|
129
195
|
return { ...rates, source: `${pid}/${b}`, kind: 'proxy' };
|
|
130
196
|
}
|
|
131
197
|
}
|
|
198
|
+
|
|
199
|
+
// Check manual free model mapping before final null return
|
|
200
|
+
const freeMapping = getFreeModelMapping(provider, model);
|
|
201
|
+
if (freeMapping) {
|
|
202
|
+
const r2 = mk(freeMapping.provider, freeMapping.model, 'proxy');
|
|
203
|
+
if (r2) return r2;
|
|
204
|
+
}
|
|
205
|
+
|
|
132
206
|
return null;
|
|
133
207
|
}
|
|
134
208
|
|
package/run-check.bat
ADDED
package/server.js
CHANGED
|
@@ -294,9 +294,10 @@ function splitModelName(name) {
|
|
|
294
294
|
function marketOf(tok, provider, model) {
|
|
295
295
|
const pr = pricing.priceFor(provider, model);
|
|
296
296
|
if (!pr) return { market: null, saved: null, pricedAs: null, priced: false, kind: 'unpriced' };
|
|
297
|
-
const
|
|
297
|
+
const marketRaw = pricing.marketOf(tok, pr);
|
|
298
298
|
const r4m = (v) => Math.round(v * 10000) / 10000;
|
|
299
|
-
|
|
299
|
+
// Calculate saved from unrounded market to avoid double-rounding error.
|
|
300
|
+
return { market: r4m(marketRaw), saved: r4m(marketRaw - (tok.cost || 0)), pricedAs: pr.source, priced: true, kind: pr.kind };
|
|
300
301
|
}
|
|
301
302
|
|
|
302
303
|
// Hybrid usage attribution over [startMs, endMs).
|
|
@@ -740,7 +741,20 @@ function getAttrAll() {
|
|
|
740
741
|
function getAttrPeriod(startMs) {
|
|
741
742
|
if (!attrAllCache) refreshAttrBundle();
|
|
742
743
|
if (!attrAllCache) return EMPTY_ATTR;
|
|
743
|
-
|
|
744
|
+
const periods = attrAllCache.a.periods;
|
|
745
|
+
const hit = periods.get(startMs);
|
|
746
|
+
if (hit) return hit;
|
|
747
|
+
// Key miss must NEVER fall back to the all-time buckets: that silently
|
|
748
|
+
// rendered lifetime tokens inside a Daily/Weekly card (the "7 days shows
|
|
749
|
+
// all-time models" bug). Pick the deepest slice that starts at or before
|
|
750
|
+
// the requested boundary; only a boundary older than every slice (or a
|
|
751
|
+
// bundle with no slices) legitimately means "all time".
|
|
752
|
+
let best = null;
|
|
753
|
+
for (const [k, sl] of periods) {
|
|
754
|
+
if (k === 0) continue;
|
|
755
|
+
if (k <= startMs && (!best || k > best.start)) best = sl;
|
|
756
|
+
}
|
|
757
|
+
return best || attrAllCache.a;
|
|
744
758
|
}
|
|
745
759
|
// Kick a fresh scan. The scan runs in a WORKER THREAD because it is
|
|
746
760
|
// synchronous better-sqlite3 + JSON work: inline it froze the event loop for
|
|
@@ -803,7 +817,7 @@ function spawnAttrWorker(now, rev) {
|
|
|
803
817
|
}
|
|
804
818
|
let w;
|
|
805
819
|
try {
|
|
806
|
-
w = new Worker(ATTR_WORKER, { workerData: { now, toolsStartMs: 0, dbRevision: rev } });
|
|
820
|
+
w = new Worker(ATTR_WORKER, { workerData: { now, toolsStartMs: 0, dbRevision: rev, dbPath: process.env.OPENCODE_DATA || '' } });
|
|
807
821
|
} catch (e) {
|
|
808
822
|
// Worker unavailable (very old Node / restricted env): build inline.
|
|
809
823
|
console.error('attr worker spawn failed, building inline:', e.message);
|
|
@@ -966,6 +980,7 @@ function getStatsFromDb(days) {
|
|
|
966
980
|
if (info.ok) {
|
|
967
981
|
priceAsOf = new Date(info.mtimeMs).toISOString();
|
|
968
982
|
marketTotal = 0;
|
|
983
|
+
savedTotal = 0;
|
|
969
984
|
for (const [name, m] of Object.entries(attr.perModel)) {
|
|
970
985
|
const { provider, model } = splitModelName(name);
|
|
971
986
|
const tok = { input: m.input, output: m.output, reasoning: m.reasoning, cacheRead: m.cacheRead, cost: m.cost };
|
|
@@ -976,10 +991,11 @@ function getStatsFromDb(days) {
|
|
|
976
991
|
continue;
|
|
977
992
|
}
|
|
978
993
|
marketTotal += mk.market;
|
|
994
|
+
savedTotal += mk.saved;
|
|
979
995
|
if (mk.kind === 'proxy') proxyMarket += mk.market;
|
|
980
996
|
}
|
|
981
997
|
marketTotal = Math.round(marketTotal * 10000) / 10000;
|
|
982
|
-
savedTotal = Math.round(
|
|
998
|
+
savedTotal = Math.round(savedTotal * 10000) / 10000;
|
|
983
999
|
proxyMarket = Math.round(proxyMarket * 10000) / 10000;
|
|
984
1000
|
}
|
|
985
1001
|
}
|
|
@@ -1142,7 +1158,7 @@ function periodStartMs(days, now) {
|
|
|
1142
1158
|
}
|
|
1143
1159
|
|
|
1144
1160
|
function buildReportFromDb(days) {
|
|
1145
|
-
const now = Date.now();
|
|
1161
|
+
const now = attrAllCache ? attrAllCache.at : Date.now(); // use bundle time for consistency
|
|
1146
1162
|
const startMs = periodStartMs(days, now);
|
|
1147
1163
|
const label = days === -1 ? 'All' : days <= 1 ? 'Daily' : days <= 7 ? 'Weekly' : 'Monthly';
|
|
1148
1164
|
|
|
@@ -1318,6 +1334,7 @@ function buildReportFromDb(days) {
|
|
|
1318
1334
|
const sumMkt = (rows) => rows.reduce((s, r) => s + (r.market || 0), 0);
|
|
1319
1335
|
const sumSaved = (rows) => rows.reduce((s, r) => s + (r.saved || 0), 0);
|
|
1320
1336
|
statsR.cost.marketTotal = Math.round(sumMkt(pProviderRows) * 10000) / 10000;
|
|
1337
|
+
// savedTotal = sum of per-model saved so it always matches the model table.
|
|
1321
1338
|
statsR.cost.savedTotal = Math.round(sumSaved(pProviderRows) * 10000) / 10000;
|
|
1322
1339
|
statsR.cost.savedPct = statsR.cost.marketTotal > 0 ? Math.round((statsR.cost.savedTotal / statsR.cost.marketTotal) * 1000) / 10 : null;
|
|
1323
1340
|
statsR.cost.priceAsOf = pricing.catalogInfo().ok ? new Date(pricing.catalogInfo().mtimeMs).toISOString() : null;
|
|
@@ -1334,7 +1351,7 @@ function buildReportFromDb(days) {
|
|
|
1334
1351
|
providers: pProviderRows,
|
|
1335
1352
|
sessions: pSessionRows,
|
|
1336
1353
|
priceAsOf: statsR.cost.priceAsOf,
|
|
1337
|
-
generatedAt:
|
|
1354
|
+
generatedAt: aNow, // bundle build time (consistent with period bucket boundaries)
|
|
1338
1355
|
};
|
|
1339
1356
|
}
|
|
1340
1357
|
|