@chatluna/patchbay 0.1.4 → 0.1.5
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/package.json
CHANGED
package/patchbay.json
CHANGED
|
@@ -2,12 +2,8 @@
|
|
|
2
2
|
"patches": [
|
|
3
3
|
{
|
|
4
4
|
"name": "@cordisjs/plugin-cli-cordis",
|
|
5
|
-
"version": "1.0.
|
|
6
|
-
"description": "Stable root include id, launcher include overrides
|
|
7
|
-
"fixes": [
|
|
8
|
-
"ChatLunaLab/v2-mirror#99",
|
|
9
|
-
"cordiverse/cordis#294"
|
|
10
|
-
]
|
|
5
|
+
"version": "1.0.6",
|
|
6
|
+
"description": "Stable root include id, launcher include overrides, IPC health pings and a ready message"
|
|
11
7
|
},
|
|
12
8
|
{
|
|
13
9
|
"name": "@cordisjs/plugin-database",
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
diff --git a/lib/worker/index.d.ts b/lib/worker/index.d.ts
|
|
2
|
+
index 4362cf8..ae92999 100644
|
|
3
|
+
--- a/lib/worker/index.d.ts
|
|
4
|
+
+++ b/lib/worker/index.d.ts
|
|
5
|
+
@@ -4,6 +4,10 @@ export interface Config {
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
execArgv?: string[];
|
|
8
|
+
path: string;
|
|
9
|
+
+ /** Fixed id for the root include entry; defaults to 'chatluna' (keeps tree ids stable). */
|
|
10
|
+
+ includeId?: string;
|
|
11
|
+
+ /** Override/extend the root include config (e.g. inject `patches` to enable a group). */
|
|
12
|
+
+ include?: Record<string, unknown>;
|
|
13
|
+
daemon: daemon.Config;
|
|
14
|
+
prelude?: EntryOptions[];
|
|
15
|
+
}
|
|
16
|
+
diff --git a/lib/worker/index.js b/lib/worker/index.js
|
|
17
|
+
index 39fe113..f0a2566 100644
|
|
18
|
+
--- a/lib/worker/index.js
|
|
19
|
+
+++ b/lib/worker/index.js
|
|
20
|
+
@@ -56,6 +56,12 @@ function* apply(ctx, config = {}) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
send({ type: "start", body: config });
|
|
24
|
+
+ // Health over IPC: the supervisor pings, the worker answers; no network address involved.
|
|
25
|
+
+ const onMessage = /* @__PURE__ */ __name((message) => {
|
|
26
|
+
+ if (message?.type === "ping") send({ type: "pong", id: message.id });
|
|
27
|
+
+ }, "onMessage");
|
|
28
|
+
+ process.on("message", onMessage);
|
|
29
|
+
+ yield () => process.off("message", onMessage);
|
|
30
|
+
if (config.heartbeatInterval) {
|
|
31
|
+
const timer = setInterval(() => {
|
|
32
|
+
send({ type: "heartbeat" });
|
|
33
|
+
@@ -86,12 +92,22 @@ async function start(config) {
|
|
34
|
+
await ctx.loader.create(plugin);
|
|
35
|
+
}
|
|
36
|
+
await ctx.loader.create({
|
|
37
|
+
+ // Fixed id so tree-side entries keep stable ids (chatluna:<id>) across restarts.
|
|
38
|
+
+ id: config.includeId ?? "chatluna",
|
|
39
|
+
name: "@cordisjs/plugin-include",
|
|
40
|
+
config: {
|
|
41
|
+
+ // `include` lets the launcher override the include config wholesale (e.g.
|
|
42
|
+
+ // `chatluna dev` injects a `patches` entry to enable the dev group).
|
|
43
|
+
path: config.path,
|
|
44
|
+
- enableLogs: true
|
|
45
|
+
+ enableLogs: true,
|
|
46
|
+
+ ...config.include
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
+ // Ready once every entry has finished loading (failed plugins included; they are logged).
|
|
50
|
+
+ if (config.daemon.enabled) {
|
|
51
|
+
+ await ctx.loader.await();
|
|
52
|
+
+ send({ type: "ready" });
|
|
53
|
+
+ }
|
|
54
|
+
}
|
|
55
|
+
__name(start, "start");
|
|
56
|
+
export {
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
diff --git a/lib/worker/index.d.ts b/lib/worker/index.d.ts
|
|
2
|
-
index 4362cf8..ae92999 100644
|
|
3
|
-
--- a/lib/worker/index.d.ts
|
|
4
|
-
+++ b/lib/worker/index.d.ts
|
|
5
|
-
@@ -4,6 +4,10 @@ export interface Config {
|
|
6
|
-
baseUrl?: string;
|
|
7
|
-
execArgv?: string[];
|
|
8
|
-
path: string;
|
|
9
|
-
+ /** Fixed id for the root include entry; defaults to 'chatluna' (keeps tree ids stable). */
|
|
10
|
-
+ includeId?: string;
|
|
11
|
-
+ /** Override/extend the root include config (e.g. inject `patches` to enable a group). */
|
|
12
|
-
+ include?: Record<string, unknown>;
|
|
13
|
-
daemon: daemon.Config;
|
|
14
|
-
prelude?: EntryOptions[];
|
|
15
|
-
}
|
|
16
|
-
diff --git a/lib/worker/index.js b/lib/worker/index.js
|
|
17
|
-
index 91ff829..9c9b5ef 100644
|
|
18
|
-
--- a/lib/worker/index.js
|
|
19
|
-
+++ b/lib/worker/index.js
|
|
20
|
-
@@ -17,20 +17,39 @@ __export(daemon_exports, {
|
|
21
|
-
});
|
|
22
|
-
var name = "daemon";
|
|
23
|
-
function* apply(ctx, config = {}) {
|
|
24
|
-
+ // Bounded: a stuck `exit` listener must not keep a signalled or orphaned worker alive.
|
|
25
|
-
+ function exit(signal) {
|
|
26
|
-
+ setTimeout(() => process.exit(1), 1e4).unref();
|
|
27
|
-
+ ctx.parallel("exit", signal).finally(() => process.exit());
|
|
28
|
-
+ }
|
|
29
|
-
+ __name(exit, "exit");
|
|
30
|
-
function handleSignal(signal) {
|
|
31
|
-
process.stderr.write("\x1B[2K\r");
|
|
32
|
-
if (config.autoRestart) {
|
|
33
|
-
process.send({ type: "exit" });
|
|
34
|
-
}
|
|
35
|
-
ctx.logger.info(`terminated by ${signal}`);
|
|
36
|
-
- ctx.parallel("exit", signal).finally(() => process.exit());
|
|
37
|
-
+ exit(signal);
|
|
38
|
-
}
|
|
39
|
-
__name(handleSignal, "handleSignal");
|
|
40
|
-
process.on("SIGINT", handleSignal);
|
|
41
|
-
yield () => process.off("SIGINT", handleSignal);
|
|
42
|
-
process.on("SIGTERM", handleSignal);
|
|
43
|
-
yield () => process.off("SIGTERM", handleSignal);
|
|
44
|
-
+ // The parent owns this worker: once its IPC channel closes, nothing pings, restarts or stops it.
|
|
45
|
-
+ const onDisconnect = /* @__PURE__ */ __name(() => {
|
|
46
|
-
+ ctx.logger.info("terminated by parent disconnect");
|
|
47
|
-
+ exit("SIGTERM");
|
|
48
|
-
+ }, "onDisconnect");
|
|
49
|
-
+ process.on("disconnect", onDisconnect);
|
|
50
|
-
+ yield () => process.off("disconnect", onDisconnect);
|
|
51
|
-
process.send({ type: "start", body: config });
|
|
52
|
-
+ // Health over IPC: the supervisor pings, the worker answers; no network address involved.
|
|
53
|
-
+ const onMessage = /* @__PURE__ */ __name((message) => {
|
|
54
|
-
+ if (message?.type === "ping") process.send({ type: "pong", id: message.id });
|
|
55
|
-
+ }, "onMessage");
|
|
56
|
-
+ process.on("message", onMessage);
|
|
57
|
-
+ yield () => process.off("message", onMessage);
|
|
58
|
-
if (config.heartbeatInterval) {
|
|
59
|
-
const timer = setInterval(() => {
|
|
60
|
-
process.send({ type: "heartbeat" });
|
|
61
|
-
@@ -43,6 +62,12 @@ __name(apply, "apply");
|
|
62
|
-
// src/worker/index.ts
|
|
63
|
-
async function start(config) {
|
|
64
|
-
const ctx = new Context();
|
|
65
|
-
+ // Output is best-effort. Without a listener, a write to a closed stdout/stderr pipe becomes an
|
|
66
|
-
+ // uncaughtException, which is logged to the same pipe and fails again, forever.
|
|
67
|
-
+ const ignore = /* @__PURE__ */ __name(() => {
|
|
68
|
-
+ }, "ignore");
|
|
69
|
-
+ process.stdout.on("error", ignore);
|
|
70
|
-
+ process.stderr.on("error", ignore);
|
|
71
|
-
process.on("uncaughtException", (error) => {
|
|
72
|
-
ctx.logger.error(error);
|
|
73
|
-
process.exitCode = 1;
|
|
74
|
-
@@ -59,12 +84,22 @@ async function start(config) {
|
|
75
|
-
await ctx.loader.create(plugin);
|
|
76
|
-
}
|
|
77
|
-
await ctx.loader.create({
|
|
78
|
-
+ // Fixed id so tree-side entries keep stable ids (chatluna:<id>) across restarts.
|
|
79
|
-
+ id: config.includeId ?? "chatluna",
|
|
80
|
-
name: "@cordisjs/plugin-include",
|
|
81
|
-
config: {
|
|
82
|
-
+ // `include` lets the launcher override the include config wholesale (e.g.
|
|
83
|
-
+ // `chatluna dev` injects a `patches` entry to enable the dev group).
|
|
84
|
-
path: config.path,
|
|
85
|
-
- enableLogs: true
|
|
86
|
-
+ enableLogs: true,
|
|
87
|
-
+ ...config.include
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
+ // Ready once every entry has finished loading (failed plugins included; they are logged).
|
|
91
|
-
+ if (config.daemon.enabled) {
|
|
92
|
-
+ await ctx.loader.await();
|
|
93
|
-
+ process.send({ type: "ready" });
|
|
94
|
-
+ }
|
|
95
|
-
}
|
|
96
|
-
__name(start, "start");
|
|
97
|
-
export {
|