web: add heartbeat and bounded reconnect tuning

This commit is contained in:
Peter Steinberger
2025-11-26 02:34:43 +01:00
parent e482e7768b
commit baf20af17f
19 changed files with 541 additions and 63 deletions

View File

@@ -1,3 +1,4 @@
import { randomUUID } from "node:crypto";
import fsSync from "node:fs";
import fs from "node:fs/promises";
import os from "node:os";
@@ -165,6 +166,24 @@ function readWebSelfId() {
}
}
/**
* Return the age (in milliseconds) of the cached WhatsApp web auth state, or null when missing.
* Helpful for heartbeats/observability to spot stale credentials.
*/
export function getWebAuthAgeMs(): number | null {
const credsPath = path.join(WA_WEB_AUTH_DIR, "creds.json");
try {
const stats = fsSync.statSync(credsPath);
return Date.now() - stats.mtimeMs;
} catch {
return null;
}
}
export function newConnectionId() {
return randomUUID();
}
export function logWebSelfId(
runtime: RuntimeEnv = defaultRuntime,
includeProviderPrefix = false,