import React, { useState, useEffect } from 'react'; import { Wrench, X, Bug, HardHat, CheckCircle2, Play, AlertTriangle } from 'lucide-react'; import { fixArchitectureErrors, AgentStatus } from '../services/geminiService'; import { Node, Edge } from 'reactflow'; import { NodeData } from '../types'; interface FixerModalProps { isOpen: boolean; onClose: () => void; onApply: (nodes: any[], edges: any[], logMsg?: string) => void; errorMsg: string; nodes: Node[]; edges: Edge[]; } const FixerModal: React.FC = ({ isOpen, onClose, onApply, errorMsg, nodes, edges }) => { const [isFixing, setIsFixing] = useState(false); const [agentStatus, setAgentStatus] = useState('idle'); const [agentMessage, setAgentMessage] = useState(''); const [error, setError] = useState(null); useEffect(() => { if (isOpen) { setAgentStatus('idle'); setAgentMessage(''); setError(null); setIsFixing(false); } }, [isOpen]); const handleStartFix = async () => { setIsFixing(true); setAgentStatus('debugger'); setAgentMessage('Initializing debugging protocols...'); try { const result = await fixArchitectureErrors(nodes, edges, errorMsg, (status, msg) => { setAgentStatus(status); setAgentMessage(msg); }); if (result && result.nodes && result.edges) { // Post-process to ensure compatibility and safe access const processedNodes = result.nodes.map((n: any) => { const data = n.data || {}; const type = data.type || n.type || 'Identity'; // Fallback return { ...n, type: 'custom', data: { ...data, type: type, label: data.label || n.label || type, // Safe access params: data.params || {} } }; }); const processedEdges = result.edges.map((e: any) => ({ ...e, animated: true, style: { stroke: '#94a3b8' } })); setTimeout(() => { onApply(processedNodes, processedEdges, "Auto-Fixer agents applied corrections."); onClose(); }, 1000); } } catch (err) { setError(err instanceof Error ? err.message : "Failed to fix architecture"); setAgentStatus('error'); setIsFixing(false); } }; const renderAgentStep = (step: AgentStatus, icon: React.ReactNode, label: string) => { const order = ['idle', 'debugger', 'architect', 'patcher', 'complete']; const stepIdx = order.indexOf(step); const currentIdx = order.indexOf(agentStatus); const isCurrent = agentStatus === step; const isDone = currentIdx > stepIdx && agentStatus !== 'error'; const isPending = currentIdx < stepIdx; let statusColor = 'text-slate-600'; if (isDone) statusColor = 'text-emerald-400'; if (isCurrent) statusColor = 'text-amber-400 animate-pulse'; if (agentStatus === 'error') statusColor = 'text-red-400'; return (
{isDone ? : icon}
{label}
{isCurrent && (
{agentMessage}
)}
{isCurrent &&
}
); } if (!isOpen) return null; return (

Auto-Fixer

{!isFixing && agentStatus !== 'complete' ? ( <>

Detected Issues

{errorMsg}

Deploy AI debugging agents to analyze the graph structure and apply corrections automatically.
) : (
{renderAgentStep('debugger', , "Debugger: Identifying Root Cause")} {renderAgentStep('architect', , "Architect: Planning Structural Fix")} {renderAgentStep('patcher', , "Patcher: Applying Fixes to Graph")} {agentStatus === 'complete' && (
Fixes Applied Successfully!
)} {agentStatus === 'error' && (
{error || "An error occurred during fixing."}
)}
)}
); }; export default FixerModal;