@vdoninja/ninja-p2p 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -0
- package/dashboard.html +602 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/message-bus.d.ts +79 -0
- package/dist/message-bus.js +234 -0
- package/dist/peer-registry.d.ts +69 -0
- package/dist/peer-registry.js +200 -0
- package/dist/protocol.d.ts +57 -0
- package/dist/protocol.js +67 -0
- package/dist/vdo-bridge.d.ts +66 -0
- package/dist/vdo-bridge.js +318 -0
- package/package.json +78 -0
- package/skills/ninja-p2p/SKILL.md +74 -0
package/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# ninja-p2p
|
|
2
|
+
|
|
3
|
+
Reusable bot-to-bot P2P communication layer built on [VDO.Ninja](https://vdo.ninja) WebRTC data channels. It lets agents discover each other inside a room, announce skills and status, send room-wide or private messages, and keep lightweight message history without a central relay.
|
|
4
|
+
|
|
5
|
+
## What This Repo Is
|
|
6
|
+
|
|
7
|
+
- A TypeScript/Node library for room-based peer discovery and messaging
|
|
8
|
+
- A standalone `dashboard.html` monitor/chat client
|
|
9
|
+
- A Codex skill at `skills/ninja-p2p`
|
|
10
|
+
- An npm package published as `@vdoninja/ninja-p2p`
|
|
11
|
+
|
|
12
|
+
## Install The Library
|
|
13
|
+
|
|
14
|
+
Install it from npm:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @vdoninja/ninja-p2p @roamhq/wrtc
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Notes:
|
|
21
|
+
|
|
22
|
+
- `@vdoninja/sdk` is pulled in automatically as a dependency.
|
|
23
|
+
- `ws` comes from `@vdoninja/sdk` in Node environments.
|
|
24
|
+
- `@roamhq/wrtc` is recommended for Node-based bots that need WebRTC support.
|
|
25
|
+
- This package is configured for public scoped publishing via `publishConfig.access = "public"`.
|
|
26
|
+
|
|
27
|
+
## Add The Codex Skill
|
|
28
|
+
|
|
29
|
+
Install the skill from this repo's `skills/ninja-p2p` folder, then restart Codex.
|
|
30
|
+
|
|
31
|
+
### PowerShell
|
|
32
|
+
|
|
33
|
+
```powershell
|
|
34
|
+
python $HOME\.codex\skills\.system\skill-installer\scripts\install-skill-from-github.py --repo steveseguin/ninja-p2p --path skills/ninja-p2p
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Bash
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
python ~/.codex/skills/.system/skill-installer/scripts/install-skill-from-github.py --repo steveseguin/ninja-p2p --path skills/ninja-p2p
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Quick Start
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { VDOBridge } from "@vdoninja/ninja-p2p";
|
|
47
|
+
|
|
48
|
+
const bridge = new VDOBridge({
|
|
49
|
+
room: "agents_room",
|
|
50
|
+
streamId: "planner_bot",
|
|
51
|
+
identity: {
|
|
52
|
+
streamId: "planner_bot",
|
|
53
|
+
role: "agent",
|
|
54
|
+
name: "Planner",
|
|
55
|
+
},
|
|
56
|
+
password: false,
|
|
57
|
+
skills: ["chat", "search"],
|
|
58
|
+
topics: ["events"],
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
await bridge.connect();
|
|
62
|
+
|
|
63
|
+
// Send to everyone in the room
|
|
64
|
+
bridge.chat("Planner online");
|
|
65
|
+
|
|
66
|
+
// Send a private message to a specific peer
|
|
67
|
+
bridge.chat("sync now", "worker_bot");
|
|
68
|
+
|
|
69
|
+
// Publish a topic event
|
|
70
|
+
bridge.publishEvent("events", "status_change", { status: "busy" });
|
|
71
|
+
|
|
72
|
+
// Listen for incoming chat
|
|
73
|
+
bridge.bus.on("message:chat", (envelope) => {
|
|
74
|
+
console.log(`${envelope.from.name}: ${envelope.payload.text}`);
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Core Features
|
|
79
|
+
|
|
80
|
+
- **Peer Registry**: Track peers, identity, skills, topics, and status
|
|
81
|
+
- **Pub/Sub Messaging**: Broadcast, direct send, and topic fanout
|
|
82
|
+
- **Offline Queue**: Queue messages for peers that are temporarily disconnected
|
|
83
|
+
- **Message History**: Replay recent messages to late joiners
|
|
84
|
+
- **Keyword Triggers**: Wake async bots from chat patterns
|
|
85
|
+
- **Identity Protocol**: Peers announce skills and status changes
|
|
86
|
+
- **Heartbeat**: Detect stale peers
|
|
87
|
+
- **Browser Dashboard**: Monitor peers and chat from a single HTML file
|
|
88
|
+
|
|
89
|
+
## Core Patterns
|
|
90
|
+
|
|
91
|
+
- Room-wide chat: `bridge.chat("hello")`
|
|
92
|
+
- Private message: `bridge.chat("hello", "target_stream_id")`
|
|
93
|
+
- Targeted command: `bridge.command("target_stream_id", "do_work", { jobId: 123 })`
|
|
94
|
+
- Topic event: `bridge.publishEvent("events", "status_change", { status: "busy" })`
|
|
95
|
+
|
|
96
|
+
## Browser Dashboard
|
|
97
|
+
|
|
98
|
+
`dashboard.html` is a standalone single-file SPA that connects to the same VDO.Ninja room. Open it locally in a browser or host it anywhere static files are supported.
|
|
99
|
+
|
|
100
|
+
Example:
|
|
101
|
+
|
|
102
|
+
```text
|
|
103
|
+
dashboard.html?room=agents_room&password=false&name=Steve&autoconnect=true
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Public API
|
|
107
|
+
|
|
108
|
+
Main entrypoint:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import { VDOBridge, MessageBus, PeerRegistry } from "@vdoninja/ninja-p2p";
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Subpath entrypoints:
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import { VDOBridge } from "@vdoninja/ninja-p2p/vdo-bridge";
|
|
118
|
+
import { createEnvelope } from "@vdoninja/ninja-p2p/protocol";
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Architecture
|
|
122
|
+
|
|
123
|
+
```text
|
|
124
|
+
VDOBridge
|
|
125
|
+
|- PeerRegistry
|
|
126
|
+
|- MessageBus
|
|
127
|
+
`- Protocol helpers
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Tests
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
npm test
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
MIT
|