UNPKG

@agentdao/core

Version:

Core functionality, skills, and ready-made UI components for AgentDAO - Web3 subscriptions, content generation, social media, help support, live chat, RSS fetching, web search, and agent pricing integration

691 lines (690 loc) โ€ข 25.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const WebSearchSkill_1 = require("./WebSearchSkill"); const ContentGeneratorSkill_1 = require("./ContentGeneratorSkill"); const SocialMediaSkill_1 = require("./SocialMediaSkill"); const PhotoSkill_1 = require("./PhotoSkill"); const HelpSupportSkill_1 = require("./HelpSupportSkill"); const Web3SubscriptionSkill_1 = require("./Web3SubscriptionSkill"); const FundAgent_1 = require("./FundAgent"); const TokenGatingSkill_1 = require("./TokenGatingSkill"); const TokenGatingService_1 = require("./TokenGatingService"); const LiveChatSkill_1 = require("./LiveChatSkill"); // Load environment variables from root app const dotenv_1 = require("dotenv"); const path_1 = require("path"); // Load .env.local from the root directory (0, dotenv_1.config)({ path: (0, path_1.resolve)(__dirname, '../../../.env.local') }); // Use real environment variables const OPENAI_API_KEY = process.env.OPENAI_API_KEY || 'test-api-key'; const UNSPLASH_ACCESS_KEY = process.env.UNSPLASH_ACCESS_KEY || 'test-unsplash-key'; const TWITTER_API_KEY = process.env.TWITTER_API_KEY || 'test-twitter-key'; const LINKEDIN_CLIENT_ID = process.env.LINKEDIN_CLIENT_ID || 'test-linkedin-key'; const FACEBOOK_APP_ID = process.env.FACEBOOK_APP_ID || 'test-facebook-key'; const INSTAGRAM_ACCESS_TOKEN = process.env.INSTAGRAM_ACCESS_TOKEN || 'test-instagram-key'; const RPC_URL = process.env.RPC_URL || 'https://mainnet.base.org'; const DATABASE_ENDPOINT = process.env.DATABASE_ENDPOINT || 'http://localhost:3000/api/dashboard'; // Blockchain configuration const TOKEN_ADDRESS = process.env.TOKEN_ADDRESS || '0x1234567890123456789012345678901234567890'; const CHAIN_ID = parseInt(process.env.CHAIN_ID || '8453'); // 8453 = Base, 1 = Ethereum, 137 = Polygon, etc. const NETWORK_NAME = process.env.NETWORK_NAME || 'Base'; // Test configurations const testConfigs = { webSearch: { agentId: 'test-web-search', agentName: 'Test Web Search Agent', domain: 'test.example.com', ai: { provider: 'openai', apiKey: OPENAI_API_KEY, model: 'gpt-4', maxTokens: 2000, temperature: 0.7 }, search: { provider: 'openai', apiKey: OPENAI_API_KEY, maxResults: 5, includeImages: false, includeNews: false }, database: { endpoint: DATABASE_ENDPOINT, apiKey: OPENAI_API_KEY } }, contentGenerator: { agentId: 'test-content-generator', agentName: 'Test Content Generator Agent', domain: 'test.example.com', ai: { provider: 'openai', apiKey: OPENAI_API_KEY, model: 'gpt-4', temperature: 0.7, maxTokens: 1000, retryAttempts: 3 }, templates: { 'blog-post': { name: 'Blog Post', type: 'blog', prompt: 'Write a blog post about {{topic}}', maxLength: 2000, format: 'markdown', variables: ['topic'], examples: ['Example blog post about AI.'] } }, brand: { name: 'Test Brand', voice: 'Professional', tone: 'Informative', keywords: ['test', 'example'], styleGuide: 'Professional and informative' }, seo: { enabled: true, keywords: ['ai', 'artificial intelligence'], metaDescriptionLength: 160, titleMaxLength: 60, autoOptimize: true }, categories: { technology: { name: 'Technology', description: 'Technology related content', keywords: ['ai', 'tech'], templates: ['blog-post'] }, ai: { name: 'AI', description: 'Artificial Intelligence content', keywords: ['ai', 'machine learning'], templates: ['blog-post'] } }, integration: { autoSave: false, saveLocation: 'database', publishAutomatically: false, reviewRequired: false }, database: { endpoint: DATABASE_ENDPOINT, apiKey: OPENAI_API_KEY } }, socialMedia: { agentId: 'test-social-media', agentName: 'Test Social Media Agent', domain: 'test.example.com', platforms: { twitter: { enabled: true, apiKey: TWITTER_API_KEY, apiSecret: 'test-api-secret', accessToken: 'test-access-token', accessTokenSecret: 'test-access-token-secret', username: 'testuser', autoReply: false } }, strategy: { postingSchedule: { enabled: false, timezone: 'UTC', schedule: {} }, contentMix: { promotional: 30, educational: 40, entertaining: 20, userGenerated: 10 }, hashtagStrategy: { maxHashtags: 5, trendingHashtags: true, brandedHashtags: ['#test', '#example'] } }, engagement: { autoRespond: false, responseTemplates: {}, mentionMonitoring: { enabled: false, keywords: [], autoRespond: false } }, analytics: { trackPerformance: true, reportFrequency: 'weekly', exportData: true, goals: { followers: 1000, engagement: 5, reach: 10000 } }, database: { endpoint: DATABASE_ENDPOINT, apiKey: OPENAI_API_KEY } }, photo: { agentId: 'test-photo', agentName: 'Test Photo Agent', domain: 'test.example.com', providers: { unsplash: { enabled: true, apiKey: UNSPLASH_ACCESS_KEY }, pexels: { enabled: true, apiKey: OPENAI_API_KEY }, pixabay: { enabled: true, apiKey: OPENAI_API_KEY } }, search: { defaultProvider: 'all', maxResults: 20, defaultSize: 'medium', includeOrientation: true }, database: { endpoint: DATABASE_ENDPOINT, apiKey: OPENAI_API_KEY } }, helpSupport: { agentId: 'test-help-support', agentName: 'Test Help Support Agent', domain: 'test.example.com', ai: { provider: 'openai', apiKey: OPENAI_API_KEY, model: 'gpt-4', temperature: 0.7, maxTokens: 500 }, knowledgeBase: { type: 'url', sources: ['https://example.com/docs'], autoUpdate: false }, autoResponse: true, escalationThreshold: 3, humanSupport: { enabled: false, email: 'support@example.com', phone: '+1234567890', responseTime: '24 hours' }, database: { endpoint: DATABASE_ENDPOINT, apiKey: OPENAI_API_KEY } }, web3Subscription: { agentId: 'test-web3-subscription', agentName: 'Test Web3 Subscription Agent', domain: 'test.example.com', adaoToken: { address: '0x1234567890123456789012345678901234567890', decimals: 18, network: 'base', logo: 'https://example.com/logo.png' }, plans: { basic: { name: 'Basic Plan', description: 'Basic features', features: ['chat', 'help'], pricing: { monthly: { price: 10, discount: 0 }, quarterly: { price: 25, discount: 5 }, annually: { price: 90, discount: 20 } }, billing: { defaultPeriod: 'monthly', allowPeriodChange: true, prorationEnabled: true } } }, provider: { rpcUrl: RPC_URL, chainId: CHAIN_ID, explorer: 'https://test-explorer.com' }, payment: { autoApprove: false, requireConfirmation: true, refundPolicy: { enabled: true, gracePeriod: 7 }, billing: { allowTrial: true, trialDays: 7, gracePeriodDays: 3 } }, integration: { webhookUrl: 'https://test-api.com/webhooks', redirectUrl: 'https://test-app.com/success', successMessage: 'Success!', errorMessage: 'Error!' }, analytics: { trackRevenue: true, trackUsage: true, exportData: true }, database: { endpoint: DATABASE_ENDPOINT, apiKey: OPENAI_API_KEY } }, fundAgent: { chainId: CHAIN_ID, network: NETWORK_NAME, rpcUrl: RPC_URL, tokenAddress: TOKEN_ADDRESS, tokenSymbol: 'TEST', tokenDecimals: 18, safeFactoryAddress: '0x1234567890123456789012345678901234567890', minDeposit: 100, agentAddress: '0x1234567890123456789012345678901234567890', database: { endpoint: DATABASE_ENDPOINT, apiKey: OPENAI_API_KEY } }, tokenGating: { subscription: { agentId: 'test-token-gating', agentName: 'Test Token Gating Agent', domain: 'test.example.com', adaoToken: { address: '0x1234567890123456789012345678901234567890', decimals: 18, network: 'base', logo: 'https://example.com/logo.png' }, plans: { basic: { name: 'Basic Plan', description: 'Basic features', features: ['chat', 'help'], pricing: { monthly: { price: 10, discount: 0 }, quarterly: { price: 25, discount: 5 }, annually: { price: 90, discount: 20 } }, billing: { defaultPeriod: 'monthly', allowPeriodChange: true, prorationEnabled: true } } }, provider: { rpcUrl: RPC_URL, chainId: CHAIN_ID, explorer: 'https://mainnet.base.org' }, payment: { autoApprove: false, requireConfirmation: true, refundPolicy: { enabled: true, gracePeriod: 7 }, billing: { allowTrial: true, trialDays: 7, gracePeriodDays: 3 } }, integration: { webhookUrl: 'https://test-api.com/webhooks', redirectUrl: 'https://test-app.com/success', successMessage: 'Success!', errorMessage: 'Error!' }, analytics: { trackRevenue: true, trackUsage: true, exportData: true }, database: { endpoint: DATABASE_ENDPOINT, apiKey: OPENAI_API_KEY } }, fundAgent: { chainId: CHAIN_ID, network: NETWORK_NAME, rpcUrl: RPC_URL, tokenAddress: TOKEN_ADDRESS, tokenSymbol: 'ADAO', tokenDecimals: 18, safeFactoryAddress: '0x1234567890123456789012345678901234567890', minDeposit: 100, agentAddress: '0x1234567890123456789012345678901234567890' }, gating: { requireSafeWallet: false, autoCreateSafe: false, minTokenForAccess: 10, gracePeriod: 7, features: { chat: { requiredPlan: 'basic', requiredTokens: 0, requireSafeWallet: false }, help: { requiredPlan: 'basic', requiredTokens: 0, requireSafeWallet: false } } }, database: { endpoint: DATABASE_ENDPOINT, apiKey: OPENAI_API_KEY } }, liveChat: { agentId: 'test-live-chat', agentName: 'Test Live Chat Agent', domain: 'test.example.com', ai: { provider: 'openai', apiKey: OPENAI_API_KEY, model: 'gpt-4', temperature: 0.7 }, chatHistory: { storage: 'database', retentionDays: 30, maxMessages: 1000 }, features: { typingIndicator: true, readReceipts: true, fileSharing: false, voiceMessages: false, emojiReactions: true }, moderation: { enabled: true, filters: ['spam', 'profanity'], autoBlock: false, profanityFilter: true, spamDetection: true }, database: { endpoint: DATABASE_ENDPOINT, apiKey: OPENAI_API_KEY } } }; async function testWebSearchSkill() { console.log('๐Ÿงช Testing WebSearchSkill...'); try { const skill = new WebSearchSkill_1.WebSearchSkill(testConfigs.webSearch); // Test web search functionality const searchResult = await skill.searchWeb({ query: 'artificial intelligence' }); console.log('โœ… WebSearchSkill.searchWeb() - Success'); console.log(` Results: ${searchResult.length} found`); // Test save search (should throw error without database) try { await skill.saveSearch('test query', searchResult); console.log('โŒ WebSearchSkill.saveSearch() - Should have thrown error'); } catch (error) { console.log('โœ… WebSearchSkill.saveSearch() - Correctly throws error without database'); } return true; } catch (error) { console.log('โŒ WebSearchSkill test failed:', error); return false; } } async function testContentGeneratorSkill() { console.log('๐Ÿงช Testing ContentGeneratorSkill...'); try { // Use the config directly since it already matches the type const skill = new ContentGeneratorSkill_1.ContentGeneratorSkill(testConfigs.contentGenerator); // Test content generation const content = await skill.generateBlogPost('AI', ['artificial intelligence', 'machine learning']); console.log('โœ… ContentGeneratorSkill.generateBlogPost() - Success'); console.log(` Generated content length: ${content.content.length} characters`); // Test save content (should throw error without database) // try { // await skill.saveContent({ // id: 'test', // type: 'blog' as const, // title: 'Test Blog Post', // content: content.content, // metadata: {}, // timestamp: new Date().toISOString() // }); // console.log('โŒ ContentGeneratorSkill.saveContent() - Should have thrown error'); // } catch (error) { // console.log('โœ… ContentGeneratorSkill.saveContent() - Correctly throws error without database'); // } return true; } catch (error) { console.log('โŒ ContentGeneratorSkill test failed:', error); return false; } } async function testSocialMediaSkill() { console.log('๐Ÿงช Testing SocialMediaSkill...'); try { const skill = new SocialMediaSkill_1.SocialMediaSkill(testConfigs.socialMedia); // Test draft creation const draftId = await skill.saveDraft('Test post content', ['twitter']); console.log('โœ… SocialMediaSkill.saveDraft() - Success'); console.log(` Draft ID: ${draftId}`); // Test get drafts (should throw error without database) try { await skill.getDraftPosts(); console.log('โŒ SocialMediaSkill.getDraftPosts() - Should have thrown error'); } catch (error) { console.log('โœ… SocialMediaSkill.getDraftPosts() - Correctly throws error without database'); } return true; } catch (error) { console.log('โŒ SocialMediaSkill test failed:', error); return false; } } async function testPhotoSkill() { console.log('๐Ÿงช Testing PhotoSkill...'); try { const skill = new PhotoSkill_1.PhotoSkill(testConfigs.photo); // Test photo search const photos = await skill.searchPhotos({ query: 'sunset' }); console.log('โœ… PhotoSkill.searchPhotos() - Success'); console.log(` Found ${photos.length} photos`); // Test get categories const categories = await skill.getCategories(); console.log('โœ… PhotoSkill.getCategories() - Success'); console.log(` Available categories: ${categories.length}`); return true; } catch (error) { console.log('โŒ PhotoSkill test failed:', error); return false; } } async function testHelpSupportSkill() { console.log('๐Ÿงช Testing HelpSupportSkill...'); try { const skill = new HelpSupportSkill_1.HelpSupportSkill(testConfigs.helpSupport); // Test message handling const response = await skill.handleMessage('How do I use this feature?', { userId: 'test-user' }); console.log('โœ… HelpSupportSkill.handleMessage() - Success'); console.log(` Response confidence: ${response.confidence}`); // Test start conversation const conversationId = await skill.startConversation('test-user'); console.log('โœ… HelpSupportSkill.startConversation() - Success'); console.log(` Conversation ID: ${conversationId}`); return true; } catch (error) { console.log('โŒ HelpSupportSkill test failed:', error); return false; } } async function testWeb3SubscriptionSkill() { console.log('๐Ÿงช Testing Web3SubscriptionSkill...'); try { const skill = new Web3SubscriptionSkill_1.Web3SubscriptionSkill(testConfigs.web3Subscription); // Test subscription check (should throw error without database) try { await skill.checkSubscription('0x1234567890123456789012345678901234567890'); console.log('โŒ Web3SubscriptionSkill.checkSubscription() - Should have thrown error'); } catch (error) { console.log('โœ… Web3SubscriptionSkill.checkSubscription() - Correctly throws error without database'); } // Test available plans const plans = await skill.getAvailablePlans(); console.log('โœ… Web3SubscriptionSkill.getAvailablePlans() - Success'); console.log(` Available plans: ${plans.length}`); return true; } catch (error) { console.log('โŒ Web3SubscriptionSkill test failed:', error); return false; } } async function testFundAgent() { console.log('๐Ÿงช Testing FundAgent...'); try { const fundAgent = new FundAgent_1.FundAgent(testConfigs.fundAgent); // Test token balance (should return 0 for test address) const balance = await fundAgent.getTokenBalance('0x1234567890123456789012345678901234567890'); console.log('โœ… FundAgent.getTokenBalance() - Success'); console.log(` Balance: ${balance} TEST tokens`); // Test wallet status (should return mock data) const status = await fundAgent.getWalletStatus('0x1234567890123456789012345678901234567890'); console.log('โœ… FundAgent.getWalletStatus() - Success'); console.log(` Wallet address: ${status.address}`); return true; } catch (error) { console.log('โŒ FundAgent test failed:', error); return false; } } async function testTokenGatingSkill() { console.log('๐Ÿงช Testing TokenGatingSkill...'); try { const skill = new TokenGatingSkill_1.TokenGatingSkill(testConfigs.tokenGating); // Test user access check const access = await skill.checkUserAccess('0x1234567890123456789012345678901234567890'); console.log('โœ… TokenGatingSkill.checkUserAccess() - Success'); console.log(` Has access: ${access.hasAccess}`); console.log(` Token balance: ${access.adaoBalance} TEST`); // Test token balance const balance = await skill.getTokenBalance('0x1234567890123456789012345678901234567890'); console.log('โœ… TokenGatingSkill.getTokenBalance() - Success'); console.log(` Balance: ${balance} TEST tokens`); return true; } catch (error) { console.log('โŒ TokenGatingSkill test failed:', error); return false; } } async function testTokenGatingService() { console.log('๐Ÿงช Testing TokenGatingService...'); try { const service = new TokenGatingService_1.TokenGatingService(testConfigs.tokenGating); // Test user access check const access = await service.checkUserAccess('0x1234567890123456789012345678901234567890'); console.log('โœ… TokenGatingService.checkUserAccess() - Success'); console.log(` Has access: ${access.hasAccess}`); console.log(` Token balance: ${access.adaoBalance} TEST`); // Test available plans const plans = await service.getAvailablePlansForUser('0x1234567890123456789012345678901234567890'); console.log('โœ… TokenGatingService.getAvailablePlansForUser() - Success'); console.log(` Available plans: ${plans.length}`); return true; } catch (error) { console.log('โŒ TokenGatingService test failed:', error); return false; } } async function testLiveChatSkill() { console.log('๐Ÿงช Testing LiveChatSkill...'); try { const skill = new LiveChatSkill_1.LiveChatSkill(testConfigs.liveChat); // Test start chat const chatId = await skill.startChat('test-user', { chatId: 'test-chat', userId: 'test-user', userAgent: 'test', location: 'test' }); console.log('โœ… LiveChatSkill.startChat() - Success'); console.log(` Chat ID: ${chatId}`); // Test send message const message = await skill.sendMessage(chatId, 'Hello, how can you help me?', 'test-user'); console.log('โœ… LiveChatSkill.sendMessage() - Success'); console.log(` Message ID: ${message.id}`); return true; } catch (error) { console.log('โŒ LiveChatSkill test failed:', error); return false; } } async function runAllTests() { console.log('๐Ÿš€ Starting comprehensive skill tests...\n'); const tests = [ { name: 'WebSearchSkill', test: testWebSearchSkill }, { name: 'ContentGeneratorSkill', test: testContentGeneratorSkill }, { name: 'SocialMediaSkill', test: testSocialMediaSkill }, { name: 'PhotoSkill', test: testPhotoSkill }, { name: 'HelpSupportSkill', test: testHelpSupportSkill }, { name: 'Web3SubscriptionSkill', test: testWeb3SubscriptionSkill }, { name: 'FundAgent', test: testFundAgent }, { name: 'TokenGatingSkill', test: testTokenGatingSkill }, { name: 'TokenGatingService', test: testTokenGatingService }, { name: 'LiveChatSkill', test: testLiveChatSkill } ]; const results = []; for (const test of tests) { console.log(`\n--- Testing ${test.name} ---`); const success = await test.test(); results.push({ name: test.name, success }); console.log(`--- ${test.name} test ${success ? 'PASSED' : 'FAILED'} ---\n`); } // Summary console.log('๐Ÿ“Š Test Results Summary:'); console.log('========================'); const passed = results.filter(r => r.success).length; const failed = results.filter(r => !r.success).length; results.forEach(result => { const status = result.success ? 'โœ… PASS' : 'โŒ FAIL'; console.log(`${status} ${result.name}`); }); console.log(`\n๐ŸŽฏ Overall: ${passed}/${results.length} tests passed`); if (failed > 0) { console.log(`โš ๏ธ ${failed} tests failed - check the logs above for details`); process.exit(1); } else { console.log('๐ŸŽ‰ All tests passed! All skills are working correctly.'); } } // Run the tests runAllTests().catch(error => { console.error('๐Ÿ’ฅ Test runner failed:', error); process.exit(1); });