"希望 可以在不同的 agent中选择是否显示供应商名字,现在只能统一开关":
Provider in model names was one switch for every agent. An agent's
Details on the Agents page now has a Provider in model names row: As in
Settings · <mode> (the default, kept for everyone), On, Not on names I
set, or Off, for that agent alone. The CLI has the same thing:
`magpie model suffix <agent> [on|own|off|every]`.
- settings.AgentSuffix keeps the agent's own mode by the id its lists are
kept by (Agent.ListsFor, lower-cased, without @wsl: or #profile). An
agent with none follows PlainNames/PlainOwnNames as before, so nothing
a user already set changes.
- provider.LabelsFor(agent, es) reads that agent's mode. Every place
that named models with Labels for an agent now passes the agent: Codex's
catalog, the agents' written lists (route.go, Pi's extension), the
gateway's /v1/models (by agentOf(r)), Muse, Antigravity, Ollama, Claude
Desktop's catalog and descriptions, Claude Science. Labels is
LabelsFor("").
- POST /api/settings/agent-suffix sets it and rewrites the agents'
configs (catalog.Touched), as Settings' switch does.
- docs/subsystems/agent-wiring.md says where the mode is kept and read.
- The picker is in agentsuffix.js, imported when an agent's Details open,
so the core grows by the one line that loads it (1,529,335 of its
1,533,802 budget, after the previous commit's move). An agent whose
list takes no names of magpie's (noNames) has no row.
Tests, each red on the old code: TestAgentSuffix (provider: modes, keys
with @wsl and #profile, reset, bad input), TestAgentSuffixReachesItsFileAlone
(agent: Pi's file follows its own mode while Codex's follows Settings'),
TestModelsListFollowsAgentSuffix (gateway /v1/models per agent),
TestModelSuffixAgentCmd (cli), settings_keep (AgentSuffix survives a
Settings save), agent-suffix.test.cjs (5 languages x 1180/390 x chromium
and webkit, and a noNames agent has no row).
Broken by hand (a copy with LabelsFor ignoring the agent and the picker
reading no own mode): TestAgentSuffix, TestAgentSuffixReachesItsFileAlone,
TestModelsListFollowsAgentSuffix and every agent-suffix GUI case went red.
TestModelSuffixAgentCmd stayed green; it checks what is saved, not the
names.
Run on mote at this change on top of 720200092: gofmt -l clean; go vet darwin, GOOS=linux
-tags nogui and GOOS=windows clean; go test -count=1 of internal/provider,
cli, gui, settings, settingsapi and agent: ok; internal/gateway in an earlier
run of this change at 3b261932e: ok (1044s), and at this head -run
'Desktop|Models|Suffix|Science|Muse|Ollama|Antigravity|Codex.*Catalog': ok.
node --test of every agent-*, i18n-* and gui-* file plus old-webkit, both
engines: 1026 of 1049. The reds are all on main or under load:
agent-switch-accounts' 20 not-connected cases (red at origin/main 7c41060c2
too, filed as #5925), old-webkit's Safari 15 styles (#5919), and one case
each of agent-compact (#5607) and agent-stale-copies (#1949), which pass
44/44 when run alone. panel-fold's 'keeps what was clicked' is red on main
too (#5796).
Rebased on 0f94acc99 and run again at this change (9d82986ea): gofmt
clean, go vet clean for darwin, linux (nogui) and windows; provider,
gui, settings, settingsapi and agent ok, the gateway's suffix and
agentOf tests ok; GUI agent-suffix, old-webkit, agent-bulk-visibility,
visibility-saving, i18n-keys and i18n-en-no-cjk in chromium and webkit,
57 of 58, the one red Safari 15's styles (#5919). internal/cli was red
only on /api/model-price having no command, from main's 40ca0c88d;
the next commit names it. Rebased again on ccc96b4a7 before the push
(proc, codex, claudetui, a remote window, routing rules, redact;
no conflict), core budget test ok there.
Not tried: a real agent with a real account picking its own mode; WSL and
Windows agents (the @wsl: key is covered by a unit test only).
108 lines
6.4 KiB
JavaScript
108 lines
6.4 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// KillTry27355 on X: Provider in model names was one switch for every
|
|
// agent. An agent's Details now has its own: As in Settings (every agent's,
|
|
// named), On, Not on names I set or Off, saved for that agent by the id its
|
|
// lists are kept by (settings.AgentSuffix). An agent whose list doesn't take
|
|
// magpie's names (noNames) has none. Every language, narrow too.
|
|
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 { agentRow } = require("./reader.cjs");
|
|
|
|
const assets = process.env.MAGPIE_ASSETS || path.resolve(__dirname, "../assets");
|
|
const words = {
|
|
en: { every: "As in Settings · Off", on: "On", off: "Off", label: "Provider in model names" },
|
|
zh: { every: "跟随设置 · 关闭", on: "开启", off: "关闭", label: "模型名带供应商" },
|
|
"zh-TW": { every: "跟隨設定 · 關閉", on: "開啟", off: "關閉", label: "模型名帶供應商" },
|
|
ja: { every: "設定に従う · オフ", on: "オン", off: "オフ", label: "モデル名にプロバイダ" },
|
|
de: { every: "Wie in Einstellungen · Aus", on: "An", off: "Aus", label: "Anbieter in Modellnamen" },
|
|
};
|
|
const row = (id) => `.row.agent[data-id="${id}"]`;
|
|
const withModels = (a) => ({ ...a, models: { shown: 1, listed: 1, by: [{ name: "Relay", icon: "generic", n: 1 }] } });
|
|
|
|
async function openPage(t, engine, lang, width) {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
|
|
const page = await browser.newPage({ viewport: { width, height: 900 }, reducedMotion: "reduce" });
|
|
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}-${width}-agent-suffix.png`) });
|
|
}
|
|
await browser.close();
|
|
});
|
|
page.setDefaultTimeout(8000);
|
|
const errors = [], posts = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
// every agent's is Off; OpenCode has none of its own yet
|
|
const cur = { lang, theme: "light", plainNames: true, agentSuffix: {} };
|
|
const agents = [withModels(agentRow("opencode", "OpenCode")), withModels({ ...agentRow("goose", "Goose"), noNames: true })];
|
|
await page.route("**/*", async (route) => {
|
|
const url = new URL(route.request().url()), json = (data) => route.fulfill({ json: data });
|
|
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs={lang:${JSON.stringify(lang)},theme:"light",web:false};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json({ agents, profiles: [], settings: cur });
|
|
if (url.pathname === "/api/settings") return json(cur);
|
|
if (url.pathname === "/api/settings/agent-suffix") {
|
|
const body = route.request().postDataJSON();
|
|
posts.push(body);
|
|
const own = { ...cur.agentSuffix };
|
|
if (body.mode) own[body.agent] = body.mode; else delete own[body.agent];
|
|
cur.agentSuffix = own;
|
|
return json(cur);
|
|
}
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (url.pathname === "/api/usage/quotas") return json([]);
|
|
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
|
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } });
|
|
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)];
|
|
try { await route.fulfill({ body: await fs.readFile(file), contentType }); }
|
|
catch { await route.fulfill({ status: 404, body: "" }); }
|
|
});
|
|
await page.goto("http://magpie.test/?view=agents");
|
|
await page.locator(row("opencode") + " .ag-link").waitFor();
|
|
return { page, errors, posts };
|
|
}
|
|
|
|
const overflows = (page) => page.evaluate(() => document.documentElement.scrollWidth > document.documentElement.clientWidth);
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const lang of Object.keys(words)) for (const width of [1180, 390]) {
|
|
test(`${engine} ${lang} ${width}: an agent's Details sets its own Provider in model names`, async (t) => {
|
|
const w = words[lang];
|
|
const { page, errors, posts } = await openPage(t, engine, lang, width);
|
|
await page.locator(row("opencode") + " .ag-link").click();
|
|
const pick = page.locator(row("opencode") + " .ag-suffix");
|
|
await pick.waitFor();
|
|
const key = pick.locator("xpath=ancestor::div[contains(@class,'ag-kv')]").locator(".ag-k");
|
|
assert.equal(await key.textContent(), w.label);
|
|
assert.equal((await pick.textContent()).trim(), w.every);
|
|
assert.equal(await overflows(page), false, "the page scrolls sideways");
|
|
|
|
await pick.click();
|
|
await page.locator(".sess-menu .pm-item", { hasText: new RegExp(`^\\s*${w.on}\\s*$`) }).click();
|
|
await page.waitForFunction(() => document.querySelector('.row.agent[data-id="opencode"] .ag-suffix')?.dataset.mode === "on");
|
|
assert.deepEqual(posts, [{ agent: "opencode", mode: "on" }]);
|
|
assert.equal((await page.locator(row("opencode") + " .ag-suffix").textContent()).trim(), w.on);
|
|
|
|
// back to every agent's
|
|
await page.locator(row("opencode") + " .ag-suffix").click();
|
|
await page.locator(".sess-menu .pm-item", { hasText: w.every }).click();
|
|
await page.waitForFunction(() => document.querySelector('.row.agent[data-id="opencode"] .ag-suffix')?.dataset.mode === "");
|
|
assert.deepEqual(posts.at(-1), { agent: "opencode", mode: "" });
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
|
|
test(`${engine}: an agent whose list takes no names of magpie's has none`, async (t) => {
|
|
const { page, errors } = await openPage(t, engine, "en", 1180);
|
|
await page.locator(row("goose") + " .ag-link").click();
|
|
await page.locator(row("goose") + " .ag-exp").waitFor();
|
|
assert.equal(await page.locator(row("goose") + " .ag-suffix").count(), 0);
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|