UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.57 kB
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{A as t,D as n,R as r,j as i}from"./control-ui-foundation-ZY_Flbbd.js";import{n as a,t as o}from"./theme-palette-CTWKNgGC.js";function s(e,n){let o={themes:[],error:null},s=e.connection.gatewayUrl,c=e.snapshot.client,l=e.snapshot.selfUser?.id,u=e.snapshot.phase===`connected`,d=0,f=!1,p=new Map,m=new Map,h=new Set,g=t=>!f&&t===d&&e.snapshot.phase===`connected`&&e.snapshot.client===c&&e.snapshot.selfUser?.id===l,_=e=>{let n,r=e.theme.source===`plugin`?e.theme.artwork:void 0;try{n=t(e.definition,{hatIds:Object.keys(r?.hats??{}),critterIds:Object.keys(r?.critters??{})})}catch{return}let o=n?.light??n?.dark,s=n?.dark??n?.light;n&&o&&s&&(m.delete(e.theme.id),p.set(e.theme.id,{generation:d,theme:{branding:{...i(n),...r?{artwork:r}:{}},mode:n.light?n.dark?void 0:`light`:`dark`,palette:{light:a(`light`,o,void 0),dark:a(`dark`,s,void 0)}}}))},v=async()=>{let t=e.snapshot.client;if(f||e.snapshot.phase!==`connected`||!t)return;c=t,l=e.snapshot.selfUser?.id;let r=++d;h.clear(),m.clear();try{let e=await t.request(`themes.list`,{});if(!g(r))return;let i=new Set(e.themes.map(e=>e.id));for(let e of p.keys())i.has(e)||p.delete(e);for(let e of m.keys())i.has(e)||m.delete(e);_(e),o={themes:e.themes,error:null,unavailableId:e.current.requestedId},n()}catch(e){g(r)&&(o={...o,error:e instanceof Error?e.message:String(e)},n())}},y=t=>{let i=e.snapshot.client;if(t===`custom`||r(t)||p.get(t)?.generation===d||h.has(t)||!o.themes.some(e=>e.id===t)||e.snapshot.phase!==`connected`||!i)return;h.add(t);let a=d,s=()=>g(a)&&o.themes.some(e=>e.id===t);i.request(`themes.get`,{id:t}).then(e=>{s()&&(_(e),n())},e=>{s()&&(m.set(t,e instanceof Error?e.message:String(e)),n())})},b=()=>{p.clear(),m.clear(),h.clear(),o={themes:[],error:null},n()},x=e.subscribe(()=>{let t=e.snapshot.phase===`connected`,n=e.connection.gatewayUrl!==s;if(!t){(u||n)&&(d+=1),u=!1,n&&(s=e.connection.gatewayUrl,l=void 0,c=null,b());return}if(!u||n||e.snapshot.client!==c||e.snapshot.selfUser?.id!==l){d+=1;let t=e.snapshot.selfUser?.id!==l;u=!0,s=e.connection.gatewayUrl,c=e.snapshot.client,l=e.snapshot.selfUser?.id,(n||t)&&b(),v()}}),S=e.subscribeEvents(t=>{(t.event===`plugins.changed`||t.event===`users.prefs.changed`&&e.snapshot.selfUser?.id)&&v()});return u&&queueMicrotask(()=>{f||v()}),{snapshot(e){let t=o.error??m.get(e)??null;return t===o.error?o:{...o,error:t}},theme(e){return y(e),p.get(e)?.theme},refresh:v,dispose(){f=!0,d+=1,x(),S(),p.clear(),m.clear()}}}function c(){return(c=e((()=>{n(),o()})))()}c();export{s as createThemeCatalog};