UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 4.16 kB
import{c as e,d as t}from"./transcript-sqlite-post-commit-B_pko32i.mjs";import{p as n}from"./transcript-sqlite-schema-facts-C1_zV4Yg.mjs";import{n as r}from"./transcript-agent-id-DmscQLD6.mjs";import{r as i}from"./transcript-openclaw-agent-db.paths-DbFl2s5M.mjs";import{n as a}from"./transcript-session-key-normalization-3Mbu27cw.mjs";import"./transcript-session-key-MDDhuEG9.mjs";import{f as o,r as s}from"./transcript-store-entry-Ch3rW6qd.mjs";import{a as c,o as l,r as u,u as d}from"./transcript-kysely-sync-CAP5xe3V.mjs";import{o as f}from"./transcript-sqlite-transaction-CBQXI8WC.mjs";import{a as p}from"./transcript-openclaw-agent-db-identity-BPgUuROx.mjs";import{n as m}from"./transcript-openclaw-agent-db-readonly-BfbPmTwU.mjs";import{i as h}from"./transcript-session-accessor.sqlite-scope-helpers-LCM13IZK.mjs";import{i as g}from"./transcript-session-accessor.sqlite-participant-projection-DbuxdQha.mjs";import{n as _,t as v}from"./transcript-session-accessor.sqlite-status-BxqCNBm4.mjs";import{n as y}from"./transcript-session-accessor.sqlite-entry-cache-Bojyjoad.mjs";import{t as b}from"./transcript-internal-session-key-aELBBJcF.mjs";import{c as x,u as S}from"./transcript-session-canonical-key-9wlUjrYM.mjs";import{o as C}from"./transcript-session-accessor.sqlite-read-scope-B5jiReWs.mjs";import{t as w}from"./transcript-session-accessor.sqlite-entry-selected.read-BznHmKXp.mjs";import{t as T}from"./transcript-session-entry-read-source-nTuZhEL_.mjs";function captureListingSource(e,t){if(!t.captureSource)return;let n=p(e),r={agentId:e.agentId,path:e.path,databaseIdentity:n.identity,databaseBirthtime:n.birthtime};T(r,e),t.captureSource(()=>T(r,typeof r.databaseIdentity==`symbol`?e:void 0))}function listSessionEntriesReadOnly(e={},t={}){let n=C({...e,sessionKey:``}),r=m(r=>{let read=()=>listSqliteSessionEntriesFromDatabase(r,n,e,t);return t.continuation?x(r,t.continuation,read):read()},h(n));return r.found?r.value:[]}function listSqliteSessionEntriesFromDatabase(s,p,m,h={}){captureListingSource(s,m);let b=h.deferParticipants||m.includeParticipants===!1?!0:void 0;if(m.sessionKeys&&!m.cronRetention&&!m.expiredCronRuns){let e=m.sessionKeys;return n(s.db,()=>{let t=w(s,e,m.projection===`list`?{}:{fullEntryKeys:e});return b?t:[...g(s.db,new Map(t.map(({sessionKey:e,entry:t})=>[e,t])))].map(([e,t])=>({sessionKey:e,entry:t}))})}if(m.cronRetention||m.expiredCronRuns){let n=m.expiredCronRuns,i=n?r(n.agentId):void 0,p=e(t(s.db),()=>f(s.db,()=>{let e=[];if(m.cronRetention){let t=m.cronRetention;for(let n of l(s.db,c(s.db).selectFrom(`session_nodes`).select(`session_key`).where(`session_key`,`>`,t.afterSessionKey??``).orderBy(`session_key`)))if(o(n.session_key)&&(e.push(n.session_key),e.length>=t.limit))break;h.captureCronRunSessionKey?.(e.length===t.limit?e.at(-1):null)}else for(let t of l(s.db,c(s.db).selectFrom(`session_nodes`).select(`session_key`).orderBy(`session_key`)))o(t.session_key)&&r(a(t.session_key).agentId)===i&&e.push(t.session_key);let t=w(s,e),f=null,p=t.filter(({sessionKey:e,entry:t})=>{if(!o(e)||n&&r(a(e).agentId)!==i)return!1;let s=t.updatedAt??0;return f=Math.min(f??s,s),!n||s<n.updatedBefore});h.captureCronRunUpdatedAt?.(f),b||(p=[...g(s.db,new Map(p.map(({sessionKey:e,entry:t})=>[e,t])))].map(([e,t])=>({sessionKey:e,entry:t})));let v=p.length?u(s.db,_(s,`full`).select(`updated_at`).where(`session_key`,`in`,d(p.map(({sessionKey:e})=>e)))).rows:[];return{entries:p,rows:v}})),y=new Map(p.rows.map(e=>[e.session_key,e]));for(let e of p.entries){let t=y.get(e.sessionKey);t&&(e.entry={...v(t),...e.entry})}return p.entries}let x=m.projection??`full`,S=!i(s.path,{agentId:s.agentId,env:p.env}),C=y(s,{cache:S,latest:m.readConsistency===`latest`,projection:x,deferParticipants:b});return Array.from(iterateSessionEntriesForListing(C,x===`list`&&m.clone!==!1))}function*iterateSessionEntriesForListing(e,t=!1){for(let n of e.keys){if(b(n))continue;let r=e.entries.get(n);if(!r)continue;let i=s(n,r);if(i!==n)throw S(`non-canonical persisted row resolves to session key ${i}`);yield{sessionKey:n,entry:t?structuredClone(r):r}}}export{listSqliteSessionEntriesFromDatabase as n,listSessionEntriesReadOnly as t};