opencode-statboard 2.10.21 → 2.10.22
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 +1 -1
- package/pricing.js +71 -0
- package/public/index.html +6 -0
- package/server.js +2 -2
package/package.json
CHANGED
package/pricing.js
CHANGED
|
@@ -130,6 +130,73 @@ function entry(data, provider, model) {
|
|
|
130
130
|
return nonzero(c) ? { input: c.input || 0, output: c.output || 0, cacheRead: c.cache_read || 0 } : null;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
// ---- live OpenRouter list-price fallback -------------------------------
|
|
134
|
+
// The local opencode catalog (models.json) is a snapshot and misses plenty of
|
|
135
|
+
// paid listings (OpenRouter alone lists 477 models). When nothing local matches
|
|
136
|
+
// we consult OpenRouter's public model list, cached on disk for 12h and
|
|
137
|
+
// refreshed in the background so no request ever waits on the network.
|
|
138
|
+
// Rates are USD per token there, so ×1e6 to match the local catalog's unit.
|
|
139
|
+
const OR_URL = 'https://openrouter.ai/api/v1/models';
|
|
140
|
+
const OR_TTL = 12 * 60 * 60 * 1000;
|
|
141
|
+
const OR_DIR = path.join(process.env.USERPROFILE || process.env.HOME || process.cwd(), '.cache', 'opencode-statboard');
|
|
142
|
+
const OR_FILE = path.join(OR_DIR, 'openrouter-models.json');
|
|
143
|
+
let orCache = { at: 0, models: null, refreshing: false };
|
|
144
|
+
|
|
145
|
+
function orLoad() {
|
|
146
|
+
if (orCache.models) return orCache;
|
|
147
|
+
try {
|
|
148
|
+
const o = JSON.parse(fs.readFileSync(OR_FILE, 'utf8'));
|
|
149
|
+
if (o && o.models && o.fetchedAt) orCache = { at: o.fetchedAt, models: o.models, refreshing: false };
|
|
150
|
+
} catch (_) { /* first run: no cache yet */ }
|
|
151
|
+
return orCache;
|
|
152
|
+
}
|
|
153
|
+
function orRefresh() {
|
|
154
|
+
if (orCache.refreshing) return;
|
|
155
|
+
orCache.refreshing = true;
|
|
156
|
+
const run = async () => {
|
|
157
|
+
try {
|
|
158
|
+
const res = await fetch(OR_URL, { headers: { 'user-agent': 'opencode-statboard' } });
|
|
159
|
+
if (!res.ok) return;
|
|
160
|
+
const j = await res.json();
|
|
161
|
+
const models = {};
|
|
162
|
+
for (const m of (j.data || [])) {
|
|
163
|
+
const p = m.pricing || {};
|
|
164
|
+
const input = Number(p.prompt || 0) * 1e6;
|
|
165
|
+
const output = Number(p.completion || 0) * 1e6;
|
|
166
|
+
const cacheRead = Number(p.input_cache_read || 0) * 1e6;
|
|
167
|
+
if (!(input > 0) && !(output > 0)) continue; // free listings carry no paid basis
|
|
168
|
+
models[m.id] = { input, output, cacheRead };
|
|
169
|
+
}
|
|
170
|
+
orCache = { at: Date.now(), models, refreshing: false };
|
|
171
|
+
try { fs.mkdirSync(OR_DIR, { recursive: true }); fs.writeFileSync(OR_FILE, JSON.stringify({ fetchedAt: orCache.at, models })); } catch (_) {}
|
|
172
|
+
} catch (_) { orCache.refreshing = false; }
|
|
173
|
+
};
|
|
174
|
+
run();
|
|
175
|
+
}
|
|
176
|
+
function orEntry(provider, model) {
|
|
177
|
+
const c = orLoad();
|
|
178
|
+
if (!c.models) {
|
|
179
|
+
if (Date.now() - c.at > OR_TTL) orRefresh();
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
if (Date.now() - c.at > OR_TTL) orRefresh();
|
|
183
|
+
const bare = stripFree(model);
|
|
184
|
+
const cands = [];
|
|
185
|
+
const push = (s) => { if (s && !cands.includes(s)) cands.push(s); };
|
|
186
|
+
push(`${provider}/${model}`); push(`${provider}/${bare}`);
|
|
187
|
+
push(model); push(bare);
|
|
188
|
+
if (model.includes('/')) { const rest = model.split('/').slice(1).join('/'); push(rest); push(stripFree(rest)); }
|
|
189
|
+
for (const id of cands) if (c.models[id]) return { ...c.models[id], id };
|
|
190
|
+
// Last resort: unique match on the final path segment (deepseek-ai/deepseek-v4.1-flash
|
|
191
|
+
// → deepseek/deepseek-v4.1-flash). Only when exactly one paid listing matches.
|
|
192
|
+
const last = String(bare).split('/').pop();
|
|
193
|
+
if (last && last !== 'unknown') {
|
|
194
|
+
const hits = Object.keys(c.models).filter((id) => id.split('/').pop() === last);
|
|
195
|
+
if (hits.length === 1) return { ...c.models[hits[0]], id: hits[0] };
|
|
196
|
+
}
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
|
|
133
200
|
// Map a usage model (provider/model as recorded in the DB) to paid rates.
|
|
134
201
|
function priceFor(provider, model) {
|
|
135
202
|
const cat = loadCatalog();
|
|
@@ -203,6 +270,10 @@ function priceFor(provider, model) {
|
|
|
203
270
|
if (r2) return r2;
|
|
204
271
|
}
|
|
205
272
|
|
|
273
|
+
// Live OpenRouter list price (paid twin of a free/unknown model).
|
|
274
|
+
const or = orEntry(provider, model);
|
|
275
|
+
if (or) return { input: or.input, output: or.output, cacheRead: or.cacheRead, source: `openrouter:${or.id}`, kind: 'openrouter' };
|
|
276
|
+
|
|
206
277
|
return null;
|
|
207
278
|
}
|
|
208
279
|
|
package/public/index.html
CHANGED
|
@@ -150,6 +150,7 @@
|
|
|
150
150
|
.badge.exact { color: #3fb950; border-color: rgba(63,185,80,.4); }
|
|
151
151
|
.badge.sibling { color: #58a6ff; border-color: rgba(88,166,255,.4); }
|
|
152
152
|
.badge.proxy { color: #d29922; border-color: rgba(210,153,34,.4); }
|
|
153
|
+
.badge.openrouter { color: #a371f7; border-color: rgba(163,113,247,.4); }
|
|
153
154
|
.badge.partial { color: #f778ba; border-color: rgba(247,120,186,.4); }
|
|
154
155
|
.badge.unpriced { color: #f85149; border-color: rgba(248,81,73,.4); }
|
|
155
156
|
.empty { color: var(--muted); font-size: 13px; padding: 12px 0; }
|
|
@@ -342,6 +343,7 @@
|
|
|
342
343
|
<span><span class="badge exact" data-i18n="kindExact">exact</span> <span data-i18n="kindExactTip">own provider + own list price</span></span>
|
|
343
344
|
<span><span class="badge sibling" data-i18n="kindSibling">sibling</span> <span data-i18n="kindSiblingTip">same provider, -free variant stripped</span></span>
|
|
344
345
|
<span><span class="badge proxy" data-i18n="kindProxy">proxy</span> <span data-i18n="kindProxyTip">borrowed price from another provider (estimate)</span></span>
|
|
346
|
+
<span><span class="badge openrouter" data-i18n="kindOpenrouter">openrouter</span> <span data-i18n="kindOpenrouterTip">live OpenRouter list price for the paid twin</span></span>
|
|
345
347
|
<span><span class="badge partial" data-i18n="kindPartial">partial</span> <span data-i18n="kindPartialTip">part priced, part not in catalog</span></span>
|
|
346
348
|
<span><span class="badge unpriced" data-i18n="kindUnpriced">unpriced</span> <span data-i18n="kindUnpricedTip">not in catalog — market/saved unknown</span></span>
|
|
347
349
|
</div>
|
|
@@ -398,6 +400,8 @@ const STRINGS = {
|
|
|
398
400
|
kindExactTip: 'own provider + own list price',
|
|
399
401
|
kindSiblingTip: 'same provider, -free variant stripped',
|
|
400
402
|
kindProxyTip: 'borrowed price from another provider (estimate)',
|
|
403
|
+
kindOpenrouter: 'openrouter',
|
|
404
|
+
kindOpenrouterTip: 'live OpenRouter list price for the paid twin',
|
|
401
405
|
kindPartialTip: 'part of the usage priced, rest not in catalog',
|
|
402
406
|
kindUnpricedTip: 'not in catalog — market/saved unknown',
|
|
403
407
|
legacyAgent: 'legacy',
|
|
@@ -444,6 +448,8 @@ const STRINGS = {
|
|
|
444
448
|
kindExactTip: '同供應商同名牌價',
|
|
445
449
|
kindSiblingTip: '同供應商,去掉 -free 變體',
|
|
446
450
|
kindProxyTip: '借用其他供應商牌價(代估)',
|
|
451
|
+
kindOpenrouter: 'openrouter',
|
|
452
|
+
kindOpenrouterTip: 'OpenRouter 即時牌價(同級付費版)',
|
|
447
453
|
kindPartialTip: '部分用量有牌價,其餘查無',
|
|
448
454
|
kindUnpricedTip: '目錄查無 — 市價/節省未知',
|
|
449
455
|
legacyAgent: '舊版',
|
package/server.js
CHANGED
|
@@ -992,7 +992,7 @@ function getStatsFromDb(days) {
|
|
|
992
992
|
}
|
|
993
993
|
marketTotal += mk.market;
|
|
994
994
|
savedTotal += mk.saved;
|
|
995
|
-
if (mk.kind === 'proxy') proxyMarket += mk.market;
|
|
995
|
+
if (mk.kind === 'proxy' || mk.kind === 'openrouter') proxyMarket += mk.market;
|
|
996
996
|
}
|
|
997
997
|
marketTotal = Math.round(marketTotal * 10000) / 10000;
|
|
998
998
|
savedTotal = Math.round(savedTotal * 10000) / 10000;
|
|
@@ -1340,7 +1340,7 @@ function buildReportFromDb(days) {
|
|
|
1340
1340
|
statsR.cost.priceAsOf = pricing.catalogInfo().ok ? new Date(pricing.catalogInfo().mtimeMs).toISOString() : null;
|
|
1341
1341
|
statsR.cost.unpricedRows = pProviderRows.filter((r) => !r.priced).length;
|
|
1342
1342
|
statsR.cost.unpricedTokens = pProviderRows.filter((r) => !r.priced).reduce((s, r) => s + r.tok_in + r.tok_out + r.tok_reasoning + r.cache_read, 0);
|
|
1343
|
-
const proxyMkt = pProviderRows.filter((r) => r.kind === 'proxy').reduce((s, r) => s + (r.market || 0), 0);
|
|
1343
|
+
const proxyMkt = pProviderRows.filter((r) => r.kind === 'proxy' || r.kind === 'openrouter').reduce((s, r) => s + (r.market || 0), 0);
|
|
1344
1344
|
statsR.cost.proxyShare = statsR.cost.marketTotal > 0 ? Math.round((proxyMkt / statsR.cost.marketTotal) * 1000) / 10 : null;
|
|
1345
1345
|
|
|
1346
1346
|
return {
|