Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

gateway: a provider that searches for some of its models is offered as a searcher, with those models only (01huadalang on Discord)

yetone55b5eca0559e
diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.md
index 93cba585e..4b85de560 100644
--- a/docs/subsystems/gateway-routing.md
+++ b/docs/subsystems/gateway-routing.md
@@ -370,6 +370,21 @@ doesn't count, and hung up after ~315s (#2316). An error before any
`TestSearchQueueKeepsCodexAlive` in
[`search_queue_test.go`](../../internal/gateway/search_queue_test.go).
+## Which providers search for another model
+
+`Searchers()` (Settings › Web search's picker) and `autoSearcher` (magpie's
+own pick) take a provider by `searchRank`, and its models by
+`searchableModel`, from the same rules that send a provider's own search
+tool on (`searchesItself`, `modelSearches`, `remoteSearch`). A provider
+that searches for some of its models only (`searchModels`: Command Code's
+Provider API, `partSearcher`) is offered and picked with those models
+alone, never under `x-cmd-zdr`; before, its searching models were left out
+of both (01huadalang on Discord). A provider none of whose models searches
+by itself, such as a plugin whose `config` hook doesn't set `searches`
+(Trae's), is not a searcher: its models are given magpie's `web_search`,
+and the row's `searchLeftOut` names it. Covered by
+`TestCommandCodeSearchesForOtherModels` and `TestSearcherChosen`.
+
## A searcher that fails or finds nothing
`modelSearch` asks the searcher picked in Settings (or the one magpie picks)
diff --git a/internal/gateway/search.go b/internal/gateway/search.go
index d065b88df..e47ea0627 100644
--- a/internal/gateway/search.go
+++ b/internal/gateway/search.go
@@ -200,6 +200,27 @@ func modelSearches(p provider.Provider, proto provider.Protocol, model string) b
return slices.Contains(searchModels[id][proto], model)
}
+// modelSearchesAny is whether model of p searches by itself on one of
+// p's APIs (modelSearches), where the gateway sends a search for it.
+func modelSearchesAny(p provider.Provider, model string) bool {
+ return slices.ContainsFunc(p.Speaks(), func(proto provider.Protocol) bool { return modelSearches(p, proto, model) })
+}
+
+// partSearcher is a provider of searchModels that searches by itself for
+// those of its models alone, on no API for every model: one magpie may
+// search with, with those models only (searchableModel). Command Code's
+// searched for themselves but were left out of the searcher picker and
+// magpie's own pick (01huadalang on Discord).
+func partSearcher(p provider.Provider) bool {
+ if p.Account != nil || slices.ContainsFunc([]provider.Protocol{provider.Anthropic, provider.Responses, provider.Chat}, func(proto provider.Protocol) bool { return searchesItself(p, proto) }) {
+ return false
+ }
+ if _, ok := searchModels[p.Preset]; ok {
+ return true
+ }
+ return slices.ContainsFunc(p.Speaks(), func(proto provider.Protocol) bool { return searchModelsHosts[provider.HostOf(p.Base(proto))] != "" })
+}
+
// searchHosts are the APIs that search by themselves: OpenAI's, xAI's,
// DeepSeek's, Zhipu's and Z.ai's web_search tool (Zhipu's on its Responses
// API only, DeepSeek's on its Responses and Anthropic APIs: their Chat APIs
@@ -270,6 +291,8 @@ func searchRank(p provider.Provider) int {
return 3
case searchesItself(p, provider.Chat):
return 4
+ case partSearcher(p) && slices.ContainsFunc(p.Available(), func(m catalog.Model) bool { return modelSearchesAny(p, m.ID) }):
+ return 4
case googleAccount(p):
// Gemini on a Google sign-in, by googleSearch (#757)
return 5
@@ -582,7 +605,7 @@ func searcherReady(p provider.Provider) (string, bool) {
// what searchableModel says of a model is the model's and the
// provider's list's, which keptSmallCands is kept by
var keep func(catalog.Model) bool
- if googleAccount(p) || p.IsRemoteMagpie() {
+ if googleAccount(p) || p.IsRemoteMagpie() || partSearcher(p) {
keep = func(m catalog.Model) bool { return searchableModel(p, m.ID) }
}
c, ready := smallReadyOf(p, keptSmallCands(p, "search", keep), provider.Anthropic)
diff --git a/internal/gateway/search_models_test.go b/internal/gateway/search_models_test.go
index ef36e4a69..497a9c28a 100644
--- a/internal/gateway/search_models_test.go
+++ b/internal/gateway/search_models_test.go
@@ -1,10 +1,17 @@
package gateway
import (
+ "encoding/json"
+ "io"
+ "net/http"
+ "net/http/httptest"
+ "slices"
"strings"
+ "sync"
"testing"
"github.com/yetone/magpie/internal/provider"
+ "github.com/yetone/magpie/internal/settings"
)
// Command Code's Provider API searches the web by itself for some of its
@@ -64,3 +71,105 @@ func TestCommandCodeSearchesForSomeModels(t *testing.T) {
save(map[string]string{"x-cmd-zdr": "1"})
run(true)
}
+
+// A model that searches by itself is offered in Settings' searcher picker
+// and picked by magpie by the same rule that sends it the vendor's search
+// tool (modelSearches), not only a provider whose every model searches:
+// Command Code's searching models searched for themselves, but were left
+// out of the picker, so a model that can't search was searched for by
+// another provider or by none (01huadalang on Discord: the picker named
+// Antigravity alone). Only its models that search are offered, and none
+// under its zero-data-retention header.
+func TestCommandCodeSearchesForOtherModels(t *testing.T) {
+ searchSandbox(t)
+ var mu sync.Mutex
+ var asked []string
+ cc := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ b, _ := io.ReadAll(r.Body)
+ if strings.HasSuffix(r.URL.Path, "/models") {
+ io.WriteString(w, `{"data":[{"id":"claude-opus-5-5"},{"id":"deepseek/deepseek-v4-pro"},{"id":"gpt-6-luna"}]}`)
+ return
+ }
+ var q struct {
+ Model string `json:"model"`
+ }
+ json.Unmarshal(b, &q)
+ mu.Lock()
+ asked = append(asked, r.URL.Path+" "+q.Model)
+ mu.Unlock()
+ if r.URL.Path != "/v1/responses" || q.Model != "gpt-6-luna" || !strings.Contains(string(b), `"web_search"`) {
+ http.Error(w, `{"error":{"message":"no search here"}}`, 400)
+ return
+ }
+ w.Header().Set("Content-Type", "text/event-stream")
+ io.WriteString(w, sse(`data: {"type":"response.created","response":{"id":"r1","model":"gpt-6-luna"}}`,
+ `data: {"type":"response.output_item.done","item":{"type":"web_search_call","status":"completed","action":{"type":"search","query":"今天上海天气","sources":[{"type":"url","url":"https://www.weather.com.cn/weather/101020100.shtml"}]}}}`,
+ `data: {"type":"response.output_text.delta","delta":"上海今天小雨,22/17℃。"}`,
+ `data: {"type":"response.completed","response":{"id":"r1","usage":{"input_tokens":4000,"output_tokens":20}}}`))
+ }))
+ t.Cleanup(cc.Close)
+ glm, result := newBlindModel(t)
+ commandCode := func(h map[string]string) provider.Provider {
+ return provider.Provider{ID: "commandcode", Name: "Command Code", Key: "k", Preset: "commandcode", Headers: h,
+ Chat: cc.URL + "/v1", Responses: cc.URL + "/v1", Anthropic: cc.URL,
+ Models: []string{"claude-opus-5-5", "deepseek/deepseek-v4-pro", "gpt-6-luna"}}
+ }
+ save(t, commandCode(nil), provider.Provider{ID: "glm", Name: "GLM", Key: "k", Chat: glm.URL, Models: []string{"glm-flash"}})
+
+ var offered []string
+ for _, c := range Searchers() {
+ for _, m := range c.Models {
+ offered = append(offered, c.Provider.ID+"/"+m.ID)
+ }
+ if c.Provider.ID == "commandcode" && (c.Small != "gpt-6-luna" || c.ManualOnly) {
+ t.Fatalf("Command Code searches with %q, manual only %v", c.Small, c.ManualOnly)
+ }
+ }
+ if !slices.Equal(offered, []string{"commandcode/gpt-6-luna"}) {
+ t.Fatalf("the picker offers %v, want Command Code's gpt-6-luna alone", offered)
+ }
+ if p, m, ok := searcher(); !ok || p.ID != "commandcode" || m != "gpt-6-luna" {
+ t.Fatalf("searcher = %s %s %v", p.ID, m, ok)
+ }
+ st := settings.Load()
+ st.Searcher = "commandcode/claude-opus-5-5" // a model of it that doesn't search
+ if err := settings.Save(st); err != nil {
+ t.Fatal(err)
+ }
+ if p, m, ok := searcher(); !ok || p.ID != "commandcode" || m != "gpt-6-luna" {
+ t.Fatalf("named a model that doesn't search, searcher = %s %s %v", p.ID, m, ok)
+ }
+ st.Searcher = ""
+ if err := settings.Save(st); err != nil {
+ t.Fatal(err)
+ }
+
+ // GLM, which can't search, is searched for by gpt-6-luna on Responses
+ blocks := searchAsClaudeCode(t)
+ mu.Lock()
+ got := slices.Clone(asked)
+ mu.Unlock()
+ if !slices.Equal(got, []string{"/v1/responses gpt-6-luna"}) {
+ t.Fatalf("Command Code asked %q", got)
+ }
+ if len(blocks) != 1 {
+ t.Fatalf("blocks %v", blocks)
+ }
+ if found, _ := blocks[0]["content"].([]any); len(found) != 1 || found[0].(map[string]any)["url"] != "https://www.weather.com.cn/weather/101020100.shtml" {
+ t.Fatalf("found %v", blocks[0])
+ }
+ if r := result(); !strings.Contains(r, "22/17℃") {
+ t.Fatalf("the model was told %q", r)
+ }
+
+ // under x-cmd-zdr none of its models searches, so none is offered
+ save(t, commandCode(map[string]string{"x-cmd-zdr": "1"}))
+ for _, c := range Searchers() {
+ if c.Provider.ID == "commandcode" {
+ t.Errorf("Command Code under x-cmd-zdr offered with %v", c.Models)
+ }
+ }
+ if p, m, ok := searcher(); ok {
+ t.Errorf("under x-cmd-zdr, searcher = %s %s", p.ID, m)
+ }
+}
diff --git a/internal/gateway/search_remote.go b/internal/gateway/search_remote.go
index 94df1a8b2..6cefced91 100644
--- a/internal/gateway/search_remote.go
+++ b/internal/gateway/search_remote.go
@@ -51,14 +51,17 @@ func remoteSearchesAny(p provider.Provider) bool {
}
// searchableModel is a model of p that magpie may search with: a Gemini
-// on a Google sign-in, one a Remote magpie searches natively for, any
-// other provider's.
+// on a Google sign-in, one a Remote magpie searches natively for, one of
+// searchModels that searches by itself (partSearcher), any other
+// provider's.
func searchableModel(p provider.Provider, model string) bool {
switch {
case googleAccount(p):
return searchModel(model)
case p.IsRemoteMagpie():
return remoteSearch(p, model) == searchNative
+ case partSearcher(p):
+ return modelSearchesAny(p, model)
}
return true
}