@elizaos/server 1.0.14 → 1.0.16

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
@@ -128,6 +128,12 @@ interface ServerOptions {
128
128
  dataDir?: string;
129
129
  postgresUrl?: string;
130
130
  }
131
+ /**
132
+ * Determines if the web UI should be enabled based on environment variables.
133
+ *
134
+ * @returns {boolean} - Returns true if UI should be enabled, false otherwise
135
+ */
136
+ declare function isWebUIEnabled(): boolean;
131
137
  /**
132
138
  * Class representing an agent server.
133
139
  */ /**
@@ -139,6 +145,7 @@ declare class AgentServer {
139
145
  server: http.Server;
140
146
  socketIO: Server;
141
147
  isInitialized: boolean;
148
+ private isWebUIEnabled;
142
149
  database: DatabaseAdapter;
143
150
  startAgent: (character: Character) => Promise<IAgentRuntime>;
144
151
  stopAgent: (runtime: IAgentRuntime) => void;
@@ -150,14 +157,6 @@ declare class AgentServer {
150
157
  * @constructor
151
158
  */
152
159
  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;
161
160
  /**
162
161
  * Initializes the database and server.
163
162
  *
@@ -254,4 +253,4 @@ declare class AgentServer {
254
253
  getServersForAgent(agentId: UUID): Promise<UUID[]>;
255
254
  }
256
255
 
257
- export { AgentServer, type CentralRootMessage, type MessageChannel, type MessageServer, type MessageServiceStructure, type ServerMiddleware, type ServerOptions, expandTildePath, hasValidRemoteUrls, jsonToCharacter, loadCharacter, loadCharacterTryPath, loadCharacters, loadCharactersFromUrl, resolvePgliteDir, tryLoadFile };
256
+ export { AgentServer, type CentralRootMessage, type MessageChannel, type MessageServer, type MessageServiceStructure, type ServerMiddleware, type ServerOptions, expandTildePath, hasValidRemoteUrls, isWebUIEnabled, jsonToCharacter, loadCharacter, loadCharacterTryPath, loadCharacters, loadCharactersFromUrl, resolvePgliteDir, tryLoadFile };
package/dist/index.js CHANGED
@@ -4,13 +4,7 @@ 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 __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() {
7
+ var __commonJS = (cb, mod) => function __require() {
14
8
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15
9
  };
16
10
  var __copyProps = (to, from, except, desc) => {
@@ -385,9 +379,10 @@ var require_lib = __commonJS({
385
379
  // src/index.ts
386
380
  var import_cors2 = __toESM(require_lib(), 1);
387
381
  import {
388
- logger as logger29
382
+ logger as logger29,
383
+ parseBooleanFromText
389
384
  } from "@elizaos/core";
390
- import express30 from "express";
385
+ import express31 from "express";
391
386
  import helmet2 from "helmet";
392
387
  import * as fs9 from "fs";
393
388
  import http from "http";
@@ -398,7 +393,7 @@ import { fileURLToPath as fileURLToPath2 } from "url";
398
393
  var import_cors = __toESM(require_lib(), 1);
399
394
  import { logger as logger25, validateUuid as validateUuid21 } from "@elizaos/core";
400
395
  import bodyParser from "body-parser";
401
- import express29 from "express";
396
+ import express30 from "express";
402
397
  import helmet from "helmet";
403
398
  import { match } from "path-to-regexp";
404
399
  import { Server as SocketIOServer } from "socket.io";
@@ -3701,7 +3696,7 @@ function teeRouter() {
3701
3696
  }
3702
3697
 
3703
3698
  // src/api/system/index.ts
3704
- import express28 from "express";
3699
+ import express29 from "express";
3705
3700
 
3706
3701
  // src/api/system/environment.ts
3707
3702
  import { logger as logger23 } from "@elizaos/core";
@@ -3810,10 +3805,118 @@ function createEnvironmentRouter() {
3810
3805
  return router;
3811
3806
  }
3812
3807
 
3808
+ // src/api/system/version.ts
3809
+ import express28 from "express";
3810
+
3811
+ // package.json
3812
+ var package_default = {
3813
+ name: "@elizaos/server",
3814
+ version: "1.0.15",
3815
+ description: "ElizaOS Server - Core server infrastructure for ElizaOS agents",
3816
+ publishConfig: {
3817
+ access: "public",
3818
+ workspaces: {
3819
+ preserveIfPresent: true
3820
+ }
3821
+ },
3822
+ license: "MIT",
3823
+ author: {
3824
+ name: "elizaOS",
3825
+ url: "https://twitter.com/eliza_OS"
3826
+ },
3827
+ repository: {
3828
+ type: "git",
3829
+ url: "https://github.com/elizaOS/eliza.git",
3830
+ directory: "packages/server"
3831
+ },
3832
+ files: [
3833
+ "dist",
3834
+ "templates"
3835
+ ],
3836
+ keywords: [],
3837
+ type: "module",
3838
+ exports: {
3839
+ ".": "./dist/index.js",
3840
+ "./package.json": "./package.json"
3841
+ },
3842
+ scripts: {
3843
+ build: "tsup",
3844
+ "type-check": "tsc --project tsconfig.build.json --noEmit",
3845
+ lint: "prettier --write ./src",
3846
+ format: "prettier --write ./src",
3847
+ "format:check": "prettier --check ./src",
3848
+ clean: "rm -rf dist .turbo node_modules .turbo-tsconfig.json tsconfig.tsbuildinfo",
3849
+ test: "bun test src/**/*.test.ts",
3850
+ "test:unit": "bun test src/**/*.test.ts --exclude **/integration/**",
3851
+ "test:integration": "bun test src/__tests__/integration/**/*.test.ts",
3852
+ "test:coverage": "bun test --coverage",
3853
+ "test:watch": "bun test --watch",
3854
+ "test:cli": "bun test tests/commands/"
3855
+ },
3856
+ devDependencies: {
3857
+ "@types/node": "^24.0.1",
3858
+ dotenv: "^16.5.0",
3859
+ prettier: "3.5.3",
3860
+ tsup: "8.5.0",
3861
+ tsx: "4.19.4",
3862
+ typescript: "^5.5.4",
3863
+ which: "^4.0.0",
3864
+ ws: "^8.18.0"
3865
+ },
3866
+ gitHead: "d5bd5c43bfebeb7ac02f9e029f924cb6cd5c2ec7",
3867
+ dependencies: {
3868
+ "@elizaos/core": "workspace:*",
3869
+ "@elizaos/plugin-sql": "workspace:*",
3870
+ "@types/express": "^5.0.2",
3871
+ "@types/helmet": "^4.0.0",
3872
+ "@types/multer": "^1.4.13",
3873
+ express: "^5.1.0",
3874
+ "express-rate-limit": "^7.5.0",
3875
+ helmet: "^8.1.0",
3876
+ multer: "^2.0.1",
3877
+ "path-to-regexp": "^8.2.0",
3878
+ "socket.io": "^4.8.1"
3879
+ }
3880
+ };
3881
+
3882
+ // src/api/system/version.ts
3883
+ function getVersionInfo() {
3884
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
3885
+ try {
3886
+ return {
3887
+ version: package_default.version,
3888
+ source: "server",
3889
+ timestamp,
3890
+ environment: process.env.NODE_ENV || "development",
3891
+ uptime: process.uptime()
3892
+ };
3893
+ } catch (error) {
3894
+ console.error("Error getting version info:", error);
3895
+ return {
3896
+ version: "unknown",
3897
+ source: "server",
3898
+ timestamp,
3899
+ environment: process.env.NODE_ENV || "development",
3900
+ uptime: process.uptime(),
3901
+ error: "Failed to retrieve version information"
3902
+ };
3903
+ }
3904
+ }
3905
+ function createVersionRouter() {
3906
+ const router = express28.Router();
3907
+ router.get("/", (_, res) => {
3908
+ const versionInfo = getVersionInfo();
3909
+ const statusCode = versionInfo.error ? 500 : 200;
3910
+ res.status(statusCode).json(versionInfo);
3911
+ });
3912
+ return router;
3913
+ }
3914
+
3813
3915
  // src/api/system/index.ts
3814
3916
  function systemRouter() {
3815
- const router = express28.Router();
3917
+ const router = express29.Router();
3816
3918
  router.use("/env", createEnvironmentRouter());
3919
+ router.use("/version", createVersionRouter());
3817
3920
  return router;
3818
3921
  }
3819
3922
 
@@ -4472,7 +4575,7 @@ function createPluginRouteHandler(agents) {
4472
4575
  };
4473
4576
  }
4474
4577
  function createApiRouter(agents, serverInstance) {
4475
- const router = express29.Router();
4578
+ const router = express30.Router();
4476
4579
  router.use(
4477
4580
  helmet({
4478
4581
  // Disable CSP here - let main app handle it with environment awareness
@@ -4510,7 +4613,7 @@ function createApiRouter(agents, serverInstance) {
4510
4613
  })
4511
4614
  );
4512
4615
  router.use(
4513
- express29.json({
4616
+ express30.json({
4514
4617
  limit: process.env.EXPRESS_MAX_PAYLOAD || "100kb"
4515
4618
  })
4516
4619
  );
@@ -5443,6 +5546,14 @@ function resolvePgliteDir(dir, fallbackDir) {
5443
5546
  }
5444
5547
  var __dirname2 = dirname(fileURLToPath2(import.meta.url));
5445
5548
  var DEFAULT_SERVER_ID5 = "00000000-0000-0000-0000-000000000000";
5549
+ function isWebUIEnabled() {
5550
+ const isProduction = process.env.NODE_ENV === "production";
5551
+ const uiEnabledEnv = process.env.ELIZA_UI_ENABLE;
5552
+ if (uiEnabledEnv !== void 0 && uiEnabledEnv.trim() !== "") {
5553
+ return parseBooleanFromText(uiEnabledEnv);
5554
+ }
5555
+ return !isProduction;
5556
+ }
5446
5557
  var AgentServer = class {
5447
5558
  app;
5448
5559
  agents;
@@ -5450,6 +5561,8 @@ var AgentServer = class {
5450
5561
  socketIO;
5451
5562
  isInitialized = false;
5452
5563
  // Flag to prevent double initialization
5564
+ isWebUIEnabled = true;
5565
+ // Default to enabled until initialized
5453
5566
  database;
5454
5567
  startAgent;
5455
5568
  stopAgent;
@@ -5471,46 +5584,6 @@ var AgentServer = class {
5471
5584
  throw error;
5472
5585
  }
5473
5586
  }
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
- }
5514
5587
  /**
5515
5588
  * Initializes the database and server.
5516
5589
  *
@@ -5631,7 +5704,7 @@ var AgentServer = class {
5631
5704
  */
5632
5705
  async initializeServer(options) {
5633
5706
  try {
5634
- this.app = express30();
5707
+ this.app = express31();
5635
5708
  const isProd = process.env.NODE_ENV === "production";
5636
5709
  logger29.debug("Setting up security headers...");
5637
5710
  if (!isProd) {
@@ -5715,8 +5788,8 @@ var AgentServer = class {
5715
5788
  })
5716
5789
  );
5717
5790
  this.app.use(
5718
- express30.json({
5719
- limit: process.env.EXPRESS_MAX_PAYLOAD || "100kb"
5791
+ express31.json({
5792
+ limit: process.env.EXPRESS_MAX_PAYLOAD || "2mb"
5720
5793
  })
5721
5794
  );
5722
5795
  const serverAuthToken = process.env.ELIZA_SERVER_AUTH_TOKEN;
@@ -5730,6 +5803,17 @@ var AgentServer = class {
5730
5803
  "Server authentication is disabled. Set ELIZA_SERVER_AUTH_TOKEN environment variable to enable."
5731
5804
  );
5732
5805
  }
5806
+ this.isWebUIEnabled = isWebUIEnabled();
5807
+ if (this.isWebUIEnabled) {
5808
+ logger29.info("Web UI enabled");
5809
+ } else {
5810
+ const uiEnabledEnv = process.env.ELIZA_UI_ENABLE;
5811
+ if (uiEnabledEnv !== void 0 && uiEnabledEnv.trim() !== "") {
5812
+ logger29.info(`Web UI disabled by environment variable (ELIZA_UI_ENABLE=${uiEnabledEnv})`);
5813
+ } else {
5814
+ logger29.info("Web UI disabled for security (production mode)");
5815
+ }
5816
+ }
5733
5817
  const uploadsBasePath = path9.join(process.cwd(), ".eliza", "data", "uploads", "agents");
5734
5818
  const generatedBasePath = path9.join(process.cwd(), ".eliza", "data", "generated");
5735
5819
  fs9.mkdirSync(uploadsBasePath, { recursive: true });
@@ -5854,13 +5938,9 @@ var AgentServer = class {
5854
5938
  }
5855
5939
  }
5856
5940
  };
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.");
5941
+ if (this.isWebUIEnabled) {
5942
+ const clientPath = path9.resolve(__dirname2, "../../cli/dist");
5943
+ this.app.use(express31.static(clientPath, staticOptions));
5864
5944
  }
5865
5945
  const pluginRouteHandler = createPluginRouteHandler(this.agents);
5866
5946
  this.app.use(pluginRouteHandler);
@@ -5898,36 +5978,20 @@ var AgentServer = class {
5898
5978
  next();
5899
5979
  }
5900
5980
  });
5901
- this.app.use((req, res) => {
5902
- if (req.path.endsWith(".js") || req.path.includes(".js?") || req.path.match(/\/[a-zA-Z0-9_-]+-[A-Za-z0-9]{8}\.js/)) {
5903
- res.setHeader("Content-Type", "application/javascript");
5904
- return res.status(404).send(`// JavaScript module not found: ${req.path}`);
5905
- }
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
- }
5930
- });
5981
+ if (this.isWebUIEnabled) {
5982
+ this.app.use((req, res) => {
5983
+ if (req.path.endsWith(".js") || req.path.includes(".js?") || req.path.match(/\/[a-zA-Z0-9_-]+-[A-Za-z0-9]{8}\.js/)) {
5984
+ res.setHeader("Content-Type", "application/javascript");
5985
+ return res.status(404).send(`// JavaScript module not found: ${req.path}`);
5986
+ }
5987
+ const cliDistPath = path9.resolve(__dirname2, "../../cli/dist");
5988
+ res.sendFile(path9.join(cliDistPath, "index.html"));
5989
+ });
5990
+ } else {
5991
+ this.app.use((_req, res) => {
5992
+ res.sendStatus(403);
5993
+ });
5994
+ }
5931
5995
  this.server = http.createServer(this.app);
5932
5996
  this.socketIO = setupSocketIO(this.server, this.agents, this);
5933
5997
  logger29.success("AgentServer HTTP server and Socket.IO initialized");
@@ -6054,11 +6118,21 @@ var AgentServer = class {
6054
6118
  logger29.debug(`Environment: ${process.env.NODE_ENV}`);
6055
6119
  const host = process.env.SERVER_HOST || "0.0.0.0";
6056
6120
  this.server.listen(port, host, () => {
6057
- if (process.env.NODE_ENV !== "development") {
6121
+ if (this.isWebUIEnabled && process.env.NODE_ENV !== "development") {
6058
6122
  console.log(
6059
6123
  `\x1B[32mStartup successful!
6060
6124
  Go to the dashboard at \x1B[1mhttp://localhost:${port}\x1B[22m\x1B[0m`
6061
6125
  );
6126
+ } else if (!this.isWebUIEnabled) {
6127
+ const actualHost = host === "0.0.0.0" ? "localhost" : host;
6128
+ const baseUrl = `http://${actualHost}:${port}`;
6129
+ console.log(
6130
+ `\x1B[32mStartup successful!\x1B[0m
6131
+ \x1B[33mWeb UI disabled.\x1B[0m \x1B[32mAPI endpoints available at:\x1B[0m
6132
+ \x1B[1m${baseUrl}/api/server/ping\x1B[22m\x1B[0m
6133
+ \x1B[1m${baseUrl}/api/agents\x1B[22m\x1B[0m
6134
+ \x1B[1m${baseUrl}/api/messaging\x1B[22m\x1B[0m`
6135
+ );
6062
6136
  }
6063
6137
  console.log(`AgentServer is listening on port ${port}`);
6064
6138
  logger29.success(
@@ -6264,6 +6338,7 @@ export {
6264
6338
  AgentServer,
6265
6339
  expandTildePath,
6266
6340
  hasValidRemoteUrls,
6341
+ isWebUIEnabled,
6267
6342
  jsonToCharacter,
6268
6343
  loadCharacter,
6269
6344
  loadCharacterTryPath,