gui: a subscription with several accounts shows one of them on Usage and in the tray panel, the others behind "Show N more accounts" (whqtian on Discord: 我这个workbuddy只有4个账号,其实大多数情况下,我不需要显示全部的账号信息,你只要显示一个账号信息即可,其他的可以点击展开再看) — every provider's card listed each account's meters, credits and curve one under another, so four WorkBuddy accounts took the page. Now a card with several accounts shows the one that answered through the gateway last (lastServedAt), else the first, with "Show 3 more accounts" / 展开其余 3 个账号 under it; opened, all are shown in their order with "Show fewer accounts" / 收起其余账号. Opened is remembered by provider (localStorage magpie.usageOpen), for the window and the tray panel alike, each following the other as it is turned; a provider with one account has no button. The folded accounts stay in the page, hidden, so Hide accounts masks them as before; the line between accounts is drawn only after one in sight. The click keeps the page where it is (backToReader). usage-fold.test.cjs (WebKit, en and zh: 4 accounts show the last-served one and the button, opening shows all without moving the page, remembered after a reload, one account has no button, masking covers them, the panel folds the same and the window follows it) fails on the old code and passes; quota-families and quota-pools open the panel's second Antigravity account first. account-mask, quota-curve, click-scroll, mask-emails, credit-days, balance-parts, usage-arrange, panel-usage, tray-usages and usage-accounts pass; the GUI tests failing here fail the same on origin/main. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass.
This commit is contained in:
@@ -514,11 +514,11 @@ body.window .field.solo { grid-column: auto; }
|
||||
.subscription-head .ic { width: 17px; height: 17px; }
|
||||
.subscription-head b { font-size: 12.5px; font-weight: 600; }
|
||||
.subscription-account { display: flex; align-items: baseline; gap: 7px; margin: 0 0 6px; font-size: 11px; color: var(--fg-2); }
|
||||
.subscription-card.several .quota-windows + .subscription-account,
|
||||
.subscription-card.several .subscription-error + .subscription-account,
|
||||
.subscription-card.several .quota-balance + .subscription-account,
|
||||
.subscription-card.several .quota-read + .subscription-account,
|
||||
.subscription-card.several .credit-days + .subscription-account { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--line); }
|
||||
.subscription-card.several .quota-windows:not([hidden]) + .subscription-account,
|
||||
.subscription-card.several .subscription-error:not([hidden]) + .subscription-account,
|
||||
.subscription-card.several .quota-balance:not([hidden]) + .subscription-account,
|
||||
.subscription-card.several .quota-read:not([hidden]) + .subscription-account,
|
||||
.subscription-card.several .credit-days:not([hidden]) + .subscription-account { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--line); }
|
||||
.subscription-account .user { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.subscription-account .plan { margin-left: auto; flex: none; font-size: 10.5px; color: var(--muted); text-transform: capitalize; }
|
||||
.subscription-head .plan { margin-left: auto; font-size: 10.5px; color: var(--muted); text-transform: capitalize; }
|
||||
@@ -571,7 +571,7 @@ body.window .field.solo { grid-column: auto; }
|
||||
.qc-key b { color: var(--fg-2); font-weight: 600; font-variant-numeric: tabular-nums; }
|
||||
.quota-resets { display: flex; align-items: center; gap: 8px; margin-top: 9px; font-size: 10.5px; font-variant-numeric: tabular-nums; }
|
||||
.quota-resets .text { margin-left: auto; flex: none; font-size: 11px; padding: 2px 7px; }
|
||||
.subscription-card.several .quota-resets + .subscription-account { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--line); }
|
||||
.subscription-card.several .quota-resets:not([hidden]) + .subscription-account { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--line); }
|
||||
.reset-ask .reset-idle { color: var(--amber); }
|
||||
.quota-balance { display: flex; align-items: baseline; gap: 6px; font-size: 10.5px; color: var(--muted); }
|
||||
.quota-windows + .quota-balance { margin-top: 9px; }
|
||||
@@ -1142,6 +1142,8 @@ body.panel .profiles #save { height: 25px; } /* the field's: the line keeps its
|
||||
/* used or left: a quiet pill at the right, over the rings; lit a moment
|
||||
when it turns */
|
||||
.pq-mode { flex: none; margin-left: auto; height: 15px; padding: 0 6px; border-radius: 999px; background: color-mix(in srgb, var(--fg) 7%, transparent); color: var(--muted); font-size: 9.5px; font-weight: 600; line-height: 15px; letter-spacing: .04em; text-transform: uppercase; transition: background .12s, color .12s; }
|
||||
.pq-more { align-self: flex-start; height: 20px; padding: 0 8px; border-radius: 999px; background: color-mix(in srgb, var(--fg) 7%, transparent); color: var(--muted); font-size: 11px; transition: background .12s, color .12s; }
|
||||
.pq-more:hover { background: color-mix(in srgb, var(--fg) 12%, transparent); color: var(--fg); }
|
||||
.pq-mode:hover { background: color-mix(in srgb, var(--fg) 12%, transparent); color: var(--fg); }
|
||||
.pq-gnote + .pq-mode { margin-left: 0; }
|
||||
.pq-mode.flash { animation: pq-mode-flash .9s ease-out; }
|
||||
@@ -1216,6 +1218,9 @@ body.panel .foot { min-height: 0; padding: 5px 8px 7px 14px; border-top: 1px sol
|
||||
.profiles .chips .hint { line-height: 30px; }
|
||||
.row-head { display: flex; align-items: center; height: 26px; }
|
||||
.label { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
|
||||
/* several accounts: the others behind a button, under the one in sight */
|
||||
.subscription-card .quota-more { display: block; margin: 8px 0 -3px -7px; font-size: 11.5px; color: var(--muted); }
|
||||
.subscription-card .quota-more:hover { color: var(--fg); }
|
||||
.text { font-size: 12px; color: var(--ctl-fg); padding: 3px 7px; border-radius: 6px; transition: background .12s, color .12s; white-space: nowrap; }
|
||||
.text:hover { color: var(--fg); background: var(--pill); }
|
||||
.text.action { height: 27px; padding: 0 10px; border: 1px solid var(--line); background: var(--card); color: var(--fg-2); box-shadow: 0 1px 1px rgba(0, 0, 0, .04); display: inline-flex; align-items: center; justify-content: center; }
|
||||
|
||||
@@ -9042,6 +9042,9 @@ function renderQuotas() {
|
||||
}
|
||||
for (const subs of groups) {
|
||||
const first = subs[0];
|
||||
// several accounts: one in sight, the others behind a button (whqtian)
|
||||
const folded = subs.length > 1 && !usageOpen.has(first.provider);
|
||||
const pick = folded ? usageShown(subs) : null;
|
||||
const card = el("div", "subscription-card" + (first.user ? " several" : ""));
|
||||
card.dataset.key = first.provider;
|
||||
const head = el("div", "subscription-head");
|
||||
@@ -9049,6 +9052,7 @@ function renderQuotas() {
|
||||
if (!first.user && (first.plan || first.until)) head.append(planSpan(first));
|
||||
card.append(head);
|
||||
for (const sub of subs) {
|
||||
const from = card.childElementCount;
|
||||
// "Every model" by the account, or the card's name: where the click
|
||||
// was, whichever way the meters under it grow or shrink
|
||||
const [meters, every] = familyQuota(sub);
|
||||
@@ -9088,11 +9092,42 @@ function renderQuotas() {
|
||||
}
|
||||
card.append(r);
|
||||
}
|
||||
if (folded && sub !== pick) for (const n of [...card.children].slice(from)) n.hidden = true;
|
||||
}
|
||||
if (subs.length > 1) card.append(usageMore(first.provider, subs.length - 1, folded, "text quota-more"));
|
||||
subscriptions.append(card);
|
||||
}
|
||||
}
|
||||
|
||||
// A subscription with several accounts shows one of them, the others behind
|
||||
// a button (whqtian on Discord: 只显示一个账号即可,其他的可以点击展开): the
|
||||
// one that answered last, else the first. Opened is remembered by provider,
|
||||
// for the window and the tray panel alike.
|
||||
let usageOpen = new Set();
|
||||
try { usageOpen = new Set(JSON.parse(localStorage.getItem("magpie.usageOpen") || "[]")); } catch {}
|
||||
addEventListener("storage", (e) => {
|
||||
if (e.key !== "magpie.usageOpen") return;
|
||||
try { usageOpen = new Set(JSON.parse(e.newValue || "[]")); } catch {}
|
||||
renderQuotas();
|
||||
});
|
||||
function usageShown(subs) {
|
||||
let pick = subs[0];
|
||||
for (const q of subs) if (q.lastServedAt && (!pick.lastServedAt || q.lastServedAt > pick.lastServedAt)) pick = q;
|
||||
return pick;
|
||||
}
|
||||
function usageMore(provider, more, folded, cls) {
|
||||
const b = el("button", cls, folded ? t(more === 1 ? "Show 1 more account" : "Show {n} more accounts", { n: more }) : t("Show fewer accounts"));
|
||||
b.type = "button";
|
||||
b.setAttribute("aria-expanded", String(!folded));
|
||||
b.onclick = () => {
|
||||
if (folded) usageOpen.add(provider); else usageOpen.delete(provider);
|
||||
try { localStorage.setItem("magpie.usageOpen", JSON.stringify([...usageOpen])); } catch {}
|
||||
renderQuotas();
|
||||
if (mode !== "panel") backToReader($("#view-usage"));
|
||||
};
|
||||
return b;
|
||||
}
|
||||
|
||||
// The Usage page's cards in the order they were dragged to (settings
|
||||
// usageOrder, by provider id), as the Agents page's rows are; one it doesn't
|
||||
// name keeps magpie's own order after them. The tray panel's Usage tab
|
||||
@@ -9720,7 +9755,10 @@ function renderPanelQuota() {
|
||||
head.append(m);
|
||||
}
|
||||
g.append(head);
|
||||
for (const q of qs) g.append(panelQuotaCard(q));
|
||||
const folded = qs.length > 1 && !usageOpen.has(qs[0].provider);
|
||||
const pick = folded ? usageShown(qs) : null;
|
||||
for (const q of qs) if (!folded || q === pick) g.append(panelQuotaCard(q));
|
||||
if (qs.length > 1) g.append(usageMore(qs[0].provider, qs.length - 1, folded, "pq-more"));
|
||||
box.append(g);
|
||||
}
|
||||
if (bals.length) {
|
||||
|
||||
@@ -1885,6 +1885,9 @@ const I18N = {
|
||||
"Several accounts or keys": "多账号 / 多 Key",
|
||||
"each provider routes over its own": "各供应商在自己的账号或 Key 间路由",
|
||||
"{n} accounts": "{n} 个账号",
|
||||
"Show 1 more account": "展开其余 1 个账号",
|
||||
"Show {n} more accounts": "展开其余 {n} 个账号",
|
||||
"Show fewer accounts": "收起其余账号",
|
||||
"A conversation stays with the account or key that answered it while what the vendor cached of it is worth keeping — within a turn always, across turns while it's fresh.": "会话留在回答过它的账号或 Key 上,只要厂商为它缓存的内容还值得保留——一轮之内总是保持,跨轮则在缓存还新鲜时保持。",
|
||||
"A conversation stays with the account or key that answered it for the whole session, while it can answer.": "整个会话都留在回答过它的账号或 Key 上,只要它还能回答。",
|
||||
"A conversation stays put within a turn, while the agent sends tool results back; when you speak again, routing decides afresh.": "一轮之内(Agent 回传工具结果时)不换;你再次发言时,路由重新决定。",
|
||||
|
||||
@@ -144,6 +144,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
// the menu bar panel: three rings an account, the families
|
||||
const panel = await open("panel", "http://magpie.test/?mode=panel", { width: 440, height: 640 });
|
||||
await panel.locator('#ptabs [data-ptab="usage"]').click();
|
||||
// its second account is behind the button, as several accounts are
|
||||
await panel.locator(".pq-group", { hasText: "Antigravity" }).locator(".pq-more").click();
|
||||
const pcards = panel.locator(".pq-group", { hasText: "Antigravity" }).locator(".pq-card");
|
||||
await pcards.first().locator(".pq-ring").first().waitFor();
|
||||
assert.equal(await pcards.count(), 2);
|
||||
|
||||
@@ -144,6 +144,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
// the menu bar panel: four rings an account, 5h and 7d a pool
|
||||
const panel = await open("panel", "http://magpie.test/?mode=panel", { width: 440, height: 640 });
|
||||
await panel.locator('#ptabs [data-ptab="usage"]').click();
|
||||
// its second account is behind the button, as several accounts are
|
||||
await panel.locator(".pq-group", { hasText: "Antigravity" }).locator(".pq-more").click();
|
||||
const pcards = panel.locator(".pq-group", { hasText: "Antigravity" }).locator(".pq-card");
|
||||
await pcards.first().locator(".pq-ring").first().waitFor();
|
||||
assert.equal(await pcards.count(), 2);
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// A subscription with several accounts shows one of them on the Usage page
|
||||
// and in the tray panel — the one that answered last, else the first — the
|
||||
// others behind "Show N more accounts" (whqtian on Discord: 只显示一个账号
|
||||
// 即可,其他的可以点击展开); opened is remembered by provider across a
|
||||
// reload; a provider with one account has no button; the click doesn't move
|
||||
// the page, and Hide accounts still hides every one. English and Chinese;
|
||||
// no backend, the API is faked here.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const ago = (m) => new Date(Date.now() - m * 60e3).toISOString();
|
||||
const wb = (user, used, served) => ({ provider: "workbuddy", name: "WorkBuddy", kind: "subscription", icon: "workbuddy-color", plan: "Pro", user, windows: [{ name: "Credits", used, display: `${used * 56} / 5600` }], ...(served ? { lastServedAt: served } : {}) });
|
||||
const quotas = () => [
|
||||
wb("alpha@example.com", 10),
|
||||
wb("bravo@example.com", 20, ago(30)),
|
||||
wb("charlie@example.com", 30, ago(2)), // answered last: the one in sight
|
||||
wb("delta@example.com", 40),
|
||||
{ provider: "zcode", name: "ZCode", kind: "subscription", icon: "zcode", plan: "Start", user: "solo@example.com", windows: [{ name: "5 hours", used: 10 }] },
|
||||
{ provider: "codex", name: "Codex", kind: "subscription", icon: "openai", plan: "Plus", user: "one@example.com", windows: [{ name: "5 hours", used: 20 }] },
|
||||
{ provider: "codex", name: "Codex", kind: "subscription", icon: "openai", plan: "Plus", user: "two@example.com", windows: [{ name: "5 hours", used: 50 }] },
|
||||
];
|
||||
|
||||
function serve(lang, panel) {
|
||||
const settings = { theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd" };
|
||||
return async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:${!panel}};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings });
|
||||
if (url.pathname === "/api/settings") return json(settings);
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } });
|
||||
if (url.pathname === "/api/usage/quotas") return json(quotas());
|
||||
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
||||
};
|
||||
}
|
||||
|
||||
const words = {
|
||||
en: { more3: "Show 3 more accounts", more1: "Show 1 more account", fewer: "Show fewer accounts", hide: "Hide accounts" },
|
||||
zh: { more3: "展开其余 3 个账号", more1: "展开其余 1 个账号", fewer: "收起其余账号", hide: "账号打码" },
|
||||
};
|
||||
|
||||
// what each card shows: its name, the accounts in sight, its button
|
||||
const cards = (page) => page.evaluate(() => [...document.querySelectorAll("#subscriptionUsage > .subscription-card")].map((c) => ({
|
||||
name: c.querySelector(".subscription-head b").textContent,
|
||||
users: [...c.querySelectorAll(".subscription-account")].filter((a) => a.offsetParent).map((a) => a.querySelector(".user").title),
|
||||
meters: [...c.querySelectorAll(".quota-windows")].filter((a) => a.offsetParent).length,
|
||||
more: c.querySelector(".quota-more")?.textContent ?? null,
|
||||
})));
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh"]) {
|
||||
const w = words[lang];
|
||||
test(`${engine} ${lang}: several accounts show one, the others behind a button`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const context = await browser.newContext({ viewport: { width: 900, height: 300 }, reducedMotion: "reduce" });
|
||||
const errors = [];
|
||||
const open = async (url) => {
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, url.includes("mode=panel")));
|
||||
await page.goto(url);
|
||||
return page;
|
||||
};
|
||||
const page = await open("http://magpie.test/?view=usage");
|
||||
await page.evaluate(() => { localStorage.removeItem("magpie.usageOpen"); localStorage.removeItem("magpie.maskEmails"); });
|
||||
await page.reload();
|
||||
await page.waitForSelector(".subscription-account .user", { state: "attached" });
|
||||
|
||||
let got = await cards(page);
|
||||
const by = (name) => got.find((c) => c.name === name);
|
||||
assert.deepEqual(by("WorkBuddy"), { name: "WorkBuddy", users: ["charlie@example.com"], meters: 1, more: w.more3 });
|
||||
assert.deepEqual(by("Codex"), { name: "Codex", users: ["one@example.com"], meters: 1, more: w.more1 });
|
||||
assert.equal(by("ZCode").more, null, "one account: no button");
|
||||
assert.deepEqual(by("ZCode").users, ["solo@example.com"]);
|
||||
|
||||
// opening it doesn't move the page
|
||||
const view = page.locator("#view-usage");
|
||||
await page.mouse.move(450, 200);
|
||||
await page.mouse.wheel(0, 60);
|
||||
await page.waitForFunction(() => document.querySelector("#view-usage").scrollTop > 0);
|
||||
await page.waitForTimeout(300);
|
||||
const head = page.locator("#subscriptionUsage > [data-key=workbuddy] .subscription-head");
|
||||
const before = await view.evaluate((v) => v.scrollTop);
|
||||
assert.ok(before > 0, "the view was scrolled");
|
||||
const headAt = await head.evaluate((e) => e.getBoundingClientRect().top);
|
||||
await page.locator("#subscriptionUsage > [data-key=workbuddy] .quota-more").click();
|
||||
await page.waitForTimeout(700);
|
||||
assert.equal(await view.evaluate((v) => v.scrollTop), before, "the view didn't scroll");
|
||||
assert.equal(await head.evaluate((e) => e.getBoundingClientRect().top), headAt, "the card stays where it was");
|
||||
got = await cards(page);
|
||||
assert.deepEqual(by("WorkBuddy"), { name: "WorkBuddy", users: ["alpha@example.com", "bravo@example.com", "charlie@example.com", "delta@example.com"], meters: 4, more: w.fewer });
|
||||
assert.equal(by("Codex").more, w.more1, "another provider stays folded");
|
||||
|
||||
// remembered across a reload, by provider
|
||||
await page.reload();
|
||||
await page.waitForSelector(".subscription-account .user", { state: "attached" });
|
||||
got = await cards(page);
|
||||
assert.equal(by("WorkBuddy").users.length, 4);
|
||||
assert.equal(by("Codex").users.length, 1);
|
||||
|
||||
// Hide accounts still hides every account, the folded ones too
|
||||
await page.locator("#usageMask").click();
|
||||
await page.waitForFunction(() => document.querySelectorAll("#subscriptionUsage .subscription-account .user .pii").length === 7);
|
||||
assert.ok(!/example\.com/.test(await page.locator("#subscriptionUsage").innerText()));
|
||||
await page.locator("#usageMask").click();
|
||||
|
||||
// the tray panel folds the same way, and follows what was opened
|
||||
const panel = await open("http://magpie.test/?mode=panel");
|
||||
await panel.setViewportSize({ width: 380, height: 900 });
|
||||
await panel.evaluate(() => setPanelTab("usage"));
|
||||
await panel.waitForSelector("#panelQuota .pq-card .pq-user");
|
||||
const pq = () => panel.evaluate(() => Object.fromEntries([...document.querySelectorAll("#panelQuota .pq-group")].map((g) => [g.querySelector(".pq-gn").textContent, { users: [...g.querySelectorAll(".pq-user")].map((u) => u.textContent), more: g.querySelector(".pq-more")?.textContent ?? null }])));
|
||||
let p = await pq();
|
||||
assert.deepEqual(p.WorkBuddy, { users: ["alpha@example.com", "bravo@example.com", "charlie@example.com", "delta@example.com"], more: w.fewer });
|
||||
assert.deepEqual(p.Codex, { users: ["one@example.com"], more: w.more1 });
|
||||
assert.equal(p.ZCode.more, null);
|
||||
await panel.locator("#panelQuota .pq-more", { hasText: w.fewer }).click();
|
||||
p = await pq();
|
||||
assert.deepEqual(p.WorkBuddy, { users: ["charlie@example.com"], more: w.more3 });
|
||||
// and the window follows the panel
|
||||
await page.waitForFunction(() => document.querySelector("#subscriptionUsage > [data-key=workbuddy] .quota-more")?.getAttribute("aria-expanded") === "false");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user