← back to Dw Boardroom V2

src/api/routes/health.ts

46 lines

// ═══════════════════════════════════════════════
// DW Boardroom V2 — Health & Status Routes
// ═══════════════════════════════════════════════

import { Router } from 'express';
import { getActiveMeeting, listMeetings } from '../../engine/meetingEngine';
import { TEAM_AGENTS, EXECUTIVES } from '../../agents/registry';
import { isGovernanceAvailable } from '../../engine/governanceClient';
import { getConnectionCount } from '../../ws/broadcast';

const router = Router();
const startTime = Date.now();

// GET /api/status — detailed status
router.get('/status', async (req, res) => {
  try {
    const govAvailable = await isGovernanceAvailable();
    const activeMeeting = getActiveMeeting();
    const recentMeetings = listMeetings(5);

    res.json({
      service: 'dw-boardroom-v2',
      version: '1.0.0',
      uptime: Math.floor((Date.now() - startTime) / 1000),
      agents: TEAM_AGENTS.length,
      executives: EXECUTIVES.length,
      wsClients: getConnectionCount(),
      activeMeeting: activeMeeting ? {
        id: activeMeeting.id,
        type: activeMeeting.meeting_type,
        phase: activeMeeting.phase,
        status: activeMeeting.status,
      } : null,
      recentMeetings: recentMeetings.length,
      governance: {
        url: process.env.GOVERNANCE_URL || 'http://127.0.0.1:4020',
        available: govAvailable,
      },
    });
  } catch (err: any) {
    res.status(500).json({ error: err.message });
  }
});

export default router;