### Creating a Dynamic Plugin Source: https://github.com/elizaos-plugins/plugin-plugin-manager/blob/main/README.md Provides an example of a dynamic plugin structure, including its name, description, actions, providers, and initialization logic. This serves as a template for custom plugins. ```typescript import type { Plugin } from '@elizaos/core'; export const myDynamicPlugin: Plugin = { name: 'my-dynamic-plugin', description: 'A plugin that can be loaded at runtime', actions: [ { name: 'MY_ACTION', similes: ['my action'], description: 'Does something useful', validate: async () => true, handler: async (runtime, message, state, options, callback) => { if (callback) { await callback({ text: 'Action executed!', actions: ['MY_ACTION'], }); } }, }, ], providers: [ { name: 'myProvider', description: 'Provides data', get: async () => ({ text: 'Provider data', values: { key: 'value' }, data: {}, }), }, ], init: async (config, runtime) => { console.log('Plugin initialized!'); }, }; ``` -------------------------------- ### Plugin with Service Integration Source: https://github.com/elizaos-plugins/plugin-plugin-manager/blob/main/README.md Illustrates how to define and integrate a custom service within a plugin. The example shows a `MyService` class that extends a base `Service` class and is registered with the plugin. ```typescript class MyService extends Service { static serviceType = 'MY_SERVICE' as ServiceTypeName; static async start(runtime: IAgentRuntime): Promise { return new MyService(runtime); } async stop(): Promise { // Cleanup resources } } const pluginWithService: Plugin = { name: 'service-plugin', services: [MyService], // ... rest of plugin }; ``` -------------------------------- ### Registering a Plugin Source: https://github.com/elizaos-plugins/plugin-plugin-manager/blob/main/README.md Shows how to register a dynamic plugin with the Plugin Manager service. This makes the plugin available for loading. ```typescript // In your code const pluginManager = runtime.getService('PLUGIN_MANAGER') as PluginManagerService; const pluginId = await pluginManager.registerPlugin(myDynamicPlugin); ``` -------------------------------- ### Run Plugin Manager Test Suite Source: https://github.com/elizaos-plugins/plugin-plugin-manager/blob/main/README.md Command to execute the comprehensive test suite for the plugin manager. This command ensures all aspects of plugin functionality, including registration, error handling, and state management, are verified. ```bash npm test -- plugin-manager ``` -------------------------------- ### Dynamic Plugin with Environment Variables Source: https://github.com/elizaos-plugins/plugin-plugin-manager/blob/main/README.md Demonstrates how to create a plugin that requires specific environment variables for its initialization. The plugin manager will track missing variables, and the plugin will throw an error if they are not found. ```typescript const pluginWithEnvVars: Plugin = { name: 'api-plugin', description: 'Plugin that requires API keys', init: async (config, runtime) => { const requiredVars = ['API_KEY', 'API_SECRET']; const missing = requiredVars.filter((v) => !runtime.getSetting(v)); if (missing.length > 0) { // Plugin manager will track these missing variables throw new Error(`Missing environment variables: ${missing.join(', ')}`); } }, // ... rest of plugin }; ``` -------------------------------- ### Adding Plugin Manager to Agent Source: https://github.com/elizaos-plugins/plugin-plugin-manager/blob/main/README.md Demonstrates how to integrate the Plugin Manager into an agent's plugin list. This ensures the manager is available for dynamic plugin operations. ```typescript import { pluginManagerPlugin } from './plugin-manager'; export const projectAgent: ProjectAgent = { character, plugins: [ // ... other plugins pluginManagerPlugin, ], }; ``` -------------------------------- ### PluginManagerService API Source: https://github.com/elizaos-plugins/plugin-plugin-manager/blob/main/README.md Defines the interface for the PluginManagerService, outlining methods for registering, loading, unloading, and managing plugins and their states. ```APIDOC PluginManagerService: // Register a new plugin async registerPlugin(plugin: Plugin): Promise // Load a registered plugin async loadPlugin({ pluginId, force? }: LoadPluginParams): Promise // Unload a loaded plugin async unloadPlugin({ pluginId }: UnloadPluginParams): Promise // Get plugin state getPlugin(id: string): PluginState | undefined // Get all plugins getAllPlugins(): PluginState[] // Get loaded plugins getLoadedPlugins(): PluginState[] // Update plugin state updatePluginState(id: string, update: Partial): void ``` -------------------------------- ### PluginState Interface Source: https://github.com/elizaos-plugins/plugin-plugin-manager/blob/main/README.md Describes the structure of a PluginState object, which holds information about a plugin's lifecycle, status, dependencies, and logs. ```APIDOC PluginState: id: string; name: string; status: PluginStatus; plugin?: Plugin; missingEnvVars: string[]; buildLog: string[]; sourceCode?: string; packageJson?: any; error?: string; createdAt: number; loadedAt?: number; unloadedAt?: number; version?: string; dependencies?: Record; ``` -------------------------------- ### Plugin Status Enum Source: https://github.com/elizaos-plugins/plugin-plugin-manager/blob/main/README.md Defines the possible states a plugin can be in during its lifecycle, including building, ready, loaded, error, and unloaded. ```typescript enum PluginStatus { BUILDING = 'building', // Plugin is being built/compiled READY = 'ready', // Plugin is ready to be loaded LOADED = 'loaded', // Plugin is currently loaded and active ERROR = 'error', // Plugin encountered an error UNLOADED = 'unloaded', // Plugin was previously loaded but is now unloaded } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.