From c9a1c557d05cdf4178b07e9420e0ced900e975cf Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 9 Nov 2026 20:12:22 +0800 Subject: [PATCH] plugins: every built-in's row leads to where it is used, and the Gateway page holds its own setting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit netube99 on X: one feature's settings are spread over pages that don't say where the rest are. Plugins › Built-in had six rows (Key limits, Groups, Rotation, Warm-ups, Middleware, Tools) with no page and no link, so a user who turned one on was left to find where it shows. And the Gateway page's one setting, Recent calls at a time, was a form under its row in Plugins › Built-in, two pages from the calls it is about. - pluginrt.Manifest gets Opens: the window page a built-in without a page of its own is used on. budget → gateway (keys' limits), groups → groups, rotation and warmups → providers (a provider's editor), middleware and tools → plugins. builtinJSON sends it; featGo links to that page by its sidebar name, as for a page plugin. - A plugin with a page draws its settings there, not under its row (renderBuiltins). The Gateway page draws its schema under Recent calls (renderGatewayOwn), saves through /api/plugins/builtin as before, and ends with a row "Port, allowed addresses and model ids" that opens Settings › Network and sharing at the gateway's rows (4 languages). Tests: - TestBuiltinSaysWhereItsSettingsAre holds SetAt, Page and Opens per built-in. - builtins.test.cjs: no form in Built-in, and each Opens row's link says its page's sidebar name. Its row reached by the wheel now counts the window's bottom too, and frees a switch under the view's floating To the bottom button by wheeling toward the window's middle: the rows grew with their links, and WebKit de 420 left Usage's switch under it. - gateway-own-settings.test.cjs (new): the setting under the calls, translated, 20, picking 50 posts {id: gateway, config: {callsPage: 50}}, the row opens Settings › Network at #portList flashed; every language, Chromium and WebKit, 1100 and 420, nothing past the window. - builtin-places.test.cjs: Library's row now leads to Library. Run at this tree (on origin/main e3f1efdaa), on mote: - gofmt -l: nothing. go vet ./internal/gui ./internal/pluginrt ./plugins/..., GOOS=linux go vet -tags nogui, GOOS=windows go vet: ok. - go test -run 'TestBuiltin|TestCoreScriptBudget|Translat' ./internal/gui ./internal/pluginrt ./plugins/...: ok. - node --test builtins builtin-places websearch-places gateway-own-settings gateway-keys-off i18n-en-no-cjk: 272 pass, 0 fail (both engines). - i18n-keys: "a plugin's words are its own" red, the same on a clean origin/main e3f1efdaa (#5332, #5327, #5482, #5426); fixed next. Broken by hand: without budget's Opens, TestBuiltinSaysWhereItsSettingsAre fails (want "gateway"); without the renderGatewayOwn call, gateway-own-settings is 0 of 10 in Chromium. Not tried: the real app; the whole GUI suite (next, behind suite.lock). --- internal/gui/assets/app.js | 9 +-- internal/gui/assets/i18n.js | 4 + internal/gui/assets/plugins/gateway/client.js | 29 ++++++++ internal/gui/builtins.go | 6 +- internal/gui/builtins_test.go | 20 +++-- internal/gui/tests/builtin-places.test.cjs | 4 +- internal/gui/tests/builtins.test.cjs | 41 +++++----- .../gui/tests/gateway-own-settings.test.cjs | 74 +++++++++++++++++++ internal/pluginrt/pluginrt.go | 4 + plugins/budget/budget.go | 3 +- plugins/groups/groups.go | 3 +- plugins/middleware/middleware.go | 3 +- plugins/rotation/rotation.go | 3 +- plugins/tools/tools.go | 3 +- plugins/warmups/warmups.go | 3 +- 15 files changed, 166 insertions(+), 43 deletions(-) create mode 100644 internal/gui/tests/gateway-own-settings.test.cjs diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 98cfc75d3..ca6529a20 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -23306,7 +23306,7 @@ function renderBuiltins(box, list, done) { } }; r.append(who, b); - if (!f.on || !f.schema || broken) return [r]; + if (!f.on || !f.schema || broken || f.page) return [r]; // a page has its own const form = magpie.ui.form(f.schema, f.config, async (change) => { try { const next = await api("plugins/builtin", { id: f.id, config: change }); @@ -23335,12 +23335,11 @@ const featWho = {}; // settings and page go back (featOff, Masking's head; netube99 on X) function featGo(line, f) { const [tab, row] = f.setAt?.split(" ") || []; - if (!tab) return; const to = []; // not to settings hidden while it is off (Observability, warm-ups) - if (f.on || !$(row)?.closest("[data-feature]")) to.push([t("Settings") + " › " + $("#setTab-" + tab).textContent, (e) => openSettingsAt(e, tab, row + " .row")]); - const nav = f.on && f.page && $(`#nav [data-view="${f.page}"]`); - if (nav) to.push([nav.textContent, () => nav.click()]); + if (tab && (f.on || !$(row)?.closest("[data-feature]"))) to.push([t("Settings") + " › " + $("#setTab-" + tab).textContent, (e) => openSettingsAt(e, tab, row + " .row")]); + const nav = f.on && $(`#nav [data-view="${f.page || f.opens}"]`); + if (nav && !nav.hidden) to.push([nav.textContent, () => nav.click()]); for (const [say, go] of to) { const b = el("button", "link", say); b.type = "button"; diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 01323be38..99bb19a91 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -1045,6 +1045,7 @@ const I18N = { "1 gateway key": "1 个网关密钥", "{n} gateway keys": "{n} 个网关密钥", "Recent calls at a time": "每次显示的最近调用", + "Port, allowed addresses and model ids": "端口、允许的地址和模型 id", "How many of the gateway's recent calls the page shows, and how many more each Show more adds": "页面显示多少条网关最近的调用,以及每次“显示其余”再多显示多少条", "This page stopped working": "此页面已停止工作", "Page": "页面", @@ -5817,6 +5818,7 @@ const I18N = { "1 gateway key": "1 個閘道金鑰", "{n} gateway keys": "{n} 個閘道金鑰", "Recent calls at a time": "每次顯示的最近呼叫", + "Port, allowed addresses and model ids": "連接埠、允許的位址和模型 id", "How many of the gateway's recent calls the page shows, and how many more each Show more adds": "頁面顯示多少筆閘道最近的呼叫,以及每次「顯示其餘」再多顯示多少筆", "This page stopped working": "此頁面已停止運作", "Page": "頁面", @@ -10560,6 +10562,7 @@ const I18N = { "1 gateway key": "ゲートウェイキー 1 個", "{n} gateway keys": "ゲートウェイキー {n} 個", "Recent calls at a time": "一度に表示する最近の呼び出し", + "Port, allowed addresses and model ids": "ポート、許可するアドレス、モデル ID", "How many of the gateway's recent calls the page shows, and how many more each Show more adds": "ページに表示するゲートウェイの最近の呼び出しの数と、「さらに表示」ごとに追加する数", "This page stopped working": "このページは動作を停止しました", "Page": "ページ", @@ -15318,6 +15321,7 @@ const I18N = { "1 gateway key": "1 Gateway-Schlüssel", "{n} gateway keys": "{n} Gateway-Schlüssel", "Recent calls at a time": "Letzte Aufrufe auf einmal", + "Port, allowed addresses and model ids": "Port, erlaubte Adressen und Modell-IDs", "How many of the gateway's recent calls the page shows, and how many more each Show more adds": "Wie viele der letzten Aufrufe des Gateways die Seite zeigt und wie viele jedes „weitere anzeigen“ hinzufügt", "This page stopped working": "Diese Seite funktioniert nicht mehr", "Page": "Seite", diff --git a/internal/gui/assets/plugins/gateway/client.js b/internal/gui/assets/plugins/gateway/client.js index de910dc06..ada5b9d43 100644 --- a/internal/gui/assets/plugins/gateway/client.js +++ b/internal/gui/assets/plugins/gateway/client.js @@ -75,6 +75,7 @@ function renderGatewayView() { page.removeAttribute("aria-busy"); renderGateway(); renderGatewayLan(); + renderGatewayOwn(); $("#gatewayKeysBlock").hidden = !providers.gateway.lan; // not shared, the keys are left out; this line says where they come from, // as a tunnel to loopback is refused until sharing is on (DD on Discord) @@ -86,6 +87,33 @@ function renderGatewayView() { renderActivity(); } +// The page's own settings, under the calls they are about (Recent calls at +// a time, drawn from the plugin's schema), and where the gateway's port, +// allow list and model ids are set: the switch, settings and page of one +// feature lead to each other (netube99 on X) +function renderGatewayOwn() { + const box = $("#gwOwn"); + const f = prefs?.builtins?.find((x) => x.id === "gateway"); + if (!f) { + box.replaceChildren(); + if (!prefs) loadSettings().then(() => view === "gateway" && renderGatewayOwn(), () => {}); + return; + } + const rows = f.schema ? magpie.ui.form(f.schema, f.config, async (change) => { + try { + applyFeatures(prefs.builtins = state.settings.builtins = await api("plugins/builtin", { id: "gateway", config: change })); + status(t("Saved"), "ok", 1500); + } catch (err) { status(t(err.message), "err"); } + renderGatewayOwn(); + }) : []; + const r = el("div", "row pref"), who = el("div", "who"), go = el("button", "text", t("Settings") + " › " + $("#setTab-network").textContent); + who.append(el("div", "name", t("Port, allowed addresses and model ids"))); + go.type = "button"; + go.onclick = (e) => openSettingsAt(e, "network", "#portList .row"); + r.append(who, go); + box.replaceChildren(...rows, r); +} + // The status card's button (leslie_luo on Discord: told to quit the older // magpie serving the gateway, with no way to tell which one it was): with // an older magpie on the port it quits that one, checked to be magpie by @@ -807,6 +835,7 @@ magpie.plugin("gateway", (ctx) => {
Recent calls
+
`, mount() { $("#foldConnect").prepend(svg(CHEV_R, 11, 1.6)); diff --git a/internal/gui/builtins.go b/internal/gui/builtins.go index ffcf426b0..386ac6177 100644 --- a/internal/gui/builtins.go +++ b/internal/gui/builtins.go @@ -42,9 +42,11 @@ type builtinJSON struct { Use string `json:"use,omitempty"` // One or Many, by InUse Parts []pluginrt.Part `json:"parts,omitempty"` // SetAt is the manifest's: the Settings tab and row of its settings; - // Page the window page it has, on or off + // Page the window page it has, on or off, which has its settings + // (schema) too; Opens the page it is used on when it has none SetAt string `json:"setAt,omitempty"` Page string `json:"page,omitempty"` + Opens string `json:"opens,omitempty"` // Schema is its settings' (pluginrt/schema.go), which the page draws // a form of; Config their values now Schema *pluginrt.Schema `json:"schema,omitempty"` @@ -77,7 +79,7 @@ func builtinsState() []builtinJSON { for _, m := range pluginrt.Registered() { c, s := byID[m.ID], st[m.ID] j := builtinJSON{ID: m.ID, Name: m.Name, Sub: m.Sub, On: s.State == pluginrt.Active, Chosen: c.Chosen, Source: c.Source, State: s.State, Why: s.Why, InUse: c.InUse, Parts: s.Parts, Schema: m.Schema(), Config: c.Config} - j.SetAt = m.SetAt + j.SetAt, j.Opens = m.SetAt, m.Opens for _, p := range m.Parts { if p.Slot == "nav.page" { j.Page = p.Key diff --git a/internal/gui/builtins_test.go b/internal/gui/builtins_test.go index 2cafb5c49..a113975c6 100644 --- a/internal/gui/builtins_test.go +++ b/internal/gui/builtins_test.go @@ -370,13 +370,17 @@ func TestBuiltinSaysWhereItsSettingsAre(t *testing.T) { if err := pluginrt.Set("redact", false); err != nil { t.Fatal(err) } - want := map[string][2]string{ - "redact": {"privacy #redactList", "masking"}, - "search": {"models #searchList", ""}, - "otel": {"otel #otelList", ""}, - "gateway": {"network #portList", "gateway"}, - "library": {"", "library"}, - "groups": {"", ""}, + want := map[string][3]string{ + "redact": {"privacy #redactList", "masking", ""}, + "search": {"models #searchList", "", ""}, + "otel": {"otel #otelList", "", ""}, + "gateway": {"network #portList", "gateway", ""}, + "library": {"", "library", ""}, + "groups": {"", "", "groups"}, + "budget": {"", "", "gateway"}, + "rotation": {"", "", "providers"}, + "warmups": {"", "", "providers"}, + "tools": {"", "", "plugins"}, } for _, b := range builtinsState() { w, ok := want[b.ID] @@ -384,7 +388,7 @@ func TestBuiltinSaysWhereItsSettingsAre(t *testing.T) { continue } delete(want, b.ID) - if got := [2]string{b.SetAt, b.Page}; got != w { + if got := [3]string{b.SetAt, b.Page, b.Opens}; got != w { t.Errorf("%s (on %v): %q, want %q", b.ID, b.On, got, w) } if b.ID == "redact" && b.On { diff --git a/internal/gui/tests/builtin-places.test.cjs b/internal/gui/tests/builtin-places.test.cjs index fc131f9dd..aa6fc8298 100644 --- a/internal/gui/tests/builtin-places.test.cjs +++ b/internal/gui/tests/builtin-places.test.cjs @@ -123,9 +123,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(await wide(page), 0); assert.deepEqual(await past(featRow(page, "redact")), []); if (!link) shots.push([`${lang}-${width}-builtin`, await featRow(page, "redact").screenshot()]); - // Observability on: its settings; Library: a page and no settings, no line + // Observability on: its settings; Library: a page and no settings, the page assert.equal((await featRow(page, "otel").locator(".feat-go").textContent()).trim(), w("Settings") + " › " + w("Observability")); - assert.equal(await featRow(page, "library").locator(".feat-go").count(), 0); + assert.equal((await featRow(page, "library").locator(".feat-go").textContent()).trim(), w("Library")); await line.locator("button.link").nth(link).click(); if (link) await page.locator("#view-masking #maskCard .msk-head").waitFor(); else await page.locator("#view-settings #redactList .row.flash").waitFor(); diff --git a/internal/gui/tests/builtins.test.cjs b/internal/gui/tests/builtins.test.cjs index 55b95b850..fe8fc1e72 100644 --- a/internal/gui/tests/builtins.test.cjs +++ b/internal/gui/tests/builtins.test.cjs @@ -53,6 +53,11 @@ function builtins(st, broken, config) { const on = chosen || inUse > 0; const f = { id: p.id, name: p.name, sub: p.sub, on, chosen, source: inUse > 0 && !chosen ? "in use" : "preset", state: on ? "active" : "off", inUse, use: inUse === 1 ? p.one : inUse > 1 ? p.many : undefined, broken }; if (p.id === "gateway") Object.assign(f, { schema: GATEWAY_SCHEMA, config }); + // as the manifests say them: the page each has, or is used on + const page = { gateway: "gateway", library: "library", redact: "masking", routing: "routing", sessions: "sessions", usage: "usage" }[p.id]; + const opens = { budget: "gateway", groups: "groups", rotation: "providers", warmups: "providers", middleware: "plugins", tools: "plugins" }[p.id]; + if (page) f.page = page; + if (opens) f.opens = opens; return f; }); } @@ -190,21 +195,14 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // nothing wider than the window assert.ok(await page.evaluate(() => { const v = document.querySelector("#view-plugins"); return v.scrollWidth <= v.clientWidth + 1; }), `${where}: fits`); - // the Gateway page's setting, under its row, from its schema: in - // the page's language, its value in the app's menu, saved as picked - const set = page.locator('#builtinList .feat-set[data-of="gateway"][data-setting="callsPage"]'); - assert.equal(await set.locator(".name").textContent(), await page.evaluate(() => t("Recent calls at a time")), where); - if (lang !== "en") assert.notEqual(await set.locator(".name").textContent(), "Recent calls at a time", `${where}: translated`); - assert.equal(await page.evaluate(() => document.querySelector('#builtinList .feat-set').previousElementSibling.dataset.id), "gateway", `${where}: under its row`); - assert.equal((await set.locator(".proto.pick").textContent()).trim(), "20", where); - await set.locator(".proto.pick").click(); - await page.locator(".proto-menu .pm-item", { hasText: "50" }).click(); - await page.waitForFunction(() => document.querySelector('#builtinList .feat-set .proto.pick')?.textContent.trim() === "50"); - assert.deepEqual(posts, [["gateway", { callsPage: 50 }]], `${where}: posted`); - assert.equal(await page.evaluate(() => document.querySelectorAll(".proto-menu").length), 0, `${where}: the menu closed`); - posts.length = 0; - assert.ok(await page.evaluate(() => { const v = document.querySelector("#view-plugins"); return v.scrollWidth <= v.clientWidth + 1; }), `${where}: the setting fits`); - + // the Gateway page's setting is on the Gateway page, by its calls + // (gateway-own-settings): none here. A row with no Settings leads to + // the page it is used on, as its sidebar names it + assert.equal(await page.locator("#builtinList .feat-set").count(), 0, `${where}: no form here`); + for (const [id, v] of [["budget", "gateway"], ["rotation", "providers"], ["middleware", "plugins"], ["tools", "plugins"]]) { + const say = await page.evaluate((v) => document.querySelector(`#nav [data-view="${v}"]`).textContent, v); + assert.equal((await page.locator(`#builtinList [data-id="${id}"] .feat-go`).textContent()).trim(), say, `${where}: ${id} leads to ${v}`); + } // Library switched on: its tab is back at once, the page stays await page.locator('#builtinList [data-id="library"] [role="switch"]').click(); await page.waitForSelector('#builtinList [data-id="library"] [aria-checked="true"]'); @@ -217,8 +215,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // too. The wheel turns over what shows of the list (its top may have // scrolled away, and a wheel there scrolls nothing), as often as the // row needs: at 420 the rows wrap and Usage's is more than one turn - // down - const below = (id) => page.evaluate((id) => { const r = document.querySelector(`#builtinList [data-id="${id}"] [role="switch"]`).getBoundingClientRect(), foot = document.querySelector("footer.foot"); return r.bottom > Math.min(document.getElementById("view-plugins").getBoundingClientRect().bottom, foot && foot.offsetParent ? foot.getBoundingClientRect().top : Infinity); }, id); + // down. Below the window counts too: the view can be taller than it + const below = (id) => page.evaluate((id) => { const r = document.querySelector(`#builtinList [data-id="${id}"] [role="switch"]`).getBoundingClientRect(), foot = document.querySelector("footer.foot"); return r.bottom > Math.min(innerHeight, document.getElementById("view-plugins").getBoundingClientRect().bottom, foot && foot.offsetParent ? foot.getBoundingClientRect().top : Infinity); }, id); const wheelTo = async (id) => { for (let i = 0; i < 5 && await below(id); i++) { const at = await page.evaluate(() => { const l = document.getElementById("builtinList").getBoundingClientRect(), v = document.getElementById("view-plugins").getBoundingClientRect(); return { x: l.x + 20, y: (Math.max(l.top, v.top) + Math.min(l.bottom, v.bottom)) / 2 }; }); @@ -232,14 +230,17 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // clamps at the list's end can carry a row's switch under the sticky // Plugins head, or past the view's top, where the head takes the // click and it waits out its timeout (#3498, red 1 of 3 in WebKit). - // Wheel back over what shows of the list, as the wheel above does, - // till the switch's centre is on the switch, and say so + // Wheel over what shows of the list, as the wheel above does, toward + // the window's middle (a row low in the window can be under the + // view's floating To the bottom button), till the switch's centre + // is on the switch, and say so const clearOfHead = (id) => page.evaluate((id) => { const s = document.querySelector(`#builtinList [data-id="${id}"] [role="switch"]`), b = s.getBoundingClientRect(), hit = document.elementFromPoint(b.left + b.width / 2, b.top + b.height / 2); return !!hit && (hit === s || s.contains(hit)); }, id); const outFromUnder = async (id) => { for (let i = 0; i < 20 && !(await clearOfHead(id)); i++) { const at = await page.evaluate(() => { const l = document.getElementById("builtinList").getBoundingClientRect(), v = document.getElementById("view-plugins").getBoundingClientRect(); return { x: l.x + 20, y: (Math.max(l.top, v.top) + Math.min(l.bottom, v.bottom)) / 2 }; }); + const low = await page.evaluate((id) => document.querySelector(`#builtinList [data-id="${id}"] [role="switch"]`).getBoundingClientRect().top > innerHeight / 2, id); await page.mouse.move(at.x, at.y); - await page.mouse.wheel(0, -50); + await page.mouse.wheel(0, low ? 50 : -50); await page.waitForFunction(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => r(true))))); } assert.equal(await clearOfHead(id), true, `${where}: ${id}'s switch clear of the sticky head`); diff --git a/internal/gui/tests/gateway-own-settings.test.cjs b/internal/gui/tests/gateway-own-settings.test.cjs new file mode 100644 index 000000000..fbb6b6cb2 --- /dev/null +++ b/internal/gui/tests/gateway-own-settings.test.cjs @@ -0,0 +1,74 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// The Gateway page's own setting, Recent calls at a time, was set in +// Plugins › Built-in, two pages from the calls it is about, and the page +// didn't say where its port and allow list are (the scattered settings +// audit after netube99 on X). It is now under the calls, drawn from the +// plugin's schema and saved as picked, with a row that opens Settings › +// Network and sharing at the gateway's rows. Every language, Chromium and +// WebKit, at 1100 and 420 wide, nothing past the window's edge. +const assert = require("node:assert/strict"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); +const { fixture } = require("./fixtures/caller-keys.cjs"); +const { strings } = require("./strings.cjs"); + +const { I18N } = strings(); +const tr = (lang, s) => (lang === "en" ? s : I18N[lang]?.[s] ?? s); + +const SCHEMA = { + type: "object", + properties: { callsPage: { type: "integer", title: "Recent calls at a time", description: "How many of the gateway's recent calls the page shows, and how many more each Show more adds", enum: [10, 20, 50, 100], default: 20 } }, + "x-order": ["callsPage"], +}; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) { + for (const width of [1100, 420]) { + test(`${engine} ${lang} ${width}: the Gateway page has its own settings and leads to Settings`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage(); + page.setDefaultTimeout(6000); + page.setDefaultNavigationTimeout(60000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + const config = { callsPage: 20 }, posts = []; + const gateway = () => ({ id: "gateway", name: "Gateway page", sub: "", on: true, chosen: true, source: "preset", state: "active", inUse: 0, + setAt: "network #portList", page: "gateway", schema: SCHEMA, config: { ...config } }); + const base = fixture(lang, "light", []); + await page.route("**/*", async (route) => { + const req = route.request(), url = new URL(req.url()); + if (url.pathname === "/api/plugins/builtin" && req.method() === "POST") { + const b = req.postDataJSON(); + posts.push(b); + Object.assign(config, b.config); + return route.fulfill({ json: [gateway()] }); + } + if (url.pathname === "/api/settings") { + return route.fulfill({ json: { lang, theme: "light", lan: false, lanURLs: [], port: 3999, fx: { rate: 7.2, at: new Date().toISOString() }, builtins: [gateway()] } }); + } + return base(route); + }); + await page.goto("http://magpie.test/?view=gateway"); + const own = page.locator("#gwOwn"); + const set = own.locator('[data-setting="callsPage"]'); + await set.waitFor(); + assert.equal((await set.locator(".name").textContent()).trim(), tr(lang, "Recent calls at a time")); + // under the calls it is about + assert.ok(await page.evaluate(() => document.querySelector("#activity").compareDocumentPosition(document.querySelector("#gwOwn")) & Node.DOCUMENT_POSITION_FOLLOWING)); + assert.equal((await set.locator(".proto.pick").textContent()).trim(), "20"); + await set.locator(".proto.pick").click(); + await page.locator(".proto-menu .pm-item", { hasText: "50" }).click(); + await page.waitForFunction(() => document.querySelector('#gwOwn [data-setting="callsPage"] .proto.pick')?.textContent.trim() === "50"); + assert.deepEqual(posts, [{ id: "gateway", config: { callsPage: 50 } }]); + assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth + 1), "fits"); + + const go = own.locator("button.text").last(); + assert.equal((await go.textContent()).trim(), tr(lang, "Settings") + " › " + tr(lang, "Network and sharing")); + await go.click(); + await page.locator("#view-settings #portList .row.flash").waitFor(); + assert.deepEqual(errors, []); + }); + } + } +} diff --git a/internal/pluginrt/pluginrt.go b/internal/pluginrt/pluginrt.go index 973f1e880..77280ea6c 100644 --- a/internal/pluginrt/pluginrt.go +++ b/internal/pluginrt/pluginrt.go @@ -63,6 +63,10 @@ type Manifest struct { // (netube99 on X: masking's switch, settings and page were three // places, none naming the others). SetAt string + // Opens is the window page it is used on when it has no page of its + // own ("providers" for routing strategies, used in a provider's + // editor): its row in Plugins › Built-in leads there + Opens string // Defaults is its config before plugins.yml's preset and rows Defaults map[string]any // Settings is a struct of its settings, their defaults its values diff --git a/plugins/budget/budget.go b/plugins/budget/budget.go index 34a2960be..e7482e756 100644 --- a/plugins/budget/budget.go +++ b/plugins/budget/budget.go @@ -21,7 +21,8 @@ func init() { pluginrt.Register(pluginrt.Manifest{ ID: "budget", API: "^1", Requires: []string{"settings", "gateway"}, Essential: true, Name: "Key limits", Sub: "Hold each gateway key to the tokens or estimated cost you set for it", - One: "1 key with a limit", Many: "{n} keys with a limit", + Opens: "gateway", + One: "1 key with a limit", Many: "{n} keys with a limit", InUse: InUse, Apply: func(c *pluginrt.Ctx) error { c.OnDispose(gwbudget.Limit(budget.Limiter{})) diff --git a/plugins/groups/groups.go b/plugins/groups/groups.go index 72e104284..1a6beb03c 100644 --- a/plugins/groups/groups.go +++ b/plugins/groups/groups.go @@ -18,7 +18,8 @@ func init() { pluginrt.Register(pluginrt.Manifest{ ID: "groups", API: "^1", Requires: []string{"window", "providers"}, Name: "Routing groups", Sub: "Several models agents pick as one: each request goes to the right one, and to the next when one fails", - One: "1 group in use", Many: "{n} groups in use", + Opens: "groups", + One: "1 group in use", Many: "{n} groups in use", // a providers.json that can't be read is not known, so it stays on InUse: provider.NamedGroups, Parts: []pluginrt.Part{{Slot: "part", Key: "groups"}}, diff --git a/plugins/middleware/middleware.go b/plugins/middleware/middleware.go index b4ae7a5c7..3ae6b8e80 100644 --- a/plugins/middleware/middleware.go +++ b/plugins/middleware/middleware.go @@ -23,7 +23,8 @@ func init() { pluginrt.Register(pluginrt.Manifest{ ID: "middleware", API: "^1", Requires: []string{"gateway"}, Essential: true, Name: "JS gateway plugins", Sub: "Run the JavaScript gateway plugins: middleware on agents' requests and replies, routings and usage observers", - One: "1 gateway plugin on", Many: "{n} gateway plugins on", + Opens: "plugins", + One: "1 gateway plugin on", Many: "{n} gateway plugins on", InUse: func() (int, error) { return middleware.On(), nil }, Apply: func(c *pluginrt.Ctx) error { c.OnDispose(gwmw.Use(middleware.Chain{})) diff --git a/plugins/rotation/rotation.go b/plugins/rotation/rotation.go index 7a1e345c6..5487d26e6 100644 --- a/plugins/rotation/rotation.go +++ b/plugins/rotation/rotation.go @@ -20,7 +20,8 @@ func init() { pluginrt.Register(pluginrt.Manifest{ ID: "rotation", API: "^1", Requires: []string{"providers", "gateway"}, Essential: true, Name: "Routing strategies", Sub: "The routings besides Smart: In order, Until used up, In turn, Least used first, Use before expiry, By weight, Free first, Speed first and Cheapest first", - One: "1 provider or group routed so", Many: "{n} providers and groups routed so", + Opens: "providers", + One: "1 provider or group routed so", Many: "{n} providers and groups routed so", InUse: inUse, Parts: []pluginrt.Part{{Slot: "part", Key: "rotation"}}, Apply: func(c *pluginrt.Ctx) error { diff --git a/plugins/tools/tools.go b/plugins/tools/tools.go index 62baca25c..4e7a4b8f2 100644 --- a/plugins/tools/tools.go +++ b/plugins/tools/tools.go @@ -19,7 +19,8 @@ func init() { pluginrt.Register(pluginrt.Manifest{ ID: "tools", API: "^1", Requires: []string{"gateway"}, Essential: true, Name: "Plugin tools", Sub: "Offer the tools your plugins give to every agent, as an MCP server", - One: "1 plugin gives tools", Many: "{n} plugins give tools", + Opens: "plugins", + One: "1 plugin gives tools", Many: "{n} plugins give tools", InUse: plugin.ToolsOn, Apply: func(c *pluginrt.Ctx) error { c.OnDispose(gwtool.Serve(gwtool.PluginTools)) diff --git a/plugins/warmups/warmups.go b/plugins/warmups/warmups.go index dbbd07992..728f53f14 100644 --- a/plugins/warmups/warmups.go +++ b/plugins/warmups/warmups.go @@ -12,7 +12,8 @@ func init() { pluginrt.Register(pluginrt.Manifest{ ID: "warmups", API: "^1", Requires: []string{"window", "settings"}, Name: "Warm-up and check-in", Sub: "Start a subscription's usage window at a time you pick, and claim vendors' daily check-in credits", - One: "1 warm-up or check-in on", Many: "{n} warm-ups and check-ins on", + Opens: "providers", + One: "1 warm-up or check-in on", Many: "{n} warm-ups and check-ins on", InUse: func() (int, error) { s, err := settings.LoadChecked() if err != nil {