diff --git a/webui/browser/fixture.tsx b/webui/browser/fixture.tsx index 3c8c2e4ab..84ff38fba 100644 --- a/webui/browser/fixture.tsx +++ b/webui/browser/fixture.tsx @@ -64,6 +64,25 @@ function TallDialogFixture({ placement }: { placement: "center" | "bottom" }) { ; } +function SessionMessagesFixture() { + const messages: UIMessage[] = [ + { id: "own-input", role: "user", content: "Please review the update.", createdAt: 1 }, + { + id: "session-message:short", role: "user", content: "Looks good.", createdAt: 2, + sessionMessage: { message_id: "short", session: { id: "handle_0123456789abcdef0123456789abcdef", name: "mira" } }, + }, + { + id: "session-message:long", role: "user", createdAt: 3, + content: "**Review notes**\n\n- Keep the layout left-aligned.\n- Preserve Markdown and links.\n\n```ts\nconst message = \"" + "long-path/".repeat(30) + "\";\n```\n\n[Release notes](https://example.com/release-notes)", + sessionMessage: { message_id: "long", session: { id: "handle_fedcba9876543210fedcba9876543210", name: "nori" } }, + }, + { id: "reply", role: "assistant", content: "Thanks, I will keep those details.", createdAt: 4 }, + ]; + return
+ +
; +} + const parameters = new URLSearchParams(location.search); const railClient = new NanobotClient({ url: "ws://127.0.0.1:8765", reconnect: false }); const railHistory: UIMessage[] = Array.from({ length: 5 }, (_, index) => [ @@ -169,6 +188,8 @@ createRoot(document.getElementById("root")!).render( ? : parameters.get("case") === "settings-icon" ? + : parameters.get("case") === "session-messages" + ? : parameters.get("case") === "history" ? : } diff --git a/webui/browser/session-messages.spec.ts b/webui/browser/session-messages.spec.ts new file mode 100644 index 000000000..11fd18b55 --- /dev/null +++ b/webui/browser/session-messages.spec.ts @@ -0,0 +1,71 @@ +import { expect, test } from "@playwright/test"; + +for (const theme of ["light", "dark"] as const) { + for (const width of [1280, 390]) { + test(`cross-session bubbles keep their source and layout at ${width}px in ${theme}`, async ({ page }) => { + await page.setViewportSize({ width, height: 900 }); + await page.addInitScript((dark) => document.documentElement.classList.toggle("dark", dark), theme === "dark"); + await page.goto("/browser/fixture.html?case=session-messages"); + const incoming = page.locator("[data-session-message]"); + await expect(incoming).toHaveCount(2); + await expect(incoming.first().getByText("@mira", { exact: true })).toBeVisible(); + await expect(incoming.first().getByText("Looks good.", { exact: true })).toBeVisible(); + await expect(incoming.last().locator("strong")).toHaveText("Review notes"); + await expect(incoming.last().locator("li")).toHaveCount(2); + await expect(incoming.last().getByRole("link", { name: "Release notes" })).toHaveAttribute("href", "https://example.com/release-notes"); + const code = incoming.last().locator("pre"); + await expect(code).toBeVisible(); + + const layout = await page.getByRole("main", { name: "Session messages" }).evaluate((main) => { + const rows = [...main.querySelectorAll("[data-session-message]")]; + const own = main.querySelector("[data-user-text-bubble] > p")!; + const ownStyle = getComputedStyle(own); + const ownRect = own.getBoundingClientRect(); + const threadRow = own.closest("[data-thread-display-unit]")!; + const rowStyle = getComputedStyle(threadRow); + const rowRect = threadRow.getBoundingClientRect(); + return { + left: rowRect.left + parseFloat(rowStyle.paddingLeft), + right: rowRect.right - parseFloat(rowStyle.paddingRight), + available: threadRow.clientWidth - parseFloat(rowStyle.paddingLeft) - parseFloat(rowStyle.paddingRight), + ownRight: ownRect.right, + ownBackground: ownStyle.backgroundColor, + ownRadius: ownStyle.borderRadius, + ownPadding: ownStyle.padding, + pageOverflows: document.documentElement.scrollWidth > innerWidth, + bubbles: rows.map((row) => { + const bubble = row.querySelector("[data-assistant-selectable]")!.parentElement!; + const style = getComputedStyle(bubble); + const rect = bubble.getBoundingClientRect(); + const handle = row.firstElementChild!.firstElementChild!.getBoundingClientRect(); + const body = bubble.querySelector("[data-assistant-selectable]")!.getBoundingClientRect(); + return { left: rect.left, top: rect.top, width: rect.width, background: style.backgroundColor, + radius: style.borderRadius, padding: style.padding, handleBottom: handle.bottom, + handleLeft: handle.left, bodyLeft: body.left }; + }), + }; + }); + expect(layout.pageOverflows).toBe(false); + expect(Math.abs(layout.ownRight - layout.right)).toBeLessThan(1); + expect(layout.bubbles[0].width).toBeLessThan(layout.bubbles[1].width); + for (const bubble of layout.bubbles) { + expect(Math.abs(bubble.left - layout.left)).toBeLessThan(1); + expect(bubble.width).toBeLessThanOrEqual(Math.min(layout.available * 0.85, 576) + 1); + expect(bubble.background).toBe(layout.ownBackground); + expect(bubble.radius).toBe(layout.ownRadius); + expect(bubble.padding).toBe(layout.ownPadding); + expect(bubble.handleBottom).toBeLessThan(bubble.top); + expect(Math.abs(bubble.handleLeft - bubble.bodyLeft)).toBeLessThan(1); + } + + const row = page.locator("[data-thread-display-unit]").filter({ has: page.getByText("@mira", { exact: true }) }); + await row.hover(); + await row.getByRole("button", { name: "Message actions", exact: true }).click(); + await expect(page.locator("[data-message-block-menu]")).toBeVisible(); + await page.context().grantPermissions(["clipboard-read", "clipboard-write"]); + if (width < 768) await page.keyboard.press("Escape"); + await (width < 768 ? row : page.locator("[data-message-block-menu]")).getByRole("button", { name: "Copy", exact: true }).click(); + await expect.poll(() => page.evaluate(() => navigator.clipboard.readText())).toBe("Looks good."); + }); + } +} diff --git a/webui/src/components/MessageBubble.tsx b/webui/src/components/MessageBubble.tsx index 8136fc26a..9315bb77e 100644 --- a/webui/src/components/MessageBubble.tsx +++ b/webui/src/components/MessageBubble.tsx @@ -28,7 +28,6 @@ import { copyTextToClipboard } from "@/lib/clipboard"; import { formatMessageEndTime } from "@/lib/format-time"; import { toMediaAttachment } from "@/lib/media"; import { matchingSlashCommand } from "@/lib/slash-command"; -import { sessionHandleColor } from "@/lib/session-handle"; import { parseQuotedUserMessage } from "@/lib/user-message-quote"; import type { CliAppInfo, @@ -384,22 +383,18 @@ function IncomingSessionMessage({ onOpenFilePreview?: (path: string) => void; }) { const handle = message.sessionMessage!.session; - const color = sessionHandleColor(handle.id); const handleName = `@${handle.name}`; return (
- {contextMenu} -
-
- {handleName} -
+
+ {handleName} +
+
+ {contextMenu}
{ .toBe(screen.getByText("reply").parentElement); }); - it("renders cross-session input with its public handle", () => { + it("renders cross-session input with its public handle above a left-aligned bubble", () => { const message: UIMessage = { id: "session-message:message-1", role: "user", @@ -250,11 +250,17 @@ describe("MessageBubble", () => { }, }; - const { container } = render(); + const contextMenu = ; + const { container } = render(); - expect(container.querySelector("[data-session-message]")).toBeInTheDocument(); - expect(screen.getByText("@mira-0123456789")).toBeInTheDocument(); - expect(screen.getByText("Please review this.")).toBeInTheDocument(); + const row = container.querySelector("[data-session-message]")!; + const handle = screen.getByText("@mira-0123456789"); + const bubble = row.querySelector("[data-assistant-selectable]")!.parentElement!; + expect(row).toHaveClass("mr-auto", "w-fit", "max-w-[min(85%,36rem)]"); + expect(handle.parentElement!.parentElement).toBe(row); + expect(bubble).toHaveClass("relative", "rounded-floating", "bg-secondary/70", "px-4", "py-2"); + expect(bubble).toContainElement(screen.getByText("Please review this.")); + expect(screen.getByRole("button", { name: "Message actions" }).parentElement).toBe(bubble); }); it("outlines temporary-chat user messages with a short dashed border", () => {