@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
107 lines (106 loc) ⢠5.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.testSearchFunctionality = testSearchFunctionality;
exports.checkAvailableSearchProviders = checkAvailableSearchProviders;
const search_utils_1 = require("./search-utils");
const env_config_1 = require("./config/env-config");
/**
* Test the new search functionality
* This demonstrates how to use the search providers with proper API key validation
*/
async function testSearchFunctionality() {
console.log('š Testing Search Functionality\n');
const testQuery = 'AI agents development';
// Test different search providers
const providers = ['google', 'bing', 'openai'];
for (const provider of providers) {
console.log(`\nš” Testing ${provider.toUpperCase()} search...`);
try {
const options = {
provider,
maxResults: 3
};
const results = await search_utils_1.SearchProviders.searchWeb(testQuery, options);
console.log(`ā
${provider.toUpperCase()} search successful! Found ${results.length} results:`);
results.forEach((result, index) => {
console.log(` ${index + 1}. ${result.title}`);
console.log(` ${result.url}`);
console.log(` ${result.snippet.substring(0, 100)}...`);
});
}
catch (error) {
if (error instanceof Error) {
console.log(`ā ${provider.toUpperCase()} search failed: ${error.message}`);
// Provide helpful setup instructions
if (provider === 'google' && !(0, env_config_1.hasApiKey)('google', 'apiKey')) {
console.log(' š” To use Google Search, add to your .env file:');
console.log(' GOOGLE_SEARCH_API_KEY=your-api-key');
console.log(' GOOGLE_SEARCH_ENGINE_ID=your-search-engine-id');
}
else if (provider === 'bing' && !(0, env_config_1.hasApiKey)('bing', 'apiKey')) {
console.log(' š” To use Bing Search, add to your .env file:');
console.log(' BING_SEARCH_API_KEY=your-api-key');
}
}
}
}
// Test news search
console.log('\nš° Testing News Search...');
try {
const newsResults = await search_utils_1.SearchProviders.searchNews('artificial intelligence', { maxResults: 2 });
console.log(`ā
News search successful! Found ${newsResults.length} articles:`);
newsResults.forEach((article, index) => {
console.log(` ${index + 1}. ${article.title} (${article.source})`);
});
}
catch (error) {
if (error instanceof Error) {
console.log(`ā News search failed: ${error.message}`);
if (!(0, env_config_1.hasApiKey)('newsapi', 'apiKey')) {
console.log(' š” To use News API, add to your .env file:');
console.log(' NEWS_API_KEY=your-api-key');
}
}
}
// Test image search
console.log('\nš¼ļø Testing Image Search...');
try {
const imageResults = await search_utils_1.SearchProviders.searchImages('AI technology', { maxResults: 2 });
console.log(`ā
Image search successful! Found ${imageResults.length} images:`);
imageResults.forEach((image, index) => {
console.log(` ${index + 1}. ${image.title}`);
console.log(` ${image.url}`);
});
}
catch (error) {
if (error instanceof Error) {
console.log(`ā Image search failed: ${error.message}`);
if (!(0, env_config_1.hasApiKey)('unsplash', 'accessKey')) {
console.log(' š” To use Unsplash API, add to your .env file:');
console.log(' UNSPLASH_ACCESS_KEY=your-access-key');
}
}
}
console.log('\nš Search functionality test completed!');
}
/**
* Check which search providers are available based on API keys
*/
function checkAvailableSearchProviders() {
console.log('š Checking Available Search Providers\n');
const providers = [
{ name: 'Google Search', hasKey: (0, env_config_1.hasApiKey)('google', 'apiKey'), hasEngineId: (0, env_config_1.hasApiKey)('google', 'searchEngineId') },
{ name: 'Bing Search', hasKey: (0, env_config_1.hasApiKey)('bing', 'apiKey') },
{ name: 'News API', hasKey: (0, env_config_1.hasApiKey)('newsapi', 'apiKey') },
{ name: 'Unsplash Images', hasKey: (0, env_config_1.hasApiKey)('unsplash', 'accessKey') }
];
providers.forEach(provider => {
const status = provider.hasKey ? 'ā
' : 'ā';
const details = provider.hasKey ? 'API key configured' : 'API key missing';
const engineStatus = provider.hasEngineId !== undefined ?
(provider.hasEngineId ? 'ā
' : 'ā') + ' Search Engine ID' : '';
console.log(`${status} ${provider.name}: ${details} ${engineStatus}`);
});
console.log('\nš¤ OpenAI Web Search: ā
Available with OpenAI API key');
console.log('\nš” Tip: OpenAI web search is used as fallback when other providers are not configured');
}