diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js index 89c7f1c78..558f9a5ce 100644 --- a/internal/gui/assets/plugins/routing/client.js +++ b/internal/gui/assets/plugins/routing/client.js @@ -1548,11 +1548,16 @@ function routingPage(part) { // the title of the session a request is of, as its agent named it, or // nothing: never one matched to it by its prompt (parentMatched), which // the list's head says is a guess (connor_yang on Discord) - const titleOf = (r) => !r || r.parentMatched ? "" : r.agent === "codex" ? codexNames.get(groupSession(r)) || "" : otherTitles.get(ownKey(r)) || ""; + const titleOf = (r) => oneLine(!r || r.parentMatched ? "" : r.agent === "codex" ? codexNames.get(groupSession(r)) || "" : otherTitles.get(ownKey(r)) || ""); // sessionName is what a request's session is called where it has a // name: its agent's title for it (the trace's, or one read since), else // nothing - const sessionName = (r) => r.sessionTitle || titleOf(r) || ""; + const sessionName = (r) => oneLine(r.sessionTitle) || titleOf(r); + // oneLine is a title as one line. A title is often its session's first + // prompt, and WebKit breaks a line at U+2028/U+2029 even under nowrap, so + // a session's block meant for one line of it stacked every line of the + // prompt (tz_188 on Discord) + function oneLine(s) { return s ? String(s).replace(/[\s\u0085]+/g, " ").trim() : ""; } const subs = new Map(); // a group in the group's way down → its heading { li, wire, key, up } // A provider's keys serving one model, FOLD_AT or more of them side by // side, fold into one row that tells of them all (#1319: 53 keys for one diff --git a/internal/gui/assets/plugins/routing/routing.css b/internal/gui/assets/plugins/routing/routing.css index b32062d4a..f3216e061 100644 --- a/internal/gui/assets/plugins/routing/routing.css +++ b/internal/gui/assets/plugins/routing/routing.css @@ -180,7 +180,7 @@ .rt-ctx-s[aria-pressed="true"] { background: var(--card-2); color: var(--fg); } .rt-ctx-s .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; } .rt-ctx-s .sub { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; } -.rt-ctx-s .ctx-stack { display: flex; max-width: none; width: 100%; height: 4px; border-radius: 2px; } +.rt-ctx-s .ctx-stack { flex: none; display: flex; max-width: none; width: 100%; height: 4px; border-radius: 2px; } .rt-log-head { display: flex; flex-wrap: wrap; align-items: center; row-gap: 2px; font-size: 12px; font-weight: 600; color: var(--fg); } .rt-log-head .grow { flex: 1; } /* a request's request and response, opened from the story's head */ diff --git a/internal/gui/tests/routing-ctx-sessions.test.cjs b/internal/gui/tests/routing-ctx-sessions.test.cjs index 1d9289fa3..a8043e465 100644 --- a/internal/gui/tests/routing-ctx-sessions.test.cjs +++ b/internal/gui/tests/routing-ctx-sessions.test.cjs @@ -173,4 +173,43 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.deepEqual((await blocks(page)).map((b) => b.name), ["docs", SESS.a.title]); assert.deepEqual(errors, []); }); + // tz_188 on Discord: ZCode's sessions are named by their first prompt, + // a long Chinese one of several lines. WebKit breaks a line at U+2028 + // and U+2029 even where a name is kept to one, so each block stacked + // the prompt's lines. Its bar took context.css's flex: 1 1 0, so in a + // block as tall as its lines it was 0px high, and in a shorter block + // beside a taller one it stretched to fill it. Each name is one line in + // every block, at every width, in every language, and every bar is 4px. + test(`${engine}: a session named by a prompt of many lines is one line in its block`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + const prompt = "你的唯一任务是采集并分析用户提供的所有网页内容,逐条提取关键信息。\u2028要求:\u2029一、严格按照格式输出;\r\n二、保留原文中的数字与链接;\u0085三、不要遗漏任何一条。\n\n"; + const titles = { a: SESS.a.title, b: SESS.b.title }; + t.after(() => { SESS.a.title = titles.a; SESS.b.title = titles.b; }); + SESS.a.title = prompt.repeat(40); + SESS.b.title = prompt; + for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) { + for (const width of [1100, 700, 390]) { + await t.test(`${lang} ${width}px`, async () => { + const { context, page, errors } = await open(browser, lang, width, [req(101, "a"), req(102, "b"), req(103, "a")]); + t.after(() => context.close()); + await page.locator(".rt-ctx-sess:not([hidden]) .rt-ctx-s").nth(1).waitFor(); + const got = await page.$$eval(".rt-ctx-s", (bs) => bs.map((b) => { + const h = (q) => b.querySelector(q).getBoundingClientRect().height; + return { name: b.querySelector(".nm").textContent, nm: h(".nm"), sub: h(".sub"), bar: h(".ctx-stack") }; + })); + assert.equal(got.length, 2); + for (const g of got) { + assert.ok(!/[\n\r\u2028\u2029\u0085]/.test(g.name), `the name is one line of text: ${JSON.stringify(g.name.slice(0, 80))}`); + assert.ok(g.name.startsWith("你的唯一任务是采集并分析用户提供的所有网页内容,逐条提取关键信息。 要求: 一、"), g.name.slice(0, 80)); + assert.ok(g.nm < 2 * g.sub, `the name is drawn on one line: ${g.nm}px against the sub-line's ${g.sub}px`); + assert.equal(Math.round(g.bar), 4, `the bar keeps its 4px: ${g.bar}`); + } + const crumbs = await page.locator(".rt-ctx .ctx-crumbs").textContent(); + assert.ok(!/[\n\r\u2028\u2029\u0085]/.test(crumbs), "the card's crumbs name it on one line too"); + assert.deepEqual(errors, []); + }); + } + } + }); }