From 74cbac06ec0bd20d0f225f29fa1c6cabd3468e77 Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 28 Sep 2026 01:21:26 +0800 Subject: [PATCH] =?UTF-8?q?gateway:=20the=20page=20is=20left=20as=20it=20i?= =?UTF-8?q?s=20when=20nothing=20on=20it=20changed=20=E2=80=94=20coming=20b?= =?UTF-8?q?ack=20to=20the=20window=20no=20longer=20wipes=20it=20to=20place?= =?UTF-8?q?holders=20and=20redraws,=20which=20put=20the=20reader=20back=20?= =?UTF-8?q?at=20the=20top;=20a=20reload=20draws=20again=20only=20what=20ch?= =?UTF-8?q?anged=20(the=20calls=20alone=20when=20only=20they=20did)=20and?= =?UTF-8?q?=20keeps=20where=20the=20reader=20was.=20The=20model=20list=20f?= =?UTF-8?q?olds=20away=20under=20its=20heading,=20with=20its=20count,=20so?= =?UTF-8?q?=20Recent=20calls=20sits=20under=20Connect;=20the=20fold=20is?= =?UTF-8?q?=20remembered.=20Asked=20on=20Discord?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/gui/assets/app.css | 6 +++++ internal/gui/assets/app.js | 40 +++++++++++++++++++++++++++++----- internal/gui/assets/i18n.js | 2 ++ internal/gui/assets/index.html | 2 +- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index d6047b4d8..280c275f3 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -720,6 +720,12 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; } #view-gateway .row-head, #view-usage .row-head { margin: 14px 0 6px; padding: 0 2px; } #view-usage .row-head.quota-head { margin: 6px 0 6px; } #view-gateway .row-head .note { font-size: 11px; color: var(--faint); } +/* the Models head folds the list away: a chevron, the label, how many */ +.fold { display: inline-flex; align-items: center; gap: 5px; margin-left: -4px; padding: 3px 6px 3px 4px; border-radius: 6px; color: var(--faint); transition: background .12s, color .12s; } +.fold:hover { background: var(--pill); color: var(--muted); } +.fold svg { flex: none; transform: rotate(90deg); transition: transform .15s ease-out; } +.fold[aria-expanded="false"] svg { transform: none; } +.fold .note { font-variant-numeric: tabular-nums; } /* the connect card: label column, then the value with a copy button */ .connect { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 10px 14px; align-items: start; padding: 12px 14px 14px; } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index c5d115b13..e851b840b 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -1201,14 +1201,25 @@ $("#save").onclick = () => { // the local gateway in whichever API the agent speaks. async function loadProviders() { - if (view === "gateway") renderGatewayLoading(); - else if (!providers) renderProvidersLoading(); + // the skeletons only while there is nothing yet: a reload keeps what is + // drawn, and where the reader is in it, until the new one is in + if (!providers) { if (view === "gateway") renderGatewayLoading(); else renderProvidersLoading(); } + const was = providers; providers = await api("providers"); // a reload's provider may be gone since if (typeof editing === "string" && !providers.providers.some((p) => p.id === editing)) editing = null; if (!providers.providers.length && editing === null) adding = true; - if (view === "gateway") renderGatewayView(); - else renderProviders(); + if (view === "gateway") { + // the gateway page is looked at and left open: coming back to the window + // redraws it only when something on it changed, and when only the calls + // did, only them (an account's last sign-in check isn't on it) + const json = (a) => JSON.stringify(a, (k, v) => (k === "seen" ? undefined : v)); + const same = (a, b) => json(a) === json(b); + if (was && !$("#view-gateway").classList.contains("loading") && same({ ...was, gateway: { ...was.gateway, calls: 0 } }, { ...providers, gateway: { ...providers.gateway, calls: 0 } })) { + if (!same(was.gateway.calls, providers.gateway.calls)) renderActivity(); + } else renderGatewayView(); + backToReader($("#view-gateway")); + } else renderProviders(); } // Rows in the shape of the list while it is first asked for; a reload keeps @@ -1645,10 +1656,27 @@ function highlight(code, lang) { } let modelQuery = ""; +// The model list can be folded away, so Recent calls sits under Connect; +// the fold is remembered. +let modelsFolded = false; +try { modelsFolded = localStorage.getItem("magpie.gwModelsFolded") === "1"; } catch {} +$("#foldModels").prepend(svg(CHEV_R, 11, 1.6)); +$("#foldModels").onclick = () => { + modelsFolded = !modelsFolded; + try { localStorage.setItem("magpie.gwModelsFolded", modelsFolded ? "1" : "0"); } catch {} + renderGatewayModels(); + backToReader($("#view-gateway")); +}; + function renderGatewayModels() { const list = $("#gwModels"); list.replaceChildren(); const all = gatewayModels(); + const fold = $("#foldModels"); + fold.setAttribute("aria-expanded", String(!modelsFolded)); + fold.title = t(modelsFolded ? "Show the models" : "Fold the models away"); + $("#modelsCount").textContent = all.length ? String(all.length) : ""; + list.hidden = modelsFolded && all.length > 0; // the search sits in the section head, beside Copy all ids; typing // redraws only the list, so it keeps its focus let q = $("#findModel"); @@ -1660,13 +1688,13 @@ function renderGatewayModels() { q.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Escape" && q.value) { q.value = modelQuery = ""; renderGatewayModels(); } }; $("#copyModels").before(q); } - q.hidden = all.length < 8; + q.hidden = all.length < 8 || list.hidden; const words = modelQuery.trim().toLowerCase().split(/\s+/).filter(Boolean); const models = q.hidden ? all : all.filter((m) => { const hay = `${m.id} ${m.name || ""} ${m.provider.name}`.toLowerCase(); return words.every((w) => hay.includes(w)); }); - $("#copyModels").hidden = !models.length; + $("#copyModels").hidden = !models.length || list.hidden; $("#copyModels").onclick = () => copy(models.map((m) => m.id).join("\n"), t("Model ids")); if (!all.length) { const empty = el("div", "empty-state", ""); diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index e5093b350..4bccbd400 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -521,6 +521,8 @@ const I18N = { "Add a provider, or sign in to Codex or Copilot; their models show up here for every agent.": "添加一个供应商,或登录 Codex / Copilot;它们的模型会出现在这里,供所有 Agent 使用。", "Use this model in the snippets": "在示例中使用此模型", "Recent calls": "最近调用", + "Show the models": "展开模型列表", + "Fold the models away": "收起模型列表", "shown by the magpie that serves the gateway": "由提供网关的那个 magpie 显示", "No requests yet. Point an agent at a model, or run the example above; every call shows up here as it happens.": "还没有请求。让某个 Agent 使用一个模型,或运行上面的示例;每次调用都会实时显示在这里。", "Show request and response bodies": "查看请求体和响应体", diff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.html index e00e0129e..ba62a4454 100644 --- a/internal/gui/assets/index.html +++ b/internal/gui/assets/index.html @@ -68,7 +68,7 @@
Connect
-
Models
+
Recent calls