UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 1.86 kB
import"./openclaw-state-read-map-size-DJbMcZYM.mjs";import{D as e,s as t,x as n}from"./openclaw-state-read-sqlite-database-admission-Ck6VG7rE.mjs";import{r}from"./openclaw-state-read-kysely-sync-DQyYiAw5.mjs";import"./openclaw-state-read-sqlite-transaction-V1rK3HH2.mjs";import"./openclaw-state-read-sqlite-number-CpW6Oa2f.mjs";import{ct as i,dt as a,st as o}from"./openclaw-state-read.worker.js";import"./openclaw-state-read-secure-random-Bwhk0Eun.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&&t(s.db,a))return[];let d=l&&e(s.db),f=o(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=i(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===e(s.db)&&n(s.db,a,m.length===0||void 0),m}export{readOutboundDeliveriesInDatabase};