File size: 3,221 Bytes
529090e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
 * Knowledge Routes - REST API for KnowledgeCompiler
 * 
 * Endpoints:
 * - GET /api/knowledge/summary - Get system state summary
 * - GET /api/knowledge/insights - Get current insights
 * - GET /api/knowledge/health - Get health status
 * - POST /api/knowledge/compile - Force recompilation
 */

import express from 'express';
import { knowledgeCompiler } from '../services/Knowledge/index.js';

const router = express.Router();

/**
 * GET /api/knowledge/summary
 * Get the current system state summary
 */
router.get('/summary', async (req, res) => {
    try {
        const forceRefresh = req.query.refresh === 'true';
        const summary = await knowledgeCompiler.getSystemSummary(forceRefresh);
        res.json({
            success: true,
            data: summary
        });
    } catch (error) {
        console.error('[Knowledge] Error getting summary:', error);
        res.status(500).json({
            success: false,
            error: 'Failed to get system summary'
        });
    }
});

/**
 * GET /api/knowledge/insights
 * Get current insights only
 */
router.get('/insights', async (req, res) => {
    try {
        const summary = await knowledgeCompiler.getSystemSummary();
        res.json({
            success: true,
            data: {
                insights: summary.insights,
                recommendations: summary.recommendations,
                timestamp: summary.timestamp
            }
        });
    } catch (error) {
        console.error('[Knowledge] Error getting insights:', error);
        res.status(500).json({
            success: false,
            error: 'Failed to get insights'
        });
    }
});

/**
 * GET /api/knowledge/health
 * Get health status only
 */
router.get('/health', async (req, res) => {
    try {
        const summary = await knowledgeCompiler.getSystemSummary();
        res.json({
            success: true,
            data: summary.health
        });
    } catch (error) {
        console.error('[Knowledge] Error getting health:', error);
        res.status(500).json({
            success: false,
            error: 'Failed to get health status'
        });
    }
});

/**
 * GET /api/knowledge/graph-stats
 * Get Neo4j graph statistics
 */
router.get('/graph-stats', async (req, res) => {
    try {
        const summary = await knowledgeCompiler.getSystemSummary();
        res.json({
            success: true,
            data: summary.graphStats
        });
    } catch (error) {
        console.error('[Knowledge] Error getting graph stats:', error);
        res.status(500).json({
            success: false,
            error: 'Failed to get graph statistics'
        });
    }
});

/**
 * POST /api/knowledge/compile
 * Force a full recompilation
 */
router.post('/compile', async (req, res) => {
    try {
        const summary = await knowledgeCompiler.compile();
        res.json({
            success: true,
            message: 'Compilation complete',
            data: summary
        });
    } catch (error) {
        console.error('[Knowledge] Error compiling:', error);
        res.status(500).json({
            success: false,
            error: 'Compilation failed'
        });
    }
});

export default router;