diff --git a/docs/reference.md b/docs/reference.md index 6a743b0aa..ccde5458b 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -378,18 +378,19 @@ agent's; any other of yours is always sent. The beta of the agent's own sign-in (`oauth-2025-04-20`, which Claude Code signed in to claude.ai asks) never goes, as the sign-in never does; one you set yourself does. -Requests go to a vendor with magpie's own User-Agent (`magpie/`). -A coding plan that serves only the agents it names knows them by theirs: -`magpie provider set user-agent=agent` (the editor's "Send the -agent's own User-Agent") sends a key+URL provider the User-Agent the agent -sent magpie, as it sent it, on every API (chat, Anthropic, Responses, -Gemini, count_tokens, embeddings, images, videos). A request the agent -sent without one, and magpie's own (its classifier's, the image tool's), -still go as magpie. A `header.User-Agent` you set wins over both. -`user-agent=magpie` turns it off again; off is the default. A signed-in -account, a plugin's and a vendor whose own client magpie goes as -(OpenCode, Cline, Kilo, another magpie) keep the User-Agent their sign-in -sends, and don't take it. +A key+URL provider is sent the User-Agent the agent sent magpie, as it +sent it, on every API (chat, Anthropic, Responses, Gemini, count_tokens, +embeddings, images, videos): a coding plan that serves only the agents it +names knows them by it, and a gateway of your own behind magpie sees which +agent asked. Through another computer's magpie (Remote magpie) the vendor +at the far end gets the agent's too. A request the agent sent without one, +and magpie's own (its classifier's, the image tool's, model lists), go with +magpie's (`magpie/`). A `header.User-Agent` you set wins over +both. `magpie provider set user-agent=magpie` (the editor's "Send the +agent's own User-Agent" unticked) sends magpie's in its place; +`user-agent=agent` is the default again. A signed-in account, a plugin's +and a vendor whose own client magpie goes as (OpenCode, Cline, Kilo) keep +the User-Agent their sign-in sends, and don't take it. `magpie usage` (and `--csv`) takes `today`, `7d`, `30d` or `all`, each from a local midnight, or a window ending now: `--last 24h` (any Go duration, `90m`) diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.md index a5752931f..d88e0ba9e 100644 --- a/docs/subsystems/gateway-routing.md +++ b/docs/subsystems/gateway-routing.md @@ -280,7 +280,7 @@ recorded as a prediction failure (`noPrediction`). - A Responses request Codex sends a Responses provider is fitted for a backend that isn't OpenAI's before it goes (`passthrough`): Responses Lite's shape taken off (`fromLite`): its `additional_tools` item lifted into `tools` (`liftAdditionalTools`, #350), its `reasoning.context` left out, its Lite marker removed from `client_metadata` (`withoutLiteMetadata`), and its `X-OpenAI-Internal-Codex-Responses-Lite` header not sent on (`liteKept`). A Codex websocket turn repeats the marker in `client_metadata`; leaving it beside a removed `reasoning.context` made a downstream Responses relay forward an inconsistent Lite request, which its ChatGPT backend refused with "requires `reasoning.context` to be `all_turns`". A subagent a Lite lead (gpt-6.1-sol) spawns on another model comes in that shape, its model name alone changed, and OpenCode Go's DeepSeek answered it 503 "Endpoint is unavailable" (TangForX on X, `TestLiteSubagentLeavesLite`). Also the tool search as a function, OpenAI-only fields left out. A relay that checks a request is Codex's own turns that shape away (#1758: 400 "Codex 客户端请求特征无效", 10014). A provider set `codexAsSent` (`magpie provider set codex=as-sent`) gets a request from Codex (`fromCodex`) as Codex sent it, its model name alone swapped, with Codex's own headers (`codexClientHeader`). That holds when Codex offers `web_search` too: the request is relayed with it, not translated for magpie's search (`searchedForIt`), which merged the developer messages into `instructions`, sent `apply_patch` as a function, left `web_search` out and added `max_output_tokens` (`codexAsSent` in `route`; maralica on Discord). `spawn_agent`'s description is still widened with the catalog's models (`spawnAgentModels`). Off is the default, and a subscription account is never sent so. `TestCodexAsSent`, `TestCodexAsSentWebSearch`, `TestFromLiteRemovesOnlyTheWebsocketLiteMarker`, `TestCodexTitleRelayKeepsLiteShapeConsistent`. - A tool a Chat request's message carries joins the request's `tools` (`liftMessageTools` in [`message_tools.go`](../../internal/gateway/message_tools.go), #2322). Pi with `supportsMidConvoToolAdditions` gives a tool it adds mid-conversation as `{"role":"system","tools":[…]}` with no content, and keeps top-level `tools` as they were at the start; no Chat API reads tools there, and `parseChat` read only the top-level ones, so the tool could be called on no route. `handle` lifts them for every Chat body before `serveAgent`, so the Chat relay, the schema fixers, redaction (the tool is a tool definition, not message text), the prompt shown and routing all see them; `parseChat` lifts too, for a body that never came through `handle` (the Claude subscription bridge's direct callers). Each tool joins once by name and the first definition wins: a top-level tool keeps its own, then the earliest message's, as `liftAdditionalTools` and a `tool_addition` (`withoutDeferredTools`) do. A system or developer message that carried only tools is left out, so it is neither relayed as an empty system message nor joined into the system text as an empty part; one with content keeps its place without `tools`. Messages stay where they are: the in-place system message the issue also asks for is not this change. `TestPiAddedToolReachesEveryRoute` sends deephbz's Pi 1.2.0 bytes through the Chat relay, Messages, Responses, Gemini and Codex, and `TestPiAddedToolOfferedToClaudeCode` through the Claude subscription bridge. - A Chat request's tool in another API's shape is put in the Chat shape, `{"type":"function","function":{name, description, parameters, strict}}` (`shapeChatTools` in [`chat_tool_shape.go`](../../internal/gateway/chat_tool_shape.go), #2622, jinyue806): MCP's `{"name","description","inputSchema"}` (ZCode), Anthropic's `input_schema`, a bare `{"name","parameters"}` and Responses' flat `{"type":"function","name",…}`. No Chat API takes those (SenseNova: "field Tools[0].Type invalid, should be set" and "function cannot be empty"), and `parseChat` read no name from them, so a translated request offered a tool named "". It runs right after `liftMessageTools`, in `handle` for every Chat body and in `parseChat`, so it holds for every Chat upstream, not SenseNova's alone. A tool with its `function`, a hosted tool (any other `type`) and one with no name are left as they came, and a request with none to shape is relayed byte for byte. `TestChatToolInAnotherShapeIsShaped` sends the report's request with each of its four tools through the Chat relay, Messages and Responses; `TestShapeChatToolsLeavesChatShape`. -- Every request to a key+URL provider goes with magpie's User-Agent (`magpie/`, `userAgentFor` in [`user_agent.go`](../../internal/gateway/user_agent.go)), except a provider set `passUserAgent` (#1851, `magpie provider set user-agent=agent`, the editor's "Send the agent's own User-Agent"): it gets the User-Agent the inbound request carried, unchanged, for a coding plan that serves only the agents it names. One the agent didn't send, and magpie's own (`magpiesOwn`: another magpie's `magpie/…`, `magpie-router/1`, `magpie-vision/1`, `magpie-search/1`, and the image tool's ` magpie-image/1`, built from MCP's clientInfo, or behind the MCP router from the first word of the agent's User-Agent), go as magpie; magpie never makes up another client's. `forwardOnce` sets it for chat, Anthropic, Responses, Gemini and count_tokens; embeddings, images and videos (`retrieveFrom`, `sendWith`, `remoteVideoContent`) set it with `stampUA` from the caller the request came with (`caller.ua`, `withCaller`), and before #1851 went with Go's default. Claude Code's and Codex's own headers are copied after, as before, and the user's `header.User-Agent` is put on when the request is signed, so it wins. `provider.PassesUserAgent` refuses it for a signed-in account, a plugin's, and a vendor whose own client magpie goes as (`OwnClient`: OpenCode, Cline, Kilo, another magpie); their signing sets their own. `TestUserAgentPassedOn`, `TestUserAgentAccountUntouched`, `TestUserAgentFor`, `TestPassesUserAgent`, `provider-user-agent.test.cjs`. +- Every request to a key+URL provider goes with the User-Agent the inbound request carried, unchanged (`userAgentFor` in [`user_agent.go`](../../internal/gateway/user_agent.go), #1851, nb5p on Discord): a coding plan that serves only the agents it names knows them by it, and a gateway of the user's own behind magpie sees which agent asked. It was once the opt-in `passUserAgent`; a file that still says it reads the same as the default now. A provider set `magpieUserAgent` (`magpie provider set user-agent=magpie`, the editor's "Send the agent's own User-Agent" unticked) goes with magpie's (`magpie/`) in its place. One the agent didn't send, and magpie's own (`magpiesOwn`: another magpie's `magpie/…`, `magpie-router/1`, `magpie-vision/1`, `magpie-search/1`, and the image tool's ` magpie-image/1`, built from MCP's clientInfo, or behind the MCP router from the first word of the agent's User-Agent), go as magpie; magpie never makes up another client's. `forwardOnce` sets it for chat, Anthropic, Responses, Gemini and count_tokens; embeddings, images and videos (`retrieveFrom`, `sendWith`, `remoteVideoContent`) set it with `stampUA` from the caller the request came with (`caller.ua`, `withCaller`), and before #1851 went with Go's default. Claude Code's and Codex's own headers are copied after, as before, and the user's `header.User-Agent` is put on when the request is signed, so it wins. `provider.PassesUserAgent` refuses it for a signed-in account, a plugin's, and a vendor whose own client magpie goes as (`OwnClient`: OpenCode, Cline, Kilo, another magpie); their signing sets their own. To another magpie the request still goes as `magpie/` (its attribution headers are trusted only from that), with the agent's User-Agent in `X-Magpie-User-Agent` (`ClientUAHeader`, `passOnUA`, on every route: forwardOnce, embeddings, images, videos; the classifier's decision request names none). The far magpie takes it only from a `magpie/` request (`callerFrom`, as `caller.ua`, `relayed`), takes it off what comes in (`withCaller`), and `agentUA` hands it to `userAgentFor` in place of the near magpie's, so the far vendor is sent the agent's; a client that writes the header itself is sent as it is. `TestUserAgentPassedOn`, `TestUserAgentAccountUntouched`, `TestUserAgentFor`, `TestPassesUserAgent`, `TestRemoteMagpieRelaysUserAgent`, `provider-user-agent.test.cjs`. - A Chat upstream that wants a turn's reasoning back (`chatReplaysReasoning` in [`chat.go`](../../internal/gateway/chat.go): a host or a model, as magpie or the provider names it, with `deepseek` in it, such as OpenCode Go's `deepseek-v4.1-flash`, or Command Code's plugin) gets every assistant tool call with `reasoning_content`, relayed (`withReasoningOnToolTurns` in `passthrough`) or translated (`buildChat`). DeepSeek turns the whole request away ("The `reasoning_content` in the thinking mode must be passed back to the API") when a tool call made since the user's last message has none, which a client sends for a turn it saw no thinking on: another model's, a translated one (#1462). The turn's own thinking goes back as it came; one sent in `reasoning` or `reasoning_details` is copied in, and `reasoning` is then left out (`asReasoningContent`): a self-hosted DeepSeek server reads the two as one field and refused pi's tool turn, which carried its thinking in `reasoning`, as "duplicate field reasoning" (ArvinCharl on X, v0.1.1560), while `reasoning_details`, a list of typed entries that can hold an encrypted one, stays; otherwise it goes with a space (`noReasoning`: DeepSeek's Chat API takes an empty one, but a relay that leaves empty fields out would drop it). An assistant message right after a tool result, a reply with no call of its own, gets one too: DeepSeek refuses it the same way (checked 2026-10-12, #1822). A reply to the user, any other model and Mistral (#494) are sent as before. - A message content that is a list of plain text parts (`[{"type":"text","text":…}]`, nothing else in a part) is relayed to a Chat upstream as the string it says, the parts joined by a newline (`textPartsAsString` in [`chat_text_parts.go`](../../internal/gateway/chat_text_parts.go), in `passthrough` before `silentAssistantsOut`). OpenAI takes either, but a vendor's own server may take a string alone: the Intern discovery API (a custom provider on OpenAI compatible, Atria-Dawn, Discord) answered DeepSeek Harness, whose pi-ai sends every user message as such a list, 422 with an "Input should be a valid string" per message. A list with an image, a file, a thinking part or a `cache_control` mark stays a list, and every other byte of the body stays as sent; `buildChat` already writes text as a string. `TestChatRelayTextPartsAsString`, `TestTextPartsAsStringOnlyPlainText`. - An assistant turn the user cut off before it said anything (only its thinking, an empty text, nothing; an isolated Codex reasoning item; a Gemini thought alone) stays in the agent's history and is sent on every later turn. DeepSeek and Kimi turn the whole request away over an assistant message with neither content nor tool calls, `reasoning_content` alone included ("Invalid assistant message: content or tool_calls must be set", #2599). Every Chat upstream gets such a turn left out, translated (`buildChat`, before `pairToolMessages`) or relayed (`silentAssistantsOut` in `passthrough`), by one rule (`withoutSilentAssistants` in [`chat.go`](../../internal/gateway/chat.go)): the two user messages it stood between join into one, and after a tool result the user's message follows the tool message. A prefill to go on from (`prefix`, `partial`, a Resume), a legacy `function_call`, a refusal and an audio reply stay, and a relayed body without such a turn goes byte for byte. `TestChatEmptyAssistantLeftOutFromAnthropic`, `…FromResponses`, `…FromGemini`, `TestChatRelayLeavesOutEmptyAssistant`, `TestChatRelaySilentAssistantsOnly`. @@ -750,7 +750,9 @@ audio or SSE, is copied to the client as it comes (`retrieveOpen`, to the remote's images API, and [`video.go`](../../internal/gateway/video.go) wraps remote task ids for later polls and downloads. `passOnCaller` in [`remote_magpie.go`](../../internal/gateway/remote_magpie.go) supplies -caller/session headers without replacing the outgoing User-Agent. +caller/session headers without replacing the outgoing User-Agent, and +`passOnUA` the agent's own User-Agent in `X-Magpie-User-Agent`, which the +remote sends its key+URL providers in place of magpie's. Conversation forwarding preserves Claude Code and Codex client headers (including Codex's `originator`) so relays behind the remote can recognize them. Decision, retrieval and media requests set magpie's User-Agent at @@ -815,7 +817,7 @@ with (`Drawers`) and leaves the video makers, and one marked a video model leaves the drawers; only a provider set up with a base URL can be marked (`MarksKinds`). Start, poll and content go to `videoBase` (its Chat base, else its Responses base) `+ /videos`, with -magpie's User-Agent (or the agent's, `passUserAgent`) and no caller headers. Its ids end with the key's +the agent's User-Agent (magpie's when set `magpieUserAgent` or the agent sent none) and no caller headers. Its ids end with the key's fingerprint (`customVideoID`, `markedKey`), so a poll and its download go on the key that started the video. A gateway key's account and model holds apply to all three routes (`videoAsker`, `videoModelHeld`), and to Grok's diff --git a/internal/cli/providers_cli.go b/internal/cli/providers_cli.go index 03a4248b7..78c122064 100644 --- a/internal/cli/providers_cli.go +++ b/internal/cli/providers_cli.go @@ -38,9 +38,8 @@ const providerUsage = `usage: magpie provider set k=v… change a provider's settings, with the same k=v pairs as add; codex=as-sent sends Codex's Responses requests as Codex sent them (a relay that checks they are Codex's own), codex=default fits them; - user-agent=agent sends the User-Agent the agent gave (pi, opencode…) - in place of magpie's, for a plan that serves only agents it names; - user-agent=magpie, the default, sends magpie's; + user-agent=agent, the default, sends the User-Agent the agent gave + (pi, opencode…); user-agent=magpie sends magpie's in its place; compaction=native asks the provider Codex's own compaction and hands Codex its sealed item as it came (a Responses API, a ChatGPT account, Copilot), compaction=magpie, the default, has magpie summarise @@ -869,12 +868,8 @@ func showProvider(p provider.Provider) error { if p.PassesErrors() { kv("errors", "pass"+muted.Render(" sent to the agent as the vendor sent them, asked once")) } - if p.PassUserAgent { - why := " the User-Agent the agent gave, not magpie's" - if !p.PassesUserAgent() { - why = " but magpie's: it goes as a client of " + p.Name + "'s own" - } - kv("user-agent", "agent's"+muted.Render(why)) + if p.MagpieUserAgent { + kv("user-agent", "magpie's"+muted.Render(" not the one the agent gave")) } if p.Unredacted { why := " Settings' redaction leaves its requests as written" @@ -1218,9 +1213,8 @@ func applyPairs(p *provider.Provider, pairs []string) error { } p.PassErrors = on case "user-agent", "ua": - // agent: a request goes with the User-Agent the agent that - // sent it gave, for a coding plan that serves only agents it - // names (#1851); magpie: magpie's own, as by default. A + // agent, the default: a request goes with the User-Agent the + // agent that sent it gave (#1851); magpie: magpie's own. A // header.User-Agent the user set stands over both var on bool switch strings.ToLower(v) { @@ -1233,7 +1227,8 @@ func applyPairs(p *provider.Provider, pairs []string) error { if on && p.Account != nil { return fmt.Errorf("%s signs in as its own client, which sends the User-Agent it does; user-agent= is for a provider with an API key", p.Name) } - p.PassUserAgent = on + // an account goes as its own client either way + p.MagpieUserAgent = !on && p.Account == nil case "search": // yes: the vendor searches the web by itself, a web search a // client offers going to it as it was sent (a relay in front of diff --git a/internal/cli/providers_user_agent_cli_test.go b/internal/cli/providers_user_agent_cli_test.go index 7a5e9b125..fc030a3d0 100644 --- a/internal/cli/providers_user_agent_cli_test.go +++ b/internal/cli/providers_user_agent_cli_test.go @@ -7,26 +7,27 @@ import ( "github.com/yetone/magpie/internal/provider" ) -// user-agent=agent has a key+URL provider pass the agent's User-Agent on -// (#1851), user-agent=magpie goes back to magpie's, and a signed-in -// account, which goes as its own client, is refused it. +// A key+URL provider passes the agent's User-Agent on by default (#1851, +// nb5p on Discord): user-agent=magpie sends magpie's in its place, +// user-agent=agent goes back to the default, and a signed-in account, which +// goes as its own client, is refused agent. func TestProviderUserAgentPair(t *testing.T) { p := provider.Provider{ID: "plan", Name: "Plan", Chat: "https://plan.example/v1", Key: "k"} - if err := applyPairs(&p, []string{"user-agent=agent"}); err != nil || !p.PassUserAgent { - t.Fatalf("agent: %v %v", p.PassUserAgent, err) + if err := applyPairs(&p, []string{"user-agent=magpie"}); err != nil || !p.MagpieUserAgent || p.PassesUserAgent() { + t.Fatalf("magpie: %v %v", p.MagpieUserAgent, err) } - if err := applyPairs(&p, []string{"user-agent=magpie"}); err != nil || p.PassUserAgent { - t.Fatalf("magpie: %v %v", p.PassUserAgent, err) + if err := applyPairs(&p, []string{"user-agent=agent"}); err != nil || p.MagpieUserAgent || !p.PassesUserAgent() { + t.Fatalf("agent: %v %v", p.MagpieUserAgent, err) } if err := applyPairs(&p, []string{"user-agent=claude"}); err == nil || !strings.Contains(err.Error(), "agent|magpie") { t.Fatalf("a made-up value: %v", err) } a := provider.Provider{ID: "zcode", Name: "ZCode", Account: &provider.Account{Agent: "zcode"}} - if err := applyPairs(&a, []string{"user-agent=agent"}); err == nil || a.PassUserAgent { + if err := applyPairs(&a, []string{"user-agent=agent"}); err == nil || a.MagpieUserAgent { t.Fatalf("an account took it: %v", err) } - if err := applyPairs(&a, []string{"user-agent=magpie"}); err != nil { - t.Fatalf("an account turning it off: %v", err) + if err := applyPairs(&a, []string{"user-agent=magpie"}); err != nil || a.MagpieUserAgent { + t.Fatalf("an account turning it off: %v %v", a.MagpieUserAgent, err) } } diff --git a/internal/gateway/draw.go b/internal/gateway/draw.go index d083a3ae1..8b808bc0d 100644 --- a/internal/gateway/draw.go +++ b/internal/gateway/draw.go @@ -1393,6 +1393,7 @@ func (s *Server) sendWith(ctx context.Context, p provider.Provider, method, url, if p.IsRemoteMagpie() { req.Header.Set("User-Agent", "magpie/"+Version) passOnCaller(ctx, req) + passOnUA(req, callerUA(ctx)) } if sign { if err := p.Sign(ctx, req, provider.Chat, body); err != nil { diff --git a/internal/gateway/embeddings.go b/internal/gateway/embeddings.go index cd5faaf52..0d51708da 100644 --- a/internal/gateway/embeddings.go +++ b/internal/gateway/embeddings.go @@ -430,6 +430,7 @@ func (s *Server) retrieveOpen(ctx context.Context, p provider.Provider, url, cty if p.IsRemoteMagpie() { req.Header.Set("User-Agent", "magpie/"+Version) passOnCaller(ctx, req) + passOnUA(req, callerUA(ctx)) } if err := p.Sign(ctx, req, provider.Chat, body); err != nil { return nil, nil, "", 502, err diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go index db8dcc00f..1c7eb0305 100644 --- a/internal/gateway/gateway.go +++ b/internal/gateway/gateway.go @@ -5684,11 +5684,12 @@ func (s *Server) forwardOnce(ctx context.Context, p provider.Provider, to provid defer provider.LetGo(req) req.Header.Set("Content-Type", "application/json") req.Header.Set("Accept", "application/json, text/event-stream") - // magpie's, or the agent's own where the provider is set to pass it - // on (#1851); a signed-in account's signing, a client the vendor - // serves (OpenCode's, Cline's, Kilo's) and the user's own header put - // theirs on after - req.Header.Set("User-Agent", userAgentFor(p, in.Get("User-Agent"))) + // the agent's own where the provider passes it on, else magpie's + // (#1851); a signed-in account's signing, a client the vendor serves + // (OpenCode's, Cline's, Kilo's) and the user's own header put theirs + // on after + ua := agentUA(ctx, in) + req.Header.Set("User-Agent", userAgentFor(p, ua)) if to == provider.Anthropic { req.Header.Set("anthropic-version", "2023-06-01") for _, h := range []string{"anthropic-version", "anthropic-beta"} { @@ -5812,6 +5813,7 @@ func (s *Server) forwardOnce(ctx context.Context, p provider.Provider, to provid } if p.IsRemoteMagpie() { passOnCaller(ctx, req) + passOnUA(req, ua) markSearching(ctx, req) } if err := p.Sign(ctx, req, to, body); err != nil { diff --git a/internal/gateway/remote_magpie.go b/internal/gateway/remote_magpie.go index 89f0da49f..110900e08 100644 --- a/internal/gateway/remote_magpie.go +++ b/internal/gateway/remote_magpie.go @@ -36,6 +36,11 @@ const ( // round and round, masked again on each pass: one passed on through // catalog.MaxVia magpies is answered 508 Loop Detected instead. HopsHeader = "X-Magpie-Hops" + // ClientUAHeader is the User-Agent the agent sent, on a request + // passed on to a remote magpie as magpie's own: that magpie sends its + // key+URL providers the agent's, as this one would have (nb5p on + // Discord). Taken, like AgentHeader, only from a magpie's request. + ClientUAHeader = "X-Magpie-User-Agent" ) // caller is who a request is recorded as: its agent, and the computer it @@ -51,8 +56,10 @@ type caller struct { // session so the other magpie records the call as one (#2505) compact string // ua is the User-Agent the request came with, as it came: the one a - // provider that passes the agent's on is sent (userAgentFor) - ua string + // provider that passes the agent's on is sent (userAgentFor). From + // another magpie, the agent's it named (ClientUAHeader), relayed true. + ua string + relayed bool // keepTurn: another magpie asked that its Responses turn be kept // though it says store false (KeepTurnHeader, remote_delta.go) keepTurn bool @@ -82,6 +89,7 @@ func withCaller(next http.Handler) http.Handler { r.Header.Del(SearchingHeader) r.Header.Del(KeepTurnHeader) r.Header.Del(HopsHeader) + r.Header.Del(ClientUAHeader) next.ServeHTTP(w, r.WithContext(ctx)) }) } @@ -108,6 +116,9 @@ func callerFrom(r *http.Request) caller { if n, err := strconv.Atoi(strings.TrimSpace(r.Header.Get(HopsHeader))); err == nil && n > 0 { c.hops = min(n, 1<<20) } + if v := r.Header.Get(ClientUAHeader); v != "" && len(v) <= 1024 && !magpiesOwn(v) { + c.ua, c.relayed = v, true + } if a := label(r.Header.Get(AgentHeader)); a != "" { c.agent = usage.AgentOf(a) c.via = label(r.Header.Get(ViaHeader)) diff --git a/internal/gateway/user_agent.go b/internal/gateway/user_agent.go index 3f8dda637..e55ed1206 100644 --- a/internal/gateway/user_agent.go +++ b/internal/gateway/user_agent.go @@ -13,8 +13,9 @@ func magpieUA() string { return "magpie/" + Version } // userAgentFor is the User-Agent a request to p goes with, ua being the // one the request came to magpie with: the agent's own, as it sent it, -// where p is set to pass it on (provider.PassesUserAgent, #1851), and -// magpie's where it isn't, where the agent sent none, and on magpie's own +// where p passes it on (provider.PassesUserAgent: a key+URL provider not +// set to go as magpie, #1851), and magpie's where it doesn't, where the +// agent sent none, and on magpie's own // requests — its classifier's, vision's, search's, the image tool's // (magpiesOwn) — which no agent sent. A User-Agent the user set among the // provider's headers is put on after, when the request is signed, and @@ -36,7 +37,7 @@ func magpiesOwn(ua string) bool { } // callerUA is the User-Agent the request ctx is for came with (withCaller), -// "" when there is none. +// or the agent's another magpie passed it on for; "" when there is none. func callerUA(ctx context.Context) string { c, _ := ctx.Value(callerCtx{}).(caller) return c.ua @@ -53,3 +54,26 @@ func stampUA(ctx context.Context, p provider.Provider, h http.Header) { } h.Set("User-Agent", userAgentFor(p, callerUA(ctx))) } + +// agentUA is the User-Agent of the agent a request with headers in is +// for: the one it came with, or, from another magpie (magpie/…), the +// agent's that magpie named (ClientUAHeader). magpie's own requests made +// here (magpie-router/1, …) keep theirs. +func agentUA(ctx context.Context, in http.Header) string { + ua := in.Get("User-Agent") + if c, ok := ctx.Value(callerCtx{}).(caller); ok && c.relayed && strings.HasPrefix(ua, "magpie/") { + return c.ua + } + return ua +} + +// passOnUA names, on a request to a remote magpie, the agent's User-Agent +// ua, for that magpie to send on as this one would; magpie's own is +// never named, and a vendor is never sent the header (withCaller takes +// it off what comes in). +func passOnUA(req *http.Request, ua string) { + req.Header.Del(ClientUAHeader) + if ua != "" && !magpiesOwn(ua) { + req.Header.Set(ClientUAHeader, ua) + } +} diff --git a/internal/gateway/user_agent_test.go b/internal/gateway/user_agent_test.go index 3a88c98e7..f49620d06 100644 --- a/internal/gateway/user_agent_test.go +++ b/internal/gateway/user_agent_test.go @@ -17,14 +17,18 @@ import ( // keeps the User-Agent each path was asked with, and answers each as its // API does. type uaVendor struct { - mu sync.Mutex - got map[string]string + mu sync.Mutex + got map[string]string + leaked []string // magpie's ClientUAHeader, which no vendor is sent } func (v *uaVendor) ServeHTTP(w http.ResponseWriter, r *http.Request) { io.Copy(io.Discard, r.Body) v.mu.Lock() v.got[r.URL.Path] = r.Header.Get("User-Agent") + if h := r.Header.Get(ClientUAHeader); h != "" { + v.leaked = append(v.leaked, r.URL.Path+": "+h) + } v.mu.Unlock() w.Header().Set("Content-Type", "application/json") switch p := r.URL.Path; { @@ -69,7 +73,8 @@ var uaRoutes = []struct{ name, path, body, upstream string }{ } // uaSetup saves a key+URL provider "ua" on every API, at a uaVendor, with -// pass for its PassUserAgent and headers for the user's own, and "ug" the +// pass for whether it sends the agent's User-Agent (MagpieUserAgent off, +// the default) and headers for the user's own, and "ug" the // same on Gemini's API alone. func uaSetup(t *testing.T, pass bool, headers map[string]string) *uaVendor { t.Helper() @@ -78,7 +83,7 @@ func uaSetup(t *testing.T, pass bool, headers map[string]string) *uaVendor { up := httptest.NewServer(v) t.Cleanup(up.Close) p := provider.Provider{ID: "ua", Name: "UA", Key: "k", Chat: up.URL + "/v1", Responses: up.URL + "/v1", Anthropic: up.URL, Gemini: up.URL + "/v1beta", - Models: []string{"m1", "embed-1", "gpt-image-1"}, PassUserAgent: pass, Headers: headers} + Models: []string{"m1", "embed-1", "gpt-image-1"}, MagpieUserAgent: !pass, Headers: headers} if err := provider.Save(p); err != nil { t.Fatal(err) } @@ -86,7 +91,7 @@ func uaSetup(t *testing.T, pass bool, headers map[string]string) *uaVendor { t.Fatal(err) } // Gemini's own wire, which a provider on Chat too isn't asked on - g := provider.Provider{ID: "ug", Name: "UG", Key: "k", Gemini: up.URL + "/v1beta", Models: []string{"m1"}, PassUserAgent: pass, Headers: headers} + g := provider.Provider{ID: "ug", Name: "UG", Key: "k", Gemini: up.URL + "/v1beta", Models: []string{"m1"}, MagpieUserAgent: !pass, Headers: headers} if err := provider.Save(g); err != nil { t.Fatal(err) } @@ -110,10 +115,11 @@ func askAs(t *testing.T, s *Server, path, body, ua string) { } } -// A key+URL provider set to pass the agent's User-Agent on (#1851) is -// asked with the one the agent sent, on every route that reaches it: a -// coding plan that serves only agents it names knows them by it. Off, the -// default, it is asked as magpie; so it is when the agent sent none, and +// A key+URL provider is asked with the User-Agent the agent sent (#1851, +// nb5p on Discord), on every route that reaches it: a coding plan that +// serves only agents it names knows them by it, and a gateway of the +// user's own behind magpie sees which agent asked. Set to go as magpie, it +// is asked as magpie; so it is when the agent sent none, and // on magpie's own requests (its classifier's, the image tool's), which no // agent sent. A User-Agent the user set in the provider's headers stands // over both. @@ -127,13 +133,13 @@ func TestUserAgentPassedOn(t *testing.T) { ua string // what the agent sent want string }{ - {"off", false, nil, pi, magpie}, - {"on", true, nil, pi, pi}, - {"on, the agent sent none", true, nil, "", magpie}, - {"on, magpie's classifier", true, nil, RouterAgent, magpie}, - {"on, magpie's image tool", true, nil, "claude-code/2.1.0 " + DrawAgent, magpie}, - {"on, the user's own header", true, map[string]string{"User-Agent": "mine/1"}, pi, "mine/1"}, - {"off, the user's own header", false, map[string]string{"User-Agent": "mine/1"}, pi, "mine/1"}, + {"as magpie", false, nil, pi, magpie}, + {"default", true, nil, pi, pi}, + {"default, the agent sent none", true, nil, "", magpie}, + {"default, magpie's classifier", true, nil, RouterAgent, magpie}, + {"default, magpie's image tool", true, nil, "claude-code/2.1.0 " + DrawAgent, magpie}, + {"default, the user's own header", true, map[string]string{"User-Agent": "mine/1"}, pi, "mine/1"}, + {"as magpie, the user's own header", false, map[string]string{"User-Agent": "mine/1"}, pi, "mine/1"}, } { t.Run(tt.name, func(t *testing.T) { v := uaSetup(t, tt.pass, tt.headers) @@ -166,7 +172,8 @@ func TestUserAgentClaudeCodeAsBefore(t *testing.T) { } } -// Which providers pass it on: a key+URL one set to, and not a signed-in +// Which providers pass it on: a key+URL one unless set to go as magpie, and +// not a signed-in // account (ZCode's Coding Plan signs without a User-Agent of its own, and // goes as magpie), a plugin's, a vendor's own client's gateway (OpenCode, // Cline, Kilo) or another magpie, each of which goes as the client it @@ -179,13 +186,13 @@ func TestUserAgentFor(t *testing.T) { p provider.Provider want string }{ - {"key", provider.Provider{Chat: "https://api.example.com/v1", PassUserAgent: true}, pi}, - {"key, off", provider.Provider{Chat: "https://api.example.com/v1"}, magpie}, - {"account", provider.Provider{Chat: "https://api.z.ai/api/coding/paas/v4", PassUserAgent: true, Account: &provider.Account{Agent: "zcode"}}, magpie}, - {"opencode", provider.Provider{Chat: "https://opencode.ai/zen/v1", PassUserAgent: true}, magpie}, - {"cline", provider.Provider{Preset: "clinepass", Chat: "https://api.cline.bot/api/v1", PassUserAgent: true}, magpie}, - {"kilo", provider.Provider{Preset: "kilo", Chat: "https://api.kilo.ai/api/gateway", PassUserAgent: true}, magpie}, - {"remote magpie", provider.Provider{Preset: provider.RemoteMagpiePreset, Chat: "http://10.0.0.2:3425/v1", PassUserAgent: true}, magpie}, + {"key", provider.Provider{Chat: "https://api.example.com/v1"}, pi}, + {"key, as magpie", provider.Provider{Chat: "https://api.example.com/v1", MagpieUserAgent: true}, magpie}, + {"account", provider.Provider{Chat: "https://api.z.ai/api/coding/paas/v4", Account: &provider.Account{Agent: "zcode"}}, magpie}, + {"opencode", provider.Provider{Chat: "https://opencode.ai/zen/v1"}, magpie}, + {"cline", provider.Provider{Preset: "clinepass", Chat: "https://api.cline.bot/api/v1"}, magpie}, + {"kilo", provider.Provider{Preset: "kilo", Chat: "https://api.kilo.ai/api/gateway"}, magpie}, + {"remote magpie", provider.Provider{Preset: provider.RemoteMagpiePreset, Chat: "http://10.0.0.2:3425/v1"}, magpie}, } { if got := userAgentFor(tt.p, pi); got != tt.want { t.Errorf("%s: %q, want %q", tt.name, got, tt.want) @@ -194,8 +201,55 @@ func TestUserAgentFor(t *testing.T) { // an account's own request headers are its signing's: stampUA leaves // them as they are h := http.Header{} - stampUA(t.Context(), provider.Provider{PassUserAgent: true, Account: &provider.Account{Agent: "zcode"}}, h) + stampUA(t.Context(), provider.Provider{Account: &provider.Account{Agent: "zcode"}}, h) if h.Get("User-Agent") != "" { t.Errorf("an account's request was stamped %q", h.Get("User-Agent")) } } + +// Through another computer's magpie (a Remote magpie provider), the vendor +// at the far end is asked with the agent's User-Agent too, not the near +// magpie's (nb5p on Discord): the near one hands it over in a header of +// magpie's own, which the far one takes only from a magpie, and which no +// vendor is sent. An agent that writes that header itself is asked as it +// is. +func TestRemoteMagpieRelaysUserAgent(t *testing.T) { + const pi = "pi-coding-agent/0.9.1 (darwin; arm64)" + v := uaSetup(t, true, nil) + far := httptest.NewServer(New().Handler()) + t.Cleanup(far.Close) + id, err := provider.Add(provider.Provider{ID: "office", Name: "Office", Preset: provider.RemoteMagpiePreset, Chat: strings.TrimPrefix(far.URL, "http://")}) + if err != nil { + t.Fatal(err) + } + office, _ := provider.Find(id) + if _, err := office.Fetch(t.Context()); err != nil { + t.Fatal(err) + } + s := New() + for _, r := range uaRoutes { + if r.name == "gemini" { + continue + } + body := strings.Replace(r.body, `"ua/`, `"`+id+`/ua/`, 1) + askAs(t, s, r.path, body, pi) + if got, ok := v.sent(r.upstream); !ok || got != pi { + t.Errorf("%s: the far vendor was asked as %q (asked: %v), want the agent's", r.name, got, ok) + } + } + // an agent that sets magpie's header itself, straight to the far one + rec := httptest.NewRecorder() + req := httptest.NewRequest("POST", far.URL+"/v1/chat/completions", strings.NewReader(uaRoutes[2].body)) + req.Header.Set("Content-Type", "application/json") + req.Header.Set("User-Agent", "curl/8.0") + req.Header.Set(ClientUAHeader, pi) + s.Handler().ServeHTTP(rec, req) + if got, _ := v.sent("/v1/chat/completions"); rec.Code != 200 || got != "curl/8.0" { + t.Errorf("a client's own %s was taken: %d, asked as %q", ClientUAHeader, rec.Code, got) + } + v.mu.Lock() + defer v.mu.Unlock() + if len(v.leaked) > 0 { + t.Errorf("a vendor was sent %s: %v", ClientUAHeader, v.leaked) + } +} diff --git a/internal/gateway/video.go b/internal/gateway/video.go index 1373d2939..8aa25f568 100644 --- a/internal/gateway/video.go +++ b/internal/gateway/video.go @@ -1535,6 +1535,7 @@ func (s *Server) remoteVideoContent(ctx context.Context, w http.ResponseWriter, // vendors are told no caller req.Header.Set("User-Agent", "magpie/"+Version) passOnCaller(ctx, req) + passOnUA(req, callerUA(ctx)) } if err := p.Sign(ctx, req, provider.Chat, nil); err != nil { writeError(w, provider.Chat, 502, err.Error()) diff --git a/internal/gateway/zcode_blocked_test.go b/internal/gateway/zcode_blocked_test.go index 308aa42f1..e96899963 100644 --- a/internal/gateway/zcode_blocked_test.go +++ b/internal/gateway/zcode_blocked_test.go @@ -225,7 +225,7 @@ func TestChatRelayRefusalSaysWhy(t *testing.T) { io.WriteString(w, c.body) })) t.Cleanup(relay.Close) - if err := provider.Save(provider.Provider{ID: "magpie-grok", Name: "magpie-grok", Key: "k", Models: []string{"grok-4.7"}, Chat: relay.URL + "/v1", PassUserAgent: true}); err != nil { + if err := provider.Save(provider.Provider{ID: "magpie-grok", Name: "magpie-grok", Key: "k", Models: []string{"grok-4.7"}, Chat: relay.URL + "/v1"}); err != nil { t.Fatal(err) } if err := provider.SaveGroup(provider.Group{Name: "G", Members: []string{"magpie-grok/grok-4.7"}, Routing: provider.Ordered}); err != nil { diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index c02d9e328..c0f628da2 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -7989,7 +7989,7 @@ function advancedSet(d, p) { !!d.proxyMode || Object.values(d.accountProxies || {}).some((x) => x?.mode) || [d.concurrency, d.maxAccounts, d.queueLimit, d.queueWait, d.maxRPM, d.priceRate, d.contexts, d.outputs, d.compacts].some((v) => String(v ?? "").trim()) || !!d.rateWindows?.length || - !!(d.searches || d.authHeader || d.passUserAgent || d.unredacted || d.countFree || d.pinUpstream || d.nativeCompaction || d.balanceToken || d.limitRestOff || d.http1 || d.imageFilesOff || d.passErrors) || + !!(d.searches || d.authHeader || d.passUserAgent === false || d.unredacted || d.countFree || d.pinUpstream || d.nativeCompaction || d.balanceToken || d.limitRestOff || d.http1 || d.imageFilesOff || d.passErrors) || !!d.fallback?.length || !!p?.balanceToken?.set; } function priceRateError(ed) { @@ -9182,7 +9182,7 @@ function baseAPIOf(p) { // draftOf is a saved provider as its editor's form holds it. function draftOf(p) { - return { id: p.id, name: p.name, preset: p.preset, chat: p.chat, responses: p.responses, anthropic: p.anthropic, gemini: p.gemini || "", catalog: p.catalog, decide: p.decide || "", key: "", api: baseAPIOf(p), chosen: pickedOf(p), none: !!p.noModels, best: !!p.bestInFamily, extra: [], headers: headerRows(p.headers), extraBody: extraBodyText(p.extraBody), replyHeaders: (p.replyHeaders || []).join(", "), passHeaders: (p.passHeaders || []).join(", "), icon: p.icon || "", iconFrom: p.iconFrom || "", fallback: [...(p.fallback || [])], unlisted: !!p.unlisted, hiddenDrawers: [...(p.hiddenDrawers || [])], hiddenVideomakers: [...(p.hiddenVideomakers || [])], searches: !!p.searches, unredacted: !!p.unredacted, countFree: !!p.countFree, insecureTLS: !!p.insecureTLS, http1: !!p.http1, limitRestOff: !!p.limitRestOff, passErrors: !!p.passErrors, imageFilesOff: !!p.imageFilesOff, nativeCompaction: !!p.nativeCompaction, passUserAgent: !!p.passUserAgent, pinUpstream: !!p.pinUpstream, authHeader: p.authHeader || "", balanceURL: p.balanceURL || "", balancePath: p.balancePath || "", balanceMethod: p.balanceMethod || "", modelsURL: p.modelsURL || "", contexts: contextsText(p.contexts), outputs: contextsText(p.outputs), compacts: contextsText(p.compacts), keysUrl: p.keysUrl || "", ...proxyDraft(p), ...concurrencyDraft(p), rateWindows: (p.rateWindows || []).map((w) => ({ ...w })) }; + return { id: p.id, name: p.name, preset: p.preset, chat: p.chat, responses: p.responses, anthropic: p.anthropic, gemini: p.gemini || "", catalog: p.catalog, decide: p.decide || "", key: "", api: baseAPIOf(p), chosen: pickedOf(p), none: !!p.noModels, best: !!p.bestInFamily, extra: [], headers: headerRows(p.headers), extraBody: extraBodyText(p.extraBody), replyHeaders: (p.replyHeaders || []).join(", "), passHeaders: (p.passHeaders || []).join(", "), icon: p.icon || "", iconFrom: p.iconFrom || "", fallback: [...(p.fallback || [])], unlisted: !!p.unlisted, hiddenDrawers: [...(p.hiddenDrawers || [])], hiddenVideomakers: [...(p.hiddenVideomakers || [])], searches: !!p.searches, unredacted: !!p.unredacted, countFree: !!p.countFree, insecureTLS: !!p.insecureTLS, http1: !!p.http1, limitRestOff: !!p.limitRestOff, passErrors: !!p.passErrors, imageFilesOff: !!p.imageFilesOff, nativeCompaction: !!p.nativeCompaction, passUserAgent: p.passUserAgent !== false, pinUpstream: !!p.pinUpstream, authHeader: p.authHeader || "", balanceURL: p.balanceURL || "", balancePath: p.balancePath || "", balanceMethod: p.balanceMethod || "", modelsURL: p.modelsURL || "", contexts: contextsText(p.contexts), outputs: contextsText(p.outputs), compacts: contextsText(p.compacts), keysUrl: p.keysUrl || "", ...proxyDraft(p), ...concurrencyDraft(p), rateWindows: (p.rateWindows || []).map((w) => ({ ...w })) }; } // duplicateProvider opens the Add form on a copy of p, its key p's unless another is pasted (#268). @@ -9766,9 +9766,9 @@ function drawEditor(p, presetID) { // the agent's User-Agent (#1851); an account or ownClient keeps its own const uaPassable = () => !p?.account && !(p ? p.ownClient : pr?.ownClient); if (uaPassable()) { - const [utk, ucb] = tick(t("Send the agent's own User-Agent"), !!draft.passUserAgent); + const [utk, ucb] = tick(t("Send the agent's own User-Agent"), draft.passUserAgent !== false); ucb.onchange = () => { draft.passUserAgent = ucb.checked; }; - advIn.append(...field(t("User-Agent"), utk, t("For a plan that serves only the coding agents it names: each request goes with the User-Agent the agent sent (pi, OpenCode, Claude Code…), not magpie's. Requests magpie makes itself, and ones the agent sent without one, still go as magpie. A User-Agent set in Headers above always wins."))); + advIn.append(...field(t("User-Agent"), utk, t("Off, every request goes as magpie. A User-Agent set in Headers above always wins."))); } const addressOf = (k) => (draft[k] ?? (isNew && pr ? pr[k] : "")) || ""; @@ -10166,7 +10166,7 @@ function drawEditor(p, presetID) { if (p?.takesImageFiles) body.imageFilesOff = !!draft.imageFilesOff; if (p ? p.takesPassErrors : custom) body.passErrors = !!draft.passErrors; if (!decideOnly(p || pr)) body.nativeCompaction = !!draft.nativeCompaction && carriesCompaction(); - body.passUserAgent = !!draft.passUserAgent && uaPassable(); + if (uaPassable()) body.passUserAgent = draft.passUserAgent !== false; const cx = parseContexts(draft.contexts || ""); if (cx.error) return contextError(ed, cx.error); body.contexts = cx.map; diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index de1d4f97f..50d3615b0 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -4075,7 +4075,7 @@ const I18N = { "{host} isn't on this computer or your local network: turned on, requests go to it unmasked.": "{host} 不在这台电脑或局域网里:打开后,请求会不脱敏地发给它。", "User-Agent": "User-Agent", "Send the agent's own User-Agent": "发送 Agent 自己的 User-Agent", - "For a plan that serves only the coding agents it names: each request goes with the User-Agent the agent sent (pi, OpenCode, Claude Code…), not magpie's. Requests magpie makes itself, and ones the agent sent without one, still go as magpie. A User-Agent set in Headers above always wins.": "给只允许指定编程 Agent 使用的套餐:每个请求带上 Agent 自己发来的 User-Agent(pi、OpenCode、Claude Code…),而不是 magpie 的。magpie 自己发出的请求,以及 Agent 没带 User-Agent 的请求,仍以 magpie 的身份发送。上面请求头里设置的 User-Agent 始终优先。", + "Off, every request goes as magpie. A User-Agent set in Headers above always wins.": "关闭时,每个请求都以 magpie 的身份发送。上面请求头里设置的 User-Agent 始终优先。", "DeepSeek and GLM models only from their makers' own APIs": "DeepSeek、GLM 模型只走各自官方上游", "Upstream": "上游", "Since 2026-11-06 Cline refuses a pinned DeepSeek or GLM request with 403, so magpie sends them unpinned and Cline picks the host; only glm-5.3-flash still asks Z.ai": "自 2026-11-06 起,Cline 对钉住上游的 DeepSeek、GLM 请求一律回 403,所以 magpie 不再钉住它们,由 Cline 自己挑上游;只有 glm-5.3-flash 仍指定 Z.ai", @@ -8717,7 +8717,7 @@ const I18N = { "{host} isn't on this computer or your local network: turned on, requests go to it unmasked.": "{host} 不在這臺電腦或區域網裡:開啟後,請求會不脫敏地發給它。", "User-Agent": "User-Agent", "Send the agent's own User-Agent": "傳送 Agent 自己的 User-Agent", - "For a plan that serves only the coding agents it names: each request goes with the User-Agent the agent sent (pi, OpenCode, Claude Code…), not magpie's. Requests magpie makes itself, and ones the agent sent without one, still go as magpie. A User-Agent set in Headers above always wins.": "給只允許指定程式設計 Agent 使用的方案:每個請求帶上 Agent 自己送來的 User-Agent(pi、OpenCode、Claude Code…),而不是 magpie 的。magpie 自己發出的請求,以及 Agent 沒帶 User-Agent 的請求,仍以 magpie 的身分傳送。上面請求頭裡設定的 User-Agent 永遠優先。", + "Off, every request goes as magpie. A User-Agent set in Headers above always wins.": "關閉時,每個請求都以 magpie 的身分傳送。上面請求頭裡設定的 User-Agent 永遠優先。", "DeepSeek and GLM models only from their makers' own APIs": "DeepSeek、GLM 模型只走各自官方上游", "Upstream": "上游", "Since 2026-11-06 Cline refuses a pinned DeepSeek or GLM request with 403, so magpie sends them unpinned and Cline picks the host; only glm-5.3-flash still asks Z.ai": "自 2026-11-06 起,Cline 對釘住上游的 DeepSeek、GLM 請求一律回 403,所以 magpie 不再釘住它們,由 Cline 自己挑上游;只有 glm-5.3-flash 仍指定 Z.ai", @@ -13375,7 +13375,7 @@ const I18N = { "{host} isn't on this computer or your local network: turned on, requests go to it unmasked.": "{host} はこのコンピューターにもローカルネットワークにもありません:オンにすると、リクエストはマスクされずに送られます。", "User-Agent": "User-Agent", "Send the agent's own User-Agent": "エージェント自身の User-Agent を送る", - "For a plan that serves only the coding agents it names: each request goes with the User-Agent the agent sent (pi, OpenCode, Claude Code…), not magpie's. Requests magpie makes itself, and ones the agent sent without one, still go as magpie. A User-Agent set in Headers above always wins.": "指定したコーディングエージェントだけが使えるプラン向け:各リクエストは magpie のものではなく、エージェントが送ってきた User-Agent(pi、OpenCode、Claude Code…)で送られます。magpie 自身のリクエストと、エージェントが User-Agent を付けなかったリクエストは、引き続き magpie として送られます。上のヘッダーで設定した User-Agent が常に優先されます。", + "Off, every request goes as magpie. A User-Agent set in Headers above always wins.": "オフにすると、すべてのリクエストが magpie として送られます。上のヘッダーで設定した User-Agent が常に優先されます。", "DeepSeek and GLM models only from their makers' own APIs": "DeepSeek・GLM モデルはそれぞれの公式 API のみ", "Upstream": "上流", "Since 2026-11-06 Cline refuses a pinned DeepSeek or GLM request with 403, so magpie sends them unpinned and Cline picks the host; only glm-5.3-flash still asks Z.ai": "2026-11-06 以降、Cline は上流を固定した DeepSeek・GLM のリクエストを 403 で拒否するため、magpie は固定せずに送り、上流は Cline が選びます。Z.ai を指定するのは glm-5.3-flash だけです", @@ -18048,7 +18048,7 @@ const I18N = { "{host} isn't on this computer or your local network: turned on, requests go to it unmasked.": "{host} ist weder auf diesem Computer noch in Ihrem lokalen Netzwerk: Eingeschaltet gehen Anfragen unmaskiert an ihn.", "User-Agent": "User-Agent", "Send the agent's own User-Agent": "Den eigenen User-Agent des Agenten senden", - "For a plan that serves only the coding agents it names: each request goes with the User-Agent the agent sent (pi, OpenCode, Claude Code…), not magpie's. Requests magpie makes itself, and ones the agent sent without one, still go as magpie. A User-Agent set in Headers above always wins.": "Für einen Tarif, der nur die genannten Coding-Agenten zulässt: Jede Anfrage geht mit dem User-Agent, den der Agent gesendet hat (pi, OpenCode, Claude Code…), nicht mit dem von magpie. Anfragen, die magpie selbst stellt, und solche, die der Agent ohne einen gesendet hat, gehen weiter als magpie. Ein oben unter Header gesetzter User-Agent hat immer Vorrang.", + "Off, every request goes as magpie. A User-Agent set in Headers above always wins.": "Aus geht jede Anfrage als magpie. Ein oben unter Header gesetzter User-Agent hat immer Vorrang.", "DeepSeek and GLM models only from their makers' own APIs": "DeepSeek- und GLM-Modelle nur über die eigene API ihres Herstellers", "Upstream": "Upstream", "Since 2026-11-06 Cline refuses a pinned DeepSeek or GLM request with 403, so magpie sends them unpinned and Cline picks the host; only glm-5.3-flash still asks Z.ai": "Seit 2026-11-06 lehnt Cline eine angeheftete DeepSeek- oder GLM-Anfrage mit 403 ab, daher sendet magpie sie ohne Anheftung und Cline wählt den Anbieter; nur glm-5.3-flash fragt weiter Z.ai an", diff --git a/internal/gui/providers.go b/internal/gui/providers.go index cb4bb8d80..8a041f66b 100644 --- a/internal/gui/providers.go +++ b/internal/gui/providers.go @@ -143,7 +143,7 @@ type providerJSON struct { NativeCompaction bool `json:"nativeCompaction"` CarriesCompaction bool `json:"carriesCompaction,omitempty"` // requests go with the agent's own User-Agent, not magpie's - // (provider.PassUserAgent, #1851); OwnClient: they go as a client of + // (provider.MagpieUserAgent off, #1851); OwnClient: they go as a client of // the vendor's own whatever is set (provider.OwnClient), so the // editor offers no such choice PassUserAgent bool `json:"passUserAgent"` @@ -739,7 +739,7 @@ func providerInfoWith(p provider.Provider, ls provider.Listing, agents []agentUs ID: p.ID, Name: p.Name, Icon: p.Icon, IconFrom: p.IconFrom, Preset: p.Preset, Host: p.Host(), Chat: p.Chat, Responses: p.Responses, Anthropic: p.Anthropic, Gemini: p.Gemini, Decide: p.Decide, BaseAPI: p.BaseAPI, ModelTest: p.ModelTest(), TestsAs: p.TestClients(), DecideTest: p.AsksDecideModels(), MarksKinds: p.MarksKinds(), Catalog: p.Catalog, Website: p.Website, KeysURL: p.KeysURL, - Proxy: p.Proxy, AccountProxies: p.AccountProxies, AccountModels: p.AccountModels, AccountCaps: p.AccountCaps, AccountWindowCaps: p.AccountWindowCaps, AccountNames: p.AccountNames, Headers: p.Headers, ExtraBody: p.ExtraBody, ReplyHeaders: p.ReplyHeaders, PassHeaders: p.PassHeaders, Searches: p.Searches, Cline: p.ClinePinnable(), PinUpstream: p.PinUpstream, Unredacted: p.Unredacted, CountFree: p.CountFree, InsecureTLS: p.InsecureTLS, TakesInsecureTLS: p.TakesInsecureTLS(), HTTP1: p.HTTP1, LimitRestOff: p.LimitRestOff, ImageFilesOff: p.ImageFilesOff, TakesImageFiles: p.TakesImageFiles(), NativeCompaction: p.NativeCompaction, CarriesCompaction: p.CarriesCompaction(), PassUserAgent: p.PassUserAgent, OwnClient: p.OwnClient(), PassErrors: p.PassErrors, TakesPassErrors: p.TakesPassErrors(), AuthHeader: p.AuthHeader, BothAuth: p.BothAuth(), BalanceURL: p.BalanceURL, BalancePath: p.BalancePath, BalanceMethod: p.BalanceMethod, ModelsURL: p.ModelsURL, + Proxy: p.Proxy, AccountProxies: p.AccountProxies, AccountModels: p.AccountModels, AccountCaps: p.AccountCaps, AccountWindowCaps: p.AccountWindowCaps, AccountNames: p.AccountNames, Headers: p.Headers, ExtraBody: p.ExtraBody, ReplyHeaders: p.ReplyHeaders, PassHeaders: p.PassHeaders, Searches: p.Searches, Cline: p.ClinePinnable(), PinUpstream: p.PinUpstream, Unredacted: p.Unredacted, CountFree: p.CountFree, InsecureTLS: p.InsecureTLS, TakesInsecureTLS: p.TakesInsecureTLS(), HTTP1: p.HTTP1, LimitRestOff: p.LimitRestOff, ImageFilesOff: p.ImageFilesOff, TakesImageFiles: p.TakesImageFiles(), NativeCompaction: p.NativeCompaction, CarriesCompaction: p.CarriesCompaction(), PassUserAgent: !p.MagpieUserAgent, OwnClient: p.OwnClient(), PassErrors: p.PassErrors, TakesPassErrors: p.TakesPassErrors(), AuthHeader: p.AuthHeader, BothAuth: p.BothAuth(), BalanceURL: p.BalanceURL, BalancePath: p.BalancePath, BalanceMethod: p.BalanceMethod, ModelsURL: p.ModelsURL, Ready: p.Ready(), Chosen: p.PicksOf(avail), Agents: make([]providerAgent, 0, len(agents)), Fallback: p.Fallback, Routing: p.Routing, Sink: p.Sink, UseFirst: p.UseFirst, Affinity: p.Affinity, KeepLogin: p.KeepLogin, KeepLoginAs: p.KeepLoginAs, SwitchOnly: p.SwitchOnly, RestartApp: p.RestartApp, Self: p.SelfAnswered(), KeepSelf: p.KeepSelf, CapStop: p.CapStop, CapCareful: p.CapCareful, Unlisted: p.Unlisted, NoModels: p.ServesNone(), BestInFamily: p.BestInFamily && len(p.Models) == 0 && !p.NoModels, Off: p.Off, Contexts: p.Contexts, MaxConcurrency: p.MaxConcurrency, PluginConcurrency: p.PluginConcurrency(), MaxAccounts: p.MaxAccounts, PluginAccounts: p.PluginAtOnce(), PriceRate: p.PriceRate, @@ -1586,6 +1586,10 @@ func providerRoutes(mux *http.ServeMux, w Windows) { // as Codex sent it (provider.Provider.NativeCompaction); a save // that leaves it out keeps it NativeCompaction *bool `json:"nativeCompaction"` + // PassUserAgent, for save: the editor's Send the agent's own + // User-Agent (provider.Provider.MagpieUserAgent off); a save + // that leaves it out keeps it + PassUserAgent *bool `json:"passUserAgent"` // AuthHeader, for save: which header the key goes in on a // third-party Anthropic API (provider.Provider.AuthHeader); a // save that leaves it out keeps it, one learned too @@ -1666,6 +1670,9 @@ func providerRoutes(mux *http.ServeMux, w Windows) { if req.NativeCompaction != nil { in.NativeCompaction = *req.NativeCompaction } + if req.PassUserAgent != nil { + in.MagpieUserAgent = !*req.PassUserAgent + } if req.AuthHeader != nil { in.AuthHeader = *req.AuthHeader } @@ -1756,7 +1763,7 @@ func providerRoutes(mux *http.ServeMux, w Windows) { pr.Unredacted = in.Unredacted pr.CountFree = in.CountFree pr.NativeCompaction = in.NativeCompaction - pr.PassUserAgent = in.PassUserAgent + pr.MagpieUserAgent = in.MagpieUserAgent pr.AuthHeader = in.AuthHeader // and what its editor sets beside them: how requests spread // over its keys, how long a conversation stays, the one @@ -2098,6 +2105,9 @@ func providerRoutes(mux *http.ServeMux, w Windows) { if req.NativeCompaction == nil { in.NativeCompaction = old.NativeCompaction } + if req.PassUserAgent == nil { + in.MagpieUserAgent = old.MagpieUserAgent + } if req.AuthHeader == nil { in.AuthHeader = old.AuthHeader } diff --git a/internal/gui/providers_routing_test.go b/internal/gui/providers_routing_test.go index b93e1e0c1..44b2d151c 100644 --- a/internal/gui/providers_routing_test.go +++ b/internal/gui/providers_routing_test.go @@ -138,7 +138,7 @@ func TestDecidePresetSaveKeepsRouting(t *testing.T) { t.Fatalf("not a decision-only provider of two keys: %+v", p) } second := p.KeyList()[1].ID - form := `"id":"typesafe","from":"typesafe","name":"TypeSafe Jev","preset":"typesafe","key":"","decide":"http://127.0.0.1:1/v1","models":[],"headers":{},"fallback":[],"noModels":false,"searches":false,"pinUpstream":false,"unredacted":false,"passUserAgent":false,"contexts":{},"proxy":"","maxConcurrency":0` + form := `"id":"typesafe","from":"typesafe","name":"TypeSafe Jev","preset":"typesafe","key":"","decide":"http://127.0.0.1:1/v1","models":[],"headers":{},"fallback":[],"noModels":false,"searches":false,"pinUpstream":false,"unredacted":false,"passUserAgent":true,"contexts":{},"proxy":"","maxConcurrency":0` post("save", `{`+form+`,"unlisted":true,"accountProxies":{"`+second+`":"http://127.0.0.1:7890"},"routing":"order","affinity":"session","sink":true}`) p, err = provider.Find("typesafe") if err != nil { diff --git a/internal/gui/tests/provider-native-compaction.test.cjs b/internal/gui/tests/provider-native-compaction.test.cjs index 9f565e686..d86b82aa5 100644 --- a/internal/gui/tests/provider-native-compaction.test.cjs +++ b/internal/gui/tests/provider-native-compaction.test.cjs @@ -22,7 +22,7 @@ const unfold = async (page) => { const base = { icon: "generic", chat: "", responses: "", anthropic: "", catalog: "", models: [{ id: "m1", name: "M1", on: true }], agents: [], fallback: [], headers: {}, - key: { set: true, masked: "sk-…1234" }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "", searches: false, unredacted: false, passUserAgent: false, + key: { set: true, masked: "sk-…1234" }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "", searches: false, unredacted: false, passUserAgent: true, }; const relay = { ...base, id: "relay", name: "Responses Relay", responses: "https://relay.example.com/v1", carriesCompaction: true }; const chat = { ...base, id: "chatonly", name: "Chat Relay", chat: "https://chat.example.com/v1" }; diff --git a/internal/gui/tests/provider-user-agent.test.cjs b/internal/gui/tests/provider-user-agent.test.cjs index 0b26aa6a3..b23431eff 100644 --- a/internal/gui/tests/provider-user-agent.test.cjs +++ b/internal/gui/tests/provider-user-agent.test.cjs @@ -1,8 +1,9 @@ // Run with Node's test runner and Playwright on the module path; see README.md. // #1851: a coding plan that serves only the agents it names knows them by -// their User-Agent. The provider editor's User-Agent row, "Send the agent's -// own User-Agent", is there for a provider with a key, opens as it was -// saved, and Save posts it. A signed-in account and a vendor magpie goes as +// their User-Agent, and a gateway of the user's own behind magpie wants to +// see the agent's (nb5p on Discord). The provider editor's User-Agent row, +// "Send the agent's own User-Agent", is there for a provider with a key, +// opens ticked unless it was saved as magpie, and Save posts it. A signed-in account and a vendor magpie goes as // the client of (OpenCode here) have no such row. In every language, wide // and narrow. const assert = require("node:assert/strict"); @@ -22,10 +23,10 @@ const unfold = async (page) => { const base = { icon: "generic", chat: "", responses: "", anthropic: "", catalog: "", models: [{ id: "m1", name: "M1", on: true }], agents: [], fallback: [], headers: {}, - key: { set: true, masked: "sk-…1234" }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "", searches: false, unredacted: false, passUserAgent: false, + key: { set: true, masked: "sk-…1234" }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "", searches: false, unredacted: false, passUserAgent: true, }; const plan = { ...base, id: "plan", name: "Agent Plan", chat: "https://plan.example.com/v1" }; -const passing = { ...base, id: "passing", name: "Passing Plan", chat: "https://passing.example.com/v1", passUserAgent: true }; +const asMagpie = { ...base, id: "asmagpie", name: "Magpie Plan", chat: "https://asmagpie.example.com/v1", passUserAgent: false }; const zen = { ...base, id: "opencode", name: "OpenCode Zen", chat: "https://opencode.ai/zen/v1", ownClient: true }; const codex = { id: "codex", name: "Codex", icon: "codex-color", chat: "", responses: "", anthropic: "", catalog: "", @@ -35,7 +36,7 @@ const codex = { }; function serve(lang, posts) { - const providers = { providers: [plan, passing, zen, codex], presets: [], excluded: [], gateway: { running: true, window: true } }; + const providers = { providers: [plan, asMagpie, zen, codex], presets: [], excluded: [], gateway: { running: true, window: true } }; const state = { agents: [], profiles: [], settings: { lang, theme: "light" } }; return async (route) => { const url = new URL(route.request().url()); @@ -58,7 +59,7 @@ function serve(lang, posts) { const strings = [ "User-Agent", "Send the agent's own User-Agent", - "For a plan that serves only the coding agents it names: each request goes with the User-Agent the agent sent (pi, OpenCode, Claude Code…), not magpie's. Requests magpie makes itself, and ones the agent sent without one, still go as magpie. A User-Agent set in Headers above always wins.", + "Off, every request goes as magpie. A User-Agent set in Headers above always wins.", ]; const words = { en: { tick: "Send the agent's own User-Agent", save: "Save" }, @@ -103,8 +104,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", return posts.at(-1); }; - test(`${engine} ${lang} ${width}: a plan with a key is set to send the agent's User-Agent, and saved so`, async (t) => { - const { page, errors, posts } = await open(t, "Agent Plan"); + test(`${engine} ${lang} ${width}: one saved as magpie opens unticked, and is set to send the agent's User-Agent`, async (t) => { + const { page, errors, posts } = await open(t, "Magpie Plan"); assert.equal(await row(page).isVisible(), true); assert.equal(await box(page).isChecked(), false, "opens as magpie"); const r = await row(page).boundingBox(); @@ -116,7 +117,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(y2, y, "the click doesn't scroll"); const saved = await save(page, posts); assert.equal(saved.action, "save"); - assert.equal(saved.body.id, "plan"); + assert.equal(saved.body.id, "asmagpie"); assert.equal(saved.body.passUserAgent, true); if (lang !== "en") { const missing = await page.evaluate(([l, ks]) => ks.filter((k) => !I18N[l][k]), [lang, strings]); @@ -125,13 +126,13 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.deepEqual(errors, []); }); - test(`${engine} ${lang} ${width}: one saved passing it opens ticked, and is saved as magpie`, async (t) => { - const { page, errors, posts } = await open(t, "Passing Plan"); - assert.equal(await box(page).isChecked(), true); + test(`${engine} ${lang} ${width}: a plan with a key opens ticked by default, and unticked is saved as magpie`, async (t) => { + const { page, errors, posts } = await open(t, "Agent Plan"); + assert.equal(await box(page).isChecked(), true, "sends the agent's by default"); await box(page).scrollIntoViewIfNeeded(); await box(page).uncheck(); const saved = await save(page, posts); - assert.equal(saved.body.id, "passing"); + assert.equal(saved.body.id, "plan"); assert.equal(saved.body.passUserAgent, false); assert.deepEqual(errors, []); }); diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 0f11075a3..14c3cd42e 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -393,15 +393,17 @@ type Provider struct { // keeps magpie's summary. NativeCompaction bool `json:"nativeCompaction,omitempty"` - // PassUserAgent has a request go to the vendor with the User-Agent the - // agent that sent it gave (pi, opencode, Claude Code…), in place of - // magpie's own (#1851): a coding plan that serves only agents it names - // knows them by it. One the agent didn't give, or magpie's own - // requests, go as magpie. Off, the default, every request goes as - // magpie. Only a key+URL provider takes it: a signed-in account, a - // plugin's and one that goes as a client of its vendor's own keep the - // identity their signing gives (see PassesUserAgent). - PassUserAgent bool `json:"passUserAgent,omitempty"` + // MagpieUserAgent has every request go to the vendor with magpie's own + // User-Agent (magpie/). Off, the default, a key+URL provider is + // sent the User-Agent the agent gave (pi, opencode, Claude Code…) as it + // gave it (#1851, nb5p on Discord): a coding plan that serves only + // agents it names, or the user's own gateway behind magpie, knows them + // by it. One the agent didn't give, and magpie's own requests, go as + // magpie either way. A signed-in account, a plugin's and one that goes + // as a client of its vendor's own keep the identity their signing + // gives (see PassesUserAgent). The opt-in "passUserAgent" it replaces + // is the default now, so a file that still says it reads the same. + MagpieUserAgent bool `json:"magpieUserAgent,omitempty"` // PinUpstream, on the Cline API, has its DeepSeek models answered only // by DeepSeek's own API (White Immortal on Discord) and its GLM models @@ -1424,7 +1426,7 @@ func AddCopy(p Provider, from string) (string, error) { p.Unredacted = p.Unredacted || src.Unredacted p.CountFree = p.CountFree || src.CountFree p.NativeCompaction = p.NativeCompaction || src.NativeCompaction - p.PassUserAgent = p.PassUserAgent || src.PassUserAgent + p.MagpieUserAgent = p.MagpieUserAgent || src.MagpieUserAgent if p.Website == "" { p.Website = src.Website } diff --git a/internal/provider/user_agent.go b/internal/provider/user_agent.go index 76b8c4808..fc23f3349 100644 --- a/internal/provider/user_agent.go +++ b/internal/provider/user_agent.go @@ -1,13 +1,13 @@ package provider // PassesUserAgent says a request to p goes with the User-Agent of the agent -// that sent it (#1851): the user set PassUserAgent, and p is a key+URL -// provider whose requests go as magpie's. A signed-in account and a +// that sent it (#1851): p is a key+URL provider, and the user didn't set +// it to go as magpie (MagpieUserAgent). A signed-in account and a // plugin's provider sign as their own client; OpenCode's, Cline's and // Kilo's gateways are sent the client they serve (OwnClient), and another // magpie is told magpie by it: none of them takes the agent's in its place. func (p Provider) PassesUserAgent() bool { - return p.PassUserAgent && p.Account == nil && !p.OwnClient() + return !p.MagpieUserAgent && p.Account == nil && !p.OwnClient() } // OwnClient says magpie's requests to p go as a client the vendor serves, diff --git a/internal/provider/user_agent_test.go b/internal/provider/user_agent_test.go index e1644207c..27dbe10d5 100644 --- a/internal/provider/user_agent_test.go +++ b/internal/provider/user_agent_test.go @@ -5,24 +5,25 @@ import ( "testing" ) -// Only a key+URL provider passes the agent's User-Agent on (#1851): a -// signed-in account, a plugin's, and one that goes as a client of its -// vendor's own (OpenCode, Cline, Kilo, another magpie) keep the identity -// their signing gives, set or not. +// A key+URL provider passes the agent's User-Agent on by default (#1851, +// nb5p on Discord), and goes as magpie only when set to: a signed-in +// account, a plugin's, and one that goes as a client of its vendor's own +// (OpenCode, Cline, Kilo, another magpie) keep the identity their signing +// gives. func TestPassesUserAgent(t *testing.T) { for _, tt := range []struct { name string p Provider want bool }{ - {"key", Provider{PassUserAgent: true, Chat: "https://api.example.com/v1"}, true}, - {"key, off", Provider{Chat: "https://api.example.com/v1"}, false}, - {"an account", Provider{PassUserAgent: true, Chat: "https://api.z.ai/api/coding/paas/v4", Account: &Account{Agent: "zcode"}}, false}, - {"a plugin's", Provider{PassUserAgent: true, Chat: "https://x.example/v1", Account: &Account{Agent: "plugin:x"}}, false}, - {"opencode", Provider{PassUserAgent: true, Chat: "https://opencode.ai/zen/v1"}, false}, - {"cline", Provider{PassUserAgent: true, Preset: "clinepass", Chat: "https://api.cline.bot/api/v1"}, false}, - {"kilo", Provider{PassUserAgent: true, Preset: "kilo", Chat: "https://api.kilo.ai/api/gateway"}, false}, - {"another magpie", Provider{PassUserAgent: true, Preset: RemoteMagpiePreset, Chat: "http://10.0.0.2:3425/v1"}, false}, + {"key", Provider{Chat: "https://api.example.com/v1"}, true}, + {"key, as magpie", Provider{MagpieUserAgent: true, Chat: "https://api.example.com/v1"}, false}, + {"an account", Provider{Chat: "https://api.z.ai/api/coding/paas/v4", Account: &Account{Agent: "zcode"}}, false}, + {"a plugin's", Provider{Chat: "https://x.example/v1", Account: &Account{Agent: "plugin:x"}}, false}, + {"opencode", Provider{Chat: "https://opencode.ai/zen/v1"}, false}, + {"cline", Provider{Preset: "clinepass", Chat: "https://api.cline.bot/api/v1"}, false}, + {"kilo", Provider{Preset: "kilo", Chat: "https://api.kilo.ai/api/gateway"}, false}, + {"another magpie", Provider{Preset: RemoteMagpiePreset, Chat: "http://10.0.0.2:3425/v1"}, false}, } { if got := tt.p.PassesUserAgent(); got != tt.want { t.Errorf("%s: %v, want %v", tt.name, got, tt.want) @@ -30,16 +31,16 @@ func TestPassesUserAgent(t *testing.T) { } } -// A copy of a provider that passes the agent's User-Agent on passes it on -// too, the form not carrying it. -func TestAddCopyPassUserAgent(t *testing.T) { +// A copy of a provider set to go as magpie goes as magpie too, the form not +// carrying it. +func TestAddCopyMagpieUserAgent(t *testing.T) { isolate(t) home := t.TempDir() t.Setenv("HOME", home) t.Setenv("USERPROFILE", home) t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) - if err := Save(Provider{ID: "plan", Name: "Plan", Chat: "https://plan.example/v1", Key: "sk-1", PassUserAgent: true}); err != nil { + if err := Save(Provider{ID: "plan", Name: "Plan", Chat: "https://plan.example/v1", Key: "sk-1", MagpieUserAgent: true}); err != nil { t.Fatal(err) } id, err := AddCopy(Provider{Name: "Plan copy", Chat: "https://plan.example/v1", Models: []string{"m"}}, "plan") @@ -50,7 +51,7 @@ func TestAddCopyPassUserAgent(t *testing.T) { if err != nil { t.Fatal(err) } - if !c.PassUserAgent { - t.Fatal("the copy goes as magpie") + if !c.MagpieUserAgent { + t.Fatal("the copy sends the agent's User-Agent") } }