xCloudxCloudDownload
Engine (OpenClaw)

WebSocket Protocol

The real-time communication protocol between xCloud and the OpenClaw engine.

Overview

xCloud communicates with the OpenClaw engine via WebSocket with JSON text frames on port 18789 (default). The protocol supports TLS with optional certificate pinning.

Three-Phase Handshake

Phase 1: Challenge

Server sends a challenge immediately on connection:

{
  "type": "event",
  "event": "connect.challenge",
  "payload": {
    "nonce": "504c5a0a-...",
    "ts": 1737264000000
  }
}

Phase 2: Connect Request

Client responds with authentication and device identity:

{
  "type": "req",
  "id": "unique-id",
  "method": "connect",
  "params": {
    "minProtocol": 3,
    "maxProtocol": 3,
    "client": {
      "id": "xcloud",
      "version": "0.1.0",
      "platform": "macos",
      "mode": "operator"
    },
    "role": "operator",
    "scopes": ["operator.read", "operator.write"],
    "auth": { "token": "..." },
    "device": {
      "id": "device_fingerprint",
      "publicKey": "...",
      "signature": "...",
      "signedAt": 1737264000000,
      "nonce": "..."
    }
  }
}

Phase 3: Hello-OK

Server confirms connection with capabilities:

{
  "type": "res",
  "id": "...",
  "ok": true,
  "payload": {
    "type": "hello-ok",
    "protocol": 3,
    "features": {
      "methods": ["sessions.send", "chat.send", "..."],
      "events": ["agent", "chat", "session.message", "..."]
    }
  }
}

Frame Types

TypeDirectionStructure
reqClient → Server{ type, id, method, params }
resServer → Client{ type, id, ok, payload/error }
eventServer → Client{ type, event, payload, seq? }

Key RPC Methods

Messaging

MethodDescription
sessions.sendSend message to agent
sessions.abortAbort current generation
chat.sendSend chat message
chat.historyGet chat history

Sessions

MethodDescription
sessions.createCreate new session
sessions.listList all sessions
sessions.subscribeSubscribe to session events
sessions.resetReset session context

Agents

MethodDescription
agents.listList all agents
agents.createCreate new agent
agents.updateUpdate agent config
agents.files.*Manage agent files

Configuration

MethodDescription
config.getGet current config
config.patchUpdate config
config.applyApply config changes

Streaming Events

Agent Response Streaming

{
  "type": "event",
  "event": "agent",
  "payload": {
    "stream": "assistant",
    "data": {
      "text": "Hello! I can help you with that.",
      "delta": " with that."
    }
  }
}
  • data.delta = new incremental text
  • data.text = accumulated text so far

Lifecycle Events

{
  "event": "agent",
  "payload": {
    "stream": "lifecycle",
    "data": { "phase": "end" }
  }
}

Tool Calls

{
  "event": "session.tool",
  "payload": {
    "tool": { "name": "exec", "input": { "command": "ls -la" } },
    "status": "running"
  }
}

Constants

ParameterValue
Protocol version3
Default port18789
RPC timeout30,000 ms
Tick interval15,000 ms
Max payload~25 MB