SurfSense/surfsense_web/components/chat/ChatInterface.tsx

65 lines
2 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-11-11 04:02:04 +02:00
import { useSetAtom } from "jotai";
2025-10-22 16:35:15 +02:00
import { useParams } from "next/navigation";
2025-11-11 04:02:04 +02:00
import { useEffect } from "react";
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-11-11 04:02:04 +02:00
import { activeChatIdAtom } from "@/stores/chat/active-chat.atom";
2025-10-23 19:48:10 +02:00
import { ChatPanelContainer } from "./ChatPanel/ChatPanelContainer";
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-11-06 13:25:05 -08:00
topK?: number;
onTopKChange?: (topK: number) => 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,
2025-11-06 13:25:05 -08:00
topK = 10,
onTopKChange,
}: ChatInterfaceProps) {
const { chat_id, search_space_id } = useParams();
2025-11-11 04:02:04 +02:00
const setActiveChatIdState = useSetAtom(activeChatIdAtom);
useEffect(() => {
const id = typeof chat_id === "string" ? chat_id : chat_id ? chat_id[0] : "";
if (!id) return;
2025-11-11 04:02:04 +02:00
setActiveChatIdState(id);
}, [chat_id, search_space_id]);
2025-07-25 18:06:48 -07:00
return (
<LlamaIndexChatSection handler={handler} className="flex h-full">
2025-11-11 04:02:04 +02:00
<div className="flex grow-1 flex-col">
2025-07-25 18:06:48 -07:00
<ChatMessagesUI />
<div className="border-t p-4">
<ChatInputUI
onDocumentSelectionChange={onDocumentSelectionChange}
selectedDocuments={selectedDocuments}
onConnectorSelectionChange={onConnectorSelectionChange}
selectedConnectors={selectedConnectors}
searchMode={searchMode}
onSearchModeChange={onSearchModeChange}
2025-11-06 13:25:05 -08:00
topK={topK}
onTopKChange={onTopKChange}
2025-07-25 18:06:48 -07:00
/>
</div>
</div>
</LlamaIndexChatSection>
);
}