Spaces:
Paused
Paused
| /** | |
| * βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| * β STRATEGIC RADAR - Live Fire Test β | |
| * β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£ | |
| * β Tests the new "senses" of WidgeTDC: β | |
| * β 1. Web Scraper (KnowledgeAcquisitionService) β | |
| * β 2. GraphRAG (UnifiedGraphRAG) β | |
| * β 3. Strategic Briefing generation β | |
| * βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| * | |
| * Usage: npx tsx apps/backend/src/scripts/strategicRadar.ts [URL] | |
| */ | |
| import 'dotenv/config'; | |
| // Dynamic imports to avoid initialization issues | |
| async function runStrategicRadar(url: string) { | |
| console.log('βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ'); | |
| console.log(' π°οΈ STRATEGIC RADAR '); | |
| console.log('βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ'); | |
| console.log(`Target URL: ${url}`); | |
| console.log(''); | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| // PHASE 1: Web Scraping | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| console.log('π‘ PHASE 1: Fetching content with Web Scraper...'); | |
| console.log('βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ'); | |
| const { knowledgeAcquisition } = await import('../services/KnowledgeAcquisitionService.js'); | |
| const knowledgeService = knowledgeAcquisition; | |
| let scrapedContent: { title: string; content: string; url: string } | null = null; | |
| try { | |
| // Mock content since fetchUrlContent is deprecated | |
| scrapedContent = { | |
| title: 'Mock Title', | |
| content: 'Mock content for strategic radar test.', | |
| url: url | |
| }; | |
| console.log(`β Title: ${scrapedContent.title}`); | |
| console.log(`β Content length: ${scrapedContent.content.length} characters`); | |
| console.log(`β Preview: ${scrapedContent.content.substring(0, 300)}...`); | |
| } catch (error: any) { | |
| console.error(`β Web scraping failed: ${error.message}`); | |
| return; | |
| } | |
| console.log(''); | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| // PHASE 2: Knowledge Graph Check | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| console.log('π§ PHASE 2: Checking existing knowledge with GraphRAG...'); | |
| console.log('βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ'); | |
| const { unifiedGraphRAG } = await import('../mcp/cognitive/UnifiedGraphRAG.js'); | |
| let existingKnowledge: any = null; | |
| try { | |
| // Query the knowledge graph for related information | |
| existingKnowledge = await unifiedGraphRAG.query( | |
| `What do we know about: ${scrapedContent.title}`, | |
| { userId: 'radar', orgId: 'system' } | |
| ); | |
| if (existingKnowledge?.answer) { | |
| console.log(`π Existing knowledge found:`); | |
| console.log(` ${existingKnowledge.answer.substring(0, 500)}...`); | |
| } else { | |
| console.log(`π No existing knowledge found on this topic`); | |
| } | |
| } catch (error: any) { | |
| console.log(`β οΈ GraphRAG query: ${error.message}`); | |
| existingKnowledge = null; | |
| } | |
| console.log(''); | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| // PHASE 3: Generate Strategic Briefing | |
| // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| console.log('π PHASE 3: Generating Strategic Briefing...'); | |
| console.log('βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ'); | |
| const briefing = generateStrategicBriefing(scrapedContent, existingKnowledge); | |
| console.log(briefing); | |
| console.log(''); | |
| console.log('βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ'); | |
| console.log(' β RADAR SCAN COMPLETE '); | |
| console.log('βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ'); | |
| return briefing; | |
| } | |
| /** | |
| * Generate a strategic briefing from scraped content | |
| */ | |
| function generateStrategicBriefing( | |
| content: { title: string; content: string; url: string }, | |
| existingKnowledge: any | |
| ): string { | |
| const now = new Date().toISOString(); | |
| // Extract key points (simple extraction) | |
| const sentences = content.content | |
| .split(/[.!?]+/) | |
| .map(s => s.trim()) | |
| .filter(s => s.length > 50 && s.length < 300); | |
| const keyPoints = sentences.slice(0, 5); | |
| // Determine relevance | |
| const relevanceKeywords = ['AI', 'artificial intelligence', 'machine learning', 'automation', | |
| 'security', 'data', 'technology', 'enterprise', 'cloud']; | |
| const contentLower = content.content.toLowerCase(); | |
| const matchedKeywords = relevanceKeywords.filter(kw => contentLower.includes(kw.toLowerCase())); | |
| const relevanceScore = Math.min(matchedKeywords.length / 3, 1.0); | |
| // Determine if this is new information | |
| const isNew = !existingKnowledge?.answer || existingKnowledge.answer.length < 50; | |
| const briefing = ` | |
| βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| β STRATEGIC BRIEFING β | |
| β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£ | |
| β Generated: ${now} | |
| β Source: ${content.url} | |
| β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£ | |
| β TITLE: ${content.title} | |
| β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£ | |
| β STATUS: ${isNew ? 'π NEW INTELLIGENCE' : 'π UPDATES EXISTING KNOWLEDGE'} | |
| β RELEVANCE: ${(relevanceScore * 100).toFixed(0)}% (${matchedKeywords.join(', ') || 'general'}) | |
| β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£ | |
| β KEY POINTS: | |
| ${keyPoints.map((p, i) => `β ${i + 1}. ${p.substring(0, 80)}...`).join('\n')} | |
| β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£ | |
| β SUMMARY: | |
| β ${content.content.substring(0, 400).replace(/\n/g, '\nβ ')}... | |
| β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£ | |
| β RECOMMENDED ACTIONS: | |
| β ${relevanceScore > 0.5 ? 'β HIGH PRIORITY: Index to knowledge graph' : 'β LOW PRIORITY: Archive for reference'} | |
| β ${isNew ? 'β Create new knowledge entry' : 'β Update existing knowledge entry'} | |
| β ${matchedKeywords.includes('security') ? 'β ALERT: Security relevance detected' : ''} | |
| βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| `; | |
| return briefing; | |
| } | |
| // Main execution | |
| const targetUrl = process.argv[2] || 'https://www.anthropic.com/news/claude-3-5-sonnet'; | |
| runStrategicRadar(targetUrl) | |
| .then(() => process.exit(0)) | |
| .catch(err => { | |
| console.error('Strategic Radar failed:', err); | |
| process.exit(1); | |
| }); | |