openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
43 lines (42 loc) • 1.93 kB
JavaScript
import { a as getSqliteWorkerStateContext } from "./sqlite-worker-state-context-CR8h__Vh.mjs";
import { l as runOpenClawStateWriteTransaction } from "./openclaw-state-db-ARhwdPJg.mjs";
import { r as assertAgentDeletionRecoveryHoldPredicate } from "./agent-deletion-journal-recovery.kernel-BMlEn3jf.mjs";
import { g as upsertCronJobRow, o as loadCronRows, s as loadedCronStoreFromRows } from "./row-codec-D4aymQkb.mjs";
import { i as recordDefaultProactiveJobInDatabase, n as readDefaultProactiveJobReceiptInDatabase } from "./proactive-job-receipt.kernel-DONrwKqL.mjs";
//#region src/cron/default-proactive-job.worker.ts
function provisionDefaultProactiveJobInWorker(e, t) {
const n = getSqliteWorkerStateContext().environment;
return runOpenClawStateWriteTransaction((e) => {
const { db: n } = e;
const r = t.storeKey;
const i = loadCronRows(n, r);
const a = readDefaultProactiveJobReceiptInDatabase(n, r, t.agentId);
assertAgentDeletionRecoveryHoldPredicate(e, t.recoveryHoldPredicate);
let o;
if (a) {
if (a.phase !== "complete") throw new Error("Proactive migration is incomplete; run openclaw doctor --fix before provisioning.");
o = {
storeKey: r,
created: false,
job: loadedCronStoreFromRows(i).store.jobs.find((e) => e.id === a.jobId)
};
} else {
if (i.some((e) => e.payload_kind === "heartbeat" && e.agent_id === t.agentId)) throw new Error("Legacy proactive state needs openclaw doctor --fix before agent provisioning.");
const e = i.reduce((e, t) => Math.max(e, t.sort_order), -1) + 1;
const a = upsertCronJobRow(n, r, t.planned, e);
recordDefaultProactiveJobInDatabase(n, r, t.agentId, a.id, a.createdAtMs);
o = {
storeKey: r,
created: true,
job: a
};
}
return { outcome: o };
}, {
database: e,
path: e.path,
env: n
}, { operationLabel: "cron.provision-default-proactive" });
}
//#endregion
export { provisionDefaultProactiveJobInWorker };