fix: properly add agent enhancements to async context

This commit is contained in:
2026-03-04 15:40:00 -08:00
parent 0e56f33539
commit 9cce26b08a

View File

@@ -558,44 +558,16 @@ app.get('/api/agents', (req, res) => {
}); });
}; };
// Load openclaw config for identity info const agentPromises = agentDirs.map(async (agentName) => {
let emoji = '🤖'; const agentPath = path.join(AGENTS_DIR, agentName);
let model = 'unknown'; const workspacePath = path.join(agentPath, 'workspace');
let identityName = agentName;
if (fs.existsSync(OPENCLAW_CONFIG)) {
try {
const openclawConfig = JSON.parse(fs.readFileSync(OPENCLAW_CONFIG, 'utf8'));
const agentConfig = openclawConfig.agents?.list?.find(a => a.id === agentName);
if (agentConfig) {
emoji = agentConfig.identity?.emoji || '🤖';
model = agentConfig.model?.primary || 'unknown';
identityName = agentConfig.identity?.name || agentName;
}
} catch {}
}
// Get last activity from session files
let lastActivity = null;
const sessionsPath = path.join(agentPath, 'sessions');
if (fs.existsSync(sessionsPath)) {
const sessionFiles = fs.readdirSync(sessionsPath).filter(f => f.endsWith('.jsonl'));
if (sessionFiles.length > 0) {
const latestSession = sessionFiles
.map(f => ({ file: f, mtime: fs.statSync(path.join(sessionsPath, f)).mtime }))
.sort((a, b) => b.mtime - a.mtime)[0];
if (latestSession) {
lastActivity = latestSession.mtime.toISOString();
}
}
}
const agent = { const agent = {
id: agentName, id: agentName,
name: identityName,
emoji, emoji,
model, model,
lastActivity, lastActivity,
name: identityName,
status: 'active', status: 'active',
currentTask: null, currentTask: null,
tools: [], tools: [],
@@ -606,6 +578,10 @@ app.get('/api/agents', (req, res) => {
completedTasks: [], completedTasks: [],
capabilities: [] capabilities: []
}; };
if (fs.existsSync(workspacePath)) {
const files = fs.readdirSync(workspacePath);
agent.files = files.filter(f => f.endsWith('.md'));
const memoryPath = path.join(workspacePath, 'MEMORY.md'); const memoryPath = path.join(workspacePath, 'MEMORY.md');
if (fs.existsSync(memoryPath)) { if (fs.existsSync(memoryPath)) {