From 743c51e81f930fae13ca7850265b9557180aec41 Mon Sep 17 00:00:00 2001 From: chengyongru <61816729+chengyongru@users.noreply.github.com> Date: Wed, 21 Oct 2026 13:10:05 +0800 Subject: [PATCH] fix(webui): stabilize earlier-history loading and reclaim space (#6349) * fix(webui): retain smoothly revealed history loading headers * refactor(webui): simplify history loading feedback * fix(webui): keep retained history headers clear of preceding text * fix(webui): reclaim completed history loading space * refactor(webui): group history projection handoff with navigation * test(webui): synchronize history motion observations * fix(webui): collapse history completion geometry handoff --- THIRD_PARTY_NOTICES.md | 34 + docs/webui.md | 2 + webui/COMPONENTS.md | 6 + webui/browser/fixture.tsx | 2 +- webui/browser/history-boundary-fixture.tsx | 7 +- webui/browser/history-boundary.spec.ts | 902 ++++++++++++++++-- webui/bun.lock | 9 + webui/package-lock.json | 61 ++ webui/package.json | 1 + .../components/thread/ThreadHistoryStatus.tsx | 15 +- .../src/components/thread/ThreadMessages.tsx | 30 +- webui/src/components/thread/ThreadShell.tsx | 32 +- .../src/components/thread/ThreadViewport.tsx | 187 ++-- .../thread/thread-history-spring.ts | 210 ++-- webui/src/components/thread/thread-motion.ts | 39 +- webui/src/globals.css | 15 +- webui/src/hooks/usePromptHistory.ts | 16 +- webui/src/tests/subagent-tasks.test.tsx | 9 +- webui/src/tests/thread-history-spring.test.ts | 176 ++-- .../src/tests/thread-history-status.test.tsx | 33 +- webui/src/tests/thread-motion.test.ts | 62 +- webui/src/tests/thread-shell.test.tsx | 85 +- webui/src/tests/thread-viewport.test.tsx | 35 +- webui/src/tests/usePromptHistory.test.tsx | 46 + 24 files changed, 1658 insertions(+), 356 deletions(-) diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 72fb1d9a9..e92b666f5 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -205,3 +205,37 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ``` + + +--- + +## Motion — history-boundary springs (MIT) + +- **Source**: https://github.com/motiondivision/motion +- **Components**: `motion`, `framer-motion`, and `motion-dom` 14.4.0; `motion-utils` 14.1.1. +- **Bundled**: `nanobot/web/dist/assets/ThreadShell-*.js` + +``` +The MIT License (MIT) + +Copyright (c) 2024 [Motion](https://motion.dev) B.V. +Copyright (c) 2018 Framer B.V. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` diff --git a/docs/webui.md b/docs/webui.md index 4a98862ab..5e3ca5aa7 100644 --- a/docs/webui.md +++ b/docs/webui.md @@ -119,6 +119,8 @@ To use work from another topic, mention it with `@` and tell nanobot what you ne The message timeline shows replies and agent activity. Expand the **Worked for** section to inspect the reasoning and tool activity for a completed turn. +To load earlier messages, scroll past the oldest loaded message, or pull down far enough and release on touch devices. The muted loading indicator settles into view while the request runs. When loading succeeds, the indicator and its temporary space disappear and normal message spacing returns. If loading fails, the blocks turn red; hover for error details, then pull again or select the red blocks to retry. If there are no earlier messages, pulling at the real history boundary briefly shows **No earlier messages**. + If the connection drops, the host control shows **Reconnecting**. Tasks in persistent topics can continue during the interruption. After reconnecting, task indicators and completed replies update automatically, including topics you have switched away from. Some text generated while disconnected may appear only after the task finishes. [Temporary chats](#temporary-chats) end when their connection is lost. When the agent writes or edits files, the activity item shows the target path, status, and changed line counts. Choose **Settings → Appearance → File edit display** to control the detail: **Summary** shows the change summary, **Diff** shows available unified patches inline, and **Collapsed diff** lets you expand them with **View diff**. Large diffs may hide unchanged lines or truncate the inline preview. Select the filename in the activity row to open the read-only file preview panel. diff --git a/webui/COMPONENTS.md b/webui/COMPONENTS.md index 5c260e513..b9f3f3a13 100644 --- a/webui/COMPONENTS.md +++ b/webui/COMPONENTS.md @@ -49,6 +49,12 @@ Supporting hooks and display-model helpers stay near the feature that owns them. `onChat` provides live events to task and model observers. `useNanobotStream` uses `onTranscript` as the single transcript owner, receiving queued events once followed by live events. +## History-boundary motion + +History request hooks own loading, pagination and errors. `usePromptHistory.operation` keeps jump/newer feedback separate from an older-page slot, including failed reads and retry; index errors have no page operation. `ThreadHistorySpring` owns input resistance, gesture thresholds and transient/rest/held targets; Motion owns spring integration, frame scheduling and interruption velocity. The reduced-motion preference removes transient travel while preserving request and committed-slot behavior. The spring never writes `scrollTop`. `ThreadViewport` hands a triggered reveal to a fixed-height slot before the original boundary display unit through `ThreadMessages.beforeUnit`, subtracting that slot from the remaining transform. `ThreadMessages.topInset` remains the single normal gutter at the start of the currently rendered list and does not travel into the middle of the timeline with a loading slot; the header paints inside its own slot, not above it over earlier text. The leading content (including unlinked tasks) has its own stable keyed prelude alongside the display units, preserving identity and disclosure state across remote and local cached prepends. The scroller's `scroll-padding-top` remains the prompt-navigation inset. The preceding message margin belongs before the slot, and reading-anchor measurements exclude the slot only for following units. This keeps the handoff and later prepends continuous without a second scroll writer. The temporary loading slot stays in the message flow while a request is pending and on failure, so native scrolling carries feedback out of view; successful completion, including an exhausted result, removes the slot and its old-boundary gutter, restoring normal message spacing. `ThreadViewport` measures and compensates the active reading anchor through the existing camera when scroll bounds permit; explicit navigation and conversation changes take priority, and at a scroll bound the camera clamps rather than preserving space artificially. The leading top inset remains a single normal gutter when the historical boundary is no longer first. Explicit navigation and conversation changes reset the reveal. Boundary feedback without a real request remains transient. + +Prompt navigation retains at most three server pages. Static ready Blocks appear only during an uncommitted boundary pull; a completed header is hidden and offers no second pagination entry point. Loading continues at the new boundary, where the header binds to the current first display unit for wheel, touch and keyboard alike; page eviction therefore does not remove the header or the message being read. A failure animates the same Blocks in red without visible error text; hovering shows details, and selecting the red Blocks or a fresh boundary gesture starts another request. Failed reads suppress scroll-triggered automatic requests, not explicit user input. + ## Typography Use the text roles in `tailwind.config.js` for shared metrics: `text-ui` for navigation, `text-control-label` for controls, `text-ui-label` for compact labels, `text-caption` for auxiliary text, and `text-title` / `text-ui-heading` for interface headings. These roles stay independent of reading preferences. Register new size utilities in `src/lib/utils.ts` so `cn()` distinguishes them from text colors. diff --git a/webui/browser/fixture.tsx b/webui/browser/fixture.tsx index ee370d674..3c8c2e4ab 100644 --- a/webui/browser/fixture.tsx +++ b/webui/browser/fixture.tsx @@ -152,7 +152,7 @@ createRoot(document.getElementById("root")!).render( : parameters.get("case") === "typography" ? : parameters.get("case") === "history-boundary" - ? + ? : parameters.get("case") === "diagrams" ? : parameters.get("case") === "thread-loading" diff --git a/webui/browser/history-boundary-fixture.tsx b/webui/browser/history-boundary-fixture.tsx index 307e1aa12..74c2aca66 100644 --- a/webui/browser/history-boundary-fixture.tsx +++ b/webui/browser/history-boundary-fixture.tsx @@ -1,5 +1,7 @@ import { Profiler, useState } from "react"; import { ThreadViewport } from "@/components/thread/ThreadViewport"; +import { SubagentTasksProvider } from "@/components/thread/SubagentTasks"; +import { useClient } from "@/providers/ClientProvider"; import { useSessionHistory } from "@/hooks/useSessions"; import { usePromptHistory } from "@/hooks/usePromptHistory"; import type { UIMessage } from "@/lib/types"; @@ -9,7 +11,8 @@ const localMessages: UIMessage[] = Array.from({ length: 280 }, (_, index) => ({ content: `Cached message ${index}`, createdAt: index + 1, })); -export function HistoryBoundaryFixture({ local = false, navigate = false }: { local?: boolean; navigate?: boolean }) { +export function HistoryBoundaryFixture({ local = false, navigate = false, tasks = false }: { local?: boolean; navigate?: boolean; tasks?: boolean }) { + const { client, token } = useClient(); const [key, setKey] = useState("websocket:boundary-a"); const history = useSessionHistory(local ? null : key); const messages = local ? localMessages : history.messages; @@ -21,11 +24,13 @@ export function HistoryBoundaryFixture({ local = false, navigate = false }: { lo { window.dispatchEvent(new CustomEvent("history-boundary-render", { detail: { phase, actualDuration } })); }}> + History boundary fixture} /> + ; } diff --git a/webui/browser/history-boundary.spec.ts b/webui/browser/history-boundary.spec.ts index 6952a2321..18420d6df 100644 --- a/webui/browser/history-boundary.spec.ts +++ b/webui/browser/history-boundary.spec.ts @@ -8,9 +8,11 @@ function historyPage(start: number, count = 12, more = start > 0) { has_more_before: more, has_more_after: start + count < 52 } }; } -async function installHistory(page: Page) { +async function installHistory(page: Page, initialStart = 40, initialCount = 12) { const reads: string[] = []; const pending: Array<(value: "success" | "error") => void> = []; + let fastResponse = false; + let releaseFastResponse: (() => void) | null = null; await page.route("**/api/sessions/**", async (route) => { const url = new URL(route.request().url()); if (url.pathname.endsWith("/prompts")) return route.fulfill({ json: { @@ -19,17 +21,26 @@ async function installHistory(page: Page) { if (!url.pathname.endsWith("/webui-thread")) return route.fulfill({ json: {} }); if (url.pathname.includes("boundary-b")) return route.fulfill({ json: historyPage(0, 2, false) }); const cursor = url.searchParams.get("before") ?? url.searchParams.get("after"); - if (cursor === null) return route.fulfill({ json: historyPage(40) }); + if (cursor === null) return route.fulfill({ json: historyPage(initialStart, initialCount) }); reads.push(url.search); - const outcome = await new Promise<"success" | "error">((resolve) => pending.push(resolve)); + const outcome = fastResponse + ? await new Promise<"success">((resolve) => { releaseFastResponse = () => resolve("success"); }) + : await new Promise<"success" | "error">((resolve) => pending.push(resolve)); if (outcome === "error") return route.fulfill({ status: 503, body: "History unavailable" }); const start = url.searchParams.has("after") ? Number(cursor) : Math.max(0, Number(cursor) - 12); const count = url.searchParams.has("after") ? 12 : Number(cursor) - start; await route.fulfill({ json: historyPage(start, count, start > 0) }); }); - return { reads, complete: (outcome: "success" | "error" = "success") => pending.shift()?.(outcome) }; + return { + reads, + useFastResponse: (value: boolean) => { fastResponse = value; }, + releaseFastResponse: () => { releaseFastResponse?.(); releaseFastResponse = null; }, + complete: (outcome: "success" | "error" = "success") => pending.shift()?.(outcome), + }; } +type HistoryFixture = Awaited>; + async function installShortHistory(page: Page) { let reads = 0; await page.route("**/api/sessions/**", async (route) => { @@ -53,7 +64,7 @@ async function positionAtTop(body: Locator) { node.dispatchEvent(new TouchEvent("touchstart", { bubbles: true, touches: [new Touch({ identifier: 1, target: node, clientX: 180, clientY: 200 })] })); node.dispatchEvent(new TouchEvent("touchend", { bubbles: true })); const first = node.querySelector("[data-thread-display-unit]")!; - return first.getBoundingClientRect().top - node.getBoundingClientRect().top; + return first.getBoundingClientRect().top; }); } @@ -63,60 +74,196 @@ async function displacement(body: Locator) { async function stableLayout(body: Locator) { await body.evaluate(async (node) => { - let previous = -1; + const frame = node.closest(".thread-viewport-frame")!; + const header = node.closest(".thread-viewport")!.querySelector(".thread-history-status"); + const first = node.querySelector("[data-thread-display-unit]"); + let previous: number[] | null = null; let stable = 0; - for (let i = 0; i < 120 && stable < 8; i++) { + for (let i = 0; i < 240 && stable < 8; i++) { await new Promise(requestAnimationFrame); - const value = node.scrollHeight + node.scrollTop; - stable = value === previous ? stable + 1 : 0; + const rect = (element: HTMLElement | null) => { + const box = element?.getBoundingClientRect(); + return [box?.top ?? 0, box?.bottom ?? 0]; + }; + const transform = new DOMMatrix(getComputedStyle(node).transform).m42; + const value = [node.scrollHeight, node.scrollTop, transform, ...rect(frame), ...rect(header), ...rect(first)]; + stable = previous && value.every((coordinate, index) => Math.abs(coordinate - previous![index]!) < 0.01) + ? stable + 1 : 0; previous = value; } + if (stable < 8) throw new Error("Thread history layout did not settle across frame and anchor geometry"); }); } -async function anchorOffset(body: Locator, text: string) { - return body.getByText(text, { exact: true }).evaluate((node) => { - const unit = node.closest("[data-thread-display-unit]")!; - const scroller = node.closest(".thread-message-viewport")!; - return unit.getBoundingClientRect().top - scroller.getBoundingClientRect().top; - }); +async function anchorTop(body: Locator, text: string) { + return body.getByText(text, { exact: true }).evaluate((node) => + node.closest("[data-thread-display-unit]")!.getBoundingClientRect().top); } -test("continuous wheel input holds real loading visible and preserves the reading anchor through prepend and delayed layout", async ({ page }) => { - const history = await installHistory(page); - await page.goto("/browser/fixture.html?case=history-boundary"); +async function openSettledHistory(page: Page, query = "") { + await page.goto(`/browser/fixture.html?case=history-boundary${query}`); const body = page.getByTestId("thread-message-region"); await expect(body).toBeVisible(); await stableLayout(body); + return { body, header: page.locator(".thread-history-status"), slot: body.locator(".thread-history-slot") }; +} + +async function requestOlderWithWheel(body: Locator, history: HistoryFixture, readCount: number) { + await body.hover(); + await body.page().mouse.wheel(0, -120); + await expect.poll(() => history.reads.length).toBe(readCount); +} + +async function positionReadingAnchor(body: Locator, text: string) { + await body.getByText(text, { exact: true }).evaluate((node) => { + const unit = node.closest("[data-thread-display-unit]")!; + const scroller = unit.closest(".thread-message-viewport")!; + scroller.scrollTop += unit.getBoundingClientRect().top - scroller.getBoundingClientRect().top - 280; + }); + await stableLayout(body); + return anchorTop(body, text); +} + +async function completePrepend(history: HistoryFixture, body: Locator, firstText: string, anchorText: string, expectedTop: number) { + history.complete(); + await expect(body.getByText(firstText, { exact: true })).toBeAttached(); + await expect(body.page().locator(".thread-history-status")).toHaveCount(0); + await stableLayout(body); + await expectAnchorCoordinate(body, anchorText, expectedTop); +} + +async function themeColor(locator: Locator, token: "--muted-foreground" | "--destructive") { + return locator.evaluate((node, variable) => { + const probe = document.createElement("span"); + probe.style.color = `hsl(var(${variable}))`; + node.append(probe); + const color = getComputedStyle(probe).color; + probe.remove(); + return color; + }, token); +} + +// Use the fixed viewport, never the transformed scroller, as the coordinate frame. +async function historyGeometry(body: Locator, text: string) { + return body.getByText(text, { exact: true }).evaluate((node) => { + const unit = node.closest("[data-thread-display-unit]")!.getBoundingClientRect(); + const frame = node.closest(".thread-viewport-frame")!.getBoundingClientRect(); + const scroller = node.closest(".thread-message-viewport")!; + const header = node.closest(".thread-viewport")!.querySelector(".thread-history-status")?.getBoundingClientRect(); + const slot = scroller.querySelector(".thread-history-slot"); + return { + headerTop: header?.top ?? 0, headerBottom: header?.bottom ?? 0, headerHeight: header?.height ?? 0, + visibleHeight: header ? Math.max(0, Math.min(header.bottom, frame.bottom) - Math.max(header.top, frame.top)) : 0, + anchorTop: unit.top, frameTop: frame.top, scrollTop: scroller.scrollTop, + transformY: new DOMMatrix(getComputedStyle(scroller).transform).m42, + slotHeight: slot ? Number.parseFloat(getComputedStyle(slot).height) : 0, + slotBeforeKey: slot?.parentElement?.nextElementSibling?.getAttribute("data-thread-display-unit") ?? null, + firstKey: scroller.querySelector("[data-thread-display-unit]")?.getAttribute("data-thread-display-unit"), + }; + }); +} + +type HistoryGeometry = Awaited>; + +async function expectCoordinates(body: Locator, text: string, reference: HistoryGeometry) { + let latest = reference; + try { + await expect.poll(async () => { + latest = await historyGeometry(body, text); + return Math.max(...(["headerTop", "headerBottom", "anchorTop", "frameTop"] as const) + .map((key) => Math.abs(latest[key] - reference[key]))); + }, { message: `${text}: header and reading unit must keep their fixed viewport coordinates` }).toBeLessThan(1); + } catch (error) { + const diagnostic = JSON.stringify({ text, before: reference, after: latest }); + console.log("history-coordinate-failure", diagnostic); + await test.info().attach("history-coordinate-failure", { body: diagnostic, contentType: "application/json" }); + throw error; + } +} + +async function expectHeaderInsideSlot(body: Locator) { + const geometry = await body.locator(".thread-history-slot").evaluate((slot) => { + const header = slot.querySelector(".thread-history-status")!.getBoundingClientRect(); + const own = slot.getBoundingClientRect(); + const before = slot.parentElement!.previousElementSibling?.getBoundingClientRect(); + const after = slot.parentElement!.nextElementSibling!.getBoundingClientRect(); + return { headerTop: header.top, headerBottom: header.bottom, slotTop: own.top, slotBottom: own.bottom, + previousBottom: before?.bottom, nextTop: after.top }; + }); + expect(Math.abs(geometry.headerTop - geometry.slotTop)).toBeLessThan(1); + expect(Math.abs(geometry.headerBottom - geometry.slotBottom)).toBeLessThan(1); + if (geometry.previousBottom !== undefined) expect(geometry.previousBottom).toBeLessThanOrEqual(geometry.headerTop); + expect(geometry.headerBottom).toBeLessThanOrEqual(geometry.nextTop); +} + +async function expectHeld(body: Locator, text: string) { + await expect(body.locator(".thread-history-slot")).toHaveCSS("height", "48px"); + await expect.poll(() => displacement(body)).toBe(0); + await expect.poll(async () => (await historyGeometry(body, text)).visibleHeight).toBeCloseTo(48, 0); + await expectHeaderInsideSlot(body); + return historyGeometry(body, text); +} + +function expectSameScroll(before: HistoryGeometry, after: HistoryGeometry, delta: number) { + expect(delta).toBeGreaterThan(0); + expect(Math.abs(after.headerTop - before.headerTop + delta)).toBeLessThan(1); + expect(Math.abs(after.anchorTop - before.anchorTop + delta)).toBeLessThan(1); +} + +async function expectNoVisibleHistoryText(header: Locator) { + await expect.poll(() => header.evaluate((node) => { + const content = node.cloneNode(true) as HTMLElement; + content.querySelectorAll(".sr-only").forEach((label) => label.remove()); + return content.textContent?.trim(); + })).toBe(""); +} + +test("wheel loading hands off to a retained 48px slot; prepend and delayed layout keep absolute reading coordinates", async ({ page }) => { + const history = await installHistory(page); + const { body, header } = await openSettledHistory(page); const nativeTop = await body.evaluate((node) => node.scrollTop); await body.hover(); await page.mouse.wheel(0, -100); await expect.poll(() => body.evaluate((node) => node.scrollTop)).toBeLessThan(nativeTop); expect(await displacement(body)).toBe(0); expect(history.reads).toHaveLength(0); - await positionAtTop(body); + const originalTop = await positionAtTop(body); + await expect(header).not.toBeInViewport(); await body.hover(); await page.mouse.wheel(80, 0); expect(await displacement(body)).toBe(0); expect(history.reads).toHaveLength(0); - await body.hover(); for (const delta of [-100, -70, -45, -28, -16, -8, -3]) await page.mouse.wheel(0, delta); - await expect(page.locator('.thread-history-status[data-state="loading"]')).toBeInViewport(); - await expect(page.locator(".thread-history-blocks")).toHaveCSS("color", "rgb(211, 94, 20)"); + await expect(header).toHaveAttribute("data-state", "loading"); + await expect(header.locator(".thread-history-blocks")).toHaveCSS("color", "rgb(98, 98, 106)"); + await expect(header.locator(".thread-history-blocks > span").first()).not.toHaveCSS("animation-name", "none"); expect(history.reads).toHaveLength(1); - await expect.poll(() => displacement(body)).toBeCloseTo(20, 1); - const still = await displacement(body); + const held = await expectHeld(body, "Question 40"); + expect(held.anchorTop - originalTop).toBeCloseTo(48, 0); + expect(held.headerTop).toBeCloseTo(held.frameTop, 0); await page.waitForTimeout(150); - expect(Math.abs(await displacement(body) - still)).toBeLessThan(0.1); - await page.screenshot({ path: "test-results/history-boundary-loading.png" }); + await expectCoordinates(body, "Question 40", held); + await page.screenshot({ path: test.info().outputPath("history-loading-held.png") }); - await body.evaluate((node) => { node.scrollTop = 500; }); - await expect(page.locator('.thread-history-status[data-state="loading"]')).toBeInViewport(); - await expect.poll(() => displacement(body)).toBe(0); - const reading = await anchorOffset(body, "Question 40"); - history.complete(); - await expect(body.getByText("Question 28", { exact: true })).toBeAttached(); - expect(Math.abs(await anchorOffset(body, "Question 40") - reading)).toBeLessThan(1); + // A programmatic scroll may clip the header, but must not retract its slot or spring. + await body.evaluate((node) => { node.scrollTop = 12; }); + await stableLayout(body); + const programmed = await historyGeometry(body, "Question 40"); + expectSameScroll(held, programmed, 12); + expect(programmed.visibleHeight).toBeCloseTo(36, 0); + expect(await displacement(body)).toBe(0); + await expect(body.locator(".thread-history-slot")).toHaveCSS("height", "48px"); + await body.evaluate((node) => { node.scrollTop = 0; }); + await stableLayout(body); + await expectCoordinates(body, "Question 40", held); + const preCompletionAnchorTop = await positionReadingAnchor(body, "Question 40"); + + await completePrepend(history, body, "Question 28", "Question 40", preCompletionAnchorTop); + const completedSpacing = await historyBoundarySpacing(body, "Question 40", "Question 41"); + const completedAnchorTop = await anchorTop(body, "Question 40"); + console.log("history-completion-spacing", JSON.stringify({ ...completedSpacing, readingDeltaPx: completedAnchorTop - preCompletionAnchorTop })); + expect(Math.abs(completedSpacing.boundaryGap! - completedSpacing.referenceGap!), JSON.stringify(completedSpacing)).toBeLessThan(1); + expect(completedSpacing.slotCount).toBe(0); expect(history.reads).toHaveLength(1); await body.getByText("Question 28", { exact: true }).evaluate((node) => { @@ -124,116 +271,337 @@ test("continuous wheel input holds real loading visible and preserves the readin delayed.style.height = "160px"; node.closest("[data-thread-display-unit]")!.prepend(delayed); }); - await page.waitForTimeout(100); - expect(Math.abs(await anchorOffset(body, "Question 40") - reading)).toBeLessThan(1); + await stableLayout(body); + await expectAnchorCoordinate(body, "Question 40", preCompletionAnchorTop); + await expect(body.locator(".thread-history-slot")).toHaveCount(0); + await page.screenshot({ path: test.info().outputPath("history-prepend-stable.png") }); + + // The reclaimed boundary scrolls as ordinary message flow, with no retained spacer. + const beforeScroll = await body.evaluate((node) => node.scrollTop); + const anchorBeforeScroll = await anchorTop(body, "Question 40"); + await body.hover(); + await page.mouse.wheel(0, 16); + await expect.poll(() => body.evaluate((node) => node.scrollTop)).toBeGreaterThan(beforeScroll); + await stableLayout(body); + const delta = await body.evaluate((node) => node.scrollTop) - beforeScroll; + expect(Math.abs((await anchorTop(body, "Question 40")) - anchorBeforeScroll + delta)).toBeLessThan(1); + expect(await displacement(body)).toBe(0); + await page.screenshot({ path: test.info().outputPath("history-native-scroll-reclaimed.png") }); + await page.mouse.wheel(0, 96); + await expect(body.locator(".thread-history-slot")).toHaveCount(0); + expect(history.reads).toHaveLength(1); }); -test("touch short-pull cancellation, armed release, loading takeover, and conversation changes converge", async ({ browser, baseURL }) => { +test("unlinked task prelude stays with the retained boundary when earlier messages load", async ({ page }) => { + const history = await installHistory(page); + await page.route("**/api/sessions/**/subagents", (route) => route.fulfill({ json: { tasks: [{ + task_id: "legacy", revision: 1, label: "Earlier check", task_description: "Check earlier work", + state: "done", phase: "completed", elapsed_seconds: 2, iteration: 1, + tool_events: [], usage: null, receipts: {}, result: "Verified", partial: false, + stop_reason: null, error: null, origin_turn_id: "legacy-turn", origin_message_id: null, + created_at: 100, completed_at: 102, + }] } })); + await page.goto("/browser/fixture.html?case=history-boundary&tasks"); + const body = page.getByTestId("thread-message-region"); + const otherTasks = body.getByRole("region", { name: "Other tasks" }); + await expect(otherTasks).toBeAttached(); + await otherTasks.getByRole("button", { name: /Other tasks/ }).click(); + await expect(otherTasks.getByRole("button", { name: /Earlier check Completed/ })).toBeVisible(); + await stableLayout(body); + const originalTop = await positionAtTop(body); + await body.hover(); + await page.mouse.wheel(0, -100); + await expect(page.locator(".thread-history-status")).toHaveAttribute("data-state", "loading"); + const held = await expectHeld(body, "Question 40"); + expect(held.anchorTop - originalTop).toBeCloseTo(48, 0); + const preCompletionAnchorTop = await positionReadingAnchor(body, "Question 40"); + history.complete(); + await expect(body.getByText("Question 28", { exact: true })).toBeAttached(); + await expect(page.locator(".thread-history-slot")).toHaveCount(0); + await stableLayout(body); + await expectAnchorCoordinate(body, "Question 40", preCompletionAnchorTop); + await expect(otherTasks).toHaveCount(1); + await expect(otherTasks.getByRole("button", { name: /Other tasks/ })).toHaveAttribute("aria-expanded", "true"); + expect(history.reads).toHaveLength(1); +}); + +test("touch reveals a static partial ready header, arms only on release, and retains a stable full loading header", async ({ browser, baseURL }) => { const context = await browser.newContext({ viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true, baseURL }); const page = await context.newPage(); const history = await installHistory(page); try { - await page.goto("/browser/fixture.html?case=history-boundary"); - const body = page.getByTestId("thread-message-region"); - await expect(body).toBeVisible(); - await stableLayout(body); + const { body, header } = await openSettledHistory(page); await positionAtTop(body); + await expect(header).not.toBeInViewport(); const cdp = await context.newCDPSession(page); const touch = async (type: "touchStart" | "touchMove" | "touchEnd", y = 200, x = 180) => cdp.send("Input.dispatchTouchEvent", { type, touchPoints: type === "touchEnd" ? [] : [{ x, y, id: 1 }], }); await touch("touchStart"); - await touch("touchMove", 210, 300); + // Leftward tests horizontal intent without Chromium's native swipe-back gesture. + await touch("touchMove", 210, 60); await touch("touchEnd"); expect(await displacement(body)).toBe(0); expect(history.reads).toHaveLength(0); - await touch("touchStart"); - await touch("touchMove", 240); - const pulled = await displacement(body); - expect(pulled).toBeGreaterThan(0); - await touch("touchEnd"); - expect(await displacement(body)).toBeGreaterThan(0); - await expect.poll(() => displacement(body)).toBe(0); - expect(history.reads).toHaveLength(0); await touch("touchStart"); - await touch("touchMove", 330); - await expect(page.locator('.thread-history-status[data-state="loading"]')).toBeVisible(); - expect(await displacement(body)).toBeGreaterThanOrEqual(42); + await touch("touchMove", 240); + const pulled = await displacement(body); + const partial = await historyGeometry(body, "Question 40"); + expect(pulled).toBeGreaterThan(0); + expect(pulled).toBeLessThan(80); + expect(partial.visibleHeight).toBeGreaterThan(0); + expect(partial.visibleHeight).toBeLessThan(partial.headerHeight); + await expect(header).toHaveAttribute("data-state", "ready"); + await expect(header.locator(".thread-history-blocks > span").first()).toHaveCSS("animation-name", "none"); + expect(history.reads).toHaveLength(0); + await page.screenshot({ path: test.info().outputPath("history-touch-partial-ready.png") }); + await touch("touchEnd"); + await expect.poll(() => displacement(body)).toBe(0); + await expect(header).not.toBeInViewport(); + expect(history.reads).toHaveLength(0); + + await touch("touchStart"); + await touch("touchMove", 400); + const armedDistance = await displacement(body); + expect(armedDistance).toBeGreaterThanOrEqual(56); + expect(armedDistance).toBeLessThan(80); + await expect(header).toHaveAttribute("data-state", "ready"); expect(history.reads).toHaveLength(0); await touch("touchEnd"); await expect.poll(() => history.reads.length).toBe(1); - await expect.poll(() => displacement(body)).toBeCloseTo(20, 1); + await expect(header).toHaveAttribute("data-state", "loading"); + const held = await expectHeld(body, "Question 40"); + await page.waitForTimeout(150); + await expectCoordinates(body, "Question 40", held); + await page.screenshot({ path: test.info().outputPath("history-touch-held.png") }); + await touch("touchStart"); await touch("touchMove", 240); - expect(await displacement(body)).toBeGreaterThan(20); await touch("touchEnd"); - await expect.poll(() => displacement(body)).toBeCloseTo(20, 1); + await expectHeld(body, "Question 40"); + await expectCoordinates(body, "Question 40", held); expect(history.reads).toHaveLength(1); + + // Native finger-up movement must be free to scroll the retained header away. + await touch("touchStart", 400); + await touch("touchMove", 376); + await touch("touchMove", 360); + await expect.poll(() => body.evaluate((node) => node.scrollTop)).toBeGreaterThan(0); + const scrolled = await historyGeometry(body, "Question 40"); + console.log("history-touch-native-scroll", JSON.stringify({ held, scrolled })); + expectSameScroll(held, scrolled, scrolled.scrollTop); + expect(scrolled.visibleHeight).toBeGreaterThan(0); + expect(scrolled.visibleHeight).toBeLessThan(48); + await touch("touchEnd"); await page.getByRole("button", { name: "Switch conversation" }).click(); await expect(body.getByText("Question 1", { exact: true })).toBeVisible(); expect(await displacement(body)).toBe(0); + await expect(body.locator(".thread-history-slot")).toHaveCount(0); history.complete(); await page.waitForTimeout(100); await expect(page.locator('.thread-history-status[data-state="loading"]')).toHaveCount(0); } finally { await context.close(); } }); -test("failure stays actionable away from the top; retry, fast completion and exhausted reduced-motion state remain truthful", async ({ page }) => { +test("reduced-motion failure keeps its functional 48px slot and retry until naturally scrolled away", async ({ page }) => { await page.emulateMedia({ reducedMotion: "reduce", colorScheme: "dark" }); const history = await installHistory(page); await page.goto("/browser/fixture.html?case=history-boundary"); await page.locator("html").evaluate((node) => node.classList.add("dark")); await expect(page.locator("main")).toHaveCSS("background-color", "rgb(48, 48, 48)"); const body = page.getByTestId("thread-message-region"); + const header = page.locator(".thread-history-status"); await expect(body).toBeVisible(); await stableLayout(body); - await positionAtTop(body); - await page.getByRole("button", { name: "Load earlier messages", exact: true }).click(); - await expect.poll(() => history.reads.length).toBe(1); - expect(await displacement(body)).toBe(0); - const block = page.locator(".thread-history-blocks > span").first(); - await expect(block).toHaveCSS("background-color", "rgb(211, 94, 20)"); - expect(await block.evaluate((node) => getComputedStyle(node).animationName)).toBe("none"); - await body.evaluate((node) => { node.scrollTop = 600; }); + const originalTop = await positionAtTop(body); + await requestOlderWithWheel(body, history, 1); + const held = await expectHeld(body, "Question 40"); + expect(held.anchorTop - originalTop).toBeCloseTo(48, 0); + const block = header.locator(".thread-history-blocks > span").first(); + const normalColor = await header.locator(".thread-history-blocks").evaluate((node) => getComputedStyle(node).color); + const mutedColor = await themeColor(header, "--muted-foreground"); + expect(normalColor).toBe(mutedColor); + console.log(`history-colors dark loading=${normalColor}`); + await expect(block).toHaveCSS("animation-name", "none"); history.complete("error"); const retry = page.getByRole("button", { name: "Loading failed. Retry", exact: true }); await expect(retry).toBeInViewport(); + await page.waitForTimeout(150); + await expectCoordinates(body, "Question 40", held); const failedBlocks = retry.locator(".thread-history-blocks"); await expect(failedBlocks).toHaveCSS("width", "24px"); await expect(failedBlocks).toHaveCSS("height", "24px"); await expect(failedBlocks).toHaveCSS("color", "rgb(252, 165, 165)"); await expect(failedBlocks.locator("span").first()).toHaveCSS("animation-name", "none"); - await expect(failedBlocks.locator("span").first()).toHaveCSS("transform", "none"); - await retry.focus(); + await expectHeaderInsideSlot(body); + await expectNoVisibleHistoryText(header); + await expect(page.getByRole("tooltip")).toHaveCount(0); + await failedBlocks.hover(); await expect(page.getByRole("tooltip")).toHaveText("HTTP 503"); - await retry.click(); + await page.screenshot({ path: test.info().outputPath("history-failure-dark.png") }); + await page.mouse.move(16, 20, { steps: 5 }); + await expect(page.getByRole("tooltip")).toHaveCount(0); + + await body.evaluate((node) => { node.scrollTop = 8; }); + await stableLayout(body); + expectSameScroll(held, await historyGeometry(body, "Question 40"), 8); + expect(await displacement(body)).toBe(0); + await body.evaluate((node) => { node.scrollTop = 0; }); + await expectCoordinates(body, "Question 40", held); + await body.hover(); + await page.mouse.wheel(0, 96); + await expect(retry).not.toBeInViewport(); + await expect(header).toHaveAttribute("data-state", "error"); + await expect(body.locator(".thread-history-slot")).toHaveCSS("height", "48px"); + expect(history.reads).toHaveLength(1); + await body.evaluate((node) => { node.scrollTop = 0; }); + await failedBlocks.click(); await expect.poll(() => history.reads.length).toBe(2); - await expect(page.locator(".thread-history-blocks")).toHaveCSS("width", "20px"); - await expect(page.locator(".thread-history-blocks")).toHaveCSS("color", "rgb(211, 94, 20)"); + await expect(header).toHaveAttribute("data-state", "loading"); + await expect(header.locator(".thread-history-blocks")).toHaveCSS("width", "20px"); + await expect(block).toHaveCSS("animation-name", "none"); history.complete(); await expect(body.getByText("Question 28", { exact: true })).toBeAttached(); - await expect(page.locator('.thread-history-status[data-state="loading"]')).toHaveCount(0); - await expect(page.locator('.thread-history-status[data-state="exhausted"]')).toHaveCount(0); - for (const start of [16, 4, 0]) { + await expect(header).toHaveCount(0); + await expectAnchorCoordinate(body, "Question 40", held.anchorTop); + await expect(body.locator(".thread-history-slot")).toHaveCount(0); + + for (const [index, start] of [16, 4, 0].entries()) { await positionAtTop(body); - await page.getByRole("button", { name: "Load earlier messages", exact: true }).click(); - await expect.poll(() => history.reads.length).toBe(start === 16 ? 3 : start === 4 ? 4 : 5); + await requestOlderWithWheel(body, history, index + 3); history.complete(); await expect(body.getByText(`Question ${start}`, { exact: true })).toBeAttached(); } await positionAtTop(body); const exhausted = page.locator('.thread-history-status[data-state="exhausted"]'); - await expect(exhausted).toHaveCount(0); await body.hover(); await page.mouse.wheel(0, -120); await expect(exhausted).toBeInViewport(); expect(await displacement(body)).toBe(0); expect(history.reads).toHaveLength(5); - await page.screenshot({ path: "test-results/history-boundary-exhausted-dark.png" }); + await page.screenshot({ path: test.info().outputPath("history-exhausted-dark.png") }); await expect(exhausted).toHaveCount(0); }); +for (const elapsedMs of [0, 80]) test(`fast responses reclaim completed slots and keep the next boundary loading${elapsedMs ? " during spring travel" : ""}`, async ({ page }) => { + const history = await installHistory(page); + history.useFastResponse(true); + await page.clock.install({ time: new Date("2026-01-01T00:00:00Z") }); + const { body, header } = await openSettledHistory(page); + await positionAtTop(body); + await expect(header).toHaveAttribute("data-state", "ready"); + await expect(header).not.toBeInViewport(); + await body.hover(); + await page.clock.pauseAt(new Date("2026-01-01T01:00:00Z")); + await page.mouse.wheel(0, -120); + await expect.poll(() => history.reads.length).toBe(1); + await expect(header).toHaveAttribute("data-state", "loading"); + if (elapsedMs > 0) await page.clock.runFor(elapsedMs); + const beforeFastRead = await historyGeometry(body, "Question 40"); + expect(beforeFastRead.slotHeight).toBe(48); + expect(Math.abs(beforeFastRead.transformY)).toBeGreaterThan(0); + if (elapsedMs > 0) expect(beforeFastRead.transformY).toBeGreaterThan(-48); + history.releaseFastResponse(); + await expect(body.getByText("Question 28", { exact: true })).toBeAttached(); + expect(history.reads).toHaveLength(1); + await expect(header).toHaveCount(0); + await expect(body.locator(".thread-history-slot")).toHaveCount(0); + const afterFastRead = await historyGeometry(body, "Question 40"); + console.log("history-fast-completion-geometry", JSON.stringify({ before: beforeFastRead, after: afterFastRead })); + await expectAnchorCoordinate(body, "Question 40", beforeFastRead.anchorTop); + const fastSpacing = await historyBoundarySpacing(body, "Question 40", "Question 41"); + expect(Math.abs(fastSpacing.boundaryGap! - fastSpacing.referenceGap!)).toBeLessThan(1); + await page.clock.resume(); + await stableLayout(body); + await expectAnchorCoordinate(body, "Question 40", beforeFastRead.anchorTop); + const settledFastSpacing = await historyBoundarySpacing(body, "Question 40", "Question 41"); + expect(Math.abs(settledFastSpacing.boundaryGap! - settledFastSpacing.referenceGap!)).toBeLessThan(1); + await expect(page.locator(".thread-history-slot")).toHaveCount(0); + await page.screenshot({ path: test.info().outputPath("history-fast-ready-hidden.png") }); + + history.useFastResponse(false); + await positionAtTop(body); + await stableLayout(body); + const atNewHead = await historyGeometry(body, "Question 28"); + expect(atNewHead.firstKey).toBe("u28"); + expect(atNewHead.slotBeforeKey).toBeNull(); + expect(atNewHead.slotHeight).toBe(0); + await expect(header).toBeHidden(); + expect(history.reads).toHaveLength(1); + await requestOlderWithWheel(body, history, 2); + await expect(header).toHaveAttribute("data-state", "loading"); + const nextHeld = await expectHeld(body, "Question 28"); + expect(nextHeld.slotBeforeKey).toBe("u28"); + expect(nextHeld.anchorTop - atNewHead.anchorTop).toBeCloseTo(48, 0); + await completePrepend(history, body, "Question 16", "Question 28", nextHeld.anchorTop); + await expect(body.locator(".thread-history-slot")).toHaveCount(0); + expect(history.reads).toEqual(["?limit=120&before=40", "?limit=120&before=28"]); +}); + +test("ordinary middle reading never reveals an exhausted overlay, even when the complete beginning is cached", async ({ page }) => { + const history = await installHistory(page, 0, 52); + await page.goto("/browser/fixture.html?case=history-boundary"); + const body = page.getByTestId("thread-message-region"); + const exhausted = page.getByText("No earlier messages", { exact: true }); + await expect(body.getByText("Question 51", { exact: true })).toBeAttached(); + await stableLayout(body); + await expect(exhausted).toHaveCount(0); + await body.evaluate((node) => { + node.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, button: 0 })); + node.scrollTop = Math.round((node.scrollHeight - node.clientHeight) / 2); + }); + await stableLayout(body); + const middle = await body.evaluate((node) => node.scrollTop); + expect(middle).toBeGreaterThan(48); + expect(middle).toBeLessThan(await body.evaluate((node) => node.scrollHeight - node.clientHeight - 48)); + await expect(exhausted).toHaveCount(0); + await body.hover(); + await page.mouse.wheel(0, -32); + await expect.poll(() => body.evaluate((node) => node.scrollTop)).toBeLessThan(middle); + await expect(exhausted).toHaveCount(0); + await page.mouse.wheel(0, 64); + await expect.poll(() => body.evaluate((node) => node.scrollTop)).toBeGreaterThan(middle); + await expect(exhausted).toHaveCount(0); + await expect(body.locator(".thread-history-slot")).toHaveCount(0); + expect(await displacement(body)).toBe(0); + expect(history.reads).toHaveLength(0); + await page.screenshot({ path: test.info().outputPath("history-middle-no-exhausted.png") }); +}); + +test("a successful exhausted result reclaims its slot and stays at the real history boundary", async ({ page }) => { + const history = await installHistory(page, 4); + const { body } = await openSettledHistory(page); + const exhausted = page.locator('.thread-history-status[data-state="exhausted"]'); + await expect(exhausted).toHaveCount(0); + await positionAtTop(body); + await requestOlderWithWheel(body, history, 1); + const held = await expectHeld(body, "Question 4"); + history.complete(); + await expect(body.getByText("Question 0", { exact: true })).toBeAttached(); + await stableLayout(body); + await expectAnchorCoordinate(body, "Question 4", held.anchorTop); + const completionReadingDeltaPx = (await anchorTop(body, "Question 4")) - held.anchorTop; + expect(Math.abs(completionReadingDeltaPx)).toBeLessThan(1); + await body.evaluate((node) => { node.scrollTop = 0; node.dispatchEvent(new Event("scroll")); }); + await stableLayout(body); + await expect(exhausted).toBeVisible(); + await expect(body.locator(".thread-history-slot")).toHaveCount(0); + const spacing = await historyBoundarySpacing(body, "Question 4", "Question 5"); + console.log("history-exhausted-spacing", JSON.stringify({ ...spacing, readingDeltaPx: completionReadingDeltaPx })); + expect(Math.abs(spacing.boundaryGap! - spacing.referenceGap!)).toBeLessThan(1); + expect(spacing.slotCount).toBe(0); + await page.screenshot({ path: test.info().outputPath("history-exhausted-reclaimed-at-boundary.png") }); + await body.hover(); + await page.mouse.wheel(0, 600); + await stableLayout(body); + await expect(exhausted).toHaveCount(0); + await expect(body.locator(".thread-history-slot")).toHaveCount(0); + expect(await displacement(body)).toBe(0); + expect(history.reads).toHaveLength(1); + await page.screenshot({ path: test.info().outputPath("history-exhausted-not-floating-in-middle.png") }); +}); + for (const reducedMotion of ["no-preference", "reduce"] as const) { test(`exhausted hints follow wheel and touch feedback, including settlement (${reducedMotion})`, async ({ page, browser, baseURL }) => { await page.emulateMedia({ reducedMotion }); @@ -308,7 +676,7 @@ test("local cached windows expand without network loading and only the complete await expect(body.getByText("Cached message 40", { exact: true })).toBeAttached(); await stableLayout(body); await test.info().attach("local-window-anchor", { body: JSON.stringify({ - before: localAnchor, after: await anchorOffset(body, "Cached message 160"), + before: localAnchor, after: await anchorTop(body, "Cached message 160"), }), contentType: "application/json" }); await expect(page.locator('.thread-history-status[data-state="exhausted"]')).toHaveCount(0); await positionAtTop(body); @@ -335,27 +703,399 @@ test("navigation-window loading and errors remain visible and retry uses the nav await page.keyboard.press("Home"); await page.getByRole("button", { name: "Jump to message: Question 38", exact: true }).click(); await expect(page.locator('.thread-history-status[data-state="loading"]')).toBeInViewport(); + await expect(body.locator(".thread-history-slot")).toHaveCount(0); history.complete(); await expect(body.getByText("Question 38", { exact: true })).toBeInViewport(); await stableLayout(body); await body.hover(); await page.mouse.wheel(0, 10000); await expect.poll(() => history.reads.length).toBe(2); + await expect(page.locator('.thread-history-status[data-state="loading"]')).toBeInViewport(); + await expect(body.locator(".thread-history-slot")).toHaveCount(0); history.complete(); await expect(body.getByText("Question 51", { exact: true })).toBeAttached(); await stableLayout(body); await positionAtTop(body); - await body.hover(); - await page.mouse.wheel(0, -120); - await expect.poll(() => history.reads.length).toBe(3); + await requestOlderWithWheel(body, history, 3); await expect(page.locator('.thread-history-status[data-state="loading"]')).toBeInViewport(); + const held = await expectHeld(body, "Question 38"); + await page.mouse.wheel(0, -80); + await stableLayout(body); + const afterRetryPressure = await historyGeometry(body, "Question 38"); + console.log("history-navigation-pressure-settled", JSON.stringify({ held, afterRetryPressure })); + await expectCoordinates(body, "Question 38", held); + expect(history.reads).toHaveLength(3); history.complete("error"); await page.getByRole("button", { name: "Loading failed. Retry", exact: true }).click(); await expect.poll(() => history.reads.length).toBe(4); + const beforeRetryCompletion = await historyGeometry(body, "Question 38"); history.complete(); await expect(body.getByText("Question 26", { exact: true })).toBeAttached(); await expect(page.locator('.thread-history-status[data-state="loading"]')).toHaveCount(0); + await expect(page.locator(".thread-history-status")).toHaveCount(0); + await expect(body.locator(".thread-history-slot")).toHaveCount(0); + await stableLayout(body); + const afterRetryCompletion = await historyGeometry(body, "Question 38"); + console.log("history-navigation-retry-completion", JSON.stringify({ beforeRetryCompletion, afterRetryCompletion })); + await expectAnchorCoordinate(body, "Question 38", held.anchorTop); + const navigationSpacing = await historyBoundarySpacing(body, "Question 38", "Question 39"); + expect(Math.abs(navigationSpacing.boundaryGap! - navigationSpacing.referenceGap!)).toBeLessThan(1); await positionAtTop(body); - await expect(page.locator('.thread-history-status[data-state="loading"]')).toBeInViewport(); + await expect(page.locator('.thread-history-status[data-state="loading"]')).toHaveCount(0); expect(history.reads).toEqual(["?limit=24&after=38", "?limit=24&after=50", "?limit=24&before=38", "?limit=24&before=38"]); }); + +async function jumpViaRail(page: Page, index: number) { + const rail = page.getByTestId("prompt-rail-scroll"); + await expect(rail).toBeVisible(); + await rail.getByRole("button").first().focus(); + await page.keyboard.press(index < 26 ? "Home" : "End"); + await rail.getByRole("button", { name: `Jump to message: Question ${index}`, exact: true }).click(); +} + +test("failed Blocks animate without visible error text; pulling retries once and pending input cannot duplicate the request", async ({ page }) => { + const history = await installHistory(page); + const { body, header, slot } = await openSettledHistory(page); + await positionAtTop(body); + await requestOlderWithWheel(body, history, 1); + const held = await expectHeld(body, "Question 40"); + expect(held.slotBeforeKey).toBe("u40"); + history.complete("error"); + await expect(header).toHaveAttribute("data-state", "error"); + const retry = page.getByRole("button", { name: "Loading failed. Retry", exact: true }); + const blocks = retry.locator(".thread-history-blocks"); + await expect(blocks).toBeInViewport(); + await expect(blocks).toHaveCSS("color", "rgb(185, 28, 28)"); + await expect(blocks.locator("span").first()).not.toHaveCSS("animation-name", "none"); + await expectHeaderInsideSlot(body); + await expectNoVisibleHistoryText(header); + await expect(page.getByRole("tooltip")).toHaveCount(0); + await stableLayout(body); + await expectCoordinates(body, "Question 40", held); + expect(history.reads).toHaveLength(1); + + // This is a fresh pull at the failed boundary, not a ready-button-only path. + await requestOlderWithWheel(body, history, 2); + await expect(header).toHaveAttribute("data-state", "loading"); + await page.mouse.wheel(0, -120); + await page.mouse.wheel(0, -80); + await body.evaluate((node) => { node.tabIndex = 0; node.focus({ preventScroll: true }); }); + await page.keyboard.press("ArrowUp"); + await stableLayout(body); + await expect(slot).toHaveCSS("height", "48px"); + await expect.poll(() => displacement(body)).toBe(0); + expect((await historyGeometry(body, "Question 40")).slotBeforeKey).toBe("u40"); + await expectCoordinates(body, "Question 40", held); + expect(history.reads).toEqual(["?limit=120&before=40", "?limit=120&before=40"]); + + history.complete(); + await expect(body.getByText("Question 28", { exact: true })).toBeAttached(); + await expect(header).toHaveCount(0); + await expect(blocks).toHaveCount(0); + await stableLayout(body); + await expect(slot).toHaveCount(0); + expect((await historyGeometry(body, "Question 40")).slotBeforeKey).toBeNull(); + await expectAnchorCoordinate(body, "Question 40", held.anchorTop); + expect(history.reads).toHaveLength(2); +}); + +test("cross-path unloaded rail jump has visible navigation feedback outside a scrolled-away older slot", async ({ page }) => { + const history = await installHistory(page); + await page.setViewportSize({ width: 1440, height: 900 }); + const { body, slot } = await openSettledHistory(page, "&navigate=1"); + await positionAtTop(body); + await requestOlderWithWheel(body, history, 1); + history.complete(); + await expect(body.getByText("Question 28", { exact: true })).toBeAttached(); + await expect(slot).toHaveCount(0); + await body.hover(); + await page.mouse.wheel(0, 128); + // Start the replacement away from the old bottom so setup cannot prefetch newer. + await positionAtTop(body); + await stableLayout(body); + await expect(slot).toHaveCount(0); + + await jumpViaRail(page, 10); + await expect.poll(() => history.reads.length).toBe(2); + await expect(page.locator('.thread-history-status[data-state="loading"]')).toBeInViewport(); + await expect(slot.locator('.thread-history-status[data-state="loading"]')).toHaveCount(0); + history.complete("error"); + const retry = page.getByRole("button", { name: "Loading failed. Retry", exact: true }); + await expect(retry).toBeInViewport(); + await expect(slot.locator('.thread-history-status[data-state="error"]')).toHaveCount(0); + await retry.click(); + await expect.poll(() => history.reads.length).toBe(3); + await expect(page.locator('.thread-history-status[data-state="loading"]')).toBeInViewport(); + expect(history.reads).toEqual(["?limit=120&before=40", "?limit=24&after=10", "?limit=24&after=10"]); + history.complete(); + await expect(body.getByText("Question 10", { exact: true })).toBeInViewport(); + await expect(page.locator('.thread-history-status[data-state="loading"]')).toHaveCount(0); + await expect(retry).toHaveCount(0); +}); + +test("cross-path newer has visible navigation feedback and forward input retries newer after its older slot scrolls away", async ({ page }) => { + const history = await installHistory(page); + await page.setViewportSize({ width: 1440, height: 900 }); + const { body, slot } = await openSettledHistory(page, "&navigate=1"); + await positionAtTop(body); + await stableLayout(body); + await jumpViaRail(page, 10); + await expect.poll(() => history.reads.length).toBe(1); + history.complete(); + await expect(body.getByText("Question 10", { exact: true })).toBeInViewport(); + await stableLayout(body); + await positionAtTop(body); + await requestOlderWithWheel(body, history, 2); + history.complete(); + await expect(body.getByText("Question 0", { exact: true })).toBeAttached(); + await expect(slot).toHaveCount(0); + await expect.poll(() => displacement(body)).toBe(0); + await body.hover(); + await page.mouse.wheel(0, 128); + await expect(slot).toHaveCount(0); + await page.mouse.wheel(0, 10000); + await expect.poll(() => history.reads.length).toBe(3); + await expect(page.locator('.thread-history-status[data-state="loading"]')).toBeInViewport(); + await expect(slot.locator('.thread-history-status[data-state="loading"]')).toHaveCount(0); + history.complete("error"); + const retry = page.getByRole("button", { name: "Loading failed. Retry", exact: true }); + await expect(retry).toBeInViewport(); + await expect(slot.locator('.thread-history-status[data-state="error"]')).toHaveCount(0); + await stableLayout(body); + expect(history.reads).toHaveLength(3); + await body.hover(); + await page.mouse.wheel(0, 120); + await expect.poll(() => history.reads.length).toBe(4); + await expect(page.locator('.thread-history-status[data-state="loading"]')).toBeInViewport(); + expect(history.reads).toEqual(["?limit=24&after=10", "?limit=24&before=10", "?limit=24&after=22", "?limit=24&after=22"]); + history.complete(); + await expect(body.getByText("Question 33", { exact: true })).toBeAttached(); + await expect(page.locator('.thread-history-status[data-state="loading"]')).toHaveCount(0); + await expect(retry).toHaveCount(0); +}); + +test("cross-path older errors never float after latest or a loaded rail jump, but boundary retry remains available", async ({ page }) => { + const history = await installHistory(page); + await page.setViewportSize({ width: 1440, height: 900 }); + const body = page.getByTestId("thread-message-region"); + const retry = page.getByRole("button", { name: "Loading failed. Retry", exact: true }); + for (const destination of ["latest", "loaded prompt"] as const) { + await test.step(destination, async () => { + const initialReads = history.reads.length; + await openSettledHistory(page, "&navigate=1"); + await positionAtTop(body); + await requestOlderWithWheel(body, history, initialReads + 1); + history.complete("error"); + await expect(retry).toBeInViewport(); + await expectHeld(body, "Question 40"); + + if (destination === "latest") { + await page.getByRole("button", { name: "Scroll to bottom", exact: true }).click(); + await expect(body.getByText("Question 51", { exact: true })).toBeInViewport(); + } else { + await jumpViaRail(page, 46); + await expect(body.getByText("Question 46", { exact: true })).toBeInViewport(); + } + await stableLayout(body); + await expect.soft(page.locator('.thread-viewport-frame > .thread-history-status[data-state="error"]')).toHaveCount(0, { timeout: 1000 }); + await expect.soft(retry).not.toBeInViewport({ timeout: 1000 }); + await body.hover(); + await page.mouse.wheel(0, -64); + await stableLayout(body); + await expect.soft(retry).not.toBeInViewport({ timeout: 1000 }); + expect(history.reads).toHaveLength(initialReads + 1); + + await positionAtTop(body); + await retry.focus(); + await expect(retry).toBeInViewport(); + expect(history.reads).toHaveLength(initialReads + 1); + await retry.click(); + await expect.poll(() => history.reads.length).toBe(initialReads + 2); + expect(history.reads.slice(initialReads)).toEqual(["?limit=120&before=40", "?limit=120&before=40"]); + history.complete(); + await expect(body.getByText("Question 28", { exact: true })).toBeAttached(); + await expect(body.locator(".thread-history-slot")).toHaveCount(0); + await expect(page.locator('.thread-history-status[data-state="loading"]')).toHaveCount(0); + }); + } +}); + + +test("bounded navigation retains three pages and reclaims each completed wheel or keyboard boundary slot", async ({ page }) => { + const history = await installHistory(page); + await page.setViewportSize({ width: 1440, height: 900 }); + await page.goto("/browser/fixture.html?case=history-boundary&navigate=1"); + const body = page.getByTestId("thread-message-region"); + const header = page.locator(".thread-history-status"); + const slot = body.locator(".thread-history-slot"); + const approachNextHead = async (text: string) => { + // Real scrolling stops just short of the boundary, before it can request. + const scrollTop = await body.evaluate((node) => node.scrollTop); + expect(scrollTop).toBeGreaterThan(120); + await body.hover(); + await page.mouse.wheel(0, 120 - scrollTop); + await expect.poll(() => body.evaluate((node) => node.scrollTop)).toBeCloseTo(120, 0); + await stableLayout(body); + await expect(header).not.toBeInViewport(); + return historyGeometry(body, text); + }; + await expect(body.getByText("Question 40", { exact: true })).toBeAttached(); + await expect(body.getByText("Question 38", { exact: true })).toHaveCount(0); + await stableLayout(body); + // Keep the replacement away from latest's bottom so setup cannot prefetch newer. + await positionAtTop(body); + await stableLayout(body); + expect(history.reads).toHaveLength(0); + + // An unloaded rail destination replaces latest with P0 (38..49). + await jumpViaRail(page, 38); + await expect.poll(() => history.reads.length).toBe(1); + history.complete(); + await expect(body.getByText("Question 38", { exact: true })).toBeInViewport(); + await expect(body.getByText("Question 49", { exact: true })).toBeAttached(); + await stableLayout(body); + await positionAtTop(body); + await requestOlderWithWheel(body, history, 2); + await expect(header).toHaveAttribute("data-state", "loading"); + const held = await expectHeld(body, "Question 38"); + expect(held.slotBeforeKey).toBe("u38"); + + await completePrepend(history, body, "Question 26", "Question 38", held.anchorTop); + expect((await historyGeometry(body, "Question 38")).slotBeforeKey).toBeNull(); + await expect(body.locator('[data-thread-display-unit^="u"]')).toHaveCount(24); + + // Reach each prepended page head instead of loading from the old reading slot. + const atSecondHead = await approachNextHead("Question 26"); + expect(atSecondHead.firstKey).toBe("u26"); + expect(atSecondHead.slotBeforeKey).toBeNull(); + expect(history.reads).toHaveLength(2); + await page.mouse.wheel(0, -120); + await expect.poll(() => history.reads.length).toBe(3); + await expect(header).toHaveAttribute("data-state", "loading"); + const secondHeld = await expectHeld(body, "Question 26"); + expect(secondHeld.slotBeforeKey).toBe("u26"); + expect(secondHeld.anchorTop - atSecondHead.anchorTop - atSecondHead.scrollTop).toBeCloseTo(48, 0); + await completePrepend(history, body, "Question 14", "Question 26", secondHeld.anchorTop); + expect((await historyGeometry(body, "Question 26")).slotBeforeKey).toBeNull(); + await expect(body.locator('[data-thread-display-unit^="u"]')).toHaveCount(36); + + // Completed feedback is removed and cannot add a fourth cached page. + await expect(header).toHaveCount(0); + await stableLayout(body); + await expect(page.getByText("No earlier messages", { exact: true })).toHaveCount(0); + await expect(slot).toHaveCount(0); + await expectAnchorCoordinate(body, "Question 26", secondHeld.anchorTop); + expect((await historyGeometry(body, "Question 26")).slotBeforeKey).toBeNull(); + expect(history.reads).toEqual(["?limit=24&after=38", "?limit=24&before=38", "?limit=24&before=26"]); + + const atNewHead = await approachNextHead("Question 14"); + expect(atNewHead.firstKey).toBe("u14"); + expect(atNewHead.slotBeforeKey).toBeNull(); + expect(history.reads).toHaveLength(3); + await page.mouse.wheel(0, -120); + await expect.poll(() => history.reads.length).toBe(4); + await expect(header).toHaveAttribute("data-state", "loading"); + const newHeld = await expectHeld(body, "Question 14"); + expect(newHeld.slotBeforeKey).toBe("u14"); + expect(newHeld.anchorTop - atNewHead.anchorTop - atNewHead.scrollTop).toBeCloseTo(48, 0); + await completePrepend(history, body, "Question 2", "Question 14", newHeld.anchorTop); + await expect(slot).toHaveCount(0); + const completed = await historyGeometry(body, "Question 14"); + expect(completed.slotBeforeKey).toBeNull(); + expect(completed.firstKey).toBe("u2"); + await expect(body.getByText("Question 37", { exact: true })).toBeAttached(); + await expect(body.getByText("Question 38", { exact: true })).toHaveCount(0); + await expect(body.getByText("Question 49", { exact: true })).toHaveCount(0); + await expect(body.locator('[data-thread-display-unit^="u"]')).toHaveCount(36); + await expect(header).toHaveCount(0); + await expect(page.getByText("No earlier messages", { exact: true })).toHaveCount(0); + expect(history.reads).toEqual(["?limit=24&after=38", "?limit=24&before=38", "?limit=24&before=26", "?limit=24&before=14"]); + + // A real Home key reaches the next boundary and rebinds without a wheel pull. + const atKeyboardHead = await approachNextHead("Question 2"); + expect(atKeyboardHead.firstKey).toBe("u2"); + expect(atKeyboardHead.slotBeforeKey).toBeNull(); + await body.evaluate((node) => { node.tabIndex = 0; node.focus({ preventScroll: true }); }); + expect(history.reads).toHaveLength(4); + await page.keyboard.press("Home"); + await expect.poll(() => history.reads.length).toBe(5); + await expect(header).toHaveAttribute("data-state", "loading"); + const keyboardHeld = await expectHeld(body, "Question 2"); + expect(keyboardHeld.slotBeforeKey).toBe("u2"); + expect(keyboardHeld.anchorTop - atKeyboardHead.anchorTop - atKeyboardHead.scrollTop).toBeCloseTo(48, 0); + history.complete(); + await expect(body.getByText("Question 0", { exact: true })).toBeAttached(); + await stableLayout(body); + await expectAnchorCoordinate(body, "Question 2", keyboardHeld.anchorTop); + await body.evaluate((node) => { node.scrollTop = 0; node.dispatchEvent(new Event("scroll")); }); + await stableLayout(body); + await expect(header).toHaveAttribute("data-state", "exhausted"); + await expect(slot).toHaveCount(0); + const keyboardCompleted = await historyGeometry(body, "Question 2"); + expect(keyboardCompleted.slotBeforeKey).toBeNull(); + expect(keyboardCompleted.firstKey).toBe("u0"); + await expect(body.getByText("Question 25", { exact: true })).toBeAttached(); + await expect(body.getByText("Question 26", { exact: true })).toHaveCount(0); + await expect(body.locator('[data-thread-display-unit^="u"]')).toHaveCount(26); + expect(history.reads).toEqual(["?limit=24&after=38", "?limit=24&before=38", "?limit=24&before=26", "?limit=24&before=14", "?limit=24&before=2"]); +}); + + +async function historyBoundarySpacing(body: Locator, boundaryText: string, referenceText: string) { + return body.evaluate((node, texts) => { + const units = Array.from(node.querySelectorAll("[data-thread-display-unit]")); + const unitFor = (text: string) => { + const content = Array.from(node.querySelectorAll("[data-user-prompt-id], p")) + .find((element) => element.textContent?.trim() === text); + return content?.closest("[data-thread-display-unit]") ?? null; + }; + const gapBefore = (unit: HTMLElement | null) => { + if (!unit) return null; + const index = units.indexOf(unit); + const previous = units[index - 1]; + return previous ? unit.getBoundingClientRect().top - previous.getBoundingClientRect().bottom : null; + }; + return { + boundaryGap: gapBefore(unitFor(texts.boundaryText)), + referenceGap: gapBefore(unitFor(texts.referenceText)), + slotCount: node.querySelectorAll(".thread-history-slot").length, + }; + }, { boundaryText, referenceText }); +} + +async function expectAnchorCoordinate(body: Locator, text: string, expectedTop: number) { + await expect.poll(async () => Math.abs(await anchorTop(body, text) - expectedTop)).toBeLessThan(1); +} + + +test("history Blocks use muted loading and destructive error colors in light and dark themes", async ({ browser }) => { + for (const colorScheme of ["light", "dark"] as const) { + const context = await browser.newContext({ viewport: { width: 1440, height: 900 }, colorScheme }); + const page = await context.newPage(); + const history = await installHistory(page); + await page.goto(`http://127.0.0.1:${process.env.NANOBOT_BROWSER_TEST_PORT ?? 4178}/browser/fixture.html?case=history-boundary`); + if (colorScheme === "dark") await page.locator("html").evaluate((node) => node.classList.add("dark")); + const body = page.getByTestId("thread-message-region"); + await expect(body).toBeVisible(); + await stableLayout(body); + await positionAtTop(body); + await requestOlderWithWheel(body, history, 1); + const loadingBlocks = page.locator('.thread-history-status[data-state="loading"] .thread-history-blocks'); + const loadingColor = await loadingBlocks.evaluate((node) => getComputedStyle(node).color); + const mutedColor = await themeColor(loadingBlocks, "--muted-foreground"); + expect(loadingColor).toBe(mutedColor); + history.complete("error"); + const retry = page.getByRole("button", { name: "Loading failed. Retry", exact: true }); + const errorBlocks = retry.locator(".thread-history-blocks"); + const errorColor = await errorBlocks.evaluate((node) => getComputedStyle(node).color); + const destructiveColor = await themeColor(errorBlocks, "--destructive"); + expect(errorColor).toBe(destructiveColor); + expect(errorColor).not.toBe(loadingColor); + console.log(`history-colors ${colorScheme} loading=${loadingColor} error=${errorColor}`); + await test.info().attach(`history-colors-${colorScheme}`, { + body: JSON.stringify({ colorScheme, loadingColor, mutedColor, errorColor, destructiveColor }), + contentType: "application/json", + }); + await page.close(); + } +}); diff --git a/webui/bun.lock b/webui/bun.lock index 171e138d7..aeb72bb69 100644 --- a/webui/bun.lock +++ b/webui/bun.lock @@ -21,6 +21,7 @@ "lucide-react": "^0.469.0", "micromark-factory-space": "^2.0.1", "micromark-util-decode-string": "^2.0.1", + "motion": "^14.4.0", "pele": "1.6.0", "qrcode": "^1.5.4", "react": "^18.3.1", @@ -628,6 +629,8 @@ "fraction.js": ["fraction.js@5.3.4", "", {}, "sha512-1X1NTtiJphryn/uLQz3whtY6jK3fTqoE3ohKs0tT+Ujr1W59oopxmoEh7Lu5p6vBaPbgoM0bzveAW4Qi5RyWDQ=="], + "framer-motion": ["framer-motion@14.4.0", "https://mirrors.tencent.com/npm/framer-motion/-/framer-motion-14.4.0.tgz", { "dependencies": { "motion-dom": "14.4.0", "motion-utils": "14.1.1", "tslib": "^2.4.0" }, "peerDependencies": { "react": "^18.0.0 || ^19.0.0", "react-dom": "^18.0.0 || ^19.0.0" }, "optionalPeers": ["react", "react-dom"] }, "sha512-HtO1fxord2rnXYRyr1laG4uY7+OtgwDc9Szcg1wlMq/LF7BO3/S7a+KEo691U7pSi+i0ueRuRqaD1UaLEmZHuQ=="], + "fsevents": ["fsevents@2.3.3", "", { "os": "darwin" }, "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw=="], "function-bind": ["function-bind@1.1.2", "", {}, "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="], @@ -890,6 +893,12 @@ "minipass": ["minipass@7.1.3", "", {}, "sha512-tEBHqDnIoM/1rXME1zgka9g6Q2lcoCkxHLuc7ODJ5BxbP5d4c2Z5cGgtXAku59200Cx7diuHTOYfSBD8n6mm8A=="], + "motion": ["motion@14.4.0", "https://mirrors.tencent.com/npm/motion/-/motion-14.4.0.tgz", { "dependencies": { "framer-motion": "14.4.0", "tslib": "^2.4.0" }, "peerDependencies": { "react": "^18.0.0 || ^19.0.0", "react-dom": "^18.0.0 || ^19.0.0" }, "optionalPeers": ["react", "react-dom"] }, "sha512-JJTIdeNjtF2zi/py0ndRKxQF+8z2pcDUgJYXul7zqbhMvyTLRsPFR9ifE/j4cFCpCMlehQVJkTwd7BZFiPKgQg=="], + + "motion-dom": ["motion-dom@14.4.0", "https://mirrors.tencent.com/npm/motion-dom/-/motion-dom-14.4.0.tgz", { "dependencies": { "motion-utils": "14.1.1" } }, "sha512-1q8RyHSdr5COpzrv3JgJ9XRjOO88ZN9CwflpkGgyO/SR/SNRP/dD6EU8SEo092kcKY34IzHC5diJPKrQRMA8lQ=="], + + "motion-utils": ["motion-utils@14.1.1", "https://mirrors.tencent.com/npm/motion-utils/-/motion-utils-14.1.1.tgz", {}, "sha512-3VvN5Uvf8B6qG+OfOui6Nht5EWp+vLuU3IqcAj7ItZGKqtmTjCebl5sGZF7/08gEHRnEl1AP/fIwbcEyVrcQGQ=="], + "ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="], "mz": ["mz@2.7.0", "", { "dependencies": { "any-promise": "^1.0.0", "object-assign": "^4.0.1", "thenify-all": "^1.0.0" } }, "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q=="], diff --git a/webui/package-lock.json b/webui/package-lock.json index 98fd545dd..a5314d770 100644 --- a/webui/package-lock.json +++ b/webui/package-lock.json @@ -24,6 +24,7 @@ "lucide-react": "^0.469.0", "micromark-factory-space": "^2.0.1", "micromark-util-decode-string": "^2.0.1", + "motion": "^14.4.0", "pele": "1.6.0", "qrcode": "^1.5.4", "react": "^18.3.1", @@ -4128,6 +4129,29 @@ "url": "https://github.com/sponsors/rawify" } }, + "node_modules/framer-motion": { + "version": "14.4.0", + "resolved": "https://mirrors.tencent.com/npm/framer-motion/-/framer-motion-14.4.0.tgz", + "integrity": "sha512-HtO1fxord2rnXYRyr1laG4uY7+OtgwDc9Szcg1wlMq/LF7BO3/S7a+KEo691U7pSi+i0ueRuRqaD1UaLEmZHuQ==", + "license": "MIT", + "dependencies": { + "motion-dom": "14.4.0", + "motion-utils": "14.1.1", + "tslib": "^2.4.0" + }, + "peerDependencies": { + "react": "^18.0.0 || ^19.0.0", + "react-dom": "^18.0.0 || ^19.0.0" + }, + "peerDependenciesMeta": { + "react": { + "optional": true + }, + "react-dom": { + "optional": true + } + } + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -6083,6 +6107,43 @@ "node": ">=16 || 14 >=14.17" } }, + "node_modules/motion": { + "version": "14.4.0", + "resolved": "https://mirrors.tencent.com/npm/motion/-/motion-14.4.0.tgz", + "integrity": "sha512-JJTIdeNjtF2zi/py0ndRKxQF+8z2pcDUgJYXul7zqbhMvyTLRsPFR9ifE/j4cFCpCMlehQVJkTwd7BZFiPKgQg==", + "license": "MIT", + "dependencies": { + "framer-motion": "14.4.0", + "tslib": "^2.4.0" + }, + "peerDependencies": { + "react": "^18.0.0 || ^19.0.0", + "react-dom": "^18.0.0 || ^19.0.0" + }, + "peerDependenciesMeta": { + "react": { + "optional": true + }, + "react-dom": { + "optional": true + } + } + }, + "node_modules/motion-dom": { + "version": "14.4.0", + "resolved": "https://mirrors.tencent.com/npm/motion-dom/-/motion-dom-14.4.0.tgz", + "integrity": "sha512-1q8RyHSdr5COpzrv3JgJ9XRjOO88ZN9CwflpkGgyO/SR/SNRP/dD6EU8SEo092kcKY34IzHC5diJPKrQRMA8lQ==", + "license": "MIT", + "dependencies": { + "motion-utils": "14.1.1" + } + }, + "node_modules/motion-utils": { + "version": "14.1.1", + "resolved": "https://mirrors.tencent.com/npm/motion-utils/-/motion-utils-14.1.1.tgz", + "integrity": "sha512-3VvN5Uvf8B6qG+OfOui6Nht5EWp+vLuU3IqcAj7ItZGKqtmTjCebl5sGZF7/08gEHRnEl1AP/fIwbcEyVrcQGQ==", + "license": "MIT" + }, "node_modules/ms": { "version": "2.1.3", "license": "MIT" diff --git a/webui/package.json b/webui/package.json index e5805aa3e..8fd6eedce 100644 --- a/webui/package.json +++ b/webui/package.json @@ -34,6 +34,7 @@ "lucide-react": "^0.469.0", "micromark-factory-space": "^2.0.1", "micromark-util-decode-string": "^2.0.1", + "motion": "^14.4.0", "pele": "1.6.0", "qrcode": "^1.5.4", "react": "^18.3.1", diff --git a/webui/src/components/thread/ThreadHistoryStatus.tsx b/webui/src/components/thread/ThreadHistoryStatus.tsx index 67e4c66f2..9d8e6001c 100644 --- a/webui/src/components/thread/ThreadHistoryStatus.tsx +++ b/webui/src/components/thread/ThreadHistoryStatus.tsx @@ -8,14 +8,16 @@ interface ThreadHistoryStatusProps { loading: boolean; error: string | null; exhausted?: boolean; + preview?: boolean; onRetry: () => void; className?: string; } -export const ThreadHistoryStatus = forwardRef(function ThreadHistoryStatus({ loading, error, exhausted = false, onRetry, className }, ref) { +export const ThreadHistoryStatus = forwardRef(function ThreadHistoryStatus({ loading, error, exhausted = false, preview = false, onRetry, className }, ref) { const { t } = useTranslation(); - const state = !loading && error ? "error" : !loading && exhausted ? "exhausted" : "loading"; - const label = t(state === "error" ? "thread.history.retryLabel" : `thread.history.${state}`); + const state = loading ? "loading" : error ? "error" : exhausted ? "exhausted" : "ready"; + const hidden = state === "ready" && !preview; + const label = state === "ready" ? undefined : t(state === "error" ? "thread.history.retryLabel" : `thread.history.${state}`); // Blocks adapted from loading.dev (MIT); see THIRD_PARTY_NOTICES.md. const blocks =