UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 6.52 kB
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{Gl as t,Jc as n,Lu as r,Pl as i,Pu as a,Ul as o,Wc as s,Xc as c,kl as l,zu as u}from"./control-ui-core-CBJ5efDh.js";import{Ei as d,Hr as f,Ti as p,Ur as m,Vr as h}from"./control-ui-core-DtLivg_r.js";import{G as g,K as _,W as v}from"./lit-runtime-IOnANfcZ.js";import{Dn as y,En as b,Vr as x,zr as S}from"./control-ui-boot-shared-XreXSF7h.js";import{il as C,mu as w,ol as T,su as E,uu as D}from"./control-ui-boot-shared-dOnP4mAA.js";import{C as O,w as k}from"./control-ui-boot-shared-Q8KG_noF.js";import{at as A,ct as j,lt as M,ot as N,st as P}from"./control-ui-boot-chat-CmENwCKi.js";var F,I;function L(){return(L=e((()=>{v(),O(),p(),a(),E(),C(),s(),l(),f(),j(),b(),S(),P(),F=0,I=class{constructor(e){this.host=e,this.active=null,this.portal=new A(()=>this.close(),100),this.observer=new MutationObserver(()=>this.sync()),this.lastOpenAt=-1/0,this.outsideInteraction=e=>{e.target instanceof Node&&!this.active?.row.contains(e.target)&&!this.portal.card?.contains(e.target)&&this.close()},this.outsideKey=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),this.portal.card?.contains(document.activeElement)&&(this.portal.returnFocus(this.active?.trigger??null),this.portal.focusInside=document.activeElement===this.active?.trigger),this.close())},this.stopLocale=r.subscribe(()=>this.sync())}scope(){return JSON.stringify([this.host.activeRouteId,this.host.sessionKey,this.host.sessionDataContext?.gateway.connectionRevision])}handleEvent(e,t){let n=e.target instanceof Element?e.target.closest(`[data-person-card]`):null;if(e.type===`keydown`&&e instanceof KeyboardEvent){e.key===`Tab`&&this.portal.handleTriggerKeyDown(e);return}if(n&&(t===void 0||e.type===`click`||h(n,e.type===`focusin`?`focus`:`pointer`,!0))){if(e.type===`click`){if(this.active?.row===n&&this.portal.explicitHold){this.close();return}this.activate(n,0),this.portal.explicitHold=!0,this.show()}else if(e.type===`pointerover`&&e instanceof PointerEvent){if(e.pointerType===`touch`||!globalThis.matchMedia?.(`(hover: hover)`).matches||this.portal.explicitHold&&this.active?.row!==n)return;let r=this.portal.card||performance.now()-this.lastOpenAt<300?80:450;this.activate(n,m(t??performance.now(),r)),this.portal.pointerInside=!0,this.portal.clearClose()}else if(e.type===`pointerout`&&e instanceof PointerEvent&&this.active?.row===n){if(e.relatedTarget instanceof Node&&n.contains(e.relatedTarget))return;this.portal.schedulePointerExit()}else if(e.type===`focusin`&&!this.portal.restoringFocus){if(e.target instanceof HTMLAnchorElement&&!e.target.matches(`:focus-visible`))return;this.activate(n,0),this.portal.focusInside=!0,this.portal.clearClose(),this.show()}else if(e.type===`focusout`&&e instanceof FocusEvent&&this.active?.row===n){if(e.relatedTarget instanceof Node&&n.contains(e.relatedTarget))return;this.portal.focusInside=!1,this.portal.scheduleClose()}}}activate(e,t){let n=e.querySelector(`[data-person-card-trigger]`)??e,r=n.dataset.personCardKey;if(!r||!this.host.connected||this.active?.id===r&&this.active.row===e)return;this.close();let i=this.host.sessionDataContext?.gateway;i&&i.snapshot.phase===`connected`&&(this.active={id:r,row:e,trigger:n,scope:this.scope(),gateway:i,client:i.snapshot.client},this.portal.markTrigger(n),this.observer.observe(this.host,{childList:!0,subtree:!0}),document.addEventListener(`pointerdown`,this.outsideInteraction,!0),document.addEventListener(`focusin`,this.outsideInteraction,!0),document.addEventListener(`keydown`,this.outsideKey,!0),this.portal.scheduleOpen(t,()=>{this.portal.held&&this.show()}))}isCurrent(){let e=this.active,t=this.host.sessionDataContext?.gateway;return!!(e&&this.host.isConnected&&this.host.connected&&t?.snapshot.phase===`connected`&&e.gateway===t&&e.client===t.snapshot.client&&e.scope===this.scope()&&this.host.contains(e.row)&&(e.row.dataset.personCardSection===void 0||!this.host.collapsedSessionSections.has(e.row.dataset.personCardSection)))}sync(){this.isCurrent()?this.portal.card&&this.show():this.close()}show(){let e=this.active,r=this.host.sessionDataContext;if(!e||!r||!this.isCurrent()){this.close();return}let a=this.host.sessionData,s=w(a.presencePayload).find(t=>k(t)===e.id);if(!s&&e.id.startsWith(`profile:`)){let t=e.id.slice(8),n=[a.sessionsResult,...Object.values(a.sessionResultsByAgent)].flatMap(e=>e?.sessions??[]).flatMap(e=>[e.owner?.actor,e.createdActor]).find(e=>e?.identity?.type===`profile`&&e.identity.id===t);n&&(s={id:t,identity:{type:`profile`,id:t},name:n.label,avatarUrl:n.avatarUrl,watchedSessions:[],entries:[]})}if(!s){this.close();return}let l=this.activity??=y(r,()=>this.sync()),f={agentsList:r.agents.state.agentsList,hello:r.gateway.snapshot.hello},p=this.portal.card,m=p??N(`openclaw-person-activity-${++F}`,`session-progress-hovercard person-activity-hovercard`),h=D(s,u(`presence.card.person`));if(m.setAttribute(`aria-label`,u(`presence.card.ariaLabel`,{name:h.name})),this.portal.renderContents(m,()=>_(M({user:s,sessionData:l.data,watchAgentId:t(f),mainKey:o(f),globalScope:i(f),routing:x({basePath:this.host.basePath,navigate:(e,t)=>this.host.onNavigate?.(e,t)},()=>this.close()),openSession:(t,i)=>{let a=n(t),s=c({face:a,sessionKey:t.key,row:t,fallbackAgentId:i,basePath:this.host.basePath,mainKey:o(f)});this.close(),T(this.host,{agentId:i,face:a,sessionKey:t.key,commit:()=>this.host.sessionDataContext?.gateway!==e.gateway||r.gateway.snapshot.client!==e.client||r.gateway.snapshot.phase!==`connected`||e.scope!==this.scope()?!1:(this.host.prepareSessionNavigation(t.key,s.options.pathname),this.host.onNavigate?.(a,s.options),d({selection:r.agentSelection,gateway:r.gateway,sessionKey:t.key,agentId:i}),!0)})}}),m)),p){this.portal.position();return}this.lastOpenAt=performance.now(),m.addEventListener(`pointerleave`,this.portal.handleCardPointerLeave),this.portal.mount(e.row,m,`horizontal`,!0,()=>_(g,m))}close(){this.portal.card&&(this.lastOpenAt=performance.now()),this.activity?.dispose(),this.activity=void 0,this.observer.disconnect(),document.removeEventListener(`pointerdown`,this.outsideInteraction,!0),document.removeEventListener(`focusin`,this.outsideInteraction,!0),document.removeEventListener(`keydown`,this.outsideKey,!0),this.portal.reset(),this.active?.trigger.setAttribute(`aria-haspopup`,`dialog`),this.active?.trigger.setAttribute(`aria-expanded`,`false`),this.active=null}dismiss(){let e=this.active!==null;return this.close(),e}dispose(){this.close(),this.stopLocale()}}})))()}L();export{I as SidebarPeopleRuntime};