@syengup/friday-channel-next 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/install.js +41 -10
  2. package/install.sh +57 -2
  3. package/package.json +1 -1
package/install.js CHANGED
@@ -144,15 +144,13 @@ console.log(" Config updated.");
144
144
  log("Restarting OpenClaw gateway...");
145
145
  execSync("openclaw gateway restart", { stdio: "inherit" });
146
146
 
147
- // --------------- show connection info ---------------
147
+ // --------------- verify ---------------
148
148
 
149
149
  function getLanIp() {
150
150
  const nets = networkInterfaces();
151
151
  for (const name of Object.keys(nets)) {
152
152
  for (const net of nets[name]) {
153
- if (net.family === "IPv4" && !net.internal) {
154
- return net.address;
155
- }
153
+ if (net.family === "IPv4" && !net.internal) return net.address;
156
154
  }
157
155
  }
158
156
  return "127.0.0.1";
@@ -162,14 +160,47 @@ const gatewayPort = config.gateway?.port || 18789;
162
160
  const gatewayToken = config.gateway?.auth?.token || "(not set)";
163
161
  const bindMode = config.gateway?.bind || "localhost";
164
162
 
165
- let gatewayUrl;
166
- if (bindMode === "lan") {
167
- const ip = getLanIp();
168
- gatewayUrl = `http://${ip}:${gatewayPort}`;
169
- } else {
170
- gatewayUrl = `http://127.0.0.1:${gatewayPort}`;
163
+ const gatewayUrl = bindMode === "lan"
164
+ ? `http://${getLanIp()}:${gatewayPort}`
165
+ : `http://127.0.0.1:${gatewayPort}`;
166
+
167
+ async function verifyGateway(url, token, retries = 6) {
168
+ const http = await import("node:http");
169
+ const { hostname, port } = new URL(url);
170
+ for (let i = 1; i <= retries; i++) {
171
+ await new Promise((r) => setTimeout(r, 1000));
172
+ try {
173
+ const res = await new Promise((resolve, reject) => {
174
+ const req = http.request(
175
+ { hostname, port, path: "/friday-next/status", method: "GET",
176
+ headers: { authorization: `Bearer ${token}` }, timeout: 5000 },
177
+ (res) => { let body = ""; res.on("data", (c) => body += c); res.on("end", () => resolve({ status: res.statusCode, body })); },
178
+ );
179
+ req.on("error", reject);
180
+ req.on("timeout", () => { req.destroy(); reject(new Error("timeout")); });
181
+ req.end();
182
+ });
183
+ if (res.status === 200) {
184
+ const data = JSON.parse(res.body);
185
+ if (data.ok) {
186
+ log("Gateway verified OK (friday-next " + data.version + ", " + data.connections + " connections).");
187
+ return true;
188
+ }
189
+ }
190
+ if (i < retries) warn(`Gateway responded ${res.status}, retrying (${i}/${retries})...`);
191
+ } catch {
192
+ if (i < retries) warn(`Gateway not ready, retrying (${i}/${retries})...`);
193
+ }
194
+ }
195
+ warn("Gateway verification timed out — check 'openclaw gateway status' manually.");
196
+ return false;
171
197
  }
172
198
 
199
+ log("Verifying gateway...");
200
+ await verifyGateway(gatewayUrl, gatewayToken);
201
+
202
+ // --------------- show connection info ---------------
203
+
173
204
  const BOLD_YELLOW = (s) => `\x1b[1;33m${s}\x1b[0m`;
174
205
 
175
206
  log("--------------------------------------------------");
package/install.sh CHANGED
@@ -109,6 +109,61 @@ console.log(" Config updated.");
109
109
  log "Restarting OpenClaw gateway..."
110
110
  openclaw gateway restart
111
111
 
112
+ # Verify gateway is up
113
+ log "Verifying gateway..."
114
+ node --input-type=module -e '
115
+ import { readFileSync } from "node:fs";
116
+ import { networkInterfaces } from "node:os";
117
+ import http from "node:http";
118
+
119
+ const config = JSON.parse(readFileSync(process.argv[1], "utf8"));
120
+
121
+ function getLanIp() {
122
+ const nets = networkInterfaces();
123
+ for (const name of Object.keys(nets)) {
124
+ for (const net of nets[name]) {
125
+ if (net.family === "IPv4" && !net.internal) return net.address;
126
+ }
127
+ }
128
+ return "127.0.0.1";
129
+ }
130
+
131
+ const port = config.gateway?.port || 18789;
132
+ const token = config.gateway?.auth?.token || "";
133
+ const bind = config.gateway?.bind || "localhost";
134
+ const host = bind === "lan" ? getLanIp() : "127.0.0.1";
135
+
136
+ async function verifyGateway() {
137
+ for (let i = 1; i <= 6; i++) {
138
+ await new Promise((r) => setTimeout(r, 1000));
139
+ try {
140
+ const res = await new Promise((resolve, reject) => {
141
+ const req = http.request(
142
+ { hostname: host, port, path: "/friday-next/status", method: "GET",
143
+ headers: { authorization: "Bearer " + token }, timeout: 5000 },
144
+ (res) => { let body = ""; res.on("data", (c) => body += c); res.on("end", () => resolve({ status: res.statusCode, body })); },
145
+ );
146
+ req.on("error", reject);
147
+ req.on("timeout", () => { req.destroy(); reject(new Error("timeout")); });
148
+ req.end();
149
+ });
150
+ if (res.status === 200) {
151
+ const data = JSON.parse(res.body);
152
+ if (data.ok) {
153
+ console.log(" Gateway verified OK (friday-next " + data.version + ", " + data.connections + " connections).");
154
+ return;
155
+ }
156
+ }
157
+ if (i < 6) console.log(" ! Gateway responded " + res.status + ", retrying (" + i + "/6)...");
158
+ } catch {
159
+ if (i < 6) console.log(" ! Gateway not ready, retrying (" + i + "/6)...");
160
+ }
161
+ }
162
+ console.log(" ! Gateway verification timed out — check '\''openclaw gateway status'\'' manually.");
163
+ }
164
+ await verifyGateway();
165
+ ' "$OPENCLAW_CONFIG"
166
+
112
167
  # Show connection info
113
168
  node --input-type=module -e '
114
169
  import { readFileSync } from "node:fs";
@@ -131,7 +186,7 @@ const token = config.gateway?.auth?.token || "(not set)";
131
186
  const bind = config.gateway?.bind || "localhost";
132
187
  const host = bind === "lan" ? getLanIp() : "127.0.0.1";
133
188
 
134
- const YB = '\x1b[1;33m', N = '\x1b[0m';
189
+ const YB = "\x1b[1;33m", N = "\x1b[0m";
135
190
  const qrPayload = JSON.stringify({ url: "http://" + host + ":" + port, token: token });
136
191
  let qrShown = false;
137
192
  try {
@@ -143,7 +198,7 @@ try {
143
198
  console.log("");
144
199
  qrcode.generate(qrPayload, { small: true });
145
200
  console.log("");
146
- console.log("If QR scan doesn't work, enter manually:");
201
+ console.log("If QR scan does not work, enter manually:");
147
202
  console.log("若二维码无法使用,请手动输入:");
148
203
  qrShown = true;
149
204
  } catch {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syengup/friday-channel-next",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "OpenClaw Friday Next Apple channel plugin",
5
5
  "type": "module",
6
6
  "files": [