Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

draw: a plugin's Gemini image model draws on generateContent through its fetch

yetonee2b7233499c0
diff --git a/docs/subsystems/provider-plugins.md b/docs/subsystems/provider-plugins.md
index 6c44709ec..99696b949 100644
--- a/docs/subsystems/provider-plugins.md
+++ b/docs/subsystems/provider-plugins.md
@@ -82,6 +82,8 @@ A plugin in front of Anthropic's or OpenAI's own API (a CPA or sub2api relay, sa
A plugin in front of an OpenAI-compatible API draws with the image models its list names (01huadalang on Discord: the SenseNova plugin, aqiu817/magpie-sensenova, lists `sensenova-u1.5-lite` from `token.sensenova.cn/v1/models`). [`Drawers`](../../internal/gateway/draw.go) lists a plugin provider's model for Settings' image generation picker when its id is an images-API model (`catalog.DrawsID` and `catalog.ImagesAPI`) and the plugin speaks it on `@ai-sdk/openai-compatible` (`Provider.PluginOpenAICompatible`); `drawImages` sends it to `/v1/images/generations` or `/v1/images/edits` under the plugin's base, through its `fetch`, which signs it as a chat. A model on another package (Anthropic's, a vendor's own API such as Cursor's) isn't listed, as no images API sits under that base. Grok's and WorkBuddy's plugins keep their own drawers. `TestSenseNovaPluginDraws`.
+A plugin's model on Gemini's API (`@ai-sdk/google`, so `Provider.APIs` is Code Assist alone) draws as a Google sign-in's image models do (XYenon's Google AI Studio plugin, XYenon/magpie-google-ai-studio). `Drawers` lists it when its id names an image model (`catalog.DrawsID`) or the plugin says it gives images (`capabilities.output.image`, or models.dev's `modalities.output`, read into `OutputModalities`), and it isn't an Imagen (`catalog.ImagesAPI`, which draws on `:predict`, not served). `draw` sends it to `drawCodeAssist` (`pluginDrawsGemini`): one `generateContent` per image through the plugin's `fetch`, with `responseModalities` `["TEXT","IMAGE"]` (`Request.draws` asks for it of a model not named for images), and an edit's pictures as the prompt's `inlineData`; the pictures come back from the answer's `inlineData`. The images routes' key holds and usage apply as for any drawer. `TestGeminiPluginDraws`.
+
A plugin can instead mark single models of its list with `searches: true` (on the `config` hook's model or the `models` hook's list): a model that searches the web by itself when asked in plain words, such as Trae's search model. The host passes it through (`plugin.Model.Searches`), `pluginCatalog` makes it the catalog model's `WebSearch` "native", and the gateway offers the provider in Settings › Web search's picker and its own pick with those models alone (`pluginSearches`, `partSearcher`).
## A plugin's service tiers
diff --git a/internal/gateway/codeassist.go b/internal/gateway/codeassist.go
index f74be1699..049cdd5b1 100644
--- a/internal/gateway/codeassist.go
+++ b/internal/gateway/codeassist.go
@@ -562,8 +562,9 @@ func buildCodeAssistSent(r *Request, sent, agent string) []byte {
gen["responseJsonSchema"] = sc
}
}
- if catalog.DrawsID(sent) {
- // an image model draws only when asked for images too
+ if catalog.DrawsID(sent) || r.draws {
+ // an image model draws only when asked for images too: one named
+ // for them, or any asked to draw (a plugin's that says it does)
gen["responseModalities"] = []string{"TEXT", "IMAGE"}
}
if len(gen) > 0 {
diff --git a/internal/gateway/draw.go b/internal/gateway/draw.go
index 6f3126a99..7def0ec7e 100644
--- a/internal/gateway/draw.go
+++ b/internal/gateway/draw.go
@@ -297,9 +297,17 @@ func Drawers(p provider.Provider) []catalog.Model {
// its list names that draw on the images API, sent through its
// fetch under the base its chat goes to (01huadalang on Discord:
// the SenseNova plugin's sensenova-u1.5-lite)
+ // A model the plugin speaks Gemini's API to (@ai-sdk/google) draws
+ // as a Google sign-in's do, on generateContent asking for images,
+ // 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() {
- if catalog.DrawsID(m.ID) && catalog.ImagesAPI(m.ID) && p.PluginOpenAICompatible(m.ID) && p.ModelKind(m.ID) != provider.KindVideo {
+ if p.ModelKind(m.ID) == provider.KindVideo {
+ continue
+ }
+ if catalog.DrawsID(m.ID) && catalog.ImagesAPI(m.ID) && p.PluginOpenAICompatible(m.ID) ||
+ pluginDrawsGemini(p, m.ID) && (catalog.DrawsID(m.ID) || slices.Contains(m.OutputModalities, "image")) {
m.Provider = p.ID
out = append(out, m)
}
@@ -1069,7 +1077,7 @@ func (s *Server) draw(ctx context.Context, p provider.Provider, model string, d
if drawsCodex(p) || drawsGrok(p) {
return s.drawImages(ctx, p, model, d)
}
- if googleAccount(p) {
+ if googleAccount(p) || pluginDrawsGemini(p, model) {
return s.drawCodeAssist(ctx, p, model, d)
}
if p.Base(provider.Chat) == "" && p.Base(provider.Responses) == "" {
@@ -1789,6 +1797,14 @@ func (s *Server) drawGemini(ctx context.Context, p provider.Provider, model stri
})
}
+// pluginDrawsGemini is whether model is one p, a plugin, speaks Gemini's
+// generateContent to (its npm @ai-sdk/google) and isn't an Imagen, which
+// draws on :predict: such a model draws through the plugin's fetch as a
+// Google sign-in's draws, on drawCodeAssist.
+func pluginDrawsGemini(p provider.Provider, model string) bool {
+ return p.IsPlugin() && !catalog.ImagesAPI(model) && slices.Equal(p.APIs(model), []provider.Protocol{provider.CodeAssist})
+}
+
// drawCodeAssist asks an image model on a Google sign-in to draw, as it is
// asked to chat: on Code Assist, in the account's envelope, which asks for
// images beside text for an image model (buildCodeAssistSent); what it
@@ -1805,7 +1821,7 @@ func (s *Server) drawCodeAssist(ctx context.Context, p provider.Provider, model
}
parts = append(parts, Part{Kind: Image, MediaType: pic.Mime, Data: base64.StdEncoding.EncodeToString(pic.Data)})
}
- req := &Request{Messages: []Message{{Role: "user", Parts: parts}}}
+ req := &Request{Messages: []Message{{Role: "user", Parts: parts}}, draws: true}
return s.eachDrawing(d.N, func() (drawn, int, error) {
// one each: the drawings are asked for at once
ask := s.askTranslated(p, provider.CodeAssist, model, http.Header{}, http.Header{})
diff --git a/internal/gateway/draw_gemini_plugin_test.go b/internal/gateway/draw_gemini_plugin_test.go
new file mode 100644
index 000000000..8910186d7
--- /dev/null
+++ b/internal/gateway/draw_gemini_plugin_test.go
@@ -0,0 +1,85 @@
+package gateway
+
+import (
+ "encoding/base64"
+ "fmt"
+ "io"
+ "net/http"
+ "slices"
+ "strings"
+ "sync"
+ "testing"
+
+ "github.com/yetone/magpie/internal/provider"
+)
+
+// A plugin's model on Gemini's API (@ai-sdk/google) that gives images
+// draws as a Google sign-in's image models do: on generateContent asking
+// for images beside text, through the plugin's fetch, the picture read
+// from its answer's inlineData (XYenon's Google AI Studio plugin). One that
+// only says it gives images is asked for them too; an Imagen, which draws
+// on :predict, and a model that gives only text are no drawers.
+func TestGeminiPluginDraws(t *testing.T) {
+ t.Setenv("FAKE_GEMINI_DRAWS", "1")
+ var mu sync.Mutex
+ var paths, bodies []string
+ pid := besideFake(t, "google-ai-studio", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ b, _ := io.ReadAll(r.Body)
+ mu.Lock()
+ paths, bodies = append(paths, r.URL.RequestURI()), append(bodies, string(b))
+ mu.Unlock()
+ if !strings.Contains(r.URL.Path, ":streamGenerateContent") {
+ w.WriteHeader(404)
+ return
+ }
+ w.Header().Set("Content-Type", "text/event-stream")
+ fmt.Fprintf(w, "data: %s\n\n", `{"candidates":[{"content":{"role":"model","parts":[{"text":"here"},{"inlineData":{"mimeType":"image/png","data":"`+base64.StdEncoding.EncodeToString(pngBytes)+`"}}]},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":5,"candidatesTokenCount":1290}}`)
+ }))
+ p, err := provider.Find(pid)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var drawers []string
+ for _, m := range Drawers(*p) {
+ drawers = append(drawers, m.ID)
+ }
+ slices.Sort(drawers)
+ if !slices.Equal(drawers, []string{"gemini-3-flash-canvas", "gemini-3-pro-image-preview"}) {
+ t.Fatalf("drawers %v, want gemini-3-flash-canvas and gemini-3-pro-image-preview", drawers)
+ }
+ s := New()
+ for _, model := range drawers {
+ mu.Lock()
+ paths, bodies = nil, nil
+ mu.Unlock()
+ code, a, raw := postImages(t, s, "/v1/images/generations", "application/json", `{"model":"`+pid+`/`+model+`","prompt":"a magpie"}`)
+ if code != 200 || len(a.Data) != 1 {
+ t.Fatalf("%s: %d %s", model, code, raw)
+ }
+ if b, _ := base64.StdEncoding.DecodeString(a.Data[0].B64); string(b) != string(pngBytes) {
+ t.Fatalf("%s: image %q", model, b)
+ }
+ mu.Lock()
+ if len(paths) != 1 || paths[0] != "/v1/models/"+model+":streamGenerateContent?alt=sse" {
+ t.Fatalf("%s was asked at %v", model, paths)
+ }
+ if !strings.Contains(bodies[0], `"responseModalities":["TEXT","IMAGE"]`) || !strings.Contains(bodies[0], "a magpie") {
+ t.Fatalf("%s was sent %s", model, bodies[0])
+ }
+ mu.Unlock()
+ }
+ // an edit: the picture goes as the prompt's inlineData
+ mu.Lock()
+ paths, bodies = nil, nil
+ mu.Unlock()
+ img := "data:image/png;base64," + base64.StdEncoding.EncodeToString(pngBytes)
+ code, a, raw := postImages(t, s, "/v1/images/edits", "application/json", `{"model":"`+pid+`/gemini-3-flash-canvas","prompt":"bluer","images":[{"image_url":"`+img+`"}]}`)
+ if code != 200 || len(a.Data) != 1 {
+ t.Fatalf("edit: %d %s", code, raw)
+ }
+ mu.Lock()
+ defer mu.Unlock()
+ if len(bodies) != 1 || !strings.Contains(bodies[0], `"inlineData"`) || !strings.Contains(bodies[0], base64.StdEncoding.EncodeToString(pngBytes)) {
+ t.Fatalf("edit was sent %v", bodies)
+ }
+}
diff --git a/internal/gateway/ir.go b/internal/gateway/ir.go
index de03bcfdf..d0e97cab9 100644
--- a/internal/gateway/ir.go
+++ b/internal/gateway/ir.go
@@ -182,6 +182,9 @@ type Request struct {
// client asked prompt_cache_retention "in_memory", or the upstream
// turned the ttl away (hourMarksRefused).
hourMarks bool
+ // draws asks the model for images beside text: a drawing asked on
+ // Gemini's API of a model not named for images (drawCodeAssist).
+ draws bool
Model string
System string
diff --git a/internal/plugin/testdata/fake/index.js b/internal/plugin/testdata/fake/index.js
index 3d8e3f2b4..d0b3b9479 100644
--- a/internal/plugin/testdata/fake/index.js
+++ b/internal/plugin/testdata/fake/index.js
@@ -93,6 +93,15 @@ export const FakePlugin = async ({ client }) => ({
cfg.provider[ID].models["sensenova-u1.5-lite"] = { name: "sensenova-u1.5-lite", limit: { context: 131072, output: 32768 } }
cfg.provider[ID].models["flux-2"] = { name: "Flux 2", provider: { npm: "@ai-sdk/anthropic" }, limit: { context: 1000, output: 100 } }
}
+ // $FAKE_GEMINI_DRAWS: image models on Gemini's API, as XYenon's Google
+ // AI Studio plugin lists them: one named for images, one that only
+ // says it gives them, and an Imagen, which draws on :predict instead
+ if (process.env.FAKE_GEMINI_DRAWS) {
+ const g = { provider: { npm: "@ai-sdk/google" }, limit: { context: 3000, output: 300 } }
+ cfg.provider[ID].models["gemini-3-pro-image-preview"] = { ...g, name: "Nano Banana Pro", modalities: { input: ["text", "image"], output: ["text", "image"] } }
+ cfg.provider[ID].models["gemini-3-flash-canvas"] = { ...g, name: "Gemini 3 Flash Canvas", modalities: { input: ["text", "image"], output: ["text", "image"] } }
+ cfg.provider[ID].models["imagen-4.0-generate-001"] = { ...g, name: "Imagen 4", modalities: { input: ["text"], output: ["image"] } }
+ }
// $FAKE_DEEPSEEK: a DeepSeek model, as Cline's cline-pass/deepseek-v4-pro
if (process.env.FAKE_DEEPSEEK) cfg.provider[ID].models["deepseek-v4-pro"] = { name: "DeepSeek V4 Pro", limit: { context: 1000, output: 100 } }
// $FAKE_GLM: a GLM model, as Cline's cline-pass/glm-5.3