openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.67 kB
JavaScript
import{a as getSqliteWorkerStateContext}from"./sqlite-worker-state-context-DJ4guxKh.mjs";import{l as runOpenClawStateWriteTransaction}from"./openclaw-state-db-BlgxYkYw.mjs";import{r as assertAgentDeletionRecoveryHoldPredicate}from"./agent-deletion-journal-recovery.kernel-DcfNqwh_.mjs";import{g as upsertCronJobRow,o as loadCronRows,s as loadedCronStoreFromRows}from"./row-codec-xXb-6VXO.mjs";import{i as recordDefaultProactiveJobInDatabase,n as readDefaultProactiveJobReceiptInDatabase}from"./proactive-job-receipt.kernel-PuhApq-s.mjs";
//!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`})}export{provisionDefaultProactiveJobInWorker};