@elizaos/plugin-bootstrap 1.0.7 → 1.0.8

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
@@ -71,7 +71,7 @@ var require_dedent = __commonJS({
71
71
 
72
72
  // src/index.ts
73
73
  import {
74
- asUUID,
74
+ asUUID as asUUID13,
75
75
  ChannelType as ChannelType9,
76
76
  composePromptFromState as composePromptFromState9,
77
77
  ContentType,
@@ -83,6 +83,7 @@ import {
83
83
  ModelType as ModelType13,
84
84
  parseKeyValueXml,
85
85
  postCreationTemplate,
86
+ Role as Role2,
86
87
  shouldRespondTemplate,
87
88
  truncateToCompleteSentence
88
89
  } from "@elizaos/core";
@@ -138,7 +139,8 @@ import {
138
139
  getUserServerRole,
139
140
  logger,
140
141
  ModelType,
141
- parseJSONObjectFromText
142
+ parseJSONObjectFromText,
143
+ asUUID
142
144
  } from "@elizaos/core";
143
145
  var optionExtractionTemplate = `# Task: Extract selected task and option from user message
144
146
 
@@ -250,55 +252,97 @@ ${task.options?.map((opt) => `- ${opt.name}: ${opt.description}`).join("\n")}`;
250
252
  const taskMap = new Map(formattedTasks.map((task) => [task.taskId, task]));
251
253
  const taskInfo = taskMap.get(taskId);
252
254
  if (!taskInfo) {
253
- await callback?.({
254
- text: `Could not find a task matching ID: ${taskId}. Please try again.`,
255
- actions: ["SELECT_OPTION_ERROR"],
256
- source: message.content.source
257
- });
255
+ const errorMessage = {
256
+ id: asUUID(v4_default()),
257
+ entityId: runtime.agentId,
258
+ agentId: runtime.agentId,
259
+ content: {
260
+ text: `Could not find a task matching ID: ${taskId}. Please try again.`,
261
+ source: message.content.source
262
+ },
263
+ roomId: message.roomId,
264
+ createdAt: Date.now()
265
+ };
266
+ responses?.push(errorMessage);
258
267
  return;
259
268
  }
260
269
  const selectedTask = tasksWithOptions.find((task) => task.id === taskInfo.fullId);
261
270
  if (!selectedTask) {
262
- await callback?.({
263
- text: "Error locating the selected task. Please try again.",
264
- actions: ["SELECT_OPTION_ERROR"],
265
- source: message.content.source
266
- });
271
+ const errorMessage = {
272
+ id: asUUID(v4_default()),
273
+ entityId: runtime.agentId,
274
+ agentId: runtime.agentId,
275
+ content: {
276
+ text: "Error locating the selected task. Please try again.",
277
+ source: message.content.source
278
+ },
279
+ roomId: message.roomId,
280
+ createdAt: Date.now()
281
+ };
282
+ responses?.push(errorMessage);
267
283
  return;
268
284
  }
269
285
  if (selectedOption === "ABORT") {
270
286
  if (!selectedTask?.id) {
271
- await callback?.({
272
- text: "Error locating the selected task. Please try again.",
273
- actions: ["SELECT_OPTION_ERROR"],
274
- source: message.content.source
275
- });
287
+ const errorMessage = {
288
+ id: asUUID(v4_default()),
289
+ entityId: runtime.agentId,
290
+ agentId: runtime.agentId,
291
+ content: {
292
+ text: "Error locating the selected task. Please try again.",
293
+ source: message.content.source
294
+ },
295
+ roomId: message.roomId,
296
+ createdAt: Date.now()
297
+ };
298
+ responses?.push(errorMessage);
276
299
  return;
277
300
  }
278
301
  await runtime.deleteTask(selectedTask.id);
279
- await callback?.({
280
- text: `Task "${selectedTask.name}" has been cancelled.`,
281
- actions: ["CHOOSE_OPTION_CANCELLED"],
282
- source: message.content.source
283
- });
302
+ const cancelMessage = {
303
+ id: asUUID(v4_default()),
304
+ entityId: runtime.agentId,
305
+ agentId: runtime.agentId,
306
+ content: {
307
+ text: `Task "${selectedTask.name}" has been cancelled.`,
308
+ source: message.content.source
309
+ },
310
+ roomId: message.roomId,
311
+ createdAt: Date.now()
312
+ };
313
+ responses?.push(cancelMessage);
284
314
  return;
285
315
  }
286
316
  try {
287
317
  const taskWorker = runtime.getTaskWorker(selectedTask.name);
288
318
  await taskWorker?.execute(runtime, { option: selectedOption }, selectedTask);
289
- await callback?.({
290
- text: `Selected option: ${selectedOption} for task: ${selectedTask.name}`,
291
- actions: ["CHOOSE_OPTION"],
292
- source: message.content.source
293
- });
319
+ const successMessage = {
320
+ id: asUUID(v4_default()),
321
+ entityId: runtime.agentId,
322
+ agentId: runtime.agentId,
323
+ content: {
324
+ text: `Selected option: ${selectedOption} for task: ${selectedTask.name}`,
325
+ source: message.content.source
326
+ },
327
+ roomId: message.roomId,
328
+ createdAt: Date.now()
329
+ };
330
+ responses?.push(successMessage);
294
331
  return;
295
332
  } catch (error) {
296
333
  logger.error("Error executing task with option:", error);
297
- await callback?.({
298
- text: "There was an error processing your selection.",
299
- actions: ["SELECT_OPTION_ERROR"],
300
- source: message.content.source
301
- });
334
+ const errorMessage = {
335
+ id: asUUID(v4_default()),
336
+ entityId: runtime.agentId,
337
+ agentId: runtime.agentId,
338
+ content: {
339
+ text: "There was an error processing your selection.",
340
+ source: message.content.source
341
+ },
342
+ roomId: message.roomId,
343
+ createdAt: Date.now()
344
+ };
345
+ responses?.push(errorMessage);
302
346
  return;
303
347
  }
304
348
  }
@@ -314,11 +358,28 @@ ${task.options?.map((opt) => `- ${opt.name}: ${opt.description}`).join("\n")}`;
314
358
  optionsText += options?.map((opt) => `- ${opt}`).join("\n");
315
359
  optionsText += "\n\n";
316
360
  });
317
- await callback?.({
318
- text: optionsText,
319
- actions: ["SELECT_OPTION_INVALID"],
320
- source: message.content.source
321
- });
361
+ const invalidMessage = {
362
+ id: asUUID(v4_default()),
363
+ entityId: runtime.agentId,
364
+ agentId: runtime.agentId,
365
+ content: {
366
+ text: optionsText,
367
+ source: message.content.source
368
+ },
369
+ roomId: message.roomId,
370
+ createdAt: Date.now()
371
+ };
372
+ await runtime.createMemory(
373
+ {
374
+ ...invalidMessage,
375
+ content: {
376
+ ...invalidMessage.content,
377
+ actions: ["SELECT_OPTION_INVALID"]
378
+ }
379
+ },
380
+ "messages"
381
+ );
382
+ responses?.push(invalidMessage);
322
383
  },
323
384
  examples: [
324
385
  [
@@ -359,7 +420,8 @@ import {
359
420
  booleanFooter,
360
421
  composePromptFromState,
361
422
  logger as logger2,
362
- ModelType as ModelType2
423
+ ModelType as ModelType2,
424
+ asUUID as asUUID2
363
425
  } from "@elizaos/core";
364
426
  var shouldFollowTemplate = `# Task: Decide if {{agentName}} should start following this room, i.e. eagerly participating without explicit mentions.
365
427
 
@@ -386,7 +448,7 @@ var followRoomAction = {
386
448
  const roomState = await runtime.getParticipantUserState(roomId, runtime.agentId);
387
449
  return roomState !== "FOLLOWED" && roomState !== "MUTED";
388
450
  },
389
- handler: async (runtime, message, state, _options, _callback, _responses) => {
451
+ handler: async (runtime, message, state, _options, _callback, responses) => {
390
452
  if (!state) {
391
453
  logger2.error("State is required for followRoomAction");
392
454
  throw new Error("State is required for followRoomAction");
@@ -460,6 +522,30 @@ var followRoomAction = {
460
522
  },
461
523
  "messages"
462
524
  );
525
+ const followMessage = {
526
+ id: asUUID2(v4_default()),
527
+ entityId: runtime.agentId,
528
+ agentId: runtime.agentId,
529
+ content: {
530
+ text: "",
531
+ // Empty text since this is just an action
532
+ thought: `I followed the room ${room.name}`,
533
+ source: message.content.source
534
+ },
535
+ roomId: message.roomId,
536
+ createdAt: Date.now()
537
+ };
538
+ await runtime.createMemory(
539
+ {
540
+ ...followMessage,
541
+ content: {
542
+ ...followMessage.content,
543
+ actions: ["FOLLOW_ROOM"]
544
+ }
545
+ },
546
+ "messages"
547
+ );
548
+ responses?.push(followMessage);
463
549
  },
464
550
  examples: [
465
551
  [
@@ -737,6 +823,7 @@ var followRoomAction = {
737
823
  };
738
824
 
739
825
  // src/actions/ignore.ts
826
+ import { asUUID as asUUID3 } from "@elizaos/core";
740
827
  var ignoreAction = {
741
828
  name: "IGNORE",
742
829
  similes: ["STOP_TALKING", "STOP_CHATTING", "STOP_CONVERSATION"],
@@ -744,10 +831,23 @@ var ignoreAction = {
744
831
  return true;
745
832
  },
746
833
  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.",
747
- handler: async (_runtime, _message, _state, _options, callback, responses) => {
748
- if (callback && responses?.[0]?.content) {
749
- await callback(responses[0].content);
834
+ handler: async (runtime, message, _state, _options, callback, responses) => {
835
+ if (responses && responses.length > 0 && responses[0]?.content) {
836
+ return true;
750
837
  }
838
+ const ignoreMessage = {
839
+ id: asUUID3(v4_default()),
840
+ entityId: runtime.agentId,
841
+ agentId: runtime.agentId,
842
+ content: {
843
+ text: "",
844
+ actions: ["IGNORE"],
845
+ source: message.content.source
846
+ },
847
+ roomId: message.roomId,
848
+ createdAt: Date.now()
849
+ };
850
+ await runtime.createMemory(ignoreMessage, "messages");
751
851
  return true;
752
852
  },
753
853
  examples: [
@@ -779,7 +879,7 @@ var ignoreAction = {
779
879
  {
780
880
  name: "{{name2}}",
781
881
  content: {
782
- text: "Uh, don\u2019t let the volatility sway your long-term strategy"
882
+ text: "Uh, don't let the volatility sway your long-term strategy"
783
883
  }
784
884
  },
785
885
  {
@@ -962,7 +1062,8 @@ import {
962
1062
  booleanFooter as booleanFooter2,
963
1063
  composePromptFromState as composePromptFromState2,
964
1064
  logger as logger3,
965
- ModelType as ModelType3
1065
+ ModelType as ModelType3,
1066
+ asUUID as asUUID4
966
1067
  } from "@elizaos/core";
967
1068
  var shouldMuteTemplate = `# Task: Decide if {{agentName}} should mute this room and stop responding unless explicitly mentioned.
968
1069
 
@@ -986,7 +1087,7 @@ var muteRoomAction = {
986
1087
  const roomState = await runtime.getParticipantUserState(roomId, runtime.agentId);
987
1088
  return roomState !== "MUTED";
988
1089
  },
989
- handler: async (runtime, message, state, _options, _callback, _responses) => {
1090
+ handler: async (runtime, message, state, _options, _callback, responses) => {
990
1091
  if (!state) {
991
1092
  logger3.error("State is required for muting a room");
992
1093
  throw new Error("State is required for muting a room");
@@ -1059,6 +1160,21 @@ var muteRoomAction = {
1059
1160
  },
1060
1161
  "messages"
1061
1162
  );
1163
+ const muteMessage = {
1164
+ id: asUUID4(v4_default()),
1165
+ entityId: runtime.agentId,
1166
+ agentId: runtime.agentId,
1167
+ content: {
1168
+ text: "",
1169
+ // Empty text since this is just an action
1170
+ thought: `I muted the room ${room.name}`,
1171
+ actions: ["MUTE_ROOM"],
1172
+ source: message.content.source
1173
+ },
1174
+ roomId: message.roomId,
1175
+ createdAt: Date.now()
1176
+ };
1177
+ await runtime.createMemory(muteMessage, "messages");
1062
1178
  },
1063
1179
  examples: [
1064
1180
  [
@@ -1172,6 +1288,7 @@ var muteRoomAction = {
1172
1288
  };
1173
1289
 
1174
1290
  // src/actions/none.ts
1291
+ import { asUUID as asUUID5 } from "@elizaos/core";
1175
1292
  var noneAction = {
1176
1293
  name: "NONE",
1177
1294
  similes: ["NO_ACTION", "NO_RESPONSE", "NO_REACTION"],
@@ -1179,7 +1296,23 @@ var noneAction = {
1179
1296
  return true;
1180
1297
  },
1181
1298
  description: "Respond but perform no additional action. This is the default if the agent is speaking and not doing anything additional.",
1182
- handler: async (_runtime, _message) => {
1299
+ handler: async (runtime, message, _state, _options, _callback, responses) => {
1300
+ if (responses && responses.length > 0) {
1301
+ return true;
1302
+ }
1303
+ const noneMessage = {
1304
+ id: asUUID5(v4_default()),
1305
+ entityId: runtime.agentId,
1306
+ agentId: runtime.agentId,
1307
+ content: {
1308
+ text: "",
1309
+ actions: ["NONE"],
1310
+ source: message.content.source
1311
+ },
1312
+ roomId: message.roomId,
1313
+ createdAt: Date.now()
1314
+ };
1315
+ await runtime.createMemory(noneMessage, "messages");
1183
1316
  return true;
1184
1317
  },
1185
1318
  examples: [
@@ -1303,6 +1436,7 @@ var noneAction = {
1303
1436
  };
1304
1437
 
1305
1438
  // src/actions/reply.ts
1439
+ import { asUUID as asUUID6 } from "@elizaos/core";
1306
1440
  import {
1307
1441
  composePromptFromState as composePromptFromState3,
1308
1442
  ModelType as ModelType4
@@ -1331,6 +1465,9 @@ function getFirstAvailableField(obj, fields) {
1331
1465
  return null;
1332
1466
  }
1333
1467
  function extractReplyContent(response, replyFieldKeys) {
1468
+ if ("isPlan" in response && response.isPlan) {
1469
+ return null;
1470
+ }
1334
1471
  const hasReplyAction = response.content.actions?.includes("REPLY");
1335
1472
  const text = getFirstAvailableField(response.content, replyFieldKeys);
1336
1473
  if (!hasReplyAction || !text) return null;
@@ -1368,10 +1505,31 @@ var replyAction = {
1368
1505
  });
1369
1506
  const responseContent = {
1370
1507
  thought: response.thought,
1371
- text: response.message || "",
1372
- actions: ["REPLY"]
1508
+ text: response.message || ""
1509
+ // IF we would add actions: ['REPLY'],
1510
+ // here that would cause a loop in this action.
1511
+ // So never add this to responses unless this is decided
1512
+ // by the agent and you want to try loop.
1373
1513
  };
1374
- await callback(responseContent);
1514
+ const replyMessage = {
1515
+ id: asUUID6(v4_default()),
1516
+ entityId: runtime.agentId,
1517
+ agentId: runtime.agentId,
1518
+ content: responseContent,
1519
+ roomId: message.roomId,
1520
+ createdAt: Date.now()
1521
+ };
1522
+ await runtime.createMemory(
1523
+ {
1524
+ ...replyMessage,
1525
+ content: {
1526
+ ...replyMessage.content,
1527
+ actions: ["REPLY"]
1528
+ }
1529
+ },
1530
+ "messages"
1531
+ );
1532
+ return true;
1375
1533
  },
1376
1534
  examples: [
1377
1535
  [
@@ -1444,7 +1602,8 @@ import {
1444
1602
  composePrompt as composePrompt2,
1445
1603
  logger as logger4,
1446
1604
  ModelType as ModelType5,
1447
- Role
1605
+ Role,
1606
+ asUUID as asUUID7
1448
1607
  } from "@elizaos/core";
1449
1608
  var canModifyRole = (currentRole, targetRole, newRole) => {
1450
1609
  if (targetRole === currentRole) return false;
@@ -1474,7 +1633,7 @@ var updateRoleAction = {
1474
1633
  !!serverId
1475
1634
  );
1476
1635
  },
1477
- handler: async (runtime, message, state, _options, callback) => {
1636
+ handler: async (runtime, message, state, _options, callback, responses) => {
1478
1637
  if (!state) {
1479
1638
  logger4.error("State is required for role assignment");
1480
1639
  throw new Error("State is required for role assignment");
@@ -1488,9 +1647,18 @@ var updateRoleAction = {
1488
1647
  }
1489
1648
  if (!world) {
1490
1649
  logger4.error("World not found");
1491
- await callback?.({
1492
- text: "I couldn't find the world. This action only works in a world."
1493
- });
1650
+ const errorMessage = {
1651
+ id: asUUID7(v4_default()),
1652
+ entityId: runtime.agentId,
1653
+ agentId: runtime.agentId,
1654
+ content: {
1655
+ text: "I couldn't find the world. This action only works in a world.",
1656
+ source: message.content.source
1657
+ },
1658
+ roomId: message.roomId,
1659
+ createdAt: Date.now()
1660
+ };
1661
+ responses?.push(errorMessage);
1494
1662
  return;
1495
1663
  }
1496
1664
  if (!world.metadata?.roles) {
@@ -1558,11 +1726,18 @@ var updateRoleAction = {
1558
1726
  }
1559
1727
  );
1560
1728
  if (!result?.length) {
1561
- await callback?.({
1562
- text: "No valid role assignments found in the request.",
1563
- actions: ["UPDATE_ROLE"],
1564
- source: "discord"
1565
- });
1729
+ const noAssignmentsMessage = {
1730
+ id: asUUID7(v4_default()),
1731
+ entityId: runtime.agentId,
1732
+ agentId: runtime.agentId,
1733
+ content: {
1734
+ text: "No valid role assignments found in the request.",
1735
+ source: "discord"
1736
+ },
1737
+ roomId: message.roomId,
1738
+ createdAt: Date.now()
1739
+ };
1740
+ responses?.push(noAssignmentsMessage);
1566
1741
  return;
1567
1742
  }
1568
1743
  let worldUpdated = false;
@@ -1573,20 +1748,43 @@ var updateRoleAction = {
1573
1748
  }
1574
1749
  const currentRole = world.metadata.roles[assignment.entityId];
1575
1750
  if (!canModifyRole(requesterRole, currentRole, assignment.newRole)) {
1576
- await callback?.({
1577
- text: `You don't have permission to change ${targetEntity?.names[0]}'s role to ${assignment.newRole}.`,
1578
- actions: ["UPDATE_ROLE"],
1579
- source: "discord"
1580
- });
1751
+ const permissionErrorMessage = {
1752
+ id: asUUID7(v4_default()),
1753
+ entityId: runtime.agentId,
1754
+ agentId: runtime.agentId,
1755
+ content: {
1756
+ text: `You don't have permission to change ${targetEntity?.names[0]}'s role to ${assignment.newRole}.`,
1757
+ source: "discord"
1758
+ },
1759
+ roomId: message.roomId,
1760
+ createdAt: Date.now()
1761
+ };
1762
+ responses?.push(permissionErrorMessage);
1581
1763
  continue;
1582
1764
  }
1583
1765
  world.metadata.roles[assignment.entityId] = assignment.newRole;
1584
1766
  worldUpdated = true;
1585
- await callback?.({
1586
- text: `Updated ${targetEntity?.names[0]}'s role to ${assignment.newRole}.`,
1587
- actions: ["UPDATE_ROLE"],
1588
- source: "discord"
1589
- });
1767
+ const successMessage = {
1768
+ id: asUUID7(v4_default()),
1769
+ entityId: runtime.agentId,
1770
+ agentId: runtime.agentId,
1771
+ content: {
1772
+ text: `Updated ${targetEntity?.names[0]}'s role to ${assignment.newRole}.`,
1773
+ source: "discord"
1774
+ },
1775
+ roomId: message.roomId,
1776
+ createdAt: Date.now()
1777
+ };
1778
+ await runtime.createMemory(
1779
+ {
1780
+ ...successMessage,
1781
+ content: {
1782
+ ...successMessage.content,
1783
+ actions: ["UPDATE_ROLE"]
1784
+ }
1785
+ },
1786
+ "messages"
1787
+ );
1590
1788
  }
1591
1789
  if (worldUpdated) {
1592
1790
  await runtime.updateWorld(world);
@@ -1651,7 +1849,8 @@ import {
1651
1849
  findEntityByName,
1652
1850
  logger as logger5,
1653
1851
  ModelType as ModelType6,
1654
- parseJSONObjectFromText as parseJSONObjectFromText2
1852
+ parseJSONObjectFromText as parseJSONObjectFromText2,
1853
+ asUUID as asUUID8
1655
1854
  } from "@elizaos/core";
1656
1855
  var targetExtractionTemplate = `# Task: Extract Target and Source Information
1657
1856
 
@@ -1725,7 +1924,6 @@ var sendMessageAction = {
1725
1924
  throw new Error("Responses are required for sendMessage action");
1726
1925
  }
1727
1926
  for (const response of responses) {
1728
- await callback(response.content);
1729
1927
  }
1730
1928
  const sourceEntityId = message.entityId;
1731
1929
  const room = state.data.room ?? await runtime.getRoom(message.roomId);
@@ -1740,22 +1938,38 @@ var sendMessageAction = {
1740
1938
  });
1741
1939
  const targetData = parseJSONObjectFromText2(targetResult);
1742
1940
  if (!targetData?.targetType || !targetData?.source) {
1743
- await callback({
1744
- text: "I couldn't determine where you want me to send the message. Could you please specify the target (user or room) and platform?",
1745
- actions: ["SEND_MESSAGE_ERROR"],
1746
- source: message.content.source
1747
- });
1941
+ const errorMessage = {
1942
+ id: asUUID8(v4_default()),
1943
+ entityId: runtime.agentId,
1944
+ agentId: runtime.agentId,
1945
+ content: {
1946
+ text: "I couldn't determine where you want me to send the message. Could you please specify the target (user or room) and platform?",
1947
+ actions: ["SEND_MESSAGE_ERROR"],
1948
+ source: message.content.source
1949
+ },
1950
+ roomId: message.roomId,
1951
+ createdAt: Date.now()
1952
+ };
1953
+ responses?.push(errorMessage);
1748
1954
  return;
1749
1955
  }
1750
1956
  const source = targetData.source.toLowerCase();
1751
1957
  if (targetData.targetType === "user") {
1752
1958
  const targetEntity = await findEntityByName(runtime, message, state);
1753
1959
  if (!targetEntity) {
1754
- await callback({
1755
- text: "I couldn't find the user you want me to send a message to. Could you please provide more details about who they are?",
1756
- actions: ["SEND_MESSAGE_ERROR"],
1757
- source: message.content.source
1758
- });
1960
+ const errorMessage = {
1961
+ id: asUUID8(v4_default()),
1962
+ entityId: runtime.agentId,
1963
+ agentId: runtime.agentId,
1964
+ content: {
1965
+ text: "I couldn't find the user you want me to send a message to. Could you please provide more details about who they are?",
1966
+ actions: ["SEND_MESSAGE_ERROR"],
1967
+ source: message.content.source
1968
+ },
1969
+ roomId: message.roomId,
1970
+ createdAt: Date.now()
1971
+ };
1972
+ responses?.push(errorMessage);
1759
1973
  return;
1760
1974
  }
1761
1975
  const userComponent = await runtime.getComponent(
@@ -1765,36 +1979,77 @@ var sendMessageAction = {
1765
1979
  sourceEntityId
1766
1980
  );
1767
1981
  if (!userComponent) {
1768
- await callback({
1769
- text: `I couldn't find ${source} information for that user. Could you please provide their ${source} details?`,
1770
- actions: ["SEND_MESSAGE_ERROR"],
1771
- source: message.content.source
1772
- });
1982
+ const errorMessage = {
1983
+ id: asUUID8(v4_default()),
1984
+ entityId: runtime.agentId,
1985
+ agentId: runtime.agentId,
1986
+ content: {
1987
+ text: `I couldn't find ${source} information for that user. Could you please provide their ${source} details?`,
1988
+ actions: ["SEND_MESSAGE_ERROR"],
1989
+ source: message.content.source
1990
+ },
1991
+ roomId: message.roomId,
1992
+ createdAt: Date.now()
1993
+ };
1994
+ responses?.push(errorMessage);
1773
1995
  return;
1774
1996
  }
1775
1997
  const sendDirectMessage = runtime.getService(source)?.sendDirectMessage;
1776
1998
  if (!sendDirectMessage) {
1777
- await callback({
1778
- text: "I couldn't find the user you want me to send a message to. Could you please provide more details about who they are?",
1779
- actions: ["SEND_MESSAGE_ERROR"],
1780
- source: message.content.source
1781
- });
1999
+ const errorMessage = {
2000
+ id: asUUID8(v4_default()),
2001
+ entityId: runtime.agentId,
2002
+ agentId: runtime.agentId,
2003
+ content: {
2004
+ text: "I couldn't find the user you want me to send a message to. Could you please provide more details about who they are?",
2005
+ actions: ["SEND_MESSAGE_ERROR"],
2006
+ source: message.content.source
2007
+ },
2008
+ roomId: message.roomId,
2009
+ createdAt: Date.now()
2010
+ };
2011
+ responses?.push(errorMessage);
1782
2012
  return;
1783
2013
  }
1784
2014
  try {
1785
2015
  await sendDirectMessage(runtime, targetEntity.id, source, message.content.text, worldId);
1786
- await callback({
1787
- text: `Message sent to ${targetEntity.names[0]} on ${source}.`,
1788
- actions: ["SEND_MESSAGE"],
1789
- source: message.content.source
1790
- });
2016
+ const successMessage = {
2017
+ id: asUUID8(v4_default()),
2018
+ entityId: runtime.agentId,
2019
+ agentId: runtime.agentId,
2020
+ content: {
2021
+ text: `Message sent to ${targetEntity.names[0]} on ${source}.`,
2022
+ source: message.content.source
2023
+ },
2024
+ roomId: message.roomId,
2025
+ createdAt: Date.now()
2026
+ };
2027
+ await runtime.createMemory(
2028
+ {
2029
+ ...successMessage,
2030
+ content: {
2031
+ ...successMessage.content,
2032
+ actions: ["SEND_MESSAGE"]
2033
+ }
2034
+ },
2035
+ "messages"
2036
+ );
2037
+ responses?.push(successMessage);
1791
2038
  } catch (error) {
1792
2039
  logger5.error(`Failed to send direct message: ${error.message}`);
1793
- await callback({
1794
- text: "I encountered an error trying to send the message. Please try again.",
1795
- actions: ["SEND_MESSAGE_ERROR"],
1796
- source: message.content.source
1797
- });
2040
+ const errorMessage = {
2041
+ id: asUUID8(v4_default()),
2042
+ entityId: runtime.agentId,
2043
+ agentId: runtime.agentId,
2044
+ content: {
2045
+ text: "I encountered an error trying to send the message. Please try again.",
2046
+ actions: ["SEND_MESSAGE_ERROR"],
2047
+ source: message.content.source
2048
+ },
2049
+ roomId: message.roomId,
2050
+ createdAt: Date.now()
2051
+ };
2052
+ responses?.push(errorMessage);
1798
2053
  }
1799
2054
  } else if (targetData.targetType === "room") {
1800
2055
  const rooms = await runtime.getRooms(worldId);
@@ -1802,45 +2057,85 @@ var sendMessageAction = {
1802
2057
  return r.name?.toLowerCase() === targetData.identifiers.roomName?.toLowerCase();
1803
2058
  });
1804
2059
  if (!targetRoom) {
1805
- await callback({
1806
- text: "I couldn't find the room you want me to send a message to. Could you please specify the exact room name?",
1807
- actions: ["SEND_MESSAGE_ERROR"],
1808
- source: message.content.source
1809
- });
2060
+ const errorMessage = {
2061
+ id: asUUID8(v4_default()),
2062
+ entityId: runtime.agentId,
2063
+ agentId: runtime.agentId,
2064
+ content: {
2065
+ text: "I couldn't find the room you want me to send a message to. Could you please specify the exact room name?",
2066
+ actions: ["SEND_MESSAGE_ERROR"],
2067
+ source: message.content.source
2068
+ },
2069
+ roomId: message.roomId,
2070
+ createdAt: Date.now()
2071
+ };
2072
+ responses?.push(errorMessage);
1810
2073
  return;
1811
2074
  }
1812
2075
  const sendRoomMessage = runtime.getService(source)?.sendRoomMessage;
1813
2076
  if (!sendRoomMessage) {
1814
- await callback({
1815
- text: "I couldn't find the room you want me to send a message to. Could you please specify the exact room name?",
1816
- actions: ["SEND_MESSAGE_ERROR"],
1817
- source: message.content.source
1818
- });
2077
+ const errorMessage = {
2078
+ id: asUUID8(v4_default()),
2079
+ entityId: runtime.agentId,
2080
+ agentId: runtime.agentId,
2081
+ content: {
2082
+ text: "I couldn't find the room you want me to send a message to. Could you please specify the exact room name?",
2083
+ actions: ["SEND_MESSAGE_ERROR"],
2084
+ source: message.content.source
2085
+ },
2086
+ roomId: message.roomId,
2087
+ createdAt: Date.now()
2088
+ };
2089
+ responses?.push(errorMessage);
1819
2090
  return;
1820
2091
  }
1821
2092
  try {
1822
2093
  await sendRoomMessage(runtime, targetRoom.id, source, message.content.text, worldId);
1823
- await callback({
1824
- text: `Message sent to ${targetRoom.name} on ${source}.`,
1825
- actions: ["SEND_MESSAGE"],
1826
- source: message.content.source
1827
- });
2094
+ const successMessage = {
2095
+ id: asUUID8(v4_default()),
2096
+ entityId: runtime.agentId,
2097
+ agentId: runtime.agentId,
2098
+ content: {
2099
+ text: `Message sent to ${targetRoom.name} on ${source}.`,
2100
+ actions: ["SEND_MESSAGE"],
2101
+ source: message.content.source
2102
+ },
2103
+ roomId: message.roomId,
2104
+ createdAt: Date.now()
2105
+ };
2106
+ responses?.push(successMessage);
1828
2107
  } catch (error) {
1829
2108
  logger5.error(`Failed to send room message: ${error.message}`);
1830
- await callback({
1831
- text: "I encountered an error trying to send the message to the room. Please try again.",
1832
- actions: ["SEND_MESSAGE_ERROR"],
1833
- source: message.content.source
1834
- });
2109
+ const errorMessage = {
2110
+ id: asUUID8(v4_default()),
2111
+ entityId: runtime.agentId,
2112
+ agentId: runtime.agentId,
2113
+ content: {
2114
+ text: "I encountered an error trying to send the message to the room. Please try again.",
2115
+ actions: ["SEND_MESSAGE_ERROR"],
2116
+ source: message.content.source
2117
+ },
2118
+ roomId: message.roomId,
2119
+ createdAt: Date.now()
2120
+ };
2121
+ responses?.push(errorMessage);
1835
2122
  }
1836
2123
  }
1837
2124
  } catch (error) {
1838
2125
  logger5.error(`Error in sendMessage handler: ${error}`);
1839
- await callback?.({
1840
- text: "There was an error processing your message request.",
1841
- actions: ["SEND_MESSAGE_ERROR"],
1842
- source: message.content.source
1843
- });
2126
+ const errorMessage = {
2127
+ id: asUUID8(v4_default()),
2128
+ entityId: runtime.agentId,
2129
+ agentId: runtime.agentId,
2130
+ content: {
2131
+ text: "There was an error processing your message request.",
2132
+ actions: ["SEND_MESSAGE_ERROR"],
2133
+ source: message.content.source
2134
+ },
2135
+ roomId: message.roomId,
2136
+ createdAt: Date.now()
2137
+ };
2138
+ responses?.push(errorMessage);
1844
2139
  }
1845
2140
  },
1846
2141
  examples: [
@@ -1902,7 +2197,8 @@ import {
1902
2197
  findWorldsForOwner,
1903
2198
  logger as logger6,
1904
2199
  ModelType as ModelType7,
1905
- parseJSONObjectFromText as parseJSONObjectFromText3
2200
+ parseJSONObjectFromText as parseJSONObjectFromText3,
2201
+ asUUID as asUUID9
1906
2202
  } from "@elizaos/core";
1907
2203
  var messageCompletionFooter = `
1908
2204
  # Instructions: Write the next message for {{agentName}}. Include the appropriate action from the list: {{actionNames}}
@@ -2171,7 +2467,7 @@ async function processSettingUpdates(runtime, serverId, worldSettings, updates)
2171
2467
  };
2172
2468
  }
2173
2469
  }
2174
- async function handleOnboardingComplete(runtime, worldSettings, state, callback) {
2470
+ async function handleOnboardingComplete(runtime, worldSettings, state, callback, responses) {
2175
2471
  try {
2176
2472
  const prompt = composePrompt3({
2177
2473
  state: {
@@ -2183,25 +2479,41 @@ async function handleOnboardingComplete(runtime, worldSettings, state, callback)
2183
2479
  prompt
2184
2480
  });
2185
2481
  const responseContent = parseJSONObjectFromText3(response);
2186
- await callback({
2187
- text: responseContent.text,
2188
- actions: ["ONBOARDING_COMPLETE"],
2189
- source: "discord"
2190
- });
2482
+ const completionMessage = {
2483
+ id: asUUID9(v4_default()),
2484
+ entityId: runtime.agentId,
2485
+ agentId: runtime.agentId,
2486
+ content: {
2487
+ text: responseContent.text,
2488
+ actions: ["ONBOARDING_COMPLETE"],
2489
+ source: "discord"
2490
+ },
2491
+ roomId: state.roomId || "",
2492
+ createdAt: Date.now()
2493
+ };
2494
+ responses?.push(completionMessage);
2191
2495
  } catch (error) {
2192
2496
  logger6.error(`Error handling settings completion: ${error}`);
2193
- await callback({
2194
- text: "Great! All required settings have been configured. Your server is now fully set up and ready to use.",
2195
- actions: ["ONBOARDING_COMPLETE"],
2196
- source: "discord"
2197
- });
2497
+ const errorMessage = {
2498
+ id: asUUID9(v4_default()),
2499
+ entityId: runtime.agentId,
2500
+ agentId: runtime.agentId,
2501
+ content: {
2502
+ text: "Great! All required settings have been configured. Your server is now fully set up and ready to use.",
2503
+ actions: ["ONBOARDING_COMPLETE"],
2504
+ source: "discord"
2505
+ },
2506
+ roomId: state.roomId || "",
2507
+ createdAt: Date.now()
2508
+ };
2509
+ responses?.push(errorMessage);
2198
2510
  }
2199
2511
  }
2200
- async function generateSuccessResponse(runtime, worldSettings, state, messages, callback) {
2512
+ async function generateSuccessResponse(runtime, worldSettings, state, messages, callback, responses) {
2201
2513
  try {
2202
2514
  const { requiredUnconfigured } = categorizeSettings(worldSettings);
2203
2515
  if (requiredUnconfigured.length === 0) {
2204
- await handleOnboardingComplete(runtime, worldSettings, state, callback);
2516
+ await handleOnboardingComplete(runtime, worldSettings, state, callback, responses);
2205
2517
  return;
2206
2518
  }
2207
2519
  const requiredUnconfiguredString = requiredUnconfigured.map(([key, setting]) => `${key}: ${setting.name}`).join("\n");
@@ -2217,25 +2529,50 @@ async function generateSuccessResponse(runtime, worldSettings, state, messages,
2217
2529
  prompt
2218
2530
  });
2219
2531
  const responseContent = parseJSONObjectFromText3(response);
2220
- await callback({
2221
- text: responseContent.text,
2222
- actions: ["SETTING_UPDATED"],
2223
- source: "discord"
2224
- });
2532
+ const successMessage = {
2533
+ id: asUUID9(v4_default()),
2534
+ entityId: runtime.agentId,
2535
+ agentId: runtime.agentId,
2536
+ content: {
2537
+ text: responseContent.text,
2538
+ source: "discord"
2539
+ },
2540
+ roomId: state.roomId || "",
2541
+ createdAt: Date.now()
2542
+ };
2543
+ await runtime.createMemory(
2544
+ {
2545
+ ...successMessage,
2546
+ content: {
2547
+ ...successMessage.content,
2548
+ actions: ["SETTING_UPDATED"]
2549
+ }
2550
+ },
2551
+ "messages"
2552
+ );
2553
+ responses?.push(successMessage);
2225
2554
  } catch (error) {
2226
2555
  logger6.error(`Error generating success response: ${error}`);
2227
- await callback({
2228
- text: "Settings updated successfully. Please continue with the remaining configuration.",
2229
- actions: ["SETTING_UPDATED"],
2230
- source: "discord"
2231
- });
2556
+ const errorMessage = {
2557
+ id: asUUID9(v4_default()),
2558
+ entityId: runtime.agentId,
2559
+ agentId: runtime.agentId,
2560
+ content: {
2561
+ text: "Settings updated successfully. Please continue with the remaining configuration.",
2562
+ actions: ["SETTING_UPDATED"],
2563
+ source: "discord"
2564
+ },
2565
+ roomId: state.roomId || "",
2566
+ createdAt: Date.now()
2567
+ };
2568
+ responses?.push(errorMessage);
2232
2569
  }
2233
2570
  }
2234
- async function generateFailureResponse(runtime, worldSettings, state, callback) {
2571
+ async function generateFailureResponse(runtime, worldSettings, state, callback, responses) {
2235
2572
  try {
2236
2573
  const { requiredUnconfigured } = categorizeSettings(worldSettings);
2237
2574
  if (requiredUnconfigured.length === 0) {
2238
- await handleOnboardingComplete(runtime, worldSettings, state, callback);
2575
+ await handleOnboardingComplete(runtime, worldSettings, state, callback, responses);
2239
2576
  return;
2240
2577
  }
2241
2578
  const requiredUnconfiguredString = requiredUnconfigured.map(([key, setting]) => `${key}: ${setting.name}`).join("\n");
@@ -2250,21 +2587,37 @@ async function generateFailureResponse(runtime, worldSettings, state, callback)
2250
2587
  prompt
2251
2588
  });
2252
2589
  const responseContent = parseJSONObjectFromText3(response);
2253
- await callback({
2254
- text: responseContent.text,
2255
- actions: ["SETTING_UPDATE_FAILED"],
2256
- source: "discord"
2257
- });
2590
+ const failureMessage = {
2591
+ id: asUUID9(v4_default()),
2592
+ entityId: runtime.agentId,
2593
+ agentId: runtime.agentId,
2594
+ content: {
2595
+ text: responseContent.text,
2596
+ actions: ["SETTING_UPDATE_FAILED"],
2597
+ source: "discord"
2598
+ },
2599
+ roomId: state.roomId || "",
2600
+ createdAt: Date.now()
2601
+ };
2602
+ responses?.push(failureMessage);
2258
2603
  } catch (error) {
2259
2604
  logger6.error(`Error generating failure response: ${error}`);
2260
- await callback({
2261
- text: "I couldn't understand your settings update. Please try again with a clearer format.",
2262
- actions: ["SETTING_UPDATE_FAILED"],
2263
- source: "discord"
2264
- });
2605
+ const errorMessage = {
2606
+ id: asUUID9(v4_default()),
2607
+ entityId: runtime.agentId,
2608
+ agentId: runtime.agentId,
2609
+ content: {
2610
+ text: "I couldn't understand your settings update. Please try again with a clearer format.",
2611
+ actions: ["SETTING_UPDATE_FAILED"],
2612
+ source: "discord"
2613
+ },
2614
+ roomId: state.roomId || "",
2615
+ createdAt: Date.now()
2616
+ };
2617
+ responses?.push(errorMessage);
2265
2618
  }
2266
2619
  }
2267
- async function generateErrorResponse(runtime, state, callback) {
2620
+ async function generateErrorResponse(runtime, state, callback, responses) {
2268
2621
  try {
2269
2622
  const prompt = composePromptFromState5({
2270
2623
  state,
@@ -2274,18 +2627,34 @@ async function generateErrorResponse(runtime, state, callback) {
2274
2627
  prompt
2275
2628
  });
2276
2629
  const responseContent = parseJSONObjectFromText3(response);
2277
- await callback({
2278
- text: responseContent.text,
2279
- actions: ["SETTING_UPDATE_ERROR"],
2280
- source: "discord"
2281
- });
2630
+ const errorMessage = {
2631
+ id: asUUID9(v4_default()),
2632
+ entityId: runtime.agentId,
2633
+ agentId: runtime.agentId,
2634
+ content: {
2635
+ text: responseContent.text,
2636
+ actions: ["SETTING_UPDATE_ERROR"],
2637
+ source: "discord"
2638
+ },
2639
+ roomId: state.roomId || "",
2640
+ createdAt: Date.now()
2641
+ };
2642
+ responses?.push(errorMessage);
2282
2643
  } catch (error) {
2283
2644
  logger6.error(`Error generating error response: ${error}`);
2284
- await callback({
2285
- text: "I'm sorry, but I encountered an error while processing your request. Please try again or contact support if the issue persists.",
2286
- actions: ["SETTING_UPDATE_ERROR"],
2287
- source: "discord"
2288
- });
2645
+ const defaultErrorMessage = {
2646
+ id: asUUID9(v4_default()),
2647
+ entityId: runtime.agentId,
2648
+ agentId: runtime.agentId,
2649
+ content: {
2650
+ text: "I'm sorry, but I encountered an error while processing your request. Please try again or contact support if the issue persists.",
2651
+ actions: ["SETTING_UPDATE_ERROR"],
2652
+ source: "discord"
2653
+ },
2654
+ roomId: state.roomId || "",
2655
+ createdAt: Date.now()
2656
+ };
2657
+ responses?.push(defaultErrorMessage);
2289
2658
  }
2290
2659
  }
2291
2660
  var updateSettingsAction = {
@@ -2316,7 +2685,7 @@ var updateSettingsAction = {
2316
2685
  return false;
2317
2686
  }
2318
2687
  },
2319
- handler: async (runtime, message, state, _options, callback) => {
2688
+ handler: async (runtime, message, state, _options, callback, responses) => {
2320
2689
  try {
2321
2690
  if (!state) {
2322
2691
  logger6.error("State is required for settings handler");
@@ -2335,7 +2704,7 @@ var updateSettingsAction = {
2335
2704
  const serverOwnership = worlds?.find((world) => world.metadata?.settings);
2336
2705
  if (!serverOwnership) {
2337
2706
  logger6.error(`No server found for user ${message.entityId} in handler`);
2338
- await generateErrorResponse(runtime, state, callback);
2707
+ await generateErrorResponse(runtime, state, callback, responses);
2339
2708
  return;
2340
2709
  }
2341
2710
  const serverId = serverOwnership?.serverId;
@@ -2347,7 +2716,7 @@ var updateSettingsAction = {
2347
2716
  const worldSettings = await getWorldSettings(runtime, serverId);
2348
2717
  if (!worldSettings) {
2349
2718
  logger6.error(`No settings state found for server ${serverId} in handler`);
2350
- await generateErrorResponse(runtime, state, callback);
2719
+ await generateErrorResponse(runtime, state, callback, responses);
2351
2720
  return;
2352
2721
  }
2353
2722
  logger6.info(`Extracting settings from message: ${message.content.text}`);
@@ -2364,7 +2733,7 @@ var updateSettingsAction = {
2364
2733
  const updatedWorldSettings = await getWorldSettings(runtime, serverId);
2365
2734
  if (!updatedWorldSettings) {
2366
2735
  logger6.error("Failed to retrieve updated settings state");
2367
- await generateErrorResponse(runtime, state, callback);
2736
+ await generateErrorResponse(runtime, state, callback, responses);
2368
2737
  return;
2369
2738
  }
2370
2739
  await generateSuccessResponse(
@@ -2372,16 +2741,17 @@ var updateSettingsAction = {
2372
2741
  updatedWorldSettings,
2373
2742
  state,
2374
2743
  updateResults.messages,
2375
- callback
2744
+ callback,
2745
+ responses
2376
2746
  );
2377
2747
  } else {
2378
2748
  logger6.info("No settings were updated");
2379
- await generateFailureResponse(runtime, worldSettings, state, callback);
2749
+ await generateFailureResponse(runtime, worldSettings, state, callback, responses);
2380
2750
  }
2381
2751
  } catch (error) {
2382
2752
  logger6.error(`Error in settings handler: ${error}`);
2383
2753
  if (state && callback) {
2384
- await generateErrorResponse(runtime, state, callback);
2754
+ await generateErrorResponse(runtime, state, callback, responses);
2385
2755
  }
2386
2756
  }
2387
2757
  },
@@ -2564,7 +2934,8 @@ import {
2564
2934
  booleanFooter as booleanFooter3,
2565
2935
  composePromptFromState as composePromptFromState6,
2566
2936
  ModelType as ModelType8,
2567
- parseBooleanFromText
2937
+ parseBooleanFromText,
2938
+ asUUID as asUUID10
2568
2939
  } from "@elizaos/core";
2569
2940
  var shouldUnfollowTemplate = `# Task: Decide if {{agentName}} should stop closely following this previously followed room and only respond when mentioned.
2570
2941
 
@@ -2587,7 +2958,7 @@ var unfollowRoomAction = {
2587
2958
  const roomState = await runtime.getParticipantUserState(roomId, runtime.agentId);
2588
2959
  return roomState === "FOLLOWED";
2589
2960
  },
2590
- handler: async (runtime, message, state, _options, _callback, _responses) => {
2961
+ handler: async (runtime, message, state, _options, _callback, responses) => {
2591
2962
  async function _shouldUnfollow(state2) {
2592
2963
  const shouldUnfollowPrompt = composePromptFromState6({
2593
2964
  state: state2,
@@ -2615,6 +2986,20 @@ var unfollowRoomAction = {
2615
2986
  },
2616
2987
  "messages"
2617
2988
  );
2989
+ const unfollowMessage = {
2990
+ id: asUUID10(v4_default()),
2991
+ entityId: runtime.agentId,
2992
+ agentId: runtime.agentId,
2993
+ content: {
2994
+ text: "",
2995
+ // Empty text since this is just an action
2996
+ thought: `I unfollowed the room ${room.name}`,
2997
+ source: message.content.source
2998
+ },
2999
+ roomId: message.roomId,
3000
+ createdAt: Date.now()
3001
+ };
3002
+ responses?.push(unfollowMessage);
2618
3003
  } else {
2619
3004
  await runtime.createMemory(
2620
3005
  {
@@ -2886,7 +3271,8 @@ import {
2886
3271
  booleanFooter as booleanFooter4,
2887
3272
  composePromptFromState as composePromptFromState7,
2888
3273
  logger as logger7,
2889
- ModelType as ModelType9
3274
+ ModelType as ModelType9,
3275
+ asUUID as asUUID11
2890
3276
  } from "@elizaos/core";
2891
3277
  var shouldUnmuteTemplate = `# Task: Decide if {{agentName}} should unmute this previously muted room and start considering it for responses again.
2892
3278
 
@@ -2909,7 +3295,7 @@ var unmuteRoomAction = {
2909
3295
  const roomState = await runtime.getParticipantUserState(roomId, runtime.agentId);
2910
3296
  return roomState === "MUTED";
2911
3297
  },
2912
- handler: async (runtime, message, state, _options, _callback, _responses) => {
3298
+ handler: async (runtime, message, state, _options, _callback, responses) => {
2913
3299
  async function _shouldUnmute(state2) {
2914
3300
  const shouldUnmutePrompt = composePromptFromState7({
2915
3301
  state: state2,
@@ -2983,6 +3369,20 @@ var unmuteRoomAction = {
2983
3369
  },
2984
3370
  "messages"
2985
3371
  );
3372
+ const unmuteMessage = {
3373
+ id: asUUID11(v4_default()),
3374
+ entityId: runtime.agentId,
3375
+ agentId: runtime.agentId,
3376
+ content: {
3377
+ text: "",
3378
+ // Empty text since this is just an action
3379
+ thought: `I unmuted the room ${room.name}`,
3380
+ source: message.content.source
3381
+ },
3382
+ roomId: message.roomId,
3383
+ createdAt: Date.now()
3384
+ };
3385
+ responses?.push(unmuteMessage);
2986
3386
  },
2987
3387
  examples: [
2988
3388
  [
@@ -3080,7 +3480,8 @@ import {
3080
3480
  composePromptFromState as composePromptFromState8,
3081
3481
  findEntityByName as findEntityByName2,
3082
3482
  logger as logger8,
3083
- ModelType as ModelType10
3483
+ ModelType as ModelType10,
3484
+ asUUID as asUUID12
3084
3485
  } from "@elizaos/core";
3085
3486
  var componentTemplate = `# Task: Extract Source and Update Component Data
3086
3487
 
@@ -3163,7 +3564,6 @@ var updateEntityAction = {
3163
3564
  throw new Error("Message is required for the updateEntity action");
3164
3565
  }
3165
3566
  for (const response of responses) {
3166
- await callback(response.content);
3167
3567
  }
3168
3568
  const sourceEntityId = message.entityId;
3169
3569
  const _roomId = message.roomId;
@@ -3172,11 +3572,19 @@ var updateEntityAction = {
3172
3572
  const worldId = room.worldId;
3173
3573
  const entity = await findEntityByName2(runtime, message, state);
3174
3574
  if (!entity) {
3175
- await callback({
3176
- text: "I'm not sure which entity you're trying to update. Could you please specify who you're talking about?",
3177
- actions: ["UPDATE_ENTITY_ERROR"],
3178
- source: message.content.source
3179
- });
3575
+ const errorMessage = {
3576
+ id: asUUID12(v4_default()),
3577
+ entityId: runtime.agentId,
3578
+ agentId: runtime.agentId,
3579
+ content: {
3580
+ text: "I'm not sure which entity you're trying to update. Could you please specify who you're talking about?",
3581
+ actions: ["UPDATE_ENTITY_ERROR"],
3582
+ source: message.content.source
3583
+ },
3584
+ roomId: message.roomId,
3585
+ createdAt: Date.now()
3586
+ };
3587
+ responses?.push(errorMessage);
3180
3588
  return;
3181
3589
  }
3182
3590
  let existingComponent = null;
@@ -3200,11 +3608,19 @@ var updateEntityAction = {
3200
3608
  }
3201
3609
  } catch (error) {
3202
3610
  logger8.error(`Failed to parse component data: ${error.message}`);
3203
- await callback({
3204
- text: "I couldn't properly understand the component information. Please try again with more specific information.",
3205
- actions: ["UPDATE_ENTITY_ERROR"],
3206
- source: message.content.source
3207
- });
3611
+ const errorMessage = {
3612
+ id: asUUID12(v4_default()),
3613
+ entityId: runtime.agentId,
3614
+ agentId: runtime.agentId,
3615
+ content: {
3616
+ text: "I couldn't properly understand the component information. Please try again with more specific information.",
3617
+ actions: ["UPDATE_ENTITY_ERROR"],
3618
+ source: message.content.source
3619
+ },
3620
+ roomId: message.roomId,
3621
+ createdAt: Date.now()
3622
+ };
3623
+ responses?.push(errorMessage);
3208
3624
  return;
3209
3625
  }
3210
3626
  const componentType = parsedResult.source.toLowerCase();
@@ -3227,11 +3643,19 @@ var updateEntityAction = {
3227
3643
  sourceEntityId,
3228
3644
  createdAt: existingComponent.createdAt
3229
3645
  });
3230
- await callback({
3231
- text: `I've updated the ${componentType} information for ${entity.names[0]}.`,
3232
- actions: ["UPDATE_ENTITY"],
3233
- source: message.content.source
3234
- });
3646
+ const successMessage = {
3647
+ id: asUUID12(v4_default()),
3648
+ entityId: runtime.agentId,
3649
+ agentId: runtime.agentId,
3650
+ content: {
3651
+ text: `I've updated the ${componentType} information for ${entity.names[0]}.`,
3652
+ actions: ["UPDATE_ENTITY"],
3653
+ source: message.content.source
3654
+ },
3655
+ roomId: message.roomId,
3656
+ createdAt: Date.now()
3657
+ };
3658
+ responses?.push(successMessage);
3235
3659
  } else {
3236
3660
  await runtime.createComponent({
3237
3661
  id: v4_default(),
@@ -3244,19 +3668,35 @@ var updateEntityAction = {
3244
3668
  sourceEntityId,
3245
3669
  createdAt: Date.now()
3246
3670
  });
3247
- await callback({
3248
- text: `I've added new ${componentType} information for ${entity.names[0]}.`,
3249
- actions: ["UPDATE_ENTITY"],
3250
- source: message.content.source
3251
- });
3671
+ const successMessage = {
3672
+ id: asUUID12(v4_default()),
3673
+ entityId: runtime.agentId,
3674
+ agentId: runtime.agentId,
3675
+ content: {
3676
+ text: `I've added new ${componentType} information for ${entity.names[0]}.`,
3677
+ actions: ["UPDATE_ENTITY"],
3678
+ source: message.content.source
3679
+ },
3680
+ roomId: message.roomId,
3681
+ createdAt: Date.now()
3682
+ };
3683
+ responses?.push(successMessage);
3252
3684
  }
3253
3685
  } catch (error) {
3254
3686
  logger8.error(`Error in updateEntity handler: ${error}`);
3255
- await callback?.({
3256
- text: "There was an error processing the entity information.",
3257
- actions: ["UPDATE_ENTITY_ERROR"],
3258
- source: message.content.source
3259
- });
3687
+ const errorMessage = {
3688
+ id: asUUID12(v4_default()),
3689
+ entityId: runtime.agentId,
3690
+ agentId: runtime.agentId,
3691
+ content: {
3692
+ text: "There was an error processing the entity information.",
3693
+ actions: ["UPDATE_ENTITY_ERROR"],
3694
+ source: message.content.source
3695
+ },
3696
+ roomId: message.roomId,
3697
+ createdAt: Date.now()
3698
+ };
3699
+ responses?.push(errorMessage);
3260
3700
  }
3261
3701
  },
3262
3702
  examples: [
@@ -3732,6 +4172,10 @@ var actionsProvider = {
3732
4172
  const actionsData = resolvedActions.filter(Boolean);
3733
4173
  const actionNames = `Possible response actions: ${formatActionNames(actionsData)}`;
3734
4174
  const actions = actionsData.length > 0 ? addHeader("# Available Actions", formatActions(actionsData)) : "";
4175
+ const actionDescriptions = actionsData.length > 0 ? addHeader(
4176
+ "# Action Descriptions",
4177
+ actionsData.map((action) => `- **${action.name}**: ${action.description}`).join("\n")
4178
+ ) : "";
3735
4179
  const actionExamples = actionsData.length > 0 ? addHeader("# Action Examples", composeActionExamples(actionsData, 10)) : "";
3736
4180
  const data = {
3737
4181
  actionsData
@@ -3739,9 +4183,10 @@ var actionsProvider = {
3739
4183
  const values = {
3740
4184
  actions,
3741
4185
  actionNames,
4186
+ actionDescriptions,
3742
4187
  actionExamples
3743
4188
  };
3744
- const text = [actionNames, actionExamples, actions].filter(Boolean).join("\n\n");
4189
+ const text = [actionNames, actionDescriptions, actionExamples, actions].filter(Boolean).join("\n\n");
3745
4190
  return {
3746
4191
  data,
3747
4192
  values,
@@ -4495,7 +4940,7 @@ var recentMessagesProvider = {
4495
4940
  if (isSelf) {
4496
4941
  sender = runtime.character.name;
4497
4942
  } else {
4498
- sender = interactionEntityMap.get(message2.entityId)?.metadata?.username || "unknown";
4943
+ sender = interactionEntityMap.get(message2.entityId)?.metadata?.userName || "unknown";
4499
4944
  }
4500
4945
  return `${sender}: ${message2.content.text}`;
4501
4946
  });
@@ -4565,7 +5010,9 @@ var recentMessagesProvider = {
4565
5010
 
4566
5011
  // src/providers/relationships.ts
4567
5012
  async function formatRelationships(runtime, relationships) {
4568
- const sortedRelationships = relationships.filter((rel) => rel.metadata?.interactions).sort((a2, b) => (b.metadata?.interactions || 0) - (a2.metadata?.interactions || 0)).slice(0, 30);
5013
+ const sortedRelationships = relationships.filter((rel) => rel.metadata?.interactions).sort(
5014
+ (a2, b) => (b.metadata?.interactions || 0) - (a2.metadata?.interactions || 0)
5015
+ ).slice(0, 30);
4569
5016
  if (sortedRelationships.length === 0) {
4570
5017
  return "";
4571
5018
  }
@@ -4709,8 +5156,8 @@ var roleProvider = {
4709
5156
  for (const entityId of Object.keys(roles)) {
4710
5157
  const userRole = roles[entityId];
4711
5158
  const user = await runtime.getEntityById(entityId);
4712
- const name = user?.metadata?.[room.source]?.name;
4713
- const username = user?.metadata?.[room.source]?.username;
5159
+ const name = user?.metadata?.name;
5160
+ const username = user?.metadata?.username;
4714
5161
  const names = user?.names;
4715
5162
  if (owners.some((owner) => owner.username === username) || admins.some((admin) => admin.username === username) || members.some((member) => member.username === username)) {
4716
5163
  continue;
@@ -4900,7 +5347,16 @@ var settingsProvider = {
4900
5347
  let serverId = void 0;
4901
5348
  let worldSettings = null;
4902
5349
  if (isOnboarding) {
4903
- world = userWorlds?.find((world2) => world2.metadata?.settings);
5350
+ world = userWorlds?.find((world2) => world2.metadata?.settings !== void 0);
5351
+ if (!world && userWorlds && userWorlds.length > 0) {
5352
+ world = userWorlds[0];
5353
+ if (!world.metadata) {
5354
+ world.metadata = {};
5355
+ }
5356
+ world.metadata.settings = {};
5357
+ await runtime.updateWorld(world);
5358
+ logger15.info(`Initialized settings for user's world ${world.id}`);
5359
+ }
4904
5360
  if (!world) {
4905
5361
  logger15.error("No world found for user during onboarding");
4906
5362
  throw new Error("No server ownership found for onboarding");
@@ -5528,7 +5984,7 @@ var messageReceivedHandler = async ({
5528
5984
  throw new Error("Agent responses map not found");
5529
5985
  }
5530
5986
  agentResponses.set(message.roomId, responseId);
5531
- const runId = asUUID(v4_default());
5987
+ const runId = asUUID13(v4_default());
5532
5988
  const startTime = Date.now();
5533
5989
  await runtime.emitEvent(EventType.RUN_STARTED, {
5534
5990
  runtime,
@@ -5680,15 +6136,16 @@ ${response}`
5680
6136
  responseContent.inReplyTo = createUniqueUuid3(runtime, message.id);
5681
6137
  const isSimple = responseContent.actions?.length === 1 && responseContent.actions[0].toUpperCase() === "REPLY" && (!responseContent.providers || responseContent.providers.length === 0);
5682
6138
  responseContent.simple = isSimple;
5683
- const responseMesssage = {
5684
- id: asUUID(v4_default()),
6139
+ const agentPlan = {
6140
+ id: asUUID13(v4_default()),
5685
6141
  entityId: runtime.agentId,
5686
6142
  agentId: runtime.agentId,
5687
6143
  content: responseContent,
5688
6144
  roomId: message.roomId,
6145
+ isPlan: true,
5689
6146
  createdAt: Date.now()
5690
6147
  };
5691
- responseMessages = [responseMesssage];
6148
+ responseMessages = [agentPlan];
5692
6149
  }
5693
6150
  agentResponses.delete(message.roomId);
5694
6151
  if (agentResponses.size === 0) {
@@ -5721,6 +6178,10 @@ ${response}`
5721
6178
  }
5722
6179
  }
5723
6180
  for (const memory of responseMessages) {
6181
+ if ("isPlan" in memory && memory.isPlan) {
6182
+ logger18.debug("[Bootstrap] Skipping agent plan in callback - internal use only");
6183
+ continue;
6184
+ }
5724
6185
  await callback(memory.content);
5725
6186
  }
5726
6187
  }
@@ -5757,7 +6218,7 @@ ${response}`
5757
6218
  };
5758
6219
  await callback(ignoreContent);
5759
6220
  const ignoreMemory = {
5760
- id: asUUID(v4_default()),
6221
+ id: asUUID13(v4_default()),
5761
6222
  entityId: runtime.agentId,
5762
6223
  agentId: runtime.agentId,
5763
6224
  content: ignoreContent,
@@ -5822,6 +6283,54 @@ var reactionReceivedHandler = async ({
5822
6283
  logger18.error("[Bootstrap] Error in reaction handler:", error);
5823
6284
  }
5824
6285
  };
6286
+ var messageDeletedHandler = async ({
6287
+ runtime,
6288
+ message
6289
+ }) => {
6290
+ try {
6291
+ if (!message.id) {
6292
+ logger18.error("[Bootstrap] Cannot delete memory: message ID is missing");
6293
+ return;
6294
+ }
6295
+ logger18.info("[Bootstrap] Deleting memory for message", message.id, "from room", message.roomId);
6296
+ await runtime.deleteMemory(message.id);
6297
+ logger18.debug("[Bootstrap] Successfully deleted memory for message", message.id);
6298
+ } catch (error) {
6299
+ logger18.error("[Bootstrap] Error in message deleted handler:", error);
6300
+ }
6301
+ };
6302
+ var channelClearedHandler = async ({
6303
+ runtime,
6304
+ roomId,
6305
+ channelId,
6306
+ memoryCount
6307
+ }) => {
6308
+ try {
6309
+ logger18.info(
6310
+ `[Bootstrap] Clearing ${memoryCount} message memories from channel ${channelId} -> room ${roomId}`
6311
+ );
6312
+ const memories = await runtime.getMemoriesByRoomIds({
6313
+ tableName: "messages",
6314
+ roomIds: [roomId]
6315
+ });
6316
+ let deletedCount = 0;
6317
+ for (const memory of memories) {
6318
+ if (memory.id) {
6319
+ try {
6320
+ await runtime.deleteMemory(memory.id);
6321
+ deletedCount++;
6322
+ } catch (error) {
6323
+ logger18.warn(`[Bootstrap] Failed to delete message memory ${memory.id}:`, error);
6324
+ }
6325
+ }
6326
+ }
6327
+ logger18.info(
6328
+ `[Bootstrap] Successfully cleared ${deletedCount}/${memories.length} message memories from channel ${channelId}`
6329
+ );
6330
+ } catch (error) {
6331
+ logger18.error("[Bootstrap] Error in channel cleared handler:", error);
6332
+ }
6333
+ };
5825
6334
  var postGeneratedHandler = async ({
5826
6335
  runtime,
5827
6336
  callback,
@@ -5864,8 +6373,8 @@ var postGeneratedHandler = async ({
5864
6373
  "ENTITIES"
5865
6374
  ]);
5866
6375
  const entity = await runtime.getEntityById(runtime.agentId);
5867
- if (entity?.metadata?.twitter?.userName) {
5868
- state.values.twitterUserName = entity?.metadata?.twitter?.userName;
6376
+ if (entity?.metadata?.twitter?.userName || entity?.metadata?.userName) {
6377
+ state.values.twitterUserName = entity?.metadata?.twitter?.userName || entity?.metadata?.userName;
5869
6378
  }
5870
6379
  const prompt = composePromptFromState9({
5871
6380
  state,
@@ -5922,9 +6431,6 @@ var postGeneratedHandler = async ({
5922
6431
  let cleanedText2 = text.replace(/^['"](.*)['"]$/, "$1");
5923
6432
  cleanedText2 = cleanedText2.replaceAll(/\\n/g, "\n\n");
5924
6433
  cleanedText2 = cleanedText2.replace(/([^\n])\n([^\n])/g, "$1\n\n$2");
5925
- if (cleanedText2.length > 280) {
5926
- cleanedText2 = truncateToCompleteSentence(cleanedText2, 280);
5927
- }
5928
6434
  return cleanedText2;
5929
6435
  }
5930
6436
  const cleanedText = cleanupPostText(parsedXmlResponse.post || "");
@@ -5984,24 +6490,45 @@ var postGeneratedHandler = async ({
5984
6490
  var syncSingleUser = async (entityId, runtime, serverId, channelId, type, source) => {
5985
6491
  try {
5986
6492
  const entity = await runtime.getEntityById(entityId);
5987
- logger18.info(`[Bootstrap] Syncing user: ${entity?.metadata?.[source]?.username || entityId}`);
6493
+ logger18.info(`[Bootstrap] Syncing user: ${entity?.metadata?.username || entityId}`);
5988
6494
  if (!channelId) {
5989
6495
  logger18.warn(`[Bootstrap] Cannot sync user ${entity?.id} without a valid channelId`);
5990
6496
  return;
5991
6497
  }
5992
6498
  const roomId = createUniqueUuid3(runtime, channelId);
5993
6499
  const worldId = createUniqueUuid3(runtime, serverId);
6500
+ const worldMetadata = type === ChannelType9.DM ? {
6501
+ ownership: {
6502
+ ownerId: entityId
6503
+ },
6504
+ roles: {
6505
+ [entityId]: Role2.OWNER
6506
+ },
6507
+ settings: {}
6508
+ // Initialize empty settings for onboarding
6509
+ } : void 0;
6510
+ logger18.info(
6511
+ `[Bootstrap] syncSingleUser - type: ${type}, isDM: ${type === ChannelType9.DM}, worldMetadata: ${JSON.stringify(worldMetadata)}`
6512
+ );
5994
6513
  await runtime.ensureConnection({
5995
6514
  entityId,
5996
6515
  roomId,
5997
- userName: entity?.metadata?.[source].username || entityId,
5998
- name: entity?.metadata?.[source].name || entity?.metadata?.[source].username || `User${entityId}`,
6516
+ name: entity?.metadata?.name || entity?.metadata?.username || `User${entityId}`,
5999
6517
  source,
6000
6518
  channelId,
6001
6519
  serverId,
6002
6520
  type,
6003
- worldId
6521
+ worldId,
6522
+ metadata: worldMetadata
6004
6523
  });
6524
+ try {
6525
+ const createdWorld = await runtime.getWorld(worldId);
6526
+ logger18.info(
6527
+ `[Bootstrap] Created world check - ID: ${worldId}, metadata: ${JSON.stringify(createdWorld?.metadata)}`
6528
+ );
6529
+ } catch (error) {
6530
+ logger18.error(`[Bootstrap] Failed to verify created world: ${error}`);
6531
+ }
6005
6532
  logger18.success(`[Bootstrap] Successfully synced user: ${entity?.id}`);
6006
6533
  } catch (error) {
6007
6534
  logger18.error(
@@ -6112,6 +6639,24 @@ var events = {
6112
6639
  logger18.debug(`[Bootstrap] Message sent: ${payload.message.content.text}`);
6113
6640
  }
6114
6641
  ],
6642
+ [EventType.MESSAGE_DELETED]: [
6643
+ async (payload) => {
6644
+ await messageDeletedHandler({
6645
+ runtime: payload.runtime,
6646
+ message: payload.message
6647
+ });
6648
+ }
6649
+ ],
6650
+ [EventType.CHANNEL_CLEARED]: [
6651
+ async (payload) => {
6652
+ await channelClearedHandler({
6653
+ runtime: payload.runtime,
6654
+ roomId: payload.roomId,
6655
+ channelId: payload.channelId,
6656
+ memoryCount: payload.memoryCount
6657
+ });
6658
+ }
6659
+ ],
6115
6660
  [EventType.WORLD_JOINED]: [
6116
6661
  async (payload) => {
6117
6662
  await handleServerSync(payload);
@@ -6124,8 +6669,9 @@ var events = {
6124
6669
  ],
6125
6670
  [EventType.ENTITY_JOINED]: [
6126
6671
  async (payload) => {
6672
+ logger18.debug(`[Bootstrap] ENTITY_JOINED event received for entity ${payload.entityId}`);
6127
6673
  if (!payload.worldId) {
6128
- logger18.error("[Bootstrap] No callback provided for entity joined");
6674
+ logger18.error("[Bootstrap] No worldId provided for entity joined");
6129
6675
  return;
6130
6676
  }
6131
6677
  if (!payload.roomId) {