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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import React, { useState, useEffect } from 'react';
|
| 3 |
+
import { Wrench, X, Bug, HardHat, CheckCircle2, Play, AlertTriangle } from 'lucide-react';
|
| 4 |
+
import { fixArchitectureErrors, AgentStatus } from '../services/geminiService';
|
| 5 |
+
import { Node, Edge } from 'reactflow';
|
| 6 |
+
import { NodeData } from '../types';
|
| 7 |
+
|
| 8 |
+
interface FixerModalProps {
|
| 9 |
+
isOpen: boolean;
|
| 10 |
+
onClose: () => void;
|
| 11 |
+
onApply: (nodes: any[], edges: any[]) => void;
|
| 12 |
+
errorMsg: string;
|
| 13 |
+
nodes: Node<NodeData>[];
|
| 14 |
+
edges: Edge[];
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
const FixerModal: React.FC<FixerModalProps> = ({ isOpen, onClose, onApply, errorMsg, nodes, edges }) => {
|
| 18 |
+
const [isFixing, setIsFixing] = useState(false);
|
| 19 |
+
const [agentStatus, setAgentStatus] = useState<AgentStatus>('idle');
|
| 20 |
+
const [agentMessage, setAgentMessage] = useState('');
|
| 21 |
+
const [error, setError] = useState<string | null>(null);
|
| 22 |
+
|
| 23 |
+
useEffect(() => {
|
| 24 |
+
if (isOpen) {
|
| 25 |
+
setAgentStatus('idle');
|
| 26 |
+
setAgentMessage('');
|
| 27 |
+
setError(null);
|
| 28 |
+
setIsFixing(false);
|
| 29 |
+
}
|
| 30 |
+
}, [isOpen]);
|
| 31 |
+
|
| 32 |
+
const handleStartFix = async () => {
|
| 33 |
+
setIsFixing(true);
|
| 34 |
+
setAgentStatus('debugger');
|
| 35 |
+
setAgentMessage('Initializing debugging protocols...');
|
| 36 |
+
|
| 37 |
+
try {
|
| 38 |
+
const result = await fixArchitectureErrors(nodes, edges, errorMsg, (status, msg) => {
|
| 39 |
+
setAgentStatus(status);
|
| 40 |
+
setAgentMessage(msg);
|
| 41 |
+
});
|
| 42 |
+
|
| 43 |
+
if (result && result.nodes && result.edges) {
|
| 44 |
+
// Post-process to ensure compatibility
|
| 45 |
+
const processedNodes = result.nodes.map((n: any) => ({
|
| 46 |
+
...n,
|
| 47 |
+
type: 'custom',
|
| 48 |
+
data: { ...n.data, label: n.data.label || n.data.type }
|
| 49 |
+
}));
|
| 50 |
+
const processedEdges = result.edges.map((e: any) => ({
|
| 51 |
+
...e, animated: true, style: { stroke: '#94a3b8' }
|
| 52 |
+
}));
|
| 53 |
+
|
| 54 |
+
setTimeout(() => {
|
| 55 |
+
onApply(processedNodes, processedEdges);
|
| 56 |
+
onClose();
|
| 57 |
+
}, 1000);
|
| 58 |
+
}
|
| 59 |
+
} catch (err) {
|
| 60 |
+
setError(err instanceof Error ? err.message : "Failed to fix architecture");
|
| 61 |
+
setAgentStatus('error');
|
| 62 |
+
setIsFixing(false);
|
| 63 |
+
}
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
const renderAgentStep = (step: AgentStatus, icon: React.ReactNode, label: string) => {
|
| 67 |
+
const order = ['idle', 'debugger', 'architect', 'patcher', 'complete'];
|
| 68 |
+
const stepIdx = order.indexOf(step);
|
| 69 |
+
const currentIdx = order.indexOf(agentStatus);
|
| 70 |
+
|
| 71 |
+
const isCurrent = agentStatus === step;
|
| 72 |
+
const isDone = currentIdx > stepIdx && agentStatus !== 'error';
|
| 73 |
+
const isPending = currentIdx < stepIdx;
|
| 74 |
+
|
| 75 |
+
let statusColor = 'text-slate-600';
|
| 76 |
+
if (isDone) statusColor = 'text-emerald-400';
|
| 77 |
+
if (isCurrent) statusColor = 'text-amber-400 animate-pulse';
|
| 78 |
+
if (agentStatus === 'error') statusColor = 'text-red-400';
|
| 79 |
+
|
| 80 |
+
return (
|
| 81 |
+
<div className={`flex items-center gap-3 p-3 rounded-lg border transition-all duration-300 ${isCurrent ? 'bg-slate-800 border-amber-500/30' : 'bg-slate-900 border-slate-800'}`}>
|
| 82 |
+
<div className={`${statusColor}`}>
|
| 83 |
+
{isDone ? <CheckCircle2 size={24} /> : icon}
|
| 84 |
+
</div>
|
| 85 |
+
<div className="flex-1">
|
| 86 |
+
<div className={`font-semibold text-sm ${isCurrent ? 'text-amber-200' : isDone ? 'text-emerald-200' : 'text-slate-400'}`}>
|
| 87 |
+
{label}
|
| 88 |
+
</div>
|
| 89 |
+
{isCurrent && (
|
| 90 |
+
<div className="text-xs text-slate-500 mt-1">{agentMessage}</div>
|
| 91 |
+
)}
|
| 92 |
+
</div>
|
| 93 |
+
{isCurrent && <div className="w-2 h-2 rounded-full bg-amber-400 animate-ping" />}
|
| 94 |
+
</div>
|
| 95 |
+
);
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
if (!isOpen) return null;
|
| 99 |
+
|
| 100 |
+
return (
|
| 101 |
+
<div className="absolute inset-0 z-50 flex items-center justify-center bg-black/80 backdrop-blur-sm p-4">
|
| 102 |
+
<div className="bg-slate-950 w-full max-w-lg rounded-xl border border-red-500/30 shadow-2xl flex flex-col overflow-hidden animate-in fade-in zoom-in duration-200">
|
| 103 |
+
|
| 104 |
+
<div className="flex items-center justify-between px-6 py-4 border-b border-slate-800 bg-gradient-to-r from-slate-900 to-slate-800">
|
| 105 |
+
<h2 className="text-lg font-bold text-white flex items-center gap-2">
|
| 106 |
+
<Wrench className="text-red-400" size={20} />
|
| 107 |
+
Auto-Fixer
|
| 108 |
+
</h2>
|
| 109 |
+
<button onClick={onClose} className="text-slate-400 hover:text-white transition-colors">
|
| 110 |
+
<X size={20} />
|
| 111 |
+
</button>
|
| 112 |
+
</div>
|
| 113 |
+
|
| 114 |
+
<div className="p-6 space-y-6">
|
| 115 |
+
{!isFixing && agentStatus !== 'complete' ? (
|
| 116 |
+
<>
|
| 117 |
+
<div className="bg-red-500/10 border border-red-500/20 rounded-lg p-4 flex gap-3 items-start">
|
| 118 |
+
<AlertTriangle className="text-red-400 shrink-0 mt-0.5" size={18} />
|
| 119 |
+
<div>
|
| 120 |
+
<h3 className="text-sm font-bold text-red-200 mb-1">Detected Issues</h3>
|
| 121 |
+
<p className="text-xs text-red-300/80 font-mono leading-relaxed max-h-32 overflow-y-auto">
|
| 122 |
+
{errorMsg}
|
| 123 |
+
</p>
|
| 124 |
+
</div>
|
| 125 |
+
</div>
|
| 126 |
+
|
| 127 |
+
<div className="text-sm text-slate-400">
|
| 128 |
+
Deploy AI debugging agents to analyze the graph structure and apply corrections automatically.
|
| 129 |
+
</div>
|
| 130 |
+
|
| 131 |
+
<div className="flex justify-end pt-2">
|
| 132 |
+
<button
|
| 133 |
+
onClick={handleStartFix}
|
| 134 |
+
className="flex items-center gap-2 px-6 py-2.5 rounded-lg font-medium text-white bg-red-600 hover:bg-red-500 transition-all shadow-lg shadow-red-900/20"
|
| 135 |
+
>
|
| 136 |
+
<Play size={18} fill="currentColor" />
|
| 137 |
+
Run Diagnostics & Fix
|
| 138 |
+
</button>
|
| 139 |
+
</div>
|
| 140 |
+
</>
|
| 141 |
+
) : (
|
| 142 |
+
<div className="space-y-3">
|
| 143 |
+
{renderAgentStep('debugger', <Bug size={24} />, "Debugger: Identifying Root Cause")}
|
| 144 |
+
{renderAgentStep('architect', <HardHat size={24} />, "Architect: Planning Structural Fix")}
|
| 145 |
+
{renderAgentStep('patcher', <Wrench size={24} />, "Patcher: Applying Fixes to Graph")}
|
| 146 |
+
|
| 147 |
+
{agentStatus === 'complete' && (
|
| 148 |
+
<div className="text-center text-emerald-400 font-bold mt-6 animate-pulse">
|
| 149 |
+
Fixes Applied Successfully!
|
| 150 |
+
</div>
|
| 151 |
+
)}
|
| 152 |
+
{agentStatus === 'error' && (
|
| 153 |
+
<div className="text-center text-red-400 font-bold mt-6">
|
| 154 |
+
{error || "An error occurred during fixing."}
|
| 155 |
+
</div>
|
| 156 |
+
)}
|
| 157 |
+
</div>
|
| 158 |
+
)}
|
| 159 |
+
</div>
|
| 160 |
+
</div>
|
| 161 |
+
</div>
|
| 162 |
+
);
|
| 163 |
+
};
|
| 164 |
+
|
| 165 |
+
export default FixerModal;
|