UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 6.1 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{Qo as t,Wo as n,as as r,gs as i,ms as a}from"./_4____________________________.js";import{$A as o,$t as s,Av as c,Cf as l,Gv as u,Hy as d,Kv as f,Sf as p,Sv as m,UA as h,Wy as g,_v as _,aj as v,ej as y,en as b,kv as x,sj as S,tn as C,yv as w,zA as T}from"./_2_____________________________.js";import{Gr as E,Kr as D,Wr as O}from"./control-ui-boot-chat-styles-DMRbEm40.js";import{n as k,t as A}from"./person-activity-card-SlbdEzFq.js";var j,M;function N(){return(N=e((()=>{u(),o(),m(),d(),v(),T(),t(),b(),A(),p(),_(),D(),j=0,M=class{constructor(e){this.host=e,this.active=null,this.portal=E(()=>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`||s(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=(e=performance.now())=>{let t=this.portal.card||performance.now()-this.lastOpenAt<300?80:450;this.activate(n,C(e,t)),this.portal.pointerInside=!0,this.portal.clearClose()};if(this.active?.row!==n&&this.portal.deferPointerSwitch(e,n,r))return;r(t)}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(e)}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 r=this.host.personCardTriggers.get(e)??e,i=r.dataset.personCardKey;if(!i||!this.host.connected||this.active?.id===i&&this.active.row===e)return;this.close();let a=this.host.sessionDataContext?.gateway;a&&a.snapshot.phase===`connected`&&(this.active={id:i,row:e,trigger:r,scope:this.scope(),gateway:a,client:a.snapshot.client},this.portal.markTrigger(r),this.observer.observe(this.host.hostElement,{childList:!0,subtree:!0}),this.stopListeners=[n(document,`pointerdown`,this.outsideInteraction,!0),n(document,`focusin`,this.outsideInteraction,!0),n(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,t=this.host.sessionDataContext;if(!e||!t||!this.isCurrent()){this.close();return}let o=this.host.sessionData,s=c(o.presencePayload).find(t=>f(t)===e.id);if(!s&&e.id.startsWith(`profile:`)){let n=e.id.slice(8),r=g(t.gateway).get(n);r&&(s=x(r));let i=[o.sessionsResult,...Object.values(o.sessionResultsByAgent)].flatMap(e=>e?.sessions??[]).flatMap(e=>[e.owner?.actor,e.createdActor]).find(e=>e?.identity?.type===`profile`&&e.identity.id===n);!s&&i&&(s={id:n,identity:{type:`profile`,id:n},name:i.label,avatarUrl:i.avatarUrl,watchedSessions:[],entries:[]})}if(!s){this.close();return}let u=this.activity??=l(t,()=>this.sync()),d={agentsList:t.agents.state.agentsList,hello:t.gateway.snapshot.hello},p=this.portal.card,m=p??O(`openclaw-person-activity-${++j}`,`session-progress-hovercard person-activity-hovercard`);this.portal.renderContents(m,()=>k(m,{user:s,sessionData:u.data,watchAgentId:i(d),mainKey:a(d),globalScope:r(d),routing:w({basePath:this.host.basePath,navigate:(e,t)=>this.host.onNavigate?.(e,t)},()=>this.close()),openSession:(n,r,i)=>{let a=h(n);this.close(),S(this.host,{agentId:r,face:a,sessionKey:n.key,commit:()=>this.host.sessionDataContext?.gateway!==e.gateway||t.gateway.snapshot.client!==e.client||t.gateway.snapshot.phase!==`connected`||e.scope!==this.scope()?!1:(this.host.prepareSessionNavigation(n.key,i.pathname),this.host.onNavigate?.(a,i),y({selection:t.agentSelection,gateway:t.gateway,sessionKey:n.key,agentId:r}),!0)})}},()=>this.portal.position())),p?this.portal.position():(this.lastOpenAt=performance.now(),this.stopListeners.push(n(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};