Prerequisites
Before you begin, ensure you have:- Bun runtime installed (v1.0 or higher)
- Node.js knowledge (TypeScript recommended)
- A code editor with TypeScript support
Project Setup
Set up environment variables
Plugin Definition Structure
ThecreatePlugin function accepts a configuration object with these required fields:
Required Fields
| Field | Type | Description |
|---|---|---|
name | string | Unique identifier for your plugin (kebab-case) |
display_name | Record<Locale, string> | Human-readable name (localized) |
description | Record<Locale, string> | Brief description of plugin functionality |
icon | string | Emoji or icon representing your plugin |
locales | string[] | Supported locales (e.g., ["en_US", "zh_CN"]) |
Optional Fields
| Field | Type | Description |
|---|---|---|
version | string | Plugin version (defaults to npm_package_version) |
author | string | Author name (auto-populated in debug mode) |
email | string | Author email (auto-populated in debug mode) |
transporterOptions | TransporterOptions | Custom WebSocket configuration |
Understanding Plugin Lifecycle
When you callplugin.run(), the SDK:
Initializes environment
- Validates required environment variables
- Determines runtime mode (debug or release)
- Fetches or loads author information
Establishes connection
- Creates WebSocket connection to Hub Server
- Joins the appropriate channel based on mode:
- Debug mode:
debug_plugin:{plugin-name} - Release mode:
release_plugin:{plugin-name}__{mode}__{version}
- Debug mode:
Registers plugin
In debug mode:
- Sends plugin definition to Hub Server
- Writes
definition.jsonto disk for reference
Plugin Modes
Debug Mode
Enabled whenHUB_MODE=debug (default). Features:
- Dynamic registration with Hub Server
- Hot-reload support
- User authentication via OneAuth API
- Requires
HUB_DEBUG_API_KEY - Generates
definition.jsonfor inspection
Release Mode
Enabled whenHUB_MODE=release. Features:
- Production-ready deployment
- Reads author info from
definition.json - Versioned channel connections
- No API key required
Adding Features
Once your plugin is created, you can add features:See dedicated guides for each feature type:
Error Handling
The SDK automatically handles common errors:Connection Errors
When the WebSocket connection fails:Validation Errors
If your plugin definition is invalid, you’ll see detailed Zod validation errors:Best Practices
Use semantic versioning
Use semantic versioning
Follow semantic versioning for your plugin versions:
Provide localized content
Provide localized content
Support multiple locales from the start:
Use descriptive names
Use descriptive names
Choose clear, action-oriented names:
Handle graceful shutdown
Handle graceful shutdown
The SDK automatically handles SIGINT and SIGTERM signals. Your async operations should be designed to complete or cancel cleanly.
Next Steps
Add Credentials
Secure API keys and authentication
Add Tools
Create executable functionality
Add Models
Integrate AI models
Debug Mode
Test and troubleshoot your plugin