forge-openclaw-plugin 0.2.30 → 0.2.32

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.
package/dist/index.html CHANGED
@@ -13,7 +13,7 @@
13
13
  />
14
14
  <link rel="icon" type="image/png" href="/forge/assets/favicon-BCHm9dUV.ico" />
15
15
  <link rel="alternate icon" href="/forge/assets/favicon-BCHm9dUV.ico" />
16
- <script type="module" crossorigin src="/forge/assets/index-CPC6E84V.js"></script>
16
+ <script type="module" crossorigin src="/forge/assets/index-BE_4LX2c.js"></script>
17
17
  <link rel="modulepreload" crossorigin href="/forge/assets/vendor-OwcH20PM.js">
18
18
  <link rel="modulepreload" crossorigin href="/forge/assets/board-q8cfwaAW.js">
19
19
  <link rel="modulepreload" crossorigin href="/forge/assets/ui-BV0OYxkH.js">
@@ -1,3 +1,5 @@
1
+ import { request as httpRequest } from "node:http";
2
+ import { request as httpsRequest } from "node:https";
1
3
  import { spawn } from "node:child_process";
2
4
  import { existsSync } from "node:fs";
3
5
  import { access, readFile } from "node:fs/promises";
@@ -133,9 +135,13 @@ function copyProxyHeaders(response, reply) {
133
135
  reply.header(name, value);
134
136
  }
135
137
  }
138
+ function buildDevWebTarget(origin, pathname, search) {
139
+ const target = new URL(pathname.startsWith("/") ? pathname.slice(1) : pathname, origin);
140
+ target.search = search;
141
+ return target;
142
+ }
136
143
  async function proxyDevAsset(input) {
137
- const target = new URL(input.pathname.startsWith("/") ? input.pathname.slice(1) : input.pathname, input.origin);
138
- target.search = input.search;
144
+ const target = buildDevWebTarget(input.origin, input.pathname, input.search);
139
145
  const response = await input.fetchImpl(target, { redirect: "manual" });
140
146
  input.reply.code(response.status);
141
147
  copyProxyHeaders(response, input.reply);
@@ -147,6 +153,56 @@ async function proxyDevAsset(input) {
147
153
  }
148
154
  return Buffer.from(await response.arrayBuffer());
149
155
  }
156
+ function writeProxyUpgradeResponse(socket, response) {
157
+ const statusCode = response.statusCode ?? 101;
158
+ const statusMessage = response.statusMessage ?? "Switching Protocols";
159
+ const headerLines = [];
160
+ for (let index = 0; index < response.rawHeaders.length; index += 2) {
161
+ const name = response.rawHeaders[index];
162
+ const value = response.rawHeaders[index + 1];
163
+ if (name && value) {
164
+ headerLines.push(`${name}: ${value}`);
165
+ }
166
+ }
167
+ socket.write(`HTTP/${response.httpVersion} ${statusCode} ${statusMessage}\r\n${headerLines.join("\r\n")}\r\n\r\n`);
168
+ }
169
+ async function proxyDevWebSocket(input) {
170
+ const requestTarget = parseRequestTarget(input.request.url ?? "/");
171
+ const normalizedRequestPath = stripBasePath(requestTarget.pathname, getDefaultBasePath());
172
+ if (!normalizedRequestPath.startsWith("/__vite_hmr")) {
173
+ return false;
174
+ }
175
+ const devWebOrigin = await input.devWebRuntime.ensureReady();
176
+ if (!devWebOrigin) {
177
+ input.socket.destroy();
178
+ return true;
179
+ }
180
+ const target = buildDevWebTarget(devWebOrigin, normalizedRequestPath, requestTarget.search);
181
+ const proxyRequest = (target.protocol === "https:" ? httpsRequest : httpRequest)(target, {
182
+ headers: {
183
+ ...input.request.headers,
184
+ host: target.host
185
+ }
186
+ });
187
+ proxyRequest.on("upgrade", (response, proxySocket, proxyHead) => {
188
+ writeProxyUpgradeResponse(input.socket, response);
189
+ if (proxyHead.length > 0) {
190
+ input.socket.write(proxyHead);
191
+ }
192
+ if (input.head.length > 0) {
193
+ proxySocket.write(input.head);
194
+ }
195
+ proxySocket.pipe(input.socket).pipe(proxySocket);
196
+ });
197
+ proxyRequest.on("response", () => {
198
+ input.socket.destroy();
199
+ });
200
+ proxyRequest.on("error", () => {
201
+ input.socket.destroy();
202
+ });
203
+ proxyRequest.end();
204
+ return true;
205
+ }
150
206
  async function waitForProcessExit(child, timeoutMs = 5_000) {
151
207
  if (child.exitCode !== null) {
152
208
  return;
@@ -327,6 +383,16 @@ export async function registerWebRoutes(app, options = {}) {
327
383
  app.addHook("onClose", async () => {
328
384
  await devWebRuntime.stop();
329
385
  });
386
+ app.server.on("upgrade", (request, socket, head) => {
387
+ void (async () => {
388
+ await proxyDevWebSocket({
389
+ devWebRuntime,
390
+ request,
391
+ socket,
392
+ head
393
+ });
394
+ })();
395
+ });
330
396
  app.get("/", async (_request, reply) => serveAsset("/", reply, { devWebRuntime, fetchImpl }));
331
397
  app.get("/*", async (request, reply) => serveAsset(request.url, reply, { devWebRuntime, fetchImpl }));
332
398
  }
@@ -2,7 +2,7 @@
2
2
  "id": "forge-openclaw-plugin",
3
3
  "name": "Forge",
4
4
  "description": "Curated OpenClaw adapter for the Forge collaboration API, UI entrypoint, and localhost auto-start runtime.",
5
- "version": "0.2.30",
5
+ "version": "0.2.32",
6
6
  "skills": [
7
7
  "./skills"
8
8
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forge-openclaw-plugin",
3
- "version": "0.2.30",
3
+ "version": "0.2.32",
4
4
  "description": "Curated OpenClaw adapter for the Forge collaboration API, UI entrypoint, and localhost auto-start runtime.",
5
5
  "type": "module",
6
6
  "license": "MIT",