diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md index 30755dd72..f8a7658f7 100644 --- a/docs/subsystems/gui-shell.md +++ b/docs/subsystems/gui-shell.md @@ -155,6 +155,7 @@ retry after a failed read. See `TestRecentCallBodiesOnDemand` and - The Usage page's cards and the tray panel's Allowances tab share one order, `settings.UsageOrder` (`byUsageOrder`). In the panel a balance-only card stands where that order puts it, and balances next to each other share one *Balances* grid (`panelBalances`, #1510); none is gathered after the plans. The panel's *Arrange* (`panelArrange`) moves rows in it and hides subscriptions from that tab alone (`settings.PanelUsageHidden`); both save through `POST /api/usage/arrange`, which changes only the field it is sent, and the Settings save keeps both. Hiding is display only: a menu bar cell's card shows though hidden (`panelPeek`). See `TestUsageArrangePanelHidden`, `panel-arrange.test.cjs` and `panel-balance-order.test.cjs`. - 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 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 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`. - 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). - Wails calls the tray's click handler both for the icon's click (`Activate`) and when the tray host opens the icon's menu (dbusmenu's "opened" event). KDE opens the menu on a right-click, and the panel that click opened took the focus and shut the menu on Wayland. On Linux the handler ignores the call when it comes from the menu opening (`menuOpening` in [`trayclick.go`](../../internal/gui/trayclick.go), which looks for Wails' `(*linuxSystemTray).Event` among its callers; `TestTrayMenuOpenFrameIsWails` fails if Wails renames it or stops calling the handler there) (#1430). diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index 5ee6f8163..43c008d7a 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -1810,6 +1810,14 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; } /* providers switched off, folded below the ones on */ #view-providers .off-head { margin: 14px 0 6px; padding: 0 2px; flex: none; } #view-providers .off-head .note { font-size: 11px; color: var(--faint); } +/* Providers' search (#1614): a toolbar field over the list, at its right + edge as Settings' is; across the page when the window is narrow. While + searching, the Turned off fold stays open on the ones that match. */ +#view-providers .pv-head { display: flex; justify-content: flex-end; margin: 0 0 10px; flex: none; } +#view-providers .pv-q { flex: 0 1 220px; min-width: 120px; } +#view-providers .pv-none { margin: 18px 2px; } +#view-providers .off-head .fold:disabled { cursor: default; opacity: 1; } +@media (max-width: 520px) { #view-providers .pv-q { flex: 1 1 100%; } } /* the Models head folds the list away: a chevron, the label, how many */ .fold { display: inline-flex; align-items: center; gap: 5px; margin-left: -4px; padding: 3px 6px 3px 4px; border-radius: 6px; color: var(--faint); transition: background .12s, color .12s; } .fold:hover { background: var(--pill); color: var(--muted); } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 5d582a45c..0025501f8 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -2156,8 +2156,11 @@ function setAgentHidden(a, hide) { } const ALT = /^Mac/.test(navigator.platform) ? "⌥" : "Alt+"; +const SHIFT = /^Mac/.test(navigator.platform) ? "⇧" : "Shift+"; // the arrows of a row menu's Move up and Move down (agents, routing groups) const MOVE_UP = "M8 12.5v-9M4 7.25l4-3.75 4 3.75", MOVE_DOWN = "M8 3.5v9M4 8.75l4 3.75 4-3.75"; +// Move to Top and Move to Bottom: the arrow to a bar (a provider row's menu) +const MOVE_TOP = "M8 13v-7.5M4.5 9l3.5-3.5 3.5 3.5M3.5 2.75h9", MOVE_BOTTOM = "M8 3v7.5M4.5 7l3.5 3.5 3.5-3.5M3.5 13.25h9"; const EYE_OFF = "M6.6 3.7A6.9 6.9 0 0 1 8 3.5c3.75 0 6.25 4.5 6.25 4.5a11 11 0 0 1-1.5 2M4.4 4.4C2.7 5.55 1.75 8 1.75 8S4.25 12.5 8 12.5c1.2 0 2.25-.45 3.1-1.05M6.75 6.75a1.75 1.75 0 0 0 2.5 2.5M2 2l12 12"; const EYE = "M1.75 8S4.25 3.5 8 3.5 14.25 8 14.25 8 11.75 12.5 8 12.5 1.75 8 1.75 8ZM8 9.75a1.75 1.75 0 1 0 0-3.5 1.75 1.75 0 0 0 0 3.5Z"; @@ -5068,6 +5071,8 @@ function renderProviders() { // a provider on is listed, and tried, in the order the user puts it in // (#499): its logo is the handle, as an agent row's is row.append(p.off ? icon(p.icon || "generic") : providerHandle(p, row), who, uses, key, providerSwitch(p), chev); + // right-click: Move to Top, Move Up, Move Down, Move to Bottom (#1614) + if (!p.off) row.oncontextmenu = (ev) => { ev.preventDefault(); openProviderMenu(row.querySelector(".pv-handle"), p); }; row.onclick = async () => { if (providerDirty() && !(await confirmDiscard())) return; editing = open ? null : p.id; draft = null; renderProviders(); @@ -5075,6 +5080,7 @@ function renderProviders() { list.append(row); if (open) dialog = renderEditor(p); } + findProviders(); renderExcluded(); renderFileError(); renderMovable(); @@ -5099,22 +5105,27 @@ function providerHandle(p, row) { const b = el("button", "ag-handle pv-handle"); b.type = "button"; b.setAttribute("aria-label", t("Arrange {agent}", { agent: p.name })); - b.title = t("Drag to reorder — a model several providers serve goes to the higher one first · Alt+↑/↓ to move"); + b.title = t("Drag to reorder — a model several providers serve goes to the higher one first · Alt+↑/↓ to move") + " · " + t("right-click to move it to the top or the bottom"); b.append(icon(p.icon || "generic")); b.onkeydown = (e) => { if (!e.altKey || (e.key !== "ArrowUp" && e.key !== "ArrowDown")) return; e.preventDefault(); e.stopPropagation(); - const ids = providers.providers.filter((x) => !x.off).map((x) => x.id); - arrangeProvider(p.id, ids.indexOf(p.id) + (e.key === "ArrowUp" ? -1 : 1), true); + const up = e.key === "ArrowUp"; + // Alt+Shift+↑/↓: all the way to the top or the bottom + if (e.shiftKey) arrangeProvider(p.id, up ? 0 : onProviderIds().length - 1, true); + else stepProvider(p.id, up ? -1 : 1, true); }; // the click that ends a drag doesn't open the row b.addEventListener("click", (e) => { if (b.dataset.dragged) { e.stopPropagation(); e.preventDefault(); } }); b.onpointerdown = (e) => { if (providerArranging) return; const list = $("#providers"); - providerArranging = dragRows(e, b, row, list, [...list.children].filter((r) => r.classList.contains("provider")), - (to) => arrangeProvider(p.id, to), closeProtoMenu, () => { + // while a search hides some, the row moves among the ones shown: it + // takes the place of the one it is dropped on (shownToOn) + const rows = [...list.children].filter((r) => r.classList.contains("provider") && !r.hidden); + providerArranging = dragRows(e, b, row, list, rows, + (to) => arrangeProvider(p.id, shownToOn(rows[to]?.dataset.id)), () => { closeProtoMenu(); closeAgentMenu(); }, () => { providerArranging = false; if (accountRenderPending && !accountArranging) { accountRenderPending = false; renderProviders(); } }); @@ -5122,6 +5133,101 @@ function providerHandle(p, row) { return b; } +// The ids of the providers that are on, in their order, and of those a +// search shows. While searching, a provider moves among the ones shown: +// Alt+↑ puts it just above the one shown above it, a drop puts it where the +// row dropped on was; the ones hidden keep their order among themselves. +// Move to Top and Move to Bottom go to the top or the bottom of them all. +const onProviderIds = () => providers.providers.filter((x) => !x.off).map((x) => x.id); +const shownProviderIds = () => [...$("#providers").children].filter((r) => r.classList.contains("provider") && !r.hidden).map((r) => r.dataset.id); +const shownToOn = (id) => (id ? onProviderIds().indexOf(id) : -1); +function stepProvider(id, by, keyboard) { + const shown = shownProviderIds(), i = shown.indexOf(id); + if (i < 0 || i + by < 0 || i + by >= shown.length) return; + arrangeProvider(id, shownToOn(shown[i + by]), keyboard); +} + +// openProviderMenu: a provider row's right-click, the quick way through a +// long list (#1614): Move to Top and Move to Bottom beside one step up or +// down, each with its keys. +function openProviderMenu(anchor, p) { + if (!anchor) return; + const again = agentMenu?.anchor === anchor; + closeAgentMenu(); + if (again) return; + const on = onProviderIds(), shown = shownProviderIds(); + const i = on.indexOf(p.id), k = shown.indexOf(p.id); + if (i < 0) return; + openRowMenu(anchor, [ + { name: "Move to top", icon: MOVE_TOP, key: ALT + SHIFT + "↑", off: i === 0, run: () => arrangeProvider(p.id, 0) }, + { name: "Move up", icon: MOVE_UP, key: ALT + "↑", off: k <= 0, run: () => stepProvider(p.id, -1) }, + { name: "Move down", icon: MOVE_DOWN, key: ALT + "↓", off: k < 0 || k >= shown.length - 1, run: () => stepProvider(p.id, 1) }, + { name: "Move to bottom", icon: MOVE_BOTTOM, key: ALT + SHIFT + "↓", off: i === on.length - 1, run: () => arrangeProvider(p.id, on.length - 1) }, + ]); +} + +// Providers' search (#1614, ququdu: "供应商很多,然后经常需要翻找"): the +// words typed keep the rows that say them all, on and off alike, matched on +// the row's own text and on what it doesn't show: its id, preset, addresses, +// every model's id and name, each account's user and plan, and the keys' +// names. The ones turned off show unfolded while searching. Escape or +// clearing the box brings back every row, the fold as it was. +let pvQuery = ""; +function providerText(p, row) { + const a = p.account; + return [row.textContent, p.id, p.name, p.preset, p.host, p.chat, p.responses, p.anthropic, p.gemini, + ...(p.models || []).flatMap((m) => [m.id, m.name]), + a?.user, a?.agentName, a?.plan, ...(a?.logins || []).flatMap((l) => [l.user, l.plan]), + ...Object.values(p.accountNames || {}), ...(p.keyList || []).map((k) => k.name), + ].filter(Boolean).join(" ").toLowerCase(); +} +function findProviders() { + const view = $("#view-providers"), q = $("#pvQ"), none = $("#pvNone"); + q.setAttribute("aria-label", t("Find a provider")); + $("#pvHead").hidden = !providers.providers.length; + view.classList.toggle("pv-searching", !!pvQuery); + const words = pvQuery.split(/\s+/).filter(Boolean), byId = new Map(providers.providers.map((p) => [p.id, p])); + let on = 0, off = 0; + for (const row of view.querySelectorAll("#providers > .row.provider, #offProviders > .row.provider")) { + const p = byId.get(row.dataset.id); + const hit = !p || words.every((w) => providerText(p, row).includes(w)); + row.hidden = !hit; + if (hit) p?.off ? off++ : on++; + } + const offs = providers.providers.filter((p) => p.off).length; + // while searching, the ones off that match show, whatever the fold says + const fold = $("#foldOff"); + fold.disabled = !!pvQuery; + fold.setAttribute("aria-expanded", String(!!pvQuery || !offFolded)); + if (pvQuery) { + $("#providers").hidden = !on; + $("#offHead").hidden = !off; + $("#offProviders").hidden = !off; + $("#offCount").textContent = off ? String(off) : ""; + } else { + $("#providers").hidden = offs === providers.providers.length; + $("#offHead").hidden = !offs; + $("#offProviders").hidden = !offs || offFolded; + $("#offCount").textContent = offs ? String(offs) : ""; + } + none.hidden = !pvQuery || on + off > 0; + none.textContent = none.hidden ? "" : t("No provider matches “{q}”", { q: q.value.trim() }); +} +{ + const q = $("#pvQ"); + if (q) { + q.oninput = () => { pvQuery = q.value.trim().toLowerCase(); findProviders(); }; + q.onkeydown = (e) => { + if (e.key !== "Escape" || !q.value) return; + e.preventDefault(); + e.stopPropagation(); + q.value = ""; + pvQuery = ""; + findProviders(); + }; + } +} + // arrangeProvider puts the provider at index `to` among the ones on; the // ones switched off keep their places among the rest. The list is drawn in // its new order at once and put back if the save fails. @@ -5149,10 +5255,12 @@ async function arrangeProvider(id, to, keyboard) { } // a later move, made while this one was saved, has the last word if (seq !== providerArrangeSeq) return; - const held = document.activeElement === handle(); + // the handle the keyboard is on keeps it as the list is drawn again: this + // one's, or another's taken up while this one was saved + const a = document.activeElement, held = a?.matches?.("#providers .pv-handle") ? a.closest(".row.provider").dataset.id : null; providers = next; renderProviders(); - if (held) handle()?.focus({ preventScroll: true }); + if (held) $(`#providers .row.provider[data-id="${CSS.escape(held)}"] .pv-handle`)?.focus({ preventScroll: true }); } let providerArrangeSeq = 0; diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 20a978b9d..ca6be0f07 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -2454,6 +2454,11 @@ const I18N = { "Search sessions": "搜索会话", "Find a setting": "查找设置", "No setting matches “{q}”": "没有和“{q}”匹配的设置", + "Find a provider": "查找供应商", + "No provider matches “{q}”": "没有和“{q}”匹配的供应商", + "Move to top": "移到顶部", + "Move to bottom": "移到底部", + "right-click to move it to the top or the bottom": "右键可移到顶部或底部", "Resume": "继续", "Resume command": "继续会话的命令", "{name} takes magpie only from its environment · click to copy the command that starts it:": "{name} 只能从环境变量接入 magpie · 点击复制启动它的命令:", @@ -6744,6 +6749,11 @@ const I18N = { "Search sessions": "搜尋會話", "Find a setting": "尋找設定", "No setting matches “{q}”": "沒有和「{q}」匹配的設定", + "Find a provider": "尋找供應商", + "No provider matches “{q}”": "沒有和「{q}」匹配的供應商", + "Move to top": "移到頂部", + "Move to bottom": "移到底部", + "right-click to move it to the top or the bottom": "按右鍵可移到頂部或底部", "Resume": "繼續", "Resume command": "繼續會話的命令", "{name} takes magpie only from its environment · click to copy the command that starts it:": "{name} 只能從環境變數接入 magpie · 點選複製啟動它的命令:", @@ -11037,6 +11047,11 @@ const I18N = { "Search sessions": "セッションを検索", "Find a setting": "設定を検索", "No setting matches “{q}”": "「{q}」に一致する設定はありません", + "Find a provider": "プロバイダを検索", + "No provider matches “{q}”": "「{q}」に一致するプロバイダはありません", + "Move to top": "一番上へ移動", + "Move to bottom": "一番下へ移動", + "right-click to move it to the top or the bottom": "右クリックで一番上・一番下へ移動", "Resume": "再開", "Resume command": "再開コマンド", "{name} takes magpie only from its environment · click to copy the command that starts it:": "{name} は環境変数からのみ magpie を使います · クリックで起動コマンドをコピー:", @@ -15329,6 +15344,11 @@ const I18N = { "Search sessions": "Sitzungen durchsuchen", "Find a setting": "Einstellung suchen", "No setting matches “{q}”": "Keine Einstellung passt zu „{q}“", + "Find a provider": "Anbieter suchen", + "No provider matches “{q}”": "Kein Anbieter passt zu „{q}“", + "Move to top": "Ganz nach oben", + "Move to bottom": "Ganz nach unten", + "right-click to move it to the top or the bottom": "Rechtsklick, um ihn ganz nach oben oder unten zu verschieben", "Resume": "Fortsetzen", "Resume command": "Befehl zum Fortsetzen", "{name} takes magpie only from its environment · click to copy the command that starts it:": "{name} übernimmt magpie nur aus seiner Umgebung · klicken, um den Startbefehl zu kopieren:", diff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.html index 635b4222f..59a063717 100644 --- a/internal/gui/assets/index.html +++ b/internal/gui/assets/index.html @@ -87,6 +87,8 @@