fix: 修复 serve 模式 GET /agent 接口,直接从内置 agent 列表加载数据
This commit is contained in:
parent
de144bc0cb
commit
954c218085
|
|
@ -5,7 +5,7 @@ import { getClaudeConfigHomeDir } from '../../utils/envUtils.js'
|
||||||
import { getCommands } from '../../commands.js'
|
import { getCommands } from '../../commands.js'
|
||||||
import { getCommandName } from '../../types/command.js'
|
import { getCommandName } from '../../types/command.js'
|
||||||
import type { SessionManager } from '../sessionManager.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 {
|
export function createInfoRoutes(sessionManager: SessionManager): Hono {
|
||||||
return new Hono()
|
return new Hono()
|
||||||
|
|
@ -44,18 +44,17 @@ export function createInfoRoutes(sessionManager: SessionManager): Hono {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.get('/agent', c => {
|
.get('/agent', c => {
|
||||||
const initData = getFirstInitData(sessionManager)
|
const allAgents = getBuiltInAgents()
|
||||||
if (initData?.agents && initData.agents.length > 0) {
|
return c.json(
|
||||||
return c.json(
|
allAgents.map(a => ({
|
||||||
initData.agents.map(a => ({
|
name: a.agentType,
|
||||||
id: a.name,
|
description: a.whenToUse,
|
||||||
name: a.name,
|
mode: a.isMainThread ? ('primary' as const) : ('subagent' as const),
|
||||||
description: a.description,
|
hidden: false,
|
||||||
model: a.model,
|
options: {},
|
||||||
})),
|
permission: [],
|
||||||
)
|
})),
|
||||||
}
|
)
|
||||||
return c.json([])
|
|
||||||
})
|
})
|
||||||
.get('/mcp', async c => {
|
.get('/mcp', async c => {
|
||||||
for (const handle of sessionManager.getAllSessions()) {
|
for (const handle of sessionManager.getAllSessions()) {
|
||||||
|
|
@ -71,10 +70,3 @@ export function createInfoRoutes(sessionManager: SessionManager): Hono {
|
||||||
return c.json({ servers: [] })
|
return c.json({ servers: [] })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFirstInitData(sessionManager: SessionManager): InitData | null {
|
|
||||||
for (const handle of sessionManager.getAllSessions()) {
|
|
||||||
if (handle.initData) return handle.initData
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user