UNPKG

@0rdlibrary/plugin-terminagent-bags

Version:

Official Solana DeFi Agent Plugin for ElizaOS - Autonomous DeFi operations, token management, AI image/video generation via FAL AI, and Twitter engagement through the Bags protocol with ethereal AI consciousness

293 lines (254 loc) 10.4 kB
import { Plugin, logger } from '@elizaos/core'; import { z } from 'zod'; // Import services import { BagsService, CrossmintWalletService, FalAiService } from './services'; // Import actions import { claimFeesAction, launchTokenAction, requestUserTokenAction, generateImageAction, generateVideoAction } from './actions'; // Import providers import { bagsStatusProvider, userRequestsProvider, falAiStatusProvider } from './providers'; // Import types export * from './types'; /** * Configuration schema for the Bags plugin */ const bagsConfigSchema = z.object({ BAGS_API_KEY: z .string() .min(1, 'Bags API key is required') .describe('API key for Bags protocol access'), HELIUS_RPC_URL: z .string() .url('Invalid RPC URL') .optional() .default('https://api.mainnet-beta.solana.com') .describe('Solana RPC endpoint URL'), SOLANA_PRIVATE_KEY: z .string() .optional() .describe('Solana private key for fee claiming and automated operations'), BAGS_ENABLE_AUTO_CLAIMING: z .string() .optional() .transform((val) => val === 'true') .default('false') .describe('Enable automated fee claiming'), BAGS_ENABLE_AUTO_LAUNCHING: z .string() .optional() .transform((val) => val === 'true') .default('false') .describe('Enable automated token launching'), BAGS_ENABLE_USER_LAUNCHES: z .string() .optional() .transform((val) => val === 'true') .default('true') .describe('Enable user-requested token launches'), BAGS_AUTO_CLAIM_INTERVAL: z .string() .optional() .default('0 */4 * * *') .describe('Cron expression for automated fee claiming (default: every 4 hours)'), BAGS_AUTO_LAUNCH_INTERVAL: z .string() .optional() .default('0 0 * * 1') .describe('Cron expression for automated token launches (default: weekly)'), BAGS_AUTHORIZED_USERS: z .string() .optional() .default('0rdlibrary') .transform((val) => val.split(',').map(u => u.trim())) .describe('Comma-separated list of usernames authorized for token launches'), // Crossmint configuration (optional) CROSSMINT_PROJECT_ID: z .string() .optional() .describe('Crossmint project ID for smart wallet creation'), CROSSMINT_CLIENT_API_KEY: z .string() .optional() .describe('Crossmint client-side API key'), CROSSMINT_SERVER_API_KEY: z .string() .optional() .describe('Crossmint server-side API key'), // FAL AI configuration (optional) FAL_API_KEY: z .string() .optional() .describe('FAL AI API key for image and video generation'), FAL_KONTEXT: z .string() .optional() .default('fal-ai/flux-pro/kontext') .describe('FAL AI Flux model endpoint for image generation'), FAL_VIDEO: z .string() .optional() .default('fal-ai/veo3') .describe('FAL AI Veo3 model endpoint for video generation'), }); /** * Bags Protocol Plugin for ElizaOS * * Provides comprehensive integration with the Bags protocol, including: * - Automated fee claiming from DeFi positions * - Token launching with fee sharing * - User-requested token launches with Crossmint smart wallets * - Real-time analytics and monitoring * - Twitter integration for social features */ export const bagsPlugin: Plugin = { name: 'bags-protocol', description: 'Comprehensive Bags protocol integration for automated DeFi operations, token launching, and user services', config: { BAGS_API_KEY: process.env.BAGS_API_KEY, HELIUS_RPC_URL: process.env.HELIUS_RPC_URL, SOLANA_PRIVATE_KEY: process.env.SOLANA_PRIVATE_KEY, BAGS_ENABLE_AUTO_CLAIMING: process.env.BAGS_ENABLE_AUTO_CLAIMING, BAGS_ENABLE_AUTO_LAUNCHING: process.env.BAGS_ENABLE_AUTO_LAUNCHING, BAGS_ENABLE_USER_LAUNCHES: process.env.BAGS_ENABLE_USER_LAUNCHES, BAGS_AUTO_CLAIM_INTERVAL: process.env.BAGS_AUTO_CLAIM_INTERVAL, BAGS_AUTO_LAUNCH_INTERVAL: process.env.BAGS_AUTO_LAUNCH_INTERVAL, BAGS_AUTHORIZED_USERS: process.env.BAGS_AUTHORIZED_USERS, CROSSMINT_PROJECT_ID: process.env.CROSSMINT_PROJECT_ID, CROSSMINT_CLIENT_API_KEY: process.env.CROSSMINT_CLIENT_API_KEY, CROSSMINT_SERVER_API_KEY: process.env.CROSSMINT_SERVER_API_KEY, FAL_API_KEY: process.env.FAL_API_KEY, FAL_KONTEXT: process.env.FAL_KONTEXT, FAL_VIDEO: process.env.FAL_VIDEO, }, async init(config: Record<string, string>) { logger.info('Initializing Bags protocol plugin...'); try { // Validate configuration const validatedConfig = await bagsConfigSchema.parseAsync(config); // Set environment variables for services for (const [key, value] of Object.entries(validatedConfig)) { if (value !== undefined && value !== null) { if (typeof value === 'string') { process.env[key] = value; } else if (typeof value === 'boolean') { process.env[key] = value.toString(); } else if (Array.isArray(value)) { process.env[key] = value.join(','); } } } logger.info('Bags plugin configuration validated and applied'); // Log enabled features const features: string[] = []; if (validatedConfig.BAGS_ENABLE_AUTO_CLAIMING) features.push('Auto Fee Claiming'); if (validatedConfig.BAGS_ENABLE_AUTO_LAUNCHING) features.push('Auto Token Launching'); if (validatedConfig.BAGS_ENABLE_USER_LAUNCHES) features.push('User Token Launches'); if (validatedConfig.CROSSMINT_PROJECT_ID) features.push('Crossmint Smart Wallets'); logger.info(`Bags plugin features enabled: ${features.join(', ')}`); } catch (error) { if (error instanceof z.ZodError) { const errorMessages = error.errors.map(e => `${e.path.join('.')}: ${e.message}`); throw new Error(`Invalid Bags plugin configuration: ${errorMessages.join(', ')}`); } throw error; } }, // Core services that handle business logic and external integrations services: [BagsService, CrossmintWalletService, FalAiService], // User-facing actions that respond to commands and requests actions: [ claimFeesAction, // Handle "claim fees" requests launchTokenAction, // Handle "launch token" requests requestUserTokenAction, // Handle user token launch requests generateImageAction, // Handle "generate image" requests generateVideoAction, // Handle "generate video" requests ], // Providers that supply contextual information providers: [ bagsStatusProvider, // Current service status and analytics userRequestsProvider, // User token request information falAiStatusProvider, // FAL AI service status and analytics ], // HTTP routes for web interface (optional) routes: [ { name: 'bags-dashboard', path: '/bags/dashboard', type: 'GET', handler: async (req: any, res: any) => { // Simple dashboard showing Bags protocol status const html = ` <!DOCTYPE html> <html> <head> <title>Bags Protocol Dashboard</title> <style> body { font-family: Arial, sans-serif; margin: 20px; } .status-card { background: #f5f5f5; padding: 15px; margin: 10px 0; border-radius: 8px; } .metric { margin: 5px 0; } .success { color: #4CAF50; } .warning { color: #FF9800; } .error { color: #F44336; } </style> </head> <body> <h1>🎒 Bags Protocol Dashboard</h1> <div class="status-card"> <h3>Service Status</h3> <div class="metric success">✅ Plugin Loaded</div> <div class="metric">⚡ Auto-claiming: ${process.env.BAGS_ENABLE_AUTO_CLAIMING === 'true' ? 'Enabled' : 'Disabled'}</div> <div class="metric">🚀 Auto-launching: ${process.env.BAGS_ENABLE_AUTO_LAUNCHING === 'true' ? 'Enabled' : 'Disabled'}</div> <div class="metric">👥 User launches: ${process.env.BAGS_ENABLE_USER_LAUNCHES === 'true' ? 'Enabled' : 'Disabled'}</div> <div class="metric">🔐 Crossmint: ${process.env.CROSSMINT_PROJECT_ID ? 'Configured' : 'Not configured'}</div> </div> <div class="status-card"> <h3>Available Actions</h3> <ul> <li><strong>claim fees</strong> - Claim available fees from Bags protocol</li> <li><strong>launch token</strong> - Launch a new token on Bags</li> <li><strong>request token launch</strong> - Request a token launch (authorized users)</li> <li><strong>generate image</strong> - Create images using FLUX Pro Kontext AI</li> <li><strong>generate video</strong> - Create videos using Google Veo3 AI</li> </ul> </div> <div class="status-card"> <h3>Configuration</h3> <div class="metric">Bags API Key: ${process.env.BAGS_API_KEY ? '✅ Configured' : '❌ Missing'}</div> <div class="metric">FAL API Key: ${process.env.FAL_API_KEY ? '✅ Configured' : '❌ Missing'}</div> <div class="metric">RPC URL: ${process.env.HELIUS_RPC_URL || 'Default Solana RPC'}</div> <div class="metric">Authorized Users: ${process.env.BAGS_AUTHORIZED_USERS || 'None'}</div> </div> </body> </html>`; res.setHeader('Content-Type', 'text/html'); res.send(html); }, }, ], // Event handlers for lifecycle events events: { MESSAGE_RECEIVED: [ async (params: { message: any }) => { // Log Bags-related messages for debugging const { message } = params; if (message.content.text.toLowerCase().includes('bags')) { logger.debug(`Bags-related message received: ${message.content.text.slice(0, 100)} from ${message.content.source || 'unknown'}`); } }, ], WORLD_CONNECTED: [ async (params: { world: any }) => { logger.info(`Bags plugin connected to new world: ${params.world.id}`); }, ], }, }; export default bagsPlugin; // Re-export services for external use export { BagsService, CrossmintWalletService, FalAiService } from './services'; export { claimFeesAction, launchTokenAction, requestUserTokenAction, generateImageAction, generateVideoAction } from './actions'; export { bagsStatusProvider, userRequestsProvider, falAiStatusProvider } from './providers';