gui: a gateway key's account menu says a provider none of whose accounts is picked is used, and how to keep the key off it (#2077, KKKKKKKEM)

A key held to some accounts (#905) is held to the accounts of the
providers its list names; a provider it names none of is used on every
account. The menu showed that provider's accounts unticked like any
other, so the reporter unticked every Codex account, ticked the rest,
and was surprised that the key's remote magpie still listed and served
Codex's models.

The rule stays as #905 set it (a key held to one Codex seat keeps its
other providers). The menu now notes each account of such a provider
"Used: no <provider> account is picked", and the badge's tooltip says a
key is kept off a provider by picking only other providers' models.
en, zh, zh-TW, ja, de.

Verified:
- gateway-key-accounts.test.cjs (chromium + webkit, en + zh) checks the
  note on OpenAI's key under a key held to a Relay account, Relay's
  unpicked account still noting its provider, the tooltip, and a key
  held to no account showing neither. With the old keys.js it fails:
  expected 'Used: no OpenAI account is picked', actual 'OpenAI' (and
  the zh equivalent).
- gateway-key-*, gateway-keys-off, i18n-keys, gui-zh-tw, gui-ja, gui-de
  in chromium and webkit: 62/62.
- The menu at 420px in German (chromium) and Chinese (webkit): no
  horizontal overflow, the note wraps inside the menu.

Not run: the whole GUI suite.
This commit is contained in:
yetone
2026-10-14 15:33:27 +08:00
parent d53a51cdfe
commit f5083e8041
4 changed files with 31 additions and 5 deletions
+1 -1
View File
@@ -165,7 +165,7 @@ readings on both sides of detected boundaries.
- A subscription switched off (`Off`) or whose account was removed from magpie (`Hidden`) is left alone in the background (`leftAlone` in [`left_alone.go`](../../internal/provider/left_alone.go); Riko on Discord, whose Claude switched off still ran `claude auth status --json` every minute). No CLI is asked who is signed in (`claudeIdentity`, `cliIdentity.get` for Cursor and Devin): what it said last, in memory or `cli-identity.json`, is served, so the account stays listed to switch on again. Nor is its allowance read (`fetchSubscriptionUsage`, `loginUsageAt`), a saved ChatGPT sign-in renewed (`RenewLogins`), the agent's account switched (`NextLogin`), a window warmed (`keepWarm`), its model list fetched (`newDue`), or a daily check-in made by the loop (`checkinNow` with `soon` false; a press still checks in). A Cursor switched off that was never asked who is signed in isn't listed until it is switched on. `TestLeftAloneRunsNoCLI` runs those paths with fake `claude`, `cursor-agent` and `devin` CLIs on PATH and checks none ran. Plugins' model lists (`KeepPluginsListed`) are asked of the plugin host all at once and aren't held back per provider.
- A provider removed or switched off takes its models out of the catalog. [Agent wiring](agent-wiring.md)'s `Reseat` moves agents off them.
- A preset marked `NoList` uses its preset model list instead of requesting `/models`, and ignores previously fetched lists, including their protocol and key restrictions, unless the user sets `ModelsURL` or chooses a region marked `Lists`. Each region can carry a different list. Volcengine Ark's Coding Plan and Agent Plan use separate preset lists. Both plans include their embedding model separately from agents' chat-model lists; Agent Plan additionally exposes its image- and video-generation models to Settings → Images; Ark itself refuses video generation on Small and Medium Agent Plans, which include it only in the Large and Max tiers. Models magpie does not yet serve (Agent Plan's speech models) are not advertised. Ark's pay-as-you-go region still fetches its own list. Coding's `/api/coding/v3/models` returns a general Ark catalog instead of the plan's model ids, while Agent's `/api/plan/v3/models` returns 404. [`presets.go`](../../internal/provider/presets.go) defines these choices; `List`, `fetch`, `live`, `planModels`, `PlanEmbeddings`, `PlanDrawers` and `PlanVideos` in [`models.go`](../../internal/provider/models.go) apply them when adding, refreshing and reading cached models. `TestVolcengineModelLists` checks that the plans make no list requests, ignore old cached lists and return their own preset models; pay-as-you-go and an explicit list URL still make requests.
- A gateway key held to some accounts (#905) is held to those of the providers its list names: a provider it names no account of, the key uses as it always did. The list keeps an account by its stable id — `logins.json`'s `id`, set once written and kept through renames; the agents that keep no logins (and plugins) are known by a hash of the account's name, so an account renamed there drops out of a key's list, holding it closer, never wider. Storing an id for every agent is a larger change, not this one's.
- A gateway key held to some accounts (#905) is held to those of the providers its list names: a provider it names no account of, the key uses as it always did. The key's menu says so on each account of such a provider ("Used: no … account is picked"), and its badge's tooltip that a key is kept off a provider by its models (#2077: unticking every Codex account left Codex's models served). The list keeps an account by its stable id — `logins.json`'s `id`, set once written and kept through renames; the agents that keep no logins (and plugins) are known by a hash of the account's name, so an account renamed there drops out of a key's list, holding it closer, never wider. Storing an id for every agent is a larger change, not this one's.
- A sub2api key's windows are fixed: each starts at the key's first request after it was empty, aligned to the relay's day, and a window not started yet says `used 0` with no `reset_at`, so it is taken to renew a span from now. They count this key's spend only, not the relay's accounts behind it. `ForgetBalances` (a key or Balance URL changed) has every key's windows read again at its next ask, a read begun before dropped; until then the last reading stands, fresher than the card's, which routing's reads never write. A key changed is another key (`keyID`), with windows of its own.
- A Volcengine Ark provider's access key (`TakesVolcAccessKey`: any of its bases on `ark.<region>.volces.com`) is kept with its keys and never sent to the GUI: `/api/providers` tells the editor its ID and whether a Secret is saved (`accessKey`). A save that leaves the Secret blank keeps it, one that leaves the ID out or sends it blank keeps both (an editor opened before the key was given sends `""`, #1821), and `clearAccessKey` drops both. The ID and Secret go together everywhere the keys go: a copy takes them, also when its form sends the source's ID without the Secret (`AddCopy`), a backup or sync without keys has neither (`withoutKeys`), and a restore, mirror or sync keeps this machine's (`KeepSecrets` in `Restore`, `Mirror`, davsync's `take`) when it came without keys, or with the same key and no access key at all, as a magpie before v0.1.1142 or one the access key was never given on sends it (#1821); another key is another account and brings its own. A copy without keys keeps this machine's secret headers (`SecretHeader`) the same way. A plan endpoint with no provider on it holding the access key is a card that says which to give (`accessKeyCard`, `needsAccessKey`), with a button to the provider's settings, not a card left out. A `providers.json` saved with a UTF-8 BOM is read through it, not taken for a broken file whose `.bak` stands in. The plan read is the endpoint's: `/api/coding` asks `GetCodingPlanUsage`, `/api/plan` asks `GetAFPUsage`, pay-as-you-go (`/api/v3`) has no card; the region is the host's. One card is read for each access key and plan. `GetCodingPlanUsage`'s reply (`QuotaUsage[]` with `Level`, `Percent`, `ResetTimestamp` in seconds) is the one three tools built on it read; `GetAFPUsage`'s buckets are read in each form those tools read (`Used` of `Quota` or `Total`, or `Percent`; `ResetTime` or `ResetTimestamp`), none of them seen from a real account here. A reply none of that reads says so on the card with the reply's head. Changing the access key drops the cached cards (`ForgetPlanQuotas`).
- A Tencent Cloud provider's SecretId and SecretKey are kept, listed and saved the same way, in the same fields (`AccessKeyVendor` tells the editor whose: `accessKey.vendor`, the preset's `accessKeyVendor`). Only the Token Plan 企业版's endpoints are read with them (`TakesTencentAccessKey`: `/plan` on `tokenhub.tencentmaas.com`, region `ap-guangzhou`, or `tokenhub-intl.tencentmaas.com`, `ap-singapore`); the personal plan (`api.lkeap.cloud.tencent.com`) has no usage API and TokenHub's pay as you go no plan, so neither has a card. The preset lists its regions that take one (`accessKeyRegions`, `presetAccessKey`), and the editor shows SecretId and SecretKey at those alone. `DescribeTokenPlanList` gives the account's team plans (a sub-user sees the ones it made); each is asked `DescribeTokenPlan` for its `PackageInfo` and `TokenSummary`, the list's kept for what the reply leaves out. The card's one window is `TotalUsed` of `CycleQuota` (else `TotalQuota`), resetting at `TokenSummary.CycleEndTime`, else counted in months from `StartTime` and never past `ExpireTime`. A plan not `enable` says its status beside the plan's name. Errors come back as 200 with `Response.Error`; an `AuthFailure…` or `UnauthorizedOperation` one says to check the key. Built from the API docs (api/1823/132270 and siblings) and the signing doc's worked example; never seen from a real account here.
+8
View File
@@ -330,6 +330,8 @@ const I18N = {
"Any model, now and later": "任何模型,包括以后添加的",
"Any model and any account, now and later": "任何模型和任何账号,包括以后添加的",
"Only these accounts: {list}": "仅限这些账号:{list}",
"Used: no {provider} account is picked": "会被使用:{provider} 没有勾选任何账号",
"A provider with no account picked is used on every account; to keep the key off it, pick only other providers' models": "没勾选任何账号的供应商,它的所有账号都可用;要让此密钥用不了它,请只勾选其他供应商的模型",
"Not signed in now": "当前未登录",
"Every {provider} model": "{provider} 的全部模型",
"Every routing group": "全部路由组",
@@ -4498,6 +4500,8 @@ const I18N = {
"Any model, now and later": "任何模型,包括以後新增的",
"Any model and any account, now and later": "任何模型和任何帳號,包括以後新增的",
"Only these accounts: {list}": "僅限這些帳號:{list}",
"Used: no {provider} account is picked": "會被使用:{provider} 沒有勾選任何帳號",
"A provider with no account picked is used on every account; to keep the key off it, pick only other providers' models": "沒勾選任何帳號的供應商,它的所有帳號都可用;要讓此金鑰用不了它,請只勾選其他供應商的模型",
"Not signed in now": "目前未登入",
"Every {provider} model": "{provider} 的全部模型",
"Every routing group": "全部路由組",
@@ -8622,6 +8626,8 @@ const I18N = {
"Any model, now and later": "今後追加されるものも含め、すべてのモデル",
"Any model and any account, now and later": "今後追加されるものも含め、すべてのモデルとアカウント",
"Only these accounts: {list}": "これらのアカウントのみ:{list}",
"Used: no {provider} account is picked": "使われます:{provider} のアカウントが一つも選ばれていません",
"A provider with no account picked is used on every account; to keep the key off it, pick only other providers' models": "アカウントを一つも選んでいないプロバイダーは、すべてのアカウントで使われます。このキーで使わせないには、ほかのプロバイダーのモデルだけを選んでください",
"Not signed in now": "今はサインインしていない",
"Every {provider} model": "{provider} のすべてのモデル",
"Every routing group": "すべてのルーティンググループ",
@@ -12767,6 +12773,8 @@ const I18N = {
"Any model, now and later": "Jedes Modell, auch künftige",
"Any model and any account, now and later": "Jedes Modell und jedes Konto, auch künftige",
"Only these accounts: {list}": "Nur diese Konten: {list}",
"Used: no {provider} account is picked": "Wird genutzt: kein {provider}-Konto ist ausgewählt",
"A provider with no account picked is used on every account; to keep the key off it, pick only other providers' models": "Ein Anbieter ohne ausgewähltes Konto wird mit jedem seiner Konten genutzt; um den Schlüssel davon fernzuhalten, wähle nur Modelle anderer Anbieter",
"Not signed in now": "Derzeit nicht angemeldet",
"Every {provider} model": "Alle Modelle von {provider}",
"Every routing group": "Alle Weiterleitungsgruppen",
+11 -2
View File
@@ -242,7 +242,8 @@ function gatewayModelsBadge(k) {
: ms.length ? (ms.length === 1 && !as.length ? ms[0] : t("{n} models", { n: ms.length }))
: (as.length === 1 ? accountShown(as[0]) : t("{n} accounts", { n: as.length }));
b.title = (ms.length ? t("Only these models: {list}", { list: ms.join(", ") }) : t("Pick the models this key may use"))
+ (as.length ? "\n" + t("Only these accounts: {list}", { list: as.map(accountShown).join(", ") }) : "");
+ (as.length ? "\n" + t("Only these accounts: {list}", { list: as.map(accountShown).join(", ") })
+ "\n" + t("A provider with no account picked is used on every account; to keep the key off it, pick only other providers' models") : "");
b.setAttribute("aria-label", t("Models this key may use"));
b.setAttribute("aria-haspopup", "menu");
b.setAttribute("aria-expanded", "false");
@@ -255,9 +256,17 @@ function gatewayModelsBadge(k) {
// by who is signed in, a key by its fingerprint
const accountsSet = new Set();
const ofProvider = new Map();
// the list holds the key only to the accounts of the providers it
// names (#905): a provider none of whose accounts is picked is used on
// every one, and its unticked accounts say so (#2077: unticking all of
// Codex's left Codex's models served)
const named = new Set(as.map((v) => v.split("/")[0].toLowerCase()));
for (const a of accounts || []) {
accountsSet.add(a.id);
const o = { v: a.id, name: a.name, note: a.plan ? a.providerName + " · " + a.plan : a.providerName, literalName: true };
const note = as.length && !named.has(String(a.provider).toLowerCase())
? t("Used: no {provider} account is picked", { provider: a.providerName })
: a.plan ? a.providerName + " · " + a.plan : a.providerName;
const o = { v: a.id, name: a.name, note, literalName: true };
ofProvider.set(a.provider, [...(ofProvider.get(a.provider) || []), o]);
}
let listed = ""; // the provider whose models the list is in
@@ -20,8 +20,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.route("**/*", fixture(lang, "light", events, { lan: true, keyHolds: { server: { accounts: ["relay/me@example.com"] }, laptop: { models: ["relay/gone"], accounts: ["relay/nobody@example.com"] } } }));
const zh = lang === "zh";
const w = zh
? { label: "此密钥可用的模型", all: "全部模型", gone: "当前未提供", off: "当前未登录" }
: { label: "Models this key may use", all: "All models", gone: "Not served now", off: "Not signed in now" };
? { label: "此密钥可用的模型", all: "全部模型", gone: "当前未提供", off: "当前未登录", used: "会被使用:OpenAI 没有勾选任何账号", hint: "没勾选任何账号的供应商" }
: { label: "Models this key may use", all: "All models", gone: "Not served now", off: "Not signed in now", used: "Used: no OpenAI account is picked", hint: "A provider with no account picked is used on every account" };
await page.goto("http://magpie.test/?view=gateway");
await page.locator("#gatewayKeys .acc[data-key]").last().waitFor();
const row = (id) => page.locator(`#gatewayKeys .acc[data-key="${id}"]`);
@@ -45,6 +45,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// OpenAI's, the key behind GPT-5 — an account by who is signed in
// with their plan in the note, a key by its fingerprint
const names = (await menu.locator(".pm-item").allTextContents()).map((s) => s.trim());
assert(!(await badge("work").getAttribute("title")).includes(w.hint), "a key held to no account names the rule");
assert.equal((await menu.locator(".pm-item", { hasText: "k-1a2b3c" }).locator(".pm-note").textContent()).trim(), "OpenAI");
const at = (s) => names.findIndex((n) => n.includes(s));
assert(at("me@example.com") > at("Model mini"), names.join(" | "));
assert(at("me@example.com") < at("GPT-5"), names.join(" | "));
@@ -74,6 +76,13 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await badge("server").click();
await menu.waitFor();
assert.deepEqual((await menu.locator(".pm-item.on").allTextContents()).map((s) => s.trim()), ["me@example.comRelay · Pro"]);
// #2077: the list holds the key to the accounts of the providers it
// names only, so OpenAI's key, none of OpenAI's picked, is used, and
// says so; Relay's unpicked account is not, and says its provider
const noteOf = async (s) => (await menu.locator(".pm-item", { hasText: s }).locator(".pm-note").textContent()).trim();
assert.equal(await noteOf("k-1a2b3c"), w.used);
assert.equal(await noteOf("spare@example.com"), "Relay");
assert(String(await badge("server").getAttribute("title")).includes(w.hint), await badge("server").getAttribute("title"));
await menu.locator(".pm-item", { hasText: "me@example.com" }).click();
await menu.locator(".pm-item", { hasText: "k-1a2b3c" }).click();
await page.keyboard.press("Escape");