diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index e8a861838..6034f621d 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -2663,6 +2663,18 @@ body.window .row.agent .who.with-models { flex-wrap: wrap; row-gap: 0; } .am-seg button { height: 24px; padding: 0 9px; border: 0; border-radius: 6px; background: none; color: var(--ctl-fg); font: inherit; font-size: 12px; cursor: pointer; transition: background-color .15s, color .15s; } .am-seg button.on { background: var(--seg-thumb); color: var(--fg); box-shadow: var(--seg-edge); } .am-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 2px; } +/* the providers down the left (蓝猫 on Discord), the models of the one + picked beside them, each scrolling on its own */ +.am-body { flex: 1 1 auto; min-height: 0; display: flex; gap: 6px; } +.am-body .am-list { min-width: 0; } +.am-rail { flex: none; width: 176px; overflow-y: auto; overscroll-behavior: contain; padding: 4px 6px 2px 2px; border-right: 1px solid var(--line-2); } +.am-ri { display: flex; align-items: center; gap: 8px; width: 100%; height: 30px; padding: 0 8px; border: 0; border-radius: 8px; background: none; color: var(--fg-2); font: inherit; font-size: 12.5px; text-align: left; cursor: pointer; transition: background-color .12s; } +.am-ri:hover { background: var(--pill); } +.am-ri.on { background: var(--accent-soft); color: var(--fg); } +.am-ri > .ic, .am-ri > svg { width: 14px; height: 14px; flex: none; color: var(--muted); } +.am-ri .rn { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.am-ri .c { flex: none; font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; } +.am-ri:focus-visible { outline: 1.5px solid var(--accent); outline-offset: -1.5px; } .am-gh { display: flex; align-items: center; margin: 6px 2px 0; } .am-fold { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 10px; border: 0; border-radius: 8px; background: none; color: var(--muted); font: inherit; font-size: 12px; text-align: left; cursor: pointer; } .am-fold > .ic, .am-fold > svg { width: 14px; height: 14px; flex: none; } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index a5eaf8ffd..f6d4fb69b 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -2101,8 +2101,6 @@ async function openAgentModels(a, anchor, ev) { const reset = el("button", "am-reset", t("Show all")); hideAll.type = reset.type = "button"; foot.append(el("span", "", t("New models are shown")), el("span", "sp"), hideAll, el("span", "am-dot", "·"), reset); - box.append(head, tools, list, foot); - // groups as the catalog has them, routing groups first; a long one // starts folded, unless the agent is set to a model in it const groups = []; @@ -2113,6 +2111,41 @@ async function openAgentModels(a, anchor, ev) { } groups.sort((x, y) => (y.name === ROUTING_GROUPS) - (x.name === ROUTING_GROUPS)); const shut = new Set(groups.filter((g) => groups.length > 1 && g.models.length > 8 && !g.models.some((m) => m.inUse)).map((g) => g.name)); + // with a few providers, a rail of them down the left: one picked shows + // its models alone, so a long list is one click away rather than a + // scroll down past the others (蓝猫 on Discord); a search looks in all + const railed = groups.length > 2 && innerWidth >= 600; + let pick = ""; + const rail = el("div", "am-rail"); + if (railed) { + const body = el("div", "am-body"); + body.append(rail, list); + box.classList.add("railed"); + box.append(head, tools, body, foot); + } else box.append(head, tools, list, foot); + const drawRail = () => { + if (!railed) return; + const top = rail.scrollTop; + rail.replaceChildren(); + const item = (name, label, lead, on, n) => { + const b = el("button", "am-ri" + (pick === name ? " on" : "")); + b.type = "button"; + b.setAttribute("aria-pressed", String(pick === name)); + b.append(lead, el("span", "rn", label), el("span", "c", `${on}/${n}`)); + b.title = label; + b.onclick = () => { pick = name; q.value = ""; list.scrollTop = 0; draw(); }; + rail.append(b); + }; + const all = el("span", "ic"); + all.append(svg("M3 4.5h10M3 8h10M3 11.5h10", 14, 1.5)); + item("", t("All providers"), all, models.filter((m) => !m.hidden).length, models.length); + for (const g of groups) { + const route = g.name === ROUTING_GROUPS; + item(g.name, route ? t(g.name) : g.name, route ? svg(FAN, 14, 1.5) : icon(g.icon || "generic"), + g.models.filter((m) => !m.hidden).length, g.models.length); + } + rail.scrollTop = top; + }; // under "Shown", one just turned off stays until the view changes let onlyShown = false, kept = new Set(); @@ -2147,12 +2180,14 @@ async function openAgentModels(a, anchor, ev) { const top = list.scrollTop; list.replaceChildren(); const words = q.value.trim().toLowerCase(); + drawRail(); for (const g of groups) { + if (pick && !words && g.name !== pick) continue; const rows = g.models.filter((m) => (!onlyShown || !m.hidden || kept.has(m.id)) && (!words || [m.name, m.id, g.name].some((s) => s.toLowerCase().includes(words)))); if (!rows.length) continue; const on = g.models.filter((m) => !m.hidden).length; - const folded = !words && shut.has(g.name); + const folded = !words && !pick && shut.has(g.name); const sec = el("section", "am-g" + (folded ? " shut" : "") + (g.name === ROUTING_GROUPS ? " routes" : "")); const gh = el("div", "am-gh"); const fold = el("button", "am-fold"); @@ -2246,7 +2281,7 @@ async function openAgentModels(a, anchor, ev) { document.body.append(box); // under the line, or over it where there's no room; the list scrolls const r = anchor.getBoundingClientRect(), pad = 8; - const w = Math.min(380, innerWidth - pad * 2); + const w = Math.min(railed ? 580 : 380, innerWidth - pad * 2); box.style.width = w + "px"; const x = Math.max(pad, Math.min(r.left - 10, innerWidth - w - pad)); box.style.left = x + "px"; diff --git a/internal/gui/tests/agent-models.test.cjs b/internal/gui/tests/agent-models.test.cjs index a83dfd8c5..bb3b67c71 100644 --- a/internal/gui/tests/agent-models.test.cjs +++ b/internal/gui/tests/agent-models.test.cjs @@ -64,8 +64,8 @@ function fixture(lang) { } const W = { - en: { entry: "23 hidden", after: "24 hidden", all: "", title: "Codex's model list", current: "Current", shown: "Shown", hideAll: "Hide all", one: "30 hidden", showAll: "Show all" }, - zh: { entry: "已隐藏 23 个", after: "已隐藏 24 个", all: "", title: "Codex 的模型列表", current: "在用", shown: "已显示", hideAll: "全部隐藏", one: "已隐藏 30 个", showAll: "全部显示" }, + en: { entry: "23 hidden", after: "24 hidden", all: "", title: "Codex's model list", current: "Current", shown: "Shown", hideAll: "Hide all", one: "30 hidden", showAll: "Show all", allTab: "All providers", routes: "Routing groups" }, + zh: { entry: "已隐藏 23 个", after: "已隐藏 24 个", all: "", title: "Codex 的模型列表", current: "在用", shown: "已显示", hideAll: "全部隐藏", one: "已隐藏 30 个", showAll: "全部显示", allTab: "全部供应商", routes: "路由组" }, }; for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { @@ -181,12 +181,34 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert(await showAll.isDisabled()); assert(!(await hideAll.isDisabled())); + // the providers down the left: one picked shows its models alone, + // a long one open; a search looks in all of them; All brings back the lot + const rail = pop.locator(".am-rail .am-ri"); + assert.deepEqual((await rail.allInnerTexts()).map((s) => s.replace(/\s+/g, " ").trim()), + [`${w.allTab} 31/31`, `${w.routes} 1/1`, "OpenAI 6/6", "OpenRouter 24/24"]); + assert.equal(await rail.first().getAttribute("aria-pressed"), "true"); + await rail.nth(3).click(); + assert.deepEqual(await pop.locator(".am-fold .gn").allInnerTexts(), ["OpenRouter"]); + assert.equal(await pop.locator(".am-mr").count(), 24, "the picked one is open"); + assert.equal(await rail.nth(3).getAttribute("aria-pressed"), "true"); + await pop.locator(".am-mr", { hasText: "Router model 7" }).click(); + await page.waitForTimeout(150); + assert.equal(await rail.nth(3).locator(".c").innerText(), "23/24", "the rail counts what's shown"); + await q.fill("O4-MINI"); + assert.deepEqual(await pop.locator(".am-fold .gn").allInnerTexts(), ["OpenAI"], "a search looks past the picked one"); + await q.fill(""); + await rail.first().click(); + assert.equal(await pop.locator(".am-fold .gn").count(), 3); + const lb = await pop.locator(".am-list").boundingBox(), rb = await pop.locator(".am-rail").boundingBox(); + assert(rb.x + rb.width <= lb.x + 1 && Math.abs(rb.y - lb.y) < 2, "the rail is left of the list"); + // Esc closes it; so does a click elsewhere await page.keyboard.press("Escape"); await pop.waitFor({ state: "detached" }); await entry.click(); await pop.waitFor(); - await page.mouse.click(900, 650); + const ob = await pop.boundingBox(); + await page.mouse.click(ob.x + ob.width + 8 < 1000 ? ob.x + ob.width + 8 : ob.x - 8, 690); await pop.waitFor({ state: "detached" }); assert.deepEqual(errors, []); });