Commit Graph
3 Commits
Author SHA1 Message Date
yetoneandggbdpq 7301c070f0 gateway: /v1/images/edits reads and forwards OpenAI's markup layer (#5364)
OpenAI's images edit takes `markup`, a transparent PNG laid over the
first image to steer the edit (JSON image_url, or a multipart file part;
never beside a mask). magpie read only the mask: a JSON markup stopped in
drawing.Extra, a multipart one was dropped, and neither the ChatGPT
backend's JSON edit nor the plain multipart edit carried it, so an edit
with a markup came back 200 with the layer left out (#5364, kongjianguan,
with the probe and the three places).

drawing has a Markup beside Mask, read from JSON (markup.image_url) and
from a multipart `markup` part, and sent where the mask is: as
{"image_url": data URL} on the ChatGPT/SenseNova JSON edit and as its own
part on the multipart edit. A markup that can't be read, or one sent with
a mask, is a 400 before anything is asked. OpenRouter, Volcengine Ark and
DashScope, which turn a mask away, turn a markup away by name too.

Patch from ggbdpq (mbox sha256 b591c6ad499789c5, matches the issue).
Changed in review:
- "markup" joins drawingRead, so it no longer also rides Extra; on Ark
  the raw field went out as an Ark field.
- Ark and DashScope refuse a markup as they refuse a mask; the patch
  refused it on OpenRouter only.
- A mask with a markup is a 400 (OpenAI's docs: "Cannot be combined
  with mask").
- Tests rewritten: the patch's broken-markup test posted to a server
  with no "art" provider, so it would have been a 400 for the unknown
  model with or without the fix; the Codex test kept its upstream in a
  package global. They now check the bytes that reach the vendor, the
  multipart-in case, the mask clash and the three refusals.

Run on mote (-tags nogui, the package's TestMain sandbox):
- TestCodexEditSendsTheMarkup, TestEditSendsTheMarkup/{json,multipart},
  TestEditWithAMarkupItCantSendIsRefused/{not base64,beside a mask},
  TestMarkupRefusedWhereNoLayerIsTaken: ok.
- Broken by hand: draw.go, draw_dashscope.go, draw_volcengine.go back to
  cff530079 (Markup field kept so the tests build): all four FAIL ("the
  ChatGPT edit's markup is \"\"", "kept as an extra field too", "the
  markup layer never reached the vendor whole", "not base64: 200, want
  400", "beside a mask: 200", "Ark: <nil>", "DashScope: <nil>",
  "OpenRouter: 502 ... want 400").
- -race -run 'Draw|Image|Edit|Ark|DashScope|OpenRouter|Markup|Mask|Volc|
  Seedream|ModelScope|SenseNova' ./internal/gateway: ok 108s.
- go vet -tags nogui, GOOS=linux go vet -tags nogui, GOOS=windows go vet
  of ./internal/gateway: clean. gofmt -l: clean.

Not tried: a real ChatGPT account's gpt-image edit with a markup (none
here), so whether that backend applies the field, or refuses it, is
unknown; OpenAI's public docs list markup for GPT Image 2.5. Not
changed: routes that drop a mask today (Grok, ModelScope, chat-model and
Gemini draws, WorkBuddy) drop a markup the same way. The full suite is
run after the push.

Reported-by: kongjianguan
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-06 11:12:12 +08:00
yetone d8501848a7 gateway: an Ark image request's own fields go to Ark, and watermark and response_format are the caller's
axelburks on Discord listed what /v1/images/generations did to a Seedream
request against Ark's images API (docs 82379/1541523). Checked against
those docs and draw.go / draw_volcengine.go; the real ones:

- Image params were dropped. drawing read OpenAI's fields alone, so
  sequential_image_generation and its options (a group of up to 15),
  optimize_prompt_options, tools, layer_decomposition and every other
  Ark field never reached Ark. Now the request's fields magpie doesn't
  read (drawingRead) are drawing.Extra, from a JSON body or a multipart
  form, masked as the prompt is (fails closed), and sent to Ark as they
  came; a form's values are typed as Ark takes them (formValue, with
  Ark's text fields kept as text). layer_decomposition with an image
  needs no prompt.
- watermark and response_format were forced. Every request went with
  watermark false and response_format b64_json. Now watermark false is
  magpie's default only, and a caller's watermark wins; response_format
  "url" asks Ark for its URL and answers it, anything else still asks
  b64_json.
- stream true would have gone to Ark and come back as events this route
  can't read: it is a 400 that names
  /v1/magpie/native/<provider>/images/generations.
Kept as it was: n stays OpenAI's, that many requests, each one image or
one group.

Tests: TestArkImagesPassOnTheirOwnFields (a group, optimize_prompt_options,
a caller's watermark, tools and url reach Ark as sent; a form's fields
typed; stream refused naming the native route). Docs: gateway-routing.md
(the Ark images row and paragraph), docs/integrating.md and the site's
integrate page (en, zh) on the vendor fields and the native route.

Run on mote at the head of this stack (the Ark video fields, the native
route and the Ark image fields, three commits on af9ac3d25):
- go test -count=1 -timeout 45m ./internal/gateway ./internal/gui
  ./internal/access: gateway and access ok; gui red only in
  TestMainWindowCorners/macOS_26_SDK (#3949, red on main).
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./...: clean. gofmt -l: nothing.
- No GUI file or script changes in this stack, so no GUI run.
The commits between were not run on their own at this base.

Broken by hand, each red, then put back:
- Extra not merged into Ark's request: TestArkImagesPassOnTheirOwnFields red
- response_format url not asked of Ark: TestArkImagesPassOnTheirOwnFields red

Not tried: no real Ark image was drawn (no money spent); the shapes are
from Ark's docs, on a fake Ark.

Credit: axelburks on Discord.
2026-11-03 18:46:55 +08:00
yetone deffaed85e draw: Volcengine Ark's Seedream is asked as its images API takes it: watermark false, reference images as JSON, one request per image, a ratio as its 2K size or an error (JL on Discord)
JL (#help): magpie_image through a Volcengine Ark provider came back
watermarked, edits went as a multipart form, and n and a ratio size
were sent as for OpenAI. Checked against Ark's own doc, 图片生成 API
(https://www.volcengine.com/docs/82379/1541523, read 2026-10-15):
- watermark is a boolean, default true ("AI 生成" in the corner);
- image is a string or string[], a URL or data:image/<fmt>;base64,...;
  there is no edits endpoint, it goes to /images/generations;
- there is no n field (one image, or a group the model sizes itself
  under sequential_image_generation, which 5.0 pro/flash refuse);
- size is a tier (1K/1.5K/2K/3K/4K by model) or WIDTHxHEIGHT; a ratio
  is to be described in the prompt. The doc lists each ratio's 2K WxH;
  4.0/4.5/5.0 lite's 2K table is inside every model's pixel range (5.0
  pro's max 2048x2048x1.1025 too), so it is the one used;
- no quality, no mask; output_format png/jpeg and background
  transparent exist (5.0 models) and are passed when asked.

drawArk (draw_volcengine.go), reached from drawImages for any
ark.*.volces.com base (the preset's plans or a pay-as-you-go provider
added by hand): JSON body with watermark false and b64_json, images in
image, one request per image through eachDrawing, a listed ratio sent
as its 2K size and any other ratio a 400 saying to put it in the
prompt or give WxH, before Ark is asked. A mask is a 400.

Not tried against the real Ark API (no Ark key here); the fake server
follows the doc's request and answer shapes.

Run (worktree at origin/main dd25997a4, go1.26.8, -tags nogui -p 1):
- go test -run 'TestArk|TestIsArk' ./internal/gateway: ok. With the
  isArk branch in drawImages removed by hand: TestArkDrawsUnmarkedOncePerImage
  (one image, no watermark field), TestArkEditSendsImagesAsJSON (404 at
  /images/edits) and TestArkSizes (ratio sent, 200) red; restored, green.
- go test -run 'Image|Draw|Ark|ModelScope|Drawing|WorkBuddyDraw|Video'
  ./internal/gateway: ok (74.5s).
- go test -run TestLoopGuardLeavesOrdinaryRepliesAlone (reads the
  docs): ok.
- gofmt -l internal/gateway: clean. go vet -tags nogui ./internal/gateway
  for GOOS=darwin, linux, windows: clean.
- Not run: the full suite.

Full suite: SUITE_LINE
2026-10-15 23:08:04 +08:00