A standalone, reverse-engineered implementation of the Rabbit R1 OpenClaw Gateway Protocol. This library allows you to build custom backends for the Rabbit R1 device without relying on the official servers or complex AI platforms.
npm install github:neooriginal/RabbitR1-OpenClaw-Hackconst { RabbitGateway } = require('rabbit-r1-lib');
// Start the gateway
const gateway = new RabbitGateway({
port: 18789,
debug: true
});
gateway.start();
// Handle device connections
gateway.on('deviceConnected', (device) => {
console.log(`R1 Connected: ${device.id}`);
// Send a welcome message
gateway.sendText(device.id, "Welcome to your custom backend!");
});
// Handle messages from the R1
gateway.on('message', (msg) => {
console.log(`User said: ${msg.text}`);
// Echo back
gateway.sendText(msg.deviceId, `You said: ${msg.text}`);
});
// Generate pairing QR Code
gateway.getQrCode().then(url => {
console.log("Scan this QR code with your R1 camera:", url);
// Use 'qrcode-terminal' or serve this data URL to a browser
});The Rabbit R1 communicates via a WebSocket connection using a JSON-RPC-like format.
- Client connects to
ws://<SERVER_IP>:18789. - Server sends Challenge: Immediately upon connection.
{ "type": "event", "event": "connect.challenge", "payload": { "nonce": "<UUID>", "ts": 1234567890 } } - Client sends Connect Request: Includes the gateway token (scanned from QR).
{ "method": "connect", "params": { "auth": { "token": "<GATEWAY_TOKEN>" }, "device": { "id": "<DEVICE_ID>" } }, "id": "<UUID>" } - Server Validates & Approves:
- Sends
node.pair.approvedevent. - Sends response to
connectrequest (ok: true). - Sends
connect.okevent.
- Sends
User -> Server:
The device sends spoken text via chat.send.
{
"method": "chat.send",
"params": {
"message": "Hello world",
"sessionKey": "main",
"idempotencyKey": "<RUN_ID>"
},
"id": "<UUID>"
}Server -> User:
The server sends responses as chat events. This triggers the R1 to speak/display text.
{
"type": "event",
"event": "chat",
"payload": {
"runId": "<RUN_ID>",
"sessionKey": "main",
"state": "final",
"message": {
"role": "assistant",
"content": [{ "type": "text", "text": "Hello human!" }]
}
}
}- Pure JS: Minimal dependencies (
ws,qrcode). - Tailscale Support: Helper method to generate QR codes with Tailscale IPs for remote access.
- Event Driven: Standard Node.js
EventEmitterinterface.
MIT