plugins: downloads take a proxy of their own, apart from the vendors' (JonahFu on X)
JonahFu on X: GitHub is unreachable without a proxy, while API requests may go direct, so plugin downloads' proxy should be set apart from the one model requests take. Before: plugin downloads already followed the global proxy (fetches through http.DefaultClient and netproxy.Func, bun add and git through netproxy.Env), so nothing ignored it; there was only no way to give them a different one. Now Settings › Network has a Plugin downloads row under Proxy: Same as above (the default, unset: downloads follow the global proxy as before), Direct, or Custom with its login, remembered as pluginProxyCustom as Proxy's Custom is. The CLI takes it as `magpie settings set pluginProxy <url|direct|"">`. It covers the plugins list and Discover's lists (fetchJSONFrom), a user's own npm registry (fetchRegistry), Bun's download (getURLFrom), bun add/update/remove and the git commands of GitHub-installed plugins (dlEnv). The plugin host (bun run) keeps the global proxy: its requests are the vendors'. Both fields belong to this computer (KeepOwn) and are left out of auto-backups, since a proxy URL may hold a password. Settings' Proxy row and the new one are drawn by one helper (proxyRow); the core's script budget is met by cutting the proxy rows' comments, no raise. Run (mote, through mote-run): gofmt -l clean; go vet of the touched packages (darwin), GOOS=linux -tags nogui ./..., GOOS=windows of the touched packages; go test -count=1 internal/settings, settingsapi, backup, netproxy, plugin, gui, cli all ok (gui after the comment cut; its first run had TestCoreScriptBudget 1,352 bytes over). GUI, chromium and webkit: settings-plugin-proxy (new, 5 languages x 2 widths), settings-proxy-remember, settings-proxy-auth, proxy-test, settings-sections, proxy-login-fields and the i18n files: 102 pass, 0 fail. plugin-proxy-page, proxy-own-wording, account-proxy, provider-proxy, routing-proxy, provider-many-keys-proxy and signin-proxy: 104 pass, 2 fail, both signin-proxy's "a subscription with no proxy offers the global one" at 380px in Chromium, red the same way on origin/mainb596da773(filed #5866). Again at this commit, rebased onb596da773: gofmt, the three go vets, the seven packages' go test (all ok, TestCoreScriptBudget included) and settings-plugin-proxy, -remember and -auth (50 pass, 0 fail). Broken by hand: fetchJSONFrom without netproxy.Downloads -> TestPluginDownloadsTakeTheirOwnProxy red (the list went direct and hit testenv's offline guard); bunCommand always taking env() -> red (bun add's HTTPS_PROXY ""); the GUI row saving key "proxy" -> settings-plugin-proxy 10 of 10 red in chromium. Not tried: a real install behind a real proxy with GitHub blocked; the Library's (skills, MCP) downloads and plugin icons (loaded by the webview through usemagpie.ai) still follow the global proxy; Windows.
This commit is contained in:
@@ -297,6 +297,8 @@ magpie downloads the Bun build for this machine (`bunTarget` in [`bun.go`](../..
|
||||
|
||||
A bun this machine can't run at all says so instead of its exit status (`wontLoad`, a `*BunUnstartableError`). Windows refuses to load Bun 1.3.14 and later before Windows 10 1809 and Windows Server 2019: they import kernel32's `CreatePseudoConsole`, which older Windows lacks, so the process ends with 0xc0000139 (STATUS_ENTRYPOINT_NOT_FOUND) before it runs (zgcwkj on Discord, a Windows service). A processor without an instruction Bun's x64 build uses (it targets SSE4.2) ends it with 0xc000001d on Windows and SIGILL elsewhere. `bun add`, `bun update` and the host's start (`whyDied`, `cantStart`) each wrap the exit in it. The message says which of the two it is and names `MAGPIE_BUN`. An install doesn't try the community repo's dist branch after it, because that `bun add` can't start either. The GUI's `fail` answers it with code `bun_unstartable`, `bunWhy` (`windows` or `cpu`) and `said`, the i18n.js key for it (`bunSaid` in api.go, kept there so app.js holds one line under its budget), which `api()` in app.js puts through `t()` in place of the English. `TestBunSaidIsTranslated` fails when a language lacks it. There is no fallback to an older Bun: the last one Windows Server 2016 loads, 1.3.13, is below `BunVersion`, and Bun's baseline assets are now the same binary. `TestWontLoadSaysWindowsOrCPU`, `TestInstallOnUnstartableBunSaysWhyAndSkipsDist` and `TestHostOnUnstartableBunSaysWhy` in [`bunload_test.go`](../../internal/plugin/bunload_test.go), `TestFailSaysBunUnstartable` in internal/gui and `plugin-bun-unstartable.test.cjs` (both engines, every language) cover these.
|
||||
|
||||
Plugin downloads can take a proxy of their own, Settings › Network › Plugin downloads (`settings.PluginProxy`, `magpie settings set pluginProxy <url|direct>`; JonahFu on X: GitHub reached only through a proxy, the vendors without). It covers the plugins list, npm's registry and a registry of the user's, GitHub, the dist branch and Bun's own download (`netproxy.Downloads` in `fetchJSONFrom`, `fetchRegistry` and `getURLFrom`), and `bun add`, `bun update`, `bun remove` and git (`dlEnv`, `netproxy.EnvDownloads`). Unset, it follows the global proxy, as every download did before. The host (`bun run`) keeps magpie's own: a plugin's requests to its vendor are API requests. `TestPluginDownloadsTakeTheirOwnProxy` holds both sides.
|
||||
|
||||
Bun takes only http:// and https:// proxies. A SOCKS5 one, such as a Mac's system SOCKS proxy, is given to every bun magpie starts as a loopback HTTP proxy in front of it (`netproxy.Bridge`): to the host through `hostEnv`, and to `bun add`, `bun update` and `bun remove` through `bunCommand` (`netproxy.EnvForBun`). Before, an install with only a SOCKS system proxy failed as `UnsupportedProxyProtocol` (#1409). An agent CLI that bun installed is updated through the bridge too (`updateEnv` in `internal/agent/cliupdate.go`). Claude Code, built with Bun, gets it for the Claude subscription's runs and sign-ins (`netproxy.EnvForBunWith`, #2651; see [Claude subscription bridge](claude-subscription-bridge.md)).
|
||||
|
||||
The host reads its proxy once, when it starts. When the proxy magpie would give a new host differs from the one the running host got (the system proxy set after magpie started, as at login before Clash is up, or Settings changed), the next call to the host replaces it (`proxyMoved` in [`host.go`](../../internal/plugin/host.go), looked at no more than every 15s, or every 2s while the host has no proxy: `proxyLookNone`, #1518). A call made for a read nobody asked for, while allowances are read only when asked (`netproxy.Held`), never reaches the host. Before this, a host started without a proxy kept none, so the Grok plugin's `grok models` couldn't renew its token and the account read as signed out after each restart (#1363).
|
||||
|
||||
@@ -398,13 +398,14 @@ func pruneAuto(dir, reason string, keep int, now time.Time) {
|
||||
}
|
||||
|
||||
// autoCollect is the setup as an export without keys holds it, and the
|
||||
// proxy taken out too: it may name a password, the file isn't sealed, and
|
||||
// proxies (plugin downloads' too) taken out: it may name a password, the file isn't sealed, and
|
||||
// a restore keeps this computer's own proxy (KeepOwn) anyway.
|
||||
func autoCollect(app string) (Bundle, error) {
|
||||
b, err := Collect(false, app)
|
||||
if err == nil && b.Settings != nil {
|
||||
s := *b.Settings
|
||||
s.Proxy, s.ProxyCustom = "", ""
|
||||
s.PluginProxy, s.PluginProxyCustom = "", ""
|
||||
b.Settings = &s
|
||||
}
|
||||
return b, err
|
||||
|
||||
@@ -179,12 +179,13 @@ func TestAutoBackupPrunes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// What a backup holds is what an export without keys holds, the proxy
|
||||
// left out too: nothing secret is in the file.
|
||||
// What a backup holds is what an export without keys holds, the proxies
|
||||
// (plugin downloads' too) left out: nothing secret is in the file.
|
||||
func TestAutoBackupHoldsNoSecrets(t *testing.T) {
|
||||
autoHome(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"
|
||||
if err := settings.Save(s); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -216,6 +217,7 @@ func TestAutoBackupHoldsNoSecrets(t *testing.T) {
|
||||
}
|
||||
ws := *want.Settings
|
||||
ws.Proxy, ws.ProxyCustom = "", ""
|
||||
ws.PluginProxy, ws.PluginProxyCustom = "", ""
|
||||
want.Settings, want.Created, want.App = &ws, time.Time{}, ""
|
||||
raw, _ := json.Marshal(want)
|
||||
var wantBack Bundle
|
||||
|
||||
+46
-40
@@ -20664,22 +20664,15 @@ const TRAY_TOTALS = [["usage:today", "Tokens and cost today"], ["usage:7d", "Tok
|
||||
// how often magpie checks for updates by itself, in minutes (settings.UpdateEveries)
|
||||
const UPDATE_EVERY = [30, 60, 360, 1440];
|
||||
|
||||
// renderProxy: magpie's own requests to vendors, and its update checks, follow the system proxy on
|
||||
// their own; this row says which one, and lets it be turned off or set. A provider, account or key
|
||||
// that names a proxy of its own (or Direct) keeps it whatever this says (netproxy.With), so the
|
||||
// line says it holds for those without one (#1832).
|
||||
let proxyCustom = false; // Custom picked, not saved yet
|
||||
// The login has fields of its own; the setting stays one address with it as
|
||||
// userinfo, split as Go's url.Parse does (last @, then first :).
|
||||
// renderProxy: the proxy for vendors with none of their own, and update checks (#1832); its
|
||||
// login in fields of its own, split as url.Parse does (last @, then first :).
|
||||
function proxyFields(value) {
|
||||
const [, scheme = "", auth, rest] = /^([a-z][\w+.-]*:\/\/)?([^/?#]*)(.*)$/is.exec((value || "").trim());
|
||||
const at = auth.lastIndexOf("@"), info = at < 0 ? "" : auth.slice(0, at), c = info.indexOf(":");
|
||||
const eu = c < 0 ? info : info.slice(0, c), ep = c < 0 ? "" : info.slice(c + 1);
|
||||
// non-UTF-8 escapes are kept as saved until edited
|
||||
const dec = (v) => { try { return decodeURIComponent(v); } catch { return v; } };
|
||||
return { address: scheme + auth.slice(at + 1) + rest, username: dec(eu), password: dec(ep), eu, ep };
|
||||
}
|
||||
// each typed part percent-encoded; one left as loaded keeps its escapes
|
||||
function proxyAddress(a, f, user, pass) {
|
||||
a = (a || "").trim();
|
||||
if (!a || !(user || pass)) return a;
|
||||
@@ -20687,9 +20680,7 @@ function proxyAddress(a, f, user, pass) {
|
||||
const [, scheme = "", rest] = /^([a-z][\w+.-]*:\/\/)?(.*)$/is.exec(a);
|
||||
return scheme + enc(user, f.username, f.eu) + (pass ? ":" + enc(pass, f.password, f.ep) : "") + "@" + rest;
|
||||
}
|
||||
// proxyLoginRow: a proxy login's fields for the proxy rows outside
|
||||
// Settings (#3382), split and joined as Settings' row does (proxyFields,
|
||||
// proxyAddress), so setURL gets the address Settings would save.
|
||||
// proxyLoginRow: Settings' login fields for other proxy rows (#3382)
|
||||
function proxyLoginRow(addr, setURL, changed) {
|
||||
const fields = {};
|
||||
const auth = el("div", "proxy-auth proxy-login");
|
||||
@@ -20723,12 +20714,10 @@ function proxyLoginRow(addr, setURL, changed) {
|
||||
return auth;
|
||||
}
|
||||
function proxyDisplay(value) {
|
||||
// Also mask an older backend's proxyNow, and environment/system proxies.
|
||||
return (value || "").replace(/^(\w+:\/\/)?[^/?#]*@/, "$1");
|
||||
}
|
||||
function renderProxy(s, keep) {
|
||||
const cur = !s.proxy ? "auto" : s.proxy === "direct" ? "off" : "custom";
|
||||
const mode = proxyCustom ? "custom" : cur;
|
||||
const sub = $("#proxySub");
|
||||
sub.textContent = {
|
||||
settings: t("Requests to vendors without a proxy of their own, and update checks, go through {proxy}", { proxy: proxyDisplay(s.proxyNow) }),
|
||||
@@ -20737,22 +20726,46 @@ function renderProxy(s, keep) {
|
||||
off: t("Off: requests to vendors without a proxy of their own, and update checks, go direct"),
|
||||
none: t("No system proxy found; requests to vendors without a proxy of their own, and update checks, go direct"),
|
||||
}[s.proxySource] || "";
|
||||
const box = $("#proxySegs");
|
||||
const row = proxyRow(s, keep, {
|
||||
key: "proxy", box: $("#proxySegs"), cur, state: proxyState,
|
||||
modes: [["auto", t("Auto")], ["off", t("Off")], ["custom", t("Custom")]],
|
||||
again: () => renderProxy(s, keep),
|
||||
});
|
||||
renderProxyCheck(s, row);
|
||||
renderPluginProxy(s, keep);
|
||||
}
|
||||
const proxyState = { custom: false };
|
||||
// plugin downloads' proxy (JonahFu on X); plugins' vendor requests follow the one above
|
||||
const pluginProxyState = { custom: false };
|
||||
function renderPluginProxy(s, keep) {
|
||||
const v = (s.pluginProxy || "").trim();
|
||||
const cur = !v ? "auto" : v === "direct" ? "off" : "custom";
|
||||
$("#pluginProxySub").textContent = cur === "auto" ? t("Plugins, npm and GitHub go through the proxy above")
|
||||
: cur === "off" ? t("Plugins, npm and GitHub go direct") : t("Plugins, npm and GitHub go through {proxy}", { proxy: proxyDisplay(v) });
|
||||
proxyRow(s, keep, {
|
||||
key: "pluginProxy", box: $("#pluginProxySegs"), cur, state: pluginProxyState,
|
||||
modes: [["auto", t("Same as above")], ["off", t("Direct")], ["custom", t("Custom")]],
|
||||
again: () => renderPluginProxy(s, keep),
|
||||
});
|
||||
}
|
||||
// proxyRow: o.key's modes, and Custom's address and login; o.state.custom is Custom not saved yet.
|
||||
function proxyRow(s, keep, o) {
|
||||
const mode = o.state.custom ? "custom" : o.cur;
|
||||
const box = o.box;
|
||||
box.replaceChildren();
|
||||
const row = el("div", "proxy-controls");
|
||||
box.append(row);
|
||||
let picking = false;
|
||||
let saveOnLeave = null;
|
||||
const pick = (id) => {
|
||||
proxyCustom = id === "custom";
|
||||
if (id === "auto") savePrefs({ ...keep, proxy: "" });
|
||||
else if (id === "off") savePrefs({ ...keep, proxy: "direct" });
|
||||
else renderProxy(s, keep);
|
||||
o.state.custom = id === "custom";
|
||||
if (id === "auto") savePrefs({ ...keep, [o.key]: "" });
|
||||
else if (id === "off") savePrefs({ ...keep, [o.key]: "direct" });
|
||||
else o.again();
|
||||
};
|
||||
if (mode === "custom") {
|
||||
// Custom picked again after Off or Auto: the last one saved, login and
|
||||
// all, which settings.Save keeps as proxyCustom (Zane on Discord)
|
||||
let fields = proxyFields(cur === "custom" ? s.proxy : s.proxyCustom || "");
|
||||
// Custom again: the last saved, s[o.key + "Custom"] (Zane on Discord)
|
||||
let fields = proxyFields(o.cur === "custom" ? s[o.key] : s[o.key + "Custom"] || "");
|
||||
const i = input(fields.address, "http://127.0.0.1:7890");
|
||||
i.className = "proxy";
|
||||
i.setAttribute("aria-label", t("Proxy address"));
|
||||
@@ -20763,7 +20776,6 @@ function renderProxy(s, keep) {
|
||||
field.className = "proxy-credential";
|
||||
field.setAttribute("aria-label", field.placeholder);
|
||||
}
|
||||
// a pasted login moves into the fields
|
||||
i.oninput = () => {
|
||||
const parsed = proxyFields(i.value);
|
||||
if (parsed.username || parsed.password) {
|
||||
@@ -20777,19 +20789,18 @@ function renderProxy(s, keep) {
|
||||
if (!i.value.trim() || saving) return;
|
||||
let v;
|
||||
try { v = proxyAddress(i.value, fields, username.value, password.value); } catch { return; }
|
||||
if (v === s.proxy) return;
|
||||
if (v === s[o.key]) return;
|
||||
saving = true;
|
||||
proxyCustom = false;
|
||||
savePrefs({ ...keep, proxy: v });
|
||||
o.state.custom = false;
|
||||
savePrefs({ ...keep, [o.key]: v });
|
||||
};
|
||||
// Moving between fields must not redraw the row with a partial login.
|
||||
// A mode click makes its own save and must not also save the old draft.
|
||||
// no save between fields, nor of the draft on a mode click
|
||||
saveOnLeave = (e) => {
|
||||
if (box.contains(e.relatedTarget)) return;
|
||||
queueMicrotask(() => { if (i.isConnected && !picking) save(); });
|
||||
};
|
||||
for (const field of [i, username, password]) {
|
||||
field.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") save(); else if (e.key === "Escape") { proxyCustom = false; renderProxy(s, keep); } };
|
||||
field.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") save(); else if (e.key === "Escape") { o.state.custom = false; o.again(); } };
|
||||
field.onfocus = () => { picking = false; };
|
||||
field.onblur = saveOnLeave;
|
||||
}
|
||||
@@ -20799,22 +20810,17 @@ function renderProxy(s, keep) {
|
||||
auth.append(username, password, apply);
|
||||
row.append(i);
|
||||
box.append(auth);
|
||||
if (proxyCustom) queueMicrotask(() => i.focus());
|
||||
if (o.state.custom) queueMicrotask(() => i.focus());
|
||||
}
|
||||
const modes = segs([["auto", t("Auto")], ["off", t("Off")], ["custom", t("Custom")]], mode, pick);
|
||||
// WebKit doesn't focus clicked buttons, so relatedTarget alone can't tell
|
||||
// a mode click from leaving the proxy editor.
|
||||
const modes = segs(o.modes, mode, pick);
|
||||
// WebKit doesn't focus clicked buttons
|
||||
modes.onpointerdown = () => { picking = true; };
|
||||
for (const button of modes.querySelectorAll("button")) button.onblur = saveOnLeave;
|
||||
row.append(modes);
|
||||
renderProxyCheck(s, row);
|
||||
return row;
|
||||
}
|
||||
|
||||
// renderProxyCheck: Test (#2076), whether magpie's requests leave by the
|
||||
// proxy: POST /api/proxy/check asks Cloudflare's trace through it and
|
||||
// direct, and the row says each exit. One exit both ways fails only when
|
||||
// the proxy didn't connect (a TUN or VPN gives one, #2369). Kept until the
|
||||
// proxy changes.
|
||||
// renderProxyCheck: Test (#2076), the exits through the proxy and direct; one both ways fails only if it didn't connect (#2369).
|
||||
let proxyCheck = null; // { key, busy, out, err }
|
||||
function renderProxyCheck(s, row) {
|
||||
const key = (s.proxySource || "") + "|" + (s.proxyNow || "");
|
||||
@@ -22664,7 +22670,7 @@ function dockChoice(s) {
|
||||
|
||||
// prefsKeep is what the settings page sends of s, all of it each time.
|
||||
function prefsKeep(s) {
|
||||
return { theme: s.theme, colorblind: !!s.colorblind, reduceMotion: !!s.reduceMotion, noBird: !!s.noBird, lang: s.lang, tray: s.tray, dock: !!s.dock, dockWindow: !!s.dockWindow, dockNever: !!s.dockNever, lightweight: s.lightweight, keepAwake: !!s.keepAwake, keepAwakeDisplay: !!s.keepAwakeDisplay, noWSLAgents: !!s.noWSLAgents, quitNoAsk: !!s.quitNoAsk, proxy: s.proxy || "",
|
||||
return { theme: s.theme, colorblind: !!s.colorblind, reduceMotion: !!s.reduceMotion, noBird: !!s.noBird, lang: s.lang, tray: s.tray, dock: !!s.dock, dockWindow: !!s.dockWindow, dockNever: !!s.dockNever, lightweight: s.lightweight, keepAwake: !!s.keepAwake, keepAwakeDisplay: !!s.keepAwakeDisplay, noWSLAgents: !!s.noWSLAgents, quitNoAsk: !!s.quitNoAsk, proxy: s.proxy || "", pluginProxy: s.pluginProxy || "",
|
||||
sessionTerminal: s.sessionTerminal || "",
|
||||
uiFont: s.uiFont || null, codeFont: s.codeFont || null,
|
||||
otel: s.otel || {},
|
||||
|
||||
@@ -1124,6 +1124,11 @@ const I18N = {
|
||||
"Password (optional)": "密码(可选)",
|
||||
"Requests to vendors without a proxy of their own, and update checks, go through {proxy}": "未单独设置代理的模型厂商请求和检查更新都经由 {proxy}",
|
||||
"Following the system proxy, {proxy}": "跟随系统代理:{proxy}",
|
||||
"Plugin downloads": "插件下载",
|
||||
"Same as above": "同上",
|
||||
"Plugins, npm and GitHub go through the proxy above": "插件、npm 和 GitHub 走上面的代理",
|
||||
"Plugins, npm and GitHub go direct": "插件、npm 和 GitHub 直连",
|
||||
"Plugins, npm and GitHub go through {proxy}": "插件、npm 和 GitHub 走 {proxy}",
|
||||
"Following HTTPS_PROXY, {proxy}": "跟随 HTTPS_PROXY:{proxy}",
|
||||
"Ask Cloudflare through the proxy and direct, and compare the addresses the two leave from": "通过代理和直连各请求一次 Cloudflare,比较两者的出口地址",
|
||||
"The test couldn't run: {error}": "无法测试:{error}",
|
||||
@@ -5967,6 +5972,11 @@ const I18N = {
|
||||
"Password (optional)": "密碼(選填)",
|
||||
"Requests to vendors without a proxy of their own, and update checks, go through {proxy}": "未單獨設定代理的模型廠商請求和檢查更新都經由 {proxy}",
|
||||
"Following the system proxy, {proxy}": "跟隨系統代理:{proxy}",
|
||||
"Plugin downloads": "外掛下載",
|
||||
"Same as above": "同上",
|
||||
"Plugins, npm and GitHub go through the proxy above": "外掛、npm 和 GitHub 走上面的代理",
|
||||
"Plugins, npm and GitHub go direct": "外掛、npm 和 GitHub 直連",
|
||||
"Plugins, npm and GitHub go through {proxy}": "外掛、npm 和 GitHub 走 {proxy}",
|
||||
"Following HTTPS_PROXY, {proxy}": "跟隨 HTTPS_PROXY:{proxy}",
|
||||
"Ask Cloudflare through the proxy and direct, and compare the addresses the two leave from": "透過代理和直連各請求一次 Cloudflare,比較兩者的出口位址",
|
||||
"The test couldn't run: {error}": "無法測試:{error}",
|
||||
@@ -10781,6 +10791,11 @@ const I18N = {
|
||||
"Password (optional)": "パスワード(任意)",
|
||||
"Requests to vendors without a proxy of their own, and update checks, go through {proxy}": "独自のプロキシを設定していないベンダーへのリクエストとアップデート確認は {proxy} を経由します",
|
||||
"Following the system proxy, {proxy}": "システムプロキシに従う:{proxy}",
|
||||
"Plugin downloads": "プラグインのダウンロード",
|
||||
"Same as above": "上と同じ",
|
||||
"Plugins, npm and GitHub go through the proxy above": "プラグイン、npm、GitHub は上のプロキシを使います",
|
||||
"Plugins, npm and GitHub go direct": "プラグイン、npm、GitHub は直接接続します",
|
||||
"Plugins, npm and GitHub go through {proxy}": "プラグイン、npm、GitHub は {proxy} を使います",
|
||||
"Following HTTPS_PROXY, {proxy}": "HTTPS_PROXY に従う:{proxy}",
|
||||
"Ask Cloudflare through the proxy and direct, and compare the addresses the two leave from": "プロキシ経由と直接で Cloudflare に 1 回ずつ問い合わせ、出口のアドレスを比べます",
|
||||
"The test couldn't run: {error}": "テストできません:{error}",
|
||||
@@ -15610,6 +15625,11 @@ const I18N = {
|
||||
"Password (optional)": "Passwort (optional)",
|
||||
"Requests to vendors without a proxy of their own, and update checks, go through {proxy}": "Anfragen an Anbieter ohne eigenen Proxy und Update-Prüfungen laufen über {proxy}",
|
||||
"Following the system proxy, {proxy}": "Folgt dem System-Proxy, {proxy}",
|
||||
"Plugin downloads": "Plugin-Downloads",
|
||||
"Same as above": "Wie oben",
|
||||
"Plugins, npm and GitHub go through the proxy above": "Plugins, npm und GitHub gehen über den Proxy oben",
|
||||
"Plugins, npm and GitHub go direct": "Plugins, npm und GitHub gehen direkt",
|
||||
"Plugins, npm and GitHub go through {proxy}": "Plugins, npm und GitHub gehen über {proxy}",
|
||||
"Following HTTPS_PROXY, {proxy}": "Folgt HTTPS_PROXY, {proxy}",
|
||||
"Ask Cloudflare through the proxy and direct, and compare the addresses the two leave from": "Fragt Cloudflare einmal über den Proxy und einmal direkt und vergleicht die Adressen, von denen beide ausgehen",
|
||||
"The test couldn't run: {error}": "Der Test konnte nicht laufen: {error}",
|
||||
|
||||
@@ -339,6 +339,10 @@
|
||||
<div class="who"><div class="name" data-t>Proxy</div><div class="sub" id="proxySub"></div></div>
|
||||
<div id="proxySegs" class="proxy-segs"></div>
|
||||
</div>
|
||||
<div class="row pref" id="pluginProxyRow">
|
||||
<div class="who"><div class="name" data-t>Plugin downloads</div><div class="sub" id="pluginProxySub"></div></div>
|
||||
<div id="pluginProxySegs" class="proxy-segs"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row-head"><span class="label">GitHub</span></div>
|
||||
<div class="list prefs" id="githubList"></div>
|
||||
|
||||
@@ -208,6 +208,7 @@ func TestSettingsSaveKeepsWhatItDoesNotSend(t *testing.T) {
|
||||
was.ClaudeRunsMost = 3
|
||||
was.RequestArchiveLocal, was.RequestArchiveLocalMB = true, 256
|
||||
was.ProxyCustom = "http://me:secret@proxy.example:8080"
|
||||
was.PluginProxyCustom = "http://me:secret@plugins.example:8080"
|
||||
was.PanelShortcut = "Ctrl+Alt+K"
|
||||
was.SearcherThen = []string{"fake/m1", "fake/m2"} // set in its own row
|
||||
was.RouterNote = "Los Angeles" // the Library's servers/hub-note
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// Plugin downloads' proxy (JonahFu on X: GitHub needs a proxy, the vendors
|
||||
// don't): Settings › Network has a row of its own under Proxy. Direct,
|
||||
// Custom with a login, and Same as above each save pluginProxy alone, the
|
||||
// global proxy as it was; Custom again brings back the last address, which
|
||||
// the server remembers as pluginProxyCustom.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
function server(lang, posts) {
|
||||
let cur = {
|
||||
theme: "light", lang, tray: "panel", currency: "usd", textSize: 100,
|
||||
proxy: "direct", proxyNow: "", proxySource: "off", pluginProxy: "",
|
||||
trayUsageEvery: 3, version: "test", dir: "/test", lanURLs: [],
|
||||
visionModels: [], imageGenModels: [], workbuddyCheckins: [],
|
||||
fx: { rate: 7.2, at: new Date().toISOString(), stale: false },
|
||||
};
|
||||
return async (route) => {
|
||||
const req = route.request(), url = new URL(req.url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = ${JSON.stringify({ lang, theme: "light", web: true })};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" }, fx: cur.fx });
|
||||
if (url.pathname === "/api/settings") {
|
||||
if (req.method() === "POST") {
|
||||
const body = req.postDataJSON();
|
||||
posts.push(body);
|
||||
// as settings.Save: the custom copy is the server's, set from the value
|
||||
const own = body.pluginProxy && body.pluginProxy !== "direct";
|
||||
cur = { ...cur, ...body, pluginProxyCustom: own ? body.pluginProxy : cur.pluginProxyCustom };
|
||||
}
|
||||
return json(cur);
|
||||
}
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
return route.fulfill({ body: await fs.readFile(file), contentType });
|
||||
};
|
||||
}
|
||||
|
||||
const labels = {
|
||||
en: { row: "Plugin downloads", same: "Same as above", direct: "Direct", custom: "Custom", user: "Username (optional)", pass: "Password (optional)", saved: "Saved" },
|
||||
zh: { row: "插件下载", same: "同上", direct: "直连", custom: "自定义", user: "用户名(可选)", pass: "密码(可选)", saved: "已保存" },
|
||||
"zh-TW": { row: "外掛下載", same: "同上", direct: "直連", custom: "自定義", user: "使用者名稱(選填)", pass: "密碼(選填)", saved: "已儲存" },
|
||||
ja: { row: "プラグインのダウンロード", same: "上と同じ", direct: "直接接続", custom: "カスタム", user: "ユーザー名(任意)", pass: "パスワード(任意)", saved: "保存しました" },
|
||||
de: { row: "Plugin-Downloads", same: "Wie oben", direct: "Direkt", custom: "Benutzerdefiniert", user: "Benutzername (optional)", pass: "Passwort (optional)", saved: "Gespeichert" },
|
||||
};
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of Object.keys(labels)) {
|
||||
const l = labels[lang];
|
||||
for (const width of [1100, 420]) {
|
||||
test(`${engine} ${lang} ${width}px: plugin downloads take a proxy of their own`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const context = await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" });
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(4000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const posts = [], errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", server(lang, posts));
|
||||
await page.goto("http://magpie.test/?view=settings&tab=network");
|
||||
const row = page.locator("#pluginProxyRow");
|
||||
await row.getByText(l.row, { exact: true }).waitFor();
|
||||
const box = page.locator("#pluginProxySegs");
|
||||
const mode = (name) => box.getByRole("button", { name, exact: true });
|
||||
const saved = async (action, want) => {
|
||||
const count = posts.length;
|
||||
const response = page.waitForResponse((r) => r.url().endsWith("/api/settings") && r.request().method() === "POST");
|
||||
await action();
|
||||
await response;
|
||||
await page.waitForFunction((word) => document.querySelector("#status")?.textContent.includes(word), l.saved);
|
||||
assert.equal(posts.length, count + 1, "save once");
|
||||
assert.equal(posts.at(-1).pluginProxy, want);
|
||||
assert.equal(posts.at(-1).proxy, "direct", "the global proxy stays as it was");
|
||||
assert(!("pluginProxyCustom" in posts.at(-1)), "the page sends the remembered proxy");
|
||||
};
|
||||
// its row starts on Same as above, Proxy's own on Off
|
||||
assert.equal(await mode(l.same).getAttribute("aria-pressed"), "true");
|
||||
assert.equal(await box.locator("input.proxy").count(), 0, "no address until Custom");
|
||||
|
||||
await mode(l.custom).click();
|
||||
const address = box.locator("input.proxy");
|
||||
await address.fill("http://127.0.0.1:7890");
|
||||
await box.getByRole("textbox", { name: l.user, exact: true }).fill("me");
|
||||
await box.getByLabel(l.pass, { exact: true }).fill("p@ss");
|
||||
await saved(() => box.getByLabel(l.pass, { exact: true }).press("Enter"), "http://me:p%40ss@127.0.0.1:7890");
|
||||
// the line under the name shows the address without the login
|
||||
const sub = await page.locator("#pluginProxySub").textContent();
|
||||
assert(sub.includes("127.0.0.1:7890") && !sub.includes("p%40ss"), sub);
|
||||
|
||||
await saved(() => mode(l.direct).click(), "direct");
|
||||
await mode(l.custom).click();
|
||||
assert.equal(await address.inputValue(), "http://127.0.0.1:7890", "Custom brings back the last address");
|
||||
await address.press("Escape");
|
||||
await saved(() => mode(l.same).click(), "");
|
||||
|
||||
// the global proxy row is drawn as before, its Test with it
|
||||
assert.equal(await page.locator("#proxySegs button.proxy-test").count(), 1);
|
||||
assert.equal(await page.locator("#pluginProxySegs button.proxy-test").count(), 0);
|
||||
// nothing is wider than the page
|
||||
const over = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
|
||||
assert(over <= 0, `the page scrolls sideways by ${over}px`);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,6 +137,24 @@ func With(ctx context.Context, choice string) context.Context {
|
||||
return ctx
|
||||
}
|
||||
|
||||
// Downloads is ctx for magpie's downloads of plugins — the plugins list,
|
||||
// npm's registry, GitHub, the plugins repo's dist branch, Bun itself —
|
||||
// which go through the proxy Settings sets for them (PluginProxy) when it
|
||||
// names one (JonahFu on X: GitHub reached only through a proxy, the
|
||||
// vendors without). Its "" leaves ctx as it is, so they follow the
|
||||
// global proxy as every other request does.
|
||||
func Downloads(ctx context.Context) context.Context {
|
||||
if c := strings.TrimSpace(settings.Load().PluginProxy); c != "" {
|
||||
return With(ctx, c)
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
// EnvDownloads is Env for a program magpie starts to download plugins
|
||||
// (bun add and update, git): plugin downloads' proxy (Downloads), or,
|
||||
// when that names none, Env's.
|
||||
func EnvDownloads(env []string) []string { return EnvWith(settings.Load().PluginProxy, env) }
|
||||
|
||||
// Choice is the proxy ctx names (With), "" when it names none — for a CLI
|
||||
// run on a provider's behalf, whose *_PROXY is set from it (EnvWith).
|
||||
func Choice(ctx context.Context) string { return choiceOf(ctx) }
|
||||
|
||||
@@ -347,6 +347,7 @@ func getURLOfficial(ctx context.Context, url string, limit int64) ([]byte, error
|
||||
// off (netproxy.AgainOverHTTP1): Bun's zip is tens of MB, which a proxy
|
||||
// that cuts HTTP/2 streams part way breaks on each try over HTTP/2.
|
||||
func getURLFrom(ctx context.Context, url string, limit int64, mirror bool) ([]byte, error) {
|
||||
ctx = netproxy.Downloads(ctx)
|
||||
var b []byte
|
||||
err := netproxy.AgainOverHTTP1(ctx, func(ctx context.Context) (err error) {
|
||||
b, err = getURLOnce(ctx, url, limit, mirror)
|
||||
@@ -402,7 +403,14 @@ func getURLOnce(ctx context.Context, url string, limit int64, mirror bool) (b []
|
||||
var bunCommand = func(ctx context.Context, bun, dir string, args ...string) *exec.Cmd {
|
||||
cmd := command(ctx, bun, args...)
|
||||
cmd.Dir = dir
|
||||
cmd.Env = append(netproxy.EnvForBun(env()), "BUN_INSTALL_CACHE_DIR="+installCacheDir())
|
||||
// bun run is the host, whose requests are the plugins' own to their
|
||||
// vendors: magpie's proxy. Every other command downloads plugins, and
|
||||
// takes plugin downloads' proxy (dlEnv).
|
||||
e := dlEnv()
|
||||
if len(args) > 0 && args[0] == "run" {
|
||||
e = env()
|
||||
}
|
||||
cmd.Env = append(netproxy.EnvForBun(e), "BUN_INSTALL_CACHE_DIR="+installCacheDir())
|
||||
cmd.Env = append(cmd.Env, caEnv(cmd.Env, dir)...)
|
||||
cmd.Env = append(cmd.Env, registryEnv(cmd.Env)...)
|
||||
return cmd
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/netproxy"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
"github.com/yetone/magpie/internal/source"
|
||||
)
|
||||
|
||||
// JonahFu on X: GitHub is reached only through a proxy, the vendors
|
||||
// without one. Plugin downloads (the list, npm's registry, GitHub, the
|
||||
// dist branch, Bun, bun add and git) go through the proxy Settings sets for
|
||||
// them, while the host — the plugins' requests to their vendors — keeps
|
||||
// magpie's own. Left unset, downloads follow the global proxy as before.
|
||||
func TestPluginDownloadsTakeTheirOwnProxy(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
t.Setenv("HOME", dir)
|
||||
t.Setenv("USERPROFILE", dir)
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(dir, "config"))
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(dir, "cache"))
|
||||
for _, k := range []string{"HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy", "ALL_PROXY", "all_proxy", "NO_PROXY", "no_proxy"} {
|
||||
t.Setenv(k, "")
|
||||
}
|
||||
|
||||
// a proxy: it answers every request sent through it, and keeps the
|
||||
// address each asked for
|
||||
var mu sync.Mutex
|
||||
var asked []string
|
||||
proxy := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
mu.Lock()
|
||||
asked = append(asked, r.URL.String())
|
||||
mu.Unlock()
|
||||
fmt.Fprint(w, `{"ok":true}`)
|
||||
}))
|
||||
t.Cleanup(proxy.Close)
|
||||
seen := func() []string {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
return slices.Clone(asked)
|
||||
}
|
||||
|
||||
// magpie's own transport, as the app installs it, put back after
|
||||
tr := http.DefaultTransport.(*http.Transport)
|
||||
wasProxy, wasClient := tr.Proxy, http.DefaultClient.Transport
|
||||
t.Cleanup(func() { tr.Proxy, http.DefaultClient.Transport = wasProxy, wasClient })
|
||||
netproxy.Install()
|
||||
|
||||
// API requests direct, plugin downloads through the proxy
|
||||
if err := settings.Save(settings.Settings{Proxy: "direct", PluginProxy: proxy.URL}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx := context.Background()
|
||||
const list = "http://plugins.example.invalid/registry.json"
|
||||
if b, err := fetchJSONFrom(ctx, list, 1<<10, source.DoOfficial); err != nil || !strings.Contains(string(b), "ok") {
|
||||
t.Fatalf("the plugins list through plugin downloads' proxy: %q %v", b, err)
|
||||
}
|
||||
const reg = "http://npm.example.invalid/@me%2fx"
|
||||
if b, err := fetchRegistry(ctx, reg, "tok", 1<<10); err != nil || !strings.Contains(string(b), "ok") {
|
||||
t.Fatalf("a registry of the user's through plugin downloads' proxy: %q %v", b, err)
|
||||
}
|
||||
const bunZip = "http://github.example.invalid/bun.zip"
|
||||
if b, err := getURLOfficial(ctx, bunZip, 1<<10); err != nil || !strings.Contains(string(b), "ok") {
|
||||
t.Fatalf("Bun's download through plugin downloads' proxy: %q %v", b, err)
|
||||
}
|
||||
if got := seen(); !slices.Contains(got, list) || !slices.Contains(got, reg) || !slices.Contains(got, bunZip) {
|
||||
t.Fatalf("the proxy was asked %v", got)
|
||||
}
|
||||
|
||||
// bun add and git get the proxy; the host (bun run) doesn't
|
||||
proxyOf := func(env []string) string {
|
||||
for _, e := range env {
|
||||
if v, ok := strings.CutPrefix(e, "HTTPS_PROXY="); ok {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
if p := proxyOf(bunCommand(ctx, "bun", dir, "add", "--ignore-scripts", "x").Env); p != proxy.URL {
|
||||
t.Fatalf("bun add's HTTPS_PROXY %q, want %q", p, proxy.URL)
|
||||
}
|
||||
if p := proxyOf(dlEnv()); p != proxy.URL {
|
||||
t.Fatalf("git's HTTPS_PROXY %q, want %q", p, proxy.URL)
|
||||
}
|
||||
if p := proxyOf(bunCommand(ctx, "bun", dir, "run", "host.js").Env); p != "" {
|
||||
t.Fatalf("the host, whose requests are API requests, got plugin downloads' proxy %q", p)
|
||||
}
|
||||
|
||||
// plugin downloads direct, API requests through the proxy: the host
|
||||
// keeps the proxy, and a download goes around it
|
||||
if err := settings.Save(settings.Settings{Proxy: proxy.URL, PluginProxy: "direct"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if p := proxyOf(bunCommand(ctx, "bun", dir, "run", "host.js").Env); p != proxy.URL {
|
||||
t.Fatalf("the host's HTTPS_PROXY %q, want magpie's %q", p, proxy.URL)
|
||||
}
|
||||
if p := proxyOf(bunCommand(ctx, "bun", dir, "add", "x").Env); p != "" {
|
||||
t.Fatalf("bun add went through %q with plugin downloads set direct", p)
|
||||
}
|
||||
n := len(seen())
|
||||
if _, err := fetchJSONFrom(ctx, "http://other.example.invalid/registry.json", 1<<10, source.DoOfficial); err == nil {
|
||||
t.Fatal("a download set direct was answered")
|
||||
}
|
||||
if len(seen()) != n {
|
||||
t.Fatalf("a download set direct went through the proxy: %v", seen())
|
||||
}
|
||||
|
||||
// unset, downloads follow the global proxy, as they always did
|
||||
if err := settings.Save(settings.Settings{Proxy: proxy.URL}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
const later = "http://plugins.example.invalid/later.json"
|
||||
if _, err := fetchJSONFrom(ctx, later, 1<<10, source.DoOfficial); err != nil || !slices.Contains(seen(), later) {
|
||||
t.Fatalf("an unset plugin downloads' proxy didn't follow the global one: %v %v", err, seen())
|
||||
}
|
||||
if p := proxyOf(bunCommand(ctx, "bun", dir, "add", "x").Env); p != proxy.URL {
|
||||
t.Fatalf("bun add's HTTPS_PROXY %q, want the global %q", p, proxy.URL)
|
||||
}
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func refreshGitCache(ctx context.Context, spec string) error {
|
||||
}
|
||||
fctx, cancel := context.WithTimeout(ctx, fetchEach)
|
||||
cmd := command(fctx, "git", "-C", dir, "fetch", "--quiet", "origin", "+refs/heads/*:refs/heads/*", "+refs/tags/*:refs/tags/*")
|
||||
cmd.Env = append(env(), "GIT_TERMINAL_PROMPT=0", "GIT_SSH_COMMAND=ssh -o BatchMode=yes")
|
||||
cmd.Env = append(dlEnv(), "GIT_TERMINAL_PROMPT=0", "GIT_SSH_COMMAND=ssh -o BatchMode=yes")
|
||||
out, err := cmd.CombinedOutput()
|
||||
cancel()
|
||||
if err != nil {
|
||||
@@ -279,7 +279,7 @@ func lsRemote(ctx context.Context, remote, ref string) (string, error) {
|
||||
args = append(args, "refs/heads/"+ref, "refs/tags/"+ref, "refs/tags/"+ref+"^{}")
|
||||
}
|
||||
cmd := command(ctx, "git", args...)
|
||||
cmd.Env = append(env(), "GIT_TERMINAL_PROMPT=0", "GIT_SSH_COMMAND=ssh -o BatchMode=yes")
|
||||
cmd.Env = append(dlEnv(), "GIT_TERMINAL_PROMPT=0", "GIT_SSH_COMMAND=ssh -o BatchMode=yes")
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("git ls-remote %s: %w", remote, err)
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/filememo"
|
||||
"github.com/yetone/magpie/internal/ghtoken"
|
||||
"github.com/yetone/magpie/internal/netproxy"
|
||||
"github.com/yetone/magpie/internal/source"
|
||||
"github.com/yetone/magpie/internal/update"
|
||||
)
|
||||
@@ -284,6 +285,8 @@ func fetchJSONFaithful(ctx context.Context, u string, limit int64) ([]byte, erro
|
||||
}
|
||||
|
||||
func fetchJSONFrom(ctx context.Context, u string, limit int64, do func(*http.Client, *http.Request) (*http.Response, error)) ([]byte, error) {
|
||||
// through plugin downloads' proxy, where Settings sets one
|
||||
ctx = netproxy.Downloads(ctx)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", u, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
toml "github.com/pelletier/go-toml/v2"
|
||||
|
||||
"github.com/yetone/magpie/internal/netproxy"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
"github.com/yetone/magpie/internal/source"
|
||||
@@ -314,6 +315,7 @@ func fetchNPM(ctx context.Context, name, suffix string, limit int64) ([]byte, er
|
||||
// fetchRegistry gets u from a registry of the user's, with its token; the
|
||||
// token never goes to any other address (a mirror, a redirect elsewhere).
|
||||
func fetchRegistry(ctx context.Context, u, token string, limit int64) ([]byte, error) {
|
||||
ctx = netproxy.Downloads(ctx) // plugin downloads' proxy
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", u, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -1015,6 +1015,11 @@ func command(ctx context.Context, name string, args ...string) *exec.Cmd {
|
||||
// env is the plugins' environment: magpie's, with its proxy.
|
||||
func env() []string { return netproxy.Env(os.Environ()) }
|
||||
|
||||
// dlEnv is env for a program that downloads plugins (bun add, update and
|
||||
// remove, git): plugin downloads' proxy where Settings sets one
|
||||
// (netproxy.EnvDownloads), never the one a plugin's requests take.
|
||||
func dlEnv() []string { return netproxy.EnvDownloads(os.Environ()) }
|
||||
|
||||
// Version is the version of the package spec installed (or checked out
|
||||
// at its path), "" when there is none.
|
||||
func Version(spec string) string {
|
||||
|
||||
@@ -16,3 +16,41 @@ func TestProxyCustomOwn(t *testing.T) {
|
||||
t.Fatal("another computer's proxy login taken here")
|
||||
}
|
||||
}
|
||||
|
||||
// Plugin downloads' proxy, and the one remembered for its Custom, are
|
||||
// this computer's own as the proxy is.
|
||||
func TestPluginProxyOwn(t *testing.T) {
|
||||
from := Settings{Theme: "dark", PluginProxy: "socks5://a:b@there:1080", PluginProxyCustom: "socks5://a:b@there:1080"}
|
||||
from.KeepOwn(Settings{PluginProxy: "direct", PluginProxyCustom: "http://c:d@here:8080"})
|
||||
if from.PluginProxy != "direct" || from.PluginProxyCustom != "http://c:d@here:8080" || from.Theme != "dark" {
|
||||
t.Fatalf("KeepOwn: %+v", from)
|
||||
}
|
||||
from.KeepOwn(Settings{})
|
||||
if from.PluginProxy != "" || from.PluginProxyCustom != "" {
|
||||
t.Fatal("another computer's plugin proxy taken here")
|
||||
}
|
||||
}
|
||||
|
||||
// Plugin downloads' proxy is checked as the proxy is, and the last of the
|
||||
// user's own is remembered for Custom while it follows or goes direct.
|
||||
func TestPluginProxySaved(t *testing.T) {
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
if err := Save(Settings{PluginProxy: " socks5://u:p@127.0.0.1:1080 "}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s := Load(); s.PluginProxy != "socks5://u:p@127.0.0.1:1080" || s.PluginProxyCustom != s.PluginProxy || s.Proxy != "" {
|
||||
t.Fatalf("%+v", s)
|
||||
}
|
||||
if err := Save(Settings{PluginProxy: "direct", PluginProxyCustom: Load().PluginProxyCustom}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s := Load(); s.PluginProxy != "direct" || s.PluginProxyCustom != "socks5://u:p@127.0.0.1:1080" {
|
||||
t.Fatalf("%+v", s)
|
||||
}
|
||||
if Save(Settings{PluginProxy: "ftp://x:21"}) == nil {
|
||||
t.Fatal("an ftp proxy accepted")
|
||||
}
|
||||
if Load().PluginProxy != "direct" {
|
||||
t.Fatal("a refused value overwrote the saved one")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,19 @@ type Settings struct {
|
||||
// Save sets it from Proxy, and it is stored as Proxy is. This
|
||||
// computer's own (KeepOwn), as Proxy is.
|
||||
ProxyCustom string `json:"proxyCustom,omitempty"`
|
||||
OTel OTel `json:"otel,omitempty"`
|
||||
// PluginProxy is the proxy magpie downloads plugins through: the
|
||||
// plugins list, npm's registry, GitHub, the plugins repo's dist
|
||||
// branch, Bun's own download, and bun add, update and git clone
|
||||
// (JonahFu on X: GitHub needs a proxy where the vendors don't). ""
|
||||
// follows Proxy, as every download did before; "direct" uses none;
|
||||
// anything else is the proxy, as Proxy takes it. A plugin's requests
|
||||
// to its vendor are API requests and follow Proxy (and the
|
||||
// provider's or account's own), never this. This computer's own
|
||||
// (KeepOwn), as Proxy is.
|
||||
PluginProxy string `json:"pluginProxy,omitempty"`
|
||||
// PluginProxyCustom is PluginProxy's ProxyCustom.
|
||||
PluginProxyCustom string `json:"pluginProxyCustom,omitempty"`
|
||||
OTel OTel `json:"otel,omitempty"`
|
||||
// GitHubToken is a GitHub token the library's requests to GitHub's
|
||||
// API carry, raising its rate limit from 60 requests an hour to 5,000.
|
||||
// It is a secret: the Settings page is told only a masked one, and a
|
||||
@@ -1462,7 +1474,7 @@ func (s Settings) Compact() int {
|
||||
|
||||
// KeepOwn puts back cur's settings that are this computer's own, which a
|
||||
// sync or a restored backup never brings from another: the window's size,
|
||||
// place and whether it was maximised, the proxy, the gateway's port, whether it
|
||||
// place and whether it was maximised, the proxy (and plugin downloads'), the gateway's port, whether it
|
||||
// is shared on the local network and the addresses let in to it, what
|
||||
// its MCP router says of itself, the Dock, gateway mode, whether WSL is
|
||||
// looked in, whether agents' sign-ins are read, when allowances are read, the terminal app a session resumes
|
||||
@@ -1478,6 +1490,7 @@ func (s *Settings) KeepOwn(cur Settings) {
|
||||
s.Window, s.Proxy, s.Port, s.Dock, s.DockWindow, s.Lightweight = cur.Window, cur.Proxy, cur.Port, cur.Dock, cur.DockWindow, cur.Lightweight
|
||||
s.DockNever, s.DockSettled = cur.DockNever, cur.DockSettled
|
||||
s.ProxyCustom = cur.ProxyCustom
|
||||
s.PluginProxy, s.PluginProxyCustom = cur.PluginProxy, cur.PluginProxyCustom
|
||||
s.WindowMaximised, s.KeepAwake, s.KeepAwakeDisplay = cur.WindowMaximised, cur.KeepAwake, cur.KeepAwakeDisplay
|
||||
s.WindowAt = cur.WindowAt
|
||||
s.TrayUsages, s.TrayUsage, s.TrayUsageEvery, s.TrayNoLogos, s.TrayNoBird, s.TrayPace, s.TrayNoCost = cur.TrayUsages, cur.TrayUsage, cur.TrayUsageEvery, cur.TrayNoLogos, cur.TrayNoBird, cur.TrayPace, cur.TrayNoCost
|
||||
@@ -2293,6 +2306,13 @@ func saveOwn(s Settings, recording, reads bool) error {
|
||||
if s.Proxy != "" && s.Proxy != "direct" {
|
||||
s.ProxyCustom = s.Proxy
|
||||
}
|
||||
s.PluginProxy = strings.TrimSpace(s.PluginProxy)
|
||||
if err := CheckProxy(s.PluginProxy); err != nil {
|
||||
return fmt.Errorf("plugin downloads: %w", err)
|
||||
}
|
||||
if s.PluginProxy != "" && s.PluginProxy != "direct" {
|
||||
s.PluginProxyCustom = s.PluginProxy
|
||||
}
|
||||
s.Vision = strings.TrimSpace(s.Vision)
|
||||
if s.Vision != "" && s.Vision != "off" && !strings.Contains(s.Vision, "/") {
|
||||
return fmt.Errorf("the vision model must be a model's id such as openai/gpt-5-mini, or off, not %q", s.Vision)
|
||||
|
||||
@@ -37,7 +37,7 @@ var Keys = []string{
|
||||
// usage and alerts
|
||||
"currency", "chineseUnits", "usageAlert", "balanceAlert", "resetReminder", "turnDoneAlert", "maskAlert",
|
||||
// network
|
||||
"proxy",
|
||||
"proxy", "pluginProxy",
|
||||
// privacy
|
||||
"redact", "redactPersonal", "redactKinds", "redactWords", "redactWordsAnyCase", "redactWordsWhole", "redactShape",
|
||||
"noStats", "noUsageStats", "otel",
|
||||
@@ -291,6 +291,7 @@ func Merge(body []byte, cur settings.Settings, web bool) (settings.Settings, err
|
||||
in.RouterAllTools = cur.RouterAllTools // set on its own (the Library's servers/hub-tools)
|
||||
in.GitHubToken = cur.GitHubToken // set on its own (github-token), never sent to the page
|
||||
in.ProxyCustom = cur.ProxyCustom // set by settings.Save from the proxy, never by the page
|
||||
in.PluginProxyCustom = cur.PluginProxyCustom // and plugin downloads' from theirs
|
||||
in.RequestArchive = cur.RequestArchive // the Gateway page's, set on its own
|
||||
in.RequestArchiveMaxMB = cur.RequestArchiveMaxMB // in settings.json only
|
||||
in.ClaudeRunsMost = cur.ClaudeRunsMost // magpie claude-code runs, or settings.json (#2956)
|
||||
|
||||
Reference in New Issue
Block a user