draw: an OpenAI-compatible plugin's image models draw (SenseNova's sensenova-u1.5-lite)

01huadalang (Discord, #feedback): SenseNova's sensenova-u1.5-lite can
draw, but magpie's image generation picker doesn't list it.
ab546a4ee (v0.1.1707) covered SenseNova added as a key provider. The
SenseNova plugin (aqiu817/magpie-sensenova, @ai-sdk/openai-compatible at
token.sensenova.cn/v1) lists the model from SenseNova's /models too, but
Drawers returned nothing for any plugin provider (p.Account != nil), so
neither the picker nor generate_image could reach it there.

- provider.PluginOpenAICompatible: the plugin speaks the model on
  @ai-sdk/openai-compatible.
- Drawers: a plugin provider's listed model that DrawsID and ImagesAPI
  and is spoken on openai-compatible is a drawer; drawImages sends it to
  /images/generations or /images/edits under the plugin's base, through
  its fetch (pluginFetch maps /v1/... onto the loader's base), in the
  shape ab546a4ee sends SenseNova (b64_json, JSON edits). An image model
  on another package (a vendor's own API) is not listed. Grok's and
  WorkBuddy's drawers are unchanged (checked before this branch).
- Fake plugin: $FAKE_SENSENOVA adds sensenova-u1.5-lite and a flux-2 on
  @ai-sdk/anthropic.
- docs/subsystems/provider-plugins.md says it.

Test: TestSenseNovaPluginDraws (internal/gateway) installs the fake
plugin as "sensenova" in a real Bun host in front of the fake SenseNova
of TestSenseNovaU1Draws: Drawers lists sensenova-u1.5-lite alone, a
generation and an edit come back through the plugin (b64, JSON images,
chat never asked). Broken by hand: without the plugin branch it is red
(drawers []); without the openai-compatible check it is red (drawers
[sensenova-u1.5-lite flux-2]).

Run at this head: gofmt -l, go vet, GOOS=windows go vet, GOOS=linux go
vet -tags nogui on internal/gateway and internal/provider (clean); go
test -tags nogui -timeout 45m ./internal/gateway ./internal/provider
./internal/plugin ./internal/catalog: gateway (716s), plugin, catalog
ok; provider crashes in TestUnreadLoginsWriteErrorsKeepCredentials
(#3632, open), and with it skipped fails TestFetchAsksASharedBaseOnce,
TestFetchAsksOneListOnceForTwoBasesOfIt and
TestFetchUnionsProtocolListsWithoutChat, red the same at the base
a47596ea6 without this change (#3854, open). Neither touched here.
After the rebase onto origin/main b103ed058: gofmt, vet (three OSes),
internal/gateway -run 'SenseNova|Draw|Image|Edit|GrokPlugin|Plugin',
internal/catalog, internal/provider -run Plugin: ok.

Not tried: a real SenseNova account or the real plugin (none here); the
images API shape is from SenseTime's launch post as ab546a4ee read it.
Not run: the full ./... suite and the GUI suite (no GUI file changed).

Reported by 01huadalang (Discord).
This commit is contained in:
yetone
2026-10-27 23:45:57 +08:00
parent b103ed0582
commit 2b0387574e
5 changed files with 91 additions and 0 deletions
+2
View File
@@ -74,6 +74,8 @@ The provider's editor lists them under *Plugin options* (`pluginOptionsField` in
A plugin in front of Anthropic's or OpenAI's own API (a CPA or sub2api relay, say) can say its upstream answers a web search tool by itself (#2027). Its `config` hook sets `searches: true` on the provider; the host passes it through (`plugin.Provider.Searches`), and [`pluginProvider`](../../internal/provider/plugins.go) sets the provider's `Searches`, as a custom provider's "Searches the web by itself" does (#359). [`searchesItself`](../../internal/gateway/search.go) honours it for a plugin's provider only, on Anthropic's or Responses' API, and only for one the plugin has a model on: a client's `web_search` then goes to the plugin's `fetch` as sent, not through magpie's search. Another sign-in's `Searches` is never read, and Codex's and Grok's stay as they were. As with a relay, `searchRank` leaves it out, so magpie never picks it to search for other models; Settings can name it by hand (`namedSearcherRank`).
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 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
+14
View File
@@ -255,6 +255,20 @@ func Drawers(p provider.Provider) []catalog.Model {
}
return out
}
if p.IsPlugin() {
// a plugin in front of an OpenAI-compatible API: the image models
// 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)
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 {
m.Provider = p.ID
out = append(out, m)
}
}
return out
}
// any other subscription is asked through its agent's own API, which
// draws nothing magpie can ask for yet. A Responses-only relay (a Codex
// backend such as sub2api) has no chat base but serves the images API
+50
View File
@@ -118,3 +118,53 @@ func TestSenseNovaU1Draws(t *testing.T) {
t.Fatalf("edit was sent %v", sent)
}
}
// The SenseNova plugin (aqiu817/magpie-sensenova), in front of
// token.sensenova.cn/v1 on @ai-sdk/openai-compatible, lists
// sensenova-u1.5-lite from SenseNova's /models: Settings' image
// generation picker lists it, and it draws and edits on SenseNova's images
// API through the plugin's fetch, in the shape TestSenseNovaU1Draws holds
// a key to. An image model the plugin speaks on another vendor's package
// isn't listed, as no images API sits under its base (01huadalang on
// Discord).
func TestSenseNovaPluginDraws(t *testing.T) {
t.Setenv("FAKE_SENSENOVA", "1")
v := &senseNova{}
pid := besideFake(t, "sensenova", v)
p, err := provider.Find(pid)
if err != nil {
t.Fatal(err)
}
var drawers []string
for _, m := range Drawers(*p) {
if m.Provider != pid {
t.Fatalf("drawer %s of %q", m.ID, m.Provider)
}
drawers = append(drawers, m.ID)
}
if !slices.Equal(drawers, []string{"sensenova-u1.5-lite"}) {
t.Fatalf("drawers %v, want sensenova-u1.5-lite alone", drawers)
}
s := New()
code, a, raw := postImages(t, s, "/v1/images/generations", "application/json", `{"model":"`+pid+`/sensenova-u1.5-lite","prompt":"a magpie","size":"1024x1024"}`)
if code != 200 || len(a.Data) != 1 {
t.Fatalf("%d %s", code, raw)
}
if b, _ := base64.StdEncoding.DecodeString(a.Data[0].B64); string(b) != string(pngBytes) {
t.Fatalf("image %q", b)
}
if sent := v.got("/v1/images/generations"); len(sent) != 1 || !strings.Contains(sent[0], `"model":"sensenova-u1.5-lite"`) || !strings.Contains(sent[0], `"response_format":"b64_json"`) {
t.Fatalf("generation was sent %v", sent)
}
if sent := v.got("/v1/chat/completions"); len(sent) != 0 {
t.Fatalf("an image model was asked on chat: %v", sent)
}
img := "data:image/png;base64," + base64.StdEncoding.EncodeToString(pngBytes)
code, a, raw = postImages(t, s, "/v1/images/edits", "application/json", `{"model":"`+pid+`/sensenova-u1.5-lite","prompt":"bluer","images":[{"image_url":"`+img+`"}]}`)
if code != 200 || len(a.Data) != 1 {
t.Fatalf("edit: %d %s", code, raw)
}
if sent := v.got("/v1/images/edits"); len(sent) != 1 || !strings.Contains(sent[0], `"images":[{"image_url":"data:image/png;base64,`) {
t.Fatalf("edit was sent %v", sent)
}
}
+8
View File
@@ -85,6 +85,14 @@ export const FakePlugin = async ({ client }) => ({
if (process.env.FAKE_RESPONSES) cfg.provider[ID].models["fake-resp"] = { name: "Fake Responses", provider: { npm: "@ai-sdk/openai" }, limit: { context: 4000, output: 400 } }
// $FAKE_GROK: a Grok model on Responses, as Grok's plugin serves it
if (process.env.FAKE_GROK) cfg.provider[ID].models["grok-4.7"] = { name: "Grok 4.7", provider: { npm: "@ai-sdk/openai" }, limit: { context: 4000, output: 400 } }
// $FAKE_SENSENOVA: SenseNova's image model as its plugin lists it from
// token.sensenova.cn/v1/models, on the provider's openai-compatible;
// and an image model on a vendor's own API (Anthropic's package), which
// no images API of the base serves
if (process.env.FAKE_SENSENOVA) {
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_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
+17
View File
@@ -97,6 +97,23 @@ func (p Provider) PluginProvider() string {
return p.Account.plugin.ID
}
// PluginOpenAICompatible is whether p is a plugin's provider that speaks
// model on an OpenAI-compatible API (@ai-sdk/openai-compatible), whose
// other routes, the images API among them, its fetch sends under the same
// base: SenseNova's plugin at token.sensenova.cn/v1. A plugin of a vendor
// with an API of its own (Cursor's, Kiro's) speaks another package.
func (p Provider) PluginOpenAICompatible(model string) bool {
if !p.IsPlugin() {
return false
}
pp := *p.Account.plugin
if cur, ok := PluginOf(p.ID); ok {
pp = cur
}
m, ok := pluginModel(pp, model)
return ok && firstOf(m.NPM, pp.NPM) == "@ai-sdk/openai-compatible"
}
// PluginOf is the plugin provider magpie's provider id is, when it is one.
func PluginOf(id string) (plugin.Provider, bool) {
for _, pp := range heldPlugins() {