@llblab/pi-telegram 0.35.1 → 0.36.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/AGENTS.md +2 -1
- package/BACKLOG.md +11 -0
- package/CHANGELOG.md +18 -0
- package/README.md +36 -7
- package/docs/README.md +2 -1
- package/docs/architecture.md +29 -2
- package/docs/compact-matrix-literal.md +23 -13
- package/docs/generative-apps.md +310 -0
- package/docs/multi-instance-bus.md +1 -1
- package/docs/outbound.md +2 -2
- package/docs/public-api.md +3 -2
- package/docs/ui-style.md +14 -7
- package/index.ts +14 -0
- package/lib/bindings.ts +118 -8
- package/lib/generative-app-worker.mjs +103 -0
- package/lib/generative-apps.ts +953 -0
- package/lib/menu-queue.ts +105 -112
- package/lib/outbound-buttons.ts +51 -2
- package/lib/outbound-markup.ts +18 -14
- package/lib/outbound.ts +5 -1
- package/lib/prompts.ts +1 -0
- package/lib/queue.ts +98 -42
- package/lib/routing.ts +15 -0
- package/lib/runtime.ts +0 -23
- package/lib/updates.ts +49 -18
- package/package.json +1 -1
- package/skills/generated-control-surface/SKILL.md +13 -5
- package/skills/generative-apps/SKILL.md +110 -0
- package/skills/telegram-bridge/SKILL.md +5 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generative App isolated method worker
|
|
3
|
+
* Zones: managed Generative App execution, bounded local processes
|
|
4
|
+
* Owns one terminable app-method invocation and its child-process cleanup
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { execFile } from "node:child_process";
|
|
8
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
9
|
+
import { pathToFileURL } from "node:url";
|
|
10
|
+
|
|
11
|
+
if (!parentPort) throw new Error("Generative App worker requires a parent port.");
|
|
12
|
+
|
|
13
|
+
const controller = new AbortController();
|
|
14
|
+
const runningChildren = new Set();
|
|
15
|
+
parentPort.on("message", (message) => {
|
|
16
|
+
if (message?.type !== "abort") return;
|
|
17
|
+
controller.abort();
|
|
18
|
+
for (const child of runningChildren) child.kill();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
function runBoundedProcess(input) {
|
|
22
|
+
if (!input || typeof input !== "object") {
|
|
23
|
+
throw new Error("Generative App run input must be an object.");
|
|
24
|
+
}
|
|
25
|
+
const command = input.command?.trim();
|
|
26
|
+
if (!command) throw new Error("Generative App run.command is required.");
|
|
27
|
+
if (!Array.isArray(input.args ?? []) || (input.args?.length ?? 0) > workerData.runMaxArgs) {
|
|
28
|
+
throw new Error(`Generative App run.args accepts at most ${workerData.runMaxArgs} strings.`);
|
|
29
|
+
}
|
|
30
|
+
const args = (input.args ?? []).map((argument) => {
|
|
31
|
+
if (typeof argument !== "string") throw new Error("Generative App run.args must contain strings.");
|
|
32
|
+
return argument;
|
|
33
|
+
});
|
|
34
|
+
if (!input.cwd || typeof input.cwd !== "string") {
|
|
35
|
+
throw new Error("Generative App run.cwd is required.");
|
|
36
|
+
}
|
|
37
|
+
const timeoutMs = Math.min(
|
|
38
|
+
workerData.runMaxTimeoutMs,
|
|
39
|
+
Math.max(1, Math.round(input.timeoutMs ?? workerData.methodTimeoutMs)),
|
|
40
|
+
);
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const child = execFile(
|
|
43
|
+
command,
|
|
44
|
+
args,
|
|
45
|
+
{
|
|
46
|
+
cwd: input.cwd,
|
|
47
|
+
encoding: "utf8",
|
|
48
|
+
maxBuffer: workerData.runMaxStreamBytes,
|
|
49
|
+
shell: false,
|
|
50
|
+
signal: controller.signal,
|
|
51
|
+
timeout: timeoutMs,
|
|
52
|
+
windowsHide: true,
|
|
53
|
+
},
|
|
54
|
+
(error, stdout, stderr) => {
|
|
55
|
+
runningChildren.delete(child);
|
|
56
|
+
if (error && error.code !== "ABORT_ERR") {
|
|
57
|
+
resolve({
|
|
58
|
+
code: typeof error.code === "number" ? error.code : 1,
|
|
59
|
+
killed: error.killed === true,
|
|
60
|
+
stderr: String(stderr).slice(-workerData.runMaxStreamBytes),
|
|
61
|
+
stdout: String(stdout).slice(-workerData.runMaxStreamBytes),
|
|
62
|
+
});
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (error) {
|
|
66
|
+
reject(error);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
resolve({
|
|
70
|
+
code: 0,
|
|
71
|
+
killed: false,
|
|
72
|
+
stderr: String(stderr),
|
|
73
|
+
stdout: String(stdout),
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
runningChildren.add(child);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const module = await import(pathToFileURL(workerData.modulePath).href);
|
|
83
|
+
if (typeof module.init !== "function") {
|
|
84
|
+
throw new Error(`Generative App ${workerData.app} must export named function init.`);
|
|
85
|
+
}
|
|
86
|
+
const method = module[workerData.method];
|
|
87
|
+
if (typeof method !== "function") {
|
|
88
|
+
throw new Error(`Generative App ${workerData.app} does not export method ${workerData.method}.`);
|
|
89
|
+
}
|
|
90
|
+
const result = await method({
|
|
91
|
+
...(workerData.argumentPresent ? { argument: workerData.argument } : {}),
|
|
92
|
+
revision: workerData.revision,
|
|
93
|
+
run: runBoundedProcess,
|
|
94
|
+
signal: controller.signal,
|
|
95
|
+
...(workerData.statePresent ? { state: workerData.state } : {}),
|
|
96
|
+
});
|
|
97
|
+
parentPort.postMessage({ ok: true, result });
|
|
98
|
+
} catch (error) {
|
|
99
|
+
parentPort.postMessage({
|
|
100
|
+
ok: false,
|
|
101
|
+
error: error instanceof Error ? error.message : String(error),
|
|
102
|
+
});
|
|
103
|
+
}
|