Plugin System
AIRI’s plugin system allows you to extend AIRI’s capabilities by integrating new services, tools, and functionalities. This guide covers everything you need to know about creating, testing, and publishing AIRI plugins.Plugin System Overview
The AIRI plugin system is built on a client-server architecture using WebSocket communication:Key Concepts
Plugin
Plugin
A self-contained module that extends AIRI’s functionality. Plugins connect to the server runtime via WebSocket and can:
- Receive configuration from UI
- Send events to other modules
- Expose tools and capabilities
- Integrate external services
Server Runtime
Server Runtime
The central communication hub (
@proj-airi/server-runtime) that:- Routes messages between plugins and UI
- Manages plugin lifecycle
- Handles authentication
- Maintains plugin registry
Plugin SDK
Plugin SDK
The SDK (
@proj-airi/plugin-sdk) provides:- WebSocket client abstraction
- Event handling utilities
- Type-safe communication
- State machine for lifecycle management
Plugin Protocol
Plugin Protocol
The protocol (
@proj-airi/plugin-protocol) defines:- Message formats
- Event types
- Metadata structure
- Routing rules
Plugin Architecture
Communication Flow
Plugin Lifecycle
- Initialize: Plugin creates SDK client instance
- Connect: WebSocket connection established
- Authenticate: Plugin sends auth token (if required)
- Announce: Plugin announces its presence and capabilities
- Configure: Plugin receives configuration from UI
- Active: Plugin sends/receives events
- Disconnect: WebSocket connection closed
Creating a Plugin
Project Setup
1
Create Plugin Directory
Create a new directory in the
plugins/ folder:2
Initialize Package
Create a
package.json:3
Create TypeScript Config
Create
tsconfig.json:4
Create Build Config
Create
tsdown.config.ts:Basic Plugin Implementation
Createsrc/index.ts:
Advanced Plugin Features
- State Management
- Event Routing
- Error Handling
- Heartbeat
Use XState for complex plugin state:
Plugin Examples
Example 1: Web Extension Plugin
Theairi-plugin-web-extension shows how to create a browser extension plugin:
Example 2: Claude Code Integration
Theairi-plugin-claude-code demonstrates CLI tool integration:
Example 3: Home Assistant Integration
Theairi-plugin-homeassistant is currently WIP but will demonstrate:
- Connecting to Home Assistant API
- Controlling smart home devices
- Receiving sensor data
- Automating routines
Check the
plugins/ directory for complete, working examples of each plugin type.Plugin SDK API
Client Class
Client Options
Event Structure
Standard Event Types
Testing Plugins
Unit Testing
Integration Testing
- Plugin connects and announces
- UI sees plugin in registry
- UI sends configuration
- Plugin receives and applies configuration
- Plugin sends events
- UI receives and displays events
Best Practices
Error Handling
Always handle connection errors and implement reconnection logic. Don’t let your plugin crash on network issues.
Type Safety
Use TypeScript and define strict types for your event data. This prevents runtime errors and improves DX.
Event Naming
Use consistent naming:
<plugin-name>:<action> (e.g., weather:update, music:play).Logging
Use structured logging with context. This helps debugging in production.
Configuration
Make your plugin configurable. Don’t hardcode values that users might want to change.
Documentation
Document your plugin’s events, configuration options, and requirements in a README.
Code Style
- Event Handlers
- Error Messages
- Configuration
Publishing Plugins
Internal Plugins
Internal plugins (inplugins/ directory):
- Follow monorepo conventions
- Use
workspace:^for internal dependencies - Add to workspace in root
package.json - Document in main README
External Plugins
For external/community plugins:1
Create Standalone Repository
Create a new repository following the plugin template structure.
2
Publish to npm
@your-org/airi-plugin-name3
Document Installation
Provide clear installation and usage instructions:
4
Submit to Plugin Registry
(Future feature) Submit your plugin to the AIRI plugin registry.
Plugin Distribution
Troubleshooting
Plugin doesn't connect
Plugin doesn't connect
Check:
- Server runtime is running (
pnpm -F @proj-airi/server-runtime dev) - WebSocket URL is correct
- No firewall blocking WebSocket connections
- Authentication token matches (if auth enabled)
Events not received
Events not received
Check:
- Plugin announced itself with
client.announce() - Event type matches exactly (case-sensitive)
- Event routing destinations are correct
- Plugin is authenticated (if auth enabled)
Connection drops
Connection drops
Check:
- Heartbeat is enabled and working
- Network is stable
- Server runtime hasn’t crashed
Type errors
Type errors
Check:
- Using latest
@proj-airi/plugin-sdkversion - TypeScript version is ~5.9.3
- Event data matches expected types
Resources
Plugin SDK Repo
Browse the plugin SDK source code
Example Plugins
Study working plugin implementations
Server Runtime
Understand the server architecture
Join Discord
Get help from the community
Next Steps
1
Review Architecture
Understand the architecture overview first.
2
Set Up Development
Follow the contributing guide to set up your environment.
3
Build Your Plugin
Start with a simple plugin and gradually add features.
4
Share Your Work
Publish your plugin and share it with the community!
