diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 2f0c64053..043f15f44 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -516,7 +516,10 @@ const I18N = { "Copy the command": "复制命令", "Conversation": "会话内容", "Show conversation": "查看会话", - "Hide conversation": "收起会话", + "Top": "回到顶部", + "Previous turn": "上一轮", + "Next turn": "下一轮", + "Bottom": "到底部", "Export Markdown": "导出 Markdown", "Save the whole conversation as a Markdown file": "将整段会话保存为 Markdown 文件", "Reading…": "读取中…", @@ -5654,7 +5657,10 @@ const I18N = { "Copy the command": "複製命令", "Conversation": "會話內容", "Show conversation": "檢視會話", - "Hide conversation": "收起會話", + "Top": "回到頂部", + "Previous turn": "上一輪", + "Next turn": "下一輪", + "Bottom": "到底部", "Export Markdown": "匯出 Markdown", "Save the whole conversation as a Markdown file": "將整段會話儲存為 Markdown 檔案", "Reading…": "讀取中…", @@ -10761,7 +10767,10 @@ const I18N = { "Copy the command": "コマンドをコピー", "Conversation": "会話", "Show conversation": "会話を表示", - "Hide conversation": "会話を隠す", + "Top": "先頭へ", + "Previous turn": "前のターン", + "Next turn": "次のターン", + "Bottom": "末尾へ", "Export Markdown": "Markdown を書き出す", "Save the whole conversation as a Markdown file": "会話全体を Markdown ファイルとして保存", "Reading…": "読み込み中…", @@ -15878,7 +15887,10 @@ const I18N = { "Copy the command": "Befehl kopieren", "Conversation": "Unterhaltung", "Show conversation": "Unterhaltung anzeigen", - "Hide conversation": "Unterhaltung ausblenden", + "Top": "Nach oben", + "Previous turn": "Vorherige Runde", + "Next turn": "Nächste Runde", + "Bottom": "Nach unten", "Export Markdown": "Als Markdown exportieren", "Save the whole conversation as a Markdown file": "Die ganze Unterhaltung als Markdown-Datei speichern", "Reading…": "Wird gelesen …", diff --git a/internal/gui/assets/plugins/sessions/client.js b/internal/gui/assets/plugins/sessions/client.js index 6bfb29d48..97ddf012d 100644 --- a/internal/gui/assets/plugins/sessions/client.js +++ b/internal/gui/assets/plugins/sessions/client.js @@ -42,7 +42,7 @@ magpie.plugin("sessions", (ctx) => { const folderBoxes = new Map(); // each folder's box as drawn, by cwd let openedFor = ""; // the agent the folders were first unfolded for let detail = ""; // the session opened to its details - const talkOpen = new Set(); // sessions whose conversation is shown, by agent/id + const talkOpen = new Set(); // conversations whose sheet was opened, by agent/id const talks = new Map(); // what was said in them, as read, by agent/id // A session's subagents sit under it, folded (#2261): the conversations // its agent started inside it (Claude Code, Qoder, OpenCode, Kimi Code: @@ -395,7 +395,7 @@ magpie.plugin("sessions", (ctx) => { if (!await confirmAction(t("Stop recording and clear saved conversations"), t("Delete all locally recorded gateway conversation content? Usage totals and native session files are kept."), t("Delete"))) return; recordingBusy = true; clear.disabled = true; - try { await api("sessions/recording", { clear: true }); talks.clear(); await load(); } + try { await api("sessions/recording", { clear: true }); talks.clear(); await load(); for (const b of document.querySelectorAll(".sess-sheet .sess-talk")) b.again?.(); } catch (err) { status(err.message, "err"); } finally { recordingBusy = false; draw(); } }; @@ -1236,7 +1236,6 @@ magpie.plugin("sessions", (ctx) => { // subRow is one subagent of s: what it was asked, the agent it ran as, // and a click shows what was said in it function subRow(s, sa, d) { - const k = s.agent + "/" + s.id + "/" + sa.id; const wrap = el("div", "sm-sub"); wrap.style.setProperty("--sub-in", String(d)); const r = el("button", "row sm-sub-row"); @@ -1246,23 +1245,13 @@ magpie.plugin("sessions", (ctx) => { who.append(el("span", "name", sa.title || sa.kind || sa.id), el("span", "sub", [sa.title ? sa.kind : "", sa.last || sa.start ? ago(sa.last || sa.start) : "", sa.id.slice(0, 8)].filter(Boolean).join(" · "))); r.append(who); - const box = el("div", "sess-talk"); - box.dataset.talk = k; - const show = () => { - const on = talkOpen.has(k); - r.setAttribute("aria-expanded", String(on)); - wrap.classList.toggle("open", on); - box.hidden = !on; - if (on) drawTalk(box, s, sa.id); - }; + r.setAttribute("aria-haspopup", "dialog"); r.onclick = (e) => { e.stopPropagation(); if (window.getSelection()?.toString()) return; - if (talkOpen.has(k)) talkOpen.delete(k); else talkOpen.add(k); - show(); + talkSheet(s, sa); }; - wrap.append(r, box); - show(); + wrap.append(r); return wrap; } @@ -1293,26 +1282,11 @@ magpie.plugin("sessions", (ctx) => { sessUsageDetail(d, s, line); if (s.path) line(t("File"), s.path + (s.files > 1 ? " " + t("+{n} more", { n: s.files - 1 }) : "")); if (s.transcript) { - const box = el("div", "sess-talk"); - box.dataset.talk = s.agent + "/" + s.id; - const b = el("button", "text sess-talk-btn"); + const b = el("button", "text sess-talk-btn", t("Show conversation")); b.type = "button"; - const show = () => { - const on = talkOpen.has(s.agent + "/" + s.id); - b.textContent = t(on ? "Hide conversation" : "Show conversation"); - b.setAttribute("aria-expanded", String(on)); - box.hidden = !on; - if (on) drawTalk(box, s); - }; - b.onclick = (e) => { - e.stopPropagation(); - const k = s.agent + "/" + s.id; - if (talkOpen.has(k)) talkOpen.delete(k); else talkOpen.add(k); - show(); - }; + b.setAttribute("aria-haspopup", "dialog"); + b.onclick = (e) => { e.stopPropagation(); talkSheet(s); }; line(t("Conversation"), b, exportBtn(s)); - d.append(box); - show(); } return d; } @@ -1416,7 +1390,7 @@ magpie.plugin("sessions", (ctx) => { if (talks.get(k) !== pending) return; talks.set(k, value); if (!talkOpen.has(k)) return; - for (const currentBox of page.querySelectorAll(".sess-talk")) { + for (const currentBox of document.querySelectorAll(".sess-talk")) { if (currentBox.dataset.talk === k) drawTalk(currentBox, s, sub); } }; @@ -1440,11 +1414,78 @@ magpie.plugin("sessions", (ctx) => { said = p.model || ""; fresh = false; } else if (p.role === "user") fresh = true; - out.push(ledSaid(p, model)); + const said1 = ledSaid(p, model); + if (p.role === "user" && (!p.kind || p.kind === "text")) said1.dataset.turn = "1"; + out.push(said1); } if (got.tr?.cut) out.push(el("p", "cx-none", t("There was more than is shown here"))); out.push(el("p", "cx-src", t(got.tr?.source === "gateway" ? "Recorded gateway traffic only; earlier, expired or uncaptured content may be missing" : "Read from the agent's session file; magpie keeps no copy"))); box.replaceChildren(...out); + box.dispatchEvent(new Event("talkdrawn")); + } + + // talkSheet shows a session's conversation (or a subagent's, sa) in a + // sheet of its own, long as it may be, with the turns to jump between and + // the top and bottom in its head (Wing8Aqua on X: the inline list was too + // long to get around). A turn is what the user said; the sheet scrolls + // to it, with no animation, as a key pressed many times would. + const NAV = { top: "M4 3.5h8M8 13V6.5M5 9 8 6l3 3", prev: "M4.5 10 8 6.5l3.5 3.5", next: "M4.5 6 8 9.5 11.5 6", bottom: "M4 12.5h8M8 3v6.5M5 7 8 10l3-3" }; + function talkSheet(s, sa) { + const k = s.agent + "/" + s.id + (sa ? "/" + sa.id : ""); + talkOpen.add(k); + const ed = el("div", "editor sess-sheet wide"); + const head = el("div", "ehead"); + const nav = (name, label) => { + const b = el("button", "sess-nav"); + b.type = "button"; + b.dataset.nav = name; + b.title = label; + b.setAttribute("aria-label", label); + b.append(svg(NAV[name], 14, 1.6)); + return b; + }; + const top = nav("top", t("Top")), prev = nav("prev", t("Previous turn")), next = nav("next", t("Next turn")), bottom = nav("bottom", t("Bottom")); + const count = el("span", "sess-turns"); + head.append(icon(agentOf(s.agent).icon), el("b", "", (sa ? sa.title || sa.kind || sa.id : s.title || s.id)), el("span", "grow"), count, top, prev, next, bottom); + const box = el("div", "sess-talk"); + box.dataset.talk = k; + const bar = el("div", "bar"); + const close = el("button", "text primary", t("Close")); + close.type = "button"; + close.onclick = (e) => { e.stopPropagation(); closeConfirmAsk(); }; + bar.append(el("span", "grow"), close); + ed.append(head, box, bar); + confirmAsk = ed; + openModal(ed); + $("#modal").classList.add("lib"); + const body = ed.querySelector(":scope > .ebody"); + const turns = () => [...box.querySelectorAll("[data-turn]")]; + const at = (n) => n.getBoundingClientRect().top - body.getBoundingClientRect().top + body.scrollTop; + const SLACK = 8; + const sync = () => { + const ts = turns(), y = body.scrollTop; + const tops = ts.map(at); + const atEnd = y + body.clientHeight >= body.scrollHeight - 1; + const here = ts.length ? (atEnd ? ts.length : Math.max(1, tops.filter((x) => x <= y + SLACK).length)) : 0; + count.hidden = !ts.length; + count.textContent = here + " / " + ts.length; + prev.disabled = !tops.some((x) => x < y - SLACK); + next.disabled = here >= ts.length; + top.disabled = y <= 0; + bottom.disabled = atEnd; + }; + const go = (y) => { body.scrollTo({ top: y, behavior: "instant" }); sync(); }; + top.onclick = () => go(0); + bottom.onclick = () => go(body.scrollHeight); + prev.onclick = () => { const y = body.scrollTop - SLACK, c = turns().map(at).filter((x) => x < y); if (c.length) go(c[c.length - 1]); }; + next.onclick = () => { const tops = turns().map(at), y = body.scrollTop + SLACK, c = tops[Math.max(1, tops.filter((x) => x <= y).length)]; if (c !== undefined) go(c); }; + let queued = 0; + body.addEventListener("scroll", () => { if (!queued) queued = requestAnimationFrame(() => { queued = 0; sync(); }); }); + box.addEventListener("talkdrawn", sync); + box.again = () => drawTalk(box, s, sa ? sa.id : ""); + box.again(); + sync(); + body.focus({ preventScroll: true }); } function askRelocate(from, wsl) { diff --git a/internal/gui/assets/plugins/sessions/sessions.css b/internal/gui/assets/plugins/sessions/sessions.css index 8264a60a8..dd3e680fe 100644 --- a/internal/gui/assets/plugins/sessions/sessions.css +++ b/internal/gui/assets/plugins/sessions/sessions.css @@ -164,7 +164,6 @@ body.window .sm-group .row.sm-sess { padding-left: 32px; } .row.sm-sub-row { width: 100%; min-height: 38px; text-align: left; padding-left: calc(11px + var(--sub-in, 0) * var(--sub-step)); } body.window .row.sm-sub-row { min-height: 42px; padding-left: calc(14px + var(--sub-in, 0) * var(--sub-step)); } .row.sm-sub-row .who { display: flex; flex-direction: column; } -.sm-sub .sess-talk { margin: 0 10px 8px; } @media (max-width: 560px) { .sm-subs { --sub-step: 10px; padding-left: calc(12px + var(--sub-depth, 0) * var(--sub-step)); padding-right: 8px; } } @@ -213,3 +212,17 @@ body.window .row.sm-sub-row { min-height: 42px; padding-left: calc(14px + var(-- .sm-sp-stats > div { display: flex; flex-direction: column; gap: 3px; min-width: 0; } .sm-sp-k { font-size: 11px; color: var(--muted); } .sm-sp-v { font-size: 13px; font-weight: 500; color: var(--fg); white-space: nowrap; } + +/* a conversation in a sheet of its own: the turns, top and bottom in its head */ +.modal .editor.sess-sheet { height: min(760px, calc(100vh - 80px)); } +.modal .editor.sess-sheet > .ehead { gap: 4px; } +.modal .editor.sess-sheet > .ehead b { min-width: 0; margin-right: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.modal .editor.sess-sheet > .ebody { display: block; outline: none; } +.sess-sheet .sess-talk { max-height: none; overflow: visible; margin: 0; padding: 0; border: 0; background: none; } +.sess-turns { flex: none; min-width: 5ch; margin-right: 4px; text-align: right; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; } +.sess-nav { flex: none; width: 26px; height: 26px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 7px; background: none; color: var(--muted); cursor: pointer; transition: background-color .12s ease, color .12s ease, transform .1s cubic-bezier(.23, 1, .32, 1); } +.sess-nav:disabled { opacity: .35; cursor: default; } +.sess-nav:focus-visible { outline: 2px solid var(--accent, var(--fg)); outline-offset: 1px; } +@media (hover: hover) and (pointer: fine) { .sess-nav:not(:disabled):hover { background: var(--pill); color: var(--fg); } } +.sess-nav:not(:disabled):active { transform: scale(.97); } +@media (max-width: 560px) { .sess-turns { display: none; } } diff --git a/internal/gui/tests/gateway-conversations.test.cjs b/internal/gui/tests/gateway-conversations.test.cjs index 4f736c103..baa1a958c 100644 --- a/internal/gui/tests/gateway-conversations.test.cjs +++ b/internal/gui/tests/gateway-conversations.test.cjs @@ -125,6 +125,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(await page.locator(".sess-talk .cx-part").count(), 5); assert.equal(await page.locator(".sess-talk details").getAttribute("open"), null); assert.equal(await row.evaluate((e) => e.getBoundingClientRect().top), top, "no click scroll"); + await page.locator(".sess-sheet .bar .primary").click(); + await page.locator(".sess-sheet").waitFor({ state: "detached" }); for (const width of [1000, 390]) { await page.setViewportSize({ width, height: 850 }); await page.waitForTimeout(100); @@ -136,13 +138,17 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", } } // A transcript read started before clearing must not restore old content. + await page.evaluate(() => document.querySelector("#nav button[data-view=sessions]").click()); + await row.locator(".who").waitFor(); + await page.waitForTimeout(300); + if (!(await page.locator(".sess-talk-btn").count())) await row.locator(".who").click(); holdNextTranscript = true; const readStarted = page.waitForRequest((r) => new URL(r.url()).pathname === "/api/sessions/transcript"); - await page.evaluate(() => magpie.call("sessions", "open")); + await page.locator(".sess-talk-btn").click(); await readStarted; await assertRecordCard(page); assert.equal(await page.locator(".sm-record .sm-record-clear").count(), 1, "kept text can be deleted from the card"); - await page.locator(".sm-record-clear").click(); + await page.locator(".sm-record-clear").evaluate((b) => b.click()); await page.locator("dialog.action-confirm .primary").click(); await page.waitForFunction(() => document.querySelector(".sm-record-switch")?.getAttribute("aria-checked") === "false"); await page.waitForFunction(() => document.querySelector(".sess-talk .cx-none") && !document.querySelector(".sess-talk .cx-part")); diff --git a/internal/gui/tests/sessions-subagents.test.cjs b/internal/gui/tests/sessions-subagents.test.cjs index 54a67e025..4dcd0ce8d 100644 --- a/internal/gui/tests/sessions-subagents.test.cjs +++ b/internal/gui/tests/sessions-subagents.test.cjs @@ -173,24 +173,27 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", const a1 = subs.nth(1).locator(".sm-sub-row"); await still(a1, "opening a subagent", () => a1.click()); - assert.equal(await a1.getAttribute("aria-expanded"), "true"); - const talk = subs.nth(1).locator(".sess-talk"); + const talk = page.locator(".sess-sheet .sess-talk"); await talk.locator(".cx-part").first().waitFor(); assert.deepEqual(calls, [{ agent: "claude", id: "c-1", sub: "ac1d8e7a80d42178d" }]); assert.equal(await talk.locator(".cx-part").count(), PARTS.length); assert((await talk.textContent()).includes("Kimi reads ~/.kimi/mcp.json")); await tidy(); - await a1.click(); - assert.equal(await talk.isVisible(), false); + await page.locator(".sess-sheet .bar .primary").click(); + await page.locator(".sess-sheet").waitFor({ state: "detached" }); await a1.click(); await talk.locator(".cx-part").first().waitFor(); assert.equal(calls.length, 1, "read once"); + await page.locator(".sess-sheet .bar .primary").click(); + await page.locator(".sess-sheet").waitFor({ state: "detached" }); // the session's own conversation is still its own await row("c-1").locator(".who").click(); await view.locator(".sess-detail .sess-talk-btn").click(); - await view.locator(".sess-detail .sess-talk .cx-part").first().waitFor(); + await page.locator(".sess-sheet .sess-talk .cx-part").first().waitFor(); assert.deepEqual(calls[1], { agent: "claude", id: "c-1" }); + await page.locator(".sess-sheet .bar .primary").click(); + await page.locator(".sess-sheet").waitFor({ state: "detached" }); // folded again, it stays folded when the row is drawn again await item.locator(".sm-subs-fold").first().click(); assert.equal(await view.locator(".sm-sub").count(), 0); diff --git a/internal/gui/tests/sessions-talk-model.test.cjs b/internal/gui/tests/sessions-talk-model.test.cjs index 38fa92241..863db4e99 100644 --- a/internal/gui/tests/sessions-talk-model.test.cjs +++ b/internal/gui/tests/sessions-talk-model.test.cjs @@ -93,7 +93,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", const detail = view.locator(".sess-detail"); await detail.waitFor(); await detail.locator(".sess-talk-btn").click(); - const talk = detail.locator(".sess-talk"); + const talk = page.locator(".sess-sheet .sess-talk"); await talk.locator(".cx-part").first().waitFor(); assert.deepEqual(calls, ["c-1"]); assert.equal(await talk.locator(".cx-part").count(), PARTS.length); diff --git a/internal/gui/tests/sessions-talk-sheet.test.cjs b/internal/gui/tests/sessions-talk-sheet.test.cjs new file mode 100644 index 000000000..0836e30bf --- /dev/null +++ b/internal/gui/tests/sessions-talk-sheet.test.cjs @@ -0,0 +1,122 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// A session's conversation opens in a sheet (Wing8Aqua on X: it was very long +// inline). The sheet's head counts the user's turns and jumps between them, +// to the top and to the bottom, like DSH's viewer; the long text scrolls in +// the sheet, never the page; Close and Escape end it. Chromium and WebKit, +// every language, a wide and a narrow window. +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 at = (min) => new Date(Date.now() - min * 60e3).toISOString(); +const TURNS = 8; +const PARTS = []; +for (let i = 1; i <= TURNS; i++) { + PARTS.push({ role: "user", kind: "text", text: `Question ${i}` }); + PARTS.push({ role: "assistant", kind: "text", text: Array.from({ length: 30 }, (_, j) => `Answer ${i} line ${j}`).join("\n") }); +} + +const nav = { en: "Sessions", zh: "会话", "zh-TW": "會話", ja: "セッション", de: "Sitzungen" }; +const labels = { + en: ["Top", "Previous turn", "Next turn", "Bottom"], + zh: ["回到顶部", "上一轮", "下一轮", "到底部"], + "zh-TW": ["回到頂部", "上一輪", "下一輪", "到底部"], + ja: ["先頭へ", "前のターン", "次のターン", "末尾へ"], + de: ["Nach oben", "Vorherige Runde", "Nächste Runde", "Nach unten"], +}; + +function serve(lang) { + const sessions = [{ agent: "pi", id: "p-1", cwd: "/work/pi", title: "Rename foo", start: at(10), last: at(5), models: [], resume: "pi --session p-1", path: "~/p-1.jsonl", size: 4096, messages: 6, files: 1, deletable: true, transcript: true }]; + return async (route) => { + const url = new URL(route.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({ agents: [], profiles: [], settings: { lang, theme: "light" } }); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/groups") return json({ groups: [] }); + if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } }); + if (url.pathname === "/api/sessions/manage") return json({ agents: [{ agent: "pi", count: 1, deletable: true, name: "Pi", icon: "pi" }], agent: "pi", sessions, terminal: true, trash: [], trashDir: "~/trash" }); + if (url.pathname === "/api/sessions/transcript") return json({ parts: PARTS }); + 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 }); + }; +} + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) { + test(`${engine} ${lang}: a long conversation opens in a sheet with turn navigation`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + const page = await (await browser.newContext({ viewport: { width: 1000, height: 700 }, reducedMotion: "reduce" })).newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang)); + await page.goto("http://magpie.test/?view=providers"); + await page.locator("#nav").getByRole("button", { name: nav[lang], exact: true }).click(); + const row = page.locator('.row.sm-sess[data-id="p-1"]'); + await row.locator(".who").click(); + await page.locator(".sess-talk-btn").click(); + const sheet = page.locator(".sess-sheet"); + await sheet.waitFor(); + await sheet.locator(".cx-part").first().waitFor(); + assert.equal(await page.locator(".sess-detail .sess-talk").count(), 0, "not inline"); + const body = sheet.locator(":scope > .ebody"); + const btn = (n) => sheet.locator(`.sess-nav[data-nav="${n}"]`); + const metrics = () => body.evaluate((e) => ({ top: e.scrollTop, max: e.scrollHeight - e.clientHeight, client: e.clientHeight })); + const m0 = await metrics(); + assert(m0.max > m0.client * 2, "the conversation is longer than the sheet"); + assert(await sheet.evaluate((e) => e.getBoundingClientRect().height <= innerHeight), "the sheet fits the window"); + assert.deepEqual(await sheet.locator(".sess-nav").evaluateAll((l) => l.map((e) => e.getAttribute("aria-label"))), [labels[lang][0], labels[lang][1], labels[lang][2], labels[lang][3]]); + const turns = sheet.locator(".sess-turns"); + assert.equal((await turns.textContent()).trim(), `1 / ${TURNS}`); + assert.equal(await btn("prev").isDisabled(), true); + assert.equal(await btn("top").isDisabled(), true); + await btn("next").click(); + assert.equal((await turns.textContent()).trim(), `2 / ${TURNS}`); + const turnTop = await sheet.locator('.sess-talk [data-turn="1"]').nth(1).evaluate((e) => e.getBoundingClientRect().top - e.closest(".ebody").getBoundingClientRect().top); + assert(Math.abs(turnTop) < 24, "the second question is at the sheet's top: " + turnTop); + await btn("next").click(); + assert.equal((await turns.textContent()).trim(), `3 / ${TURNS}`); + await btn("prev").click(); + assert.equal((await turns.textContent()).trim(), `2 / ${TURNS}`); + await btn("bottom").click(); + const mb = await metrics(); + assert(Math.abs(mb.top - mb.max) < 2, "at the bottom"); + assert.equal(await btn("bottom").isDisabled(), true); + assert.equal((await turns.textContent()).trim(), `${TURNS} / ${TURNS}`); + assert.equal(await btn("next").isDisabled(), true); + await btn("top").click(); + assert.equal((await metrics()).top, 0); + assert.equal((await turns.textContent()).trim(), `1 / ${TURNS}`); + assert.equal(await page.evaluate(() => scrollY), 0, "the page never scrolled"); + + // narrow + await page.setViewportSize({ width: 390, height: 640 }); + await page.waitForTimeout(100); + assert(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), "no page overflow"); + assert(await sheet.evaluate((e) => { const r = e.getBoundingClientRect(); return r.left >= 0 && r.right <= innerWidth && r.bottom <= innerHeight; }), "the sheet fits a phone"); + for (const n of ["top", "prev", "next", "bottom"]) assert(await btn(n).isVisible(), n + " reachable"); + await btn("next").click(); + await btn("bottom").click(); + const mn = await metrics(); + assert(Math.abs(mn.top - mn.max) < 2); + + // Escape ends it, and it opens again from what was read + await page.keyboard.press("Escape"); + await sheet.waitFor({ state: "detached" }); + await page.locator(".sess-talk-btn").click(); + await sheet.locator(".cx-part").first().waitFor(); + await sheet.locator(".bar .primary").click(); + await sheet.waitFor({ state: "detached" }); + assert.deepEqual(errors, []); + }); + } +} diff --git a/internal/gui/tests/sessions-talk.test.cjs b/internal/gui/tests/sessions-talk.test.cjs index 52b1850e0..6d533a2dc 100644 --- a/internal/gui/tests/sessions-talk.test.cjs +++ b/internal/gui/tests/sessions-talk.test.cjs @@ -153,9 +153,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert(keys.includes(w.talk)); const show = detail.locator(".sess-talk-btn"); assert.equal((await show.textContent()).trim(), w.show); - assert.equal(await detail.locator(".sess-talk").isVisible(), false, "the conversation waits to be asked for"); + assert.equal(await page.locator(".sess-sheet").count(), 0, "the conversation waits to be asked for"); await still(row("p-1"), "showing the conversation", () => show.click()); - const talk = detail.locator(".sess-talk"); + const talk = page.locator(".sess-sheet .sess-talk"); await talk.locator(".cx-part").first().waitFor(); assert.deepEqual(calls.filter((c) => c.path === "transcript"), [{ path: "transcript", agent: "pi", id: "p-1" }]); assert.equal(await talk.locator(".cx-part").count(), PARTS.length); @@ -165,13 +165,14 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.deepEqual(await talk.locator(".cx-name").allTextContents(), ["bash", "bash"]); assert.equal(await talk.locator("details.cx-part").getAttribute("open"), null, "thinking is folded"); assert((await talk.locator(".cx-t").first().textContent()).includes("Rename foo to bar")); - assert.equal((await show.textContent()).trim(), w.hide); - // hidden, and shown again from what was read - await show.click(); - assert.equal(await talk.isVisible(), false); + // closed, and shown again from what was read + await page.locator(".sess-sheet .bar .primary").click(); + await page.locator(".sess-sheet").waitFor({ state: "detached" }); await show.click(); await talk.locator(".cx-part").first().waitFor(); assert.equal(calls.filter((c) => c.path === "transcript").length, 1, "read once"); + await page.locator(".sess-sheet .bar .primary").click(); + await page.locator(".sess-sheet").waitFor({ state: "detached" }); const border = await page.evaluate(() => [...document.querySelectorAll("#view-sessions, #view-sessions *")] .filter((e) => parseFloat(getComputedStyle(e).borderLeftWidth) > 1 && getComputedStyle(e).borderLeftColor !== getComputedStyle(e).borderRightColor).map((e) => e.className)); @@ -192,7 +193,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", if (lang === "zh") { const missing = await page.evaluate(() => ["Continue in {agent}", "Continue in", "Continue this session in another agent", "Continue in another agent", - "Copy the command", "Conversation", "Show conversation", "Hide conversation", "Reading…"].filter((k) => !I18N.zh[k] || !I18N.ja[k] || !I18N.de[k])); + "Copy the command", "Conversation", "Show conversation", "Top", "Bottom", "Previous turn", "Next turn", "Reading…"].filter((k) => !I18N.zh[k] || !I18N.ja[k] || !I18N.de[k])); assert.deepEqual(missing, [], "every string has its Chinese, Japanese and German"); } assert.deepEqual(errors, []);