gui: the provider editor's Advanced rows sit under four small headings
The provider editor's Advanced held some thirty rows in one run (item 19). They now sit under four small headings, Routing, Models, Limits and cost, and Connection, each row keeping its order inside its group; a row the list doesn't name stays with the one before it, and the headings show only when two groups are used. No page, row or fold moves elsewhere. advgroups.js is imported when Providers first draws, so it weighs nothing on the core script, and the editor opens with the headings already in place. Not done from item 19: a routing group's strategy stays under the group's Advanced. The owner folded it there on purpose (9edc6506e, 11-09, "the Add group form was too long"; and for providers on 11-12, "这些也要折叠在高级里"), and routing-advanced holds the provider side. New test: advanced-headings, for an account and a key, both engines, every language: the headings in order, Routing/Stays under Routing, Context window under Models, Requests at once under Limits and cost, Proxy under Connection, the heading across the whole row. Broken by hand: both groupAdvanced(advIn) calls removed, advanced-headings 10 of 10 red; put back, 10 of 10 green. Run (mote, Chromium and WebKit, en zh zh-TW ja de): - before the rebase, 23 GUI files: every one green except plugin-provider-options (my bug, fixed in this branch before the push) and settings-groups' "warm-ups and check-in in each service's provider editor", red the same way at fresh origin/main98c487d09(an extra "Spend extra usage" row; #6597, commented with the sha). - rebased on origin/main98c487d09: advanced-headings, plugin-provider-options, i18n-keys, routing-advanced, provider-prefs, settings-search, panel-profiles, builtins, chatgpt-usage-why, provider-concurrency, websearch-places, library-mcp-hub all green; go test ./internal/gui -run 'TestCoreScriptBudget|TestI18n|TestCSS' ok; ./internal/library, pii, plugin, provider and access ok; go vet ok. No budget raised. The Codex client row07d19510fadded to the Codex provider's Advanced sits under Connection, beside User-Agent: which client the requests say they come from. advanced-headings has a Codex account for it; with the row left out of the list, 10 of 10 red. Again at the pushed head, rebased on origin/main39c5040d7and07d19510f(mote, Chromium and WebKit, every language): advanced-headings, plugin-provider-options, i18n-keys, routing-advanced, provider-prefs, settings-search, panel-profiles, builtins, chatgpt-usage-why, provider-concurrency, websearch-places, library-mcp-hub, codex-client, codex-client-editor and nav-timeout all green; go test ./internal/gui -run 'TestCoreScriptBudget|TestI18n|TestCSS' ok; ./internal/library, pii, plugin, provider, access, ghtoken, davsync and gwmw ok, and the gateway and agent tests whose strings changed; gofmt -l empty; go vet, GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./internal/... clean. (GOOS=linux go vet ./... without nogui stops in Wails' cgo-only webview_window_linux.go, the same on origin/main 39c5040d7.) Not tried: the real app window, and Linux/Windows runs (cross-OS go vet only).
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// advGroups puts the provider editor's Advanced rows under four small
|
||||
// headings (item 19 of the 11-17 scan: some thirty rows in one run read as
|
||||
// a wall). Each row keeps its own order inside its group, and a row this
|
||||
// list doesn't name stays with the row before it. A heading shows only
|
||||
// when Advanced holds rows of two groups or more. app.js's groupAdvanced
|
||||
// imports this when an editor first opens, so it weighs nothing on the
|
||||
// core.
|
||||
(() => {
|
||||
const GROUPS = [
|
||||
["Routing", ["Routing", "Rate limited", "Stays", "Resets", "Warm up", "Check in", "Claude Code", "Fallback", "Rests", "Errors"]],
|
||||
["Models", ["Context window", "Max output", "Compaction", "Compact at", "Images", "Web search"]],
|
||||
["Limits and cost", ["Requests at once", "Accounts at once", "Requests per minute", "Queue size", "Price rate", "Free for me", "Billing", "Rate windows", "Account balance", "Balance URL", "Balance field"]],
|
||||
["Connection", ["Headers", "Extra body", "Reply headers", "Request headers to pass", "Proxy", "Upstream", "Key header", "User-Agent", "Codex client", "Masking", "Certificate", "HTTP version", "WebSocket", "Agents"]],
|
||||
];
|
||||
window.advGroups = function (box) {
|
||||
if (box.dataset.grouped) return;
|
||||
box.dataset.grouped = "1";
|
||||
const of = new Map();
|
||||
GROUPS.forEach(([, labels], i) => labels.forEach((k) => of.set(t(k), i)));
|
||||
// a row is its label and the control after it; anything else (the
|
||||
// balance slot, a placeholder a lazy module fills) is a row of its own
|
||||
const rows = [];
|
||||
for (let n = box.firstChild; n; ) {
|
||||
const next = n.nextSibling;
|
||||
if (n.nodeName === "LABEL" && next) {
|
||||
rows.push({ nodes: [n, next], key: n.firstChild?.textContent?.trim() });
|
||||
n = next.nextSibling;
|
||||
} else {
|
||||
rows.push({ nodes: [n], key: n.classList?.contains("bal-slot") ? t("Account balance") : "" });
|
||||
n = next;
|
||||
}
|
||||
}
|
||||
let last = GROUPS.length - 1;
|
||||
for (const r of rows) last = r.group = of.has(r.key) ? of.get(r.key) : last;
|
||||
const used = new Set(rows.map((r) => r.group));
|
||||
const heads = used.size > 1;
|
||||
for (const [i, [name]] of GROUPS.entries()) {
|
||||
if (!used.has(i)) continue;
|
||||
if (heads) box.append(el("div", "adv-head", t(name)));
|
||||
for (const r of rows) if (r.group === i) box.append(...r.nodes);
|
||||
}
|
||||
};
|
||||
})();
|
||||
@@ -3976,6 +3976,8 @@ body:not(.side-nav) #addSheet > .row-head.stuck::before { opacity: 1; box-shadow
|
||||
the longest, on one line, rather than wrap a last 址 under it (#875) */
|
||||
.editor .more .inner { display: grid; grid-template-columns: minmax(var(--ed-lab, 72px), max-content) minmax(0, 1fr); gap: 10px 14px; align-items: first baseline; padding-top: 8px; }
|
||||
.editor .more .inner label { white-space: nowrap; }
|
||||
.editor .more .inner > .adv-head { grid-column: 1 / -1; font-size: 11px; font-weight: 600; color: var(--muted); margin-top: 8px; }
|
||||
.editor .more .inner > .adv-head:first-child { margin-top: 0; }
|
||||
.editor .warnbox { grid-column: 1 / -1; font-size: 12px; line-height: 1.5; color: var(--fg); background: color-mix(in srgb, var(--amber) 12%, transparent); border: 1px solid color-mix(in srgb, var(--amber) 35%, transparent); border-radius: 8px; padding: 8px 10px; }
|
||||
.editor .warnbox.soft { background: none; color: var(--amber); border: 0; padding: 0 0 0 var(--ed-at, 86px); }
|
||||
.editor.import .mchips .mchip { cursor: default; }
|
||||
|
||||
@@ -6180,6 +6180,7 @@ const setupPaste = (q) => {
|
||||
};
|
||||
function renderProviders(quiet) {
|
||||
pasteLoad();
|
||||
advMod();
|
||||
if (accountArranging || providerArranging) { accountRenderPending = true; return; }
|
||||
providersBehind = false;
|
||||
// a rebuild clamps the scroll to the top: put it back
|
||||
@@ -8076,6 +8077,11 @@ document.addEventListener("click", (e) => {
|
||||
if (closing) d.open = false;
|
||||
}, () => {});
|
||||
}, true); // before the editor, which keeps its clicks to itself
|
||||
// groupAdvanced: the editor's Advanced rows under small headings
|
||||
// (advgroups.js, fetched as Providers first draws, so an editor opens with
|
||||
// them in place)
|
||||
const advMod = () => (advMod.p ||= import("./advgroups.js"));
|
||||
const groupAdvanced = (b) => self.advGroups ? advGroups(b) : advMod().then(() => b.isConnected && advGroups(b), () => {});
|
||||
// advancedSet says whether a setting under the editor's Advanced is set,
|
||||
// which opens it: none hides behind a fold
|
||||
function advancedSet(d, p) {
|
||||
@@ -9760,6 +9766,7 @@ function drawEditor(p, presetID) {
|
||||
const urls = [p.chat, p.responses, p.anthropic].filter(Boolean);
|
||||
if (urls.length && !urls.some((u) => u.startsWith("plugin://"))) ed.append(...field(t("Endpoints"), renderEndpoints(p, p)));
|
||||
ed.append(adv);
|
||||
groupAdvanced(advIn);
|
||||
const bar = el("div", "bar");
|
||||
// removing only hides it from magpie; the agent stays signed in
|
||||
const del = el("button", "text danger", t("Remove"));
|
||||
@@ -10339,6 +10346,7 @@ function drawEditor(p, presetID) {
|
||||
ed.append(...row);
|
||||
}
|
||||
ed.append(adv);
|
||||
groupAdvanced(advIn);
|
||||
|
||||
if (custom) {
|
||||
const more = edAligned(el("details", "more"));
|
||||
|
||||
@@ -5074,6 +5074,8 @@ const I18N = {
|
||||
"The options it runs with": "它运行时用的选项",
|
||||
"It runs with no options; its package suggests some": "它没有设置选项,包里有建议的选项",
|
||||
"Applied to the next request": "下一个请求起生效",
|
||||
"Limits and cost": "限额与费用",
|
||||
"Connection": "连接",
|
||||
"Its switches are in {name}'s editor": "它的开关在 {name} 的编辑器里",
|
||||
"Not set: these are its package's example": "未设置:这是包里给的示例",
|
||||
"Not JSON: {error}": "不是 JSON:{error}",
|
||||
@@ -10517,6 +10519,8 @@ const I18N = {
|
||||
"The options it runs with": "它執行時用的選項",
|
||||
"It runs with no options; its package suggests some": "它沒有設定選項,包裡有建議的選項",
|
||||
"Applied to the next request": "下一個請求起生效",
|
||||
"Limits and cost": "限額與費用",
|
||||
"Connection": "連線",
|
||||
"Its switches are in {name}'s editor": "它的開關在 {name} 的編輯器裡",
|
||||
"Not set: these are its package's example": "未設定:這是包裡給的範例",
|
||||
"Not JSON: {error}": "不是 JSON:{error}",
|
||||
@@ -15979,6 +15983,8 @@ const I18N = {
|
||||
"The options it runs with": "実行時に使うオプション",
|
||||
"It runs with no options; its package suggests some": "オプションは未設定です。パッケージに推奨のオプションがあります",
|
||||
"Applied to the next request": "次のリクエストから適用されます",
|
||||
"Limits and cost": "制限と費用",
|
||||
"Connection": "接続",
|
||||
"Its switches are in {name}'s editor": "スイッチは {name} のエディタにあります",
|
||||
"Not set: these are its package's example": "未設定:パッケージの例です",
|
||||
"Not JSON: {error}": "JSON ではありません:{error}",
|
||||
@@ -21465,6 +21471,8 @@ const I18N = {
|
||||
"The options it runs with": "Die Optionen, mit denen es läuft",
|
||||
"It runs with no options; its package suggests some": "Es läuft ohne Optionen; sein Paket schlägt welche vor",
|
||||
"Applied to the next request": "Gilt ab der nächsten Anfrage",
|
||||
"Limits and cost": "Limits und Kosten",
|
||||
"Connection": "Verbindung",
|
||||
"Its switches are in {name}'s editor": "Die Schalter sind im Editor von {name}",
|
||||
"Not set: these are its package's example": "Nicht gesetzt: das Beispiel seines Pakets",
|
||||
"Not JSON: {error}": "Kein JSON: {error}",
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// The provider editor's Advanced holds some thirty rows. They sit under
|
||||
// four small headings, Routing, Models, Limits and cost, and Connection
|
||||
// (advgroups.js; the 11-17 scan, item 19), each row in its own order
|
||||
// inside its group. For an account and a key, in every language, both
|
||||
// engines.
|
||||
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");
|
||||
const base = { icon: "generic", catalog: "", models: [{ id: "glm-5", name: "GLM-5", on: true }], agents: [], fallback: [], headers: {}, routing: "", affinity: "", ready: true };
|
||||
const sub = {
|
||||
...base, id: "workbuddy-ai", name: "WorkBuddy AI", chat: "", responses: "", anthropic: "", keyList: [],
|
||||
account: {
|
||||
agent: "workbuddy-ai", agentName: "WorkBuddy AI", user: "one@example.test", plan: "Pro",
|
||||
logins: ["one", "two"].map((n, i) => ({ user: `${n}@example.test`, plan: "Pro", active: i === 0, on: true })),
|
||||
},
|
||||
};
|
||||
// Codex's own Codex client row (07d19510f) goes under Connection, beside User-Agent
|
||||
const codex = {
|
||||
...base, id: "codex", name: "ChatGPT", chat: "", responses: "", anthropic: "", keyList: [],
|
||||
account: {
|
||||
agent: "codex", agentName: "Codex", user: "one@example.test", plan: "Plus",
|
||||
logins: ["one", "two"].map((n, i) => ({ user: `${n}@example.test`, plan: "Plus", active: i === 0, on: true })),
|
||||
},
|
||||
};
|
||||
const relay = {
|
||||
...base, id: "relay", name: "Relay", chat: "https://relay.example.invalid/v1", responses: "", anthropic: "", key: { set: true, masked: "sk-…1234" },
|
||||
keyList: [1, 2].map((i) => ({ id: `key-${i}`, name: `Key ${i}`, masked: `sk-…000${i}`, active: i === 1, on: true })),
|
||||
};
|
||||
|
||||
function serve(lang, p) {
|
||||
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
||||
const providers = { providers: [p], presets: [], excluded: [], gateway: { running: true, window: true } };
|
||||
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:${JSON.stringify(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/providers") return json(providers);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
await route.fulfill({ body: await fs.readFile(file), contentType: { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)] });
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// the heading each label sits under, in order, as the reader sees it
|
||||
const layout = () => {
|
||||
const inner = document.querySelector(".editor details.advanced > .inner");
|
||||
const out = [];
|
||||
let head = "";
|
||||
for (const n of inner.children) {
|
||||
if (n.classList.contains("adv-head")) { head = n.textContent; out.push({ head }); }
|
||||
else if (n.nodeName === "LABEL" && !n.hidden && n.textContent) out.push({ label: n.textContent, under: head });
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
||||
test(`${engine} ${lang}: the provider editor's Advanced rows sit under Routing, Models, Limits and cost, Connection`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
for (const p of [sub, codex, relay]) {
|
||||
const page = await (await browser.newContext({ viewport: { width: 900, height: 760 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, p));
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
await page.locator(".row.provider", { hasText: p.name }).first().click();
|
||||
await page.locator(".editor .accts").first().waitFor();
|
||||
await page.locator(".editor details.advanced > summary").click();
|
||||
await page.locator(".editor details.advanced .adv-head").first().waitFor();
|
||||
const said = await page.evaluate(() => Object.fromEntries(["Routing", "Models", "Limits and cost", "Connection", "Stays", "Context window", "Requests at once", "Headers", "Proxy", "Codex client"].map((k) => [k, t(k)])));
|
||||
const rows = await page.evaluate(layout);
|
||||
const at = `${p.name}: ${JSON.stringify(rows)}`;
|
||||
const heads = rows.filter((r) => r.head).map((r) => r.head);
|
||||
assert.deepEqual(heads, [said.Routing, said.Models, said["Limits and cost"], said.Connection].filter((h) => heads.includes(h)), `${at}: headings in order`);
|
||||
assert.ok(heads.length >= 3, `${at}: three headings or more`);
|
||||
assert.ok(rows[0].head, `${at}: a heading comes first`);
|
||||
const under = (label) => rows.find((r) => r.label === label)?.under;
|
||||
assert.equal(under(said.Routing), said.Routing, at);
|
||||
assert.equal(under(said.Stays), said.Routing, at);
|
||||
assert.equal(under(said["Context window"]), said.Models, at);
|
||||
assert.equal(under(said["Requests at once"]), said["Limits and cost"], at);
|
||||
assert.equal(under(said.Proxy), said.Connection, at);
|
||||
if (p === codex) assert.equal(under(said["Codex client"]), said.Connection, at);
|
||||
// the heading takes the whole row: the labels keep their column
|
||||
const box = await page.evaluate(() => {
|
||||
const h = document.querySelector(".editor .adv-head"), inner = h.parentElement;
|
||||
return { h: h.getBoundingClientRect().width, inner: inner.getBoundingClientRect().width - parseFloat(getComputedStyle(inner).paddingLeft) - parseFloat(getComputedStyle(inner).paddingRight) };
|
||||
});
|
||||
assert.ok(Math.abs(box.h - box.inner) < 2, `${at}: heading spans the row ${JSON.stringify(box)}`);
|
||||
assert.deepEqual(errors, [], at);
|
||||
await page.context().close();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user