openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
2 lines • 7.53 kB
JavaScript
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./user-prefs-request-DMVPtOdQ.js","./_1____________________________.css","./_0____________________________________.css"])))=>i.map(i=>d[i]);
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{$t as t,$u as n,Qu as r,Rl as i,Vl as a,_n as o,an as s,en as c,fn as l,hn as u,nn as d,on as f,pn as p,vn as m,xn as h}from"./_4____________________________.js";import{BS as g,HS as _,RS as v,US as y,WS as b,bD as x,eD as S,fk as C,mk as w,tD as T,vD as E,yD as D,zS as O}from"./_2_____________________________.js";import{a as k,i as A,r as j,t as M}from"./server-prefs-write-batch-BFG8yduO.js";async function N(e,t,n){let i=()=>e.pushWriter===t&&e.pushEpoch===n;for(;e.pendingPrefs;){if(!i()||(e.reconcilePersistedPendingPrefs(),!e.pendingPrefs))return;let n=p.filter(t=>e.pendingPrefs?.[t]!==void 0&&(l[t].configSync===!1||t===`theme`&&typeof e.pendingPrefs.theme==`string`&&e.pendingPrefs.theme.includes(`/`))&&!(e.pushProfileId&&e.pushCanWrite));if(n.length){if(!t.state.connected)return;e.cancelPendingKeys(e.pendingScope,n),e.updateRetainedLocalKeys(e.pendingScope,n,!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 o=e.pushProfileId&&e.pushCanWrite?A(e.pendingPrefs):{},_=Object.keys(o).length>0,v=_?o:{...e.pendingPrefs};if(_||(u(v),delete v.navigationConfirmation),!Object.keys(v).length){e.pendingPrefs=null,e.writePendingStorage(null),e.publishPreferenceWrites();return}if(_&&v.background!==void 0&&Object.keys(v).length>1){let{background:e,...t}=v;v=t}let x=e.pushAfterCommit,S=t.state.client,C=e.pushProfileId,M=S?.gatewayUrl??``,N=()=>i()&&t.state.client===S&&t.state.connected&&f(M)===C;if(_&&!N())return;let P;if(_&&v.background!==void 0&&S&&C){if(!e.pushCanWrite)return;let t=s(M,C);if(!t){T(S);try{if(!await O(S,C,M,{isCurrent:N})||!N())return}catch(t){N()&&e.batchIsCurrent(v)&&(e.recordPreferenceWriteFailures(e.pendingScope,{background:v.background},t),e.publishPreferenceWrites());return}if(e.reconcilePersistedPendingPrefs(),!e.batchIsCurrent(v))continue;t=s(M,C)}if(!t)return;P=t.background??null}let F=v.sidebarEntries!==void 0,I=v.sidebarEntries,L=!1,R=!1,z=(t,n)=>{n.sidebarEntries&&(!t?.sidebarEntries||!h(n.sidebarEntriesBase,t.sidebarEntries)?e.composeSidebar=null:(I=E(I,t.sidebarEntries,n.sidebarEntries),L=!0,R||=D(n)))};I&&(e.composeSidebar=z);try{for(let n=0;n<2;n+=1){if(!i()||_&&!N())return;_&&t.state.client&&(c(),T(t.state.client));let o={},f=s(M,C),E=_?await r(async()=>{let{writeProfileAppearancePrefs:e}=await import(`./server-prefs-profile-runtime-CMyNoQ-O.js`).then(e=>(e.n(),e.r));return{writeProfileAppearancePrefs:e}},__vite__mapDeps([0,1,2]),import.meta.url).then(({writeProfileAppearancePrefs:n})=>n(t.state.client,v,()=>!N()||!e.pushCanWrite?!1:(e.reconcilePersistedPendingPrefs(),e.batchIsCurrent(v)?(F&&(o=b(e,e.pendingScope)??{}),!0):(e.drainRequested=!!e.pendingPrefs,!1)),C,P)):await t.runExternalMutation(e=>e.request(`config.patch`,{raw:JSON.stringify({ui:{prefs:v}}),note:`control-ui prefs sync`}),{waitForWritesResumed:!0,configWriteAck:e=>e,shouldRefresh:()=>!1,canDispatch:()=>!i()||t.state.client!==S||t.canPatch===!1?!1:(e.reconcilePersistedPendingPrefs(),e.batchIsCurrent(v)?!0:(e.drainRequested=!!e.pendingPrefs,!1)),dispatchError:`Access changed before preferences could sync.`});if(!i()||_&&!N())return;e.reconcilePersistedPendingPrefs();let D=`batch`in E?E.batch:v,O=Object.hasOwn(D,`sidebarEntries`)?{...D,sidebarEntriesBase:v.sidebarEntriesBase,sidebarEntriesOrder:v.sidebarEntriesOrder}:D;if(E.ok){_&&c();for(let t of p){if(!Object.hasOwn(D,t))continue;let n=e.preferenceWriteFailures.get(e.pendingScope);h(n?.get(t)?.value,D[t])&&n?.delete(t)}let n=`committedBatch`in E?E.committedBatch??D:D,r=b(e,e.pendingScope)??{};if(F&&S&&C&&e.pendingPrefs&&Object.hasOwn(e.pendingPrefs,`sidebarEntries`)&&s(M,C)!==f&&!h(r.sidebarEntries,n.sidebarEntries)){if(T(S),await g({client:S,profileId:C,scope:M,configObject:t.state.configSnapshot?.config,onApplied:()=>void 0,isCurrent:N}).catch(()=>!1),!i()||!N())return;e.reconcilePersistedPendingPrefs(),r=b(e,e.pendingScope)??{}}let a=_?s(t.state.client?.gatewayUrl??``,e.pushProfileId):null,m={...n},v=!1,w={},A={};if(F){let t=l.sidebarEntries.extract(r.sidebarEntries);a&&t!==void 0&&(w.sidebarEntries=t);let i=e.pendingPrefs&&Object.hasOwn(e.pendingPrefs,`sidebarEntries`),s=!h(r.sidebarEntries,o.sidebarEntries)&&!h(r.sidebarEntries,n.sidebarEntries);Object.hasOwn(m,`sidebarEntries`)&&(!i||s)&&(delete m.sidebarEntries,v=!0,i&&s&&t!==void 0&&(A.sidebarEntries=t))}_&&C&&d(M,C,w),L&&e.composeSidebar===z&&e.pendingPrefs?.sidebarEntries&&O.sidebarEntries&&(e.pendingPrefs.sidebarEntriesBase=I,e.pendingPrefs.sidebarEntriesOrder=R||void 0,delete O.sidebarEntries,u(O)),e.pendingPrefs=j(e.pendingPrefs,O,e.pendingPersistedKeys),_&&C&&d(M,C,m);let P=k(r,m,a,t.state.configSnapshot?.config);if(_&&!v&&(e.lastReconciledConfigObject=null),m.sidebarEntries&&(A.sidebarEntries=m.sidebarEntries),e.pendingPrefs&&Object.hasOwn(e.pendingPrefs,`sidebarEntries`)&&delete A.sidebarEntries,Object.keys(A).length&&e.applyServerPrefsPatch(A),Object.keys(m).length&&y(e,e.pendingScope,P),e.mergePendingIntoStorage(O),e.publishPreferenceWrites(),!i()||(!v&&E.refresh.ok&&x&&e.lastReconciledScope===e.pendingScope&&(e.lastReconciledConfigObject=null),v||x?.({needsRefresh:!E.refresh.ok}),!i()))return;break}if(E.reason===`conflict`&&_&&D.background!==void 0&&S&&C){let n=e.pendingPrefs&&Object.hasOwn(e.pendingPrefs,`background`)?e.pendingPrefs.background:D.background;if(e.cancelPendingKeys(e.pendingScope,[`background`]),e.recordPreferenceWriteFailures(e.pendingScope,{background:n},`Background changed elsewhere. Review the latest selection, then retry your change.`,!0),e.updateRetainedLocalKeys(e.pendingScope,[`background`],!0),e.publishPreferenceWrites(),c(!0),T(S),await g({client:S,profileId:C,scope:M,configObject:t.state.configSnapshot?.config,onApplied:()=>void 0,isCurrent:N}).catch(()=>!1),N()&&x?.({needsRefresh:!1,retainedLocal:!0}),!N())return;break}if(E.reason===`conflict`&&n===0)await a(250);else{if(E.reason===`conflict`){e.recordPreferenceWriteFailures(e.pendingScope,D,E.error),e.publishPreferenceWrites();return}if(E.reason===`error`||E.reason===`rejected`){let t=Object.fromEntries(p.filter(t=>Object.hasOwn(D,t)&&e.pendingPrefs&&Object.hasOwn(e.pendingPrefs,t)&&h(e.pendingPrefs[t],D[t])).map(e=>[e,D[e]]));e.recordPreferenceWriteFailures(e.pendingScope,t,E.error,E.reason===`rejected`),_&&E.reason===`rejected`&&e.updateRetainedLocalKeys(e.pendingScope,p.filter(e=>m(e)&&Object.hasOwn(t,e)),!0);let n=l.sidebarEntries.extract(t.sidebarEntries);E.reason===`rejected`&&n&&e.batchIsCurrent(O)&&(e.applyServerPrefsPatch({sidebarEntries:n}),e.updateRetainedLocalKeys(e.pendingScope,[`sidebarEntries`],!0),w({placement:`top-right`,severity:`error`,message:E.error})),e.publishPreferenceWrites()}if(E.reason===`unavailable`&&t.state.connected&&!e.batchIsCurrent(D))break;if(E.reason===`error`||E.reason===`unavailable`||E.reason===`suspended`)return;e.pendingPrefs=j(e.pendingPrefs,O,e.pendingPersistedKeys),e.mergePendingIntoStorage(O),e.publishPreferenceWrites(),x?.({needsRefresh:!1,retainedLocal:!0});break}}}finally{e.composeSidebar===z&&(e.composeSidebar=null)}}}function P(){return(P=e((()=>{i(),C(),_(),x(),t(),v(),o(),M(),S(),n()})))()}P();export{N as drainPendingPrefs};