@friendlyrobot/discord-pi-agent 0.8.2 → 0.9.0
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 -3
- package/package.json +1 -1
- package/dist/discord-client.d.ts +0 -5
package/dist/index.js
CHANGED
|
@@ -952,29 +952,61 @@ 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 sendTypingSafe(channel, channelKey) {
|
|
976
|
+
logger5.info({ channelKey }, "[TYPING] calling sendTyping()");
|
|
977
|
+
channel.sendTyping().then(() => {
|
|
978
|
+
logger5.info({ channelKey }, "[TYPING] sendTyping() OK");
|
|
979
|
+
}).catch((error) => {
|
|
980
|
+
logger5.warn({ channelKey, error }, "[TYPING] sendTyping() FAILED");
|
|
981
|
+
});
|
|
982
|
+
}
|
|
957
983
|
function startTypingForChannel(channel, channelKey) {
|
|
958
984
|
const existing = typingIntervals.get(channelKey);
|
|
959
985
|
if (existing) {
|
|
960
986
|
existing.refs += 1;
|
|
987
|
+
logger5.info({ channelKey, refs: existing.refs }, "[TYPING] ref++ (reusing existing interval)");
|
|
961
988
|
return;
|
|
962
989
|
}
|
|
963
|
-
|
|
990
|
+
logger5.info({ channelKey }, "[TYPING] started new interval");
|
|
991
|
+
sendTypingSafe(channel, channelKey);
|
|
964
992
|
const interval = setInterval(() => {
|
|
965
|
-
channel
|
|
993
|
+
sendTypingSafe(channel, channelKey);
|
|
966
994
|
}, TYPING_INTERVAL_MS);
|
|
967
995
|
typingIntervals.set(channelKey, { interval, refs: 1 });
|
|
968
996
|
}
|
|
969
997
|
function stopTypingForChannel(channelKey) {
|
|
970
998
|
const entry = typingIntervals.get(channelKey);
|
|
971
999
|
if (!entry) {
|
|
1000
|
+
logger5.info({ channelKey }, "[TYPING] stop called but no entry found");
|
|
972
1001
|
return;
|
|
973
1002
|
}
|
|
974
1003
|
entry.refs -= 1;
|
|
975
1004
|
if (entry.refs <= 0) {
|
|
976
1005
|
clearInterval(entry.interval);
|
|
977
1006
|
typingIntervals.delete(channelKey);
|
|
1007
|
+
logger5.info({ channelKey }, "[TYPING] interval cleared (refs hit 0)");
|
|
1008
|
+
} else {
|
|
1009
|
+
logger5.info({ channelKey, refs: entry.refs }, "[TYPING] ref-- (interval still active)");
|
|
978
1010
|
}
|
|
979
1011
|
}
|
|
980
1012
|
async function sendReply(message, text) {
|
|
@@ -1097,8 +1129,11 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1097
1129
|
}, "new thread session");
|
|
1098
1130
|
}
|
|
1099
1131
|
const channelKey = message.channel.id;
|
|
1100
|
-
|
|
1132
|
+
const canSend = message.channel.isSendable();
|
|
1133
|
+
logger5.info({ channelKey, scope, canSend, channelType: message.channel.type }, "[TYPING] checking sendable");
|
|
1134
|
+
if (canSend) {
|
|
1101
1135
|
startTypingForChannel(message.channel, channelKey);
|
|
1136
|
+
logger5.info({ channelKey, scope }, "[TYPING] interval requested");
|
|
1102
1137
|
}
|
|
1103
1138
|
const commandResult = await handleCommand(content, {
|
|
1104
1139
|
agentService,
|
|
@@ -1138,6 +1173,7 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1138
1173
|
logger5.debug({ messageId: message.id }, "channel not sendable");
|
|
1139
1174
|
return;
|
|
1140
1175
|
}
|
|
1176
|
+
await addWorkingReaction(message);
|
|
1141
1177
|
const queuePosition = promptQueue.getSnapshot().pending;
|
|
1142
1178
|
logger5.debug({
|
|
1143
1179
|
scope,
|
|
@@ -1154,14 +1190,18 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
1154
1190
|
messageId: message.id,
|
|
1155
1191
|
scope
|
|
1156
1192
|
}, "processing message");
|
|
1193
|
+
logger5.info({ messageId: message.id, scope, channelKey }, "[TYPING] prompt enqueued, starting processing");
|
|
1157
1194
|
const promptContent = buildDiscordPromptContent(message, scope, content, config);
|
|
1158
1195
|
const transformedPrompt = await config.promptTransform(promptContent);
|
|
1196
|
+
logger5.info({ messageId: message.id, scope, channelKey }, "[TYPING] about to call collectReply/session.prompt");
|
|
1159
1197
|
return collectReply(session, transformedPrompt, {
|
|
1160
1198
|
logPrefix: `[agent:${session.sessionId}]`
|
|
1161
1199
|
});
|
|
1162
1200
|
});
|
|
1163
1201
|
} finally {
|
|
1164
1202
|
stopTypingForChannel(channelKey);
|
|
1203
|
+
logger5.info({ channelKey, scope }, "[TYPING] interval released");
|
|
1204
|
+
await removeWorkingReaction(message);
|
|
1165
1205
|
}
|
|
1166
1206
|
logger5.info({
|
|
1167
1207
|
direction: "OUT",
|
package/package.json
CHANGED
package/dist/discord-client.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Client } from "discord.js";
|
|
2
|
-
import type { AgentService } from "./agent-service";
|
|
3
|
-
import type { PromptQueue } from "./prompt-queue";
|
|
4
|
-
import type { ResolvedDiscordPiBridgeConfig } from "./types";
|
|
5
|
-
export declare function startDiscordClient(config: ResolvedDiscordPiBridgeConfig, agentService: AgentService, promptQueue: PromptQueue): Promise<Client>;
|