fix: properly define agent enhancement variables before use
This commit is contained in:
33
server.js
33
server.js
@@ -557,11 +557,42 @@ app.get('/api/agents', (req, res) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const agentPromises = agentDirs.map(async (agentName) => {
|
const agentPromises = agentDirs.map(async (agentName) => {
|
||||||
const agentPath = path.join(AGENTS_DIR, agentName);
|
const agentPath = path.join(AGENTS_DIR, agentName);
|
||||||
const workspacePath = path.join(agentPath, 'workspace');
|
const workspacePath = path.join(agentPath, 'workspace');
|
||||||
|
|
||||||
|
// Load openclaw config for identity info
|
||||||
|
let emoji = '🤖';
|
||||||
|
let model = 'unknown';
|
||||||
|
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,
|
||||||
emoji,
|
emoji,
|
||||||
|
|||||||
Reference in New Issue
Block a user