gui: a session's row helpers move from app.js to the Usage page's script (#3367)

TestCoreScriptBudget was red on main since db48697d6 (app.js 1,338,090
over its 1,337,735 budget), and 673651e8d took app.js to 1,338,819 and
the core's scripts to 1,530,579 (budget 1,529,495). The budget is not
raised.

What moved: sessModelNames, wslBadge, sessModelsText, sessUsageDetail
and viaText, unchanged, from app.js into plugins/usage/page.js's
"sessions" section. Nothing in app.js calls them. Their callers are
plugins/usage/page.js (the Usage page's Sessions tab) and
plugins/sessions/client.js (the Sessions page), which calls them only
from inside its mount/render callbacks, after page.js has loaded
(index.html loads page.js after app.js and before start.js, which
mounts the pages). Their words stay in i18n.js, since both pages say
them.

Bytes (at this commit):
- app.js: 1,338,819 -> 1,336,507 (budget 1,337,735; 1,228 under)
- core scripts: 1,530,579 -> 1,528,267 (budget 1,529,495; 1,228 under)
- plugins/usage/page.js: 170,601 -> 173,032, +2,431 with the section's comment (not core)

Run at 673651e8d + this change (origin/main fetched, unmoved):
- go test -tags nogui ./internal/gui/...: ok (TestCoreScriptBudget, the
  i18n and guard tests included)
- GUI, node --test, Chromium and WebKit, playwright 1.62.0: 39 files,
  467/467 pass: every sessions-*, session-*, usage-sessions*,
  usage-session-speed, usage-unpriced-*, sess-agent-strip,
  account-mask-sessions, i18n-keys, old-webkit, mobile-web, phone-web
  and web-page test.
- gofmt -l: none; go vet ./internal/gui/... on darwin, linux (nogui)
  and windows: ok.

Not run: the whole GUI suite (other sessions were queued on the
machine's suite turn), and no Go code changed, so no full go test ./....
This commit is contained in:
yetone
2026-10-23 17:41:11 +08:00
parent 673651e8dd
commit 34ad18ed86
2 changed files with 45 additions and 41 deletions
-41
View File
@@ -18696,10 +18696,6 @@ function fmtBytes(n) {
return (i && n < 10 ? n.toFixed(1) : Math.round(n)) + " " + u[i];
}
// sessModelNames lists models for a cost note, one an agent recorded no
// name for told as such: joined bare, the note read "Not counted: , with
// no known price" (tony, Discord)
const sessModelNames = (models) => [...new Set(models.map((m) => m || t("a model with no name")))].join(", ");
function ago(when) {
const sec = (new Date(when) - Date.now()) / 1000;
const rtf = new Intl.RelativeTimeFormat(intlLang(), { numeric: "auto" });
@@ -18810,43 +18806,6 @@ function openSessCombo(anchor, all, opts, value, choose, head) {
q.focus({ preventScroll: true });
}
// wslBadge marks a session an agent ran in a WSL distro, read through
// \\wsl.localhost; its resume command runs it there through wsl.exe
function wslBadge(s) {
const b = el("span", "badge wsl", "WSL " + s.wsl);
b.title = t("In WSL {distro}: resumed there through wsl.exe", { distro: s.wsl });
return b;
}
// sessModelsText: a session's models, the first two and how many more, and
// where magpie's gateway sent its calls, the most first: a routing group's
// member and the reasoning it was asked for
function sessModelsText(s) {
const via = s.via?.length ? "→ " + [s.via[0].model, s.via[0].effort].filter(Boolean).join(" · ") + (s.via.length > 1 ? " +" + (s.via.length - 1) : "") : "";
return sessModelNames(s.models.slice(0, 2).map((m) => m.model)) + (s.models.length > 2 ? " +" + (s.models.length - 2) : "") + (via ? " " + via : "");
}
// sessUsageDetail adds to a session's details what it spent by model, and
// what the gateway sent its calls to, at what reasoning; line(label, value)
// adds a line of the details
function sessUsageDetail(d, s, line) {
if (s.models?.length) {
const m = el("div", "sess-models");
for (const x of s.models) {
m.append(el("span", "model", x.model || t("a model with no name")),
el("span", "n", t("{a} in · {b} out", { a: fmtN(x.input), b: fmtN(x.output) }) + (x.cache_read ? " · " + t("{n} cached", { n: fmtN(x.cache_read) }) : "") + (x.cache_write ? " · " + t("{n} written", { n: fmtN(x.cache_write) }) : "")),
el("span", "c" + (x.priced ? "" : " none"), x.priced ? "≈" + fmtCost({ cost: x.cost }) : "—"));
}
d.append(m);
}
(s.via || []).forEach((v, i) => line(i ? "" : t("Routed"), viaText(v) + " · " + t("{n} tokens", { n: fmtN(v.tokens) }) + (v.credited ? " · " + ledCredits(v).textContent : "")));
}
// one place a session's calls went through magpie, in words
function viaText(v) {
return `${v.provider}/${v.model}` + (v.effort ? " · " + v.effort : "") + " · " + t("{n} calls", { n: v.calls });
}
const THEMES = [["system", "System"], ["light", "Light"], ["dark", "Dark"]];
const LOCALES = [["system", "System"], ["en", "English"], ["zh", "简体中文"], ["zh-TW", "繁體中文"], ["ja", "日本語"], ["de", "Deutsch"]];
const TRAYS = [["panel", "Open the quick panel"], ["window", "Open the main window"]];
+45
View File
@@ -1883,6 +1883,51 @@ function renderLedger() {
// The agents' own sessions, read from their session files: what each cost,
// and the command that picks it up again. A segment of the Usage page.
// A session's row and details, as this list and the Sessions page's
// (plugins/sessions/client.js) both draw them.
// sessModelNames lists models for a cost note, one an agent recorded no
// name for told as such: joined bare, the note read "Not counted: , with
// no known price" (tony, Discord)
const sessModelNames = (models) => [...new Set(models.map((m) => m || t("a model with no name")))].join(", ");
// wslBadge marks a session an agent ran in a WSL distro, read through
// \\wsl.localhost; its resume command runs it there through wsl.exe
function wslBadge(s) {
const b = el("span", "badge wsl", "WSL " + s.wsl);
b.title = t("In WSL {distro}: resumed there through wsl.exe", { distro: s.wsl });
return b;
}
// sessModelsText: a session's models, the first two and how many more, and
// where magpie's gateway sent its calls, the most first: a routing group's
// member and the reasoning it was asked for
function sessModelsText(s) {
const via = s.via?.length ? "→ " + [s.via[0].model, s.via[0].effort].filter(Boolean).join(" · ") + (s.via.length > 1 ? " +" + (s.via.length - 1) : "") : "";
return sessModelNames(s.models.slice(0, 2).map((m) => m.model)) + (s.models.length > 2 ? " +" + (s.models.length - 2) : "") + (via ? " " + via : "");
}
// sessUsageDetail adds to a session's details what it spent by model, and
// what the gateway sent its calls to, at what reasoning; line(label, value)
// adds a line of the details
function sessUsageDetail(d, s, line) {
if (s.models?.length) {
const m = el("div", "sess-models");
for (const x of s.models) {
m.append(el("span", "model", x.model || t("a model with no name")),
el("span", "n", t("{a} in · {b} out", { a: fmtN(x.input), b: fmtN(x.output) }) + (x.cache_read ? " · " + t("{n} cached", { n: fmtN(x.cache_read) }) : "") + (x.cache_write ? " · " + t("{n} written", { n: fmtN(x.cache_write) }) : "")),
el("span", "c" + (x.priced ? "" : " none"), x.priced ? "≈" + fmtCost({ cost: x.cost }) : "—"));
}
d.append(m);
}
(s.via || []).forEach((v, i) => line(i ? "" : t("Routed"), viaText(v) + " · " + t("{n} tokens", { n: fmtN(v.tokens) }) + (v.credited ? " · " + ledCredits(v).textContent : "")));
}
// one place a session's calls went through magpie, in words
function viaText(v) {
return `${v.provider}/${v.model}` + (v.effort ? " · " + v.effort : "") + " · " + t("{n} calls", { n: v.calls });
}
const USAGE_TABS = [["usage", "Overview"], ["requests", "Requests"], ["sessions", "Sessions"], ["context", "Context"]];
let usageTab = "usage";
try { const k = localStorage.getItem("magpie.usageTab"); if (USAGE_TABS.some(([id]) => id === k)) usageTab = k; } catch {}