SurfSense/surfsense_web/components/chat/ChatInterface.tsx

79 lines
2.4 KiB
TypeScript
Raw Normal View History

"use client";
2025-07-27 10:41:15 -07:00
import { type ChatHandler, ChatSection as LlamaIndexChatSection } from "@llamaindex/chat-ui";
2025-10-22 14:41:47 +02:00
import { PanelRight } from "lucide-react";
import { useState } from "react";
import type { ResearchMode } from "@/components/chat";
2025-07-27 10:41:15 -07:00
import { ChatInputUI } from "@/components/chat/ChatInputGroup";
import { ChatMessagesUI } from "@/components/chat/ChatMessages";
2025-07-27 10:41:15 -07:00
import type { Document } from "@/hooks/use-documents";
2025-10-22 14:41:47 +02:00
import { cn } from "@/lib/utils";
2025-10-22 15:14:38 +02:00
import { ChatPanelContainer } from "./ChatPannel/ChatPannelContainer";
interface ChatInterfaceProps {
2025-07-25 18:06:48 -07:00
handler: ChatHandler;
onDocumentSelectionChange?: (documents: Document[]) => void;
selectedDocuments?: Document[];
onConnectorSelectionChange?: (connectorTypes: string[]) => void;
selectedConnectors?: string[];
searchMode?: "DOCUMENTS" | "CHUNKS";
onSearchModeChange?: (mode: "DOCUMENTS" | "CHUNKS") => void;
}
2025-07-25 18:06:48 -07:00
export default function ChatInterface({
2025-07-25 18:06:48 -07:00
handler,
onDocumentSelectionChange,
selectedDocuments = [],
onConnectorSelectionChange,
selectedConnectors = [],
searchMode,
onSearchModeChange,
}: ChatInterfaceProps) {
2025-10-22 14:41:47 +02:00
const [isChatPannelOpen, setIsChatPannelOpen] = useState(false);
2025-07-25 18:06:48 -07:00
return (
<LlamaIndexChatSection handler={handler} className="flex h-full">
2025-10-22 14:41:47 +02:00
<div className="flex gap-4 flex-1 w-full">
<div className="flex grow-1 flex-col">
<ChatMessagesUI />
<div className="border-t p-4">
<ChatInputUI
onDocumentSelectionChange={onDocumentSelectionChange}
selectedDocuments={selectedDocuments}
onConnectorSelectionChange={onConnectorSelectionChange}
selectedConnectors={selectedConnectors}
searchMode={searchMode}
onSearchModeChange={onSearchModeChange}
/>
</div>
</div>
<div
className={cn(
2025-10-22 14:43:51 +02:00
"border rounded-2xl shrink-0 flex flex-col h-full transition-all",
2025-10-22 14:41:47 +02:00
isChatPannelOpen ? "w-72" : "w-14"
)}
>
<div
className={cn(
2025-10-22 14:43:51 +02:00
"w-full border-b p-2 flex items-center transition-all ",
2025-10-22 14:41:47 +02:00
isChatPannelOpen ? "justify-end" : " justify-center "
)}
>
<button
type="button"
onClick={() => setIsChatPannelOpen(!isChatPannelOpen)}
className={cn(" shrink-0 rounded-full p-2 w-fit hover:bg-muted")}
>
<PanelRight className="h-5 w-5" strokeWidth={1.5} />
</button>
</div>
2025-10-22 15:14:38 +02:00
<div className="border-b rounded-lg grow-1">
<ChatPanelContainer />
</div>
2025-07-25 18:06:48 -07:00
</div>
</div>
</LlamaIndexChatSection>
);
}