diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index e2e9477d5..9255db9f5 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -5640,7 +5640,7 @@ function keptNote(m) { } else { words.append(el("span", "", t("{provider} is used only through routing groups, and {model} is in none, so no agent can use it. Make a group of it, or untick “Only through routing groups” in {provider}'s models.", { provider: m.provider, model }))); act.textContent = t("Make a routing group of it"); - act.dataset.feature = "routing"; // made on the Routing page + act.dataset.feature = "routing groups"; act.onclick = (ev) => { ev.stopPropagation(); closePicker(); @@ -11509,7 +11509,7 @@ function renderModels(p) { if (!p.unlisted) { lost.append(" " + t("Once saved, make a group of them in Routing groups.")); return; } for (const id of none.slice(0, 4)) { const b = el("button", "text action", t("Make a routing group of {model}", { model: id })); - b.dataset.feature = "routing"; // made on the Routing page + b.dataset.feature = "routing groups"; b.onclick = (ev) => { if (mode !== "window") api("window/main?view=groups&newgroup=" + encodeURIComponent(p.id + "/" + id), {}); else window.newGroupWith?.(p.id + "/" + id, "", ev); }; lost.append(b); } @@ -23144,8 +23144,8 @@ async function show(v) { v = magpie.replacing?.(v) || v; // a page gateway mode leaves out (a link to it, an address kept) opens Providers if (gatewayMode && GATEWAY_HIDES.includes(v)) v = "providers"; - // and one a built-in plugin switched off has, Agents - if (featureHides($(`#nav button[data-view="${v}"]`))) v = gatewayMode ? "providers" : "agents"; + // and one a built-in plugin switched off has, offView + v = offView(v); if (v !== view) { if (v === "plugins" && pluginUpdates) window.pluginTabTo?.("installed"); if (view === "providers" && (editing !== null || importing || importingApps)) { @@ -23234,6 +23234,12 @@ function setGatewayMode(on) { else if (!sideNav()) slide($("#nav"), "nav"); navSubs(); } +// offView: v, or the page a plugin switched off sends it to (yyddbds) +function offView(v) { + if (!featureHides($(`#nav button[data-view="${v}"]`))) return v; + if (v === "groups" && !featureHides($('#nav button[data-view="routing"]'))) return "routing"; + return gatewayMode ? "providers" : "agents"; +} // navHides leaves out the tabs of the pages gateway mode or a built-in // plugin switched off leaves out function navHides() { @@ -23255,7 +23261,8 @@ function applyFeatures(list) { if (mode === "panel" && panelTab !== "agents") setPanelTab(panelTab); // its tab may be gone if (mode !== "window") return; navHides(); - if (featureHides($(`#nav button[data-view="${view}"]`))) show(gatewayMode ? "providers" : "agents"); + window.routingGroupsHome?.(); + if (offView(view) !== view) show(offView(view)); else if (!sideNav()) slide($("#nav"), "nav"); setSetTab(setTab); navSubs(); diff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.html index c501bfe72..a13bb4651 100644 --- a/internal/gui/assets/index.html +++ b/internal/gui/assets/index.html @@ -72,7 +72,7 @@ Models - + Insights diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js index 652f2df8c..a1be68403 100644 --- a/internal/gui/assets/plugins/routing/client.js +++ b/internal/gui/assets/plugins/routing/client.js @@ -21,7 +21,7 @@ magpie.plugin("routing", (ctx) => { title: "Routing", html: `
Routinglive, as the gateway decides - +
@@ -2832,19 +2832,21 @@ function routingPage(part) { async function goRouting(e, go) { const i = go.indexOf(":"), kind = go.slice(0, i), id = CSS.escape(go.slice(i + 1)); const row = kind === "group" ? gList.querySelector(`.rt-group[data-id="${id}"]`) : pList.querySelector(`.rt-pool[data-provider="${id}"]`); - if (!row) return; - // they are on the Routing groups page: it opens, and the row comes + if (!row || featureHides(row)) return; + // they are on the Routing groups page (on Routing with the groups + // off: groupsHome): it opens, and the row comes // into sight as the reader's click asked. A page just opened is at the // row at once, and that is where the reader is in it (arrived): else // the page put itself back where the reader last left it - const asked = window.scrollOnPurpose?.(e), opens = gView().hidden; - if (opens && !(await window.show("groups"))) return; + const home = gsec.closest("main") || gView(); + const asked = window.scrollOnPurpose?.(e), opens = home.hidden; + if (opens && !(await window.show(home.id.slice("view-".length)))) return; // from Routing: its toolbar leads back to the request (gBack) - if (opens && e.target.closest?.("#view-routing")) openedFrom(e.target.closest(".rt-go")); + if (opens && home === gView() && e.target.closest?.("#view-routing")) openedFrom(e.target.closest(".rt-go")); if (asked) { readerScrolls(1000); row.scrollIntoView({ block: "center", behavior: opens || still() ? "auto" : "smooth" }); - if (opens) window.arrived?.(gView()); + if (opens) window.arrived?.(home); } row.classList.remove("rt-found"); void row.offsetWidth; @@ -5816,6 +5818,8 @@ function routingPage(part) { applyFeatures(next); status(t("Routing groups are on"), "ok", 1500); loadGroups(); + // the note was on Routing (groupsHome): the groups are on their page + if (!$("#view-routing").hidden && document.body.classList.contains("window")) window.show("groups"); } catch (err) { status(t(err.message), "err"); } finally { @@ -5824,7 +5828,8 @@ function routingPage(part) { }; const gOffBox = el("div", "list rt-goffbox"); gOffBox.append(el("div", "rt-goffwhy", t("Routing groups are off in Plugins › Built-in: the groups magpie finds, one model several providers serve, still route, but your own can't be made or changed here.")), gOn); - gOff.append(gOffBox); + // on Routing then (groupsHome), under its requests, named as before 11-06 + gOff.append(el("div", "row-head", el("span", "label", t("Routing groups"))), gOffBox); // the settings that hold for every group, under the list (11-06) const sHead = el("div", "row-head rt-gset-head"); sHead.dataset.feature = "groups"; @@ -5834,9 +5839,16 @@ function routingPage(part) { gSet.append(gFound, gNames, ...gDefs); gsec.append(gHead, gList, gOff, sHead, gSet, pHead, pList); // on the Routing groups page, a page of their own; Try again on it puts - // them back in its markup made anew + // them back in its markup made anew. With the groups off, that page's + // tab leaves the sidebar (yyddbds on Discord: it stayed), and what is + // left of it, the note that turns them on and the providers' own + // accounts, goes under Routing's requests, where it was before 11-06. + // app.js asks again when a built-in is switched (applyFeatures). const gHome = () => $("#rtGroups"); - window.routingGroupsHome = (main) => (main?.querySelector("#rtGroups") || gHome())?.append(gsec); + window.routingGroupsHome = (main) => { + const to = featuresOff.has("groups") ? more : main?.querySelector("#rtGroups") || gHome(); + if (to && gsec.parentElement !== to) to.append(gsec); + }; window.routingGroupsHome(); if (gHome()) byWidth(gHome(), { max520: (w) => w <= 520 }); const ROUTE_OPTS = [["", "Smart"], ["order", "In order"], ["drain", "Until used up"], ["rotate", "In turn"], ["usage", "Least used"], ["pace", "Use before expiry"], ["free", "Free first"], ["fast", "Speed first"]]; diff --git a/internal/gui/tests/routing-groups-off.test.cjs b/internal/gui/tests/routing-groups-off.test.cjs index e294c6f49..c60fbbca5 100644 --- a/internal/gui/tests/routing-groups-off.test.cjs +++ b/internal/gui/tests/routing-groups-off.test.cjs @@ -6,6 +6,11 @@ // after which the groups and New group are back and the note is gone. With // them on, there is no note. English and Chinese, Chromium and WebKit, wide // and narrow, and every language has the strings. +// yyddbds on Discord: with them off, the sidebar still had a Routing +// groups tab. Off, it is gone (and Routing's own "Routing groups ›"), an +// address kept for the page opens Routing, and what is left of the page, +// the note and the providers' own accounts, is under Routing's requests. +// Turned on, the tab is back and the groups' page opens. const assert = require("node:assert/strict"); const fs = require("node:fs/promises"); const path = require("node:path"); @@ -17,6 +22,7 @@ const models = [ { id: "a/m", name: "m", providerName: "A", icon: "generic" }, { id: "b/m", name: "m", providerName: "B", icon: "generic" }, ]; +const pools = [{ provider: "a", name: "A", icon: "generic", kind: "key", who: ["k1", "k2"], routing: "", affinity: "" }]; const mine = { id: "mine", name: "Mine", members: ["a/m", "b/m"], ready: true, memberInfo: [{ id: "a/m", ready: true }, { id: "b/m", ready: true }] }; function serve(lang, start, posts) { @@ -39,7 +45,7 @@ function serve(lang, start, posts) { 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({ models, pools: [], deciders: [], found: true, groups: [mine] }); + if (url.pathname === "/api/groups") return json({ models, pools: [], deciders: [], found: true, groups: [mine], pools }); 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); @@ -58,6 +64,10 @@ const keys = [ "Routing groups are off in Plugins › Built-in: the groups magpie finds, one model several providers serve, still route, but your own can't be made or changed here.", ]; +// the pages' tabs a reader sees, the sidebar's or the header's +const tabs = (page) => page.evaluate(() => [...document.querySelectorAll("#nav button[data-view]")].filter((b) => !b.hidden && b.offsetParent && getComputedStyle(b).display !== "none").map((b) => b.dataset.view)); +const shown = (page) => page.evaluate(() => [...document.querySelectorAll("main.view")].filter((v) => !v.hidden).map((v) => v.id)); + async function open(engine, width, t, name) { const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); const page = await (await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" })).newPage(); @@ -76,16 +86,26 @@ async function open(engine, width, t, name) { for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { for (const lang of ["en", "zh"]) { const w = words[lang]; - for (const width of [900, 420]) { - test(`${engine} ${lang} ${width}px: with routing groups off, the Routing page says so and turns them on`, async (t) => { + // the sidebar from 1024 points, the header's tabs under it, and narrow + for (const width of [1200, 900, 420]) { + test(`${engine} ${lang} ${width}px: with routing groups off, their tab is gone, and Routing says so and turns them on`, async (t) => { const page = await open(engine, width, t, `${engine}-${lang}-${width}-routing-groups-off.png`); const errors = [], posts = []; page.on("pageerror", (e) => errors.push(e.message)); await page.route("**/*", serve(lang, false, posts)); await page.goto("http://magpie.test/?view=groups"); - const note = page.locator(".rt-gsec .rt-goff"); + const note = page.locator("#view-routing .rt-gsec .rt-goff"); await note.waitFor(); + assert.deepEqual(await shown(page), ["view-routing"], "an address kept for the groups' page opens Routing"); + if (width >= 800) { + const ts = await tabs(page); + assert(ts.includes("routing"), ts.join()); + assert(!ts.includes("groups"), `no Routing groups tab: ${ts.join()}`); + } + assert.equal(await page.locator("#rtToGroups").isVisible(), false, "nor Routing's way to the page"); + // the providers' own accounts are still to be set, on Routing + await page.locator("#view-routing .rt-pool[data-provider=\"a\"]").waitFor({ state: "visible" }); const text = await note.innerText(); assert(text.includes(w.why), text); const btn = note.locator("button", { hasText: w.on }); @@ -98,15 +118,19 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await btn.click(); await note.waitFor({ state: "hidden" }); assert.deepEqual(posts, [{ id: "groups", on: true }]); - await page.locator(".rt-group", { hasText: "Mine" }).waitFor({ state: "visible" }); - await page.locator(".rt-gnew").waitFor({ state: "visible" }); + // on, the groups' page opens, with them and New group, its tab back + await page.locator("#view-groups .rt-group", { hasText: "Mine" }).waitFor({ state: "visible" }); + await page.locator("#view-groups .rt-gnew").waitFor({ state: "visible" }); + assert.deepEqual(await shown(page), ["view-groups"]); + if (width >= 1024) assert((await tabs(page)).includes("groups"), "the tab is back"); + await page.locator("#view-groups .rt-pool[data-provider=\"a\"]").waitFor({ state: "visible" }); await page.waitForFunction((m) => document.querySelector("#status").textContent.includes(m), w.done); assert.deepEqual(errors, []); }); } test(`${engine} ${lang}: with routing groups on, there is no note`, async (t) => { - const page = await open(engine, 900, t, `${engine}-${lang}-routing-groups-on.png`); + const page = await open(engine, 1200, t, `${engine}-${lang}-routing-groups-on.png`); const errors = []; page.on("pageerror", (e) => errors.push(e.message)); await page.route("**/*", serve(lang, true, [])); @@ -114,6 +138,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.locator(".rt-group", { hasText: "Mine" }).waitFor({ state: "visible" }); assert.equal(await page.locator(".rt-goff").isVisible(), false); assert(await page.locator(".rt-gnew").isVisible()); + assert.deepEqual(await shown(page), ["view-groups"]); + assert((await tabs(page)).includes("groups"), "the tab is there"); assert.deepEqual(errors, []); }); }