@friendlyrobot/discord-pi-agent 0.5.1 → 0.5.3
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 +25 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -17,7 +17,8 @@ import {
|
|
|
17
17
|
import { Lexer } from "marked";
|
|
18
18
|
var CODE_BLOCK_WRAPPER = "```\n{TABLE}\n```";
|
|
19
19
|
async function transformMarkdownTablesToCodeBlocks(text) {
|
|
20
|
-
const
|
|
20
|
+
const normalized = normalizeCodeFences(text);
|
|
21
|
+
const formatted = await formatWithPrettier(normalized);
|
|
21
22
|
const tokens = Lexer.lex(formatted);
|
|
22
23
|
const result = [];
|
|
23
24
|
for (const token of tokens) {
|
|
@@ -29,6 +30,25 @@ async function transformMarkdownTablesToCodeBlocks(text) {
|
|
|
29
30
|
}
|
|
30
31
|
return formatWithPrettier(result.join(""));
|
|
31
32
|
}
|
|
33
|
+
function normalizeCodeFences(text) {
|
|
34
|
+
const lines = text.split(`
|
|
35
|
+
`);
|
|
36
|
+
const result = [];
|
|
37
|
+
for (const line of lines) {
|
|
38
|
+
const trimmed = line.trimEnd();
|
|
39
|
+
if (trimmed.endsWith("```") && !trimmed.startsWith("```")) {
|
|
40
|
+
const beforeFence = trimmed.slice(0, -3).trimEnd();
|
|
41
|
+
if (beforeFence) {
|
|
42
|
+
result.push(beforeFence);
|
|
43
|
+
}
|
|
44
|
+
result.push("```");
|
|
45
|
+
} else {
|
|
46
|
+
result.push(line);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return result.join(`
|
|
50
|
+
`);
|
|
51
|
+
}
|
|
32
52
|
async function formatWithPrettier(text) {
|
|
33
53
|
const prettier = await import("prettier");
|
|
34
54
|
try {
|
|
@@ -828,6 +848,10 @@ async function onMessage(message, config, agentService, sessionRegistry, authCon
|
|
|
828
848
|
console.log("[gateway] ignored bot message", { messageId: message.id });
|
|
829
849
|
return;
|
|
830
850
|
}
|
|
851
|
+
if (message.system) {
|
|
852
|
+
console.log("[gateway] ignored system message", { messageId: message.id });
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
831
855
|
const scope = resolveScope(message);
|
|
832
856
|
if (scope === null) {
|
|
833
857
|
console.log("[gateway] unsupported channel type, ignoring", {
|