@elizaos/plugin-bootstrap 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +137 -423
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
package/dist/index.js
CHANGED
|
@@ -72,19 +72,19 @@ var require_dedent = __commonJS({
|
|
|
72
72
|
// src/index.ts
|
|
73
73
|
import {
|
|
74
74
|
asUUID,
|
|
75
|
-
ChannelType as
|
|
75
|
+
ChannelType as ChannelType9,
|
|
76
76
|
composePromptFromState as composePromptFromState9,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
ContentType,
|
|
78
|
+
createUniqueUuid as createUniqueUuid3,
|
|
79
|
+
EventType,
|
|
80
|
+
imageDescriptionTemplate,
|
|
81
|
+
logger as logger18,
|
|
80
82
|
messageHandlerTemplate,
|
|
81
83
|
ModelType as ModelType13,
|
|
84
|
+
parseKeyValueXml,
|
|
82
85
|
postCreationTemplate,
|
|
83
86
|
shouldRespondTemplate,
|
|
84
|
-
truncateToCompleteSentence
|
|
85
|
-
parseKeyValueXml,
|
|
86
|
-
imageDescriptionTemplate,
|
|
87
|
-
ContentType
|
|
87
|
+
truncateToCompleteSentence
|
|
88
88
|
} from "@elizaos/core";
|
|
89
89
|
|
|
90
90
|
// ../../node_modules/uuid/dist/esm/stringify.js
|
|
@@ -180,10 +180,6 @@ var choiceAction = {
|
|
|
180
180
|
logger.error("State is required for validating the action");
|
|
181
181
|
throw new Error("State is required for validating the action");
|
|
182
182
|
}
|
|
183
|
-
const pendingTasks = await runtime.getTasks({
|
|
184
|
-
roomId: message.roomId,
|
|
185
|
-
tags: ["AWAITING_CHOICE"]
|
|
186
|
-
});
|
|
187
183
|
const room = state.data.room ?? await runtime.getRoom(message.roomId);
|
|
188
184
|
if (!room || !room.serverId) {
|
|
189
185
|
return false;
|
|
@@ -192,7 +188,21 @@ var choiceAction = {
|
|
|
192
188
|
if (userRole !== "OWNER" && userRole !== "ADMIN") {
|
|
193
189
|
return false;
|
|
194
190
|
}
|
|
195
|
-
|
|
191
|
+
try {
|
|
192
|
+
const pendingTasks = await runtime.getTasks({
|
|
193
|
+
roomId: message.roomId,
|
|
194
|
+
tags: ["AWAITING_CHOICE"]
|
|
195
|
+
});
|
|
196
|
+
const room2 = state.data.room ?? await runtime.getRoom(message.roomId);
|
|
197
|
+
const userRole2 = await getUserServerRole(runtime, message.entityId, room2.serverId);
|
|
198
|
+
if (userRole2 !== "OWNER" && userRole2 !== "ADMIN") {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
return pendingTasks && pendingTasks.length > 0 && pendingTasks.some((task) => task.metadata?.options);
|
|
202
|
+
} catch (error) {
|
|
203
|
+
logger.error("Error validating choice action:", error);
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
196
206
|
},
|
|
197
207
|
handler: async (runtime, message, state, _options, callback, responses) => {
|
|
198
208
|
const pendingTasks = await runtime.getTasks({
|
|
@@ -4907,8 +4917,9 @@ var settingsProvider = {
|
|
|
4907
4917
|
world = await runtime.getWorld(room.worldId);
|
|
4908
4918
|
if (!world) {
|
|
4909
4919
|
logger15.error(`No world found for room ${room.worldId}`);
|
|
4920
|
+
throw new Error(`No world found for room ${room.worldId}`);
|
|
4910
4921
|
}
|
|
4911
|
-
serverId = world
|
|
4922
|
+
serverId = world.serverId;
|
|
4912
4923
|
if (serverId) {
|
|
4913
4924
|
worldSettings = await getWorldSettings2(runtime, serverId);
|
|
4914
4925
|
} else {
|
|
@@ -4916,6 +4927,7 @@ var settingsProvider = {
|
|
|
4916
4927
|
}
|
|
4917
4928
|
} catch (error) {
|
|
4918
4929
|
logger15.error(`Error processing world data: ${error}`);
|
|
4930
|
+
throw new Error("Failed to process world information");
|
|
4919
4931
|
}
|
|
4920
4932
|
}
|
|
4921
4933
|
if (!serverId) {
|
|
@@ -5169,254 +5181,13 @@ var worldProvider = {
|
|
|
5169
5181
|
}
|
|
5170
5182
|
};
|
|
5171
5183
|
|
|
5172
|
-
// src/services/scenario.ts
|
|
5173
|
-
import {
|
|
5174
|
-
ChannelType as ChannelType9,
|
|
5175
|
-
EventType,
|
|
5176
|
-
Service,
|
|
5177
|
-
createUniqueUuid as createUniqueUuid3,
|
|
5178
|
-
logger as logger17
|
|
5179
|
-
} from "@elizaos/core";
|
|
5180
|
-
var ScenarioService = class _ScenarioService extends Service {
|
|
5181
|
-
/**
|
|
5182
|
-
* Constructor for creating a new instance of the class.
|
|
5183
|
-
*
|
|
5184
|
-
* @param runtime - The IAgentRuntime instance to be passed to the constructor.
|
|
5185
|
-
*/
|
|
5186
|
-
constructor(runtime) {
|
|
5187
|
-
super(runtime);
|
|
5188
|
-
this.runtime = runtime;
|
|
5189
|
-
this.setupEventListeners();
|
|
5190
|
-
}
|
|
5191
|
-
static serviceType = "scenario";
|
|
5192
|
-
capabilityDescription = "The agent is currently in a scenario testing environment. It can Create groups, send messages, and talk to other agents in a live interactive testing environment.";
|
|
5193
|
-
messageHandlers = /* @__PURE__ */ new Map();
|
|
5194
|
-
worlds = /* @__PURE__ */ new Map();
|
|
5195
|
-
activeActions = /* @__PURE__ */ new Map();
|
|
5196
|
-
activeEvaluators = /* @__PURE__ */ new Map();
|
|
5197
|
-
setupEventListeners() {
|
|
5198
|
-
this.runtime.registerEvent(EventType.ACTION_STARTED, async (data) => {
|
|
5199
|
-
this.activeActions.set(data.actionId, {
|
|
5200
|
-
actionId: data.actionId,
|
|
5201
|
-
actionName: data.actionName,
|
|
5202
|
-
startTime: Date.now(),
|
|
5203
|
-
completed: false
|
|
5204
|
-
});
|
|
5205
|
-
return Promise.resolve();
|
|
5206
|
-
});
|
|
5207
|
-
this.runtime.registerEvent(EventType.ACTION_COMPLETED, async (data) => {
|
|
5208
|
-
const action = this.activeActions.get(data.actionId);
|
|
5209
|
-
if (action) {
|
|
5210
|
-
action.completed = true;
|
|
5211
|
-
action.error = data.error;
|
|
5212
|
-
}
|
|
5213
|
-
return Promise.resolve();
|
|
5214
|
-
});
|
|
5215
|
-
this.runtime.registerEvent(EventType.EVALUATOR_STARTED, async (data) => {
|
|
5216
|
-
this.activeEvaluators.set(data.evaluatorId, {
|
|
5217
|
-
evaluatorId: data.evaluatorId,
|
|
5218
|
-
evaluatorName: data.evaluatorName,
|
|
5219
|
-
startTime: Date.now(),
|
|
5220
|
-
completed: false
|
|
5221
|
-
});
|
|
5222
|
-
logger17.debug("[Bootstrap] Evaluator started", data);
|
|
5223
|
-
return Promise.resolve();
|
|
5224
|
-
});
|
|
5225
|
-
this.runtime.registerEvent(
|
|
5226
|
-
EventType.EVALUATOR_COMPLETED,
|
|
5227
|
-
async (data) => {
|
|
5228
|
-
const evaluator = this.activeEvaluators.get(data.evaluatorId);
|
|
5229
|
-
if (evaluator) {
|
|
5230
|
-
evaluator.completed = true;
|
|
5231
|
-
evaluator.error = data.error;
|
|
5232
|
-
}
|
|
5233
|
-
logger17.debug("[Bootstrap] Evaluator completed", data);
|
|
5234
|
-
return Promise.resolve();
|
|
5235
|
-
}
|
|
5236
|
-
);
|
|
5237
|
-
}
|
|
5238
|
-
/**
|
|
5239
|
-
* Start the scenario service with the given runtime.
|
|
5240
|
-
* @param {IAgentRuntime} runtime - The agent runtime
|
|
5241
|
-
* @returns {Promise<ScenarioService>} - The started scenario service
|
|
5242
|
-
*/
|
|
5243
|
-
static async start(runtime) {
|
|
5244
|
-
const service = new _ScenarioService(runtime);
|
|
5245
|
-
return service;
|
|
5246
|
-
}
|
|
5247
|
-
/**
|
|
5248
|
-
* Stops the Scenario service associated with the given runtime.
|
|
5249
|
-
*
|
|
5250
|
-
* @param {IAgentRuntime} runtime The runtime to stop the service for.
|
|
5251
|
-
* @throws {Error} When the Scenario service is not found.
|
|
5252
|
-
*/
|
|
5253
|
-
static async stop(runtime) {
|
|
5254
|
-
const service = runtime.getService(_ScenarioService.serviceType);
|
|
5255
|
-
if (!service) {
|
|
5256
|
-
throw new Error("Scenario service not found");
|
|
5257
|
-
}
|
|
5258
|
-
service.stop();
|
|
5259
|
-
}
|
|
5260
|
-
/**
|
|
5261
|
-
* Asynchronously stops the current process by clearing all message handlers and worlds.
|
|
5262
|
-
*/
|
|
5263
|
-
async stop() {
|
|
5264
|
-
this.messageHandlers.clear();
|
|
5265
|
-
this.worlds.clear();
|
|
5266
|
-
this.activeActions.clear();
|
|
5267
|
-
this.activeEvaluators.clear();
|
|
5268
|
-
}
|
|
5269
|
-
/**
|
|
5270
|
-
* Creates a new world with the specified name and owner.
|
|
5271
|
-
* @param name The name of the world
|
|
5272
|
-
* @param ownerName The name of the world owner
|
|
5273
|
-
* @returns The created world's ID
|
|
5274
|
-
*/
|
|
5275
|
-
async createWorld(name, ownerName) {
|
|
5276
|
-
const serverId = createUniqueUuid3(this.runtime.agentId, name);
|
|
5277
|
-
const worldId = v4_default();
|
|
5278
|
-
const ownerId = v4_default();
|
|
5279
|
-
const world = {
|
|
5280
|
-
id: worldId,
|
|
5281
|
-
name,
|
|
5282
|
-
serverId,
|
|
5283
|
-
agentId: this.runtime.agentId,
|
|
5284
|
-
// TODO: get the server id, create it or whatever
|
|
5285
|
-
metadata: {
|
|
5286
|
-
// this is wrong, the owner needs to be tracked by scenario and similar to how we do it with Discord etc
|
|
5287
|
-
owner: {
|
|
5288
|
-
id: ownerId,
|
|
5289
|
-
name: ownerName
|
|
5290
|
-
}
|
|
5291
|
-
}
|
|
5292
|
-
};
|
|
5293
|
-
this.worlds.set(worldId, world);
|
|
5294
|
-
return worldId;
|
|
5295
|
-
}
|
|
5296
|
-
/**
|
|
5297
|
-
* Creates a room in the specified world.
|
|
5298
|
-
* @param worldId The ID of the world to create the room in
|
|
5299
|
-
* @param name The name of the room
|
|
5300
|
-
* @returns The created room's ID
|
|
5301
|
-
*/
|
|
5302
|
-
async createRoom(worldId, name) {
|
|
5303
|
-
const world = this.worlds.get(worldId);
|
|
5304
|
-
if (!world) {
|
|
5305
|
-
throw new Error(`World ${worldId} not found`);
|
|
5306
|
-
}
|
|
5307
|
-
const roomId = v4_default();
|
|
5308
|
-
await this.runtime.ensureRoomExists({
|
|
5309
|
-
id: roomId,
|
|
5310
|
-
name,
|
|
5311
|
-
source: "scenario",
|
|
5312
|
-
type: ChannelType9.GROUP,
|
|
5313
|
-
channelId: roomId,
|
|
5314
|
-
serverId: worldId,
|
|
5315
|
-
worldId
|
|
5316
|
-
});
|
|
5317
|
-
return roomId;
|
|
5318
|
-
}
|
|
5319
|
-
/**
|
|
5320
|
-
* Adds a participant to a room
|
|
5321
|
-
* @param worldId The world ID
|
|
5322
|
-
* @param roomId The room ID
|
|
5323
|
-
* @param participantId The participant's ID
|
|
5324
|
-
*/
|
|
5325
|
-
async addParticipant(worldId, roomId, participantId) {
|
|
5326
|
-
const world = this.worlds.get(worldId);
|
|
5327
|
-
if (!world) {
|
|
5328
|
-
throw new Error(`World ${worldId} not found`);
|
|
5329
|
-
}
|
|
5330
|
-
const room = this.runtime.getRoom(roomId);
|
|
5331
|
-
if (!room) {
|
|
5332
|
-
throw new Error(`Room ${roomId} not found in world ${worldId}`);
|
|
5333
|
-
}
|
|
5334
|
-
await this.runtime.addParticipant(roomId, participantId);
|
|
5335
|
-
}
|
|
5336
|
-
/**
|
|
5337
|
-
* Sends a message in a specific room
|
|
5338
|
-
* @param sender The runtime of the sending agent
|
|
5339
|
-
* @param worldId The world ID
|
|
5340
|
-
* @param roomId The room ID
|
|
5341
|
-
* @param text The message text
|
|
5342
|
-
*/
|
|
5343
|
-
async sendMessage(sender, worldId, roomId, text) {
|
|
5344
|
-
const world = this.worlds.get(worldId);
|
|
5345
|
-
if (!world) {
|
|
5346
|
-
throw new Error(`World ${worldId} not found`);
|
|
5347
|
-
}
|
|
5348
|
-
const memory = {
|
|
5349
|
-
entityId: sender.agentId,
|
|
5350
|
-
agentId: sender.agentId,
|
|
5351
|
-
roomId,
|
|
5352
|
-
content: {
|
|
5353
|
-
text,
|
|
5354
|
-
source: "scenario",
|
|
5355
|
-
name: sender.character.name,
|
|
5356
|
-
userName: sender.character.name,
|
|
5357
|
-
channelType: ChannelType9.GROUP
|
|
5358
|
-
}
|
|
5359
|
-
};
|
|
5360
|
-
const participants = await this.runtime.getParticipantsForRoom(roomId);
|
|
5361
|
-
for (const participantId of participants) {
|
|
5362
|
-
this.runtime.emitEvent("MESSAGE_RECEIVED", {
|
|
5363
|
-
runtime: this.runtime,
|
|
5364
|
-
message: memory,
|
|
5365
|
-
roomId,
|
|
5366
|
-
entityId: participantId,
|
|
5367
|
-
source: "scenario",
|
|
5368
|
-
type: ChannelType9.GROUP
|
|
5369
|
-
});
|
|
5370
|
-
}
|
|
5371
|
-
}
|
|
5372
|
-
/**
|
|
5373
|
-
* Waits for all active actions and evaluators to complete
|
|
5374
|
-
* @param timeout Maximum time to wait in milliseconds
|
|
5375
|
-
* @returns True if all completed successfully, false if timeout occurred
|
|
5376
|
-
*/
|
|
5377
|
-
async waitForCompletion(timeout = 3e4) {
|
|
5378
|
-
const startTime = Date.now();
|
|
5379
|
-
while (Date.now() - startTime < timeout) {
|
|
5380
|
-
const allActionsComplete = Array.from(this.activeActions.values()).every(
|
|
5381
|
-
(action) => action.completed
|
|
5382
|
-
);
|
|
5383
|
-
const allEvaluatorsComplete = Array.from(this.activeEvaluators.values()).every(
|
|
5384
|
-
(evaluator) => evaluator.completed
|
|
5385
|
-
);
|
|
5386
|
-
if (allActionsComplete && allEvaluatorsComplete) {
|
|
5387
|
-
return true;
|
|
5388
|
-
}
|
|
5389
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
5390
|
-
}
|
|
5391
|
-
return false;
|
|
5392
|
-
}
|
|
5393
|
-
/**
|
|
5394
|
-
* Gets the current state of all active actions and evaluators
|
|
5395
|
-
*/
|
|
5396
|
-
getActiveState() {
|
|
5397
|
-
return {
|
|
5398
|
-
actions: Array.from(this.activeActions.values()),
|
|
5399
|
-
evaluators: Array.from(this.activeEvaluators.values())
|
|
5400
|
-
};
|
|
5401
|
-
}
|
|
5402
|
-
/**
|
|
5403
|
-
* Cleans up the scenario state
|
|
5404
|
-
*/
|
|
5405
|
-
async cleanup() {
|
|
5406
|
-
this.worlds.clear();
|
|
5407
|
-
this.activeActions.clear();
|
|
5408
|
-
this.activeEvaluators.clear();
|
|
5409
|
-
this.messageHandlers.clear();
|
|
5410
|
-
}
|
|
5411
|
-
};
|
|
5412
|
-
|
|
5413
5184
|
// src/services/task.ts
|
|
5414
5185
|
import {
|
|
5415
|
-
logger as
|
|
5416
|
-
Service
|
|
5186
|
+
logger as logger17,
|
|
5187
|
+
Service,
|
|
5417
5188
|
ServiceType
|
|
5418
5189
|
} from "@elizaos/core";
|
|
5419
|
-
var TaskService = class _TaskService extends
|
|
5190
|
+
var TaskService = class _TaskService extends Service {
|
|
5420
5191
|
timer = null;
|
|
5421
5192
|
TICK_INTERVAL = 1e3;
|
|
5422
5193
|
// Check every second
|
|
@@ -5425,7 +5196,7 @@ var TaskService = class _TaskService extends Service2 {
|
|
|
5425
5196
|
/**
|
|
5426
5197
|
* Start the TaskService with the given runtime.
|
|
5427
5198
|
* @param {IAgentRuntime} runtime - The runtime for the TaskService.
|
|
5428
|
-
* @returns {Promise<
|
|
5199
|
+
* @returns {Promise<Service>} A promise that resolves with the TaskService instance.
|
|
5429
5200
|
*/
|
|
5430
5201
|
static async start(runtime) {
|
|
5431
5202
|
const service = new _TaskService(runtime);
|
|
@@ -5440,21 +5211,21 @@ var TaskService = class _TaskService extends Service2 {
|
|
|
5440
5211
|
this.runtime.registerTaskWorker({
|
|
5441
5212
|
name: "REPEATING_TEST_TASK",
|
|
5442
5213
|
validate: async (_runtime, _message, _state) => {
|
|
5443
|
-
|
|
5214
|
+
logger17.debug("[Bootstrap] Validating repeating test task");
|
|
5444
5215
|
return true;
|
|
5445
5216
|
},
|
|
5446
5217
|
execute: async (_runtime, _options) => {
|
|
5447
|
-
|
|
5218
|
+
logger17.debug("[Bootstrap] Executing repeating test task");
|
|
5448
5219
|
}
|
|
5449
5220
|
});
|
|
5450
5221
|
this.runtime.registerTaskWorker({
|
|
5451
5222
|
name: "ONETIME_TEST_TASK",
|
|
5452
5223
|
validate: async (_runtime, _message, _state) => {
|
|
5453
|
-
|
|
5224
|
+
logger17.debug("[Bootstrap] Validating one-time test task");
|
|
5454
5225
|
return true;
|
|
5455
5226
|
},
|
|
5456
5227
|
execute: async (_runtime, _options) => {
|
|
5457
|
-
|
|
5228
|
+
logger17.debug("[Bootstrap] Executing one-time test task");
|
|
5458
5229
|
}
|
|
5459
5230
|
});
|
|
5460
5231
|
const tasks = await this.runtime.getTasksByName("REPEATING_TEST_TASK");
|
|
@@ -5491,7 +5262,7 @@ var TaskService = class _TaskService extends Service2 {
|
|
|
5491
5262
|
try {
|
|
5492
5263
|
await this.checkTasks();
|
|
5493
5264
|
} catch (error) {
|
|
5494
|
-
|
|
5265
|
+
logger17.error("[Bootstrap] Error checking tasks:", error);
|
|
5495
5266
|
}
|
|
5496
5267
|
}, this.TICK_INTERVAL);
|
|
5497
5268
|
}
|
|
@@ -5520,7 +5291,7 @@ var TaskService = class _TaskService extends Service2 {
|
|
|
5520
5291
|
continue;
|
|
5521
5292
|
}
|
|
5522
5293
|
} catch (error) {
|
|
5523
|
-
|
|
5294
|
+
logger17.error(`[Bootstrap] Error validating task ${task.name}:`, error);
|
|
5524
5295
|
continue;
|
|
5525
5296
|
}
|
|
5526
5297
|
}
|
|
@@ -5562,20 +5333,20 @@ var TaskService = class _TaskService extends Service2 {
|
|
|
5562
5333
|
}
|
|
5563
5334
|
if (task.metadata?.updatedAt === task.metadata?.createdAt) {
|
|
5564
5335
|
if (task.tags?.includes("immediate")) {
|
|
5565
|
-
|
|
5336
|
+
logger17.debug("[Bootstrap] Immediately running task", task.name);
|
|
5566
5337
|
await this.executeTask(task);
|
|
5567
5338
|
continue;
|
|
5568
5339
|
}
|
|
5569
5340
|
}
|
|
5570
5341
|
if (now - taskStartTime >= updateIntervalMs) {
|
|
5571
|
-
|
|
5342
|
+
logger17.debug(
|
|
5572
5343
|
`[Bootstrap] Executing task ${task.name} - interval of ${updateIntervalMs}ms has elapsed`
|
|
5573
5344
|
);
|
|
5574
5345
|
await this.executeTask(task);
|
|
5575
5346
|
}
|
|
5576
5347
|
}
|
|
5577
5348
|
} catch (error) {
|
|
5578
|
-
|
|
5349
|
+
logger17.error("[Bootstrap] Error checking tasks:", error);
|
|
5579
5350
|
}
|
|
5580
5351
|
}
|
|
5581
5352
|
/**
|
|
@@ -5586,12 +5357,12 @@ var TaskService = class _TaskService extends Service2 {
|
|
|
5586
5357
|
async executeTask(task) {
|
|
5587
5358
|
try {
|
|
5588
5359
|
if (!task || !task.id) {
|
|
5589
|
-
|
|
5360
|
+
logger17.debug(`[Bootstrap] Task not found`);
|
|
5590
5361
|
return;
|
|
5591
5362
|
}
|
|
5592
5363
|
const worker = this.runtime.getTaskWorker(task.name);
|
|
5593
5364
|
if (!worker) {
|
|
5594
|
-
|
|
5365
|
+
logger17.debug(`[Bootstrap] No worker found for task type: ${task.name}`);
|
|
5595
5366
|
return;
|
|
5596
5367
|
}
|
|
5597
5368
|
if (task.tags?.includes("repeat")) {
|
|
@@ -5601,20 +5372,20 @@ var TaskService = class _TaskService extends Service2 {
|
|
|
5601
5372
|
updatedAt: Date.now()
|
|
5602
5373
|
}
|
|
5603
5374
|
});
|
|
5604
|
-
|
|
5375
|
+
logger17.debug(
|
|
5605
5376
|
`[Bootstrap] Updated repeating task ${task.name} (${task.id}) with new timestamp`
|
|
5606
5377
|
);
|
|
5607
5378
|
}
|
|
5608
|
-
|
|
5379
|
+
logger17.debug(`[Bootstrap] Executing task ${task.name} (${task.id})`);
|
|
5609
5380
|
await worker.execute(this.runtime, task.metadata || {}, task);
|
|
5610
5381
|
if (!task.tags?.includes("repeat")) {
|
|
5611
5382
|
await this.runtime.deleteTask(task.id);
|
|
5612
|
-
|
|
5383
|
+
logger17.debug(
|
|
5613
5384
|
`[Bootstrap] Deleted non-repeating task ${task.name} (${task.id}) after execution`
|
|
5614
5385
|
);
|
|
5615
5386
|
}
|
|
5616
5387
|
} catch (error) {
|
|
5617
|
-
|
|
5388
|
+
logger17.error(`[Bootstrap] Error executing task ${task.id}:`, error);
|
|
5618
5389
|
}
|
|
5619
5390
|
}
|
|
5620
5391
|
/**
|
|
@@ -5662,13 +5433,13 @@ async function processAttachments(attachments, runtime) {
|
|
|
5662
5433
|
if (!attachments || attachments.length === 0) {
|
|
5663
5434
|
return [];
|
|
5664
5435
|
}
|
|
5665
|
-
|
|
5436
|
+
logger18.debug(`[Bootstrap] Processing ${attachments.length} attachment(s)`);
|
|
5666
5437
|
const processedAttachments = [];
|
|
5667
5438
|
for (const attachment of attachments) {
|
|
5668
5439
|
try {
|
|
5669
5440
|
const processedAttachment = { ...attachment };
|
|
5670
5441
|
if (attachment.contentType === ContentType.IMAGE && !attachment.description) {
|
|
5671
|
-
|
|
5442
|
+
logger18.debug(`[Bootstrap] Generating description for image: ${attachment.url}`);
|
|
5672
5443
|
try {
|
|
5673
5444
|
const response = await runtime.useModel(ModelType13.IMAGE_DESCRIPTION, {
|
|
5674
5445
|
prompt: imageDescriptionTemplate,
|
|
@@ -5680,29 +5451,29 @@ async function processAttachments(attachments, runtime) {
|
|
|
5680
5451
|
processedAttachment.description = parsedXml.description;
|
|
5681
5452
|
processedAttachment.title = parsedXml.title || "Image";
|
|
5682
5453
|
processedAttachment.text = parsedXml.text;
|
|
5683
|
-
|
|
5454
|
+
logger18.debug(
|
|
5684
5455
|
`[Bootstrap] Generated description: ${processedAttachment.description?.substring(0, 100)}...`
|
|
5685
5456
|
);
|
|
5686
5457
|
} else {
|
|
5687
|
-
|
|
5458
|
+
logger18.warn(`[Bootstrap] Failed to parse XML response for image description`);
|
|
5688
5459
|
}
|
|
5689
5460
|
} else if (response && typeof response === "object" && "description" in response) {
|
|
5690
5461
|
processedAttachment.description = response.description;
|
|
5691
5462
|
processedAttachment.title = response.title || "Image";
|
|
5692
5463
|
processedAttachment.text = response.description;
|
|
5693
|
-
|
|
5464
|
+
logger18.debug(
|
|
5694
5465
|
`[Bootstrap] Generated description: ${processedAttachment.description?.substring(0, 100)}...`
|
|
5695
5466
|
);
|
|
5696
5467
|
} else {
|
|
5697
|
-
|
|
5468
|
+
logger18.warn(`[Bootstrap] Unexpected response format for image description`);
|
|
5698
5469
|
}
|
|
5699
5470
|
} catch (error) {
|
|
5700
|
-
|
|
5471
|
+
logger18.error(`[Bootstrap] Error generating image description:`, error);
|
|
5701
5472
|
}
|
|
5702
5473
|
}
|
|
5703
5474
|
processedAttachments.push(processedAttachment);
|
|
5704
5475
|
} catch (error) {
|
|
5705
|
-
|
|
5476
|
+
logger18.error(`[Bootstrap] Failed to process attachment ${attachment.url}:`, error);
|
|
5706
5477
|
processedAttachments.push(attachment);
|
|
5707
5478
|
}
|
|
5708
5479
|
}
|
|
@@ -5716,10 +5487,10 @@ function shouldBypassShouldRespond(runtime, room, source) {
|
|
|
5716
5487
|
return cleaned.split(",").map((v) => v.trim()).filter(Boolean);
|
|
5717
5488
|
}
|
|
5718
5489
|
const defaultBypassTypes = [
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
|
|
5490
|
+
ChannelType9.DM,
|
|
5491
|
+
ChannelType9.VOICE_DM,
|
|
5492
|
+
ChannelType9.SELF,
|
|
5493
|
+
ChannelType9.API
|
|
5723
5494
|
];
|
|
5724
5495
|
const defaultBypassSources = ["client_chat"];
|
|
5725
5496
|
const bypassTypesSetting = normalizeEnvList(runtime.getSetting("SHOULD_RESPOND_BYPASS_TYPES"));
|
|
@@ -5747,7 +5518,7 @@ var messageReceivedHandler = async ({
|
|
|
5747
5518
|
const timeoutDuration = 60 * 60 * 1e3;
|
|
5748
5519
|
let timeoutId = void 0;
|
|
5749
5520
|
try {
|
|
5750
|
-
|
|
5521
|
+
logger18.info(`[Bootstrap] Message received from ${message.entityId} in room ${message.roomId}`);
|
|
5751
5522
|
const responseId = v4_default();
|
|
5752
5523
|
if (!latestResponseIds.has(runtime.agentId)) {
|
|
5753
5524
|
latestResponseIds.set(runtime.agentId, /* @__PURE__ */ new Map());
|
|
@@ -5759,7 +5530,7 @@ var messageReceivedHandler = async ({
|
|
|
5759
5530
|
agentResponses.set(message.roomId, responseId);
|
|
5760
5531
|
const runId = asUUID(v4_default());
|
|
5761
5532
|
const startTime = Date.now();
|
|
5762
|
-
await runtime.emitEvent(
|
|
5533
|
+
await runtime.emitEvent(EventType.RUN_STARTED, {
|
|
5763
5534
|
runtime,
|
|
5764
5535
|
runId,
|
|
5765
5536
|
messageId: message.id,
|
|
@@ -5771,7 +5542,7 @@ var messageReceivedHandler = async ({
|
|
|
5771
5542
|
});
|
|
5772
5543
|
const timeoutPromise = new Promise((_, reject) => {
|
|
5773
5544
|
timeoutId = setTimeout(async () => {
|
|
5774
|
-
await runtime.emitEvent(
|
|
5545
|
+
await runtime.emitEvent(EventType.RUN_TIMEOUT, {
|
|
5775
5546
|
runtime,
|
|
5776
5547
|
runId,
|
|
5777
5548
|
messageId: message.id,
|
|
@@ -5790,13 +5561,13 @@ var messageReceivedHandler = async ({
|
|
|
5790
5561
|
const processingPromise = (async () => {
|
|
5791
5562
|
try {
|
|
5792
5563
|
if (message.entityId === runtime.agentId) {
|
|
5793
|
-
|
|
5564
|
+
logger18.debug(`[Bootstrap] Skipping message from self (${runtime.agentId})`);
|
|
5794
5565
|
throw new Error("Message is from the agent itself");
|
|
5795
5566
|
}
|
|
5796
|
-
|
|
5567
|
+
logger18.debug(
|
|
5797
5568
|
`[Bootstrap] Processing message: ${truncateToCompleteSentence(message.content.text || "", 50)}...`
|
|
5798
5569
|
);
|
|
5799
|
-
|
|
5570
|
+
logger18.debug("[Bootstrap] Saving message to memory and embeddings");
|
|
5800
5571
|
await Promise.all([
|
|
5801
5572
|
runtime.addEmbeddingToMemory(message),
|
|
5802
5573
|
runtime.createMemory(message, "messages")
|
|
@@ -5806,7 +5577,7 @@ var messageReceivedHandler = async ({
|
|
|
5806
5577
|
runtime.agentId
|
|
5807
5578
|
);
|
|
5808
5579
|
if (agentUserState === "MUTED" && !message.content.text?.toLowerCase().includes(runtime.character.name.toLowerCase())) {
|
|
5809
|
-
|
|
5580
|
+
logger18.debug(`[Bootstrap] Ignoring muted room ${message.roomId}`);
|
|
5810
5581
|
return;
|
|
5811
5582
|
}
|
|
5812
5583
|
let state = await runtime.composeState(
|
|
@@ -5832,23 +5603,24 @@ var messageReceivedHandler = async ({
|
|
|
5832
5603
|
state,
|
|
5833
5604
|
template: runtime.character.templates?.shouldRespondTemplate || shouldRespondTemplate
|
|
5834
5605
|
});
|
|
5835
|
-
|
|
5606
|
+
logger18.debug(
|
|
5836
5607
|
`[Bootstrap] Evaluating response for ${runtime.character.name}
|
|
5837
5608
|
Prompt: ${shouldRespondPrompt}`
|
|
5838
5609
|
);
|
|
5839
5610
|
const response = await runtime.useModel(ModelType13.TEXT_SMALL, {
|
|
5840
5611
|
prompt: shouldRespondPrompt
|
|
5841
5612
|
});
|
|
5842
|
-
|
|
5613
|
+
logger18.debug(
|
|
5843
5614
|
`[Bootstrap] Response evaluation for ${runtime.character.name}:
|
|
5844
5615
|
${response}`
|
|
5845
5616
|
);
|
|
5846
|
-
|
|
5617
|
+
logger18.debug(`[Bootstrap] Response type: ${typeof response}`);
|
|
5847
5618
|
const responseObject = parseKeyValueXml(response);
|
|
5848
|
-
|
|
5849
|
-
|
|
5619
|
+
logger18.debug("[Bootstrap] Parsed response:", responseObject);
|
|
5620
|
+
const nonResponseActions = ["IGNORE", "NONE"];
|
|
5621
|
+
shouldRespond = responseObject?.action && !nonResponseActions.includes(responseObject.action.toUpperCase());
|
|
5850
5622
|
} else {
|
|
5851
|
-
|
|
5623
|
+
logger18.debug(
|
|
5852
5624
|
`[Bootstrap] Skipping shouldRespond check for ${runtime.character.name} because ${room?.type} ${room?.source}`
|
|
5853
5625
|
);
|
|
5854
5626
|
shouldRespond = true;
|
|
@@ -5859,7 +5631,7 @@ ${response}`
|
|
|
5859
5631
|
if (shouldRespond) {
|
|
5860
5632
|
state = await runtime.composeState(message, ["ACTIONS"]);
|
|
5861
5633
|
if (!state.values.actionNames) {
|
|
5862
|
-
|
|
5634
|
+
logger18.warn("actionNames data missing from state, even though it was requested");
|
|
5863
5635
|
}
|
|
5864
5636
|
const prompt = composePromptFromState9({
|
|
5865
5637
|
state,
|
|
@@ -5872,9 +5644,9 @@ ${response}`
|
|
|
5872
5644
|
let response = await runtime.useModel(ModelType13.TEXT_LARGE, {
|
|
5873
5645
|
prompt
|
|
5874
5646
|
});
|
|
5875
|
-
|
|
5647
|
+
logger18.debug("[Bootstrap] *** Raw LLM Response ***\n", response);
|
|
5876
5648
|
const parsedXml = parseKeyValueXml(response);
|
|
5877
|
-
|
|
5649
|
+
logger18.debug("[Bootstrap] *** Parsed XML Content ***\n", parsedXml);
|
|
5878
5650
|
if (parsedXml) {
|
|
5879
5651
|
responseContent = {
|
|
5880
5652
|
...parsedXml,
|
|
@@ -5889,7 +5661,7 @@ ${response}`
|
|
|
5889
5661
|
}
|
|
5890
5662
|
retries++;
|
|
5891
5663
|
if (!responseContent?.thought || !responseContent?.actions) {
|
|
5892
|
-
|
|
5664
|
+
logger18.warn(
|
|
5893
5665
|
"[Bootstrap] *** Missing required fields (thought or actions), retrying... ***\n",
|
|
5894
5666
|
response,
|
|
5895
5667
|
parsedXml,
|
|
@@ -5899,13 +5671,13 @@ ${response}`
|
|
|
5899
5671
|
}
|
|
5900
5672
|
const currentResponseId = agentResponses.get(message.roomId);
|
|
5901
5673
|
if (currentResponseId !== responseId) {
|
|
5902
|
-
|
|
5674
|
+
logger18.info(
|
|
5903
5675
|
`Response discarded - newer message being processed for agent: ${runtime.agentId}, room: ${message.roomId}`
|
|
5904
5676
|
);
|
|
5905
5677
|
return;
|
|
5906
5678
|
}
|
|
5907
5679
|
if (responseContent && message.id) {
|
|
5908
|
-
responseContent.inReplyTo =
|
|
5680
|
+
responseContent.inReplyTo = createUniqueUuid3(runtime, message.id);
|
|
5909
5681
|
const isSimple = responseContent.actions?.length === 1 && responseContent.actions[0].toUpperCase() === "REPLY" && (!responseContent.providers || responseContent.providers.length === 0);
|
|
5910
5682
|
responseContent.simple = isSimple;
|
|
5911
5683
|
const responseMesssage = {
|
|
@@ -5927,7 +5699,7 @@ ${response}`
|
|
|
5927
5699
|
}
|
|
5928
5700
|
if (responseContent && responseContent.simple && responseContent.text) {
|
|
5929
5701
|
if (responseContent.providers && responseContent.providers.length > 0) {
|
|
5930
|
-
|
|
5702
|
+
logger18.debug("[Bootstrap] Simple response used providers", responseContent.providers);
|
|
5931
5703
|
}
|
|
5932
5704
|
await callback(responseContent);
|
|
5933
5705
|
} else {
|
|
@@ -5942,7 +5714,7 @@ ${response}`
|
|
|
5942
5714
|
if (responseMessages.length) {
|
|
5943
5715
|
for (const responseMessage of responseMessages) {
|
|
5944
5716
|
if (responseMessage.content.providers && responseMessage.content.providers.length > 0) {
|
|
5945
|
-
|
|
5717
|
+
logger18.debug(
|
|
5946
5718
|
"[Bootstrap] Complex response used providers",
|
|
5947
5719
|
responseMessage.content.providers
|
|
5948
5720
|
);
|
|
@@ -5963,16 +5735,16 @@ ${response}`
|
|
|
5963
5735
|
responseMessages
|
|
5964
5736
|
);
|
|
5965
5737
|
} else {
|
|
5966
|
-
|
|
5738
|
+
logger18.debug("[Bootstrap] Agent decided not to respond (shouldRespond is false).");
|
|
5967
5739
|
const currentResponseId = agentResponses.get(message.roomId);
|
|
5968
5740
|
if (currentResponseId !== responseId) {
|
|
5969
|
-
|
|
5741
|
+
logger18.info(
|
|
5970
5742
|
`Ignore response discarded - newer message being processed for agent: ${runtime.agentId}, room: ${message.roomId}`
|
|
5971
5743
|
);
|
|
5972
5744
|
return;
|
|
5973
5745
|
}
|
|
5974
5746
|
if (!message.id) {
|
|
5975
|
-
|
|
5747
|
+
logger18.error("[Bootstrap] Message ID is missing, cannot create ignore response.");
|
|
5976
5748
|
return;
|
|
5977
5749
|
}
|
|
5978
5750
|
const ignoreContent = {
|
|
@@ -5980,7 +5752,7 @@ ${response}`
|
|
|
5980
5752
|
actions: ["IGNORE"],
|
|
5981
5753
|
simple: true,
|
|
5982
5754
|
// Treat it as simple for callback purposes
|
|
5983
|
-
inReplyTo:
|
|
5755
|
+
inReplyTo: createUniqueUuid3(runtime, message.id)
|
|
5984
5756
|
// Reference original message
|
|
5985
5757
|
};
|
|
5986
5758
|
await callback(ignoreContent);
|
|
@@ -5993,7 +5765,7 @@ ${response}`
|
|
|
5993
5765
|
createdAt: Date.now()
|
|
5994
5766
|
};
|
|
5995
5767
|
await runtime.createMemory(ignoreMemory, "messages");
|
|
5996
|
-
|
|
5768
|
+
logger18.debug("[Bootstrap] Saved ignore response to memory", {
|
|
5997
5769
|
memoryId: ignoreMemory.id
|
|
5998
5770
|
});
|
|
5999
5771
|
agentResponses.delete(message.roomId);
|
|
@@ -6001,7 +5773,7 @@ ${response}`
|
|
|
6001
5773
|
latestResponseIds.delete(runtime.agentId);
|
|
6002
5774
|
}
|
|
6003
5775
|
}
|
|
6004
|
-
await runtime.emitEvent(
|
|
5776
|
+
await runtime.emitEvent(EventType.RUN_ENDED, {
|
|
6005
5777
|
runtime,
|
|
6006
5778
|
runId,
|
|
6007
5779
|
messageId: message.id,
|
|
@@ -6015,7 +5787,7 @@ ${response}`
|
|
|
6015
5787
|
});
|
|
6016
5788
|
} catch (error) {
|
|
6017
5789
|
console.error("error is", error);
|
|
6018
|
-
await runtime.emitEvent(
|
|
5790
|
+
await runtime.emitEvent(EventType.RUN_ENDED, {
|
|
6019
5791
|
runtime,
|
|
6020
5792
|
runId,
|
|
6021
5793
|
messageId: message.id,
|
|
@@ -6044,10 +5816,10 @@ var reactionReceivedHandler = async ({
|
|
|
6044
5816
|
await runtime.createMemory(message, "messages");
|
|
6045
5817
|
} catch (error) {
|
|
6046
5818
|
if (error.code === "23505") {
|
|
6047
|
-
|
|
5819
|
+
logger18.warn("[Bootstrap] Duplicate reaction memory, skipping");
|
|
6048
5820
|
return;
|
|
6049
5821
|
}
|
|
6050
|
-
|
|
5822
|
+
logger18.error("[Bootstrap] Error in reaction handler:", error);
|
|
6051
5823
|
}
|
|
6052
5824
|
};
|
|
6053
5825
|
var postGeneratedHandler = async ({
|
|
@@ -6058,7 +5830,7 @@ var postGeneratedHandler = async ({
|
|
|
6058
5830
|
roomId,
|
|
6059
5831
|
source
|
|
6060
5832
|
}) => {
|
|
6061
|
-
|
|
5833
|
+
logger18.info("[Bootstrap] Generating new post...");
|
|
6062
5834
|
await runtime.ensureWorldExists({
|
|
6063
5835
|
id: worldId,
|
|
6064
5836
|
name: `${runtime.character.name}'s Feed`,
|
|
@@ -6069,13 +5841,13 @@ var postGeneratedHandler = async ({
|
|
|
6069
5841
|
id: roomId,
|
|
6070
5842
|
name: `${runtime.character.name}'s Feed`,
|
|
6071
5843
|
source,
|
|
6072
|
-
type:
|
|
5844
|
+
type: ChannelType9.FEED,
|
|
6073
5845
|
channelId: `${userId}-home`,
|
|
6074
5846
|
serverId: userId,
|
|
6075
5847
|
worldId
|
|
6076
5848
|
});
|
|
6077
5849
|
const message = {
|
|
6078
|
-
id:
|
|
5850
|
+
id: createUniqueUuid3(runtime, `tweet-${Date.now()}`),
|
|
6079
5851
|
entityId: runtime.agentId,
|
|
6080
5852
|
agentId: runtime.agentId,
|
|
6081
5853
|
roomId,
|
|
@@ -6122,7 +5894,7 @@ var postGeneratedHandler = async ({
|
|
|
6122
5894
|
}
|
|
6123
5895
|
retries++;
|
|
6124
5896
|
if (!responseContent?.thought || !responseContent?.actions) {
|
|
6125
|
-
|
|
5897
|
+
logger18.warn(
|
|
6126
5898
|
"[Bootstrap] *** Missing required fields, retrying... ***\n",
|
|
6127
5899
|
response,
|
|
6128
5900
|
parsedXml,
|
|
@@ -6140,7 +5912,7 @@ var postGeneratedHandler = async ({
|
|
|
6140
5912
|
});
|
|
6141
5913
|
const parsedXmlResponse = parseKeyValueXml(xmlResponseText);
|
|
6142
5914
|
if (!parsedXmlResponse) {
|
|
6143
|
-
|
|
5915
|
+
logger18.error(
|
|
6144
5916
|
"[Bootstrap] Failed to parse XML response for post creation. Raw response:",
|
|
6145
5917
|
xmlResponseText
|
|
6146
5918
|
);
|
|
@@ -6160,7 +5932,7 @@ var postGeneratedHandler = async ({
|
|
|
6160
5932
|
if (RM) {
|
|
6161
5933
|
for (const m of RM.data.recentMessages) {
|
|
6162
5934
|
if (cleanedText === m.content.text) {
|
|
6163
|
-
|
|
5935
|
+
logger18.log("[Bootstrap] Already recently posted that, retrying", cleanedText);
|
|
6164
5936
|
postGeneratedHandler({
|
|
6165
5937
|
runtime,
|
|
6166
5938
|
callback,
|
|
@@ -6178,7 +5950,7 @@ var postGeneratedHandler = async ({
|
|
|
6178
5950
|
const googleRefusalRegex = /(i\s+can'?t\s+help\s+with\s+that|that\s+goes\s+against\s+(our\s+)?(policy|policies)|i'?m\s+still\s+learning|response\s+must\s+follow\s+(usage|safety)\s+policies|i'?ve\s+been\s+designed\s+to\s+avoid\s+that)/i;
|
|
6179
5951
|
const generalRefusalRegex = /(response\s+was\s+withheld|content\s+was\s+filtered|this\s+request\s+cannot\s+be\s+completed|violates\s+our\s+safety\s+policy|content\s+is\s+not\s+available)/i;
|
|
6180
5952
|
if (oaiRefusalRegex.test(cleanedText) || anthropicRefusalRegex.test(cleanedText) || googleRefusalRegex.test(cleanedText) || generalRefusalRegex.test(cleanedText)) {
|
|
6181
|
-
|
|
5953
|
+
logger18.log("[Bootstrap] Got prompt moderation refusal, retrying", cleanedText);
|
|
6182
5954
|
postGeneratedHandler({
|
|
6183
5955
|
runtime,
|
|
6184
5956
|
callback,
|
|
@@ -6197,7 +5969,7 @@ var postGeneratedHandler = async ({
|
|
|
6197
5969
|
content: {
|
|
6198
5970
|
text: cleanedText,
|
|
6199
5971
|
source,
|
|
6200
|
-
channelType:
|
|
5972
|
+
channelType: ChannelType9.FEED,
|
|
6201
5973
|
thought: parsedXmlResponse.thought || "",
|
|
6202
5974
|
type: "post"
|
|
6203
5975
|
},
|
|
@@ -6212,13 +5984,13 @@ var postGeneratedHandler = async ({
|
|
|
6212
5984
|
var syncSingleUser = async (entityId, runtime, serverId, channelId, type, source) => {
|
|
6213
5985
|
try {
|
|
6214
5986
|
const entity = await runtime.getEntityById(entityId);
|
|
6215
|
-
|
|
5987
|
+
logger18.info(`[Bootstrap] Syncing user: ${entity?.metadata?.[source]?.username || entityId}`);
|
|
6216
5988
|
if (!channelId) {
|
|
6217
|
-
|
|
5989
|
+
logger18.warn(`[Bootstrap] Cannot sync user ${entity?.id} without a valid channelId`);
|
|
6218
5990
|
return;
|
|
6219
5991
|
}
|
|
6220
|
-
const roomId =
|
|
6221
|
-
const worldId =
|
|
5992
|
+
const roomId = createUniqueUuid3(runtime, channelId);
|
|
5993
|
+
const worldId = createUniqueUuid3(runtime, serverId);
|
|
6222
5994
|
await runtime.ensureConnection({
|
|
6223
5995
|
entityId,
|
|
6224
5996
|
roomId,
|
|
@@ -6230,9 +6002,9 @@ var syncSingleUser = async (entityId, runtime, serverId, channelId, type, source
|
|
|
6230
6002
|
type,
|
|
6231
6003
|
worldId
|
|
6232
6004
|
});
|
|
6233
|
-
|
|
6005
|
+
logger18.success(`[Bootstrap] Successfully synced user: ${entity?.id}`);
|
|
6234
6006
|
} catch (error) {
|
|
6235
|
-
|
|
6007
|
+
logger18.error(
|
|
6236
6008
|
`[Bootstrap] Error syncing user: ${error instanceof Error ? error.message : String(error)}`
|
|
6237
6009
|
);
|
|
6238
6010
|
}
|
|
@@ -6245,71 +6017,13 @@ var handleServerSync = async ({
|
|
|
6245
6017
|
source,
|
|
6246
6018
|
onComplete
|
|
6247
6019
|
}) => {
|
|
6248
|
-
|
|
6020
|
+
logger18.debug(`[Bootstrap] Handling server sync event for server: ${world.name}`);
|
|
6249
6021
|
try {
|
|
6250
|
-
await runtime.
|
|
6251
|
-
|
|
6252
|
-
name: world.name,
|
|
6253
|
-
agentId: runtime.agentId,
|
|
6254
|
-
serverId: world.serverId,
|
|
6255
|
-
metadata: {
|
|
6256
|
-
...world.metadata
|
|
6257
|
-
}
|
|
6258
|
-
});
|
|
6259
|
-
if (rooms && rooms.length > 0) {
|
|
6260
|
-
for (const room of rooms) {
|
|
6261
|
-
await runtime.ensureRoomExists({
|
|
6262
|
-
id: room.id,
|
|
6263
|
-
name: room.name,
|
|
6264
|
-
source,
|
|
6265
|
-
type: room.type,
|
|
6266
|
-
channelId: room.channelId,
|
|
6267
|
-
serverId: world.serverId,
|
|
6268
|
-
worldId: world.id
|
|
6269
|
-
});
|
|
6270
|
-
}
|
|
6271
|
-
}
|
|
6272
|
-
if (entities && entities.length > 0) {
|
|
6273
|
-
const batchSize = 50;
|
|
6274
|
-
for (let i2 = 0; i2 < entities.length; i2 += batchSize) {
|
|
6275
|
-
const entityBatch = entities.slice(i2, i2 + batchSize);
|
|
6276
|
-
const firstRoomUserIsIn = rooms.length > 0 ? rooms[0] : null;
|
|
6277
|
-
if (!firstRoomUserIsIn) {
|
|
6278
|
-
logger19.warn(`[Bootstrap] No rooms found for syncing users`);
|
|
6279
|
-
continue;
|
|
6280
|
-
}
|
|
6281
|
-
await Promise.all(
|
|
6282
|
-
entityBatch.map(async (entity) => {
|
|
6283
|
-
try {
|
|
6284
|
-
if (!entity?.id) {
|
|
6285
|
-
logger19.warn(`[Bootstrap] No entity ID found for syncing users`);
|
|
6286
|
-
return;
|
|
6287
|
-
}
|
|
6288
|
-
await runtime.ensureConnection({
|
|
6289
|
-
entityId: entity.id,
|
|
6290
|
-
roomId: firstRoomUserIsIn.id,
|
|
6291
|
-
userName: entity.metadata?.[source].username,
|
|
6292
|
-
name: entity.metadata?.[source].name,
|
|
6293
|
-
source,
|
|
6294
|
-
channelId: firstRoomUserIsIn.channelId,
|
|
6295
|
-
serverId: world.serverId,
|
|
6296
|
-
type: firstRoomUserIsIn.type,
|
|
6297
|
-
worldId: world.id
|
|
6298
|
-
});
|
|
6299
|
-
} catch (err) {
|
|
6300
|
-
logger19.warn(`[Bootstrap] Failed to sync user ${entity.metadata?.username}: ${err}`);
|
|
6301
|
-
}
|
|
6302
|
-
})
|
|
6303
|
-
);
|
|
6304
|
-
if (i2 + batchSize < entities.length) {
|
|
6305
|
-
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
6306
|
-
}
|
|
6307
|
-
}
|
|
6308
|
-
}
|
|
6309
|
-
logger19.debug(`Successfully synced standardized world structure for ${world.name}`);
|
|
6022
|
+
await runtime.ensureConnections(entities, rooms, source, world);
|
|
6023
|
+
logger18.debug(`Successfully synced standardized world structure for ${world.name}`);
|
|
6310
6024
|
onComplete?.();
|
|
6311
6025
|
} catch (error) {
|
|
6312
|
-
|
|
6026
|
+
logger18.error(
|
|
6313
6027
|
`Error processing standardized server data: ${error instanceof Error ? error.message : String(error)}`
|
|
6314
6028
|
);
|
|
6315
6029
|
}
|
|
@@ -6320,7 +6034,7 @@ var controlMessageHandler = async ({
|
|
|
6320
6034
|
source
|
|
6321
6035
|
}) => {
|
|
6322
6036
|
try {
|
|
6323
|
-
|
|
6037
|
+
logger18.debug(
|
|
6324
6038
|
`[controlMessageHandler] Processing control message: ${message.payload.action} for room ${message.roomId}`
|
|
6325
6039
|
);
|
|
6326
6040
|
const serviceNames = Array.from(runtime.getAllServices().keys());
|
|
@@ -6338,24 +6052,24 @@ var controlMessageHandler = async ({
|
|
|
6338
6052
|
roomId: message.roomId
|
|
6339
6053
|
}
|
|
6340
6054
|
});
|
|
6341
|
-
|
|
6055
|
+
logger18.debug(
|
|
6342
6056
|
`[controlMessageHandler] Control message ${message.payload.action} sent successfully`
|
|
6343
6057
|
);
|
|
6344
6058
|
} else {
|
|
6345
|
-
|
|
6059
|
+
logger18.error("[controlMessageHandler] WebSocket service does not have sendMessage method");
|
|
6346
6060
|
}
|
|
6347
6061
|
} else {
|
|
6348
|
-
|
|
6062
|
+
logger18.error("[controlMessageHandler] No WebSocket service found to send control message");
|
|
6349
6063
|
}
|
|
6350
6064
|
} catch (error) {
|
|
6351
|
-
|
|
6065
|
+
logger18.error(`[controlMessageHandler] Error processing control message: ${error}`);
|
|
6352
6066
|
}
|
|
6353
6067
|
};
|
|
6354
6068
|
var events = {
|
|
6355
|
-
[
|
|
6069
|
+
[EventType.MESSAGE_RECEIVED]: [
|
|
6356
6070
|
async (payload) => {
|
|
6357
6071
|
if (!payload.callback) {
|
|
6358
|
-
|
|
6072
|
+
logger18.error("No callback provided for message");
|
|
6359
6073
|
return;
|
|
6360
6074
|
}
|
|
6361
6075
|
await messageReceivedHandler({
|
|
@@ -6366,10 +6080,10 @@ var events = {
|
|
|
6366
6080
|
});
|
|
6367
6081
|
}
|
|
6368
6082
|
],
|
|
6369
|
-
[
|
|
6083
|
+
[EventType.VOICE_MESSAGE_RECEIVED]: [
|
|
6370
6084
|
async (payload) => {
|
|
6371
6085
|
if (!payload.callback) {
|
|
6372
|
-
|
|
6086
|
+
logger18.error("No callback provided for voice message");
|
|
6373
6087
|
return;
|
|
6374
6088
|
}
|
|
6375
6089
|
await messageReceivedHandler({
|
|
@@ -6380,7 +6094,7 @@ var events = {
|
|
|
6380
6094
|
});
|
|
6381
6095
|
}
|
|
6382
6096
|
],
|
|
6383
|
-
[
|
|
6097
|
+
[EventType.REACTION_RECEIVED]: [
|
|
6384
6098
|
async (payload) => {
|
|
6385
6099
|
await reactionReceivedHandler({
|
|
6386
6100
|
runtime: payload.runtime,
|
|
@@ -6388,38 +6102,38 @@ var events = {
|
|
|
6388
6102
|
});
|
|
6389
6103
|
}
|
|
6390
6104
|
],
|
|
6391
|
-
[
|
|
6105
|
+
[EventType.POST_GENERATED]: [
|
|
6392
6106
|
async (payload) => {
|
|
6393
6107
|
await postGeneratedHandler(payload);
|
|
6394
6108
|
}
|
|
6395
6109
|
],
|
|
6396
|
-
[
|
|
6110
|
+
[EventType.MESSAGE_SENT]: [
|
|
6397
6111
|
async (payload) => {
|
|
6398
|
-
|
|
6112
|
+
logger18.debug(`[Bootstrap] Message sent: ${payload.message.content.text}`);
|
|
6399
6113
|
}
|
|
6400
6114
|
],
|
|
6401
|
-
[
|
|
6115
|
+
[EventType.WORLD_JOINED]: [
|
|
6402
6116
|
async (payload) => {
|
|
6403
6117
|
await handleServerSync(payload);
|
|
6404
6118
|
}
|
|
6405
6119
|
],
|
|
6406
|
-
[
|
|
6120
|
+
[EventType.WORLD_CONNECTED]: [
|
|
6407
6121
|
async (payload) => {
|
|
6408
6122
|
await handleServerSync(payload);
|
|
6409
6123
|
}
|
|
6410
6124
|
],
|
|
6411
|
-
[
|
|
6125
|
+
[EventType.ENTITY_JOINED]: [
|
|
6412
6126
|
async (payload) => {
|
|
6413
6127
|
if (!payload.worldId) {
|
|
6414
|
-
|
|
6128
|
+
logger18.error("[Bootstrap] No callback provided for entity joined");
|
|
6415
6129
|
return;
|
|
6416
6130
|
}
|
|
6417
6131
|
if (!payload.roomId) {
|
|
6418
|
-
|
|
6132
|
+
logger18.error("[Bootstrap] No roomId provided for entity joined");
|
|
6419
6133
|
return;
|
|
6420
6134
|
}
|
|
6421
6135
|
if (!payload.metadata?.type) {
|
|
6422
|
-
|
|
6136
|
+
logger18.error("[Bootstrap] No type provided for entity joined");
|
|
6423
6137
|
return;
|
|
6424
6138
|
}
|
|
6425
6139
|
await syncSingleUser(
|
|
@@ -6432,7 +6146,7 @@ var events = {
|
|
|
6432
6146
|
);
|
|
6433
6147
|
}
|
|
6434
6148
|
],
|
|
6435
|
-
[
|
|
6149
|
+
[EventType.ENTITY_LEFT]: [
|
|
6436
6150
|
async (payload) => {
|
|
6437
6151
|
try {
|
|
6438
6152
|
const entity = await payload.runtime.getEntityById(payload.entityId);
|
|
@@ -6444,34 +6158,34 @@ var events = {
|
|
|
6444
6158
|
};
|
|
6445
6159
|
await payload.runtime.updateEntity(entity);
|
|
6446
6160
|
}
|
|
6447
|
-
|
|
6161
|
+
logger18.info(`[Bootstrap] User ${payload.entityId} left world ${payload.worldId}`);
|
|
6448
6162
|
} catch (error) {
|
|
6449
|
-
|
|
6163
|
+
logger18.error(`[Bootstrap] Error handling user left: ${error.message}`);
|
|
6450
6164
|
}
|
|
6451
6165
|
}
|
|
6452
6166
|
],
|
|
6453
|
-
[
|
|
6167
|
+
[EventType.ACTION_STARTED]: [
|
|
6454
6168
|
async (payload) => {
|
|
6455
|
-
|
|
6169
|
+
logger18.debug(`[Bootstrap] Action started: ${payload.actionName} (${payload.actionId})`);
|
|
6456
6170
|
}
|
|
6457
6171
|
],
|
|
6458
|
-
[
|
|
6172
|
+
[EventType.ACTION_COMPLETED]: [
|
|
6459
6173
|
async (payload) => {
|
|
6460
6174
|
const status = payload.error ? `failed: ${payload.error.message}` : "completed";
|
|
6461
|
-
|
|
6175
|
+
logger18.debug(`[Bootstrap] Action ${status}: ${payload.actionName} (${payload.actionId})`);
|
|
6462
6176
|
}
|
|
6463
6177
|
],
|
|
6464
|
-
[
|
|
6178
|
+
[EventType.EVALUATOR_STARTED]: [
|
|
6465
6179
|
async (payload) => {
|
|
6466
|
-
|
|
6180
|
+
logger18.debug(
|
|
6467
6181
|
`[Bootstrap] Evaluator started: ${payload.evaluatorName} (${payload.evaluatorId})`
|
|
6468
6182
|
);
|
|
6469
6183
|
}
|
|
6470
6184
|
],
|
|
6471
|
-
[
|
|
6185
|
+
[EventType.EVALUATOR_COMPLETED]: [
|
|
6472
6186
|
async (payload) => {
|
|
6473
6187
|
const status = payload.error ? `failed: ${payload.error.message}` : "completed";
|
|
6474
|
-
|
|
6188
|
+
logger18.debug(
|
|
6475
6189
|
`[Bootstrap] Evaluator ${status}: ${payload.evaluatorName} (${payload.evaluatorId})`
|
|
6476
6190
|
);
|
|
6477
6191
|
}
|
|
@@ -6516,7 +6230,7 @@ var bootstrapPlugin = {
|
|
|
6516
6230
|
recentMessagesProvider,
|
|
6517
6231
|
worldProvider
|
|
6518
6232
|
],
|
|
6519
|
-
services: [TaskService
|
|
6233
|
+
services: [TaskService]
|
|
6520
6234
|
};
|
|
6521
6235
|
var index_default = bootstrapPlugin;
|
|
6522
6236
|
export {
|