'use client'; import { useEffect, useState } from 'react'; import { Plus, Copy, Trash2 } from 'lucide-react'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@/components/ui/alert-dialog'; interface Agent { id: string; name: string; api_key: string; permission_tier: string; status: 'active' | 'disabled'; } export function SettingsAgents() { const [agents, setAgents] = useState([]); const [loading, setLoading] = useState(true); const [createDialogOpen, setCreateDialogOpen] = useState(false); const [newAgentName, setNewAgentName] = useState(''); const [newAgentTier, setNewAgentTier] = useState('read_only'); const [creating, setCreating] = useState(false); const [deletingId, setDeletingId] = useState(null); const [agentToDelete, setAgentToDelete] = useState(null); const [error, setError] = useState(null); const [status, setStatus] = useState(null); useEffect(() => { fetchAgents(); }, []); async function fetchAgents() { setLoading(true); setError(null); try { const response = await fetch('/api/agents'); if (!response.ok) throw new Error('Unable to load agents.'); const data = await response.json(); setAgents(data.items || []); } catch (error) { console.error('Failed to fetch agents:', error); setError('Unable to load agents. Please try again.'); } finally { setLoading(false); } } async function createAgent() { if (!newAgentName.trim()) return; setCreating(true); setError(null); setStatus(null); try { const response = await fetch('/api/agents', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: newAgentName, permission_tier: newAgentTier, status: 'active', }), }); if (!response.ok) throw new Error('Unable to create agent.'); setNewAgentName(''); setCreateDialogOpen(false); setStatus('Agent created successfully.'); await fetchAgents(); } catch (error) { console.error('Failed to create agent:', error); setError('Unable to create agent. Please try again.'); } finally { setCreating(false); } } async function deleteAgent() { if (!agentToDelete) return; setDeletingId(agentToDelete.id); setError(null); setStatus(null); try { const response = await fetch(`/api/agents/${agentToDelete.id}`, { method: 'DELETE' }); if (!response.ok) throw new Error('Unable to delete agent.'); setAgentToDelete(null); setStatus('Agent deleted successfully.'); await fetchAgents(); } catch (error) { console.error('Failed to delete agent:', error); setError('Unable to delete agent. Please try again.'); } finally { setDeletingId(null); } } function copyApiKey(apiKey: string) { navigator.clipboard.writeText(apiKey); } return (
Agents & Permissions Manage AI agents and their access levels.
Create Agent
setNewAgentName(e.target.value)} placeholder="e.g., Hermes, Claude" />
{error && (
{error}
)} {status &&

{status}

} {loading ? (

Loading agents...

) : agents.length === 0 ? (

No agents configured

) : (
{agents.map((agent) => (

{agent.name}

{agent.status}

{agent.permission_tier.replace('_', ' ')}

{agent.api_key.slice(0, 8)}...
))}
)} !open && setAgentToDelete(null)}> Delete {agentToDelete?.name}? This will revoke the agent's access. Cancel {deletingId ? 'Deleting...' : 'Delete agent'}
); }