@friendlyrobot/discord-pi-agent 0.10.6 → 0.11.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 +42 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -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
|
-
|
|
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;
|