diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index e0932a3ed..aae330f9d 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -2008,6 +2008,8 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; } .mchip.on { color: var(--accent); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent); font-weight: 500; } .mchip.on::before { content: "✓"; font-size: 10px; } .mchip.own.on::before { content: "+"; } +/* served with none picked: the vendor's list stands in for the picks */ +.mchip.auto { color: var(--accent); border-style: dashed; border-color: color-mix(in srgb, var(--accent) 45%, transparent); } /* an image model in the editor: listed, not picked */ .mchip.ro, .mchip.ro:hover { cursor: default; color: var(--muted); border-color: var(--line); } .mchip.ro:active { transform: none; } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 37a610c6f..fbf0e4084 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -6286,11 +6286,15 @@ function renderModels(p) { chips.replaceChildren(); const f = (q?.value || "").trim().toLowerCase(); let shown = 0; + // with none picked agents are served the vendor's list, up to 24 of + // it: those are drawn as served, not as left out (#614: the one model + // unticked and saved was still "1 model" on the card) + const served = draft.chosen.length || decideOnly(p) || draft.unlisted ? new Set() : new Set(p.models.slice(0, 24).map((m) => m.id)); // a filter is a search: what it doesn't match is left out, picked or not for (const m of p.models) { const on = draft.chosen.includes(m.id); if (f && !m.id.toLowerCase().includes(f) && !(m.name || "").toLowerCase().includes(f) && !(m.default || "").toLowerCase().includes(f)) continue; - const c = el("button", "mchip" + (on ? " on" : "")); + const c = el("button", "mchip" + (on ? " on" : served.has(m.id) ? " auto" : "")); c.append(el("span", "", m.name && m.name !== m.id ? m.name : m.id)); // one the plan serves at no cost to it (WorkBuddy's x0.00 credits) // or one its vendor names free (#185) @@ -6303,6 +6307,7 @@ function renderModels(p) { if (m.default) c.title = `${m.id} · ${m.default}`; else if (m.name && m.name !== m.id) c.title = m.id; if (free) c.title = (c.title || m.id) + " · " + t(m.free ? "free: it doesn't use the plan's credits" : "free: so its name says"); + if (served.has(m.id)) c.title = (c.title || m.id) + "\n" + t("Agents see it: none are picked, so the vendor's list is used"); tested(c, m.id); menu(c, m.id); c.onclick = () => { draft.chosen = on ? draft.chosen.filter((x) => x !== m.id) : [...draft.chosen, m.id]; draw(); }; @@ -6326,7 +6331,7 @@ function renderModels(p) { drawNames(); why.textContent = decideOnly(p) ? t("Agents never see them: a routing group picks one as its classifier.") : draft.unlisted ? t("Agents don't see them: only the routing groups they are in use them.") - : t(draft.chosen.length ? "Agents see the models picked." : "None picked: agents see the vendor's list, up to {n}.", { n: 24 }); + : t(draft.chosen.length ? "Agents see the models picked." : "None picked: agents see the vendor's list, up to {n}. To show them none, tick Only through routing groups, or switch the provider off.", { n: 24 }); drawLost(); }; // those of its models in no routing group, while it is kept for groups: diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 29a16a8ec..f46c73cf0 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -2220,7 +2220,8 @@ const I18N = { "Pick {group}": "选 {group}", "{provider} is used only through routing groups: agents reach {model} by picking {group}.": "{provider} 设为只通过路由分组使用:选 {group} 即可用到 {model}。", "{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} 设为只通过路由分组使用,而 {model} 不在任何分组里,所以没有 Agent 能用到它。可以用它建一个分组,或在 {provider} 的模型里取消勾选「只通过路由分组使用」。", - "None picked: agents see the vendor's list, up to {n}.": "未勾选:Agent 看到供应商的列表,最多 {n} 个。", + "None picked: agents see the vendor's list, up to {n}. To show them none, tick Only through routing groups, or switch the provider off.": "未勾选:Agent 看到供应商的列表,最多 {n} 个。不想让 Agent 看到任何模型,就勾选「只通过路由分组使用」,或关掉这个供应商。", + "Agents see it: none are picked, so the vendor's list is used": "Agent 能看到它:没有勾选任何模型时,用的是供应商的列表", "Add a server once and switch it on for the agents that should have it — magpie writes it into each one's config in the shape that agent reads.": "服务器只需添加一次,再为需要的 Agent 开启 — magpie 会按各 Agent 能读的格式写进它们的配置。", "+ Add a server": "+ 添加服务器", "No servers in the library yet": "资源库里还没有服务器", diff --git a/internal/gui/tests/provider-none-picked.test.cjs b/internal/gui/tests/provider-none-picked.test.cjs new file mode 100644 index 000000000..0efe286f3 --- /dev/null +++ b/internal/gui/tests/provider-none-picked.test.cjs @@ -0,0 +1,89 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// A provider with none of its models picked serves agents its vendor's +// list (#614: the one model unticked and saved was still "1 model" on the +// card, and the editor showed it unticked as if left out). With no pick the +// models agents are served are drawn as served (dashed, .auto), their title +// says why, and the hint says how to show agents none. A pick drops the +// rest back to plain chips. In English and Chinese, Chromium and WebKit. +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 fetched = new Date(Date.now() - 3600e3).toISOString(); +const relay = { + id: "router", name: "Router", icon: "generic", host: "router.example.com", chat: "https://router.example.com/v1", responses: "", anthropic: "", catalog: "", + models: [{ id: "glm-5.3-free", name: "glm-5.3-free", on: true }, { id: "glm-5.2", name: "glm-5.2", on: true }], chosen: [], fetched, agents: [], fallback: [], headers: {}, + key: { set: true, masked: "sk-…one" }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "", +}; + +function serve(lang) { + const providers = { providers: [relay], presets: [], excluded: [], gateway: { running: true, window: true } }; + const state = { agents: [], profiles: [], settings: { lang, theme: "light" } }; + return async (route) => { + const req = route.request(), url = new URL(req.url()); + const json = (data) => route.fulfill({ json: data }); + if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` }); + 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/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/providers") return json(providers); + if (url.pathname === "/api/groups") return json({ groups: [] }); + 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 }); + }; +} + +const words = { + en: { why: "Agents see it: none are picked", hint: "To show them none, tick Only through routing groups" }, + zh: { why: "Agent 能看到它:没有勾选任何模型时", hint: "不想让 Agent 看到任何模型,就勾选「只通过路由分组使用」" }, +}; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of ["en", "zh"]) { + const w = words[lang]; + test(`${engine} ${lang}: with none picked, the models agents are served are drawn as served`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const page = await (await browser.newContext({ viewport: { width: 900, height: 760 }, 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, `${engine}-${lang}-provider-none-picked.png`) }); + } + await browser.close(); + }); + page.setDefaultTimeout(5000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang)); + await page.goto("http://magpie.test/?view=providers"); + await page.locator(".row.provider", { hasText: "Router" }).click(); + const editor = page.locator("#modal:not([hidden]) .editor"); + const chip = (id) => editor.locator(".mchips .mchip", { hasText: id }); + await chip("glm-5.2").waitFor(); + const cls = (id) => chip(id).evaluate((c) => [c.classList.contains("on"), c.classList.contains("auto")]); + + // opened, both are served and shown picked; unpick both + assert.deepEqual(await cls("glm-5.3-free"), [true, false]); + await chip("glm-5.3-free").click(); + await chip("glm-5.2").click(); + for (const id of ["glm-5.3-free", "glm-5.2"]) { + assert.deepEqual(await cls(id), [false, true], id + " drawn as served"); + assert.ok((await chip(id).getAttribute("title")).includes(w.why), id + " title"); + } + assert.equal(await chip("glm-5.2").evaluate((c) => getComputedStyle(c).borderTopStyle), "dashed"); + await editor.getByText(w.hint).waitFor(); + + // one picked: the other is plain, left out + await chip("glm-5.2").click(); + assert.deepEqual(await cls("glm-5.2"), [true, false]); + assert.deepEqual(await cls("glm-5.3-free"), [false, false]); + assert.equal(await editor.getByText(w.hint).count(), 0); + assert.deepEqual(errors, []); + }); + } +}