__init__.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. """
  2. Plugin System for Trixy Application
  3. This module provides a comprehensive plugin system with:
  4. - Dynamic plugin loading from ./plugins/*/ directories
  5. - Base TrixyPlugin class with event integration
  6. - Plugin lifecycle management (load, initialize, enable, disable, unload)
  7. - Thread-safe plugin operations
  8. - Configuration management with auto-type casting
  9. - Health monitoring and error isolation
  10. - Hot-reload capability for development
  11. Plugin Structure:
  12. ./plugins/plugin_name/
  13. ├── main.py # Plugin class (extends TrixyPlugin)
  14. ├── config.json # Plugin configuration
  15. └── config_view.py # Optional: custom TUI configuration
  16. Usage:
  17. from trixy_core.plugins import PluginManager, TrixyPlugin
  18. # Create plugin manager
  19. plugin_manager = PluginManager(application)
  20. # Load all plugins
  21. plugin_manager.load_all_plugins()
  22. # Enable/disable plugins
  23. plugin_manager.enable_plugin("my_plugin")
  24. plugin_manager.disable_plugin("my_plugin")
  25. # Hot reload during development
  26. plugin_manager.reload_plugin("my_plugin")
  27. Plugin Development:
  28. from trixy_core.plugins import TrixyPlugin
  29. from trixy_core.events import TrixyEvent
  30. class MyPlugin(TrixyPlugin):
  31. @TrixyEvent(["wakeword_received", "text_received"])
  32. def handle_events(self, event_name, event_data):
  33. # React to events
  34. pass
  35. """
  36. from .trixy_plugin import (
  37. TrixyPlugin,
  38. PluginState,
  39. PluginError,
  40. PluginLoadError,
  41. PluginConfigError,
  42. PluginStateError
  43. )
  44. from .plugin_manager import (
  45. PluginManager,
  46. PluginInfo,
  47. PluginHealthStatus,
  48. PluginManagerError
  49. )
  50. from .plugin_loader import (
  51. PluginLoader,
  52. PluginLoadResult,
  53. PluginLoaderError
  54. )
  55. from .config_handler import (
  56. PluginConfigHandler,
  57. ConfigValue,
  58. ConfigHandlerError
  59. )
  60. # Utility function for logging (consistent with other modules)
  61. def pprint(message: str) -> None:
  62. """
  63. Plugin system logging function that adapts based on mode.
  64. In production: uses proper logging, in debug: uses print.
  65. """
  66. print(f"[PLUGINS] {message}")
  67. # Export main classes and functions
  68. __all__ = [
  69. # Core plugin classes
  70. 'TrixyPlugin',
  71. 'PluginManager',
  72. 'PluginLoader',
  73. 'PluginConfigHandler',
  74. # Plugin state and info
  75. 'PluginState',
  76. 'PluginInfo',
  77. 'PluginHealthStatus',
  78. 'PluginLoadResult',
  79. 'ConfigValue',
  80. # Exceptions
  81. 'PluginError',
  82. 'PluginLoadError',
  83. 'PluginConfigError',
  84. 'PluginStateError',
  85. 'PluginManagerError',
  86. 'PluginLoaderError',
  87. 'ConfigHandlerError',
  88. # Utilities
  89. 'pprint'
  90. ]
  91. # Version information
  92. __version__ = "1.0.0"