@elizaos/plugin-bootstrap 1.0.7 → 1.0.9
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 +124 -66
- package/dist/index.js.map +1 -1
- package/package.json +5 -6
package/dist/index.js
CHANGED
|
@@ -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";
|
|
@@ -1322,25 +1323,6 @@ Response format should be formatted in a valid JSON block like this:
|
|
|
1322
1323
|
\`\`\`
|
|
1323
1324
|
|
|
1324
1325
|
Your response should include the valid JSON block and nothing else.`;
|
|
1325
|
-
function getFirstAvailableField(obj, fields) {
|
|
1326
|
-
for (const field of fields) {
|
|
1327
|
-
if (typeof obj[field] === "string" && obj[field].trim() !== "") {
|
|
1328
|
-
return obj[field];
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
return null;
|
|
1332
|
-
}
|
|
1333
|
-
function extractReplyContent(response, replyFieldKeys) {
|
|
1334
|
-
const hasReplyAction = response.content.actions?.includes("REPLY");
|
|
1335
|
-
const text = getFirstAvailableField(response.content, replyFieldKeys);
|
|
1336
|
-
if (!hasReplyAction || !text) return null;
|
|
1337
|
-
return {
|
|
1338
|
-
...response.content,
|
|
1339
|
-
thought: response.content.thought,
|
|
1340
|
-
text,
|
|
1341
|
-
actions: ["REPLY"]
|
|
1342
|
-
};
|
|
1343
|
-
}
|
|
1344
1326
|
var replyAction = {
|
|
1345
1327
|
name: "REPLY",
|
|
1346
1328
|
similes: ["GREET", "REPLY_TO_MESSAGE", "SEND_REPLY", "RESPOND", "RESPONSE"],
|
|
@@ -1349,15 +1331,7 @@ var replyAction = {
|
|
|
1349
1331
|
return true;
|
|
1350
1332
|
},
|
|
1351
1333
|
handler: async (runtime, message, state, _options, callback, responses) => {
|
|
1352
|
-
const replyFieldKeys = ["message", "text"];
|
|
1353
|
-
const existingReplies = responses?.map((r) => extractReplyContent(r, replyFieldKeys)).filter((reply) => reply !== null) ?? [];
|
|
1354
1334
|
const allProviders = responses?.flatMap((res) => res.content?.providers ?? []) ?? [];
|
|
1355
|
-
if (existingReplies.length > 0 && allProviders.length === 0) {
|
|
1356
|
-
for (const reply of existingReplies) {
|
|
1357
|
-
await callback(reply);
|
|
1358
|
-
}
|
|
1359
|
-
return;
|
|
1360
|
-
}
|
|
1361
1335
|
state = await runtime.composeState(message, [...allProviders ?? [], "RECENT_MESSAGES"]);
|
|
1362
1336
|
const prompt = composePromptFromState3({
|
|
1363
1337
|
state,
|
|
@@ -1372,6 +1346,7 @@ var replyAction = {
|
|
|
1372
1346
|
actions: ["REPLY"]
|
|
1373
1347
|
};
|
|
1374
1348
|
await callback(responseContent);
|
|
1349
|
+
return true;
|
|
1375
1350
|
},
|
|
1376
1351
|
examples: [
|
|
1377
1352
|
[
|
|
@@ -3731,6 +3706,12 @@ var actionsProvider = {
|
|
|
3731
3706
|
const resolvedActions = await Promise.all(actionPromises);
|
|
3732
3707
|
const actionsData = resolvedActions.filter(Boolean);
|
|
3733
3708
|
const actionNames = `Possible response actions: ${formatActionNames(actionsData)}`;
|
|
3709
|
+
const actionsWithDescriptions = actionsData.length > 0 ? addHeader(
|
|
3710
|
+
"# Available Actions",
|
|
3711
|
+
actionsData.map(
|
|
3712
|
+
(action) => `- **${action.name}**: ${action.description || "No description available"}`
|
|
3713
|
+
).join("\n")
|
|
3714
|
+
) : "";
|
|
3734
3715
|
const actions = actionsData.length > 0 ? addHeader("# Available Actions", formatActions(actionsData)) : "";
|
|
3735
3716
|
const actionExamples = actionsData.length > 0 ? addHeader("# Action Examples", composeActionExamples(actionsData, 10)) : "";
|
|
3736
3717
|
const data = {
|
|
@@ -3739,9 +3720,10 @@ var actionsProvider = {
|
|
|
3739
3720
|
const values = {
|
|
3740
3721
|
actions,
|
|
3741
3722
|
actionNames,
|
|
3742
|
-
actionExamples
|
|
3723
|
+
actionExamples,
|
|
3724
|
+
actionsWithDescriptions
|
|
3743
3725
|
};
|
|
3744
|
-
const text = [actionNames, actionExamples, actions].filter(Boolean).join("\n\n");
|
|
3726
|
+
const text = [actionNames, actionsWithDescriptions, actionExamples, actions].filter(Boolean).join("\n\n");
|
|
3745
3727
|
return {
|
|
3746
3728
|
data,
|
|
3747
3729
|
values,
|
|
@@ -4495,7 +4477,7 @@ var recentMessagesProvider = {
|
|
|
4495
4477
|
if (isSelf) {
|
|
4496
4478
|
sender = runtime.character.name;
|
|
4497
4479
|
} else {
|
|
4498
|
-
sender = interactionEntityMap.get(message2.entityId)?.metadata?.
|
|
4480
|
+
sender = interactionEntityMap.get(message2.entityId)?.metadata?.userName || "unknown";
|
|
4499
4481
|
}
|
|
4500
4482
|
return `${sender}: ${message2.content.text}`;
|
|
4501
4483
|
});
|
|
@@ -4565,7 +4547,9 @@ var recentMessagesProvider = {
|
|
|
4565
4547
|
|
|
4566
4548
|
// src/providers/relationships.ts
|
|
4567
4549
|
async function formatRelationships(runtime, relationships) {
|
|
4568
|
-
const sortedRelationships = relationships.filter((rel) => rel.metadata?.interactions).sort(
|
|
4550
|
+
const sortedRelationships = relationships.filter((rel) => rel.metadata?.interactions).sort(
|
|
4551
|
+
(a2, b) => (b.metadata?.interactions || 0) - (a2.metadata?.interactions || 0)
|
|
4552
|
+
).slice(0, 30);
|
|
4569
4553
|
if (sortedRelationships.length === 0) {
|
|
4570
4554
|
return "";
|
|
4571
4555
|
}
|
|
@@ -4709,8 +4693,8 @@ var roleProvider = {
|
|
|
4709
4693
|
for (const entityId of Object.keys(roles)) {
|
|
4710
4694
|
const userRole = roles[entityId];
|
|
4711
4695
|
const user = await runtime.getEntityById(entityId);
|
|
4712
|
-
const name = user?.metadata?.
|
|
4713
|
-
const username = user?.metadata?.
|
|
4696
|
+
const name = user?.metadata?.name;
|
|
4697
|
+
const username = user?.metadata?.username;
|
|
4714
4698
|
const names = user?.names;
|
|
4715
4699
|
if (owners.some((owner) => owner.username === username) || admins.some((admin) => admin.username === username) || members.some((member) => member.username === username)) {
|
|
4716
4700
|
continue;
|
|
@@ -4900,7 +4884,16 @@ var settingsProvider = {
|
|
|
4900
4884
|
let serverId = void 0;
|
|
4901
4885
|
let worldSettings = null;
|
|
4902
4886
|
if (isOnboarding) {
|
|
4903
|
-
world = userWorlds?.find((world2) => world2.metadata?.settings);
|
|
4887
|
+
world = userWorlds?.find((world2) => world2.metadata?.settings !== void 0);
|
|
4888
|
+
if (!world && userWorlds && userWorlds.length > 0) {
|
|
4889
|
+
world = userWorlds[0];
|
|
4890
|
+
if (!world.metadata) {
|
|
4891
|
+
world.metadata = {};
|
|
4892
|
+
}
|
|
4893
|
+
world.metadata.settings = {};
|
|
4894
|
+
await runtime.updateWorld(world);
|
|
4895
|
+
logger15.info(`Initialized settings for user's world ${world.id}`);
|
|
4896
|
+
}
|
|
4904
4897
|
if (!world) {
|
|
4905
4898
|
logger15.error("No world found for user during onboarding");
|
|
4906
4899
|
throw new Error("No server ownership found for onboarding");
|
|
@@ -5528,7 +5521,7 @@ var messageReceivedHandler = async ({
|
|
|
5528
5521
|
throw new Error("Agent responses map not found");
|
|
5529
5522
|
}
|
|
5530
5523
|
agentResponses.set(message.roomId, responseId);
|
|
5531
|
-
const runId =
|
|
5524
|
+
const runId = runtime.startRun();
|
|
5532
5525
|
const startTime = Date.now();
|
|
5533
5526
|
await runtime.emitEvent(EventType.RUN_STARTED, {
|
|
5534
5527
|
runtime,
|
|
@@ -5703,27 +5696,7 @@ ${response}`
|
|
|
5703
5696
|
}
|
|
5704
5697
|
await callback(responseContent);
|
|
5705
5698
|
} else {
|
|
5706
|
-
await runtime.processActions(
|
|
5707
|
-
message,
|
|
5708
|
-
responseMessages,
|
|
5709
|
-
state,
|
|
5710
|
-
async (memory) => {
|
|
5711
|
-
return [];
|
|
5712
|
-
}
|
|
5713
|
-
);
|
|
5714
|
-
if (responseMessages.length) {
|
|
5715
|
-
for (const responseMessage of responseMessages) {
|
|
5716
|
-
if (responseMessage.content.providers && responseMessage.content.providers.length > 0) {
|
|
5717
|
-
logger18.debug(
|
|
5718
|
-
"[Bootstrap] Complex response used providers",
|
|
5719
|
-
responseMessage.content.providers
|
|
5720
|
-
);
|
|
5721
|
-
}
|
|
5722
|
-
}
|
|
5723
|
-
for (const memory of responseMessages) {
|
|
5724
|
-
await callback(memory.content);
|
|
5725
|
-
}
|
|
5726
|
-
}
|
|
5699
|
+
await runtime.processActions(message, responseMessages, state, callback);
|
|
5727
5700
|
}
|
|
5728
5701
|
await runtime.evaluate(
|
|
5729
5702
|
message,
|
|
@@ -5822,6 +5795,54 @@ var reactionReceivedHandler = async ({
|
|
|
5822
5795
|
logger18.error("[Bootstrap] Error in reaction handler:", error);
|
|
5823
5796
|
}
|
|
5824
5797
|
};
|
|
5798
|
+
var messageDeletedHandler = async ({
|
|
5799
|
+
runtime,
|
|
5800
|
+
message
|
|
5801
|
+
}) => {
|
|
5802
|
+
try {
|
|
5803
|
+
if (!message.id) {
|
|
5804
|
+
logger18.error("[Bootstrap] Cannot delete memory: message ID is missing");
|
|
5805
|
+
return;
|
|
5806
|
+
}
|
|
5807
|
+
logger18.info("[Bootstrap] Deleting memory for message", message.id, "from room", message.roomId);
|
|
5808
|
+
await runtime.deleteMemory(message.id);
|
|
5809
|
+
logger18.debug("[Bootstrap] Successfully deleted memory for message", message.id);
|
|
5810
|
+
} catch (error) {
|
|
5811
|
+
logger18.error("[Bootstrap] Error in message deleted handler:", error);
|
|
5812
|
+
}
|
|
5813
|
+
};
|
|
5814
|
+
var channelClearedHandler = async ({
|
|
5815
|
+
runtime,
|
|
5816
|
+
roomId,
|
|
5817
|
+
channelId,
|
|
5818
|
+
memoryCount
|
|
5819
|
+
}) => {
|
|
5820
|
+
try {
|
|
5821
|
+
logger18.info(
|
|
5822
|
+
`[Bootstrap] Clearing ${memoryCount} message memories from channel ${channelId} -> room ${roomId}`
|
|
5823
|
+
);
|
|
5824
|
+
const memories = await runtime.getMemoriesByRoomIds({
|
|
5825
|
+
tableName: "messages",
|
|
5826
|
+
roomIds: [roomId]
|
|
5827
|
+
});
|
|
5828
|
+
let deletedCount = 0;
|
|
5829
|
+
for (const memory of memories) {
|
|
5830
|
+
if (memory.id) {
|
|
5831
|
+
try {
|
|
5832
|
+
await runtime.deleteMemory(memory.id);
|
|
5833
|
+
deletedCount++;
|
|
5834
|
+
} catch (error) {
|
|
5835
|
+
logger18.warn(`[Bootstrap] Failed to delete message memory ${memory.id}:`, error);
|
|
5836
|
+
}
|
|
5837
|
+
}
|
|
5838
|
+
}
|
|
5839
|
+
logger18.info(
|
|
5840
|
+
`[Bootstrap] Successfully cleared ${deletedCount}/${memories.length} message memories from channel ${channelId}`
|
|
5841
|
+
);
|
|
5842
|
+
} catch (error) {
|
|
5843
|
+
logger18.error("[Bootstrap] Error in channel cleared handler:", error);
|
|
5844
|
+
}
|
|
5845
|
+
};
|
|
5825
5846
|
var postGeneratedHandler = async ({
|
|
5826
5847
|
runtime,
|
|
5827
5848
|
callback,
|
|
@@ -5864,8 +5885,8 @@ var postGeneratedHandler = async ({
|
|
|
5864
5885
|
"ENTITIES"
|
|
5865
5886
|
]);
|
|
5866
5887
|
const entity = await runtime.getEntityById(runtime.agentId);
|
|
5867
|
-
if (entity?.metadata?.twitter?.userName) {
|
|
5868
|
-
state.values.twitterUserName = entity?.metadata?.twitter?.userName;
|
|
5888
|
+
if (entity?.metadata?.twitter?.userName || entity?.metadata?.userName) {
|
|
5889
|
+
state.values.twitterUserName = entity?.metadata?.twitter?.userName || entity?.metadata?.userName;
|
|
5869
5890
|
}
|
|
5870
5891
|
const prompt = composePromptFromState9({
|
|
5871
5892
|
state,
|
|
@@ -5922,9 +5943,6 @@ var postGeneratedHandler = async ({
|
|
|
5922
5943
|
let cleanedText2 = text.replace(/^['"](.*)['"]$/, "$1");
|
|
5923
5944
|
cleanedText2 = cleanedText2.replaceAll(/\\n/g, "\n\n");
|
|
5924
5945
|
cleanedText2 = cleanedText2.replace(/([^\n])\n([^\n])/g, "$1\n\n$2");
|
|
5925
|
-
if (cleanedText2.length > 280) {
|
|
5926
|
-
cleanedText2 = truncateToCompleteSentence(cleanedText2, 280);
|
|
5927
|
-
}
|
|
5928
5946
|
return cleanedText2;
|
|
5929
5947
|
}
|
|
5930
5948
|
const cleanedText = cleanupPostText(parsedXmlResponse.post || "");
|
|
@@ -5984,24 +6002,45 @@ var postGeneratedHandler = async ({
|
|
|
5984
6002
|
var syncSingleUser = async (entityId, runtime, serverId, channelId, type, source) => {
|
|
5985
6003
|
try {
|
|
5986
6004
|
const entity = await runtime.getEntityById(entityId);
|
|
5987
|
-
logger18.info(`[Bootstrap] Syncing user: ${entity?.metadata?.
|
|
6005
|
+
logger18.info(`[Bootstrap] Syncing user: ${entity?.metadata?.username || entityId}`);
|
|
5988
6006
|
if (!channelId) {
|
|
5989
6007
|
logger18.warn(`[Bootstrap] Cannot sync user ${entity?.id} without a valid channelId`);
|
|
5990
6008
|
return;
|
|
5991
6009
|
}
|
|
5992
6010
|
const roomId = createUniqueUuid3(runtime, channelId);
|
|
5993
6011
|
const worldId = createUniqueUuid3(runtime, serverId);
|
|
6012
|
+
const worldMetadata = type === ChannelType9.DM ? {
|
|
6013
|
+
ownership: {
|
|
6014
|
+
ownerId: entityId
|
|
6015
|
+
},
|
|
6016
|
+
roles: {
|
|
6017
|
+
[entityId]: Role2.OWNER
|
|
6018
|
+
},
|
|
6019
|
+
settings: {}
|
|
6020
|
+
// Initialize empty settings for onboarding
|
|
6021
|
+
} : void 0;
|
|
6022
|
+
logger18.info(
|
|
6023
|
+
`[Bootstrap] syncSingleUser - type: ${type}, isDM: ${type === ChannelType9.DM}, worldMetadata: ${JSON.stringify(worldMetadata)}`
|
|
6024
|
+
);
|
|
5994
6025
|
await runtime.ensureConnection({
|
|
5995
6026
|
entityId,
|
|
5996
6027
|
roomId,
|
|
5997
|
-
|
|
5998
|
-
name: entity?.metadata?.[source].name || entity?.metadata?.[source].username || `User${entityId}`,
|
|
6028
|
+
name: entity?.metadata?.name || entity?.metadata?.username || `User${entityId}`,
|
|
5999
6029
|
source,
|
|
6000
6030
|
channelId,
|
|
6001
6031
|
serverId,
|
|
6002
6032
|
type,
|
|
6003
|
-
worldId
|
|
6033
|
+
worldId,
|
|
6034
|
+
metadata: worldMetadata
|
|
6004
6035
|
});
|
|
6036
|
+
try {
|
|
6037
|
+
const createdWorld = await runtime.getWorld(worldId);
|
|
6038
|
+
logger18.info(
|
|
6039
|
+
`[Bootstrap] Created world check - ID: ${worldId}, metadata: ${JSON.stringify(createdWorld?.metadata)}`
|
|
6040
|
+
);
|
|
6041
|
+
} catch (error) {
|
|
6042
|
+
logger18.error(`[Bootstrap] Failed to verify created world: ${error}`);
|
|
6043
|
+
}
|
|
6005
6044
|
logger18.success(`[Bootstrap] Successfully synced user: ${entity?.id}`);
|
|
6006
6045
|
} catch (error) {
|
|
6007
6046
|
logger18.error(
|
|
@@ -6112,6 +6151,24 @@ var events = {
|
|
|
6112
6151
|
logger18.debug(`[Bootstrap] Message sent: ${payload.message.content.text}`);
|
|
6113
6152
|
}
|
|
6114
6153
|
],
|
|
6154
|
+
[EventType.MESSAGE_DELETED]: [
|
|
6155
|
+
async (payload) => {
|
|
6156
|
+
await messageDeletedHandler({
|
|
6157
|
+
runtime: payload.runtime,
|
|
6158
|
+
message: payload.message
|
|
6159
|
+
});
|
|
6160
|
+
}
|
|
6161
|
+
],
|
|
6162
|
+
[EventType.CHANNEL_CLEARED]: [
|
|
6163
|
+
async (payload) => {
|
|
6164
|
+
await channelClearedHandler({
|
|
6165
|
+
runtime: payload.runtime,
|
|
6166
|
+
roomId: payload.roomId,
|
|
6167
|
+
channelId: payload.channelId,
|
|
6168
|
+
memoryCount: payload.memoryCount
|
|
6169
|
+
});
|
|
6170
|
+
}
|
|
6171
|
+
],
|
|
6115
6172
|
[EventType.WORLD_JOINED]: [
|
|
6116
6173
|
async (payload) => {
|
|
6117
6174
|
await handleServerSync(payload);
|
|
@@ -6124,8 +6181,9 @@ var events = {
|
|
|
6124
6181
|
],
|
|
6125
6182
|
[EventType.ENTITY_JOINED]: [
|
|
6126
6183
|
async (payload) => {
|
|
6184
|
+
logger18.debug(`[Bootstrap] ENTITY_JOINED event received for entity ${payload.entityId}`);
|
|
6127
6185
|
if (!payload.worldId) {
|
|
6128
|
-
logger18.error("[Bootstrap] No
|
|
6186
|
+
logger18.error("[Bootstrap] No worldId provided for entity joined");
|
|
6129
6187
|
return;
|
|
6130
6188
|
}
|
|
6131
6189
|
if (!payload.roomId) {
|