Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
gui: Settings' gateway rows move out of app.js to plugins/gateway/settings.js
yetonead3833512ef5
diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.jsindex 8f9a1d58e..f8b51d492 100644--- a/internal/gui/assets/app.js+++ b/internal/gui/assets/app.js@@ -22471,298 +22471,6 @@ function editRedactRule(r, n, row) {if (d.err) head.querySelector(".sub").classList.add("err");}-// renderPort: the gateway's address on this computer (Magic_zero on Discord:-// 3425 taken by another program, or one easier to tell apart). Only its-// port, 1024 up, is typed here; magpie moves its gateway there and every-// agent it connected with it, or says why it can't (another program has-// it). MAGPIE_ADDR, a whole host:port, comes first and the field shows it,-// off (Chicring on Discord: the row was titled a port while it showed one).-let portDraft = { value: null, err: "" };-// portSays is the gateway's word on a port it couldn't take, in the page's-// language: it says the port, so it is matched rather than looked up-function portSays(m) {- let x;- if ((x = /^port (\d+) is in use by another program/.exec(m))) return t("Port {p} is in use by another program: pick another one", { p: x[1] });- if ((x = /^another magpie serves the gateway at (\S+):/.exec(m))) return t("Another magpie serves the gateway at {url}: set its port there, or quit it first", { url: x[1] });- if (/from 1024 to 65535/.test(m)) return t("A port is a number from 1024 to 65535");- return t(m);-}-function renderPort(s) {- const box = $("#portList");- const r = el("div", "row pref port-row");- const who = el("div", "who");- who.append(el("div", "name", t("Gateway address")));- const sub = el("div", "sub");- const d = portDraft;- const now = s.addrEnv ? "" : String(s.port || 3425);- const field = input(d.value ?? now, "3425");- field.className = "words gateway-port";- field.inputMode = "numeric";- field.setAttribute("aria-label", t("Gateway address"));- const save = el("button", "text", t("Apply"));- if (s.addrEnv) {- field.value = s.addrEnv;- field.disabled = save.disabled = true;- sub.textContent = t("MAGPIE_ADDR={addr} sets the gateway’s whole address, host:port: unset it to set the port here", { addr: s.addrEnv });- } else if (d.err) {- sub.textContent = d.err;- sub.classList.add("err");- } else sub.textContent = t("Only the port is set here, 1024 to 65535; MAGPIE_ADDR=host:port sets the whole address instead. Agents magpie connected move with it. Now {url}", { url: s.gateway || "" });- who.append(sub);- save.onclick = () => {- const p = Number(field.value.trim());- if (!Number.isInteger(p) || p < 1024 || p > 65535) {- d.value = field.value; d.err = t("A port is a number from 1024 to 65535");- return renderPort(s);- }- if (p === (s.port || 3425)) { d.value = null; d.err = ""; return renderPort(s); }- save.disabled = true;- writingPrefs(api("settings/port", { port: p }).then((res) => res.settings && (prefs = res.settings, res)))- .then((res) => {- portDraft = { value: null, err: "" };- const n = res.port?.moved?.length || 0;- if (res.port?.error) status(res.port.error, "err");- else status(n ? t("Gateway on port {p}; {n} agents moved with it", { p, n }) : t("Gateway on port {p}", { p }), "ok", 2500);- // the sidebar's gateway line, and the list's address the pages- // copy, say where it is now, not the port before (noahhrreion on- // Discord: it kept the old one until Providers was opened)- if (res.settings?.gateway) renderSideGw({ ...sideGwAt, url: res.settings.gateway, running: true });- if (providers) loadProviders().catch(() => {});- renderSettings();- })- .catch((e) => { d.value = field.value; d.err = portSays(e.message); status(d.err, "err"); renderSettings(); });- };- field.oninput = () => { d.value = field.value; };- field.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") save.onclick(); if (e.key === "Escape") { portDraft = { value: null, err: "" }; renderPort(s); } };- const val = el("div", "val");- val.append(field, save);- r.append(who, val);- box.replaceChildren(r); // swapped whole: the list is never laid out empty-}--// renderBareIds: Model ids without the provider (settings.bareModelIDs,-// love1sbug on X, moving from CLIProxyAPI): the gateway's /v1/models-// lists each model by its own id as well, gpt-5.6-sol beside-// codex/gpt-5.6-sol. Posted on its own; off by default.-function renderBareIds(s) {- $("#bareIdsSegs").replaceChildren(segs([[false, t("Off")], [true, t("On")]], !!s.bareModelIDs, (on) =>- writingPrefs(api("settings/bare-ids", { on })).then((ns) => { prefs = state.settings = ns; renderSettings(); })- .catch((e) => { status(t(e.message), "err"); renderSettings(); })));-}--// renderCORS: the web pages whose scripts may call the gateway from a-// browser (#1051), by origin — a row to add one, and one row each to take-// it away. A page listed calls with a gateway key; none listed, no page-// can read what the gateway answers, as before.-let corsDraft = { value: "", err: "" };-// corsSays is the gateway's word on an origin it didn't take, in the-// page's language-function corsSays(m) {- if (/wildcard/.test(m)) return t("Name each origin: a wildcard would let every web page use magpie");- if (/is not an (extension's )?origin/.test(m)) return t("Write an origin as http://localhost:3000 or https://app.example.com, or a browser extension's as chrome-extension://, moz-extension:// or safari-web-extension:// followed by its ID");- return t(m);-}-function renderCORS(s) {- const box = $("#corsList");- box.replaceChildren();- const origins = s.corsOrigins || [];- const d = corsDraft;- const set = (next, done) => writingPrefs(api("settings/cors", { origins: next }))- .then((ns) => { prefs = ns; d.err = ""; done?.(); renderSettings(); status(t("Saved"), "ok", 1500); })- .catch((e) => { d.err = corsSays(e.message); status(d.err, "err"); renderSettings(); });- const field = input(d.value, "http://localhost:3000");- field.className = "words rule-match";- field.setAttribute("aria-label", t("Web page origin"));- field.autocomplete = "off";- field.spellcheck = false;- const add = el("button", "text", t("Add"));- add.onclick = () => {- d.value = field.value.trim();- if (!d.value) return field.focus();- set([...origins, d.value], () => { corsDraft = { value: "", err: "" }; });- };- field.oninput = () => { d.value = field.value; };- field.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") add.onclick(); };- const r = el("div", "row pref rule-row");- const who = el("div", "who");- who.append(el("div", "name", t("Web pages that may call magpie")),- el("div", "sub" + (d.err ? " err" : ""), d.err || t("Scripts on these origins can call the gateway from a browser, each request with a gateway key from Gateway. A page from any other site is refused; pages on this computer are not")));- const val = el("div", "val rule-add");- val.append(field, add);- r.append(who, val);- box.append(r);- for (const o of origins) {- const row = el("div", "row pref cors-origin"); // an extension's id runs long: wrapped, never cut- const w = el("div", "who");- w.append(el("div", "name", o));- const x = el("button", "text", t("Remove"));- x.onclick = () => set(origins.filter((v) => v !== o));- const v = el("div", "val");- v.append(x);- row.append(w, v);- box.append(row);- }-}--// renderAllow: the addresses other computers may reach magpie from at-// all (lc on Discord: magpie in Docker on a public host), as IPs and CIDR-// ranges, under Share on local network — a row to add one, and one row-// each to take it away. None listed lets every address in, with a gateway-// key, as before; this computer is always let in. MAGPIE_ALLOW_IPS, where-// set, is the list, shown and not edited here.-// A list that would shut out the page saving it names the address magpie-// sees the page from (Mathresearcher on Discord: which address?), and-// offers to add it to the list that was refused; behind Docker or a proxy-// that is the proxy's, not the user's computer's (gateway.peerAddr).-let allowDraft = { value: "", err: "", addr: "", tried: null };-function allowSays(m) {- if (/is not an IP address/.test(m)) return t("Write an address as 203.0.113.7, or a range as 10.0.0.0/8 or 2001:db8::/32");- const out = /shut out (\S+), the address/.exec(m);- if (out) return t("That list leaves out {addr}, the address magpie sees this page open from: add it first, or this page can’t reach magpie", { addr: out[1] });- if (/MAGPIE_ALLOW_IPS/.test(m)) return t("MAGPIE_ALLOW_IPS sets this list; change it there");- return t(m);-}-function renderAllow(s) {- const box = $("#allowList");- box.replaceChildren();- const env = s.allowIPsEnv || "";- if (!s.lan && !s.onNetwork && !env) return;- const list = env ? (s.allowIPsFromEnv || []) : (s.allowIPs || []);- const d = allowDraft;- const set = (next, done) => writingPrefs(api("settings/allowips", { ips: next }))- .then((ns) => { prefs = ns; d.err = d.addr = ""; d.tried = null; done?.(); renderSettings(); status(t("Saved"), "ok", 1500); })- .catch((e) => {- d.err = allowSays(e.message);- d.addr = /shut out (\S+), the address/.exec(e.message)?.[1] || "";- d.tried = d.addr ? { next, done } : null;- status(d.err, "err"); renderSettings();- });- const r = el("div", "row pref rule-row");- const who = el("div", "who");- const sub = d.err || (env ? t("Set by MAGPIE_ALLOW_IPS. Other computers reach magpie only from these addresses, even with a gateway key; this computer always can")- : t("Other computers reach magpie only from these addresses or ranges (CIDR), even with a gateway key; this computer always can. None listed lets every address in"));- who.append(el("div", "name", t("Allowed addresses")), el("div", "sub" + (d.err ? " err" : ""), sub));- // the address the refusal named, added to the list that was refused in- // one click- if (d.err && d.addr && d.tried && !env) {- const fix = el("button", "text allow-fix", t("Add {addr}", { addr: d.addr }));- fix.type = "button";- fix.title = t("Behind Docker or a reverse proxy, this is the proxy’s address, not your computer’s: adding it lets in everyone who comes through that proxy");- const { next, done } = d.tried;- fix.onclick = () => set([...next, d.addr], done);- who.append(fix);- }- r.append(who);- if (!env) {- const field = input(d.value, "203.0.113.7, 10.0.0.0/8");- field.className = "words rule-match allow-ip";- field.setAttribute("aria-label", t("IP address or range"));- field.autocomplete = "off";- field.spellcheck = false;- const add = el("button", "text", t("Add"));- add.onclick = () => {- d.value = field.value.trim();- if (!d.value) return field.focus();- set([...list, ...d.value.split(/[\s,;]+/).filter(Boolean)], () => { allowDraft = { value: "", err: "" }; });- };- field.oninput = () => { d.value = field.value; };- field.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") add.onclick(); };- const val = el("div", "val rule-add");- val.append(field, add);- r.append(val);- }- box.append(r);- for (const a of list) {- const row = el("div", "row pref allow-ip-row");- const w = el("div", "who");- w.append(el("div", "name", a));- const v = el("div", "val");- if (!env) {- const x = el("button", "text", t("Remove"));- x.onclick = () => set(list.filter((o) => o !== a));- v.append(x);- }- row.append(w, v);- box.append(row);- }-}--// renderLAN: the gateway shared on the local network, for agents on other-// machines. Gateway keys and connection examples live together in Gateway.-let lanSelectedURL = "", lanProtocol = "openai";-// the address picked under Share on local network is kept like Connect's-let lanWant = "";-try { lanWant = localStorage.getItem("magpie.lanAddress") || ""; } catch {}-function renderLAN(s) {- const box = $("#lanList");- box.replaceChildren();- const row = (name, sub, value, ...tools) => {- const r = el("div", "row pref");- const who = el("div", "who");- who.append(el("div", "name", name));- if (sub) who.append(el("div", "sub", sub));- const val = el("div", "val");- if (value) val.append(el("code", "", value));- val.append(...tools);- r.append(who, val);- box.append(r);- return r;- };- const set = (body) => writingPrefs(api("settings/lan", body)).then((ns) => {- prefs = ns; renderSettings();- if (ns.rekeyed) status(ns.rekeyed, "err");- })- .catch((e) => { status(t(e.message), "err"); renderSettings(); });- row(t("Share on local network"), t("Agents on other computers on this network, or through a tunnel to this one such as Cloudflare Tunnel, can use magpie’s models with a gateway key from Gateway"), "",- segs([["off", t("Off")], ["on", t("On")]], s.lan ? "on" : "off", (v) => set({ on: v === "on" })));- if (!s.lan) return;- let urls = s.lanURLs || [], sub = "";- // in a container magpie finds only the container's own addresses; the- // page opened over the network was reached at the host's, so the- // gateway is offered there, on its port- if (s.lanContainer) {- const host = location.hostname, port = urls.length ? new URL(urls[0]).port : "";- if (web && host && port && !/^(localhost|127\.|\[::1\]$)/.test(host)) {- urls = ["http://" + host + ":" + port]; // an IPv6 hostname comes bracketed- sub = t("Where this page was opened, on the gateway’s port; MAGPIE_PUBLIC_URL sets another");- } else sub = t("The container’s own addresses, which other devices can’t reach: set MAGPIE_PUBLIC_URL to the host’s");- }- if (!urls.length) row(t("Address"), t("This computer has no local network address right now"), "");- else {- lanSelectedURL = urls.includes(lanWant) ? lanWant : urls[0];- const controls = el("div", "lan-address-controls");- const address = urls.length === 1 ? el("code", "lan-address-text") : el("button", "proto pick lan-interface");- if (urls.length > 1) {- address.type = "button";- address.setAttribute("aria-label", t("Address"));- address.onclick = (e) => {- e.stopPropagation();- if (address.classList.contains("open")) return closeProtoMenu();- const suffix = lanProtocol === "openai" ? "/v1" : "";- openProtoMenu(address, urls.map((u) => ({ v: u, name: u + suffix, note: "" })), lanSelectedURL,- (v) => { lanSelectedURL = lanWant = v; keepPick("magpie.lanAddress", v); update(); }, "Address", "lan-address-menu");- };- }- const copyControl = el("span", "lan-copy");- const update = () => {- const label = lanProtocol === "openai" ? "OpenAI" : "Anthropic";- const url = lanSelectedURL + (lanProtocol === "openai" ? "/v1" : "");- if (urls.length === 1) address.textContent = url;- else address.replaceChildren(el("span", "lan-url", url), svg(CHEV, 11, 1.6));- address.title = url;- const what = t("{label} address", { label });- const button = copyBtn(url, what, t("Copied {label} address", { label }));- button.setAttribute("aria-label", t("Copy") + " " + what);- copyControl.replaceChildren(button);- };- controls.append(segs([["openai", "OpenAI"], ["anthropic", "Anthropic"]], lanProtocol,- (v) => { lanProtocol = v; update(); }), address, copyControl);- row(t("Address"), "", "", controls).classList.add("lan-address-row");- update();- }- if (sub) row(t("In a container"), sub, "").classList.add("lan-container");-}-// renderUpdate fills in the version row: whether a newer magpie is out.// The app checks and downloads on its own, so usually the row just offers// the restart; a check can also be asked for. That check leaves the buttondiff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.htmlindex 63572f543..d3677b08d 100644--- a/internal/gui/assets/index.html+++ b/internal/gui/assets/index.html@@ -510,6 +510,7 @@<script src="plugins/usage/page.js"></script><script src="plugins/redact/page.js"></script><script src="plugins/otel/page.js"></script>+<script src="plugins/gateway/settings.js"></script><script src="start.js"></script></body></html>diff --git a/internal/gui/assets/plugins/gateway/settings.js b/internal/gui/assets/plugins/gateway/settings.jsnew file mode 100644index 000000000..742e70b32--- /dev/null+++ b/internal/gui/assets/plugins/gateway/settings.js@@ -0,0 +1,297 @@+// Settings › Network and sharing's gateway rows (the gateway plugin's part+// of Settings): its port, model ids without the provider, sharing on the+// local network and the addresses let in, and the web pages that may call+// it. Run after app.js, whose helpers it shares (el, segs, input, api,+// writingPrefs), and before start.js draws Settings.++// renderPort: the gateway's address on this computer (Magic_zero on Discord:+// 3425 taken by another program, or one easier to tell apart). Only its+// port, 1024 up, is typed here; magpie moves its gateway there and every+// agent it connected with it, or says why it can't (another program has+// it). MAGPIE_ADDR, a whole host:port, comes first and the field shows it,+// off (Chicring on Discord: the row was titled a port while it showed one).+let portDraft = { value: null, err: "" };+// portSays is the gateway's word on a port it couldn't take, in the page's+// language: it says the port, so it is matched rather than looked up+function portSays(m) {+ let x;+ if ((x = /^port (\d+) is in use by another program/.exec(m))) return t("Port {p} is in use by another program: pick another one", { p: x[1] });+ if ((x = /^another magpie serves the gateway at (\S+):/.exec(m))) return t("Another magpie serves the gateway at {url}: set its port there, or quit it first", { url: x[1] });+ if (/from 1024 to 65535/.test(m)) return t("A port is a number from 1024 to 65535");+ return t(m);+}+function renderPort(s) {+ const box = $("#portList");+ const r = el("div", "row pref port-row");+ const who = el("div", "who");+ who.append(el("div", "name", t("Gateway address")));+ const sub = el("div", "sub");+ const d = portDraft;+ const now = s.addrEnv ? "" : String(s.port || 3425);+ const field = input(d.value ?? now, "3425");+ field.className = "words gateway-port";+ field.inputMode = "numeric";+ field.setAttribute("aria-label", t("Gateway address"));+ const save = el("button", "text", t("Apply"));+ if (s.addrEnv) {+ field.value = s.addrEnv;+ field.disabled = save.disabled = true;+ sub.textContent = t("MAGPIE_ADDR={addr} sets the gateway’s whole address, host:port: unset it to set the port here", { addr: s.addrEnv });+ } else if (d.err) {+ sub.textContent = d.err;+ sub.classList.add("err");+ } else sub.textContent = t("Only the port is set here, 1024 to 65535; MAGPIE_ADDR=host:port sets the whole address instead. Agents magpie connected move with it. Now {url}", { url: s.gateway || "" });+ who.append(sub);+ save.onclick = () => {+ const p = Number(field.value.trim());+ if (!Number.isInteger(p) || p < 1024 || p > 65535) {+ d.value = field.value; d.err = t("A port is a number from 1024 to 65535");+ return renderPort(s);+ }+ if (p === (s.port || 3425)) { d.value = null; d.err = ""; return renderPort(s); }+ save.disabled = true;+ writingPrefs(api("settings/port", { port: p }).then((res) => res.settings && (prefs = res.settings, res)))+ .then((res) => {+ portDraft = { value: null, err: "" };+ const n = res.port?.moved?.length || 0;+ if (res.port?.error) status(res.port.error, "err");+ else status(n ? t("Gateway on port {p}; {n} agents moved with it", { p, n }) : t("Gateway on port {p}", { p }), "ok", 2500);+ // the sidebar's gateway line, and the list's address the pages+ // copy, say where it is now, not the port before (noahhrreion on+ // Discord: it kept the old one until Providers was opened)+ if (res.settings?.gateway) renderSideGw({ ...sideGwAt, url: res.settings.gateway, running: true });+ if (providers) loadProviders().catch(() => {});+ renderSettings();+ })+ .catch((e) => { d.value = field.value; d.err = portSays(e.message); status(d.err, "err"); renderSettings(); });+ };+ field.oninput = () => { d.value = field.value; };+ field.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") save.onclick(); if (e.key === "Escape") { portDraft = { value: null, err: "" }; renderPort(s); } };+ const val = el("div", "val");+ val.append(field, save);+ r.append(who, val);+ box.replaceChildren(r); // swapped whole: the list is never laid out empty+}++// renderBareIds: Model ids without the provider (settings.bareModelIDs,+// love1sbug on X, moving from CLIProxyAPI): the gateway's /v1/models+// lists each model by its own id as well, gpt-5.6-sol beside+// codex/gpt-5.6-sol. Posted on its own; off by default.+function renderBareIds(s) {+ $("#bareIdsSegs").replaceChildren(segs([[false, t("Off")], [true, t("On")]], !!s.bareModelIDs, (on) =>+ writingPrefs(api("settings/bare-ids", { on })).then((ns) => { prefs = state.settings = ns; renderSettings(); })+ .catch((e) => { status(t(e.message), "err"); renderSettings(); })));+}++// renderCORS: the web pages whose scripts may call the gateway from a+// browser (#1051), by origin — a row to add one, and one row each to take+// it away. A page listed calls with a gateway key; none listed, no page+// can read what the gateway answers, as before.+let corsDraft = { value: "", err: "" };+// corsSays is the gateway's word on an origin it didn't take, in the+// page's language+function corsSays(m) {+ if (/wildcard/.test(m)) return t("Name each origin: a wildcard would let every web page use magpie");+ if (/is not an (extension's )?origin/.test(m)) return t("Write an origin as http://localhost:3000 or https://app.example.com, or a browser extension's as chrome-extension://, moz-extension:// or safari-web-extension:// followed by its ID");+ return t(m);+}+function renderCORS(s) {+ const box = $("#corsList");+ box.replaceChildren();+ const origins = s.corsOrigins || [];+ const d = corsDraft;+ const set = (next, done) => writingPrefs(api("settings/cors", { origins: next }))+ .then((ns) => { prefs = ns; d.err = ""; done?.(); renderSettings(); status(t("Saved"), "ok", 1500); })+ .catch((e) => { d.err = corsSays(e.message); status(d.err, "err"); renderSettings(); });+ const field = input(d.value, "http://localhost:3000");+ field.className = "words rule-match";+ field.setAttribute("aria-label", t("Web page origin"));+ field.autocomplete = "off";+ field.spellcheck = false;+ const add = el("button", "text", t("Add"));+ add.onclick = () => {+ d.value = field.value.trim();+ if (!d.value) return field.focus();+ set([...origins, d.value], () => { corsDraft = { value: "", err: "" }; });+ };+ field.oninput = () => { d.value = field.value; };+ field.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") add.onclick(); };+ const r = el("div", "row pref rule-row");+ const who = el("div", "who");+ who.append(el("div", "name", t("Web pages that may call magpie")),+ el("div", "sub" + (d.err ? " err" : ""), d.err || t("Scripts on these origins can call the gateway from a browser, each request with a gateway key from Gateway. A page from any other site is refused; pages on this computer are not")));+ const val = el("div", "val rule-add");+ val.append(field, add);+ r.append(who, val);+ box.append(r);+ for (const o of origins) {+ const row = el("div", "row pref cors-origin"); // an extension's id runs long: wrapped, never cut+ const w = el("div", "who");+ w.append(el("div", "name", o));+ const x = el("button", "text", t("Remove"));+ x.onclick = () => set(origins.filter((v) => v !== o));+ const v = el("div", "val");+ v.append(x);+ row.append(w, v);+ box.append(row);+ }+}++// renderAllow: the addresses other computers may reach magpie from at+// all (lc on Discord: magpie in Docker on a public host), as IPs and CIDR+// ranges, under Share on local network — a row to add one, and one row+// each to take it away. None listed lets every address in, with a gateway+// key, as before; this computer is always let in. MAGPIE_ALLOW_IPS, where+// set, is the list, shown and not edited here.+// A list that would shut out the page saving it names the address magpie+// sees the page from (Mathresearcher on Discord: which address?), and+// offers to add it to the list that was refused; behind Docker or a proxy+// that is the proxy's, not the user's computer's (gateway.peerAddr).+let allowDraft = { value: "", err: "", addr: "", tried: null };+function allowSays(m) {+ if (/is not an IP address/.test(m)) return t("Write an address as 203.0.113.7, or a range as 10.0.0.0/8 or 2001:db8::/32");+ const out = /shut out (\S+), the address/.exec(m);+ if (out) return t("That list leaves out {addr}, the address magpie sees this page open from: add it first, or this page can’t reach magpie", { addr: out[1] });+ if (/MAGPIE_ALLOW_IPS/.test(m)) return t("MAGPIE_ALLOW_IPS sets this list; change it there");+ return t(m);+}+function renderAllow(s) {+ const box = $("#allowList");+ box.replaceChildren();+ const env = s.allowIPsEnv || "";+ if (!s.lan && !s.onNetwork && !env) return;+ const list = env ? (s.allowIPsFromEnv || []) : (s.allowIPs || []);+ const d = allowDraft;+ const set = (next, done) => writingPrefs(api("settings/allowips", { ips: next }))+ .then((ns) => { prefs = ns; d.err = d.addr = ""; d.tried = null; done?.(); renderSettings(); status(t("Saved"), "ok", 1500); })+ .catch((e) => {+ d.err = allowSays(e.message);+ d.addr = /shut out (\S+), the address/.exec(e.message)?.[1] || "";+ d.tried = d.addr ? { next, done } : null;+ status(d.err, "err"); renderSettings();+ });+ const r = el("div", "row pref rule-row");+ const who = el("div", "who");+ const sub = d.err || (env ? t("Set by MAGPIE_ALLOW_IPS. Other computers reach magpie only from these addresses, even with a gateway key; this computer always can")+ : t("Other computers reach magpie only from these addresses or ranges (CIDR), even with a gateway key; this computer always can. None listed lets every address in"));+ who.append(el("div", "name", t("Allowed addresses")), el("div", "sub" + (d.err ? " err" : ""), sub));+ // the address the refusal named, added to the list that was refused in+ // one click+ if (d.err && d.addr && d.tried && !env) {+ const fix = el("button", "text allow-fix", t("Add {addr}", { addr: d.addr }));+ fix.type = "button";+ fix.title = t("Behind Docker or a reverse proxy, this is the proxy’s address, not your computer’s: adding it lets in everyone who comes through that proxy");+ const { next, done } = d.tried;+ fix.onclick = () => set([...next, d.addr], done);+ who.append(fix);+ }+ r.append(who);+ if (!env) {+ const field = input(d.value, "203.0.113.7, 10.0.0.0/8");+ field.className = "words rule-match allow-ip";+ field.setAttribute("aria-label", t("IP address or range"));+ field.autocomplete = "off";+ field.spellcheck = false;+ const add = el("button", "text", t("Add"));+ add.onclick = () => {+ d.value = field.value.trim();+ if (!d.value) return field.focus();+ set([...list, ...d.value.split(/[\s,;]+/).filter(Boolean)], () => { allowDraft = { value: "", err: "" }; });+ };+ field.oninput = () => { d.value = field.value; };+ field.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") add.onclick(); };+ const val = el("div", "val rule-add");+ val.append(field, add);+ r.append(val);+ }+ box.append(r);+ for (const a of list) {+ const row = el("div", "row pref allow-ip-row");+ const w = el("div", "who");+ w.append(el("div", "name", a));+ const v = el("div", "val");+ if (!env) {+ const x = el("button", "text", t("Remove"));+ x.onclick = () => set(list.filter((o) => o !== a));+ v.append(x);+ }+ row.append(w, v);+ box.append(row);+ }+}++// renderLAN: the gateway shared on the local network, for agents on other+// machines. Gateway keys and connection examples live together in Gateway.+let lanSelectedURL = "", lanProtocol = "openai";+// the address picked under Share on local network is kept like Connect's+let lanWant = "";+try { lanWant = localStorage.getItem("magpie.lanAddress") || ""; } catch {}+function renderLAN(s) {+ const box = $("#lanList");+ box.replaceChildren();+ const row = (name, sub, value, ...tools) => {+ const r = el("div", "row pref");+ const who = el("div", "who");+ who.append(el("div", "name", name));+ if (sub) who.append(el("div", "sub", sub));+ const val = el("div", "val");+ if (value) val.append(el("code", "", value));+ val.append(...tools);+ r.append(who, val);+ box.append(r);+ return r;+ };+ const set = (body) => writingPrefs(api("settings/lan", body)).then((ns) => {+ prefs = ns; renderSettings();+ if (ns.rekeyed) status(ns.rekeyed, "err");+ })+ .catch((e) => { status(t(e.message), "err"); renderSettings(); });+ row(t("Share on local network"), t("Agents on other computers on this network, or through a tunnel to this one such as Cloudflare Tunnel, can use magpie’s models with a gateway key from Gateway"), "",+ segs([["off", t("Off")], ["on", t("On")]], s.lan ? "on" : "off", (v) => set({ on: v === "on" })));+ if (!s.lan) return;+ let urls = s.lanURLs || [], sub = "";+ // in a container magpie finds only the container's own addresses; the+ // page opened over the network was reached at the host's, so the+ // gateway is offered there, on its port+ if (s.lanContainer) {+ const host = location.hostname, port = urls.length ? new URL(urls[0]).port : "";+ if (web && host && port && !/^(localhost|127\.|\[::1\]$)/.test(host)) {+ urls = ["http://" + host + ":" + port]; // an IPv6 hostname comes bracketed+ sub = t("Where this page was opened, on the gateway’s port; MAGPIE_PUBLIC_URL sets another");+ } else sub = t("The container’s own addresses, which other devices can’t reach: set MAGPIE_PUBLIC_URL to the host’s");+ }+ if (!urls.length) row(t("Address"), t("This computer has no local network address right now"), "");+ else {+ lanSelectedURL = urls.includes(lanWant) ? lanWant : urls[0];+ const controls = el("div", "lan-address-controls");+ const address = urls.length === 1 ? el("code", "lan-address-text") : el("button", "proto pick lan-interface");+ if (urls.length > 1) {+ address.type = "button";+ address.setAttribute("aria-label", t("Address"));+ address.onclick = (e) => {+ e.stopPropagation();+ if (address.classList.contains("open")) return closeProtoMenu();+ const suffix = lanProtocol === "openai" ? "/v1" : "";+ openProtoMenu(address, urls.map((u) => ({ v: u, name: u + suffix, note: "" })), lanSelectedURL,+ (v) => { lanSelectedURL = lanWant = v; keepPick("magpie.lanAddress", v); update(); }, "Address", "lan-address-menu");+ };+ }+ const copyControl = el("span", "lan-copy");+ const update = () => {+ const label = lanProtocol === "openai" ? "OpenAI" : "Anthropic";+ const url = lanSelectedURL + (lanProtocol === "openai" ? "/v1" : "");+ if (urls.length === 1) address.textContent = url;+ else address.replaceChildren(el("span", "lan-url", url), svg(CHEV, 11, 1.6));+ address.title = url;+ const what = t("{label} address", { label });+ const button = copyBtn(url, what, t("Copied {label} address", { label }));+ button.setAttribute("aria-label", t("Copy") + " " + what);+ copyControl.replaceChildren(button);+ };+ controls.append(segs([["openai", "OpenAI"], ["anthropic", "Anthropic"]], lanProtocol,+ (v) => { lanProtocol = v; update(); }), address, copyControl);+ row(t("Address"), "", "", controls).classList.add("lan-address-row");+ update();+ }+ if (sub) row(t("In a container"), sub, "").classList.add("lan-container");+}diff --git a/internal/gui/core_budget_test.go b/internal/gui/core_budget_test.goindex 7d6c2bfed..9fad8a6ae 100644--- a/internal/gui/core_budget_test.go+++ b/internal/gui/core_budget_test.go@@ -15,8 +15,8 @@ import (// so a page can't quietly grow back into the core; a change that needs more// raises them and says why in its commit.const (- appScriptBudget = 1_325_845 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%; a dialog growing out of the row that opened it and folding back into it, the core's own since every page's dialogs open through it (10-20); Codex's and Claude Code's own settings moved from Settings into the agent's row on the Agents page, the core's own since the tray panel and the window both draw them (10-20); 1,314,432 with Settings › Privacy's record of what was masked (its summary, the records view and the local model's controls), which belongs to Settings, the core's own, plus 1.5%; 1,336,481 with a provider's Names & levels saying Provider in model names is Settings' and opening it there (joe), and Settings' Image recognition saying where a custom provider's model is marked (nexnull), both in the core's own pages, with no room added (10-23); 1,337,633 with Settings › Models › Replies' Intent classifier timeout (#2934, reyoung), Settings' own row, drawn by waitRow, which the Image generation timeout's row now shares, with no room added; 1,337,735 with the provider editor's link naming a partner's page by its own host (siteHost) instead of usemagpie.ai's /go link, the core's own editor, with no room added (10-23); 1,338,084 with Check in now saying what the press came to (claimed +credits, already today, not available yet) where it said "refreshed" (#3326), the check-in row the tray panel draws too, the core's own, with no room added (10-23); 1,338,929 with a new partner's tile keeping a small dot until it is opened, in the add sheet, the core's own, with no room added (10-23); 1,343,324 with the sidebar's open-page row marked by one shape that moves on a spring (navTopGo), the window's own shell, which every page sits beside, with no room added (10-23); 1,343,465 with a dialog kept centred while its content comes in, until it is pressed (holdModal, every page's dialogs), the core's own, with no room added (10-24); 1,317,486 with what masking did moved out to Insights › Masking (plugins/redact), the budget lowered to it (10-24); 1,321,336 with Codex's one subagent model, its card's square saying plainly what each choice does and a row with a name in its sheet, where two squares read alike (the owner), the Agents page's, which the tray panel draws too, the core's own, with no room added (10-24); 1,321,424 with Settings › Models' Image generation MCP server row beside Image recognition's (JonahFu on X), the two drawn by one helper (mcpRow), Settings' own, with no room added (10-25); 1,321,994 with a provider of the user's set never to rest for a limit (zoecats), the provider editor's Advanced row, the core's own editor, with no room added (10-25); 1,322,289 with Settings › Privacy's Keep a key's form under Mask secrets (Charles Cao on X), Settings' own row, with no room added (10-25); 1,322,537 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,323,401 with the tray panel drawing its last allowances at once and asking for them beside the state (#3160, #3134), the tray panel's, the core's own, and the 4 bytes 84c50f032 added, with no room added (10-25); 1,326,105 with many releases' notes merged into one list by kind, each line with its version (the owner), in the update sheet and What's new, with no room added (10-25); 1,321,319 with Settings › Observability moved out to its plugin (plugins/otel/page.js) and its Langfuse setup there (an X user), the budget lowered to it (10-26); a quota card whose window is used but names no reset no longer saying "Not used yet" (windy on Discord) raised it to 1,321,347, and back to 1,321,319 with Settings' model pickers sharing one row helper (modelOpt) where six kept their own copy, no raise (10-26); 1,325,845 with every slow page's skeletons getting magpie's bird hopping bar to bar (skelBird, the owner after the Plugins page's README), one bird for the window over whatever page or dialog is loading, the core's own, with no room added (10-26)- coreScriptBudget = 1_541_967 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added; 1,535,084 with the sidebar's spring, with no room added; 1,549,478 with the context window card's map (tiles by tokens, the default look, the block grid a switch away) and its text view showing an inline image, in context.js, which the Routing page draws as well as Usage, so the core's own, with no room added (10-24); 1,550,768 with a usage card's refresh opening after its text (#840's card, which the tray panel draws too), the Add key spinner, and a dialog kept centred while its content comes in, with no room added (10-24); 1,524,789 with what masking did moved out to Insights › Masking, lowered to it; 1,528,525 with Codex's one subagent model, with no room added (10-24); 1,528,972 with the Image generation MCP server row (JonahFu on X), with no room added (10-25); 1,529,542 with the limit-rest row (zoecats), with no room added (10-25); 1,529,837 with Keep a key's form (Charles Cao on X), with no room added (10-25); 1,530,050 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,530,631 with a plugin's page growing to its README on the dialog's spring instead of in one jump (the owner), the Plugins page's, in plugins.js, with no room added (10-25); 1,533,445 with the context map counting its tokens on as a live request grows, a tile pointed at keeping its tip, a tool's gathered results saying how many and the small files their folder (the owner, after flohoeller's map on X), in context.js, which the Routing page draws as well as Usage, and the 4 bytes 84c50f032 added to app.js (Settings' Version row) without a raise, with no room added (10-25); 1,534,312 with the tray panel's last allowances drawn at once (#3160, #3134), with no room added (10-25); 1,537,016 with many releases' notes merged into one list by kind (the owner), in app.js, with no room added (10-25); 1,542,244 with a plugin's README loading under magpie's bird bouncing down its lines instead of pulsing bars (the owner), the Plugins page's, in plugins.js, with no room added (10-26); 1,542,418 with a page plugin's sidebar tab coming and going as it is installed, switched on or off, or removed, instead of on the Plugins page's next load (the owner), in plugins.js, with no room added (10-26); 1,537,645 with Settings › Observability moved out to plugins/otel, lowered to it (10-26); 1,537,673 with a used window with no reset not "Not used yet" (windy on Discord), and back to 1,537,645 with Settings' model pickers sharing modelOpt (10-26); 1,541,967 with every slow page's skeletons getting magpie's bird (skelBird, the owner), in app.js, the README's bird sharing its drawing and styles, with no room added (10-26)+ appScriptBudget = 1_310_129 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%; a dialog growing out of the row that opened it and folding back into it, the core's own since every page's dialogs open through it (10-20); Codex's and Claude Code's own settings moved from Settings into the agent's row on the Agents page, the core's own since the tray panel and the window both draw them (10-20); 1,314,432 with Settings › Privacy's record of what was masked (its summary, the records view and the local model's controls), which belongs to Settings, the core's own, plus 1.5%; 1,336,481 with a provider's Names & levels saying Provider in model names is Settings' and opening it there (joe), and Settings' Image recognition saying where a custom provider's model is marked (nexnull), both in the core's own pages, with no room added (10-23); 1,337,633 with Settings › Models › Replies' Intent classifier timeout (#2934, reyoung), Settings' own row, drawn by waitRow, which the Image generation timeout's row now shares, with no room added; 1,337,735 with the provider editor's link naming a partner's page by its own host (siteHost) instead of usemagpie.ai's /go link, the core's own editor, with no room added (10-23); 1,338,084 with Check in now saying what the press came to (claimed +credits, already today, not available yet) where it said "refreshed" (#3326), the check-in row the tray panel draws too, the core's own, with no room added (10-23); 1,338,929 with a new partner's tile keeping a small dot until it is opened, in the add sheet, the core's own, with no room added (10-23); 1,343,324 with the sidebar's open-page row marked by one shape that moves on a spring (navTopGo), the window's own shell, which every page sits beside, with no room added (10-23); 1,343,465 with a dialog kept centred while its content comes in, until it is pressed (holdModal, every page's dialogs), the core's own, with no room added (10-24); 1,317,486 with what masking did moved out to Insights › Masking (plugins/redact), the budget lowered to it (10-24); 1,321,336 with Codex's one subagent model, its card's square saying plainly what each choice does and a row with a name in its sheet, where two squares read alike (the owner), the Agents page's, which the tray panel draws too, the core's own, with no room added (10-24); 1,321,424 with Settings › Models' Image generation MCP server row beside Image recognition's (JonahFu on X), the two drawn by one helper (mcpRow), Settings' own, with no room added (10-25); 1,321,994 with a provider of the user's set never to rest for a limit (zoecats), the provider editor's Advanced row, the core's own editor, with no room added (10-25); 1,322,289 with Settings › Privacy's Keep a key's form under Mask secrets (Charles Cao on X), Settings' own row, with no room added (10-25); 1,322,537 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,323,401 with the tray panel drawing its last allowances at once and asking for them beside the state (#3160, #3134), the tray panel's, the core's own, and the 4 bytes 84c50f032 added, with no room added (10-25); 1,326,105 with many releases' notes merged into one list by kind, each line with its version (the owner), in the update sheet and What's new, with no room added (10-25); 1,321,319 with Settings › Observability moved out to its plugin (plugins/otel/page.js) and its Langfuse setup there (an X user), the budget lowered to it (10-26); a quota card whose window is used but names no reset no longer saying "Not used yet" (windy on Discord) raised it to 1,321,347, and back to 1,321,319 with Settings' model pickers sharing one row helper (modelOpt) where six kept their own copy, no raise (10-26); 1,325,845 with every slow page's skeletons getting magpie's bird hopping bar to bar (skelBird, the owner after the Plugins page's README), one bird for the window over whatever page or dialog is loading, the core's own, with no room added (10-26); 1,310,129 with Settings › Network and sharing's gateway rows (its port, bare ids, local network, allowed addresses, web pages) moved out to the gateway plugin (plugins/gateway/settings.js), the budget lowered to it (10-27)+ coreScriptBudget = 1_526_251 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added; 1,535,084 with the sidebar's spring, with no room added; 1,549,478 with the context window card's map (tiles by tokens, the default look, the block grid a switch away) and its text view showing an inline image, in context.js, which the Routing page draws as well as Usage, so the core's own, with no room added (10-24); 1,550,768 with a usage card's refresh opening after its text (#840's card, which the tray panel draws too), the Add key spinner, and a dialog kept centred while its content comes in, with no room added (10-24); 1,524,789 with what masking did moved out to Insights › Masking, lowered to it; 1,528,525 with Codex's one subagent model, with no room added (10-24); 1,528,972 with the Image generation MCP server row (JonahFu on X), with no room added (10-25); 1,529,542 with the limit-rest row (zoecats), with no room added (10-25); 1,529,837 with Keep a key's form (Charles Cao on X), with no room added (10-25); 1,530,050 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,530,631 with a plugin's page growing to its README on the dialog's spring instead of in one jump (the owner), the Plugins page's, in plugins.js, with no room added (10-25); 1,533,445 with the context map counting its tokens on as a live request grows, a tile pointed at keeping its tip, a tool's gathered results saying how many and the small files their folder (the owner, after flohoeller's map on X), in context.js, which the Routing page draws as well as Usage, and the 4 bytes 84c50f032 added to app.js (Settings' Version row) without a raise, with no room added (10-25); 1,534,312 with the tray panel's last allowances drawn at once (#3160, #3134), with no room added (10-25); 1,537,016 with many releases' notes merged into one list by kind (the owner), in app.js, with no room added (10-25); 1,542,244 with a plugin's README loading under magpie's bird bouncing down its lines instead of pulsing bars (the owner), the Plugins page's, in plugins.js, with no room added (10-26); 1,542,418 with a page plugin's sidebar tab coming and going as it is installed, switched on or off, or removed, instead of on the Plugins page's next load (the owner), in plugins.js, with no room added (10-26); 1,537,645 with Settings › Observability moved out to plugins/otel, lowered to it (10-26); 1,537,673 with a used window with no reset not "Not used yet" (windy on Discord), and back to 1,537,645 with Settings' model pickers sharing modelOpt (10-26); 1,541,967 with every slow page's skeletons getting magpie's bird (skelBird, the owner), in app.js, the README's bird sharing its drawing and styles, with no room added (10-26); 1,526,251 with Settings' gateway rows moved out to plugins/gateway/settings.js, lowered to it (10-27))func TestCoreScriptBudget(t *testing.T) {