diff --git a/docs/reference.md b/docs/reference.md index f4b7d460b..8e8491ff1 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -418,6 +418,17 @@ agent's own User-Agent" unticked) sends magpie's in its place; 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 provider set search=yes` (the editor's Advanced › Web search, +"Searches the web by itself") is for a relay in front of Anthropic's or +OpenAI's own API that runs web search itself. Claude Code's WebSearch, +Codex's `web_search` tool and Codex's web.run (its `POST /v1/alpha/search`) +then go to the relay as they were sent, with its key, instead of through +magpie's search; the relay's answer goes back as it came. If the relay's +search fails, magpie searches in its place and says why. In a routing group +the member a turn would go to first decides. `search=no`, the default, +keeps magpie's search; Settings › Models › Web search set to magpie's +search for models that search by themselves wins over 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`) or `--days 1.5`; the CSV then holds that window's calls only (#2075). diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.md index 017aa87b5..8837b308a 100644 --- a/docs/subsystems/gateway-routing.md +++ b/docs/subsystems/gateway-routing.md @@ -1998,6 +1998,26 @@ searches left the 5-hour window at the same percent, about 2s each, while mode reaches only the backend's search. Covered by `TestChatGPTAccountSearchesByItsWebSearch`, `TestResponsesWebSearchModeKept` and `TestCodexPagesRead`. + +Codex's web.run on any other model (its `POST /v1/alpha/search`, or under +`CodexPath`) is searched by magpie (`alphaSearchHere`), unless the provider +the turn would go to is a key+URL relay with a Responses base set to search +by itself (`Searches`, "Searches the web by itself"; `upstreamSearches`). +Then [`relaySearchers`](../../internal/gateway/codex_search.go) sends the +body as Codex sent it, with the bare model, to `/alpha/search` +with the relay's key, Codex's turn headers, its originator and the agent's +User-Agent, and its 2xx reply goes back as it came (YIXIE233 on X: a relay +in front of a ChatGPT pool that serves `/v1/alpha/search`). A group goes by +its plan: the leading member decides, and later members that search are +tried after it; one that doesn't is skipped. Accounts and models a key may +not use are left out. When every try fails, magpie searches and the output +starts with why. `magpieSearches` (Settings' `searchAll`) keeps magpie's +search, as for the Responses `web_search` tool, which a relay set so was +already sent as is (`searchedForIt`). A plugin's provider is not sent +web.run: its fetch serves turns, not this route. Covered by +`TestCodexWebRunGoesToRelayThatSearches` and +`TestCodexWebRunInGroupFollowsLeadingMember` (both red on the old code), +and `TestResponsesWebSearchToolToRelayThatSearches`. Covered by `TestCommandCodeSearchesForOtherModels`, `TestPluginSearchModelIsASearcher` and `TestSearcherChosen`. diff --git a/internal/cli/providers_cli.go b/internal/cli/providers_cli.go index 9d694a9fb..e520c1aff 100644 --- a/internal/cli/providers_cli.go +++ b/internal/cli/providers_cli.go @@ -188,8 +188,8 @@ const providerUsage = `usage: (Advanced › Connect to: connects to 10.0.0.5, then gw.corp.example's address, while TLS and Host still say relay.example.com) magpie provider set my-relay search=yes - (the relay answers Claude Code's WebSearch and Codex's web_search itself: - those go to it as sent, not through magpie's own search) + (the relay answers Claude Code's WebSearch and Codex's web search itself, web_search + and web.run's /alpha/search: those go to it as sent, not through magpie's search) magpie provider add lmstudio address=http://192.168.1.5:1234 magpie provider set lmstudio address=192.168.1.5:1234 (Ollama, LM Studio, oMLX or MLX-Serve on another port or computer: each of its @@ -1392,8 +1392,9 @@ func applyPairs(p *provider.Provider, pairs []string) error { 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 - // Anthropic's or OpenAI's API) + // client offers going to it as it was sent, Codex's web.run + // (/alpha/search) too (a relay in front of Anthropic's or + // OpenAI's API; YIXIE233 on X) if v != "yes" && v != "no" { return fmt.Errorf("search=yes|no, not %q", v) } diff --git a/internal/gateway/codex_search.go b/internal/gateway/codex_search.go index 3100e090d..3b3772755 100644 --- a/internal/gateway/codex_search.go +++ b/internal/gateway/codex_search.go @@ -77,17 +77,93 @@ func (s *Server) alphaSearchBody(w http.ResponseWriter, r *http.Request, body [] } note := "" if ons, model := chatGPTSearchers(r, q.Model); len(ons) > 0 { - answered, why := s.alphaSearchOn(w, r, withModel(body, model), model, ons) + ts := make([]searchTarget, len(ons)) + for i, on := range ons { + ts[i] = searchTarget{p: on, model: model, url: provider.CodexBase + AlphaSearchPath} + } + answered, why := s.alphaSearchOn(w, r, body, ts) if answered { return } // a failure would end the turn: magpie searches in its place log.Printf("web search on ChatGPT for %s: %s", q.Model, why) note = "ChatGPT's web search failed (" + why + "); magpie searched in its place.\n\n" + } else if ts := s.relaySearchers(r, q.Model); len(ts) > 0 { + answered, why := s.alphaSearchOn(w, r, body, ts) + if answered { + return + } + log.Printf("web search on %s for %s: %s", ts[0].p.Name, q.Model, why) + note = ts[0].p.Name + "'s web search failed (" + why + "); magpie searched in its place.\n\n" } s.alphaSearchHere(w, r, q, note) } +// searchTarget is where a web.run search goes: the provider, its model +// as it knows it, and the address its search is at. +type searchTarget struct { + p provider.Provider + model string + url string +} + +// upstreamSearches is whether p answers Codex's web.run itself, at +// alpha/search under its Responses address: a key+URL provider set to +// search the web by itself (Searches, #359), as a relay of OpenAI's API +// or of the ChatGPT backend does. Such a relay's web.run was searched by +// magpie, and the relay's own search never used (YIXIE233 on X). +func upstreamSearches(p provider.Provider) bool { + return p.Account == nil && !p.IsPlugin() && p.Searches && p.Base(provider.Responses) != "" +} + +// relaySearchers is where a web.run search for model goes when a provider +// set to search by itself serves it (upstreamSearches): the model's +// provider, or the members of a routing group, in the order a turn of +// the model is routed, those that search by themselves alone. None when +// the one a turn goes to first can't, or Settings has magpie search for +// every model (magpieSearches): magpie searches then, as before. +func (s *Server) relaySearchers(r *http.Request, model string) []searchTarget { + who, keyHeld := keyHolds(r) + ref := model + if !provider.IsGroupRef(ref) { + if gid, ok := keyGroupFor(r, ref); ok { + ref = gid + } + } + var cs []candidate + if provider.IsGroupRef(ref) { + g, ms, ok := provider.FindGroup(ref) + if !ok { + return nil + } + if keyHeld { + keep := groupKeeps(who, g, ms) + ms = slices.DeleteFunc(slices.Clone(ms), func(m provider.Member) bool { return !keep[m.Provider.ID+"/"+m.Model] }) + } + cs, _ = s.planGroup(g.Live(), ms, provider.Responses) + } else { + p, bare, ok := provider.Resolve(model) + if !ok || keyHeld && !modelAllowed(who, p, bare) { + return nil + } + cs = s.candidates(p, bare, provider.Responses) + } + var out []searchTarget + for _, c := range cs { + if !accountAllowed(who, c) { + continue + } + if !upstreamSearches(c.p) || magpieSearches(r.Context(), c.p) { + if len(out) == 0 { + return nil // the turn goes to one that can't: magpie's + } + continue + } + out = append(out, searchTarget{p: c.p, model: c.model, url: c.p.Base(provider.Responses) + AlphaSearchPath}) + } + return out +} + // chatGPTSearchers is the ChatGPT accounts a web search for model may go // to, the one it is served on first and those resting or with a revoked // sign-in last, with the model as the backend knows it: none when model @@ -121,35 +197,40 @@ func chatGPTSearchers(r *http.Request, model string) ([]provider.Provider, strin return append(ready, later...), bare } -// alphaSearchOn sends the search to the ChatGPT backend on each account in -// turn, the next asked when one is refused, limited or fails, and relays -// the backend's answer as it is. It says whether one answered: when none -// did, nothing is written, and the search is magpie's (alphaSearchHere), -// with why returned. -func (s *Server) alphaSearchOn(w http.ResponseWriter, r *http.Request, body []byte, model string, ons []provider.Provider) (bool, string) { +// alphaSearchOn sends the search to each target in turn — the ChatGPT +// backend on each account, or a provider that searches by itself — the +// next asked when one is refused, limited or fails, and relays the +// answer as it is. It says whether one answered: when none did, nothing +// is written, and the search is magpie's (alphaSearchHere), with why +// returned. +func (s *Server) alphaSearchOn(w http.ResponseWriter, r *http.Request, body []byte, ts []searchTarget) (bool, string) { start := time.Now() // as written only when every account it may be asked on is set to go // unmasked (provider.SkipsRedaction, isee1_1 on Discord); magpie's own // search in its place masks its query itself (maskedQuery) - if len(ons) > 0 && !slices.ContainsFunc(ons, func(p provider.Provider) bool { return !p.SkipsRedaction() }) { - return s.alphaSearchAsked(w, r, body, model, ons, start) + if len(ts) > 0 && !slices.ContainsFunc(ts, func(t searchTarget) bool { return !t.p.SkipsRedaction() }) { + return s.alphaSearchAsked(w, r, body, ts, start) } w, body, unmask, hits, err := redactedHits(r.Context(), w, body) defer unmask() if err != nil { return false, err.Error() } - noteMasked(r, "search", hits, sentOf(hits, body), 0, "openai", model) - return s.alphaSearchAsked(w, r, body, model, ons, start) + noteMasked(r, "search", hits, sentOf(hits, body), 0, "openai", ts[0].model) + return s.alphaSearchAsked(w, r, body, ts, start) } // alphaSearchAsked is alphaSearchOn once body is as it goes. -func (s *Server) alphaSearchAsked(w http.ResponseWriter, r *http.Request, body []byte, model string, ons []provider.Provider, start time.Time) (bool, string) { +func (s *Server) alphaSearchAsked(w http.ResponseWriter, r *http.Request, body []byte, ts []searchTarget, start time.Time) (bool, string) { var errs []string - for _, on := range ons { - who := "OpenAI (" + on.Account.User + "): " + for _, t := range ts { + on, model := t.p, t.model + who := on.Name + ": " + if on.Account != nil { + who = "OpenAI (" + on.Account.User + "): " + } ctx := on.Via(r.Context()) - req, err := http.NewRequestWithContext(ctx, http.MethodPost, provider.CodexBase+AlphaSearchPath, bytes.NewReader(body)) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, t.url, bytes.NewReader(withModel(body, model))) if err != nil { errs = append(errs, who+err.Error()) continue @@ -159,6 +240,14 @@ func (s *Server) alphaSearchAsked(w http.ResponseWriter, r *http.Request, body [ req.Header[k] = vs } } + if on.Account == nil { + // a relay is asked as Codex asks it: its originator, and its + // User-Agent where the provider passes it on + if o := r.Header.Get("originator"); o != "" { + req.Header.Set("originator", o) + } + req.Header.Set("User-Agent", userAgentFor(on, r.Header.Get("User-Agent"))) + } req.Header.Set("Content-Type", "application/json") // a nil body: the search is answered in JSON, not streamed if err := on.Sign(ctx, req, provider.Responses, nil); err != nil { diff --git a/internal/gateway/codex_search_relay_test.go b/internal/gateway/codex_search_relay_test.go new file mode 100644 index 000000000..526bdbc5e --- /dev/null +++ b/internal/gateway/codex_search_relay_test.go @@ -0,0 +1,230 @@ +package gateway + +import ( + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "strings" + "sync" + "testing" + + "github.com/yetone/magpie/internal/provider" +) + +// searchingRelay is a fake relay of OpenAI's API that answers Codex's +// web.run at /v1/alpha/search and a turn at /v1/responses, and records +// what reached it. +type searchingRelay struct { + *httptest.Server + mu sync.Mutex + paths []string + bodies []map[string]any + heads []http.Header + status int +} + +func newSearchingRelay(t *testing.T) *searchingRelay { + t.Helper() + f := &searchingRelay{status: 200} + f.Server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + b, _ := io.ReadAll(r.Body) + var q map[string]any + json.Unmarshal(b, &q) + f.mu.Lock() + f.paths = append(f.paths, r.URL.Path) + f.bodies = append(f.bodies, q) + f.heads = append(f.heads, r.Header.Clone()) + status := f.status + f.mu.Unlock() + switch r.URL.Path { + case "/v1/alpha/search": + if status != 200 { + http.Error(w, `{"error":"no search here"}`, status) + return + } + w.Header().Set("Content-Type", "application/json") + io.WriteString(w, `{"encrypted_output":"relay-cipher","output":"OpenAI news from the relay","results":[{"type":"text_result","ref_id":"turn0search0","url":"https://example.com/r"}]}`) + case "/v1/responses": + if q["stream"] == true { + w.Header().Set("Content-Type", "text/event-stream") + io.WriteString(w, "event: response.created\ndata: {\"type\":\"response.created\",\"response\":{\"id\":\"resp_1\",\"object\":\"response\",\"status\":\"in_progress\",\"model\":\"gpt-5.5\",\"output\":[]}}\n\n"+ + "event: response.output_item.done\ndata: {\"type\":\"response.output_item.done\",\"output_index\":0,\"item\":{\"type\":\"message\",\"id\":\"msg_1\",\"role\":\"assistant\",\"status\":\"completed\",\"content\":[{\"type\":\"output_text\",\"text\":\"Go 1.27.1 is out.\",\"annotations\":[]}]}}\n\n"+ + "event: response.completed\ndata: {\"type\":\"response.completed\",\"response\":{\"id\":\"resp_1\",\"object\":\"response\",\"status\":\"completed\",\"model\":\"gpt-5.5\",\"output\":[{\"type\":\"message\",\"id\":\"msg_1\",\"role\":\"assistant\",\"status\":\"completed\",\"content\":[{\"type\":\"output_text\",\"text\":\"Go 1.27.1 is out.\",\"annotations\":[]}]}],\"usage\":{\"input_tokens\":5,\"output_tokens\":5,\"total_tokens\":10}}}\n\n") + return + } + w.Header().Set("Content-Type", "application/json") + io.WriteString(w, `{"id":"resp_1","object":"response","status":"completed","model":"gpt-5.5","output":[{"type":"web_search_call","id":"ws_1","status":"completed","action":{"type":"search","query":"go"}},{"type":"message","id":"msg_1","role":"assistant","status":"completed","content":[{"type":"output_text","text":"Go 1.27.1 is out.","annotations":[]}]}],"usage":{"input_tokens":5,"output_tokens":5,"total_tokens":10}}`) + default: + http.NotFound(w, r) + } + })) + t.Cleanup(f.Close) + return f +} + +func (f *searchingRelay) reached() []string { + f.mu.Lock() + defer f.mu.Unlock() + return append([]string(nil), f.paths...) +} + +func (f *searchingRelay) reset(status int) { + f.mu.Lock() + f.paths, f.bodies, f.heads, f.status = nil, nil, nil, status + f.mu.Unlock() +} + +// A relay of OpenAI's API that runs Codex's web.run itself, set to search +// the web by itself, is sent web.run as Codex sent it: magpie's searcher +// was asked instead, and the relay's own search never used (YIXIE233 on +// X). Not set so, it is searched by magpie as before; set so and failing, +// magpie searches in its place and says why. +func TestCodexWebRunGoesToRelayThatSearches(t *testing.T) { + fresh(t) + relay := newSearchingRelay(t) + apis := newSearchAPIs(t) + if err := provider.SetSearchAPI(apis.api("tavily", "tvly-k")); err != nil { + t.Fatal(err) + } + save := func(searches bool) { + t.Helper() + p := provider.Provider{ID: "relay", Name: "Relay", Key: "relay-k", Responses: relay.URL + "/v1", Models: []string{"gpt-5.5"}, Searches: searches} + if err := provider.Save(p); err != nil { + t.Fatal(err) + } + } + h := New().Handler() + + // off: magpie's search, as before; the relay is asked nothing + save(false) + got := readSearchReply(t, codexSearchPost(h, "/v1/alpha/search", codexSearchBody("relay/gpt-5.5"))) + if !strings.Contains(got.Output, "go1.27.1") || len(relay.reached()) != 0 || len(apis.asked) != 1 { + t.Fatalf("off: %+v, relay %v, apis %v", got, relay.reached(), apis.asked) + } + + // on: the relay's own search, the request as it came, its answer as it is + save(true) + for _, path := range []string{"/v1/alpha/search", CodexPath + "/alpha/search"} { + relay.reset(200) + apis.asked = nil + got = readSearchReply(t, codexSearchPost(h, path, codexSearchBody("relay/gpt-5.5"))) + if got.Output != "OpenAI news from the relay" || got.EncryptedOutput == nil || *got.EncryptedOutput != "relay-cipher" || len(got.Results) != 1 { + t.Fatalf("%s: answered %+v", path, got) + } + if len(apis.asked) != 0 { + t.Fatalf("%s: magpie searched too: %v", path, apis.asked) + } + if p := relay.reached(); len(p) != 1 || p[0] != "/v1/alpha/search" { + t.Fatalf("%s: relay reached %v", path, p) + } + q, hd := relay.bodies[0], relay.heads[0] + cmds, _ := q["commands"].(map[string]any) + if q["model"] != "gpt-5.5" || q["id"] != "search-session" || cmds["open"] == nil || cmds["search_query"] == nil || q["settings"] == nil || q["max_output_tokens"] != float64(2500) { + t.Fatalf("%s: body %v", path, q) + } + if hd.Get("Authorization") != "Bearer relay-k" || hd.Get("x-openai-actor-authorization") != "" || + hd.Get("x-codex-turn-metadata") != `{"turn_id":"t1"}` || hd.Get("originator") != "codex_exec" { + t.Fatalf("%s: headers %v", path, hd) + } + } + + // on, and the relay can't: magpie searches in its place, never ending the turn + relay.reset(404) + apis.asked = nil + got = readSearchReply(t, codexSearchPost(h, "/v1/alpha/search", codexSearchBody("relay/gpt-5.5"))) + if !strings.Contains(got.Output, "Relay's web search failed") || !strings.Contains(got.Output, "404") || + !strings.Contains(got.Output, "go1.27.1") || len(apis.asked) != 1 { + t.Fatalf("relay failing: %+v, apis %v", got, apis.asked) + } +} + +// In a routing group the switch is the member's that a turn goes to: a +// group led by a relay that searches sends web.run to it, one led by a +// provider that doesn't is searched by magpie, though a member after it +// searches. +func TestCodexWebRunInGroupFollowsLeadingMember(t *testing.T) { + fresh(t) + relay := newSearchingRelay(t) + other := newSearchingRelay(t) + apis := newSearchAPIs(t) + if err := provider.SetSearchAPI(apis.api("tavily", "tvly-k")); err != nil { + t.Fatal(err) + } + for _, p := range []provider.Provider{ + {ID: "relay", Name: "Relay", Key: "relay-k", Responses: relay.URL + "/v1", Models: []string{"gpt-5.5"}, Searches: true}, + {ID: "plain", Name: "Plain", Key: "plain-k", Responses: other.URL + "/v1", Models: []string{"gpt-5.5"}}, + } { + if err := provider.Save(p); err != nil { + t.Fatal(err) + } + } + h := New().Handler() + group := func(members ...string) { + t.Helper() + if err := provider.SaveGroup(provider.Group{ID: "g", Name: "G", Members: members, Routing: provider.Ordered}); err != nil { + t.Fatal(err) + } + } + + group("relay/gpt-5.5", "plain/gpt-5.5") + got := readSearchReply(t, codexSearchPost(h, "/v1/alpha/search", codexSearchBody("group/g"))) + if got.Output != "OpenAI news from the relay" || len(apis.asked) != 0 || len(other.reached()) != 0 { + t.Fatalf("relay first: %+v, apis %v, plain %v", got, apis.asked, other.reached()) + } + if relay.bodies[0]["model"] != "gpt-5.5" { + t.Fatalf("relay asked for %v", relay.bodies[0]["model"]) + } + + relay.reset(200) + group("plain/gpt-5.5", "relay/gpt-5.5") + got = readSearchReply(t, codexSearchPost(h, "/v1/alpha/search", codexSearchBody("group/g"))) + if !strings.Contains(got.Output, "go1.27.1") || len(apis.asked) != 1 || len(relay.reached()) != 0 || len(other.reached()) != 0 { + t.Fatalf("plain first: %+v, apis %v, relay %v, plain %v", got, apis.asked, relay.reached(), other.reached()) + } +} + +// Codex's web_search tool on a turn goes to a relay set to search by +// itself as Codex sent it, and magpie's searcher isn't asked; not set so, +// the relay is sent no web_search tool, magpie's search in its place. +func TestResponsesWebSearchToolToRelayThatSearches(t *testing.T) { + fresh(t) + relay := newSearchingRelay(t) + apis := newSearchAPIs(t) + if err := provider.SetSearchAPI(apis.api("tavily", "tvly-k")); err != nil { + t.Fatal(err) + } + body := `{"model":"relay/gpt-5.5","stream":false,"input":[{"role":"user","content":[{"type":"input_text","text":"What is the latest Go release?"}]}],"tools":[{"type":"web_search","external_web_access":true}]}` + ask := func(searches bool) map[string]any { + t.Helper() + if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "relay-k", Responses: relay.URL + "/v1", Models: []string{"gpt-5.5"}, Searches: searches}); err != nil { + t.Fatal(err) + } + relay.reset(200) + apis.asked = nil + rec := httptest.NewRecorder() + New().Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodPost, "/v1/responses", strings.NewReader(body))) + if rec.Code != 200 { + t.Fatalf("%d %s", rec.Code, rec.Body.String()) + } + if len(relay.bodies) == 0 { + t.Fatal("the relay was asked nothing") + } + return relay.bodies[0] + } + hasSearch := func(q map[string]any) bool { + tools, _ := q["tools"].([]any) + for _, x := range tools { + if m, _ := x.(map[string]any); m["type"] == "web_search" { + return true + } + } + return false + } + if q := ask(true); !hasSearch(q) || len(apis.asked) != 0 { + t.Fatalf("on: tools %v, apis %v", q["tools"], apis.asked) + } + if q := ask(false); hasSearch(q) { + t.Fatalf("off: the relay was sent web_search: %v", q["tools"]) + } +} diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index aa2f4e0ce..820a96f1b 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -9990,7 +9990,7 @@ function drawEditor(p, presetID) { if (custom) { const [stk, scb] = tick(t("Searches the web by itself"), !!draft.searches); scb.onchange = () => { draft.searches = scb.checked; }; - const row = field(t("Web search"), stk, t("For a relay in front of Anthropic's or OpenAI's own API: Claude Code's WebSearch and Codex's web_search go to it as they were sent, not through magpie's search. magpie doesn't automatically search with it for other models, but you can name it as the searcher.")); + const row = field(t("Web search"), stk, t("For a relay in front of Anthropic's or OpenAI's API: Claude Code's WebSearch and Codex's web_search and web.run go to it as sent, not through magpie's search. magpie doesn't automatically search with it for other models, but you can name it as the searcher.")); showSearch = () => { for (const e of row) e.style.display = searchable() ? "" : "none"; }; showSearch(); advIn.append(...row); diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index ff4c0bb62..988b18d2c 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -4751,7 +4751,7 @@ const I18N = { "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", - "For a relay in front of Anthropic's or OpenAI's own API: Claude Code's WebSearch and Codex's web_search go to it as they were sent, not through magpie's search. magpie doesn't automatically search with it for other models, but you can name it as the searcher.": "用于 Anthropic 或 OpenAI 官方 API 前的中转:Claude Code 的 WebSearch 和 Codex 的 web_search 原样发给它,不经 magpie 搜索。不会自动用它为其他模型搜索,但可手动选为代搜供应商。", + "For a relay in front of Anthropic's or OpenAI's API: Claude Code's WebSearch and Codex's web_search and web.run go to it as sent, not through magpie's search. magpie doesn't automatically search with it for other models, but you can name it as the searcher.": "用于 Anthropic 或 OpenAI 官方 API 前的中转:Claude Code 的 WebSearch 和 Codex 的联网搜索(web_search、web.run)原样发给它,不经 magpie 搜索。不会自动用它为其他模型搜索,但可手动选为代搜供应商。", "Its models leave the list agents pick from; the routing groups they are in still use them": "它的模型不出现在 Agent 的可选列表里;所在的路由分组仍会使用它们", "Picked: the routing groups it is in use it. Agents don't see it.": "已选:它所在的路由分组会用到。Agent 看不到它。", "Left out of {agents}'s model list, on the Agents page": "已在 Agent 页从 {agents} 的模型列表中隐藏", @@ -10135,7 +10135,7 @@ const I18N = { "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", - "For a relay in front of Anthropic's or OpenAI's own API: Claude Code's WebSearch and Codex's web_search go to it as they were sent, not through magpie's search. magpie doesn't automatically search with it for other models, but you can name it as the searcher.": "用於 Anthropic 或 OpenAI 官方 API 前的中轉:Claude Code 的 WebSearch 和 Codex 的 web_search 原樣發給它,不經 magpie 搜尋。不會自動用它為其他模型搜尋,但可手動選為代搜供應商。", + "For a relay in front of Anthropic's or OpenAI's API: Claude Code's WebSearch and Codex's web_search and web.run go to it as sent, not through magpie's search. magpie doesn't automatically search with it for other models, but you can name it as the searcher.": "用於 Anthropic 或 OpenAI 官方 API 前的中轉:Claude Code 的 WebSearch 和 Codex 的網路搜尋(web_search、web.run)原樣發給它,不經 magpie 搜尋。不會自動用它為其他模型搜尋,但可手動選為代搜供應商。", "Its models leave the list agents pick from; the routing groups they are in still use them": "它的模型不出現在 Agent 的可選列表裡;所在的路由分組仍會使用它們", "Picked: the routing groups it is in use it. Agents don't see it.": "已選:它所在的路由分組會用到。Agent 看不到它。", "Left out of {agents}'s model list, on the Agents page": "已在 Agent 頁從 {agents} 的模型列表中隱藏", @@ -15537,7 +15537,7 @@ const I18N = { "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 だけです", - "For a relay in front of Anthropic's or OpenAI's own API: Claude Code's WebSearch and Codex's web_search go to it as they were sent, not through magpie's search. magpie doesn't automatically search with it for other models, but you can name it as the searcher.": "Anthropic または OpenAI 公式 API の前段にあるリレー向け:Claude Code の WebSearch と Codex の web_search は magpie の検索を通さず、送られたままこのプロバイダに届きます。magpie は他のモデルのためにこれで自動検索はしませんが、検索役として指定することはできます。", + "For a relay in front of Anthropic's or OpenAI's API: Claude Code's WebSearch and Codex's web_search and web.run go to it as sent, not through magpie's search. magpie doesn't automatically search with it for other models, but you can name it as the searcher.": "Anthropic または OpenAI 公式 API の前段にあるリレー向け:Claude Code の WebSearch と Codex の Web 検索(web_search、web.run)は magpie の検索を通さず、送られたままこのプロバイダに届きます。magpie は他のモデルのためにこれで自動検索はしませんが、検索役として指定することはできます。", "Its models leave the list agents pick from; the routing groups they are in still use them": "そのモデルはエージェントが選ぶリストから外れます。所属するルーティンググループでは引き続き使われます", "Picked: the routing groups it is in use it. Agents don't see it.": "選択済み:所属するルーティンググループが使います。エージェントには見えません。", "Left out of {agents}'s model list, on the Agents page": "エージェントページで {agents} のモデル一覧から外されています", @@ -20956,7 +20956,7 @@ const I18N = { "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", - "For a relay in front of Anthropic's or OpenAI's own API: Claude Code's WebSearch and Codex's web_search go to it as they were sent, not through magpie's search. magpie doesn't automatically search with it for other models, but you can name it as the searcher.": "Für ein Relay vor der eigenen API von Anthropic oder OpenAI: WebSearch von Claude Code und web_search von Codex gehen unverändert dorthin, nicht über die Suche von magpie. magpie sucht damit nicht automatisch für andere Modelle, aber Sie können es als Suchdienst festlegen.", + "For a relay in front of Anthropic's or OpenAI's API: Claude Code's WebSearch and Codex's web_search and web.run go to it as sent, not through magpie's search. magpie doesn't automatically search with it for other models, but you can name it as the searcher.": "Für ein Relay vor der eigenen API von Anthropic oder OpenAI: WebSearch von Claude Code und die Websuche von Codex (web_search, web.run) gehen unverändert dorthin, nicht über die Suche von magpie. magpie sucht damit nicht automatisch für andere Modelle, aber Sie können es als Suchdienst festlegen.", "Its models leave the list agents pick from; the routing groups they are in still use them": "Seine Modelle verschwinden aus der Auswahlliste der Agenten; die Weiterleitungsgruppen, in denen sie sind, nutzen sie weiterhin", "Picked: the routing groups it is in use it. Agents don't see it.": "Ausgewählt: Die Weiterleitungsgruppen, in denen es ist, nutzen es. Agenten sehen es nicht.", "Left out of {agents}'s model list, on the Agents page": "Auf der Seite Agenten aus der Modellliste von {agents} genommen", diff --git a/internal/gui/tests/provider-search.test.cjs b/internal/gui/tests/provider-search.test.cjs index 9bf85aee2..1cccfec13 100644 --- a/internal/gui/tests/provider-search.test.cjs +++ b/internal/gui/tests/provider-search.test.cjs @@ -5,7 +5,9 @@ // saved; Save posts it, ticked or not. A relay with only a Chat address has // no API to search on: the row comes once an Anthropic one is typed. A // signed-in account (Codex here) has no such row: magpie knows how it -// searches. In English and Chinese. +// searches. Its note names Codex's web.run, which goes to such a relay +// too (YIXIE233 on X), and reads whole at a phone's width. In English, +// Chinese, Traditional Chinese, Japanese and German. const assert = require("node:assert/strict"); const fs = require("node:fs/promises"); const path = require("node:path"); @@ -59,12 +61,16 @@ function serve(lang, posts) { const words = { en: { tick: "Searches the web by itself", save: "Save", more: "More endpoints", anthropic: "Anthropic URL" }, zh: { tick: "自己能联网搜索", save: "保存", more: "更多端点", anthropic: "Anthropic 地址" }, + "zh-TW": { tick: "自己能聯網搜尋", save: "儲存", more: "更多端點", anthropic: "Anthropic 位址" }, + ja: { tick: "自分でウェブ検索する", save: "保存", more: "その他のエンドポイント", anthropic: "Anthropic URL" }, + de: { tick: "Sucht selbst im Web", save: "Speichern", more: "Weitere Endpunkte", anthropic: "Anthropic-URL" }, }; +const note = "For a relay in front of Anthropic's or OpenAI's API: Claude Code's WebSearch and Codex's web_search and web.run go to it as sent, not through magpie's search. magpie doesn't automatically search with it for other models, but you can name it as the searcher."; for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { - for (const lang of ["en", "zh"]) { + for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) { const w = words[lang]; - const open = async (t, name) => { + const open = async (t, name, width = 900) => { const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); t.after(async () => { if (process.env.ARTIFACT_DIR) { @@ -73,7 +79,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", } await browser.close(); }); - const page = await (await browser.newContext({ viewport: { width: 900, height: 760 }, reducedMotion: "reduce" })).newPage(); + const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage(); page.setDefaultTimeout(5000); page.setDefaultNavigationTimeout(60000); const errors = []; @@ -103,11 +109,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(saved.action, "save"); assert.equal(saved.body.id, "relay"); assert.equal(saved.body.searches, true); - const missing = await page.evaluate(() => [ - "Web search", "Searches the web by itself", - "For a relay in front of Anthropic's or OpenAI's own API: Claude Code's WebSearch and Codex's web_search go to it as they were sent, not through magpie's search. magpie doesn't automatically search with it for other models, but you can name it as the searcher.", - ].filter((k) => !I18N.zh[k])); - assert.deepEqual(missing, [], "every string has its Chinese"); + const missing = await page.evaluate((note) => ["zh", "zh-TW", "ja", "de"].flatMap((l) => + ["Web search", "Searches the web by itself", note].filter((k) => !I18N[l][k] || !I18N[l][note].includes("web.run")).map((k) => l + ": " + k)), note); + assert.deepEqual(missing, [], "every string has its Chinese, Japanese and German, web.run named"); assert.deepEqual(errors, []); }); @@ -139,6 +143,21 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.deepEqual(errors, []); }); + test(`${engine} ${lang}: at a phone's width the note names web.run and reads whole`, async (t) => { + const { page, errors } = await open(t, "Relay", 400); + const tick = page.locator(".editor label.tick", { hasText: w.tick }); + await tick.scrollIntoViewIfNeeded(); + assert.equal(await tick.isVisible(), true); + const shown = await page.evaluate((note) => t(note), note); + assert.match(shown, /web\.run/); + const help = page.locator(".editor").getByText(shown, { exact: true }); + assert.equal(await help.isVisible(), true, "the note is shown"); + const box = await help.boundingBox(); + assert.ok(box.x >= 0 && box.x + box.width <= 400, `the note fits the width: ${JSON.stringify(box)}`); + assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "no sideways scroll"); + assert.deepEqual(errors, []); + }); + test(`${engine} ${lang}: a signed-in account has no such row`, async (t) => { const { page, errors } = await open(t, "Codex"); assert.equal(await page.locator(".editor label.tick", { hasText: w.tick }).count(), 0);