diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js index 22e74b9a3..01b5ee098 100644 --- a/internal/gui/assets/plugins/routing/client.js +++ b/internal/gui/assets/plugins/routing/client.js @@ -2568,6 +2568,10 @@ function routingPage(part) { else if (w.speaks) s = t("{api} only", { api: API[w.speaks] || w.speaks }); else s = w.kind === "key" ? t("API key") : t("one key"); if (row.st.textContent !== s) row.st.textContent = s; + // the intent is the user's own words, of any length: cut short on + // the row (routing.css), read whole over it + const full = said && s.includes(said) ? s : ""; + if (row.st.title !== full) { if (full) row.st.title = full; else row.st.removeAttribute("title"); } // an empty title would hide the row's own // an account's windows each, with when they reset, in its tooltip // (#1835): the row says the fullest one while idle and what it is // doing while it answers, and a second line on every seat would @@ -4441,7 +4445,10 @@ function routingPage(part) { return pointAt(l.p, l.rev ? lens[i] - d : d); }; if (!total) return; - const d = e * total, pt = point(d); + // every wire ends at a card, and the sky is under the cards: a flight + // starts and ends a dot clear of them, so a dot held at its seat or + // waiting at magpie is seen whole + const edge = Math.min(6, total / 4), d = edge + e * (total - 2 * edge), pt = point(d); setAttr(tr.dot, "cx", String(pt.x)); setAttr(tr.dot, "cy", String(pt.y)); tr.dot.removeAttribute("visibility"); diff --git a/internal/gui/assets/plugins/routing/routing.css b/internal/gui/assets/plugins/routing/routing.css index fa0e54bf5..41414a037 100644 --- a/internal/gui/assets/plugins/routing/routing.css +++ b/internal/gui/assets/plugins/routing/routing.css @@ -19,9 +19,13 @@ .rt-flows { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; will-change: transform; } .rt-flows path { fill: none; stroke: var(--agent, var(--muted)); stroke-width: 1.5; stroke-dasharray: 3 5; animation: rtflow .7s linear infinite; } @keyframes rtflow { to { stroke-dashoffset: -8; } } -/* the magpies, over the nodes: one carries each request out, another - brings its answer back — the dot at the tip of its beak */ -.rt-sky { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; overflow: visible; pointer-events: none; } +/* the magpies: one carries each request out, another brings its answer + back — the dot at the tip of its beak. They fly along the wires and + under the cards, through magpie's box rather than over its words: over + them, with two agents sending at once one sat on the hub's address and + another on a member's row (penershu on X). Each flight starts and ends + a dot clear of the card at either end of its wire (pose). */ +.rt-sky { position: absolute; inset: 0; z-index: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; } /* each agent's requests and answers fly in its colour: a request filled with it, an answer ringed with it, a failure ringed red */ .rt-sky .pkt { fill: var(--agent, var(--fg)); filter: drop-shadow(0 0 3px var(--agent, var(--muted))); } @@ -56,7 +60,7 @@ .rt-hub.tick, .rt-src.tick { animation: rttick .4s ease-out; } @keyframes rttick { 40% { transform: scale(1.04); } } .rt-accts { position: relative; z-index: 1; list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; min-width: 0; } -.rt-accts li { position: relative; display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; align-items: center; column-gap: 10px; row-gap: 6px; padding: 9px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; font-size: 13px; transition: opacity .3s, border-color .3s, transform .5s cubic-bezier(.2, .8, .2, 1); } +.rt-accts li { position: relative; display: grid; grid-template-columns: 10px minmax(0, 1fr) fit-content(60%); align-items: center; column-gap: 10px; row-gap: 6px; padding: 9px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; font-size: 13px; transition: opacity .3s, border-color .3s, transform .5s cubic-bezier(.2, .8, .2, 1); } .rt-accts li { margin-left: calc(var(--depth, 0) * 18px); } /* a key off screen is not laid out or painted (#3164): with hundreds of keys open, WebKit painted every row again on each frame a magpie flew. @@ -96,6 +100,10 @@ .rt-accts b code.mdl, :is(.rt-req, .rt-probe) code, .rt-act code.mdl { font: var(--code-style, normal) 500 11px/1.5 var(--code-font, var(--code)); font-stretch: var(--code-stretch, 100%); color: var(--fg-2); background: var(--card-2); border-radius: 5px; padding: 0 5px; } .rt-accts b code.mdl { margin-left: 7px; font-weight: 450; } .rt-accts em { font-style: normal; font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; } +/* what a row says has at most its column: a long one (an intent smart + routing picked it for) is cut short, its name kept, never run off the + row's edge (penershu on X) */ +.rt-accts li > em { min-width: 0; overflow: hidden; text-overflow: ellipsis; } .rt-accts .bar { grid-column: 2 / 4; height: 3px; border-radius: 2px; background: var(--card-2); overflow: hidden; } .rt-accts .bar i { display: block; height: 100%; width: 0; border-radius: 2px; background: var(--muted); transition: width .4s; } .rt-accts li.nobar .bar { display: none; } diff --git a/internal/gui/tests/routing-held-dot.test.cjs b/internal/gui/tests/routing-held-dot.test.cjs index d79253c8a..32ef0102f 100644 --- a/internal/gui/tests/routing-held-dot.test.cjs +++ b/internal/gui/tests/routing-held-dot.test.cjs @@ -80,7 +80,9 @@ for (const engine of engines) for (const lang of langs) for (const width of widt const atSeat = async (when) => { const w = await page.evaluate(where); assert(w, `${when}: the seat answering must be marked, with the request's dot held at it`); - assert(Math.abs(w.dot.x - w.seat.l) <= 6, `${when}: the held dot (x ${w.dot.x.toFixed(1)}) must sit at the seat's edge (x ${w.seat.l.toFixed(1)})`); + // beside it, a dot clear of the card: the sky is under the cards + // (routing-sky-under) + assert(w.dot.x < w.seat.l && w.seat.l - w.dot.x <= 10, `${when}: the held dot (x ${w.dot.x.toFixed(1)}) must sit at the seat's edge (x ${w.seat.l.toFixed(1)})`); assert(w.dot.y >= w.seat.t && w.dot.y <= w.seat.b, `${when}: the held dot (y ${w.dot.y.toFixed(1)}) must sit beside the seat (y ${w.seat.t.toFixed(1)}–${w.seat.b.toFixed(1)})`); }; await atSeat("Routing picked"); diff --git a/internal/gui/tests/routing-sky-under.test.cjs b/internal/gui/tests/routing-sky-under.test.cjs new file mode 100644 index 000000000..ab6be4854 --- /dev/null +++ b/internal/gui/tests/routing-sky-under.test.cjs @@ -0,0 +1,176 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// penershu on X (v0.1.2123): with two agents sending at once through one +// group, the Routing stage's magpies were drawn over the cards — one over +// the hub's "127.0.0.1:3425", its request's dot beside it, another over a +// member's row — and the row smart routing's intent picked ran its long +// intent off the row's right edge, its name squeezed out. The magpies fly +// under the cards now: nothing in the sky covers a card's words, a dot held +// at its seat or waiting at magpie sits whole beside the card, and a long +// intent is cut short on its row, read whole in its tooltip, the name kept. +// Three agents at once (one still waiting at magpie), at a wide window (the +// reporter's, where a row says it on its name's line), at 1100px, at the +// narrow stage and at a phone's width, in every language, both engines. +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 INTENT = "Design architecture, define module boundaries, or compare substantial technical approaches. Exclude routine implementation"; +const models = [ + { id: "a/fast", name: "fast", providerName: "A", icon: "generic", context: 256000, ready: true }, + { id: "b/opus", name: "opus", providerName: "B", icon: "generic", context: 1000000, ready: true }, +]; +const groups = () => ({ + models, + groups: [{ id: "jd", name: "jd-auto-balanced", members: ["a/fast", "b/opus"], routing: "order", ready: true, classifier: "c/cls", + memberInfo: [{ id: "a/fast", ready: true, context: 256000 }, { id: "b/opus", ready: true, context: 1000000 }], + rules: [{ use: "b/opus", intent: INTENT }] }], + pools: [], +}); +const now = Date.now(); +const order = () => [{ id: "b", provider: "b", name: "B", kind: "account", model: "opus", known: true, used: 10 }, + { id: "a", provider: "a", name: "A", kind: "account", model: "fast", known: true, used: 20 }]; +const group = { id: "jd", name: "jd-auto-balanced", members: ["a/fast", "b/opus"] }; +const at = (ms) => new Date(now - ms).toISOString(); +// claude's request is with b (the intent's pick), codex's with a, and +// kimi's waits at magpie for routing to pick +const routes = () => [ + { id: 7, seq: 7, time: at(3000), agent: "claude", model: "group/jd", provider: "b", tokens: 9000, group, order: order(), + tries: [{ id: "b", model: "opus", start: at(2500) }], done: false, + rule: { n: 1, use: "b/opus", when: [`intent "${INTENT}"`], turn: 3, tokens: 9000, classified: { by: "c/cls", intents: [INTENT], intent: INTENT, ms: 300 } } }, + { id: 8, seq: 8, time: at(2000), agent: "codex", model: "group/jd", provider: "a", tokens: 4000, group, order: order().slice(1), + tries: [{ id: "a", model: "fast", start: at(1500) }], done: false }, + { id: 9, seq: 9, time: at(1000), agent: "kimi", model: "group/jd", provider: "", tokens: 2000, group, order: [], tries: [], done: false }, +]; + +function serve(lang) { + const state = { agents: [ + { id: "claude", name: "Claude Code", path: "/test/claude", fields: [] }, + { id: "codex", name: "Codex", path: "/test/codex", fields: [] }, + { id: "kimi", name: "Kimi Code", path: "/test/kimi", fields: [] }, + ], profiles: [], settings: { lang, theme: "light" } }; + let first = true; + return async (r) => { + const url = new URL(r.request().url()); + const json = (data) => r.fulfill({ json: data }); + if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` }); + if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json(state); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/gateway/trace") { + if (url.searchParams.get("wait")) return new Promise(() => {}); // nothing more comes + const rs = first ? routes() : []; + first = false; + return json({ mine: true, now: new Date().toISOString(), seq: 9, totals: { requests: 3, rerouted: 0, errors: 0 }, routes: rs }); + } + if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] }); + if (url.pathname === "/api/groups") return json(groups()); + if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3425" } }); + 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 r.fulfill({ body: await fs.readFile(file), contentType }); + }; +} + +// covered: the words on the stage's cards that something in the sky would +// be drawn over. The sky is filled whole with a probe, made hittable, and +// each card's words asked what is on top of them. +const covered = () => { + const sky = document.querySelector(".rt-sky"); + const NS = "http://www.w3.org/2000/svg"; + const probe = document.createElementNS(NS, "rect"); + probe.setAttribute("x", "-5000"); probe.setAttribute("y", "-5000"); + probe.setAttribute("width", "10000"); probe.setAttribute("height", "10000"); + probe.style.pointerEvents = "all"; + sky.append(probe); + sky.style.pointerEvents = "auto"; + const out = []; + try { + const words = [...document.querySelectorAll(".rt-stage .rt-node b, .rt-stage .rt-node small, .rt-stage .rt-node i, .rt-accts li:not(.rt-gap) > b, .rt-accts li:not(.rt-gap) > em, .rt-accts li.rt-sub > b")]; + for (const w of words) { + const r = w.getBoundingClientRect(); + if (!r.width || !r.height) continue; + for (const [x, y] of [[r.left + 2, r.top + r.height / 2], [r.left + r.width / 2, r.top + r.height / 2], [r.right - 2, r.top + r.height / 2]]) { + const hit = document.elementFromPoint(x, y); + if (hit && sky.contains(hit)) { out.push(`${w.tagName.toLowerCase()} "${w.textContent.slice(0, 30)}"`); break; } + } + } + } finally { probe.remove(); sky.style.pointerEvents = ""; } + return out; +}; + +// dots: each request's dot at rest, and the cards it overlaps +const dots = () => { + const cards = [...document.querySelectorAll(".rt-stage .rt-node, .rt-accts li:not(.rt-gap)")].map((e) => [e, e.getBoundingClientRect()]); + return [...document.querySelectorAll(".rt-sky .pkt")].filter((d) => d.getAttribute("visibility") !== "hidden").map((d) => { + const r = d.getBoundingClientRect(), cx = r.left + r.width / 2, cy = r.top + r.height / 2, rad = Number(d.getAttribute("r")) || 4.5; + const over = cards.filter(([, c]) => cx + rad > c.left + .5 && cx - rad < c.right - .5 && cy + rad > c.top + .5 && cy - rad < c.bottom - .5) + .map(([e]) => e.className || e.tagName); + // the nearest card: how far the dot is from it + const gap = Math.min(...cards.map(([, c]) => Math.hypot(Math.max(c.left - cx, 0, cx - c.right), Math.max(c.top - cy, 0, cy - c.bottom)))); + return { held: d.classList.contains("held"), over, gap }; + }); +}; + +// the row the intent picked: what it says, and whether its name kept room +const intentRow = (intent) => { + const em = [...document.querySelectorAll(".rt-accts li > em")].find((e) => e.textContent.includes(intent)); + if (!em) return null; + const li = em.parentElement, b = li.querySelector(":scope > b"), e = em.getBoundingClientRect(), l = li.getBoundingClientRect(); + return { emRight: e.right, liRight: l.right, cardRight: document.querySelector(".rt").getBoundingClientRect().right, name: b.getBoundingClientRect().width, title: em.title, text: em.textContent, cut: em.scrollWidth > em.clientWidth + 1, wraps: getComputedStyle(em).whiteSpace !== "nowrap" }; +}; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) { + for (const width of [1600, 1100, 560, 390]) { + test(`${engine} ${lang} ${width}px: three agents at once, the magpies fly under the cards and a long intent stays in its row`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const page = await (await browser.newContext({ viewport: { width, height: 1000 } })).newPage(); + page.setDefaultTimeout(8000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + t.after(async () => { + if (process.env.ARTIFACT_DIR) { + await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true }); + await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-sky-under.png`) }).catch(() => {}); + } + await browser.close(); + }); + await page.route("**/*", serve(lang)); + await page.goto("http://magpie.test/?view=routing"); + // the two requests routing picked for are held at their seats, the + // third's dot waits at magpie + await page.waitForFunction(() => document.querySelectorAll(".rt-sky .pkt.held").length === 2); + await page.waitForFunction(() => document.querySelectorAll(".rt-sky .pkt:not([visibility])").length === 3); + await page.waitForTimeout(900); // the third's flight to magpie lands, the carriers fly off + const flown = await page.evaluate(() => document.querySelectorAll(".rt-sky .rt-flier").length); + assert(flown >= 1, "the magpie carrying the waiting request stays with it at magpie"); + + assert.deepEqual(await page.evaluate(covered), [], "nothing in the sky may be drawn over a card's words"); + const ds = await page.evaluate(dots); + assert.equal(ds.length, 3, JSON.stringify(ds)); + for (const d of ds) { + assert.deepEqual(d.over, [], `a ${d.held ? "held" : "waiting"} dot must sit whole beside its card, not under or over it: ${JSON.stringify(ds)}`); + assert(d.gap <= 12, `a ${d.held ? "held" : "waiting"} dot must sit at its card (${d.gap.toFixed(1)}px off): ${JSON.stringify(ds)}`); + } + + const row = await page.evaluate(intentRow, INTENT); + assert(row, "the row the intent picked says the intent"); + assert(row.emRight <= row.liRight + .5, `the intent runs off its row: ${JSON.stringify(row)}`); + assert(row.liRight <= row.cardRight + .5, `the row runs off the stage's card: ${JSON.stringify(row)}`); + if (width >= 1600) assert(!row.wraps, `a wide list says it on the name's line: ${JSON.stringify(row)}`); + if (!row.wraps) { + assert(row.name >= 60, `the row's name keeps room beside the intent: ${JSON.stringify(row)}`); + assert(row.cut, `a long intent is cut short on one line: ${JSON.stringify(row)}`); + } + assert.equal(row.title, row.text, "the whole intent is in the tooltip"); + const wide = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); + assert(wide <= 0, `no sideways scroll: ${wide}px`); + assert.deepEqual(errors, []); + }); + } + } +}