openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 1.89 kB
JavaScript
import"./openclaw-state-read-subsystem-Dwoo5bcz.mjs";import{o as e,v as t,w as n}from"./openclaw-state-read-sqlite-database-admission-CrkztOzk.mjs";import{r}from"./openclaw-state-read-kysely-sync-Bcu0Qb7F.mjs";import"./openclaw-state-read-sqlite-number-5mfxKD9j.mjs";import"./openclaw-state-read-sqlite-transaction-Bt-IwVhZ.mjs";import{a as i,o as a,u as o}from"./openclaw-state-read-delivery-queue-sqlite.types-CRRiZl3P.mjs";import"./openclaw-state-read-secure-random-DS7aQ3jW.mjs";const s=`outbound-prepared-v1`,c=`outbound-session-generation-v1`,l=`outbound-command-owner-v1`,u=[l,s,c];function outboundDeliveryQueueName(e){return e.deliveryCompletion?.kind===`pending-final`&&e.deliveryCompletion.commandOwnerReference!==void 0?l:e.sessionGeneration===void 0?s:c}[...u.map(e=>[e,`prepared`])];function projectOutboundDelivery(e,t){if(!u.some(t=>t===e))throw Error(`Unsupported outbound delivery format: ${e}`);let n=t;if(e===`outbound-command-owner-v1`){if(n.deliveryCompletion?.kind!==`pending-final`)throw Error(`Missing command-owner delivery completion: ${t.id}`);n.deliveryCompletion.commandOwnerReference??=null}if(e!==outboundDeliveryQueueName(n))throw Error(`Outbound delivery authority does not match its format: ${t.id}`);return n}function readOutboundDeliveriesInDatabase(s,c){let l=c.id===void 0&&c.mode===`unfinished`;if(l&&e(s.db,o))return[];let d=l&&n(s.db),f=i(s,u,c.mode).select(`queue_name`).orderBy(`enqueued_at`,`asc`).orderBy(`id`,`asc`);c.id!==void 0&&(f=f.where(`id`,`=`,c.id));let p=/* @__PURE__ */ new Set,m=r(s.db,f).rows.flatMap(e=>{let t=a(e);if(!t)return[];if(p.has(t.id))throw Error(`Ambiguous outbound delivery custody: ${t.id}`);return p.add(t.id),[{queueName:e.queue_name,entry:projectOutboundDelivery(e.queue_name,t)}]});return l&&!s.db.isTransaction&&d!==void 0&&d===n(s.db)&&t(s.db,o,m.length===0||void 0),m}export{readOutboundDeliveriesInDatabase};