UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 3.47 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Ii as t,Ot as n,Pi as r,Ti as i,jt as a,vi as o}from"./control-ui-connection-Bfj9beF_.js";import{Fd as s,Id as c,Nd as l,Pd as u,XO as d,_k as f,_v as p,av as m,cv as h,dj as g,dk as _,ek as v,gk as y,hy as b,mj as x,my as S,nD as C,py as w,rv as T,tD as E,uk as D,uv as O,vk as k}from"./control-ui-boot-shared-DFTSUQQ0.js";import{n as A,t as j}from"./person-activity-card-Dycvew6k.js";function M(e,t,n){let r=R.get(e);r||(r=new Map,R.set(e,r));let i=JSON.stringify(n),a=r.get(i);if(a&&Date.now()<a.expiresAt)return a.read;r.delete(i),r.size>=L&&r.delete(r.keys().next().value);let o={expiresAt:1/0,read:t.request(`users.mentionable`,n,{timeoutMs:I}).then(e=>(o.expiresAt=Date.now()+P,e),()=>(o.expiresAt=Date.now()+F,null))};return r.set(i,o),o.read}function N(e){let{host:a,card:o,context:c,profileId:l,label:d,connection:h,portal:g,close:y}=e,w,T,E=s(()=>{let e=c?b(c.gateway).get(l()):void 0;return p(w?.data?.presencePayload).users.filter(t=>O(t,e?{type:`profile`,id:e.id}:T))},P);async function D(){let e=h.capture(),t=l();if(!e||!c)return null;let n=null;try{let r=b(c.gateway);await r.load(!0);let i=r.get(t);i?n={id:i.id,identity:{type:`profile`,id:i.id},name:i.displayName?.trim()||i.githubIdentity?.login||x(`presence.card.person`),avatarUrl:S(i),watchedSessions:[]}:r.result||(n=await j(c,e.client,t))}catch{}return g.card!==o||l()!==t||!h.isCurrent(e)?null:(E.sync(),n)}async function j(e,r,i){let o=a.closest(`[data-chat-session-key]`)?.dataset.chatSessionKey,{snapshot:s}=e.gateway,{hello:c,selfUser:l}=s;if(!c||!o&&n(c.auth??null))return null;let u=d().replace(/^@/u,``).trim(),f=u.slice(0,128),p=o?{sessionKey:o,query:f}:C(s,{method:`sessions.create`,sessionScope:!0}).allowed?{agentId:e.agentSelection.state.selectedId??t({agentsList:e.agents.state.agentsList,hello:c}),query:f}:void 0,m=l?.identity?.id===i||!p?void 0:(await M(c,r,p))?.users.find(e=>e.profileId===i);return T={type:`profile`,id:i},{id:i,identity:T,name:m?.displayName||u||x(`presence.card.person`),avatarUrl:m?.avatarUrl,watchedSessions:[]}}let N=h.capture()?D():null;function P(){if(g.card!==o)return;E.sync();let e=w?.data,n={agentsList:c?.agents.state.agentsList,hello:c?.gateway.snapshot.hello},s=h.capture(),l=c?.router.getState().location,u=d();g.renderContents(o,()=>A(o,N&&c?{name:u,read:N.then(o=>{if(!o)return{status:`unavailable`,name:u};let d=p(e?.presencePayload).users.find(e=>O(e,o.identity));return{user:{...o,name:d?.name??o.name,avatarUrl:d?.avatarUrl??o.avatarUrl,watchedSessions:d?.watchedSessions??[],entries:d?.entries??(e?.presencePayload?[]:void 0)},ariaName:o.name,sessionData:e,watchAgentId:t(n),mainKey:r(n),globalScope:i(n),routing:m(c,y),openSession:(e,t,n)=>{if(!s||!h.isCurrent(s))return;let{client:r,hello:i}=c.gateway.snapshot,o=v(e);y(),k(a,{agentId:t,face:o,sessionKey:e.key,commit:()=>{let a=c.gateway.snapshot;return!h.capture()||c.router.getState().location!==l||a.phase!==`connected`||a.client!==r||a.hello!==i?!1:(f(c.gateway,n.pathname,e.key),c.navigate(o,n),_({selection:c.agentSelection,gateway:c.gateway,sessionKey:e.key,agentId:t}),!0)}})}}})}:{status:`unavailable`,name:u},()=>g.position())),g.position()}return c&&(w=u(c,P)),E.connect(),{refresh:P,dispose(){E.disconnect(),w?.dispose(),A(o)}}}var P,F,I,L,R;function z(){return(z=e((()=>{D(),a(),c(),h(),w(),g(),E(),y(),d(),o(),j(),l(),T(),P=3e5,F=3e4,I=15e3,L=16,R=new WeakMap})))()}z();export{N as createPersonReferenceCard};