feat: add agent emoji, model, and last activity to agents page
This commit is contained in:
44
server.js
44
server.js
@@ -558,12 +558,44 @@ app.get('/api/agents', (req, res) => {
|
||||
});
|
||||
};
|
||||
|
||||
const agentPromises = agentDirs.map(async (agentName) => {
|
||||
const agentPath = path.join(AGENTS_DIR, agentName);
|
||||
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 = {
|
||||
name: agentName,
|
||||
id: agentName,
|
||||
name: identityName,
|
||||
emoji,
|
||||
model,
|
||||
lastActivity,
|
||||
status: 'active',
|
||||
currentTask: null,
|
||||
tools: [],
|
||||
@@ -574,10 +606,6 @@ app.get('/api/agents', (req, res) => {
|
||||
completedTasks: [],
|
||||
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');
|
||||
if (fs.existsSync(memoryPath)) {
|
||||
|
||||
Reference in New Issue
Block a user