openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.03 kB
JavaScript
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{Sr as t,Tr as n,br as r,wr as i,xr as a,yr as o}from"./control-ui-core-3P365fbR.js";import{Gn as s,Wn as c}from"./control-ui-core-CFW9Qtjn.js";import{a as l,d as u,f as d,i as f,l as p,n as m,r as h,s as g,u as _}from"./session-roster-cache.reader-EFFQX3Sf.js";function v(e){try{if(!n(e.query))return null;let t={...e,query:u(e.query),result:{...e.result,sessions:e.result.sessions.filter(h).map(d)}},r=JSON.stringify(t,(e,t)=>e===`avatarUrl`||e===`channelAvatarUrl`?void 0:t);return new TextEncoder().encode(r).byteLength<=1572864?l(JSON.parse(r)):null}catch{return null}}async function y(e,n){if(n!==t)return;let r=await f();if(r)try{if(n!==t)return;let i=r.transaction(o,`readwrite`),a=_(i),s=i.objectStore(o),c=await p(s.getAll()),u=new Map;for(let e of c){let t=l(e);if(!t){s.clear(),u.clear();break}u.set(t.scope,t)}for(let t of e){let e=v(t);e?(s.put(e),u.set(e.scope,e)):(s.delete(t.scope),u.delete(t.scope))}let d=[...u.values()].toSorted((e,t)=>t.savedAt-e.savedAt);for(let[e,t]of d.entries())(e>=6||Date.now()-t.savedAt>2592e6)&&s.delete(t.scope);await a}catch{r.close(),await g()}finally{r.close()}}function b(e,t){!globalThis.indexedDB||t<=(w.get(e.scope)??0)||(w.set(e.scope,t),C.set(e.scope,e),T!==null&&clearTimeout(T),T=setTimeout(()=>void x(),500))}async function x(){T!==null&&(clearTimeout(T),T=null);let e=[...C.values()];C.clear();let n=t;e.length>0&&(E=E.then(()=>y(e,n))),await E}async function S(){a(),c(),T!==null&&(clearTimeout(T),T=null),C.clear(),w.clear(),await E,await g()}var C,w,T,E;function D(){return(D=e((()=>{s(),i(),m(),r(),C=new Map,w=new Map,T=null,E=Promise.resolve(),globalThis.indexedDB&&typeof window<`u`&&typeof window.addEventListener==`function`&&typeof document<`u`&&typeof document.addEventListener==`function`&&(window.addEventListener(`pagehide`,()=>void x()),document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`hidden`&&x()}))})))()}D();export{S as clearCachedBootState,b as persistSessionRoster};