feat: add novel hyper-p2p-intent-router v0.1.0 + workspace updates
- Created brand-new never-before-seen Bare/Pear module: hyper-p2p-intent-router
- Full production implementation: intent registration, Jaccard+keyword resolution, Protomux delivery, Hyperswarm discovery, Hyperbee persistence
- Complete test suite, examples, README, docs/architecture.md (Mermaid), docs/api.md
- Updated main README.md: added new module to Active Modules, marked as completed in roadmap, expanded This Run section with research study + full Node.js builtin scan (100% Bare compliant)
- Scanned all 8 modules for Node.js globals/builtins — no fixes needed
- Minor fixes in new module (constructor options, bootstrap handling)
- All work strictly inside /root/user-data/342128351638585344/projects/modules/
- Continuous autonomous novel primitive development
🤖 Autonomous Holepunch dev agent run
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
const HyperP2PIntentRouter = require('../index.js')
|
||||
const crypto = require('bare-crypto')
|
||||
const path = require('bare-path')
|
||||
const process = require('bare-process')
|
||||
|
||||
async function main () {
|
||||
console.log('hyper-p2p-intent-router basic usage example')
|
||||
|
||||
const router = new HyperP2PIntentRouter({
|
||||
storageDir: path.join(process.cwd(), 'example-intent-router-storage')
|
||||
})
|
||||
|
||||
router.on('ready', () => console.log('Router ready'))
|
||||
router.on('intent:registered', (intent) => console.log('Registered:', intent.id))
|
||||
router.on('message:received', (msg) => console.log('Received intent message:', msg))
|
||||
|
||||
await router.ready()
|
||||
|
||||
// Register several intents
|
||||
await router.registerIntent({
|
||||
id: 'ai-image-gen',
|
||||
description: 'Stable Diffusion image generation service',
|
||||
capabilities: ['image-generation', 'stable-diffusion', 'gpu'],
|
||||
topics: ['ai', 'graphics', 'creative'],
|
||||
priority: 10
|
||||
})
|
||||
|
||||
await router.registerIntent({
|
||||
id: 'ml-inference',
|
||||
description: 'ONNX / TensorFlow model inference',
|
||||
capabilities: ['ml', 'inference', 'gpu', 'cpu'],
|
||||
topics: ['ai', 'ml'],
|
||||
priority: 8
|
||||
})
|
||||
|
||||
await router.registerIntent({
|
||||
id: 'p2p-storage',
|
||||
description: 'Hypercore-backed decentralized storage',
|
||||
capabilities: ['storage', 'hypercore', 'p2p'],
|
||||
priority: 5
|
||||
})
|
||||
|
||||
// Resolve examples
|
||||
console.log('\n--- Resolving for GPU + AI ---')
|
||||
const gpuMatches = await router.resolveIntent({
|
||||
capabilities: ['gpu', 'ai'],
|
||||
keywords: ['image', 'generation']
|
||||
})
|
||||
console.log('Top matches:', gpuMatches.slice(0, 3))
|
||||
|
||||
console.log('\n--- Resolving for storage ---')
|
||||
const storageMatches = await router.resolveIntent({
|
||||
capabilities: ['storage']
|
||||
})
|
||||
console.log('Storage matches:', storageMatches)
|
||||
|
||||
// Simulate sending
|
||||
try {
|
||||
const sendRes = await router.sendToIntent({
|
||||
capabilities: ['ml', 'inference']
|
||||
}, {
|
||||
model: 'llama-3',
|
||||
prompt: 'Explain P2P intent routing'
|
||||
})
|
||||
console.log('Send result:', sendRes)
|
||||
} catch (e) {
|
||||
console.log('Send demo (no real peers):', e.message)
|
||||
}
|
||||
|
||||
// Show local + peer snapshot
|
||||
console.log('\nLocal intents:', router.getLocalIntents().length)
|
||||
console.log('Known peer intents:', router.getPeerIntents().length)
|
||||
|
||||
// Graceful shutdown
|
||||
setTimeout(async () => {
|
||||
await router.close()
|
||||
console.log('\nExample complete. Router closed.')
|
||||
process.exit(0)
|
||||
}, 2000)
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in New Issue
Block a user