'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'; 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'); useEffect(() => { fetchAgents(); }, []); async function fetchAgents() { try { const response = await fetch('/api/agents'); if (response.ok) { const data = await response.json(); setAgents(data.items || []); } } catch (error) { console.error('Failed to fetch agents:', error); } finally { setLoading(false); } } async function createAgent() { if (!newAgentName.trim()) return; try { await fetch('/api/agents', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: newAgentName, permission_tier: newAgentTier, status: 'active', }), }); setNewAgentName(''); setCreateDialogOpen(false); fetchAgents(); } catch (error) { console.error('Failed to create agent:', error); } } async function deleteAgent(id: string) { if (!confirm('Are you sure? This will revoke the agent\'s access.')) return; try { await fetch(`/api/agents/${id}`, { method: 'DELETE' }); fetchAgents(); } catch (error) { console.error('Failed to delete agent:', error); } } 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" />
{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)}...
))}
)}
); }