From ae0fde771d8eb499b7e030eccd08a96b2533c6f0 Mon Sep 17 00:00:00 2001 From: "opencode-agent[bot]" <219766164+opencode-agent[bot]@users.noreply.github.com> Date: Thu, 5 Nov 2026 18:52:14 +0000 Subject: [PATCH] feat(session-ui): move user message actions into a chevron menu on each bubble (#60819) Co-authored-by: iamdavidhill <1879069+iamdavidhill@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> --- .../app/e2e/regression/btw-sidebar.spec.ts | 2 +- .../app/e2e/regression/session-header.spec.ts | 19 +- .../app/e2e/regression/session-queue.spec.ts | 34 +- .../e2e/regression/timeline-geometry.spec.ts | 4 +- packages/app/e2e/utils/timeline.ts | 23 +- packages/app/src/runtime/i18n/en.ts | 2 +- .../session-message-projection.spec.ts | 296 ++++++++++++------ .../session-timeline-mobile.spec.ts | 44 ++- .../src/components/message-part.css | 133 ++++++-- .../src/message/current-message.tsx | 12 +- .../src/message/message-content.tsx | 208 ++++++------ .../src/message/prompt-message.stories.tsx | 18 -- .../src/storybook/current-session-story.tsx | 12 +- .../src/timeline/projection.test.ts | 52 --- .../session-ui/src/timeline/projection.ts | 42 --- .../src/timeline/session-timeline-row.tsx | 165 ++++++++-- .../timeline/steer-arrival-machine.test.ts | 35 +++ .../src/timeline/steer-arrival-machine.ts | 26 +- .../src/timeline/timeline-row.stories.tsx | 84 +++++ packages/ui/src/i18n/en.ts | 3 +- 20 files changed, 820 insertions(+), 394 deletions(-) diff --git a/packages/app/e2e/regression/btw-sidebar.spec.ts b/packages/app/e2e/regression/btw-sidebar.spec.ts index 9fab3463316..6ae47c9a64e 100644 --- a/packages/app/e2e/regression/btw-sidebar.spec.ts +++ b/packages/app/e2e/regression/btw-sidebar.spec.ts @@ -225,7 +225,7 @@ test("answers /btw in the side panel without admitting a prompt", async ({ page await expect(panel.getByText("exponential backoff", { exact: false })).toBeVisible() await expect(panel.getByText("const delay = 2 ** attempt", { exact: true })).toBeVisible() await expect(panel.getByRole("button", { name: "Copy message", exact: true })).toHaveCount(1) - await expect(panel.getByRole("button", { name: "Rewind to here", exact: true })).toHaveCount(0) + await expect(panel.getByRole("button", { name: "Revert to here", exact: true })).toHaveCount(0) await expect(panel.getByRole("button", { name: "Copy answer", exact: true })).toHaveCount(1) await expect(panel.locator('[data-slot="text-part-meta"]')).toContainText(/\d+s/) await panel.locator('[data-component="user-message"]').hover() diff --git a/packages/app/e2e/regression/session-header.spec.ts b/packages/app/e2e/regression/session-header.spec.ts index a46def6643b..640a7a59709 100644 --- a/packages/app/e2e/regression/session-header.spec.ts +++ b/packages/app/e2e/regression/session-header.spec.ts @@ -3,6 +3,7 @@ import { expect, test, type Page } from "@playwright/test" import { REMOTE_SERVER, seed, sessionHref } from "../utils/app" import { fixture, mockStressTimeline } from "../utils/session-fixture" import { reviewTabs } from "../utils/side-panel" +import { chooseUserMessageAction, openUserMessageMenu } from "../utils/timeline" import { expectSessionTitle } from "../utils/waits" import { mockRemoteServer, mockWorkspace, openSession } from "../utils/workspace" @@ -724,7 +725,6 @@ test.describe("revert", () => { if (step) settles.push(step) }) const message = page.locator('[data-message-id="msg_second"]') - await message.hover() const response = page.waitForResponse( (response) => @@ -732,7 +732,8 @@ test.describe("revert", () => { new URL(response.url()).pathname === `/api/session/${session.id}/revert/stage`, ) - await message.getByRole("button", { name: "Rewind to here" }).click() + // The newest prompt's revert undoes the last turn. + await chooseUserMessageAction(page, message, "Undo") expect((await response).ok()).toBe(true) await expect(page.getByRole("textbox", { name: "Prompt" })).toHaveText("Second prompt") @@ -741,15 +742,14 @@ test.describe("revert", () => { expect(settles).toEqual(["/interrupt", "/wait", "/revert/stage"]) }) - test("Undo on the Rewound toast clears the revert and puts the draft back before the staged event arrives", async ({ + test("Undo on the Reverted toast clears the revert and puts the draft back before the staged event arrives", async ({ page, }) => { const { session, editor } = await openSession(page, workspace) const prompt = page.getByRole("textbox", { name: "Prompt" }) await editor.pressSequentially("Unsent draft") const message = page.locator('[data-message-id="msg_second"]') - await message.hover() - await message.getByRole("button", { name: "Rewind to here" }).click() + await chooseUserMessageAction(page, message, "Undo") await expect(prompt).toHaveText("Second prompt") const cleared = page.waitForRequest( @@ -821,9 +821,9 @@ test.describe("revert", () => { }) const prompt = page.getByRole("textbox", { name: "Prompt" }) await editor.pressSequentially("Draft in source") + // The session is already reverted to msg_second, so msg_first is the newest prompt left. const message = page.locator('[data-timeline-row="UserMessage"][data-message-id="msg_first"]') - await message.hover() - await message.getByRole("button", { name: "Rewind to here" }).click() + await chooseUserMessageAction(page, message, "Undo") await expect(prompt).toHaveText("First prompt") await tabs(page).filter({ hasText: "Rewind other" }).click() @@ -883,8 +883,7 @@ test.describe("revert", () => { }) await page.goto(sessionHref("ses_child")) await expectSessionTitle(page, "Session message revert") - const message = page.locator('[data-message-id="msg_second"]') - await message.hover() - await expect(message.getByRole("button", { name: "Rewind to here" })).toHaveCount(0) + const menu = await openUserMessageMenu(page, page.locator('[data-message-id="msg_second"]')) + await expect(menu.getByRole("menuitem", { name: /^(Revert to here|Undo)$/ })).toHaveCount(0) }) }) diff --git a/packages/app/e2e/regression/session-queue.spec.ts b/packages/app/e2e/regression/session-queue.spec.ts index f9cc211908d..e032f7c5597 100644 --- a/packages/app/e2e/regression/session-queue.spec.ts +++ b/packages/app/e2e/regression/session-queue.spec.ts @@ -8,6 +8,7 @@ import { Schema } from "effect" import { holdRoute, provider, seed, SERVER } from "../utils/app" import type { MockServerConfig } from "../utils/mock-server" import { installSseTransport } from "../utils/sse-transport" +import { chooseUserMessageAction, openUserMessageMenu } from "../utils/timeline" import { openSession } from "../utils/workspace" const sessionID = "ses_session_queue_regression" @@ -1067,14 +1068,12 @@ test("reverting to another prompt replaces the file chips of an earlier restore" const view = await openQueue(page, mock) const chip = view.composer.locator('[data-slot="composer-context-file"]') - for (const [id, text, chips] of [ - ["msg_queue_second", "Second prompt", 1], - ["msg_queue_first", "First prompt", 0], + // The newest prompt's revert is Undo. The mock never hides the reverted prompt, so the first stays an earlier one. + for (const [id, text, chips, action] of [ + ["msg_queue_second", "Second prompt", 1, "Undo"], + ["msg_queue_first", "First prompt", 0, "Revert to here"], ] as const) { - const row = userRow(page, id) - - await row.hover() - await row.getByRole("button", { name: "Rewind to here" }).click() + await chooseUserMessageAction(page, userRow(page, id), action) await expect(view.input).toHaveText(text) await expect(chip).toHaveCount(chips) } @@ -1120,8 +1119,7 @@ test("reverting a delivered prompt leaves queued prompts alone, as in the TUI", (response) => new URL(response.url()).pathname === `/api/session/${sessionID}/revert/stage`, ) - await delivered.hover() - await delivered.getByRole("button", { name: "Rewind to here" }).click() + await chooseUserMessageAction(page, delivered, "Undo") expect((await staged).ok()).toBe(true) await expect(view.input).toHaveText("First prompt") @@ -1194,9 +1192,9 @@ for (const [action, status] of [ if (status === "steering") await expect(message).toHaveAttribute("data-pending", "true") else await expect(message).not.toHaveAttribute("data-pending") - await pending.hover() - await expect(pending.getByRole("button", { name: "Rewind to here" })).toHaveCount(0) - await pending.getByRole("button", { name: action }).click() + const menu = await openUserMessageMenu(page, pending) + await expect(menu.getByRole("menuitem", { name: /^(Revert to here|Undo)$/ })).toHaveCount(0) + await menu.getByRole("menuitem", { name: action, exact: true }).click() await expect(pending).toHaveCount(0) expect(mock.changes).toEqual([{ inboxID, action: action === "Delete" ? "cancel" : "queue" }]) @@ -1208,7 +1206,7 @@ for (const [action, status] of [ }) } -test("waiting steers group under one Pending line, each keeping its own actions beside its bubble", async ({ +test("waiting steers group under one Pending line, each keeping its own actions in its chevron menu", async ({ page, }) => { const mock = createQueueMock( @@ -1228,8 +1226,8 @@ test("waiting steers group under one Pending line, each keeping its own actions await expect(first.locator('[data-slot="user-message-meta"]')).toBeHidden() await first.locator('[data-slot="user-message-text"]').hover() - await expect(first.locator('[data-slot="user-message-run-actions"]')).toHaveCSS("opacity", "1") - await first.getByRole("button", { name: "Move to queue" }).click() + await expect(first.locator('[data-slot="user-message-menu"]')).toHaveCSS("opacity", "1") + await chooseUserMessageAction(page, first, "Move to queue") await expect.poll(() => mock.changes).toEqual([{ inboxID: mock.rows[0].id, action: "queue" }]) }) @@ -1367,8 +1365,10 @@ for (const delivery of ["steer", "queue"] as const) { await expect(bubble).toHaveCSS("color", colors.pending.text) await expect(bubble).toHaveCSS("transition-duration", "0s") await expect(pending.locator('[data-slot="user-message-copy-wrapper"]')).toHaveCSS("opacity", "1") - // The steer keeps U1's agent and model, so Pending is all its meta line says. - await expect(pending.locator('[data-slot="user-message-meta"]')).toHaveText(/^Pending$/, { useInnerText: true }) + // Pending closes the meta line, after the agent and model that show on hover. + await expect(pending.locator('[data-slot="user-message-meta"]')).toHaveText(/^Queue Model\s*·\s*Pending$/, { + useInnerText: true, + }) await bubble.evaluate((element) => (element.dataset.deliveryMarker = "pending")) } diff --git a/packages/app/e2e/regression/timeline-geometry.spec.ts b/packages/app/e2e/regression/timeline-geometry.spec.ts index 8f90e659574..4e19574c8ec 100644 --- a/packages/app/e2e/regression/timeline-geometry.spec.ts +++ b/packages/app/e2e/regression/timeline-geometry.spec.ts @@ -884,9 +884,9 @@ test("groups consecutive sent prompts under the last one's meta line, with each await expect(first.locator('[data-slot="user-message-copy-wrapper"]')).toBeHidden() await expect(last.locator('[data-slot="user-message-copy-wrapper"]')).toBeVisible() - // The first message keeps its own actions, shown beside its bubble on hover. + // The first message keeps its own actions, in a chevron its bubble shows on hover. await bubble(first).hover() - await expect(first.locator('[data-slot="user-message-run-actions"]')).toHaveCSS("opacity", "1") + await expect(first.locator('[data-slot="user-message-menu"]')).toHaveCSS("opacity", "1") await expect(first.getByRole("button", { name: "More actions" })).toHaveCount(1) }) diff --git a/packages/app/e2e/utils/timeline.ts b/packages/app/e2e/utils/timeline.ts index 5a8ae0fd5b8..bfedc7ba936 100644 --- a/packages/app/e2e/utils/timeline.ts +++ b/packages/app/e2e/utils/timeline.ts @@ -11,7 +11,7 @@ import type { import { EventManifest } from "@opencode/schema/event-manifest" import { SessionMessage } from "@opencode/schema/session-message" import type { TimelineDetail } from "@opencode/session-ui/timeline/detail" -import { expect, test, type Page, type TestInfo } from "@playwright/test" +import { expect, test, type Locator, type Page, type TestInfo } from "@playwright/test" import { Schema } from "effect" import { SERVER, seed, sessionHref } from "./app" import { mockOpenCodeServer, type MockServerConfig } from "./mock-server" @@ -1117,3 +1117,24 @@ function provider() { default: { providerID: "opencode", modelID: "claude-opus-4-6" }, } } + +/** Hovers a user message, opens the chevron menu its bubble (or, without text, its footer) shows, and picks an action. */ +export async function chooseUserMessageAction(page: Page, row: Locator, name: string) { + const bubble = row.locator('[data-slot="user-message-text"]') + + if ((await bubble.count()) > 0) await bubble.hover() + else await row.locator('[data-component="user-message"]').hover() + await row.getByRole("button", { name: "More actions", exact: true }).click() + await page.getByRole("menuitem", { name, exact: true }).click() +} + +/** Hovers a user message, opens its chevron menu, and returns the open menu. */ +export async function openUserMessageMenu(page: Page, row: Locator) { + const bubble = row.locator('[data-slot="user-message-text"]') + + if ((await bubble.count()) > 0) await bubble.hover() + else await row.locator('[data-component="user-message"]').hover() + await row.getByRole("button", { name: "More actions", exact: true }).click() + + return page.getByRole("menu") +} diff --git a/packages/app/src/runtime/i18n/en.ts b/packages/app/src/runtime/i18n/en.ts index e37694393de..369faacd26e 100644 --- a/packages/app/src/runtime/i18n/en.ts +++ b/packages/app/src/runtime/i18n/en.ts @@ -24,7 +24,7 @@ export const dict = { "session.location.choose": "Choose directory", "session.location.worktree": "Choose worktree", "session.location.worktreesFailed": "Failed to load worktrees", - "session.rewind.toast.title": "Rewound", + "session.rewind.toast.title": "Reverted", "session.rewind.toast.undo": "Undo", "session.location.moving": "Moving session…", "session.location.moveFailed": "Failed to move session", diff --git a/packages/session-ui/component-tests/session-message-projection.spec.ts b/packages/session-ui/component-tests/session-message-projection.spec.ts index dbbd89a47d7..cc1ca0535f6 100644 --- a/packages/session-ui/component-tests/session-message-projection.spec.ts +++ b/packages/session-ui/component-tests/session-message-projection.spec.ts @@ -69,113 +69,217 @@ story("keeps quote attachment icons fixed while long text truncates", async ({ m story.describe("message actions menu", () => { story.use({ timezoneId: "UTC" }) - story("shows the creation time and disables actions the message cannot take", async ({ mount, page }) => { - const timeline = await mount("current-prompt-message--pending") - const message = timeline.locator('[data-component="user-message"]') - const more = timeline.getByRole("button", { name: "More actions", exact: true }) - const fork = page.getByRole("menuitem", { name: "Fork from here", exact: true }) - const copy = page.getByRole("menuitem", { name: "Copy message", exact: true }) + story( + "opens from a chevron in the bubble with the send time and the actions the message can take", + async ({ mount, page }) => { + const timeline = await mount("current-prompt-message--pending") + const chevron = timeline.locator('[data-slot="user-message-menu"]') + const more = timeline.getByRole("button", { name: "More actions", exact: true }) + const fork = page.getByRole("menuitem", { name: "Fork from here", exact: true }) + const copy = page.getByRole("menuitem", { name: "Copy message", exact: true }) + const revert = page.getByRole("menuitem", { name: "Revert to here", exact: true }) + const remove = page.getByRole("menuitem", { name: "Delete", exact: true }) - // The meta line keeps agent and model; the time moved into the menu. - await expect(timeline.locator('[data-slot="user-message-meta"] time')).toHaveCount(0) + // The meta line keeps agent and model; the time lives in the menu. + await expect(timeline.locator('[data-slot="user-message-meta"] time')).toHaveCount(0) - await timeline.getByLabel("Delivery state").selectOption("delivered") - await message.hover() - await expect(timeline.getByRole("button", { name: "Rewind to here", exact: true })).toBeVisible() + const bubble = timeline.locator('[data-slot="user-message-text"]') + await timeline.getByLabel("Delivery state").selectOption("delivered") + await page.mouse.move(0, 0) + await expect(chevron).toHaveCSS("opacity", "0") + await bubble.hover() + await expect(chevron).toHaveCSS("opacity", "1") + await more.click() + const menu = page.getByRole("menu") + await expect(menu.locator("time")).toHaveText("Jan 1, 2025, 12:00 AM") + await expect(fork).toBeEnabled() + await expect(copy).toBeEnabled() + await expect(revert).toBeEnabled() + // An open menu keeps its chevron in view after the pointer leaves the message. + await page.mouse.move(0, 0) + await expect(chevron).toHaveCSS("opacity", "1") + await page.keyboard.press("Escape") + await expect(menu).toBeHidden() + // The menu hands focus back without a ring, so the chevron hides once the pointer is away. + await expect(more).toBeFocused() + await expect(chevron).toHaveCSS("opacity", "0") + + // A pending steer is queued or deleted rather than reverted, and has no history to fork; a message without text has + // nothing to copy. + await timeline.getByLabel("Delivery state").selectOption("steering") + await timeline.getByLabel("Prompt text", { exact: true }).uncheck() + // Without a bubble, the chevron sits in the footer and shows while the message is hovered. + await timeline.locator('[data-component="user-message"]').hover() + await more.click() + await expect(page.getByRole("menuitem", { name: "Move to queue", exact: true })).toBeEnabled() + await expect(fork).toHaveCount(0) + await expect(copy).toHaveAttribute("aria-disabled", "true") + await expect(revert).toHaveCount(0) + await expect(remove).toBeEnabled() + await page.keyboard.press("Escape") + + await timeline.getByLabel("Prompt text", { exact: true }).check() + await timeline.getByLabel("Delivery state").selectOption("delivered") + await page.evaluate(() => document.fonts.ready.then(() => undefined)) + + for (const width of [1000, 390]) { + await page.setViewportSize({ width, height: 844 }) + await bubble.hover() + const box = await bubble.boundingBox() + const trigger = await more.boundingBox() + const lineHeight = await bubble.evaluate((element) => parseFloat(getComputedStyle(element).lineHeight)) + + if (!box || !trigger) throw new Error("Message geometry is unavailable") + // Pinned to the bubble's top trailing corner, centered on its first line, as far from the side as from the top. + expect(Math.abs(box.y + 8 + lineHeight / 2 - trigger.y - trigger.height / 2)).toBeLessThan(1) + expect(Math.abs(box.x + box.width - trigger.x - trigger.width - (trigger.y - box.y))).toBeLessThan(1) + } + }, + ) + + story("opens upward, 4px from the chevron, with its trailing edge on the chevron's", async ({ mount, page }) => { + const timeline = await mount("current-session-timeline-rows--prompt-runs") + await timeline.getByRole("button", { name: "Send next", exact: true }).click() + const message = timeline.locator('[data-component="user-message"]').first() + await message.locator('[data-slot="user-message-text"]').hover() + const more = message.getByRole("button", { name: "More actions", exact: true }) + // An open menu hides the rest of the page from the accessibility tree, so measure the trigger first. + const trigger = await more.boundingBox() await more.click() - const menu = page.getByRole("menu") - await expect(menu.locator("time")).toHaveText("Jan 1, 2025, 12:00 AM") - await expect(fork).toBeEnabled() - await expect(copy).toBeEnabled() - // An open menu keeps the footer in view after the pointer leaves the message. - await page.mouse.move(0, 0) - await expect(timeline.locator('[data-slot="user-message-copy-wrapper"]')).toHaveCSS("opacity", "1") - await page.keyboard.press("Escape") - await expect(menu).toBeHidden() + const menu = page.locator('[data-component="menu-v2-content"]') + await expect(menu).toBeVisible() + const box = await menu.boundingBox() - // A pending steer cannot fork, and a message without text has nothing to copy. - await timeline.getByLabel("Delivery state").selectOption("steering") - await timeline.getByLabel("Prompt text", { exact: true }).uncheck() - await more.click() - await expect(fork).toHaveAttribute("aria-disabled", "true") - await expect(copy).toHaveAttribute("aria-disabled", "true") - await page.keyboard.press("Escape") - - await timeline.getByLabel("Prompt text", { exact: true }).check() - await timeline.getByLabel("Delivery state").selectOption("delivered") - await page.evaluate(() => document.fonts.ready.then(() => undefined)) - - for (const width of [1000, 390]) { - await page.setViewportSize({ width, height: 844 }) - const bubble = await timeline.locator('[data-slot="user-message-text"]').boundingBox() - const trigger = await more.boundingBox() - const footer = await timeline.locator('[data-slot="user-message-copy-wrapper"]').boundingBox() - const box = await message.boundingBox() - - if (!bubble || !trigger || !footer || !box) throw new Error("Message geometry is unavailable") - expect(Math.abs(bubble.x + bubble.width - box.x - box.width)).toBeLessThan(1) - expect(footer.y).toBeGreaterThanOrEqual(bubble.y + bubble.height) - expect(footer.x + footer.width).toBeLessThanOrEqual(bubble.x + bubble.width + 1) - expect(Math.abs(trigger.x + trigger.width - footer.x - footer.width)).toBeLessThan(1) - expect(Math.abs(trigger.y + trigger.height / 2 - footer.y - footer.height / 2)).toBeLessThan(1) - } + if (!trigger || !box) throw new Error("Menu geometry is unavailable") + expect(Math.abs(trigger.y - box.y - box.height - 4)).toBeLessThan(1) + expect(Math.abs(trigger.x + trigger.width - box.x - box.width)).toBeLessThan(1) }) }) -story("keeps the footer in view while an outside click closes the actions menu", async ({ mount, page }) => { - const timeline = await mount("current-prompt-message--pending") - const footer = timeline.locator('[data-slot="user-message-copy-wrapper"]') +story( + "fades the footer and chevron out once, without flicker, as an outside click closes the menu", + async ({ mount, page }) => { + // The timeline keeps a run's meta line shown while one of its menus is open, so mount it rather than a bare message. + const timeline = await mount("current-session-timeline-rows--prompt-runs") + const message = timeline.locator('[data-component="user-message"]').first() - await timeline.getByLabel("Delivery state").selectOption("delivered") - await timeline.locator('[data-component="user-message"]').hover() - await timeline.getByRole("button", { name: "More actions", exact: true }).click() - await expect(page.getByRole("menu")).toBeVisible() - await page.mouse.move(0, 0) + await message.locator('[data-slot="user-message-text"]').hover() + await message.getByRole("button", { name: "More actions", exact: true }).click() + await expect(page.getByRole("menu")).toBeVisible() + await page.mouse.move(0, 0) - // Kobalte drops the expanded state a task before it returns focus to the trigger, so record every frame from the - // click until a few frames after the menu has gone rather than the settled state. - const frames = await footer.evaluateHandle((element) => { - const opacities: string[] = [] - const closed = { frames: 0 } + // Kobalte drops the expanded state a task before it returns focus to the trigger, so record every frame from the + // click until well after the menu has gone rather than the settled state. + const frames = await message.evaluateHandle((element) => { + const slots = ["user-message-copy-wrapper", "user-message-menu"] + const samples = slots.map((): number[] => []) + const closed = { frames: 0 } - const done = new Promise((resolve) => { - const tick = () => { - opacities.push(getComputedStyle(element).opacity) + const done = new Promise((resolve) => { + const tick = () => { + slots.forEach((slot, index) => { + const target = element.querySelector(`[data-slot="${slot}"]`) + samples[index]!.push(target ? parseFloat(getComputedStyle(target).opacity) : 0) + }) - if (!document.querySelector('[role="menu"]')) closed.frames += 1 + if (!document.querySelector('[role="menu"]')) closed.frames += 1 - if (closed.frames < 5) return requestAnimationFrame(tick) + if (closed.frames < 30) return requestAnimationFrame(tick) - resolve(opacities) - } + resolve(samples) + } - requestAnimationFrame(tick) + requestAnimationFrame(tick) + }) + + return { done } }) - return { done } - }) + await page.mouse.click(0, 0) + const samples = await frames.evaluate((sampler) => sampler.done) - await page.mouse.click(0, 0) - expect(new Set(await frames.evaluate((sampler) => sampler.done))).toEqual(new Set(["1"])) -}) + // Each starts shown and only ever fades: no frame comes back up after a lower one. + samples.forEach((opacities) => { + expect(opacities[0]).toBe(1) + expect(opacities.every((value, index) => index === 0 || value <= opacities[index - 1]!)).toBe(true) + }) + }, +) -story("keeps pending steer actions usable after a request fails", async ({ mount }) => { +story("keeps pending steer actions usable after a request fails", async ({ mount, page }) => { const timeline = await mount("current-prompt-message--pending") - const queue = timeline.getByRole("button", { name: "Move to queue", exact: true }) - const remove = timeline.getByRole("button", { name: "Delete", exact: true }) + const more = timeline.getByRole("button", { name: "More actions", exact: true }) + const queue = page.getByRole("menuitem", { name: "Move to queue", exact: true }) + const remove = page.getByRole("menuitem", { name: "Delete", exact: true }) const failures = timeline.getByLabel("Failed actions") + const bubble = timeline.locator('[data-slot="user-message-text"]') + + // The chevron shows only while its bubble is hovered, and a closing menu leaves the pointer over the menu's place. + const open = async () => { + await bubble.hover() + await more.click() + } await timeline.getByLabel("Actions fail").check() - await timeline.locator('[data-component="user-message"]').hover() + await open() await queue.click() await expect(failures).toHaveText("1") + await open() await expect(queue).toBeEnabled() await expect(remove).toBeEnabled() await remove.click() await expect(failures).toHaveText("2") + await open() await expect(remove).toBeEnabled() }) +story("shows a run's meta line while the pointer is anywhere in the run, gaps included", async ({ mount, page }) => { + const timeline = await mount("current-session-timeline-rows--prompt-runs") + const send = timeline.getByRole("button", { name: "Send next", exact: true }) + await send.click() + await send.click() + const bubbles = timeline.locator('[data-slot="user-message-text"]') + await expect(bubbles).toHaveCount(3) + + const footer = timeline + .locator('[data-component="user-message"]') + .last() + .locator('[data-slot="user-message-copy-wrapper"]') + + await page.mouse.move(0, 0) + await expect(footer).toHaveCSS("opacity", "0") + await bubbles.first().hover() + await expect(footer).toHaveCSS("opacity", "1") + + // The 4px gap between two bubbles belongs to the run, so crossing it keeps the line. + const above = await bubbles.nth(0).boundingBox() + const below = await bubbles.nth(1).boundingBox() + + if (!above || !below) throw new Error("Run geometry is unavailable") + await page.mouse.move(below.x + below.width / 2, (above.y + above.height + below.y) / 2) + await expect(footer).toHaveCSS("opacity", "1") + await page.mouse.move(0, 0) + await expect(footer).toHaveCSS("opacity", "0") +}) + +story("names the newest prompt's revert Undo and earlier ones Revert to here", async ({ mount, page }) => { + const timeline = await mount("current-session-timeline-rows--prompt-runs") + await timeline.getByRole("button", { name: "Send next", exact: true }).click() + const messages = timeline.locator('[data-component="user-message"]') + await expect(messages).toHaveCount(2) + + for (const [index, label] of [ + [1, "Undo"], + [0, "Revert to here"], + ] as const) { + await messages.nth(index).locator('[data-slot="user-message-text"]').hover() + await messages.nth(index).getByRole("button", { name: "More actions", exact: true }).click() + await expect(page.getByRole("menuitem", { name: label, exact: true })).toBeVisible() + await expect(page.getByRole("menuitem", { name: index ? "Revert to here" : "Undo", exact: true })).toHaveCount(0) + await page.keyboard.press("Escape") + } +}) + story("drops a pending footer at once on delivery with and without hover", async ({ mount, page }) => { const timeline = await mount("current-prompt-message--pending") const message = timeline.locator('[data-component="user-message"]') @@ -185,8 +289,8 @@ story("drops a pending footer at once on delivery with and without hover", async await page.mouse.move(0, 0) await expect(footer).toHaveCSS("height", "20px") await expect(footer).toHaveCSS("margin-top", "8px") - // A steer names only the model it changes, so change it to measure the gap after the labels. - await timeline.getByLabel("Changes model", { exact: true }).check() + const bubble = timeline.locator('[data-slot="user-message-text"]') + const labels = timeline.locator('[data-slot="user-message-meta-label"]') for (const hover of [true, false]) { await timeline.getByLabel("Delivery state").selectOption("steering") @@ -196,14 +300,15 @@ story("drops a pending footer at once on delivery with and without hover", async if (!before) throw new Error("Pending footer geometry is unavailable") - if (hover) await message.hover() + if (hover) await bubble.hover() if (!hover) await page.mouse.move(0, 0) - const label = await timeline.locator('[data-slot="user-message-meta-item"]').last().boundingBox() - const actions = await timeline.locator('[data-slot="user-message-actions"]').boundingBox() + // Pending closes the line, and the agent and model before it show only on hover. + await expect(labels).toHaveCSS("opacity", hover ? "1" : "0") + const line = await footer.boundingBox() - if (!label || !actions) throw new Error("Pending footer geometry is unavailable") - expect(actions.x - label.x - label.width).toBeLessThanOrEqual(9) + if (!line) throw new Error("Pending footer geometry is unavailable") + expect(Math.abs(before.x + before.width - line.x - line.width)).toBeLessThan(1) await timeline.getByLabel("Delivery state").selectOption("delivered") // The first frame after delivery already shows the delivered footer: nothing shrinks or fades out. @@ -252,7 +357,7 @@ story("marks pending metadata without badging delivered, starting, or queued pro if (!pending) await expect(indicator).toBeHidden() // A prompt still sending has no server row, so it offers no action until the server has it. - await expect(timeline.locator('[data-slot="user-message-actions"]')).toHaveCount(status === "sending" ? 0 : 1) + await expect(timeline.locator('[data-slot="user-message-menu"]')).toHaveCount(status === "sending" ? 0 : 1) const colors = await timeline.evaluate((element, pending) => { const probe = document.createElement("span") @@ -269,7 +374,7 @@ story("marks pending metadata without badging delivered, starting, or queued pro await expect(text).toHaveCSS("background-color", colors.background) } - await timeline.locator('[data-component="user-message"]').hover() + await text.hover() await expect(timeline.locator('[data-slot="user-message-meta-item"]')).toHaveText([ "Build", "Claude Sonnet 4", @@ -279,12 +384,16 @@ story("marks pending metadata without badging delivered, starting, or queued pro await expect(separator).toHaveText("\u00B7") await expect(timeline.locator('[data-slot="user-message-meta-label"]')).toHaveCSS("gap", "4px") - // A steer with the previous prompt's agent and model joins the running turn unchanged, so it names neither. + // A steer reads agent · model · Pending. Pending stays in view; the agent and model show on hover, as on any message. await timeline.getByLabel("Delivery state").selectOption("steering") - await expect(timeline.locator('[data-slot="user-message-meta"]')).toHaveText(/^Pending$/, { useInnerText: true }) - await expect(timeline.locator('[data-slot="user-message-meta-item"]')).toHaveCount(0) - await timeline.getByLabel("Changes model", { exact: true }).check() - await expect(timeline.locator('[data-slot="user-message-meta-item"]')).toHaveText(["Claude Sonnet 4", "Balanced"]) + await expect(timeline.locator('[data-slot="user-message-meta"]')).toHaveText( + /^Build\s*·\s*Claude Sonnet 4\s*Balanced\s*·\s*Pending$/, + { useInnerText: true }, + ) + await expect(timeline.locator('[data-slot="user-message-meta-label"]')).toHaveCSS("opacity", "1") + await page.mouse.move(0, 0) + await expect(timeline.locator('[data-slot="user-message-meta-label"]')).toHaveCSS("opacity", "0") + await expect(indicator).toBeVisible() await timeline.getByLabel("Voice message", { exact: true }).check() const voice = timeline.getByRole("img", { name: "Voice", exact: true }) await expect(voice).toBeVisible() @@ -299,7 +408,7 @@ story("marks pending metadata without badging delivered, starting, or queued pro await expect(voice.locator('[data-slot="icon-svg"]')).toHaveCSS("width", "14px") await expect(voice.locator('[data-slot="icon-svg"]')).toHaveCSS("height", "14px") - await expect(timeline.locator('[data-slot="user-message-meta"]')).toHaveText(/^Pending/) + await expect(timeline.locator('[data-slot="user-message-meta"]')).toHaveText(/Pending$/) await timeline.getByLabel("Grouped prompts", { exact: true }).check() await expect(timeline.locator('[data-run-folded] [data-slot="user-message-copy-wrapper"]')).toBeHidden() await expect( @@ -313,7 +422,10 @@ story("marks pending metadata without badging delivered, starting, or queued pro await timeline.getByLabel("Prompt text", { exact: true }).uncheck() await expect(timeline.getByText("notes.json", { exact: true })).toBeVisible() await expect(indicator).toBeVisible() - await timeline.getByRole("button", { name: "Move to queue", exact: true }).click() + // A steer without text offers its actions from a chevron in its footer. + await timeline.locator('[data-component="user-message"]').hover() + await timeline.getByRole("button", { name: "More actions", exact: true }).click() + await page.getByRole("menuitem", { name: "Move to queue", exact: true }).click() await expect(indicator).toBeHidden() }) diff --git a/packages/session-ui/component-tests/session-timeline-mobile.spec.ts b/packages/session-ui/component-tests/session-timeline-mobile.spec.ts index 231849aa13f..2953d367c8f 100644 --- a/packages/session-ui/component-tests/session-timeline-mobile.spec.ts +++ b/packages/session-ui/component-tests/session-timeline-mobile.spec.ts @@ -8,7 +8,7 @@ story.describe("touch timeline", () => { expect(await page.evaluate(() => matchMedia("(hover: none)").matches)).toBe(true) for (const action of [ - { slot: "user-message-copy-wrapper", name: "More actions" }, + { slot: "user-message-menu", name: "More actions" }, { slot: "text-part-copy-wrapper", name: "Copy response" }, ]) { const actions = timeline.locator(`[data-slot="${action.slot}"]`) @@ -29,6 +29,46 @@ story.describe("touch timeline", () => { await expect(responseMeta.locator('[data-slot="text-part-meta-speed"]')).toBeHidden() }) + story("keeps the always-shown chevron clear of the prompt's text", async ({ mount }) => { + const timeline = await mount("current-prompt-message--pending") + await timeline.getByLabel("Delivery state").selectOption("delivered") + const bubble = timeline.locator('[data-slot="user-message-text"]') + await expect(bubble.getByRole("button", { name: "More actions", exact: true })).toBeVisible() + + // Every rendered line box of the prompt, against the chevron's box: none may overlap. + const overlaps = await bubble.evaluate((element) => { + const menu = element.querySelector('[data-slot="user-message-menu"]') + const chevron = menu?.querySelector("button")?.getBoundingClientRect() + + if (!menu || !chevron) throw new Error("The chevron is not rendered") + + const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT, { + acceptNode: (node) => (menu.contains(node) ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT), + }) + + const lines: DOMRect[] = [] + + for (let node = walker.nextNode(); node; node = walker.nextNode()) { + const range = document.createRange() + range.selectNodeContents(node) + lines.push(...range.getClientRects()) + } + + if (lines.length === 0) throw new Error("The prompt has no text") + + return lines.filter( + (line) => + line.width > 0 && + line.left < chevron.right && + line.right > chevron.left && + line.top < chevron.bottom && + line.bottom > chevron.top, + ).length + }) + + expect(overlaps).toBe(0) + }) + story("keeps shell copy visible without hover", async ({ mount }) => { const timeline = await mount("current-session-terminal-work--expanded-shell") const copy = timeline.locator('[data-slot="bash-copy"]') @@ -63,7 +103,7 @@ story("desktop message actions still appear on hover and keyboard focus", async expect(await page.evaluate(() => matchMedia("(hover: hover)").matches)).toBe(true) for (const action of [ - { slot: "user-message-copy-wrapper", name: "More actions" }, + { slot: "user-message-menu", name: "More actions" }, { slot: "text-part-copy-wrapper", name: "Copy response" }, ]) { const actions = timeline.locator(`[data-slot="${action.slot}"]`) diff --git a/packages/session-ui/src/components/message-part.css b/packages/session-ui/src/components/message-part.css index e120641612c..09825d29d9d 100644 --- a/packages/session-ui/src/components/message-part.css +++ b/packages/session-ui/src/components/message-part.css @@ -277,7 +277,7 @@ gap: 8px; width: 100%; - /* Hover actions show and hide at once, without a fade. */ + /* The meta line shows and hides at once, together with the chevron. */ @media (hover: hover) { opacity: 0; pointer-events: none; @@ -362,14 +362,6 @@ } } - [data-slot="user-message-actions"] { - --user-message-transition-gap: 6px; - display: inline-flex; - flex: none; - align-items: center; - gap: 6px; - } - [data-slot="user-message-transition"] { display: inline-grid; grid-template-columns: 0fr; @@ -416,27 +408,79 @@ } } - &:hover [data-slot="user-message-copy-wrapper"], - &:focus-within [data-slot="user-message-copy-wrapper"], + /* A closed menu hands focus back without a ring, so only keyboard focus keeps the meta line shown. */ + &:has([data-slot="user-message-body"]:hover) [data-slot="user-message-copy-wrapper"], + &:not(:has([data-slot="user-message-body"])):hover [data-slot="user-message-copy-wrapper"], + /* A footer holding its own buttons, as the /btw panel's does, stays reachable anywhere over the message. */ + &:has([data-slot="user-message-copy-wrapper"] button):hover [data-slot="user-message-copy-wrapper"], + &:has(:focus-visible) [data-slot="user-message-copy-wrapper"], [data-slot="user-message-copy-wrapper"]:has([data-expanded], [data-closing]), - &:hover [data-slot="user-message-meta-tail"], - &:focus-within [data-slot="user-message-meta-tail"] { + &:has([data-slot="user-message-body"]:hover) [data-slot="user-message-meta-tail"], + &:has([data-slot="user-message-copy-wrapper"] button):hover [data-slot="user-message-meta-tail"], + &:has(:focus-visible) [data-slot="user-message-meta-tail"] { opacity: 1; pointer-events: auto; } - /* A pending steer keeps its Pending label and actions in view. */ + /* A run's last message carries the whole run's agent and model, so hovering anywhere in the run shows it. */ + &[data-run-hovered] [data-slot="user-message-copy-wrapper"] { + opacity: 1; + pointer-events: auto; + } + + /* A pending steer keeps its Pending label in view. */ &[data-pending] [data-slot="user-message-copy-wrapper"] { opacity: 1; pointer-events: auto; } + /* Its agent and model show on hover, like any other message's meta line. */ + @media (hover: hover) { + &[data-pending] { + [data-slot="user-message-meta-label"], + [data-slot="user-message-pending-separator"] { + opacity: 0; + } + } + + &[data-pending]:has([data-slot="user-message-body"]:hover), + &[data-pending]:not(:has([data-slot="user-message-body"])):hover, + &[data-pending]:has(:focus-visible), + &[data-pending][data-run-hovered] { + [data-slot="user-message-meta-label"], + [data-slot="user-message-pending-separator"] { + opacity: 1; + } + } + } + [data-slot="user-message-copy-wrapper"] > * { opacity: var(--user-run-meta, 1); } - /* The last message of a run carries the meta line; the others fold theirs away and offer their actions beside - the bubble. */ + /* The bubbles of a run and the gaps between them are one hover zone: each body reaches across the 4px gap to its + neighbor, so the pointer never falls between them. */ + [data-slot="user-message-body"] { + position: relative; + } + + &[data-run-above] [data-slot="user-message-body"]::before, + &[data-run-folded] [data-slot="user-message-body"]::after { + content: ""; + position: absolute; + inset-inline: 0; + height: 4px; + } + + &[data-run-above] [data-slot="user-message-body"]::before { + bottom: 100%; + } + + &[data-run-folded] [data-slot="user-message-body"]::after { + top: 100%; + } + + /* The last message of a run carries the meta line; the others fold theirs away. */ &[data-run-folded] { [data-slot="user-message-body"] { position: relative; @@ -452,13 +496,27 @@ visibility: hidden; } - [data-slot="user-message-run-actions"] { + /* Every bubble offers its actions from a chevron pinned to its top trailing corner, centered on the first line. + The bubble color fades in behind it so text under the corner never competes with the control. */ + [data-slot="user-message-text"] { + --user-message-bubble: var(--v2-background-bg-layer-02); + position: relative; + } + + /* Inset from the trailing edge by the same distance as from the top. */ + [data-slot="user-message-menu"] { + --user-message-menu-inset: calc(8px + (1lh - 20px) / 2); position: absolute; - /* Centered on the bubble's last line. */ - bottom: calc(8px + (1lh - 20px) / 2); - inset-inline-end: calc(100% + 4px); + top: var(--user-message-menu-inset); + inset-inline-end: var(--user-message-menu-inset); display: flex; - align-items: center; + padding-inline-start: 16px; + background: linear-gradient(to left, var(--user-message-bubble) calc(100% - 16px), transparent); + border-radius: 4px; + + &:dir(rtl) { + background: linear-gradient(to right, var(--user-message-bubble) calc(100% - 16px), transparent); + } @media (hover: hover) { opacity: 0; @@ -466,9 +524,35 @@ } } - &:hover [data-slot="user-message-run-actions"], - &:focus-within [data-slot="user-message-run-actions"], - [data-slot="user-message-run-actions"]:has([data-expanded], [data-closing]) { + /* Without hover the chevron always shows, so the first line keeps room for it instead of fading text under it. The + float also widens a short bubble, so a one-word prompt stays readable. 20px spans the 20px button, less the 12px + text padding it overlaps, plus a 4px gap at the 8px inset. */ + @media not (hover: hover) { + [data-slot="user-message-text"]:has(> [data-slot="user-message-menu"])::before { + content: ""; + float: inline-end; + width: 20px; + height: 1lh; + } + + [data-slot="user-message-text"] > [data-slot="user-message-menu"] { + padding: 0; + background: none; + } + } + + [data-slot="user-message-copy-wrapper"] [data-slot="user-message-menu"] { + position: static; + padding: 0; + background: none; + } + + /* Only the bubble itself shows its chevron; a message without one shows it in its footer on hover. A closed menu hands + focus back without a ring, so only keyboard focus keeps the chevron shown. */ + [data-slot="user-message-text"]:hover [data-slot="user-message-menu"], + &:not(:has([data-slot="user-message-text"])):hover [data-slot="user-message-menu"], + &:has(:focus-visible) [data-slot="user-message-menu"], + [data-slot="user-message-menu"]:has([data-expanded], [data-closing]) { opacity: 1; pointer-events: auto; } @@ -1885,6 +1969,7 @@ /* Only delivery animates. A steer can render once before its admission marks it pending, and must not fade from the delivered color. */ :root body [data-component="user-message"][data-pending] [data-slot="user-message-text"] { + --user-message-bubble: var(--v2-background-bg-layer-01); background: var(--v2-background-bg-layer-01); color: var(--v2-text-text-muted); transition: none; diff --git a/packages/session-ui/src/message/current-message.tsx b/packages/session-ui/src/message/current-message.tsx index ce8bbf2b91c..dc0197d186d 100644 --- a/packages/session-ui/src/message/current-message.tsx +++ b/packages/session-ui/src/message/current-message.tsx @@ -27,10 +27,13 @@ export function SessionUserMessage(props: { voice?: boolean historicalAgent: string historicalModel: SessionMessageAssistant["model"] - /** The agent and model the previous prompt chose; a waiting steer names only what it changes. */ - previousSelection?: { agent: string; model: SessionMessageAssistant["model"] } actions?: SessionUserActions run?: UserRun + /** The newest delivered prompt, whose revert undoes the last turn. */ + latest?: boolean + runSnaps?: () => boolean + runHovered?: boolean + onMenuOpenChange?: (open: boolean) => void fold?: boolean expanded?: boolean onExpandedChange?: (expanded: boolean) => void @@ -45,9 +48,12 @@ export function SessionUserMessage(props: { voice={props.voice} agent={props.historicalAgent} model={props.historicalModel} - previousSelection={props.previousSelection} actions={props.actions} run={props.run} + latest={props.latest} + runSnaps={props.runSnaps} + runHovered={props.runHovered} + onMenuOpenChange={props.onMenuOpenChange} fold={props.fold} expanded={props.expanded} onExpandedChange={props.onExpandedChange} diff --git a/packages/session-ui/src/message/message-content.tsx b/packages/session-ui/src/message/message-content.tsx index 7fec66e42c0..43dd7c6e248 100644 --- a/packages/session-ui/src/message/message-content.tsx +++ b/packages/session-ui/src/message/message-content.tsx @@ -105,10 +105,6 @@ function modelItems(data: ReturnType, model: SessionMessageAssis return [{ label: name }, { label: model.variant[0]?.toUpperCase() + model.variant.slice(1), variant: true }] } -function sameModel(a: SessionMessageAssistant["model"], b: SessionMessageAssistant["model"]) { - return a.providerID === b.providerID && a.id === b.id && (a.variant ?? "default") === (b.variant ?? "default") -} - function MetaItems(props: { items: MetaItem[]; slot: "user-message" | "text-part" }) { return ( @@ -134,7 +130,7 @@ function MetaItems(props: { items: MetaItem[]; slot: "user-message" | "text-part function MessageActionButton( props: Pick, "disabled" | "onMouseDown" | "onClick" | "aria-label"> & { - icon: "check" | "copy" | "reset" | "fork" | "arrow-down-to-line" | "outline-trash" + icon: "check" | "copy" label: JSX.Element size?: "small" | "normal" }, @@ -260,13 +256,19 @@ export function CurrentUserMessageDisplay(props: { text: string agent: string model: SessionMessageAssistant["model"] - /** The agent and model the previous prompt chose; a waiting steer names only what it changes. */ - previousSelection?: { agent: string; model: SessionMessageAssistant["model"] } actions?: SessionUserActions comments?: SessionUserComment[] references?: SessionUserAttachmentReference[] voice?: boolean run?: UserRun + /** The newest delivered prompt, whose revert undoes the last turn. */ + latest?: boolean + /** Whether run changes snap now, while a message arrives, rather than spring. Omitted, folding always snaps. */ + runSnaps?: () => boolean + /** The pointer is somewhere in this message's run, so its last bubble shows the run's meta line. */ + runHovered?: boolean + /** An open menu keeps its run's meta line in view while the pointer is on the menu. */ + onMenuOpenChange?: (open: boolean) => void /** Folds a long message to its first lines with a Read more toggle. Omitted, the message always shows in full. */ fold?: boolean /** Whether a folded message is open. The timeline owns it so it survives row recycling. */ @@ -298,12 +300,6 @@ export function CurrentUserMessageDisplay(props: { const agents = createMemo(() => props.message.agents ?? []) const comments = createMemo(() => props.comments ?? []) - const sent = createMemo(() => - new Intl.DateTimeFormat(i18n.locale(), { dateStyle: "medium", timeStyle: "short" }).format( - props.message.time.created, - ), - ) - // Mobile shows the current agent and model in the composer and switch notices, so repeating them per message is noise. const mobile = createMediaQuery("(max-width: 767px)") @@ -313,27 +309,35 @@ export function CurrentUserMessageDisplay(props: { return agent ? [{ label: agent }] : [] }) - // A waiting steer joins the running turn, so its agent and model only say something when it changes them. - const changedLabels = createMemo(() => { - const previous = props.previousSelection + // The menu names the day relatively: Today and Yesterday, then the date this year, then the date with its year. + const sent = createMemo(() => { + const created = new Date(props.message.time.created) + const now = new Date() + const midnight = (date: Date) => new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime() + const days = Math.round((midnight(now) - midnight(created)) / 86_400_000) + const time = new Intl.DateTimeFormat(i18n.locale(), { timeStyle: "short" }).format(created) - if (!previous) return [...agentItems(), ...modelItems(data, props.model)] + if (days === 0 || days === 1) { + const day = new Intl.RelativeTimeFormat(i18n.locale(), { numeric: "auto" }).format(-days, "day") - return [ - ...(previous.agent === props.agent ? [] : agentItems()), - ...(sameModel(previous.model, props.model) ? [] : modelItems(data, props.model)), - ] + return `${day[0]?.toLocaleUpperCase(i18n.locale())}${day.slice(1)}, ${time}` + } + + if (created.getFullYear() === now.getFullYear()) + return new Intl.DateTimeFormat(i18n.locale(), { + month: "short", + day: "numeric", + hour: "numeric", + minute: "2-digit", + }).format(created) + + return new Intl.DateTimeFormat(i18n.locale(), { dateStyle: "medium", timeStyle: "short" }).format(created) }) - const metaLabels = createMemo(() => { - if (mobile()) return [] + // A waiting steer reads agent · model · Pending; mobile shows the agent and model in the composer instead. + const metaLabels = createMemo(() => (mobile() ? [] : [...agentItems(), ...modelItems(data, props.model)])) - if (waiting()) return changedLabels() - - return [...agentItems(), ...modelItems(data, props.model)] - }) - - // In a run, only the last message keeps the meta line; the others offer their actions beside the bubble. + // In a run, only the last message keeps the meta line; every bubble offers its actions from its own chevron. // Bubble corners tighten where two bubbles meet, as in the iOS app's grouped corners. const folded = createMemo(() => !!props.run?.below && !!props.text) @@ -360,8 +364,9 @@ export function CurrentUserMessageDisplay(props: { el.style.setProperty("--user-run-bottom", `${value.bottom}`) el.toggleAttribute("data-run-meta-hidden", value.meta === 0) }, - // Folding a meta line away is instant; the next message's line takes its place as that message grows in. - { ...userRunSpring, snap: folded }, + // Folding a meta line away is instant while the next message grows in to take its place; otherwise it springs in step + // with the line that replaces it. + { ...userRunSpring, snap: () => folded() && (props.runSnaps?.() ?? true) }, ) // Delivery drops the Pending footer at once rather than fading it like the hover reveal. @@ -417,85 +422,77 @@ export function CurrentUserMessageDisplay(props: { onCleanup(() => dispatch({ type: "disposed" })) - const renderActions = () => ( + const renderMenu = () => ( - - - - event.preventDefault()} - onClick={(event) => { - event.stopPropagation() - request("queue") - }} - aria-label={i18n.t("ui.message.moveToQueue")} - /> - event.preventDefault()} - onClick={(event) => { - event.stopPropagation() - request("remove") - }} - aria-label={i18n.t("ui.message.deletePending")} - /> - - - - - event.preventDefault()} - onClick={(event) => { - event.stopPropagation() - request("revert") - }} - aria-label={i18n.t("ui.message.revertMessage")} - /> - - - - - } - size="small" - variant="ghost-muted" - onMouseDown={(event: MouseEvent) => event.preventDefault()} - onClick={(event: MouseEvent) => event.stopPropagation()} - aria-label={i18n.t("ui.message.moreActions")} - /> - + + props.onMenuOpenChange?.(open)}> + {/* The chevron explains itself, so it carries only an accessible name, no tooltip. */} + } + size="small" + variant="ghost-muted" + onMouseDown={(event: MouseEvent) => event.preventDefault()} + onClick={(event: MouseEvent) => event.stopPropagation()} + aria-label={i18n.t("ui.message.moreActions")} + /> - + + + - request("fork")}> - {i18n.t("ui.message.forkMessage")} - + + request("queue")}> + + {i18n.t("ui.message.moveToQueue")} + + void writeClipboard(props.text)}> + {i18n.t("ui.message.copyMessage")} {/* Like the iOS app, a Voice message also offers the full prompt the session received. */} void writeClipboard(props.message.text)}> + {i18n.t("ui.message.copyFullMessage")} + {/* A pending steer has no history to fork from yet. */} + + request("fork")}> + + {i18n.t("ui.message.forkMessage")} + + + {/* A pending steer is withdrawn rather than reverted; a sent message reverts only where the host allows it. */} + + + request("revert")}> + + {props.latest ? i18n.t("ui.message.undoMessage") : i18n.t("ui.message.revertMessage")} + + + } + > + + request("remove")} + > + + {i18n.t("ui.message.deletePending")} + + @@ -654,6 +651,8 @@ export function CurrentUserMessageDisplay(props: { data-component="user-message" data-pending={waiting() ? "true" : undefined} data-run-folded={folded() ? "" : undefined} + data-run-above={meetsAbove() ? "" : undefined} + data-run-hovered={props.runHovered ? "" : undefined} data-run-meta-hidden={restingPose.meta === 0 ? "" : undefined} style={{ "--user-run-meta": `${restingPose.meta}`, @@ -696,10 +695,8 @@ export function CurrentUserMessageDisplay(props: { 0}> + {renderMenu()} - -
{renderActions()}
-
{/* Like the TUI, a pending steer of only attachments still offers its actions. */} @@ -707,22 +704,23 @@ export function CurrentUserMessageDisplay(props: {
- - {i18n.t("ui.message.pending")} - 0}> - - - 0}> + {/* Pending closes the line and stays in view; the agent and model before it show on hover. */} + + 0}> + + + {i18n.t("ui.message.pending")} + - {renderActions()} + {renderMenu()}
diff --git a/packages/session-ui/src/message/prompt-message.stories.tsx b/packages/session-ui/src/message/prompt-message.stories.tsx index ae66b0007d4..645342f535a 100644 --- a/packages/session-ui/src/message/prompt-message.stories.tsx +++ b/packages/session-ui/src/message/prompt-message.stories.tsx @@ -21,7 +21,6 @@ export const Pending = { voice: boolean text: boolean grouped: boolean - changed: boolean fails: boolean failures: number }>({ @@ -29,7 +28,6 @@ export const Pending = { voice: false, text: true, grouped: false, - changed: false, fails: false, failures: 0, }) @@ -41,12 +39,6 @@ export const Pending = { throw new Error("Request failed") } - // The prompt before this one; a waiting steer names only the agent and model it changes. - const previousSelection = () => ({ - agent: "build", - model: state.changed ? { ...STORY_MODEL, variant: "precise" } : STORY_MODEL, - }) - const message = createMemo(() => ({ id: "msg_pending_prompt_story", type: "user", @@ -117,14 +109,6 @@ export const Pending = { />{" "} Grouped prompts -