Commit Graph
11 Commits
Author SHA1 Message Date
yetone e2aaf21f73 gui: a custom provider's Balance URL is asked above its balance token
A relay's user wanting their balance opened the editor and found
"Account balance" asking for a new-api System Access Token or a sub2api
JWT and user id, while the setting that worked (Balance URL
https://app.yylx.io/v1/usage, token left empty) sat at the foot of the
form under More endpoints (小鱼 of yylx.io, WeChat, 11-05).

The Balance URL and Balance field now sit right above Account balance in
Advanced (balSlot), and Advanced opens when a Balance URL is saved. The
token's hint says first to leave it empty, that most relays tell a key's
balance at the Balance URL above (sub2api's …/v1/usage, new-api's
…/api/usage/token), and only then what the token is for. zh, zh-TW, ja
and de have it. In Advanced's narrower column the method picker and URL
wrap, so the URL keeps at least 120px at 420px.

Run (mote, Playwright 1.62.0):
- balance-url-first (new), balance-fix, balance-method and the other
  balance-* files: 186/186 in Chromium and WebKit, at 900 and 420px,
  en/zh/zh-TW/ja/de.
- The whole GUI suite, cut short after 733 tests (it ran for hours
  beside other sessions): red only in account-eye chromium en/ja (#5052)
  and account-weight webkit ja 390 (#4644), both open and in files this
  change doesn't reach.
- i18n-keys: "a plugin's words are its own" red, the same on main
  (#5327).

TestCoreScriptBudget: the hint took the core 494 bytes over its budget;
five comments in the provider editor were cut (573 bytes), so it is 79
under, with no raise.
- go test ./internal/provider ./internal/gui ./internal/cli ./internal/tui
  at the rebased head: ok but internal/gui's TestMainWindowCorners on
  mote's macOS 27 (#3949, open) and the budget before the cut.

Broken by hand: balance-url-first on the old app.js fails at "a saved
Balance URL opens Advanced" (chromium).

Filed: #5336, Advanced is 46px too wide at 420px on main (the Rests
tick's label); the new test checks only the balance rows for it.

Not tried: the real app on Linux (WebKitGTK); no motion or new API here.
2026-11-05 14:19:28 +08:00
yetone e189542dfb providers: a new-api relay's user id is its own field beside the balance token (zxc56823)
zxc56823 (Discord #general) added a new-api site with a key and an access
token. The balance card said 请在供应商的「请求头」中添加 New-Api-User = 你的
用户 ID, so they typed 272298 as a header's *name* and left its value
empty. The editor drops a header with no value, so New-Api-User never
reached /api/user/self. new-api v0.9's authHelper still answered 401
"未提供 New-Api-User", and the balance stayed unread. CC Switch asks for
"User ID" in a field of its own and sends it as New-Api-User beside
"Authorization: Bearer <access token>". magpie sends the same request
apart from Bearer, which new-api strips. The id can't be worked out from
the token or the key, so the field can't be zero-config.

- Provider editor, Account balance: when the Balance URL is
  /api/user/self, a "User ID" field sits beside the token, with the line
  that says where the id is shown. The field keeps the id in the
  New-Api-User header row and redraws Headers. It keeps its focus while
  typing, and turns amber when what's typed isn't digits.
- A header named by digits alone with an empty value is the user id.
  headersOf in app.js and userIDHeader in provider.go (cleanHeaders on
  save, and the balance read for an unsaved check) both send it as
  New-Api-User=<digits>. A New-Api-User with a value of its own wins, and
  the digits header is dropped. So the reporter's saved form now works
  without being retyped.
- The 401's hint and the card's text name the User ID field, not Headers
  (en, zh, zh-TW, ja, de).
- The core script budget is unchanged. The ~1.6KB is paid for by four
  comments cut in app.js.

Run at this tree (on origin/main 3d7b1233d, on mote):
- go test -count=1 -timeout 45m ./internal/provider/ ./internal/gui/:
  provider ok. In gui, the one red is TestMainWindowCorners/macOS_26_SDK,
  which is red on mote's macOS 27 (#3949). Nothing here touches AppKit.
  Before the comment cuts, TestCoreScriptBudget was red at +2,373 bytes.
  Now app.js is 9 bytes under its base.
- GOOS=windows go vet ./... ok. gofmt -l is clean. For Linux vet,
  go vet -tags gtk3 ./... in WSL magpie-desktop was ok at the previous
  base 6b8134430; the change is the same.
- GUI, both engines: balance-fix (en, zh, zh-TW, ja, de at 1100 and
  420px), i18n-keys, header-session-hint, balance-method and
  balance-field-default: 178 pass, 0 fail. Earlier, at 6b8134430, the 45
  GUI files that draw the provider editor, its headers, its balance or
  Advanced ran: 1010 tests, 992 pass. The 18 reds are in four files
  (editor-advanced-align, provider-typed, vertex-editor, zhipu-team), and
  the same 18 are red on a clean origin/main 3d7b1233d. Filed as #4615,
  #4673, #4720/#4721 and #4728. The macOS reds are noted on #4673.

Broken by hand:
- Both userIDHeader calls taken out: TestNewAPIUserIDTypedAsHeaderName
  goes red with the fake new-api's 401 未提供 New-Api-User.
- headersOf's digits mapping taken out: balance-fix's first test and the
  User ID tests go red.

Not tried: a real new-api site and account (the fake serves v0.9's
authHelper and quota/500000 from new-api's source). Also not tried:
Linux WebKitGTK and the Windows app.
2026-11-03 13:00:55 +08:00
yetone b328a7790b gui tests: balance-fix types the account token into its own box, not the proxy's password (#4683)
9c8636a35 (#3382) gave the Proxy field a login, so a new custom
provider's Advanced fold has a "Password (optional)" box before the
account balance token. The test took the second password input as the
token, typed it into the proxy's password, and the Balance URL hint
never came: every "Sub2API balance shortcut" case and "a token on a new
custom provider with no Balance URL" were red at main in both engines,
not only under load or on Linux (#4683, #4682). The token box is now
found by its own placeholder, in each language. The app is unchanged.

Run on mote: balance-fix.test.cjs, chromium + webkit, every language
and width: 100/100 ok at this head; at main 5ec237568 the same file was
red in every Sub2API case and the /api/user/self case.
Found by a debug run listing the editor's password inputs.
Not tried: other tests that pick a password input by position
(grepped: only balance-fix does in the editor).
2026-11-03 05:11:59 +08:00
yetone b0174e7615 usage: a ChatGPT card says why its allowance can't be read, and a ChatGPT API account says where it shows
hmy on Discord: five ChatGPT accounts each said only "暂时无法获取额度"
(Allowance unavailable). danzi002 on Discord: accounts added through the
API never show usage, ones added as ChatGPT do.

What changed:
- Codex's usage read (codexWindows) now words its failure
  (codex_usage_words.go): a Cloudflare challenge names the proxy/VPN
  address as the usual cause; any other HTTP answer names its status and
  what ChatGPT said; a network error says chatgpt.com couldn't be
  reached; a reply magpie can't decode says so. The error still unwraps
  to accountStatusError, so expiry and passing logic is unchanged.
- A ChatGPT API account (chatgpt-api) was read as a Codex account: a
  saved one said "chatgpt-api accounts can't be used side by side", the
  one in use read Codex's own sign-in ("Codex is signed out", or another
  account's allowance under its name). OpenAI's API tells no plan usage,
  so its row now says so, names chatgpt.com/settings/usage (SeeAt) and
  says the same account added as ChatGPT shows it here.
- GUI quotaError translates each of these (en, zh, zh-TW, ja, de), and
  "not read yet" (errNotAsked) gets its own words. The generic fallback
  now reads "Allowance unavailable — hover for why"; the row's tooltip
  has always been the raw error. Comments in app.js were shortened to
  stay under TestCoreScriptBudget, which is not raised.
- docs/subsystems/providers-accounts.md describes the words.

Endpoint: the real wham/usage read of the owner's accounts in a sandbox
HOME copy (read-only, ~/.codex untouched) answered 200 and parsed, so
the endpoint itself is not broken; the "error decoding response body"
work is another session's and is not touched here.

Run (on mote; provider and gui again at the pushed head, rebased on
18c69aa46; 2251ca1ce, new under it, changed app.js and the budget):
- gofmt -l clean; GOOS=linux -tags nogui and GOOS=windows go vet of
  provider and gui clean.
- go test -timeout 45m ./...: ok except TestEveryRouteHasACommandOrIsNamed
  (#4826, red on origin/main 2251ca1ce too), TestMainWindowCorners (#3949,
  red on main too) and TestCodexPoolSaysTheClientsVersion (#4807, red in
  the full run, ok alone here and on main). At the pushed head:
  provider ok, gui ok but TestMainWindowCorners (#3949), core budget ok.
- GUI: chatgpt-usage-why.test.cjs (new; chromium and webkit, 560 and
  390, en/zh/zh-TW/ja/de, each row's words, its status code, the raw
  tooltip, no overflow) and the six tests whose generic line changed.
  The whole GUI suite was not run before this push: another session's
  full suite held mote. The change adds no API call and no layout, only
  words; the whole suite runs after the push and its reds get issues.

Broken by hand:
- codexWindows returning the bare err: TestCodexUsageSaysWhy and
  TestCodexLoginUsageSaysCloudflare red.
- the GUI ChatGPT patterns removed: chatgpt-usage-why 0/2.
- the chatgpt-api branch off: TestChatGPTAPIUsageSaysWhere red, the
  row read "Codex is signed out; run codex login".

Not tried: a real Cloudflare challenge (the fixture is the start of its
page as Cloudflare serves it, not hmy's bytes, which magpie hasn't got); a real ChatGPT API account (none signed in here); making a
ChatGPT API account's usage readable, since its token is for
api.openai.com and OpenAI shows plan usage only on chatgpt.com.
2026-11-02 20:04:32 +08:00
yetone ce8b67de37 gui tests: a page's first load gets a minute, not a click's 5s (#4470)
claude-switch-only set page.setDefaultTimeout(5000) and then called
page.goto with no timeout of its own, so Playwright held the first load
of app.js, i18n.js and the plugins to the 5s bar meant for clicks. On a
busy box (a whole-suite run at load 130-160) that load took longer and
goto timed out. The same pattern is in 988 GUI test files (1174 pages):
every one of them now also sets setDefaultNavigationTimeout(60000) on
the same page, right after its default, so goto, reload and waitForURL
wait on the load itself with room, while clicks and waits keep their
short bar. group-from-model-add's own 20s navigation bar is raised to the
same minute. claude-switch-only also gives its first provider row (drawn
from the page's first reads) a minute before clicking it.

nav-timeout.test.cjs (no browser) reads every GUI test file and names
each page given a default under a minute without a navigation timeout of
at least a minute, so a new file can't bring the pattern back.

What was run (WSL magpie-desktop, Playwright 1.62.0, load 70-260 from
other sessions):
- node --check on every file in internal/gui/tests: all parse.
- nav-timeout.test.cjs against origin/main's test files: red (names the
  1174 pages); against this tree: its only reds were my own probe copies
  of the old files, since removed.
- By hand: claude-switch-only with app.js served 7s late (a busy box's
  first load), --test-name-pattern "1100 en": origin/main's file 4 of 4
  red with "page.goto: Timeout 5000ms exceeded"; this file 4 of 4 green.
- claude-switch-only.test.cjs, both engines, en/zh/ja/de, 1100 and 420:
  32 of 32. group-from-model-add, usage-access-key-card and i18n-keys:
  green. agent-plugin-agents: Chromium green; WebKit's de 420 subtest red
  on a 5s waitForFunction at line 115 (a wait after load, not the
  navigation), at load ~230.

Not tried: the whole GUI suite (about 1000 files; the change is one
mechanical line per page), Windows or mote (mote's browsers, #4125).
2026-10-31 02:09:18 +08:00
yetone 0cad76cd99 gui: the provider editor folds rarely used fields under Advanced
The owner: "Provider表单太复杂了…有一些可以折叠在高级里面". Headers,
proxy, concurrency and RPM limits, prices, context and output windows,
native compaction and fallback now sit in an "Advanced" fold beside the
key and models. It opens on its own when any of them is set, keeps the
state it was left in across the editor's redraws (keyed by the provider
being edited), and a Save refused on a field inside it opens it and
focuses that field. A signed-in account's editor folds the same.
Strings in zh, zh-TW, ja and de.

Motion ("整个弹窗高度的改变也应该是丝滑的动画"): the fold grows and
shrinks on one spring-like curve, its rows fading in, its arrow turning,
and the dialog's height follows on the same curve both ways; clicked
again mid-way it turns back from where it is. Reduce motion: at once.

Every dialog holds its place: the element last pressed or focused stays
where it was while the dialog grows or shrinks (a relative top plus a
max-height cap), so the button under the pointer doesn't run away. Where
there is no room above, only a pressed button below the fields shortens
them through the cap; nothing a click does scrolls the fields
(models-fold, names-fold). An element mid-scale (a Copy button's pop) is
measured by its parent (key-copy). The names list holds its height while
drawNames rebuilds it, so WebKit doesn't clamp the editor's scroll mid
rebuild (provider-detect, "Ask on one API moved" 64→190).

Tests: provider-advanced-fold (new, 5 languages × 2 engines, 420px);
about 21 editor tests open Advanced before reaching a folded field;
balance-method and plugin-move find the fold by its class; detect-draft
allows 0.5px. appScriptBudget 1,250,000 and coreScriptBudget 1,426,000
(1,232,466 and 1,405,937 with this).

Run: go test ./internal/gui/ ok. Every GUI file (771) in a full run,
4 at a time; its reds, rerun alone at this head, both engines:
key-copy 8/0, models-fold 4/0, names-fold 8/0, balance-method 42/0,
provider-detect 4/0, plus provider-remove 16/0, plugin-move 8/0,
provider-detect-draft 20/0, provider-advanced-fold 50/0,
provider-add-models 4/0. Red on origin/main as well, filed: #2435
(agent-connect-no-models, fixed in cf21b71ff), #2439 (fonts), #2443
(key-balance-card), #2228 (quota-count-wrap, quota-name-translated),
#1905 (routing-wb-restricted), #2448 (s3-sync); mobile-web and
library-workbuddy-trust red only under load, noted on #1544;
readable-focus and text-size fixed on main in 1a16fc0b5 and d3ca90afc.
2026-10-16 04:08:02 +08:00
ggbdpq 7a6b101045 provider, gui: a login token beside sub2api's /v1/usage is told the panel's account query, not sent to the key's
What changed:
- balance.go: the guard that never sends a balance token to new-api's
  /api/usage/token (c9e47f043) now covers sub2api's /v1/usage too, and
  says to set <site>/api/v1/user/profile (Balance field $data.balance)
  or remove the token, as the new-api branch says its /api/user/self.
- gui: the editor's token warning (balanceFix) and the refusal wording
  (balanceError) each name sub2api's /v1/usage beside the token; two new
  strings in zh, zh-TW, ja and de.

Run:
- TestSub2APIKeyUsageWithLoginToken (new): a JWT beside /v1/usage is
  never sent there and the panel's account query is named; the key alone
  still asks. On upstream/main 2c18c697 it fails asked=true with the
  panel's raw 401 (the token went out as Authorization).
- TestKeyUsageWithAccessToken, TestBalanceKeyAsBearer and the balance
  tests unchanged; go test -tags nogui -p 2 -count=1
  ./internal/provider ok (71.9s). i18n-keys.test.cjs 3/3.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows on
  internal/provider and internal/gui; go build darwin, GOOS=linux
  -tags nogui, GOOS=windows.

Generated-by: GLM-5.3-Flash (ZCode)

Review (yetone, #2217): read line by line and kept, with one change in
the GUI. The editor's warning for a token beside /v1/usage offered both
/api/user/self and /api/v1/user/profile, but /v1/usage is sub2api's, so
only the panel's profile is offered now, and a saved "$remaining" (the
key query's field) gives way to $data.balance as the button sets the
URL. balance-fix.test.cjs gets a test for it (chromium and webkit, 440
wide): it is red on the patch's app.js ("only sub2api's account query
is offered") and on main's.

Run at the reviewed head, on origin/main 2a99e7a42, and
again on 91b9065a5 for vet, gui, provider, tui, gateway, agent and
the tests named here:
- TestSub2APIKeyUsageWithLoginToken is red with main's balance.go (ok
  true, the panel's 401 "invalid API key", asked true) and green with
  the patch.
- node --test balance-fix.test.cjs i18n-keys.test.cjs: 103 pass, 0 fail
  (chromium + webkit; the file's matrix is en, zh, ja, de at 900 and
  440; zh-TW strings are checked by i18n-keys only).
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows ./...;
  go build for the three; go test -tags nogui -count=1 -p 4 ./... at a machine load of 100-150:
  50 packages ok; internal/agent and internal/gateway ran past the 10m
  default under that load and pass with -timeout 40m (674s, 798s);
  internal/gui's TestSetAnswersWhileDevinAndProvidersHang failed once
  (a state took 10.4s; open as #1375) and the package passes rerun.
Not tried: a real sub2api panel.
2026-10-15 01:56:35 +08:00
如是 52ad2d9845 gui: a ZCode account with nothing left to spend says so, and says what to do (#1245)
A ZCode account whose free Start Plan (体验套餐) has run out and which has
no GLM Coding Plan of its own reads as "Allowance unavailable" on the
Usage page's card, which is the words for a reading that failed — the
account's real state is that it has nothing to spend. The built-in already
names it (zcodeStartQuota, internal/provider/zcode_start.go: "this account
has no GLM Coding Plan, and ZCode's Start Plan has ended or was never
started") and the plugin's usage error is that same string byte for byte
(NO_START, magpie-community/plugins packages/zcode); quotaError matched
neither, so both fell through to the fallback.

The card now says it, and says the action on the card itself: the
"subscribe at …" wording is in the sign-in errors (zcodeSignedIn /
signedIn), which never reach this card, so there was nothing to hover for
(yetone on #1001). "has ended" would also be wrong for an account that
never started one, hence "no free Start Plan".

The match is anchored on the whole card sentence, so the sign-in errors —
which name the address themselves — and the sibling "…Start Plan could not
be read: <err>" (a reading that failed) are both left alone.

zh, zh-TW, ja and de get the new string. balance-fix.test.cjs gains both
card errors, the sign-in error and the could-not-be-read one, asserting
the first two get the card's words and the last two do not; the new string
joins its list of those needing a Chinese. Red/green: the two card
assertions fail with the mapping taken out of app.js, and the
could-not-be-read and sign-in ones fail if the match is loosened to
"Start Plan has ended" anywhere in the string. 108 tests pass across
balance-fix, gui-de, gui-ja, gui-zh-tw and i18n-keys.
2026-10-08 15:39:50 +08:00
mslxl cd8d64a9fc feat(gui): add Sub2API balance autofill on account balance hint (#1059)
* feat(gui): add Sub2API balance autofill

Offer Sub2API alongside NewAPI in the custom provider's balance-token hint.
Fill /api/v1/user/profile and $data.balance, and describe both endpoints in
the existing translations.

Verified: native macOS build; 10 existing browser and translation checks;
Sub2API flows in Chromium and WebKit, four languages, at 900px and 440px;
live web assets. The original code fails the temporary two-shortcut check.
Full Go suite, cross-platform builds and live-account validation not run.

* fix(gui): preserve custom balance fields in account shortcuts

Use the same replacement rule for both account balance shortcuts, keeping
user-written expressions. Describe both endpoints in the key-only URL
warning and restore the rationale for flagging missing and key-only URLs.

Add browser cases for both URL states, new providers, saved form values,
narrow layouts and all four languages.

Validation: 111/111 related checks across Chromium and WebKit; native macOS
build; 38/38 after baseline failure checks. New button cases fail against
d9b2cdc5 app.js, and custom-field checks fail against cf3f3d9d app.js.
Full Go suite, cross-platform builds and live-account validation not run.
2026-10-07 19:11:01 +08:00
Fanbuz 5ebb053ce1 fix: 统一额度相关的中英文界面文案 (#493) 2026-10-02 09:37:00 +08:00
yetone c9e47f043e balance: a custom provider's balance token can't be left where it is never asked, and new-api's refusals say what to do (TJHHHH: OK了,希望有防呆机制 — a new-api relay's System Access Token pasted beside a Balance URL of /api/usage/token, no New-Api-User header, and the Usage page never showed a balance) — new-api has two balance queries: /api/usage/token tells a key what is left on it and takes the key alone, and /api/user/self tells the account's quota to the access token with the user's id in New-Api-User. A token beside the first could only ever be turned down, and the second without the header answered {"success":false,"message":"无权进行此操作,未提供 New-Api-User"}, which a 401 showed as JSON and a 200 read as a field missing. The editor now says so under the token as soon as it is there: beside …/api/usage/token, or with no Balance URL at all (the token field is now offered on every custom provider, not only one with a URL saved), a warning with one button, Use https://<site>/api/user/self, which sets the URL, sets the Balance field to $data.quota / 500000 when it was empty or named /api/usage/token's fields, and opens More endpoints to show it; once the URL is /api/user/self and no New-Api-User header has a value, it asks for New-Api-User = your user ID (shown in the site's personal settings) until one is typed. The URL is not switched behind the user's back: what the editor shows is what is asked, and the field typed for /api/usage/token's reply wouldn't read /api/user/self's anyway. Behind it, Balance never sends a token to /api/usage/token and says what to set instead; a reply of success:false with a message, at a 401 or a 200, is that message as the error, with the header to add put in front when it is about New-Api-User (not provided, format error or mismatch, in new-api's Chinese or English); and /api/user/self with an empty field reads the quota, $1 to 500000. The Balance field has a Check balance button (POST /api/provider/balance) that asks as the form has it, before a Save, the saved provider with the form's URL, field, headers and token; it and the Usage page's card say either fix plainly, the relay's own words on hover. A JWT beside new-api's URL is not warned about: new-api's own dashboard sign-ins are JWTs now, so a token's shape can't tell new-api from a sub2api panel. Tested with new TestKeyUsageWithAccessToken (never asked, the fix said, the key alone still asks), TestUserSelfDefaultField and TestNewAPIUserRefusal (401 and 200, Chinese and English, the mismatch, and an unrelated refusal left as it came), which all fail on main; and a new internal/gui/tests/balance-fix.test.cjs in Chromium and WebKit (the warning on the saved setup, the click, the header hint going once typed, Check balance with and without the header and what it posted, Save, the Usage card's words, every new string in Chinese, and a new provider with a token and no URL). go build (and GOOS=linux, GOOS=windows), go test -tags nogui ./... and the other GUI tests pass 2026-09-29 17:56:43 +08:00