xiaozhi-client 2.3.0 → 2.3.1-beta.1

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.
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from 'node:module';
2
- const require = createRequire(import.meta.url);
3
- var __require = require;
2
+ globalThis.require = createRequire(import.meta.url);
3
+
4
4
  var __defProp = Object.defineProperty;
5
5
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
6
  var __export = (target, all) => {
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from 'node:module';
2
- const require = createRequire(import.meta.url);
3
- var __require = require;
2
+ globalThis.require = createRequire(import.meta.url);
3
+
4
4
  var __create = Object.create;
5
5
  var __defProp = Object.defineProperty;
6
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -58071,7 +58071,7 @@ var UpdateApiHandler = class extends BaseHandler {
58071
58071
  import fs3 from "fs";
58072
58072
  import path6 from "path";
58073
58073
  import { fileURLToPath as fileURLToPath4 } from "url";
58074
- var VERSION2 = "2.3.0";
58074
+ var VERSION2 = "2.3.1-beta.1";
58075
58075
  var APP_NAME = "xiaozhi-client";
58076
58076
  var VersionUtils = class _VersionUtils {
58077
58077
  static {
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire } from 'node:module';
3
- const require = createRequire(import.meta.url);
4
- var __require = require;
3
+ globalThis.require = createRequire(import.meta.url);
4
+
5
5
  var __create = Object.create;
6
6
  var __defProp = Object.defineProperty;
7
7
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -59788,7 +59788,7 @@ var VERSION2, APP_NAME, VersionUtils;
59788
59788
  var init_version2 = __esm({
59789
59789
  "../utils/version.ts"() {
59790
59790
  "use strict";
59791
- VERSION2 = "2.3.0";
59791
+ VERSION2 = "2.3.1-beta.1";
59792
59792
  APP_NAME = "xiaozhi-client";
59793
59793
  VersionUtils = class _VersionUtils {
59794
59794
  static {
package/dist/cli/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ import { createRequire } from 'node:module';
3
+ globalThis.require = createRequire(import.meta.url);
4
+
2
5
  var __defProp = Object.defineProperty;
3
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
7
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -2663,9 +2666,16 @@ var init_PathUtils = __esm({
2663
2666
  }
2664
2667
  /**
2665
2668
  * 获取项目根目录路径
2669
+ *
2670
+ * 兼容开发和构建两种环境:
2671
+ * - 开发环境:脚本位于 src/cli/ 下,需向上 3 级
2672
+ * - 构建环境:脚本位于 dist/cli/ 下,需向上 2 级
2666
2673
  */
2667
2674
  static getProjectRoot() {
2668
2675
  const scriptDir = _PathUtils.getScriptDir();
2676
+ if (scriptDir.endsWith("/dist/cli") || scriptDir.endsWith("\\dist\\cli")) {
2677
+ return path5.join(scriptDir, "..", "..");
2678
+ }
2669
2679
  return path5.join(scriptDir, "..", "..", "..");
2670
2680
  }
2671
2681
  /**
@@ -2749,11 +2759,11 @@ var init_PathUtils = __esm({
2749
2759
  }
2750
2760
  /**
2751
2761
  * 获取 Web 服务器启动器路径
2752
- * 返回项目根目录 dist 下的 WebServerLauncher.js(向后兼容包装脚本)
2762
+ * 返回项目根目录 dist/backend 下的 WebServerLauncher.js
2753
2763
  */
2754
2764
  static getWebServerLauncherPath() {
2755
2765
  const projectRoot = _PathUtils.getProjectRoot();
2756
- return path5.join(projectRoot, "dist", "WebServerLauncher.js");
2766
+ return path5.join(projectRoot, "dist", "backend", "WebServerLauncher.js");
2757
2767
  }
2758
2768
  /**
2759
2769
  * 创建安全的文件路径
@@ -3754,56 +3764,40 @@ var init_ServiceManager = __esm({
3754
3764
  }
3755
3765
  }
3756
3766
  /**
3757
- * 启动普通模式
3767
+ * 启动普通模式(始终以守护进程方式运行)
3758
3768
  */
3759
- async startNormalMode(options) {
3760
- if (options.daemon) {
3761
- await this.startWebServerInDaemon();
3762
- } else {
3763
- await this.startWebServerInForeground();
3764
- }
3769
+ async startNormalMode(_options) {
3770
+ await this.startWebServerInDaemon();
3765
3771
  }
3766
3772
  /**
3767
- * 启动 MCP Server 模式
3773
+ * 启动 MCP Server 模式(始终以守护进程方式运行)
3768
3774
  */
3769
3775
  async startMcpServerMode(options) {
3770
3776
  const port = options.port || 3e3;
3771
3777
  const { spawn: spawn2 } = await import("child_process");
3772
- if (options.daemon) {
3773
- const scriptPath = PathUtils.getExecutablePath("cli");
3774
- const child = spawn2(
3775
- "node",
3776
- [scriptPath, "start", "--server", port.toString()],
3777
- {
3778
- detached: true,
3779
- stdio: ["ignore", "ignore", "ignore"],
3780
- // 完全忽略所有 stdio,避免阻塞
3781
- env: {
3782
- ...process.env,
3783
- XIAOZHI_CONFIG_DIR: PathUtils.getConfigDir(),
3784
- XIAOZHI_DAEMON: "true",
3785
- MCP_SERVER_MODE: "true"
3786
- }
3778
+ const scriptPath = PathUtils.getExecutablePath("cli");
3779
+ const child = spawn2(
3780
+ "node",
3781
+ [scriptPath, "start", "--server", port.toString()],
3782
+ {
3783
+ detached: true,
3784
+ stdio: ["ignore", "ignore", "ignore"],
3785
+ // 完全忽略所有 stdio,避免阻塞
3786
+ env: {
3787
+ ...process.env,
3788
+ XIAOZHI_CONFIG_DIR: PathUtils.getConfigDir(),
3789
+ XIAOZHI_DAEMON: "true",
3790
+ MCP_SERVER_MODE: "true"
3787
3791
  }
3788
- );
3789
- this.processManager.savePidInfo(child.pid || 0, "daemon");
3790
- child.unref();
3791
- consola2.success(
3792
- `MCP Server \u5DF2\u5728\u540E\u53F0\u542F\u52A8 (PID: ${child.pid}, Port: ${port})`
3793
- );
3794
- consola2.info("\u4F7F\u7528 'xiaozhi status' \u67E5\u770B\u72B6\u6001");
3795
- process.exit(0);
3796
- } else {
3797
- const { WebServer } = await import("../backend/WebServer.js");
3798
- const server = new WebServer(port);
3799
- const cleanup = /* @__PURE__ */ __name(async () => {
3800
- await server.stop();
3801
- process.exit(0);
3802
- }, "cleanup");
3803
- process.once("SIGINT", cleanup);
3804
- process.once("SIGTERM", cleanup);
3805
- await server.start();
3806
- }
3792
+ }
3793
+ );
3794
+ this.processManager.savePidInfo(child.pid || 0, "daemon");
3795
+ child.unref();
3796
+ consola2.success(
3797
+ `MCP Server \u5DF2\u5728\u540E\u53F0\u542F\u52A8 (PID: ${child.pid}, Port: ${port})`
3798
+ );
3799
+ consola2.info("\u4F7F\u7528 'xiaozhi status' \u67E5\u770B\u72B6\u6001");
3800
+ process.exit(0);
3807
3801
  }
3808
3802
  /**
3809
3803
  * 后台模式启动 WebServer
@@ -3826,29 +3820,18 @@ var init_ServiceManager = __esm({
3826
3820
  XIAOZHI_DAEMON: "true"
3827
3821
  }
3828
3822
  });
3829
- this.processManager.savePidInfo(child.pid || 0, "daemon");
3823
+ if (!child.pid) {
3824
+ throw new ServiceError(
3825
+ "\u65E0\u6CD5\u521B\u5EFA\u5B88\u62A4\u8FDB\u7A0B\uFF08node \u542F\u52A8\u5931\u8D25\uFF09\uFF0C\u8BF7\u68C0\u67E5 Node.js \u5B89\u88C5\u662F\u5426\u6B63\u5E38"
3826
+ );
3827
+ }
3828
+ this.processManager.savePidInfo(child.pid, "daemon");
3830
3829
  child.unref();
3831
3830
  consola2.success(`\u540E\u53F0\u670D\u52A1\u5DF2\u542F\u52A8 (PID: ${child.pid})`);
3832
3831
  consola2.info("\u4F7F\u7528 'xiaozhi status' \u67E5\u770B\u72B6\u6001");
3833
3832
  consola2.info("\u4F7F\u7528 'xiaozhi attach' \u67E5\u770B\u65E5\u5FD7");
3834
3833
  process.exit(0);
3835
3834
  }
3836
- /**
3837
- * 前台模式启动 WebServer
3838
- */
3839
- async startWebServerInForeground() {
3840
- const { WebServer } = await import("../backend/WebServer.js");
3841
- const server = new WebServer();
3842
- const cleanup = /* @__PURE__ */ __name(async () => {
3843
- await server.stop();
3844
- this.processManager.cleanupPidFile();
3845
- process.exit(0);
3846
- }, "cleanup");
3847
- process.once("SIGINT", cleanup);
3848
- process.once("SIGTERM", cleanup);
3849
- this.processManager.savePidInfo(process.pid, "foreground");
3850
- await server.start();
3851
- }
3852
3835
  };
3853
3836
  }
3854
3837
  });
@@ -5630,7 +5613,7 @@ init_config();
5630
5613
  import fs from "fs";
5631
5614
  import path3 from "path";
5632
5615
  import { fileURLToPath as fileURLToPath3 } from "url";
5633
- var VERSION = "2.3.0";
5616
+ var VERSION = "2.3.1-beta.1";
5634
5617
  var APP_NAME = "xiaozhi-client";
5635
5618
  var VersionUtils = class _VersionUtils {
5636
5619
  static {