pi-web-ui 0.2.3 → 0.2.5

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/README.md CHANGED
@@ -28,7 +28,9 @@ your existing pi auth/config/extensions — nothing extra to install or configur
28
28
 
29
29
  ## Quick start
30
30
 
31
- Requires Node.js ≥ 20.11 and a configured pi install (run `pi` once to log in).
31
+ Requires Node.js ≥ 22.19 (the pi SDK requires it; older Node fails with
32
+ `Unexpected token 'with'` when loading the SDK) and a configured pi install
33
+ (run `pi` once to log in).
32
34
 
33
35
  ```bash
34
36
  npm install
package/bin/pi-web-ui.mjs CHANGED
@@ -68,6 +68,24 @@ server 选项:
68
68
  PORT / PI_WEB_CWD / PI_WEB_DATA_DIR / PI_CODING_AGENT_DIR
69
69
  `;
70
70
 
71
+ /** Minimum Node required by the pi SDK (its dist uses `import … with { type: "json" }`). */
72
+ const NODE_MIN = [22, 19, 0];
73
+ function checkNodeVersion() {
74
+ const v = process.versions.node.split(".").map(Number);
75
+ const tooOld =
76
+ v[0] < NODE_MIN[0] ||
77
+ (v[0] === NODE_MIN[0] && v[1] < NODE_MIN[1]) ||
78
+ (v[0] === NODE_MIN[0] && v[1] === NODE_MIN[1] && v[2] < NODE_MIN[2]);
79
+ if (tooOld) {
80
+ console.error(
81
+ `✖ pi-web-ui 需要 Node.js >= ${NODE_MIN.join(".")}(当前 ${process.versions.node})。\n` +
82
+ ` pi SDK 的代码使用了 import attributes(with)语法,旧版 Node 无法解析。\n` +
83
+ ` 请升级 Node:https://nodejs.org(或 nvm-windows / fnm)后重装:npm i -g pi-web-ui`,
84
+ );
85
+ process.exit(1);
86
+ }
87
+ }
88
+
71
89
  function fail(msg) {
72
90
  console.error(`✖ ${msg}`);
73
91
  process.exit(1);
@@ -712,6 +730,7 @@ async function serverCmd(argv) {
712
730
  }
713
731
 
714
732
  async function main() {
733
+ checkNodeVersion();
715
734
  const argv = process.argv.slice(2);
716
735
  if (argv.length === 0) {
717
736
  await startForeground({});
@@ -562,25 +562,40 @@ export class ClientSession {
562
562
  this.piCheckCache = { at: now, configured };
563
563
  return configured;
564
564
  }
565
- /** Run a command async, collecting stdout+stderr; kills on timeout. */
565
+ /**
566
+ * Run a command async, collecting stdout+stderr; kills on timeout.
567
+ * Never throws / never crashes the server: spawn errors (ENOENT etc.)
568
+ * resolve with code -1 so callers can report them as notices.
569
+ */
566
570
  runAsync(cmd, args, timeoutMs) {
567
571
  return new Promise((resolve) => {
568
572
  let p;
569
573
  try {
570
- p = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
574
+ p = spawn(cmd, args, {
575
+ stdio: ["ignore", "pipe", "pipe"],
576
+ // Windows: npm and friends are .cmd shims — Node can only exec
577
+ // them through the shell (otherwise spawn npm → ENOENT).
578
+ shell: process.platform === "win32",
579
+ });
571
580
  }
572
581
  catch (err) {
573
582
  resolve({ code: -1, out: String(err) });
574
583
  return;
575
584
  }
576
585
  let out = "";
586
+ let settled = false;
587
+ const done = (code, text) => {
588
+ if (settled)
589
+ return;
590
+ settled = true;
591
+ clearTimeout(t);
592
+ resolve({ code, out: text ?? out });
593
+ };
594
+ const t = setTimeout(() => p.kill(), timeoutMs);
577
595
  p.stdout?.on("data", (d) => (out += d.toString()));
578
596
  p.stderr?.on("data", (d) => (out += d.toString()));
579
- const t = setTimeout(() => p.kill(), timeoutMs);
580
- p.on("close", (code) => {
581
- clearTimeout(t);
582
- resolve({ code, out });
583
- });
597
+ p.on("error", (err) => done(-1, String(err)));
598
+ p.on("close", (code) => done(code));
584
599
  });
585
600
  }
586
601
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-web-ui",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Web chat interface for the pi coding agent, powered by the pi SDK (@earendil-works/pi-coding-agent) — one-command run, Docker/systemd/launchd deployable",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -30,7 +30,7 @@
30
30
  "url": "git+https://github.com/xing-shuyin/pi-web-ui.git"
31
31
  },
32
32
  "engines": {
33
- "node": ">=20.11"
33
+ "node": ">=22.19.0"
34
34
  },
35
35
  "scripts": {
36
36
  "prepublishOnly": "npm run build",