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{Pu as t,_u as n,bn as r,mc as i,qu as a,vu as o,yn as s,zu as c}from"./control-ui-core-CBJ5efDh.js";import{Di as l,Ei as u,Oi as d,a as f,ci as p,i as m,ii as h,ji as g,ki as _,oi as v,pi as y,ui as b}from"./control-ui-boot-shared-UG5ko-VG.js";function x(e,t){let n=b(e);if(t.length===0)return{gatewayOwner:n.gatewayOwner,retirements:[],storageFailed:!1};let r=a();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 o=[],s=[],c=!1;try{let e=p(r,n);for(let a of t){if(!a.key.trim())return{gatewayOwner:n.gatewayOwner,retirements:o,storageFailed:!0};let t={sessionKey:a.key,agentId:a.agentId},u=i(t),f=e.sessions[u],p=f?.draftRevision??0,m=d(r,n.key,u,p).latestAttempt,h=a.retireBeforeRevision;p<a.retireBeforeRevision&&(h=l(Math.max(m,a.retireBeforeRevision)),_(r,n.key,u,h),c||=!!f?.draft||!!f?.queue?.length,e.sessions[u]={draftRevision:h,updatedAt:Date.now()},s.push({storeSessionKey:u,revision:h})),o.push({scope:t,minimumRevision:h,retireBeforeRevision:a.retireBeforeRevision})}if(s.length===0)return{gatewayOwner:n.gatewayOwner,retirements:o,storageFailed:!1};y(r,n,e);let a=p(r,n);for(let{storeSessionKey:e,revision:t}of s){let i=a.sessions[e];if(i?.draftRevision!==t||i.draft||i.queue?.length)return{gatewayOwner:n.gatewayOwner,retirements:o,storageFailed:!0};g(r,n.key,e,t)}return c&&v(),{gatewayOwner:n.gatewayOwner,retirements:o,storageFailed:!1}}catch{return{gatewayOwner:n.gatewayOwner,retirements:o,storageFailed:!0}}}function S(){return(S=e((()=>{u(),h()})))()}async function C(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:a}=t.client,o=x({settings:{gatewayUrl:t.gatewayUrl},client:t.client},n),c=o.retirements.map(e=>({scopeKey:`chat:v3:${i(e.scope)}`,minimumRevision:e.minimumRevision,retireBeforeRevision:e.retireBeforeRevision})),[,l]=await Promise.all([s({...t,settings:{gatewayUrl:t.gatewayUrl}},n),a&&r?f({gatewayOwner:o.gatewayOwner,recoveryScope:r},c):`storage-failed`]);if(o.storageFailed||l===`storage-failed`)throw Error(`Draft storage cleanup failed`)}catch{o({message:c(`sessionsView.draftCleanupFailed`)})}}function w(){return(w=e((()=>{t(),r(),n(),m(),S(),h()})))()}w();export{C as retireDeletedComposerDrafts};