diff --git a/src/components/NewSession.tsx b/src/components/NewSession.tsx index 91ad76b..e23420c 100644 --- a/src/components/NewSession.tsx +++ b/src/components/NewSession.tsx @@ -1,5 +1,5 @@ import { useState, useEffect } from 'preact/hooks' -import { getBackends } from '../lib/api' +import { getBackends, getAgents } from '../lib/api' interface CreateParams { cwd: string @@ -13,8 +13,6 @@ interface Props { onCreate: (p: CreateParams) => Promise } -const AGENTS = ['default', 'coding', 'devops', 'greybeard', 'qa', 'reviewer', 'writer'] - const DEFAULT_MODELS: Record = { anthropic: 'claude-opus-4-5', openai: 'gpt-4o', @@ -29,6 +27,7 @@ export function NewSession({ onClose, onCreate }: Props) { const [model, setModel] = useState(DEFAULT_MODELS['anthropic']) const [agent, setAgent] = useState('default') const [backends, setBackends] = useState([]) + const [agents, setAgents] = useState(['default']) const [loading, setLoading] = useState(false) useEffect(() => { @@ -39,6 +38,9 @@ export function NewSession({ onClose, onCreate }: Props) { setModel(DEFAULT_MODELS[bs[0]] ?? '') } }).catch(() => {}) + getAgents().then(as => { + if (as.length > 0) setAgents(as) + }).catch(() => {}) }, []) const handleBackend = (b: string) => { @@ -100,7 +102,7 @@ export function NewSession({ onClose, onCreate }: Props) { value={agent} onChange={e => setAgent((e.target as HTMLSelectElement).value)} > - {AGENTS.map(a => )} + {agents.map(a => )} diff --git a/src/lib/api.ts b/src/lib/api.ts index 1f571fb..5601f82 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -67,6 +67,16 @@ export async function getBackends(): Promise { return Array.isArray(data) ? (data as string[]) : [] } +export async function getAgents(): Promise { + const r = await fetch('/a/') + if (!r.ok) return [] + const data = await r.json() + if (!Array.isArray(data)) return [] + return data + .filter((e: any) => e.name?.endsWith('.json')) + .map((e: any) => e.name.replace(/\.json$/, '')) +} + export async function killSession(id: string): Promise { await fetch(`/s/${id}`, { method: 'DELETE' }) }