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

import type { BuiltinRenderProps } from '@lobechat/types';
import { Empty, Flexbox } from '@lobehub/ui';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';

import type { SearchKnowledgeBaseArgs, SearchKnowledgeBaseState } from '../../../types';
import FileItem from './Item';

const SearchKnowledgeBase = memo<
  BuiltinRenderProps<SearchKnowledgeBaseArgs, SearchKnowledgeBaseState>
>(({ pluginState }) => {
  const { t } = useTranslation('plugin');
  const { fileResults, scope } = pluginState || {};

  // Nothing was searched — saying "No results" would read as "the files don't
  // contain it" when the agent simply has no library to look in.
  if (scope === 'none') {
    return <Empty description={t('builtins.lobe-knowledge-base.render.noScope')} />;
  }

  if (!fileResults || fileResults.length === 0) {
    return <Empty description={t('builtins.lobe-knowledge-base.inspector.noResults')} />;
  }

  return (
    <Flexbox horizontal gap={8} wrap={'wrap'}>
      {fileResults.map((file, index) => {
        return <FileItem index={index} key={file.fileId} {...file} />;
      })}
    </Flexbox>
  );
});

export default SearchKnowledgeBase;