Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(ui): add collapsible animations and data-state custom variants

Steven Enamakela83de78f1c7e
diff --git a/app/src/components/assistant-ui/attachment.tsx b/app/src/components/assistant-ui/attachment.tsx
new file mode 100644
index 0000000000..b59a195ac2
--- /dev/null
+++ b/app/src/components/assistant-ui/attachment.tsx
@@ -0,0 +1,294 @@
+"use client";
+
+import { type PropsWithChildren, useEffect, useState, type FC } from "react";
+import {
+ XIcon,
+ PlusIcon,
+ FileText,
+ Loader2Icon,
+ AlertCircleIcon,
+} from "lucide-react";
+import {
+ AttachmentPrimitive,
+ ComposerPrimitive,
+ MessagePrimitive,
+ useAuiState,
+ useAui,
+} from "@assistant-ui/react";
+import { useShallow } from "zustand/react/shallow";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipProvider,
+ TooltipTrigger,
+} from "@/components/assistant-ui/ui/tooltip";
+import {
+ Dialog,
+ DialogTitle,
+ DialogContent,
+ DialogTrigger,
+} from "@/components/assistant-ui/ui/dialog";
+import {
+ Avatar,
+ AvatarImage,
+ AvatarFallback,
+} from "@/components/assistant-ui/ui/avatar";
+import { TooltipIconButton } from "@/components/assistant-ui/tooltip-icon-button";
+import { cn } from "@/components/assistant-ui/lib/utils";
+
+const useFileSrc = (file: File | undefined) => {
+ const [src, setSrc] = useState<string | undefined>(undefined);
+
+ useEffect(() => {
+ if (!file) {
+ setSrc(undefined);
+ return;
+ }
+
+ const objectUrl = URL.createObjectURL(file);
+ setSrc(objectUrl);
+
+ return () => {
+ URL.revokeObjectURL(objectUrl);
+ };
+ }, [file]);
+
+ return src;
+};
+
+const useAttachmentSrc = () => {
+ const { file, src } = useAuiState(
+ useShallow((s): { file?: File; src?: string } => {
+ if (s.attachment.type !== "image") return {};
+ if (s.attachment.file) return { file: s.attachment.file };
+ const src = s.attachment.content?.filter((c) => c.type === "image")[0]
+ ?.image;
+ if (!src) return {};
+ return { src };
+ }),
+ );
+
+ return useFileSrc(file) ?? src;
+};
+
+type AttachmentPreviewProps = {
+ src: string;
+};
+
+const AttachmentPreview: FC<AttachmentPreviewProps> = ({ src }) => {
+ const [isLoaded, setIsLoaded] = useState(false);
+ return (
+ <img
+ src={src}
+ alt="Attachment preview"
+ className={cn(
+ "block h-auto max-h-[80vh] w-auto max-w-full rounded-sm object-contain transition-opacity duration-300 motion-reduce:transition-none",
+ isLoaded
+ ? "aui-attachment-preview-image-loaded opacity-100"
+ : "aui-attachment-preview-image-loading opacity-0",
+ )}
+ onLoad={() => setIsLoaded(true)}
+ />
+ );
+};
+
+const AttachmentPreviewDialog: FC<PropsWithChildren> = ({ children }) => {
+ const src = useAttachmentSrc();
+
+ if (!src) return children;
+
+ return (
+ <Dialog>
+ <DialogTrigger
+ className="aui-attachment-preview-trigger cursor-zoom-in"
+ asChild
+ >
+ {children}
+ </DialogTrigger>
+ <DialogContent className="aui-attachment-preview-dialog-content [&>button]:bg-foreground/60 [&>button]:hover:bg-foreground/80 [&_svg]:text-background p-2 sm:max-w-3xl [&>button]:rounded-full [&>button]:p-1 [&>button]:opacity-100 [&>button]:ring-0!">
+ <DialogTitle className="aui-sr-only sr-only">
+ Image Attachment Preview
+ </DialogTitle>
+ <div className="aui-attachment-preview bg-background relative mx-auto flex max-h-[80dvh] w-full items-center justify-center overflow-hidden rounded-sm">
+ <AttachmentPreview src={src} />
+ </div>
+ </DialogContent>
+ </Dialog>
+ );
+};
+
+const AttachmentThumb: FC = () => {
+ const src = useAttachmentSrc();
+
+ return (
+ <Avatar className="aui-attachment-tile-avatar h-full w-full rounded-none">
+ <AvatarImage
+ src={src}
+ alt="Attachment preview"
+ className="aui-attachment-tile-image rounded-none object-cover"
+ />
+ <AvatarFallback>
+ <FileText className="aui-attachment-tile-fallback-icon text-muted-foreground/80 size-6 stroke-[1.5]" />
+ </AvatarFallback>
+ </Avatar>
+ );
+};
+
+const AttachmentUI: FC = () => {
+ const aui = useAui();
+ const isComposer = aui.attachment.source !== "message";
+
+ const isImage = useAuiState((s) => s.attachment.type === "image");
+ const typeLabel = useAuiState((s) => {
+ const type = s.attachment.type;
+ switch (type) {
+ case "image":
+ return "Image";
+ case "document":
+ return "Document";
+ case "file":
+ return "File";
+ default:
+ return type;
+ }
+ });
+
+ const uploadState = useAuiState((s) =>
+ s.attachment.status.type === "running"
+ ? "uploading"
+ : s.attachment.status.type === "incomplete" &&
+ s.attachment.status.reason === "error"
+ ? "error"
+ : undefined,
+ );
+ const isUploading = uploadState === "uploading";
+ const isError = uploadState === "error";
+
+ const errorMessage = useAuiState((s) =>
+ s.attachment.status.type === "incomplete" &&
+ s.attachment.status.reason === "error"
+ ? (s.attachment.status.message ?? "Upload failed")
+ : undefined,
+ );
+
+ return (
+ <TooltipProvider>
+ <Tooltip>
+ <AttachmentPrimitive.Root
+ className={cn(
+ "aui-attachment-root relative",
+ isComposer &&
+ "animate-in fade-in-0 zoom-in-95 duration-200 motion-reduce:animate-none",
+ isImage &&
+ !isComposer &&
+ "aui-attachment-root-message only:*:first:size-24",
+ )}
+ >
+ <AttachmentPreviewDialog>
+ <TooltipTrigger asChild>
+ <div
+ className={cn(
+ "aui-attachment-tile bg-muted hover:after:bg-foreground/10 focus-visible:ring-ring/50 relative size-14 cursor-pointer overflow-hidden rounded-[calc(var(--composer-radius,1.5rem)-var(--composer-padding,8px))] transition-transform outline-none after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] after:ring-1 after:ring-black/10 after:transition-colors after:ring-inset focus-visible:ring-1 active:scale-[0.96] motion-reduce:transition-none dark:after:ring-white/10",
+ isError &&
+ "after:ring-destructive/60 dark:after:ring-destructive/60",
+ )}
+ role="button"
+ tabIndex={0}
+ onKeyDown={(e) => {
+ if (e.key === "Enter") {
+ e.preventDefault();
+ e.currentTarget.click();
+ } else if (e.key === " ") {
+ e.preventDefault();
+ }
+ }}
+ onKeyUp={(e) => {
+ if (e.key === " ") e.currentTarget.click();
+ }}
+ aria-label={`${typeLabel} attachment${
+ isError ? ", upload failed" : isUploading ? ", uploading" : ""
+ }`}
+ >
+ <AttachmentThumb />
+ {isUploading && (
+ <div
+ aria-hidden="true"
+ className="aui-attachment-tile-uploading bg-background/60 animate-in fade-in-0 absolute inset-0 flex items-center justify-center backdrop-blur-[2px] motion-reduce:animate-none"
+ >
+ <Loader2Icon className="text-muted-foreground size-4 animate-spin" />
+ </div>
+ )}
+ {isError && (
+ <div
+ aria-hidden="true"
+ className="aui-attachment-tile-error bg-background/70 animate-in fade-in-0 absolute inset-0 flex items-center justify-center backdrop-blur-[2px] motion-reduce:animate-none"
+ >
+ <AlertCircleIcon className="text-destructive size-4" />
+ </div>
+ )}
+ </div>
+ </TooltipTrigger>
+ </AttachmentPreviewDialog>
+ {isComposer && <AttachmentRemove />}
+ </AttachmentPrimitive.Root>
+ <TooltipContent side="top">
+ <AttachmentPrimitive.Name />
+ {errorMessage && (
+ <p className="aui-attachment-error-message">{errorMessage}</p>
+ )}
+ </TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
+ );
+};
+
+const AttachmentRemove: FC = () => {
+ return (
+ <AttachmentPrimitive.Remove asChild>
+ <TooltipIconButton
+ tooltip="Remove file"
+ className="aui-attachment-tile-remove absolute end-1 top-1 size-5 rounded-full bg-black/50! text-white after:absolute after:-inset-1.5 hover:bg-black/70! hover:text-white! active:scale-[0.96] motion-reduce:transition-none"
+ side="top"
+ >
+ <XIcon className="aui-attachment-remove-icon size-3 stroke-[2.5]" />
+ </TooltipIconButton>
+ </AttachmentPrimitive.Remove>
+ );
+};
+
+export const UserMessageAttachments: FC = () => {
+ return (
+ <div className="aui-user-message-attachments-end col-span-full col-start-1 row-start-1 flex w-full flex-row justify-end gap-2">
+ <MessagePrimitive.Attachments>
+ {() => <AttachmentUI />}
+ </MessagePrimitive.Attachments>
+ </div>
+ );
+};
+
+export const ComposerAttachments: FC = () => {
+ return (
+ <div className="aui-composer-attachments flex w-full flex-row items-center gap-2 overflow-x-auto empty:hidden">
+ <ComposerPrimitive.Attachments>
+ {() => <AttachmentUI />}
+ </ComposerPrimitive.Attachments>
+ </div>
+ );
+};
+
+export const ComposerAddAttachment: FC = () => {
+ return (
+ <ComposerPrimitive.AddAttachment asChild>
+ <TooltipIconButton
+ tooltip="Add Attachment"
+ side="bottom"
+ variant="ghost"
+ size="icon"
+ className="aui-composer-add-attachment text-muted-foreground hover:text-foreground hover:bg-muted-foreground/15 dark:border-muted-foreground/15 dark:hover:bg-muted-foreground/30 size-7 rounded-full active:scale-[0.96] motion-reduce:transition-none"
+ aria-label="Add Attachment"
+ >
+ <PlusIcon className="aui-attachment-add-icon size-4" />
+ </TooltipIconButton>
+ </ComposerPrimitive.AddAttachment>
+ );
+};
diff --git a/app/src/components/assistant-ui/file.tsx b/app/src/components/assistant-ui/file.tsx
new file mode 100644
index 0000000000..047d3bd89a
--- /dev/null
+++ b/app/src/components/assistant-ui/file.tsx
@@ -0,0 +1,265 @@
+"use client";
+
+import { memo, type FC } from "react";
+import { cva, type VariantProps } from "class-variance-authority";
+import {
+ FileIcon,
+ FileTextIcon,
+ ImageIcon,
+ MusicIcon,
+ VideoIcon,
+ BracesIcon,
+ DownloadIcon,
+} from "lucide-react";
+import type { FileMessagePartComponent } from "@assistant-ui/react";
+import { cn } from "@/components/assistant-ui/lib/utils";
+
+const fileVariants = cva(
+ "aui-file-root inline-flex items-center gap-3 rounded-lg transition-colors",
+ {
+ variants: {
+ variant: {
+ outline: "border-border hover:bg-muted/50 border",
+ ghost: "hover:bg-muted/50",
+ muted: "bg-muted/50 hover:bg-muted/70",
+ },
+ size: {
+ sm: "px-2.5 py-1.5 text-xs",
+ default: "px-3 py-2 text-sm",
+ lg: "px-4 py-3 text-base",
+ },
+ },
+ defaultVariants: {
+ variant: "outline",
+ size: "default",
+ },
+ },
+);
+
+function getMimeTypeIcon(mimeType: string): FC<{ className?: string }> {
+ const type = mimeType.toLowerCase();
+ if (type.startsWith("image/")) {
+ return ImageIcon;
+ }
+ if (type === "application/pdf") {
+ return FileTextIcon;
+ }
+ if (type === "application/json") {
+ return BracesIcon;
+ }
+ if (type.startsWith("text/")) {
+ return FileTextIcon;
+ }
+ if (type.startsWith("audio/")) {
+ return MusicIcon;
+ }
+ if (type.startsWith("video/")) {
+ return VideoIcon;
+ }
+ return FileIcon;
+}
+
+export type FileDataKind = "data-uri" | "url" | "base64" | "id";
+
+function getFileDataKind(
+ data: string,
+ sourceType?: "url" | "id",
+): FileDataKind {
+ if (sourceType === "url" && /^data:/i.test(data)) return "data-uri";
+ if (sourceType) return sourceType;
+ if (/^data:/i.test(data)) return "data-uri";
+ if (/^https?:\/\//i.test(data)) return "url";
+ return "base64";
+}
+
+function getBase64Size(base64: string): number {
+ const commaIndex = base64.indexOf(",");
+ const base64Data = commaIndex >= 0 ? base64.slice(commaIndex + 1) : base64;
+ const padding = (base64Data.match(/=/g) || []).length;
+ return Math.floor((base64Data.length * 3) / 4) - padding;
+}
+
+function formatFileSize(bytes: number): string {
+ if (bytes < 1024) {
+ return `${bytes} B`;
+ }
+ if (bytes < 1024 * 1024) {
+ return `${(bytes / 1024).toFixed(1)} KB`;
+ }
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
+}
+
+export type FileRootProps = React.ComponentProps<"div"> &
+ VariantProps<typeof fileVariants>;
+
+function FileRoot({
+ className,
+ variant,
+ size,
+ children,
+ ...props
+}: FileRootProps) {
+ return (
+ <div
+ data-slot="file-root"
+ data-variant={variant}
+ data-size={size}
+ className={cn(fileVariants({ variant, size, className }))}
+ {...props}
+ >
+ {children}
+ </div>
+ );
+}
+
+type FileIconDisplayProps = React.ComponentProps<"span"> & {
+ mimeType?: string;
+};
+
+function FileIconDisplay({
+ mimeType,
+ className,
+ children,
+ ...props
+}: FileIconDisplayProps) {
+ const IconComponent = mimeType ? getMimeTypeIcon(mimeType) : FileIcon;
+
+ return (
+ <span
+ data-slot="file-icon"
+ className={cn("text-muted-foreground shrink-0", className)}
+ {...props}
+ >
+ {children ?? <IconComponent className="size-5" />}
+ </span>
+ );
+}
+
+function FileName({
+ className,
+ children,
+ ...props
+}: React.ComponentProps<"span">) {
+ return (
+ <span
+ data-slot="file-name"
+ className={cn("min-w-0 flex-1 truncate font-medium", className)}
+ {...props}
+ >
+ {children || "Unnamed file"}
+ </span>
+ );
+}
+
+type FileSizeProps = React.ComponentProps<"span"> & {
+ bytes: number;
+};
+
+function FileSize({ bytes, className, ...props }: FileSizeProps) {
+ return (
+ <span
+ data-slot="file-size"
+ className={cn("text-muted-foreground shrink-0", className)}
+ {...props}
+ >
+ {formatFileSize(bytes)}
+ </span>
+ );
+}
+
+type FileDownloadProps = Omit<React.ComponentProps<"a">, "href"> & {
+ data: string;
+ mimeType: string;
+ filename?: string;
+ sourceType?: "url" | "id";
+};
+
+function FileDownload({
+ data,
+ mimeType,
+ filename,
+ sourceType,
+ className,
+ children,
+ ...props
+}: FileDownloadProps) {
+ if (typeof data !== "string") return null;
+ const kind = getFileDataKind(data, sourceType);
+ if (kind === "id") return null;
+ if (kind === "url" && !/^(https?:\/\/|blob:)/i.test(data)) return null;
+ const href = kind === "base64" ? `data:${mimeType};base64,${data}` : data;
+
+ return (
+ <a
+ data-slot="file-download"
+ href={href}
+ download={filename || "download"}
+ {...(kind === "url" && { target: "_blank", rel: "noopener noreferrer" })}
+ className={cn(
+ "text-muted-foreground hover:bg-accent hover:text-accent-foreground shrink-0 rounded-md p-1 transition-colors",
+ className,
+ )}
+ {...props}
+ >
+ {children || <DownloadIcon className="size-4" />}
+ </a>
+ );
+}
+
+const FileImpl: FileMessagePartComponent = ({
+ filename,
+ data,
+ mimeType,
+ sourceType,
+}) => {
+ const kind = getFileDataKind(data, sourceType);
+ const showSize =
+ typeof data === "string" && (kind === "base64" || kind === "data-uri");
+
+ return (
+ <FileRoot>
+ <FileIconDisplay mimeType={mimeType} />
+ <div className="flex min-w-0 flex-1 flex-col gap-0.5">
+ <FileName>{filename}</FileName>
+ {showSize && (
+ <FileSize bytes={getBase64Size(data)} className="text-xs" />
+ )}
+ </div>
+ <FileDownload
+ data={data}
+ mimeType={mimeType}
+ {...(filename !== undefined && { filename })}
+ {...(sourceType !== undefined && { sourceType })}
+ />
+ </FileRoot>
+ );
+};
+
+const File = memo(FileImpl) as unknown as FileMessagePartComponent & {
+ Root: typeof FileRoot;
+ Icon: typeof FileIconDisplay;
+ Name: typeof FileName;
+ Size: typeof FileSize;
+ Download: typeof FileDownload;
+};
+
+File.displayName = "File";
+File.Root = FileRoot;
+File.Icon = FileIconDisplay;
+File.Name = FileName;
+File.Size = FileSize;
+File.Download = FileDownload;
+
+export {
+ File,
+ FileRoot,
+ FileIconDisplay,
+ FileName,
+ FileSize,
+ FileDownload,
+ fileVariants,
+ getMimeTypeIcon,
+ getFileDataKind,
+ getBase64Size,
+ formatFileSize,
+};
diff --git a/app/src/components/assistant-ui/follow-up-suggestions.tsx b/app/src/components/assistant-ui/follow-up-suggestions.tsx
new file mode 100644
index 0000000000..77de2e4cfb
--- /dev/null
+++ b/app/src/components/assistant-ui/follow-up-suggestions.tsx
@@ -0,0 +1,83 @@
+"use client";
+
+import { AuiIf, useAuiState, ThreadPrimitive } from "@assistant-ui/react";
+import { useCallback, useEffect, useRef, useState, type FC } from "react";
+
+const FollowupSuggestionsRow: FC = () => {
+ const suggestions = useAuiState((s) => s.thread.suggestions);
+ const scrollRef = useRef<HTMLDivElement>(null);
+ const rtlRef = useRef<boolean | null>(null);
+ const [fades, setFades] = useState({ left: false, right: false });
+
+ const updateFades = useCallback(() => {
+ const el = scrollRef.current;
+ if (!el) return;
+ const maxScroll = el.scrollWidth - el.clientWidth;
+ // scrollLeft runs 0..-max in RTL; normalize to hidden width per physical edge.
+ const fromStart = Math.abs(el.scrollLeft);
+ // getComputedStyle forces a style recalc per scroll event; direction is stable, read it once.
+ const rtl = (rtlRef.current ??= getComputedStyle(el).direction === "rtl");
+ const [left, right] = rtl
+ ? [maxScroll - fromStart, fromStart]
+ : [fromStart, maxScroll - fromStart];
+ setFades((prev) => {
+ const next = { left: left > 1, right: right > 1 };
+ return prev.left === next.left && prev.right === next.right ? prev : next;
+ });
+ }, []);
+
+ useEffect(() => {
+ updateFades();
+ const el = scrollRef.current;
+ if (!el?.firstElementChild) return undefined;
+ const observer = new ResizeObserver(updateFades);
+ observer.observe(el);
+ observer.observe(el.firstElementChild);
+ return () => observer.disconnect();
+ }, [updateFades]);
+
+ const maskImage = `linear-gradient(to right, ${
+ fades.left ? "transparent, black 2rem" : "black"
+ }, ${fades.right ? "black calc(100% - 2rem), transparent" : "black"})`;
+
+ return (
+ <div
+ ref={scrollRef}
+ onScroll={updateFades}
+ // overflow-x clips both axes; py-1/-my-1 gives focus rings vertical room without changing outer height.
+ className="aui-thread-followup-suggestions -my-1 w-full overflow-x-auto py-1 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"
+ style={{ maskImage, WebkitMaskImage: maskImage }}
+ >
+ <div className="mx-auto flex min-h-8 w-max items-center gap-2 px-0.5">
+ {suggestions.map((suggestion, idx) => (
+ <ThreadPrimitive.Suggestion
+ key={idx}
+ className="aui-thread-followup-suggestion bg-background hover:bg-muted/80 rounded-full border px-3 py-1 text-sm whitespace-nowrap transition-colors ease-in"
+ prompt={suggestion.prompt}
+ method="replace"
+ autoSend
+ >
+ {suggestion.title ?? suggestion.prompt}
+ {suggestion.label && (
+ <span className="aui-thread-followup-suggestion-label text-muted-foreground ms-1">
+ {suggestion.label}
+ </span>
+ )}
+ </ThreadPrimitive.Suggestion>
+ ))}
+ </div>
+ </div>
+ );
+};
+
+export const ThreadFollowupSuggestions: FC = () => (
+ <AuiIf
+ condition={(s) =>
+ !s.thread.isEmpty &&
+ !s.thread.isRunning &&
+ s.thread.suggestions.length > 0
+ }
+ >
+ <FollowupSuggestionsRow />
+ </AuiIf>
+);
diff --git a/app/src/components/assistant-ui/image.tsx b/app/src/components/assistant-ui/image.tsx
new file mode 100644
index 0000000000..8fa219f28b
--- /dev/null
+++ b/app/src/components/assistant-ui/image.tsx
@@ -0,0 +1,492 @@
+"use client";
+
+import {
+ memo,
+ useState,
+ useEffect,
+ useRef,
+ type PropsWithChildren,
+} from "react";
+import { createPortal } from "react-dom";
+import { cva, type VariantProps } from "class-variance-authority";
+import {
+ CopyIcon,
+ DownloadIcon,
+ ImageIcon,
+ ImageOffIcon,
+ Loader2Icon,
+ RefreshCwIcon,
+ ShieldAlertIcon,
+} from "lucide-react";
+import type {
+ ImageMessagePart,
+ ImageMessagePartComponent,
+} from "@assistant-ui/react";
+import { cn } from "@/components/assistant-ui/lib/utils";
+
+const extensionForMimeType = (mimeType?: string): string => {
+ switch (mimeType) {
+ case "image/png":
+ return "png";
+ case "image/jpeg":
+ case "image/jpg":
+ return "jpg";
+ case "image/webp":
+ return "webp";
+ case "image/gif":
+ return "gif";
+ case "image/svg+xml":
+ return "svg";
+ default:
+ return "png";
+ }
+};
+
+const dataUriToBlob = (dataUri: string): Blob => {
+ const commaIndex = dataUri.indexOf(",");
+ const meta = commaIndex >= 0 ? dataUri.slice(0, commaIndex) : dataUri;
+ const data = commaIndex >= 0 ? dataUri.slice(commaIndex + 1) : "";
+ const mime =
+ meta.match(/data:([^;]+)/i)?.[1]?.toLowerCase() ??
+ "application/octet-stream";
+ if (!/;base64/i.test(meta)) {
+ const text = data.replace(/(?:%[0-9A-Fa-f]{2})+/g, (seq) => {
+ try {
+ return decodeURIComponent(seq);
+ } catch {
+ return seq;
+ }
+ });
+ return new Blob([text], { type: mime });
+ }
+ const bytes = atob(data);
+ const arr = new Uint8Array(bytes.length);
+ for (let i = 0; i < bytes.length; i++) arr[i] = bytes.charCodeAt(i);
+ return new Blob([arr], { type: mime });
+};
+
+const mimeFromImage = (image: string): string | undefined =>
+ image.match(/^data:([^;,]+)/i)?.[1]?.toLowerCase();
+
+const downloadImagePart = (
+ part: Pick<ImageMessagePart, "image" | "filename">,
+): void => {
+ if (typeof document === "undefined") return;
+ const ext = extensionForMimeType(mimeFromImage(part.image));
+ const filename = part.filename ?? `image.${ext}`;
+ const isDataUri = /^data:/i.test(part.image);
+ const objectUrl = isDataUri
+ ? URL.createObjectURL(dataUriToBlob(part.image))
+ : null;
+ const href = objectUrl ?? part.image;
+ const a = document.createElement("a");
+ a.href = href;
+ a.download = filename;
+ a.rel = "noopener";
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
+ if (objectUrl) setTimeout(() => URL.revokeObjectURL(objectUrl), 40_000);
+};
+
+const copyImagePart = async (
+ part: Pick<ImageMessagePart, "image">,
+): Promise<void> => {
+ if (
+ typeof navigator === "undefined" ||
+ !navigator.clipboard ||
+ typeof ClipboardItem === "undefined"
+ ) {
+ throw new Error("Clipboard API is not available in this environment.");
+ }
+ const blob = /^data:/i.test(part.image)
+ ? dataUriToBlob(part.image)
+ : await fetch(part.image).then((r) => r.blob());
+ const mime = mimeFromImage(part.image) ?? blob.type ?? "image/png";
+ await navigator.clipboard.write([new ClipboardItem({ [mime]: blob })]);
+};
+
+const imageVariants = cva(
+ "aui-image-root relative overflow-hidden rounded-lg",
+ {
+ variants: {
+ variant: {
+ outline: "border-border border",
+ ghost: "",
+ muted: "bg-muted/50",
+ },
+ size: {
+ sm: "max-w-64",
+ default: "max-w-96",
+ lg: "max-w-[512px]",
+ full: "w-full",
+ },
+ },
+ defaultVariants: {
+ variant: "outline",
+ size: "default",
+ },
+ },
+);
+
+export type ImageRootProps = React.ComponentProps<"div"> &
+ VariantProps<typeof imageVariants>;
+
+function ImageRoot({
+ className,
+ variant,
+ size,
+ children,
+ ...props
+}: ImageRootProps) {
+ return (
+ <div
+ data-slot="image-root"
+ data-variant={variant}
+ data-size={size}
+ className={cn(imageVariants({ variant, size, className }))}
+ {...props}
+ >
+ {children}
+ </div>
+ );
+}
+
+type ImagePreviewProps = Omit<React.ComponentProps<"img">, "children"> & {
+ containerClassName?: string;
+};
+
+function ImagePreview({
+ className,
+ containerClassName,
+ onLoad,
+ onError,
+ alt = "Image content",
+ src,
+ ...props
+}: ImagePreviewProps) {
+ const imgRef = useRef<HTMLImageElement>(null);
+ const [loadedSrc, setLoadedSrc] = useState<string | undefined>(undefined);
+ const [errorSrc, setErrorSrc] = useState<string | undefined>(undefined);
+
+ const loaded = loadedSrc === src;
+ const error = errorSrc === src;
+
+ useEffect(() => {
+ if (
+ typeof src === "string" &&
+ imgRef.current?.complete &&
+ imgRef.current.naturalWidth > 0
+ ) {
+ setLoadedSrc(src);
+ }
+ }, [src]);
+
+ return (
+ <div
+ data-slot="image-preview"
+ className={cn("relative min-h-32", containerClassName)}
+ >
+ {!loaded && !error && (
+ <div
+ data-slot="image-preview-loading"
+ className="bg-muted/50 absolute inset-0 flex items-center justify-center"
+ >
+ <ImageIcon className="text-muted-foreground size-8 animate-pulse" />
+ </div>
+ )}
+ {error ? (
+ <div
+ data-slot="image-preview-error"
+ className="bg-muted/50 flex min-h-32 items-center justify-center p-4"
+ >
+ <ImageOffIcon className="text-muted-foreground size-8" />
+ </div>
+ ) : (
+ <img
+ ref={imgRef}
+ src={src}
+ alt={alt}
+ className={cn(
+ "block h-auto w-full object-contain",
+ !loaded && "invisible",
+ className,
+ )}
+ onLoad={(e) => {
+ if (typeof src === "string") setLoadedSrc(src);
+ onLoad?.(e);
+ }}
+ onError={(e) => {
+ if (typeof src === "string") setErrorSrc(src);
+ onError?.(e);
+ }}
+ {...props}
+ />
+ )}
+ </div>
+ );
+}
+
+function ImageFilename({
+ className,
+ children,
+ ...props
+}: React.ComponentProps<"span">) {
+ if (!children) return null;
+
+ return (
+ <span
+ data-slot="image-filename"
+ className={cn(
+ "text-muted-foreground block truncate px-2 py-1.5 text-xs",
+ className,
+ )}
+ {...props}
+ >
+ {children}
+ </span>
+ );
+}
+
+type ImageZoomProps = PropsWithChildren<{
+ src: string;
+ alt?: string;
+}>;
+
+function ImageZoom({ src, alt = "Image preview", children }: ImageZoomProps) {
+ const [isMounted, setIsMounted] = useState(false);
+ const [isOpen, setIsOpen] = useState(false);
+
+ useEffect(() => {
+ setIsMounted(true);
+ }, []);
+
+ const handleOpen = () => setIsOpen(true);
+ const handleClose = () => setIsOpen(false);
+
+ useEffect(() => {
+ if (!isOpen) return;
+ const handleKeyDown = (e: KeyboardEvent) => {
+ if (e.key === "Escape") setIsOpen(false);
+ };
+ document.addEventListener("keydown", handleKeyDown);
+ return () => document.removeEventListener("keydown", handleKeyDown);
+ }, [isOpen]);
+
+ useEffect(() => {
+ if (!isOpen) return;
+ const originalOverflow = document.body.style.overflow;
+ document.body.style.overflow = "hidden";
+ return () => {
+ document.body.style.overflow = originalOverflow;
+ };
+ }, [isOpen]);
+
+ return (
+ <>
+ <div
+ onClick={handleOpen}
+ onKeyDown={(e) => e.key === "Enter" && handleOpen()}
+ role="button"
+ tabIndex={0}
+ className="aui-image-zoom-trigger cursor-zoom-in"
+ aria-label="Click to zoom image"
+ >
+ {children}
+ </div>
+ {isMounted &&
+ isOpen &&
+ createPortal(
+ <div
+ data-slot="image-zoom-overlay"
+ role="button"
+ tabIndex={0}
+ className="aui-image-zoom-overlay fade-in animate-in fixed inset-0 z-50 flex items-center justify-center bg-black/80 duration-200"
+ onClick={handleClose}
+ onKeyDown={(e) => e.key === "Enter" && handleClose()}
+ aria-label="Close zoomed image"
+ >
+ <img
+ data-slot="image-zoom-content"
+ src={src}
+ alt={alt}
+ className="aui-image-zoom-content fade-in zoom-in-95 animate-in max-h-[90vh] max-w-[90vw] cursor-zoom-out object-contain duration-200"
+ onClick={(e) => {
+ e.stopPropagation();
+ handleClose();
+ }}
+ />
+ </div>,
+ document.body,
+ )}
+ </>
+ );
+}
+
+function ImageGenerating({ className }: { className?: string }) {
+ return (
+ <div
+ data-slot="image-generating"
+ className={cn(
+ "bg-muted/50 flex min-h-32 items-center justify-center p-4",
+ className,
+ )}
+ >
+ <Loader2Icon className="text-muted-foreground size-8 animate-spin" />
+ <span className="sr-only">Generating image…</span>
+ </div>
+ );
+}
+
+function ImageContentFilterError({
+ className,
+ reason,
+}: {
+ className?: string;
+ reason?: string;
+}) {
+ return (
+ <div
+ data-slot="image-content-filter-error"
+ className={cn(
+ "bg-muted/50 flex min-h-32 flex-col items-center justify-center gap-2 p-4 text-center",
+ className,
+ )}
+ >
+ <ShieldAlertIcon className="text-muted-foreground size-8" />
+ <p className="text-sm font-medium">Image could not be generated</p>
+ {reason && <p className="text-muted-foreground text-xs">{reason}</p>}
+ </div>
+ );
+}
+
+export type ImageActionsProps = {
+ part: ImageMessagePart;
+ /**
+ * Wire to your own generation call to show a regenerate button. The button
+ * renders only when this is set and the part carries a `prompt`.
+ */
+ onRegenerate?: () => void | Promise<void>;
+ className?: string;
+};
+
+function RegenerateButton({
+ onRegenerate,
+}: {
+ onRegenerate: () => void | Promise<void>;
+}) {
+ const [isRegenerating, setIsRegenerating] = useState(false);
+ return (
+ <button
+ type="button"
+ onClick={async () => {
+ setIsRegenerating(true);
+ try {
+ await onRegenerate();
+ } finally {
+ setIsRegenerating(false);
+ }
+ }}
+ disabled={isRegenerating}
+ data-slot="image-regenerate"
+ aria-label="Regenerate image"
+ className="hover:bg-muted inline-flex size-7 items-center justify-center rounded disabled:opacity-50"
+ >
+ <RefreshCwIcon
+ className={cn("size-4", isRegenerating && "animate-spin")}
+ />
+ </button>
+ );
+}
+
+function ImageActions({ part, onRegenerate, className }: ImageActionsProps) {
+ return (
+ <div
+ data-slot="image-actions"
+ className={cn("flex items-center gap-1 p-1", className)}
+ >
+ <button
+ type="button"
+ onClick={() => downloadImagePart(part)}
+ data-slot="image-download"
+ aria-label="Download image"
+ className="hover:bg-muted inline-flex size-7 items-center justify-center rounded"
+ >
+ <DownloadIcon className="size-4" />
+ </button>
+ <button
+ type="button"
+ onClick={() => {
+ copyImagePart(part).catch(() => {});
+ }}
+ data-slot="image-copy"
+ aria-label="Copy image"
+ className="hover:bg-muted inline-flex size-7 items-center justify-center rounded"
+ >
+ <CopyIcon className="size-4" />
+ </button>
+ {onRegenerate && <RegenerateButton onRegenerate={onRegenerate} />}
+ </div>
+ );
+}
+
+const ImageImpl: ImageMessagePartComponent = (props) => {
+ const { image, filename, status } = props;
+
+ if (status?.type === "running") {
+ return (
+ <ImageRoot>
+ <ImageGenerating />
+ <ImageFilename>{filename}</ImageFilename>
+ </ImageRoot>
+ );
+ }
+
+ if (status?.type === "incomplete" && status.reason === "content-filter") {
+ return (
+ <ImageRoot>
+ <ImageContentFilterError reason="The provider blocked this image." />
+ </ImageRoot>
+ );
+ }
+
+ return (
+ <ImageRoot>
+ <ImageZoom src={image} alt={filename || "Image content"}>
+ <ImagePreview src={image} alt={filename || "Image content"} />
+ </ImageZoom>
+ <ImageFilename>{filename}</ImageFilename>
+ </ImageRoot>
+ );
+};
+
+const Image = memo(ImageImpl) as unknown as ImageMessagePartComponent & {
+ Root: typeof ImageRoot;
+ Preview: typeof ImagePreview;
+ Filename: typeof ImageFilename;
+ Zoom: typeof ImageZoom;
+ Actions: typeof ImageActions;
+ Generating: typeof ImageGenerating;
+ ContentFilterError: typeof ImageContentFilterError;
+};
+
+Image.displayName = "Image";
+Image.Root = ImageRoot;
+Image.Preview = ImagePreview;
+Image.Filename = ImageFilename;
+Image.Zoom = ImageZoom;
+Image.Actions = ImageActions;
+Image.Generating = ImageGenerating;
+Image.ContentFilterError = ImageContentFilterError;
+
+export {
+ Image,
+ ImageRoot,
+ ImagePreview,
+ ImageFilename,
+ ImageZoom,
+ ImageActions,
+ ImageGenerating,
+ ImageContentFilterError,
+ imageVariants,
+};
diff --git a/app/src/components/assistant-ui/markdown-text.tsx b/app/src/components/assistant-ui/markdown-text.tsx
new file mode 100644
index 0000000000..b1d610ef29
--- /dev/null
+++ b/app/src/components/assistant-ui/markdown-text.tsx
@@ -0,0 +1,259 @@
+"use client";
+
+import "@assistant-ui/react-markdown/styles/dot.css";
+
+import {
+ type CodeHeaderProps,
+ MarkdownTextPrimitive,
+ unstable_memoizeMarkdownComponents as memoizeMarkdownComponents,
+ useIsMarkdownCodeBlock,
+} from "@assistant-ui/react-markdown";
+import remarkGfm from "remark-gfm";
+import { type FC, memo, useState } from "react";
+import { CheckIcon, CopyIcon } from "lucide-react";
+
+import { TooltipIconButton } from "@/components/assistant-ui/tooltip-icon-button";
+import { cn } from "@/components/assistant-ui/lib/utils";
+
+const MarkdownTextImpl = () => {
+ return (
+ <MarkdownTextPrimitive
+ remarkPlugins={[remarkGfm]}
+ className="aui-md"
+ components={defaultComponents}
+ defer
+ />
+ );
+};
+
+export const MarkdownText = memo(MarkdownTextImpl);
+
+const CodeHeader: FC<CodeHeaderProps> = ({ language, code }) => {
+ const { isCopied, copyToClipboard } = useCopyToClipboard();
+ const onCopy = () => {
+ if (!code || isCopied) return;
+ copyToClipboard(code);
+ };
+
+ return (
+ <div className="aui-code-header-root border-border/50 bg-muted/50 mt-3 flex items-center justify-between rounded-t-xl border border-b-0 px-3.5 py-1.5 text-xs">
+ <span className="aui-code-header-language text-muted-foreground font-medium lowercase">
+ {language}
+ </span>
+ <TooltipIconButton tooltip="Copy" onClick={onCopy}>
+ {!isCopied && (
+ <CopyIcon className="animate-in zoom-in-75 fade-in duration-150" />
+ )}
+ {isCopied && (
+ <CheckIcon className="animate-in zoom-in-50 fade-in duration-200 ease-out" />
+ )}
+ </TooltipIconButton>
+ </div>
+ );
+};
+
+const useCopyToClipboard = ({
+ copiedDuration = 3000,
+}: {
+ copiedDuration?: number;
+} = {}) => {
+ const [isCopied, setIsCopied] = useState<boolean>(false);
+
+ const copyToClipboard = (value: string) => {
+ if (!value || typeof navigator === "undefined" || !navigator.clipboard) {
+ return;
+ }
+
+ navigator.clipboard.writeText(value).then(
+ () => {
+ setIsCopied(true);
+ setTimeout(() => setIsCopied(false), copiedDuration);
+ },
+ () => {},
+ );
+ };
+
+ return { isCopied, copyToClipboard };
+};
+
+const defaultComponents = memoizeMarkdownComponents({
+ h1: ({ className, ...props }) => (
+ <h1
+ className={cn(
+ "aui-md-h1 mt-5 mb-2 scroll-m-20 text-xl font-semibold first:mt-0 last:mb-0",
+ className,
+ )}
+ {...props}
+ />
+ ),
+ h2: ({ className, ...props }) => (
+ <h2
+ className={cn(
+ "aui-md-h2 mt-5 mb-2 scroll-m-20 text-lg font-semibold first:mt-0 last:mb-0",
+ className,
+ )}
+ {...props}
+ />
+ ),
+ h3: ({ className, ...props }) => (
+ <h3
+ className={cn(
+ "aui-md-h3 mt-4 mb-1.5 scroll-m-20 text-base font-semibold first:mt-0 last:mb-0",
+ className,
+ )}
+ {...props}
+ />
+ ),
+ h4: ({ className, ...props }) => (
+ <h4
+ className={cn(
+ "aui-md-h4 mt-3.5 mb-1 scroll-m-20 text-base font-medium first:mt-0 last:mb-0",
+ className,
+ )}
+ {...props}
+ />
+ ),
+ h5: ({ className, ...props }) => (
+ <h5
+ className={cn(
+ "aui-md-h5 mt-3 mb-1 text-sm font-semibold first:mt-0 last:mb-0",
+ className,
+ )}
+ {...props}
+ />
+ ),
+ h6: ({ className, ...props }) => (
+ <h6
+ className={cn(
+ "aui-md-h6 mt-3 mb-1 text-sm font-medium first:mt-0 last:mb-0",
+ className,
+ )}
+ {...props}
+ />
+ ),
+ p: ({ className, ...props }) => (
+ <p
+ className={cn(
+ "aui-md-p my-3 leading-relaxed first:mt-0 last:mb-0",
+ className,
+ )}
+ {...props}
+ />
+ ),
+ a: ({ className, ...props }) => (
+ <a
+ className={cn(
+ "aui-md-a text-primary hover:text-primary/80 underline underline-offset-2",
+ className,
+ )}
+ {...props}
+ />
+ ),
+ blockquote: ({ className, ...props }) => (
+ <blockquote
+ className={cn(
+ "aui-md-blockquote border-muted-foreground/30 text-muted-foreground my-3 border-s-2 ps-4",
+ className,
+ )}
+ {...props}
+ />
+ ),
+ ul: ({ className, ...props }) => (
+ <ul
+ className={cn(
+ "aui-md-ul marker:text-muted-foreground my-3 ms-5 list-disc [&>li]:mt-1",
+ className,
+ )}
+ {...props}
+ />
+ ),
+ ol: ({ className, ...props }) => (
+ <ol
+ className={cn(
+ "aui-md-ol marker:text-muted-foreground my-3 ms-5 list-decimal [&>li]:mt-1",
+ className,
+ )}
+ {...props}
+ />
+ ),
+ hr: ({ className, ...props }) => (
+ <hr
+ className={cn("aui-md-hr border-muted-foreground/20 my-3", className)}
+ {...props}
+ />
+ ),
+ table: ({ className, ...props }) => (
+ <table
+ className={cn(
+ "aui-md-table my-3 w-full border-separate border-spacing-0 overflow-y-auto",
+ className,
+ )}
+ {...props}
+ />
+ ),
+ th: ({ className, ...props }) => (
+ <th
+ className={cn(
+ "aui-md-th bg-muted px-3 py-1.5 text-start font-medium first:rounded-ss-lg last:rounded-se-lg [[align=center]]:text-center [[align=right]]:text-right",
+ className,
+ )}
+ {...props}
+ />
+ ),
+ td: ({ className, ...props }) => (
+ <td
+ className={cn(
+ "aui-md-td border-muted-foreground/20 border-s border-b px-3 py-1.5 text-start last:border-e [[align=center]]:text-center [[align=right]]:text-right",
+ className,
+ )}
+ {...props}
+ />
+ ),
+ tr: ({ className, ...props }) => (
+ <tr
+ className={cn(
+ "aui-md-tr m-0 border-b p-0 first:border-t [&:last-child>td:first-child]:rounded-es-lg [&:last-child>td:last-child]:rounded-ee-lg",
+ className,
+ )}
+ {...props}
+ />
+ ),
+ li: ({ className, ...props }) => (
+ <li className={cn("aui-md-li leading-relaxed", className)} {...props} />
+ ),
+ strong: ({ className, ...props }) => (
+ <strong
+ className={cn("aui-md-strong font-semibold", className)}
+ {...props}
+ />
+ ),
+ sup: ({ className, ...props }) => (
+ <sup
+ className={cn("aui-md-sup [&>a]:text-xs [&>a]:no-underline", className)}
+ {...props}
+ />
+ ),
+ pre: ({ className, ...props }) => (
+ <pre
+ className={cn(
+ "aui-md-pre border-border/50 bg-muted/30 overflow-x-auto rounded-t-none rounded-b-xl border border-t-0 p-3.5 text-[13px] leading-relaxed",
+ className,
+ )}
+ {...props}
+ />
+ ),
+ code: function Code({ className, ...props }) {
+ const isCodeBlock = useIsMarkdownCodeBlock();
+ return (
+ <code
+ className={cn(
+ !isCodeBlock &&
+ "aui-md-inline-code bg-muted rounded-md px-1.5 py-0.5 font-mono text-[0.85em]",
+ className,
+ )}
+ {...props}
+ />
+ );
+ },
+ CodeHeader,
+});
diff --git a/app/src/components/assistant-ui/reasoning.tsx b/app/src/components/assistant-ui/reasoning.tsx
new file mode 100644
index 0000000000..d468207d73
--- /dev/null
+++ b/app/src/components/assistant-ui/reasoning.tsx
@@ -0,0 +1,397 @@
+"use client";
+
+import {
+ createContext,
+ memo,
+ useCallback,
+ useContext,
+ useEffect,
+ useLayoutEffect,
+ useRef,
+ useState,
+} from "react";
+import { cva, type VariantProps } from "class-variance-authority";
+import { BrainIcon, ChevronDownIcon } from "lucide-react";
+import {
+ useScrollLock,
+ useAuiState,
+ type ReasoningMessagePartComponent,
+ type ReasoningGroupComponent,
+} from "@assistant-ui/react";
+import { MarkdownText } from "@/components/assistant-ui/markdown-text";
+import {
+ Collapsible,
+ CollapsibleContent,
+ CollapsibleTrigger,
+} from "@/components/assistant-ui/ui/collapsible";
+import { cn } from "@/components/assistant-ui/lib/utils";
+
+const ANIMATION_DURATION = 200;
+
+const ReasoningPreviewContext = createContext(false);
+
+const reasoningVariants = cva("aui-reasoning-root mb-4 w-full", {
+ variants: {
+ variant: {
+ outline: "rounded-lg border px-3 py-2",
+ ghost: "",
+ muted: "bg-muted/50 rounded-lg px-3 py-2",
+ },
+ },
+ defaultVariants: {
+ variant: "outline",
+ },
+});
+
+export type ReasoningRootProps = Omit<
+ React.ComponentProps<typeof Collapsible>,
+ "open" | "onOpenChange"
+> &
+ VariantProps<typeof reasoningVariants> & {
+ open?: boolean;
+ onOpenChange?: (open: boolean) => void;
+ defaultOpen?: boolean;
+ /**
+ * Whether the reasoning is currently streaming. While `true` the
+ * disclosure is held open with a bottom-pinned live preview; when
+ * streaming ends it returns to `defaultOpen`, and the first manual
+ * toggle takes over the open/close state permanently. The live preview
+ * keeps following the newest tokens while the disclosure is open during
+ * streaming, even after a manual toggle, and pauses while the reader is
+ * scrolled up.
+ */
+ streaming?: boolean;
+ };
+
+function ReasoningRoot({
+ className,
+ variant,
+ open: controlledOpen,
+ onOpenChange: controlledOnOpenChange,
+ defaultOpen = false,
+ streaming,
+ children,
+ ...props
+}: ReasoningRootProps) {
+ const collapsibleRef = useRef<HTMLDivElement>(null);
+ const initialOpenRef = useRef(defaultOpen);
+ const [userOpen, setUserOpen] = useState<boolean | null>(null);
+ const lockScroll = useScrollLock(collapsibleRef, ANIMATION_DURATION);
+
+ const isControlled = controlledOpen !== undefined;
+ const isOpen = isControlled
+ ? controlledOpen
+ : (userOpen ?? (streaming || initialOpenRef.current));
+ const isPreview = streaming === true && isOpen;
+
+ const prevStreamingRef = useRef(streaming);
+ useLayoutEffect(() => {
+ if (prevStreamingRef.current === streaming) return;
+ prevStreamingRef.current = streaming;
+ // A streaming transition only animates the panel when the resting state
+ // is collapsed; with `defaultOpen` the disclosure stays open across it.
+ if (!isControlled && userOpen === null && !initialOpenRef.current) {
+ lockScroll();
+ }
+ }, [streaming, isControlled, userOpen, lockScroll]);
+
+ const handleOpenChange = useCallback(
+ (open: boolean) => {
+ lockScroll();
+ if (!isControlled) {
+ setUserOpen(open);
+ }
+ controlledOnOpenChange?.(open);
+ },
+ [lockScroll, isControlled, controlledOnOpenChange],
+ );
+
+ return (
+ <Collapsible
+ ref={collapsibleRef}
+ data-slot="reasoning-root"
+ data-variant={variant}
+ open={isOpen}
+ onOpenChange={handleOpenChange}
+ className={cn(
+ "group/reasoning-root",
+ reasoningVariants({ variant, className }),
+ )}
+ style={
+ {
+ "--animation-duration": `${ANIMATION_DURATION}ms`,
+ } as React.CSSProperties
+ }
+ {...props}
+ >
+ <ReasoningPreviewContext.Provider value={isPreview}>
+ {children}
+ </ReasoningPreviewContext.Provider>
+ </Collapsible>
+ );
+}
+
+function ReasoningFade({
+ side = "bottom",
+ className,
+ ...props
+}: React.ComponentProps<"div"> & { side?: "top" | "bottom" }) {
+ if (side === "top") {
+ return (
+ <div
+ data-slot="reasoning-fade"
+ className={cn(
+ "aui-reasoning-fade pointer-events-none absolute inset-x-0 top-0 z-10 h-8",
+ "bg-[linear-gradient(to_bottom,var(--color-background),transparent)]",
+ "group-data-[variant=muted]/reasoning-root:bg-[linear-gradient(to_bottom,color-mix(in_oklab,var(--color-muted)_50%,var(--color-background)),transparent)]",
+ "fade-in-0 animate-in",
+ "animation-duration-(--animation-duration)",
+ className,
+ )}
+ {...props}
+ />
+ );
+ }
+
+ return (
+ <div
+ data-slot="reasoning-fade"
+ className={cn(
+ "aui-reasoning-fade pointer-events-none absolute inset-x-0 bottom-0 z-10 h-8",
+ "bg-[linear-gradient(to_top,var(--color-background),transparent)]",
+ "group-data-[variant=muted]/reasoning-root:bg-[linear-gradient(to_top,color-mix(in_oklab,var(--color-muted)_50%,var(--color-background)),transparent)]",
+ "fade-in-0 animate-in",
+ "animation-duration-(--animation-duration)",
+ className,
+ )}
+ {...props}
+ />
+ );
+}
+
+function ReasoningTrigger({
+ active,
+ duration,
+ className,
+ ...props
+}: React.ComponentProps<typeof CollapsibleTrigger> & {
+ active?: boolean;
+ duration?: number;
+}) {
+ const durationText = duration ? ` (${duration}s)` : "";
+
+ return (
+ <CollapsibleTrigger
+ data-slot="reasoning-trigger"
+ className={cn(
+ "aui-reasoning-trigger group/trigger text-muted-foreground hover:text-foreground flex max-w-[75%] origin-left items-center gap-2 py-1.5 text-sm transition-[color,scale] active:scale-[0.98]",
+ className,
+ )}
+ {...props}
+ >
+ <BrainIcon
+ data-slot="reasoning-trigger-icon"
+ className="aui-reasoning-trigger-icon size-4 shrink-0"
+ />
+ <span
+ data-slot="reasoning-trigger-label"
+ className="aui-reasoning-trigger-label-wrapper relative inline-block leading-none tabular-nums"
+ >
+ <span>Reasoning{durationText}</span>
+ {active ? (
+ <span
+ aria-hidden
+ data-slot="reasoning-trigger-shimmer"
+ className="aui-reasoning-trigger-shimmer shimmer pointer-events-none absolute inset-0 motion-reduce:animate-none"
+ >
+ Reasoning{durationText}
+ </span>
+ ) : null}
+ </span>
+ <ChevronDownIcon
+ data-slot="reasoning-trigger-chevron"
+ className={cn(
+ "aui-reasoning-trigger-chevron mt-0.5 size-4 shrink-0",
+ "transition-transform duration-(--animation-duration) ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:transition-none",
+ "-rotate-90",
+ "group-data-open/trigger:rotate-0",
+ "group-data-panel-open/trigger:rotate-0",
+ )}
+ />
+ </CollapsibleTrigger>
+ );
+}
+
+function ReasoningContent({
+ className,
+ children,
+ ...props
+}: React.ComponentProps<typeof CollapsibleContent>) {
+ const isPreview = useContext(ReasoningPreviewContext);
+
+ return (
+ <CollapsibleContent
+ data-slot="reasoning-content"
+ className={cn(
+ "aui-reasoning-content text-muted-foreground relative overflow-hidden text-sm outline-none",
+ "group/collapsible-content ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:animate-none",
+ "data-closed:animate-collapsible-up",
+ "data-open:animate-collapsible-down",
+ "data-closed:fill-mode-forwards",
+ "data-closed:pointer-events-none",
+ "[--tw-duration:var(--animation-duration)]",
+ className,
+ )}
+ {...props}
+ >
+ <ReasoningFade side="top" />
+ {children}
+ {isPreview ? <ReasoningFade /> : null}
+ </CollapsibleContent>
+ );
+}
+
+function ReasoningText({
+ className,
+ children,
+ ...props
+}: React.ComponentProps<"div">) {
+ const isPreview = useContext(ReasoningPreviewContext);
+ const scrollRef = useRef<HTMLDivElement>(null);
+ const contentRef = useRef<HTMLDivElement>(null);
+
+ useEffect(() => {
+ if (!isPreview) return;
+ const scrollEl = scrollRef.current;
+ const contentEl = contentRef.current;
+ if (!scrollEl || !contentEl) return;
+
+ let pinned = true;
+ let lastScrollTop = scrollEl.scrollTop;
+ let lastScrollHeight = scrollEl.scrollHeight;
+ const isAtBottom = () =>
+ Math.abs(
+ scrollEl.scrollHeight - scrollEl.scrollTop - scrollEl.clientHeight,
+ ) <= 1 || scrollEl.scrollHeight <= scrollEl.clientHeight;
+
+ const pin = () => {
+ if (!pinned) return;
+ scrollEl.scrollTop = scrollEl.scrollHeight;
+ };
+ // A pin's own scroll event can arrive after new content grew the scroll
+ // height and read as "not at bottom"; only an upward move at unchanged
+ // scroll height is user intent.
+ const onScroll = () => {
+ if (isAtBottom()) {
+ pinned = true;
+ } else if (
+ scrollEl.scrollTop < lastScrollTop &&
+ scrollEl.scrollHeight === lastScrollHeight
+ ) {
+ pinned = false;
+ }
+ lastScrollTop = scrollEl.scrollTop;
+ lastScrollHeight = scrollEl.scrollHeight;
+ };
+
+ pin();
+ scrollEl.addEventListener("scroll", onScroll);
+ const observer = new ResizeObserver(pin);
+ observer.observe(contentEl);
+ return () => {
+ scrollEl.removeEventListener("scroll", onScroll);
+ observer.disconnect();
+ };
+ }, [isPreview]);
+
+ return (
+ <div
+ ref={scrollRef}
+ data-slot="reasoning-text"
+ className={cn(
+ "aui-reasoning-text relative z-0 max-h-64 overflow-y-auto ps-6 pt-2 pb-2 leading-relaxed text-pretty",
+ "transform-gpu transition-[transform,opacity] ease-[cubic-bezier(0.32,0.72,0,1)]",
+ "motion-reduce:animate-none",
+ "group-data-open/collapsible-content:animate-in",
+ "group-data-closed/collapsible-content:animate-out",
+ "group-data-open/collapsible-content:fade-in-0",
+ "group-data-closed/collapsible-content:fade-out-0",
+ "group-data-open/collapsible-content:slide-in-from-top-4",
+ "group-data-closed/collapsible-content:slide-out-to-top-4",
+ "group-data-open/collapsible-content:blur-in-[2px]",
+ "group-data-closed/collapsible-content:blur-out-[2px]",
+ "group-data-open/collapsible-content:animation-duration-(--animation-duration)",
+ "group-data-closed/collapsible-content:animation-duration-(--animation-duration)",
+ className,
+ )}
+ {...props}
+ >
+ <div ref={contentRef} className="aui-reasoning-text-content space-y-4">
+ {children}
+ </div>
+ </div>
+ );
+}
+
+const ReasoningImpl: ReasoningMessagePartComponent = () => <MarkdownText />;
+
+const ReasoningGroupImpl: ReasoningGroupComponent = ({
+ children,
+ startIndex,
+ endIndex,
+}) => {
+ const isReasoningStreaming = useAuiState((s) => {
+ if (s.message.status?.type !== "running") return false;
+ for (let index = startIndex; index <= endIndex; index++) {
+ if (s.message.parts[index]?.status.type === "running") return true;
+ }
+ return false;
+ });
+
+ return (
+ <ReasoningRoot streaming={isReasoningStreaming}>
+ <ReasoningTrigger active={isReasoningStreaming} />
+ <ReasoningContent aria-busy={isReasoningStreaming}>
+ <ReasoningText>{children}</ReasoningText>
+ </ReasoningContent>
+ </ReasoningRoot>
+ );
+};
+
+const Reasoning = memo(
+ ReasoningImpl,
+) as unknown as ReasoningMessagePartComponent & {
+ Root: typeof ReasoningRoot;
+ Trigger: typeof ReasoningTrigger;
+ Content: typeof ReasoningContent;
+ Text: typeof ReasoningText;
+ Fade: typeof ReasoningFade;
+};
+
+Reasoning.displayName = "Reasoning";
+Reasoning.Root = ReasoningRoot;
+Reasoning.Trigger = ReasoningTrigger;
+Reasoning.Content = ReasoningContent;
+Reasoning.Text = ReasoningText;
+Reasoning.Fade = ReasoningFade;
+
+/**
+ * @deprecated This wrapper targets the legacy `components.ReasoningGroup`
+ * prop on `<MessagePrimitive.Parts>`. Use `<MessagePrimitive.GroupedParts>`
+ * with a `groupBy` returning `"group-reasoning"` and compose `ReasoningRoot`
+ * / `ReasoningTrigger` / `ReasoningContent` / `ReasoningText` directly.
+ * See `thread.tsx` for an example.
+ */
+const ReasoningGroup = memo(ReasoningGroupImpl);
+ReasoningGroup.displayName = "ReasoningGroup";
+
+export {
+ Reasoning,
+ ReasoningGroup,
+ ReasoningRoot,
+ ReasoningTrigger,
+ ReasoningContent,
+ ReasoningText,
+ ReasoningFade,
+ reasoningVariants,
+};
diff --git a/app/src/components/assistant-ui/thread.tsx b/app/src/components/assistant-ui/thread.tsx
new file mode 100644
index 0000000000..5ed871f22c
--- /dev/null
+++ b/app/src/components/assistant-ui/thread.tsx
@@ -0,0 +1,642 @@
+"use client";
+
+import {
+ ComposerAddAttachment,
+ ComposerAttachments,
+ UserMessageAttachments,
+} from "@/components/assistant-ui/attachment";
+import { File } from "@/components/assistant-ui/file";
+import { ThreadFollowupSuggestions } from "@/components/assistant-ui/follow-up-suggestions";
+import { Image } from "@/components/assistant-ui/image";
+import { MarkdownText } from "@/components/assistant-ui/markdown-text";
+import {
+ Reasoning,
+ ReasoningContent,
+ ReasoningRoot,
+ ReasoningText,
+ ReasoningTrigger,
+} from "@/components/assistant-ui/reasoning";
+import { ToolFallback } from "@/components/assistant-ui/tool-fallback";
+import {
+ ToolGroupContent,
+ ToolGroupRoot,
+ ToolGroupTrigger,
+} from "@/components/assistant-ui/tool-group";
+import { TooltipIconButton } from "@/components/assistant-ui/tooltip-icon-button";
+import { Button } from "@/components/assistant-ui/ui/button";
+import { Skeleton } from "@/components/assistant-ui/ui/skeleton";
+import { cn } from "@/components/assistant-ui/lib/utils";
+import {
+ ActionBarMorePrimitive,
+ ActionBarPrimitive,
+ AuiIf,
+ type AssistantState,
+ BranchPickerPrimitive,
+ ComposerPrimitive,
+ ErrorPrimitive,
+ groupPartByType,
+ MessagePrimitive,
+ SuggestionPrimitive,
+ ThreadPrimitive,
+ type FileMessagePartComponent,
+ type ImageMessagePartComponent,
+ type ToolCallMessagePartComponent,
+ useAuiState,
+} from "@assistant-ui/react";
+import {
+ ArrowDownIcon,
+ ArrowUpIcon,
+ CheckIcon,
+ ChevronLeftIcon,
+ ChevronRightIcon,
+ CopyIcon,
+ DownloadIcon,
+ MicIcon,
+ MoreHorizontalIcon,
+ PencilIcon,
+ RefreshCwIcon,
+ SquareIcon,
+} from "lucide-react";
+import {
+ createContext,
+ useContext,
+ type ComponentType,
+ type FC,
+ type PropsWithChildren,
+} from "react";
+
+export type ThreadGroupPart = MessagePrimitive.GroupedParts.GroupPart;
+
+/**
+ * Optional component overrides for the thread. `AssistantMessage` and
+ * `Welcome` replace whole sections; the remaining slots override how the
+ * assistant message renders tool calls and part groups. Tool UIs registered
+ * by name (toolkit `render`, `useAssistantDataUI`) take precedence over
+ * `ToolFallback`.
+ */
+export type ThreadComponents = {
+ AssistantMessage?: ComponentType | undefined;
+ Welcome?: ComponentType | undefined;
+ ToolFallback?: ToolCallMessagePartComponent | undefined;
+ ToolGroup?:
+ | ComponentType<PropsWithChildren<{ group: ThreadGroupPart }>>
+ | undefined;
+ ReasoningGroup?:
+ | ComponentType<PropsWithChildren<{ group: ThreadGroupPart }>>
+ | undefined;
+};
+
+export type ThreadProps = {
+ components?: ThreadComponents | undefined;
+};
+
+const EMPTY_COMPONENTS: ThreadComponents = {};
+
+const ThreadComponentsContext =
+ createContext<ThreadComponents>(EMPTY_COMPONENTS);
+
+// Startup exposes a loading placeholder thread; treat it as a new chat so
+// the composer mounts centered. Loads after startup keep the docked layout.
+const isNewChatView = (s: AssistantState) =>
+ s.thread.messages.length === 0 &&
+ (!s.thread.isLoading || s.threads.isLoading);
+
+// A switched thread that is still fetching its history: skeleton, not welcome.
+const isHistoryLoadingView = (s: AssistantState) =>
+ s.thread.messages.length === 0 &&
+ s.thread.isLoading &&
+ !s.thread.isDisabled &&
+ !s.threads.isLoading;
+
+const ThreadHistorySkeleton: FC = () => (
+ <div
+ data-slot="aui_thread-history-skeleton"
+ role="status"
+ className="animate-in fade-in fill-mode-both flex flex-col gap-y-6 [animation-delay:150ms] [animation-duration:200ms]"
+ >
+ <span className="sr-only">Loading conversation</span>
+ <Skeleton className="ml-auto h-9 w-2/5 rounded-xl motion-reduce:animate-none" />
+ <div className="flex flex-col gap-y-2">
+ <Skeleton className="h-4 w-11/12 motion-reduce:animate-none" />
+ <Skeleton className="h-4 w-4/5 motion-reduce:animate-none" />
+ <Skeleton className="h-4 w-3/5 motion-reduce:animate-none" />
+ </div>
+ <Skeleton className="ml-auto h-9 w-1/3 rounded-xl motion-reduce:animate-none" />
+ <div className="flex flex-col gap-y-2">
+ <Skeleton className="h-4 w-10/12 motion-reduce:animate-none" />
+ <Skeleton className="h-4 w-2/3 motion-reduce:animate-none" />
+ </div>
+ </div>
+);
+
+export const Thread: FC<ThreadProps> = ({ components = EMPTY_COMPONENTS }) => {
+ const isEmpty = useAuiState(isNewChatView);
+
+ return (
+ <ThreadComponentsContext.Provider value={components}>
+ <ThreadRoot isEmpty={isEmpty} />
+ </ThreadComponentsContext.Provider>
+ );
+};
+
+const ThreadRoot: FC<{ isEmpty: boolean }> = ({ isEmpty }) => {
+ const { Welcome = ThreadWelcome } = useContext(ThreadComponentsContext);
+
+ return (
+ <ThreadPrimitive.Root
+ className="aui-root aui-thread-root bg-background @container flex h-full flex-col"
+ style={{
+ ["--thread-max-width" as string]: "44rem",
+ ["--composer-bg" as string]: "var(--color-card)",
+ ["--composer-radius" as string]: "1.5rem",
+ ["--composer-padding" as string]: "8px",
+ }}
+ >
+ <ThreadPrimitive.Viewport
+ turnAnchor="top"
+ data-slot="aui_thread-viewport"
+ className="relative flex flex-1 flex-col overflow-x-auto overflow-y-scroll scroll-smooth"
+ >
+ <div
+ className={cn(
+ "mx-auto flex w-full max-w-(--thread-max-width) flex-1 flex-col px-4 pt-4",
+ isEmpty && "justify-center",
+ )}
+ >
+ <AuiIf condition={isNewChatView}>
+ <Welcome />
+ </AuiIf>
+ <AuiIf condition={isHistoryLoadingView}>
+ <ThreadHistorySkeleton />
+ </AuiIf>
+
+ <div
+ data-slot="aui_message-group"
+ className="mb-14 flex flex-col gap-y-6 empty:hidden"
+ >
+ <ThreadPrimitive.Messages>
+ {() => <ThreadMessage />}
+ </ThreadPrimitive.Messages>
+ </div>
+
+ <ThreadPrimitive.ViewportFooter
+ className={cn(
+ "aui-thread-viewport-footer bg-background flex flex-col gap-4 overflow-visible pb-4 md:pb-6",
+ !isEmpty &&
+ "sticky bottom-0 mt-auto rounded-t-(--composer-radius)",
+ )}
+ >
+ <ThreadScrollToBottom />
+ <ThreadFollowupSuggestions />
+ <Composer />
+ <AuiIf condition={(s) => isNewChatView(s) && s.composer.isEmpty}>
+ <ThreadSuggestions />
+ </AuiIf>
+ </ThreadPrimitive.ViewportFooter>
+ </div>
+ </ThreadPrimitive.Viewport>
+ </ThreadPrimitive.Root>
+ );
+};
+
+const ThreadMessage: FC = () => {
+ const { AssistantMessage: AssistantMessageComponent = AssistantMessage } =
+ useContext(ThreadComponentsContext);
+ const role = useAuiState((s) => s.message.role);
+ const isEditing = useAuiState((s) => s.message.composer.isEditing);
+
+ if (isEditing) return <EditComposer />;
+ if (role === "user") return <UserMessage />;
+ return <AssistantMessageComponent />;
+};
+
+const ThreadScrollToBottom: FC = () => {
+ return (
+ <ThreadPrimitive.ScrollToBottom asChild>
+ <TooltipIconButton
+ tooltip="Scroll to bottom"
+ variant="outline"
+ className="aui-thread-scroll-to-bottom dark:border-border dark:bg-background dark:hover:bg-accent absolute -top-12 z-10 self-center rounded-full p-4 disabled:invisible"
+ >
+ <ArrowDownIcon />
+ </TooltipIconButton>
+ </ThreadPrimitive.ScrollToBottom>
+ );
+};
+
+const ThreadWelcome: FC = () => {
+ return (
+ <div className="aui-thread-welcome-root mb-6 flex flex-col items-center px-4 text-center">
+ <h1 className="aui-thread-welcome-message-inner fade-in slide-in-from-bottom-1 animate-in fill-mode-both text-2xl font-medium tracking-tight duration-200">
+ How can I help you today?
+ </h1>
+ </div>
+ );
+};
+
+const ThreadSuggestions: FC = () => {
+ return (
+ <div className="aui-thread-welcome-suggestions flex w-full flex-wrap items-center justify-center gap-2 px-4">
+ <ThreadPrimitive.Suggestions>
+ {() => <ThreadSuggestionItem />}
+ </ThreadPrimitive.Suggestions>
+ </div>
+ );
+};
+
+const ThreadSuggestionItem: FC = () => {
+ return (
+ <div className="aui-thread-welcome-suggestion-display fade-in slide-in-from-bottom-2 animate-in fill-mode-both duration-200">
+ <SuggestionPrimitive.Trigger send asChild>
+ <Button
+ variant="ghost"
+ className="aui-thread-welcome-suggestion text-foreground hover:bg-muted border-border/60 h-auto gap-1.5 rounded-full border px-3.5 py-1.5 text-sm font-normal whitespace-nowrap transition-colors"
+ >
+ <SuggestionPrimitive.Title className="aui-thread-welcome-suggestion-text-1" />
+ <SuggestionPrimitive.Description className="aui-thread-welcome-suggestion-text-2 empty:hidden" />
+ </Button>
+ </SuggestionPrimitive.Trigger>
+ </div>
+ );
+};
+
+const Composer: FC = () => {
+ return (
+ <ComposerPrimitive.Root className="aui-composer-root relative flex w-full flex-col">
+ <ComposerPrimitive.AttachmentDropzone asChild>
+ <div
+ data-slot="aui_composer-shell"
+ className="border-border/60 data-[dragging=true]:border-ring focus-within:border-border dark:border-muted-foreground/15 dark:focus-within:border-muted-foreground/30 flex w-full cursor-text flex-col gap-2 rounded-(--composer-radius) border bg-(--composer-bg) p-(--composer-padding) transition-[border-color] data-[dragging=true]:border-dashed data-[dragging=true]:bg-[color-mix(in_oklab,var(--color-accent)_50%,var(--color-background))]"
+ >
+ <ComposerAttachments />
+ <ComposerPrimitive.Input
+ placeholder="Send a message..."
+ className="aui-composer-input caret-primary placeholder:text-muted-foreground/60 max-h-48 min-h-10 w-full resize-none bg-transparent px-2.5 py-1 text-base leading-6 outline-none"
+ rows={1}
+ autoFocus
+ enterKeyHint="send"
+ aria-label="Message input"
+ />
+ <ComposerAction />
+ </div>
+ </ComposerPrimitive.AttachmentDropzone>
+ </ComposerPrimitive.Root>
+ );
+};
+
+const ComposerAction: FC = () => {
+ return (
+ <div className="aui-composer-action-wrapper relative flex items-center justify-between">
+ <ComposerAddAttachment />
+ <div className="flex items-center gap-1.5">
+ <AuiIf condition={(s) => s.thread.capabilities.dictation}>
+ <AuiIf condition={(s) => s.composer.dictation == null}>
+ <ComposerPrimitive.Dictate asChild>
+ <TooltipIconButton
+ tooltip="Voice input"
+ side="bottom"
+ type="button"
+ variant="ghost"
+ size="icon"
+ className="aui-composer-dictate text-muted-foreground hover:text-foreground size-7 rounded-full"
+ aria-label="Start voice input"
+ >
+ <MicIcon className="aui-composer-dictate-icon size-4" />
+ </TooltipIconButton>
+ </ComposerPrimitive.Dictate>
+ </AuiIf>
+ <AuiIf condition={(s) => s.composer.dictation != null}>
+ <ComposerPrimitive.StopDictation asChild>
+ <TooltipIconButton
+ tooltip="Stop dictation"
+ side="bottom"
+ type="button"
+ variant="ghost"
+ size="icon"
+ className="aui-composer-stop-dictation text-destructive size-7 rounded-full"
+ aria-label="Stop voice input"
+ >
+ <SquareIcon className="aui-composer-stop-dictation-icon size-3.5 animate-pulse fill-current" />
+ </TooltipIconButton>
+ </ComposerPrimitive.StopDictation>
+ </AuiIf>
+ </AuiIf>
+ <AuiIf condition={(s) => !s.thread.isRunning}>
+ <ComposerPrimitive.Send asChild>
+ <TooltipIconButton
+ tooltip="Send message"
+ side="bottom"
+ type="button"
+ variant="default"
+ size="icon"
+ className="aui-composer-send size-7 rounded-full"
+ aria-label="Send message"
+ >
+ <ArrowUpIcon className="aui-composer-send-icon size-4" />
+ </TooltipIconButton>
+ </ComposerPrimitive.Send>
+ </AuiIf>
+ <AuiIf condition={(s) => s.thread.isRunning}>
+ <ComposerPrimitive.Cancel asChild>
+ <Button
+ type="button"
+ variant="default"
+ size="icon"
+ className="aui-composer-cancel size-7 rounded-full"
+ aria-label="Stop generating"
+ >
+ <SquareIcon className="aui-composer-cancel-icon size-3.5 fill-current" />
+ </Button>
+ </ComposerPrimitive.Cancel>
+ </AuiIf>
+ </div>
+ </div>
+ );
+};
+
+const MessageError: FC = () => {
+ return (
+ <MessagePrimitive.Error>
+ <ErrorPrimitive.Root className="aui-message-error-root border-destructive bg-destructive/10 text-destructive dark:bg-destructive/5 mt-2 rounded-md border p-3 text-sm dark:text-red-200">
+ <ErrorPrimitive.Message className="aui-message-error-message line-clamp-2" />
+ </ErrorPrimitive.Root>
+ </MessagePrimitive.Error>
+ );
+};
+
+const AssistantMessage: FC = () => {
+ const {
+ ToolFallback: ToolFallbackComponent = ToolFallback,
+ ToolGroup,
+ ReasoningGroup,
+ } = useContext(ThreadComponentsContext);
+
+ const ACTION_BAR_PT = "pt-1.5";
+ // Keep the action bar inside the contained root's paint box, then cancel its reserved space in flow.
+ const ACTION_BAR_HEIGHT = `min-h-7.5 ${ACTION_BAR_PT}`;
+
+ return (
+ <MessagePrimitive.Root
+ data-slot="aui_assistant-message-root"
+ data-role="assistant"
+ className="fade-in slide-in-from-bottom-1 animate-in relative -mb-7.5 pb-7.5 duration-150 [contain-intrinsic-size:auto_200px] [content-visibility:auto]"
+ >
+ <div
+ data-slot="aui_assistant-message-content"
+ className="text-foreground px-2 leading-relaxed wrap-break-word"
+ >
+ <MessagePrimitive.GroupedParts
+ groupBy={groupPartByType({
+ reasoning: ["group-chainOfThought", "group-reasoning"],
+ "tool-call": ["group-chainOfThought", "group-tool"],
+ "standalone-tool-call": [],
+ })}
+ >
+ {({ part, children }) => {
+ switch (part.type) {
+ case "group-chainOfThought":
+ return <div data-slot="aui_chain-of-thought">{children}</div>;
+ case "group-tool":
+ if (ToolGroup) {
+ return <ToolGroup group={part}>{children}</ToolGroup>;
+ }
+ return (
+ <ToolGroupRoot variant="ghost">
+ <ToolGroupTrigger
+ count={part.indices.length}
+ active={part.status.type === "running"}
+ />
+ <ToolGroupContent>{children}</ToolGroupContent>
+ </ToolGroupRoot>
+ );
+ case "group-reasoning": {
+ if (ReasoningGroup) {
+ return (
+ <ReasoningGroup group={part}>{children}</ReasoningGroup>
+ );
+ }
+ const running = part.status.type === "running";
+ return (
+ <ReasoningRoot streaming={running}>
+ <ReasoningTrigger active={running} />
+ <ReasoningContent aria-busy={running}>
+ <ReasoningText>{children}</ReasoningText>
+ </ReasoningContent>
+ </ReasoningRoot>
+ );
+ }
+ case "text":
+ return <MarkdownText />;
+ case "reasoning":
+ return <Reasoning {...part} />;
+ case "tool-call":
+ return part.toolUI ?? <ToolFallbackComponent {...part} />;
+ case "data":
+ return part.dataRendererUI;
+ case "file":
+ return (
+ <div data-slot="aui_assistant-message-file" className="py-1">
+ <File {...part} />
+ </div>
+ );
+ case "image":
+ return (
+ <div data-slot="aui_assistant-message-image" className="py-1">
+ <Image {...part} />
+ </div>
+ );
+ case "indicator":
+ return (
+ <span
+ data-slot="aui_assistant-message-indicator"
+ className="animate-pulse font-sans"
+ aria-label="Assistant is working"
+ >
+ {"●"}
+ </span>
+ );
+ default:
+ return null;
+ }
+ }}
+ </MessagePrimitive.GroupedParts>
+ <MessageError />
+ </div>
+
+ <div
+ data-slot="aui_assistant-message-footer"
+ className={cn("ms-2 flex items-center", ACTION_BAR_HEIGHT)}
+ >
+ <BranchPicker />
+ <AssistantActionBar />
+ </div>
+ </MessagePrimitive.Root>
+ );
+};
+
+const AssistantActionBar: FC = () => {
+ return (
+ <ActionBarPrimitive.Root
+ hideWhenRunning
+ autohide="not-last"
+ className="aui-assistant-action-bar-root text-muted-foreground animate-in fade-in col-start-3 row-start-2 -ms-1 flex gap-1 duration-200"
+ >
+ <ActionBarPrimitive.Copy asChild>
+ <TooltipIconButton tooltip="Copy">
+ <AuiIf condition={(s) => s.message.isCopied}>
+ <CheckIcon className="animate-in zoom-in-50 fade-in duration-200 ease-out" />
+ </AuiIf>
+ <AuiIf condition={(s) => !s.message.isCopied}>
+ <CopyIcon className="animate-in zoom-in-75 fade-in duration-150" />
+ </AuiIf>
+ </TooltipIconButton>
+ </ActionBarPrimitive.Copy>
+ <ActionBarPrimitive.Reload asChild>
+ <TooltipIconButton tooltip="Refresh">
+ <RefreshCwIcon />
+ </TooltipIconButton>
+ </ActionBarPrimitive.Reload>
+ <ActionBarMorePrimitive.Root>
+ <ActionBarMorePrimitive.Trigger asChild>
+ <TooltipIconButton
+ tooltip="More"
+ className="data-[state=open]:bg-accent"
+ >
+ <MoreHorizontalIcon />
+ </TooltipIconButton>
+ </ActionBarMorePrimitive.Trigger>
+ <ActionBarMorePrimitive.Content
+ side="bottom"
+ align="start"
+ sideOffset={6}
+ className="aui-action-bar-more-content bg-popover text-popover-foreground data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=open]:animate-in data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=closed]:animate-out data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-xl border p-1.5"
+ >
+ <ActionBarPrimitive.ExportMarkdown asChild>
+ <ActionBarMorePrimitive.Item className="aui-action-bar-more-item hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground flex cursor-pointer items-center gap-2 rounded-lg px-2.5 py-1.5 text-sm outline-none select-none">
+ <DownloadIcon className="size-4" />
+ Export as Markdown
+ </ActionBarMorePrimitive.Item>
+ </ActionBarPrimitive.ExportMarkdown>
+ </ActionBarMorePrimitive.Content>
+ </ActionBarMorePrimitive.Root>
+ </ActionBarPrimitive.Root>
+ );
+};
+
+const UserFilePart: FileMessagePartComponent = (part) => (
+ <div data-slot="aui_user-message-file" className="py-1">
+ <File {...part} />
+ </div>
+);
+
+const UserImagePart: ImageMessagePartComponent = (part) => (
+ <div data-slot="aui_user-message-image" className="py-1">
+ <Image {...part} />
+ </div>
+);
+
+const UserMessage: FC = () => {
+ return (
+ <MessagePrimitive.Root
+ data-slot="aui_user-message-root"
+ className="fade-in slide-in-from-bottom-1 animate-in grid auto-rows-auto grid-cols-[minmax(72px,1fr)_auto] content-start gap-y-2 px-2 duration-150 [contain-intrinsic-size:auto_200px] [content-visibility:auto] [&:where(>*)]:col-start-2"
+ data-role="user"
+ >
+ <UserMessageAttachments />
+
+ <div className="aui-user-message-content-wrapper relative col-start-2 min-w-0">
+ <div className="aui-user-message-content peer bg-muted text-foreground rounded-xl px-4 py-2 wrap-break-word empty:hidden">
+ <MessagePrimitive.Parts
+ components={{ File: UserFilePart, Image: UserImagePart }}
+ />
+ </div>
+ <div className="aui-user-action-bar-wrapper absolute start-0 top-1/2 -translate-x-full -translate-y-1/2 pe-2 peer-empty:hidden rtl:translate-x-full">
+ <UserActionBar />
+ </div>
+ </div>
+
+ <BranchPicker
+ data-slot="aui_user-branch-picker"
+ className="col-span-full col-start-1 row-start-3 -me-1 justify-end"
+ />
+ </MessagePrimitive.Root>
+ );
+};
+
+const UserActionBar: FC = () => {
+ return (
+ <ActionBarPrimitive.Root
+ hideWhenRunning
+ autohide="not-last"
+ className="aui-user-action-bar-root flex flex-col items-end"
+ >
+ <ActionBarPrimitive.Edit asChild>
+ <TooltipIconButton tooltip="Edit" className="aui-user-action-edit">
+ <PencilIcon />
+ </TooltipIconButton>
+ </ActionBarPrimitive.Edit>
+ </ActionBarPrimitive.Root>
+ );
+};
+
+const EditComposer: FC = () => {
+ return (
+ <MessagePrimitive.Root
+ data-slot="aui_edit-composer-wrapper"
+ className="flex flex-col px-2 [contain-intrinsic-size:auto_200px] [content-visibility:auto]"
+ >
+ <ComposerPrimitive.Root className="aui-edit-composer-root border-border/60 dark:border-muted-foreground/15 ms-auto flex w-full max-w-[85%] cursor-text flex-col rounded-(--composer-radius) border bg-(--composer-bg)">
+ <ComposerPrimitive.Input
+ className="aui-edit-composer-input text-foreground min-h-14 w-full resize-none bg-transparent px-4 pt-3 pb-1 text-base outline-none"
+ autoFocus
+ />
+ <div className="aui-edit-composer-footer mx-2.5 mb-2.5 flex items-center gap-1.5 self-end">
+ <ComposerPrimitive.Cancel asChild>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-8 rounded-full px-3.5"
+ >
+ Cancel
+ </Button>
+ </ComposerPrimitive.Cancel>
+ <ComposerPrimitive.Send asChild>
+ <Button size="sm" className="h-8 rounded-full px-3.5">
+ Update
+ </Button>
+ </ComposerPrimitive.Send>
+ </div>
+ </ComposerPrimitive.Root>
+ </MessagePrimitive.Root>
+ );
+};
+
+const BranchPicker: FC<BranchPickerPrimitive.Root.Props> = ({
+ className,
+ ...rest
+}) => {
+ return (
+ <BranchPickerPrimitive.Root
+ hideWhenSingleBranch
+ className={cn(
+ "aui-branch-picker-root text-muted-foreground -ms-2 me-2 inline-flex items-center text-xs",
+ className,
+ )}
+ {...rest}
+ >
+ <BranchPickerPrimitive.Previous asChild>
+ <TooltipIconButton tooltip="Previous">
+ <ChevronLeftIcon />
+ </TooltipIconButton>
+ </BranchPickerPrimitive.Previous>
+ <span className="aui-branch-picker-state font-medium">
+ <BranchPickerPrimitive.Number /> / <BranchPickerPrimitive.Count />
+ </span>
+ <BranchPickerPrimitive.Next asChild>
+ <TooltipIconButton tooltip="Next">
+ <ChevronRightIcon />
+ </TooltipIconButton>
+ </BranchPickerPrimitive.Next>
+ </BranchPickerPrimitive.Root>
+ );
+};
diff --git a/app/src/components/assistant-ui/tool-fallback.tsx b/app/src/components/assistant-ui/tool-fallback.tsx
new file mode 100644
index 0000000000..28cd627f40
--- /dev/null
+++ b/app/src/components/assistant-ui/tool-fallback.tsx
@@ -0,0 +1,629 @@
+"use client";
+
+import { memo, useCallback, useRef, useState } from "react";
+import {
+ AlertCircleIcon,
+ CheckIcon,
+ ChevronDownIcon,
+ LoaderIcon,
+ XCircleIcon,
+} from "lucide-react";
+import {
+ useScrollLock,
+ useToolCallElapsed,
+ type ToolApprovalOption,
+ type ToolCallMessagePart,
+ type ToolCallMessagePartProps,
+ type ToolCallMessagePartStatus,
+ type ToolCallMessagePartComponent,
+} from "@assistant-ui/react";
+import {
+ Collapsible,
+ CollapsibleContent,
+ CollapsibleTrigger,
+} from "@/components/assistant-ui/ui/collapsible";
+import { cn } from "@/components/assistant-ui/lib/utils";
+import { Button } from "@/components/assistant-ui/ui/button";
+
+const ANIMATION_DURATION = 200;
+
+const pressable = "active:scale-[0.98]";
+
+export type ToolFallbackRootProps = Omit<
+ React.ComponentProps<typeof Collapsible>,
+ "open" | "onOpenChange"
+> & {
+ open?: boolean;
+ onOpenChange?: (open: boolean) => void;
+ defaultOpen?: boolean;
+};
+
+function ToolFallbackRoot({
+ className,
+ open: controlledOpen,
+ onOpenChange: controlledOnOpenChange,
+ defaultOpen = false,
+ children,
+ ...props
+}: ToolFallbackRootProps) {
+ const collapsibleRef = useRef<HTMLDivElement>(null);
+ const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);
+ const lockScroll = useScrollLock(collapsibleRef, ANIMATION_DURATION);
+
+ const isControlled = controlledOpen !== undefined;
+ const isOpen = isControlled ? controlledOpen : uncontrolledOpen;
+
+ const handleOpenChange = useCallback(
+ (open: boolean) => {
+ lockScroll();
+ if (!isControlled) {
+ setUncontrolledOpen(open);
+ }
+ controlledOnOpenChange?.(open);
+ },
+ [lockScroll, isControlled, controlledOnOpenChange],
+ );
+
+ return (
+ <Collapsible
+ ref={collapsibleRef}
+ data-slot="tool-fallback-root"
+ open={isOpen}
+ onOpenChange={handleOpenChange}
+ className={cn(
+ "aui-tool-fallback-root group/tool-fallback-root w-full",
+ className,
+ )}
+ style={
+ {
+ "--animation-duration": `${ANIMATION_DURATION}ms`,
+ } as React.CSSProperties
+ }
+ {...props}
+ >
+ {children}
+ </Collapsible>
+ );
+}
+
+type ToolStatus = ToolCallMessagePartStatus["type"];
+
+const statusIconMap: Record<ToolStatus, React.ElementType> = {
+ running: LoaderIcon,
+ complete: CheckIcon,
+ incomplete: XCircleIcon,
+ "requires-action": AlertCircleIcon,
+};
+
+const formatToolDuration = (ms: number) => {
+ if (ms < 1000) return "<1s";
+ const seconds = ms / 1000;
+ if (seconds < 10) return `${(Math.floor(seconds * 10) / 10).toFixed(1)}s`;
+ if (seconds < 60) return `${Math.floor(seconds)}s`;
+ return `${Math.floor(seconds / 60)}m ${Math.floor(seconds % 60)}s`;
+};
+
+function ToolFallbackDuration({
+ className,
+ ...props
+}: React.ComponentProps<"span">) {
+ const elapsedMs = useToolCallElapsed();
+ if (elapsedMs === undefined) return null;
+
+ return (
+ <span
+ data-slot="tool-fallback-duration"
+ className={cn(
+ "aui-tool-fallback-duration text-muted-foreground text-xs tabular-nums",
+ className,
+ )}
+ {...props}
+ >
+ {formatToolDuration(elapsedMs)}
+ </span>
+ );
+}
+
+function ToolFallbackTrigger({
+ toolName,
+ status,
+ className,
+ ...props
+}: React.ComponentProps<typeof CollapsibleTrigger> & {
+ toolName: string;
+ status?: ToolCallMessagePartStatus;
+}) {
+ const statusType = status?.type ?? "complete";
+ const isRunning = statusType === "running";
+ const isCancelled =
+ status?.type === "incomplete" && status.reason === "cancelled";
+
+ const Icon = statusIconMap[statusType];
+ const label = isCancelled ? "Cancelled tool" : "Used tool";
+
+ return (
+ <CollapsibleTrigger
+ data-slot="tool-fallback-trigger"
+ className={cn(
+ "aui-tool-fallback-trigger group/trigger text-muted-foreground hover:text-foreground flex w-fit origin-left items-center gap-2 py-1.5 text-sm transition-[color,scale] active:scale-[0.98]",
+ className,
+ )}
+ {...props}
+ >
+ <Icon
+ data-slot="tool-fallback-trigger-icon"
+ className={cn(
+ "aui-tool-fallback-trigger-icon size-4 shrink-0",
+ isCancelled && "text-muted-foreground",
+ isRunning && "animate-spin [animation-duration:0.6s]",
+ )}
+ />
+ <span
+ data-slot="tool-fallback-trigger-label"
+ className={cn(
+ "aui-tool-fallback-trigger-label-wrapper relative inline-block text-start leading-none",
+ isCancelled && "text-muted-foreground line-through",
+ )}
+ >
+ <span>
+ {label}: <b>{toolName}</b>
+ </span>
+ {isRunning && (
+ <span
+ aria-hidden
+ data-slot="tool-fallback-trigger-shimmer"
+ className="aui-tool-fallback-trigger-shimmer shimmer pointer-events-none absolute inset-0 motion-reduce:animate-none"
+ >
+ {label}: <b>{toolName}</b>
+ </span>
+ )}
+ </span>
+ <ToolFallbackDuration />
+ <ChevronDownIcon
+ data-slot="tool-fallback-trigger-chevron"
+ className={cn(
+ "aui-tool-fallback-trigger-chevron size-4 shrink-0",
+ "transition-transform duration-(--animation-duration) ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:transition-none",
+ "-rotate-90",
+ "group-data-open/trigger:rotate-0",
+ "group-data-panel-open/trigger:rotate-0",
+ )}
+ />
+ </CollapsibleTrigger>
+ );
+}
+
+function ToolFallbackContent({
+ className,
+ children,
+ ...props
+}: React.ComponentProps<typeof CollapsibleContent>) {
+ return (
+ <CollapsibleContent
+ data-slot="tool-fallback-content"
+ className={cn(
+ "aui-tool-fallback-content relative overflow-hidden text-sm outline-none",
+ "group/collapsible-content ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:animate-none",
+ "data-closed:animate-collapsible-up",
+ "data-open:animate-collapsible-down",
+ "data-closed:fill-mode-forwards",
+ "data-closed:pointer-events-none",
+ "[--tw-duration:var(--animation-duration)]",
+ className,
+ )}
+ {...props}
+ >
+ <div
+ className={cn(
+ "flex flex-col gap-2 ps-6 pt-1 pb-2 ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:animate-none",
+ "group-data-open/collapsible-content:animate-in group-data-open/collapsible-content:fade-in-0 group-data-open/collapsible-content:blur-in-[2px] group-data-open/collapsible-content:slide-in-from-top-1",
+ "group-data-closed/collapsible-content:animate-out group-data-closed/collapsible-content:fade-out-0 group-data-closed/collapsible-content:blur-out-[2px] group-data-closed/collapsible-content:slide-out-to-top-1",
+ "group-data-closed/collapsible-content:animation-duration-(--animation-duration) group-data-open/collapsible-content:animation-duration-(--animation-duration)",
+ )}
+ >
+ {children}
+ </div>
+ </CollapsibleContent>
+ );
+}
+
+function ToolFallbackArgs({
+ argsText,
+ className,
+ ...props
+}: React.ComponentProps<"div"> & {
+ argsText?: string;
+}) {
+ if (!argsText) return null;
+
+ return (
+ <div
+ data-slot="tool-fallback-args"
+ className={cn("aui-tool-fallback-args", className)}
+ {...props}
+ >
+ <pre className="aui-tool-fallback-args-value bg-muted/50 text-foreground/90 rounded-md p-2.5 text-xs whitespace-pre-wrap">
+ {argsText}
+ </pre>
+ </div>
+ );
+}
+
+function ToolFallbackResult({
+ result,
+ className,
+ ...props
+}: React.ComponentProps<"div"> & {
+ result?: unknown;
+}) {
+ if (result === undefined) return null;
+
+ return (
+ <div
+ data-slot="tool-fallback-result"
+ className={cn("aui-tool-fallback-result", className)}
+ {...props}
+ >
+ <p className="aui-tool-fallback-result-header text-muted-foreground text-xs font-medium">
+ Result:
+ </p>
+ <pre className="aui-tool-fallback-result-content bg-muted/50 text-foreground/90 mt-1 rounded-md p-2.5 text-xs whitespace-pre-wrap">
+ {typeof result === "string" ? result : JSON.stringify(result, null, 2)}
+ </pre>
+ </div>
+ );
+}
+
+function ToolFallbackError({
+ status,
+ className,
+ ...props
+}: React.ComponentProps<"div"> & {
+ status?: ToolCallMessagePartStatus;
+}) {
+ if (status?.type !== "incomplete") return null;
+
+ const error = status.error;
+ const errorText = error
+ ? typeof error === "string"
+ ? error
+ : JSON.stringify(error)
+ : null;
+
+ if (!errorText) return null;
+
+ const isCancelled = status.reason === "cancelled";
+ const headerText = isCancelled ? "Cancelled reason:" : "Error:";
+
+ return (
+ <div
+ data-slot="tool-fallback-error"
+ className={cn("aui-tool-fallback-error", className)}
+ {...props}
+ >
+ <p className="aui-tool-fallback-error-header text-muted-foreground font-semibold">
+ {headerText}
+ </p>
+ <p className="aui-tool-fallback-error-reason text-muted-foreground">
+ {errorText}
+ </p>
+ </div>
+ );
+}
+
+const APPROVED_RESULT = "Approved by user";
+const DENIED_RESULT = "User denied tool execution";
+
+const APPROVAL_OPTION_DEFAULT_LABELS: Record<string, string> = {
+ "allow-once": "Allow",
+ "allow-always": "Always allow",
+ "reject-once": "Deny",
+ "reject-always": "Always deny",
+};
+
+const isAllowKind = (kind: string) =>
+ kind === "allow-once" || kind === "allow-always";
+
+const approvalOptionLabel = (option: ToolApprovalOption) =>
+ option.label ??
+ (Object.hasOwn(APPROVAL_OPTION_DEFAULT_LABELS, option.kind)
+ ? APPROVAL_OPTION_DEFAULT_LABELS[option.kind]
+ : undefined) ??
+ option.id;
+
+const offersInterruptAction = (
+ status: ToolCallMessagePartStatus | undefined,
+ approval: ToolCallMessagePart["approval"],
+ interrupt: ToolCallMessagePart["interrupt"],
+) =>
+ status?.type !== "requires-action" ||
+ status.reason !== "interrupt" ||
+ approval != null ||
+ interrupt != null;
+
+function ToolFallbackApproval({
+ className,
+ addResult,
+ resume,
+ interrupt,
+ approval,
+ respondToApproval,
+ status,
+ ...props
+}: React.ComponentProps<"div"> &
+ Partial<
+ Pick<
+ ToolCallMessagePartProps,
+ "addResult" | "resume" | "respondToApproval" | "status"
+ >
+ > & {
+ interrupt?: ToolCallMessagePart["interrupt"];
+ approval?: ToolCallMessagePart["approval"];
+ }) {
+ const [submitted, setSubmitted] = useState(false);
+ const [confirmingId, setConfirmingId] = useState<string | null>(null);
+
+ if (
+ approval != null &&
+ (approval.approved !== undefined || approval.resolution !== undefined)
+ )
+ return null;
+
+ if (!offersInterruptAction(status, approval, interrupt)) return null;
+
+ // Custom (`_`-prefixed) kinds cannot be resolved to a boolean by the kit;
+ // hosts using custom kinds render their own bar. A declared option list is
+ // a host constraint: the kit never adds an approval path beyond it, but
+ // always preserves a refusal path.
+ const declaredOptions = respondToApproval ? approval?.options : undefined;
+ const options = declaredOptions?.filter((o) =>
+ Object.hasOwn(APPROVAL_OPTION_DEFAULT_LABELS, o.kind),
+ );
+
+ const respond = (approved: boolean) => {
+ if (submitted) return;
+ if (
+ approval != null &&
+ approval.approved === undefined &&
+ respondToApproval
+ ) {
+ respondToApproval({ approved });
+ } else if (interrupt) {
+ resume?.({ approved });
+ } else if (
+ status?.type === "requires-action" &&
+ status.reason === "interrupt"
+ ) {
+ return;
+ } else {
+ addResult?.(approved ? APPROVED_RESULT : DENIED_RESULT);
+ }
+ setSubmitted(true);
+ };
+
+ const respondWithOption = (option: ToolApprovalOption) => {
+ if (submitted) return;
+ respondToApproval?.({ optionId: option.id });
+ setSubmitted(true);
+ setConfirmingId(null);
+ };
+
+ const handleOption = (option: ToolApprovalOption) => {
+ if (option.confirm) {
+ setConfirmingId(option.id);
+ } else {
+ respondWithOption(option);
+ }
+ };
+
+ const confirming =
+ confirmingId != null
+ ? options?.find((o) => o.id === confirmingId)
+ : undefined;
+
+ if (confirming) {
+ const confirmMeta =
+ typeof confirming.confirm === "object" ? confirming.confirm : undefined;
+ const confirmDescription =
+ confirmMeta?.description ?? confirming.description;
+ return (
+ <div
+ data-slot="tool-fallback-approval-confirm"
+ className={cn(
+ "aui-tool-fallback-approval-confirm flex flex-col gap-2 pt-1",
+ className,
+ )}
+ {...props}
+ >
+ <p className="aui-tool-fallback-approval-confirm-title font-semibold">
+ {confirmMeta?.title ?? `${approvalOptionLabel(confirming)}?`}
+ </p>
+ {confirmDescription && (
+ <p className="aui-tool-fallback-approval-confirm-description text-muted-foreground">
+ {confirmDescription}
+ </p>
+ )}
+ {confirming.grants && confirming.grants.length > 0 && (
+ <ul className="aui-tool-fallback-approval-confirm-grants flex flex-col gap-1">
+ {confirming.grants.map((grant) => (
+ <li key={grant}>
+ <code className="aui-tool-fallback-approval-confirm-grant bg-muted rounded px-1.5 py-0.5 text-xs">
+ {grant}
+ </code>
+ </li>
+ ))}
+ </ul>
+ )}
+ <div className="flex items-center gap-2">
+ <Button
+ size="sm"
+ className={pressable}
+ onClick={() => respondWithOption(confirming)}
+ disabled={submitted}
+ >
+ Confirm
+ </Button>
+ <Button
+ size="sm"
+ variant="outline"
+ className={pressable}
+ onClick={() => setConfirmingId(null)}
+ disabled={submitted}
+ >
+ Back
+ </Button>
+ </div>
+ </div>
+ );
+ }
+
+ if (declaredOptions && declaredOptions.length > 0) {
+ const allowOptions = options?.filter((o) => isAllowKind(o.kind)) ?? [];
+ const rejectOptions = options?.filter((o) => !isAllowKind(o.kind)) ?? [];
+ return (
+ <div
+ data-slot="tool-fallback-approval"
+ className={cn(
+ "aui-tool-fallback-approval flex flex-wrap items-center gap-2 pt-1",
+ className,
+ )}
+ {...props}
+ >
+ {[...allowOptions, ...rejectOptions].map((option) => (
+ <Button
+ key={option.id}
+ size="sm"
+ variant={option === allowOptions[0] ? "default" : "outline"}
+ className={pressable}
+ onClick={() => handleOption(option)}
+ disabled={submitted}
+ >
+ {approvalOptionLabel(option)}
+ </Button>
+ ))}
+ {rejectOptions.length === 0 && (
+ <Button
+ size="sm"
+ variant="outline"
+ className={pressable}
+ onClick={() => respond(false)}
+ disabled={submitted}
+ >
+ Deny
+ </Button>
+ )}
+ </div>
+ );
+ }
+
+ return (
+ <div
+ data-slot="tool-fallback-approval"
+ className={cn(
+ "aui-tool-fallback-approval flex items-center gap-2 pt-1",
+ className,
+ )}
+ {...props}
+ >
+ <Button
+ size="sm"
+ className={pressable}
+ onClick={() => respond(true)}
+ disabled={submitted}
+ >
+ Allow
+ </Button>
+ <Button
+ size="sm"
+ variant="outline"
+ className={pressable}
+ onClick={() => respond(false)}
+ disabled={submitted}
+ >
+ Deny
+ </Button>
+ </div>
+ );
+}
+
+const ToolFallbackImpl: ToolCallMessagePartComponent = ({
+ toolName,
+ argsText,
+ result,
+ status,
+ addResult,
+ resume,
+ interrupt,
+ approval,
+ respondToApproval,
+}) => {
+ const isCancelled =
+ status?.type === "incomplete" && status.reason === "cancelled";
+ const isRequiresAction = status?.type === "requires-action";
+ const shouldRenderApproval =
+ isRequiresAction && offersInterruptAction(status, approval, interrupt);
+
+ const [open, setOpen] = useState(isRequiresAction);
+ const [prevRequiresAction, setPrevRequiresAction] =
+ useState(isRequiresAction);
+ if (isRequiresAction !== prevRequiresAction) {
+ setPrevRequiresAction(isRequiresAction);
+ if (isRequiresAction) setOpen(true);
+ }
+
+ return (
+ <ToolFallbackRoot open={open} onOpenChange={setOpen}>
+ <ToolFallbackTrigger toolName={toolName} status={status} />
+ <ToolFallbackContent>
+ <ToolFallbackError status={status} />
+ <ToolFallbackArgs
+ argsText={argsText}
+ className={cn(isCancelled && "opacity-60")}
+ />
+ {shouldRenderApproval && (
+ <ToolFallbackApproval
+ addResult={addResult}
+ resume={resume}
+ interrupt={interrupt}
+ approval={approval}
+ respondToApproval={respondToApproval}
+ status={status}
+ />
+ )}
+ {!isCancelled && <ToolFallbackResult result={result} />}
+ </ToolFallbackContent>
+ </ToolFallbackRoot>
+ );
+};
+
+const ToolFallback = memo(
+ ToolFallbackImpl,
+) as unknown as ToolCallMessagePartComponent & {
+ Root: typeof ToolFallbackRoot;
+ Trigger: typeof ToolFallbackTrigger;
+ Content: typeof ToolFallbackContent;
+ Args: typeof ToolFallbackArgs;
+ Result: typeof ToolFallbackResult;
+ Error: typeof ToolFallbackError;
+ Approval: typeof ToolFallbackApproval;
+};
+
+ToolFallback.displayName = "ToolFallback";
+ToolFallback.Root = ToolFallbackRoot;
+ToolFallback.Trigger = ToolFallbackTrigger;
+ToolFallback.Content = ToolFallbackContent;
+ToolFallback.Args = ToolFallbackArgs;
+ToolFallback.Result = ToolFallbackResult;
+ToolFallback.Error = ToolFallbackError;
+ToolFallback.Approval = ToolFallbackApproval;
+
+export {
+ ToolFallback,
+ ToolFallbackRoot,
+ ToolFallbackTrigger,
+ ToolFallbackContent,
+ ToolFallbackArgs,
+ ToolFallbackResult,
+ ToolFallbackError,
+ ToolFallbackApproval,
+};
diff --git a/app/src/components/assistant-ui/tool-group.tsx b/app/src/components/assistant-ui/tool-group.tsx
new file mode 100644
index 0000000000..21e08fa1d8
--- /dev/null
+++ b/app/src/components/assistant-ui/tool-group.tsx
@@ -0,0 +1,238 @@
+"use client";
+
+import {
+ memo,
+ useCallback,
+ useRef,
+ useState,
+ type FC,
+ type PropsWithChildren,
+} from "react";
+import { ChevronDownIcon, LoaderIcon } from "lucide-react";
+import { cva, type VariantProps } from "class-variance-authority";
+import { useScrollLock } from "@assistant-ui/react";
+import {
+ Collapsible,
+ CollapsibleContent,
+ CollapsibleTrigger,
+} from "@/components/assistant-ui/ui/collapsible";
+import { cn } from "@/components/assistant-ui/lib/utils";
+
+const ANIMATION_DURATION = 200;
+
+const toolGroupVariants = cva("aui-tool-group-root group/tool-group w-full", {
+ variants: {
+ variant: {
+ outline: "rounded-lg border py-3",
+ ghost: "",
+ muted: "border-muted-foreground/30 bg-muted/30 rounded-lg border py-3",
+ },
+ },
+ defaultVariants: { variant: "outline" },
+});
+
+export type ToolGroupRootProps = Omit<
+ React.ComponentProps<typeof Collapsible>,
+ "open" | "onOpenChange"
+> &
+ VariantProps<typeof toolGroupVariants> & {
+ open?: boolean;
+ onOpenChange?: (open: boolean) => void;
+ defaultOpen?: boolean;
+ };
+
+function ToolGroupRoot({
+ className,
+ variant,
+ open: controlledOpen,
+ onOpenChange: controlledOnOpenChange,
+ defaultOpen = false,
+ children,
+ ...props
+}: ToolGroupRootProps) {
+ const collapsibleRef = useRef<HTMLDivElement>(null);
+ const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);
+ const lockScroll = useScrollLock(collapsibleRef, ANIMATION_DURATION);
+
+ const isControlled = controlledOpen !== undefined;
+ const isOpen = isControlled ? controlledOpen : uncontrolledOpen;
+
+ const handleOpenChange = useCallback(
+ (open: boolean) => {
+ lockScroll();
+ if (!isControlled) {
+ setUncontrolledOpen(open);
+ }
+ controlledOnOpenChange?.(open);
+ },
+ [lockScroll, isControlled, controlledOnOpenChange],
+ );
+
+ return (
+ <Collapsible
+ ref={collapsibleRef}
+ data-slot="tool-group-root"
+ data-variant={variant ?? "outline"}
+ open={isOpen}
+ onOpenChange={handleOpenChange}
+ className={cn(
+ toolGroupVariants({ variant }),
+ "group/tool-group-root",
+ className,
+ )}
+ style={
+ {
+ "--animation-duration": `${ANIMATION_DURATION}ms`,
+ } as React.CSSProperties
+ }
+ {...props}
+ >
+ {children}
+ </Collapsible>
+ );
+}
+
+function ToolGroupTrigger({
+ count,
+ active = false,
+ className,
+ ...props
+}: React.ComponentProps<typeof CollapsibleTrigger> & {
+ count: number;
+ active?: boolean;
+}) {
+ const label = `${count} tool ${count === 1 ? "call" : "calls"}`;
+
+ return (
+ <CollapsibleTrigger
+ data-slot="tool-group-trigger"
+ className={cn(
+ "aui-tool-group-trigger group/trigger flex origin-left items-center gap-2 text-sm transition-[color,scale] active:scale-[0.98]",
+ "group-data-[variant=ghost]/tool-group-root:text-muted-foreground group-data-[variant=ghost]/tool-group-root:hover:text-foreground group-data-[variant=ghost]/tool-group-root:py-1.5",
+ "group-data-[variant=outline]/tool-group-root:w-full group-data-[variant=outline]/tool-group-root:px-4",
+ "group-data-[variant=muted]/tool-group-root:w-full group-data-[variant=muted]/tool-group-root:px-4",
+ className,
+ )}
+ {...props}
+ >
+ {active && (
+ <LoaderIcon
+ data-slot="tool-group-trigger-loader"
+ className="aui-tool-group-trigger-loader size-3 shrink-0 animate-spin [animation-duration:0.6s]"
+ />
+ )}
+ <span
+ data-slot="tool-group-trigger-label"
+ className={cn(
+ "aui-tool-group-trigger-label-wrapper relative inline-block text-start leading-none font-medium",
+ "group-data-[variant=ghost]/tool-group-root:font-normal",
+ "group-data-[variant=outline]/tool-group-root:grow",
+ "group-data-[variant=muted]/tool-group-root:grow",
+ )}
+ >
+ <span className="text-xs">{label}</span>
+ {active && (
+ <span
+ aria-hidden
+ data-slot="tool-group-trigger-shimmer"
+ className="aui-tool-group-trigger-shimmer shimmer pointer-events-none absolute inset-0 text-xs motion-reduce:animate-none"
+ >
+ {label}
+ </span>
+ )}
+ </span>
+ <ChevronDownIcon
+ data-slot="tool-group-trigger-chevron"
+ className={cn(
+ "aui-tool-group-trigger-chevron size-3 shrink-0",
+ "transition-transform duration-(--animation-duration) ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:transition-none",
+ "-rotate-90",
+ "group-data-open/trigger:rotate-0",
+ "group-data-panel-open/trigger:rotate-0",
+ )}
+ />
+ </CollapsibleTrigger>
+ );
+}
+
+function ToolGroupContent({
+ className,
+ children,
+ ...props
+}: React.ComponentProps<typeof CollapsibleContent>) {
+ return (
+ <CollapsibleContent
+ data-slot="tool-group-content"
+ className={cn(
+ "aui-tool-group-content relative overflow-hidden text-sm outline-none",
+ "group/collapsible-content ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:animate-none",
+ "data-closed:animate-collapsible-up",
+ "data-open:animate-collapsible-down",
+ "data-closed:fill-mode-forwards",
+ "data-closed:pointer-events-none",
+ "[--tw-duration:var(--animation-duration)]",
+ className,
+ )}
+ {...props}
+ >
+ <div
+ className={cn(
+ "mt-2 flex flex-col gap-2",
+ "group-data-[variant=ghost]/tool-group-root:mt-1 group-data-[variant=ghost]/tool-group-root:gap-1",
+ "group-data-[variant=outline]/tool-group-root:mt-3 group-data-[variant=outline]/tool-group-root:border-t group-data-[variant=outline]/tool-group-root:px-4 group-data-[variant=outline]/tool-group-root:pt-3",
+ "group-data-[variant=muted]/tool-group-root:mt-3 group-data-[variant=muted]/tool-group-root:border-t group-data-[variant=muted]/tool-group-root:px-4 group-data-[variant=muted]/tool-group-root:pt-3",
+ "[&>*]:animate-in [&>*]:fade-in-0 [&>*]:blur-in-[2px] [&>*]:slide-in-from-top-1 [&>*]:animation-duration-(--animation-duration) [&>*]:ease-[cubic-bezier(0.32,0.72,0,1)]",
+ "[&>*]:motion-reduce:animate-none",
+ "[&>*:nth-child(2)]:[animation-delay:40ms]",
+ "[&>*:nth-child(3)]:[animation-delay:80ms]",
+ "[&>*:nth-child(4)]:[animation-delay:120ms]",
+ "[&>*:nth-child(n+5)]:[animation-delay:160ms]",
+ )}
+ >
+ {children}
+ </div>
+ </CollapsibleContent>
+ );
+}
+
+type ToolGroupComponent = FC<
+ PropsWithChildren<{ startIndex: number; endIndex: number }>
+> & {
+ Root: typeof ToolGroupRoot;
+ Trigger: typeof ToolGroupTrigger;
+ Content: typeof ToolGroupContent;
+};
+
+const ToolGroupImpl: FC<
+ PropsWithChildren<{ startIndex: number; endIndex: number }>
+> = ({ children, startIndex, endIndex }) => {
+ const toolCount = endIndex - startIndex + 1;
+
+ return (
+ <ToolGroupRoot>
+ <ToolGroupTrigger count={toolCount} />
+ <ToolGroupContent>{children}</ToolGroupContent>
+ </ToolGroupRoot>
+ );
+};
+
+/**
+ * @deprecated This wrapper targets the legacy `components.ToolGroup` prop
+ * on `<MessagePrimitive.Parts>`. Use `<MessagePrimitive.GroupedParts>` with
+ * a `groupBy` returning `"group-tool"` and compose `ToolGroupRoot` /
+ * `ToolGroupTrigger` / `ToolGroupContent` directly. See `thread.tsx`.
+ */
+const ToolGroup = memo(ToolGroupImpl) as unknown as ToolGroupComponent;
+
+ToolGroup.displayName = "ToolGroup";
+ToolGroup.Root = ToolGroupRoot;
+ToolGroup.Trigger = ToolGroupTrigger;
+ToolGroup.Content = ToolGroupContent;
+
+export {
+ ToolGroup,
+ ToolGroupRoot,
+ ToolGroupTrigger,
+ ToolGroupContent,
+ toolGroupVariants,
+};
diff --git a/app/src/components/assistant-ui/tooltip-icon-button.tsx b/app/src/components/assistant-ui/tooltip-icon-button.tsx
new file mode 100644
index 0000000000..2f10fd7ed7
--- /dev/null
+++ b/app/src/components/assistant-ui/tooltip-icon-button.tsx
@@ -0,0 +1,48 @@
+"use client";
+
+import { type ComponentPropsWithRef, forwardRef } from "react";
+import { Slot } from "radix-ui";
+
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipProvider,
+ TooltipTrigger,
+} from "@/components/assistant-ui/ui/tooltip";
+import { Button } from "@/components/assistant-ui/ui/button";
+import { cn } from "@/components/assistant-ui/lib/utils";
+
+export type TooltipIconButtonProps = ComponentPropsWithRef<typeof Button> & {
+ tooltip: string;
+ side?: "top" | "bottom" | "left" | "right";
+};
+
+export const TooltipIconButton = forwardRef<
+ HTMLButtonElement,
+ TooltipIconButtonProps
+>(({ children, tooltip, side = "bottom", className, ...rest }, ref) => {
+ return (
+ <TooltipProvider delayDuration={0}>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button
+ variant="ghost"
+ size="icon"
+ {...rest}
+ className={cn(
+ "aui-button-icon size-6 p-1 active:scale-90",
+ className,
+ )}
+ ref={ref}
+ >
+ <Slot.Slottable>{children}</Slot.Slottable>
+ <span className="aui-sr-only sr-only">{tooltip}</span>
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent side={side}>{tooltip}</TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
+ );
+});
+
+TooltipIconButton.displayName = "TooltipIconButton";
diff --git a/app/src/components/assistant-ui/ui/avatar.tsx b/app/src/components/assistant-ui/ui/avatar.tsx
new file mode 100644
index 0000000000..11c06d6c08
--- /dev/null
+++ b/app/src/components/assistant-ui/ui/avatar.tsx
@@ -0,0 +1,48 @@
+import * as React from "react"
+import * as AvatarPrimitive from "@radix-ui/react-avatar"
+
+import { cn } from "@/components/assistant-ui/lib/utils"
+
+const Avatar = React.forwardRef<
+ React.ElementRef<typeof AvatarPrimitive.Root>,
+ React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>
+>(({ className, ...props }, ref) => (
+ <AvatarPrimitive.Root
+ ref={ref}
+ className={cn(
+ "relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",
+ className
+ )}
+ {...props}
+ />
+))
+Avatar.displayName = AvatarPrimitive.Root.displayName
+
+const AvatarImage = React.forwardRef<
+ React.ElementRef<typeof AvatarPrimitive.Image>,
+ React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
+>(({ className, ...props }, ref) => (
+ <AvatarPrimitive.Image
+ ref={ref}
+ className={cn("aspect-square h-full w-full", className)}
+ {...props}
+ />
+))
+AvatarImage.displayName = AvatarPrimitive.Image.displayName
+
+const AvatarFallback = React.forwardRef<
+ React.ElementRef<typeof AvatarPrimitive.Fallback>,
+ React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
+>(({ className, ...props }, ref) => (
+ <AvatarPrimitive.Fallback
+ ref={ref}
+ className={cn(
+ "flex h-full w-full items-center justify-center rounded-full bg-muted",
+ className
+ )}
+ {...props}
+ />
+))
+AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName
+
+export { Avatar, AvatarImage, AvatarFallback }
diff --git a/app/src/components/assistant-ui/ui/button.tsx b/app/src/components/assistant-ui/ui/button.tsx
new file mode 100644
index 0000000000..f8d6e9306e
--- /dev/null
+++ b/app/src/components/assistant-ui/ui/button.tsx
@@ -0,0 +1,57 @@
+import * as React from "react"
+import { Slot } from "@radix-ui/react-slot"
+import { cva, type VariantProps } from "class-variance-authority"
+
+import { cn } from "@/components/assistant-ui/lib/utils"
+
+const buttonVariants = cva(
+ "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
+ {
+ variants: {
+ variant: {
+ default:
+ "bg-primary text-primary-foreground shadow hover:bg-primary/90",
+ destructive:
+ "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
+ outline:
+ "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
+ secondary:
+ "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
+ ghost: "hover:bg-accent hover:text-accent-foreground",
+ link: "text-primary underline-offset-4 hover:underline",
+ },
+ size: {
+ default: "h-9 px-4 py-2",
+ sm: "h-8 rounded-md px-3 text-xs",
+ lg: "h-10 rounded-md px-8",
+ icon: "h-9 w-9",
+ },
+ },
+ defaultVariants: {
+ variant: "default",
+ size: "default",
+ },
+ }
+)
+
+export interface ButtonProps
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
+ VariantProps<typeof buttonVariants> {
+ asChild?: boolean
+}
+
+const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
+ ({ className, variant, size, asChild = false, ...props }, ref) => {
+ const Comp = asChild ? Slot : "button"
+ return (
+ <Comp
+ className={cn(buttonVariants({ variant, size, className }))}
+ ref={ref}
+ {...props}
+ />
+ )
+ }
+)
+Button.displayName = "Button"
+
+export { Button, buttonVariants }
diff --git a/app/src/components/assistant-ui/ui/collapsible.tsx b/app/src/components/assistant-ui/ui/collapsible.tsx
new file mode 100644
index 0000000000..a23e7a2812
--- /dev/null
+++ b/app/src/components/assistant-ui/ui/collapsible.tsx
@@ -0,0 +1,9 @@
+import * as CollapsiblePrimitive from "@radix-ui/react-collapsible"
+
+const Collapsible = CollapsiblePrimitive.Root
+
+const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger
+
+const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent
+
+export { Collapsible, CollapsibleTrigger, CollapsibleContent }
diff --git a/app/src/components/assistant-ui/ui/dialog.tsx b/app/src/components/assistant-ui/ui/dialog.tsx
new file mode 100644
index 0000000000..7b89e19509
--- /dev/null
+++ b/app/src/components/assistant-ui/ui/dialog.tsx
@@ -0,0 +1,120 @@
+import * as React from "react"
+import * as DialogPrimitive from "@radix-ui/react-dialog"
+import { X } from "lucide-react"
+
+import { cn } from "@/components/assistant-ui/lib/utils"
+
+const Dialog = DialogPrimitive.Root
+
+const DialogTrigger = DialogPrimitive.Trigger
+
+const DialogPortal = DialogPrimitive.Portal
+
+const DialogClose = DialogPrimitive.Close
+
+const DialogOverlay = React.forwardRef<
+ React.ElementRef<typeof DialogPrimitive.Overlay>,
+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
+>(({ className, ...props }, ref) => (
+ <DialogPrimitive.Overlay
+ ref={ref}
+ className={cn(
+ "fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
+ className
+ )}
+ {...props}
+ />
+))
+DialogOverlay.displayName = DialogPrimitive.Overlay.displayName
+
+const DialogContent = React.forwardRef<
+ React.ElementRef<typeof DialogPrimitive.Content>,
+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
+>(({ className, children, ...props }, ref) => (
+ <DialogPortal>
+ <DialogOverlay />
+ <DialogPrimitive.Content
+ ref={ref}
+ className={cn(
+ "fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
+ className
+ )}
+ {...props}
+ >
+ {children}
+ <DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
+ <X className="h-4 w-4" />
+ <span className="sr-only">Close</span>
+ </DialogPrimitive.Close>
+ </DialogPrimitive.Content>
+ </DialogPortal>
+))
+DialogContent.displayName = DialogPrimitive.Content.displayName
+
+const DialogHeader = ({
+ className,
+ ...props
+}: React.HTMLAttributes<HTMLDivElement>) => (
+ <div
+ className={cn(
+ "flex flex-col space-y-1.5 text-center sm:text-left",
+ className
+ )}
+ {...props}
+ />
+)
+DialogHeader.displayName = "DialogHeader"
+
+const DialogFooter = ({
+ className,
+ ...props
+}: React.HTMLAttributes<HTMLDivElement>) => (
+ <div
+ className={cn(
+ "flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
+ className
+ )}
+ {...props}
+ />
+)
+DialogFooter.displayName = "DialogFooter"
+
+const DialogTitle = React.forwardRef<
+ React.ElementRef<typeof DialogPrimitive.Title>,
+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
+>(({ className, ...props }, ref) => (
+ <DialogPrimitive.Title
+ ref={ref}
+ className={cn(
+ "text-lg font-semibold leading-none tracking-tight",
+ className
+ )}
+ {...props}
+ />
+))
+DialogTitle.displayName = DialogPrimitive.Title.displayName
+
+const DialogDescription = React.forwardRef<
+ React.ElementRef<typeof DialogPrimitive.Description>,
+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
+>(({ className, ...props }, ref) => (
+ <DialogPrimitive.Description
+ ref={ref}
+ className={cn("text-sm text-muted-foreground", className)}
+ {...props}
+ />
+))
+DialogDescription.displayName = DialogPrimitive.Description.displayName
+
+export {
+ Dialog,
+ DialogPortal,
+ DialogOverlay,
+ DialogTrigger,
+ DialogClose,
+ DialogContent,
+ DialogHeader,
+ DialogFooter,
+ DialogTitle,
+ DialogDescription,
+}
diff --git a/app/src/components/assistant-ui/ui/skeleton.tsx b/app/src/components/assistant-ui/ui/skeleton.tsx
new file mode 100644
index 0000000000..240182e8f7
--- /dev/null
+++ b/app/src/components/assistant-ui/ui/skeleton.tsx
@@ -0,0 +1,15 @@
+import { cn } from "@/components/assistant-ui/lib/utils"
+
+function Skeleton({
+ className,
+ ...props
+}: React.HTMLAttributes<HTMLDivElement>) {
+ return (
+ <div
+ className={cn("animate-pulse rounded-md bg-primary/10", className)}
+ {...props}
+ />
+ )
+}
+
+export { Skeleton }
diff --git a/app/src/components/assistant-ui/ui/tooltip.tsx b/app/src/components/assistant-ui/ui/tooltip.tsx
new file mode 100644
index 0000000000..99cdd9b228
--- /dev/null
+++ b/app/src/components/assistant-ui/ui/tooltip.tsx
@@ -0,0 +1,32 @@
+"use client"
+
+import * as React from "react"
+import * as TooltipPrimitive from "@radix-ui/react-tooltip"
+
+import { cn } from "@/components/assistant-ui/lib/utils"
+
+const TooltipProvider = TooltipPrimitive.Provider
+
+const Tooltip = TooltipPrimitive.Root
+
+const TooltipTrigger = TooltipPrimitive.Trigger
+
+const TooltipContent = React.forwardRef<
+ React.ElementRef<typeof TooltipPrimitive.Content>,
+ React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
+>(({ className, sideOffset = 4, ...props }, ref) => (
+ <TooltipPrimitive.Portal>
+ <TooltipPrimitive.Content
+ ref={ref}
+ sideOffset={sideOffset}
+ className={cn(
+ "z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",
+ className
+ )}
+ {...props}
+ />
+ </TooltipPrimitive.Portal>
+))
+TooltipContent.displayName = TooltipPrimitive.Content.displayName
+
+export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
diff --git a/app/src/index.css b/app/src/index.css
index 5d6d5e6b26..a4d3a2a112 100644
--- a/app/src/index.css
+++ b/app/src/index.css
@@ -7,6 +7,7 @@
/* Canonical theme tokens (colour + font-role CSS variables). Must precede the
Tailwind layers so the var-backed utility colours resolve. */
@import './styles/tokens.css';
+@import "tw-shimmer";
/* Tailwind CSS imports */
@tailwind base;
@@ -313,3 +314,26 @@
--cmd-overlay: rgb(var(--surface-overlay) / 0.7);
--cmd-shadow-palette: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.25);
}
+
+@custom-variant data-open (&:where([data-state="open"], [data-open]:not([data-open="false"])));
+
+@custom-variant data-closed (&:where([data-state="closed"], [data-closed]:not([data-closed="false"])));
+
+@theme inline {
+ @keyframes collapsible-down {
+ from {
+ height: 0;
+ }
+ to {
+ height: var(--radix-collapsible-content-height, var(--collapsible-panel-height, auto));
+ }
+ }
+ @keyframes collapsible-up {
+ from {
+ height: var(--radix-collapsible-content-height, var(--collapsible-panel-height, auto));
+ }
+ to {
+ height: 0;
+ }
+ }
+}
\ No newline at end of file