Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

1.1 KB
Raw Blame
import { Router } from 'express';
import { getRunningAgents, killProcess, getProcessInfo } from '../services/agents.js';
import { asyncHandler, ServerError } from '../lib/errorHandler.js';

const router = Router();

// GET /api/agents - Get all running AI agents
router.get('/', asyncHandler(async (req, res) => {
  const agents = await getRunningAgents();
  res.json(agents);
}));

// GET /api/agents/:pid - Get specific process info
router.get('/:pid', asyncHandler(async (req, res) => {
  const pid = parseInt(req.params.pid, 10);
  if (Number.isNaN(pid)) throw new ServerError('Invalid PID', { status: 400, code: 'INVALID_PARAM' });
  const info = await getProcessInfo(pid);
  if (!info) {
    throw new ServerError('Process not found', { status: 404, code: 'NOT_FOUND' });
  }
  res.json(info);
}));

// DELETE /api/agents/:pid - Kill a process
router.delete('/:pid', asyncHandler(async (req, res) => {
  const pid = parseInt(req.params.pid, 10);
  if (Number.isNaN(pid)) throw new ServerError('Invalid PID', { status: 400, code: 'INVALID_PARAM' });
  await killProcess(pid);
  res.json({ success: true, pid });
}));

export default router;