opencode-statboard 1.0.0 → 1.0.2
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 +8 -2
- package/public/index.html +5 -4
- package/server.js +13 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-statboard",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Real-time dashboard for opencode token usage and cost statistics",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"bin": {
|
|
@@ -9,7 +9,13 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"start": "node server.js"
|
|
11
11
|
},
|
|
12
|
-
"keywords": [
|
|
12
|
+
"keywords": [
|
|
13
|
+
"opencode",
|
|
14
|
+
"dashboard",
|
|
15
|
+
"tokens",
|
|
16
|
+
"usage",
|
|
17
|
+
"statistics"
|
|
18
|
+
],
|
|
13
19
|
"author": "thumb2086",
|
|
14
20
|
"license": "MIT",
|
|
15
21
|
"repository": {
|
package/public/index.html
CHANGED
|
@@ -154,7 +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="
|
|
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>
|
|
158
159
|
<span class="pill" data-days="7" onclick="loadReport(7)" data-i18n="weekly">Weekly</span>
|
|
159
160
|
<span class="pill" data-days="30" onclick="loadReport(30)" data-i18n="monthly">Monthly</span>
|
|
160
161
|
</div>
|
|
@@ -174,7 +175,7 @@ const STRINGS = {
|
|
|
174
175
|
thModel: 'Model', thMsgs: 'Messages', thUsage: 'Usage', thCost: 'Cost',
|
|
175
176
|
dailyTrend: 'DAILY TREND ({days} DAYS)',
|
|
176
177
|
inputDay: 'Input / Day', outputDay: 'Output / Day', cacheReadDay: 'Cache Read / Day', costDay: 'Cost / Day',
|
|
177
|
-
report: 'USAGE REPORT', daily: 'Daily', weekly: 'Weekly', monthly: 'Monthly',
|
|
178
|
+
report: 'USAGE REPORT', today: 'Today', daily: 'Daily', weekly: 'Weekly', monthly: 'Monthly',
|
|
178
179
|
updating: 'updating…', generating: 'Generating trend data…', cachedAt: 'cached at', allFree: 'All models free — no cost recorded',
|
|
179
180
|
live: 'Live', loading: 'Loading…', lastUpdated: 'Last updated', dataAgo: 'data generated',
|
|
180
181
|
statsFail: 'Failed to read opencode stats', connFail: 'Connection failed',
|
|
@@ -190,7 +191,7 @@ const STRINGS = {
|
|
|
190
191
|
thModel: '模型', thMsgs: '訊息', thUsage: '用量', thCost: '費用',
|
|
191
192
|
dailyTrend: '近 {days} 天趨勢',
|
|
192
193
|
inputDay: 'Input / 天', outputDay: 'Output / 天', cacheReadDay: 'Cache Read / 天', costDay: '費用 / 天',
|
|
193
|
-
report: '用量報告', daily: '每日', weekly: '每週', monthly: '每月',
|
|
194
|
+
report: '用量報告', today: '今天', daily: '每日', weekly: '每週', monthly: '每月',
|
|
194
195
|
updating: '更新中…', generating: '趨勢資料產生中…', cachedAt: '快取於', allFree: '全部使用免費模型,無費用紀錄',
|
|
195
196
|
live: '即時更新', loading: '載入中…', lastUpdated: '更新於', dataAgo: '數據產生於',
|
|
196
197
|
statsFail: 'opencode stats 讀取失敗', connFail: '連線失敗',
|
|
@@ -455,7 +456,7 @@ async function loadReport(days) {
|
|
|
455
456
|
applyI18n();
|
|
456
457
|
poll();
|
|
457
458
|
setInterval(poll, 15000);
|
|
458
|
-
loadReport(
|
|
459
|
+
loadReport(0);
|
|
459
460
|
</script>
|
|
460
461
|
</body>
|
|
461
462
|
</html>
|
package/server.js
CHANGED
|
@@ -258,15 +258,18 @@ function parseTSV(text) {
|
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
async function buildReport(days) {
|
|
261
|
-
const label = days <= 1 ? 'Daily' : days <= 7 ? 'Weekly' : 'Monthly';
|
|
262
|
-
|
|
261
|
+
const label = days === 0 ? 'Today' : days <= 1 ? 'Daily' : days <= 7 ? 'Weekly' : 'Monthly';
|
|
262
|
+
const timeFilter = days === 0
|
|
263
|
+
? `(strftime('%s','now','start of day') * 1000)`
|
|
264
|
+
: `(strftime('%s','now','-${days} day') * 1000)`;
|
|
265
|
+
let statsR = await runStats(['stats', '--days', String(Math.max(days, 1)), '--models', '20']);
|
|
263
266
|
if (!statsR) {
|
|
264
267
|
await new Promise((r) => setTimeout(r, 2000));
|
|
265
|
-
statsR = await runStats(['stats', '--days', String(days), '--models', '20']);
|
|
268
|
+
statsR = await runStats(['stats', '--days', String(Math.max(days, 1)), '--models', '20']);
|
|
266
269
|
}
|
|
267
270
|
const [agentR, modelR] = await Promise.all([
|
|
268
|
-
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 >=
|
|
269
|
-
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 >=
|
|
271
|
+
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']),
|
|
272
|
+
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']),
|
|
270
273
|
]);
|
|
271
274
|
return {
|
|
272
275
|
label: label,
|
|
@@ -355,7 +358,11 @@ setInterval(() => {
|
|
|
355
358
|
}, CACHE_CLEANUP_MS);
|
|
356
359
|
|
|
357
360
|
(async () => {
|
|
358
|
-
|
|
361
|
+
server.listen(PORT, '127.0.0.1', () => {
|
|
362
|
+
console.log(`opencode stats dashboard: http://127.0.0.1:${PORT}`);
|
|
363
|
+
});
|
|
364
|
+
setInterval(refresh, REFRESH_MS);
|
|
365
|
+
setInterval(refreshModels, 60000);
|
|
359
366
|
await refresh();
|
|
360
367
|
await refreshModels();
|
|
361
368
|
for (const d of [1, 7, 30]) {
|
|
@@ -366,9 +373,4 @@ setInterval(() => {
|
|
|
366
373
|
const t = await generateTrend(d);
|
|
367
374
|
if (t) trendCache[String(d)] = t;
|
|
368
375
|
}
|
|
369
|
-
setInterval(refresh, REFRESH_MS);
|
|
370
|
-
setInterval(refreshModels, 60000);
|
|
371
|
-
server.listen(PORT, '127.0.0.1', () => {
|
|
372
|
-
console.log(`opencode stats dashboard: http://127.0.0.1:${PORT}`);
|
|
373
|
-
});
|
|
374
376
|
})();
|