ac4af582301a4e8a29245dbba767eba31334ddf9
21
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
96f99b7609 |
provider: a Codex reset's lost use record is named, not silent (#5556)
noteResetUsed dropped the errors of keeping codex-resets-used.json: a full disk or a denied path left the spend a success with no record and no word of it. It says so now, and spendCodexReset names the loss in the log. The spend stays a success either way: the reset is spent on the server, so a lost record must never read as one to spend again. Run (wsl-run, magpie-desktop, Go 1.26.8), with #5555 on top: - go vet ./internal/provider; gofmt -l internal/provider: clean - go test -count=1 -run 'Reset|Expiring|CapNeverSpends' ./internal/provider: ok - go test -race -count=5 -run 'TestResetUse|TestExpiringSpend|TestSpendExpiringCodexResets': ok Broken by hand: the write's error dropped again (`_ = steady.WriteFile`): TestResetUseWriteFailureSeen red, "the record's loss went unnamed". Not changed (pre-existing, its own issue): when readResetsUsed fails for a reason other than a parse (a denied read), no copy is put aside and the history is written over, and the `.bad-` copy's own write error is dropped. Not tried: a real full disk or denied path on a real account. Reported-by: cgsme Co-authored-by: ggbdpq <ggbdpq@gmail.com> |
||
|
|
c57a5f7f58 |
gateway: a vendor's redirect to another origin is sent no provider key
Go's http.Client follows up to 10 redirects to any host, https to http included, and on a hop to another domain drops only Authorization, Cookie and WWW-Authenticate. So a vendor (or anything answering at its URL) that redirected elsewhere got x-api-key, x-goog-api-key, api-key and a provider's own headers sent there; Authorization too when only the port differed, and all of them in the clear on an https to http hop on the same host. The class is fixed where the requests leave: - provider.KeepsCredentials is a CheckRedirect that follows a redirect only to the request's own origin (scheme, host, port; or http to https on the same host and default ports), at most 10, and gives any other 3xx back as the answer (http.ErrUseLastResponse). - provider.Keyed(c) is a copy of c with c's own CheckRedirect, then KeepsCredentials. Provider.do, the choke point of every p.Do, sends through it, and every http.DefaultClient.Do in internal/provider that carries a credential is Keyed(http.DefaultClient).Do. A copy per call, since netproxy.Install sets the default client's transport at run time. Left alone: Grok's public download, Antigravity's version URL and cline.go's unsigned read. - the gateway's client (s.client, every vendor call), the Codex relay's and the Codex websocket's take KeepsCredentials, and so does chatgpt_api's siwcClient. The native route needs nothing more: the vendor's 3xx comes back to the caller as it came, Location included, and the caller decides. Translated routes don't follow either, rather than following with credentials stripped: it is the rule search_api.go had already (#1580), no vendor magpie speaks to was found redirecting its API to another origin, a stripped request elsewhere would only fail with a confusing 401, and the vendor-URL downloads (video, images) are fetched unsigned through vendorClient, so they are not affected. Tests: TestRedirectKeepsTheKeyAtItsOrigin (307 and 302 elsewhere with Authorization, x-api-key, x-goog-api-key, api-key and a custom header; a same-origin redirect followed with every key; three clients), TestRedirectNeverDowngrades (an https vendor's redirect to http on its own host and port), TestSameOrigin, TestKeyedKeepsTheClientsRule, TestNativeRedirectKeepsTheKey (Anthropic and Gemini providers with an own header) and TestChatRedirectKeepsTheKey. Broken by hand: with Provider.do back on client.Do and s.client without CheckRedirect, the thief got every key header, /away answered 200, the https vendor's /plain was followed (400 from the TLS port spoken to in http), the native route's claudeish and gem answered the thief's {"stolen":true} with Authorization, X-Api-Key and X-Relay-Secret sent there, and the chat route sent Api-Key, Authorization and X-Relay-Secret to it. TestSameOrigin and TestKeyedKeepsTheClientsRule don't depend on the wiring and passed. Run on mote at the pushed head 883690a0b (this commit and the next, on origin/main |
||
|
|
5ee5274bd9 |
quotas: a remote magpie's Codex reset is used from its card here (#3850)
prgrmrwy runs magpie on a home server and uses it from work through a remote magpie (and DSH). The remote Codex card said "1 reset", but the reset could only be used from the GUI of the computer that holds the sign-in. What changed: - Gateway: POST /v1/magpie/quotas/codex-reset?user=<email>[&credit=<id>] (Server.codexReset) spends one of that account's resets with provider.SpendCodexReset. That is the Usage page's own code (UseCodexResetCard, then AwaitAllowance), moved out of internal/gui/usage.go so both use it. A reset can't be undone, so the route needs an enabled gateway key with full access, from loopback too. No key gets 401, and that covers every corsGuard exemption that has no key: Origin null, app schemes, *.localhost and a missing Origin. A read-only key gets 403 gateway_key_read_only (readOnlyGuard, which readOnlyRefused now lists, and again in the handler). A held key gets 403 gateway_key_held, even one told quotas. The account must be named (400 otherwise). One ask runs per account at a time (409). When the reset is used, that card is read again. - Remote client: UseRemoteCodexReset (remote_quotas.go) asks the remote with the provider's key. remoteJSON's status mapping is shared through remoteBody. A read-only key there is told as such, and a 404 as a remote too old. With no answer in time it says the reset may have been used, and it never asks again by itself. A remote Codex card now keeps its Resets; a GLM team's (byWindow) and every check-in are still dropped. - GUI: "Use a reset" / "Use one..." show on a remote Codex card (codexResetCard). They open the same in-app confirmation sheet, with a line saying which computer's magpie uses it, and send the card's provider to /api/usage/codex-reset. The remote's errors are put in the user's words. New strings are in all 5 languages. - DSH: no code here. Its provider plugin reads /v1/magpie/quotas/cards and can call the new route with a full key. - resetOutcome (a reset's result in words) moved from app.js into resetask.js, the only place that says it, so the core's scripts stay in TestCoreScriptBudget's 1,533,802 with no raise (1,533,003 after; origin/main |
||
|
|
323159f1cc |
usage: a Codex reset's confirmation picks which of the account's resets is used (01huadalang)
01huadalang on Discord: resets were used only automatically, or by hand
the one that runs out first. Which account was already the user's to pick
(each account's card has its own Use); which of its resets was not.
- Usage card's "Use a reset" and the menu bar panel's "Use one...": when
the account holds two or more resets listed with their ids, the
confirmation has a "Reset to use" pop-up (the app's menu, not <select>),
soonest first and picked unless another is. Once another is picked it
names the account and that reset ("The one used is me@'s reset that
runs out ..."), and says the sooner one is kept and lost if unused.
Escape closes the open menu first, not the confirmation.
- POST /api/usage/codex-reset takes an optional credit. The server reads
the account's resets again and spends that credit only if it is still
held; a gone one is refused and no other is spent in its place. With no
credit it is as before (the soonest). Auto-use is unchanged.
- ResetCard carries the credit id; `magpie quota reset --card n` is the
CLI's sibling, its prompt naming the reset.
- askReset's dialog moved out to resetask.js, imported when Use is
pressed (like signsheets.js), so the core's scripts are 1,530,733 bytes,
under the 1,533,105 budget with no raise (the pick alone took it 2,068
over). Five keys in zh, zh-TW, ja, de.
Run on mote (mote-run), at the base
|
||
|
|
04ec2d710c |
provider: a failed read of when Codex resets run out no longer leaves one about to expire unspent for six hours (donutsone on X)
donutsone on X: "codex 自动使用重置卡没有生效": "before one expires" was
on and the card ran out unspent.
Cause: codexResets reads when the cards run out in a second call bounded
at 4s, best effort. When it failed (a timeout through a slow proxy, a 5xx)
Until was nil, the same as "none runs out". expiringResets.check took
that nil for "never": it dropped the expiry it had read before and left
the account unread for resetExpiryFar (6h). One failed read anywhere in
the card's last ~6.5 hours, including the 5-minute looks of its last
hour, let it run out.
Fix: a failed read sets ResetCredits.untilUnread. check treats a
held reset with an unread Until as a failed look, keeping the last read
expiry and looking again by it (every 5 minutes near it). The background
look also waits up to 30s for that read (withResetDetailsWait), where the
Usage card keeps its 4s. Nothing changes for the card, routing or the
"never runs out" case.
Tests: TestExpiringResetSpentPastAFailedRead runs SpendExpiringCodexResets
against a fake ChatGPT: card seen 20 minutes out with nothing used, then
the account used while the credits read returns 502, then read again.
Red on the old code ("a failed read leaves the account for 5h59m59s, past
the card running out"), green now. TestCodexResetsUntilUnread checks a
failed read is unread, a card with no expires_at is not, and the longer
background bound.
Run on mote (macOS 27):
- at e9c0c1824 (this change on
|
||
|
|
d3898ca8d3 |
provider: ChatGPT account calls go with Codex's headers, and saved accounts are listed once a day
Two follow-ups of 6e55914b6's audit of what magpie sends OpenAI for
idle saved Codex accounts (owl, Discord #general: three ChatGPT accounts
deactivated). Product call made by the session the owner delegated
product calls to; mimicking the official client is allowed for every
vendor but Claude Code. Identity, base_instructions and prompts are not
touched.
- Headers. GET /backend-api/wham/usage, /wham/rate-limit-reset-credits,
POST .../consume and POST auth.openai.com/oauth/token (live and saved
sign-ins, and the sign-in's code exchange) went with Go's
"Go-http-client/1.1" and no originator. They now carry Codex's
originator and User-Agent through codexClientHeaders, the part of
codexSign that /codex/models and /responses already used. No version
header on them: codex-rs sends it with model requests only
(login/src/auth/default_client.rs default_headers is originator +
User-Agent; backend-client/src/client.rs adds auth headers).
- Refresh body. codex-rs (main f32b6cfd and rust-v0.165.0,
login/src/oauth/client.rs refresh, auth/manager.rs
request_chatgpt_token_refresh) sends JSON client_id, grant_type,
refresh_token and refresh_reason, and no scope. magpie sent
scope "openid profile email" and no reason. It now sends codex-rs's
fields: proactive_expiry near expiry, unauthorized_recovery after a
401 (stale token), scheduled from the 8-day keep-alive, forced for an
import or a revoked-sign-in check. The code exchange's form already
matched exchange_code; only its headers changed.
- Model lists. The active Codex account's /codex/models fetch (hourly
KeepAccountsListed, FetchNew, Refresh) also fetched every switched-on
saved account's list each time. codexFetchSaved now asks one with no
list at once, and the others once a day, one per call, oldest asked
first; a failed ask is remembered so a deactivated account doesn't go
first every hour. The active account's list is unchanged.
Docs: providers-accounts.md says both.
Tests (codex_quiet_test.go), each red on the old behaviour (broken by
hand: wham/refresh/exchange headers removed, scope back, the age check
and the one-a-look cap removed, the keep-alive's reason dropped, and
separately the failed-ask memory skipped):
- TestCodexAccountCallsGoAsCodex counts the requests to a fake (usage 1,
credits 1, consume 1, token 2) and checks User-Agent/originator on
each and the refresh body's keys. Old: Go-http-client/1.1, "" and
scope in the body.
- TestCodexRefreshSaysWhy: scheduled, forced, unauthorized_recovery.
Old: no reason.
- TestSavedCodexListsOnceADay: 2 asks on the first look, 0 an hour on,
1 then 1 a day on, 0 again, and 0 within the day while failing. Old:
2 on every look; without the memory, a failing one asked again.
Run (mote-run, at origin/main
|
||
|
|
3b8bcc3654 |
provider: a ChatGPT token the backend calls expired before its exp is refreshed once and read again (willz on Discord, #2973)
willz on Discord (macOS, v0.1.1330): two saved Team Codex accounts showed
only "Unauthorized". /backend-api/wham/usage answered 401 "authentication
token has expired. Please try refreshing it." while each access token's
JWT exp was still ahead, so codexToken and savedLoginToken handed the
same token back on every read, and on every request, until the account
was signed in again. #2973 is the same 401 on the request path.
What changed
- SignInExpired (codex_expired.go) tells such a 401 by its words:
token_expired, "authentication token is/has expired", "Please try
refreshing it". It never matches refresh_token_expired, which is a
revoked sign-in. accountJSON now keeps the first 4KB of a refusal's
body on accountStatusError for it.
- Refreshes are keyed on the token that was turned away:
codexTokenRenewing(dir, stale) for Codex's own sign-in and
renewSavedLoginFrom(user, stale) for a saved one. Under the lock that
signing waits on, each reads its store afresh. If the store holds
another token by then (renewed by Codex or by another reply), that
token is used and no refresh is spent, so two replies for one token
spend one rotation. Otherwise they refresh. Codex's own sign-in is
written back through codexStore.write (temp and rename, every other
field kept). A saved one goes through writeLogins and only its own
row is changed; nothing is matched by name.
- The usage read (codexWindowsRenewing) refreshes once on such a 401 and
reads once more, never again. It is used by loginQuota (saved and
current accounts), codexSubscriptionUsage, and the reset spenders
through codexUserWindows (autoreset, expiring, stillExpiring), which
read the same windows with the same tokens.
- A refresh that is refused shows its own words on the card: a saved
account is marked lapsed, "add the account again to use it"
(savedRefreshFailed); Codex's own says "run codex login".
- A token that was refreshed and is still called expired says "sign in
to this account again" (errCodexStillExpired).
- A refresh that got no answer is shown as that, not as signed out.
- Request path: noteSignIn renews the account a request went with
(NoteExpiredSignIn, at most 20s, through Account.renew, which is set
on Codex's own account and each saved one). Nothing is marked. The
request fails over as a 401 did before, and the next one goes with
the new token.
- Docs: providers-accounts.md ("A token called expired") and
gateway-routing.md.
The request-path hook and its gateway tests (codex_refresh_401_test.go,
taken as written) are ggbdpq's patch on #2973. Here they rest on the
stale-keyed refresh. The patch's forced refresh skipped the fresh
keychain read, so it could spend a refresh token Codex had already
rotated.
Tests
- TestCodexUsageRenewsTokenCalledExpired: a saved and a current account,
both with an hour left, get 401 token_expired. Each is refreshed once,
read once more, and kept where it lives (auth.json in the sandbox
HOME, logins.json). A second read refreshes nothing.
- TestCodexUsageExpiredOnce: a refused refresh says to sign in again; a
token still called expired is read no third time.
- TestCodexUsageOther401NotRenewed, TestSignInExpiredWords,
TestNoteExpiredSignIn (two replies for one token make one refresh).
- ggbdpq's TestCodexExpired401RefreshesLogin and
TestCodexOther401DoesntRefresh.
Run at 482d6707a (this change) (rebased on
|
||
|
|
7dc5cd8f08 |
provider: Codex keeping its sign-in in the macOS keychain is read and written there (#2367, Dony2050)
Codex 0.162 with cli_auth_credentials_store = "keyring" or "auto" saves
its ChatGPT sign-in to the keychain and deletes auth.json. magpie read
only auth.json, so it hid the Codex provider and every saved account.
Adapted from Dony2050's fcebfc322 (fix/codex-macos-keychain). The changes
from that branch are below.
What Codex does (codex-rs at rust-v0.162.1: login/src/auth/storage.rs,
config/src/types.rs, features/src/lib.rs). The item is service "Codex
Auth", account "cli|" plus the first 16 hex digits of the SHA-256 of the
canonicalised CODEX_HOME. Its value is auth.json's JSON on one line.
keyring reads only the item. auto reads the item, and falls back to
auth.json when there is no item or the item can't be loaded. Saves follow
the same order. With [features] secret_auth_storage on (the default on
Windows), keyring and auto use Codex's encrypted storage instead.
internal/provider/codex_store.go is now the one reader and writer:
- A keychain interface. The real one runs `security` the way Claude Code's
item is read (keychainText, proc.CommandContext, 10s bound; errors carry
no argv or output). Tests get a fake (isolate, CodexKeychainForTest).
- readCodexLogin follows Codex's rules on macOS. keyring with no item is
signed out. keyring with a refused read is unknown (codexStoreError),
never signed out. With the encrypted storage, on Linux and on Windows,
keyring and ephemeral are unknown and auto is auth.json. A config.toml
that doesn't parse reads auth.json as before.
- Reads are kept 10s, a refusal 10 minutes, and only one `security` ask
runs at a time. Each read can be a Keychain prompt, and codexToken runs
on every request.
- A refresh writes the rotated tokens back where they came from, with
unknown fields kept, after re-reading the item.
- saveCodexLogin (switch, first sign-in) re-reads the store first. It
refuses when the store couldn't be read, when config.toml doesn't parse,
for ephemeral, and for a store magpie doesn't read. It never deletes
auth.json; Codex cleans that up itself.
- deleteCodexLogin (signing the last account out) removes the item, then
auth.json, as `codex logout` does.
- Routed through it: codexAccount, codexToken (it now takes the home dir),
liveLogin, CodexAPIKeySignedIn, codexLoginAuth, the usage card's
codexUntil, session identities, switchSavedLogin, addLogin, forgetLogin,
and agent's codexChatGPT/Source (provider.CodexSignIn).
- savedButSignedOut now says what was found (codexSignedOutWhy): nothing
in the item, an item macOS wouldn't give (allow it, or use file), or a
store magpie doesn't read here (use file). This replaces ed6e27f5f's
codexCredentialsStore and its single "magpie doesn't read the keychain"
text.
Changed from fcebfc322: secret_auth_storage is honoured (the branch would
read and write the wrong item); there is no second keychain package; reads
are cached and a denial backs off (the branch spawned `security` on every
read); auth.json is not deleted after every keychain write; auto falls back
to the file only when there is no item; the tests use an interface fake on
every OS instead of a darwin-only PATH fake; codexChatGPT keeps its
meaning; a malformed config.toml doesn't hide a file sign-in.
Run (in the wt-2367 worktree, sandbox HOMEs only, no real keychain or
`security` run, nothing under ~/.codex):
- gofmt -l: clean. go vet -tags nogui ./... for darwin, linux and windows:
clean.
- go test -p 1 -tags nogui ./internal/provider: ok (293s).
./internal/agent: ok (1291s). An earlier agent run hit the disk filling
up (ENOSPC from other sessions' builds); it was rerun with room.
./internal/gateway -run 'Codex|Login|Account': ok (261s).
- Broken by hand. The keychain never read (keychainItem false):
TestCodexSignedInInKeychain, TestCodexKeychainRefreshWritesItem,
TestCodexKeychainSwitch, TestCodexKeychainAskedSeldom,
TestCodexKeychainSignOut and TestSavedButSignedOut go red. saveCodexLogin
ignoring a refused read: TestCodexKeychainSwitch red ("switched over a
sign-in the keychain wouldn't give"). No cache:
TestCodexKeychainAskedSeldom red (20 asks for 20 reads). agent's
codexChatGPT reading auth.json only: TestCodexSignInInKeychain red.
- Not tried: an item Codex itself wrote. Codex writes it through
keyring-rs, and its ACL may trust only codex, so macOS may prompt the
first time magpie reads it, and Codex may prompt after magpie rewrites
it (`add-generic-password -U`). An unanswered prompt is killed at 10s
and reads as unknown. The reporter is asked to confirm on #2367, which
stays open.
Landing: this goes on top of ed6e27f5f (in this worktree as its
cherry-pick 66cdde294) and replaces that commit's message.
Co-authored-by: Dony2050 <88673296+Dony2050@users.noreply.github.com>
Full suite: SUITE_LINE
|
||
|
|
7b1fdf669e |
provider: the Mac's menu bar reads a Codex card again as soon as a reset is spent or the card is refreshed, not at its next tick (#2357, zkhCreator)
After a Codex reset the tray panel's card showed the windows started again and "Updated just now", while the menu bar's cells still showed the old figures. The menu bar (watchTrayUsage) re-reads the cards on its timer, every 3 minutes unless Settings says otherwise, or when OnSubscriptionUsage's hook says a whole read of the accounts landed. Two paths change what Quotas answers without that hook: a card read again on its own (RefreshUsage, the card's refresh button and the gateway's quotas refresh) and a Codex reset spent (useCodexReset, by hand, before one expires or when the week runs out), which drops the cached cards. The panel read the new card at once; the menu bar waited for its tick. toldUsage() fires the hook; the background read uses it as before, and RefreshUsage and useCodexReset now call it after they change the cache. After a reset the menu bar's read finds the cache empty and waits for the new reading (up to its 15 s), whose landing tells it once more; that second read hits the fresh cache, so nothing loops. Tested: TestRefreshOneCard and TestUseCodexReset now hold a hook and fail without the calls (broken by hand, both removed): quota_refresh_test.go:81: a card read again on its own didn't tell the menu bar codex_resets_test.go:229: a reset spent didn't tell the menu bar and pass with them. go test -tags nogui -p 1 ./internal/provider passes; -race -count=5 on TestRefreshOneCard, TestUseCodexReset and TestSubscriptionUsage* passes. gofmt -l clean; go vet (darwin nogui, GOOS=linux nogui, GOOS=windows) on internal/provider and go build ./internal/gui pass. Not tried in the real menu bar with a real Codex reset: no reset was spent. Whether the reporter refreshed the card by its own button, used a reset in magpie, or OpenAI reset every account (a read with no card refresh, which already told the menu bar) is asked on the issue. Full suite: SUITE_LINE |
||
|
|
4795f56469 |
provider, gui, cli: a Codex account's card says the last reset magpie used, when and why (foobra12 on Discord)
foobra12: "magpie会自动使用codex重置卡吗 我发现刚才好像不小心自动给我使用了
一张". Auto-use is off by default and spends only for accounts switched on
(the week used up with no other account to answer, or a reset ~30 min
before it expires), but a reset magpie spent was said only in the gateway's
log. A reset gone from the card read the same whether magpie used it, the
user did, or it ran out.
Each reset magpie spends is now kept in codex-resets-used.json (by account,
when, why: week / expiring / hand, windows started again; 90 days, 200 at
most, under a cross-process filelock, written with steady.WriteFile; a file
that doesn't parse is copied aside to .bad-<ts>, never read as empty). Only
a consume whose outcome is "reset" is kept. useCodexReset carries why:
AutoUseCodexReset passes week, SpendExpiringCodexResets expiring, and
UseCodexReset (Usage page, panel, CLI) hand.
loginReading, the choke point for LoginUsage and the Usage page, attaches
an account's last 5 uses to its reading (cached readings too, so a reading
kept from before a use still says it), and Quota/SubscriptionQuota carry
resetsUsed. The auto-use row on the Usage page's and the panel's card adds
a line "Last reset used: {when} · {why}" (zh 上次用卡:… · 自动,重置卡到期前),
every kept use in its title; an account in brief has it in its switch's
title. `magpie quota auto-reset <account>` lists them. en, zh, zh-TW, ja, de.
The default (off) and the expiry rule are unchanged: both are documented in
the switch's title and only reach accounts the user turned on.
Run:
- go test -tags nogui -count=10 -run TestResetUse ./internal/provider/
- break by hand: noteResetUsed call removed -> TestResetUsesKept red
("kept [], want [week hand expiring]"); loginReading attach removed ->
red ("the card's reading has []")
- node --test codex-resets-used.test.cjs: chromium+webkit, 1100 and 420,
en zh zh-TW ja de, the Usage page card, brief title, the panel card; 3
runs green; with the say.append removed, 5/5 red
- codex-auto-reset, routing-auto-reset, quota-curve, click-scroll,
tray-usages, i18n-keys, gui-ja, gui-de, gui-zh-tw: green.
old-webkit is red on "Safari 15.0 styles" at app.css .prefs
.val:has(> .side-effort), from
|
||
|
|
aef0327b61 |
gateway, provider: comments no longer say magpie spends Claude's usage resets (#1972)
AutoReset and ResetOutcome still named Claude's resets, which
|
||
|
|
b69b0e8100 |
usage: a GLM Coding Plan key's card on bigmodel.cn or Z.ai shows its reset cards, five-hour and weekly, counted from customer-package-reset/list (targetType=PERSONAL) as the vendor's usage page counts them: only those still available; a list that can't be read shows none, never 0. Read only, never spent from magpie (#1191)
The list is asked with the plan's key, bare in Authorization, at the host its term (subscription/list) is asked at, so open.bigmodel.cn and api.z.ai alike; a ZCode account on the built-in gets the same. The tooltip says "The plan's resets" for a person's own, "The team plan's" for a team's (ResetCredits.Team). Tested: the reporter's literal reply (ids and times filled in, same shape) in TestZhipuPersonalResets, TestPlanQuotas and TestZCodeAccounts, each failing with the change reverted; reset-each-title in Chromium and WebKit, en/zh/ja/de; a real Z.ai key through zhipuPersonalResets (1 five-hour, 1 weekly). Not tried: a real bigmodel.cn key. |
||
|
|
e8e97d163f | gui: a card's resets, hovered, list each one left and when it runs out, a line each, soonest first (#960, Magixyne) — the tooltip only said when the first runs out, the date the card already shows. ResetCredits.Each carries them: a Codex account's from its credits (available ones, listed only when they match the count; one that never runs out last), a GLM team's with each one's window. Codex lines are numbered ("Reset 2 runs out …"), a team's say five-hour or weekly; a plugin's, with no list, keep the one line. zh/ja/de added. reset-each-title (Usage page at 900 and 440px, the panel) passes in Chromium and WebKit, en/zh/ja/de, and fails without the fix; TestCodexResetsCounted and the team test check the order. i18n-keys, gui-ja, gui-de, codex-auto-reset, reset-reminder, routing-auto-reset, panel-usage pass; go test ./internal/provider/ ./internal/gui/ ./internal/tui/ and vet pass. | ||
|
|
9bf6d43527 |
claude: magpie no longer asks Anthropic for a Claude account's usage, and adding a Claude account warns of a ban (the user: 不要伪造任何的 Claude 请求,能否通过 claude cli 获取 / 我害怕被封; 添加账号时要像其他的 Subscription Provider 一样显示风险提示) — the usage was read by magpie itself calling Anthropic's /api/oauth/usage with the account's token, on a timer, for every saved account, and Claude's usage-limit resets (cedar_ember) were listed, spent and auto-spent the same way. Now the usage is what Claude Code's own /usage prints (claude -p /usage, a command Claude Code answers itself without asking a model), run only when Usage is opened or Refresh pressed (GUI, magpie quota, accounts, TUI), for the account Claude Code is signed in to, at most once in 30s; a saved account shows only what Claude Code reported while using it, or the last reading kept. The Claude resets, Auto-use and their settings are gone (Codex's stay). Session jsonl files hold no usage figures, so they aren't read. Starting a Claude sign-in or import (GUI and CLI) first says Anthropic may suspend or ban the account and that it is at the user's own risk. TestClaudeWindowsAsked, TestParseClaudeUsage, TestClaudeUsageRunsClaudeCode, claude-usage-asked.test.cjs and claude-risk.test.cjs fail without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass; routing-auto-reset, codex-auto-reset, quota-families, tray-usages, click-scroll, old-webkit, plugin-signin, usage-alert, usage-ledger pass.
|
||
|
|
a9ff84fd80 | accounts: a Claude account's usage-limit resets show on its card, and can be used, by hand or by themselves (StringKe on Discord: claude-code usage 里有 reset) — magpie read Claude usage without the resets. It now asks as Claude Code does (/api/oauth/usage?cedar_ember=1&skip_spend=1) and shows ↺ N resets · until … on the card and panel. "Use a reset" spends the grant Anthropic names next through POST /api/organizations/{org}/reset_rate_limits, as Claude Code's /limit-reset does, the organization read from /api/oauth/profile; Auto-use (off by default, per account) spends one only when the account's whole week is used up, every other candidate is resting and the grant clears seven_day, at most one a week. The routing page labels an automatic one. Checked against fake servers with the user's JSON, never against Anthropic. TestClaudeGrants, TestClaudeResetsOnCard, TestUseClaudeReset, TestAutoUseClaudeReset, TestClaudeAutoReset and claude-resets.test.cjs (Chromium, WebKit, en/zh) fail without the change; codex-auto-reset, routing-auto-reset, click-scroll, old-webkit pass. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass. | ||
|
|
3dc8f00f06 | providers: each account of a subscription holding several can go through its own proxy — the provider's, none, or its own address (Discord, gakki: 是否可以为不同的codex账号设置不用的代理,现在是同一个供应商下使用相同的代理) — the per-provider proxy (#237) was one for all of Codex's signed-in accounts. A subscription's entry in providers.json now keeps accountProxies, by the account's name in lower case, each checked by settings.CheckProxy on save (ftp:// refused), addresses trimmed, accounts following the provider's proxy left out. Provider.ProxyChoice picks an account's own proxy, else the provider's, else the global one, so everything that already went through Provider.Via follows the account: gateway turns and fallback across accounts, usage and quota, token refresh, Codex's warm-up, reset and saved accounts' model lists, Claude's warm-up and the *_PROXY of Claude Code runs (ViaLogin / ProxyOfLogin), and Codex's own sign-in relayed as it came (ViaSignedIn). Extra accounts of Copilot, ZCode, Kiro and the like, made afresh without the provider's settings, now read them from providers.json, so they honour the provider's proxy too. A save without accountProxies keeps them; {} clears them. The provider editor, for a subscription with two or more accounts, lists each under the Proxy row: Provider's proxy | Direct | Custom, the address field's room kept so a pick moves nothing; Custom with no address is refused before anything is posted, its field focused without scrolling. en and zh together; no border stripes. Tested with internal/gateway/account_proxy_test.go in a sandbox HOME against fake proxies and a fake ChatGPT backend: three Codex accounts (own proxy, direct, following the provider) each reach the backend their own way in one turn and for usage; clearing an account's proxy sends it through the provider's, clearing the provider's through the global one, direct staying direct; ftp:// refused; TestClaudeAccountProxyEnv covers each Claude account's HTTPS_PROXY. Both fail with the per-account lookup off. account-proxy.test.cjs, Chromium and WebKit, en and zh (new), provider-proxy, click-scroll and old-webkit pass. go vet ./internal/..., go build -tags nogui (and GOOS=linux, GOOS=windows) and go test -tags nogui ./... pass. Not tried against a real proxy, real accounts or the real Wails window; Grok's per-account usage and Kiro's usage on a key still use the provider's proxy. | ||
|
|
8117d6f4a9 |
zcode: a seat on a team's GLM Coding Plan (团队套餐) is signed in, routed and metered as ZCode does it, on BigModel (智谱) as well as Z.ai, and a Zhipu key on a team plan shows its 5-hour and weekly windows and resets (#236 EZN7L2C3: a BigModel team GLM Coding Plan, the sign-in refused it and the usage was never read) — magpie's ZCode sign-in only went to Z.ai and only looked for the account's own coding-plan key, so a member of a team's plan, whose seat lives in a team project, was refused, and a key on a team plan read nothing from /api/monitor/usage/quota/limit. Read from ZCode.app 3.14.3 (host/index.js and config/provider/zcode-builtin.json): the team rules account:{zai|bigmodel}-team-coding-plan use the individual plans' base URLs with no extra inference headers; getCustomerInfo lists the projects, projectType "2" being a team's (isBigModelTeamCodingPlanProject); fetchTeamCodingPlanEntitlement asks /api/biz/team/subscribe/product/querySubscribeDetail (EFFECTIVE + memberGrantStatus VALID usable, UNASSIGNED no seat, EXPIRED run out); ensureBigModelTeamPlanProjectApiKeyWithStatus / copyBigModelTeamPlanProjectApiKeySecret find or create "zcode-team-api-key" (keyType 2) in the team project and copy its secret; createBigModelBizHeaders sends the access token bare in Authorization with bigmodel-organization / bigmodel-project; resolveAccountTeamPlanRuntimeApiKey takes the stored oauth:{family}:access_token (skipping BigModel's when it equals zcodejwttoken); buildQuotaLimitUrl adds type=2 and createBigModelUsageHeaders sends the key with the org/project headers; ZCode keeps the chosen team in ~/.zcode/v2/setting.json providerFamilyConnectionSelections (legacy modelProviderFamilySelectedKeys "team-plan:builtin:…", migrateLegacyAccountConnectionSettings); pollPendingOAuth/startOAuthWithPolling init with {provider:"zai"|"bigmodel"}, BigModel's redirect param being redirect, its token the poll's bigmodel.access_token. Now: the sign-in first asks where the account is — Z.ai or BigModel (智谱) (POST /api/signin takes a site, StartSignInAt, "zcode:bigmodel" too) — and on its site tries the account's own plan, then a team project with a usable seat (a new zcode_team.go: zcodeTeamSignIn keeps the team key, org, project and the biz token, the plan named by its product, "GLM Coding Team" otherwise), then the Start Plan; a team seat not yet granted or a team plan expired is refused saying so ("…has no seat on it yet — ask the team's admin…"), and an account with none of them names both plans and the site's subscribe page. ZCode's own team login is read from its credentials and setting.json (zcodeOwnTeam), its key minted lazily and kept (zcodeTeamKeyOf, retried after a minute, "sign in to ZCode again" when refused). Team requests go to the family's Anthropic base signed with the team key, no ZCode headers, never the Start Plan. Team usage asks bigmodel.cn (or api.z.ai) /api/monitor/usage/quota/limit?type=2 with the key and Authorization, Bigmodel-Organization, Bigmodel-Project, Set-Language, Accept-Language: CREDIT_LIMIT windows, unit 3 "5 hours" and unit 6 weekly, "current / total" when there is no remaining; /api/biz/customer-package-reset/list?targetType=TEAM gives the resets, fiveHourResets and weekResets counted where available is true, the soonest expireTime as until; the plan's end from querySubscribeDetail, Renew off. ResetCredits gains byWindow/fiveHour/weekly and Words(), "2 five-hour resets · 1 weekly reset" in the CLI, TUI and GUI (en and zh), with no "Use a reset" button for them since they are spent on the vendor's page. The Zhipu GLM key provider (planquota.go) falls back to the team query when the personal one fails or has no windows, adding the team headers when a ZCode team login holds that key. Personal accounts, Coding Plan and Start Plan, are routed, signed and metered as before. Tested with a new internal/provider/zcode_team_test.go against a fake bigmodel.cn/Z.ai in a sandbox HOME, no real tokens: a BigModel team sign-in through StartSignIn("zcode:bigmodel") is added (redirect param, plan "GLM Coding Team Pro", key made with keyType 2, org/project kept), its requests at the BigModel base signed with the team key and no ZCode headers, usage 5 hours 42% "420 / 1000" with a 5h span and weekly 10%, the quota headers sent, resets 2 five-hour and 1 weekly until 2026-10-05, plan until 2026-12-31; an unassigned seat is refused with no key made; ZCode's own team login from credentials + setting.json is found and metered while an individual plan stays as it was; the key provider's team fallback. TestPlanQuotas gains the type=2 case; the zcode Start Plan and account tests pass. A new internal/gui/tests/zcode-site.test.cjs, Chromium and WebKit, en and zh: starting ZCode's sign-in asks the site and posts nothing, BigModel posts {agent:"zcode",site:"bigmodel"} and keeps it, and the by-window resets read in both languages; signin-callback, click-scroll and login-import pass. go vet ./internal/..., go build -tags nogui (and GOOS=linux, GOOS=windows) and go test -tags nogui ./... pass (TestUserPath timed out under load and passes alone). Not tried against a real account: BigModel's OAuth sign-in and poll shape, the Set-Language values, customer-package-reset's field formats, querySubscribeDetail on Z.ai, type=2 for a pasted key with no org/project, and the time formats are from ZCode's code, not seen on the wire; not tried in the real Wails window.
|
||
|
|
125da38943 | providers: each provider, a signed-in account like Codex's among them, goes through its own proxy — the one in Settings, none, or its own address (#237 xosi: 目前似乎是全局设置代理的,codex和国模供应商无法单独区分设置代理) — magpie had one proxy, Settings' (or the environment's, or the system's), for every request it made, so Codex, which needs a proxy from China, and a vendor at home, which is slower or refused through one, couldn't both be right. A provider now has a proxy, "" (following the global one, as before and the default), "direct" (none, whatever Settings says) or an http://, https:// or socks5:// address (host:port meaning http), kept as proxy in providers.json only when set, and for an account provider in its picks entry beside its models. It is checked on save by the same rule Settings' proxy is (settings.CheckProxy, now shared), so ftp:// and the like are refused. netproxy.With puts a provider's choice on a request's context and netproxy.Func honours it; netproxy.Dispatch sends such a request through a clone of the transport kept for that proxy alone (at most 32, cleared past that), since a transport shares an HTTP/2 connection by host whatever proxy dialled it; loopback is never proxied. The gateway's client and http.DefaultClient go through Dispatch, and every request made on a provider's behalf carries its choice: the gateway's turns (attempt, forward, draw, decide, the Codex backend), and the model lists, balances, plan and subscription usage, tests, sign-in, Codex's warm-up and reset, while the Claude subscription's and warm-up's CLI runs get the account's proxy in their *_PROXY (netproxy.EnvWith). The provider editor, a key provider's and a signed-in account's alike, has a Proxy row after Fallback: Global proxy | Direct | Custom (全局代理 | 直连 | 自定义), the address field beside the options only for Custom, its room kept otherwise so a pick never changes the centred dialog's height and moves nothing, and a line under it saying what the pick does; Save posts proxy ("" , "direct" or the trimmed address), a save without it keeps the old one, and Custom with no address is refused before anything is posted ("Proxy: type its address, like http://127.0.0.1:7890"). No border stripes; en and zh strings together. Tested with a new internal/gateway/proxy_test.go in a sandbox HOME: with a global proxy set, provider A's turns and model list go through its own fake proxy, B's (direct) straight to the vendor, C's (following) through the global one, none through another, and A set back to following goes through the global one; ftp:// is refused (fails with With neutered). netproxy_test.go's TestWith covers Func, Dispatch's per-proxy transports and EnvWith. A new internal/gui/tests/provider-proxy.test.cjs in Chromium and WebKit, en and zh: a key provider opens on Global proxy with no address, Custom unfilled is refused and nothing posted, a padded socks5 address saved trimmed, Direct saved as "direct" and Global as ""; Codex's account opens on Custom with its address and saves Direct with its models; every pick leaves the option within 1px; no left border. go build -tags nogui (and GOOS=linux, GOOS=windows), go test -tags nogui ./..., provider-proxy, click-scroll, old-webkit, balance-fix and add-sheet pass (click-scroll's WebKit case failed once alongside the others and passes alone, twice). Not tried against a real proxy or the real Wails window. | ||
|
|
29c27c65f2 | routing: an account out of quota rests until it says it's back, not an hour at a time (关于路由组优先级高的模型异常的展示文案 #147) — ChatGPT's usage-limit refusal reaches the failover put in words, its resets_at only as the Retry-After magpie made of it, and a Retry-After is trusted for an hour at most, so a Plus account out until 21:34 read "59 分钟后恢复" and was tried, refused and benched again each hour; the reset now goes on beside the error for the rest to take as the vendor's own, the window it filled renews next, a bare Retry-After alone keeps the hour, a rate limit and a failure keep their short rests, and a Codex reset spent in magpie brings the account back at once. The Routing page says when as well as how long: "quota used up · back at 10:29 PM · in 3 h 41 min" (额度用尽 · 22:29 恢复 · 还有 3 小时 41 分钟) | ||
|
|
9946d4cc85 | usage: a Codex reset used is the one that runs out first, and its button says so (hover 的时候详细说明一下,不然用户不敢点,怕用掉了保质期最长的那个) — magpie named no credit when it spent one, leaving the vendor to choose; now it reads the account's credits and names the one to go first (credit_id, as Codex's own client does), one that never runs out last, and spends none when it can't tell which that is. The button's tooltip says it uses the one running out first, and when, and that it asks first; the confirmation and magpie quota reset say which too | ||
|
|
502246c563 | usage: a Codex account's rate-limit resets are on its card, so they don't go unused (可能把 resets card 在里边反应出来么?免得我们忘了用) — wham/usage's rate_limit_reset_credits count, and from /wham/rate-limit-reset-credits when the first of those left runs out, show as "↺ 2 resets · until Sat 22:30" under a hairline on the tray's Usage card, under the account's windows in the window's Usage view, and in magpie quota / accounts and the TUI (nothing when there are none, no date when none expire); "Use one…" asks first — which account, that its windows start again at once, that it can't be undone, and that there is nothing to start again when no window has been used — then spends one with a fresh redeem_request_id on that account (POST /api/usage/codex-reset, or magpie quota reset [<account>] [--yes]), says what came of it in words and reads the usage again; the account signed in now is found from Codex's own auth.json, not only the list magpie keeps. panel: a section's account count is a quiet rounded pill by its name, not a bare 2 at the far end (那个 2 是没有仔细打磨), the "N accounts" kept as its tooltip |