@friendlyrobot/discord-pi-agent 0.8.1 → 0.8.3
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 +43 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -952,16 +952,47 @@ function isAuthorized(message, scope, authConfig) {
|
|
|
952
952
|
}
|
|
953
953
|
return false;
|
|
954
954
|
}
|
|
955
|
+
var WORKING_EMOJI = "⚙️";
|
|
956
|
+
async function addWorkingReaction(message) {
|
|
957
|
+
try {
|
|
958
|
+
await message.react(WORKING_EMOJI);
|
|
959
|
+
} catch (error) {
|
|
960
|
+
logger5.debug({ messageId: message.id, error }, "failed to add working reaction");
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
async function removeWorkingReaction(message) {
|
|
964
|
+
try {
|
|
965
|
+
const reaction = message.reactions.cache.get(WORKING_EMOJI);
|
|
966
|
+
if (reaction) {
|
|
967
|
+
await reaction.users.remove(message.client.user);
|
|
968
|
+
}
|
|
969
|
+
} catch (error) {
|
|
970
|
+
logger5.debug({ messageId: message.id, error }, "failed to remove working reaction");
|
|
971
|
+
}
|
|
972
|
+
}
|
|
955
973
|
var TYPING_INTERVAL_MS = 9000;
|
|
956
|
-
|
|
974
|
+
var typingIntervals = new Map;
|
|
975
|
+
function startTypingForChannel(channel, channelKey) {
|
|
976
|
+
const existing = typingIntervals.get(channelKey);
|
|
977
|
+
if (existing) {
|
|
978
|
+
existing.refs += 1;
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
957
981
|
channel.sendTyping();
|
|
958
|
-
|
|
982
|
+
const interval = setInterval(() => {
|
|
959
983
|
channel.sendTyping();
|
|
960
984
|
}, TYPING_INTERVAL_MS);
|
|
985
|
+
typingIntervals.set(channelKey, { interval, refs: 1 });
|
|
961
986
|
}
|
|
962
|
-
function
|
|
963
|
-
|
|
964
|
-
|
|
987
|
+
function stopTypingForChannel(channelKey) {
|
|
988
|
+
const entry = typingIntervals.get(channelKey);
|
|
989
|
+
if (!entry) {
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
entry.refs -= 1;
|
|
993
|
+
if (entry.refs <= 0) {
|
|
994
|
+
clearInterval(entry.interval);
|
|
995
|
+
typingIntervals.delete(channelKey);
|
|
965
996
|
}
|
|
966
997
|
}
|
|
967
998
|
async function sendReply(message, text) {
|
|
@@ -1083,9 +1114,9 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1083
1114
|
threadName: message.channel.name
|
|
1084
1115
|
}, "new thread session");
|
|
1085
1116
|
}
|
|
1086
|
-
|
|
1117
|
+
const channelKey = message.channel.id;
|
|
1087
1118
|
if (message.channel.isSendable()) {
|
|
1088
|
-
|
|
1119
|
+
startTypingForChannel(message.channel, channelKey);
|
|
1089
1120
|
}
|
|
1090
1121
|
const commandResult = await handleCommand(content, {
|
|
1091
1122
|
agentService,
|
|
@@ -1093,7 +1124,7 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1093
1124
|
session
|
|
1094
1125
|
});
|
|
1095
1126
|
if (commandResult.handled) {
|
|
1096
|
-
|
|
1127
|
+
stopTypingForChannel(channelKey);
|
|
1097
1128
|
if (commandResult.archive && scope.startsWith("thread:")) {
|
|
1098
1129
|
logger5.info({ scope }, "archiving thread");
|
|
1099
1130
|
const archiveChannel = message.channel;
|
|
@@ -1121,10 +1152,11 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1121
1152
|
return;
|
|
1122
1153
|
}
|
|
1123
1154
|
if (!message.channel.isSendable()) {
|
|
1124
|
-
|
|
1155
|
+
stopTypingForChannel(channelKey);
|
|
1125
1156
|
logger5.debug({ messageId: message.id }, "channel not sendable");
|
|
1126
1157
|
return;
|
|
1127
1158
|
}
|
|
1159
|
+
await addWorkingReaction(message);
|
|
1128
1160
|
const queuePosition = promptQueue.getSnapshot().pending;
|
|
1129
1161
|
logger5.debug({
|
|
1130
1162
|
scope,
|
|
@@ -1148,7 +1180,8 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1148
1180
|
});
|
|
1149
1181
|
});
|
|
1150
1182
|
} finally {
|
|
1151
|
-
|
|
1183
|
+
stopTypingForChannel(channelKey);
|
|
1184
|
+
await removeWorkingReaction(message);
|
|
1152
1185
|
}
|
|
1153
1186
|
logger5.info({
|
|
1154
1187
|
direction: "OUT",
|