@friendlyrobot/discord-pi-agent 0.8.0 → 0.8.2
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 +38 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -952,16 +952,29 @@ function isAuthorized(message, scope, authConfig) {
|
|
|
952
952
|
}
|
|
953
953
|
return false;
|
|
954
954
|
}
|
|
955
|
-
var TYPING_INTERVAL_MS =
|
|
956
|
-
|
|
955
|
+
var TYPING_INTERVAL_MS = 9000;
|
|
956
|
+
var typingIntervals = new Map;
|
|
957
|
+
function startTypingForChannel(channel, channelKey) {
|
|
958
|
+
const existing = typingIntervals.get(channelKey);
|
|
959
|
+
if (existing) {
|
|
960
|
+
existing.refs += 1;
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
957
963
|
channel.sendTyping();
|
|
958
|
-
|
|
964
|
+
const interval = setInterval(() => {
|
|
959
965
|
channel.sendTyping();
|
|
960
966
|
}, TYPING_INTERVAL_MS);
|
|
967
|
+
typingIntervals.set(channelKey, { interval, refs: 1 });
|
|
961
968
|
}
|
|
962
|
-
function
|
|
963
|
-
|
|
964
|
-
|
|
969
|
+
function stopTypingForChannel(channelKey) {
|
|
970
|
+
const entry = typingIntervals.get(channelKey);
|
|
971
|
+
if (!entry) {
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
entry.refs -= 1;
|
|
975
|
+
if (entry.refs <= 0) {
|
|
976
|
+
clearInterval(entry.interval);
|
|
977
|
+
typingIntervals.delete(channelKey);
|
|
965
978
|
}
|
|
966
979
|
}
|
|
967
980
|
async function sendReply(message, text) {
|
|
@@ -1083,9 +1096,9 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1083
1096
|
threadName: message.channel.name
|
|
1084
1097
|
}, "new thread session");
|
|
1085
1098
|
}
|
|
1086
|
-
|
|
1099
|
+
const channelKey = message.channel.id;
|
|
1087
1100
|
if (message.channel.isSendable()) {
|
|
1088
|
-
|
|
1101
|
+
startTypingForChannel(message.channel, channelKey);
|
|
1089
1102
|
}
|
|
1090
1103
|
const commandResult = await handleCommand(content, {
|
|
1091
1104
|
agentService,
|
|
@@ -1093,7 +1106,7 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1093
1106
|
session
|
|
1094
1107
|
});
|
|
1095
1108
|
if (commandResult.handled) {
|
|
1096
|
-
|
|
1109
|
+
stopTypingForChannel(channelKey);
|
|
1097
1110
|
if (commandResult.archive && scope.startsWith("thread:")) {
|
|
1098
1111
|
logger5.info({ scope }, "archiving thread");
|
|
1099
1112
|
const archiveChannel = message.channel;
|
|
@@ -1121,7 +1134,7 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1121
1134
|
return;
|
|
1122
1135
|
}
|
|
1123
1136
|
if (!message.channel.isSendable()) {
|
|
1124
|
-
|
|
1137
|
+
stopTypingForChannel(channelKey);
|
|
1125
1138
|
logger5.debug({ messageId: message.id }, "channel not sendable");
|
|
1126
1139
|
return;
|
|
1127
1140
|
}
|
|
@@ -1134,18 +1147,22 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1134
1147
|
if (queuePosition > 0) {
|
|
1135
1148
|
await sendReply(message, `Queued. ${queuePosition} request(s) ahead of this one.`);
|
|
1136
1149
|
}
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1150
|
+
let response;
|
|
1151
|
+
try {
|
|
1152
|
+
response = await promptQueue.enqueue(async () => {
|
|
1153
|
+
logger5.debug({
|
|
1154
|
+
messageId: message.id,
|
|
1155
|
+
scope
|
|
1156
|
+
}, "processing message");
|
|
1157
|
+
const promptContent = buildDiscordPromptContent(message, scope, content, config);
|
|
1158
|
+
const transformedPrompt = await config.promptTransform(promptContent);
|
|
1159
|
+
return collectReply(session, transformedPrompt, {
|
|
1160
|
+
logPrefix: `[agent:${session.sessionId}]`
|
|
1161
|
+
});
|
|
1146
1162
|
});
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1163
|
+
} finally {
|
|
1164
|
+
stopTypingForChannel(channelKey);
|
|
1165
|
+
}
|
|
1149
1166
|
logger5.info({
|
|
1150
1167
|
direction: "OUT",
|
|
1151
1168
|
scope,
|