UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 3.63 kB
import{n as e}from"./transcript-store-entry-Ch3rW6qd.mjs";import{a as t,o as n,r,u as i}from"./transcript-kysely-sync-CAP5xe3V.mjs";import{t as a}from"./transcript-session-accessor.sqlite-scope-helpers-LCM13IZK.mjs";import{t as o}from"./transcript-session-entry-snapshots-B1SDC3sn.mjs";import{t as s}from"./transcript-session-accessor.sqlite-status-BxqCNBm4.mjs";import{i as c,u as l}from"./transcript-store-maintenance-D8wNasjV.mjs";import{n as u,t as d}from"./transcript-session-accessor.sqlite-references-kQFI5a8W.mjs";import{n as f}from"./transcript-text-bytes-DrHX89-B.mjs";function*recentSessionHistoryIds(e,n){if(e.preserveRecentMs==null)return;let i=t(e.database.db),a=r(e.database.db,i.selectFrom(`session_windows`).innerJoin(`session_nodes`,`session_nodes.session_key`,`session_windows.session_key`).select([`session_nodes.current_session_id`,`session_nodes.session_key`,`session_nodes.updated_at`,`session_nodes.entry_json`,`session_windows.session_id`]).$if(n!==void 0,e=>e.where(`session_windows.session_id`,`=`,n))).rows;for(let t of a){let n=s(t);n&&l({key:t.session_key,entry:n,preserveRecentMs:e.preserveRecentMs})&&(yield t.session_id)}}function collectRecentSessionHistoryIds(e){return new Set(recentSessionHistoryIds(e))}function readDiskEvictableArchivedSessionBatchInDatabase(e,t){let n=Math.max(1,t.limit??64),i=[],l=new Set(t.liveSessionKeys),u=t.after;for(;i.length<n;){let d=a(e.db).selectFrom(`session_nodes`).select([`archived_at`,`current_session_id`,`entry_json`,`session_key`,`updated_at`]).select(o).where(`archived_at`,`is not`,null).orderBy(`archived_at`,`asc`).orderBy(`session_key`,`asc`).limit(64);if(u){let e=u;d=d.where(t=>t.or([t(`archived_at`,`>`,e.archivedAt),t.and([t(`archived_at`,`=`,e.archivedAt),t(`session_key`,`>`,e.sessionKey)])]))}let f=r(e.db,d).rows,p=0;for(let e of f){if(p+=1,e.archived_at==null)continue;u={archivedAt:e.archived_at,sessionKey:e.session_key};let r=s(e);if(r&&c({key:e.session_key,entry:r,preserveRecentMs:t.preserveRecentMs,preserveKeys:l})&&(i.push({archivedAt:e.archived_at,entry:r,sessionKey:e.session_key}),i.length>=n))break}let m=f.length<64&&p===f.length;if(i.length>=n||m)return{candidates:i,...u?{cursor:u}:{},exhausted:m}}return{candidates:i,...u?{cursor:u}:{},exhausted:!1}}function collectSessionAdmissionReferences(t){let r=/* @__PURE__ */ new Set,o=t.admissionIdentities;if(o.length===0)return r;for(let e of o)r.add(e);let c=new Set([...o].map(t=>e(t))),l=a(t.database.db),u=[];for(let r of n(t.database.db,l.selectFrom(`session_nodes`).select(e=>[`session_key`,f(t.database.db,e.ref(`session_key`)).as(`key_bytes`)])))c.has(e(r.session_key))&&u.push(r.key_bytes);let p=u.length?n(t.database.db,l.selectFrom(`session_nodes`).select([`entry_json`,`current_session_id`]).where(`session_key`,`in`,l.selectFrom(`session_nodes`).select(`session_key`).where(e=>e(f(t.database.db,e.ref(`session_key`)),`in`,i(u))))):[];for(let e of p){r.add(e.current_session_id);let t=s(e);if(t)for(let e of d(t))r.add(e)}let m=n(t.database.db,l.selectFrom(`session_windows`).select([`session_id`,`session_key`]));for(let t of m)c.has(e(t.session_key))&&r.add(t.session_id);return r}function readHistoricalSessionIdsInDatabase(e){let{database:t}=e,n=u(t,void 0,void 0,e);for(let t of collectSessionAdmissionReferences(e))n.add(t);for(let t of collectRecentSessionHistoryIds(e))n.add(t);let i=a(t.db);return r(t.db,i.selectFrom(`session_windows`).select(`session_id`).orderBy(`updated_at`,`asc`).orderBy(`session_id`,`asc`)).rows.flatMap(e=>n.has(e.session_id)?[]:[e.session_id])}export{readDiskEvictableArchivedSessionBatchInDatabase,readHistoricalSessionIdsInDatabase};