UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 3.48 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{K as t,Qo as n,U as r,as as i,gs as a,ms as o}from"./_4____________________________.js";import{$A as s,Cf as c,GN as l,Hy as u,Iv as d,JN as f,JO as p,Lv as m,Sf as h,Sv as g,Tf as _,UA as v,Uy as y,Wy as b,YO as x,_v as S,aj as C,ej as w,jv as T,oj as E,sj as D,wf as O,wv as k,yv as A,zA as j}from"./_2_____________________________.js";import{n as M,t as N}from"./person-activity-card-SlbdEzFq.js";function P(e,t,n){let r=B.get(e);r||(r=new Map,B.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>=z&&r.delete(r.keys().next().value);let o={expiresAt:1/0,read:t.request(`users.mentionable`,n,{timeoutMs:R}).then(e=>(o.expiresAt=Date.now()+I,e),()=>(o.expiresAt=Date.now()+L,null))};return r.set(i,o),o.read}function F(e){let{host:t,card:n,context:s,profileId:l,label:u,connection:d,portal:p,close:h}=e,g,_,S=O(()=>{let e=s?b(s.gateway).get(l()):void 0;return T(g?.data?.presencePayload).users.filter(t=>k(t,e?{type:`profile`,id:e.id}:_))},F);async function C(){let e=d.capture(),t=l();if(!e||!s)return null;let r=null;try{let n=b(s.gateway);await n.load(!0);let i=n.get(t);i?r={id:i.id,identity:{type:`profile`,id:i.id},name:m(i.id,i.displayName,i.githubIdentity?.login)||f(`presence.card.person`),avatarUrl:y(i),watchedSessions:[]}:n.result||(r=await j(s,e.client,t))}catch{}return p.card!==n||l()!==t||!d.isCurrent(e)?null:(S.sync(),r)}async function j(e,n,i){let o=t.closest(`[data-chat-session-key]`)?.dataset.chatSessionKey,{snapshot:s}=e.gateway,{hello:c,selfUser:l}=s;if(!c||!o&&r(c.auth??null))return null;let d=u().replace(/^@/u,``).trim(),p=d.slice(0,128),m=o?{sessionKey:o,query:p}:x(s,{method:`sessions.create`,sessionScope:!0}).allowed?{agentId:e.agentSelection.state.selectedId??a({agentsList:e.agents.state.agentsList,hello:c}),query:p}:void 0,h=l?.identity?.id===i||!m?void 0:(await P(c,n,m))?.users.find(e=>e.profileId===i);return _={type:`profile`,id:i},{id:i,identity:_,name:h?.displayName||d||f(`presence.card.person`),avatarUrl:h?.avatarUrl,watchedSessions:[]}}let N=d.capture()?C():null;function F(){if(p.card!==n)return;S.sync();let e=g?.data,r={agentsList:s?.agents.state.agentsList,hello:s?.gateway.snapshot.hello},c=d.capture(),l=s?.router.getState().location,f=u();p.renderContents(n,()=>M(n,N&&s?{name:f,read:N.then(n=>{if(!n)return{status:`unavailable`,name:f};let u=T(e?.presencePayload).users.find(e=>k(e,n.identity));return{user:{...n,name:u?.name??n.name,avatarUrl:u?.avatarUrl??n.avatarUrl,watchedSessions:u?.watchedSessions??[],entries:u?.entries??(e?.presencePayload?[]:void 0)},ariaName:n.name,sessionData:e,watchAgentId:a(r),mainKey:o(r),globalScope:i(r),routing:A(s,h),openSession:(e,n,r)=>{if(!c||!d.isCurrent(c))return;let{client:i,hello:a}=s.gateway.snapshot,o=v(e);h(),D(t,{agentId:n,face:o,sessionKey:e.key,commit:()=>{let t=s.gateway.snapshot;return!d.capture()||s.router.getState().location!==l||t.phase!==`connected`||t.client!==i||t.hello!==a?!1:(E(s.gateway,r.pathname,e.key),s.navigate(o,r),w({selection:s.agentSelection,gateway:s.gateway,sessionKey:e.key,agentId:n}),!0)}})}}})}:{status:`unavailable`,name:f},()=>p.position())),p.position()}return s&&(g=c(s,F)),S.connect(),{refresh:F,dispose(){S.disconnect(),g?.dispose(),M(n)}}}var I,L,R,z,B;function V(){return(V=e((()=>{d(),s(),t(),_(),g(),u(),l(),p(),C(),j(),n(),N(),h(),S(),I=3e5,L=3e4,R=15e3,z=16,B=new WeakMap})))()}V();export{F as createPersonReferenceCard};