90 lines
2.6 KiB
JavaScript
90 lines
2.6 KiB
JavaScript
// Simple test for natural language navigation
|
|
// This tests the URL mapping functionality
|
|
|
|
const urlMappings = new Map([
|
|
['google', 'https://www.google.com'],
|
|
['google.com', 'https://www.google.com'],
|
|
['youtube', 'https://www.youtube.com'],
|
|
['youtube.com', 'https://www.youtube.com'],
|
|
['facebook', 'https://www.facebook.com'],
|
|
['facebook.com', 'https://www.facebook.com'],
|
|
['twitter', 'https://www.twitter.com'],
|
|
['twitter.com', 'https://www.twitter.com'],
|
|
['x.com', 'https://www.x.com'],
|
|
['github', 'https://www.github.com'],
|
|
['github.com', 'https://www.github.com'],
|
|
]);
|
|
|
|
function processNavigationRequest(args) {
|
|
if (!args || !args.url) {
|
|
return args;
|
|
}
|
|
|
|
const url = args.url.toLowerCase().trim();
|
|
|
|
// Check if it's a natural language request like "google", "open google", etc.
|
|
const patterns = [
|
|
/^(?:open\s+|go\s+to\s+|navigate\s+to\s+)?(.+?)(?:\.com)?$/i,
|
|
/^(.+?)$/i
|
|
];
|
|
|
|
for (const pattern of patterns) {
|
|
const match = url.match(pattern);
|
|
if (match) {
|
|
const site = match[1].toLowerCase().trim();
|
|
const mappedUrl = urlMappings.get(site);
|
|
if (mappedUrl) {
|
|
console.log(`✅ Mapped natural language request "${url}" to "${mappedUrl}"`);
|
|
return { ...args, url: mappedUrl };
|
|
}
|
|
}
|
|
}
|
|
|
|
// If no mapping found, check if it's already a valid URL
|
|
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
|
// Try to make it a valid URL
|
|
const processedUrl = url.includes('.') ? `https://${url}` : `https://www.google.com/search?q=${encodeURIComponent(url)}`;
|
|
console.log(`✅ Processed URL "${url}" to "${processedUrl}"`);
|
|
return { ...args, url: processedUrl };
|
|
}
|
|
|
|
return args;
|
|
}
|
|
|
|
// Test cases
|
|
console.log('🧪 Testing Natural Language Navigation Processing\n');
|
|
|
|
const testCases = [
|
|
'google',
|
|
'open google',
|
|
'go to google',
|
|
'navigate to google',
|
|
'youtube',
|
|
'open youtube',
|
|
'facebook',
|
|
'github',
|
|
'example.com',
|
|
'search for cats',
|
|
'python tutorials',
|
|
'https://www.example.com',
|
|
];
|
|
|
|
testCases.forEach(testCase => {
|
|
console.log(`\n📝 Testing: "${testCase}"`);
|
|
const result = processNavigationRequest({ url: testCase });
|
|
console.log(` Result: ${result.url}`);
|
|
});
|
|
|
|
console.log('\n✨ Test completed!');
|
|
|
|
// Test the MCP tool call format
|
|
console.log('\n🔧 Testing MCP Tool Call Format:');
|
|
console.log('Tool: chrome_navigate_natural');
|
|
console.log('Args: { "query": "open google" }');
|
|
|
|
const naturalArgs = { query: "open google" };
|
|
const navigationArgs = { url: naturalArgs.query, ...naturalArgs };
|
|
delete navigationArgs.query;
|
|
const processedArgs = processNavigationRequest(navigationArgs);
|
|
console.log('Processed args:', processedArgs);
|