openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 6.25 kB
JavaScript
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{Gu as t,Ic as n,Lc as r,Nu as i,Pu as a,Wc as o,Wl as s,Wu as c,Xc as l,Zl as u,dl as d,fu as f,hl as p,ju as m,kl as h,ll as g,uu as _,xu as v,yl as y,yu as b,zu as x}from"./control-ui-core-CBJ5efDh.js";import{Ai as S,ki as C}from"./control-ui-core-DtLivg_r.js";import{Z as w,at as T}from"./lit-runtime-IOnANfcZ.js";import{Ca as E,Mt as D,Nt as O,Sa as k}from"./control-ui-boot-shared-UG5ko-VG.js";import{Ur as A,Wr as j,Zr as M,mt as N}from"./ui-CmSP4d14.js";var P,F;function I(){return(I=e((()=>{t(),P={agentsHome:{manage:`Manage agents`,create:`New agent`,openChat:`Open chat`,openMainChat:`Open main chat`,allSessions:`All sessions`,collapseOthers:`Collapse others`,agentOptions:`Options for {agent}`,expandAgent:`Expand {agent}`,collapseAgent:`Collapse {agent}`,working:`Working now`,workingPreview:`Working: {preview}`,seeAll:`See all`,seeAllCount:`See all {count} agents`,lastActive:`Active {time}`,neverActive:`No recent activity`,noMessage:`No messages yet`,loading:`Loading agents…`,disconnected:`Connect to the Gateway to see your agents.`,loadFailed:`Could not load agents. Try again.`,empty:`Your team starts here. Add an agent to get started.`}},F=Object.assign(()=>{Object.assign(c,P)},{catalog:P})})))()}function L(e,t,n=()=>null){if(!e)return[];let r=y(e).agents;if(r.length===0)return[];let i=new Map;return t.forEach(t=>{let n=u(t,e.defaultId),r=i.get(n)??[];r.push(t),i.set(n,r)}),r.map(t=>{let r=n(t.id),a=d(t,r),o=s({agentsList:e},e.mainKey,t.id).sessionKey,c=i.get(t.id)??[],l=c.reduce((e,t)=>!e||(t.updatedAt??0)>(e.updatedAt??0)?t:e,void 0),u=c.find(e=>e.key===o)??c.find(e=>e.isMain);return{id:t.id,name:a,role:t.identity?.theme,model:t.model?.primary,avatar:f(t,r),textAvatar:p(t,r),mainKey:o,activeNow:c.some(N),unreadCount:c.filter(e=>e.unread&&!e.archived).length,lastActiveAt:l?.updatedAt??0,preview:(u??l)?.lastMessagePreview}})}function R(){return(R=e((()=>{_(),h(),g()})))()}function z(e){let t=V.get(e.sessions);return t||(t=new H(e),V.set(e.sessions,t)),t}var B,V,H;function U(){return(U=e((()=>{a(),v(),O(),g(),R(),B={cards:[],result:null,involvingMe:!1,loading:!1,error:null,subscriptionError:null},V=new WeakMap,H=class{constructor(e){this.context=e,this.current=B,this.listeners=new Set,this.binding=null,this.involvingMe=!1;let t=[];this.observation=D(e.gateway,{sync:()=>this.synchronize(),onSnapshot:()=>this.synchronize(),onAttach:()=>{t=[e.agents.subscribe(()=>this.project()),e.agentIdentity.subscribe(()=>this.project()),e.sessions.subscribe(()=>{this.current.subscriptionError!==e.sessions.eventSubscriptionError&&this.project()})]},onDetach:()=>{t.forEach(e=>e()),t=[],this.retire(),this.publish({...B,involvingMe:this.involvingMe})}})}get snapshot(){return this.current}subscribe(e){let t=()=>e();return this.listeners.add(t),this.listeners.size===1&&(this.observation.attach(),this.synchronize()),()=>{this.listeners.delete(t)&&this.listeners.size===0&&this.observation.detach()}}publish(e){this.current=e;for(let t of Array.from(this.listeners)){if(this.current!==e)return;t()}}project(){let e=this.binding;if(!e||!this.isCurrent(e)){this.publish({...B,involvingMe:this.involvingMe});return}let{result:t,loading:n,error:r}=e.snapshot;this.publish({result:t,involvingMe:this.involvingMe,loading:e.metadataLoading||n,error:e.metadataError??r,subscriptionError:this.context.sessions.eventSubscriptionError,cards:L(this.context.agents.state.agentsList??void 0,t?.sessions.filter(e=>e.archived!==!0)??[],e=>this.context.agentIdentity.get(e))})}isCurrent(e){return this.binding===e&&this.context.sessions.isConnectionScopeCurrent(e.connection)}retire(){let e=this.binding;this.binding=null,e?.observation?.dispose()}synchronize(){if(this.listeners.size===0)return;this.binding&&!this.isCurrent(this.binding)&&this.retire();let e=this.context.sessions.captureConnectionScope();if(!e){this.project();return}if(!this.binding){let t={connection:e,snapshot:{result:null,agentId:null,loading:!1,error:null},requested:!1,metadataLoading:!1,metadataError:null};if(this.binding=t,t.observation=this.context.sessions.observeList({source:`agent-roster`,rowMode:`compact`,includeDerivedTitles:!0,includeLastMessage:!0,archivedFilter:`all`,involvingMe:this.involvingMe,excludeDock:!0,limit:300,pageSize:100},e=>{this.isCurrent(t)&&(t.snapshot=e,this.project())}),!this.isCurrent(t)){t.observation.dispose();return}}!this.binding.requested&&this.visible()&&this.refreshBinding(this.binding)}setInvolvingMe(e){this.involvingMe!==e&&(this.involvingMe=e,this.retire(),this.project(),this.synchronize())}visible(){return typeof document>`u`||document.visibilityState!==`hidden`}refresh(){return this.synchronize(),this.binding&&this.visible()?this.refreshBinding(this.binding):Promise.resolve()}refreshBinding(e){return e.request?e.request:(e.requested=!0,e.metadataLoading=!0,e.metadataError=null,e.request=Promise.resolve().then(async()=>{try{let t=await this.context.agents.ensureList();if(!this.isCurrent(e))return;if(!t)throw Error(this.context.agents.state.agentsError??x(`agentsHome.loadFailed`));await this.context.agentIdentity.ensure(y(t).agents.map(({id:e})=>e))}catch(t){this.isCurrent(e)&&(e.metadataError=b(t,x(`agentsHome.loadFailed`)));return}finally{e.metadataLoading=!1,this.isCurrent(e)&&this.project()}this.isCurrent(e)&&this.visible()?await e.observation?.refresh().catch(()=>void 0):this.isCurrent(e)&&(e.requested=!1)}).finally(()=>{e.request=void 0}),this.project(),e.request)}}})))()}var W;function G(){return(G=e((()=>{j(),w(),S(),E(),o(),i(),r(),U(),W=class extends m{constructor(){super(),this.active=!0,this.avatars=new k(this),new n(this).watchStore(()=>this.active&&this.context?z(this.context):void 0)}get roster(){return z(this.context).snapshot}get connected(){return this.context.gateway.snapshot.phase===`connected`}refresh(){return z(this.context).refresh()}cards(){return this.roster.cards.map(e=>Object.assign({},e,{avatar:e.avatar?this.avatars.resolve(e.avatar):null,target:l({context:this.context,face:`chat`,sessionKey:e.mainKey,agentId:e.id})}))}},M([T({attribute:!1})],W.prototype,`active`,void 0),M([A({context:C,subscribe:!0})],W.prototype,`context`,void 0)})))()}export{I as a,z as i,G as n,F as o,U as r,W as t};