@friendlyrobot/discord-pi-agent 0.9.2 → 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.
Files changed (2) hide show
  1. package/dist/index.js +31 -27
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -973,32 +973,38 @@ 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
- const rawFetchPromise = (async () => {
979
- const token = channel.client.token;
980
- const url = `https://discord.com/api/v10/channels/${channel.id}/typing`;
981
- const response = await fetch(url, {
977
+ const token = channel.client.token;
978
+ const url = `https://discord.com/api/v10/channels/${channel.id}/typing`;
979
+ const res = await fetch(url, {
980
+ method: "POST",
981
+ headers: { Authorization: `Bot ${token}` }
982
+ });
983
+ if (res.ok) {
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, {
982
999
  method: "POST",
983
1000
  headers: { Authorization: `Bot ${token}` }
984
1001
  });
985
- logger5.info({ channelKey, status: response.status }, "[TYPING] raw fetch status");
986
- return "raw-ok";
987
- })();
988
- const result = await Promise.race([
989
- channel.sendTyping().then(() => "ok"),
990
- rawFetchPromise,
991
- new Promise((resolve) => setTimeout(() => resolve("timeout"), 5000))
992
- ]);
993
- if (result === "timeout") {
994
- logger5.warn({ channelKey }, "[TYPING] BOTH calls TIMEOUT after 5s");
995
- } else if (result === "raw-ok") {
996
- logger5.info({ channelKey }, "[TYPING] raw fetch OK, discord.js STUCK");
997
- } else {
998
- logger5.info({ channelKey }, "[TYPING] sendTyping() OK");
1002
+ logger5.info({ channelKey }, "[TYPING] retry done");
1003
+ return;
999
1004
  }
1005
+ logger5.warn({ channelKey, status: res.status }, "[TYPING] unexpected status");
1000
1006
  } catch (error) {
1001
- logger5.warn({ channelKey, error }, "[TYPING] sendTyping() FAILED");
1007
+ logger5.warn({ channelKey, error }, "[TYPING] FAILED");
1002
1008
  }
1003
1009
  }
1004
1010
  function startTypingForChannel(channel, channelKey) {
@@ -1141,6 +1147,11 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
1141
1147
  channelType: message.channel.type,
1142
1148
  content
1143
1149
  }, "message received");
1150
+ const channelKey = message.channel.id;
1151
+ const canSend = message.channel.isSendable();
1152
+ if (canSend) {
1153
+ startTypingForChannel(message.channel, channelKey);
1154
+ }
1144
1155
  const { entry, created } = await sessionRegistry.getOrCreate(scope);
1145
1156
  const { session, promptQueue } = entry;
1146
1157
  if (created && scope.startsWith("thread:") && message.channel.isThread()) {
@@ -1149,13 +1160,6 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
1149
1160
  threadName: message.channel.name
1150
1161
  }, "new thread session");
1151
1162
  }
1152
- const channelKey = message.channel.id;
1153
- const canSend = message.channel.isSendable();
1154
- logger5.info({ channelKey, scope, canSend, channelType: message.channel.type }, "[TYPING] checking sendable");
1155
- if (canSend) {
1156
- startTypingForChannel(message.channel, channelKey);
1157
- logger5.info({ channelKey, scope }, "[TYPING] interval requested");
1158
- }
1159
1163
  const commandResult = await handleCommand(content, {
1160
1164
  agentService,
1161
1165
  promptQueue,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@friendlyrobot/discord-pi-agent",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "description": "Reusable Discord gateway bridge for persistent pi agent sessions",
5
5
  "license": "MIT",
6
6
  "type": "module",