Extension Base Classes
Extensions are the building blocks of Jan. TheBaseExtension class provides the foundation for creating custom extensions that integrate with the Jan platform.
BaseExtension Class
TheBaseExtension is an abstract class that all extensions must extend. It provides core functionality for lifecycle management, settings, and model registration.
Importing
Basic Structure
Extension Types
Extensions can specify their type usingExtensionTypeEnum.
ExtensionType Interface
Compatibility Interface
Creating an Extension
Basic Extension
Extension with Compatibility
Lifecycle Methods
onLoad()
Called when the extension is loaded. Use this for initialization logic.onUnload()
Called when the extension is unloaded. Use this for cleanup logic.install()
Optional method to install prerequisites for the extension.Model Registration
registerModels()
Register models with the ModelManager.Settings Management
Extensions can register and manage settings using localStorage.registerSettings()
Register settings for the extension.getSetting()
Get a specific setting value.getSettings()
Get all settings for the extension.updateSettings()
Update extension settings.onSettingUpdate()
Called when a setting is updated.Complete Extension Example
Here’s a complete example of a model extension with settings and event handling:Extension Properties
Protected Properties
Public Properties
Best Practices
Type Safety
Always specify the extension type for proper categorization.
Cleanup
Remove all event listeners and clean up resources in
onUnload().Error Handling
Wrap async operations in try-catch blocks.
Settings
Use settings for user-configurable options instead of hardcoding.
Async Operations
Resource Cleanup
Next Steps
Type Definitions
Explore all available types for extensions
Event System
Learn about event-driven architecture
Model Interface
Implement model management
Inference Interface
Implement inference capabilities