diff --git a/internal/gateway/draw.go b/internal/gateway/draw.go index 9fe0b1a69..2508f675b 100644 --- a/internal/gateway/draw.go +++ b/internal/gateway/draw.go @@ -266,7 +266,13 @@ func drawsCodex(p provider.Provider) bool { // own picks named for images, and those the user said draw (#1399), less // those they said make videos; a ChatGPT account's GPT Image, a Grok // subscription's Grok Imagine, a WorkBuddy plan's those its config lists. -func Drawers(p provider.Provider) []catalog.Model { +func Drawers(p provider.Provider) []catalog.Model { return DrawersOf(p, p.Available) } + +// DrawersOf is Drawers with p's model list from avail, called only when +// it is wanted: the Providers page has each provider's list at hand, and +// reading it again for each was 15 MB of what twenty window polls +// allocated. What avail gives is only read. +func DrawersOf(p provider.Provider, avail func() []catalog.Model) []catalog.Model { if drawsWorkBuddy(p) { return wbDrawers(p) } @@ -284,7 +290,7 @@ func Drawers(p provider.Provider) []catalog.Model { // the image models a Google sign-in lists (Antigravity's // gemini-3.1-flash-image), which draw on Code Assist (#757) var out []catalog.Model - for _, m := range p.Available() { + for _, m := range avail() { if catalog.DrawsID(m.ID) { m.Provider = p.ID out = append(out, m) @@ -302,7 +308,7 @@ func Drawers(p provider.Provider) []catalog.Model { // when it says it gives images or is named for them (XYenon's // Google AI Studio plugin). var out []catalog.Model - for _, m := range p.Available() { + for _, m := range avail() { if p.ModelKind(m.ID) == provider.KindVideo { continue } diff --git a/internal/gateway/drawers_of_test.go b/internal/gateway/drawers_of_test.go new file mode 100644 index 000000000..f13f9ee3e --- /dev/null +++ b/internal/gateway/drawers_of_test.go @@ -0,0 +1,26 @@ +package gateway + +import ( + "testing" + + "github.com/yetone/magpie/internal/catalog" + "github.com/yetone/magpie/internal/provider" +) + +// The image models a Google sign-in can draw with come from the model list +// the caller has (the Providers page's), read once, not from a list read +// again for them. +func TestDrawersOfTheCallersList(t *testing.T) { + p := provider.Provider{ID: "antigravity", Account: &provider.Account{Agent: "antigravity"}} + calls := 0 + got := DrawersOf(p, func() []catalog.Model { + calls++ + return []catalog.Model{{ID: "gemini-3-pro"}, {ID: agDrawer}} + }) + if len(got) != 1 || got[0].ID != agDrawer || got[0].Provider != "antigravity" { + t.Fatalf("drawers %+v, want %s alone", got, agDrawer) + } + if calls != 1 { + t.Fatalf("the list was read %d times", calls) + } +} diff --git a/internal/gui/providers.go b/internal/gui/providers.go index 9ac6c5e4b..fdfc34fad 100644 --- a/internal/gui/providers.go +++ b/internal/gui/providers.go @@ -930,7 +930,7 @@ func providerInfoWith(p provider.Provider, ls provider.Listing, agents []agentUs out.Exposed = len(exposed) // its image models aren't among those agents chat with; the editor // lists them apart, as Settings → Images is where one is picked - for _, m := range gateway.Drawers(p) { + for _, m := range gateway.DrawersOf(p, func() []catalog.Model { return ls.Available }) { out.DrawIDs = append(out.DrawIDs, m.ID) } out.Draws = len(out.DrawIDs)