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