opencode-statboard 1.0.8 → 1.0.10

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": "opencode-statboard",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Real-time dashboard for opencode token usage and cost statistics",
5
5
  "main": "server.js",
6
6
  "bin": {
package/public/index.html CHANGED
@@ -353,6 +353,12 @@ async function poll() {
353
353
  try {
354
354
  const r = await fetch('/api/stats?days=' + currentDays + '&_=' + Date.now(), { cache: 'no-store' });
355
355
  const j = await r.json();
356
+ if (j.loading) {
357
+ $('pill').textContent = t('updating');
358
+ $('pill').className = 'pill lang';
359
+ $('updated').textContent = t('updating');
360
+ return;
361
+ }
356
362
  if (!j.ok) {
357
363
  $('errbanner').textContent = t('statsFail') + ': ' + (j.error || '');
358
364
  $('errbanner').classList.add('show');
package/server.js CHANGED
@@ -18,7 +18,7 @@ const EXE = (() => {
18
18
  return 'opencode';
19
19
  })();
20
20
 
21
- const state = { data: null, busy: false, error: null, updatedAt: 0, models: null, modelsBusy: false };
21
+ const state = { data: null, busy: false, error: null, updatedAt: 0, models: null, modelsBusy: false, loading: true };
22
22
 
23
23
  let indexHtmlCache = null;
24
24
 
@@ -223,6 +223,7 @@ async function refresh() {
223
223
  } else {
224
224
  state.error = state.error || 'opencode stats failed';
225
225
  }
226
+ state.loading = false;
226
227
  state.busy = false;
227
228
  }
228
229
 
@@ -290,7 +291,7 @@ async function buildReport(days) {
290
291
  }
291
292
  const [agentR, modelR] = await Promise.all([
292
293
  run(['db', `SELECT agent, COUNT(*) AS sessions, ROUND(SUM(cost),4) AS cost, SUM(tokens_input) AS tok_in, SUM(tokens_output) AS tok_out, SUM(tokens_cache_read) AS cache_read FROM session WHERE agent IS NOT NULL AND time_updated >= ${timeFilter} GROUP BY agent ORDER BY cost DESC;`, '--format', 'tsv']),
293
- run(['db', `SELECT json_extract(model,'$.providerID') AS provider, json_extract(model,'$.id') AS model, COUNT(*) AS sessions, ROUND(SUM(cost),4) AS cost, SUM(tokens_input) AS tok_in, SUM(tokens_output) AS tok_out, SUM(tokens_cache_read) AS cache_read FROM session WHERE model IS NOT NULL AND time_updated >= ${timeFilter} GROUP BY provider, model ORDER BY cost DESC;`, '--format', 'tsv']),
294
+ run(['db', `SELECT COALESCE(json_extract(model,'$.providerID'), 'unknown') AS provider, COALESCE(json_extract(model,'$.id'), 'unknown') AS model, COUNT(*) AS sessions, ROUND(SUM(cost),4) AS cost, SUM(tokens_input) AS tok_in, SUM(tokens_output) AS tok_out, SUM(tokens_cache_read) AS cache_read FROM session WHERE time_updated >= ${timeFilter} GROUP BY provider, model ORDER BY cost DESC;`, '--format', 'tsv']),
294
295
  ]);
295
296
  return {
296
297
  label: label,
@@ -329,6 +330,7 @@ const server = http.createServer(async (req, res) => {
329
330
  res.setHeader('Cache-Control', 'no-store');
330
331
  res.end(JSON.stringify({
331
332
  ok: !!state.data,
333
+ loading: state.loading,
332
334
  error: state.error,
333
335
  generatedAt: state.updatedAt,
334
336
  data: state.data,