feat(session-ui): refine prompt styling and pending badges (#57463)

This commit is contained in:
usrnk1
2026-10-20 19:54:40 +02:00
committed by GitHub
Unverified
parent e5e4f4b2b5
commit 22c3eb1241
5 changed files with 232 additions and 21 deletions
@@ -1,5 +1,68 @@
import { expect, story } from "../../storybook/playwright/story"
story("badges pending steers without marking delivered, starting, or queued prompts", async ({ mount }) => {
const timeline = await mount("current-prompt-message--pending")
const badge = timeline.getByRole("img", { name: "Pending", exact: true })
const text = timeline.locator('[data-slot="user-message-text"]')
for (const status of ["steering", "stranded", "starting", "queued", "delivered"]) {
await timeline.getByLabel("Delivery state").selectOption(status)
const pending = status === "steering" || status === "stranded"
await expect(badge).toHaveCount(pending ? 1 : 0)
const colors = await timeline.evaluate((element, pending) => {
const probe = document.createElement("span")
probe.style.color = `var(--v2-text-text-${pending ? "muted" : "base"})`
probe.style.backgroundColor = `var(--v2-background-bg-layer-${pending ? "01" : "02"})`
element.append(probe)
const result = { color: getComputedStyle(probe).color, background: getComputedStyle(probe).backgroundColor }
probe.remove()
return result
}, pending)
await expect(text).toHaveCSS("color", colors.color)
await expect(text).toHaveCSS("background-color", colors.background)
}
await timeline.getByLabel("Delivery state").selectOption("steering")
await timeline.getByLabel("Voice message", { exact: true }).check()
const voice = timeline.getByRole("img", { name: "Voice", exact: true })
await expect(voice).toBeVisible()
await expect(badge).toBeVisible()
await expect(voice.locator("use")).toHaveAttribute("href", "#opencode-v2-icon-outline-wave-audio")
await expect(badge.locator("use")).toHaveAttribute("href", "#opencode-v2-icon-outline-steer")
for (const marker of [voice, badge]) {
await expect(marker).toHaveCSS("width", "20px")
await expect(marker).toHaveCSS("height", "20px")
await expect(marker.locator('[data-slot="icon-svg"]')).toHaveCSS("width", "14px")
await expect(marker.locator('[data-slot="icon-svg"]')).toHaveCSS("height", "14px")
}
const badgeColors = await badge.evaluate((element) => {
const probe = document.createElement("span")
probe.style.color = "var(--v2-icon-icon-muted)"
probe.style.backgroundColor = "var(--v2-background-bg-layer-02)"
element.append(probe)
const colors = { color: getComputedStyle(probe).color, background: getComputedStyle(probe).backgroundColor }
probe.remove()
return colors
})
await expect(badge).toHaveCSS("color", badgeColors.color)
await expect(badge).toHaveCSS("background-color", badgeColors.background)
const boxes = await Promise.all([voice.boundingBox(), badge.boundingBox()])
expect(boxes[0]!.x + boxes[0]!.width).toBeLessThanOrEqual(boxes[1]!.x)
await timeline.getByLabel("Prompt text", { exact: true }).uncheck()
await expect(timeline.getByText("notes.json", { exact: true })).toBeVisible()
await expect(badge).toBeVisible()
await timeline.getByRole("button", { name: "Move to queue", exact: true }).click()
await expect(badge).toHaveCount(0)
})
// Moved from packages/app/e2e/regression/session-timeline-collapse-state.spec.ts
story("keeps a manually collapsed tool collapsed when later assistant content streams", async ({ mount }) => {
const timeline = await mount("current-session-file-changes--changing-files", { args: { scenario: "streaming" } })
@@ -80,6 +143,25 @@ story("renders user image, file attachment, file reference, and agent reference"
await expect(timeline.getByText("@src/a.ts", { exact: true })).toBeVisible()
await expect(timeline.getByText("@explore", { exact: true })).toBeVisible()
const accent = await timeline.evaluate((element) => {
const probe = document.createElement("span")
probe.style.color = "var(--v2-text-text-accent)"
element.append(probe)
const color = getComputedStyle(probe).color
probe.remove()
return color
})
for (const mention of await timeline.locator("[data-highlight]").all()) {
await expect(mention).toHaveCSS("color", accent)
await expect(mention).toHaveCSS("font-weight", "440")
}
for (const prefix of await timeline.locator('[data-slot="user-message-mention-prefix"]').all()) {
await expect(prefix).toHaveCSS("color", accent)
}
const attachments = timeline.locator('[data-slot="user-message-attachments"]')
const body = timeline.locator('[data-slot="user-message-body"]')
const [attachmentsBox, bodyBox] = await Promise.all([attachments.boundingBox(), body.boundingBox()])
@@ -139,7 +139,8 @@
margin-top: 8px;
}
[data-slot="user-message-voice"] {
[data-slot="user-message-voice"],
[data-slot="user-message-pending"] {
position: absolute;
top: -8px;
inset-inline-start: -8px;
@@ -149,7 +150,6 @@
border-radius: 9999px;
background: var(--v2-background-bg-layer-03);
box-shadow: 0 0 0 2px var(--v2-background-bg-base);
color: var(--v2-icon-icon-muted);
[data-component="tooltip-v2-trigger"] {
width: 100%;
@@ -160,8 +160,27 @@
}
[data-slot="icon-svg"] {
width: 12px;
height: 12px;
width: 14px;
height: 14px;
}
}
[data-slot="user-message-voice"] {
color: var(--v2-icon-icon-muted);
}
[data-slot="user-message-pending"] {
color: var(--v2-icon-icon-muted);
background: var(--v2-background-bg-layer-02);
}
&[data-pending] {
position: relative;
margin-block-start: 8px;
[data-slot="user-message-pending"] {
inset-inline-start: auto;
inset-inline-end: -8px;
}
}
@@ -185,14 +204,14 @@
[data-highlight="file"],
[data-highlight="agent"] {
color: inherit;
font-weight: 600;
color: var(--v2-text-text-accent);
font-weight: 440;
direction: ltr;
unicode-bidi: isolate;
}
[data-slot="user-message-mention-prefix"] {
color: var(--v2-blue-500);
color: var(--v2-text-text-accent);
}
[data-slot="user-message-link"] {
@@ -1477,8 +1496,8 @@
font-weight: 440;
[data-slot="user-message-text"] {
background: var(--v2-blue-1200);
color: var(--v2-blue-300);
background: var(--v2-background-bg-layer-02);
color: var(--v2-text-text-base);
}
[data-slot="user-message-comments"] {
@@ -1519,19 +1538,10 @@
}
}
:root[data-color-scheme="light"] body [data-component="user-message"] [data-slot="user-message-text"] {
background: var(--v2-blue-100);
color: var(--v2-blue-700);
}
/* 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"] {
background: var(--v2-background-bg-layer-02);
color: var(--v2-text-text-base);
background: var(--v2-background-bg-layer-01);
color: var(--v2-text-text-muted);
transition: none;
[data-slot="user-message-mention-prefix"] {
color: currentColor;
}
}
@@ -384,6 +384,13 @@ export function CurrentUserMessageDisplay(props: {
data-pending={waiting() ? "true" : undefined}
data-timeline-part-id={props.text ? `${props.message.id}:text:0` : undefined}
>
<Show when={waiting()}>
<div data-slot="user-message-pending" role="img" aria-label={i18n.t("ui.message.pending")}>
<Tooltip appearance="compact" value={i18n.t("ui.message.pending")} placement="top" gutter={4}>
<Icon name="outline-steer" size="small" />
</Tooltip>
</div>
</Show>
{renderAttachments()}
<Show
when={props.text}
@@ -397,7 +404,7 @@ export function CurrentUserMessageDisplay(props: {
<Show when={props.voice}>
<div data-slot="user-message-voice" role="img" aria-label={i18n.t("ui.message.voice")}>
<Tooltip appearance="compact" value={i18n.t("ui.message.voice")} placement="top" gutter={4}>
<Icon name="waveform" size="small" />
<Icon name="outline-wave-audio" size="small" />
</Tooltip>
</div>
</Show>
@@ -0,0 +1,104 @@
import { createMemo, For } from "solid-js"
import { createStore } from "solid-js/store"
import type { SessionMessageUser } from "@opencode/client/promise"
import type { SessionUserActions } from "../actions"
import { CurrentUserMessageDisplay } from "./message-content"
import { CurrentSessionProviders } from "../storybook/current-session-story"
import { CURRENT_SESSION_ID, STORY_MODEL, STORY_TIME } from "../storybook/current-session-fixtures"
export default {
title: "OpenCode/Conversation/Prompt message",
id: "current-prompt-message",
parameters: { layout: "fullscreen" },
}
export const Pending = {
render: () => {
const statuses = ["delivered", "starting", "steering", "stranded", "queued"] as const
const [state, setState] = createStore<{ status: (typeof statuses)[number]; voice: boolean; text: boolean }>({
status: "steering",
voice: false,
text: true,
})
const message = createMemo<SessionMessageUser>(() => ({
id: "msg_pending_prompt_story",
type: "user",
text: state.text ? "Keep the prompt styling consistent with the rest of the timeline." : "",
time: { created: STORY_TIME },
files: state.text
? []
: [{ name: "notes.json", mime: "application/json", data: "e30=", source: { type: "inline" } }],
}))
const document = createMemo(() => ({
sessionID: CURRENT_SESSION_ID,
messages: [message()],
status: { type: "idle" as const },
diffs: [],
}))
const actions = {
pending: {
status: () => (state.status === "delivered" ? undefined : state.status),
queue: async () => {
setState("status", "queued")
},
remove: async () => {
setState("status", "delivered")
},
},
} satisfies SessionUserActions
return (
<section class="mx-auto flex w-full max-w-[840px] flex-col gap-8 p-6">
<div class="flex flex-wrap items-center gap-4">
<label>
Delivery state{" "}
<select
aria-label="Delivery state"
value={state.status}
onChange={(event) => {
const status = statuses.find((status) => status === event.currentTarget.value)
if (status) setState("status", status)
}}
>
<For each={statuses}>
{(status) => <option value={status}>{status[0].toUpperCase() + status.slice(1)}</option>}
</For>
</select>
</label>
<label>
<input
type="checkbox"
checked={state.voice}
onChange={(event) => setState("voice", event.currentTarget.checked)}
/>{" "}
Voice message
</label>
<label>
<input
type="checkbox"
checked={state.text}
onChange={(event) => setState("text", event.currentTarget.checked)}
/>{" "}
Prompt text
</label>
</div>
<CurrentSessionProviders document={document()}>
<CurrentUserMessageDisplay
sessionID={CURRENT_SESSION_ID}
message={message()}
text={message().text}
agent="build"
model={STORY_MODEL}
voice={state.voice}
actions={actions}
/>
</CurrentSessionProviders>
</section>
)
},
}
+8
View File
@@ -274,6 +274,14 @@ const icons = {
viewBox: "0 0 16 16",
body: `<path d="M2 7V9M4.5 5V11M7 2.5V13.5M9.5 4.5V11.5M12 6V10M14.5 7.25V8.75" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>`,
},
"outline-steer": {
viewBox: "0 0 16 16",
body: `<path d="M8 14C11.3137 14 14 11.3137 14 8C14 4.68634 11.3137 2 8 2C4.68626 2 2 4.68634 2 8C2 11.3137 4.68626 14 8 14Z" stroke-linecap="round" stroke-linejoin="round" stroke="currentColor"/><path d="M8 3.86328V12.1391C10.2854 12.1391 12.1379 10.2863 12.1379 8.00121C12.1379 5.71608 10.2854 3.86328 8 3.86328Z" fill="currentColor"/>`,
},
"outline-wave-audio": {
viewBox: "0 0 16 16",
body: `<path d="M14.5 8.01193V8" stroke-linecap="square" stroke="currentColor"/><path d="M1.5 8.00607V7.99414" stroke-linecap="square" stroke="currentColor"/><path d="M3.66699 10.5141V5.48438" stroke-linecap="square" stroke="currentColor"/><path d="M10.167 10.5141V5.48438" stroke-linecap="square" stroke="currentColor"/><path d="M8 11.6004V4.39844" stroke-linecap="square" stroke="currentColor"/><path d="M12.333 9.20144V6.80078" stroke-linecap="square" stroke="currentColor"/><path d="M5.83301 13.5323V2.4668" stroke-linecap="square" stroke="currentColor"/>`,
},
archive: {
viewBox: "0 0 16 16",
body: `<path d="M13.1112 13.5555V14.0555H13.6112V13.5555H13.1112ZM2.889 13.5555H2.389L2.389 14.0555H2.889V13.5555ZM3.38901 5.55546L3.38901 5.05546L2.38901 5.05546L2.38901 5.55546L2.88901 5.55546L3.38901 5.55546ZM14.4446 2.44434H14.9446V1.94434L14.4446 1.94434L14.4446 2.44434ZM14.4446 5.55545L14.4446 6.05545L14.9446 6.05545V5.55545H14.4446ZM1.55566 5.55546L1.05566 5.55545L1.05566 6.05546L1.55566 6.05546L1.55566 5.55546ZM1.5557 2.44436L1.5557 1.94436L1.05571 1.94436L1.0557 2.44435L1.5557 2.44436ZM13.1112 5.55546H12.6112V13.5555H13.1112H13.6112V5.55546H13.1112ZM2.889 13.5555H3.389L3.38901 5.55546L2.88901 5.55546L2.38901 5.55546L2.389 13.5555H2.889ZM14.4446 2.44434H13.9446V5.55545H14.4446H14.9446V2.44434H14.4446ZM1.55566 5.55546L2.05566 5.55547L2.0557 2.44436L1.5557 2.44436L1.0557 2.44435L1.05566 5.55545L1.55566 5.55546ZM6.22234 8.22213V8.72213H9.7779V8.22213V7.72213H6.22234V8.22213ZM13.1112 13.5555V13.0555H2.889V13.5555V14.0555H13.1112V13.5555ZM1.5557 2.44436L1.5557 2.94436L14.4446 2.94434L14.4446 2.44434L14.4446 1.94434L1.5557 1.94436L1.5557 2.44436ZM14.4446 5.55545L14.4446 5.05545L1.55566 5.05546L1.55566 5.55546L1.55566 6.05546L14.4446 6.05545L14.4446 5.55545Z" fill="currentColor"/>`,