🙌 OpenHands: AI-Driven Development
fix(chat): polish pending user message sending UX (#1053)
FraterCCCLXIIIa53bff52d4bd
diff --git a/__tests__/components/chat-message.test.tsx b/__tests__/components/chat-message.test.tsxindex e719687984..d43b8bff60 100644--- a/__tests__/components/chat-message.test.tsx+++ b/__tests__/components/chat-message.test.tsx@@ -1,4 +1,4 @@-import { render, screen, waitFor } from "@testing-library/react";+import { render, screen, waitFor, fireEvent } from "@testing-library/react";import userEvent from "@testing-library/user-event";import { describe, it, expect } from "vitest";import { ChatMessage } from "#/components/features/chat/chat-message";@@ -65,4 +65,19 @@ describe("ChatMessage", () => {expect(codeElement.tagName.toLowerCase()).toBe("code");expect(codeElement.closest("article")).not.toBeNull();});++ it("truncates long sent user messages to three lines with view more on hover", async () => {+ const longMessage = `${"Here's a long message. ".repeat(40)}`.trim();+ render(<ChatMessage type="user" message={longMessage} />);++ expect(screen.getByTestId("chat-message-truncation-gradient")).toBeInTheDocument();+ expect(screen.getByTestId("chat-message-view-more")).toHaveClass("opacity-0");++ fireEvent.mouseEnter(screen.getByTestId("user-message"));+ expect(screen.getByTestId("chat-message-view-more")).toHaveClass("opacity-100");++ fireEvent.click(screen.getByTestId("chat-message-expand"));+ expect(screen.queryByTestId("chat-message-truncation-gradient")).not.toBeInTheDocument();+ expect(screen.queryByTestId("chat-message-view-more")).not.toBeInTheDocument();+ });});diff --git a/__tests__/components/features/chat/pending-user-messages.test.tsx b/__tests__/components/features/chat/pending-user-messages.test.tsxindex dd00935cce..c1b3dc8833 100644--- a/__tests__/components/features/chat/pending-user-messages.test.tsx+++ b/__tests__/components/features/chat/pending-user-messages.test.tsx@@ -1,10 +1,11 @@import React from "react";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";-import { render, screen, waitFor } from "@testing-library/react";+import { render, screen, waitFor, fireEvent } from "@testing-library/react";import userEvent from "@testing-library/user-event";import { renderWithProviders } from "test-utils";import { PendingUserMessages } from "#/components/features/chat/pending-user-messages";import { useOptimisticUserMessageStore } from "#/stores/optimistic-user-message-store";+import { useConversationStore } from "#/stores/conversation-store";const ACTIVE_CONVO = "conv-active";@@ -22,6 +23,10 @@ describe("PendingUserMessages", () => {beforeEach(() => {mockSend.mockReset();useOptimisticUserMessageStore.setState({ pendingMessages: [] });+ useConversationStore.setState({+ messageRestoreIfEmpty: null,+ messageToSend: null,+ });});afterEach(() => {@@ -33,7 +38,7 @@ describe("PendingUserMessages", () => {expect(container).toBeEmptyDOMElement();});- it("renders each queued message with the faded 'sending' treatment", () => {+ it("renders each queued message with the sending treatment", () => {useOptimisticUserMessageStore.getState().enqueuePendingMessage({conversationId: ACTIVE_CONVO,text: "first message",@@ -73,6 +78,43 @@ describe("PendingUserMessages", () => {expect(screen.queryByText("from another conversation")).toBeNull();});+ it("removes a sending message when stop is clicked", async () => {+ useOptimisticUserMessageStore.getState().enqueuePendingMessage({+ conversationId: ACTIVE_CONVO,+ text: "cancel me",+ });++ renderWithProviders(<PendingUserMessages />);++ const message = screen.getByTestId("user-message");+ fireEvent.mouseEnter(message);+ await waitFor(() => {+ expect(screen.getByTestId("chat-message-stop")).toBeVisible();+ });+ fireEvent.click(screen.getByTestId("chat-message-stop"));++ await waitFor(() => {+ expect(screen.queryByTestId("user-message")).not.toBeInTheDocument();+ });+ expect(useOptimisticUserMessageStore.getState().pendingMessages).toHaveLength(+ 0,+ );+ expect(useConversationStore.getState().messageRestoreIfEmpty).toEqual(+ expect.objectContaining({ text: "cancel me" }),+ );+ });++ it("keeps the stop button out of the bubble layout while sending", () => {+ useOptimisticUserMessageStore.getState().enqueuePendingMessage({+ conversationId: ACTIVE_CONVO,+ text: "hold my spot",+ });++ renderWithProviders(<PendingUserMessages />);++ expect(screen.getByTestId("chat-message-stop")).toHaveClass("opacity-0");+ });+it("shows an error state with a retry link when the message is in 'error'", () => {const id = useOptimisticUserMessageStore.getState()diff --git a/__tests__/components/shared/text-shimmer.test.tsx b/__tests__/components/shared/text-shimmer.test.tsxnew file mode 100644index 0000000000..8abf93dc56--- /dev/null+++ b/__tests__/components/shared/text-shimmer.test.tsx@@ -0,0 +1,30 @@+import { describe, expect, it, vi } from "vitest";+import { render, screen } from "@testing-library/react";+import { TextShimmer } from "#/components/shared/text-shimmer";++vi.mock("framer-motion", async () => {+ const actual = await vi.importActual<typeof import("framer-motion")>(+ "framer-motion",+ );+ return {+ ...actual,+ useReducedMotion: () => false,+ };+});++describe("TextShimmer", () => {+ it("renders with a clipped dual-layer shimmer background", () => {+ render(+ <TextShimmer data-testid="shimmer" duration={3} spread={2}>+ Sending...+ </TextShimmer>,+ );++ const shimmer = screen.getByTestId("shimmer");+ expect(shimmer.style.backgroundImage).toContain("repeating-linear-gradient");+ expect(shimmer.style.backgroundImage).toContain("var(--oh-foreground)");+ expect(shimmer.style.backgroundImage).toContain("var(--oh-muted)");+ expect(shimmer.style.backgroundSize).toBe("200% 100%");+ expect(shimmer.style.animation).toContain("oh-text-shimmer-");+ });+});diff --git a/src/components/features/chat/chat-message.tsx b/src/components/features/chat/chat-message.tsxindex d60a22455c..ac3764a827 100644--- a/src/components/features/chat/chat-message.tsx+++ b/src/components/features/chat/chat-message.tsx@@ -5,10 +5,144 @@ import { CopyToClipboardButton } from "#/components/shared/buttons/copy-to-clipbimport type { SourceType } from "#/types/agent-server/core/base/common";import { StyledTooltip } from "#/components/shared/buttons/styled-tooltip";import { I18nKey } from "#/i18n/declaration";+import { TextShimmer } from "#/components/shared/text-shimmer";import { MarkdownRenderer } from "../markdown/markdown-renderer";export type ChatMessagePendingStatus = "sending" | "error";+const USER_MESSAGE_MAX_LINES = 3;+const USER_MESSAGE_LINE_HEIGHT_PX = 24;++function PendingStopIcon({ className }: { className?: string }) {+ return (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ viewBox="0 0 24 24"+ fill="none"+ aria-hidden+ className={className}+ >+ <circle+ cx="12"+ cy="12"+ r="10"+ className="fill-[var(--oh-foreground)] transition-colors duration-150 group-hover:fill-[var(--oh-text-secondary)]"+ />+ <rect+ x="9"+ y="9"+ width="6"+ height="6"+ rx="1"+ className="fill-[var(--oh-color-tertiary)]"+ />+ </svg>+ );+}++const chatBubbleMarkdownComponents = {+ p: ({ children }: React.ComponentProps<"p">) => (+ <p className="m-0 leading-6">{children}</p>+ ),+};++function UserMessageBody({+ message,+ isHovering,+ isExpanded,+ onTruncatableChange,+}: {+ message: string;+ isHovering: boolean;+ isExpanded: boolean;+ onTruncatableChange: (truncatable: boolean) => void;+}) {+ const { t } = useTranslation("openhands");+ const contentRef = React.useRef<HTMLDivElement>(null);+ const [isTruncatable, setIsTruncatable] = React.useState(false);++ React.useLayoutEffect(() => {+ const content = contentRef.current;+ if (!content || isExpanded) {+ setIsTruncatable(false);+ onTruncatableChange(false);+ return undefined;+ }++ const measure = () => {+ const lineHeight = Number.parseFloat(+ getComputedStyle(content).lineHeight,+ );+ const linePx =+ Number.isFinite(lineHeight) && lineHeight > 0+ ? lineHeight+ : USER_MESSAGE_LINE_HEIGHT_PX;+ const maxHeight = USER_MESSAGE_MAX_LINES * linePx;+ const newlineCount = (message.match(/\n/g) ?? []).length;++ const truncatable =+ content.scrollHeight > maxHeight + 1 ||+ newlineCount >= USER_MESSAGE_MAX_LINES ||+ message.trim().length > 220;++ setIsTruncatable((previous) => {+ if (previous !== truncatable) {+ onTruncatableChange(truncatable);+ }+ return truncatable;+ });+ };++ measure();++ const observer = new ResizeObserver(measure);+ observer.observe(content);++ return () => observer.disconnect();+ }, [message, isExpanded, onTruncatableChange]);++ const isCollapsed = isTruncatable && !isExpanded;++ return (+ <div className="relative min-w-0">+ <div+ ref={contentRef}+ className={cn(+ "text-sm leading-6 whitespace-normal [word-break:break-word]",+ isCollapsed && "line-clamp-3",+ )}+ >+ <MarkdownRenderer+ includeStandard+ includeHeadings+ components={chatBubbleMarkdownComponents}+ >+ {message}+ </MarkdownRenderer>+ </div>++ {isCollapsed ? (+ <>+ <div+ aria-hidden+ data-testid="chat-message-truncation-gradient"+ className="pointer-events-none absolute inset-x-0 bottom-0 h-10 bg-gradient-to-t from-tertiary to-transparent"+ />+ <span+ data-testid="chat-message-view-more"+ className={cn(+ "pointer-events-none absolute bottom-1 left-1/2 z-10 inline-flex -translate-x-1/2 items-center rounded-full border border-[var(--oh-border-subtle)] bg-[var(--oh-surface-raised)] px-2.5 py-0.5 text-xs font-normal text-[var(--oh-foreground)] transition-opacity duration-150",+ isHovering ? "opacity-100" : "opacity-0",+ )}+ >+ {t(I18nKey.COMMON$VIEW_MORE)}+ </span>+ </>+ ) : null}+ </div>+ );+}+interface ChatMessageProps {type: SourceType;message: string;@@ -20,6 +154,7 @@ interface ChatMessageProps {isFromPlanningAgent?: boolean;pendingStatus?: ChatMessagePendingStatus;onRetry?: () => void;+ onStop?: () => void;}export function ChatMessage({@@ -30,10 +165,20 @@ export function ChatMessage({isFromPlanningAgent = false,pendingStatus,onRetry,+ onStop,}: React.PropsWithChildren<ChatMessageProps>) {const { t } = useTranslation("openhands");const [isHovering, setIsHovering] = React.useState(false);const [isCopy, setIsCopy] = React.useState(false);+ const [isExpanded, setIsExpanded] = React.useState(false);+ const [isTruncatable, setIsTruncatable] = React.useState(false);+ const [isSingleLinePendingMessage, setIsSingleLinePendingMessage] =+ React.useState(true);+ const pendingMessageContentRef = React.useRef<HTMLDivElement>(null);++ React.useEffect(() => {+ setIsExpanded(false);+ }, [message]);const handleCopyToClipboard = async () => {await navigator.clipboard.writeText(message);@@ -54,30 +199,95 @@ export function ChatMessage({};}, [isCopy]);- return (+ const isPendingUserMessage =+ type === "user" &&+ (pendingStatus === "error" || pendingStatus === "sending");+ const canStopPendingMessage = pendingStatus === "sending" && onStop != null;+ const showStopButton = canStopPendingMessage && isHovering;+ const useTruncatedUserBody = type === "user" && pendingStatus == null;+ const isCollapsed = useTruncatedUserBody && isTruncatable && !isExpanded;+ const hasBubbleChildren = React.Children.count(children) > 0;++ React.useLayoutEffect(() => {+ if (!canStopPendingMessage || useTruncatedUserBody) {+ return undefined;+ }++ const content = pendingMessageContentRef.current;+ if (!content) {+ return undefined;+ }++ const measure = () => {+ const lineHeight = Number.parseFloat(+ getComputedStyle(content).lineHeight,+ );+ const linePx =+ Number.isFinite(lineHeight) && lineHeight > 0+ ? lineHeight+ : USER_MESSAGE_LINE_HEIGHT_PX;++ setIsSingleLinePendingMessage(content.scrollHeight <= linePx + 1);+ };++ measure();++ const observer = new ResizeObserver(measure);+ observer.observe(content);++ return () => observer.disconnect();+ }, [message, canStopPendingMessage, useTruncatedUserBody]);++ const messageContent = useTruncatedUserBody ? (+ <UserMessageBody+ message={message}+ isHovering={isHovering}+ isExpanded={isExpanded}+ onTruncatableChange={setIsTruncatable}+ />+ ) : (+ <div+ ref={pendingMessageContentRef}+ className="min-w-0 text-sm leading-6 whitespace-normal [word-break:break-word]"+ >+ <MarkdownRenderer+ includeStandard+ includeHeadings+ components={chatBubbleMarkdownComponents}+ >+ {message}+ </MarkdownRenderer>+ </div>+ );++ const renderedMessageContent = messageContent;++ const messageBubble = (<articledata-testid={`${type}-message`}data-pending-status={pendingStatus}onMouseEnter={() => setIsHovering(true)}onMouseLeave={() => setIsHovering(false)}className={cn(- "rounded-xl relative w-fit max-w-full last:mb-4",- "flex flex-col gap-2",- type === "user" && "p-4 bg-tertiary self-end",+ "rounded-xl relative w-fit max-w-full flex flex-col",+ hasBubbleChildren && "gap-2",+ type === "user" && "mt-6 bg-tertiary self-end px-4 py-2.5",type === "agent" && "mt-6 w-full max-w-full bg-transparent",isFromPlanningAgent &&type === "agent" &&"border border-[#597ff4] bg-tertiary p-4 mt-2",- pendingStatus === "sending" && "opacity-60",- pendingStatus === "error" && "border border-status-fail-border",+ pendingStatus === "error" &&+ "border border-[var(--oh-status-error)]/40",+ !isPendingUserMessage && "last:mb-4",)}><divclassName={cn(- "absolute -top-2.5 -right-2.5",- !isHovering ? "hidden" : "flex",+ "absolute -top-2.5 -right-2.5 z-10",+ !isHovering || pendingStatus === "sending" ? "hidden" : "flex","items-center gap-1",)}+ onClick={(event) => event.stopPropagation()}>{actions?.map((action, index) =>action.tooltip ? (@@ -112,44 +322,91 @@ export function ChatMessage({/></div>- <div className="text-sm whitespace-normal [word-break:break-word]">- <MarkdownRenderer includeStandard includeHeadings>- {message}- </MarkdownRenderer>- </div>+ {renderedMessageContent}- {pendingStatus === "sending" && (- <span- role="status"- aria-live="polite"- data-testid="chat-message-sending"- className="self-end text-xs italic text-content-muted"+ {canStopPendingMessage ? (+ <button+ type="button"+ onClick={(event) => {+ event.stopPropagation();+ onStop?.();+ }}+ data-testid="chat-message-stop"+ aria-label={t(I18nKey.BUTTON$STOP)}+ aria-hidden={!showStopButton}+ tabIndex={showStopButton ? 0 : -1}+ className={cn(+ "group absolute z-10 inline-flex h-7 w-7 cursor-pointer items-center justify-center rounded-full bg-[var(--oh-color-tertiary)] text-[var(--oh-foreground)] transition-opacity duration-150",+ isSingleLinePendingMessage+ ? "right-3 top-1/2 -translate-y-1/2"+ : "right-3 bottom-2.5",+ showStopButton ? "opacity-100" : "pointer-events-none opacity-0",+ )}>- {t(I18nKey.CHAT_INTERFACE$MESSAGE_SENDING)}- </span>- )}+ <PendingStopIcon className="block h-7 w-7 max-w-none" />+ </button>+ ) : null}++ {isCollapsed ? (+ <button+ type="button"+ data-testid="chat-message-expand"+ aria-expanded={false}+ aria-label={t(I18nKey.COMMON$VIEW_MORE)}+ className="absolute inset-0 z-[1] cursor-pointer rounded-xl border-0 bg-transparent p-0"+ onClick={() => setIsExpanded(true)}+ />+ ) : null}++ {children}+ </article>+ );- {pendingStatus === "error" && (- <span+ if (type === "user" && pendingStatus === "error") {+ return (+ <div className="flex w-fit max-w-full flex-col items-end gap-1.5 self-end last:mb-4">+ {messageBubble}+ <divrole="alert"data-testid="chat-message-error"- className="self-end text-xs text-status-fail-text"+ className="flex items-center gap-2 text-xs text-[var(--oh-status-error)]">- {t(I18nKey.CHAT_INTERFACE$MESSAGE_SEND_FAILED)}{" "}- {onRetry && (+ <span>{t(I18nKey.CHAT_INTERFACE$MESSAGE_SEND_FAILED)}</span>+ {onRetry ? (<buttontype="button"onClick={onRetry}- className="underline cursor-pointer"+ className="cursor-pointer rounded-md border border-[var(--oh-border)] px-2 py-1 text-xs font-normal text-[var(--oh-foreground)] hover:bg-[var(--oh-interactive-hover)]"data-testid="chat-message-retry">{t(I18nKey.CHAT_INTERFACE$MESSAGE_RETRY)}</button>- )}- </span>- )}+ ) : null}+ </div>+ </div>+ );+ }- {children}- </article>- );+ if (type === "user" && pendingStatus === "sending") {+ return (+ <div className="flex w-full max-w-full flex-col last:mb-4">+ {messageBubble}+ <div className="my-1 w-full py-1 text-sm">+ <TextShimmer+ as="p"+ role="status"+ aria-live="polite"+ data-testid="chat-message-sending"+ className="block w-full text-sm font-normal"+ duration={1}+ spread={2}+ >+ {t(I18nKey.CHAT_INTERFACE$MESSAGE_SENDING)}+ </TextShimmer>+ </div>+ </div>+ );+ }++ return messageBubble;}diff --git a/src/components/features/chat/pending-user-messages.tsx b/src/components/features/chat/pending-user-messages.tsxindex 9efeb51b5b..e9ccc1985b 100644--- a/src/components/features/chat/pending-user-messages.tsx+++ b/src/components/features/chat/pending-user-messages.tsx@@ -1,5 +1,6 @@import React from "react";import { useOptimisticUserMessageStore } from "#/stores/optimistic-user-message-store";+import { useConversationStore } from "#/stores/conversation-store";import { useSendMessage } from "#/hooks/use-send-message";import { createChatMessage } from "#/services/chat-service";import { useOptionalConversationId } from "#/hooks/use-conversation-id";@@ -30,6 +31,12 @@ export function PendingUserMessages() {const markPendingMessageSending = useOptimisticUserMessageStore((state) => state.markPendingMessageSending,);+ const removePendingMessage = useOptimisticUserMessageStore(+ (state) => state.removePendingMessage,+ );+ const restoreMessageToInputIfEmpty = useConversationStore(+ (state) => state.restoreMessageToInputIfEmpty,+ );const { send } = useSendMessage();const visibleMessages = React.useMemo(@@ -72,6 +79,14 @@ export function PendingUserMessages() {[send, markPendingMessageError, markPendingMessageSending],);+ const handleStop = React.useCallback(+ (id: string, text: string) => {+ restoreMessageToInputIfEmpty(text);+ removePendingMessage(id);+ },+ [restoreMessageToInputIfEmpty, removePendingMessage],+ );+if (visibleMessages.length === 0) {return null;}@@ -89,6 +104,11 @@ export function PendingUserMessages() {? () => handleRetry(message.id): undefined}+ onStop={+ message.status === "sending"+ ? () => handleStop(message.id, message.text)+ : undefined+ }>{message.imageUrls.length > 0 && (<ImageCarousel size="small" images={message.imageUrls} />diff --git a/src/components/shared/text-shimmer.tsx b/src/components/shared/text-shimmer.tsxnew file mode 100644index 0000000000..7428ceb8bc--- /dev/null+++ b/src/components/shared/text-shimmer.tsx@@ -0,0 +1,88 @@+import React, { useId, useMemo } from "react";+import { useReducedMotion } from "framer-motion";+import { cn } from "#/utils/utils";++/**+ * The gradient is an oversized repeating pattern; animating background-position+ * by exactly one period loops with no visible jump and no muted gap between+ * sweeps (the pattern is periodic, so a highlight is always near the text).+ */+const SHIMMER_BACKGROUND_SIZE = "200%";+/** Gradient period as a percentage of the (oversized) background image. */+const SHIMMER_PERIOD = 8;+/** Shifting background-position by one period == 2 * period (image is 2x wide). */+const SHIMMER_TRAVEL = SHIMMER_PERIOD * 2;++export type TextShimmerProps = {+ children: string;+ as?: React.ElementType;+ className?: string;+ duration?: number;+ spread?: number;+} & Omit<React.HTMLAttributes<HTMLElement>, "children" | "className">;++function TextShimmerComponent({+ children,+ as: Component = "p",+ className,+ duration = 2,+ spread = 2,+ style,+ ...rest+}: TextShimmerProps) {+ const reduceMotion = useReducedMotion();+ const reactId = useId();+ const animationName = `oh-text-shimmer-${reactId.replace(/:/g, "")}`;++ // Wider spread => wider bright band within each repeating period.+ const bandHalfWidth = useMemo(+ () => Math.min(SHIMMER_PERIOD / 2 - 1, 1 + spread / 2),+ [spread],+ );++ const shimmerStyle = useMemo(() => {+ const center = SHIMMER_PERIOD / 2;+ return {+ ...style,+ backgroundImage: `repeating-linear-gradient(90deg, var(--oh-muted) 0%, var(--oh-muted) ${center - bandHalfWidth}%, var(--oh-foreground) ${center}%, var(--oh-muted) ${center + bandHalfWidth}%, var(--oh-muted) ${SHIMMER_PERIOD}%)`,+ backgroundSize: `${SHIMMER_BACKGROUND_SIZE} 100%`,+ backgroundRepeat: "no-repeat",+ WebkitBackgroundClip: "text",+ backgroundClip: "text",+ color: "transparent",+ WebkitTextFillColor: "transparent",+ animation: `${animationName} ${duration}s linear infinite`,+ } as React.CSSProperties;+ }, [animationName, bandHalfWidth, duration, style]);++ if (reduceMotion) {+ return (+ <Component+ className={cn("text-[var(--oh-muted)]", className)}+ style={style}+ {...rest}+ >+ {children}+ </Component>+ );+ }++ return (+ <>+ <style+ dangerouslySetInnerHTML={{+ __html: `@keyframes ${animationName}{from{background-position:${SHIMMER_TRAVEL}% center}to{background-position:0% center}}`,+ }}+ />+ <Component+ className={cn("relative inline-block", className)}+ style={shimmerStyle}+ {...rest}+ >+ {children}+ </Component>+ </>+ );+}++export const TextShimmer = React.memo(TextShimmerComponent);diff --git a/src/dev/seed-pending-chat-preview.ts b/src/dev/seed-pending-chat-preview.tsnew file mode 100644index 0000000000..90268a23da--- /dev/null+++ b/src/dev/seed-pending-chat-preview.ts@@ -0,0 +1,69 @@+import { useOptimisticUserMessageStore } from "#/stores/optimistic-user-message-store";++const PREVIEW_SENDING_TEXT = "can you review the readme";++const PREVIEW_SENDING_MULTILINE_TEXT =+ "can you review the readme and then update the contributing guide " ++ "to match, making sure the setup steps and scripts are consistent " ++ "across both files";++const PREVIEW_ERROR_TEXT =+ "here's a long message. here's a long message. here's a long message. " ++ "here's a long message. here's a long message. here's a long message.";++export function seedPendingChatPreview(conversationId: string): void {+ const store = useOptimisticUserMessageStore.getState();+ store.clearPendingMessages();++ store.enqueuePendingMessage({+ conversationId,+ text: PREVIEW_SENDING_TEXT,+ });++ store.enqueuePendingMessage({+ conversationId,+ text: PREVIEW_SENDING_MULTILINE_TEXT,+ });++ const errorId = store.enqueuePendingMessage({+ conversationId,+ text: PREVIEW_ERROR_TEXT,+ });+ store.markPendingMessageError(errorId, "Failed to send message");+}++export function installPendingChatPreview(): void {+ (+ window as Window &+ typeof globalThis & {+ __OH_SEED_PENDING_PREVIEW__?: typeof seedPendingChatPreview;+ __OH_CLEAR_PENDING_PREVIEW__?: () => void;+ }+ ).__OH_SEED_PENDING_PREVIEW__ = seedPendingChatPreview;+ (+ window as Window &+ typeof globalThis & {+ __OH_CLEAR_PENDING_PREVIEW__?: () => void;+ }+ ).__OH_CLEAR_PENDING_PREVIEW__ = () => {+ useOptimisticUserMessageStore.getState().clearPendingMessages();+ };++ const params = new URLSearchParams(window.location.search);+ const preview = params.get("previewPendingChat");+ if (!preview) {+ return;+ }++ const conversationId = preview === "true" ? "1" : preview;+ const targetPath = `/conversations/${conversationId}`;++ if (!window.location.pathname.startsWith(targetPath)) {+ window.location.assign(+ `${targetPath}?previewPendingChat=${encodeURIComponent(conversationId)}`,+ );+ return;+ }++ seedPendingChatPreview(conversationId);+}diff --git a/src/entry.client.tsx b/src/entry.client.tsxindex 3b2dc09737..72c9cbbaa5 100644--- a/src/entry.client.tsx+++ b/src/entry.client.tsx@@ -37,6 +37,12 @@ async function prepareApp() {).__TEST_INVALIDATE_QUERIES__ = (queryKey?: unknown[]) =>void queryClient.invalidateQueries(queryKey ? { queryKey } : undefined);}++ if (import.meta.env.DEV) {+ const { installPendingChatPreview } =+ await import("./dev/seed-pending-chat-preview");+ installPendingChatPreview();+ }}prepareApp().then(() =>diff --git a/src/hooks/chat/use-chat-input-logic.ts b/src/hooks/chat/use-chat-input-logic.tsindex d31f3262da..4c68388c2c 100644--- a/src/hooks/chat/use-chat-input-logic.ts+++ b/src/hooks/chat/use-chat-input-logic.ts@@ -20,8 +20,10 @@ export const useChatInputLogic = () => {const {messageToSend: rawMessageToSend,+ messageRestoreIfEmpty,hasRightPanelToggled,setMessageToSend,+ clearMessageRestoreIfEmpty,setIsRightPanelShown,} = useConversationStore();@@ -39,6 +41,24 @@ export const useChatInputLogic = () => {// touches the element content on the home page.const messageToSend = conversationId ? rawMessageToSend : null;+ // Restore a cancelled pending send back into the input only when empty.+ useEffect(() => {+ if (!conversationId || !messageRestoreIfEmpty) {+ return;+ }++ const currentText = getTextContent(chatInputRef.current).trim();+ if (currentText.length === 0) {+ setMessageToSend(messageRestoreIfEmpty.text);+ }+ clearMessageRestoreIfEmpty();+ }, [+ conversationId,+ messageRestoreIfEmpty,+ setMessageToSend,+ clearMessageRestoreIfEmpty,+ ]);+// Save current input value when drawer state changes (conversation view only)useEffect(() => {if (!conversationId) return;diff --git a/src/i18n/translation.json b/src/i18n/translation.jsonindex 2882a009ee..9382f1fbfa 100644--- a/src/i18n/translation.json+++ b/src/i18n/translation.json@@ -8755,21 +8755,21 @@"ca": "Enviant..."},"CHAT_INTERFACE$MESSAGE_SEND_FAILED": {- "en": "Failed to send.",- "ja": "送信に失敗しました。",- "zh-CN": "发送失败。",- "zh-TW": "傳送失敗。",- "ko-KR": "보내기 실패.",- "no": "Sending mislyktes.",- "it": "Invio non riuscito.",- "pt": "Falha ao enviar.",- "es": "Error al enviar.",- "ar": "فشل الإرسال.",- "fr": "Échec de l'envoi.",- "tr": "Gönderilemedi.",- "de": "Senden fehlgeschlagen.",- "uk": "Не вдалося надіслати.",- "ca": "Error en enviar."+ "en": "Failed to send",+ "ja": "送信に失敗しました",+ "zh-CN": "发送失败",+ "zh-TW": "傳送失敗",+ "ko-KR": "보내기 실패",+ "no": "Sending mislyktes",+ "it": "Invio non riuscito",+ "pt": "Falha ao enviar",+ "es": "Error al enviar",+ "ar": "فشل الإرسال",+ "fr": "Échec de l'envoi",+ "tr": "Gönderilemedi",+ "de": "Senden fehlgeschlagen",+ "uk": "Не вдалося надіслати",+ "ca": "Error en enviar"},"CHAT_INTERFACE$MESSAGE_RETRY": {"en": "Retry",diff --git a/src/icons/stop-circle.svg b/src/icons/stop-circle.svgindex da2ff0d713..6645c26ee9 100644--- a/src/icons/stop-circle.svg+++ b/src/icons/stop-circle.svg@@ -1,4 +1,3 @@<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">- <path d="M9 9H15V15H9V9Z" fill="currentColor"/>- <path fill-rule="evenodd" clip-rule="evenodd" d="M12.9 1.50004C15.3 1.65004 17.55 2.85004 19.2 4.50004C21.15 6.60004 22.2 9.15004 22.2 12.15C22.2 14.55 21.3 16.8 19.8 18.75C18.3 20.55 16.2 21.9 13.8 22.35C11.4 22.8 9 22.5 6.9 21.3C4.8 20.1 3.15 18.3 2.25 16.05C1.35 13.8 1.2 11.25 1.95 9.00004C2.7 6.60004 4.05 4.65004 6.15 3.30004C8.1 1.95004 10.5 1.35004 12.9 1.50004ZM13.65 20.85C15.6 20.4 17.4 19.35 18.75 17.7C19.95 16.05 20.7 14.1 20.55 12C20.55 9.60004 19.65 7.20004 18 5.55004C16.5 4.05004 14.7 3.15004 12.6 3.00004C10.65 2.85004 8.55 3.30004 6.9 4.50004C5.25 5.70004 4.05 7.35004 3.45 9.45004C2.85 11.4 2.85 13.5 3.75 15.45C4.65 17.4 6 18.9 7.8 19.95C9.6 21 11.7 21.3 13.65 20.85Z" fill="currentColor"/>+ <path fill-rule="evenodd" clip-rule="evenodd" d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22ZM10 9H14A1 1 0 0 1 15 10V14A1 1 0 0 1 14 15H10A1 1 0 0 1 9 14V10A1 1 0 0 1 10 9Z" fill="currentColor"/></svg>diff --git a/src/stores/conversation-store.ts b/src/stores/conversation-store.tsindex 8e3b75ee6e..458f9553ca 100644--- a/src/stores/conversation-store.ts+++ b/src/stores/conversation-store.ts@@ -32,6 +32,8 @@ interface ConversationState {loadingFiles: string[]; // File names currently being processedloadingImages: string[]; // Image names currently being processedmessageToSend: IMessageToSend | null;+ /** One-shot restore request consumed by the chat input when empty. */+ messageRestoreIfEmpty: IMessageToSend | null;shouldShownAgentLoading: boolean;submittedMessage: string | null;shouldHideSuggestions: boolean; // New state to hide suggestions when input expands@@ -61,6 +63,8 @@ interface ConversationActions {removeImageLoading: (imageName: string) => void;clearAllLoading: () => void;setMessageToSend: (text: string) => void;+ restoreMessageToInputIfEmpty: (text: string) => void;+ clearMessageRestoreIfEmpty: () => void;setSubmittedMessage: (message: string | null) => void;resetConversationState: () => void;setHasRightPanelToggled: (hasRightPanelToggled: boolean) => void;@@ -117,6 +121,7 @@ export const useConversationStore = create<ConversationStore>()(loadingFiles: [],loadingImages: [],messageToSend: null,+ messageRestoreIfEmpty: null,shouldShownAgentLoading: false,submittedMessage: null,shouldHideSuggestions: false,@@ -289,6 +294,25 @@ export const useConversationStore = create<ConversationStore>()("setMessageToSend",),+ restoreMessageToInputIfEmpty: (text) =>+ set(+ {+ messageRestoreIfEmpty: {+ text,+ timestamp: Date.now(),+ },+ },+ false,+ "restoreMessageToInputIfEmpty",+ ),++ clearMessageRestoreIfEmpty: () =>+ set(+ { messageRestoreIfEmpty: null },+ false,+ "clearMessageRestoreIfEmpty",+ ),+setSubmittedMessage: (submittedMessage) =>set({ submittedMessage }, false, "setSubmittedMessage"),diff --git a/src/tailwind.css b/src/tailwind.cssindex 17bb1cc0b6..af317f1fd1 100644--- a/src/tailwind.css+++ b/src/tailwind.css@@ -606,6 +606,32 @@ button.extension-module-card-interactive {var(--cool-grey-50);}+/* Flowing gradient text used for live agent activity (matches Proton). */+@keyframes gradient-slide {+ 0% {+ background-position: 200% 50%;+ }+ 100% {+ background-position: 0% 50%;+ }+}++.gradient-flow {+ color: transparent;+ background-image: linear-gradient(+ 90deg,+ var(--oh-muted) 0%,+ var(--oh-foreground) 50%,+ var(--oh-muted) 100%+ );+ background-size: 200% 100%;+ background-repeat: repeat-x;+ -webkit-background-clip: text;+ background-clip: text;+ -webkit-text-fill-color: transparent;+ animation: gradient-slide 1.25s linear infinite;+}+/* CTA card gradient and shadow */.cta-card-gradient {background: