diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md index 3ef1656f6..c3c039411 100644 --- a/docs/subsystems/gui-shell.md +++ b/docs/subsystems/gui-shell.md @@ -158,6 +158,7 @@ retry after a failed read. See `TestRecentCallBodiesOnDemand` and - Opening the allowances is asking to see them (#1588, `quotasOpened` in `app.js`): the Usage page from the nav or its Overview tab picked, the window brought back to the front on the Overview, the tray panel's Allowances tab picked or the panel brought up on it, and a menu bar cell clicked each load `usage/quotas?asked=1`, as Refresh now does. An asked read makes the backend read every account again (`AskClaudeUsage`), so an opening within 30s (`QUOTAS_OPEN_GAP`) of the last asked read sends an ordinary read instead, which joins one on its way; Refresh now always asks. A panel page loaded while it is put away (hidden, or without focus) doesn't ask. The timed refresh is unchanged and never asks. See `allowance-open-read.test.cjs`. - The Usage page's cards are packed into columns, never all stretched to a row's height (`packUsage`, #860): each card in that order goes to the leftmost column that ends highest, on 1px grid rows, so short cards stack beside a tall one. The last card in each column then reaches down to where the tallest column ends (a `min-height`, cleared before the cards are measured again), so cards side by side in one row are as tall as each other and a stack ends with the tall card beside it (ikunbots on X); content stays at each card's top. The page's order (DOM, dragging, Alt+arrows) stays `UsageOrder`. The column count is the most 260px columns that fit, or one fewer when that leaves much less empty room; it is chosen again only when the cards change or the width fits another number of columns, so a card opened or folded stays where it is, even as the scrollbar comes in. See `usage-pack.test.cjs`. - The Providers page has a search box over its list (#1614, `findProviders` in [`app.js`](../../internal/gui/assets/app.js)): the words typed keep the rows, on and off, whose text or data say them all: name, id, preset, addresses, every model's id and name, the account's user and plan and each login's, account names and key names. The Turned off fold stays open while searching; Escape or clearing the box shows every row and the fold as it was. A row that is on reorders by dragging its logo, Alt+↑/↓, Alt+Shift+↑/↓ (top, bottom) or its right-click menu (`openProviderMenu`: Move to top, Move up, Move down, Move to bottom). While searching, a step or a drop moves it among the rows shown (it takes the place of the row it passes, `stepProvider`, `shownToOn`) and the hidden ones keep their order; Move to top and Move to bottom go to the ends of the whole list. Every move saves the whole order through `POST /api/providers/arrange`. See `provider-find.test.cjs` and `provider-order.test.cjs`. +- A new user's Agents page (the window's first page and the panel's Agents tab) has a *Get started* card above the agents in the welcome's place (wangye1644294 on X, `guideCard` in [`app.js`](../../internal/gui/assets/app.js)). Its three steps are: add a model source; connect an agent, where the agents magpie found that can be connected are named and each is connected in one click (`agents/connect`); and, optional, a routing group, with the most harmless starter template that can be made from the user's models (`provider.Templates`, Never stuck first) added in one click through `POST /api/groups/template`. Every tick comes from the state: the models magpie serves (`served` in `/api/state`, groups left out), an agent wired, or a group that isn't automatic. None comes from the card having been seen. The card goes once the first two steps are done. Its close button saves `settings.GuideHidden` through `POST /api/settings/guide`, so the panel, the window and a reload agree, and the Settings save keeps it. See `getting-started.test.cjs`. - The page must work in Chromium (Windows' WebView2) and WebKit (macOS, and WebKitGTK on Linux). GUI tests run in both engines. - On Linux the panel is frameless and the main window has a hidden title bar (`plainTitlebar`). GTK 3 asks KDE's Wayland session (KWin's decoration protocol) for a frame drawn by KWin on any window without client-side decorations, an undecorated one too, so `ownFrame` tells KWin the panel draws its own on each realize (#1283). GTK 4 builds ask for none themselves. With no KWin title bar, and with a Wayland window placed by the compositor rather than by the icon, the panel's header is its drag handle on Linux, as the window's is (`--wails-draggable` in `app.js`; `panel-drag-linux.test.cjs`); on the Mac and Windows the panel isn't dragged (#1430). - A Wayland window can't place itself, so under Hyprland and niri the compositor is asked to put the panel under the bar. Under Hyprland `placePanel` gives it a window rule at the cursor (`omarchy.PlacePanel`) and closes it on a click outside (`omarchy.ReportClicks`). niri (`omarchy.Niri`, `NIRI_SOCKET` set) takes no rules at runtime and doesn't report the cursor. There `omarchy.NiriPanel` watches niri's event stream and moves the panel each time it opens: the window of magpie's pid titled `panelTitle`, moved with `MoveFloatingWindow` (after `MoveWindowToFloating` if it was tiled). It goes 6 px under the working area's top, centred on the x the tray host passed to `Activate(x, y)`. Wails keeps that x in its Linux tray (`trayClick`, `TestTrayClickIsWails`), and it is taken across the bar, since that's all a Wayland bar knows. With no click (`magpie panel`), or with one off the output, it goes top right. Wails' `HideOnFocusLost` closes it, since a click on another window takes niri's focus. It still opens in the middle and slides up, and a bar at the bottom or the side isn't accounted for (#1670). diff --git a/internal/gui/api.go b/internal/gui/api.go index 14806d17f..d7a8d3b57 100644 --- a/internal/gui/api.go +++ b/internal/gui/api.go @@ -276,6 +276,10 @@ type stateJSON struct { // Last: this is the state kept from the last read (laststate.go), for // the page to draw while the fresh one is read Last bool `json:"last,omitempty"` + // Served is how many models magpie serves, groups left out: the Get + // started card's first step ("add a model source") is done once + // there is one, agents found or not + Served int `json:"served"` } // unlistedJSON is a model of a provider kept for routing groups, and the @@ -1089,6 +1093,8 @@ func Handler(w Windows, gw *gateway.Server) http.Handler { in.CompactAt = cur.CompactAt // and so is the threshold // Claude Desktop's list, set in its row on the Agents page in.DesktopLongest = cur.DesktopLongest + // and the Get started card put away, from the card itself + in.GuideHidden = cur.GuideHidden in.CodexTitles = cur.CodexTitles // set on its own (codex-titles below) // and so is the model Codex's auto-review runs on (codex-auto-review) @@ -1280,6 +1286,21 @@ func Handler(w Windows, gw *gateway.Server) http.Handler { } writeJSON(rw, settingsState()) }) + // the Agents page's Get started card put away, or back (GuideHidden) + mux.HandleFunc("POST /api/settings/guide", func(rw http.ResponseWriter, r *http.Request) { + var in struct{ Hidden bool } + if err := json.NewDecoder(r.Body).Decode(&in); err != nil { + fail(rw, err) + return + } + s := settings.Load() + s.GuideHidden = in.Hidden + if err := settings.Save(s); err != nil { + fail(rw, err) + return + } + writeJSON(rw, settingsState()) + }) // whether Claude Desktop lists a model of 1M or more once, by its 1M id // (settings.DesktopLongest, #1272): it reads the list as it starts mux.HandleFunc("POST /api/settings/desktop-longest", func(rw http.ResponseWriter, r *http.Request) { @@ -1861,6 +1882,11 @@ func state() stateJSON { } s.Unlisted = unlistedModels() s.CLIBehind = cliBehind() + for _, e := range provider.Served() { + if e.Group == "" { + s.Served++ + } + } for _, a := range agent.Clients() { s.Clients = append(s.Clients, clientJSON{ID: a.ID, Name: a.Name, Icon: a.Icon}) } diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index 298b86c5c..03375130f 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -3556,6 +3556,42 @@ body.window .row.agent > .ag-conn { margin-left: 12px; align-self: center; curso .ag-lead .ag-lead-h { display: block; font-size: 14px; margin-bottom: 4px; } .ag-lead p { margin: 0; line-height: 1.55; color: var(--muted); } .ag-lead .text.primary { margin-top: 12px; } +/* Get started (wangye1644294 on X): a new user's steps, in the lead's + place, as a grouped list on a card, each step's number turning into a + tick as it is done; nothing striped, the tick is the state */ +.ag-lead.guiding { margin: 0 0 12px; } +.guide { padding: 14px 16px 6px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); } +.guide-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; } +.guide-h { font-size: 14px; } +.guide-n { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; } +.guide-x { margin-left: auto; flex: none; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 11px; color: var(--muted); } +.guide-x:hover { background: var(--pill); color: var(--fg); } +.guide-x:focus-visible, .guide-agent:focus-visible { outline: 1.5px solid var(--accent); outline-offset: 1px; } +.guide-steps { list-style: none; } +.guide-step { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; } +.guide-step + .guide-step { border-top: 1px solid var(--line-2); } +.guide-tick { flex: none; display: grid; place-items: center; width: 20px; height: 20px; margin-top: 0; border-radius: 10px; border: 1.5px solid var(--faint); color: var(--muted); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; } +.guide-step.done .guide-tick { border-color: var(--green); background: var(--green); color: var(--card); } +.guide-body { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; line-height: 1.45; } +.ag-lead .guide-title { font-weight: 550; } +.guide-step.done .guide-title { color: var(--fg-2); } +.guide-say { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; } +.guide-step.optional:not(.done) .guide-title { color: var(--fg-2); } +.ag-lead .guide .text.primary { margin-top: 5px; } +.guide-acts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; } +.guide-acts .text { margin-top: 5px; } +.guide-agents { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 5px; } +.guide-agent { display: inline-flex; align-items: center; gap: 6px; height: 26px; max-width: 100%; padding: 0 10px 0 7px; border: 1px solid var(--line); border-radius: 13px; background: var(--card); color: var(--fg); font-size: 12px; cursor: pointer; transition: background .12s, border-color .12s; } +.guide-agent > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.guide-agent .ic { width: 15px; height: 15px; flex: none; } +.guide-agent:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); } +.guide-agent:disabled { cursor: default; color: var(--muted); } +.guide-agent:disabled .ic { opacity: .55; } +.guide-agent.busy { color: var(--fg); } +.guide-more { color: var(--muted); font-size: 12px; } +body.panel .guide { padding: 10px 12px 4px; border-radius: 10px; } +body.panel .guide-step { gap: 10px; padding: 8px 0; } +body.panel:not([data-ptab="agents"]) #agentsLead { display: none; } /* the first line keeps its place opened: a line of its own height, the row not centring what it holds; no gap between its lines, which the opened part couldn't fold away: it starts where the shut row ended */ diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 1cdb80e24..996150357 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -1334,6 +1334,16 @@ function agentsLead(list) { list.before(lead); } lead.replaceChildren(); + // a new user's first view: the Get started card in the welcome's place, + // in the panel as in the window + const g = guideShown(); + lead.classList.toggle("guiding", !!g); + if (g) { + lead.hidden = false; + lead.classList.remove("welcome"); + lead.append(guideCard(g)); + return; + } const kinds = mode === "panel" ? [] : state.agents.map(connectKind); lead.hidden = !kinds.some((k) => k === "ok" || k === "empty"); if (lead.hidden) return; @@ -1354,9 +1364,227 @@ function agentsLead(list) { } } +// ---------- Get started (wangye1644294 on X) ---------- +// A new user is shown three steps above the agents: add a model source, +// connect an agent (those magpie found here listed, each connected in a +// click), and, optionally, a routing group made of their own models in a +// click (provider.Templates). Each step is ticked from what is so — the +// models magpie serves (state.served), an agent wired, a group of the +// user's own — never from having been seen. The card goes once the first +// two are done, or when put away (settings.GuideHidden, saved on the +// server so the panel and the window agree). + +// the templates offered as a starter, most harmless first: each behind +// the other changes no model the agent asked for until one fails +const GUIDE_TEMPLATES = ["steady", "thrifty", "smart"]; +const GUIDE_TEMPLATE_NAMES = { smart: "Hard to strong, easy to cheap", thrifty: "Cheap first", steady: "Never stuck" }; +const GUIDE_TEMPLATE_SAYS = { + smart: "A hard task goes to the strongest model, an easy one and compaction to a cheap one", + thrifty: "A cheap model first; the strongest for high reasoning, or when the cheap ones fail", + steady: "The strongest model of each provider, each behind the other: one down doesn't stop the agent", +}; +const GUIDE_X = "M4.5 4.5l7 7M11.5 4.5l-7 7"; +const GUIDE_CHIPS = 6; // agents named on the card; the rest are in the list under it +// guideGroups: /api/groups as the card last read it, and for which served +// count, read again when the models change or a group is added +let guideGroups = null, guideGroupsFor = null, guideGroupsBusy = false; +let guideBusy = ""; // what the card is doing: "hide", "template", an agent's id + +// guideShown: the steps' state when the card is to be shown, else null +function guideShown() { + if (gatewayMode || !state || state.settings?.guideHidden) return null; + const source = (state.served || 0) > 0 || anyMagpieModels(); + const agent = state.agents.some((a) => a.wired); + if (source && agent) return null; + const own = guideGroups?.groups?.filter((x) => !x.auto) || []; + return { source, agent, routing: own.length > 0, own }; +} + +function guideStep(n, done, title, say) { + const li = el("li", "guide-step" + (done ? " done" : "")); + const tick = el("span", "guide-tick"); + tick.setAttribute("aria-hidden", "true"); + if (done) tick.append(svg(CHECK, 12, 2)); + else tick.textContent = String(n); + const body = el("div", "guide-body"); + const h = el("b", "guide-title", title); + body.append(h); + if (say) body.append(el("span", "guide-say", say)); + li.append(tick, body); + li.setAttribute("aria-label", (done ? t("Done") + ": " : "") + title); + return { li, body }; +} + +function guideCard(g) { + const card = el("section", "guide"); + card.setAttribute("aria-label", t("Get started")); + const head = el("div", "guide-head"); + const steps = [g.source, g.agent]; + head.append(el("b", "guide-h", t("Get started")), el("span", "guide-n", t("{n} of {m} done", { n: steps.filter(Boolean).length, m: steps.length }))); + const x = el("button", "guide-x"); + x.type = "button"; + x.title = t("Hide Get started"); + x.setAttribute("aria-label", x.title); + x.append(svg(GUIDE_X, 12, 1.6)); + x.disabled = guideBusy === "hide"; + x.onclick = (e) => { e.stopPropagation(); hideGuide(); }; + head.append(x); + card.append(head); + const list = el("ol", "guide-steps"); + + // 1: a model source + const one = guideStep(1, g.source, t("Add a model source"), + g.source ? t("{n} models ready to use", { n: state.served || 0 }) : t("A subscription you already pay for, a provider, or an API key")); + one.li.dataset.step = "source"; + if (!g.source) { + const add = el("button", "text primary guide-go", t("Add a provider")); + add.type = "button"; + add.onclick = (e) => { + e.stopPropagation(); + if (mode === "window") addProviderFromAgents(); + else api("window/main?view=providers", {}).catch((err) => status(err.message, "err")); + }; + one.body.append(add); + } + list.append(one.li); + + // 2: an agent, those found here named, each connected in a click + const found = state.agents.filter((a) => connectKind(a) === "ok" || connectKind(a) === "empty"); + const two = guideStep(2, g.agent, t("Connect an agent"), + g.agent ? "" : found.length ? t("magpie found these on this computer. Click one to connect it:") : t("Install Claude Code, Codex, Gemini CLI, OpenCode… and magpie will list them here.")); + two.li.dataset.step = "agent"; + if (!g.agent && found.length) { + const chips = el("div", "guide-agents"); + for (const a of found.slice(0, GUIDE_CHIPS)) { + const b = el("button", "guide-agent"); + b.type = "button"; + b.dataset.id = a.id; + b.append(icon(a.icon), el("span", "", a.name)); + const ready = connectKind(a) === "ok"; + b.disabled = !ready || !!guideBusy; + b.classList.toggle("busy", guideBusy === a.id); + b.title = ready ? t("Switch on and {agent}'s model list gets magpie's models", { agent: a.name }) : t("Add a key or a subscription first; then there are models to connect"); + b.onclick = (e) => { e.stopPropagation(); guideConnect(a); }; + chips.append(b); + } + if (found.length > GUIDE_CHIPS) chips.append(el("span", "guide-more", t("+{n} more below", { n: found.length - GUIDE_CHIPS }))); + two.body.append(chips); + } + list.append(two.li); + + // 3, optional: a routing group of the user's own models + const three = guideStep(3, g.routing, t("Set up routing (optional)"), + g.routing ? g.own.map((x) => x.name || x.id).join(", ") : t("A routing group sends each request to the right model, and to the next one when a model fails")); + three.li.dataset.step = "routing"; + three.li.classList.add("optional"); + if (!g.routing && g.source) { + guideLoadGroups(); + const acts = el("div", "guide-acts"); + const tp = GUIDE_TEMPLATES.map((k) => guideGroups?.templates?.find((x) => x.kind === k && !x.need && x.group?.members?.length)).find(Boolean); + if (tp) { + const name = t(GUIDE_TEMPLATE_NAMES[tp.kind] || tp.group.name); + const add = el("button", "text primary guide-go guide-tpl", t("Add “{name}”", { name })); + add.type = "button"; + add.dataset.kind = tp.kind; + add.title = t(GUIDE_TEMPLATE_SAYS[tp.kind] || "") + "\n" + tp.group.members.join(" → "); + add.disabled = !!guideBusy; + add.onclick = (e) => { e.stopPropagation(); guideTemplate(tp, name); }; + acts.append(add); + } + const open = el("button", "text guide-open", t("Open Routing")); + open.type = "button"; + open.onclick = (e) => { + e.stopPropagation(); + if (mode === "window") show("routing"); + else api("window/main?view=routing", {}).catch((err) => status(err.message, "err")); + }; + acts.append(open); + three.body.append(acts); + if (tp) three.body.append(el("span", "guide-say guide-tpl-say", t(GUIDE_TEMPLATE_SAYS[tp.kind] || ""))); + } + list.append(three.li); + card.append(list); + return card; +} + +// guideLoadGroups reads the groups and templates for step 3, once for +// each count of models served, and draws the card again with them +function guideLoadGroups(again) { + const key = String(state.served || 0); + if (guideGroupsBusy || (!again && guideGroupsFor === key)) return; + guideGroupsBusy = true; + guideGroupsFor = key; + api("groups").then((gs) => { guideGroups = gs; }, () => { /* the step links to Routing still */ }) + .finally(() => { guideGroupsBusy = false; if (view === "agents" || mode === "panel") guideRedraw(); }); +} + +// guideRedraw draws the lead again, and the panel to its height +function guideRedraw() { + const list = $("#agents"); + if (!list || !state) return; + agentsLead(list); + fit(); +} + +async function guideConnect(a) { + if (guideBusy) return; + guideBusy = a.id; + guideRedraw(); + try { + state = await api("agents/connect/" + a.id, {}); + guideBusy = ""; + renderAgents(); + const msg = connectedSaid(a, state.connected); + if (state.notice) status(withNotice(msg, state.notice), "warn", 9000); + else status(msg, "ok", 7000); + } catch (err) { + guideBusy = ""; + guideRedraw(); + status(t(err.message), "err"); + } +} + +async function guideTemplate(tp, name) { + if (guideBusy) return; + guideBusy = "template"; + guideRedraw(); + try { + guideGroups = await api("groups/template", { kind: tp.kind, name }); + guideBusy = ""; + status(t("Added {name}", { name }), "ok"); + // the agents' pickers list the new group + state = await api("state"); + renderAgents(); + } catch (err) { + guideBusy = ""; + guideRedraw(); + status(t(err.message), "err"); + } +} + +async function hideGuide() { + if (guideBusy) return; + guideBusy = "hide"; + guideRedraw(); + try { + prefs = await writingPrefs(api("settings/guide", { hidden: true })); + state.settings = prefs; + guideBusy = ""; + renderAgents(); + } catch (err) { + guideBusy = ""; + guideRedraw(); + status(t(err.message), "err"); + } +} + async function addProviderFromAgents() { if (!await show("providers")) return; - $("#addProvider")?.click(); + // the list not read yet (the page's first opening): clicked before it is + // in, the button drew a list of nothing and threw; read, an empty list + // opens the sheet itself + if (!providers) { try { await loadProviders(); } catch { return; } } + if (!adding) $("#addProvider")?.click(); } // desktopLongestLine: Claude Desktop lists a model of 1M or more twice, the diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 052bbfd4e..f451891bd 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -4,6 +4,18 @@ // works. {name} slots are filled by t(str, vars). const I18N = { zh: { + "Get started": "快速上手", + "{n} of {m} done": "已完成 {n}/{m}", + "Hide Get started": "隐藏快速上手", + "Add a model source": "添加模型来源", + "{n} models ready to use": "已有 {n} 个模型可用", + "A subscription you already pay for, a provider, or an API key": "你已经付费的订阅、一个供应商,或一个 API 密钥", + "Connect an agent": "接入一个 agent", + "magpie found these on this computer. Click one to connect it:": "magpie 在这台电脑上找到了这些,点一下即可接入:", + "+{n} more below": "下方还有 {n} 个", + "Set up routing (optional)": "设置路由(可选)", + "A routing group sends each request to the right model, and to the next one when a model fails": "路由组把每个请求发给合适的模型,一个模型出错时交给下一个", + "Add “{name}”": "添加「{name}」", "account": "账号", "active in Aside": "Aside 正在使用", "the account active in {agent}": "{agent} 当前使用的账号", @@ -4372,6 +4384,18 @@ const I18N = { "~/.dsh/settings.yaml sets its own DeepSeek endpoint or key, which dsh puts over magpie's; clear it in dsh's Models page to go through magpie.": "~/.dsh/settings.yaml 设置了自己的 DeepSeek 地址或 Key,dsh 会优先用它而不是 magpie 的;请在 dsh 的 Models 页面清除它,才能走 magpie。", }, "zh-TW": { + "Get started": "快速上手", + "{n} of {m} done": "已完成 {n}/{m}", + "Hide Get started": "隱藏快速上手", + "Add a model source": "新增模型來源", + "{n} models ready to use": "已有 {n} 個模型可用", + "A subscription you already pay for, a provider, or an API key": "你已經付費的訂閱、一個供應商,或一個 API 金鑰", + "Connect an agent": "接入一個 agent", + "magpie found these on this computer. Click one to connect it:": "magpie 在這台電腦上找到了這些,點一下即可接入:", + "+{n} more below": "下方還有 {n} 個", + "Set up routing (optional)": "設定路由(選用)", + "A routing group sends each request to the right model, and to the next one when a model fails": "路由組把每個請求送給合適的模型,一個模型出錯時交給下一個", + "Add “{name}”": "新增「{name}」", "account": "帳號", "active in Aside": "Aside 正在使用", "the account active in {agent}": "{agent} 目前使用的帳號", @@ -8723,6 +8747,18 @@ const I18N = { "~/.dsh/settings.yaml sets its own DeepSeek endpoint or key, which dsh puts over magpie's; clear it in dsh's Models page to go through magpie.": "~/.dsh/settings.yaml 設定了自己的 DeepSeek 位址或 Key,dsh 會優先用它而不是 magpie 的;請在 dsh 的 Models 頁面清除它,才能走 magpie。", }, ja: { + "Get started": "はじめに", + "{n} of {m} done": "{m} 件中 {n} 件完了", + "Hide Get started": "「はじめに」を隠す", + "Add a model source": "モデルの提供元を追加", + "{n} models ready to use": "{n} 個のモデルが使えます", + "A subscription you already pay for, a provider, or an API key": "契約済みのサブスクリプション、プロバイダ、または API キー", + "Connect an agent": "エージェントを接続", + "magpie found these on this computer. Click one to connect it:": "magpie がこのコンピュータで見つけたものです。クリックすると接続します:", + "+{n} more below": "ほか {n} 件は下に", + "Set up routing (optional)": "ルーティングを設定(任意)", + "A routing group sends each request to the right model, and to the next one when a model fails": "ルーティンググループは各リクエストを適したモデルに送り、モデルが失敗したら次のモデルに回します", + "Add “{name}”": "「{name}」を追加", "account": "アカウント", "active in Aside": "Aside で使用中", "the account active in {agent}": "{agent} で使用中のアカウント", @@ -13076,6 +13112,18 @@ const I18N = { "~/.dsh/settings.yaml sets its own DeepSeek endpoint or key, which dsh puts over magpie's; clear it in dsh's Models page to go through magpie.": "~/.dsh/settings.yaml に独自の DeepSeek エンドポイントやキーがあり、dsh は magpie のものよりそちらを優先します。magpie を経由するには dsh の Models ページで消してください。", }, de: { + "Get started": "Erste Schritte", + "{n} of {m} done": "{n} von {m} erledigt", + "Hide Get started": "Erste Schritte ausblenden", + "Add a model source": "Eine Modellquelle hinzufügen", + "{n} models ready to use": "{n} Modelle einsatzbereit", + "A subscription you already pay for, a provider, or an API key": "Ein Abo, das Sie schon bezahlen, ein Anbieter oder ein API-Schlüssel", + "Connect an agent": "Einen Agenten verbinden", + "magpie found these on this computer. Click one to connect it:": "magpie hat diese auf diesem Computer gefunden. Klicken Sie einen an, um ihn zu verbinden:", + "+{n} more below": "{n} weitere unten", + "Set up routing (optional)": "Weiterleitung einrichten (optional)", + "A routing group sends each request to the right model, and to the next one when a model fails": "Eine Weiterleitungsgruppe schickt jede Anfrage an das passende Modell und an das nächste, wenn eines ausfällt", + "Add “{name}”": "„{name}“ hinzufügen", "account": "Konto", "active in Aside": "in Aside aktiv", "the account active in {agent}": "das in {agent} aktive Konto", diff --git a/internal/gui/settings_keep_test.go b/internal/gui/settings_keep_test.go index 789f00485..d5ccb22d7 100644 --- a/internal/gui/settings_keep_test.go +++ b/internal/gui/settings_keep_test.go @@ -159,6 +159,7 @@ func TestSettingsSaveKeepsWhatItDoesNotSend(t *testing.T) { WindowMaximised: true, FullContext: true, DesktopLongest: true, + GuideHidden: true, GatewayMode: "off", QuotaReads: "asked", NoAccountDiscovery: true, diff --git a/internal/gui/tests/agent-grip.test.cjs b/internal/gui/tests/agent-grip.test.cjs index af841b934..6c42e3ad1 100644 --- a/internal/gui/tests/agent-grip.test.cjs +++ b/internal/gui/tests/agent-grip.test.cjs @@ -21,7 +21,7 @@ const { chromium, webkit } = require("playwright"); const assets = path.resolve(__dirname, "../assets"); function fixture(lang) { - const state = { agents: ["alpha", "beta", "gamma"].map((id) => ({ id, name: id, icon: "generic", path: "/fixture/" + id, fields: [] })), profiles: [], settings: { lang, theme: "light" } }; + const state = { agents: ["alpha", "beta", "gamma"].map((id) => ({ id, name: id, icon: "generic", path: "/fixture/" + id, fields: [] })), profiles: [], settings: { lang, theme: "light", guideHidden: true } }; // the Get started card put away: these rows are the page, the test reads where they sit const posted = []; const route = async (route) => { const request = route.request(), url = new URL(request.url()); diff --git a/internal/gui/tests/cursor-local-effort.test.cjs b/internal/gui/tests/cursor-local-effort.test.cjs index 10c1fda03..c66a3831e 100644 --- a/internal/gui/tests/cursor-local-effort.test.cjs +++ b/internal/gui/tests/cursor-local-effort.test.cjs @@ -29,7 +29,7 @@ const filler = Array.from({ length: 6 }, (_, i) => ({ id: "pi" + i, name: "Pi " function serve(lang, sets) { let effort = ""; - const st = () => ({ agents: [cursorLocal(effort), ...filler], profiles: [], settings: { lang, theme: "light" } }); + const st = () => ({ agents: [cursorLocal(effort), ...filler], profiles: [], settings: { lang, theme: "light", guideHidden: true } }); // Get started put away: the row is read where it sits return async (route) => { const req = route.request(), url = new URL(req.url()); if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` }); diff --git a/internal/gui/tests/fold-show-grip.test.cjs b/internal/gui/tests/fold-show-grip.test.cjs index b4a0c0e12..d23283067 100644 --- a/internal/gui/tests/fold-show-grip.test.cjs +++ b/internal/gui/tests/fold-show-grip.test.cjs @@ -21,7 +21,9 @@ const quotas = [ ]; function server(lang) { - const settings = { lang, theme: "dark", agentsHidden: ["idle"] }; + // the Get started card put away: the rows are the page, and the fold opened + // takes the view down with it once the page is taller than the window + const settings = { lang, theme: "dark", agentsHidden: ["idle"], guideHidden: true }; return async (route) => { const url = new URL(route.request().url()); const json = (data) => route.fulfill({ json: data }); diff --git a/internal/gui/tests/getting-started.test.cjs b/internal/gui/tests/getting-started.test.cjs new file mode 100644 index 000000000..485452dc8 --- /dev/null +++ b/internal/gui/tests/getting-started.test.cjs @@ -0,0 +1,218 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// wangye1644294 on X: magpie isn't friendly to a first-time user; a guide, +// routing set up in a click and the agents found here, please. A new user's +// Agents page (the window's first page, and the panel's first tab) has a Get +// started card: add a model source, connect an agent (those found here, each +// connected in a click), and, optionally, a routing group made of their own +// models in a click. Each step is ticked from the state the server gives, +// never from having been seen; the card goes once the first two are done, +// and put away it stays away, kept in the settings, not the page's storage. +// Both engines, a wide and a narrow window and the panel, every language. +// 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 assets = path.resolve(__dirname, "../assets"); +const shots = process.env.ARTIFACT_DIR; + +// world is what the fake server knows, changed by the page's writes +function newWorld() { + return { served: 0, wired: false, hidden: false, groups: [] }; +} + +function agents(w) { + // with no model served, the agents' pickers have none of magpie's + const mine = w.served ? [{ value: "relay/m1", label: "m1", ref: "relay/m1", note: "Relay · via magpie" }] : []; + const field = (value, own) => [{ key: "model", label: "model", value, options: [...own, ...mine] }]; + return [ + { id: "codex", name: "Codex", icon: "generic", path: "/fixture/codex", wired: w.wired, fields: field(w.wired ? "relay/m1" : "", [{ value: "gpt-5.4", label: "GPT-5.4" }]) }, + { id: "claude", name: "Claude Code", icon: "generic", path: "/fixture/claude", fields: field("", [{ value: "sonnet", label: "Sonnet" }]) }, + { id: "opencode", name: "OpenCode", icon: "generic", path: "/fixture/opencode", fields: field("", []) }, + // never connectable: not offered on the card + { id: "cursor", name: "Cursor", icon: "generic", path: "/fixture/cursor", fields: [] }, + ]; +} + +const templates = [ + { kind: "smart", group: { id: "smart-split", name: "Hard to strong, easy to cheap", members: ["relay/m1", "other/m2"] } }, + { kind: "thrifty", need: "cheap", of: "m1", group: { id: "cheap-first", name: "Cheap first", members: [] } }, + { kind: "steady", group: { id: "never-stuck", name: "Never stuck", members: ["relay/m1", "other/m2"] } }, +]; + +function server(lang, w, posts) { + const settings = () => ({ lang, theme: "light", guideHidden: w.hidden || undefined }); + const state = () => ({ agents: agents(w), profiles: [], served: w.served, settings: settings() }); + const groups = () => ({ groups: w.groups, models: [], pools: [], deciders: [], templates }); + return async (route) => { + const req = route.request(), url = new URL(req.url()); + const json = (data, status = 200) => route.fulfill({ status, json: data }); + if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` }); + if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (req.method() === "POST") posts.push(url.pathname + url.search); + if (url.pathname === "/api/state") return json(state()); + if (url.pathname === "/api/settings/guide") { + w.hidden = !!req.postDataJSON().hidden; + return json(settings()); + } + if (url.pathname === "/api/agents/connect/codex") { + w.wired = true; + return json(state()); + } + if (url.pathname === "/api/groups/template") { + const { kind, name } = req.postDataJSON(); + const tp = templates.find((x) => x.kind === kind); + w.groups.push({ ...tp.group, name }); + return json(groups()); + } + if (url.pathname === "/api/groups") return json(groups()); + if (url.pathname === "/api/usage/quotas") return json([]); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/agents/cli") return json({ agents: {}, pending: false }); + if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } }); + if (url.pathname.startsWith("/api/")) return json({}); + 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)]; + try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); } + }; +} + +const LAYOUTS = [ + { name: "window", url: "/?view=agents", viewport: { width: 1100, height: 760 } }, + { name: "narrow", url: "/?view=agents", viewport: { width: 420, height: 760 } }, + { name: "panel", url: "/?mode=panel", viewport: { width: 400, height: 640 } }, +]; +const LANGS = ["en", "zh", "zh-TW", "ja", "de"]; +const STRINGS = ["Get started", "Add a model source", "Connect an agent", "Set up routing (optional)", "Hide Get started", + "A subscription you already pay for, a provider, or an API key", "magpie found these on this computer. Click one to connect it:", + "A routing group sends each request to the right model, and to the next one when a model fails", "+{n} more below", "{n} of {m} done", "{n} models ready to use", "Add “{name}”"]; + +async function open(browser, layout, lang, w, posts) { + const context = await browser.newContext({ viewport: layout.viewport, reducedMotion: "reduce" }); + await context.addInitScript(() => { try { localStorage.setItem("magpie.panelTab", "agents"); } catch {} }); + const page = await context.newPage(); + page.setDefaultTimeout(5000); + page.errors = []; + page.on("pageerror", (e) => page.errors.push(e.message)); + await page.route("**/*", server(lang, w, posts)); + await page.goto("http://magpie.test" + layout.url); + await page.locator(".row.agent").first().waitFor(); + return { context, page }; +} + +const stepDone = (page, step) => page.locator(`.guide-step[data-step="${step}"]`).evaluate((e) => e.classList.contains("done")); +const tops = (page) => page.evaluate(() => [document.scrollingElement.scrollTop, document.querySelector("#view-agents")?.scrollTop]); +const sideways = (page) => page.evaluate(() => { + const v = document.querySelector("#view-agents"), g = document.querySelector(".guide"); + return v.scrollWidth > v.clientWidth + 1 || document.scrollingElement.scrollWidth > innerWidth + || (g && [...g.querySelectorAll("*")].some((e) => e.getBoundingClientRect().right > g.getBoundingClientRect().right + 1)); +}); + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of LANGS) { + for (const layout of LAYOUTS) { + test(`${engine} ${lang} ${layout.name}: Get started ticks from state, connects in a click and goes once done`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + const w = newWorld(), posts = []; + const { page } = await open(browser, layout, lang, w, posts); + const tr = (s, v) => page.evaluate(([s, v]) => t(s, v), [s, v]); + if (lang !== "en") { + for (const s of STRINGS) assert.notEqual(await tr(s), s, `${lang} has "${s}"`); + } + + // a new user: nothing served, nothing wired + const card = page.locator("#agentsLead .guide"); + await card.waitFor(); + assert.equal((await page.locator(".guide-h").textContent()), await tr("Get started")); + assert.equal(await stepDone(page, "source"), false); + assert.equal(await stepDone(page, "agent"), false); + assert.equal(await page.locator(".guide-n").textContent(), await tr("{n} of {m} done", { n: 0, m: 2 })); + // the agents found here are named, Cursor (never connectable) not; + // with no models yet they can't be connected + assert.deepEqual(await page.locator(".guide-agent").evaluateAll((bs) => bs.map((b) => b.dataset.id)), ["codex", "claude", "opencode"]); + assert.ok(await page.locator(".guide-agent").evaluateAll((bs) => bs.every((b) => b.disabled))); + // routing waits for a model source: no button yet + assert.equal(await page.locator(".guide-tpl").count(), 0); + assert.equal(await sideways(page), false, "nothing runs off sideways"); + if (shots && (lang === "en" || lang === "zh")) await page.screenshot({ path: path.join(shots, `getting-started-${engine}-${lang}-${layout.name}-new.png`) }); + + // the first step's button: the window opens the add sheet, the + // panel the window on Providers + const top = await tops(page); + await page.locator('.guide-step[data-step="source"] .guide-go').click(); + if (layout.name === "panel") { + for (let i = 0; i < 50 && !posts.includes("/api/window/main?view=providers"); i++) await page.waitForTimeout(20); + assert.ok(posts.includes("/api/window/main?view=providers"), posts.join(" ")); + } else { + await page.locator("#view-providers").waitFor({ state: "visible" }); + await page.locator("#addSheet").waitFor({ state: "visible" }); + } + + // a provider added: the step is ticked from the state, the agents can + // be connected, and a routing group is a click away + w.served = 12; + await page.goto("http://magpie.test" + layout.url); + await card.waitFor(); + assert.equal(await stepDone(page, "source"), true); + assert.match(await page.locator('.guide-step[data-step="source"] .guide-say').textContent(), /12/); + assert.equal(await page.locator(".guide-n").textContent(), await tr("{n} of {m} done", { n: 1, m: 2 })); + const codex = page.locator('.guide-agent[data-id="codex"]'); + assert.equal(await codex.isDisabled(), false); + const tpl = page.locator(".guide-tpl"); + await tpl.waitFor(); + assert.equal(await tpl.getAttribute("data-kind"), "steady", "the harmless template first; the one that can't be made isn't offered"); + const name = await tr("Never stuck"); + assert.equal(await tpl.textContent(), await tr("Add “{name}”", { name })); + if (shots && (lang === "en" || lang === "zh")) await page.screenshot({ path: path.join(shots, `getting-started-${engine}-${lang}-${layout.name}-source.png`) }); + + const before = await tops(page); + await tpl.click(); + await page.locator('.guide-step[data-step="routing"].done').waitFor(); + assert.ok(posts.includes("/api/groups/template")); + assert.equal(w.groups[0].name, name, "saved under the name shown"); + assert.match(await page.locator('.guide-step[data-step="routing"] .guide-say').textContent(), new RegExp(name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))); + + // one click connects Codex, and with both steps done the card goes + await codex.click(); + await card.waitFor({ state: "detached" }); + assert.ok(posts.includes("/api/agents/connect/codex")); + assert.deepEqual(await tops(page), before, "no click moved the page"); + assert.equal(top[0], before[0]); + + // done stays done: a reload brings no card back + await page.goto("http://magpie.test" + layout.url); + await page.locator(".row.agent").first().waitFor(); + assert.equal(await page.locator(".guide").count(), 0); + assert.deepEqual(page.errors, []); + }); + + test(`${engine} ${lang} ${layout.name}: Get started put away stays away, in the settings`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + const w = newWorld(), posts = []; + const first = await open(browser, layout, lang, w, posts); + const page = first.page; + await page.locator("#agentsLead .guide").waitFor(); + const top = await tops(page); + await page.locator(".guide-x").click(); + await page.locator(".guide").waitFor({ state: "detached" }); + assert.ok(posts.includes("/api/settings/guide")); + assert.equal(w.hidden, true); + assert.deepEqual(await tops(page), top, "no click moved the page"); + assert.deepEqual(page.errors, []); + await first.context.close(); + + // a fresh browser storage (the other window, a reinstall's webview): + // still away, though no step is done + const again = await open(browser, layout, lang, w, posts); + await again.page.waitForTimeout(150); + assert.equal(await again.page.locator(".guide").count(), 0); + assert.equal(await again.page.evaluate(() => { try { return Object.keys(localStorage).filter((k) => /guide/i.test(k)).length; } catch { return 0; } }), 0, "nothing kept in localStorage"); + assert.deepEqual(again.page.errors, []); + }); + } + } +} diff --git a/internal/gui/tests/panel-fold.test.cjs b/internal/gui/tests/panel-fold.test.cjs index 66c1dafe5..7cbcf4fe7 100644 --- a/internal/gui/tests/panel-fold.test.cjs +++ b/internal/gui/tests/panel-fold.test.cjs @@ -21,7 +21,8 @@ const agent = (id, used) => ({ }); const state = { agents: [...Array.from({ length: 10 }, (_, i) => agent("agent-" + i, true)), agent("codex", true), agent("unset-1", false), agent("unset-2", false)], - profiles: [], settings: { lang: "en", theme: "light" }, + // Get started put away: the list and its scroll are what is measured + profiles: [], settings: { lang: "en", theme: "light", guideHidden: true }, }; async function serve(route) { diff --git a/internal/gui/tests/profile-details.test.cjs b/internal/gui/tests/profile-details.test.cjs index db60879ed..1d4997031 100644 --- a/internal/gui/tests/profile-details.test.cjs +++ b/internal/gui/tests/profile-details.test.cjs @@ -47,7 +47,8 @@ function server(lang, calls, count) { const profiles = [...Array.from({ length: count }, (_, i) => filler(i)), work, filler(99)]; return async (route) => { const req = route.request(), url = new URL(req.url()); - const state = () => ({ agents: [agent("codex", "Codex"), agent("claude", "Claude Code")], profiles, settings: { lang, theme: "light" } }); + // Get started put away: the profiles strip is what is read, where it sits + const state = () => ({ agents: [agent("codex", "Codex"), agent("claude", "Claude Code")], profiles, settings: { lang, theme: "light", guideHidden: true } }); if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` }); if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); if (url.pathname === "/api/state") return route.fulfill({ json: state() }); diff --git a/internal/settings/settings.go b/internal/settings/settings.go index 03abd13f7..d2d0840f1 100644 --- a/internal/settings/settings.go +++ b/internal/settings/settings.go @@ -364,6 +364,10 @@ type Settings struct { // "[1m]", and adds none to one whose id has it. Off, as before, it shows // both, the plain one compacting at Claude Code's 200K. DesktopLongest bool `json:"desktopLongest,omitempty"` + // GuideHidden: the user put away the Agents page's Get started card + // (wangye1644294 on X) before finishing it. Kept here, not in the + // page's storage, so the panel, the window and a reload agree. + GuideHidden bool `json:"guideHidden,omitempty"` // CompactAt is the window told for a longer one when FullContext is // off, in tokens: 0 is WorkingWindow (#876: 272K was the only one). // A provider's or a model's own (ModelCompacts) comes before it.