@friendlyrobot/discord-pi-agent 0.21.1 → 0.21.4
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/README.md +14 -3
- package/dist/agent-model-service.js +132 -0
- package/dist/agent-resource-service.js +70 -0
- package/dist/agent-service.js +189 -0
- package/dist/agent-turn-runner.js +148 -0
- package/dist/config.js +103 -0
- package/dist/debug-print.js +22 -0
- package/dist/discord-attachments.js +148 -0
- package/dist/discord-auth.d.ts +3 -2
- package/dist/discord-auth.js +37 -0
- package/dist/discord-gateway-client.js +49 -0
- package/dist/discord-media-resolution.js +107 -0
- package/dist/discord-message-handler.js +195 -0
- package/dist/discord-replies.js +112 -0
- package/dist/discord-typing.js +75 -0
- package/dist/index.js +57 -1904
- package/dist/logger.js +26 -0
- package/dist/markdown-table-transformer.js +138 -0
- package/dist/media-description.js +87 -0
- package/dist/message-chunker.js +38 -0
- package/dist/prompt-context.d.ts +3 -0
- package/dist/prompt-context.js +48 -0
- package/dist/prompt-queue.js +37 -0
- package/dist/session-commands.js +281 -0
- package/dist/session-registry.d.ts +1 -1
- package/dist/session-registry.js +73 -0
- package/dist/types.js +1 -0
- package/package.json +4 -5
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { createModuleLogger } from "./logger";
|
|
3
|
+
import { PromptQueue } from "./prompt-queue";
|
|
4
|
+
import { DEFAULT_WORKING_EMOJI } from "./discord-replies";
|
|
5
|
+
/**
|
|
6
|
+
* Derive a deterministic session directory from a scope key.
|
|
7
|
+
*
|
|
8
|
+
* "dm" → <agentDir>/sessions
|
|
9
|
+
* "thread:<id>" → <agentDir>/sessions/thread-<id>
|
|
10
|
+
*/
|
|
11
|
+
export function sessionDirForScope(agentDir, scope) {
|
|
12
|
+
if (scope === "dm") {
|
|
13
|
+
return path.join(agentDir, "sessions");
|
|
14
|
+
}
|
|
15
|
+
if (scope.startsWith("thread:")) {
|
|
16
|
+
const threadId = scope.slice(7);
|
|
17
|
+
return path.join(agentDir, "sessions", `thread-${threadId}`);
|
|
18
|
+
}
|
|
19
|
+
throw new Error(`Unknown session scope: ${scope}`);
|
|
20
|
+
}
|
|
21
|
+
const logger = createModuleLogger("session-registry");
|
|
22
|
+
export class SessionRegistry {
|
|
23
|
+
scopes = new Map();
|
|
24
|
+
agentService;
|
|
25
|
+
constructor(agentService) {
|
|
26
|
+
this.agentService = agentService;
|
|
27
|
+
}
|
|
28
|
+
async getOrCreate(scope) {
|
|
29
|
+
const existing = this.scopes.get(scope);
|
|
30
|
+
if (existing) {
|
|
31
|
+
return { entry: existing, created: false };
|
|
32
|
+
}
|
|
33
|
+
const sessionDir = sessionDirForScope(this.agentService.getAgentDir(), scope);
|
|
34
|
+
const session = await this.agentService.createSession(sessionDir);
|
|
35
|
+
const promptQueue = new PromptQueue();
|
|
36
|
+
const entry = {
|
|
37
|
+
session,
|
|
38
|
+
promptQueue,
|
|
39
|
+
createdAt: new Date(),
|
|
40
|
+
workingEmoji: DEFAULT_WORKING_EMOJI,
|
|
41
|
+
};
|
|
42
|
+
this.scopes.set(scope, entry);
|
|
43
|
+
logger.debug({
|
|
44
|
+
scope,
|
|
45
|
+
sessionDir,
|
|
46
|
+
sessionId: session.sessionId,
|
|
47
|
+
}, "scope registered");
|
|
48
|
+
return { entry, created: true };
|
|
49
|
+
}
|
|
50
|
+
async remove(scope) {
|
|
51
|
+
const entry = this.scopes.get(scope);
|
|
52
|
+
if (!entry) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
logger.debug({ scope }, "removing scope");
|
|
56
|
+
await entry.session.abort();
|
|
57
|
+
entry.session.dispose();
|
|
58
|
+
this.scopes.delete(scope);
|
|
59
|
+
}
|
|
60
|
+
get(scope) {
|
|
61
|
+
return this.scopes.get(scope);
|
|
62
|
+
}
|
|
63
|
+
getScopes() {
|
|
64
|
+
return Array.from(this.scopes.keys());
|
|
65
|
+
}
|
|
66
|
+
async shutdownAll() {
|
|
67
|
+
logger.info({ count: this.scopes.size }, "shutting down all scopes");
|
|
68
|
+
const scopes = Array.from(this.scopes.keys());
|
|
69
|
+
for (const scope of scopes) {
|
|
70
|
+
await this.remove(scope);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
package/dist/types.js
ADDED
|
@@ -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.21.
|
|
3
|
+
"version": "0.21.4",
|
|
4
4
|
"description": "Reusable Discord gateway for persistent pi agent sessions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -29,10 +29,9 @@
|
|
|
29
29
|
"test": "LOG_LEVEL=silent vitest run",
|
|
30
30
|
"test:coverage": "LOG_LEVEL=silent vitest run --coverage",
|
|
31
31
|
"format": "prettier --write .",
|
|
32
|
-
"build:
|
|
33
|
-
"build:
|
|
34
|
-
"build
|
|
35
|
-
"build": "bun run --sequential 'build:*'",
|
|
32
|
+
"build:clean": "rm -rf dist",
|
|
33
|
+
"build:emit": "tsgo -p tsconfig.build.json --declaration --declarationMap false",
|
|
34
|
+
"build": "npm run build:clean && npm run build:emit",
|
|
36
35
|
"typecheck": "tsgo --noEmit -p tsconfig.json"
|
|
37
36
|
},
|
|
38
37
|
"dependencies": {
|