最后更新:2026-01-22 · 翻译自 docs.openclaw.ai
127.0.0.1:18789)上的 WebSocket 连接到 Gateway。node,并带有显式的能力(caps)和命令(commands)。agent、chat、presence、health、heartbeat、cron。health、status、send、agent、system-presence。tick、agent、presence、shutdown。role: node。canvas.*、camera.*、screen.record、location.get。协议细节:Gateway 协议
Client Gateway
| |
|---- req:connect -------->|
|<------ res (ok) ---------| (或 res error + close)
| (payload=hello-ok 携带快照: presence + health)
| |
|<------ event:presence ---|
|<------ event:tick -------|
| |
|------- req:agent ------->|
|<------ res:agent --------| (ack: {runId, status:"accepted"})
|<------ event:agent ------| (流式传输)
|<------ res:agent --------| (最终: {runId, status, summary})
| |
connect。{type:"req", id, method, params} → {type:"res", id, ok, payload|error}{type:"event", event, payload, seq?, stateVersion?}OPENCLAW_GATEWAY_TOKEN(或 --token),connect.params.auth.token 必须匹配,否则套接字将被关闭。send、agent),需要幂等键(idempotency key)才能安全重试;服务器保留一个短期的去重缓存。connect 中包含 role: "node" 以及 caps/commands/permissions。connect.challenge 的 nonce,并需要明确批准。gateway.auth.*)仍然适用于所有连接,无论本地还是远程。ssh -N -L 18789:127.0.0.1:18789 user@hostopenclaw gateway(前台运行,日志输出到 stdout)。health 请求(也包含在 hello-ok 中)。launchd/systemd 实现自动重启。connect 的第一帧都会导致硬关闭。