UNPKG

education-module-ai

Version:
213 lines (212 loc) 7.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pluginManager = void 0; const analytics_plugin_1 = require("./analytics-plugin"); const notification_plugin_1 = require("./notification-plugin"); /** * Plugin Manager for the Education Module * Manages and coordinates all plugins */ class PluginManager { constructor() { this.plugins = []; this.initialized = false; } /** * Register a plugin with the manager */ registerPlugin(plugin) { this.plugins.push(plugin); console.log(`Plugin registered: ${plugin.constructor.name}`); } /** * Initialize all registered plugins */ async initialize() { if (this.initialized) { return; } console.log("Initializing education module plugins..."); for (const plugin of this.plugins) { try { await plugin.initialize(); console.log(`Plugin initialized: ${plugin.constructor.name}`); } catch (error) { console.error(`Failed to initialize plugin ${plugin.constructor.name}:`, error); } } this.initialized = true; console.log("All education module plugins initialized"); } /** * Notify plugins when educational content is created */ async notifyContentCreated(content) { for (const plugin of this.plugins) { if (plugin.onContentCreated) { try { await plugin.onContentCreated(content); } catch (error) { console.error(`Error in plugin ${plugin.constructor.name} onContentCreated:`, error); } } } } /** * Notify plugins when educational content is updated */ async notifyContentUpdated(content) { for (const plugin of this.plugins) { if (plugin.onContentUpdated) { try { await plugin.onContentUpdated(content); } catch (error) { console.error(`Error in plugin ${plugin.constructor.name} onContentUpdated:`, error); } } } } /** * Notify plugins when educational content is deleted */ async notifyContentDeleted(contentId) { for (const plugin of this.plugins) { if (plugin.onContentDeleted) { try { await plugin.onContentDeleted(contentId); } catch (error) { console.error(`Error in plugin ${plugin.constructor.name} onContentDeleted:`, error); } } } } /** * Notify plugins when a learning session is started */ async notifySessionStarted(session) { for (const plugin of this.plugins) { if (plugin.onSessionStarted) { try { await plugin.onSessionStarted(session); } catch (error) { console.error(`Error in plugin ${plugin.constructor.name} onSessionStarted:`, error); } } } } /** * Notify plugins when a learning session is ended */ async notifySessionEnded(session) { for (const plugin of this.plugins) { if (plugin.onSessionEnded) { try { await plugin.onSessionEnded(session); } catch (error) { console.error(`Error in plugin ${plugin.constructor.name} onSessionEnded:`, error); } } } } /** * Notify plugins when a message is sent in a learning session */ async notifySessionMessageSent(session, message) { for (const plugin of this.plugins) { if (plugin.onSessionMessageSent) { try { await plugin.onSessionMessageSent(session, message); } catch (error) { console.error(`Error in plugin ${plugin.constructor.name} onSessionMessageSent:`, error); } } } } /** * Notify plugins when a user profile is created */ async notifyProfileCreated(profile) { for (const plugin of this.plugins) { if (plugin.onProfileCreated) { try { await plugin.onProfileCreated(profile); } catch (error) { console.error(`Error in plugin ${plugin.constructor.name} onProfileCreated:`, error); } } } } /** * Notify plugins when a user profile is updated */ async notifyProfileUpdated(profile) { for (const plugin of this.plugins) { if (plugin.onProfileUpdated) { try { await plugin.onProfileUpdated(profile); } catch (error) { console.error(`Error in plugin ${plugin.constructor.name} onProfileUpdated:`, error); } } } } /** * Notify plugins when a user profile is deleted */ async notifyProfileDeleted(profileId) { for (const plugin of this.plugins) { if (plugin.onProfileDeleted) { try { await plugin.onProfileDeleted(profileId); } catch (error) { console.error(`Error in plugin ${plugin.constructor.name} onProfileDeleted:`, error); } } } } /** * Notify plugins when a learning path is generated */ async notifyLearningPathGenerated(path) { for (const plugin of this.plugins) { if (plugin.onLearningPathGenerated) { try { await plugin.onLearningPathGenerated(path); } catch (error) { console.error(`Error in plugin ${plugin.constructor.name} onLearningPathGenerated:`, error); } } } } /** * Notify plugins when a learning path is completed */ async notifyLearningPathCompleted(path) { for (const plugin of this.plugins) { if (plugin.onLearningPathCompleted) { try { await plugin.onLearningPathCompleted(path); } catch (error) { console.error(`Error in plugin ${plugin.constructor.name} onLearningPathCompleted:`, error); } } } } } // Create and export a singleton instance exports.pluginManager = new PluginManager(); // Register default plugins exports.pluginManager.registerPlugin(new analytics_plugin_1.AnalyticsPlugin()); exports.pluginManager.registerPlugin(new notification_plugin_1.NotificationPlugin());