import { useEffect, useState } from 'react' import Editor from '@monaco-editor/react' import { useStore } from '../store' const API = '/api' export function AgentsPage() { const { agents, fetchAgents } = useStore() const [selected, setSelected] = useState(null) const [tab, setTab] = useState<'AGENT.md' | 'SOUL.md'>('AGENT.md') const [content, setContent] = useState('') const [newName, setNewName] = useState('') useEffect(() => { fetchAgents() }, []) useEffect(() => { if (!selected) return fetch(`${API}/agents/${selected}/files/${tab}`).then(r => r.json()).then(d => setContent(d.content || '')) }, [selected, tab]) const save = async () => { if (!selected) return await fetch(`${API}/agents/${selected}/files/${tab}`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ content }) }) } const create = async () => { if (!newName.trim()) return await fetch(`${API}/agents`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: newName.trim() }) }) setNewName('') fetchAgents() } const del = async (name: string) => { await fetch(`${API}/agents/${name}`, { method: 'DELETE' }) if (selected === name) setSelected(null) fetchAgents() } return (
{/* Agent list */}
setNewName(e.target.value)} onKeyDown={e => e.key === 'Enter' && create()} />
{agents.map(a => (
setSelected(a.name)} className={`flex items-center justify-between px-3 py-2 cursor-pointer text-sm hover:bg-gray-700 ${selected === a.name ? 'bg-gray-700' : ''}`}> {a.name}
))}
{/* Editor */}
{selected ? ( <>
{selected}
{(['AGENT.md', 'SOUL.md'] as const).map(t => ( ))}
setContent(v || '')} options={{ minimap: { enabled: false }, wordWrap: 'on', fontSize: 13 }} />
) : (
选择一个 agent 编辑
)}
) }