refactor(webui): derive footer spacing from thread tail
This commit is contained in:
1 parent
900675e7f8
commit
0f3cabb16d
4 files changed
+23
-20
No files matched your search
@@ -66,8 +66,8 @@ interface MessageBubbleProps {
|
|||||||
temporary?: boolean;
|
temporary?: boolean;
|
||||||
/** When false, hide this message's copy button. Default true. */
|
/** When false, hide this message's copy button. Default true. */
|
||||||
showCopyAction?: boolean;
|
showCopyAction?: boolean;
|
||||||
/** Whether this is the final assistant text slice before the next user turn. */
|
/** Whether this message is the final display unit in the thread. */
|
||||||
isTerminalAssistantSlice?: boolean;
|
isThreadTail?: boolean;
|
||||||
cliApps?: CliAppInfo[];
|
cliApps?: CliAppInfo[];
|
||||||
mcpPresets?: McpPresetInfo[];
|
mcpPresets?: McpPresetInfo[];
|
||||||
slashCommands?: SlashCommand[];
|
slashCommands?: SlashCommand[];
|
||||||
@@ -332,7 +332,7 @@ export function MessageBubble({
|
|||||||
isTurnStreaming = false,
|
isTurnStreaming = false,
|
||||||
temporary = false,
|
temporary = false,
|
||||||
showCopyAction = true,
|
showCopyAction = true,
|
||||||
isTerminalAssistantSlice = true,
|
isThreadTail = true,
|
||||||
cliApps = [],
|
cliApps = [],
|
||||||
mcpPresets = [],
|
mcpPresets = [],
|
||||||
slashCommands = [],
|
slashCommands = [],
|
||||||
@@ -486,7 +486,7 @@ export function MessageBubble({
|
|||||||
? completedAt
|
? completedAt
|
||||||
: message.createdAt;
|
: message.createdAt;
|
||||||
const assistantTimestampLabel =
|
const assistantTimestampLabel =
|
||||||
message.role === "assistant" && !message.isStreaming
|
message.role === "assistant" && !message.isStreaming && !isTurnStreaming
|
||||||
? formatMessageEndTime(assistantTimestamp)
|
? formatMessageEndTime(assistantTimestamp)
|
||||||
: "";
|
: "";
|
||||||
const showCompletedAt =
|
const showCompletedAt =
|
||||||
@@ -494,8 +494,7 @@ export function MessageBubble({
|
|||||||
&& (!empty || hasReasoning || media.length > 0);
|
&& (!empty || hasReasoning || media.length > 0);
|
||||||
const showAssistantTimestamp =
|
const showAssistantTimestamp =
|
||||||
assistantTimestampLabel.length > 0
|
assistantTimestampLabel.length > 0
|
||||||
&& (!empty || hasReasoning || media.length > 0)
|
&& (!empty || hasReasoning || media.length > 0);
|
||||||
&& (!isTurnStreaming || isTerminalAssistantSlice);
|
|
||||||
const assistantTimestampTitle = showAssistantTimestamp ? fmtDateTime(assistantTimestamp) : "";
|
const assistantTimestampTitle = showAssistantTimestamp ? fmtDateTime(assistantTimestamp) : "";
|
||||||
const showAutomationTrigger = showAssistantTimestamp && automationSourceLabel.length > 0;
|
const showAutomationTrigger = showAssistantTimestamp && automationSourceLabel.length > 0;
|
||||||
const showAssistantFooterRow =
|
const showAssistantFooterRow =
|
||||||
@@ -505,7 +504,7 @@ export function MessageBubble({
|
|||||||
&& (!empty || hasReasoning || media.length > 0);
|
&& (!empty || hasReasoning || media.length > 0);
|
||||||
const showAssistantFooterSlot =
|
const showAssistantFooterSlot =
|
||||||
hasAssistantFooterContent
|
hasAssistantFooterContent
|
||||||
&& (showAssistantFooterRow || isTerminalAssistantSlice);
|
&& (showAssistantFooterRow || ((message.isStreaming || isTurnStreaming) && isThreadTail));
|
||||||
return (
|
return (
|
||||||
<div className="w-full text-[15px]" style={{ lineHeight: "var(--cjk-line-height)" }}>
|
<div className="w-full text-[15px]" style={{ lineHeight: "var(--cjk-line-height)" }}>
|
||||||
{hasReasoning ? (
|
{hasReasoning ? (
|
||||||
|
|||||||
@@ -143,6 +143,14 @@ export function ThreadMessages({
|
|||||||
unit.type === "message" && unit.message.role === "assistant" && forkFlags[index]
|
unit.type === "message" && unit.message.role === "assistant" && forkFlags[index]
|
||||||
? nextUserIndex
|
? nextUserIndex
|
||||||
: undefined;
|
: 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 (
|
if (
|
||||||
unit.type === "message"
|
unit.type === "message"
|
||||||
&& unit.message.role === "user"
|
&& unit.message.role === "user"
|
||||||
@@ -158,15 +166,8 @@ export function ThreadMessages({
|
|||||||
userPromptId={userPromptId}
|
userPromptId={userPromptId}
|
||||||
hasBodyBelow={hasBodyBelow}
|
hasBodyBelow={hasBodyBelow}
|
||||||
deferOffscreenRender={deferOffscreenRender}
|
deferOffscreenRender={deferOffscreenRender}
|
||||||
isTurnStreaming={
|
isTurnStreaming={unitTurnStreaming}
|
||||||
unit.type === "activity"
|
isThreadTail={isThreadTail}
|
||||||
? liveActivityClusterIndices.has(index)
|
|
||||||
: isStreaming && (
|
|
||||||
unit.message.turnId && activeTurnId !== null
|
|
||||||
? unit.message.turnId === activeTurnId
|
|
||||||
: index > currentTurnStartIndex
|
|
||||||
)
|
|
||||||
}
|
|
||||||
retryStatus={
|
retryStatus={
|
||||||
unit.type === "activity" && liveActivityClusterIndices.has(index)
|
unit.type === "activity" && liveActivityClusterIndices.has(index)
|
||||||
? retryStatus
|
? retryStatus
|
||||||
@@ -256,6 +257,7 @@ interface ThreadDisplayUnitProps {
|
|||||||
hasBodyBelow: boolean;
|
hasBodyBelow: boolean;
|
||||||
deferOffscreenRender: boolean;
|
deferOffscreenRender: boolean;
|
||||||
isTurnStreaming: boolean;
|
isTurnStreaming: boolean;
|
||||||
|
isThreadTail: boolean;
|
||||||
retryStatus: RetryStatus | null;
|
retryStatus: RetryStatus | null;
|
||||||
forkIndex?: number;
|
forkIndex?: number;
|
||||||
showForkBoundary: boolean;
|
showForkBoundary: boolean;
|
||||||
@@ -278,6 +280,7 @@ const ThreadDisplayUnit = memo(function ThreadDisplayUnit({
|
|||||||
hasBodyBelow,
|
hasBodyBelow,
|
||||||
deferOffscreenRender,
|
deferOffscreenRender,
|
||||||
isTurnStreaming,
|
isTurnStreaming,
|
||||||
|
isThreadTail,
|
||||||
retryStatus,
|
retryStatus,
|
||||||
forkIndex,
|
forkIndex,
|
||||||
showForkBoundary,
|
showForkBoundary,
|
||||||
@@ -343,8 +346,8 @@ const ThreadDisplayUnit = memo(function ThreadDisplayUnit({
|
|||||||
<MessageBubble
|
<MessageBubble
|
||||||
message={unit.message}
|
message={unit.message}
|
||||||
isTurnStreaming={isTurnStreaming}
|
isTurnStreaming={isTurnStreaming}
|
||||||
|
isThreadTail={isThreadTail}
|
||||||
temporary={temporary}
|
temporary={temporary}
|
||||||
isTerminalAssistantSlice={forkIndex !== undefined}
|
|
||||||
cliApps={cliApps}
|
cliApps={cliApps}
|
||||||
mcpPresets={mcpPresets}
|
mcpPresets={mcpPresets}
|
||||||
slashCommands={slashCommands}
|
slashCommands={slashCommands}
|
||||||
@@ -369,6 +372,7 @@ function threadDisplayUnitPropsEqual(
|
|||||||
&& previous.hasBodyBelow === next.hasBodyBelow
|
&& previous.hasBodyBelow === next.hasBodyBelow
|
||||||
&& previous.deferOffscreenRender === next.deferOffscreenRender
|
&& previous.deferOffscreenRender === next.deferOffscreenRender
|
||||||
&& previous.isTurnStreaming === next.isTurnStreaming
|
&& previous.isTurnStreaming === next.isTurnStreaming
|
||||||
|
&& previous.isThreadTail === next.isThreadTail
|
||||||
&& previous.retryStatus === next.retryStatus
|
&& previous.retryStatus === next.retryStatus
|
||||||
&& previous.forkIndex === next.forkIndex
|
&& previous.forkIndex === next.forkIndex
|
||||||
&& previous.showForkBoundary === next.showForkBoundary
|
&& previous.showForkBoundary === next.showForkBoundary
|
||||||
|
|||||||
@@ -868,7 +868,7 @@ describe("MessageBubble", () => {
|
|||||||
expect(visibleFooter).toHaveClass("mt-2", "min-h-8", "opacity-100");
|
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 = {
|
const message: UIMessage = {
|
||||||
id: "a-intermediate",
|
id: "a-intermediate",
|
||||||
role: "assistant",
|
role: "assistant",
|
||||||
@@ -880,7 +880,7 @@ describe("MessageBubble", () => {
|
|||||||
<MessageBubble
|
<MessageBubble
|
||||||
message={message}
|
message={message}
|
||||||
isTurnStreaming
|
isTurnStreaming
|
||||||
isTerminalAssistantSlice={false}
|
isThreadTail={false}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1532,7 +1532,7 @@ describe("ThreadMessages", () => {
|
|||||||
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||||
expect(firstAnswer.querySelector("[data-assistant-footer]")).not.toBeInTheDocument();
|
expect(firstAnswer.querySelector("[data-assistant-footer]")).not.toBeInTheDocument();
|
||||||
expect(finalAnswer.querySelector("[data-assistant-footer]"))
|
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="Copy"]')).toHaveLength(1);
|
||||||
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Fork"]')).toHaveLength(1);
|
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Fork"]')).toHaveLength(1);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user