opencode-statboard 2.10.14 → 2.10.16
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/fix-i18n.js +161 -0
- package/package.json +1 -1
- package/test-open.js +4 -0
- package/tui-dashboard.js +48 -12
package/fix-i18n.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const c = fs.readFileSync('tui-dashboard.js', 'utf8');
|
|
3
|
+
|
|
4
|
+
const zhOld = ` zh: {
|
|
5
|
+
title: 'opencode-statboard v{version} TUI',
|
|
6
|
+
keys: '[1]總覽 [2]專案 [3]模型 [4]趨勢 [5]熱力 [W]網頁 [R]重整 [Q]離開 [L]語言',
|
|
7
|
+
footer: '上次更新: {time} | 視圖: {view} | W:網頁 R:重整 Q:離開',
|
|
8
|
+
loading: '載入資料中...',
|
|
9
|
+
error: '錯誤: {error}',
|
|
10
|
+
overview: '總覽',
|
|
11
|
+
projects: '專案',
|
|
12
|
+
models: '模型',
|
|
13
|
+
trend: '趨勢 (90 天)',
|
|
14
|
+
heatmap: '熱力圖',
|
|
15
|
+
noData: '無資料',
|
|
16
|
+
sessions: '會話',
|
|
17
|
+
main: '主',
|
|
18
|
+
total: '總計',
|
|
19
|
+
projectsLabel: '專案數',
|
|
20
|
+
days: '天數',
|
|
21
|
+
messages: '訊息',
|
|
22
|
+
tokens: 'Token',
|
|
23
|
+
input: '輸入',
|
|
24
|
+
output: '輸出',
|
|
25
|
+
reasoning: '推理',
|
|
26
|
+
cacheRead: '快取讀取',
|
|
27
|
+
cacheWrite: '快取寫入',
|
|
28
|
+
total: '總計',
|
|
29
|
+
cost: '成本',
|
|
30
|
+
marketValue: '市場價值',
|
|
31
|
+
saved: '節省',
|
|
32
|
+
avgCostDay: '日均成本',
|
|
33
|
+
avgTokensDay: '日均Token',
|
|
34
|
+
projectHeader: '{專案:<45} {會話:>10} {Token:>18} {成本:>14}',
|
|
35
|
+
modelHeader: '{模型:<40} {供應商:<14} {Token:>18} {成本:>12} {速度:>10}',
|
|
36
|
+
unknown: '未知',
|
|
37
|
+
today: '今天',
|
|
38
|
+
version: '版本',
|
|
39
|
+
sun: '日', mon: '一', tue: '二', wed: '三', thu: '四', fri: '五', sat: '六'
|
|
40
|
+
}`;
|
|
41
|
+
|
|
42
|
+
const zhNew = ` zh: {
|
|
43
|
+
title: 'opencode-statboard v{version} TUI',
|
|
44
|
+
keys: '[1]總覽 [2]專案 [3]模型 [4]趨勢 [5]熱力 [W]網頁 [R]重整 [Q]離開 [L]語言',
|
|
45
|
+
footer: '上次更新: {time} | 視圖: {view} | W:網頁 R:重整 Q:離開',
|
|
46
|
+
loading: '載入資料中...',
|
|
47
|
+
error: '錯誤: {error}',
|
|
48
|
+
overview: '總覽',
|
|
49
|
+
projects: '專案',
|
|
50
|
+
models: '模型',
|
|
51
|
+
trend: '趨勢 (90 天)',
|
|
52
|
+
heatmap: '熱力圖',
|
|
53
|
+
noData: '無資料',
|
|
54
|
+
sessions: '會話',
|
|
55
|
+
main: '主',
|
|
56
|
+
total: '總計',
|
|
57
|
+
projectsLabel: '專案數',
|
|
58
|
+
days: '天數',
|
|
59
|
+
messages: '訊息',
|
|
60
|
+
tokens: 'Token',
|
|
61
|
+
input: '輸入',
|
|
62
|
+
output: '輸出',
|
|
63
|
+
reasoning: '推理',
|
|
64
|
+
cacheRead: '快取讀取',
|
|
65
|
+
cacheWrite: '快取寫入',
|
|
66
|
+
total: '總計',
|
|
67
|
+
cost: '成本',
|
|
68
|
+
marketValue: '市場價值',
|
|
69
|
+
saved: '節省',
|
|
70
|
+
avgCostDay: '日均成本',
|
|
71
|
+
avgTokensDay: '日均Token',
|
|
72
|
+
projectHeader: '{專案:<45} {會話:>10} {Token:>18} {成本:>14}',
|
|
73
|
+
modelHeader: '{模型:<40} {供應商:<14} {Token:>18} {成本:>12} {速度:>10}',
|
|
74
|
+
unknown: '未知',
|
|
75
|
+
today: '今天',
|
|
76
|
+
version: '版本',
|
|
77
|
+
sun: '日', mon: '一', tue: '二', wed: '三', thu: '四', fri: '五', sat: '六',
|
|
78
|
+
day: '日', week: '周', month: '月', quarter: '季', all: '全',
|
|
79
|
+
range: '範圍'
|
|
80
|
+
}`;
|
|
81
|
+
|
|
82
|
+
const enOld = ` en: {
|
|
83
|
+
title: 'opencode-statboard v{version} TUI',
|
|
84
|
+
keys: '[1]Overview [2]Projects [3]Models [4]Trend [5]Heatmap [W]Web [R]Refresh [Q]Quit',
|
|
85
|
+
footer: 'Last update: {time} | View: {view} | W:Web R:Refresh Q:Quit',
|
|
86
|
+
loading: 'Loading data...',
|
|
87
|
+
error: 'Error: {error}',
|
|
88
|
+
overview: 'OVERVIEW',
|
|
89
|
+
projects: 'PROJECTS',
|
|
90
|
+
models: 'MODELS',
|
|
91
|
+
trend: 'TREND (90 days)',
|
|
92
|
+
heatmap: 'HEATMAP',
|
|
93
|
+
noData: 'No data',
|
|
94
|
+
sessions: 'Sessions',
|
|
95
|
+
main: 'main',
|
|
96
|
+
total: 'total',
|
|
97
|
+
projectsLabel: 'Projects',
|
|
98
|
+
days: 'Days',
|
|
99
|
+
messages: 'Messages',
|
|
100
|
+
tokens: 'Tokens',
|
|
101
|
+
input: 'Input',
|
|
102
|
+
output: 'Output',
|
|
103
|
+
reasoning: 'Reasoning',
|
|
104
|
+
cacheRead: 'Cache Read',
|
|
105
|
+
cacheWrite: 'Cache Write',
|
|
106
|
+
total: 'Total',
|
|
107
|
+
cost: 'Cost',
|
|
108
|
+
marketValue: 'Market Value',
|
|
109
|
+
saved: 'Saved',
|
|
110
|
+
avgCostDay: 'Avg Cost/Day',
|
|
111
|
+
avgTokensDay: 'Avg Tokens/Day',
|
|
112
|
+
projectHeader: '{Project:<45} {Sessions:>10} {Tokens:>18} {Cost:>14}',
|
|
113
|
+
modelHeader: '{Model:<40} {Provider:<14} {Tokens:>18} {Cost:>12} {Speed:>10}',
|
|
114
|
+
unknown: 'unknown',
|
|
115
|
+
today: 'Today',
|
|
116
|
+
version: 'Version'
|
|
117
|
+
}`;
|
|
118
|
+
|
|
119
|
+
const enNew = ` en: {
|
|
120
|
+
title: 'opencode-statboard v{version} TUI',
|
|
121
|
+
keys: '[1]Overview [2]Projects [3]Models [4]Trend [5]Heatmap [W]Web [R]Refresh [Q]Quit [L]Lang',
|
|
122
|
+
footer: 'Last update: {time} | View: {view} | W:Web R:Refresh Q:Quit',
|
|
123
|
+
loading: 'Loading data...',
|
|
124
|
+
error: 'Error: {error}',
|
|
125
|
+
overview: 'OVERVIEW',
|
|
126
|
+
projects: 'PROJECTS',
|
|
127
|
+
models: 'MODELS',
|
|
128
|
+
trend: 'TREND (90 days)',
|
|
129
|
+
heatmap: 'HEATMAP',
|
|
130
|
+
noData: 'No data',
|
|
131
|
+
sessions: 'Sessions',
|
|
132
|
+
main: 'main',
|
|
133
|
+
total: 'total',
|
|
134
|
+
projectsLabel: 'Projects',
|
|
135
|
+
days: 'Days',
|
|
136
|
+
messages: 'Messages',
|
|
137
|
+
tokens: 'Tokens',
|
|
138
|
+
input: 'Input',
|
|
139
|
+
output: 'Output',
|
|
140
|
+
reasoning: 'Reasoning',
|
|
141
|
+
cacheRead: 'Cache Read',
|
|
142
|
+
cacheWrite: 'Cache Write',
|
|
143
|
+
total: 'Total',
|
|
144
|
+
cost: 'Cost',
|
|
145
|
+
marketValue: 'Market Value',
|
|
146
|
+
saved: 'Saved',
|
|
147
|
+
avgCostDay: 'Avg Cost/Day',
|
|
148
|
+
avgTokensDay: 'Avg Tokens/Day',
|
|
149
|
+
projectHeader: '{Project:<45} {Sessions:>10} {Tokens:>18} {Cost:>14}',
|
|
150
|
+
modelHeader: '{Model:<40} {Provider:<14} {Tokens:>18} {Cost:>12} {Speed:>10}',
|
|
151
|
+
unknown: 'unknown',
|
|
152
|
+
today: 'Today',
|
|
153
|
+
version: 'Version',
|
|
154
|
+
day: 'Day', week: 'Week', month: 'Month', quarter: 'Quarter', all: 'All',
|
|
155
|
+
range: 'Range'
|
|
156
|
+
}`;
|
|
157
|
+
|
|
158
|
+
let newContent = c.replace(zhOld, zhNew).replace(enOld, enNew);
|
|
159
|
+
|
|
160
|
+
fs.writeFileSync('tui-dashboard.js', newContent);
|
|
161
|
+
console.log('Done');
|
package/package.json
CHANGED
package/test-open.js
ADDED
package/tui-dashboard.js
CHANGED
|
@@ -14,7 +14,7 @@ const pkg = require('./package.json');
|
|
|
14
14
|
const I18N = {
|
|
15
15
|
en: {
|
|
16
16
|
title: 'opencode-statboard v{version} TUI',
|
|
17
|
-
keys: '[1]Overview [2]Projects [3]Models [4]Trend [5]Heatmap [W]Web [R]Refresh [Q]Quit',
|
|
17
|
+
keys: '[1]Overview [2]Projects [3]Models [4]Trend [5]Heatmap [W]Web [R]Refresh [Q]Quit [L]Lang',
|
|
18
18
|
footer: 'Last update: {time} | View: {view} | W:Web R:Refresh Q:Quit',
|
|
19
19
|
loading: 'Loading data...',
|
|
20
20
|
error: 'Error: {error}',
|
|
@@ -46,7 +46,9 @@ const I18N = {
|
|
|
46
46
|
modelHeader: '{Model:<40} {Provider:<14} {Tokens:>18} {Cost:>12} {Speed:>10}',
|
|
47
47
|
unknown: 'unknown',
|
|
48
48
|
today: 'Today',
|
|
49
|
-
version: 'Version'
|
|
49
|
+
version: 'Version',
|
|
50
|
+
day: 'Day', week: 'Week', month: 'Month', quarter: 'Quarter', all: 'All',
|
|
51
|
+
range: 'Range'
|
|
50
52
|
},
|
|
51
53
|
zh: {
|
|
52
54
|
title: 'opencode-statboard v{version} TUI',
|
|
@@ -83,7 +85,9 @@ const I18N = {
|
|
|
83
85
|
unknown: '未知',
|
|
84
86
|
today: '今天',
|
|
85
87
|
version: '版本',
|
|
86
|
-
sun: '日', mon: '一', tue: '二', wed: '三', thu: '四', fri: '五', sat: '六'
|
|
88
|
+
sun: '日', mon: '一', tue: '二', wed: '三', thu: '四', fri: '五', sat: '六',
|
|
89
|
+
day: '日', week: '周', month: '月', quarter: '季', all: '全',
|
|
90
|
+
range: '範圍'
|
|
87
91
|
},
|
|
88
92
|
en: {
|
|
89
93
|
title: 'opencode-statboard v{version} TUI',
|
|
@@ -145,6 +149,14 @@ class TUIServer {
|
|
|
145
149
|
this.lastUpdate = null;
|
|
146
150
|
this._earlyLogs = [];
|
|
147
151
|
this.lang = 'zh'; // Default to Chinese
|
|
152
|
+
this.timeRange = 7; // Default to 7 days (week)
|
|
153
|
+
this.timeRanges = [
|
|
154
|
+
{ key: 'd', days: 1, label: { en: 'Day', zh: '日' } },
|
|
155
|
+
{ key: 'w', days: 7, label: { en: 'Week', zh: '周' } },
|
|
156
|
+
{ key: 'm', days: 30, label: { en: 'Month', zh: '月' } },
|
|
157
|
+
{ key: 'q', days: 90, label: { en: 'Quarter', zh: '季' } },
|
|
158
|
+
{ key: 'a', days: -1, label: { en: 'All', zh: '全' } }
|
|
159
|
+
];
|
|
148
160
|
}
|
|
149
161
|
|
|
150
162
|
async start() {
|
|
@@ -216,11 +228,13 @@ class TUIServer {
|
|
|
216
228
|
|
|
217
229
|
async pollData() {
|
|
218
230
|
try {
|
|
231
|
+
const days = this.timeRange;
|
|
232
|
+
const trendDays = days === -1 ? 90 : days; // trend uses 90 for "all"
|
|
219
233
|
const [stats, report, models, trend] = await Promise.all([
|
|
220
|
-
this.fetchData('/api/stats?days=
|
|
221
|
-
this.fetchData('/api/report?days=
|
|
222
|
-
this.fetchData('/api/stats?days=
|
|
223
|
-
this.fetchData('/api/stats?days=
|
|
234
|
+
this.fetchData('/api/stats?days=' + days),
|
|
235
|
+
this.fetchData('/api/report?days=' + days),
|
|
236
|
+
this.fetchData('/api/stats?days=' + days).then(r => r.models || []),
|
|
237
|
+
this.fetchData('/api/stats?days=' + trendDays)
|
|
224
238
|
]);
|
|
225
239
|
|
|
226
240
|
// Parse stats response
|
|
@@ -317,6 +331,11 @@ class TUIServer {
|
|
|
317
331
|
this.screen.key(['w'], () => this.openWeb());
|
|
318
332
|
this.screen.key(['l'], () => this.toggleLang());
|
|
319
333
|
|
|
334
|
+
// Time range keys
|
|
335
|
+
this.timeRanges.forEach(tr => {
|
|
336
|
+
this.screen.key([tr.key], () => this.setTimeRange(tr.days));
|
|
337
|
+
});
|
|
338
|
+
|
|
320
339
|
this.createLayout();
|
|
321
340
|
this.render();
|
|
322
341
|
}
|
|
@@ -327,6 +346,18 @@ class TUIServer {
|
|
|
327
346
|
this.render();
|
|
328
347
|
}
|
|
329
348
|
|
|
349
|
+
setTimeRange(days) {
|
|
350
|
+
this.timeRange = days;
|
|
351
|
+
this.pollData();
|
|
352
|
+
this.createLayout();
|
|
353
|
+
this.render();
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
getTimeRangeLabel() {
|
|
357
|
+
const tr = this.timeRanges.find(r => r.days === this.timeRange);
|
|
358
|
+
return tr ? tr.label[this.lang] : String(this.timeRange);
|
|
359
|
+
}
|
|
360
|
+
|
|
330
361
|
t(key) {
|
|
331
362
|
return I18N[this.lang][key] || key;
|
|
332
363
|
}
|
|
@@ -347,7 +378,7 @@ class TUIServer {
|
|
|
347
378
|
tags: true,
|
|
348
379
|
border: { type: 'line' },
|
|
349
380
|
style: { border: { fg: 'cyan' } },
|
|
350
|
-
content: '{center}{bold}' + t('title').replace('{version}', pkg.version) + '{/bold} | ' + t('keys') + ' [L]Lang{/center}'
|
|
381
|
+
content: '{center}{bold}' + t('title').replace('{version}', pkg.version) + '{/bold} | ' + t('keys') + ' [L]Lang | ' + t('range') + ': ' + this.getTimeRangeLabel() + '{/center}'
|
|
351
382
|
});
|
|
352
383
|
|
|
353
384
|
this.layout.main = blessed.box({
|
|
@@ -542,7 +573,7 @@ class TUIServer {
|
|
|
542
573
|
|
|
543
574
|
for (const m of models.slice(0, 30)) {
|
|
544
575
|
const name = m.name.length > 38 ? m.name.slice(0, 35) + '...' : m.name;
|
|
545
|
-
const provider = (m.provider || 'unknown').slice(0, 12);
|
|
576
|
+
const provider = (m.provider || (m.name.includes('/') ? m.name.split('/')[0] : 'unknown')).slice(0, 12);
|
|
546
577
|
const tokens = this.formatNumber(m.tokens?.total || m.tokens || 0);
|
|
547
578
|
const cost = this.formatCost(m.cost || 0);
|
|
548
579
|
const speed = m.speed ? m.speed.toFixed(1) + ' tok/s' : '\u2014';
|
|
@@ -573,7 +604,7 @@ class TUIServer {
|
|
|
573
604
|
|
|
574
605
|
const height = this.getContentHeight() - 4;
|
|
575
606
|
const width = this.getContentWidth();
|
|
576
|
-
const chartHeight = Math.max(1, Math.floor(height /
|
|
607
|
+
const chartHeight = Math.max(1, Math.floor(height / 5) - 2);
|
|
577
608
|
|
|
578
609
|
// Helper: render one chart with its own max
|
|
579
610
|
const renderChart = (data, label, color, maxVal) => {
|
|
@@ -598,13 +629,17 @@ class TUIServer {
|
|
|
598
629
|
|
|
599
630
|
const maxIn = Math.max(...input, 1);
|
|
600
631
|
const maxOut = Math.max(...output, 1);
|
|
632
|
+
const maxCache = Math.max(...cache, 1);
|
|
633
|
+
const maxTotal = Math.max(...labels.map((_, i) => (input[i] || 0) + (output[i] || 0) + (reasoning[i] || 0) + (cache[i] || 0)), 1);
|
|
601
634
|
const maxCost = Math.max(...cost, 1);
|
|
602
635
|
|
|
603
636
|
let out = '{center}{bold}\u2501\u2501\u2501 ' + t('trend') + ' \u2501\u2501\u2501{/bold}{/center}\n\n';
|
|
604
637
|
|
|
605
638
|
out += renderChart(input, t('input') + ' (cyan)', 'cyan', maxIn) + '\n';
|
|
606
639
|
out += renderChart(output, t('output') + ' (green)', 'green', maxOut) + '\n';
|
|
607
|
-
out += renderChart(
|
|
640
|
+
out += renderChart(cache, t('cacheRead') + ' (yellow)', 'yellow', maxCache) + '\n';
|
|
641
|
+
out += renderChart(labels.map((_, i) => (input[i] || 0) + (output[i] || 0) + (reasoning[i] || 0) + (cache[i] || 0)), t('total') + ' (magenta)', 'magenta', maxTotal) + '\n';
|
|
642
|
+
out += renderChart(cost, t('cost') + ' (red)', 'red', maxCost) + '\n';
|
|
608
643
|
|
|
609
644
|
// X-axis: show first date, middle date, last date
|
|
610
645
|
let xAxis = '';
|
|
@@ -625,7 +660,8 @@ class TUIServer {
|
|
|
625
660
|
out += '\n{gray}Range: ' + firstDate + ' \u2192 ' + lastDate + ' (' + labels.length + ' days){/gray}\n';
|
|
626
661
|
|
|
627
662
|
const lastIdx = labels.length - 1;
|
|
628
|
-
|
|
663
|
+
const totalTokens = (input[lastIdx] || 0) + (output[lastIdx] || 0) + (reasoning[lastIdx] || 0) + (cache[lastIdx] || 0);
|
|
664
|
+
out += '\n{bold}' + t('today') + ':{/bold} Input: ' + this.formatNumber(input[lastIdx] || 0) + ' | Output: ' + this.formatNumber(output[lastIdx] || 0) + ' | Cache: ' + this.formatNumber(cache[lastIdx] || 0) + ' | Total: ' + this.formatNumber(totalTokens) + ' | Cost: ' + this.formatCost(cost[lastIdx] || 0);
|
|
629
665
|
|
|
630
666
|
return out;
|
|
631
667
|
}
|