diff --git a/docs/subsystems/plugin-runtime.md b/docs/subsystems/plugin-runtime.md index 6f7595a78..8c841dae8 100644 --- a/docs/subsystems/plugin-runtime.md +++ b/docs/subsystems/plugin-runtime.md @@ -23,7 +23,7 @@ the plugin host) are a different thing; see | Part | What it does | Source | | --- | --- | --- | | Registry | A plugin calls `pluginrt.Register(Manifest)` from `init`. `Registered` lists them by id; two with one id panic. `plugins/all` imports every plugin, and only `main.go` imports `plugins/all`, so core code and its tests run without any. | [`pluginrt.go`](../../internal/pluginrt/pluginrt.go), [`plugins/all/all.go`](../../plugins/all/all.go) | -| Manifest | `ID`, `API` (a caret range of the host API, `"^1"`; `pluginrt.API` is `"1.0"`), `Requires` and `Provides` (services), `Essential`, `Name`/`Sub` (English; the window translates them), `One`/`Many` (what is in use, of 1 or `{n}`), `InUse`, `Apply`, `Parts` (`{Slot, Key}`: the window's parts it is), `Defaults` (its config), `Settings` (a struct of its settings, made into `Defaults` and a schema at `Register`) and `Client` (its files in the window, under `internal/gui/assets/plugins//`: scripts, its `i18n.js` and a `.css`). | [`pluginrt.go`](../../internal/pluginrt/pluginrt.go) | +| Manifest | `ID`, `API` (a caret range of the host API, `"^1"`; `pluginrt.API` is `"1.0"`), `Requires` and `Provides` (services), `Essential`, `Name`/`Sub` (English; the window translates them), `One`/`Many` (what is in use, of 1 or `{n}`), `InUse`, `Apply`, `Parts` (`{Slot, Key}`: the window's parts it is), `SetAt` (where Settings has its settings, a tab and the row they start at, `"privacy #redactList"`: its Plugins › Built-in row links there and to its `nav.page` while it is on (`featGo`), a link to settings hidden while it is off left out, and its settings, while it is off, say so first with a Turn on (`featOff`); `redact`, `search`, `gateway` and `otel` have one; netube99 on X), `Defaults` (its config), `Settings` (a struct of its settings, made into `Defaults` and a schema at `Register`) and `Client` (its files in the window, under `internal/gui/assets/plugins//`: scripts, its `i18n.js` and a `.css`). | [`pluginrt.go`](../../internal/pluginrt/pluginrt.go) | | Lifecycle | `Runtime.Reconcile(on, config)`. Off first: every plugin no longer wanted, and every one requiring a service one of those provided, is disposed newest first. Then on: each wanted plugin whose requirements are provided (by `Core`, `settings`, `providers`, `gateway`, `window`, or an active plugin) is applied, again and again until no more can be. States: `off`, `pending` (waiting for a service, logged), `active`, `failed` (Apply returned an error or panicked, or the API range doesn't match; what it registered before is undone), `disposed`. A failed plugin never stops the others. | [`pluginrt.go`](../../internal/pluginrt/pluginrt.go) | | Ctx | What `Apply` gets: `OnDispose(f)`, `Contribute(slot, key)`, `Provide(name, v)` (withdrawn when it goes), `Service(name)`, and its composed `Config`. Disposers run in reverse, each one's panic logged and the rest still run. | [`pluginrt.go`](../../internal/pluginrt/pluginrt.go) | | plugins.yml | `appdir.Config()/plugins.yml`: `preset` (`essentials` or `all`; `all` unless the user picks Essentials), `settled` (the defaults the file was last brought up to) and `plugins`, rows of `{id, enabled, config}` holding only what the user set. | [`config.go`](../../internal/pluginrt/config.go) | diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index afb022cf5..e2e9477d5 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -300,14 +300,9 @@ function keepIcons(...roots) { keptIcons.get(e.dataset.icon).push(e); } } -// A mono logo is a CSS mask, not an : a row drawn again makes its -// span afresh, and only the spans on the page keep the picture, so the -// engine may let it go between rows and paint the new one empty until it -// is loaded again: the logo blinks, an beside it doesn't (#1847). Every -// mask picture that has loaded is kept by a span of its own on a hidden -// shelf for as long as the page is open, so a logo drawn again paints at -// once on any page. Each picture is tried once, not once per logo: a -// probe made for every logo asked for the file again on a redraw. +// A mono logo is a CSS mask, which a redrawn row can paint empty until it +// loads again (#1847): each loaded picture is kept by a span on a hidden +// shelf, and tried once, not once per logo. const maskLoads = new Map(); let maskShelf = null; function maskSpan(src, failed) { @@ -4313,13 +4308,9 @@ function fit(extra = 0, glide) { const still = !glide || calm(); fitSend("window/fit?h=" + h + (still ? "" : "&ms=" + glide.ms + "&ease=" + glide.ease)); } -// fitSend asks for one height at a time. Wails serves each of the page's -// requests on a goroutine of its own, so two fits asked together reached -// the panel in either order (69 of 400 pairs the wrong way round in a real -// WKWebView), and the older one landing last kept the panel at its height: -// fit.last and the panel's own height then took the newer as done, and the -// Allowances tab's card was cut off by the foot (robot_yz on X). A fit -// asked while one is on its way waits for it, and only the latest goes. +// fitSend asks for one height at a time: Wails serves requests on their own +// goroutines, so two fits could land in either order and the older keep the +// panel short (robot_yz on X). One asked meanwhile waits; only the latest goes. function fitSend(path) { if (fitSend.busy) { fitSend.next = path; return; } fitSend.busy = true; @@ -6791,14 +6782,10 @@ function accountPlan(a) { // page that gets anything else connected to it: base URL, key, model ids, // and a snippet in whichever language the reader is holding. -// copy asks magpie to put text on the clipboard, as the page's own -// clipboard API is refused inside the app's window; a browser tab on the -// dev UI falls back to it. A tab on `magpie web` reached over plain http -// from another computer (a NAS's) has no clipboard API at all, so the -// older copy command is the last try there. magpie refuses a copy it -// couldn't read back (#1881: GTK 3 on KDE Plasma without middle-click -// paste served it empty), and the page's ways are tried then too. When -// none copies, the page says so and shows the text to copy by hand. +// copy asks magpie for the clipboard (the window refuses the page's API), +// then the page's API, then the old copy command (plain-http `magpie web`). +// magpie refuses a copy it can't read back (#1881); none copying, the page +// shows the text to copy by hand. async function copy(text, what, btn, message) { const done = () => { status(message || t("{what} copied", { what }), "ok"); flashCopied(btn); }; const res = await fetch("/api/copy", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ text }) }).catch(() => null); @@ -14627,14 +14614,10 @@ async function accountAction(path, body, okMsg, confirmed = false, say = (m) => } } -// An account's or key's own models (#474): one of several can be kept for -// some of the provider's models only — a small allowance kept for the cheap -// ones — and the gateway never sends it another. Unset, it serves all the -// provider's, as before. The pill on its row says which it serves; a click -// opens the provider's models under it as chips, picked and saved apart -// from the editor's Save. acctModels is the row being picked: { id, ref, -// chosen }. Picks left unsaved there go with the editor's Save, which says -// it saved them (#2862). +// An account's or key's own models (#474): kept for some models only, the +// gateway sends it no other; unset, all. Its pill opens them as chips, +// saved apart from the editor's Save, which takes unsaved picks (#2862). +// acctModels is the row being picked: { id, ref, chosen }. let acctModels = null; function accountModelsOf(p, ref) { return p.accountModels?.[String(ref).toLowerCase()] || []; } // accountModelsDraft: the open picker's unsaved picks as accountmodels takes @@ -21836,6 +21819,7 @@ function renderRedact(s, keep) { box.replaceChildren(); find.replaceChildren(); share.replaceChildren(); + featOff(box, s, "redact", t("Nothing is masked until it is on. Choosing anything to mask below turns it on")); const rowIn = (into, name, sub, ...tools) => { const r = el("div", "row pref"); const who = el("div", "who"); @@ -23054,14 +23038,8 @@ function hold(h) { // button held, and room made for the button slid the chip up under the // tabs, out of sight if (want > max && h.top) want = max; - // room is only kept while some of the view stays in sight: a redraw can take - // away the whole of what the reader was looking at (a group's editor closed - // on its Save, the list it had in it), and scrolled to `want` not one row of - // the view would be in sight, only the room — a blank page. The browser's own - // clamp after the content shrank stands instead. - // A sliver is as blank: with the group editor's rows folded under - // Advanced, its Save left the last settings card, 88px of a 594px window, - // above the room. So a third of the window is content, or no room. + // room only while a third of the window still shows the view, never a + // blank page; the browser's own clamp stands instead if (want > max && contentEnd(v) - want < v.clientHeight / 3) want = max; if (want > max) setRoom(v, want + v.clientHeight - contentEnd(v)); v.scrollTop = want; @@ -23296,7 +23274,10 @@ function renderBuiltins(box, list, done) { const who = el("div", "who"); who.append(el("div", "name", t(f.name)), el("div", "sub", t(f.sub))); if (f.inUse > 0) who.append(el("div", "sub feat-why", t(f.use, { n: f.inUse }))); - featWho[f.id]?.(who, f); // a plugin's own line (plugins/search) + const line = el("div", "sub feat-go"); + featWho[f.id]?.(line, f, who); // what it does now (plugins/search) + featGo(line, f); + if (line.childNodes.length) who.append(line); const b = el("button", "lib-switch use-credits" + (f.on ? " on" : "")); b.type = "button"; b.setAttribute("role", "switch"); @@ -23345,6 +23326,46 @@ function renderBuiltins(box, list, done) { } window.renderBuiltins = renderBuiltins; const featWho = {}; +// featGo: a built-in's row goes to its settings and its page, as their +// settings and page go back (featOff, Masking's head; netube99 on X) +function featGo(line, f) { + const [tab, row] = f.setAt?.split(" ") || []; + if (!tab) return; + const to = []; + // not to settings hidden while it is off (Observability, warm-ups) + if (f.on || !$(row)?.closest("[data-feature]")) to.push([t("Settings") + " › " + $("#setTab-" + tab).textContent, (e) => openSettingsAt(e, tab, row + " .row")]); + const nav = f.on && f.page && $(`#nav [data-view="${f.page}"]`); + if (nav) to.push([nav.textContent, () => nav.click()]); + for (const [say, go] of to) { + const b = el("button", "link", say); + b.type = "button"; + b.onclick = go; + line.append(line.childNodes.length ? " · " : "", b); + } +} +// featOff: the settings of a built-in switched off say so, and turn it on +function featOff(box, s, id, sub) { + if (s.builtins?.find((f) => f.id === id)?.on !== false) return; + const r = el("div", "row pref feat-off"), who = el("div", "who"), val = el("div", "val"); + r.dataset.of = id; + who.append(el("div", "name", t("Off in Plugins › Built-in")), el("div", "sub", sub)); + const on = el("button", "text", t("Turn on")); + on.type = "button"; + on.onclick = async () => { + on.disabled = true; + try { + applyFeatures(prefs.builtins = await api("plugins/builtin", { id, on: true })); + renderSettings(); + status(t("Saved"), "ok", 1500); + } catch (err) { + on.disabled = false; + status(t(err.message), "err"); + } + }; + val.append(on); + r.append(who, val); + box.append(r); +} // openSettings: the Settings page, in the window (the panel opens it there) function openSettings() { if (mode !== "window") { api("window/main?view=settings", {}); return; } @@ -23539,13 +23560,9 @@ function markNav(v) { } // ---- the sidebar ---------------------------------------------------------- -// A window wide enough has its pages down a sidebar, as a Mac app's: in -// groups, the open page's own tabs under it, Settings at its foot and the -// gateway's address under that, the header saying where the reader is -// ("Work / Library / MCP servers"). Narrower, and magpie web on a phone, -// the pages go back into the header as tabs and each page shows its own -// tabs again, as iPadOS's sidebar turns into a tab bar when it has no room. -// It is the same #nav, moved between the two. +// A wide window has its pages down a sidebar, as a Mac app's; narrower +// (and on a phone) they go back into the header as tabs, as iPadOS's +// sidebar does. It is the same #nav, moved between the two. var SIDE_AT = 1024; var sideQuery = matchMedia(`(min-width: ${SIDE_AT}px)`); function sideNav() { return document.body.classList.contains("side-nav"); } diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index d5f32279d..758d1bec0 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -1145,6 +1145,7 @@ const I18N = { "Searches with {names}": "当前用 {names} 搜索", "Nothing to search with yet": "还没有可用的搜索来源", "Set up in Settings": "在设置中配置", + "Nothing is masked until it is on. Choosing anything to mask below turns it on": "开启前不会脱敏任何内容。在下方选择要脱敏的内容即会开启", "Web search is off in Plugins › Built-in: its tools say so until it is turned on": "联网搜索已在 插件 › 内置 中关闭:重新开启前,它的工具会提示这一点", "Nothing searches yet: add a search API in Settings → Models → Web search, or a provider that can search. Until then its tools say so": "还没有可用的搜索:在 设置 → 模型 → 联网搜索 添加搜索 API,或添加能搜索的供应商。在此之前,它的工具会提示这一点", "Image recognition is off in Settings → Models → Images: its tool says so until a model is picked there": "识图已在 设置 → 模型 → 图像 中关闭:在那里选好模型前,它的工具会提示这一点", @@ -5907,6 +5908,7 @@ const I18N = { "Searches with {names}": "目前用 {names} 搜尋", "Nothing to search with yet": "還沒有可用的搜尋來源", "Set up in Settings": "在設定中設定", + "Nothing is masked until it is on. Choosing anything to mask below turns it on": "開啟前不會脫敏任何內容。在下方選擇要脫敏的內容即會開啟", "Web search is off in Plugins › Built-in: its tools say so until it is turned on": "聯網搜尋已在 外掛 › 內建 中關閉:重新開啟前,它的工具會提示這一點", "Nothing searches yet: add a search API in Settings → Models → Web search, or a provider that can search. Until then its tools say so": "還沒有可用的搜尋:在 設定 → 模型 → 聯網搜尋 新增搜尋 API,或新增能搜尋的供應商。在此之前,它的工具會提示這一點", "Image recognition is off in Settings → Models → Images: its tool says so until a model is picked there": "識圖已在 設定 → 模型 → 影像 中關閉:在那裡選好模型前,它的工具會提示這一點", @@ -10640,6 +10642,7 @@ const I18N = { "Searches with {names}": "{names} で検索します", "Nothing to search with yet": "検索に使えるものがまだありません", "Set up in Settings": "設定で設定する", + "Nothing is masked until it is on. Choosing anything to mask below turns it on": "オンにするまで何もマスクされません。下でマスクするものを選ぶとオンになります", "Web search is off in Plugins › Built-in: its tools say so until it is turned on": "ウェブ検索は プラグイン › 内蔵 でオフになっています:オンにするまで、ツールはそのことを伝えます", "Nothing searches yet: add a search API in Settings → Models → Web search, or a provider that can search. Until then its tools say so": "まだ検索できるものがありません:設定 → モデル → ウェブ検索 で検索 API を追加するか、検索できるプロバイダを追加してください。それまではツールがそのことを伝えます", "Image recognition is off in Settings → Models → Images: its tool says so until a model is picked there": "画像認識は 設定 → モデル → 画像 でオフになっています:そこでモデルを選ぶまで、ツールはそのことを伝えます", @@ -15388,6 +15391,7 @@ const I18N = { "Searches with {names}": "Sucht mit {names}", "Nothing to search with yet": "Noch keine Suchquelle eingerichtet", "Set up in Settings": "In den Einstellungen einrichten", + "Nothing is masked until it is on. Choosing anything to mask below turns it on": "Bis sie eingeschaltet ist, wird nichts maskiert. Etwas unten zum Maskieren wählen schaltet sie ein", "Web search is off in Plugins › Built-in: its tools say so until it is turned on": "Die Websuche ist unter Erweiterungen › Eingebaut ausgeschaltet: Ihre Tools sagen das, bis sie eingeschaltet wird", "Nothing searches yet: add a search API in Settings → Models → Web search, or a provider that can search. Until then its tools say so": "Noch sucht nichts: Füge unter Einstellungen → Modelle → Websuche eine Such-API hinzu oder einen Anbieter, der suchen kann. Bis dahin sagen ihre Tools das", "Image recognition is off in Settings → Models → Images: its tool says so until a model is picked there": "Die Bilderkennung ist unter Einstellungen → Modelle → Bilder ausgeschaltet: Ihr Tool sagt das, bis dort ein Modell gewählt ist", diff --git a/internal/gui/assets/plugins/library/client.js b/internal/gui/assets/plugins/library/client.js index 823662b11..fb975817f 100644 --- a/internal/gui/assets/plugins/library/client.js +++ b/internal/gui/assets/plugins/library/client.js @@ -6709,7 +6709,7 @@ magpie.plugin("library", (ctx) => { const go = el("button", "link", t("Set up in Settings")); go.type = "button"; go.onclick = async (e) => { if (await closeLibModal()) openSettingsAt(e, "models", "#searchList .row"); }; - hint.append(go); + hint.append(" ", go); ed.append(hint); } else if (x.name === "magpie-vision") { ed.append(el("p", "mk-hint", t("Pick the agents that may read images with it: each image goes to the Image recognition model set in Settings → Models → Images, and costs what that model charges."))); diff --git a/internal/gui/assets/plugins/redact/page.js b/internal/gui/assets/plugins/redact/page.js index 0d0c6e762..cfff3bbd8 100644 --- a/internal/gui/assets/plugins/redact/page.js +++ b/internal/gui/assets/plugins/redact/page.js @@ -143,7 +143,16 @@ function drawMaskCard() { b.type = "button"; b.onclick = maskTurnOn; head.append(b); - } else head.append(maskOffButton()); + } else { + // back to its settings (netube99 on X), unless Turn off goes there + if (!maskSettings().redactWords?.length) { + const set = el("button", "text", t("Settings") + " › " + $("#setTab-privacy").textContent); + set.type = "button"; + set.onclick = (e) => openSettingsAt(e, "privacy", "#redactList .row"); + head.append(set); + } + head.append(maskOffButton()); + } if (sum?.requests || maskDays === 30) head.append(segs([["7", t("7 days")], ["30", t("30 days")]], String(maskDays), (v) => { maskDays = +v; try { localStorage.setItem("magpie.maskDays", v); } catch {} diff --git a/internal/gui/assets/plugins/redact/redact.css b/internal/gui/assets/plugins/redact/redact.css index 69176e738..37b316c9a 100644 --- a/internal/gui/assets/plugins/redact/redact.css +++ b/internal/gui/assets/plugins/redact/redact.css @@ -6,8 +6,10 @@ #view-masking .grow { flex: 1; } .msk-card { position: relative; padding: 16px 20px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); } .msk-card[hidden], .msk-list[hidden], .msk-one[hidden] { display: none; } -.msk-head { display: flex; align-items: flex-start; gap: 12px; } +.msk-head { display: flex; align-items: flex-start; gap: 8px 12px; } .msk-title { min-width: 0; } +/* narrow, its buttons go under the words rather than off the side */ +@media (max-width: 600px) { .msk-head { flex-wrap: wrap; } .msk-title { flex-basis: 100%; } } .msk-title h2 { margin: 0; font-size: 13px; font-weight: 600; color: var(--fg); } .msk-sub { display: block; margin-top: 3px; font-size: 12px; line-height: 1.4; color: var(--muted); } .msk-band { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr); gap: 36px; align-items: center; margin-top: 12px; } diff --git a/internal/gui/assets/plugins/search/settings.js b/internal/gui/assets/plugins/search/settings.js index 6b4994d49..4da89a16c 100644 --- a/internal/gui/assets/plugins/search/settings.js +++ b/internal/gui/assets/plugins/search/settings.js @@ -15,7 +15,7 @@ function renderSearch(s, keep) { const box = $("#searchList"); box.replaceChildren(); const off = s.builtins?.find((f) => f.id === "search")?.on === false; - if (off) searchOffRow(box); + featOff(box, s, "search", t("magpie searches for no model until it is on. Adding a search API or naming a provider below turns it on")); 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) @@ -197,48 +197,14 @@ function renderSearch(s, keep) { mcp.querySelector(".who").append(...libWay("magpie-web-search", t("Give agents Magpie Web Search…"), "search-mcp-lib")); } -// searchOffRow: Web search switched off in Plugins › Built-in (netube99 on -// X: the switch, the Library and Settings said nothing of each other). -// Nothing here searches until it is on, which adding a search API or -// naming a provider does by itself (InUse in plugins/search). -function searchOffRow(box) { - const r = el("div", "row pref search-off"); - const who = el("div", "who"); - who.append(el("div", "name", t("Off in Plugins › Built-in")), - el("div", "sub", t("magpie searches for no model until it is on. Adding a search API or naming a provider below turns it on"))); - const on = el("button", "text", t("Turn on")); - on.type = "button"; - on.onclick = async () => { - on.disabled = true; - try { - const next = await api("plugins/builtin", { id: "search", on: true }); - prefs.builtins = next; - applyFeatures(next); - renderSettings(); - status(t("Saved"), "ok", 1500); - } catch (err) { - on.disabled = false; - status(t(err.message), "err"); - } - }; - const val = el("div", "val"); - val.append(on); - r.append(who, val); - box.append(r); -} - -// Plugins › Built-in › Web search's own line: what a model that can't -// search is searched with now, or that nothing is yet, and the way to -// Settings, where it is set up -featWho.search = (who, f) => { - const line = el("div", "sub search-now"); - if (f.on) line.append(f.searches?.length ? t("Searches with {names}", { names: f.searches.join(" → ") }) - : el("span", "warn", t("Nothing to search with yet")), " · "); - const go = el("button", "link", t("Set up in Settings")); - go.type = "button"; - go.onclick = (e) => openSettingsAt(e, "models", "#searchList .row"); - line.append(go); - who.append(line); +// Plugins › Built-in › Web search's own line (featGo): what a model that +// can't search is searched with now, in place of how many are set up, or +// that nothing is yet (netube99 on X) +featWho.search = (line, f, who) => { + if (!f.on) return; + if (f.searches?.length) who.querySelector(".feat-why")?.remove(); + line.append(f.searches?.length ? t("Searches with {names}", { names: f.searches.join(" → ") }) + : el("span", "warn", t("Nothing to search with yet"))); }; // searchArrange: the search APIs are asked in the order they are listed, diff --git a/internal/gui/builtins.go b/internal/gui/builtins.go index b1cc53ec7..ffcf426b0 100644 --- a/internal/gui/builtins.go +++ b/internal/gui/builtins.go @@ -41,6 +41,10 @@ type builtinJSON struct { InUse int `json:"inUse"` Use string `json:"use,omitempty"` // One or Many, by InUse Parts []pluginrt.Part `json:"parts,omitempty"` + // SetAt is the manifest's: the Settings tab and row of its settings; + // Page the window page it has, on or off + SetAt string `json:"setAt,omitempty"` + Page string `json:"page,omitempty"` // Schema is its settings' (pluginrt/schema.go), which the page draws // a form of; Config their values now Schema *pluginrt.Schema `json:"schema,omitempty"` @@ -73,6 +77,12 @@ func builtinsState() []builtinJSON { for _, m := range pluginrt.Registered() { c, s := byID[m.ID], st[m.ID] j := builtinJSON{ID: m.ID, Name: m.Name, Sub: m.Sub, On: s.State == pluginrt.Active, Chosen: c.Chosen, Source: c.Source, State: s.State, Why: s.Why, InUse: c.InUse, Parts: s.Parts, Schema: m.Schema(), Config: c.Config} + j.SetAt = m.SetAt + for _, p := range m.Parts { + if p.Slot == "nav.page" { + j.Page = p.Key + } + } if err != nil { j.Broken, j.Chosen = err.Error(), j.On } @@ -95,15 +105,13 @@ func builtinsState() []builtinJSON { func searchesNow() []string { var apis []string for _, a := range provider.SearchAPIs() { - if v, ok := provider.SearchVendorOf(a.Vendor); ok { - apis = append(apis, v.Name) - } + apis = append(apis, a.Name()) } by := gateway.Searcher() switch { case by == "": return apis - case settings.Load().SearchFirst == "api": + case settings.Load().SearchFirst == settings.SearchFirstAPI: return append(apis, by) } return append([]string{by}, apis...) diff --git a/internal/gui/builtins_test.go b/internal/gui/builtins_test.go index 2dcde8b9a..2cafb5c49 100644 --- a/internal/gui/builtins_test.go +++ b/internal/gui/builtins_test.go @@ -6,11 +6,13 @@ import ( "net/http/httptest" "os" "path/filepath" + "slices" "strings" "testing" "github.com/yetone/magpie/internal/gateway" "github.com/yetone/magpie/internal/pluginrt" + "github.com/yetone/magpie/internal/provider" "github.com/yetone/magpie/internal/settings" _ "github.com/yetone/magpie/plugins/all" ) @@ -319,3 +321,77 @@ func TestBuiltinsTranslated(t *testing.T) { } } } + +// Web search's row says what a model that can't search is searched with +// now (netube99 on X): nothing yet in a new home, a search API once one +// is set, and none while it is off. +func TestBuiltinSearchSaysWhatSearches(t *testing.T) { + builtinHome(t) + if _, err := pluginrt.Settle(); err != nil { + t.Fatal(err) + } + search := func() builtinJSON { + for _, b := range builtinsState() { + if b.ID == "search" { + return b + } + } + t.Fatal("no search row") + return builtinJSON{} + } + if b := search(); !b.On || len(b.Searches) != 0 { + t.Fatalf("a new home: %+v", b) + } + if err := provider.SetSearchAPI(provider.SearchAPI{Vendor: "tavily", Key: "tvly-test"}); err != nil { + t.Fatal(err) + } + if b := search(); !b.On || !slices.Equal(b.Searches, []string{"Tavily"}) { + t.Fatalf("with Tavily: %+v", b) + } + if err := provider.RemoveSearchAPI("tavily"); err != nil { + t.Fatal(err) + } + if err := pluginrt.Set("search", false); err != nil { + t.Fatal(err) + } + if b := search(); b.On || b.Searches != nil { + t.Fatalf("off: %+v", b) + } +} + +// A built-in with settings says where they are, and its page on or off, +// for its row to go to both (netube99 on X: masking's switch, settings and +// page didn't name each other) +func TestBuiltinSaysWhereItsSettingsAre(t *testing.T) { + builtinHome(t) + if _, err := pluginrt.Settle(); err != nil { + t.Fatal(err) + } + if err := pluginrt.Set("redact", false); err != nil { + t.Fatal(err) + } + want := map[string][2]string{ + "redact": {"privacy #redactList", "masking"}, + "search": {"models #searchList", ""}, + "otel": {"otel #otelList", ""}, + "gateway": {"network #portList", "gateway"}, + "library": {"", "library"}, + "groups": {"", ""}, + } + for _, b := range builtinsState() { + w, ok := want[b.ID] + if !ok { + continue + } + delete(want, b.ID) + if got := [2]string{b.SetAt, b.Page}; got != w { + t.Errorf("%s (on %v): %q, want %q", b.ID, b.On, got, w) + } + if b.ID == "redact" && b.On { + t.Error("redact stayed on") + } + } + if len(want) > 0 { + t.Errorf("not listed: %v", want) + } +} diff --git a/internal/gui/tests/builtin-places.test.cjs b/internal/gui/tests/builtin-places.test.cjs new file mode 100644 index 000000000..fc131f9dd --- /dev/null +++ b/internal/gui/tests/builtin-places.test.cjs @@ -0,0 +1,181 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// netube99 on X: masking is switched on in Plugins › Built-in, set in +// Settings › Privacy and seen on Insights › Masking, and none of the three +// leads to the others. A built-in with settings (its manifest's SetAt) now +// has, under its row, Settings › and its page while it is on +// (featGo); its settings, while it is off, say so first and turn it on +// (featOff); Masking's head goes back to Settings › Privacy. Settings +// hidden while their plugin is off (Observability) get no link then. +// Every language, Chromium and WebKit, at 1100 and 420 wide, nothing +// running off to the side; no backend, the API is faked here. +const assert = require("node:assert/strict"); +const fs = require("node:fs/promises"); +const path = require("node:path"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); +const { strings } = require("./strings.cjs"); + +const assets = path.resolve(__dirname, "../assets"); +const { I18N } = strings(); +const LANGS = ["en", "zh", "zh-TW", "ja", "de"]; +const tr = (lang, s) => (lang === "en" ? s : I18N[lang]?.[s] ?? s); + +function fixture(lang, { redact = true, otel = true } = {}) { + const st = { redact, otel }; + const posts = []; + const row = (id, name, sub, on, more) => ({ id, name, sub, on, chosen: on, source: "preset", state: on ? "active" : "off", inUse: 0, ...more }); + const builtins = () => [ + row("redact", "Privacy masking", "Secrets, personal data and your own words go to vendors as placeholders, and come back as they were", st.redact, + { setAt: "privacy #redactList", page: "masking", ...(st.redact ? { inUse: 1, use: "Masking is on" } : {}) }), + row("otel", "Observability", "Send each request's trace to an OpenTelemetry collector", st.otel, { setAt: "otel #otelList" }), + row("library", "Library", "Instructions, MCP servers, skills and hooks, kept once and given to every agent", true, { page: "library" }), + ]; + const settings = () => ({ + theme: "light", lang, tray: "panel", currency: "usd", textSize: 100, + redact: st.redact, redactPersonal: false, redactWords: [], redactRules: [], redactKinds: {}, + version: "0.1.400", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3999", port: 3999, + proxyNow: "none", proxySource: "none", vision: "", imageGen: "", lanURLs: [], + visionModels: [], imageGenModels: [], workbuddyCheckins: [], searchChoices: [], searchAPIs: [], + fx: { rate: 7.2, at: new Date().toISOString(), stale: false }, + builtins: builtins(), + }); + const route = async (route) => { + const req = route.request(), url = new URL(req.url()); + const json = (data) => route.fulfill({ json: data }); + if (url.pathname === "/boot.js") { + const off = builtins().filter((f) => !f.on).map((f) => f.id); + return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = ${JSON.stringify({ lang, theme: "light", textSize: 100, featuresOff: off })};` }); + } + if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: settings(), fx: settings().fx }); + if (url.pathname === "/api/settings") return json(settings()); + if (url.pathname === "/api/plugins/builtin") { + if (req.method() !== "POST") return json(builtins()); + const b = req.postDataJSON(); + posts.push(b); + if (b.id in st) st[b.id] = b.on; + return json(builtins()); + } + if (url.pathname === "/api/plugins") return json({ bun: true, bunVersion: "1.4.2", plugins: [], picker: false, movable: [] }); + if (url.pathname === "/api/plugins/listings") return json({ listings: [] }); + if (url.pathname === "/api/plugins/github") return json({ repos: [] }); + if (url.pathname === "/api/usage/quotas") return json([]); + if (url.pathname === "/api/groups") return json({ groups: [], models: [] }); + if (url.pathname === "/api/providers") return json({ providers: [], presets: [], gateway: { running: true } }); + if (url.pathname === "/api/masking/records") return json({ records: [], more: false }); + if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 }); + if (url.pathname.startsWith("/api/")) return json({}); + if (url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" }); + const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname); + const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png", ".jpg": "image/jpeg" }[path.extname(file)]; + const body = await fs.readFile(file).catch(() => null); + await (body ? route.fulfill({ body, contentType }) : route.fulfill({ status: 404, body: "" })); + }; + return { route, posts }; +} + +const wide = (page) => page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); +const featRow = (page, id) => page.locator(`#builtinList .feat-row[data-id="${id}"]`); +// nothing in a box reaches past its right edge or the window's +const past = (box) => box.evaluate((b) => { + const r = b.getBoundingClientRect(); + return [...b.querySelectorAll("*")].filter((e) => e.getBoundingClientRect().right > Math.min(r.right, innerWidth) + 1).map((e) => e.className || e.tagName); +}); + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + test(engine + ": a built-in's switch, settings and page lead to each other", async (t) => { + assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit"); + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const shots = []; + t.after(async () => { + if (process.env.ARTIFACT_DIR) { + await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true }); + for (const [name, buf] of shots) await fs.writeFile(path.join(process.env.ARTIFACT_DIR, `${engine}-builtin-places-${name}.png`), buf); + } + await browser.close(); + }); + const open = async (lang, width, where, opts) => { + const f = fixture(lang, opts); + const context = await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" }); + const page = await context.newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + page.errors = []; + page.on("pageerror", (e) => { if (engine === "webkit" && /due to access control checks/.test(e.message)) return; page.errors.push(e.message); }); // a goto in WebKit can cut off a fetch (#1350) + await page.route("**/*", f.route); + await page.goto("http://magpie.test/" + where); + return { page, posts: f.posts }; + }; + const builtinTab = async (page) => { + const side = await page.evaluate(() => document.body.classList.contains("side-nav")); + await page.locator(side ? ".nav-sub:not(.leaving) .nav-s" : "#view-plugins .lib-tabs .opt").first().click(); + await featRow(page, "redact").waitFor(); + }; + for (const lang of LANGS) { + const w = (s) => tr(lang, s); + for (const width of [1100, 420]) { + await t.test(`${lang} at ${width}px: masking's Built-in row goes to its settings and its page`, async () => { + for (const link of [0, 1]) { + const { page } = await open(lang, width, "?view=plugins"); + await builtinTab(page); + const line = featRow(page, "redact").locator(".who .feat-go"); + assert.equal((await line.textContent()).trim(), w("Settings") + " › " + w("Privacy") + " · " + w("Masking")); + assert.equal(await wide(page), 0); + assert.deepEqual(await past(featRow(page, "redact")), []); + if (!link) shots.push([`${lang}-${width}-builtin`, await featRow(page, "redact").screenshot()]); + // Observability on: its settings; Library: a page and no settings, no line + assert.equal((await featRow(page, "otel").locator(".feat-go").textContent()).trim(), w("Settings") + " › " + w("Observability")); + assert.equal(await featRow(page, "library").locator(".feat-go").count(), 0); + await line.locator("button.link").nth(link).click(); + if (link) await page.locator("#view-masking #maskCard .msk-head").waitFor(); + else await page.locator("#view-settings #redactList .row.flash").waitFor(); + assert.deepEqual(page.errors, []); + await page.context().close(); + } + }); + await t.test(`${lang} at ${width}px: off, Built-in goes to its settings only, and they say it is off`, async () => { + const { page, posts } = await open(lang, width, "?view=plugins", { redact: false, otel: false }); + await builtinTab(page); + const line = featRow(page, "redact").locator(".who .feat-go"); + assert.equal((await line.textContent()).trim(), w("Settings") + " › " + w("Privacy")); + // Observability's settings go with it + assert.equal(await featRow(page, "otel").locator(".feat-go").count(), 0); + await line.locator("button.link").click(); + const off = page.locator("#redactList .row.feat-off"); + await off.waitFor(); + assert.equal(await page.locator("#redactList .row").first().evaluate((r) => r.classList.contains("feat-off")), true); + assert.equal((await off.locator(".name").textContent()).trim(), w("Off in Plugins › Built-in")); + assert.equal((await off.locator(".sub").textContent()).trim(), w("Nothing is masked until it is on. Choosing anything to mask below turns it on")); + assert.equal(await wide(page), 0); + assert.deepEqual(await past(off), []); + shots.push([`${lang}-${width}-settings-off`, await off.screenshot()]); + await off.locator("button", { hasText: w("Turn on") }).click(); + await off.waitFor({ state: "detached" }); + assert.deepEqual(posts, [{ id: "redact", on: true }]); + assert.deepEqual(page.errors, []); + await page.context().close(); + }); + await t.test(`${lang} at ${width}px: on, Privacy has no off row`, async () => { + const { page } = await open(lang, width, "?view=settings&tab=privacy"); + await page.locator("#redactList .row").first().waitFor(); + assert.equal(await page.locator("#redactList .row.feat-off").count(), 0); + assert.deepEqual(page.errors, []); + await page.context().close(); + }); + await t.test(`${lang} at ${width}px: Masking's head goes back to Settings › Privacy`, async () => { + const { page } = await open(lang, width, "?view=masking"); + const head = page.locator("#maskCard .msk-head"); + const set = head.locator("button.text", { hasText: w("Settings") + " › " + w("Privacy") }); + await set.waitFor(); + assert.equal(await wide(page), 0); + assert.deepEqual(await past(head), []); + shots.push([`${lang}-${width}-masking`, await head.screenshot()]); + await set.click(); + await page.locator("#view-settings #redactList .row.flash").waitFor(); + assert.deepEqual(page.errors, []); + await page.context().close(); + }); + } + } + }); +} diff --git a/internal/gui/tests/websearch-places.test.cjs b/internal/gui/tests/websearch-places.test.cjs new file mode 100644 index 000000000..43aa61004 --- /dev/null +++ b/internal/gui/tests/websearch-places.test.cjs @@ -0,0 +1,215 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// netube99 on X: web search is set in three places, Plugins › Built-in's +// Web search switch, a search server from the Library and Settings › +// Models › Web search, and none said what the others do. Now each says it: +// Built-in's row names what searches now ("Searches with …", or that +// nothing does yet) and opens Settings at Web search (featGo, the link +// every built-in with settings has, builtin-places.test.cjs); Settings, +// with the plugin off, says so first and turns it on there (featOff), and no "Now done by" +// stands under it; a Library search server's sheet says the agents call it +// themselves, beside magpie's web search, and opens Settings, naming the +// search API there for one Settings has too. Every language, Chromium and +// WebKit, at 1100 and 420 wide, nothing running off to the side; no +// backend, the API is faked here. +const assert = require("node:assert/strict"); +const fs = require("node:fs/promises"); +const path = require("node:path"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); +const { strings } = require("./strings.cjs"); + +const assets = path.resolve(__dirname, "../assets"); +const { I18N } = strings(); +const LANGS = ["en", "zh", "zh-TW", "ja", "de"]; +const tr = (lang, s) => (lang === "en" ? s : I18N[lang]?.[s] ?? s); +const HOME = "/Users/tester"; +const OWN = "Agents call it themselves, beside magpie's web search, which doesn't use it."; +const AS_API = "As a search API in Settings → Models → Web search, {name} searches for every model, with no server to add."; + +// search: the Web search plugin as builtinsState gives it: on, and what +// searches now (searchesNow) +function fixture(lang, { on = true, searches = [] } = {}) { + const st = { on }; + const posts = []; + const builtins = () => [ + { id: "library", name: "Library", sub: "Instructions, MCP servers, skills and hooks, kept once and given to every agent", on: true, chosen: true, source: "preset", state: "active", inUse: 0 }, + { id: "search", name: "Web search", sub: "Models that can't search the web search with a provider that can, or a search API", on: st.on, chosen: st.on, source: "preset", state: st.on ? "active" : "off", setAt: "models #searchList", inUse: searches.length, ...(searches.length ? { use: searches.length === 1 ? "1 search source set up" : "{n} search sources set up" } : {}), ...(st.on && searches.length ? { searches } : {}) }, + ]; + const settings = () => ({ + theme: "light", lang, tray: "panel", currency: "usd", textSize: 100, redactWords: [], + version: "0.1.400", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3999", port: 3999, + proxyNow: "none", proxySource: "none", vision: "", imageGen: "", lanURLs: [], + visionModels: [], imageGenModels: [], workbuddyCheckins: [], + searcher: "", searchChoices: [], searchProvider: "Kimi", + searchVendors: [{ id: "tavily", name: "Tavily", keysURL: "https://app.tavily.com/home" }], + searchAPIs: [], + fx: { rate: 7.2, at: new Date().toISOString(), stale: false }, + builtins: builtins(), + }); + const lib = () => ({ + dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME, + agents: [{ id: "pi", name: "Pi", icon: "generic", mcp: `${HOME}/.pi/mcp.json`, skills: `${HOME}/.pi/skills` }], + instructions: { agents: [], sets: [] }, foundServers: [], projects: [], foundSkills: [], skills: [], problems: [], servers: [], + }); + const route = async (route) => { + const req = route.request(), url = new URL(req.url()); + const json = (data) => route.fulfill({ json: data }); + if (url.pathname === "/boot.js") { + return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = ${JSON.stringify({ lang, theme: "light", textSize: 100, featuresOff: st.on ? [] : ["search"] })};` }); + } + if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: settings(), fx: settings().fx }); + if (url.pathname === "/api/settings") return json(settings()); + if (url.pathname === "/api/plugins/builtin") { + if (req.method() !== "POST") return json(builtins()); + const b = req.postDataJSON(); + posts.push(b); + if (b.id === "search") st.on = b.on; + return json(builtins()); + } + if (url.pathname === "/api/library") return json(lib()); + if (url.pathname === "/api/library/market/servers") { + return json({ items: [ + { id: "tavily", name: "tavily", featured: true, title: "Tavily", publisher: "Tavily", description: "Search and extract from the web with Tavily.", transport: "stdio", runs: "npx", inputs: [{ key: "TAVILY_API_KEY", where: "env", label: "API key", secret: true, required: true }] }, + { id: "anysearch", name: "anysearch", featured: true, title: "AnySearch", publisher: "AnySearch", description: "Real-time web search.", transport: "http", inputs: [] }, + { id: "fetch", name: "fetch", featured: true, title: "Fetch", publisher: "Model Context Protocol", description: "Fetch a web page and hand it over as Markdown.", transport: "stdio", runs: "uvx", inputs: [] }, + ] }); + } + if (url.pathname === "/api/library/market/skills") return json({ items: [] }); + if (url.pathname === "/api/plugins") return json({ bun: true, bunVersion: "1.4.2", plugins: [], picker: false, movable: [] }); + if (url.pathname === "/api/plugins/listings") return json({ listings: [] }); + if (url.pathname === "/api/plugins/github") return json({ repos: [] }); + if (url.pathname === "/api/usage/quotas") return json([]); + if (url.pathname === "/api/groups") return json({ groups: [], models: [] }); + if (url.pathname === "/api/providers") return json({ providers: [], presets: [], gateway: { running: true } }); + if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 }); + if (url.pathname.startsWith("/api/")) return json({}); + if (url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" }); + const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname); + const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)]; + const body = await fs.readFile(file).catch(() => null); + await (body ? route.fulfill({ body, contentType }) : route.fulfill({ status: 404, body: "" })); + }; + return { route, posts }; +} + +const wide = (page) => page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); +const searchRow = (page) => page.locator('#builtinList .feat-row[data-id="search"]'); + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + test(engine + ": web search's three places say what each does and lead to the others", async (t) => { + assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit"); + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const shots = []; + t.after(async () => { + if (process.env.ARTIFACT_DIR) { + await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true }); + for (const [name, buf] of shots) await fs.writeFile(path.join(process.env.ARTIFACT_DIR, `${engine}-websearch-places-${name}.png`), buf); + } + await browser.close(); + }); + const open = async (lang, width, where, opts) => { + const f = fixture(lang, opts); + const context = await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" }); + const page = await context.newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + page.errors = []; + page.on("pageerror", (e) => { if (engine === "webkit" && /due to access control checks/.test(e.message)) return; page.errors.push(e.message); }); // a goto in WebKit can cut off a fetch (#1350) + await page.route("**/*", f.route); + await page.addInitScript(() => { localStorage.setItem("magpie.libTab", "mcp"); }); + await page.goto("http://magpie.test/" + where); + return { page, posts: f.posts }; + }; + const builtinTab = async (page) => { + const side = await page.evaluate(() => document.body.classList.contains("side-nav")); + await page.locator(side ? ".nav-sub:not(.leaving) .nav-s" : "#view-plugins .lib-tabs .opt").first().click(); + await searchRow(page).waitFor(); + }; + for (const lang of LANGS) { + const w = (s, v) => { let x = tr(lang, s); for (const [k, val] of Object.entries(v || {})) x = x.replaceAll(`{${k}}`, val); return x; }; + for (const width of [1100, 420]) { + await t.test(`${lang} at ${width}px: Built-in's Web search names what searches and opens Settings there`, async () => { + const { page } = await open(lang, width, "?view=plugins", { searches: ["Kimi", "Tavily"] }); + await builtinTab(page); + const line = searchRow(page).locator(".who .feat-go"); + assert.equal((await line.textContent()).trim(), w("Searches with {names}", { names: "Kimi → Tavily" }) + " · " + w("Settings") + " › " + w("Models")); + // the names, not how many are set up + assert.equal(await searchRow(page).locator(".feat-why").count(), 0); + assert.equal(await wide(page), 0); + shots.push([`${lang}-${width}-builtin`, await searchRow(page).screenshot()]); + await line.locator("button.link").click(); + await page.locator("#view-settings #searchList .row.flash").waitFor(); + assert.equal(await page.locator("#view-settings").isVisible(), true); + assert.deepEqual(page.errors, []); + await page.context().close(); + }); + await t.test(`${lang} at ${width}px: on with nothing to search with, Built-in says so`, async () => { + const { page } = await open(lang, width, "?view=plugins", { searches: [] }); + await builtinTab(page); + const line = searchRow(page).locator(".who .feat-go"); + assert.equal((await line.locator(".warn").textContent()).trim(), w("Nothing to search with yet")); + assert.equal(await line.locator("button.link").count(), 1); + assert.equal(await wide(page), 0); + assert.deepEqual(page.errors, []); + await page.context().close(); + }); + await t.test(`${lang} at ${width}px: off, Settings says so first and Turn on brings it back`, async () => { + const { page, posts } = await open(lang, width, "?view=settings&tab=models", { on: false }); + const off = page.locator("#searchList .row.feat-off"); + await off.waitFor(); + assert.equal(await page.locator("#searchList .row").first().evaluate((r) => r.classList.contains("feat-off")), true); + assert.equal((await off.locator(".name").textContent()).trim(), w("Off in Plugins › Built-in")); + assert.equal(await wide(page), 0); + shots.push([`${lang}-${width}-settings-off`, await off.screenshot()]); + // no "Now done by" while nothing searches + const now = w("Now done by {who}; these come after it", { who: "Kimi" }); + assert.equal(await page.locator("#searchList").evaluate((b, s) => b.textContent.includes(s), now), false); + await off.locator("button", { hasText: w("Turn on") }).click(); + await page.locator("#searchList .row.feat-off").waitFor({ state: "detached" }); + assert.deepEqual(posts, [{ id: "search", on: true }]); + assert.deepEqual(page.errors, []); + await page.context().close(); + }); + await t.test(`${lang} at ${width}px: on, Settings has no off row`, async () => { + const { page } = await open(lang, width, "?view=settings&tab=models", { searches: ["Kimi"] }); + await page.locator("#searchList .searcher-row").waitFor(); + assert.equal(await page.locator("#searchList .row.feat-off").count(), 0); + assert.deepEqual(page.errors, []); + await page.context().close(); + }); + for (const [id, name, api] of [["tavily", "Tavily", true], ["anysearch", "AnySearch", false]]) { + await t.test(`${lang} at ${width}px: the Library's ${name} says it is the agents' own, and opens Settings`, async () => { + const { page } = await open(lang, width, "?view=library"); + const card = page.locator(`#view-library .mk[data-market="mcp"] .mk-card[data-id="${id}"]`); + await card.waitFor(); + await card.click(); + const sheet = page.locator("#modal .mk-sheet"); + await sheet.waitFor(); + const hint = sheet.locator(".mk-hint", { has: page.locator("button.link") }); + const want = w(OWN) + (api ? " " + w(AS_API, { name }) : "") + " " + w("Set up in Settings"); + assert.equal((await hint.textContent()).trim(), want); + assert.equal(await wide(page), 0); + shots.push([`${lang}-${width}-${id}`, await sheet.screenshot()]); + await hint.locator("button.link").click(); + await page.locator("#view-settings #searchList .row.flash").waitFor(); + await page.locator("#modal").waitFor({ state: "hidden" }); // the sheet closes + assert.deepEqual(page.errors, []); + await page.context().close(); + }); + } + await t.test(`${lang} at ${width}px: a server that doesn't search says none of it`, async () => { + const { page } = await open(lang, width, "?view=library"); + const card = page.locator('#view-library .mk[data-market="mcp"] .mk-card[data-id="fetch"]'); + await card.waitFor(); + await card.click(); + const sheet = page.locator("#modal .mk-sheet"); + await sheet.waitFor(); + assert.equal(await sheet.evaluate((s, own) => s.textContent.includes(own), w(OWN)), false); + assert.deepEqual(page.errors, []); + await page.context().close(); + }); + } + } + }); +} diff --git a/internal/pluginrt/pluginrt.go b/internal/pluginrt/pluginrt.go index 782744741..973f1e880 100644 --- a/internal/pluginrt/pluginrt.go +++ b/internal/pluginrt/pluginrt.go @@ -57,6 +57,12 @@ type Manifest struct { // "settings.section" otel, "part" groups (whatever the page marks // data-feature=""). The runtime contributes them before Apply. Parts []Part + // SetAt is where Settings has its settings, when it has any there: the + // tab and the row they start at, "privacy #redactList". Its row in + // Plugins › Built-in goes there, and there an off plugin says so + // (netube99 on X: masking's switch, settings and page were three + // places, none naming the others). + SetAt string // Defaults is its config before plugins.yml's preset and rows Defaults map[string]any // Settings is a struct of its settings, their defaults its values diff --git a/plugins/gateway/gateway.go b/plugins/gateway/gateway.go index 63e1c06a4..66d150a8c 100644 --- a/plugins/gateway/gateway.go +++ b/plugins/gateway/gateway.go @@ -27,6 +27,7 @@ func init() { keys, err := access.List() return len(keys), err }, + SetAt: "network #portList", Parts: []pluginrt.Part{{Slot: "nav.page", Key: "gateway"}}, Settings: Settings{CallsPage: 20}, Client: []string{"keys.js", "client.js"}, diff --git a/plugins/otel/otel.go b/plugins/otel/otel.go index 56ed5bf00..c76f50093 100644 --- a/plugins/otel/otel.go +++ b/plugins/otel/otel.go @@ -35,6 +35,7 @@ func init() { } return 0, nil }, + SetAt: "otel #otelList", Parts: []pluginrt.Part{{Slot: "settings.section", Key: "otel"}}, Client: []string{"i18n.js", "page.js"}, Apply: func(c *pluginrt.Ctx) error { diff --git a/plugins/redact/redact.go b/plugins/redact/redact.go index 739de5ea9..db1302850 100644 --- a/plugins/redact/redact.go +++ b/plugins/redact/redact.go @@ -22,6 +22,7 @@ func init() { Name: "Privacy masking", Sub: "Secrets, personal data and your own words go to vendors as placeholders, and come back as they were", One: "Masking is on", Many: "Masking is on", InUse: InUse, + SetAt: "privacy #redactList", // Insights › Masking: what masking did, request by request Parts: []pluginrt.Part{{Slot: "nav.page", Key: "masking"}}, Client: []string{"i18n.js", "redact.css", "client.js", "page.js"}, diff --git a/plugins/search/search.go b/plugins/search/search.go index 6a875f16e..4bdf55dfe 100644 --- a/plugins/search/search.go +++ b/plugins/search/search.go @@ -23,6 +23,7 @@ func init() { Name: "Web search", Sub: "Models that can't search the web search with a provider that can, or a search API", One: "1 search source set up", Many: "{n} search sources set up", InUse: InUse, + SetAt: "models #searchList", Apply: func(c *pluginrt.Ctx) error { c.OnDispose(gwtool.Serve(gwtool.WebSearch)) return nil