@elizaos/server 1.0.13 → 1.0.14

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.d.ts CHANGED
@@ -150,6 +150,14 @@ declare class AgentServer {
150
150
  * @constructor
151
151
  */
152
152
  constructor();
153
+ /**
154
+ * Dynamically resolves the client path based on the installation context.
155
+ * Handles both development and production scenarios.
156
+ *
157
+ * @returns {string} The resolved path to the client dist directory
158
+ * @throws {Error} If no valid client path can be found
159
+ */
160
+ private resolveClientPath;
153
161
  /**
154
162
  * Initializes the database and server.
155
163
  *
package/dist/index.js CHANGED
@@ -4,7 +4,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __commonJS = (cb, mod) => function __require() {
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined") return require.apply(this, arguments);
11
+ throw Error('Dynamic require of "' + x + '" is not supported');
12
+ });
13
+ var __commonJS = (cb, mod) => function __require2() {
8
14
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
15
  };
10
16
  var __copyProps = (to, from, except, desc) => {
@@ -5465,6 +5471,46 @@ var AgentServer = class {
5465
5471
  throw error;
5466
5472
  }
5467
5473
  }
5474
+ /**
5475
+ * Dynamically resolves the client path based on the installation context.
5476
+ * Handles both development and production scenarios.
5477
+ *
5478
+ * @returns {string} The resolved path to the client dist directory
5479
+ * @throws {Error} If no valid client path can be found
5480
+ */
5481
+ resolveClientPath() {
5482
+ try {
5483
+ const cliPackageJson = __require.resolve("@elizaos/cli/package.json");
5484
+ const cliDir = path9.dirname(cliPackageJson);
5485
+ const cliDistPath = path9.join(cliDir, "dist");
5486
+ if (fs9.existsSync(path9.join(cliDistPath, "index.html"))) {
5487
+ logger29.debug(`[CLIENT PATH] Resolved client path from npm package: ${cliDistPath}`);
5488
+ return cliDistPath;
5489
+ }
5490
+ } catch (e) {
5491
+ logger29.debug("[CLIENT PATH] Could not resolve @elizaos/cli package, trying other methods");
5492
+ }
5493
+ const relativePath = path9.resolve(__dirname2, "../../cli/dist");
5494
+ if (fs9.existsSync(path9.join(relativePath, "index.html"))) {
5495
+ logger29.debug(`[CLIENT PATH] Resolved client path from relative path: ${relativePath}`);
5496
+ return relativePath;
5497
+ }
5498
+ const cwdPath = path9.join(process.cwd(), "dist");
5499
+ if (fs9.existsSync(path9.join(cwdPath, "index.html"))) {
5500
+ logger29.debug(`[CLIENT PATH] Resolved client path from current directory: ${cwdPath}`);
5501
+ return cwdPath;
5502
+ }
5503
+ if (process.env.ELIZA_CLIENT_PATH) {
5504
+ const envPath = path9.resolve(process.env.ELIZA_CLIENT_PATH);
5505
+ if (fs9.existsSync(path9.join(envPath, "index.html"))) {
5506
+ logger29.debug(`[CLIENT PATH] Resolved client path from environment variable: ${envPath}`);
5507
+ return envPath;
5508
+ }
5509
+ }
5510
+ throw new Error(
5511
+ "Unable to locate client files. Please ensure @elizaos/cli is properly installed."
5512
+ );
5513
+ }
5468
5514
  /**
5469
5515
  * Initializes the database and server.
5470
5516
  *
@@ -5808,8 +5854,14 @@ var AgentServer = class {
5808
5854
  }
5809
5855
  }
5810
5856
  };
5811
- const clientPath = path9.resolve(__dirname2, "../../cli/dist");
5812
- this.app.use(express30.static(clientPath, staticOptions));
5857
+ try {
5858
+ const clientPath = this.resolveClientPath();
5859
+ this.app.use(express30.static(clientPath, staticOptions));
5860
+ logger29.info(`[STATIC] Serving client files from: ${clientPath}`);
5861
+ } catch (error) {
5862
+ logger29.error("[STATIC] Failed to resolve client path:", error);
5863
+ logger29.warn("[STATIC] Client UI will not be available. API endpoints will still work.");
5864
+ }
5813
5865
  const pluginRouteHandler = createPluginRouteHandler(this.agents);
5814
5866
  this.app.use(pluginRouteHandler);
5815
5867
  const apiRouter = createApiRouter(this.agents, this);
@@ -5851,8 +5903,30 @@ var AgentServer = class {
5851
5903
  res.setHeader("Content-Type", "application/javascript");
5852
5904
  return res.status(404).send(`// JavaScript module not found: ${req.path}`);
5853
5905
  }
5854
- const cliDistPath = path9.resolve(__dirname2, "../../cli/dist");
5855
- res.sendFile(path9.join(cliDistPath, "index.html"));
5906
+ try {
5907
+ const cliDistPath = this.resolveClientPath();
5908
+ res.sendFile(path9.join(cliDistPath, "index.html"), (err) => {
5909
+ if (err && !res.headersSent) {
5910
+ logger29.error("[STATIC] Failed to serve index.html:", err);
5911
+ res.status(404).json({
5912
+ success: false,
5913
+ error: {
5914
+ message: "Client UI not available. Please ensure @elizaos/cli is properly installed.",
5915
+ code: 404
5916
+ }
5917
+ });
5918
+ }
5919
+ });
5920
+ } catch (error) {
5921
+ logger29.error("[STATIC] Failed to resolve client path for fallback route:", error);
5922
+ res.status(404).json({
5923
+ success: false,
5924
+ error: {
5925
+ message: "Client UI not available. API endpoints are still accessible at /api/*",
5926
+ code: 404
5927
+ }
5928
+ });
5929
+ }
5856
5930
  });
5857
5931
  this.server = http.createServer(this.app);
5858
5932
  this.socketIO = setupSocketIO(this.server, this.agents, this);