{"id":136,"date":"2026-03-21T22:47:19","date_gmt":"2026-03-21T14:47:19","guid":{"rendered":"https:\/\/pa.yingzhi8.cn\/index.php\/2026\/03\/21\/gateway-protocol\/"},"modified":"2026-03-21T23:28:54","modified_gmt":"2026-03-21T15:28:54","slug":"gateway-protocol","status":"publish","type":"post","link":"https:\/\/pa.yingzhi8.cn\/index.php\/2026\/03\/21\/gateway-protocol\/","title":{"rendered":"\u7f51\u5173 \u7f51\u5173\u534f\u8bae"},"content":{"rendered":"<h1>Gateway \u7f51\u5173 \u7f51\u5173\u534f\u8bae<\/h1>\n<h1>Gateway \u7f51\u5173 \u7f51\u5173\u534f\u8bae\uff08WebSocket\uff09<\/h1>\n<p>Gateway \u7f51\u5173 \u7f51\u5173 WS \u534f\u8bae\u662f OpenClaw \u7684<strong>\u5355\u4e00\u63a7\u5236\u5e73\u9762 + \u8282\u70b9\u4f20\u8f93<\/strong>\u3002\u6240\u6709\u5ba2\u6237\u7aef\uff08CLI\u3001Web UI\u3001macOS \u5e94\u7528\u3001iOS\/Android \u8282\u70b9\u3001\u65e0\u5934\u8282\u70b9\uff09\u90fd\u901a\u8fc7 WebSocket \u8fde\u63a5\uff0c\u5e76\u5728\u63e1\u624b\u65f6\u58f0\u660e\u5176<strong>\u89d2\u8272<\/strong> + <strong>\u4f5c\u7528\u57df<\/strong>\u3002<\/p>\n<h2>\u4f20\u8f93<\/h2>\n<ul>\n<li>WebSocket\uff0c\u5e26\u6709 JSON \u8d1f\u8f7d\u7684\u6587\u672c\u5e27\u3002<\/li>\n<li>\u7b2c\u4e00\u5e27<strong>\u5fc5\u987b<\/strong>\u662f <code>connect<\/code> \u8bf7\u6c42\u3002<\/li>\n<\/ul>\n<h2>\u63e1\u624b\uff08connect\uff09<\/h2>\n<p>Gateway \u7f51\u5173 \u7f51\u5173 \u2192 \u5ba2\u6237\u7aef\uff08\u8fde\u63a5\u524d\u8d28\u8be2\uff09\uff1a<\/p>\n<p>&#8220;`json  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\n{<br \/>\n  &#8220;type&#8221;: &#8220;event&#8221;,<br \/>\n  &#8220;event&#8221;: &#8220;connect.challenge&#8221;,<br \/>\n  &#8220;payload&#8221;: { &#8220;nonce&#8221;: &#8220;\u2026&#8221;, &#8220;ts&#8221;: 1737264000000 }<br \/>\n}<\/p>\n<pre><code>\n\u5ba2\u6237\u7aef \u2192 Gateway \u7f51\u5173\uff1a\n\n```json  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n{\n  &quot;type&quot;: &quot;req&quot;,\n  &quot;id&quot;: &quot;\u2026&quot;,\n  &quot;method&quot;: &quot;connect&quot;,\n  &quot;params&quot;: {\n    &quot;minProtocol&quot;: 3,\n    &quot;maxProtocol&quot;: 3,\n    &quot;client&quot;: {\n      &quot;id&quot;: &quot;cli&quot;,\n      &quot;version&quot;: &quot;1.2.3&quot;,\n      &quot;platform&quot;: &quot;macos&quot;,\n      &quot;mode&quot;: &quot;operator&quot;\n    },\n    &quot;role&quot;: &quot;operator&quot;,\n    &quot;scopes&quot;: [&quot;operator.read&quot;, &quot;operator.write&quot;],\n    &quot;caps&quot;: [],\n    &quot;commands&quot;: [],\n    &quot;permissions&quot;: {},\n    &quot;auth&quot;: { &quot;token&quot;: &quot;\u2026&quot; },\n    &quot;locale&quot;: &quot;en-US&quot;,\n    &quot;userAgent&quot;: &quot;openclaw-cli\/1.2.3&quot;,\n    &quot;device&quot;: {\n      &quot;id&quot;: &quot;device_fingerprint&quot;,\n      &quot;publicKey&quot;: &quot;\u2026&quot;,\n      &quot;signature&quot;: &quot;\u2026&quot;,\n      &quot;signedAt&quot;: 1737264000000,\n      &quot;nonce&quot;: &quot;\u2026&quot;\n    }\n  }\n}\n<\/code><\/pre>\n<p>Gateway \u7f51\u5173 \u7f51\u5173 \u2192 \u5ba2\u6237\u7aef\uff1a<\/p>\n<p>&#8220;`json  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\n{<br \/>\n  &#8220;type&#8221;: &#8220;res&#8221;,<br \/>\n  &#8220;id&#8221;: &#8220;\u2026&#8221;,<br \/>\n  &#8220;ok&#8221;: true,<br \/>\n  &#8220;payload&#8221;: { &#8220;type&#8221;: &#8220;hello-ok&#8221;, &#8220;protocol&#8221;: 3, &#8220;policy&#8221;: { &#8220;tickIntervalMs&#8221;: 15000 } }<br \/>\n}<\/p>\n<pre><code>\n\u5f53\u9881\u53d1\u8bbe\u5907\u4ee4\u724c\u65f6\uff0c`hello-ok` \u8fd8\u5305\u542b\uff1a\n\n```json  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n{\n  &quot;auth&quot;: {\n    &quot;deviceToken&quot;: &quot;\u2026&quot;,\n    &quot;role&quot;: &quot;operator&quot;,\n    &quot;scopes&quot;: [&quot;operator.read&quot;, &quot;operator.write&quot;]\n  }\n}\n<\/code><\/pre>\n<h3>\u8282\u70b9\u793a\u4f8b<\/h3>\n<p><code>json  theme={\"theme\":{\"light\":\"min-light\",\"dark\":\"min-dark\"}}<br \/>\n{<br \/>\n  \"type\": \"req\",<br \/>\n  \"id\": \"\u2026\",<br \/>\n  \"method\": \"connect\",<br \/>\n  \"params\": {<br \/>\n    \"minProtocol\": 3,<br \/>\n    \"maxProtocol\": 3,<br \/>\n    \"client\": {<br \/>\n      \"id\": \"ios-node\",<br \/>\n      \"version\": \"1.2.3\",<br \/>\n      \"platform\": \"ios\",<br \/>\n      \"mode\": \"node\"<br \/>\n    },<br \/>\n    \"role\": \"node\",<br \/>\n    \"scopes\": [],<br \/>\n    \"caps\": [\"camera\", \"canvas\", \"screen\", \"location\", \"voice\"],<br \/>\n    \"commands\": [\"camera.snap\", \"canvas.navigate\", \"screen.record\", \"location.get\"],<br \/>\n    \"permissions\": { \"camera.capture\": true, \"screen.record\": false },<br \/>\n    \"auth\": { \"token\": \"\u2026\" },<br \/>\n    \"locale\": \"en-US\",<br \/>\n    \"userAgent\": \"openclaw-ios\/1.2.3\",<br \/>\n    \"device\": {<br \/>\n      \"id\": \"device_fingerprint\",<br \/>\n      \"publicKey\": \"\u2026\",<br \/>\n      \"signature\": \"\u2026\",<br \/>\n      \"signedAt\": 1737264000000,<br \/>\n      \"nonce\": \"\u2026\"<br \/>\n    }<br \/>\n  }<br \/>\n}<\/code><\/p>\n<h2>\u5e27\u683c\u5f0f<\/h2>\n<ul>\n<li><strong>Request<\/strong>\uff1a<code>{type:\"req\", id, method, params}<\/code><\/li>\n<li><strong>Response<\/strong>\uff1a<code>{type:\"res\", id, ok, payload|error}<\/code><\/li>\n<li><strong>Event<\/strong>\uff1a<code>{type:\"event\", event, payload, seq?, stateVersion?}<\/code><\/li>\n<\/ul>\n<p>\u6709\u526f\u4f5c\u7528\u7684\u65b9\u6cd5\u9700\u8981<strong>\u5e42\u7b49\u952e<\/strong>\uff08\u89c1\u6a21\u5f0f\uff09\u3002<\/p>\n<h2>\u89d2\u8272 + \u4f5c\u7528\u57df<\/h2>\n<h3>\u89d2\u8272<\/h3>\n<ul>\n<li><code>operator<\/code> = \u63a7\u5236\u5e73\u9762\u5ba2\u6237\u7aef\uff08CLI\/UI\/\u81ea\u52a8\u5316\uff09\u3002<\/li>\n<li><code>node<\/code> = \u80fd\u529b\u5bbf\u4e3b\uff08camera\/screen\/canvas\/system.run\uff09\u3002<\/li>\n<\/ul>\n<h3>\u4f5c\u7528\u57df\uff08operator\uff09<\/h3>\n<p>\u5e38\u7528\u4f5c\u7528\u57df\uff1a<\/p>\n<ul>\n<li><code>operator.read<\/code><\/li>\n<li><code>operator.write<\/code><\/li>\n<li><code>operator.admin<\/code><\/li>\n<li><code>operator.approvals<\/code><\/li>\n<li><code>operator.pairing<\/code><\/li>\n<\/ul>\n<h3>\u80fd\u529b\/\u547d\u4ee4\/\u6743\u9650\uff08node\uff09<\/h3>\n<p>\u8282\u70b9\u5728\u8fde\u63a5\u65f6\u58f0\u660e\u80fd\u529b\u58f0\u660e\uff1a<\/p>\n<ul>\n<li><code>caps<\/code>\uff1a\u9ad8\u7ea7\u80fd\u529b\u7c7b\u522b\u3002<\/li>\n<li><code>commands<\/code>\uff1ainvoke \u7684\u547d\u4ee4\u5141\u8bb8\u5217\u8868\u3002<\/li>\n<li><code>permissions<\/code>\uff1a\u7ec6\u7c92\u5ea6\u5f00\u5173\uff08\u4f8b\u5982 <code>screen.record<\/code>\u3001<code>camera.capture<\/code>\uff09\u3002<\/li>\n<\/ul>\n<p>Gateway \u7f51\u5173 \u7f51\u5173\u5c06\u8fd9\u4e9b\u89c6\u4e3a<strong>\u58f0\u660e<\/strong>\u5e76\u5f3a\u5236\u6267\u884c\u670d\u52a1\u5668\u7aef\u5141\u8bb8\u5217\u8868\u3002<\/p>\n<h2>\u5728\u7ebf\u72b6\u6001<\/h2>\n<ul>\n<li><code>system-presence<\/code> \u8fd4\u56de\u4ee5\u8bbe\u5907\u8eab\u4efd\u4e3a\u952e\u7684\u6761\u76ee\u3002<\/li>\n<li>\u5728\u7ebf\u72b6\u6001\u6761\u76ee\u5305\u542b <code>deviceId<\/code>\u3001<code>roles<\/code> \u548c <code>scopes<\/code>\uff0c\u4ee5\u4fbf UI \u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u8bbe\u5907\u663e\u793a\u5355\u884c\uff0c<br \/>\n  \u5373\u4f7f\u5b83\u540c\u65f6\u4ee5 <strong>operator<\/strong> \u548c <strong>node<\/strong> \u8eab\u4efd\u8fde\u63a5\u3002<\/li>\n<\/ul>\n<h3>\u8282\u70b9\u8f85\u52a9\u65b9\u6cd5<\/h3>\n<ul>\n<li>\u8282\u70b9\u53ef\u4ee5\u8c03\u7528 <code>skills.bins<\/code> \u6765\u83b7\u53d6\u5f53\u524d\u7684 skill \u53ef\u6267\u884c\u6587\u4ef6\u5217\u8868\uff0c<br \/>\n  \u7528\u4e8e\u81ea\u52a8\u5141\u8bb8\u68c0\u67e5\u3002<\/li>\n<\/ul>\n<h2>Exec \u5ba1\u6279<\/h2>\n<ul>\n<li>\u5f53 exec \u8bf7\u6c42\u9700\u8981\u5ba1\u6279\u65f6\uff0cGateway \u7f51\u5173 \u7f51\u5173\u5e7f\u64ad <code>exec.approval.requested<\/code>\u3002<\/li>\n<li>\u64cd\u4f5c\u8005\u5ba2\u6237\u7aef\u901a\u8fc7\u8c03\u7528 <code>exec.approval.resolve<\/code> \u6765\u89e3\u51b3\uff08\u9700\u8981 <code>operator.approvals<\/code> \u4f5c\u7528\u57df\uff09\u3002<\/li>\n<\/ul>\n<h2>\u7248\u672c\u63a7\u5236<\/h2>\n<ul>\n<li><code>PROTOCOL_VERSION<\/code> \u5728 <code>src\/gateway\/protocol\/schema.ts<\/code> \u4e2d\u3002<\/li>\n<li>\u5ba2\u6237\u7aef\u53d1\u9001 <code>minProtocol<\/code> + <code>maxProtocol<\/code>\uff1b\u670d\u52a1\u5668\u62d2\u7edd\u4e0d\u5339\u914d\u7684\u3002<\/li>\n<li>\u6a21\u5f0f + \u6a21\u578b\u4ece TypeBox \u5b9a\u4e49\u751f\u6210\uff1a<\/li>\n<li><code>pnpm protocol:gen<\/code><\/li>\n<li><code>pnpm protocol:gen:swift<\/code><\/li>\n<li><code>pnpm protocol:check<\/code><\/li>\n<\/ul>\n<h2>\u8ba4\u8bc1<\/h2>\n<ul>\n<li>\u5982\u679c\u8bbe\u7f6e\u4e86 <code>OPENCLAW_GATEWAY_TOKEN<\/code>\uff08\u6216 <code>--token<\/code>\uff09\uff0c<code>connect.params.auth.token<\/code><br \/>\n  \u5fc5\u987b\u5339\u914d\uff0c\u5426\u5219\u5957\u63a5\u5b57\u5c06\u88ab\u5173\u95ed\u3002<\/li>\n<li>\u914d\u5bf9\u540e\uff0cGateway \u7f51\u5173 \u7f51\u5173\u4f1a\u9881\u53d1\u4e00\u4e2a\u4f5c\u7528\u4e8e\u8fde\u63a5\u89d2\u8272 + \u4f5c\u7528\u57df\u7684<strong>\u8bbe\u5907\u4ee4\u724c<\/strong>\u3002\u5b83\u5728 <code>hello-ok.auth.deviceToken<\/code> \u4e2d\u8fd4\u56de\uff0c<br \/>\n  \u5ba2\u6237\u7aef\u5e94\u5c06\u5176\u6301\u4e45\u5316\u4ee5\u4f9b\u5c06\u6765\u8fde\u63a5\u4f7f\u7528\u3002<\/li>\n<li>\u8bbe\u5907\u4ee4\u724c\u53ef\u4ee5\u901a\u8fc7 <code>device.token.rotate<\/code> \u548c <code>device.token.revoke<\/code> \u8f6e\u6362\/\u64a4\u9500\uff08\u9700\u8981 <code>operator.pairing<\/code> \u4f5c\u7528\u57df\uff09\u3002<\/li>\n<\/ul>\n<h2>\u8bbe\u5907\u8eab\u4efd + \u914d\u5bf9<\/h2>\n<ul>\n<li>\u8282\u70b9\u5e94\u5305\u542b\u4ece\u5bc6\u94a5\u5bf9\u6307\u7eb9\u6d3e\u751f\u7684\u7a33\u5b9a\u8bbe\u5907\u8eab\u4efd\uff08<code>device.id<\/code>\uff09\u3002<\/li>\n<li>Gateway \u7f51\u5173 \u7f51\u5173\u4e3a\u6bcf\u4e2a\u8bbe\u5907 + \u89d2\u8272\u9881\u53d1\u4ee4\u724c\u3002<\/li>\n<li>\u65b0\u8bbe\u5907 ID \u9700\u8981\u914d\u5bf9\u6279\u51c6\uff0c\u9664\u975e\u542f\u7528\u4e86\u672c\u5730\u81ea\u52a8\u6279\u51c6\u3002<\/li>\n<li><strong>\u672c\u5730<\/strong>\u8fde\u63a5\u5305\u62ec loopback \u548c Gateway \u7f51\u5173 \u7f51\u5173\u4e3b\u673a\u81ea\u8eab\u7684 tailnet \u5730\u5740<br \/>\n  \uff08\u56e0\u6b64\u540c\u4e3b\u673a tailnet \u7ed1\u5b9a\u4ecd\u53ef\u81ea\u52a8\u6279\u51c6\uff09\u3002<\/li>\n<li>\u6240\u6709 WS \u5ba2\u6237\u7aef\u5728 <code>connect<\/code> \u671f\u95f4\u5fc5\u987b\u5305\u542b <code>device<\/code> \u8eab\u4efd\uff08operator + node\uff09\u3002<br \/>\n  \u63a7\u5236 UI <strong>\u4ec5<\/strong>\u5728\u542f\u7528 <code>gateway.controlUi.allowInsecureAuth<\/code> \u65f6\u53ef\u4ee5\u7701\u7565\u5b83<br \/>\n  \uff08\u6216\u4f7f\u7528 <code>gateway.controlUi.dangerouslyDisableDeviceAuth<\/code> \u7528\u4e8e\u7d27\u6025\u60c5\u51b5\uff09\u3002<\/li>\n<li>\u975e\u672c\u5730\u8fde\u63a5\u5fc5\u987b\u7b7e\u7f72\u670d\u52a1\u5668\u63d0\u4f9b\u7684 <code>connect.challenge<\/code> nonce\u3002<\/li>\n<\/ul>\n<h2>TLS + \u56fa\u5b9a<\/h2>\n<ul>\n<li>WS \u8fde\u63a5\u652f\u6301 TLS\u3002<\/li>\n<li>\u5ba2\u6237\u7aef\u53ef\u4ee5\u9009\u62e9\u6027\u5730\u56fa\u5b9a Gateway \u7f51\u5173 \u7f51\u5173\u8bc1\u4e66\u6307\u7eb9\uff08\u89c1 <code>gateway.tls<\/code><br \/>\n  \u914d\u7f6e\u52a0\u4e0a <code>gateway.remote.tlsFingerprint<\/code> \u6216 CLI <code>--tls-fingerprint<\/code>\uff09\u3002<\/li>\n<\/ul>\n<h2>\u8303\u56f4<\/h2>\n<p>\u6b64\u534f\u8bae\u66b4\u9732<strong>\u5b8c\u6574\u7684 Gateway \u7f51\u5173 \u7f51\u5173 API<\/strong>\uff08status\u3001\u6e20\u9053s\u3001models\u3001chat\u3001<br \/>\nagent\u3001sessions\u3001nodes\u3001approvals \u7b49\uff09\u3002\u786e\u5207\u7684\u63a5\u53e3\u7531 <code>src\/gateway\/protocol\/schema.ts<\/code> \u4e2d\u7684 TypeBox \u6a21\u5f0f\u5b9a\u4e49\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Gateway \u7f51\u5173 \u7f51\u5173\u534f\u8bae Gateway \u7f51\u5173 \u7f51\u5173\u534f\u8bae\uff08WebSocket\uff09 Gateway \u7f51\u5173 \u7f51 [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-136","post","type-post","status-publish","format-standard","hentry","category-docs"],"_links":{"self":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/comments?post=136"}],"version-history":[{"count":2,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/136\/revisions"}],"predecessor-version":[{"id":819,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/136\/revisions\/819"}],"wp:attachment":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/media?parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/categories?post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/tags?post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}