Files
magpie/internal
yetone db87e014f2 gateway: /v1/magpie/native/<provider>/<path> passes Ark's own images and video-task API on
axelburks on Discord asked for a way to reach what the OpenAI-shaped
routes can't carry: Ark's image stream, its task list and cancel, a
field newer than magpie. A coordinator asked for it to stay behind the
gateway's key and auth like every route, and for the design to be said.

Decided:
- One route, /v1/magpie/native/{provider}/{path...} (POST, GET, DELETE),
  for Volcengine Ark only (isArk, not a remote magpie), at the paths it
  makes images and videos at: POST images/generations; POST/GET
  contents/generations/tasks (with Ark's query); GET/DELETE
  contents/generations/tasks/<id> (nativeArkPath). Never Ark's chat,
  whose routing, usage and masking are the chat routes'. Another
  provider or path is a 404 that says what is served.
- Behind every guard a /v1 route has (a key beyond loopback, corsGuard,
  the key's rate), and refused to a read-only key (readOnlyRefused).
- Refused (403) to a key held to models, accounts or a spend limit, or
  issued by one (nativeHeld): a poll or a cancel can't be tied to a
  model, and magpie prices no answer it doesn't read, so it couldn't
  hold such a key to them. Such keys use /v1/images/generations and
  /v1/videos, which now pass the vendor's own fields on.
- A model the user switched off is refused. The body's strings are
  masked (fails closed) and put back in the answer (restoring); numbers
  go exact (UseNumber, a 17-digit seed is kept).
- Signed with the provider's key and magpie's User-Agent; no caller
  header goes on but Accept. The answer comes back as it came, an event
  stream flushed as it arrives.
- Each request is a Requests row and a usage record (Operation
  "native", no tokens).

Tests: TestNativeArkRoute (the stream, the task list's query and a
cancel reach Ark signed with the provider's key, the body as sent; chat,
a wrong method, a deeper path, another provider, an unknown one and
every held key are refused without Ark being asked),
TestNativeArkStreamsAsItComes (the first event reaches the caller while
Ark holds the rest), TestReadOnlyKeyEveryRoute (the three patterns in
readOnlyRefused). Docs: gateway-routing.md's native route section.

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:
- nativeHeld skipped: TestNativeArkRoute red
- an issuer's hold not read: TestNativeArkRoute red
- nativeArkPath skipped: TestNativeArkRoute red
- isArk not checked: TestNativeArkRoute red
- no flush: TestNativeArkStreamsAsItComes red (its 30s bound)
- the DELETE pattern out of readOnlyRefused: TestReadOnlyKeyEveryRoute red

Not tried: no real Ark request through the route (it would spend money);
Ark's answers are a fake shaped from its docs.

Credit: axelburks on Discord.
2026-11-03 18:46:54 +08:00
..
…
…
…
…
…
…
…