Commit Graph
4 Commits
Author SHA1 Message Date
yetone 019b308f1a provider: one key added again for another API of the same host is a provider of its own (#3388)
energetic_wolf_99424 (Discord #help) has one relay key that works in both
the OpenAI and the Anthropic format. They added a custom provider with it in
one format; adding a second custom provider with the same key in the other
format was refused with "<name> is already added with that key". The same
refusal blocked OpenCode Go beside OpenCode Zen with one account's key
(#3388, found by ggbdpq, verified by Edward4226).

Add's duplicate check (add in provider.go) used sameProvider, which
judges by key + host + headers only. It now also needs servesAll: the new
provider brings no API, and no address of one, that the provider already
there lacks (Chat, Responses, Anthropic and Gemini compared slot by slot
after normalize). So the same key at the same addresses is still refused
as the one already here, and another format, or another product path on
the host, is added under its own id. The GUI, the CLI (`magpie provider
add`) and the TUI all go through provider.Add, so all three are covered.
AddCopy never had the check. Two providers sharing one key already existed
(AddCopy, another host), so nothing keyed by the key (KeyID, usage by
provider id, resting) meets a new state.

Not changed: the app import still calls an entry "Already added" when the
provider there has the key at that host, even if the entry brings an API it
lacks; filed as #4904.

Run at this head (rebased on 1829cd52f), on mote:
- go test ./internal/provider -count=1: ok (191s).
- gofmt -l clean; go vet -tags nogui ./internal/provider ./internal/cli
  ./internal/tui ./internal/gui for darwin, linux and windows: ok.
- Before the rebase (base 07f4d46c5, same diff): go test ./internal/cli
  ./internal/tui ./internal/gui: tui ok; cli red only on
  TestEveryRouteHasACommandOrIsNamed (#4826, checkin-account route), gui
  red only on TestMainWindowCorners/macOS_26_SDK (#3949, macOS 27).

Broken by hand: dropping `&& servesAll(...)` turns TestAddSameKeyOtherFormat
red with the reporter's refusal ("Relay is already added with that key
(relay); ...").

Not tried: the real GUI Add dialog, a real relay key in both formats, a
real OpenCode key.

Reported by energetic_wolf_99424; #3388 by ggbdpq.
2026-11-02 18:16:09 +08:00
yetone a2714f7506 claude: a Claude account's usage resets are read in the zone /usage names on Windows too, and the provider tests pass whole on Windows (goal: 插件订阅 provider 跟内置的所有逻辑都要一模一样, run on Windows and Linux) — Windows has no time zone database, so "resets Oct 1 at 3:30pm (Asia/Shanghai)" was read in the machine's own zone, hours off for anyone not in that zone; magpie now carries the database (time/tzdata). The provider tests set HOME but not USERPROFILE, which Windows takes the home from, so on Windows they read the test box's own agent sign-ins (Gemini models in a list, an extra provider, a Cursor version); every test home sets both now. Tests whose fake CLI is a shell script (Claude Code's auth status, codex --version, macOS's security) skip on Windows, as the fake devin did, and file mode bits go unchecked there. TestParseClaudeUsage fails on Windows without the change. On Windows and on Linux (WSL) the provider package passes whole, three times on Windows (15 failed before), the plugin package and the move/plugin/Grok/Devin/usage tests five times over on Linux. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass. 2026-10-01 13:51:24 +08:00
yetone a46a6bb2ec providers: a custom provider named in Chinese is added under its site's name, and a second one beside it (mamba on Discord: 供应商里面自己添加第三方URL只能加一个吗,第二个会提示id重复) — a provider's id is its name slugged to Latin letters and digits, so a name such as 中转站 slugged to nothing and Add was refused ("provider id must be lowercase letters, digits and dashes, not \"\""). Now such a name takes its id from the host of its URL, api. and www. and the .com left off (api.relay-one.com is relay-one), and one on an IP address or localhost-like address is custom; a taken id moves on to relay-one-2 as before, and a second 中转站 is named 中转站 2. Tested: two 中转站 on one host, one on a host with a port, one on 127.0.0.1 and one on [::1] each added under its own id; checked in a sandbox magpie web that 中转站 is added beside another custom provider 2026-09-29 09:17:47 +08:00
yetone 35ebc94d58 provider: a preset's provider takes request headers of the user's own, and a preset can be added more than once (#50) — which workspace a key that reaches several is for (anthropic-workspace-id), or who the app is to OpenRouter, could only be said by a custom provider, so it meant giving up the preset's endpoints and catalog; the editor now shows headers for presets as well, offering the ones the vendor documents with their values left to fill in, and "Add another" makes one more provider of a preset under an id of its own (anthropic-2) where adding again replaced the first; the same key, host and headers twice is refused as the one already there, and importers keep a preset's headers and its preset when they split an entry off to a free id 2026-09-25 09:36:42 +08:00