fix(webui): render cross-session inputs as left-aligned bubbles (NAN-317) (#6369)

* fix(webui): render cross-session inputs as left-aligned bubbles (NAN-317)

* fix(webui): place source handles above session bubbles
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-21 18:03:37 +08:00
1 parent b32b1327ce
commit d2ab462b42
4 files changed
+109 -16

No files matched your search

+21
View File
@@ -64,6 +64,25 @@ function TallDialogFixture({ placement }: { placement: "center" | "bottom" }) {
</main>;
}
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 <main className="mx-auto max-w-3xl px-6 py-8" aria-label="Session messages">
<ThreadMessages messages={messages} isStreaming={false} />
</main>;
}
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(<TooltipProvider>
? <ClientProvider client={railClient} token="fixture" webuiCapabilities={["webui.prompt-navigation.v1"]}><RailFixture /></ClientProvider>
: parameters.get("case") === "settings-icon"
? <Button variant="icon" size="icon" aria-label="Settings"><SettingsIcon className="h-4 w-4" /></Button>
: parameters.get("case") === "session-messages"
? <SessionMessagesFixture />
: parameters.get("case") === "history"
? <HistoryFixture />
: <TallDialogFixture placement={parameters.get("placement") === "bottom" ? "bottom" : "center"} />}
+71
View File
@@ -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<HTMLElement>("[data-session-message]")];
const own = main.querySelector<HTMLElement>("[data-user-text-bubble] > p")!;
const ownStyle = getComputedStyle(own);
const ownRect = own.getBoundingClientRect();
const threadRow = own.closest<HTMLElement>("[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<HTMLElement>("[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.");
});
}
}
+6 -11
View File
@@ -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 (
<div
data-session-message
className="group relative w-full text-reading"
className="group relative mr-auto w-fit min-w-0 max-w-[min(85%,36rem)] text-reading"
>
{contextMenu}
<div
className="min-w-0 rounded-es-[16px] border-s-2 bg-background pb-1 ps-2.5"
style={{ borderInlineStartColor: color }}
>
<div className="mb-1.5 flex items-center text-[12px] text-muted-foreground">
<SessionHandleLabel id={handle.id}>{handleName}</SessionHandleLabel>
</div>
<div className="mb-1.5 flex items-center px-4 text-[12px] text-muted-foreground">
<SessionHandleLabel id={handle.id}>{handleName}</SessionHandleLabel>
</div>
<div className="relative min-w-0 rounded-floating bg-secondary/70 px-4 py-2">
{contextMenu}
<div data-assistant-selectable="true" className="min-w-0">
<MarkdownText
preserveStreamingLayout
+11 -5
View File
@@ -235,7 +235,7 @@ describe("MessageBubble", () => {
.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(<MessageBubble message={message} />);
const contextMenu = <button data-message-block-menu-trigger>Message actions</button>;
const { container } = render(<MessageBubble message={message} contextMenu={contextMenu} />);
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", () => {