fix: 修复 serve 模式 GET /agent 接口,直接从内置 agent 列表加载数据

This commit is contained in:
DoSun 2026-05-07 18:00:52 +08:00
parent de144bc0cb
commit 954c218085

View File

@ -5,7 +5,7 @@ import { getClaudeConfigHomeDir } from '../../utils/envUtils.js'
import { getCommands } from '../../commands.js'
import { getCommandName } from '../../types/command.js'
import type { SessionManager } from '../sessionManager.js'
import type { InitData } from '../sessionHandle.js'
import { getBuiltInAgents } from '@claude-code-best/builtin-tools/tools/AgentTool/builtInAgents.js'
export function createInfoRoutes(sessionManager: SessionManager): Hono {
return new Hono()
@ -44,18 +44,17 @@ export function createInfoRoutes(sessionManager: SessionManager): Hono {
}
})
.get('/agent', c => {
const initData = getFirstInitData(sessionManager)
if (initData?.agents && initData.agents.length > 0) {
return c.json(
initData.agents.map(a => ({
id: a.name,
name: a.name,
description: a.description,
model: a.model,
})),
)
}
return c.json([])
const allAgents = getBuiltInAgents()
return c.json(
allAgents.map(a => ({
name: a.agentType,
description: a.whenToUse,
mode: a.isMainThread ? ('primary' as const) : ('subagent' as const),
hidden: false,
options: {},
permission: [],
})),
)
})
.get('/mcp', async c => {
for (const handle of sessionManager.getAllSessions()) {
@ -71,10 +70,3 @@ export function createInfoRoutes(sessionManager: SessionManager): Hono {
return c.json({ servers: [] })
})
}
function getFirstInitData(sessionManager: SessionManager): InitData | null {
for (const handle of sessionManager.getAllSessions()) {
if (handle.initData) return handle.initData
}
return null
}