ac4af582301a4e8a29245dbba767eba31334ddf9
8
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
c056b7c8c3 |
provider: a Responses provider's turns may go over the Responses WebSocket (#5781)
A provider the user added with an http(s) Responses address can now send its Responses turns over the Responses WebSocket that magpie already speaks to chatgpt.com (codexSocket), with `socket=auto|on|off`: - off, or absent: today's behaviour exactly. Provider.Via hides any socket value an outer context carried, so such a provider never dials. - auto: tries the socket, falls back to HTTP when the handshake is refused or the socket ends before the reply, and speaks HTTP to a host for 10 minutes once it refused the handshake (codexShun). - on: the same fallback, but never shuns; the socket is tried each turn. Provider.Via puts the provider's Responses host and path in the request's context (withSocket); codexSocket's gate is provider.SocketTurn, which takes a ChatGPT turn as before, or a POST to that host at <Responses>/responses. The rest is the ChatGPT leg's: the kept socket and its delta (codexKeepKey now also hashes the scheme, X-Api-Key and Api-Key), the error frames, 1009 handling. A provider's reply with no Content-Type is marked text/event-stream, since it is read as one. Routing, keys, limits, usage and masking are unchanged: only the transport under the request differs. Set with `magpie provider set <id> socket=auto|on|off` (refused on a provider with an account, no http(s) Responses address, or Vertex, TakesSocket), saved in providers.json as "socket", shown by `provider show`, and in the editor's Advanced as a WebSocket tick beside HTTP version (ticked saves auto, keeps a CLI's on, unticked saves off; shown only while the Responses address is http(s) and there is no account). docs/subsystems/providers-accounts.md describes it. app.js pays for its rows by three long comments cut to one line (renderMove, the vendors' status pages, header rows): the core's scripts are 478 bytes smaller than on |
||
|
|
ee91d86ea0 |
provider: a custom provider can be held to HTTP/1.1, and a TLS record error on HTTP/2 moves its host there
kepner_53726 (Discord, magpie 0.1.2926): a custom Anthropic provider at a
company intranet gateway failed 124 turns in 3 days mid-stream with "tls:
bad record MAC" / "received record with version eaf1", each a 200 with 0
output tokens, until a restart; a plain Go 1.26.8 client to the gateway held.
Cause: none found in magpie. The bytes are read by stdlib crypto/tls, and
every conn wrapper on the path only passes them through, so a record whose
MAC fails was mangled before it reached us: by the gateway or a box between
(the system proxy route, a TLS-inspecting middlebox). HTTP/2 meets it far
more than one-off clients do: one long-lived connection carries every
stream, plus magpie's health pings (netproxy.HTTP2Health), so a gateway
that interleaves its writes racily breaks it.
- Provider.HTTP1 ("HTTP version" row, "HTTP/1.1 only" tick, under the
editor's Advanced; shown for a provider of the user's own at an https://
address, the same set InsecureTLS takes). Via adds netproxy.WithHTTP1 for
its own base URLs' hosts; Dispatch sends those over its HTTP/1.1 copy.
Another host, and a request made for another provider (With), keep HTTP/2.
Save refuses it on a preset's; a save that leaves the key out keeps it.
- With no setting: a TLS record error read on an HTTP/2 reply (h2Watch) or
round trip marks the host:port, and Dispatch speaks HTTP/1.1 to it for 6
hours. Go's transport already drops the broken connection. Zero-config
default otherwise unchanged.
- Advanced opens by itself when the tick is set. No note under the row
(the core script budget, not raised).
Run (mote, at
|
||
|
|
9fa11784db |
provider: a provider's proxy and off switch are read from providers.json as parsed once
A live magpie's heap profile (v0.1.2404, 53 minutes) allocated 3.6 GB of its 33 GB in provider.load, a parse of the whole providers.json, mostly for one field of one provider: storedPicks (its proxy, 1.73 GB) and leftAlone (switched off or hidden, 1.24 GB), asked for each request and each background look, then customIDs, keptAs, loginSwitching and accountRemoved. These six only read, so they now go through storedFile: filememo's parse of the file, kept until its time or size changes (and its bytes, written in the last two seconds), and dropped by every write magpie makes (writePrivate's Forget). A file missing or not decoding goes the way load goes, to its last good generation. What load's other callers get is unchanged, as some of them edit what they read before a save. TestStoredParsedOnceUntilTheFileChanges: 30 providers of 100 models. storedPicks and leftAlone with the file unchanged take under 40 allocations (a parse is 3381); a provider switched off since is left alone at once; another process's edit of the same size is seen; a zeroed file still finds its providers. Broken by hand: storedFile parsing each time, red (3386 allocations); a broken file read as none, red. Run at this tree on mote: gofmt clean; go vet ./internal/provider on darwin, linux and windows; go test -count=1 -timeout 45m ./internal/provider (ok 116.0s) ./internal/gateway (ok 613.2s). |
||
|
|
3f4186fd8e |
providers: a provider you added can skip its own host's certificate check, nowhere else (#2383, fangzhengjin)
A vLLM on the LAN, an Ollama behind a self-signed certificate or a company CA can't be reached over https today. A custom provider now has "Don't check its certificate" (Certificate, in its editor, shown while an address is https), with a short risk note, in en/zh/zh-TW/ja/de. Scope, enforced in Go, not only in the GUI: - Only a provider the user added with their own base URL takes it (TakesInsecureTLS: no preset, no account, no Vertex, no subscription id). Save refuses it on anything else, and Via ignores a hand-set flag. - It reaches the hosts of the provider's own base URLs alone (netproxy.WithUncheckedTLS): a redirect elsewhere, a models/balance/ image URL on another host, and a nested request for another provider (With drops it) are still checked. - Every route: it is set in Provider.Via, which the gateway's attempt and forwardOnce (count_tokens too), List, Test, Detect, balance, draw, embeddings and video all go through. - The unchecked host gets its own cloned transport (the route key holds the flag), so the leave never reaches another request. An https:// proxy is refused for it, because its TLS would be dialled with the same config and go unchecked too; http:// and socks5:// proxies work. - The editor shows the saved value, Test/Detect/Fetch carry it before a save, and a save that omits it keeps it. Backup, export and WebDAV sync carry it (backup.Collect). Rewritten from fangzhengjin's fork 749e82a25 rather than applied: it had no Go-side limit to custom providers, set InsecureSkipVerify for every host the provider's requests reached (redirects, other hosts, nested requests) and for an https:// proxy's own certificate, never showed the flag back to the editor (the next save cleared it), and didn't carry it into Test/Detect/Fetch. Its transport cache key holding the flag is kept. Run in this worktree (-tags nogui -p 1, sandbox HOME): - go test -run 'TestUnchecked|TestWith|TestDispatch' ./internal/netproxy ok - go test -run 'TestInsecureTLS|TestVia|Proxy' ./internal/provider ok - go test -run TestInsecureTLS ./internal/gateway ok (chat, responses, anthropic, count_tokens, gemini against a self-signed server) - go test -run 'TestProviderSaveInsecureTLS|TestProviderSaveKeeps|Typed' ./internal/gui ok - go test ./internal/backup ok - GUI provider-insecure-tls.test.cjs: chromium 30/30, webkit 30/30 (en, zh, zh-TW, ja, de at 1100 and 420) - gofmt -l clean; go vet -tags nogui for darwin, linux, windows on netproxy, provider, gui, gateway, backup clean Broken by hand, each went red, then restored: - With not clearing the leave -> TestUncheckedTLSOnlyItsHost - the https:// proxy guard off -> TestUncheckedTLSStillChecksItsProxy - TakesInsecureTLS always true -> TestInsecureTLSNotForPresetsOrSubscriptions - Via not setting it -> TestInsecureTLSOwnProviderOnly and all 5 routes of TestInsecureTLSEveryRoute - backup field tagged json:"-" -> TestRoundTrip - save not keeping an omitted flag, providerInfo not showing it -> TestProviderSaveInsecureTLS - draftOf/asTyped not carrying it -> 2 of 3 GUI tests (en 1100 chromium) Not tried: a real vLLM or Ollama behind a self-signed certificate; the image, video, balance, embeddings and draw routes are covered through Via, not each by its own test. The full suite was not run. Co-authored-by: fangzhengjin <12680972+fangzhengjin@users.noreply.github.com> Full suite: SUITE_LINE |
||
|
|
3a53d06d99 |
provider, plugin: a subscription's sign-in goes through the proxy its account's requests use, not always the global one (#1663, demystify0137)
What changed: every sign-in started in magpie now leaves through the
account's own proxy (ProxyOfLogin: the account's, else the
subscription's, else the global one). Before, the sign-in's token
exchange and checks went through the global proxy while the account's
later refresh and usage calls went through its own (ViaLogin), so the
vendor saw one account come from two exits.
- signin.go: SignInOptions{Site, Proxy, User}, StartSignInWith; the flow
picks its proxy (pickProxy, validated with settings.CheckProxy) and
every request goes through s.via. Each built-in sign-in (Claude,
Codex/ChatGPT, Grok, Zed, WorkBuddy, Copilot, ZCode, Factory, MiMo,
Qoder, Command Code, Kiro) uses s.via; Claude Code's own login gets the
proxy as *_PROXY (netproxy.EnvWith).
- proxy.go keepSignInProxy: a proxy picked for the sign-in is kept as
the subscription's when the account is its only one, else as that
account's own entry. "" (global) is refused while the subscription has
a proxy and other accounts, since nothing could keep it.
- plugin host: authorize and callback run under via.run(proxy), so a
plugin's sign-in fetches go through the same proxy; plugins_cli.go
does the same for `magpie plugins login`. PluginAPIKey goes through Via.
- gui: POST /api/signin and /api/plugin-signin take proxy and user.
What was run:
- go test -tags nogui ./... (sandbox HOME), all packages ok.
- gofmt -l, GOOS=linux and GOOS=windows go vet -tags nogui on the
touched packages.
- Red without the change (each broken by hand, then restored):
TestSignInGoesThroughItsProxy, TestDeviceSignInGoesThroughItsProxy,
TestPluginSignInGoesThroughItsProxy, TestClaudeSignInGoesThroughItsProxy
(internal/provider) and TestPluginSignInProxy (internal/plugin) each
fail with the s.via / EnvWith / via.run / keepSignInProxy removed.
Not tried: a real vendor account through a real proxy. The browser's own
leg of an OAuth sign-in goes through the browser's network, not magpie's.
Devin's CLI probes still use the global proxy.
|
||
|
|
b6d88ce66e |
provider, gui: each of a provider's keys can go through a proxy of its own, as a subscription's accounts can (Beyfish_Wang on X: 不同 key 走不同的代理)
A provider of keys kept one proxy for all of them: Save dropped
AccountProxies for it. Now AccountProxies holds a key's proxy by its
KeyID, ProxyChoice reads it for the key a try uses (WithKey), and Save
keeps only the keys the provider still holds. The key editor's Proxy
row has a line per key (Provider's proxy | Direct | Custom), named as
the Accounts list names it, when the provider has two or more.
Run:
- go test ./internal/provider ./internal/gui ./internal/gateway: ok;
TestKeyProxy fails without the provider change ("kept map[]").
- account-proxy.test.cjs, Chromium + WebKit, en + zh: 16/16; the new
key cases fail without the app.js change. Also at 440px: 16/16.
- gui-ja, gui-de, i18n-keys, account-models, provider-many-keys,
provider-typed, provider-proxy: all pass.
- Built binary, `magpie serve` in a sandbox HOME, three keys, four
local proxies: k-1 (429) through its own proxy, k-2 (429) through its
own, k-3 through the provider's; the global proxy got nothing.
|
||
|
|
3dc8f00f06 | providers: each account of a subscription holding several can go through its own proxy — the provider's, none, or its own address (Discord, gakki: 是否可以为不同的codex账号设置不用的代理,现在是同一个供应商下使用相同的代理) — the per-provider proxy (#237) was one for all of Codex's signed-in accounts. A subscription's entry in providers.json now keeps accountProxies, by the account's name in lower case, each checked by settings.CheckProxy on save (ftp:// refused), addresses trimmed, accounts following the provider's proxy left out. Provider.ProxyChoice picks an account's own proxy, else the provider's, else the global one, so everything that already went through Provider.Via follows the account: gateway turns and fallback across accounts, usage and quota, token refresh, Codex's warm-up, reset and saved accounts' model lists, Claude's warm-up and the *_PROXY of Claude Code runs (ViaLogin / ProxyOfLogin), and Codex's own sign-in relayed as it came (ViaSignedIn). Extra accounts of Copilot, ZCode, Kiro and the like, made afresh without the provider's settings, now read them from providers.json, so they honour the provider's proxy too. A save without accountProxies keeps them; {} clears them. The provider editor, for a subscription with two or more accounts, lists each under the Proxy row: Provider's proxy | Direct | Custom, the address field's room kept so a pick moves nothing; Custom with no address is refused before anything is posted, its field focused without scrolling. en and zh together; no border stripes. Tested with internal/gateway/account_proxy_test.go in a sandbox HOME against fake proxies and a fake ChatGPT backend: three Codex accounts (own proxy, direct, following the provider) each reach the backend their own way in one turn and for usage; clearing an account's proxy sends it through the provider's, clearing the provider's through the global one, direct staying direct; ftp:// refused; TestClaudeAccountProxyEnv covers each Claude account's HTTPS_PROXY. Both fail with the per-account lookup off. account-proxy.test.cjs, Chromium and WebKit, en and zh (new), provider-proxy, click-scroll and old-webkit pass. go vet ./internal/..., go build -tags nogui (and GOOS=linux, GOOS=windows) and go test -tags nogui ./... pass. Not tried against a real proxy, real accounts or the real Wails window; Grok's per-account usage and Kiro's usage on a key still use the provider's proxy. | ||
|
|
125da38943 | providers: each provider, a signed-in account like Codex's among them, goes through its own proxy — the one in Settings, none, or its own address (#237 xosi: 目前似乎是全局设置代理的,codex和国模供应商无法单独区分设置代理) — magpie had one proxy, Settings' (or the environment's, or the system's), for every request it made, so Codex, which needs a proxy from China, and a vendor at home, which is slower or refused through one, couldn't both be right. A provider now has a proxy, "" (following the global one, as before and the default), "direct" (none, whatever Settings says) or an http://, https:// or socks5:// address (host:port meaning http), kept as proxy in providers.json only when set, and for an account provider in its picks entry beside its models. It is checked on save by the same rule Settings' proxy is (settings.CheckProxy, now shared), so ftp:// and the like are refused. netproxy.With puts a provider's choice on a request's context and netproxy.Func honours it; netproxy.Dispatch sends such a request through a clone of the transport kept for that proxy alone (at most 32, cleared past that), since a transport shares an HTTP/2 connection by host whatever proxy dialled it; loopback is never proxied. The gateway's client and http.DefaultClient go through Dispatch, and every request made on a provider's behalf carries its choice: the gateway's turns (attempt, forward, draw, decide, the Codex backend), and the model lists, balances, plan and subscription usage, tests, sign-in, Codex's warm-up and reset, while the Claude subscription's and warm-up's CLI runs get the account's proxy in their *_PROXY (netproxy.EnvWith). The provider editor, a key provider's and a signed-in account's alike, has a Proxy row after Fallback: Global proxy | Direct | Custom (全局代理 | 直连 | 自定义), the address field beside the options only for Custom, its room kept otherwise so a pick never changes the centred dialog's height and moves nothing, and a line under it saying what the pick does; Save posts proxy ("" , "direct" or the trimmed address), a save without it keeps the old one, and Custom with no address is refused before anything is posted ("Proxy: type its address, like http://127.0.0.1:7890"). No border stripes; en and zh strings together. Tested with a new internal/gateway/proxy_test.go in a sandbox HOME: with a global proxy set, provider A's turns and model list go through its own fake proxy, B's (direct) straight to the vendor, C's (following) through the global one, none through another, and A set back to following goes through the global one; ftp:// is refused (fails with With neutered). netproxy_test.go's TestWith covers Func, Dispatch's per-proxy transports and EnvWith. A new internal/gui/tests/provider-proxy.test.cjs in Chromium and WebKit, en and zh: a key provider opens on Global proxy with no address, Custom unfilled is refused and nothing posted, a padded socks5 address saved trimmed, Direct saved as "direct" and Global as ""; Codex's account opens on Custom with its address and saves Direct with its models; every pick leaves the option within 1px; no left border. go build -tags nogui (and GOOS=linux, GOOS=windows), go test -tags nogui ./..., provider-proxy, click-scroll, old-webkit, balance-fix and add-sheet pass (click-scroll's WebKit case failed once alongside the others and passes alone, twice). Not tried against a real proxy or the real Wails window. |