@friendlyrobot/discord-pi-agent 0.19.13 → 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.
@@ -2,3 +2,8 @@ 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
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 {
@@ -1165,6 +1193,33 @@ async function sendReply(message, text) {
1165
1193
  }, "send reply failed");
1166
1194
  }
1167
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
+ }
1168
1223
 
1169
1224
  // src/media-description.ts
1170
1225
  var logger8 = createModuleLogger("media-description");
@@ -1449,11 +1504,6 @@ function normalizeContextValue(value) {
1449
1504
 
1450
1505
  // src/discord-message-handler.ts
1451
1506
  var logger11 = createModuleLogger("discord-message-handler");
1452
- function codeFence(text) {
1453
- return `\`\`\`
1454
- ${text}
1455
- \`\`\``;
1456
- }
1457
1507
  function buildDiscordPromptContent(message, scope, content, config) {
1458
1508
  const isThread = scope.startsWith("thread:") && message.channel.isThread();
1459
1509
  return buildDiscordMessageContextPrompt(content, {
@@ -1543,7 +1593,9 @@ ${attachment.content}`;
1543
1593
  logger11.info({ scope }, "archiving thread");
1544
1594
  const archiveChannel = message.channel;
1545
1595
  if (archiveChannel.isSendable()) {
1546
- await archiveChannel.send(codeFence(commandResult.response ?? "Archiving..."));
1596
+ await archiveChannel.send(`\`\`\`
1597
+ ${commandResult.response ?? "Archiving..."}
1598
+ \`\`\``);
1547
1599
  }
1548
1600
  try {
1549
1601
  if (archiveChannel.isThread()) {
@@ -1561,7 +1613,7 @@ ${attachment.content}`;
1561
1613
  hasResponse: Boolean(commandResult.response)
1562
1614
  }, `command handled: ${content}`);
1563
1615
  if (commandResult.response) {
1564
- await sendReply(message, codeFence(commandResult.response));
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.13",
3
+ "version": "0.19.15",
4
4
  "description": "Reusable Discord gateway for persistent pi agent sessions",
5
5
  "license": "MIT",
6
6
  "type": "module",