openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.26 kB
JavaScript
import{F as e}from"./openclaw-state-read-openclaw-state-db-cache-DyomEqgV.mjs";import{a as t,d as n,f as r,g as i,i as a,n as o}from"./openclaw-state-read-schemas-YhOPoIHM.mjs";import{d as s,n as c,t as l}from"./openclaw-state-read-row-codec-CeR1CPnW.mjs";import{r as u}from"./openclaw-state-read-sqlite-transaction-Bt-IwVhZ.mjs";import{n as d}from"./openclaw-state-read-agent-id-DmscQLD6.mjs";import"./openclaw-state-read-session-key-H2_GWFw8.mjs";import{r as f}from"./openclaw-state-read-config-machine-state-row-DjFRA9Zl.mjs";import"./openclaw-state-read-config-machine-state-write-DdwbPpIz.mjs";const p=r({jobId:i().min(1),provisionedAtMs:n().int().nonnegative(),phase:o([`pending`,`complete`]),heartbeatEnabled:t().optional(),convertedJobIds:a(i().min(1)).optional()}).strict();function decodeDefaultProactiveJobReceipt(e){if(e===void 0)return;let t=p.safeParse(e);if(!t.success)throw Error(`Invalid default automation cutover receipt; preserve this state and use a known-good backup or manual repair before retrying. Doctor cannot safely reconstruct it. No automation was recreated.`);return t.data}function defaultProactiveJobReceiptKey(e,t){return`automation-default:${e}:${d(t)}`}function readDefaultProactiveJobReceiptInDatabase(e,t,n){let r=f(e,defaultProactiveJobReceiptKey(t,n));return decodeDefaultProactiveJobReceipt(r?JSON.parse(r.value_json):void 0)}function readReceipts(e,t){let n=t.storeKey;return{storeKey:n,receipts:Object.fromEntries(t.agentIds.flatMap(t=>{let r=readDefaultProactiveJobReceiptInDatabase(e,n,t);return r?[[t,r]]:[]}))}}const m={"automationProactive.storeSelection":(t,n)=>u(n,()=>({type:`automationProactive.storeSelection`,selection:s(n,t.storePath,e().environment,t.defaultStorePath)})),"automationProactive.receipts":(e,t)=>u(t,()=>({type:`automationProactive.receipts`,receipts:readReceipts(t,e).receipts})),"automationProactive.jobs":(e,t)=>u(t,()=>{let{storeKey:n,receipts:r}=readReceipts(t,e),i=new Set(Object.values(r).flatMap(e=>e.phase===`complete`?[e.jobId].concat(e.convertedJobIds??[]):[])),a=i.size>0?c(l(t,n,i)).store.jobs:[],o=new Map(a.map(e=>[e.id,e]));return{type:`automationProactive.jobs`,jobs:[...i].flatMap(e=>{let t=o.get(e);return t?[t]:[]})}})};export{m as proactiveJobReceiptReadOperations};