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useEffect } from 'react'
|
| 2 |
+
import { motion, AnimatePresence } from 'framer-motion'
|
| 3 |
+
import {
|
| 4 |
+
FaRobot, FaBrain, FaCode, FaDatabase, FaCloud, FaShieldAlt,
|
| 5 |
+
FaChartLine, FaProjectDiagram, FaBug, FaFileCode, FaGitAlt,
|
| 6 |
+
FaDocker, FaServer, FaMobile, FaPalette, FaGlobe, FaLock,
|
| 7 |
+
FaNetworkWired, FaMemory, FaMicrochip, FaCogs, FaRocket,
|
| 8 |
+
FaTerminal, FaBook, FaGraduationCap, FaLightbulb, FaMagic,
|
| 9 |
+
FaTools, FaRegClock, FaSearch, FaFilter, FaDownload, FaUpload,
|
| 10 |
+
FaSave, FaTrash, FaEdit, FaCopy, FaPaste, FaUndo, FaRedo,
|
| 11 |
+
FaPlay, FaStop, FaPause, FaStepForward, FaStepBackward,
|
| 12 |
+
FaExpand, FaCompress, FaFullscreen, FaRegWindowMaximize,
|
| 13 |
+
FaRegWindowMinimize, FaWindowClose, FaRegWindowRestore,
|
| 14 |
+
FaDesktop, FaLaptop, FaTablet, FaMobileAlt, FaTv,
|
| 15 |
+
FaGamepad, FaHeadphones, FaMicrophone, FaVideo, FaCamera,
|
| 16 |
+
FaImage, FaFilm, FaMusic, FaPodcast, FaBroadcastTower,
|
| 17 |
+
FaSatellite, FaWifi, FaEthernet, FaUsb, FaBluetooth,
|
| 18 |
+
FaSimCard, FaSdCard, FaHdd, FaCompactDisc, FaPrint,
|
| 19 |
+
FaScanner, FaKeyboard, FaMouse, FaGamepadAlt, FaJoystick,
|
| 20 |
+
FaVrCardboard, FaGlasses, FaWatch, FaClock, FaStopwatch
|
| 21 |
+
} from 'react-icons/fa'
|
| 22 |
+
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
|
| 23 |
+
import { vscDarkPlus } from 'react-syntax-highlighter/dist/cjs/styles/prism'
|
| 24 |
+
import toast from 'react-hot-toast'
|
| 25 |
+
|
| 26 |
+
export default function AIAgent({ language, theme }) {
|
| 27 |
+
const [activeModel, setActiveModel] = useState('code-assistant')
|
| 28 |
+
const [messages, setMessages] = useState([])
|
| 29 |
+
const [input, setInput] = useState('')
|
| 30 |
+
const [isProcessing, setIsProcessing] = useState(false)
|
| 31 |
+
const [selectedCapability, setSelectedCapability] = useState('code-generation')
|
| 32 |
+
const [context, setContext] = useState({})
|
| 33 |
+
const [models] = useState([
|
| 34 |
+
{ id: 'code-assistant', name: 'Code Assistant', icon: FaCode, description: 'Full-stack programming assistant' },
|
| 35 |
+
{ id: 'database-expert', name: 'Database Expert', icon: FaDatabase, description: 'Database design and optimization' },
|
| 36 |
+
{ id: 'cloud-architect', name: 'Cloud Architect', icon: FaCloud, description: 'Cloud infrastructure and deployment' },
|
| 37 |
+
{ id: 'security-specialist', name: 'Security Specialist', icon: FaShieldAlt, description: 'Security analysis and protection' },
|
| 38 |
+
{ id: 'performance-analyst', name: 'Performance Analyst', icon: FaChartLine, description: 'Performance optimization' },
|
| 39 |
+
{ id: 'project-manager', name: 'Project Manager', icon: FaProjectDiagram, description: 'Project planning and management' },
|
| 40 |
+
{ id: 'debugger', name: 'Bug Hunter', icon: FaBug, description: 'Debug and fix issues' },
|
| 41 |
+
{ id: 'documentation', name: 'Documentation', icon: FaBook, description: 'Generate documentation' },
|
| 42 |
+
{ id: 'testing', name: 'Testing Expert', icon: FaVrCardboard, description: 'Automated testing' },
|
| 43 |
+
{ id: 'deployment', name: 'Deployment', icon: FaRocket, description: 'CI/CD and deployment' }
|
| 44 |
+
])
|
| 45 |
+
|
| 46 |
+
const capabilities = [
|
| 47 |
+
{ id: 'code-generation', name: 'Code Generation', icon: FaCode },
|
| 48 |
+
{ id: 'code-review', name: 'Code Review', icon: FaSearch },
|
| 49 |
+
{ id: 'refactoring', name: 'Refactoring', icon: FaEdit },
|
| 50 |
+
{ id: 'optimization', name: 'Optimization', icon: FaRocket },
|
| 51 |
+
{ id: 'debugging', name: 'Debugging', icon: FaBug },
|
| 52 |
+
{ id: 'testing', name: 'Testing', icon: FaFlask },
|
| 53 |
+
{ id: 'documentation', name: 'Documentation', icon: FaBook },
|
| 54 |
+
{ id: 'architecture', name: 'Architecture', icon: FaProjectDiagram },
|
| 55 |
+
{ id: 'security', name: 'Security', icon: FaShieldAlt },
|
| 56 |
+
{ id: 'performance', name: 'Performance', icon: FaChartLine },
|
| 57 |
+
{ id: 'database', name: 'Database', icon: FaDatabase },
|
| 58 |
+
{ id: 'api', name: 'API Design', icon: FaNetworkWired },
|
| 59 |
+
{ id: 'ui-ux', name: 'UI/UX', icon: FaPalette },
|
| 60 |
+
{ id: 'mobile', name: 'Mobile Dev', icon: FaMobile },
|
| 61 |
+
{ id: 'web', name: 'Web Dev', icon: FaGlobe },
|
| 62 |
+
{ id: 'devops', name: 'DevOps', icon: FaServer },
|
| 63 |
+
{ id: 'ml', name: 'Machine Learning', icon: FaBrain },
|
| 64 |
+
{ id: 'blockchain', name: 'Blockchain', icon: FaLink },
|
| 65 |
+
{ id: 'iot', name: 'IoT', icon: FaWifi },
|
| 66 |
+
{ id: 'gaming', name: 'Game Dev', icon: FaGamepad }
|
| 67 |
+
]
|
| 68 |
+
|
| 69 |
+
const handleSendMessage = async () => {
|
| 70 |
+
if (!input.trim()) return
|
| 71 |
+
|
| 72 |
+
const userMessage = {
|
| 73 |
+
id: Date.now(),
|
| 74 |
+
type: 'user',
|
| 75 |
+
content: input,
|
| 76 |
+
capability: selectedCapability,
|
| 77 |
+
model: activeModel,
|
| 78 |
+
timestamp: new Date()
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
setMessages(prev => [...prev, userMessage])
|
| 82 |
+
setInput('')
|
| 83 |
+
setIsProcessing(true)
|
| 84 |
+
|
| 85 |
+
try {
|
| 86 |
+
// Simulate AI processing
|
| 87 |
+
await new Promise(resolve => setTimeout(resolve, 2000))
|
| 88 |
+
|
| 89 |
+
const aiResponse = await generateAIResponse(input, selectedCapability, activeModel)
|
| 90 |
+
|
| 91 |
+
const assistantMessage = {
|
| 92 |
+
id: Date.now() + 1,
|
| 93 |
+
type: 'assistant',
|
| 94 |
+
content: aiResponse,
|
| 95 |
+
capability: selectedCapability,
|
| 96 |
+
model: activeModel,
|
| 97 |
+
timestamp: new Date()
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
setMessages(prev => [...prev, assistantMessage])
|
| 101 |
+
} catch (error) {
|
| 102 |
+
toast.error(language === 'fa' ? 'خطا در پردازش درخواست' : 'Error processing request')
|
| 103 |
+
} finally {
|
| 104 |
+
setIsProcessing(false)
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
const generateAIResponse = async (prompt, capability, model) => {
|
| 109 |
+
const responses = {
|
| 110 |
+
'code-generation': `// Generated code for: ${prompt}\nfunction generateSolution() {\n // AI-generated implementation\n return "Solution generated by ${model}";\n}`,
|
| 111 |
+
'code-review': `Code Review Results:\n✓ Code follows best practices\n✓ No security vulnerabilities detected\n⚠ Consider optimizing performance\n✓ Documentation is complete`,
|
| 112 |
+
'refactoring': `Refactored Code:\n// Improved version with better structure\nclass RefactoredSolution {\n constructor() {\n this.optimized = true;\n }\n}`,
|
| 113 |
+
'debugging': `Debug Analysis:\n🐛 Issue identified in line 42\n🔧 Suggested fix: Initialize variable before use\n✅ Solution implemented successfully`,
|
| 114 |
+
'testing': `Test Coverage Report:\n✓ Unit tests: 95%\n✓ Integration tests: 88%\n✓ E2E tests: 92%\n📊 Overall coverage: 92%`,
|
| 115 |
+
'documentation': `Generated Documentation:\n# API Documentation\n\n## Overview\nThis module provides...\n\n## Installation\n\`\`\`bash\nnpm install package\n\`\`\`\n\n## Usage\n\`\`\`javascript\nimport { module } from 'package';\n\`\`\``,
|
| 116 |
+
'architecture': `Architecture Recommendation:\n🏗️ Pattern: Microservices\n📊 Scalability: High\n🔒 Security: Enterprise grade\n⚡ Performance: Optimized`,
|
| 117 |
+
'security': `Security Analysis:\n🔒 SSL/TLS: Configured\n🛡️ Firewall: Active\n🔐 Authentication: OAuth 2.0\n✅ No vulnerabilities found`,
|
| 118 |
+
'performance': `Performance Metrics:\n⚡ Response time: 45ms\n💾 Memory usage: 128MB\n📈 Throughput: 1000 req/s\n🎯 Score: 95/100`,
|
| 119 |
+
'database': `Database Schema:\n📊 Tables: Optimized\n🔍 Indexes: Properly configured\n⚡ Queries: Optimized\n💾 Storage: Efficient`,
|
| 120 |
+
'api': `API Design:\n🌐 RESTful: Yes\n📝 Documentation: Complete\n🔒 Security: JWT auth\n⚡ Performance: High`,
|
| 121 |
+
'ui-ux': `UI/UX Recommendations:\n🎨 Design: Modern\n📱 Responsive: Yes\n♿ Accessible: WCAG 2.1\n⚡ Performance: Optimized`,
|
| 122 |
+
'mobile': `Mobile Solution:\n📱 Platform: Cross-platform\n⚡ Performance: Native-like\n🔋 Battery: Optimized\n📦 Size: Minimal`,
|
| 123 |
+
'web': `Web Solution:\n🌐 Framework: Next.js\n⚡ Performance: Optimized\n🔒 Security: HTTPS\n📱 Responsive: Yes`,
|
| 124 |
+
'devops': `DevOps Pipeline:\n🚀 CI/CD: Automated\n🐳 Docker: Containerized\n☁️ Cloud: AWS\n📊 Monitoring: Enabled`,
|
| 125 |
+
'ml': `ML Solution:\n🧠 Model: Neural Network\n📊 Accuracy: 98%\n⚡ Training: Optimized\n🔮 Prediction: Real-time`,
|
| 126 |
+
'blockchain': `Blockchain Solution:\n⛓️ Network: Ethereum\n🔐 Smart Contract: Audited\n⚡ Gas: Optimized\n🔒 Security: High`,
|
| 127 |
+
'iot': `IoT Solution:\n📡 Devices: Connected\n🔌 Protocol: MQTT\n⚡ Real-time: Yes\n🔒 Security: Encrypted`,
|
| 128 |
+
'gaming': `Game Development:\n🎮 Engine: Unity\n⚡ Performance: 60 FPS\n🎨 Graphics: 4K\n🎯 Gameplay: Smooth`
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
return responses[capability] || `AI Response from ${model} for: ${prompt}`
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
const exportConversation = () => {
|
| 135 |
+
const data = JSON.stringify(messages, null, 2)
|
| 136 |
+
const blob = new Blob([data], { type: 'application/json' })
|
| 137 |
+
const url = URL.createObjectURL(blob)
|
| 138 |
+
const a = document.createElement('a')
|
| 139 |
+
a.href = url
|
| 140 |
+
a.download = 'ai-conversation.json'
|
| 141 |
+
a.click()
|
| 142 |
+
toast.success(language === 'fa' ? 'گفتگو export شد' : 'Conversation exported')
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
const clearConversation = () => {
|
| 146 |
+
setMessages([])
|
| 147 |
+
toast.success(language === 'fa' ? 'گفتگو پاک شد' : 'Conversation cleared')
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
return (
|
| 151 |
+
<div className="flex flex-col h-full space-y-4">
|
| 152 |
+
{/* Header */}
|
| 153 |
+
<div className="flex items-center justify-between p-4 bg-gray-800 rounded-lg">
|
| 154 |
+
<div className="flex items-center space-x-reverse space-x-3">
|
| 155 |
+
<FaRobot className="w-6 h-6 text-primary-400" />
|
| 156 |
+
<h2 className="text-lg font-semibold">AI Agent Studio</h2>
|
| 157 |
+
</div>
|
| 158 |
+
<div className="flex items-center space-x-reverse space-x-2">
|
| 159 |
+
<button
|
| 160 |
+
onClick={exportConversation}
|
| 161 |
+
className="px-3 py-1 bg-gray-700 text-white rounded-lg hover:bg-gray-600 transition-all text-sm"
|
| 162 |
+
>
|
| 163 |
+
<FaDownload className="w-4 h-4 inline ml-2" />
|
| 164 |
+
{language === 'fa' ? 'export' : 'Export'}
|
| 165 |
+
</button>
|
| 166 |
+
<button
|
| 167 |
+
onClick={clearConversation}
|
| 168 |
+
className="px-3 py-1 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-all text-sm"
|
| 169 |
+
>
|
| 170 |
+
<FaTrash className="w-4 h-4 inline ml-2" />
|
| 171 |
+
{language === 'fa' ? 'پاک کردن' : 'Clear'}
|
| 172 |
+
</button>
|
| 173 |
+
</div>
|
| 174 |
+
</div>
|
| 175 |
+
|
| 176 |
+
<div className="flex-1 flex space-x-reverse space-x-4 min-h-0">
|
| 177 |
+
{/* Sidebar */}
|
| 178 |
+
<div className="w-80 bg-gray-800 rounded-lg p-4 space-y-4 overflow-y-auto">
|
| 179 |
+
{/* Models */}
|
| 180 |
+
<div>
|
| 181 |
+
<h3 className="text-sm font-medium mb-3">AI Models</h3>
|
| 182 |
+
<div className="space-y-2">
|
| 183 |
+
{models.map(model => {
|
| 184 |
+
const Icon = model.icon
|
| 185 |
+
return (
|
| 186 |
+
<button
|
| 187 |
+
key={model.id}
|
| 188 |
+
onClick={() => setActiveModel(model.id)}
|
| 189 |
+
className={`w-full p-3 rounded-lg transition-all text-left ${
|
| 190 |
+
activeModel === model.id
|
| 191 |
+
? 'bg-primary-600 text-white'
|
| 192 |
+
: 'bg-gray-700 text-gray-300 hover:bg-gray-600'
|
| 193 |
+
}`}
|
| 194 |
+
>
|
| 195 |
+
<div className="flex items-center space-x-reverse space-x-2">
|
| 196 |
+
<Icon className="w-4 h-4" />
|
| 197 |
+
<div>
|
| 198 |
+
<div className="text-sm font-medium">{model.name}</div>
|
| 199 |
+
<div className="text-xs opacity-75">{model.description}</div>
|
| 200 |
+
</div>
|
| 201 |
+
</div>
|
| 202 |
+
</button>
|
| 203 |
+
)
|
| 204 |
+
})}
|
| 205 |
+
</div>
|
| 206 |
+
</div>
|
| 207 |
+
|
| 208 |
+
{/* Capabilities */}
|
| 209 |
+
<div>
|
| 210 |
+
<h3 className="text-sm font-medium mb-3">Capabilities</h3>
|
| 211 |
+
<div className="grid grid-cols-2 gap-2">
|
| 212 |
+
{capabilities.map(cap => {
|
| 213 |
+
const Icon = cap.icon
|
| 214 |
+
return (
|
| 215 |
+
<button
|
| 216 |
+
key={cap.id}
|
| 217 |
+
onClick={() => setSelectedCapability(cap.id)}
|
| 218 |
+
className={`p-2 rounded-lg transition-all flex flex-col items-center justify-center ${
|
| 219 |
+
selectedCapability === cap.id
|
| 220 |
+
? 'bg-primary-600 text-white'
|
| 221 |
+
: 'bg-gray-700 text-gray-300 hover:bg-gray-600'
|
| 222 |
+
}`}
|
| 223 |
+
>
|
| 224 |
+
<Icon className="w-4 h-4 mb-1" />
|
| 225 |
+
<span className="text-xs">{cap.name}</span>
|
| 226 |
+
</button>
|
| 227 |
+
)
|
| 228 |
+
})}
|
| 229 |
+
</div>
|
| 230 |
+
</div>
|
| 231 |
+
</div>
|
| 232 |
+
|
| 233 |
+
{/* Chat Area */}
|
| 234 |
+
<div className="flex-1 bg-gray-800 rounded-lg flex flex-col">
|
| 235 |
+
<div className="flex-1 p-4 overflow-y-auto space-y-4">
|
| 236 |
+
<AnimatePresence>
|
| 237 |
+
{messages.map(message => (
|
| 238 |
+
<motion.div
|
| 239 |
+
key={message.id}
|
| 240 |
+
initial={{ opacity: 0, y: 20 }}
|
| 241 |
+
animate={{ opacity: 1, y: 0 }}
|
| 242 |
+
exit={{ opacity: 0, y: -20 }}
|
| 243 |
+
className={`flex ${message.type === 'user' ? 'justify-start' : 'justify-end'}`}
|
| 244 |
+
>
|
| 245 |
+
<div className={`max-w-lg p-4 rounded-lg ${
|
| 246 |
+
message.type === 'user'
|
| 247 |
+
? 'bg-gray-700 text-white'
|
| 248 |
+
: 'bg-primary-600 text-white'
|
| 249 |
+
}`}>
|
| 250 |
+
<div className="flex items-center space-x-reverse space-x-2 mb-2">
|
| 251 |
+
{message.type === 'user' ? (
|
| 252 |
+
<FaUser className="w-4 h-4" />
|
| 253 |
+
) : (
|
| 254 |
+
<FaRobot className="w-4 h-4" />
|
| 255 |
+
)}
|
| 256 |
+
<span className="text-xs opacity-75">
|
| 257 |
+
{message.model} • {message.capability}
|
| 258 |
+
</span>
|
| 259 |
+
</div>
|
| 260 |
+
{message.content.includes('```') ? (
|
| 261 |
+
<SyntaxHighlighter
|
| 262 |
+
language="javascript"
|
| 263 |
+
style={vscDarkPlus}
|
| 264 |
+
className="rounded"
|
| 265 |
+
>
|
| 266 |
+
{message.content}
|
| 267 |
+
</SyntaxHighlighter>
|
| 268 |
+
) : (
|
| 269 |
+
<div className="whitespace-pre-wrap text-sm">
|
| 270 |
+
{message.content}
|
| 271 |
+
</div>
|
| 272 |
+
)}
|
| 273 |
+
</div>
|
| 274 |
+
</motion.div>
|
| 275 |
+
))}
|
| 276 |
+
</AnimatePresence>
|
| 277 |
+
|
| 278 |
+
{isProcessing && (
|
| 279 |
+
<motion.div
|
| 280 |
+
initial={{ opacity: 0 }}
|
| 281 |
+
animate={{ opacity: 1 }}
|
| 282 |
+
className="flex justify-end"
|
| 283 |
+
>
|
| 284 |
+
<div className="bg-primary-600 p-4 rounded-lg">
|
| 285 |
+
<div className="flex space-x-reverse space-x-1">
|
| 286 |
+
<div className="w-2 h-2 bg-white rounded-full animate-bounce" />
|
| 287 |
+
<div className="w-2 h-2 bg-white rounded-full animate-bounce" style={{ animationDelay: '150ms' }} />
|
| 288 |
+
<div className="w-2 h-2 bg-white rounded-full animate-bounce" style={{ animationDelay: '300ms' }} />
|
| 289 |
+
</div>
|
| 290 |
+
</div>
|
| 291 |
+
</motion.div>
|
| 292 |
+
)}
|
| 293 |
+
</div>
|
| 294 |
+
|
| 295 |
+
{/* Input */}
|
| 296 |
+
<div className="p-4 border-t border-gray-700">
|
| 297 |
+
<div className="flex space-x-reverse space-x-2">
|
| 298 |
+
<input
|
| 299 |
+
type="text"
|
| 300 |
+
value={input}
|
| 301 |
+
onChange={(e) => setInput(e.target.value)}
|
| 302 |
+
onKeyPress={(e) => e.key === 'Enter' && handleSendMessage()}
|
| 303 |
+
placeholder="Ask AI anything..."
|
| 304 |
+
className="flex-1 px-4 py-2 bg-gray-700 text-white rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500"
|
| 305 |
+
disabled={isProcessing}
|
| 306 |
+
/>
|
| 307 |
+
<button
|
| 308 |
+
onClick={handleSendMessage}
|
| 309 |
+
disabled={!input.trim() || isProcessing}
|
| 310 |
+
className="px-4 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 disabled:opacity-50 transition-all"
|
| 311 |
+
>
|
| 312 |
+
<FaPaperPlane className="w-4 h-4" />
|
| 313 |
+
</button>
|
| 314 |
+
</div>
|
| 315 |
+
</div>
|
| 316 |
+
</div>
|
| 317 |
+
</div>
|
| 318 |
+
</div>
|
| 319 |
+
)
|
| 320 |
+
}
|