openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
27 lines • 6.8 kB
JavaScript
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{Cu as t,Eu as n,Tu as r,du as i,ju as a,pu as o}from"./control-ui-core-BncvAZjR.js";import{_r as s,br as c,na as l,ra as u,xr as d}from"./control-ui-core-9qYjK5B2.js";import{$ as f,X as p,Y as m,ct as h,nt as g,ut as _}from"./lit-runtime-B8uOr6OX.js";import{br as v,yr as y}from"./control-ui-boot-shared-umGE-sEP.js";import{d as b,l as x,u as S}from"./gateway-runtime-Cr51Pi7N.js";import{ii as C}from"./ui-DuRgK6kL.js";import{Kt as w,Xt as T,ht as E,mt as D}from"./control-ui-boot-chat-C8hdsB2M.js";import{i as O,n as k,r as A}from"./board-view-1zQa7RX5.js";var j;function M(){return(M=e((()=>{v(),m(),g(),d(),u(),n(),T(),A(),o(),x(),r(),D(),k(),j=class extends t{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.providerSubscriptions=[],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=c(e.hello?.auth??null);return{canMutate:t,canGrant:s(e.hello?.auth??null),canPinWidgets:t&&S(e,y.BOARD_WIDGET_PUT_CANVAS_DOC)===!0,canPinMcpApps:t&&b(e,`board.widget.appView`)===!0&&b(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(b(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,n,r){try{let i=r?null:await e.sessions.describe({key:e.sessionKey},{client:e.client});if(n!==this.bindingGeneration)return;if(!r&&!i?.session){this.documentState=`not-found`;return}let a=this.gatewaySnapshot;if(!a||a.client!==e.client)return;let o=r??{sessionKey:i.session.key,agentId:i.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.providerSubscriptions.push(c.snapshot$.subscribe(()=>this.reconcileProvider(c))),this.providerSubscriptions.push(c.loadError$.subscribe(()=>this.reconcileProvider(c))),this.providerSubscriptions.push(c.events.subscribe(({command:e})=>{e.kind===`focus_tab`&&c.snapshot$.value.tabs.some(t=>t.tabId===e.tabId)&&(this.activeTabId=e.tabId)})),this.reconcileProvider(c)}catch(e){n===this.bindingGeneration&&(this.errorText=i(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;for(let e of this.providerSubscriptions)e();this.providerSubscriptions=[],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 E(`board`,a(`common.loading`));let e=this.documentState===`missing-session`?a(`dashboardDocument.missingSession`):this.documentState===`not-found`?a(`dashboardDocument.notFound`):this.documentState===`unavailable`?a(`dashboardDocument.unavailable`):null;if(e!==null)return f`<div class="board-document__state" role="status">${e}</div>`;if(this.documentState===`error`)return f`<div class="board-document__state board-document__state--error" role="alert">
${a(`dashboardDocument.loadFailed`,{error:this.errorText})}
</div>`;let t=this.provider,n=this.snapshot,r=this.binding?.session;if(!t||!n||!r)return p;let i={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 f`<openclaw-board-view
.active=${!0}
.bridgeEnabled=${!this.passive}
.fitAutoContent=${!0}
.session=${r}
.snapshot=${o}
.activeTabId=${this.activeTabId}
.widgetFrameUrl=${(e,n)=>t.widgetFrameUrl(e,n)}
.callbacks=${i}
.canMutate=${!this.passive&&t.canMutate}
.canGrant=${!this.passive&&t.canGrant}
></openclaw-board-view>`}render(){return f`
<main class="board-document" aria-label=${a(`board.label`)}>
${this.onDocumentClose?f`<button
class="btn btn--ghost btn--icon board-document__close"
type="button"
aria-label=${a(`dashboardDocument.close`)}
title=${a(`dashboardDocument.close`)}
=${this.onDocumentClose}
>
${l.x}
</button>`:p}
<div class="board-document__content">${this.renderState()}</div>
</main>
`}},C([_({attribute:!1})],j.prototype,`gatewaySnapshot`,void 0),C([_({attribute:!1})],j.prototype,`sessions`,void 0),C([_({attribute:!1})],j.prototype,`sessionKey`,void 0),C([_({attribute:!1})],j.prototype,`preparedSession`,void 0),C([_({attribute:!1})],j.prototype,`onDocumentClose`,void 0),C([_({type:Boolean})],j.prototype,`passive`,void 0),C([h()],j.prototype,`documentState`,void 0),C([h()],j.prototype,`snapshot`,void 0),C([h()],j.prototype,`activeTabId`,void 0),C([h()],j.prototype,`errorText`,void 0),customElements.get(`openclaw-board-document`)||customElements.define(`openclaw-board-document`,j)})))()}M();export{j as OpenClawBoardDocument};