Files
magpie/docs
yetone 5ccc05afe7 gateway: a plugin's non-streaming Responses request is relayed streamed and given back whole, so Grok's x_search runs (plugins#112, Watchyourback)
Plugin accounts only stream (Account.Stream), so a stream:false request
was translated: parsed to the IR and rebuilt. The Responses parser keeps
only function and web_search tools, so x_search never reached the Grok
plugin, and Grok answered "let me look that up" without searching. The
rendered reply also hardcoded "tools": [], dropped
usage.server_side_tool_usage_details, and dropped web_search's open_page
item. Watchyourback's capture of the plugin's fetch showed this (no tools
field, input wrapped into message[], store:false); CodeAlex52's code read
agreed.

Now a plugin's request on Responses that asked for one body is relayed
like a streamed one (gathers, used by serve's relay decision and by
passthrough):
- It is asked with stream:true, and the stream goes through the relay's
  usual tidies.
- The client gets the `response` of the stream's response.completed (or
  response.incomplete) as one application/json body. Its output is
  filled from response.output_item.done items, or else the streamed
  text, when that event's output is empty (gathered.go).
- A non-200 goes back as before.
- A whole reply goes back as it came.
- A stream that fails, or ends without its last event, is a 502, as a
  translated one is, never an empty 200.
- Usage is counted from the stream, as for a streamed relay.

Left as it was:
- Messages: its stream has no event holding the whole reply, so
  gathering it means assembling the message from deltas. That is not a
  simple sibling.
- Subscriptions magpie signs in to itself (ChatGPT backend, Qoder,
  MiMo...): their own code fits their requests, and their fakes end in a
  response.completed with no output. A first version that covered every
  stream-only account broke 7 Codex/ChatGPT-API tests, so it was
  narrowed to plugins.

TestGrokPluginGetsNamespacedTools now expects the namespace's freeform
custom tool to be left out (grokBody), as the built-in and the streamed
plugin already did. The translation had offered it as a function.

Tests (fake grok plugin through the plugin host):
- TestGrokPluginNonStreamKeepsHostedTools: upstream SSE with a
  custom_tool_call, tools [x_search] and server_side_tool_usage_details.
  Asserts the plugin was asked stream:true with tools [x_search]; the
  client gets application/json with the custom_tool_call, message,
  tools and details; usage is recorded at 50/7.
- TestGrokPluginNonStreamEndedShort: no response.completed gives 502.
- TestGatheredTextOnlyStream: deltas only.
Each was broken by hand and went red:
- the relay condition reverted: "the plugin was offered null";
- the missing-completed check removed: 200;
- the text fallback removed.

Run: gofmt -l; go vet ./internal/gateway on darwin, GOOS=linux -tags
nogui and GOOS=windows; go test ./internal/gateway -count=1 (ok, 1400s,
load ~200).
Not tried: a real Grok account or the real grok plugin; the reporter's
allowed_x_handles case.
2026-10-14 20:25:21 +08:00
..