88b4c00ea11c8653cada22e11edf20ab1594de43
13
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
d9ca84a2f4 |
gateway: built-in TLS, magpie serve/web/daemon install --tls-cert --tls-key, reloaded on renewal (RoderickZH)
magpie serve, magpie web and magpie daemon install take --tls-cert <file> --tls-key <file> (or MAGPIE_TLS_CERT / MAGPIE_TLS_KEY). The gateway and the web UI on its listener then serve HTTPS to other computers. Without them nothing changes. - Half a pair, a file that doesn't parse, or a flag with no value is refused at start with a message naming the missing flag. - The pair is re-read when either file's mtime or size changes (certbot renewal), with no restart. A renewal that doesn't parse keeps the certificate already served and is logged once. - Other computers get HTTPS only. Plain HTTP from them gets net/http's 400 "Client sent an HTTP request to an HTTPS server". - This computer (loopback, or a peer address equal to the local one) may still use plain http on the same port. Its connections are sniffed on their own goroutine (a first byte of 0x16 is TLS) for up to 10s, so a silent client holds nobody else up. gateway.URL() stays http://127.0.0.1:<port>, which agents, MCP servers, ServedBy, the healthcheck and daemon status all use, and no certificate covers loopback. - WSL NAT and containers count as other computers. - ALPN is http/1.1 only (hijacked connections and websockets need it), with TLS 1.2 as the minimum. - Printed links, LAN addresses, publicURL, the serve/web banners and daemon install show https:// for other computers' addresses. - The DNS-rebinding Host checks (foreignPage, rebound, the MCP loopbackHost) don't depend on the scheme and are unchanged. - daemon install carries MAGPIE_TLS_* into the unit or plist. A reinstall or `daemon web on` that names no certificate keeps the installed pair, and --no-tls removes it. - Docs: reference.md gets an HTTPS section that names Caddy as the alternative, gateway-routing.md gets a TLS row, and docker.html (en, zh, ja) gets the env rows. What was run: - New tests: internal/gateway/tls_test.go (others HTTPS-only, this computer both, a silent local client holds no other, renewed certificate served, CheckTLS, addresses, Relisten keeps TLS), internal/cli/tls_cli_test.go and daemon TestInstallCarriesTLS (linux and darwin, paths with space, %, & and "). - Each was broken by hand and went red: no wrap in listen, no reload, a synchronous sniff, a bad renewal dropping the certificate, http in publicURL or the pinned LANURLs, the carried entries removed, and keepTLS as a no-op. - Real use under a sandbox HOME, with a self-signed pair, on 0.0.0.0:3461: - Half a pair, a garbage certificate, a flag with no value, and the env set to half a pair each exit 1 with the message. - curl -k https://127.0.0.1 and https://<LAN IP>/v1/models with a key: 200. Plain http on loopback: 200. - The cert files were swapped for a second pair while it ran. openssl s_client then showed the new CN and serial, and curl --cacert with the new pair got 200. A junk key file then kept the second pair, logged once. - From the Windows box over the LAN: plain http got 400; https with the key got 200, and without it 401. - magpie web --addr 0.0.0.0:3462: https network links. From Windows, http got 400 and https with the key got 303. - gofmt -l clean. go vet passed on darwin, GOOS=linux -tags nogui and GOOS=windows. - go test -tags nogui for ./internal/cli, ./internal/daemon, and the TLS tests of ./internal/gateway and ./internal/gui: all pass at the rebased head. - Two reds in the full suite (`go test -tags nogui ./...`) are the same on origin/main f074996d9; both are filed: - TestGatewayHeldByAContainer failed 2 of 5 there (#2107). - The gateway package runs past go test's default 10m under load: 1208s on main and 1221s here, both passing with -timeout 40m (#2108). |
||
|
|
bf25842714 |
gateway: a provider's own cap on how long a key that keeps failing rests (#2008, Gaudi-XIX)
A key that keeps failing doubles its rest from a minute up to 10 minutes, and one rate limited again as soon as its rest is over up to 30; both caps were fixed, so a free key down for hours was asked again every 10 or 30 minutes all the while. `magpie provider rest-cap <id> 4h` (Provider.RestCap, minutes, at most MaxQuotaRest, 8 days) sets where both ladders stop for that provider's keys and accounts (RestCapOr in restAfterMarked's default branch and in rateRest); `default` gives back the gateway's own. A time the vendor names still stands over it. Unset, nothing differs. It is kept by the editor's save, the account copy and normalize. Run: go test -tags nogui ./internal/provider ./internal/gateway ./internal/cli ./internal/gui (temp HOME). Broken by hand: both ladders back on the fixed caps fail TestOwnRestCap (rate-long #6: 30m, want 32m); the GUI keep removed fails TestSaveKeepsQuotaResetAt. Not tried against a real vendor's outage. |
||
|
|
064cffdbfd |
gateway: a key out of a daily allowance rests until the time of day it comes back (#2008, Gaudi-XIX)
A free tier's "You've reached today's free-model token quota" says nothing of when it is back, so it rested 15 minutes (or the provider's own quota-rest), and was asked again all day. A vendor Retry-After over an hour was cut to the hour, and that hour then stood over the user's own longer rest. - Provider.QuotaResetAt: "08:00" on this computer's clock, or "00:00+08:00" on the vendor's. `magpie provider quota-rest <id> until 08:00` sets it; a number of minutes set after it replaces it, and default clears both. normalize drops one that isn't a time of day. It is kept by the editor's save and the account copy. - restAfterMarked's quota branch rests until its next occurrence (OwnQuotaRest). A time the vendor names, or a window's end, still stands over it; a Retry-After stands unless it was cut to longestWait while the user's own rest is longer. - Defaults are unchanged: nothing set, nothing differs. Run: go test -tags nogui ./internal/provider ./internal/gateway ./internal/cli ./internal/gui (temp HOME). Broken by hand, each fails: OwnQuotaRest replaced by QuotaRestFor (TestQuotaRestsUntilTheTimeOfDaySet, 3 asserts), the Retry-After guard removed (the 7200 case), the GUI keep removed (TestSaveKeepsQuotaResetAt), default not clearing it (TestQuotaRestUntil). Not tried against a real free-tier vendor. |
||
|
|
80211e7075 |
provider: a balance field sums, maxes or counts a list's items, and one amount it can't read is "—" (#1993, RicardoWYP)
A relay's /api/subscription/self tells usage per subscription, a list.
A balance path could only name one index (subscriptions.0), so several
active subscriptions read as the first, ".0 + .1" failed whole when only
one existed, and a weekly cap of 0 ("divides by 0") hid every amount of
the field.
Now a path goes through a list's items with "*" (a.*.used), or those
that match with "[key=value]" / "[key!=value]" (a[status=active].used,
also on an object: a.*.subscription[status=active].used). Such a path is
several values, made one by sum(), max(), min() or count(); arithmetic
between two of them goes item by item, so max(a.*.used / a.*.cap) is the
fullest window. Several values left outside a function are an error
naming the functions, not a guessed sum. Within a list an item without
the path, or divided by 0, is left out; max/min of nothing is an error.
In a field of several ";" amounts, one that can't be read shows "—"
(BalancePart.Error says why, as the card's hover on the Usage page and
in the panel) and the others still show; the read fails only when none
can be read. A single amount alone still fails as before.
The GUI hint (zh, zh-TW, ja, de) and `magpie provider` help say the new
syntax.
Run:
- TestBalancePathLists, with the reporter's literal JSON: against the
old balance.go it fails ("nothing at \"sum\" in the reply", and the
"—" cases error); passes now. TestReadBalancePath's one case that
expected a whole-field failure with one bad amount now expects it
only when every amount fails.
- go test -tags nogui ./internal/provider ./internal/cli ./internal/gui
under a temp HOME: ok.
- balance-parts, gui-de, gui-ja, gui-zh-tw, i18n-keys in Chromium and
WebKit: 14 pass. With the title lines removed, balance-parts fails on
the missing hover text.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui on
provider and cli.
Not tried against the reporter's real relay.
|
||
|
|
c4e6abf3cc |
gui, cli: a model id typed with a space in it stays one model, "Opus 5.5" not Opus and 5.5 (#1976)
elonnzhang on #1976: on a Baidu OneAPI relay, typing `Opus 5.5` in the provider editor's add box (or the add form's Models field) and pressing Enter added two models, `Opus` and `5.5`. Both read the box with split(/[,\s]+/), while their hints say "comma separated". - app.js: one typedIds() for both, split at commas (and line breaks) with each id trimmed. chosenIds() (the add box, and an id left in it at Save) and the add form's Models field use it. - CLI siblings, which split the same way: `magpie provider set models=` now splits at commas only. A group's models=, models-=, fast= and weight= split at commas, and an item with a space that names no model the group can have is still split at its spaces, so `models=m,b/x a/m` (TestApplyGroupPairs) still works. levels= and `magpie visible` (effort levels and family names) are unchanged. - Tests: the reporter's two GUI assertions in models-add-and-icons (from their fork branch). A new model-id-space.test.cjs covers both boxes in en, zh, zh-TW, ja and de, Chromium and WebKit, at 1100 and 420 wide. TestModelIDsKeepTheirSpace covers the CLI. The fork's change to provider-add-models.test.cjs is not taken: filling the Models field there replaces the picks it holds, so it failed on its own terms. Run: on the old split, model-id-space fails (4/4 for en and de at 420 in Chromium) and TestModelIDsKeepTheirSpace fails (models = ["Opus" "5.5" ...]). With the whole-item check forced off, it fails on members. With the fix: model-id-space 40/40, models-add-and-icons 4/4 and provider-add-models 4/4 pass. `go test -tags nogui ./internal/cli` is ok. gofmt is clean, and go vet passes for darwin, linux (-tags nogui) and windows. Not tried: a real relay with a spaced model id served end to end. |
||
|
|
79099d6adb |
provider, gui, tui: Ollama, LM Studio and oMLX take an address, so a server on another port or computer is the preset's provider (#1165)
The three On this machine presets were pinned to localhost and their default port: one started on another port, or on another computer on the LAN, had to be rebuilt as a custom provider or typed URL by URL in the CLI. They now take an Address (scheme, host and port), and each of their URLs keeps its own path there (provider.AtAddress, AddressOf; no scheme means http, only http/https, port 1-65535, a pasted path is dropped, anything else refused with nothing changed). - GUI: the add and edit editors have a Server address section under the key, folded unless the saved address isn't the preset's, opened and focused on a refused one. The Endpoints, Test and Refresh follow what is typed; URLs are sent only when the address changed, so ones set apart (an import, the CLI) are left alone. zh, zh-TW, ja, de. - TUI: adding a local preset asks for its address before the key (Enter keeps the default), and w edits it. - CLI: the usage shows provider add ollama url=... anthropic=.... - LM Studio's and oMLX's notes say "port N by default". timonwong's PR head e63cf18e, merged onto main, which had given oMLX a decision API (#1641) since: presets.go keeps main's oMLX Decide; app.js keeps both the Vertex block and the address one; the docs row and -run list take both. Run: see the next commit. |
||
|
|
6794cccd53 |
cli: models and visible find a WSL agent by its id, in any case (#271)
`magpie models --agent` and `magpie visible <agent>` turned the typed name
into an agent through usage's AgentOf, which knows the built-in agents
only, so a WSL agent's id (claude@wsl:Ubuntu) was "no agent". Both now
use agent.Find, as every other agent command does, and visible keeps its
key lowered, as VisibleTo looks it up.
Landed from #271 (AnxForever), merged onto main by hand. The test moved
from the repo root into internal/cli, where the code it tests lives, with
one more case added: TestWSLAgentByIDInModelsAndVisible.
Run (merged onto
|
||
|
|
248a68598c |
gateway, provider, gui, cli: a key+URL provider may be sent the agent's own User-Agent in place of magpie's (#1851)
Every forward went with User-Agent magpie/<version>. A coding plan that serves only the agents it names (pi, OpenCode, Claude Code…) knows them by their User-Agent, so it turned magpie away. What changed - provider: PassUserAgent (passUserAgent in providers.json), off by default. PassesUserAgent takes it only for a key+URL provider: never a signed-in account, a plugin's, or a vendor whose own client magpie goes as (OwnClient: OpenCode, Cline, Kilo, another magpie). A copy keeps it. - gateway: userAgentFor in forwardOnce (chat, Anthropic, Responses, Gemini, count_tokens) sends the inbound User-Agent unchanged where the provider passes it on. It sends magpie's where it doesn't, where the agent sent none, and on magpie's own requests (magpiesOwn: magpie/…, magpie-router/vision/search, the image tool's "<client> magpie-image/1", which is built from MCP clientInfo, not a User-Agent). magpie never invents another client's. The claude-cli/Codex header copies, the OpenCode/Cline/Kilo overrides and account signing run after it as before, and the user's header.User-Agent is put on at signing, so it wins. - gateway: embeddings, images and videos (retrieveFrom, sendWith, remoteVideoContent) now stamp the same for a key+URL provider through stampUA, from the caller's User-Agent kept on the request ctx (caller.ua, withCaller). Before, they went with Go's default (Go-http-client/1.1). Account and remote-magpie paths are untouched. - cli: `magpie provider set <id> user-agent=agent|magpie`, refused for a signed-in account; `magpie provider <id>` shows it. - gui: the provider editor's User-Agent row, "Send the agent's own User-Agent", with an explanation, for a provider with a key only (the JSON says ownClient for presets and providers); en/zh/zh-TW/ja/de. The TUI only adds presets, so it has no field for this. - docs: reference.md (provider set) and subsystems/gateway-routing.md. What was run - gofmt -l clean; go vet ./... on darwin, GOOS=linux -tags nogui and GOOS=windows. - go test -count=1 ./internal/gateway ./internal/provider ./internal/cli ./internal/gui: all ok (sandbox HOME, private GOCACHE). - TestUserAgentPassedOn covers 7 routes (messages, count_tokens, chat, responses, gemini, embeddings, images) x off / on / on with no UA / on with magpie-router/1 / on with the image tool's UA / the user's header with it on and off. TestUserAgentAccountUntouched: a Factory account with passUserAgent in providers.json is still asked as factory-cli/. Also TestUserAgentClaudeCodeAsBefore, TestUserAgentFor, TestPassesUserAgent, TestAddCopyPassUserAgent, TestProviderUserAgentPair. - Broken by hand, each went red: forwardOnce back to magpie's UA (5 routes red); stampUA removed from embeddings/draw (both red, seen as Go-http-client/1.1); PassesUserAgent ignoring accounts/OwnClient; magpiesOwn dropped (the internal UAs leaked on all 7 routes); the GUI row shown for OpenCode and Save not posting it. - provider-user-agent.test.cjs: 60/60 in chromium and webkit, en, zh, zh-TW, ja, de, at 900 and 440 wide. The provider/editor/add/i18n GUI tests in chromium: 244/244. Not run - Not tried against a real coding plan that checks User-Agent, nor with a real agent through a live gateway. Videos have no test of their own (they go through sendWith, which the images test covers). - The GUI suite was not run in full; the Windows box was not used. |
||
|
|
10d60b1899 |
provider: a provider saved with Select none serves no models, unlisted or not (#1818)
Select none saved `models: []`, which omitempty wrote as no models key at
all, so the provider read back as "no picks" and served the first 24 of
the vendor's list on /v1/models, in auto groups and on the card, while
the editor said none would be served.
What changed:
- Provider.NoModels (json noModels) records the choice; ServesNone() is
NoModels with no picks. A file with no models key still serves the
vendor's list as before.
- Exposed() is empty for it, so the catalog, /v1/models and auto groups
leave it out; resolveIn refuses an explicit pid/model to it; listedBy
and Deciders skip it (a decide-only provider is still a decider).
- SetModels and normalize clear NoModels once there are picks.
- GUI: the editor sends noModels on Save, an edit that omits it keeps it,
the card's exposed count is 0, the hint says nothing is served; with
unlisted the dashed chips explain they are only for groups. Strings in
en, zh, zh-TW, ja, de.
- CLI: `magpie provider models <id> none`.
- docs/subsystems/providers-accounts.md describes it.
Decision (owner delegated): Select none means none, whether or not
unlisted is on; unlisted keeps meaning "hide from the list, still
usable by groups that name it".
Run:
- go test ./internal/provider ./internal/gui ./internal/cli -count=1
(green; second pass ran too) with private GOCACHE and sandbox HOME.
- Broke Exposed's ServesNone check: TestSelectNoneServesNone red
("exposed 24"); broke resolveIn's: red ("watched/m0 resolved"); broke
the GUI keep line: TestProviderSaveSelectNone red ("exposed 24").
- GUI tests chromium + webkit, 5 languages: provider-none-picked 20/20,
provider-draft-picks 10/10 (red with noneChosen broken), plus 12
related model/group/editor tests green.
- gofmt -l clean; go vet darwin, linux -tags nogui, windows clean for the
three packages.
Not run: the gateway package; Codex native model narrowing is unchanged.
searcher-pick.test.cjs fails 3 webkit cases (hover timeout) identically
on the unmodified base
|
||
|
|
af7d97fa2f |
gateway: a Responses provider set codex=as-sent gets Codex's requests as Codex sent them, for a relay that checks they are Codex's own (#1758)
A relay that checks a request is Codex's own answered magpie 400 "Codex 客户端请求特征无效" (10014). magpie fits every Codex request for a Responses backend that isn't OpenAI's: Responses Lite's additional_tools item is lifted into tools (#350), the tool search goes as a function, and OpenAI-only fields such as stream_options.reasoning_summary_delivery are left out. The reporter found that the relay takes the request when additional_tools is left as an input item, and that the lifted shape is what it refuses. The lifting stays the default, because backends that aren't OpenAI's refuse additional_tools or silently drop it (#350). A provider can now opt out: `magpie provider set <id> codex=as-sent` (`codexAsSent` in providers.json; `codex=default` turns it back off). With it on, a request from Codex (fromCodex: Codex's User-Agent or originator) goes as Codex sent it, with only its model name swapped. Codex's own headers go with it as before. A subscription account is never sent this way, and the GUI's provider save keeps the setting. What was run: - TestCodexAsSent: by default the request is still fitted; with codexAsSent the upstream gets exactly what Codex sent, with model m1, X-Codex-Turn-Metadata and the Responses Lite header. It fails on the old gateway.go and passes now. TestAdditionalTools and the gateway's Codex tests pass. Not verified: not tried against the reporter's relay. Their check was made by hand outside magpie, so which other fields that relay looks at is not known. There is no GUI control for the setting (CLI or providers.json only). |
||
|
|
ff930886a2 |
gateway: keys all out of their allowance are answered from their rests with a Retry-After, not asked again on every request, and a key listed twice is asked once (#1772)
A fleet on four Ollama Cloud keys, every one out of its weekly allowance:
each new request asked every key again (the first twice) and answered
429 with no Retry-After, so an agent that waits as told asked again at
once, and the vendor saw four refused requests a turn.
What changed:
- The first key twice: the reporter's providers.json named the first key
in "keys" as well as "key". KeysOn now lists a key once.
- When every key left for a request rests out of its allowance (a 429 or
402 that failure() calls quota or credit, keys only), the request is
answered from the rest without asking: the vendor's own words, "not
asked again before HH:MM", and Retry-After until the first of them is
back (quotaHeld, soonestBack). Accounts are left out, so autoReset
can still spend a reset for them; a 403 or 400 worded as quota is
asked as before.
- The last key out of its allowance now rests as the ones before it do
(before, the last one left was never rested), and a 429 the vendor gave
no Retry-After for gets the soonest rest's end as one.
- A provider can set how long its keys rest when the vendor says nothing
of when the allowance is back: quotaRest (minutes) in providers.json,
or `magpie provider quota-rest <id> 7d`; default stays 15 minutes, at
most 8 days. A time the vendor names (resets_at, Retry-After, a
window) still wins. A GUI save keeps it.
What was run:
- TestAllRestingAnswersFromRest, TestFirstKeyListedTwiceAskedOnce and
TestOwnQuotaRest fail on the old code (no Retry-After, keys re-asked;
"dead-1 dead-1 dead-2 ok-3", the reporter's log); they pass now, with
TestQuotaHeldOnlyForKeysOutOfAllowance, TestDeadChainWalksEachOnce and
TestRestMinutes. The mock answers with the reporter's literal 429 body.
- go test -tags nogui ./internal/provider ./internal/gui pass. A gateway
package run at load ~60 hit its 20m timeout mid-suite with only
TestMaxRPM* red; those pass 8/8 alone here and on origin/main
|
||
|
|
94aa153973 |
tui, provider, serve: a signed-in account's models are fetched at start, so Routing offers Cursor's whole list without m (#1789, reyoung)
The terminal and `magpie serve` never called provider.FetchNew, which the window calls at start: a signed-in Cursor account's list exists only at Cursor, so the TUI's Routing pickers (and a headless gateway's /v1/models) offered the fallback cursor/auto alone until the list was fetched by hand with m on the Providers page. - tui: Init fetches the new lists (fetchModelsCmd, alongside the catalog sync). A model picker open when they arrive (Routing members, the classifier, a provider's models, an agent's model field) is filled in place through its relist, keeping its filter and the model under the cursor. A list left missing (no network) is asked for again a minute later (modelsRetry). Built on reyoung's branch and test. - serve: FetchNew at start, again each minute while a list is missing. - provider: FetchNew reports whether a list is missing, and waits for a CLI asked who is signed in for the first time (awaitIdentities), then lists the accounts again. With the real Cursor account in a fresh sandbox, `cursor-agent about` answered after a look's 3s firstAsk, so FetchNew saw no Cursor account and `magpie serve` still listed 1 model with the TUI fix alone. The window's startBackend gets the same wait. - docs: providers-accounts.md says who fetches the lists and when. Run: - internal/tui TestTUIFetchesSubscriptionModels (6 views) and TestTUIAsksAgainForAMissingList, -race x3; red with the Init fetch, the relist, the cursor restore or the retry tick each removed by hand. A first `about` slowed to 12s injected: passes (the test re-asks). - internal/provider TestFetchNewWaitsForASlowSignIn: red without awaitIdentities (no provider "cursor"); TestFetchNewAccount covers the missing result. - Real Cursor account, sandbox HOME with a keychain holding only Cursor's two items: TUI on main showed cursor/auto only in Routing; the fix shows the full list and "24 models" on Providers. `magpie serve`: main 1 Cursor model at /v1/models, the fix 24 within 5s. - gofmt -l, go vet (darwin, GOOS=linux, GOOS=windows), go test ./... in a sandbox HOME. Not tried: Linux and Windows real Cursor CLIs (the fake CLI tests skip on Windows); Devin's CLI identity goes through the same wait but wasn't tried with a real account. |
||
|
|
23e764d0e0 |
cli: magpie's commands move from the root into internal/cli; the root keeps only main.go
The root held 89 .go files (30 commands, 59 tests). They move as they are to internal/cli (package cli), with git mv so history follows them. The only code change is main() becoming cli.Main(version): the root's new main.go keeps `var version` in package main, so -ldflags "-X main.version=…" in the Makefile, the Dockerfile and magpie-releases, and every workflow, work unchanged. go-winres's rsrc_windows_*.syso still land next to package main in the root. Tests that read testdata by a root-relative path now go up one level (../plugin/testdata/fake, ../sessions/testdata). Five subsystem doc links point at internal/cli/. Run: - go build ./..., gofmt -l, go vet on darwin, linux and windows (nogui) - builds with tags production, dev, "production nogui"; windows -H windowsgui; linux CGO_ENABLED=0 - make release-cli TARGETS="darwin/arm64 linux/amd64 windows/amd64 android/arm64" VERSION=9.9.9-tidy: all four built, binary prints "magpie 9.9.9-tidy" - docker build --build-arg VERSION=7.7.7-tidy: container prints "magpie 7.7.7-tidy" - go test ./internal/cli (default and nogui): 152 tests, the same count as the root on main - go test ./...: all packages pass (agent, gateway, library, provider timed out at 10m under other sessions' load and passed rerun alone with -timeout 40m; none of them changed) - the built binary in a sandbox HOME: version, help, ls, providers, claude, and an unknown command's error |