@friendlyrobot/discord-pi-agent 0.19.14 → 0.19.15

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.
@@ -1,6 +1,9 @@
1
1
  import type { Message } from "discord.js";
2
2
  export declare function addWorkingReaction(message: Message): Promise<void>;
3
3
  export declare function removeWorkingReaction(message: Message): Promise<void>;
4
- export declare function sendReply(message: Message, text: string, opts?: {
5
- codeFence?: boolean;
6
- }): Promise<void>;
4
+ export declare function sendReply(message: Message, text: string): Promise<void>;
5
+ /**
6
+ * Sends a command response wrapped in triple backticks.
7
+ * Splits by newlines so each chunk stays within Discord's 2000-char limit.
8
+ */
9
+ export declare function sendCommandReply(message: Message, text: string): Promise<void>;
package/dist/index.js CHANGED
@@ -1122,6 +1122,34 @@ function chunkMessage(text, maxChunkSize = SAFE_MESSAGE_LIMIT) {
1122
1122
 
1123
1123
  // src/discord-replies.ts
1124
1124
  var logger7 = createModuleLogger("discord-replies");
1125
+ var DISCORD_MESSAGE_LIMIT2 = 2000;
1126
+ var FENCE_OVERHEAD = 8;
1127
+ var MAX_CODE_FENCE_CONTENT = DISCORD_MESSAGE_LIMIT2 - FENCE_OVERHEAD;
1128
+ function chunkByLines(text, maxSize) {
1129
+ const lines = text.split(`
1130
+ `);
1131
+ const chunks = [];
1132
+ let current = "";
1133
+ for (const line of lines) {
1134
+ const candidate = current ? current + `
1135
+ ` + line : line;
1136
+ if (candidate.length > maxSize) {
1137
+ if (current) {
1138
+ chunks.push(current);
1139
+ current = line;
1140
+ } else {
1141
+ chunks.push(line.slice(0, maxSize));
1142
+ current = line.slice(maxSize);
1143
+ }
1144
+ } else {
1145
+ current = candidate;
1146
+ }
1147
+ }
1148
+ if (current) {
1149
+ chunks.push(current);
1150
+ }
1151
+ return chunks;
1152
+ }
1125
1153
  var WORKING_EMOJI = "⚙️";
1126
1154
  async function addWorkingReaction(message) {
1127
1155
  try {
@@ -1140,7 +1168,7 @@ async function removeWorkingReaction(message) {
1140
1168
  logger7.debug({ messageId: message.id, error }, "failed to remove working reaction");
1141
1169
  }
1142
1170
  }
1143
- async function sendReply(message, text, opts) {
1171
+ async function sendReply(message, text) {
1144
1172
  const channel = message.channel;
1145
1173
  if (!channel.isSendable()) {
1146
1174
  logger7.debug({
@@ -1148,10 +1176,7 @@ async function sendReply(message, text, opts) {
1148
1176
  }, "reply skipped, channel not sendable");
1149
1177
  return;
1150
1178
  }
1151
- const wrap = opts?.codeFence ? (c) => `\`\`\`
1152
- ${c}
1153
- \`\`\`` : (c) => c;
1154
- const chunks = chunkMessage(text).map(wrap);
1179
+ const chunks = chunkMessage(text);
1155
1180
  const [firstChunk, ...remainingChunks] = chunks;
1156
1181
  if (!firstChunk) {
1157
1182
  return;
@@ -1168,6 +1193,33 @@ ${c}
1168
1193
  }, "send reply failed");
1169
1194
  }
1170
1195
  }
1196
+ async function sendCommandReply(message, text) {
1197
+ const channel = message.channel;
1198
+ if (!channel.isSendable()) {
1199
+ logger7.debug({
1200
+ messageId: message.id
1201
+ }, "command reply skipped, channel not sendable");
1202
+ return;
1203
+ }
1204
+ const chunks = chunkByLines(text, MAX_CODE_FENCE_CONTENT).map((c) => `\`\`\`
1205
+ ${c}
1206
+ \`\`\``);
1207
+ const [firstChunk, ...remainingChunks] = chunks;
1208
+ if (!firstChunk) {
1209
+ return;
1210
+ }
1211
+ try {
1212
+ await message.reply(firstChunk);
1213
+ for (const chunk of remainingChunks) {
1214
+ await channel.send(chunk);
1215
+ }
1216
+ } catch (error) {
1217
+ logger7.error({
1218
+ messageId: message.id,
1219
+ error
1220
+ }, "send command reply failed");
1221
+ }
1222
+ }
1171
1223
 
1172
1224
  // src/media-description.ts
1173
1225
  var logger8 = createModuleLogger("media-description");
@@ -1561,7 +1613,7 @@ ${commandResult.response ?? "Archiving..."}
1561
1613
  hasResponse: Boolean(commandResult.response)
1562
1614
  }, `command handled: ${content}`);
1563
1615
  if (commandResult.response) {
1564
- await sendReply(message, commandResult.response, { codeFence: true });
1616
+ await sendCommandReply(message, commandResult.response);
1565
1617
  }
1566
1618
  return;
1567
1619
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@friendlyrobot/discord-pi-agent",
3
- "version": "0.19.14",
3
+ "version": "0.19.15",
4
4
  "description": "Reusable Discord gateway for persistent pi agent sessions",
5
5
  "license": "MIT",
6
6
  "type": "module",