@friendlyrobot/discord-pi-agent 0.10.6 → 0.11.2

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 +43 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -52,7 +52,7 @@ function debugPrint(body, title) {
52
52
  }
53
53
  console.info(centeredFence(label));
54
54
  console.info(body);
55
- console.info(centeredFence("END"));
55
+ console.info(centeredFence(`${label} END`));
56
56
  }
57
57
 
58
58
  // src/markdown-table-transformer.ts
@@ -1082,6 +1082,39 @@ async function sendReply(message, text) {
1082
1082
  }, "send reply failed");
1083
1083
  }
1084
1084
  }
1085
+ var TEXT_ATTACHMENT_EXTENSIONS = [".txt", ".md", ".json", ".csv", ".log", ".yml", ".yaml", ".xml", ".toml", ".ini", ".cfg"];
1086
+ var MAX_ATTACHMENT_SIZE_BYTES = 25 * 1024 * 1024;
1087
+ async function readTextAttachments(message) {
1088
+ const attachments = message.attachments;
1089
+ if (attachments.size === 0) {
1090
+ return [];
1091
+ }
1092
+ const results = [];
1093
+ for (const [, attachment] of attachments) {
1094
+ const ext = attachment.name?.slice(attachment.name.lastIndexOf(".")).toLowerCase();
1095
+ if (!ext || !TEXT_ATTACHMENT_EXTENSIONS.includes(ext)) {
1096
+ logger5.debug({ messageId: message.id, filename: attachment.name, ext }, "skipping non-text attachment");
1097
+ continue;
1098
+ }
1099
+ if (attachment.size > MAX_ATTACHMENT_SIZE_BYTES) {
1100
+ logger5.warn({ messageId: message.id, filename: attachment.name, size: attachment.size }, "attachment too large, skipping");
1101
+ continue;
1102
+ }
1103
+ try {
1104
+ logger5.info({ messageId: message.id, filename: attachment.name, size: attachment.size }, "fetching attachment");
1105
+ const response = await fetch(attachment.url);
1106
+ if (!response.ok) {
1107
+ logger5.warn({ messageId: message.id, filename: attachment.name, status: response.status }, "failed to fetch attachment");
1108
+ continue;
1109
+ }
1110
+ const content = await response.text();
1111
+ results.push({ filename: attachment.name, content });
1112
+ } catch (error) {
1113
+ logger5.error({ messageId: message.id, filename: attachment.name, error }, "error fetching attachment");
1114
+ }
1115
+ }
1116
+ return results;
1117
+ }
1085
1118
  async function startGatewayClient(config, agentService, sessionRegistry, authConfig) {
1086
1119
  const client = new Client({
1087
1120
  intents: [
@@ -1149,7 +1182,15 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
1149
1182
  }, "unauthorized");
1150
1183
  return;
1151
1184
  }
1152
- const content = message.content.trim();
1185
+ let content = message.content.trim();
1186
+ const attachmentContents = await readTextAttachments(message);
1187
+ if (attachmentContents.length > 0) {
1188
+ const suffix = attachmentContents.map((a) => `
1189
+
1190
+ --- Attachment: ${a.filename} ---
1191
+ ${a.content}`).join("");
1192
+ content = content ? content + suffix : attachmentContents[0].content;
1193
+ }
1153
1194
  if (!content) {
1154
1195
  logger5.debug({ messageId: message.id }, "ignored empty message");
1155
1196
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@friendlyrobot/discord-pi-agent",
3
- "version": "0.10.6",
3
+ "version": "0.11.2",
4
4
  "description": "Reusable Discord gateway bridge for persistent pi agent sessions",
5
5
  "license": "MIT",
6
6
  "type": "module",