import React, { useState, useEffect, useRef } from 'react'; import ReactMarkdown from 'react-markdown'; import remarkMath from 'remark-math'; import rehypeKatex from 'rehype-katex'; import { Send, Bot, User, Sparkles } from 'lucide-react'; import { querySystem } from '../api'; import { motion } from 'framer-motion'; const Notebook = ({ messages, setMessages, onCitationClick, notebookId }) => { // Accept notebookId // const [messages, setMessages] = useState([ ... ]); // Removed internal state const [input, setInput] = useState(''); const [loading, setLoading] = useState(false); const scrollRef = useRef(null); useEffect(() => { if (scrollRef.current) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } }, [messages]); const handleSend = async () => { if (!input.trim()) return; const userMsg = { role: 'user', content: input }; setMessages(prev => [...prev, userMsg]); setInput(''); setLoading(true); try { // Pass notebookId to querySystem const response = await querySystem(userMsg.content, notebookId); const botMsg = { role: 'assistant', content: response.answer, citations: response.citations }; setMessages(prev => [...prev, botMsg]); } catch (err) { setMessages(prev => [...prev, { role: 'assistant', content: 'Connection error. Please ensure background services are running.' }]); } setLoading(false); }; return (
AI can make mistakes. Check important info.