openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 6.61 kB
JavaScript
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{_l as t,hc as n,hl as r,hu as i,nl as a,ol as o,pu as s,uu as c,xc as l,yc as u}from"./control-ui-core-3P365fbR.js";import{Fr as d,Ir as f,Pr as p,hi as m,mi as h}from"./control-ui-core-CFW9Qtjn.js";import{X as g,Y as _,Z as v}from"./lit-runtime-P5vbNq6b.js";import{Gi as y,Io as b,Ui as x,Uo as S,zo as C}from"./control-ui-boot-shared-DoKu-5Ju.js";import{$n as w,Qn as T,Xn as E,Yn as D,Zn as O,aa as k,sa as A}from"./control-ui-boot-shared-CG9HtEG-.js";import{K as j,q as M}from"./control-ui-boot-shared-BykNRHBP.js";var N,P;function F(){return(F=e((()=>{_(),j(),h(),c(),b(),x(),n(),a(),d(),T(),k(),O(),N=0,P=class{constructor(e){this.host=e,this.active=null,this.portal=new D(()=>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.returnFocus(),this.close())},this.stopLocale=s.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`||p(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,f(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,n=this.host.sessionDataContext;if(!e||!n||!this.isCurrent()){this.close();return}let a=this.host.sessionData,s=S(a.presencePayload).find(t=>M(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 c={agentsList:n.agents.state.agentsList,hello:n.gateway.snapshot.hello},d=this.portal.card,f=d??E(`openclaw-person-activity-${++N}`,`session-progress-hovercard person-activity-hovercard`),p=C(s,i(`presence.card.person`));if(f.setAttribute(`aria-label`,i(`presence.card.ariaLabel`,{name:p.name})),this.portal.renderContents(f,()=>v(w({user:s,sessionData:a,watchAgentId:t(c),mainKey:r(c),globalScope:o(c),routing:A({basePath:this.host.basePath,navigate:(e,t)=>this.host.onNavigate?.(e,t)},()=>this.close()),openSession:(t,i)=>{let a=u(t),o=l({face:a,sessionKey:t.key,row:t,fallbackAgentId:i,basePath:this.host.basePath,mainKey:r(c)});this.close(),y(this.host,{agentId:i,face:a,sessionKey:t.key,commit:()=>this.host.sessionDataContext?.gateway!==e.gateway||n.gateway.snapshot.client!==e.client||n.gateway.snapshot.phase!==`connected`||e.scope!==this.scope()?!1:(this.host.prepareSessionNavigation(t.key,o.options.pathname),this.host.onNavigate?.(a,o.options),m({selection:n.agentSelection,gateway:n.gateway,sessionKey:t.key,agentId:i}),!0)})}}),f)),d){this.portal.position();return}this.lastOpenAt=performance.now(),f.addEventListener(`pointerleave`,()=>{this.portal.pointerOverCard=!1,this.portal.scheduleClose()}),f.addEventListener(`keydown`,e=>{let t=this.portal.focusables();e.key===`Tab`&&document.activeElement===(e.shiftKey?t[0]:t.at(-1))&&(e.preventDefault(),this.returnFocus(),this.close())}),this.portal.mount(e.row,f,`horizontal`,!0,()=>v(g,f))}returnFocus(){this.portal.returnFocus(this.active?.trigger??null),this.portal.focusInside=document.activeElement===this.active?.trigger}close(){this.portal.card&&(this.lastOpenAt=performance.now()),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()}}})))()}F();export{P as SidebarPeopleRuntime};