-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo-integration.ts
More file actions
148 lines (123 loc) · 5.1 KB
/
demo-integration.ts
File metadata and controls
148 lines (123 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* TrustSwarm Integration Demo
*
* Demonstrates using npx claude-flow@alpha and npx agentic-flow
* for production fraud detection with AgentDB optimization
*/
import { createEnhancedOrchestrator } from '../lib/enhanced-swarm-orchestrator'
import type { TransactionData } from '../lib/swarm-orchestrator'
/**
* Demo: Analyze suspicious transaction with enhanced swarm
*/
async function demoEnhancedAnalysis() {
console.log(`
╔═══════════════════════════════════════════════════════════╗
║ TrustSwarm Enhanced Integration Demo ║
║ Using claude-flow + agentic-flow + agentdb ║
╚═══════════════════════════════════════════════════════════╝
`)
// Create enhanced orchestrator with all optimizations enabled
const orchestrator = createEnhancedOrchestrator({
enableClaudeFlow: true,
enableAgenticFlow: true,
optimization: {
speed: true, // Enable QUIC (50-70% faster)
cost: true, // Enable multi-model optimization
quality: true // Maintain high accuracy
},
learning: {
enableReasoningBank: true, // Learn successful patterns
enableReflexion: true, // Self-critique and improvement
enablePatternLearning: true // Store fraud patterns
}
})
// Example 1: Legitimate transaction
console.log('\n📊 Example 1: Analyzing legitimate transaction...\n')
const legitimateTx: TransactionData = {
txHash: '0xlegitimate123...',
from: '0x1234567890abcdef1234567890abcdef12345678',
to: '0xabcdef1234567890abcdef1234567890abcdef12',
amount: 50,
chain: 'base',
memo: 'Payment for services rendered - Invoice #1234',
timestamp: Date.now()
}
const result1 = await orchestrator.analyzeTransaction(legitimateTx)
console.log(`
📈 Results:
Trust Score: ${result1.score.overall}/1000
Risk Level: ${result1.score.riskLevel.toUpperCase()}
Confidence: ${(result1.score.confidence * 100).toFixed(1)}%
Performance:
• Total Latency: ${result1.performance.totalLatency.toFixed(0)}ms
• Cost Savings: $${result1.performance.costSavings.toFixed(4)}
• Models Used: ${JSON.stringify(result1.performance.modelUsed, null, 2)}
Explainability:
${result1.score.explainability.map(e => ` - ${e}`).join('\n')}
`)
// Example 2: Phishing attempt
console.log('\n📊 Example 2: Analyzing phishing attempt...\n')
const phishingTx: TransactionData = {
txHash: '0xphishing456...',
from: '0x0000000000000000000000000000000000000001',
to: '0x9999999999999999999999999999999999999999',
amount: 10000,
chain: 'ethereum',
memo: 'URGENT: Verify your account immediately or it will be suspended! Click here now!',
timestamp: Date.now()
}
const result2 = await orchestrator.analyzeTransaction(phishingTx)
console.log(`
🚨 FRAUD DETECTED:
Trust Score: ${result2.score.overall}/1000
Risk Level: ${result2.score.riskLevel.toUpperCase()}
Confidence: ${(result2.score.confidence * 100).toFixed(1)}%
Performance:
• Total Latency: ${result2.performance.totalLatency.toFixed(0)}ms
• Cost Savings: $${result2.performance.costSavings.toFixed(4)}
• Models Used: ${JSON.stringify(result2.performance.modelUsed, null, 2)}
Fraud Indicators:
${result2.score.explainability.map(e => ` - ${e}`).join('\n')}
`)
// Example 3: Learn from feedback
console.log('\n📊 Example 3: Learning from feedback...\n')
await orchestrator.learnFromFeedback({
taskId: result2.taskId,
actualOutcome: 'fraud',
notes: 'Confirmed phishing attempt, user reported'
})
// Example 4: Get performance report
console.log('\n📊 Example 4: Performance Report...\n')
const report = orchestrator.getPerformanceReport()
console.log(`
📊 Overall Performance:
Claude Flow Metrics:
• Solve Rate: ${report.claudeFlow ? (report.claudeFlow.solveRate * 100).toFixed(1) : 'N/A'}%
• Token Reduction: ${report.claudeFlow ? (report.claudeFlow.tokenReduction * 100).toFixed(1) : 'N/A'}%
• Speed Improvement: ${report.claudeFlow ? report.claudeFlow.speedImprovement : 'N/A'}x
• Memory Optimization: ${report.claudeFlow ? report.claudeFlow.memoryOptimization : 'N/A'}x
Agentic Flow Metrics:
• Total Savings: $${report.agenticFlow ? report.agenticFlow.totalSavings.toFixed(2) : '0.00'}
• QUIC Speedup: ${report.agenticFlow ? report.agenticFlow.quicSpeedup : '1.0'}x
AgentDB Stats:
• Total Documents: ${report.agentDB.totalDocuments}
• Fraud Patterns: ${report.agentDB.totalPatterns}
• Trust Scores: ${report.agentDB.totalScores}
• Collections: ${report.agentDB.collections}
`)
}
/**
* Run demo
*/
if (require.main === module) {
demoEnhancedAnalysis()
.then(() => {
console.log('\n✅ Demo completed successfully!\n')
process.exit(0)
})
.catch((error) => {
console.error('\n❌ Demo failed:', error)
process.exit(1)
})
}
export default demoEnhancedAnalysis