Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.4 KB
Raw Blame
'use client';

import { agentDisplayName, type SidebarAgentItem } from '@lobechat/types';
import { memo } from 'react';

import AgentAvatar from '@/components/AgentAvatar';
import { useAgentAvatarActivity } from '@/features/AgentAvatarActivity/useAgentAvatarActivity';
import AgentGroupAvatar from '@/features/AgentGroupAvatar';

interface SidebarItemAvatarProps {
  item: SidebarAgentItem;
  /** Single-agent avatar shape; group avatars keep their stacked layout. */
  shape?: 'circle' | 'square';
  size: number;
}

/** Agent avatar that renders the stacked group variant for group chats. */
const SidebarItemAvatar = memo<SidebarItemAvatarProps>(({ item, shape, size }) => {
  const { avatar, backgroundColor, id, type } = item;
  const activity = useAgentAvatarActivity(type === 'group' ? undefined : id);

  return type === 'group' ? (
    <AgentGroupAvatar
      avatar={typeof avatar === 'string' ? avatar : undefined}
      backgroundColor={backgroundColor || undefined}
      memberAvatars={Array.isArray(avatar) ? avatar : []}
      size={size}
    />
  ) : (
    <AgentAvatar
      {...activity.avatar}
      {...activity.hover}
      agentId={id}
      avatar={typeof avatar === 'string' ? avatar : undefined}
      background={backgroundColor || undefined}
      name={agentDisplayName(item)}
      shape={shape}
      size={size}
    />
  );
});

SidebarItemAvatar.displayName = 'SidebarItemAvatar';

export default SidebarItemAvatar;