bnpanel 0.6.3 → 0.6.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.
Files changed (2) hide show
  1. package/index.js +68 -5
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -7852,6 +7852,16 @@ import fs7 from "node:fs";
7852
7852
  import net from "node:net";
7853
7853
  import path7 from "node:path";
7854
7854
  import { spawn } from "node:child_process";
7855
+ function resolveNodeRuntime(env = process.env) {
7856
+ const explicit = env.PANEL_NODE_BIN || env.NODE_BIN;
7857
+ if (explicit) return { command: explicit, env: {} };
7858
+ const npmNode = env.npm_node_execpath;
7859
+ if (npmNode && fs7.existsSync(npmNode)) return { command: npmNode, env: {} };
7860
+ if (process.versions.electron) {
7861
+ return { command: process.execPath, env: { ELECTRON_RUN_AS_NODE: "1" } };
7862
+ }
7863
+ return { command: process.execPath, env: {} };
7864
+ }
7855
7865
  var Supervisor = class {
7856
7866
  constructor(paths, spawnImpl = spawn) {
7857
7867
  this.paths = paths;
@@ -7872,7 +7882,17 @@ var Supervisor = class {
7872
7882
  const entry = path7.resolve(agent.dir, agent.manifest.entry.host);
7873
7883
  const workspaceRoot = opts.workspaceRoot ? path7.isAbsolute(opts.workspaceRoot) ? opts.workspaceRoot : path7.resolve(opts.workspaceRoot) : this.paths.workspaces;
7874
7884
  const workspace = path7.join(workspaceRoot, agent.id);
7875
- fs7.mkdirSync(workspace, { recursive: true });
7885
+ try {
7886
+ fs7.mkdirSync(workspace, { recursive: true });
7887
+ const probe = path7.join(workspace, `.write-probe-${process.pid}`);
7888
+ fs7.writeFileSync(probe, "");
7889
+ fs7.rmSync(probe, { force: true });
7890
+ } catch (err) {
7891
+ const e = err;
7892
+ throw new Error(
7893
+ `\u5DE5\u4F5C\u76EE\u5F55\u4E0D\u53EF\u7528\uFF1A${workspace}\uFF08${e.code ?? "ERROR"}: ${e.message}\uFF09\u3002\u8BF7\u5728\u8BBE\u7F6E\u91CC\u6362\u6210\u672C\u673A\u53EF\u5199\u7684\u76EE\u5F55\u540E\u91CD\u8BD5\u3002`
7894
+ );
7895
+ }
7876
7896
  const env = {
7877
7897
  ...process.env,
7878
7898
  PANEL_PORT: String(port),
@@ -7889,15 +7909,47 @@ var Supervisor = class {
7889
7909
  ...opts.panelCallbackToken ? { PANEL_CALLBACK_TOKEN: opts.panelCallbackToken } : {},
7890
7910
  ...opts.extraEnv ?? {}
7891
7911
  };
7892
- const child = this.spawnImpl(process.execPath, [entry], { cwd: agent.dir, env });
7912
+ const node = resolveNodeRuntime();
7913
+ const child = this.spawnImpl(node.command, [entry], { cwd: agent.dir, env: { ...env, ...node.env } });
7893
7914
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
7894
7915
  const record = { id: agent.id, pid: child.pid ?? -1, port, url: `http://127.0.0.1:${port}`, startedAt, child, restarts: 0 };
7895
7916
  this.running.set(agent.id, record);
7917
+ let tail = "";
7918
+ let spawnError = null;
7919
+ const capture = (chunk) => {
7920
+ tail = (tail + chunk.toString()).slice(-1200);
7921
+ };
7922
+ child.stdout?.on("data", capture);
7923
+ child.stderr?.on("data", capture);
7924
+ child.once("error", (err) => {
7925
+ spawnError = err;
7926
+ });
7896
7927
  child.once("exit", () => {
7897
7928
  const current = this.running.get(agent.id);
7898
7929
  if (current?.child === child) this.running.delete(agent.id);
7899
7930
  });
7900
- await waitForPort(port, opts.timeoutMs ?? 2e4);
7931
+ const exitWatcher = new Promise((_2, reject) => {
7932
+ child.once("error", (err) => reject(new Error(`Agent \u8FDB\u7A0B\u542F\u52A8\u5931\u8D25\uFF1A${err.message}`)));
7933
+ child.once("exit", (code) => reject(new Error(`Agent \u8FDB\u7A0B\u542F\u52A8\u540E\u7ACB\u5373\u9000\u51FA\uFF08exitCode=${code}\uFF09`)));
7934
+ });
7935
+ exitWatcher.catch(() => {
7936
+ });
7937
+ try {
7938
+ const waiter = waitForPort(port, opts.timeoutMs ?? 2e4);
7939
+ waiter.catch(() => {
7940
+ });
7941
+ await Promise.race([waiter, exitWatcher]);
7942
+ } catch (err) {
7943
+ this.running.delete(agent.id);
7944
+ if (!child.killed) child.kill("SIGKILL");
7945
+ const lines = [`${err.message}`];
7946
+ if (spawnError) lines.push(`\u542F\u52A8\u5931\u8D25\uFF1A${spawnError.message}`);
7947
+ else if (child.exitCode !== null) lines.push(`Agent \u8FDB\u7A0B\u5DF2\u9000\u51FA\uFF0CexitCode=${child.exitCode}`);
7948
+ lines.push(`workspace=${workspace}`, `command=${node.command}`);
7949
+ if (tail.trim()) lines.push(`--- agent output ---
7950
+ ${tail.trim()}`);
7951
+ throw new Error(lines.join("\n"));
7952
+ }
7901
7953
  return this.list().find((r) => r.id === agent.id);
7902
7954
  }
7903
7955
  async stop(id) {
@@ -9618,7 +9670,8 @@ function createPanelApp(options = {}) {
9618
9670
  settings: {
9619
9671
  autoInstallUpdates: !!settings.autoInstallUpdates,
9620
9672
  autoUpdate: settings.autoUpdate !== false,
9621
- autoKickoffInDsh: settings.autoKickoffInDsh !== false
9673
+ autoKickoffInDsh: settings.autoKickoffInDsh !== false,
9674
+ workspaceRoot: settings.workspaceRoot || null
9622
9675
  },
9623
9676
  panel: {
9624
9677
  name: packageName,
@@ -9657,7 +9710,8 @@ function createPanelApp(options = {}) {
9657
9710
  tasks: queue.list(),
9658
9711
  settings: {
9659
9712
  autoInstallUpdates: !!settings.autoInstallUpdates,
9660
- autoKickoffInDsh: settings.autoKickoffInDsh !== false
9713
+ autoKickoffInDsh: settings.autoKickoffInDsh !== false,
9714
+ workspaceRoot: settings.workspaceRoot || null
9661
9715
  },
9662
9716
  dsh: {
9663
9717
  skills: !!dsh?.skills?.available?.(),
@@ -10301,6 +10355,15 @@ function createPanelApp(options = {}) {
10301
10355
  } else {
10302
10356
  try {
10303
10357
  const target = path14.isAbsolute(raw) ? raw : path14.resolve(raw);
10358
+ const trim = (p2) => p2.replace(/[\\/]+$/, "").toLowerCase();
10359
+ const picked = trim(target);
10360
+ const panelRoot = trim(path14.resolve(paths.root));
10361
+ if (picked === panelRoot || picked.startsWith(`${panelRoot}${path14.sep}`)) {
10362
+ return send(res, 400, { error: "\u4E0D\u80FD\u9009\u9762\u677F\u6570\u636E\u76EE\u5F55\uFF08DSH-PANEL\uFF09\u6216\u5176\u5B50\u76EE\u5F55\uFF0C\u8BF7\u6362\u4E00\u4E2A\u72EC\u7ACB\u6587\u4EF6\u5939\uFF0C\u4F8B\u5982 D:\\BiuNow" });
10363
+ }
10364
+ if (trim(path14.parse(target).root) === picked) {
10365
+ return send(res, 400, { error: "\u4E0D\u80FD\u76F4\u63A5\u9009\u78C1\u76D8\u6839\u76EE\u5F55\uFF0C\u8BF7\u5728\u5176\u4E0B\u65B0\u5EFA\u4E00\u4E2A\u6587\u4EF6\u5939" });
10366
+ }
10304
10367
  fs14.mkdirSync(target, { recursive: true });
10305
10368
  const probe = path14.join(target, `.bnpanel-write-test-${Date.now()}`);
10306
10369
  fs14.writeFileSync(probe, "ok");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bnpanel",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "type": "module",
5
5
  "description": "无需AI生图/生视频,本机低配置即可运行的‘解说、动效、风格化’视频创作工厂。",
6
6
  "license": "UNLICENSED",