Gateway پروٹوکول (WebSocket)¶
Gateway WS پروٹوکول واحد کنٹرول پلین + نوڈ ٹرانسپورٹ ہے برائے OpenClaw. All clients (CLI, web UI, macOS app, iOS/Android nodes, headless nodes) connect over WebSocket and declare their role + scope at handshake time.
ٹرانسپورٹ¶
- WebSocket، ٹیکسٹ فریمز کے ساتھ JSON پے لوڈز۔
- پہلا فریم لازمی طور پر ایک
connectدرخواست ہونا چاہیے۔
ہینڈ شیک (connect)¶
Gateway → کلائنٹ (پری-کنیکٹ چیلنج):
{
"type": "event",
"event": "connect.challenge",
"payload": { "nonce": "…", "ts": 1737264000000 }
}
کلائنٹ → Gateway:
{
"type": "req",
"id": "…",
"method": "connect",
"params": {
"minProtocol": 3,
"maxProtocol": 3,
"client": {
"id": "cli",
"version": "1.2.3",
"platform": "macos",
"mode": "operator"
},
"role": "operator",
"scopes": ["operator.read", "operator.write"],
"caps": [],
"commands": [],
"permissions": {},
"auth": { "token": "…" },
"locale": "en-US",
"userAgent": "openclaw-cli/1.2.3",
"device": {
"id": "device_fingerprint",
"publicKey": "…",
"signature": "…",
"signedAt": 1737264000000,
"nonce": "…"
}
}
}
Gateway → کلائنٹ:
{
"type": "res",
"id": "…",
"ok": true,
"payload": { "type": "hello-ok", "protocol": 3, "policy": { "tickIntervalMs": 15000 } }
}
جب ڈیوائس ٹوکن جاری کیا جاتا ہے تو، hello-ok میں یہ بھی شامل ہوتا ہے:
{
"auth": {
"deviceToken": "…",
"role": "operator",
"scopes": ["operator.read", "operator.write"]
}
}
نوڈ کی مثال¶
{
"type": "req",
"id": "…",
"method": "connect",
"params": {
"minProtocol": 3,
"maxProtocol": 3,
"client": {
"id": "ios-node",
"version": "1.2.3",
"platform": "ios",
"mode": "node"
},
"role": "node",
"scopes": [],
"caps": ["camera", "canvas", "screen", "location", "voice"],
"commands": ["camera.snap", "canvas.navigate", "screen.record", "location.get"],
"permissions": { "camera.capture": true, "screen.record": false },
"auth": { "token": "…" },
"locale": "en-US",
"userAgent": "openclaw-ios/1.2.3",
"device": {
"id": "device_fingerprint",
"publicKey": "…",
"signature": "…",
"signedAt": 1737264000000,
"nonce": "…"
}
}
}
Framing¶
- Request:
{type:"req", id, method, params} - Response:
{type:"res", id, ok, payload|error} - Event:
{type:"event", event, payload, seq?, stateVersion?}
Side-effecting methods require idempotency keys (see schema).
Roles + scopes¶
Roles¶
operator= control plane client (CLI/UI/automation).node= capability host (camera/screen/canvas/system.run).
Scopes (operator)¶
Common scopes:
operator.readoperator.writeoperator.adminoperator.approvalsoperator.pairing
Caps/commands/permissions (node)¶
Nodes declare capability claims at connect time:
caps: high-level capability categories.commands: command allowlist for invoke.permissions: granular toggles (e.g.screen.record,camera.capture).
The Gateway treats these as claims and enforces server-side allowlists.
Presence¶
system-presencereturns entries keyed by device identity.-
- Presence entries میں
deviceId,rolesاورscopesشامل ہوتے ہیں تاکہ UIs ہر ڈیوائس کے لیے ایک ہی قطار دکھا سکیں چاہے وہ بیک وقت operator اور node کے طور پر کنیکٹ ہو۔
- Presence entries میں
2. Node helper methods¶
-
- Nodes خودکار اجازت (auto-allow) کی جانچ کے لیے موجودہ skill executables کی فہرست حاصل کرنے کے لیے
skills.binsکو کال کر سکتے ہیں۔
- Nodes خودکار اجازت (auto-allow) کی جانچ کے لیے موجودہ skill executables کی فہرست حاصل کرنے کے لیے
ایگزیک منظوریات¶
-
- جب کسی exec درخواست کو منظوری درکار ہو، تو گیٹ وے
exec.approval.requestedبراڈکاسٹ کرتا ہے۔
- جب کسی exec درخواست کو منظوری درکار ہو، تو گیٹ وے
-
- Operator کلائنٹس
exec.approval.resolveکال کر کے حل کرتے ہیں (اس کے لیےoperator.approvalsاسکوپ درکار ہے)۔
- Operator کلائنٹس
Versioning¶
PROTOCOL_VERSIONsrc/gateway/protocol/schema.tsمیں موجود ہے۔- کلائنٹس
minProtocol+maxProtocolبھیجتے ہیں؛ سرور عدم مطابقت کو مسترد کر دیتا ہے۔ -
- Schemas + models، TypeBox definitions سے جنریٹ کیے جاتے ہیں:
pnpm protocol:genpnpm protocol:gen:swiftpnpm protocol:check
Auth¶
-
- اگر
OPENCLAW_GATEWAY_TOKEN(یا--token) سیٹ ہو، توconnect.params.auth.tokenکا میچ ہونا لازمی ہے ورنہ ساکٹ بند کر دی جاتی ہے۔
- اگر
-
- pairing کے بعد، گیٹ وے کنکشن کے رول + اسکوپس تک محدود ایک device token جاری کرتا ہے۔ 9. یہ
hello-ok.auth.deviceTokenمیں واپس کیا جاتا ہے اور آئندہ کنیکشنز کے لیے کلائنٹ کو اسے محفوظ کرنا چاہیے۔
- pairing کے بعد، گیٹ وے کنکشن کے رول + اسکوپس تک محدود ایک device token جاری کرتا ہے۔ 9. یہ
-
- Device tokens کو
device.token.rotateاورdevice.token.revokeکے ذریعے روٹیٹ/ریووٖک کیا جا سکتا ہے (اس کے لیےoperator.pairingاسکوپ درکار ہے)۔
- Device tokens کو
Device identity + pairing¶
-
- Nodes کو ایک مستحکم ڈیوائس شناخت (
device.id) شامل کرنی چاہیے جو keypair fingerprint سے اخذ کی گئی ہو۔
- Nodes کو ایک مستحکم ڈیوائس شناخت (
-
- Gateways ہر ڈیوائس + رول کے لیے ٹوکن جاری کرتے ہیں۔
- Pairing approvals are required for new device IDs unless local auto-approval is enabled.
-
- Local کنیکشنز میں loopback اور گیٹ وے ہوسٹ کا اپنا tailnet ایڈریس شامل ہوتا ہے (تاکہ اسی ہوسٹ کے tailnet binds بھی auto-approve ہو سکیں)۔
-
- تمام WS کلائنٹس کو
connectکے دورانdeviceشناخت شامل کرنی لازمی ہے (operator + node)۔ - Control UI اسے صرف اسی صورت میں چھوڑ سکتی ہے جب
gateway.controlUi.allowInsecureAuthفعال ہو (یا ہنگامی استعمال کے لیےgateway.controlUi.dangerouslyDisableDeviceAuth)۔
- تمام WS کلائنٹس کو
- Non-local connections must sign the server-provided
connect.challengenonce.
TLS + pinning¶
-
- WS کنیکشنز کے لیے TLS سپورٹ موجود ہے۔
-
- کلائنٹس اختیاری طور پر گیٹ وے سرٹیفکیٹ فنگرپرنٹ پن کر سکتے ہیں (دیکھیے
gateway.tlsکنفیگ کے ساتھgateway.remote.tlsFingerprintیا CLI--tls-fingerprint)۔
- کلائنٹس اختیاری طور پر گیٹ وے سرٹیفکیٹ فنگرپرنٹ پن کر سکتے ہیں (دیکھیے
Scope¶
- یہ پروٹوکول مکمل گیٹ وے API کو ایکسپوز کرتا ہے (status, channels, models, chat,
agent, sessions, nodes, approvals، وغیرہ)۔ The exact surface is defined by the
TypeBox schemas in
src/gateway/protocol/schema.ts.