routing: a found group's card leaves out a provider switched off, and counts it (XYenon)
XYenon on Discord (#feedback, 10-30): "已经关闭的提供商还会显示在路由页的 自动成组里是不是不太对". A provider switched off stays a member of the groups magpie found (#2671, on purpose: agents on auto-<model> aren't moved while it is off), and the gateway already skips it (membersIn reads only providers that are on; TestFoundGroupWithAProviderOff covers chat, and a fallback group, affinity and a group's classifier (decide_group.go) go through the same FindGroup). So no request reached it. What was wrong was the page: the card still listed it as "B · model (switched off)" and its logo sat in the group's icon stack, where every other model list leaves a provider switched off out. - Routing page (plugins/routing/client.js): a found group's card, its remove-picker row and its logos (groupIcons, also used by the group pickers) leave out members whose provider is switched off; a tag "{n} switched off" says how many, its title why (offWords). When none would be left they are listed as before. The editor and a manual group's pick still show them, greyed with why. A group of the user's is unchanged: it lists what they put in. - i18n: "{n} switched off" in zh, zh-TW, ja, de. - TUI (sibling): the routing list's line for a found group does the same ("N models · ... · 1 switched off"), and a group's page marks such a member "· switched off: skipped until it is on again" (any group). - docs/subsystems/providers-accounts.md: the row says it. Tests: routing-provider-off.test.cjs gains a found group (card text, tag text and title, no logo of the provider off, editor still has it) and one whose only member is off (listed as before, no tag); every language, 1100 and 420 wide, Chromium and WebKit. TestFoundGroupLineLeavesASwitchedOffProviderOut (internal/tui). Run on mote (mote-run, this tree): node --test of 45 GUI files (group-*, panel-routing*, routing-group*, routing-groups*, routing-provider-off, i18n-keys, found-*, remove-found*): 488/488 pass. go test ./internal/tui ok; go test ./internal/gui: all ok except TestMainWindowCorners/macOS_26_SDK, red on macOS 27 and already filed (#3949), an AppKit window test this change doesn't reach. gofmt -l clean; go vet ./internal/tui for darwin, linux (-tags nogui), windows ok. Broken by hand: with client.js from HEAD the new GUI case is red (expected 'A Cloud · luna', actual 'A Cloud · luna → B Cloud · luna (switched off)'); with listedMembers returning every member the TUI test is red ("2 models · ... pa/luna → pb/luna"). Not tried: the real app with a real provider switched off; the full GUI suite (1002 files) and the full go test ./... were not run.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -5016,7 +5016,15 @@ function routingPage(part) {
|
||||
renderGroups();
|
||||
return true;
|
||||
};
|
||||
const groupIcons = (g) => [...new Map((g.memberInfo || []).filter((i) => i.icon).map((i) => [i.provider || i.icon, i.icon])).values()];
|
||||
// offIn: the members of a group magpie found whose provider is switched
|
||||
// off (XYenon on Discord). magpie keeps them in the group so agents on it
|
||||
// aren't moved while one is off (#2671), but the gateway skips them, so a
|
||||
// found group's card and logos leave them out, as every model list leaves
|
||||
// a provider switched off out, and say how many in a tag; the editor still
|
||||
// has them, greyed with why. A group of the user's lists what they put in.
|
||||
const offIn = (g) => g.auto ? (g.memberInfo || []).filter((i) => i.providerOff && g.members.includes(i.id)) : [];
|
||||
const shownMembers = (g) => { const off = offIn(g).map((i) => i.id); const left = g.members.filter((id) => !off.includes(id)); return left.length ? left : g.members; };
|
||||
const groupIcons = (g) => { const shown = shownMembers(g); return [...new Map((g.memberInfo || []).filter((i) => i.icon && shown.includes(i.id)).map((i) => [i.provider || i.icon, i.icon])).values()]; };
|
||||
// offOf: a member whose provider is switched off (groupsState's
|
||||
// providerOff), said by its provider's name and model rather than a bare
|
||||
// id: the group skips it until the provider is on again
|
||||
@@ -5491,7 +5499,7 @@ function routingPage(part) {
|
||||
const main = el("div", "main"), nm = el("div", "nm");
|
||||
nm.append(el("b", "", g.name), el("code", "mdl", g.ref || "group/" + g.id));
|
||||
if (g.auto) nm.append(el("small", "auto", t("found by magpie")));
|
||||
main.append(nm, el("div", "mem", g.members.map((id) => memberLabel(g, id)).join(g.routing === "order" ? " → " : " · ")));
|
||||
main.append(nm, el("div", "mem", shownMembers(g).map((id) => memberLabel(g, id)).join(g.routing === "order" ? " → " : " · ")));
|
||||
row.append(cb, ics, main);
|
||||
return row;
|
||||
}
|
||||
@@ -5549,7 +5557,7 @@ function routingPage(part) {
|
||||
if (g.auto) nm.append(el("small", "auto", t("found by magpie")));
|
||||
const manual = g.routing === "manual";
|
||||
const sep = g.routing === "order" ? " → " : " · ";
|
||||
const mem = manual ? pickRow(g) : el("div", "mem", g.members.map((id) => memberLabel(g, id) + (g.off?.includes(id) ? ` (${t("off")})` : "")).join(sep));
|
||||
const mem = manual ? pickRow(g) : el("div", "mem", shownMembers(g).map((id) => memberLabel(g, id) + (g.off?.includes(id) ? ` (${t("off")})` : "")).join(sep));
|
||||
main.append(nm, mem);
|
||||
for (const p of g.patterns || []) {
|
||||
const line = el("div", "mem pat" + (p.models ? "" : " none"));
|
||||
@@ -5587,6 +5595,12 @@ function routingPage(part) {
|
||||
r.title = (manual ? t("The rules wait while you pick the model by hand.") + "\n" : "") + g.rules.map((x, i) => `${i + 1}. ${ruleText(x)} → ${x.pause ? t("pause") + " " : ""}${rUses(x).map((u) => memberLabel(g, u)).join(", ")}${x.useEffort ? " · " + t("{level} reasoning", { level: x.useEffort }) : ""}`).join("\n");
|
||||
tags.append(r);
|
||||
}
|
||||
const offs = manual ? [] : offIn(g);
|
||||
if (offs.length && shownMembers(g).length < g.members.length) {
|
||||
const k = el("span", "tag idle rt-goff", t("{n} switched off", { n: offs.length }));
|
||||
k.title = offs.map(offWords).join("\n");
|
||||
tags.append(k);
|
||||
}
|
||||
if (g.disabled) tags.append(el("span", "tag idle", t("switched off")));
|
||||
else if (!g.ready) tags.append(el("span", "tag bad", t("no member ready")));
|
||||
const edit = el("button", "text", t("Edit"));
|
||||
|
||||
@@ -34,6 +34,7 @@ magpie.strings({
|
||||
"“· routing group” is set for every group above": "是否带「· routing group」在上方统一设置,对所有路由组生效",
|
||||
"{agent} guessed your next message for its composer by itself, reading the whole conversation again. Not a turn of the conversation; Codex composer predictions, under Settings in Codex's row on the Agents page, picks its model, and Codex's Settings › General › Show predictions turns it off.": "{agent} 自行为输入框猜测你的下一条消息,每次都把整段对话重读一遍。不属于对话轮次;在 Agent 页 Codex 那一行的设置里,用 Codex 输入框预测 选它用的模型,在 Codex 的 设置 › 常规 › 显示预测内容 里可以关掉。",
|
||||
"{name} is switched off: the group skips it until it is on again": "{name} 已关闭:开启前这个组会跳过它",
|
||||
"{n} switched off": "{n} 个已关闭",
|
||||
"Off: agents aren't offered {name} and a request to it is turned away. Click to switch it on": "已关闭:Agent 列表里没有 {name},发给它的请求会被拒绝。点击打开",
|
||||
"On: agents may pick {name}. Click to switch it off and keep it as it is": "已打开:Agent 可以选用 {name}。点击暂时关闭,组的设置原样保留",
|
||||
"{name} switched on": "已打开 {name}",
|
||||
@@ -636,6 +637,7 @@ magpie.strings({
|
||||
"Whether “· routing group” follows a group’s name in the agents’ lists: one setting for every group, and for the provider after each model’s name, as on Settings.": "Agent 的模型列表裡,路由組名後面是否帶「· routing group」。這是所有路由組共用的一個設定,也決定模型名後面是否帶供應商,和「設定」裡的是同一個。",
|
||||
"“· routing group” is set for every group above": "是否帶「· routing group」在上方統一設定,對所有路由組生效",
|
||||
"{name} is switched off: the group skips it until it is on again": "{name} 已關閉:開啟前這個組會跳過它",
|
||||
"{n} switched off": "{n} 個已關閉",
|
||||
"Off: agents aren't offered {name} and a request to it is turned away. Click to switch it on": "已關閉:Agent 列表裡沒有 {name},發給它的請求會被拒絕。點選開啟",
|
||||
"On: agents may pick {name}. Click to switch it off and keep it as it is": "已開啟:Agent 可以選用 {name}。點選暫時關閉,組的設定原樣保留",
|
||||
"{name} switched on": "已開啟 {name}",
|
||||
@@ -1216,6 +1218,7 @@ magpie.strings({
|
||||
"“· routing group” is set for every group above": "「· routing group」を付けるかは上で全グループ共通に設定します",
|
||||
"{agent} guessed your next message for its composer by itself, reading the whole conversation again. Not a turn of the conversation; Codex composer predictions, under Settings in Codex's row on the Agents page, picks its model, and Codex's Settings › General › Show predictions turns it off.": "{agent} が入力欄に表示する次のメッセージの予測を自分で行い、そのたびに会話全体を読み直しました。会話のターンではありません。エージェントページの Codex の行にある設定の Codex の入力予測 でモデルを選べ、Codex の 設定 › 一般 › 予測候補を表示 でオフにできます。",
|
||||
"{name} is switched off: the group skips it until it is on again": "{name} はオフです。オンに戻すまでグループはスキップします",
|
||||
"{n} switched off": "{n} 件オフ",
|
||||
"Off: agents aren't offered {name} and a request to it is turned away. Click to switch it on": "オフ:{name} はエージェントに表示されず、届いたリクエストは断られます。クリックでオン",
|
||||
"On: agents may pick {name}. Click to switch it off and keep it as it is": "オン:エージェントは {name} を選べます。クリックで一時的にオフ(設定はそのまま)",
|
||||
"{name} switched on": "{name} をオンにしました",
|
||||
@@ -1808,6 +1811,7 @@ magpie.strings({
|
||||
"“· routing group” is set for every group above": "„· routing group“ wird oben für alle Gruppen eingestellt",
|
||||
"{agent} guessed your next message for its composer by itself, reading the whole conversation again. Not a turn of the conversation; Codex composer predictions, under Settings in Codex's row on the Agents page, picks its model, and Codex's Settings › General › Show predictions turns it off.": "{agent} hat deine nächste Nachricht für sein Eingabefeld selbst vorhergesagt und dafür das ganze Gespräch erneut gelesen. Kein Zug des Gesprächs; das Modell wählst du mit Codex-Eingabevorhersagen unter Einstellungen in der Zeile von Codex auf der Seite Agenten, und in Codex unter Einstellungen › Allgemein › Textvorschläge anzeigen schaltest du es ab.",
|
||||
"{name} is switched off: the group skips it until it is on again": "{name} ist ausgeschaltet: Die Gruppe überspringt es, bis es wieder eingeschaltet ist",
|
||||
"{n} switched off": "{n} ausgeschaltet",
|
||||
"Off: agents aren't offered {name} and a request to it is turned away. Click to switch it on": "Aus: Agents wird {name} nicht angeboten, eine Anfrage daran wird abgewiesen. Klicken zum Einschalten",
|
||||
"On: agents may pick {name}. Click to switch it off and keep it as it is": "An: Agents können {name} wählen. Klicken zum Ausschalten – die Gruppe bleibt, wie sie ist",
|
||||
"{name} switched on": "{name} eingeschaltet",
|
||||
|
||||
@@ -14,7 +14,7 @@ const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const models = [{ id: "a/sol", name: "sol", providerName: "A Cloud", icon: "generic" }];
|
||||
const models = [{ id: "a/sol", name: "sol", providerName: "A Cloud", icon: "generic" }, { id: "a/luna", name: "luna", providerName: "A Cloud", icon: "openai" }];
|
||||
const info = [
|
||||
{ id: "a/sol", ready: true, provider: "a", name: "A Cloud", model: "sol", on: 1 },
|
||||
{ id: "b/sol", ready: false, providerOff: true, provider: "b", name: "B Cloud", icon: "generic", model: "sol", on: 0 },
|
||||
@@ -24,6 +24,15 @@ const base = { members: ["a/sol", "b/sol", "c/sol"], ready: true, memberInfo: in
|
||||
const groups = { models, pools: [], groups: [
|
||||
{ ...base, id: "auto-sol", name: "Sol", routing: "order" },
|
||||
{ ...base, id: "hand", name: "Hand", routing: "manual", pick: "a/sol", picked: "a/sol" },
|
||||
// one magpie found (XYenon on Discord): its card leaves the member out
|
||||
{ id: "auto-luna", name: "Luna", auto: true, routing: "order", ready: true, offers: [], shared: [],
|
||||
members: ["a/luna", "b/luna"], memberInfo: [
|
||||
{ id: "a/luna", ready: true, provider: "a", name: "A Cloud", icon: "openai", model: "luna", on: 1 },
|
||||
{ id: "b/luna", ready: false, providerOff: true, provider: "b", name: "B Cloud", icon: "anthropic", model: "luna", on: 0 },
|
||||
] },
|
||||
// every member's provider off: nothing left to show, so they are said
|
||||
{ id: "auto-terra", name: "Terra", auto: true, routing: "order", ready: false, offers: [], shared: [],
|
||||
members: ["b/terra"], memberInfo: [{ id: "b/terra", ready: false, providerOff: true, provider: "b", name: "B Cloud", icon: "anthropic", model: "terra", on: 0 }] },
|
||||
] };
|
||||
|
||||
function serve(lang) {
|
||||
@@ -80,6 +89,27 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.equal(await pick.evaluate((b) => b.classList.contains("off")), true);
|
||||
assert.equal(await hand.locator('.rt-pick[data-member="c/sol"]').getAttribute("title"), await say("No provider serves {id} now; it is skipped", { id: "c/sol" }));
|
||||
|
||||
// a group magpie found lists only the members it can send to, and
|
||||
// its logos are theirs: the switched-off one is counted in a tag
|
||||
// that says why when hovered
|
||||
const found = page.locator(".rt-group", { hasText: "Luna" }).first();
|
||||
assert.equal(await found.locator(".mem").first().textContent(), "A Cloud · luna");
|
||||
const tag = found.locator(".tag.rt-goff");
|
||||
assert.equal(await tag.textContent(), await say("{n} switched off", { n: 1 }));
|
||||
if (lang !== "en") assert.notEqual(await tag.textContent(), "1 switched off", `${lang} has it in its own words`);
|
||||
assert.equal(await tag.getAttribute("title"), why);
|
||||
const logos = await found.locator(".rt-ghandle").innerHTML();
|
||||
assert.ok(!logos.includes("anthropic"), "no logo of the provider switched off: " + logos);
|
||||
const terra = page.locator(".rt-group", { hasText: "Terra" }).first();
|
||||
assert.equal(await terra.locator(".mem").first().textContent(), `B Cloud · terra (${off})`);
|
||||
assert.equal(await terra.locator(".tag.rt-goff").count(), 0);
|
||||
// its editor still has the member, greyed with why
|
||||
await found.locator("button", { hasText: await say("Edit") }).dispatchEvent("click");
|
||||
const fed = page.locator(".rt-gedit");
|
||||
assert.equal(await fed.locator(".fbrow", { has: page.locator(".n small", { hasText: `B Cloud · ${off}` }) }).count(), 1);
|
||||
await fed.locator("button", { hasText: await say("Cancel") }).first().dispatchEvent("click");
|
||||
await fed.waitFor({ state: "detached" });
|
||||
|
||||
// the editor: its row muted, saying why
|
||||
// the page puts back a scroll the reader didn't make, so at 420 the
|
||||
// button is clicked where it is
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// A group magpie found keeps a member whose provider is switched off
|
||||
// (#2671), but its line on the routing page lists only those the gateway
|
||||
// can send to, and says how many are off (XYenon on Discord: a provider
|
||||
// switched off was still listed in the found group). A group of the user's
|
||||
// lists what they put in; the group's own page marks the member off.
|
||||
func TestFoundGroupLineLeavesASwitchedOffProviderOut(t *testing.T) {
|
||||
home(t)
|
||||
for _, p := range []provider.Provider{
|
||||
{ID: "pa", Name: "PA", Key: "k", Models: []string{"luna"}, Chat: "http://127.0.0.1:1/v1"},
|
||||
{ID: "pb", Name: "PB", Key: "k", Models: []string{"luna"}, Chat: "http://127.0.0.1:1/v1"},
|
||||
} {
|
||||
if err := provider.Save(p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := provider.SaveGroup(provider.Group{ID: "mine", Name: "Mine", Members: []string{"pa/luna", "pb/luna"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := provider.SetOff("pb", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m := press(t, model{w: 160, h: 40}, "3")
|
||||
line := func(name string) string {
|
||||
t.Helper()
|
||||
for _, l := range strings.Split(m.View(), "\n") {
|
||||
if strings.Contains(l, name) {
|
||||
return l
|
||||
}
|
||||
}
|
||||
t.Fatalf("no %s line:\n%s", name, m.View())
|
||||
return ""
|
||||
}
|
||||
if l := line("auto/luna"); strings.Contains(l, "pb/luna") || !strings.Contains(l, "pa/luna") || !strings.Contains(l, "1 model ") || !strings.Contains(l, "1 switched off") {
|
||||
t.Fatalf("found group's line: %q", l)
|
||||
}
|
||||
if l := line("group/mine"); !strings.Contains(l, "pa/luna → pb/luna") || strings.Contains(l, "switched off") {
|
||||
t.Fatalf("the user's group's line: %q", l)
|
||||
}
|
||||
m.gid, m.mode = "auto-luna", modeGroup
|
||||
v := m.View()
|
||||
if !strings.Contains(v, "pb/luna · switched off") || strings.Contains(v, "pa/luna · switched off") {
|
||||
t.Fatalf("the found group's page:\n%s", v)
|
||||
}
|
||||
// on again: listed as before
|
||||
if err := provider.SetOff("pb", false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m = press(t, model{w: 160, h: 40}, "3")
|
||||
if l := line("auto/luna"); !strings.Contains(l, "pa/luna → pb/luna") || strings.Contains(l, "switched off") {
|
||||
t.Fatalf("pb on again: %q", l)
|
||||
}
|
||||
}
|
||||
+43
-2
@@ -32,6 +32,40 @@ func (m *model) reloadGroups() {
|
||||
m.shown = len(m.groups)
|
||||
m.groups = append(m.groups, removed...)
|
||||
m.grow = clamp(m.grow, len(m.groups))
|
||||
m.provOff = map[string]bool{}
|
||||
for _, p := range provider.All() {
|
||||
if !p.On() {
|
||||
m.provOff[p.ID] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// memberOff is whether a member of a group is a model of a provider
|
||||
// switched off: the group keeps it (one magpie found too, #2671) and the
|
||||
// gateway skips it until the provider is on again.
|
||||
func (m model) memberOff(id string) bool {
|
||||
if provider.IsGroupRef(id) {
|
||||
return false
|
||||
}
|
||||
pid, _, ok := strings.Cut(id, "/")
|
||||
return ok && m.provOff[pid]
|
||||
}
|
||||
|
||||
// listedMembers are the members a group's line lists: of a group magpie
|
||||
// found, those its providers being on lets it send to (XYenon on Discord:
|
||||
// a provider switched off was still listed in it), as every model list
|
||||
// leaves a provider switched off out, and how many it left out; all of
|
||||
// them when that would leave none. A group of the user's lists what they
|
||||
// put in.
|
||||
func (m model) listedMembers(g provider.Group) ([]string, int) {
|
||||
if !g.Auto {
|
||||
return g.Members, 0
|
||||
}
|
||||
on := slices.DeleteFunc(slices.Clone(g.Members), m.memberOff)
|
||||
if len(on) == 0 {
|
||||
return g.Members, 0
|
||||
}
|
||||
return on, len(g.Members) - len(on)
|
||||
}
|
||||
|
||||
var routings = []string{"", provider.Ordered, provider.Rotate, provider.LeastUsed, provider.Pace, provider.Weighted, provider.FreeFirst, provider.Fastest, provider.Manual}
|
||||
@@ -593,7 +627,11 @@ func (m model) viewGroups() string {
|
||||
b.WriteString(line + "\n")
|
||||
continue
|
||||
}
|
||||
notes := []string{fmt.Sprintf("%d model%s", len(g.Members), plural(len(g.Members))), groupRouting(g)}
|
||||
listed, off := m.listedMembers(g)
|
||||
notes := []string{fmt.Sprintf("%d model%s", len(listed), plural(len(listed))), groupRouting(g)}
|
||||
if off > 0 {
|
||||
notes = append(notes, fmt.Sprintf("%d switched off", off))
|
||||
}
|
||||
if g.Affinity != "" {
|
||||
notes = append(notes, staysName(g.Affinity))
|
||||
}
|
||||
@@ -606,7 +644,7 @@ func (m model) viewGroups() string {
|
||||
if g.Auto {
|
||||
notes = append(notes, "found")
|
||||
}
|
||||
members := strings.Join(g.Members, " → ")
|
||||
members := strings.Join(listed, " → ")
|
||||
if len(g.Match) > 0 {
|
||||
notes = append(notes, fmt.Sprintf("%d pattern%s", len(g.Match), plural(len(g.Match))))
|
||||
}
|
||||
@@ -653,6 +691,9 @@ func (m model) viewGroup() string {
|
||||
if slices.Contains(g.Matched, id) {
|
||||
name += sMuted.Render(" · by pattern")
|
||||
}
|
||||
if m.memberOff(id) {
|
||||
name += sMuted.Render(" · switched off: skipped until it is on again")
|
||||
}
|
||||
b.WriteString(pad + marker + sFaint.Render(fmt.Sprintf("%d ", i+1)) + name + "\n")
|
||||
}
|
||||
// patterns find models in the catalog each time (#766): how many now,
|
||||
|
||||
@@ -117,6 +117,7 @@ type model struct {
|
||||
bal map[string]string
|
||||
asked bool // balances were asked for
|
||||
groups []provider.Group
|
||||
provOff map[string]bool // providers switched off, read with the groups
|
||||
grow int
|
||||
shown int // groups from here on were removed: listed last, to bring back
|
||||
gid string // the group open
|
||||
|
||||
Reference in New Issue
Block a user