@elizaos/server 1.0.11 → 1.0.12
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.js +326 -311
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -400,7 +400,7 @@ import { match } from "path-to-regexp";
|
|
|
400
400
|
import { Server as SocketIOServer } from "socket.io";
|
|
401
401
|
|
|
402
402
|
// src/api/agents/index.ts
|
|
403
|
-
import
|
|
403
|
+
import express8 from "express";
|
|
404
404
|
|
|
405
405
|
// src/api/agents/crud.ts
|
|
406
406
|
import {
|
|
@@ -1186,24 +1186,170 @@ function createAgentMemoryRouter(agents) {
|
|
|
1186
1186
|
return router;
|
|
1187
1187
|
}
|
|
1188
1188
|
|
|
1189
|
+
// src/api/memory/rooms.ts
|
|
1190
|
+
import { validateUuid as validateUuid7, logger as logger7, createUniqueUuid as createUniqueUuid3, ChannelType } from "@elizaos/core";
|
|
1191
|
+
import express7 from "express";
|
|
1192
|
+
function createRoomManagementRouter(agents) {
|
|
1193
|
+
const router = express7.Router();
|
|
1194
|
+
router.post("/:agentId/rooms", async (req, res) => {
|
|
1195
|
+
const agentId = validateUuid7(req.params.agentId);
|
|
1196
|
+
if (!agentId) {
|
|
1197
|
+
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
1198
|
+
}
|
|
1199
|
+
const runtime = agents.get(agentId);
|
|
1200
|
+
if (!runtime) {
|
|
1201
|
+
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
1202
|
+
}
|
|
1203
|
+
try {
|
|
1204
|
+
const { name, type = ChannelType.DM, source = "client", worldId, metadata } = req.body;
|
|
1205
|
+
if (!name) {
|
|
1206
|
+
return sendError(res, 400, "MISSING_PARAM", "Room name is required");
|
|
1207
|
+
}
|
|
1208
|
+
const roomId = createUniqueUuid3(runtime, `room-${Date.now()}`);
|
|
1209
|
+
const serverId = req.body.serverId || `server-${Date.now()}`;
|
|
1210
|
+
let resolvedWorldId = worldId;
|
|
1211
|
+
if (!resolvedWorldId) {
|
|
1212
|
+
const worldName = `World for ${name}`;
|
|
1213
|
+
resolvedWorldId = createUniqueUuid3(runtime, `world-${Date.now()}`);
|
|
1214
|
+
await runtime.ensureWorldExists({
|
|
1215
|
+
id: resolvedWorldId,
|
|
1216
|
+
name: worldName,
|
|
1217
|
+
agentId: runtime.agentId,
|
|
1218
|
+
serverId,
|
|
1219
|
+
metadata
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
await runtime.ensureRoomExists({
|
|
1223
|
+
id: roomId,
|
|
1224
|
+
name,
|
|
1225
|
+
source,
|
|
1226
|
+
type,
|
|
1227
|
+
channelId: roomId,
|
|
1228
|
+
serverId,
|
|
1229
|
+
worldId: resolvedWorldId,
|
|
1230
|
+
metadata
|
|
1231
|
+
});
|
|
1232
|
+
await runtime.addParticipant(runtime.agentId, roomId);
|
|
1233
|
+
await runtime.ensureParticipantInRoom(runtime.agentId, roomId);
|
|
1234
|
+
await runtime.setParticipantUserState(roomId, runtime.agentId, "FOLLOWED");
|
|
1235
|
+
sendSuccess(
|
|
1236
|
+
res,
|
|
1237
|
+
{
|
|
1238
|
+
id: roomId,
|
|
1239
|
+
name,
|
|
1240
|
+
agentId,
|
|
1241
|
+
createdAt: Date.now(),
|
|
1242
|
+
source,
|
|
1243
|
+
type,
|
|
1244
|
+
worldId: resolvedWorldId,
|
|
1245
|
+
serverId,
|
|
1246
|
+
metadata
|
|
1247
|
+
},
|
|
1248
|
+
201
|
|
1249
|
+
);
|
|
1250
|
+
} catch (error) {
|
|
1251
|
+
logger7.error(`[ROOM CREATE] Error creating room for agent ${agentId}:`, error);
|
|
1252
|
+
sendError(
|
|
1253
|
+
res,
|
|
1254
|
+
500,
|
|
1255
|
+
"CREATE_ERROR",
|
|
1256
|
+
"Failed to create room",
|
|
1257
|
+
error instanceof Error ? error.message : String(error)
|
|
1258
|
+
);
|
|
1259
|
+
}
|
|
1260
|
+
});
|
|
1261
|
+
router.get("/:agentId/rooms", async (req, res) => {
|
|
1262
|
+
const agentId = validateUuid7(req.params.agentId);
|
|
1263
|
+
if (!agentId) {
|
|
1264
|
+
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
1265
|
+
}
|
|
1266
|
+
const runtime = agents.get(agentId);
|
|
1267
|
+
if (!runtime) {
|
|
1268
|
+
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
1269
|
+
}
|
|
1270
|
+
try {
|
|
1271
|
+
const worlds = await runtime.getAllWorlds();
|
|
1272
|
+
const participantRoomIds = await runtime.getRoomsForParticipant(agentId);
|
|
1273
|
+
const agentRooms = [];
|
|
1274
|
+
for (const world of worlds) {
|
|
1275
|
+
const worldRooms = await runtime.getRooms(world.id);
|
|
1276
|
+
for (const room of worldRooms) {
|
|
1277
|
+
if (participantRoomIds.includes(room.id)) {
|
|
1278
|
+
agentRooms.push({
|
|
1279
|
+
...room
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
sendSuccess(res, { rooms: agentRooms });
|
|
1285
|
+
} catch (error) {
|
|
1286
|
+
logger7.error(`[ROOMS LIST] Error retrieving rooms for agent ${agentId}:`, error);
|
|
1287
|
+
sendError(
|
|
1288
|
+
res,
|
|
1289
|
+
500,
|
|
1290
|
+
"RETRIEVAL_ERROR",
|
|
1291
|
+
"Failed to retrieve agent rooms",
|
|
1292
|
+
error instanceof Error ? error.message : String(error)
|
|
1293
|
+
);
|
|
1294
|
+
}
|
|
1295
|
+
});
|
|
1296
|
+
router.get("/:agentId/rooms/:roomId", async (req, res) => {
|
|
1297
|
+
const agentId = validateUuid7(req.params.agentId);
|
|
1298
|
+
const roomId = validateUuid7(req.params.roomId);
|
|
1299
|
+
if (!agentId || !roomId) {
|
|
1300
|
+
return sendError(res, 400, "INVALID_ID", "Invalid agent ID or room ID format");
|
|
1301
|
+
}
|
|
1302
|
+
const runtime = agents.get(agentId);
|
|
1303
|
+
if (!runtime) {
|
|
1304
|
+
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
1305
|
+
}
|
|
1306
|
+
try {
|
|
1307
|
+
const room = await runtime.getRoom(roomId);
|
|
1308
|
+
if (!room) {
|
|
1309
|
+
return sendError(res, 404, "NOT_FOUND", "Room not found");
|
|
1310
|
+
}
|
|
1311
|
+
let worldName;
|
|
1312
|
+
if (room.worldId) {
|
|
1313
|
+
const world = await runtime.getWorld(room.worldId);
|
|
1314
|
+
worldName = world?.name;
|
|
1315
|
+
}
|
|
1316
|
+
sendSuccess(res, {
|
|
1317
|
+
...room,
|
|
1318
|
+
...worldName && { worldName }
|
|
1319
|
+
});
|
|
1320
|
+
} catch (error) {
|
|
1321
|
+
logger7.error(`[ROOM DETAILS] Error retrieving room ${roomId} for agent ${agentId}:`, error);
|
|
1322
|
+
sendError(
|
|
1323
|
+
res,
|
|
1324
|
+
500,
|
|
1325
|
+
"RETRIEVAL_ERROR",
|
|
1326
|
+
"Failed to retrieve room details",
|
|
1327
|
+
error instanceof Error ? error.message : String(error)
|
|
1328
|
+
);
|
|
1329
|
+
}
|
|
1330
|
+
});
|
|
1331
|
+
return router;
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1189
1334
|
// src/api/agents/index.ts
|
|
1190
1335
|
function agentsRouter(agents, serverInstance) {
|
|
1191
|
-
const router =
|
|
1336
|
+
const router = express8.Router();
|
|
1192
1337
|
router.use("/", createAgentCrudRouter(agents, serverInstance));
|
|
1193
1338
|
router.use("/", createAgentLifecycleRouter(agents, serverInstance));
|
|
1194
1339
|
router.use("/", createAgentWorldsRouter(agents));
|
|
1195
1340
|
router.use("/", createAgentPanelsRouter(agents));
|
|
1196
1341
|
router.use("/", createAgentLogsRouter(agents));
|
|
1197
|
-
router.use("/", createAgentMemoryRouter(agents
|
|
1342
|
+
router.use("/", createAgentMemoryRouter(agents));
|
|
1343
|
+
router.use("/", createRoomManagementRouter(agents));
|
|
1198
1344
|
return router;
|
|
1199
1345
|
}
|
|
1200
1346
|
|
|
1201
1347
|
// src/api/messaging/index.ts
|
|
1202
|
-
import
|
|
1348
|
+
import express12 from "express";
|
|
1203
1349
|
|
|
1204
1350
|
// src/api/messaging/core.ts
|
|
1205
|
-
import { logger as
|
|
1206
|
-
import
|
|
1351
|
+
import { logger as logger8, validateUuid as validateUuid8 } from "@elizaos/core";
|
|
1352
|
+
import express9 from "express";
|
|
1207
1353
|
|
|
1208
1354
|
// src/bus.ts
|
|
1209
1355
|
import EventEmitter from "events";
|
|
@@ -1216,7 +1362,7 @@ var bus_default = internalMessageBus;
|
|
|
1216
1362
|
// src/api/messaging/core.ts
|
|
1217
1363
|
var DEFAULT_SERVER_ID = "00000000-0000-0000-0000-000000000000";
|
|
1218
1364
|
function createMessagingCoreRouter(serverInstance) {
|
|
1219
|
-
const router =
|
|
1365
|
+
const router = express9.Router();
|
|
1220
1366
|
router.post("/submit", async (req, res) => {
|
|
1221
1367
|
const {
|
|
1222
1368
|
channel_id,
|
|
@@ -1232,14 +1378,14 @@ function createMessagingCoreRouter(serverInstance) {
|
|
|
1232
1378
|
metadata
|
|
1233
1379
|
// Should include agent_name if author_id is agent's runtime.agentId
|
|
1234
1380
|
} = req.body;
|
|
1235
|
-
const isValidServerId = server_id === DEFAULT_SERVER_ID ||
|
|
1236
|
-
if (!
|
|
1381
|
+
const isValidServerId = server_id === DEFAULT_SERVER_ID || validateUuid8(server_id);
|
|
1382
|
+
if (!validateUuid8(channel_id) || !validateUuid8(author_id) || !content || !isValidServerId || !source_type || !raw_message) {
|
|
1237
1383
|
return res.status(400).json({
|
|
1238
1384
|
success: false,
|
|
1239
1385
|
error: "Missing required fields: channel_id, server_id, author_id, content, source_type, raw_message"
|
|
1240
1386
|
});
|
|
1241
1387
|
}
|
|
1242
|
-
if (in_reply_to_message_id && !
|
|
1388
|
+
if (in_reply_to_message_id && !validateUuid8(in_reply_to_message_id)) {
|
|
1243
1389
|
return res.status(400).json({
|
|
1244
1390
|
success: false,
|
|
1245
1391
|
error: "Invalid in_reply_to_message_id format"
|
|
@@ -1247,12 +1393,12 @@ function createMessagingCoreRouter(serverInstance) {
|
|
|
1247
1393
|
}
|
|
1248
1394
|
try {
|
|
1249
1395
|
const newRootMessageData = {
|
|
1250
|
-
channelId:
|
|
1251
|
-
authorId:
|
|
1396
|
+
channelId: validateUuid8(channel_id),
|
|
1397
|
+
authorId: validateUuid8(author_id),
|
|
1252
1398
|
content,
|
|
1253
1399
|
rawMessage: raw_message,
|
|
1254
1400
|
sourceType: source_type || "agent_response",
|
|
1255
|
-
inReplyToRootMessageId: in_reply_to_message_id ?
|
|
1401
|
+
inReplyToRootMessageId: in_reply_to_message_id ? validateUuid8(in_reply_to_message_id) || void 0 : void 0,
|
|
1256
1402
|
metadata
|
|
1257
1403
|
};
|
|
1258
1404
|
const createdMessage = await serverInstance.createMessage(newRootMessageData);
|
|
@@ -1277,13 +1423,13 @@ function createMessagingCoreRouter(serverInstance) {
|
|
|
1277
1423
|
}
|
|
1278
1424
|
res.status(201).json({ success: true, data: createdMessage });
|
|
1279
1425
|
} catch (error) {
|
|
1280
|
-
|
|
1426
|
+
logger8.error("[Messages Router /submit] Error submitting agent message:", error);
|
|
1281
1427
|
res.status(500).json({ success: false, error: "Failed to submit agent message" });
|
|
1282
1428
|
}
|
|
1283
1429
|
});
|
|
1284
1430
|
router.post("/complete", async (req, res) => {
|
|
1285
1431
|
const { channel_id, server_id } = req.body;
|
|
1286
|
-
if (!
|
|
1432
|
+
if (!validateUuid8(channel_id) || !validateUuid8(server_id)) {
|
|
1287
1433
|
return res.status(400).json({
|
|
1288
1434
|
success: false,
|
|
1289
1435
|
error: "Missing or invalid fields: channel_id, server_id"
|
|
@@ -1298,7 +1444,7 @@ function createMessagingCoreRouter(serverInstance) {
|
|
|
1298
1444
|
}
|
|
1299
1445
|
res.status(200).json({ success: true, message: "Completion event emitted" });
|
|
1300
1446
|
} catch (error) {
|
|
1301
|
-
|
|
1447
|
+
logger8.error("[Messages Router /notify-complete] Error notifying message complete:", error);
|
|
1302
1448
|
res.status(500).json({ success: false, error: "Failed to notify message completion" });
|
|
1303
1449
|
}
|
|
1304
1450
|
});
|
|
@@ -1317,7 +1463,7 @@ function createMessagingCoreRouter(serverInstance) {
|
|
|
1317
1463
|
sourceId: messagePayload.source_id,
|
|
1318
1464
|
// Original platform message ID
|
|
1319
1465
|
sourceType: messagePayload.source_type,
|
|
1320
|
-
inReplyToRootMessageId: messagePayload.in_reply_to_message_id ?
|
|
1466
|
+
inReplyToRootMessageId: messagePayload.in_reply_to_message_id ? validateUuid8(messagePayload.in_reply_to_message_id) || void 0 : void 0,
|
|
1321
1467
|
metadata: messagePayload.metadata
|
|
1322
1468
|
};
|
|
1323
1469
|
const createdRootMessage = await serverInstance.createMessage(messageToCreate);
|
|
@@ -1339,7 +1485,7 @@ function createMessagingCoreRouter(serverInstance) {
|
|
|
1339
1485
|
metadata: createdRootMessage.metadata
|
|
1340
1486
|
};
|
|
1341
1487
|
bus_default.emit("new_message", messageForBus);
|
|
1342
|
-
|
|
1488
|
+
logger8.info(
|
|
1343
1489
|
"[Messages Router /ingest-external] Published to internal message bus:",
|
|
1344
1490
|
createdRootMessage.id
|
|
1345
1491
|
);
|
|
@@ -1362,7 +1508,7 @@ function createMessagingCoreRouter(serverInstance) {
|
|
|
1362
1508
|
data: { messageId: createdRootMessage.id }
|
|
1363
1509
|
});
|
|
1364
1510
|
} catch (error) {
|
|
1365
|
-
|
|
1511
|
+
logger8.error("[Messages Router /ingest-external] Error ingesting external message:", error);
|
|
1366
1512
|
res.status(500).json({ success: false, error: "Failed to ingest message" });
|
|
1367
1513
|
}
|
|
1368
1514
|
});
|
|
@@ -1370,17 +1516,17 @@ function createMessagingCoreRouter(serverInstance) {
|
|
|
1370
1516
|
}
|
|
1371
1517
|
|
|
1372
1518
|
// src/api/messaging/servers.ts
|
|
1373
|
-
import { logger as
|
|
1374
|
-
import
|
|
1519
|
+
import { logger as logger9, validateUuid as validateUuid9 } from "@elizaos/core";
|
|
1520
|
+
import express10 from "express";
|
|
1375
1521
|
var DEFAULT_SERVER_ID2 = "00000000-0000-0000-0000-000000000000";
|
|
1376
1522
|
function createServersRouter(serverInstance) {
|
|
1377
|
-
const router =
|
|
1523
|
+
const router = express10.Router();
|
|
1378
1524
|
router.get("/central-servers", async (_req, res) => {
|
|
1379
1525
|
try {
|
|
1380
1526
|
const servers = await serverInstance.getServers();
|
|
1381
1527
|
res.json({ success: true, data: { servers } });
|
|
1382
1528
|
} catch (error) {
|
|
1383
|
-
|
|
1529
|
+
logger9.error("[Messages Router /central-servers] Error fetching servers:", error);
|
|
1384
1530
|
res.status(500).json({ success: false, error: "Failed to fetch servers" });
|
|
1385
1531
|
}
|
|
1386
1532
|
});
|
|
@@ -1401,16 +1547,16 @@ function createServersRouter(serverInstance) {
|
|
|
1401
1547
|
});
|
|
1402
1548
|
res.status(201).json({ success: true, data: { server } });
|
|
1403
1549
|
} catch (error) {
|
|
1404
|
-
|
|
1550
|
+
logger9.error("[Messages Router /servers] Error creating server:", error);
|
|
1405
1551
|
res.status(500).json({ success: false, error: "Failed to create server" });
|
|
1406
1552
|
}
|
|
1407
1553
|
});
|
|
1408
1554
|
router.post(
|
|
1409
1555
|
"/servers/:serverId/agents",
|
|
1410
1556
|
async (req, res) => {
|
|
1411
|
-
const serverId = req.params.serverId === DEFAULT_SERVER_ID2 ? DEFAULT_SERVER_ID2 :
|
|
1557
|
+
const serverId = req.params.serverId === DEFAULT_SERVER_ID2 ? DEFAULT_SERVER_ID2 : validateUuid9(req.params.serverId);
|
|
1412
1558
|
const { agentId } = req.body;
|
|
1413
|
-
if (!serverId || !
|
|
1559
|
+
if (!serverId || !validateUuid9(agentId)) {
|
|
1414
1560
|
return res.status(400).json({
|
|
1415
1561
|
success: false,
|
|
1416
1562
|
error: "Invalid serverId or agentId format"
|
|
@@ -1433,7 +1579,7 @@ function createServersRouter(serverInstance) {
|
|
|
1433
1579
|
}
|
|
1434
1580
|
});
|
|
1435
1581
|
} catch (error) {
|
|
1436
|
-
|
|
1582
|
+
logger9.error(
|
|
1437
1583
|
`[MessagesRouter] Error adding agent ${agentId} to server ${serverId}:`,
|
|
1438
1584
|
error
|
|
1439
1585
|
);
|
|
@@ -1444,8 +1590,8 @@ function createServersRouter(serverInstance) {
|
|
|
1444
1590
|
router.delete(
|
|
1445
1591
|
"/servers/:serverId/agents/:agentId",
|
|
1446
1592
|
async (req, res) => {
|
|
1447
|
-
const serverId = req.params.serverId === DEFAULT_SERVER_ID2 ? DEFAULT_SERVER_ID2 :
|
|
1448
|
-
const agentId =
|
|
1593
|
+
const serverId = req.params.serverId === DEFAULT_SERVER_ID2 ? DEFAULT_SERVER_ID2 : validateUuid9(req.params.serverId);
|
|
1594
|
+
const agentId = validateUuid9(req.params.agentId);
|
|
1449
1595
|
if (!serverId || !agentId) {
|
|
1450
1596
|
return res.status(400).json({
|
|
1451
1597
|
success: false,
|
|
@@ -1469,7 +1615,7 @@ function createServersRouter(serverInstance) {
|
|
|
1469
1615
|
}
|
|
1470
1616
|
});
|
|
1471
1617
|
} catch (error) {
|
|
1472
|
-
|
|
1618
|
+
logger9.error(
|
|
1473
1619
|
`[MessagesRouter] Error removing agent ${agentId} from server ${serverId}:`,
|
|
1474
1620
|
error
|
|
1475
1621
|
);
|
|
@@ -1480,7 +1626,7 @@ function createServersRouter(serverInstance) {
|
|
|
1480
1626
|
router.get(
|
|
1481
1627
|
"/servers/:serverId/agents",
|
|
1482
1628
|
async (req, res) => {
|
|
1483
|
-
const serverId = req.params.serverId === DEFAULT_SERVER_ID2 ? DEFAULT_SERVER_ID2 :
|
|
1629
|
+
const serverId = req.params.serverId === DEFAULT_SERVER_ID2 ? DEFAULT_SERVER_ID2 : validateUuid9(req.params.serverId);
|
|
1484
1630
|
if (!serverId) {
|
|
1485
1631
|
return res.status(400).json({
|
|
1486
1632
|
success: false,
|
|
@@ -1498,7 +1644,7 @@ function createServersRouter(serverInstance) {
|
|
|
1498
1644
|
}
|
|
1499
1645
|
});
|
|
1500
1646
|
} catch (error) {
|
|
1501
|
-
|
|
1647
|
+
logger9.error(`[MessagesRouter] Error fetching agents for server ${serverId}:`, error);
|
|
1502
1648
|
res.status(500).json({ success: false, error: "Failed to fetch server agents" });
|
|
1503
1649
|
}
|
|
1504
1650
|
}
|
|
@@ -1506,7 +1652,7 @@ function createServersRouter(serverInstance) {
|
|
|
1506
1652
|
router.get(
|
|
1507
1653
|
"/agents/:agentId/servers",
|
|
1508
1654
|
async (req, res) => {
|
|
1509
|
-
const agentId =
|
|
1655
|
+
const agentId = validateUuid9(req.params.agentId);
|
|
1510
1656
|
if (!agentId) {
|
|
1511
1657
|
return res.status(400).json({
|
|
1512
1658
|
success: false,
|
|
@@ -1524,7 +1670,7 @@ function createServersRouter(serverInstance) {
|
|
|
1524
1670
|
}
|
|
1525
1671
|
});
|
|
1526
1672
|
} catch (error) {
|
|
1527
|
-
|
|
1673
|
+
logger9.error(`[MessagesRouter] Error fetching servers for agent ${agentId}:`, error);
|
|
1528
1674
|
res.status(500).json({ success: false, error: "Failed to fetch agent servers" });
|
|
1529
1675
|
}
|
|
1530
1676
|
}
|
|
@@ -1536,22 +1682,22 @@ function createServersRouter(serverInstance) {
|
|
|
1536
1682
|
import {
|
|
1537
1683
|
composePromptFromState,
|
|
1538
1684
|
ModelType,
|
|
1539
|
-
ChannelType,
|
|
1540
|
-
logger as
|
|
1541
|
-
validateUuid as
|
|
1685
|
+
ChannelType as ChannelType2,
|
|
1686
|
+
logger as logger14,
|
|
1687
|
+
validateUuid as validateUuid13
|
|
1542
1688
|
} from "@elizaos/core";
|
|
1543
|
-
import
|
|
1689
|
+
import express11 from "express";
|
|
1544
1690
|
|
|
1545
1691
|
// src/upload.ts
|
|
1546
1692
|
import fs2 from "fs";
|
|
1547
1693
|
import path2 from "path";
|
|
1548
1694
|
import fileUpload from "express-fileupload";
|
|
1549
|
-
import { validateUuid as
|
|
1695
|
+
import { validateUuid as validateUuid10, logger as logger11 } from "@elizaos/core";
|
|
1550
1696
|
|
|
1551
1697
|
// src/api/shared/file-utils.ts
|
|
1552
1698
|
import fs from "fs";
|
|
1553
1699
|
import path from "path";
|
|
1554
|
-
import { logger as
|
|
1700
|
+
import { logger as logger10 } from "@elizaos/core";
|
|
1555
1701
|
function createSecureUploadDir(id, type) {
|
|
1556
1702
|
if (id.includes("..") || id.includes("/") || id.includes("\\") || id.includes("\0")) {
|
|
1557
1703
|
throw new Error(`Invalid ${type.slice(0, -1)} ID: contains illegal characters`);
|
|
@@ -1582,15 +1728,15 @@ var cleanupFile = (filePath) => {
|
|
|
1582
1728
|
const resolvedPath = path.resolve(filePath);
|
|
1583
1729
|
const normalizedPath = path.normalize(resolvedPath);
|
|
1584
1730
|
if (normalizedPath.includes("..") || !normalizedPath.startsWith(process.cwd())) {
|
|
1585
|
-
|
|
1731
|
+
logger10.warn(`[SECURITY] Potentially unsafe file path blocked: ${filePath}`);
|
|
1586
1732
|
return;
|
|
1587
1733
|
}
|
|
1588
1734
|
if (fs.existsSync(normalizedPath)) {
|
|
1589
1735
|
fs.unlinkSync(normalizedPath);
|
|
1590
|
-
|
|
1736
|
+
logger10.debug(`[FILE] Successfully cleaned up file: ${normalizedPath}`);
|
|
1591
1737
|
}
|
|
1592
1738
|
} catch (error) {
|
|
1593
|
-
|
|
1739
|
+
logger10.error(`Error cleaning up file ${filePath}:`, error);
|
|
1594
1740
|
}
|
|
1595
1741
|
};
|
|
1596
1742
|
var cleanupUploadedFile = (file) => {
|
|
@@ -1633,14 +1779,14 @@ function generateSecureFilename(originalName) {
|
|
|
1633
1779
|
return `${uniqueSuffix}-${sanitizedName}`;
|
|
1634
1780
|
}
|
|
1635
1781
|
function ensureUploadDir(id, type) {
|
|
1636
|
-
if (!
|
|
1782
|
+
if (!validateUuid10(id)) {
|
|
1637
1783
|
throw new Error(`Invalid ${type.slice(0, -1)} ID format`);
|
|
1638
1784
|
}
|
|
1639
1785
|
const uploadDir = createSecureUploadDir(id, type);
|
|
1640
1786
|
if (!fs2.existsSync(uploadDir)) {
|
|
1641
1787
|
fs2.mkdirSync(uploadDir, { recursive: true });
|
|
1642
1788
|
}
|
|
1643
|
-
|
|
1789
|
+
logger11.debug(`[UPLOAD] Secure ${type.slice(0, -1)} upload directory created: ${uploadDir}`);
|
|
1644
1790
|
return uploadDir;
|
|
1645
1791
|
}
|
|
1646
1792
|
var agentAudioUpload = () => fileUpload({
|
|
@@ -1707,19 +1853,19 @@ async function processUploadedFile(file, targetId, type) {
|
|
|
1707
1853
|
const finalPath = path2.join(uploadDir, filename);
|
|
1708
1854
|
await file.mv(finalPath);
|
|
1709
1855
|
const url = `/media/uploads/${type}/${targetId}/${filename}`;
|
|
1710
|
-
|
|
1856
|
+
logger11.debug(`[UPLOAD] File processed successfully: ${filename}`);
|
|
1711
1857
|
return { filename, path: finalPath, url };
|
|
1712
1858
|
} catch (error) {
|
|
1713
|
-
|
|
1859
|
+
logger11.error("[UPLOAD] Error processing uploaded file:", error);
|
|
1714
1860
|
throw error;
|
|
1715
1861
|
}
|
|
1716
1862
|
}
|
|
1717
1863
|
|
|
1718
1864
|
// src/api/shared/middleware.ts
|
|
1719
|
-
import { validateUuid as
|
|
1865
|
+
import { validateUuid as validateUuid12, logger as logger13 } from "@elizaos/core";
|
|
1720
1866
|
|
|
1721
1867
|
// src/api/shared/validation.ts
|
|
1722
|
-
import { validateUuid as
|
|
1868
|
+
import { validateUuid as validateUuid11, logger as logger12 } from "@elizaos/core";
|
|
1723
1869
|
var getRuntime = (agents, agentId) => {
|
|
1724
1870
|
const runtime = agents.get(agentId);
|
|
1725
1871
|
if (!runtime) {
|
|
@@ -1743,7 +1889,7 @@ var securityMiddleware = () => {
|
|
|
1743
1889
|
const realIp = req.get("X-Real-IP");
|
|
1744
1890
|
const clientIp = forwarded || realIp || req.ip;
|
|
1745
1891
|
if (userAgent && (userAgent.includes("..") || userAgent.includes("<script"))) {
|
|
1746
|
-
|
|
1892
|
+
logger13.warn(`[SECURITY] Suspicious User-Agent from ${clientIp}: ${userAgent}`);
|
|
1747
1893
|
}
|
|
1748
1894
|
const url = req.originalUrl || req.url;
|
|
1749
1895
|
const queryString = JSON.stringify(req.query);
|
|
@@ -1769,12 +1915,12 @@ var securityMiddleware = () => {
|
|
|
1769
1915
|
}
|
|
1770
1916
|
for (const indicator of suspiciousIndicators) {
|
|
1771
1917
|
if (url.includes(indicator.pattern) || queryString.includes(indicator.pattern)) {
|
|
1772
|
-
|
|
1918
|
+
logger13.warn(`[SECURITY] ${indicator.name} detected from ${clientIp}: ${url}`);
|
|
1773
1919
|
break;
|
|
1774
1920
|
}
|
|
1775
1921
|
}
|
|
1776
1922
|
if (hasSqlPattern) {
|
|
1777
|
-
|
|
1923
|
+
logger13.warn(`[SECURITY] SQL injection pattern detected from ${clientIp}: ${url}`);
|
|
1778
1924
|
}
|
|
1779
1925
|
next();
|
|
1780
1926
|
};
|
|
@@ -1823,7 +1969,7 @@ var createApiRateLimit = () => {
|
|
|
1823
1969
|
// Disable the `X-RateLimit-*` headers
|
|
1824
1970
|
handler: (req, res) => {
|
|
1825
1971
|
const clientIp = req.ip || "unknown";
|
|
1826
|
-
|
|
1972
|
+
logger13.warn(`[SECURITY] Rate limit exceeded for IP: ${clientIp}`);
|
|
1827
1973
|
res.status(429).json({
|
|
1828
1974
|
success: false,
|
|
1829
1975
|
error: {
|
|
@@ -1851,7 +1997,7 @@ var createFileSystemRateLimit = () => {
|
|
|
1851
1997
|
legacyHeaders: false,
|
|
1852
1998
|
handler: (req, res) => {
|
|
1853
1999
|
const clientIp = req.ip || "unknown";
|
|
1854
|
-
|
|
2000
|
+
logger13.warn(
|
|
1855
2001
|
`[SECURITY] File system rate limit exceeded for IP: ${clientIp}, endpoint: ${req.path}`
|
|
1856
2002
|
);
|
|
1857
2003
|
res.status(429).json({
|
|
@@ -1881,7 +2027,7 @@ var createUploadRateLimit = () => {
|
|
|
1881
2027
|
legacyHeaders: false,
|
|
1882
2028
|
handler: (req, res) => {
|
|
1883
2029
|
const clientIp = req.ip || "unknown";
|
|
1884
|
-
|
|
2030
|
+
logger13.warn(
|
|
1885
2031
|
`[SECURITY] Upload rate limit exceeded for IP: ${clientIp}, endpoint: ${req.path}`
|
|
1886
2032
|
);
|
|
1887
2033
|
res.status(429).json({
|
|
@@ -1898,11 +2044,11 @@ var createUploadRateLimit = () => {
|
|
|
1898
2044
|
// src/api/messaging/channels.ts
|
|
1899
2045
|
var DEFAULT_SERVER_ID3 = "00000000-0000-0000-0000-000000000000";
|
|
1900
2046
|
function createChannelsRouter(agents, serverInstance) {
|
|
1901
|
-
const router =
|
|
2047
|
+
const router = express11.Router();
|
|
1902
2048
|
router.post(
|
|
1903
2049
|
"/central-channels/:channelId/messages",
|
|
1904
2050
|
async (req, res) => {
|
|
1905
|
-
const channelIdParam =
|
|
2051
|
+
const channelIdParam = validateUuid13(req.params.channelId);
|
|
1906
2052
|
const {
|
|
1907
2053
|
author_id,
|
|
1908
2054
|
// This is the GUI user's central ID
|
|
@@ -1917,92 +2063,92 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
1917
2063
|
source_type
|
|
1918
2064
|
// Should be something like 'eliza_gui'
|
|
1919
2065
|
} = req.body;
|
|
1920
|
-
const isValidServerId = server_id === DEFAULT_SERVER_ID3 ||
|
|
1921
|
-
if (!channelIdParam || !
|
|
2066
|
+
const isValidServerId = server_id === DEFAULT_SERVER_ID3 || validateUuid13(server_id);
|
|
2067
|
+
if (!channelIdParam || !validateUuid13(author_id) || !content || !isValidServerId) {
|
|
1922
2068
|
return res.status(400).json({
|
|
1923
2069
|
success: false,
|
|
1924
2070
|
error: "Missing required fields: channelId, server_id, author_id, content"
|
|
1925
2071
|
});
|
|
1926
2072
|
}
|
|
1927
2073
|
try {
|
|
1928
|
-
|
|
2074
|
+
logger14.info(
|
|
1929
2075
|
`[Messages Router] Checking if channel ${channelIdParam} exists before creating message`
|
|
1930
2076
|
);
|
|
1931
2077
|
let channelExists = false;
|
|
1932
2078
|
try {
|
|
1933
2079
|
const existingChannel = await serverInstance.getChannelDetails(channelIdParam);
|
|
1934
2080
|
channelExists = !!existingChannel;
|
|
1935
|
-
|
|
2081
|
+
logger14.info(`[Messages Router] Channel ${channelIdParam} exists: ${channelExists}`);
|
|
1936
2082
|
} catch (error) {
|
|
1937
2083
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1938
|
-
|
|
2084
|
+
logger14.info(
|
|
1939
2085
|
`[Messages Router] Channel ${channelIdParam} does not exist, will create it. Error: ${errorMessage}`
|
|
1940
2086
|
);
|
|
1941
2087
|
}
|
|
1942
2088
|
if (!channelExists) {
|
|
1943
|
-
|
|
2089
|
+
logger14.info(
|
|
1944
2090
|
`[Messages Router] Auto-creating channel ${channelIdParam} with serverId ${server_id}`
|
|
1945
2091
|
);
|
|
1946
2092
|
try {
|
|
1947
2093
|
const servers = await serverInstance.getServers();
|
|
1948
2094
|
const serverExists = servers.some((s) => s.id === server_id);
|
|
1949
|
-
|
|
2095
|
+
logger14.info(
|
|
1950
2096
|
`[Messages Router] Server ${server_id} exists: ${serverExists}. Available servers: ${servers.map((s) => s.id).join(", ")}`
|
|
1951
2097
|
);
|
|
1952
2098
|
if (!serverExists) {
|
|
1953
|
-
|
|
2099
|
+
logger14.error(
|
|
1954
2100
|
`[Messages Router] Server ${server_id} does not exist, cannot create channel`
|
|
1955
2101
|
);
|
|
1956
2102
|
return res.status(500).json({ success: false, error: `Server ${server_id} does not exist` });
|
|
1957
2103
|
}
|
|
1958
|
-
const isDmChannel = metadata?.isDm || metadata?.channelType ===
|
|
2104
|
+
const isDmChannel = metadata?.isDm || metadata?.channelType === ChannelType2.DM || metadata?.channel_type === ChannelType2.DM;
|
|
1959
2105
|
const channelData = {
|
|
1960
2106
|
id: channelIdParam,
|
|
1961
2107
|
// Use the specific channel ID from the URL
|
|
1962
2108
|
messageServerId: server_id,
|
|
1963
2109
|
name: isDmChannel ? `DM ${channelIdParam.substring(0, 8)}` : `Chat ${channelIdParam.substring(0, 8)}`,
|
|
1964
|
-
type: isDmChannel ?
|
|
2110
|
+
type: isDmChannel ? ChannelType2.DM : ChannelType2.GROUP,
|
|
1965
2111
|
sourceType: "auto_created",
|
|
1966
2112
|
metadata: {
|
|
1967
2113
|
created_by: "gui_auto_creation",
|
|
1968
2114
|
created_for_user: author_id,
|
|
1969
2115
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1970
|
-
channel_type: isDmChannel ?
|
|
2116
|
+
channel_type: isDmChannel ? ChannelType2.DM : ChannelType2.GROUP,
|
|
1971
2117
|
...metadata
|
|
1972
2118
|
}
|
|
1973
2119
|
};
|
|
1974
|
-
|
|
2120
|
+
logger14.info(
|
|
1975
2121
|
"[Messages Router] Creating channel with data:",
|
|
1976
2122
|
JSON.stringify(channelData, null, 2)
|
|
1977
2123
|
);
|
|
1978
2124
|
const participants = [author_id];
|
|
1979
2125
|
if (isDmChannel) {
|
|
1980
2126
|
const otherParticipant = metadata?.targetUserId || metadata?.recipientId;
|
|
1981
|
-
if (otherParticipant &&
|
|
2127
|
+
if (otherParticipant && validateUuid13(otherParticipant)) {
|
|
1982
2128
|
participants.push(otherParticipant);
|
|
1983
|
-
|
|
2129
|
+
logger14.info(
|
|
1984
2130
|
`[Messages Router] DM channel will include participants: ${participants.join(", ")}`
|
|
1985
2131
|
);
|
|
1986
2132
|
} else {
|
|
1987
|
-
|
|
2133
|
+
logger14.warn(
|
|
1988
2134
|
`[Messages Router] DM channel missing second participant, only adding author: ${author_id}`
|
|
1989
2135
|
);
|
|
1990
2136
|
}
|
|
1991
2137
|
}
|
|
1992
2138
|
await serverInstance.createChannel(channelData, participants);
|
|
1993
|
-
|
|
1994
|
-
`[Messages Router] Auto-created ${isDmChannel ?
|
|
2139
|
+
logger14.info(
|
|
2140
|
+
`[Messages Router] Auto-created ${isDmChannel ? ChannelType2.DM : ChannelType2.GROUP} channel ${channelIdParam} for message submission with ${participants.length} participants`
|
|
1995
2141
|
);
|
|
1996
2142
|
} catch (createError) {
|
|
1997
2143
|
const errorMessage = createError instanceof Error ? createError.message : String(createError);
|
|
1998
|
-
|
|
2144
|
+
logger14.error(
|
|
1999
2145
|
`[Messages Router] Failed to auto-create channel ${channelIdParam}:`,
|
|
2000
2146
|
createError
|
|
2001
2147
|
);
|
|
2002
2148
|
return res.status(500).json({ success: false, error: `Failed to create channel: ${errorMessage}` });
|
|
2003
2149
|
}
|
|
2004
2150
|
} else {
|
|
2005
|
-
|
|
2151
|
+
logger14.info(
|
|
2006
2152
|
`[Messages Router] Channel ${channelIdParam} already exists, proceeding with message creation`
|
|
2007
2153
|
);
|
|
2008
2154
|
}
|
|
@@ -2010,7 +2156,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2010
2156
|
channelId: channelIdParam,
|
|
2011
2157
|
authorId: author_id,
|
|
2012
2158
|
content,
|
|
2013
|
-
inReplyToRootMessageId: in_reply_to_message_id ?
|
|
2159
|
+
inReplyToRootMessageId: in_reply_to_message_id ? validateUuid13(in_reply_to_message_id) || void 0 : void 0,
|
|
2014
2160
|
rawMessage: raw_message,
|
|
2015
2161
|
metadata,
|
|
2016
2162
|
sourceType: source_type || "eliza_gui"
|
|
@@ -2036,7 +2182,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2036
2182
|
// Will be undefined here, which is fine
|
|
2037
2183
|
};
|
|
2038
2184
|
bus_default.emit("new_message", messageForBus);
|
|
2039
|
-
|
|
2185
|
+
logger14.info(
|
|
2040
2186
|
"[Messages Router /central-channels/:channelId/messages] GUI Message published to internal bus:",
|
|
2041
2187
|
messageForBus.id
|
|
2042
2188
|
);
|
|
@@ -2056,7 +2202,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2056
2202
|
}
|
|
2057
2203
|
res.status(201).json({ success: true, data: messageForBus });
|
|
2058
2204
|
} catch (error) {
|
|
2059
|
-
|
|
2205
|
+
logger14.error(
|
|
2060
2206
|
"[Messages Router /central-channels/:channelId/messages] Error processing GUI message:",
|
|
2061
2207
|
error
|
|
2062
2208
|
);
|
|
@@ -2067,7 +2213,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2067
2213
|
router.get(
|
|
2068
2214
|
"/central-channels/:channelId/messages",
|
|
2069
2215
|
async (req, res) => {
|
|
2070
|
-
const channelId =
|
|
2216
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
2071
2217
|
const limit = req.query.limit ? Number.parseInt(req.query.limit, 10) : 50;
|
|
2072
2218
|
const before = req.query.before ? Number.parseInt(req.query.before, 10) : void 0;
|
|
2073
2219
|
const beforeDate = before ? new Date(before) : void 0;
|
|
@@ -2094,7 +2240,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2094
2240
|
});
|
|
2095
2241
|
res.json({ success: true, data: { messages: messagesForGui } });
|
|
2096
2242
|
} catch (error) {
|
|
2097
|
-
|
|
2243
|
+
logger14.error(
|
|
2098
2244
|
`[Messages Router /central-channels/:channelId/messages] Error fetching messages for channel ${channelId}:`,
|
|
2099
2245
|
error
|
|
2100
2246
|
);
|
|
@@ -2105,7 +2251,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2105
2251
|
router.get(
|
|
2106
2252
|
"/central-servers/:serverId/channels",
|
|
2107
2253
|
async (req, res) => {
|
|
2108
|
-
const serverId = req.params.serverId === DEFAULT_SERVER_ID3 ? DEFAULT_SERVER_ID3 :
|
|
2254
|
+
const serverId = req.params.serverId === DEFAULT_SERVER_ID3 ? DEFAULT_SERVER_ID3 : validateUuid13(req.params.serverId);
|
|
2109
2255
|
if (!serverId) {
|
|
2110
2256
|
return res.status(400).json({ success: false, error: "Invalid serverId" });
|
|
2111
2257
|
}
|
|
@@ -2113,7 +2259,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2113
2259
|
const channels = await serverInstance.getChannelsForServer(serverId);
|
|
2114
2260
|
res.json({ success: true, data: { channels } });
|
|
2115
2261
|
} catch (error) {
|
|
2116
|
-
|
|
2262
|
+
logger14.error(
|
|
2117
2263
|
`[Messages Router /central-servers/:serverId/channels] Error fetching channels for server ${serverId}:`,
|
|
2118
2264
|
error
|
|
2119
2265
|
);
|
|
@@ -2122,22 +2268,36 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2122
2268
|
}
|
|
2123
2269
|
);
|
|
2124
2270
|
router.post("/channels", async (req, res) => {
|
|
2125
|
-
const
|
|
2126
|
-
|
|
2271
|
+
const serverId = req.body.serverId;
|
|
2272
|
+
const { name, type, sourceType, sourceId, metadata } = req.body;
|
|
2273
|
+
const topic = req.body.topic ?? req.body.description;
|
|
2274
|
+
if (!serverId) {
|
|
2275
|
+
return res.status(400).json({
|
|
2276
|
+
success: false,
|
|
2277
|
+
error: "Missing required fields: serverId."
|
|
2278
|
+
});
|
|
2279
|
+
}
|
|
2280
|
+
if (!name) {
|
|
2127
2281
|
return res.status(400).json({
|
|
2128
2282
|
success: false,
|
|
2129
|
-
error: "Missing required fields:
|
|
2283
|
+
error: "Missing required fields: name."
|
|
2130
2284
|
});
|
|
2131
2285
|
}
|
|
2132
|
-
if (!
|
|
2286
|
+
if (!type) {
|
|
2133
2287
|
return res.status(400).json({
|
|
2134
2288
|
success: false,
|
|
2135
|
-
error: "
|
|
2289
|
+
error: "Missing required fields: type."
|
|
2290
|
+
});
|
|
2291
|
+
}
|
|
2292
|
+
if (!validateUuid13(serverId)) {
|
|
2293
|
+
return res.status(400).json({
|
|
2294
|
+
success: false,
|
|
2295
|
+
error: "Invalid serverId format"
|
|
2136
2296
|
});
|
|
2137
2297
|
}
|
|
2138
2298
|
try {
|
|
2139
2299
|
const channel = await serverInstance.createChannel({
|
|
2140
|
-
messageServerId,
|
|
2300
|
+
messageServerId: serverId,
|
|
2141
2301
|
name,
|
|
2142
2302
|
type,
|
|
2143
2303
|
sourceType,
|
|
@@ -2147,14 +2307,14 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2147
2307
|
});
|
|
2148
2308
|
res.status(201).json({ success: true, data: { channel } });
|
|
2149
2309
|
} catch (error) {
|
|
2150
|
-
|
|
2310
|
+
logger14.error("[Messages Router /channels] Error creating channel:", error);
|
|
2151
2311
|
res.status(500).json({ success: false, error: "Failed to create channel" });
|
|
2152
2312
|
}
|
|
2153
2313
|
});
|
|
2154
2314
|
router.get("/dm-channel", async (req, res) => {
|
|
2155
|
-
const targetUserId =
|
|
2156
|
-
const currentUserId =
|
|
2157
|
-
const providedDmServerId = req.query.dmServerId === DEFAULT_SERVER_ID3 ? DEFAULT_SERVER_ID3 :
|
|
2315
|
+
const targetUserId = validateUuid13(req.query.targetUserId);
|
|
2316
|
+
const currentUserId = validateUuid13(req.query.currentUserId);
|
|
2317
|
+
const providedDmServerId = req.query.dmServerId === DEFAULT_SERVER_ID3 ? DEFAULT_SERVER_ID3 : validateUuid13(req.query.dmServerId);
|
|
2158
2318
|
if (!targetUserId || !currentUserId) {
|
|
2159
2319
|
res.status(400).json({ success: false, error: "Missing targetUserId or currentUserId" });
|
|
2160
2320
|
return;
|
|
@@ -2170,7 +2330,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2170
2330
|
if (existingServer) {
|
|
2171
2331
|
dmServerIdToUse = providedDmServerId;
|
|
2172
2332
|
} else {
|
|
2173
|
-
|
|
2333
|
+
logger14.warn(
|
|
2174
2334
|
`Provided dmServerId ${providedDmServerId} not found, using default DM server logic.`
|
|
2175
2335
|
);
|
|
2176
2336
|
dmServerIdToUse = DEFAULT_SERVER_ID3;
|
|
@@ -2188,7 +2348,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2188
2348
|
stack: error.stack,
|
|
2189
2349
|
originalError: error
|
|
2190
2350
|
} : { message: String(error) };
|
|
2191
|
-
|
|
2351
|
+
logger14.error("Error finding/creating DM channel:", errorDetails);
|
|
2192
2352
|
res.status(500).json({ success: false, error: "Failed to find or create DM channel" });
|
|
2193
2353
|
}
|
|
2194
2354
|
});
|
|
@@ -2196,12 +2356,12 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2196
2356
|
const {
|
|
2197
2357
|
name,
|
|
2198
2358
|
participantCentralUserIds,
|
|
2199
|
-
type =
|
|
2359
|
+
type = ChannelType2.GROUP,
|
|
2200
2360
|
server_id,
|
|
2201
2361
|
metadata
|
|
2202
2362
|
} = req.body;
|
|
2203
|
-
const isValidServerId = server_id === DEFAULT_SERVER_ID3 ||
|
|
2204
|
-
if (!name || !isValidServerId || !Array.isArray(participantCentralUserIds) || participantCentralUserIds.some((id) => !
|
|
2363
|
+
const isValidServerId = server_id === DEFAULT_SERVER_ID3 || validateUuid13(server_id);
|
|
2364
|
+
if (!name || !isValidServerId || !Array.isArray(participantCentralUserIds) || participantCentralUserIds.some((id) => !validateUuid13(id))) {
|
|
2205
2365
|
return res.status(400).json({
|
|
2206
2366
|
success: false,
|
|
2207
2367
|
error: 'Invalid payload. Required: name, server_id (UUID or "0"), participantCentralUserIds (array of UUIDs). Optional: type, metadata.'
|
|
@@ -2224,7 +2384,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2224
2384
|
res.status(201).json({ success: true, data: newChannel });
|
|
2225
2385
|
} catch (error) {
|
|
2226
2386
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
2227
|
-
|
|
2387
|
+
logger14.error(
|
|
2228
2388
|
"[Messages Router /central-channels] Error creating group channel:",
|
|
2229
2389
|
errorMessage
|
|
2230
2390
|
);
|
|
@@ -2234,7 +2394,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2234
2394
|
router.get(
|
|
2235
2395
|
"/central-channels/:channelId/details",
|
|
2236
2396
|
async (req, res) => {
|
|
2237
|
-
const channelId =
|
|
2397
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
2238
2398
|
if (!channelId) {
|
|
2239
2399
|
return res.status(400).json({ success: false, error: "Invalid channelId" });
|
|
2240
2400
|
}
|
|
@@ -2245,7 +2405,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2245
2405
|
}
|
|
2246
2406
|
res.json({ success: true, data: channelDetails });
|
|
2247
2407
|
} catch (error) {
|
|
2248
|
-
|
|
2408
|
+
logger14.error(`[Messages Router] Error fetching details for channel ${channelId}:`, error);
|
|
2249
2409
|
res.status(500).json({ success: false, error: "Failed to fetch channel details" });
|
|
2250
2410
|
}
|
|
2251
2411
|
}
|
|
@@ -2253,7 +2413,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2253
2413
|
router.get(
|
|
2254
2414
|
"/central-channels/:channelId/participants",
|
|
2255
2415
|
async (req, res) => {
|
|
2256
|
-
const channelId =
|
|
2416
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
2257
2417
|
if (!channelId) {
|
|
2258
2418
|
return res.status(400).json({ success: false, error: "Invalid channelId" });
|
|
2259
2419
|
}
|
|
@@ -2261,7 +2421,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2261
2421
|
const participants = await serverInstance.getChannelParticipants(channelId);
|
|
2262
2422
|
res.json({ success: true, data: participants });
|
|
2263
2423
|
} catch (error) {
|
|
2264
|
-
|
|
2424
|
+
logger14.error(
|
|
2265
2425
|
`[Messages Router] Error fetching participants for channel ${channelId}:`,
|
|
2266
2426
|
error
|
|
2267
2427
|
);
|
|
@@ -2272,9 +2432,9 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2272
2432
|
router.post(
|
|
2273
2433
|
"/central-channels/:channelId/agents",
|
|
2274
2434
|
async (req, res) => {
|
|
2275
|
-
const channelId =
|
|
2435
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
2276
2436
|
const { agentId } = req.body;
|
|
2277
|
-
if (!channelId || !
|
|
2437
|
+
if (!channelId || !validateUuid13(agentId)) {
|
|
2278
2438
|
return res.status(400).json({
|
|
2279
2439
|
success: false,
|
|
2280
2440
|
error: "Invalid channelId or agentId format"
|
|
@@ -2289,7 +2449,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2289
2449
|
});
|
|
2290
2450
|
}
|
|
2291
2451
|
await serverInstance.addParticipantsToChannel(channelId, [agentId]);
|
|
2292
|
-
|
|
2452
|
+
logger14.info(`[Messages Router] Added agent ${agentId} to channel ${channelId}`);
|
|
2293
2453
|
res.status(201).json({
|
|
2294
2454
|
success: true,
|
|
2295
2455
|
data: {
|
|
@@ -2299,7 +2459,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2299
2459
|
}
|
|
2300
2460
|
});
|
|
2301
2461
|
} catch (error) {
|
|
2302
|
-
|
|
2462
|
+
logger14.error(
|
|
2303
2463
|
`[Messages Router] Error adding agent ${agentId} to channel ${channelId}:`,
|
|
2304
2464
|
error
|
|
2305
2465
|
);
|
|
@@ -2314,8 +2474,8 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2314
2474
|
router.delete(
|
|
2315
2475
|
"/central-channels/:channelId/agents/:agentId",
|
|
2316
2476
|
async (req, res) => {
|
|
2317
|
-
const channelId =
|
|
2318
|
-
const agentId =
|
|
2477
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
2478
|
+
const agentId = validateUuid13(req.params.agentId);
|
|
2319
2479
|
if (!channelId || !agentId) {
|
|
2320
2480
|
return res.status(400).json({
|
|
2321
2481
|
success: false,
|
|
@@ -2341,7 +2501,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2341
2501
|
await serverInstance.updateChannel(channelId, {
|
|
2342
2502
|
participantCentralUserIds: updatedParticipants
|
|
2343
2503
|
});
|
|
2344
|
-
|
|
2504
|
+
logger14.info(`[Messages Router] Removed agent ${agentId} from channel ${channelId}`);
|
|
2345
2505
|
res.status(200).json({
|
|
2346
2506
|
success: true,
|
|
2347
2507
|
data: {
|
|
@@ -2351,7 +2511,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2351
2511
|
}
|
|
2352
2512
|
});
|
|
2353
2513
|
} catch (error) {
|
|
2354
|
-
|
|
2514
|
+
logger14.error(
|
|
2355
2515
|
`[Messages Router] Error removing agent ${agentId} from channel ${channelId}:`,
|
|
2356
2516
|
error
|
|
2357
2517
|
);
|
|
@@ -2366,7 +2526,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2366
2526
|
router.get(
|
|
2367
2527
|
"/central-channels/:channelId/agents",
|
|
2368
2528
|
async (req, res) => {
|
|
2369
|
-
const channelId =
|
|
2529
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
2370
2530
|
if (!channelId) {
|
|
2371
2531
|
return res.status(400).json({
|
|
2372
2532
|
success: false,
|
|
@@ -2385,7 +2545,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2385
2545
|
}
|
|
2386
2546
|
});
|
|
2387
2547
|
} catch (error) {
|
|
2388
|
-
|
|
2548
|
+
logger14.error(`[Messages Router] Error fetching agents for channel ${channelId}:`, error);
|
|
2389
2549
|
res.status(500).json({
|
|
2390
2550
|
success: false,
|
|
2391
2551
|
error: "Failed to fetch channel agents"
|
|
@@ -2396,20 +2556,20 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2396
2556
|
router.delete(
|
|
2397
2557
|
"/central-channels/:channelId/messages/:messageId",
|
|
2398
2558
|
async (req, res) => {
|
|
2399
|
-
const channelId =
|
|
2400
|
-
const messageId =
|
|
2559
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
2560
|
+
const messageId = validateUuid13(req.params.messageId);
|
|
2401
2561
|
if (!channelId || !messageId) {
|
|
2402
2562
|
return res.status(400).json({ success: false, error: "Invalid channelId or messageId" });
|
|
2403
2563
|
}
|
|
2404
2564
|
try {
|
|
2405
2565
|
await serverInstance.deleteMessage(messageId);
|
|
2406
|
-
|
|
2566
|
+
logger14.info(`[Messages Router] Deleted message ${messageId} from central database`);
|
|
2407
2567
|
const deletedMessagePayload = {
|
|
2408
2568
|
messageId,
|
|
2409
2569
|
channelId
|
|
2410
2570
|
};
|
|
2411
2571
|
bus_default.emit("message_deleted", deletedMessagePayload);
|
|
2412
|
-
|
|
2572
|
+
logger14.info(
|
|
2413
2573
|
`[Messages Router] Emitted message_deleted event to internal bus for message ${messageId}`
|
|
2414
2574
|
);
|
|
2415
2575
|
if (serverInstance.socketIO) {
|
|
@@ -2420,7 +2580,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2420
2580
|
}
|
|
2421
2581
|
res.status(204).send();
|
|
2422
2582
|
} catch (error) {
|
|
2423
|
-
|
|
2583
|
+
logger14.error(
|
|
2424
2584
|
`[Messages Router] Error deleting message ${messageId} from channel ${channelId}:`,
|
|
2425
2585
|
error
|
|
2426
2586
|
);
|
|
@@ -2431,7 +2591,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2431
2591
|
router.delete(
|
|
2432
2592
|
"/central-channels/:channelId/messages",
|
|
2433
2593
|
async (req, res) => {
|
|
2434
|
-
const channelId =
|
|
2594
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
2435
2595
|
if (!channelId) {
|
|
2436
2596
|
return res.status(400).json({ success: false, error: "Invalid channelId" });
|
|
2437
2597
|
}
|
|
@@ -2441,7 +2601,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2441
2601
|
channelId
|
|
2442
2602
|
};
|
|
2443
2603
|
bus_default.emit("channel_cleared", channelClearedPayload);
|
|
2444
|
-
|
|
2604
|
+
logger14.info(
|
|
2445
2605
|
`[Messages Router] Emitted channel_cleared event to internal bus for channel ${channelId}`
|
|
2446
2606
|
);
|
|
2447
2607
|
if (serverInstance.socketIO) {
|
|
@@ -2451,7 +2611,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2451
2611
|
}
|
|
2452
2612
|
res.status(204).send();
|
|
2453
2613
|
} catch (error) {
|
|
2454
|
-
|
|
2614
|
+
logger14.error(`[Messages Router] Error clearing messages for channel ${channelId}:`, error);
|
|
2455
2615
|
res.status(500).json({ success: false, error: "Failed to clear messages" });
|
|
2456
2616
|
}
|
|
2457
2617
|
}
|
|
@@ -2459,7 +2619,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2459
2619
|
router.patch(
|
|
2460
2620
|
"/central-channels/:channelId",
|
|
2461
2621
|
async (req, res) => {
|
|
2462
|
-
const channelId =
|
|
2622
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
2463
2623
|
if (!channelId) {
|
|
2464
2624
|
return res.status(400).json({ success: false, error: "Invalid channelId" });
|
|
2465
2625
|
}
|
|
@@ -2478,7 +2638,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2478
2638
|
}
|
|
2479
2639
|
res.json({ success: true, data: updatedChannel });
|
|
2480
2640
|
} catch (error) {
|
|
2481
|
-
|
|
2641
|
+
logger14.error(`[Messages Router] Error updating channel ${channelId}:`, error);
|
|
2482
2642
|
res.status(500).json({ success: false, error: "Failed to update channel" });
|
|
2483
2643
|
}
|
|
2484
2644
|
}
|
|
@@ -2486,7 +2646,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2486
2646
|
router.delete(
|
|
2487
2647
|
"/central-channels/:channelId",
|
|
2488
2648
|
async (req, res) => {
|
|
2489
|
-
const channelId =
|
|
2649
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
2490
2650
|
if (!channelId) {
|
|
2491
2651
|
return res.status(400).json({ success: false, error: "Invalid channelId" });
|
|
2492
2652
|
}
|
|
@@ -2494,14 +2654,14 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2494
2654
|
const messages = await serverInstance.getMessagesForChannel(channelId);
|
|
2495
2655
|
const messageCount = messages.length;
|
|
2496
2656
|
await serverInstance.deleteChannel(channelId);
|
|
2497
|
-
|
|
2657
|
+
logger14.info(
|
|
2498
2658
|
`[Messages Router] Deleted channel ${channelId} with ${messageCount} messages from central database`
|
|
2499
2659
|
);
|
|
2500
2660
|
const channelClearedPayload = {
|
|
2501
2661
|
channelId
|
|
2502
2662
|
};
|
|
2503
2663
|
bus_default.emit("channel_cleared", channelClearedPayload);
|
|
2504
|
-
|
|
2664
|
+
logger14.info(
|
|
2505
2665
|
`[Messages Router] Emitted channel_cleared event to internal bus for deleted channel ${channelId}`
|
|
2506
2666
|
);
|
|
2507
2667
|
if (serverInstance.socketIO) {
|
|
@@ -2511,7 +2671,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2511
2671
|
}
|
|
2512
2672
|
res.status(204).send();
|
|
2513
2673
|
} catch (error) {
|
|
2514
|
-
|
|
2674
|
+
logger14.error(`[Messages Router] Error deleting channel ${channelId}:`, error);
|
|
2515
2675
|
res.status(500).json({ success: false, error: "Failed to delete channel" });
|
|
2516
2676
|
}
|
|
2517
2677
|
}
|
|
@@ -2522,7 +2682,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2522
2682
|
createFileSystemRateLimit(),
|
|
2523
2683
|
channelUpload(),
|
|
2524
2684
|
async (req, res) => {
|
|
2525
|
-
const channelId =
|
|
2685
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
2526
2686
|
if (!channelId) {
|
|
2527
2687
|
res.status(400).json({ success: false, error: "Invalid channelId format" });
|
|
2528
2688
|
return;
|
|
@@ -2557,7 +2717,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2557
2717
|
return;
|
|
2558
2718
|
}
|
|
2559
2719
|
const result = await processUploadedFile(mediaFile, channelId, "channels");
|
|
2560
|
-
|
|
2720
|
+
logger14.info(
|
|
2561
2721
|
`[MessagesRouter /upload-media] Secure file uploaded for channel ${channelId}: ${result.filename}. URL: ${result.url}`
|
|
2562
2722
|
);
|
|
2563
2723
|
res.json({
|
|
@@ -2573,7 +2733,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2573
2733
|
});
|
|
2574
2734
|
} catch (error) {
|
|
2575
2735
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
2576
|
-
|
|
2736
|
+
logger14.error(
|
|
2577
2737
|
`[MessagesRouter /upload-media] Error processing upload for channel ${channelId}: ${errorMessage}`,
|
|
2578
2738
|
error
|
|
2579
2739
|
);
|
|
@@ -2587,7 +2747,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2587
2747
|
router.post(
|
|
2588
2748
|
"/central-channels/:channelId/generate-title",
|
|
2589
2749
|
async (req, res) => {
|
|
2590
|
-
const channelId =
|
|
2750
|
+
const channelId = validateUuid13(req.params.channelId);
|
|
2591
2751
|
const { agentId } = req.body;
|
|
2592
2752
|
if (!channelId) {
|
|
2593
2753
|
return res.status(400).json({
|
|
@@ -2595,7 +2755,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2595
2755
|
error: "Invalid channel ID format"
|
|
2596
2756
|
});
|
|
2597
2757
|
}
|
|
2598
|
-
if (!agentId || !
|
|
2758
|
+
if (!agentId || !validateUuid13(agentId)) {
|
|
2599
2759
|
return res.status(400).json({
|
|
2600
2760
|
success: false,
|
|
2601
2761
|
error: "Valid agent ID is required"
|
|
@@ -2609,7 +2769,7 @@ function createChannelsRouter(agents, serverInstance) {
|
|
|
2609
2769
|
error: "Agent not found or not active"
|
|
2610
2770
|
});
|
|
2611
2771
|
}
|
|
2612
|
-
|
|
2772
|
+
logger14.info(`[CHANNEL SUMMARIZE] Summarizing channel ${channelId}`);
|
|
2613
2773
|
const limit = req.query.limit ? Number.parseInt(req.query.limit, 10) : 50;
|
|
2614
2774
|
const before = req.query.before ? Number.parseInt(req.query.before, 10) : void 0;
|
|
2615
2775
|
const beforeDate = before ? new Date(before) : void 0;
|
|
@@ -2663,22 +2823,22 @@ Respond with just the title, nothing else.
|
|
|
2663
2823
|
// Keep titles short
|
|
2664
2824
|
});
|
|
2665
2825
|
if (!newTitle || newTitle.trim().length === 0) {
|
|
2666
|
-
|
|
2826
|
+
logger14.warn(`[ChatTitleEvaluator] Failed to generate title for room ${channelId}`);
|
|
2667
2827
|
return;
|
|
2668
2828
|
}
|
|
2669
2829
|
const cleanTitle = newTitle.trim().replace(/^["']|["']$/g, "");
|
|
2670
|
-
|
|
2830
|
+
logger14.info(`[ChatTitleEvaluator] Generated title: "${cleanTitle}" for room ${channelId}`);
|
|
2671
2831
|
const result = {
|
|
2672
2832
|
title: cleanTitle,
|
|
2673
2833
|
channelId
|
|
2674
2834
|
};
|
|
2675
|
-
|
|
2835
|
+
logger14.success(`[CHANNEL SUMMARIZE] Successfully summarized channel ${channelId}`);
|
|
2676
2836
|
res.json({
|
|
2677
2837
|
success: true,
|
|
2678
2838
|
data: result
|
|
2679
2839
|
});
|
|
2680
2840
|
} catch (error) {
|
|
2681
|
-
|
|
2841
|
+
logger14.error("[CHANNEL SUMMARIZE] Error summarizing channel:", error);
|
|
2682
2842
|
res.status(500).json({
|
|
2683
2843
|
success: false,
|
|
2684
2844
|
error: "Failed to summarize channel",
|
|
@@ -2692,7 +2852,7 @@ Respond with just the title, nothing else.
|
|
|
2692
2852
|
|
|
2693
2853
|
// src/api/messaging/index.ts
|
|
2694
2854
|
function messagingRouter(agents, serverInstance) {
|
|
2695
|
-
const router =
|
|
2855
|
+
const router = express12.Router();
|
|
2696
2856
|
if (!serverInstance) {
|
|
2697
2857
|
throw new Error("ServerInstance is required for messaging router");
|
|
2698
2858
|
}
|
|
@@ -2703,17 +2863,17 @@ function messagingRouter(agents, serverInstance) {
|
|
|
2703
2863
|
}
|
|
2704
2864
|
|
|
2705
2865
|
// src/api/media/index.ts
|
|
2706
|
-
import
|
|
2866
|
+
import express15 from "express";
|
|
2707
2867
|
|
|
2708
2868
|
// src/api/media/agents.ts
|
|
2709
|
-
import { validateUuid as
|
|
2710
|
-
import
|
|
2869
|
+
import { validateUuid as validateUuid14, logger as logger15, getContentTypeFromMimeType } from "@elizaos/core";
|
|
2870
|
+
import express13 from "express";
|
|
2711
2871
|
function createAgentMediaRouter() {
|
|
2712
|
-
const router =
|
|
2872
|
+
const router = express13.Router();
|
|
2713
2873
|
router.post("/:agentId/upload-media", agentMediaUpload(), async (req, res) => {
|
|
2714
2874
|
const agentMediaReq = req;
|
|
2715
|
-
|
|
2716
|
-
const agentId =
|
|
2875
|
+
logger15.debug("[MEDIA UPLOAD] Processing media upload");
|
|
2876
|
+
const agentId = validateUuid14(agentMediaReq.params.agentId);
|
|
2717
2877
|
if (!agentId) {
|
|
2718
2878
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
2719
2879
|
}
|
|
@@ -2745,7 +2905,7 @@ function createAgentMediaRouter() {
|
|
|
2745
2905
|
}
|
|
2746
2906
|
try {
|
|
2747
2907
|
const result = await processUploadedFile(mediaFile, agentId, "agents");
|
|
2748
|
-
|
|
2908
|
+
logger15.info(
|
|
2749
2909
|
`[MEDIA UPLOAD] Successfully uploaded ${mediaType}: ${result.filename}. URL: ${result.url}`
|
|
2750
2910
|
);
|
|
2751
2911
|
sendSuccess(res, {
|
|
@@ -2756,7 +2916,7 @@ function createAgentMediaRouter() {
|
|
|
2756
2916
|
size: mediaFile.size
|
|
2757
2917
|
});
|
|
2758
2918
|
} catch (error) {
|
|
2759
|
-
|
|
2919
|
+
logger15.error(`[MEDIA UPLOAD] Error processing upload: ${error}`);
|
|
2760
2920
|
cleanupUploadedFile(mediaFile);
|
|
2761
2921
|
sendError(
|
|
2762
2922
|
res,
|
|
@@ -2771,11 +2931,11 @@ function createAgentMediaRouter() {
|
|
|
2771
2931
|
}
|
|
2772
2932
|
|
|
2773
2933
|
// src/api/media/channels.ts
|
|
2774
|
-
import { validateUuid as
|
|
2775
|
-
import
|
|
2934
|
+
import { validateUuid as validateUuid15, logger as logger16 } from "@elizaos/core";
|
|
2935
|
+
import express14 from "express";
|
|
2776
2936
|
import rateLimit2 from "express-rate-limit";
|
|
2777
2937
|
function createChannelMediaRouter() {
|
|
2778
|
-
const router =
|
|
2938
|
+
const router = express14.Router();
|
|
2779
2939
|
const uploadMediaRateLimiter = rateLimit2({
|
|
2780
2940
|
windowMs: 15 * 60 * 1e3,
|
|
2781
2941
|
// 15 minutes
|
|
@@ -2790,7 +2950,7 @@ function createChannelMediaRouter() {
|
|
|
2790
2950
|
channelUpload(),
|
|
2791
2951
|
async (req, res) => {
|
|
2792
2952
|
const channelMediaReq = req;
|
|
2793
|
-
const channelId =
|
|
2953
|
+
const channelId = validateUuid15(channelMediaReq.params.channelId);
|
|
2794
2954
|
if (!channelId) {
|
|
2795
2955
|
res.status(400).json({ success: false, error: "Invalid channelId format" });
|
|
2796
2956
|
return;
|
|
@@ -2815,7 +2975,7 @@ function createChannelMediaRouter() {
|
|
|
2815
2975
|
}
|
|
2816
2976
|
try {
|
|
2817
2977
|
const result = await processUploadedFile(mediaFile, channelId, "channels");
|
|
2818
|
-
|
|
2978
|
+
logger16.info(
|
|
2819
2979
|
`[Channel Media Upload] File uploaded for channel ${channelId}: ${result.filename}. URL: ${result.url}`
|
|
2820
2980
|
);
|
|
2821
2981
|
res.json({
|
|
@@ -2830,7 +2990,7 @@ function createChannelMediaRouter() {
|
|
|
2830
2990
|
}
|
|
2831
2991
|
});
|
|
2832
2992
|
} catch (error) {
|
|
2833
|
-
|
|
2993
|
+
logger16.error(
|
|
2834
2994
|
`[Channel Media Upload] Error processing upload for channel ${channelId}: ${error.message}`,
|
|
2835
2995
|
error
|
|
2836
2996
|
);
|
|
@@ -2844,7 +3004,7 @@ function createChannelMediaRouter() {
|
|
|
2844
3004
|
|
|
2845
3005
|
// src/api/media/index.ts
|
|
2846
3006
|
function mediaRouter() {
|
|
2847
|
-
const router =
|
|
3007
|
+
const router = express15.Router();
|
|
2848
3008
|
router.use("/agents", createAgentMediaRouter());
|
|
2849
3009
|
router.use("/channels", createChannelMediaRouter());
|
|
2850
3010
|
return router;
|
|
@@ -2854,13 +3014,13 @@ function mediaRouter() {
|
|
|
2854
3014
|
import express17 from "express";
|
|
2855
3015
|
|
|
2856
3016
|
// src/api/memory/groups.ts
|
|
2857
|
-
import { validateUuid as
|
|
2858
|
-
import
|
|
3017
|
+
import { validateUuid as validateUuid16, logger as logger17, createUniqueUuid as createUniqueUuid4, ChannelType as ChannelType3 } from "@elizaos/core";
|
|
3018
|
+
import express16 from "express";
|
|
2859
3019
|
function createGroupMemoryRouter(agents, serverInstance) {
|
|
2860
|
-
const router =
|
|
3020
|
+
const router = express16.Router();
|
|
2861
3021
|
const db = serverInstance?.database;
|
|
2862
3022
|
router.post("/groups/:serverId", async (req, res) => {
|
|
2863
|
-
const serverId =
|
|
3023
|
+
const serverId = validateUuid16(req.params.serverId);
|
|
2864
3024
|
const { name, worldId, source, metadata, agentIds = [] } = req.body;
|
|
2865
3025
|
if (!Array.isArray(agentIds) || agentIds.length === 0) {
|
|
2866
3026
|
return sendError(res, 400, "BAD_REQUEST", "agentIds must be a non-empty array");
|
|
@@ -2870,7 +3030,7 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
2870
3030
|
for (const agentId of agentIds) {
|
|
2871
3031
|
try {
|
|
2872
3032
|
const runtime = getRuntime(agents, agentId);
|
|
2873
|
-
const roomId =
|
|
3033
|
+
const roomId = createUniqueUuid4(runtime, serverId);
|
|
2874
3034
|
const roomName = name || `Chat ${(/* @__PURE__ */ new Date()).toLocaleString()}`;
|
|
2875
3035
|
await runtime.ensureWorldExists({
|
|
2876
3036
|
id: worldId,
|
|
@@ -2882,7 +3042,7 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
2882
3042
|
id: roomId,
|
|
2883
3043
|
name: roomName,
|
|
2884
3044
|
source,
|
|
2885
|
-
type:
|
|
3045
|
+
type: ChannelType3.API,
|
|
2886
3046
|
worldId,
|
|
2887
3047
|
serverId,
|
|
2888
3048
|
metadata,
|
|
@@ -2896,10 +3056,10 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
2896
3056
|
name: roomName,
|
|
2897
3057
|
source: "client",
|
|
2898
3058
|
worldId,
|
|
2899
|
-
type:
|
|
3059
|
+
type: ChannelType3.API
|
|
2900
3060
|
});
|
|
2901
3061
|
} catch (error) {
|
|
2902
|
-
|
|
3062
|
+
logger17.error(`[ROOM CREATE] Error creating room for agent ${agentId}:`, error);
|
|
2903
3063
|
errors.push({
|
|
2904
3064
|
agentId,
|
|
2905
3065
|
code: error instanceof Error && error.message === "Agent not found" ? "NOT_FOUND" : "CREATE_ERROR",
|
|
@@ -2922,7 +3082,7 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
2922
3082
|
});
|
|
2923
3083
|
});
|
|
2924
3084
|
router.delete("/groups/:serverId", async (req, res) => {
|
|
2925
|
-
const worldId =
|
|
3085
|
+
const worldId = validateUuid16(req.params.serverId);
|
|
2926
3086
|
if (!worldId) {
|
|
2927
3087
|
return sendError(res, 400, "INVALID_ID", "Invalid serverId (worldId) format");
|
|
2928
3088
|
}
|
|
@@ -2933,7 +3093,7 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
2933
3093
|
await db.deleteRoomsByWorldId(worldId);
|
|
2934
3094
|
res.status(204).send();
|
|
2935
3095
|
} catch (error) {
|
|
2936
|
-
|
|
3096
|
+
logger17.error("[GROUP DELETE] Error deleting group:", error);
|
|
2937
3097
|
sendError(
|
|
2938
3098
|
res,
|
|
2939
3099
|
500,
|
|
@@ -2944,7 +3104,7 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
2944
3104
|
}
|
|
2945
3105
|
});
|
|
2946
3106
|
router.delete("/groups/:serverId/memories", async (req, res) => {
|
|
2947
|
-
const worldId =
|
|
3107
|
+
const worldId = validateUuid16(req.params.serverId);
|
|
2948
3108
|
if (!worldId) {
|
|
2949
3109
|
return sendError(res, 400, "INVALID_ID", "Invalid serverId (worldId) format");
|
|
2950
3110
|
}
|
|
@@ -2959,7 +3119,7 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
2959
3119
|
}
|
|
2960
3120
|
res.status(204).send();
|
|
2961
3121
|
} catch (error) {
|
|
2962
|
-
|
|
3122
|
+
logger17.error("[GROUP MEMORIES DELETE] Error clearing memories:", error);
|
|
2963
3123
|
sendError(
|
|
2964
3124
|
res,
|
|
2965
3125
|
500,
|
|
@@ -2972,151 +3132,6 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
2972
3132
|
return router;
|
|
2973
3133
|
}
|
|
2974
3134
|
|
|
2975
|
-
// src/api/memory/rooms.ts
|
|
2976
|
-
import { validateUuid as validateUuid16, logger as logger17, createUniqueUuid as createUniqueUuid4, ChannelType as ChannelType3 } from "@elizaos/core";
|
|
2977
|
-
import express16 from "express";
|
|
2978
|
-
function createRoomManagementRouter(agents) {
|
|
2979
|
-
const router = express16.Router();
|
|
2980
|
-
router.post("/:agentId/rooms", async (req, res) => {
|
|
2981
|
-
const agentId = validateUuid16(req.params.agentId);
|
|
2982
|
-
if (!agentId) {
|
|
2983
|
-
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
2984
|
-
}
|
|
2985
|
-
const runtime = agents.get(agentId);
|
|
2986
|
-
if (!runtime) {
|
|
2987
|
-
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
2988
|
-
}
|
|
2989
|
-
try {
|
|
2990
|
-
const { name, type = ChannelType3.DM, source = "client", worldId, metadata } = req.body;
|
|
2991
|
-
if (!name) {
|
|
2992
|
-
return sendError(res, 400, "MISSING_PARAM", "Room name is required");
|
|
2993
|
-
}
|
|
2994
|
-
const roomId = createUniqueUuid4(runtime, `room-${Date.now()}`);
|
|
2995
|
-
const serverId = req.body.serverId || `server-${Date.now()}`;
|
|
2996
|
-
let resolvedWorldId = worldId;
|
|
2997
|
-
if (!resolvedWorldId) {
|
|
2998
|
-
const worldName = `World for ${name}`;
|
|
2999
|
-
resolvedWorldId = createUniqueUuid4(runtime, `world-${Date.now()}`);
|
|
3000
|
-
await runtime.ensureWorldExists({
|
|
3001
|
-
id: resolvedWorldId,
|
|
3002
|
-
name: worldName,
|
|
3003
|
-
agentId: runtime.agentId,
|
|
3004
|
-
serverId,
|
|
3005
|
-
metadata
|
|
3006
|
-
});
|
|
3007
|
-
}
|
|
3008
|
-
await runtime.ensureRoomExists({
|
|
3009
|
-
id: roomId,
|
|
3010
|
-
name,
|
|
3011
|
-
source,
|
|
3012
|
-
type,
|
|
3013
|
-
channelId: roomId,
|
|
3014
|
-
serverId,
|
|
3015
|
-
worldId: resolvedWorldId,
|
|
3016
|
-
metadata
|
|
3017
|
-
});
|
|
3018
|
-
await runtime.addParticipant(runtime.agentId, roomId);
|
|
3019
|
-
await runtime.ensureParticipantInRoom(runtime.agentId, roomId);
|
|
3020
|
-
await runtime.setParticipantUserState(roomId, runtime.agentId, "FOLLOWED");
|
|
3021
|
-
sendSuccess(
|
|
3022
|
-
res,
|
|
3023
|
-
{
|
|
3024
|
-
id: roomId,
|
|
3025
|
-
name,
|
|
3026
|
-
agentId,
|
|
3027
|
-
createdAt: Date.now(),
|
|
3028
|
-
source,
|
|
3029
|
-
type,
|
|
3030
|
-
worldId: resolvedWorldId,
|
|
3031
|
-
serverId,
|
|
3032
|
-
metadata
|
|
3033
|
-
},
|
|
3034
|
-
201
|
|
3035
|
-
);
|
|
3036
|
-
} catch (error) {
|
|
3037
|
-
logger17.error(`[ROOM CREATE] Error creating room for agent ${agentId}:`, error);
|
|
3038
|
-
sendError(
|
|
3039
|
-
res,
|
|
3040
|
-
500,
|
|
3041
|
-
"CREATE_ERROR",
|
|
3042
|
-
"Failed to create room",
|
|
3043
|
-
error instanceof Error ? error.message : String(error)
|
|
3044
|
-
);
|
|
3045
|
-
}
|
|
3046
|
-
});
|
|
3047
|
-
router.get("/:agentId/rooms", async (req, res) => {
|
|
3048
|
-
const agentId = validateUuid16(req.params.agentId);
|
|
3049
|
-
if (!agentId) {
|
|
3050
|
-
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
3051
|
-
}
|
|
3052
|
-
const runtime = agents.get(agentId);
|
|
3053
|
-
if (!runtime) {
|
|
3054
|
-
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
3055
|
-
}
|
|
3056
|
-
try {
|
|
3057
|
-
const worlds = await runtime.getAllWorlds();
|
|
3058
|
-
const participantRoomIds = await runtime.getRoomsForParticipant(agentId);
|
|
3059
|
-
const agentRooms = [];
|
|
3060
|
-
for (const world of worlds) {
|
|
3061
|
-
const worldRooms = await runtime.getRooms(world.id);
|
|
3062
|
-
for (const room of worldRooms) {
|
|
3063
|
-
if (participantRoomIds.includes(room.id)) {
|
|
3064
|
-
agentRooms.push({
|
|
3065
|
-
...room
|
|
3066
|
-
});
|
|
3067
|
-
}
|
|
3068
|
-
}
|
|
3069
|
-
}
|
|
3070
|
-
sendSuccess(res, { rooms: agentRooms });
|
|
3071
|
-
} catch (error) {
|
|
3072
|
-
logger17.error(`[ROOMS LIST] Error retrieving rooms for agent ${agentId}:`, error);
|
|
3073
|
-
sendError(
|
|
3074
|
-
res,
|
|
3075
|
-
500,
|
|
3076
|
-
"RETRIEVAL_ERROR",
|
|
3077
|
-
"Failed to retrieve agent rooms",
|
|
3078
|
-
error instanceof Error ? error.message : String(error)
|
|
3079
|
-
);
|
|
3080
|
-
}
|
|
3081
|
-
});
|
|
3082
|
-
router.get("/:agentId/rooms/:roomId", async (req, res) => {
|
|
3083
|
-
const agentId = validateUuid16(req.params.agentId);
|
|
3084
|
-
const roomId = validateUuid16(req.params.roomId);
|
|
3085
|
-
if (!agentId || !roomId) {
|
|
3086
|
-
return sendError(res, 400, "INVALID_ID", "Invalid agent ID or room ID format");
|
|
3087
|
-
}
|
|
3088
|
-
const runtime = agents.get(agentId);
|
|
3089
|
-
if (!runtime) {
|
|
3090
|
-
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
3091
|
-
}
|
|
3092
|
-
try {
|
|
3093
|
-
const room = await runtime.getRoom(roomId);
|
|
3094
|
-
if (!room) {
|
|
3095
|
-
return sendError(res, 404, "NOT_FOUND", "Room not found");
|
|
3096
|
-
}
|
|
3097
|
-
let worldName;
|
|
3098
|
-
if (room.worldId) {
|
|
3099
|
-
const world = await runtime.getWorld(room.worldId);
|
|
3100
|
-
worldName = world?.name;
|
|
3101
|
-
}
|
|
3102
|
-
sendSuccess(res, {
|
|
3103
|
-
...room,
|
|
3104
|
-
...worldName && { worldName }
|
|
3105
|
-
});
|
|
3106
|
-
} catch (error) {
|
|
3107
|
-
logger17.error(`[ROOM DETAILS] Error retrieving room ${roomId} for agent ${agentId}:`, error);
|
|
3108
|
-
sendError(
|
|
3109
|
-
res,
|
|
3110
|
-
500,
|
|
3111
|
-
"RETRIEVAL_ERROR",
|
|
3112
|
-
"Failed to retrieve room details",
|
|
3113
|
-
error instanceof Error ? error.message : String(error)
|
|
3114
|
-
);
|
|
3115
|
-
}
|
|
3116
|
-
});
|
|
3117
|
-
return router;
|
|
3118
|
-
}
|
|
3119
|
-
|
|
3120
3135
|
// src/api/memory/index.ts
|
|
3121
3136
|
function memoryRouter(agents, serverInstance) {
|
|
3122
3137
|
const router = express17.Router();
|
|
@@ -5938,7 +5953,7 @@ var AgentServer = class {
|
|
|
5938
5953
|
next();
|
|
5939
5954
|
},
|
|
5940
5955
|
apiRouter,
|
|
5941
|
-
(err, req, res) => {
|
|
5956
|
+
(err, req, res, _next) => {
|
|
5942
5957
|
logger29.error(`API error: ${req.method} ${req.path}`, err);
|
|
5943
5958
|
res.status(500).json({
|
|
5944
5959
|
success: false,
|