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.

2.0 KB
Raw Blame
'use client';

import { ActionIcon, Block, Text } from '@lobehub/ui';
import { ChevronsUpDownIcon } from 'lucide-react';
import React, { memo } from 'react';
import { type PropsWithChildren } from 'react';
import { useTranslation } from 'react-i18next';

import { SkeletonItem } from '@/features/NavPanel/components/SkeletonList';
import { useNavItemMetrics } from '@/features/NavPanel/density';
import { useActiveRouteParams } from '@/hooks/useActiveRouteParams';
import SupervisorAvatar from '@/routes/(main)/group/features/GroupAvatar';
import { useAgentGroupStore } from '@/store/agentGroup';
import { agentGroupSelectors } from '@/store/agentGroup/selectors';

import SwitchPanel from './SwitchPanel';

const Agent = memo<PropsWithChildren>(() => {
  const { t } = useTranslation(['chat', 'common']);
  const { headerAvatarSize, headerChevronSize, headerLabelFontSize, headerLabelWeight } =
    useNavItemMetrics();

  const { gid } = useActiveRouteParams<{ gid: string }>();
  const [isGroupsInit, groupMeta] = useAgentGroupStore((s) => [
    agentGroupSelectors.isGroupsInit(s),
    agentGroupSelectors.getGroupMeta(gid ?? '')(s),
  ]);

  const displayTitle = groupMeta?.title || t('untitledGroup', { ns: 'chat' });

  if (isGroupsInit) return <SkeletonItem height={headerAvatarSize + 4} padding={0} />;

  return (
    <SwitchPanel>
      <Block
        clickable
        horizontal
        align={'center'}
        gap={8}
        padding={2}
        variant={'borderless'}
        style={{
          minWidth: 32,
          overflow: 'hidden',
        }}
      >
        <SupervisorAvatar size={headerAvatarSize} />
        <Text ellipsis fontSize={headerLabelFontSize} weight={headerLabelWeight}>
          {displayTitle}
        </Text>
        <ActionIcon
          icon={ChevronsUpDownIcon}
          size={headerChevronSize}
          style={{
            width: headerChevronSize.blockSize,
          }}
        />
      </Block>
    </SwitchPanel>
  );
});

export default Agent;