gui: the Routing page's head has New group, by Hide accounts, which opens an empty routing group's editor and brings it into view (#944, mintonight) — the groups' New group sat only at their own head, below the live stage and the requests, out of sight on a first look, so a user used the groups magpie finds for days without knowing one of any models could be made. The head's New group has a plus and a tooltip saying what a group is (zh/ja/de); its click opens the editor, scrolls to it only through scrollOnPurpose and focuses the name without a scroll of its own. The groups' own New group has the plus too. group-new-head.test.cjs is new (Chromium, WebKit; English, Chinese) and fails 4/4 without the change. go vet, go build (GOOS=linux nogui, GOOS=windows), go test -tags nogui ./... under a temp HOME and the group-* and click-scroll GUI tests pass.
This commit is contained in:
@@ -2314,6 +2314,7 @@ const I18N = {
|
||||
"{n} keys for {api}": "{n} 个 {api} 密钥",
|
||||
"New group": "新建组",
|
||||
"models agents pick as one": "Agent 当作一个模型来选",
|
||||
"Make a routing group of any models you like — agents pick it as one model": "用任意模型新建一个路由组,Agent 会把它当作一个模型来选",
|
||||
"Filter groups and models": "筛选路由组和模型",
|
||||
"No group or model matches “{q}”": "没有路由组或模型匹配“{q}”",
|
||||
"No group yet. A model two of your providers serve becomes one on its own; New group makes one of any models you like.": "还没有路由组。两个供应商都提供的模型会自动成组;「新建组」可组合任意模型。",
|
||||
@@ -5725,6 +5726,7 @@ const I18N = {
|
||||
"{n} keys for {api}": "{api} 用のキー {n} 個",
|
||||
"New group": "新しいグループ",
|
||||
"models agents pick as one": "エージェントが 1 つとして選ぶモデル群",
|
||||
"Make a routing group of any models you like — agents pick it as one model": "好きなモデルでルーティンググループを作ります。エージェントはそれを 1 つのモデルとして選べます",
|
||||
"Filter groups and models": "グループとモデルを絞り込む",
|
||||
"No group or model matches “{q}”": "「{q}」に一致するグループやモデルはありません",
|
||||
"No group yet. A model two of your providers serve becomes one on its own; New group makes one of any models you like.": "グループはまだありません。2 つのプロバイダが提供するモデルは自動でグループになります。「新しいグループ」で好きなモデルをまとめられます。",
|
||||
@@ -9127,6 +9129,7 @@ const I18N = {
|
||||
"{n} keys for {api}": "{n} Schlüssel für {api}",
|
||||
"New group": "Neue Gruppe",
|
||||
"models agents pick as one": "Modelle, die Agenten als eines wählen",
|
||||
"Make a routing group of any models you like — agents pick it as one model": "Eine Routing-Gruppe aus beliebigen Modellen erstellen – Agenten wählen sie als ein Modell",
|
||||
"Filter groups and models": "Gruppen und Modelle filtern",
|
||||
"No group or model matches “{q}”": "Keine Gruppe und kein Modell passt zu „{q}“",
|
||||
"No group yet. A model two of your providers serve becomes one on its own; New group makes one of any models you like.": "Noch keine Gruppe. Ein Modell, das zwei Ihrer Anbieter bereitstellen, wird automatisch zu einer; „Neue Gruppe“ fasst beliebige Modelle zusammen.",
|
||||
|
||||
@@ -107,6 +107,7 @@
|
||||
|
||||
<main class="view" id="view-routing" hidden>
|
||||
<div class="row-head"><span class="label" data-t>Routing</span><span class="rt-livedot" aria-hidden="true"></span><span class="note" data-t>live, as the gateway decides</span><span class="grow"></span>
|
||||
<button class="text rt-newgroup" id="rtNewGroup" type="button" data-tt="Make a routing group of any models you like — agents pick it as one model"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true"><path d="M8 3.5v9M3.5 8h9"/></svg><span data-t>New group</span></button>
|
||||
<button class="text rt-mask" id="rtMask" aria-pressed="false" data-tt="Mask the accounts on this page — email addresses and account names — for a screenshot to share"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9.9 4.2A10.4 10.4 0 0 1 12 4c6.5 0 10 8 10 8a17.6 17.6 0 0 1-2.2 3.2M6.6 6.6C3.9 8.4 2 12 2 12s3.5 8 10 8a9.7 9.7 0 0 0 5.4-1.6M9.9 9.9a3 3 0 0 0 4.2 4.2M2 2l20 20"/></svg><span data-t>Hide accounts</span></button></div>
|
||||
<section class="rt" id="rt"></section>
|
||||
<div class="rt-more" id="rtMore"></div>
|
||||
|
||||
@@ -135,8 +135,12 @@
|
||||
#view-routing .row-head { margin: 14px 0 6px; padding: 0 2px; gap: 0; }
|
||||
#view-routing .row-head .note { font-size: 11px; color: var(--faint); margin-left: 8px; }
|
||||
#view-routing .row-head .rt-livedot + .note { margin-left: 8px; }
|
||||
.rt-mask { display: inline-flex; align-items: center; gap: 5px; }
|
||||
.rt-mask svg { width: 13px; height: 13px; flex: none; }
|
||||
.rt-mask, .rt-newgroup { display: inline-flex; align-items: center; gap: 5px; }
|
||||
.rt-mask svg, .rt-newgroup svg { width: 13px; height: 13px; flex: none; }
|
||||
/* the routing groups' New group, at the top too: the groups sit below the
|
||||
requests, out of sight on a first look (#944) */
|
||||
.rt-newgroup { margin-right: 6px; }
|
||||
.rt-gnew { display: inline-flex; align-items: center; gap: 4px; }
|
||||
/* on, it says so in its struck eye and its words, a shade darker: a
|
||||
page tool, not a banner */
|
||||
.rt-mask[aria-pressed="true"] { color: var(--fg-2); }
|
||||
|
||||
@@ -2592,8 +2592,10 @@
|
||||
const shown = words.length ? all.filter((g) => gEdit?.id === g.id || groupMatches(g, words)) : all;
|
||||
if (gSel) gSel = new Set([...gSel].filter((id) => shown.some((g) => g.id === id)));
|
||||
if (gSel && !all.length) gSel = null;
|
||||
const newBtn = el("button", "text", t("New group"));
|
||||
newBtn.onclick = () => { gSel = null; gEdit = { id: "", draft: { name: "", members: [], match: [], matched: [], fast: [], off: [], routing: "", affinity: "", rules: [] } }; renderGroups(); };
|
||||
const newBtn = el("button", "text rt-gnew");
|
||||
newBtn.type = "button";
|
||||
newBtn.append(svg(PLUS, 11, 1.8), el("span", "", t("New group")));
|
||||
newBtn.onclick = () => newGroup();
|
||||
const head = [el("span", "label", t("Routing groups")), el("span", "grow"), el("span", "note", t("models agents pick as one"))];
|
||||
const typing = document.activeElement === gQ, [a, b] = [gQ.selectionStart, gQ.selectionEnd];
|
||||
if (all.length > 1 || gQ.value) {
|
||||
@@ -3649,6 +3651,23 @@
|
||||
if (ed && window.scrollOnPurpose?.(ev)) ed.scrollIntoView({ block: "center", behavior: "smooth" });
|
||||
ed?.querySelector("input")?.focus({ preventScroll: true });
|
||||
};
|
||||
// newGroup: an empty new group's editor. The groups sit below the
|
||||
// requests, out of sight on a first look, so the page's head has a New
|
||||
// group too (mintonight, #944), which brings the editor into view.
|
||||
function newGroup(ev) {
|
||||
gSel = null;
|
||||
gEdit = { id: "", draft: { name: "", members: [], match: [], matched: [], fast: [], off: [], routing: "", affinity: "", rules: [] } };
|
||||
renderGroups();
|
||||
if (!ev) return;
|
||||
const ed = gList.querySelector(".rt-gedit");
|
||||
if (ed && window.scrollOnPurpose?.(ev)) ed.scrollIntoView({ block: "center", behavior: "smooth" });
|
||||
ed?.querySelector("input")?.focus({ preventScroll: true });
|
||||
}
|
||||
const headNew = $("#rtNewGroup");
|
||||
if (headNew) headNew.onclick = async (ev) => {
|
||||
if (!groups) await loadGroups();
|
||||
if (groups) newGroup(ev);
|
||||
};
|
||||
const askedGroup = document.body.classList.contains("window") && params.get("newgroup");
|
||||
if (askedGroup) loadGroups().then(() => window.newGroupWith(askedGroup, ""));
|
||||
else loadGroups();
|
||||
|
||||
@@ -376,6 +376,14 @@ and the status line says which agent was moved to the model from one provider;
|
||||
clicked on, the found group is back. Neither click moves the page, the switch
|
||||
has no left-border accent, and every string has its Chinese.
|
||||
|
||||
`group-new-head.test.cjs` checks that a routing group of any models can be
|
||||
made from the top of the Routing page, in Chromium and WebKit, English and
|
||||
Chinese (mintonight, #944: the groups' New group sat below the requests, so
|
||||
only found groups were used). The page's head has New group with a plus and a
|
||||
tooltip saying what a group is, in sight while the groups are below the fold;
|
||||
its click opens an empty group's editor, brings it into view and focuses its
|
||||
name. The groups' own New group has the plus too. No left-border accent.
|
||||
|
||||
`name-suffix-where-named.test.cjs` checks the setting that says whether a
|
||||
provider's name or "· routing group" follows a name in the agents' lists (#868)
|
||||
where names are given, in Chromium and WebKit, English and Chinese. The
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// A routing group of any models is made with New group, which sat only at
|
||||
// the routing groups' head, below the requests: out of sight on a first
|
||||
// look, so a user used the found groups for days without knowing their
|
||||
// own could be made (mintonight, #944). The Routing page's head has a New
|
||||
// group too, by Hide accounts, with a plus and a tooltip saying what a
|
||||
// group is; its click opens an empty group's editor and brings it into
|
||||
// view, its name field focused. The groups' own New group has the plus as
|
||||
// well. No left-border accent. In English and Chinese, Chromium and WebKit.
|
||||
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 models = [
|
||||
{ id: "a/m", name: "m", providerName: "A", icon: "generic" },
|
||||
{ id: "b/m", name: "m", providerName: "B", icon: "generic" },
|
||||
];
|
||||
const info = (ids) => ids.map((id) => ({ id, ready: true }));
|
||||
const found = { id: "auto-m", name: "Model M", members: ["a/m", "b/m"], auto: true, ready: true, memberInfo: info(["a/m", "b/m"]) };
|
||||
|
||||
const words = {
|
||||
en: { btn: "New group", tip: "Make a routing group of any models you like — agents pick it as one model" },
|
||||
zh: { btn: "新建组", tip: "用任意模型新建一个路由组,Agent 会把它当作一个模型来选" },
|
||||
};
|
||||
|
||||
// requests enough to put the groups below the window's fold
|
||||
const now = Date.now();
|
||||
const routes = Array.from({ length: 30 }, (_, i) => ({
|
||||
id: "r" + i, seq: i + 1, at: new Date(now - i * 60000).toISOString(), agent: "claude", asked: "group/auto-m",
|
||||
model: "a/m", provider: "a", status: 200, ms: 900, ttft: 300, in: 100, out: 20, done: true,
|
||||
}));
|
||||
|
||||
function serve(lang) {
|
||||
const state = { agents: [{ id: "claude", name: "Claude Code", path: "/test/claude", fields: [] }], profiles: [], settings: { lang, theme: "light" } };
|
||||
return async (r) => {
|
||||
const url = new URL(r.request().url());
|
||||
const json = (data) => r.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
||||
if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json(state);
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/gateway/trace") {
|
||||
if (url.searchParams.get("wait")) return new Promise(() => {}); // nothing more comes
|
||||
return json({ mine: true, now: new Date().toISOString(), seq: 30, totals: { requests: 30, rerouted: 0, errors: 0 }, routes });
|
||||
}
|
||||
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
|
||||
if (url.pathname === "/api/groups") return json({ models, pools: [], deciders: [], found: true, groups: [found] });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } });
|
||||
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 r.fulfill({ body: await fs.readFile(file), contentType });
|
||||
};
|
||||
}
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh"]) {
|
||||
const w = words[lang];
|
||||
test(`${engine} ${lang}: New group in the Routing page's head`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const page = await (await browser.newContext({ viewport: { width: 1000, height: 560 }, reducedMotion: "reduce" })).newPage();
|
||||
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}-group-new-head.png`) });
|
||||
}
|
||||
await browser.close();
|
||||
});
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang));
|
||||
await page.goto("http://magpie.test/?view=routing");
|
||||
await page.locator(".rt-group", { hasText: "Model M" }).waitFor({ state: "attached" });
|
||||
|
||||
// the groups' own New group: with a plus
|
||||
const inList = page.locator(".rt-gsec > .row-head button", { hasText: w.btn });
|
||||
assert.equal(await inList.count(), 1);
|
||||
assert.equal(await inList.locator("svg").count(), 1, "the groups' New group has a plus");
|
||||
|
||||
// the page's head: a New group in sight on arrival, the groups not
|
||||
const head = page.locator("#view-routing > .row-head #rtNewGroup");
|
||||
await head.waitFor();
|
||||
assert.equal((await head.textContent()).trim(), w.btn);
|
||||
assert.equal(await head.getAttribute("title"), w.tip);
|
||||
assert.equal(await head.locator("svg").count(), 1);
|
||||
const vh = await page.evaluate(() => innerHeight);
|
||||
const hb = await head.boundingBox();
|
||||
assert(hb && hb.y >= 0 && hb.y + hb.height <= vh, "the head's New group is in sight");
|
||||
const gTop = await page.locator(".rt-gsec").evaluate((e) => e.getBoundingClientRect().top);
|
||||
assert(gTop > vh, `the groups are below the fold here (${gTop} > ${vh})`);
|
||||
const border = await head.evaluate((e) => { const c = getComputedStyle(e); return c.borderLeftWidth !== c.borderRightWidth || c.borderLeftColor !== c.borderRightColor; });
|
||||
assert.equal(border, false, "no left-border accent");
|
||||
|
||||
await head.click();
|
||||
const ed = page.locator(".rt-gsec .rt-gedit");
|
||||
await ed.waitFor();
|
||||
// an empty new group's editor, in view, its name field focused
|
||||
await page.waitForFunction(() => {
|
||||
const e = document.querySelector(".rt-gsec .rt-gedit");
|
||||
const r = e?.getBoundingClientRect();
|
||||
return r && r.top < innerHeight && r.bottom > 0;
|
||||
});
|
||||
assert.equal(await ed.locator("input").first().inputValue(), "");
|
||||
assert.equal(await ed.evaluate((e) => e.contains(document.activeElement) && document.activeElement.tagName), "INPUT");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user