gui: Settings' search finds settings on every page, ⌘K opens it (canlee886 on X)
canlee886 asked for a search that reaches a setting by keyword even when it lives outside Settings, such as routing group strategy and members. Settings' search now lists, under its own results, hits from the other pages, each under that page's name: Routing groups (a group by name, its strategy, its members), Providers (the editor's fields, e.g. Proxy, per provider), Agents, Library and Usage. Open goes to that page and row (a group's editor at the field, a provider's editor with the field lit) without scrolling anything the user didn't ask for. ⌘K / Ctrl+K, or the header's new magnifier, opens the search from any page. - The finder is a lazy module, finder.js (like provlinks.js), loaded on the first search. app.js only calls it, so TestCoreScriptBudget's budget is unchanged: core 1272271 (310 under), app 1087580 (668 under), at fe038cfac rebased on7f11dfc77. - The routing plugin exposes routingFind and routingOpenGroup for its groups. - The magnifier is the header's first thing to go when room runs short (a new "spare" stage before "tight"), so the brand still shows at 860px in the Windows window (brand.test.cjs went red without it). ⌘K and Settings' own box still reach the search there. - No native select, no accents. Rows reuse the settings-search look. Guard: find-anywhere.test.cjs, in Chromium and WebKit, in en, zh, zh-TW, ja and de at 560x420 (with the magnifier at 1100), and on magpie web at phone width. It types a group's name, "strategy" and Proxy, checks the pages listed, opens each, and checks the landing row is in view with no overflow. Red on the base (an archive of88b65d758plus the test): both engines time out, with no results from other pages. What was run, and where: - WSL magpie-desktop (xiaomi-gpu), at fe038cfac (rebased on7f11dfc77): gofmt -l clean; go vet -tags gtk3, GOOS=linux go vet -tags nogui and GOOS=windows go vet for ./internal/gui/... ok. go test -tags gtk3 ./internal/gui: only TestClipboardReadBack red, the same on the base (#7073, #7074). GUI files find-anywhere, brand, settings-search, settings-search-reach, header-zoom-fit, header-centre, header-presets, header-relang, click-scroll, text-size, group-editor-fits, group-editor-align, i18n-keys and menu-scroll: 181 pass, 29 fail. The reds are webkit click-scroll (#4385), webkit header-centre (#3479), menu-scroll in both engines (#1550) and webkit text-size (#1866), all red the same on the base run. - WSL magpie-desktop, before the rebase (on88b65d758): the whole GUI suite, 29497 tests, 28180 pass, 1317 fail. find-anywhere was green in both engines. Comparing by name against a base run over the 418 tests both covered: 13 ok to red and 13 red to ok, all noise except brand's "the logo and name in the header", fixed by the spare stage above. A near-file run then had the same reds on mine and the base, plus group-editor-selected (#5049, #6876), and the guard red only on the base. - mica: go vet before the rebase was ok. go test and the GUI suite there hit ENOSPC (disk full from other runs); the 8 tests it broke passed alone. That's why the suites moved to WSL. Not tried: the real desktop app (only the GUI suite's pages), and Windows' own webview.
This commit is contained in:
@@ -362,6 +362,7 @@ body.panel .seg { display: none; }
|
||||
they don't fit there, in the row rather than over it: halfway between what
|
||||
is either side of them, not a third of the room their left and two thirds
|
||||
their right (#442) */
|
||||
.top.spare #find { display: none; }
|
||||
.top.tight .brand > span:not(.logo), .top.tight .update span { display: none; }
|
||||
.top.tight .update { width: 22px; padding: 0; justify-content: center; margin-right: 4px; }
|
||||
.top.tight .update-hide { right: -5px; }
|
||||
@@ -4255,6 +4256,16 @@ body:not(.side-nav) #view-settings .set-head.stuck::before { opacity: 1; box-sha
|
||||
.set-searching .set-page::before { content: attr(data-part); display: block; margin: 4px 2px 6px; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
|
||||
.set-none { margin: 18px 2px; font-size: 13px; color: var(--muted); text-align: center; }
|
||||
.set-page > .list:not(:last-child) { margin-bottom: 8px; }
|
||||
/* what the search finds on the other pages (finder.js): a part per page
|
||||
after Settings' own, named by it; the place Open goes to is lit there */
|
||||
.set-else { display: contents; }
|
||||
.set-else[hidden] { display: none; }
|
||||
.find-more { margin: 0 2px; }
|
||||
body.web .row.pref.find-row { flex-wrap: nowrap; }
|
||||
body.web .row.pref.find-row > .who { flex-basis: auto; min-width: 0; }
|
||||
.find-lit { animation: flash 1.2s ease-out; border-radius: 6px; }
|
||||
/* the tray panel has Settings' button; the window's header finds */
|
||||
body.panel #find { display: none; }
|
||||
/* Plugins › Built-in: what the list is over its rows, and a row in use
|
||||
saying what uses it under its switch, which can't be turned off */
|
||||
.feat-say { margin: 2px 4px 10px; font-size: 12px; line-height: 1.45; color: var(--muted); }
|
||||
|
||||
+32
-58
@@ -19556,12 +19556,15 @@ if (!web) addEventListener("keydown", (e) => {
|
||||
}, true);
|
||||
// Cmd+, (Ctrl+, off the Mac) opens Settings, as it does in a Mac app
|
||||
// (#670), from the window or the panel alike and from a text box too; in a
|
||||
// browser tab it is the browser's.
|
||||
if (!web) addEventListener("keydown", (e) => {
|
||||
// browser tab it is the browser's. Cmd+K (Ctrl+K) is Settings' search,
|
||||
// which finds a setting on any page (findAnywhere), in a tab too.
|
||||
addEventListener("keydown", (e) => {
|
||||
const mod = /^Mac/.test(navigator.platform) ? e.metaKey && !e.ctrlKey : e.ctrlKey && !e.metaKey;
|
||||
if (!mod || e.altKey || e.shiftKey || e.repeat || (e.key !== "," && e.code !== "Comma")) return;
|
||||
if (!mod || e.altKey || e.shiftKey || e.repeat) return;
|
||||
const k = e.code === "KeyK" || e.key === "k" ? findAnywhere : !web && (e.key === "," || e.code === "Comma") ? openSettings : null;
|
||||
if (!k) return;
|
||||
e.preventDefault();
|
||||
openSettings();
|
||||
k();
|
||||
}, true);
|
||||
|
||||
// Font discovery is lazy and separate from polling the app's state. Drafts
|
||||
@@ -19997,59 +20000,11 @@ function setSetTab(tab, remember) {
|
||||
setSetTab(setTab);
|
||||
}
|
||||
|
||||
// Settings' search (sgfvdsg86265 on X): rows matching the words, shown or
|
||||
// English, by their text, section heading or part name; Escape restores.
|
||||
const setText = (n) => [n.textContent, ...[...n.querySelectorAll("[data-en]")].map((e) => e.dataset.en)].join(" ").toLowerCase();
|
||||
// Settings' search, and what it finds on the other pages: finder.js,
|
||||
// loaded the first time a search runs or the box is focused
|
||||
function findSettings() {
|
||||
if (!provLinksDrawn && setQuery) provLinksDraw();
|
||||
const v = $("#view-settings");
|
||||
v.classList.add("set-searching");
|
||||
const words = setQuery.split(/\s+/);
|
||||
let any = false;
|
||||
for (const id of SET_TABS) {
|
||||
const page = $("#setPage-" + id), tab = $("#setTab-" + id);
|
||||
const part = setText(tab) + (id === "otel" ? " otel" : ""); // not "usage" for Allowances
|
||||
let hits = 0, head = "";
|
||||
const lit = new Set();
|
||||
for (const n of page.querySelectorAll(".row-head, .row")) {
|
||||
if (n.matches(".row-head")) {
|
||||
head = setText(n);
|
||||
continue;
|
||||
}
|
||||
if (n.parentElement.closest(".row")) continue; // a row in a row goes with it
|
||||
const says = part + " " + head + " " + setText(n);
|
||||
const hit = words.every((w) => says.includes(w));
|
||||
n.classList.toggle("set-miss", !hit);
|
||||
let shows = hit;
|
||||
for (let a = n; shows && a && a !== page; a = a.parentElement) if (a.hidden) shows = false;
|
||||
if (shows && featureHides(n)) shows = false; // a built-in plugin switched off
|
||||
// a provider's link with no such provider to open
|
||||
const ps = n.agents && (providers || providersEarly?.got)?.providers;
|
||||
if (shows && ps && !ps.some((x) => n.agents.includes(x.account?.agent))) n.classList.add("set-miss"), shows = false;
|
||||
if (!shows) continue;
|
||||
hits++;
|
||||
lit.add(n.closest(".list") || n.parentElement);
|
||||
}
|
||||
// a section's heading and list go when nothing in them is left
|
||||
for (const box of page.querySelectorAll(".list")) {
|
||||
if (box.parentElement.closest(".row")) continue; // inside a row: it goes with the row
|
||||
box.classList.toggle("set-miss", ![...lit].some((l) => box.contains(l)));
|
||||
}
|
||||
for (const h of page.querySelectorAll(":scope > .row-head")) {
|
||||
const next = h.nextElementSibling;
|
||||
h.classList.toggle("set-miss", !next || next.classList.contains("set-miss"));
|
||||
}
|
||||
page.dataset.part = tab.textContent;
|
||||
page.hidden = !hits;
|
||||
any ||= hits > 0;
|
||||
}
|
||||
window.setFolds?.(v); // a hit under a folded Advanced (provlinks.js)
|
||||
// the built-ins that match (setfeats.js)
|
||||
if (window.setFeatsFind) any = setFeatsFind(words) > 0 || any;
|
||||
else import("./setfeats.js").then(() => setQuery && findSettings(), () => {});
|
||||
const none = $("#setNone");
|
||||
none.hidden = any;
|
||||
none.textContent = t("No setting matches “{q}”", { q: $("#setQ").value.trim() });
|
||||
if (window.setFind) setFind();
|
||||
else import("./finder.js").then(() => setQuery && setFind(), () => {});
|
||||
}
|
||||
function searchSettings(q) {
|
||||
setQuery = q.trim().toLowerCase();
|
||||
@@ -20060,11 +20015,13 @@ function searchSettings(q) {
|
||||
window.setFolds?.(v, 1);
|
||||
$("#setNone").hidden = true;
|
||||
window.setFeatsFind?.([]);
|
||||
window.findElse?.([]);
|
||||
setSetTab(setTab);
|
||||
}
|
||||
{
|
||||
const q = $("#setQ");
|
||||
q.oninput = () => searchSettings(q.value);
|
||||
q.onfocus = () => import("./finder.js").catch(() => {});
|
||||
q.onkeydown = (e) => {
|
||||
if (e.key === "Escape" && q.value) {
|
||||
e.preventDefault();
|
||||
@@ -23637,6 +23594,20 @@ async function openSettingsAt(e, tab, row) {
|
||||
row.classList.add("flash");
|
||||
}
|
||||
$("#prefs").onclick = () => { window.navFold?.("settings") || openSettings(); $("#prefs").blur(); };
|
||||
// Settings' search from any page (canlee886 on X): it finds the settings of
|
||||
// every page, finder.js. Back goes to the page it was brought up from
|
||||
async function findAnywhere() {
|
||||
$("#find").blur();
|
||||
if (mode !== "window") return openSettings();
|
||||
closeProtoMenu();
|
||||
closeAgentMenu();
|
||||
jumpFrom("settings");
|
||||
if (!await show("settings")) return;
|
||||
const q = $("#setQ");
|
||||
q.focus({ preventScroll: true });
|
||||
q.select();
|
||||
}
|
||||
$("#find").onclick = findAnywhere;
|
||||
|
||||
// The header's refresh reads again what the page shown draws (#844)
|
||||
function refreshKind() {
|
||||
@@ -23780,7 +23751,7 @@ function fitTop() {
|
||||
st?.classList.toggle("tight", st.scrollWidth > st.clientWidth);
|
||||
// a phone's browser: the tabs have a row of their own (app.css), at their size;
|
||||
// and beside the sidebar the header holds only where the reader is and the icons
|
||||
if (phoneWeb() || sideNav()) { top.classList.remove("tight", "cramped", "inrow", "crowded", "packed"); return; }
|
||||
if (phoneWeb() || sideNav()) { top.classList.remove("spare", "tight", "cramped", "inrow", "crowded", "packed"); return; }
|
||||
const fits = () => {
|
||||
const a = actions.getBoundingClientRect();
|
||||
// the buttons sit against the padding; under a page zoom (the text size)
|
||||
@@ -23793,7 +23764,10 @@ function fitTop() {
|
||||
const n = nav.getBoundingClientRect();
|
||||
return left + 8 <= n.left && n.right + 8 <= a.left;
|
||||
};
|
||||
top.classList.remove("tight", "cramped", "inrow", "crowded", "packed");
|
||||
top.classList.remove("spare", "tight", "cramped", "inrow", "crowded", "packed");
|
||||
if (fits()) return;
|
||||
// Find goes first: ⌘K and Settings' own box still reach it
|
||||
top.classList.add("spare");
|
||||
if (fits()) return;
|
||||
top.classList.add("tight");
|
||||
if (fits()) return;
|
||||
|
||||
@@ -0,0 +1,239 @@
|
||||
// Settings' search, and what it finds on the other pages (canlee886 on X):
|
||||
// a routing group's strategy, a provider's proxy or an agent are set on
|
||||
// their own pages, and a search for one in Settings said no setting
|
||||
// matched. Each page's places that match are listed after Settings' own
|
||||
// rows, under the page's name, and Open goes to that page and to the
|
||||
// place, lit. ⌘K (Ctrl+K off the Mac) and the header's magnifier bring the
|
||||
// search up from any page (app.js findAnywhere). app.js imports this the
|
||||
// first time a search runs, so it weighs nothing on the core.
|
||||
|
||||
// Settings' own rows matching the words, shown or English, by their text,
|
||||
// section heading or part name (sgfvdsg86265 on X); Escape restores
|
||||
const setText = (n) => [n.textContent, ...[...n.querySelectorAll("[data-en]")].map((e) => e.dataset.en)].join(" ").toLowerCase();
|
||||
window.setFind = function () {
|
||||
if (!provLinksDrawn && setQuery) provLinksDraw();
|
||||
const v = $("#view-settings");
|
||||
v.classList.add("set-searching");
|
||||
const words = setQuery.split(/\s+/);
|
||||
let any = false;
|
||||
for (const id of SET_TABS) {
|
||||
const page = $("#setPage-" + id), tab = $("#setTab-" + id);
|
||||
const part = setText(tab) + (id === "otel" ? " otel" : ""); // not "usage" for Allowances
|
||||
let hits = 0, head = "";
|
||||
const lit = new Set();
|
||||
for (const n of page.querySelectorAll(".row-head, .row")) {
|
||||
if (n.matches(".row-head")) {
|
||||
head = setText(n);
|
||||
continue;
|
||||
}
|
||||
if (n.parentElement.closest(".row")) continue; // a row in a row goes with it
|
||||
const says = part + " " + head + " " + setText(n);
|
||||
const hit = words.every((w) => says.includes(w));
|
||||
n.classList.toggle("set-miss", !hit);
|
||||
let shows = hit;
|
||||
for (let a = n; shows && a && a !== page; a = a.parentElement) if (a.hidden) shows = false;
|
||||
if (shows && featureHides(n)) shows = false; // a built-in plugin switched off
|
||||
// a provider's link with no such provider to open
|
||||
const ps = n.agents && (providers || providersEarly?.got)?.providers;
|
||||
if (shows && ps && !ps.some((x) => n.agents.includes(x.account?.agent))) n.classList.add("set-miss"), shows = false;
|
||||
if (!shows) continue;
|
||||
hits++;
|
||||
lit.add(n.closest(".list") || n.parentElement);
|
||||
}
|
||||
// a section's heading and list go when nothing in them is left
|
||||
for (const box of page.querySelectorAll(".list")) {
|
||||
if (box.parentElement.closest(".row")) continue; // inside a row: it goes with the row
|
||||
box.classList.toggle("set-miss", ![...lit].some((l) => box.contains(l)));
|
||||
}
|
||||
for (const h of page.querySelectorAll(":scope > .row-head")) {
|
||||
const next = h.nextElementSibling;
|
||||
h.classList.toggle("set-miss", !next || next.classList.contains("set-miss"));
|
||||
}
|
||||
page.dataset.part = tab.textContent;
|
||||
page.hidden = !hits;
|
||||
any ||= hits > 0;
|
||||
}
|
||||
window.setFolds?.(v); // a hit under a folded Advanced (provlinks.js)
|
||||
// the built-ins that match (setfeats.js)
|
||||
if (window.setFeatsFind) any = setFeatsFind(words) > 0 || any;
|
||||
else import("./setfeats.js").then(() => setQuery && setFind(), () => {});
|
||||
any = elseFind(words) > 0 || any;
|
||||
const none = $("#setNone");
|
||||
none.hidden = any;
|
||||
none.textContent = t("No setting matches “{q}”", { q: $("#setQ").value.trim() });
|
||||
};
|
||||
|
||||
// a place's words: its English and the reader's language, lower case
|
||||
const say = (...s) => s.filter(Boolean).map((x) => x + " " + t(x)).join(" ").toLowerCase();
|
||||
// the pages the sidebar has: one switched off is not offered
|
||||
const pageOn = (v) => {
|
||||
const b = $(`#nav button[data-view="${v}"]`);
|
||||
return !!b && !b.hidden && !featureHides(b);
|
||||
};
|
||||
// a place found lit, once more on a second Open
|
||||
function lightUp(n) {
|
||||
n.classList.remove("find-lit");
|
||||
void n.offsetWidth;
|
||||
n.classList.add("find-lit");
|
||||
}
|
||||
// to a page from Settings' search, Back coming back to the search
|
||||
async function goTo(v) {
|
||||
jumpFrom(v);
|
||||
return show(v);
|
||||
}
|
||||
// at a place on a page now shown: in sight when the click asked, and lit
|
||||
function landAt(n, go, v) {
|
||||
if (!n) return;
|
||||
if (go) { n.scrollIntoView({ block: "center" }); arrived($("#view-" + v)); }
|
||||
lightUp(n);
|
||||
}
|
||||
// a page's control drawn a moment after it is shown (a plugin page's tabs)
|
||||
async function drawn(sel) {
|
||||
for (let i = 0; i < 40; i++) {
|
||||
const n = $(sel);
|
||||
if (n) return n;
|
||||
await new Promise((r) => setTimeout(r, 50));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const LIB_TABS = [["instructions", "Instructions"], ["memory", "Memory"], ["mcp", "MCP servers", "mcp"], ["skills", "Skills"], ["hooks", "Hooks"],
|
||||
["env", "Environment variables", "env"], ["subagents", "Subagents"], ["plugins", "Claude plugins"]];
|
||||
const USE_TABS = [["usage", "Overview", "allowances quota"], ["requests", "Requests", "ledger"], ["sessions", "Sessions"], ["context", "Context"]];
|
||||
// what a provider's editor sets, and the words a reader may look for it by;
|
||||
// when says whether this provider's editor has it
|
||||
const PROV_FIELDS = [["Models", "model"], ["Accounts", "keys", (p) => p.account || p.keyList?.length], ["API key", "token", (p) => !p.account && !p.keyList?.length],
|
||||
["Endpoints", "base url address", (p) => !p.account], ["Proxy"], ["Fallback"], ["Context window"], ["Max output", "tokens", (p) => !p.account],
|
||||
["Concurrency"], ["Requests per minute", "rpm rate limit"], ["Price rate"], ["Free for me"], ["Headers", "", (p) => !p.account], ["Extra body", "", (p) => !p.account]];
|
||||
|
||||
// every place on the other pages: { page, key, name, sub, own, of, open }.
|
||||
// own is the place's own words, of its parent's (a group's or a provider's
|
||||
// name): a field of every group is listed only for words that say the
|
||||
// field, not for a group's name alone
|
||||
function places() {
|
||||
const out = [];
|
||||
for (const v of ["agents", "sessions", "library", "providers", "routing", "groups", "gateway", "usage", "masking", "plugins"]) {
|
||||
if (!pageOn(v)) continue;
|
||||
out.push({ page: v, key: v, name: t(pageName(v)), own: say(pageName(v)) + " " + v, open: () => goTo(v) });
|
||||
}
|
||||
if (pageOn("agents")) {
|
||||
for (const a of state.agents || []) out.push({ page: "agents", key: "a:" + a.id, name: a.name, own: (a.name + " " + a.id).toLowerCase(), open: async (go) => {
|
||||
if (await goTo("agents")) landAt($(`#agents .row.agent[data-id="${CSS.escape(a.id)}"]`), go, "agents");
|
||||
} });
|
||||
out.push({ page: "agents", key: "profiles", name: t("Profiles"), own: say("Profiles"), open: async (go) => { if (await goTo("agents")) landAt($("#view-agents .profiles"), go, "agents"); } });
|
||||
}
|
||||
const tabs = (v, list, sel) => {
|
||||
if (!pageOn(v)) return;
|
||||
for (const [id, name, more] of list) out.push({ page: v, key: v + ":" + id, name: t(name), own: say(name) + " " + (more || ""), open: async (go) => {
|
||||
if (!await goTo(v)) return;
|
||||
const b = await drawn(sel(id));
|
||||
if (!b) return;
|
||||
if (!b.classList.contains("on")) b.click();
|
||||
landAt($(sel(id)), go, v);
|
||||
} });
|
||||
};
|
||||
tabs("library", LIB_TABS, (id) => `#view-library .lib-tabs .opt[data-seg="${id}"]`);
|
||||
tabs("usage", USE_TABS, (id) => `#usageTab .opt[data-seg="${id}"]`);
|
||||
if (pageOn("providers")) {
|
||||
for (const p of providers?.providers || []) {
|
||||
const name = p.name || p.id;
|
||||
const open = (f) => async (go) => {
|
||||
if (f) advanced = { of: p.id, open: true }; // a field under Advanced is in sight
|
||||
jumpFrom("providers");
|
||||
await openProvider(p.id);
|
||||
if (view !== "providers") return;
|
||||
// the editor is drawn in the modal, and again as the list comes in:
|
||||
// the place is lit once the same one is there a moment later
|
||||
const at = () => {
|
||||
const ed = $("#modal .editor");
|
||||
return (f && ed && [...ed.querySelectorAll("label")].find((x) => x.textContent.trim().startsWith(t(f)))) || ed;
|
||||
};
|
||||
let n = await drawn("#modal .editor");
|
||||
for (let i = 0; i < 10 && n; i++) {
|
||||
await new Promise((r) => setTimeout(r, 150));
|
||||
const m = at();
|
||||
if (m === n) break;
|
||||
n = m;
|
||||
}
|
||||
if (view === "providers") landAt(n, go, "providers");
|
||||
};
|
||||
const of = (name + " " + p.id).toLowerCase();
|
||||
out.push({ page: "providers", key: "p:" + p.id, name, own: of, open: open(null) });
|
||||
for (const [f, more, when] of PROV_FIELDS) {
|
||||
if (when && !when(p)) continue;
|
||||
out.push({ page: "providers", key: "p:" + p.id + ":" + f, name: t(f), sub: name, own: say(f) + " " + (more || ""), of, open: open(f) });
|
||||
}
|
||||
}
|
||||
}
|
||||
// the routing groups, read by their page (plugins/routing/client.js)
|
||||
const gs = pageOn("groups") && window.routingFind?.();
|
||||
for (const g of gs?.groups || []) {
|
||||
const of = (g.name + " " + g.id + " " + (g.note || "")).toLowerCase();
|
||||
out.push({ page: "groups", key: "g:" + g.id, name: g.name, sub: g.note, own: of, open: (go) => { jumpFrom("groups"); return routingOpenGroup(g.id, "", go); } });
|
||||
for (const [f, name, words] of gs.fields) {
|
||||
out.push({ page: "groups", key: "g:" + g.id + ":" + f, name, sub: g.name, own: words, of, open: (go) => { jumpFrom("groups"); return routingOpenGroup(g.id, f, go); } });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// the rows a page shows before Show more
|
||||
const FIRST = 8;
|
||||
let elseMore = new Set(), elseWords = "";
|
||||
function elseFind(words) {
|
||||
let box = document.getElementById("setElse");
|
||||
if (!box) {
|
||||
box = el("div", "set-else");
|
||||
box.id = "setElse";
|
||||
$("#view-settings").append(box);
|
||||
}
|
||||
const q = words.join(" ");
|
||||
if (q !== elseWords) elseMore = new Set(), elseWords = q;
|
||||
const found = !words.length ? [] : places().filter((x) => {
|
||||
const all = x.own + " " + (x.of || "");
|
||||
return words.every((w) => all.includes(w)) && (!x.of || words.some((w) => x.own.includes(w)));
|
||||
});
|
||||
// a page's places, its own name first, then what a name says before a field
|
||||
const by = new Map();
|
||||
for (const x of found) {
|
||||
if (!by.has(x.page)) by.set(x.page, []);
|
||||
by.get(x.page).push(x);
|
||||
}
|
||||
const key = document.documentElement.lang + " " + q + " " + [...elseMore].join(",") + " " + found.map((x) => x.key + "=" + x.name + "/" + (x.sub || "")).join(" ");
|
||||
if (box.dataset.key === key) return found.length;
|
||||
box.dataset.key = key;
|
||||
const secs = [];
|
||||
for (const [v, list] of by) {
|
||||
list.sort((a, b) => !!a.of - !!b.of);
|
||||
const sec = el("section", "set-page find-page");
|
||||
sec.dataset.page = v;
|
||||
sec.dataset.part = t(pageName(v));
|
||||
const rows = el("div", "list prefs");
|
||||
const all = elseMore.has(v);
|
||||
for (const x of all ? list : list.slice(0, FIRST)) {
|
||||
const r = el("div", "row pref find-row");
|
||||
r.dataset.key = x.key;
|
||||
const who = el("div", "who");
|
||||
who.append(el("div", "name", x.name));
|
||||
if (x.sub) who.append(el("div", "sub", x.sub));
|
||||
const go = el("button", "text", t("Open"));
|
||||
go.type = "button";
|
||||
go.onclick = (e) => x.open(scrollOnPurpose(e, 3000));
|
||||
r.append(who, go);
|
||||
rows.append(r);
|
||||
}
|
||||
if (!all && list.length > FIRST) {
|
||||
const more = el("button", "text find-more", t("Show {n} more", { n: list.length - FIRST }));
|
||||
more.type = "button";
|
||||
more.onclick = () => { elseMore.add(v); elseFind(words); };
|
||||
sec.append(rows, more);
|
||||
} else sec.append(rows);
|
||||
secs.push(sec);
|
||||
}
|
||||
box.replaceChildren(...secs);
|
||||
// after the built-ins found, which setfeats.js adds once
|
||||
const feats = document.getElementById("setFeats");
|
||||
if (feats && feats.nextElementSibling !== box) feats.after(box);
|
||||
box.hidden = !found.length;
|
||||
return found.length;
|
||||
}
|
||||
window.findElse = elseFind;
|
||||
@@ -106,6 +106,10 @@
|
||||
<button class="icon" id="open" title="Open the main window" data-tt>
|
||||
<svg viewBox="0 0 16 16" width="14" height="14"><path d="M6 3H3.5A1.5 1.5 0 0 0 2 4.5v8A1.5 1.5 0 0 0 3.5 14h8a1.5 1.5 0 0 0 1.5-1.5V10M9 2h5v5M14 2 8 8" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
||||
</button>
|
||||
<!-- Settings' search, which finds a setting on any page (app.js findAnywhere) -->
|
||||
<button type="button" class="icon" id="find" title="Find a setting" data-tt data-keys="⌘K|Ctrl+K">
|
||||
<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><circle cx="7" cy="7" r="4.25"/><path d="m10.25 10.25 3.25 3.25"/></g></svg>
|
||||
</button>
|
||||
<button class="icon" id="prefs" title="Settings" data-tt data-keys="⌘,|Ctrl+,">
|
||||
<svg viewBox="0 0 24 24" width="14" height="14"><g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></g></svg>
|
||||
<span class="side-l" data-t>Settings</span></button>
|
||||
|
||||
@@ -9494,6 +9494,33 @@ function routingPage(part) {
|
||||
};
|
||||
gTicks();
|
||||
new MutationObserver(gTicks).observe(gView(), { attributes: true, attributeFilter: ["hidden"] });
|
||||
// Settings' search (app.js finder.js, canlee886 on X): the groups by name,
|
||||
// and what a group's editor sets, each with the words it is found by in
|
||||
// English and the reader's language: a group's strategy is its Routing
|
||||
const G_FIELDS = [["Name"], ["Note"], ["In agents’ lists", "hidden show"], ["Models", "members model"], ["Accounts", "keys"], ["Gateway keys"],
|
||||
["Masking", "redact"], ["Patterns", "match"], ["Model lists"], ["Routing", "strategy order turn", "Routing strategies", ...GROUP_ROUTE_OPTS.map((x) => x[1])],
|
||||
["Rate limited", "429"], ["Slow to start", "first token timeout"], ["Every member busy"], ["Context", "window"], ["Compact at", "compaction"], ["Stays", "affinity session sticky"]];
|
||||
window.routingFind = () => featuresOff.has("groups") || !groups ? null : {
|
||||
groups: groups.groups.filter((g) => !g.hidden).map((g) => ({ id: g.id, name: g.name || g.id, note: g.note || "" })),
|
||||
fields: G_FIELDS.map(([f, more = "", ...also]) => [f, t(f), [f, t(f), more, ...also.flatMap((x) => [x, t(x)])].join(" ").toLowerCase()]),
|
||||
};
|
||||
// routingOpenGroup: the group's editor, at field (its label, in English)
|
||||
// when given, in sight when the reader's click asked (go) and lit
|
||||
window.routingOpenGroup = async (id, field, go) => {
|
||||
if (gView().hidden && !(await window.show("groups"))) return;
|
||||
if (!groups) await loadGroups();
|
||||
const g = groups?.groups.find((x) => x.id === id);
|
||||
if (!g || (gEdit?.id !== id && !(await openGroupEditor(g)))) return;
|
||||
const ed = gList.querySelector(".rt-gedit");
|
||||
if (!ed) return;
|
||||
const l = field && [...ed.querySelectorAll("label")].find((x) => x.textContent.trim() === t(field));
|
||||
if (l?.closest("details")) l.closest("details").open = true;
|
||||
const at = l || ed;
|
||||
if (go) { at.scrollIntoView({ block: "center" }); window.arrived?.(gView()); }
|
||||
at.classList.remove("find-lit");
|
||||
void at.offsetWidth;
|
||||
at.classList.add("find-lit");
|
||||
};
|
||||
// newGroupWith: a new group's editor, opened with the model in it — a
|
||||
// model of a provider kept for routing groups that no group has, which
|
||||
// agents can reach no other way. The picker and the provider's editor
|
||||
|
||||
@@ -0,0 +1,232 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// A setting on another page is found from Settings' search (canlee886 on X:
|
||||
// a search that goes to the setting, a routing group's among them). ⌘K
|
||||
// (Ctrl+K off the Mac) and the header's magnifier bring the search up from
|
||||
// any page, its box focused. A group's strategy is found by "strategy" in
|
||||
// English and by "Routing strategies" in the language shown, a row per
|
||||
// group under the Routing groups page's name; a group by its name; a
|
||||
// provider's Proxy under Providers; Library's tabs under Library. Open goes
|
||||
// to that page, opens the group's editor (its Advanced too) or the
|
||||
// provider's, and lights the field, in sight; Back comes back to the
|
||||
// search. An Open no click asked for moves nothing. Nothing is posted. In
|
||||
// the smallest window (560 x 420) and magpie web on a phone (390 wide)
|
||||
// nothing runs off to the side. Every language, Chromium and WebKit; no
|
||||
// backend, the API is faked here. ARTIFACT_DIR gets screenshots.
|
||||
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 { provPrefsProviders } = require("./reader.cjs");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const models = [
|
||||
{ id: "oa/gpt-6.1-sol", name: "gpt-6.1-sol", providerName: "OpenAI", icon: "generic", context: 1000000 },
|
||||
{ id: "an/claude-opus-5-5", name: "claude-opus-5-5", providerName: "Anthropic", icon: "generic", context: 200000 },
|
||||
];
|
||||
const members = models.map((m) => m.id);
|
||||
const group = (id, name) => ({ id, name, members, routing: "order", ready: true, memberInfo: members.map((m) => ({ id: m, ready: true })) });
|
||||
const groups = { models, pools: [], groups: [group("sol", "Sol"), group("opus", "Opus pool")] };
|
||||
|
||||
function server(lang, posts, web) {
|
||||
const state = { agents: [{ id: "codex", name: "Codex", path: "/test/codex", fields: [] }], profiles: [], settings: { lang, theme: "light", textSize: 100 } };
|
||||
return async (route) => {
|
||||
const req = route.request(), url = new URL(req.url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (req.method() !== "GET" && url.pathname !== "/api/update/using" && url.pathname !== "/api/page-away") posts.push(url.pathname);
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:${web},textSize:100};` });
|
||||
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/settings") return json({ theme: "light", lang, textSize: 100, version: "0.1.400", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3425", proxyNow: "none", proxySource: "none", lanURLs: [], redactWords: [], fx: { rate: 7.2, at: new Date().toISOString(), stale: false } });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/providers") return json(provPrefsProviders(["codex"], { codex: "ChatGPT" }));
|
||||
if (url.pathname === "/api/groups") return json(groups);
|
||||
if (url.pathname === "/api/gateway/trace") {
|
||||
if (url.searchParams.get("wait")) return new Promise(() => {});
|
||||
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/usage/quotas") return json([]);
|
||||
if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 });
|
||||
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 route.fulfill({ body: await fs.readFile(file), contentType });
|
||||
};
|
||||
}
|
||||
|
||||
// the rows found on the other pages: each page's name and its rows
|
||||
const found = (page) => page.evaluate(() => [...document.querySelectorAll("#setElse .find-page")].filter((s) => s.getClientRects().length)
|
||||
.map((s) => [s.dataset.part, [...s.querySelectorAll(".find-row")].map((r) => [r.querySelector(".name").textContent, r.querySelector(".sub")?.textContent || ""])]));
|
||||
const overflow = (page) => page.evaluate(() => {
|
||||
const out = [], de = document.documentElement;
|
||||
if (de.scrollWidth > de.clientWidth) out.push("page " + de.scrollWidth + ">" + de.clientWidth);
|
||||
for (const v of document.querySelectorAll(".view:not([hidden])")) if (v.scrollWidth > v.clientWidth + 0.5) out.push(v.id + " " + v.scrollWidth + ">" + v.clientWidth);
|
||||
for (const r of document.querySelectorAll("#setElse .find-row")) {
|
||||
const b = r.getBoundingClientRect(), go = r.querySelector("button").getBoundingClientRect();
|
||||
if (go.right > b.right + 0.5) out.push("Open past its row: " + r.textContent);
|
||||
}
|
||||
return out;
|
||||
});
|
||||
const inSight = (loc) => loc.evaluate((e) => {
|
||||
const r = e.getBoundingClientRect();
|
||||
return r.height > 0 && r.top >= 0 && r.bottom <= innerHeight;
|
||||
});
|
||||
const viewIs = (page, v) => page.waitForFunction((v) => !document.querySelector("#view-" + v).hidden, v);
|
||||
|
||||
const LANGS = ["en", "zh", "zh-TW", "ja", "de"];
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(engine + ": a setting on any page, from Settings' search", async (t) => {
|
||||
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const shots = [];
|
||||
t.after(async () => {
|
||||
if (process.env.ARTIFACT_DIR) {
|
||||
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
||||
for (const [name, buf] of shots) await fs.writeFile(path.join(process.env.ARTIFACT_DIR, `${engine}-find-anywhere-${name}.png`), buf);
|
||||
}
|
||||
await browser.close();
|
||||
});
|
||||
const open = async (lang, posts, { width = 560, height = 420, web = false, at = "agents" } = {}) => {
|
||||
const context = await browser.newContext({ viewport: { width, height }, reducedMotion: "reduce" });
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
page.errors = [];
|
||||
page.on("pageerror", (e) => {
|
||||
if (engine === "webkit" && /due to access control checks/.test(e.message)) return; // a goto in WebKit can cut off a fetch (#1350)
|
||||
if (/^ResizeObserver loop completed with undelivered notifications/.test(e.message)) return;
|
||||
page.errors.push(e.message);
|
||||
});
|
||||
await page.route("**/*", server(lang, posts, web));
|
||||
await page.goto("http://magpie.test/?view=" + at);
|
||||
await viewIs(page, at);
|
||||
await page.waitForFunction(() => window.routingFind?.()?.groups.length === 2, null, { timeout: 30000 });
|
||||
return page;
|
||||
};
|
||||
const type = async (page, s) => {
|
||||
await page.locator("#setQ").fill(s);
|
||||
await page.waitForFunction(() => window.setFind && document.querySelector("#setElse"));
|
||||
await page.waitForTimeout(60);
|
||||
};
|
||||
|
||||
for (const lang of LANGS) {
|
||||
await t.test(lang, async () => {
|
||||
const posts = [];
|
||||
const page = await open(lang, posts);
|
||||
const tr = (s, vars) => page.evaluate(([s, vars]) => t(s, vars), [s, vars]);
|
||||
const mac = await page.evaluate(() => /^Mac/.test(navigator.platform));
|
||||
|
||||
// ⌘K from the Agents page: Settings' search, focused, Back to Agents
|
||||
await page.keyboard.press(mac ? "Meta+k" : "Control+k");
|
||||
await viewIs(page, "settings");
|
||||
assert.equal(await page.evaluate(() => document.activeElement?.id), "setQ");
|
||||
assert(await page.locator("#navBack").isVisible(), "Back goes to the page it came from");
|
||||
|
||||
// a group's strategy, by the English word and by the language's
|
||||
const routing = await tr("Routing");
|
||||
const strategyRows = [[await tr("Routing groups"), [[routing, "Sol"], [routing, "Opus pool"]]]];
|
||||
await type(page, "strategy");
|
||||
assert.deepEqual(await found(page), strategyRows);
|
||||
const sec = page.locator('#setElse .find-page[data-page="groups"]');
|
||||
assert.equal(await sec.evaluate((s) => getComputedStyle(s, "::before").content), JSON.stringify(await tr("Routing groups")));
|
||||
assert(await page.locator("#setNone").isHidden(), "found: no 'nothing matches'");
|
||||
assert.deepEqual(await overflow(page), []);
|
||||
shots.push([lang + "-strategy", await page.screenshot()]);
|
||||
await type(page, await tr("Routing strategies"));
|
||||
assert.deepEqual(await found(page), strategyRows);
|
||||
|
||||
// an Open no click asked for opens the editor and moves nothing
|
||||
await page.locator("#setElse .find-row", { hasText: "Opus pool" }).locator("button").evaluate((b) => b.click());
|
||||
await viewIs(page, "groups");
|
||||
const ed = page.locator(".rt-gedit");
|
||||
await ed.waitFor();
|
||||
const lit = ed.locator("label.find-lit");
|
||||
await lit.waitFor();
|
||||
assert.equal(await lit.textContent(), routing);
|
||||
assert.equal(await page.locator("#view-groups").evaluate((v) => v.scrollTop), 0, "no scroll the reader didn't ask for");
|
||||
assert.equal(await inSight(lit), false, "the field is below the fold at 420 high");
|
||||
|
||||
// Back: the search as it was; the reader's click on Sol's Routing
|
||||
await page.locator("#navBack").click();
|
||||
await viewIs(page, "settings");
|
||||
assert.equal(await page.locator("#setQ").inputValue(), await tr("Routing strategies"));
|
||||
await page.waitForFunction(() => document.querySelectorAll("#setElse .find-row").length === 2);
|
||||
await page.locator("#setElse .find-row", { hasText: "Sol" }).locator("button").click();
|
||||
await viewIs(page, "groups");
|
||||
await page.locator(".rt-gedit label.find-lit").waitFor();
|
||||
const name = page.locator(".rt-gedit input").first();
|
||||
assert.equal(await name.inputValue(), "Sol");
|
||||
const l = page.locator(".rt-gedit label.find-lit");
|
||||
assert.equal(await l.textContent(), routing);
|
||||
assert(await l.evaluate((x) => x.closest("details").open), "Advanced opened");
|
||||
await page.waitForFunction(() => {
|
||||
const r = document.querySelector(".rt-gedit label.find-lit").getBoundingClientRect();
|
||||
return r.top >= 0 && r.bottom <= innerHeight;
|
||||
});
|
||||
assert.deepEqual(await overflow(page), []);
|
||||
shots.push([lang + "-group-routing", await page.screenshot()]);
|
||||
|
||||
// a header short of room drops the magnifier before the name (⌘K stays)
|
||||
assert.equal(await page.locator("#find").isVisible(), false, lang + ": magnifier at 560");
|
||||
// a group by its name, from the header's magnifier: its row, not its fields
|
||||
await page.setViewportSize({ width: 1100, height: 700 });
|
||||
await page.locator("#find").click();
|
||||
await viewIs(page, "settings");
|
||||
assert.equal(await page.evaluate(() => document.activeElement?.id), "setQ");
|
||||
await type(page, "sol");
|
||||
assert.deepEqual(await found(page), [[await tr("Routing groups"), [["Sol", ""]]]]);
|
||||
await page.setViewportSize({ width: 560, height: 420 });
|
||||
|
||||
// a provider's Proxy, under Providers; Open lights it in the editor
|
||||
await type(page, await tr("Proxy"));
|
||||
const provs = await tr("Providers");
|
||||
assert.deepEqual((await found(page)).find(([p]) => p === provs), [provs, [[await tr("Proxy"), "ChatGPT"]]]);
|
||||
await page.locator('#setElse .find-page[data-page="providers"] .find-row button').click();
|
||||
await viewIs(page, "providers");
|
||||
const pl = page.locator("#modal .editor label.find-lit");
|
||||
await pl.waitFor();
|
||||
assert.equal((await pl.textContent()).trim(), await tr("Proxy"));
|
||||
|
||||
// Library's tabs under Library, the shortcut over the editor's modal
|
||||
await page.keyboard.press(mac ? "Meta+k" : "Control+k");
|
||||
await viewIs(page, "settings");
|
||||
await page.waitForFunction(() => document.querySelector("#modal").hidden, null, { timeout: 3000 }); // the editor's modal closed
|
||||
await type(page, "skills");
|
||||
const lib = await tr("Library");
|
||||
assert.deepEqual((await found(page)).find(([p]) => p === lib), [lib, [[await tr("Skills"), ""]]]);
|
||||
// and nothing found says so
|
||||
await type(page, "zzqx");
|
||||
assert.deepEqual(await found(page), []);
|
||||
assert(await page.locator("#setNone").isVisible());
|
||||
|
||||
assert.deepEqual(posts, []);
|
||||
assert.deepEqual(page.errors, []);
|
||||
await page.context().close();
|
||||
});
|
||||
}
|
||||
|
||||
await t.test("magpie web on a phone", async () => {
|
||||
const posts = [];
|
||||
const page = await open("en", posts, { width: 390, height: 700, web: true, at: "routing" });
|
||||
await page.locator("#find").click();
|
||||
await viewIs(page, "settings");
|
||||
await type(page, "strategy");
|
||||
assert.equal((await found(page))[0][1].length, 2);
|
||||
// Open beside the place's name, not under it as a phone's settings rows are
|
||||
assert.deepEqual(await page.evaluate(() => [...document.querySelectorAll("#setElse .find-row")].filter((r) => {
|
||||
const w = r.querySelector(".who").getBoundingClientRect(), b = r.querySelector("button").getBoundingClientRect();
|
||||
return b.top >= w.bottom - 1 || b.left < w.right;
|
||||
}).map((r) => r.textContent)), []);
|
||||
assert.deepEqual(await overflow(page), []);
|
||||
shots.push(["web-390", await page.screenshot()]);
|
||||
await page.locator("#setElse .find-row", { hasText: "Sol" }).locator("button").click();
|
||||
await viewIs(page, "groups");
|
||||
await page.locator(".rt-gedit label.find-lit").waitFor();
|
||||
assert.deepEqual(await overflow(page), []);
|
||||
assert.deepEqual(posts, []);
|
||||
assert.deepEqual(page.errors, []);
|
||||
await page.context().close();
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user