@friendlyrobot/discord-pi-agent 0.9.3 → 0.9.4
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 +27 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -973,7 +973,6 @@ async function removeWorkingReaction(message) {
|
|
|
973
973
|
var TYPING_INTERVAL_MS = 9000;
|
|
974
974
|
var typingIntervals = new Map;
|
|
975
975
|
async function sendTypingSafe(channel, channelKey) {
|
|
976
|
-
logger5.info({ channelKey }, "[TYPING] calling sendTyping()");
|
|
977
976
|
try {
|
|
978
977
|
const token = channel.client.token;
|
|
979
978
|
const url = `https://discord.com/api/v10/channels/${channel.id}/typing`;
|
|
@@ -981,13 +980,31 @@ async function sendTypingSafe(channel, channelKey) {
|
|
|
981
980
|
method: "POST",
|
|
982
981
|
headers: { Authorization: `Bot ${token}` }
|
|
983
982
|
});
|
|
984
|
-
const body = await res.text();
|
|
985
|
-
logger5.info({ channelKey, status: res.status, headers: Object.fromEntries(res.headers.entries()), body }, "[TYPING] raw fetch response");
|
|
986
983
|
if (res.ok) {
|
|
987
|
-
logger5.info({ channelKey }, "[TYPING]
|
|
984
|
+
logger5.info({ channelKey }, "[TYPING] OK");
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
if (res.status === 429) {
|
|
988
|
+
const body = await res.text();
|
|
989
|
+
let retryMs = 3000;
|
|
990
|
+
try {
|
|
991
|
+
const parsed = JSON.parse(body);
|
|
992
|
+
if (typeof parsed.retry_after === "number") {
|
|
993
|
+
retryMs = parsed.retry_after * 1000 + 500;
|
|
994
|
+
}
|
|
995
|
+
} catch {}
|
|
996
|
+
logger5.warn({ channelKey, retryMs }, "[TYPING] 429, retrying after delay");
|
|
997
|
+
await new Promise((resolve) => setTimeout(resolve, retryMs));
|
|
998
|
+
await fetch(url, {
|
|
999
|
+
method: "POST",
|
|
1000
|
+
headers: { Authorization: `Bot ${token}` }
|
|
1001
|
+
});
|
|
1002
|
+
logger5.info({ channelKey }, "[TYPING] retry done");
|
|
1003
|
+
return;
|
|
988
1004
|
}
|
|
1005
|
+
logger5.warn({ channelKey, status: res.status }, "[TYPING] unexpected status");
|
|
989
1006
|
} catch (error) {
|
|
990
|
-
logger5.warn({ channelKey, error }, "[TYPING]
|
|
1007
|
+
logger5.warn({ channelKey, error }, "[TYPING] FAILED");
|
|
991
1008
|
}
|
|
992
1009
|
}
|
|
993
1010
|
function startTypingForChannel(channel, channelKey) {
|
|
@@ -1130,6 +1147,11 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1130
1147
|
channelType: message.channel.type,
|
|
1131
1148
|
content
|
|
1132
1149
|
}, "message received");
|
|
1150
|
+
const channelKey = message.channel.id;
|
|
1151
|
+
const canSend = message.channel.isSendable();
|
|
1152
|
+
if (canSend) {
|
|
1153
|
+
startTypingForChannel(message.channel, channelKey);
|
|
1154
|
+
}
|
|
1133
1155
|
const { entry, created } = await sessionRegistry.getOrCreate(scope);
|
|
1134
1156
|
const { session, promptQueue } = entry;
|
|
1135
1157
|
if (created && scope.startsWith("thread:") && message.channel.isThread()) {
|
|
@@ -1138,13 +1160,6 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1138
1160
|
threadName: message.channel.name
|
|
1139
1161
|
}, "new thread session");
|
|
1140
1162
|
}
|
|
1141
|
-
const channelKey = message.channel.id;
|
|
1142
|
-
const canSend = message.channel.isSendable();
|
|
1143
|
-
logger5.info({ channelKey, scope, canSend, channelType: message.channel.type }, "[TYPING] checking sendable");
|
|
1144
|
-
if (canSend) {
|
|
1145
|
-
startTypingForChannel(message.channel, channelKey);
|
|
1146
|
-
logger5.info({ channelKey, scope }, "[TYPING] interval requested");
|
|
1147
|
-
}
|
|
1148
1163
|
const commandResult = await handleCommand(content, {
|
|
1149
1164
|
agentService,
|
|
1150
1165
|
promptQueue,
|