UNPKG

education-module-ai

Version:
158 lines (157 loc) 7.71 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DEFAULT_SUBJECTS = exports.DEFAULT_EDUCATIONAL_LEVELS = exports.EducationConfigService = exports.initEducationDatabase = exports.educationSqliteTables = exports.EducationModuleAdapter = void 0; exports.configureEducationModule = configureEducationModule; exports.initializeEducationAPI = initializeEducationAPI; // Export all models __exportStar(require("./models/index"), exports); // Export all controllers __exportStar(require("./controllers/index"), exports); // Export all services __exportStar(require("./services/index"), exports); // Export all plugins __exportStar(require("./plugins/index"), exports); // Export context for frontend components __exportStar(require("./context"), exports); // Export frontend components __exportStar(require("./components"), exports); // Export database adapter // Instead of exporting everything with a wildcard, export specific items const index_1 = require("./database/index"); Object.defineProperty(exports, "EducationModuleAdapter", { enumerable: true, get: function () { return index_1.EducationModuleAdapter; } }); Object.defineProperty(exports, "educationSqliteTables", { enumerable: true, get: function () { return index_1.educationSqliteTables; } }); Object.defineProperty(exports, "initEducationDatabase", { enumerable: true, get: function () { return index_1.initEducationDatabase; } }); // Import the education config service const EducationalContent_1 = require("./models/EducationalContent"); Object.defineProperty(exports, "EducationConfigService", { enumerable: true, get: function () { return EducationalContent_1.EducationConfigService; } }); Object.defineProperty(exports, "DEFAULT_EDUCATIONAL_LEVELS", { enumerable: true, get: function () { return EducationalContent_1.DEFAULT_EDUCATIONAL_LEVELS; } }); Object.defineProperty(exports, "DEFAULT_SUBJECTS", { enumerable: true, get: function () { return EducationalContent_1.DEFAULT_SUBJECTS; } }); // Configuration function to setup education module function configureEducationModule(config) { const configService = EducationalContent_1.EducationConfigService.getInstance(); configService.configure(config); console.log("Education module configured with custom settings"); if (config.levels) { console.log(`Configured educational levels: ${config.levels.join(', ')}`); } if (config.subjects) { console.log(`Configured subjects: ${config.subjects.join(', ')}`); } } // Main server initialization const dotenv_1 = __importDefault(require("dotenv")); const express_1 = __importDefault(require("express")); const cors_1 = __importDefault(require("cors")); const body_parser_1 = __importDefault(require("body-parser")); const index_2 = require("./controllers/index"); const index_3 = require("./plugins/index"); const agent_framework_backend_1 = require("@defikitdotnet/agent-framework-backend"); // Load environment variables dotenv_1.default.config(); /** * Initialize the Education Module API with optional configuration */ async function initializeEducationAPI(config) { console.log("Initializing Education Module API..."); // Apply configuration if provided if (config) { configureEducationModule(config); } // Create Express app const app = (0, express_1.default)(); // Register middleware app.use((0, cors_1.default)()); app.use(body_parser_1.default.json()); // Initialize plugins await index_3.pluginManager.initialize(); console.log("Plugins initialized successfully"); // Register controllers const controllers = [ new index_2.EducationalContentController(), new index_2.LearningSessionController(), new index_2.UserProfileController(), ]; // Register routes using @defikitdotnet/agent-framework-backend (0, agent_framework_backend_1.registerControllers)(app, controllers); console.log("Controllers registered successfully"); // Add direct route for quiz endpoint const educationalContentController = controllers[0]; app.post('/api/educational-contents/quiz', (req, res) => { console.log("Direct quiz endpoint called"); return educationalContentController.generateQuiz(req, res); }); console.log("Added direct route for quiz endpoint"); // Add direct route for answer question endpoint app.post('/api/educational-contents/answer-question', (req, res) => { console.log("Direct answer question endpoint called"); return educationalContentController.answerQuestion(req, res); }); console.log("Added direct route for answer question endpoint"); const learningSessionController = controllers[1]; // Add direct route for get all learning paths endpoint app.post('/api/learning-sessions/generate-path', (req, res) => { console.log("Direct generate learning path endpoint called"); return learningSessionController.generateLearningPath(req, res); }); console.log("Added direct route for generate learning path endpoint"); // Add endpoint to get configuration app.get('/api/education-config', (req, res) => { const configService = EducationalContent_1.EducationConfigService.getInstance(); res.json({ levels: configService.levels, subjects: configService.subjects }); }); console.log("Added endpoint for education configuration"); // Print all registered routes console.log("All registered routes:"); app._router.stack.forEach((middleware) => { if (middleware.route) { // Routes registered directly console.log(`${Object.keys(middleware.route.methods).join(',')} ${middleware.route.path}`); } else if (middleware.name === 'router' && middleware.handle.stack) { // Routes registered within a router middleware.handle.stack.forEach((handler) => { if (handler.route) { console.log(`${Object.keys(handler.route.methods).join(',')} ${middleware.regexp} -> ${handler.route.path}`); } }); } }); return app; } // Auto-start if this file is run directly via 'node' command, but not when imported if (require.main === module) { initializeEducationAPI().then(app => { const port = process.env.PORT || 3009; app.listen(port, () => { console.log(`Education Module API running on port ${port}`); console.log("Available API routes:"); console.log("- /api/educational-contents"); console.log("- /api/learning-sessions"); console.log("- /api/user-profiles"); console.log("- /api/education-config"); }); }).catch(error => { console.error("Failed to initialize Education Module API:", error); process.exit(1); }); }