@elizaos/plugin-bootstrap 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -83,6 +83,7 @@ import {
83
83
  ModelType as ModelType14,
84
84
  parseKeyValueXml as parseKeyValueXml9,
85
85
  postCreationTemplate,
86
+ parseBooleanFromText as parseBooleanFromText2,
86
87
  Role as Role2,
87
88
  shouldRespondTemplate,
88
89
  truncateToCompleteSentence,
@@ -6913,7 +6914,7 @@ async function processAttachments(attachments, runtime) {
6913
6914
  if (!attachments || attachments.length === 0) {
6914
6915
  return [];
6915
6916
  }
6916
- logger20.debug(`[Bootstrap] Processing ${attachments.length} attachment(s)`);
6917
+ runtime.logger.debug(`[Bootstrap] Processing ${attachments.length} attachment(s)`);
6917
6918
  const processedAttachments = [];
6918
6919
  for (const attachment of attachments) {
6919
6920
  try {
@@ -6921,7 +6922,7 @@ async function processAttachments(attachments, runtime) {
6921
6922
  const isRemote = /^(http|https):\/\//.test(attachment.url);
6922
6923
  const url = isRemote ? attachment.url : getLocalServerUrl(attachment.url);
6923
6924
  if (attachment.contentType === ContentType2.IMAGE && !attachment.description) {
6924
- logger20.debug(`[Bootstrap] Generating description for image: ${attachment.url}`);
6925
+ runtime.logger.debug(`[Bootstrap] Generating description for image: ${attachment.url}`);
6925
6926
  let imageUrl = url;
6926
6927
  if (!isRemote) {
6927
6928
  const res = await fetch(url);
@@ -6942,24 +6943,24 @@ async function processAttachments(attachments, runtime) {
6942
6943
  processedAttachment.description = parsedXml.description;
6943
6944
  processedAttachment.title = parsedXml.title || "Image";
6944
6945
  processedAttachment.text = parsedXml.text;
6945
- logger20.debug(
6946
+ runtime.logger.debug(
6946
6947
  `[Bootstrap] Generated description: ${processedAttachment.description?.substring(0, 100)}...`
6947
6948
  );
6948
6949
  } else {
6949
- logger20.warn(`[Bootstrap] Failed to parse XML response for image description`);
6950
+ runtime.logger.warn(`[Bootstrap] Failed to parse XML response for image description`);
6950
6951
  }
6951
6952
  } else if (response && typeof response === "object" && "description" in response) {
6952
6953
  processedAttachment.description = response.description;
6953
6954
  processedAttachment.title = response.title || "Image";
6954
6955
  processedAttachment.text = response.description;
6955
- logger20.debug(
6956
+ runtime.logger.debug(
6956
6957
  `[Bootstrap] Generated description: ${processedAttachment.description?.substring(0, 100)}...`
6957
6958
  );
6958
6959
  } else {
6959
- logger20.warn(`[Bootstrap] Unexpected response format for image description`);
6960
+ runtime.logger.warn(`[Bootstrap] Unexpected response format for image description`);
6960
6961
  }
6961
6962
  } catch (error) {
6962
- logger20.error(`[Bootstrap] Error generating image description:`, error);
6963
+ runtime.logger.error(`[Bootstrap] Error generating image description:`, error);
6963
6964
  }
6964
6965
  } else if (attachment.contentType === ContentType2.DOCUMENT && !attachment.text) {
6965
6966
  const res = await fetch(url);
@@ -6967,20 +6968,20 @@ async function processAttachments(attachments, runtime) {
6967
6968
  const contentType = res.headers.get("content-type") || "";
6968
6969
  const isPlainText = contentType.startsWith("text/plain");
6969
6970
  if (isPlainText) {
6970
- logger20.debug(`[Bootstrap] Processing plain text document: ${attachment.url}`);
6971
+ runtime.logger.debug(`[Bootstrap] Processing plain text document: ${attachment.url}`);
6971
6972
  const textContent = await res.text();
6972
6973
  processedAttachment.text = textContent;
6973
6974
  processedAttachment.title = processedAttachment.title || "Text File";
6974
- logger20.debug(
6975
+ runtime.logger.debug(
6975
6976
  `[Bootstrap] Extracted text content (first 100 chars): ${processedAttachment.text?.substring(0, 100)}...`
6976
6977
  );
6977
6978
  } else {
6978
- logger20.warn(`[Bootstrap] Skipping non-plain-text document: ${contentType}`);
6979
+ runtime.logger.warn(`[Bootstrap] Skipping non-plain-text document: ${contentType}`);
6979
6980
  }
6980
6981
  }
6981
6982
  processedAttachments.push(processedAttachment);
6982
6983
  } catch (error) {
6983
- logger20.error(`[Bootstrap] Failed to process attachment ${attachment.url}:`, error);
6984
+ runtime.logger.error(`[Bootstrap] Failed to process attachment ${attachment.url}:`, error);
6984
6985
  processedAttachments.push(attachment);
6985
6986
  }
6986
6987
  }
@@ -7025,7 +7026,9 @@ var messageReceivedHandler = async ({
7025
7026
  const timeoutDuration = 60 * 60 * 1e3;
7026
7027
  let timeoutId = void 0;
7027
7028
  try {
7028
- logger20.info(`[Bootstrap] Message received from ${message.entityId} in room ${message.roomId}`);
7029
+ runtime.logger.info(
7030
+ `[Bootstrap] Message received from ${message.entityId} in room ${message.roomId}`
7031
+ );
7029
7032
  const responseId = v4_default();
7030
7033
  if (!latestResponseIds.has(runtime.agentId)) {
7031
7034
  latestResponseIds.set(runtime.agentId, /* @__PURE__ */ new Map());
@@ -7034,6 +7037,12 @@ var messageReceivedHandler = async ({
7034
7037
  if (!agentResponses) {
7035
7038
  throw new Error("Agent responses map not found");
7036
7039
  }
7040
+ const previousResponseId = agentResponses.get(message.roomId);
7041
+ if (previousResponseId) {
7042
+ logger20.warn(
7043
+ `[Bootstrap] Updating response ID for room ${message.roomId} from ${previousResponseId} to ${responseId} - this may discard in-progress responses`
7044
+ );
7045
+ }
7037
7046
  agentResponses.set(message.roomId, responseId);
7038
7047
  const runId = runtime.startRun();
7039
7048
  const startTime = Date.now();
@@ -7045,7 +7054,10 @@ var messageReceivedHandler = async ({
7045
7054
  entityId: message.entityId,
7046
7055
  startTime,
7047
7056
  status: "started",
7048
- source: "messageHandler"
7057
+ source: "messageHandler",
7058
+ // this shouldn't be a standard
7059
+ // but we need to expose content somewhere
7060
+ metadata: message.content
7049
7061
  });
7050
7062
  const timeoutPromise = new Promise((_, reject) => {
7051
7063
  timeoutId = setTimeout(async () => {
@@ -7068,23 +7080,65 @@ var messageReceivedHandler = async ({
7068
7080
  const processingPromise = (async () => {
7069
7081
  try {
7070
7082
  if (message.entityId === runtime.agentId) {
7071
- logger20.debug(`[Bootstrap] Skipping message from self (${runtime.agentId})`);
7083
+ runtime.logger.debug(`[Bootstrap] Skipping message from self (${runtime.agentId})`);
7072
7084
  throw new Error("Message is from the agent itself");
7073
7085
  }
7074
- logger20.debug(
7086
+ runtime.logger.debug(
7075
7087
  `[Bootstrap] Processing message: ${truncateToCompleteSentence(message.content.text || "", 50)}...`
7076
7088
  );
7077
- logger20.debug("[Bootstrap] Saving message to memory and embeddings");
7078
- await Promise.all([
7079
- runtime.addEmbeddingToMemory(message),
7080
- runtime.createMemory(message, "messages")
7081
- ]);
7089
+ runtime.logger.debug("[Bootstrap] Saving message to memory and embeddings");
7090
+ if (message.id) {
7091
+ const existingMemory = await runtime.getMemoryById(message.id);
7092
+ if (existingMemory) {
7093
+ runtime.logger.debug("[Bootstrap] Memory already exists, skipping creation");
7094
+ await runtime.addEmbeddingToMemory(message);
7095
+ } else {
7096
+ await Promise.all([
7097
+ runtime.addEmbeddingToMemory(message),
7098
+ runtime.createMemory(message, "messages")
7099
+ ]);
7100
+ }
7101
+ } else {
7102
+ await Promise.all([
7103
+ runtime.addEmbeddingToMemory(message),
7104
+ runtime.createMemory(message, "messages")
7105
+ ]);
7106
+ }
7082
7107
  const agentUserState = await runtime.getParticipantUserState(
7083
7108
  message.roomId,
7084
7109
  runtime.agentId
7085
7110
  );
7111
+ const defLllmOff = parseBooleanFromText2(runtime.getSetting("BOOTSTRAP_DEFLLMOFF"));
7112
+ if (defLllmOff && agentUserState === null) {
7113
+ runtime.logger.debug("bootstrap - LLM is off by default");
7114
+ await runtime.emitEvent(EventType.RUN_ENDED, {
7115
+ runtime,
7116
+ runId,
7117
+ messageId: message.id,
7118
+ roomId: message.roomId,
7119
+ entityId: message.entityId,
7120
+ startTime,
7121
+ status: "off",
7122
+ endTime: Date.now(),
7123
+ duration: Date.now() - startTime,
7124
+ source: "messageHandler"
7125
+ });
7126
+ return;
7127
+ }
7086
7128
  if (agentUserState === "MUTED" && !message.content.text?.toLowerCase().includes(runtime.character.name.toLowerCase())) {
7087
- logger20.debug(`[Bootstrap] Ignoring muted room ${message.roomId}`);
7129
+ runtime.logger.debug(`[Bootstrap] Ignoring muted room ${message.roomId}`);
7130
+ await runtime.emitEvent(EventType.RUN_ENDED, {
7131
+ runtime,
7132
+ runId,
7133
+ messageId: message.id,
7134
+ roomId: message.roomId,
7135
+ entityId: message.entityId,
7136
+ startTime,
7137
+ status: "muted",
7138
+ endTime: Date.now(),
7139
+ duration: Date.now() - startTime,
7140
+ source: "messageHandler"
7141
+ });
7088
7142
  return;
7089
7143
  }
7090
7144
  let state = await runtime.composeState(
@@ -7116,50 +7170,50 @@ var messageReceivedHandler = async ({
7116
7170
  state,
7117
7171
  template: runtime.character.templates?.shouldRespondTemplate || shouldRespondTemplate
7118
7172
  });
7119
- logger20.debug(
7173
+ runtime.logger.debug(
7120
7174
  `[Bootstrap] Evaluating response for ${runtime.character.name}
7121
7175
  Prompt: ${shouldRespondPrompt}`
7122
7176
  );
7123
7177
  const response = await runtime.useModel(ModelType14.TEXT_SMALL, {
7124
7178
  prompt: shouldRespondPrompt
7125
7179
  });
7126
- logger20.debug(
7180
+ runtime.logger.debug(
7127
7181
  `[Bootstrap] Response evaluation for ${runtime.character.name}:
7128
7182
  ${response}`
7129
7183
  );
7130
- logger20.debug(`[Bootstrap] Response type: ${typeof response}`);
7184
+ runtime.logger.debug(`[Bootstrap] Response type: ${typeof response}`);
7131
7185
  const responseObject = parseKeyValueXml9(response);
7132
- logger20.debug("[Bootstrap] Parsed response:", responseObject);
7186
+ runtime.logger.debug("[Bootstrap] Parsed response:", responseObject);
7133
7187
  const nonResponseActions = ["IGNORE", "NONE"];
7134
7188
  shouldRespond = responseObject?.action && !nonResponseActions.includes(responseObject.action.toUpperCase());
7135
7189
  } else {
7136
- logger20.debug(
7190
+ runtime.logger.debug(
7137
7191
  `[Bootstrap] Skipping shouldRespond check for ${runtime.character.name} because ${room?.type} ${room?.source}`
7138
7192
  );
7139
7193
  shouldRespond = true;
7140
7194
  }
7141
7195
  let responseMessages = [];
7142
- console.log("shouldRespond is", shouldRespond);
7143
- console.log("shouldSkipShouldRespond", shouldSkipShouldRespond);
7196
+ let responseContent = null;
7144
7197
  if (shouldRespond) {
7145
7198
  state = await runtime.composeState(message, ["ACTIONS"]);
7146
7199
  if (!state.values.actionNames) {
7147
- logger20.warn("actionNames data missing from state, even though it was requested");
7200
+ runtime.logger.warn(
7201
+ "actionNames data missing from state, even though it was requested"
7202
+ );
7148
7203
  }
7149
7204
  const prompt = composePromptFromState10({
7150
7205
  state,
7151
7206
  template: runtime.character.templates?.messageHandlerTemplate || messageHandlerTemplate
7152
7207
  });
7153
- let responseContent = null;
7154
7208
  let retries = 0;
7155
7209
  const maxRetries = 3;
7156
7210
  while (retries < maxRetries && (!responseContent?.thought || !responseContent?.actions)) {
7157
7211
  let response = await runtime.useModel(ModelType14.TEXT_LARGE, {
7158
7212
  prompt
7159
7213
  });
7160
- logger20.debug("[Bootstrap] *** Raw LLM Response ***\n", response);
7214
+ runtime.logger.debug("[Bootstrap] *** Raw LLM Response ***\n", response);
7161
7215
  const parsedXml = parseKeyValueXml9(response);
7162
- logger20.debug("[Bootstrap] *** Parsed XML Content ***\n", parsedXml);
7216
+ runtime.logger.debug("[Bootstrap] *** Parsed XML Content ***\n", parsedXml);
7163
7217
  if (parsedXml) {
7164
7218
  responseContent = {
7165
7219
  ...parsedXml,
@@ -7174,7 +7228,7 @@ ${response}`
7174
7228
  }
7175
7229
  retries++;
7176
7230
  if (!responseContent?.thought || !responseContent?.actions) {
7177
- logger20.warn(
7231
+ runtime.logger.warn(
7178
7232
  "[Bootstrap] *** Missing required fields (thought or actions), retrying... ***\n",
7179
7233
  response,
7180
7234
  parsedXml,
@@ -7184,7 +7238,7 @@ ${response}`
7184
7238
  }
7185
7239
  const currentResponseId = agentResponses.get(message.roomId);
7186
7240
  if (currentResponseId !== responseId) {
7187
- logger20.info(
7241
+ runtime.logger.info(
7188
7242
  `Response discarded - newer message being processed for agent: ${runtime.agentId}, room: ${message.roomId}`
7189
7243
  );
7190
7244
  return;
@@ -7232,24 +7286,74 @@ ${response}`
7232
7286
  }
7233
7287
  if (responseContent && responseContent.simple && responseContent.text) {
7234
7288
  if (responseContent.providers && responseContent.providers.length > 0) {
7235
- logger20.debug("[Bootstrap] Simple response used providers", responseContent.providers);
7289
+ runtime.logger.debug(
7290
+ "[Bootstrap] Simple response used providers",
7291
+ responseContent.providers
7292
+ );
7236
7293
  }
7237
7294
  await callback(responseContent);
7238
7295
  } else {
7239
- await runtime.processActions(message, responseMessages, state, callback);
7296
+ await runtime.processActions(message, responseMessages, state, async (content) => {
7297
+ runtime.logger.debug("action callback", content);
7298
+ if (responseContent) {
7299
+ responseContent.actionCallbacks = content;
7300
+ }
7301
+ return callback(content);
7302
+ });
7240
7303
  }
7241
- await runtime.evaluate(message, state, shouldRespond, callback, responseMessages);
7304
+ await runtime.evaluate(
7305
+ message,
7306
+ state,
7307
+ shouldRespond,
7308
+ async (content) => {
7309
+ runtime.logger.debug("evaluate callback", content);
7310
+ if (responseContent) {
7311
+ responseContent.evalCallbacks = content;
7312
+ }
7313
+ return callback(content);
7314
+ },
7315
+ responseMessages
7316
+ );
7242
7317
  } else {
7243
- logger20.debug("[Bootstrap] Agent decided not to respond (shouldRespond is false).");
7318
+ runtime.logger.debug(
7319
+ "[Bootstrap] Agent decided not to respond (shouldRespond is false)."
7320
+ );
7244
7321
  const currentResponseId = agentResponses.get(message.roomId);
7245
- if (currentResponseId !== responseId) {
7246
- logger20.info(
7322
+ const keepResp = parseBooleanFromText2(runtime.getSetting("BOOTSTRAP_KEEP_RESP"));
7323
+ if (currentResponseId !== responseId && !keepResp) {
7324
+ runtime.logger.info(
7247
7325
  `Ignore response discarded - newer message being processed for agent: ${runtime.agentId}, room: ${message.roomId}`
7248
7326
  );
7327
+ await runtime.emitEvent(EventType.RUN_ENDED, {
7328
+ runtime,
7329
+ runId,
7330
+ messageId: message.id,
7331
+ roomId: message.roomId,
7332
+ entityId: message.entityId,
7333
+ startTime,
7334
+ status: "replaced",
7335
+ endTime: Date.now(),
7336
+ duration: Date.now() - startTime,
7337
+ source: "messageHandler"
7338
+ });
7249
7339
  return;
7250
7340
  }
7251
7341
  if (!message.id) {
7252
- logger20.error("[Bootstrap] Message ID is missing, cannot create ignore response.");
7342
+ runtime.logger.error(
7343
+ "[Bootstrap] Message ID is missing, cannot create ignore response."
7344
+ );
7345
+ await runtime.emitEvent(EventType.RUN_ENDED, {
7346
+ runtime,
7347
+ runId,
7348
+ messageId: message.id,
7349
+ roomId: message.roomId,
7350
+ entityId: message.entityId,
7351
+ startTime,
7352
+ status: "noMessageId",
7353
+ endTime: Date.now(),
7354
+ duration: Date.now() - startTime,
7355
+ source: "messageHandler"
7356
+ });
7253
7357
  return;
7254
7358
  }
7255
7359
  const ignoreContent = {
@@ -7270,7 +7374,7 @@ ${response}`
7270
7374
  createdAt: Date.now()
7271
7375
  };
7272
7376
  await runtime.createMemory(ignoreMemory, "messages");
7273
- logger20.debug("[Bootstrap] Saved ignore response to memory", {
7377
+ runtime.logger.debug("[Bootstrap] Saved ignore response to memory", {
7274
7378
  memoryId: ignoreMemory.id
7275
7379
  });
7276
7380
  agentResponses.delete(message.roomId);
@@ -7278,6 +7382,51 @@ ${response}`
7278
7382
  latestResponseIds.delete(runtime.agentId);
7279
7383
  }
7280
7384
  }
7385
+ let entityName = "noname";
7386
+ if (message.metadata && "entityName" in message.metadata) {
7387
+ entityName = message.metadata.entityName;
7388
+ }
7389
+ const isDM = message.content?.channelType?.toUpperCase() === "DM";
7390
+ let roomName = entityName;
7391
+ if (!isDM) {
7392
+ const roomDatas = await runtime.getRoomsByIds([message.roomId]);
7393
+ if (roomDatas?.length) {
7394
+ const roomData = roomDatas[0];
7395
+ if (roomData.name) {
7396
+ roomName = roomData.name;
7397
+ }
7398
+ if (roomData.worldId) {
7399
+ const worldData = await runtime.getWorld(roomData.worldId);
7400
+ if (worldData) {
7401
+ roomName = worldData.name + "-" + roomName;
7402
+ }
7403
+ }
7404
+ }
7405
+ }
7406
+ const date = /* @__PURE__ */ new Date();
7407
+ const availableActions = state.data?.providers?.ACTIONS?.data?.actionsData?.map(
7408
+ (a2) => a2.name
7409
+ ) || [-1];
7410
+ const logData = {
7411
+ at: date.toString(),
7412
+ timestamp: parseInt("" + date.getTime() / 1e3),
7413
+ messageId: message.id,
7414
+ // can extract roomId or whatever
7415
+ userEntityId: message.entityId,
7416
+ input: message.content.text,
7417
+ thought: responseContent?.thought,
7418
+ simple: responseContent?.simple,
7419
+ availableActions,
7420
+ actions: responseContent?.actions,
7421
+ providers: responseContent?.providers,
7422
+ irt: responseContent?.inReplyTo,
7423
+ output: responseContent?.text,
7424
+ // to strip out
7425
+ entityName,
7426
+ source: message.content.source,
7427
+ channelType: message.content.channelType,
7428
+ roomName
7429
+ };
7281
7430
  await runtime.emitEvent(EventType.RUN_ENDED, {
7282
7431
  runtime,
7283
7432
  runId,
@@ -7288,7 +7437,10 @@ ${response}`
7288
7437
  status: "completed",
7289
7438
  endTime: Date.now(),
7290
7439
  duration: Date.now() - startTime,
7291
- source: "messageHandler"
7440
+ source: "messageHandler",
7441
+ entityName,
7442
+ responseContent,
7443
+ metadata: logData
7292
7444
  });
7293
7445
  } catch (error) {
7294
7446
  console.error("error is", error);
@@ -7321,10 +7473,10 @@ var reactionReceivedHandler = async ({
7321
7473
  await runtime.createMemory(message, "messages");
7322
7474
  } catch (error) {
7323
7475
  if (error.code === "23505") {
7324
- logger20.warn("[Bootstrap] Duplicate reaction memory, skipping");
7476
+ runtime.logger.warn("[Bootstrap] Duplicate reaction memory, skipping");
7325
7477
  return;
7326
7478
  }
7327
- logger20.error("[Bootstrap] Error in reaction handler:", error);
7479
+ runtime.logger.error("[Bootstrap] Error in reaction handler:", error);
7328
7480
  }
7329
7481
  };
7330
7482
  var messageDeletedHandler = async ({
@@ -7333,14 +7485,19 @@ var messageDeletedHandler = async ({
7333
7485
  }) => {
7334
7486
  try {
7335
7487
  if (!message.id) {
7336
- logger20.error("[Bootstrap] Cannot delete memory: message ID is missing");
7488
+ runtime.logger.error("[Bootstrap] Cannot delete memory: message ID is missing");
7337
7489
  return;
7338
7490
  }
7339
- logger20.info("[Bootstrap] Deleting memory for message", message.id, "from room", message.roomId);
7491
+ runtime.logger.info(
7492
+ "[Bootstrap] Deleting memory for message",
7493
+ message.id,
7494
+ "from room",
7495
+ message.roomId
7496
+ );
7340
7497
  await runtime.deleteMemory(message.id);
7341
- logger20.debug("[Bootstrap] Successfully deleted memory for message", message.id);
7498
+ runtime.logger.debug("[Bootstrap] Successfully deleted memory for message", message.id);
7342
7499
  } catch (error) {
7343
- logger20.error("[Bootstrap] Error in message deleted handler:", error);
7500
+ runtime.logger.error("[Bootstrap] Error in message deleted handler:", error);
7344
7501
  }
7345
7502
  };
7346
7503
  var channelClearedHandler = async ({
@@ -7350,7 +7507,7 @@ var channelClearedHandler = async ({
7350
7507
  memoryCount
7351
7508
  }) => {
7352
7509
  try {
7353
- logger20.info(
7510
+ runtime.logger.info(
7354
7511
  `[Bootstrap] Clearing ${memoryCount} message memories from channel ${channelId} -> room ${roomId}`
7355
7512
  );
7356
7513
  const memories = await runtime.getMemoriesByRoomIds({
@@ -7364,15 +7521,15 @@ var channelClearedHandler = async ({
7364
7521
  await runtime.deleteMemory(memory.id);
7365
7522
  deletedCount++;
7366
7523
  } catch (error) {
7367
- logger20.warn(`[Bootstrap] Failed to delete message memory ${memory.id}:`, error);
7524
+ runtime.logger.warn(`[Bootstrap] Failed to delete message memory ${memory.id}:`, error);
7368
7525
  }
7369
7526
  }
7370
7527
  }
7371
- logger20.info(
7528
+ runtime.logger.info(
7372
7529
  `[Bootstrap] Successfully cleared ${deletedCount}/${memories.length} message memories from channel ${channelId}`
7373
7530
  );
7374
7531
  } catch (error) {
7375
- logger20.error("[Bootstrap] Error in channel cleared handler:", error);
7532
+ runtime.logger.error("[Bootstrap] Error in channel cleared handler:", error);
7376
7533
  }
7377
7534
  };
7378
7535
  var postGeneratedHandler = async ({
@@ -7383,7 +7540,7 @@ var postGeneratedHandler = async ({
7383
7540
  roomId,
7384
7541
  source
7385
7542
  }) => {
7386
- logger20.info("[Bootstrap] Generating new post...");
7543
+ runtime.logger.info("[Bootstrap] Generating new post...");
7387
7544
  await runtime.ensureWorldExists({
7388
7545
  id: worldId,
7389
7546
  name: `${runtime.character.name}'s Feed`,
@@ -7447,7 +7604,7 @@ var postGeneratedHandler = async ({
7447
7604
  }
7448
7605
  retries++;
7449
7606
  if (!responseContent?.thought || !responseContent?.actions) {
7450
- logger20.warn(
7607
+ runtime.logger.warn(
7451
7608
  "[Bootstrap] *** Missing required fields, retrying... ***\n",
7452
7609
  response,
7453
7610
  parsedXml,
@@ -7465,7 +7622,7 @@ var postGeneratedHandler = async ({
7465
7622
  });
7466
7623
  const parsedXmlResponse = parseKeyValueXml9(xmlResponseText);
7467
7624
  if (!parsedXmlResponse) {
7468
- logger20.error(
7625
+ runtime.logger.error(
7469
7626
  "[Bootstrap] Failed to parse XML response for post creation. Raw response:",
7470
7627
  xmlResponseText
7471
7628
  );
@@ -7482,7 +7639,7 @@ var postGeneratedHandler = async ({
7482
7639
  if (RM) {
7483
7640
  for (const m of RM.data.recentMessages) {
7484
7641
  if (cleanedText === m.content.text) {
7485
- logger20.log("[Bootstrap] Already recently posted that, retrying", cleanedText);
7642
+ runtime.logger.info("[Bootstrap] Already recently posted that, retrying", cleanedText);
7486
7643
  postGeneratedHandler({
7487
7644
  runtime,
7488
7645
  callback,
@@ -7500,7 +7657,7 @@ var postGeneratedHandler = async ({
7500
7657
  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;
7501
7658
  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;
7502
7659
  if (oaiRefusalRegex.test(cleanedText) || anthropicRefusalRegex.test(cleanedText) || googleRefusalRegex.test(cleanedText) || generalRefusalRegex.test(cleanedText)) {
7503
- logger20.log("[Bootstrap] Got prompt moderation refusal, retrying", cleanedText);
7660
+ runtime.logger.info("[Bootstrap] Got prompt moderation refusal, retrying", cleanedText);
7504
7661
  postGeneratedHandler({
7505
7662
  runtime,
7506
7663
  callback,
@@ -7534,9 +7691,9 @@ var postGeneratedHandler = async ({
7534
7691
  var syncSingleUser = async (entityId, runtime, serverId, channelId, type, source) => {
7535
7692
  try {
7536
7693
  const entity = await runtime.getEntityById(entityId);
7537
- logger20.info(`[Bootstrap] Syncing user: ${entity?.metadata?.username || entityId}`);
7694
+ runtime.logger.info(`[Bootstrap] Syncing user: ${entity?.metadata?.username || entityId}`);
7538
7695
  if (!channelId) {
7539
- logger20.warn(`[Bootstrap] Cannot sync user ${entity?.id} without a valid channelId`);
7696
+ runtime.logger.warn(`[Bootstrap] Cannot sync user ${entity?.id} without a valid channelId`);
7540
7697
  return;
7541
7698
  }
7542
7699
  const roomId = createUniqueUuid3(runtime, channelId);
@@ -7551,7 +7708,7 @@ var syncSingleUser = async (entityId, runtime, serverId, channelId, type, source
7551
7708
  settings: {}
7552
7709
  // Initialize empty settings for onboarding
7553
7710
  } : void 0;
7554
- logger20.info(
7711
+ runtime.logger.info(
7555
7712
  `[Bootstrap] syncSingleUser - type: ${type}, isDM: ${type === ChannelType9.DM}, worldMetadata: ${JSON.stringify(worldMetadata)}`
7556
7713
  );
7557
7714
  await runtime.ensureConnection({
@@ -7567,15 +7724,15 @@ var syncSingleUser = async (entityId, runtime, serverId, channelId, type, source
7567
7724
  });
7568
7725
  try {
7569
7726
  const createdWorld = await runtime.getWorld(worldId);
7570
- logger20.info(
7727
+ runtime.logger.info(
7571
7728
  `[Bootstrap] Created world check - ID: ${worldId}, metadata: ${JSON.stringify(createdWorld?.metadata)}`
7572
7729
  );
7573
7730
  } catch (error) {
7574
- logger20.error(`[Bootstrap] Failed to verify created world: ${error}`);
7731
+ runtime.logger.error(`[Bootstrap] Failed to verify created world: ${error}`);
7575
7732
  }
7576
- logger20.success(`[Bootstrap] Successfully synced user: ${entity?.id}`);
7733
+ runtime.logger.success(`[Bootstrap] Successfully synced user: ${entity?.id}`);
7577
7734
  } catch (error) {
7578
- logger20.error(
7735
+ runtime.logger.error(
7579
7736
  `[Bootstrap] Error syncing user: ${error instanceof Error ? error.message : String(error)}`
7580
7737
  );
7581
7738
  }
@@ -7588,13 +7745,13 @@ var handleServerSync = async ({
7588
7745
  source,
7589
7746
  onComplete
7590
7747
  }) => {
7591
- logger20.debug(`[Bootstrap] Handling server sync event for server: ${world.name}`);
7748
+ runtime.logger.debug(`[Bootstrap] Handling server sync event for server: ${world.name}`);
7592
7749
  try {
7593
7750
  await runtime.ensureConnections(entities, rooms, source, world);
7594
- logger20.debug(`Successfully synced standardized world structure for ${world.name}`);
7751
+ runtime.logger.debug(`Successfully synced standardized world structure for ${world.name}`);
7595
7752
  onComplete?.();
7596
7753
  } catch (error) {
7597
- logger20.error(
7754
+ runtime.logger.error(
7598
7755
  `Error processing standardized server data: ${error instanceof Error ? error.message : String(error)}`
7599
7756
  );
7600
7757
  }
@@ -7604,7 +7761,7 @@ var controlMessageHandler = async ({
7604
7761
  message
7605
7762
  }) => {
7606
7763
  try {
7607
- logger20.debug(
7764
+ runtime.logger.debug(
7608
7765
  `[controlMessageHandler] Processing control message: ${message.payload.action} for room ${message.roomId}`
7609
7766
  );
7610
7767
  const serviceNames = Array.from(runtime.getAllServices().keys());
@@ -7622,24 +7779,28 @@ var controlMessageHandler = async ({
7622
7779
  roomId: message.roomId
7623
7780
  }
7624
7781
  });
7625
- logger20.debug(
7782
+ runtime.logger.debug(
7626
7783
  `[controlMessageHandler] Control message ${message.payload.action} sent successfully`
7627
7784
  );
7628
7785
  } else {
7629
- logger20.error("[controlMessageHandler] WebSocket service does not have sendMessage method");
7786
+ runtime.logger.error(
7787
+ "[controlMessageHandler] WebSocket service does not have sendMessage method"
7788
+ );
7630
7789
  }
7631
7790
  } else {
7632
- logger20.error("[controlMessageHandler] No WebSocket service found to send control message");
7791
+ runtime.logger.error(
7792
+ "[controlMessageHandler] No WebSocket service found to send control message"
7793
+ );
7633
7794
  }
7634
7795
  } catch (error) {
7635
- logger20.error(`[controlMessageHandler] Error processing control message: ${error}`);
7796
+ runtime.logger.error(`[controlMessageHandler] Error processing control message: ${error}`);
7636
7797
  }
7637
7798
  };
7638
7799
  var events = {
7639
7800
  [EventType.MESSAGE_RECEIVED]: [
7640
7801
  async (payload) => {
7641
7802
  if (!payload.callback) {
7642
- logger20.error("No callback provided for message");
7803
+ payload.runtime.logger.error("No callback provided for message");
7643
7804
  return;
7644
7805
  }
7645
7806
  await messageReceivedHandler({
@@ -7653,7 +7814,7 @@ var events = {
7653
7814
  [EventType.VOICE_MESSAGE_RECEIVED]: [
7654
7815
  async (payload) => {
7655
7816
  if (!payload.callback) {
7656
- logger20.error("No callback provided for voice message");
7817
+ payload.runtime.logger.error("No callback provided for voice message");
7657
7818
  return;
7658
7819
  }
7659
7820
  await messageReceivedHandler({
@@ -7679,7 +7840,7 @@ var events = {
7679
7840
  ],
7680
7841
  [EventType.MESSAGE_SENT]: [
7681
7842
  async (payload) => {
7682
- logger20.debug(`[Bootstrap] Message sent: ${payload.message.content.text}`);
7843
+ payload.runtime.logger.debug(`[Bootstrap] Message sent: ${payload.message.content.text}`);
7683
7844
  }
7684
7845
  ],
7685
7846
  [EventType.MESSAGE_DELETED]: [
@@ -7712,17 +7873,19 @@ var events = {
7712
7873
  ],
7713
7874
  [EventType.ENTITY_JOINED]: [
7714
7875
  async (payload) => {
7715
- logger20.debug(`[Bootstrap] ENTITY_JOINED event received for entity ${payload.entityId}`);
7876
+ payload.runtime.logger.debug(
7877
+ `[Bootstrap] ENTITY_JOINED event received for entity ${payload.entityId}`
7878
+ );
7716
7879
  if (!payload.worldId) {
7717
- logger20.error("[Bootstrap] No worldId provided for entity joined");
7880
+ payload.runtime.logger.error("[Bootstrap] No worldId provided for entity joined");
7718
7881
  return;
7719
7882
  }
7720
7883
  if (!payload.roomId) {
7721
- logger20.error("[Bootstrap] No roomId provided for entity joined");
7884
+ payload.runtime.logger.error("[Bootstrap] No roomId provided for entity joined");
7722
7885
  return;
7723
7886
  }
7724
7887
  if (!payload.metadata?.type) {
7725
- logger20.error("[Bootstrap] No type provided for entity joined");
7888
+ payload.runtime.logger.error("[Bootstrap] No type provided for entity joined");
7726
7889
  return;
7727
7890
  }
7728
7891
  await syncSingleUser(
@@ -7747,9 +7910,11 @@ var events = {
7747
7910
  };
7748
7911
  await payload.runtime.updateEntity(entity);
7749
7912
  }
7750
- logger20.info(`[Bootstrap] User ${payload.entityId} left world ${payload.worldId}`);
7913
+ payload.runtime.logger.info(
7914
+ `[Bootstrap] User ${payload.entityId} left world ${payload.worldId}`
7915
+ );
7751
7916
  } catch (error) {
7752
- logger20.error(`[Bootstrap] Error handling user left: ${error.message}`);
7917
+ payload.runtime.logger.error(`[Bootstrap] Error handling user left: ${error.message}`);
7753
7918
  }
7754
7919
  }
7755
7920
  ],