@friendlyrobot/discord-pi-agent 0.3.18 → 0.4.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.
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DiscordPiBridge, DiscordPiBridgeConfig } from "./types";
|
|
2
2
|
export { buildTimeContextPrompt, type TimeContextPromptOptions, } from "./prompt-context";
|
|
3
|
+
export { transformMarkdownTablesToCodeBlocks } from "./markdown-table-transformer";
|
|
3
4
|
export { loadDiscordPiBridgeConfigFromEnv, resolveConfig } from "./config";
|
|
4
5
|
export type { AgentStatus, DiscordPiBridge, DiscordPiBridgeConfig, PromptTransform, ResolvedDiscordPiBridgeConfig, } from "./types";
|
|
5
6
|
export declare function startDiscordPiBridge(config: DiscordPiBridgeConfig): Promise<DiscordPiBridge>;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
3
|
+
|
|
1
4
|
// src/agent-service.ts
|
|
2
5
|
import fs from "node:fs/promises";
|
|
3
6
|
import path from "node:path";
|
|
@@ -10,6 +13,36 @@ import {
|
|
|
10
13
|
SettingsManager
|
|
11
14
|
} from "@mariozechner/pi-coding-agent";
|
|
12
15
|
|
|
16
|
+
// src/markdown-table-transformer.ts
|
|
17
|
+
import { Lexer } from "marked";
|
|
18
|
+
var CODE_BLOCK_WRAPPER = "```\n{TABLE}\n```";
|
|
19
|
+
async function transformMarkdownTablesToCodeBlocks(text) {
|
|
20
|
+
const formatted = await formatWithPrettier(text);
|
|
21
|
+
const tokens = Lexer.lex(formatted);
|
|
22
|
+
const result = [];
|
|
23
|
+
for (const token of tokens) {
|
|
24
|
+
if (token.type === "table") {
|
|
25
|
+
result.push(CODE_BLOCK_WRAPPER.replace("{TABLE}", token.raw.trimEnd()));
|
|
26
|
+
} else {
|
|
27
|
+
result.push(token.raw);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return formatWithPrettier(result.join(""));
|
|
31
|
+
}
|
|
32
|
+
async function formatWithPrettier(text) {
|
|
33
|
+
const prettier = await import("prettier");
|
|
34
|
+
try {
|
|
35
|
+
const formatted = await prettier.format(text, {
|
|
36
|
+
parser: "markdown",
|
|
37
|
+
printWidth: 80
|
|
38
|
+
});
|
|
39
|
+
return formatted.trim();
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error("[markdown-table-transformer] Prettier formatting failed:", error);
|
|
42
|
+
return text;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
13
46
|
// src/reply-buffer.ts
|
|
14
47
|
async function collectReply(session, prompt, options = {}) {
|
|
15
48
|
const logPrefix = options.logPrefix ?? "[agent]";
|
|
@@ -67,7 +100,8 @@ async function collectReply(session, prompt, options = {}) {
|
|
|
67
100
|
return errorMessage;
|
|
68
101
|
}
|
|
69
102
|
if (finalText) {
|
|
70
|
-
|
|
103
|
+
const transformed = await transformMarkdownTablesToCodeBlocks(finalText);
|
|
104
|
+
return transformed;
|
|
71
105
|
}
|
|
72
106
|
return "No response generated.";
|
|
73
107
|
}
|
|
@@ -756,6 +790,7 @@ function registerSignalHandlers(stop) {
|
|
|
756
790
|
});
|
|
757
791
|
}
|
|
758
792
|
export {
|
|
793
|
+
transformMarkdownTablesToCodeBlocks,
|
|
759
794
|
startDiscordPiBridge,
|
|
760
795
|
resolveConfig,
|
|
761
796
|
loadDiscordPiBridgeConfigFromEnv,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transforms markdown tables into Discord-friendly code blocks.
|
|
3
|
+
* Discord doesn't support markdown tables natively, so we:
|
|
4
|
+
* 1. Format the entire document with Prettier (tables get formatted)
|
|
5
|
+
* 2. Use marked Lexer to identify tables
|
|
6
|
+
* 3. Wrap tables in triple backticks
|
|
7
|
+
* 4. Run Prettier once more on the entire result (tables stay formatted in code blocks)
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Transforms markdown tables in the text to Discord-friendly code blocks.
|
|
11
|
+
* Uses marked's Lexer to properly identify tables.
|
|
12
|
+
*/
|
|
13
|
+
export declare function transformMarkdownTablesToCodeBlocks(text: string): Promise<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friendlyrobot/discord-pi-agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Reusable Discord gateway bridge for persistent pi agent sessions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"scripts": {
|
|
28
28
|
"test:watch": "vitest",
|
|
29
29
|
"test": "vitest run",
|
|
30
|
-
"update-deps": "bun add @mariozechner/pi-ai@latest @mariozechner/pi-coding-agent@latest discord.js@latest dotenv@latest; bun add -d @types/node@latest
|
|
30
|
+
"update-deps": "bun add @mariozechner/pi-ai@latest @mariozechner/pi-coding-agent@latest marked@latest discord.js@latest dotenv@latest prettier@latest; bun add -d @types/node@latest typescript@latest vitest@latest @vitest/ui@latest",
|
|
31
31
|
"format": "prettier --write .",
|
|
32
32
|
"build": "rm -rf dist && bun build ./src/index.ts --outdir ./dist --target node --format esm --packages external && tsc -p tsconfig.json --emitDeclarationOnly --declaration --declarationMap false",
|
|
33
33
|
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
@@ -36,12 +36,13 @@
|
|
|
36
36
|
"@mariozechner/pi-ai": "^0.70.0",
|
|
37
37
|
"@mariozechner/pi-coding-agent": "^0.70.0",
|
|
38
38
|
"discord.js": "^14.26.3",
|
|
39
|
-
"dotenv": "^17.4.2"
|
|
39
|
+
"dotenv": "^17.4.2",
|
|
40
|
+
"marked": "^18.0.2",
|
|
41
|
+
"prettier": "^3.8.3"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"@types/node": "^25.6.0",
|
|
43
45
|
"@vitest/ui": "^4.1.5",
|
|
44
|
-
"prettier": "^3.8.3",
|
|
45
46
|
"typescript": "^6.0.3",
|
|
46
47
|
"vitest": "^4.1.5"
|
|
47
48
|
}
|