gui: Hide accounts leaves the user's own account names and plans in sight (#3656)
With Hide accounts (账号打码) on, the name a user gave an account (#1515) was blurred like the account, so faketrader's several Antigravity accounts couldn't be told apart; and an Antigravity account whose value is "Google" blurred "Google" of its plan "Google AI Pro" on Usage and on the Providers row. The name the user gave an account is shown text, not an identity. The account is. - provider: a card's Alias says whether it is the user's own name (SubscriptionQuota.Named, set by withAccountNames from AccountNameOf), since Alias is also a plugin's name for an account (PluginUserOf, a masked phone, #4416) or a seat's key plan, and the Usage page and tray panel may have no /api/providers to tell them apart. labelProvider is AccountLabelOf's "plugin:" lookup, shared. - app.js names(): the user's own names (accountNames) and named aliases are no longer accounts to hide; accountUsers, an unnamed alias and a seat still are (noteAccounts keeps an alias without named). - app.js mask(): labels are scoped by element, never by value (LESSONS: scope an exemption by where the value sits). In .own-name, .plan, .acct-plan (the Providers row's plan pill, new class), .model-value and .subscription-head > b only an address is hidden; a plan's and a model's tooltip too (TIPS). The own name's tooltip ("name · account") is masked in full. - .own-name is set only where the text is the user's own: the editor's rename span when it has one (else it shows the raw account and stays hidden), Usage's quota-alias and the panel's pq-user when q.named. From skygunner's patch (95c0511 on19253f67), changed: - Its .acct-who .rename exemption showed a raw non-email account (the rename span shows the account when it has no name of the user's). Now only an own-name span is exempt. - Its [title]:not(LABELS) skipped those elements' tooltips altogether, so the address in "alias · user" (quota-alias, rename) went unmasked. Tooltips are masked; only a plan's or model's hides just an address. - Dropping every alias from names() would have shown a plugin's name for an account (#4416 came after the patch's base). Named tells the user's own apart. - The n.data.length < 2 skip the patch removed is kept. - Its test is rewritten on the new fixtures: an unnamed plugin alias, an address in a plan, the editor with and without an own name, the panel, a model value, tooltips. account-alias.test.cjs and account-eye.test.cjs said Hide accounts hides the user's own name; they now say it stays in sight, the accounts still hidden. account-alias brings the window's page to the front before clicking #usageMask, and the panel's before waiting on it: behind the panel's page it gets no frames and the click waited for one, red 5 times in 2 runs atfb3942ee6(#2984's account-alias half), 0 in 100 after. Not changed: the tray panel card's tooltip is one string of account and plan, so a plan word that equals an account's value is still hidden there (#4677). OpenCode Zen's "Signed in as <account>" in the issue's screenshot is the raw account, hidden as before. Core scripts: app.js's own comments in the masking module are cut, so the core is 742 bytes under its budget at the pushed head (no raise). What was run: - At this on4c815ac2a, on mote (then rebased onto39bade71d, whose 8 commits change only i18n.js and plugins/gateway/settings.js; the budget measured again, 742 under): gofmt -l; go vet of provider, gui, usageapi; go test -tags nogui ./internal/provider ./internal/usageapi ok; TestCoreScriptBudget ok; the 19 masking GUI files (account-*, mask-*, masking-records, privacy-*, provider-mask, provider-unmasked, routing-masking, window-mask, click-scroll, i18n-keys), both engines: 539/540. The red was account-alias's panel wait behind the window's page, fixed by the panel bringToFront above. account-alias + account-mask-alias-plan after it: 4 runs, 159/160 (one red in "renamed in place", whose body this change doesn't touch, #4749). account-alias 6 more runs: 120/120 here, 117/120 on origin/main90c02326b(#2984). - account-mask-alias-plan: 20/20 on the fix (Chromium, WebKit; en, zh, zh-TW, ja, de; 1100 and 420), 20/20 red atfb3942ee6(the alias is masked); red with the plan selectors taken out of LABELS by hand. account_plugin_user_test red with Named always false by hand. - At 4eeba1ca6 (this on90c02326b): go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., go build for darwin, linux (nogui) and windows: ok. go test -tags nogui ./... on the Linux box: every package ok except internal/agent (8 install tests red the same on origin/main there, #4033, #3548) and internal/gui (TestSettingsSaveKeepsWhatItDoesNotSend, red on main, #4514; TestColdTurnsTaken on mote once, #4510). The whole GUI suite on the Linux box, 6 wide: 16857 pass, 491 fail in 100 files, none of them the masking files but account-every-reset; being run against origin/main to sort. Co-authored-by: skygunner <84759+skygunner@users.noreply.github.com> Co-authored-by: vincent <vincent@users.noreply.github.com> Co-authored-by: Fake Trader <9635792+faketrader@users.noreply.github.com>
This commit is contained in:
co-authored by
skygunner
vincent
Fake Trader
parent
39bade71d1
commit
9097687a31
@@ -458,7 +458,7 @@ covers it in both engines, every language and a narrow window.
|
||||
- In Usage → Allowances, Trends → Cycle offers each account's own recorded cycle menu beside its curve (`quotaCurve`, `quotaRecordedCycles` in [`app.js`](../../internal/gui/assets/app.js)). The longest window (usually weekly) owns the menu; shorter windows are drawn over the selected dates with their own reset breaks. `/api/usage/quotas/history?days=45` supplies all retained readings, including remote cards. Completed cycles come from observed boundaries, not seven-day arithmetic; an early reset ends the previous cycle at the vendor's new start if it fits between readings, otherwise at the first new reading. Each menu option gives its observed duration, so an early reset is not labelled as a full seven days. The selected meters, plot, legend, tooltip and dashed pace use that cycle's last readings, never today's percentages. A window without a reading in the selected interval says so instead of showing a current value. A local account's past cycle asks `/api/usage/quotas/history/holds?provider=&user=&from=&to=` once per selection (`quotaCycleHoldsOf`), which asks no vendor (#2009, NorethSea): `HistoricalWindowHolds` in [`window_holds_history.go`](../../internal/usage/window_holds_history.go) reckons each window's whole at its own last reading in that cycle, from the request log up to that reading, so the 5-hour figure is the cycle's last 5-hour window, never its short windows added up. Its tooltip names that window's start and the reading's time. It shows "Loading…" until the answer comes. A window it can't reckon says "not enough data" with the reason, as a current card does; a reply that comes after another cycle was picked is dropped, and a card's Refresh or an asked read reckons again. Historical meters show the cycle end and sampling time; current account actions, balances and policies are left out until returning to the current view. Accounts are independent, and a selection survives card refreshes in the same page. Trends → 2 days temporarily shows recent readings; Off removes the curves; the tray always shows its current cycle. See `quota-curve.test.cjs` and the [history limits and reset inference](providers-accounts.md#constraints-and-failure-behavior).
|
||||
- The Usage page's cards are packed into columns, never all stretched to a row's height (`packUsage`, #860): each card in that order goes to the leftmost column that ends highest, on 1px grid rows, so short cards stack beside a tall one. The last card in each column then reaches down to where the tallest column ends (a `min-height`, cleared before the cards are measured again), so cards side by side in one row are as tall as each other and a stack ends with the tall card beside it (ikunbots on X); content stays at each card's top. The page's order (DOM, dragging, Alt+arrows) stays `UsageOrder`. The column count is the most 260px columns that fit, or one fewer when that leaves much less empty room; it is chosen again only when the cards change or the width fits another number of columns, so a card opened or folded stays where it is, even as the scrollbar comes in. See `usage-pack.test.cjs`.
|
||||
- The Providers page has a search box over its list (#1614, `findProviders` in [`app.js`](../../internal/gui/assets/app.js)): the words typed keep the rows, on and off, whose text or data say them all: name, id, preset, addresses, every model's id and name, the account's user and plan and each login's, account names and key names. The Turned off fold stays open while searching; Escape or clearing the box shows every row and the fold as it was. A row that is on reorders by dragging its logo, Alt+↑/↓, Alt+Shift+↑/↓ (top, bottom) or its right-click menu (`openProviderMenu`: Move to top, Move up, Move down, Move to bottom). While searching, a step or a drop moves it among the rows shown (it takes the place of the row it passes, `stepProvider`, `shownToOn`) and the hidden ones keep their order; Move to top and Move to bottom go to the ends of the whole list. Every move saves the whole order through `POST /api/providers/arrange`. See `provider-find.test.cjs` and `provider-order.test.cjs`.
|
||||
- Hide accounts (`window.hideAccounts` at the end of [`app.js`](../../internal/gui/assets/app.js)) masks every account name and address in the window's text and tooltips, its menus and dialogs too, by the switch of the page in sight (`cur`, again on each `show`). Routing's and Usage's buttons, and Settings › Privacy's row, are one switch, stored in `magpie.maskEmails`, which the panel follows; the Providers page has its own (`#pvMask` beside its search box, `magpie.maskProviders`), so Routing's leaves Providers alone (a Discord user in #feedback). A `magpie.maskProviders` not stored yet starts from `magpie.maskEmails`, so one who had it on before keeps Providers hidden; while neither is chosen, both follow Mask personal data, and turning that on (`set(true, true)`) turns both on (`provider-mask.test.cjs`). While it is on, an account's name on the provider editor's row (`accountNameButton`, and the one-account line) and on its Usage card (`quotaWho`), and on the tray panel's Usage card (`panelQuotaCard`'s `.pq-who`, in sight while the card is hovered), has an eye (`hideAccounts.eye`), in sight on hover or keyboard focus. A click shows that one account, its address and the name the user gave it together (`kin`), everywhere that page draws it, tooltips included, while the others stay hidden (yogurt36 on Discord, for a screen share). The accounts shown are a set held in memory that `hits()` skips; nothing stores them. The window and the panel are pages of their own, each with its own set: one shown in the window stays hidden in the panel and the other way round, so a screenshot of either shows only what was shown there. Closing the window hides them again: the page stays loaded while the window is hidden, so `hideMain` runs `mainClosedJS` (`hideAccounts.closed`) first. Putting the panel away hides the panel's again, from its `visibilitychange` (the one that drops `panelPeek`) (`account-eye.test.cjs`, `TestClosingHidesShownAccounts`).
|
||||
- Hide accounts (`window.hideAccounts` at the end of [`app.js`](../../internal/gui/assets/app.js)) masks every account name and address in the window's text and tooltips, its menus and dialogs too, by the switch of the page in sight (`cur`, again on each `show`). Routing's and Usage's buttons, and Settings › Privacy's row, are one switch, stored in `magpie.maskEmails`, which the panel follows; the Providers page has its own (`#pvMask` beside its search box, `magpie.maskProviders`), so Routing's leaves Providers alone (a Discord user in #feedback). A `magpie.maskProviders` not stored yet starts from `magpie.maskEmails`, so one who had it on before keeps Providers hidden; while neither is chosen, both follow Mask personal data, and turning that on (`set(true, true)`) turns both on (`provider-mask.test.cjs`). While it is on, an account's name on the provider editor's row (`accountNameButton`, and the one-account line) and on its Usage card (`quotaWho`), and on the tray panel's Usage card (`panelQuotaCard`'s `.pq-who`, in sight while the card is hovered), has an eye (`hideAccounts.eye`), in sight on hover or keyboard focus. A click shows that one account, its address and the name the user gave it together (`kin`), everywhere that page draws it, tooltips included, while the others stay hidden (yogurt36 on Discord, for a screen share). The accounts shown are a set held in memory that `hits()` skips; nothing stores them. The window and the panel are pages of their own, each with its own set: one shown in the window stays hidden in the panel and the other way round, so a screenshot of either shows only what was shown there. Closing the window hides them again: the page stays loaded while the window is hidden, so `hideMain` runs `mainClosedJS` (`hideAccounts.closed`) first. Putting the panel away hides the panel's again, from its `visibilitychange` (the one that drops `panelPeek`) (`account-eye.test.cjs`, `TestClosingHidesShownAccounts`). What it hides is the accounts: their addresses, their vendors' values (`user`, `account`, Routing's `who`) and a name that stands for one, a plugin's (`accountUsers`, a card's `alias` without `named`) or a seat's. The name the user gave an account (`AccountNames`; a card's `alias` with `named`, which `withAccountNames` sets) is no account and stays in sight, beside the account it names, hidden (faketrader in #3656: several accounts couldn't be told apart). A label is scoped by its element, never by its value: in the user's own name (`.own-name`), a plan (`.plan`, the Providers row's `.acct-plan`), a model (`.model-value`) and a Usage card's title (`.subscription-head > b`) only an address is hidden, so an Antigravity account whose value is "Google" leaves "Google AI Pro" readable while an address written in a plan is still hidden; the same holds for the tooltips of plans and models (`TIPS`), not for the own name's, which says the account (`LABELS` in app.js, `account-mask-alias-plan.test.cjs`). The tray panel card's tooltip joins the account and the plan in one string, and still hides a plan's word that is an account's value.
|
||||
- A new user's Agents page (the window's first page and the panel's Agents tab) has a *Get started* card above the agents in the welcome's place (wangye1644294 on X, `guideCard` in [`app.js`](../../internal/gui/assets/app.js)). Its three steps are: add a model source; connect an agent, where the agents magpie found that can be connected are named and each is connected in one click (`agents/connect`); and, optional, a routing group, with the most harmless starter template that can be made from the user's models (`provider.Templates`, Never stuck first) added in one click through `POST /api/groups/template`. Every tick comes from the state: the models magpie serves (`served` in `/api/state`, groups left out), an agent wired, or a group that isn't automatic. None comes from the card having been seen. The card goes once the first two steps are done. Its close button saves `settings.GuideHidden` through `POST /api/settings/guide`, so the panel, the window and a reload agree, and the Settings save keeps it. See `getting-started.test.cjs`.
|
||||
- A connected agent's row in the window opens and closes on a click anywhere on it that isn't one of its controls, as a disclosure row does on the Mac (NG_shiyu on X, `connectRow` in [`app.js`](../../internal/gui/assets/app.js)): the click is handed to the row's *Models {n}* link (`expandLink`), which stays the control the keyboard and a screen reader use and keeps `aria-expanded`. Buttons, links, inputs, anything with a role, the grip and the opened sheet (`.ag-exp`) keep their own clicks, and a click that ends a text selection does nothing. The panel's rows did this already (`agent-row-disclose.test.cjs`).
|
||||
- An agent whose own model menu is the list picked in magpie (ZCode, Claude Desktop, Cursor Private Inference, …: `listsMenu`) says that list as its ticks are, on its button and on the panel row (`menuSaid` in [`app.js`](../../internal/gui/assets/app.js)): every model ticked is *All N models*, one or two by their names, more as *Showing x / N models*, none as *No models*. It never says the first names and a +N: routing groups come first, so that read as a pick of one group and one model while every model was on (NG_shiyu on X). Other agents' start pickers still say the one model or group they start on (`agent-menu-label.test.cjs`).
|
||||
|
||||
@@ -67,7 +67,7 @@ keys and accounts per request is in [Gateway routing and fallback](gateway-routi
|
||||
| A lab's models | models.dev keeps two catalogs: `api.json`, each provider's models with that host's prices, and `models.json`, each lab's models with only what is the model's on every host (name, window, reply limit, thinking, inputs, release), no price. `Sync` keeps the second beside the first as `labs.json` (`LabsPath`, `syncLabs`: best effort, through a rename, a failed fetch keeping the last; a catalog with none beside it is `Stale` once a process, so it comes at the next look). A model only a lab lists, no provider (models.dev took the gated Claude Mythos 5.1 out of anthropic's list in #11327 and kept its lab file), is voted into the same tables as a listed one (`loadGen`, `labs`), so `ContextOf`, `OutputOf`, `NameOf`, `Thinks`, `SeesImages` and every entry built on them know it wherever a vendor's or an account's list has it; a thinking one with no levels takes the levels of the newest of its family a provider gives them (`labKinEfforts`: Mythos 5.1 takes Mythos 5's). A model a provider lists keeps what providers say of it. `catalog.Describe` builds a model from these for a list that names an id alone. `TestLabOnlyModelIsKnown`, `TestLabsLeaveListedModels`, `TestSyncKeepsLabs`, `TestAnthropicKeyGatedModelDescribed` (iebb on Discord). | [`labs.go`](../../internal/catalog/labs.go), [`catalog.go`](../../internal/catalog/catalog.go) |
|
||||
| A Claude account's models | magpie never asks Anthropic with a Claude sign-in, so a Claude account's list is models.dev's anthropic list and what Anthropic told the account's Claude Code beyond it. Claude Code keeps that in its `.claude.json` from its own bootstrap: `additionalModelOptionsCache` (models its /model picker offers beyond its own; a `null` value or a `disabled` one is not a model), `modelAccessCache` (`entitled` per API id) and `additionalModelCostsCache` (Anthropic's prices). `claudeModels` reads the file of Claude Code's own sign-in (`claudeProfilePath`) and of each saved account's directory (`claudeAccountDir`), through `filememo`, and adds each model none of them lists, described by `catalog.Describe` and priced as Anthropic told it. `Account.Lists` for a Claude account goes by its own file (`claudeLists`: the saved directory's, or Claude Code's own when its `oauthAccount` is that account, the one Anthropic answered last): a model it isn't entitled to is out, so routing tries the accounts entitled to a gated model first; with no file, every model is taken to be in, as before. `ListPrice` of a provider whose catalogs include anthropic falls back to that price after every catalog (`claudeCodePrice`). The agent's own Claude Code model picker (`claudeOwn`) offers what `ClaudeCodeModels` gives for the account signed in here; a WSL distro's keeps the catalog's. Not done: a Claude Code that never started on a saved account has no file, so its gated models show only once it has run there. `TestClaudeAccountListsGatedModels`. | [`claude_code_models.go`](../../internal/provider/claude_code_models.go), [`account.go`](../../internal/provider/account.go), [`codex_models.go`](../../internal/provider/codex_models.go), [`claude.go`](../../internal/agent/claude.go) |
|
||||
| A key's own windows | A sub2api key given a spending limit per 5 hours, day or 7 days answers its `/v1/usage` with `rate_limits` and no `remaining` (`readSub2APIKeyLimits`). With the Balance URL set to it, the key's card shows them as the windows *5 hours*, *1 day*, *7 days*, in USD, beside a balance field the user wrote; *Check balance* and `magpie provider show` give what its fullest window has left (`Balance`). A Balance URL at an account query left without its token (a sub2api panel's `/api/v1/user/profile`, new-api's `/api/user/self`, after the token was removed) asks the same panel's query for the key instead, the saved URL untouched (`keyQueryOf`, `BalanceQuery`), unless the user's Headers carry an Authorization or Cookie of their own. A Balance URL of the user's own is asked with GET, or with POST and no body when the provider's `BalanceMethod` says so (#2368: an endpoint that answers only a POST; the editor's GET/POST beside the URL, `balance.method=` on the command line); any other method is refused before anything is sent (`balanceMethodOf`). `KeyAllowance` gives routing the same windows: never waited for, read in the background at most once a minute, a failed read keeping the last, and seeded from the card's last reading (`quotas.json`) after a restart. A key bought as a plan (Kimi Code, GLM Coding Plan and Z.ai, MiniMax Coding Plan, OpenCode Go, Command Code, Ollama Cloud: `planQuotaSourceOf`) gives routing its card's windows the same way (`planKeyWindows`, Zhipu's team quota behind a key with none of its own); the Usage page's read of its card is taken at once (`noteKeyAllowance`), and a key there that turns out pay-as-you-go, with no windows, is asked again only every 30 minutes (`keyNoWindowsAge`). Kimi Code's `/usages` (`readKimiCode`) is read as kimi-cli and kimi-code read it: the week's `usage` and each `limits[]` window as counts, and the shares in `usages` (`limit_5h`, `limit_7d`, and `limit_month_total` as a *Month* window renewing at its `reset_time`, lidazi2016 on Discord); a window told both ways is the share's, and `limit_month_code`, the part of the month code used, is no window. `TestReadKimiCode`, `TestReadKimiCodeMonth`. A Command Code plan's key has its month of credits as a *Credits* window beside the 5-hour and weekly ones, as the signed-in subscription's card has (`cmdKeyWindows`, #2451): billing/credits leaves the plan out, so it is the key's billing/subscriptions plan, asked at most every ten minutes and the last one kept while it can't be read; the same reply's period end is the Credits window's reset, left off once it has passed (#2454); a key whose plan was never read has its two windows alone. Ollama Cloud's `ollama.com/api/balance` (#1888, `readOllamaPlan`) tells the plan's included allowance as one window in USD, *Month* when its period is a month long, renewing at `period.until`, and Aside while credits bought on top are left; those credits are the key's balance card (`readOllamaCredits`), and a reply that names none has no balance card rather than $0. StepFun's Step Plan is read through a platform sign-in, not the key, and isn't one of them: the sign-in is the provider's own, kept by provider id in `stepfun-auth.json` (two StepFun providers on one site can be two accounts, #2384), one card per signed-in provider; a file from before that, kept by site, is given on read to the StepFun providers on that site (`stepfunBySite`), and copies of one sign-in are renewed together. Nor are Volcengine Ark's Coding Plan and Agent Plan (#1427): their 5-hour, weekly and monthly windows are told only to the account's access key (`AccessKeyID`, `SecretAccessKey`), asked of `open.volcengineapi.com` (`GetCodingPlanUsage`, `GetAFPUsage`) and signed as Volcengine's own SDK signs (`volcSign`), so they are cards on the Usage page (`volcPlanQuotas` in `PlanQuotas`), never routing's windows. Nor is Tencent Cloud's Token Plan 企业版 (#1574): what a team plan has used of its cycle's credits (专业套餐) or tokens (轻享套餐) is told only to the account's SecretId and SecretKey (kept as `AccessKeyID`, `SecretAccessKey`), asked of `tokenhub.tencentcloudapi.com` (`DescribeTokenPlanList`, `DescribeTokenPlan`, version 2026-03-22) and signed TC3-HMAC-SHA256 (`tc3Sign`), one card per team plan (`tencentPlanQuotas`). | [`sub2api_usage.go`](../../internal/provider/sub2api_usage.go), [`key_allowance.go`](../../internal/provider/key_allowance.go), [`volcengine_usage.go`](../../internal/provider/volcengine_usage.go), [`tencent_usage.go`](../../internal/provider/tencent_usage.go) |
|
||||
| Account names and seats | `AccountNames` (by the account, in lower case, like `AccountCaps`) are names the user gives accounts, set by `SetAccountName` (GUI `provider/accountname`, `magpie accounts alias`); they live in providers.json only, never in a vendor's or plugin's sign-in. A name picks its account wherever the account's own name does (`AccountByName`): the CLI's `accountNamed` (switch, forget, alias), the pool's `--accounts`, and `accountRef` (caps, models, weights, concurrency) after an exact name. It is refused when two accounts have it or it is another account's email or name, so it never picks by guess; `accountRef` then finds no account, as the GUI passes exact names (StringKe in #4532, `TestAccountsAliasPicksTheAccount`). A GLM Coding Plan read with a key (`glmPlan`) and a ZCode account (built-in or `zcode-plugin`) whose windows' resets agree are one seat (`seatMatch`, #90/#953), shown once, on the account's card (`seatCards`, used by `quotas`, `Allotted` and `CachedCards`). A match is remembered in `seats.json` beside `quotas.json`: a failed read or a window with no reset yet is unknown and keeps the key's card off while the account is signed in; windows that disagree forget it (#1515). Cards carry `Seat` (the key provider's name, and the key's when it has several) and `Alias` (the user's name, else `Seat`), as `/v1/magpie/quotas`, `magpie quota` and `magpie accounts` do. Records (a trace's `who`, usage's `ProviderAccount`) keep the vendor's name, the key the user's name is kept by, and every list of them looks the name up as it is shown (`AccountShown`, `AccountShownOf`, `AccountRef.Shown`), so a request from before a rename reads by the new name too: the Routing page's accounts and requests (`userShown` in `plugins/routing/client.js`, from `/api/providers`' `accountNames`), its Several accounts pools (`onOf`), the Usage page's Accounts and the request log's Account filter (`usageapi`), `magpie usage`, and a gateway key's accounts (`AccountNames`, `/api/caller-keys`). Before plugins#310 (a renamed Kiro account read by its old name on every request after) those showed the vendor's name. An account with no name of the user's own goes by the name its plugin's `usage()` gives it (`PluginUserOf`, the `user` of its last read: `loginUsageCache`, else `quotas.json`), else by its id: a Huawei Cloud CodeArts account kept by its IAM id `iam::<domain>:user:<name>` reads as the masked phone its card shows (#4416). `AccountShown`, `AccountShownOf` and `AccountLabelOf` (cards' `Alias`, `magpie accounts`, usageapi's Account filter, the quota alert) apply it, and the GUI has it as `/api/providers`' `accountUsers` (`accountShownOf` in app.js: the editor's rows, the per-account proxy lines, Routing's `userShown`, Hide accounts). The id stays the key everything is kept by; nothing stored changes. A read that fails keeps the last good `user`; nothing read yet, or a plugin whose windows are all model pools (not kept in `quotas.json`) after a restart, is its id until the next read. | [`account_names.go`](../../internal/provider/account_names.go), [`account_seats.go`](../../internal/provider/account_seats.go) |
|
||||
| Account names and seats | `AccountNames` (by the account, in lower case, like `AccountCaps`) are names the user gives accounts, set by `SetAccountName` (GUI `provider/accountname`, `magpie accounts alias`); they live in providers.json only, never in a vendor's or plugin's sign-in. A name picks its account wherever the account's own name does (`AccountByName`): the CLI's `accountNamed` (switch, forget, alias), the pool's `--accounts`, and `accountRef` (caps, models, weights, concurrency) after an exact name. It is refused when two accounts have it or it is another account's email or name, so it never picks by guess; `accountRef` then finds no account, as the GUI passes exact names (StringKe in #4532, `TestAccountsAliasPicksTheAccount`). A GLM Coding Plan read with a key (`glmPlan`) and a ZCode account (built-in or `zcode-plugin`) whose windows' resets agree are one seat (`seatMatch`, #90/#953), shown once, on the account's card (`seatCards`, used by `quotas`, `Allotted` and `CachedCards`). A match is remembered in `seats.json` beside `quotas.json`: a failed read or a window with no reset yet is unknown and keeps the key's card off while the account is signed in; windows that disagree forget it (#1515). Cards carry `Seat` (the key provider's name, and the key's when it has several) and `Alias` (the user's name, else the plugin's, else `Seat`) with `Named` when it is the user's own, which Hide accounts leaves in sight (#3656), as `/v1/magpie/quotas`, `magpie quota` and `magpie accounts` do. Records (a trace's `who`, usage's `ProviderAccount`) keep the vendor's name, the key the user's name is kept by, and every list of them looks the name up as it is shown (`AccountShown`, `AccountShownOf`, `AccountRef.Shown`), so a request from before a rename reads by the new name too: the Routing page's accounts and requests (`userShown` in `plugins/routing/client.js`, from `/api/providers`' `accountNames`), its Several accounts pools (`onOf`), the Usage page's Accounts and the request log's Account filter (`usageapi`), `magpie usage`, and a gateway key's accounts (`AccountNames`, `/api/caller-keys`). Before plugins#310 (a renamed Kiro account read by its old name on every request after) those showed the vendor's name. An account with no name of the user's own goes by the name its plugin's `usage()` gives it (`PluginUserOf`, the `user` of its last read: `loginUsageCache`, else `quotas.json`), else by its id: a Huawei Cloud CodeArts account kept by its IAM id `iam::<domain>:user:<name>` reads as the masked phone its card shows (#4416). `AccountShown`, `AccountShownOf` and `AccountLabelOf` (cards' `Alias`, `magpie accounts`, usageapi's Account filter, the quota alert) apply it, and the GUI has it as `/api/providers`' `accountUsers` (`accountShownOf` in app.js: the editor's rows, the per-account proxy lines, Routing's `userShown`, Hide accounts). The id stays the key everything is kept by; nothing stored changes. A read that fails keeps the last good `user`; nothing read yet, or a plugin whose windows are all model pools (not kept in `quotas.json`) after a restart, is its id until the next read. | [`account_names.go`](../../internal/provider/account_names.go), [`account_seats.go`](../../internal/provider/account_seats.go) |
|
||||
| Last served | `served.json` records when each account, plan or key last answered, shown as `lastServedAt` (#570) on `/v1/magpie/quotas` and on the Usage page's own cards (`Quotas` → `cardsServed`, this computer's cards only, the caches left alone). The Usage page and the tray panel show the last-answered account in full, and a menu bar card that follows the account in use (`codex|*`) takes the one that answered within the last hour, else `InUseLogin`'s guess, else the one that answered last at all (a plugin's accounts, #1516) (`trayInUseCard`; okingkee on X: A spent, B answering, the menu bar stayed on A). `NoteServed` calls `OnServedMoved` when a provider's answers move to another account or key, and `SwitchLogin` after a switch, so the menu bar reads its cards again at once. | [`served.go`](../../internal/provider/served.go), [`trayusage.go`](../../internal/gui/trayusage.go) |
|
||||
| Partners | Services that pay to be listed first in the add sheet, under a heading of their own ("Partners · magpie's sponsors"). The list is `site/partners.js`, served at `usemagpie.ai/api/partners`: a change reaches users with a deploy, not a release. `Partners` never waits: it returns what was fetched last and fetches again behind the call on a process's first ask, whatever the kept list's age, and hourly after (10 minutes after a failure), keeping the list in `partners.json` in the cache folder. The magpie serving the gateway fetches it when it starts and whenever it is due, asked for or not (`KeepPartnersFresh`), so an app left open on another page still learns of a partner added. The file also says when the last fetch started (`tried`) and, when it failed, why (`error`, logged once until a fetch gets the list again), so a list that stops changing tells a fetch that fails from one that never came back (`tried` after `at`, no error) and from none asked (#3362). Each entry is checked again on every read (`validPartners`): its own id, never a built-in preset's, a name, an endpoint, https only, at most 12; what only magpie's presets may set (a decision API, no key, a user endpoint) is cleared. Its logo is fetched through `FetchIcon` and kept as an uploaded icon, used as it is while its `iconUrl` stays the same; the prune after a save of `providers.json` (`pruneIcons`) leaves the logos of the partners listed now (`keptPartnerIcons`), as it leaves a plugin's. A partner is a preset to the rest of magpie (`Preset`, `FromPreset`, the editor), and one no longer listed still is to the providers added from it (`Seen`), without the sponsored mark. The window lists a partner in the languages it names (`langs`) only and shows its tagline in the page's language (`notes`, else `en`). `MAGPIE_PARTNERS` points it elsewhere, `off` lists none; tests list none unless they name a list. How often each listed partner was shown, opened (its row, its key page) and added is counted per UTC day (`CountPartner`, capped at 20 of each and 5 adds, kept in `partner-counts.json` in the cache folder) and sent with the next day's stats event as `magpie partner` events (`internal/stats`); nothing is counted with the stats or their usage part off. A listed partner the add sheet (or the TUI's, or `magpie providers presets`) hasn't shown yet is new (`NoticePartners` keeps those shown, as `noticed` in `partners.json`, whatever the stats); the window's add button carries a small dot for it, with its name in the title, until the sheet shows it. | [`partners.go`](../../internal/provider/partners.go), [`partner_events.go`](../../internal/provider/partner_events.go), [`site/partners.js`](../../site/partners.js) |
|
||||
| Local servers | A preset of `KindLocal` (Ollama, LM Studio, oMLX, MLX-Serve) is at its server's default port on this machine. Another address — a port, or another computer — is given in the window's editor, in its Server address field, shown first above the key and never folded (a folded one read as an LM Studio whose base URL can't be changed, mengxiangziyou on X), or in the TUI (asked on adding, `w` after); on the command line with `address=` (`atAddress` in `providers_cli.go`: every URL moves, from the preset's when the provider was saved with none, and `address=` alone puts a local server back at its preset's), or the URLs themselves (`url=`, `anthropic=`, `responses=`). `AtAddress` replaces only each URL's scheme, host and port, each API keeping its path; `AddressOf` is the address an editor starts from. The window sends the URLs moved only when the address was changed, so a Save doesn't move URLs set apart (another app's import). A provider of the user's own (no preset) has `w` in the TUI too: each base URL it has is asked in turn, typed in as it is, Enter alone keeping one (`customURLsAsk`). | [`local_address.go`](../../internal/provider/local_address.go), [`providers_cli.go`](../../internal/cli/providers_cli.go) |
|
||||
|
||||
+23
-35
@@ -6149,7 +6149,7 @@ function renderProviders(quiet) {
|
||||
} else if (p.account) {
|
||||
// the row names the vendor: a plan too long for the pill goes without it
|
||||
const plan = accountPlan(p.account), bare = plan.startsWith(p.name + " ") ? plan.slice(p.name.length + 1) : "";
|
||||
key = el("span", "key acct", bare && plan.length > 15 ? bare : plan);
|
||||
key = el("span", "key acct acct-plan", bare && plan.length > 15 ? bare : plan);
|
||||
key.title = t("{agent} is signed in; its models are here for every other agent", { agent: p.account.agentName });
|
||||
} else if (p.vertex) {
|
||||
// Vertex AI signs with the user's Google credentials, never a key;
|
||||
@@ -13829,7 +13829,7 @@ function accountNameButton(p, user) {
|
||||
const wrap = el("span", "acct-who");
|
||||
// a span, not a button: the address stays selectable, and a drag that
|
||||
// selects it renames nothing
|
||||
const name = el("span", "n rename", accountShownOf(p, user));
|
||||
const name = el("span", "n rename" + (own ? " own-name" : ""), accountShownOf(p, user));
|
||||
name.tabIndex = 0;
|
||||
name.setAttribute("role", "button");
|
||||
name.title = own || vend ? t("{user} · click to rename", { user }) : t("Name this account");
|
||||
@@ -17464,7 +17464,7 @@ function panelQuotaCard(q) {
|
||||
// in for (#1515), before the account itself
|
||||
// and its eye while Hide accounts is on, as on the Usage page (yogurt36)
|
||||
const who = el("span", "pq-who");
|
||||
who.append(el("span", "pq-user", q.alias || q.user || q.name));
|
||||
who.append(el("span", "pq-user" + (q.alias && q.named ? " own-name" : ""), q.alias || q.user || q.name));
|
||||
if ((q.user || q.alias) && window.hideAccounts) who.append(hideAccounts.eye(q.user || q.alias, q.provider));
|
||||
card.append(who);
|
||||
card.title = [q.name, q.alias, q.user, q.seat && q.seat !== q.alias && "≡ " + q.seat, q.plan, q.until ? planTerm(q) : "", q.balance && t("Balance") + " " + q.balance].filter(Boolean).join(" · ");
|
||||
@@ -24154,42 +24154,30 @@ renderPluginDot();
|
||||
window.addEventListener("focus", renderPluginDot);
|
||||
setInterval(renderPluginDot, 15 * 60 * 1000);
|
||||
// ---------- hiding accounts, for a screenshot to share ----------
|
||||
// Routing and Usage each have a Hide accounts button, one setting for both,
|
||||
// which the tray panel follows too. Each account on the page — an email
|
||||
// address, or a name that isn't one (WorkBuddy's nickname or phone number,
|
||||
// a plugin's account id, #568), in a row, a sentence, a tooltip — is
|
||||
// swapped for blurred stand-in letters while it's on, as the page redraws
|
||||
// too; the account itself is kept aside to put back.
|
||||
//
|
||||
// accountNames are the names of subscription accounts magpie has told the
|
||||
// page of (noteAccounts, from what the API answered), beside the accounts
|
||||
// of the providers and allowances it holds now.
|
||||
// While on, each account on the page (an address, or a name: a nickname,
|
||||
// a phone, a plugin's id, #568) in a row, sentence or tooltip is swapped for
|
||||
// blurred stand-in letters, the account kept aside to put back. accountNames:
|
||||
// the accounts the API's answers named (noteAccounts).
|
||||
const accountNames = new Set();
|
||||
// generic words an account can't be named, lest every one of them on the
|
||||
// page is hidden
|
||||
// "api key" and "signed in" are what magpie calls a plugin's account that
|
||||
// has no name (pluginLabels), "(2)" after one a second such: words of a
|
||||
// sentence too, a plugin's summary among them (outloudvi on Discord: Kiro's
|
||||
// "…or an API key" blurred)
|
||||
// words no account is named, lest each is hidden: "api key", "signed in"
|
||||
// (and "(2)") name a plugin's nameless account (pluginLabels, outloudvi)
|
||||
const NOT_ACCOUNTS = new Set(["default", "own", "desktop", "account", "main", "local", "unknown", "none", "free", "pro", "api key", "signed in"]);
|
||||
function noteAccount(s) {
|
||||
if (typeof s !== "string") return;
|
||||
s = s.trim();
|
||||
if (s.length >= 2 && s.length <= 80 && !/[\n\r]/.test(s)) accountNames.add(s);
|
||||
}
|
||||
// noteAccounts takes the accounts out of an answer of the API: a user, an
|
||||
// account named, or a route's account (kind "account", who)
|
||||
// noteAccounts: an answer's user, account, or route account (kind account)
|
||||
function noteAccounts(x, depth = 0) {
|
||||
if (!x || typeof x !== "object" || depth > 8) return;
|
||||
if (Array.isArray(x)) { for (const v of x) noteAccounts(v, depth + 1); return; }
|
||||
// for…in, not Object.entries: every answer is walked, Routing's trace a
|
||||
// second, and entries made an array for each object and each key in it,
|
||||
// ~8 MB of garbage a minute on Routing alone (#1481)
|
||||
// for…in, not Object.entries: ~8 MB of garbage a minute on Routing (#1481)
|
||||
for (const k in x) {
|
||||
if (!Object.hasOwn(x, k)) continue;
|
||||
const v = x[k];
|
||||
if (typeof v === "string") {
|
||||
if (k === "user" || k === "account" || k === "alias" || (k === "who" && x.kind === "account")) noteAccount(v);
|
||||
// an alias, not the user's own (named, #3656)
|
||||
if (k === "user" || k === "account" || (k === "alias" && !x.named) || (k === "who" && x.kind === "account")) noteAccount(v);
|
||||
} else if (k === "who" && x.kind === "account" && Array.isArray(v)) for (const w of v) noteAccount(w);
|
||||
else if (v && typeof v === "object") noteAccounts(v, depth + 1);
|
||||
}
|
||||
@@ -24214,8 +24202,8 @@ window.noteAccounts = noteAccounts;
|
||||
for (const p of providers?.providers || []) {
|
||||
for (const n of [p.id, p.name, p.account?.agentName, p.account?.agent]) if (n) not.add(String(n).toLowerCase());
|
||||
if (p.account) { all.add((p.account.user || "").trim()); for (const l of p.account.logins || []) all.add((l.user || "").trim()); }
|
||||
// the names the user gave accounts (#1515), as the accounts are
|
||||
for (const n of [...Object.values(p.accountNames || {}), ...Object.values(p.accountUsers || {})]) all.add(String(n).trim());
|
||||
// a plugin's name for one (#4416), not the user's (#3656)
|
||||
for (const n of Object.values(p.accountUsers || {})) all.add(String(n).trim());
|
||||
}
|
||||
// a plugin's provider, signed in or not, is a provider too: its name
|
||||
// on the Plugins page and the add sheet is no account (lileo0668)
|
||||
@@ -24223,7 +24211,7 @@ window.noteAccounts = noteAccounts;
|
||||
for (const q of quotas || []) {
|
||||
for (const n of [q.provider, q.name, q.plan]) if (n) not.add(String(n).toLowerCase());
|
||||
all.add((q.user || "").trim());
|
||||
if (q.alias && q.alias !== q.seat) all.add(q.alias.trim());
|
||||
if (q.alias && !q.named && q.alias !== q.seat) all.add(q.alias.trim());
|
||||
}
|
||||
for (const a of state?.agents || []) for (const n of [a.id, a.name]) if (n) not.add(String(n).toLowerCase());
|
||||
return [...all].filter((n) => n.length >= 2 && !IS_EMAIL.test(n) && !not.has(n.toLowerCase().replace(/ \(\d+\)$/, ""))).sort((a, b) => b.length - a.length);
|
||||
@@ -24272,12 +24260,12 @@ window.noteAccounts = noteAccounts;
|
||||
const SKIP = new Set(["SCRIPT", "STYLE", "OPTION", "TEXTAREA"]);
|
||||
// a demo's made-up text (data-no-pii) is never hidden (outloudvi)
|
||||
const KEEP = "[data-no-pii]";
|
||||
// Usage's Sessions and Context are read from the agents' own logs, which
|
||||
// name no account (their answers aren't looked through for one, see api):
|
||||
// a project, a session or a prompt there that has an account's name in
|
||||
// it is no account, so only an address is hidden there (#1973: the
|
||||
// project lingting-react-ui with the account lingting)
|
||||
// Sessions and Context come from the agents' logs, which name no account:
|
||||
// only an address is hidden there (#1973, a project lingting-react-ui)
|
||||
const NAMELESS = "#sessionsPane, #contextPane";
|
||||
// labels (the user's own name, a plan, a model, a card's title) hide an
|
||||
// address only, not "Google" of "Google AI Pro" (#3656); TIPS, tooltips
|
||||
const LABELS = ".own-name, .plan, .acct-plan, .model-value, .subscription-head > b", TIPS = ".plan, .acct-plan, .model-value";
|
||||
// A switch's chosen is the choice made here; till then accounts hide
|
||||
// while Privacy masks personal data (inaction). The whole window
|
||||
// follows the switch of the page in sight: Routing's and Usage's, or
|
||||
@@ -24294,7 +24282,7 @@ window.noteAccounts = noteAccounts;
|
||||
const page = (() => {
|
||||
const view = document.body;
|
||||
function mask(root = view) {
|
||||
const all = finder(), reOf = (e) => e?.closest(NAMELESS) ? EMAIL : all;
|
||||
const all = finder(), reOf = (e) => e?.closest(NAMELESS) || e?.closest?.(LABELS) ? EMAIL : all;
|
||||
const walk = document.createTreeWalker(root, NodeFilter.SHOW_TEXT), found = [];
|
||||
for (let n; (n = walk.nextNode());) {
|
||||
if (n.data.length < 2 || SKIP.has(n.parentElement?.tagName) || n.parentElement?.closest(".pii, " + KEEP)) continue;
|
||||
@@ -24323,7 +24311,7 @@ window.noteAccounts = noteAccounts;
|
||||
// one masked already reads as an account too, its stars and all
|
||||
if (!e.dataset || "piiTitle" in e.dataset || !e.title || e.closest(KEEP)) continue;
|
||||
let out = "", last = 0;
|
||||
for (const m of hits(e.title, reOf(e), e)) {
|
||||
for (const m of hits(e.title, e.matches?.(TIPS) || e.closest?.(NAMELESS) ? EMAIL : all, e)) {
|
||||
out += e.title.slice(last, m.index) + m[0].replace(m[0].includes("@") ? /[^@.]/g : /./gu, "•"); // a tooltip can't blur
|
||||
last = m.index + m[0].length;
|
||||
}
|
||||
|
||||
@@ -424,7 +424,7 @@ function keysSumTip(subs) {
|
||||
function quotaWho(q) {
|
||||
const out = [];
|
||||
if (q.alias) {
|
||||
const a = el("span", "user quota-alias", q.alias);
|
||||
const a = el("span", "user quota-alias" + (q.named ? " own-name" : ""), q.alias);
|
||||
a.title = q.user ? q.alias + " · " + q.user : q.alias;
|
||||
out.push(a);
|
||||
if (q.user) {
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
// by its address with the key plan it is the same seat as; a click on the
|
||||
// name types a new one in place, posted once to provider/accountname. The
|
||||
// Usage page's card and the tray panel's name it the same way, and Hide
|
||||
// accounts hides the name. A click moves nothing; no native select, no
|
||||
// border stripe; it fits at 360px. In every language.
|
||||
// accounts hides the accounts but not that name, the user's own (#3656).
|
||||
// A click moves nothing; no native select, no border stripe; it fits at
|
||||
// 360px. In every language.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
@@ -35,7 +36,7 @@ const fresh = () => ({
|
||||
const quotas = () => [
|
||||
{ provider: "zcode", name: "ZCode", icon: "zcode", plan: "Pro", user: TEAM, alias: SEAT, seat: SEAT,
|
||||
windows: [{ name: "5 hours", used: 20, resetsAt: inHours(3) }] },
|
||||
{ provider: "zcode", name: "ZCode", icon: "zcode", plan: "Lite", user: ME, alias: "Personal",
|
||||
{ provider: "zcode", name: "ZCode", icon: "zcode", plan: "Lite", user: ME, alias: "Personal", named: true,
|
||||
windows: [{ name: "5 hours", used: 60, resetsAt: inHours(2) }] },
|
||||
];
|
||||
|
||||
@@ -161,7 +162,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
}
|
||||
});
|
||||
|
||||
test(`${engine} ${lang}: the Usage page and the tray panel name the account, and Hide accounts hides the name`, async (t) => {
|
||||
test(`${engine} ${lang}: the Usage page and the tray panel name the account, and Hide accounts hides the account, not its name`, async (t) => {
|
||||
const browser = await launch(t);
|
||||
for (const width of [900, 360]) {
|
||||
const context = await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" });
|
||||
@@ -198,12 +199,20 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
const pq = await panel.evaluate(() => [...document.querySelectorAll("#panelQuota .pq-card")].map((c) => ({ text: c.querySelector(".pq-user").textContent, title: c.title.split(" · ").slice(0, 3).join(" · ") })));
|
||||
assert.deepEqual(pq, [{ text: SEAT, title: `ZCode · ${SEAT} · ${TEAM}` }, { text: "Personal", title: `ZCode · Personal · ${ME}` }]);
|
||||
|
||||
// Hide accounts: the name of the user's own is an account's name too
|
||||
// Hide accounts: the accounts hidden, the user's own name for one
|
||||
// in sight (#3656), in its tooltip too. The window to the front: a
|
||||
// page behind the panel's gets no frames, and a click waits for one
|
||||
await page.bringToFront();
|
||||
await page.locator("#usageMask").click();
|
||||
await page.waitForFunction(() => [...document.querySelectorAll(".subscription-account .pii")].some((e) => e.dataset.raw === "Personal"));
|
||||
await page.waitForFunction((me) => [...document.querySelectorAll(".subscription-account .pii")].some((e) => e.dataset.raw === me), ME);
|
||||
const shown = await page.evaluate(() => [...document.querySelectorAll(".subscription-account")].map((a) => a.textContent + " " + [...a.querySelectorAll("[title]")].map((e) => e.title).join(" ")).join(" | "));
|
||||
assert.ok(!/Personal|3141592636|me@example/.test(shown), shown);
|
||||
await panel.waitForFunction(() => [...document.querySelectorAll("#panelQuota .pq-user .pii")].some((e) => e.dataset.raw === "Personal"));
|
||||
assert.ok(!/3141592636|me@example/.test(shown), shown);
|
||||
assert.equal(await page.locator(".subscription-account .quota-alias.own-name").textContent(), "Personal");
|
||||
assert.equal(await page.locator(".subscription-account .quota-alias.own-name .pii").count(), 0);
|
||||
assert.match(await page.locator(".subscription-account .quota-alias.own-name").getAttribute("title"), /^Personal · [^m]/);
|
||||
await panel.bringToFront(); // the same, the other way round
|
||||
await panel.waitForFunction((me) => [...document.querySelectorAll("#panelQuota .pq-card")].some((c) => c.querySelector(".pq-user").textContent === "Personal" && !c.title.includes(me)), ME);
|
||||
assert.ok(!/3141592636|me@example/.test(await panel.locator("#panelQuota").evaluate((e) => e.textContent + [...e.querySelectorAll("[title]")].map((x) => x.title).join(" "))));
|
||||
assert.deepEqual(errors, []);
|
||||
await context.close();
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
// Discord, for a screen share): with Hide accounts on, an account's name
|
||||
// on the provider editor's row and on its Usage card has a quiet eye, in
|
||||
// sight on hover or keyboard focus. A click shows that account, by its
|
||||
// address and the name the user gave it, wherever the window draws it,
|
||||
// tooltips too; the others stay hidden. The tray panel's Usage cards have
|
||||
// address wherever the window draws it, tooltips too; the others stay
|
||||
// hidden. The name the user gave one is in sight throughout (#3656). The tray panel's Usage cards have
|
||||
// the same eye. Each page's shown accounts are its own: one shown in the
|
||||
// window stays hidden in the panel and the other way round. Closing the
|
||||
// window (hideMain's closed) or putting the panel away hides them again. With Hide accounts off there is no eye. A click moves nothing;
|
||||
@@ -35,7 +35,7 @@ const provider = () => ({
|
||||
const quotas = () => [
|
||||
{ provider: "zcode", name: "ZCode", icon: "zcode", plan: "Pro", user: TEAM, alias: SEAT, seat: SEAT,
|
||||
windows: [{ name: "5 hours", used: 20, resetsAt: inHours(3) }] },
|
||||
{ provider: "zcode", name: "ZCode", icon: "zcode", plan: "Lite", user: ME, alias: "Personal",
|
||||
{ provider: "zcode", name: "ZCode", icon: "zcode", plan: "Lite", user: ME, alias: "Personal", named: true,
|
||||
windows: [{ name: "5 hours", used: 60, resetsAt: inHours(2) }] },
|
||||
];
|
||||
|
||||
@@ -116,7 +116,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
|
||||
await page.evaluate(() => hideAccounts.set(true, true));
|
||||
await sample(page);
|
||||
await page.waitForFunction(() => document.querySelectorAll("#sample .pii").length === 3);
|
||||
await page.waitForFunction(() => document.querySelectorAll("#sample .pii").length === 2);
|
||||
await page.waitForFunction((me) => document.querySelector(`.editor .acc[data-account-id="${me}"] .acct-user .pii`), ME);
|
||||
for (const id of [ME, TEAM]) assert.ok(!(await seen(row(id))).includes(id), `${id} is hidden first`);
|
||||
|
||||
@@ -175,12 +175,12 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await panel.locator("#panelQuota .pq-user").first().waitFor();
|
||||
await panel.waitForFunction(() => document.querySelector("#panelQuota .pq-user .pii"));
|
||||
const pq = await panel.evaluate(() => [...document.querySelectorAll("#panelQuota .pq-card")].map((c) => c.textContent + c.title).join(" "));
|
||||
assert.ok(!pq.includes(ME) && !pq.includes("Personal"), "the panel still hides it: " + pq);
|
||||
assert.ok(!pq.includes(ME), "the panel still hides it: " + pq);
|
||||
await panel.close();
|
||||
|
||||
// the window closed: every account hidden again
|
||||
await page.evaluate(() => hideAccounts.closed());
|
||||
await page.waitForFunction(() => document.querySelectorAll("#sample .pii").length === 3);
|
||||
await page.waitForFunction(() => document.querySelectorAll("#sample .pii").length === 2);
|
||||
for (const id of [ME, TEAM]) assert.ok(!(await seen(row(id))).includes(id), `${id} is hidden after the window closed`);
|
||||
assert.equal(await eye(ME).getAttribute("aria-pressed"), "false");
|
||||
|
||||
@@ -224,7 +224,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.equal(await opacity(eye("Personal")), "none", "no eye while Hide accounts is off");
|
||||
|
||||
await panel.evaluate(() => hideAccounts.set(true));
|
||||
await panel.waitForFunction(() => document.querySelectorAll("#panelQuota .pq-user .pii").length === 2);
|
||||
await panel.waitForFunction(() => document.querySelectorAll("#panelQuota .pq-user .pii").length === 1);
|
||||
await panel.waitForFunction((me) => [...document.querySelectorAll("#panelQuota .pq-card")].some((c) => c.querySelector(".pq-user").textContent === "Personal" && !c.title.includes(me)), ME);
|
||||
await panel.mouse.move(0, 0);
|
||||
assert.equal(await opacity(eye("Personal")), "0");
|
||||
await card("Personal").hover();
|
||||
@@ -235,7 +236,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
// a click shows that one, its card's tooltip too; the other stays hidden; nothing moves
|
||||
const sc = await scrolled(panel);
|
||||
await eye("Personal").click();
|
||||
await panel.waitForFunction(() => document.querySelectorAll("#panelQuota .pq-user .pii").length === 1);
|
||||
await panel.waitForFunction((me) => [...document.querySelectorAll("#panelQuota .pq-card")].some((c) => c.querySelector(".pq-user").textContent === "Personal" && c.title.includes(me)), ME);
|
||||
assert.equal(await panel.locator("#panelQuota .pq-user .pii").count(), 1);
|
||||
assert.equal(await scrolled(panel), sc, "a click scrolled");
|
||||
assert.equal(await card("Personal").locator(".pq-user").textContent(), "Personal");
|
||||
assert.ok((await card("Personal").getAttribute("title")).includes(ME), "its tooltip names it");
|
||||
@@ -254,7 +256,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await win.locator(".subscription-account .quota-alias").first().waitFor();
|
||||
await win.waitForFunction(() => document.querySelectorAll(".subscription-account .quota-of .pii").length === 2);
|
||||
const ws = await win.evaluate(() => [...document.querySelectorAll(".subscription-account")].map((c) => c.textContent).join(" "));
|
||||
assert.ok(!ws.includes(ME) && !ws.includes("Personal"), "the window still hides it: " + ws);
|
||||
assert.ok(!ws.includes(ME) && ws.includes("Personal"), "the window still hides it, not its name: " + ws);
|
||||
await win.close();
|
||||
|
||||
// put away (the panel's page goes hidden): hidden again
|
||||
@@ -262,7 +264,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
Object.defineProperty(document, "hidden", { configurable: true, get: () => true });
|
||||
document.dispatchEvent(new Event("visibilitychange"));
|
||||
});
|
||||
await panel.waitForFunction(() => document.querySelectorAll("#panelQuota .pq-user .pii").length === 2);
|
||||
await panel.waitForFunction((me) => [...document.querySelectorAll("#panelQuota .pq-card")].some((c) => c.querySelector(".pq-user").textContent === "Personal" && !c.title.includes(me)), ME);
|
||||
assert.ok(!(await seen(card("Personal"))).includes(ME), "hidden once the panel is put away");
|
||||
assert.equal(await eye("Personal").getAttribute("aria-pressed"), "false");
|
||||
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// Hide accounts hides accounts, not the labels around them (#3656,
|
||||
// faketrader): the name a user gave an account (#1515) stayed blurred,
|
||||
// so several accounts couldn't be told apart, and an Antigravity account
|
||||
// whose value is "Google" blurred "Google" of its plan "Google AI Pro" on
|
||||
// Usage and Providers. Now the user's own name stays in sight while the
|
||||
// account beside it is hidden; a plugin's name for an account (a masked
|
||||
// phone, #4416) is the account's and is hidden; a plan, a model and a
|
||||
// card's title hide only an address, so one written in a plan still is;
|
||||
// the account "Google" is hidden in its own rows, sentences and tooltips,
|
||||
// in the window and the tray panel. Every language, wide and narrow.
|
||||
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 RAW = "raw@example.com", ALIAS = "Work laptop", IAM = "iam::42:user:ops", PHONE = "138****5678", BOSS = "boss@corp.example";
|
||||
const PLAN = "Google AI Pro";
|
||||
const base = { icon: "generic", chat: "", responses: "", anthropic: "", catalog: "", agents: [], fallback: [], headers: {}, keyList: [], proxy: "", models: [{ id: "gemini-3-pro", name: "", on: true }] };
|
||||
const providers = () => ({ providers: [
|
||||
{ ...base, id: "antigravity", name: "Antigravity", icon: "antigravity-color",
|
||||
account: { agent: "antigravity", agentName: "Antigravity", user: "Google", plan: PLAN,
|
||||
logins: [{ user: "Google", plan: PLAN, active: true, on: true }, { user: RAW, plan: PLAN, on: true }] },
|
||||
accountNames: { [RAW]: ALIAS } },
|
||||
{ ...base, id: "fakeco", name: "FakeCo", account: { agent: "fakeco", agentName: "FakeCo", user: IAM, plan: "Team", logins: [{ user: IAM, plan: "Team", active: true, on: true }] },
|
||||
accountUsers: { [IAM]: PHONE } },
|
||||
], presets: [], excluded: [], gateway: { running: true, window: true } });
|
||||
const quotas = () => [
|
||||
{ provider: "antigravity", name: "Antigravity", icon: "antigravity-color", plan: PLAN, user: "Google", windows: [{ name: "Gemini", used: 5 }] },
|
||||
{ provider: "antigravity", name: "Antigravity", icon: "antigravity-color", plan: PLAN, user: RAW, alias: ALIAS, named: true, windows: [{ name: "Gemini", used: 30 }] },
|
||||
// the plugin's name for its account: the account's, not the user's own
|
||||
{ provider: "fakeco", name: "FakeCo", plan: "Team of " + BOSS, user: IAM, alias: PHONE, windows: [{ name: "Credits", used: 10 }] },
|
||||
];
|
||||
|
||||
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:${JSON.stringify(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());
|
||||
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 === "/api/login/usage") return json({});
|
||||
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: "" }); }
|
||||
};
|
||||
}
|
||||
|
||||
// what of an element is in sight: its text and every tooltip in it
|
||||
const seen = (loc) => loc.evaluate((e) => [e.textContent, ...[e, ...e.querySelectorAll("[title]")].map((x) => x.title || "")].join(" | "));
|
||||
const raws = (loc) => loc.evaluate((e) => [...e.querySelectorAll(".pii")].map((p) => p.dataset.raw));
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
||||
for (const width of [1100, 420]) {
|
||||
test(`${engine} ${lang} ${width}: Hide accounts hides the accounts, not their names, plans or models`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const context = await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" });
|
||||
const errors = [];
|
||||
const open = async (url) => {
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, url.includes("mode=panel")));
|
||||
await page.goto(url);
|
||||
return page;
|
||||
};
|
||||
|
||||
// Usage
|
||||
const page = await open("http://magpie.test/?view=usage");
|
||||
await page.locator(".subscription-account .quota-alias").first().waitFor();
|
||||
await page.evaluate(() => {
|
||||
const d = document.createElement("div");
|
||||
d.id = "sample";
|
||||
d.textContent = "Google answered · Work laptop waited · gemini-3-pro";
|
||||
d.title = "Google · raw@example.com";
|
||||
document.querySelector("#view-usage").append(d);
|
||||
const m = document.createElement("span");
|
||||
m.id = "model";
|
||||
m.className = "model-value";
|
||||
m.textContent = "Google Gemini via Google";
|
||||
document.querySelector("#view-usage").append(m);
|
||||
});
|
||||
await page.evaluate(() => hideAccounts.set(true, true));
|
||||
await page.waitForFunction(() => document.querySelector("#sample .pii"));
|
||||
const acct = (u) => page.locator(".subscription-account", { has: page.locator(`.pii[data-raw="${u}"]`) }).first();
|
||||
// the user's own name, in sight; the account beside it, hidden
|
||||
const mine = acct(RAW);
|
||||
assert.equal(await mine.locator(".quota-alias").textContent(), ALIAS);
|
||||
assert.deepEqual(await raws(mine.locator(".quota-alias")), []);
|
||||
assert.ok(!(await seen(mine)).includes(RAW), "the address is hidden, its tooltips too: " + await seen(mine));
|
||||
// the account named Google: hidden in its row, its plan in sight
|
||||
const google = acct("Google");
|
||||
assert.equal(await google.locator(".plan").textContent(), PLAN);
|
||||
assert.equal(await mine.locator(".plan").textContent(), PLAN);
|
||||
// the plugin's name for an account is the account
|
||||
const fake = acct(PHONE);
|
||||
assert.ok(!(await seen(fake)).includes(PHONE), "the plugin's name is hidden: " + await seen(fake));
|
||||
// an address in a plan is still hidden
|
||||
assert.deepEqual(await raws(fake.locator(".plan")), [BOSS]);
|
||||
assert.ok(!(await fake.locator(".plan").textContent()).includes(BOSS));
|
||||
// elsewhere: the account in a sentence and a tooltip, never the name
|
||||
assert.deepEqual(await raws(page.locator("#sample")), ["Google"]);
|
||||
assert.match(await page.locator("#sample").textContent(), /^\S+ answered · Work laptop waited · gemini-3-pro$/);
|
||||
assert.equal(await page.locator("#sample").getAttribute("title"), "•••••• · •••@•••••••.•••");
|
||||
// a model's name is a label
|
||||
assert.equal(await page.locator("#model").textContent(), "Google Gemini via Google");
|
||||
assert.ok(!(await page.locator("#view-usage").textContent()).includes(RAW));
|
||||
await page.evaluate(() => hideAccounts.set(false, true));
|
||||
await page.waitForFunction(() => !document.querySelector("#view-usage .pii"));
|
||||
assert.equal(await page.locator("#sample").textContent(), "Google answered · Work laptop waited · gemini-3-pro");
|
||||
await page.evaluate(() => hideAccounts.set(true, true));
|
||||
|
||||
// Providers: the row's plan in sight, its account hidden
|
||||
await page.evaluate(() => show("providers"));
|
||||
const row = page.locator(".row.provider", { hasText: "Antigravity" }).first();
|
||||
await row.waitFor();
|
||||
await page.waitForFunction(() => document.querySelector("#view-providers .pii"));
|
||||
assert.equal(await row.locator(".acct-plan").textContent(), PLAN);
|
||||
assert.deepEqual(await raws(row.locator(".sub")), ["Google"]);
|
||||
await row.click();
|
||||
const login = (id) => page.locator(`.editor .accts .acc[data-account-id="${id}"]`);
|
||||
await login(RAW).locator(".acct-who").waitFor();
|
||||
await page.waitForFunction((raw) => document.querySelector(`.editor .acc[data-account-id="${raw}"] .acct-user .pii`), RAW);
|
||||
// the user's own name in sight, the address and its tooltip hidden
|
||||
assert.equal(await login(RAW).locator(".rename").textContent(), ALIAS);
|
||||
assert.ok(!(await seen(login(RAW))).includes(RAW), "the address is hidden in the row: " + await seen(login(RAW)));
|
||||
// an account with no name of the user's is shown by its own: hidden
|
||||
assert.deepEqual(await raws(login("Google").locator(".rename")), ["Google"]);
|
||||
for (const id of ["Google", RAW]) assert.equal(await login(id).locator(".plan").textContent(), PLAN);
|
||||
|
||||
// the tray panel follows the window's switch
|
||||
const panel = await open("http://magpie.test/?mode=panel");
|
||||
await panel.evaluate(() => setPanelTab("usage"));
|
||||
await panel.locator("#panelQuota .pq-user").first().waitFor();
|
||||
const more = panel.locator('#panelQuota .pq-more:not(.pq-arrange)[aria-expanded="false"]');
|
||||
for (let i = 0; i < 4 && await more.count(); i++) await more.first().click();
|
||||
await panel.waitForFunction(() => document.querySelectorAll("#panelQuota .pq-card").length === 3);
|
||||
await panel.evaluate(() => hideAccounts.set(true));
|
||||
await panel.waitForFunction(() => document.querySelector("#panelQuota .pq-user .pii"));
|
||||
const pq = await panel.evaluate(() => [...document.querySelectorAll("#panelQuota .pq-card")].map((c) => ({
|
||||
user: c.querySelector(".pq-user").textContent, raw: c.querySelector(".pq-user .pii")?.dataset.raw ?? null, title: c.title })));
|
||||
const own = pq.find((c) => c.user === ALIAS);
|
||||
assert.ok(own, "the user's own name is in sight: " + JSON.stringify(pq));
|
||||
assert.ok(!own.title.includes(RAW), "its tooltip hides the address: " + own.title);
|
||||
assert.deepEqual(pq.map((c) => c.raw).filter(Boolean).sort(), ["138****5678", "Google"].sort());
|
||||
assert.ok(pq.every((c) => !c.title.includes(PHONE) && !c.title.includes(RAW) && !c.title.includes(BOSS)), JSON.stringify(pq));
|
||||
|
||||
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth), 0, `no sideways scroll at ${width}px`);
|
||||
assert.deepEqual(errors, []);
|
||||
await context.close();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,12 +139,19 @@ func AccountShownOf(id, user string) string { return cmp.Or(AccountLabelOf(id, u
|
||||
// (PluginUserOf); "" for none. id is a provider's or "plugin:<id>", as
|
||||
// logins name a plugin's accounts.
|
||||
func AccountLabelOf(id, user string) string {
|
||||
if p, ok := strings.CutPrefix(id, "plugin:"); ok {
|
||||
id = PluginID(p)
|
||||
}
|
||||
id = labelProvider(id)
|
||||
return cmp.Or(AccountNameOf(id, user), PluginUserOf(id, user))
|
||||
}
|
||||
|
||||
// labelProvider is the provider id behind id, a provider's or
|
||||
// "plugin:<id>" as logins name a plugin's accounts.
|
||||
func labelProvider(id string) string {
|
||||
if p, ok := strings.CutPrefix(id, "plugin:"); ok {
|
||||
return PluginID(p)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// PluginUserOf is the name a plugin's usage gives its account user
|
||||
// (usage().user, a masked phone) where that isn't user itself, "" for
|
||||
// none or one not read. A plugin's accountId is the account's key in
|
||||
@@ -223,12 +230,14 @@ func SetAccountName(id, ref, name string) error {
|
||||
|
||||
// withAccountNames is qs with each account's name of the user's own on
|
||||
// its card, else the name of the key plan it stands for (Seat), as
|
||||
// Alias. qs is not changed: it is a cache's.
|
||||
// Alias; Named when Alias is the user's own name. qs is not changed: it
|
||||
// is a cache's.
|
||||
func withAccountNames(qs []SubscriptionQuota) []SubscriptionQuota {
|
||||
out := make([]SubscriptionQuota, len(qs))
|
||||
for i, q := range qs {
|
||||
if q.From == "" {
|
||||
q.Alias = cmp.Or(AccountLabelOf(q.Provider, q.User), q.Seat)
|
||||
own := AccountNameOf(labelProvider(q.Provider), q.User)
|
||||
q.Alias, q.Named = cmp.Or(own, AccountLabelOf(q.Provider, q.User), q.Seat), own != ""
|
||||
}
|
||||
out[i] = q
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ func TestAccountNameOfAPluginAccount(t *testing.T) {
|
||||
}
|
||||
// on its card, as every surface reads it
|
||||
qs := withAccountNames([]SubscriptionQuota{{Provider: id, User: "31****36@qq.com"}})
|
||||
if qs[0].Alias != "某某·GLM 高级版" {
|
||||
t.Fatalf("card alias %q", qs[0].Alias)
|
||||
if qs[0].Alias != "某某·GLM 高级版" || !qs[0].Named {
|
||||
t.Fatalf("card alias %q, the user's own %v", qs[0].Alias, qs[0].Named)
|
||||
}
|
||||
// and on what the vendor's name is kept by: the Usage page's Accounts,
|
||||
// a gateway key's accounts, Routing's pools (magpie-community/plugins#310:
|
||||
|
||||
@@ -78,12 +78,17 @@ func TestPluginAccountShownByItsUsageUser(t *testing.T) {
|
||||
if len(keys) != 1 || keys[0] != id+"/"+want {
|
||||
t.Fatalf("%s: a gateway key's accounts read %q", why, keys)
|
||||
}
|
||||
alias := withAccountNames([]SubscriptionQuota{{Provider: id, User: iam}})[0].Alias
|
||||
card := withAccountNames([]SubscriptionQuota{{Provider: id, User: iam}})[0]
|
||||
if want == iam {
|
||||
want = ""
|
||||
}
|
||||
if alias != want {
|
||||
t.Fatalf("%s: the card's alias is %q, not %q", why, alias, want)
|
||||
if card.Alias != want {
|
||||
t.Fatalf("%s: the card's alias is %q, not %q", why, card.Alias, want)
|
||||
}
|
||||
// the plugin's name for the account is the account's, hidden
|
||||
// with it; only a name of the user's own is Named (#3656)
|
||||
if card.Named != (want == "Work") {
|
||||
t.Fatalf("%s: %q read as the user's own: %v", why, card.Alias, card.Named)
|
||||
}
|
||||
}
|
||||
shown(iam, "nothing read yet")
|
||||
|
||||
@@ -221,6 +221,11 @@ type SubscriptionQuota struct {
|
||||
// handed out, never cached.
|
||||
Alias string `json:"alias,omitempty"`
|
||||
Seat string `json:"seat,omitempty"`
|
||||
// Named is set when Alias is the user's own name (AccountNames), not
|
||||
// the plugin's name for the account (PluginUserOf, a masked phone) or
|
||||
// Seat: the GUI's Hide accounts keeps the user's own name in sight
|
||||
// and hides the others as accounts (#3656).
|
||||
Named bool `json:"named,omitempty"`
|
||||
// GatewayKey is set on the card of a gateway key a remote magpie gave
|
||||
// this computer (#1547, remote_key_limits.go): the limit that magpie
|
||||
// holds the key to, beside the windows that show it.
|
||||
|
||||
Reference in New Issue
Block a user