/**
 * Dashboard API Routes for Agentic AI Features
 *
 * Exposes REST endpoints for the Dashboard v4 Agentic Workspace.
 * Registered in the dashboard HTTP server (soc-api-server.ts or equivalent).
 */
import { Logger } from '../utils/logger.js';
/**
 * Register all agentic API routes on an Express/Fastify-like router.
 * Usage:
 *   const router = express.Router();
 *   registerAgenticRoutes(router, { container });
 */
export function registerAgenticRoutes(router, ctx) {
    const { container } = ctx;
    // ── Meta / Status ─────────────────────────────────────────────
    router.get('/api/agentic/status', (_req, res) => {
        const metrics = container.telemetry.getMetrics(container.taskQueue.getStats());
        res.json({
            uptimeMs: metrics.uptimeMs,
            totalDecisions: metrics.totalDecisions,
            avgConfidence: metrics.avgConfidence,
            llmTokensUsed: metrics.llmTokensUsed,
            llmCostEstimate: metrics.llmCostEstimate,
            llmAvailable: container.modelProvider.isAvailable(),
            features: getFeatureStatus(container),
        });
    });
    router.get('/api/agentic/tasks', (_req, res) => {
        const stats = container.taskQueue.getStats();
        res.json(stats);
    });
    router.post('/api/agentic/tasks/:id/approve', (req, res) => {
        const approved = container.approvalGate.approve(req.params.id);
        res.json({ success: approved });
    });
    router.post('/api/agentic/tasks/:id/deny', (req, res) => {
        const denied = container.approvalGate.deny(req.params.id);
        res.json({ success: denied });
    });
    // ── Policy Generation ─────────────────────────────────────────
    router.get('/api/agentic/policy-gen/status', (_req, res) => {
        const summary = container.behaviorCollector.getSummary();
        const history = container.behaviorCollector.getHistory();
        res.json({
            active: container.behaviorCollector.isActive(),
            currentObservation: summary,
            historicalWindows: history.length,
        });
    });
    router.get('/api/agentic/policy-gen/generated', (_req, res) => {
        const windows = container.behaviorCollector.getHistory();
        if (windows.length === 0)
            return res.json({ policies: [] });
        const latest = windows[windows.length - 1];
        const analysis = container.patternAnalyzer.analyze(latest, latest.stats);
        const policy = container.policySynthesizer.synthesize(analysis);
        res.json({
            policy,
            toolProfiles: analysis.toolProfiles,
            workflows: analysis.normalWorkflows,
        });
    });
    // ── Prompt Injection ──────────────────────────────────────────
    router.get('/api/agentic/prompt-injection/stats', (_req, res) => {
        res.json(container.promptInjectionDetector.getStats());
    });
    // ── Threat Prediction ─────────────────────────────────────────
    router.get('/api/agentic/threat-prediction/:serverName', (req, res) => {
        // Requires servers to be loaded — this is a lightweight endpoint
        res.json({
            serverName: req.params.serverName,
            note: 'Use predict_threats MCP tool for full forecast',
        });
    });
    // ── Compliance ────────────────────────────────────────────────
    router.get('/api/compliance/posture', (_req, res) => {
        const frameworks = ['soc2', 'hipaa', 'pci-dss', 'fedramp', 'iso27001'];
        const postures = frameworks.map(f => container.controlMapper.evaluate(f, [], []));
        const overall = Math.round(postures.reduce((s, p) => s + p.postureScore, 0) / postures.length);
        res.json({ frameworks: postures, overall });
    });
    router.get('/api/compliance/evidence/:framework', (req, res) => {
        const framework = req.params.framework;
        const posture = container.controlMapper.evaluate(framework, [], []);
        res.json(posture);
    });
    // ── Drift Detection ───────────────────────────────────────────
    router.get('/api/agentic/drift/:serverName', (req, res) => {
        const baselines = container.driftDetector.getBaselines(req.params.serverName);
        res.json({ serverName: req.params.serverName, baselineCount: baselines.length, latestBaseline: baselines[baselines.length - 1] || null });
    });
    // ── Red Team ──────────────────────────────────────────────────
    router.get('/api/agentic/red-team/results', (_req, res) => {
        res.json({
            status: 'ready',
            baseAttacks: 16,
            mutationStrategies: 6,
            combinationEngine: 'active',
        });
    });
    // ── Threat Mesh ───────────────────────────────────────────────
    router.get('/api/agentic/threat-mesh/status', (_req, res) => {
        res.json(container.threatMeshNode.getStats());
    });
    // ── Honeypots ─────────────────────────────────────────────────
    router.get('/api/agentic/honeypots', (_req, res) => {
        res.json({
            summary: container.honeypotManager.getSummary(),
            honeypots: container.honeypotManager.getAll(),
        });
    });
    // ── Trust Negotiation ─────────────────────────────────────────
    router.get('/api/agentic/trust/sessions', (_req, res) => {
        res.json({
            sessions: container.trustProtocol.getActiveSessions(),
            registry: container.trustProtocol.getTrustRegistry(),
            stats: container.trustProtocol.getStats(),
        });
    });
    // ── Supply Chain ──────────────────────────────────────────────
    router.get('/api/agentic/supply-chain/status', (_req, res) => {
        res.json({ status: 'active', modules: ['signature-verifier', 'typo-squat-detector', 'dependency-confusion-detector'] });
    });
    Logger.info('[AgenticRoutes] Registered 15 dashboard API endpoints');
}
function getFeatureStatus(container) {
    return [
        { name: 'Policy Generation', status: container.behaviorCollector.isActive() ? 'observing' : 'idle' },
        { name: 'Prompt Injection Detection', status: 'active' },
        { name: 'Threat Prediction', status: 'active' },
        { name: 'Supply Chain Verification', status: 'active' },
        { name: 'Drift Detection', status: 'active' },
        { name: 'Compliance Mapping', status: 'active' },
        { name: 'Red Team Engine', status: 'active' },
        { name: 'Threat Intel Mesh', status: container.threatMeshNode.isEnabled() ? 'active' : 'disabled' },
        { name: 'Honeypot Manager', status: `${container.honeypotManager.getSummary().active} active` },
        { name: 'Trust Negotiation', status: 'active' },
    ];
}
//# sourceMappingURL=agentic-routes.js.map