UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

2 lines • 3.35 kB
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./_1____________________________.css"])))=>i.map(i=>d[i]); import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{$u as t,Fa as n,Pa as r,Qu as i,li as a,oi as o,qa as s}from"./_4____________________________.js";import{$g as c,J as l,OD as u,Yg as d,Zg as f,__ as p,fk as m,g_ as h,h_ as g,i_ as _,m_ as v,mk as y,q as b,t_ as x,y_ as S}from"./_2_____________________________.js";function C(e,t){let r=t.map(({key:t,agentId:r})=>n(e,{sessionKey:t,agentId:r}));return i(async()=>{let{deleteStoredChatSnapshot:e}=await import(`./_4____________________________.js`).then(e=>(e.Ui(),e.Wi));return{deleteStoredChatSnapshot:e}},__vite__mapDeps([0]),import.meta.url).then(({deleteStoredChatSnapshot:e})=>Promise.all(r.map(t=>e(t))).then(()=>void 0))}function w(){return(w=e((()=>{r(),t()})))()}function T(e,t){let n=x(e);if(t.length===0)return{gatewayOwner:n.gatewayOwner,retirements:[],storageFailed:!1};let r=s();if(!r)return{gatewayOwner:n.gatewayOwner,retirements:t.flatMap(e=>e.key.trim()?[{scope:{sessionKey:e.key,agentId:e.agentId},minimumRevision:e.retireBeforeRevision,retireBeforeRevision:e.retireBeforeRevision}]:[]),storageFailed:!0};let i=[],a=[],o=!1;try{let e=c(r,n);for(let s of t){if(!s.key.trim())return{gatewayOwner:n.gatewayOwner,retirements:i,storageFailed:!0};let t={sessionKey:s.key,agentId:s.agentId},c=u(t),l=e.sessions[c],d=l?.draftRevision??0,f=h(r,n.key,c,d).latestAttempt,m=s.retireBeforeRevision;d<s.retireBeforeRevision&&(m=g(Math.max(f,s.retireBeforeRevision)),p(r,n.key,c,m),o||=!!l?.draft||!!l?.queue?.length,e.sessions[c]={draftRevision:m,updatedAt:Date.now()},a.push({storeSessionKey:c,revision:m})),i.push({scope:t,minimumRevision:m,retireBeforeRevision:s.retireBeforeRevision})}if(a.length===0)return{gatewayOwner:n.gatewayOwner,retirements:i,storageFailed:!1};_(r,n,e);let s=c(r,n);for(let{storeSessionKey:e,revision:t}of a){let a=s.sessions[e];if(a?.draftRevision!==t||a.draft||a.queue?.length)return{gatewayOwner:n.gatewayOwner,retirements:i,storageFailed:!0};S(r,n.key,e,t)}return o&&f(),{gatewayOwner:n.gatewayOwner,retirements:i,storageFailed:!1}}catch{return{gatewayOwner:n.gatewayOwner,retirements:i,storageFailed:!0}}}function E(){return(E=e((()=>{v(),d()})))()}async function D(e,t,n){try{if(t.client&&!t.client.recoveryScopeReady&&t.isCurrent()){let n=()=>{},r;await new Promise((i,a)=>{r=setTimeout(()=>a(Error(`Draft recovery scope unavailable`)),1e4);let o=()=>{(t.client?.recoveryScopeReady||!t.isCurrent())&&i()};n=e.gateway.subscribe(o),o()}).finally(()=>{clearTimeout(r),n()})}if(!t.client||!t.isCurrent())throw Error(`Draft cleanup connection changed`);let{recoveryScope:r,recoveryScopeReady:i}=t.client,a=T({settings:{gatewayUrl:t.gatewayUrl},client:t.client},n),o=a.retirements.map(e=>({scopeKey:`chat:v3:${u(e.scope)}`,minimumRevision:e.minimumRevision,retireBeforeRevision:e.retireBeforeRevision})),[,s]=await Promise.all([C({...t,settings:{gatewayUrl:t.gatewayUrl}},n),i&&r?l({gatewayOwner:a.gatewayOwner,recoveryScope:r},o):`storage-failed`]);if(a.storageFailed||s===`storage-failed`)throw Error(`Draft storage cleanup failed`)}catch{y({placement:`top-right`,severity:`warning`,message:a(`sessionsView.draftCleanupFailed`)})}}function O(){return(O=e((()=>{o(),w(),m(),b(),E(),d()})))()}O();export{D as retireDeletedComposerDrafts};