gui: an agent with every model hidden opens its list at a refused connect

塔哥 on Discord: Grok Build had every magpie model taken out of its
list, was switched off, and could not be connected again. Connect
answers all_hidden, and the Pick that puts a model back is drawn only
in a connected agent's row (connectPanel), so nothing in the window
could undo it.

Now a refused connect with code all_hidden opens the agent's model list
where it was asked: at the row's switch (connectSwitch), and at the Get
started card's chip (guideConnect), its sibling. The status says to
pick one, then connect, in en, zh, zh-TW, ja and de. A model picked
there lets the next connect go through.

Run:
- agent-connect-all-hidden.test.cjs (new): chromium and webkit, en and
  zh, widths 1000 and 560 at the switch and 1000 at the Get started
  chip: 12/12. With HEAD's app.js it fails (chromium 0/4, broken by
  hand).
- agent-models-all-hidden, agent-models-loading, -only-picked, -own,
  -picker, -redraw, agent-models, agents-hidden-last, click-scroll:
  all pass. getting-started: 60/60.
- go test ./internal/gui -run 'I18n|Lang|Transl|Strings|Locale': ok.
No Go changed; gofmt/vet not affected.
Full suite: not run for this commit alone; run on the batch before push.
This commit is contained in:
yetone
2026-10-16 00:16:43 +08:00
parent a786c51cb0
commit 94942f9f3f
3 changed files with 149 additions and 3 deletions
+25 -3
View File
@@ -125,7 +125,10 @@ async function api(path, body, heads, signal) {
// reader's language
if (data?.code === "no_models") err.message = t("Add a provider or subscription in magpie first, then connect {agent}", { agent: data.agent });
// magpie has models, and none is left in the agent's model list (#1989)
if (data?.code === "all_hidden") err.message = t("None of magpie's models is left in {agent}'s model list: pick one under Model list → Pick, then connect {agent}", { agent: data.agent });
if (data?.code === "all_hidden") {
err.code = data.code;
err.message = t("None of magpie's models is left in {agent}'s model list: pick one under Model list → Pick, then connect {agent}", { agent: data.agent });
}
if (data?.why) err.why = data.why; // a failed move's reason, said in the reader's language
// an account the agent is signed in to, refused removal while it has
// another: said in the reader's language
@@ -1098,6 +1101,8 @@ function connectSwitch(a) {
s.setAttribute("aria-label", t("Connect {agent} to magpie", { agent: a.name }));
s.title = a.wired ? t("Connected · switch off to put back what {agent} had before magpie", { agent: a.name }) : t("Switch on and {agent}'s model list gets magpie's models", { agent: a.name });
s.append(el("i"));
// the list opened from a failed connect, drawn again while it is open
if (!a.wired) holdAgentModels(a, s);
s.onclick = async (e) => {
e.stopPropagation();
if (a.wired) { askDisconnect(a); return; }
@@ -1114,6 +1119,15 @@ function connectSwitch(a) {
} catch (err) {
s.disabled = false;
s.classList.remove("on");
// every model taken out of its list: the Pick that puts one back is
// in a connected agent's row only, so its list opens here (塔哥 on
// Discord: Grok Build, all hidden, then switched off, couldn't be
// connected again)
if (err.code === "all_hidden") {
status(t("None of magpie's models is left in {agent}'s model list: pick one, then connect {agent}", { agent: a.name }), "err");
openAgentModels(a, s, e);
return;
}
status(t(err.message), "err");
}
};
@@ -1609,7 +1623,7 @@ function guideCard(g) {
b.disabled = !ready || !!guideBusy;
b.classList.toggle("busy", guideBusy === a.id);
b.title = ready ? t("Switch on and {agent}'s model list gets magpie's models", { agent: a.name }) : t("Add a key or a subscription first; then there are models to connect");
b.onclick = (e) => { e.stopPropagation(); guideConnect(a); };
b.onclick = (e) => { e.stopPropagation(); guideConnect(a, e); };
chips.append(b);
}
if (found.length > GUIDE_CHIPS) chips.append(el("span", "guide-more", t("+{n} more below", { n: found.length - GUIDE_CHIPS })));
@@ -1673,7 +1687,7 @@ function guideRedraw() {
fit();
}
async function guideConnect(a) {
async function guideConnect(a, ev) {
if (guideBusy) return;
guideBusy = a.id;
guideRedraw();
@@ -1687,6 +1701,14 @@ async function guideConnect(a) {
} catch (err) {
guideBusy = "";
guideRedraw();
// every model taken out of its list: its list opens at its chip, as
// at the row's switch (connectSwitch)
const chip = err.code === "all_hidden" && document.querySelector(`.guide-agent[data-id="${CSS.escape(a.id)}"]`);
if (chip) {
status(t("None of magpie's models is left in {agent}'s model list: pick one, then connect {agent}", { agent: a.name }), "err");
openAgentModels(a, chip, ev);
return;
}
status(t(err.message), "err");
}
}
+4
View File
@@ -617,6 +617,7 @@ const I18N = {
"A proxy in front of magpie stopped waiting; magpie may still be finishing, check again in a minute ({what})": "magpie 前面的代理等不及先返回了;magpie 可能仍在处理,请过一分钟再看看({what})",
"A proxy in front of magpie answered, not magpie ({what})": "这是 magpie 前面的代理返回的,不是 magpie 的回应({what})",
"None of magpie's models is left in {agent}'s model list: pick one under Model list → Pick, then connect {agent}": "magpie 的模型都不在 {agent} 的模型列表里:先在「模型列表 → 挑选」里选一个,再接入 {agent}",
"None of magpie's models is left in {agent}'s model list: pick one, then connect {agent}": "magpie 的模型都不在 {agent} 的模型列表里:先选一个,再接入 {agent}",
"Connected · switch off to put back what {agent} had before magpie": "已接入 · 关掉即还原 {agent} 接入 magpie 之前的设置",
"Switch on and {agent}'s model list gets magpie's models": "打开后,{agent} 的模型列表里就有 magpie 的模型",
"{agent} is connected to magpie": "{agent} 已接入 magpie",
@@ -4256,6 +4257,7 @@ const I18N = {
"A proxy in front of magpie stopped waiting; magpie may still be finishing, check again in a minute ({what})": "magpie 前面的代理等不及先回傳了;magpie 可能仍在處理,請過一分鐘再看看({what})",
"A proxy in front of magpie answered, not magpie ({what})": "這是 magpie 前面的代理回傳的,不是 magpie 的回應({what})",
"None of magpie's models is left in {agent}'s model list: pick one under Model list → Pick, then connect {agent}": "magpie 的模型都不在 {agent} 的模型列表裡:先在「模型列表 → 挑選」裡選一個,再接入 {agent}",
"None of magpie's models is left in {agent}'s model list: pick one, then connect {agent}": "magpie 的模型都不在 {agent} 的模型列表裡:先選一個,再接入 {agent}",
"Connected · switch off to put back what {agent} had before magpie": "已接入 · 關掉即還原 {agent} 接入 magpie 之前的設定",
"Switch on and {agent}'s model list gets magpie's models": "開啟後,{agent} 的模型列表裡就有 magpie 的模型",
"{agent} is connected to magpie": "{agent} 已接入 magpie",
@@ -7861,6 +7863,7 @@ const I18N = {
"A proxy in front of magpie stopped waiting; magpie may still be finishing, check again in a minute ({what})": "magpie の前のプロキシが待ちきれずに応答しました。magpie はまだ処理中かもしれません。1 分ほどして確認してください({what})",
"A proxy in front of magpie answered, not magpie ({what})": "magpie ではなく、その前のプロキシからの応答です({what})",
"None of magpie's models is left in {agent}'s model list: pick one under Model list → Pick, then connect {agent}": "{agent} のモデル一覧に magpie のモデルが一つも残っていません:「モデル一覧 → 選択」で一つ選んでから、{agent} を接続してください",
"None of magpie's models is left in {agent}'s model list: pick one, then connect {agent}": "{agent} のモデル一覧に magpie のモデルが一つも残っていません:一つ選んでから、{agent} を接続してください",
"Connected · switch off to put back what {agent} had before magpie": "接続済み · オフにすると {agent} を magpie 接続前の設定に戻します",
"Switch on and {agent}'s model list gets magpie's models": "オンにすると {agent} のモデル一覧に magpie のモデルが加わります",
"{agent} is connected to magpie": "{agent} は magpie に接続されています",
@@ -11483,6 +11486,7 @@ const I18N = {
"A proxy in front of magpie stopped waiting; magpie may still be finishing, check again in a minute ({what})": "Ein Proxy vor magpie hat nicht länger gewartet; magpie arbeitet möglicherweise noch, prüfen Sie es in einer Minute erneut ({what})",
"A proxy in front of magpie answered, not magpie ({what})": "Ein Proxy vor magpie hat geantwortet, nicht magpie ({what})",
"None of magpie's models is left in {agent}'s model list: pick one under Model list → Pick, then connect {agent}": "In der Modellliste von {agent} ist keines der Modelle von magpie übrig: Wählen Sie unter Modellliste → Wählen eines aus und verbinden Sie dann {agent}",
"None of magpie's models is left in {agent}'s model list: pick one, then connect {agent}": "In der Modellliste von {agent} ist keines der Modelle von magpie übrig: Wählen Sie eines aus und verbinden Sie dann {agent}",
"Connected · switch off to put back what {agent} had before magpie": "Verbunden · ausschalten, um den Stand von {agent} vor magpie wiederherzustellen",
"Switch on and {agent}'s model list gets magpie's models": "Einschalten, dann erhält die Modellliste von {agent} die magpie-Modelle",
"{agent} is connected to magpie": "{agent} ist mit magpie verbunden",
@@ -0,0 +1,120 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// Every model taken out of an agent's list, then the agent switched off
// (塔哥 on Discord, Grok Build): connecting it again is refused until one
// is picked, and the Pick that picks one is in a connected agent's row
// only. The refused switch opens the agent's list itself, a model picked
// there lets it connect; so does the Get started card's chip.
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 fixture(lang, guide) {
const list = ["grok-5", "grok-5-mini", "grok-code"].map((m) =>
({ id: "xai/" + m, name: m, group: "xAI", icon: "xai", context: 1e6, hidden: true }));
const posts = [];
let wired = false, connects = 0;
const count = () => ({ shown: list.filter((m) => !m.hidden).length, listed: list.length });
const state = () => {
const options = list.filter((m) => !m.hidden).map((m) => ({ value: m.id, label: m.name, ref: m.id }));
return {
agents: [{
id: "grok", name: "Grok Build", path: "/test/.grok/user-settings.json", icon: "xai", wired,
fields: [{ key: "model", label: "model", value: wired ? options[0]?.value || "" : "grok-4", options }],
models: count(),
}],
profiles: [], settings: { lang, theme: "light", guideHidden: !guide },
// models served, so the Get started card offers to connect an agent
served: guide ? 3 : 0,
};
};
async function serve(route) {
const req = route.request();
const url = new URL(req.url());
const json = (data, status = 200) => route.fulfill({ status, json: data });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${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(state());
if (url.pathname === "/api/agents/connect/grok") {
connects++;
// the gateway's answer to Connect's AllHiddenError (api.go)
if (!list.some((m) => !m.hidden)) return json({ error: "None of magpie's models is left in Grok Build's model list", code: "all_hidden", agent: "Grok Build" }, 400);
wired = true;
return json({ ...state(), connected: { how: "first", field: "model", value: list.find((m) => !m.hidden).id } });
}
if (url.pathname === "/api/agent-models/grok") {
if (req.method() === "POST") {
const { hidden } = req.postDataJSON();
posts.push(hidden);
for (const m of list) m.hidden = hidden.includes(m.id);
return json({ models: list, count: count() });
}
return json({ models: list });
}
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/groups") return json({ groups: [] });
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, window: true } });
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)];
await route.fulfill({ body: await fs.readFile(file), contentType });
}
return { serve, posts, connects: () => connects };
}
const W = {
en: { pick: "None of magpie's models is left in Grok Build's model list: pick one, then connect Grok Build" },
zh: { pick: "magpie 的模型都不在 Grok Build 的模型列表里:先选一个,再接入 Grok Build" },
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh"]) {
for (const [width, guide] of [[1000, false], [560, false], [1000, true]]) {
test(`${engine} ${lang} ${width}${guide ? " Get started" : ""}: a switched-off agent with every model hidden opens its list to pick one`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await browser.newPage({ viewport: { width, height: 700 } });
page.setDefaultTimeout(5000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
const fx = fixture(lang, guide);
await page.route("**/*", fx.serve);
t.after(async () => {
if (process.env.ARTIFACT_DIR) {
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}${guide ? "-guide" : ""}-connect-all-hidden.png`) });
}
await browser.close();
});
await page.goto("http://magpie.test/");
const row = page.locator('.row.agent[data-id="grok"]');
const sw = row.locator(".ag-conn");
const chip = page.locator('.guide-agent[data-id="grok"]');
const connect = guide ? chip : sw;
await connect.waitFor();
assert.equal(await row.locator(".ag-exp").count(), 0, "a switched-off row has no Pick");
await connect.click();
const pop = page.locator(".am-pop:not(.leaving)");
await pop.waitFor();
assert.equal(fx.connects(), 1);
assert.equal(await page.locator("#status").innerText(), W[lang].pick);
assert.equal(await sw.getAttribute("aria-checked"), "false", "not connected");
// one picked, the list closed: the switch connects
await pop.locator(".am-mr").first().click();
await page.waitForTimeout(150);
assert.deepEqual(fx.posts.at(-1), ["xai/grok-5-mini", "xai/grok-code"]);
await page.keyboard.press("Escape");
await pop.waitFor({ state: "detached" });
await page.waitForTimeout(300);
await (guide ? chip : row.locator(".ag-conn")).click();
await page.waitForFunction(() => document.querySelector('.row.agent[data-id="grok"] .ag-conn')?.getAttribute("aria-checked") === "true");
assert.equal(fx.connects(), 2);
assert.deepEqual(errors, []);
});
}
}
}