@elizaos/plugin-bootstrap 1.0.0-beta.37 → 1.0.0-beta.40

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
@@ -79,11 +79,10 @@ import {
79
79
  logger as logger17,
80
80
  messageHandlerTemplate,
81
81
  ModelType as ModelType13,
82
- parseJSONObjectFromText as parseJSONObjectFromText4,
83
82
  postCreationTemplate,
84
- providersTemplate,
85
83
  shouldRespondTemplate,
86
- truncateToCompleteSentence
84
+ truncateToCompleteSentence,
85
+ parseKeyValueXml
87
86
  } from "@elizaos/core";
88
87
 
89
88
  // ../../node_modules/uuid/dist/esm/stringify.js
@@ -723,7 +722,10 @@ var ignoreAction = {
723
722
  return true;
724
723
  },
725
724
  description: "Call this action if ignoring the user. If the user is aggressive, creepy or is finished with the conversation, use this action. Or, if both you and the user have already said goodbye, use this action instead of saying bye again. Use IGNORE any time the conversation has naturally ended. Do not use IGNORE if the user has engaged directly, or if something went wrong an you need to tell them. Only ignore if the user should be ignored.",
726
- handler: async (_runtime, _message) => {
725
+ handler: async (_runtime, _message, _state, _options, callback, responses) => {
726
+ if (callback && responses?.[0]?.content) {
727
+ await callback(responses[0].content);
728
+ }
727
729
  return true;
728
730
  },
729
731
  examples: [
@@ -3649,7 +3651,6 @@ import { addHeader as addHeader2, ChannelType as ChannelType3 } from "@elizaos/c
3649
3651
  var anxietyProvider = {
3650
3652
  name: "ANXIETY",
3651
3653
  description: "Social directions for the AI to follow based on the channel type",
3652
- dynamic: true,
3653
3654
  get: async (_runtime, message) => {
3654
3655
  const channelType = message.content.channelType;
3655
3656
  const groupAnxietyExamples = [
@@ -3842,7 +3843,7 @@ var characterProvider = {
3842
3843
  const bio = addHeader4(`# About ${character.name}`, bioText);
3843
3844
  const system = character.system ?? "";
3844
3845
  const topicString = character.topics && character.topics.length > 0 ? character.topics[Math.floor(Math.random() * character.topics.length)] : null;
3845
- const topic = topicString ? `${character.name} is currently interested in ${topicString}` : "";
3846
+ const topic = topicString || "";
3846
3847
  const topics = character.topics && character.topics.length > 0 ? `${character.name} is also interested in ${character.topics.filter((topic2) => topic2 !== topicString).sort(() => 0.5 - Math.random()).slice(0, 5).map((topic2, index, array) => {
3847
3848
  if (index === array.length - 2) {
3848
3849
  return `${topic2} and `;
@@ -3853,7 +3854,7 @@ var characterProvider = {
3853
3854
  return `${topic2}, `;
3854
3855
  }).join("")}` : "";
3855
3856
  const adjectiveString = character.adjectives && character.adjectives.length > 0 ? character.adjectives[Math.floor(Math.random() * character.adjectives.length)] : "";
3856
- const adjective = adjectiveString ? `${character.name} is ${adjectiveString}` : "";
3857
+ const adjective = adjectiveString || "";
3857
3858
  const formattedCharacterPostExamples = !character.postExamples ? "" : character.postExamples.sort(() => 0.5 - Math.random()).map((post) => {
3858
3859
  const messageString = `${post}`;
3859
3860
  return messageString;
@@ -3921,7 +3922,9 @@ var characterProvider = {
3921
3922
  examples,
3922
3923
  system
3923
3924
  };
3924
- const text = [bio, adjective, topic, topics, adjective, directions, examples, system].filter(Boolean).join("\n\n");
3925
+ const topicSentence = topicString ? `${character.name} is currently interested in ${topicString}` : "";
3926
+ const adjectiveSentence = adjectiveString ? `${character.name} is ${adjectiveString}` : "";
3927
+ const text = [bio, adjectiveSentence, topicSentence, topics, directions, examples, system].filter(Boolean).join("\n\n");
3925
3928
  return {
3926
3929
  values,
3927
3930
  data,
@@ -4184,14 +4187,17 @@ var factsProvider = {
4184
4187
  tableName: "facts",
4185
4188
  embedding,
4186
4189
  roomId: message.roomId,
4187
- count: 10
4190
+ worldId: message.worldId,
4191
+ count: 6,
4192
+ query: message.content.text
4188
4193
  }),
4189
- runtime.getMemories({
4194
+ runtime.searchMemories({
4195
+ embedding,
4196
+ query: message.content.text,
4190
4197
  tableName: "facts",
4191
4198
  roomId: message.roomId,
4192
- count: 10,
4193
- start: 0,
4194
- end: Date.now()
4199
+ entityId: message.entityId,
4200
+ count: 6
4195
4201
  })
4196
4202
  ]);
4197
4203
  const allFacts = [...relevantFacts, ...recentFactsData].filter(
@@ -4226,14 +4232,19 @@ var factsProvider = {
4226
4232
  import { addHeader as addHeader7 } from "@elizaos/core";
4227
4233
  var knowledgeProvider = {
4228
4234
  name: "KNOWLEDGE",
4229
- description: "Knowledge from the knowledge base that the agent knows",
4235
+ description: "Knowledge from the knowledge base that the agent knows, retrieved whenever the agent needs to answer a question about their expertise.",
4230
4236
  dynamic: true,
4231
4237
  get: async (runtime, message) => {
4232
4238
  const knowledgeData = await runtime.getKnowledge(message);
4233
- const knowledge = knowledgeData && knowledgeData.length > 0 ? addHeader7(
4239
+ const firstFiveKnowledgeItems = knowledgeData?.slice(0, 5);
4240
+ let knowledge = (firstFiveKnowledgeItems && firstFiveKnowledgeItems.length > 0 ? addHeader7(
4234
4241
  "# Knowledge",
4235
- knowledgeData.map((knowledge2) => `- ${knowledge2.content.text}`).join("\n")
4236
- ) : "";
4242
+ firstFiveKnowledgeItems.map((knowledge2) => `- ${knowledge2.content.text}`).join("\n")
4243
+ ) : "") + "\n";
4244
+ const tokenLength = 3.5;
4245
+ if (knowledge.length > 4e3 * tokenLength) {
4246
+ knowledge = knowledge.slice(0, 4e3 * tokenLength);
4247
+ }
4237
4248
  return {
4238
4249
  data: {
4239
4250
  knowledge
@@ -5035,7 +5046,7 @@ var ScenarioService = class _ScenarioService extends Service {
5035
5046
  this.setupEventListeners();
5036
5047
  }
5037
5048
  static serviceType = "scenario";
5038
- capabilityDescription = "The agent is currently in a scenario testing environment. It can create rooms, send messages, and talk to other agents in a live interactive testing environment.";
5049
+ 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.";
5039
5050
  messageHandlers = /* @__PURE__ */ new Map();
5040
5051
  worlds = /* @__PURE__ */ new Map();
5041
5052
  activeActions = /* @__PURE__ */ new Map();
@@ -5387,6 +5398,10 @@ var TaskService = class _TaskService extends Service2 {
5387
5398
  const now = Date.now();
5388
5399
  for (const task of tasks) {
5389
5400
  let taskStartTime;
5401
+ if (!task.tags?.includes("repeat")) {
5402
+ await this.executeTask(task);
5403
+ continue;
5404
+ }
5390
5405
  if (typeof task.updatedAt === "number") {
5391
5406
  taskStartTime = task.updatedAt;
5392
5407
  } else if (task.metadata?.updatedAt && typeof task.metadata.updatedAt === "number") {
@@ -5401,6 +5416,13 @@ var TaskService = class _TaskService extends Service2 {
5401
5416
  await this.executeTask(task);
5402
5417
  continue;
5403
5418
  }
5419
+ if (task.metadata.updatedAt === task.metadata.createdAt) {
5420
+ if (task.tags?.includes("immediate")) {
5421
+ logger16.debug("immediately running task", task.name);
5422
+ await this.executeTask(task);
5423
+ continue;
5424
+ }
5425
+ }
5404
5426
  if (now - taskStartTime >= updateIntervalMs) {
5405
5427
  logger16.debug(
5406
5428
  `Executing task ${task.name} - interval of ${updateIntervalMs}ms has elapsed`
@@ -5428,9 +5450,6 @@ var TaskService = class _TaskService extends Service2 {
5428
5450
  logger16.debug(`No worker found for task type: ${task.name}`);
5429
5451
  return;
5430
5452
  }
5431
- logger16.debug(`Executing task ${task.name} (${task.id})`);
5432
- await worker.execute(this.runtime, task.metadata || {}, task);
5433
- logger16.debug("task.tags are", task.tags);
5434
5453
  if (task.tags?.includes("repeat")) {
5435
5454
  await this.runtime.updateTask(task.id, {
5436
5455
  metadata: {
@@ -5439,7 +5458,10 @@ var TaskService = class _TaskService extends Service2 {
5439
5458
  }
5440
5459
  });
5441
5460
  logger16.debug(`Updated repeating task ${task.name} (${task.id}) with new timestamp`);
5442
- } else {
5461
+ }
5462
+ logger16.debug(`Executing task ${task.name} (${task.id})`);
5463
+ await worker.execute(this.runtime, task.metadata || {}, task);
5464
+ if (!task.tags?.includes("repeat")) {
5443
5465
  await this.runtime.deleteTask(task.id);
5444
5466
  logger16.debug(`Deleted non-repeating task ${task.name} (${task.id}) after execution`);
5445
5467
  }
@@ -5550,16 +5572,15 @@ var messageReceivedHandler = async ({
5550
5572
  return;
5551
5573
  }
5552
5574
  let state = await runtime.composeState(message, [
5553
- "PROVIDERS",
5575
+ "ANXIETY",
5554
5576
  "SHOULD_RESPOND",
5577
+ "ENTITIES",
5555
5578
  "CHARACTER",
5556
- "RECENT_MESSAGES",
5557
- "ENTITIES"
5579
+ "RECENT_MESSAGES"
5558
5580
  ]);
5559
5581
  const room = await runtime.getRoom(message.roomId);
5560
5582
  const shouldSkipShouldRespond = room?.type === ChannelType10.DM || room?.type === ChannelType10.VOICE_DM || room?.type === ChannelType10.SELF;
5561
5583
  let shouldRespond = true;
5562
- let providers = [];
5563
5584
  if (!shouldSkipShouldRespond) {
5564
5585
  const shouldRespondPrompt = composePromptFromState9({
5565
5586
  state,
@@ -5576,32 +5597,15 @@ var messageReceivedHandler = async ({
5576
5597
  logger17.debug(`*** Should Respond Response for ${runtime.character.name} ***
5577
5598
  `, response);
5578
5599
  logger17.debug(`*** Raw Response Type: ${typeof response} ***`);
5579
- let processedResponse = response;
5580
- if (typeof response === "string" && response.includes("```")) {
5581
- logger17.debug("*** Response contains code block markers, attempting to clean up ***");
5582
- processedResponse = response.replace(/```json\n|\n```|```/g, "");
5583
- logger17.debug("*** Processed Response ***\n", processedResponse);
5584
- }
5585
- const responseObject = parseJSONObjectFromText4(processedResponse);
5586
- logger17.debug("*** Parsed Response Object ***", responseObject);
5600
+ const responseObject = parseKeyValueXml(response);
5601
+ logger17.debug("*** Parsed XML Response Object ***", responseObject);
5587
5602
  shouldRespond = responseObject?.action && responseObject.action === "RESPOND";
5588
- providers = responseObject?.providers || [];
5589
5603
  } else {
5590
- const providersPrompt = composePromptFromState9({
5591
- state,
5592
- template: runtime.character.templates?.providersTemplate || providersTemplate
5593
- });
5594
- const response = await runtime.useModel(ModelType13.TEXT_SMALL, {
5595
- prompt: providersPrompt
5596
- });
5597
- const responseObject = parseJSONObjectFromText4(response);
5598
- providers = responseObject?.providers || [];
5604
+ shouldRespond = true;
5599
5605
  }
5600
- logger17.debug("*** Should Respond ***", shouldRespond);
5601
- logger17.debug("*** Providers Value ***", providers);
5602
- state = await runtime.composeState(message, null, providers);
5603
5606
  let responseMessages = [];
5604
5607
  if (shouldRespond) {
5608
+ state = await runtime.composeState(message);
5605
5609
  const prompt = composePromptFromState9({
5606
5610
  state,
5607
5611
  template: runtime.character.templates?.messageHandlerTemplate || messageHandlerTemplate
@@ -5610,13 +5614,26 @@ var messageReceivedHandler = async ({
5610
5614
  let retries = 0;
5611
5615
  const maxRetries = 3;
5612
5616
  while (retries < maxRetries && (!responseContent?.thought || !responseContent?.actions)) {
5613
- const response = await runtime.useModel(ModelType13.TEXT_LARGE, {
5617
+ let response = await runtime.useModel(ModelType13.TEXT_LARGE, {
5614
5618
  prompt
5615
5619
  });
5616
- responseContent = parseJSONObjectFromText4(response);
5620
+ logger17.debug("*** Raw LLM Response ***\n", response);
5621
+ const parsedXml = parseKeyValueXml(response);
5622
+ logger17.debug("*** Parsed XML Content ***\n", parsedXml);
5623
+ if (parsedXml) {
5624
+ responseContent = {
5625
+ thought: parsedXml.thought || "",
5626
+ actions: parsedXml.actions || ["IGNORE"],
5627
+ providers: parsedXml.providers || [],
5628
+ text: parsedXml.text || "",
5629
+ simple: parsedXml.simple || false
5630
+ };
5631
+ } else {
5632
+ responseContent = null;
5633
+ }
5617
5634
  retries++;
5618
- if (!responseContent?.thought && !responseContent?.actions) {
5619
- logger17.warn("*** Missing required fields, retrying... ***");
5635
+ if (!responseContent?.thought || !responseContent?.actions) {
5636
+ logger17.warn("*** Missing required fields (thought or actions), retrying... ***");
5620
5637
  }
5621
5638
  }
5622
5639
  const currentResponseId = agentResponses.get(message.roomId);
@@ -5628,26 +5645,63 @@ var messageReceivedHandler = async ({
5628
5645
  }
5629
5646
  if (responseContent) {
5630
5647
  responseContent.inReplyTo = createUniqueUuid4(runtime, message.id);
5631
- responseMessages = [
5632
- {
5633
- id: asUUID(v4_default()),
5634
- entityId: runtime.agentId,
5635
- agentId: runtime.agentId,
5636
- content: responseContent,
5637
- roomId: message.roomId,
5638
- createdAt: Date.now()
5639
- }
5640
- ];
5641
- callback(responseContent);
5648
+ const responseMesssage = {
5649
+ id: asUUID(v4_default()),
5650
+ entityId: runtime.agentId,
5651
+ agentId: runtime.agentId,
5652
+ content: responseContent,
5653
+ roomId: message.roomId,
5654
+ createdAt: Date.now()
5655
+ };
5656
+ responseMessages = [responseMesssage];
5657
+ }
5658
+ agentResponses.delete(message.roomId);
5659
+ if (agentResponses.size === 0) {
5660
+ latestResponseIds.delete(runtime.agentId);
5661
+ }
5662
+ if (responseContent?.providers.length > 0) {
5663
+ state = await runtime.composeState(message, null, [...responseContent?.providers]);
5664
+ }
5665
+ if (responseContent && responseContent.simple && responseContent.text && (responseContent.actions.length === 0 || responseContent.actions.length === 1 && responseContent.actions[0].toUpperCase() === "REPLY")) {
5666
+ await callback(responseContent);
5667
+ } else {
5668
+ await runtime.processActions(message, responseMessages, state, callback);
5669
+ }
5670
+ await runtime.evaluate(message, state, shouldRespond, callback, responseMessages);
5671
+ } else {
5672
+ logger17.debug("Agent decided not to respond (shouldRespond is false).");
5673
+ const currentResponseId = agentResponses.get(message.roomId);
5674
+ if (currentResponseId !== responseId) {
5675
+ logger17.info(
5676
+ `Ignore response discarded - newer message being processed for agent: ${runtime.agentId}, room: ${message.roomId}`
5677
+ );
5678
+ return;
5642
5679
  }
5680
+ const ignoreContent = {
5681
+ thought: "Agent decided not to respond to this message.",
5682
+ actions: ["IGNORE"],
5683
+ simple: true,
5684
+ // Treat it as simple for callback purposes
5685
+ inReplyTo: createUniqueUuid4(runtime, message.id)
5686
+ // Reference original message
5687
+ };
5688
+ await callback(ignoreContent);
5689
+ const ignoreMemory = {
5690
+ id: asUUID(v4_default()),
5691
+ entityId: runtime.agentId,
5692
+ agentId: runtime.agentId,
5693
+ content: ignoreContent,
5694
+ roomId: message.roomId,
5695
+ createdAt: Date.now()
5696
+ };
5697
+ await runtime.createMemory(ignoreMemory, "messages");
5698
+ logger17.debug("Saved ignore response to memory", { memoryId: ignoreMemory.id });
5643
5699
  agentResponses.delete(message.roomId);
5644
5700
  if (agentResponses.size === 0) {
5645
5701
  latestResponseIds.delete(runtime.agentId);
5646
5702
  }
5647
- await runtime.processActions(message, responseMessages, state, callback);
5648
5703
  }
5649
5704
  onComplete?.();
5650
- await runtime.evaluate(message, state, shouldRespond, callback, responseMessages);
5651
5705
  await runtime.emitEvent(EventType2.RUN_ENDED, {
5652
5706
  runtime,
5653
5707
  runId,
@@ -5727,21 +5781,63 @@ var postGeneratedHandler = async ({
5727
5781
  entityId: runtime.agentId,
5728
5782
  agentId: runtime.agentId,
5729
5783
  roomId,
5730
- content: {}
5784
+ content: {},
5785
+ metadata: {
5786
+ entityName: runtime.character.name,
5787
+ type: "message"
5788
+ }
5731
5789
  };
5732
- const state = await runtime.composeState(message, null, [
5790
+ let state = await runtime.composeState(message, null, [
5791
+ "PROVIDERS",
5733
5792
  "CHARACTER",
5734
- "RECENT_MESSAGES",
5793
+ //'RECENT_MESSAGES',
5735
5794
  "ENTITIES"
5736
5795
  ]);
5796
+ const entity = await runtime.getEntityById(runtime.agentId);
5797
+ if (entity?.metadata?.twitter?.userName) {
5798
+ state.values.twitterUserName = entity?.metadata?.twitter?.userName;
5799
+ }
5800
+ const prompt = composePromptFromState9({
5801
+ state,
5802
+ template: runtime.character.templates?.messageHandlerTemplate || messageHandlerTemplate
5803
+ });
5804
+ let responseContent = null;
5805
+ let retries = 0;
5806
+ const maxRetries = 3;
5807
+ while (retries < maxRetries && (!responseContent?.thought || !responseContent?.actions)) {
5808
+ const response = await runtime.useModel(ModelType13.TEXT_SMALL, {
5809
+ prompt
5810
+ });
5811
+ const parsedXml = parseKeyValueXml(response);
5812
+ if (parsedXml) {
5813
+ responseContent = {
5814
+ thought: parsedXml.thought || "",
5815
+ actions: parsedXml.actions || ["IGNORE"],
5816
+ providers: parsedXml.providers || [],
5817
+ text: parsedXml.text || "",
5818
+ simple: parsedXml.simple || false
5819
+ };
5820
+ } else {
5821
+ responseContent = null;
5822
+ }
5823
+ retries++;
5824
+ if (!responseContent?.thought || !responseContent?.actions) {
5825
+ logger17.warn("*** Missing required fields, retrying... ***");
5826
+ }
5827
+ }
5828
+ state = await runtime.composeState(message, responseContent.providers);
5737
5829
  const postPrompt = composePromptFromState9({
5738
5830
  state,
5739
5831
  template: runtime.character.templates?.postCreationTemplate || postCreationTemplate
5740
5832
  });
5741
- const jsonResponse = await runtime.useModel(ModelType13.OBJECT_LARGE, {
5742
- prompt: postPrompt,
5743
- output: "no-schema"
5833
+ const xmlResponseText = await runtime.useModel(ModelType13.TEXT_LARGE, {
5834
+ prompt: postPrompt
5744
5835
  });
5836
+ const parsedXmlResponse = parseKeyValueXml(xmlResponseText);
5837
+ if (!parsedXmlResponse) {
5838
+ logger17.error("Failed to parse XML response for post creation. Raw response:", xmlResponseText);
5839
+ return;
5840
+ }
5745
5841
  function cleanupPostText(text) {
5746
5842
  let cleanedText2 = text.replace(/^['"](.*)['"]$/, "$1");
5747
5843
  cleanedText2 = cleanedText2.replaceAll(/\\n/g, "\n\n");
@@ -5750,7 +5846,40 @@ var postGeneratedHandler = async ({
5750
5846
  }
5751
5847
  return cleanedText2;
5752
5848
  }
5753
- const cleanedText = cleanupPostText(jsonResponse.post);
5849
+ const cleanedText = cleanupPostText(parsedXmlResponse.post || "");
5850
+ const RM = state.providerData?.find((pd) => pd.providerName === "RECENT_MESSAGES");
5851
+ if (RM) {
5852
+ for (const m of RM.data.recentMessages) {
5853
+ if (cleanedText === m.content.text) {
5854
+ logger17.log("we've already recently posted that, retrying", cleanedText);
5855
+ postGeneratedHandler({
5856
+ runtime,
5857
+ callback,
5858
+ worldId,
5859
+ userId,
5860
+ roomId,
5861
+ source
5862
+ });
5863
+ return;
5864
+ }
5865
+ }
5866
+ }
5867
+ const oaiRefusalRegex = /((i\s+do\s+not|i'm\s+not)\s+(feel\s+)?comfortable\s+generating\s+that\s+type\s+of\s+content)|(inappropriate|explicit|respectful|offensive|guidelines|aim\s+to\s+(be\s+)?helpful|communicate\s+respectfully)/i;
5868
+ const anthropicRefusalRegex = /(i'?m\s+unable\s+to\s+help\s+with\s+that\s+request|due\s+to\s+safety\s+concerns|that\s+may\s+violate\s+(our\s+)?guidelines|provide\s+helpful\s+and\s+safe\s+responses|let'?s\s+try\s+a\s+different\s+direction|goes\s+against\s+(our\s+)?use\s+case\s+policies|ensure\s+safe\s+and\s+responsible\s+use)/i;
5869
+ 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;
5870
+ 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;
5871
+ if (oaiRefusalRegex.test(cleanedText) || anthropicRefusalRegex.test(cleanedText) || googleRefusalRegex.test(cleanedText) || generalRefusalRegex.test(cleanedText)) {
5872
+ logger17.log("got prompt moderation refusal, retrying", cleanedText);
5873
+ postGeneratedHandler({
5874
+ runtime,
5875
+ callback,
5876
+ worldId,
5877
+ userId,
5878
+ roomId,
5879
+ source
5880
+ });
5881
+ return;
5882
+ }
5754
5883
  const responseMessages = [
5755
5884
  {
5756
5885
  id: v4_default(),
@@ -5760,7 +5889,7 @@ var postGeneratedHandler = async ({
5760
5889
  text: cleanedText,
5761
5890
  source,
5762
5891
  channelType: ChannelType10.FEED,
5763
- thought: jsonResponse.thought || "",
5892
+ thought: parsedXmlResponse.thought || "",
5764
5893
  type: "post"
5765
5894
  },
5766
5895
  roomId: message.roomId,
@@ -5772,11 +5901,11 @@ var postGeneratedHandler = async ({
5772
5901
  }
5773
5902
  };
5774
5903
  var syncSingleUser = async (entityId, runtime, serverId, channelId, type, source) => {
5775
- const entity = await runtime.getEntityById(entityId);
5776
- logger17.info(`Syncing user: ${entity.metadata[source].username || entity.id}`);
5777
5904
  try {
5905
+ const entity = await runtime.getEntityById(entityId);
5906
+ logger17.info(`Syncing user: ${entity?.metadata[source]?.username || entityId}`);
5778
5907
  if (!channelId) {
5779
- logger17.warn(`Cannot sync user ${entity.id} without a valid channelId`);
5908
+ logger17.warn(`Cannot sync user ${entity?.id} without a valid channelId`);
5780
5909
  return;
5781
5910
  }
5782
5911
  const roomId = createUniqueUuid4(runtime, channelId);
@@ -5784,15 +5913,15 @@ var syncSingleUser = async (entityId, runtime, serverId, channelId, type, source
5784
5913
  await runtime.ensureConnection({
5785
5914
  entityId,
5786
5915
  roomId,
5787
- userName: entity.metadata[source].username || entity.id,
5788
- name: entity.metadata[source].name || entity.metadata[source].username || `User${entity.id}`,
5916
+ userName: entity?.metadata[source].username || entityId,
5917
+ name: entity?.metadata[source].name || entity?.metadata[source].username || `User${entityId}`,
5789
5918
  source,
5790
5919
  channelId,
5791
5920
  serverId,
5792
5921
  type,
5793
5922
  worldId
5794
5923
  });
5795
- logger17.success(`Successfully synced user: ${entity.id}`);
5924
+ logger17.success(`Successfully synced user: ${entity?.id}`);
5796
5925
  } catch (error) {
5797
5926
  logger17.error(`Error syncing user: ${error instanceof Error ? error.message : String(error)}`);
5798
5927
  }