Spaces:
Running
Running
Upload components/AgentSelector.jsx with huggingface_hub
Browse files- components/AgentSelector.jsx +97 -0
components/AgentSelector.jsx
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState, useEffect } from 'react'
|
| 2 |
+
import { Shield, Zap, Eye, Volume2, Video, Search, Lightbulb, CheckCircle, AlertCircle } from 'lucide-react'
|
| 3 |
+
|
| 4 |
+
const agentIcons = {
|
| 5 |
+
'text-analyzer': Search,
|
| 6 |
+
'image-processor': Eye,
|
| 7 |
+
'audio-guard': Volume2,
|
| 8 |
+
'video-shield': Video,
|
| 9 |
+
'security-auditor': Shield,
|
| 10 |
+
'creative-solver': Lightbulb
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
const statusColors = {
|
| 14 |
+
active: 'text-green-500',
|
| 15 |
+
monitoring: 'text-yellow-500',
|
| 16 |
+
idle: 'text-gray-500'
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
export default function AgentSelector({ onAgentSelect, selectedAgent }) {
|
| 20 |
+
const [agents, setAgents] = useState([])
|
| 21 |
+
const [loading, setLoading] = useState(true)
|
| 22 |
+
|
| 23 |
+
useEffect(() => {
|
| 24 |
+
fetchAgents()
|
| 25 |
+
}, [])
|
| 26 |
+
|
| 27 |
+
const fetchAgents = async () => {
|
| 28 |
+
try {
|
| 29 |
+
const response = await fetch('/api/agents/status')
|
| 30 |
+
const data = await response.json()
|
| 31 |
+
setAgents(data.agents)
|
| 32 |
+
} catch (error) {
|
| 33 |
+
console.error('Failed to fetch agents:', error)
|
| 34 |
+
} finally {
|
| 35 |
+
setLoading(false)
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
if (loading) {
|
| 40 |
+
return (
|
| 41 |
+
<div className="card">
|
| 42 |
+
<div className="animate-pulse space-y-4">
|
| 43 |
+
<div className="h-4 bg-dark-300 dark:bg-dark-600 rounded w-3/4"></div>
|
| 44 |
+
<div className="h-4 bg-dark-300 dark:bg-dark-600 rounded w-1/2"></div>
|
| 45 |
+
</div>
|
| 46 |
+
</div>
|
| 47 |
+
)
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
return (
|
| 51 |
+
<div className="card">
|
| 52 |
+
<h2 className="text-2xl font-bold mb-6 flex items-center">
|
| 53 |
+
<Zap className="mr-2 h-6 w-6 text-primary-500" />
|
| 54 |
+
Agent Selection
|
| 55 |
+
</h2>
|
| 56 |
+
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
| 57 |
+
{agents.map((agent) => {
|
| 58 |
+
const Icon = agentIcons[agent.id] || Shield
|
| 59 |
+
return (
|
| 60 |
+
<button
|
| 61 |
+
key={agent.id}
|
| 62 |
+
onClick={() => onAgentSelect(agent)}
|
| 63 |
+
className={`p-4 rounded-lg border-2 transition-all duration-200 text-left ${
|
| 64 |
+
selectedAgent?.id === agent.id
|
| 65 |
+
? 'border-primary-500 bg-primary-50 dark:bg-primary-900/20'
|
| 66 |
+
: 'border-dark-300 dark:border-dark-600 hover:border-dark-400 dark:hover:border-dark-500'
|
| 67 |
+
}`}
|
| 68 |
+
>
|
| 69 |
+
<div className="flex items-start justify-between mb-2">
|
| 70 |
+
<div className="flex items-center space-x-3">
|
| 71 |
+
<Icon className="h-5 w-5 text-primary-500" />
|
| 72 |
+
<h3 className="font-semibold">{agent.name}</h3>
|
| 73 |
+
</div>
|
| 74 |
+
{agent.status === 'active' ? (
|
| 75 |
+
<CheckCircle className={`h-4 w-4 ${statusColors.active}`} />
|
| 76 |
+
) : (
|
| 77 |
+
<AlertCircle className={`h-4 w-4 ${statusColors.monitoring}`} />
|
| 78 |
+
)}
|
| 79 |
+
</div>
|
| 80 |
+
<p className="text-sm text-dark-600 dark:text-dark-400 mb-2">{agent.type}</p>
|
| 81 |
+
<div className="flex flex-wrap gap-1">
|
| 82 |
+
{agent.capabilities.slice(0, 2).map((cap, idx) => (
|
| 83 |
+
<span
|
| 84 |
+
key={idx}
|
| 85 |
+
className="text-xs px-2 py-1 bg-dark-100 dark:bg-dark-700 rounded-full"
|
| 86 |
+
>
|
| 87 |
+
{cap}
|
| 88 |
+
</span>
|
| 89 |
+
))}
|
| 90 |
+
</div>
|
| 91 |
+
</button>
|
| 92 |
+
)
|
| 93 |
+
})}
|
| 94 |
+
</div>
|
| 95 |
+
</div>
|
| 96 |
+
)
|
| 97 |
+
}
|