@rotriz/pi-web-ui 1.0.1 → 1.0.2

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 (2) hide show
  1. package/extension.mjs +17 -2
  2. package/package.json +2 -2
package/extension.mjs CHANGED
@@ -10,9 +10,24 @@ import { dirname, join } from "node:path";
10
10
  import { exec, execFile } from "node:child_process";
11
11
  import { fileURLToPath } from "node:url";
12
12
  import { existsSync } from "node:fs";
13
+ import { request } from "node:http";
13
14
 
14
15
  const PORT = Number(process.env.PI_WEB_PORT || process.env.PORT || 3123);
15
16
 
17
+ // HTTP GET helper — works on Node 14+ without global fetch
18
+ function httpGet(url) {
19
+ return new Promise((resolve) => {
20
+ const req = request(url, (res) => {
21
+ let data = "";
22
+ res.on("data", (chunk) => (data += chunk));
23
+ res.on("end", () => resolve({ ok: res.statusCode >= 200 && res.statusCode < 300, status: res.statusCode, data }));
24
+ });
25
+ req.on("error", () => resolve({ ok: false, status: 0, data: "" }));
26
+ req.setTimeout(3000, () => { req.destroy(); resolve({ ok: false, status: 0, data: "" }); });
27
+ req.end();
28
+ });
29
+ }
30
+
16
31
  function openBrowser(url) {
17
32
  const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
18
33
  exec(`${cmd} ${JSON.stringify(url)}`, () => {});
@@ -38,7 +53,7 @@ export default function (pi) {
38
53
  async function ensureServer() {
39
54
  // Check if server is already running (from a previous session or manual start)
40
55
  try {
41
- const res = await fetch(`${origin}/api/tabs`);
56
+ const res = await httpGet(`${origin}/api/tabs`);
42
57
  if (res.ok) return; // Already running, reuse it
43
58
  } catch {}
44
59
 
@@ -58,7 +73,7 @@ export default function (pi) {
58
73
  for (let i = 0; i < 60; i++) {
59
74
  await new Promise((r) => setTimeout(r, 500));
60
75
  try {
61
- const res = await fetch(`${origin}/api/tabs`);
76
+ const res = await httpGet(`${origin}/api/tabs`);
62
77
  if (res.ok) return;
63
78
  } catch {}
64
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rotriz/pi-web-ui",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Web UI extension for the Pi coding agent — browser-based session management, git integration, and task tracking",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -30,6 +30,6 @@
30
30
  "@earendil-works/pi-coding-agent": "*"
31
31
  },
32
32
  "engines": {
33
- "node": ">=20"
33
+ "node": ">=16"
34
34
  }
35
35
  }