opencode-statboard 2.3.1 → 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/.github/workflows/publish.yml +1 -1
- package/AGENTS.md +4 -2
- package/package.json +1 -1
- package/pricing.js +67 -33
- package/public/index.html +673 -456
- package/server.js +254 -108
package/public/index.html
CHANGED
|
@@ -8,14 +8,15 @@
|
|
|
8
8
|
:root {
|
|
9
9
|
--bg: #0d1117; --panel: #161b22; --border: #30363d; --text: #e6edf3; --muted: #8b949e;
|
|
10
10
|
--in: #58a6ff; --out: #3fb950; --cache: #d29922; --cost: #f778ba; --tool: #a371f7;
|
|
11
|
+
--warn: #e3b341; --dim: #6e7681;
|
|
11
12
|
}
|
|
12
13
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
13
|
-
body { background: var(--bg); color: var(--text); font-family: "Segoe UI", "Microsoft JhengHei", sans-serif; padding: 24px; }
|
|
14
|
-
header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom:
|
|
14
|
+
body { background: var(--bg); color: var(--text); font-family: "Segoe UI", "Microsoft JhengHei", sans-serif; padding: 24px; max-width: 1560px; margin: 0 auto; }
|
|
15
|
+
header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
|
|
15
16
|
h1 { font-size: 20px; font-weight: 600; }
|
|
16
17
|
h1 .dot { color: #3fb950; }
|
|
17
|
-
.status { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
|
|
18
|
-
.pill { padding: 4px 12px; border-radius: 999px; font-size: 12px; border: 1px solid var(--border); cursor: pointer; user-select: none; }
|
|
18
|
+
.status { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
|
|
19
|
+
.pill { padding: 4px 12px; border-radius: 999px; font-size: 12px; border: 1px solid var(--border); cursor: pointer; user-select: none; white-space: nowrap; }
|
|
19
20
|
.pill.ok { color: #3fb950; border-color: #238636; background: rgba(63,185,80,.08); }
|
|
20
21
|
.pill.err { color: #f85149; border-color: #da3633; background: rgba(248,81,73,.08); }
|
|
21
22
|
.pill.lang { color: var(--text); border-color: var(--border); background: rgba(139,148,158,.08); }
|
|
@@ -23,145 +24,186 @@
|
|
|
23
24
|
.pill.backup { color: var(--cache); border-color: var(--cache); background: rgba(210,153,34,.08); }
|
|
24
25
|
.pill.backup:hover { background: rgba(210,153,34,.18); }
|
|
25
26
|
.pill.backup.busy { opacity: .6; pointer-events: none; }
|
|
26
|
-
.
|
|
27
|
-
|
|
27
|
+
.version { font-size: 11px; color: var(--muted); background: var(--panel); border: 1px solid var(--border); padding: 2px 8px; border-radius: 4px; }
|
|
28
|
+
|
|
29
|
+
/* ---- caveat line ---- */
|
|
30
|
+
.caveat { font-size: 11px; color: var(--dim); line-height: 1.6; margin-bottom: 14px; letter-spacing: .1px; }
|
|
31
|
+
|
|
32
|
+
/* ---- single global scope bar ---- */
|
|
33
|
+
.scopebar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; margin-bottom: 18px; position: sticky; top: 0; z-index: 20; box-shadow: 0 6px 20px rgba(0,0,0,.35); }
|
|
34
|
+
.scopebar .sb-label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; }
|
|
35
|
+
.range-btns { display: flex; gap: 4px; flex-wrap: wrap; }
|
|
36
|
+
.range-btns .pill.active { color: var(--text); border-color: #58a6ff; background: rgba(88,166,255,.12); font-weight: 600; }
|
|
28
37
|
.range-btns .pill:not(.active) { color: var(--muted); border-color: var(--border); background: transparent; }
|
|
29
38
|
.range-btns .pill:not(.active):hover { background: rgba(139,148,158,.08); }
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
.scopebar .sb-now { font-size: 12px; color: var(--text); margin-left: auto; font-weight: 600; }
|
|
40
|
+
|
|
41
|
+
h2 { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 14px; }
|
|
42
|
+
|
|
43
|
+
/* ---- headline cards: the dominant tier ---- */
|
|
44
|
+
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
|
|
45
|
+
.card { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
|
|
46
|
+
.card.hero { border-color: #2d3748; box-shadow: inset 0 1px 0 rgba(255,255,255,.03); }
|
|
47
|
+
.card .v { font-size: 26px; font-weight: 700; margin-top: 4px; line-height: 1.15; letter-spacing: -.5px; }
|
|
48
|
+
.card.hero .v { font-size: 34px; }
|
|
35
49
|
.card .l { font-size: 12px; color: var(--muted); }
|
|
36
|
-
.
|
|
37
|
-
.
|
|
38
|
-
.
|
|
39
|
-
.
|
|
40
|
-
.
|
|
50
|
+
.card .subs { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
|
|
51
|
+
.card .subs b { color: var(--text); font-weight: 600; }
|
|
52
|
+
.subs .k-in { color: var(--in); } .subs .k-out { color: var(--out); }
|
|
53
|
+
.subs .k-reasoning { color: var(--tool); } .subs .k-cache { color: var(--cache); }
|
|
54
|
+
.subs .warn { color: var(--warn); cursor: pointer; border-bottom: 1px dashed var(--warn); }
|
|
55
|
+
.subs .warn:hover { color: #f0c674; }
|
|
56
|
+
.foot-note { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; margin-top: 14px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
|
|
57
|
+
|
|
58
|
+
/* ---- breakdown / pricing tables ---- */
|
|
41
59
|
.scrollx { overflow-x: auto; }
|
|
42
|
-
.scrollx table { min-width:
|
|
43
|
-
td.clip { max-width:
|
|
44
|
-
.rep-head { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
|
|
45
|
-
.rep-hint { color: var(--muted); font-size: 12px; font-weight: 400; }
|
|
46
|
-
.rep-pre { font-family: monospace; font-size: 13px; line-height: 1.6; white-space: pre; overflow-x: auto; color: var(--text); margin: 0; }
|
|
60
|
+
.scrollx table { min-width: 1080px; }
|
|
61
|
+
td.clip { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
47
62
|
.track { background: #21262d; border-radius: 4px; height: 12px; overflow: hidden; }
|
|
48
|
-
.
|
|
63
|
+
.track.share { min-width: 90px; height: 10px; }
|
|
49
64
|
.stack { display: flex; height: 100%; }
|
|
50
65
|
.stack > div { height: 100%; }
|
|
51
|
-
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-bottom: 12px; flex-wrap: wrap; }
|
|
52
|
-
.legend span { display: flex; align-items: center; gap: 6px; }
|
|
53
|
-
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
|
|
54
66
|
table { width: 100%; border-collapse: collapse; font-size: 13px; }
|
|
55
|
-
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
|
|
67
|
+
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; white-space: nowrap; }
|
|
56
68
|
th:first-child, td:first-child { text-align: left; }
|
|
57
69
|
th { color: var(--muted); font-weight: 500; font-size: 12px; }
|
|
70
|
+
tbody tr:hover td { background: rgba(139,148,158,.06); }
|
|
71
|
+
td.bd-name { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
|
|
72
|
+
td.na { color: var(--dim); }
|
|
73
|
+
|
|
74
|
+
.rep-hint { color: var(--muted); font-size: 12px; font-weight: 400; }
|
|
75
|
+
.rep-pre { font-family: monospace; font-size: 12.5px; line-height: 1.6; white-space: pre; overflow-x: auto; color: var(--text); margin: 0; }
|
|
76
|
+
|
|
77
|
+
/* ---- trend ---- */
|
|
58
78
|
.chart { position: relative; display: flex; align-items: flex-end; gap: 2px; height: 200px; padding-top: 10px; }
|
|
59
79
|
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
|
|
60
80
|
.chart .bars { display: flex; gap: 2px; align-items: flex-end; justify-content: center; height: 170px; width: 100%; }
|
|
61
|
-
.chart .bars > div { border-radius: 2px 2px 0 0; min-width: 4px; transition: height .4s ease; }
|
|
62
|
-
.chart .x { font-size: 10px; color: var(--muted); line-height: 1; }
|
|
63
|
-
.chart .tip { font-size: 10px; color: var(--muted); line-height: 1.2; text-align: center; }
|
|
64
81
|
.trend-x { display: flex; height: 16px; margin-top: 4px; }
|
|
65
82
|
.trend-x span { flex: 1; text-align: center; font-size: 10px; color: var(--muted); line-height: 16px; overflow: hidden; text-overflow: clip; white-space: nowrap; }
|
|
66
|
-
.
|
|
67
|
-
|
|
83
|
+
.trend-wrap { display: flex; gap: 24px; flex-wrap: wrap; }
|
|
84
|
+
.trend-wrap > div { flex: 1; min-width: 300px; }
|
|
85
|
+
.trend-wrap #costSection { min-width: 240px; }
|
|
86
|
+
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-bottom: 12px; flex-wrap: wrap; }
|
|
87
|
+
.legend span { display: flex; align-items: center; gap: 6px; }
|
|
88
|
+
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
|
|
89
|
+
|
|
68
90
|
.error-banner { display: none; background: rgba(248,81,73,.1); border: 1px solid #da3633; color: #f85149; padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
|
|
69
91
|
.error-banner.show { display: block; }
|
|
92
|
+
|
|
93
|
+
/* ---- collapsible sections: primary vs secondary tier ---- */
|
|
70
94
|
details.tool-section { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
|
|
71
|
-
details.tool-section summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
|
|
95
|
+
details.tool-section summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; justify-content: space-between; }
|
|
72
96
|
details.tool-section summary::-webkit-details-marker { display: none; }
|
|
73
|
-
details.tool-section summary::before { content: '
|
|
97
|
+
details.tool-section summary::before { content: '\25B8'; font-size: 12px; color: var(--muted); transition: transform .2s; flex: none; }
|
|
74
98
|
details.tool-section[open] summary::before { transform: rotate(90deg); }
|
|
75
99
|
details.tool-section summary h2 { margin: 0; }
|
|
76
|
-
.
|
|
77
|
-
|
|
78
|
-
.
|
|
79
|
-
.
|
|
100
|
+
details.tool-section.secondary { background: transparent; padding: 12px 18px; }
|
|
101
|
+
details.tool-section.secondary[open] { padding: 18px; }
|
|
102
|
+
details.tool-section.secondary summary h2 { font-size: 11px; }
|
|
103
|
+
.scope-tag { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; font-weight: 500; white-space: nowrap; flex: none; margin-left: 12px; font-variant-numeric: tabular-nums; }
|
|
104
|
+
|
|
105
|
+
.subtabs { display: flex; gap: 4px; margin: 0 0 14px 20px; }
|
|
106
|
+
.subtabs .pill { color: var(--muted); background: transparent; }
|
|
107
|
+
.subtabs .pill.active { color: var(--text); border-color: #58a6ff; background: rgba(88,166,255,.12); font-weight: 600; }
|
|
108
|
+
|
|
109
|
+
.badge { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
|
|
110
|
+
.badge.exact { color: #3fb950; border-color: rgba(63,185,80,.4); }
|
|
111
|
+
.badge.sibling { color: #58a6ff; border-color: rgba(88,166,255,.4); }
|
|
112
|
+
.badge.proxy { color: #d29922; border-color: rgba(210,153,34,.4); }
|
|
113
|
+
.badge.partial { color: #f778ba; border-color: rgba(247,120,186,.4); }
|
|
114
|
+
.badge.unpriced { color: #f85149; border-color: rgba(248,81,73,.4); }
|
|
115
|
+
.empty { color: var(--muted); font-size: 13px; padding: 12px 0; }
|
|
116
|
+
|
|
80
117
|
.trend-bar { position: absolute; bottom: 0; border-radius: 2px 2px 0 0; transition: height .4s ease; }
|
|
81
118
|
.trend-bar-cache { left: 0; right: 0; opacity: .2; }
|
|
82
|
-
.version { font-size: 11px; color: var(--muted); background: var(--panel); border: 1px solid var(--border); padding: 2px 8px; border-radius: 4px; }
|
|
83
119
|
.trend-bar-input { left: 25%; width: 22%; z-index: 1; }
|
|
84
120
|
.trend-bar-output { left: 53%; width: 22%; z-index: 1; }
|
|
85
121
|
.trend-bar-reasoning { left: 76%; width: 22%; z-index: 1; }
|
|
122
|
+
@media (max-width: 640px) { body { padding: 14px; } .card.hero .v { font-size: 26px; } }
|
|
86
123
|
</style>
|
|
87
124
|
</head>
|
|
88
125
|
<body>
|
|
89
126
|
<header>
|
|
90
|
-
<h1><span class="dot"
|
|
127
|
+
<h1><span class="dot">●</span> <span data-i18n="title">opencode Dashboard</span> <span class="version">v__VERSION__</span></h1>
|
|
91
128
|
<div class="status">
|
|
92
|
-
<span id="updated">Loading
|
|
129
|
+
<span id="updated">Loading…</span>
|
|
93
130
|
<span class="pill ok" id="pill" data-i18n="live">Live</span>
|
|
94
131
|
<span class="pill lang" id="langBtn" onclick="toggleLang()"></span>
|
|
95
132
|
<span class="pill backup" id="backupBtn" onclick="backupDb()" data-i18n="backup">Backup DB</span>
|
|
96
133
|
</div>
|
|
97
134
|
</header>
|
|
98
135
|
|
|
136
|
+
<div class="caveat" id="caveat"></div>
|
|
137
|
+
|
|
138
|
+
<div class="scopebar">
|
|
139
|
+
<span class="sb-label" data-i18n="scope">Scope</span>
|
|
140
|
+
<div class="range-btns" id="scopeBtns">
|
|
141
|
+
<span class="pill" data-days="-1" onclick="setScope(-1)" data-i18n="all">All time</span>
|
|
142
|
+
<span class="pill" data-days="1" onclick="setScope(1)" data-i18n="today">Today</span>
|
|
143
|
+
<span class="pill" data-days="7" onclick="setScope(7)" data-i18n="last7">7 days</span>
|
|
144
|
+
<span class="pill" data-days="30" onclick="setScope(30)" data-i18n="mtd">Month to date</span>
|
|
145
|
+
</div>
|
|
146
|
+
<span class="sb-now" id="scopeNow"></span>
|
|
147
|
+
</div>
|
|
148
|
+
|
|
99
149
|
<div class="error-banner" id="errbanner"></div>
|
|
100
150
|
|
|
101
|
-
|
|
102
|
-
|
|
151
|
+
<!-- 1. HEADLINE — follows the global scope -->
|
|
152
|
+
<details class="tool-section" open id="sec-headline">
|
|
153
|
+
<summary><h2 data-i18n="headline">HEADLINE</h2><span class="scope-tag" id="tag-headline"></span></summary>
|
|
103
154
|
<div class="cards">
|
|
104
|
-
<div class="card
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
155
|
+
<div class="card hero">
|
|
156
|
+
<div class="l" data-i18n="tokens">Tokens</div>
|
|
157
|
+
<div class="v" id="hl-tokens">—</div>
|
|
158
|
+
<div class="subs">
|
|
159
|
+
<span class="k-in"><span data-i18n="tIn">in</span> <b id="hl-in">—</b></span>
|
|
160
|
+
<span class="k-out"><span data-i18n="tOut">out</span> <b id="hl-out">—</b></span>
|
|
161
|
+
<span class="k-reasoning"><span data-i18n="tReasoning">reasoning</span> <b id="hl-reasoning">—</b></span>
|
|
162
|
+
<span class="k-cache"><span data-i18n="tCache">cache</span> <b id="hl-cache">—</b></span>
|
|
163
|
+
</div>
|
|
164
|
+
</div>
|
|
165
|
+
<div class="card hero">
|
|
166
|
+
<div class="l" data-i18n="totalCost">Total Cost</div>
|
|
167
|
+
<div class="v" id="hl-cost">—</div>
|
|
168
|
+
<div class="subs"><span data-i18n="costShare">actual paid</span></div>
|
|
169
|
+
</div>
|
|
170
|
+
<div class="card hero">
|
|
171
|
+
<div class="l" data-i18n="marketValue">Market Value</div>
|
|
172
|
+
<div class="v" id="hl-market">—</div>
|
|
173
|
+
<div class="subs">
|
|
174
|
+
<span data-i18n="atCatalog">same usage at catalog list prices</span>
|
|
175
|
+
<span id="hl-priceAsOf"></span>
|
|
176
|
+
<span class="warn" id="hl-unpriced" onclick="openPricing()"></span>
|
|
177
|
+
</div>
|
|
178
|
+
</div>
|
|
179
|
+
<div class="card hero">
|
|
180
|
+
<div class="l" data-i18n="saved">Saved</div>
|
|
181
|
+
<div class="v" id="hl-saved">—</div>
|
|
182
|
+
<div class="subs"><span id="hl-savedPct"></span></div>
|
|
183
|
+
</div>
|
|
113
184
|
</div>
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
<
|
|
117
|
-
<summary><h2 data-i18n="tokenStats">TOKEN STATISTICS</h2></summary>
|
|
118
|
-
<div class="legend">
|
|
119
|
-
<span><i class="sw" style="background:var(--in)"></i>Input</span>
|
|
120
|
-
<span><i class="sw" style="background:var(--out)"></i>Output</span>
|
|
121
|
-
<span><i class="sw" style="background:var(--tool)"></i>Reasoning</span>
|
|
122
|
-
<span><i class="sw" style="background:var(--cache)"></i>Cache Read</span>
|
|
123
|
-
<span><i class="sw" style="background:var(--cost)"></i>Cache Write</span>
|
|
185
|
+
<div class="foot-note">
|
|
186
|
+
<span id="hl-meta"></span>
|
|
187
|
+
<span id="hl-proxy"></span>
|
|
124
188
|
</div>
|
|
125
|
-
<div id="token-bars"></div>
|
|
126
|
-
</details>
|
|
127
|
-
|
|
128
|
-
<details class="tool-section" open id="sec-tools">
|
|
129
|
-
<summary><h2 data-i18n="toolUsage">TOOL USAGE</h2></summary>
|
|
130
|
-
<div id="tool-bars"></div>
|
|
131
|
-
</details>
|
|
132
|
-
|
|
133
|
-
<details class="tool-section" open id="sec-models">
|
|
134
|
-
<summary><h2 data-i18n="modelUsage">MODEL USAGE</h2></summary>
|
|
135
|
-
<table>
|
|
136
|
-
<thead>
|
|
137
|
-
<tr><th data-i18n="thModel">Model</th><th data-i18n="thMsgs">Messages</th><th>Input</th><th>Output</th><th>Cache Read</th><th data-i18n="thSpeed">Speed</th><th style="width:26%" data-i18n="thUsage">Usage</th><th data-i18n="thCost">Cost</th></tr>
|
|
138
|
-
</thead>
|
|
139
|
-
<tbody id="model-rows"></tbody>
|
|
140
|
-
</table>
|
|
141
189
|
</details>
|
|
142
190
|
|
|
191
|
+
<!-- 2. TREND — bucket count follows the scope -->
|
|
143
192
|
<details class="tool-section" open id="sec-trend">
|
|
144
|
-
<summary><
|
|
145
|
-
|
|
146
|
-
<div
|
|
147
|
-
<span class="pill active" data-days="7" onclick="setRange(7)">7D</span>
|
|
148
|
-
<span class="pill" data-days="30" onclick="setRange(30)">30D</span>
|
|
149
|
-
<span class="pill" data-days="90" onclick="setRange(90)">90D</span>
|
|
150
|
-
</div>
|
|
151
|
-
</div></summary>
|
|
152
|
-
<div style="display:flex;gap:24px;flex-wrap:wrap">
|
|
153
|
-
<div style="flex:1;min-width:300px">
|
|
193
|
+
<summary><h2 data-i18n="trend">TREND</h2><span class="scope-tag" id="tag-trend"></span></summary>
|
|
194
|
+
<div class="trend-wrap">
|
|
195
|
+
<div>
|
|
154
196
|
<div class="legend">
|
|
155
197
|
<span><i class="sw" style="background:var(--in)"></i><span data-i18n="inputDay">Input / Day</span></span>
|
|
156
198
|
<span><i class="sw" style="background:var(--out)"></i><span data-i18n="outputDay">Output / Day</span></span>
|
|
157
|
-
<span><i class="sw" style="background:var(--tool)"></i>Reasoning / Day</span>
|
|
199
|
+
<span><i class="sw" style="background:var(--tool)"></i><span data-i18n="reasoningDay">Reasoning / Day</span></span>
|
|
158
200
|
<span><i class="sw" style="background:var(--cache)"></i><span data-i18n="cacheReadDay">Cache Read / Day</span></span>
|
|
159
201
|
<span id="trendStatus" style="color:var(--cache);font-size:11px"></span>
|
|
160
202
|
</div>
|
|
161
203
|
<div class="chart" id="trendTokensChart"><div class="bars" id="trend-tokens"></div></div>
|
|
162
204
|
<div class="trend-x" id="trend-token-x"></div>
|
|
163
205
|
</div>
|
|
164
|
-
<div id="costSection"
|
|
206
|
+
<div id="costSection">
|
|
165
207
|
<div class="legend"><span><i class="sw" style="background:var(--cost)"></i><span data-i18n="costDay">Cost / Day</span></span></div>
|
|
166
208
|
<div class="chart" id="trendCostChart"><div class="bars" id="trend-cost"></div></div>
|
|
167
209
|
<div class="trend-x" id="trend-cost-x"></div>
|
|
@@ -170,105 +212,247 @@
|
|
|
170
212
|
</div>
|
|
171
213
|
</details>
|
|
172
214
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
215
|
+
<!-- 3. BREAKDOWN — one table, three sub-tabs, sorted by tokens -->
|
|
216
|
+
<details class="tool-section" open id="sec-breakdown">
|
|
217
|
+
<summary><h2 data-i18n="breakdown">BREAKDOWN</h2><span class="scope-tag" id="tag-breakdown"></span></summary>
|
|
218
|
+
<div class="subtabs" id="bdTabs">
|
|
219
|
+
<span class="pill active" data-tab="models" onclick="setTab('models')" data-i18n="tabModels">Models</span>
|
|
220
|
+
<span class="pill" data-tab="agents" onclick="setTab('agents')" data-i18n="tabAgents">Agents</span>
|
|
221
|
+
<span class="pill" data-tab="sessions" onclick="setTab('sessions')" data-i18n="tabSessions">Sessions</span>
|
|
222
|
+
</div>
|
|
223
|
+
<div class="legend">
|
|
224
|
+
<span><i class="sw" style="background:var(--in)"></i><span data-i18n="tIn">in</span></span>
|
|
225
|
+
<span><i class="sw" style="background:var(--out)"></i><span data-i18n="tOut">out</span></span>
|
|
226
|
+
<span><i class="sw" style="background:var(--tool)"></i><span data-i18n="tReasoning">reasoning</span></span>
|
|
227
|
+
<span><i class="sw" style="background:var(--cache)"></i><span data-i18n="tCache">cache</span></span>
|
|
228
|
+
<span id="bdSortNote" style="color:var(--dim)"></span>
|
|
229
|
+
</div>
|
|
230
|
+
<div class="scrollx">
|
|
231
|
+
<table>
|
|
232
|
+
<thead>
|
|
233
|
+
<tr>
|
|
234
|
+
<th id="th-name" data-i18n="thName">Name</th>
|
|
235
|
+
<th style="width:120px" data-i18n="thShare">Share</th>
|
|
236
|
+
<th id="th-count" data-i18n="thSessions">Sessions</th>
|
|
237
|
+
<th data-i18n="tIn">in</th>
|
|
238
|
+
<th data-i18n="tOut">out</th>
|
|
239
|
+
<th data-i18n="tReasoning">reasoning</th>
|
|
240
|
+
<th data-i18n="tCache">cache</th>
|
|
241
|
+
<th data-i18n="thSpeed">Speed</th>
|
|
242
|
+
<th data-i18n="thWall">Wall</th>
|
|
243
|
+
<th data-i18n="marketValue">Market</th>
|
|
244
|
+
<th data-i18n="saved">Saved</th>
|
|
245
|
+
</tr>
|
|
246
|
+
</thead>
|
|
247
|
+
<tbody id="bd-models"></tbody>
|
|
248
|
+
<tbody id="bd-agents" style="display:none"></tbody>
|
|
249
|
+
<tbody id="bd-sessions" style="display:none"></tbody>
|
|
250
|
+
</table>
|
|
251
|
+
</div>
|
|
252
|
+
<div id="bd-empty" class="empty" style="display:none"></div>
|
|
184
253
|
</details>
|
|
185
254
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
<
|
|
255
|
+
<!-- 4. TOOLS -->
|
|
256
|
+
<details class="tool-section secondary" open id="sec-tools">
|
|
257
|
+
<summary><h2 data-i18n="toolUsage">TOOLS</h2><span class="scope-tag" id="tag-tools"></span></summary>
|
|
258
|
+
<div class="bar-row" id="tool-bars"></div>
|
|
189
259
|
</details>
|
|
190
260
|
|
|
191
|
-
|
|
192
|
-
|
|
261
|
+
<!-- 5. PRICING BASIS (collapsed by default) -->
|
|
262
|
+
<details class="tool-section secondary" id="sec-pricing">
|
|
263
|
+
<summary><h2 data-i18n="pricingBasis">PRICING BASIS</h2><span class="scope-tag" id="tag-pricing"></span></summary>
|
|
193
264
|
<div class="legend">
|
|
194
|
-
<span><
|
|
195
|
-
<span><
|
|
265
|
+
<span><span class="badge exact" data-i18n="kindExact">exact</span> <span data-i18n="kindExactTip">own provider + own list price</span></span>
|
|
266
|
+
<span><span class="badge sibling" data-i18n="kindSibling">sibling</span> <span data-i18n="kindSiblingTip">same provider, -free variant stripped</span></span>
|
|
267
|
+
<span><span class="badge proxy" data-i18n="kindProxy">proxy</span> <span data-i18n="kindProxyTip">borrowed price from another provider (estimate)</span></span>
|
|
268
|
+
<span><span class="badge partial" data-i18n="kindPartial">partial</span> <span data-i18n="kindPartialTip">part priced, part not in catalog</span></span>
|
|
269
|
+
<span><span class="badge unpriced" data-i18n="kindUnpriced">unpriced</span> <span data-i18n="kindUnpricedTip">not in catalog — market/saved unknown</span></span>
|
|
196
270
|
</div>
|
|
197
|
-
<div
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
<
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
<span><i class="sw" style="background:var(--out)"></i>active</span>
|
|
271
|
+
<div class="scrollx">
|
|
272
|
+
<table>
|
|
273
|
+
<thead>
|
|
274
|
+
<tr><th data-i18n="thUsageModel">Usage model</th><th data-i18n="thPricedAs">Priced as</th><th data-i18n="thKind">Basis</th><th data-i18n="marketValue">Market</th><th data-i18n="saved">Saved</th></tr>
|
|
275
|
+
</thead>
|
|
276
|
+
<tbody id="pricing-rows"></tbody>
|
|
277
|
+
</table>
|
|
205
278
|
</div>
|
|
206
|
-
<div id="
|
|
279
|
+
<div id="pricing-empty" class="empty" style="display:none"></div>
|
|
207
280
|
</details>
|
|
208
281
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
<
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
<div id="savings-bars"></div>
|
|
282
|
+
<!-- 6. RAW TEXT (collapsed by default) -->
|
|
283
|
+
<details class="tool-section secondary" id="sec-raw">
|
|
284
|
+
<summary><h2 data-i18n="rawText">RAW TEXT</h2><span class="scope-tag" id="tag-raw"></span></summary>
|
|
285
|
+
<div class="rep-hint" style="margin-bottom:10px" data-i18n="rawHint">Plain-text statement, same numbers as the tables above.</div>
|
|
286
|
+
<pre class="rep-pre" id="rawText"></pre>
|
|
215
287
|
</details>
|
|
216
288
|
|
|
217
289
|
<script>
|
|
218
290
|
const STRINGS = {
|
|
219
291
|
en: {
|
|
220
292
|
title: 'opencode Dashboard',
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
293
|
+
scope: 'Scope', all: 'All time', today: 'Today', last7: '7 days', mtd: 'Month to date',
|
|
294
|
+
scopeSuffix: { '-1': 'All time', '1': 'Today (local)', '7': 'Last 7 days (local)', '30': 'Month to date (local)' },
|
|
295
|
+
trendScope: '{n}-day buckets · today leftmost',
|
|
296
|
+
allTimeTrend: 'All time · 90-day buckets · today leftmost',
|
|
297
|
+
toolsScope: '{scope} · tool counts are all-time',
|
|
298
|
+
headline: 'HEADLINE', trend: 'TREND', breakdown: 'BREAKDOWN', toolUsage: 'TOOLS',
|
|
299
|
+
pricingBasis: 'PRICING BASIS', rawText: 'RAW TEXT',
|
|
300
|
+
rawHint: 'Plain-text statement, same numbers as the tables above.',
|
|
301
|
+
tokens: 'Tokens', tIn: 'in', tOut: 'out', tReasoning: 'reasoning', tCache: 'cache',
|
|
302
|
+
totalCost: 'Total Cost', marketValue: 'Market Value', saved: 'Saved',
|
|
303
|
+
costShare: 'actual paid', atCatalog: 'same usage at catalog list prices',
|
|
304
|
+
savedOf: '{pct}% of market value',
|
|
305
|
+
sessionsLabel: 'Sessions', messagesLabel: 'Messages', daysLabel: 'Days',
|
|
306
|
+
avgCostDay: 'Avg cost / day', avgTokensSession: 'Avg tokens / session', medianTokensSession: 'Median tokens / session',
|
|
307
|
+
activeLabel: 'active',
|
|
308
|
+
pricesAsOf: 'prices as of {d}',
|
|
309
|
+
unpricedModels: '{n} models unpriced ({t} tokens not valued)',
|
|
310
|
+
proxyShare: '{pct}% of market value is proxy estimate',
|
|
311
|
+
caveat: 'V1+V2 merged · per-message token authority · session residual spread across the session\'s days',
|
|
312
|
+
tabModels: 'Models', tabAgents: 'Agents', tabSessions: 'Sessions',
|
|
313
|
+
thName: 'Name', thShare: 'Share', thSessions: 'Sessions', thMsgs: 'Msgs',
|
|
314
|
+
thSpeed: 'Speed', thWall: 'Wall',
|
|
315
|
+
sortNote: 'sorted by tokens (in + out + reasoning + cache) — cost is 0 for free models, so it cannot sort',
|
|
316
|
+
sessionsTop: 'top {n} sessions',
|
|
317
|
+
thUsageModel: 'Usage model', thPricedAs: 'Priced as', thKind: 'Basis',
|
|
318
|
+
kindExact: 'exact', kindSibling: 'sibling', kindProxy: 'proxy',
|
|
319
|
+
kindPartial: 'partial', kindUnpriced: 'unpriced',
|
|
320
|
+
kindExactTip: 'own provider + own list price',
|
|
321
|
+
kindSiblingTip: 'same provider, -free variant stripped',
|
|
322
|
+
kindProxyTip: 'borrowed price from another provider (estimate)',
|
|
323
|
+
kindPartialTip: 'part of the usage priced, rest not in catalog',
|
|
324
|
+
kindUnpricedTip: 'not in catalog — market/saved unknown',
|
|
325
|
+
legacyAgent: 'legacy',
|
|
326
|
+
inputDay: 'Input / Day', outputDay: 'Output / Day', reasoningDay: 'Reasoning / Day',
|
|
327
|
+
cacheReadDay: 'Cache Read / Day', costDay: 'Cost / Day',
|
|
328
|
+
noData: 'No data for this scope',
|
|
329
|
+
updating: 'updating…', generating: 'Generating trend data…', cachedAt: 'cached at',
|
|
330
|
+
allFree: 'All models free — no cost recorded in this scope',
|
|
231
331
|
live: 'Live', loading: 'Loading…', lastUpdated: 'Last updated', dataAgo: 'data generated',
|
|
232
|
-
statsFail: 'Failed to read opencode stats', connFail: 'Connection failed',
|
|
332
|
+
statsFail: 'Failed to read opencode stats', connFail: 'Connection failed', reportFail: 'Failed to read usage report',
|
|
233
333
|
langBtn: '繁中',
|
|
234
334
|
backup: 'Backup DB', backingUp: 'Backing up…', backupFail: 'Backup failed',
|
|
235
335
|
},
|
|
236
336
|
'zh-TW': {
|
|
237
337
|
title: 'opencode 用量儀表板',
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
338
|
+
scope: '範圍', all: '全期', today: '今天', last7: '近 7 天', mtd: '本月至今',
|
|
339
|
+
scopeSuffix: { '-1': '全期', '1': '今天(本地)', '7': '近 7 天(本地)', '30': '本月至今(本地)' },
|
|
340
|
+
trendScope: '{n} 天分桶 · 今天在最左',
|
|
341
|
+
allTimeTrend: '全期 · 90 天分桶 · 今天在最左',
|
|
342
|
+
toolsScope: '{scope} · 工具統計一律為全期',
|
|
343
|
+
headline: '重點指標', trend: '趨勢', breakdown: '明細', toolUsage: '工具',
|
|
344
|
+
pricingBasis: '定價依據', rawText: '原始文字',
|
|
345
|
+
rawHint: '純文字報表,數字與上方表格一致。',
|
|
346
|
+
tokens: 'Tokens', tIn: '輸入', tOut: '輸出', tReasoning: '推理', tCache: '快取',
|
|
347
|
+
totalCost: '總費用', marketValue: '市價', saved: '已節省',
|
|
348
|
+
costShare: '實際付費', atCatalog: '同等用量依牌價換算',
|
|
349
|
+
savedOf: '占市價 {pct}%',
|
|
350
|
+
sessionsLabel: '工作階段', messagesLabel: '訊息數', daysLabel: '天數',
|
|
351
|
+
avgCostDay: '平均費用 / 天', avgTokensSession: '平均 tokens / 場', medianTokensSession: '中位數 tokens / 場',
|
|
352
|
+
activeLabel: '實際執行',
|
|
353
|
+
pricesAsOf: '牌價日期 {d}',
|
|
354
|
+
unpricedModels: '{n} 個模型查無牌價({t} tokens 未計價)',
|
|
355
|
+
proxyShare: '市價中有 {pct}% 屬借價代估',
|
|
356
|
+
caveat: 'V1+V2 資料合併 · 以單則訊息 token 為準 · 場次餘額依該場涵蓋的天數分攤',
|
|
357
|
+
tabModels: '模型', tabAgents: '代理', tabSessions: '場次',
|
|
358
|
+
thName: '名稱', thShare: '占比', thSessions: '場次', thMsgs: '訊息',
|
|
359
|
+
thSpeed: '速度', thWall: '耗時',
|
|
360
|
+
sortNote: '依 tokens(輸入+輸出+推理+快取)排序 —— 免費模型費用皆為 0,無法作為排序依據',
|
|
361
|
+
sessionsTop: '前 {n} 場',
|
|
362
|
+
thUsageModel: '使用模型', thPricedAs: '採用牌價', thKind: '依據',
|
|
363
|
+
kindExact: 'exact', kindSibling: 'sibling', kindProxy: 'proxy',
|
|
364
|
+
kindPartial: 'partial', kindUnpriced: 'unpriced',
|
|
365
|
+
kindExactTip: '同供應商同名牌價',
|
|
366
|
+
kindSiblingTip: '同供應商,去掉 -free 變體',
|
|
367
|
+
kindProxyTip: '借用其他供應商牌價(代估)',
|
|
368
|
+
kindPartialTip: '部分用量有牌價,其餘查無',
|
|
369
|
+
kindUnpricedTip: '目錄查無 — 市價/節省未知',
|
|
370
|
+
legacyAgent: '舊版',
|
|
371
|
+
inputDay: '輸入 / 天', outputDay: '輸出 / 天', reasoningDay: '推理 / 天',
|
|
372
|
+
cacheReadDay: '快取讀取 / 天', costDay: '費用 / 天',
|
|
373
|
+
noData: '此範圍沒有資料',
|
|
374
|
+
updating: '更新中…', generating: '趨勢資料產生中…', cachedAt: '快取於',
|
|
375
|
+
allFree: '此範圍全部使用免費模型,無費用紀錄',
|
|
248
376
|
live: '即時更新', loading: '載入中…', lastUpdated: '更新於', dataAgo: '數據產生於',
|
|
249
|
-
statsFail: 'opencode stats 讀取失敗', connFail: '連線失敗',
|
|
377
|
+
statsFail: 'opencode stats 讀取失敗', connFail: '連線失敗', reportFail: '用量報告讀取失敗',
|
|
250
378
|
langBtn: 'EN',
|
|
251
379
|
backup: '備份 DB', backingUp: '備份中…', backupFail: '備份失敗',
|
|
252
380
|
}
|
|
253
381
|
};
|
|
254
382
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
383
|
+
const $ = (id) => document.getElementById(id);
|
|
384
|
+
let lang = localStorage.getItem('lang') || (navigator.language.startsWith('zh') ? 'zh-TW' : 'en');
|
|
258
385
|
const t = (key) => (STRINGS[lang] || STRINGS.en)[key] || key;
|
|
386
|
+
const fmtLang = (key, vars) => Object.keys(vars || {}).reduce((s, k) => s.split('{' + k + '}').join(vars[k]), t(key));
|
|
387
|
+
|
|
388
|
+
// ---- scope model -------------------------------------------------------
|
|
389
|
+
// One global scope drives the whole page: -1 all time, 1 today,
|
|
390
|
+
// 7 last 7 local days, 30 month to date. No section owns a range button.
|
|
391
|
+
const SCOPE_DAYS = [-1, 1, 7, 30];
|
|
392
|
+
const ALL_TIME_TREND_DAYS = 90;
|
|
393
|
+
const SESSION_TOP_N = 20;
|
|
394
|
+
const savedScope = parseInt(localStorage.getItem('scopeDays') || '', 10);
|
|
395
|
+
let scopeDays = SCOPE_DAYS.indexOf(savedScope) >= 0 ? savedScope : 7;
|
|
396
|
+
const savedTab = localStorage.getItem('bdTab');
|
|
397
|
+
let bdTab = ['models', 'agents', 'sessions'].indexOf(savedTab || '') >= 0 ? savedTab : 'models';
|
|
398
|
+
|
|
399
|
+
const scopeLabel = (days) => (STRINGS[lang] || STRINGS.en).scopeSuffix[String(days)] || String(days);
|
|
400
|
+
const trendDays = (days) => (days === -1 ? ALL_TIME_TREND_DAYS : days);
|
|
401
|
+
|
|
402
|
+
// ---- formatting --------------------------------------------------------
|
|
403
|
+
const fmt = (n) => {
|
|
404
|
+
if (n == null || isNaN(n)) return '—';
|
|
405
|
+
if (n >= 1e9) return (n / 1e9).toFixed(2) + 'B';
|
|
406
|
+
if (n >= 1e6) return (n / 1e6).toFixed(1) + 'M';
|
|
407
|
+
if (n >= 1e3) return (n / 1e3).toFixed(1) + 'K';
|
|
408
|
+
return String(Math.round(n));
|
|
409
|
+
};
|
|
410
|
+
const fmtCost = (n) => (n == null || isNaN(n)) ? '—' : '$' + n.toFixed(2);
|
|
411
|
+
const fmtDur = (ms) => {
|
|
412
|
+
if (ms == null || isNaN(ms)) return '—';
|
|
413
|
+
const v = Math.round(ms / 1000);
|
|
414
|
+
const d = Math.floor(v / 86400), h = Math.floor(v % 86400 / 3600), m = Math.floor(v % 3600 / 60), s = v % 60;
|
|
415
|
+
if (d > 0) return d + 'd' + h + 'h';
|
|
416
|
+
if (h > 0) return h + 'h' + String(m).padStart(2, '0') + 'm';
|
|
417
|
+
if (m > 0) return m + 'm' + String(s).padStart(2, '0') + 's';
|
|
418
|
+
return s + 's';
|
|
419
|
+
};
|
|
420
|
+
const fmtSpeed = (n) => (n == null || isNaN(n) || !isFinite(n)) ? '—' : ((n >= 100 ? Math.round(n) : Math.round(n * 10) / 10) + ' tok/s');
|
|
421
|
+
const fmtPct = (n) => (n == null || isNaN(n)) ? '—' : (Math.round(n * 10) / 10) + '%';
|
|
422
|
+
const fmtDay = (iso) => (iso ? String(iso).slice(0, 10) : '—');
|
|
423
|
+
const esc = (s) => String(s == null ? '' : s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
424
|
+
const dispAgent = (n) => (n === 'unknown' ? t('legacyAgent') : (n == null || n === '' ? t('legacyAgent') : n));
|
|
425
|
+
const fullName = (r) => ((r && r.provider) || '?') + '/' + ((r && r.model) || '?');
|
|
426
|
+
|
|
427
|
+
// ---- pricing basis -----------------------------------------------------
|
|
428
|
+
// `kind` is the server's verdict (exact/sibling/proxy/partial/unpriced).
|
|
429
|
+
// Fall back to deriving it from pricedAs so the UI still tells the truth on
|
|
430
|
+
// older builds. Anything with a null market is unpriced — never render 0.
|
|
431
|
+
function kindOf(row, name) {
|
|
432
|
+
if (row && row.kind) return row.kind;
|
|
433
|
+
if (!row || row.market == null || row.saved == null) return 'unpriced';
|
|
434
|
+
const pa = row.pricedAs;
|
|
435
|
+
if (typeof pa !== 'string') return pa === true ? 'exact' : 'unpriced';
|
|
436
|
+
if (pa.indexOf('proxy:') === 0) return 'proxy';
|
|
437
|
+
return pa === name ? 'exact' : 'sibling';
|
|
438
|
+
}
|
|
439
|
+
const kindLabel = (k) => (STRINGS[lang] || STRINGS.en)['kind' + k.charAt(0).toUpperCase() + k.slice(1)] || k;
|
|
440
|
+
const tokenTotal = (r) => (+(r && r.tok_in) || 0) + (+(r && r.tok_out) || 0) + (+(r && r.tok_reasoning) || 0) + (+(r && r.cache_read) || 0);
|
|
259
441
|
|
|
442
|
+
// ---- i18n / section persistence ---------------------------------------
|
|
260
443
|
function applyI18n() {
|
|
261
444
|
document.documentElement.lang = lang === 'zh-TW' ? 'zh-Hant' : 'en';
|
|
262
|
-
document.querySelectorAll('[data-i18n]').forEach((el) => {
|
|
263
|
-
el.textContent = t(el.dataset.i18n);
|
|
264
|
-
});
|
|
445
|
+
document.querySelectorAll('[data-i18n]').forEach((el) => { el.textContent = t(el.dataset.i18n); });
|
|
265
446
|
$('langBtn').textContent = t('langBtn');
|
|
266
|
-
$('
|
|
267
|
-
$('
|
|
447
|
+
$('caveat').textContent = t('caveat');
|
|
448
|
+
$('bdSortNote').textContent = t('sortNote');
|
|
449
|
+
applyScopeTags();
|
|
450
|
+
setTab(bdTab);
|
|
451
|
+
renderAll();
|
|
268
452
|
}
|
|
269
453
|
|
|
270
454
|
function restoreSections() {
|
|
271
|
-
document.querySelectorAll('#
|
|
455
|
+
document.querySelectorAll('#scopeBtns .pill, #bdTabs .pill').forEach((el) => {
|
|
272
456
|
el.addEventListener('click', (e) => e.stopPropagation());
|
|
273
457
|
});
|
|
274
458
|
document.querySelectorAll('details.tool-section[id]').forEach((el) => {
|
|
@@ -281,12 +465,33 @@ function restoreSections() {
|
|
|
281
465
|
});
|
|
282
466
|
}
|
|
283
467
|
|
|
468
|
+
// Every section title carries the scope it is currently showing. Tools is
|
|
469
|
+
// the honest exception: the API cannot slice tool counts, so it says so.
|
|
470
|
+
function applyScopeTags() {
|
|
471
|
+
const sl = scopeLabel(scopeDays);
|
|
472
|
+
$('tag-headline').textContent = sl;
|
|
473
|
+
$('tag-breakdown').textContent = sl;
|
|
474
|
+
$('tag-pricing').textContent = sl;
|
|
475
|
+
$('tag-raw').textContent = sl;
|
|
476
|
+
$('tag-trend').textContent = scopeDays === -1 ? t('allTimeTrend') : fmtLang('trendScope', { n: trendDays(scopeDays) });
|
|
477
|
+
$('tag-tools').textContent = fmtLang('toolsScope', { scope: sl });
|
|
478
|
+
$('scopeNow').textContent = sl;
|
|
479
|
+
$('updated').textContent = lastUpdatedText || t('loading');
|
|
480
|
+
}
|
|
481
|
+
|
|
284
482
|
function toggleLang() {
|
|
285
483
|
lang = lang === 'en' ? 'zh-TW' : 'en';
|
|
286
|
-
localStorage.setItem('lang', lang);
|
|
484
|
+
try { localStorage.setItem('lang', lang); } catch (_) {}
|
|
287
485
|
applyI18n();
|
|
288
486
|
}
|
|
289
487
|
|
|
488
|
+
function openPricing() {
|
|
489
|
+
const d = $('sec-pricing');
|
|
490
|
+
d.open = true;
|
|
491
|
+
try { localStorage.setItem('oc-sec-' + d.id, '1'); } catch (_) {}
|
|
492
|
+
try { d.scrollIntoView({ block: 'nearest' }); } catch (_) {}
|
|
493
|
+
}
|
|
494
|
+
|
|
290
495
|
async function backupDb() {
|
|
291
496
|
const btn = $('backupBtn');
|
|
292
497
|
btn.classList.add('busy');
|
|
@@ -294,325 +499,367 @@ async function backupDb() {
|
|
|
294
499
|
try {
|
|
295
500
|
const r = await fetch('/api/backup', { cache: 'no-store' });
|
|
296
501
|
const j = await r.json();
|
|
297
|
-
if (j.ok && j.file) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
} else {
|
|
301
|
-
btn.textContent = '✗ ' + t('backupFail');
|
|
302
|
-
btn.title = j.error || '';
|
|
303
|
-
}
|
|
304
|
-
} catch (e) {
|
|
305
|
-
btn.textContent = '✗ ' + t('backupFail');
|
|
306
|
-
btn.title = e.message;
|
|
307
|
-
}
|
|
502
|
+
if (j.ok && j.file) { btn.textContent = '✓ ' + j.file; btn.title = (j.size / 1024 / 1024).toFixed(1) + ' MB'; }
|
|
503
|
+
else { btn.textContent = '✗ ' + t('backupFail'); btn.title = j.error || ''; }
|
|
504
|
+
} catch (e) { btn.textContent = '✗ ' + t('backupFail'); btn.title = e.message; }
|
|
308
505
|
btn.classList.remove('busy');
|
|
309
506
|
setTimeout(() => { btn.textContent = t('backup'); }, 5000);
|
|
310
507
|
}
|
|
311
508
|
|
|
312
|
-
|
|
313
|
-
let
|
|
509
|
+
// ---- caches (scope switches re-render without hitting the API) ---------
|
|
510
|
+
let lastStats = null;
|
|
511
|
+
let lastUpdatedText = '';
|
|
512
|
+
let lastTools = [];
|
|
513
|
+
const reportCache = Object.create(null); // days -> report
|
|
514
|
+
const trendCache = Object.create(null); // bucketDays -> trend payload
|
|
515
|
+
|
|
516
|
+
// ---- headline + breakdown + pricing + raw ------------------------------
|
|
517
|
+
function renderReport(rep) {
|
|
518
|
+
window.__lastReport = rep;
|
|
519
|
+
if (!rep) return;
|
|
520
|
+
const c = (rep.stats && rep.stats.cost) || {};
|
|
521
|
+
const o = (rep.stats && rep.stats.overview) || {};
|
|
522
|
+
const cacheAll = (c.cacheRead || 0) + (c.cacheWrite || 0);
|
|
523
|
+
|
|
524
|
+
$('hl-tokens').textContent = fmt((c.input || 0) + (c.output || 0) + (c.reasoning || 0) + cacheAll);
|
|
525
|
+
$('hl-in').textContent = fmt(c.input);
|
|
526
|
+
$('hl-out').textContent = fmt(c.output);
|
|
527
|
+
$('hl-reasoning').textContent = fmt(c.reasoning);
|
|
528
|
+
$('hl-cache').textContent = fmt(cacheAll);
|
|
529
|
+
$('hl-cost').textContent = fmtCost(c.total);
|
|
530
|
+
$('hl-market').textContent = fmtCost(c.marketTotal);
|
|
531
|
+
$('hl-saved').textContent = fmtCost(c.savedTotal);
|
|
532
|
+
$('hl-savedPct').textContent = (c.marketTotal > 0 && c.savedPct != null) ? fmtLang('savedOf', { pct: fmtPct(c.savedPct) }) : '';
|
|
533
|
+
|
|
534
|
+
const meta = [t('sessionsLabel') + ' ' + fmt(o.sessions), t('messagesLabel') + ' ' + fmt(o.messages),
|
|
535
|
+
t('daysLabel') + ' ' + fmt(o.days), t('avgCostDay') + ' ' + fmtCost(c.avgDay),
|
|
536
|
+
t('avgTokensSession') + ' ' + fmt(c.avgTokensSession), t('medianTokensSession') + ' ' + fmt(c.medianTokensSession)];
|
|
537
|
+
$('hl-meta').textContent = meta.join(' · ');
|
|
538
|
+
|
|
539
|
+
// Pricing credibility: catalog date, proxy-estimated share, unpriced rows.
|
|
540
|
+
const priceAsOf = c.priceAsOf || rep.priceAsOf || null;
|
|
541
|
+
$('hl-priceAsOf').textContent = priceAsOf ? fmtLang('pricesAsOf', { d: fmtDay(priceAsOf) }) : '';
|
|
542
|
+
const prov = rep.providers || [];
|
|
543
|
+
const unpriced = prov.filter((p) => kindOf(p, fullName(p)) === 'unpriced');
|
|
544
|
+
const unpricedRows = c.unpricedRows != null ? c.unpricedRows : unpriced.length;
|
|
545
|
+
const unpricedTokens = c.unpricedTokens != null
|
|
546
|
+
? c.unpricedTokens
|
|
547
|
+
: unpriced.reduce((s, p) => s + tokenTotal(p), 0);
|
|
548
|
+
const warn = $('hl-unpriced');
|
|
549
|
+
warn.textContent = unpricedRows > 0
|
|
550
|
+
? fmtLang('unpricedModels', { n: unpricedRows, t: fmt(unpricedTokens) }) : '';
|
|
551
|
+
warn.title = warn.textContent ? t('pricingBasis') : '';
|
|
552
|
+
let proxyShare = c.proxyShare;
|
|
553
|
+
if (proxyShare == null) {
|
|
554
|
+
const proxyTok = prov.filter((p) => kindOf(p, fullName(p)) === 'proxy').reduce((s, p) => s + tokenTotal(p), 0);
|
|
555
|
+
const allTok = prov.reduce((s, p) => s + tokenTotal(p), 0);
|
|
556
|
+
proxyShare = allTok > 0 ? (proxyTok / allTok) * 100 : null;
|
|
557
|
+
}
|
|
558
|
+
$('hl-proxy').textContent = (proxyShare != null && proxyShare > 0) ? fmtLang('proxyShare', { pct: fmtPct(proxyShare) }) : '';
|
|
314
559
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
if (n >= 1e3) return (n / 1e3).toFixed(1) + 'K';
|
|
320
|
-
return String(Math.round(n));
|
|
321
|
-
};
|
|
322
|
-
const fmtCost = (n) => (n == null || isNaN(n)) ? '—' : '$' + n.toFixed(2);
|
|
323
|
-
const fmtDur = (ms) => { const v = Math.round((ms || 0) / 1000); if (!isFinite(v) || v < 0) return '—'; const d = Math.floor(v / 86400), h = Math.floor(v % 86400 / 3600), m = Math.floor(v % 3600 / 60), s = v % 60; if (d > 0) return d + 'd' + h + 'h'; if (h > 0) return h + 'h' + String(m).padStart(2, '0') + 'm'; if (m > 0) return m + 'm' + String(s).padStart(2, '0') + 's'; return s + 's'; };
|
|
324
|
-
const esc = (s) => String(s == null ? '' : s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
325
|
-
const fmtSpeed = (n) => (n == null || isNaN(n) || !isFinite(n)) ? '—' : ((n >= 100 ? Math.round(n) : Math.round(n * 10) / 10) + ' tok/s');
|
|
560
|
+
renderBreakdown(rep);
|
|
561
|
+
renderPricing(rep);
|
|
562
|
+
$('rawText').textContent = formatReport(rep);
|
|
563
|
+
}
|
|
326
564
|
|
|
327
|
-
function
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
565
|
+
function shareCell(row, total) {
|
|
566
|
+
const tk = tokenTotal(row);
|
|
567
|
+
const seg = (v) => (tk > 0 ? (v / tk) * 100 : 0);
|
|
568
|
+
const w = total > 0 ? Math.max(0.4, (tk / total) * 100) : 0;
|
|
569
|
+
if (tk <= 0) return '<div class="track share"></div>';
|
|
570
|
+
return `<div class="track share" title="${esc(fmt(tk))}"><div class="stack" style="width:${w}%">`
|
|
571
|
+
+ `<div style="width:${seg(+row.tok_in || 0)}%;background:var(--in)"></div>`
|
|
572
|
+
+ `<div style="width:${seg(+row.tok_out || 0)}%;background:var(--out)"></div>`
|
|
573
|
+
+ `<div style="width:${seg(+row.tok_reasoning || 0)}%;background:var(--tool)"></div>`
|
|
574
|
+
+ `<div style="width:${seg(+row.cache_read || 0)}%;background:var(--cache)"></div>`
|
|
575
|
+
+ '</div></div>';
|
|
332
576
|
}
|
|
333
577
|
|
|
334
|
-
function
|
|
335
|
-
const
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
$('token-bars').innerHTML =
|
|
350
|
-
barRow('Input', d.cost.input, max, 'var(--in)') +
|
|
351
|
-
barRow('Output', d.cost.output, max, 'var(--out)') +
|
|
352
|
-
barRow('Reasoning', d.cost.reasoning, max, 'var(--tool)') +
|
|
353
|
-
barRow('Cache Read', d.cost.cacheRead, max, 'var(--cache)') +
|
|
354
|
-
barRow('Cache Write', d.cost.cacheWrite, max, 'var(--cost)');
|
|
355
|
-
}
|
|
578
|
+
function bdRow(name, title, row, total, countVal) {
|
|
579
|
+
const wall = row.wallMs;
|
|
580
|
+
const active = row.activeMs;
|
|
581
|
+
return `<tr><td class="bd-name" title="${esc(title)}">${esc(name)}</td>`
|
|
582
|
+
+ `<td>${shareCell(row, total)}</td>`
|
|
583
|
+
+ `<td>${countVal}</td>`
|
|
584
|
+
+ `<td>${fmt(row.tok_in)}</td>`
|
|
585
|
+
+ `<td>${fmt(row.tok_out)}</td>`
|
|
586
|
+
+ `<td>${fmt(row.tok_reasoning)}</td>`
|
|
587
|
+
+ `<td>${fmt(row.cache_read)}</td>`
|
|
588
|
+
+ `<td>${fmtSpeed(row.speed)}</td>`
|
|
589
|
+
+ `<td title="${esc(active == null ? '' : t('activeLabel') + ' ' + fmtDur(active))}">${fmtDur(wall)}</td>`
|
|
590
|
+
+ `<td>${fmtCost(row.market)}</td>`
|
|
591
|
+
+ `<td>${fmtCost(row.saved)}</td></tr>`;
|
|
592
|
+
}
|
|
356
593
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
594
|
+
const sortByTokens = (a, b) => tokenTotal(b) - tokenTotal(a);
|
|
595
|
+
const sumTokens = (rows) => rows.reduce((s, r) => s + tokenTotal(r), 0);
|
|
596
|
+
|
|
597
|
+
function renderBreakdown(rep) {
|
|
598
|
+
const prov = (rep.providers || []).slice().sort(sortByTokens);
|
|
599
|
+
const ags = (rep.agents || []).slice().sort(sortByTokens);
|
|
600
|
+
const sess = (rep.sessions || []).slice(0, SESSION_TOP_N).sort(sortByTokens);
|
|
601
|
+
|
|
602
|
+
$('bd-models').innerHTML = prov.map((p) =>
|
|
603
|
+
bdRow(fullName(p), fullName(p) + ' · ' + (p.pricedAs || kindOf(p, fullName(p))), p, sumTokens(prov), fmt(p.sessions))).join('');
|
|
604
|
+
$('bd-agents').innerHTML = ags.map((a) =>
|
|
605
|
+
bdRow(dispAgent(a.agent), (a.agent || '') + ' · ' + t('sessionsLabel') + ' ' + fmt(a.sessions), a, sumTokens(ags), fmt(a.sessions))).join('');
|
|
606
|
+
$('bd-sessions').innerHTML = sess.map((s) =>
|
|
607
|
+
bdRow(String(s.id).slice(0, 12), String(s.id) + ' · ' + (s.title || '') + ' · ' + (s.agent || '') + ' · ' + fullName(s),
|
|
608
|
+
s, sumTokens(sess), fmt(s.messages))).join('');
|
|
609
|
+
|
|
610
|
+
const empty = !prov.length && !ags.length && !sess.length;
|
|
611
|
+
$('bd-empty').style.display = empty ? '' : 'none';
|
|
612
|
+
$('bd-empty').textContent = empty ? t('noData') : '';
|
|
613
|
+
$('bdSortNote').textContent = t('sortNote');
|
|
614
|
+
setTab(bdTab);
|
|
615
|
+
}
|
|
360
616
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
617
|
+
function setTab(tab) {
|
|
618
|
+
bdTab = tab;
|
|
619
|
+
try { localStorage.setItem('bdTab', tab); } catch (_) {}
|
|
620
|
+
['models', 'agents', 'sessions'].forEach((k) => { $('bd-' + k).style.display = k === tab ? '' : 'none'; });
|
|
621
|
+
const heads = {
|
|
622
|
+
models: [t('thUsageModel'), t('thSessions')],
|
|
623
|
+
agents: [t('tabAgents'), t('thSessions')],
|
|
624
|
+
sessions: [t('tabSessions'), t('thMsgs')],
|
|
625
|
+
};
|
|
626
|
+
const h = heads[tab] || heads.models;
|
|
627
|
+
$('th-name').textContent = h[0];
|
|
628
|
+
$('th-count').textContent = h[1];
|
|
629
|
+
document.querySelectorAll('#bdTabs .pill').forEach((el) => {
|
|
630
|
+
el.classList.toggle('active', el.dataset.tab === tab);
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
function renderPricing(rep) {
|
|
635
|
+
const prov = (rep.providers || []).slice().sort(sortByTokens);
|
|
636
|
+
$('pricing-rows').innerHTML = prov.map((p) => {
|
|
637
|
+
const name = fullName(p);
|
|
638
|
+
const kind = kindOf(p, name);
|
|
639
|
+
return `<tr><td class="clip" title="${esc(name)}">${esc(name)}</td>`
|
|
640
|
+
+ `<td class="clip" title="${esc(p.pricedAs || '')}">${kind === 'unpriced' ? '—' : esc(p.pricedAs || '—')}</td>`
|
|
641
|
+
+ `<td><span class="badge ${esc(kind)}">${esc(kindLabel(kind))}</span></td>`
|
|
642
|
+
+ `<td>${fmtCost(p.market)}</td>`
|
|
643
|
+
+ `<td>${fmtCost(p.saved)}</td></tr>`;
|
|
644
|
+
}).join('');
|
|
645
|
+
$('pricing-empty').style.display = prov.length ? 'none' : '';
|
|
646
|
+
$('pricing-empty').textContent = prov.length ? '' : t('noData');
|
|
647
|
+
}
|
|
379
648
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
} else {
|
|
649
|
+
// ---- trend (buckets follow scope; newest day leftmost) -----------------
|
|
650
|
+
function renderTrend(data) {
|
|
651
|
+
if (!data || !data.labels || !data.labels.length) {
|
|
384
652
|
$('trend-tokens').innerHTML = '';
|
|
385
653
|
$('trend-token-x').innerHTML = '';
|
|
386
654
|
$('trend-cost').innerHTML = '';
|
|
387
655
|
$('trend-cost-x').innerHTML = '';
|
|
388
656
|
$('costZeroNote').style.display = 'none';
|
|
389
|
-
$('costSection').querySelector('.legend').style.display = '';
|
|
390
657
|
$('trendCostChart').style.display = '';
|
|
391
658
|
$('trend-cost-x').style.display = '';
|
|
392
659
|
$('trendStatus').textContent = '⏳ ' + t('generating');
|
|
660
|
+
return;
|
|
393
661
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
const
|
|
398
|
-
const
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
662
|
+
const ts = data.generatedAt || 0;
|
|
663
|
+
const day = (s) => String(s == null ? 0 : s);
|
|
664
|
+
// Server already emits newest→oldest, so today sits at the left edge as-is.
|
|
665
|
+
const labels = data.labels || [];
|
|
666
|
+
const input = data.input || [];
|
|
667
|
+
const output = data.output || [];
|
|
668
|
+
const reasoning = data.reasoning || [];
|
|
669
|
+
const cache = data.cacheRead || [];
|
|
670
|
+
const cost = data.cost || [];
|
|
671
|
+
const sessions = data.sessions || [];
|
|
672
|
+
const n = labels.length;
|
|
673
|
+
|
|
674
|
+
const maxAll = Math.max(1, ...input, ...output, ...reasoning, ...cache);
|
|
675
|
+
const genTime = ts ? new Date(ts).toLocaleTimeString(lang === 'zh-TW' ? 'zh-TW' : 'en', { hour12: false }) : '?';
|
|
676
|
+
|
|
677
|
+
$('trend-tokens').innerHTML = labels.map((l, i) => {
|
|
678
|
+
const hi = (input[i] / maxAll) * 100, ho = (output[i] / maxAll) * 100;
|
|
679
|
+
const hr = (reasoning[i] / maxAll) * 100, hc = (cache[i] / maxAll) * 100;
|
|
680
|
+
const tip = [l, t('sessionsLabel') + ' ' + day(sessions[i]),
|
|
681
|
+
t('tIn') + ' ' + fmt(input[i]), t('tOut') + ' ' + fmt(output[i]),
|
|
682
|
+
t('tReasoning') + ' ' + fmt(reasoning[i]), t('tCache') + ' ' + fmt(cache[i]),
|
|
683
|
+
t('totalCost') + ' ' + fmtCost(cost[i])].join(' · ') + ' · ' + genTime;
|
|
684
|
+
return `<div class="col" title="${esc(tip)}">`
|
|
685
|
+
+ '<div style="display:flex;gap:2px;align-items:flex-end;width:100%;height:170px;justify-content:center">'
|
|
686
|
+
+ '<div style="position:relative;width:100%;height:100%">'
|
|
687
|
+
+ `<div class="trend-bar trend-bar-cache" style="height:${Math.max(hc, 1)}%;background:var(--cache)"></div>`
|
|
688
|
+
+ `<div class="trend-bar trend-bar-input" style="height:${Math.max(hi, 1)}%;background:var(--in)"></div>`
|
|
689
|
+
+ `<div class="trend-bar trend-bar-output" style="height:${Math.max(ho, 1)}%;background:var(--out)"></div>`
|
|
690
|
+
+ `<div class="trend-bar trend-bar-reasoning" style="height:${Math.max(hr, 1)}%;background:var(--tool)"></div>`
|
|
691
|
+
+ '</div></div></div>';
|
|
418
692
|
}).join('');
|
|
419
693
|
|
|
420
694
|
const labelStep = Math.max(1, Math.ceil(n / 14));
|
|
421
|
-
$('trend-token-x').innerHTML =
|
|
422
|
-
|
|
423
|
-
return `<span style="${vis}">${l}</span>`;
|
|
424
|
-
}).join('');
|
|
695
|
+
$('trend-token-x').innerHTML = labels.map((l, i) =>
|
|
696
|
+
`<span style="${i % labelStep === 0 ? '' : 'visibility:hidden'}">${esc(l)}</span>`).join('');
|
|
425
697
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
$('costZeroNote').style.display = 'none';
|
|
431
|
-
const costThreshold = 0.0001;
|
|
432
|
-
const displayCost = data.cost.map((v) => v < costThreshold ? 0 : v);
|
|
433
|
-
const hasRealCost = displayCost.some((v) => v > 0);
|
|
434
|
-
if (!hasRealCost) {
|
|
435
|
-
$('costSection').querySelector('.legend').style.display = 'none';
|
|
436
|
-
$('trendCostChart').style.display = 'none';
|
|
437
|
-
$('trend-cost-x').style.display = 'none';
|
|
438
|
-
$('costZeroNote').style.display = '';
|
|
439
|
-
$('costZeroNote').textContent = t('allFree');
|
|
440
|
-
} else {
|
|
441
|
-
const maxCost = Math.max(...displayCost);
|
|
442
|
-
$('trend-cost').innerHTML = data.labels.map((l, i) => {
|
|
443
|
-
const h = maxCost > 0 ? (displayCost[i] / maxCost) * 100 : 0;
|
|
444
|
-
const tip = l + ': $' + (displayCost[i] || 0).toFixed(4);
|
|
445
|
-
return `<div class="col" title="${tip}">
|
|
446
|
-
<div style="display:flex;align-items:flex-end;width:100%;height:170px;justify-content:center">
|
|
447
|
-
<div style="width:50%;height:${Math.max(h, 1)}%;background:var(--cost);border-radius:2px 2px 0 0"></div>
|
|
448
|
-
</div>
|
|
449
|
-
</div>`;
|
|
450
|
-
}).join('');
|
|
451
|
-
$('trend-cost-x').innerHTML = data.labels.map((l, i) => {
|
|
452
|
-
const vis = i % labelStep === 0 ? '' : 'visibility:hidden';
|
|
453
|
-
return `<span style="${vis}">${l}</span>`;
|
|
454
|
-
}).join('');
|
|
455
|
-
}
|
|
456
|
-
} else {
|
|
457
|
-
$('costSection').querySelector('.legend').style.display = 'none';
|
|
698
|
+
$('trendStatus').textContent = data.stale ? ' ⟳ ' + t('updating') : '';
|
|
699
|
+
const anyCost = cost.some((v) => v > 0);
|
|
700
|
+
const costLegend = $('costSection').querySelector('.legend');
|
|
701
|
+
if (!anyCost) {
|
|
458
702
|
$('trendCostChart').style.display = 'none';
|
|
459
703
|
$('trend-cost-x').style.display = 'none';
|
|
704
|
+
costLegend.style.display = 'none';
|
|
460
705
|
$('costZeroNote').style.display = '';
|
|
461
706
|
$('costZeroNote').textContent = t('allFree');
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
costLegend.style.display = '';
|
|
710
|
+
$('trendCostChart').style.display = '';
|
|
711
|
+
$('trend-cost-x').style.display = '';
|
|
712
|
+
$('costZeroNote').style.display = 'none';
|
|
713
|
+
const maxCost = Math.max(...cost);
|
|
714
|
+
$('trend-cost').innerHTML = labels.map((l, i) => {
|
|
715
|
+
const h = maxCost > 0 ? (cost[i] / maxCost) * 100 : 0;
|
|
716
|
+
return `<div class="col" title="${esc(l + ' · ' + fmtCost(cost[i]) + ' · ' + genTime)}">`
|
|
717
|
+
+ '<div style="display:flex;align-items:flex-end;width:100%;height:170px;justify-content:center">'
|
|
718
|
+
+ `<div style="width:50%;height:${Math.max(h, 1)}%;background:var(--cost);border-radius:2px 2px 0 0"></div>`
|
|
719
|
+
+ '</div></div>';
|
|
720
|
+
}).join('');
|
|
721
|
+
$('trend-cost-x').innerHTML = labels.map((l, i) =>
|
|
722
|
+
`<span style="${i % labelStep === 0 ? '' : 'visibility:hidden'}">${esc(l)}</span>`).join('');
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// ---- tools (all-time; the API cannot slice them) -----------------------
|
|
726
|
+
function renderTools(tools) {
|
|
727
|
+
if (!tools || !tools.length) {
|
|
728
|
+
$('tool-bars').innerHTML = lastStats ? '<div class="empty">' + esc(t('noData')) + '</div>' : '';
|
|
729
|
+
return;
|
|
462
730
|
}
|
|
731
|
+
const max = Math.max.apply(null, tools.map((x) => x.count || 0));
|
|
732
|
+
$('tool-bars').innerHTML = tools.map((tool) => {
|
|
733
|
+
const pct = max > 0 ? Math.max(0.5, ((tool.count || 0) / max) * 100) : 0;
|
|
734
|
+
return `<div class="bar-row" style="display:grid;grid-template-columns:150px 1fr 140px;align-items:center;gap:12px;padding:5px 0;font-size:13px">`
|
|
735
|
+
+ `<div style="color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis" title="${esc(tool.name || '')}">${esc(tool.name || '')}</div>`
|
|
736
|
+
+ `<div class="track"><div class="fill" style="width:${pct}%;background:var(--tool)"></div></div>`
|
|
737
|
+
+ `<div style="text-align:right;font-variant-numeric:tabular-nums">${fmt(tool.count)} · ${fmtPct(tool.pct)}</div></div>`;
|
|
738
|
+
}).join('');
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// ---- one render pass over everything (no network) ---------------------
|
|
742
|
+
function renderAll() {
|
|
743
|
+
applyScopeTags();
|
|
744
|
+
if (window.__lastReport) renderReport(window.__lastReport);
|
|
745
|
+
const tr = trendCache[trendDays(scopeDays)];
|
|
746
|
+
renderTrend(tr || null);
|
|
747
|
+
renderTools(lastTools);
|
|
463
748
|
}
|
|
464
749
|
|
|
750
|
+
// ---- data loading ------------------------------------------------------
|
|
465
751
|
async function poll() {
|
|
752
|
+
const bucket = trendDays(scopeDays);
|
|
466
753
|
try {
|
|
467
|
-
const r = await fetch('/api/stats?days=' +
|
|
754
|
+
const r = await fetch('/api/stats?days=' + bucket + '&_=' + Date.now(), { cache: 'no-store' });
|
|
468
755
|
const j = await r.json();
|
|
469
756
|
if (j.loading) {
|
|
470
757
|
$('pill').textContent = t('updating');
|
|
471
758
|
$('pill').className = 'pill lang';
|
|
472
|
-
|
|
473
|
-
|
|
759
|
+
lastUpdatedText = t('updating');
|
|
760
|
+
$('updated').textContent = lastUpdatedText;
|
|
761
|
+
return null;
|
|
474
762
|
}
|
|
475
763
|
if (!j.ok) {
|
|
476
764
|
$('errbanner').textContent = t('statsFail') + ': ' + (j.error || '');
|
|
477
765
|
$('errbanner').classList.add('show');
|
|
478
766
|
$('pill').textContent = t('statsFail');
|
|
479
767
|
$('pill').className = 'pill err';
|
|
480
|
-
return;
|
|
768
|
+
return null;
|
|
481
769
|
}
|
|
482
770
|
$('errbanner').classList.remove('show');
|
|
483
771
|
$('pill').textContent = t('live');
|
|
484
772
|
$('pill').className = 'pill ok';
|
|
485
|
-
|
|
773
|
+
lastStats = j;
|
|
774
|
+
lastTools = (j.data && j.data.tools) || [];
|
|
775
|
+
if (j.trend && j.trend.labels && j.trend.labels.length) {
|
|
776
|
+
trendCache[bucket] = j.trend;
|
|
777
|
+
trendCache[trendDays(j.trend.step || bucket)] = j.trend;
|
|
778
|
+
renderTrend(trendCache[trendDays(scopeDays)] || j.trend);
|
|
779
|
+
} else {
|
|
780
|
+
renderTrend(null);
|
|
781
|
+
}
|
|
782
|
+
renderTools(lastTools);
|
|
486
783
|
const ago = Math.round((Date.now() - (j.generatedAt || 0)) / 1000);
|
|
487
784
|
const time = new Date().toLocaleTimeString(lang === 'zh-TW' ? 'zh-TW' : 'en', { hour12: false });
|
|
488
|
-
|
|
785
|
+
lastUpdatedText = t('lastUpdated') + ' ' + time + ' (' + t('dataAgo') + ' ' + ago + 's)';
|
|
786
|
+
$('updated').textContent = lastUpdatedText;
|
|
787
|
+
return j;
|
|
489
788
|
} catch (e) {
|
|
490
789
|
$('updated').textContent = t('connFail') + ': ' + e.message;
|
|
790
|
+
lastUpdatedText = $('updated').textContent;
|
|
791
|
+
return null;
|
|
491
792
|
}
|
|
492
793
|
}
|
|
493
794
|
|
|
494
|
-
function setRange(days) {
|
|
495
|
-
currentDays = days;
|
|
496
|
-
localStorage.setItem('trendDays', days);
|
|
497
|
-
document.querySelectorAll('#rangeBtns .pill').forEach((el) => {
|
|
498
|
-
el.classList.toggle('active', parseInt(el.dataset.days, 10) === days);
|
|
499
|
-
});
|
|
500
|
-
$('trendTitle').textContent = t('dailyTrend').replace('{days}', days);
|
|
501
|
-
poll();
|
|
502
|
-
}
|
|
503
|
-
|
|
504
795
|
let reportLoading = false;
|
|
505
796
|
let reportRetry = 0;
|
|
506
797
|
const MAX_REPORT_RETRIES = 12;
|
|
507
798
|
|
|
508
|
-
function
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
const sess = r.sessions || [];
|
|
537
|
-
const xmax = Math.max(0, ...sess.map((s) => s.wallMs || 0));
|
|
538
|
-
$('session-bars').innerHTML = sess.length ? sess.map((s) =>
|
|
539
|
-
twoBars(String(s.id).slice(0, 12), s.wallMs || 0, s.activeMs || 0, xmax,
|
|
540
|
-
fmtDur(s.wallMs) + ' · ' + fmtSpeed(s.speed),
|
|
541
|
-
(s.title || '') + ' · ' + s.agent + ' · ' + s.provider + '/' + s.model + ' · ' + (s.messages || 0) + ' msgs')
|
|
542
|
-
).join('') : '<div class="val">—</div>';
|
|
543
|
-
|
|
544
|
-
const mkt = (r.providers || []).slice().sort((a, b) => (b.market || 0) - (a.market || 0));
|
|
545
|
-
const mmax = Math.max(0, ...mkt.map((p) => p.market || 0));
|
|
546
|
-
$('savings-bars').innerHTML = mkt.length ? mkt.map((p) => {
|
|
547
|
-
const pct = mmax > 0 ? Math.max(0.5, ((p.market || 0) / mmax) * 100) : 0;
|
|
548
|
-
const sv = p.saved == null ? '—' : fmtCost(p.saved) + ' saved';
|
|
549
|
-
const tip = 'market ' + fmtCost(p.market) + ' · actual ' + fmtCost(p.cost) + ' · via ' + (p.pricedAs || '?');
|
|
550
|
-
return `<div class="bar-row wide"><div class="name" title="${esc(fullName(p))}">${esc(fullName(p))}</div>
|
|
551
|
-
<div class="track"><div class="fill" style="width:${pct}%;background:var(--cost)"></div></div>
|
|
552
|
-
<div class="val" title="${esc(tip)}">${sv}</div></div>`;
|
|
553
|
-
}).join('') : '<div class="val">—</div>';
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
function repTable(heads, rows) {
|
|
557
|
-
return `<div class="scrollx"><table><thead><tr>${heads.map((h) => `<th>${esc(h)}</th>`).join('')}</tr></thead><tbody>${rows.join('')}</tbody></table></div>`;
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
function repBlock(title, hint, body, isOpen) {
|
|
561
|
-
return `<details class="tool-section"${isOpen ? ' open' : ''}><summary><h2>${esc(title)}</h2><span class="rep-hint">${esc(hint)}</span></summary>${body}</details>`;
|
|
799
|
+
async function loadReport(days) {
|
|
800
|
+
if (reportLoading) return reportCache[days] || null;
|
|
801
|
+
reportLoading = true;
|
|
802
|
+
try {
|
|
803
|
+
const r = await fetch('/api/report?days=' + days + '&_=' + Date.now(), { cache: 'no-store' });
|
|
804
|
+
const j = await r.json();
|
|
805
|
+
if (j.ok === false) { $('rawText').textContent = t('reportFail'); return null; }
|
|
806
|
+
if (!j.ready || !j.report) {
|
|
807
|
+
$('rawText').textContent = '⏳ ' + t('generating') + '…';
|
|
808
|
+
reportRetry++;
|
|
809
|
+
if (reportRetry < MAX_REPORT_RETRIES) {
|
|
810
|
+
const delay = Math.min(1000 * Math.pow(1.5, reportRetry), 15000);
|
|
811
|
+
setTimeout(() => loadReport(days), delay);
|
|
812
|
+
}
|
|
813
|
+
return null;
|
|
814
|
+
}
|
|
815
|
+
reportRetry = 0;
|
|
816
|
+
reportCache[days] = j.report;
|
|
817
|
+
applyScopeTags();
|
|
818
|
+
renderReport(j.report);
|
|
819
|
+
return j.report;
|
|
820
|
+
} catch (e) {
|
|
821
|
+
$('rawText').textContent = t('connFail') + ': ' + e.message;
|
|
822
|
+
return null;
|
|
823
|
+
} finally {
|
|
824
|
+
reportLoading = false;
|
|
825
|
+
}
|
|
562
826
|
}
|
|
563
827
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
})), true);
|
|
582
|
-
|
|
583
|
-
const ags = r.agents || [];
|
|
584
|
-
h += repBlock(t('repAgents'), ags.length + ' agents' + (ags.length ? ' · ' + ags[0].agent : ''),
|
|
585
|
-
repTable(['Agent', 'Sess', 'Cost', 'In', 'Out', 'Speed', 'Wall', 'Active', 'Market', 'Saved'], ags.map((a) =>
|
|
586
|
-
`<tr><td>${esc(a.agent)}</td><td>${a.sessions}</td><td>${fmtCost(a.cost)}</td><td>${fmt(a.tok_in)}</td><td>${fmt(a.tok_out)}</td><td>${fmtSpeed(a.speed)}</td><td>${fmtDur(a.wallMs)}</td><td>${fmtDur(a.activeMs)}</td><td>${fmtCost(a.market)}</td><td>${fmtCost(a.saved)}</td></tr>`)), true);
|
|
587
|
-
|
|
588
|
-
const sess = r.sessions || [];
|
|
589
|
-
h += repBlock(t('repSessions'), 'top ' + sess.length + ' by wall',
|
|
590
|
-
repTable(['Session', 'Agent', 'Model', 'Wall', 'Active', 'Msgs', 'In', 'Out', 'Speed', 'Saved'], sess.map((s) => {
|
|
591
|
-
const name = s.provider + '/' + s.model;
|
|
592
|
-
return `<tr><td class="clip" title="${esc(s.id + ' · ' + (s.title || ''))}">${esc(String(s.id).slice(0, 12))}</td><td>${esc(s.agent)}</td><td class="clip" title="${esc(name)}">${esc(name)}</td><td>${fmtDur(s.wallMs)}</td><td>${fmtDur(s.activeMs)}</td><td>${s.messages}</td><td>${fmt(s.tok_in)}</td><td>${fmt(s.tok_out)}</td><td>${fmtSpeed(s.speed)}</td><td>${fmtCost(s.saved)}</td></tr>`;
|
|
593
|
-
})), true);
|
|
594
|
-
|
|
595
|
-
const basis = prov.filter((p) => p.pricedAs && p.pricedAs !== (p.provider + '/' + p.model));
|
|
596
|
-
if (basis.length) {
|
|
597
|
-
h += repBlock(t('repPricing'), basis.length + ' mappings',
|
|
598
|
-
repTable(['Usage', 'Basis'], basis.map((p) =>
|
|
599
|
-
`<tr><td class="clip" title="${esc(p.provider + '/' + p.model)}">${esc(p.provider + '/' + p.model)}</td><td class="clip" title="${esc(p.pricedAs)}">${esc(p.pricedAs)}</td></tr>`)), false);
|
|
828
|
+
// ---- global scope switch ----------------------------------------------
|
|
829
|
+
// Always repaints every section's scope tag first (cache-backed, instant),
|
|
830
|
+
// then refreshes from the API only for a scope we have not seen yet.
|
|
831
|
+
async function setScope(days) {
|
|
832
|
+
days = parseInt(days, 10);
|
|
833
|
+
if (SCOPE_DAYS.indexOf(days) < 0) return null;
|
|
834
|
+
scopeDays = days;
|
|
835
|
+
try { localStorage.setItem('scopeDays', String(days)); } catch (_) {}
|
|
836
|
+
document.querySelectorAll('#scopeBtns .pill').forEach((el) => {
|
|
837
|
+
el.classList.toggle('active', parseInt(el.dataset.days, 10) === days);
|
|
838
|
+
});
|
|
839
|
+
const cached = reportCache[days];
|
|
840
|
+
if (cached) {
|
|
841
|
+
window.__lastReport = cached;
|
|
842
|
+
applyScopeTags();
|
|
843
|
+
renderAll();
|
|
844
|
+
return cached;
|
|
600
845
|
}
|
|
601
|
-
|
|
602
|
-
|
|
846
|
+
applyScopeTags();
|
|
847
|
+
$('rawText').textContent = '⏳ ' + t('generating') + '…';
|
|
848
|
+
const [rep] = await Promise.all([loadReport(days), poll()]);
|
|
849
|
+
return rep;
|
|
603
850
|
}
|
|
604
851
|
|
|
852
|
+
// ---- plain-text statement (RAW TEXT) ----------------------------------
|
|
605
853
|
function formatReport(jr) {
|
|
606
854
|
const genTime = jr.generatedAt ? new Date(jr.generatedAt).toLocaleTimeString(lang === 'zh-TW' ? 'zh-TW' : 'en', { hour12: false }) : '?';
|
|
607
|
-
const cachedNote = jr.stale ? ' [
|
|
608
|
-
const
|
|
609
|
-
const
|
|
855
|
+
const cachedNote = jr.stale ? ' [' + t('updating') + ']' : ' [' + t('cachedAt') + ' ' + genTime + ']';
|
|
856
|
+
const fCost = (n) => { const v = parseFloat(n); if (isNaN(v)) return '—'; return v === 0 ? '$0.00' : '$' + v.toFixed(4); };
|
|
857
|
+
const fT = (n) => { const v = parseInt(n, 10); if (isNaN(v)) return '—'; if (v >= 1e9) return (v / 1e9).toFixed(2) + 'B'; if (v >= 1e6) return (v / 1e6).toFixed(1) + 'M'; if (v >= 1e3) return (v / 1e3).toFixed(1) + 'K'; return String(v); };
|
|
610
858
|
const pad = (s, w) => { s = String(s); return s.length >= w ? s : s + ' '.repeat(w - s.length); };
|
|
611
859
|
const rpad = (s, w) => { s = String(s); return s.length >= w ? s : ' '.repeat(w - s.length) + s; };
|
|
612
860
|
let out = '';
|
|
613
861
|
out += 'OPENCODE USAGE STATEMENT\n';
|
|
614
|
-
|
|
615
|
-
out += 'Period: ' + jr.label + ' | ' + periodText + cachedNote + '\n';
|
|
862
|
+
out += 'Period: ' + jr.label + ' | ' + scopeLabel(jr.days) + cachedNote + '\n';
|
|
616
863
|
out += '---\n';
|
|
617
864
|
const s = jr.stats;
|
|
618
865
|
if (s && s.ok) {
|
|
@@ -622,83 +869,53 @@ function formatReport(jr) {
|
|
|
622
869
|
out += ' Sessions ........... ' + (o.sessions || 0) + '\n';
|
|
623
870
|
out += ' Messages ........... ' + (o.messages || 0) + '\n';
|
|
624
871
|
out += ' Total Cost ......... $' + (c.total || 0).toFixed(2) + '\n';
|
|
625
|
-
out += ' Tokens In/Out ...... ' +
|
|
626
|
-
out += ' Tokens Reasoning ... ' +
|
|
627
|
-
out += ' Cache Read/Write ... ' +
|
|
628
|
-
out += ' Market value
|
|
629
|
-
out += ' Saved
|
|
872
|
+
out += ' Tokens In/Out ...... ' + fT(c.input) + ' / ' + fT(c.output) + '\n';
|
|
873
|
+
out += ' Tokens Reasoning ... ' + fT(c.reasoning) + '\n';
|
|
874
|
+
out += ' Cache Read/Write ... ' + fT(c.cacheRead) + ' / ' + fT(c.cacheWrite) + '\n';
|
|
875
|
+
out += ' Market value ....... ' + (c.marketTotal == null ? '—' : '$' + c.marketTotal.toFixed(2)) + '\n';
|
|
876
|
+
out += ' Saved .............. ' + (c.savedTotal == null ? '—' : '$' + c.savedTotal.toFixed(2)) + (c.marketTotal > 0 && c.savedPct != null ? ' (' + c.savedPct + '%)' : '') + '\n';
|
|
877
|
+
if (c.priceAsOf) out += ' Prices as of ....... ' + fmtDay(c.priceAsOf) + '\n';
|
|
630
878
|
out += '\n';
|
|
631
879
|
}
|
|
632
880
|
if (jr.providers && jr.providers.length) {
|
|
633
881
|
out += 'PROVIDERS & MODELS\n';
|
|
634
882
|
jr.providers.forEach((p) => {
|
|
635
|
-
|
|
883
|
+
const name = p.provider + '/' + p.model;
|
|
884
|
+
out += ' ' + pad(name, 45) + pad(p.sessions + ' sessions', 14) + ' ' + rpad(fCost(p.cost), 10) + ' ' + rpad(fT(p.tok_in), 8) + ' in / ' + rpad(fT(p.tok_out), 8) + ' out cache: ' + rpad(fT(p.cache_read), 8) + ' ' + rpad(fmtSpeed(p.speed), 11) + ' mkt:' + rpad(fCost(p.market), 11) + ' svd:' + rpad(fCost(p.saved), 11) + ' [' + kindOf(p, name) + ']\n';
|
|
636
885
|
});
|
|
637
886
|
out += '\n';
|
|
638
|
-
const basis = (jr.providers || []).filter((p) => p.pricedAs && p.pricedAs !== (p.provider + '/' + p.model));
|
|
639
|
-
if (basis.length) {
|
|
640
|
-
out += 'PRICING (free → paid basis' + (jr.priceAsOf ? ', prices as of ' + jr.priceAsOf.slice(0, 10) : '') + ')\n';
|
|
641
|
-
basis.forEach((p) => {
|
|
642
|
-
out += ' ' + pad(p.provider + '/' + p.model, 45) + '→ ' + p.pricedAs + '\n';
|
|
643
|
-
});
|
|
644
|
-
out += '\n';
|
|
645
|
-
}
|
|
646
887
|
}
|
|
647
888
|
if (jr.agents && jr.agents.length) {
|
|
648
889
|
out += 'AGENTS\n';
|
|
649
890
|
jr.agents.forEach((a) => {
|
|
650
|
-
out += ' ' + pad(a.agent, 45) + pad(a.sessions + ' sessions', 14) + ' ' + rpad(
|
|
891
|
+
out += ' ' + pad(a.agent, 45) + pad(a.sessions + ' sessions', 14) + ' ' + rpad(fCost(a.cost), 10) + ' ' + rpad(fT(a.tok_in), 8) + ' in / ' + rpad(fT(a.tok_out), 8) + ' out cache: ' + rpad(fT(a.cache_read), 8) + ' ' + rpad(fmtSpeed(a.speed), 11) + ' wall:' + rpad(fmtDur(a.wallMs), 9) + 'act:' + rpad(fmtDur(a.activeMs), 9) + ' mkt:' + rpad(fCost(a.market), 11) + ' svd:' + rpad(fCost(a.saved), 11) + '\n';
|
|
651
892
|
});
|
|
652
893
|
}
|
|
653
894
|
if (jr.sessions && jr.sessions.length) {
|
|
654
|
-
out += 'SESSIONS (top ' + jr.sessions.length + ' by
|
|
895
|
+
out += 'SESSIONS (top ' + jr.sessions.length + ' by tokens)\n';
|
|
655
896
|
jr.sessions.forEach((s) => {
|
|
656
|
-
out += ' ' + pad(String(s.id).slice(0, 12), 13) + pad((s.title || '').slice(0, 28), 29) + pad(s.agent, 9) + pad((s.provider + '/' + s.model).slice(0, 30), 31) + 'wall:' + rpad(fmtDur(s.wallMs), 9) + 'act:' + rpad(fmtDur(s.activeMs), 9) + rpad(s.messages + 'msgs', 8) + rpad(
|
|
897
|
+
out += ' ' + pad(String(s.id).slice(0, 12), 13) + pad((s.title || '').slice(0, 28), 29) + pad(s.agent, 9) + pad((s.provider + '/' + s.model).slice(0, 30), 31) + 'wall:' + rpad(fmtDur(s.wallMs), 9) + 'act:' + rpad(fmtDur(s.activeMs), 9) + rpad(s.messages + 'msgs', 8) + rpad(fT(s.tok_in), 8) + ' in / ' + rpad(fT(s.tok_out), 8) + ' out ' + rpad(fmtSpeed(s.speed), 11) + ' ' + rpad(fCost(s.cost), 10) + ' mkt:' + rpad(fCost(s.market), 11) + ' svd:' + rpad(fCost(s.saved), 11) + '\n';
|
|
657
898
|
});
|
|
658
899
|
out += '\n';
|
|
659
900
|
}
|
|
660
901
|
return out || 'No data for this period.';
|
|
661
902
|
}
|
|
662
903
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
});
|
|
669
|
-
try {
|
|
670
|
-
const r = await fetch('/api/report?days=' + days + '&_=' + Date.now(), { cache: 'no-store' });
|
|
671
|
-
const j = await r.json();
|
|
672
|
-
if (!j.ok) { $('reportContent').textContent = 'Error'; reportLoading = false; return; }
|
|
673
|
-
if (!j.ready || !j.report) {
|
|
674
|
-
$('reportContent').textContent = '⏳ ' + t('generating') + '…';
|
|
675
|
-
reportRetry++;
|
|
676
|
-
if (reportRetry < MAX_REPORT_RETRIES) {
|
|
677
|
-
const delay = Math.min(1000 * Math.pow(1.5, reportRetry), 15000);
|
|
678
|
-
setTimeout(() => loadReport(days), delay);
|
|
679
|
-
}
|
|
680
|
-
reportLoading = false;
|
|
681
|
-
return;
|
|
682
|
-
}
|
|
683
|
-
reportRetry = 0;
|
|
684
|
-
$('reportContent').innerHTML = renderReportTables(j.report);
|
|
685
|
-
renderReportCharts(j.report);
|
|
686
|
-
} catch (e) {
|
|
687
|
-
$('reportContent').textContent = t('connFail') + ': ' + e.message;
|
|
688
|
-
}
|
|
689
|
-
reportLoading = false;
|
|
690
|
-
}
|
|
904
|
+
// ---- boot ---------------------------------------------------------------
|
|
905
|
+
window.__setScope = setScope; // days = -1 | 1 | 7 | 30
|
|
906
|
+
window.__setTab = setTab;
|
|
907
|
+
window.__renderAll = renderAll;
|
|
908
|
+
window.__lastReport = null;
|
|
691
909
|
|
|
692
910
|
applyI18n();
|
|
693
911
|
restoreSections();
|
|
912
|
+
document.querySelectorAll('#scopeBtns .pill').forEach((el) => {
|
|
913
|
+
el.classList.toggle('active', parseInt(el.dataset.days, 10) === scopeDays);
|
|
914
|
+
});
|
|
915
|
+
renderAll();
|
|
694
916
|
poll();
|
|
695
917
|
setInterval(poll, 15000);
|
|
696
|
-
loadReport(
|
|
697
|
-
// Preload report data for other periods so tab switching is instant.
|
|
698
|
-
// Load with delays to avoid competing with the first poll for bandwidth.
|
|
699
|
-
setTimeout(() => loadReport(7), 1500);
|
|
700
|
-
setTimeout(() => loadReport(30), 3000);
|
|
701
|
-
setTimeout(() => loadReport(-1), 4500);
|
|
918
|
+
loadReport(scopeDays);
|
|
702
919
|
</script>
|
|
703
920
|
</body>
|
|
704
|
-
</html>
|
|
921
|
+
</html>
|