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.9 KB
Raw Blame
'use client';

import { Flexbox } from '@lobehub/ui';
import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';
import * as stylex from '@stylexjs/stylex';
import { memo, useMemo } from 'react';
import { useTranslation } from 'react-i18next';

import AgentSelectionEmpty from '@/features/AgentSelectionEmpty';

import AgentItem from './AgentItem';
import { type AgentItemData } from './AgentItem';
import { useAgentSelectionStore } from './store';

const styles = stylex.create({
  container: { overflowY: 'auto', flex: '1', padding: `${cssVar.paddingSM}px` },
  title: { fontSize: '12px', fontWeight: 500, color: cssVar.colorTextSecondary },
});

interface SelectedAgentListProps {
  agents: AgentItemData[];
}

const SelectedAgentList = memo<SelectedAgentListProps>(({ agents }) => {
  const { t } = useTranslation(['chat', 'common']);

  const selectedAgentIds = useAgentSelectionStore((s) => s.selectedAgentIds);

  const defaultTitle = useMemo(() => t('defaultSession', { ns: 'common' }), [t]);

  // Get selected agents data
  const selectedAgents = useMemo(() => {
    return selectedAgentIds
      .map((id) => agents.find((a) => a.id === id))
      .filter((a): a is AgentItemData => a !== undefined);
  }, [agents, selectedAgentIds]);

  if (selectedAgents.length === 0) {
    return (
      <Flexbox className={stylex.props(styles.container).className} flex={1}>
        <AgentSelectionEmpty variant="noSelected" />
      </Flexbox>
    );
  }

  return (
    <Flexbox className={stylex.props(styles.container).className} gap={4}>
      <div {...stylex.props(styles.title)}>
        {t('memberSelection.selectedAgents', { count: selectedAgents.length })}
      </div>
      <Flexbox>
        {selectedAgents.map((agent) => (
          <AgentItem showRemove agent={agent} defaultTitle={defaultTitle} key={agent.id} />
        ))}
      </Flexbox>
    </Flexbox>
  );
});

export default SelectedAgentList;