providers: Custom provider beside the add sheet's search (jackutan on X)

The add sheet drew "+ Custom provider" only under every preset section
(vendors, relays, local, remote), and only while the search was empty,
so it was hard to find. It is now a text button in the sheet's head,
right after "Find a vendor…", there as the sheet opens and kept while
searching; its old hint is its title. A search that finds nothing still
offers "Add it as a custom provider" in its line. Below 760px the head
wraps: the title, Import… and Close on the first line, the search and
Custom provider on a line of their own, so no language clips them. The
foot line and its styles are gone; app.js is 248 bytes smaller.

Run (WSL magpie-desktop, Playwright 1.62.0, Chromium + WebKit):
- add-sheet-custom.test.cjs (new): en, zh, zh-TW, ja, de at 980, 761
  and 420px, 32/32 pass. Against origin/main's assets (MAGPIE_ASSETS)
  0/32: no button in the head.
- add-sheet, provider-detect-draft, provider-add-gemini, model-id-space,
  provider-curl-paste, system-one, provider-add-models,
  provider-url-each-api, provider-retrieval-only, i18n-keys (selectors
  moved from .custom-foot to .row-head) pass, but for reds that are red
  the same at origin/main b46f23ffa in the same run (below).
- 72 GUI files that reach the add sheet, concurrency 3: the reds are
  the same files as origin/main b46f23ffa run alone: vertex-editor
  (#4720, #4721), tencent-cloud (#4321, #4399), remote-magpie (#4398),
  plugin-moved-signin (#2900, #4218), plugin-signin-no-url (#5938,
  filed now), plugin-pick-sub webkit ja 420 (#5937, filed now), plus
  page.goto timeouts under the run's load (load ~70).
- plugins-more-discover, zcode-site-layout, provider-retrieval-only,
  twice each at this change and at b46f23ffa: here 43/43 then 39/43,
  there 41/43 twice; webkit "More in Plugins opens Discover" (#5559)
  and "ZCode's site step" (#4727) are red on both.
- At 9c39edb92 + this: add-sheet-custom, add-sheet, i18n-keys
  42/42. Rebased onto 4eeee5215 (no add-sheet code); TestCoreScriptBudget ok there.
- TestCoreScriptBudget (Windows box): ok.

Not tried: macOS WebKit and the real app (mote refused SSH all session);
the tray panel's narrow sheet in the real app.
This commit is contained in:
yetone
2026-11-10 20:01:02 +08:00
parent 4eeee52158
commit 4d95d81eae
12 changed files with 146 additions and 31 deletions
+9 -4
View File
@@ -3355,10 +3355,15 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
.tile .nm .badge { flex: none; }
.tile .have { flex: none; width: 6px; height: 6px; border-radius: 3px; background: var(--green); }
.tile .cnt { flex: none; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sheet .custom-foot { display: flex; align-items: center; gap: 8px; margin-top: 14px; padding: 10px 2px 0; border-top: 1px solid var(--line-2); }
.sheet .custom-foot .custom { display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 10px 0 6px; border-radius: 8px; color: var(--accent); font-size: 13px; }
.sheet .custom-foot .custom:hover, .sheet .custom-foot .custom.on { background: var(--accent-soft); }
.sheet .custom-foot .hint { font-size: 12px; color: var(--muted); }
.sheet .row-head .custom { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); }
.sheet .row-head .custom:hover, .sheet .row-head .custom.on { color: var(--accent); background: var(--accent-soft); }
/* narrow: the search and Custom provider on a line of their own */
@media (max-width: 760px) {
.sheet .row-head { flex-wrap: wrap; height: auto; row-gap: 8px; }
.sheet .row-head::after { content: ""; order: 1; flex-basis: 100%; }
.sheet .row-head .find { order: 2; flex: 1; width: auto; min-width: 0; }
.sheet .row-head .custom { order: 2; }
}
/* the provider editor, in a dialog */
/* the label column is as wide as its longest label, so that label starts
at the padding and the fields end the same way on the right (the
+8 -12
View File
@@ -7120,7 +7120,7 @@ function shinePartners(k, grid) {
seen.observe(k);
}
// The add sheet: presets first (a key is all they need), custom last.
// The add sheet: presets, and a custom provider beside its search (jackutan on X).
let presetQuery = "", addReturnPick = null;
function renderAdd() {
const sheet = $("#addSheet");
@@ -7155,7 +7155,12 @@ function renderAdd() {
if (q.value) { q.value = presetQuery = ""; drawTiles(); } else if (providers.providers.length) closeAddSheet();
};
q.oninput = () => { presetQuery = q.value; drawTiles(); };
head.append(q);
const c = el("button", "text custom" + (editing?.custom ? " on" : ""));
c.append(svg(PLUS, 11, 1.8), t("Custom provider"));
c.dataset.pick = "custom";
c.title = t("any OpenAI or Anthropic compatible URL");
c.onclick = () => { editing = { custom: true }; draft = null; renderProviders(); };
head.append(q, c);
const imp = el("button", "text", t("Import…"));
imp.title = t("Bring over providers set up in other apps");
imp.onclick = openImportApps;
@@ -7269,20 +7274,11 @@ function renderAdd() {
const none = el("div", "none");
none.append(t("Nothing called “{q}”. ", { q: presetQuery.trim() }));
const b = el("button", "link", t("Add it as a custom provider"));
b.onclick = () => { editing = { custom: true }; draft = null; renderProviders(); };
b.onclick = c.onclick;
const pl = el("button", "link", t("look for a plugin"));
pl.onclick = () => openPlugins(presetQuery.trim());
none.append(b, t(", or "), pl);
tiles.append(none);
} else if (!f) {
// a vendor not listed: one line under them all
const foot = el("div", "custom-foot");
const c = el("button", "custom" + (editing?.custom ? " on" : ""));
c.append(svg(PLUS, 13, 1.8), el("span", "", t("Custom provider")));
c.dataset.pick = "custom";
c.onclick = () => { editing = { custom: true }; draft = null; renderProviders(); };
foot.append(c, el("span", "hint", t("any OpenAI or Anthropic compatible URL")));
tiles.append(foot);
}
};
drawTiles();
@@ -0,0 +1,114 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// The add sheet's custom provider is in sight as the sheet opens (jackutan on
// X: hard to find): a button beside the search, above every preset, kept
// while searching, where it was one line under every section and gone while
// searching. A search that finds nothing still offers "Add it as a custom
// provider". Every language, wide and narrow; the API is faked.
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(process.env.MAGPIE_ASSETS || path.join(__dirname, "../assets"));
const preset = (id, name, kind) => ({ id, name, icon: "openai", kind, chat: `https://api.${id}.example.com/v1`, added: false });
// enough presets that the sections run past a short window
const presets = [];
for (const kind of ["vendor", "relay", "local"]) for (let i = 0; i < 18; i++) presets.push(preset(kind + i, kind[0].toUpperCase() + kind.slice(1) + " " + i, kind));
const providers = [{ id: "openrouter", name: "OpenRouter", icon: "openai", preset: "relay0", models: [], agents: [], key: { set: true, masked: "sk-…ab12" } }];
function server(lang) {
return async (route) => {
const url = new URL(route.request().url());
const json = (data) => route.fulfill({ json: data });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` });
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" } });
if (url.pathname === "/api/providers") return json({ providers, presets, excluded: [], gateway: { running: true, window: true } });
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
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)];
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
};
}
const L = {
en: { custom: "Custom provider", hint: "any OpenAI or Anthropic compatible URL", none: "Add it as a custom provider" },
zh: { custom: "自定义供应商", hint: "任意 OpenAI / Anthropic 兼容的 URL", none: "添加为自定义供应商" },
"zh-TW": { custom: "自定義供應商", hint: "任意 OpenAI / Anthropic 相容的 URL", none: "新增為自定義供應商" },
ja: { custom: "カスタムプロバイダ", hint: "OpenAI または Anthropic 互換の任意の URL", none: "カスタムプロバイダとして追加" },
de: { custom: "Benutzerdefinierter Anbieter", hint: "jede OpenAI- oder Anthropic-kompatible URL", none: "Als benutzerdefinierten Anbieter hinzufügen" },
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": the custom provider is in sight as the add sheet opens", async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
for (const lang of Object.keys(L)) for (const width of [980, 761, 420]) {
await t.test(lang + " " + width, async () => {
const w = L[lang];
const ctx = await browser.newContext({ viewport: { width, height: 560 }, reducedMotion: "reduce" });
t.after(() => ctx.close());
const page = await ctx.newPage();
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang));
await page.goto("http://magpie.test/?view=providers");
await page.locator("#addProvider").click();
const sheet = page.locator("#addSheet");
await sheet.locator(".tile").first().waitFor();
// beside the search, above the first preset, in the window as it opens
const custom = sheet.locator(".row-head .custom");
assert.equal(await custom.count(), 1);
assert.equal((await custom.textContent()).trim(), w.custom);
assert.equal(await custom.getAttribute("title"), w.hint);
const box = await page.evaluate(() => {
const r = (e) => e.getBoundingClientRect();
const c = document.querySelector("#addSheet .row-head .custom"), head = c.parentElement, find = head.querySelector(".find");
const tile = document.querySelector("#addSheet .tile");
const els = [...head.children].map(r);
return {
c: r(c), find: r(find), tile: r(tile), head: r(head), sheet: r(document.querySelector("#addSheet")), vw: innerWidth, vh: innerHeight,
overlap: els.some((a, i) => els.some((b, j) => i < j && a.width && b.width && a.left < b.right - 0.5 && b.left < a.right - 0.5 && a.top < b.bottom - 0.5 && b.top < a.bottom - 0.5)),
out: [...head.children].filter((e) => r(e).width && (r(e).left < r(head).left - 1 || r(e).right > Math.min(r(head).right, innerWidth) + 1)).map((e) => e.textContent || e.className),
wraps: c.scrollWidth > c.clientWidth + 1, lines: Math.round(r(c).height),
};
});
assert(box.c.top >= 0 && box.c.bottom <= box.vh, "in the window: " + JSON.stringify(box.c));
assert(box.c.left >= box.sheet.left - 1 && box.c.right <= Math.min(box.sheet.right, box.vw) + 1, "inside the sheet: " + JSON.stringify([box.c, box.sheet]));
assert(box.c.bottom <= box.tile.top, "above the presets");
assert(Math.abs((box.c.top + box.c.bottom) / 2 - (box.find.top + box.find.bottom) / 2) <= 2, "on the search's line");
assert(!box.overlap, "the head's controls apart");
assert(box.out.length === 0, "the head's controls inside the sheet: " + box.out);
assert(!box.wraps && box.lines <= 26, "one line, unclipped: " + box.lines);
if (process.env.ARTIFACT_DIR) await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}.png`) });
// no second entry at the foot
assert.equal(await sheet.locator(".custom-foot").count(), 0);
// kept while a search finds something
await sheet.locator(".find").fill(lang === "en" ? "relay 1" : "Relay 1");
await sheet.locator(".tile").first().waitFor();
assert(await custom.isVisible());
// and one that finds nothing still offers it in its line
await sheet.locator(".find").fill("zzqq");
const none = sheet.locator(".none button", { hasText: w.none });
await none.waitFor();
assert(await custom.isVisible());
await none.click();
await page.locator(".editor.new").waitFor();
await page.keyboard.press("Escape");
await page.locator("#modal").waitFor({ state: "hidden" });
// the head's button opens the custom editor
await sheet.locator(".find").fill("");
await custom.click();
await page.locator(".editor.new").waitFor();
assert.deepEqual(errors, []);
});
}
});
}
+7 -7
View File
@@ -8,8 +8,8 @@
// subscription's account count beside it when more than one. A vendor's
// global and China presets are one row with nothing added to it, the
// regions' hosts in its title, its editor switching between them with
// the key kept. A custom provider is one line
// under them all, gone while searching. English and Chinese; no backend,
// the key kept. A custom provider is a button
// beside the search, kept while searching. English and Chinese; no backend,
// the API is faked here.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
@@ -137,13 +137,13 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.match(kt, new RegExp(w.china + " api\\.moonshot\\.cn"));
assert.match(kt, /api\.moonshot\.example\.com/);
// the custom provider: one line at the foot, gone while searching
const foot = sheet.locator(".custom-foot");
assert.equal(await foot.locator(".custom").textContent(), w.custom);
assert.equal(await foot.locator(".hint").textContent(), w.customHint);
// the custom provider: beside the search, kept while searching
const custom = sheet.locator(".row-head .custom");
assert.equal(await custom.textContent(), w.custom);
assert.equal(await custom.getAttribute("title"), w.customHint);
await sheet.locator(".find").fill("deep");
assert.deepEqual(await rows.locator(".n").allTextContents(), ["DeepSeek"]);
assert.equal(await foot.count(), 0);
assert.equal(await custom.count(), 1);
await sheet.locator(".find").fill("china");
assert.deepEqual(await rows.locator(".n").allTextContents(), ["Kimi"]);
await sheet.locator(".find").fill("");
+1 -1
View File
@@ -85,7 +85,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const posts = [];
const { page, errors } = await open(t, posts);
await page.locator("#addProvider").click();
await page.locator("#addSheet .custom-foot .custom").click();
await page.locator("#addSheet .row-head .custom").click();
const ed = page.locator(".editor.new");
await ed.locator(".add-models").waitFor();
const L = await page.evaluate(() => ({ name: t("e.g. My Relay"), add: t("Add") }));
@@ -57,7 +57,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.goto("http://magpie.test/?view=providers");
const S = L[lang];
await page.locator("#addProvider").click();
await page.locator("#addSheet .custom-foot .custom").click();
await page.locator("#addSheet .row-head .custom").click();
const ed = page.locator(".editor.new");
await ed.locator(".base-url").waitFor();
await ed.locator(`input[placeholder="${S.name}"]`).fill("Gem Relay");
@@ -66,7 +66,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
hint: zh ? "可选:用「获取模型」从供应商列表中勾选,或直接填写模型 ID;不选则保存后自动获取模型列表。" : "Optional: Fetch models to pick from the vendor's list, or type ids; none picked, magpie asks for the list after saving.",
};
await page.locator("#addProvider").click();
await page.locator("#addSheet .custom-foot .custom").click();
await page.locator("#addSheet .row-head .custom").click();
const ed = page.locator(".editor.new");
await ed.locator(".add-models").waitFor();
const field = ed.locator(".add-models .detect-row input");
@@ -135,7 +135,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.goto("http://magpie.test/?view=providers");
await page.locator("#addProvider").click();
await page.locator("#addSheet .custom-foot .custom").click();
await page.locator("#addSheet .row-head .custom").click();
await baseURL.waitFor();
await ed.locator("input[placeholder]").first().fill("Kimi");
@@ -83,7 +83,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.goto("http://magpie.test/?view=providers");
const T = (s) => tr(lang, s);
await page.locator("#addProvider").click();
await page.locator("#addSheet .custom-foot .custom").click();
await page.locator("#addSheet .row-head .custom").click();
const ed = page.locator(".editor.new");
await ed.locator(".detect").waitFor();
const detect = ed.getByRole("button", { name: T("Detect APIs"), exact: true });
@@ -56,7 +56,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// the add form's Fetch models
await page.locator("#addProvider").click();
await page.locator("#addSheet .custom-foot .custom").click();
await page.locator("#addSheet .row-head .custom").click();
const ed = page.locator(".editor.new");
await ed.locator(".add-models").waitFor();
await ed.locator('input[type="url"][placeholder="https://…/v1"]').first().fill("http://embed.test/v1");
@@ -64,7 +64,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const addNew = async (name) => {
await page.goto("http://magpie.test/?view=providers");
await page.locator("#addProvider").click();
await page.locator("#addSheet .custom-foot .custom").click();
await page.locator("#addSheet .row-head .custom").click();
await baseURL.waitFor();
await ed.locator('input[placeholder]').first().fill(name);
};
+1 -1
View File
@@ -120,7 +120,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// a custom System One: probed at its address, saved as decide
await page.goto("http://magpie.test/?view=providers");
await page.locator("#addProvider").click();
await sheet.locator(".custom-foot .custom").click();
await sheet.locator(".row-head .custom").click();
await ed.waitFor();
await ed.locator("input").first().fill("My Decider");
await ed.locator(".segs .opt", { hasText: "System One" }).click();