Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
routing: a found group's card leaves out a provider switched off, and counts it (XYenon)
yetone2a1ef15ba97c
diff --git a/docs/subsystems/providers-accounts.md b/docs/subsystems/providers-accounts.mdindex 16469fdb2..871bc0530 100644--- a/docs/subsystems/providers-accounts.md+++ b/docs/subsystems/providers-accounts.md@@ -49,7 +49,7 @@ keys and accounts per request is in [Gateway routing and fallback](gateway-routi| Import from files | `ImportLogins` (ChatGPT, Claude), `ImportGoogleAccounts` (Antigravity) and `ImportFactoryKeys` take other tools' files, from the window (`signin/import`) or `magpie accounts import` (#1453). ChatGPT reads Codex's `auth.json`, CLIProxyAPI's and Cockpit Tools' files, Sub2API's export (`sub2apiEntry`) and codexbar's `~/.codexbar/config.json` (`codexbarEntries`: the `openai_oauth` provider's accounts and `openAI.remoteConnectionAccounts`, the workspace from `openAIAccountId`). Each ChatGPT and Google sign-in is refreshed before it is added, so the tool the file came from is signed out of it; both surfaces say so first, and the command imports nothing without `--yes` or a yes. Claude reads CLIProxyAPI's files and Sub2API's export, whose Claude account says its email as Anthropic does, `email_address`, in `credentials` or `extra`, and keeps its `scope`, `account_uuid` and `org_uuid` as Claude Code's scopes, `accountUuid` and `organizationUuid` (#1975); a file with no email is refused, as Claude Code's own `.credentials.json` is. Claude's are kept as the file has them. A refresh token magpie holds already is `exists`, never refreshed; accounts are matched by email and workspace, or for Claude organization (`sameLogin`). An entry with an access token and no refresh token is refused (`accessOnly`). One file of several that holds no account is a failed row with its place (`ImportedAccount.File`), never skipped. The files are only read. | [`login_import.go`](../../internal/provider/login_import.go), [`google_import.go`](../../internal/provider/google_import.go), [`factory_key.go`](../../internal/provider/factory_key.go), [`accounts_cli.go`](../../internal/cli/accounts_cli.go) || Used-up switch | When the account Codex or Claude Code is signed in to has used its allowance, the agent is signed in to the next account that is on and has room (#208). For Codex, *Only switch Codex's sign-in* (`SwitchOnly`, `SetSwitchOnly`) keeps magpie's `openai_base_url` failover out of Codex's config, so the switch is all magpie does (#1907); an unreadable providers.json reads as switch-only, so the failover is not written on a guess. For Claude, the same setting keeps the accounts to Claude Code (`Provider.KeptToAgent`): `On()` is false, so the gateway, catalog and groups serve nothing on them, while switching and usage, gated by `leftAlone` on the raw `Off`, go on. | [`codex_switch.go`](../../internal/provider/codex_switch.go) || Claude Code's proxy | Claude Code on its own subscription asks Anthropic itself, through the proxy its env names. While any Claude account has a proxy of its own (`AccountProxies`), the `env` of Claude Code's `settings.json` names the proxy of the account it is signed in to (#1807): `HTTPS_PROXY` and `HTTP_PROXY` set to that account's own, else the subscription's `Proxy` (`ProxyOfLogin`), and `NO_PROXY` to loopback; none for `direct` or a SOCKS proxy, which Claude Code can't use. It is written on every switch (`switchLogin`, the user's or `SwitchWhenSpent`), when the Claude subscription is saved, and at the gateway's look every `loginSwitchEvery` (a sign-in made in Claude Code itself). Claude Code reads its env at start, so only sessions started after the switch take it. A proxy key the user set (in either case) is theirs: magpie then writes none and takes out none of theirs. What magpie wrote is kept in `claude-proxy-env.json`, and a key is magpie's only while it holds that value. A `settings.json` that doesn't parse is left as it is. Its log lines name the proxy through `netproxy.Redact`, without its user and password (#1886); the env gets it whole. | [`claude_proxy_env.go`](../../internal/provider/claude_proxy_env.go) |-| Routing groups | User-made groups from the Routing view, and auto-found groups of the same model across providers (derived, never stored). The same model is the same id as vendors agree on it (`sameModel`): lowercase, without a vendor's prefix, a version's dot as `-`, a run of spaces, `_` and `-` as one `-` (a relay listing its display name as the id, `GPT-6 Sol`, joins `gpt-6-sol`, Chill on Discord: `TestSameModelDisplayNameAsID`), and without a YYYYMMDD or Ark YYMMDD snapshot date. Every word still counts (`gpt-6`, `gpt-6-mini` and `gpt-6-sol` stay apart), as do a `:variant`, a four-digit release and OpenAI's dashed date (`gpt-4o-2024-08-06`, a pinned snapshot whose group id agents may already name). A provider kept "Only through routing groups" joins them the same way. Members are `provider/model[:effort]`. A group can nest another (`group/<id>`); `SaveGroup` refuses loops. A group given another id (`agent.RenameGroup`: the Routing page, `magpie groups rename`, the TUI) moves every agent field on `group/<old>` to `group/<new>`, spelled as the agent spells it, through the same `renameRefs` a provider's rename uses, then `SyncCatalog`; before, the agents stayed on a group magpie no longer had (lucis0116 on X, `TestRenameGroupMovesTheAgentsOnIt`). A provider's or group's display name needs no move: `store` and `SaveGroup` drop the catalog, and `SyncCatalog` writes the new labels into every agent's list. `Match` takes a glob or `re:` pattern (#766), both matched in any case (`compilePattern`; `(?-i)` inside a `re:` makes case matter). A found group follows the providers magpie has: one removed leaves it, while one switched off stays in it (`foundGroups`, `heldOffEntries`; one without a key, such as a plugin not signed in, finds no group), skipped by `membersIn` and said as switched off on the Routing page, so switching one of two providers off for a while doesn't take the group away from the agents, rules and groups set to it; it is back in its place once on again (#2671: `TestFoundGroupStaysWithAProviderOff`, `TestFoundGroupWithAProviderOff`, `TestReseatKeepsAFoundGroupWithAProviderOff`, `TestFoundGroupMemberOfASwitchedOffProvider`). A found group the user changed (an `auto-…` id stored) is read without the members of providers magpie no longer has (`withoutRemoved`, not written back, so a provider back under its id is back in it), except a manual group's pick, a rule's model, or all of them when none would be left. A switched-off provider's members stay in it, skipped by `membersIn`, and the Routing page says them as switched off (`memberJSON.providerOff`). The user's own groups keep their members. Three templates make a group in one click from the models the user has (`provider.Templates`, `AddTemplate`; the Routing page's cards before a first group and its Templates menu after, `magpie group template [kind] [name]`): `smart` sends a hard turn to the strongest model and an easy one or a compaction to a cheap one, asked by a classifier (the decision API when there is one, else the cheapest priced model that doesn't reason); `thrifty` starts on two cheap models of different providers and sends high reasoning to the strongest; `steady` fails over between the strongest model of up to three providers. A model is weighed by its maker's list price when known, else what its provider charges, else by its id's size words (`sizeOf`); one over `tooDear` (USD 100 a million output tokens) is never picked. A template that can't be made says what is missing (`Need`). It is saved under a name and id no group has (`freeGroupName`, shared with `CopyGroup`), never over one. A group is shared as text (`ShareGroup`, a group row's Copy to share): JSON marked `"magpie": "routing-group"` with a format `version` (`ShareVersion`), holding the group's members as it names them, patterns, routing, rules, classifier and settings. A group holds only `provider/model` ids, never a key, account or address, and the derived matches, found/hidden/off flags and the rules that hold by a folder (a path on the sharer's machine, `Rule.Folders`) stay behind; a pasted one is left out too. `ImportGroup` (the Routing page's Import, `POST /api/groups/import`) reads it with words or a code fence around it, refuses another text, a newer format or none (`ShareError`, said in the reader's language). A member whose provider the importer has is kept; else the same model (`AutoGroupOf`) under the first provider of theirs that serves it (`Instead`); else it is left out and named (`Missing`), with the rules that send to it, its place among the off and fast members, and a classifier gone takes the intent rules and auto effort with it. Nothing is added when no member is left; what is added gets a free name, never replacing a group. A group of patterns only that match nothing now (a plugin's models not listed) has no members: `/api/groups` says them, and an unmakeable template's, as `[]`, never `null`; the Routing page reads the response through `groupsFrom` and draws a group it still can't draw as one row saying so, so one bad group never hides the rest (#1585). | [`group.go`](../../internal/provider/group.go), [`grouptemplate.go`](../../internal/provider/grouptemplate.go), [`group_share.go`](../../internal/provider/group_share.go) |+| Routing groups | User-made groups from the Routing view, and auto-found groups of the same model across providers (derived, never stored). The same model is the same id as vendors agree on it (`sameModel`): lowercase, without a vendor's prefix, a version's dot as `-`, a run of spaces, `_` and `-` as one `-` (a relay listing its display name as the id, `GPT-6 Sol`, joins `gpt-6-sol`, Chill on Discord: `TestSameModelDisplayNameAsID`), and without a YYYYMMDD or Ark YYMMDD snapshot date. Every word still counts (`gpt-6`, `gpt-6-mini` and `gpt-6-sol` stay apart), as do a `:variant`, a four-digit release and OpenAI's dashed date (`gpt-4o-2024-08-06`, a pinned snapshot whose group id agents may already name). A provider kept "Only through routing groups" joins them the same way. Members are `provider/model[:effort]`. A group can nest another (`group/<id>`); `SaveGroup` refuses loops. A group given another id (`agent.RenameGroup`: the Routing page, `magpie groups rename`, the TUI) moves every agent field on `group/<old>` to `group/<new>`, spelled as the agent spells it, through the same `renameRefs` a provider's rename uses, then `SyncCatalog`; before, the agents stayed on a group magpie no longer had (lucis0116 on X, `TestRenameGroupMovesTheAgentsOnIt`). A provider's or group's display name needs no move: `store` and `SaveGroup` drop the catalog, and `SyncCatalog` writes the new labels into every agent's list. `Match` takes a glob or `re:` pattern (#766), both matched in any case (`compilePattern`; `(?-i)` inside a `re:` makes case matter). A found group follows the providers magpie has: one removed leaves it, while one switched off stays in it (`foundGroups`, `heldOffEntries`; one without a key, such as a plugin not signed in, finds no group), skipped by `membersIn`, left off a found group's card, logos and TUI line with a count of those switched off (XYenon on Discord: `routing-provider-off.test.cjs`, `TestFoundGroupLineLeavesASwitchedOffProviderOut`) and said as switched off in its editor and the TUI's group page, so switching one of two providers off for a while doesn't take the group away from the agents, rules and groups set to it; it is back in its place once on again (#2671: `TestFoundGroupStaysWithAProviderOff`, `TestFoundGroupWithAProviderOff`, `TestReseatKeepsAFoundGroupWithAProviderOff`, `TestFoundGroupMemberOfASwitchedOffProvider`). A found group the user changed (an `auto-…` id stored) is read without the members of providers magpie no longer has (`withoutRemoved`, not written back, so a provider back under its id is back in it), except a manual group's pick, a rule's model, or all of them when none would be left. A switched-off provider's members stay in it, skipped by `membersIn`, and the Routing page says them as switched off (`memberJSON.providerOff`). The user's own groups keep their members. Three templates make a group in one click from the models the user has (`provider.Templates`, `AddTemplate`; the Routing page's cards before a first group and its Templates menu after, `magpie group template [kind] [name]`): `smart` sends a hard turn to the strongest model and an easy one or a compaction to a cheap one, asked by a classifier (the decision API when there is one, else the cheapest priced model that doesn't reason); `thrifty` starts on two cheap models of different providers and sends high reasoning to the strongest; `steady` fails over between the strongest model of up to three providers. A model is weighed by its maker's list price when known, else what its provider charges, else by its id's size words (`sizeOf`); one over `tooDear` (USD 100 a million output tokens) is never picked. A template that can't be made says what is missing (`Need`). It is saved under a name and id no group has (`freeGroupName`, shared with `CopyGroup`), never over one. A group is shared as text (`ShareGroup`, a group row's Copy to share): JSON marked `"magpie": "routing-group"` with a format `version` (`ShareVersion`), holding the group's members as it names them, patterns, routing, rules, classifier and settings. A group holds only `provider/model` ids, never a key, account or address, and the derived matches, found/hidden/off flags and the rules that hold by a folder (a path on the sharer's machine, `Rule.Folders`) stay behind; a pasted one is left out too. `ImportGroup` (the Routing page's Import, `POST /api/groups/import`) reads it with words or a code fence around it, refuses another text, a newer format or none (`ShareError`, said in the reader's language). A member whose provider the importer has is kept; else the same model (`AutoGroupOf`) under the first provider of theirs that serves it (`Instead`); else it is left out and named (`Missing`), with the rules that send to it, its place among the off and fast members, and a classifier gone takes the intent rules and auto effort with it. Nothing is added when no member is left; what is added gets a free name, never replacing a group. A group of patterns only that match nothing now (a plugin's models not listed) has no members: `/api/groups` says them, and an unmakeable template's, as `[]`, never `null`; the Routing page reads the response through `groupsFrom` and draws a group it still can't draw as one row saying so, so one bad group never hides the rest (#1585). | [`group.go`](../../internal/provider/group.go), [`grouptemplate.go`](../../internal/provider/grouptemplate.go), [`group_share.go`](../../internal/provider/group_share.go) || Allowance | `Quotas` asks every vendor at once: subscription windows (`SubscriptionUsage`), key-bought plans (`PlanQuotas`) and key balances (`KeyBalances`). The Usage page, `magpie quota --json` and `GET /v1/magpie/quotas` read it, each window with its whole-window estimate (`Holds`/`HoldsWhy`, `usage.WithWindowHolds`, which `quotaReport` reaches through the `ReckonHolds` hook since package provider can't import usage, #2333). A single card can be read again on its own (#840). A remote magpie's cards come from what it has kept (`CachedCards`, `GET /v1/magpie/quotas/cards`) and are never read there for this computer except by a card's refresh (`POST /v1/magpie/quotas/refresh`, throttled per card). What it has kept is the Usage page's cards with the readings made behind the requests since laid over them, a later one over an earlier by `readSeq` (`cards_kept.go`): each account's `LoginUsage` reading (the used-up switch, the Codex warm-up, routing's `Allowances`), and each key's `KeyAllowance` windows on its plan or balance card. A Claude account's windows Claude Code told as it answered (`NoteClaudeLimits`, kept in `claudeUsage` with their own `heardSeq`, which drops the account's `LoginUsage` reading) stand on its card over any reading started before them (`withHeardClaude`, #2206), so a magpie only requests reach still tells them. An account or key read that way and never on the page gets a card from that reading, and after a restart, before either is read again, the cards come from `quotas.json`, dated (`AsOf`). A magpie serving only other magpies has nobody on its page (#1313). Each key of a remote-magpie provider also gets a card of its own, under `<remote>/~keys`, one section per key (#1547, `remoteKeyCards` in `remote_key_limits.go`): the gateway key's limit as that magpie holds it, read from `GET /v1/magpie/limit` asked with that key alone, so a key never sees another's numbers. It shows a window per cap (tokens, spend) named for the period, used against the cap, with its reset, plus `GatewayKey` (what is left, calls, a cycle of days, used up); a key held to no limit shows `Unlimited`. It is kept for `remoteCardsFor` like the remote's cards and read again by the card's refresh (`?provider=<remote>/~keys&user=<key name>`). A read that fails keeps the last numbers, dated (`AsOf`); with none the card says why, never zero or no limit. A remote from before `/v1/magpie/limit` (404) says it is too old to tell (`errRemoteNoKeyLimit`). A remote that holds the key to a budget, models or accounts answers its cards 403 `gateway_key_held` (#1981, `errKeyHeld`): the cards kept from before are dropped and only the key's own card shows. Its owner can let the key be told the cards of what it may use (#2216, `magpie gateway-key quotas <id> on`); the remote then answers those, and 403 as before when that is none. A remote's cards are kept by provider and key (`remoteCardsID`), so a changed key never shows what the old one was told, and a read is kept only over one asked before it (`keepRemoteCards`). Cursor, Grok and a Kiro key keep the page's cards only. With Settings → Allowances → *Allowance reads* at *When I ask* (`QuotaReads == "asked"`, #1518: magpie started at login before the proxy app read by itself, direct), only a read the user asked for goes out: the Usage page or the tray panel's Allowances opened (no more than once in 30s, `quotasOpened`, #1588) or refreshed (`?asked=1`), a card's refresh (`RefreshUsage`), `magpie quota`, `magpie accounts`, `magpie quota wait` and the TUI's quotas (`Asked`). Any other read (`quotaReading` → `holdUnasked`) carries `netproxy.Hold`, so its requests fail before they leave, and every reader gives back what it last read, dated, or "not read yet" (`errNotAsked`): routing, the used-up switch, the menu bar and alerts go by that. An account refused for its quota (`StaleAllowance` → `markStaleRead`) or a key refused (`StaleKeyAllowance` → `refused`) is still read, once (`unheld`). Warm-up and check-in are not reads and are unchanged. A plugin's window may carry a prepaid wallet's `balance` in its `unit` and no share (`QuotaWindow.Balance`, #3950): the card and `magpie quota` show the figure (`BalanceText`), and routing reads it through `Allowance.Left`. | [`cards_kept.go`](../../internal/provider/cards_kept.go), [`quotas.go`](../../internal/provider/quotas.go), [`subscription_usage.go`](../../internal/provider/subscription_usage.go), [`planquota.go`](../../internal/provider/planquota.go), [`balance.go`](../../internal/provider/balance.go), [`quota_refresh.go`](../../internal/provider/quota_refresh.go), [`remote_quotas.go`](../../internal/provider/remote_quotas.go), [`remote_key_limits.go`](../../internal/provider/remote_key_limits.go), [`quota_asked.go`](../../internal/provider/quota_asked.go) || A remote magpie's prices | A local magpie asks a remote magpie's `/v1/models` with `X-Magpie-Prices` (`PricesHeader`, sent by `listHeaders`). The remote answers each model's `magpie_price`: what its own Usage page counts the model at (`EntryPriceIn`: the price its user set, else its provider's list price at its price rate; a routing group only when every member costs the same). It tells it only to a request from its own computer or one let in with a gateway key (`local` or `sharedWith`); a list that didn't ask gets no `magpie_price` (a remote request without a valid key never reaches the list: `lanGuard` refuses it); every list told to those callers also carries the same price as OpenRouter's `pricing`, for agents ([gateway routing](gateway-routing.md)). The local keeps the price with the fetched list (`catalog.Model.Price`; a value that isn't a price, or has a negative part, is dropped, the model kept) and uses it as that provider's list price (`ListPrice` → `remotePrice`). A price the local user set (`provider/model`, `provider/*`, `*/model`) still comes first, and the local provider's own price rate still applies on top. A remote from before this sends no field and the models stay priced as before; an older local sends no header and is sent nothing new. The model editor says the greyed price is the other magpie's (`remoteList`). | [`remote_magpie.go`](../../internal/provider/remote_magpie.go), [`models.go`](../../internal/provider/models.go), [`gateway.go`](../../internal/gateway/gateway.go) (`models`), [`live.go`](../../internal/catalog/live.go) || A remote magpie's service tiers | A remote magpie's `/v1/models` gives each model the `service_tiers` its own Codex is offered on it (`codexTiers` → `codexcat.ServiceTiers`, from the same `CodexCatalog` and `codexcat.Entries` as its `/v1/codex/models`: Fast on a ChatGPT account's GPT model, the tiers of Codex's own entry on a relay's, none on a model it offers none). The local keeps the ids (`catalog.Model.Tiers` → `Entry.Tiers`), `codexListed` hands them on for the remote's models, and `codexcat.Entries` offers them to the local Codex with Codex's own names (`namedTiers`). The gateway sends the tier Codex asks for to a remote magpie as it was asked (`Request.OwnTier`, as for a provider added by its address; dropped and not sent again if refused), and the remote serves it as its own Codex's turn (#1234). An agent's picker offers the bolt on a remote's model whose tiers hold `priority` (`provider.CanFast` reads them with `RemoteTiers`; Ultrafast too where they hold `ultrafast`, `UltraOn`), and a fast pick of one goes on with `service_tier` `priority` on the remote's Chat or Responses: an agent on Messages, whose fast is Claude's `speed`, has it turned into the tier the remote offers (`forwardTranslated`), so Claude Code's pick reaches the remote's vendor too (littlekk88 on Discord; `TestRemoteMagpieFastPick`, red without either half). A remote from before this sends no tiers, and its models are offered none, as before. The list gives every client the tiers, not only a magpie asking with `X-Magpie-Drawers`: Cindy shows its Fast switch on a model whose `service_tiers` hold `priority` (#1914, `TestModelsListTiersForEveryClient`). | [`codexcat.go`](../../internal/codexcat/codexcat.go), [`codex_models.go`](../../internal/provider/codex_models.go), [`codex_catalog.go`](../../internal/gateway/codex_catalog.go), [`gateway.go`](../../internal/gateway/gateway.go), [`live.go`](../../internal/catalog/live.go) |diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.jsindex bc87c968f..22e74b9a3 100644--- a/internal/gui/assets/plugins/routing/client.js+++ b/internal/gui/assets/plugins/routing/client.js@@ -5016,7 +5016,15 @@ function routingPage(part) {renderGroups();return true;};- const groupIcons = (g) => [...new Map((g.memberInfo || []).filter((i) => i.icon).map((i) => [i.provider || i.icon, i.icon])).values()];+ // offIn: the members of a group magpie found whose provider is switched+ // off (XYenon on Discord). magpie keeps them in the group so agents on it+ // aren't moved while one is off (#2671), but the gateway skips them, so a+ // found group's card and logos leave them out, as every model list leaves+ // a provider switched off out, and say how many in a tag; the editor still+ // has them, greyed with why. A group of the user's lists what they put in.+ const offIn = (g) => g.auto ? (g.memberInfo || []).filter((i) => i.providerOff && g.members.includes(i.id)) : [];+ const shownMembers = (g) => { const off = offIn(g).map((i) => i.id); const left = g.members.filter((id) => !off.includes(id)); return left.length ? left : g.members; };+ const groupIcons = (g) => { const shown = shownMembers(g); return [...new Map((g.memberInfo || []).filter((i) => i.icon && shown.includes(i.id)).map((i) => [i.provider || i.icon, i.icon])).values()]; };// offOf: a member whose provider is switched off (groupsState's// providerOff), said by its provider's name and model rather than a bare// id: the group skips it until the provider is on again@@ -5491,7 +5499,7 @@ function routingPage(part) {const main = el("div", "main"), nm = el("div", "nm");nm.append(el("b", "", g.name), el("code", "mdl", g.ref || "group/" + g.id));if (g.auto) nm.append(el("small", "auto", t("found by magpie")));- main.append(nm, el("div", "mem", g.members.map((id) => memberLabel(g, id)).join(g.routing === "order" ? " → " : " · ")));+ main.append(nm, el("div", "mem", shownMembers(g).map((id) => memberLabel(g, id)).join(g.routing === "order" ? " → " : " · ")));row.append(cb, ics, main);return row;}@@ -5549,7 +5557,7 @@ function routingPage(part) {if (g.auto) nm.append(el("small", "auto", t("found by magpie")));const manual = g.routing === "manual";const sep = g.routing === "order" ? " → " : " · ";- const mem = manual ? pickRow(g) : el("div", "mem", g.members.map((id) => memberLabel(g, id) + (g.off?.includes(id) ? ` (${t("off")})` : "")).join(sep));+ const mem = manual ? pickRow(g) : el("div", "mem", shownMembers(g).map((id) => memberLabel(g, id) + (g.off?.includes(id) ? ` (${t("off")})` : "")).join(sep));main.append(nm, mem);for (const p of g.patterns || []) {const line = el("div", "mem pat" + (p.models ? "" : " none"));@@ -5587,6 +5595,12 @@ function routingPage(part) {r.title = (manual ? t("The rules wait while you pick the model by hand.") + "\n" : "") + g.rules.map((x, i) => `${i + 1}. ${ruleText(x)} → ${x.pause ? t("pause") + " " : ""}${rUses(x).map((u) => memberLabel(g, u)).join(", ")}${x.useEffort ? " · " + t("{level} reasoning", { level: x.useEffort }) : ""}`).join("\n");tags.append(r);}+ const offs = manual ? [] : offIn(g);+ if (offs.length && shownMembers(g).length < g.members.length) {+ const k = el("span", "tag idle rt-goff", t("{n} switched off", { n: offs.length }));+ k.title = offs.map(offWords).join("\n");+ tags.append(k);+ }if (g.disabled) tags.append(el("span", "tag idle", t("switched off")));else if (!g.ready) tags.append(el("span", "tag bad", t("no member ready")));const edit = el("button", "text", t("Edit"));diff --git a/internal/gui/assets/plugins/routing/i18n.js b/internal/gui/assets/plugins/routing/i18n.jsindex eced6e535..885f6e346 100644--- a/internal/gui/assets/plugins/routing/i18n.js+++ b/internal/gui/assets/plugins/routing/i18n.js@@ -34,6 +34,7 @@ magpie.strings({"“· routing group” is set for every group above": "是否带「· routing group」在上方统一设置,对所有路由组生效","{agent} guessed your next message for its composer by itself, reading the whole conversation again. Not a turn of the conversation; Codex composer predictions, under Settings in Codex's row on the Agents page, picks its model, and Codex's Settings › General › Show predictions turns it off.": "{agent} 自行为输入框猜测你的下一条消息,每次都把整段对话重读一遍。不属于对话轮次;在 Agent 页 Codex 那一行的设置里,用 Codex 输入框预测 选它用的模型,在 Codex 的 设置 › 常规 › 显示预测内容 里可以关掉。","{name} is switched off: the group skips it until it is on again": "{name} 已关闭:开启前这个组会跳过它",+ "{n} switched off": "{n} 个已关闭","Off: agents aren't offered {name} and a request to it is turned away. Click to switch it on": "已关闭:Agent 列表里没有 {name},发给它的请求会被拒绝。点击打开","On: agents may pick {name}. Click to switch it off and keep it as it is": "已打开:Agent 可以选用 {name}。点击暂时关闭,组的设置原样保留","{name} switched on": "已打开 {name}",@@ -636,6 +637,7 @@ magpie.strings({"Whether “· routing group” follows a group’s name in the agents’ lists: one setting for every group, and for the provider after each model’s name, as on Settings.": "Agent 的模型列表裡,路由組名後面是否帶「· routing group」。這是所有路由組共用的一個設定,也決定模型名後面是否帶供應商,和「設定」裡的是同一個。","“· routing group” is set for every group above": "是否帶「· routing group」在上方統一設定,對所有路由組生效","{name} is switched off: the group skips it until it is on again": "{name} 已關閉:開啟前這個組會跳過它",+ "{n} switched off": "{n} 個已關閉","Off: agents aren't offered {name} and a request to it is turned away. Click to switch it on": "已關閉:Agent 列表裡沒有 {name},發給它的請求會被拒絕。點選開啟","On: agents may pick {name}. Click to switch it off and keep it as it is": "已開啟:Agent 可以選用 {name}。點選暫時關閉,組的設定原樣保留","{name} switched on": "已開啟 {name}",@@ -1216,6 +1218,7 @@ magpie.strings({"“· routing group” is set for every group above": "「· routing group」を付けるかは上で全グループ共通に設定します","{agent} guessed your next message for its composer by itself, reading the whole conversation again. Not a turn of the conversation; Codex composer predictions, under Settings in Codex's row on the Agents page, picks its model, and Codex's Settings › General › Show predictions turns it off.": "{agent} が入力欄に表示する次のメッセージの予測を自分で行い、そのたびに会話全体を読み直しました。会話のターンではありません。エージェントページの Codex の行にある設定の Codex の入力予測 でモデルを選べ、Codex の 設定 › 一般 › 予測候補を表示 でオフにできます。","{name} is switched off: the group skips it until it is on again": "{name} はオフです。オンに戻すまでグループはスキップします",+ "{n} switched off": "{n} 件オフ","Off: agents aren't offered {name} and a request to it is turned away. Click to switch it on": "オフ:{name} はエージェントに表示されず、届いたリクエストは断られます。クリックでオン","On: agents may pick {name}. Click to switch it off and keep it as it is": "オン:エージェントは {name} を選べます。クリックで一時的にオフ(設定はそのまま)","{name} switched on": "{name} をオンにしました",@@ -1808,6 +1811,7 @@ magpie.strings({"“· routing group” is set for every group above": "„· routing group“ wird oben für alle Gruppen eingestellt","{agent} guessed your next message for its composer by itself, reading the whole conversation again. Not a turn of the conversation; Codex composer predictions, under Settings in Codex's row on the Agents page, picks its model, and Codex's Settings › General › Show predictions turns it off.": "{agent} hat deine nächste Nachricht für sein Eingabefeld selbst vorhergesagt und dafür das ganze Gespräch erneut gelesen. Kein Zug des Gesprächs; das Modell wählst du mit Codex-Eingabevorhersagen unter Einstellungen in der Zeile von Codex auf der Seite Agenten, und in Codex unter Einstellungen › Allgemein › Textvorschläge anzeigen schaltest du es ab.","{name} is switched off: the group skips it until it is on again": "{name} ist ausgeschaltet: Die Gruppe überspringt es, bis es wieder eingeschaltet ist",+ "{n} switched off": "{n} ausgeschaltet","Off: agents aren't offered {name} and a request to it is turned away. Click to switch it on": "Aus: Agents wird {name} nicht angeboten, eine Anfrage daran wird abgewiesen. Klicken zum Einschalten","On: agents may pick {name}. Click to switch it off and keep it as it is": "An: Agents können {name} wählen. Klicken zum Ausschalten – die Gruppe bleibt, wie sie ist","{name} switched on": "{name} eingeschaltet",diff --git a/internal/gui/tests/routing-provider-off.test.cjs b/internal/gui/tests/routing-provider-off.test.cjsindex 77c3251b7..0bf4efd08 100644--- a/internal/gui/tests/routing-provider-off.test.cjs+++ b/internal/gui/tests/routing-provider-off.test.cjs@@ -14,7 +14,7 @@ const { test } = require("node:test");const { chromium, webkit } = require("playwright");const assets = path.resolve(__dirname, "../assets");-const models = [{ id: "a/sol", name: "sol", providerName: "A Cloud", icon: "generic" }];+const models = [{ id: "a/sol", name: "sol", providerName: "A Cloud", icon: "generic" }, { id: "a/luna", name: "luna", providerName: "A Cloud", icon: "openai" }];const info = [{ id: "a/sol", ready: true, provider: "a", name: "A Cloud", model: "sol", on: 1 },{ id: "b/sol", ready: false, providerOff: true, provider: "b", name: "B Cloud", icon: "generic", model: "sol", on: 0 },@@ -24,6 +24,15 @@ const base = { members: ["a/sol", "b/sol", "c/sol"], ready: true, memberInfo: inconst groups = { models, pools: [], groups: [{ ...base, id: "auto-sol", name: "Sol", routing: "order" },{ ...base, id: "hand", name: "Hand", routing: "manual", pick: "a/sol", picked: "a/sol" },+ // one magpie found (XYenon on Discord): its card leaves the member out+ { id: "auto-luna", name: "Luna", auto: true, routing: "order", ready: true, offers: [], shared: [],+ members: ["a/luna", "b/luna"], memberInfo: [+ { id: "a/luna", ready: true, provider: "a", name: "A Cloud", icon: "openai", model: "luna", on: 1 },+ { id: "b/luna", ready: false, providerOff: true, provider: "b", name: "B Cloud", icon: "anthropic", model: "luna", on: 0 },+ ] },+ // every member's provider off: nothing left to show, so they are said+ { id: "auto-terra", name: "Terra", auto: true, routing: "order", ready: false, offers: [], shared: [],+ members: ["b/terra"], memberInfo: [{ id: "b/terra", ready: false, providerOff: true, provider: "b", name: "B Cloud", icon: "anthropic", model: "terra", on: 0 }] },] };function serve(lang) {@@ -80,6 +89,27 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",assert.equal(await pick.evaluate((b) => b.classList.contains("off")), true);assert.equal(await hand.locator('.rt-pick[data-member="c/sol"]').getAttribute("title"), await say("No provider serves {id} now; it is skipped", { id: "c/sol" }));+ // a group magpie found lists only the members it can send to, and+ // its logos are theirs: the switched-off one is counted in a tag+ // that says why when hovered+ const found = page.locator(".rt-group", { hasText: "Luna" }).first();+ assert.equal(await found.locator(".mem").first().textContent(), "A Cloud · luna");+ const tag = found.locator(".tag.rt-goff");+ assert.equal(await tag.textContent(), await say("{n} switched off", { n: 1 }));+ if (lang !== "en") assert.notEqual(await tag.textContent(), "1 switched off", `${lang} has it in its own words`);+ assert.equal(await tag.getAttribute("title"), why);+ const logos = await found.locator(".rt-ghandle").innerHTML();+ assert.ok(!logos.includes("anthropic"), "no logo of the provider switched off: " + logos);+ const terra = page.locator(".rt-group", { hasText: "Terra" }).first();+ assert.equal(await terra.locator(".mem").first().textContent(), `B Cloud · terra (${off})`);+ assert.equal(await terra.locator(".tag.rt-goff").count(), 0);+ // its editor still has the member, greyed with why+ await found.locator("button", { hasText: await say("Edit") }).dispatchEvent("click");+ const fed = page.locator(".rt-gedit");+ assert.equal(await fed.locator(".fbrow", { has: page.locator(".n small", { hasText: `B Cloud · ${off}` }) }).count(), 1);+ await fed.locator("button", { hasText: await say("Cancel") }).first().dispatchEvent("click");+ await fed.waitFor({ state: "detached" });+// the editor: its row muted, saying why// the page puts back a scroll the reader didn't make, so at 420 the// button is clicked where it isdiff --git a/internal/tui/group_provider_off_test.go b/internal/tui/group_provider_off_test.gonew file mode 100644index 000000000..48af3fda2--- /dev/null+++ b/internal/tui/group_provider_off_test.go@@ -0,0 +1,61 @@+package tui++import (+ "strings"+ "testing"++ "github.com/yetone/magpie/internal/provider"+)++// A group magpie found keeps a member whose provider is switched off+// (#2671), but its line on the routing page lists only those the gateway+// can send to, and says how many are off (XYenon on Discord: a provider+// switched off was still listed in the found group). A group of the user's+// lists what they put in; the group's own page marks the member off.+func TestFoundGroupLineLeavesASwitchedOffProviderOut(t *testing.T) {+ home(t)+ for _, p := range []provider.Provider{+ {ID: "pa", Name: "PA", Key: "k", Models: []string{"luna"}, Chat: "http://127.0.0.1:1/v1"},+ {ID: "pb", Name: "PB", Key: "k", Models: []string{"luna"}, Chat: "http://127.0.0.1:1/v1"},+ } {+ if err := provider.Save(p); err != nil {+ t.Fatal(err)+ }+ }+ if err := provider.SaveGroup(provider.Group{ID: "mine", Name: "Mine", Members: []string{"pa/luna", "pb/luna"}}); err != nil {+ t.Fatal(err)+ }+ if err := provider.SetOff("pb", true); err != nil {+ t.Fatal(err)+ }+ m := press(t, model{w: 160, h: 40}, "3")+ line := func(name string) string {+ t.Helper()+ for _, l := range strings.Split(m.View(), "\n") {+ if strings.Contains(l, name) {+ return l+ }+ }+ t.Fatalf("no %s line:\n%s", name, m.View())+ return ""+ }+ if l := line("auto/luna"); strings.Contains(l, "pb/luna") || !strings.Contains(l, "pa/luna") || !strings.Contains(l, "1 model ") || !strings.Contains(l, "1 switched off") {+ t.Fatalf("found group's line: %q", l)+ }+ if l := line("group/mine"); !strings.Contains(l, "pa/luna → pb/luna") || strings.Contains(l, "switched off") {+ t.Fatalf("the user's group's line: %q", l)+ }+ m.gid, m.mode = "auto-luna", modeGroup+ v := m.View()+ if !strings.Contains(v, "pb/luna · switched off") || strings.Contains(v, "pa/luna · switched off") {+ t.Fatalf("the found group's page:\n%s", v)+ }+ // on again: listed as before+ if err := provider.SetOff("pb", false); err != nil {+ t.Fatal(err)+ }+ m = press(t, model{w: 160, h: 40}, "3")+ if l := line("auto/luna"); !strings.Contains(l, "pa/luna → pb/luna") || strings.Contains(l, "switched off") {+ t.Fatalf("pb on again: %q", l)+ }+}diff --git a/internal/tui/routing.go b/internal/tui/routing.goindex 169b4cdf2..0aaa0aa97 100644--- a/internal/tui/routing.go+++ b/internal/tui/routing.go@@ -32,6 +32,40 @@ func (m *model) reloadGroups() {m.shown = len(m.groups)m.groups = append(m.groups, removed...)m.grow = clamp(m.grow, len(m.groups))+ m.provOff = map[string]bool{}+ for _, p := range provider.All() {+ if !p.On() {+ m.provOff[p.ID] = true+ }+ }+}++// memberOff is whether a member of a group is a model of a provider+// switched off: the group keeps it (one magpie found too, #2671) and the+// gateway skips it until the provider is on again.+func (m model) memberOff(id string) bool {+ if provider.IsGroupRef(id) {+ return false+ }+ pid, _, ok := strings.Cut(id, "/")+ return ok && m.provOff[pid]+}++// listedMembers are the members a group's line lists: of a group magpie+// found, those its providers being on lets it send to (XYenon on Discord:+// a provider switched off was still listed in it), as every model list+// leaves a provider switched off out, and how many it left out; all of+// them when that would leave none. A group of the user's lists what they+// put in.+func (m model) listedMembers(g provider.Group) ([]string, int) {+ if !g.Auto {+ return g.Members, 0+ }+ on := slices.DeleteFunc(slices.Clone(g.Members), m.memberOff)+ if len(on) == 0 {+ return g.Members, 0+ }+ return on, len(g.Members) - len(on)}var routings = []string{"", provider.Ordered, provider.Rotate, provider.LeastUsed, provider.Pace, provider.Weighted, provider.FreeFirst, provider.Fastest, provider.Manual}@@ -593,7 +627,11 @@ func (m model) viewGroups() string {b.WriteString(line + "\n")continue}- notes := []string{fmt.Sprintf("%d model%s", len(g.Members), plural(len(g.Members))), groupRouting(g)}+ listed, off := m.listedMembers(g)+ notes := []string{fmt.Sprintf("%d model%s", len(listed), plural(len(listed))), groupRouting(g)}+ if off > 0 {+ notes = append(notes, fmt.Sprintf("%d switched off", off))+ }if g.Affinity != "" {notes = append(notes, staysName(g.Affinity))}@@ -606,7 +644,7 @@ func (m model) viewGroups() string {if g.Auto {notes = append(notes, "found")}- members := strings.Join(g.Members, " → ")+ members := strings.Join(listed, " → ")if len(g.Match) > 0 {notes = append(notes, fmt.Sprintf("%d pattern%s", len(g.Match), plural(len(g.Match))))}@@ -653,6 +691,9 @@ func (m model) viewGroup() string {if slices.Contains(g.Matched, id) {name += sMuted.Render(" · by pattern")}+ if m.memberOff(id) {+ name += sMuted.Render(" · switched off: skipped until it is on again")+ }b.WriteString(pad + marker + sFaint.Render(fmt.Sprintf("%d ", i+1)) + name + "\n")}// patterns find models in the catalog each time (#766): how many now,diff --git a/internal/tui/tui.go b/internal/tui/tui.goindex fc934e00b..a8654309c 100644--- a/internal/tui/tui.go+++ b/internal/tui/tui.go@@ -117,6 +117,7 @@ type model struct {bal map[string]stringasked bool // balances were asked forgroups []provider.Group+ provOff map[string]bool // providers switched off, read with the groupsgrow intshown int // groups from here on were removed: listed last, to bring backgid string // the group open