images: a routing group can be Settings > Images' image model (7up6666 on X)

Settings > Images > Image generation now offers each routing group with
a member that draws (gateway.GroupDraws: a member among its provider's
Drawers), with no provider of its own, so the picker puts it under
Routing groups as the Image recognition picker does. Picked, "group/<id>"
is what a request naming no model draws with, the Magpie Image MCP's
included: the gateway already drew on a group member by member in its
routing's order (drawingGroup, #2005), it was only never offered.

A picked group none of whose members draws any more (all removed, or a
group of chat models) is DrawerMissing (drawerMissing): the row says the
pick is missing and Automatic draws in its place, as for a removed model.
Before, a group of chat models would have been sent the drawing.
ListedDrawer and DrawerHidden leave a group ref as it is.

Run:
- mote, at this change on e84f40369: gofmt -l, go vet ./...,
  GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., the
  Linux and Windows builds: ok. go test -count=1 -run
  "Draw|Drawer|Image|Budget|HiddenDrawers|Account|Aside" over
  internal/provider, gateway, gui and agent: all four ok (the new tests,
  TestImageGroupMovesOnToTheNextMember and the size budgets among them).
- wsl-run, Chromium and WebKit: the seven image GUI files and
  i18n-keys, 182 of 182.
- Rebased again onto 4d9058a98 (which changed app.js, api.go and
  i18n.js, "Picked only" among them) and run there: go vet
  ./internal/gui and go test -run "Budget|Image|Drawer" ./internal/gui
  ok; wsl-run, both engines: image-models-hide,
  provider-picked-only-shows-picks, images-missing and i18n-keys, 90 of 90.
  Pushed on 0366e35c1, which changes only internal/catalog after it.

New tests: TestImageGroupPickedInSettingsDraws (gateway: the group
pick draws with no model named, over HTTP and through the Magpie Image
MCP, moving past a member's 502; a chat-only group and one whose drawers
are gone are missing), TestImageGenOffersDrawingGroups (gui).

Broken by hand:
- drawerMissing without the GroupDraws check: the gateway test is red
  ("chat-only group: drawer \"group/talkers\" missing \"\"").
- api.go without the group loop: the gui test is red (group not offered).

Not tried: a real group of real image accounts; a GUI test (app.js is
unchanged: its picker already files an entry with no provider under
Routing groups); the real Linux app.
This commit is contained in:
yetone
2026-10-29 15:50:37 +08:00
parent ded4935745
commit d9cf85ae8b
5 changed files with 209 additions and 3 deletions
File diff suppressed because one or more lines are too long
+39 -2
View File
@@ -90,7 +90,7 @@ func drawer() (string, bool) {
return "", false
case "":
default:
if pickedMissing(v) == "" {
if drawerMissing(v) == "" {
return v, true
}
}
@@ -109,7 +109,44 @@ func Drawer() string {
// when magpie can't find it any more, so that AutoDrawer's draws in its
// place, as VisionMissing is Image recognition's. "" when none is named,
// it is off, or it resolves.
func DrawerMissing() string { return pickedMissing(settings.Load().ImageGen) }
func DrawerMissing() string { return drawerMissing(settings.Load().ImageGen) }
// drawerMissing is v, an Image generation pick, when magpie can't draw
// with it: pickedMissing's, and a routing group ("group/<id>", 7up6666 on
// X) none of whose members draws any more.
func drawerMissing(v string) string {
if m := pickedMissing(v); m != "" || !provider.IsGroupRef(v) {
return m
}
if !GroupDraws(v) {
return v
}
return ""
}
// GroupDraws is whether the routing group ref ("group/<id>") has a member
// that draws: a model among its provider's Drawers. Such a group may be
// picked in Settings › Images, and draws on those members in its routing's
// order, moving on while one fails (drawingGroup, #2005).
func GroupDraws(ref string) bool {
_, ms, ok := provider.FindGroup(ref)
if !ok {
return false
}
for _, m := range ms {
if drawsModel(m.Provider, m.Model) {
return true
}
}
return false
}
// drawsModel is whether model is one of p's Drawers, a ChatGPT account's
// other GPT Image names as its one (ListedDrawer).
func drawsModel(p provider.Provider, model string) bool {
_, id, _ := strings.Cut(ListedDrawer(p.ID+"/"+model), "/")
return slices.ContainsFunc(Drawers(p), func(m catalog.Model) bool { return m.ID == id })
}
func resolveDrawing(id string) (provider.Provider, string, bool) {
if strings.Contains(id, "/") {
+98
View File
@@ -0,0 +1,98 @@
package gateway
import (
"io"
"net/http"
"net/http/httptest"
"strings"
"sync/atomic"
"testing"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
)
// 7up6666 on X: a routing group of image models, picked in Settings ›
// Images, is what a request naming no model draws with, the Magpie Image
// MCP's included: on its members in its routing's order, the next asked
// while one fails. A group with no member that draws is no pick (it shows
// as missing, and Automatic draws in its place), nor is one whose members
// are all gone.
func TestImageGroupPickedInSettingsDraws(t *testing.T) {
s, e := easeled(t)
t.Setenv("MAGPIE_PUBLIC_URL", "")
t.Cleanup(s.imageStore.running.Wait)
var brokeAsked atomic.Int32
broke := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
brokeAsked.Add(1)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(502)
io.WriteString(w, `{"error":{"message":"upstream error: bad gateway","type":"upstream_error"}}`)
}))
t.Cleanup(broke.Close)
if err := provider.Save(provider.Provider{ID: "flare-a", Name: "Flare A", Chat: broke.URL + "/v1", Key: "ka", Models: []string{"gpt-image-2.5-flare"}}); err != nil {
t.Fatal(err)
}
art, _ := provider.Find("art")
art.Models = append(art.Models, "gpt-image-2.5-flare")
if err := provider.Save(*art); err != nil {
t.Fatal(err)
}
for _, g := range []provider.Group{
{ID: "painters", Name: "Painters", Members: []string{"flare-a/gpt-image-2.5-flare", "art/gpt-image-2.5-flare"}, Routing: "order"},
{ID: "talkers", Name: "Talkers", Members: []string{"art/text"}},
} {
if err := provider.SaveGroup(g); err != nil {
t.Fatal(err)
}
}
if !GroupDraws("group/painters") || GroupDraws("group/talkers") || GroupDraws("group/nope") {
t.Fatal("GroupDraws")
}
if ListedDrawer("group/painters") != "group/painters" || DrawerHidden("group/painters") {
t.Fatal("a group pick is listed as it is, and never hidden")
}
pick := func(v string) {
t.Helper()
st := settings.Load()
st.ImageGen = v
if err := settings.Save(st); err != nil {
t.Fatal(err)
}
}
pick("group/painters")
if Drawer() != "group/painters" || DrawerMissing() != "" {
t.Fatalf("the group pick isn't what draws: %q missing %q", Drawer(), DrawerMissing())
}
code, a, raw := postImages(t, s, "/v1/images/generations", "application/json", `{"prompt":"a magpie"}`)
if code != 200 || len(a.Data) != 1 || a.Model != "art/gpt-image-2.5-flare" || brokeAsked.Load() == 0 {
t.Fatalf("drawn with no model named: %d %s (first member asked %d)", code, raw, brokeAsked.Load())
}
// the MCP draws with the pick too
h := lanGuard(s.Handler())
before := len(e.got("/v1/images/generations"))
m := readImageReply(t, imagePost(h, "127.0.0.1:5000", imageToolCall(GenerateImageTool, map[string]any{"prompt": "a magpie"})))
if m.Result.IsError || len(e.got("/v1/images/generations")) != before+1 || !strings.Contains(m.Result.Content[0].Text, "art/gpt-image-2.5-flare") {
t.Fatalf("MCP: %+v", m)
}
// a group that draws nothing is said missing, and Automatic draws
pick("group/talkers")
if DrawerMissing() != "group/talkers" || Drawer() == "group/talkers" || Drawer() == "" {
t.Fatalf("chat-only group: drawer %q missing %q", Drawer(), DrawerMissing())
}
// as is one whose drawing members are all gone
pick("group/painters")
if err := provider.Delete("flare-a"); err != nil {
t.Fatal(err)
}
art, _ = provider.Find("art")
art.Models = []string{"text"}
if err := provider.Save(*art); err != nil {
t.Fatal(err)
}
if DrawerMissing() != "group/painters" || Drawer() == "group/painters" {
t.Fatalf("group with no drawers left: drawer %q missing %q", Drawer(), DrawerMissing())
}
}
+7
View File
@@ -738,6 +738,13 @@ func settingsState() settingsJSON {
s.ImageGenModels = append(s.ImageGenModels, modelRef{ID: p.ID + "/" + m.ID, Name: name, Provider: p.ID, PName: p.Name, Icon: p.Icon, VendorPicks: gateway.VendorPicksDrawer(p)})
}
}
// the routing groups with a member that draws (7up6666 on X): a
// group picked here draws on its members in its routing's order
for _, e := range provider.Served() {
if e.Group != "" && gateway.GroupDraws(e.ID) {
s.ImageGenModels = append(s.ImageGenModels, modelRef{ID: e.ID, Name: e.Name, PName: e.Group})
}
}
if v := gateway.ListedDrawer(s.ImageGen); v != s.ImageGen {
s.ImageGenShown = v
}
+64
View File
@@ -0,0 +1,64 @@
package gui
import (
"os"
"testing"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
)
// 7up6666 on X: Settings › Images offers each routing group with a member
// that draws, under the group's name with no provider of its own (the
// picker puts it with Routing groups); a group of chat models only isn't
// offered, and a picked group none of whose members draws is said missing.
func TestImageGenOffersDrawingGroups(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("USERPROFILE", os.Getenv("HOME"))
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
t.Setenv("XDG_CACHE_HOME", t.TempDir())
if err := provider.Save(provider.Provider{ID: "pics", Name: "Pics", Chat: "https://pics.example/v1", Key: "sk-p", Models: []string{"text", "gpt-image-1"}}); err != nil {
t.Fatal(err)
}
for _, g := range []provider.Group{
{ID: "painters", Name: "Painters", Members: []string{"pics/gpt-image-1"}},
{ID: "talkers", Name: "Talkers", Members: []string{"pics/text"}},
} {
if err := provider.SaveGroup(g); err != nil {
t.Fatal(err)
}
}
find := func(id string) (modelRef, bool) {
for _, m := range settingsState().ImageGenModels {
if m.ID == id {
return m, true
}
}
return modelRef{}, false
}
m, ok := find("group/painters")
if !ok || m.Provider != "" || m.Name != "Painters" {
t.Fatalf("drawing group offered as %+v %v", m, ok)
}
if _, ok := find("group/talkers"); ok {
t.Fatal("a chat-only group is offered to draw with")
}
if _, ok := find("pics/gpt-image-1"); !ok {
t.Fatal("the provider's own image model left the list")
}
st := settings.Load()
st.ImageGen = "group/talkers"
if err := settings.Save(st); err != nil {
t.Fatal(err)
}
if s := settingsState(); s.ImageGenMissing != "group/talkers" {
t.Fatalf("a picked group that draws nothing isn't said missing: %q", s.ImageGenMissing)
}
st.ImageGen = "group/painters"
if err := settings.Save(st); err != nil {
t.Fatal(err)
}
if s := settingsState(); s.ImageGenMissing != "" || s.ImageGenHidden {
t.Fatalf("a drawing group pick: missing %q hidden %v", s.ImageGenMissing, s.ImageGenHidden)
}
}