import classNames from '~/lib/classNames' import StyledButton from '../StyledButton' import { router, usePage } from '@inertiajs/react' import { ChatSession } from '../../../types/chat' import { IconMessage } from '@tabler/icons-react' import { useState } from 'react' import KnowledgeBaseModal from './KnowledgeBaseModal' interface ChatSidebarProps { sessions: ChatSession[] activeSessionId: string | null onSessionSelect: (id: string) => void onNewChat: () => void onClearHistory: () => void isInModal?: boolean } export default function ChatSidebar({ sessions, activeSessionId, onSessionSelect, onNewChat, onClearHistory, isInModal = false, }: ChatSidebarProps) { const { aiAssistantName } = usePage<{ aiAssistantName: string }>().props const [isKnowledgeBaseModalOpen, setIsKnowledgeBaseModalOpen] = useState( () => new URLSearchParams(window.location.search).get('knowledge_base') === 'true' ) function handleCloseKnowledgeBase() { setIsKnowledgeBaseModalOpen(false) const params = new URLSearchParams(window.location.search) if (params.has('knowledge_base')) { params.delete('knowledge_base') const newUrl = [window.location.pathname, params.toString()].filter(Boolean).join('?') window.history.replaceState(window.history.state, '', newUrl) } } return (
New Chat
{sessions.length === 0 ? (
No previous chats
) : (
{sessions.map((session) => ( ))}
)}
Project Nomad Logo { if (isInModal) { window.open('/chat', '_blank') } else { router.visit('/home') } }} icon={isInModal ? 'IconExternalLink' : 'IconHome'} variant="outline" size="sm" fullWidth > {isInModal ? 'Open in New Tab' : 'Back to Home'} { router.visit('/settings/models') }} icon="IconDatabase" variant="primary" size="sm" fullWidth > Models & Settings { setIsKnowledgeBaseModalOpen(true) }} icon="IconBrain" variant="primary" size="sm" fullWidth > Knowledge Base {sessions.length > 0 && ( Clear History )}
{isKnowledgeBaseModalOpen && ( )}
) }