mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 17:01:53 +03:00
feat: add heartbeat toggle with live RPC control
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
monitorWebProvider,
|
||||
resolveHeartbeatRecipients,
|
||||
runWebHeartbeatOnce,
|
||||
setHeartbeatsEnabled,
|
||||
type WebMonitorTuning,
|
||||
} from "../provider-web.js";
|
||||
import { defaultRuntime } from "../runtime.js";
|
||||
@@ -240,6 +241,11 @@ Examples:
|
||||
respond({ type: "result", ok: true });
|
||||
return;
|
||||
}
|
||||
if (cmd.type === "set-heartbeats") {
|
||||
setHeartbeatsEnabled(Boolean(cmd.enabled));
|
||||
respond({ type: "result", ok: true });
|
||||
return;
|
||||
}
|
||||
if (cmd.type !== "send" || !cmd.text) {
|
||||
respond({ type: "error", error: "unsupported command" });
|
||||
return;
|
||||
|
||||
@@ -7,6 +7,7 @@ export {
|
||||
monitorWebProvider,
|
||||
resolveHeartbeatRecipients,
|
||||
runWebHeartbeatOnce,
|
||||
setHeartbeatsEnabled,
|
||||
type WebMonitorTuning,
|
||||
} from "./web/auto-reply.js";
|
||||
export {
|
||||
|
||||
@@ -33,6 +33,11 @@ import { getWebAuthAgeMs } from "./session.js";
|
||||
const WEB_TEXT_LIMIT = 4000;
|
||||
const DEFAULT_GROUP_HISTORY_LIMIT = 50;
|
||||
|
||||
let heartbeatsEnabled = true;
|
||||
export function setHeartbeatsEnabled(enabled: boolean) {
|
||||
heartbeatsEnabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message via IPC if relay is running, otherwise fall back to direct.
|
||||
* This avoids Signal session corruption from multiple Baileys connections.
|
||||
@@ -1026,6 +1031,7 @@ export async function monitorWebProvider(
|
||||
|
||||
if (keepAlive) {
|
||||
heartbeat = setInterval(() => {
|
||||
if (!heartbeatsEnabled) return;
|
||||
const authAgeMs = getWebAuthAgeMs();
|
||||
const minutesSinceLastMessage = lastMessageAt
|
||||
? Math.floor((Date.now() - lastMessageAt) / 60000)
|
||||
@@ -1081,6 +1087,7 @@ export async function monitorWebProvider(
|
||||
}
|
||||
|
||||
const runReplyHeartbeat = async () => {
|
||||
if (!heartbeatsEnabled) return;
|
||||
const queued = getQueueSize();
|
||||
if (queued > 0) {
|
||||
heartbeatLogger.info(
|
||||
@@ -1282,6 +1289,7 @@ export async function monitorWebProvider(
|
||||
if (replyHeartbeatMinutes && !replyHeartbeatTimer) {
|
||||
const intervalMs = replyHeartbeatMinutes * 60_000;
|
||||
replyHeartbeatTimer = setInterval(() => {
|
||||
if (!heartbeatsEnabled) return;
|
||||
void runReplyHeartbeat();
|
||||
}, intervalMs);
|
||||
if (tuning.replyHeartbeatNow) {
|
||||
|
||||
Reference in New Issue
Block a user