Commit Graph
14 Commits
Author SHA1 Message Date
yetone 577a0e4377 gateway: every upstream's call ids reach an Anthropic client as [A-Za-z0-9_-] only and go back to the upstream as it gave them, not only Devin's (#1304, StarMoonCity)
d3581077 made Devin's "Bash:0#a65b…" ids safe in the built-in Devin only. Any other upstream whose output reaches Claude Code through /v1/messages (a plugin's provider, a Chat or Responses relay, another vendor) could give an id with another character, and Claude Code drops the call and fails the turn "could not be parsed". The mapping now sits at the Anthropic boundary: anthropicEncoder and renderAnthropic give the client anthropicOutID (an unsafe id, or one beginning "mp_", as "mp_" and its base64url), and parseAnthropic turns tool_use ids and tool_result tool_use_ids back with anthropicInID, so the upstream gets its own id on the next turn, before unsignCalls reads Gemini's signatures off it. It is stateless, the same scheme as Devin's (safeCallID/rawCallID, which devinOutID/devinInID now call with "dv_"). An id that is safe already, Devin's "dv_…" ones (built-in and plugin) among them, goes both ways byte for byte, so prompt caching and every upstream that works today see no change. buildAnthropic still gives an Anthropic upstream the ids as they came. Chat's tool_calls id and Responses' call_id are left as they are: Codex and pi take any id, and no client that refuses one is known.

TestAnthropicCallIDsSafeBothWays gives the reporter's literal id from a Chat upstream through New().Handler() on /v1/messages, streamed and whole, and answers the call the way Claude Code does: with anthropicOutID/anthropicInID returning the id as it came (the old code) it fails "stream=true: call id \"Bash:0#a65b6a5e02194b87bbc796c4428c946d\", want one of [A-Za-z0-9_-] only"; with only anthropicInID taken out it fails with the upstream getting "mp_QmFz…" for its call and result. TestAnthropicSafeCallIDsUnchanged keeps toolu_/call_ ids and Devin's dv_ ids as they came, end to end too; with the mark set to "dv_" it fails on the double-encoded Devin ids.

go test -tags nogui ./internal/gateway ./internal/provider pass on Linux (golang:1.26.8 in Docker, temp HOME, module cache read-only; this Mac's syspolicyd is pegged and new binaries hang at launch, so no darwin test run). go vet -tags nogui ./internal/gateway for darwin, GOOS=linux and GOOS=windows, and gofmt -l pass. Not tried with a real Devin account or a real Claude Code session; an Anthropic upstream relayed as-is (passthrough) keeps its ids as it gave them.
2026-10-08 20:05:39 +08:00
yetone d358107766 gateway: Devin's call ids reach the agent as [A-Za-z0-9_-] only and go back to Devin as Devin gave them, so Claude Code runs SWE-2's tool calls (#1304, StarMoonCity)
SWE-2 names a call after its tool and turn ("Bash:0#a65b6a5e02194b87bbc796c4428c946d"). Claude Code takes a tool_use id only of [A-Za-z0-9_-], dropped every such call and failed the turn with "The model's tool call could not be parsed (retry also failed)"; Codex and pi take any id. decodeDevin now sends an id with another character, or one beginning "dv_", as "dv_" and its base64url (devinOutID), and buildDevin turns it back (devinInID) on the assistant's call and on the result that answers it, so Devin sees its own id. A safe id goes both ways as it came. It is stateless, and the same mapping the Devin plugin makes in 0.1.13 (outID/inID).

TestDevinCallIDsSafeBothWays takes Devin's reply with the reporter's literal id through serveDevin on Anthropic, Chat and Responses, and answers the call in the next request of each: with devinOutID and devinInID made to return the id as it came (the old behavior) it fails "anthropic: call id \"Bash:0#a65b6a5e02194b87bbc796c4428c946d\", want one of [A-Za-z0-9_-] only"; with only devinInID taken out (a one-way clean, as the issue proposed) it fails too, Devin getting the cleaned id. TestDevinSafeCallIDsUnchanged keeps safe ids, and a caller's own "dv_…", as they came.

go test -tags nogui ./internal/provider ./internal/gateway pass on Linux (golang:1.26.8 in Docker, temp HOME, module cache mounted read-only): on this Mac every freshly built test binary hangs at exec (syspolicyd at 100% CPU), so no darwin test run. go vet -tags nogui for darwin, GOOS=linux and GOOS=windows and gofmt -l pass. Not tried against a real Devin account.
2026-10-08 19:57:21 +08:00
yetone 14ed370e54 gateway: a temperature or top_p of 0 on the built-in Devin goes as 1e-6, so a greedy request isn't a 400 "an internal error occurred" for users not moved to the plugin (magpie-community/plugins#50, versun)
The same fix plugin 0.1.12 makes, for the built-in's buildDevin: Devin
answers every request with temperature or top_p exactly 0 with 400 "an
internal error occurred (trace ID …)", on every model; 1e-6 goes through.
Any other value goes as it came, and none still as Devin's defaults
(1, 0.95).

Verified: TestDevinSamplingZero fails on the old devin.go ("temperature
0: temperature 0 top_p 0.95, want 1e-06 0.95", likewise top_p 0 and -0)
and passes with the change. It also catches top_p left unchanged and
every value under 0.5 sent as 1e-6. Devin's behaviour was checked live
on a real account through the plugin's request, which carries the same
field 8 (0 → 400 on swe-2 and claude-sonnet-5-5, 1e-6 → 200); the
built-in path itself wasn't run against Devin. go vet (darwin, linux,
windows) and go test -tags nogui ./internal/gateway pass in a sandbox
HOME.
2026-10-08 18:17:17 +08:00
yetone 7067fce5ec gateway: a turn's parallel tool calls split over two assistant messages keep their results on Chat, Cursor and Devin (#1275)
An Anthropic request may send one turn's tool_use blocks in consecutive
assistant messages, answered by one user message. buildChat's
pairToolMessages, cursorMessages and buildDevin each closed the first
message's calls at the second one: the calls were answered "interrupted"
and the real results went out as a stray user message (Chat) or were
dropped (Cursor, Devin). joinSplitCalls now joins an assistant message
onto an assistant message before it that made tool calls, as Anthropic
reads them, so the calls are pending together. Responses, Messages,
Kiro and Gemini/Code Assist already kept the results.

Tests (split_calls_test.go): Chat, Cursor and Devin split cases fail on
main and pass now; a truly unanswered call of a split turn still gets
the synthetic result; text after a call in its own message; two text-only
assistant messages unchanged; Responses guard.
2026-10-08 16:47:52 +08:00
yetone 01e66e0f4a gateway: a reply a Claude subscription account answered carries its anthropic-ratelimit-unified-5h/7d headers, so a Claude Code signed in to claude.ai shows the 5-hour and weekly limits in its status line (claude-hud, #1257)
Claude Code tells the allowance in its rate_limit_event, not as headers, so
magpie says what it keeps of the account again as Anthropic does: a share
0-1 and a Unix-seconds reset per window, set as the request comes in and
again as the reply begins, after the turn's own event.

Claude Code 2.1.293 reads them only when it is signed in to claude.ai (the
sign-in field's claudeai); with magpie's key it ignores them.

Run: go test -tags nogui ./... (temp HOME); the two new tests fail without
limitHeaders; GOOS=linux/windows go vet of gateway and provider; real
Claude Code 2.1.293 in a sandbox HOME against a fake server sending these
headers: its statusline stdin had rate_limits.five_hour/seven_day with
used_percentage 42/17 when OAuth-signed in, none with ANTHROPIC_AUTH_TOKEN.
Not run: a real Claude account through a running magpie.
2026-10-08 15:28:52 +08:00
yetone 40c5b92a93 gateway: structured output crosses every translation: a Responses text.format or a Chat response_format reaches a Chat, Responses, Messages or Gemini upstream in its own words (frostming on Discord: responses.parse through magpie to OpenRouter came back as plain text)
The IR held a schema only from Anthropic's output_config.format, and only
Messages (and Claude Code's --json-schema) were asked for one. A Responses
request to a provider magpie speaks Chat or Messages to (OpenRouter has no
Responses URL) lost text.format; a Chat request translated to Responses or
Messages lost response_format; an Anthropic schema translated to Chat or
Responses was lost too.

Format (format.go) now carries json_schema (name, description, schema,
strict) or json_object from Responses, Chat, Anthropic and Gemini, and each
builder asks for it in its upstream's field. Where a target can't say it
(json_object on Messages or Claude Code; the vendor bridges Cursor, Devin,
Kiro, Qoder, Command Code, Zed) it is told in the system prompt. An upstream
answering 400/422 naming the field (DeepSeek's "This response_format type is
unavailable now") is asked again with it told in words, and so from then on.
Relayed requests are unchanged.
2026-10-08 10:37:02 +08:00
yetone 5c78e232a4 gateway: the built-in Devin sends a tool whose parameters have a root anyOf, oneOf or allOf as a plain object, as the plugin's 0.1.9 does, so Devin's Claude models no longer answer 502 to Codex desktop's automation_update for users still on the built-in (#1196); provider.ObjectRoot keeps the root's and allOf's own required fields beside anyOf/oneOf branches, which only add the fields every branch requires (it used to intersect them away)
buildDevin folds every offered tool's parameters through objectSchema
(provider.ObjectRoot, as anthropic.go does for #646); a schema with no root
combinator goes byte for byte as it came.

TestBuildDevinObjectRoot builds from #1196's literal parameters with oneOf,
anyOf and allOf; without the devin.go change it fails ("oneOf: sent {...
oneOf ..."). TestObjectRootKeepsOwnRequired fails on the old ObjectRoot with
"required = [id n]" (allOf's "kind" dropped). Run: go test -tags nogui
./internal/gateway ./internal/provider (temp HOME, pinned caches), both ok;
GOOS=linux and GOOS=windows go vet -tags nogui on both packages, ok. Not
tried against a real Devin account.
2026-10-08 05:35:01 +08:00
yetone b56bfb5a94 gateway: an upstream that answers 200 with a web page, with nothing at all, or with JSON that isn't, has failed as a 502 does, so a group asks its next member (#1012, cth123456: Codex on group/medium, agentrouter/deepseek-v4-flash now and then answered 200 text/html; the log said status=200 done=true in=0 out=0 served=null, codex/gpt-6-luna was never asked, and Codex failed with "stream disconnected before completion: stream closed before response.completed") — the candidate loop judged a try by its status alone, and holdWriter passes a 200 that is neither text/event-stream nor application/json straight to the agent, so the page went to Codex as the reply. notAnAPIReply now reads every 2xx (but 204) an upstream gives, in forwardOnce (every relayed and translated request, every API, plugins included) and in the built-in clients' own requests (the ChatGPT backend's /responses, Kiro, Zed, Qoder, Devin, Cursor, Command Code): a text/html reply, a body that begins as a web page whatever its Content-Type, an empty body, or one sent as JSON that doesn't begin with { or [ is turned into the 502 it stands for, with a JSON error saying what came back ("answered 200 OK with a web page (text/html), not an API reply: “Just a moment...”", the firewall hint for a block page). It then fails over, rests a minute and is logged as any 502 before the reply begins does; a provider with nobody after it hands the agent that 502 rather than the page. Only the first bytes are peeked, which a stream waits for anyway; a read that fails is left to the reader, a compressed body and anything else as it came. TestNotAnAPIReplyFailsOver (Chat, Responses and Messages, streamed and not, a member answering a Cloudflare page as text/html, as JSON and as SSE, an empty body as JSON and as SSE, and plain text as JSON; the next member must answer and the log name why) fails without the change in all 36 cases (the page relayed to the agent, or b never asked, or no reason logged) and passes; TestNotAnAPIReplyAlone (a 502 with the reason, logged 502) and TestCodexBackendWebPage (the ChatGPT backend's page reached Codex as a 200) fail without it and pass; TestAPIReplyUntouched keeps JSON after whitespace, SSE with and without a Content-Type, gzip, XML, a 204 and a 404 as they came. -race -count=10 on them; go test -tags nogui ./internal/gateway ./internal/provider, go vet (darwin, windows), gofmt -l, linux and windows (nogui) builds pass. Not tried with the reporter's relay (agentrouter) itself; the page is a Cloudflare challenge's, as the issue has only its Content-Type. docs/subsystems/gateway-routing.md says it. 2026-10-06 18:26:31 +08:00
Trojanking 7e2f5d9db7 devin: send the images a tool returned (#682)
A tool_result that holds only an image (Claude Code's Read on a PNG) reached
Devin as "(no output)": buildDevin read the result's text and never its
Images. Carry the ones that hold bytes on the tool message; Devin takes no
URL.
2026-10-03 21:30:50 +08:00
yetone fa9daa6945 docs: every built-in subscription a plugin serves once moved says so in its code, and AGENTS.md says where a fix for it goes (user: 对内置的订阅 provider 在代码层面和文档层面加上注释,防止又有别的 agent 在改内置订阅 provider 的代码而不知道生效的其实是对应的插件代码) — a moved Cursor, Devin, Grok, Command Code plan, Kiro, Zed, Qoder, Factory, Xiaomi MiMo, ZCode or WorkBuddy (provider.Moved; since v0.1.642 also the default for a new sign-in, provider.Adopt) is signed in, listed, requested and metered by its @magpie-community plugin, and none of the built-in's code in internal/provider/<name>*.go, internal/gateway/<name>.go, internal/zed or internal/qoder serves it; a fix made there alone never reaches those users. Each of those files now opens with a PLUGIN-SERVED notice naming the subscription's id, its plugin package, where the plugin lives (magpie-community/plugins, packages/<name>) and the mover whose min to raise so moved users get the fixed plugin (keepMovedCurrent); Qoder's adds that Qoder CN isn't moved and still runs there. AGENTS.md (CLAUDE.md imports it) lists the moved built-ins with their packages and movers, how to tell whether a user's is moved (move.state "plugin", onPlugins), the order a fix goes in (the plugin, publish, raise min, the built-in only for those not moved), the magpie code that does run for a moved one (internal/plugin, plugins.go, plugin_usage.go, pluginsignin.go, migrate*.go, app.js's subOf/pluginSubs/startPluginSignIn), and the parity tests. movers in migrate.go and SUBS in app.js point there too. TestMovedBuiltinsSayTheirPlugin fails for a mover whose code carries no PLUGIN-SERVED notice naming its id and package (it failed while a wrapped package name was split). Comments and docs only, no behaviour changed. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass (TestProvidersAnswerWhileListsComeIn and TestClaudeSignedOut failed once on their timing under load, pass alone; untouched). 2026-10-02 19:37:02 +08:00
yetone f654bec468 gateway: a model's web search goes to a search API of the user's own when no provider can search (#419 by HwFee: let me set up Tavily, Brave or SearXNG with my key rather than lose the search tool) — with no provider that searches by itself and no provider magpie could search with, the gateway took the client's web search tool away. Tavily, Brave Search, Exa, Firecrawl and SearXNG (an address of one's own, a key only if it asks for one) can now be set up, in an order: the injected web_search tool is then offered, and a search goes to the searcher's model as before, or, with none or when it fails, to each search API in turn, called directly with no model, its results handed back as the same hits and text the searcher path gives, so clients see the same web_search_tool_result blocks. The order is provider searches itself, searcher provider, search APIs, strip. They are kept in providers.json (0600) like provider keys; a backup carries them, their keys only when it carries keys, and one restored without keys keeps the key here; sync does the same, and a backup or sync from a magpie before them leaves the ones here alone. magpie search lists them, magpie search add <api> [key] [url=…] adds or updates one, magpie search rm <api> removes one; Settings has a Web search section (联网搜索) to add and remove them. Prompts, identity lines and headers to model providers are unchanged. TestWebSearchBySearchAPI, TestNoSearchAPINoTool, TestBackupSearchAPIs, TestSyncSearchAPIs and search-api.test.cjs fail without the change; TestSearchAPIsEachAsked checks each vendor against a fake, TestSearchCLI the command. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass; search-api, provider-search, click-scroll, old-webkit pass. 2026-10-01 19:44:44 +08:00
yetone 85fa42c172 devin: a tool's description goes in the instructions and the tool with a pointer to it, so WorkBuddy's requests are answered (silenx on X: devin 的到 workbuddy 下使用一直出现 502,不知哪里设置问题) — Devin answers "an internal error occurred" to some agents' tools as they describe themselves, whatever the model: WorkBuddy's Read ("Reads a file from the local filesystem. You can access any file directly by using this tool.", also with case or spacing changed, or with words before it) and its TaskOutput ("Takes a task_id parameter identifying the task"), which magpie passed on as a 502 on every request. The same words in a message go through, so the descriptions are now at the head of the first message after the instructions, in <tool_descriptions>, and each tool is sent with its name, its schema and a pointer to its own. Reproduced in a sandbox HOME on a Devin Teams sign-in with WorkBuddy's own request, captured from its bundled CLI: 502 on SWE-2, Claude Opus 5.5 and SWE-1.7 Lightning, 200 without tools; now 200, and WorkBuddy's CLI on all three read a file and wrote another through its Read and Write tools; Claude Code on SWE-2 did the same. TestBuildDevin checks the descriptions in the instructions, each tool's pointer, and none of either when no tool is to be called. go vet, go build -tags nogui (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui ./... pass. 2026-09-30 14:09:57 +08:00
yetone 4f5699aae5 providers: Kiro and Devin keep several accounts, as the other subscriptions do (Kiro要支持增加多个账号…Devin也要能够增加多个账号) — both only borrowed their CLI's one sign-in (Devin wrote devin's credentials.toml, Kiro kept one kiro-auth-token.json), so signing in again replaced the account. The CLI's or IDE's own account is now read as it is and each further account gets a home of magpie's: Kiro's token file is kept and refreshed there, and Devin's credentials.toml sits in a data folder the devin CLI is run with (XDG_DATA_HOME / APPDATA), so devin auth status and models list answer for it. They are listed, switched, ticked on and forgotten like the others, and the gateway moves on to the next when one is out; the single Kiro sign-in kept before is moved into a home of its own. Tested with a fake Kiro and a fake devin CLI (second account, signing in again, switching, forgetting); not with real accounts 2026-09-29 15:20:22 +08:00
yetone ce8d0e065c devin: served straight through Devin's API, not the CLI over ACP — each request goes to the GetChatMessage RPC the devin CLI itself uses, with its sign-in: the conversation as it is, the caller's tools, images and all, and the reply streamed back text, thinking and tool calls as they come. A family's name is sent as its variant at the effort asked for; Adaptive and Fusion, which the API doesn't serve, are no longer listed. The instructions go at the head of the first message, as Kiro's do, since Devin turns away Claude Code's own in its system field. Tested live from a sandbox: Claude Code and OpenCode on Opus 5.5, SWE-2 and GPT-6 Sol list, read and write files through several tool rounds; images and a tool round trip answered on Claude, SWE, GPT and Gemini models 2026-09-27 15:30:24 +08:00