opencode-statboard 2.4.0 → 2.5.0

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/server.js CHANGED
@@ -279,15 +279,17 @@ function splitModelName(name) {
279
279
  }
280
280
 
281
281
  // Market estimate for token usage at catalog paid rates (USD). saved is
282
- // market minus actual cost. pricedAs records the catalog entry used
283
- // ("proxy:" prefix = fallback estimate). Null when no pricing catalog.
282
+ // market minus actual cost. kind is 'exact' | 'sibling' | 'proxy' — how the
283
+ // rate was found; null (kind 'unpriced') when the catalog has NO comparable
284
+ // paid listing, in which case we report no money at all rather than inventing
285
+ // a rate (that fake rate once turned a $0 model into $212 of phantom savings).
284
286
  // Market-price engine rules live in pricing.js (shared with check scripts).
285
287
  function marketOf(tok, provider, model) {
286
288
  const pr = pricing.priceFor(provider, model);
287
- if (!pr) return { market: null, saved: null, pricedAs: null };
289
+ if (!pr) return { market: null, saved: null, pricedAs: null, priced: false, kind: 'unpriced' };
288
290
  const market = pricing.marketOf(tok, pr);
289
291
  const r4m = (v) => Math.round(v * 10000) / 10000;
290
- return { market: r4m(market), saved: r4m(market - (tok.cost || 0)), pricedAs: pr.source };
292
+ return { market: r4m(market), saved: r4m(market - (tok.cost || 0)), pricedAs: pr.source, priced: true, kind: pr.kind };
291
293
  }
292
294
 
293
295
  // Hybrid usage attribution over [startMs, endMs).
@@ -582,8 +584,12 @@ function getStatsFromDb(days) {
582
584
 
583
585
  // Savings estimate: market value of all-time usage at catalog paid rates,
584
586
  // priced per MESSAGE model (residual falls back to the session's model) —
585
- // the same basis as the report providers table.
587
+ // the same basis as the report providers table. Rows the catalog cannot
588
+ // price are EXCLUDED and disclosed (unpricedTokens/unpricedRows) instead of
589
+ // being valued at a made-up rate; proxyShare is how much of the priced
590
+ // total comes from cross-provider estimates.
586
591
  let marketTotal = null, savedTotal = null, priceAsOf = null;
592
+ let unpricedRows = 0, unpricedTokens = 0, proxyMarket = 0;
587
593
  {
588
594
  const info = pricing.catalogInfo();
589
595
  if (info.ok) {
@@ -591,14 +597,19 @@ function getStatsFromDb(days) {
591
597
  marketTotal = 0;
592
598
  for (const [name, m] of Object.entries(attr.perModel)) {
593
599
  const { provider, model } = splitModelName(name);
594
- const mk = marketOf({ input: m.input, output: m.output, reasoning: m.reasoning, cacheRead: m.cacheRead, cost: m.cost }, provider, model);
595
- if (mk.market === null) { marketTotal = null; break; }
600
+ const tok = { input: m.input, output: m.output, reasoning: m.reasoning, cacheRead: m.cacheRead, cost: m.cost };
601
+ const mk = marketOf(tok, provider, model);
602
+ if (!mk.priced) {
603
+ unpricedRows++;
604
+ unpricedTokens += tok.input + tok.output + tok.reasoning + tok.cacheRead;
605
+ continue;
606
+ }
596
607
  marketTotal += mk.market;
608
+ if (mk.kind === 'proxy') proxyMarket += mk.market;
597
609
  }
598
- if (marketTotal !== null) {
599
- marketTotal = Math.round(marketTotal * 10000) / 10000;
600
- savedTotal = Math.round((marketTotal - T.cost) * 10000) / 10000;
601
- } else { savedTotal = null; }
610
+ marketTotal = Math.round(marketTotal * 10000) / 10000;
611
+ savedTotal = Math.round((marketTotal - T.cost) * 10000) / 10000;
612
+ proxyMarket = Math.round(proxyMarket * 10000) / 10000;
602
613
  }
603
614
  }
604
615
 
@@ -616,6 +627,8 @@ function getStatsFromDb(days) {
616
627
  cacheRead: Math.round(T.cacheRead),
617
628
  cacheWrite: Math.round(T.cacheWrite),
618
629
  marketTotal, savedTotal, priceAsOf,
630
+ unpricedRows, unpricedTokens, proxyMarket,
631
+ proxyShare: marketTotal > 0 ? Math.round((proxyMarket / marketTotal) * 1000) / 10 : null,
619
632
  },
620
633
  tools,
621
634
  models,
@@ -846,20 +859,21 @@ function buildReportFromDb(days) {
846
859
  tok_in: Math.round(m.input), tok_out: Math.round(m.output),
847
860
  tok_reasoning: Math.round(m.reasoning), cache_read: Math.round(m.cacheRead),
848
861
  speed: m.speedMs > 0 ? Math.round((m.speedOut / (m.speedMs / 1000)) * 10) / 10 : null,
849
- market: mk.market, saved: mk.saved, pricedAs: mk.pricedAs,
862
+ market: mk.market, saved: mk.saved, pricedAs: mk.pricedAs, priced: mk.priced, kind: mk.kind,
850
863
  };
851
864
  })
852
865
  .sort((x, y) => y.cost - x.cost);
853
866
 
854
867
  var pAgentRows = Object.entries(a.perAgentPeriod)
855
868
  .map(([agent, m]) => {
856
- let market = 0, saved = 0, priced = false;
869
+ let market = 0, saved = 0, pricedAny = false, unpriced = 0, proxy = 0;
857
870
  const bag = (a.perAgentModelPeriod && a.perAgentModelPeriod[agent]) || {};
858
871
  for (const [name, b] of Object.entries(bag)) {
859
872
  const { provider, model } = splitModelName(name);
860
873
  const mk = marketOf({ input: b.input, output: b.output, reasoning: b.reasoning, cacheRead: b.cacheRead, cost: b.cost }, provider, model);
861
- if (mk.market === null) { market = null; break; }
862
- market += mk.market; saved += mk.saved; priced = true;
874
+ if (!mk.priced) { unpriced++; continue; }
875
+ market += mk.market; saved += mk.saved; pricedAny = true;
876
+ if (mk.kind === 'proxy') proxy += mk.market;
863
877
  }
864
878
  // Wall = period span measured on the message clock (see wallMs above).
865
879
  let agentWall = 0;
@@ -871,9 +885,10 @@ function buildReportFromDb(days) {
871
885
  speed: msgAgentAgg[agent] && msgAgentAgg[agent].ms > 0 ? Math.round((msgAgentAgg[agent].o / (msgAgentAgg[agent].ms / 1000)) * 10) / 10 : null,
872
886
  wallMs: Math.round(agentWall),
873
887
  activeMs: msgAgentAgg[agent] ? Math.round(msgAgentAgg[agent].ms) : 0,
874
- market: market === null ? null : Math.round(market * 10000) / 10000,
875
- saved: market === null ? null : Math.round(saved * 10000) / 10000,
876
- pricedAs: priced,
888
+ market: pricedAny ? Math.round(market * 10000) / 10000 : null,
889
+ saved: pricedAny ? Math.round(saved * 10000) / 10000 : null,
890
+ pricedAs: pricedAny ? (proxy > 0 && proxy >= market - 0.01 ? 'mixed' : 'exact') : null,
891
+ priced: pricedAny, kind: !pricedAny ? 'unpriced' : (unpriced > 0 ? 'partial' : (proxy > 0 ? 'proxy' : 'exact')),
877
892
  };
878
893
  })
879
894
  .sort((x, y) => y.cost - x.cost);
@@ -905,7 +920,7 @@ function buildReportFromDb(days) {
905
920
  tok_reasoning: Math.round(mg.rq || 0),
906
921
  cost: r4(ps.cost),
907
922
  speed: (mg.ms || 0) > 0 ? Math.round(((mg.o || 0) / (mg.ms / 1000)) * 10) / 10 : null,
908
- market, saved, pricedAs,
923
+ market, saved, pricedAs, priced: mkS.priced, kind: mkS.kind,
909
924
  };
910
925
  })
911
926
  .sort((x, y) => y.activeMs - x.activeMs)
@@ -916,14 +931,19 @@ function buildReportFromDb(days) {
916
931
  var pSessionRows = [];
917
932
  }
918
933
 
919
- // Period market = Σ provider rows (already period-scoped); saved = Σ provider
920
- // saved so it can never mix a period cost with a lifetime market.
934
+ // Period market = Σ priced provider rows (already period-scoped); saved = Σ
935
+ // provider saved so it can never mix a period cost with a lifetime market.
936
+ // Unpriced rows are disclosed, not valued.
921
937
  const sumMkt = (rows) => rows.reduce((s, r) => s + (r.market || 0), 0);
922
938
  const sumSaved = (rows) => rows.reduce((s, r) => s + (r.saved || 0), 0);
923
939
  statsR.cost.marketTotal = Math.round(sumMkt(pProviderRows) * 10000) / 10000;
924
940
  statsR.cost.savedTotal = Math.round(sumSaved(pProviderRows) * 10000) / 10000;
925
941
  statsR.cost.savedPct = statsR.cost.marketTotal > 0 ? Math.round((statsR.cost.savedTotal / statsR.cost.marketTotal) * 1000) / 10 : null;
926
942
  statsR.cost.priceAsOf = pricing.catalogInfo().ok ? new Date(pricing.catalogInfo().mtimeMs).toISOString() : null;
943
+ statsR.cost.unpricedRows = pProviderRows.filter((r) => !r.priced).length;
944
+ 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);
945
+ const proxyMkt = pProviderRows.filter((r) => r.kind === 'proxy').reduce((s, r) => s + (r.market || 0), 0);
946
+ statsR.cost.proxyShare = statsR.cost.marketTotal > 0 ? Math.round((proxyMkt / statsR.cost.marketTotal) * 1000) / 10 : null;
927
947
 
928
948
  return {
929
949
  label,