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

65 lines (55 loc) 2.1 kB
import { TokenLaunchParams } from '../types'; import { logger } from '@elizaos/core'; /** * Parse token parameters from user message text * Extracts name, symbol, description, and optional fields */ export function parseTokenParameters(text: string): TokenLaunchParams | null { try { const params: Partial<TokenLaunchParams> = {}; // Extract name (look for "name:" or similar patterns) const nameMatch = text.match(/(?:name|token name):\s*([^\n,]+)/i); if (nameMatch) { params.name = nameMatch[1].trim(); } // Extract symbol (look for "symbol:" or "$SYMBOL") const symbolMatch = text.match(/(?:symbol|ticker):\s*\$?([A-Z0-9]{1,10})/i) || text.match(/\$([A-Z0-9]{1,10})/); if (symbolMatch) { params.symbol = symbolMatch[1].trim().toUpperCase(); } // Extract description const descMatch = text.match(/(?:description|desc|about):\s*([^\n,]+)/i); if (descMatch) { params.description = descMatch[1].trim(); } // Extract image URL const imageMatch = text.match(/(?:image|img|logo):\s*(https?:\/\/[^\s,]+)/i); if (imageMatch) { params.imageUrl = imageMatch[1].trim(); } // Extract website const websiteMatch = text.match(/(?:website|site|web):\s*(https?:\/\/[^\s,]+)/i); if (websiteMatch) { params.website = websiteMatch[1].trim(); } // Extract Twitter const twitterMatch = text.match(/(?:twitter|x\.com):\s*(https?:\/\/[^\s,]+)/i); if (twitterMatch) { params.twitter = twitterMatch[1].trim(); } // Extract initial buy amount const buyMatch = text.match(/(?:initial buy|buy amount):\s*(\d*\.?\d+)/i); if (buyMatch) { params.initialBuyAmountSOL = parseFloat(buyMatch[1]); } // Return null if essential fields are missing if (!params.name || !params.symbol || !params.description) { return null; } return params as TokenLaunchParams; } catch (error) { logger.error(`Error parsing token parameters: ${error instanceof Error ? error.message : String(error)}`); return null; } }