openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
30 lines (29 loc) • 1.89 kB
JavaScript
import { n as migrateHeartbeatPrompt } from "./doctor-heartbeat-legacy-DmzlheVU.mjs";
import { createHash } from "node:crypto";
//#region src/commands/doctor-heartbeat-task-identity.ts
/** Identity and execution metadata for heartbeat tasks migrated into cron. */
const HEARTBEAT_TASK_DECLARATION_PREFIX = "heartbeat-task:";
const MIGRATED_HEARTBEAT_TASK_DESCRIPTION = "Migrated from heartbeat monitor scratch by openclaw doctor.";
/** Cutover receipts prove origin; the definition timestamp excludes later edits. */
function resolveHeartbeatTaskPromptRepair(e, t, n) {
if (!t?.convertedJobIds?.includes(e.id) || e.description !== "Migrated from heartbeat monitor scratch by openclaw doctor." || e.createdAtMs !== n || e.state.runningAtMs !== void 0 || e.payload.kind !== "agentTurn") return;
const r = migrateHeartbeatPrompt(e.payload.message);
return r === e.payload.message ? void 0 : r;
}
/** Whether a declaration key belongs to the doctor-owned heartbeat-task namespace. */
function isHeartbeatTaskDeclarationKey(e) {
return e?.startsWith(HEARTBEAT_TASK_DECLARATION_PREFIX) === true;
}
/** Stable declaration identity; duplicate names add their deterministic occurrence ordinal. */
function heartbeatTaskDeclarationKey(e, t, n = 0) {
const r = createHash("sha256").update(e).update("\0").update(t);
if (n > 0) r.update("\0").update(String(n));
const i = r.digest("hex").slice(0, 24);
return `${HEARTBEAT_TASK_DECLARATION_PREFIX}${e}:${i}`;
}
/** Migrated jobs keep public system-event payloads so cron tools can edit or remove them normally. */
function isHeartbeatTaskCronJob(e) {
return isHeartbeatTaskDeclarationKey(e.declarationKey) && e.payload.kind === "systemEvent" && e.sessionTarget === "main";
}
//#endregion
export { resolveHeartbeatTaskPromptRepair as i, heartbeatTaskDeclarationKey as n, isHeartbeatTaskCronJob as r, MIGRATED_HEARTBEAT_TASK_DESCRIPTION as t };