From 74c67785c8a8eb019fcf229a95a9910042ef27bc Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 5 Oct 2026 21:44:49 +0800 Subject: [PATCH] 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) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- internal/gui/assets/app.js | 4 +- internal/gui/assets/i18n.js | 6 + internal/gui/assets/routing.css | 3 + internal/gui/assets/routing.js | 60 +++++-- internal/gui/tests/README.md | 10 ++ internal/gui/tests/group-pick-filter.test.cjs | 154 ++++++++++++++++++ 6 files changed, 225 insertions(+), 12 deletions(-) create mode 100644 internal/gui/tests/group-pick-filter.test.cjs diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index c774eea64..7f4b1b693 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -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) { diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index a94f7a3f5..bb67c1ebe 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -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", diff --git a/internal/gui/assets/routing.css b/internal/gui/assets/routing.css index da0169479..4d5a789c8 100644 --- a/internal/gui/assets/routing.css +++ b/internal/gui/assets/routing.css @@ -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; } diff --git a/internal/gui/assets/routing.js b/internal/gui/assets/routing.js index 7f4c72fc1..4216e024b 100644 --- a/internal/gui/assets/routing.js +++ b/internal/gui/assets/routing.js @@ -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); }; diff --git a/internal/gui/tests/README.md b/internal/gui/tests/README.md index a4d4d50ac..072b798cf 100644 --- a/internal/gui/tests/README.md +++ b/internal/gui/tests/README.md @@ -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 diff --git a/internal/gui/tests/group-pick-filter.test.cjs b/internal/gui/tests/group-pick-filter.test.cjs new file mode 100644 index 000000000..1b39137c3 --- /dev/null +++ b/internal/gui/tests/group-pick-filter.test.cjs @@ -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