diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md index f141a3737..908d286e8 100644 --- a/docs/subsystems/gui-shell.md +++ b/docs/subsystems/gui-shell.md @@ -20,7 +20,7 @@ three. | The page | `app.js` keeps one state object per view and renders it into a list, with no framework. The views have their own files: `plugins.js` and `context.js`, and those a plugin adds under `assets/plugins//` (the Gateway, Sessions, Library, Routing and Usage pages, see [plugin runtime](plugin-runtime.md)) (Usage's Context tab, and the context window card the Routing page draws under a request's story, fed by `/api/context` in `context.go`, which scores and tags each agent; a client whose User-Agent names only an HTTP library, a runtime or an API SDK (`usage.IsLibrary`: curl, Bun, python-httpx, Go-http-client, OpenAI/Python), or nothing (`other`), is no agent and goes on one card, `scripts`, named Scripts with its libraries listed, read from each route's kept agent so older history folds too, while the Usage page's Agents list keeps each by its own name (theforeveriris on X, `context_scripts_test.go`, `context-scripts.test.cjs`); clicking a part, a cell or an item opens its text from `/api/context/text`, the last 10 requests' masked bodies in memory, else the request archive's copy masked the same way, with a 404 saying why there is none (`archive`: off, missing, cut, unread; `context_archive.go`), and its Reply the reply from `/api/context/reply` (`openCtxText`, in `ctxtext.js`, `context-text.test.cjs`), rendered 100 items and 20000 characters at a time; a session's details on the Sessions page and Usage's Sessions list draw a Context line of its requests from `/api/context/session`, which reads only the days from its first to its last (30 at most) and keeps that one session, so the tab's 80-session cap never leaves it out (`sessCtxLine` in `plugins/usage/page.js`, liang_yongxiang on Discord, `context_session_test.go`, `sessions-context-line.test.cjs`); its "Tuned for you" cards are fed by `/api/tune` in `tune.go`, see [agent wiring](agent-wiring.md)). Strings go through `t()` with translations in `i18n.js`, and a plugin's own in its `i18n.js` (zh, zh-TW, ja and de; the English text is the key and the fallback). zh-TW is Traditional Chinese with Taiwan's words; a system language of zh-TW, zh-HK, zh-MO or any zh-Hant picks it, and the tray menu and notifications follow (`trayLang`). Dropdowns use `openProtoMenu`. Every app menu (`openProtoMenu`, `openRowMenu`, `openSessCombo`) is placed by `placeMenu`: under its anchor, or over it when the window runs out below; one that fits neither way takes the larger room, its height held to it, and scrolls inside itself, and a scroll inside a menu doesn't close it (#1437, `removed-groups-menu-scroll.test.cjs`). The highest any popover goes is `popTop`: 8px under `header.top` on a Mac window, where the traffic lights are drawn over the page, and 8px from the top elsewhere; `placeMenu`, the field picker's `placePop` (which also holds `#pop`'s height to that room) and an agent's model list (`openAgentModels`) all use it (#1573, `popover-mac-chrome.test.cjs`). Scrolling is done only by `scrollOnPurpose(e)` with the reader's event. | [`assets/app.js`](../../internal/gui/assets/app.js), [`assets/i18n.js`](../../internal/gui/assets/i18n.js) | | Window navigation | In the window from 1024 points wide (`SIDE_AT`, the same width as app.css's `side-nav` rules), `layoutNav` moves the brand, the pages (`#nav`) and Settings into the sidebar (`#side`): the pages in four groups (Work, Models, Insights, Extend; a group none of whose pages shows, as in gateway mode, leaves out its name), the gateway's address at its foot (`sideGwRead`, read from `/api/providers` only while there is a sidebar, or drawn at once from boot.js's `sideGateway`; on a page other machines open, `magpie web`, it is `MAGPIE_PUBLIC_URL` while they are let in, as the Gateway page's address and About's Gateway URL are, noahhrreion on Discord; a port applied in Settings redraws it), and the header a breadcrumb (`renderCrumb`). A page whose head holds only its tools (Library, Plugins, Settings) has them in the title bar after the breadcrumb, `tools` setting the room between it and the window's own buttons. When they don't fit there the tools show their icons alone (`tools-tight`; each keeps its name as `aria-label` and in its tooltip), then the breadcrumb drops its leading parts, and last the page's name is cut at its end, so no tool lies over the title (#2625, `title-bar-tools.test.cjs`). The open page's own tabs (`NAV_SUBS`: Usage, Library, Plugins, Settings) are listed under it as `.nav-s` rows (`role="tab"`, `data-of` the page tab's id) and the page's strip is hidden; a row's click clicks that tab at once, the selection (`.nav-hl`) having set off as the row was pressed (`navSubGlide`; back if the press leaves the row), and is the list's only shape: a row hovered or pressed has no ground of its own, and a `MutationObserver` draws the list again when the strip changes. A page's tabs share its one scroll, so a row that picks another tab opens it at its top (`scrollOnPurpose` with the row's click); the tab already open, picked again, leaves the page where it is (`sidebar-tab-top.test.cjs`). The list opens and folds with an iOS-like spring (`navSubEnter`, `navSubLeave`; none under reduced motion), and a folding list is out of reach at once. The open page's own row is marked the same way, by one shape (`.nav-top-hl`, the rows' own ground given up to it, hovered or pressed too) that `navTopGo` moves to the row picked on a damped spring, as iOS moves a selection (`NAV_SPRING`, SwiftUI's response 0.42s and damping 0.84; `navTopStep` steps it each frame): it sets off as the row is pressed and comes back if the press leaves the row or the page isn't left, turns with the speed it has when the press changes its mind, and follows its row while the list above it folds, landing where the row ends up. It is put in place, not sent, when the window opens on a page or the rows move under it at rest (a `ResizeObserver`), is away while Settings is open (it has its own selection at the foot), comes back fading in on its row, jumps under reduced motion, and isn't drawn in the header's tabs, which have their `.thumb`. `#nav` is `position: relative` in the sidebar for it, so `.seg`'s centring `left` and `top` are reset. See `sidebar-glide.test.cjs`. Narrower, the page beside a sidebar would be narrower than Usage's requests table needs (768 points), so they go back into the header's row, as a Mac sidebar gives way in a narrow window. At every width the reader can pick the sidebar or the header's tabs from the title bar's button (`#sideToggle`, ⌃⌘S or Ctrl+Shift+S; `toggleSideNav`), kept in localStorage `magpie.navLayout` (`side` or `top`) and so laid out from the first frame; none picked, the sidebar comes from `SIDE_AT`. Picked in a narrow window the sidebar is narrower (184 points under 860), and magpie web on a phone keeps its own tab bar and has no button. The two layouts trade places in a view transition (`navMorph`, app.css `.nav-morph`): the sidebar slides, each page's tab flies to its place in the other, and the page slides as one (its old image dropped, so no line prints twice); without view transitions, under reduced motion, or in the Linux app the change is at once: WebKitGTK with compositing off (`WEBKIT_DISABLE_COMPOSITING_MODE`, which `webkit_linux.go` sets under Wayland) crashes in a view transition. Elsewhere a transition still going after `MORPH_MAX` (1.5s) is skipped, so a webview that never ends one can't leave the window on the old layout's picture. See `side-toggle.test.cjs`. A window made wider or narrower drops what a click held (`heldWidth`): the page laid out again isn't the click's doing. The reader's own place is kept instead for a second while the page is laid out again (`relaid`, a `ResizeObserver` on the open page's parts calling `backToReader`): crossing `SIDE_AT` the browser clamps the scroll to each layout it passes through, and the page ended short of its foot (#1672, `text-size.test.cjs`). See `sidebar.test.cjs`. A sidebar longer than a short window keeps no scroll bar beside its pages: the native bars of `.side-scroll` and `.side-foot` are hidden, and `sideBars` lays a thin bar over each box's edge that shows while it scrolls, fades about a second after it stops (kept while hovered or dragged), can be dragged or clicked to page, and is gone when the box fits, the same in WebKit, WebView2 and WebKitGTK. See `sidebar-overlay-scrollbar.test.cjs`. The window opens on the page the reader last left, as a Mac app comes back as it was (molvqingtai and lc on Discord): `show` keeps the page in localStorage `magpie.lastView` (which the app's webview keeps across restarts, as it keeps `magpie.navLayout`), and `keptView` opens it at start. A page asked for in the address (`?view=`, the tray's links, a reload) wins, Agents too; a kept name that is no page opens the first page, and one gateway mode leaves out opens Providers (`show`). Opening on it scrolls nothing. See `last-page.test.cjs`. | [`assets/app.js`](../../internal/gui/assets/app.js), [`assets/app.css`](../../internal/gui/assets/app.css) | | Settings › Privacy | The page opens on what masking kept from vendors (`drawMaskObs` in app.js, fed by `/api/masking/summary`): the values masked over 7 or 30 days with a chart of the days, the kinds, what only the local model found, agents to providers, and the values masked most, each shown only while pointed at (`maskTip`, `/api/masking/value`, which says it is gone after a restart). Its records (`drawMaskRecs`, `/api/masking/records` and `/api/masking/record`) take the page's place, filtered by kind, finder, agent or provider, a day at a time, each opening on the text the vendor saw with its placeholders marked. `maskedBadge`, on the Gateway page's recent calls and the Routing page's log, opens a request's own record (`openMaskRecord`), in amber with the count sent as written when every value found was on Warn. Below the card, *What to mask*, *How it's found* (the rules, always on while anything is masked, and the local model on top of them), *When a value is found* (Mask, Warn or Block per kind, the secret kinds first and the personal ones behind *Show all kinds*, and the *Never mask* list; `renderMaskActions`, with *Never mask* and *Masked words* drawn a value a row by `wordList` in `plugins/redact/settings.js`, saved as the same list of strings the one comma-separated box saved, `redact-words-list.test.cjs`), *Try it* (`renderMaskTry`, the text as the vendor would get it from `/api/masking/preview`, kept in no storage) and *Sharing*. *Agents' session history* (`renderSessionReads`, read from `/api/sessions/reads` only while the Privacy part is shown) has *Agents found later* and a row per agent found, the choice the Sessions page asks first on a fresh install; see [gateway sessions](gateway-sessions.md#which-agents-sessions-magpie-reads). While anything is masked, *Instead of masking, send to* (`redactRouteRow` in `plugins/redact/settings.js`, the redact plugin's part of Settings, which wraps `renderRedact` so app.js carries none of it) picks, in the app menu, a model a request masking would change goes to as written: Off by default, and only the models `/api/settings` lists as `maskRouteModels` (every route of theirs unmasked, `gateway.MaskRoute`), saved with `POST /api/settings/redact-route` (`redact-route.test.cjs`). See [gateway routing](gateway-routing.md) for what is recorded. | [`assets/app.js`](../../internal/gui/assets/app.js), [`masking.go`](../../internal/gui/masking.go) | -| Built-in plugins | Plugins › Built-in, the page's first tab (`drawBuiltin` in `plugins.js`, rows by `renderBuiltins` in `app.js`), lists magpie's built-in plugins, each with a name, a line on what it is and a switch: Routing groups, Library, Observability, Sessions, Warm-up and check-in, and the Gateway and Routing pages (Essential). A plugin on with settings has their rows under its row, drawn from its schema by the kernel's `ui.form`, and a change posts `{id, config}`. The Gateway page is drawn by its plugin's own scripts through the window's kernel (`kernel.js`, `assets/plugins/gateway/`); see the [plugin runtime](plugin-runtime.md), "The window's kernel". They are `plugins/*` registered with the [plugin runtime](plugin-runtime.md); `GET /api/plugins/builtin` says each one (`builtinJSON`: on is active, the user's own choice, what of it is in use) and `POST {id, on}` (or `{id, config}`) writes plugins.yml. A page marks what goes with a plugin `data-feature=""`. Off, `featureStyle` hides everything so marked (rows drawn later too), `navHides` leaves its page's tab out of the sidebar and the header, `show` opens Agents for an address kept for it, and `setSetTab`, `partShows` and `findSettings` leave its Settings tab and rows out, of the search too. One in use stays on: its switch is disabled and the row says what uses it, and the POST refuses it off. A plugins.yml that doesn't parse is said above the list and no switch moves. `boot.js` says which are off (`featuresOff`) and their settings (`pluginConfig`) before the first paint, and `settings.builtins` carries the list on every state read. The TUI doesn't follow them. See `builtins.test.cjs`, `builtins_test.go`. | [`builtins.go`](../../internal/gui/builtins.go), [`assets/plugins.js`](../../internal/gui/assets/plugins.js), [`assets/app.js`](../../internal/gui/assets/app.js) | +| Built-in plugins | Plugins › Built-in, the page's first tab (`drawBuiltin` in `plugins.js`, rows by `renderBuiltins` in `app.js`), lists magpie's built-in plugins, each with a name, a line on what it is and a switch: Routing groups, Library, Observability, Sessions, Warm-up and check-in, and the Gateway and Routing pages (Essential). A plugin on with settings has their rows under its row, drawn from its schema by the kernel's `ui.form`, and a change posts `{id, config}`. The Gateway page is drawn by its plugin's own scripts through the window's kernel (`kernel.js`, `assets/plugins/gateway/`); see the [plugin runtime](plugin-runtime.md), "The window's kernel". They are `plugins/*` registered with the [plugin runtime](plugin-runtime.md); `GET /api/plugins/builtin` says each one (`builtinJSON`: on is active, the user's own choice, what of it is in use) and `POST {id, on}` (or `{id, config}`) writes plugins.yml. A page marks what goes with a plugin `data-feature=""`. Off, `featureStyle` hides everything so marked (rows drawn later too), `navHides` leaves its page's tab out of the sidebar and the header, `show` opens Agents for an address kept for it, and `setSetTab`, `partShows` and `findSettings` leave its Settings tab and rows out, of the search too. Settings' search lists the built-ins themselves after its own rows, off or on, by name, line or a setting in their schema (Gateway's Recent calls at a time is on its own page), and Open lights the row in Plugins › Built-in (`setFeatsFind` in the lazy [`setfeats.js`](../../internal/gui/assets/setfeats.js), `settings-search.test.cjs`). Its provider links are drawn the first time a search wants them (`provlinks.js`). One in use stays on: its switch is disabled and the row says what uses it, and the POST refuses it off. A plugins.yml that doesn't parse is said above the list and no switch moves. `boot.js` says which are off (`featuresOff`) and their settings (`pluginConfig`) before the first paint, and `settings.builtins` carries the list on every state read. The TUI doesn't follow them. See `builtins.test.cjs`, `builtins_test.go`. | [`builtins.go`](../../internal/gui/builtins.go), [`assets/plugins.js`](../../internal/gui/assets/plugins.js), [`assets/app.js`](../../internal/gui/assets/app.js) | | The app's log | `runGUI` and `runPanel` (so `magpie`, `app`, `tray`, `panel`, a window view and a `magpie:` link) call `startLog` before `gui.Run`: `applog.Start` sends the standard logger, which the gateway, the plugin host and Wails' error handler write to, to `app.log` in `appdir.Logs` as well as stderr (`quiet`, which never fails, first, since io.MultiWriter stops at a failed writer and an app opened from Explorer has no stderr), and points `debug.SetCrashOutput` at it, so a panic is in it. Opened from the Finder, the Dock or the Start menu the app has no terminal, and wrote its log nowhere (rayem1w on X, 0.1.2330). The folder is `~/Library/Logs/magpie` on macOS (beside the launch agent's `serve.log`, which launchd writes for `magpie serve`: the two processes never share a file), `%LOCALAPPDATA%\magpie\logs` on Windows, `$XDG_STATE_HOME/magpie` (`~/.local/state/magpie`) elsewhere, and `logs` in a portable data folder. The file is 0600. At 5 MiB (`Limit`) it becomes `app.old.log`; when another magpie (an update's new process) rotated it already (`os.SameFile` of the open file and the path differs), it is only opened again, and when it can't be moved it is emptied. Each line goes through `scrub`, which masks bearer and basic credentials, key and token query parameters, and `sk-`, `AIza`, `gh?_` and JWT shapes, though nothing logged is meant to carry one. Settings › About's Log row (`#logRow`, `settingsJSON.Log` from `applog.Current`, so `magpie web`, which writes no file, shows none) has its path and an Open (`POST /api/settings/log/reveal`) that shows its folder; `magpie log` prints where every log is, `-n` the last lines, `-f` follows across a rotation (`TestTheAppWritesItsLog`, `TestLogFollows`). | [`internal/applog/applog.go`](../../internal/applog/applog.go), [`gui_on.go`](../../internal/cli/gui_on.go), [`log_cli.go`](../../internal/cli/log_cli.go) | | No GUI build | `-tags nogui` builds magpie without the GUI: `hasGUI` is false and `runGUI` says to use `magpie tui`. The files of `internal/gui` that need Wails build under `!nogui`. | [`gui_off.go`](../../internal/cli/gui_off.go) | | The terminal quitting | `magpie tui` that served the gateway with an agent connected hands the gateway on as it quits, on Linux where nothing opens magpie at login (a WSL distro, a server over SSH; zaidu259434 on X): `keepGateway` starts magpie's service when it is installed, installs it (`daemon.Install`) when the user never removed it (`daemon.Removed`, a mark `magpie daemon uninstall` leaves), and otherwise starts `magpie serve` in its own session (`serveInBackground`, log in magpie's cache). Elsewhere, or with nothing connected, it only says the gateway stopped. Where magpie opens at login (`autostart.Enabled`, which on Linux counts a package's own autostart entry, also on a box no desktop logs into) it leaves the gateway to the app, and the note says `magpie autostart off` has the terminal hand it on where no desktop logs in (`atLoginNote`, #3756). | [`keep.go`](../../internal/tui/keep.go) | diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 9af3082ac..d276b3306 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -19796,6 +19796,9 @@ function findSettings() { page.hidden = !hits; any ||= hits > 0; } + // the built-ins that match (setfeats.js) + if (window.setFeatsFind) any = setFeatsFind(words) > 0 || any; + else import("./setfeats.js").then(() => setQuery && findSettings(), () => {}); const none = $("#setNone"); none.hidden = any; none.textContent = t("No setting matches “{q}”", { q: $("#setQ").value.trim() }); @@ -19807,6 +19810,7 @@ function searchSettings(q) { v.classList.remove("set-searching"); for (const n of v.querySelectorAll(".set-miss")) n.classList.remove("set-miss"); $("#setNone").hidden = true; + window.setFeatsFind?.([]); setSetTab(setTab); } { diff --git a/internal/gui/assets/setfeats.js b/internal/gui/assets/setfeats.js new file mode 100644 index 000000000..c2ce6e25d --- /dev/null +++ b/internal/gui/assets/setfeats.js @@ -0,0 +1,68 @@ +// Settings' search, through Plugins › Built-in too: a built-in's switch, +// and the settings it has there or on its own page (Gateway's Recent calls +// at a time), were found by nothing in Settings, and one switched off took +// its Settings rows away with it, so a search for it said no setting +// matched (the scattered settings audit after netube99 on X). Each built-in +// whose name, words or settings match is listed after Settings' own rows, +// off ones too, and Open goes to its row in Plugins › Built-in. Loaded by +// app.js the first time a search runs, as provlinks.js is. + +// the built-in an Open is for: its row is lit (and scrolled to once) each +// time Plugins › Built-in draws it in the next few seconds, as the list is +// drawn again when the plugins are read +let featAt = null, featAtEnd = 0; +{ + const draw = window.renderBuiltins; + window.renderBuiltins = (box, list, done) => { + draw(box, list, done); + const row = featAt && box.querySelector(`.feat-row[data-id="${featAt.id}"]`); + if (!row) return; + if (!featAt.scrolled) row.scrollIntoView({ block: "center" }); + featAt.scrolled = true; + row.classList.add("flash"); + }; +} +window.setFeatsFind = function (words) { + let box = document.getElementById("setFeats"); + if (!box) { + box = el("section", "set-page set-feats"); + box.id = "setFeats"; + box.append(el("div", "list prefs")); + $("#view-settings").append(box); + } + const list = box.firstChild; + const say = (s) => (s ? s + " " + t(s) : ""); + const found = ((words.length && prefs?.builtins) || []).filter((f) => { + const props = Object.values(f.schema?.properties || {}); + const text = [say(f.name), say(f.sub), ...props.map((p) => say(p.title) + " " + say(p.description))].join(" ").toLowerCase(); + return words.every((w) => text.includes(w)); + }); + // drawn again only when it changes: a draw is a change Settings' + // observer runs the search again on + const key = document.documentElement.lang + " " + found.map((f) => f.id + (f.on ? "+" : "-")).join(" "); + if (box.dataset.key === key) return found.length; + box.dataset.key = key; + list.replaceChildren(); + for (const f of found) { + const r = el("div", "row pref feat-find"); + r.dataset.id = f.id; + const who = el("div", "who"); + who.append(el("div", "name", t(f.name))); + const sub = [f.on ? "" : t("Off"), f.sub ? t(f.sub) : ""].filter(Boolean).join(" · "); + if (sub) who.append(el("div", "sub", sub)); + const go = el("button", "text", t("Open")); + go.type = "button"; + go.onclick = () => { + featAt = { id: f.id, scrolled: false }; + clearTimeout(featAtEnd); + featAtEnd = setTimeout(() => { featAt = null; }, 3000); + window.pluginTabTo?.("builtin"); + show("plugins"); + }; + r.append(who, go); + list.append(r); + } + box.dataset.part = t("Plugins") + " › " + t("Built-in"); + box.hidden = !found.length; + return found.length; +}; diff --git a/internal/gui/tests/old-webkit.test.cjs b/internal/gui/tests/old-webkit.test.cjs index ac79887a4..6551674b7 100644 --- a/internal/gui/tests/old-webkit.test.cjs +++ b/internal/gui/tests/old-webkit.test.cjs @@ -165,7 +165,7 @@ test("compat.js is the first of the page's own scripts", async () => { // Image generation, provlinks.js when Settings' search first wants its // provider links; the checks above // still read them - for (const f of await scripts()) if (!["webfonts.js", "cfgblocked.js", "signsheets.js", "ruleedit.js", "ratewindows.js", "traywindows.js", "autoresetown.js", "registry.js", "navlamp.js", "whatsnew.js", "claudemode.js", "ctxtext.js", "resetask.js", "quotaall.js", "quitask.js", "checkinnow.js", "autobackup.js", "scrollends.js", "profilerename.js", "settingshints.js", "keyspend.js", "syncfiles.js", "agentcompact.js", "balfound.js", "passerrors.js", "keybalance.js", "modellimits.js", "notices.js", "videogen.js", "provlinks.js"].includes(f)) assert(all.includes(f), f + " is not loaded by index.html"); + for (const f of await scripts()) if (!["webfonts.js", "cfgblocked.js", "signsheets.js", "ruleedit.js", "ratewindows.js", "traywindows.js", "autoresetown.js", "registry.js", "navlamp.js", "whatsnew.js", "claudemode.js", "ctxtext.js", "resetask.js", "quotaall.js", "quitask.js", "checkinnow.js", "autobackup.js", "scrollends.js", "profilerename.js", "settingshints.js", "keyspend.js", "syncfiles.js", "agentcompact.js", "balfound.js", "passerrors.js", "keybalance.js", "modellimits.js", "notices.js", "videogen.js", "provlinks.js", "setfeats.js"].includes(f)) assert(all.includes(f), f + " is not loaded by index.html"); }); test("the styles hold up in Safari 15.0", async () => { diff --git a/internal/gui/tests/settings-search.test.cjs b/internal/gui/tests/settings-search.test.cjs index c2981d981..0f74fc2d6 100644 --- a/internal/gui/tests/settings-search.test.cjs +++ b/internal/gui/tests/settings-search.test.cjs @@ -6,7 +6,9 @@ // of it; a setting that moved to its provider's editor (the warm-ups, the // owner on 11-07) is found as a link per provider, Codex's and Claude // Code's alike, whose Open takes the reader to that editor; nothing found -// says so; a link needs its provider, and its plugin on. Escape, or clearing the box, brings back the part +// says so; a link needs its provider, and its plugin on; a built-in +// whose name, words or settings match is listed after them, off or on, and +// Open goes to its row in Plugins › Built-in. Escape, or clearing the box, brings back the part // picked as it was. Nothing is posted and the page doesn't scroll. In the // smallest window (560 x 420) and magpie web on a phone (390 wide), nothing // runs off to the side. Every language; no backend, the API is faked here. @@ -20,7 +22,7 @@ const { openPart, provPrefsProviders } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); -function server(lang, posts, web, { provs = ["codex", "claude"], off = [] } = {}) { +function server(lang, posts, web, { provs = ["codex", "claude"], off = [], builtins = undefined } = {}) { const cur = { theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd", textSize: 100, dock: false, dockWindow: false, proxy: "", redact: false, redactPersonal: false, redactWords: [], @@ -29,7 +31,7 @@ function server(lang, posts, web, { provs = ["codex", "claude"], off = [] } = {} version: "0.1.400", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3425", proxyNow: "none", proxySource: "none", login: false, visionModels: [], imageGenModels: [], workbuddyCheckins: [], lanURLs: [], - fx: { rate: 7.2, at: new Date().toISOString(), stale: false }, + fx: { rate: 7.2, at: new Date().toISOString(), stale: false }, builtins, }; return async (route) => { const req = route.request(), url = new URL(req.url()); @@ -40,6 +42,7 @@ function server(lang, posts, web, { provs = ["codex", "claude"], off = [] } = {} if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light", textSize: 100 }, fx: cur.fx }); if (url.pathname === "/api/settings") return json(cur); if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/plugins/builtin" && builtins) return json(builtins); if (url.pathname === "/api/providers") return json(provPrefsProviders(provs, { codex: "ChatGPT", claude: "Claude" })); if (url.pathname === "/api/usage/quotas") return json([]); if (url.pathname === "/api/groups") return json({ groups: [], models: [] }); @@ -203,6 +206,50 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", } }); + // the built-ins are found too, with what they set on their own page or + // in Plugins › Built-in, and one switched off (its Settings tab gone + // with it), and Open goes to its row in Plugins › Built-in + await t.test("built-ins are found, and Open goes to their row", async () => { + 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("otel", "Observability", "Send each request's trace to an OpenTelemetry collector", false, { setAt: "otel #otelList" }), + row("gateway", "Gateway page", "", true, { page: "gateway", setAt: "network #portList", config: { callsPage: 20 }, + schema: { type: "object", properties: { callsPage: { type: "integer", title: "Recent calls at a time", description: "How many of the gateway's recent calls the page shows, and how many more each Show more adds", enum: [10, 20, 50, 100], default: 20 } } } }), + ]; + for (const lang of LANGS) { + const posts = []; + const page = await open(lang, posts, { builtins, off: ["otel"] }); + const tr = (s, vars) => page.evaluate(([s, vars]) => t(s, vars), [s, vars]); + const found = page.locator("#setFeats .feat-find:visible"); + for (const [words, want] of [ + [await tr("Recent calls at a time"), [[await tr("Gateway page"), ""]]], + ["recent calls", [[await tr("Gateway page"), ""]]], + [await tr("Observability"), [[await tr("Observability"), await tr("Off") + " · " + await tr("Send each request's trace to an OpenTelemetry collector")]]], + ["zzqqxx", []], + ]) { + await type(page, words.toLowerCase()); + await page.waitForFunction((n) => document.querySelectorAll("#setFeats .feat-find").length === n || (!n && !document.querySelector("#setFeats:not([hidden])")), want.length); + const got = []; + for (const r of await found.all()) got.push([(await r.locator(".name").textContent()).trim(), (await r.locator(".sub").count() ? (await r.locator(".sub").textContent()).trim() : "")]); + assert.deepEqual(got, want, lang + " " + words); + const s = await state(page); + assert.equal(s.none, want.length ? "" : await tr("No setting matches “{q}”", { q: words.toLowerCase() }), "no 'nothing matches' over a built-in found"); + if (want.length) assert.equal(await page.locator("#setFeats").getAttribute("data-part"), await tr("Plugins") + " › " + await tr("Built-in")); + assert.deepEqual(await overflow(page), []); + } + await type(page, await tr("Observability")); + shots.push([lang + "-builtins", await page.screenshot()]); + await type(page, ""); + assert.equal(await seen(page, "#setFeats"), false, "put away with the search"); + await type(page, "recent calls"); + await found.first().locator("button", { hasText: await tr("Open") }).click(); + await page.locator('#builtinList .feat-row.flash[data-id="gateway"]').waitFor(); + assert.deepEqual(posts, [], "finding and opening posts nothing"); + assert.deepEqual(page.errors, []); + await page.context().close(); + } + }); + await t.test("magpie web on a phone", async () => { const page = await open("zh", [], { width: 390, height: 760, web: true }); assert.deepEqual(await overflow(page), []);