diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.md index 0efd79738..739aabc5e 100644 --- a/docs/subsystems/gateway-routing.md +++ b/docs/subsystems/gateway-routing.md @@ -639,7 +639,7 @@ Discord) gives a model whose provider searches the web by itself (`searchesFor`) magpie's search too: the searcher and the search APIs, in their usual order, as a model that can't search has. Settings › Models › Web search shows it as "Models that search by themselves", Their own or -magpie's, when magpie has anything to search with. +magpie's; with nothing magpie can search with the row is dimmed and says where to add a search. [`magpieSearches`](../../internal/gateway/search.go) is the one check: on in Settings, magpie can search for this provider (`canSearchFor`), and the request isn't magpie's own searcher request (`searching`), which needs the diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index 33de9fe79..d625d942a 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -3196,7 +3196,7 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; } .opt { position: relative; z-index: 1; white-space: nowrap; height: 22px; padding: 0 10px; border-radius: 5px; font-size: 12px; color: var(--muted); transition: color .18s var(--ease), transform .14s var(--ease); } .opt.on { color: var(--fg); } /* how often magpie checks for updates, while it doesn't by itself */ -.update-every-row.off .segs, .update-restart-row.off .segs { opacity: .55; } +.update-every-row.off .segs, .update-restart-row.off .segs, .search-all-row.off .segs { opacity: .55; } /* Command line: each shell's `magpie`, a dot for whether it runs this app */ .cli-row .sub { overflow-wrap: anywhere; } .cli-shells { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; } diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 9adee451c..53188999f 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -1338,6 +1338,7 @@ const I18N = { "Models that search by themselves": "自带联网搜索的模型", "Search with their provider's own search, or with magpie's, as every other model does": "用供应商自带的联网搜索,或像其他模型一样用 magpie 代搜", "Their own": "自带搜索", + "magpie has nothing to search with: add a Search API above, or pick a provider under Searches for other models": "magpie 现在没有可用的搜索:请在上方添加搜索 API,或在「代搜供应商」里选一个供应商", "magpie's": "magpie 代搜", "When provider search is off, only configured Search APIs are used, for every model. Without a Search API, magpie does not add a search tool.": "关闭供应商代搜后,所有模型都只使用已配置的搜索 API;未配置时,Magpie 不添加搜索工具。", "Model search": "模型代搜", @@ -5577,6 +5578,7 @@ const I18N = { "Models that search by themselves": "自帶聯網搜尋的模型", "Search with their provider's own search, or with magpie's, as every other model does": "用供應商內建的聯網搜尋,或像其他模型一樣用 magpie 代搜", "Their own": "內建搜尋", + "magpie has nothing to search with: add a Search API above, or pick a provider under Searches for other models": "magpie 目前沒有可用的搜尋:請在上方新增搜尋 API,或在「代搜供應商」中選一個供應商", "magpie's": "magpie 代搜", "When provider search is off, only configured Search APIs are used, for every model. Without a Search API, magpie does not add a search tool.": "關閉供應商代搜後,所有模型都只使用已設定的搜尋 API;未設定時,Magpie 不新增搜尋工具。", "Model search": "模型代搜", @@ -9786,6 +9788,7 @@ const I18N = { "Models that search by themselves": "自分でウェブ検索するモデル", "Search with their provider's own search, or with magpie's, as every other model does": "プロバイダのネイティブなウェブ検索を使うか、ほかのモデルと同じく magpie の検索を使います", "Their own": "ネイティブ検索", + "magpie has nothing to search with: add a Search API above, or pick a provider under Searches for other models": "magpie が検索に使えるものがありません。上で検索 API を追加するか、「他のモデルの代わりに検索」でプロバイダを選んでください", "magpie's": "magpie の検索", "When provider search is off, only configured Search APIs are used, for every model. Without a Search API, magpie does not add a search tool.": "プロバイダによる代行検索がオフの場合、どのモデルにも設定済みの検索 API のみを使用します。検索 API がない場合、magpie は検索ツールを追加しません。", "Model search": "モデルによる代理検索", @@ -14026,6 +14029,7 @@ const I18N = { "Models that search by themselves": "Modelle, die selbst suchen", "Search with their provider's own search, or with magpie's, as every other model does": "Mit der nativen Websuche ihres Anbieters oder, wie jedes andere Modell, mit der von magpie", "Their own": "Eigene Suche", + "magpie has nothing to search with: add a Search API above, or pick a provider under Searches for other models": "magpie hat nichts zum Suchen: Füge oben eine Such-API hinzu oder wähle unter „Sucht für andere Modelle“ einen Anbieter", "magpie's": "Von magpie", "When provider search is off, only configured Search APIs are used, for every model. Without a Search API, magpie does not add a search tool.": "Wenn die Anbietersuche ausgeschaltet ist, werden für jedes Modell nur konfigurierte Such-APIs verwendet. Ohne Such-API fügt magpie kein Suchwerkzeug hinzu.", "Model search": "Modellsuche", diff --git a/internal/gui/assets/plugins/search/settings.js b/internal/gui/assets/plugins/search/settings.js index 126005a92..be46077f5 100644 --- a/internal/gui/assets/plugins/search/settings.js +++ b/internal/gui/assets/plugins/search/settings.js @@ -160,14 +160,19 @@ function renderSearch(s, keep) { r.id = "searchFirstRow"; } // a model whose provider searches the web by itself is given magpie's - // search instead, as every other model is (cybercaius on Discord); only - // while magpie has a search to give it - if (s.searchProvider || asked.length) { - const r = row(t("Models that search by themselves"), t("Search with their provider's own search, or with magpie's, as every other model does"), - segs([["own", t("Their own")], ["magpie", t("magpie's")]], s.searchAll ? "magpie" : "own", - (v) => writingPrefs(api("settings/search-all", { on: v === "magpie" })) - .then((ns) => { prefs = state.settings = ns; renderSettings(); }).catch(settingsErr))); + // search instead, as every other model is (cybercaius on Discord). The + // row is always there: with nothing magpie can search with it can't be + // chosen, and says why and where to add a search ("开关在哪个位置") + { + const can = !!(s.searchProvider || asked.length); + const sw = segs([["own", t("Their own")], ["magpie", t("magpie's")]], s.searchAll ? "magpie" : "own", + (v) => writingPrefs(api("settings/search-all", { on: v === "magpie" })) + .then((ns) => { prefs = state.settings = ns; renderSettings(); }).catch(settingsErr)); + if (!can) for (const b of sw.querySelectorAll("button")) b.disabled = true; + const r = row(t("Models that search by themselves"), can ? t("Search with their provider's own search, or with magpie's, as every other model does") + : t("magpie has nothing to search with: add a Search API above, or pick a provider under Searches for other models"), sw); r.id = "searchAllRow"; + r.classList.add("search-all-row", ...(can ? [] : ["off"])); } // the same search as an MCP server of the gateway's (Kayphoon on // Discord), for an agent to mount as its web_search and web_fetch tools diff --git a/internal/gui/tests/search-all.test.cjs b/internal/gui/tests/search-all.test.cjs index d7347ffef..dd8a9f848 100644 --- a/internal/gui/tests/search-all.test.cjs +++ b/internal/gui/tests/search-all.test.cjs @@ -5,7 +5,7 @@ // A click sets searchAll on its own (POST /api/settings/search-all), a save // of the rest of the page doesn't send it (the server keeps it), and the // page isn't moved. With nothing magpie -// can search with the row isn't there. With provider search off and +// can search with the row is there, dimmed, and says why. With provider search off and // searchAll on, the searcher's note no longer says a provider's own search // is unchanged. In every language, wide and narrow. const assert = require("node:assert/strict"); @@ -17,18 +17,18 @@ const { watchSettingsReads, settingsDrawn, reach } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); const words = { - en: { name: "Models that search by themselves", own: "Their own", magpie: "magpie's", apis: "Search APIs", every: "for every model", unchanged: "unchanged" }, - zh: { name: "自带联网搜索的模型", own: "自带搜索", magpie: "magpie 代搜", apis: "搜索 API", every: "所有模型", unchanged: "不受影响" }, - "zh-TW": { name: "自帶聯網搜尋的模型", own: "內建搜尋", magpie: "magpie 代搜", apis: "搜尋 API", every: "所有模型", unchanged: "不受影響" }, - ja: { name: "自分でウェブ検索するモデル", own: "ネイティブ検索", magpie: "magpie の検索", apis: "検索 API", every: "どのモデルにも", unchanged: "影響しません" }, - de: { name: "Modelle, die selbst suchen", own: "Eigene Suche", magpie: "Von magpie", apis: "Such-APIs", every: "für jedes Modell", unchanged: "unverändert" }, + en: { name: "Models that search by themselves", own: "Their own", magpie: "magpie's", apis: "Search APIs", every: "for every model", unchanged: "unchanged", none: "add a Search API" }, + zh: { name: "自带联网搜索的模型", own: "自带搜索", magpie: "magpie 代搜", apis: "搜索 API", every: "所有模型", unchanged: "不受影响", none: "添加搜索 API" }, + "zh-TW": { name: "自帶聯網搜尋的模型", own: "內建搜尋", magpie: "magpie 代搜", apis: "搜尋 API", every: "所有模型", unchanged: "不受影響", none: "新增搜尋 API" }, + ja: { name: "自分でウェブ検索するモデル", own: "ネイティブ検索", magpie: "magpie の検索", apis: "検索 API", every: "どのモデルにも", unchanged: "影響しません", none: "検索 API を追加" }, + de: { name: "Modelle, die selbst suchen", own: "Eigene Suche", magpie: "Von magpie", apis: "Such-APIs", every: "für jedes Modell", unchanged: "unverändert", none: "Such-API hinzu" }, }; function serve(lang, saved, all, { provider = true, apis = true, searcher = "ds", searchAll = false } = {}) { const settings = { lang, theme: "light", redact: true, searcher, searchAll, searchProvider: provider ? "DeepSeek · deepseek-flash" : "", searchVendors: [{ id: "tavily", name: "Tavily", keysURL: "https://app.tavily.com/home" }], - searchAPIs: apis ? [{ vendor: "tavily", name: "Tavily", key: "tvly…abcd", ready: true }] : [], + searchAPIs: apis ? [{ vendor: "tavily", name: "Tavily", key: "tvly…abcd", ready: true, ...(apis === "off" ? { off: true } : {}) }] : [], searchChoices: [{ id: "ds", name: "DeepSeek", icon: "deepseek", small: "deepseek-flash", models: [] }] }; const state = { agents: [], profiles: [], settings }; return async (r) => { @@ -125,10 +125,21 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", }); } - test(`${engine} ${lang}: with nothing magpie can search with there is nothing to choose`, async (t) => { - const { page } = await open(engine, t, lang, [], { provider: false, apis: false }); - await page.locator("#searchList .row.search-add").waitFor(); - assert.equal(await page.locator("#searchAllRow").count(), 0); + test(`${engine} ${lang}: with nothing magpie can search with the row says why and can't be chosen`, async (t) => { + // cybercaius turned the search APIs off and couldn't find the row + // ("开关在哪个位置"): it stays, dimmed, and says where to add a search + const all = []; + const { page } = await open(engine, t, lang, [], { provider: false, apis: "off", searcher: "off" }, 560, all); + const row = page.locator("#searchList #searchAllRow"); + await reach(page, row); + assert.equal(await row.locator(".name").textContent(), w.name); + assert((await row.locator(".sub").innerText()).includes(w.none), await row.locator(".sub").innerText()); + assert.equal(await row.locator(".segs button:disabled").count(), 2, "both choices can't be picked"); + assert(await row.evaluate((r) => r.classList.contains("off"))); + assert(await page.evaluate(() => document.scrollingElement.scrollWidth <= innerWidth), "the page scrolls sideways"); + await row.locator(".segs button", { hasText: w.magpie }).click({ force: true }); + await page.waitForTimeout(200); + assert.deepEqual(all, [], "a dimmed choice saved nothing"); }); test(`${engine} ${lang}: provider search off, every model is searched with the APIs`, async (t) => {