UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 6.01 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Ii as t,Pi as n,Ti as r,lo as i,vi as a}from"./control-ui-connection-Bfj9beF_.js";import{Av as o,Gt as s,Nd as c,Pd as l,Ut as u,Wt as d,XO as f,av as p,cv as m,dk as h,ek as g,gk as _,gv as v,hv as y,hy as b,kv as x,py as S,rv as C,uk as w,vk as T}from"./control-ui-boot-shared-DFTSUQQ0.js";import{cc as E,oc as D,sc as O}from"./control-ui-boot-chat-DewxEbIm.js";import{n as k,t as A}from"./person-activity-card-Dycvew6k.js";var j,M;function N(){return(N=e((()=>{x(),w(),m(),S(),_(),f(),a(),d(),A(),c(),C(),E(),j=0,M=class{constructor(e){this.host=e,this.active=null,this.portal=O(()=>this.close(),100),this.observer=new MutationObserver(()=>this.sync()),this.lastOpenAt=-1/0,this.stopListeners=[],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.stopGateway=e.sessionDataContext?.gateway.subscribe(()=>{this.isCurrent()||this.close()})}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);else if(n&&(t===void 0||e.type===`click`||u(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,s(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=this.host.personCardTriggers.get(e)??e,r=n.dataset.personCardKey;if(!r||!this.host.connected||this.active?.id===r&&this.active.row===e)return;this.close();let a=this.host.sessionDataContext?.gateway;a&&a.snapshot.phase===`connected`&&(this.active={id:r,row:e,trigger:n,scope:this.scope(),gateway:a,client:a.snapshot.client},this.portal.markTrigger(n),this.observer.observe(this.host.hostElement,{childList:!0,subtree:!0}),this.stopListeners=[i(document,`pointerdown`,this.outsideInteraction,!0),i(document,`focusin`,this.outsideInteraction,!0),i(document,`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.hostElement.contains(e.row))}sync(){this.isCurrent()?this.portal.card&&this.show():this.close()}show(){let e=this.active,a=this.host.sessionDataContext;if(!e||!a||!this.isCurrent()){this.close();return}let s=this.host.sessionData,c=v(s.presencePayload).find(t=>o(t)===e.id);if(!c&&e.id.startsWith(`profile:`)){let t=e.id.slice(8),n=b(a.gateway).get(t);n&&(c=y(n));let r=[s.sessionsResult,...Object.values(s.sessionResultsByAgent)].flatMap(e=>e?.sessions??[]).flatMap(e=>[e.owner?.actor,e.createdActor]).find(e=>e?.identity?.type===`profile`&&e.identity.id===t);!c&&r&&(c={id:t,identity:{type:`profile`,id:t},name:r.label,avatarUrl:r.avatarUrl,watchedSessions:[],entries:[]})}if(!c){this.close();return}let u=this.activity??=l(a,()=>this.sync()),d={agentsList:a.agents.state.agentsList,hello:a.gateway.snapshot.hello},f=this.portal.card,m=f??D(`openclaw-person-activity-${++j}`,`session-progress-hovercard person-activity-hovercard`);this.portal.renderContents(m,()=>k(m,{user:c,sessionData:u.data,watchAgentId:t(d),mainKey:n(d),globalScope:r(d),routing:p({basePath:this.host.basePath,navigate:(e,t)=>this.host.onNavigate?.(e,t)},()=>this.close()),openSession:(t,n,r)=>{let i=g(t);this.close(),T(this.host,{agentId:n,face:i,sessionKey:t.key,commit:()=>this.host.sessionDataContext?.gateway!==e.gateway||a.gateway.snapshot.client!==e.client||a.gateway.snapshot.phase!==`connected`||e.scope!==this.scope()?!1:(this.host.prepareSessionNavigation(t.key,r.pathname),this.host.onNavigate?.(i,r),h({selection:a.agentSelection,gateway:a.gateway,sessionKey:t.key,agentId:n}),!0)})}},()=>this.portal.position())),f?this.portal.position():(this.lastOpenAt=performance.now(),this.stopListeners.push(i(m,`pointerleave`,this.portal.handleCardPointerLeave)),this.portal.mount(e.row,m,`horizontal`,!0,()=>k(m)))}close(){this.portal.card&&(this.lastOpenAt=performance.now()),this.activity?.dispose(),this.activity=void 0,this.observer.disconnect(),this.stopListeners.forEach(e=>e()),this.stopListeners=[],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.stopGateway?.()}}})))()}N();export{M as SidebarPeopleRuntime};