Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
gui: Settings' web search rows move out of app.js to plugins/search/settings.js (#4133)
yetone3959192e947a
diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.mdindex 804c0e924..1e488228d 100644--- a/docs/subsystems/gui-shell.md+++ b/docs/subsystems/gui-shell.md@@ -407,9 +407,9 @@ covers it in both engines, every language and a narrow window.- Settings → General is laid out as macOS System Settings is (1ooogle on X): a row says its name alone when that says enough (Appearance, Colorblind mode, Language, Text size, the fonts, the tray click, Open at login, Show in Dock), and keeps one short line where the setting isn't clear from its name or has a consequence (Lightweight mode, Prevent sleep, Session terminal). Codex's, Claude Code's and Grok Build's own settings (Codex subagents, Long conversations, which is all of Grok Build's, background compaction, thread titles and descriptions, composer predictions, the auto-review and memories models) aren't here: they are in the agent's opened row on the Agents page (`AGENT_PREFS`, `connectPanel`), the panel's row has a Settings line that opens them in a sheet (`openAgentPrefs`), as does the agent's menu, and Settings' search finds them with a row that opens that sheet (`#agentPrefLinks`). Each row is one element moved between its places, so its handlers and state go with it (the owner, 10-20; `agent-prefs.test.cjs`). Long conversations is the exception with no Codex, Claude Code or Grok Build here, in gateway mode or a magpie in Docker: it sets the windows the gateway serves, which agents on other computers read, so it stays in General (`renderAgentPrefLinks`, Linka on Discord). A font row's line shows only while its fonts load or fail; the text size keys are the choices' tooltip, and Colorblind mode's note is its Off/On control's (`#colorblindSegs`). Colorblind mode (`settings.Colorblind`, `data-colorblind="1"` on `:root`, #2073) switches the chart series (`--c1`…`--c7`) in both light and dark themes to an Okabe–Ito palette where adjacent series differ in hue and lightness. On a quota curve each window (`data-series`, its index mod 7, set by `drawQuotaPlot` and `quotaCurve`'s legend only) gets a dash of its own on `path.qc-line`, its legend key shows a sample of that line (`.qc-sample`) for the dot, and the even paces (`line.qc-even`) are dotted; the curve's tooltip says so. The balance curve sets no `data-series` and keeps its solid line, dashed fit and dot. The Context tab's "good" grade, which takes `--c2` as a colour rather than a series, keeps a blue (`--c1`). Language is one menu button showing the language picked, opened in the app's menu (`renderLangPick`). See `settings-general.test.cjs` and `quota-curve.test.cjs`. Open at login reads `autostart.Enabled`, which on macOS 13 and later also asks Background Task Management about magpie's launch agent (`SMAppService.statusForLegacyURL:`, matched by the plist's Label, not its path); a record the user switched off in System Settings › General › Login Items reads as needing allowing, and the row keeps On with one line saying so and a button that opens Login Items (`/api/open` allows that one `x-apple.systempreferences` URL). The status read again when the window comes back to the front clears the line. On macOS 12, in a build without cgo, or when the system can't be asked, the plist alone decides, as before (#2120, `login-allow.test.cjs`, `login_allow_test.go`).- A setting row's line under its name (`.row.pref .sub`, in Settings, Plugins › Built-in and an agent's own settings) wraps whole beside its control, never cut to one line with an ellipsis (arculongus on Discord, `settings-lines-wrap.test.cjs`).-- Settings' search-provider picker offers **Off**, saved as `searcher: "off"`. Its help explains API-only search and suppresses provider fallback/own-search hints while off; the search priority row is hidden because no provider competes with the APIs. See [gateway search behavior](gateway-routing.md#turning-provider-search-off), [`renderSearcher`](../../internal/gui/assets/app.js), `TestSettingsSearchProviderOff` and `searcher-pick.test.cjs`.-- Settings' search APIs are asked in their listed order: each API's row (with its keys' row) is dragged as one, or moved with Alt+↑/↓, and has a switch that turns it off without removing its key (#2286). See [the search APIs' order](gateway-routing.md#the-search-apis-order-and-one-switched-off), `searchArrange` in [`app.js`](../../internal/gui/assets/app.js) and `search-order.test.cjs`.-- Settings' Search APIs add row has a base URL field under the key for every API (#1580): the vendor's own address is its placeholder, picking an API already added fills in its saved URL so a new key alone keeps it, and Add with no key changes only the URL. See [a search API's base URL](gateway-routing.md#a-search-apis-base-url), [`renderSearch`](../../internal/gui/assets/app.js) and `search-api.test.cjs`.+- Settings' search-provider picker offers **Off**, saved as `searcher: "off"`. Its help explains API-only search and suppresses provider fallback/own-search hints while off; the search priority row is hidden because no provider competes with the APIs. See [gateway search behavior](gateway-routing.md#turning-provider-search-off), [`renderSearcher`](../../internal/gui/assets/plugins/search/settings.js), `TestSettingsSearchProviderOff` and `searcher-pick.test.cjs`.+- Settings' search APIs are asked in their listed order: each API's row (with its keys' row) is dragged as one, or moved with Alt+↑/↓, and has a switch that turns it off without removing its key (#2286). See [the search APIs' order](gateway-routing.md#the-search-apis-order-and-one-switched-off), `searchArrange` in [`plugins/search/settings.js`](../../internal/gui/assets/plugins/search/settings.js) and `search-order.test.cjs`.+- Settings' Search APIs add row has a base URL field under the key for every API (#1580): the vendor's own address is its placeholder, picking an API already added fills in its saved URL so a new key alone keeps it, and Add with no key changes only the URL. See [a search API's base URL](gateway-routing.md#a-search-apis-base-url), [`renderSearch`](../../internal/gui/assets/plugins/search/settings.js) and `search-api.test.cjs`.- Every user-visible string has zh, zh-TW, ja and de translations with the same placeholders. `gui-zh-tw.test.cjs`, `gui-ja.test.cjs` and `gui-de.test.cjs` fail on a missing one; `gui-zh-tw.test.cjs` also fails on a zh-TW string with a Simplified character left in it.- A click never moves the page. Code scrolls a view only with the reader's event in hand (`scrollOnPurpose`); `click-scroll.test.cjs` guards this. A click is taken where the reader left the view: a scroll not theirs made just before it, whose scroll event the browser sends only at the next frame, after the click, is put back first (`backToReader` in the click guard, #1554). What was clicked is held where it was (`hold`); a view at its top when clicked stays at its top, and what comes in above the control moves it down instead (#2134, `update-auto.test.cjs`), as long as it moves less than half its own height and so stays under the pointer. When what the click does leaves the page shorter under it (a list emptied), the view keeps room at its foot for it to stay (`.view-room`), room that goes as the reader scrolls back. A control under what it unrolls (`data-unrolls`, "Show 7 more") goes down with what it opens: what's held is the part it is in, so the rows open downwards. Anything larger above it, as the stage a day picked on Routing brings in above the bar, is scrolled past, and the control stays where it was clicked (`routing-days-fit.test.cjs`, `routing-failed-open.test.cjs`).- A scroll not the reader's is put back, so every way the reader scrolls has to count as theirs: the wheel and a trackpad's coast after the lift (WebKit on the Mac plays the coast itself and the page hears its scrolls with no wheel for each, so the wheel starts the same chain a touch fling does, `flings`/`flingUntil`: each scroll keeps the next one the reader's till it rests, and a click ends it; issenn on Discord, `view-trackpad-coast.test.cjs`), a wheel or coast the page is never told of (macOS 13's WebKit, Safari 16.6's, scrolled a view under wheels it never dispatched, so every scroll was put back and only the bar's drag moved the page: three scrolls put back the same way within a second are taken as the reader's run and given back, and so is each one after it that goes on the same way within a second of the last, so a wheel turned slowly or on a loaded Mac loses no step; a scroll by code is one, not a run, and two at rest are still put back; issenn on Discord, `view-wheel-unheard.test.cjs`. Under a click's 4s hold the same holds: only a put-back that comes with the page redrawn since the hold last held (`redrawn`: the view's height or where the first held parts sit moved from `h.lay`) is the hold's and never counts toward a run, so a profile opened on the Agents page and wheeled through at once scrolls, issennknight on Discord, `view-wheel-after-click.test.cjs`. The parts `h.lay` measures are those still in the page that scroll with it: a part drawn again since (the Usage page's tabs, the agents' list under an agent opened or closed) is a redraw once, not at every scroll, and a sticky one (Settings' tabs at a narrow width) is left out, as it sits still while the page scrolls; `view-wheel-after-redraw.test.cjs`), a touch and its fling, the keys, a drag, the scrollbar's own drag (`barDrag`, #1089) and the middle button's autoscroll (`panning`, 多喝热水 on Discord). Chromium and WebView2 give the autoscroll a press of button 1 and then no event of the reader's while it scrolls; from that press the view follows it till Chromium ends it, on the next press (which reaches the page only as a pointerup), a key (a keyup), or the lift after the mouse moved while held. A field the guard brings back into view after putting a scroll back is one focused since the reader last scrolled that view, not one they scrolled away from (`scrolledFrom`): the middle press focuses the button under it. See `view-middle-autoscroll.test.cjs`.diff --git a/docs/subsystems/plugin-runtime.md b/docs/subsystems/plugin-runtime.mdindex 4277469fb..1a5e3e451 100644--- a/docs/subsystems/plugin-runtime.md+++ b/docs/subsystems/plugin-runtime.md@@ -242,7 +242,7 @@ it, on or off.| --- | --- | --- || `gwtool` | `Serve(name)` serves a tool until its remove; `Gate()` makes every tool wait on `Serve` until its stop; `Served(name)` is not gated, or served. The gateway holds `Gate` while it serves (`ListenAndServe`, `TestServingGatesTools`), so a process not serving it (the CLI, the TUI, an agent's config written there) has every tool, as before the point. `WebSearch` is the search's name. | [`gwtool.go`](../../internal/gwtool/gwtool.go), [`gateway.go`](../../internal/gateway/gateway.go) || Off | `searchServed` gates the three places every search path goes through: `canSearch` (the stand-in tool, `/v1/models`' search note to another magpie, the subscriptions' search, `CanSearch` for the agents' rows), `searchesOwn` (a Kimi Code or WorkBuddy plan's own search service, a Google sign-in's Gemini) and `webSearch` itself, which answers `errSearchOff` without asking a searcher or a search API. So off, a request with `web_search` goes to the vendor as it does with no searcher set up, and the MCP server and Codex's search say the plugin is off (`TestSearchOnAndOff`). | [`search.go`](../../internal/gateway/search.go), [`search_api.go`](../../internal/gateway/search_api.go), [`search_kimi.go`](../../internal/gateway/search_kimi.go) |-| `plugins/search` | Requires `settings` and `gateway`, Essential. Apply serves `gwtool.WebSearch`. `InUse` counts the search APIs set up (`provider.SearchAPIsSet`, the file alone) and a searcher picked in Settings (neither magpie's pick nor off); an unreadable providers.json or settings.json is an error, so it stays on. The gateway's `KeepFresh` watches both files, so a search API added from the CLI or the window turns it on within 2s. | [`search.go`](../../plugins/search/search.go) |+| `plugins/search` | Requires `settings` and `gateway`, Essential. Apply serves `gwtool.WebSearch`. `InUse` counts the search APIs set up (`provider.SearchAPIsSet`, the file alone) and a searcher picked in Settings (neither magpie's pick nor off); an unreadable providers.json or settings.json is an error, so it stays on. The gateway's `KeepFresh` watches both files, so a search API added from the CLI or the window turns it on within 2s. Settings › Models › Web search's rows are its script in the window, `plugins/search/settings.js`, loaded after app.js and drawn whether it is on or off (#4133). | [`search.go`](../../plugins/search/search.go), [`settings.js`](../../internal/gui/assets/plugins/search/settings.js) |## Gateway extension points (P3): budgetdiff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.jsindex 7b0ae8c3f..3096831bf 100644--- a/internal/gui/assets/app.js+++ b/internal/gui/assets/app.js@@ -21275,370 +21275,6 @@ function mcpAddress(s, path) {return ((web && s.publicURL) || s.gateway || providers?.gateway?.url || `http://127.0.0.1:${s.port || 3425}`).replace(/\/+$/, "") + path;}-// renderSearch: the web search APIs a model's search goes to when no-// provider can search (#419) — one row each, in the order they are tried,-// and a row to add one: which API, its key, and the address of one the user-// runs (SearXNG). They are set on their own; one magpie refuses is said in-// the row, what was typed kept.-let searchDraft = { vendor: "tavily", key: "", url: "", err: "" };-function renderSearch(s, keep) {- const box = $("#searchList");- box.replaceChildren();- renderSearcher(s, keep, box);- // rows go into the box, or into a search API's own unit (its row and its- // keys' row), which is dragged as one (#2286)- let into = box;- const row = (name, sub, ...tools) => {- const r = el("div", "row pref");- const who = el("div", "who");- who.append(el("div", "name", name), el("div", "sub", sub));- const val = el("div", "val");- val.append(...tools);- r.append(who, val);- into.append(r);- return r;- };- const set = (body, done) => writingPrefs(api("settings/search-api", body))- .then((ns) => { prefs = ns; searchDraft.err = ""; done?.(); renderSettings(); status(t("Saved"), "ok", 1500); })- .catch((e) => { searchDraft.err = e.message; status(e.message, "err"); renderSettings(); });- const vendors = s.searchVendors || [];- const d = searchDraft;- if (!vendors.some((v) => v.id === d.vendor)) d.vendor = vendors[0]?.id || "";- const vendor = () => vendors.find((v) => v.id === d.vendor) || {};- // the one of the picked vendor already added: Add then changes it, its- // key kept when none is typed- const saved = () => (s.searchAPIs || []).find((a) => a.vendor === d.vendor);- const pick = el("button", "proto pick search-vendor");- pick.type = "button";- pick.setAttribute("aria-label", t("Search API"));- const key = input(d.key, t("API key"), "password");- // any API's base URL (#1580): an endpoint of the user's own that answers- // as that API does; empty is the vendor's own, a SearXNG's is required- const url = input(d.url, "https://searx.example.com");- key.className = "words search-key";- url.className = "words search-url";- key.setAttribute("aria-label", t("API key"));- const get = el("button", "link", t("Get a key ↗"));- get.onclick = () => vendor().keysURL && api("open", { url: vendor().keysURL });- const draw = () => {- const v = vendor();- pick.replaceChildren(el("span", "", v.name || ""), svg(CHEV, 11, 1.6));- // the address it is set at shows in the field, so changing its key- // never puts the vendor's own back in its place- if (d.urlOf !== d.vendor) { d.url = saved()?.url || ""; d.urlOf = d.vendor; }- url.value = d.url;- url.placeholder = v.needURL ? "https://searx.example.com" : t("Base URL, empty for {url}", { url: v.base || "" });- url.setAttribute("aria-label", v.needURL ? t("Address") : t("Base URL"));- key.placeholder = v.needURL ? t("API key, if it needs one")- : saved()?.key ? t("A new key, or empty to keep {key}", { key: saved().key })- : v.keyOptional ? t("API key, or empty for its free search")- : t("API key, or several split by commas");- get.hidden = !v.keysURL;- };- pick.onclick = (e) => {- e.stopPropagation();- if (pick.classList.contains("open")) return closeProtoMenu();- openProtoMenu(pick, vendors.map((v) => ({ v: v.id, name: v.name, note: v.needURL ? t("your own") : "" })), d.vendor,- (id) => { d.vendor = id; draw(); }, "Search API");- };- const add = el("button", "text", t("Add"));- add.onclick = () => {- d.key = key.value.trim(); d.url = url.value.trim();- // one added before keeps its key when none is typed- // You.com is asked at its free search with none (#1626)- if (vendor().needURL ? !d.url : !d.key && !saved()?.key && !vendor().keyOptional) return (vendor().needURL ? url : key).focus();- set({ vendor: d.vendor, key: d.key, url: d.url },- () => { searchDraft = { vendor: d.vendor, key: "", url: "", err: "" }; });- };- for (const i of [key, url]) {- i.oninput = () => { d.key = key.value; d.url = url.value; };- i.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") add.onclick(); };- }- draw();- // the ones a search asks: one switched off is kept, never asked (#2286)- const asked = (s.searchAPIs || []).filter((a) => !a.off);- const apiFirst = s.searchFirst === "api" && asked.length > 0;- const by = s.searcher === "off" ? t("Provider search is off; only these APIs are used")- : !s.searchProvider ? t("No provider can search, so these are asked")- : apiFirst ? t("Asked before {who}, which searches when these fail", { who: s.searchProvider })- : t("Now done by {who}; these come after it", { who: s.searchProvider });- const head = row(t("Search APIs"), d.err || t("When a model can't search the web, magpie searches for it with these, in this order, and gives it what they found") + " · " + by,- pick, key, get, add, url);- head.classList.add("rule-row", "search-add");- head.querySelector(".val").classList.add("rule-add");- if (d.err) head.querySelector(".sub").classList.add("err");- const units = [];- (s.searchAPIs || []).forEach((a, n) => {- const unit = el("div", "search-unit" + (a.off ? " off" : ""));- unit.dataset.vendor = a.vendor;- box.append(unit);- into = unit;- units.push(unit);- const x = el("button", "text", t("Remove"));- x.onclick = () => set({ vendor: a.vendor, remove: true });- const what = [a.key || (a.ready ? "" : t("needs its key")), a.url].filter(Boolean).join(" · ");- const tools = [x];- if (a.key) {- // its saved key shown in its row and hidden again, as a provider's- // editor does (OnurBen on Discord)- const eye = el("button", "text search-eye", t("Show"));- eye.onclick = async () => {- const sub = r.querySelector(".sub");- if (eye.textContent === t("Show")) {- try { sub.textContent = [(await api("settings/search-key", { vendor: a.vendor })).key, a.url].filter(Boolean).join(" · "); } catch (e) { status(e.message, "err"); return; }- sub.classList.add("revealed");- eye.textContent = t("Hide");- } else {- sub.textContent = what;- sub.classList.remove("revealed");- eye.textContent = t("Show");- }- };- const cp = el("button", "text search-copy", t("Copy"));- cp.onclick = async () => {- try { copy((await api("settings/search-key", { vendor: a.vendor })).key, t("API key"), cp); } catch (e) { status(e.message, "err"); }- };- tools.unshift(eye, cp);- }- // switched off it stays, key and all, and no search asks it (#2286)- const sw = el("button", "lib-switch use-credits search-on" + (a.off ? "" : " on"));- sw.type = "button";- sw.setAttribute("role", "switch");- sw.setAttribute("aria-checked", String(!a.off));- sw.setAttribute("aria-label", t("Ask {name}", { name: a.name }));- sw.title = a.off ? t("Off: kept with its key, and never asked") : t("On: asked in its turn");- sw.append(el("i"));- sw.onclick = () => {- if (sw.disabled) return;- sw.disabled = true;- set({ vendor: a.vendor, on: !!a.off });- };- tools.push(sw);- const r = row(`${n + 1}. ${a.name}`, a.off ? [t("Off"), what].filter(Boolean).join(" · ") : what, ...tools);- r.classList.add("search-api");- // with-keys, not :has(), which Safari before 15.4 can't parse- if (a.keys > 1 || a.quota) { unit.classList.add("with-keys"); searchKeysRow(s, a, row, set); }- into = box;- });- searchArrange(box, units, set);- // which goes first when both a provider and a search API can search- // (#928); with only one of them there is nothing to choose- if (s.searchProvider && asked.length) {- const r = row(t("Search first with"), t("The other is asked when it fails"),- segs([["model", t("Model search")], ["api", t("Search APIs")]], apiFirst ? "api" : "model",- (v) => savePrefs({ ...keep, searchFirst: v === "api" ? "api" : "" })));- r.id = "searchFirstRow";- }- // 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- const mcpURL = mcpAddress(s, "/mcp/magpie/web-search");- const mcp = row(t("MCP server"), t("Cursor, Claude Desktop and other agents can add this search as an MCP server (Streamable HTTP), with a web_search tool and a web_fetch tool that reads a page by its URL. From another computer, send a gateway key as Authorization: Bearer <key>."),- el("code", "", mcpURL), copyBtn(mcpURL, t("Address")));- mcp.id = "searchMcpRow";-}--// searchArrange: the search APIs are asked in the order they are listed,-// and put in another by dragging one anywhere off its buttons, or with-// Alt+↑/↓ on it (#2286, as routing's groups are, #779). The new order-// shows at once and is put back when it can't be saved.-let searchArranging = false;-function searchArrange(box, units, set) {- if (units.length < 2) return;- const move = (unit, to) => {- const from = units.indexOf(unit);- to = Math.max(0, Math.min(units.length - 1, to));- for (const u of units) u.style.transform = "";- if (to === from) return;- // moving a node in the page takes the keyboard off it- const focus = document.activeElement === unit;- const order = units.map((u) => u.dataset.vendor);- order.splice(to, 0, ...order.splice(from, 1));- const anchor = units.at(-1).nextSibling;- const next = order.map((v) => units.find((u) => u.dataset.vendor === v));- for (const u of next) box.insertBefore(u, anchor);- // a second move before the page is drawn again goes from this order- units.splice(0, units.length, ...next);- next.forEach((u, i) => {- const name = u.querySelector(".search-api .name");- if (name) name.textContent = name.textContent.replace(/^\d+\./, `${i + 1}.`);- });- if (focus) unit.focus({ preventScroll: true });- set({ arrange: order }, () => {- if (focus) requestAnimationFrame(() => document.querySelector(`#searchList .search-unit[data-vendor="${CSS.escape(unit.dataset.vendor)}"]`)?.focus({ preventScroll: true }));- });- // a refused order: set draws the page again from what is saved, the- // order as it was- };- for (const unit of units) {- const name = unit.querySelector(".search-api .name")?.textContent || "";- unit.tabIndex = 0;- unit.setAttribute("role", "group");- unit.setAttribute("aria-label", name + " · " + t("Drag to reorder · Alt+↑/↓ to move"));- unit.title = t("Drag to reorder · Alt+↑/↓ to move");- unit.prepend(el("span", "grip"));- unit.addEventListener("click", (e) => {- if (unit.dataset.dragged) { e.preventDefault(); e.stopImmediatePropagation(); }- }, true);- unit.onkeydown = (e) => {- if (e.target !== unit || !e.altKey || !["ArrowUp", "ArrowDown"].includes(e.key) || searchArranging) return;- e.preventDefault(); e.stopPropagation();- move(unit, units.indexOf(unit) + (e.key === "ArrowUp" ? -1 : 1));- };- unit.onpointerdown = (e) => {- if (searchArranging || e.target.closest("input, textarea, select, a, button, code, .segs, .sub.revealed")) return;- searchArranging = dragRows(e, unit, unit, box, units, (to) => move(unit, to), () => {},- () => { searchArranging = false; });- };- }-}--// searchKeysRow: under a search API with several keys, or one whose keys-// quota magpie can read (Tavily's), a row of its keys (SlouchyQuill on-// Discord): how a search picks among them, in turn (the default) or in-// order, and what each has used of its limit, read once as the page is-// drawn and again on Check again. A read that fails says unknown and why,-// never 0; a key a search set aside lately says why and until when.-const searchQuotaSeen = {};-function searchKeysRow(s, a, row, set) {- const tools = [];- if (a.keys > 1) tools.push(segs([["", t("In turn")], ["order", t("In order")]], a.pick || "",- (v) => set({ vendor: a.vendor, pick: v || "turns" })));- const mine = el("div", "search-quota");- const seenAs = [a.key, a.url].join(" ");- const ask = (fresh) => {- searchQuotaSeen[a.vendor] = { as: seenAs, loading: true };- draw();- api("settings/search-quota", { vendor: a.vendor, fresh })- .then((r) => { searchQuotaSeen[a.vendor] = { as: seenAs, keys: r.keys || [] }; })- .catch((e) => { searchQuotaSeen[a.vendor] = { as: seenAs, err: e.message }; })- .finally(draw);- };- // the list in the page now: Settings may have been drawn again while- // the read was out- const draw = () => {- const list = document.querySelector(`.search-keys[data-vendor="${a.vendor}"] .search-quota`) || mine;- const seen = searchQuotaSeen[a.vendor];- list.replaceChildren();- if (!seen || seen.loading) return list.append(el("div", "faint", t("Reading what each key has used…")));- if (seen.err) return list.append(el("div", "err", t("Unknown: {why}", { why: seen.err })));- const num = (n) => Number(n).toLocaleString(intlLang());- for (const q of seen.keys) {- const line = el("div", "quota-key");- const said = !q.known ? t("Unknown: {why}", { why: q.err || "" })- : q.unlimited ? t("{used} used, no limit", { used: num(q.used) })- : t("{used} of {limit} used", { used: num(q.used), limit: num(q.limit) });- const notes = [];- if (q.known && q.of === "plan") notes.push(q.plan ? t("{plan} plan, shared by its account's keys", { plan: q.plan }) : t("the plan's, shared by its account's keys"));- if (q.paygoLeft > 0) notes.push(t("{n} pay-as-you-go left", { n: num(q.paygoLeft) }));- if (q.resting) notes.push(t("asked last until {time}: {why}", { time: hhmm(q.restUntil),- why: { "turned away": t("turned away"), "out of credit": t("out of credit"), "rate limited": t("rate limited"), "used up": t("used up") }[q.resting] || q.resting }));- const used = el("span", q.known ? (q.usedUp ? "used warn" : "used") : "used err", said);- line.append(el("code", "", q.key), used);- if (q.usedUp) line.append(el("span", "warn", t("used up")));- if (notes.length) line.append(el("span", "faint", notes.join(" · ")));- list.append(line);- }- };- if (a.quota) {- const again = el("button", "text search-quota-again", t("Check again"));- again.onclick = () => ask(true);- tools.push(again);- }- const r = row(t("Keys of {name}", { name: a.name }),- a.keys > 1 ? t("In turn spreads searches over the keys; in order uses the first until it is refused. A key refused lately is asked last.") : t("What the key has used of its limit"),- ...tools);- r.classList.add("search-keys");- r.dataset.vendor = a.vendor;- if (a.quota) {- r.querySelector(".who").append(mine);- if (searchQuotaSeen[a.vendor]?.as !== seenAs) ask(false);- else draw();- }-}--// renderSearcher: the provider that searches the web for a model that-// can't — the one magpie picks, or one named, by itself (its small model)-// or with a model of it. One named that is gone, off or can't search gives-// way to magpie's pick, which the row says. Relays said to search can be-// named, but are never picked automatically (#359), and the row says so.-function renderSearcher(s, keep, box) {- const choices = s.searchChoices || [];- const v = s.searcher || "";- const off = v === "off";- const named = (id) => {- const [pid, ...rest] = id.split("/");- const c = choices.find((x) => x.id === pid);- if (!c) return id;- if (c.service) return `${c.name} · ${t("its web search")}`;- if (!rest.length) return `${c.name} · ${c.smallName || c.small}`;- const m = c.models.find((x) => x.id === id);- return `${m ? m.name : rest.join("/")} · ${c.name}`;- };- const icOf = (id) => choices.find((x) => x.id === id.split("/")[0])?.icon;- const r = el("div", "row pref searcher-row");- const who = el("div", "who");- const sub = el("div", "sub", off ? t("When provider search is off, only configured Search APIs are used. Without a Search API, magpie does not add a search tool. Providers' native web search is unchanged.") : t("When a model can't search the web directly, the selected provider searches for it and returns the results. Searches may use the service's quota or incur charges; if the provider magpie picks fails, it tries other available sources, but a provider you select here is never replaced by another provider, only by your Search APIs."));- if (!off && v && s.searchUnused) {- const why = { gone: t("it is no longer in magpie"), off: t("it is turned off"), cant: t("it can't search the web by itself"), nomodel: t("it lists no model") }[s.searchUnused] || s.searchUnused;- sub.append(" · ", el("span", "warn searcher-unused", t("{who} isn't used: {why}, so magpie picks one", { who: named(v), why })));- }- // the one named didn't search last time, and no other provider searched- // in its place (Gearclickist on Discord: Grok picked answered without- // searching, and Codex's pricier model searched instead, unasked). First,- // so it reads before the help.- const failed = s.searchFailed;- if (!off && v && !s.searchUnused && failed) {- const why = failed.notSearched ? t("it answered without searching the web, so its account or plan may not offer web search") : failed.nothingFound ? t("its reply named no page it found") : failed.why || t("it failed");- sub.prepend(el("span", "warn searcher-failed", t("{who} didn't search {when}: {why}. No other provider searched in its place; pick Automatic or another provider, or add a Search API.", { who: named(v), when: ago(failed.at), why })), " · ");- }- const plans = choices.filter((c) => c.service).map((c) => c.name);- if (!off && plans.length) sub.append(" · ", el("span", "searcher-own",- t("A Kimi Code plan ({names}) searches for its own models first, with its web search; for other models only when named here", { names: plans.join(", ") })));- const googles = choices.filter((c) => c.own).map((c) => c.name);- if (!off && googles.length) sub.append(" · ", el("span", "searcher-own",- t("{names} search for their own models first, with Gemini's Google Search", { names: googles.join(", ") })));- if (!off && s.searchRelays?.length) sub.append(" · ", el("span", "searcher-relays",- t("These relays must be selected manually and are not used for automatic selection or fallback: {names}.", { names: s.searchRelays.join(", ") })));- // Being left out can also mean no usable model, not just no search support.- if (!off && s.searchLeftOut?.length) sub.append(" · ", el("span", "searcher-left-out",- t("These providers can't be selected to search for other models with the current configuration: {names}. Their models can still get search results through other available search providers or configured search APIs.", { names: s.searchLeftOut.length > 6- ? t("{names} and {n} more", { names: s.searchLeftOut.slice(0, 5).join(", "), n: s.searchLeftOut.length - 5 })- : s.searchLeftOut.join(", ") })));- who.append(el("div", "name", t("Searches for other models")), sub);- const b = el("button", "rt-cond on searcher-pick");- b.type = "button";- b.setAttribute("aria-label", t("Searches for other models"));- if (off) b.append(el("span", "", t("Off")));- else if (v && !s.searchUnused) b.append(icon(icOf(v) || "generic"), el("span", "", named(v)));- else {- if (s.searchAuto) b.append(icon(choices[0]?.icon || "generic"));- b.append(el("span", "", t("Automatic") + " · " + (s.searchAuto || t("no provider that searches"))));- }- const options = [{ value: "", label: t("Automatic"), note: s.searchAuto || t("no provider that searches"), reset: true },- { value: "off", label: t("Off"), note: t("Search APIs"), reset: true }];- for (const c of choices) {- if (c.service) {- options.push({ value: c.id, label: t("its web search"), note: c.name, icon: c.icon, group: c.name });- continue;- }- // its small model is offered once (Player on Discord): the model of the- // same name below it searched just the same, "<provider>/<small>" being- // that model named rather than magpie's pick, so a pick saved so is- // ticked here. No "via magpie": no agent asks for these- const small = c.small ? `${c.id}/${c.small}` : "";- options.push({ value: v === small ? small : c.id, label: t("{model}, its small model", { model: c.smallName || c.small }), note: c.name, icon: c.icon, group: c.name });- for (const m of c.models) if (m.id !== small) options.push({ value: m.id, label: m.name || m.id, note: c.name, icon: c.icon, group: c.name });- }- b.onclick = (ev) => openPicker({ id: "", name: "", fields: [] }, { key: "searcher", label: "model", value: v, options,- onPick: (id) => { if (id !== v) savePrefs({ ...keep, searcher: id }); } }, b, ev);- const val = el("div", "val");- val.append(b);- if (!off) sideEffortChip(val, s.searchEfforts, s.searcherEffort || "", s.searchEffortNow, "searcher-effort",- "none sent, the model's own", (e) => savePrefs({ ...keep, searcherEffort: e }));- r.append(who, val);- box.append(r);-}-// sideEffortChip: beside a model magpie asks on its own (Image// recognition's, the searcher's), how hard it thinks (MOMO on Discord,// "外置模型能不能提供思考深度选项"): only the levels that model has, anddiff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.htmlindex f97f27226..33c1cb326 100644--- a/internal/gui/assets/index.html+++ b/internal/gui/assets/index.html@@ -525,6 +525,7 @@<script src="plugins/redact/demo.js"></script><script src="plugins/otel/page.js"></script><script src="plugins/gateway/settings.js"></script>+<script src="plugins/search/settings.js"></script><script src="start.js"></script></body></html>diff --git a/internal/gui/assets/plugins/search/settings.js b/internal/gui/assets/plugins/search/settings.jsnew file mode 100644index 000000000..68614bc72--- /dev/null+++ b/internal/gui/assets/plugins/search/settings.js@@ -0,0 +1,370 @@+// Settings › Models › Web search's rows (the search plugin's part of+// Settings): the provider that searches for a model that can't, and the+// search APIs tried when no provider can, with their keys and order. Run+// after app.js, whose helpers it shares (el, segs, input, api, writingPrefs,+// dragRows, openPicker, sideEffortChip, savePrefs), and before start.js+// draws Settings.++// renderSearch: the web search APIs a model's search goes to when no+// provider can search (#419) — one row each, in the order they are tried,+// and a row to add one: which API, its key, and the address of one the user+// runs (SearXNG). They are set on their own; one magpie refuses is said in+// the row, what was typed kept.+let searchDraft = { vendor: "tavily", key: "", url: "", err: "" };+function renderSearch(s, keep) {+ const box = $("#searchList");+ box.replaceChildren();+ renderSearcher(s, keep, box);+ // rows go into the box, or into a search API's own unit (its row and its+ // keys' row), which is dragged as one (#2286)+ let into = box;+ const row = (name, sub, ...tools) => {+ const r = el("div", "row pref");+ const who = el("div", "who");+ who.append(el("div", "name", name), el("div", "sub", sub));+ const val = el("div", "val");+ val.append(...tools);+ r.append(who, val);+ into.append(r);+ return r;+ };+ const set = (body, done) => writingPrefs(api("settings/search-api", body))+ .then((ns) => { prefs = ns; searchDraft.err = ""; done?.(); renderSettings(); status(t("Saved"), "ok", 1500); })+ .catch((e) => { searchDraft.err = e.message; status(e.message, "err"); renderSettings(); });+ const vendors = s.searchVendors || [];+ const d = searchDraft;+ if (!vendors.some((v) => v.id === d.vendor)) d.vendor = vendors[0]?.id || "";+ const vendor = () => vendors.find((v) => v.id === d.vendor) || {};+ // the one of the picked vendor already added: Add then changes it, its+ // key kept when none is typed+ const saved = () => (s.searchAPIs || []).find((a) => a.vendor === d.vendor);+ const pick = el("button", "proto pick search-vendor");+ pick.type = "button";+ pick.setAttribute("aria-label", t("Search API"));+ const key = input(d.key, t("API key"), "password");+ // any API's base URL (#1580): an endpoint of the user's own that answers+ // as that API does; empty is the vendor's own, a SearXNG's is required+ const url = input(d.url, "https://searx.example.com");+ key.className = "words search-key";+ url.className = "words search-url";+ key.setAttribute("aria-label", t("API key"));+ const get = el("button", "link", t("Get a key ↗"));+ get.onclick = () => vendor().keysURL && api("open", { url: vendor().keysURL });+ const draw = () => {+ const v = vendor();+ pick.replaceChildren(el("span", "", v.name || ""), svg(CHEV, 11, 1.6));+ // the address it is set at shows in the field, so changing its key+ // never puts the vendor's own back in its place+ if (d.urlOf !== d.vendor) { d.url = saved()?.url || ""; d.urlOf = d.vendor; }+ url.value = d.url;+ url.placeholder = v.needURL ? "https://searx.example.com" : t("Base URL, empty for {url}", { url: v.base || "" });+ url.setAttribute("aria-label", v.needURL ? t("Address") : t("Base URL"));+ key.placeholder = v.needURL ? t("API key, if it needs one")+ : saved()?.key ? t("A new key, or empty to keep {key}", { key: saved().key })+ : v.keyOptional ? t("API key, or empty for its free search")+ : t("API key, or several split by commas");+ get.hidden = !v.keysURL;+ };+ pick.onclick = (e) => {+ e.stopPropagation();+ if (pick.classList.contains("open")) return closeProtoMenu();+ openProtoMenu(pick, vendors.map((v) => ({ v: v.id, name: v.name, note: v.needURL ? t("your own") : "" })), d.vendor,+ (id) => { d.vendor = id; draw(); }, "Search API");+ };+ const add = el("button", "text", t("Add"));+ add.onclick = () => {+ d.key = key.value.trim(); d.url = url.value.trim();+ // one added before keeps its key when none is typed+ // You.com is asked at its free search with none (#1626)+ if (vendor().needURL ? !d.url : !d.key && !saved()?.key && !vendor().keyOptional) return (vendor().needURL ? url : key).focus();+ set({ vendor: d.vendor, key: d.key, url: d.url },+ () => { searchDraft = { vendor: d.vendor, key: "", url: "", err: "" }; });+ };+ for (const i of [key, url]) {+ i.oninput = () => { d.key = key.value; d.url = url.value; };+ i.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") add.onclick(); };+ }+ draw();+ // the ones a search asks: one switched off is kept, never asked (#2286)+ const asked = (s.searchAPIs || []).filter((a) => !a.off);+ const apiFirst = s.searchFirst === "api" && asked.length > 0;+ const by = s.searcher === "off" ? t("Provider search is off; only these APIs are used")+ : !s.searchProvider ? t("No provider can search, so these are asked")+ : apiFirst ? t("Asked before {who}, which searches when these fail", { who: s.searchProvider })+ : t("Now done by {who}; these come after it", { who: s.searchProvider });+ const head = row(t("Search APIs"), d.err || t("When a model can't search the web, magpie searches for it with these, in this order, and gives it what they found") + " · " + by,+ pick, key, get, add, url);+ head.classList.add("rule-row", "search-add");+ head.querySelector(".val").classList.add("rule-add");+ if (d.err) head.querySelector(".sub").classList.add("err");+ const units = [];+ (s.searchAPIs || []).forEach((a, n) => {+ const unit = el("div", "search-unit" + (a.off ? " off" : ""));+ unit.dataset.vendor = a.vendor;+ box.append(unit);+ into = unit;+ units.push(unit);+ const x = el("button", "text", t("Remove"));+ x.onclick = () => set({ vendor: a.vendor, remove: true });+ const what = [a.key || (a.ready ? "" : t("needs its key")), a.url].filter(Boolean).join(" · ");+ const tools = [x];+ if (a.key) {+ // its saved key shown in its row and hidden again, as a provider's+ // editor does (OnurBen on Discord)+ const eye = el("button", "text search-eye", t("Show"));+ eye.onclick = async () => {+ const sub = r.querySelector(".sub");+ if (eye.textContent === t("Show")) {+ try { sub.textContent = [(await api("settings/search-key", { vendor: a.vendor })).key, a.url].filter(Boolean).join(" · "); } catch (e) { status(e.message, "err"); return; }+ sub.classList.add("revealed");+ eye.textContent = t("Hide");+ } else {+ sub.textContent = what;+ sub.classList.remove("revealed");+ eye.textContent = t("Show");+ }+ };+ const cp = el("button", "text search-copy", t("Copy"));+ cp.onclick = async () => {+ try { copy((await api("settings/search-key", { vendor: a.vendor })).key, t("API key"), cp); } catch (e) { status(e.message, "err"); }+ };+ tools.unshift(eye, cp);+ }+ // switched off it stays, key and all, and no search asks it (#2286)+ const sw = el("button", "lib-switch use-credits search-on" + (a.off ? "" : " on"));+ sw.type = "button";+ sw.setAttribute("role", "switch");+ sw.setAttribute("aria-checked", String(!a.off));+ sw.setAttribute("aria-label", t("Ask {name}", { name: a.name }));+ sw.title = a.off ? t("Off: kept with its key, and never asked") : t("On: asked in its turn");+ sw.append(el("i"));+ sw.onclick = () => {+ if (sw.disabled) return;+ sw.disabled = true;+ set({ vendor: a.vendor, on: !!a.off });+ };+ tools.push(sw);+ const r = row(`${n + 1}. ${a.name}`, a.off ? [t("Off"), what].filter(Boolean).join(" · ") : what, ...tools);+ r.classList.add("search-api");+ // with-keys, not :has(), which Safari before 15.4 can't parse+ if (a.keys > 1 || a.quota) { unit.classList.add("with-keys"); searchKeysRow(s, a, row, set); }+ into = box;+ });+ searchArrange(box, units, set);+ // which goes first when both a provider and a search API can search+ // (#928); with only one of them there is nothing to choose+ if (s.searchProvider && asked.length) {+ const r = row(t("Search first with"), t("The other is asked when it fails"),+ segs([["model", t("Model search")], ["api", t("Search APIs")]], apiFirst ? "api" : "model",+ (v) => savePrefs({ ...keep, searchFirst: v === "api" ? "api" : "" })));+ r.id = "searchFirstRow";+ }+ // 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+ const mcpURL = mcpAddress(s, "/mcp/magpie/web-search");+ const mcp = row(t("MCP server"), t("Cursor, Claude Desktop and other agents can add this search as an MCP server (Streamable HTTP), with a web_search tool and a web_fetch tool that reads a page by its URL. From another computer, send a gateway key as Authorization: Bearer <key>."),+ el("code", "", mcpURL), copyBtn(mcpURL, t("Address")));+ mcp.id = "searchMcpRow";+}++// searchArrange: the search APIs are asked in the order they are listed,+// and put in another by dragging one anywhere off its buttons, or with+// Alt+↑/↓ on it (#2286, as routing's groups are, #779). The new order+// shows at once and is put back when it can't be saved.+let searchArranging = false;+function searchArrange(box, units, set) {+ if (units.length < 2) return;+ const move = (unit, to) => {+ const from = units.indexOf(unit);+ to = Math.max(0, Math.min(units.length - 1, to));+ for (const u of units) u.style.transform = "";+ if (to === from) return;+ // moving a node in the page takes the keyboard off it+ const focus = document.activeElement === unit;+ const order = units.map((u) => u.dataset.vendor);+ order.splice(to, 0, ...order.splice(from, 1));+ const anchor = units.at(-1).nextSibling;+ const next = order.map((v) => units.find((u) => u.dataset.vendor === v));+ for (const u of next) box.insertBefore(u, anchor);+ // a second move before the page is drawn again goes from this order+ units.splice(0, units.length, ...next);+ next.forEach((u, i) => {+ const name = u.querySelector(".search-api .name");+ if (name) name.textContent = name.textContent.replace(/^\d+\./, `${i + 1}.`);+ });+ if (focus) unit.focus({ preventScroll: true });+ set({ arrange: order }, () => {+ if (focus) requestAnimationFrame(() => document.querySelector(`#searchList .search-unit[data-vendor="${CSS.escape(unit.dataset.vendor)}"]`)?.focus({ preventScroll: true }));+ });+ // a refused order: set draws the page again from what is saved, the+ // order as it was+ };+ for (const unit of units) {+ const name = unit.querySelector(".search-api .name")?.textContent || "";+ unit.tabIndex = 0;+ unit.setAttribute("role", "group");+ unit.setAttribute("aria-label", name + " · " + t("Drag to reorder · Alt+↑/↓ to move"));+ unit.title = t("Drag to reorder · Alt+↑/↓ to move");+ unit.prepend(el("span", "grip"));+ unit.addEventListener("click", (e) => {+ if (unit.dataset.dragged) { e.preventDefault(); e.stopImmediatePropagation(); }+ }, true);+ unit.onkeydown = (e) => {+ if (e.target !== unit || !e.altKey || !["ArrowUp", "ArrowDown"].includes(e.key) || searchArranging) return;+ e.preventDefault(); e.stopPropagation();+ move(unit, units.indexOf(unit) + (e.key === "ArrowUp" ? -1 : 1));+ };+ unit.onpointerdown = (e) => {+ if (searchArranging || e.target.closest("input, textarea, select, a, button, code, .segs, .sub.revealed")) return;+ searchArranging = dragRows(e, unit, unit, box, units, (to) => move(unit, to), () => {},+ () => { searchArranging = false; });+ };+ }+}++// searchKeysRow: under a search API with several keys, or one whose keys+// quota magpie can read (Tavily's), a row of its keys (SlouchyQuill on+// Discord): how a search picks among them, in turn (the default) or in+// order, and what each has used of its limit, read once as the page is+// drawn and again on Check again. A read that fails says unknown and why,+// never 0; a key a search set aside lately says why and until when.+const searchQuotaSeen = {};+function searchKeysRow(s, a, row, set) {+ const tools = [];+ if (a.keys > 1) tools.push(segs([["", t("In turn")], ["order", t("In order")]], a.pick || "",+ (v) => set({ vendor: a.vendor, pick: v || "turns" })));+ const mine = el("div", "search-quota");+ const seenAs = [a.key, a.url].join(" ");+ const ask = (fresh) => {+ searchQuotaSeen[a.vendor] = { as: seenAs, loading: true };+ draw();+ api("settings/search-quota", { vendor: a.vendor, fresh })+ .then((r) => { searchQuotaSeen[a.vendor] = { as: seenAs, keys: r.keys || [] }; })+ .catch((e) => { searchQuotaSeen[a.vendor] = { as: seenAs, err: e.message }; })+ .finally(draw);+ };+ // the list in the page now: Settings may have been drawn again while+ // the read was out+ const draw = () => {+ const list = document.querySelector(`.search-keys[data-vendor="${a.vendor}"] .search-quota`) || mine;+ const seen = searchQuotaSeen[a.vendor];+ list.replaceChildren();+ if (!seen || seen.loading) return list.append(el("div", "faint", t("Reading what each key has used…")));+ if (seen.err) return list.append(el("div", "err", t("Unknown: {why}", { why: seen.err })));+ const num = (n) => Number(n).toLocaleString(intlLang());+ for (const q of seen.keys) {+ const line = el("div", "quota-key");+ const said = !q.known ? t("Unknown: {why}", { why: q.err || "" })+ : q.unlimited ? t("{used} used, no limit", { used: num(q.used) })+ : t("{used} of {limit} used", { used: num(q.used), limit: num(q.limit) });+ const notes = [];+ if (q.known && q.of === "plan") notes.push(q.plan ? t("{plan} plan, shared by its account's keys", { plan: q.plan }) : t("the plan's, shared by its account's keys"));+ if (q.paygoLeft > 0) notes.push(t("{n} pay-as-you-go left", { n: num(q.paygoLeft) }));+ if (q.resting) notes.push(t("asked last until {time}: {why}", { time: hhmm(q.restUntil),+ why: { "turned away": t("turned away"), "out of credit": t("out of credit"), "rate limited": t("rate limited"), "used up": t("used up") }[q.resting] || q.resting }));+ const used = el("span", q.known ? (q.usedUp ? "used warn" : "used") : "used err", said);+ line.append(el("code", "", q.key), used);+ if (q.usedUp) line.append(el("span", "warn", t("used up")));+ if (notes.length) line.append(el("span", "faint", notes.join(" · ")));+ list.append(line);+ }+ };+ if (a.quota) {+ const again = el("button", "text search-quota-again", t("Check again"));+ again.onclick = () => ask(true);+ tools.push(again);+ }+ const r = row(t("Keys of {name}", { name: a.name }),+ a.keys > 1 ? t("In turn spreads searches over the keys; in order uses the first until it is refused. A key refused lately is asked last.") : t("What the key has used of its limit"),+ ...tools);+ r.classList.add("search-keys");+ r.dataset.vendor = a.vendor;+ if (a.quota) {+ r.querySelector(".who").append(mine);+ if (searchQuotaSeen[a.vendor]?.as !== seenAs) ask(false);+ else draw();+ }+}++// renderSearcher: the provider that searches the web for a model that+// can't — the one magpie picks, or one named, by itself (its small model)+// or with a model of it. One named that is gone, off or can't search gives+// way to magpie's pick, which the row says. Relays said to search can be+// named, but are never picked automatically (#359), and the row says so.+function renderSearcher(s, keep, box) {+ const choices = s.searchChoices || [];+ const v = s.searcher || "";+ const off = v === "off";+ const named = (id) => {+ const [pid, ...rest] = id.split("/");+ const c = choices.find((x) => x.id === pid);+ if (!c) return id;+ if (c.service) return `${c.name} · ${t("its web search")}`;+ if (!rest.length) return `${c.name} · ${c.smallName || c.small}`;+ const m = c.models.find((x) => x.id === id);+ return `${m ? m.name : rest.join("/")} · ${c.name}`;+ };+ const icOf = (id) => choices.find((x) => x.id === id.split("/")[0])?.icon;+ const r = el("div", "row pref searcher-row");+ const who = el("div", "who");+ const sub = el("div", "sub", off ? t("When provider search is off, only configured Search APIs are used. Without a Search API, magpie does not add a search tool. Providers' native web search is unchanged.") : t("When a model can't search the web directly, the selected provider searches for it and returns the results. Searches may use the service's quota or incur charges; if the provider magpie picks fails, it tries other available sources, but a provider you select here is never replaced by another provider, only by your Search APIs."));+ if (!off && v && s.searchUnused) {+ const why = { gone: t("it is no longer in magpie"), off: t("it is turned off"), cant: t("it can't search the web by itself"), nomodel: t("it lists no model") }[s.searchUnused] || s.searchUnused;+ sub.append(" · ", el("span", "warn searcher-unused", t("{who} isn't used: {why}, so magpie picks one", { who: named(v), why })));+ }+ // the one named didn't search last time, and no other provider searched+ // in its place (Gearclickist on Discord: Grok picked answered without+ // searching, and Codex's pricier model searched instead, unasked). First,+ // so it reads before the help.+ const failed = s.searchFailed;+ if (!off && v && !s.searchUnused && failed) {+ const why = failed.notSearched ? t("it answered without searching the web, so its account or plan may not offer web search") : failed.nothingFound ? t("its reply named no page it found") : failed.why || t("it failed");+ sub.prepend(el("span", "warn searcher-failed", t("{who} didn't search {when}: {why}. No other provider searched in its place; pick Automatic or another provider, or add a Search API.", { who: named(v), when: ago(failed.at), why })), " · ");+ }+ const plans = choices.filter((c) => c.service).map((c) => c.name);+ if (!off && plans.length) sub.append(" · ", el("span", "searcher-own",+ t("A Kimi Code plan ({names}) searches for its own models first, with its web search; for other models only when named here", { names: plans.join(", ") })));+ const googles = choices.filter((c) => c.own).map((c) => c.name);+ if (!off && googles.length) sub.append(" · ", el("span", "searcher-own",+ t("{names} search for their own models first, with Gemini's Google Search", { names: googles.join(", ") })));+ if (!off && s.searchRelays?.length) sub.append(" · ", el("span", "searcher-relays",+ t("These relays must be selected manually and are not used for automatic selection or fallback: {names}.", { names: s.searchRelays.join(", ") })));+ // Being left out can also mean no usable model, not just no search support.+ if (!off && s.searchLeftOut?.length) sub.append(" · ", el("span", "searcher-left-out",+ t("These providers can't be selected to search for other models with the current configuration: {names}. Their models can still get search results through other available search providers or configured search APIs.", { names: s.searchLeftOut.length > 6+ ? t("{names} and {n} more", { names: s.searchLeftOut.slice(0, 5).join(", "), n: s.searchLeftOut.length - 5 })+ : s.searchLeftOut.join(", ") })));+ who.append(el("div", "name", t("Searches for other models")), sub);+ const b = el("button", "rt-cond on searcher-pick");+ b.type = "button";+ b.setAttribute("aria-label", t("Searches for other models"));+ if (off) b.append(el("span", "", t("Off")));+ else if (v && !s.searchUnused) b.append(icon(icOf(v) || "generic"), el("span", "", named(v)));+ else {+ if (s.searchAuto) b.append(icon(choices[0]?.icon || "generic"));+ b.append(el("span", "", t("Automatic") + " · " + (s.searchAuto || t("no provider that searches"))));+ }+ const options = [{ value: "", label: t("Automatic"), note: s.searchAuto || t("no provider that searches"), reset: true },+ { value: "off", label: t("Off"), note: t("Search APIs"), reset: true }];+ for (const c of choices) {+ if (c.service) {+ options.push({ value: c.id, label: t("its web search"), note: c.name, icon: c.icon, group: c.name });+ continue;+ }+ // its small model is offered once (Player on Discord): the model of the+ // same name below it searched just the same, "<provider>/<small>" being+ // that model named rather than magpie's pick, so a pick saved so is+ // ticked here. No "via magpie": no agent asks for these+ const small = c.small ? `${c.id}/${c.small}` : "";+ options.push({ value: v === small ? small : c.id, label: t("{model}, its small model", { model: c.smallName || c.small }), note: c.name, icon: c.icon, group: c.name });+ for (const m of c.models) if (m.id !== small) options.push({ value: m.id, label: m.name || m.id, note: c.name, icon: c.icon, group: c.name });+ }+ b.onclick = (ev) => openPicker({ id: "", name: "", fields: [] }, { key: "searcher", label: "model", value: v, options,+ onPick: (id) => { if (id !== v) savePrefs({ ...keep, searcher: id }); } }, b, ev);+ const val = el("div", "val");+ val.append(b);+ if (!off) sideEffortChip(val, s.searchEfforts, s.searcherEffort || "", s.searchEffortNow, "searcher-effort",+ "none sent, the model's own", (e) => savePrefs({ ...keep, searcherEffort: e }));+ r.append(who, val);+ box.append(r);+}diff --git a/internal/gui/core_budget_test.go b/internal/gui/core_budget_test.goindex 380832670..523a78183 100644--- a/internal/gui/core_budget_test.go+++ b/internal/gui/core_budget_test.go@@ -15,8 +15,8 @@ import (// so a page can't quietly grow back into the core; a change that needs more// raises them and says why in its commit.const (- appScriptBudget = 1_313_704 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%; a dialog growing out of the row that opened it and folding back into it, the core's own since every page's dialogs open through it (10-20); Codex's and Claude Code's own settings moved from Settings into the agent's row on the Agents page, the core's own since the tray panel and the window both draw them (10-20); 1,314,432 with Settings › Privacy's record of what was masked (its summary, the records view and the local model's controls), which belongs to Settings, the core's own, plus 1.5%; 1,336,481 with a provider's Names & levels saying Provider in model names is Settings' and opening it there (joe), and Settings' Image recognition saying where a custom provider's model is marked (nexnull), both in the core's own pages, with no room added (10-23); 1,337,633 with Settings › Models › Replies' Intent classifier timeout (#2934, reyoung), Settings' own row, drawn by waitRow, which the Image generation timeout's row now shares, with no room added; 1,337,735 with the provider editor's link naming a partner's page by its own host (siteHost) instead of usemagpie.ai's /go link, the core's own editor, with no room added (10-23); 1,338,084 with Check in now saying what the press came to (claimed +credits, already today, not available yet) where it said "refreshed" (#3326), the check-in row the tray panel draws too, the core's own, with no room added (10-23); 1,338,929 with a new partner's tile keeping a small dot until it is opened, in the add sheet, the core's own, with no room added (10-23); 1,343,324 with the sidebar's open-page row marked by one shape that moves on a spring (navTopGo), the window's own shell, which every page sits beside, with no room added (10-23); 1,343,465 with a dialog kept centred while its content comes in, until it is pressed (holdModal, every page's dialogs), the core's own, with no room added (10-24); 1,317,486 with what masking did moved out to Insights › Masking (plugins/redact), the budget lowered to it (10-24); 1,321,336 with Codex's one subagent model, its card's square saying plainly what each choice does and a row with a name in its sheet, where two squares read alike (the owner), the Agents page's, which the tray panel draws too, the core's own, with no room added (10-24); 1,321,424 with Settings › Models' Image generation MCP server row beside Image recognition's (JonahFu on X), the two drawn by one helper (mcpRow), Settings' own, with no room added (10-25); 1,321,994 with a provider of the user's set never to rest for a limit (zoecats), the provider editor's Advanced row, the core's own editor, with no room added (10-25); 1,322,289 with Settings › Privacy's Keep a key's form under Mask secrets (Charles Cao on X), Settings' own row, with no room added (10-25); 1,322,537 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,323,401 with the tray panel drawing its last allowances at once and asking for them beside the state (#3160, #3134), the tray panel's, the core's own, and the 4 bytes 84c50f032 added, with no room added (10-25); 1,326,105 with many releases' notes merged into one list by kind, each line with its version (the owner), in the update sheet and What's new, with no room added (10-25); 1,321,319 with Settings › Observability moved out to its plugin (plugins/otel/page.js) and its Langfuse setup there (an X user), the budget lowered to it (10-26); a quota card whose window is used but names no reset no longer saying "Not used yet" (windy on Discord) raised it to 1,321,347, and back to 1,321,319 with Settings' model pickers sharing one row helper (modelOpt) where six kept their own copy, no raise (10-26); 1,325,845 with every slow page's skeletons getting magpie's bird hopping bar to bar (skelBird, the owner after the Plugins page's README), one bird for the window over whatever page or dialog is loading, the core's own, with no room added (10-26); 1,310,129 with Settings › Network and sharing's gateway rows (its port, bare ids, local network, allowed addresses, web pages) moved out to the gateway plugin (plugins/gateway/settings.js), the budget lowered to it (10-27); 1,310,269 with Test models naming the first model that failed and its error in the status line, where it said only how many (ysm119 on Discord), the provider editor's, the core's own, with no room added (10-27); 1,310,460 with Settings › About's Website row linking usemagpie.ai (the owner), Settings' own row, with no room added (10-27); 1,309,669 with a pool's Stop at the caps and Check usage near a cap ticks under a provider's accounts (plugins#349), the core's own editor, its account rows' Remove and add rows each drawn by one helper (forgetOf, addRow), with no room added (10-28); 1,311,681 with Install another agent on the Agents page naming the agents Plugins has (More in Plugins) and opening Plugins at its Agents (the owner), the Agents page's, the core's own, with no room added (10-28); 1,311,735 with More in Plugins in sight while Install another agent is folded (the owner), with no room added (10-29); 1,313,704 with a window whose WebKit scrolls under wheels it never tells of (macOS 13) remembered once seen, a scroll at rest then waiting 120ms for a second the same way within 80ms before it is put back, kept for a late wheel to give back (waitsBack), and a load landing under the wheel keeping the reader's way (backAfterLoad, issennknight), the window's own scroll guard, with no room added (10-29)- coreScriptBudget = 1_532_830 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added; 1,535,084 with the sidebar's spring, with no room added; 1,549,478 with the context window card's map (tiles by tokens, the default look, the block grid a switch away) and its text view showing an inline image, in context.js, which the Routing page draws as well as Usage, so the core's own, with no room added (10-24); 1,550,768 with a usage card's refresh opening after its text (#840's card, which the tray panel draws too), the Add key spinner, and a dialog kept centred while its content comes in, with no room added (10-24); 1,524,789 with what masking did moved out to Insights › Masking, lowered to it; 1,528,525 with Codex's one subagent model, with no room added (10-24); 1,528,972 with the Image generation MCP server row (JonahFu on X), with no room added (10-25); 1,529,542 with the limit-rest row (zoecats), with no room added (10-25); 1,529,837 with Keep a key's form (Charles Cao on X), with no room added (10-25); 1,530,050 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,530,631 with a plugin's page growing to its README on the dialog's spring instead of in one jump (the owner), the Plugins page's, in plugins.js, with no room added (10-25); 1,533,445 with the context map counting its tokens on as a live request grows, a tile pointed at keeping its tip, a tool's gathered results saying how many and the small files their folder (the owner, after flohoeller's map on X), in context.js, which the Routing page draws as well as Usage, and the 4 bytes 84c50f032 added to app.js (Settings' Version row) without a raise, with no room added (10-25); 1,534,312 with the tray panel's last allowances drawn at once (#3160, #3134), with no room added (10-25); 1,537,016 with many releases' notes merged into one list by kind (the owner), in app.js, with no room added (10-25); 1,542,244 with a plugin's README loading under magpie's bird bouncing down its lines instead of pulsing bars (the owner), the Plugins page's, in plugins.js, with no room added (10-26); 1,542,418 with a page plugin's sidebar tab coming and going as it is installed, switched on or off, or removed, instead of on the Plugins page's next load (the owner), in plugins.js, with no room added (10-26); 1,537,645 with Settings › Observability moved out to plugins/otel, lowered to it (10-26); 1,537,673 with a used window with no reset not "Not used yet" (windy on Discord), and back to 1,537,645 with Settings' model pickers sharing modelOpt (10-26); 1,541,967 with every slow page's skeletons getting magpie's bird (skelBird, the owner), in app.js, the README's bird sharing its drawing and styles, with no room added (10-26); 1,526,251 with Settings' gateway rows moved out to plugins/gateway/settings.js, lowered to it (10-27); 1,526,391 with Test models naming the first failed model and its error (ysm119 on Discord), in app.js, with no room added (10-27); 1,526,556 with About's Website row (the owner), in app.js, with no room added (10-27); 1,526,500 with a pool's cap ticks (plugins#349), in app.js, with no room added (10-28); 1,527,245 with About's Open-source licenses row and dialog (the owner), in app.js, with no room added (10-28); 1,528,076 with the Partners heading's light (the owner), in app.js, with no room added (10-28); 1,530,449 with Install another agent's More in Plugins row (the owner), in app.js, and Plugins opening at its Agents, in plugins.js, with no room added (10-28); 1,530,807 with layout.js measuring the scrollbar into --bar, which every page's right padding takes off so its sides match (the owner), the window's own shell, with no room added (10-28); 1,530,861 with More in Plugins in sight while Install another agent is folded (the owner), in app.js, with no room added (10-29); 1,532,830 with waitsBack and backAfterLoad (issennknight, macOS 13), the window's own scroll guard, in app.js, with no room added (10-29)+ appScriptBudget = 1_311_735 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%; a dialog growing out of the row that opened it and folding back into it, the core's own since every page's dialogs open through it (10-20); Codex's and Claude Code's own settings moved from Settings into the agent's row on the Agents page, the core's own since the tray panel and the window both draw them (10-20); 1,314,432 with Settings › Privacy's record of what was masked (its summary, the records view and the local model's controls), which belongs to Settings, the core's own, plus 1.5%; 1,336,481 with a provider's Names & levels saying Provider in model names is Settings' and opening it there (joe), and Settings' Image recognition saying where a custom provider's model is marked (nexnull), both in the core's own pages, with no room added (10-23); 1,337,633 with Settings › Models › Replies' Intent classifier timeout (#2934, reyoung), Settings' own row, drawn by waitRow, which the Image generation timeout's row now shares, with no room added; 1,337,735 with the provider editor's link naming a partner's page by its own host (siteHost) instead of usemagpie.ai's /go link, the core's own editor, with no room added (10-23); 1,338,084 with Check in now saying what the press came to (claimed +credits, already today, not available yet) where it said "refreshed" (#3326), the check-in row the tray panel draws too, the core's own, with no room added (10-23); 1,338,929 with a new partner's tile keeping a small dot until it is opened, in the add sheet, the core's own, with no room added (10-23); 1,343,324 with the sidebar's open-page row marked by one shape that moves on a spring (navTopGo), the window's own shell, which every page sits beside, with no room added (10-23); 1,343,465 with a dialog kept centred while its content comes in, until it is pressed (holdModal, every page's dialogs), the core's own, with no room added (10-24); 1,317,486 with what masking did moved out to Insights › Masking (plugins/redact), the budget lowered to it (10-24); 1,321,336 with Codex's one subagent model, its card's square saying plainly what each choice does and a row with a name in its sheet, where two squares read alike (the owner), the Agents page's, which the tray panel draws too, the core's own, with no room added (10-24); 1,321,424 with Settings › Models' Image generation MCP server row beside Image recognition's (JonahFu on X), the two drawn by one helper (mcpRow), Settings' own, with no room added (10-25); 1,321,994 with a provider of the user's set never to rest for a limit (zoecats), the provider editor's Advanced row, the core's own editor, with no room added (10-25); 1,322,289 with Settings › Privacy's Keep a key's form under Mask secrets (Charles Cao on X), Settings' own row, with no room added (10-25); 1,322,537 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,323,401 with the tray panel drawing its last allowances at once and asking for them beside the state (#3160, #3134), the tray panel's, the core's own, and the 4 bytes 84c50f032 added, with no room added (10-25); 1,326,105 with many releases' notes merged into one list by kind, each line with its version (the owner), in the update sheet and What's new, with no room added (10-25); 1,321,319 with Settings › Observability moved out to its plugin (plugins/otel/page.js) and its Langfuse setup there (an X user), the budget lowered to it (10-26); a quota card whose window is used but names no reset no longer saying "Not used yet" (windy on Discord) raised it to 1,321,347, and back to 1,321,319 with Settings' model pickers sharing one row helper (modelOpt) where six kept their own copy, no raise (10-26); 1,325,845 with every slow page's skeletons getting magpie's bird hopping bar to bar (skelBird, the owner after the Plugins page's README), one bird for the window over whatever page or dialog is loading, the core's own, with no room added (10-26); 1,310,129 with Settings › Network and sharing's gateway rows (its port, bare ids, local network, allowed addresses, web pages) moved out to the gateway plugin (plugins/gateway/settings.js), the budget lowered to it (10-27); 1,310,269 with Test models naming the first model that failed and its error in the status line, where it said only how many (ysm119 on Discord), the provider editor's, the core's own, with no room added (10-27); 1,310,460 with Settings › About's Website row linking usemagpie.ai (the owner), Settings' own row, with no room added (10-27); 1,309,669 with a pool's Stop at the caps and Check usage near a cap ticks under a provider's accounts (plugins#349), the core's own editor, its account rows' Remove and add rows each drawn by one helper (forgetOf, addRow), with no room added (10-28); 1,311,681 with Install another agent on the Agents page naming the agents Plugins has (More in Plugins) and opening Plugins at its Agents (the owner), the Agents page's, the core's own, with no room added (10-28); 1,311,735 with More in Plugins in sight while Install another agent is folded (the owner), with no room added (10-29); 1,313,704 with a window whose WebKit scrolls under wheels it never tells of (macOS 13) remembered once seen, a scroll at rest then waiting 120ms for a second the same way within 80ms before it is put back, kept for a late wheel to give back (waitsBack), and a load landing under the wheel keeping the reader's way (backAfterLoad, issennknight), the window's own scroll guard, with no room added (10-29); back to 1,311,735 with Settings › Models › Web search's rows (renderSearch, renderSearcher, the search APIs' keys) moved out to the search plugin (plugins/search/settings.js), app.js 1,292,527 after it, not lowered further since what is left plus 1.5% is over it (#4133, 10-29)+ coreScriptBudget = 1_530_861 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added; 1,535,084 with the sidebar's spring, with no room added; 1,549,478 with the context window card's map (tiles by tokens, the default look, the block grid a switch away) and its text view showing an inline image, in context.js, which the Routing page draws as well as Usage, so the core's own, with no room added (10-24); 1,550,768 with a usage card's refresh opening after its text (#840's card, which the tray panel draws too), the Add key spinner, and a dialog kept centred while its content comes in, with no room added (10-24); 1,524,789 with what masking did moved out to Insights › Masking, lowered to it; 1,528,525 with Codex's one subagent model, with no room added (10-24); 1,528,972 with the Image generation MCP server row (JonahFu on X), with no room added (10-25); 1,529,542 with the limit-rest row (zoecats), with no room added (10-25); 1,529,837 with Keep a key's form (Charles Cao on X), with no room added (10-25); 1,530,050 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,530,631 with a plugin's page growing to its README on the dialog's spring instead of in one jump (the owner), the Plugins page's, in plugins.js, with no room added (10-25); 1,533,445 with the context map counting its tokens on as a live request grows, a tile pointed at keeping its tip, a tool's gathered results saying how many and the small files their folder (the owner, after flohoeller's map on X), in context.js, which the Routing page draws as well as Usage, and the 4 bytes 84c50f032 added to app.js (Settings' Version row) without a raise, with no room added (10-25); 1,534,312 with the tray panel's last allowances drawn at once (#3160, #3134), with no room added (10-25); 1,537,016 with many releases' notes merged into one list by kind (the owner), in app.js, with no room added (10-25); 1,542,244 with a plugin's README loading under magpie's bird bouncing down its lines instead of pulsing bars (the owner), the Plugins page's, in plugins.js, with no room added (10-26); 1,542,418 with a page plugin's sidebar tab coming and going as it is installed, switched on or off, or removed, instead of on the Plugins page's next load (the owner), in plugins.js, with no room added (10-26); 1,537,645 with Settings › Observability moved out to plugins/otel, lowered to it (10-26); 1,537,673 with a used window with no reset not "Not used yet" (windy on Discord), and back to 1,537,645 with Settings' model pickers sharing modelOpt (10-26); 1,541,967 with every slow page's skeletons getting magpie's bird (skelBird, the owner), in app.js, the README's bird sharing its drawing and styles, with no room added (10-26); 1,526,251 with Settings' gateway rows moved out to plugins/gateway/settings.js, lowered to it (10-27); 1,526,391 with Test models naming the first failed model and its error (ysm119 on Discord), in app.js, with no room added (10-27); 1,526,556 with About's Website row (the owner), in app.js, with no room added (10-27); 1,526,500 with a pool's cap ticks (plugins#349), in app.js, with no room added (10-28); 1,527,245 with About's Open-source licenses row and dialog (the owner), in app.js, with no room added (10-28); 1,528,076 with the Partners heading's light (the owner), in app.js, with no room added (10-28); 1,530,449 with Install another agent's More in Plugins row (the owner), in app.js, and Plugins opening at its Agents, in plugins.js, with no room added (10-28); 1,530,807 with layout.js measuring the scrollbar into --bar, which every page's right padding takes off so its sides match (the owner), the window's own shell, with no room added (10-28); 1,530,861 with More in Plugins in sight while Install another agent is folded (the owner), in app.js, with no room added (10-29); 1,532,830 with waitsBack and backAfterLoad (issennknight, macOS 13), the window's own scroll guard, in app.js, with no room added (10-29); the context map's tile wording (a4e929212) and Cindy's Add magpie (628ac36fc) had taken the core over it, and Web search's rows moved out to plugins/search/settings.js brought it back to 1,530,861 (#4133, 10-29))func TestCoreScriptBudget(t *testing.T) {