opencode-statboard 1.0.6 → 1.0.8

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.6",
3
+ "version": "1.0.8",
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
@@ -154,8 +154,8 @@
154
154
  <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:14px">
155
155
  <h2 data-i18n="report" style="margin:0">USAGE REPORT</h2>
156
156
  <div class="range-btns" id="reportBtns">
157
- <span class="pill active" data-days="0" onclick="loadReport(0)" data-i18n="today">Today</span>
158
- <span class="pill" data-days="1" onclick="loadReport(1)" data-i18n="daily">Daily</span>
157
+ <span class="pill" data-days="-1" onclick="loadReport(-1)" data-i18n="all">All</span>
158
+ <span class="pill active" data-days="1" onclick="loadReport(1)" data-i18n="daily">Daily</span>
159
159
  <span class="pill" data-days="7" onclick="loadReport(7)" data-i18n="weekly">Weekly</span>
160
160
  <span class="pill" data-days="30" onclick="loadReport(30)" data-i18n="monthly">Monthly</span>
161
161
  </div>
@@ -175,7 +175,7 @@ const STRINGS = {
175
175
  thModel: 'Model', thMsgs: 'Messages', thUsage: 'Usage', thCost: 'Cost',
176
176
  dailyTrend: 'DAILY TREND ({days} DAYS)',
177
177
  inputDay: 'Input / Day', outputDay: 'Output / Day', cacheReadDay: 'Cache Read / Day', costDay: 'Cost / Day',
178
- report: 'USAGE REPORT', today: 'Today', daily: 'Daily', weekly: 'Weekly', monthly: 'Monthly',
178
+ report: 'USAGE REPORT', all: 'All', daily: 'Daily', weekly: 'Weekly', monthly: 'Monthly',
179
179
  updating: 'updating…', generating: 'Generating trend data…', cachedAt: 'cached at', allFree: 'All models free — no cost recorded',
180
180
  live: 'Live', loading: 'Loading…', lastUpdated: 'Last updated', dataAgo: 'data generated',
181
181
  statsFail: 'Failed to read opencode stats', connFail: 'Connection failed',
@@ -191,7 +191,7 @@ const STRINGS = {
191
191
  thModel: '模型', thMsgs: '訊息', thUsage: '用量', thCost: '費用',
192
192
  dailyTrend: '近 {days} 天趨勢',
193
193
  inputDay: 'Input / 天', outputDay: 'Output / 天', cacheReadDay: 'Cache Read / 天', costDay: '費用 / 天',
194
- report: '用量報告', today: '今天', daily: '每日', weekly: '每週', monthly: '每月',
194
+ report: '用量報告', all: '全部', daily: '每日', weekly: '每週', monthly: '每月',
195
195
  updating: '更新中…', generating: '趨勢資料產生中…', cachedAt: '快取於', allFree: '全部使用免費模型,無費用紀錄',
196
196
  live: '即時更新', loading: '載入中…', lastUpdated: '更新於', dataAgo: '數據產生於',
197
197
  statsFail: 'opencode stats 讀取失敗', connFail: '連線失敗',
@@ -456,7 +456,7 @@ async function loadReport(days) {
456
456
  applyI18n();
457
457
  poll();
458
458
  setInterval(poll, 15000);
459
- loadReport(0);
459
+ loadReport(1);
460
460
  </script>
461
461
  </body>
462
462
  </html>
package/server.js CHANGED
@@ -271,18 +271,22 @@ function parseTSV(text) {
271
271
  }
272
272
 
273
273
  async function buildReport(days) {
274
- const label = days === 0 ? 'Today' : days <= 1 ? 'Daily' : days <= 7 ? 'Weekly' : 'Monthly';
275
- const timeFilter = days === 0
276
- ? `(strftime('%s','now','start of day') * 1000)`
274
+ const label = days === -1 ? 'All' : days <= 1 ? 'Daily' : days <= 7 ? 'Weekly' : 'Monthly';
275
+ const timeFilter = days === -1
276
+ ? '1=1'
277
277
  : days <= 1
278
278
  ? `(strftime('%s','now','start of day') * 1000)`
279
279
  : days <= 7
280
280
  ? `(strftime('%s','now','start of day', '-${days - 1} day') * 1000)`
281
281
  : `(strftime('%s','now','start of month') * 1000)`;
282
- let statsR = await runStats(['stats', '--days', String(Math.max(days, 1)), '--models', '20']);
282
+ let statsR = days === -1
283
+ ? await runStats(['stats', '--models', '20'])
284
+ : await runStats(['stats', '--days', String(Math.max(days, 1)), '--models', '20']);
283
285
  if (!statsR) {
284
286
  await new Promise((r) => setTimeout(r, 2000));
285
- statsR = await runStats(['stats', '--days', String(Math.max(days, 1)), '--models', '20']);
287
+ statsR = days === -1
288
+ ? await runStats(['stats', '--models', '20'])
289
+ : await runStats(['stats', '--days', String(Math.max(days, 1)), '--models', '20']);
286
290
  }
287
291
  const [agentR, modelR] = await Promise.all([
288
292
  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']),