ac4af582301a4e8a29245dbba767eba31334ddf9
3
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
abe7b00631 |
gateway: a key+URL provider is sent the agent's own User-Agent by default, through a remote magpie too
nb5p runs a gateway of their own behind magpie and saw nearly every request arrive as "magpie/<version>". The agent's User-Agent now goes on as the agent sent it, wherever magpie isn't itself the client. What each path sends now: - Key+URL providers (official vendor keys and custom OpenAI/Anthropic compatible ones), on chat, Anthropic, Responses, Gemini, count_tokens, embeddings, images and videos: the agent's User-Agent, as sent. Before, this was the opt-in passUserAgent (#1851) and the default was magpie's. The opt-out is magpieUserAgent: `magpie provider set <id> user-agent=magpie`, or untick "Send the agent's own User-Agent" in the editor. passUserAgent is no longer a field, so a file that set it true reads the same as the new default. A provider someone turned back off after opting in can't be told apart from one never touched, and now sends the agent's too. - When the agent sent no User-Agent, and on magpie's own requests (classifier magpie-router/1, vision, search, the image tool, model lists): magpie's, unchanged. - A header.User-Agent the user set: still wins over both. - Subscription accounts (Claude, Codex, Copilot, Google, ZCode…), plugins, and OpenCode/Cline/Kilo: unchanged. Their signing sets the official client's UA (provider.PassesUserAgent still refuses an Account or OwnClient). - Claude Code and Codex header copies: unchanged. - Remote magpie: the near magpie still asks as magpie/<v>, because the far end trusts X-Magpie-Agent/Via only from that. It now adds X-Magpie-User-Agent (passOnUA, on forwardOnce, embeddings, draw and video; the classifier's decision request names none). The far end takes it only from a magpie/ request (callerFrom) and strips it on arrival (withCaller). agentUA/callerUA then hand it to userAgentFor, so the far vendor sees the agent's. A client that writes the header itself, straight to a magpie, is ignored. magpie's own UAs are never relayed (magpiesOwn). Vendor check: invalid-key requests with magpie/, claude-cli, a Chrome UA and pi's went to Anthropic, OpenAI, Gemini, DeepSeek, Moonshot, Kimi For Coding, Zhipu, OpenRouter, xAI, DashScope, MiniMax, Volcengine Ark, Groq and Mistral. Every vendor gave the same auth error for every UA, so no edge-level UA gating was seen. Kimi For Coding's agent allow-list sits behind a valid key, which wasn't tried. Run (mote): - go test -run 'UserAgent|RemoteMagpie|ZCode|Blocked' ./internal/gateway: ok - go test ./internal/provider ./internal/cli ./internal/gui: ok - node --test provider-user-agent, provider-native-compaction and i18n-keys (chromium and webkit; en/zh/zh-TW/ja/de; 900 and 440 wide): 123 of 124 pass. The red is i18n-keys "a plugin's words are its own" (plugins' words said in files this change doesn't touch), already filed as #5327/#5332, #5426 and #5482. - gofmt -l clean; go vet; GOOS=linux -tags nogui and GOOS=windows vet: ok at the rebased head (on |
||
|
|
82f48f0935 |
gateway, provider, gui: a provider set to compact natively is asked Codex's compaction_trigger as sent and its sealed compaction goes back unchanged; a checkpoint stays with its writer (#1099)
A new per-provider option, off by default. With it on, Codex's compaction_trigger reaches the provider as Codex sent it, and the provider's encrypted compaction item goes back to Codex unchanged instead of magpie's magpie1: summary. Off, nothing changes. Where it can be on (provider.CarriesCompaction): a provider with a Responses API (Sub2API and other OpenAI relays, a remote magpie), a ChatGPT (codex) account, and the built-in GitHub Copilot on its GPT Responses path. Copilot's Claude models are asked on chat completions, so they still get magpie's summary (CompactsOn). A group compacts natively only when every member does. No silent downgrade: - A turn carrying a sealed compaction goes only to the key or account that wrote it (compactions.json beside affinity.json, 0600, 1024 entries / 30 days). With none left, Codex gets a 400 saying the conversation was compacted natively on <who>, not a summarised or dropped context. - A provider whose request would have to be translated (not relayed) is refused with a 400 instead of losing the item. - The upstream's own refusal goes back to Codex as it came, one call. - base_instructions and Codex's identity are untouched. Turning it on: - GUI: the provider editor's Compaction row, "Codex compacts on this provider" (shown only where the wire can carry it; zh, zh-TW, ja, de). - CLI: magpie provider set <id> compaction=native|magpie. A provider that can't carry it is refused. Run on origin/main |
||
|
|
248a68598c |
gateway, provider, gui, cli: a key+URL provider may be sent the agent's own User-Agent in place of magpie's (#1851)
Every forward went with User-Agent magpie/<version>. A coding plan that serves only the agents it names (pi, OpenCode, Claude Code…) knows them by their User-Agent, so it turned magpie away. What changed - provider: PassUserAgent (passUserAgent in providers.json), off by default. PassesUserAgent takes it only for a key+URL provider: never a signed-in account, a plugin's, or a vendor whose own client magpie goes as (OwnClient: OpenCode, Cline, Kilo, another magpie). A copy keeps it. - gateway: userAgentFor in forwardOnce (chat, Anthropic, Responses, Gemini, count_tokens) sends the inbound User-Agent unchanged where the provider passes it on. It sends magpie's where it doesn't, where the agent sent none, and on magpie's own requests (magpiesOwn: magpie/…, magpie-router/vision/search, the image tool's "<client> magpie-image/1", which is built from MCP clientInfo, not a User-Agent). magpie never invents another client's. The claude-cli/Codex header copies, the OpenCode/Cline/Kilo overrides and account signing run after it as before, and the user's header.User-Agent is put on at signing, so it wins. - gateway: embeddings, images and videos (retrieveFrom, sendWith, remoteVideoContent) now stamp the same for a key+URL provider through stampUA, from the caller's User-Agent kept on the request ctx (caller.ua, withCaller). Before, they went with Go's default (Go-http-client/1.1). Account and remote-magpie paths are untouched. - cli: `magpie provider set <id> user-agent=agent|magpie`, refused for a signed-in account; `magpie provider <id>` shows it. - gui: the provider editor's User-Agent row, "Send the agent's own User-Agent", with an explanation, for a provider with a key only (the JSON says ownClient for presets and providers); en/zh/zh-TW/ja/de. The TUI only adds presets, so it has no field for this. - docs: reference.md (provider set) and subsystems/gateway-routing.md. What was run - gofmt -l clean; go vet ./... on darwin, GOOS=linux -tags nogui and GOOS=windows. - go test -count=1 ./internal/gateway ./internal/provider ./internal/cli ./internal/gui: all ok (sandbox HOME, private GOCACHE). - TestUserAgentPassedOn covers 7 routes (messages, count_tokens, chat, responses, gemini, embeddings, images) x off / on / on with no UA / on with magpie-router/1 / on with the image tool's UA / the user's header with it on and off. TestUserAgentAccountUntouched: a Factory account with passUserAgent in providers.json is still asked as factory-cli/. Also TestUserAgentClaudeCodeAsBefore, TestUserAgentFor, TestPassesUserAgent, TestAddCopyPassUserAgent, TestProviderUserAgentPair. - Broken by hand, each went red: forwardOnce back to magpie's UA (5 routes red); stampUA removed from embeddings/draw (both red, seen as Go-http-client/1.1); PassesUserAgent ignoring accounts/OwnClient; magpiesOwn dropped (the internal UAs leaked on all 7 routes); the GUI row shown for OpenCode and Save not posting it. - provider-user-agent.test.cjs: 60/60 in chromium and webkit, en, zh, zh-TW, ja, de, at 900 and 440 wide. The provider/editor/add/i18n GUI tests in chromium: 244/244. Not run - Not tried against a real coding plan that checks User-Agent, nor with a real agent through a live gateway. Videos have no test of their own (they go through sendWith, which the images test covers). - The GUI suite was not run in full; the Windows box was not used. |