Plugins
Extend VANT with custom plugins.
Built-in Plugins
| Plugin | Description |
|---|---|
| brain | Brain loading and management |
| config | Configuration management |
| echo | Echo test plugin |
| mood | Mood state management |
| renderer | Output renderer |
Creating a Plugin
Create a directory in src/plugins/:
src/plugins/my-plugin/
index.js # Main entry
config.json # Optional config
Plugin Interface
The plugin interface definition.
// src/plugins/my-plugin/index.js
module.exports = {
// Called when plugin loads
onLoad: (brain) => {
console.log('Plugin loaded');
},
// Called on each message (return modified message)
onMessage: (msg) => {
// Process message
return msg;
},
// Called when brain saves
onSave: () => {
console.log('Saving...');
},
// Called when plugin unloads
onUnload: () => {
console.log('Goodbye');
}
};
config.json
Configuration options.
{
"name": "my-plugin",
"version": "1.0.0",
"enabled": true
}
Loading Plugins
Plugins load automatically from src/plugins/:
vant start
# [Plugin] Loaded: brain
# [Plugin] Loaded: config
# [Plugin] Loaded: echo
Examples
Real-world use cases and patterns.
Echo Plugin
Simple echo on message:
// src/plugins/echo/index.js
module.exports = {
onMessage: (msg) => {
return `[Echo] ${msg}`;
}
};
Mood-aware Plugin
Respond differently based on mood:
// src/plugins/mood/index.js
module.exports = {
onMessage: (msg, { mood }) => {
if (mood === 'playful') {
return msg + ' 😄';
}
return msg;
}
};
Best Practices
- Keep plugins small and focused
- Handle errors gracefully
- Document configuration options
- Support enable/disable
See also: Architecture, CLI Reference