UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 3 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{$n as t,Pi as n,Zn as r}from"./_4____________________________.js";import{$k as i,AN as a,Dx as o,EN as s,eA as c}from"./_2_____________________________.js";import{n as l,r as u}from"./theme-palette-Dps8CLSX.js";function d(e,t,i){let a={themes:[],error:null},o=e.connection.gatewayUrl,l=e.snapshot.client,d=e.snapshot.selfUser?.id,f=e.snapshot.phase===`connected`,p=!1,m=new Map,h=new Map,g=new Set,_={},v=Promise.withResolvers(),y,b=new Map,x=new Map,S=()=>{v.resolve(),v=Promise.withResolvers(),_={},y=void 0,b.clear(),x.clear()},C=e=>{let t=a.error??h.get(e)??h.values().next().value??null;return{...a,error:t,palettes:new Map(Array.from(m,([e,t])=>[e,t.palette]))}},w=(t,n)=>!p&&e.snapshot.phase===`connected`&&e.snapshot.client===t&&e.snapshot.selfUser?.id===n,T=e=>{let t=e.definition,n=e.theme.source===`plugin`?e.theme.artwork:void 0,r=t?.light??t?.dark,i=t?.dark??t?.light;t&&r&&i&&(h.delete(e.theme.id),m.set(e.theme.id,{branding:{...c(t),...n?{artwork:n}:{}},mode:t.light?t.dark?void 0:`light`:`dark`,palette:{light:u(`light`,r,void 0),dark:u(`dark`,i,void 0)}}),g.add(e.theme.id),x.clear())},E=()=>{let n=e.snapshot.client;if(p||e.snapshot.phase!==`connected`||!n)return;l=n,d=e.snapshot.selfUser?.id;let o=d;g.clear(),h.clear(),b.clear();let c=(async()=>{try{let e=await n.request(`themes.list`,{});if(!w(n,o))return;let r=new Set(e.themes.map(e=>e.id));for(let e of[m,h])for(let t of e.keys())r.has(t)||e.delete(t);T(e),a={themes:e.themes,error:null,unavailableId:e.current.requestedId},t()}catch(e){w(n,o)&&(a={...a,error:e instanceof r?e:s(e)},t())}})();return y=c,x.clear(),i?.(),c},D=o=>{let c=e.snapshot.client;if(o===`custom`||n(o)||g.has(o)||!a.themes.some(e=>e.id===o)||e.snapshot.phase!==`connected`||!c)return;g.add(o);let l=e.snapshot.selfUser?.id,u=c.request(`themes.get`,{id:o}).then(e=>{w(c,l)&&(T(e),t())},e=>{w(c,l)&&(h.set(o,e instanceof r?e:s(e)),x.clear(),t())});b.set(o,u),x.delete(o),i?.()},O=()=>{m.clear(),h.clear(),g.clear(),a={themes:[],error:null},t()},k=e.subscribe(()=>{let t=e.snapshot.phase===`connected`,n=e.connection.gatewayUrl!==o;if(!t)(f||n)&&S(),f=!1,n&&(o=e.connection.gatewayUrl,d=void 0,l=null,O());else if(!f||n||e.snapshot.client!==l||e.snapshot.selfUser?.id!==d){S();let t=e.snapshot.selfUser?.id!==d;f=!0,o=e.connection.gatewayUrl,l=e.snapshot.client,d=e.snapshot.selfUser?.id,(n||t)&&O(),E()}}),A=e.subscribeEvents(t=>{(t.event===`plugins.changed`||t.event===`users.prefs.changed`&&e.snapshot.selfUser?.id)&&E()});return f&&queueMicrotask(()=>{p||E()}),{snapshot(e){for(let e of a.themes)D(e.id);let t=C(e);if(!y&&!b.has(e))return t;let n=x.get(e);if(!n){let t=_;n={scope:t,result:Promise.race([Promise.all([y,b.get(e)]),v.promise]).then(()=>!p&&t===_?C(e):void 0)},x.set(e,n)}return{...t,read:n}},theme(e){return D(e),m.get(e)},refresh:E,dispose(){p=!0,S(),k(),A(),m.clear(),h.clear()}}}function f(){return(f=e((()=>{i(),o(),a(),t(),l()})))()}f();export{d as createThemeCatalog};