GAIA Agent
Your advanced AI assistant for system analysis, debugging, and configuration management.
const { useState, useEffect, useRef } = React; const EXAMPLE_PROMPTS = [ { text: "Analyze System Performance", color: "green", icon: "chart" }, { text: "Debug Error Logs", color: "yellow", icon: "warning" }, { text: "Compare Configurations", color: "blue", icon: "document" } ]; const ICONS = { chat: "M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z", download: "M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4", settings: "M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z M15 12a3 3 0 11-6 0 3 3 0 016 0z", menu: "M4 6h16M4 12h16M4 18h16", attach: "M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13", send: "M2.01 21L23 12 2.01 3 2 10l15 2-15 2z", chart: "M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z", warning: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z", document: "M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" }; const Icon = ({ path, className }) => ( ); const App = () => { const [sidebarOpen, setSidebarOpen] = useState(true); const [input, setInput] = useState(''); const [isLoading, setIsLoading] = useState(false); const [currentSessionId, setCurrentSessionId] = useState(null); const [sessions, setSessions] = useState([]); const [uploadedFiles, setUploadedFiles] = useState([]); const messagesEndRef = useRef(null); const fileInputRef = useRef(null); useEffect(() => { const initialSession = { id: crypto.randomUUID(), title: 'New Chat', messages: [], updatedAt: Date.now() }; setSessions([initialSession]); setCurrentSessionId(initialSession.id); }, []); useEffect(() => { messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); }, [sessions, currentSessionId]); const createNewSession = () => ({ id: crypto.randomUUID(), title: 'New Chat', messages: [], updatedAt: Date.now() }); const handleNewChat = () => { const newSession = createNewSession(); setSessions(prev => [newSession, ...prev]); setCurrentSessionId(newSession.id); if (window.innerWidth < 1024) setSidebarOpen(false); }; const handleDeleteSession = (e, sessionId) => { e.stopPropagation(); setSessions(prev => { const filtered = prev.filter(s => s.id !== sessionId); if (filtered.length === 0) { const newSession = createNewSession(); setCurrentSessionId(newSession.id); return [newSession]; } if (sessionId === currentSessionId) { setCurrentSessionId(filtered[0].id); } return filtered; }); }; const updateSessionMessages = (sessionId, newMessage) => { setSessions(prev => prev.map(s => s.id === sessionId ? { ...s, messages: [...s.messages, newMessage] } : s )); }; const handleSendMessage = async () => { if ((!input.trim() && uploadedFiles.length === 0) || !currentSessionId) return; const userMessage = input; const filesToSend = [...uploadedFiles]; const userMsg = { role: 'user', content: userMessage, files: filesToSend.map(f => f.name) }; setInput(''); setUploadedFiles([]); setIsLoading(true); updateSessionMessages(currentSessionId, userMsg); try { setSessions(prevSessions => { const currentSession = prevSessions.find(s => s.id === currentSessionId); const formData = new FormData(); formData.append('message', userMessage); formData.append('history', JSON.stringify(currentSession?.messages || [])); filesToSend.forEach(file => { formData.append('files', file); }); fetch('/api/chat', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { if (data.reply) { updateSessionMessages(currentSessionId, { role: 'model', content: data.reply }); } setIsLoading(false); }) .catch(error => { console.error('Error:', error); updateSessionMessages(currentSessionId, { role: 'model', content: "Error: Could not connect to agent." }); setIsLoading(false); }); return prevSessions; }); } catch (error) { console.error('Error:', error); updateSessionMessages(currentSessionId, { role: 'model', content: "Error: Could not connect to agent." }); setIsLoading(false); } }; const handleKeyDown = (e) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSendMessage(); } }; const selectSession = (sessionId) => { setCurrentSessionId(sessionId); if (window.innerWidth < 1024) setSidebarOpen(false); }; const handleFileSelect = (e) => { const files = Array.from(e.target.files); setUploadedFiles(prev => [...prev, ...files]); }; const removeFile = (index) => { setUploadedFiles(prev => prev.filter((_, i) => i !== index)); }; const handleExportChat = () => { if (!currentSession || currentSession.messages.length === 0) return; const chatData = { title: currentSession.title, exportedAt: new Date().toISOString(), messages: currentSession.messages }; const blob = new Blob([JSON.stringify(chatData, null, 2)], { type: 'application/json' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `chat-${currentSession.title.replace(/\s+/g, '-').toLowerCase()}-${Date.now()}.json`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); }; const currentSession = sessions.find(s => s.id === currentSessionId); return (
Your advanced AI assistant for system analysis, debugging, and configuration management.