Plugins vs Services
| Aspect | Plugins | Services |
|---|---|---|
| Purpose | React to ticks, expose actions | Fetch and cache data |
| Lifecycle | Tied to tick cycle | Independent background |
| Interface | onTick, actions | getData, refresh |
| Reference | src/plugins/types.ts | src/services/types.ts |
Plugin Interface
Plugins hook into the agent tick lifecycle:| Field | Type | Description |
|---|---|---|
name | string | Unique identifier |
version | string | Semver version |
init | function | Called on registration |
cleanup | function | Called on agent stop |
onTick | function | Called after each tick |
actions | object | Callable methods |
Plugin interface in src/plugins/types.ts
Service Interface
Services run independently, caching data:| Method | Description |
|---|---|
initialize(runtime) | Setup with runtime context |
start() | Begin fetching |
stop() | Cleanup |
getData<T>() | Get cached data |
refresh() | Force refresh |
getHealth() | Status and stats |
Service interface in src/services/types.ts
Built-in Services
| Service | Description | Reference |
|---|---|---|
ChanService | 4chan SFW board threads | src/services/chan.ts |
NewsService | RSS/API news aggregation | src/services/news.ts |
MarketService | Crypto price data | src/services/market.ts |
Creating a Plugin
definePlugin() in src/plugins/loader.ts
Plugin Utilities
| Function | Description |
|---|---|
definePlugin(def) | Create and validate plugin |
validatePlugin(obj) | Check plugin structure |
loadPlugin(path) | Dynamic import |
sortPluginsByDependencies(plugins) | Resolve load order |
src/plugins/loader.ts
Service Types
| Type | Description |
|---|---|
news | News feeds |
market | Price data |
social | Social mentions |
calendar | Scheduling |
wallet | Blockchain data |
storage | File storage |
custom | User-defined |
ServiceType enum in src/services/types.ts