@tritard/waterbrother 0.16.126 → 0.16.127
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 +1 -1
- package/src/cli.js +55 -35
- package/src/discord.js +2 -2
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -2925,7 +2925,7 @@ function isProcessAlive(pid) {
|
|
|
2925
2925
|
|
|
2926
2926
|
async function maybeAutostartGateway(runtime, { cwd, io = console } = {}) {
|
|
2927
2927
|
if (process.env.WATERBROTHER_GATEWAY_CHILD === "1") {
|
|
2928
|
-
return { attempted: false, started: false, reason: "gateway-child" };
|
|
2928
|
+
return { attempted: false, started: false, reason: "gateway-child", handles: [] };
|
|
2929
2929
|
}
|
|
2930
2930
|
|
|
2931
2931
|
const gateway = runtime?.gateway || {};
|
|
@@ -2933,38 +2933,54 @@ async function maybeAutostartGateway(runtime, { cwd, io = console } = {}) {
|
|
|
2933
2933
|
? gateway.startupChannels.map((value) => String(value || "").trim().toLowerCase()).filter(Boolean)
|
|
2934
2934
|
: [];
|
|
2935
2935
|
|
|
2936
|
-
if (!gateway.enabled ||
|
|
2937
|
-
return { attempted: false, started: false, reason: "not-configured",
|
|
2936
|
+
if (!gateway.enabled || startupChannels.length === 0) {
|
|
2937
|
+
return { attempted: false, started: false, reason: "not-configured", handles: [] };
|
|
2938
2938
|
}
|
|
2939
2939
|
|
|
2940
|
-
const
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
}
|
|
2940
|
+
const handles = [];
|
|
2941
|
+
let attempted = false;
|
|
2942
|
+
let started = false;
|
|
2944
2943
|
|
|
2945
|
-
const
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2944
|
+
for (const serviceId of startupChannels) {
|
|
2945
|
+
if (serviceId === "telegram") {
|
|
2946
|
+
const telegram = runtime?.channels?.telegram || {};
|
|
2947
|
+
if (!telegram.enabled || !String(telegram.botToken || "").trim()) continue;
|
|
2948
|
+
} else if (serviceId === "discord") {
|
|
2949
|
+
const discord = runtime?.channels?.discord || {};
|
|
2950
|
+
if (!discord.enabled || !String(discord.botToken || "").trim() || !String(discord.applicationId || "").trim()) continue;
|
|
2951
|
+
} else {
|
|
2952
|
+
continue;
|
|
2953
|
+
}
|
|
2949
2954
|
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
WATERBROTHER_GATEWAY_CHILD: "1"
|
|
2955
|
+
attempted = true;
|
|
2956
|
+
const processInfo = await loadGatewayProcessInfo(serviceId);
|
|
2957
|
+
if (isProcessAlive(processInfo.pid)) {
|
|
2958
|
+
handles.push({ service: serviceId, attempted: true, started: false, reason: "already-running", pid: processInfo.pid, child: null });
|
|
2959
|
+
continue;
|
|
2956
2960
|
}
|
|
2957
|
-
});
|
|
2958
|
-
child.unref();
|
|
2959
2961
|
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2962
|
+
const child = spawn(process.execPath, [BIN_PATH, serviceId === "telegram" ? "gateway" : "discord", "run", ...(serviceId === "telegram" ? [serviceId] : []), "--skip-onboarding"].filter(Boolean), {
|
|
2963
|
+
cwd,
|
|
2964
|
+
stdio: "ignore",
|
|
2965
|
+
env: {
|
|
2966
|
+
...process.env,
|
|
2967
|
+
WATERBROTHER_GATEWAY_CHILD: "1"
|
|
2968
|
+
}
|
|
2969
|
+
});
|
|
2970
|
+
child.unref();
|
|
2971
|
+
|
|
2972
|
+
await saveGatewayProcessInfo(serviceId, {
|
|
2973
|
+
pid: child.pid,
|
|
2974
|
+
startedAt: new Date().toISOString(),
|
|
2975
|
+
command: serviceId === "telegram" ? "gateway run telegram --skip-onboarding" : "discord run --skip-onboarding"
|
|
2976
|
+
});
|
|
2965
2977
|
|
|
2966
|
-
|
|
2967
|
-
|
|
2978
|
+
io.log?.(dim(`${serviceId} gateway autostarted in background (pid ${child.pid})`));
|
|
2979
|
+
handles.push({ service: serviceId, attempted: true, started: true, pid: child.pid, child });
|
|
2980
|
+
started = true;
|
|
2981
|
+
}
|
|
2982
|
+
|
|
2983
|
+
return { attempted, started, reason: handles.length ? "" : "not-ready", handles };
|
|
2968
2984
|
}
|
|
2969
2985
|
|
|
2970
2986
|
async function stopManagedGateway(service, gatewayHandle, { io = console } = {}) {
|
|
@@ -2997,8 +3013,8 @@ async function stopManagedGateway(service, gatewayHandle, { io = console } = {})
|
|
|
2997
3013
|
|
|
2998
3014
|
async function stopTrackedGateway(service = "telegram", { io = console } = {}) {
|
|
2999
3015
|
const normalized = String(service || "telegram").trim().toLowerCase();
|
|
3000
|
-
if (
|
|
3001
|
-
throw new Error("Usage: waterbrother gateway stop [telegram]");
|
|
3016
|
+
if (!["telegram", "discord"].includes(normalized)) {
|
|
3017
|
+
throw new Error("Usage: waterbrother gateway stop [telegram|discord]");
|
|
3002
3018
|
}
|
|
3003
3019
|
const processInfo = await loadGatewayProcessInfo(normalized);
|
|
3004
3020
|
const pid = Number(processInfo?.pid || 0);
|
|
@@ -7915,18 +7931,22 @@ Be concrete about surfaces — name actual pages/flows. Choose the best stack fo
|
|
|
7915
7931
|
if (gatewayCleanupDone) return;
|
|
7916
7932
|
gatewayCleanupDone = true;
|
|
7917
7933
|
await clearTelegramBridgeHost();
|
|
7918
|
-
|
|
7919
|
-
|
|
7934
|
+
for (const handle of Array.isArray(gatewayHandle?.handles) ? gatewayHandle.handles : []) {
|
|
7935
|
+
if (handle?.started && handle?.child) {
|
|
7936
|
+
await stopManagedGateway(handle.service, handle, { io: console });
|
|
7937
|
+
}
|
|
7920
7938
|
}
|
|
7921
7939
|
};
|
|
7922
7940
|
const cleanupManagedGatewaySync = () => {
|
|
7923
7941
|
if (gatewayCleanupDone) return;
|
|
7924
7942
|
gatewayCleanupDone = true;
|
|
7925
|
-
const
|
|
7926
|
-
|
|
7927
|
-
|
|
7928
|
-
|
|
7929
|
-
|
|
7943
|
+
for (const handle of Array.isArray(gatewayHandle?.handles) ? gatewayHandle.handles : []) {
|
|
7944
|
+
const pid = Number(handle?.pid || 0);
|
|
7945
|
+
if (Number.isFinite(pid) && pid > 0 && isProcessAlive(pid)) {
|
|
7946
|
+
try {
|
|
7947
|
+
process.kill(pid, "SIGTERM");
|
|
7948
|
+
} catch {}
|
|
7949
|
+
}
|
|
7930
7950
|
}
|
|
7931
7951
|
};
|
|
7932
7952
|
const handleExitSignal = () => {
|
package/src/discord.js
CHANGED
|
@@ -381,8 +381,8 @@ export async function runDiscordGateway(runtime = {}, { log = console.log, signa
|
|
|
381
381
|
log(`discord: replied in ${msg.channel_id}`);
|
|
382
382
|
return;
|
|
383
383
|
}
|
|
384
|
-
if (
|
|
385
|
-
const bridged = await runPromptViaBridge(runtime, msg, String(msg.content || "").trim());
|
|
384
|
+
if (shouldReplyToMessage(msg, botUser?.id)) {
|
|
385
|
+
const bridged = await runPromptViaBridge(runtime, msg, extractMentionContent(String(msg.content || "").trim(), botUser?.id));
|
|
386
386
|
if (bridged?.content) {
|
|
387
387
|
await sendChannelMessage(discord, msg.channel_id, bridged.content);
|
|
388
388
|
log(`discord: bridged reply in ${msg.channel_id}`);
|