Young on Discord: a provider of several keys, each of a relay group that
serves some of its models, had every key added or imported allow every
model, so the user narrowed each by hand, and requests went to a key
that can't serve the model.
A key added now (GUI Add key, Import keys, several keys pasted in the
provider's key field, and Import local configurations, CC Switch's
entries folded into one provider included) is asked for its own
/models, with that key alone, within the add's 8s wait and beside the
provider's own Fetch. What it answers becomes its AccountModels when it
leaves out a model the provider's other keys serve.
Only a new key with no models of its own is given a list: the keys a
provider had keep theirs (none, or the user's), and a pick the user
makes while the list is asked is kept. A key whose list can't be told
keeps every model, as before, and no empty list is written: a refused
key, an empty list, one past the wait, a base that didn't answer (its
part would be the provider's old list), a vendor with no list
(Preset.NoList, plan-only presets, Cline and Kilo's feeds), a provider
of one key, and a key that lists every model the others do (a list
would only hold back what the vendor adds later).
The CLI has no key add (`provider key` replaces the key), so it is
unchanged.
Run on mote at the pushed head (on origin/main fa6725ee7):
- go test -count=1 -timeout 45m ./internal/provider/: ok
- go test -count=1 -timeout 45m ./internal/gui/: ok but
TestMainWindowCorners, red the same 3 of 3 on origin/main b3eb26400
on mote's macOS 27 (#3949)
- GOOS=linux go vet -tags nogui ./internal/provider/ ./internal/gui/
and GOOS=windows go vet ./...: clean
- gofmt -l internal/provider internal/gui: clean
Tests use a fake relay that answers per key (httptest), no network.
Broken by hand, each red:
- give existing keys a list too (drop the before check):
TestNewKeyTakesItsOwnModels (2 keys given a list, want 1)
- take a list with a base that didn't answer:
TestNewKeyHalfAnsweredKeepsAll
- give a list even when it has every model, and skip the Save:
TestNewKeyTakesItsOwnModels / TestImportedKeysTakeTheirOwnModels
Not tried: a real relay account with per-group keys; the "replace key"
action (it keeps the key's slot); a model the vendor later adds to a
prefilled key's group is added by hand in the key's models, as with
any list. No GUI asset changed.
@hu_xiaomi on X asked whether magpie could pick up OpenCode Go's API key
by itself. OpenCode keeps what `opencode auth login` signs in to in
auth.json, in $XDG_DATA_HOME/opencode (~/.local/share/opencode when that
is unset, on Windows too). Its format and path were checked against
anomalyco/opencode v1.19.0, packages/opencode/src/auth/index.ts.
- OpenCode is now a source in the import picker (appReaders,
import_opencode.go). An "api" key comes in on the magpie preset with
the same id: opencode-go on OpenCode Go, opencode (Zen) on OpenCode
Zen, and a vendor's key (openai, anthropic, deepseek, openrouter, ...)
on that vendor's preset, the same way Alma's almaPresets work.
- auth.json keeps no address beside a key, so a key for a provider with
no preset is listed and skipped ("it has no base URL"). Sign-ins
(oauth: Claude Pro/Max, Copilot; wellknown: an enterprise server's
token) are listed and skipped with the reason the picker already
translates. No new GUI strings.
- OpenCode is read only when the user opens the picker. The Providers
page's automatic discovery leaves it out (DiscoverSources, the `asked`
flag), because the file holds every sign-in OpenCode has. magpie never
writes to it. OPENCODE_AUTH_CONTENT is not read.
- presetAt: the first preset at a host won even when a later one matched
the URL exactly. OpenCode Zen and Go share opencode.ai, so a Zen key
would have landed on Go. An exact match now wins.
- importSources: a source whose stat fails with anything but not-exist
(a folder magpie can't search) is found with an error, which means
unknown. Before, it read as "Not found".
- The picker's tab shows OpenCode's own mark (icons/opencode.svg).
- docs/reference.md describes the source.
Not added: an "use the key OpenCode has" offer in the OpenCode Go add
sheet, because no other app has one there (no sibling to follow).
Run (macOS, go1.26.8, worktree at dd25997a4 before the rebase):
- go test -tags nogui -timeout 40m ./...: every package ok
(63 ok, none failed; gateway 1806s, agent 1769s at load ~160-230)
- gofmt -l internal/provider internal/gui: clean
- go vet ./...; GOOS=linux go vet -tags nogui ./...;
GOOS=windows go vet ./...: clean
- GUI, playwright 1.62.0: import-opencode.test.cjs in chromium and webkit,
en/zh/zh-TW/ja/de, at 900 and 390px: 20/20. import-collision,
import-row, provider-discovery and key-import pass. login-import fails
in chromium (fill/click timeouts) at load ~230. It fails the same way
with HEAD's app.js (dd25997a4 = origin/main, just fetched), and #1307
already tracks it.
- Broken by hand, each went red and was then put back:
1. presetAt's old first-hit rule: TestImportOpenCodeAuth, Zen came in
as opencode-go-2.
2. no sign-in skip: TestImportOpenCodeAuth, anthropic's oauth entry.
3. stat errors read as not found: TestImportOpenCodeAuthUnknown,
unreadable folder.
4. discovery reads OpenCode: TestImportOpenCodeAuth and
TestOpenCodeWaitsForThePicker.
5. XDG_DATA_HOME ignored: TestImportOpenCodeAuth, TestImportOpenCodeAuthUnknown
and TestOpenCodeWaitsForThePicker.
6. tab icon left at app-opencode.png: import-opencode.test.cjs.
Fixtures are auth.json as OpenCode v1.19.0 writes it
(JSON.stringify(data, null, 2), 0600), under a sandbox HOME and
XDG_DATA_HOME. Not tried: a real OpenCode install with a real key, and
the Windows box (the path logic is the same there; GOOS=windows vet only).
Dudung1018's CC Switch had third-party providers named as magpie's
subscriptions are: a Pi proxy "workbuddy", an OpenCode relay "Claude".
Reproduced in a sandbox GUI with a CC Switch db in cc-switch's real
schema:
- the default import answered 400 "workbuddy is the id of the workbuddy
subscription; pick another name", after some picks had already been
written. That is why the reporter later saw "already added" and couldn't
find where the key went.
- the "Replace it" choice on a row named "claude" wrote the relay's models
as the Claude subscription's picks, and dropped its key and address.
What changed:
- importapps: a row whose id is a subscription's (signed in or not), or
magpie's own, is marked reserved. It is picked like a new one and added
under a free id beside the subscription. Replace is refused for it, and
key mode never joins an account or a provider at another address.
- the picker has a name field on every row whose name collides. A renamed
row is added under its new name, and Replace is no longer offered for it.
"Add as another key" names the provider the key went to.
- import links (magpie://import, magpie import) named or id'd as a
subscription get a free id.
- the new sub-line is in en, zh, zh-TW, ja and de.
What was run:
- sandbox GUI on the old build (the 400, the partial write, the Replace
case), then on the new one. The same picks gave 200 ["Relay 1487",
"Claude (findcg)", "workbuddy"]: findcg got one more key, and relay-1487
and workbuddy-2 were added at their own addresses.
- importapps_reserved_test.go: 4 tests on the real cc-switch schema, all
red on the old code.
- import-collision.test.cjs: chromium and webkit, in en/zh/zh-TW/ja/de, at
900 and 390px, 20/20 passing and red on the old assets.
provider-discovery.test.cjs still passes.
- go test -tags nogui ./... green, gofmt -l, and GOOS=linux and windows go
vet for internal/provider and internal/gui.