Spaces:
Running
Running
feat: update gateway connection to use token-based authentication and web-client identity headers
Browse files- health-server.js +8 -8
- wa-guardian.js +9 -9
health-server.js
CHANGED
|
@@ -7,6 +7,7 @@ const { randomUUID } = require("node:crypto");
|
|
| 7 |
const PORT = 7861;
|
| 8 |
const GATEWAY_PORT = 7860;
|
| 9 |
const GATEWAY_HOST = "127.0.0.1";
|
|
|
|
| 10 |
const startTime = Date.now();
|
| 11 |
const LLM_MODEL = process.env.LLM_MODEL || "Not Set";
|
| 12 |
const GATEWAY_TOKEN = process.env.GATEWAY_TOKEN || "";
|
|
@@ -85,7 +86,12 @@ function extractErrorMessage(msg) {
|
|
| 85 |
function createGatewayConnection() {
|
| 86 |
return new Promise((resolve, reject) => {
|
| 87 |
const { WebSocket } = require("/home/node/.openclaw/openclaw-app/node_modules/ws");
|
| 88 |
-
const ws = new WebSocket(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
let resolved = false;
|
| 90 |
|
| 91 |
ws.on("message", (data) => {
|
|
@@ -100,14 +106,8 @@ function createGatewayConnection() {
|
|
| 100 |
minProtocol: 3,
|
| 101 |
maxProtocol: 3,
|
| 102 |
auth: { token: GATEWAY_TOKEN },
|
| 103 |
-
client: { id: "
|
| 104 |
-
role: "operator",
|
| 105 |
scopes: ["operator.read"],
|
| 106 |
-
caps: [],
|
| 107 |
-
commands: [],
|
| 108 |
-
permissions: {},
|
| 109 |
-
locale: "en-US",
|
| 110 |
-
userAgent: "huggingclaw-health-server/1.0.0",
|
| 111 |
},
|
| 112 |
}));
|
| 113 |
return;
|
|
|
|
| 7 |
const PORT = 7861;
|
| 8 |
const GATEWAY_PORT = 7860;
|
| 9 |
const GATEWAY_HOST = "127.0.0.1";
|
| 10 |
+
const GATEWAY_ORIGIN = `http://${GATEWAY_HOST}:${GATEWAY_PORT}`;
|
| 11 |
const startTime = Date.now();
|
| 12 |
const LLM_MODEL = process.env.LLM_MODEL || "Not Set";
|
| 13 |
const GATEWAY_TOKEN = process.env.GATEWAY_TOKEN || "";
|
|
|
|
| 86 |
function createGatewayConnection() {
|
| 87 |
return new Promise((resolve, reject) => {
|
| 88 |
const { WebSocket } = require("/home/node/.openclaw/openclaw-app/node_modules/ws");
|
| 89 |
+
const ws = new WebSocket(
|
| 90 |
+
`ws://${GATEWAY_HOST}:${GATEWAY_PORT}/?token=${encodeURIComponent(GATEWAY_TOKEN)}`,
|
| 91 |
+
{
|
| 92 |
+
headers: { Origin: GATEWAY_ORIGIN },
|
| 93 |
+
},
|
| 94 |
+
);
|
| 95 |
let resolved = false;
|
| 96 |
|
| 97 |
ws.on("message", (data) => {
|
|
|
|
| 106 |
minProtocol: 3,
|
| 107 |
maxProtocol: 3,
|
| 108 |
auth: { token: GATEWAY_TOKEN },
|
| 109 |
+
client: { id: "huggingclaw-dashboard", platform: "web", mode: "ui", version: "1.0.0" },
|
|
|
|
| 110 |
scopes: ["operator.read"],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
},
|
| 112 |
}));
|
| 113 |
return;
|
wa-guardian.js
CHANGED
|
@@ -12,7 +12,8 @@ const path = require("path");
|
|
| 12 |
const { WebSocket } = require('/home/node/.openclaw/openclaw-app/node_modules/ws');
|
| 13 |
const { randomUUID } = require('node:crypto');
|
| 14 |
|
| 15 |
-
const
|
|
|
|
| 16 |
const GATEWAY_TOKEN = process.env.GATEWAY_TOKEN || "huggingclaw";
|
| 17 |
const CHECK_INTERVAL = 5000;
|
| 18 |
const WAIT_TIMEOUT = 120000;
|
|
@@ -51,7 +52,12 @@ function writeResetMarker() {
|
|
| 51 |
|
| 52 |
async function createConnection() {
|
| 53 |
return new Promise((resolve, reject) => {
|
| 54 |
-
const ws = new WebSocket(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
let resolved = false;
|
| 56 |
|
| 57 |
ws.on("message", (data) => {
|
|
@@ -66,14 +72,8 @@ async function createConnection() {
|
|
| 66 |
minProtocol: 3,
|
| 67 |
maxProtocol: 3,
|
| 68 |
auth: { token: GATEWAY_TOKEN },
|
| 69 |
-
client: { id: "wa-guardian", platform: "
|
| 70 |
-
role: "operator",
|
| 71 |
scopes: ["operator.admin", "operator.pairing", "operator.read", "operator.write"],
|
| 72 |
-
caps: [],
|
| 73 |
-
commands: [],
|
| 74 |
-
permissions: {},
|
| 75 |
-
locale: "en-US",
|
| 76 |
-
userAgent: "huggingclaw-wa-guardian/1.0.0",
|
| 77 |
}
|
| 78 |
}));
|
| 79 |
return;
|
|
|
|
| 12 |
const { WebSocket } = require('/home/node/.openclaw/openclaw-app/node_modules/ws');
|
| 13 |
const { randomUUID } = require('node:crypto');
|
| 14 |
|
| 15 |
+
const GATEWAY_WS_URL = "ws://127.0.0.1:7860";
|
| 16 |
+
const GATEWAY_ORIGIN = "http://127.0.0.1:7860";
|
| 17 |
const GATEWAY_TOKEN = process.env.GATEWAY_TOKEN || "huggingclaw";
|
| 18 |
const CHECK_INTERVAL = 5000;
|
| 19 |
const WAIT_TIMEOUT = 120000;
|
|
|
|
| 52 |
|
| 53 |
async function createConnection() {
|
| 54 |
return new Promise((resolve, reject) => {
|
| 55 |
+
const ws = new WebSocket(
|
| 56 |
+
`${GATEWAY_WS_URL}/?token=${encodeURIComponent(GATEWAY_TOKEN)}`,
|
| 57 |
+
{
|
| 58 |
+
headers: { Origin: GATEWAY_ORIGIN },
|
| 59 |
+
},
|
| 60 |
+
);
|
| 61 |
let resolved = false;
|
| 62 |
|
| 63 |
ws.on("message", (data) => {
|
|
|
|
| 72 |
minProtocol: 3,
|
| 73 |
maxProtocol: 3,
|
| 74 |
auth: { token: GATEWAY_TOKEN },
|
| 75 |
+
client: { id: "huggingclaw-wa-guardian", platform: "web", mode: "ui", version: "1.0.0" },
|
|
|
|
| 76 |
scopes: ["operator.admin", "operator.pairing", "operator.read", "operator.write"],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
}
|
| 78 |
}));
|
| 79 |
return;
|