From 0f3cabb16d1062d01b86ecd1bf31652df5b7b311 Mon Sep 17 00:00:00 2001 From: chengyongru Date: Fri, 18 Sep 2026 18:43:20 +0800 Subject: [PATCH] refactor(webui): derive footer spacing from thread tail --- webui/src/components/MessageBubble.tsx | 13 +++++----- .../src/components/thread/ThreadMessages.tsx | 24 +++++++++++-------- webui/src/tests/message-bubble.test.tsx | 4 ++-- webui/src/tests/thread-messages.test.tsx | 2 +- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/webui/src/components/MessageBubble.tsx b/webui/src/components/MessageBubble.tsx index 979cff3b4..5220e09a8 100644 --- a/webui/src/components/MessageBubble.tsx +++ b/webui/src/components/MessageBubble.tsx @@ -66,8 +66,8 @@ interface MessageBubbleProps { temporary?: boolean; /** When false, hide this message's copy button. Default true. */ showCopyAction?: boolean; - /** Whether this is the final assistant text slice before the next user turn. */ - isTerminalAssistantSlice?: boolean; + /** Whether this message is the final display unit in the thread. */ + isThreadTail?: boolean; cliApps?: CliAppInfo[]; mcpPresets?: McpPresetInfo[]; slashCommands?: SlashCommand[]; @@ -332,7 +332,7 @@ export function MessageBubble({ isTurnStreaming = false, temporary = false, showCopyAction = true, - isTerminalAssistantSlice = true, + isThreadTail = true, cliApps = [], mcpPresets = [], slashCommands = [], @@ -486,7 +486,7 @@ export function MessageBubble({ ? completedAt : message.createdAt; const assistantTimestampLabel = - message.role === "assistant" && !message.isStreaming + message.role === "assistant" && !message.isStreaming && !isTurnStreaming ? formatMessageEndTime(assistantTimestamp) : ""; const showCompletedAt = @@ -494,8 +494,7 @@ export function MessageBubble({ && (!empty || hasReasoning || media.length > 0); const showAssistantTimestamp = assistantTimestampLabel.length > 0 - && (!empty || hasReasoning || media.length > 0) - && (!isTurnStreaming || isTerminalAssistantSlice); + && (!empty || hasReasoning || media.length > 0); const assistantTimestampTitle = showAssistantTimestamp ? fmtDateTime(assistantTimestamp) : ""; const showAutomationTrigger = showAssistantTimestamp && automationSourceLabel.length > 0; const showAssistantFooterRow = @@ -505,7 +504,7 @@ export function MessageBubble({ && (!empty || hasReasoning || media.length > 0); const showAssistantFooterSlot = hasAssistantFooterContent - && (showAssistantFooterRow || isTerminalAssistantSlice); + && (showAssistantFooterRow || ((message.isStreaming || isTurnStreaming) && isThreadTail)); return (
{hasReasoning ? ( diff --git a/webui/src/components/thread/ThreadMessages.tsx b/webui/src/components/thread/ThreadMessages.tsx index 4f87039c3..18f337669 100644 --- a/webui/src/components/thread/ThreadMessages.tsx +++ b/webui/src/components/thread/ThreadMessages.tsx @@ -143,6 +143,14 @@ export function ThreadMessages({ unit.type === "message" && unit.message.role === "assistant" && forkFlags[index] ? nextUserIndex : undefined; + const unitTurnStreaming = unit.type === "activity" + ? liveActivityClusterIndices.has(index) + : isStreaming && ( + unit.message.turnId && activeTurnId !== null + ? unit.message.turnId === activeTurnId + : index > currentTurnStartIndex + ); + const isThreadTail = index === units.length - 1; if ( unit.type === "message" && unit.message.role === "user" @@ -158,15 +166,8 @@ export function ThreadMessages({ userPromptId={userPromptId} hasBodyBelow={hasBodyBelow} deferOffscreenRender={deferOffscreenRender} - isTurnStreaming={ - unit.type === "activity" - ? liveActivityClusterIndices.has(index) - : isStreaming && ( - unit.message.turnId && activeTurnId !== null - ? unit.message.turnId === activeTurnId - : index > currentTurnStartIndex - ) - } + isTurnStreaming={unitTurnStreaming} + isThreadTail={isThreadTail} retryStatus={ unit.type === "activity" && liveActivityClusterIndices.has(index) ? retryStatus @@ -256,6 +257,7 @@ interface ThreadDisplayUnitProps { hasBodyBelow: boolean; deferOffscreenRender: boolean; isTurnStreaming: boolean; + isThreadTail: boolean; retryStatus: RetryStatus | null; forkIndex?: number; showForkBoundary: boolean; @@ -278,6 +280,7 @@ const ThreadDisplayUnit = memo(function ThreadDisplayUnit({ hasBodyBelow, deferOffscreenRender, isTurnStreaming, + isThreadTail, retryStatus, forkIndex, showForkBoundary, @@ -343,8 +346,8 @@ const ThreadDisplayUnit = memo(function ThreadDisplayUnit({ { expect(visibleFooter).toHaveClass("mt-2", "min-h-8", "opacity-100"); }); - it("omits hidden footer space for an intermediate assistant answer", () => { + it("omits footer space when an active answer is no longer the tail", () => { const message: UIMessage = { id: "a-intermediate", role: "assistant", @@ -880,7 +880,7 @@ describe("MessageBubble", () => { , ); diff --git a/webui/src/tests/thread-messages.test.tsx b/webui/src/tests/thread-messages.test.tsx index fb334a2db..262655906 100644 --- a/webui/src/tests/thread-messages.test.tsx +++ b/webui/src/tests/thread-messages.test.tsx @@ -1532,7 +1532,7 @@ describe("ThreadMessages", () => { .closest("[data-thread-display-unit]")!; expect(firstAnswer.querySelector("[data-assistant-footer]")).not.toBeInTheDocument(); expect(finalAnswer.querySelector("[data-assistant-footer]")) - .toHaveAttribute("data-state", "visible"); + .toHaveAttribute("data-state", "reserved"); expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Copy"]')).toHaveLength(1); expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Fork"]')).toHaveLength(1);