fix(webui): hide live activity timer on narrow screens

This commit is contained in:
chengyongru authored and chengyongru committed 2026-11-20 00:46:21 +08:00
1 parent 5537bdabd3
commit b9b491e74c
6 files changed
+54 -55

No files matched your search

+20 -19
View File
@@ -22,12 +22,9 @@ test("the collapsed row rolls with its icon and a burst lands on the latest acti
const wheelBox = (await wheel.boundingBox())!; const wheelBox = (await wheel.boundingBox())!;
expect(wheelBox.x).toBeGreaterThan(headerBox.x + headerBox.width); expect(wheelBox.x).toBeGreaterThan(headerBox.x + headerBox.width);
expect(wheelBox.y + wheelBox.height / 2).toBeCloseTo(headerBox.y + headerBox.height / 2, 0); expect(wheelBox.y + wheelBox.height / 2).toBeCloseTo(headerBox.y + headerBox.height / 2, 0);
const iconOffset = await wheel.evaluate((element) => { const icon = (await wheel.locator("[data-activity-marker] svg").boundingBox())!;
const icon = element.querySelector("[data-activity-marker] svg")!.getBoundingClientRect(); const label = (await toggle.locator("[data-sheen-text]").boundingBox())!;
const label = element.previousElementSibling!.querySelector("span")!.getBoundingClientRect(); expect(Math.abs(icon.y + icon.height / 2 - (label.y + label.height / 2))).toBeLessThan(0.2);
return icon.top + icon.height / 2 - (label.top + label.height / 2);
});
expect(Math.abs(iconOffset)).toBeLessThan(0.2);
const height = (await toggle.boundingBox())!.height; const height = (await toggle.boundingBox())!.height;
// This is a status update on the same tool, not a new row. // This is a status update on the same tool, not a new row.
@@ -79,14 +76,16 @@ test("the collapsed row rolls with its icon and a burst lands on the latest acti
await expect(wheel).toContainText("A better way to travel overnight"); await expect(wheel).toContainText("A better way to travel overnight");
}); });
test("narrow reduced-motion preview replaces the row without scrolling the page", async ({ page }) => { test("the narrow preview is a single tappable row and honors reduced motion", async ({ page }) => {
await page.setViewportSize({ width: 360, height: 740 }); await page.setViewportSize({ width: 360, height: 740 });
const wheel = page.getByTestId("latest-activity-wheel"); const wheel = page.getByTestId("latest-activity-wheel");
await expect(wheel).toContainText("brief.md"); await expect(wheel).toContainText("brief.md");
// Change the system preference while the wheel is already mounted. // Change the system preference while the wheel is already mounted.
await page.emulateMedia({ reducedMotion: "reduce" }); await page.emulateMedia({ reducedMotion: "reduce" });
await page.getByRole("button", { name: "切换主题" }).click(); await page.getByRole("button", { name: "切换主题" }).click();
const toggle = page.getByRole("button", { name: /处理中/ }); const toggle = page.getByRole("button", { name: "正在处理", exact: true });
await expect(toggle).toHaveAttribute("aria-expanded", "false");
await expect(toggle).toHaveText("");
const next = page.getByRole("button", { name: "下一条" }); const next = page.getByRole("button", { name: "下一条" });
await next.click({ clickCount: 2 }); await next.click({ clickCount: 2 });
await expect(wheel).toContainText("夜间列车旅行指南"); await expect(wheel).toContainText("夜间列车旅行指南");
@@ -111,9 +110,15 @@ test("narrow reduced-motion preview replaces the row without scrolling the page"
})).toBeLessThan(1); })).toBeLessThan(1);
const header = (await toggle.boundingBox())!; const header = (await toggle.boundingBox())!;
const row = (await wheel.boundingBox())!; const row = (await wheel.boundingBox())!;
expect(row.y).toBeGreaterThanOrEqual(header.y + header.height - 0.2); expect(row.y + row.height / 2).toBeCloseTo(header.y + header.height / 2, 0);
expect(row.width).toBeGreaterThan(header.width);
expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBe(360); expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBe(360);
// Tap where the tool summary is displayed, rather than on the activity icon.
await toggle.click({ position: { x: row.x - header.x + 48, y: header.height / 2 } });
const expanded = page.getByRole("button", { name: "正在处理, 收起处理过程", exact: true });
await expect(expanded).toHaveAttribute("aria-expanded", "true");
await expect(expanded).toHaveText("正在处理");
await expect(page.getByRole("link", { name: /Planning an overnight rail trip/ })).toBeVisible();
}); });
test("the elapsed label keeps a compact gap before the collapsed activity", async ({ page }) => { test("the elapsed label keeps a compact gap before the collapsed activity", async ({ page }) => {
@@ -141,19 +146,15 @@ test("the elapsed label keeps a compact gap before the collapsed activity", asyn
} }
}); });
test("the working label stays in place when activity is expanded and collapsed", async ({ page }) => { test("the activity disclosure stays anchored through resize and expansion", async ({ page }) => {
for (const width of [960, 360]) { for (const width of [960, 360]) {
await page.setViewportSize({ width, height: 740 }); await page.setViewportSize({ width, height: 740 });
// The responsive action row changes height; measure after that resize commits. // The responsive action row changes height; measure after that resize commits.
await expect(page.locator("[data-message-mobile-actions]")).toHaveCount(width < 768 ? 1 : 0); await expect(page.locator("[data-message-mobile-actions]")).toHaveCount(width < 768 ? 1 : 0);
const toggle = page.getByRole("button", { name: /处理中/ }); const mobile = width < 640;
const labelPosition = () => toggle.evaluate((button) => { const toggle = page.getByRole("button", { name: mobile ? /^正在处理/ : /^处理中 \d/ });
const label = button.querySelector("[data-sheen-text]")!; const anchor = toggle.locator(mobile ? "svg.lucide-activity" : "[data-sheen-text]");
const range = document.createRange(); const labelPosition = async () => (await anchor.boundingBox())!;
range.selectNodeContents(label);
const { x, y } = range.getBoundingClientRect();
return { x, y, width: button.getBoundingClientRect().width };
});
const collapsed = await labelPosition(); const collapsed = await labelPosition();
await toggle.click(); await toggle.click();
await expect(toggle).toHaveAttribute("aria-expanded", "true"); await expect(toggle).toHaveAttribute("aria-expanded", "true");
+5 -6
View File
@@ -59,8 +59,8 @@ async function expectAnswerOrder(page: Page) {
} }
for (const scenario of [ for (const scenario of [
{ locale: "en", width: 1440, waiting: /Connection failed\. Retrying in [1-9][0-9]*s/, retrying: "Connection failed. Retrying" }, { locale: "en", width: 1440, working: /^Working for \d/, waiting: /Connection failed\. Retrying in [1-9][0-9]*s/, retrying: "Connection failed. Retrying" },
{ locale: "zh-CN", width: 390, waiting: /连接失败,[1-9][0-9]* 秒后重试/, retrying: "连接失败,正在重试" }, { locale: "zh-CN", width: 390, working: "正在处理", waiting: /连接失败,[1-9][0-9]* 秒后重试/, retrying: "连接失败,正在重试" },
]) { ]) {
test(`shows retry progress in the live thread at ${scenario.width}px (${scenario.locale})`, async ({ page }, info) => { test(`shows retry progress in the live thread at ${scenario.width}px (${scenario.locale})`, async ({ page }, info) => {
await page.setViewportSize({ width: scenario.width, height: 900 }); await page.setViewportSize({ width: scenario.width, height: 900 });
@@ -68,10 +68,9 @@ for (const scenario of [
const { emit, errors } = await openThread(page, [], scenario.locale); const { emit, errors } = await openThread(page, [], scenario.locale);
emit({ event: "user_message", ...base, text: "Retry fixture", starts_turn: true, active_turn_id: turnId }); emit({ event: "user_message", ...base, text: "Retry fixture", starts_turn: true, active_turn_id: turnId });
await expect(page.getByText("Retry fixture", { exact: true })).toBeVisible(); await expect(page.getByText("Retry fixture", { exact: true })).toBeVisible();
emit( emit({ event: "goal_status", ...base, status: "running", started_at: Date.now() / 1000 });
{ event: "goal_status", ...base, status: "running", started_at: Date.now() / 1000 }, await expect(page.getByRole("status", { name: scenario.working })).toHaveText(scenario.working);
{ event: "retry_status", ...base, state: "waiting", attempt: 1, max_attempts: 4, error_kind: "connection", retry_after_s: 30 }, emit({ event: "retry_status", ...base, state: "waiting", attempt: 1, max_attempts: 4, error_kind: "connection", retry_after_s: 30 });
);
await expect(page.getByRole("status", { name: scenario.waiting })).toBeVisible(); await expect(page.getByRole("status", { name: scenario.waiting })).toBeVisible();
await page.screenshot({ path: info.outputPath("retry-waiting.png") }); await page.screenshot({ path: info.outputPath("retry-waiting.png") });
await page.clock.fastForward(30_000); await page.clock.fastForward(30_000);
+1 -1
View File
@@ -15,7 +15,7 @@ for (const width of [1280, 360]) {
await expect(activity).toContainText("Command failed (exit 7) curl -u •••• https://example.invalid"); await expect(activity).toContainText("Command failed (exit 7) curl -u •••• https://example.invalid");
await page.getByRole("button", { name: "many", exact: true }).click(); await page.getByRole("button", { name: "many", exact: true }).click();
await expect(activity.getByTestId("latest-activity-wheel")).toContainText("Command still running"); await expect(activity.getByTestId("latest-activity-wheel")).toContainText("Command still running");
await activity.getByRole("button", { name: /^Working for / }).click(); await activity.getByRole("button", { name: width < 640 ? "Working" : /^Working for /, exact: true }).click();
const disclosure = activity.getByRole("button", { name: "Show 24 earlier checks" }); const disclosure = activity.getByRole("button", { name: "Show 24 earlier checks" });
await expect(activity.getByTestId("activity-step")).toHaveCount(1); await expect(activity.getByTestId("activity-step")).toHaveCount(1);
await disclosure.click(); await disclosure.click();
@@ -55,6 +55,7 @@ import { formControlFocusClassName } from "@/components/ui/form-control";
import { useFileEditDisplayMode } from "@/hooks/useFileEditDisplayMode"; import { useFileEditDisplayMode } from "@/hooks/useFileEditDisplayMode";
import { useLocalPreferences } from "@/hooks/useLocalPreferences"; import { useLocalPreferences } from "@/hooks/useLocalPreferences";
import { useLogoFallback } from "@/hooks/useLogoFallback"; import { useLogoFallback } from "@/hooks/useLogoFallback";
import { useMediaQuery } from "@/hooks/useMediaQuery";
import { usePageVisibility } from "@/hooks/usePageVisibility"; import { usePageVisibility } from "@/hooks/usePageVisibility";
import { useThreadVisibility } from "@/hooks/useThreadVisibility"; import { useThreadVisibility } from "@/hooks/useThreadVisibility";
import type { FileEditDisplayMode } from "@/lib/local-preferences"; import type { FileEditDisplayMode } from "@/lib/local-preferences";
@@ -251,6 +252,7 @@ function FoldedAgentActivity({
}: AgentActivityClusterProps) { }: AgentActivityClusterProps) {
const { t } = useTranslation(); const { t } = useTranslation();
const { activityMode, fileEditDisplayMode } = useLocalPreferences(); const { activityMode, fileEditDisplayMode } = useLocalPreferences();
const mobile = useMediaQuery("(max-width: 639px)");
const pageVisible = usePageVisibility(); const pageVisible = usePageVisibility();
const threadVisible = useThreadVisibility(); const threadVisible = useThreadVisibility();
const activityMessages = useMemo(() => coalesceActivityMessages(messages), [messages]); const activityMessages = useMemo(() => coalesceActivityMessages(messages), [messages]);
@@ -322,6 +324,11 @@ function FoldedAgentActivity({
); );
const activityDuration = formatActivityDuration(durationMs); const activityDuration = formatActivityDuration(durationMs);
const showActivityPreview = isTurnStreaming && hasVisibleActivity && !outerExpanded && !hideHeader && !retryStatus; const showActivityPreview = isTurnStreaming && hasVisibleActivity && !outerExpanded && !hideHeader && !retryStatus;
const preview = useMemo(() => {
if (!showActivityPreview) return null;
const row = latestActivityRow(activityMessages, fileEditsByMessage, cliAppsByName, mcpPresetsByName);
return row ? <LatestActivityWheel row={row} visible={pageVisible && threadVisible} /> : null;
}, [showActivityPreview, activityMessages, fileEditsByMessage, cliAppsByName, mcpPresetsByName, pageVisible, threadVisible]);
const workingLabel = (duration: string) => t("message.activityWorkingFor", { const workingLabel = (duration: string) => t("message.activityWorkingFor", {
duration, duration,
defaultValue: "Working for {{duration}}", defaultValue: "Working for {{duration}}",
@@ -356,7 +363,7 @@ function FoldedAgentActivity({
defaultValue: "{{error}} Retrying", defaultValue: "{{error}} Retrying",
}) })
: isTurnStreaming : isTurnStreaming
? workingLabel(activityDuration) ? mobile ? t("message.agentActivity.working") : workingLabel(activityDuration)
: durationMs <= 0 : durationMs <= 0
? t("message.activityWorked", { defaultValue: "Worked" }) ? t("message.activityWorked", { defaultValue: "Worked" })
: t("message.activityWorkedFor", { : t("message.activityWorkedFor", {
@@ -409,15 +416,8 @@ function FoldedAgentActivity({
collapseLabel={t("message.collapseActivity")} collapseLabel={t("message.collapseActivity")}
contentId={detailsId} contentId={detailsId}
label={activityLabel} label={activityLabel}
preview={showActivityPreview ? ( preview={preview}
<CollapsedActivityPreview compactPreview={mobile && preview !== null}
messages={activityMessages}
fileEditsByMessage={fileEditsByMessage}
cliAppsByName={cliAppsByName}
mcpPresetsByName={mcpPresetsByName}
visible={pageVisible && threadVisible}
/>
) : undefined}
hasDetails={hasVisibleActivity} hasDetails={hasVisibleActivity}
onToggle={toggleOuter} onToggle={toggleOuter}
> >
@@ -501,16 +501,12 @@ function traceLines(message: UIMessage): string[] {
return message.content.trim() ? [message.content] : []; return message.content.trim() ? [message.content] : [];
} }
const CollapsedActivityPreview = memo(function CollapsedActivityPreview({ function latestActivityRow(
messages, fileEditsByMessage, cliAppsByName, mcpPresetsByName, visible, messages: UIMessage[],
}: { fileEditsByMessage: Map<string, FileEditSummary[]>,
messages: UIMessage[]; cliAppsByName: Map<string, CliAppInfo>,
fileEditsByMessage: Map<string, FileEditSummary[]>; mcpPresetsByName: Map<string, McpPresetInfo>,
cliAppsByName: Map<string, CliAppInfo>; ) {
mcpPresetsByName: Map<string, McpPresetInfo>;
visible: boolean;
}) {
const row = useMemo(() => {
for (let index = messages.length - 1; index >= 0; index -= 1) { for (let index = messages.length - 1; index >= 0; index -= 1) {
const message = messages[index]; const message = messages[index];
if (isReasoningOnlyAssistant(message)) { if (isReasoningOnlyAssistant(message)) {
@@ -552,10 +548,7 @@ const CollapsedActivityPreview = memo(function CollapsedActivityPreview({
return <ActivityTraceRow key={key} line={line} active state={state} />; return <ActivityTraceRow key={key} line={line} active state={state} />;
} }
return null; return null;
}, [messages, fileEditsByMessage, cliAppsByName, mcpPresetsByName]); }
return row ? <LatestActivityWheel row={row} visible={visible} /> : null;
});
const ActivityMessageTimeline = memo(function ActivityMessageTimeline({ const ActivityMessageTimeline = memo(function ActivityMessageTimeline({
messages, messages,
@@ -34,7 +34,7 @@ export function LatestActivityWheel({ row, visible }: { row: ReactElement; visib
aria-hidden aria-hidden
{...{ inert: "" }} {...{ inert: "" }}
data-testid="latest-activity-wheel" data-testid="latest-activity-wheel"
className="relative h-6 min-w-0 overflow-hidden pe-1 max-sm:ms-6 sm:flex-1 [mask-image:linear-gradient(transparent,black_10%,black_90%,transparent)] [&_[data-activity-marker]]:self-center [&_[data-activity-marker]]:items-center [&_[data-activity-marker]]:pt-0" className="relative h-6 min-w-0 overflow-hidden pe-1 [mask-image:linear-gradient(transparent,black_10%,black_90%,transparent)] [&_[data-activity-marker]]:self-center [&_[data-activity-marker]]:items-center [&_[data-activity-marker]]:pt-0"
> >
{canRoll ? <motion.div {canRoll ? <motion.div
key={frame.key} key={frame.key}
@@ -12,6 +12,7 @@ interface ThinkingReasoningShellProps {
contentId?: string; contentId?: string;
label: string; label: string;
preview?: ReactNode; preview?: ReactNode;
compactPreview?: boolean;
children: ReactNode; children: ReactNode;
hasDetails?: boolean; hasDetails?: boolean;
onToggle: () => void; onToggle: () => void;
@@ -26,6 +27,7 @@ export function ThinkingReasoningShell({
contentId: providedContentId, contentId: providedContentId,
label, label,
preview, preview,
compactPreview = false,
children, children,
hasDetails = true, hasDetails = true,
onToggle, onToggle,
@@ -36,7 +38,7 @@ export function ThinkingReasoningShell({
if (expanded && !hasExpanded) setHasExpanded(true); if (expanded && !hasExpanded) setHasExpanded(true);
const headerClassName = cn( const headerClassName = cn(
"touch-target inline-flex h-7 min-w-0 items-center gap-1.5 rounded-md px-1.5", "touch-target inline-flex h-7 min-w-0 items-center gap-1.5 rounded-md px-1.5",
preview && "max-sm:self-start", compactPreview && "col-start-1 row-start-1",
); );
const labelClassName = "min-w-0 truncate text-[12px] font-normal leading-4 tabular-nums"; const labelClassName = "min-w-0 truncate text-[12px] font-normal leading-4 tabular-nums";
const headerLabel = ( const headerLabel = (
@@ -52,7 +54,7 @@ export function ThinkingReasoningShell({
<Activity className={cn("h-3.5 w-3.5 shrink-0", active ? "activity-current" : "text-muted-foreground")} strokeWidth={1.5} aria-hidden> <Activity className={cn("h-3.5 w-3.5 shrink-0", active ? "activity-current" : "text-muted-foreground")} strokeWidth={1.5} aria-hidden>
{active ? <path className="activity-current-trace" pathLength={100} d="M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2" /> : null} {active ? <path className="activity-current-trace" pathLength={100} d="M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2" /> : null}
</Activity> </Activity>
{headerLabel} {!compactPreview && headerLabel}
</> </>
); );
return ( return (
@@ -64,8 +66,8 @@ export function ThinkingReasoningShell({
data-block-context-expanded={contextual && expanded ? true : undefined} data-block-context-expanded={contextual && expanded ? true : undefined}
> >
{showHeader ? <div className={cn( {showHeader ? <div className={cn(
"flex min-h-7 items-center gap-1.5", "min-h-7 items-center",
preview && "max-sm:flex-col max-sm:items-stretch max-sm:gap-0", compactPreview ? "grid grid-cols-1" : "flex gap-1.5",
)}> )}>
{hasDetails ? ( {hasDetails ? (
<button <button
@@ -96,7 +98,11 @@ export function ThinkingReasoningShell({
{headerContent} {headerContent}
</div> </div>
)} )}
{preview ? (
<div className={cn("min-w-0 flex-1", compactPreview && "pointer-events-none col-start-1 row-start-1 ms-7")}>
{preview} {preview}
</div>
) : null}
</div> : null} </div> : null}
{hasDetails ? ( {hasDetails ? (