openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.76 kB
JavaScript
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{Eu as t,bn as n,ju as r,lu as i,sc as a,uu as o,xn as s,zu as c}from"./control-ui-core-BncvAZjR.js";import{Aa as l,Da as u,Ma as d,Pa as f,Sa as p,ba as m,d as h,f as g,ja as _,ka as v,va as y,wa as b}from"./control-ui-boot-shared-DJkUdZmL.js";function x(e,t){let n=b(e);if(t.length===0)return{gatewayOwner:n.gatewayOwner,retirements:[],storageFailed:!1};let r=c();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=[],o=[],s=!1;try{let e=p(r,n),c=!1;for(let u of t){if(!u.key.trim())return{gatewayOwner:n.gatewayOwner,retirements:i,storageFailed:!0};let t={sessionKey:u.key,agentId:u.agentId},f=a(t),p=e.sessions[f],m=p?.draftRevision??0,h=_(r,n.key,f,m).latestAttempt,g=u.retireBeforeRevision;m<u.retireBeforeRevision&&(g=l(Math.max(h,u.retireBeforeRevision)),d(r,n.key,f,g),s||=!!p?.draft||!!p?.queue?.length,e.sessions[f]={draftRevision:g,updatedAt:Date.now()},o.push({storeSessionKey:f,revision:g}),c=!0),i.push({scope:t,minimumRevision:g,retireBeforeRevision:u.retireBeforeRevision})}if(!c)return{gatewayOwner:n.gatewayOwner,retirements:i,storageFailed:!1};u(r,n,e);let h=p(r,n);for(let{storeSessionKey:e,revision:t}of o){let a=h.sessions[e];if(a?.draftRevision!==t||a.draft||a.queue?.length)return{gatewayOwner:n.gatewayOwner,retirements:i,storageFailed:!0};f(r,n.key,e,t)}return s&&m(),{gatewayOwner:n.gatewayOwner,retirements:i,storageFailed:!1}}catch{return{gatewayOwner:n.gatewayOwner,retirements:i,storageFailed:!0}}}function S(){return(S=e((()=>{v(),y()})))()}async function C(e,t,i){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:o}=t.client,s=x({settings:{gatewayUrl:t.gatewayUrl},client:t.client},i),c=s.retirements.map(e=>({scopeKey:`chat:v3:${a(e.scope)}`,minimumRevision:e.minimumRevision,retireBeforeRevision:e.retireBeforeRevision})),[,l]=await Promise.all([n({...t,settings:{gatewayUrl:t.gatewayUrl}},i),o&&r?g({gatewayOwner:s.gatewayOwner,recoveryScope:r},c):`storage-failed`]);if(s.storageFailed||l===`storage-failed`)throw Error(`Draft storage cleanup failed`)}catch{o({message:r(`sessionsView.draftCleanupFailed`)})}}function w(){return(w=e((()=>{t(),s(),i(),h(),S(),y()})))()}w();export{C as retireDeletedComposerDrafts};