import ReactMarkdown from 'react-markdown' import { SERVER_URL } from '@/hooks/useAuth' export type SearchItem = { filename: string content: string chunks: any[] tags: string[] mime_type: string metadata: any } export const Tag = ({ tags }: { tags: string[] }) => { return (
{tags?.map((tag: string, index: number) => ( {tag} ))}
) } export const TextResult = ({ filename, content, chunks, tags, metadata }: SearchItem) => { return (

{filename || metadata?.title || metadata?.url || 'Untitled'}

{content &&

{content}

} {chunks && chunks.length > 0 && (
Relevant sections: {chunks.map(({preview, score}, chunkIndex) => (
Score: {(score || 0).toFixed(3)}

{preview}

))}
)}
) } export const MarkdownResult = ({ filename, content, chunks, tags, metadata }: SearchItem) => { return (

{filename || metadata?.title || metadata?.url || 'Untitled'}

{content && (
{content}
)} {chunks && chunks.length > 0 && (
Relevant sections: {chunks.map(({preview, score}, chunkIndex) => (
Score: {(score || 0).toFixed(3)}

{preview}

))}
)}
) } export const ImageResult = ({ filename, tags, metadata }: SearchItem) => { const title = metadata?.title || filename || 'Untitled' return (

{title}

{title}
) } const MetadataItem = ({ item, value }: { item: string, value: any }) => { if (item === "url") { return
  • {value}
  • } if (item === "filename") { return
  • {value}
  • } if (typeof value === 'string') { return
  • {item}: {value}
  • } return
  • {item}: {JSON.stringify(value)}
  • } export const Metadata = ({ metadata }: { metadata: any }) => { if (!metadata) return null return (
    ) } export const PDFResult = ({ filename, content, tags, metadata }: SearchItem) => { return (

    {filename || 'Untitled'}

    View PDF {content &&
    View Source {content}
    }
    ) } export const EmailResult = ({ content, tags, metadata }: SearchItem) => { return (

    {metadata?.title || metadata?.subject || 'Untitled'}

    {content &&
    {content}
    }
    ) } export const SearchResult = ({ result }: { result: SearchItem }) => { if (result.mime_type?.startsWith('image/')) { return } if (result.mime_type?.startsWith('text/markdown')) { return } if (result.mime_type?.startsWith('text/')) { return } if (result.mime_type?.startsWith('application/pdf')) { return } if (result.mime_type?.startsWith('message/rfc822')) { return } console.log(result) return null } export default SearchResult