diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index 5489f56a6..0f77f77e5 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -2067,6 +2067,10 @@ body.panel .profiles #save { height: 25px; } /* the field's: the line keeps its .subscription-account .acct-auto-n { color: var(--muted); } .subscription-account .acct-auto + .plan { margin-left: 0; } .subscription-account .acct-auto + .quota-every { margin-left: 4px; } +/* Warm up on an account whose 5 hours haven't started (quotaWarm): at the + line's right, before its resets' switch, plan and fold */ +.subscription-account .acct-warm { flex: none; margin: -2px 0 -2px auto; font-size: 11px; padding: 2px 7px; } +.subscription-account .acct-warm ~ :is(.acct-auto, .plan) { margin-left: 0; } .pq-bals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } .pq-card.bal { grid-template-columns: minmax(0, 1fr); } .pq-bn { display: flex; align-items: center; gap: 6px; } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index df50e1bf0..9b97b2bf8 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -15839,6 +15839,8 @@ function renderQuotas(lazy) { who.dataset.card = trayCardID(sub); if (sub.balanceCard) who.dataset.balCard = sub.balanceCard; who.append(...quotaWho(sub)); + const warm = quotaWarm(sub); + if (warm) who.append(warm); // in brief, its resets and whether it uses them by itself (#719) const auto = brief && autoResetBrief(sub); if (auto) who.append(auto); @@ -15900,8 +15902,8 @@ function renderQuotas(lazy) { const credits = !brief && !history && creditsRow(sub, "quota-credits"); if (credits) card.append(credits); } - // in the card's head, beside its name: no line of its own - // (of the keys in sight: the ones folded away are the foot's button's) + // in the card's head, beside its name, of the keys in sight (the + // folded ones are the foot's button's) if (several) head.append(usageMore(folded.size ? subs.filter((q) => !folded.has(q)) : subs, "text quota-more")); if (keys && (folded.size || usageKeysAll.has(first.provider))) card.append(keysMore(first.provider, folded.size)); if (accts && (folded.size || usageAcctsAll.has(first.provider))) card.append(acctsMore(first.provider, folded.size)); @@ -21028,10 +21030,9 @@ function renderWarmAtOwn(s) { } } -// renderWarmNow is Warm up now (a Windows user on Discord): one account's -// warm-up request, the one the scheduled warm-up sends, sent at once. One -// account is sent at a press; with more the press asks which. What it came -// to stays on the row's line (warmNowSaid) across renders. +// renderWarmNow is Warm up now (a Windows user on Discord): the scheduled +// warm-up's request to one account at once, of several the menu's; what it +// came to stays on its line (warmNowSaid). An account's card: quotaWarm. const warmNowSaid = {}; function renderWarmNow(agent, users, rowId) { const row = $(rowId), sub = row.querySelector(".sub"), box = row.lastElementChild; diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 99098c041..8025591a3 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -1203,6 +1203,7 @@ const I18N = { "Warm up now": "现在预热", "Sends the warm-up's one tiny request to an account now": "现在给一个账号发出预热的那条极小请求", "Warm up": "预热", + "The 5-hour window hasn't started: one tiny request starts it now": "5 小时窗口还没开始:发一个极小的请求,现在就开始计时", "Warm up…": "预热…", "Warm up which account": "预热哪个账号", "Warming up {who}…": "正在预热 {who}…", @@ -5570,6 +5571,7 @@ const I18N = { "Warm up now": "現在預熱", "Sends the warm-up's one tiny request to an account now": "現在給一個帳號發出預熱的那條極小請求", "Warm up": "預熱", + "The 5-hour window hasn't started: one tiny request starts it now": "5 小時視窗還沒開始:發一個極小的請求,現在就開始計時", "Warm up…": "預熱…", "Warm up which account": "預熱哪個帳號", "Warming up {who}…": "正在預熱 {who}…", @@ -9906,6 +9908,7 @@ const I18N = { "Warm up now": "今すぐウォームアップ", "Sends the warm-up's one tiny request to an account now": "ウォームアップのごく小さなリクエストを今すぐアカウントに送ります", "Warm up": "ウォームアップ", + "The 5-hour window hasn't started: one tiny request starts it now": "5 時間枠はまだ始まっていません。ごく小さなリクエストを 1 つ送って今すぐ始めます", "Warm up…": "ウォームアップ…", "Warm up which account": "ウォームアップするアカウント", "Warming up {who}…": "{who} をウォームアップ中…", @@ -14273,6 +14276,7 @@ const I18N = { "Warm up now": "Jetzt vorwärmen", "Sends the warm-up's one tiny request to an account now": "Sendet die winzige Vorwärm-Anfrage jetzt an ein Konto", "Warm up": "Vorwärmen", + "The 5-hour window hasn't started: one tiny request starts it now": "Das 5-Stunden-Fenster hat noch nicht begonnen: eine winzige Anfrage startet es jetzt", "Warm up…": "Vorwärmen…", "Warm up which account": "Welches Konto vorwärmen", "Warming up {who}…": "{who} wird vorgewärmt…", diff --git a/internal/gui/assets/plugins/usage/page.js b/internal/gui/assets/plugins/usage/page.js index 61e40eda8..383d229f3 100644 --- a/internal/gui/assets/plugins/usage/page.js +++ b/internal/gui/assets/plugins/usage/page.js @@ -447,6 +447,44 @@ function quotaWho(q) { return out; } +// quotaWarm is Warm up on the card of a Codex or Claude account whose +// 5-hour window isn't running (01huadalang on Discord, who looked here, not +// in Settings): the request Settings › Usage's Warm up now sends (POST +// /api/warm-now {agent, user}), for this account. Idle is as the +// warm-up tells it (idle in codex_warmup.go): nothing used and its reset a +// whole window away, or gone by; or not read at all, which a Claude account +// never used is, while a Codex account with no 5-hour window has none to +// start. One just warmed reads the same for warmSlack, so it waits that out. +const quotaWarmed = new Map(); +function quotaWarm(q) { + const agent = q.provider, user = q.user, key = agent + "\n" + user?.toLowerCase(); + if (!user || q.error || !(state.settings?.[agent + "Users"] || []).some((u) => u.toLowerCase() === user.toLowerCase())) return null; + const w = q.windows?.find((x) => x.name === "5 hours"), now = Date.now(), at = w?.resetsAt ? Date.parse(w.resetsAt) : 0; + if (w ? !(at && at <= now) && (w.used > 0 || at && at - now < 5 * 3600e3 - 600e3) : agent !== "claude") return null; + const busy = quotaWarmed.get(key); + if (busy && busy !== true && now - busy < 600e3) return null; + const b = el("button", "text acct-warm" + (busy === true ? " busy" : ""), t("Warm up")); + b.type = "button"; + b.disabled = busy === true; + b.title = t("The 5-hour window hasn't started: one tiny request starts it now"); + b.onclick = async (e) => { + e.stopPropagation(); + quotaWarmed.set(key, true); + renderQuotas(); + try { + await api("warm-now", { agent, user }); + quotaWarmed.set(key, Date.now()); + status(t("Warmed up {who}", { who: user }), "ok"); + } catch (err) { + quotaWarmed.delete(key); + status(t("Couldn't warm up {who}: {why}", { who: user, why: err.message }), "err"); + } + renderQuotas(); + loadQuotas(); // the window it started + }; + return b; +} + function ownCalls(n) { return t("{n} by magpie itself", { n: fmtN(n) }); } diff --git a/internal/gui/core_budget_test.go b/internal/gui/core_budget_test.go index 260863aad..b571993f0 100644 --- a/internal/gui/core_budget_test.go +++ b/internal/gui/core_budget_test.go @@ -16,7 +16,7 @@ import ( // raises them and says why in its commit. const ( appScriptBudget = 1_316_874 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%; a dialog growing out of the row that opened it and folding back into it, the core's own since every page's dialogs open through it (10-20); Codex's and Claude Code's own settings moved from Settings into the agent's row on the Agents page, the core's own since the tray panel and the window both draw them (10-20); 1,314,432 with Settings › Privacy's record of what was masked (its summary, the records view and the local model's controls), which belongs to Settings, the core's own, plus 1.5%; 1,336,481 with a provider's Names & levels saying Provider in model names is Settings' and opening it there (joe), and Settings' Image recognition saying where a custom provider's model is marked (nexnull), both in the core's own pages, with no room added (10-23); 1,337,633 with Settings › Models › Replies' Intent classifier timeout (#2934, reyoung), Settings' own row, drawn by waitRow, which the Image generation timeout's row now shares, with no room added; 1,337,735 with the provider editor's link naming a partner's page by its own host (siteHost) instead of usemagpie.ai's /go link, the core's own editor, with no room added (10-23); 1,338,084 with Check in now saying what the press came to (claimed +credits, already today, not available yet) where it said "refreshed" (#3326), the check-in row the tray panel draws too, the core's own, with no room added (10-23); 1,338,929 with a new partner's tile keeping a small dot until it is opened, in the add sheet, the core's own, with no room added (10-23); 1,343,324 with the sidebar's open-page row marked by one shape that moves on a spring (navTopGo), the window's own shell, which every page sits beside, with no room added (10-23); 1,343,465 with a dialog kept centred while its content comes in, until it is pressed (holdModal, every page's dialogs), the core's own, with no room added (10-24); 1,317,486 with what masking did moved out to Insights › Masking (plugins/redact), the budget lowered to it (10-24); 1,321,336 with Codex's one subagent model, its card's square saying plainly what each choice does and a row with a name in its sheet, where two squares read alike (the owner), the Agents page's, which the tray panel draws too, the core's own, with no room added (10-24); 1,321,424 with Settings › Models' Image generation MCP server row beside Image recognition's (JonahFu on X), the two drawn by one helper (mcpRow), Settings' own, with no room added (10-25); 1,321,994 with a provider of the user's set never to rest for a limit (zoecats), the provider editor's Advanced row, the core's own editor, with no room added (10-25); 1,322,289 with Settings › Privacy's Keep a key's form under Mask secrets (Charles Cao on X), Settings' own row, with no room added (10-25); 1,322,537 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,323,401 with the tray panel drawing its last allowances at once and asking for them beside the state (#3160, #3134), the tray panel's, the core's own, and the 4 bytes 84c50f032 added, with no room added (10-25); 1,326,105 with many releases' notes merged into one list by kind, each line with its version (the owner), in the update sheet and What's new, with no room added (10-25); 1,321,319 with Settings › Observability moved out to its plugin (plugins/otel/page.js) and its Langfuse setup there (an X user), the budget lowered to it (10-26); a quota card whose window is used but names no reset no longer saying "Not used yet" (windy on Discord) raised it to 1,321,347, and back to 1,321,319 with Settings' model pickers sharing one row helper (modelOpt) where six kept their own copy, no raise (10-26); 1,325,845 with every slow page's skeletons getting magpie's bird hopping bar to bar (skelBird, the owner after the Plugins page's README), one bird for the window over whatever page or dialog is loading, the core's own, with no room added (10-26); 1,310,129 with Settings › Network and sharing's gateway rows (its port, bare ids, local network, allowed addresses, web pages) moved out to the gateway plugin (plugins/gateway/settings.js), the budget lowered to it (10-27); 1,310,269 with Test models naming the first model that failed and its error in the status line, where it said only how many (ysm119 on Discord), the provider editor's, the core's own, with no room added (10-27); 1,310,460 with Settings › About's Website row linking usemagpie.ai (the owner), Settings' own row, with no room added (10-27); 1,309,669 with a pool's Stop at the caps and Check usage near a cap ticks under a provider's accounts (plugins#349), the core's own editor, its account rows' Remove and add rows each drawn by one helper (forgetOf, addRow), with no room added (10-28); 1,311,681 with Install another agent on the Agents page naming the agents Plugins has (More in Plugins) and opening Plugins at its Agents (the owner), the Agents page's, the core's own, with no room added (10-28); 1,311,735 with More in Plugins in sight while Install another agent is folded (the owner), with no room added (10-29); 1,313,704 with a window whose WebKit scrolls under wheels it never tells of (macOS 13) remembered once seen, a scroll at rest then waiting 120ms for a second the same way within 80ms before it is put back, kept for a late wheel to give back (waitsBack), and a load landing under the wheel keeping the reader's way (backAfterLoad, issennknight), the window's own scroll guard, with no room added (10-29); back to 1,311,735 with Settings › Models › Web search's rows (renderSearch, renderSearcher, the search APIs' keys) moved out to the search plugin (plugins/search/settings.js), app.js 1,292,527 after it, not lowered further since what is left plus 1.5% is over it (#4133, 10-29); 1,315,316 with the Agents row of a Claude Code or Codex not connected saying the account it is signed in to and switching it to another (Switch accounts only, the owner on X), in place of the failover line's ChatGPT accounts button, the Agents page's, the core's own, its comments cut down, with no room added (10-30); 1,317,705 with a Claude account added from a setup-token (sfss5362 on X): the sign-in's Use a setup-token instead…, its sheet, and its account row's magpie only, the provider editor's account rows, the core's own editor, its comments cut down, with no room added (10-30); back to 1,315,316 with the setup-token sheet and Copilot's GHE.com one moved out to signsheets.js, loaded when one is asked for (signAsk, 10-30); 1,315,479 with the provider editor lining its Advanced up with its fields (the owner: 高级这个折叠按钮为什么在一个前不着村后不着店的位置?) and a refresh on each of its accounts (在这里也要加上手动刷新用量的按钮), the core's own editor, with no room added (10-31); 1,315,603 with About's Log row, the path of the log the app writes and an Open for its folder (rayem1w on X), in app.js, its comment cut to one line, with no room added (10-31); 1,316,781 with a provider's model listed by an id of the user's (zeewell on X), the provider editor's Names & levels Listed as box beside Same as, the core's own editor, with no room added (10-31); 1,316,874 with a package manager's magpie (the AUR's magpie-bin) naming the command that updates it in Settings' Version row and lighting no Update pill (shuhai on Discord), the core's own update row, which the tray panel reads too, its comments cut to one line, with no room added (10-31); Settings › Sync's Kept on this computer row (hayden4608 on Discord) raised it to 1,317,497, which is no bound; the 1,316,874 it had came back once later trims left app.js at 1,308,363 (10-31) - coreScriptBudget = 1_533_802 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added; 1,535,084 with the sidebar's spring, with no room added; 1,549,478 with the context window card's map (tiles by tokens, the default look, the block grid a switch away) and its text view showing an inline image, in context.js, which the Routing page draws as well as Usage, so the core's own, with no room added (10-24); 1,550,768 with a usage card's refresh opening after its text (#840's card, which the tray panel draws too), the Add key spinner, and a dialog kept centred while its content comes in, with no room added (10-24); 1,524,789 with what masking did moved out to Insights › Masking, lowered to it; 1,528,525 with Codex's one subagent model, with no room added (10-24); 1,528,972 with the Image generation MCP server row (JonahFu on X), with no room added (10-25); 1,529,542 with the limit-rest row (zoecats), with no room added (10-25); 1,529,837 with Keep a key's form (Charles Cao on X), with no room added (10-25); 1,530,050 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,530,631 with a plugin's page growing to its README on the dialog's spring instead of in one jump (the owner), the Plugins page's, in plugins.js, with no room added (10-25); 1,533,445 with the context map counting its tokens on as a live request grows, a tile pointed at keeping its tip, a tool's gathered results saying how many and the small files their folder (the owner, after flohoeller's map on X), in context.js, which the Routing page draws as well as Usage, and the 4 bytes 84c50f032 added to app.js (Settings' Version row) without a raise, with no room added (10-25); 1,534,312 with the tray panel's last allowances drawn at once (#3160, #3134), with no room added (10-25); 1,537,016 with many releases' notes merged into one list by kind (the owner), in app.js, with no room added (10-25); 1,542,244 with a plugin's README loading under magpie's bird bouncing down its lines instead of pulsing bars (the owner), the Plugins page's, in plugins.js, with no room added (10-26); 1,542,418 with a page plugin's sidebar tab coming and going as it is installed, switched on or off, or removed, instead of on the Plugins page's next load (the owner), in plugins.js, with no room added (10-26); 1,537,645 with Settings › Observability moved out to plugins/otel, lowered to it (10-26); 1,537,673 with a used window with no reset not "Not used yet" (windy on Discord), and back to 1,537,645 with Settings' model pickers sharing modelOpt (10-26); 1,541,967 with every slow page's skeletons getting magpie's bird (skelBird, the owner), in app.js, the README's bird sharing its drawing and styles, with no room added (10-26); 1,526,251 with Settings' gateway rows moved out to plugins/gateway/settings.js, lowered to it (10-27); 1,526,391 with Test models naming the first failed model and its error (ysm119 on Discord), in app.js, with no room added (10-27); 1,526,556 with About's Website row (the owner), in app.js, with no room added (10-27); 1,526,500 with a pool's cap ticks (plugins#349), in app.js, with no room added (10-28); 1,527,245 with About's Open-source licenses row and dialog (the owner), in app.js, with no room added (10-28); 1,528,076 with the Partners heading's light (the owner), in app.js, with no room added (10-28); 1,530,449 with Install another agent's More in Plugins row (the owner), in app.js, and Plugins opening at its Agents, in plugins.js, with no room added (10-28); 1,530,807 with layout.js measuring the scrollbar into --bar, which every page's right padding takes off so its sides match (the owner), the window's own shell, with no room added (10-28); 1,530,861 with More in Plugins in sight while Install another agent is folded (the owner), in app.js, with no room added (10-29); 1,532,830 with waitsBack and backAfterLoad (issennknight, macOS 13), the window's own scroll guard, in app.js, with no room added (10-29); the context map's tile wording (a4e929212) and Cindy's Add magpie (628ac36fc) had taken the core over it, and Web search's rows moved out to plugins/search/settings.js brought it back to 1,530,861 (#4133, 10-29); 1,532,459 with a provider editor's account rows on one line each, First or Make first at its right end and the settings that aren't set under ⋯ (the owner), the core's own editor, in app.js, which stays in its budget with its comments cut down, with no room added (10-29); 1,532,602 with a plugin's README waiting for its bird to land on three lines before it goes in, however soon it came (the owner, 10-30), in plugins.js, with no room added; 1,536,357 with Switch accounts only on the Agents row (the owner on X), in app.js, with no room added (10-30); 1,537,034 with a plugin's README read once shown at once, with no bird, when its page opens again and read again behind it, the last 20 kept (the owner), in plugins.js, with no room added (10-30); 1,539,423 with a Claude account added from a setup-token (sfss5362 on X), in app.js, with no room added (10-30); 1,538,975 with purposes.js written as compact JSON by genpurposes and the MCP tool purpose in it, 448 bytes less in all (ferock on Discord), lowered to it (10-30); 1,536,586 with the setup-token sheet and Copilot's GHE.com one moved out to signsheets.js, lowered by the 2,389 the setup-token raised it (10-30); 1,536,631 with the 45 bytes b62fa332f added to app.js (Send requests unmasked for subscriptions and plugin providers too) without a raise, with no room added (10-31); 1,537,356 with Settings › Models › Replies › Claude Code's interactive mode, a row beside Short Claude system prompt (the owner), in app.js, with no room added (10-31); Long conversations in Codex's row naming the config.toml keys Codex reads before it, with Take it out, and the window magpie tells Codex for the model it runs (zgjfjfl on Discord) raised it to 1,537,669, and it is back under 1,537,356 with the key list and the window's size written by the server (codexKeysText, tokensSize) and the row's words cut, no raise (10-31); 1,538,554 with the same two, with no room added (10-31); 1,538,678 with About's Log row (rayem1w on X), with no room added (10-31); 1,539,856 with a model's Listed as id (zeewell on X), in app.js, with no room added (10-31); Tuned for you's Codex row offering the advice to background compaction (herman_hong on Discord) and a package manager's magpie naming its command (shuhai on Discord) took it to 1,541,798, and the release notes' dialogs (What's new, the update's ask) moved out to whatsnew.js, loaded when one opens, brought it back under 1,539,856, no raise (10-31); 1,540,479 for Settings › Sync's Kept on this computer row (hayden4608 on Discord) was taken back to 1,539,856 once the core weighed 1,533,355, no raise (10-31); 1,532,958 with the context window card's head naming the agent and the model's lab (the owner), in context.js, after the card's part text viewer moved out to ctxtext.js (7,005 bytes), lowered to it (10-31); 1,533,105 with the provider editor's Claude Code runs as row moved above the accounts, its pill and hover card in claudemode.js, and Settings found at the row that draws anew (the owner), in app.js and i18n.js, with no room added (11-01); a Codex account's credits spent only after every other account, key and fallback (gokoshiki on Discord) fit in it with the Codex options' comments in app.js cut down, no raise (11-01); a plugin option's words in the window's language and the filtered-models note (plugins#590, anewuser6937 on Discord) fit in it with three of the provider editor's comments in app.js cut down, no raise (11-01); 1,533,802 with a closed Mac window telling its page it is out of sight (#4293, pipi-1997), in app.js, which every page needs, its comments cut to one line, with no room added (11-01) + coreScriptBudget = 1_533_802 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added; 1,535,084 with the sidebar's spring, with no room added; 1,549,478 with the context window card's map (tiles by tokens, the default look, the block grid a switch away) and its text view showing an inline image, in context.js, which the Routing page draws as well as Usage, so the core's own, with no room added (10-24); 1,550,768 with a usage card's refresh opening after its text (#840's card, which the tray panel draws too), the Add key spinner, and a dialog kept centred while its content comes in, with no room added (10-24); 1,524,789 with what masking did moved out to Insights › Masking, lowered to it; 1,528,525 with Codex's one subagent model, with no room added (10-24); 1,528,972 with the Image generation MCP server row (JonahFu on X), with no room added (10-25); 1,529,542 with the limit-rest row (zoecats), with no room added (10-25); 1,529,837 with Keep a key's form (Charles Cao on X), with no room added (10-25); 1,530,050 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,530,631 with a plugin's page growing to its README on the dialog's spring instead of in one jump (the owner), the Plugins page's, in plugins.js, with no room added (10-25); 1,533,445 with the context map counting its tokens on as a live request grows, a tile pointed at keeping its tip, a tool's gathered results saying how many and the small files their folder (the owner, after flohoeller's map on X), in context.js, which the Routing page draws as well as Usage, and the 4 bytes 84c50f032 added to app.js (Settings' Version row) without a raise, with no room added (10-25); 1,534,312 with the tray panel's last allowances drawn at once (#3160, #3134), with no room added (10-25); 1,537,016 with many releases' notes merged into one list by kind (the owner), in app.js, with no room added (10-25); 1,542,244 with a plugin's README loading under magpie's bird bouncing down its lines instead of pulsing bars (the owner), the Plugins page's, in plugins.js, with no room added (10-26); 1,542,418 with a page plugin's sidebar tab coming and going as it is installed, switched on or off, or removed, instead of on the Plugins page's next load (the owner), in plugins.js, with no room added (10-26); 1,537,645 with Settings › Observability moved out to plugins/otel, lowered to it (10-26); 1,537,673 with a used window with no reset not "Not used yet" (windy on Discord), and back to 1,537,645 with Settings' model pickers sharing modelOpt (10-26); 1,541,967 with every slow page's skeletons getting magpie's bird (skelBird, the owner), in app.js, the README's bird sharing its drawing and styles, with no room added (10-26); 1,526,251 with Settings' gateway rows moved out to plugins/gateway/settings.js, lowered to it (10-27); 1,526,391 with Test models naming the first failed model and its error (ysm119 on Discord), in app.js, with no room added (10-27); 1,526,556 with About's Website row (the owner), in app.js, with no room added (10-27); 1,526,500 with a pool's cap ticks (plugins#349), in app.js, with no room added (10-28); 1,527,245 with About's Open-source licenses row and dialog (the owner), in app.js, with no room added (10-28); 1,528,076 with the Partners heading's light (the owner), in app.js, with no room added (10-28); 1,530,449 with Install another agent's More in Plugins row (the owner), in app.js, and Plugins opening at its Agents, in plugins.js, with no room added (10-28); 1,530,807 with layout.js measuring the scrollbar into --bar, which every page's right padding takes off so its sides match (the owner), the window's own shell, with no room added (10-28); 1,530,861 with More in Plugins in sight while Install another agent is folded (the owner), in app.js, with no room added (10-29); 1,532,830 with waitsBack and backAfterLoad (issennknight, macOS 13), the window's own scroll guard, in app.js, with no room added (10-29); the context map's tile wording (a4e929212) and Cindy's Add magpie (628ac36fc) had taken the core over it, and Web search's rows moved out to plugins/search/settings.js brought it back to 1,530,861 (#4133, 10-29); 1,532,459 with a provider editor's account rows on one line each, First or Make first at its right end and the settings that aren't set under ⋯ (the owner), the core's own editor, in app.js, which stays in its budget with its comments cut down, with no room added (10-29); 1,532,602 with a plugin's README waiting for its bird to land on three lines before it goes in, however soon it came (the owner, 10-30), in plugins.js, with no room added; 1,536,357 with Switch accounts only on the Agents row (the owner on X), in app.js, with no room added (10-30); 1,537,034 with a plugin's README read once shown at once, with no bird, when its page opens again and read again behind it, the last 20 kept (the owner), in plugins.js, with no room added (10-30); 1,539,423 with a Claude account added from a setup-token (sfss5362 on X), in app.js, with no room added (10-30); 1,538,975 with purposes.js written as compact JSON by genpurposes and the MCP tool purpose in it, 448 bytes less in all (ferock on Discord), lowered to it (10-30); 1,536,586 with the setup-token sheet and Copilot's GHE.com one moved out to signsheets.js, lowered by the 2,389 the setup-token raised it (10-30); 1,536,631 with the 45 bytes b62fa332f added to app.js (Send requests unmasked for subscriptions and plugin providers too) without a raise, with no room added (10-31); 1,537,356 with Settings › Models › Replies › Claude Code's interactive mode, a row beside Short Claude system prompt (the owner), in app.js, with no room added (10-31); Long conversations in Codex's row naming the config.toml keys Codex reads before it, with Take it out, and the window magpie tells Codex for the model it runs (zgjfjfl on Discord) raised it to 1,537,669, and it is back under 1,537,356 with the key list and the window's size written by the server (codexKeysText, tokensSize) and the row's words cut, no raise (10-31); 1,538,554 with the same two, with no room added (10-31); 1,538,678 with About's Log row (rayem1w on X), with no room added (10-31); 1,539,856 with a model's Listed as id (zeewell on X), in app.js, with no room added (10-31); Tuned for you's Codex row offering the advice to background compaction (herman_hong on Discord) and a package manager's magpie naming its command (shuhai on Discord) took it to 1,541,798, and the release notes' dialogs (What's new, the update's ask) moved out to whatsnew.js, loaded when one opens, brought it back under 1,539,856, no raise (10-31); 1,540,479 for Settings › Sync's Kept on this computer row (hayden4608 on Discord) was taken back to 1,539,856 once the core weighed 1,533,355, no raise (10-31); 1,532,958 with the context window card's head naming the agent and the model's lab (the owner), in context.js, after the card's part text viewer moved out to ctxtext.js (7,005 bytes), lowered to it (10-31); 1,533,105 with the provider editor's Claude Code runs as row moved above the accounts, its pill and hover card in claudemode.js, and Settings found at the row that draws anew (the owner), in app.js and i18n.js, with no room added (11-01); a Codex account's credits spent only after every other account, key and fallback (gokoshiki on Discord) fit in it with the Codex options' comments in app.js cut down, no raise (11-01); a plugin option's words in the window's language and the filtered-models note (plugins#590, anewuser6937 on Discord) fit in it with three of the provider editor's comments in app.js cut down, no raise (11-01); 1,533,802 with a closed Mac window telling its page it is out of sight (#4293, pipi-1997), in app.js, which every page needs, its comments cut to one line, with no room added (11-01); Warm up on a Codex or Claude account's Usage card (01huadalang on Discord), in plugins/usage/page.js, its one call in app.js paid for by two comments cut, no raise (11-01) ) func TestCoreScriptBudget(t *testing.T) { diff --git a/internal/gui/tests/quota-warm.test.cjs b/internal/gui/tests/quota-warm.test.cjs new file mode 100644 index 000000000..37c6959ed --- /dev/null +++ b/internal/gui/tests/quota-warm.test.cjs @@ -0,0 +1,147 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// Warm up on the Usage page's card (01huadalang on Discord: many Codex +// accounts, one to start its 5-hour countdown by hand, looked for on the +// card, not in Settings): a Codex or Claude account whose 5-hour window +// isn't running has a Warm up on its line, which sends that account the +// request Settings' Warm up now sends (POST /api/warm-now {agent, user}). +// Not running: nothing used and its reset a whole window away, a reset gone +// by, or a Claude account with no window read. One running, or an account +// magpie isn't signed in to, has none. Once warmed it goes; refused, the +// reason is in the status line and the button comes back. en, zh, zh-TW, +// ja, de at 1100px and 390px; 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 now = Date.now(); +const iso = (ms) => new Date(ms).toISOString(); +const H = 3600e3; +const quotas = [ + // not started: nothing used, its reset five hours away + { provider: "codex", name: "Codex", icon: "codex-color", plan: "Plus", user: "idle-account-with-a-long-name@example.com", lastServedAt: iso(now), windows: [{ name: "5 hours", used: 0, resetsAt: iso(now + 5 * H) }, { name: "7 days", used: 12, resetsAt: iso(now + 50 * H) }] }, + // running + { provider: "codex", name: "Codex", icon: "codex-color", plan: "Pro", user: "busy@example.com", windows: [{ name: "5 hours", used: 30, resetsAt: iso(now + 2 * H) }, { name: "7 days", used: 40, resetsAt: iso(now + 50 * H) }] }, + // its reset gone by: started over from nothing + { provider: "codex", name: "Codex", icon: "codex-color", plan: "Plus", user: "Ran-Out@Example.com", windows: [{ name: "5 hours", used: 100, resetsAt: iso(now - H) }] }, + // unused, but started a while ago: running + { provider: "codex", name: "Codex", icon: "codex-color", plan: "Plus", user: "zero@example.com", windows: [{ name: "5 hours", used: 0, resetsAt: iso(now + 3 * H) }] }, + // not one magpie is signed in to + { provider: "codex", name: "Codex", icon: "codex-color", plan: "Plus", user: "elsewhere@example.com", windows: [{ name: "5 hours", used: 0, resetsAt: iso(now + 5 * H) }] }, + // a Claude account never used: no window read + { provider: "claude", name: "Claude Code", icon: "claude-color", plan: "Max", user: "claude@example.com", windows: [] }, +]; +const WHY = "429 Too Many Requests: usage limit reached"; + +function serve(lang, asked) { + const settings = { lang, theme: "light", currency: "usd", codexUsers: ["idle-account-with-a-long-name@example.com", "busy@example.com", "ran-out@example.com", "zero@example.com"], claudeUsers: ["claude@example.com"] }; + const state = { agents: [], profiles: [], settings }; + return async (r) => { + const url = new URL(r.request().url()); + const json = (data, status = 200) => r.fulfill({ status, json: data }); + if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` }); + if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json(state); + if (url.pathname === "/api/settings") return json(settings); + if (url.pathname === "/api/warm-now") { + const b = r.request().postDataJSON(); + asked.push([b.agent, b.user]); + return b.agent === "claude" ? json({ error: WHY }, 400) : json({ ok: true }); + } + if (url.pathname === "/api/gateway/trace") { + if (url.searchParams.get("wait")) return new Promise(() => {}); + return json({ mine: true, now: new Date().toISOString(), seq: 0, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] }); + } + if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] }); + if (url.pathname === "/api/groups") return json({ models: [], groups: [], pools: [] }); + if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } }); + if (url.pathname === "/api/usage/quotas") return json(quotas); + 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 r.fulfill({ body: await fs.readFile(file), contentType }); } catch { await r.fulfill({ status: 404, body: "" }); } + }; +} + +const W = { + en: { go: "Warm up", tip: "The 5-hour window hasn't started", done: "Warmed up idle-account-with-a-long-name@example.com", failed: "Couldn't warm up claude@example.com: " }, + zh: { go: "预热", tip: "5 小时窗口还没开始", done: "已预热 idle-account-with-a-long-name@example.com", failed: "claude@example.com 预热失败:" }, + "zh-TW": { go: "預熱", tip: "5 小時視窗還沒開始", done: "已預熱 idle-account-with-a-long-name@example.com", failed: "claude@example.com 預熱失敗:" }, + ja: { go: "ウォームアップ", tip: "5 時間枠はまだ始まっていません", done: "idle-account-with-a-long-name@example.com をウォームアップしました", failed: "claude@example.com をウォームアップできませんでした: " }, + de: { go: "Vorwärmen", tip: "Das 5-Stunden-Fenster hat noch nicht begonnen", done: "idle-account-with-a-long-name@example.com vorgewärmt", failed: "claude@example.com konnte nicht vorgewärmt werden: " }, +}; +const launch = (engine) => engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }); +// the account line's Warm up, by the account +const warmOf = (page, user) => page.locator(".subscription-account", { has: page.locator(`[title="${user}"]`) }).locator("button.acct-warm"); +// nothing on an account's line runs past its card, nor the page sideways +const sideways = (page) => page.evaluate(() => { + const out = []; + const de = document.documentElement; + if (de.scrollWidth > de.clientWidth) out.push("page"); + for (const b of document.querySelectorAll(".acct-warm")) { + const c = b.closest(".subscription-card").getBoundingClientRect(), r = b.getBoundingClientRect(); + if (r.right > c.right + 0.5 || r.left < c.left - 0.5) out.push(b.closest(".subscription-account").dataset.card); + } + return out; +}); + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of Object.keys(W)) { + const w = W[lang]; + for (const width of [1100, 390]) { + test(`${engine} ${lang} ${width}px: Warm up on an account's card whose 5 hours haven't started`, async (t) => { + const browser = await launch(engine); + let page; + t.after(async () => { + if (process.env.ARTIFACT_DIR && page) { + await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true }); + await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `quota-warm-${engine}-${lang}-${width}.png`), fullPage: true }); + } + await browser.close(); + }); + page = await (await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" })).newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = [], asked = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang, asked)); + await page.goto("http://magpie.test/?view=usage"); + + const idle = warmOf(page, "idle-account-with-a-long-name@example.com"); + await idle.waitFor(); + assert.equal((await idle.innerText()).trim(), w.go); + assert.ok((await idle.getAttribute("title")).startsWith(w.tip), await idle.getAttribute("title")); + await warmOf(page, "Ran-Out@Example.com").waitFor(); + await warmOf(page, "claude@example.com").waitFor(); + for (const u of ["busy@example.com", "zero@example.com", "elsewhere@example.com"]) { + assert.equal(await page.locator(".subscription-account", { has: page.locator(`[title="${u}"]`) }).count(), 1, u + "'s line is there"); + assert.equal(await warmOf(page, u).count(), 0, u + " has no Warm up"); + } + assert.equal(await page.locator(".acct-warm").count(), 3); + assert.deepEqual(await sideways(page), []); + assert.deepEqual(asked, [], "drawing it sent nothing"); + + // pressed: that account alone, and it goes once warmed + await idle.click(); + await page.waitForFunction((s) => document.querySelector("#status")?.textContent.includes(s), w.done); + assert.deepEqual(asked, [["codex", "idle-account-with-a-long-name@example.com"]]); + await idle.waitFor({ state: "detached" }); + assert.equal(await page.locator(".acct-warm").count(), 2); + + // refused: the vendor's reason in the status line, and it can be pressed again + const claude = warmOf(page, "claude@example.com"); + await claude.click(); + await page.waitForFunction((s) => document.querySelector("#status")?.textContent.includes(s), w.failed + WHY); + assert.deepEqual(asked.at(-1), ["claude", "claude@example.com"]); + await page.waitForFunction(() => { const b = [...document.querySelectorAll(".acct-warm")].find((x) => x.closest(".subscription-account").textContent.includes("claude@example.com")); return b && !b.disabled; }); + assert.equal(asked.length, 2); + assert.deepEqual(await sideways(page), []); + assert.equal(await page.locator("select").count(), 0); + assert.deepEqual(errors, []); + }); + } + } +}