From d06d2383a451b9b9dd78d39d143e7fc5ec27bae8 Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 13 Nov 2026 11:40:10 +0800 Subject: [PATCH] gui: connect addresses' save and the typed certificate move into tlscerts.js, within the core script budget (quantum_lsfc on X) The Connect to row put TestCoreScriptBudget 180 bytes over (1265892 > 1265712). The typed-certificate copy in asTyped and the resolve line in Save now live in tlscerts.js, which the editor imports, so the core carries no new code. A save before tlscerts.js has loaded sends no resolve, and the server keeps what was saved (a left-out resolve keeps it), as it already did for the server pin. Run on mote at the head rebased on origin/main b942a872b: go test -count=1 -timeout 45m ./internal/netproxy ./internal/provider ./internal/gateway ./internal/gui, all ok; gofmt -l clean; go vet ./... for darwin, linux (-tags nogui) and windows ok; provider-resolve.test.cjs (chromium and webkit; en zh zh-TW ja de; 1100 and 420) 60 of 60 ok. Rebased again on origin/main dea131174 and run on mote: netproxy, provider and gui (TestCoreScriptBudget) ok, gofmt and the three vets ok, provider-resolve 60 of 60 and i18n-keys ok; internal/gateway was not run again at that head (no new main commit touches the offline check or the dial). The 94 GUI files the editor's Save, Test and certificate rows reach, run at origin/main 436d507f0: 88 reds in 15 files, the same tests red on that main run alone (filed: #6424, and #6010 #6156 #5838 #4621 #4391 #5147 #6030 #6209 #4397 #4673 #6099). Not tried: a real managed network with an L4 SNI gateway (the reporter's), and the rule's dial on Windows or Linux beyond go vet. --- internal/gui/assets/app.js | 10 ++++------ internal/gui/assets/tlscerts.js | 11 +++++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 8cde4ce77..2aa86c4ec 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -8048,9 +8048,8 @@ function asTyped() { // provider of the user's own body.insecureTLS = !!draft.insecureTLS; body.http1 = !!draft.http1; - // a client certificate typed (#5596) is tried as it would be saved - for (const k of CERT_FIELDS) if (draft[k] != null) body[k] = draft[k].trim(); - if (draft.resolve) body.resolve = draft.resolve; // connect addresses (tlscerts.js) + // a client certificate typed (#5596) and connect addresses are tried as they would be saved + window.tlsTyped?.(draft, body); return body; } const CERT_FIELDS = ["clientCert", "clientKey", "serverCA", "serverPin"]; @@ -9278,7 +9277,7 @@ function baseAPIOf(p) { // draftOf is a saved provider as its editor's form holds it. function draftOf(p) { - return { id: p.id, name: p.name, preset: p.preset, chat: p.chat, responses: p.responses, anthropic: p.anthropic, gemini: p.gemini || "", catalog: p.catalog, decide: p.decide || "", key: "", api: baseAPIOf(p), chosen: pickedOf(p), none: !!p.noModels, best: !!p.bestInFamily, extra: [], headers: headerRows(p.headers), extraBody: extraBodyText(p.extraBody), replyHeaders: (p.replyHeaders || []).join(", "), passHeaders: (p.passHeaders || []).join(", "), icon: p.icon || "", iconFrom: p.iconFrom || "", fallback: [...(p.fallback || [])], unlisted: !!p.unlisted, hiddenDrawers: [...(p.hiddenDrawers || [])], hiddenVideomakers: [...(p.hiddenVideomakers || [])], searches: !!p.searches, unredacted: !!p.unredacted, countFree: !!p.countFree, billing: p.billing || "", insecureTLS: !!p.insecureTLS, http1: !!p.http1, clientCert: p.clientCert || "", clientKey: p.clientKey || "", serverCA: p.serverCA || "", serverPin: p.serverPin || "", resolve: p.resolve || null, socket: p.socket || "", limitRestOff: !!p.limitRestOff, noBalanceProbe: !!p.noBalanceProbe, upstreamProviders: !!p.upstreamProviders, passErrors: !!p.passErrors, imageFilesOff: !!p.imageFilesOff, nativeCompaction: !!p.nativeCompaction, passUserAgent: p.passUserAgent !== false, pinUpstream: !!p.pinUpstream, authHeader: p.authHeader || "", balanceURL: p.balanceURL || "", balancePath: p.balancePath || "", balanceMethod: p.balanceMethod || "", modelsURL: p.modelsURL || "", listOff: !!p.listOff, contexts: contextsText(p.contexts), outputs: contextsText(p.outputs), compacts: contextsText(p.compacts), keysUrl: p.keysUrl || "", ...proxyDraft(p), ...concurrencyDraft(p), rateWindows: (p.rateWindows || []).map((w) => ({ ...w })) }; + return { id: p.id, name: p.name, preset: p.preset, chat: p.chat, responses: p.responses, anthropic: p.anthropic, gemini: p.gemini || "", catalog: p.catalog, decide: p.decide || "", key: "", api: baseAPIOf(p), chosen: pickedOf(p), none: !!p.noModels, best: !!p.bestInFamily, extra: [], headers: headerRows(p.headers), extraBody: extraBodyText(p.extraBody), replyHeaders: (p.replyHeaders || []).join(", "), passHeaders: (p.passHeaders || []).join(", "), icon: p.icon || "", iconFrom: p.iconFrom || "", fallback: [...(p.fallback || [])], unlisted: !!p.unlisted, hiddenDrawers: [...(p.hiddenDrawers || [])], hiddenVideomakers: [...(p.hiddenVideomakers || [])], searches: !!p.searches, unredacted: !!p.unredacted, countFree: !!p.countFree, billing: p.billing || "", insecureTLS: !!p.insecureTLS, http1: !!p.http1, clientCert: p.clientCert || "", clientKey: p.clientKey || "", serverCA: p.serverCA || "", serverPin: p.serverPin || "", resolve: p.resolve, socket: p.socket || "", limitRestOff: !!p.limitRestOff, noBalanceProbe: !!p.noBalanceProbe, upstreamProviders: !!p.upstreamProviders, passErrors: !!p.passErrors, imageFilesOff: !!p.imageFilesOff, nativeCompaction: !!p.nativeCompaction, passUserAgent: p.passUserAgent !== false, pinUpstream: !!p.pinUpstream, authHeader: p.authHeader || "", balanceURL: p.balanceURL || "", balancePath: p.balancePath || "", balanceMethod: p.balanceMethod || "", modelsURL: p.modelsURL || "", listOff: !!p.listOff, contexts: contextsText(p.contexts), outputs: contextsText(p.outputs), compacts: contextsText(p.compacts), keysUrl: p.keysUrl || "", ...proxyDraft(p), ...concurrencyDraft(p), rateWindows: (p.rateWindows || []).map((w) => ({ ...w })) }; } // duplicateProvider opens the Add form on a copy of p, its key p's unless another is pasted (#268). @@ -10307,8 +10306,7 @@ function drawEditor(p, presetID) { body.billing = draft.billing || ""; if (tlsTakes()) { body.insecureTLS = !!draft.insecureTLS && onHTTPS(); body.http1 = !!draft.http1 && onHTTPS(); } if (certTakes()) for (const k of CERT_FIELDS) body[k] = onHTTPS() ? (draft[k] || "").trim() : ""; - else pinBody(body); - if (draft.resolve) body.resolve = draft.resolve; + pinBody(body, certTakes()); if (socketable()) body.socket = draft.socket || ""; if (custom) body.limitRestOff = !!draft.limitRestOff; body.noBalanceProbe = !!draft.noBalanceProbe; diff --git a/internal/gui/assets/tlscerts.js b/internal/gui/assets/tlscerts.js index 7c827f958..8934c4ceb 100644 --- a/internal/gui/assets/tlscerts.js +++ b/internal/gui/assets/tlscerts.js @@ -54,11 +54,18 @@ function drawPin(pin, draft, peek, seen) { // every one of theirs and Remote magpie's, and a preset's pointed at their // own server, never the vendor's own hosts; save has the Save body carry // the pin. The client certificate's fields are saved by app.js itself. +window.tlsTyped = (draft, body) => { + for (const k of ["clientCert", "clientKey", "serverCA", "serverPin"]) if (draft[k] != null) body[k] = draft[k].trim(); + if (draft.resolve) body.resolve = draft.resolve; +}; + window.tlsCertRows = function ({ p, pr, draft, at, certTakes, onHTTPS, addressOf, asTyped, show, save }) { if (!at.isConnected) return; - const rows = []; + const rows = [], saves = []; + const keep = (f) => saves.push(f); + save((body, own) => { if (!own) for (const f of saves) f(body); if (draft.resolve) body.resolve = draft.resolve; }); const takes = certTakes() || (p ? !!p.takesServerPin || (!!p.preset && !p.account) : !!pr) && (p?.preset || pr?.id) !== "google-vertex"; - if (takes) rows.push(pinRow({ p, pr, draft, certTakes, addressOf, asTyped, show, save })); + if (takes) rows.push(pinRow({ p, pr, draft, certTakes, addressOf, asTyped, show, save: keep })); if (certTakes()) { const box = el("div", "client-cert"); for (const [k, label, hold] of [["clientCert", t("Certificate"), "client.pem"], ["clientKey", t("Key"), "client-key.pem"], ["serverCA", t("Server CA"), "ca.pem"]]) {