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

98 lines (97 loc) • 4.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.testGoogleSearch = testGoogleSearch; exports.testAllSearchProviders = testAllSearchProviders; const search_utils_1 = require("./search-utils"); const env_config_1 = require("./config/env-config"); /** * Test Google Search API with the provided keys */ async function testGoogleSearch() { console.log('šŸ” Testing Google Search API Integration\n'); // Check if API keys are available console.log('šŸ”‘ Checking API Keys:'); console.log(` Google API Key: ${(0, env_config_1.hasApiKey)('google', 'apiKey') ? 'āœ… Found' : 'āŒ Missing'}`); console.log(` Search Engine ID: ${(0, env_config_1.hasApiKey)('google', 'searchEngineId') ? 'āœ… Found' : 'āŒ Missing'}`); if (!(0, env_config_1.hasApiKey)('google', 'apiKey')) { console.log('\nāŒ Google Search API key not found!'); console.log('Please add to your .env file:'); console.log('GOOGLE_SEARCH_API_KEY=your-api-key'); return; } if (!(0, env_config_1.hasApiKey)('google', 'searchEngineId')) { console.log('\nāŒ Google Search Engine ID not found!'); console.log('Please add to your .env file:'); console.log('GOOGLE_SEARCH_ENGINE_ID=your-search-engine-id'); return; } // Display the keys (masked for security) const apiKey = (0, env_config_1.getApiKey)('google', 'apiKey'); const searchEngineId = (0, env_config_1.getApiKey)('google', 'searchEngineId'); console.log(` API Key: ${apiKey.substring(0, 10)}...${apiKey.substring(apiKey.length - 4)}`); console.log(` Search Engine ID: ${searchEngineId}`); // Test the search console.log('\nšŸ” Testing Google Search...'); try { const testQuery = 'AI agents development'; const results = await search_utils_1.SearchProviders.searchWeb(testQuery, { provider: 'google', maxResults: 3 }); console.log(`āœ… Google Search successful! Found ${results.length} results:\n`); results.forEach((result, index) => { console.log(`${index + 1}. ${result.title}`); console.log(` URL: ${result.url}`); console.log(` Snippet: ${result.snippet.substring(0, 150)}...`); console.log(` Source: ${result.source}`); console.log(''); }); } catch (error) { console.log(`āŒ Google Search failed: ${error instanceof Error ? error.message : 'Unknown error'}`); if (error instanceof Error && error.message.includes('403')) { console.log('\nšŸ’” This might be due to:'); console.log(' - Invalid API key'); console.log(' - API quota exceeded'); console.log(' - Search Engine ID not configured correctly'); console.log(' - Search Engine not set to search the entire web'); } } } /** * Test all available search providers */ async function testAllSearchProviders() { console.log('šŸ” Testing All Search Providers\n'); const testQuery = 'artificial intelligence'; const providers = ['google', 'bing', 'openai']; for (const provider of providers) { console.log(`\nšŸ“” Testing ${provider.toUpperCase()}...`); try { const results = await search_utils_1.SearchProviders.searchWeb(testQuery, { provider, maxResults: 2 }); console.log(`āœ… ${provider.toUpperCase()} successful! Found ${results.length} results`); if (results.length > 0) { console.log(` First result: ${results[0].title}`); } } catch (error) { console.log(`āŒ ${provider.toUpperCase()} failed: ${error instanceof Error ? error.message : 'Unknown error'}`); } } } // Run tests if this file is executed directly if (require.main === module) { testGoogleSearch() .then(() => testAllSearchProviders()) .then(() => { console.log('\nšŸŽ‰ All tests completed!'); process.exit(0); }) .catch((error) => { console.error('Test failed:', error); process.exit(1); }); }