fix agent list
This commit is contained in:
parent
700d0dae46
commit
c377280fca
|
|
@ -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<void>
|
||||
}
|
||||
|
||||
const AGENTS = ['default', 'coding', 'devops', 'greybeard', 'qa', 'reviewer', 'writer']
|
||||
|
||||
const DEFAULT_MODELS: Record<string, string> = {
|
||||
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<string[]>([])
|
||||
const [agents, setAgents] = useState<string[]>(['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 => <option key={a} value={a}>{a}</option>)}
|
||||
{agents.map(a => <option key={a} value={a}>{a}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -67,6 +67,16 @@ export async function getBackends(): Promise<string[]> {
|
|||
return Array.isArray(data) ? (data as string[]) : []
|
||||
}
|
||||
|
||||
export async function getAgents(): Promise<string[]> {
|
||||
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<void> {
|
||||
await fetch(`/s/${id}`, { method: 'DELETE' })
|
||||
}
|
||||
|
|
|
|||
Reference in New Issue