Skip to content

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

feat(assistant-ui): add attachment and avatar components

Steven Enamakelb29f4d4dd57d
diff --git a/app/src/components/assistant-ui/attachment.tsx b/app/src/components/assistant-ui/attachment.tsx
index b50a5a65af..305b5c5043 100644
--- a/app/src/components/assistant-ui/attachment.tsx
+++ b/app/src/components/assistant-ui/attachment.tsx
@@ -1,6 +1,12 @@
"use client";
-import { type PropsWithChildren, useEffect, useState, type FC } from "react";
+import {
+ type PropsWithChildren,
+ useEffect,
+ useState,
+ type FC,
+ isValidElement,
+} from "react";
import {
XIcon,
PlusIcon,
@@ -28,11 +34,7 @@ import {
DialogContent,
DialogTrigger,
} from "@/components/assistant-ui/ui/dialog";
-import {
- Avatar,
- AvatarImage,
- AvatarFallback,
-} from "@/components/assistant-ui/ui/avatar";
+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";
@@ -100,11 +102,10 @@ const AttachmentPreviewDialog: FC<PropsWithChildren> = ({ children }) => {
return (
<Dialog>
<DialogTrigger
+ nativeButton={false}
className="aui-attachment-preview-trigger cursor-zoom-in"
- asChild
- >
- {children}
- </DialogTrigger>
+ render={isValidElement(children) ? children : <button type="button" />}
+ />
<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
@@ -121,7 +122,7 @@ const AttachmentThumb: FC = () => {
const src = useAttachmentSrc();
return (
- <Avatar className="aui-attachment-tile-avatar h-full w-full rounded-none">
+ <Avatar className="aui-attachment-tile-avatar h-full w-full rounded-none after:hidden">
<AvatarImage
src={src}
alt="Attachment preview"
@@ -181,52 +182,47 @@ const AttachmentUI: FC = () => {
"animate-in fade-in-0 zoom-in-95 duration-200 motion-reduce:animate-none",
isImage &&
!isComposer &&
- "aui-attachment-root-message first:*:only:size-24",
+ "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-hidden 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-xs 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-xs motion-reduce:animate-none"
- >
- <AlertCircleIcon className="text-destructive size-4" />
- </div>
- )}
- </div>
+ <TooltipTrigger
+ render={
+ <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}
+ 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>
+ )}
</TooltipTrigger>
</AttachmentPreviewDialog>
{isComposer && <AttachmentRemove />}
@@ -244,14 +240,16 @@ const AttachmentUI: FC = () => {
const AttachmentRemove: FC = () => {
return (
- <AttachmentPrimitive.Remove asChild>
- <TooltipIconButton
- tooltip="Remove file"
- className="aui-attachment-tile-remove absolute inset-e-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
+ render={
+ <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]" />
</AttachmentPrimitive.Remove>
);
};
@@ -278,17 +276,19 @@ export const ComposerAttachments: FC = () => {
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
+ render={
+ <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" />
</ComposerPrimitive.AddAttachment>
);
};
diff --git a/app/src/components/assistant-ui/ui/avatar.tsx b/app/src/components/assistant-ui/ui/avatar.tsx
index 11c06d6c08..f7fe4123ba 100644
--- a/app/src/components/assistant-ui/ui/avatar.tsx
+++ b/app/src/components/assistant-ui/ui/avatar.tsx
@@ -1,48 +1,109 @@
+"use client"
+
import * as React from "react"
-import * as AvatarPrimitive from "@radix-ui/react-avatar"
+import { Avatar as AvatarPrimitive } from "@base-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 }
+function Avatar({
+ className,
+ size = "default",
+ ...props
+}: AvatarPrimitive.Root.Props & {
+ size?: "default" | "sm" | "lg"
+}) {
+ return (
+ <AvatarPrimitive.Root
+ data-slot="avatar"
+ data-size={size}
+ className={cn(
+ "group/avatar relative flex size-8 shrink-0 rounded-full select-none after:absolute after:inset-0 after:rounded-full after:border after:border-border after:mix-blend-darken data-[size=lg]:size-10 data-[size=sm]:size-6 dark:after:mix-blend-lighten",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function AvatarImage({ className, ...props }: AvatarPrimitive.Image.Props) {
+ return (
+ <AvatarPrimitive.Image
+ data-slot="avatar-image"
+ className={cn(
+ "aspect-square size-full rounded-full object-cover",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function AvatarFallback({
+ className,
+ ...props
+}: AvatarPrimitive.Fallback.Props) {
+ return (
+ <AvatarPrimitive.Fallback
+ data-slot="avatar-fallback"
+ className={cn(
+ "flex size-full items-center justify-center rounded-full bg-muted text-sm text-muted-foreground group-data-[size=sm]/avatar:text-xs",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function AvatarBadge({ className, ...props }: React.ComponentProps<"span">) {
+ return (
+ <span
+ data-slot="avatar-badge"
+ className={cn(
+ "absolute right-0 bottom-0 z-10 inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground bg-blend-color ring-2 ring-background select-none",
+ "group-data-[size=sm]/avatar:size-2 group-data-[size=sm]/avatar:[&>svg]:hidden",
+ "group-data-[size=default]/avatar:size-2.5 group-data-[size=default]/avatar:[&>svg]:size-2",
+ "group-data-[size=lg]/avatar:size-3 group-data-[size=lg]/avatar:[&>svg]:size-2",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function AvatarGroup({ className, ...props }: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="avatar-group"
+ className={cn(
+ "group/avatar-group flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:ring-background",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+function AvatarGroupCount({
+ className,
+ ...props
+}: React.ComponentProps<"div">) {
+ return (
+ <div
+ data-slot="avatar-group-count"
+ className={cn(
+ "relative flex size-8 shrink-0 items-center justify-center rounded-full bg-muted text-sm text-muted-foreground ring-2 ring-background group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=sm]/avatar-group:size-6 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3",
+ className
+ )}
+ {...props}
+ />
+ )
+}
+
+export {
+ Avatar,
+ AvatarImage,
+ AvatarFallback,
+ AvatarGroup,
+ AvatarGroupCount,
+ AvatarBadge,
+}