openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
27 lines • 7.01 kB
JavaScript
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{qr as t}from"./control-ui-foundation-ZY_Flbbd.js";import{Gl as n,hu as r,lu as i,ql as a,su as o,uu as s}from"./control-ui-core-3P365fbR.js";import{Xi as c,Zi as l,_r as u,gr as d,pr as f}from"./control-ui-core-CFW9Qtjn.js";import{$ as p,X as m,Y as h,ct as g,nt as _,ut as v}from"./lit-runtime-P5vbNq6b.js";import{Gt as y,Kt as b}from"./control-ui-boot-shared-Rs4iS2kF.js";import{d as x,l as S,u as C}from"./gateway-runtime-5YzSCmfV.js";import{$n as w,rr as T}from"./control-ui-boot-shared-DoKu-5Ju.js";import{nn as E,rn as D}from"./control-ui-boot-shared-CG9HtEG-.js";import{a as O,i as k,t as A}from"./board-view-BD5Z3h_5.js";var j;function M(){return(M=e((()=>{b(),h(),_(),u(),l(),s(),T(),k(),a(),S(),i(),E(),A(),j=class extends o{constructor(...e){super(...e),this.sessionKey=null,this.preparedSession=null,this.onDocumentClose=null,this.passive=!1,this.documentState=`loading`,this.activeTabId=``,this.errorText=``,this.provider=null,this.providerLease=null,this.binding=null,this.unsubscribeSnapshot=null,this.unsubscribeLoadError=null,this.unsubscribeEvents=null,this.bindingGeneration=0}connectedCallback(){super.connectedCallback(),this.requestUpdate(`gatewaySnapshot`)}disconnectedCallback(){this.releaseProvider(),super.disconnectedCallback()}updated(e){(e.has(`sessionKey`)||e.has(`preparedSession`)||e.has(`sessions`)||e.has(`gatewaySnapshot`))&&this.synchronizeProvider()}providerCapabilities(e){let t=d(e.hello?.auth??null);return{canMutate:t,canGrant:f(e.hello?.auth??null),canPinWidgets:t&&C(e,y.BOARD_WIDGET_PUT_CANVAS_DOC)===!0,canPinMcpApps:t&&x(e,`board.widget.appView`)===!0&&x(e,`board.widget.put`)===!0}}synchronizeProvider(){if(!this.isConnected)return;let e=(this.preparedSession?.sessionKey??this.sessionKey)?.trim()??``;if(!e){this.releaseProvider(),this.documentState=`missing-session`;return}let t=this.gatewaySnapshot,n=t?.client;if(!t||!n){this.releaseProvider(),this.documentState=`loading`;return}if(x(t,`board.get`)===!1){this.releaseProvider(),this.documentState=`unavailable`;return}let r=this.providerCapabilities(t),i=JSON.stringify(r);if(this.binding?.client===n&&this.binding.sessions===this.sessions&&this.binding.sessionKey===e&&(!this.preparedSession||this.binding.session.agentId===this.preparedSession.agentId)&&this.binding.capabilityKey===i){this.providerLease?.update(n,t.phase===`connected`,r);return}this.releaseProvider(),this.documentState=`loading`;let a=this.bindingGeneration;this.bindProvider({client:n,sessions:this.sessions,sessionKey:e,capabilityKey:i},r,a,this.preparedSession)}async bindProvider(e,t,r,i){try{let n=i?null:await e.sessions.describe({key:e.sessionKey},{client:e.client});if(r!==this.bindingGeneration)return;if(!i&&!n?.session){this.documentState=`not-found`;return}let a=this.gatewaySnapshot;if(!a||a.client!==e.client)return;let o=i??{sessionKey:n.session.key,agentId:n.session.agentId},s=w(o,e.client,a.phase===`connected`,t.canPinWidgets,t.canPinMcpApps,t.canMutate,t.canGrant),c=s.provider;this.provider=c,this.providerLease=s,this.binding={...e,session:o},this.unsubscribeSnapshot=c.snapshot$.subscribe(()=>this.reconcileProvider(c)),this.unsubscribeLoadError=c.loadError$.subscribe(()=>this.reconcileProvider(c)),this.unsubscribeEvents=c.events.subscribe(e=>{let t=e.command;t.kind===`focus_tab`&&c.snapshot$.value.tabs.some(e=>e.tabId===t.tabId)&&(this.activeTabId=t.tabId)}),this.reconcileProvider(c)}catch(e){r===this.bindingGeneration&&(this.errorText=n(e),this.documentState=`error`)}}selectAvailableTab(){let e=this.snapshot;e&&(e.tabs.some(e=>e.tabId===this.activeTabId)||(this.activeTabId=e.tabs[0]?.tabId??e.widgets[0]?.tabId??``))}reconcileProvider(e){if(this.provider!==e)return;if(e.hasLoadedSnapshot){this.snapshot=e.snapshot$.value,this.selectAvailableTab(),this.documentState=`ready`;return}let t=e.loadError$.value;t?(this.errorText=t,this.documentState=`error`):(this.errorText=``,this.documentState=`loading`)}releaseProvider(){this.bindingGeneration+=1,this.unsubscribeSnapshot?.(),this.unsubscribeLoadError?.(),this.unsubscribeEvents?.(),this.unsubscribeSnapshot=null,this.unsubscribeLoadError=null,this.unsubscribeEvents=null,this.providerLease?.release(),this.provider=null,this.providerLease=null,this.binding=null,this.snapshot=void 0,this.activeTabId=``,this.errorText=``}renderState(){if(this.documentState===`loading`)return D(`board`,r(`common.loading`));let e=this.documentState===`missing-session`?r(`dashboardDocument.missingSession`):this.documentState===`not-found`?r(`dashboardDocument.notFound`):this.documentState===`unavailable`?r(`dashboardDocument.unavailable`):null;if(e!==null)return p`<div class="board-document__state" role="status">${e}</div>`;if(this.documentState===`error`)return p`<div class="board-document__state board-document__state--error" role="alert">
${r(`dashboardDocument.loadFailed`,{error:this.errorText})}
</div>`;let t=this.provider,n=this.snapshot,i=this.binding?.session;if(!t||!n||!i)return m;let a={appViewGeneration:t.appViewGeneration,applyOps:e=>t.applyOps(e),grant:(e,n)=>t.grant(e,n),selectTab:e=>{this.activeTabId=e},frameLoadFailed:e=>t.refreshWidgetFrame(e),...this.passive?{}:{widgetAppView:(e,n)=>t.widgetAppView(e,n),refreshWidgetAppView:(e,n)=>t.refreshWidgetAppView(e,n)}},o=this.passive?{...n,widgets:n.widgets.filter(e=>O(e,this.gatewaySnapshot?.hello?.controlUiWidgetKinds??[]))}:n;return p`<openclaw-board-view
.active=${!0}
.bridgeEnabled=${!this.passive}
.fitAutoContent=${!0}
.session=${i}
.snapshot=${o}
.activeTabId=${this.activeTabId}
.widgetFrameUrl=${(e,n)=>t.widgetFrameUrl(e,n)}
.callbacks=${a}
.canMutate=${!this.passive&&t.canMutate}
.canGrant=${!this.passive&&t.canGrant}
></openclaw-board-view>`}render(){return p`
<main class="board-document" aria-label=${r(`board.label`)}>
${this.onDocumentClose?p`<button
class="btn btn--ghost btn--icon board-document__close"
type="button"
aria-label=${r(`dashboardDocument.close`)}
title=${r(`dashboardDocument.close`)}
=${this.onDocumentClose}
>
${c.x}
</button>`:m}
<div class="board-document__content">${this.renderState()}</div>
</main>
`}},t([v({attribute:!1})],j.prototype,`gatewaySnapshot`,void 0),t([v({attribute:!1})],j.prototype,`sessions`,void 0),t([v({attribute:!1})],j.prototype,`sessionKey`,void 0),t([v({attribute:!1})],j.prototype,`preparedSession`,void 0),t([v({attribute:!1})],j.prototype,`onDocumentClose`,void 0),t([v({type:Boolean})],j.prototype,`passive`,void 0),t([g()],j.prototype,`documentState`,void 0),t([g()],j.prototype,`snapshot`,void 0),t([g()],j.prototype,`activeTabId`,void 0),t([g()],j.prototype,`errorText`,void 0),customElements.get(`openclaw-board-document`)||customElements.define(`openclaw-board-document`,j)})))()}M();export{j as OpenClawBoardDocument};