@elizaos/server 1.0.18 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +7 -1
- package/dist/index.js +97 -81
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -196,9 +196,10 @@ declare class AgentServer {
|
|
|
196
196
|
* Starts the server on the specified port.
|
|
197
197
|
*
|
|
198
198
|
* @param {number} port - The port number on which the server should listen.
|
|
199
|
+
* @returns {Promise<void>} A promise that resolves when the server is listening.
|
|
199
200
|
* @throws {Error} If the port is invalid or if there is an error while starting the server.
|
|
200
201
|
*/
|
|
201
|
-
start(port: number): void
|
|
202
|
+
start(port: number): Promise<void>;
|
|
202
203
|
/**
|
|
203
204
|
* Stops the server if it is running. Closes the server connection,
|
|
204
205
|
* stops the database connection, and logs a success message.
|
|
@@ -251,6 +252,11 @@ declare class AgentServer {
|
|
|
251
252
|
* @returns {Promise<UUID[]>} Array of server IDs
|
|
252
253
|
*/
|
|
253
254
|
getServersForAgent(agentId: UUID): Promise<UUID[]>;
|
|
255
|
+
/**
|
|
256
|
+
* Registers signal handlers for graceful shutdown.
|
|
257
|
+
* This is called once in the constructor to prevent handler accumulation.
|
|
258
|
+
*/
|
|
259
|
+
private registerSignalHandlers;
|
|
254
260
|
}
|
|
255
261
|
|
|
256
262
|
export { AgentServer, type CentralRootMessage, type MessageChannel, type MessageServer, type MessageServiceStructure, type ServerMiddleware, type ServerOptions, expandTildePath, hasValidRemoteUrls, isWebUIEnabled, jsonToCharacter, loadCharacter, loadCharacterTryPath, loadCharacters, loadCharactersFromUrl, resolvePgliteDir, tryLoadFile };
|
package/dist/index.js
CHANGED
|
@@ -3811,7 +3811,7 @@ import express28 from "express";
|
|
|
3811
3811
|
// package.json
|
|
3812
3812
|
var package_default = {
|
|
3813
3813
|
name: "@elizaos/server",
|
|
3814
|
-
version: "1.0.
|
|
3814
|
+
version: "1.0.19",
|
|
3815
3815
|
description: "ElizaOS Server - Core server infrastructure for ElizaOS agents",
|
|
3816
3816
|
publishConfig: {
|
|
3817
3817
|
access: "public",
|
|
@@ -4160,7 +4160,7 @@ var SocketIORouter = class {
|
|
|
4160
4160
|
this.sendErrorResponse(socket, `Server ${serverId} does not exist`);
|
|
4161
4161
|
return;
|
|
4162
4162
|
}
|
|
4163
|
-
const isDmChannel = metadata?.isDm || metadata?.channelType === ChannelType5.DM
|
|
4163
|
+
const isDmChannel = metadata?.isDm || metadata?.channelType === ChannelType5.DM;
|
|
4164
4164
|
const channelData = {
|
|
4165
4165
|
id: channelId,
|
|
4166
4166
|
// Use the specific channel ID from the client
|
|
@@ -5200,7 +5200,8 @@ var MessageBusService = class _MessageBusService extends Service {
|
|
|
5200
5200
|
logger27.warn(`[MessageBusService] Invalid SERVER_PORT value: ${serverPort}`);
|
|
5201
5201
|
}
|
|
5202
5202
|
}
|
|
5203
|
-
const
|
|
5203
|
+
const host = process.platform === "win32" ? "127.0.0.1" : "localhost";
|
|
5204
|
+
const defaultUrl = validatedPort ? `http://${host}:${validatedPort}` : `http://${host}:3000`;
|
|
5204
5205
|
const baseUrl = envUrl ?? defaultUrl;
|
|
5205
5206
|
try {
|
|
5206
5207
|
const url = new URL(baseUrl);
|
|
@@ -5574,6 +5575,7 @@ var AgentServer = class {
|
|
|
5574
5575
|
this.agents = /* @__PURE__ */ new Map();
|
|
5575
5576
|
this.loadCharacterTryPath = loadCharacterTryPath;
|
|
5576
5577
|
this.jsonToCharacter = jsonToCharacter;
|
|
5578
|
+
this.registerSignalHandlers();
|
|
5577
5579
|
} catch (error) {
|
|
5578
5580
|
logger29.error("Failed to initialize AgentServer (constructor):", error);
|
|
5579
5581
|
throw error;
|
|
@@ -5592,7 +5594,7 @@ var AgentServer = class {
|
|
|
5592
5594
|
}
|
|
5593
5595
|
try {
|
|
5594
5596
|
logger29.debug("Initializing AgentServer (async operations)...");
|
|
5595
|
-
const agentDataDir =
|
|
5597
|
+
const agentDataDir = resolvePgliteDir(options?.dataDir);
|
|
5596
5598
|
logger29.info(`[INIT] Database Dir for SQL plugin: ${agentDataDir}`);
|
|
5597
5599
|
this.database = createDatabaseAdapter(
|
|
5598
5600
|
{
|
|
@@ -6101,94 +6103,67 @@ var AgentServer = class {
|
|
|
6101
6103
|
* Starts the server on the specified port.
|
|
6102
6104
|
*
|
|
6103
6105
|
* @param {number} port - The port number on which the server should listen.
|
|
6106
|
+
* @returns {Promise<void>} A promise that resolves when the server is listening.
|
|
6104
6107
|
* @throws {Error} If the port is invalid or if there is an error while starting the server.
|
|
6105
6108
|
*/
|
|
6106
6109
|
start(port) {
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
|
|
6110
|
-
|
|
6111
|
-
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6110
|
+
return new Promise((resolve, reject) => {
|
|
6111
|
+
try {
|
|
6112
|
+
if (!port || typeof port !== "number") {
|
|
6113
|
+
throw new Error(`Invalid port number: ${port}`);
|
|
6114
|
+
}
|
|
6115
|
+
logger29.debug(`Starting server on port ${port}...`);
|
|
6116
|
+
logger29.debug(`Current agents count: ${this.agents.size}`);
|
|
6117
|
+
logger29.debug(`Environment: ${process.env.NODE_ENV}`);
|
|
6118
|
+
const host = process.env.SERVER_HOST || "0.0.0.0";
|
|
6119
|
+
this.server.listen(port, host, () => {
|
|
6120
|
+
if (this.isWebUIEnabled && process.env.NODE_ENV !== "development") {
|
|
6121
|
+
console.log(
|
|
6122
|
+
`\x1B[32mStartup successful!
|
|
6119
6123
|
Go to the dashboard at \x1B[1mhttp://localhost:${port}\x1B[22m\x1B[0m`
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
|
|
6123
|
-
|
|
6124
|
-
|
|
6125
|
-
|
|
6124
|
+
);
|
|
6125
|
+
} else if (!this.isWebUIEnabled) {
|
|
6126
|
+
const actualHost = host === "0.0.0.0" ? "localhost" : host;
|
|
6127
|
+
const baseUrl = `http://${actualHost}:${port}`;
|
|
6128
|
+
console.log(
|
|
6129
|
+
`\x1B[32mStartup successful!\x1B[0m
|
|
6126
6130
|
\x1B[33mWeb UI disabled.\x1B[0m \x1B[32mAPI endpoints available at:\x1B[0m
|
|
6127
6131
|
\x1B[1m${baseUrl}/api/server/ping\x1B[22m\x1B[0m
|
|
6128
6132
|
\x1B[1m${baseUrl}/api/agents\x1B[22m\x1B[0m
|
|
6129
6133
|
\x1B[1m${baseUrl}/api/messaging\x1B[22m\x1B[0m`
|
|
6130
|
-
|
|
6131
|
-
}
|
|
6132
|
-
console.log(`AgentServer is listening on port ${port}`);
|
|
6133
|
-
logger29.success(
|
|
6134
|
-
`REST API bound to ${host}:${port}. If running locally, access it at http://localhost:${port}.`
|
|
6135
|
-
);
|
|
6136
|
-
logger29.debug(`Active agents: ${this.agents.size}`);
|
|
6137
|
-
this.agents.forEach((agent, id) => {
|
|
6138
|
-
logger29.debug(`- Agent ${id}: ${agent.character.name}`);
|
|
6139
|
-
});
|
|
6140
|
-
}).on("error", (error) => {
|
|
6141
|
-
logger29.error(`Failed to bind server to ${host}:${port}:`, error);
|
|
6142
|
-
if (error.code === "EADDRINUSE") {
|
|
6143
|
-
logger29.error(
|
|
6144
|
-
`Port ${port} is already in use. Please try a different port or stop the process using that port.`
|
|
6145
|
-
);
|
|
6146
|
-
} else if (error.code === "EACCES") {
|
|
6147
|
-
logger29.error(
|
|
6148
|
-
`Permission denied to bind to port ${port}. Try using a port above 1024 or running with appropriate permissions.`
|
|
6149
|
-
);
|
|
6150
|
-
} else if (error.code === "EADDRNOTAVAIL") {
|
|
6151
|
-
logger29.error(
|
|
6152
|
-
`Cannot bind to ${host}:${port} - address not available. Check if the host address is correct.`
|
|
6153
|
-
);
|
|
6154
|
-
}
|
|
6155
|
-
throw error;
|
|
6156
|
-
});
|
|
6157
|
-
const gracefulShutdown = async () => {
|
|
6158
|
-
logger29.info("Received shutdown signal, initiating graceful shutdown...");
|
|
6159
|
-
logger29.debug("Stopping all agents...");
|
|
6160
|
-
for (const [id, agent] of this.agents.entries()) {
|
|
6161
|
-
try {
|
|
6162
|
-
await agent.stop();
|
|
6163
|
-
logger29.debug(`Stopped agent ${id}`);
|
|
6164
|
-
} catch (error) {
|
|
6165
|
-
logger29.error(`Error stopping agent ${id}:`, error);
|
|
6134
|
+
);
|
|
6166
6135
|
}
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
logger29.
|
|
6136
|
+
console.log(`AgentServer is listening on port ${port}`);
|
|
6137
|
+
logger29.success(
|
|
6138
|
+
`REST API bound to ${host}:${port}. If running locally, access it at http://localhost:${port}.`
|
|
6139
|
+
);
|
|
6140
|
+
logger29.debug(`Active agents: ${this.agents.size}`);
|
|
6141
|
+
this.agents.forEach((agent, id) => {
|
|
6142
|
+
logger29.debug(`- Agent ${id}: ${agent.character.name}`);
|
|
6143
|
+
});
|
|
6144
|
+
resolve();
|
|
6145
|
+
}).on("error", (error) => {
|
|
6146
|
+
logger29.error(`Failed to bind server to ${host}:${port}:`, error);
|
|
6147
|
+
if (error.code === "EADDRINUSE") {
|
|
6148
|
+
logger29.error(
|
|
6149
|
+
`Port ${port} is already in use. Please try a different port or stop the process using that port.`
|
|
6150
|
+
);
|
|
6151
|
+
} else if (error.code === "EACCES") {
|
|
6152
|
+
logger29.error(
|
|
6153
|
+
`Permission denied to bind to port ${port}. Try using a port above 1024 or running with appropriate permissions.`
|
|
6154
|
+
);
|
|
6155
|
+
} else if (error.code === "EADDRNOTAVAIL") {
|
|
6156
|
+
logger29.error(
|
|
6157
|
+
`Cannot bind to ${host}:${port} - address not available. Check if the host address is correct.`
|
|
6158
|
+
);
|
|
6174
6159
|
}
|
|
6175
|
-
|
|
6176
|
-
this.server.close(() => {
|
|
6177
|
-
logger29.success("Server closed successfully");
|
|
6178
|
-
process.exit(0);
|
|
6160
|
+
reject(error);
|
|
6179
6161
|
});
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
process.on("SIGTERM", gracefulShutdown);
|
|
6186
|
-
process.on("SIGINT", gracefulShutdown);
|
|
6187
|
-
logger29.debug("Shutdown handlers registered");
|
|
6188
|
-
} catch (error) {
|
|
6189
|
-
logger29.error("Failed to start server:", error);
|
|
6190
|
-
throw error;
|
|
6191
|
-
}
|
|
6162
|
+
} catch (error) {
|
|
6163
|
+
logger29.error("Failed to start server:", error);
|
|
6164
|
+
reject(error);
|
|
6165
|
+
}
|
|
6166
|
+
});
|
|
6192
6167
|
}
|
|
6193
6168
|
/**
|
|
6194
6169
|
* Stops the server if it is running. Closes the server connection,
|
|
@@ -6328,6 +6303,47 @@ Go to the dashboard at \x1B[1mhttp://localhost:${port}\x1B[22m\x1B[0m`
|
|
|
6328
6303
|
}
|
|
6329
6304
|
return serverIds;
|
|
6330
6305
|
}
|
|
6306
|
+
/**
|
|
6307
|
+
* Registers signal handlers for graceful shutdown.
|
|
6308
|
+
* This is called once in the constructor to prevent handler accumulation.
|
|
6309
|
+
*/
|
|
6310
|
+
registerSignalHandlers() {
|
|
6311
|
+
const gracefulShutdown = async () => {
|
|
6312
|
+
logger29.info("Received shutdown signal, initiating graceful shutdown...");
|
|
6313
|
+
logger29.debug("Stopping all agents...");
|
|
6314
|
+
for (const [id, agent] of this.agents.entries()) {
|
|
6315
|
+
try {
|
|
6316
|
+
await agent.stop();
|
|
6317
|
+
logger29.debug(`Stopped agent ${id}`);
|
|
6318
|
+
} catch (error) {
|
|
6319
|
+
logger29.error(`Error stopping agent ${id}:`, error);
|
|
6320
|
+
}
|
|
6321
|
+
}
|
|
6322
|
+
if (this.database) {
|
|
6323
|
+
try {
|
|
6324
|
+
await this.database.close();
|
|
6325
|
+
logger29.info("Database closed.");
|
|
6326
|
+
} catch (error) {
|
|
6327
|
+
logger29.error("Error closing database:", error);
|
|
6328
|
+
}
|
|
6329
|
+
}
|
|
6330
|
+
if (this.server) {
|
|
6331
|
+
this.server.close(() => {
|
|
6332
|
+
logger29.success("Server closed successfully");
|
|
6333
|
+
process.exit(0);
|
|
6334
|
+
});
|
|
6335
|
+
setTimeout(() => {
|
|
6336
|
+
logger29.error("Could not close connections in time, forcing shutdown");
|
|
6337
|
+
process.exit(1);
|
|
6338
|
+
}, 5e3);
|
|
6339
|
+
} else {
|
|
6340
|
+
process.exit(0);
|
|
6341
|
+
}
|
|
6342
|
+
};
|
|
6343
|
+
process.on("SIGTERM", gracefulShutdown);
|
|
6344
|
+
process.on("SIGINT", gracefulShutdown);
|
|
6345
|
+
logger29.debug("Shutdown handlers registered");
|
|
6346
|
+
}
|
|
6331
6347
|
};
|
|
6332
6348
|
export {
|
|
6333
6349
|
AgentServer,
|