fix(telemetry): discover agents from ~/.openclaw/agents and clean docs

- Fallback to agent directory discovery when agents.json is absent
- Count configured agent workspaces (excluding main)
- Rewrite plugin docs to API key-only flow
This commit is contained in:
zhi
2026-03-20 08:02:19 +00:00
parent 040cde8cad
commit ab42936408
3 changed files with 69 additions and 115 deletions

View File

@@ -4,7 +4,7 @@
* Runs as separate process from Gateway.
* Collects system metrics and OpenClaw status, sends to Monitor.
*/
import { readFile, access } from 'fs/promises';
import { readFile, access, readdir } from 'fs/promises';
import { constants } from 'fs';
import { exec } from 'child_process';
import { promisify } from 'util';
@@ -191,10 +191,24 @@ async function getOpenclawAgents() {
try {
await access(agentConfigPath, constants.R_OK);
const data = JSON.parse(await readFile(agentConfigPath, 'utf8'));
return data.agents || [];
if (Array.isArray(data.agents) && data.agents.length > 0) {
return data.agents;
}
} catch {
return [];
// fall through to directory-based discovery
}
const agentsDir = `${CONFIG.openclawPath}/agents`;
await access(agentsDir, constants.R_OK);
const entries = await readdir(agentsDir, { withFileTypes: true });
return entries
.filter((entry) => entry.isDirectory())
.filter((entry) => entry.name !== 'main')
.map((entry) => ({
id: entry.name,
name: entry.name,
status: 'configured',
}));
} catch {
return [];
}