magpie-tokentracker 0.2.0 → 0.2.1
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 +1 -1
- package/page/app.js +99 -32
- package/page/board.html +10 -6
- package/page/boot.js +88 -15
- package/page/index.html +7 -0
- package/page/style.css +74 -12
- package/server.mjs +13 -1
package/package.json
CHANGED
package/page/app.js
CHANGED
|
@@ -25,7 +25,9 @@
|
|
|
25
25
|
title: "TokenTracker 用量",
|
|
26
26
|
sub: "本机 TokenTracker 追踪的 token 与花费",
|
|
27
27
|
today: "今天", d7: "7 天", d30: "30 天",
|
|
28
|
-
refresh: "刷新", cloud: "
|
|
28
|
+
refresh: "刷新", cloud: "云同步",
|
|
29
|
+
cloudHint: "官方账号登录、云同步和排行榜",
|
|
30
|
+
cloudOpenBlocked: "这个窗口打不开外链。直接跳过去会变成白屏,也回不来。把下面的地址复制到浏览器打开,看板留在这里。",
|
|
29
31
|
tokens: "总 Token", cost: "花费", cache: "缓存读取", sessions: "会话",
|
|
30
32
|
input: "输入", output: "输出", cacheWrite: "缓存写入", cacheRead: "缓存读取",
|
|
31
33
|
perSession: "均 / 会话", cacheHit: "命中率", sessionsHint: "有用量的会话",
|
|
@@ -58,6 +60,8 @@
|
|
|
58
60
|
sub: "Token usage and cost tracked by the local TokenTracker",
|
|
59
61
|
today: "Today", d7: "7 days", d30: "30 days",
|
|
60
62
|
refresh: "Refresh", cloud: "Cloud",
|
|
63
|
+
cloudHint: "Official account, cloud sync, and the leaderboard",
|
|
64
|
+
cloudOpenBlocked: "This window can't open outside links. Leaving this page turns it into a blank screen with no way back. Copy the address below into a browser. This board stays here.",
|
|
61
65
|
tokens: "Total tokens", cost: "Cost", cache: "Cache read", sessions: "Sessions",
|
|
62
66
|
input: "input", output: "output", cacheWrite: "cache write", cacheRead: "cache read",
|
|
63
67
|
perSession: "avg / session", cacheHit: "hit rate", sessionsHint: "sessions with usage",
|
|
@@ -89,10 +93,21 @@
|
|
|
89
93
|
const T = TEXT[lang];
|
|
90
94
|
|
|
91
95
|
const $ = (id) => document.getElementById(id);
|
|
96
|
+
// magpie 的页面 frame 是 sandbox="allow-scripts"(opaque origin):裸碰 localStorage
|
|
97
|
+
// 直接抛 SecurityError,会炸掉整个脚本、页面停在骨架屏。包一层降级成无记忆,
|
|
98
|
+
// 代价只是沙盒里记不住上次选的周期。
|
|
99
|
+
const store = {
|
|
100
|
+
get(key) {
|
|
101
|
+
try { return localStorage.getItem(key); } catch { return null; }
|
|
102
|
+
},
|
|
103
|
+
set(key, value) {
|
|
104
|
+
try { localStorage.setItem(key, value); } catch { /* opaque origin:放弃记忆 */ }
|
|
105
|
+
},
|
|
106
|
+
};
|
|
92
107
|
const PERIODS = ["today", "7d", "30d"];
|
|
93
108
|
// URL ?period= 优先(boot/分享链接直达),其次记住的选择,默认「今天」。
|
|
94
109
|
const periodParam = params.get("period");
|
|
95
|
-
const savedPeriod =
|
|
110
|
+
const savedPeriod = store.get("magpie-tokentracker-period");
|
|
96
111
|
const state = {
|
|
97
112
|
period: PERIODS.includes(periodParam) ? periodParam : PERIODS.includes(savedPeriod) ? savedPeriod : "today",
|
|
98
113
|
data: null,
|
|
@@ -165,7 +180,9 @@
|
|
|
165
180
|
$("title").textContent = T.title;
|
|
166
181
|
$("sub").textContent = T.sub;
|
|
167
182
|
$("refresh").textContent = T.refresh;
|
|
168
|
-
|
|
183
|
+
$("cloud-btn").textContent = T.cloud;
|
|
184
|
+
$("cloud-btn").title = T.cloudHint;
|
|
185
|
+
$("cloud-open-text").textContent = T.cloudOpenBlocked;
|
|
169
186
|
$("offline-title").textContent = T.offlineTitle;
|
|
170
187
|
$("offline-text").textContent = T.offlineText;
|
|
171
188
|
$("offline-retry").textContent = T.offlineRetry;
|
|
@@ -220,35 +237,63 @@
|
|
|
220
237
|
}
|
|
221
238
|
const max = Math.max(...points.map((p) => p.tokens), 1);
|
|
222
239
|
$("trend-hint").textContent = fmtTokens(points.reduce((s, p) => s + p.tokens, 0));
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
|
|
240
|
+
// 刻度最多 10 个:24 小时的每小时图只标每 3 小时(标签只写小时数),30 天的图也只标每 3 天。
|
|
241
|
+
const every = Math.max(1, Math.ceil(points.length / 10));
|
|
242
|
+
const hourly = series && series.kind === "hourly";
|
|
243
|
+
const tick = (p) => (hourly ? String(Number(String(p.label).split(":")[0]) || 0) : p.label);
|
|
244
|
+
// 纵轴:0 / 一半 / 最高,横线对齐刻度,柱子高度只按绘图区算。
|
|
245
|
+
const yTicks = [
|
|
246
|
+
{ pct: 100, value: max },
|
|
247
|
+
{ pct: 50, value: max / 2 },
|
|
248
|
+
{ pct: 0, value: 0 },
|
|
249
|
+
];
|
|
250
|
+
el.innerHTML = `<div class="chart-wrap">
|
|
251
|
+
<div class="chart-y">${yTicks
|
|
252
|
+
.map((t) => `<span style="bottom:${t.pct}%">${escapeHtml(fmtTokens(t.value))}</span>`)
|
|
253
|
+
.join("")}</div>
|
|
254
|
+
<div class="chart-plot">
|
|
255
|
+
${yTicks.map((t) => `<span class="chart-line${t.pct ? "" : " is-base"}" style="bottom:${t.pct}%"></span>`).join("")}
|
|
256
|
+
<div class="chart-bars">${points
|
|
257
|
+
.map((p, i) => {
|
|
258
|
+
const h = Math.max(p.tokens ? 3 : 0, Math.round((p.tokens / max) * 100));
|
|
259
|
+
const show = i % every === 0;
|
|
260
|
+
return `<div class="col" title="${escapeHtml(p.label)} · ${escapeHtml(fmtTokens(p.tokens))}">
|
|
261
|
+
<span class="col-bar" style="height:${h}%"></span>
|
|
262
|
+
<span class="col-label${show ? "" : " is-blank"}">${escapeHtml(show ? tick(p) : "")}</span>
|
|
263
|
+
</div>`;
|
|
264
|
+
})
|
|
265
|
+
.join("")}</div>
|
|
266
|
+
</div>
|
|
267
|
+
</div>`;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// /api/usage 透传 TokenTracker 的字段名(input/output/cacheRead/cacheHitRate/conversations),
|
|
271
|
+
// 这里两个名字都认,免得版本差异让卡片掉成 0。
|
|
272
|
+
function pick(...values) {
|
|
273
|
+
for (const value of values) if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
274
|
+
return 0;
|
|
232
275
|
}
|
|
233
276
|
|
|
234
277
|
function render(data) {
|
|
235
278
|
const c = data.cards;
|
|
279
|
+
const input = pick(c.inputTokens, c.input);
|
|
280
|
+
const output = pick(c.outputTokens, c.output);
|
|
281
|
+
const cacheRead = pick(c.cacheReadTokens, c.cacheRead);
|
|
282
|
+
const cacheWrite = pick(c.cacheWriteTokens, c.cacheWrite);
|
|
283
|
+
const cacheHitRatio = pick(c.cacheHitRatio, c.cacheHitRate);
|
|
284
|
+
const sessions = pick(c.sessions, c.conversations);
|
|
236
285
|
$("v-tokens").textContent = fmtTokens(c.tokens);
|
|
237
|
-
$("m-tokens").textContent = `${T.input} ${fmtTokens(
|
|
286
|
+
$("m-tokens").textContent = `${T.input} ${fmtTokens(input)} · ${T.output} ${fmtTokens(output)}`;
|
|
238
287
|
$("v-cost").textContent = fmtCost(c.costUsd);
|
|
239
|
-
$("m-cost").textContent =
|
|
240
|
-
$("v-cache").textContent = fmtTokens(
|
|
241
|
-
$("m-cache").textContent = `${T.cacheHit} ${fmtPct(
|
|
242
|
-
$("v-sessions").textContent = fmtInt(
|
|
288
|
+
$("m-cost").textContent = sessions ? `${fmtCost(c.costUsd / sessions)} ${T.perSession}` : "";
|
|
289
|
+
$("v-cache").textContent = fmtTokens(cacheRead);
|
|
290
|
+
$("m-cache").textContent = `${T.cacheHit} ${fmtPct(cacheHitRatio)} · ${T.cacheWrite} ${fmtTokens(cacheWrite)}`;
|
|
291
|
+
$("v-sessions").textContent = fmtInt(sessions);
|
|
243
292
|
$("m-sessions").textContent = T.sessionsHint;
|
|
244
293
|
|
|
245
|
-
renderBars("source-bars", data.sources, (r) => r.tokens, (r) => r.name);
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
data.models,
|
|
249
|
-
(r) => r.tokens,
|
|
250
|
-
(r) => r.name,
|
|
251
|
-
);
|
|
294
|
+
renderBars("source-bars", data.sources, (r) => r.tokens, (r) => r.name || r.id);
|
|
295
|
+
// 接口给的是模型 id(如 smart-split、glm-5.3-flash),没有 name;不兜底就只剩空条。
|
|
296
|
+
renderBars("model-bars", data.models, (r) => r.tokens, (r) => r.name || r.id);
|
|
252
297
|
renderChart(data.series);
|
|
253
298
|
|
|
254
299
|
const tt = data.tokentracker || {};
|
|
@@ -380,7 +425,24 @@
|
|
|
380
425
|
|
|
381
426
|
// 沙盒 frame 里外链用 location.href 导航,不用 window.open。
|
|
382
427
|
function go(url) {
|
|
383
|
-
if (url)
|
|
428
|
+
if (!url) return;
|
|
429
|
+
// 沙盒 frame 通常没有弹窗权限,window.open 返回 null。
|
|
430
|
+
// 绝不能 location.href:那会把看板整页换成外链。7680 没起来就是白屏,而且没有返回。
|
|
431
|
+
let popup = null;
|
|
432
|
+
try {
|
|
433
|
+
popup = window.open(url, "_blank", "noopener,noreferrer");
|
|
434
|
+
} catch {
|
|
435
|
+
popup = null;
|
|
436
|
+
}
|
|
437
|
+
if (popup) return;
|
|
438
|
+
const box = $("cloud-open");
|
|
439
|
+
const input = $("cloud-open-url");
|
|
440
|
+
if (!box || !input) return;
|
|
441
|
+
input.value = url;
|
|
442
|
+
box.hidden = false;
|
|
443
|
+
box.scrollIntoView({ block: "nearest" });
|
|
444
|
+
input.focus();
|
|
445
|
+
input.select();
|
|
384
446
|
}
|
|
385
447
|
|
|
386
448
|
function renderCloud(data) {
|
|
@@ -473,7 +535,7 @@
|
|
|
473
535
|
|
|
474
536
|
function selectPeriod(period) {
|
|
475
537
|
state.period = period;
|
|
476
|
-
|
|
538
|
+
store.set("magpie-tokentracker-period", period);
|
|
477
539
|
document.querySelectorAll("#periods button").forEach((b) => {
|
|
478
540
|
b.setAttribute("aria-selected", String(b.dataset.period === period));
|
|
479
541
|
});
|
|
@@ -485,13 +547,16 @@
|
|
|
485
547
|
const open = panel.hidden;
|
|
486
548
|
panel.hidden = !open;
|
|
487
549
|
$("cloud-btn").setAttribute("aria-expanded", String(open));
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
550
|
+
$("cloud-btn").classList.toggle("is-on", open);
|
|
551
|
+
if (!open) return;
|
|
552
|
+
if (cloud.data) renderCloud(cloud.data);
|
|
553
|
+
else {
|
|
554
|
+
$("cloud-body").innerHTML = `<p class="empty">${escapeHtml(T.loading)}</p>`;
|
|
555
|
+
loadCloud();
|
|
494
556
|
}
|
|
557
|
+
// 面板在头部下面。视口被滚到底时点「云同步」看不到它,会以为按钮没反应。
|
|
558
|
+
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
559
|
+
panel.scrollIntoView({ block: "nearest" });
|
|
495
560
|
}
|
|
496
561
|
|
|
497
562
|
function startTimer() {
|
|
@@ -513,6 +578,8 @@
|
|
|
513
578
|
load({ force: true });
|
|
514
579
|
for (const name of Object.keys(panels)) loadPanel(name, { force: true });
|
|
515
580
|
});
|
|
581
|
+
// 重载走 magpie 页面右上角的 ⟳。以前这里有个「← 返回插件页」,它只是让 frame
|
|
582
|
+
// 回退一页再自动跳回来,等于重新加载,和 ⟳ 重复,看着像没反应,已删掉。
|
|
516
583
|
$("cloud-btn").addEventListener("click", toggleCloud);
|
|
517
584
|
$("offline-retry").addEventListener("click", () => load({ force: true }));
|
|
518
585
|
document.addEventListener("visibilitychange", () => {
|
package/page/board.html
CHANGED
|
@@ -24,10 +24,19 @@
|
|
|
24
24
|
<button type="button" role="tab" data-period="30d" aria-selected="false">30 天</button>
|
|
25
25
|
</div>
|
|
26
26
|
<button type="button" id="refresh" class="ghost">刷新</button>
|
|
27
|
-
<button type="button" id="cloud-btn" class="ghost" aria-expanded="false" aria-controls="cloud-panel"
|
|
27
|
+
<button type="button" id="cloud-btn" class="ghost" aria-expanded="false" aria-controls="cloud-panel" title="官方账号登录、云同步和排行榜">云同步</button>
|
|
28
28
|
</div>
|
|
29
29
|
</header>
|
|
30
30
|
|
|
31
|
+
<section class="panel wide" id="cloud-panel" hidden>
|
|
32
|
+
<header class="panel-head"><h2 id="cloud-title"></h2></header>
|
|
33
|
+
<div id="cloud-body"></div>
|
|
34
|
+
<div id="cloud-open" class="cloud-open" hidden>
|
|
35
|
+
<p id="cloud-open-text"></p>
|
|
36
|
+
<input id="cloud-open-url" type="text" readonly spellcheck="false">
|
|
37
|
+
</div>
|
|
38
|
+
</section>
|
|
39
|
+
|
|
31
40
|
<section class="cards" id="cards">
|
|
32
41
|
<article class="card" id="card-tokens">
|
|
33
42
|
<p class="card-label" data-k="tokens"></p>
|
|
@@ -88,11 +97,6 @@
|
|
|
88
97
|
<div class="badges" id="badge-rows"></div>
|
|
89
98
|
</section>
|
|
90
99
|
|
|
91
|
-
<section class="panel wide" id="cloud-panel" hidden>
|
|
92
|
-
<header class="panel-head"><h2 id="cloud-title"></h2></header>
|
|
93
|
-
<div id="cloud-body"></div>
|
|
94
|
-
</section>
|
|
95
|
-
|
|
96
100
|
<section class="panel offline" id="offline" hidden>
|
|
97
101
|
<h2 id="offline-title"></h2>
|
|
98
102
|
<p id="offline-text"></p>
|
package/page/boot.js
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
//
|
|
3
3
|
// 优先用 window.magpie.service(magpie web 在自己域名下转发),桌面窗口没有它,
|
|
4
4
|
// 回退 http://127.0.0.1:<port>/。端口从插件选项读,跟服务启动时用的是同一个值。
|
|
5
|
-
//
|
|
5
|
+
//
|
|
6
|
+
// 探活只在 service 转发模式(magpie web)下做:那是同源请求,结果可信。
|
|
7
|
+
// 桌面窗口的带路页 CSP 会把跨源 fetch 和 <script> 全部拦掉(0.1.4345 实测),
|
|
8
|
+
// 双失败和服务真死无法区分——在桌面版里做跨源探测只会把活服务误判成死服务,
|
|
9
|
+
// 所以桌面版保持原来的直接跳转:跳转本身就是最快的验证。
|
|
6
10
|
(async () => {
|
|
7
11
|
const DEFAULT_PORT = 3491;
|
|
8
12
|
const words = {
|
|
@@ -11,16 +15,24 @@
|
|
|
11
15
|
bridging: "正在连接宿主桥接…",
|
|
12
16
|
err: (m) => `桥接未响应:${m} —— 直接打开本机看板…`,
|
|
13
17
|
nobridge: "未检测到宿主桥接,直接打开本机看板…",
|
|
18
|
+
probing: "正在检查看板服务…",
|
|
14
19
|
ready: "已定位看板服务,正在跳转…",
|
|
15
20
|
readyLocal: "已就绪,正在打开本机看板…",
|
|
21
|
+
down: "看板服务没有启动:重启 magpie 后再试,或点下面的重试。",
|
|
22
|
+
retrying: "正在重试…",
|
|
23
|
+
retry: "重试",
|
|
16
24
|
},
|
|
17
25
|
en: {
|
|
18
26
|
title: "TokenTracker",
|
|
19
27
|
bridging: "Connecting to the host bridge…",
|
|
20
28
|
err: (m) => `Bridge did not respond: ${m} — opening the local board…`,
|
|
21
29
|
nobridge: "No host bridge detected — opening the local board…",
|
|
30
|
+
probing: "Checking the board service…",
|
|
22
31
|
ready: "Board located, navigating…",
|
|
23
32
|
readyLocal: "Ready — opening the local board…",
|
|
33
|
+
down: "The board service is not running. Restart magpie and try again, or click retry.",
|
|
34
|
+
retrying: "Retrying…",
|
|
35
|
+
retry: "Retry",
|
|
24
36
|
},
|
|
25
37
|
};
|
|
26
38
|
let lang = String(navigator.language || "en").toLowerCase().startsWith("zh") ? "zh" : "en";
|
|
@@ -34,7 +46,6 @@
|
|
|
34
46
|
msg.classList.toggle("bad", !!bad);
|
|
35
47
|
};
|
|
36
48
|
const setBar = (pct, bad) => {
|
|
37
|
-
if (!bar) return;
|
|
38
49
|
bar.style.width = pct + "%";
|
|
39
50
|
if (bar.parentElement) bar.parentElement.classList.toggle("bad", !!bad);
|
|
40
51
|
};
|
|
@@ -82,23 +93,85 @@
|
|
|
82
93
|
say(w.nobridge);
|
|
83
94
|
} else {
|
|
84
95
|
setBar(72);
|
|
85
|
-
say(
|
|
96
|
+
say(w.probing);
|
|
86
97
|
}
|
|
87
98
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
99
|
+
const base = service || `http://127.0.0.1:${port}`;
|
|
100
|
+
|
|
101
|
+
// 探活:只该在 service 转发模式(同源,结果可信)下调用。
|
|
102
|
+
async function probeService(root) {
|
|
103
|
+
try {
|
|
104
|
+
const ctrl = new AbortController();
|
|
105
|
+
const timer = setTimeout(() => ctrl.abort(), 2500);
|
|
106
|
+
const res = await fetch(`${root}/api/healthz`, { signal: ctrl.signal, cache: "no-store" });
|
|
107
|
+
clearTimeout(timer);
|
|
108
|
+
if (res.ok) return true;
|
|
109
|
+
} catch {
|
|
110
|
+
// 转发路径也不通
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function addRetry(onRetry) {
|
|
116
|
+
if (document.querySelector(".box button")) return;
|
|
117
|
+
const btn = document.createElement("button");
|
|
118
|
+
btn.type = "button";
|
|
119
|
+
btn.textContent = w.retry;
|
|
120
|
+
btn.addEventListener("click", async () => {
|
|
121
|
+
btn.disabled = true;
|
|
122
|
+
say(w.retrying);
|
|
123
|
+
const ok = await probeService(base);
|
|
124
|
+
if (ok === false) {
|
|
125
|
+
btn.disabled = false;
|
|
126
|
+
say(w.down, true);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
onRetry();
|
|
130
|
+
});
|
|
131
|
+
(document.querySelector(".box") || document.body).appendChild(btn);
|
|
96
132
|
}
|
|
97
|
-
|
|
133
|
+
|
|
134
|
+
function gotoBoard() {
|
|
135
|
+
let target = service || `${base}/`;
|
|
98
136
|
try {
|
|
99
|
-
location.
|
|
137
|
+
const u = new URL(target, location.href);
|
|
138
|
+
u.searchParams.set("lang", lang);
|
|
139
|
+
if (theme) u.searchParams.set("theme", theme);
|
|
140
|
+
target = u.href;
|
|
100
141
|
} catch {
|
|
101
|
-
|
|
142
|
+
target += (target.includes("?") ? "&" : "?") + "lang=" + lang + (theme ? "&theme=" + theme : "");
|
|
143
|
+
}
|
|
144
|
+
setBar(96);
|
|
145
|
+
say(service ? w.ready : w.readyLocal);
|
|
146
|
+
setTimeout(() => {
|
|
147
|
+
try {
|
|
148
|
+
// assign 而不是 replace:看板页因此能 history.back() 回到这一页,
|
|
149
|
+
// 「跳过去就白屏、回不来」是上一版的事故。
|
|
150
|
+
location.assign(target);
|
|
151
|
+
} catch {
|
|
152
|
+
// 下面的 meta refresh 兜底
|
|
153
|
+
}
|
|
154
|
+
}, 200);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (bridgeError) {
|
|
158
|
+
// 桥接都没握上:保留原行为,直接跳,让目标侧自己兜底。
|
|
159
|
+
gotoBoard();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (service) {
|
|
164
|
+
// magpie.web:转发是同源请求,探活结果可信,失败再拦。
|
|
165
|
+
say(w.probing);
|
|
166
|
+
setBar(84);
|
|
167
|
+
const alive = await probeService(service);
|
|
168
|
+
if (alive === false) {
|
|
169
|
+
setBar(100, true);
|
|
170
|
+
say(w.down, true);
|
|
171
|
+
addRetry(gotoBoard);
|
|
172
|
+
return;
|
|
102
173
|
}
|
|
103
|
-
}
|
|
174
|
+
}
|
|
175
|
+
// 桌面窗口:跨源探测会被 CSP 全拦、与服务真死无法区分,直接跳转。
|
|
176
|
+
gotoBoard();
|
|
104
177
|
})();
|
package/page/index.html
CHANGED
|
@@ -19,6 +19,13 @@
|
|
|
19
19
|
.bar.bad i { background: #f85149; }
|
|
20
20
|
.box span { display: block; font-size: 11.5px; min-height: 2.4em; }
|
|
21
21
|
.box span.bad { color: #f85149; }
|
|
22
|
+
.box button {
|
|
23
|
+
margin-top: 10px; padding: 4px 16px; font: inherit; border-radius: 6px;
|
|
24
|
+
border: 1px solid color-mix(in srgb, CanvasText 30%, transparent);
|
|
25
|
+
background: transparent; color: CanvasText; cursor: pointer;
|
|
26
|
+
}
|
|
27
|
+
.box button:hover { background: color-mix(in srgb, CanvasText 10%, transparent); }
|
|
28
|
+
.box button[disabled] { opacity: .5; cursor: default; }
|
|
22
29
|
</style>
|
|
23
30
|
</head>
|
|
24
31
|
<body>
|
package/page/style.css
CHANGED
|
@@ -68,12 +68,12 @@ body {
|
|
|
68
68
|
display: flex;
|
|
69
69
|
align-items: center;
|
|
70
70
|
justify-content: space-between;
|
|
71
|
-
gap:
|
|
72
|
-
flex-wrap:
|
|
71
|
+
gap: 12px;
|
|
72
|
+
flex-wrap: nowrap; /* 标题和这排按钮要同一行,窄了只收标题 */
|
|
73
73
|
margin-bottom: 18px;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
.brand { display: flex; align-items: center; gap:
|
|
76
|
+
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
|
|
77
77
|
|
|
78
78
|
.status {
|
|
79
79
|
width: 10px;
|
|
@@ -85,10 +85,17 @@ body {
|
|
|
85
85
|
.status[data-state="ok"] { background: var(--brand); }
|
|
86
86
|
.status[data-state="bad"] { background: var(--danger); }
|
|
87
87
|
|
|
88
|
-
.titles
|
|
89
|
-
.titles
|
|
88
|
+
.titles { min-width: 0; }
|
|
89
|
+
.titles h1 {
|
|
90
|
+
margin: 0; font-size: 18px; font-weight: 650; letter-spacing: -0.01em;
|
|
91
|
+
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
|
92
|
+
}
|
|
93
|
+
.titles p {
|
|
94
|
+
margin: 1px 0 0; color: var(--muted); font-size: 12.5px;
|
|
95
|
+
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
|
96
|
+
}
|
|
90
97
|
|
|
91
|
-
.actions { display: flex; align-items: center; gap: 8px; flex-wrap:
|
|
98
|
+
.actions { display: flex; align-items: center; gap: 8px; flex: none; flex-wrap: nowrap; }
|
|
92
99
|
|
|
93
100
|
.segmented {
|
|
94
101
|
display: flex;
|
|
@@ -127,6 +134,11 @@ button.ghost {
|
|
|
127
134
|
}
|
|
128
135
|
button.ghost:hover { border-color: var(--muted); }
|
|
129
136
|
button.ghost:disabled { opacity: 0.55; cursor: default; }
|
|
137
|
+
button.ghost.is-on {
|
|
138
|
+
border-color: var(--accent);
|
|
139
|
+
color: var(--accent);
|
|
140
|
+
font-weight: 600;
|
|
141
|
+
}
|
|
130
142
|
|
|
131
143
|
button.link {
|
|
132
144
|
appearance: none;
|
|
@@ -232,19 +244,44 @@ button.link {
|
|
|
232
244
|
|
|
233
245
|
/* ---------- 趋势柱 ---------- */
|
|
234
246
|
|
|
247
|
+
/* 纵轴和横轴分开摆:柱子高度只按绘图区算,标签绝对定位,不占柱子的百分比基准。 */
|
|
248
|
+
.chart-wrap { display: grid; grid-template-columns: 46px 1fr; gap: 4px; }
|
|
249
|
+
|
|
250
|
+
.chart-y { position: relative; height: 150px; }
|
|
251
|
+
.chart-y span {
|
|
252
|
+
position: absolute;
|
|
253
|
+
right: 0;
|
|
254
|
+
transform: translateY(50%);
|
|
255
|
+
font-size: 10px;
|
|
256
|
+
color: var(--muted);
|
|
257
|
+
font-variant-numeric: tabular-nums;
|
|
258
|
+
white-space: nowrap;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.chart-plot { position: relative; height: 150px; margin-bottom: 18px; }
|
|
262
|
+
.chart-line {
|
|
263
|
+
position: absolute;
|
|
264
|
+
left: 0;
|
|
265
|
+
right: 0;
|
|
266
|
+
border-top: 1px solid var(--line);
|
|
267
|
+
pointer-events: none;
|
|
268
|
+
}
|
|
269
|
+
.chart-line.is-base { border-top-color: var(--muted); opacity: 0.55; }
|
|
270
|
+
|
|
235
271
|
.chart-bars {
|
|
272
|
+
position: absolute;
|
|
273
|
+
inset: 0;
|
|
236
274
|
display: grid;
|
|
237
275
|
grid-auto-flow: column;
|
|
238
276
|
grid-auto-columns: 1fr;
|
|
239
277
|
align-items: end;
|
|
240
278
|
gap: 4px;
|
|
241
|
-
height: 150px;
|
|
242
279
|
}
|
|
243
280
|
.col {
|
|
281
|
+
position: relative;
|
|
244
282
|
display: flex;
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
justify-content: flex-end;
|
|
283
|
+
align-items: flex-end;
|
|
284
|
+
justify-content: center;
|
|
248
285
|
height: 100%;
|
|
249
286
|
min-width: 0;
|
|
250
287
|
}
|
|
@@ -256,11 +293,15 @@ button.link {
|
|
|
256
293
|
background: linear-gradient(180deg, var(--brand), var(--brand-deep));
|
|
257
294
|
}
|
|
258
295
|
.col-label {
|
|
259
|
-
|
|
296
|
+
position: absolute;
|
|
297
|
+
bottom: -16px;
|
|
298
|
+
left: 50%;
|
|
299
|
+
transform: translateX(-50%);
|
|
260
300
|
font-size: 10px;
|
|
261
|
-
color: var(--muted);
|
|
262
301
|
white-space: nowrap;
|
|
302
|
+
color: var(--muted);
|
|
263
303
|
}
|
|
304
|
+
.col-label.is-blank { visibility: hidden; }
|
|
264
305
|
|
|
265
306
|
/* ---------- 配额 ---------- */
|
|
266
307
|
|
|
@@ -385,6 +426,22 @@ progress.quota-bar::-moz-progress-bar {
|
|
|
385
426
|
font-size: 12.5px;
|
|
386
427
|
}
|
|
387
428
|
.cloud-fine { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
|
|
429
|
+
.cloud-open {
|
|
430
|
+
margin-top: 12px;
|
|
431
|
+
padding-top: 12px;
|
|
432
|
+
border-top: 1px solid var(--line);
|
|
433
|
+
}
|
|
434
|
+
.cloud-open p { margin: 0 0 8px; color: var(--warn); font-size: 13px; }
|
|
435
|
+
.cloud-open input {
|
|
436
|
+
width: 100%;
|
|
437
|
+
box-sizing: border-box;
|
|
438
|
+
padding: 8px 10px;
|
|
439
|
+
border: 1px solid var(--line);
|
|
440
|
+
border-radius: 8px;
|
|
441
|
+
background: var(--surface-2);
|
|
442
|
+
color: var(--fg);
|
|
443
|
+
font: 13px/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
|
|
444
|
+
}
|
|
388
445
|
|
|
389
446
|
/* ---------- 离线 ---------- */
|
|
390
447
|
|
|
@@ -413,6 +470,11 @@ body.offline #trend { display: none; }
|
|
|
413
470
|
|
|
414
471
|
@media (max-width: 720px) {
|
|
415
472
|
.page { padding: 14px 12px 24px; }
|
|
473
|
+
.top { gap: 8px; }
|
|
474
|
+
.brand { gap: 8px; }
|
|
475
|
+
.titles h1 { font-size: 16px; }
|
|
476
|
+
.titles p { display: none; } /* 一行放不下时先让副标题让位 */
|
|
477
|
+
.actions { gap: 6px; }
|
|
416
478
|
.cards { grid-template-columns: 1fr 1fr; }
|
|
417
479
|
.grid { grid-template-columns: 1fr; }
|
|
418
480
|
.quotas { grid-template-columns: 1fr; }
|
package/server.mjs
CHANGED
|
@@ -28,7 +28,7 @@ import { apiGet, ensureRunning, probe, resolvePort, baseUrl } from "./lib/tokent
|
|
|
28
28
|
|
|
29
29
|
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
30
30
|
const SERVICE_NAME = "magpie-tokentracker";
|
|
31
|
-
const BUILD =
|
|
31
|
+
const BUILD = 6; // 服务行为变了就 +1:端口被占时老 build 不复用,等它退
|
|
32
32
|
const REBIND_MS = 20000; // magpie 自升级交接时旧宿主几秒内退出,等它即可
|
|
33
33
|
const REBIND_STEP_MS = 1000;
|
|
34
34
|
const PAGE_DIR = path.join(HERE, "page");
|
|
@@ -486,6 +486,18 @@ export async function startServer(rawOptions = {}) {
|
|
|
486
486
|
|
|
487
487
|
if (route === "/api/healthz") {
|
|
488
488
|
// 指纹给「端口被占时复用还是等它退」的判定用
|
|
489
|
+
if (url.searchParams.has("probe")) {
|
|
490
|
+
// 带路页的跨源 <script> 探测:nosniff 会严格校验 MIME,返回 JSON 会被拦成
|
|
491
|
+
// onerror(与连接拒绝不可区分),所以这里回一段合法 JS 让 onload 干净触发。
|
|
492
|
+
const body = "true;/* magpie-tokentracker healthz */";
|
|
493
|
+
res.writeHead(200, {
|
|
494
|
+
"Content-Type": "text/javascript; charset=utf-8",
|
|
495
|
+
"Cache-Control": "no-store",
|
|
496
|
+
"Content-Length": Buffer.byteLength(body),
|
|
497
|
+
});
|
|
498
|
+
res.end(body);
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
489
501
|
json(res, 200, { ok: true, service: SERVICE_NAME, build: BUILD });
|
|
490
502
|
return;
|
|
491
503
|
}
|