diff --git a/docs/subsystems/providers-accounts.md b/docs/subsystems/providers-accounts.md index 385240dbf..5c9ed3a1e 100644 --- a/docs/subsystems/providers-accounts.md +++ b/docs/subsystems/providers-accounts.md @@ -63,7 +63,7 @@ keys and accounts per request is in [Gateway routing and fallback](gateway-routi | Removing the signed-in account | `ForgetLogin` signs Codex or Claude Code in to another of its accounts first (`nextOnForget`: the first other that is on, else one whose sign-in holds, else any, never a setup-token account or one Codex keeps in another folder: `switchable`), then forgets this one; a switch that fails removes nothing (StringKe, #4532: Claude's was refused while Codex's switched). Codex's only account is signed out as `codex logout` does. Claude Code is never signed out: its last account it can be signed in to is refused with `SignedInError{Only}` (GUI code `signed_in_only`, and that account has no *Remove*). Claude Code's own credential is never deleted; the forgotten account's folder (`forgetClaudeDir`) is its own. `TestForgetLiveClaudeSwitchesFirst`, `TestForgetOnlyClaudeIsKept`, `codex-signout.test.cjs`. | | 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/`); `SaveGroup` refuses loops. A group given another id (`agent.RenameGroup`: the Routing groups page, `magpie groups rename`, the TUI) moves every agent field on `group/` to `group/`, 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). What a pattern matches follows the members named, in the catalog's order, until the user drags it elsewhere (usrname1833 on Discord): `Placed` keeps the whole order, named and matched alike, and the group is read and routed in it (`placedIn`); a model matched since goes last, one no longer matched drops out, a save that sends the named members only leaves the matched where they were (`placedOver`), and a provider's or group's rename carries it (`TestGroupPatternMembersKeepTheirPlace`, `group-member-drag.test.cjs`). 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. It keeps following its model as a found group does (Kxsg79bEYFP4 on X: a third provider with the model, a plugin's, had stayed out of a group the user had changed): `SaveGroup` stores, for an `auto-…` id, what it had seen (`Group.Seen`: the models magpie found in it by that save, and those the user named, as `provider/model`), and a provider that serves the model since joins it as it is read, after the user's own members (`joined`, not written back), unless kept out of found groups. A model seen and not a member is one the user took out, and stays out; a provider's rename or a fold carries `Seen` (`mapModelRefs`), and a shared group leaves it behind. A found group changed before `Seen` was kept takes in nothing, as nothing says which of its models the user took out; its next save sees what is found then (`TestChangedFoundGroupTakesInANewProvider`, `TestChangedFoundGroupFromBeforeKeepsItsMembers`, `TestChangedFoundGroupTakesInAPluginProvider`). A switched-off provider's members stay in it, skipped by `membersIn`, and the Routing groups 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 groups 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 groups 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 groups 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 Remote magpie's cards (`GET /v1/magpie/quotas/cards`, `writeCards`) carry the estimate too, for the owner or a key with no limits on what it sees, since the computer reading them has none of the remote's calls to reckon from (linkaww on Discord: a Docker magpie's ChatGPT Pro week showed no whole on the other computer; `TestRemoteMagpieCardsCarryTheirWholes`). A Codex card's estimate counts the calls of a ChatGPT API account (`chatgpt-api`) that is the same ChatGPT account, whose plan limits they share: the tokens of both must name the same `chatgpt_account_id` and `chatgpt_user_id`, never matched by name, so two Team seats of one email stay apart (`SamePlanAccounts` in [`chatgpt_same_plan.go`](../../internal/provider/chatgpt_same_plan.go), jctaoo on Discord, `TestWindowHoldsCountsTheSameChatGPTAccountThroughTheAPI`). 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). What it has kept includes its own Remote magpies' cards as it last read them (`passedOnCards`, no remote asked), so a chain passes every card on (yuyong_id on Discord: magpie3 → magpie2 → magpie1 showed none of magpie1's Codex at magpie3), named after each magpie (`magpie2/magpie1/codex`, "Codex · magpie1 · magpie2"); the card standing for a remote and its keys' limits stay the reader's own. Each card carries `via`, the `catalog.Self` of each magpie it went through, and a reader leaves out one that loops (`catalog.Loops`, as a model's `magpie_via`). A refresh of such a card is passed to the magpie it came from (`quotaCardsRefresh` takes a card id this magpie has from a remote); a Codex reset is offered on the magpie next door only, and quota history isn't passed on. The status line's kept report (`KeptQuotaReport`) has a remote's cards the same way. Each key of a remote-magpie provider also gets a card of its own, under `/~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=/~keys&user=`). 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's Codex card keeps its `Resets` (not a GLM team's, `ByWindow`), and its check-ins are dropped: **Use one…** there goes through `/api/usage/codex-reset` with the card's `provider`, and `UseRemoteCodexReset` asks the remote's `POST /v1/magpie/quotas/codex-reset?user=` with the provider's key (#3850). The remote spends it with `SpendCodexReset`, the same function as the Usage page (`UseCodexResetCard`, then `AwaitAllowance`). The account is always named. A 403 `gateway_key_read_only` is told as a read-only key there, and a 404 as a remote too old. No answer within `RemoteResetWait` says the reset may have been used, and it is never asked again by itself. 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 beside the key's own card the remote's card says it tells this key no quotas, and that on that computer Quotas is turned on for the key and it is let use every model of a provider whose usage it is to see (`errRemoteHeld`; yi_time on Discord saw the remote's Claude vanish from every page with no word). Its owner can let the key be told the cards of what it may use (#2216, `magpie gateway-key quotas on`); the remote then answers those, and 403 held as before when that is none (`writeCards`), so that key shows the same card. 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) | +| 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 Remote magpie's cards (`GET /v1/magpie/quotas/cards`, `writeCards`) carry the estimate too, for the owner or a key with no limits on what it sees, since the computer reading them has none of the remote's calls to reckon from (linkaww on Discord: a Docker magpie's ChatGPT Pro week showed no whole on the other computer; `TestRemoteMagpieCardsCarryTheirWholes`). A Codex card's estimate counts the calls of a ChatGPT API account (`chatgpt-api`) that is the same ChatGPT account, whose plan limits they share: the tokens of both must name the same `chatgpt_account_id` and `chatgpt_user_id`, never matched by name, so two Team seats of one email stay apart (`SamePlanAccounts` in [`chatgpt_same_plan.go`](../../internal/provider/chatgpt_same_plan.go), jctaoo on Discord, `TestWindowHoldsCountsTheSameChatGPTAccountThroughTheAPI`). 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). What it has kept includes its own Remote magpies' cards as it last read them (`passedOnCards`, no remote asked), so a chain passes every card on (yuyong_id on Discord: magpie3 → magpie2 → magpie1 showed none of magpie1's Codex at magpie3), named after each magpie (`magpie2/magpie1/codex`, "Codex · magpie1 · magpie2"); the card standing for a remote and its keys' limits stay the reader's own. Each card carries `via`, the `catalog.Self` of each magpie it went through, and a reader leaves out one that loops (`catalog.Loops`, as a model's `magpie_via`). A refresh of such a card is passed to the magpie it came from (`quotaCardsRefresh` takes a card id this magpie has from a remote); a Codex reset is offered on the magpie next door only, and quota history isn't passed on. The status line's kept report (`KeptQuotaReport`) has a remote's cards the same way. A ChatGPT account's card has an *Image generation* row (`WithImageLane`, [`image_lane.go`](../../internal/provider/image_lane.go), `Lane` `images`, Text and Aside so routing, holds and history never see it; hqqqqqqqh on X, #6160): ChatGPT's images have a quota apart from the 5-hour and weekly windows, and neither `/wham/usage` (`additional_rate_limits` is null) nor the reply headers (`x-codex-primary-*`, `x-codex-secondary-*`) tell it. So the row says *Used up* with the reset time while the image model is resting on that account after a refusal (`ImageRest`, the gateway's `restingUntil`, whose time is the refusal's `resets_at`, #2244) and *Unknown* otherwise, never a share or a count (`TestWithImageLaneOnlyReadCodexCards`, `TestCodexImageRowIsTheRefusalsResetTime`, `codex-image-row.test.cjs`). Not done: the count of images made in the window. Each key of a remote-magpie provider also gets a card of its own, under `/~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=/~keys&user=`). 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's Codex card keeps its `Resets` (not a GLM team's, `ByWindow`), and its check-ins are dropped: **Use one…** there goes through `/api/usage/codex-reset` with the card's `provider`, and `UseRemoteCodexReset` asks the remote's `POST /v1/magpie/quotas/codex-reset?user=` with the provider's key (#3850). The remote spends it with `SpendCodexReset`, the same function as the Usage page (`UseCodexResetCard`, then `AwaitAllowance`). The account is always named. A 403 `gateway_key_read_only` is told as a read-only key there, and a 404 as a remote too old. No answer within `RemoteResetWait` says the reset may have been used, and it is never asked again by itself. 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 beside the key's own card the remote's card says it tells this key no quotas, and that on that computer Quotas is turned on for the key and it is let use every model of a provider whose usage it is to see (`errRemoteHeld`; yi_time on Discord saw the remote's Claude vanish from every page with no word). Its owner can let the key be told the cards of what it may use (#2216, `magpie gateway-key quotas on`); the remote then answers those, and 403 held as before when that is none (`writeCards`), so that key shows the same card. 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) | | Two magpies each the other's remote | The list a magpie gives another magpie (`X-Magpie-Drawers`) names, as `magpie_via`, the magpies each model passes through to its vendor, itself last (`catalog.ViaHere`, `viaOf`; a routing group's are its members' together, so a group with the other magpie's own group of the model in it is left out there too). Each process has a random id (`catalog.Self`). A fetched list leaves out a model whose `magpie_via` has this magpie and another one (it went out of here and came back), or more than `MaxVia` (8), so two magpies that are each other's remote no longer list each other's models back one level deeper on every 10-minute fetch, without end, each level another member of the found `auto/` group and another trip round the two (cdredfox on Discord, 100-200% CPU). A remote that is this magpie itself (sync carries a Remote magpie provider to the computer it names, hanslin1666) has its models through this id alone, taken once; one through this id twice or more is left out. Such a remote is found by its own list: a fetch whose models' `magpie_via` ends with this magpie's own `Self` is kept, by provider id and the address it answered at, in `remote-self.json` (`noteSelf`; another lister, or a list with no via, takes it away; an empty list or a failed fetch changes nothing; this computer's own file, never in a backup or a sync). The provider is then left out (`SelfLeftOut` in `On`, `SwitchedOff`, `remoteMagpies`): its models are not listed beside this magpie's own nor in a found group, and a request naming one, an agent's pick sync brought from the other computer, is served here with the remote's id taken off the front (`ThroughSelf` in `Resolve` and `ResolveRoute`), not passed through the gateway again. The Providers row says *This magpie* (greyed while left out) and its editor says why, with **Use it anyway** (`KeepSelf`, `provider/keepself`, `SetKeepSelf`), the user's to set (hanslin1666): kept, it is served as any remote, each request twice through this magpie. `KeepSelf` is this computer's own like `KeepLogin` (`Mirror`, `Restore`, blanked in davsync's `hashes`), since the other computer's copy points at this one, which is not itself (`TestRemoteMagpieThatIsThisOneIsLeftOut`, `TestRemoteSelfRecord`, `remote-self.test.cjs`). Each request passed on to a Remote magpie says how many magpies it went through (`X-Magpie-Hops`, `passOnCaller`); one that arrives having passed `MaxVia` is answered 508 Loop Detected (`withCaller`), read only from a magpie's request and taken off every request as it arrives. A magpie older than the field sends none, and its models are taken as they were. The quota cards a Remote passes on follow the same ways (X on 0.1.3678: A → B → C → A told Kiro and Codex by `remote-B/kiro` and `remote-B/remote-C/remote-A/remote-B/remote-C/kiro`, hours apart, to a Remote enabled for one local model): a card's `via` that names any magpie twice is a loop too, so one that came round after this magpie restarted (its old `Self` is no longer this one's) is left out (`catalog.Loops`), and isn't kept in `remoteCardCache` (`keepRemoteCards`). A Remote's cards are shown, and passed on, only for the providers it is enabled for: the first part of the card's provider id must be the first part of an exposed model's id there (`remoteCardWanted`), unknown, so all shown, while its list isn't read. One subscription account's copies (same provider, same `user`) are one card, the newest complete reading, then the shorter way (`oneCardPerAccount`, in `RemoteCards` and `CachedCards`; a key's cards, whose `user` is a name two keys may share, are not merged) (`TestRemoteCardsFollowEnabledModelsAndDedupe`, `TestLoopsOnARepeatedMagpie`). | [`magpie_via.go`](../../internal/catalog/magpie_via.go), [`live.go`](../../internal/catalog/live.go), [`gateway.go`](../../internal/gateway/gateway.go), [`remote_magpie.go`](../../internal/provider/remote_magpie.go), [`remote_self.go`](../../internal/provider/remote_self.go), [`remote_quotas_scope.go`](../../internal/provider/remote_quotas_scope.go) | diff --git a/internal/gateway/image_rest.go b/internal/gateway/image_rest.go new file mode 100644 index 000000000..7725a6bc5 --- /dev/null +++ b/internal/gateway/image_rest.go @@ -0,0 +1,32 @@ +package gateway + +import ( + "strings" + "time" + + "github.com/yetone/magpie/internal/provider" +) + +func init() { provider.ImageRest = imageRestOf } + +// imageRestOf is when the ChatGPT account user draws again, as the refusal +// that rested its image model said (restDrawer; usage_limit_reached's +// resets_at), while that rest holds. It is the only thing magpie learns of +// the account's image allowance, which the backend shows no share of +// (provider.ImageLane, #6160), and it is only that: not when the allowance +// began, nor what it counted. The latest of several resting image models +// (a rest per model) is the one that says when drawing is back. +func imageRestOf(agent, user string, now time.Time) (time.Time, bool) { + restingUntil.Lock() + defer restingUntil.Unlock() + var last time.Time + for k, r := range restingUntil.note { + if r.agent != agent || !strings.EqualFold(r.user, user) || !strings.HasPrefix(r.Model, codexDrawerFamily) { + continue + } + if until := restingUntil.m[k]; until.After(now) && until.After(last) { + last = until + } + } + return last, !last.IsZero() +} diff --git a/internal/gateway/image_rest_test.go b/internal/gateway/image_rest_test.go new file mode 100644 index 000000000..c9168971d --- /dev/null +++ b/internal/gateway/image_rest_test.go @@ -0,0 +1,58 @@ +package gateway + +import ( + "net/http" + "testing" + "time" + + "github.com/yetone/magpie/internal/provider" +) + +// #6160: a ChatGPT account's image allowance shows on its card as the time +// the refusal that rested it said, and as unknown before any refusal; the +// chat windows around it are as they were. +func TestCodexImageRowIsTheRefusalsResetTime(t *testing.T) { + user := "Image.Lane@example.com" + c := candidate{p: provider.Provider{ID: "codex", Account: &provider.Account{Agent: "codex", User: user}}, model: codexDrawer} + t.Cleanup(func() { clearRest(c.restID()) }) + card := func() provider.SubscriptionQuota { + in := []provider.SubscriptionQuota{{Provider: "codex", User: user, Windows: []provider.QuotaWindow{{Name: "5 hours", Used: 40}, {Name: "7 days", Used: 10}}}} + out := provider.WithImageLane(in, time.Now()) + if len(in[0].Windows) != 2 { + t.Fatalf("the cached card was written to: %d windows", len(in[0].Windows)) + } + return out[0] + } + row := func(q provider.SubscriptionQuota) provider.QuotaWindow { + if len(q.Windows) != 3 || q.Windows[0].Name != "5 hours" || q.Windows[1].Name != "7 days" { + t.Fatalf("windows = %+v", q.Windows) + } + return q.Windows[2] + } + w := row(card()) + if w.Lane != provider.ImageLane || !w.Text || !w.Aside || w.ResetsAt != nil || w.Used != 0 || w.Display != "Unknown" { + t.Fatalf("before any refusal the row = %+v, want unknown with no time", w) + } + at := time.Now().Add(3 * time.Hour).Truncate(time.Second) + body := []byte(`{"error":{"type":"usage_limit_reached","resets_at":` + itoa(int(at.Unix())) + `}}`) + restDrawer(c, http.StatusTooManyRequests, string(body)) + w = row(card()) + if w.ResetsAt == nil || w.ResetsAt.Sub(at).Abs() > 2*time.Second || w.Display != "Used up" || w.Used != 0 || !w.Text { + t.Fatalf("after the refusal the row = %+v, want used up until %v and no share", w, at) + } + // another account's refusal is not this one's + other := candidate{p: provider.Provider{ID: "codex", Account: &provider.Account{Agent: "codex", User: "other@example.com"}}, model: codexDrawer} + t.Cleanup(func() { clearRest(other.restID()) }) + restDrawer(other, http.StatusTooManyRequests, string(body)) + clearRest(c.restID()) + if w = row(card()); w.ResetsAt != nil { + t.Fatalf("a rest lifted still shows a time: %+v", w) + } + // a chat model's rest on the account is not the image allowance + chat := candidate{p: c.p, model: "gpt-5"} + t.Cleanup(func() { clearRest(chat.restID()) }) + restDrawer(chat, http.StatusTooManyRequests, string(body)) + if w = row(card()); w.ResetsAt != nil { + t.Fatalf("a chat model's rest shows as the image row: %+v", w) + } +} diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 65fcdfb00..e25decf56 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -14441,7 +14441,8 @@ function quotaText(w) { if (w.balance != null) return t("{n} left", { n: (countFormat.format(w.balance) + " " + t(w.unit || "")).trim() }); // a text row used 100 is Claude's overages (claudeOveragesWindow): "In use", said in the reader's language if (w.text && w.used >= 100) return t("In use"); - if (quotaNoShare(w)) return w.display || t("No allowance reported"); + // a Text row's display is said in the reader's language (the image row's "Used up" and "Unknown", #6160) + if (quotaNoShare(w)) return t(w.display || "No allowance reported"); const used = to100(w.used); const n = quotaLeft ? 100 - used : used; const pct = t(quotaLeft ? "{n} left" : "{n} used", { n: (Number.isInteger(n) ? n : n.toFixed(1)) + "%" }); diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index e01fa8d7b..04457c36d 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -2346,6 +2346,7 @@ const I18N = { "Droid Core · 7 days": "Droid Core · 7 天", "Droid Core · 30 days": "Droid Core · 30 天", "Extra usage": "额外用量", + "Used up": "已用完", "Usage credits": "额外用量额度", "Gift plans to claim in the ZCode app": "待在 ZCode 客户端领取的赠送额度", "ZCode gift plans (-Trial models) need ZCode's sign-in": "ZCode 赠送额度(-Trial 模型)需要 ZCode 登录", @@ -7426,6 +7427,7 @@ const I18N = { "Droid Core · 7 days": "Droid Core · 7 天", "Droid Core · 30 days": "Droid Core · 30 天", "Extra usage": "額外用量", + "Used up": "已用完", "Usage credits": "額外用量額度", "Gift plans to claim in the ZCode app": "待在 ZCode 用戶端領取的贈送額度", "ZCode gift plans (-Trial models) need ZCode's sign-in": "ZCode 贈送額度(-Trial 模型)需要 ZCode 登入", @@ -12482,6 +12484,7 @@ const I18N = { "Droid Core · 7 days": "Droid Core · 7日", "Droid Core · 30 days": "Droid Core · 30日", "Extra usage": "追加使用量", + "Used up": "使い切り", "Usage credits": "追加使用量のクレジット", "Gift plans to claim in the ZCode app": "ZCode アプリで受け取れるギフト枠", "ZCode gift plans (-Trial models) need ZCode's sign-in": "ZCode のギフト枠(-Trial モデル)には ZCode でのサインインが必要", @@ -17569,6 +17572,7 @@ const I18N = { "Droid Core · 7 days": "Droid Core · 7 Tage", "Droid Core · 30 days": "Droid Core · 30 Tage", "Extra usage": "Zusätzliche Nutzung", + "Used up": "Aufgebraucht", "Usage credits": "Nutzungsguthaben", "Gift plans to claim in the ZCode app": "In der ZCode-App abzuholen", "ZCode gift plans (-Trial models) need ZCode's sign-in": "ZCode-Geschenkpläne (-Trial-Modelle) brauchen die ZCode-Anmeldung", diff --git a/internal/gui/tests/codex-image-row.test.cjs b/internal/gui/tests/codex-image-row.test.cjs new file mode 100644 index 000000000..3dffdbb90 --- /dev/null +++ b/internal/gui/tests/codex-image-row.test.cjs @@ -0,0 +1,83 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// A ChatGPT account's image allowance (#6160) is a row of its own on the +// Usage card, beside the 5-hour and weekly windows: "used up" with the time +// it comes back when a refusal named it, "unknown" when nothing is known, +// and never a share or a meter. In every language, at the window's width +// and a phone's. No backend, the API is faked here. +const assert = require("node:assert/strict"); +const fs = require("node:fs/promises"); +const path = require("node:path"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); + +const assets = path.resolve(__dirname, "../assets"); + +const soon = new Date(Date.now() + 3 * 3600 * 1000).toISOString(); +const img = (extra) => ({ name: "Image generation", lane: "images", text: true, aside: true, used: 0, display: "Unknown", ...extra }); +const chat = [{ name: "5 hours", used: 40, resetSecs: 3600 }, { name: "7 days", used: 10, resetSecs: 86400 }]; +const quotas = [ + { provider: "codex", name: "Codex", icon: "codex-color", user: "spent@example.com", windows: [...chat, img({ display: "Used up", resetsAt: soon, resetSecs: 10800 })] }, + { provider: "codex", name: "Codex", icon: "codex-color", user: "fresh@example.com", windows: [...chat, img({})] }, +]; + +const words = { + en: { name: "Image generation", used: "Used up", unknown: "Unknown" }, + zh: { name: "生图模型", used: "已用完", unknown: "未知" }, + "zh-TW": { name: "生圖模型", used: "已用完", unknown: "未知" }, + ja: { name: "画像生成", used: "使い切り", unknown: "不明" }, + de: { name: "Bilderzeugung", used: "Aufgebraucht", unknown: "Unbekannt" }, +}; + +function serve(lang) { + const settings = { theme: "light", lang, currency: "usd" }; + return async (route) => { + const url = new URL(route.request().url()); + const json = (body) => route.fulfill({ json: body }); + if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` }); + 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: [], presets: [], excluded: [], gateway: { running: true, window: true } }); + if (url.pathname === "/api/usage/quotas") return json(quotas); + if (url.pathname === "/api/usage/quotas/history") return json([]); + if (url.pathname === "/api/usage") return json({ days: [] }); + if (url.pathname === "/api/groups") return json({ groups: [], models: [] }); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname.startsWith("/api/")) return json({}); + const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname); + const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)]; + try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); } + }; +} + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + test(`${engine}: a ChatGPT account's image row says used up until a time, or unknown, in every language`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + for (const width of [900, 390]) for (const lang of Object.keys(words)) { + const at = `${lang} ${width}`; + const errors = []; + const page = await (await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" })).newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang)); + await page.goto("http://magpie.test/?view=usage&tab=usage"); + await page.locator("#subscriptionUsage .quota").first().waitFor(); + await page.locator(".quota-more").click(); + const w = words[lang]; + for (const [user, text, resets] of [["spent@example.com", w.used, true], ["fresh@example.com", w.unknown, false]]) { + const mine = page.locator(`[data-card="codex|${user}"] + .quota-windows`); + const row = mine.locator(".quota", { hasText: w.name }); + await row.waitFor(); + assert.equal((await row.locator(".quota-n").textContent()).trim(), text, at + " " + user); + assert.equal(await row.locator(".quota-track").count(), 0, at + " an image row has no meter, nothing told a share"); + assert.equal(await row.locator(".quota-reset").count(), resets ? 1 : 0, at + " " + user + " reset line"); + assert.doesNotMatch(await row.textContent(), /%/, at + " no percent is made up"); + } + assert.equal(await page.locator('[data-card="codex|spent@example.com"] + .quota-windows .quota-track').count(), 2, at + " the chat windows keep their meters"); + assert.deepEqual(errors, [], at); + await page.context().close(); + } + }); +} diff --git a/internal/provider/image_lane.go b/internal/provider/image_lane.go new file mode 100644 index 000000000..4dd9d77b7 --- /dev/null +++ b/internal/provider/image_lane.go @@ -0,0 +1,50 @@ +package provider + +import ( + "strings" + "time" +) + +// ImageLane is the name of a ChatGPT account's image window (QuotaWindow.Lane). +// Drawing with gpt-image-2 counts against an allowance of its own, apart from +// Codex's 5-hour and weekly windows (#6160), and the backend tells no share of +// it: /wham/usage has no image window (additional_rate_limits is null) and a +// reply carries no x-codex-* header for one. What magpie knows is the refusal +// it got, usage_limit_reached with the time it comes back, which the gateway +// keeps as the image model's rest (ImageRest). So the row says that time, or +// "unknown": never a share, which nothing told. +const ImageLane = "images" + +// ImageRest is, set by the gateway, when the image model of the ChatGPT +// account user (as its usage is read, Account.UsageAgent) is back, while the +// vendor's refusal keeps it resting; false when it is not. +var ImageRest func(agent, user string, now time.Time) (time.Time, bool) + +// WithImageLane is qs with a row for the image allowance added to each +// ChatGPT account's card that was read: Text and Aside, so no share is told +// and routing never reads it, with ResetsAt when a refusal named the time it +// comes back and no time otherwise. A card of another magpie is as it came; +// qs and its windows, which the caches share, are left as they were. +func WithImageLane(qs []SubscriptionQuota, now time.Time) []SubscriptionQuota { + out := make([]SubscriptionQuota, len(qs)) + for i, q := range qs { + out[i] = q + if q.Provider != "codex" || q.From != "" || q.Error != "" || q.User == "" { + continue + } + ws := make([]QuotaWindow, 0, len(q.Windows)+1) + for _, w := range q.Windows { + if w.Lane != ImageLane { + ws = append(ws, w) + } + } + w := QuotaWindow{Name: "Image generation", Lane: ImageLane, Text: true, Aside: true, Display: "Unknown"} + if ImageRest != nil { + if until, ok := ImageRest("codex", strings.ToLower(q.User), now); ok { + w.Display, w.ResetsAt, w.ResetSecs = "Used up", &until, int64(until.Sub(now)/time.Second) + } + } + out[i].Windows = append(ws, w) + } + return out +} diff --git a/internal/provider/image_lane_test.go b/internal/provider/image_lane_test.go new file mode 100644 index 000000000..0f0f33293 --- /dev/null +++ b/internal/provider/image_lane_test.go @@ -0,0 +1,38 @@ +package provider + +import ( + "testing" + "time" +) + +// WithImageLane adds the image row to a read ChatGPT account's card only, +// once, and says unknown, never a share, when nothing was heard. +func TestWithImageLaneOnlyReadCodexCards(t *testing.T) { + was := ImageRest + t.Cleanup(func() { ImageRest = was }) + ImageRest = nil + now := time.Now() + win := []QuotaWindow{{Name: "5 hours", Used: 100}} + in := []SubscriptionQuota{ + {Provider: "codex", User: "a@x.com", Windows: win}, + {Provider: "codex", User: "b@x.com", Error: "not signed in"}, + {Provider: "codex", User: "c@x.com", From: "elsewhere", Windows: win}, + {Provider: "claude", User: "d@x.com", Windows: win}, + } + out := WithImageLane(WithImageLane(in, now), now) + if len(out[0].Windows) != 2 || out[0].Windows[1].Lane != ImageLane || out[0].Windows[1].Used != 0 || out[0].Windows[1].Display != "Unknown" || out[0].Windows[1].ResetsAt != nil { + t.Fatalf("read card = %+v", out[0].Windows) + } + for _, i := range []int{1, 2, 3} { + if len(out[i].Windows) != len(in[i].Windows) { + t.Errorf("card %d got a row: %+v", i, out[i].Windows) + } + } + until := now.Add(time.Hour) + ImageRest = func(agent, user string, _ time.Time) (time.Time, bool) { + return until, agent == "codex" && user == "a@x.com" + } + if w := WithImageLane(in, now)[0].Windows[1]; w.ResetsAt == nil || !w.ResetsAt.Equal(until) || w.ResetSecs != 3600 { + t.Fatalf("row = %+v", w) + } +} diff --git a/internal/provider/quotas.go b/internal/provider/quotas.go index 7c44b9a9d..938208a30 100644 --- a/internal/provider/quotas.go +++ b/internal/provider/quotas.go @@ -56,7 +56,7 @@ func quotas(ctx context.Context) (subs, plans, balances []SubscriptionQuota) { go func() { p <- PlanQuotas(ctx) }() go func() { r <- RemoteCards(ctx) }() plans, subs = seatCards(<-p, SubscriptionUsage(ctx)) - subs, balances = withAccountNames(subs), <-b + subs, balances = WithImageLane(withAccountNames(subs), time.Now()), <-b // a remote magpie's cards, each after this computer's of its kind for _, q := range <-r { switch q.Kind { @@ -132,6 +132,8 @@ type QuotaSpan struct { // Text: the window is its Display alone, Used and Remaining no // reading (QuotaWindow.Text) Text bool `json:"text,omitempty"` + // Lane names an allowance apart from the account's own (QuotaWindow.Lane) + Lane string `json:"lane,omitempty"` // Amount of Limit in Unit: the window's count, used, when the vendor // counts it so ("credits") Amount float64 `json:"amount,omitempty"` @@ -206,7 +208,7 @@ func quotaReport(subs, plans, balances []SubscriptionQuota, now time.Time) []Quo // a pool's own windows stand in for the models' drawing on it, // as the usage page shows them for _, w := range PooledWindows(q.Windows) { - s := QuotaSpan{Unlimited: w.Unlimited, Name: w.Name, Used: w.Used, Remaining: max(0, 100-w.Used), ResetsAt: w.ResetsAt, Display: w.Display, Text: w.Text, + s := QuotaSpan{Unlimited: w.Unlimited, Name: w.Name, Used: w.Used, Remaining: max(0, 100-w.Used), ResetsAt: w.ResetsAt, Display: w.Display, Text: w.Text, Lane: w.Lane, Amount: w.Amount, Limit: w.Limit, Unit: w.Unit, Pool: w.Pool, RunsOutAt: w.RunsOutAt, RunsOut: w.RunsOut, Balance: w.Balance, Spent: w.Spent, SpentSince: w.SpentSince, Holds: w.Holds, HoldsWhy: w.HoldsWhy} if s.ResetsAt == nil && w.ResetSecs > 0 { diff --git a/internal/provider/remote_quotas.go b/internal/provider/remote_quotas.go index 0e50ce0b7..21e7f312d 100644 --- a/internal/provider/remote_quotas.go +++ b/internal/provider/remote_quotas.go @@ -140,7 +140,7 @@ func CachedCards(now time.Time) []SubscriptionQuota { } plans, balances = withKeyReadings(plans, ps, "plan"), withKeyReadings(balances, ps, "balance") plans, subs = seatCards(plans, subs) - subs = withAccountNames(subs) + subs = WithImageLane(withAccountNames(subs), now) out := []SubscriptionQuota{} for _, g := range []struct { kind string diff --git a/internal/provider/subscription_usage.go b/internal/provider/subscription_usage.go index 2bbd97445..5817323e8 100644 --- a/internal/provider/subscription_usage.go +++ b/internal/provider/subscription_usage.go @@ -41,6 +41,11 @@ type QuotaWindow struct { // "100% left". Claude's "Extra usage" row (claudeOveragesWindow) is // the one Text window with Used 100: the account counts as spent. Text bool `json:"text,omitempty"` + // Lane names a window of an allowance apart from the account's own + // ("images", ImageLane): its row is Text, and says only when it comes + // back, if known. Added as cards are handed out (WithImageLane), never + // cached. + Lane string `json:"lane,omitempty"` // Amount of Limit is the window's own count in Unit, when the vendor // counts it so (WorkBuddy's credits): Used is Amount as a share of // Limit. The GUI says it as used or left, as it says the share (#659).