UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 3.37 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{lo as t}from"./control-ui-connection-Bfj9beF_.js";import{Hx as n,MD as r,fD as i,kD as a,pD as o}from"./control-ui-boot-shared-DFTSUQQ0.js";var s;function c(){return(c=e((()=>{o(),a(),s=class{constructor(e,t){this.notify=e,this.options=t,this.lifecycle=n({client:null,phase:`stopped`}),this.stopActivation=[],this.currentGateway=null,this.currentSnapshot=null,this.currentClient=null,this.currentConnected=!1,this.hasBoundGateway=!1}connect(e=this.options.getGateway()){this.options.onPageActivation&&(this.stopActivation=[t(document,`visibilitychange`,this.options.onPageActivation),t(globalThis,`focus`,this.options.onPageActivation)]),this.refresh(e)}refresh(e=this.options.getGateway()){let t=e??null;if(this.hasBoundGateway&&t===this.currentGateway)return;this.stopGateway?.(),this.stopGateway=void 0;let n=!this.hasBoundGateway,r=this.hasBoundGateway&&this.currentGateway!==t;this.hasBoundGateway=!0,this.currentGateway=t,t&&(this.applySnapshot(t.snapshot,{initial:n,sourceChanged:r}),this.stopGateway=t.subscribe(e=>{this.currentGateway===t&&this.options.getGateway()===t&&this.applySnapshot(e,{initial:!1,sourceChanged:!1})}))}get gateway(){return this.currentGateway}get snapshot(){return this.currentSnapshot}get client(){return this.currentClient}get connected(){return this.currentConnected}get epoch(){return this.lifecycle.epoch}capture(){return this.lifecycle.capture()}isCurrent(e){return this.lifecycle.isCurrent(e)}invalidate(){this.lifecycle.invalidate()}isRouteDataCurrent(e){let t=this.options.getGateway();if(!t||e.gateway!==t)return!1;let n=t.snapshot;return e.gatewaySnapshot===n||e.gatewaySnapshot.phase===`connected`&&n.phase===`connected`&&e.gatewaySnapshot.client===n.client&&e.gatewaySnapshot.hello!==null&&e.gatewaySnapshot.hello===n.hello}dispose(){this.stopActivation.forEach(e=>e()),this.stopActivation=[],this.stopGateway?.(),this.stopGateway=void 0;let e=this.currentSnapshot;if(this.currentGateway=null,e){let t={...e,client:null,phase:`stopped`},n=this.lifecycle.transition(t),r=this.currentClient!==null,i=this.currentConnected;this.currentSnapshot=null,this.currentClient=null,this.currentConnected=!1,n&&this.options.invalidateRequests?.({snapshot:t,initial:!1,sourceChanged:!1,clientChanged:r,connectionChanged:i,identityChanged:!1,becameConnected:!1,becameAvailable:!1})}else this.lifecycle.invalidate();this.notify()}applySnapshot(e,t){let n=this.currentClient,a=this.currentConnected,o=this.currentSnapshot!==null&&r(this.currentSnapshot),s=e.phase===`connected`,c=n!==e.client,l=a!==s,u=this.currentGateway?i(this.currentGateway).key:void 0,d=!t.initial&&(t.sourceChanged||c||this.currentPresentationKey!==void 0&&this.currentPresentationKey!==u),f=this.lifecycle.transition(e);d&&!f&&this.lifecycle.invalidate(),this.currentSnapshot=e,this.currentClient=e.client,this.currentConnected=s,this.currentPresentationKey=u;let p={snapshot:e,initial:t.initial,sourceChanged:t.sourceChanged,clientChanged:c,connectionChanged:l,identityChanged:d,becameConnected:s&&!a,becameAvailable:r(e)&&!o};p.identityChanged&&this.options.onIdentityChange?.(p),!t.initial&&(f||d)&&this.options.invalidateRequests?.(p),this.options.onSnapshot?.(p),s&&(t.initial||p.identityChanged||p.connectionChanged)&&this.options.ensureInitialData?.(p),this.notify()}}})))()}export{c as n,s as t};