yetone
05ef7bcec7
gateway: Cursor's built-in shows the model a tool's images, in the message after its results ( #1861 )
...
Found while checking every translation of a tool's images for #1861 .
cursorMessages wrote a tool result's text alone, so an image Codex's
view_image (or any tool) returned never reached a model behind the
Cursor built-in. Cursor's plugin already gets it, since magpie hands it
a Chat body (seeLater: the result says the image follows, and a user
message after the results carries it).
The built-in now does the same: a result with images says
"[The tool returned an image; it follows in the next message.]", and a
user message after the results holds "[From the result of <name> (tool
call <id>):]" and each image as Cursor's image block (cursorImage, the
same block a user's own image already used). gateway-routing.md names
Cursor among the translations.
TestCodexToolImageCursor, from codex-rs 0.162's view_image output, fails
on the old cursor.go and passes now.
Run: gofmt -l; go vet darwin, linux -tags nogui, windows on
internal/gateway; go test -tags nogui ./internal/gateway
./internal/provider (sandbox HOME, ok).
Not tried: a real Cursor account. Whether Cursor's backend shows the
model an image in a user message that follows tool results is taken from
how it takes a user's own image, not seen.
2026-10-13 04:00:57 +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
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
yetone
730a163f47
cursor: a step that calls tools records what it used, the cache included ( #676 ) — Cursor tells a turn's usage (TurnEndedUpdate) only once the client has run the tools and sent their results in the same Run, and the caller runs them after the Run is closed, so every tool step was recorded as an estimated input with no cache (2395 / 0 where Cursor counted 4265, 4224 of them cached), while text turns showed ~99% cache. After the calls Cursor sends only the checkpoint (no token details) and heartbeats; a cancelled Run ends with an error and no usage. Every Run is counted in the dashboard's usage events (DashboardService/GetFilteredUsageEvents) by its conversation_id, input apart from the cache read and written; one shows about 2.5 s after the Run closes. So a tool step with no TurnEnded now closes the Run and looks for its event (after 1.5 s, every 0.5 s, up to 6 s): its conversation's, no older than the Run, not already counted; else the estimate as before. A Run with no conversation id gets one, to be found by. The estimate is also no longer added to a turn read wholly from the cache (input 0, cache read > 0). The mover's min for cursor is 0.1.9, which does the same in the plugin (magpie-community/plugins: cursor 0.1.9). TestCursorToolStepReadsItsUsageEvent fails on the old code (5008 estimated, 0 cached) and passes. Tried with the real Cursor account: the built-in (grok-4.7-medium-fast) reports 6153 in, 6144 cached on a tool call, streamed or not; and through a sandbox magpie's plugin host with plugin 0.1.9, 6186 in, 6144 cached, 121 out, where 0.1.8 recorded 5057 estimated, 0 cached. A tool step now takes about 2.5 s longer to finish. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass.
2026-10-03 21:14:13 +08:00
yetone
0887a9d7eb
cursor: a model Cursor serves only in Max Mode is asked for again in Max Mode, and the models Cursor's picker offers beyond cursor-agent models (GLM-5.3, GLM-5.3 Flash) are listed (ARNO on Discord: 调用cursor模型报错:AI_APICallError: Cursor: Max Mode Required: The model "gpt-5.6-luna-low" requires Max Mode to be enabled; cursor provider里少了glm-5.3和glm-5.3-flash模型) — the built-in Cursor (deprecated, served by @magpie-community/opencode-cursor-auth once moved; that plugin's 0.1.7, magpie-community/plugins 3ae3e43, carries the same two fixes) asked every model with no max_mode in the Run's ModelDetails (7) or RequestedModel (2), and a model whose picker entry has supportsNonMaxMode false or a variant isMaxMode (gpt-5.6-luna-*) is refused MAX_MODE_REQUIRED, where cursor-agent turns Max Mode on itself. askCursor now asks such a model again with max_mode set in both when Cursor refuses it so, and keeps asking it in Max Mode from then on (cursorMaxOnly). The list came from cursor-agent models (GetUsableModels) alone; Cursor's picker, AiService/AvailableModels, also offers models that list leaves out, so the account's list now adds them (cursorPickerModels: one per variant slug, else the model's name; hidden, Tab-only, chat-only, non-agent ones and the four the CLI drops stay out, and so does a model the list has under any of its slugs), the picker best-effort. TestServeCursorMaxModeRequired (a fake Cursor refusing gpt-5.6-luna-low without Max Mode; it fails without the change) and TestCursorPickerModels (no GLM-5.3 without the change) are new, against fakes; no request was made to Cursor. The mover's min stays 0.1.5 until 0.1.7 is published. 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, TestUserPath and TestFXInState failed once each under load and pass on a rerun).
2026-10-02 22:18:22 +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
0f41570859
cursor: a conversation's Runs keep one conversation_id, so Grok's prompt cache on Cursor sticks, and Cursor's usage no longer counts the cache twice ( #498 , congee949). buildCursorRun put a new UUID in AgentRunRequest's conversation_id (field 5) on every Run, so Cursor's backend had nothing to keep a conversation on the machine holding its cached prefix — the x-grok-conv-id grokSigned sends xAI direct — and a Codex thread on cursor/grok-4.7-fast read about 2% from cache against 94% on the grok provider, its first token growing with the whole prompt. The id is now a UUID (v4-shaped, like the official client's) hashed from what names the session — the client's prompt_cache_key (Codex's thread id), else the agent's own session header (Claude Code's, OpenCode's) — together with the conversation's first user message, which every later request repeats; with neither key nor session header each Run still gets a fresh one, since a first message alone ("hi") would put strangers under one id. On concurrent subagents: Cursor's own client keeps one conversationId per agent session, and whether its backend treats the id as more than a cache-affinity key isn't known, so subagents sharing a session (Claude Code's Task agents share its session id; a Codex collab agent has its own thread and key anyway) get ids of their own through their own first message, never one id sent twice at once. TurnEndedUpdate's input_tokens is the whole prompt, cache read and written included, as Cursor's client has it; decode kept it as Usage.Input, which everywhere else is the uncached rest that prompt() and pricing add the cache to, so a cached turn was counted twice (in=137300 with cache_read=132352 is 4948 uncached). Input is now input_tokens less cache read and write, never below 0, and reasoning_tokens (field 5) is kept as Reasoning. TestCursorConversationID (same Codex key → same id across turns, other key → other id; same Claude Code session → same id, a subagent's first message → another; nothing naming it → a new id each Run), TestCursorUsageTakesTheCacheOut and the updated TestCursorDecodesTheEnd fail without the change. No real Cursor request was made. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./internal/gateway/ ./internal/provider/ pass.
2026-10-02 11:08:14 +08:00
yetone
5200c0a61b
gateway: a Cursor tool call whose arguments aren't whole JSON keeps its place in the history (follow-up to #434 ) — a call's arguments are sent to Cursor as they are, to keep large integers exact; arguments cut short, as the search loop's streamed ones can be, made the whole assistant message fail to marshal and drop out of the history. Arguments that aren't valid JSON are now sent as {} as before #434 . TestCursorTruncatedArgsKeepCall fails without the change.
2026-10-01 23:20:57 +08:00
Charan Rathore
d5645e57ce
gateway: preserve large integers in Cursor tool history ( #434 )
2026-10-01 23:08:24 +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
e9b3c8f2ca
provider: Cursor's per-effort picks become the model with efforts (Leo: Cursor 旧模型清单没有迁移) — a Cursor model list picked before each family was one model still named grok-4.7-low … -xhigh and the -fast ones, so /v1/models and the model lists written for agents (Pi's models.json) kept those ids with no reasoning, and Pi never sent reasoning_effort. Now each saved pick that is one of Cursor's ids at an effort is the family magpie offers for it (grok-4.7, grok-4.7-fast), in the order picked, once; ids of a family of one stay. An agent set to such an id (magpie/cursor/grok-4.7-low) is moved at start-up to the family, spelled its way, and to the effort the id was at when its own is unset and it has that one; a model the picker doesn't offer is left. A request naming one of Cursor's own ids with a reasoning_effort goes at that effort where Cursor has the id (grok-4.7-low at high is grok-4.7-high), else as named; and Chat Completions' service_tier: priority asks for the fast id as Responses' does. Tested with sandbox HOME/cache: legacy picks → grok-4.7|low,medium,xhigh, grok-4.7-fast; a sandbox Pi moved to curs/grok-4.7 at low
2026-09-28 19:59:08 +08:00
yetone
0984edaa03
cursor: the Run goes to the agent API Cursor's server config names for the account — ServerConfigService/GetServerConfig on api2.cursor.sh, whose agentUrlConfig cursor-agent reads to pick agentUrl in privacy mode (which the Run always asks for) and agentnUrl otherwise — asked once a token, kept by the token's hash so another account asks again, asked afresh and the Run tried once more after a region error, and the global agentn.global.api5.cursor.sh while the config can't be had (retried after a minute), as a team served in one region only was turned away by the global API with 'This region is not yet available for your team'; Cursor's errors have words of their own, no longer Devin's: an unauthenticated or expired sign-in says to sign in to Cursor again in magpie, a region or team restriction says so plainly with a 403 and doesn't ask for a sign-in; and Cursor's expanded ids (grok-4.7-low … grok-4.7-xhigh-fast, Claude with and without thinking, gpt-5.5-extra-high) are offered as one model a family, with the efforts it really has, named as Cursor names its default without the effort and holding what the least of its variants holds, fast and thinking families of their own (GPT-5.5 is 1M, GPT-5.5 Fast isn't said to be) and a family of one kept as Cursor's id — the list saved stays Cursor's own, and the gateway turns model and effort (and Codex's Fast) back into the variant at that effort, Cursor's default for one between those it has, else the nearest, while any of Cursor's own ids still goes as it is
2026-09-28 17:14:07 +08:00
yetone
d6c3baa0b8
cursor: served straight through Cursor's agent API, not cursor-agent over ACP — each request is a Run on AgentService, the stream cursor-agent itself opens, with its sign-in (the keychain's or auth.json's token, renewed by cursor-agent near its end): the conversation goes whole as AI SDK messages the server reads as blobs, the caller's tools as MCP tools the model calls through CallDynamicTool, and the reply streams back text, thinking and calls, the Run closed once the step's calls are all made. None of Cursor's own tools run. Tested live from a sandbox: Claude Code and OpenCode on Sonnet 5 and GPT-5.4 mini read and write files through several tool rounds; parallel calls, a continuation and an image answered
2026-09-27 20:41:29 +08:00