fix(webui): remove intermediate answer footer gap
This commit is contained in:
1 parent
fa754c2204
commit
900675e7f8
4 files changed
+38
-2
No files matched your search
@@ -66,6 +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. */
|
||||||
|
isTerminalAssistantSlice?: boolean;
|
||||||
cliApps?: CliAppInfo[];
|
cliApps?: CliAppInfo[];
|
||||||
mcpPresets?: McpPresetInfo[];
|
mcpPresets?: McpPresetInfo[];
|
||||||
slashCommands?: SlashCommand[];
|
slashCommands?: SlashCommand[];
|
||||||
@@ -330,6 +332,7 @@ export function MessageBubble({
|
|||||||
isTurnStreaming = false,
|
isTurnStreaming = false,
|
||||||
temporary = false,
|
temporary = false,
|
||||||
showCopyAction = true,
|
showCopyAction = true,
|
||||||
|
isTerminalAssistantSlice = true,
|
||||||
cliApps = [],
|
cliApps = [],
|
||||||
mcpPresets = [],
|
mcpPresets = [],
|
||||||
slashCommands = [],
|
slashCommands = [],
|
||||||
@@ -491,14 +494,18 @@ 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 =
|
||||||
showCopyButton || showForkButton || showAssistantTimestamp;
|
showCopyButton || showForkButton || showAssistantTimestamp;
|
||||||
const showAssistantFooterSlot =
|
const hasAssistantFooterContent =
|
||||||
message.role === "assistant"
|
message.role === "assistant"
|
||||||
&& (!empty || hasReasoning || media.length > 0);
|
&& (!empty || hasReasoning || media.length > 0);
|
||||||
|
const showAssistantFooterSlot =
|
||||||
|
hasAssistantFooterContent
|
||||||
|
&& (showAssistantFooterRow || isTerminalAssistantSlice);
|
||||||
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 ? (
|
||||||
|
|||||||
@@ -344,6 +344,7 @@ const ThreadDisplayUnit = memo(function ThreadDisplayUnit({
|
|||||||
message={unit.message}
|
message={unit.message}
|
||||||
isTurnStreaming={isTurnStreaming}
|
isTurnStreaming={isTurnStreaming}
|
||||||
temporary={temporary}
|
temporary={temporary}
|
||||||
|
isTerminalAssistantSlice={forkIndex !== undefined}
|
||||||
cliApps={cliApps}
|
cliApps={cliApps}
|
||||||
mcpPresets={mcpPresets}
|
mcpPresets={mcpPresets}
|
||||||
slashCommands={slashCommands}
|
slashCommands={slashCommands}
|
||||||
|
|||||||
@@ -868,6 +868,25 @@ 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", () => {
|
||||||
|
const message: UIMessage = {
|
||||||
|
id: "a-intermediate",
|
||||||
|
role: "assistant",
|
||||||
|
content: "I will keep working.",
|
||||||
|
createdAt: Date.now(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const { container } = render(
|
||||||
|
<MessageBubble
|
||||||
|
message={message}
|
||||||
|
isTurnStreaming
|
||||||
|
isTerminalAssistantSlice={false}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(container.querySelector("[data-assistant-footer]")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
it("does not show copy when showCopyAction is false", () => {
|
it("does not show copy when showCopyAction is false", () => {
|
||||||
const message: UIMessage = {
|
const message: UIMessage = {
|
||||||
id: "a-mid",
|
id: "a-mid",
|
||||||
|
|||||||
@@ -1526,11 +1526,20 @@ describe("ThreadMessages", () => {
|
|||||||
<ThreadMessages {...props} isStreaming activeTurnId={activeTurnId} />,
|
<ThreadMessages {...props} isStreaming activeTurnId={activeTurnId} />,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const firstAnswer = screen.getByText("first answer slice")
|
||||||
|
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||||
|
const finalAnswer = screen.getByText("second answer slice")
|
||||||
|
.closest<HTMLElement>("[data-thread-display-unit]")!;
|
||||||
|
expect(firstAnswer.querySelector("[data-assistant-footer]")).not.toBeInTheDocument();
|
||||||
|
expect(finalAnswer.querySelector("[data-assistant-footer]"))
|
||||||
|
.toHaveAttribute("data-state", "visible");
|
||||||
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);
|
||||||
|
|
||||||
rerender(<ThreadMessages {...props} isStreaming={false} activeTurnId={null} />);
|
rerender(<ThreadMessages {...props} isStreaming={false} activeTurnId={null} />);
|
||||||
|
|
||||||
|
expect(firstAnswer.querySelector("[data-assistant-footer]"))
|
||||||
|
.toHaveAttribute("data-state", "visible");
|
||||||
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Copy"]')).toHaveLength(3);
|
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Copy"]')).toHaveLength(3);
|
||||||
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Fork"]')).toHaveLength(2);
|
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Fork"]')).toHaveLength(2);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user