@elizaos/server 1.3.0 → 1.3.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/client/assets/{index-TZ8BgtSM.js → index-Bag8VjjC.js} +23476 -22733
- package/dist/client/assets/index-Bag8VjjC.js.br +0 -0
- package/dist/client/assets/{index-TZ8BgtSM.js.map → index-Bag8VjjC.js.map} +1 -1
- package/dist/client/assets/{index-BQg5aCT3.js → index-Cg8M_OX7.js} +31 -28
- package/dist/client/assets/index-Cg8M_OX7.js.br +0 -0
- package/dist/client/assets/index-Cg8M_OX7.js.map +1 -0
- package/dist/client/assets/{vendor-BWTRqS51.js → vendor-H6SVl4X5.js} +69 -69
- package/dist/client/assets/vendor-H6SVl4X5.js.br +0 -0
- package/dist/client/assets/vendor-H6SVl4X5.js.map +1 -0
- package/dist/client/index.html +2 -2
- package/dist/index.d.ts +103 -1
- package/dist/index.js +789 -404
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/client/assets/index-BQg5aCT3.js.br +0 -0
- package/dist/client/assets/index-BQg5aCT3.js.map +0 -1
- package/dist/client/assets/index-TZ8BgtSM.js.br +0 -0
- package/dist/client/assets/vendor-BWTRqS51.js.br +0 -0
- package/dist/client/assets/vendor-BWTRqS51.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -385,10 +385,10 @@ var require_lib = __commonJS({
|
|
|
385
385
|
// src/index.ts
|
|
386
386
|
var import_cors2 = __toESM(require_lib(), 1);
|
|
387
387
|
import {
|
|
388
|
-
logger as
|
|
388
|
+
logger as logger30,
|
|
389
389
|
parseBooleanFromText
|
|
390
390
|
} from "@elizaos/core";
|
|
391
|
-
import
|
|
391
|
+
import express32 from "express";
|
|
392
392
|
import helmet2 from "helmet";
|
|
393
393
|
import * as fs9 from "fs";
|
|
394
394
|
import http from "http";
|
|
@@ -398,8 +398,8 @@ import { fileURLToPath as fileURLToPath2 } from "url";
|
|
|
398
398
|
|
|
399
399
|
// src/api/index.ts
|
|
400
400
|
var import_cors = __toESM(require_lib(), 1);
|
|
401
|
-
import { logger as
|
|
402
|
-
import
|
|
401
|
+
import { logger as logger26, validateUuid as validateUuid22 } from "@elizaos/core";
|
|
402
|
+
import express31 from "express";
|
|
403
403
|
import helmet from "helmet";
|
|
404
404
|
import { match } from "path-to-regexp";
|
|
405
405
|
import { Server as SocketIOServer } from "socket.io";
|
|
@@ -1149,9 +1149,9 @@ function createAgentMemoryRouter(agents) {
|
|
|
1149
1149
|
if (!runtime) {
|
|
1150
1150
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
1151
1151
|
}
|
|
1152
|
-
const
|
|
1152
|
+
const deleted = (await runtime.getAllMemories()).length;
|
|
1153
1153
|
await runtime.clearAllAgentMemories();
|
|
1154
|
-
sendSuccess(res, {
|
|
1154
|
+
sendSuccess(res, { deleted, message: "All agent memories cleared successfully" });
|
|
1155
1155
|
} catch (error) {
|
|
1156
1156
|
logger6.error("[DELETE ALL AGENT MEMORIES] Error deleting all agent memories:", error);
|
|
1157
1157
|
sendError(
|
|
@@ -1377,7 +1377,7 @@ function agentsRouter(agents, serverInstance) {
|
|
|
1377
1377
|
}
|
|
1378
1378
|
|
|
1379
1379
|
// src/api/messaging/index.ts
|
|
1380
|
-
import
|
|
1380
|
+
import express13 from "express";
|
|
1381
1381
|
|
|
1382
1382
|
// src/api/messaging/core.ts
|
|
1383
1383
|
import { logger as logger8, validateUuid as validateUuid8 } from "@elizaos/core";
|
|
@@ -2800,24 +2800,384 @@ Respond with just the title, nothing else.
|
|
|
2800
2800
|
return router;
|
|
2801
2801
|
}
|
|
2802
2802
|
|
|
2803
|
+
// src/api/messaging/sessions.ts
|
|
2804
|
+
import { logger as logger13, validateUuid as validateUuid13, ChannelType as ChannelType3 } from "@elizaos/core";
|
|
2805
|
+
import express12 from "express";
|
|
2806
|
+
|
|
2807
|
+
// ../../node_modules/uuid/dist/esm/stringify.js
|
|
2808
|
+
var byteToHex = [];
|
|
2809
|
+
for (let i = 0; i < 256; ++i) {
|
|
2810
|
+
byteToHex.push((i + 256).toString(16).slice(1));
|
|
2811
|
+
}
|
|
2812
|
+
function unsafeStringify(arr, offset = 0) {
|
|
2813
|
+
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
2814
|
+
}
|
|
2815
|
+
|
|
2816
|
+
// ../../node_modules/uuid/dist/esm/rng.js
|
|
2817
|
+
import { randomFillSync } from "crypto";
|
|
2818
|
+
var rnds8Pool = new Uint8Array(256);
|
|
2819
|
+
var poolPtr = rnds8Pool.length;
|
|
2820
|
+
function rng() {
|
|
2821
|
+
if (poolPtr > rnds8Pool.length - 16) {
|
|
2822
|
+
randomFillSync(rnds8Pool);
|
|
2823
|
+
poolPtr = 0;
|
|
2824
|
+
}
|
|
2825
|
+
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
// ../../node_modules/uuid/dist/esm/native.js
|
|
2829
|
+
import { randomUUID } from "crypto";
|
|
2830
|
+
var native_default = { randomUUID };
|
|
2831
|
+
|
|
2832
|
+
// ../../node_modules/uuid/dist/esm/v4.js
|
|
2833
|
+
function v4(options, buf, offset) {
|
|
2834
|
+
if (native_default.randomUUID && !buf && !options) {
|
|
2835
|
+
return native_default.randomUUID();
|
|
2836
|
+
}
|
|
2837
|
+
options = options || {};
|
|
2838
|
+
const rnds = options.random ?? options.rng?.() ?? rng();
|
|
2839
|
+
if (rnds.length < 16) {
|
|
2840
|
+
throw new Error("Random bytes length must be >= 16");
|
|
2841
|
+
}
|
|
2842
|
+
rnds[6] = rnds[6] & 15 | 64;
|
|
2843
|
+
rnds[8] = rnds[8] & 63 | 128;
|
|
2844
|
+
if (buf) {
|
|
2845
|
+
offset = offset || 0;
|
|
2846
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
2847
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
2848
|
+
}
|
|
2849
|
+
for (let i = 0; i < 16; ++i) {
|
|
2850
|
+
buf[offset + i] = rnds[i];
|
|
2851
|
+
}
|
|
2852
|
+
return buf;
|
|
2853
|
+
}
|
|
2854
|
+
return unsafeStringify(rnds);
|
|
2855
|
+
}
|
|
2856
|
+
var v4_default = v4;
|
|
2857
|
+
|
|
2858
|
+
// src/api/messaging/sessions.ts
|
|
2859
|
+
var SESSION_TIMEOUT_MS = parseInt(process.env.SESSION_TIMEOUT_MINUTES || "30") * 60 * 1e3;
|
|
2860
|
+
var sessions = /* @__PURE__ */ new Map();
|
|
2861
|
+
var DEFAULT_SERVER_ID4 = "00000000-0000-0000-0000-000000000000";
|
|
2862
|
+
var MAX_CONTENT_LENGTH = 4e3;
|
|
2863
|
+
var MAX_METADATA_SIZE = 1024 * 10;
|
|
2864
|
+
var MAX_LIMIT = 100;
|
|
2865
|
+
var DEFAULT_LIMIT = 50;
|
|
2866
|
+
function validateMetadata(metadata) {
|
|
2867
|
+
if (!metadata || typeof metadata !== "object") {
|
|
2868
|
+
return true;
|
|
2869
|
+
}
|
|
2870
|
+
const metadataStr = JSON.stringify(metadata);
|
|
2871
|
+
if (metadataStr.length > MAX_METADATA_SIZE) {
|
|
2872
|
+
throw new Error(`Metadata exceeds maximum size of ${MAX_METADATA_SIZE} bytes`);
|
|
2873
|
+
}
|
|
2874
|
+
return true;
|
|
2875
|
+
}
|
|
2876
|
+
function validateContent(content) {
|
|
2877
|
+
if (typeof content !== "string") {
|
|
2878
|
+
throw new Error("Content must be a string");
|
|
2879
|
+
}
|
|
2880
|
+
if (content.length === 0) {
|
|
2881
|
+
throw new Error("Content cannot be empty");
|
|
2882
|
+
}
|
|
2883
|
+
if (content.length > MAX_CONTENT_LENGTH) {
|
|
2884
|
+
throw new Error(`Content exceeds maximum length of ${MAX_CONTENT_LENGTH} characters`);
|
|
2885
|
+
}
|
|
2886
|
+
return true;
|
|
2887
|
+
}
|
|
2888
|
+
function errorResponse(res, status, message, details) {
|
|
2889
|
+
logger13.error(`[Sessions API] Error: ${message}`, details);
|
|
2890
|
+
return res.status(status).json({
|
|
2891
|
+
error: message,
|
|
2892
|
+
details: process.env.NODE_ENV === "development" ? details : void 0
|
|
2893
|
+
});
|
|
2894
|
+
}
|
|
2895
|
+
function createSessionsRouter(agents, serverInstance) {
|
|
2896
|
+
const router = express12.Router();
|
|
2897
|
+
router.get("/sessions/health", (_req, res) => {
|
|
2898
|
+
const response = {
|
|
2899
|
+
status: "healthy",
|
|
2900
|
+
activeSessions: sessions.size,
|
|
2901
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
2902
|
+
};
|
|
2903
|
+
res.json(response);
|
|
2904
|
+
});
|
|
2905
|
+
router.post("/sessions", async (req, res) => {
|
|
2906
|
+
try {
|
|
2907
|
+
const body = req.body;
|
|
2908
|
+
if (!body.agentId || !body.userId) {
|
|
2909
|
+
return errorResponse(res, 400, "Missing required fields: agentId and userId");
|
|
2910
|
+
}
|
|
2911
|
+
if (!validateUuid13(body.agentId) || !validateUuid13(body.userId)) {
|
|
2912
|
+
return errorResponse(res, 400, "Invalid UUID format for agentId or userId");
|
|
2913
|
+
}
|
|
2914
|
+
const agent = agents.get(body.agentId);
|
|
2915
|
+
if (!agent) {
|
|
2916
|
+
return errorResponse(res, 404, "Agent not found");
|
|
2917
|
+
}
|
|
2918
|
+
if (body.metadata && !validateMetadata(body.metadata)) {
|
|
2919
|
+
return errorResponse(res, 400, "Invalid metadata");
|
|
2920
|
+
}
|
|
2921
|
+
const sessionId = v4_default();
|
|
2922
|
+
const channelId = v4_default();
|
|
2923
|
+
await serverInstance.createChannel({
|
|
2924
|
+
id: channelId,
|
|
2925
|
+
name: `session-${sessionId}`,
|
|
2926
|
+
type: ChannelType3.DM,
|
|
2927
|
+
messageServerId: DEFAULT_SERVER_ID4,
|
|
2928
|
+
metadata: {
|
|
2929
|
+
sessionId,
|
|
2930
|
+
agentId: body.agentId,
|
|
2931
|
+
userId: body.userId,
|
|
2932
|
+
...body.metadata || {}
|
|
2933
|
+
}
|
|
2934
|
+
});
|
|
2935
|
+
await serverInstance.addParticipantsToChannel(channelId, [body.agentId]);
|
|
2936
|
+
const session = {
|
|
2937
|
+
id: sessionId,
|
|
2938
|
+
agentId: body.agentId,
|
|
2939
|
+
channelId,
|
|
2940
|
+
userId: body.userId,
|
|
2941
|
+
metadata: body.metadata || {},
|
|
2942
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2943
|
+
lastActivity: /* @__PURE__ */ new Date()
|
|
2944
|
+
};
|
|
2945
|
+
sessions.set(sessionId, session);
|
|
2946
|
+
const response = {
|
|
2947
|
+
sessionId,
|
|
2948
|
+
agentId: session.agentId,
|
|
2949
|
+
userId: session.userId,
|
|
2950
|
+
createdAt: session.createdAt,
|
|
2951
|
+
metadata: session.metadata
|
|
2952
|
+
};
|
|
2953
|
+
res.status(201).json(response);
|
|
2954
|
+
} catch (error) {
|
|
2955
|
+
errorResponse(
|
|
2956
|
+
res,
|
|
2957
|
+
500,
|
|
2958
|
+
"Failed to create session",
|
|
2959
|
+
error instanceof Error ? error.message : String(error)
|
|
2960
|
+
);
|
|
2961
|
+
}
|
|
2962
|
+
});
|
|
2963
|
+
router.get("/sessions/:sessionId", async (req, res) => {
|
|
2964
|
+
const { sessionId } = req.params;
|
|
2965
|
+
const session = sessions.get(sessionId);
|
|
2966
|
+
if (!session) {
|
|
2967
|
+
return errorResponse(res, 404, "Session not found");
|
|
2968
|
+
}
|
|
2969
|
+
const response = {
|
|
2970
|
+
sessionId: session.id,
|
|
2971
|
+
agentId: session.agentId,
|
|
2972
|
+
userId: session.userId,
|
|
2973
|
+
createdAt: session.createdAt,
|
|
2974
|
+
lastActivity: session.lastActivity,
|
|
2975
|
+
metadata: session.metadata
|
|
2976
|
+
};
|
|
2977
|
+
res.json(response);
|
|
2978
|
+
});
|
|
2979
|
+
router.post("/sessions/:sessionId/messages", async (req, res) => {
|
|
2980
|
+
try {
|
|
2981
|
+
const { sessionId } = req.params;
|
|
2982
|
+
const body = req.body;
|
|
2983
|
+
const session = sessions.get(sessionId);
|
|
2984
|
+
if (!session) {
|
|
2985
|
+
return errorResponse(res, 404, "Session not found");
|
|
2986
|
+
}
|
|
2987
|
+
try {
|
|
2988
|
+
validateContent(body.content);
|
|
2989
|
+
} catch (error) {
|
|
2990
|
+
return errorResponse(res, 400, error instanceof Error ? error.message : String(error));
|
|
2991
|
+
}
|
|
2992
|
+
if (body.metadata && !validateMetadata(body.metadata)) {
|
|
2993
|
+
return errorResponse(res, 400, "Invalid metadata");
|
|
2994
|
+
}
|
|
2995
|
+
session.lastActivity = /* @__PURE__ */ new Date();
|
|
2996
|
+
const message = await serverInstance.createMessage({
|
|
2997
|
+
channelId: session.channelId,
|
|
2998
|
+
authorId: session.userId,
|
|
2999
|
+
content: body.content,
|
|
3000
|
+
rawMessage: {
|
|
3001
|
+
content: body.content,
|
|
3002
|
+
attachments: body.attachments
|
|
3003
|
+
},
|
|
3004
|
+
sourceType: "user",
|
|
3005
|
+
metadata: {
|
|
3006
|
+
sessionId,
|
|
3007
|
+
...body.metadata || {}
|
|
3008
|
+
}
|
|
3009
|
+
});
|
|
3010
|
+
res.status(201).json({
|
|
3011
|
+
id: message.id,
|
|
3012
|
+
content: message.content,
|
|
3013
|
+
authorId: message.authorId,
|
|
3014
|
+
createdAt: message.createdAt,
|
|
3015
|
+
metadata: message.metadata
|
|
3016
|
+
});
|
|
3017
|
+
} catch (error) {
|
|
3018
|
+
errorResponse(
|
|
3019
|
+
res,
|
|
3020
|
+
500,
|
|
3021
|
+
"Failed to send message",
|
|
3022
|
+
error instanceof Error ? error.message : String(error)
|
|
3023
|
+
);
|
|
3024
|
+
}
|
|
3025
|
+
});
|
|
3026
|
+
router.get("/sessions/:sessionId/messages", async (req, res) => {
|
|
3027
|
+
try {
|
|
3028
|
+
const { sessionId } = req.params;
|
|
3029
|
+
const query = req.query;
|
|
3030
|
+
const session = sessions.get(sessionId);
|
|
3031
|
+
if (!session) {
|
|
3032
|
+
return errorResponse(res, 404, "Session not found");
|
|
3033
|
+
}
|
|
3034
|
+
let messageLimit = DEFAULT_LIMIT;
|
|
3035
|
+
if (query.limit) {
|
|
3036
|
+
const parsedLimit = parseInt(query.limit, 10);
|
|
3037
|
+
if (isNaN(parsedLimit) || parsedLimit < 1) {
|
|
3038
|
+
return errorResponse(res, 400, "Invalid limit parameter");
|
|
3039
|
+
}
|
|
3040
|
+
messageLimit = Math.min(parsedLimit, MAX_LIMIT);
|
|
3041
|
+
}
|
|
3042
|
+
let beforeDate;
|
|
3043
|
+
let afterDate;
|
|
3044
|
+
if (query.before) {
|
|
3045
|
+
const beforeTimestamp = parseInt(query.before, 10);
|
|
3046
|
+
if (isNaN(beforeTimestamp)) {
|
|
3047
|
+
return errorResponse(res, 400, "Invalid before parameter");
|
|
3048
|
+
}
|
|
3049
|
+
beforeDate = new Date(beforeTimestamp);
|
|
3050
|
+
}
|
|
3051
|
+
if (query.after) {
|
|
3052
|
+
const afterTimestamp = parseInt(query.after, 10);
|
|
3053
|
+
if (isNaN(afterTimestamp)) {
|
|
3054
|
+
return errorResponse(res, 400, "Invalid after parameter");
|
|
3055
|
+
}
|
|
3056
|
+
afterDate = new Date(afterTimestamp);
|
|
3057
|
+
}
|
|
3058
|
+
let messages;
|
|
3059
|
+
if (afterDate) {
|
|
3060
|
+
messages = await serverInstance.getMessagesForChannel(
|
|
3061
|
+
session.channelId,
|
|
3062
|
+
messageLimit * 2,
|
|
3063
|
+
// Get extra to ensure we have enough after filtering
|
|
3064
|
+
void 0
|
|
3065
|
+
// Don't use beforeDate for initial query
|
|
3066
|
+
);
|
|
3067
|
+
messages = messages.filter((msg) => msg.createdAt > afterDate).slice(0, messageLimit);
|
|
3068
|
+
} else {
|
|
3069
|
+
messages = await serverInstance.getMessagesForChannel(
|
|
3070
|
+
session.channelId,
|
|
3071
|
+
messageLimit,
|
|
3072
|
+
beforeDate
|
|
3073
|
+
);
|
|
3074
|
+
}
|
|
3075
|
+
const simplifiedMessages = messages.map((msg) => {
|
|
3076
|
+
let rawMessage = {};
|
|
3077
|
+
try {
|
|
3078
|
+
rawMessage = typeof msg.rawMessage === "string" ? JSON.parse(msg.rawMessage) : msg.rawMessage || {};
|
|
3079
|
+
} catch (error) {
|
|
3080
|
+
logger13.warn(
|
|
3081
|
+
`[Sessions API] Failed to parse rawMessage for message ${msg.id}`,
|
|
3082
|
+
error instanceof Error ? error.message : String(error)
|
|
3083
|
+
);
|
|
3084
|
+
}
|
|
3085
|
+
return {
|
|
3086
|
+
id: msg.id,
|
|
3087
|
+
content: msg.content,
|
|
3088
|
+
authorId: msg.authorId,
|
|
3089
|
+
isAgent: msg.sourceType === "agent_response",
|
|
3090
|
+
createdAt: msg.createdAt,
|
|
3091
|
+
metadata: {
|
|
3092
|
+
...msg.metadata,
|
|
3093
|
+
thought: rawMessage.thought,
|
|
3094
|
+
actions: rawMessage.actions
|
|
3095
|
+
}
|
|
3096
|
+
};
|
|
3097
|
+
});
|
|
3098
|
+
const response = {
|
|
3099
|
+
messages: simplifiedMessages,
|
|
3100
|
+
hasMore: messages.length === messageLimit
|
|
3101
|
+
};
|
|
3102
|
+
res.json(response);
|
|
3103
|
+
} catch (error) {
|
|
3104
|
+
errorResponse(
|
|
3105
|
+
res,
|
|
3106
|
+
500,
|
|
3107
|
+
"Failed to fetch messages",
|
|
3108
|
+
error instanceof Error ? error.message : String(error)
|
|
3109
|
+
);
|
|
3110
|
+
}
|
|
3111
|
+
});
|
|
3112
|
+
router.delete("/sessions/:sessionId", async (req, res) => {
|
|
3113
|
+
try {
|
|
3114
|
+
const { sessionId } = req.params;
|
|
3115
|
+
const session = sessions.get(sessionId);
|
|
3116
|
+
if (!session) {
|
|
3117
|
+
return errorResponse(res, 404, "Session not found");
|
|
3118
|
+
}
|
|
3119
|
+
sessions.delete(sessionId);
|
|
3120
|
+
res.json({ success: true });
|
|
3121
|
+
} catch (error) {
|
|
3122
|
+
errorResponse(
|
|
3123
|
+
res,
|
|
3124
|
+
500,
|
|
3125
|
+
"Failed to delete session",
|
|
3126
|
+
error instanceof Error ? error.message : String(error)
|
|
3127
|
+
);
|
|
3128
|
+
}
|
|
3129
|
+
});
|
|
3130
|
+
router.get("/sessions", async (_req, res) => {
|
|
3131
|
+
const activeSessions = Array.from(sessions.values()).map((session) => ({
|
|
3132
|
+
sessionId: session.id,
|
|
3133
|
+
agentId: session.agentId,
|
|
3134
|
+
userId: session.userId,
|
|
3135
|
+
createdAt: session.createdAt,
|
|
3136
|
+
lastActivity: session.lastActivity,
|
|
3137
|
+
metadata: session.metadata
|
|
3138
|
+
}));
|
|
3139
|
+
res.json({
|
|
3140
|
+
sessions: activeSessions,
|
|
3141
|
+
total: activeSessions.length
|
|
3142
|
+
});
|
|
3143
|
+
});
|
|
3144
|
+
const cleanupInterval = setInterval(
|
|
3145
|
+
() => {
|
|
3146
|
+
const now = /* @__PURE__ */ new Date();
|
|
3147
|
+
for (const [sessionId, session] of sessions.entries()) {
|
|
3148
|
+
if (now.getTime() - session.lastActivity.getTime() > SESSION_TIMEOUT_MS) {
|
|
3149
|
+
sessions.delete(sessionId);
|
|
3150
|
+
logger13.info(`[Sessions API] Cleaned up inactive session: ${sessionId}`);
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
},
|
|
3154
|
+
5 * 60 * 1e3
|
|
3155
|
+
);
|
|
3156
|
+
process.on("SIGTERM", () => {
|
|
3157
|
+
clearInterval(cleanupInterval);
|
|
3158
|
+
});
|
|
3159
|
+
return router;
|
|
3160
|
+
}
|
|
3161
|
+
|
|
2803
3162
|
// src/api/messaging/index.ts
|
|
2804
3163
|
function messagingRouter(agents, serverInstance) {
|
|
2805
|
-
const router =
|
|
3164
|
+
const router = express13.Router();
|
|
2806
3165
|
if (!serverInstance) {
|
|
2807
3166
|
throw new Error("ServerInstance is required for messaging router");
|
|
2808
3167
|
}
|
|
2809
3168
|
router.use("/", createMessagingCoreRouter(serverInstance));
|
|
2810
3169
|
router.use("/", createServersRouter(serverInstance));
|
|
2811
3170
|
router.use("/", createChannelsRouter(agents, serverInstance));
|
|
3171
|
+
router.use("/", createSessionsRouter(agents, serverInstance));
|
|
2812
3172
|
return router;
|
|
2813
3173
|
}
|
|
2814
3174
|
|
|
2815
3175
|
// src/api/media/index.ts
|
|
2816
|
-
import
|
|
3176
|
+
import express16 from "express";
|
|
2817
3177
|
|
|
2818
3178
|
// src/api/media/agents.ts
|
|
2819
|
-
import { validateUuid as
|
|
2820
|
-
import
|
|
3179
|
+
import { validateUuid as validateUuid14, logger as logger14, getContentTypeFromMimeType } from "@elizaos/core";
|
|
3180
|
+
import express14 from "express";
|
|
2821
3181
|
import multer2 from "multer";
|
|
2822
3182
|
import fs2 from "fs";
|
|
2823
3183
|
import path2 from "path";
|
|
@@ -2851,10 +3211,10 @@ async function saveUploadedFile(file, agentId) {
|
|
|
2851
3211
|
return { filename, url };
|
|
2852
3212
|
}
|
|
2853
3213
|
function createAgentMediaRouter() {
|
|
2854
|
-
const router =
|
|
3214
|
+
const router = express14.Router();
|
|
2855
3215
|
router.post("/:agentId/upload-media", upload.single("file"), async (req, res) => {
|
|
2856
|
-
|
|
2857
|
-
const agentId =
|
|
3216
|
+
logger14.debug("[MEDIA UPLOAD] Processing media upload with multer");
|
|
3217
|
+
const agentId = validateUuid14(req.params.agentId);
|
|
2858
3218
|
if (!agentId) {
|
|
2859
3219
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
2860
3220
|
}
|
|
@@ -2872,7 +3232,7 @@ function createAgentMediaRouter() {
|
|
|
2872
3232
|
}
|
|
2873
3233
|
try {
|
|
2874
3234
|
const result = await saveUploadedFile(req.file, agentId);
|
|
2875
|
-
|
|
3235
|
+
logger14.info(
|
|
2876
3236
|
`[MEDIA UPLOAD] Successfully uploaded ${mediaType}: ${result.filename}. URL: ${result.url}`
|
|
2877
3237
|
);
|
|
2878
3238
|
sendSuccess(res, {
|
|
@@ -2883,7 +3243,7 @@ function createAgentMediaRouter() {
|
|
|
2883
3243
|
size: req.file.size
|
|
2884
3244
|
});
|
|
2885
3245
|
} catch (error) {
|
|
2886
|
-
|
|
3246
|
+
logger14.error(`[MEDIA UPLOAD] Error processing upload: ${error}`);
|
|
2887
3247
|
sendError(
|
|
2888
3248
|
res,
|
|
2889
3249
|
500,
|
|
@@ -2897,8 +3257,8 @@ function createAgentMediaRouter() {
|
|
|
2897
3257
|
}
|
|
2898
3258
|
|
|
2899
3259
|
// src/api/media/channels.ts
|
|
2900
|
-
import { validateUuid as
|
|
2901
|
-
import
|
|
3260
|
+
import { validateUuid as validateUuid15, logger as logger15 } from "@elizaos/core";
|
|
3261
|
+
import express15 from "express";
|
|
2902
3262
|
import rateLimit2 from "express-rate-limit";
|
|
2903
3263
|
import multer3 from "multer";
|
|
2904
3264
|
import fs3 from "fs";
|
|
@@ -2933,7 +3293,7 @@ async function saveUploadedFile2(file, channelId) {
|
|
|
2933
3293
|
return { filename, url };
|
|
2934
3294
|
}
|
|
2935
3295
|
function createChannelMediaRouter() {
|
|
2936
|
-
const router =
|
|
3296
|
+
const router = express15.Router();
|
|
2937
3297
|
const uploadMediaRateLimiter = rateLimit2({
|
|
2938
3298
|
windowMs: 15 * 60 * 1e3,
|
|
2939
3299
|
// 15 minutes
|
|
@@ -2947,7 +3307,7 @@ function createChannelMediaRouter() {
|
|
|
2947
3307
|
// Apply rate limiter
|
|
2948
3308
|
upload2.single("file"),
|
|
2949
3309
|
async (req, res) => {
|
|
2950
|
-
const channelId =
|
|
3310
|
+
const channelId = validateUuid15(req.params.channelId);
|
|
2951
3311
|
if (!channelId) {
|
|
2952
3312
|
res.status(400).json({ success: false, error: "Invalid channelId format" });
|
|
2953
3313
|
return;
|
|
@@ -2958,7 +3318,7 @@ function createChannelMediaRouter() {
|
|
|
2958
3318
|
}
|
|
2959
3319
|
try {
|
|
2960
3320
|
const result = await saveUploadedFile2(req.file, channelId);
|
|
2961
|
-
|
|
3321
|
+
logger15.info(
|
|
2962
3322
|
`[Channel Media Upload] File uploaded for channel ${channelId}: ${result.filename}. URL: ${result.url}`
|
|
2963
3323
|
);
|
|
2964
3324
|
res.json({
|
|
@@ -2973,7 +3333,7 @@ function createChannelMediaRouter() {
|
|
|
2973
3333
|
}
|
|
2974
3334
|
});
|
|
2975
3335
|
} catch (error) {
|
|
2976
|
-
|
|
3336
|
+
logger15.error(
|
|
2977
3337
|
`[Channel Media Upload] Error processing upload for channel ${channelId}: ${error.message}`,
|
|
2978
3338
|
error
|
|
2979
3339
|
);
|
|
@@ -2986,32 +3346,32 @@ function createChannelMediaRouter() {
|
|
|
2986
3346
|
|
|
2987
3347
|
// src/api/media/index.ts
|
|
2988
3348
|
function mediaRouter() {
|
|
2989
|
-
const router =
|
|
3349
|
+
const router = express16.Router();
|
|
2990
3350
|
router.use("/agents", createAgentMediaRouter());
|
|
2991
3351
|
router.use("/channels", createChannelMediaRouter());
|
|
2992
3352
|
return router;
|
|
2993
3353
|
}
|
|
2994
3354
|
|
|
2995
3355
|
// src/api/memory/index.ts
|
|
2996
|
-
import
|
|
3356
|
+
import express18 from "express";
|
|
2997
3357
|
|
|
2998
3358
|
// src/api/memory/groups.ts
|
|
2999
|
-
import { validateUuid as
|
|
3000
|
-
import
|
|
3359
|
+
import { validateUuid as validateUuid17, logger as logger18, createUniqueUuid as createUniqueUuid4, ChannelType as ChannelType4 } from "@elizaos/core";
|
|
3360
|
+
import express17 from "express";
|
|
3001
3361
|
|
|
3002
3362
|
// src/api/shared/file-utils.ts
|
|
3003
3363
|
import fs4 from "fs";
|
|
3004
3364
|
import path4 from "path";
|
|
3005
|
-
import { logger as
|
|
3365
|
+
import { logger as logger16 } from "@elizaos/core";
|
|
3006
3366
|
var cleanupUploadedFile = (file) => {
|
|
3007
|
-
|
|
3367
|
+
logger16.debug(`[FILE] Multer file ${file.originalname} in memory, no cleanup needed`);
|
|
3008
3368
|
};
|
|
3009
3369
|
|
|
3010
3370
|
// src/upload.ts
|
|
3011
3371
|
import fs5 from "fs";
|
|
3012
3372
|
import path5 from "path";
|
|
3013
3373
|
import multer4 from "multer";
|
|
3014
|
-
import { validateUuid as
|
|
3374
|
+
import { validateUuid as validateUuid16, logger as logger17 } from "@elizaos/core";
|
|
3015
3375
|
var storage3 = multer4.memoryStorage();
|
|
3016
3376
|
var agentAudioUpload = () => multer4({
|
|
3017
3377
|
storage: storage3,
|
|
@@ -3033,10 +3393,10 @@ function validateAudioFile(file) {
|
|
|
3033
3393
|
|
|
3034
3394
|
// src/api/memory/groups.ts
|
|
3035
3395
|
function createGroupMemoryRouter(agents, serverInstance) {
|
|
3036
|
-
const router =
|
|
3396
|
+
const router = express17.Router();
|
|
3037
3397
|
const db = serverInstance?.database;
|
|
3038
3398
|
router.post("/groups/:serverId", async (req, res) => {
|
|
3039
|
-
const serverId =
|
|
3399
|
+
const serverId = validateUuid17(req.params.serverId);
|
|
3040
3400
|
const { name, worldId, source, metadata, agentIds = [] } = req.body;
|
|
3041
3401
|
if (!Array.isArray(agentIds) || agentIds.length === 0) {
|
|
3042
3402
|
return sendError(res, 400, "BAD_REQUEST", "agentIds must be a non-empty array");
|
|
@@ -3058,7 +3418,7 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
3058
3418
|
id: roomId,
|
|
3059
3419
|
name: roomName,
|
|
3060
3420
|
source,
|
|
3061
|
-
type:
|
|
3421
|
+
type: ChannelType4.API,
|
|
3062
3422
|
worldId,
|
|
3063
3423
|
serverId,
|
|
3064
3424
|
metadata,
|
|
@@ -3072,10 +3432,10 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
3072
3432
|
name: roomName,
|
|
3073
3433
|
source: "client",
|
|
3074
3434
|
worldId,
|
|
3075
|
-
type:
|
|
3435
|
+
type: ChannelType4.API
|
|
3076
3436
|
});
|
|
3077
3437
|
} catch (error) {
|
|
3078
|
-
|
|
3438
|
+
logger18.error(`[ROOM CREATE] Error creating room for agent ${agentId}:`, error);
|
|
3079
3439
|
errors.push({
|
|
3080
3440
|
agentId,
|
|
3081
3441
|
code: error instanceof Error && error.message === "Agent not found" ? "NOT_FOUND" : "CREATE_ERROR",
|
|
@@ -3098,7 +3458,7 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
3098
3458
|
});
|
|
3099
3459
|
});
|
|
3100
3460
|
router.delete("/groups/:serverId", async (req, res) => {
|
|
3101
|
-
const worldId =
|
|
3461
|
+
const worldId = validateUuid17(req.params.serverId);
|
|
3102
3462
|
if (!worldId) {
|
|
3103
3463
|
return sendError(res, 400, "INVALID_ID", "Invalid serverId (worldId) format");
|
|
3104
3464
|
}
|
|
@@ -3109,7 +3469,7 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
3109
3469
|
await db.deleteRoomsByWorldId(worldId);
|
|
3110
3470
|
res.status(204).send();
|
|
3111
3471
|
} catch (error) {
|
|
3112
|
-
|
|
3472
|
+
logger18.error("[GROUP DELETE] Error deleting group:", error);
|
|
3113
3473
|
sendError(
|
|
3114
3474
|
res,
|
|
3115
3475
|
500,
|
|
@@ -3120,7 +3480,7 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
3120
3480
|
}
|
|
3121
3481
|
});
|
|
3122
3482
|
router.delete("/groups/:serverId/memories", async (req, res) => {
|
|
3123
|
-
const worldId =
|
|
3483
|
+
const worldId = validateUuid17(req.params.serverId);
|
|
3124
3484
|
if (!worldId) {
|
|
3125
3485
|
return sendError(res, 400, "INVALID_ID", "Invalid serverId (worldId) format");
|
|
3126
3486
|
}
|
|
@@ -3135,7 +3495,7 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
3135
3495
|
}
|
|
3136
3496
|
res.status(204).send();
|
|
3137
3497
|
} catch (error) {
|
|
3138
|
-
|
|
3498
|
+
logger18.error("[GROUP MEMORIES DELETE] Error clearing memories:", error);
|
|
3139
3499
|
sendError(
|
|
3140
3500
|
res,
|
|
3141
3501
|
500,
|
|
@@ -3150,7 +3510,7 @@ function createGroupMemoryRouter(agents, serverInstance) {
|
|
|
3150
3510
|
|
|
3151
3511
|
// src/api/memory/index.ts
|
|
3152
3512
|
function memoryRouter(agents, serverInstance) {
|
|
3153
|
-
const router =
|
|
3513
|
+
const router = express18.Router();
|
|
3154
3514
|
router.use("/", createAgentMemoryRouter(agents));
|
|
3155
3515
|
router.use("/", createGroupMemoryRouter(agents, serverInstance));
|
|
3156
3516
|
router.use("/", createRoomManagementRouter(agents));
|
|
@@ -3158,22 +3518,22 @@ function memoryRouter(agents, serverInstance) {
|
|
|
3158
3518
|
}
|
|
3159
3519
|
|
|
3160
3520
|
// src/api/audio/index.ts
|
|
3161
|
-
import
|
|
3521
|
+
import express22 from "express";
|
|
3162
3522
|
|
|
3163
3523
|
// src/api/audio/processing.ts
|
|
3164
|
-
import { logger as
|
|
3165
|
-
import
|
|
3524
|
+
import { logger as logger19, ModelType as ModelType2, validateUuid as validateUuid18 } from "@elizaos/core";
|
|
3525
|
+
import express19 from "express";
|
|
3166
3526
|
import fs6 from "fs";
|
|
3167
3527
|
import os from "os";
|
|
3168
3528
|
import path6 from "path";
|
|
3169
3529
|
function createAudioProcessingRouter(agents) {
|
|
3170
|
-
const router =
|
|
3530
|
+
const router = express19.Router();
|
|
3171
3531
|
router.use(createUploadRateLimit());
|
|
3172
3532
|
router.use(createFileSystemRateLimit());
|
|
3173
3533
|
router.post("/:agentId/audio-messages", agentAudioUpload().single("file"), async (req, res) => {
|
|
3174
3534
|
const audioReq = req;
|
|
3175
|
-
|
|
3176
|
-
const agentId =
|
|
3535
|
+
logger19.debug("[AUDIO MESSAGE] Processing audio message");
|
|
3536
|
+
const agentId = validateUuid18(req.params.agentId);
|
|
3177
3537
|
if (!agentId) {
|
|
3178
3538
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
3179
3539
|
}
|
|
@@ -3201,11 +3561,11 @@ function createAudioProcessingRouter(agents) {
|
|
|
3201
3561
|
);
|
|
3202
3562
|
}
|
|
3203
3563
|
const transcription = await runtime.useModel(ModelType2.TRANSCRIPTION, audioFile.buffer);
|
|
3204
|
-
|
|
3564
|
+
logger19.info(`[AUDIO MESSAGE] Transcription for agent ${agentId}: ${transcription}`);
|
|
3205
3565
|
cleanupUploadedFile(audioFile);
|
|
3206
3566
|
sendSuccess(res, { transcription, message: "Audio transcribed, further processing TBD." });
|
|
3207
3567
|
} catch (error) {
|
|
3208
|
-
|
|
3568
|
+
logger19.error("[AUDIO MESSAGE] Error processing audio:", error);
|
|
3209
3569
|
cleanupUploadedFile(audioFile);
|
|
3210
3570
|
sendError(
|
|
3211
3571
|
res,
|
|
@@ -3218,8 +3578,8 @@ function createAudioProcessingRouter(agents) {
|
|
|
3218
3578
|
});
|
|
3219
3579
|
router.post("/:agentId/transcriptions", agentAudioUpload().single("file"), async (req, res) => {
|
|
3220
3580
|
const audioReq = req;
|
|
3221
|
-
|
|
3222
|
-
const agentId =
|
|
3581
|
+
logger19.debug("[TRANSCRIPTION] Request to transcribe audio");
|
|
3582
|
+
const agentId = validateUuid18(req.params.agentId);
|
|
3223
3583
|
if (!agentId) {
|
|
3224
3584
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
3225
3585
|
}
|
|
@@ -3233,7 +3593,7 @@ function createAudioProcessingRouter(agents) {
|
|
|
3233
3593
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
3234
3594
|
}
|
|
3235
3595
|
try {
|
|
3236
|
-
|
|
3596
|
+
logger19.debug("[TRANSCRIPTION] Reading audio file");
|
|
3237
3597
|
if (!validateAudioFile(audioFile)) {
|
|
3238
3598
|
cleanupUploadedFile(audioFile);
|
|
3239
3599
|
return sendError(res, 400, "INVALID_FILE_TYPE", "Invalid audio file type");
|
|
@@ -3247,16 +3607,16 @@ function createAudioProcessingRouter(agents) {
|
|
|
3247
3607
|
`Audio file too large (max ${MAX_FILE_SIZE_DISPLAY})`
|
|
3248
3608
|
);
|
|
3249
3609
|
}
|
|
3250
|
-
|
|
3610
|
+
logger19.debug("[TRANSCRIPTION] Transcribing audio");
|
|
3251
3611
|
const transcription = await runtime.useModel(ModelType2.TRANSCRIPTION, audioFile.buffer);
|
|
3252
3612
|
cleanupUploadedFile(audioFile);
|
|
3253
3613
|
if (!transcription) {
|
|
3254
3614
|
return sendError(res, 500, "PROCESSING_ERROR", "Failed to transcribe audio");
|
|
3255
3615
|
}
|
|
3256
|
-
|
|
3616
|
+
logger19.success("[TRANSCRIPTION] Successfully transcribed audio");
|
|
3257
3617
|
sendSuccess(res, { text: transcription });
|
|
3258
3618
|
} catch (error) {
|
|
3259
|
-
|
|
3619
|
+
logger19.error("[TRANSCRIPTION] Error transcribing audio:", error);
|
|
3260
3620
|
cleanupUploadedFile(audioFile);
|
|
3261
3621
|
sendError(
|
|
3262
3622
|
res,
|
|
@@ -3271,8 +3631,8 @@ function createAudioProcessingRouter(agents) {
|
|
|
3271
3631
|
}
|
|
3272
3632
|
|
|
3273
3633
|
// src/api/audio/synthesis.ts
|
|
3274
|
-
import { validateUuid as
|
|
3275
|
-
import
|
|
3634
|
+
import { validateUuid as validateUuid19, logger as logger20, ModelType as ModelType3 } from "@elizaos/core";
|
|
3635
|
+
import express20 from "express";
|
|
3276
3636
|
|
|
3277
3637
|
// src/api/audio/audioBuffer.ts
|
|
3278
3638
|
import { Readable } from "stream";
|
|
@@ -3329,9 +3689,9 @@ async function convertToAudioBuffer(speechResponse, detectMimeType) {
|
|
|
3329
3689
|
|
|
3330
3690
|
// src/api/audio/synthesis.ts
|
|
3331
3691
|
function createSynthesisRouter(agents) {
|
|
3332
|
-
const router =
|
|
3692
|
+
const router = express20.Router();
|
|
3333
3693
|
router.post("/:agentId/audio-messages/synthesize", async (req, res) => {
|
|
3334
|
-
const agentId =
|
|
3694
|
+
const agentId = validateUuid19(req.params.agentId);
|
|
3335
3695
|
if (!agentId) {
|
|
3336
3696
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
3337
3697
|
}
|
|
@@ -3346,14 +3706,14 @@ function createSynthesisRouter(agents) {
|
|
|
3346
3706
|
try {
|
|
3347
3707
|
const speechResponse = await runtime.useModel(ModelType3.TEXT_TO_SPEECH, text);
|
|
3348
3708
|
const audioResult = await convertToAudioBuffer(speechResponse, true);
|
|
3349
|
-
|
|
3709
|
+
logger20.debug("[TTS] Setting response headers");
|
|
3350
3710
|
res.set({
|
|
3351
3711
|
"Content-Type": audioResult.mimeType,
|
|
3352
3712
|
"Content-Length": audioResult.buffer.length.toString()
|
|
3353
3713
|
});
|
|
3354
3714
|
res.send(audioResult.buffer);
|
|
3355
3715
|
} catch (error) {
|
|
3356
|
-
|
|
3716
|
+
logger20.error("[TTS] Error generating speech:", error);
|
|
3357
3717
|
sendError(
|
|
3358
3718
|
res,
|
|
3359
3719
|
500,
|
|
@@ -3364,8 +3724,8 @@ function createSynthesisRouter(agents) {
|
|
|
3364
3724
|
}
|
|
3365
3725
|
});
|
|
3366
3726
|
router.post("/:agentId/speech/generate", async (req, res) => {
|
|
3367
|
-
|
|
3368
|
-
const agentId =
|
|
3727
|
+
logger20.debug("[SPEECH GENERATE] Request to generate speech from text");
|
|
3728
|
+
const agentId = validateUuid19(req.params.agentId);
|
|
3369
3729
|
if (!agentId) {
|
|
3370
3730
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
3371
3731
|
}
|
|
@@ -3378,21 +3738,21 @@ function createSynthesisRouter(agents) {
|
|
|
3378
3738
|
return sendError(res, 404, "NOT_FOUND", "Agent not found");
|
|
3379
3739
|
}
|
|
3380
3740
|
try {
|
|
3381
|
-
|
|
3741
|
+
logger20.debug("[SPEECH GENERATE] Using text-to-speech model");
|
|
3382
3742
|
const speechResponse = await runtime.useModel(ModelType3.TEXT_TO_SPEECH, text);
|
|
3383
3743
|
const audioResult = await convertToAudioBuffer(speechResponse, true);
|
|
3384
|
-
|
|
3385
|
-
|
|
3744
|
+
logger20.debug("[SPEECH GENERATE] Detected audio MIME type:", audioResult.mimeType);
|
|
3745
|
+
logger20.debug("[SPEECH GENERATE] Setting response headers");
|
|
3386
3746
|
res.set({
|
|
3387
3747
|
"Content-Type": audioResult.mimeType,
|
|
3388
3748
|
"Content-Length": audioResult.buffer.length.toString()
|
|
3389
3749
|
});
|
|
3390
3750
|
res.send(audioResult.buffer);
|
|
3391
|
-
|
|
3751
|
+
logger20.success(
|
|
3392
3752
|
`[SPEECH GENERATE] Successfully generated speech for: ${runtime.character.name}`
|
|
3393
3753
|
);
|
|
3394
3754
|
} catch (error) {
|
|
3395
|
-
|
|
3755
|
+
logger20.error("[SPEECH GENERATE] Error generating speech:", error);
|
|
3396
3756
|
sendError(
|
|
3397
3757
|
res,
|
|
3398
3758
|
500,
|
|
@@ -3407,19 +3767,19 @@ function createSynthesisRouter(agents) {
|
|
|
3407
3767
|
|
|
3408
3768
|
// src/api/audio/conversation.ts
|
|
3409
3769
|
import {
|
|
3410
|
-
validateUuid as
|
|
3411
|
-
logger as
|
|
3770
|
+
validateUuid as validateUuid20,
|
|
3771
|
+
logger as logger21,
|
|
3412
3772
|
ModelType as ModelType4,
|
|
3413
|
-
ChannelType as
|
|
3773
|
+
ChannelType as ChannelType5,
|
|
3414
3774
|
createUniqueUuid as createUniqueUuid5,
|
|
3415
3775
|
composePrompt,
|
|
3416
3776
|
messageHandlerTemplate
|
|
3417
3777
|
} from "@elizaos/core";
|
|
3418
|
-
import
|
|
3778
|
+
import express21 from "express";
|
|
3419
3779
|
function createConversationRouter(agents) {
|
|
3420
|
-
const router =
|
|
3780
|
+
const router = express21.Router();
|
|
3421
3781
|
router.post("/:agentId/speech/conversation", async (req, res) => {
|
|
3422
|
-
const agentId =
|
|
3782
|
+
const agentId = validateUuid20(req.params.agentId);
|
|
3423
3783
|
if (!agentId) {
|
|
3424
3784
|
return sendError(res, 400, "INVALID_ID", "Invalid agent ID format");
|
|
3425
3785
|
}
|
|
@@ -3435,14 +3795,14 @@ function createConversationRouter(agents) {
|
|
|
3435
3795
|
const roomId = createUniqueUuid5(runtime, rawRoomId ?? `default-room-${agentId}`);
|
|
3436
3796
|
const entityId = createUniqueUuid5(runtime, rawUserId ?? "Anon");
|
|
3437
3797
|
const worldId = rawWorldId ?? createUniqueUuid5(runtime, "direct");
|
|
3438
|
-
|
|
3798
|
+
logger21.debug("[SPEECH CONVERSATION] Ensuring connection");
|
|
3439
3799
|
await runtime.ensureConnection({
|
|
3440
3800
|
entityId,
|
|
3441
3801
|
roomId,
|
|
3442
3802
|
userName: req.body.userName,
|
|
3443
3803
|
name: req.body.name,
|
|
3444
3804
|
source: "direct",
|
|
3445
|
-
type:
|
|
3805
|
+
type: ChannelType5.API,
|
|
3446
3806
|
worldId,
|
|
3447
3807
|
worldName: "Direct"
|
|
3448
3808
|
});
|
|
@@ -3452,7 +3812,7 @@ function createConversationRouter(agents) {
|
|
|
3452
3812
|
attachments: [],
|
|
3453
3813
|
source: "direct",
|
|
3454
3814
|
inReplyTo: void 0,
|
|
3455
|
-
channelType:
|
|
3815
|
+
channelType: ChannelType5.API
|
|
3456
3816
|
};
|
|
3457
3817
|
const userMessageMemory = {
|
|
3458
3818
|
id: messageId,
|
|
@@ -3463,16 +3823,16 @@ function createConversationRouter(agents) {
|
|
|
3463
3823
|
content,
|
|
3464
3824
|
createdAt: Date.now()
|
|
3465
3825
|
};
|
|
3466
|
-
|
|
3826
|
+
logger21.debug("[SPEECH CONVERSATION] Creating memory");
|
|
3467
3827
|
await runtime.createMemory(userMessageMemory, "messages");
|
|
3468
|
-
|
|
3828
|
+
logger21.debug("[SPEECH CONVERSATION] Composing state");
|
|
3469
3829
|
const state = await runtime.composeState(userMessageMemory);
|
|
3470
|
-
|
|
3830
|
+
logger21.debug("[SPEECH CONVERSATION] Creating context");
|
|
3471
3831
|
const prompt = composePrompt({
|
|
3472
3832
|
state,
|
|
3473
3833
|
template: messageHandlerTemplate
|
|
3474
3834
|
});
|
|
3475
|
-
|
|
3835
|
+
logger21.debug("[SPEECH CONVERSATION] Using LLM for response");
|
|
3476
3836
|
const llmResponse = await runtime.useModel(ModelType4.TEXT_LARGE, {
|
|
3477
3837
|
// Renamed to llmResponse
|
|
3478
3838
|
messages: [
|
|
@@ -3489,7 +3849,7 @@ function createConversationRouter(agents) {
|
|
|
3489
3849
|
if (!llmResponse) {
|
|
3490
3850
|
return sendError(res, 500, "MODEL_ERROR", "No response from model");
|
|
3491
3851
|
}
|
|
3492
|
-
|
|
3852
|
+
logger21.debug("[SPEECH CONVERSATION] Creating response memory");
|
|
3493
3853
|
const responseMessage = {
|
|
3494
3854
|
// Explicitly type as Memory
|
|
3495
3855
|
id: createUniqueUuid5(runtime, `resp-${messageId}`),
|
|
@@ -3512,20 +3872,20 @@ function createConversationRouter(agents) {
|
|
|
3512
3872
|
async () => [userMessageMemory]
|
|
3513
3873
|
// Callback should return relevant memories
|
|
3514
3874
|
);
|
|
3515
|
-
|
|
3875
|
+
logger21.debug("[SPEECH CONVERSATION] Generating speech response from LLM output");
|
|
3516
3876
|
const speechAudioResponse = await runtime.useModel(ModelType4.TEXT_TO_SPEECH, llmResponse);
|
|
3517
3877
|
const audioResult = await convertToAudioBuffer(speechAudioResponse, true);
|
|
3518
|
-
|
|
3878
|
+
logger21.debug("[SPEECH CONVERSATION] Setting response headers");
|
|
3519
3879
|
res.set({
|
|
3520
3880
|
"Content-Type": audioResult.mimeType,
|
|
3521
3881
|
"Content-Length": audioResult.buffer.length.toString()
|
|
3522
3882
|
});
|
|
3523
3883
|
res.send(audioResult.buffer);
|
|
3524
|
-
|
|
3884
|
+
logger21.success(
|
|
3525
3885
|
`[SPEECH CONVERSATION] Successfully processed conversation for: ${runtime.character.name}`
|
|
3526
3886
|
);
|
|
3527
3887
|
} catch (error) {
|
|
3528
|
-
|
|
3888
|
+
logger21.error("[SPEECH CONVERSATION] Error processing conversation:", error);
|
|
3529
3889
|
sendError(
|
|
3530
3890
|
res,
|
|
3531
3891
|
500,
|
|
@@ -3540,7 +3900,7 @@ function createConversationRouter(agents) {
|
|
|
3540
3900
|
|
|
3541
3901
|
// src/api/audio/index.ts
|
|
3542
3902
|
function audioRouter(agents) {
|
|
3543
|
-
const router =
|
|
3903
|
+
const router = express22.Router();
|
|
3544
3904
|
router.use("/", createAudioProcessingRouter(agents));
|
|
3545
3905
|
router.use("/", createSynthesisRouter(agents));
|
|
3546
3906
|
router.use("/", createConversationRouter(agents));
|
|
@@ -3548,23 +3908,23 @@ function audioRouter(agents) {
|
|
|
3548
3908
|
}
|
|
3549
3909
|
|
|
3550
3910
|
// src/api/runtime/index.ts
|
|
3551
|
-
import
|
|
3911
|
+
import express26 from "express";
|
|
3552
3912
|
|
|
3553
3913
|
// src/api/runtime/health.ts
|
|
3554
|
-
import { logger as
|
|
3555
|
-
import
|
|
3914
|
+
import { logger as logger22 } from "@elizaos/core";
|
|
3915
|
+
import express23 from "express";
|
|
3556
3916
|
function createHealthRouter(agents, serverInstance) {
|
|
3557
|
-
const router =
|
|
3917
|
+
const router = express23.Router();
|
|
3558
3918
|
router.get("/ping", (_req, res) => {
|
|
3559
3919
|
res.json({ pong: true, timestamp: Date.now() });
|
|
3560
3920
|
});
|
|
3561
3921
|
router.get("/hello", (_req, res) => {
|
|
3562
|
-
|
|
3922
|
+
logger22.info("Hello endpoint hit");
|
|
3563
3923
|
res.setHeader("Content-Type", "application/json");
|
|
3564
3924
|
res.send(JSON.stringify({ message: "Hello World!" }));
|
|
3565
3925
|
});
|
|
3566
3926
|
router.get("/status", (_req, res) => {
|
|
3567
|
-
|
|
3927
|
+
logger22.info("Status endpoint hit");
|
|
3568
3928
|
res.setHeader("Content-Type", "application/json");
|
|
3569
3929
|
res.send(
|
|
3570
3930
|
JSON.stringify({
|
|
@@ -3575,7 +3935,7 @@ function createHealthRouter(agents, serverInstance) {
|
|
|
3575
3935
|
);
|
|
3576
3936
|
});
|
|
3577
3937
|
router.get("/health", (_req, res) => {
|
|
3578
|
-
|
|
3938
|
+
logger22.log({ apiRoute: "/health" }, "Health check route hit");
|
|
3579
3939
|
const healthcheck = {
|
|
3580
3940
|
status: "OK",
|
|
3581
3941
|
version: process.env.APP_VERSION || "unknown",
|
|
@@ -3588,7 +3948,7 @@ function createHealthRouter(agents, serverInstance) {
|
|
|
3588
3948
|
res.status(statusCode).json(healthcheck);
|
|
3589
3949
|
});
|
|
3590
3950
|
router.post("/stop", (_req, res) => {
|
|
3591
|
-
|
|
3951
|
+
logger22.log({ apiRoute: "/stop" }, "Server stopping...");
|
|
3592
3952
|
serverInstance?.stop();
|
|
3593
3953
|
res.json({ message: "Server stopping..." });
|
|
3594
3954
|
});
|
|
@@ -3596,8 +3956,8 @@ function createHealthRouter(agents, serverInstance) {
|
|
|
3596
3956
|
}
|
|
3597
3957
|
|
|
3598
3958
|
// src/api/runtime/logging.ts
|
|
3599
|
-
import { logger as
|
|
3600
|
-
import
|
|
3959
|
+
import { logger as logger23 } from "@elizaos/core";
|
|
3960
|
+
import express24 from "express";
|
|
3601
3961
|
var LOG_LEVELS = {
|
|
3602
3962
|
fatal: 60,
|
|
3603
3963
|
error: 50,
|
|
@@ -3610,14 +3970,14 @@ var LOG_LEVELS = {
|
|
|
3610
3970
|
trace: 10
|
|
3611
3971
|
};
|
|
3612
3972
|
function createLoggingRouter() {
|
|
3613
|
-
const router =
|
|
3973
|
+
const router = express24.Router();
|
|
3614
3974
|
const logsHandler = async (req, res) => {
|
|
3615
3975
|
const since = req.query.since ? Number(req.query.since) : Date.now() - 36e5;
|
|
3616
3976
|
const requestedLevel = req.query.level?.toString().toLowerCase() || "all";
|
|
3617
3977
|
const requestedAgentName = req.query.agentName?.toString() || "all";
|
|
3618
3978
|
const requestedAgentId = req.query.agentId?.toString() || "all";
|
|
3619
3979
|
const limit = Math.min(Number(req.query.limit) || 100, 1e3);
|
|
3620
|
-
const destination =
|
|
3980
|
+
const destination = logger23[Symbol.for("pino-destination")];
|
|
3621
3981
|
if (!destination?.recentLogs) {
|
|
3622
3982
|
return res.status(500).json({
|
|
3623
3983
|
error: "Logger destination not available",
|
|
@@ -3658,7 +4018,7 @@ function createLoggingRouter() {
|
|
|
3658
4018
|
}
|
|
3659
4019
|
return timeMatch && levelMatch && agentNameMatch && agentIdMatch;
|
|
3660
4020
|
}).slice(-limit);
|
|
3661
|
-
|
|
4021
|
+
logger23.debug("Logs request processed", {
|
|
3662
4022
|
requestedLevel,
|
|
3663
4023
|
requestedLevelValue,
|
|
3664
4024
|
requestedAgentName,
|
|
@@ -3697,7 +4057,7 @@ function createLoggingRouter() {
|
|
|
3697
4057
|
router.post("/logs", logsHandler);
|
|
3698
4058
|
const logsClearHandler = (_req, res) => {
|
|
3699
4059
|
try {
|
|
3700
|
-
const destination =
|
|
4060
|
+
const destination = logger23[Symbol.for("pino-destination")];
|
|
3701
4061
|
if (!destination?.clear) {
|
|
3702
4062
|
return res.status(500).json({
|
|
3703
4063
|
error: "Logger clear method not available",
|
|
@@ -3705,7 +4065,7 @@ function createLoggingRouter() {
|
|
|
3705
4065
|
});
|
|
3706
4066
|
}
|
|
3707
4067
|
destination.clear();
|
|
3708
|
-
|
|
4068
|
+
logger23.debug("Logs cleared via API endpoint");
|
|
3709
4069
|
res.json({ status: "success", message: "Logs cleared successfully" });
|
|
3710
4070
|
} catch (error) {
|
|
3711
4071
|
res.status(500).json({
|
|
@@ -3719,9 +4079,9 @@ function createLoggingRouter() {
|
|
|
3719
4079
|
}
|
|
3720
4080
|
|
|
3721
4081
|
// src/api/runtime/debug.ts
|
|
3722
|
-
import
|
|
4082
|
+
import express25 from "express";
|
|
3723
4083
|
function createDebugRouter(serverInstance) {
|
|
3724
|
-
const router =
|
|
4084
|
+
const router = express25.Router();
|
|
3725
4085
|
router.get("/servers", async (_req, res) => {
|
|
3726
4086
|
try {
|
|
3727
4087
|
const servers = await serverInstance?.getServers();
|
|
@@ -3742,7 +4102,7 @@ function createDebugRouter(serverInstance) {
|
|
|
3742
4102
|
|
|
3743
4103
|
// src/api/runtime/index.ts
|
|
3744
4104
|
function runtimeRouter(agents, serverInstance) {
|
|
3745
|
-
const router =
|
|
4105
|
+
const router = express26.Router();
|
|
3746
4106
|
router.use("/", createHealthRouter(agents, serverInstance));
|
|
3747
4107
|
router.use("/", createLoggingRouter(agents, serverInstance));
|
|
3748
4108
|
router.use("/debug", createDebugRouter(serverInstance));
|
|
@@ -3750,18 +4110,18 @@ function runtimeRouter(agents, serverInstance) {
|
|
|
3750
4110
|
}
|
|
3751
4111
|
|
|
3752
4112
|
// src/api/tee/index.ts
|
|
3753
|
-
import
|
|
4113
|
+
import express27 from "express";
|
|
3754
4114
|
function teeRouter() {
|
|
3755
|
-
const router =
|
|
4115
|
+
const router = express27.Router();
|
|
3756
4116
|
return router;
|
|
3757
4117
|
}
|
|
3758
4118
|
|
|
3759
4119
|
// src/api/system/index.ts
|
|
3760
|
-
import
|
|
4120
|
+
import express30 from "express";
|
|
3761
4121
|
|
|
3762
4122
|
// src/api/system/environment.ts
|
|
3763
|
-
import { logger as
|
|
3764
|
-
import
|
|
4123
|
+
import { logger as logger24 } from "@elizaos/core";
|
|
4124
|
+
import express28 from "express";
|
|
3765
4125
|
import { existsSync, writeFileSync } from "fs";
|
|
3766
4126
|
import path7 from "path";
|
|
3767
4127
|
import dotenv from "dotenv";
|
|
@@ -3804,7 +4164,7 @@ function resolveEnvFile(startDir = process.cwd()) {
|
|
|
3804
4164
|
return path7.join(startDir, ".env");
|
|
3805
4165
|
}
|
|
3806
4166
|
function createEnvironmentRouter() {
|
|
3807
|
-
const router =
|
|
4167
|
+
const router = express28.Router();
|
|
3808
4168
|
router.get("/local", async (_req, res) => {
|
|
3809
4169
|
try {
|
|
3810
4170
|
const localEnvPath = getLocalEnvPath();
|
|
@@ -3820,7 +4180,7 @@ function createEnvironmentRouter() {
|
|
|
3820
4180
|
data: localEnvs
|
|
3821
4181
|
});
|
|
3822
4182
|
} catch (error) {
|
|
3823
|
-
|
|
4183
|
+
logger24.error(`[ENVS GET] Error retrieving local envs`, error);
|
|
3824
4184
|
res.status(500).json({
|
|
3825
4185
|
success: false,
|
|
3826
4186
|
error: {
|
|
@@ -3852,7 +4212,7 @@ function createEnvironmentRouter() {
|
|
|
3852
4212
|
message: "Local env updated"
|
|
3853
4213
|
});
|
|
3854
4214
|
} catch (error) {
|
|
3855
|
-
|
|
4215
|
+
logger24.error(`[ENVS POST] Error updating local envs`, error);
|
|
3856
4216
|
res.status(500).json({
|
|
3857
4217
|
success: false,
|
|
3858
4218
|
error: {
|
|
@@ -3867,12 +4227,12 @@ function createEnvironmentRouter() {
|
|
|
3867
4227
|
}
|
|
3868
4228
|
|
|
3869
4229
|
// src/api/system/version.ts
|
|
3870
|
-
import
|
|
4230
|
+
import express29 from "express";
|
|
3871
4231
|
|
|
3872
4232
|
// package.json
|
|
3873
4233
|
var package_default = {
|
|
3874
4234
|
name: "@elizaos/server",
|
|
3875
|
-
version: "1.3.
|
|
4235
|
+
version: "1.3.2",
|
|
3876
4236
|
description: "ElizaOS Server - Core server infrastructure for ElizaOS agents",
|
|
3877
4237
|
publishConfig: {
|
|
3878
4238
|
access: "public",
|
|
@@ -3923,10 +4283,10 @@ var package_default = {
|
|
|
3923
4283
|
which: "^4.0.0",
|
|
3924
4284
|
ws: "^8.18.0"
|
|
3925
4285
|
},
|
|
3926
|
-
gitHead: "
|
|
4286
|
+
gitHead: "48d0b08182b5fd5b17dd58198b1fee15b0815775",
|
|
3927
4287
|
dependencies: {
|
|
3928
|
-
"@elizaos/core": "
|
|
3929
|
-
"@elizaos/plugin-sql": "
|
|
4288
|
+
"@elizaos/core": "workspace:*",
|
|
4289
|
+
"@elizaos/plugin-sql": "workspace:*",
|
|
3930
4290
|
"@types/express": "^5.0.2",
|
|
3931
4291
|
"@types/helmet": "^4.0.0",
|
|
3932
4292
|
"@types/multer": "^1.4.13",
|
|
@@ -3964,7 +4324,7 @@ function getVersionInfo() {
|
|
|
3964
4324
|
}
|
|
3965
4325
|
}
|
|
3966
4326
|
function createVersionRouter() {
|
|
3967
|
-
const router =
|
|
4327
|
+
const router = express29.Router();
|
|
3968
4328
|
router.get("/", (_, res) => {
|
|
3969
4329
|
const versionInfo = getVersionInfo();
|
|
3970
4330
|
const statusCode = versionInfo.error ? 500 : 200;
|
|
@@ -3975,7 +4335,7 @@ function createVersionRouter() {
|
|
|
3975
4335
|
|
|
3976
4336
|
// src/api/system/index.ts
|
|
3977
4337
|
function systemRouter() {
|
|
3978
|
-
const router =
|
|
4338
|
+
const router = express30.Router();
|
|
3979
4339
|
router.use("/env", createEnvironmentRouter());
|
|
3980
4340
|
router.use("/version", createVersionRouter());
|
|
3981
4341
|
return router;
|
|
@@ -3983,13 +4343,13 @@ function systemRouter() {
|
|
|
3983
4343
|
|
|
3984
4344
|
// src/socketio/index.ts
|
|
3985
4345
|
import {
|
|
3986
|
-
logger as
|
|
4346
|
+
logger as logger25,
|
|
3987
4347
|
SOCKET_MESSAGE_TYPE,
|
|
3988
|
-
validateUuid as
|
|
3989
|
-
ChannelType as
|
|
4348
|
+
validateUuid as validateUuid21,
|
|
4349
|
+
ChannelType as ChannelType6,
|
|
3990
4350
|
EventType
|
|
3991
4351
|
} from "@elizaos/core";
|
|
3992
|
-
var
|
|
4352
|
+
var DEFAULT_SERVER_ID5 = "00000000-0000-0000-0000-000000000000";
|
|
3993
4353
|
var SocketIORouter = class {
|
|
3994
4354
|
agents;
|
|
3995
4355
|
connections;
|
|
@@ -4001,22 +4361,22 @@ var SocketIORouter = class {
|
|
|
4001
4361
|
this.connections = /* @__PURE__ */ new Map();
|
|
4002
4362
|
this.logStreamConnections = /* @__PURE__ */ new Map();
|
|
4003
4363
|
this.serverInstance = serverInstance;
|
|
4004
|
-
|
|
4364
|
+
logger25.info(`[SocketIO] Router initialized with ${this.agents.size} agents`);
|
|
4005
4365
|
}
|
|
4006
4366
|
setupListeners(io) {
|
|
4007
|
-
|
|
4367
|
+
logger25.info(`[SocketIO] Setting up Socket.IO event listeners`);
|
|
4008
4368
|
const messageTypes = Object.keys(SOCKET_MESSAGE_TYPE).map(
|
|
4009
4369
|
(key) => `${key}: ${SOCKET_MESSAGE_TYPE[key]}`
|
|
4010
4370
|
);
|
|
4011
|
-
|
|
4371
|
+
logger25.info(`[SocketIO] Registered message types: ${messageTypes.join(", ")}`);
|
|
4012
4372
|
io.on("connection", (socket) => {
|
|
4013
4373
|
this.handleNewConnection(socket, io);
|
|
4014
4374
|
});
|
|
4015
4375
|
}
|
|
4016
4376
|
handleNewConnection(socket, _io) {
|
|
4017
|
-
|
|
4377
|
+
logger25.info(`[SocketIO] New connection: ${socket.id}`);
|
|
4018
4378
|
socket.on(String(SOCKET_MESSAGE_TYPE.ROOM_JOINING), (payload) => {
|
|
4019
|
-
|
|
4379
|
+
logger25.debug(
|
|
4020
4380
|
`[SocketIO] Channel joining event received directly: ${JSON.stringify(payload)}`
|
|
4021
4381
|
);
|
|
4022
4382
|
this.handleChannelJoining(socket, payload);
|
|
@@ -4024,7 +4384,7 @@ var SocketIORouter = class {
|
|
|
4024
4384
|
socket.on(String(SOCKET_MESSAGE_TYPE.SEND_MESSAGE), (payload) => {
|
|
4025
4385
|
const messagePreview = payload.message?.substring(0, 50) + (payload.message?.length > 50 ? "..." : "");
|
|
4026
4386
|
const channelId = payload.channelId || payload.roomId;
|
|
4027
|
-
|
|
4387
|
+
logger25.info(
|
|
4028
4388
|
`[SocketIO] SEND_MESSAGE event received directly: ${JSON.stringify({
|
|
4029
4389
|
senderId: payload.senderId,
|
|
4030
4390
|
channelId,
|
|
@@ -4034,7 +4394,7 @@ var SocketIORouter = class {
|
|
|
4034
4394
|
this.handleMessageSubmission(socket, payload);
|
|
4035
4395
|
});
|
|
4036
4396
|
socket.on("message", (data) => {
|
|
4037
|
-
|
|
4397
|
+
logger25.info(
|
|
4038
4398
|
`[SocketIO] Generic 'message' event received: ${JSON.stringify(data)} (SocketID: ${socket.id})`
|
|
4039
4399
|
);
|
|
4040
4400
|
this.handleGenericMessage(socket, data);
|
|
@@ -4044,11 +4404,11 @@ var SocketIORouter = class {
|
|
|
4044
4404
|
socket.on("update_log_filters", (filters) => this.handleLogFilterUpdate(socket, filters));
|
|
4045
4405
|
socket.on("disconnect", () => this.handleDisconnect(socket));
|
|
4046
4406
|
socket.on("error", (error) => {
|
|
4047
|
-
|
|
4407
|
+
logger25.error(`[SocketIO] Socket error for ${socket.id}: ${error.message}`, error);
|
|
4048
4408
|
});
|
|
4049
4409
|
if (process.env.NODE_ENV === "development") {
|
|
4050
4410
|
socket.onAny((event, ...args) => {
|
|
4051
|
-
|
|
4411
|
+
logger25.info(`[SocketIO DEBUG ${socket.id}] Event '${event}': ${JSON.stringify(args)}`);
|
|
4052
4412
|
});
|
|
4053
4413
|
}
|
|
4054
4414
|
socket.emit("connection_established", {
|
|
@@ -4059,7 +4419,7 @@ var SocketIORouter = class {
|
|
|
4059
4419
|
handleGenericMessage(socket, data) {
|
|
4060
4420
|
try {
|
|
4061
4421
|
if (!(data && typeof data === "object" && "type" in data && "payload" in data)) {
|
|
4062
|
-
|
|
4422
|
+
logger25.warn(
|
|
4063
4423
|
`[SocketIO ${socket.id}] Malformed 'message' event data: ${JSON.stringify(data)}`
|
|
4064
4424
|
);
|
|
4065
4425
|
return;
|
|
@@ -4067,21 +4427,21 @@ var SocketIORouter = class {
|
|
|
4067
4427
|
const { type, payload } = data;
|
|
4068
4428
|
switch (type) {
|
|
4069
4429
|
case SOCKET_MESSAGE_TYPE.ROOM_JOINING:
|
|
4070
|
-
|
|
4430
|
+
logger25.info(`[SocketIO ${socket.id}] Handling channel joining via 'message' event`);
|
|
4071
4431
|
this.handleChannelJoining(socket, payload);
|
|
4072
4432
|
break;
|
|
4073
4433
|
case SOCKET_MESSAGE_TYPE.SEND_MESSAGE:
|
|
4074
|
-
|
|
4434
|
+
logger25.info(`[SocketIO ${socket.id}] Handling message sending via 'message' event`);
|
|
4075
4435
|
this.handleMessageSubmission(socket, payload);
|
|
4076
4436
|
break;
|
|
4077
4437
|
default:
|
|
4078
|
-
|
|
4438
|
+
logger25.warn(
|
|
4079
4439
|
`[SocketIO ${socket.id}] Unknown message type received in 'message' event: ${type}`
|
|
4080
4440
|
);
|
|
4081
4441
|
break;
|
|
4082
4442
|
}
|
|
4083
4443
|
} catch (error) {
|
|
4084
|
-
|
|
4444
|
+
logger25.error(
|
|
4085
4445
|
`[SocketIO ${socket.id}] Error processing 'message' event: ${error.message}`,
|
|
4086
4446
|
error
|
|
4087
4447
|
);
|
|
@@ -4090,7 +4450,7 @@ var SocketIORouter = class {
|
|
|
4090
4450
|
handleChannelJoining(socket, payload) {
|
|
4091
4451
|
const channelId = payload.channelId || payload.roomId;
|
|
4092
4452
|
const { agentId, entityId, serverId, metadata } = payload;
|
|
4093
|
-
|
|
4453
|
+
logger25.debug(
|
|
4094
4454
|
`[SocketIO] handleChannelJoining called with payload:`,
|
|
4095
4455
|
JSON.stringify(payload, null, 2)
|
|
4096
4456
|
);
|
|
@@ -4099,18 +4459,18 @@ var SocketIORouter = class {
|
|
|
4099
4459
|
return;
|
|
4100
4460
|
}
|
|
4101
4461
|
if (agentId) {
|
|
4102
|
-
const agentUuid =
|
|
4462
|
+
const agentUuid = validateUuid21(agentId);
|
|
4103
4463
|
if (agentUuid) {
|
|
4104
4464
|
this.connections.set(socket.id, agentUuid);
|
|
4105
|
-
|
|
4465
|
+
logger25.info(`[SocketIO] Socket ${socket.id} associated with agent ${agentUuid}`);
|
|
4106
4466
|
}
|
|
4107
4467
|
}
|
|
4108
4468
|
socket.join(channelId);
|
|
4109
|
-
|
|
4110
|
-
if (entityId && (serverId ||
|
|
4111
|
-
const finalServerId = serverId ||
|
|
4112
|
-
const isDm = metadata?.isDm || metadata?.channelType ===
|
|
4113
|
-
|
|
4469
|
+
logger25.info(`[SocketIO] Socket ${socket.id} joined Socket.IO channel: ${channelId}`);
|
|
4470
|
+
if (entityId && (serverId || DEFAULT_SERVER_ID5)) {
|
|
4471
|
+
const finalServerId = serverId || DEFAULT_SERVER_ID5;
|
|
4472
|
+
const isDm = metadata?.isDm || metadata?.channelType === ChannelType6.DM;
|
|
4473
|
+
logger25.info(
|
|
4114
4474
|
`[SocketIO] Emitting ENTITY_JOINED event for entityId: ${entityId}, serverId: ${finalServerId}, isDm: ${isDm}`
|
|
4115
4475
|
);
|
|
4116
4476
|
const runtime = Array.from(this.agents.values())[0];
|
|
@@ -4122,19 +4482,19 @@ var SocketIORouter = class {
|
|
|
4122
4482
|
// Use serverId as worldId identifier
|
|
4123
4483
|
roomId: channelId,
|
|
4124
4484
|
metadata: {
|
|
4125
|
-
type: isDm ?
|
|
4485
|
+
type: isDm ? ChannelType6.DM : ChannelType6.GROUP,
|
|
4126
4486
|
isDm,
|
|
4127
4487
|
...metadata
|
|
4128
4488
|
},
|
|
4129
4489
|
source: "socketio"
|
|
4130
4490
|
});
|
|
4131
|
-
|
|
4491
|
+
logger25.info(`[SocketIO] ENTITY_JOINED event emitted successfully for ${entityId}`);
|
|
4132
4492
|
} else {
|
|
4133
|
-
|
|
4493
|
+
logger25.warn(`[SocketIO] No runtime available to emit ENTITY_JOINED event`);
|
|
4134
4494
|
}
|
|
4135
4495
|
} else {
|
|
4136
|
-
|
|
4137
|
-
`[SocketIO] Missing entityId (${entityId}) or serverId (${serverId ||
|
|
4496
|
+
logger25.debug(
|
|
4497
|
+
`[SocketIO] Missing entityId (${entityId}) or serverId (${serverId || DEFAULT_SERVER_ID5}) - not emitting ENTITY_JOINED event`
|
|
4138
4498
|
);
|
|
4139
4499
|
}
|
|
4140
4500
|
const successMessage = `Socket ${socket.id} successfully joined channel ${channelId}.`;
|
|
@@ -4143,24 +4503,24 @@ var SocketIORouter = class {
|
|
|
4143
4503
|
channelId,
|
|
4144
4504
|
roomId: channelId,
|
|
4145
4505
|
// Keep for backward compatibility
|
|
4146
|
-
...agentId && { agentId:
|
|
4506
|
+
...agentId && { agentId: validateUuid21(agentId) || agentId }
|
|
4147
4507
|
};
|
|
4148
4508
|
socket.emit("channel_joined", responsePayload);
|
|
4149
4509
|
socket.emit("room_joined", responsePayload);
|
|
4150
|
-
|
|
4510
|
+
logger25.info(`[SocketIO] ${successMessage}`);
|
|
4151
4511
|
}
|
|
4152
4512
|
async handleMessageSubmission(socket, payload) {
|
|
4153
4513
|
const channelId = payload.channelId || payload.roomId;
|
|
4154
4514
|
const { senderId, senderName, message, serverId, source, metadata, attachments } = payload;
|
|
4155
|
-
|
|
4515
|
+
logger25.info(
|
|
4156
4516
|
`[SocketIO ${socket.id}] Received SEND_MESSAGE for central submission: channel ${channelId} from ${senderName || senderId}`
|
|
4157
4517
|
);
|
|
4158
|
-
|
|
4518
|
+
logger25.info(
|
|
4159
4519
|
`[SocketIO ${socket.id}] Full payload for debugging:`,
|
|
4160
4520
|
JSON.stringify(payload, null, 2)
|
|
4161
4521
|
);
|
|
4162
|
-
const isValidServerId = serverId ===
|
|
4163
|
-
if (!
|
|
4522
|
+
const isValidServerId = serverId === DEFAULT_SERVER_ID5 || validateUuid21(serverId);
|
|
4523
|
+
if (!validateUuid21(channelId) || !isValidServerId || !validateUuid21(senderId) || !message) {
|
|
4164
4524
|
this.sendErrorResponse(
|
|
4165
4525
|
socket,
|
|
4166
4526
|
`For SEND_MESSAGE: channelId, serverId (server_id), senderId (author_id), and message are required.`
|
|
@@ -4168,9 +4528,9 @@ var SocketIORouter = class {
|
|
|
4168
4528
|
return;
|
|
4169
4529
|
}
|
|
4170
4530
|
try {
|
|
4171
|
-
const isDmForWorldSetup = metadata?.isDm || metadata?.channelType ===
|
|
4531
|
+
const isDmForWorldSetup = metadata?.isDm || metadata?.channelType === ChannelType6.DM;
|
|
4172
4532
|
if (isDmForWorldSetup && senderId) {
|
|
4173
|
-
|
|
4533
|
+
logger25.info(
|
|
4174
4534
|
`[SocketIO] Detected DM channel during message submission, emitting ENTITY_JOINED for proper world setup`
|
|
4175
4535
|
);
|
|
4176
4536
|
const runtime = Array.from(this.agents.values())[0];
|
|
@@ -4182,85 +4542,85 @@ var SocketIORouter = class {
|
|
|
4182
4542
|
// Use serverId as worldId identifier
|
|
4183
4543
|
roomId: channelId,
|
|
4184
4544
|
metadata: {
|
|
4185
|
-
type:
|
|
4545
|
+
type: ChannelType6.DM,
|
|
4186
4546
|
isDm: true,
|
|
4187
4547
|
...metadata
|
|
4188
4548
|
},
|
|
4189
4549
|
source: "socketio_message"
|
|
4190
4550
|
});
|
|
4191
|
-
|
|
4551
|
+
logger25.info(`[SocketIO] ENTITY_JOINED event emitted for DM channel setup: ${senderId}`);
|
|
4192
4552
|
}
|
|
4193
4553
|
}
|
|
4194
|
-
|
|
4554
|
+
logger25.info(
|
|
4195
4555
|
`[SocketIO ${socket.id}] Checking if channel ${channelId} exists before creating message`
|
|
4196
4556
|
);
|
|
4197
4557
|
let channelExists = false;
|
|
4198
4558
|
try {
|
|
4199
4559
|
const existingChannel = await this.serverInstance.getChannelDetails(channelId);
|
|
4200
4560
|
channelExists = !!existingChannel;
|
|
4201
|
-
|
|
4561
|
+
logger25.info(`[SocketIO ${socket.id}] Channel ${channelId} exists: ${channelExists}`);
|
|
4202
4562
|
} catch (error) {
|
|
4203
|
-
|
|
4563
|
+
logger25.info(
|
|
4204
4564
|
`[SocketIO ${socket.id}] Channel ${channelId} does not exist, will create it. Error: ${error.message}`
|
|
4205
4565
|
);
|
|
4206
4566
|
}
|
|
4207
4567
|
if (!channelExists) {
|
|
4208
|
-
|
|
4568
|
+
logger25.info(
|
|
4209
4569
|
`[SocketIO ${socket.id}] Auto-creating channel ${channelId} with serverId ${serverId}`
|
|
4210
4570
|
);
|
|
4211
4571
|
try {
|
|
4212
4572
|
const servers = await this.serverInstance.getServers();
|
|
4213
4573
|
const serverExists = servers.some((s) => s.id === serverId);
|
|
4214
|
-
|
|
4574
|
+
logger25.info(
|
|
4215
4575
|
`[SocketIO ${socket.id}] Server ${serverId} exists: ${serverExists}. Available servers: ${servers.map((s) => s.id).join(", ")}`
|
|
4216
4576
|
);
|
|
4217
4577
|
if (!serverExists) {
|
|
4218
|
-
|
|
4578
|
+
logger25.error(
|
|
4219
4579
|
`[SocketIO ${socket.id}] Server ${serverId} does not exist, cannot create channel`
|
|
4220
4580
|
);
|
|
4221
4581
|
this.sendErrorResponse(socket, `Server ${serverId} does not exist`);
|
|
4222
4582
|
return;
|
|
4223
4583
|
}
|
|
4224
|
-
const isDmChannel = metadata?.isDm || metadata?.channelType ===
|
|
4584
|
+
const isDmChannel = metadata?.isDm || metadata?.channelType === ChannelType6.DM;
|
|
4225
4585
|
const channelData = {
|
|
4226
4586
|
id: channelId,
|
|
4227
4587
|
// Use the specific channel ID from the client
|
|
4228
4588
|
messageServerId: serverId,
|
|
4229
4589
|
name: isDmChannel ? `DM ${channelId.substring(0, 8)}` : `Chat ${channelId.substring(0, 8)}`,
|
|
4230
|
-
type: isDmChannel ?
|
|
4590
|
+
type: isDmChannel ? ChannelType6.DM : ChannelType6.GROUP,
|
|
4231
4591
|
sourceType: "auto_created",
|
|
4232
4592
|
metadata: {
|
|
4233
4593
|
created_by: "socketio_auto_creation",
|
|
4234
4594
|
created_for_user: senderId,
|
|
4235
4595
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4236
|
-
channel_type: isDmChannel ?
|
|
4596
|
+
channel_type: isDmChannel ? ChannelType6.DM : ChannelType6.GROUP,
|
|
4237
4597
|
...metadata
|
|
4238
4598
|
}
|
|
4239
4599
|
};
|
|
4240
|
-
|
|
4600
|
+
logger25.info(
|
|
4241
4601
|
`[SocketIO ${socket.id}] Creating channel with data:`,
|
|
4242
4602
|
JSON.stringify(channelData, null, 2)
|
|
4243
4603
|
);
|
|
4244
4604
|
let participants = [senderId];
|
|
4245
4605
|
if (isDmChannel) {
|
|
4246
4606
|
const otherParticipant = metadata?.targetUserId || metadata?.recipientId || payload.targetUserId;
|
|
4247
|
-
if (otherParticipant &&
|
|
4607
|
+
if (otherParticipant && validateUuid21(otherParticipant)) {
|
|
4248
4608
|
participants.push(otherParticipant);
|
|
4249
|
-
|
|
4609
|
+
logger25.info(
|
|
4250
4610
|
`[SocketIO ${socket.id}] DM channel will include participants: ${participants.join(", ")}`
|
|
4251
4611
|
);
|
|
4252
4612
|
} else {
|
|
4253
|
-
|
|
4613
|
+
logger25.warn(
|
|
4254
4614
|
`[SocketIO ${socket.id}] DM channel missing second participant, only adding sender: ${senderId}`
|
|
4255
4615
|
);
|
|
4256
4616
|
}
|
|
4257
4617
|
}
|
|
4258
4618
|
await this.serverInstance.createChannel(channelData, participants);
|
|
4259
|
-
|
|
4260
|
-
`[SocketIO ${socket.id}] Auto-created ${isDmChannel ?
|
|
4619
|
+
logger25.info(
|
|
4620
|
+
`[SocketIO ${socket.id}] Auto-created ${isDmChannel ? ChannelType6.DM : ChannelType6.GROUP} channel ${channelId} for message submission with ${participants.length} participants`
|
|
4261
4621
|
);
|
|
4262
4622
|
} catch (createError) {
|
|
4263
|
-
|
|
4623
|
+
logger25.error(
|
|
4264
4624
|
`[SocketIO ${socket.id}] Failed to auto-create channel ${channelId}:`,
|
|
4265
4625
|
createError
|
|
4266
4626
|
);
|
|
@@ -4268,7 +4628,7 @@ var SocketIORouter = class {
|
|
|
4268
4628
|
return;
|
|
4269
4629
|
}
|
|
4270
4630
|
} else {
|
|
4271
|
-
|
|
4631
|
+
logger25.info(
|
|
4272
4632
|
`[SocketIO ${socket.id}] Channel ${channelId} already exists, proceeding with message creation`
|
|
4273
4633
|
);
|
|
4274
4634
|
}
|
|
@@ -4287,7 +4647,7 @@ var SocketIORouter = class {
|
|
|
4287
4647
|
sourceType: source || "socketio_client"
|
|
4288
4648
|
};
|
|
4289
4649
|
const createdRootMessage = await this.serverInstance.createMessage(newRootMessageData);
|
|
4290
|
-
|
|
4650
|
+
logger25.info(
|
|
4291
4651
|
`[SocketIO ${socket.id}] Message from ${senderId} (msgId: ${payload.messageId || "N/A"}) submitted to central store (central ID: ${createdRootMessage.id}). It will be processed by agents and broadcasted upon their reply.`
|
|
4292
4652
|
);
|
|
4293
4653
|
const messageBroadcast = {
|
|
@@ -4318,7 +4678,7 @@ var SocketIORouter = class {
|
|
|
4318
4678
|
// Keep for backward compatibility
|
|
4319
4679
|
});
|
|
4320
4680
|
} catch (error) {
|
|
4321
|
-
|
|
4681
|
+
logger25.error(
|
|
4322
4682
|
`[SocketIO ${socket.id}] Error during central submission for message: ${error.message}`,
|
|
4323
4683
|
error
|
|
4324
4684
|
);
|
|
@@ -4326,14 +4686,14 @@ var SocketIORouter = class {
|
|
|
4326
4686
|
}
|
|
4327
4687
|
}
|
|
4328
4688
|
sendErrorResponse(socket, errorMessage) {
|
|
4329
|
-
|
|
4689
|
+
logger25.error(`[SocketIO ${socket.id}] Sending error to client: ${errorMessage}`);
|
|
4330
4690
|
socket.emit("messageError", {
|
|
4331
4691
|
error: errorMessage
|
|
4332
4692
|
});
|
|
4333
4693
|
}
|
|
4334
4694
|
handleLogSubscription(socket) {
|
|
4335
4695
|
this.logStreamConnections.set(socket.id, {});
|
|
4336
|
-
|
|
4696
|
+
logger25.info(`[SocketIO ${socket.id}] Client subscribed to log stream`);
|
|
4337
4697
|
socket.emit("log_subscription_confirmed", {
|
|
4338
4698
|
subscribed: true,
|
|
4339
4699
|
message: "Successfully subscribed to log stream"
|
|
@@ -4341,7 +4701,7 @@ var SocketIORouter = class {
|
|
|
4341
4701
|
}
|
|
4342
4702
|
handleLogUnsubscription(socket) {
|
|
4343
4703
|
this.logStreamConnections.delete(socket.id);
|
|
4344
|
-
|
|
4704
|
+
logger25.info(`[SocketIO ${socket.id}] Client unsubscribed from log stream`);
|
|
4345
4705
|
socket.emit("log_subscription_confirmed", {
|
|
4346
4706
|
subscribed: false,
|
|
4347
4707
|
message: "Successfully unsubscribed from log stream"
|
|
@@ -4351,13 +4711,13 @@ var SocketIORouter = class {
|
|
|
4351
4711
|
const existingFilters = this.logStreamConnections.get(socket.id);
|
|
4352
4712
|
if (existingFilters !== void 0) {
|
|
4353
4713
|
this.logStreamConnections.set(socket.id, { ...existingFilters, ...filters });
|
|
4354
|
-
|
|
4714
|
+
logger25.info(`[SocketIO ${socket.id}] Updated log filters:`, filters);
|
|
4355
4715
|
socket.emit("log_filters_updated", {
|
|
4356
4716
|
success: true,
|
|
4357
4717
|
filters: this.logStreamConnections.get(socket.id)
|
|
4358
4718
|
});
|
|
4359
4719
|
} else {
|
|
4360
|
-
|
|
4720
|
+
logger25.warn(`[SocketIO ${socket.id}] Cannot update filters: not subscribed to log stream`);
|
|
4361
4721
|
socket.emit("log_filters_updated", {
|
|
4362
4722
|
success: false,
|
|
4363
4723
|
error: "Not subscribed to log stream"
|
|
@@ -4375,7 +4735,7 @@ var SocketIORouter = class {
|
|
|
4375
4735
|
shouldBroadcast = shouldBroadcast && logEntry.agentName === filters.agentName;
|
|
4376
4736
|
}
|
|
4377
4737
|
if (filters.level && filters.level !== "all") {
|
|
4378
|
-
const numericLevel = typeof filters.level === "string" ?
|
|
4738
|
+
const numericLevel = typeof filters.level === "string" ? logger25.levels.values[filters.level.toLowerCase()] || 70 : filters.level;
|
|
4379
4739
|
shouldBroadcast = shouldBroadcast && logEntry.level >= numericLevel;
|
|
4380
4740
|
}
|
|
4381
4741
|
if (shouldBroadcast) {
|
|
@@ -4389,11 +4749,11 @@ var SocketIORouter = class {
|
|
|
4389
4749
|
this.connections.delete(socket.id);
|
|
4390
4750
|
this.logStreamConnections.delete(socket.id);
|
|
4391
4751
|
if (agentIdAssociated) {
|
|
4392
|
-
|
|
4752
|
+
logger25.info(
|
|
4393
4753
|
`[SocketIO] Client ${socket.id} (associated with agent ${agentIdAssociated}) disconnected.`
|
|
4394
4754
|
);
|
|
4395
4755
|
} else {
|
|
4396
|
-
|
|
4756
|
+
logger25.info(`[SocketIO] Client ${socket.id} disconnected.`);
|
|
4397
4757
|
}
|
|
4398
4758
|
}
|
|
4399
4759
|
};
|
|
@@ -4412,7 +4772,7 @@ function setupSocketIO(server, agents, serverInstance) {
|
|
|
4412
4772
|
return io;
|
|
4413
4773
|
}
|
|
4414
4774
|
function setupLogStreaming(io, router) {
|
|
4415
|
-
const loggerInstance =
|
|
4775
|
+
const loggerInstance = logger26;
|
|
4416
4776
|
const destination = loggerInstance[Symbol.for("pino-destination")];
|
|
4417
4777
|
if (destination && typeof destination.write === "function") {
|
|
4418
4778
|
const originalWrite = destination.write.bind(destination);
|
|
@@ -4436,14 +4796,14 @@ function setupLogStreaming(io, router) {
|
|
|
4436
4796
|
}
|
|
4437
4797
|
function createPluginRouteHandler(agents) {
|
|
4438
4798
|
return (req, res, next) => {
|
|
4439
|
-
|
|
4799
|
+
logger26.debug("Handling plugin request in the plugin route handler", {
|
|
4440
4800
|
path: req.path,
|
|
4441
4801
|
method: req.method,
|
|
4442
4802
|
query: req.query
|
|
4443
4803
|
});
|
|
4444
4804
|
const agentApiRoutePattern = /^\/agents\/[a-f0-9-]{36}\/(?!plugins\/)/i;
|
|
4445
4805
|
if (agentApiRoutePattern.test(req.path)) {
|
|
4446
|
-
|
|
4806
|
+
logger26.debug(`Skipping agent API route in plugin handler: ${req.path}`);
|
|
4447
4807
|
return next();
|
|
4448
4808
|
}
|
|
4449
4809
|
if (req.path.startsWith("/api/messages/")) {
|
|
@@ -4451,24 +4811,24 @@ function createPluginRouteHandler(agents) {
|
|
|
4451
4811
|
}
|
|
4452
4812
|
const clientRoutePattern = /^\/(chat|settings|agents|profile|dashboard|login|register|admin|home|about)\b/i;
|
|
4453
4813
|
if (clientRoutePattern.test(req.path)) {
|
|
4454
|
-
|
|
4814
|
+
logger26.debug(`Skipping client-side route in plugin handler: ${req.path}`);
|
|
4455
4815
|
return next();
|
|
4456
4816
|
}
|
|
4457
4817
|
if (req.path.endsWith(".js") || req.path.includes(".js?") || req.path.match(/index-[A-Za-z0-9]{8}\.js/)) {
|
|
4458
|
-
|
|
4818
|
+
logger26.debug(`JavaScript request in plugin handler: ${req.method} ${req.path}`);
|
|
4459
4819
|
res.setHeader("Content-Type", "application/javascript");
|
|
4460
4820
|
}
|
|
4461
4821
|
if (agents.size === 0) {
|
|
4462
|
-
|
|
4822
|
+
logger26.debug("No agents available, skipping plugin route handling.");
|
|
4463
4823
|
return next();
|
|
4464
4824
|
}
|
|
4465
4825
|
let handled = false;
|
|
4466
4826
|
const agentIdFromQuery = req.query.agentId;
|
|
4467
4827
|
const reqPath = req.path;
|
|
4468
|
-
if (agentIdFromQuery &&
|
|
4828
|
+
if (agentIdFromQuery && validateUuid22(agentIdFromQuery)) {
|
|
4469
4829
|
const runtime = agents.get(agentIdFromQuery);
|
|
4470
4830
|
if (runtime) {
|
|
4471
|
-
|
|
4831
|
+
logger26.debug(
|
|
4472
4832
|
`Agent-scoped request for Agent ID: ${agentIdFromQuery} from query. Path: ${reqPath}`
|
|
4473
4833
|
);
|
|
4474
4834
|
for (const route of runtime.routes) {
|
|
@@ -4479,7 +4839,7 @@ function createPluginRouteHandler(agents) {
|
|
|
4479
4839
|
if (routePath.endsWith("/*")) {
|
|
4480
4840
|
const baseRoute = routePath.slice(0, -1);
|
|
4481
4841
|
if (reqPath.startsWith(baseRoute)) {
|
|
4482
|
-
|
|
4842
|
+
logger26.debug(
|
|
4483
4843
|
`Agent ${agentIdFromQuery} plugin wildcard route: [${route.type.toUpperCase()}] ${routePath} for request: ${reqPath}`
|
|
4484
4844
|
);
|
|
4485
4845
|
try {
|
|
@@ -4488,7 +4848,7 @@ function createPluginRouteHandler(agents) {
|
|
|
4488
4848
|
handled = true;
|
|
4489
4849
|
}
|
|
4490
4850
|
} catch (error) {
|
|
4491
|
-
|
|
4851
|
+
logger26.error(
|
|
4492
4852
|
`Error handling plugin wildcard route for agent ${agentIdFromQuery}: ${routePath}`,
|
|
4493
4853
|
{
|
|
4494
4854
|
error,
|
|
@@ -4506,14 +4866,14 @@ function createPluginRouteHandler(agents) {
|
|
|
4506
4866
|
}
|
|
4507
4867
|
}
|
|
4508
4868
|
} else {
|
|
4509
|
-
|
|
4869
|
+
logger26.debug(
|
|
4510
4870
|
`Agent ${agentIdFromQuery} attempting plugin route match: [${route.type.toUpperCase()}] ${routePath} vs request path: ${reqPath}`
|
|
4511
4871
|
);
|
|
4512
4872
|
let matcher;
|
|
4513
4873
|
try {
|
|
4514
4874
|
matcher = match(routePath, { decode: decodeURIComponent });
|
|
4515
4875
|
} catch (err) {
|
|
4516
|
-
|
|
4876
|
+
logger26.error(
|
|
4517
4877
|
`Invalid plugin route path syntax for agent ${agentIdFromQuery}: "${routePath}"`,
|
|
4518
4878
|
err
|
|
4519
4879
|
);
|
|
@@ -4521,7 +4881,7 @@ function createPluginRouteHandler(agents) {
|
|
|
4521
4881
|
}
|
|
4522
4882
|
const matched = matcher(reqPath);
|
|
4523
4883
|
if (matched) {
|
|
4524
|
-
|
|
4884
|
+
logger26.debug(
|
|
4525
4885
|
`Agent ${agentIdFromQuery} plugin route matched: [${route.type.toUpperCase()}] ${routePath} vs request path: ${reqPath}`
|
|
4526
4886
|
);
|
|
4527
4887
|
req.params = { ...matched.params || {} };
|
|
@@ -4531,7 +4891,7 @@ function createPluginRouteHandler(agents) {
|
|
|
4531
4891
|
handled = true;
|
|
4532
4892
|
}
|
|
4533
4893
|
} catch (error) {
|
|
4534
|
-
|
|
4894
|
+
logger26.error(
|
|
4535
4895
|
`Error handling plugin route for agent ${agentIdFromQuery}: ${routePath}`,
|
|
4536
4896
|
{
|
|
4537
4897
|
error,
|
|
@@ -4552,7 +4912,7 @@ function createPluginRouteHandler(agents) {
|
|
|
4552
4912
|
}
|
|
4553
4913
|
}
|
|
4554
4914
|
} else {
|
|
4555
|
-
|
|
4915
|
+
logger26.warn(
|
|
4556
4916
|
`Agent ID ${agentIdFromQuery} provided in query, but agent runtime not found. Path: ${reqPath}.`
|
|
4557
4917
|
);
|
|
4558
4918
|
if (reqPath.startsWith("/api/")) {
|
|
@@ -4568,8 +4928,8 @@ function createPluginRouteHandler(agents) {
|
|
|
4568
4928
|
return next();
|
|
4569
4929
|
}
|
|
4570
4930
|
}
|
|
4571
|
-
} else if (agentIdFromQuery && !
|
|
4572
|
-
|
|
4931
|
+
} else if (agentIdFromQuery && !validateUuid22(agentIdFromQuery)) {
|
|
4932
|
+
logger26.warn(`Invalid Agent ID format in query: ${agentIdFromQuery}. Path: ${reqPath}.`);
|
|
4573
4933
|
if (reqPath.startsWith("/api/")) {
|
|
4574
4934
|
res.status(400).json({
|
|
4575
4935
|
success: false,
|
|
@@ -4583,7 +4943,7 @@ function createPluginRouteHandler(agents) {
|
|
|
4583
4943
|
return next();
|
|
4584
4944
|
}
|
|
4585
4945
|
} else {
|
|
4586
|
-
|
|
4946
|
+
logger26.debug(`No valid agentId in query. Trying global match for path: ${reqPath}`);
|
|
4587
4947
|
for (const [_, runtime] of agents) {
|
|
4588
4948
|
if (handled) break;
|
|
4589
4949
|
for (const route of runtime.routes) {
|
|
@@ -4597,14 +4957,14 @@ function createPluginRouteHandler(agents) {
|
|
|
4597
4957
|
if (routePath.endsWith("/*")) {
|
|
4598
4958
|
const baseRoute = routePath.slice(0, -1);
|
|
4599
4959
|
if (reqPath.startsWith(baseRoute)) {
|
|
4600
|
-
|
|
4960
|
+
logger26.debug(
|
|
4601
4961
|
`Global plugin wildcard route: [${route.type.toUpperCase()}] ${routePath} (Agent: ${runtime.agentId}) for request: ${reqPath}`
|
|
4602
4962
|
);
|
|
4603
4963
|
try {
|
|
4604
4964
|
route?.handler?.(req, res, runtime);
|
|
4605
4965
|
handled = true;
|
|
4606
4966
|
} catch (error) {
|
|
4607
|
-
|
|
4967
|
+
logger26.error(
|
|
4608
4968
|
`Error handling global plugin wildcard route ${routePath} (Agent: ${runtime.agentId})`,
|
|
4609
4969
|
{ error, path: reqPath }
|
|
4610
4970
|
);
|
|
@@ -4618,14 +4978,14 @@ function createPluginRouteHandler(agents) {
|
|
|
4618
4978
|
}
|
|
4619
4979
|
}
|
|
4620
4980
|
} else if (reqPath === routePath) {
|
|
4621
|
-
|
|
4981
|
+
logger26.debug(
|
|
4622
4982
|
`Global plugin route matched: [${route.type.toUpperCase()}] ${routePath} (Agent: ${runtime.agentId}) for request: ${reqPath}`
|
|
4623
4983
|
);
|
|
4624
4984
|
try {
|
|
4625
4985
|
route?.handler?.(req, res, runtime);
|
|
4626
4986
|
handled = true;
|
|
4627
4987
|
} catch (error) {
|
|
4628
|
-
|
|
4988
|
+
logger26.error(
|
|
4629
4989
|
`Error handling global plugin route ${routePath} (Agent: ${runtime.agentId})`,
|
|
4630
4990
|
{ error, path: reqPath }
|
|
4631
4991
|
);
|
|
@@ -4644,12 +5004,12 @@ function createPluginRouteHandler(agents) {
|
|
|
4644
5004
|
if (handled) {
|
|
4645
5005
|
return;
|
|
4646
5006
|
}
|
|
4647
|
-
|
|
5007
|
+
logger26.debug(`No plugin route handled ${req.method} ${req.path}, passing to next middleware.`);
|
|
4648
5008
|
next();
|
|
4649
5009
|
};
|
|
4650
5010
|
}
|
|
4651
5011
|
function createApiRouter(agents, serverInstance) {
|
|
4652
|
-
const router =
|
|
5012
|
+
const router = express31.Router();
|
|
4653
5013
|
router.use(
|
|
4654
5014
|
helmet({
|
|
4655
5015
|
// Disable CSP here - let main app handle it with environment awareness
|
|
@@ -4687,7 +5047,7 @@ function createApiRouter(agents, serverInstance) {
|
|
|
4687
5047
|
}
|
|
4688
5048
|
|
|
4689
5049
|
// src/authMiddleware.ts
|
|
4690
|
-
import { logger as
|
|
5050
|
+
import { logger as logger27 } from "@elizaos/core";
|
|
4691
5051
|
function apiKeyAuthMiddleware(req, res, next) {
|
|
4692
5052
|
const serverAuthToken = process.env.ELIZA_SERVER_AUTH_TOKEN;
|
|
4693
5053
|
if (!serverAuthToken) {
|
|
@@ -4698,7 +5058,7 @@ function apiKeyAuthMiddleware(req, res, next) {
|
|
|
4698
5058
|
}
|
|
4699
5059
|
const apiKey = req.headers?.["x-api-key"];
|
|
4700
5060
|
if (!apiKey || apiKey !== serverAuthToken) {
|
|
4701
|
-
|
|
5061
|
+
logger27.warn(`Unauthorized access attempt: Missing or invalid X-API-KEY from ${req.ip}`);
|
|
4702
5062
|
return res.status(401).send("Unauthorized: Invalid or missing X-API-KEY");
|
|
4703
5063
|
}
|
|
4704
5064
|
next();
|
|
@@ -4706,12 +5066,12 @@ function apiKeyAuthMiddleware(req, res, next) {
|
|
|
4706
5066
|
|
|
4707
5067
|
// src/services/message.ts
|
|
4708
5068
|
import {
|
|
4709
|
-
ChannelType as
|
|
5069
|
+
ChannelType as ChannelType7,
|
|
4710
5070
|
EventType as EventType2,
|
|
4711
5071
|
Service,
|
|
4712
5072
|
createUniqueUuid as createUniqueUuid6,
|
|
4713
|
-
logger as
|
|
4714
|
-
validateUuid as
|
|
5073
|
+
logger as logger28,
|
|
5074
|
+
validateUuid as validateUuid23
|
|
4715
5075
|
} from "@elizaos/core";
|
|
4716
5076
|
var MessageBusService = class _MessageBusService extends Service {
|
|
4717
5077
|
static serviceType = "message-bus-service";
|
|
@@ -4723,7 +5083,11 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
4723
5083
|
subscribedServers = /* @__PURE__ */ new Set();
|
|
4724
5084
|
constructor(runtime) {
|
|
4725
5085
|
super(runtime);
|
|
4726
|
-
this.boundHandleIncomingMessage =
|
|
5086
|
+
this.boundHandleIncomingMessage = (data) => {
|
|
5087
|
+
this.handleIncomingMessage(data).catch((error) => {
|
|
5088
|
+
logger28.error(`[${this.runtime.character.name}] Error handling incoming message:`, error);
|
|
5089
|
+
});
|
|
5090
|
+
};
|
|
4727
5091
|
this.boundHandleServerAgentUpdate = this.handleServerAgentUpdate.bind(this);
|
|
4728
5092
|
this.boundHandleMessageDeleted = this.handleMessageDeleted.bind(this);
|
|
4729
5093
|
this.boundHandleChannelCleared = this.handleChannelCleared.bind(this);
|
|
@@ -4738,7 +5102,7 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
4738
5102
|
await service.stop();
|
|
4739
5103
|
}
|
|
4740
5104
|
async connectToMessageBus() {
|
|
4741
|
-
|
|
5105
|
+
logger28.info(
|
|
4742
5106
|
`[${this.runtime.character.name}] MessageBusService: Subscribing to internal message bus for 'new_message', 'message_deleted', and 'channel_cleared' events.`
|
|
4743
5107
|
);
|
|
4744
5108
|
bus_default.on("new_message", this.boundHandleIncomingMessage);
|
|
@@ -4753,9 +5117,9 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
4753
5117
|
try {
|
|
4754
5118
|
const serverApiUrl = this.getCentralMessageServerUrl();
|
|
4755
5119
|
this.validChannelIds.clear();
|
|
4756
|
-
const
|
|
5120
|
+
const DEFAULT_SERVER_ID7 = "00000000-0000-0000-0000-000000000000";
|
|
4757
5121
|
const serversToCheck = new Set(this.subscribedServers);
|
|
4758
|
-
serversToCheck.add(
|
|
5122
|
+
serversToCheck.add(DEFAULT_SERVER_ID7);
|
|
4759
5123
|
for (const serverId of serversToCheck) {
|
|
4760
5124
|
try {
|
|
4761
5125
|
const channelsUrl = new URL(
|
|
@@ -4769,31 +5133,31 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
4769
5133
|
const data = await response.json();
|
|
4770
5134
|
if (data.success && data.data?.channels && Array.isArray(data.data.channels)) {
|
|
4771
5135
|
data.data.channels.forEach((channel) => {
|
|
4772
|
-
if (channel.id &&
|
|
5136
|
+
if (channel.id && validateUuid23(channel.id)) {
|
|
4773
5137
|
this.validChannelIds.add(channel.id);
|
|
4774
5138
|
}
|
|
4775
5139
|
});
|
|
4776
|
-
|
|
5140
|
+
logger28.info(
|
|
4777
5141
|
`[${this.runtime.character.name}] MessageBusService: Fetched ${data.data.channels.length} channels from server ${serverId}`
|
|
4778
5142
|
);
|
|
4779
5143
|
}
|
|
4780
5144
|
} else {
|
|
4781
|
-
|
|
5145
|
+
logger28.warn(
|
|
4782
5146
|
`[${this.runtime.character.name}] MessageBusService: Failed to fetch channels for server ${serverId}: ${response.status} ${response.statusText}`
|
|
4783
5147
|
);
|
|
4784
5148
|
}
|
|
4785
5149
|
} catch (serverError) {
|
|
4786
|
-
|
|
5150
|
+
logger28.error(
|
|
4787
5151
|
`[${this.runtime.character.name}] MessageBusService: Error fetching channels for server ${serverId}:`,
|
|
4788
5152
|
serverError
|
|
4789
5153
|
);
|
|
4790
5154
|
}
|
|
4791
5155
|
}
|
|
4792
|
-
|
|
5156
|
+
logger28.info(
|
|
4793
5157
|
`[${this.runtime.character.name}] MessageBusService: Loaded ${this.validChannelIds.size} valid channel IDs from ${serversToCheck.size} servers (including default server)`
|
|
4794
5158
|
);
|
|
4795
5159
|
} catch (error) {
|
|
4796
|
-
|
|
5160
|
+
logger28.error(
|
|
4797
5161
|
`[${this.runtime.character.name}] MessageBusService: Error in fetchValidChannelIds:`,
|
|
4798
5162
|
error
|
|
4799
5163
|
);
|
|
@@ -4802,8 +5166,8 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
4802
5166
|
async getChannelParticipants(channelId) {
|
|
4803
5167
|
try {
|
|
4804
5168
|
const serverApiUrl = this.getCentralMessageServerUrl();
|
|
4805
|
-
if (!
|
|
4806
|
-
|
|
5169
|
+
if (!validateUuid23(channelId)) {
|
|
5170
|
+
logger28.warn(
|
|
4807
5171
|
`[${this.runtime.character.name}] MessageBusService: Invalid channel ID format: ${channelId}`
|
|
4808
5172
|
);
|
|
4809
5173
|
return [];
|
|
@@ -4818,11 +5182,11 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
4818
5182
|
});
|
|
4819
5183
|
if (detailsResponse.ok) {
|
|
4820
5184
|
this.validChannelIds.add(channelId);
|
|
4821
|
-
|
|
5185
|
+
logger28.info(
|
|
4822
5186
|
`[${this.runtime.character.name}] MessageBusService: Discovered new channel ${channelId}, added to valid channels`
|
|
4823
5187
|
);
|
|
4824
5188
|
} else {
|
|
4825
|
-
|
|
5189
|
+
logger28.warn(
|
|
4826
5190
|
`[${this.runtime.character.name}] MessageBusService: Channel ${channelId} does not exist or is not accessible`
|
|
4827
5191
|
);
|
|
4828
5192
|
return [];
|
|
@@ -4843,7 +5207,7 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
4843
5207
|
}
|
|
4844
5208
|
return [];
|
|
4845
5209
|
} catch (error) {
|
|
4846
|
-
|
|
5210
|
+
logger28.error(
|
|
4847
5211
|
`[${this.runtime.character.name}] MessageBusService: Error fetching participants for channel ${channelId}:`,
|
|
4848
5212
|
error
|
|
4849
5213
|
);
|
|
@@ -4864,27 +5228,27 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
4864
5228
|
const data = await response.json();
|
|
4865
5229
|
if (data.success && data.data?.servers) {
|
|
4866
5230
|
this.subscribedServers = new Set(data.data.servers);
|
|
4867
|
-
const
|
|
4868
|
-
this.subscribedServers.add(
|
|
4869
|
-
|
|
5231
|
+
const DEFAULT_SERVER_ID7 = "00000000-0000-0000-0000-000000000000";
|
|
5232
|
+
this.subscribedServers.add(DEFAULT_SERVER_ID7);
|
|
5233
|
+
logger28.info(
|
|
4870
5234
|
`[${this.runtime.character.name}] MessageBusService: Agent is subscribed to ${this.subscribedServers.size} servers (including default server)`
|
|
4871
5235
|
);
|
|
4872
5236
|
}
|
|
4873
5237
|
} else {
|
|
4874
|
-
const
|
|
4875
|
-
this.subscribedServers.add(
|
|
4876
|
-
|
|
5238
|
+
const DEFAULT_SERVER_ID7 = "00000000-0000-0000-0000-000000000000";
|
|
5239
|
+
this.subscribedServers.add(DEFAULT_SERVER_ID7);
|
|
5240
|
+
logger28.warn(
|
|
4877
5241
|
`[${this.runtime.character.name}] MessageBusService: Failed to fetch agent servers, but added default server`
|
|
4878
5242
|
);
|
|
4879
5243
|
}
|
|
4880
5244
|
} catch (error) {
|
|
4881
|
-
|
|
5245
|
+
logger28.error(
|
|
4882
5246
|
`[${this.runtime.character.name}] MessageBusService: Error fetching agent servers:`,
|
|
4883
5247
|
error
|
|
4884
5248
|
);
|
|
4885
|
-
const
|
|
4886
|
-
this.subscribedServers.add(
|
|
4887
|
-
|
|
5249
|
+
const DEFAULT_SERVER_ID7 = "00000000-0000-0000-0000-000000000000";
|
|
5250
|
+
this.subscribedServers.add(DEFAULT_SERVER_ID7);
|
|
5251
|
+
logger28.info(
|
|
4888
5252
|
`[${this.runtime.character.name}] MessageBusService: Added default server after error`
|
|
4889
5253
|
);
|
|
4890
5254
|
}
|
|
@@ -4895,13 +5259,13 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
4895
5259
|
}
|
|
4896
5260
|
if (data.type === "agent_added_to_server") {
|
|
4897
5261
|
this.subscribedServers.add(data.serverId);
|
|
4898
|
-
|
|
5262
|
+
logger28.info(
|
|
4899
5263
|
`[${this.runtime.character.name}] MessageBusService: Agent added to server ${data.serverId}`
|
|
4900
5264
|
);
|
|
4901
5265
|
await this.fetchValidChannelIds();
|
|
4902
5266
|
} else if (data.type === "agent_removed_from_server") {
|
|
4903
5267
|
this.subscribedServers.delete(data.serverId);
|
|
4904
|
-
|
|
5268
|
+
logger28.info(
|
|
4905
5269
|
`[${this.runtime.character.name}] MessageBusService: Agent removed from server ${data.serverId}`
|
|
4906
5270
|
);
|
|
4907
5271
|
await this.fetchValidChannelIds();
|
|
@@ -4909,19 +5273,19 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
4909
5273
|
}
|
|
4910
5274
|
async validateServerSubscription(message) {
|
|
4911
5275
|
if (!this.subscribedServers.has(message.server_id)) {
|
|
4912
|
-
|
|
5276
|
+
logger28.debug(
|
|
4913
5277
|
`[${this.runtime.character.name}] MessageBusService: Agent not subscribed to server ${message.server_id}, ignoring message`
|
|
4914
5278
|
);
|
|
4915
5279
|
return false;
|
|
4916
5280
|
}
|
|
4917
|
-
|
|
5281
|
+
logger28.info(
|
|
4918
5282
|
`[${this.runtime.character.name}] MessageBusService: Passed server subscription check for ${message.server_id}`
|
|
4919
5283
|
);
|
|
4920
5284
|
return true;
|
|
4921
5285
|
}
|
|
4922
5286
|
async validateNotSelfMessage(message) {
|
|
4923
5287
|
if (message.author_id === this.runtime.agentId) {
|
|
4924
|
-
|
|
5288
|
+
logger28.debug(
|
|
4925
5289
|
`[${this.runtime.character.name}] MessageBusService: Agent is the author of the message, ignoring message`
|
|
4926
5290
|
);
|
|
4927
5291
|
return false;
|
|
@@ -4943,7 +5307,7 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
4943
5307
|
});
|
|
4944
5308
|
} catch (error) {
|
|
4945
5309
|
if (error.message && error.message.includes("worlds_pkey")) {
|
|
4946
|
-
|
|
5310
|
+
logger28.debug(
|
|
4947
5311
|
`[${this.runtime.character.name}] MessageBusService: World ${agentWorldId} already exists, continuing with message processing`
|
|
4948
5312
|
);
|
|
4949
5313
|
} else {
|
|
@@ -4959,14 +5323,14 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
4959
5323
|
channelId: message.channel_id,
|
|
4960
5324
|
serverId: message.server_id,
|
|
4961
5325
|
source: message.source_type || "central-bus",
|
|
4962
|
-
type: message.metadata?.channelType ||
|
|
5326
|
+
type: message.metadata?.channelType || ChannelType7.GROUP,
|
|
4963
5327
|
metadata: {
|
|
4964
5328
|
...message.metadata?.channelMetadata || {}
|
|
4965
5329
|
}
|
|
4966
5330
|
});
|
|
4967
5331
|
} catch (error) {
|
|
4968
5332
|
if (error.message && error.message.includes("rooms_pkey")) {
|
|
4969
|
-
|
|
5333
|
+
logger28.debug(
|
|
4970
5334
|
`[${this.runtime.character.name}] MessageBusService: Room ${agentRoomId} already exists, continuing with message processing`
|
|
4971
5335
|
);
|
|
4972
5336
|
} else {
|
|
@@ -4998,8 +5362,9 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
4998
5362
|
attachments: message.metadata?.attachments,
|
|
4999
5363
|
inReplyTo: message.in_reply_to_message_id ? createUniqueUuid6(this.runtime, message.in_reply_to_message_id) : void 0
|
|
5000
5364
|
};
|
|
5365
|
+
const uniqueMemoryId = createUniqueUuid6(this.runtime, `${message.id}-${this.runtime.agentId}`);
|
|
5001
5366
|
return {
|
|
5002
|
-
id:
|
|
5367
|
+
id: uniqueMemoryId,
|
|
5003
5368
|
entityId: agentAuthorEntityId,
|
|
5004
5369
|
agentId: this.runtime.agentId,
|
|
5005
5370
|
roomId: agentRoomId,
|
|
@@ -5018,25 +5383,45 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
5018
5383
|
}
|
|
5019
5384
|
};
|
|
5020
5385
|
}
|
|
5021
|
-
async handleIncomingMessage(
|
|
5022
|
-
|
|
5386
|
+
async handleIncomingMessage(data) {
|
|
5387
|
+
if (!data || typeof data !== "object") {
|
|
5388
|
+
logger28.error(
|
|
5389
|
+
`[${this.runtime.character.name}] MessageBusService: Invalid message data received`
|
|
5390
|
+
);
|
|
5391
|
+
return;
|
|
5392
|
+
}
|
|
5393
|
+
const messageData = data;
|
|
5394
|
+
if (!messageData.id || !messageData.channel_id || !messageData.author_id || !messageData.content) {
|
|
5395
|
+
logger28.error(
|
|
5396
|
+
`[${this.runtime.character.name}] MessageBusService: Message missing required fields`,
|
|
5397
|
+
{
|
|
5398
|
+
hasId: !!messageData.id,
|
|
5399
|
+
hasChannelId: !!messageData.channel_id,
|
|
5400
|
+
hasAuthorId: !!messageData.author_id,
|
|
5401
|
+
hasContent: !!messageData.content
|
|
5402
|
+
}
|
|
5403
|
+
);
|
|
5404
|
+
return;
|
|
5405
|
+
}
|
|
5406
|
+
const message = messageData;
|
|
5407
|
+
logger28.info(
|
|
5023
5408
|
`[${this.runtime.character.name}] MessageBusService: Received message from central bus`,
|
|
5024
5409
|
{ messageId: message.id }
|
|
5025
5410
|
);
|
|
5026
5411
|
const participants = await this.getChannelParticipants(message.channel_id);
|
|
5027
5412
|
if (!participants.includes(this.runtime.agentId)) {
|
|
5028
|
-
|
|
5413
|
+
logger28.info(
|
|
5029
5414
|
`[${this.runtime.character.name}] MessageBusService: Agent not a participant in channel ${message.channel_id}, ignoring message`
|
|
5030
5415
|
);
|
|
5031
5416
|
return;
|
|
5032
5417
|
}
|
|
5033
|
-
|
|
5418
|
+
logger28.info(
|
|
5034
5419
|
`[${this.runtime.character.name} - ${this.runtime.agentId}] MessageBusService: Agent is a participant in channel ${message.channel_id}, proceeding with message processing`
|
|
5035
5420
|
);
|
|
5036
5421
|
try {
|
|
5037
5422
|
if (!await this.validateServerSubscription(message)) return;
|
|
5038
5423
|
if (!await this.validateNotSelfMessage(message)) return;
|
|
5039
|
-
|
|
5424
|
+
logger28.info(
|
|
5040
5425
|
`[${this.runtime.character.name}] MessageBusService: All checks passed, proceeding to create agent memory and emit MESSAGE_RECEIVED event`
|
|
5041
5426
|
);
|
|
5042
5427
|
const { agentWorldId, agentRoomId } = await this.ensureWorldAndRoomExist(message);
|
|
@@ -5049,13 +5434,13 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
5049
5434
|
);
|
|
5050
5435
|
const existingMemory = await this.runtime.getMemoryById(agentMemory.id);
|
|
5051
5436
|
if (existingMemory) {
|
|
5052
|
-
|
|
5437
|
+
logger28.debug(
|
|
5053
5438
|
`[${this.runtime.character.name}] MessageBusService: Memory ${agentMemory.id} already exists, skipping duplicate processing`
|
|
5054
5439
|
);
|
|
5055
5440
|
return;
|
|
5056
5441
|
}
|
|
5057
5442
|
const callbackForCentralBus = async (responseContent) => {
|
|
5058
|
-
|
|
5443
|
+
logger28.info(
|
|
5059
5444
|
`[${this.runtime.character.name}] Agent generated response for message. Preparing to send back to bus.`
|
|
5060
5445
|
);
|
|
5061
5446
|
await this.runtime.createMemory(
|
|
@@ -5090,7 +5475,7 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
5090
5475
|
}
|
|
5091
5476
|
});
|
|
5092
5477
|
} catch (error) {
|
|
5093
|
-
|
|
5478
|
+
logger28.error(
|
|
5094
5479
|
`[${this.runtime.character.name}] MessageBusService: Error processing incoming message:`,
|
|
5095
5480
|
error
|
|
5096
5481
|
);
|
|
@@ -5098,7 +5483,7 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
5098
5483
|
}
|
|
5099
5484
|
async handleMessageDeleted(data) {
|
|
5100
5485
|
try {
|
|
5101
|
-
|
|
5486
|
+
logger28.info(
|
|
5102
5487
|
`[${this.runtime.character.name}] MessageBusService: Received message_deleted event for message ${data.messageId}`
|
|
5103
5488
|
);
|
|
5104
5489
|
const agentMemoryId = createUniqueUuid6(this.runtime, data.messageId);
|
|
@@ -5109,16 +5494,16 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
5109
5494
|
message: existingMemory,
|
|
5110
5495
|
source: "message-bus-service"
|
|
5111
5496
|
});
|
|
5112
|
-
|
|
5497
|
+
logger28.debug(
|
|
5113
5498
|
`[${this.runtime.character.name}] MessageBusService: Successfully processed message deletion for ${data.messageId}`
|
|
5114
5499
|
);
|
|
5115
5500
|
} else {
|
|
5116
|
-
|
|
5501
|
+
logger28.warn(
|
|
5117
5502
|
`[${this.runtime.character.name}] MessageBusService: No memory found for deleted message ${data.messageId}`
|
|
5118
5503
|
);
|
|
5119
5504
|
}
|
|
5120
5505
|
} catch (error) {
|
|
5121
|
-
|
|
5506
|
+
logger28.error(
|
|
5122
5507
|
`[${this.runtime.character.name}] MessageBusService: Error handling message deletion:`,
|
|
5123
5508
|
error
|
|
5124
5509
|
);
|
|
@@ -5126,7 +5511,7 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
5126
5511
|
}
|
|
5127
5512
|
async handleChannelCleared(data) {
|
|
5128
5513
|
try {
|
|
5129
|
-
|
|
5514
|
+
logger28.info(
|
|
5130
5515
|
`[${this.runtime.character.name}] MessageBusService: Received channel_cleared event for channel ${data.channelId}`
|
|
5131
5516
|
);
|
|
5132
5517
|
const agentRoomId = createUniqueUuid6(this.runtime, data.channelId);
|
|
@@ -5134,7 +5519,7 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
5134
5519
|
tableName: "messages",
|
|
5135
5520
|
roomIds: [agentRoomId]
|
|
5136
5521
|
});
|
|
5137
|
-
|
|
5522
|
+
logger28.info(
|
|
5138
5523
|
`[${this.runtime.character.name}] MessageBusService: Found ${memories.length} memories to delete for channel ${data.channelId}`
|
|
5139
5524
|
);
|
|
5140
5525
|
await this.runtime.emitEvent(EventType2.CHANNEL_CLEARED, {
|
|
@@ -5144,11 +5529,11 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
5144
5529
|
channelId: data.channelId,
|
|
5145
5530
|
memoryCount: memories.length
|
|
5146
5531
|
});
|
|
5147
|
-
|
|
5532
|
+
logger28.info(
|
|
5148
5533
|
`[${this.runtime.character.name}] MessageBusService: Successfully processed channel clear for ${data.channelId} -> room ${agentRoomId}`
|
|
5149
5534
|
);
|
|
5150
5535
|
} catch (error) {
|
|
5151
|
-
|
|
5536
|
+
logger28.error(
|
|
5152
5537
|
`[${this.runtime.character.name}] MessageBusService: Error handling channel clear:`,
|
|
5153
5538
|
error
|
|
5154
5539
|
);
|
|
@@ -5161,14 +5546,14 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
5161
5546
|
const channelId = room?.channelId;
|
|
5162
5547
|
const serverId = world?.serverId;
|
|
5163
5548
|
if (!channelId || !serverId) {
|
|
5164
|
-
|
|
5549
|
+
logger28.error(
|
|
5165
5550
|
`[${this.runtime.character.name}] MessageBusService: Cannot map agent room/world to central IDs for response. AgentRoomID: ${agentRoomId}, AgentWorldID: ${agentWorldId}. Room or World object missing, or channelId/serverId not found on them.`
|
|
5166
5551
|
);
|
|
5167
5552
|
return;
|
|
5168
5553
|
}
|
|
5169
5554
|
const shouldSkip = content.actions?.includes("IGNORE") || !content.text || content.text.trim() === "";
|
|
5170
5555
|
if (shouldSkip) {
|
|
5171
|
-
|
|
5556
|
+
logger28.info(
|
|
5172
5557
|
`[${this.runtime.character.name}] MessageBusService: Skipping response (reason: ${content.actions?.includes("IGNORE") ? "IGNORE action" : "No text"})`
|
|
5173
5558
|
);
|
|
5174
5559
|
return;
|
|
@@ -5198,10 +5583,10 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
5198
5583
|
agentName: this.runtime.character.name,
|
|
5199
5584
|
attachments: content.attachments,
|
|
5200
5585
|
channelType: originalMessage?.metadata?.channelType || room?.type,
|
|
5201
|
-
isDm: originalMessage?.metadata?.isDm || (originalMessage?.metadata?.channelType || room?.type) ===
|
|
5586
|
+
isDm: originalMessage?.metadata?.isDm || (originalMessage?.metadata?.channelType || room?.type) === ChannelType7.DM
|
|
5202
5587
|
}
|
|
5203
5588
|
};
|
|
5204
|
-
|
|
5589
|
+
logger28.info(
|
|
5205
5590
|
`[${this.runtime.character.name}] MessageBusService: Sending payload to central server API endpoint (/api/messaging/submit):`,
|
|
5206
5591
|
payloadToServer
|
|
5207
5592
|
);
|
|
@@ -5214,12 +5599,12 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
5214
5599
|
body: JSON.stringify(payloadToServer)
|
|
5215
5600
|
});
|
|
5216
5601
|
if (!response.ok) {
|
|
5217
|
-
|
|
5602
|
+
logger28.error(
|
|
5218
5603
|
`[${this.runtime.character.name}] MessageBusService: Error sending response to central server: ${response.status} ${await response.text()}`
|
|
5219
5604
|
);
|
|
5220
5605
|
}
|
|
5221
5606
|
} catch (error) {
|
|
5222
|
-
|
|
5607
|
+
logger28.error(
|
|
5223
5608
|
`[${this.runtime.character.name}] MessageBusService: Error sending agent response to bus:`,
|
|
5224
5609
|
error
|
|
5225
5610
|
);
|
|
@@ -5235,7 +5620,7 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
5235
5620
|
body: JSON.stringify({ channel_id: channelId, server_id: serverId })
|
|
5236
5621
|
});
|
|
5237
5622
|
} catch (error) {
|
|
5238
|
-
|
|
5623
|
+
logger28.warn(
|
|
5239
5624
|
`[${this.runtime.character.name}] MessageBusService: Failed to notify completion`,
|
|
5240
5625
|
error
|
|
5241
5626
|
);
|
|
@@ -5260,7 +5645,7 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
5260
5645
|
if (!isNaN(portNum) && portNum > 0 && portNum <= 65535) {
|
|
5261
5646
|
validatedPort = portNum;
|
|
5262
5647
|
} else {
|
|
5263
|
-
|
|
5648
|
+
logger28.warn(`[MessageBusService] Invalid SERVER_PORT value: ${serverPort}`);
|
|
5264
5649
|
}
|
|
5265
5650
|
}
|
|
5266
5651
|
const host = process.platform === "win32" ? "127.0.0.1" : "localhost";
|
|
@@ -5269,14 +5654,14 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
5269
5654
|
try {
|
|
5270
5655
|
const url = new URL(baseUrl);
|
|
5271
5656
|
if (!["http:", "https:"].includes(url.protocol)) {
|
|
5272
|
-
|
|
5657
|
+
logger28.warn(
|
|
5273
5658
|
`[MessageBusService] Unsafe protocol in CENTRAL_MESSAGE_SERVER_URL: ${url.protocol}`
|
|
5274
5659
|
);
|
|
5275
5660
|
return defaultUrl;
|
|
5276
5661
|
}
|
|
5277
5662
|
const allowedHosts = ["localhost", "127.0.0.1", "::1"];
|
|
5278
5663
|
if (!allowedHosts.includes(url.hostname)) {
|
|
5279
|
-
|
|
5664
|
+
logger28.warn(
|
|
5280
5665
|
`[MessageBusService] Unsafe hostname in CENTRAL_MESSAGE_SERVER_URL: ${url.hostname}`
|
|
5281
5666
|
);
|
|
5282
5667
|
return defaultUrl;
|
|
@@ -5284,7 +5669,7 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
5284
5669
|
if (url.port) {
|
|
5285
5670
|
const portNum = parseInt(url.port, 10);
|
|
5286
5671
|
if (isNaN(portNum) || portNum <= 0 || portNum > 65535) {
|
|
5287
|
-
|
|
5672
|
+
logger28.warn(
|
|
5288
5673
|
`[MessageBusService] Invalid port in CENTRAL_MESSAGE_SERVER_URL: ${url.port}`
|
|
5289
5674
|
);
|
|
5290
5675
|
return defaultUrl;
|
|
@@ -5295,14 +5680,14 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
5295
5680
|
url.hash = "";
|
|
5296
5681
|
return url.toString().replace(/\/$/, "");
|
|
5297
5682
|
} catch (error) {
|
|
5298
|
-
|
|
5683
|
+
logger28.error(
|
|
5299
5684
|
`[MessageBusService] Invalid URL format in CENTRAL_MESSAGE_SERVER_URL: ${baseUrl}`
|
|
5300
5685
|
);
|
|
5301
5686
|
return defaultUrl;
|
|
5302
5687
|
}
|
|
5303
5688
|
}
|
|
5304
5689
|
async stop() {
|
|
5305
|
-
|
|
5690
|
+
logger28.info(`[${this.runtime.character.name}] MessageBusService stopping...`);
|
|
5306
5691
|
bus_default.off("new_message", this.boundHandleIncomingMessage);
|
|
5307
5692
|
bus_default.off("server_agent_update", this.boundHandleServerAgentUpdate);
|
|
5308
5693
|
bus_default.off("message_deleted", this.boundHandleMessageDeleted);
|
|
@@ -5320,7 +5705,7 @@ import fs8 from "fs";
|
|
|
5320
5705
|
import path8 from "path";
|
|
5321
5706
|
import { fileURLToPath } from "url";
|
|
5322
5707
|
import {
|
|
5323
|
-
logger as
|
|
5708
|
+
logger as logger29,
|
|
5324
5709
|
parseAndValidateCharacter,
|
|
5325
5710
|
validateCharacter
|
|
5326
5711
|
} from "@elizaos/core";
|
|
@@ -5350,7 +5735,7 @@ async function loadCharactersFromUrl(url) {
|
|
|
5350
5735
|
return characters;
|
|
5351
5736
|
} catch (e) {
|
|
5352
5737
|
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
5353
|
-
|
|
5738
|
+
logger29.error(`Error loading character(s) from ${url}: ${errorMsg}`);
|
|
5354
5739
|
if (errorMsg.includes("Character validation failed") || errorMsg.includes("validation")) {
|
|
5355
5740
|
throw new Error(
|
|
5356
5741
|
`Invalid character data from URL '${url}'. The character data does not match the required schema: ${errorMsg}`
|
|
@@ -5401,13 +5786,13 @@ async function jsonToCharacter(character) {
|
|
|
5401
5786
|
}
|
|
5402
5787
|
const revalidationResult = validateCharacter(updatedCharacter);
|
|
5403
5788
|
if (!revalidationResult.success) {
|
|
5404
|
-
|
|
5789
|
+
logger29.warn(
|
|
5405
5790
|
"Character became invalid after adding environment settings, using original validated character"
|
|
5406
5791
|
);
|
|
5407
5792
|
return validatedCharacter;
|
|
5408
5793
|
}
|
|
5409
5794
|
if (!revalidationResult.data) {
|
|
5410
|
-
|
|
5795
|
+
logger29.warn("Revalidation succeeded but no data returned, using original character");
|
|
5411
5796
|
return validatedCharacter;
|
|
5412
5797
|
}
|
|
5413
5798
|
return revalidationResult.data;
|
|
@@ -5428,30 +5813,30 @@ async function loadCharacter(filePath) {
|
|
|
5428
5813
|
function handleCharacterLoadError(path10, error) {
|
|
5429
5814
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
5430
5815
|
if (errorMsg.includes("ENOENT") || errorMsg.includes("no such file")) {
|
|
5431
|
-
|
|
5816
|
+
logger29.error(`Character file not found: ${path10}`);
|
|
5432
5817
|
throw new Error(
|
|
5433
5818
|
`Character '${path10}' not found. Please check if the file exists and the path is correct.`
|
|
5434
5819
|
);
|
|
5435
5820
|
} else if (errorMsg.includes("Character validation failed")) {
|
|
5436
|
-
|
|
5821
|
+
logger29.error(`Character validation failed for: ${path10}`);
|
|
5437
5822
|
throw new Error(`Character file '${path10}' contains invalid character data. ${errorMsg}`);
|
|
5438
5823
|
} else if (errorMsg.includes("JSON")) {
|
|
5439
|
-
|
|
5824
|
+
logger29.error(`JSON parsing error in character file: ${path10}`);
|
|
5440
5825
|
throw new Error(`Character file '${path10}' has malformed JSON. Please check the file content.`);
|
|
5441
5826
|
} else if (errorMsg.includes("Invalid JSON")) {
|
|
5442
|
-
|
|
5827
|
+
logger29.error(`Invalid JSON in character file: ${path10}`);
|
|
5443
5828
|
throw new Error(
|
|
5444
5829
|
`Character file '${path10}' has invalid JSON format. Please check the file content.`
|
|
5445
5830
|
);
|
|
5446
5831
|
} else {
|
|
5447
|
-
|
|
5832
|
+
logger29.error(`Error loading character from ${path10}: ${errorMsg}`);
|
|
5448
5833
|
throw new Error(`Failed to load character '${path10}': ${errorMsg}`);
|
|
5449
5834
|
}
|
|
5450
5835
|
}
|
|
5451
5836
|
async function safeLoadCharacter(path10) {
|
|
5452
5837
|
try {
|
|
5453
5838
|
const character = await loadCharacter(path10);
|
|
5454
|
-
|
|
5839
|
+
logger29.info(`Successfully loaded character from: ${path10}`);
|
|
5455
5840
|
return character;
|
|
5456
5841
|
} catch (e) {
|
|
5457
5842
|
return handleCharacterLoadError(path10, e);
|
|
@@ -5526,7 +5911,7 @@ async function readCharactersFromStorage(characterPaths) {
|
|
|
5526
5911
|
characterPaths.push(path8.join(uploadDir, fileName));
|
|
5527
5912
|
}
|
|
5528
5913
|
} catch (err) {
|
|
5529
|
-
|
|
5914
|
+
logger29.error(`Error reading directory: ${err.message}`);
|
|
5530
5915
|
}
|
|
5531
5916
|
return characterPaths;
|
|
5532
5917
|
}
|
|
@@ -5544,12 +5929,12 @@ async function loadCharacters(charactersArg) {
|
|
|
5544
5929
|
loadedCharacters.push(character);
|
|
5545
5930
|
} catch (error) {
|
|
5546
5931
|
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
5547
|
-
|
|
5932
|
+
logger29.error(`Failed to load character from '${characterPath}': ${errorMsg}`);
|
|
5548
5933
|
}
|
|
5549
5934
|
}
|
|
5550
5935
|
}
|
|
5551
5936
|
if (hasValidRemoteUrls()) {
|
|
5552
|
-
|
|
5937
|
+
logger29.info("Loading characters from remote URLs");
|
|
5553
5938
|
const characterUrls = commaSeparatedStringToArray(process.env.REMOTE_CHARACTER_URLS || "");
|
|
5554
5939
|
for (const characterUrl of characterUrls) {
|
|
5555
5940
|
const characters = await loadCharactersFromUrl(characterUrl);
|
|
@@ -5557,8 +5942,8 @@ async function loadCharacters(charactersArg) {
|
|
|
5557
5942
|
}
|
|
5558
5943
|
}
|
|
5559
5944
|
if (loadedCharacters.length === 0) {
|
|
5560
|
-
|
|
5561
|
-
|
|
5945
|
+
logger29.info("No characters found, using default character");
|
|
5946
|
+
logger29.warn("Server package does not include a default character. Please provide one.");
|
|
5562
5947
|
}
|
|
5563
5948
|
return loadedCharacters;
|
|
5564
5949
|
}
|
|
@@ -5604,7 +5989,7 @@ function resolvePgliteDir(dir, fallbackDir) {
|
|
|
5604
5989
|
return resolved;
|
|
5605
5990
|
}
|
|
5606
5991
|
var __dirname2 = dirname(fileURLToPath2(import.meta.url));
|
|
5607
|
-
var
|
|
5992
|
+
var DEFAULT_SERVER_ID6 = "00000000-0000-0000-0000-000000000000";
|
|
5608
5993
|
function isWebUIEnabled() {
|
|
5609
5994
|
const isProduction = process.env.NODE_ENV === "production";
|
|
5610
5995
|
const uiEnabledEnv = process.env.ELIZA_UI_ENABLE;
|
|
@@ -5636,13 +6021,13 @@ var AgentServer = class {
|
|
|
5636
6021
|
*/
|
|
5637
6022
|
constructor() {
|
|
5638
6023
|
try {
|
|
5639
|
-
|
|
6024
|
+
logger30.debug("Initializing AgentServer (constructor)...");
|
|
5640
6025
|
this.agents = /* @__PURE__ */ new Map();
|
|
5641
6026
|
this.loadCharacterTryPath = loadCharacterTryPath;
|
|
5642
6027
|
this.jsonToCharacter = jsonToCharacter;
|
|
5643
6028
|
this.registerSignalHandlers();
|
|
5644
6029
|
} catch (error) {
|
|
5645
|
-
|
|
6030
|
+
logger30.error("Failed to initialize AgentServer (constructor):", error);
|
|
5646
6031
|
throw error;
|
|
5647
6032
|
}
|
|
5648
6033
|
}
|
|
@@ -5654,13 +6039,13 @@ var AgentServer = class {
|
|
|
5654
6039
|
*/
|
|
5655
6040
|
async initialize(options) {
|
|
5656
6041
|
if (this.isInitialized) {
|
|
5657
|
-
|
|
6042
|
+
logger30.warn("AgentServer is already initialized, skipping initialization");
|
|
5658
6043
|
return;
|
|
5659
6044
|
}
|
|
5660
6045
|
try {
|
|
5661
|
-
|
|
6046
|
+
logger30.debug("Initializing AgentServer (async operations)...");
|
|
5662
6047
|
const agentDataDir = resolvePgliteDir(options?.dataDir);
|
|
5663
|
-
|
|
6048
|
+
logger30.info(`[INIT] Database Dir for SQL plugin: ${agentDataDir}`);
|
|
5664
6049
|
this.database = createDatabaseAdapter(
|
|
5665
6050
|
{
|
|
5666
6051
|
dataDir: agentDataDir,
|
|
@@ -5669,47 +6054,47 @@ var AgentServer = class {
|
|
|
5669
6054
|
"00000000-0000-0000-0000-000000000002"
|
|
5670
6055
|
);
|
|
5671
6056
|
await this.database.init();
|
|
5672
|
-
|
|
5673
|
-
|
|
6057
|
+
logger30.success("Consolidated database initialized successfully");
|
|
6058
|
+
logger30.info("[INIT] Running database migrations for messaging tables...");
|
|
5674
6059
|
try {
|
|
5675
6060
|
const migrationService = new DatabaseMigrationService();
|
|
5676
6061
|
const db = this.database.getDatabase();
|
|
5677
6062
|
await migrationService.initializeWithDatabase(db);
|
|
5678
6063
|
migrationService.discoverAndRegisterPluginSchemas([sqlPlugin]);
|
|
5679
6064
|
await migrationService.runAllPluginMigrations();
|
|
5680
|
-
|
|
6065
|
+
logger30.success("[INIT] Database migrations completed successfully");
|
|
5681
6066
|
} catch (migrationError) {
|
|
5682
|
-
|
|
6067
|
+
logger30.error("[INIT] Failed to run database migrations:", migrationError);
|
|
5683
6068
|
throw new Error(
|
|
5684
6069
|
`Database migration failed: ${migrationError instanceof Error ? migrationError.message : String(migrationError)}`
|
|
5685
6070
|
);
|
|
5686
6071
|
}
|
|
5687
6072
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
5688
|
-
|
|
6073
|
+
logger30.info("[INIT] Ensuring default server exists...");
|
|
5689
6074
|
await this.ensureDefaultServer();
|
|
5690
|
-
|
|
6075
|
+
logger30.success("[INIT] Default server setup complete");
|
|
5691
6076
|
await this.initializeServer(options);
|
|
5692
6077
|
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
5693
6078
|
this.isInitialized = true;
|
|
5694
6079
|
} catch (error) {
|
|
5695
|
-
|
|
6080
|
+
logger30.error("Failed to initialize AgentServer (async operations):", error);
|
|
5696
6081
|
console.trace(error);
|
|
5697
6082
|
throw error;
|
|
5698
6083
|
}
|
|
5699
6084
|
}
|
|
5700
6085
|
async ensureDefaultServer() {
|
|
5701
6086
|
try {
|
|
5702
|
-
|
|
6087
|
+
logger30.info("[AgentServer] Checking for default server...");
|
|
5703
6088
|
const servers = await this.database.getMessageServers();
|
|
5704
|
-
|
|
6089
|
+
logger30.debug(`[AgentServer] Found ${servers.length} existing servers`);
|
|
5705
6090
|
servers.forEach((s) => {
|
|
5706
|
-
|
|
6091
|
+
logger30.debug(`[AgentServer] Existing server: ID=${s.id}, Name=${s.name}`);
|
|
5707
6092
|
});
|
|
5708
6093
|
const defaultServer = servers.find(
|
|
5709
6094
|
(s) => s.id === "00000000-0000-0000-0000-000000000000"
|
|
5710
6095
|
);
|
|
5711
6096
|
if (!defaultServer) {
|
|
5712
|
-
|
|
6097
|
+
logger30.info(
|
|
5713
6098
|
"[AgentServer] Creating default server with UUID 00000000-0000-0000-0000-000000000000..."
|
|
5714
6099
|
);
|
|
5715
6100
|
try {
|
|
@@ -5718,43 +6103,43 @@ var AgentServer = class {
|
|
|
5718
6103
|
VALUES ('00000000-0000-0000-0000-000000000000', 'Default Server', 'eliza_default', NOW(), NOW())
|
|
5719
6104
|
ON CONFLICT (id) DO NOTHING
|
|
5720
6105
|
`);
|
|
5721
|
-
|
|
6106
|
+
logger30.success("[AgentServer] Default server created via raw SQL");
|
|
5722
6107
|
const checkResult = await this.database.db.execute(
|
|
5723
6108
|
"SELECT id, name FROM message_servers WHERE id = '00000000-0000-0000-0000-000000000000'"
|
|
5724
6109
|
);
|
|
5725
|
-
|
|
6110
|
+
logger30.debug("[AgentServer] Raw SQL check result:", checkResult);
|
|
5726
6111
|
} catch (sqlError) {
|
|
5727
|
-
|
|
6112
|
+
logger30.error("[AgentServer] Raw SQL insert failed:", sqlError);
|
|
5728
6113
|
try {
|
|
5729
6114
|
const server = await this.database.createMessageServer({
|
|
5730
6115
|
id: "00000000-0000-0000-0000-000000000000",
|
|
5731
6116
|
name: "Default Server",
|
|
5732
6117
|
sourceType: "eliza_default"
|
|
5733
6118
|
});
|
|
5734
|
-
|
|
6119
|
+
logger30.success("[AgentServer] Default server created via ORM with ID:", server.id);
|
|
5735
6120
|
} catch (ormError) {
|
|
5736
|
-
|
|
6121
|
+
logger30.error("[AgentServer] Both SQL and ORM creation failed:", ormError);
|
|
5737
6122
|
throw new Error(`Failed to create default server: ${ormError.message}`);
|
|
5738
6123
|
}
|
|
5739
6124
|
}
|
|
5740
6125
|
const verifyServers = await this.database.getMessageServers();
|
|
5741
|
-
|
|
6126
|
+
logger30.debug(`[AgentServer] After creation attempt, found ${verifyServers.length} servers`);
|
|
5742
6127
|
verifyServers.forEach((s) => {
|
|
5743
|
-
|
|
6128
|
+
logger30.debug(`[AgentServer] Server after creation: ID=${s.id}, Name=${s.name}`);
|
|
5744
6129
|
});
|
|
5745
6130
|
const verifyDefault = verifyServers.find(
|
|
5746
6131
|
(s) => s.id === "00000000-0000-0000-0000-000000000000"
|
|
5747
6132
|
);
|
|
5748
6133
|
if (!verifyDefault) {
|
|
5749
|
-
throw new Error(`Failed to create or verify default server with ID ${
|
|
6134
|
+
throw new Error(`Failed to create or verify default server with ID ${DEFAULT_SERVER_ID6}`);
|
|
5750
6135
|
} else {
|
|
5751
|
-
|
|
6136
|
+
logger30.success("[AgentServer] Default server creation verified successfully");
|
|
5752
6137
|
}
|
|
5753
6138
|
} else {
|
|
5754
|
-
|
|
6139
|
+
logger30.info("[AgentServer] Default server already exists with ID:", defaultServer.id);
|
|
5755
6140
|
}
|
|
5756
6141
|
} catch (error) {
|
|
5757
|
-
|
|
6142
|
+
logger30.error("[AgentServer] Error ensuring default server:", error);
|
|
5758
6143
|
throw error;
|
|
5759
6144
|
}
|
|
5760
6145
|
}
|
|
@@ -5769,12 +6154,12 @@ var AgentServer = class {
|
|
|
5769
6154
|
if (options?.clientPath) {
|
|
5770
6155
|
this.clientPath = options.clientPath;
|
|
5771
6156
|
}
|
|
5772
|
-
this.app =
|
|
6157
|
+
this.app = express32();
|
|
5773
6158
|
const isProd = process.env.NODE_ENV === "production";
|
|
5774
|
-
|
|
6159
|
+
logger30.debug("Setting up security headers...");
|
|
5775
6160
|
if (!isProd) {
|
|
5776
|
-
|
|
5777
|
-
|
|
6161
|
+
logger30.debug(`NODE_ENV: ${process.env.NODE_ENV}`);
|
|
6162
|
+
logger30.debug(`CSP will be: ${isProd ? "ENABLED" : "MINIMAL_DEV"}`);
|
|
5778
6163
|
}
|
|
5779
6164
|
this.app.use(
|
|
5780
6165
|
helmet2({
|
|
@@ -5838,12 +6223,12 @@ var AgentServer = class {
|
|
|
5838
6223
|
})
|
|
5839
6224
|
);
|
|
5840
6225
|
if (options?.middlewares) {
|
|
5841
|
-
|
|
6226
|
+
logger30.debug("Applying custom middlewares...");
|
|
5842
6227
|
for (const middleware of options.middlewares) {
|
|
5843
6228
|
this.app.use(middleware);
|
|
5844
6229
|
}
|
|
5845
6230
|
}
|
|
5846
|
-
|
|
6231
|
+
logger30.debug("Setting up standard middlewares...");
|
|
5847
6232
|
this.app.use(
|
|
5848
6233
|
(0, import_cors2.default)({
|
|
5849
6234
|
origin: process.env.CORS_ORIGIN || true,
|
|
@@ -5853,30 +6238,30 @@ var AgentServer = class {
|
|
|
5853
6238
|
})
|
|
5854
6239
|
);
|
|
5855
6240
|
this.app.use(
|
|
5856
|
-
|
|
6241
|
+
express32.json({
|
|
5857
6242
|
limit: process.env.EXPRESS_MAX_PAYLOAD || "2mb"
|
|
5858
6243
|
})
|
|
5859
6244
|
);
|
|
5860
6245
|
const serverAuthToken = process.env.ELIZA_SERVER_AUTH_TOKEN;
|
|
5861
6246
|
if (serverAuthToken) {
|
|
5862
|
-
|
|
6247
|
+
logger30.info("Server authentication enabled. Requires X-API-KEY header for /api routes.");
|
|
5863
6248
|
this.app.use("/api", (req, res, next) => {
|
|
5864
6249
|
apiKeyAuthMiddleware(req, res, next);
|
|
5865
6250
|
});
|
|
5866
6251
|
} else {
|
|
5867
|
-
|
|
6252
|
+
logger30.warn(
|
|
5868
6253
|
"Server authentication is disabled. Set ELIZA_SERVER_AUTH_TOKEN environment variable to enable."
|
|
5869
6254
|
);
|
|
5870
6255
|
}
|
|
5871
6256
|
this.isWebUIEnabled = isWebUIEnabled();
|
|
5872
6257
|
if (this.isWebUIEnabled) {
|
|
5873
|
-
|
|
6258
|
+
logger30.info("Web UI enabled");
|
|
5874
6259
|
} else {
|
|
5875
6260
|
const uiEnabledEnv = process.env.ELIZA_UI_ENABLE;
|
|
5876
6261
|
if (uiEnabledEnv !== void 0 && uiEnabledEnv.trim() !== "") {
|
|
5877
|
-
|
|
6262
|
+
logger30.info(`Web UI disabled by environment variable (ELIZA_UI_ENABLE=${uiEnabledEnv})`);
|
|
5878
6263
|
} else {
|
|
5879
|
-
|
|
6264
|
+
logger30.info("Web UI disabled for security (production mode)");
|
|
5880
6265
|
}
|
|
5881
6266
|
}
|
|
5882
6267
|
const uploadsBasePath = path9.join(process.cwd(), ".eliza", "data", "uploads", "agents");
|
|
@@ -5907,13 +6292,13 @@ var AgentServer = class {
|
|
|
5907
6292
|
res.sendFile(sanitizedFilename, { root: agentUploadsPath }, (err) => {
|
|
5908
6293
|
if (err) {
|
|
5909
6294
|
if (err.message === "Request aborted") {
|
|
5910
|
-
|
|
6295
|
+
logger30.warn(`[MEDIA] Download aborted: ${req.originalUrl}`);
|
|
5911
6296
|
} else if (!res.headersSent) {
|
|
5912
|
-
|
|
6297
|
+
logger30.warn(`[MEDIA] File not found: ${agentUploadsPath}/${sanitizedFilename}`);
|
|
5913
6298
|
res.status(404).json({ error: "File not found" });
|
|
5914
6299
|
}
|
|
5915
6300
|
} else {
|
|
5916
|
-
|
|
6301
|
+
logger30.debug(`[MEDIA] Successfully served: ${sanitizedFilename}`);
|
|
5917
6302
|
}
|
|
5918
6303
|
});
|
|
5919
6304
|
}
|
|
@@ -5961,12 +6346,12 @@ var AgentServer = class {
|
|
|
5961
6346
|
}
|
|
5962
6347
|
res.sendFile(filePath, (err) => {
|
|
5963
6348
|
if (err) {
|
|
5964
|
-
|
|
6349
|
+
logger30.warn(`[STATIC] Channel media file not found: ${filePath}`, err);
|
|
5965
6350
|
if (!res.headersSent) {
|
|
5966
6351
|
res.status(404).json({ error: "File not found" });
|
|
5967
6352
|
}
|
|
5968
6353
|
} else {
|
|
5969
|
-
|
|
6354
|
+
logger30.debug(`[STATIC] Served channel media file: ${filePath}`);
|
|
5970
6355
|
}
|
|
5971
6356
|
});
|
|
5972
6357
|
}
|
|
@@ -6101,30 +6486,30 @@ var AgentServer = class {
|
|
|
6101
6486
|
})()
|
|
6102
6487
|
].filter(Boolean)
|
|
6103
6488
|
].filter(Boolean);
|
|
6104
|
-
|
|
6105
|
-
|
|
6106
|
-
|
|
6489
|
+
logger30.debug(`[STATIC] process.argv[0]: ${process.argv[0]}`);
|
|
6490
|
+
logger30.debug(`[STATIC] process.argv[1]: ${process.argv[1]}`);
|
|
6491
|
+
logger30.debug(`[STATIC] __dirname: ${__dirname2}`);
|
|
6107
6492
|
for (const possiblePath of possiblePaths) {
|
|
6108
6493
|
if (possiblePath && existsSync3(path9.join(possiblePath, "index.html"))) {
|
|
6109
6494
|
clientPath = possiblePath;
|
|
6110
|
-
|
|
6495
|
+
logger30.info(`[STATIC] Found client files at: ${clientPath}`);
|
|
6111
6496
|
break;
|
|
6112
6497
|
}
|
|
6113
6498
|
}
|
|
6114
6499
|
if (clientPath) {
|
|
6115
6500
|
this.clientPath = clientPath;
|
|
6116
|
-
this.app.use(
|
|
6117
|
-
|
|
6501
|
+
this.app.use(express32.static(clientPath, staticOptions));
|
|
6502
|
+
logger30.info(`[STATIC] Serving static files from: ${clientPath}`);
|
|
6118
6503
|
} else {
|
|
6119
|
-
|
|
6504
|
+
logger30.warn("[STATIC] Client dist path not found. Searched locations:");
|
|
6120
6505
|
possiblePaths.forEach((p) => {
|
|
6121
|
-
if (p)
|
|
6506
|
+
if (p) logger30.warn(`[STATIC] - ${p}`);
|
|
6122
6507
|
});
|
|
6123
|
-
|
|
6124
|
-
|
|
6508
|
+
logger30.warn("[STATIC] The web UI will not be available.");
|
|
6509
|
+
logger30.warn(
|
|
6125
6510
|
"[STATIC] To fix this, ensure the client is built: cd packages/client && bun run build"
|
|
6126
6511
|
);
|
|
6127
|
-
|
|
6512
|
+
logger30.warn("[STATIC] Then rebuild the server: cd packages/server && bun run build");
|
|
6128
6513
|
}
|
|
6129
6514
|
}
|
|
6130
6515
|
const pluginRouteHandler = createPluginRouteHandler(this.agents);
|
|
@@ -6134,13 +6519,13 @@ var AgentServer = class {
|
|
|
6134
6519
|
"/api",
|
|
6135
6520
|
(req, _res, next) => {
|
|
6136
6521
|
if (req.path !== "/ping") {
|
|
6137
|
-
|
|
6522
|
+
logger30.debug(`API request: ${req.method} ${req.path}`);
|
|
6138
6523
|
}
|
|
6139
6524
|
next();
|
|
6140
6525
|
},
|
|
6141
6526
|
apiRouter,
|
|
6142
6527
|
(err, req, res, _next) => {
|
|
6143
|
-
|
|
6528
|
+
logger30.error(`API error: ${req.method} ${req.path}`, err);
|
|
6144
6529
|
res.status(500).json({
|
|
6145
6530
|
success: false,
|
|
6146
6531
|
error: {
|
|
@@ -6173,27 +6558,27 @@ var AgentServer = class {
|
|
|
6173
6558
|
if (resolvedClientPath) {
|
|
6174
6559
|
const indexFilePath = path9.join(resolvedClientPath, "index.html");
|
|
6175
6560
|
if (!existsSync3(indexFilePath)) {
|
|
6176
|
-
|
|
6177
|
-
|
|
6561
|
+
logger30.error(`[STATIC] index.html not found at expected path: ${indexFilePath}`);
|
|
6562
|
+
logger30.error(`[STATIC] Client path was: ${resolvedClientPath}`);
|
|
6178
6563
|
res.status(404).send("Client application not found");
|
|
6179
6564
|
return;
|
|
6180
6565
|
}
|
|
6181
6566
|
res.sendFile("index.html", { root: resolvedClientPath }, (err) => {
|
|
6182
6567
|
if (err) {
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6568
|
+
logger30.warn(`[STATIC] Failed to serve index.html: ${err.message}`);
|
|
6569
|
+
logger30.warn(`[STATIC] Attempted root: ${resolvedClientPath}`);
|
|
6570
|
+
logger30.warn(`[STATIC] Full path was: ${indexFilePath}`);
|
|
6571
|
+
logger30.warn(`[STATIC] Error code: ${err.code || "unknown"}`);
|
|
6187
6572
|
if (!res.headersSent) {
|
|
6188
6573
|
res.status(404).send("Client application not found");
|
|
6189
6574
|
}
|
|
6190
6575
|
} else {
|
|
6191
|
-
|
|
6576
|
+
logger30.debug(`[STATIC] Successfully served index.html for route: ${req.path}`);
|
|
6192
6577
|
}
|
|
6193
6578
|
});
|
|
6194
6579
|
} else {
|
|
6195
|
-
|
|
6196
|
-
|
|
6580
|
+
logger30.warn("[STATIC] Client dist path not found in SPA fallback");
|
|
6581
|
+
logger30.warn("[STATIC] Neither local nor instance clientPath variables are set");
|
|
6197
6582
|
res.status(404).send("Client application not found");
|
|
6198
6583
|
}
|
|
6199
6584
|
});
|
|
@@ -6204,9 +6589,9 @@ var AgentServer = class {
|
|
|
6204
6589
|
}
|
|
6205
6590
|
this.server = http.createServer(this.app);
|
|
6206
6591
|
this.socketIO = setupSocketIO(this.server, this.agents, this);
|
|
6207
|
-
|
|
6592
|
+
logger30.success("AgentServer HTTP server and Socket.IO initialized");
|
|
6208
6593
|
} catch (error) {
|
|
6209
|
-
|
|
6594
|
+
logger30.error("Failed to complete server initialization:", error);
|
|
6210
6595
|
throw error;
|
|
6211
6596
|
}
|
|
6212
6597
|
}
|
|
@@ -6229,47 +6614,47 @@ var AgentServer = class {
|
|
|
6229
6614
|
throw new Error("Runtime missing character configuration");
|
|
6230
6615
|
}
|
|
6231
6616
|
this.agents.set(runtime.agentId, runtime);
|
|
6232
|
-
|
|
6617
|
+
logger30.debug(`Agent ${runtime.character.name} (${runtime.agentId}) added to agents map`);
|
|
6233
6618
|
try {
|
|
6234
6619
|
if (messageBusConnectorPlugin) {
|
|
6235
6620
|
await runtime.registerPlugin(messageBusConnectorPlugin);
|
|
6236
|
-
|
|
6621
|
+
logger30.info(
|
|
6237
6622
|
`[AgentServer] Automatically registered MessageBusConnector for agent ${runtime.character.name}`
|
|
6238
6623
|
);
|
|
6239
6624
|
} else {
|
|
6240
|
-
|
|
6625
|
+
logger30.error(`[AgentServer] CRITICAL: MessageBusConnector plugin definition not found.`);
|
|
6241
6626
|
}
|
|
6242
6627
|
} catch (e) {
|
|
6243
|
-
|
|
6628
|
+
logger30.error(
|
|
6244
6629
|
`[AgentServer] CRITICAL: Failed to register MessageBusConnector for agent ${runtime.character.name}`,
|
|
6245
6630
|
e
|
|
6246
6631
|
);
|
|
6247
6632
|
}
|
|
6248
6633
|
const teePlugin = runtime.plugins.find((p) => p.name === "phala-tee-plugin");
|
|
6249
6634
|
if (teePlugin) {
|
|
6250
|
-
|
|
6635
|
+
logger30.debug(`Found TEE plugin for agent ${runtime.agentId}`);
|
|
6251
6636
|
if (teePlugin.providers) {
|
|
6252
6637
|
for (const provider of teePlugin.providers) {
|
|
6253
6638
|
runtime.registerProvider(provider);
|
|
6254
|
-
|
|
6639
|
+
logger30.debug(`Registered TEE provider: ${provider.name}`);
|
|
6255
6640
|
}
|
|
6256
6641
|
}
|
|
6257
6642
|
if (teePlugin.actions) {
|
|
6258
6643
|
for (const action of teePlugin.actions) {
|
|
6259
6644
|
runtime.registerAction(action);
|
|
6260
|
-
|
|
6645
|
+
logger30.debug(`Registered TEE action: ${action.name}`);
|
|
6261
6646
|
}
|
|
6262
6647
|
}
|
|
6263
6648
|
}
|
|
6264
|
-
|
|
6649
|
+
logger30.success(
|
|
6265
6650
|
`Successfully registered agent ${runtime.character.name} (${runtime.agentId}) with core services.`
|
|
6266
6651
|
);
|
|
6267
|
-
await this.addAgentToServer(
|
|
6268
|
-
|
|
6269
|
-
`[AgentServer] Auto-associated agent ${runtime.character.name} with server ID: ${
|
|
6652
|
+
await this.addAgentToServer(DEFAULT_SERVER_ID6, runtime.agentId);
|
|
6653
|
+
logger30.info(
|
|
6654
|
+
`[AgentServer] Auto-associated agent ${runtime.character.name} with server ID: ${DEFAULT_SERVER_ID6}`
|
|
6270
6655
|
);
|
|
6271
6656
|
} catch (error) {
|
|
6272
|
-
|
|
6657
|
+
logger30.error("Failed to register agent:", error);
|
|
6273
6658
|
throw error;
|
|
6274
6659
|
}
|
|
6275
6660
|
}
|
|
@@ -6281,7 +6666,7 @@ var AgentServer = class {
|
|
|
6281
6666
|
*/
|
|
6282
6667
|
unregisterAgent(agentId) {
|
|
6283
6668
|
if (!agentId) {
|
|
6284
|
-
|
|
6669
|
+
logger30.warn("[AGENT UNREGISTER] Attempted to unregister undefined or invalid agent runtime");
|
|
6285
6670
|
return;
|
|
6286
6671
|
}
|
|
6287
6672
|
try {
|
|
@@ -6289,20 +6674,20 @@ var AgentServer = class {
|
|
|
6289
6674
|
if (agent) {
|
|
6290
6675
|
try {
|
|
6291
6676
|
agent.stop().catch((stopError) => {
|
|
6292
|
-
|
|
6677
|
+
logger30.error(
|
|
6293
6678
|
`[AGENT UNREGISTER] Error stopping agent services for ${agentId}:`,
|
|
6294
6679
|
stopError
|
|
6295
6680
|
);
|
|
6296
6681
|
});
|
|
6297
|
-
|
|
6682
|
+
logger30.debug(`[AGENT UNREGISTER] Stopping services for agent ${agentId}`);
|
|
6298
6683
|
} catch (stopError) {
|
|
6299
|
-
|
|
6684
|
+
logger30.error(`[AGENT UNREGISTER] Error initiating stop for agent ${agentId}:`, stopError);
|
|
6300
6685
|
}
|
|
6301
6686
|
}
|
|
6302
6687
|
this.agents.delete(agentId);
|
|
6303
|
-
|
|
6688
|
+
logger30.debug(`Agent ${agentId} removed from agents map`);
|
|
6304
6689
|
} catch (error) {
|
|
6305
|
-
|
|
6690
|
+
logger30.error(`Error removing agent ${agentId}:`, error);
|
|
6306
6691
|
}
|
|
6307
6692
|
}
|
|
6308
6693
|
/**
|
|
@@ -6325,9 +6710,9 @@ var AgentServer = class {
|
|
|
6325
6710
|
if (!port || typeof port !== "number") {
|
|
6326
6711
|
throw new Error(`Invalid port number: ${port}`);
|
|
6327
6712
|
}
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6713
|
+
logger30.debug(`Starting server on port ${port}...`);
|
|
6714
|
+
logger30.debug(`Current agents count: ${this.agents.size}`);
|
|
6715
|
+
logger30.debug(`Environment: ${process.env.NODE_ENV}`);
|
|
6331
6716
|
const host = process.env.SERVER_HOST || "0.0.0.0";
|
|
6332
6717
|
this.server.listen(port, host, () => {
|
|
6333
6718
|
if (this.isWebUIEnabled && process.env.NODE_ENV !== "development") {
|
|
@@ -6347,33 +6732,33 @@ Go to the dashboard at \x1B[1mhttp://localhost:${port}\x1B[22m\x1B[0m`
|
|
|
6347
6732
|
);
|
|
6348
6733
|
}
|
|
6349
6734
|
console.log(`AgentServer is listening on port ${port}`);
|
|
6350
|
-
|
|
6735
|
+
logger30.success(
|
|
6351
6736
|
`REST API bound to ${host}:${port}. If running locally, access it at http://localhost:${port}.`
|
|
6352
6737
|
);
|
|
6353
|
-
|
|
6738
|
+
logger30.debug(`Active agents: ${this.agents.size}`);
|
|
6354
6739
|
this.agents.forEach((agent, id) => {
|
|
6355
|
-
|
|
6740
|
+
logger30.debug(`- Agent ${id}: ${agent.character.name}`);
|
|
6356
6741
|
});
|
|
6357
6742
|
resolve();
|
|
6358
6743
|
}).on("error", (error) => {
|
|
6359
|
-
|
|
6744
|
+
logger30.error(`Failed to bind server to ${host}:${port}:`, error);
|
|
6360
6745
|
if (error.code === "EADDRINUSE") {
|
|
6361
|
-
|
|
6746
|
+
logger30.error(
|
|
6362
6747
|
`Port ${port} is already in use. Please try a different port or stop the process using that port.`
|
|
6363
6748
|
);
|
|
6364
6749
|
} else if (error.code === "EACCES") {
|
|
6365
|
-
|
|
6750
|
+
logger30.error(
|
|
6366
6751
|
`Permission denied to bind to port ${port}. Try using a port above 1024 or running with appropriate permissions.`
|
|
6367
6752
|
);
|
|
6368
6753
|
} else if (error.code === "EADDRNOTAVAIL") {
|
|
6369
|
-
|
|
6754
|
+
logger30.error(
|
|
6370
6755
|
`Cannot bind to ${host}:${port} - address not available. Check if the host address is correct.`
|
|
6371
6756
|
);
|
|
6372
6757
|
}
|
|
6373
6758
|
reject(error);
|
|
6374
6759
|
});
|
|
6375
6760
|
} catch (error) {
|
|
6376
|
-
|
|
6761
|
+
logger30.error("Failed to start server:", error);
|
|
6377
6762
|
reject(error);
|
|
6378
6763
|
}
|
|
6379
6764
|
});
|
|
@@ -6385,7 +6770,7 @@ Go to the dashboard at \x1B[1mhttp://localhost:${port}\x1B[22m\x1B[0m`
|
|
|
6385
6770
|
async stop() {
|
|
6386
6771
|
if (this.server) {
|
|
6387
6772
|
this.server.close(() => {
|
|
6388
|
-
|
|
6773
|
+
logger30.success("Server stopped");
|
|
6389
6774
|
});
|
|
6390
6775
|
}
|
|
6391
6776
|
}
|
|
@@ -6433,7 +6818,7 @@ Go to the dashboard at \x1B[1mhttp://localhost:${port}\x1B[22m\x1B[0m`
|
|
|
6433
6818
|
for (const message of messages) {
|
|
6434
6819
|
await this.database.deleteMessage(message.id);
|
|
6435
6820
|
}
|
|
6436
|
-
|
|
6821
|
+
logger30.info(`[AgentServer] Cleared all messages for central channel: ${channelId}`);
|
|
6437
6822
|
}
|
|
6438
6823
|
async findOrCreateCentralDmChannel(user1Id, user2Id, messageServerId) {
|
|
6439
6824
|
return this.database.findOrCreateDmChannel(user1Id, user2Id, messageServerId);
|
|
@@ -6456,7 +6841,7 @@ Go to the dashboard at \x1B[1mhttp://localhost:${port}\x1B[22m\x1B[0m`
|
|
|
6456
6841
|
metadata: createdMessage.metadata
|
|
6457
6842
|
};
|
|
6458
6843
|
bus_default.emit("new_message", messageForBus);
|
|
6459
|
-
|
|
6844
|
+
logger30.info(`[AgentServer] Published message ${createdMessage.id} to internal message bus`);
|
|
6460
6845
|
}
|
|
6461
6846
|
return createdMessage;
|
|
6462
6847
|
}
|
|
@@ -6465,7 +6850,7 @@ Go to the dashboard at \x1B[1mhttp://localhost:${port}\x1B[22m\x1B[0m`
|
|
|
6465
6850
|
}
|
|
6466
6851
|
// Optional: Method to remove a participant
|
|
6467
6852
|
async removeParticipantFromChannel() {
|
|
6468
|
-
|
|
6853
|
+
logger30.warn(
|
|
6469
6854
|
`[AgentServer] Remove participant operation not directly supported in database adapter`
|
|
6470
6855
|
);
|
|
6471
6856
|
}
|
|
@@ -6522,31 +6907,31 @@ Go to the dashboard at \x1B[1mhttp://localhost:${port}\x1B[22m\x1B[0m`
|
|
|
6522
6907
|
*/
|
|
6523
6908
|
registerSignalHandlers() {
|
|
6524
6909
|
const gracefulShutdown = async () => {
|
|
6525
|
-
|
|
6526
|
-
|
|
6910
|
+
logger30.info("Received shutdown signal, initiating graceful shutdown...");
|
|
6911
|
+
logger30.debug("Stopping all agents...");
|
|
6527
6912
|
for (const [id, agent] of this.agents.entries()) {
|
|
6528
6913
|
try {
|
|
6529
6914
|
await agent.stop();
|
|
6530
|
-
|
|
6915
|
+
logger30.debug(`Stopped agent ${id}`);
|
|
6531
6916
|
} catch (error) {
|
|
6532
|
-
|
|
6917
|
+
logger30.error(`Error stopping agent ${id}:`, error);
|
|
6533
6918
|
}
|
|
6534
6919
|
}
|
|
6535
6920
|
if (this.database) {
|
|
6536
6921
|
try {
|
|
6537
6922
|
await this.database.close();
|
|
6538
|
-
|
|
6923
|
+
logger30.info("Database closed.");
|
|
6539
6924
|
} catch (error) {
|
|
6540
|
-
|
|
6925
|
+
logger30.error("Error closing database:", error);
|
|
6541
6926
|
}
|
|
6542
6927
|
}
|
|
6543
6928
|
if (this.server) {
|
|
6544
6929
|
this.server.close(() => {
|
|
6545
|
-
|
|
6930
|
+
logger30.success("Server closed successfully");
|
|
6546
6931
|
process.exit(0);
|
|
6547
6932
|
});
|
|
6548
6933
|
setTimeout(() => {
|
|
6549
|
-
|
|
6934
|
+
logger30.error("Could not close connections in time, forcing shutdown");
|
|
6550
6935
|
process.exit(1);
|
|
6551
6936
|
}, 5e3);
|
|
6552
6937
|
} else {
|
|
@@ -6555,7 +6940,7 @@ Go to the dashboard at \x1B[1mhttp://localhost:${port}\x1B[22m\x1B[0m`
|
|
|
6555
6940
|
};
|
|
6556
6941
|
process.on("SIGTERM", gracefulShutdown);
|
|
6557
6942
|
process.on("SIGINT", gracefulShutdown);
|
|
6558
|
-
|
|
6943
|
+
logger30.debug("Shutdown handlers registered");
|
|
6559
6944
|
}
|
|
6560
6945
|
};
|
|
6561
6946
|
export {
|