Fix pixel office agent discovery fallback

This commit is contained in:
xmanrui
2026-03-09 03:20:19 +08:00
parent d7c15240ec
commit 2fee2788b4
+26 -2
View File
@@ -40,6 +40,30 @@ export interface AgentActivity {
subagents?: SubagentInfo[]
}
type AgentConfigEntry = {
id: string
name?: string
emoji?: string
identity?: { emoji?: string }
}
async function loadAgentList(config: any, agentsDir: string): Promise<AgentConfigEntry[]> {
const configured = Array.isArray(config?.agents?.list)
? config.agents.list.filter((agent: any) => agent && typeof agent.id === 'string' && agent.id)
: []
if (configured.length > 0) return configured
try {
if (!existsSync(agentsDir)) return []
const dirs = await fs.readdir(agentsDir, { withFileTypes: true })
return dirs
.filter((entry) => entry.isDirectory() && !entry.name.startsWith('.'))
.map((entry) => ({ id: entry.name }))
} catch {
return []
}
}
function isSubtaskDescription(desc: string): boolean {
const d = desc.toLowerCase()
return desc.startsWith('Subtask:') || desc.startsWith('子任务') || d.includes('subtask')
@@ -494,8 +518,8 @@ export async function GET() {
const configContent = await fs.readFile(configPath, 'utf8')
const config = parseJsonText(configContent)
const agentList = Array.isArray(config.agents) ? config.agents : config.agents?.list
if (agentList && Array.isArray(agentList)) {
const agentList = await loadAgentList(config, agentsDir)
if (agentList.length > 0) {
const now = Date.now()
for (const agent of agentList) {