openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 3.64 kB
JavaScript
import{n as e,r as t}from"./rolldown-runtime-CNOWq4Kh.js";import{$n as n,At as r,Ba as i,Ua as a,ar as o,er as s,et as c,ir as l,jt as u,lr as d,na as f,nr as p,or as m,sa as h,sr as g,tt as _,za as v}from"./control-ui-connection-Bfj9beF_.js";import{fT as y,mT as b,pT as x}from"./control-ui-boot-shared-DFTSUQQ0.js";import{n as S,t as C}from"./server-prefs-write-batch-CgG7ptxp.js";import{n as w,t as T}from"./user-prefs-request-BE7DKPZP.js";var E=t({canSyncAppearancePreference:()=>D,loadProfileAppearancePrefs:()=>A,readProfileAppearancePrefs:()=>k,writeProfileAppearancePrefs:()=>O});function D(e,t){let{runtimeConfig:n}=e;if(!n.state.connected)return null;let i=e.gateway.snapshot;return t&&s[t].configSync===!1&&!i.selfUser?!1:t&&i.selfUser?r(i.hello?.auth??null):n.canPatch!==!1}async function O(e,t,n,r,i){let o=t,l=(e,t=`unavailable`,n=o)=>({ok:!1,reason:t,error:e,batch:n}),u=Object.keys(o).some(g);u&&(o=Object.fromEntries(Object.entries(o).filter(([e])=>g(e))));let h=o.theme!==void 0||o.themeMode!==void 0;if(h&&(o=Object.fromEntries(Object.entries(o).filter(([e])=>[`theme`,`themeMode`,`accent`,`fontUi`,`fontChat`].includes(e)))),!e||!n())return l(`Profile preferences are unavailable.`);if(o.background!==void 0&&i===void 0)return l(`Background preferences have not loaded.`);h&&x(e);try{if(u){if(!r)return l(`Navigation profile is unavailable.`);let i=t.sidebarEntriesBase,a=Object.keys(o).filter(g),c=await w(e,r,{keys:a.map(e=>p[e])});if(!n()||c.status!==`ok`)return l(`Navigation preferences are unavailable.`);let u={...o};if(Array.isArray(o.sidebarEntries)){let e=s.sidebarEntries.extract(i),n=s.sidebarEntries.extract(c.entries[p.sidebarEntries]??f);if(!e||!d(e,i))return l(`Shortcuts are saved only on this device because their previous sync state is missing. Edit a shortcut to sync again.`,`rejected`,{sidebarEntries:o.sidebarEntries});if(!n)return l(`Navigation preferences are unavailable.`);u.sidebarEntries=S(e,o.sidebarEntries,n,t.sidebarEntriesOrder)}let m=Object.fromEntries(a.map(e=>[p[e],u[e]])),h=Object.fromEntries(a.map(e=>{let t=p[e];return[t,c.entries[t]??null]})),_=await b(e,{entries:m,expectedEntries:h});return _.status===`ok`?{ok:!0,value:_,refresh:{ok:!0},batch:o,committedBatch:u}:l(`Navigation preferences changed or are unavailable.`,_.status===`conflict`?`conflict`:`unavailable`)}if(h){let t={...o.accent===void 0?{}:{accent:o.accent},...o.fontUi===void 0?{}:{fontUi:o.fontUi},...o.fontChat===void 0?{}:{fontChat:o.fontChat}};return{ok:!0,value:await e.request(`themes.set`,{...o.theme===void 0?{}:{id:o.theme},...o.themeMode===void 0?{}:{mode:o.themeMode},...Object.keys(t).length?{appearance:t}:{}}),refresh:{ok:!0},batch:o}}if(o.tabIcon!=null&&!a(o.tabIcon))return l(`Invalid tab icon preference.`,`rejected`);let c=Object.fromEntries(Object.entries(o).flatMap(([e,t])=>m(e)?[[v[e],t]]:[])),_=await b(e,{entries:c,...o.background===void 0?{}:{expectedEntries:{[v.background]:i}}});return _.status===`ok`?{ok:!0,value:_,refresh:{ok:!0},batch:o}:l(`Profile preferences are unavailable.`,_.status===`conflict`?`conflict`:`rejected`)}catch(e){let t=e instanceof c&&(e.gatewayCode===`INVALID_REQUEST`||e.gatewayCode===`FORBIDDEN`);return l(e instanceof Error?e.message:String(e),t?`rejected`:`error`)}finally{h&&x(e)}}async function k(e,t){let r=await w(e,t,{keys:n});return r.status===`ok`?l(r.entries):null}async function A(e,t,n,r,i,a){if(a!==i.requestId)return!1;let o=()=>a===i.requestId&&(r?.isCurrent()??!0),s=await k(e,t);return!o()||!s?!1:(i.appearance={profileId:t,scope:n,prefs:s},!0)}function j(){return(j=e((()=>{i(),_(),h(),u(),o(),C(),y(),T()})))()}export{j as n,E as r,D as t};