feat(webui): show when the agent picks up queued messages (#6719)

This commit is contained in:
chengyongru authored and GitHub committed 2026-11-19 16:03:16 +08:00
1 parent 3025a01cf0
commit b453de9cf6
26 files changed
+642 -29

No files matched your search

+6 -1
View File
@@ -2,6 +2,7 @@ import { useState, type ReactNode } from "react";
import { FileText, ImageIcon, Video } from "lucide-react";
import { useTranslation } from "react-i18next";
import { PendingEdgeOverlay, type PendingEdgeState } from "@/components/PendingEdgeOverlay";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
import type { UIMediaKind } from "@/lib/types";
@@ -10,12 +11,14 @@ import { cn } from "@/lib/utils";
export const attachmentCardActionClassName = "absolute right-0 top-0 grid h-11 w-11 place-items-center rounded-full focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring";
/** The card owns only its information surface; callers own removal, download, and status. */
export function AttachmentCard({ name, description, children, action, invalid = false }: {
export function AttachmentCard({ name, description, children, action, invalid = false, edgeState = "solid", onSealEnd }: {
name: string;
description?: string;
children: ReactNode;
action?: ReactNode;
invalid?: boolean;
edgeState?: PendingEdgeState;
onSealEnd?: () => void;
}) {
const [detailsOpen, setDetailsOpen] = useState(false);
const [hintOpen, setHintOpen] = useState(false);
@@ -28,7 +31,9 @@ export function AttachmentCard({ name, description, children, action, invalid =
return <span className={cn(
"relative block h-24 w-24 max-w-full shrink-0 rounded-control border transition-colors motion-reduce:transition-none",
invalid ? "border-destructive/40 bg-destructive/5 text-destructive" : "border-border/70 bg-muted/35",
edgeState !== "solid" && "border-transparent",
)}>
<PendingEdgeOverlay state={edgeState} solidTone="card" inset="-inset-px" onSealEnd={onSealEnd} />
<TooltipProvider>
<Tooltip open={hintOpen && !detailsOpen} onOpenChange={setHintOpen}>
<Popover open={detailsOpen} onOpenChange={changeDetailsOpen}>
+18 -5
View File
@@ -8,6 +8,7 @@ import { ImageThumbnail } from "@/components/ImageGallery";
import { ImageLightbox } from "@/components/ImageLightbox";
import { useRegisterInlineImage } from "@/components/InlineImageContext";
import { AttachmentCard, AttachmentTypeFace, attachmentCardActionClassName } from "@/components/AttachmentCard";
import { PendingEdgeOverlay, type PendingEdgeState } from "@/components/PendingEdgeOverlay";
interface AttachmentTileProps {
attachment: UIMediaAttachment;
@@ -15,9 +16,11 @@ interface AttachmentTileProps {
inline?: boolean;
variant?: "default" | "compact";
pending?: boolean;
edgeState?: PendingEdgeState;
onSealEnd?: () => void;
}
export function AttachmentTile({ attachment, className, inline = false, variant = "default", pending = false }: AttachmentTileProps) {
export function AttachmentTile({ attachment, className, inline = false, variant = "default", pending = false, edgeState = "solid", onSealEnd }: AttachmentTileProps) {
const { t } = useTranslation();
const videoUrl = attachment.url;
const [failedUrl, setFailedUrl] = useState<string | undefined>(undefined);
@@ -31,7 +34,7 @@ export function AttachmentTile({ attachment, className, inline = false, variant
return (
<span className={cn("not-prose my-3 block max-w-full", className)}>
<ImageThumbnail key={attachment.url} image={attachment}
size={variant === "compact" ? "compact" : "large"}
size={variant === "compact" ? "compact" : "large"} edgeState={edgeState} onSealEnd={onSealEnd}
onOpen={() => setImageOpen(true)} onError={() => setFailedUrl(attachment.url)} />
<ImageLightbox images={[attachment]} index={imageOpen ? 0 : null}
onIndexChange={() => {}} onOpenChange={setImageOpen} />
@@ -46,6 +49,8 @@ export function AttachmentTile({ attachment, className, inline = false, variant
className={className}
inline={inline}
variant={variant}
edgeState={edgeState}
onSealEnd={onSealEnd}
>
<video
src={videoUrl}
@@ -73,7 +78,7 @@ export function AttachmentTile({ attachment, className, inline = false, variant
</a> : undefined;
return <span data-file-attachment className={cn("not-prose inline-flex w-24 max-w-full shrink-0 flex-col gap-1 align-top", className)}>
<AttachmentCard name={name} description={status} action={download}>
<AttachmentCard name={name} description={status} action={download} edgeState={edgeState} onSealEnd={onSealEnd}>
<AttachmentTypeFace name={filePath} kind={attachment.kind} />
</AttachmentCard>
{status ? <span className="break-words text-center text-[11px] leading-4 text-muted-foreground">{status}</span> : null}
@@ -92,16 +97,21 @@ function AttachmentFrame({
className,
inline = false,
variant = "default",
edgeState = "solid",
onSealEnd,
}: {
attachment: UIMediaAttachment;
children: ReactNode;
className?: string;
inline?: boolean;
variant?: "default" | "compact";
edgeState?: PendingEdgeState;
onSealEnd?: () => void;
}) {
const frameClassName = cn(
"not-prose my-3 block w-fit max-w-full overflow-hidden rounded-control",
"border border-border/60 bg-muted/40",
"not-prose relative my-3 block w-fit max-w-full overflow-hidden rounded-control",
edgeState === "solid" && "ring-1 ring-inset ring-border/60",
"bg-muted/40",
attachment.kind === "image" && "bg-background/85",
attachment.kind === "video" ? "w-[min(100%,32rem)]" : "",
variant === "compact" && "my-1 rounded-xl shadow-none",
@@ -114,13 +124,16 @@ function AttachmentFrame({
) : (
<div className={bodyClassName}>{children}</div>
);
const edgeOverlay = <PendingEdgeOverlay state={edgeState} solidTone="media" onSealEnd={onSealEnd} />;
return inline ? (
<span className={frameClassName}>
{body}
{edgeOverlay}
</span>
) : (
<figure className={frameClassName}>
{body}
{edgeOverlay}
</figure>
);
}
+14 -5
View File
@@ -3,15 +3,18 @@ import { ImageIcon } from "lucide-react";
import { useTranslation } from "react-i18next";
import { ImageLightbox } from "@/components/ImageLightbox";
import { PendingEdgeOverlay, type PendingEdgeState } from "@/components/PendingEdgeOverlay";
import { IMAGE_GAP, imageFrameRatio, layoutImageRows, type ImageDimensions } from "@/lib/image-gallery-layout";
import type { UIImage } from "@/lib/types";
import { cn } from "@/lib/utils";
/** A bounded, quiet preview; the viewer still contains every delivered image. */
export function ImageGallery({ images, align = "left", size = "large" }: {
export function ImageGallery({ images, align = "left", size = "large", edgeState = "solid", onSealEnd }: {
images: UIImage[];
align?: "left" | "right";
size?: "compact" | "large";
edgeState?: PendingEdgeState;
onSealEnd?: () => void;
}) {
const { t } = useTranslation();
const [index, setIndex] = useState<number | null>(null);
@@ -70,7 +73,8 @@ export function ImageGallery({ images, align = "left", size = "large" }: {
const remaining = images.length - visible.length;
const overflow = position === visible.length - 1 && remaining > 0;
return <ImageThumbnail key={`${image.url ?? image.name}-${position}`}
image={image} size={size} frame={frame}
image={image} size={size} frame={frame} edgeState={edgeState}
onSealEnd={position === 0 ? onSealEnd : undefined}
onLoad={(value) => { if (image.url) remember(image.url, value); }}
onError={() => { if (image.url) remember(image.url, null); }}
label={overflow ? t("lightbox.viewAll", { count: images.length }) : undefined}
@@ -83,9 +87,11 @@ export function ImageGallery({ images, align = "left", size = "large" }: {
</>;
}
export function ImageThumbnail({ image, size = "large", frame, onOpen, label, overlay, onLoad, onError }: {
export function ImageThumbnail({ image, size = "large", frame, onOpen, label, overlay, onLoad, onError, edgeState = "solid", onSealEnd }: {
image: UIImage;
size?: "compact" | "large";
edgeState?: PendingEdgeState;
onSealEnd?: () => void;
frame?: ImageDimensions & { left: number; top: number };
onOpen?: () => void;
label?: string;
@@ -96,11 +102,13 @@ export function ImageThumbnail({ image, size = "large", frame, onOpen, label, ov
const { t } = useTranslation();
const [failed, setFailed] = useState(false);
const classes = cn(
"relative block max-w-full shrink-0 overflow-hidden rounded-control bg-muted/25 ring-1 ring-inset ring-border/60",
"relative block max-w-full shrink-0 overflow-hidden rounded-control bg-muted/25",
edgeState === "solid" && "ring-1 ring-inset ring-border/60",
!frame && (size === "large" ? "w-[min(100%,28rem)]" : "w-48"),
);
const style: CSSProperties | undefined = frame ? { ...frame, position: "absolute" } : undefined;
const unavailable = t("message.attachmentUnavailable");
const edgeOverlay = <PendingEdgeOverlay state={edgeState} solidTone="media" onSealEnd={onSealEnd} />;
const content = image.url && !failed ? <img src={image.url} alt={image.name ?? ""}
loading="lazy" decoding="async" draggable={false}
onLoad={(event) => {
@@ -114,11 +122,12 @@ export function ImageThumbnail({ image, size = "large", frame, onOpen, label, ov
<ImageIcon className="h-4 w-4 shrink-0" aria-hidden />
<span className="min-w-0 truncate">{unavailable}</span>
</span>;
if (!onOpen || ((!image.url || failed) && !overlay)) return <span className={classes} style={style}>{content}</span>;
if (!onOpen || ((!image.url || failed) && !overlay)) return <span className={classes} style={style}>{content}{edgeOverlay}</span>;
return <button type="button" onClick={onOpen} style={style}
aria-label={label ?? (image.name ? `${t("lightbox.open")}: ${image.name}` : t("lightbox.open"))}
className={cn(classes, "cursor-zoom-in p-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background")}>
{content}
{overlay ? <span className="absolute inset-0 flex items-center justify-center bg-black/45 text-xl font-medium text-white" aria-hidden>{overlay}</span> : null}
{edgeOverlay}
</button>;
}
+54 -8
View File
@@ -19,6 +19,7 @@ import { ImageGallery } from "@/components/ImageGallery";
import { InlineImageProvider, useInlineImages } from "@/components/InlineImageContext";
import { INLINE_REFERENCE_HIGHLIGHT_COLOR, InlineTokenHighlight } from "@/components/InlineTokenHighlight";
import { MarkdownText } from "@/components/MarkdownText";
import { PendingEdgeOverlay, usePendingEdgeState, type PendingEdgeState } from "@/components/PendingEdgeOverlay";
import { SlashCommandText } from "@/components/SlashCommandText";
import { ReasoningRow } from "@/components/thread/activity/ReasoningRow";
import { StreamingLabelSheen } from "@/components/ui/streaming-label-sheen";
@@ -424,6 +425,11 @@ export function MessageBubble({
() => mergeMcpMentionPresets(mcpPresets, message.mcpPresets),
[mcpPresets, message.mcpPresets],
);
const { edgeState, completeSeal } = usePendingEdgeState(
message.id,
message.role === "user" ? message.processingStatus : undefined,
temporary || message.role !== "user",
);
if (message.kind === "compaction" && message.compaction) {
return <ContextCompactionNotice compaction={message.compaction} />;
@@ -453,6 +459,15 @@ export function MessageBubble({
const hasText = userContent.trim().length > 0;
const showDeliveryStatus =
message.deliveryStatus === "sending" || message.deliveryStatus === "failed";
const processingStatus = message.processingStatus;
const showProcessingStatus = !temporary && processingStatus === "pending";
const mediaEdgeState: PendingEdgeState = !hasText ? edgeState : "solid";
const mediaSealEnd = !hasText ? completeSeal : undefined;
const userMedia = hasImages
? <ImageGallery images={images} align="right" size="compact" edgeState={mediaEdgeState} onSealEnd={mediaSealEnd} />
: hasMedia
? <MessageMedia media={media} align="right" pending={message.deliveryStatus === "sending"} edgeState={mediaEdgeState} onSealEnd={mediaSealEnd} />
: null;
const quotedContext = parsedMessage.quotedContext;
const slashCommand = matchingSlashCommand(userContent, slashCommands);
const bangPrefix = /^(\s*)!/.exec(userContent);
@@ -487,10 +502,7 @@ export function MessageBubble({
className="group relative ml-auto flex w-fit max-w-[min(85%,36rem)] flex-col items-end gap-1.5"
>
{!hasText ? contextMenu : null}
{hasImages ? <ImageGallery images={images} align="right" size="compact" /> : null}
{!hasImages && hasMedia ? (
<MessageMedia media={media} align="right" pending={message.deliveryStatus === "sending"} />
) : null}
{userMedia}
{quotedContext ? (
<UserQuotedContext
text={quotedContext}
@@ -503,18 +515,26 @@ export function MessageBubble({
<p
data-theme-surface
data-temporary-message={temporary ? "true" : undefined}
data-pending-edge={edgeState !== "solid" ? edgeState : undefined}
className={cn(
"ml-auto w-fit max-w-full min-w-0 rounded-floating px-4 py-2",
"relative ml-auto w-fit max-w-full min-w-0 rounded-floating px-4 py-2",
"text-left text-reading whitespace-pre-wrap [overflow-wrap:anywhere]",
temporary
? "border border-dashed border-muted-foreground/40 bg-transparent"
: "user-message-surface bg-secondary/70",
showProcessingStatus && "user-message-surface-dashed",
)}
>
<PendingEdgeOverlay state={edgeState} onSealEnd={completeSeal} />
{messageText}
</p>
</div>
) : null}
{!showDeliveryStatus && showProcessingStatus ? (
<span role="status" className="sr-only">
{t("message.delivery.waiting")}
</span>
) : null}
{showDeliveryStatus ? (
<div className="flex min-h-8 items-center justify-end gap-1.5 text-muted-foreground">
<UserDeliveryStatus
@@ -657,10 +677,14 @@ function MessageMedia({
media,
align,
pending = false,
edgeState = "solid",
onSealEnd,
}: {
media: UIMediaAttachment[];
align: "left" | "right";
pending?: boolean;
edgeState?: PendingEdgeState;
onSealEnd?: () => void;
}) {
const inlineImages = useInlineImages();
if (media.length === 0) return null;
@@ -681,6 +705,9 @@ function MessageMedia({
}
}
if (images.length === 0 && videos.length === 0 && files.length === 0) return null;
const attachSealToImages = images.length > 0;
const attachSealToVideos = !attachSealToImages && videos.length > 0;
const attachSealToFiles = !attachSealToImages && !attachSealToVideos;
return (
<div
@@ -690,15 +717,34 @@ function MessageMedia({
)}
>
{images.length > 0 ? (
<ImageGallery images={images} align={align} size={align === "left" ? "large" : "compact"} />
<ImageGallery
images={images}
align={align}
size={align === "left" ? "large" : "compact"}
edgeState={edgeState}
onSealEnd={attachSealToImages ? onSealEnd : undefined}
/>
) : null}
{videos.map((item, i) => (
<AttachmentTile key={`video-${i}`} attachment={item} pending={pending} className="my-0" />
<AttachmentTile
key={`video-${i}`}
attachment={item}
pending={pending}
edgeState={edgeState}
onSealEnd={attachSealToVideos && i === 0 ? onSealEnd : undefined}
className="my-0"
/>
))}
{files.length > 0 ? (
<div className={cn("flex w-full min-w-0 flex-wrap items-start gap-2", align === "right" && "justify-end")}>
{files.map((item, i) => (
<AttachmentTile key={`file-${i}`} attachment={item} pending={pending} />
<AttachmentTile
key={`file-${i}`}
attachment={item}
pending={pending}
edgeState={edgeState}
onSealEnd={attachSealToFiles && i === 0 ? onSealEnd : undefined}
/>
))}
</div>
) : null}
+103
View File
@@ -0,0 +1,103 @@
import { useCallback, useEffect, useState } from "react";
import type { InputProcessingStatus } from "@/lib/types";
import { cn } from "@/lib/utils";
export type PendingEdgeState = "solid" | "pending" | "sealing";
const SEAL_FALLBACK_MS = 560;
/**
* Tracks the visual edge lifecycle for queued user messages:
* - "pending" while waiting in queue (dashed with subtle breathing)
* - "cancelled" when stopped before consumption (static dashed)
* - "sealing" for a single transition when a live message moves pending -> consumed
* - "solid" at rest (including historical messages loaded as consumed)
*/
export function usePendingEdgeState(
messageId: string,
processingStatus: InputProcessingStatus | undefined,
disabled: boolean,
): { edgeState: PendingEdgeState; completeSeal: () => void } {
const [tracked, setTracked] = useState<{
id: string;
status: InputProcessingStatus | undefined;
sealing: boolean;
}>({
id: messageId,
status: processingStatus,
sealing: false,
});
if (tracked.id !== messageId || tracked.status !== processingStatus) {
const shouldSeal =
!disabled &&
tracked.id === messageId &&
((tracked.status === "pending" && processingStatus === "consumed") ||
(tracked.sealing && processingStatus === undefined));
setTracked({
id: messageId,
status: processingStatus,
sealing: shouldSeal,
});
}
const edgeState: PendingEdgeState = disabled
? "solid"
: processingStatus === "pending"
? "pending"
: tracked.sealing
? "sealing"
: "solid";
const completeSeal = useCallback(() => {
setTracked((prev) => (prev.sealing ? { ...prev, sealing: false } : prev));
}, []);
useEffect(() => {
if (edgeState !== "sealing") return;
const timer = window.setTimeout(completeSeal, SEAL_FALLBACK_MS);
return () => window.clearTimeout(timer);
}, [edgeState, completeSeal]);
return { edgeState, completeSeal };
}
export function PendingEdgeOverlay({
state,
solidTone = "bubble",
inset = "inset-0",
onSealEnd,
}: {
state: PendingEdgeState;
solidTone?: "bubble" | "card" | "media";
inset?: string;
onSealEnd?: () => void;
}) {
if (state === "solid") return null;
return (
<span
aria-hidden="true"
data-pending-edge-overlay={state}
data-solid-tone={solidTone}
className={cn("pending-edge-overlay", inset)}
onAnimationEnd={(event) => {
if (
state === "sealing" &&
(event.animationName === "pending-edge-seal" ||
event.animationName === "pending-edge-fade-out")
) {
onSealEnd?.();
}
}}
>
<span className="pending-edge-layer pending-edge-layer-dashed" />
{state === "sealing" ? (
<>
<span className="pending-edge-layer pending-edge-layer-solid" />
<span className="pending-edge-layer pending-edge-layer-sheen" />
</>
) : null}
</span>
);
}