provider, gui, cli: a group can keep its models out of the lists agents see, offered through the group alone (#1783)

cybershape asked for a client's model list to show only a group, not
every model behind it. A provider could already be kept for routing
groups (Provider.Unlisted), but that hides the whole provider, and the
models a group names may come from providers used elsewhere too.

Group.Unlists (json "unlists"): the models a group names (a member fixed
at an effort counts as its model) and those its patterns match leave
Catalog(), so `magpie models`, /v1/models and every agent's list
(CatalogFor) show the group without them. They stay in Served(), so a
group routes over them and a request naming one as provider/model is
still answered, and Unlisted() returns them for the GUI as it does an
unlisted provider's. A nested group keeps its own setting; a group
switched off or hidden keeps nothing out. With no group unlisting,
Catalog() takes a fast path and is unchanged.

- Routing view: the group editor's "Model lists" (Its models too / The
  group alone, segmented, with a hint), saved with Save; the card shows
  "Its models unlisted". Both group Save paths send unlists. zh, zh-TW,
  ja, de.
- CLI: `magpie group set <id> listed=no|yes`; `magpie group <id>` shows
  listed: no.
- TUI: the group member picker offered Catalog(), so models kept out of
  the lists (an unlisted provider's, before this too) couldn't be put in
  a group from the TUI. It offers Served(), as the GUI's picker does.
- docs/reference.md, Routing groups: listed=no.

Product call: a per-group switch, off by default, rather than hiding
members of every group, so existing lists don't change under anyone.

Run:
- go test ./internal/provider -run 'Group|Catalog|Unlisted|Served',
  ./internal/gui, root package, ./internal/tui: ok.
  TestGroupUnlistsItsModels fails with the Catalog filter removed;
  TestMemberOptionsOfferUnlistedModels fails with the picker on
  Catalog(); TestApplyGroupPairs covers listed=no/YES/maybe.
- GUI group-unlists.test.cjs, Chromium and WebKit, en zh zh-TW ja de, at
  1100px and 420px: 20/20. i18n-keys: ok.
- gofmt; go vet darwin, windows, linux (-tags nogui): clean.

Not tried: with the reporter's own client; a real agent's model file
written after toggling (CatalogFor is covered by the test).
This commit is contained in:
yetone
2026-10-12 19:38:18 +08:00
parent 0d58ec8dcb
commit c533499446
11 changed files with 362 additions and 12 deletions
+9
View File
@@ -1116,6 +1116,15 @@ the vendor's cache of it is worth keeping), `session`, `turn` or `off`.
`models=` replaces the whole list, in order; a bare model id works when only
one provider serves it.
`listed=no` (the group editor's **Model lists: The group alone**) keeps the
models a group names, and those its patterns match, out of `magpie models`,
`/v1/models` and every agent's list, so a client offers the group alone.
They are still served: the group routes over them, and a request naming one
as `provider/model` is answered. A group in it keeps its own setting, and a
group switched off keeps nothing out. `listed=yes` lists them again. To keep
a whole provider for groups, use its **Only through routing groups** switch
instead.
A group can also be of decision models alone (Jev and the like: TypeSafe's,
Bailian's `decision-model-preview`, a plugin's marked models) — never mixed
with models that hold a conversation. It is not offered to agents; it is asked
+17 -2
View File
@@ -33,7 +33,9 @@ const groupUsage = `usage:
effort=auto (the classifier picks each turn's reasoning; needs classifier=),
effort=agent (the agent's again), classifier=<provider/model>|group/<id>,
pick=<model> (routing=manual, every request to that one of its models),
fast=<m1>[,m2…] (the models sent in their vendor's fast mode; empty for none)
fast=<m1>[,m2…] (the models sent in their vendor's fast mode; empty for none),
listed=no (its models leave the lists agents see, offered through the
group alone; listed=yes lists them too again)
magpie group pick <id> <model> route the group manually, every request to that one of its models
(as clicking it on the group's card in the Routing view does)
magpie group copy <id> [name] duplicate a group with its models, routing and rules, listed after it
@@ -434,6 +436,16 @@ func applyGroupPairs(g *provider.Group, pairs []string, resolve func(string) (st
}
case "family", "tag":
g.Family = strings.TrimSpace(v)
case "listed":
// no: the models in it leave the lists agents see (#1783)
switch strings.ToLower(strings.TrimSpace(v)) {
case "no":
g.Unlists = true
case "yes":
g.Unlists = false
default:
err = fmt.Errorf("listed=no (its models offered through the group alone) or listed=yes, not %q", v)
}
case "effort", "reasoning":
switch strings.ToLower(strings.TrimSpace(v)) {
case "auto", "jev":
@@ -463,7 +475,7 @@ func applyGroupPairs(g *provider.Group, pairs []string, resolve func(string) (st
g.Pick, err = pickMember(g.Members, v)
g.Routing = provider.Manual
default:
return fmt.Errorf("unknown field %q (fields: name, models, models+, models-, routing, pick, stays, context, levels, family, effort, classifier, fast; magpie group help)", k)
return fmt.Errorf("unknown field %q (fields: name, models, models+, models-, routing, pick, stays, context, levels, family, effort, classifier, fast, listed; magpie group help)", k)
}
if err != nil {
return err
@@ -1005,6 +1017,9 @@ func showGroup(g provider.Group) error {
kv("routing", routingName(g.Routing))
}
kv("stays", staysName(g.Affinity))
if g.Unlists {
kv("listed", "no"+muted.Render(" its models are offered through the group alone; listed=yes lists them too"))
}
names := catalogByID()
for i, id := range g.Members {
k := ""
+8 -1
View File
@@ -126,7 +126,14 @@ func TestApplyGroupPairs(t *testing.T) {
t.Errorf("context=%s: %d %v", c.v, g.Context, err)
}
}
for _, bad := range [][]string{{"models"}, {"colour=red"}, {"id=x"}, {"models=nope"}, {"routing=fast"}, {"models-=a/m"}, {"context=lots"}} {
// listed=no: its models offered through the group alone (#1783)
if err := applyGroupPairs(&g, []string{"listed=no"}, resolve, false); err != nil || !g.Unlists {
t.Fatalf("listed=no: %v %v", g.Unlists, err)
}
if err := applyGroupPairs(&g, []string{"listed=YES"}, resolve, false); err != nil || g.Unlists {
t.Fatalf("listed=yes: %v %v", g.Unlists, err)
}
for _, bad := range [][]string{{"models"}, {"colour=red"}, {"id=x"}, {"models=nope"}, {"routing=fast"}, {"models-=a/m"}, {"context=lots"}, {"listed=maybe"}} {
h := g
if err := applyGroupPairs(&h, bad, resolve, false); err == nil {
t.Errorf("%v: no error", bad)
+24
View File
@@ -3026,6 +3026,12 @@ const I18N = {
"Keeps its place": "保持原位",
"Goes to the back": "排到最后",
"Rate limited to the back": "限流后排到最后",
"Model lists": "模型列表",
"Its models too": "也列出成员模型",
"The group alone": "只列出本组",
"Its models unlisted": "成员模型不单独列出",
"Agents' model lists and the gateway's /v1/models show the group and each of its models.": "Agent 的模型列表和网关的 /v1/models 会列出本组,也列出组里的每个模型。",
"Agents' model lists and the gateway's /v1/models show the group, not the models it names or its patterns match: they are used through it. A request naming one is still answered.": "Agent 的模型列表和网关的 /v1/models 只列出本组,不列出它点名的模型和模式匹配到的模型:这些模型通过本组使用。直接点名其中一个模型的请求仍会被应答。",
"Wait": "一直等",
"2 min": "2 分钟",
"Slow to start": "迟迟不出字",
@@ -7360,6 +7366,12 @@ const I18N = {
"Keeps its place": "保持原位",
"Goes to the back": "排到最後",
"Rate limited to the back": "限流後排到最後",
"Model lists": "模型清單",
"Its models too": "也列出成員模型",
"The group alone": "只列出本組",
"Its models unlisted": "成員模型不單獨列出",
"Agents' model lists and the gateway's /v1/models show the group and each of its models.": "Agent 的模型清單和閘道的 /v1/models 會列出本組,也列出組裡的每個模型。",
"Agents' model lists and the gateway's /v1/models show the group, not the models it names or its patterns match: they are used through it. A request naming one is still answered.": "Agent 的模型清單和閘道的 /v1/models 只列出本組,不列出它點名的模型和模式比對到的模型:這些模型透過本組使用。直接點名其中一個模型的請求仍會被回應。",
"Wait": "一直等",
"2 min": "2 分鐘",
"Slow to start": "遲遲不出字",
@@ -11707,6 +11719,12 @@ const I18N = {
"Keeps its place": "位置を維持",
"Goes to the back": "最後尾へ",
"Rate limited to the back": "レート制限で最後尾へ",
"Model lists": "モデル一覧",
"Its models too": "メンバーのモデルも",
"The group alone": "グループだけ",
"Its models unlisted": "メンバーは一覧に出さない",
"Agents' model lists and the gateway's /v1/models show the group and each of its models.": "エージェントのモデル一覧とゲートウェイの /v1/models に、グループとその各モデルが並びます。",
"Agents' model lists and the gateway's /v1/models show the group, not the models it names or its patterns match: they are used through it. A request naming one is still answered.": "エージェントのモデル一覧とゲートウェイの /v1/models にはグループだけが並び、指定したモデルやパターンに合うモデルは出ません。これらはグループを通して使われます。モデルを名指しするリクエストには引き続き応答します。",
"Wait": "待つ",
"2 min": "2 分",
"Slow to start": "応答開始が遅いとき",
@@ -16053,6 +16071,12 @@ const I18N = {
"Keeps its place": "Behält seinen Platz",
"Goes to the back": "Wandert nach hinten",
"Rate limited to the back": "Bei Rate-Limit nach hinten",
"Model lists": "Modelllisten",
"Its models too": "Auch seine Modelle",
"The group alone": "Nur die Gruppe",
"Its models unlisted": "Modelle nicht gelistet",
"Agents' model lists and the gateway's /v1/models show the group and each of its models.": "Die Modelllisten der Agenten und /v1/models des Gateways zeigen die Gruppe und jedes ihrer Modelle.",
"Agents' model lists and the gateway's /v1/models show the group, not the models it names or its patterns match: they are used through it. A request naming one is still answered.": "Die Modelllisten der Agenten und /v1/models des Gateways zeigen die Gruppe, nicht die Modelle, die sie nennt oder deren Muster passen: Sie werden über die Gruppe genutzt. Eine Anfrage, die eines davon nennt, wird weiter beantwortet.",
"Wait": "Warten",
"2 min": "2 Min.",
"Slow to start": "Langsamer Start",
+20 -3
View File
@@ -3011,6 +3011,12 @@
// what one rate limited with quota left does then (provider.Sink), as in
// a provider's editor (app.js SINKS)
const SINK_OPTS = [["", "Keeps its place"], ["sink", "Goes to the back"]];
// whether agents' model lists show the group's models too (#1783)
const LIST_OPTS = [["", "Its models too"], ["unlists", "The group alone"]];
const LIST_HINT = {
"": "Agents' model lists and the gateway's /v1/models show the group and each of its models.",
unlists: "Agents' model lists and the gateway's /v1/models show the group, not the models it names or its patterns match: they are used through it. A request naming one is still answered.",
};
const SINK_HINT = {
"": "One rate limited while it still has quota rests as long as the vendor asks, then takes its place in the order again.",
sink: "One rate limited (429) while it still has quota goes to the back of the order, behind every one not rate limited since, and comes round again once those ahead of it are rate limited in turn — so the load goes round rather than back to the first each time. Out of quota, it rests as usual. Kept until magpie restarts.",
@@ -3166,7 +3172,7 @@
// there, rather than leaving the slot empty.
const openGroupEditor = async (g) => {
if (groupDirty() && !(await confirmDiscard())) return false;
gEdit = { id: g.id, draft: { name: g.name, members: [...g.members], match: [...(g.match || [])], matched: [...(g.matched || [])], fast: [...(g.fast || [])], off: [...(g.off || [])], routing: g.routing || "", pick: g.pick || "", affinity: g.affinity || "", sink: !!g.sink, firstToken: g.firstToken || 0, patience: patienceOf(g.patience), context: g.context || 0, classifier: g.classifier || "", effort: g.effort || "", levels: [...(g.levels || [])], rules: (g.rules || []).map((r) => ({ ...r, intent: r.intent || "", agents: [...(r.agents || [])], folders: [...(r.folders || [])], exceptFolders: [...(r.exceptFolders || [])], time: r.time ? { ...r.time, days: [...(r.time.days || [])] } : null })) } };
gEdit = { id: g.id, draft: { name: g.name, members: [...g.members], match: [...(g.match || [])], matched: [...(g.matched || [])], fast: [...(g.fast || [])], off: [...(g.off || [])], routing: g.routing || "", pick: g.pick || "", affinity: g.affinity || "", sink: !!g.sink, unlists: !!g.unlists, firstToken: g.firstToken || 0, patience: patienceOf(g.patience), context: g.context || 0, classifier: g.classifier || "", effort: g.effort || "", levels: [...(g.levels || [])], rules: (g.rules || []).map((r) => ({ ...r, intent: r.intent || "", agents: [...(r.agents || [])], folders: [...(r.folders || [])], exceptFolders: [...(r.exceptFolders || [])], time: r.time ? { ...r.time, days: [...(r.time.days || [])] } : null })) } };
renderGroups();
return true;
};
@@ -3603,6 +3609,11 @@
k.title = t(SINK_HINT.sink);
tags.append(k);
}
if (g.unlists) {
const k = el("span", "tag unlists", t("Its models unlisted"));
k.title = t(LIST_HINT.unlists);
tags.append(k);
}
if (g.firstToken > 0 && !manual) tags.append(el("span", "tag", t("Next after {n} without a first token", { n: took(g.firstToken * 1000) })));
if (g.rules?.length) {
const r = el("span", "tag" + (manual ? " idle" : ""), t(g.rules.length === 1 ? "1 rule" : "{n} rules", { n: g.rules.length }));
@@ -3759,7 +3770,7 @@
b.onclick = (e) => {
e.stopPropagation(); // the card opens the editor; this picks
if (on) return;
groupAction("save", { id: g.id, name: g.name, members: namedOf(g), match: g.match || [], routing: "manual", pick: id, affinity: g.affinity || "", sink: !!g.sink, firstToken: g.firstToken || 0, patience: g.patience || 0, rules: g.rules || [], effort: g.effort || "", classifier: g.classifier || "", context: g.context || 0, levels: g.levels || [], family: g.family || "", fast: g.fast || [], off: g.off || [] },
groupAction("save", { id: g.id, name: g.name, members: namedOf(g), match: g.match || [], routing: "manual", pick: id, affinity: g.affinity || "", sink: !!g.sink, firstToken: g.firstToken || 0, patience: g.patience || 0, rules: g.rules || [], effort: g.effort || "", classifier: g.classifier || "", context: g.context || 0, levels: g.levels || [], family: g.family || "", fast: g.fast || [], off: g.off || [], unlists: !!g.unlists },
t("{name}: every request to {model}", { name: g.name, model: memberName(id) }));
};
box.append(b);
@@ -4085,6 +4096,12 @@
const pw = el("div");
pw.append(pbox, el("div", "hint", t("Every model a pattern matches is in the group, now and as providers list new ones, after the models above: * is any run of characters in provider/model, re: starts a regular expression.")));
ed.append(el("label", "", t("Patterns")), pw);
// its models in the lists agents see too, or the group alone (#1783)
const listHint = el("div", "hint", t(LIST_HINT[d.unlists ? "unlists" : ""])), listW = el("div");
const listPick = segs(LIST_OPTS.map(([id, n]) => [id, t(n)]), d.unlists ? "unlists" : "", (v) => { d.unlists = v === "unlists"; listHint.textContent = t(LIST_HINT[v]); });
listPick.classList.add("list-pick");
listW.append(listPick, listHint);
ed.append(el("label", "", t("Model lists")), listW);
const rHint = el("div", "hint", t(GROUP_HINT[d.routing] || GROUP_HINT[""]));
const rw = el("div");
@@ -4509,7 +4526,7 @@
if (own && !d.levels.length) return status(t("Pick a level to offer, or leave them to its models"), "warn");
saveBtn.classList.add("busy");
// refused, Add can be pressed again (busy, it takes no clicks)
groupAction("save", { id: idOf(), from: g?.id, name: d.name.trim() || idOf(), members: namedOf(d), match: d.match, routing: d.routing, pick: d.pick || "", affinity: d.affinity, sink: !!d.sink && sinkable(d.routing), firstToken: d.firstToken || 0, patience: d.patience || 0, rules: d.rules, effort: d.effort, classifier: d.rules.some((r) => r.intent) || d.effort === "auto" ? d.classifier : "", context: d.context || 0, levels: own ? d.levels : [], family: g?.family || "", fast: d.fast.filter((x) => d.members.includes(x)), off: d.off.filter((x) => d.members.includes(x)) }, t(g ? "{name} saved" : "{name} added", { name: d.name.trim() || idOf() }))
groupAction("save", { id: idOf(), from: g?.id, name: d.name.trim() || idOf(), members: namedOf(d), match: d.match, routing: d.routing, pick: d.pick || "", affinity: d.affinity, sink: !!d.sink && sinkable(d.routing), firstToken: d.firstToken || 0, patience: d.patience || 0, rules: d.rules, effort: d.effort, classifier: d.rules.some((r) => r.intent) || d.effort === "auto" ? d.classifier : "", context: d.context || 0, levels: own ? d.levels : [], family: g?.family || "", fast: d.fast.filter((x) => d.members.includes(x)), off: d.off.filter((x) => d.members.includes(x)), unlists: !!d.unlists }, t(g ? "{name} saved" : "{name} added", { name: d.name.trim() || idOf() }))
.then(() => saveBtn.classList.remove("busy"));
};
// what goes wrong is said where it is seen, never a click that does nothing
+136
View File
@@ -0,0 +1,136 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// #1783 (cybershape): a group can keep its models out of the lists agents
// and the gateway's /v1/models show, so a client lists the group alone.
// The group editor's "Model lists": "Its models too", the default, or "The
// group alone", sent with the Save as unlists; the group's card says so.
// No native select, a click never scrolls the page, and every language has
// its words. Wide and narrow.
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 members = ["a/m1", "a/m2"];
const groups = (unlists) => ({
models: members.map((id) => ({ id, name: id.slice(2), providerName: "A", icon: "generic" })),
pools: [],
groups: [{ id: "g", name: "Glim", members, fast: [], off: [], routing: "", ready: true, ...(unlists ? { unlists: true } : {}), memberInfo: members.map((id) => ({ id, ready: true })) }],
});
const prov = { icon: "generic", catalog: "", models: [{ id: "m1", name: "m1", on: true }, { id: "m2", name: "m2", on: true }], agents: [], fallback: [], headers: {}, routing: "order", affinity: "", ready: true, id: "a", name: "A", chat: "http://127.0.0.1:1/v1", responses: "", anthropic: "", keyList: [] };
function serve(lang, posts) {
let unlists = false;
const state = { agents: [{ id: "pi", name: "Pi", path: "/test/pi", fields: [] }], profiles: [], settings: { lang, theme: "light" } };
const providers = { providers: [prov], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } };
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 = {lang:${JSON.stringify(lang)},theme:"light",web:true};` });
if (url.pathname === "/wails/runtime.js") return r.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/gateway/trace") {
if (url.searchParams.get("wait")) return new Promise(() => {}); // nothing more comes
return json({ mine: true, now: new Date().toISOString(), seq: 0, 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(groups(unlists));
if (url.pathname === "/api/providers") return json(providers);
if (r.request().method() === "POST" && url.pathname.startsWith("/api/groups/")) {
const body = JSON.parse(r.request().postData() || "{}");
posts.push({ path: url.pathname, body });
if (url.pathname === "/api/groups/save") unlists = !!body.unlists;
return json(groups(unlists));
}
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 r.fulfill({ body: await fs.readFile(file), contentType }); } catch { await r.fulfill({ status: 404, body: "" }); }
};
}
const H0 = "Agents' model lists and the gateway's /v1/models show the group and each of its models.";
const H1 = "Agents' model lists and the gateway's /v1/models show the group, not the models it names or its patterns match: they are used through it. A request naming one is still answered.";
const KEYS = ["Model lists", "Its models too", "The group alone", "Its models unlisted", H0, H1, "Edit", "Save"];
const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
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]) {
const launch = () => engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" });
test(`${engine} ${lang} ${width}px: a group lists itself alone, made with its Save`, async (t) => {
const browser = await launch();
t.after(() => browser.close());
const height = 1000;
const page = await (await browser.newContext({ viewport: { width, height }, reducedMotion: "reduce" })).newPage();
page.setDefaultTimeout(5000);
const errors = [], posts = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, posts));
await page.goto("http://magpie.test/?view=routing");
const card = page.locator(".rt-group", { hasText: "Glim" });
await card.waitFor();
const w = await page.evaluate(([keys, lang]) => Object.fromEntries(keys.map((k) => [k, lang === "en" ? k : I18N[lang][k]])), [KEYS, lang]);
assert.deepEqual(Object.entries(w).filter(([, v]) => !v).map(([k]) => k), [], "every string has its words");
assert.equal(await card.locator(".tag.unlists").count(), 0, "listed by default: no tag");
const ed = page.locator(".rt-gedit");
const label = ed.locator("label", { hasText: new RegExp(`^${esc(w["Model lists"])}$`) });
const field = label.locator("xpath=following-sibling::div[1]");
const opt = (k) => field.locator(".list-pick .opt", { hasText: new RegExp(`^${esc(w[k])}$`) });
const save = ed.locator("button.primary", { hasText: w.Save });
const saveIt = async () => {
await page.mouse.move(width / 2, 500); // the reader scrolls to it
for (let i = 0; i < 20 && (await save.boundingBox()).y > height - 160; i++) {
await page.mouse.wheel(0, 300);
await page.waitForTimeout(150);
}
const bb = await save.boundingBox();
await page.mouse.click(bb.x + bb.width / 2, bb.y + bb.height / 2);
await page.waitForFunction(() => !document.querySelector(".rt-gedit"));
};
const toOpt = async (k) => {
await page.mouse.move(width / 2, 500);
for (let i = 0; i < 20 && (await opt(k).boundingBox()).y > height - 160; i++) {
await page.mouse.wheel(0, 300);
await page.waitForTimeout(150);
}
};
await card.locator("button", { hasText: w.Edit }).click();
await label.waitFor();
assert.match(await opt("Its models too").getAttribute("class"), /\bon\b/, "its models too by default");
assert.equal(await field.locator(".hint").last().textContent(), w[H0]);
await toOpt("The group alone");
const box = await opt("The group alone").boundingBox();
assert.ok(box.x >= 0 && box.x + box.width <= width, `the option fits the width: ${JSON.stringify(box)}`);
const y = await page.evaluate(() => document.scrollingElement.scrollTop);
await opt("The group alone").click();
assert.match(await opt("The group alone").getAttribute("class"), /\bon\b/);
assert.equal(await field.locator(".hint").last().textContent(), w[H1]);
assert.equal(await page.evaluate(() => document.scrollingElement.scrollTop), y, "a click never scrolls the page");
assert.equal(await page.locator("select").count(), 0, "no native select");
assert.deepEqual(posts, [], "nothing is sent before the Save");
await saveIt();
assert.equal(posts.find((p) => p.path === "/api/groups/save")?.body.unlists, true);
const tag = card.locator(".tag.unlists");
await tag.waitFor();
assert.equal((await tag.textContent()).trim(), w["Its models unlisted"]);
assert.equal(await tag.getAttribute("title"), w[H1]);
// and back: its models listed again
await card.locator("button", { hasText: w.Edit }).click();
await label.waitFor();
assert.match(await opt("The group alone").getAttribute("class"), /\bon\b/, "the editor opens with what was saved");
await toOpt("Its models too");
await opt("Its models too").click();
await saveIt();
assert.equal(posts.filter((p) => p.path === "/api/groups/save").at(-1).body.unlists, false);
await page.waitForFunction(() => !document.querySelector(".rt-group .tag.unlists"));
assert.deepEqual(errors, []);
});
}
}
}
+7
View File
@@ -210,6 +210,13 @@ type Group struct {
// Family is a tag the group goes by in which agents are shown it
// (settings' Visible), with its id.
Family string `json:"family,omitempty"`
// Unlists keeps the models the group names, or its patterns match,
// out of the lists agents and the gateway's model list show (#1783):
// they are offered through the group alone, as a provider kept for
// routing groups offers its own (Provider.Unlisted), and a request
// naming one is still served. A group in it keeps its own, as it
// says. Not while the group is switched off.
Unlists bool `json:"unlists,omitempty"`
// Auto is set on a group magpie found: one model served by several
// providers. It is derived, never stored.
Auto bool `json:"auto,omitempty"`
+79
View File
@@ -0,0 +1,79 @@
package provider
import (
"slices"
"testing"
)
// #1783 (cybershape): a group can keep its models out of the lists agents
// and the gateway's /v1/models show, so a client lists the group alone.
// The models it names, fixed at an effort too, and those its patterns
// match leave the lists; a group in it keeps its own; the models stay
// served (a request naming one, the group itself) and are kept for the
// GUI as the unlisted provider's are. Switched off, the group keeps
// nothing out.
func TestGroupUnlistsItsModels(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("USERPROFILE", t.TempDir())
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
for _, p := range []Provider{
{ID: "a", Name: "a", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m1", "m2", "m3"}},
{ID: "b", Name: "b", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"n1", "n2"}},
} {
if err := Save(p); err != nil {
t.Fatal(err)
}
}
if err := SaveGroup(Group{Name: "Inner", Members: []string{"a/m3"}}); err != nil {
t.Fatal(err)
}
if err := SaveGroup(Group{Name: "G", Members: []string{"a/m1:high", "group/inner"}, Match: []string{"b/*"}, Unlists: true}); err != nil {
t.Fatal(err)
}
ids := func(es []Entry) []string {
var out []string
for _, e := range es {
out = append(out, e.ID)
}
slices.Sort(out)
return out
}
if got, want := ids(Catalog()), []string{"a/m2", "a/m3", "group/g", "group/inner"}; !slices.Equal(got, want) {
t.Fatalf("Catalog %v, want %v", got, want)
}
if shown, _ := CatalogFor("opencode"); !slices.Equal(ids(shown), []string{"a/m2", "a/m3", "group/g", "group/inner"}) {
t.Fatalf("an agent's list: %v", ids(shown))
}
if got, want := ids(Unlisted()), []string{"a/m1", "b/n1", "b/n2"}; !slices.Equal(got, want) {
t.Fatalf("Unlisted %v, want %v", got, want)
}
if got := ids(Served()); !slices.Contains(got, "a/m1") || !slices.Contains(got, "b/n2") {
t.Fatalf("served: %v", got)
}
if _, ms, ok := FindGroup("group/g"); !ok || len(ms) != 4 {
t.Fatalf("the group's members: %v %v", ms, ok)
}
if g, _, _ := FindGroup("group/g"); !g.Unlists {
t.Fatal("Unlists not kept by the save")
}
// switched off, its models are listed again
if err := SwitchGroup("g", false); err != nil {
t.Fatal(err)
}
if got := ids(Catalog()); !slices.Contains(got, "a/m1") || !slices.Contains(got, "b/n1") {
t.Fatalf("with the group off: %v", got)
}
if err := SwitchGroup("g", true); err != nil {
t.Fatal(err)
}
// listed again by the user
g, _, _ := FindGroup("group/g")
g.Unlists = false
if err := SaveGroup(g); err != nil {
t.Fatal(err)
}
if got := ids(Catalog()); len(got) != 7 || len(Unlisted()) != 0 {
t.Fatalf("listed again: %v, unlisted %v", got, ids(Unlisted()))
}
}
+33 -5
View File
@@ -1352,14 +1352,40 @@ type Entry struct {
func Catalog() []Entry {
entries := providerEntries()
out := groupEntries(entries)
kept := unlistedByGroups(entries)
for _, e := range entries {
if !e.Provider.Unlisted {
if !e.Provider.Unlisted && !kept[e.ID] {
out = append(out, e)
}
}
return out
}
// unlistedByGroups are the models, by "provider/model", that a group
// keeps out of the lists (Group.Unlists): those it names, a member fixed
// at an effort counting as its model, and those its patterns match.
func unlistedByGroups(entries []Entry) map[string]bool {
if !slices.ContainsFunc(heldOf("file", load).Groups, func(g Group) bool { return g.Unlists }) {
return nil
}
out := map[string]bool{}
for _, g := range groupsIn(entries) {
if !g.Unlists || g.Hidden || g.Disabled {
continue
}
for _, id := range g.Members {
if strings.HasPrefix(id, GroupPrefix) {
continue
}
model, _ := memberEffortIn(entries, id)
if p, m, ok := resolveIn(entries, model); ok {
out[p.ID+"/"+m] = true
}
}
}
return out
}
// Served is the catalog with the unlisted providers' models as well: every
// model a routing group can be made of, or a request can name.
func Served() []Entry {
@@ -1368,12 +1394,14 @@ func Served() []Entry {
}
// Unlisted are the models Served has and Catalog doesn't: those of the
// providers kept for routing groups (Provider.Unlisted), which agents
// aren't offered.
// providers kept for routing groups (Provider.Unlisted), and those a group
// keeps out of the lists (Group.Unlists), which agents aren't offered.
func Unlisted() []Entry {
var out []Entry
for _, e := range providerEntries() {
if e.Provider.Unlisted {
entries := providerEntries()
kept := unlistedByGroups(entries)
for _, e := range entries {
if e.Provider.Unlisted || kept[e.ID] {
out = append(out, e)
}
}
+25
View File
@@ -41,3 +41,28 @@ func TestMemberOptionsDecisionGroup(t *testing.T) {
t.Fatalf("a new group offered %v", got)
}
}
// The member picker offers the models kept out of the lists agents see:
// a provider's kept for routing groups and a group's with listed=no
// (#1783), as the Routing view's does. They are what groups are made of.
func TestMemberOptionsOfferUnlistedModels(t *testing.T) {
home(t)
for _, p := range []provider.Provider{
{ID: "ua", Name: "UA", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m1"}},
{ID: "ub", Name: "UB", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"n1"}, Unlisted: true},
} {
if err := provider.Save(p); err != nil {
t.Fatal(err)
}
}
if err := provider.SaveGroup(provider.Group{ID: "g", Name: "G", Members: []string{"ua/m1"}, Unlists: true}); err != nil {
t.Fatal(err)
}
var got []string
for _, o := range memberOptions(nil, "other") {
got = append(got, o.Value)
}
if !slices.Contains(got, "ua/m1") || !slices.Contains(got, "ub/n1") || !slices.Contains(got, "group/g") {
t.Fatalf("offered %v", got)
}
}
+4 -1
View File
@@ -193,7 +193,10 @@ func memberOptions(skip []string, self string) []agent.Option {
g, _ := findGroup(self)
decides := self != "" && g.Decides()
if !decides {
for _, e := range provider.Catalog() {
// every model a group can be made of: those kept out of the lists
// agents see too (a provider kept for routing groups, a group's
// with listed=no, #1783), as the Routing view's picker offers
for _, e := range provider.Served() {
if slices.Contains(skip, e.ID) || e.ID == provider.GroupPrefix+self {
continue
}