| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- """
- Plugin System for Trixy Application
- This module provides a comprehensive plugin system with:
- - Dynamic plugin loading from ./plugins/*/ directories
- - Base TrixyPlugin class with event integration
- - Plugin lifecycle management (load, initialize, enable, disable, unload)
- - Thread-safe plugin operations
- - Configuration management with auto-type casting
- - Health monitoring and error isolation
- - Hot-reload capability for development
- Plugin Structure:
- ./plugins/plugin_name/
- ├── main.py # Plugin class (extends TrixyPlugin)
- ├── config.json # Plugin configuration
- └── config_view.py # Optional: custom TUI configuration
- Usage:
- from trixy_core.plugins import PluginManager, TrixyPlugin
-
- # Create plugin manager
- plugin_manager = PluginManager(application)
-
- # Load all plugins
- plugin_manager.load_all_plugins()
-
- # Enable/disable plugins
- plugin_manager.enable_plugin("my_plugin")
- plugin_manager.disable_plugin("my_plugin")
-
- # Hot reload during development
- plugin_manager.reload_plugin("my_plugin")
- Plugin Development:
- from trixy_core.plugins import TrixyPlugin
- from trixy_core.events import TrixyEvent
-
- class MyPlugin(TrixyPlugin):
- @TrixyEvent(["wakeword_received", "text_received"])
- def handle_events(self, event_name, event_data):
- # React to events
- pass
- """
- from .trixy_plugin import (
- TrixyPlugin,
- PluginState,
- PluginError,
- PluginLoadError,
- PluginConfigError,
- PluginStateError
- )
- from .plugin_manager import (
- PluginManager,
- PluginInfo,
- PluginHealthStatus,
- PluginManagerError
- )
- from .plugin_loader import (
- PluginLoader,
- PluginLoadResult,
- PluginLoaderError
- )
- from .config_handler import (
- PluginConfigHandler,
- ConfigValue,
- ConfigHandlerError
- )
- # Utility function for logging (consistent with other modules)
- def pprint(message: str) -> None:
- """
- Plugin system logging function that adapts based on mode.
- In production: uses proper logging, in debug: uses print.
- """
- print(f"[PLUGINS] {message}")
- # Export main classes and functions
- __all__ = [
- # Core plugin classes
- 'TrixyPlugin',
- 'PluginManager',
- 'PluginLoader',
- 'PluginConfigHandler',
-
- # Plugin state and info
- 'PluginState',
- 'PluginInfo',
- 'PluginHealthStatus',
- 'PluginLoadResult',
- 'ConfigValue',
-
- # Exceptions
- 'PluginError',
- 'PluginLoadError',
- 'PluginConfigError',
- 'PluginStateError',
- 'PluginManagerError',
- 'PluginLoaderError',
- 'ConfigHandlerError',
-
- # Utilities
- 'pprint'
- ]
- # Version information
- __version__ = "1.0.0"
|