2.1 XpertPlugin
XpertPlugin is the main entry interface for plugins, defining plugin metadata (meta), configuration (config), lifecycle methods, and module registration logic.
- meta: Basic plugin metadata, including
name,version,category,icon,description, etc. - config: Defines the plugin’s configuration schema (based on
zod), supporting default values and UI form rendering. - register: Returns a
DynamicModuleto mount the plugin to the main application (optionally as global).
2.2 Plugin Lifecycle
The plugin system provides a complete set of lifecycle hooks for each plugin, allowing developers to execute initialization or cleanup logic at different stages.- onInit: Suitable for resource initialization (e.g., loading configs, registering resource pools).
- onStart: Suitable for starting background tasks or service listeners.
- onStop: Suitable for cleaning up resources, closing connections, releasing caches.
2.3 Plugin Health Check
Plugins can implement thecheckHealth method to report their running status, enabling unified health monitoring by the host system.
- status: Running status (
upordown) - details: Optional dependency check details, such as API connectivity or database status
2.4 Plugin Context
PluginContext provides plugins with runtime access to the host system, including application context, logging service, and configuration.
- app: NestJS’s
INestApplicationContext, allowing access to the DI container. - logger: Unified logging interface, supporting
debug,log,warn,error. - config: Final config object after zod validation and merging defaults.
- resolve: Retrieve other providers from the NestJS container.
2.5 Plugin Configuration Specification
Each plugin can define a configuration specification to constrain and validate config parameters, usually implemented via azod schema:
- Supports type safety (zod type inference)
- Supports default values and secure input (e.g., API key secrets)
- The host system automatically renders the config UI based on the schema
2.6 XpertServerPlugin Decorator
@XpertServerPlugin is an enhanced Nestjs Module class decorator, used to register plugins as NestJS modules and attach plugin metadata.
- Essentially extends NestJS’s
@Moduledecorator - Supports registering submodules, services, controllers, entities, etc.
- The plugin thus becomes a complete NestJS dynamic module
2.7 Enhancement Points
Enhancement points are the key mechanism for plugins to extend the host system. The host system defines a series of strategy interfaces, and plugins can implement these interfaces and use decorators to be automatically discovered and registered.IntegrationStrategy
Used to connect external systems or API services, such as Firecrawl, OpenAI, etc.- meta: Metadata for the integration provider (name, description, icon, etc.)
- execute: Executes the integration logic (e.g., calling external APIs)
DocumentSourceStrategy
Used to connect new data sources, such as web crawlers, file parsers, databases. Plugins only need to implement the corresponding interface to make the data source available to agents/BI.2.8 Strategy Registry
All strategy classes (Integration, DocumentSource, etc.) are registered to the strategy registry via decorators + NestJS dependency injection. For example, IntegrationStrategy:IntegrationStrategyRegistryautomatically discovers classes decorated with@IntegrationStrategyKey- Plugins do not need to manually register strategies; implementing the interface and using the decorator is enough for system recognition
📌 Summary:
XpertPlugindefines plugin metadata, configuration, and lifecycleXpertServerPluginregisters plugins as NestJS modules- Enhancement points (Strategy) are the core for plugins to extend host system functionality
- All plugins form extensible and maintainable modules via lifecycle + strategy interfaces + config schema