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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState, useEffect, useRef } from 'react';
|
| 2 |
+
import Editor from '@monaco-editor/react';
|
| 3 |
+
import { Bot, Terminal, Code, Play, FileCode, Plus, Settings, Activity, Zap, Cpu } from 'lucide-react';
|
| 4 |
+
|
| 5 |
+
export default function AgentWorkspace() {
|
| 6 |
+
const [files, setFiles] = useState([
|
| 7 |
+
{ name: 'main.py', language: 'python', content: '# Welcome to the Autonomous Agent Workspace\n# Initialize your multi-agent system below\n\nimport os\nimport json\nfrom core.agent import Agent\n\ndef main():\n print("System Online...")\n \nif __name__ == "__main__":\n main()' },
|
| 8 |
+
{ name: 'config.json', language: 'json', content: '{\n "model": "gpt-4",\n "temperature": 0.7,\n "max_tokens": 2048\n}' },
|
| 9 |
+
{ name: 'styles.css', language: 'css', content: '.container {\n display: flex;\n justify-content: center;\n align-items: center;\n height: 100vh;\n}' }
|
| 10 |
+
]);
|
| 11 |
+
|
| 12 |
+
const [activeFile, setActiveFile] = useState(files[0]);
|
| 13 |
+
const [logs, setLogs] = useState([]);
|
| 14 |
+
const [isProcessing, setIsProcessing] = useState(false);
|
| 15 |
+
const endOfLogsRef = useRef(null);
|
| 16 |
+
|
| 17 |
+
const scrollToBottom = () => {
|
| 18 |
+
endOfLogsRef.current?.scrollIntoView({ behavior: "smooth" });
|
| 19 |
+
};
|
| 20 |
+
|
| 21 |
+
useEffect(() => {
|
| 22 |
+
scrollToBottom();
|
| 23 |
+
}, [logs]);
|
| 24 |
+
|
| 25 |
+
const addLog = (agent, message, type = 'info') => {
|
| 26 |
+
const timestamp = new Date().toLocaleTimeString('en-US', { hour12: false, hour: "numeric", minute: "numeric", second: "numeric" });
|
| 27 |
+
const colors = {
|
| 28 |
+
'Architect': 'text-purple-400',
|
| 29 |
+
'Coder': 'text-cyan-400',
|
| 30 |
+
'Reviewer': 'text-emerald-400',
|
| 31 |
+
'System': 'text-yellow-400'
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
setLogs(prev => [...prev, {
|
| 35 |
+
id: Date.now() + Math.random(),
|
| 36 |
+
agent,
|
| 37 |
+
message,
|
| 38 |
+
type,
|
| 39 |
+
timestamp,
|
| 40 |
+
color: colors[agent] || 'text-slate-300'
|
| 41 |
+
}]);
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
const handleEditorChange = (value) => {
|
| 45 |
+
const updatedFiles = files.map(f =>
|
| 46 |
+
f.name === activeFile.name ? { ...f, content: value } : f
|
| 47 |
+
);
|
| 48 |
+
setFiles(updatedFiles);
|
| 49 |
+
setActiveFile({ ...activeFile, content: value });
|
| 50 |
+
};
|
| 51 |
+
|
| 52 |
+
const simulateCollaboration = async () => {
|
| 53 |
+
setIsProcessing(true);
|
| 54 |
+
setLogs([]);
|
| 55 |
+
|
| 56 |
+
// Step 1: System Start
|
| 57 |
+
addLog('System', 'Initializing autonomous agent swarm...', 'system');
|
| 58 |
+
await new Promise(r => setTimeout(r, 800));
|
| 59 |
+
|
| 60 |
+
// Step 2: Architect Agent
|
| 61 |
+
addLog('Architect', 'Analyzing project structure requirements.', 'info');
|
| 62 |
+
await new Promise(r => setTimeout(r, 1500));
|
| 63 |
+
addLog('Architect', 'Proposing modular architecture for scalability.', 'success');
|
| 64 |
+
|
| 65 |
+
// Update main.py
|
| 66 |
+
const newPythonContent = `# Autonomous Agent System - Generated by Agents
|
| 67 |
+
import os
|
| 68 |
+
import json
|
| 69 |
+
from core.agent import Agent
|
| 70 |
+
from core.task_manager import TaskManager
|
| 71 |
+
|
| 72 |
+
class AgentSwarm:
|
| 73 |
+
def __init__(self, config):
|
| 74 |
+
self.agents = []
|
| 75 |
+
self.config = config
|
| 76 |
+
self.initialize_agents()
|
| 77 |
+
|
| 78 |
+
def initialize_agents(self):
|
| 79 |
+
"""Initialize specialized agents for different tasks"""
|
| 80 |
+
print(f"Initializing {self.config.get('swarm_size', 3)} agents...")
|
| 81 |
+
|
| 82 |
+
def execute_task(self, task):
|
| 83 |
+
"""Distribute task to most suitable agent"""
|
| 84 |
+
print(f"Executing: {task}")
|
| 85 |
+
return {"status": "completed", "result": "Success"}
|
| 86 |
+
|
| 87 |
+
def main():
|
| 88 |
+
config = {"swarm_size": 5, "mode": "collaborative"}
|
| 89 |
+
swarm = AgentSwarm(config)
|
| 90 |
+
swarm.execute_task("System Optimization")
|
| 91 |
+
|
| 92 |
+
if __name__ == "__main__":
|
| 93 |
+
main()`;
|
| 94 |
+
|
| 95 |
+
setFiles(prev => prev.map(f => f.name === 'main.py' ? { ...f, content: newPythonContent } : f));
|
| 96 |
+
if(activeFile.name === 'main.py') setActiveFile({ ...activeFile, content: newPythonContent });
|
| 97 |
+
await new Promise(r => setTimeout(r, 1000));
|
| 98 |
+
|
| 99 |
+
// Step 3: Coder Agent
|
| 100 |
+
addLog('Coder', 'Refining implementation in main.py.', 'info');
|
| 101 |
+
await new Promise(r => setTimeout(r, 1200));
|
| 102 |
+
addLog('Coder', 'Adding error handling and async support.', 'warning');
|
| 103 |
+
|
| 104 |
+
// Create new file
|
| 105 |
+
const newFile = {
|
| 106 |
+
name: 'utils.js',
|
| 107 |
+
language: 'javascript',
|
| 108 |
+
content: '// Utility functions for the Agent Swarm\n\nexport const debounce = (func, wait) => {\n let timeout;\n return function executedFunction(...args) {\n const later = () => {\n clearTimeout(timeout);\n func(...args);\n };\n clearTimeout(timeout);\n timeout = setTimeout(later, wait);\n };\n};\n\nexport const generateId = () => {\n return Math.random().toString(36).substr(2, 9);\n};'
|
| 109 |
+
};
|
| 110 |
+
|
| 111 |
+
setFiles(prev => [...prev, newFile]);
|
| 112 |
+
addLog('Coder', 'Created new module: utils.js', 'success');
|
| 113 |
+
await new Promise(r => setTimeout(r, 1000));
|
| 114 |
+
|
| 115 |
+
// Step 4: Reviewer Agent
|
| 116 |
+
addLog('Reviewer', 'Scanning code for vulnerabilities...', 'info');
|
| 117 |
+
await new Promise(r => setTimeout(r, 1500));
|
| 118 |
+
addLog('Reviewer', 'Linting passed. No critical issues found.', 'success');
|
| 119 |
+
addLog('Reviewer', 'Optimizing import statements.', 'warning');
|
| 120 |
+
|
| 121 |
+
// Step 5: Finalize
|
| 122 |
+
addLog('System', 'Swarm collaboration complete. Project updated.', 'system');
|
| 123 |
+
setIsProcessing(false);
|
| 124 |
+
};
|
| 125 |
+
|
| 126 |
+
return (
|
| 127 |
+
<div className="flex flex-col h-[700px] bg-slate-900 rounded-xl border border-slate-700 shadow-2xl overflow-hidden">
|
| 128 |
+
{/* Toolbar */}
|
| 129 |
+
<div className="h-12 bg-slate-800 border-b border-slate-700 flex items-center justify-between px-4">
|
| 130 |
+
<div className="flex items-center gap-4">
|
| 131 |
+
<div className="flex items-center gap-2 text-slate-300">
|
| 132 |
+
<Cpu className="w-4 h-4 text-indigo-400" />
|
| 133 |
+
<span className="font-semibold text-sm">Agent Workspace</span>
|
| 134 |
+
</div>
|
| 135 |
+
<div className="h-4 w-px bg-slate-600"></div>
|
| 136 |
+
<div className="flex items-center gap-2">
|
| 137 |
+
{files.map((file) => (
|
| 138 |
+
<button
|
| 139 |
+
key={file.name}
|
| 140 |
+
onClick={() => setActiveFile(file)}
|
| 141 |
+
className={`flex items-center gap-1.5 px-3 py-1 rounded-md text-xs font-medium transition-all ${
|
| 142 |
+
activeFile.name === file.name
|
| 143 |
+
? 'bg-indigo-600 text-white shadow-md'
|
| 144 |
+
: 'text-slate-400 hover:text-white hover:bg-slate-700'
|
| 145 |
+
}`}
|
| 146 |
+
>
|
| 147 |
+
<FileCode className="w-3.5 h-3.5" />
|
| 148 |
+
{file.name}
|
| 149 |
+
</button>
|
| 150 |
+
))}
|
| 151 |
+
<button className="text-slate-500 hover:text-white p-1 rounded hover:bg-slate-700 transition-colors">
|
| 152 |
+
<Plus className="w-4 h-4" />
|
| 153 |
+
</button>
|
| 154 |
+
</div>
|
| 155 |
+
</div>
|
| 156 |
+
|
| 157 |
+
<button
|
| 158 |
+
onClick={simulateCollaboration}
|
| 159 |
+
disabled={isProcessing}
|
| 160 |
+
className={`flex items-center gap-2 px-4 py-1.5 rounded-md text-sm font-medium transition-all ${
|
| 161 |
+
isProcessing
|
| 162 |
+
? 'bg-slate-700 text-slate-400 cursor-not-allowed'
|
| 163 |
+
: 'bg-gradient-to-r from-indigo-600 to-purple-600 hover:from-indigo-500 hover:to-purple-500 text-white shadow-lg shadow-indigo-900/30'
|
| 164 |
+
}`}
|
| 165 |
+
>
|
| 166 |
+
{isProcessing ? (
|
| 167 |
+
<>
|
| 168 |
+
<Activity className="w-4 h-4 animate-pulse" />
|
| 169 |
+
Agents Working...
|
| 170 |
+
</>
|
| 171 |
+
) : (
|
| 172 |
+
<>
|
| 173 |
+
<Zap className="w-4 h-4" />
|
| 174 |
+
Deploy Agents
|
| 175 |
+
</>
|
| 176 |
+
)}
|
| 177 |
+
</button>
|
| 178 |
+
</div>
|
| 179 |
+
|
| 180 |
+
{/* Main Content Area */}
|
| 181 |
+
<div className="flex flex-1 overflow-hidden">
|
| 182 |
+
{/* Left: Agent Stream */}
|
| 183 |
+
<div className="w-80 bg-slate-950 border-r border-slate-800 flex flex-col">
|
| 184 |
+
<div className="p-3 border-b border-slate-800 flex items-center justify-between">
|
| 185 |
+
<div className="flex items-center gap-2 text-xs font-semibold text-slate-400 uppercase tracking-wider">
|
| 186 |
+
<Terminal className="w-3.5 h-3.5" />
|
| 187 |
+
Agent Stream
|
| 188 |
+
</div>
|
| 189 |
+
<div className={`flex items-center gap-1.5 px-2 py-0.5 rounded-full text-[10px] font-medium ${
|
| 190 |
+
isProcessing ? 'bg-emerald-900/50 text-emerald-400' : 'bg-slate-800 text-slate-500'
|
| 191 |
+
}`}>
|
| 192 |
+
<span className={`w-1.5 h-1.5 rounded-full ${isProcessing ? 'bg-emerald-400 animate-pulse' : 'bg-slate-600'}`}></span>
|
| 193 |
+
{isProcessing ? 'Live' : 'Idle'}
|
| 194 |
+
</div>
|
| 195 |
+
</div>
|
| 196 |
+
|
| 197 |
+
<div className="flex-1 overflow-y-auto p-3 space-y-3">
|
| 198 |
+
{logs.length === 0 && !isProcessing && (
|
| 199 |
+
<div className="h-full flex flex-col items-center justify-center text-slate-600 space-y-3">
|
| 200 |
+
<Bot className="w-10 h-10 opacity-20" />
|
| 201 |
+
<p className="text-xs text-center px-4">Deploy agents to start collaborative coding session.</p>
|
| 202 |
+
</div>
|
| 203 |
+
)}
|
| 204 |
+
|
| 205 |
+
{logs.map((log) => (
|
| 206 |
+
<div key={log.id} className="flex gap-2 text-sm animate-in fade-in slide-in-from-bottom-2 duration-300">
|
| 207 |
+
<div className="flex-shrink-0 w-16 text-right">
|
| 208 |
+
<span className={`text-xs font-mono ${log.color} font-medium`}>{log.agent}</span>
|
| 209 |
+
</div>
|
| 210 |
+
<div className="flex-1">
|
| 211 |
+
<div className="bg-slate-900 p-2 rounded-lg border border-slate-800/50">
|
| 212 |
+
<p className="text-slate-300 text-xs leading-relaxed">{log.message}</p>
|
| 213 |
+
</div>
|
| 214 |
+
<span className="text-[10px] text-slate-600 font-mono ml-1">{log.timestamp}</span>
|
| 215 |
+
</div>
|
| 216 |
+
</div>
|
| 217 |
+
))}
|
| 218 |
+
<div ref={endOfLogsRef} />
|
| 219 |
+
</div>
|
| 220 |
+
</div>
|
| 221 |
+
|
| 222 |
+
{/* Right: Monaco Editor */}
|
| 223 |
+
<div className="flex-1 flex flex-col bg-[#1e1e1e]">
|
| 224 |
+
<div className="bg-[#252526] h-8 flex items-center px-4 border-b border-black">
|
| 225 |
+
<span className="text-xs text-slate-400 font-mono flex items-center gap-2">
|
| 226 |
+
<Code className="w-3 h-3" />
|
| 227 |
+
{activeFile.name}
|
| 228 |
+
</span>
|
| 229 |
+
</div>
|
| 230 |
+
<div className="flex-1 relative">
|
| 231 |
+
<Editor
|
| 232 |
+
height="100%"
|
| 233 |
+
language={activeFile.language}
|
| 234 |
+
theme="vs-dark"
|
| 235 |
+
value={activeFile.content}
|
| 236 |
+
onChange={handleEditorChange}
|
| 237 |
+
options={{
|
| 238 |
+
minimap: { enabled: false },
|
| 239 |
+
fontSize: 14,
|
| 240 |
+
lineNumbers: 'on',
|
| 241 |
+
roundedSelection: false,
|
| 242 |
+
scrollBeyondLastLine: false,
|
| 243 |
+
automaticLayout: true,
|
| 244 |
+
tabSize: 2,
|
| 245 |
+
wordWrap: 'on',
|
| 246 |
+
padding: { top: 16 }
|
| 247 |
+
|
| 248 |
+
/>
|
| 249 |
+
</div>
|
| 250 |
+
</div>
|
| 251 |
+
</div>
|
| 252 |
+
</div>
|
| 253 |
+
);
|
| 254 |
+
}
|