@elizaos/plugin-discord 2.0.0-alpha.10 → 2.0.0-alpha.11
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/compat.d.ts +3 -3
- package/dist/compat.d.ts.map +1 -1
- package/dist/identity.d.ts +4 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/index.js +157 -126
- package/dist/index.js.map +9 -8
- package/dist/messages.d.ts.map +1 -1
- package/dist/messaging.d.ts.map +1 -1
- package/dist/service.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -4,15 +4,29 @@ var __getProtoOf = Object.getPrototypeOf;
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
7
12
|
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
8
20
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
21
|
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
22
|
for (let key of __getOwnPropNames(mod))
|
|
11
23
|
if (!__hasOwnProp.call(to, key))
|
|
12
24
|
__defProp(to, key, {
|
|
13
|
-
get: (
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
14
26
|
enumerable: true
|
|
15
27
|
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
16
30
|
return to;
|
|
17
31
|
};
|
|
18
32
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
@@ -6456,8 +6470,8 @@ ${attachment.text}
|
|
|
6456
6470
|
}).join(`
|
|
6457
6471
|
`) || "";
|
|
6458
6472
|
const entity = actorMap.get(memory.entityId);
|
|
6459
|
-
const entityName = entity?.name ?? "Unknown User";
|
|
6460
|
-
const entityUsername =
|
|
6473
|
+
const entityName = entity?.name ?? entity?.names?.[0] ?? "Unknown User";
|
|
6474
|
+
const entityUsername = "";
|
|
6461
6475
|
return `${entityName} (${entityUsername}): ${memory.content.text}
|
|
6462
6476
|
${attachments}`;
|
|
6463
6477
|
}).join(`
|
|
@@ -7563,10 +7577,9 @@ var voiceStateProvider = {
|
|
|
7563
7577
|
// service.ts
|
|
7564
7578
|
import {
|
|
7565
7579
|
ChannelType as ChannelType7,
|
|
7566
|
-
createUniqueUuid as
|
|
7580
|
+
createUniqueUuid as createUniqueUuid6,
|
|
7567
7581
|
EventType as EventType3,
|
|
7568
7582
|
MemoryType as MemoryType7,
|
|
7569
|
-
Role,
|
|
7570
7583
|
Service,
|
|
7571
7584
|
stringToUuid as stringToUuid3
|
|
7572
7585
|
} from "@elizaos/core";
|
|
@@ -7672,11 +7685,66 @@ function getDiscordSettings(runtime) {
|
|
|
7672
7685
|
};
|
|
7673
7686
|
}
|
|
7674
7687
|
|
|
7688
|
+
// identity.ts
|
|
7689
|
+
import {
|
|
7690
|
+
createUniqueUuid as createUniqueUuid3,
|
|
7691
|
+
Role
|
|
7692
|
+
} from "@elizaos/core";
|
|
7693
|
+
var CANONICAL_OWNER_SETTING_KEY = "MILADY_ADMIN_ENTITY_ID";
|
|
7694
|
+
function getCanonicalOwnerId(runtime) {
|
|
7695
|
+
const value = runtime.getSetting?.(CANONICAL_OWNER_SETTING_KEY);
|
|
7696
|
+
if (typeof value !== "string") {
|
|
7697
|
+
return;
|
|
7698
|
+
}
|
|
7699
|
+
const trimmed = value.trim();
|
|
7700
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
7701
|
+
}
|
|
7702
|
+
function buildDiscordWorldMetadata(runtime, guildOwnerId) {
|
|
7703
|
+
const ownerId = getCanonicalOwnerId(runtime);
|
|
7704
|
+
if (ownerId) {
|
|
7705
|
+
return {
|
|
7706
|
+
ownership: { ownerId },
|
|
7707
|
+
roles: {
|
|
7708
|
+
[ownerId]: Role.OWNER
|
|
7709
|
+
}
|
|
7710
|
+
};
|
|
7711
|
+
}
|
|
7712
|
+
if (!guildOwnerId) {
|
|
7713
|
+
return;
|
|
7714
|
+
}
|
|
7715
|
+
const discordOwnerId = createUniqueUuid3(runtime, guildOwnerId);
|
|
7716
|
+
return {
|
|
7717
|
+
ownership: { ownerId: discordOwnerId },
|
|
7718
|
+
roles: {
|
|
7719
|
+
[discordOwnerId]: Role.OWNER
|
|
7720
|
+
}
|
|
7721
|
+
};
|
|
7722
|
+
}
|
|
7723
|
+
function buildDiscordEntityMetadata(userId, userName, name, globalName) {
|
|
7724
|
+
return {
|
|
7725
|
+
default: {
|
|
7726
|
+
username: userName,
|
|
7727
|
+
name
|
|
7728
|
+
},
|
|
7729
|
+
discord: {
|
|
7730
|
+
id: userId,
|
|
7731
|
+
userId,
|
|
7732
|
+
userName,
|
|
7733
|
+
username: userName,
|
|
7734
|
+
name,
|
|
7735
|
+
...typeof globalName === "string" && globalName.length > 0 ? { globalName } : {}
|
|
7736
|
+
},
|
|
7737
|
+
originalId: userId,
|
|
7738
|
+
username: userName,
|
|
7739
|
+
displayName: name
|
|
7740
|
+
};
|
|
7741
|
+
}
|
|
7742
|
+
|
|
7675
7743
|
// messages.ts
|
|
7676
7744
|
import {
|
|
7677
7745
|
ChannelType as ChannelType5,
|
|
7678
7746
|
checkPairingAllowed,
|
|
7679
|
-
createUniqueUuid as
|
|
7747
|
+
createUniqueUuid as createUniqueUuid4,
|
|
7680
7748
|
EventType,
|
|
7681
7749
|
isInAllowlist,
|
|
7682
7750
|
ServiceType as ServiceType4,
|
|
@@ -8605,8 +8673,18 @@ class MessageManager {
|
|
|
8605
8673
|
}
|
|
8606
8674
|
const isBotMentioned = !!(clientUser?.id && message.mentions.users && message.mentions.users.has(clientUser.id));
|
|
8607
8675
|
const isReplyToBot = !!message.reference?.messageId && message.mentions.repliedUser?.id === clientUser?.id;
|
|
8676
|
+
const mentionedOtherUsers = message.mentions.users ? Array.from(message.mentions.users.values()).some((user) => user.id !== clientUser?.id && user.id !== message.author.id) : false;
|
|
8677
|
+
const isReplyToOtherUser = !!message.reference?.messageId && !!message.mentions.repliedUser?.id && message.mentions.repliedUser.id !== clientUser?.id && message.mentions.repliedUser.id !== message.author.id;
|
|
8608
8678
|
const isInThread = message.channel.isThread();
|
|
8609
8679
|
const isDM = message.channel.type === DiscordChannelType3.DM;
|
|
8680
|
+
if (!isDM && (mentionedOtherUsers || isReplyToOtherUser)) {
|
|
8681
|
+
this.runtime.logger.debug({
|
|
8682
|
+
src: "plugin:discord",
|
|
8683
|
+
agentId: this.runtime.agentId,
|
|
8684
|
+
channelId: message.channel.id
|
|
8685
|
+
}, "Ignoring message that targets another mentioned user");
|
|
8686
|
+
return;
|
|
8687
|
+
}
|
|
8610
8688
|
if (this.discordSettings.shouldRespondOnlyToMentions) {
|
|
8611
8689
|
const shouldProcess = isDM || isBotMentioned || isReplyToBot;
|
|
8612
8690
|
if (!shouldProcess) {
|
|
@@ -8623,11 +8701,11 @@ class MessageManager {
|
|
|
8623
8701
|
channelId: message.channel.id
|
|
8624
8702
|
}, "Strict mode: processing message");
|
|
8625
8703
|
}
|
|
8626
|
-
const entityId =
|
|
8704
|
+
const entityId = createUniqueUuid4(this.runtime, message.author.id);
|
|
8627
8705
|
const userName = message.author.bot ? `${message.author.username}#${message.author.discriminator}` : message.author.username;
|
|
8628
8706
|
const name = message.author.displayName;
|
|
8629
8707
|
const channelId = message.channel.id;
|
|
8630
|
-
const roomId =
|
|
8708
|
+
const roomId = createUniqueUuid4(this.runtime, channelId);
|
|
8631
8709
|
let type;
|
|
8632
8710
|
let messageServerId;
|
|
8633
8711
|
if (message.guild) {
|
|
@@ -8654,8 +8732,10 @@ class MessageManager {
|
|
|
8654
8732
|
channelId: message.channel.id,
|
|
8655
8733
|
messageServerId: messageServerId ? stringToUuid(messageServerId) : undefined,
|
|
8656
8734
|
type,
|
|
8657
|
-
worldId:
|
|
8658
|
-
worldName: message.guild?.name
|
|
8735
|
+
worldId: createUniqueUuid4(this.runtime, messageServerId ?? roomId),
|
|
8736
|
+
worldName: message.guild?.name,
|
|
8737
|
+
userId: message.author.id,
|
|
8738
|
+
metadata: buildDiscordWorldMetadata(this.runtime, message.guild?.ownerId ?? undefined)
|
|
8659
8739
|
});
|
|
8660
8740
|
try {
|
|
8661
8741
|
const canSendResult = canSendMessage(message.channel);
|
|
@@ -8729,7 +8809,7 @@ class MessageManager {
|
|
|
8729
8809
|
typingData.interval = setInterval(startTyping, 8000);
|
|
8730
8810
|
}
|
|
8731
8811
|
if (message.id && !content.inReplyTo) {
|
|
8732
|
-
content.inReplyTo =
|
|
8812
|
+
content.inReplyTo = createUniqueUuid4(this.runtime, message.id);
|
|
8733
8813
|
}
|
|
8734
8814
|
let messages = [];
|
|
8735
8815
|
if (content && content.channelType === "DM") {
|
|
@@ -8783,7 +8863,7 @@ class MessageManager {
|
|
|
8783
8863
|
const actions = content.actions;
|
|
8784
8864
|
const hasAttachments = m.attachments?.size > 0;
|
|
8785
8865
|
const memory = {
|
|
8786
|
-
id:
|
|
8866
|
+
id: createUniqueUuid4(this.runtime, m.id),
|
|
8787
8867
|
entityId: this.runtime.agentId,
|
|
8788
8868
|
agentId: this.runtime.agentId,
|
|
8789
8869
|
content: {
|
|
@@ -8873,18 +8953,18 @@ Embed #${parseInt(i, 10) + 1}:
|
|
|
8873
8953
|
if (message.reference) {
|
|
8874
8954
|
let messageId;
|
|
8875
8955
|
if (message.reference.messageId) {
|
|
8876
|
-
messageId =
|
|
8956
|
+
messageId = createUniqueUuid4(this.runtime, message.reference.messageId);
|
|
8877
8957
|
} else {
|
|
8878
8958
|
try {
|
|
8879
8959
|
const refMsg = await message.fetchReference();
|
|
8880
|
-
messageId =
|
|
8960
|
+
messageId = createUniqueUuid4(this.runtime, refMsg.id);
|
|
8881
8961
|
} catch {}
|
|
8882
8962
|
}
|
|
8883
8963
|
if (messageId) {
|
|
8884
8964
|
processedContent += `
|
|
8885
8965
|
Referencing MessageID ${messageId} (discord: ${message.reference.messageId})`;
|
|
8886
8966
|
if (message.reference.channelId !== message.channel.id) {
|
|
8887
|
-
const roomId =
|
|
8967
|
+
const roomId = createUniqueUuid4(this.runtime, message.reference.channelId);
|
|
8888
8968
|
processedContent += ` in channel ${roomId}`;
|
|
8889
8969
|
}
|
|
8890
8970
|
if (message.reference.guildId && message.guild && message.reference.guildId !== message.guild.id) {
|
|
@@ -9126,7 +9206,7 @@ import {
|
|
|
9126
9206
|
} from "@discordjs/voice";
|
|
9127
9207
|
import {
|
|
9128
9208
|
ChannelType as ChannelType6,
|
|
9129
|
-
createUniqueUuid as
|
|
9209
|
+
createUniqueUuid as createUniqueUuid5,
|
|
9130
9210
|
EventType as EventType2,
|
|
9131
9211
|
logger as logger3,
|
|
9132
9212
|
ModelType as ModelType20,
|
|
@@ -9759,8 +9839,8 @@ class VoiceManager extends EventEmitter {
|
|
|
9759
9839
|
if (!message || message.trim() === "" || message.length < 3) {
|
|
9760
9840
|
return { text: "", actions: ["IGNORE"] };
|
|
9761
9841
|
}
|
|
9762
|
-
const roomId =
|
|
9763
|
-
const uniqueEntityId =
|
|
9842
|
+
const roomId = createUniqueUuid5(this.runtime, channelId);
|
|
9843
|
+
const uniqueEntityId = createUniqueUuid5(this.runtime, entityId);
|
|
9764
9844
|
const type = await this.getChannelType(channel);
|
|
9765
9845
|
await this.runtime.ensureConnection({
|
|
9766
9846
|
entityId: uniqueEntityId,
|
|
@@ -9771,11 +9851,11 @@ class VoiceManager extends EventEmitter {
|
|
|
9771
9851
|
channelId,
|
|
9772
9852
|
messageServerId: stringToUuid2(channel.guild.id),
|
|
9773
9853
|
type,
|
|
9774
|
-
worldId:
|
|
9854
|
+
worldId: createUniqueUuid5(this.runtime, channel.guild.id),
|
|
9775
9855
|
worldName: channel.guild.name
|
|
9776
9856
|
});
|
|
9777
9857
|
const memory = {
|
|
9778
|
-
id:
|
|
9858
|
+
id: createUniqueUuid5(this.runtime, `${channelId}-voice-message-${Date.now()}`),
|
|
9779
9859
|
agentId: this.runtime.agentId,
|
|
9780
9860
|
entityId: uniqueEntityId,
|
|
9781
9861
|
roomId,
|
|
@@ -9793,7 +9873,7 @@ class VoiceManager extends EventEmitter {
|
|
|
9793
9873
|
const callback = async (content, _actionName) => {
|
|
9794
9874
|
try {
|
|
9795
9875
|
const responseMemory = {
|
|
9796
|
-
id:
|
|
9876
|
+
id: createUniqueUuid5(this.runtime, `${memory.id}-voice-response-${Date.now()}`),
|
|
9797
9877
|
entityId: this.runtime.agentId,
|
|
9798
9878
|
agentId: this.runtime.agentId,
|
|
9799
9879
|
content: {
|
|
@@ -10154,7 +10234,7 @@ class DiscordService extends Service {
|
|
|
10154
10234
|
}
|
|
10155
10235
|
}
|
|
10156
10236
|
const sentMessages = [];
|
|
10157
|
-
const roomId =
|
|
10237
|
+
const roomId = createUniqueUuid6(runtime, targetChannel.id);
|
|
10158
10238
|
const channelType = await this.getChannelType(targetChannel);
|
|
10159
10239
|
if (content.text || files.length > 0) {
|
|
10160
10240
|
if (content.text) {
|
|
@@ -10187,7 +10267,7 @@ class DiscordService extends Service {
|
|
|
10187
10267
|
}
|
|
10188
10268
|
const targetChannelGuild = "guild" in targetChannel ? targetChannel.guild : null;
|
|
10189
10269
|
const serverId = targetChannelGuild?.id ? targetChannelGuild.id : targetChannel.id;
|
|
10190
|
-
const worldId =
|
|
10270
|
+
const worldId = createUniqueUuid6(runtime, serverId);
|
|
10191
10271
|
const worldName = targetChannelGuild?.name ? targetChannelGuild.name : undefined;
|
|
10192
10272
|
const clientUser = client.user;
|
|
10193
10273
|
await this.runtime.ensureConnection({
|
|
@@ -10206,7 +10286,7 @@ class DiscordService extends Service {
|
|
|
10206
10286
|
try {
|
|
10207
10287
|
const hasAttachments = sentMsg.attachments.size > 0;
|
|
10208
10288
|
const memory = {
|
|
10209
|
-
id:
|
|
10289
|
+
id: createUniqueUuid6(runtime, sentMsg.id),
|
|
10210
10290
|
entityId: runtime.agentId,
|
|
10211
10291
|
agentId: runtime.agentId,
|
|
10212
10292
|
roomId,
|
|
@@ -10705,8 +10785,8 @@ class DiscordService extends Service {
|
|
|
10705
10785
|
this.runtime.logger.info(`New member joined: ${member.user.username} (${member.id})`);
|
|
10706
10786
|
const guild = member.guild;
|
|
10707
10787
|
const tag = member.user.bot ? `${member.user.username}#${member.user.discriminator}` : member.user.username;
|
|
10708
|
-
const worldId =
|
|
10709
|
-
const entityId =
|
|
10788
|
+
const worldId = createUniqueUuid6(this.runtime, guild.id);
|
|
10789
|
+
const entityId = createUniqueUuid6(this.runtime, member.id);
|
|
10710
10790
|
this.runtime.emitEvent(["DISCORD_USER_JOINED" /* ENTITY_JOINED */], {
|
|
10711
10791
|
runtime: this.runtime,
|
|
10712
10792
|
entityId,
|
|
@@ -11006,8 +11086,7 @@ class DiscordService extends Service {
|
|
|
11006
11086
|
}, "Failed to register commands to newly joined guild");
|
|
11007
11087
|
}
|
|
11008
11088
|
}
|
|
11009
|
-
const
|
|
11010
|
-
const worldId = createUniqueUuid5(this.runtime, fullGuild.id);
|
|
11089
|
+
const worldId = createUniqueUuid6(this.runtime, fullGuild.id);
|
|
11011
11090
|
const standardizedData = {
|
|
11012
11091
|
runtime: this.runtime,
|
|
11013
11092
|
rooms: await this.buildStandardizedRooms(fullGuild, worldId),
|
|
@@ -11018,10 +11097,7 @@ class DiscordService extends Service {
|
|
|
11018
11097
|
agentId: this.runtime.agentId,
|
|
11019
11098
|
serverId: fullGuild.id,
|
|
11020
11099
|
metadata: {
|
|
11021
|
-
|
|
11022
|
-
roles: {
|
|
11023
|
-
[ownerId]: Role.OWNER
|
|
11024
|
-
}
|
|
11100
|
+
...buildDiscordWorldMetadata(this.runtime, fullGuild.ownerId)
|
|
11025
11101
|
}
|
|
11026
11102
|
},
|
|
11027
11103
|
source: "discord"
|
|
@@ -11037,11 +11113,11 @@ class DiscordService extends Service {
|
|
|
11037
11113
|
this.runtime.emitEvent([EventType3.WORLD_JOINED], standardizedData);
|
|
11038
11114
|
}
|
|
11039
11115
|
async handleInteractionCreate(interaction) {
|
|
11040
|
-
const entityId =
|
|
11116
|
+
const entityId = createUniqueUuid6(this.runtime, interaction.user.id);
|
|
11041
11117
|
const userName = interaction.user.bot ? `${interaction.user.username}#${interaction.user.discriminator}` : interaction.user.username;
|
|
11042
11118
|
const name = interaction.user.displayName;
|
|
11043
11119
|
const interactionChannelId = interaction.channel?.id;
|
|
11044
|
-
const roomId =
|
|
11120
|
+
const roomId = createUniqueUuid6(this.runtime, interactionChannelId || userName);
|
|
11045
11121
|
let type;
|
|
11046
11122
|
let serverId;
|
|
11047
11123
|
if (interaction.guild) {
|
|
@@ -11068,8 +11144,10 @@ class DiscordService extends Service {
|
|
|
11068
11144
|
channelId: interactionChannelId,
|
|
11069
11145
|
messageServerId: serverId ? stringToUuid3(serverId) : undefined,
|
|
11070
11146
|
type,
|
|
11071
|
-
worldId:
|
|
11072
|
-
worldName: interaction.guild?.name || undefined
|
|
11147
|
+
worldId: createUniqueUuid6(this.runtime, serverId ?? roomId),
|
|
11148
|
+
worldName: interaction.guild?.name || undefined,
|
|
11149
|
+
userId: interaction.user.id,
|
|
11150
|
+
metadata: buildDiscordWorldMetadata(this.runtime, interaction.guild?.ownerId)
|
|
11073
11151
|
});
|
|
11074
11152
|
if (interaction.isCommand()) {
|
|
11075
11153
|
this.runtime.logger.debug({
|
|
@@ -11256,7 +11334,7 @@ class DiscordService extends Service {
|
|
|
11256
11334
|
const rooms = [];
|
|
11257
11335
|
for (const [channelId, channel] of guild.channels.cache) {
|
|
11258
11336
|
if (channel.type === DiscordChannelType5.GuildText || channel.type === DiscordChannelType5.GuildVoice) {
|
|
11259
|
-
const roomId =
|
|
11337
|
+
const roomId = createUniqueUuid6(this.runtime, channelId);
|
|
11260
11338
|
let channelType;
|
|
11261
11339
|
switch (channel.type) {
|
|
11262
11340
|
case DiscordChannelType5.GuildText:
|
|
@@ -11271,7 +11349,7 @@ class DiscordService extends Service {
|
|
|
11271
11349
|
let participants = [];
|
|
11272
11350
|
if (guild.memberCount < 1000 && channel.type === DiscordChannelType5.GuildText) {
|
|
11273
11351
|
try {
|
|
11274
|
-
participants = Array.from(guild.members.cache.values()).filter((member) => channel.permissionsFor(member)?.has(PermissionsBitField5.Flags.ViewChannel)).map((member) =>
|
|
11352
|
+
participants = Array.from(guild.members.cache.values()).filter((member) => channel.permissionsFor(member)?.has(PermissionsBitField5.Flags.ViewChannel)).map((member) => createUniqueUuid6(this.runtime, member.id));
|
|
11275
11353
|
} catch (error) {
|
|
11276
11354
|
this.runtime.logger.warn({
|
|
11277
11355
|
src: "plugin:discord",
|
|
@@ -11312,29 +11390,14 @@ class DiscordService extends Service {
|
|
|
11312
11390
|
const tag = member.user.bot ? `${member.user.username}#${member.user.discriminator}` : member.user.username;
|
|
11313
11391
|
if (member.id !== botId) {
|
|
11314
11392
|
entities.push({
|
|
11315
|
-
id:
|
|
11393
|
+
id: createUniqueUuid6(this.runtime, member.id),
|
|
11316
11394
|
names: Array.from(new Set([
|
|
11317
11395
|
member.user.username,
|
|
11318
11396
|
member.displayName,
|
|
11319
11397
|
member.user.globalName
|
|
11320
11398
|
].filter(Boolean))),
|
|
11321
11399
|
agentId: this.runtime.agentId,
|
|
11322
|
-
metadata:
|
|
11323
|
-
default: {
|
|
11324
|
-
username: tag,
|
|
11325
|
-
name: member.displayName || member.user.username
|
|
11326
|
-
},
|
|
11327
|
-
discord: member.user.globalName ? {
|
|
11328
|
-
username: tag,
|
|
11329
|
-
name: member.displayName || member.user.username,
|
|
11330
|
-
globalName: member.user.globalName,
|
|
11331
|
-
userId: member.id
|
|
11332
|
-
} : {
|
|
11333
|
-
username: tag,
|
|
11334
|
-
name: member.displayName || member.user.username,
|
|
11335
|
-
userId: member.id
|
|
11336
|
-
}
|
|
11337
|
-
}
|
|
11400
|
+
metadata: buildDiscordEntityMetadata(member.id, tag, member.displayName || member.user.username, member.user.globalName ?? undefined)
|
|
11338
11401
|
});
|
|
11339
11402
|
}
|
|
11340
11403
|
}
|
|
@@ -11347,7 +11410,7 @@ class DiscordService extends Service {
|
|
|
11347
11410
|
const onlineMembers = await guild.members.fetch({ limit: 100 });
|
|
11348
11411
|
for (const [, member] of onlineMembers) {
|
|
11349
11412
|
if (member.id !== botId) {
|
|
11350
|
-
const entityId =
|
|
11413
|
+
const entityId = createUniqueUuid6(this.runtime, member.id);
|
|
11351
11414
|
if (!entities.some((u) => u.id === entityId)) {
|
|
11352
11415
|
const tag = member.user.bot ? `${member.user.username}#${member.user.discriminator}` : member.user.username;
|
|
11353
11416
|
entities.push({
|
|
@@ -11358,22 +11421,7 @@ class DiscordService extends Service {
|
|
|
11358
11421
|
member.user.globalName
|
|
11359
11422
|
].filter(Boolean))),
|
|
11360
11423
|
agentId: this.runtime.agentId,
|
|
11361
|
-
metadata:
|
|
11362
|
-
default: {
|
|
11363
|
-
username: tag,
|
|
11364
|
-
name: member.displayName || member.user.username
|
|
11365
|
-
},
|
|
11366
|
-
discord: member.user.globalName ? {
|
|
11367
|
-
username: tag,
|
|
11368
|
-
name: member.displayName || member.user.username,
|
|
11369
|
-
globalName: member.user.globalName,
|
|
11370
|
-
userId: member.id
|
|
11371
|
-
} : {
|
|
11372
|
-
username: tag,
|
|
11373
|
-
name: member.displayName || member.user.username,
|
|
11374
|
-
userId: member.id
|
|
11375
|
-
}
|
|
11376
|
-
}
|
|
11424
|
+
metadata: buildDiscordEntityMetadata(member.id, tag, member.displayName || member.user.username, member.user.globalName ?? undefined)
|
|
11377
11425
|
});
|
|
11378
11426
|
}
|
|
11379
11427
|
}
|
|
@@ -11397,29 +11445,14 @@ class DiscordService extends Service {
|
|
|
11397
11445
|
if (member.id !== botId) {
|
|
11398
11446
|
const tag = member.user.bot ? `${member.user.username}#${member.user.discriminator}` : member.user.username;
|
|
11399
11447
|
entities.push({
|
|
11400
|
-
id:
|
|
11448
|
+
id: createUniqueUuid6(this.runtime, member.id),
|
|
11401
11449
|
names: Array.from(new Set([
|
|
11402
11450
|
member.user.username,
|
|
11403
11451
|
member.displayName,
|
|
11404
11452
|
member.user.globalName
|
|
11405
11453
|
].filter(Boolean))),
|
|
11406
11454
|
agentId: this.runtime.agentId,
|
|
11407
|
-
metadata:
|
|
11408
|
-
default: {
|
|
11409
|
-
username: tag,
|
|
11410
|
-
name: member.displayName || member.user.username
|
|
11411
|
-
},
|
|
11412
|
-
discord: member.user.globalName ? {
|
|
11413
|
-
username: tag,
|
|
11414
|
-
name: member.displayName || member.user.username,
|
|
11415
|
-
globalName: member.user.globalName,
|
|
11416
|
-
userId: member.id
|
|
11417
|
-
} : {
|
|
11418
|
-
username: tag,
|
|
11419
|
-
name: member.displayName || member.user.username,
|
|
11420
|
-
userId: member.id
|
|
11421
|
-
}
|
|
11422
|
-
}
|
|
11455
|
+
metadata: buildDiscordEntityMetadata(member.id, tag, member.displayName || member.user.username, member.user.globalName ?? undefined)
|
|
11423
11456
|
});
|
|
11424
11457
|
}
|
|
11425
11458
|
}
|
|
@@ -11465,8 +11498,7 @@ class DiscordService extends Service {
|
|
|
11465
11498
|
try {
|
|
11466
11499
|
const fullGuild = await guild.fetch();
|
|
11467
11500
|
this.runtime.logger.info(`Discord server connected: ${fullGuild.name} (${fullGuild.id})`);
|
|
11468
|
-
const worldId =
|
|
11469
|
-
const ownerId = createUniqueUuid5(this.runtime, fullGuild.ownerId);
|
|
11501
|
+
const worldId = createUniqueUuid6(this.runtime, fullGuild.id);
|
|
11470
11502
|
const standardizedData = {
|
|
11471
11503
|
name: fullGuild.name,
|
|
11472
11504
|
runtime: this.runtime,
|
|
@@ -11478,10 +11510,7 @@ class DiscordService extends Service {
|
|
|
11478
11510
|
agentId: this.runtime.agentId,
|
|
11479
11511
|
serverId: fullGuild.id,
|
|
11480
11512
|
metadata: {
|
|
11481
|
-
|
|
11482
|
-
roles: {
|
|
11483
|
-
[ownerId]: Role.OWNER
|
|
11484
|
-
}
|
|
11513
|
+
...buildDiscordWorldMetadata(this.runtime, fullGuild.ownerId)
|
|
11485
11514
|
}
|
|
11486
11515
|
},
|
|
11487
11516
|
source: "discord"
|
|
@@ -11677,9 +11706,9 @@ class DiscordService extends Service {
|
|
|
11677
11706
|
}
|
|
11678
11707
|
}
|
|
11679
11708
|
const timestamp = Date.now();
|
|
11680
|
-
const roomId =
|
|
11681
|
-
const entityId =
|
|
11682
|
-
const reactionUUID =
|
|
11709
|
+
const roomId = createUniqueUuid6(this.runtime, reaction.message.channel.id);
|
|
11710
|
+
const entityId = createUniqueUuid6(this.runtime, user.id);
|
|
11711
|
+
const reactionUUID = createUniqueUuid6(this.runtime, `${reaction.message.id}-${user.id}-${emoji}-${timestamp}`);
|
|
11683
11712
|
if (!entityId || !roomId) {
|
|
11684
11713
|
this.runtime.logger.error({
|
|
11685
11714
|
src: "plugin:discord",
|
|
@@ -11700,15 +11729,17 @@ class DiscordService extends Service {
|
|
|
11700
11729
|
entityId,
|
|
11701
11730
|
roomId,
|
|
11702
11731
|
userName,
|
|
11703
|
-
worldId:
|
|
11732
|
+
worldId: createUniqueUuid6(this.runtime, reaction.message.guild?.id ?? roomId),
|
|
11704
11733
|
worldName: reaction.message.guild?.name || undefined,
|
|
11705
11734
|
name,
|
|
11706
11735
|
source: "discord",
|
|
11707
11736
|
channelId: reaction.message.channel.id,
|
|
11708
11737
|
messageServerId: reaction.message.guild?.id ? stringToUuid3(reaction.message.guild.id) : undefined,
|
|
11709
|
-
type: channelType
|
|
11738
|
+
type: channelType,
|
|
11739
|
+
userId: user.id,
|
|
11740
|
+
metadata: buildDiscordWorldMetadata(this.runtime, reaction.message.guild?.ownerId)
|
|
11710
11741
|
});
|
|
11711
|
-
const inReplyTo =
|
|
11742
|
+
const inReplyTo = createUniqueUuid6(this.runtime, reaction.message.id);
|
|
11712
11743
|
const memory = {
|
|
11713
11744
|
id: reactionUUID,
|
|
11714
11745
|
entityId,
|
|
@@ -11786,7 +11817,7 @@ class DiscordService extends Service {
|
|
|
11786
11817
|
}
|
|
11787
11818
|
async getSpiderState(channelId) {
|
|
11788
11819
|
try {
|
|
11789
|
-
const stateId =
|
|
11820
|
+
const stateId = createUniqueUuid6(this.runtime, `discord-spider-state-${channelId}`);
|
|
11790
11821
|
const stateMemory = await this.runtime.getMemoryById(stateId);
|
|
11791
11822
|
const stateMemoryContent = stateMemory?.content;
|
|
11792
11823
|
if (stateMemoryContent?.text) {
|
|
@@ -11811,8 +11842,8 @@ class DiscordService extends Service {
|
|
|
11811
11842
|
}
|
|
11812
11843
|
async saveSpiderState(state) {
|
|
11813
11844
|
try {
|
|
11814
|
-
const stateId =
|
|
11815
|
-
const roomId =
|
|
11845
|
+
const stateId = createUniqueUuid6(this.runtime, `discord-spider-state-${state.channelId}`);
|
|
11846
|
+
const roomId = createUniqueUuid6(this.runtime, state.channelId);
|
|
11816
11847
|
this.runtime.logger.debug(`[SpiderState] Saving channel=${state.channelId} stateId=${stateId}`);
|
|
11817
11848
|
let existing = null;
|
|
11818
11849
|
try {
|
|
@@ -11844,7 +11875,7 @@ class DiscordService extends Service {
|
|
|
11844
11875
|
}
|
|
11845
11876
|
}
|
|
11846
11877
|
} catch {}
|
|
11847
|
-
worldId =
|
|
11878
|
+
worldId = createUniqueUuid6(this.runtime, serverId ?? state.channelId);
|
|
11848
11879
|
const entityId = this.runtime.agentId;
|
|
11849
11880
|
try {
|
|
11850
11881
|
const entity = await this.runtime.getEntityById(entityId);
|
|
@@ -11966,7 +11997,7 @@ class DiscordService extends Service {
|
|
|
11966
11997
|
}
|
|
11967
11998
|
const channel = fetchedChannel;
|
|
11968
11999
|
const serverId = "guild" in channel && channel.guild ? channel.guild.id : ("guildId" in channel) && channel.guildId ? channel.guildId : channel.id;
|
|
11969
|
-
const worldId = serverId ?
|
|
12000
|
+
const worldId = serverId ? createUniqueUuid6(this.runtime, serverId) : this.runtime.agentId;
|
|
11970
12001
|
await this.runtime.ensureWorldExists({
|
|
11971
12002
|
id: worldId,
|
|
11972
12003
|
agentId: this.runtime.agentId,
|
|
@@ -11977,7 +12008,7 @@ class DiscordService extends Service {
|
|
|
11977
12008
|
})()
|
|
11978
12009
|
});
|
|
11979
12010
|
await this.runtime.ensureRoomExists({
|
|
11980
|
-
id:
|
|
12011
|
+
id: createUniqueUuid6(this.runtime, channel.id),
|
|
11981
12012
|
agentId: this.runtime.agentId,
|
|
11982
12013
|
name: "name" in channel && channel.name || channel.id,
|
|
11983
12014
|
source: "discord",
|
|
@@ -12340,13 +12371,13 @@ class DiscordService extends Service {
|
|
|
12340
12371
|
if (!message.author || !message.channel) {
|
|
12341
12372
|
return null;
|
|
12342
12373
|
}
|
|
12343
|
-
const entityId =
|
|
12344
|
-
const roomId =
|
|
12374
|
+
const entityId = createUniqueUuid6(this.runtime, message.author.id);
|
|
12375
|
+
const roomId = createUniqueUuid6(this.runtime, message.channel.id);
|
|
12345
12376
|
const channel = message.channel;
|
|
12346
12377
|
const channelType = await this.getChannelType(channel);
|
|
12347
12378
|
const channelGuild = "guild" in channel ? channel.guild : null;
|
|
12348
12379
|
const serverId = channelGuild?.id ? channelGuild.id : message.guild?.id ?? message.channel.id;
|
|
12349
|
-
const worldId = serverId ?
|
|
12380
|
+
const worldId = serverId ? createUniqueUuid6(this.runtime, serverId) : this.runtime.agentId;
|
|
12350
12381
|
let textContent;
|
|
12351
12382
|
let attachments;
|
|
12352
12383
|
const optionsProcessedContent = options?.processedContent;
|
|
@@ -12376,7 +12407,7 @@ class DiscordService extends Service {
|
|
|
12376
12407
|
...options?.extraMetadata ? options.extraMetadata : {}
|
|
12377
12408
|
};
|
|
12378
12409
|
const memory = {
|
|
12379
|
-
id:
|
|
12410
|
+
id: createUniqueUuid6(this.runtime, message.id),
|
|
12380
12411
|
entityId,
|
|
12381
12412
|
agentId: this.runtime.agentId,
|
|
12382
12413
|
roomId,
|
|
@@ -12386,7 +12417,7 @@ class DiscordService extends Service {
|
|
|
12386
12417
|
source: "discord",
|
|
12387
12418
|
channelType,
|
|
12388
12419
|
url: message.url,
|
|
12389
|
-
inReplyTo: message.reference?.messageId ?
|
|
12420
|
+
inReplyTo: message.reference?.messageId ? createUniqueUuid6(this.runtime, message.reference.messageId) : undefined,
|
|
12390
12421
|
...options?.extraContent ? options.extraContent : {}
|
|
12391
12422
|
},
|
|
12392
12423
|
metadata,
|
|
@@ -12413,24 +12444,20 @@ class DiscordService extends Service {
|
|
|
12413
12444
|
const channelType = await this.getChannelType(firstMessage.channel);
|
|
12414
12445
|
const firstMessageChannelGuild = "guild" in firstMessage.channel ? firstMessage.channel.guild : null;
|
|
12415
12446
|
const serverId = firstMessageChannelGuild?.id ? firstMessageChannelGuild.id : firstMessage.guild?.id ?? firstMessage.channel.id;
|
|
12416
|
-
const worldId = serverId ?
|
|
12447
|
+
const worldId = serverId ? createUniqueUuid6(this.runtime, serverId) : this.runtime.agentId;
|
|
12417
12448
|
const entities = Array.from(uniqueAuthors.entries()).map(([authorId, message]) => {
|
|
12418
12449
|
const userName = message.author.username;
|
|
12419
12450
|
const name = (message.member && "displayName" in message.member && typeof message.member.displayName === "string" ? message.member.displayName : undefined) ?? ("globalName" in message.author && typeof message.author.globalName === "string" ? message.author.globalName : undefined) ?? userName;
|
|
12420
12451
|
return {
|
|
12421
|
-
id:
|
|
12452
|
+
id: createUniqueUuid6(this.runtime, authorId),
|
|
12422
12453
|
names: [userName, name].filter((n) => typeof n === "string" && n.length > 0),
|
|
12423
|
-
metadata:
|
|
12424
|
-
originalId: authorId,
|
|
12425
|
-
username: userName,
|
|
12426
|
-
displayName: name
|
|
12427
|
-
},
|
|
12454
|
+
metadata: buildDiscordEntityMetadata(authorId, userName, name),
|
|
12428
12455
|
agentId: this.runtime.agentId
|
|
12429
12456
|
};
|
|
12430
12457
|
});
|
|
12431
12458
|
const rooms = [
|
|
12432
12459
|
{
|
|
12433
|
-
id:
|
|
12460
|
+
id: createUniqueUuid6(this.runtime, firstMessage.channel.id),
|
|
12434
12461
|
channelId: firstMessage.channel.id,
|
|
12435
12462
|
type: channelType,
|
|
12436
12463
|
source: "discord"
|
|
@@ -12440,7 +12467,8 @@ class DiscordService extends Service {
|
|
|
12440
12467
|
id: worldId,
|
|
12441
12468
|
messageServerId: stringToUuid3(serverId),
|
|
12442
12469
|
name: firstMessage.guild?.name ?? `DM-${firstMessage.channel.id}`,
|
|
12443
|
-
agentId: this.runtime.agentId
|
|
12470
|
+
agentId: this.runtime.agentId,
|
|
12471
|
+
metadata: buildDiscordWorldMetadata(this.runtime, firstMessageChannelGuild?.ownerId ?? firstMessage.guild?.ownerId ?? undefined)
|
|
12444
12472
|
};
|
|
12445
12473
|
await this.runtime.ensureConnections(entities, rooms, "discord", world);
|
|
12446
12474
|
for (const authorId of uniqueAuthors.keys()) {
|
|
@@ -13407,13 +13435,15 @@ function splitLongLine(line2, maxChars, opts) {
|
|
|
13407
13435
|
}
|
|
13408
13436
|
return out;
|
|
13409
13437
|
}
|
|
13438
|
+
function isReasoningItalicsPayload(source) {
|
|
13439
|
+
return source.startsWith(`Reasoning:
|
|
13440
|
+
_`) && source.trimEnd().endsWith("_");
|
|
13441
|
+
}
|
|
13410
13442
|
function rebalanceReasoningItalics(source, chunks) {
|
|
13411
13443
|
if (chunks.length <= 1) {
|
|
13412
13444
|
return chunks;
|
|
13413
13445
|
}
|
|
13414
|
-
|
|
13415
|
-
_`) && source.trimEnd().endsWith("_");
|
|
13416
|
-
if (!opensWithReasoningItalics) {
|
|
13446
|
+
if (!isReasoningItalicsPayload(source)) {
|
|
13417
13447
|
return chunks;
|
|
13418
13448
|
}
|
|
13419
13449
|
const adjusted = [...chunks];
|
|
@@ -13438,12 +13468,13 @@ _`) && source.trimEnd().endsWith("_");
|
|
|
13438
13468
|
return adjusted;
|
|
13439
13469
|
}
|
|
13440
13470
|
function chunkDiscordText(text, opts = {}) {
|
|
13441
|
-
const
|
|
13471
|
+
const requestedMaxChars = Math.max(1, Math.floor(opts.maxChars ?? DEFAULT_MAX_CHARS));
|
|
13442
13472
|
const maxLines = Math.max(1, Math.floor(opts.maxLines ?? DEFAULT_MAX_LINES));
|
|
13443
13473
|
const body = text ?? "";
|
|
13444
13474
|
if (!body) {
|
|
13445
13475
|
return [];
|
|
13446
13476
|
}
|
|
13477
|
+
const maxChars = isReasoningItalicsPayload(body) ? Math.max(1, requestedMaxChars - 2) : requestedMaxChars;
|
|
13447
13478
|
const alreadyOk = body.length <= maxChars && countLines(body) <= maxLines;
|
|
13448
13479
|
if (alreadyOk) {
|
|
13449
13480
|
return [body];
|
|
@@ -14140,5 +14171,5 @@ export {
|
|
|
14140
14171
|
COMMAND_ARG_CUSTOM_ID_KEY
|
|
14141
14172
|
};
|
|
14142
14173
|
|
|
14143
|
-
//# debugId=
|
|
14174
|
+
//# debugId=B20F70AAC326598264756E2164756E21
|
|
14144
14175
|
//# sourceMappingURL=index.js.map
|