gui: a group's model picker ticks a member with its reasoning fixed and takes it out on a click, and the routing groups can be filtered by name and model (#907, Moody-Sin; PAMI on Discord)

Picker. In a group's Add a model picker, a model already in the group as a member with fixed reasoning (deepseek/deepseek-v4-pro:max) was not ticked. Clicking it added deepseek/deepseek-v4-pro a second time. The picker matched members by their exact id. A model is now matched by the member it is in the group as, itself or with an effort. That member is ticked, and a click takes it out, together with its fast/off/rules entries, as for any member. A member that a pattern put in still gets the warning. The note naming the other groups a model is in (since v0.1.989) is cut off by its ellipsis when there are several groups, so it now shows in full on hover (title).

Groups filter. With many routing groups one was hard to find. A filter now sits over the list, beside Select and New group, whenever there are two groups or more. It keeps the groups that match every word typed, against the name, the id, a member's id and its provider and model names, and a pattern. The keyboard stays in the box as the list is redrawn. Escape clears it, and when nothing matches the list says so. The group being edited stays listed whatever the filter. Select's "all" picks only the groups shown. A move (Alt+↑/↓ or the menu) goes past the card listed next to it. en/zh/ja/de.

Tested in a sandbox HOME with magpie web (this build, port 3511, no gateway): five groups over DeepSeek, Kimi and GLM. "kimi" kept Main, Long context reasoning heavy and Backup. In Main's picker, deepseek-v4-pro (in Main as :max) and kimi-k3 were ticked, and each note named the other groups, whole in its title.

group-pick-filter.test.cjs is new (WebKit and Chromium, en and zh). It covers the tick and the click out for a:two:max with no duplicate saved, the note's tooltip, the filter by model name, id, every word and name, none matching, Escape, the keyboard kept, no scroll, no select and no left border. It fails without the change. With only the picker matching put back, it fails on "a member with its effort is not ticked".

The group-*, routing-effort*, routing-manual, routing-save*, routing-steady, routing-compact, click-scroll, claude-picker-fold and agent-model-groups tests pass in WebKit (77). go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass. internal/gateway failed once in the full run under load and passed alone.
This commit is contained in:
yetone
2026-10-05 21:51:18 +08:00
parent 9dda306a33
commit 74c67785c8
6 changed files with 225 additions and 12 deletions
+3 -1
View File
@@ -3893,7 +3893,9 @@ function renderList() {
const path = pathTag(o);
if (path) { words.append(path); note = note.replace(/(^| · )via magpie$/, ""); }
if (q && o.group && !note) note = o.group;
if (note) words.append(el("span", "n", note));
// a note cut off by its ellipsis (the other groups a model is in,
// #907) reads whole on hover
if (note) { const n = el("span", "n", note); n.title = note; words.append(n); }
li.append(words);
if (o.run) li.title = t(DISCONNECT_TIP, { agent: pick.agent.name });
if (pick.modelPicker && o.value && !o.custom && !o.run) {
+6
View File
@@ -2269,6 +2269,8 @@ const I18N = {
"{n} keys for {api}": "{n} 个 {api} 密钥",
"New group": "新建组",
"models agents pick as one": "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.": "还没有路由组。两个供应商都提供的模型会自动成组;「新建组」可组合任意模型。",
"1 found group removed": "已移除 1 个自动创建的组",
"{n} found groups removed": "已移除 {n} 个自动创建的组",
@@ -5621,6 +5623,8 @@ const I18N = {
"{n} keys for {api}": "{api} 用のキー {n} 個",
"New group": "新しいグループ",
"models agents pick as one": "エージェントが 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 つのプロバイダが提供するモデルは自動でグループになります。「新しいグループ」で好きなモデルをまとめられます。",
"1 found group removed": "自動作成のグループ 1 件を削除済み",
"{n} found groups removed": "自動作成のグループ {n} 件を削除済み",
@@ -8964,6 +8968,8 @@ 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",
"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.",
"1 found group removed": "1 gefundene Gruppe entfernt",
"{n} found groups removed": "{n} gefundene Gruppen entfernt",
+3
View File
@@ -272,6 +272,8 @@ button.rt-session { cursor: pointer; }
/* routing groups, and the providers routing over several of their own */
.rt-gsec { display: grid; gap: 6px; margin-top: 16px; }
.rt-gsec .row-head .note { margin-right: 6px; }
/* the groups filtered by name and model, beside Select and New group */
.rt-gsec .rt-gfilter { width: 190px; min-width: 0; flex: 0 1 190px; height: 24px; margin: 0 6px 0 4px; }
.rt-gsec .rt-pools { margin-bottom: 0; }
.rt-gsec .row-head + .list + .row-head { margin-top: 8px; }
.rt-groups > *, .rt-pools > * { border-top: 1px solid var(--line-2); }
@@ -390,6 +392,7 @@ button.rt-session { cursor: pointer; }
.rt-gsec .segs .opt { white-space: nowrap; }
@container (max-width: 520px) {
.rt-gsec .row-head .note { display: none; }
.rt-gsec .rt-gfilter { flex: 1 1 auto; width: auto; }
.rt-gedit { grid-template-columns: minmax(0, 1fr); gap: 4px; }
.rt-gedit label { text-align: left; padding-top: 8px; }
.rt-gedit .segs .opt { padding-left: 9px; padding-right: 9px; }
+49 -11
View File
@@ -2452,16 +2452,39 @@
// gSel: the groups picked to be removed together, while picking (lc on
// Discord: they could only be removed one at a time); null otherwise
let gSel = null;
// gQ: the groups filtered by name and by the models in them, as many
// as there may be (PAMI on Discord); kept across redraws, and focused
// again when one comes while typing
const gQ = el("input", "sess-filter rt-gfilter");
gQ.type = "search";
gQ.spellcheck = false;
gQ.autocomplete = "off";
gQ.oninput = () => renderGroups();
gQ.onkeydown = (e) => { if (e.key === "Escape" && gQ.value) { e.stopPropagation(); gQ.value = ""; renderGroups(); } };
// groupMatches: every word of the filter in the group's name, id, or a
// member's id or label (its provider and model names)
function groupMatches(g, words) {
const hay = [g.name, g.id, "group/" + g.id, ...g.members.flatMap((id) => [id, memberLabel(g, id)]), ...(g.patterns || []).map((p) => p.pattern)].join("\n").toLowerCase();
return words.every((w) => hay.includes(w));
}
function drawGroups() {
const shown = groups.groups.filter((g) => !g.hidden), hidden = groups.groups.filter((g) => g.hidden);
const all = groups.groups.filter((g) => !g.hidden), hidden = groups.groups.filter((g) => g.hidden);
const words = gQ.value.trim().toLowerCase().split(/\s+/).filter(Boolean);
// the group being changed stays, whatever the filter
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 && !shown.length) gSel = null;
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 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) {
gQ.placeholder = t("Filter groups and models");
head.push(gQ);
}
if (!gSel) {
// several removed at once: pick them, then Remove
if (shown.length > 1) {
if (all.length > 1) {
const pick = el("button", "text rt-gselect", t("Select"));
pick.title = t("Pick several groups to remove together");
pick.onclick = () => { gEdit = null; gSel = new Set(); renderGroups(); };
@@ -2470,12 +2493,14 @@
head.push(newBtn);
}
gHead.replaceChildren(...head);
if (typing && gQ.isConnected) { gQ.focus({ preventScroll: true }); try { gQ.setSelectionRange(a, b); } catch {} }
drawFound();
drawNames();
const rows = [];
if (gSel) rows.push(selectBar(shown));
if (gEdit && !gEdit.id) rows.push(groupEditor(null));
for (const g of shown) rows.push(gSel ? pickedRow(g) : gEdit?.id === g.id ? groupEditor(g) : groupRow(g));
if (!rows.length && all.length) rows.push(el("div", "none rt-gnone", t("No group or model matches “{q}”", { q: gQ.value.trim() })));
if (!rows.length) rows.push(el("div", "none rt-gnone", groups.found === false
? t("No group yet. New group makes one of any models you like.")
: t("No group yet. A model two of your providers serve becomes one on its own; New group makes one of any models you like.")));
@@ -2700,7 +2725,7 @@
if (!e.altKey || (e.key !== "ArrowUp" && e.key !== "ArrowDown")) return;
e.preventDefault();
e.stopPropagation();
moveGroup(g.id, shownGroups().indexOf(g.id) + (e.key === "ArrowUp" ? -1 : 1), true);
moveGroup(g.id, nextTo(g.id, e.key === "ArrowUp" ? -1 : 1), true);
};
// the card opens the editor; the handle its menu, but not for the
// click that ends a drag
@@ -2722,12 +2747,20 @@
const again = agentMenu?.anchor === anchor;
closeAgentMenu();
if (again) return;
const ids = shownGroups(), i = ids.indexOf(g.id);
const up = nextTo(g.id, -1), down = nextTo(g.id, 1);
openRowMenu(anchor, [
{ name: "Move up", icon: MOVE_UP, key: ALT + "↑", off: i <= 0, run: () => moveGroup(g.id, i - 1, true) },
{ name: "Move down", icon: MOVE_DOWN, key: ALT + "↓", off: i < 0 || i >= ids.length - 1, run: () => moveGroup(g.id, i + 1, true) },
{ name: "Move up", icon: MOVE_UP, key: ALT + "↑", off: up < 0, run: () => moveGroup(g.id, up, true) },
{ name: "Move down", icon: MOVE_DOWN, key: ALT + "↓", off: down < 0, run: () => moveGroup(g.id, down, true) },
]);
}
// nextTo: where a group moved one up (-1) or down goes, among them all:
// the place of the card listed next to it, so a filtered list moves it
// past the one the reader sees; -1 at either end
function nextTo(id, by) {
const seen = [...gList.querySelectorAll(".rt-group[data-id]")].map((r) => r.dataset.id);
const n = seen[seen.indexOf(id) + by];
return n === undefined || !seen.includes(id) ? -1 : shownGroups().indexOf(n);
}
// moveGroup puts the group at index `to` among the ones listed; the
// removed ones keep their places after them. The list is drawn in its new
// order at once and put back if the save fails.
@@ -3011,11 +3044,16 @@
.map((x) => ({ value: "group/" + x.id, label: x.name, note: noted("group/" + x.id, "group/" + x.id), icons: groupIcons(x), group: ROUTING_GROUPS, ref: "group/" + x.id }));
const options = [...subs, ...groups.models
.map((x) => ({ value: x.id, label: x.name || x.id, note: noted(x.providerName, x.id), icon: x.icon, group: x.providerName, ref: x.id, context: x.context }))];
openPicker({ id: "", name: "", fields: [] }, { key: "member", label: "model", value: "", options, multi: true, picked: (id) => d.members.includes(id), onPick: (id) => {
// the member a model is in the group as: itself, or with its
// reasoning fixed (deepseek/x:max), which is ticked as it and taken
// out by it rather than added twice (#907)
const holding = (id) => d.members.includes(id) ? id : d.members.find((m) => splitMember(m)[0] === id);
openPicker({ id: "", name: "", fields: [] }, { key: "member", label: "model", value: "", options, multi: true, picked: (id) => !!holding(id), onPick: (id) => {
if (!id) return;
if (!d.members.includes(id)) d.members.splice(named(), 0, id); // after those named, before a pattern's
else if (d.matched.includes(id)) return status(t("In the group by a pattern: switch it off to send it nothing"), "warn");
else { d.members.splice(d.members.indexOf(id), 1); rematch(); }
const m = holding(id);
if (!m) d.members.splice(named(), 0, id); // after those named, before a pattern's
else if (d.matched.includes(m)) return status(t("In the group by a pattern: switch it off to send it nothing"), "warn");
else { d.members.splice(d.members.indexOf(m), 1); rematch(); }
draw(); drawRules();
} }, addBtn, ev);
};
+10
View File
@@ -700,6 +700,16 @@ Add threw. A save the server refuses shows its error in sight, the editor
stays, and a second Add is posted, where the button stayed busy. At 600x420
and 1000x700, in Chromium and WebKit, English and Chinese.
`group-pick-filter.test.cjs` covers a group's Add a model picker and the
filter over the routing groups (#907; PAMI on Discord). A model in the group
with its reasoning fixed (a/two:max) is ticked, and a click takes that member
out instead of adding it a second time. A model that is in other groups names
them, and the whole note shows on hover. The filter keeps the groups whose
name, id or models match every word typed, and the keyboard stays in it.
When nothing matches it says so, and Escape clears it. The page never moves,
and there is no select or left border. In Chromium and WebKit, English and
Chinese.
`old-webkit.test.cjs` holds the page to Safari 15.0, the WebKit macOS 12 can
have (#220: a regex lookbehind in app.js, a syntax error before Safari 16.4,
left the panel with its headings and nothing working). Every script in
@@ -0,0 +1,154 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// #907 (Moody-Sin): in a group's Add a model picker, a model in the group
// with its reasoning fixed (a/two:max) was neither ticked nor taken out by
// a click: it was added a second time. PAMI on Discord: with many groups,
// one was hard to find.
// - The picker ticks a model in the group as itself or with an effort, and
// a click takes that member out (its effort with it), not adds it twice;
// a model in other groups says them, the whole note on hover.
// - Over the groups, a filter keeps those whose name, id or models match
// every word typed; the keyboard stays in it as the list is drawn, none
// matching says so, Escape clears it. Not one <select>, no left border.
// No click or keystroke moves the page. 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/one", name: "one", providerName: "A", icon: "generic" },
{ id: "a/two", name: "two", providerName: "A", icon: "generic" },
{ id: "b/three", name: "three", providerName: "B", icon: "generic" },
];
const words = {
en: { edit: "Edit", save: "Save", add: "Add another model", in: "in Other, Fast lane", filter: "Filter groups and models", none: "No group or model matches “zzz”" },
zh: { edit: "编辑", save: "保存", add: "再添加一个模型", in: "已在 Other, Fast lane", filter: "筛选路由组和模型", none: "没有路由组或模型匹配“zzz”" },
};
function serve(lang, posts) {
const groups = () => ({
models, pools: [],
groups: [
{ id: "g", name: "G", members: ["a/one", "a/two:max"], off: [], routing: "order", ready: true, memberInfo: [{ id: "a/one", ready: true }, { id: "a/two:max", ready: true }] },
{ id: "other", name: "Other", members: ["a/two"], off: [], routing: "order", ready: true, memberInfo: [{ id: "a/two", ready: true }] },
{ id: "fast", name: "Fast lane", members: ["a/two:low", "b/three"], off: [], routing: "order", ready: true, memberInfo: [{ id: "a/two:low", ready: true }, { id: "b/three", ready: true }] },
{ id: "auto-one", name: "Found one", members: ["a/one"], auto: true, ready: true, memberInfo: [{ id: "a/one", ready: true }] },
],
});
const state = { agents: [{ id: "codex", name: "Codex", path: "/test/codex", 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: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
}
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
if (url.pathname === "/api/groups") return json(groups());
if (url.pathname.startsWith("/api/groups/")) {
posts.push({ path: url.pathname, body: JSON.parse(r.request().postData() || "{}") });
return json(groups());
}
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}: a member with its effort ticked and taken out, the groups filtered`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await (await browser.newContext({ viewport: { width: 1100, height: 1400 }, reducedMotion: "reduce" })).newPage();
t.after(() => browser.close());
page.setDefaultTimeout(5000);
const errors = [], posts = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, posts));
await page.goto("http://magpie.test/?view=routing");
const card = (id) => page.locator(`.rt-group[data-id="${id}"]`);
await card("g").waitFor();
await page.locator(".rt-gsec").evaluate((x) => x.scrollIntoView({ block: "center" })); // as the reader would
await page.waitForTimeout(200);
const at = () => page.evaluate(() => [...document.querySelectorAll("*")].filter((e) => e.scrollTop).map((e) => [e.id || e.className, e.scrollTop]).join(";"));
const before = await at();
const listed = () => page.locator(".rt-groups .rt-group").evaluateAll((rs) => rs.map((r) => r.dataset.id));
// the filter: by name, by a model's name or id, every word
const q = page.locator(".rt-gsec .row-head input.rt-gfilter");
assert.equal(await q.getAttribute("placeholder"), w.filter);
await q.click();
await page.keyboard.type("three");
assert.deepEqual(await listed(), ["fast"], "by a model's name");
assert.equal(await page.evaluate(() => document.activeElement?.classList.contains("rt-gfilter")), true, "the keyboard left the filter");
await q.fill("a/two other");
assert.deepEqual(await listed(), ["other"], "every word, a model's id");
await q.fill("found");
assert.deepEqual(await listed(), ["auto-one"], "by name");
await q.fill("zzz");
assert.deepEqual(await listed(), []);
assert.equal((await page.locator(".rt-groups .rt-gnone").textContent()).trim(), w.none);
await q.focus();
await page.keyboard.press("Escape");
assert.equal(await q.inputValue(), "");
assert.deepEqual(await listed(), ["g", "other", "fast", "auto-one"]);
const border = await q.evaluate((x) => { const s = getComputedStyle(x); return [s.borderLeftWidth, s.borderLeftColor] + "|" + [s.borderRightWidth, s.borderRightColor]; });
assert.equal(border.split("|")[0], border.split("|")[1], "the filter has a left border of its own");
assert.equal(await at(), before, "the filter moved the page");
// the picker: a/two is in G as a/two:max
await card("g").locator("button", { hasText: w.edit }).click();
const ed = page.locator(".rt-gedit");
await ed.locator("button.rt-gadd", { hasText: w.add }).click();
const pop = page.locator("#pop");
const opt = (name) => pop.locator("li", { has: page.locator(".v", { hasText: new RegExp(`^${name}$`) }) }).first();
await opt("two").waitFor();
const cur = (name) => opt(name).evaluate((li) => li.classList.contains("cur"));
assert.equal(await cur("two"), true, "a member with its effort is not ticked");
assert.equal(await cur("one"), true);
assert.equal(await cur("three"), false);
const note = opt("two").locator(".n");
assert((await note.textContent()).includes(w.in), "the picker doesn't say the other groups two is in");
assert.equal(await note.getAttribute("title"), await note.textContent(), "the note has no tooltip");
const rows = () => ed.locator(".fbl").first().locator(".fbrow").count();
assert.equal(await rows(), 2);
await opt("two").click();
assert.equal(await rows(), 1, "clicked, it was not taken out");
assert.equal(await cur("two"), false);
await opt("two").click();
assert.equal(await rows(), 2);
assert.equal(await cur("two"), true);
await page.keyboard.press("Escape");
await pop.waitFor({ state: "hidden" });
const b = ed.locator("button.primary", { hasText: w.save });
await page.mouse.move(550, 600);
for (let i = 0; i < 10 && (await b.boundingBox()).y > 1400 - 160; i++) {
await page.mouse.wheel(0, 300);
await page.waitForTimeout(150);
}
const bb = await b.boundingBox();
await page.mouse.click(bb.x + bb.width / 2, bb.y + bb.height / 2);
await page.waitForFunction(() => !document.querySelector(".rt-gedit"));
const sent = posts.find((p) => p.path === "/api/groups/save");
assert.deepEqual(sent.body.members, ["a/one", "a/two"], "a member added twice, or its effort kept");
assert.equal(await page.locator("select").count(), 0, "a native select");
const missing = await page.evaluate(() => ["Filter groups and models", "No group or model matches “{q}”"]
.filter((k) => !I18N.zh[k] || !I18N.ja[k] || !I18N.de[k]));
assert.deepEqual(missing, [], "every string has its Chinese, Japanese and German");
assert.deepEqual(errors, []);
});
}
}