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).
80 lines
2.7 KiB
Go
80 lines
2.7 KiB
Go
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()))
|
|
}
|
|
}
|