import React, { useState, useEffect } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { Box, Typography, Card, CardContent, LinearProgress, Button, Alert, Stepper, Step, StepLabel, StepContent, CircularProgress, } from '@mui/material'; import { Check as CheckIcon, Error as ErrorIcon, Refresh as RefreshIcon, } from '@mui/icons-material'; import client from '../api/client'; // Compilation steps const COMPILATION_STEPS = [ { label: 'Initializing', description: 'Setting up agent environment' }, { label: 'Analyzing Prompt', description: 'Extracting domain and configuration' }, { label: 'Compiling Knowledge', description: 'Building knowledge base' }, { label: 'Generating Embeddings', description: 'Creating vector store' }, { label: 'Finalizing', description: 'Saving agent artifacts' }, ]; function CompilationProgress() { const { agentName } = useParams(); const navigate = useNavigate(); const [status, setStatus] = useState({ status: 'starting', percentage: 0, current_step: 'Initializing...', error: null, }); const [activeStep, setActiveStep] = useState(0); useEffect(() => { const pollStatus = async () => { try { // Use Phase 2 API const response = await client.get(`/api/compile/${agentName}/status`); const data = response.data; // Map to expected format const mappedStatus = { status: data.agent_status === 'ready' ? 'complete' : data.agent_status === 'failed' ? 'error' : 'processing', percentage: data.job?.progress || 0, current_step: data.job?.current_step || 'Processing...', error: data.job?.error_message, stats: null }; setStatus(mappedStatus); // Update active step based on percentage if (mappedStatus.percentage < 20) setActiveStep(0); else if (mappedStatus.percentage < 40) setActiveStep(1); else if (mappedStatus.percentage < 60) setActiveStep(2); else if (mappedStatus.percentage < 90) setActiveStep(3); else setActiveStep(4); // Continue polling if not complete if (mappedStatus.status !== 'complete' && mappedStatus.status !== 'error') { setTimeout(pollStatus, 2000); } } catch (err) { console.error('Failed to get status:', err); // Fallback to Phase 1 API try { const fallbackResponse = await client.get(`/api/compile-status/${agentName}`); setStatus(fallbackResponse.data); } catch { setStatus({ status: 'error', percentage: 0, current_step: 'Failed to get status', error: err.message, }); } } }; pollStatus(); }, [agentName]); const getStatusColor = () => { switch (status.status) { case 'complete': return 'success'; case 'error': return 'error'; default: return 'primary'; } }; const handleContinue = () => { navigate(`/ready/${agentName}`); }; const handleRetry = () => { navigate('/create'); }; return ( {/* Header */} {status.status === 'complete' ? '🎉 Agent Ready!' : status.status === 'error' ? '❌ Compilation Failed' : '⚙️ Compiling Agent'} MEXAR ULTIMATE | {agentName.replace(/_/g, ' ').toUpperCase()} {/* Progress Card */} {/* Progress Bar */} {status.current_step} {status.percentage}% {/* Status Steps */} {COMPILATION_STEPS.map((step, index) => ( {step.description} } StepIconComponent={() => { if (status.status === 'error' && index === activeStep) { return ; } if (index < activeStep || status.status === 'complete') { return ; } if (index === activeStep) { return ; } return ( {index + 1} ); }} > {step.label} {index === activeStep && status.status !== 'complete' && status.status !== 'error' && ( Processing... )} ))} {/* Error Message */} {status.status === 'error' && ( Compilation Error {status.error || 'An unexpected error occurred during compilation.'} )} {/* Statistics Preview (when complete) */} {status.status === 'complete' && status.stats && ( 📊 Compilation Statistics {status.stats.nodes_count} Knowledge Nodes {status.stats.edges_count} Relationships Ready Status )} {/* Action Buttons */} {status.status === 'complete' && ( )} {status.status === 'error' && ( <> )} {status.status === 'processing' && ( )} {/* Tips while waiting */} {status.status !== 'complete' && status.status !== 'error' && ( 💡 Did you know? MEXAR uses a high-performance Vector Database architecture. The semantic search context enables fast responses, while the retrieval mechanism provides explainable reasoning paths for every answer. )} ); } export default CompilationProgress;