Skip to main content

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.
The plugin SDK (@proj-airi/plugin-sdk) is currently a work in progress. APIs may change without warning. Check the GitHub repository for the latest updates.

Plugin System Overview

The AIRI plugin system is built on a client-server architecture using WebSocket communication:

Key Concepts

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
The central communication hub (@proj-airi/server-runtime) that:
  • Routes messages between plugins and UI
  • Manages plugin lifecycle
  • Handles authentication
  • Maintains plugin registry
The SDK (@proj-airi/plugin-sdk) provides:
  • WebSocket client abstraction
  • Event handling utilities
  • Type-safe communication
  • State machine for lifecycle management
The protocol (@proj-airi/plugin-protocol) defines:
  • Message formats
  • Event types
  • Metadata structure
  • Routing rules

Plugin Architecture

Communication Flow

Plugin Lifecycle

  1. Initialize: Plugin creates SDK client instance
  2. Connect: WebSocket connection established
  3. Authenticate: Plugin sends auth token (if required)
  4. Announce: Plugin announces its presence and capabilities
  5. Configure: Plugin receives configuration from UI
  6. Active: Plugin sends/receives events
  7. 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

Create src/index.ts:

Advanced Plugin Features

Use XState for complex plugin state:

Plugin Examples

Example 1: Web Extension Plugin

The airi-plugin-web-extension shows how to create a browser extension plugin:

Example 2: Claude Code Integration

The airi-plugin-claude-code demonstrates CLI tool integration:

Example 3: Home Assistant Integration

The airi-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

Test the full flow:
  1. Plugin connects and announces
  2. UI sees plugin in registry
  3. UI sends configuration
  4. Plugin receives and applies configuration
  5. Plugin sends events
  6. 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

Publishing Plugins

Internal Plugins

Internal plugins (in plugins/ directory):
  1. Follow monorepo conventions
  2. Use workspace:^ for internal dependencies
  3. Add to workspace in root package.json
  4. 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

Use scoped package name: @your-org/airi-plugin-name
3

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

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)
Debug:
Check:
  • Plugin announced itself with client.announce()
  • Event type matches exactly (case-sensitive)
  • Event routing destinations are correct
  • Plugin is authenticated (if auth enabled)
Debug:
Check:
  • Heartbeat is enabled and working
  • Network is stable
  • Server runtime hasn’t crashed
Fix:
Check:
  • Using latest @proj-airi/plugin-sdk version
  • TypeScript version is ~5.9.3
  • Event data matches expected types
Fix:

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!