UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

27 lines • 6.84 kB
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{Nu as t,Pu as n,ju as r,xu as i,yu as a,zu as o}from"./control-ui-core-CBJ5efDh.js";import{Cr as s,br as c,ca as l,sa as u,wr as d}from"./control-ui-core-DtLivg_r.js";import{G as f,J as p,W as m,Z as h,at as g,rt as _}from"./lit-runtime-IOnANfcZ.js";import{Sr as v,xr as y}from"./control-ui-boot-shared-CkXlyZBY.js";import{d as b,l as x,u as S}from"./gateway-runtime-C77LeWZN.js";import{Zr as C}from"./ui-CmSP4d14.js";import{P as w,R as T}from"./control-ui-boot-chat-CGYcTLro.js";import{H as E,U as D}from"./control-ui-boot-chat-CmENwCKi.js";import{i as O,n as k,r as A}from"./board-view-DvSYdNVj.js";var j;function M(){return(M=e((()=>{v(),m(),h(),d(),l(),n(),T(),A(),i(),x(),t(),E(),k(),j=class extends r{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=s(e.hello?.auth??null);return{canMutate:t,canGrant:c(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=a(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 D(`board`,o(`common.loading`));let e=this.documentState===`missing-session`?o(`dashboardDocument.missingSession`):this.documentState===`not-found`?o(`dashboardDocument.notFound`):this.documentState===`unavailable`?o(`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"> ${o(`dashboardDocument.loadFailed`,{error:this.errorText})} </div>`;let t=this.provider,n=this.snapshot,r=this.binding?.session;if(!t||!n||!r)return f;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)}},a=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=${r} .snapshot=${a} .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 p` <main class="board-document" aria-label=${o(`board.label`)}> ${this.onDocumentClose?p`<button class="btn btn--ghost btn--icon board-document__close" type="button" aria-label=${o(`dashboardDocument.close`)} title=${o(`dashboardDocument.close`)} @click=${this.onDocumentClose} > ${u.x} </button>`:f} <div class="board-document__content">${this.renderState()}</div> </main> `}},C([g({attribute:!1})],j.prototype,`gatewaySnapshot`,void 0),C([g({attribute:!1})],j.prototype,`sessions`,void 0),C([g({attribute:!1})],j.prototype,`sessionKey`,void 0),C([g({attribute:!1})],j.prototype,`preparedSession`,void 0),C([g({attribute:!1})],j.prototype,`onDocumentClose`,void 0),C([g({type:Boolean})],j.prototype,`passive`,void 0),C([_()],j.prototype,`documentState`,void 0),C([_()],j.prototype,`snapshot`,void 0),C([_()],j.prototype,`activeTabId`,void 0),C([_()],j.prototype,`errorText`,void 0),customElements.get(`openclaw-board-document`)||customElements.define(`openclaw-board-document`,j)})))()}M();export{j as OpenClawBoardDocument};