Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

usage: a card's account button names the accounts it opens and folds back the ones it opened

yetonead2424ade4b7
diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js
index 407c85f28..f7d5dbc93 100644
--- a/internal/gui/assets/app.js
+++ b/internal/gui/assets/app.js
@@ -15610,13 +15610,19 @@ function renderQuotas(lazy) {
// account's full or brief is remembered by provider and account
// (magpie.usageAccounts), for the window and the panel alike; a provider
// opened before that (magpie.usageOpen) starts with every account in full.
-let usageOpen = new Set(), usageAccts = {};
+// The accounts the card's button opened are remembered too
+// (magpie.usageAcctsOpened), so that its fold puts those back in brief,
+// and only those (WuSix on Discord: with both accounts in brief, 展开 opened
+// both and 收起其余账号 folded only the second).
+let usageOpen = new Set(), usageAccts = {}, usageByMore = new Set();
try { usageOpen = new Set(JSON.parse(localStorage.getItem("magpie.usageOpen") || "[]")); } catch {}
try { usageAccts = JSON.parse(localStorage.getItem("magpie.usageAccounts") || "{}") || {}; } catch {}
+try { usageByMore = new Set(JSON.parse(localStorage.getItem("magpie.usageAcctsOpened") || "[]")); } catch {}
addEventListener("storage", (e) => {
- if (e.key !== "magpie.usageOpen" && e.key !== "magpie.usageAccounts") return;
+ if (e.key !== "magpie.usageOpen" && e.key !== "magpie.usageAccounts" && e.key !== "magpie.usageAcctsOpened") return;
try { usageOpen = new Set(JSON.parse(localStorage.getItem("magpie.usageOpen") || "[]")); } catch {}
try { usageAccts = JSON.parse(localStorage.getItem("magpie.usageAccounts") || "{}") || {}; } catch {}
+ try { usageByMore = new Set(JSON.parse(localStorage.getItem("magpie.usageAcctsOpened") || "[]")); } catch {}
renderQuotas();
});
function usageShown(subs) {
@@ -15631,9 +15637,16 @@ function usageAcctOpen(q, subs) {
if (typeof v === "boolean") return v;
return usageOpen.has(q.provider) || q === usageShown(subs);
}
-function setUsageAccts(list, open) {
- for (const q of list) usageAccts[usageAcctKey(q)] = typeof open === "function" ? open(q) : open;
+// setUsageAccts: the accounts in list in full (open true) or in brief;
+// byMore: true when the card's button opened them, false when it or
+// anything else did (an account's own fold, a menu bar cell asking for it)
+function setUsageAccts(list, open, byMore = false) {
+ for (const q of list) {
+ usageAccts[usageAcctKey(q)] = typeof open === "function" ? open(q) : open;
+ if (byMore) usageByMore.add(usageAcctKey(q)); else usageByMore.delete(usageAcctKey(q));
+ }
try { localStorage.setItem("magpie.usageAccounts", JSON.stringify(usageAccts)); } catch {}
+ try { localStorage.setItem("magpie.usageAcctsOpened", JSON.stringify([...usageByMore])); } catch {}
renderQuotas();
}
// A card of a provider's keys shows the first three, and any in full,
@@ -15707,20 +15720,28 @@ function keysSum(subs) {
return balanceAmount(subs[0], total);
}
// the card's button: the accounts in brief (or, in the panel, left out) in
-// full, or every one but the one in sight back in brief
+// full, its count the ones it opens; or, every one in full, the ones it
+// opened back in brief (none of them: every one but the one in sight). An
+// account's own fold leaves the button's count and fold as they are.
function usageMore(subs, cls) {
const closed = subs.filter((q) => !usageAcctOpen(q, subs));
const panel = mode === "panel";
// the panel draws the one in sight when none is in full
const n = closed.length - (panel && closed.length === subs.length ? 1 : 0);
- const b = el("button", cls, n
- ? t(panel ? (n === 1 ? "Show 1 more account" : "Show {n} more accounts") : (n === 1 ? "Show 1 more account in full" : "Show {n} more accounts in full"), { n })
- : t(panel ? "Show fewer accounts" : "Show the other accounts in brief"));
+ const pick = usageShown(subs);
+ const opened = subs.filter((q) => usageByMore.has(usageAcctKey(q)));
+ const fold = opened.length ? opened : subs.filter((q) => q !== pick);
+ // with none in full, "the other" accounts would be all of them
+ const label = n
+ ? (panel ? (n === 1 ? "Show 1 more account" : "Show {n} more accounts")
+ : n === subs.length ? "Show all {n} accounts in full"
+ : (n === 1 ? "Show 1 more account in full" : "Show {n} more accounts in full"))
+ : (panel ? "Show fewer accounts" : fold.length === subs.length ? "Show every account in brief" : "Show the other accounts in brief");
+ const b = el("button", cls, t(label, { n }));
b.type = "button";
b.setAttribute("aria-expanded", String(!n));
b.onclick = () => {
- const pick = usageShown(subs);
- if (n) setUsageAccts(closed, true); else setUsageAccts(subs, (q) => q === pick);
+ if (n) setUsageAccts(closed, true, true); else setUsageAccts(fold, false);
if (!panel) backToReader($("#view-usage"));
};
return b;
diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js
index 8c2e1d614..6fcf539a3 100644
--- a/internal/gui/assets/i18n.js
+++ b/internal/gui/assets/i18n.js
@@ -3173,6 +3173,8 @@ const I18N = {
"Show 1 more account in full": "展开其余 1 个账号",
"Show {n} more accounts in full": "展开其余 {n} 个账号",
"Show the other accounts in brief": "收起其余账号",
+ "Show all {n} accounts in full": "展开全部 {n} 个账号",
+ "Show every account in brief": "收起全部账号",
"Show this account in full": "展开此账号",
"Show this account in brief": "收起此账号",
"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 上:一轮之内始终保持,跨轮则在缓存新鲜时保持。",
@@ -7017,6 +7019,8 @@ const I18N = {
"Show 1 more account in full": "展開其餘 1 個帳號",
"Show {n} more accounts in full": "展開其餘 {n} 個帳號",
"Show the other accounts in brief": "收起其餘帳號",
+ "Show all {n} accounts in full": "展開全部 {n} 個帳號",
+ "Show every account in brief": "收起全部帳號",
"Show this account in full": "展開此帳號",
"Show this account in brief": "收起此帳號",
"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 上:一輪之內始終保持,跨輪則在快取新鮮時保持。",
@@ -10877,6 +10881,8 @@ const I18N = {
"Show 1 more account in full": "さらに 1 個のアカウントを詳しく表示",
"Show {n} more accounts in full": "さらに {n} 個のアカウントを詳しく表示",
"Show the other accounts in brief": "他のアカウントを簡潔に表示",
+ "Show all {n} accounts in full": "{n} 個すべてのアカウントを詳しく表示",
+ "Show every account in brief": "すべてのアカウントを簡潔に表示",
"Show this account in full": "このアカウントを詳しく表示",
"Show this account in brief": "このアカウントを簡潔に表示",
"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.": "会話は、ベンダーがキャッシュした内容に保持する価値がある間、応答したアカウントやキーにとどまります。ターン内では常に、ターンをまたぐ場合はキャッシュが新しい間です。",
@@ -14746,6 +14752,8 @@ const I18N = {
"Show 1 more account in full": "1 weiteres Konto vollständig anzeigen",
"Show {n} more accounts in full": "{n} weitere Konten vollständig anzeigen",
"Show the other accounts in brief": "Die übrigen Konten kurz anzeigen",
+ "Show all {n} accounts in full": "Alle {n} Konten vollständig anzeigen",
+ "Show every account in brief": "Alle Konten kurz anzeigen",
"Show this account in full": "Dieses Konto vollständig anzeigen",
"Show this account in brief": "Dieses Konto kurz anzeigen",
"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.": "Eine Unterhaltung bleibt beim Konto oder Schlüssel, das sie beantwortet hat, solange sich der Cache des Anbieters dafür lohnt – innerhalb einer Runde immer, über Runden hinweg, solange er frisch ist.",
diff --git a/internal/gui/tests/usage-fold.test.cjs b/internal/gui/tests/usage-fold.test.cjs
index 562b4a6f6..44fcc7679 100644
--- a/internal/gui/tests/usage-fold.test.cjs
+++ b/internal/gui/tests/usage-fold.test.cjs
@@ -188,6 +188,79 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
});
}
+ // WuSix on Discord (#help): three accounts, one deleted, and the two
+ // left were both in brief. The button said 展开其余 2 个账号 though no
+ // account was in full, opened both, and then 收起其余账号 folded only the
+ // second, leaving 展开其余 1 个账号. The count names the accounts the
+ // button opens, its fold puts back in brief the ones it opened, and an
+ // account's own fold still works on its own. At a narrow width.
+ for (const lang of ["en", "zh"]) {
+ const w = {
+ en: { all2: "Show all 2 accounts in full", more2: "Show 2 more accounts in full", more1: "Show 1 more account in full", every: "Show every account in brief", other: "Show the other accounts in brief" },
+ zh: { all2: "展开全部 2 个账号", more2: "展开其余 2 个账号", more1: "展开其余 1 个账号", every: "收起全部账号", other: "收起其余账号" },
+ }[lang];
+ test(`${engine} ${lang}: an account deleted, the button opens and folds the ones it names`, async (t) => {
+ const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
+ t.after(() => browser.close());
+ const page = await (await browser.newContext({ viewport: { width: 420, height: 800 }, reducedMotion: "reduce" })).newPage();
+ page.setDefaultTimeout(5000);
+ const errors = [];
+ page.on("pageerror", (e) => errors.push(e.message));
+ let list = [wb("[email protected]", 10), wb("[email protected]", 20, ago(30)), wb("[email protected]", 30, ago(2))];
+ await page.route("**/*", serve(lang, false, () => list));
+ const card = async () => (await cards(page)).find((c) => c.name === "WorkBuddy");
+ const more = page.locator("#subscriptionUsage > [data-key=workbuddy] .quota-more");
+ const settle = (text) => page.waitForFunction((text) => document.querySelector("#subscriptionUsage > [data-key=workbuddy] .quota-more")?.textContent === text, text);
+ await page.goto("http://magpie.test/?view=usage");
+ await page.waitForSelector(".subscription-account .user", { state: "attached" });
+
+ // three accounts: the one that answered last in full; opened and
+ // folded again, the card is as it was
+ assert.deepEqual([(await card()).full, (await card()).more], [["[email protected]"], w.more2]);
+ await more.click();
+ await settle(w.other);
+ assert.equal((await card()).full.length, 3);
+ await more.click();
+ await settle(w.more2);
+ assert.deepEqual([(await card()).full, (await card()).brief], [["[email protected]"], ["[email protected]", "[email protected]"]]);
+
+ // charlie deleted: the two left both in brief, and the button says so
+ list = list.filter((q) => q.user !== "[email protected]");
+ await page.reload();
+ await page.waitForSelector(".subscription-account .user", { state: "attached" });
+ let c = await card();
+ assert.deepEqual([c.full, c.brief, c.more], [[], ["[email protected]", "[email protected]"], w.all2]);
+ // it opens both
+ await more.click();
+ await settle(w.every);
+ c = await card();
+ assert.deepEqual([c.full, c.brief], [["[email protected]", "[email protected]"], []]);
+ assert.equal(await more.getAttribute("aria-expanded"), "true");
+ // and folds both
+ await more.click();
+ await settle(w.all2);
+ c = await card();
+ assert.deepEqual([c.full, c.brief], [[], ["[email protected]", "[email protected]"]]);
+ assert.equal(await more.getAttribute("aria-expanded"), "false");
+
+ // an account's own fold still works on its own
+ const fold = (user) => page.locator("#subscriptionUsage > [data-key=workbuddy] .subscription-account", { hasText: user }).locator(".quota-acct-fold");
+ await fold("[email protected]").click();
+ await settle(w.more1);
+ assert.deepEqual((await card()).full, ["[email protected]"]);
+ // the button opens bravo, and folds bravo alone
+ await more.click();
+ await settle(w.other);
+ await more.click();
+ await settle(w.more1);
+ assert.deepEqual([(await card()).full, (await card()).brief], [["[email protected]"], ["[email protected]"]]);
+ await fold("[email protected]").click();
+ await settle(w.all2);
+ assert.deepEqual((await card()).full, []);
+ assert.deepEqual(errors, []);
+ });
+ }
+
// ARNO's Usage page: 17 subscriptions, 29 accounts. With Trends off, at
// 1280×800, every account is on the page and most of their bars are on
// the first screen without opening anything, as many as before the curves.