冰朔 8743426ed0
Some checks failed
自动更新代码和重启 / update-and-restart (push) Has been cancelled
CI检查 + 自动部署 / check (push) Has been cancelled
CI检查 + 自动部署 / deploy (push) Has been cancelled
persona-brain-db 搬家: repo根→brain/fifth-domain/zero-point/zhuyuan/persona-brain-db/ · 零点原核子模块归位 · 删旧副本·cognitive-index新增
2026-06-04 21:10:05 +08:00

47 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Agent注册 CRUD · /brain/agents
* Phase A只读Phase C启用写入
*/
const { Router } = require('express');
const router = Router();
// GET /brain/agents - 列出所有Agent
router.get('/', (req, res) => {
try {
const rows = req.db.prepare('SELECT * FROM agent_registry').all();
const parsed = rows.map(parseJsonFields);
res.json({ data: parsed, total: parsed.length });
} catch (err) {
res.status(500).json({ error: true, message: err.message });
}
});
// GET /brain/agents/:id - 查询单个Agent
router.get('/:id', (req, res) => {
try {
const row = req.db
.prepare('SELECT * FROM agent_registry WHERE agent_id = ?')
.get(req.params.id);
if (!row) {
return res.status(404).json({ error: true, message: 'Agent not found' });
}
res.json({ data: parseJsonFields(row) });
} catch (err) {
res.status(500).json({ error: true, message: err.message });
}
});
function parseJsonFields(row) {
const jsonFields = ['capabilities', 'performance'];
const result = { ...row };
for (const field of jsonFields) {
if (result[field]) {
try { result[field] = JSON.parse(result[field]); } catch (_e) { /* keep raw */ }
}
}
return result;
}
module.exports = router;