SurfSense/surfsense_web/components/chat/ChatInterface.tsx

72 lines
2.3 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";
2025-10-22 16:35:15 +02:00
import { useParams } from "next/navigation";
2025-10-22 15:35:44 +02:00
import { createContext, useState } from "react";
2025-10-22 14:41:47 +02:00
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-23 01:28:07 +02:00
import { ChatPanelContainer } from "./ChatPannel/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-07-25 18:06:48 -07:00
2025-10-22 15:35:44 +02:00
interface ChatInterfaceContext {
isChatPannelOpen: boolean;
setIsChatPannelOpen: (value: boolean) => void;
2025-10-23 01:28:07 +02:00
chat_id: string;
2025-10-22 15:35:44 +02:00
}
export const chatInterfaceContext = createContext<ChatInterfaceContext | null>(null);
export default function ChatInterface({
2025-07-25 18:06:48 -07:00
handler,
onDocumentSelectionChange,
selectedDocuments = [],
onConnectorSelectionChange,
selectedConnectors = [],
searchMode,
onSearchModeChange,
}: ChatInterfaceProps) {
2025-10-23 01:28:07 +02:00
const { chat_id } = useParams();
2025-10-22 14:41:47 +02:00
const [isChatPannelOpen, setIsChatPannelOpen] = useState(false);
2025-10-22 15:35:44 +02:00
const contextValue = {
isChatPannelOpen,
setIsChatPannelOpen,
2025-10-23 01:28:07 +02:00
chat_id: typeof chat_id === "string" ? chat_id : chat_id ? chat_id[0] : "",
2025-10-22 15:35:44 +02:00
};
2025-10-22 14:41:47 +02:00
2025-07-25 18:06:48 -07:00
return (
2025-10-22 15:35:44 +02:00
<chatInterfaceContext.Provider value={contextValue}>
<LlamaIndexChatSection handler={handler} className="flex h-full">
<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>
2025-10-22 14:41:47 +02:00
</div>
2025-10-23 01:28:07 +02:00
<ChatPanelContainer />
2025-07-25 18:06:48 -07:00
</div>
2025-10-22 15:35:44 +02:00
</LlamaIndexChatSection>
</chatInterfaceContext.Provider>
2025-07-25 18:06:48 -07:00
);
}