import React, { useState, useEffect, useRef } from 'react'; import { Boxes, User, Lock } from 'lucide-react'; import Navbar from './components/Navbar'; import IngestionPage from './pages/IngestionPage'; import SearchPlaygroundPage from './pages/SearchPlaygroundPage'; import AdvancedRagPage from './pages/AdvancedRagPage'; import VectorDbPage from './pages/VectorDbPage'; import FundamentalsPage from './pages/FundamentalsPage'; import RagasEvalPage from './pages/RagasEvalPage'; import { usePipelineStore } from './store/pipelineStore'; import { useAuthStore } from './store/authStore'; import api from './api/client'; function App() { const { isAuthenticated, login, logout } = useAuthStore(); const [username, setUsername] = useState('admin'); const [password, setPassword] = useState('admin123'); const [activeTab, setActiveTab] = useState('search'); const { setDocuments, activeJob, addStep } = usePipelineStore(); const ws = useRef(null); // Sync hash routing useEffect(() => { const hash = window.location.hash.replace('#', ''); if (['ingest', 'search', 'advanced', 'vectordb', 'fundamentals', 'eval'].includes(hash)) { setActiveTab(hash); } }, []); // Load documents useEffect(() => { if (isAuthenticated) { api.get('/ingest/documents').then(res => { setDocuments(res.data); const { selectedDoc, setSelectedDoc } = usePipelineStore.getState(); if (res.data && res.data.length > 0) { if (!selectedDoc || !res.data.some(d => d.id === selectedDoc.id)) { setSelectedDoc(res.data[0]); } } }).catch(console.error); } }, [isAuthenticated]); // WebSocket Connection for Pipeline Trace useEffect(() => { if (activeJob && isAuthenticated) { const token = sessionStorage.getItem('token'); const apiBase = import.meta.env.VITE_API_BASE_URL || window.location.origin; const wsProtocol = apiBase.startsWith('https') ? 'wss' : 'ws'; const wsHost = apiBase.replace(/^https?:\/\//, ''); const wsUrl = `${wsProtocol}://${wsHost}/ws/pipeline/${activeJob}?token=${token}`; ws.current = new WebSocket(wsUrl); ws.current.onmessage = (event) => { const step = JSON.parse(event.data); addStep(step); if (step.step === 'DONE') { api.get('/ingest/documents').then(res => { setDocuments(res.data); if (res.data && res.data.length > 0) { const newDoc = step.metadata?.doc_id ? res.data.find(d => d.id === step.metadata.doc_id) || res.data[0] : res.data[0]; usePipelineStore.getState().setSelectedDoc(newDoc); } }).catch(console.error); } }; return () => { if (ws.current) ws.current.close(); }; } }, [activeJob, isAuthenticated]); const handleAuth = async (e) => { e.preventDefault(); await login(username, password); }; if (!isAuthenticated) { return (
Enterprise A-to-Z RAG Ecosystem v3.0
DEFAULT CREDENTIALS: admin / admin123