"use client"; import { ChatSection, ChatHandler, ChatInput, ChatCanvas, ChatMessages, } from "@llamaindex/chat-ui"; import { Button } from "../ui/button"; import { FolderOpen } from "lucide-react"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from "../ui/dialog"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "../ui/select"; import { Badge } from "../ui/badge"; import { Suspense, useState, useCallback } from "react"; import { useParams } from "next/navigation"; import { useDocuments, DocumentType, Document } from "@/hooks/use-documents"; import { DocumentsDataTable } from "./DocumentsDataTable"; import { ResearchMode } from "@/components/chat"; import React from "react"; interface ChatInterfaceProps { handler: ChatHandler; onDocumentSelectionChange?: (documents: Document[]) => void; selectedDocuments?: Document[]; searchMode?: "DOCUMENTS" | "CHUNKS"; onSearchModeChange?: (mode: "DOCUMENTS" | "CHUNKS") => void; researchMode?: ResearchMode; onResearchModeChange?: (mode: ResearchMode) => void; } const DocumentSelector = React.memo( ({ onSelectionChange, selectedDocuments = [], }: { onSelectionChange?: (documents: Document[]) => void; selectedDocuments?: Document[]; }) => { const { search_space_id } = useParams(); const [isOpen, setIsOpen] = useState(false); const { documents, loading, isLoaded, fetchDocuments } = useDocuments( Number(search_space_id) ); const handleOpenChange = useCallback( (open: boolean) => { setIsOpen(open); if (open && !isLoaded) { fetchDocuments(); } }, [fetchDocuments, isLoaded] ); const handleSelectionChange = useCallback( (documents: Document[]) => { onSelectionChange?.(documents); }, [onSelectionChange] ); const handleDone = useCallback(() => { setIsOpen(false); }, [selectedDocuments]); const selectedCount = selectedDocuments.length; return (
Select Documents Choose documents to include in your research context
{loading ? (

Loading documents...

) : isLoaded ? ( ) : null}
); } ); const SearchModeSelector = ({ searchMode, onSearchModeChange, }: { searchMode?: "DOCUMENTS" | "CHUNKS"; onSearchModeChange?: (mode: "DOCUMENTS" | "CHUNKS") => void; }) => { return (
Scope:
); }; const ResearchModeSelector = ({ researchMode, onResearchModeChange, }: { researchMode?: ResearchMode; onResearchModeChange?: (mode: ResearchMode) => void; }) => { const researchModeLabels: Record = { QNA: "Q&A", REPORT_GENERAL: "General Report", REPORT_DEEP: "Deep Report", REPORT_DEEPER: "Deeper Report", }; const researchModeShortLabels: Record = { QNA: "Q&A", REPORT_GENERAL: "General", REPORT_DEEP: "Deep", REPORT_DEEPER: "Deeper", }; return (
Mode:
); }; const CustomChatInputOptions = ({ onDocumentSelectionChange, selectedDocuments, searchMode, onSearchModeChange, researchMode, onResearchModeChange, }: { onDocumentSelectionChange?: (documents: Document[]) => void; selectedDocuments?: Document[]; searchMode?: "DOCUMENTS" | "CHUNKS"; onSearchModeChange?: (mode: "DOCUMENTS" | "CHUNKS") => void; researchMode?: ResearchMode; onResearchModeChange?: (mode: ResearchMode) => void; }) => { return (
Loading...
}> ); }; const CustomChatInput = ({ onDocumentSelectionChange, selectedDocuments, searchMode, onSearchModeChange, researchMode, onResearchModeChange, }: { onDocumentSelectionChange?: (documents: Document[]) => void; selectedDocuments?: Document[]; searchMode?: "DOCUMENTS" | "CHUNKS"; onSearchModeChange?: (mode: "DOCUMENTS" | "CHUNKS") => void; researchMode?: ResearchMode; onResearchModeChange?: (mode: ResearchMode) => void; }) => { return ( ); }; export default function ChatInterface({ handler, onDocumentSelectionChange, selectedDocuments = [], searchMode, onSearchModeChange, researchMode, onResearchModeChange, }: ChatInterfaceProps) { return (
{/* Custom message rendering */}
); }