routing: with routing groups off, the Routing page says so and turns them on (bigbenniu on X)
bigbenniu on X: on a new install the Routing page had nothing past its
requests, no New group and no word of where it had gone. A new install's
Essentials preset leaves the "groups" built-in off, and everything marked
data-feature="groups" was hidden without a trace.
Now an element can be marked data-feature-off="<id>", the other way
round: featureStyle shows it only while that feature is off. Where the
routing groups were, the Routing page shows such a note: routing groups
are off in Plugins › Built-in, the groups magpie finds still route, your
own can't be made or changed here; and a "Turn on routing groups" button
that posts plugins/builtin {id:"groups",on:true}, applies the answer and
reloads the groups. It sits after the groups' own rows, so their order
(group-found-off's check) is as it was. Strings in zh, zh-TW, ja and de.
Run:
- internal/gui/tests/routing-groups-off.test.cjs (new), Chromium and
WebKit, en and zh, 900 and 420px: groups off shows the note and its
button, New group and the groups hidden, the note fits the window;
the click posts {id:"groups",on:true}, the note goes, the groups and
New group come back, the status says so; groups on shows no note;
every new string in zh, zh-TW, ja and de. 18/18 with group-found-off.
Red by hand two ways: without the note's data-feature-off (6 of 7
red in Chromium), and without featureStyle's data-feature-off rule
(6 of 7 red). Screenshots looked at, zh 900 and 420.
- 119 GUI files (routing*, group*, panel-routing*, builtins, *-off*):
all pass but routing-bodies (10) and routing-keys-fold (5), which
fail the same 15 on a fresh origin/main ea3dee96a run alone: #2559
and #1612.
- go test -tags nogui ./internal/gui ok. No Go file changed.
Not tried in the real Wails window.
This commit is contained in:
@@ -25,7 +25,10 @@ const GATEWAY_HIDES = ["agents", "library"];
|
||||
// (navHides), a link to the page opens Agents (show), and Settings and its
|
||||
// search pass over its rows. boot.js says which before the first paint,
|
||||
// each read of the settings after (applyFeatures). The gateway is the
|
||||
// same either way.
|
||||
// same either way. Whatever is marked data-feature-off="<id>" is the
|
||||
// other way round, there only while its feature is off: where a page
|
||||
// says what went and turns it back on (bigbenniu on X: with routing
|
||||
// groups off, the Routing page had no New group and said nothing of why).
|
||||
let featuresOff = new Set(window.bootPrefs?.featuresOff || []);
|
||||
const featureSel = () => [...featuresOff].map((id) => `[data-feature~="${id}"]`).join(",");
|
||||
const featureHides = (n) => { const sel = featureSel(); return !!sel && !!n?.closest(sel); };
|
||||
@@ -36,8 +39,9 @@ function featureStyle() {
|
||||
st.id = "featureStyle";
|
||||
document.head.append(st);
|
||||
}
|
||||
const sel = featureSel();
|
||||
st.textContent = sel ? sel + "{display:none!important}" : "";
|
||||
const sel = featureSel(), off = [...featuresOff].map((id) => `[data-feature-off~="${id}"]`).join(",");
|
||||
st.textContent = (sel ? sel + "{display:none!important}" : "") +
|
||||
(off ? `[data-feature-off]:not(${off})` : "[data-feature-off]") + "{display:none!important}";
|
||||
}
|
||||
featureStyle();
|
||||
// a page a plugin adds (kernel.js) that draws from /api/providers, as the
|
||||
|
||||
@@ -3486,7 +3486,32 @@ function routingPage(part) {
|
||||
const gNames = el("div", "rt-gnames");
|
||||
// the groups go with the routing groups built-in plugin; the pools stay
|
||||
for (const n of [gHead, gFound, gNames, gList]) n.dataset.feature = "groups";
|
||||
gsec.append(gHead, gFound, gNames, gList, pHead, pList);
|
||||
// and off (a new install's Essentials leaves it off), where they were
|
||||
// the page says so and turns it on (bigbenniu on X: past the requests
|
||||
// there was nothing, and no word of where New group had gone). The
|
||||
// groups magpie finds route all the same.
|
||||
const gOff = el("div", "rt-goff");
|
||||
gOff.dataset.featureOff = "groups";
|
||||
const gOn = el("button", "text rt-goffon", t("Turn on routing groups"));
|
||||
gOn.type = "button";
|
||||
gOn.onclick = async () => {
|
||||
gOn.disabled = true;
|
||||
try {
|
||||
const next = await api("plugins/builtin", { id: "groups", on: true });
|
||||
if (state.settings) state.settings.builtins = next;
|
||||
applyFeatures(next);
|
||||
status(t("Routing groups are on"), "ok", 1500);
|
||||
loadGroups();
|
||||
} catch (err) {
|
||||
status(t(err.message), "err");
|
||||
} finally {
|
||||
gOn.disabled = false;
|
||||
}
|
||||
};
|
||||
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(el("div", "row-head", el("span", "label", t("Routing groups"))), gOffBox);
|
||||
gsec.append(gHead, gFound, gNames, gList, gOff, pHead, pList);
|
||||
// after the requests: a request picked in the list plays on the stage,
|
||||
// so the list sits right under it
|
||||
more.append(gsec);
|
||||
|
||||
@@ -110,6 +110,9 @@ magpie.strings({
|
||||
"{who} is made for {api}, not {other} as the keys routed over are, so it isn't one of them: it's tried after them.": "{who} 用于 {api},与参与路由的 {other} 密钥不同,不算其中一员,排在它们之后尝试。",
|
||||
"{n} keys for {api}": "{n} 个 {api} 密钥",
|
||||
"New group": "新建组",
|
||||
"Turn on routing groups": "打开路由组",
|
||||
"Routing groups are on": "路由组已开启",
|
||||
"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.": "路由组在「插件 › 内置」中已关闭:magpie 自动找到的组(多个供应商提供的同一个模型)照常路由,但这里不能新建或修改你自己的组。",
|
||||
"Make a routing group of any models you like — agents pick it as one model": "用任意模型新建一个路由组,Agent 会把它当作一个模型来选",
|
||||
"Filter groups and models": "筛选路由组和模型",
|
||||
"No group or model matches “{q}”": "没有路由组或模型匹配“{q}”",
|
||||
@@ -635,6 +638,9 @@ magpie.strings({
|
||||
"{who} is made for {api}, not {other} as the keys routed over are, so it isn't one of them: it's tried after them.": "{who} 用於 {api},與參與路由的 {other} 金鑰不同,不算其中一員,排在它們之後嘗試。",
|
||||
"{n} keys for {api}": "{n} 個 {api} 金鑰",
|
||||
"New group": "新增組",
|
||||
"Turn on routing groups": "開啟路由組",
|
||||
"Routing groups are on": "路由組已開啟",
|
||||
"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.": "路由組在「外掛 › 內建」中已關閉:magpie 自動找到的組(多個供應商提供的同一個模型)照常路由,但這裡不能新增或修改你自己的組。",
|
||||
"Make a routing group of any models you like — agents pick it as one model": "用任意模型新增一個路由組,Agent 會把它當作一個模型來選",
|
||||
"Filter groups and models": "篩選路由組和模型",
|
||||
"No group or model matches “{q}”": "沒有路由組或模型匹配「{q}」",
|
||||
@@ -1140,6 +1146,9 @@ magpie.strings({
|
||||
"{who} is made for {api}, not {other} as the keys routed over are, so it isn't one of them: it's tried after them.": "{who} は {api} 用で、ルーティング対象のキーのような {other} 用ではないため、その一員にはなりません。それらの後に試されます。",
|
||||
"{n} keys for {api}": "{api} 用のキー {n} 個",
|
||||
"New group": "新しいグループ",
|
||||
"Turn on routing groups": "ルーティンググループをオンにする",
|
||||
"Routing groups are on": "ルーティンググループをオンにしました",
|
||||
"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.": "ルーティンググループは「プラグイン › 内蔵」でオフになっています。magpie が見つけたグループ(複数のプロバイダが提供する同じモデル)はそのままルーティングされますが、自分のグループはここで作成・変更できません。",
|
||||
"Make a routing group of any models you like — agents pick it as one model": "好きなモデルでルーティンググループを作ります。エージェントはそれを 1 つのモデルとして選べます",
|
||||
"Filter groups and models": "グループとモデルを絞り込む",
|
||||
"No group or model matches “{q}”": "「{q}」に一致するグループやモデルはありません",
|
||||
@@ -1656,6 +1665,9 @@ magpie.strings({
|
||||
"{who} is made for {api}, not {other} as the keys routed over are, so it isn't one of them: it's tried after them.": "{who} ist für {api} gedacht, nicht für {other} wie die Schlüssel der Weiterleitung, und gehört daher nicht zu ihnen: Es wird nach ihnen versucht.",
|
||||
"{n} keys for {api}": "{n} Schlüssel für {api}",
|
||||
"New group": "Neue Gruppe",
|
||||
"Turn on routing groups": "Weiterleitungsgruppen einschalten",
|
||||
"Routing groups are on": "Weiterleitungsgruppen sind an",
|
||||
"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.": "Weiterleitungsgruppen sind unter Erweiterungen › Eingebaut ausgeschaltet: Die Gruppen, die magpie findet (ein Modell, das mehrere Anbieter bereitstellen), leiten weiter, aber eigene lassen sich hier nicht anlegen oder ändern.",
|
||||
"Make a routing group of any models you like — agents pick it as one model": "Eine Routing-Gruppe aus beliebigen Modellen erstellen – Agenten wählen sie als ein Modell",
|
||||
"Filter groups and models": "Gruppen und Modelle filtern",
|
||||
"No group or model matches “{q}”": "Keine Gruppe und kein Modell passt zu „{q}“",
|
||||
|
||||
@@ -456,6 +456,12 @@ button.rt-session { cursor: pointer; }
|
||||
.rt-pick.off { opacity: .55; }
|
||||
.rt-pick:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
|
||||
.rt-gnone { padding: 14px; font-size: 12px; line-height: 1.5; }
|
||||
/* the routing groups switched off: where they were, a line of why and the
|
||||
way back on */
|
||||
.rt-goff { display: grid; gap: 6px; }
|
||||
.rt-goffbox { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 14px; }
|
||||
.rt-goffwhy { flex: 1 1 260px; min-width: 0; font-size: 12px; line-height: 1.5; color: var(--fg-2); }
|
||||
.rt-goffon { flex: none; }
|
||||
.rt-gfound, .rt-gnames { display: flex; align-items: center; gap: 12px; padding: 2px 4px 4px; }
|
||||
.rt-gfound .txt, .rt-gnames .txt { flex: 1; min-width: 0; display: grid; gap: 2px; }
|
||||
.rt-gfound b, .rt-gnames b { font-size: 12.5px; font-weight: 600; }
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// bigbenniu on X: a new install's Essentials leaves routing groups off, and
|
||||
// the Routing page then had nothing past its requests: no New group, no
|
||||
// groups, and no word of why. With them off, where they were the page says
|
||||
// so and has a button that turns them on (plugins/builtin {id:"groups"}),
|
||||
// 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.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const models = [
|
||||
{ id: "a/m", name: "m", providerName: "A", icon: "generic" },
|
||||
{ id: "b/m", name: "m", providerName: "B", icon: "generic" },
|
||||
];
|
||||
const 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) {
|
||||
let on = start;
|
||||
const builtins = () => [{ id: "groups", on }];
|
||||
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 = ${JSON.stringify({ lang, theme: "light", web: true, featuresOff: on ? [] : ["groups"] })};` });
|
||||
if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light", builtins: builtins() } });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/plugins/builtin") {
|
||||
posts.push(JSON.parse(r.request().postData() || "{}"));
|
||||
on = true;
|
||||
return json(builtins());
|
||||
}
|
||||
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({ models, pools: [], deciders: [], found: true, groups: [mine] });
|
||||
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)];
|
||||
const body = await fs.readFile(file).catch(() => null);
|
||||
await (body ? r.fulfill({ body, contentType }) : r.fulfill({ status: 404, body: "" }));
|
||||
};
|
||||
}
|
||||
|
||||
const words = {
|
||||
en: { why: "Routing groups are off in Plugins › Built-in", on: "Turn on routing groups", done: "Routing groups are on" },
|
||||
zh: { why: "路由组在「插件 › 内置」中已关闭", on: "打开路由组", done: "路由组已开启" },
|
||||
};
|
||||
const keys = [
|
||||
"Turn on routing groups", "Routing groups are on",
|
||||
"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.",
|
||||
];
|
||||
|
||||
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();
|
||||
t.after(async () => {
|
||||
if (process.env.ARTIFACT_DIR) {
|
||||
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
||||
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, name) });
|
||||
}
|
||||
await browser.close();
|
||||
});
|
||||
page.setDefaultTimeout(5000);
|
||||
return page;
|
||||
}
|
||||
|
||||
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) => {
|
||||
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=routing");
|
||||
|
||||
const note = page.locator(".rt-gsec .rt-goff");
|
||||
await note.waitFor();
|
||||
const text = await note.innerText();
|
||||
assert(text.includes(w.why), text);
|
||||
const btn = note.locator("button", { hasText: w.on });
|
||||
assert(await btn.isVisible());
|
||||
assert.equal(await page.locator("#rtNewGroup").isVisible(), false, "New group is off with them");
|
||||
assert.equal(await page.locator(".rt-group", { hasText: "Mine" }).isVisible(), false);
|
||||
assert(await note.evaluate((n) => n.getBoundingClientRect().right <= innerWidth + 1), "the note fits the window");
|
||||
assert(await btn.evaluate((b) => b.getBoundingClientRect().right <= innerWidth + 1), "so does its button");
|
||||
|
||||
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("#rtNewGroup").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 errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, true, []));
|
||||
await page.goto("http://magpie.test/?view=routing");
|
||||
await page.locator(".rt-group", { hasText: "Mine" }).waitFor({ state: "visible" });
|
||||
assert.equal(await page.locator(".rt-goff").isVisible(), false);
|
||||
assert(await page.locator("#rtNewGroup").isVisible());
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
|
||||
test(`${engine}: the note's strings are in every language`, async (t) => {
|
||||
const page = await open(engine, 900, t, `${engine}-routing-groups-off-i18n.png`);
|
||||
await page.route("**/*", serve("en", false, []));
|
||||
await page.goto("http://magpie.test/?view=routing");
|
||||
await page.locator(".rt-goff").waitFor();
|
||||
const missing = await page.evaluate((ks) => ["zh", "zh-TW", "ja", "de"].flatMap((l) => ks.filter((k) => !I18N[l]?.[k]).map((k) => `${l}: ${k}`)), keys);
|
||||
assert.deepEqual(missing, []);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user