UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 5.46 kB
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{AC as t,kC as n}from"./control-ui-boot-shared-DFTSUQQ0.js";import{P as r,U as i}from"./solid-runtime-C416s-HC.js";var a;function o(){return(o=e((()=>{a=class{constructor(e){this.root=e,this.generation=0,this.committedGeneration=-1,this.rootCommitted=!1,this.presentation=null,this.cleanups=[],this.rosterFloor=0,this.connectionRevision=-1,this.connectionClient=null,this.settlementError=null,this.hook={snapshot:()=>this.snapshot,diagnostics:()=>{let e=this.runtime?.context,t=e?.agents.state;return{agentSelection:e?.agentSelection.state??null,gateway:{assistantAgentId:e?.gateway.snapshot.assistantAgentId??null,phase:e?.gateway.snapshot.phase??null},roster:{agentsError:t?.agentsError??null,agentsList:t?.agentsList??null,agentsLoading:t?.agentsLoading??null,connected:t?.connected??null},router:this.snapshot.route,settlementError:this.settlementError}},navigate:(e,t)=>{if(!this.runtime)throw Error(`Control UI is disconnected`);this.runtime.context.navigate(e,t)}}}connect(e,t){this.disconnect(),this.runtime=e,this.settlePresentation=t,this.connectionRevision=e.context.gateway.connectionRevision,this.connectionClient=e.context.gateway.snapshot.client,this.rosterFloor=0;let n=()=>{let{gateway:t,sessions:n}=e.context;(t.connectionRevision!==this.connectionRevision||t.snapshot.client!==this.connectionClient||t.snapshot.phase!==`connected`)&&(this.rosterFloor=n.canonicalListRevision,this.connectionRevision=t.connectionRevision,this.connectionClient=t.snapshot.client),this.invalidate()};this.cleanups=[e.context.gateway.subscribe(n),e.context.sessions.subscribe(()=>this.invalidate()),e.router.subscribe(()=>this.invalidate())];let r=this.root.ownerDocument.defaultView;r&&Object.defineProperty(r,"openclawControlUi",{configurable:!0,writable:!0,value:this.hook}),this.invalidate()}disconnect(){for(let e of this.cleanups.splice(0))e();let e=this.root.ownerDocument.defaultView;e?.openclawControlUi===this.hook&&delete e.openclawControlUi,this.runtime=void 0,this.settlement=void 0,this.settlePresentation=void 0,this.presentation=null,this.rootCommitted=!1,this.invalidate()}invalidateRoot(){this.rootCommitted=!1,this.invalidate()}commitRoot(){this.rootCommitted=!0,this.invalidate()}invalidate(){this.generation+=1,this.settlementError=null,this.root.removeAttribute(`data-openclaw-ready`),!this.settlement&&this.runtime&&this.settle()}async settle(){let e={};this.settlement=e;try{for(;this.settlement===e&&this.runtime&&this.settlePresentation;){let t=this.runtime,n=this.generation,r;try{r=await this.settlePresentation()}catch(r){if(this.settlement!==e)return;if(t!==this.runtime||n!==this.generation)continue;this.settlementError=String(r);break}if(this.settlement!==e)return;if(t===this.runtime&&n===this.generation){this.presentation=r,this.committedGeneration=n,this.snapshot.ready&&this.root.setAttribute(`data-openclaw-ready`,String(n));break}}}finally{this.settlement===e&&(this.settlement=void 0)}}get snapshot(){let e=this.runtime?.context,t=e?.sessions.state,n=this.runtime?.router.getState(),r=e?.gateway.snapshot.phase??null,i=!!(this.committedGeneration===this.generation&&this.presentation?.kind===`shell`&&n&&n.status!==`loading`&&n.status!==`idle`&&n.pendingMatches.length===0),a=!!(e&&e.sessions.canonicalListRevision>this.rosterFloor&&t?.result&&!t.loading&&!t.resultCached),o=r===`reconnecting`||r===`offline`||r===`reload-required`;return{generation:this.generation,booted:this.rootCommitted,gatewayPhase:r,routeReady:i,rosterReady:a,ready:this.rootCommitted&&this.committedGeneration===this.generation&&(o||this.presentation?.kind===`login`||this.presentation?.kind===`standalone`||this.presentation?.kind===`shell`&&i&&(!this.presentation.navigationVisible||a)),basePath:e?.basePath??``,sessionKey:this.presentation?.sessionKey??null,route:n?{status:n.status,resolvedLocation:n.resolvedLocation,matches:n.matches.map(({routeId:e})=>({routeId:e})),pendingMatches:n.pendingMatches.map(({routeId:e})=>({routeId:e}))}:null,terminalActivationReady:this.committedGeneration===this.generation&&this.presentation?.terminalActivationReady===!0}}}})))()}async function s(e,n){if(e.readiness=n,await e.updateComplete,!e.shellElement?.isConnected)return{kind:`loading`,navigationVisible:!1};let r=e.navigationSidebar,i=e.workspaceChromeVisible&&e.navDrawerElement?.isConnected===!0&&r.navigationVisible!==!1;if(i){if(!r.isConnected||!customElements.get(`openclaw-app-sidebar`))return{kind:`loading`,navigationVisible:!0};await r.updateComplete,await new Promise(e=>{t(e,()=>()=>e())}),await r.updateComplete}let a=e.routeOutlet;return!a||!await a.settlePresentation()?{kind:`loading`,navigationVisible:i}:(await a.renderedElement?.(`openclaw-chat-page`)?.updateComplete,{kind:`shell`,navigationVisible:i,sessionKey:e.activeSessionKey})}function c(e,t,n,i){let o=new a(e);return o.connect(t,async()=>{await Promise.resolve();let{login:e,shell:n,terminal:r}=i(),a;return a=t.documentMode||t.focusLocation?{kind:`standalone`,navigationVisible:!1}:e?.isConnected?{kind:`login`,navigationVisible:!1}:n?.element.isConnected?await s(n,o):{kind:`loading`,navigationVisible:!1},await r?.updateComplete,{...a,terminalActivationReady:n?.element.isConnected?n.terminalActivationReady===!0:r?.isConnected===!0&&r.available===!0}}),r(()=>(n(),o.invalidateRoot(),{}),()=>o.commitRoot()),o}function l(){return(l=e((()=>{i(),n(),o()})))()}l();export{c as createSolidControlUiReadiness};