"use client"; import { useState, useEffect } from "react"; import { Bot } from "lucide-react"; import { cn } from "@/lib/utils"; import { useActorName } from "@/features/workspace"; interface ActorAvatarProps { actorType: string; actorId: string; size?: number; avatarUrl?: string | null; getName?: (type: string, id: string) => string; getInitials?: (type: string, id: string) => string; getAvatarUrl?: (type: string, id: string) => string | null; className?: string; } function ActorAvatar({ actorType, actorId, size = 20, avatarUrl, getName, getInitials, getAvatarUrl, className, }: ActorAvatarProps) { const actorNameHook = useActorName(); const resolveName = getName ?? actorNameHook.getActorName; const resolveInitials = getInitials ?? actorNameHook.getActorInitials; const resolveAvatarUrl = getAvatarUrl ?? actorNameHook.getActorAvatarUrl; const name = resolveName(actorType, actorId); const initials = resolveInitials(actorType, actorId); const isAgent = actorType === "agent"; const resolvedUrl = avatarUrl !== undefined ? avatarUrl : resolveAvatarUrl(actorType, actorId); const [imgError, setImgError] = useState(false); // Reset error state when URL changes (e.g. user uploads new avatar) useEffect(() => { setImgError(false); }, [resolvedUrl]); return (
{resolvedUrl && !imgError ? ( {name} setImgError(true)} /> ) : isAgent ? ( ) : ( initials )}
); } export { ActorAvatar, type ActorAvatarProps };