@elizaos/server 1.5.10 → 1.5.11-alpha.2
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/api/agents/crud.d.ts +2 -2
- package/dist/api/agents/index.d.ts +2 -2
- package/dist/api/agents/lifecycle.d.ts +2 -2
- package/dist/api/agents/logs.d.ts +2 -2
- package/dist/api/agents/panels.d.ts +2 -2
- package/dist/api/agents/runs.d.ts +2 -2
- package/dist/api/agents/worlds.d.ts +2 -2
- package/dist/api/audio/conversation.d.ts +2 -2
- package/dist/api/audio/index.d.ts +2 -2
- package/dist/api/audio/processing.d.ts +2 -2
- package/dist/api/audio/synthesis.d.ts +2 -2
- package/dist/api/index.d.ts +5 -5
- package/dist/api/memory/agents.d.ts +2 -2
- package/dist/api/memory/groups.d.ts +2 -2
- package/dist/api/memory/index.d.ts +2 -2
- package/dist/api/memory/rooms.d.ts +2 -2
- package/dist/api/messaging/channels.d.ts +2 -2
- package/dist/api/messaging/index.d.ts +2 -2
- package/dist/api/messaging/sessions.d.ts +2 -2
- package/dist/api/runtime/health.d.ts +2 -2
- package/dist/api/runtime/index.d.ts +2 -2
- package/dist/api/shared/middleware.d.ts +2 -2
- package/dist/api/shared/validation.d.ts +2 -2
- package/dist/characters/default.d.ts +14 -0
- package/dist/client/assets/{main-Dbnvjs-Q.js → main-BT6UkYWg.js} +20 -20
- package/dist/client/assets/{main-Dbnvjs-Q.js.map → main-BT6UkYWg.js.map} +1 -1
- package/dist/client/assets/{main-Cxu5WF7C.js → main-CYEf9_sq.js} +3 -3
- package/dist/client/assets/{main-Cxu5WF7C.js.map → main-CYEf9_sq.js.map} +1 -1
- package/dist/client/index.html +1 -1
- package/dist/index.d.ts +34 -5
- package/dist/index.js +578 -263
- package/dist/managers/ConfigManager.d.ts +32 -0
- package/dist/managers/PluginLoader.d.ts +27 -0
- package/dist/socketio/index.d.ts +3 -4
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -21934,11 +21934,12 @@ var require_src32 = __commonJS((exports) => {
|
|
|
21934
21934
|
|
|
21935
21935
|
// src/index.ts
|
|
21936
21936
|
import {
|
|
21937
|
-
logger as
|
|
21937
|
+
logger as logger31,
|
|
21938
21938
|
parseBooleanFromText,
|
|
21939
21939
|
getDatabaseDir,
|
|
21940
21940
|
getGeneratedDir as getGeneratedDir2,
|
|
21941
|
-
getUploadsAgentsDir as getUploadsAgentsDir4
|
|
21941
|
+
getUploadsAgentsDir as getUploadsAgentsDir4,
|
|
21942
|
+
ElizaOS as ElizaOS2
|
|
21942
21943
|
} from "@elizaos/core";
|
|
21943
21944
|
import cors2 from "cors";
|
|
21944
21945
|
import express33 from "express";
|
|
@@ -22483,10 +22484,10 @@ var helmet = Object.assign(function helmet2(options = {}) {
|
|
|
22483
22484
|
});
|
|
22484
22485
|
|
|
22485
22486
|
// src/index.ts
|
|
22486
|
-
import * as
|
|
22487
|
+
import * as fs7 from "node:fs";
|
|
22487
22488
|
import http4 from "node:http";
|
|
22488
22489
|
import os3 from "node:os";
|
|
22489
|
-
import
|
|
22490
|
+
import path9, { basename as basename2, dirname as dirname3, extname, join as join5 } from "node:path";
|
|
22490
22491
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
22491
22492
|
|
|
22492
22493
|
// src/api/index.ts
|
|
@@ -22529,7 +22530,7 @@ var sendSuccess = (res, data, status = 200) => {
|
|
|
22529
22530
|
};
|
|
22530
22531
|
|
|
22531
22532
|
// src/api/agents/crud.ts
|
|
22532
|
-
function createAgentCrudRouter(
|
|
22533
|
+
function createAgentCrudRouter(elizaOS, serverInstance) {
|
|
22533
22534
|
const router = express.Router();
|
|
22534
22535
|
const db = serverInstance?.database;
|
|
22535
22536
|
router.get("/", async (_, res) => {
|
|
@@ -22538,7 +22539,7 @@ function createAgentCrudRouter(agents, serverInstance) {
|
|
|
22538
22539
|
return sendError(res, 500, "DB_ERROR", "Database not available");
|
|
22539
22540
|
}
|
|
22540
22541
|
const allAgents = await db.getAgents();
|
|
22541
|
-
const runtimes =
|
|
22542
|
+
const runtimes = elizaOS.getAgents().map((a) => a.agentId);
|
|
22542
22543
|
const response = allAgents.map((agent) => ({
|
|
22543
22544
|
id: agent.id,
|
|
22544
22545
|
name: agent.name || "",
|
|
@@ -22570,7 +22571,7 @@ function createAgentCrudRouter(agents, serverInstance) {
|
|
|
22570
22571
|
if (!agent) {
|
|
22571
22572
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
22572
22573
|
}
|
|
22573
|
-
const runtime =
|
|
22574
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
22574
22575
|
const response = {
|
|
22575
22576
|
...agent,
|
|
22576
22577
|
status: runtime ? "active" : "inactive"
|
|
@@ -22670,12 +22671,13 @@ function createAgentCrudRouter(agents, serverInstance) {
|
|
|
22670
22671
|
await db.updateAgent(agentId, updates);
|
|
22671
22672
|
}
|
|
22672
22673
|
const updatedAgent = await db.getAgent(agentId);
|
|
22673
|
-
const
|
|
22674
|
-
if (
|
|
22675
|
-
|
|
22676
|
-
await
|
|
22674
|
+
const activeRuntime = elizaOS.getAgent(agentId);
|
|
22675
|
+
if (activeRuntime && updatedAgent) {
|
|
22676
|
+
const { enabled, status: status2, createdAt, updatedAt, ...characterData } = updatedAgent;
|
|
22677
|
+
await elizaOS.updateAgent(agentId, characterData);
|
|
22678
|
+
logger.debug(`[AGENT UPDATE] Updated active agent ${agentId} without restart`);
|
|
22677
22679
|
}
|
|
22678
|
-
const runtime =
|
|
22680
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
22679
22681
|
const status = runtime ? "active" : "inactive";
|
|
22680
22682
|
sendSuccess(res, { ...updatedAgent, status });
|
|
22681
22683
|
} catch (error) {
|
|
@@ -22719,11 +22721,11 @@ function createAgentCrudRouter(agents, serverInstance) {
|
|
|
22719
22721
|
let lastError = null;
|
|
22720
22722
|
while (retryCount <= MAX_RETRIES) {
|
|
22721
22723
|
try {
|
|
22722
|
-
const runtime =
|
|
22724
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
22723
22725
|
if (runtime) {
|
|
22724
22726
|
logger.debug(`[AGENT DELETE] Agent ${agentId} is running, unregistering from server`);
|
|
22725
22727
|
try {
|
|
22726
|
-
serverInstance?.unregisterAgent(agentId);
|
|
22728
|
+
await serverInstance?.unregisterAgent(agentId);
|
|
22727
22729
|
logger.debug(`[AGENT DELETE] Agent ${agentId} unregistered successfully`);
|
|
22728
22730
|
} catch (stopError) {
|
|
22729
22731
|
logger.error(`[AGENT DELETE] Error stopping agent ${agentId}:`, stopError instanceof Error ? stopError.message : String(stopError));
|
|
@@ -22782,7 +22784,7 @@ function createAgentCrudRouter(agents, serverInstance) {
|
|
|
22782
22784
|
// src/api/agents/lifecycle.ts
|
|
22783
22785
|
import { validateUuid as validateUuid2, logger as logger2 } from "@elizaos/core";
|
|
22784
22786
|
import express2 from "express";
|
|
22785
|
-
function createAgentLifecycleRouter(
|
|
22787
|
+
function createAgentLifecycleRouter(elizaOS, serverInstance) {
|
|
22786
22788
|
const router = express2.Router();
|
|
22787
22789
|
const db = serverInstance?.database;
|
|
22788
22790
|
router.post("/:agentId/start", async (req, res) => {
|
|
@@ -22799,7 +22801,7 @@ function createAgentLifecycleRouter(agents, serverInstance) {
|
|
|
22799
22801
|
logger2.debug("[AGENT START] Agent not found");
|
|
22800
22802
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
22801
22803
|
}
|
|
22802
|
-
const isActive = !!
|
|
22804
|
+
const isActive = !!elizaOS.getAgent(agentId);
|
|
22803
22805
|
if (isActive) {
|
|
22804
22806
|
logger2.debug(`[AGENT START] Agent ${agentId} is already running`);
|
|
22805
22807
|
return sendSuccess(res, {
|
|
@@ -22808,8 +22810,8 @@ function createAgentLifecycleRouter(agents, serverInstance) {
|
|
|
22808
22810
|
status: "active"
|
|
22809
22811
|
});
|
|
22810
22812
|
}
|
|
22811
|
-
await serverInstance?.
|
|
22812
|
-
const runtime =
|
|
22813
|
+
await serverInstance?.startAgents([agent]);
|
|
22814
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
22813
22815
|
if (!runtime) {
|
|
22814
22816
|
throw new Error("Failed to start agent");
|
|
22815
22817
|
}
|
|
@@ -22830,11 +22832,11 @@ function createAgentLifecycleRouter(agents, serverInstance) {
|
|
|
22830
22832
|
logger2.debug("[AGENT STOP] Invalid agent ID format");
|
|
22831
22833
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
22832
22834
|
}
|
|
22833
|
-
const runtime =
|
|
22835
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
22834
22836
|
if (!runtime) {
|
|
22835
22837
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
22836
22838
|
}
|
|
22837
|
-
serverInstance?.unregisterAgent(agentId);
|
|
22839
|
+
await serverInstance?.unregisterAgent(agentId);
|
|
22838
22840
|
logger2.debug(`[AGENT STOP] Successfully stopped agent: ${runtime.character.name} (${agentId})`);
|
|
22839
22841
|
sendSuccess(res, {
|
|
22840
22842
|
message: "Agent stopped"
|
|
@@ -22846,11 +22848,11 @@ function createAgentLifecycleRouter(agents, serverInstance) {
|
|
|
22846
22848
|
// src/api/agents/worlds.ts
|
|
22847
22849
|
import { validateUuid as validateUuid3, logger as logger3, createUniqueUuid } from "@elizaos/core";
|
|
22848
22850
|
import express3 from "express";
|
|
22849
|
-
function createAgentWorldsRouter(
|
|
22851
|
+
function createAgentWorldsRouter(elizaOS) {
|
|
22850
22852
|
const router = express3.Router();
|
|
22851
22853
|
router.get("/worlds", async (_req, res) => {
|
|
22852
22854
|
try {
|
|
22853
|
-
const runtime =
|
|
22855
|
+
const runtime = elizaOS.getAgents()[0];
|
|
22854
22856
|
if (!runtime) {
|
|
22855
22857
|
return sendError(res, 404, "NOT_FOUND", "No active agents found to get worlds");
|
|
22856
22858
|
}
|
|
@@ -22887,7 +22889,7 @@ function createAgentWorldsRouter(agents) {
|
|
|
22887
22889
|
if (!agentId) {
|
|
22888
22890
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
22889
22891
|
}
|
|
22890
|
-
const runtime =
|
|
22892
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
22891
22893
|
if (!runtime) {
|
|
22892
22894
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
22893
22895
|
}
|
|
@@ -22899,7 +22901,7 @@ function createAgentWorldsRouter(agents) {
|
|
|
22899
22901
|
if (!agentId || !worldId) {
|
|
22900
22902
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID or world ID format");
|
|
22901
22903
|
}
|
|
22902
|
-
const runtime =
|
|
22904
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
22903
22905
|
if (!runtime) {
|
|
22904
22906
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
22905
22907
|
}
|
|
@@ -22928,14 +22930,14 @@ function createAgentWorldsRouter(agents) {
|
|
|
22928
22930
|
// src/api/agents/panels.ts
|
|
22929
22931
|
import { validateUuid as validateUuid4, logger as logger4 } from "@elizaos/core";
|
|
22930
22932
|
import express4 from "express";
|
|
22931
|
-
function createAgentPanelsRouter(
|
|
22933
|
+
function createAgentPanelsRouter(elizaOS) {
|
|
22932
22934
|
const router = express4.Router();
|
|
22933
22935
|
router.get("/:agentId/panels", async (req, res) => {
|
|
22934
22936
|
const agentId = validateUuid4(req.params.agentId);
|
|
22935
22937
|
if (!agentId) {
|
|
22936
22938
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
22937
22939
|
}
|
|
22938
|
-
const runtime =
|
|
22940
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
22939
22941
|
if (!runtime) {
|
|
22940
22942
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
22941
22943
|
}
|
|
@@ -22956,7 +22958,7 @@ function createAgentPanelsRouter(agents) {
|
|
|
22956
22958
|
// src/api/agents/logs.ts
|
|
22957
22959
|
import { validateUuid as validateUuid5, logger as logger5 } from "@elizaos/core";
|
|
22958
22960
|
import express5 from "express";
|
|
22959
|
-
function createAgentLogsRouter(
|
|
22961
|
+
function createAgentLogsRouter(elizaOS) {
|
|
22960
22962
|
const router = express5.Router();
|
|
22961
22963
|
router.get("/:agentId/logs", async (req, res) => {
|
|
22962
22964
|
const agentId = validateUuid5(req.params.agentId);
|
|
@@ -22964,7 +22966,7 @@ function createAgentLogsRouter(agents) {
|
|
|
22964
22966
|
if (!agentId) {
|
|
22965
22967
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
22966
22968
|
}
|
|
22967
|
-
const runtime =
|
|
22969
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
22968
22970
|
if (!runtime) {
|
|
22969
22971
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
22970
22972
|
}
|
|
@@ -23010,7 +23012,7 @@ function createAgentLogsRouter(agents) {
|
|
|
23010
23012
|
if (!agentId || !logId) {
|
|
23011
23013
|
return sendError(res, 400, "INVALID_ID", "Invalid agent or log ID format");
|
|
23012
23014
|
}
|
|
23013
|
-
const runtime =
|
|
23015
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
23014
23016
|
if (!runtime) {
|
|
23015
23017
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
23016
23018
|
}
|
|
@@ -23028,14 +23030,14 @@ function createAgentLogsRouter(agents) {
|
|
|
23028
23030
|
// src/api/agents/runs.ts
|
|
23029
23031
|
import { validateUuid as validateUuid6 } from "@elizaos/core";
|
|
23030
23032
|
import express6 from "express";
|
|
23031
|
-
function createAgentRunsRouter(
|
|
23033
|
+
function createAgentRunsRouter(elizaOS) {
|
|
23032
23034
|
const router = express6.Router();
|
|
23033
23035
|
router.get("/:agentId/runs", async (req, res) => {
|
|
23034
23036
|
const agentId = validateUuid6(req.params.agentId);
|
|
23035
23037
|
if (!agentId) {
|
|
23036
23038
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
23037
23039
|
}
|
|
23038
|
-
const runtime =
|
|
23040
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
23039
23041
|
if (!runtime) {
|
|
23040
23042
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
23041
23043
|
}
|
|
@@ -23184,7 +23186,7 @@ function createAgentRunsRouter(agents) {
|
|
|
23184
23186
|
if (roomId && !validateUuid6(roomId)) {
|
|
23185
23187
|
return sendError(res, 400, "INVALID_ID", "Invalid room ID format");
|
|
23186
23188
|
}
|
|
23187
|
-
const runtime =
|
|
23189
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
23188
23190
|
if (!runtime) {
|
|
23189
23191
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
23190
23192
|
}
|
|
@@ -23320,7 +23322,7 @@ function createAgentRunsRouter(agents) {
|
|
|
23320
23322
|
import { MemoryType, createUniqueUuid as createUniqueUuid2 } from "@elizaos/core";
|
|
23321
23323
|
import { validateUuid as validateUuid7, logger as logger6 } from "@elizaos/core";
|
|
23322
23324
|
import express7 from "express";
|
|
23323
|
-
function createAgentMemoryRouter(
|
|
23325
|
+
function createAgentMemoryRouter(elizaOS) {
|
|
23324
23326
|
const router = express7.Router();
|
|
23325
23327
|
router.get("/:agentId/rooms/:roomId/memories", async (req, res) => {
|
|
23326
23328
|
const agentId = validateUuid7(req.params.agentId);
|
|
@@ -23328,7 +23330,7 @@ function createAgentMemoryRouter(agents) {
|
|
|
23328
23330
|
if (!agentId || !roomId) {
|
|
23329
23331
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID or room ID format");
|
|
23330
23332
|
}
|
|
23331
|
-
const runtime =
|
|
23333
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
23332
23334
|
if (!runtime) {
|
|
23333
23335
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
23334
23336
|
}
|
|
@@ -23358,7 +23360,7 @@ function createAgentMemoryRouter(agents) {
|
|
|
23358
23360
|
if (!agentId) {
|
|
23359
23361
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID");
|
|
23360
23362
|
}
|
|
23361
|
-
const runtime =
|
|
23363
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
23362
23364
|
if (!runtime) {
|
|
23363
23365
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
23364
23366
|
}
|
|
@@ -23402,7 +23404,7 @@ function createAgentMemoryRouter(agents) {
|
|
|
23402
23404
|
if (!agentId || !memoryId) {
|
|
23403
23405
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID or memory ID format");
|
|
23404
23406
|
}
|
|
23405
|
-
const runtime =
|
|
23407
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
23406
23408
|
if (!runtime) {
|
|
23407
23409
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
23408
23410
|
}
|
|
@@ -23435,7 +23437,7 @@ function createAgentMemoryRouter(agents) {
|
|
|
23435
23437
|
if (!agentId) {
|
|
23436
23438
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID");
|
|
23437
23439
|
}
|
|
23438
|
-
const runtime =
|
|
23440
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
23439
23441
|
if (!runtime) {
|
|
23440
23442
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
23441
23443
|
}
|
|
@@ -23457,7 +23459,7 @@ function createAgentMemoryRouter(agents) {
|
|
|
23457
23459
|
if (!roomId) {
|
|
23458
23460
|
return sendError(res, 400, "INVALID_ID", "Invalid room ID");
|
|
23459
23461
|
}
|
|
23460
|
-
const runtime =
|
|
23462
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
23461
23463
|
if (!runtime) {
|
|
23462
23464
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
23463
23465
|
}
|
|
@@ -23476,7 +23478,7 @@ function createAgentMemoryRouter(agents) {
|
|
|
23476
23478
|
if (!agentId || !memoryId) {
|
|
23477
23479
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID or memory ID format");
|
|
23478
23480
|
}
|
|
23479
|
-
const runtime =
|
|
23481
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
23480
23482
|
if (!runtime) {
|
|
23481
23483
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
23482
23484
|
}
|
|
@@ -23493,14 +23495,14 @@ function createAgentMemoryRouter(agents) {
|
|
|
23493
23495
|
// src/api/memory/rooms.ts
|
|
23494
23496
|
import { validateUuid as validateUuid8, logger as logger7, createUniqueUuid as createUniqueUuid3, ChannelType } from "@elizaos/core";
|
|
23495
23497
|
import express8 from "express";
|
|
23496
|
-
function createRoomManagementRouter(
|
|
23498
|
+
function createRoomManagementRouter(elizaOS) {
|
|
23497
23499
|
const router = express8.Router();
|
|
23498
23500
|
router.post("/:agentId/rooms", async (req, res) => {
|
|
23499
23501
|
const agentId = validateUuid8(req.params.agentId);
|
|
23500
23502
|
if (!agentId) {
|
|
23501
23503
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
23502
23504
|
}
|
|
23503
|
-
const runtime =
|
|
23505
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
23504
23506
|
if (!runtime) {
|
|
23505
23507
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
23506
23508
|
}
|
|
@@ -23557,7 +23559,7 @@ function createRoomManagementRouter(agents) {
|
|
|
23557
23559
|
if (!agentId) {
|
|
23558
23560
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
23559
23561
|
}
|
|
23560
|
-
const runtime =
|
|
23562
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
23561
23563
|
if (!runtime) {
|
|
23562
23564
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
23563
23565
|
}
|
|
@@ -23587,7 +23589,7 @@ function createRoomManagementRouter(agents) {
|
|
|
23587
23589
|
if (!agentId || !roomId) {
|
|
23588
23590
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID or room ID format");
|
|
23589
23591
|
}
|
|
23590
|
-
const runtime =
|
|
23592
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
23591
23593
|
if (!runtime) {
|
|
23592
23594
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
23593
23595
|
}
|
|
@@ -23614,16 +23616,16 @@ function createRoomManagementRouter(agents) {
|
|
|
23614
23616
|
}
|
|
23615
23617
|
|
|
23616
23618
|
// src/api/agents/index.ts
|
|
23617
|
-
function agentsRouter(
|
|
23619
|
+
function agentsRouter(elizaOS, serverInstance) {
|
|
23618
23620
|
const router = express9.Router();
|
|
23619
|
-
router.use("/", createAgentCrudRouter(
|
|
23620
|
-
router.use("/", createAgentLifecycleRouter(
|
|
23621
|
-
router.use("/", createAgentWorldsRouter(
|
|
23622
|
-
router.use("/", createAgentPanelsRouter(
|
|
23623
|
-
router.use("/", createAgentLogsRouter(
|
|
23624
|
-
router.use("/", createAgentRunsRouter(
|
|
23625
|
-
router.use("/", createAgentMemoryRouter(
|
|
23626
|
-
router.use("/", createRoomManagementRouter(
|
|
23621
|
+
router.use("/", createAgentCrudRouter(elizaOS, serverInstance));
|
|
23622
|
+
router.use("/", createAgentLifecycleRouter(elizaOS, serverInstance));
|
|
23623
|
+
router.use("/", createAgentWorldsRouter(elizaOS));
|
|
23624
|
+
router.use("/", createAgentPanelsRouter(elizaOS));
|
|
23625
|
+
router.use("/", createAgentLogsRouter(elizaOS));
|
|
23626
|
+
router.use("/", createAgentRunsRouter(elizaOS));
|
|
23627
|
+
router.use("/", createAgentMemoryRouter(elizaOS));
|
|
23628
|
+
router.use("/", createRoomManagementRouter(elizaOS));
|
|
23627
23629
|
return router;
|
|
23628
23630
|
}
|
|
23629
23631
|
|
|
@@ -24178,8 +24180,8 @@ import { validateUuid as validateUuid12, logger as logger11 } from "@elizaos/cor
|
|
|
24178
24180
|
|
|
24179
24181
|
// src/api/shared/validation.ts
|
|
24180
24182
|
import { validateUuid as validateUuid11, logger as logger10 } from "@elizaos/core";
|
|
24181
|
-
var getRuntime = (
|
|
24182
|
-
const runtime =
|
|
24183
|
+
var getRuntime = (elizaOS, agentId) => {
|
|
24184
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
24183
24185
|
if (!runtime) {
|
|
24184
24186
|
throw new Error(`Agent not found: ${agentId}`);
|
|
24185
24187
|
}
|
|
@@ -24921,7 +24923,7 @@ async function saveChannelUploadedFile(file, channelId) {
|
|
|
24921
24923
|
const url = `/media/uploads/channels/${channelId}/${filename}`;
|
|
24922
24924
|
return { filename, url };
|
|
24923
24925
|
}
|
|
24924
|
-
function createChannelsRouter(
|
|
24926
|
+
function createChannelsRouter(elizaOS, serverInstance) {
|
|
24925
24927
|
const router = express12.Router();
|
|
24926
24928
|
router.post("/central-channels/:channelId/messages", async (req, res) => {
|
|
24927
24929
|
const channelIdParam = validateUuid13(req.params.channelId);
|
|
@@ -25494,7 +25496,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
25494
25496
|
});
|
|
25495
25497
|
}
|
|
25496
25498
|
try {
|
|
25497
|
-
const runtime =
|
|
25499
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
25498
25500
|
if (!runtime) {
|
|
25499
25501
|
return res.status(404).json({
|
|
25500
25502
|
success: false,
|
|
@@ -26000,7 +26002,7 @@ function asyncHandler(fn) {
|
|
|
26000
26002
|
Promise.resolve(fn(req, res, next)).catch(next);
|
|
26001
26003
|
};
|
|
26002
26004
|
}
|
|
26003
|
-
function createSessionsRouter(
|
|
26005
|
+
function createSessionsRouter(elizaOS, serverInstance) {
|
|
26004
26006
|
const router = express13.Router();
|
|
26005
26007
|
router.get("/sessions/health", (_req, res) => {
|
|
26006
26008
|
const now = Date.now();
|
|
@@ -26040,7 +26042,7 @@ function createSessionsRouter(agents, serverInstance) {
|
|
|
26040
26042
|
if (!validateUuid14(body.userId)) {
|
|
26041
26043
|
throw new InvalidUuidError("userId", body.userId);
|
|
26042
26044
|
}
|
|
26043
|
-
const agent =
|
|
26045
|
+
const agent = elizaOS.getAgent(body.agentId);
|
|
26044
26046
|
if (!agent) {
|
|
26045
26047
|
throw new AgentNotFoundError(body.agentId);
|
|
26046
26048
|
}
|
|
@@ -26348,7 +26350,7 @@ function createSessionsRouter(agents, serverInstance) {
|
|
|
26348
26350
|
}
|
|
26349
26351
|
}
|
|
26350
26352
|
}
|
|
26351
|
-
const agent =
|
|
26353
|
+
const agent = elizaOS.getAgent(session.agentId);
|
|
26352
26354
|
const agentConfig = agent ? getAgentTimeoutConfig(agent) : undefined;
|
|
26353
26355
|
session.timeoutConfig = mergeTimeoutConfigs(newConfig, agentConfig);
|
|
26354
26356
|
session.expiresAt = calculateExpirationDate(session.createdAt, session.lastActivity, session.timeoutConfig, session.renewalCount);
|
|
@@ -26465,15 +26467,15 @@ function createSessionsRouter(agents, serverInstance) {
|
|
|
26465
26467
|
}
|
|
26466
26468
|
|
|
26467
26469
|
// src/api/messaging/index.ts
|
|
26468
|
-
function messagingRouter(
|
|
26470
|
+
function messagingRouter(elizaOS, serverInstance) {
|
|
26469
26471
|
const router = express14.Router();
|
|
26470
26472
|
if (!serverInstance) {
|
|
26471
26473
|
throw new Error("ServerInstance is required for messaging router");
|
|
26472
26474
|
}
|
|
26473
26475
|
router.use("/", createMessagingCoreRouter(serverInstance));
|
|
26474
26476
|
router.use("/", createServersRouter(serverInstance));
|
|
26475
|
-
router.use("/", createChannelsRouter(
|
|
26476
|
-
router.use("/", createSessionsRouter(
|
|
26477
|
+
router.use("/", createChannelsRouter(elizaOS, serverInstance));
|
|
26478
|
+
router.use("/", createSessionsRouter(elizaOS, serverInstance));
|
|
26477
26479
|
return router;
|
|
26478
26480
|
}
|
|
26479
26481
|
|
|
@@ -26669,7 +26671,7 @@ function validateAudioFile(file) {
|
|
|
26669
26671
|
return ALLOWED_AUDIO_MIME_TYPES.some((allowed) => allowed === file.mimetype);
|
|
26670
26672
|
}
|
|
26671
26673
|
// src/api/memory/groups.ts
|
|
26672
|
-
function createGroupMemoryRouter(
|
|
26674
|
+
function createGroupMemoryRouter(elizaOS, serverInstance) {
|
|
26673
26675
|
const router = express18.Router();
|
|
26674
26676
|
const db = serverInstance?.database;
|
|
26675
26677
|
router.post("/groups/:serverId", async (req, res) => {
|
|
@@ -26682,7 +26684,7 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
26682
26684
|
let errors = [];
|
|
26683
26685
|
for (const agentId of agentIds) {
|
|
26684
26686
|
try {
|
|
26685
|
-
const runtime = getRuntime(
|
|
26687
|
+
const runtime = getRuntime(elizaOS, agentId);
|
|
26686
26688
|
const roomId = createUniqueUuid4(runtime, serverId);
|
|
26687
26689
|
const roomName = name || `Chat ${new Date().toLocaleString()}`;
|
|
26688
26690
|
await runtime.ensureWorldExists({
|
|
@@ -26774,11 +26776,11 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
26774
26776
|
}
|
|
26775
26777
|
|
|
26776
26778
|
// src/api/memory/index.ts
|
|
26777
|
-
function memoryRouter(
|
|
26779
|
+
function memoryRouter(elizaOS, serverInstance) {
|
|
26778
26780
|
const router = express19.Router();
|
|
26779
|
-
router.use("/", createAgentMemoryRouter(
|
|
26780
|
-
router.use("/", createGroupMemoryRouter(
|
|
26781
|
-
router.use("/", createRoomManagementRouter(
|
|
26781
|
+
router.use("/", createAgentMemoryRouter(elizaOS));
|
|
26782
|
+
router.use("/", createGroupMemoryRouter(elizaOS, serverInstance));
|
|
26783
|
+
router.use("/", createRoomManagementRouter(elizaOS));
|
|
26782
26784
|
return router;
|
|
26783
26785
|
}
|
|
26784
26786
|
|
|
@@ -26788,7 +26790,7 @@ import express23 from "express";
|
|
|
26788
26790
|
// src/api/audio/processing.ts
|
|
26789
26791
|
import { logger as logger19, ModelType as ModelType2, validateUuid as validateUuid19 } from "@elizaos/core";
|
|
26790
26792
|
import express20 from "express";
|
|
26791
|
-
function createAudioProcessingRouter(
|
|
26793
|
+
function createAudioProcessingRouter(elizaOS) {
|
|
26792
26794
|
const router = express20.Router();
|
|
26793
26795
|
router.use(createUploadRateLimit());
|
|
26794
26796
|
router.use(createFileSystemRateLimit());
|
|
@@ -26803,7 +26805,7 @@ function createAudioProcessingRouter(agents) {
|
|
|
26803
26805
|
if (!audioFile) {
|
|
26804
26806
|
return sendError(res, 400, "INVALID_REQUEST", "No audio file provided");
|
|
26805
26807
|
}
|
|
26806
|
-
const runtime =
|
|
26808
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
26807
26809
|
if (!runtime) {
|
|
26808
26810
|
cleanupUploadedFile(audioFile);
|
|
26809
26811
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
@@ -26838,7 +26840,7 @@ function createAudioProcessingRouter(agents) {
|
|
|
26838
26840
|
if (!audioFile) {
|
|
26839
26841
|
return sendError(res, 400, "INVALID_REQUEST", "No audio file provided");
|
|
26840
26842
|
}
|
|
26841
|
-
const runtime =
|
|
26843
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
26842
26844
|
if (!runtime) {
|
|
26843
26845
|
cleanupUploadedFile(audioFile);
|
|
26844
26846
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
@@ -26927,7 +26929,7 @@ async function convertToAudioBuffer(speechResponse, detectMimeType) {
|
|
|
26927
26929
|
}
|
|
26928
26930
|
|
|
26929
26931
|
// src/api/audio/synthesis.ts
|
|
26930
|
-
function createSynthesisRouter(
|
|
26932
|
+
function createSynthesisRouter(elizaOS) {
|
|
26931
26933
|
const router = express21.Router();
|
|
26932
26934
|
router.post("/:agentId/audio-messages/synthesize", async (req, res) => {
|
|
26933
26935
|
const agentId = validateUuid20(req.params.agentId);
|
|
@@ -26938,7 +26940,7 @@ function createSynthesisRouter(agents) {
|
|
|
26938
26940
|
if (!text) {
|
|
26939
26941
|
return sendError(res, 400, "INVALID_REQUEST", "Text is required for speech synthesis");
|
|
26940
26942
|
}
|
|
26941
|
-
const runtime =
|
|
26943
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
26942
26944
|
if (!runtime) {
|
|
26943
26945
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
26944
26946
|
}
|
|
@@ -26966,7 +26968,7 @@ function createSynthesisRouter(agents) {
|
|
|
26966
26968
|
if (!text) {
|
|
26967
26969
|
return sendError(res, 400, "INVALID_REQUEST", "Text is required for speech synthesis");
|
|
26968
26970
|
}
|
|
26969
|
-
const runtime =
|
|
26971
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
26970
26972
|
if (!runtime) {
|
|
26971
26973
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
26972
26974
|
}
|
|
@@ -27001,7 +27003,7 @@ import {
|
|
|
27001
27003
|
messageHandlerTemplate
|
|
27002
27004
|
} from "@elizaos/core";
|
|
27003
27005
|
import express22 from "express";
|
|
27004
|
-
function createConversationRouter(
|
|
27006
|
+
function createConversationRouter(elizaOS) {
|
|
27005
27007
|
const router = express22.Router();
|
|
27006
27008
|
router.post("/:agentId/speech/conversation", async (req, res) => {
|
|
27007
27009
|
const agentId = validateUuid21(req.params.agentId);
|
|
@@ -27012,7 +27014,7 @@ function createConversationRouter(agents) {
|
|
|
27012
27014
|
if (!text) {
|
|
27013
27015
|
return sendError(res, 400, "INVALID_REQUEST", "Text is required for conversation");
|
|
27014
27016
|
}
|
|
27015
|
-
const runtime =
|
|
27017
|
+
const runtime = elizaOS.getAgent(agentId);
|
|
27016
27018
|
if (!runtime) {
|
|
27017
27019
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
27018
27020
|
}
|
|
@@ -27105,11 +27107,11 @@ function createConversationRouter(agents) {
|
|
|
27105
27107
|
}
|
|
27106
27108
|
|
|
27107
27109
|
// src/api/audio/index.ts
|
|
27108
|
-
function audioRouter(
|
|
27110
|
+
function audioRouter(elizaOS) {
|
|
27109
27111
|
const router = express23.Router();
|
|
27110
|
-
router.use("/", createAudioProcessingRouter(
|
|
27111
|
-
router.use("/", createSynthesisRouter(
|
|
27112
|
-
router.use("/", createConversationRouter(
|
|
27112
|
+
router.use("/", createAudioProcessingRouter(elizaOS));
|
|
27113
|
+
router.use("/", createSynthesisRouter(elizaOS));
|
|
27114
|
+
router.use("/", createConversationRouter(elizaOS));
|
|
27113
27115
|
return router;
|
|
27114
27116
|
}
|
|
27115
27117
|
|
|
@@ -27119,7 +27121,7 @@ import express27 from "express";
|
|
|
27119
27121
|
// src/api/runtime/health.ts
|
|
27120
27122
|
import { logger as logger22 } from "@elizaos/core";
|
|
27121
27123
|
import express24 from "express";
|
|
27122
|
-
function createHealthRouter(
|
|
27124
|
+
function createHealthRouter(elizaOS, serverInstance) {
|
|
27123
27125
|
const router = express24.Router();
|
|
27124
27126
|
router.get("/ping", (_req, res) => {
|
|
27125
27127
|
res.json({ pong: true, timestamp: Date.now() });
|
|
@@ -27134,7 +27136,7 @@ function createHealthRouter(agents, serverInstance) {
|
|
|
27134
27136
|
res.setHeader("Content-Type", "application/json");
|
|
27135
27137
|
res.send(JSON.stringify({
|
|
27136
27138
|
status: "ok",
|
|
27137
|
-
agentCount:
|
|
27139
|
+
agentCount: elizaOS.getAgents().length,
|
|
27138
27140
|
timestamp: new Date().toISOString()
|
|
27139
27141
|
}));
|
|
27140
27142
|
});
|
|
@@ -27145,7 +27147,7 @@ function createHealthRouter(agents, serverInstance) {
|
|
|
27145
27147
|
version: process.env.APP_VERSION || "unknown",
|
|
27146
27148
|
timestamp: new Date().toISOString(),
|
|
27147
27149
|
dependencies: {
|
|
27148
|
-
agents:
|
|
27150
|
+
agents: elizaOS.getAgents().length > 0 ? "healthy" : "no_agents"
|
|
27149
27151
|
}
|
|
27150
27152
|
};
|
|
27151
27153
|
const statusCode = healthcheck.dependencies.agents === "healthy" ? 200 : 503;
|
|
@@ -27316,9 +27318,9 @@ function createDebugRouter(serverInstance) {
|
|
|
27316
27318
|
}
|
|
27317
27319
|
|
|
27318
27320
|
// src/api/runtime/index.ts
|
|
27319
|
-
function runtimeRouter(
|
|
27321
|
+
function runtimeRouter(elizaOS, serverInstance) {
|
|
27320
27322
|
const router = express27.Router();
|
|
27321
|
-
router.use("/", createHealthRouter(
|
|
27323
|
+
router.use("/", createHealthRouter(elizaOS, serverInstance));
|
|
27322
27324
|
router.use("/", createLoggingRouter());
|
|
27323
27325
|
router.use("/debug", createDebugRouter(serverInstance));
|
|
27324
27326
|
return router;
|
|
@@ -27452,7 +27454,7 @@ import express30 from "express";
|
|
|
27452
27454
|
// package.json
|
|
27453
27455
|
var package_default = {
|
|
27454
27456
|
name: "@elizaos/server",
|
|
27455
|
-
version: "1.5.
|
|
27457
|
+
version: "1.5.11-alpha.2",
|
|
27456
27458
|
description: "ElizaOS Server - Core server infrastructure for ElizaOS agents",
|
|
27457
27459
|
publishConfig: {
|
|
27458
27460
|
access: "public",
|
|
@@ -27575,16 +27577,16 @@ import {
|
|
|
27575
27577
|
var DEFAULT_SERVER_ID5 = "00000000-0000-0000-0000-000000000000";
|
|
27576
27578
|
|
|
27577
27579
|
class SocketIORouter {
|
|
27578
|
-
|
|
27580
|
+
elizaOS;
|
|
27579
27581
|
connections;
|
|
27580
27582
|
logStreamConnections;
|
|
27581
27583
|
serverInstance;
|
|
27582
|
-
constructor(
|
|
27583
|
-
this.
|
|
27584
|
+
constructor(elizaOS, serverInstance) {
|
|
27585
|
+
this.elizaOS = elizaOS;
|
|
27584
27586
|
this.connections = new Map;
|
|
27585
27587
|
this.logStreamConnections = new Map;
|
|
27586
27588
|
this.serverInstance = serverInstance;
|
|
27587
|
-
logger25.info(`[SocketIO] Router initialized with ${this.
|
|
27589
|
+
logger25.info(`[SocketIO] Router initialized with ${this.elizaOS.getAgents().length} agents`);
|
|
27588
27590
|
}
|
|
27589
27591
|
setupListeners(io) {
|
|
27590
27592
|
logger25.info(`[SocketIO] Setting up Socket.IO event listeners`);
|
|
@@ -27676,7 +27678,7 @@ class SocketIORouter {
|
|
|
27676
27678
|
const finalServerId = serverId || DEFAULT_SERVER_ID5;
|
|
27677
27679
|
const isDm = metadata?.isDm || metadata?.channelType === ChannelType6.DM;
|
|
27678
27680
|
logger25.info(`[SocketIO] Emitting ENTITY_JOINED event for entityId: ${entityId}, serverId: ${finalServerId}, isDm: ${isDm}`);
|
|
27679
|
-
const runtime =
|
|
27681
|
+
const runtime = this.elizaOS.getAgents()[0];
|
|
27680
27682
|
if (runtime) {
|
|
27681
27683
|
runtime.emitEvent(EventType.ENTITY_JOINED, {
|
|
27682
27684
|
entityId,
|
|
@@ -27722,7 +27724,7 @@ class SocketIORouter {
|
|
|
27722
27724
|
const isDmForWorldSetup = metadata?.isDm || metadata?.channelType === ChannelType6.DM;
|
|
27723
27725
|
if (isDmForWorldSetup && senderId) {
|
|
27724
27726
|
logger25.info(`[SocketIO] Detected DM channel during message submission, emitting ENTITY_JOINED for proper world setup`);
|
|
27725
|
-
const runtime =
|
|
27727
|
+
const runtime = this.elizaOS.getAgents()[0];
|
|
27726
27728
|
if (runtime) {
|
|
27727
27729
|
runtime.emitEvent(EventType.ENTITY_JOINED, {
|
|
27728
27730
|
entityId: senderId,
|
|
@@ -27914,14 +27916,14 @@ class SocketIORouter {
|
|
|
27914
27916
|
}
|
|
27915
27917
|
|
|
27916
27918
|
// src/api/index.ts
|
|
27917
|
-
function setupSocketIO(server,
|
|
27919
|
+
function setupSocketIO(server, elizaOS, serverInstance) {
|
|
27918
27920
|
const io = new SocketIOServer(server, {
|
|
27919
27921
|
cors: {
|
|
27920
27922
|
origin: "*",
|
|
27921
27923
|
methods: ["GET", "POST"]
|
|
27922
27924
|
}
|
|
27923
27925
|
});
|
|
27924
|
-
const centralSocketRouter = new SocketIORouter(
|
|
27926
|
+
const centralSocketRouter = new SocketIORouter(elizaOS, serverInstance);
|
|
27925
27927
|
centralSocketRouter.setupListeners(io);
|
|
27926
27928
|
setupLogStreaming(io, centralSocketRouter);
|
|
27927
27929
|
return io;
|
|
@@ -27952,7 +27954,7 @@ function setupLogStreaming(io, router) {
|
|
|
27952
27954
|
};
|
|
27953
27955
|
}
|
|
27954
27956
|
}
|
|
27955
|
-
function createPluginRouteHandler(
|
|
27957
|
+
function createPluginRouteHandler(elizaOS) {
|
|
27956
27958
|
return (req, res, next) => {
|
|
27957
27959
|
logger26.debug("Handling plugin request in the plugin route handler", `path: ${req.path}, method: ${req.method}`, {
|
|
27958
27960
|
path: req.path,
|
|
@@ -27976,7 +27978,7 @@ function createPluginRouteHandler(agents) {
|
|
|
27976
27978
|
logger26.debug(`JavaScript request in plugin handler: ${req.method} ${req.path}`);
|
|
27977
27979
|
res.setHeader("Content-Type", "application/javascript");
|
|
27978
27980
|
}
|
|
27979
|
-
if (
|
|
27981
|
+
if (elizaOS.getAgents().length === 0) {
|
|
27980
27982
|
logger26.debug("No agents available, skipping plugin route handling.");
|
|
27981
27983
|
return next();
|
|
27982
27984
|
}
|
|
@@ -28054,7 +28056,7 @@ function createPluginRouteHandler(agents) {
|
|
|
28054
28056
|
return handled;
|
|
28055
28057
|
}
|
|
28056
28058
|
if (agentIdFromQuery && validateUuid23(agentIdFromQuery)) {
|
|
28057
|
-
const runtime =
|
|
28059
|
+
const runtime = elizaOS.getAgent(agentIdFromQuery);
|
|
28058
28060
|
if (runtime) {
|
|
28059
28061
|
logger26.debug(`Agent-scoped request for Agent ID: ${agentIdFromQuery} from query. Path: ${reqPath}`);
|
|
28060
28062
|
handled = findRouteInRuntime(runtime);
|
|
@@ -28089,7 +28091,7 @@ function createPluginRouteHandler(agents) {
|
|
|
28089
28091
|
}
|
|
28090
28092
|
} else {
|
|
28091
28093
|
logger26.debug(`No valid agentId in query. Trying global match for path: ${reqPath}`);
|
|
28092
|
-
for (const
|
|
28094
|
+
for (const runtime of elizaOS.getAgents()) {
|
|
28093
28095
|
if (handled)
|
|
28094
28096
|
break;
|
|
28095
28097
|
handled = findRouteInRuntime(runtime);
|
|
@@ -28102,7 +28104,7 @@ function createPluginRouteHandler(agents) {
|
|
|
28102
28104
|
next();
|
|
28103
28105
|
};
|
|
28104
28106
|
}
|
|
28105
|
-
function createApiRouter(
|
|
28107
|
+
function createApiRouter(elizaOS, serverInstance) {
|
|
28106
28108
|
const router = express32.Router();
|
|
28107
28109
|
router.use(helmet({
|
|
28108
28110
|
contentSecurityPolicy: false,
|
|
@@ -28121,14 +28123,14 @@ function createApiRouter(agents, serverInstance) {
|
|
|
28121
28123
|
router.use(securityMiddleware());
|
|
28122
28124
|
router.use("/media", mediaRouter());
|
|
28123
28125
|
router.use(validateContentTypeMiddleware());
|
|
28124
|
-
router.use("/agents", agentsRouter(
|
|
28125
|
-
router.use("/messaging", messagingRouter(
|
|
28126
|
-
router.use("/memory", memoryRouter(
|
|
28127
|
-
router.use("/audio", audioRouter(
|
|
28128
|
-
router.use("/server", runtimeRouter(
|
|
28126
|
+
router.use("/agents", agentsRouter(elizaOS, serverInstance));
|
|
28127
|
+
router.use("/messaging", messagingRouter(elizaOS, serverInstance));
|
|
28128
|
+
router.use("/memory", memoryRouter(elizaOS, serverInstance));
|
|
28129
|
+
router.use("/audio", audioRouter(elizaOS));
|
|
28130
|
+
router.use("/server", runtimeRouter(elizaOS, serverInstance));
|
|
28129
28131
|
router.use("/tee", teeRouter());
|
|
28130
28132
|
router.use("/system", systemRouter());
|
|
28131
|
-
router.use(createPluginRouteHandler(
|
|
28133
|
+
router.use(createPluginRouteHandler(elizaOS));
|
|
28132
28134
|
return router;
|
|
28133
28135
|
}
|
|
28134
28136
|
|
|
@@ -43543,8 +43545,205 @@ function _init2(options = {}, getDefaultIntegrationsImpl) {
|
|
|
43543
43545
|
}
|
|
43544
43546
|
// src/index.ts
|
|
43545
43547
|
import sqlPlugin, { createDatabaseAdapter, DatabaseMigrationService } from "@elizaos/plugin-sql";
|
|
43546
|
-
|
|
43548
|
+
|
|
43549
|
+
// src/managers/PluginLoader.ts
|
|
43550
|
+
import { logger as logger30 } from "@elizaos/core";
|
|
43551
|
+
|
|
43552
|
+
class PluginLoader {
|
|
43553
|
+
isValidPluginShape(obj) {
|
|
43554
|
+
if (!obj || typeof obj !== "object" || !obj.name) {
|
|
43555
|
+
return false;
|
|
43556
|
+
}
|
|
43557
|
+
return !!(obj.init || obj.services || obj.providers || obj.actions || obj.evaluators || obj.description);
|
|
43558
|
+
}
|
|
43559
|
+
validatePlugin(plugin) {
|
|
43560
|
+
const errors = [];
|
|
43561
|
+
if (!plugin) {
|
|
43562
|
+
errors.push("Plugin is null or undefined");
|
|
43563
|
+
return { isValid: false, errors };
|
|
43564
|
+
}
|
|
43565
|
+
if (!plugin.name) {
|
|
43566
|
+
errors.push("Plugin must have a name");
|
|
43567
|
+
}
|
|
43568
|
+
if (plugin.actions) {
|
|
43569
|
+
if (!Array.isArray(plugin.actions)) {
|
|
43570
|
+
errors.push("Plugin actions must be an array");
|
|
43571
|
+
} else {
|
|
43572
|
+
const invalidActions = plugin.actions.filter((a) => typeof a !== "object" || !a);
|
|
43573
|
+
if (invalidActions.length > 0) {
|
|
43574
|
+
errors.push("Plugin actions must be an array of action objects");
|
|
43575
|
+
}
|
|
43576
|
+
}
|
|
43577
|
+
}
|
|
43578
|
+
if (plugin.services) {
|
|
43579
|
+
if (!Array.isArray(plugin.services)) {
|
|
43580
|
+
errors.push("Plugin services must be an array");
|
|
43581
|
+
} else {
|
|
43582
|
+
const invalidServices = plugin.services.filter((s) => typeof s !== "function" && (typeof s !== "object" || !s));
|
|
43583
|
+
if (invalidServices.length > 0) {
|
|
43584
|
+
errors.push("Plugin services must be an array of service classes or objects");
|
|
43585
|
+
}
|
|
43586
|
+
}
|
|
43587
|
+
}
|
|
43588
|
+
if (plugin.providers && !Array.isArray(plugin.providers)) {
|
|
43589
|
+
errors.push("Plugin providers must be an array");
|
|
43590
|
+
}
|
|
43591
|
+
if (plugin.evaluators && !Array.isArray(plugin.evaluators)) {
|
|
43592
|
+
errors.push("Plugin evaluators must be an array");
|
|
43593
|
+
}
|
|
43594
|
+
return {
|
|
43595
|
+
isValid: errors.length === 0,
|
|
43596
|
+
errors
|
|
43597
|
+
};
|
|
43598
|
+
}
|
|
43599
|
+
async loadAndPreparePlugin(pluginName) {
|
|
43600
|
+
try {
|
|
43601
|
+
let pluginModule;
|
|
43602
|
+
try {
|
|
43603
|
+
pluginModule = await import(pluginName);
|
|
43604
|
+
} catch (error2) {
|
|
43605
|
+
logger30.error(`Failed to load plugin ${pluginName}: ${error2}`);
|
|
43606
|
+
return null;
|
|
43607
|
+
}
|
|
43608
|
+
if (!pluginModule) {
|
|
43609
|
+
logger30.error(`Failed to load module for plugin ${pluginName}.`);
|
|
43610
|
+
return null;
|
|
43611
|
+
}
|
|
43612
|
+
const expectedFunctionName = `${pluginName.replace(/^@elizaos\/plugin-/, "").replace(/^@elizaos\//, "").replace(/-./g, (match3) => match3[1].toUpperCase())}Plugin`;
|
|
43613
|
+
const exportsToCheck = [
|
|
43614
|
+
pluginModule[expectedFunctionName],
|
|
43615
|
+
pluginModule.default,
|
|
43616
|
+
...Object.values(pluginModule)
|
|
43617
|
+
];
|
|
43618
|
+
for (const potentialPlugin of exportsToCheck) {
|
|
43619
|
+
if (this.isValidPluginShape(potentialPlugin)) {
|
|
43620
|
+
return potentialPlugin;
|
|
43621
|
+
}
|
|
43622
|
+
if (typeof potentialPlugin === "function" && potentialPlugin.length === 0) {
|
|
43623
|
+
try {
|
|
43624
|
+
const produced = potentialPlugin();
|
|
43625
|
+
if (this.isValidPluginShape(produced)) {
|
|
43626
|
+
return produced;
|
|
43627
|
+
}
|
|
43628
|
+
} catch (err) {
|
|
43629
|
+
logger30.debug(`Factory export threw for ${pluginName}: ${err}`);
|
|
43630
|
+
}
|
|
43631
|
+
}
|
|
43632
|
+
}
|
|
43633
|
+
logger30.warn(`Could not find a valid plugin export in ${pluginName}.`);
|
|
43634
|
+
return null;
|
|
43635
|
+
} catch (error2) {
|
|
43636
|
+
logger30.error(`Error loading plugin ${pluginName}: ${error2}`);
|
|
43637
|
+
return null;
|
|
43638
|
+
}
|
|
43639
|
+
}
|
|
43640
|
+
resolvePluginDependencies(availablePlugins, isTestMode = false) {
|
|
43641
|
+
const resolutionOrder = [];
|
|
43642
|
+
const visited = new Set;
|
|
43643
|
+
const visiting = new Set;
|
|
43644
|
+
function visit2(pluginName) {
|
|
43645
|
+
if (!availablePlugins.has(pluginName)) {
|
|
43646
|
+
logger30.warn(`Plugin dependency "${pluginName}" not found and will be skipped.`);
|
|
43647
|
+
return;
|
|
43648
|
+
}
|
|
43649
|
+
if (visited.has(pluginName))
|
|
43650
|
+
return;
|
|
43651
|
+
if (visiting.has(pluginName)) {
|
|
43652
|
+
logger30.error(`Circular dependency detected involving plugin: ${pluginName}`);
|
|
43653
|
+
return;
|
|
43654
|
+
}
|
|
43655
|
+
visiting.add(pluginName);
|
|
43656
|
+
const plugin = availablePlugins.get(pluginName);
|
|
43657
|
+
if (plugin) {
|
|
43658
|
+
const deps = [...plugin.dependencies || []];
|
|
43659
|
+
if (isTestMode) {
|
|
43660
|
+
deps.push(...plugin.testDependencies || []);
|
|
43661
|
+
}
|
|
43662
|
+
for (const dep of deps) {
|
|
43663
|
+
visit2(dep);
|
|
43664
|
+
}
|
|
43665
|
+
}
|
|
43666
|
+
visiting.delete(pluginName);
|
|
43667
|
+
visited.add(pluginName);
|
|
43668
|
+
resolutionOrder.push(pluginName);
|
|
43669
|
+
}
|
|
43670
|
+
for (const name of availablePlugins.keys()) {
|
|
43671
|
+
if (!visited.has(name)) {
|
|
43672
|
+
visit2(name);
|
|
43673
|
+
}
|
|
43674
|
+
}
|
|
43675
|
+
const finalPlugins = resolutionOrder.map((name) => availablePlugins.get(name)).filter((p) => p);
|
|
43676
|
+
logger30.info({ plugins: finalPlugins.map((p) => p.name) }, `Final plugins being loaded:`);
|
|
43677
|
+
return finalPlugins;
|
|
43678
|
+
}
|
|
43679
|
+
}
|
|
43680
|
+
|
|
43681
|
+
// src/managers/ConfigManager.ts
|
|
43547
43682
|
var import_dotenv2 = __toESM(require_main(), 1);
|
|
43683
|
+
import * as fs6 from "node:fs";
|
|
43684
|
+
import * as path8 from "node:path";
|
|
43685
|
+
|
|
43686
|
+
class ConfigManager {
|
|
43687
|
+
async loadEnvConfig() {
|
|
43688
|
+
const envPath = this.findEnvFile();
|
|
43689
|
+
if (envPath) {
|
|
43690
|
+
import_dotenv2.default.config({ path: envPath });
|
|
43691
|
+
}
|
|
43692
|
+
return process.env;
|
|
43693
|
+
}
|
|
43694
|
+
findEnvFile() {
|
|
43695
|
+
const possiblePaths = [
|
|
43696
|
+
path8.join(process.cwd(), ".env"),
|
|
43697
|
+
path8.join(process.cwd(), ".env.local")
|
|
43698
|
+
];
|
|
43699
|
+
for (const envPath of possiblePaths) {
|
|
43700
|
+
if (fs6.existsSync(envPath)) {
|
|
43701
|
+
return envPath;
|
|
43702
|
+
}
|
|
43703
|
+
}
|
|
43704
|
+
return null;
|
|
43705
|
+
}
|
|
43706
|
+
hasCharacterSecrets(character) {
|
|
43707
|
+
return Boolean(character?.settings?.secrets && Object.keys(character.settings.secrets).length > 0);
|
|
43708
|
+
}
|
|
43709
|
+
ensureCharacterSettings(character) {
|
|
43710
|
+
if (!character.settings) {
|
|
43711
|
+
character.settings = {};
|
|
43712
|
+
}
|
|
43713
|
+
}
|
|
43714
|
+
async loadLocalEnvSecrets() {
|
|
43715
|
+
const envPath = this.findEnvFile();
|
|
43716
|
+
if (!envPath)
|
|
43717
|
+
return null;
|
|
43718
|
+
try {
|
|
43719
|
+
const buf = fs6.readFileSync(envPath);
|
|
43720
|
+
return import_dotenv2.default.parse(buf);
|
|
43721
|
+
} catch {
|
|
43722
|
+
return null;
|
|
43723
|
+
}
|
|
43724
|
+
}
|
|
43725
|
+
async setDefaultSecretsFromEnv(character) {
|
|
43726
|
+
this.ensureCharacterSettings(character);
|
|
43727
|
+
if (this.hasCharacterSecrets(character)) {
|
|
43728
|
+
return false;
|
|
43729
|
+
}
|
|
43730
|
+
const envSecrets = await this.loadLocalEnvSecrets();
|
|
43731
|
+
if (!envSecrets) {
|
|
43732
|
+
return false;
|
|
43733
|
+
}
|
|
43734
|
+
if (!character.settings) {
|
|
43735
|
+
character.settings = {};
|
|
43736
|
+
}
|
|
43737
|
+
character.settings.secrets = envSecrets;
|
|
43738
|
+
return true;
|
|
43739
|
+
}
|
|
43740
|
+
}
|
|
43741
|
+
|
|
43742
|
+
// src/index.ts
|
|
43743
|
+
import { encryptedCharacter, stringToUuid as stringToUuid2 } from "@elizaos/core";
|
|
43744
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
43745
|
+
var import_dotenv3 = __toESM(require_main(), 1);
|
|
43746
|
+
import { ElizaOS as ElizaOS3 } from "@elizaos/core";
|
|
43548
43747
|
function expandTildePath(filepath) {
|
|
43549
43748
|
if (!filepath) {
|
|
43550
43749
|
return filepath;
|
|
@@ -43553,19 +43752,19 @@ function expandTildePath(filepath) {
|
|
|
43553
43752
|
if (filepath === "~") {
|
|
43554
43753
|
return process.cwd();
|
|
43555
43754
|
} else if (filepath.startsWith("~/")) {
|
|
43556
|
-
return
|
|
43755
|
+
return path9.join(process.cwd(), filepath.slice(2));
|
|
43557
43756
|
} else if (filepath.startsWith("~~")) {
|
|
43558
43757
|
return filepath;
|
|
43559
43758
|
} else {
|
|
43560
|
-
return
|
|
43759
|
+
return path9.join(process.cwd(), filepath.slice(1));
|
|
43561
43760
|
}
|
|
43562
43761
|
}
|
|
43563
43762
|
return filepath;
|
|
43564
43763
|
}
|
|
43565
43764
|
function resolvePgliteDir(dir, fallbackDir) {
|
|
43566
43765
|
const envPath = resolveEnvFile();
|
|
43567
|
-
if (
|
|
43568
|
-
|
|
43766
|
+
if (existsSync5(envPath)) {
|
|
43767
|
+
import_dotenv3.default.config({ path: envPath });
|
|
43569
43768
|
}
|
|
43570
43769
|
if (dir) {
|
|
43571
43770
|
const resolved2 = expandTildePath(dir);
|
|
@@ -43594,119 +43793,229 @@ function isWebUIEnabled() {
|
|
|
43594
43793
|
|
|
43595
43794
|
class AgentServer {
|
|
43596
43795
|
app;
|
|
43597
|
-
agents;
|
|
43598
43796
|
server;
|
|
43599
43797
|
socketIO;
|
|
43600
43798
|
isInitialized = false;
|
|
43601
43799
|
isWebUIEnabled = true;
|
|
43602
43800
|
clientPath;
|
|
43801
|
+
elizaOS;
|
|
43802
|
+
pluginLoader;
|
|
43803
|
+
configManager;
|
|
43603
43804
|
database;
|
|
43604
|
-
startAgent;
|
|
43605
|
-
stopAgent;
|
|
43606
43805
|
loadCharacterTryPath;
|
|
43607
43806
|
jsonToCharacter;
|
|
43807
|
+
async startAgents(characters, plugins = []) {
|
|
43808
|
+
if (!this.elizaOS || !this.pluginLoader || !this.configManager) {
|
|
43809
|
+
throw new Error("Server not properly initialized");
|
|
43810
|
+
}
|
|
43811
|
+
const preparations = await Promise.all(characters.map(async (character) => {
|
|
43812
|
+
character.id ??= stringToUuid2(character.name);
|
|
43813
|
+
if (!this.configManager?.hasCharacterSecrets(character)) {
|
|
43814
|
+
await this.configManager?.setDefaultSecretsFromEnv(character);
|
|
43815
|
+
}
|
|
43816
|
+
const loadedPlugins = new Map;
|
|
43817
|
+
const pluginsToLoad = new Set(character.plugins || []);
|
|
43818
|
+
for (const p of plugins) {
|
|
43819
|
+
if (typeof p === "string") {
|
|
43820
|
+
pluginsToLoad.add(p);
|
|
43821
|
+
} else if (this.pluginLoader?.isValidPluginShape(p) && !loadedPlugins.has(p.name)) {
|
|
43822
|
+
loadedPlugins.set(p.name, p);
|
|
43823
|
+
(p.dependencies || []).forEach((dep) => {
|
|
43824
|
+
pluginsToLoad.add(dep);
|
|
43825
|
+
});
|
|
43826
|
+
}
|
|
43827
|
+
}
|
|
43828
|
+
const allAvailablePlugins = new Map;
|
|
43829
|
+
for (const p of loadedPlugins.values()) {
|
|
43830
|
+
allAvailablePlugins.set(p.name, p);
|
|
43831
|
+
}
|
|
43832
|
+
for (const name of pluginsToLoad) {
|
|
43833
|
+
if (!allAvailablePlugins.has(name)) {
|
|
43834
|
+
const loaded = await this.pluginLoader?.loadAndPreparePlugin(name);
|
|
43835
|
+
if (loaded) {
|
|
43836
|
+
allAvailablePlugins.set(loaded.name, loaded);
|
|
43837
|
+
}
|
|
43838
|
+
}
|
|
43839
|
+
}
|
|
43840
|
+
let haveSql = false;
|
|
43841
|
+
for (const [name] of allAvailablePlugins.entries()) {
|
|
43842
|
+
if (name === sqlPlugin.name || name === "mysql") {
|
|
43843
|
+
haveSql = true;
|
|
43844
|
+
break;
|
|
43845
|
+
}
|
|
43846
|
+
}
|
|
43847
|
+
if (!haveSql) {
|
|
43848
|
+
allAvailablePlugins.set(sqlPlugin.name, sqlPlugin);
|
|
43849
|
+
}
|
|
43850
|
+
allAvailablePlugins.set(messageBusConnectorPlugin.name, messageBusConnectorPlugin);
|
|
43851
|
+
const finalPlugins = this.pluginLoader?.resolvePluginDependencies(allAvailablePlugins, false);
|
|
43852
|
+
const preparedCharacter = encryptedCharacter(character);
|
|
43853
|
+
return { character: preparedCharacter, plugins: finalPlugins };
|
|
43854
|
+
}));
|
|
43855
|
+
const agentIds = await this.elizaOS.addAgents(preparations.map((p) => ({
|
|
43856
|
+
character: p.character,
|
|
43857
|
+
plugins: p.plugins
|
|
43858
|
+
})));
|
|
43859
|
+
await this.elizaOS.startAgents(agentIds);
|
|
43860
|
+
const runtimes = [];
|
|
43861
|
+
const settings = await this.configManager?.loadEnvConfig();
|
|
43862
|
+
for (const id of agentIds) {
|
|
43863
|
+
const runtime = this.elizaOS.getAgent(id);
|
|
43864
|
+
if (runtime) {
|
|
43865
|
+
Object.assign(runtime, { settings });
|
|
43866
|
+
await this.registerAgent(runtime);
|
|
43867
|
+
if (this.database) {
|
|
43868
|
+
try {
|
|
43869
|
+
const existingAgent = await this.database.getAgent(runtime.agentId);
|
|
43870
|
+
if (!existingAgent) {
|
|
43871
|
+
await this.database.createAgent({
|
|
43872
|
+
...runtime.character,
|
|
43873
|
+
id: runtime.agentId
|
|
43874
|
+
});
|
|
43875
|
+
logger31.info(`Persisted agent ${runtime.character.name} (${runtime.agentId}) to database`);
|
|
43876
|
+
}
|
|
43877
|
+
} catch (error2) {
|
|
43878
|
+
logger31.error({ error: error2 }, `Failed to persist agent ${runtime.agentId} to database`);
|
|
43879
|
+
}
|
|
43880
|
+
}
|
|
43881
|
+
runtimes.push(runtime);
|
|
43882
|
+
}
|
|
43883
|
+
}
|
|
43884
|
+
return runtimes;
|
|
43885
|
+
}
|
|
43886
|
+
async stopAgents(agentIds) {
|
|
43887
|
+
if (!this.elizaOS) {
|
|
43888
|
+
throw new Error("ElizaOS not initialized");
|
|
43889
|
+
}
|
|
43890
|
+
await this.elizaOS.stopAgents(agentIds);
|
|
43891
|
+
}
|
|
43892
|
+
getAllAgents() {
|
|
43893
|
+
if (!this.elizaOS) {
|
|
43894
|
+
return [];
|
|
43895
|
+
}
|
|
43896
|
+
return this.elizaOS.getAgents();
|
|
43897
|
+
}
|
|
43898
|
+
getAgent(agentId) {
|
|
43899
|
+
if (!this.elizaOS) {
|
|
43900
|
+
return;
|
|
43901
|
+
}
|
|
43902
|
+
return this.elizaOS.getAgent(agentId);
|
|
43903
|
+
}
|
|
43608
43904
|
constructor() {
|
|
43609
43905
|
try {
|
|
43610
|
-
|
|
43611
|
-
this.agents = new Map;
|
|
43906
|
+
logger31.debug("Initializing AgentServer (constructor)...");
|
|
43612
43907
|
this.loadCharacterTryPath = loadCharacterTryPath;
|
|
43613
43908
|
this.jsonToCharacter = jsonToCharacter;
|
|
43614
43909
|
this.registerSignalHandlers();
|
|
43615
43910
|
} catch (error2) {
|
|
43616
|
-
|
|
43911
|
+
logger31.error({ error: error2 }, "Failed to initialize AgentServer (constructor):");
|
|
43617
43912
|
throw error2;
|
|
43618
43913
|
}
|
|
43619
43914
|
}
|
|
43620
43915
|
async initialize(options) {
|
|
43621
43916
|
if (this.isInitialized) {
|
|
43622
|
-
|
|
43917
|
+
logger31.warn("AgentServer is already initialized, skipping initialization");
|
|
43623
43918
|
return;
|
|
43624
43919
|
}
|
|
43625
43920
|
try {
|
|
43626
|
-
|
|
43921
|
+
logger31.debug("Initializing AgentServer (async operations)...");
|
|
43627
43922
|
const agentDataDir = resolvePgliteDir(options?.dataDir);
|
|
43628
|
-
|
|
43923
|
+
logger31.info(`[INIT] Database Dir for SQL plugin: ${agentDataDir}`);
|
|
43924
|
+
const dbDir = path9.dirname(agentDataDir);
|
|
43925
|
+
if (!fs7.existsSync(dbDir)) {
|
|
43926
|
+
fs7.mkdirSync(dbDir, { recursive: true });
|
|
43927
|
+
logger31.info(`[INIT] Created database directory: ${dbDir}`);
|
|
43928
|
+
}
|
|
43929
|
+
const tempServerAgentId = "00000000-0000-0000-0000-000000000000";
|
|
43629
43930
|
this.database = createDatabaseAdapter({
|
|
43630
43931
|
dataDir: agentDataDir,
|
|
43631
43932
|
postgresUrl: options?.postgresUrl
|
|
43632
|
-
},
|
|
43933
|
+
}, tempServerAgentId);
|
|
43633
43934
|
await this.database.init();
|
|
43634
|
-
|
|
43635
|
-
|
|
43935
|
+
logger31.success("Database initialized for server operations");
|
|
43936
|
+
logger31.info("[INIT] Running database migrations for messaging tables...");
|
|
43636
43937
|
try {
|
|
43637
43938
|
const migrationService = new DatabaseMigrationService;
|
|
43638
43939
|
const db = this.database.getDatabase();
|
|
43639
43940
|
await migrationService.initializeWithDatabase(db);
|
|
43640
43941
|
migrationService.discoverAndRegisterPluginSchemas([sqlPlugin]);
|
|
43641
43942
|
await migrationService.runAllPluginMigrations();
|
|
43642
|
-
|
|
43943
|
+
logger31.success("[INIT] Database migrations completed successfully");
|
|
43643
43944
|
} catch (migrationError) {
|
|
43644
|
-
|
|
43945
|
+
logger31.error({ error: migrationError }, "[INIT] Failed to run database migrations:");
|
|
43645
43946
|
throw new Error(`Database migration failed: ${migrationError instanceof Error ? migrationError.message : String(migrationError)}`);
|
|
43646
43947
|
}
|
|
43647
43948
|
await new Promise((resolve2) => setTimeout(resolve2, 500));
|
|
43648
|
-
|
|
43949
|
+
logger31.info("[INIT] Ensuring default server exists...");
|
|
43649
43950
|
await this.ensureDefaultServer();
|
|
43650
|
-
|
|
43951
|
+
logger31.success("[INIT] Default server setup complete");
|
|
43952
|
+
logger31.info("[INIT] Server uses temporary adapter for migrations only");
|
|
43953
|
+
logger31.info("[INIT] Initializing ElizaOS...");
|
|
43954
|
+
logger31.debug("[INIT] ElizaOS will use agent-specific database adapters from SQL plugin");
|
|
43955
|
+
this.elizaOS = new ElizaOS2;
|
|
43956
|
+
this.elizaOS.enableEditableMode();
|
|
43957
|
+
this.pluginLoader = new PluginLoader;
|
|
43958
|
+
this.configManager = new ConfigManager;
|
|
43959
|
+
logger31.success("[INIT] ElizaOS initialized");
|
|
43651
43960
|
await this.initializeServer(options);
|
|
43652
43961
|
await new Promise((resolve2) => setTimeout(resolve2, 250));
|
|
43653
43962
|
this.isInitialized = true;
|
|
43654
43963
|
} catch (error2) {
|
|
43655
|
-
|
|
43964
|
+
logger31.error({ error: error2 }, "Failed to initialize AgentServer (async operations):");
|
|
43656
43965
|
console.trace(error2);
|
|
43657
43966
|
throw error2;
|
|
43658
43967
|
}
|
|
43659
43968
|
}
|
|
43660
43969
|
async ensureDefaultServer() {
|
|
43661
43970
|
try {
|
|
43662
|
-
|
|
43971
|
+
logger31.info("[AgentServer] Checking for default server...");
|
|
43663
43972
|
const servers = await this.database.getMessageServers();
|
|
43664
|
-
|
|
43973
|
+
logger31.debug(`[AgentServer] Found ${servers.length} existing servers`);
|
|
43665
43974
|
servers.forEach((s) => {
|
|
43666
|
-
|
|
43975
|
+
logger31.debug(`[AgentServer] Existing server: ID=${s.id}, Name=${s.name}`);
|
|
43667
43976
|
});
|
|
43668
43977
|
const defaultServer = servers.find((s) => s.id === "00000000-0000-0000-0000-000000000000");
|
|
43669
43978
|
if (!defaultServer) {
|
|
43670
|
-
|
|
43979
|
+
logger31.info("[AgentServer] Creating default server with UUID 00000000-0000-0000-0000-000000000000...");
|
|
43671
43980
|
try {
|
|
43672
43981
|
await this.database.db.execute(`
|
|
43673
43982
|
INSERT INTO message_servers (id, name, source_type, created_at, updated_at)
|
|
43674
43983
|
VALUES ('00000000-0000-0000-0000-000000000000', 'Default Server', 'eliza_default', NOW(), NOW())
|
|
43675
43984
|
ON CONFLICT (id) DO NOTHING
|
|
43676
43985
|
`);
|
|
43677
|
-
|
|
43986
|
+
logger31.success("[AgentServer] Default server created via raw SQL");
|
|
43678
43987
|
const checkResult = await this.database.db.execute("SELECT id, name FROM message_servers WHERE id = '00000000-0000-0000-0000-000000000000'");
|
|
43679
|
-
|
|
43988
|
+
logger31.debug("[AgentServer] Raw SQL check result:", checkResult);
|
|
43680
43989
|
} catch (sqlError) {
|
|
43681
|
-
|
|
43990
|
+
logger31.error("[AgentServer] Raw SQL insert failed:", sqlError);
|
|
43682
43991
|
try {
|
|
43683
43992
|
const server = await this.database.createMessageServer({
|
|
43684
43993
|
id: "00000000-0000-0000-0000-000000000000",
|
|
43685
43994
|
name: "Default Server",
|
|
43686
43995
|
sourceType: "eliza_default"
|
|
43687
43996
|
});
|
|
43688
|
-
|
|
43997
|
+
logger31.success("[AgentServer] Default server created via ORM with ID:", server.id);
|
|
43689
43998
|
} catch (ormError) {
|
|
43690
|
-
|
|
43999
|
+
logger31.error("[AgentServer] Both SQL and ORM creation failed:", ormError);
|
|
43691
44000
|
throw new Error(`Failed to create default server: ${ormError.message}`);
|
|
43692
44001
|
}
|
|
43693
44002
|
}
|
|
43694
44003
|
const verifyServers = await this.database.getMessageServers();
|
|
43695
|
-
|
|
44004
|
+
logger31.debug(`[AgentServer] After creation attempt, found ${verifyServers.length} servers`);
|
|
43696
44005
|
verifyServers.forEach((s) => {
|
|
43697
|
-
|
|
44006
|
+
logger31.debug(`[AgentServer] Server after creation: ID=${s.id}, Name=${s.name}`);
|
|
43698
44007
|
});
|
|
43699
44008
|
const verifyDefault = verifyServers.find((s) => s.id === "00000000-0000-0000-0000-000000000000");
|
|
43700
44009
|
if (!verifyDefault) {
|
|
43701
44010
|
throw new Error(`Failed to create or verify default server with ID ${DEFAULT_SERVER_ID6}`);
|
|
43702
44011
|
} else {
|
|
43703
|
-
|
|
44012
|
+
logger31.success("[AgentServer] Default server creation verified successfully");
|
|
43704
44013
|
}
|
|
43705
44014
|
} else {
|
|
43706
|
-
|
|
44015
|
+
logger31.info("[AgentServer] Default server already exists with ID:", defaultServer.id);
|
|
43707
44016
|
}
|
|
43708
44017
|
} catch (error2) {
|
|
43709
|
-
|
|
44018
|
+
logger31.error({ error: error2 }, "[AgentServer] Error ensuring default server:");
|
|
43710
44019
|
throw error2;
|
|
43711
44020
|
}
|
|
43712
44021
|
}
|
|
@@ -43717,7 +44026,7 @@ class AgentServer {
|
|
|
43717
44026
|
}
|
|
43718
44027
|
this.app = express33();
|
|
43719
44028
|
const DEFAULT_SENTRY_DSN = "https://c20e2d51b66c14a783b0689d536f7e5c@o4509349865259008.ingest.us.sentry.io/4509352524120064";
|
|
43720
|
-
const sentryDsn = process.env.SENTRY_DSN
|
|
44029
|
+
const sentryDsn = process.env.SENTRY_DSN?.trim() || DEFAULT_SENTRY_DSN;
|
|
43721
44030
|
const sentryEnabled = Boolean(sentryDsn);
|
|
43722
44031
|
if (sentryEnabled) {
|
|
43723
44032
|
try {
|
|
@@ -43727,16 +44036,16 @@ class AgentServer {
|
|
|
43727
44036
|
integrations: [vercelAIIntegration({ force: sentryEnabled })],
|
|
43728
44037
|
tracesSampleRate: Number(process.env.SENTRY_TRACES_SAMPLE_RATE || 0)
|
|
43729
44038
|
});
|
|
43730
|
-
|
|
44039
|
+
logger31.info("[Sentry] Initialized Sentry for @elizaos/server");
|
|
43731
44040
|
} catch (sentryInitError) {
|
|
43732
|
-
|
|
44041
|
+
logger31.error({ error: sentryInitError }, "[Sentry] Failed to initialize Sentry");
|
|
43733
44042
|
}
|
|
43734
44043
|
}
|
|
43735
44044
|
const isProd = false;
|
|
43736
|
-
|
|
44045
|
+
logger31.debug("Setting up security headers...");
|
|
43737
44046
|
if (!isProd) {
|
|
43738
|
-
|
|
43739
|
-
|
|
44047
|
+
logger31.debug(`NODE_ENV: ${"development"}`);
|
|
44048
|
+
logger31.debug(`CSP will be: ${isProd ? "ENABLED" : "MINIMAL_DEV"}`);
|
|
43740
44049
|
}
|
|
43741
44050
|
this.app.use(helmet({
|
|
43742
44051
|
contentSecurityPolicy: isProd ? {
|
|
@@ -43784,12 +44093,12 @@ class AgentServer {
|
|
|
43784
44093
|
xssFilter: true
|
|
43785
44094
|
}));
|
|
43786
44095
|
if (options?.middlewares) {
|
|
43787
|
-
|
|
44096
|
+
logger31.debug("Applying custom middlewares...");
|
|
43788
44097
|
for (const middleware2 of options.middlewares) {
|
|
43789
44098
|
this.app.use(middleware2);
|
|
43790
44099
|
}
|
|
43791
44100
|
}
|
|
43792
|
-
|
|
44101
|
+
logger31.debug("Setting up standard middlewares...");
|
|
43793
44102
|
this.app.use(cors2({
|
|
43794
44103
|
origin: process.env.CORS_ORIGIN || true,
|
|
43795
44104
|
credentials: true,
|
|
@@ -43801,28 +44110,28 @@ class AgentServer {
|
|
|
43801
44110
|
}));
|
|
43802
44111
|
const serverAuthToken = process.env.ELIZA_SERVER_AUTH_TOKEN;
|
|
43803
44112
|
if (serverAuthToken) {
|
|
43804
|
-
|
|
44113
|
+
logger31.info("Server authentication enabled. Requires X-API-KEY header for /api routes.");
|
|
43805
44114
|
this.app.use("/api", (req, res, next) => {
|
|
43806
44115
|
apiKeyAuthMiddleware(req, res, next);
|
|
43807
44116
|
});
|
|
43808
44117
|
} else {
|
|
43809
|
-
|
|
44118
|
+
logger31.warn("Server authentication is disabled. Set ELIZA_SERVER_AUTH_TOKEN environment variable to enable.");
|
|
43810
44119
|
}
|
|
43811
44120
|
this.isWebUIEnabled = isWebUIEnabled();
|
|
43812
44121
|
if (this.isWebUIEnabled) {
|
|
43813
|
-
|
|
44122
|
+
logger31.info("Web UI enabled");
|
|
43814
44123
|
} else {
|
|
43815
44124
|
const uiEnabledEnv = process.env.ELIZA_UI_ENABLE;
|
|
43816
44125
|
if (uiEnabledEnv !== undefined && uiEnabledEnv.trim() !== "") {
|
|
43817
|
-
|
|
44126
|
+
logger31.info(`Web UI disabled by environment variable (ELIZA_UI_ENABLE=${uiEnabledEnv})`);
|
|
43818
44127
|
} else {
|
|
43819
|
-
|
|
44128
|
+
logger31.info("Web UI disabled for security (production mode)");
|
|
43820
44129
|
}
|
|
43821
44130
|
}
|
|
43822
44131
|
const uploadsBasePath = getUploadsAgentsDir4();
|
|
43823
44132
|
const generatedBasePath = getGeneratedDir2();
|
|
43824
|
-
|
|
43825
|
-
|
|
44133
|
+
fs7.mkdirSync(uploadsBasePath, { recursive: true });
|
|
44134
|
+
fs7.mkdirSync(generatedBasePath, { recursive: true });
|
|
43826
44135
|
this.app.get("/media/uploads/agents/:agentId/:filename", (req, res) => {
|
|
43827
44136
|
const agentId = req.params.agentId;
|
|
43828
44137
|
const filename = req.params.filename;
|
|
@@ -43832,26 +44141,26 @@ class AgentServer {
|
|
|
43832
44141
|
return;
|
|
43833
44142
|
}
|
|
43834
44143
|
const sanitizedFilename = basename2(filename);
|
|
43835
|
-
const agentUploadsPath =
|
|
43836
|
-
const filePath =
|
|
44144
|
+
const agentUploadsPath = join5(uploadsBasePath, agentId);
|
|
44145
|
+
const filePath = join5(agentUploadsPath, sanitizedFilename);
|
|
43837
44146
|
if (!filePath.startsWith(agentUploadsPath)) {
|
|
43838
44147
|
res.status(403).json({ error: "Access denied" });
|
|
43839
44148
|
return;
|
|
43840
44149
|
}
|
|
43841
|
-
if (!
|
|
44150
|
+
if (!fs7.existsSync(filePath)) {
|
|
43842
44151
|
res.status(404).json({ error: "File does not exist!!!!!!!" });
|
|
43843
44152
|
return;
|
|
43844
44153
|
}
|
|
43845
44154
|
res.sendFile(sanitizedFilename, { root: agentUploadsPath }, (err) => {
|
|
43846
44155
|
if (err) {
|
|
43847
44156
|
if (err.message === "Request aborted") {
|
|
43848
|
-
|
|
44157
|
+
logger31.warn(`[MEDIA] Download aborted: ${req.originalUrl}`);
|
|
43849
44158
|
} else if (!res.headersSent) {
|
|
43850
|
-
|
|
44159
|
+
logger31.warn(`[MEDIA] File not found: ${agentUploadsPath}/${sanitizedFilename}`);
|
|
43851
44160
|
res.status(404).json({ error: "File not found" });
|
|
43852
44161
|
}
|
|
43853
44162
|
} else {
|
|
43854
|
-
|
|
44163
|
+
logger31.debug(`[MEDIA] Successfully served: ${sanitizedFilename}`);
|
|
43855
44164
|
}
|
|
43856
44165
|
});
|
|
43857
44166
|
});
|
|
@@ -43864,17 +44173,17 @@ class AgentServer {
|
|
|
43864
44173
|
return;
|
|
43865
44174
|
}
|
|
43866
44175
|
const sanitizedFilename = basename2(filename);
|
|
43867
|
-
const agentGeneratedPath =
|
|
43868
|
-
const filePath =
|
|
44176
|
+
const agentGeneratedPath = join5(generatedBasePath, agentId);
|
|
44177
|
+
const filePath = join5(agentGeneratedPath, sanitizedFilename);
|
|
43869
44178
|
if (!filePath.startsWith(agentGeneratedPath)) {
|
|
43870
44179
|
res.status(403).json({ error: "Access denied" });
|
|
43871
44180
|
return;
|
|
43872
44181
|
}
|
|
43873
|
-
if (!
|
|
44182
|
+
if (!existsSync5(filePath)) {
|
|
43874
44183
|
res.status(404).json({ error: "File not found" });
|
|
43875
44184
|
return;
|
|
43876
44185
|
}
|
|
43877
|
-
const absolutePath =
|
|
44186
|
+
const absolutePath = path9.resolve(filePath);
|
|
43878
44187
|
const options2 = {
|
|
43879
44188
|
dotfiles: "deny"
|
|
43880
44189
|
};
|
|
@@ -43883,7 +44192,7 @@ class AgentServer {
|
|
|
43883
44192
|
const ext2 = extname(filename).toLowerCase();
|
|
43884
44193
|
const mimeType = ext2 === ".png" ? "image/png" : ext2 === ".jpg" || ext2 === ".jpeg" ? "image/jpeg" : "application/octet-stream";
|
|
43885
44194
|
res.setHeader("Content-Type", mimeType);
|
|
43886
|
-
const stream =
|
|
44195
|
+
const stream = fs7.createReadStream(absolutePath);
|
|
43887
44196
|
stream.on("error", () => res.status(404).json({ error: "File not found" }));
|
|
43888
44197
|
stream.pipe(res);
|
|
43889
44198
|
}
|
|
@@ -43898,20 +44207,20 @@ class AgentServer {
|
|
|
43898
44207
|
return;
|
|
43899
44208
|
}
|
|
43900
44209
|
const sanitizedFilename = basename2(filename);
|
|
43901
|
-
const channelUploadsPath =
|
|
43902
|
-
const filePath =
|
|
44210
|
+
const channelUploadsPath = join5(uploadsBasePath, "channels", channelId);
|
|
44211
|
+
const filePath = join5(channelUploadsPath, sanitizedFilename);
|
|
43903
44212
|
if (!filePath.startsWith(channelUploadsPath)) {
|
|
43904
44213
|
res.status(403).json({ error: "Access denied" });
|
|
43905
44214
|
return;
|
|
43906
44215
|
}
|
|
43907
44216
|
res.sendFile(filePath, (err) => {
|
|
43908
44217
|
if (err) {
|
|
43909
|
-
|
|
44218
|
+
logger31.warn({ err, filePath }, `[STATIC] Channel media file not found: ${filePath}`);
|
|
43910
44219
|
if (!res.headersSent) {
|
|
43911
44220
|
res.status(404).json({ error: "File not found" });
|
|
43912
44221
|
}
|
|
43913
44222
|
} else {
|
|
43914
|
-
|
|
44223
|
+
logger31.debug(`[STATIC] Served channel media file: ${filePath}`);
|
|
43915
44224
|
}
|
|
43916
44225
|
});
|
|
43917
44226
|
});
|
|
@@ -43955,11 +44264,11 @@ class AgentServer {
|
|
|
43955
44264
|
if (this.isWebUIEnabled) {
|
|
43956
44265
|
const possiblePaths = [
|
|
43957
44266
|
this.clientPath,
|
|
43958
|
-
|
|
43959
|
-
|
|
44267
|
+
path9.resolve(__dirname3, "client"),
|
|
44268
|
+
path9.resolve(__dirname3, "../../client/dist"),
|
|
43960
44269
|
(() => {
|
|
43961
44270
|
try {
|
|
43962
|
-
return
|
|
44271
|
+
return path9.resolve(path9.dirname(__require.resolve("@elizaos/client/package.json")), "dist");
|
|
43963
44272
|
} catch {
|
|
43964
44273
|
return null;
|
|
43965
44274
|
}
|
|
@@ -43967,12 +44276,12 @@ class AgentServer {
|
|
|
43967
44276
|
(() => {
|
|
43968
44277
|
try {
|
|
43969
44278
|
if (process.argv[1]) {
|
|
43970
|
-
const serverPath =
|
|
43971
|
-
const possibleClientPath =
|
|
43972
|
-
if (
|
|
44279
|
+
const serverPath = path9.dirname(process.argv[1]);
|
|
44280
|
+
const possibleClientPath = path9.join(serverPath, "client");
|
|
44281
|
+
if (existsSync5(path9.join(possibleClientPath, "index.html"))) {
|
|
43973
44282
|
return possibleClientPath;
|
|
43974
44283
|
}
|
|
43975
|
-
if (
|
|
44284
|
+
if (existsSync5(path9.join(serverPath, "index.html"))) {
|
|
43976
44285
|
return serverPath;
|
|
43977
44286
|
}
|
|
43978
44287
|
}
|
|
@@ -43981,8 +44290,8 @@ class AgentServer {
|
|
|
43981
44290
|
})(),
|
|
43982
44291
|
(() => {
|
|
43983
44292
|
try {
|
|
43984
|
-
const bunGlobalPath =
|
|
43985
|
-
if (
|
|
44293
|
+
const bunGlobalPath = path9.join(os3.homedir(), ".bun/install/global/node_modules/@elizaos/server/dist/client");
|
|
44294
|
+
if (existsSync5(path9.join(bunGlobalPath, "index.html"))) {
|
|
43986
44295
|
return bunGlobalPath;
|
|
43987
44296
|
}
|
|
43988
44297
|
try {
|
|
@@ -43992,8 +44301,8 @@ class AgentServer {
|
|
|
43992
44301
|
});
|
|
43993
44302
|
if (proc.exitCode === 0 && proc.stdout) {
|
|
43994
44303
|
const npmRoot = new TextDecoder().decode(proc.stdout).trim();
|
|
43995
|
-
const globalServerPath =
|
|
43996
|
-
if (
|
|
44304
|
+
const globalServerPath = path9.join(npmRoot, "@elizaos/server/dist/client");
|
|
44305
|
+
if (existsSync5(path9.join(globalServerPath, "index.html"))) {
|
|
43997
44306
|
return globalServerPath;
|
|
43998
44307
|
}
|
|
43999
44308
|
}
|
|
@@ -44004,15 +44313,15 @@ class AgentServer {
|
|
|
44004
44313
|
...[
|
|
44005
44314
|
"/usr/local/lib/node_modules/@elizaos/server/dist/client",
|
|
44006
44315
|
"/usr/lib/node_modules/@elizaos/server/dist/client",
|
|
44007
|
-
|
|
44316
|
+
path9.join(os3.homedir(), ".npm-global/lib/node_modules/@elizaos/server/dist/client"),
|
|
44008
44317
|
(() => {
|
|
44009
44318
|
try {
|
|
44010
|
-
const nvmPath =
|
|
44011
|
-
if (
|
|
44012
|
-
const versions =
|
|
44319
|
+
const nvmPath = path9.join(os3.homedir(), ".nvm/versions/node");
|
|
44320
|
+
if (existsSync5(nvmPath)) {
|
|
44321
|
+
const versions = fs7.readdirSync(nvmPath);
|
|
44013
44322
|
for (const version of versions) {
|
|
44014
|
-
const cliPath =
|
|
44015
|
-
if (
|
|
44323
|
+
const cliPath = path9.join(nvmPath, version, "lib/node_modules/@elizaos/server/dist/client");
|
|
44324
|
+
if (existsSync5(path9.join(cliPath, "index.html"))) {
|
|
44016
44325
|
return cliPath;
|
|
44017
44326
|
}
|
|
44018
44327
|
}
|
|
@@ -44022,37 +44331,37 @@ class AgentServer {
|
|
|
44022
44331
|
})()
|
|
44023
44332
|
].filter(Boolean)
|
|
44024
44333
|
].filter(Boolean);
|
|
44025
|
-
|
|
44026
|
-
|
|
44027
|
-
|
|
44334
|
+
logger31.debug(`[STATIC] process.argv[0]: ${process.argv[0]}`);
|
|
44335
|
+
logger31.debug(`[STATIC] process.argv[1]: ${process.argv[1]}`);
|
|
44336
|
+
logger31.debug(`[STATIC] __dirname: ${__dirname3}`);
|
|
44028
44337
|
for (const possiblePath of possiblePaths) {
|
|
44029
|
-
if (possiblePath &&
|
|
44338
|
+
if (possiblePath && existsSync5(path9.join(possiblePath, "index.html"))) {
|
|
44030
44339
|
clientPath = possiblePath;
|
|
44031
|
-
|
|
44340
|
+
logger31.info(`[STATIC] Found client files at: ${clientPath}`);
|
|
44032
44341
|
break;
|
|
44033
44342
|
}
|
|
44034
44343
|
}
|
|
44035
44344
|
if (clientPath) {
|
|
44036
44345
|
this.clientPath = clientPath;
|
|
44037
44346
|
this.app.use(express33.static(clientPath, staticOptions));
|
|
44038
|
-
|
|
44347
|
+
logger31.info(`[STATIC] Serving static files from: ${clientPath}`);
|
|
44039
44348
|
} else {
|
|
44040
|
-
|
|
44349
|
+
logger31.warn("[STATIC] Client dist path not found. Searched locations:");
|
|
44041
44350
|
possiblePaths.forEach((p) => {
|
|
44042
44351
|
if (p)
|
|
44043
|
-
|
|
44352
|
+
logger31.warn(`[STATIC] - ${p}`);
|
|
44044
44353
|
});
|
|
44045
|
-
|
|
44046
|
-
|
|
44047
|
-
|
|
44354
|
+
logger31.warn("[STATIC] The web UI will not be available.");
|
|
44355
|
+
logger31.warn("[STATIC] To fix this, ensure the client is built: cd packages/client && bun run build");
|
|
44356
|
+
logger31.warn("[STATIC] Then rebuild the server: cd packages/server && bun run build");
|
|
44048
44357
|
}
|
|
44049
44358
|
}
|
|
44050
|
-
const pluginRouteHandler = createPluginRouteHandler(this.
|
|
44359
|
+
const pluginRouteHandler = createPluginRouteHandler(this.elizaOS);
|
|
44051
44360
|
this.app.use(pluginRouteHandler);
|
|
44052
|
-
const apiRouter = createApiRouter(this.
|
|
44361
|
+
const apiRouter = createApiRouter(this.elizaOS, this);
|
|
44053
44362
|
this.app.use("/api", (req, _res, next) => {
|
|
44054
44363
|
if (req.path !== "/ping") {
|
|
44055
|
-
|
|
44364
|
+
logger31.debug(`API request: ${req.method} ${req.path}`);
|
|
44056
44365
|
}
|
|
44057
44366
|
next();
|
|
44058
44367
|
}, apiRouter, (err, req, res, _next) => {
|
|
@@ -44067,7 +44376,7 @@ class AgentServer {
|
|
|
44067
44376
|
return scope;
|
|
44068
44377
|
});
|
|
44069
44378
|
}
|
|
44070
|
-
|
|
44379
|
+
logger31.error({ err }, `API error: ${req.method} ${req.path}`);
|
|
44071
44380
|
res.status(500).json({
|
|
44072
44381
|
success: false,
|
|
44073
44382
|
error: {
|
|
@@ -44115,29 +44424,29 @@ class AgentServer {
|
|
|
44115
44424
|
}
|
|
44116
44425
|
const resolvedClientPath = clientPath || this.clientPath;
|
|
44117
44426
|
if (resolvedClientPath) {
|
|
44118
|
-
const indexFilePath =
|
|
44119
|
-
if (!
|
|
44120
|
-
|
|
44121
|
-
|
|
44427
|
+
const indexFilePath = path9.join(resolvedClientPath, "index.html");
|
|
44428
|
+
if (!existsSync5(indexFilePath)) {
|
|
44429
|
+
logger31.error(`[STATIC] index.html not found at expected path: ${indexFilePath}`);
|
|
44430
|
+
logger31.error(`[STATIC] Client path was: ${resolvedClientPath}`);
|
|
44122
44431
|
res.status(404).send("Client application not found");
|
|
44123
44432
|
return;
|
|
44124
44433
|
}
|
|
44125
44434
|
res.sendFile("index.html", { root: resolvedClientPath }, (err) => {
|
|
44126
44435
|
if (err) {
|
|
44127
|
-
|
|
44128
|
-
|
|
44129
|
-
|
|
44130
|
-
|
|
44436
|
+
logger31.warn(`[STATIC] Failed to serve index.html: ${err.message}`);
|
|
44437
|
+
logger31.warn(`[STATIC] Attempted root: ${resolvedClientPath}`);
|
|
44438
|
+
logger31.warn(`[STATIC] Full path was: ${indexFilePath}`);
|
|
44439
|
+
logger31.warn(`[STATIC] Error code: ${err.code || "unknown"}`);
|
|
44131
44440
|
if (!res.headersSent) {
|
|
44132
44441
|
res.status(404).send("Client application not found");
|
|
44133
44442
|
}
|
|
44134
44443
|
} else {
|
|
44135
|
-
|
|
44444
|
+
logger31.debug(`[STATIC] Successfully served index.html for route: ${req.path}`);
|
|
44136
44445
|
}
|
|
44137
44446
|
});
|
|
44138
44447
|
} else {
|
|
44139
|
-
|
|
44140
|
-
|
|
44448
|
+
logger31.warn("[STATIC] Client dist path not found in SPA fallback");
|
|
44449
|
+
logger31.warn("[STATIC] Neither local nor instance clientPath variables are set");
|
|
44141
44450
|
res.status(404).send("Client application not found");
|
|
44142
44451
|
}
|
|
44143
44452
|
});
|
|
@@ -44147,10 +44456,10 @@ class AgentServer {
|
|
|
44147
44456
|
});
|
|
44148
44457
|
}
|
|
44149
44458
|
this.server = http4.createServer(this.app);
|
|
44150
|
-
this.socketIO = setupSocketIO(this.server, this.
|
|
44151
|
-
|
|
44459
|
+
this.socketIO = setupSocketIO(this.server, this.elizaOS, this);
|
|
44460
|
+
logger31.success("AgentServer HTTP server and Socket.IO initialized");
|
|
44152
44461
|
} catch (error2) {
|
|
44153
|
-
|
|
44462
|
+
logger31.error({ error: error2 }, "Failed to complete server initialization:");
|
|
44154
44463
|
throw error2;
|
|
44155
44464
|
}
|
|
44156
44465
|
}
|
|
@@ -44165,63 +44474,64 @@ class AgentServer {
|
|
|
44165
44474
|
if (!runtime.character) {
|
|
44166
44475
|
throw new Error("Runtime missing character configuration");
|
|
44167
44476
|
}
|
|
44168
|
-
|
|
44169
|
-
logger30.debug(`Agent ${runtime.character.name} (${runtime.agentId}) added to agents map`);
|
|
44477
|
+
logger31.debug(`Agent ${runtime.character.name} (${runtime.agentId}) registered`);
|
|
44170
44478
|
try {
|
|
44171
44479
|
if (messageBusConnectorPlugin) {
|
|
44172
44480
|
await runtime.registerPlugin(messageBusConnectorPlugin);
|
|
44173
|
-
|
|
44481
|
+
logger31.info(`[AgentServer] Automatically registered MessageBusConnector for agent ${runtime.character.name}`);
|
|
44174
44482
|
} else {
|
|
44175
|
-
|
|
44483
|
+
logger31.error(`[AgentServer] CRITICAL: MessageBusConnector plugin definition not found.`);
|
|
44176
44484
|
}
|
|
44177
44485
|
} catch (e) {
|
|
44178
|
-
|
|
44486
|
+
logger31.error({ error: e }, `[AgentServer] CRITICAL: Failed to register MessageBusConnector for agent ${runtime.character.name}`);
|
|
44179
44487
|
}
|
|
44180
44488
|
const teePlugin = runtime.plugins.find((p) => p.name === "phala-tee-plugin");
|
|
44181
44489
|
if (teePlugin) {
|
|
44182
|
-
|
|
44490
|
+
logger31.debug(`Found TEE plugin for agent ${runtime.agentId}`);
|
|
44183
44491
|
if (teePlugin.providers) {
|
|
44184
44492
|
for (const provider of teePlugin.providers) {
|
|
44185
44493
|
runtime.registerProvider(provider);
|
|
44186
|
-
|
|
44494
|
+
logger31.debug(`Registered TEE provider: ${provider.name}`);
|
|
44187
44495
|
}
|
|
44188
44496
|
}
|
|
44189
44497
|
if (teePlugin.actions) {
|
|
44190
44498
|
for (const action of teePlugin.actions) {
|
|
44191
44499
|
runtime.registerAction(action);
|
|
44192
|
-
|
|
44500
|
+
logger31.debug(`Registered TEE action: ${action.name}`);
|
|
44193
44501
|
}
|
|
44194
44502
|
}
|
|
44195
44503
|
}
|
|
44196
|
-
|
|
44504
|
+
logger31.success(`Successfully registered agent ${runtime.character.name} (${runtime.agentId}) with core services.`);
|
|
44197
44505
|
await this.addAgentToServer(DEFAULT_SERVER_ID6, runtime.agentId);
|
|
44198
|
-
|
|
44506
|
+
logger31.info(`[AgentServer] Auto-associated agent ${runtime.character.name} with server ID: ${DEFAULT_SERVER_ID6}`);
|
|
44199
44507
|
} catch (error2) {
|
|
44200
|
-
|
|
44508
|
+
logger31.error({ error: error2 }, "Failed to register agent:");
|
|
44201
44509
|
throw error2;
|
|
44202
44510
|
}
|
|
44203
44511
|
}
|
|
44204
|
-
unregisterAgent(agentId) {
|
|
44512
|
+
async unregisterAgent(agentId) {
|
|
44205
44513
|
if (!agentId) {
|
|
44206
|
-
|
|
44514
|
+
logger31.warn("[AGENT UNREGISTER] Attempted to unregister undefined or invalid agent runtime");
|
|
44207
44515
|
return;
|
|
44208
44516
|
}
|
|
44209
44517
|
try {
|
|
44210
|
-
const agent = this.
|
|
44518
|
+
const agent = this.elizaOS?.getAgent(agentId);
|
|
44211
44519
|
if (agent) {
|
|
44212
44520
|
try {
|
|
44213
44521
|
agent.stop().catch((stopError) => {
|
|
44214
|
-
|
|
44522
|
+
logger31.error({ error: stopError, agentId }, `[AGENT UNREGISTER] Error stopping agent services for ${agentId}:`);
|
|
44215
44523
|
});
|
|
44216
|
-
|
|
44524
|
+
logger31.debug(`[AGENT UNREGISTER] Stopping services for agent ${agentId}`);
|
|
44217
44525
|
} catch (stopError) {
|
|
44218
|
-
|
|
44526
|
+
logger31.error({ error: stopError, agentId }, `[AGENT UNREGISTER] Error initiating stop for agent ${agentId}:`);
|
|
44219
44527
|
}
|
|
44220
44528
|
}
|
|
44221
|
-
this.
|
|
44222
|
-
|
|
44529
|
+
if (this.elizaOS) {
|
|
44530
|
+
await this.elizaOS.deleteAgents([agentId]);
|
|
44531
|
+
}
|
|
44532
|
+
logger31.debug(`Agent ${agentId} unregistered`);
|
|
44223
44533
|
} catch (error2) {
|
|
44224
|
-
|
|
44534
|
+
logger31.error({ error: error2, agentId }, `Error removing agent ${agentId}:`);
|
|
44225
44535
|
}
|
|
44226
44536
|
}
|
|
44227
44537
|
registerMiddleware(middleware2) {
|
|
@@ -44233,9 +44543,9 @@ class AgentServer {
|
|
|
44233
44543
|
if (!port || typeof port !== "number") {
|
|
44234
44544
|
throw new Error(`Invalid port number: ${port}`);
|
|
44235
44545
|
}
|
|
44236
|
-
|
|
44237
|
-
|
|
44238
|
-
|
|
44546
|
+
logger31.debug(`Starting server on port ${port}...`);
|
|
44547
|
+
logger31.debug(`Current agents count: ${this.elizaOS?.getAgents().length || 0}`);
|
|
44548
|
+
logger31.debug(`Environment: ${"development"}`);
|
|
44239
44549
|
const host = process.env.SERVER_HOST || "0.0.0.0";
|
|
44240
44550
|
this.server.listen(port, host, () => {
|
|
44241
44551
|
if (this.isWebUIEnabled && false) {} else if (!this.isWebUIEnabled) {
|
|
@@ -44248,25 +44558,26 @@ class AgentServer {
|
|
|
44248
44558
|
` + ` \x1B[1m${baseUrl}/api/messaging\x1B[22m\x1B[0m`);
|
|
44249
44559
|
}
|
|
44250
44560
|
console.log(`AgentServer is listening on port ${port}`);
|
|
44251
|
-
|
|
44252
|
-
|
|
44253
|
-
|
|
44254
|
-
|
|
44561
|
+
logger31.success(`REST API bound to ${host}:${port}. If running locally, access it at http://localhost:${port}.`);
|
|
44562
|
+
const agents = this.elizaOS?.getAgents() || [];
|
|
44563
|
+
logger31.debug(`Active agents: ${agents.length}`);
|
|
44564
|
+
agents.forEach((agent) => {
|
|
44565
|
+
logger31.debug(`- Agent ${agent.agentId}: ${agent.character.name}`);
|
|
44255
44566
|
});
|
|
44256
44567
|
resolve2();
|
|
44257
44568
|
}).on("error", (error2) => {
|
|
44258
|
-
|
|
44569
|
+
logger31.error({ error: error2, host, port }, `Failed to bind server to ${host}:${port}:`);
|
|
44259
44570
|
if (error2.code === "EADDRINUSE") {
|
|
44260
|
-
|
|
44571
|
+
logger31.error(`Port ${port} is already in use. Please try a different port or stop the process using that port.`);
|
|
44261
44572
|
} else if (error2.code === "EACCES") {
|
|
44262
|
-
|
|
44573
|
+
logger31.error(`Permission denied to bind to port ${port}. Try using a port above 1024 or running with appropriate permissions.`);
|
|
44263
44574
|
} else if (error2.code === "EADDRNOTAVAIL") {
|
|
44264
|
-
|
|
44575
|
+
logger31.error(`Cannot bind to ${host}:${port} - address not available. Check if the host address is correct.`);
|
|
44265
44576
|
}
|
|
44266
44577
|
reject(error2);
|
|
44267
44578
|
});
|
|
44268
44579
|
} catch (error2) {
|
|
44269
|
-
|
|
44580
|
+
logger31.error({ error: error2 }, "Failed to start server:");
|
|
44270
44581
|
reject(error2);
|
|
44271
44582
|
}
|
|
44272
44583
|
});
|
|
@@ -44274,7 +44585,7 @@ class AgentServer {
|
|
|
44274
44585
|
async stop() {
|
|
44275
44586
|
if (this.server) {
|
|
44276
44587
|
this.server.close(() => {
|
|
44277
|
-
|
|
44588
|
+
logger31.success("Server stopped");
|
|
44278
44589
|
});
|
|
44279
44590
|
}
|
|
44280
44591
|
}
|
|
@@ -44321,7 +44632,7 @@ class AgentServer {
|
|
|
44321
44632
|
for (const message of messages) {
|
|
44322
44633
|
await this.database.deleteMessage(message.id);
|
|
44323
44634
|
}
|
|
44324
|
-
|
|
44635
|
+
logger31.info(`[AgentServer] Cleared all messages for central channel: ${channelId}`);
|
|
44325
44636
|
}
|
|
44326
44637
|
async findOrCreateCentralDmChannel(user1Id, user2Id, messageServerId) {
|
|
44327
44638
|
return this.database.findOrCreateDmChannel(user1Id, user2Id, messageServerId);
|
|
@@ -44344,7 +44655,7 @@ class AgentServer {
|
|
|
44344
44655
|
metadata: createdMessage.metadata
|
|
44345
44656
|
};
|
|
44346
44657
|
bus_default.emit("new_message", messageForBus);
|
|
44347
|
-
|
|
44658
|
+
logger31.info(`[AgentServer] Published message ${createdMessage.id} to internal message bus`);
|
|
44348
44659
|
}
|
|
44349
44660
|
return createdMessage;
|
|
44350
44661
|
}
|
|
@@ -44355,7 +44666,7 @@ class AgentServer {
|
|
|
44355
44666
|
return this.database.updateMessage(messageId, patch);
|
|
44356
44667
|
}
|
|
44357
44668
|
async removeParticipantFromChannel() {
|
|
44358
|
-
|
|
44669
|
+
logger31.warn(`[AgentServer] Remove participant operation not directly supported in database adapter`);
|
|
44359
44670
|
}
|
|
44360
44671
|
async addAgentToServer(serverId, agentId) {
|
|
44361
44672
|
const server = await this.getServerById(serverId);
|
|
@@ -44383,31 +44694,32 @@ class AgentServer {
|
|
|
44383
44694
|
}
|
|
44384
44695
|
registerSignalHandlers() {
|
|
44385
44696
|
const gracefulShutdown = async () => {
|
|
44386
|
-
|
|
44387
|
-
|
|
44388
|
-
|
|
44697
|
+
logger31.info("Received shutdown signal, initiating graceful shutdown...");
|
|
44698
|
+
logger31.debug("Stopping all agents...");
|
|
44699
|
+
const agents = this.elizaOS?.getAgents() || [];
|
|
44700
|
+
for (const agent of agents) {
|
|
44389
44701
|
try {
|
|
44390
44702
|
await agent.stop();
|
|
44391
|
-
|
|
44703
|
+
logger31.debug(`Stopped agent ${agent.agentId}`);
|
|
44392
44704
|
} catch (error2) {
|
|
44393
|
-
|
|
44705
|
+
logger31.error({ error: error2, agentId: agent.agentId }, `Error stopping agent ${agent.agentId}:`);
|
|
44394
44706
|
}
|
|
44395
44707
|
}
|
|
44396
44708
|
if (this.database) {
|
|
44397
44709
|
try {
|
|
44398
44710
|
await this.database.close();
|
|
44399
|
-
|
|
44711
|
+
logger31.info("Database closed.");
|
|
44400
44712
|
} catch (error2) {
|
|
44401
|
-
|
|
44713
|
+
logger31.error({ error: error2 }, "Error closing database:");
|
|
44402
44714
|
}
|
|
44403
44715
|
}
|
|
44404
44716
|
if (this.server) {
|
|
44405
44717
|
this.server.close(() => {
|
|
44406
|
-
|
|
44718
|
+
logger31.success("Server closed successfully");
|
|
44407
44719
|
process.exit(0);
|
|
44408
44720
|
});
|
|
44409
44721
|
setTimeout(() => {
|
|
44410
|
-
|
|
44722
|
+
logger31.error("Could not close connections in time, forcing shutdown");
|
|
44411
44723
|
process.exit(1);
|
|
44412
44724
|
}, 5000);
|
|
44413
44725
|
} else {
|
|
@@ -44416,7 +44728,7 @@ class AgentServer {
|
|
|
44416
44728
|
};
|
|
44417
44729
|
process.on("SIGTERM", gracefulShutdown);
|
|
44418
44730
|
process.on("SIGINT", gracefulShutdown);
|
|
44419
|
-
|
|
44731
|
+
logger31.debug("Shutdown handlers registered");
|
|
44420
44732
|
}
|
|
44421
44733
|
}
|
|
44422
44734
|
export {
|
|
@@ -44430,5 +44742,8 @@ export {
|
|
|
44430
44742
|
isWebUIEnabled,
|
|
44431
44743
|
hasValidRemoteUrls,
|
|
44432
44744
|
expandTildePath,
|
|
44745
|
+
PluginLoader,
|
|
44746
|
+
ElizaOS3 as ElizaOS,
|
|
44747
|
+
ConfigManager,
|
|
44433
44748
|
AgentServer
|
|
44434
44749
|
};
|