feat(session-ui): reveal token throughput on response footer hover (#61646)

This commit is contained in:
usrnk1
2026-11-04 13:38:14 +01:00
committed by GitHub
Unverified
parent b9d0982b44
commit 5a750e64a2
8 changed files with 184 additions and 10 deletions
@@ -1,5 +1,51 @@
import { expect, story } from "../../stories/playwright/story"
story("reveals turn speed only while hovering the response metadata", async ({ mount, page }) => {
const timeline = await mount("current-session-timeline-rows--response-speed", { args: { steered: true } })
const footer = timeline.locator('[data-slot="text-part-copy-wrapper"]').last()
const meta = footer.locator('[data-slot="text-part-meta"]')
const speed = meta.locator('[data-slot="text-part-meta-speed"]')
await page.evaluate(() => document.fonts.ready.then(() => undefined))
await expect(meta.locator('[data-slot="text-part-meta-item"]').last()).toHaveText("5m 2s")
await expect(speed).toHaveText("·60.0 tok/s")
await timeline.getByText("The timeline checks passed.", { exact: false }).hover()
await expect(footer).toHaveCSS("opacity", "1")
await expect(speed).toBeHidden()
for (const width of [1000, 390]) {
await page.setViewportSize({ width, height: 844 })
await timeline.getByText("The timeline checks passed.", { exact: false }).hover()
await meta.hover()
await expect(speed).toBeVisible()
expect(
await speed.evaluate((element) => {
const box = element.getBoundingClientRect()
const parent = element.parentElement!.getBoundingClientRect()
return box.left >= parent.left && box.right <= parent.right + 1
}),
).toBe(true)
await footer.getByRole("button", { name: "Copy response", exact: true }).hover()
await expect(speed).toBeHidden()
}
})
story("omits turn speed when a model step has no streaming time", async ({ mount }) => {
const timeline = await mount("current-session-timeline-rows--response-speed", { args: { measured: false } })
const meta = timeline.locator('[data-slot="text-part-meta"]')
await timeline.getByText("The timeline checks passed.", { exact: false }).hover()
await meta.hover()
await expect(meta).toContainText("5m 2s")
await expect(meta.locator('[data-slot="text-part-meta-speed"]')).toHaveCount(0)
})
story("keeps quote attachment icons fixed while long text truncates", async ({ mount, page }) => {
const gallery = await mount("current-session-timeline-rows--quote-attachments")
@@ -4,7 +4,7 @@ story.describe("touch timeline", () => {
story.use({ hasTouch: true, isMobile: true, viewport: { width: 390, height: 844 } })
story("keeps message actions and metadata visible without hover", async ({ mount, page }) => {
const timeline = await mount("current-session-timeline-rows--conversation", { args: { scenario: "interruption" } })
const timeline = await mount("current-session-timeline-rows--response-speed")
expect(await page.evaluate(() => matchMedia("(hover: none)").matches)).toBe(true)
for (const action of [
@@ -25,6 +25,8 @@ story.describe("touch timeline", () => {
await expect(responseMeta).not.toBeEmpty()
await expect(responseMeta).not.toContainText("Build")
await expect(responseMeta).not.toContainText("Sonnet")
await expect(responseMeta.locator('[data-slot="text-part-meta-speed"]')).toHaveText("·60.0 tok/s")
await expect(responseMeta.locator('[data-slot="text-part-meta-speed"]')).toBeHidden()
})
story("keeps shell copy visible without hover", async ({ mount }) => {
@@ -548,6 +548,19 @@
}
}
[data-slot="text-part-meta-speed"] {
display: none;
flex: none;
align-items: center;
gap: 4px;
}
@media (hover: hover) {
[data-slot="text-part-meta"]:hover [data-slot="text-part-meta-speed"] {
display: inline-flex;
}
}
[data-slot="text-part-meta-separator"] {
flex: none;
}
@@ -61,6 +61,7 @@ export function SessionAssistantContent(props: {
contentID: string
showAssistantCopyPartID?: string | null
turnDurationMs?: number | null
turnTokensPerSecond?: number
sources?: TurnSources
onOpenSources?: () => void
defaultOpen?: boolean
@@ -79,6 +80,7 @@ export function SessionAssistantContent(props: {
message={props.message}
showCopy={props.showAssistantCopyPartID === props.contentID}
turnDurationMs={props.turnDurationMs}
turnTokensPerSecond={props.turnTokensPerSecond}
sources={props.sources}
onOpenSources={props.onOpenSources}
/>
@@ -1139,6 +1139,7 @@ export function AssistantTextContent(props: {
message: SessionMessageAssistant
showCopy: boolean
turnDurationMs?: number | null
turnTokensPerSecond?: number
/** The finished turn's web searches and fetches, shown as a chip in its footer. */
sources?: TurnSources
onOpenSources?: () => void
@@ -1197,6 +1198,17 @@ export function AssistantTextContent(props: {
),
])
const speed = createMemo(() => {
if (props.turnTokensPerSecond === undefined) return undefined
return i18n.t("ui.message.tokensPerSecond", {
value: new Intl.NumberFormat(i18n.locale(), {
minimumFractionDigits: 1,
maximumFractionDigits: 1,
}).format(props.turnTokensPerSecond),
})
})
const [copied, setCopied] = createSignal(false)
const copy = async () => {
@@ -1242,6 +1254,14 @@ export function AssistantTextContent(props: {
<Show when={meta().length > 0}>
<span data-slot="text-part-meta">
<MetaItems items={meta()} slot="text-part" />
<Show when={speed()}>
{(label) => (
<span data-slot="text-part-meta-speed">
<span aria-hidden="true">{"\u00B7"}</span>
<span dir="auto">{label()}</span>
</span>
)}
</Show>
</span>
</Show>
</div>
@@ -5,6 +5,7 @@ import type {
SessionStatus,
} from "@opencode/client/promise"
import { useI18n } from "@opencode/ui/context/i18n"
import { SessionTurn } from "@opencode/util/session-turn"
import { Option, Predicate, Schema } from "effect"
import {
For,
@@ -109,6 +110,16 @@ export function createSessionTimelineRowRenderer(input: {
const patchGroupKeys = input.disclosure.patchGroupKeys ?? new Map<string, string>()
const patchPartKeys = new WeakMap<SessionMessageAssistant["content"][number], string>()
const turns = createMemo(() => {
const messages = [...input.projection.messageByID().values()]
return {
messages,
legacy: SessionTurn.legacy(messages),
indexes: new Map(messages.map((message, index) => [message.id, index])),
}
})
const patchOwners = createMemo(() => {
const owners = new Map<string, string>()
const rows = input.projection.rows()
@@ -194,17 +205,17 @@ export function createSessionTimelineRowRenderer(input: {
if (user?.type !== "user") return null
const completed = (input.projection.assistantMessagesByParent().get(messageID) ?? emptyAssistantMessages).reduce<
number | undefined
>((latest, message) => {
if (message.time.completed === undefined) return latest
const message = input.projection
.assistantMessagesByParent()
.get(messageID)
?.findLast((message) => message.time.completed !== undefined)
return latest === undefined ? message.time.completed : Math.max(latest, message.time.completed)
}, undefined)
if (message?.time.completed === undefined || message.time.completed < user.time.created) return undefined
if (completed === undefined || completed < user.time.created) return undefined
return completed - user.time.created
return SessionTurn.duration(turns().messages, message, {
index: turns().indexes.get(message.id),
legacy: turns().legacy,
})
}
const copyContentID = (messageID: string) => {
@@ -455,6 +466,23 @@ export function createSessionTimelineRowRenderer(input: {
return value.steps.length > 0 ? value : undefined
})
const turnTokensPerSecond = createMemo(() => {
const current = ref()
if (!current || copyContentID(row().userMessageID) !== current.partID) return undefined
const messages = input.projection.assistantMessagesByParent().get(row().userMessageID) ?? emptyAssistantMessages
const last = messages.at(-1)
if (!last) return undefined
return SessionTurn.tokensPerSecond(turns().messages, last, {
index: turns().indexes.get(last.id),
legacy: turns().legacy,
})
})
const disclosureKey = () => (content()?.type === "reasoning" ? ref()!.partID : row().group.key)
return (
@@ -468,6 +496,7 @@ export function createSessionTimelineRowRenderer(input: {
contentID={ref()!.partID}
showAssistantCopyPartID={copyContentID(row().userMessageID)}
turnDurationMs={duration(row().userMessageID)}
turnTokensPerSecond={turnTokensPerSecond()}
sources={turnSourcesValue()}
onOpenSources={() => sourcesHost?.open(row().userMessageID)}
defaultOpen={defaultOpen()}
@@ -58,6 +58,67 @@ export const StreamingReasoningAndText = {
),
}
export const ResponseSpeed = {
args: { measured: true, steered: false },
render: (args: { measured: boolean; steered: boolean }) => (
<CurrentSessionTimelineStory
title="Response speed"
description="Hover the response, then its metadata line to reveal tokens per second across both model steps."
width="720px"
document={{
sessionID: CURRENT_SESSION_ID,
status: { type: "idle" },
diffs: [],
messages: [
{
id: "msg_speed_user",
type: "user",
text: "Check the timeline performance.",
time: { created: STORY_TIME },
},
{
id: "msg_speed_inspect",
type: "assistant",
agent: "build",
model: STORY_MODEL,
content: [{ type: "text", text: "I'll inspect the timeline before checking the results." }],
tokens: { input: 1000, output: 270, reasoning: 30, cache: { read: 0, write: 0 } },
time: {
created: STORY_TIME + 100,
streamed: args.measured ? STORY_TIME + 3100 : undefined,
completed: STORY_TIME + 290_000,
},
},
...(args.steered
? [
{
id: "msg_speed_steer",
type: "user" as const,
text: "Include narrow layouts in the check.",
time: { created: STORY_TIME + 290_000 },
},
]
: []),
{
id: "msg_speed_reply",
type: "assistant",
agent: "build",
model: STORY_MODEL,
content: [{ type: "text", text: "The timeline checks passed. No performance regressions were found." }],
tokens: { input: 2000, output: 500, reasoning: 100, cache: { read: 0, write: 0 } },
time: {
created: STORY_TIME + 290_000,
streamed: STORY_TIME + 302_000,
completed: STORY_TIME + 302_000,
},
},
{ id: "msg_speed_idle", type: "idle", outcome: "succeeded", time: { created: STORY_TIME + 302_000 } },
],
}}
/>
),
}
function AgentReasoningStory(props: { mode: ReasoningMode; reasoning: string; tool: boolean; text: string }) {
const content = [
...(props.reasoning === "none"
+1
View File
@@ -294,6 +294,7 @@ const source = {
"ui.message.duration.seconds": "{{count}}s",
"ui.message.duration.minutesSeconds": "{{minutes}}m {{seconds}}s",
"ui.message.duration.hoursMinutes": "{{hours}}h {{minutes}}m",
"ui.message.tokensPerSecond": "{{value}} tok/s",
"ui.message.interrupted": "Interrupted",
"ui.message.modelVariant": "{{model}} ({{variant}})",
"ui.message.time.justNow": "Just now",