gui: Providers has a search box, and a provider's right-click moves it to the top or the bottom (#1614, ququdu)
ququdu has many providers and kept scrolling to find one, and moving one
far up the list meant a long drag. The Providers page had neither a search
nor a quick move; its rows moved only by dragging the logo or Alt+↑/↓ one
step at a time.
- A search box over the list, at its right edge as Settings' is (full width
in a narrow window). 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; nothing
found says so; Escape or clearing the box shows every row and the fold
as it was (findProviders).
- A row that is on has a right-click menu, as an agent row has: Move to
top, Move up, Move down, Move to bottom (openProviderMenu), with their
keys. Alt+Shift+↑/↓ on the logo go to the top or the bottom.
- While searching, a row still moves, among the rows shown: Alt+↑/↓ and a
drop put it where the shown row it passes was, and the hidden rows keep
their order (stepProvider, shownToOn). Move to top and Move to bottom go
to the ends of the whole list. Every move saves the whole order through
/api/providers/arrange as before.
- After a save, the keyboard stays on the handle it is on, also when it
was another row's taken up while the save was out (it was lost before).
- The logo's tooltip says right-click moves it to the top or the bottom.
- Drag already scrolls the page near its edges (dragRows); unchanged.
Strings in zh, zh-TW, ja and de. docs/subsystems/gui-shell.md says how it
works.
Run:
- provider-find.test.cjs (new), en, zh, zh-TW, ja, de at 420x560, Chromium
and WebKit: matches by name, model id, account user, key name and two
words; the off row found with its fold open; nothing-found text; Alt+↑ and
a drag while filtered, with the posted order checked; Escape; the menu's
four items, which are off at each end; Alt+Shift+↑/↓; nothing scrolled,
nothing but the order posted, no overflow. Fails on the old assets ("no
search box on the Providers page"), and goes red with each of five breaks
by hand: steps over the full list while filtered, no right-click menu,
drop index taken as a full-list index, no Alt+Shift, the off fold
honoured while searching.
- provider-order.test.cjs updated for the tooltip.
- Every GUI test that opens the Providers page (150 files): WebKit 754/754;
Chromium 748/752 under load ~100, the 4 in azure-endpoint and
routing-save (30s waits on the add sheet and routing) pass alone in both
engines, with provider-search, provider-order and settings-search
(31/31). gui-zh-tw, gui-ja, gui-de pass in both.
- go test -tags nogui ./internal/gui/... (sandbox HOME), go vet darwin,
GOOS=linux and GOOS=windows -tags nogui.
- Screenshots looked at: zh narrow with a search, zh wide with the menu.
This commit is contained in:
@@ -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).
|
||||
|
||||
@@ -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); }
|
||||
|
||||
+115
-7
@@ -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;
|
||||
|
||||
|
||||
@@ -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:",
|
||||
|
||||
@@ -87,6 +87,8 @@
|
||||
<div class="who" role="status" aria-live="polite"><b id="providerDiscoveryCount"></b><span id="providerDiscoverySources"></span></div>
|
||||
<div class="actions"><button class="text primary" id="reviewProviderDiscovery">Review and import…</button><button class="text" id="dismissProviderDiscovery" data-t data-tt="Hide these configurations until they change">Ignore</button></div>
|
||||
</aside>
|
||||
<div class="pv-head" id="pvHead" hidden><input class="sess-filter pv-q" id="pvQ" type="search" spellcheck="false" autocomplete="off" placeholder="Find a provider" aria-label="Find a provider" data-tp></div>
|
||||
<p class="set-none pv-none" id="pvNone" role="status" hidden></p>
|
||||
<div class="list" id="providers"></div>
|
||||
<div class="row-head off-head" id="offHead" hidden><button class="fold" id="foldOff" aria-expanded="false" aria-controls="offProviders"><span class="label" data-t>Turned off</span><span class="note" id="offCount"></span></button></div>
|
||||
<div class="list" id="offProviders" hidden></div>
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// #1614 (ququdu): "供应商很多,然后经常需要翻找,排序拖动也比较慢". The
|
||||
// Providers page has a search box over the list: the words typed keep the
|
||||
// rows that say them, matched on the name, the id, a model's id, an
|
||||
// account's user and the rest, the ones turned off too (their fold opens
|
||||
// while searching); nothing found says so; Escape clears it and puts the
|
||||
// fold back. A row's right-click has Move to Top, Move Up, Move Down and
|
||||
// Move to Bottom, Alt+Shift+↑/↓ go to the top or the bottom from the
|
||||
// keyboard. While searching, a row moves among the ones shown (Alt+↑/↓, a
|
||||
// drag) and the ones hidden keep their order. Nothing scrolls, and in a
|
||||
// narrow window nothing runs off to the side. Every language, Chromium and
|
||||
// WebKit; 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 prov = (id, name, extra = {}) => ({
|
||||
id, name, icon: "generic", host: id + ".example.com", chat: "https://" + id + ".example.com/v1", responses: "", anthropic: "", catalog: "",
|
||||
models: [{ id: id + "-chat", name: name + " Chat", on: true }], agents: [], fallback: [], headers: {},
|
||||
key: { set: true, masked: "sk-…" + id }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "", ...extra,
|
||||
});
|
||||
|
||||
function fixture(lang) {
|
||||
const providers = {
|
||||
providers: [
|
||||
prov("openai", "OpenAI"),
|
||||
prov("relay-one", "Relay One", { models: [{ id: "gpt-5", name: "GPT-5", on: true }] }),
|
||||
prov("anthropic", "Anthropic"),
|
||||
prov("relay-two", "Relay Two", { models: [{ id: "gpt-5", name: "GPT-5", on: true }] }),
|
||||
prov("deepseek", "DeepSeek", { models: [{ id: "deepseek-v3.2", name: "DeepSeek V3.2", on: true }] }),
|
||||
prov("relay-three", "Relay Three", { models: [{ id: "gpt-5", name: "GPT-5", on: true }] }),
|
||||
prov("moonshot", "Moonshot", { keyList: [{ id: "k1", name: "work key", masked: "sk-…1", active: true, on: true }] }),
|
||||
prov("zhipu", "Zhipu GLM", { account: { user: "alice@example.com", agentName: "ZCode", agentIcon: "generic", plan: "Coding Plan" } }),
|
||||
prov("relay-off", "Relay Off", { off: true, models: [{ id: "gpt-5", name: "GPT-5", on: true }] }),
|
||||
],
|
||||
presets: [], excluded: [], gateway: { running: true, window: true },
|
||||
};
|
||||
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
||||
const posted = [];
|
||||
const route = async (route) => {
|
||||
const request = route.request(), url = new URL(request.url());
|
||||
const json = (data) => route.fulfill({ 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 (url.pathname === "/api/state") return json(state);
|
||||
if (url.pathname === "/api/providers/arrange") {
|
||||
const { order } = request.postDataJSON();
|
||||
posted.push(order);
|
||||
providers.providers = order.map((id) => providers.providers.find((p) => p.id === id));
|
||||
return json(providers);
|
||||
}
|
||||
if (request.method() !== "GET") posted.push(url.pathname);
|
||||
if (url.pathname === "/api/providers") return json(providers);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||||
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)];
|
||||
await route.fulfill({ body: await fs.readFile(file), contentType });
|
||||
};
|
||||
return { posted, route, providers };
|
||||
}
|
||||
|
||||
const ON = ["openai", "relay-one", "anthropic", "relay-two", "deepseek", "relay-three", "moonshot", "zhipu"];
|
||||
// the rows that show, on and off
|
||||
const shown = (page) => page.evaluate(() => {
|
||||
const ids = (sel) => [...document.querySelectorAll(sel)].filter((r) => r.getClientRects().length).map((r) => r.dataset.id);
|
||||
return { on: ids("#providers > .row.provider"), off: ids("#offProviders > .row.provider") };
|
||||
});
|
||||
const none = (page) => page.evaluate(() => {
|
||||
const n = document.querySelector("#pvNone");
|
||||
return n.getClientRects().length ? n.textContent : "";
|
||||
});
|
||||
const scrolled = (page) => page.evaluate(() => [scrollX, scrollY, document.querySelector("#view-providers").scrollTop]);
|
||||
const overflow = (page) => page.evaluate(() => {
|
||||
const out = [], de = document.documentElement, v = document.querySelector("#view-providers");
|
||||
if (de.scrollWidth > de.clientWidth) out.push("page " + de.scrollWidth + ">" + de.clientWidth);
|
||||
if (v.scrollWidth > v.clientWidth) out.push("view " + v.scrollWidth + ">" + v.clientWidth);
|
||||
const r = v.getBoundingClientRect(), q = document.querySelector("#pvQ").getBoundingClientRect();
|
||||
if (q.left < r.left - 0.5 || q.right > r.right + 0.5) out.push("box " + q.left + "-" + q.right);
|
||||
return out;
|
||||
});
|
||||
|
||||
const LANGS = ["en", "zh", "zh-TW", "ja", "de"];
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(engine + ": the Providers page can be searched, and a provider moved to the top", { timeout: 180000 }, async (t) => {
|
||||
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const errors = [];
|
||||
t.after(async () => {
|
||||
await browser.close();
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
for (const lang of LANGS) {
|
||||
await t.test(lang, async () => {
|
||||
const ctx = await browser.newContext({ viewport: { width: 420, height: 560 }, reducedMotion: "reduce" });
|
||||
const page = await ctx.newPage(), f = fixture(lang);
|
||||
page.setDefaultTimeout(5000);
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", f.route);
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
await page.locator("#providers > .row.provider").nth(7).waitFor();
|
||||
const tr = (s, vars) => page.evaluate(([s, vars]) => t(s, vars), [s, vars]);
|
||||
const q = page.locator("#pvQ");
|
||||
const type = async (s) => { await q.fill(s); await page.waitForTimeout(60); };
|
||||
|
||||
// the box is over the list, in the shown language, inside the window
|
||||
assert(await q.isVisible(), "no search box on the Providers page");
|
||||
assert.equal(await q.getAttribute("placeholder"), await tr("Find a provider"));
|
||||
assert.equal(await q.getAttribute("aria-label"), await tr("Find a provider"));
|
||||
if (lang !== "en") assert.notEqual(await tr("Find a provider"), "Find a provider", "no translation");
|
||||
assert.deepEqual(await overflow(page), []);
|
||||
assert.deepEqual(await shown(page), { on: ON, off: [] }, "the ones off start folded");
|
||||
const y0 = await scrolled(page);
|
||||
|
||||
// by name, case aside; by a model's id, the one off too and its fold
|
||||
// opened; by an account's user; by a key's name; by two words
|
||||
await type("deepSEEK");
|
||||
assert.deepEqual(await shown(page), { on: ["deepseek"], off: [] });
|
||||
await type("gpt-5");
|
||||
assert.deepEqual(await shown(page), { on: ["relay-one", "relay-two", "relay-three"], off: ["relay-off"] });
|
||||
assert.equal(await page.locator("#foldOff").getAttribute("aria-expanded"), "true");
|
||||
await type("alice@example");
|
||||
assert.deepEqual(await shown(page), { on: ["zhipu"], off: [] });
|
||||
await type("work key");
|
||||
assert.deepEqual(await shown(page), { on: ["moonshot"], off: [] });
|
||||
await type("relay two");
|
||||
assert.deepEqual(await shown(page), { on: ["relay-two"], off: [] });
|
||||
assert.equal(await none(page), "");
|
||||
|
||||
// nothing found says so
|
||||
await type("no-such-thing");
|
||||
assert.deepEqual(await shown(page), { on: [], off: [] });
|
||||
assert.equal(await none(page), await tr("No provider matches “{q}”", { q: "no-such-thing" }));
|
||||
assert.deepEqual(await overflow(page), []);
|
||||
|
||||
// while searching, Alt+↑ moves a row above the one shown above it;
|
||||
// the ones hidden keep their order
|
||||
await type("relay");
|
||||
assert.deepEqual((await shown(page)).on, ["relay-one", "relay-two", "relay-three"]);
|
||||
await page.locator('#providers > .row.provider[data-id="relay-three"] .pv-handle').focus();
|
||||
await page.keyboard.press("Alt+ArrowUp");
|
||||
await page.waitForFunction(() => document.querySelector("#status")?.textContent);
|
||||
await page.waitForFunction(() => [...document.querySelectorAll("#providers > .row.provider")].filter((r) => !r.hidden).map((r) => r.dataset.id).join() === "relay-one,relay-three,relay-two");
|
||||
assert.deepEqual(f.posted.at(-1), ["openai", "relay-one", "anthropic", "relay-three", "relay-two", "deepseek", "moonshot", "zhipu", "relay-off"]);
|
||||
await page.waitForFunction(() => document.activeElement?.closest(".row.provider")?.dataset.id === "relay-three");
|
||||
assert.equal(await q.inputValue(), "relay", "the move cleared the search");
|
||||
|
||||
// a drag among the ones shown: relay-two dropped on relay-one takes
|
||||
// its place, relay-one and the hidden anthropic after it
|
||||
const box = async (id) => page.locator(`#providers > .row.provider[data-id="${id}"] .pv-handle`).boundingBox();
|
||||
const from = await box("relay-two"), to = await box("relay-one");
|
||||
await page.mouse.move(from.x + from.width / 2, from.y + from.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(from.x + from.width / 2, to.y - 10, { steps: 12 });
|
||||
await page.locator("#providers > .row.dragging").waitFor();
|
||||
await page.mouse.up();
|
||||
await page.waitForFunction(() => [...document.querySelectorAll("#providers > .row.provider")].filter((r) => !r.hidden).map((r) => r.dataset.id).join() === "relay-two,relay-one,relay-three");
|
||||
assert.deepEqual(f.posted.at(-1), ["openai", "relay-two", "relay-one", "anthropic", "relay-three", "deepseek", "moonshot", "zhipu", "relay-off"]);
|
||||
|
||||
// Escape clears it: every row back, the fold as it was
|
||||
await q.focus();
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await q.inputValue(), "");
|
||||
assert.deepEqual(await shown(page), { on: ["openai", "relay-two", "relay-one", "anthropic", "relay-three", "deepseek", "moonshot", "zhipu"], off: [] });
|
||||
assert.equal(await page.locator("#foldOff").getAttribute("aria-expanded"), "false");
|
||||
assert.equal(await none(page), "");
|
||||
|
||||
// the last one's right-click: Move to Top goes first, with nothing scrolled
|
||||
const row = page.locator('#providers > .row.provider[data-id="zhipu"]');
|
||||
await row.locator(".name").click({ button: "right" });
|
||||
const menu = page.locator(".pop.row-menu");
|
||||
await menu.waitFor();
|
||||
const names = await menu.locator(".rm-name").allTextContents();
|
||||
assert.deepEqual(names, [await tr("Move to top"), await tr("Move up"), await tr("Move down"), await tr("Move to bottom")]);
|
||||
assert.deepEqual(await menu.locator(".rm-item").evaluateAll((bs) => bs.map((b) => b.disabled)), [false, false, true, true]);
|
||||
await menu.locator(".rm-item").first().click();
|
||||
await page.waitForFunction(() => document.querySelector("#providers > .row.provider").dataset.id === "zhipu");
|
||||
assert.deepEqual(f.posted.at(-1), ["zhipu", "openai", "relay-two", "relay-one", "anthropic", "relay-three", "deepseek", "moonshot", "relay-off"]);
|
||||
assert.equal(await page.locator("#providers > .row.provider.selected").count(), 0, "the right-click opened the row");
|
||||
|
||||
// the first one's: Move to Bottom
|
||||
await page.locator('#providers > .row.provider[data-id="zhipu"] .name').click({ button: "right" });
|
||||
await menu.waitFor();
|
||||
assert.deepEqual(await menu.locator(".rm-item").evaluateAll((bs) => bs.map((b) => b.disabled)), [true, true, false, false]);
|
||||
await menu.locator(".rm-item").last().click();
|
||||
await page.waitForFunction(() => [...document.querySelectorAll("#providers > .row.provider")].at(-1).dataset.id === "zhipu");
|
||||
assert.deepEqual(f.posted.at(-1), ["openai", "relay-two", "relay-one", "anthropic", "relay-three", "deepseek", "moonshot", "zhipu", "relay-off"]);
|
||||
|
||||
// Alt+Shift+↑ from the keyboard: to the top, the keyboard kept on it
|
||||
await page.locator('#providers > .row.provider[data-id="moonshot"] .pv-handle').focus();
|
||||
await page.keyboard.press("Alt+Shift+ArrowUp");
|
||||
await page.waitForFunction(() => document.querySelector("#providers > .row.provider").dataset.id === "moonshot");
|
||||
await page.waitForFunction(() => document.activeElement?.closest(".row.provider")?.dataset.id === "moonshot");
|
||||
assert.deepEqual(f.posted.at(-1), ["moonshot", "openai", "relay-two", "relay-one", "anthropic", "relay-three", "deepseek", "zhipu", "relay-off"]);
|
||||
await page.keyboard.press("Alt+Shift+ArrowDown");
|
||||
await page.waitForFunction(() => [...document.querySelectorAll("#providers > .row.provider")].at(-1).dataset.id === "moonshot");
|
||||
assert.deepEqual(f.posted.at(-1), ["openai", "relay-two", "relay-one", "anthropic", "relay-three", "deepseek", "zhipu", "moonshot", "relay-off"]);
|
||||
|
||||
// only the order was posted, and nothing scrolled
|
||||
assert(f.posted.every((x) => Array.isArray(x)), "something else was posted: " + JSON.stringify(f.posted.filter((x) => !Array.isArray(x))));
|
||||
assert.deepEqual(await scrolled(page), y0);
|
||||
assert.deepEqual(await overflow(page), []);
|
||||
if (process.env.ARTIFACT_DIR) {
|
||||
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
||||
await type("relay");
|
||||
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-provider-find-${lang}.png`) });
|
||||
}
|
||||
await ctx.close();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -89,7 +89,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert(x.inRow, `${x.id}'s grip is off its row or over its logo`);
|
||||
}
|
||||
assert.equal(await page.locator("#offProviders .pv-handle").count(), 0, "a provider switched off has a handle");
|
||||
const tip = await page.evaluate(() => t("Drag to reorder — a model several providers serve goes to the higher one first · Alt+↑/↓ to move"));
|
||||
const tip = await page.evaluate(() => 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"));
|
||||
if (lang === "zh") assert.match(tip, /拖动/);
|
||||
assert.equal(await page.locator("#providers .pv-handle").first().getAttribute("title"), tip);
|
||||
await page.locator("#providers > .row.provider").nth(1).locator(".name").hover();
|
||||
|
||||
Reference in New Issue
Block a user