openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
2 lines • 7.38 kB
JavaScript
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./user-prefs-request-BE7DKPZP.js","./control-ui-connection-D5QrEAFW.css","./control-ui-boot-shared-styles-BorAdMVO.css"])))=>i.map(i=>d[i]);
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Bn as t,Ln as n,Rn as r,Un as i,Wn as a,ar as o,er as s,lr as c,lu as l,rr as u,tr as d,uu as f,wc as p,xc as m}from"./control-ui-connection-Bfj9beF_.js";import{$x as h,AT as g,Jx as _,MT as v,Qx as y,Yx as b,Zx as x,bD as S,fT as C,jT as w,pT as T,qx as E,vD as D}from"./control-ui-boot-shared-DFTSUQQ0.js";import{a as O,i as k,r as A,t as j}from"./server-prefs-write-batch-CgG7ptxp.js";async function M(e,n,o){let f=()=>e.pushWriter===n&&e.pushEpoch===o;for(;e.pendingPrefs;){if(!f()||(e.reconcilePersistedPendingPrefs(),!e.pendingPrefs))return;let o=d.filter(t=>e.pendingPrefs?.[t]!==void 0&&(s[t].configSync===!1||t===`theme`&&typeof e.pendingPrefs.theme==`string`&&e.pendingPrefs.theme.includes(`/`))&&!(e.pushProfileId&&e.pushCanWrite));if(o.length){if(!n.state.connected)return;e.cancelPendingKeys(e.pendingScope,o),e.updateRetainedLocalKeys(e.pendingScope,o,!0),e.pushAfterCommit?.({needsRefresh:!1,retainedLocal:!0});continue}if(e.pushProfileId&&e.pendingPrefs.theme===`custom`){e.cancelPendingKeys(e.pendingScope,[`theme`]),e.updateRetainedLocalKeys(e.pendingScope,[`theme`],!0);continue}let m=e.pushProfileId&&e.pushCanWrite?k(e.pendingPrefs):{},v=Object.keys(m).length>0,x=v?m:{...e.pendingPrefs};if(v||(u(x),delete x.navigationConfirmation),!Object.keys(x).length){e.pendingPrefs=null,e.writePendingStorage(null),e.publishPreferenceWrites();return}if(v&&x.background!==void 0&&Object.keys(x).length>1){let{background:e,...t}=x;x=t}let C=e.pushAfterCommit,E=n.state.client,D=e.pushProfileId,j=E?.gatewayUrl??``,M=()=>f()&&n.state.client===E&&n.state.connected&&a(j)===D;if(v&&!M())return;let N;if(v&&x.background!==void 0&&E&&D){if(!e.pushCanWrite)return;let t=i(j,D);if(!t){T(E);try{if(!await _(E,D,j,{isCurrent:M})||!M())return}catch(t){M()&&e.batchIsCurrent(x)&&(e.recordPreferenceWriteFailures(e.pendingScope,{background:x.background},t),e.publishPreferenceWrites());return}if(e.reconcilePersistedPendingPrefs(),!e.batchIsCurrent(x))continue;t=i(j,D)}if(!t)return;N=t.background??null}let P=x.sidebarEntries!==void 0,F=x.sidebarEntries,I=!1,L=!1,R=(t,n)=>{n.sidebarEntries&&(!t?.sidebarEntries||!c(n.sidebarEntriesBase,t.sidebarEntries)?e.composeSidebar=null:(F=g(F,t.sidebarEntries,n.sidebarEntries),I=!0,L||=w(n)))};F&&(e.composeSidebar=R);try{for(let a=0;a<2;a+=1){if(!f()||v&&!M())return;v&&n.state.client&&(r(),T(n.state.client));let o={},m=i(j,D),g=v?await l(async()=>{let{writeProfileAppearancePrefs:e}=await import(`./server-prefs-profile-runtime-BOA5SpPv.js`).then(e=>(e.n(),e.r));return{writeProfileAppearancePrefs:e}},__vite__mapDeps([0,1,2]),import.meta.url).then(({writeProfileAppearancePrefs:t})=>t(n.state.client,x,()=>!M()||!e.pushCanWrite?!1:(e.reconcilePersistedPendingPrefs(),e.batchIsCurrent(x)?(P&&(o=h(e,e.pendingScope)??{}),!0):(e.drainRequested=!!e.pendingPrefs,!1)),D,N)):await n.runExternalMutation(e=>e.request(`config.patch`,{raw:JSON.stringify({ui:{prefs:x}}),note:`control-ui prefs sync`}),{waitForWritesResumed:!0,configWriteAck:e=>e,shouldRefresh:()=>!1,canDispatch:()=>!f()||n.state.client!==E||n.canPatch===!1?!1:(e.reconcilePersistedPendingPrefs(),e.batchIsCurrent(x)?!0:(e.drainRequested=!!e.pendingPrefs,!1)),dispatchError:`Access changed before preferences could sync.`});if(!f()||v&&!M())return;e.reconcilePersistedPendingPrefs();let _=`batch`in g?g.batch:x,w=Object.hasOwn(_,`sidebarEntries`)?{..._,sidebarEntriesBase:x.sidebarEntriesBase,sidebarEntriesOrder:x.sidebarEntriesOrder}:_;if(g.ok){v&&r();for(let t of d){if(!Object.hasOwn(_,t))continue;let n=e.preferenceWriteFailures.get(e.pendingScope);c(n?.get(t)?.value,_[t])&&n?.delete(t)}let a=`committedBatch`in g?g.committedBatch??_:_,l=h(e,e.pendingScope)??{};if(P&&E&&D&&e.pendingPrefs&&Object.hasOwn(e.pendingPrefs,`sidebarEntries`)&&i(j,D)!==m&&!c(l.sidebarEntries,a.sidebarEntries)){if(T(E),await b({client:E,profileId:D,scope:j,configObject:n.state.configSnapshot?.config,onApplied:()=>void 0,isCurrent:M}).catch(()=>!1),!f()||!M())return;e.reconcilePersistedPendingPrefs(),l=h(e,e.pendingScope)??{}}let p=v?i(n.state.client?.gatewayUrl??``,e.pushProfileId):null,x={...a},S=!1,k={},N={};if(P){let t=s.sidebarEntries.extract(l.sidebarEntries);p&&t!==void 0&&(k.sidebarEntries=t);let n=e.pendingPrefs&&Object.hasOwn(e.pendingPrefs,`sidebarEntries`),r=!c(l.sidebarEntries,o.sidebarEntries)&&!c(l.sidebarEntries,a.sidebarEntries);Object.hasOwn(x,`sidebarEntries`)&&(!n||r)&&(delete x.sidebarEntries,S=!0,n&&r&&t!==void 0&&(N.sidebarEntries=t))}v&&D&&t(j,D,k),I&&e.composeSidebar===R&&e.pendingPrefs?.sidebarEntries&&w.sidebarEntries&&(e.pendingPrefs.sidebarEntriesBase=F,e.pendingPrefs.sidebarEntriesOrder=L||void 0,delete w.sidebarEntries,u(w)),e.pendingPrefs=A(e.pendingPrefs,w,e.pendingPersistedKeys),v&&D&&t(j,D,x);let z=O(l,x,p,n.state.configSnapshot?.config);if(v&&!S&&(e.lastReconciledConfigObject=null),x.sidebarEntries&&(N.sidebarEntries=x.sidebarEntries),e.pendingPrefs&&Object.hasOwn(e.pendingPrefs,`sidebarEntries`)&&delete N.sidebarEntries,Object.keys(N).length&&e.applyServerPrefsPatch(N),Object.keys(x).length&&y(e,e.pendingScope,z),e.mergePendingIntoStorage(w),e.publishPreferenceWrites(),!f()||(!S&&g.refresh.ok&&C&&e.lastReconciledScope===e.pendingScope&&(e.lastReconciledConfigObject=null),S||C?.({needsRefresh:!g.refresh.ok}),!f()))return;break}if(g.reason===`conflict`&&v&&_.background!==void 0&&E&&D){let t=e.pendingPrefs&&Object.hasOwn(e.pendingPrefs,`background`)?e.pendingPrefs.background:_.background;if(e.cancelPendingKeys(e.pendingScope,[`background`]),e.recordPreferenceWriteFailures(e.pendingScope,{background:t},`Background changed elsewhere. Review the latest selection, then retry your change.`,!0),e.updateRetainedLocalKeys(e.pendingScope,[`background`],!0),e.publishPreferenceWrites(),r(!0),T(E),await b({client:E,profileId:D,scope:j,configObject:n.state.configSnapshot?.config,onApplied:()=>void 0,isCurrent:M}).catch(()=>!1),M()&&C?.({needsRefresh:!1,retainedLocal:!0}),!M())return;break}if(g.reason===`conflict`&&a===0)await p(250);else{if(g.reason===`conflict`){e.recordPreferenceWriteFailures(e.pendingScope,_,g.error),e.publishPreferenceWrites();return}if(g.reason===`error`||g.reason===`rejected`){let t=Object.fromEntries(d.filter(t=>Object.hasOwn(_,t)&&e.pendingPrefs&&Object.hasOwn(e.pendingPrefs,t)&&c(e.pendingPrefs[t],_[t])).map(e=>[e,_[e]]));e.recordPreferenceWriteFailures(e.pendingScope,t,g.error,g.reason===`rejected`);let n=s.sidebarEntries.extract(t.sidebarEntries);g.reason===`rejected`&&n&&e.batchIsCurrent(w)&&(e.applyServerPrefsPatch({sidebarEntries:n}),e.updateRetainedLocalKeys(e.pendingScope,[`sidebarEntries`],!0),S({message:g.error})),e.publishPreferenceWrites()}if(g.reason===`unavailable`&&n.state.connected&&!e.batchIsCurrent(_))break;if(g.reason===`error`||g.reason===`unavailable`||g.reason===`suspended`)return;e.pendingPrefs=A(e.pendingPrefs,w,e.pendingPersistedKeys),e.mergePendingIntoStorage(w),e.publishPreferenceWrites(),C?.({needsRefresh:!1,retainedLocal:!0});break}}}finally{e.composeSidebar===R&&(e.composeSidebar=null)}}}function N(){return(N=e((()=>{m(),D(),x(),v(),n(),E(),o(),j(),C(),f()})))()}N();export{M as drainPendingPrefs};