From 8718e0427db8fcc3faab7326aa35e1f8a259745b Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 11 Nov 2026 17:15:48 +0800 Subject: [PATCH] settings: app updates get their own proxy choice (moonlityu on X) Settings > Network has a new "App updates" row under the plugin proxy row: Same as above (default, today's behaviour), Direct, Custom or a saved proxy. It is Settings.UpdateProxy / UpdateProxyCustom, kept per computer (KeepOwn), left out of auto-backups with the other proxies, and listed in the saved proxies' "in use" check, so a saved proxy used by updates can't be deleted. update.proxied() wraps its transport: a request that names no proxy of its own (magpie update --proxy does) takes the setting; unset, it follows the global proxy as before. A value a user already set is never changed. Per-model proxy inside one provider is not added: a proxy belongs to a provider, an account or a key, so a provider can't split by model without a second provider on the same URL (noted in providers-accounts.md). app.js stays within TestCoreScriptBudget by cutting five long comments, no raise. Run (Linux via wsl-run, rebased on origin/main 961427f12): go test of internal/update, settings, settingsapi, backup and internal/gui (-tags nogui) incl. TestCoreScriptBudget and the settings-keep guards; new settings-update-proxy.test.cjs in chromium and webkit, 5 languages, 1100 and 420px; gofmt; go vet for darwin, windows and linux (nogui) on the touched packages. Broken by hand: removing the updateProxy wrapper turns TestUpdateTakesItsOwnProxy red. GUI reds named: settings-proxy-auth "optional proxy credentials" webkit (expected 'name', actual ''; red on origin/main too, #5562, seen again); saved-proxies "webkit de 420px" stopped passing with the third row because the add form's Save button sat 1px below a 760px window and WebKit's scrollTop stuck at 214 (#6130); that test's window is now 900px high. Not tried: a real update behind a real proxy, the Windows/macOS apps, WebKitGTK. --- docs/subsystems/providers-accounts.md | 2 +- internal/backup/auto.go | 1 + internal/backup/auto_test.go | 2 + internal/gui/assets/app.js | 33 +++-- internal/gui/assets/i18n.js | 16 +++ internal/gui/assets/index.html | 4 + internal/gui/proxies.go | 5 +- internal/gui/settings_keep_test.go | 1 + internal/gui/tests/saved-proxies.test.cjs | 2 +- .../gui/tests/settings-update-proxy.test.cjs | 118 ++++++++++++++++++ internal/settings/proxy_custom_test.go | 27 ++++ internal/settings/settings.go | 17 +++ internal/settingsapi/settingsapi.go | 3 +- internal/update/proxy_test.go | 66 ++++++++++ internal/update/update.go | 23 +++- 15 files changed, 297 insertions(+), 23 deletions(-) create mode 100644 internal/gui/tests/settings-update-proxy.test.cjs diff --git a/docs/subsystems/providers-accounts.md b/docs/subsystems/providers-accounts.md index 954132711..bf13ec320 100644 --- a/docs/subsystems/providers-accounts.md +++ b/docs/subsystems/providers-accounts.md @@ -86,7 +86,7 @@ keys and accounts per request is in [Gateway routing and fallback](gateway-routi | Local servers | A preset of `KindLocal` (Ollama, LM Studio, oMLX, MLX-Serve) is at its server's default port on this machine. Another address — a port, or another computer — is given in the window's editor, in its Server address field, shown first above the key and never folded (a folded one read as an LM Studio whose base URL can't be changed, mengxiangziyou on X), or in the TUI (asked on adding, `w` after); on the command line with `address=` (`atAddress` in `providers_cli.go`: every URL moves, from the preset's when the provider was saved with none, and `address=` alone puts a local server back at its preset's), or the URLs themselves (`url=`, `anthropic=`, `responses=`). `AtAddress` replaces only each URL's scheme, host and port, each API keeping its path; `AddressOf` is the address an editor starts from. The window sends the URLs moved only when the address was changed, so a Save doesn't move URLs set apart (another app's import). A provider of the user's own (no preset) has `w` in the TUI too: each base URL it has is asked in turn, typed in as it is, Enter alone keeping one (`customURLsAsk`). | [`local_address.go`](../../internal/provider/local_address.go), [`providers_cli.go`](../../internal/cli/providers_cli.go) | | Protocol detection | Works out which of Chat, Responses, Anthropic Messages and Gemini generateContent a base URL speaks when a provider is added. Each is asked at the URL as it takes it (`DetectBase`); Gemini's at the `…/v1beta` beside a typed `…/v1` or bare host, a Gemini model from the list picked for it, with the key in `x-goog-api-key` (#1346). Each API is asked with a model that chats, if the list has one; an embedding or rerank model (`catalog.ServesOf`) is asked only on Chat's URL, at its `/embeddings` or `/rerank` with the smallest body and no extra body, as the gateway's `retrieve` asks it, and the other APIs say why they weren't asked (heatonz on Discord: a vendor of only those detected nothing, asked to chat; `TestDetectEmbeddingOnly`). A saved provider whose list has nothing to chat with tests on such a model (`testModel`, `TestTestEmbeddingOnly`), and its editor and the add form's Fetch models say the models need no pick (`retrieval` in the list's answer and the provider's JSON, `provider-retrieval-only.test.cjs`). A model's test (Test models, a model's right-click, `magpie provider test`) asks the account or key a request for it goes to: `provider.AccountsFor` and `provider.KeysFor` ([`route_accounts.go`](../../internal/provider/route_accounts.go)), which the gateway's `perKeyEvery` routes by too, its usage and spend caps aside (one the user lets serve it, `AccountModels`; whose own list or plan has it, `Account.Lists`, `PlanServing`, `Serving`; in the user's order, `AccountsOn`), so a pool whose accounts list different models (a newapi plugin's) asks the one whose list has it, and one every account is barred from isn't asked. The provider's Test picks each endpoint's model from every account's and asks it of the account that serves it (`routedTo`), and with keys the first key with a model of its own to test (`testWith`). The request log's row names the account asked (`loggedAs`; #4992, `TestModelTestAsksTheAccountThatServesIt`). Detection, endpoint tests and model tests share `probe`, which adds `anthropic-version` only for Anthropic Messages; OpenAI probes omit that default so a relay that refuses it can answer. A Chat or Responses URL typed without its version (CRS's `…/openai`, Cyrus_4433 on X: CRS serves `/openai/v1/chat/completions` and `/openai/responses`, and answers anything else 404 `Not Found`) that is answered 404 is asked once more under `/v1` (`missingV1`, not for an account, Azure, Bedrock or Vertex); answered there, the saved provider's URL takes the `/v1` (`setV1`), the result carries it (`Result.V1`), Detect hands it on as the base, and the editor's URL field follows (`draft.onV1`), so Save doesn't put it back. A model's own 404 at both stays a 404 and changes nothing. CRS lists at `/api/v1/models`, which `catalog.RelayOpenAIList` adds to an unversioned `…/openai` base's list URLs, and a list answered there adds `/v1` as `fixV1` does (`TestCRSOpenAIBaseTestsUnderV1`, `TestCRSOpenAIBaseListsAtAPI`, `TestCRSOpenAIBaseDetectsV1`, `TestModel404KeepsBase`, `provider-test-v1.test.cjs`). A model's test that the vendor turns away with its word that the model is served on another API (`catalog.WrongEndpoint`, the gateway's words) asks the next API the provider has a URL for, as the gateway's `usable` takes it (the model's picked or listed API, else each API it isn't named-only on), with a key that sees the model there (`keySeeing`); that API's answer is the model's, and with none left, or every one saying it, the first stays. As Codex the next API is asked with Codex's headers, as the gateway sends them on Responses and Chat; as Claude Code it isn't, since the gateway sends Claude Code's on Messages alone (#3766, `TestTestModelsMovesToTheAPIServingIt`, `TestTestModelsKeepsAModelOnItsAPI`, `TestTestModelsAsAClientMovesAsTheGatewayDoes`). User-supplied headers still apply through `Sign`. The editor asks with the form as it stands, before any Save (#1545): the URL, key and models typed (`picked`, else the saved picks, else the vendor list); a key not typed again is the saved provider's, or for an unsaved copy the copied one's (`copyOf`). The probe writes nothing and adds no provider, and the route stays behind `magpie web`'s key. An endpoint or model test fails fast and can be stopped (RIck on Discord: 测试模型 took long to fail and couldn't be cancelled): a probe on magpie's own client that has no connection in `connectWait` (10s) fails then (`connecting`, an httptrace `GotConn`), and a host that couldn't be reached (no connection, DNS, refused, a bad certificate) fails the run's other models at once (`withUnreached`, `TestTestModelsUnreachedHostFailsOnce`); a stream that breaks off before an answer is a failure. While a test runs its Test models and endpoints' Test read Stop, which aborts the window's request and posts `provider/teststop` with the test's `run`, ending the vendor's request on the server too (`testRuns` in [`providers.go`](../../internal/gui/providers.go), since WebView2 doesn't end the request when a fetch is aborted; `TestProviderTestStops`, `model-test-stop.test.cjs`). | [`detect.go`](../../internal/provider/detect.go), [`test.go`](../../internal/provider/test.go) | | A pasted curl command | A curl command from a vendor's docs pasted into a custom provider's Base URL or API key fills the editor in (@mark_li21 on X). `curlOf` reads it as a shell would (lines joined by `\`, cmd's `^` or PowerShell's backtick; `curl.exe`; quotes and escapes), and takes: the API its URL's endpoint names (`…/chat/completions` Chat, `…/messages` Anthropic Messages, `…/responses` Responses) with the base URL before it, spelled as that API wants it (`respellURL`: Anthropic at its root, `/v1` after a bare host); the key from `Authorization: Bearer`, `x-api-key` or `api-key`, unless it only stands for one (`$OPENAI_API_KEY`, `${X}`, `%X%`, ``, `YOUR_API_KEY`), when the key's box is left empty and focused; and the `model` of its JSON body, added to a new provider's models (a saved one's picks are left alone, since adding to none would narrow what it serves). A preset's editor takes only the key. A note (`editorError`, kind `note`) says what was taken, a placeholder like `{WorkspaceId}` left in the URL, and a URL with no known endpoint. Text that isn't a curl command pastes as before, several keys included. Tested on the docs' own examples (`fixtures/curl`). | [`app.js`](../../internal/gui/assets/app.js) (`curlOf`, `fromCurl`), [`provider-curl-paste.test.cjs`](../../internal/gui/tests/provider-curl-paste.test.cjs) | -| Saved proxies | `settings.Proxies` holds named proxies (`NamedProxy`: id, name, address, optional login), kept in Settings › Network. Wherever a proxy is chosen (global, plugin downloads, a provider, a key, a Claude account) the value is "" (inherit), `direct`, an address as typed, or `@` for a saved one (@tsingchao on X). Addresses as typed are untouched. `netproxy.Parse`, `Resolve`, `Redact`, `EnvWith` and `Dispatch` resolve an `@id` at the lowest layer, so an edit reaches every user at the next request; a Claude Code `settings.json` env is a snapshot and is rewritten after an edit (`provider.ProxyEdited`). An `@id` this computer lacks fails closed (`netproxy.DeadProxy`, the request error and the provider row say "Proxy missing: {name}", `provider.ProxyGone`); it never goes direct. The password is written to settings.json (0600) and never read back by the page, logged or put in `Settings` sync; the list rides with the providers part of a sync (`backup.Bundle.Proxies`, `settings.MergeProxies`, passwords only with keys). A proxy in use cannot be deleted (409). `TestSavedProxyChoice`, `TestDanglingProxyReferenceFailsClosed`, `TestSavedProxiesTravelWithProviders`, `saved-proxies.test.cjs`, `provider-proxy-missing.test.cjs`. | [`proxies.go`](../../internal/settings/proxies.go), [`netproxy.go`](../../internal/netproxy/netproxy.go), [`proxies.go`](../../internal/gui/proxies.go) | +| Saved proxies | `settings.Proxies` holds named proxies (`NamedProxy`: id, name, address, optional login), kept in Settings › Network. Wherever a proxy is chosen (global, plugin downloads, app updates, a provider, a key, a Claude account) the value is "" (inherit), `direct`, an address as typed, or `@` for a saved one (@tsingchao on X). Addresses as typed are untouched. App updates take a proxy of their own, Settings › Network › App updates (`settings.UpdateProxy`, `magpie settings set updateProxy `; moonlityu on X: models direct, updates through a proxy): "" follows the global proxy as before, a proxy given to one `magpie update --proxy` run comes first, and it covers the feed, the notes and the release's file (`updateProxy` in [`update.go`](../../internal/update/update.go); `TestUpdateTakesItsOwnProxy`, `settings-update-proxy.test.cjs`). Per-model proxies within one provider are not offered: a proxy belongs to a provider, an account or a key, and a model that needs the other route is a second provider on the same URL. `netproxy.Parse`, `Resolve`, `Redact`, `EnvWith` and `Dispatch` resolve an `@id` at the lowest layer, so an edit reaches every user at the next request; a Claude Code `settings.json` env is a snapshot and is rewritten after an edit (`provider.ProxyEdited`). An `@id` this computer lacks fails closed (`netproxy.DeadProxy`, the request error and the provider row say "Proxy missing: {name}", `provider.ProxyGone`); it never goes direct. The password is written to settings.json (0600) and never read back by the page, logged or put in `Settings` sync; the list rides with the providers part of a sync (`backup.Bundle.Proxies`, `settings.MergeProxies`, passwords only with keys). A proxy in use cannot be deleted (409). `TestSavedProxyChoice`, `TestDanglingProxyReferenceFailsClosed`, `TestSavedProxiesTravelWithProviders`, `saved-proxies.test.cjs`, `provider-proxy-missing.test.cjs`. | [`proxies.go`](../../internal/settings/proxies.go), [`netproxy.go`](../../internal/netproxy/netproxy.go), [`proxies.go`](../../internal/gui/proxies.go) | ## Remote magpie diff --git a/internal/backup/auto.go b/internal/backup/auto.go index 3c6e86cf9..356a78f50 100644 --- a/internal/backup/auto.go +++ b/internal/backup/auto.go @@ -406,6 +406,7 @@ func autoCollect(app string) (Bundle, error) { s := *b.Settings s.Proxy, s.ProxyCustom = "", "" s.PluginProxy, s.PluginProxyCustom = "", "" + s.UpdateProxy, s.UpdateProxyCustom = "", "" s.Proxies = nil b.Settings = &s } diff --git a/internal/backup/auto_test.go b/internal/backup/auto_test.go index bac7d6b98..507f03ff0 100644 --- a/internal/backup/auto_test.go +++ b/internal/backup/auto_test.go @@ -186,6 +186,7 @@ func TestAutoBackupHoldsNoSecrets(t *testing.T) { s := settings.Load() s.GitHubToken, s.LANKey, s.Proxy = "ghp_SYNTHETIC_PRIVATE_TOKEN", "lan-SYNTHETIC-KEY", "http://user:proxy-SYNTHETIC-pass@10.0.0.1:8080" s.PluginProxy = "socks5://user:plugin-SYNTHETIC-pass@10.0.0.2:1080" + s.UpdateProxy = "socks5://user:update-SYNTHETIC-pass@10.0.0.3:1080" if err := settings.Save(s); err != nil { t.Fatal(err) } @@ -218,6 +219,7 @@ func TestAutoBackupHoldsNoSecrets(t *testing.T) { ws := *want.Settings ws.Proxy, ws.ProxyCustom = "", "" ws.PluginProxy, ws.PluginProxyCustom = "", "" + ws.UpdateProxy, ws.UpdateProxyCustom = "", "" want.Settings, want.Created, want.App = &ws, time.Time{}, "" raw, _ := json.Marshal(want) var wantBack Bundle diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 0c69aec59..3349dfd65 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -2089,7 +2089,6 @@ function appRestart(a) { return go; } -// Air's own Codex and Claude Agent: the IDE plugin's run this computer's codex and claude, the app's never go through magpie (jumy_18634) const AIR_KINDS = new Set(["air", "air-ide"]); function airSaid(a, line) { const warn = (s) => { const w = line(el("span", "ag-dot"), el("span", "", s)); w.classList.add("ag-warn", "ag-air-own"); return w; }; @@ -6138,7 +6137,6 @@ function renderProviders(quiet) { key = el("span", "key " + (p.key.set ? (keyPill(p) === p.key.masked ? "on" : "on acct") : p.ready ? "free" : "none"), p.key.set ? keyPill(p) : p.ready ? t("no key") : t("needs a key")); key.title = p.key.set ? t("API key {masked}", { masked: p.key.masked }) : p.ready ? t("Local servers need no key") : t("Open the row and paste an API key"); } - // every pill is one width so the dots line up down the list; a label too long for it ends in "…" and is said whole on hover const label = key.textContent; key.textContent = ""; key.append(el("span", "", label)); @@ -8512,7 +8510,6 @@ function iconPicker(ed) { // spring, and closing folds it back into that (still there, re-rendered or // not); with nothing pressed it rises from a little below. const SPRING = CSS.supports?.("animation-timing-function", "linear(0, 1)") - // a damped spring (damping .8): 1.5% over, settled by the end of the duration it runs for (460 ms) ? "linear(0, 0.0203, 0.0723, 0.1448, 0.2292, 0.3188, 0.4086, 0.4951, 0.576, 0.6498, 0.7157, 0.7735, 0.8232, 0.8654, 0.9005, 0.9293, 0.9525, 0.9708, 0.9849, 0.9956, 1.0033, 1.0087, 1.0122, 1.0142, 1.015, 1.0151, 1.0146, 1.0136, 1.0124, 1.0111, 1.0097, 1.0084, 1.0071, 1.0059, 1.0049, 1.0039, 1.0031, 1.0024, 1.0018, 1.0013, 1)" : "cubic-bezier(.2, .9, .25, 1.02)"; const IOS_EASE = "cubic-bezier(.32, .72, 0, 1)"; @@ -9195,7 +9192,6 @@ function vertexRoot(u) { if (!u.includes("://")) u = "https://" + u; return u.replace(/\/v1(?:beta1)?$/, ""); } -// with a key (keyed) the project is optional: express mode asks at the global endpoint, and a base URL stands in for Google's host function vertexBase(v, keyed) { const project = (v?.project || "").trim().toLowerCase(), loc = (v?.location || "").trim().toLowerCase() || "global"; const root = keyed ? vertexRoot(v?.baseUrl) : ""; @@ -9908,7 +9904,6 @@ function drawEditor(p, presetID) { advIn.append(...field(t("Images"), itk, t("Off: an agent's images are sent inline on every turn."))); } - // a balance token of the vendor's own (AiHubMix), or a custom one's (balanceFix), its URL above (balSlot) let balFix = null, balSlot = null; if (custom) { balSlot = el("div", "bal-slot"); @@ -14438,7 +14433,6 @@ function to100(v) { return Math.max(0, Math.min(100, v)); } // quotaNoShare: no share was said (0 is one, absent is not, #3650), or the // window is a wallet's balance (#3950): its text or figure is all there is function quotaNoShare(w) { return !!w.text || w.used == null || w.balance != null; } -// spanBtn: a span as a button: a