openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
336 lines • 59.9 kB
JavaScript
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./session-progress-BHGEJjf9.js","./rolldown-runtime-DkW27tQK.js","./control-ui-foundation-Cydpkyqa.js","./control-ui-core-Rwzhj6nO.js","./lit-runtime-CV_MH99K.js","./control-ui-core-YphAl4aM.js","./control-ui-core-vvcQQV2m.js","./gateway-runtime-Bqqcp9-I.js","./control-ui-core-ClxHIvNM.css","./control-ui-boot-chat-_QSl8fbH.js","./control-ui-boot-shared-BYq7Cchl.js","./control-ui-boot-shared-Deak_Sjt.js","./control-ui-boot-shared-gfE6fZcA.js","./markdown-runtime-Bn6OdBVq.js","./control-ui-boot-shared-DfZ39Yj9.js","./control-ui-boot-shared-CXVvK2AW.js","./control-ui-boot-shared-3juXI2I2.js","./control-ui-boot-shared-BVNXvWX-.js","./control-ui-boot-shared-KspYIvAF.css","./control-ui-boot-chat-Cgwe4GEM.js","./config-runtime-D-5ybyEi.js","./mcp-app-view-registration-BuAQbPJ2.js"])))=>i.map(i=>d[i]);
import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{Kn as t,R as n,ii as r,ri as i,wr as a,z as o}from"./control-ui-foundation-Cydpkyqa.js";import{Bn as s,Eo as c,Ga as l,Oo as u,Sc as d,To as f,Wa as ee,bc as p,n as te,oa as ne,r as re,sa as ie,zn as ae}from"./control-ui-core-Rwzhj6nO.js";import{$ as m,K as h,X as g,_ as oe,at as _,h as se,m as ce,q as v,st as y,v as le}from"./lit-runtime-CV_MH99K.js";import{Rt as ue,_ as de,g as fe,zt as pe}from"./control-ui-core-YphAl4aM.js";import{Gt as me,Ht as he,Wt as ge,Yt as b,Z as _e,en as x}from"./control-ui-core-vvcQQV2m.js";import{Bn as ve,Dn as ye,En as be,Fn as xe,Pn as Se,Rn as Ce,zn as we}from"./control-ui-boot-chat-_QSl8fbH.js";import{ba as Te,xa as Ee}from"./control-ui-boot-shared-CXVvK2AW.js";import{i as De,n as Oe,r as ke}from"./control-ui-boot-chat-CazDfK3O.js";import{n as Ae,t as je}from"./control-ui-disabled-2SNbmzuV.js";import{n as Me,t as Ne}from"./near-viewport-observer-BfnpDHlZ.js";import{n as Pe,r as Fe}from"./widget-sandbox-host-BBp_TNUu.js";function S(e,t,n){return Math.min(n,Math.max(t,Number.isFinite(e)?Math.round(e):t))}function C(e,t){return{name:e.name,w:e.w,h:e.h,order:t}}function w(e,t=A){return e.map(e=>({name:e.name,w:S(e.w,1,12),h:S(e.h,1,t),order:Number.isFinite(e.order)?e.order:0})).toSorted((e,t)=>e.order-t.order||e.name.localeCompare(t.name)).map(C)}function Ie(e,t,n,r,i){for(let a=n;a<n+i;a+=1)for(let n=t;n<t+r;n+=1)if(e[a]?.[n])return!1;return!0}function Le(e,t){for(let n=t.y;n<t.y+t.h;n+=1){let r=e[n]??Array.from({length:12},()=>!1);e[n]=r;for(let e=t.x;e<t.x+t.w;e+=1)r[e]=!0}}function Re(e,t){for(let n=0;;n+=1)for(let r=0;r<=12-t.w;r+=1)if(Ie(e,r,n,t.w,t.h))return{name:t.name,x:r,y:n,w:t.w,h:t.h}}function T(e,t=A){let n=[],r=[];for(let i of w(e,t)){let e=Re(n,i);Le(n,e),r.push(e)}return r}function E(e,t){return t.x>=e.x&&t.x<e.x+e.w&&t.y>=e.y&&t.y<e.y+e.h}function ze(e,t,n){let r=w(e),i=r.findIndex(e=>e.name===t);if(i<0)return{items:r,rects:T(r)};let a=T(r),o={x:S(n.x,0,11),y:Math.max(0,Number.isFinite(n.y)?Math.floor(n.y):0)},s=a.find(e=>e.name===t);if(s&&E(s,o))return{items:r,rects:a};let[c]=r.splice(i,1);if(!c)return{items:r,rects:T(r)};let l=a.find(e=>e.name!==t&&E(e,o))??a.filter(e=>e.name!==t&&(e.y>o.y||e.y===o.y&&e.x>=o.x)).toSorted((e,t)=>e.y-t.y||e.x-t.x)[0],u=l?r.findIndex(e=>e.name===l.name):r.length;r.splice(Math.max(0,u),0,c);let d=r.map(C);return{items:d,rects:T(d)}}function Be(e,t,n,r){return w(e).map(e=>e.name===t?{name:e.name,w:S(n,1,12),h:S(r,1,A),order:e.order}:e)}function Ve(e,t,n){let r=w(e),i=r.findIndex(e=>e.name===t);if(i<0)return r;let a=n===`left`||n===`up`?-1:1,o=Math.min(r.length-1,Math.max(0,i+a));if(o!==i){let[e]=r.splice(i,1);e&&r.splice(o,0,e)}return r.map(C)}function He(e){return`grid-column: ${e.x+1} / span ${e.w}; grid-row: ${e.y+1} / span ${e.h};`}function D(){return typeof window.matchMedia==`function`&&!window.matchMedia(`(hover: hover) and (pointer: fine)`).matches?N:0}function O(e,t,n){if(!(e.contentKind!==`html`||e.heightMode===`fixed`||t===void 0||!Number.isFinite(t)||t<=0))return t+2+n+((e.presentation??`card`)===`card`?24:0)}function Ue(e){return e*56+(e-1)*12}function k(e,t,n=0,r=M){let i=O(e,t,n);if(i===void 0)return e.sizeH;let a=Math.ceil((i+12)/68);return Math.min(r,Math.max(j,a))}function We(e,t,n=0,r=M){let i=O(e,t,n);if(i!==void 0)return Math.min(i,Ue(k(e,t,n,r)))}var A,j,M,N,Ge;function P(){return(P=e((()=>{A=20,j=2,M=20,N=38,Ge=`(hover: hover) and (pointer: fine)`})))()}function Ke(){return(Ke=e((()=>{})))()}function qe(e,t,n){let r=e.tabId===t,i=e.tabId===n;return g`
<wa-tab
class=${`board-tabs__tab ${r?`board-tabs__tab--active`:``} ${i?`board-tabs__tab--drop`:``}`}
panel=${e.tabId}
?active=${r}
data-board-tab-id=${e.tabId}
>
${e.title}
</wa-tab>
`}function Je(e){return g`
<wa-dropdown-item
class="board-tabs__overflow-item"
value=${e.tabId}
data-board-tab-id=${e.tabId}
>
${e.title}
</wa-dropdown-item>
`}function Ye(e){let{tabs:t,activeTabId:n,hoverTabId:r,onTabShow:i,onOverflowSelect:a}=e;if(t.length<=1)return v;let o=t.slice(0,6),s=t.find(e=>e.tabId===n);s&&!o.some(e=>e.tabId===s.tabId)&&(o[o.length-1]=s);let c=new Set(o.map(e=>e.tabId)),l=t.filter(e=>!c.has(e.tabId));return g`
<nav class="board-tabs" aria-label=${x(`board.tabsLabel`)}>
<wa-tab-group
class="board-tabs__track"
.active=${n}
activation="manual"
without-scroll-controls
@wa-tab-show=${i}
>
${o.map(e=>qe(e,n,r))}
</wa-tab-group>
${l.length>0?g`
<wa-dropdown
class="board-tabs__overflow"
placement="bottom-end"
@wa-select=${a}
>
<button
class="board-tabs__overflow-trigger"
slot="trigger"
type="button"
aria-label=${x(`board.moreTabs`)}
title=${x(`board.moreTabs`)}
>
•••
</button>
${l.map(e=>Je(e))}
</wa-dropdown>
`:v}
</nav>
`}function Xe(){return(Xe=e((()=>{h(),b()})))()}function Ze(e){return e?.split(`:`,1)[0]?.trim()||`unknown`}function Qe(e,t){if(!e)return null;let n=et[e];if(!n)return null;let r=Ze(e);return t.some(t=>t.kind===e&&t.pluginId===r)?n:null}function $e(e){let t=F.get(e.kind);if(t)return t;let n=e.loader();return F.set(e.kind,n),n.catch(()=>{F.get(e.kind)===n&&F.delete(e.kind)}),n}var et,F;function tt(){return(tt=e((()=>{b(),r(),et={"session:progress":{kind:`session:progress`,label:x(`sessionProgressCard.widgetLabel`),loader:async()=>(await i(async()=>{let{renderSessionProgressWidget:e}=await import(`./session-progress-BHGEJjf9.js`);return{renderSessionProgressWidget:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]),import.meta.url)).renderSessionProgressWidget}},F=new Map})))()}function nt(e){let{appView:t,widget:n}=e,r=n.grantState===`pending`||n.grantState===`rejected`?rt:0,i=Math.max(160,e.rectHeight*56+Math.max(0,e.rectHeight-1)*12-38-r),a=t?.status===`ready`&&t.expiresAtMs>Date.now()?t:void 0,o=g`<div class="board-widget__app-loading" data-test-id="board-mcp-app-loading">
${x(`board.widget.appLoading`)}
</div>`,s=a&&(!e.active||e.nearVisible)?g`<mcp-app-view
class="board-widget__mcp-app-view"
.sessionKey=${e.sessionKey}
.viewId=${a.viewId}
.height=${i}
.fixedHeight=${!0}
.title=${n.title||n.name}
@openclaw-mcp-app-view-expired=${e.expired}
></mcp-app-view>`:!e.nearVisible||!t?o:t.status===`stale`?g`<div class="board-widget__stale" data-test-id="board-mcp-app-stale">
<strong>${x(`board.widget.appStaleTitle`)}</strong>
<span>${x(`board.widget.appStaleDetail`)}</span>
<div class="board-widget__grant-actions">
<button
class="btn btn--small btn--primary"
type="button"
?disabled=${e.loading}
@click=${e.retry}
>
${x(`board.widget.retry`)}
</button>
<button
class="btn btn--small"
type="button"
?disabled=${e.busy}
@click=${e.remove}
>
${x(`board.widget.remove`)}
</button>
</div>
</div>`:o;return g`<div class="board-widget__mcp-app">${e.accessNotice}${s}</div>`}var rt;function it(){return(it=e((()=>{h(),b(),P(),rt=112})))()}function I(e,t){return`${e}\0${t.name}\0${t.revision}\0${t.instanceId??``}\0${t.grantState}`}function L(e){e!==void 0&&window.clearTimeout(e)}var at,ot;function st(){return(st=e((()=>{u(),Me(),at=5e3,ot=class{constructor(e){this.host=e,this.loading=!1,this.appViewGeneration=0,this.key=``,this.generation=0,this.visibility=new Ne(600,()=>this.visibilityChanged())}get nearVisible(){return this.visibility.nearVisible}update(e,t){if(this.callbacks=t,!e||e.contentKind!==`mcp-app`||!t){this.reset();return}let n=I(this.host.sessionKey(),e),r=t.appViewGeneration();(n!==this.key||r!==this.appViewGeneration)&&(this.clearTimers(),this.generation+=1,this.loading=!1,this.key=n,this.appViewGeneration=r,this.state=void 0)}activityChanged(){this.host.active()||(this.visibility.disconnect(),this.clearTimers())}observe(e,t){if(!e||!t){this.visibility.disconnect();return}this.visibility.observe(e)}sync(){let e=this.host.widget(),t=this.callbacks;if(!this.host.active()||!e||e.contentKind!==`mcp-app`||!t){this.renewalTimer=L(this.renewalTimer);return}if(!this.nearVisible){this.loading||(this.renewalTimer=L(this.renewalTimer));return}!this.state&&!this.loading?this.load(e,t,`cached`):this.state?.status===`ready`&&!this.loading&&this.renewalTimer===void 0&&this.expiryTimer===void 0&&this.scheduleRenewal(e,t,this.state,!1)}disconnect(){this.visibility.disconnect(),this.reset(),this.callbacks=void 0}retry(){let e=this.host.widget();this.host.active()&&e&&this.callbacks&&this.load(e,this.callbacks,`refresh`)}expire(){let e=this.host.widget(),t=this.callbacks;if(!e||!t)return;let n=this.loading;this.state={status:`stale`,error:`MCP App view expired`},this.loading=!1,this.notify(),this.host.active()&&!n&&this.load(e,t,`expired`)}reset(){this.clearTimers(),this.generation+=1,this.key=``,this.appViewGeneration=0,this.state=void 0,this.loading=!1}clearTimers(){this.renewalTimer=L(this.renewalTimer),this.expiryTimer=L(this.expiryTimer)}visibilityChanged(){queueMicrotask(()=>{this.host.connected()&&this.notify()}),!this.nearVisible&&!this.loading&&(this.renewalTimer=L(this.renewalTimer))}async load(e,t,n){if(!this.host.active()||this.loading||!this.nearVisible)return;let r=I(this.host.sessionKey(),e);if(r!==this.key)return;let i=++this.generation,a=()=>{let e=this.host.widget();return this.host.connected()&&i===this.generation&&this.key===r&&e?.contentKind===`mcp-app`&&I(this.host.sessionKey(),e)===r};this.clearTimers(),this.loading=!0;let o=n===`refresh`&&this.state?.status===`ready`?this.state:null;n===`expired`&&(this.state=void 0),this.notify(),o&&(this.expiryTimer=window.setTimeout(()=>{this.expiryTimer=void 0,a()&&(this.state={status:`stale`,error:`MCP App lease expired while renewing`},this.loading=!1,this.notify())},Math.max(0,o.expiresAtMs-Date.now())));try{let r=await(n===`cached`?t.widgetAppView(e.name,e.revision):t.refreshWidgetAppView(e.name,e.revision));if(!a())return;if(r.status===`stale`&&o&&o.expiresAtMs>Date.now()){this.loading=!1,this.notify();return}this.clearTimers(),this.state=r,this.loading=!1,this.scheduleRenewal(e,t,r,n!==`cached`),this.notify()}catch(e){if(!a())return;if(o&&o.expiresAtMs>Date.now()){this.loading=!1,this.notify();return}this.clearTimers(),this.state={status:`stale`,error:c(e)},this.loading=!1,this.notify()}}scheduleExpiry(e,t){if(t.status!==`ready`)return;this.expiryTimer=L(this.expiryTimer);let n=this.key;this.expiryTimer=window.setTimeout(()=>{this.expiryTimer=void 0;let r=this.host.widget(),i=this.state;this.host.connected()&&this.key===n&&r?.name===e.name&&r.revision===e.revision&&i?.status===`ready`&&i.viewId===t.viewId&&i.expiresAtMs===t.expiresAtMs&&(this.state={status:`stale`,error:`MCP App lease expired`},this.notify())},Math.max(0,t.expiresAtMs-Date.now()))}scheduleRenewal(e,t,n,r){if(this.renewalTimer=L(this.renewalTimer),n.status!==`ready`||!this.host.active())return;let i=this.key,a=n.expiresAtMs-Date.now()-at;if(!this.nearVisible){r&&a<=0&&this.scheduleExpiry(e,n);return}if(a<=0){r?this.scheduleExpiry(e,n):this.load(e,t,`refresh`);return}this.renewalTimer=window.setTimeout(()=>{this.renewalTimer=void 0;let n=this.host.widget();this.host.connected()&&this.host.active()&&this.nearVisible&&this.key===i&&n?.name===e.name&&n.revision===e.revision&&this.load(n,t,`refresh`)},a)}notify(){this.host.requestUpdate()}}})))()}function ct(e){let{widget:t}=e,n=t.declared?.netOrigins??[],r=t.declared?.tools??[];return g`
<div class="board-widget__grant board-widget__grant--pending" data-test-id="board-pending">
<div class="board-widget__grant-mark" aria-hidden="true">!</div>
<strong>${x(`board.widget.needsApproval`)}</strong>
${n.length>0||r.length>0?g`<div class="board-widget__grant-groups">
${n.length>0?g`<section>
<strong>${x(`board.widget.networkAccess`)}</strong>
<ul class="board-widget__grant-summary">
${n.map(e=>g`<li>${e}</li>`)}
</ul>
</section>`:v}
${r.length>0?g`<section>
<strong>${x(`board.widget.hostTools`)}</strong>
<ul class="board-widget__grant-summary">
${r.map(e=>g`<li>${e}</li>`)}
</ul>
</section>`:v}
</div>`:t.declaredSummary?.length?g`<ul class="board-widget__grant-summary">
${t.declaredSummary.map(e=>g`<li>${e}</li>`)}
</ul>`:g`<span>${x(`board.widget.needsApprovalDetail`)}</span>`}
<div class="board-widget__grant-actions">
<button
class="btn btn--small btn--primary"
type="button"
data-test-id="board-grant-allow"
?disabled=${e.disabled}
@click=${()=>e.onGrant(`granted`)}
>
${x(`board.widget.allow`)}
</button>
<button
class="btn btn--small"
type="button"
data-test-id="board-grant-reject"
?disabled=${e.disabled}
@click=${()=>e.onGrant(`rejected`)}
>
${x(`board.widget.reject`)}
</button>
</div>
${e.error??v}
</div>
`}function lt(e){if(e.grantState!==`granted`||!e.declared)return v;let t=[...(e.declared.netOrigins??[]).map(e=>x(`board.widget.networkCapability`,{capability:e})),...(e.declared.tools??[]).map(e=>x(`board.widget.toolCapability`,{capability:e}))];return t.length===0?v:g`
<openclaw-tooltip
.content=${`${x(`board.widget.activeCapabilities`)}\n${t.join(`
`)}`}
>
<span class="board-widget__capabilities" data-test-id="board-capabilities-granted">
${x(`board.widget.granted`)}
</span>
</openclaw-tooltip>
`}function R(){return(R=e((()=>{h(),b()})))()}function ut(e){let t=e.querySelector(`.board-widget__menu`);t&&(t.open=!1)}function dt(e){let{widget:t,tabs:n,disabled:r,onSelect:i}=e,a=n.filter(e=>e.tabId!==t.tabId);return g`
<wa-dropdown class="board-widget__menu" placement="bottom-end" @wa-select=${i}>
<button
class="board-widget__menu-trigger"
slot="trigger"
type="button"
aria-label=${x(`board.widget.menuLabel`)}
title=${x(`board.widget.menuLabel`)}
>
⋮
</button>
<div class="board-widget__menu-heading">${x(`board.widget.moveToTab`)}</div>
${a.length>0?a.map(e=>g`
<wa-dropdown-item value=${`move:${e.tabId}`} ?disabled=${r}>
${e.title}
</wa-dropdown-item>
`):g`<span class="board-widget__menu-empty">${x(`board.widget.noOtherTabs`)}</span>`}
<div class="board-widget__menu-heading">${x(`board.widget.resize`)}</div>
${Object.entries(V).map(([e,t])=>g`
<wa-dropdown-item
class="board-widget__preset"
value=${`resize:${e}`}
?disabled=${r}
>
${e.toUpperCase()}
<span slot="details">${t.w}×${t.h}</span>
</wa-dropdown-item>
`)}
${t.contentKind===`html`?g`<wa-dropdown-item
class="board-widget__preset"
type="checkbox"
value="height:auto"
?checked=${t.heightMode!==`fixed`}
?disabled=${r}
>
${x(`board.widget.autoHeight`)}
</wa-dropdown-item>`:v}
<div class="board-widget__menu-separator" role="separator"></div>
<wa-dropdown-item class="board-widget__menu-danger" value="remove" ?disabled=${r}>
<span slot="icon" class="board-widget__menu-icon" aria-hidden="true">${ge.trash}</span>
${x(`board.widget.remove`)}
</wa-dropdown-item>
</wa-dropdown>
`}function ft(e){return ct(e)}function pt(e){return g`
<div class="board-widget__grant board-widget__grant--rejected" data-test-id="board-rejected">
<strong>${x(`board.widget.rejected`)}</strong>
<span>${x(`board.widget.rejectedDetail`)}</span>
<button
class="btn btn--small"
type="button"
?disabled=${e.disabled}
@click=${e.onRemove}
>
${x(`board.widget.remove`)}
</button>
</div>
`}function mt(e){return g`
<div class="board-widget__disabled-plugin" data-test-id="board-disabled-plugin">
${e.content??g`<strong>${x(`board.widget.disabledPlugin`,{pluginId:e.pluginId})}</strong>`}
<button
class="btn btn--small"
type="button"
?disabled=${e.disabled}
@click=${e.onRemove}
>
${x(`board.widget.remove`)}
</button>
</div>
`}function z(e,t){let n=c(e);return g`
<div class="board-widget__error" role="alert" data-test-id="board-widget-error">
<strong>${x(`board.widget.errorTitle`)}</strong>
<span>${x(`board.widget.errorDetail`)}</span>
<details>
<summary>${x(`board.widget.errorShow`)}</summary>
<code>${n}</code>
</details>
${t?g`<button class="btn btn--small" type="button" @click=${t}>
${x(`board.widget.retry`)}
</button>`:v}
</div>
`}function B(e,t=!1){return g`
<div
class=${`board-widget__error ${t?`board-widget__error--inline`:``}`}
role="alert"
data-test-id="board-widget-action-error"
>
<strong>${x(`board.widget.actionErrorTitle`)}</strong>
<span>${x(`board.widget.actionErrorDetail`)}</span>
<details>
<summary>${x(`board.widget.errorShow`)}</summary>
<code>${e}</code>
</details>
</div>
`}var V;function ht(){return(ht=e((()=>{h(),b(),u(),me(),R(),V={sm:{w:3,h:3},md:{w:6,h:4},lg:{w:8,h:6},xl:{w:12,h:8}}})))()}function gt(e){return Ee(e)!==null}function _t(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.type===`openclaw:widget-bridge-request`&&typeof t.id==`string`&&t.id.length>0&&t.id.length<=128&&typeof t.method==`string`&&typeof t.ticket==`string`}function vt(e){if(!t(e))throw Error(`widget host request params are invalid`);return e}function H(e,t){let n=e[t];if(typeof n!=`string`||n.length===0)throw Error(`widget host request ${t} is required`);return n}var U,yt,bt,xt,St;function Ct(){return(Ct=e((()=>{xe(),Te(),U=8192,yt=5e3,bt=6e4,xt=12,St=class{constructor(e){this.recentStatePayloads=new Map,this.pendingStates=new Map,this.stateAttemptTimes=[],this.frame=e.frame,this.ticket=e.ticket,this.client=e.client,this.rateKey=e.rateKey,this.confirmPrompt=e.confirmPrompt,this.dispatchPrompt=e.dispatchPrompt??Se,this.now=e.now??Date.now,this.openUrl=e.openUrl??gt}updateIdentity(e,t){this.frame=e,this.ticket=t}async emitState(e){let t=JSON.stringify(e);if(t===void 0)throw Error(`widget state payload must be JSON`);if(new TextEncoder().encode(t).byteLength>U)throw Error(`widget state payload exceeds ${U} UTF-8 bytes`);let n=this.now();for(let[e,t]of this.recentStatePayloads)n-t>=yt&&this.recentStatePayloads.delete(e);if(this.recentStatePayloads.has(t))return{ok:!0,appended:!1,coalesced:!0};let r=this.pendingStates.get(t);if(r)return await r;if(this.stateAttemptTimes=this.stateAttemptTimes.filter(e=>n-e<bt),this.stateAttemptTimes.length>=xt)throw Error(`widget state emission rate limit exceeded`);this.stateAttemptTimes.push(n);let i=this.client.request(`board.event`,{ticket:this.ticket,payload:e});this.pendingStates.set(t,i);try{let e=await i;return this.recentStatePayloads.set(t,this.now()),e}finally{this.pendingStates.get(t)===i&&this.pendingStates.delete(t)}}async handle(e,n={}){if(e.ticket!==this.ticket)throw Error(`widget view ticket does not match the active frame`);let r=vt(e.params);switch(e.method){case`host.open`:{let e=H(r,`url`);if(!/^https?:\/\//i.test(e))throw Error(`widget link url is invalid`);if(!this.openUrl(e))throw Error(`widget link could not be opened`);return{ok:!0}}case`prompt.send`:{if(n.promptUserActivated!==!0)throw Error(`widget prompt requires active user interaction`);let e=H(r,`text`),t=await this.client.request(`board.prompt.authorize`,{ticket:this.ticket});if(n.isCurrent?.()===!1)throw Error(`widget prompt request is no longer current`);if(!this.dispatchPrompt(this.frame,e,this.rateKey,t.confirmationRequired===!1?void 0:this.confirmPrompt))throw Error(`widget prompt was not accepted`);return{ok:!0}}case`state.emit`:return await this.emitState(r.payload);case`data.read`:{let e=H(r,`bindingId`),n=r.params;if(n!==void 0&&!t(n))throw Error(`widget data binding params are invalid`);return await this.client.request(`board.data.read`,{ticket:this.ticket,bindingId:e,...n?{params:n}:{}})}case`action.run`:{let e=H(r,`action`),n=r.params;if(n!==void 0&&!t(n))throw Error(`widget action params are invalid`);return await this.client.request(`board.action`,{ticket:this.ticket,action:e,params:n??{}})}case`cron.trigger`:return await this.client.request(`board.action`,{ticket:this.ticket,action:`cron.trigger`,jobId:H(r,`jobId`)});default:throw Error(`widget host method is not supported: ${e.method}`)}}}})))()}var W,G;function wt(){return(wt=e((()=>{u(),Fe(),Ct(),W=class extends Error{constructor(e,t){super(t),this.kind=e}},G=class{constructor(e){this.active=!0,this.bridgeController=null,this.bridgePort=null,this.adoptedTicket=``,this.offeredTicket=``,this.requestGeneration=0,this.pendingRequests=new Map,this.options=e,this.documentHost=new Pe(this.documentOptions())}get frame(){return this.options.frame}setActive(e){if(e!==this.active){if(this.active=e,this.documentHost.setActive(e),!e){this.cancelPendingRequests(`Widget inactive`),this.requestGeneration+=1;return}this.postHostInit()}}update(e){let t=this.options.client,n=this.documentKey(),r=this.options.sandboxUrl;this.options=e;let i=n!==this.documentKey(),a=r!==e.sandboxUrl;(i||a)&&(this.reset(),this.bridgeController=null,this.bridgeClient=void 0),t!==e.client&&(this.cancelPendingRequests(`Gateway connection changed`),this.requestGeneration+=1,this.bridgeController=null,this.bridgeClient=void 0,this.documentHost.loaded||this.documentHost.reset()),this.documentHost.update(this.documentOptions()),e.widget.viewTicket&&!i&&(this.adoptedTicket&&this.bridgeController?.updateIdentity(e.frame,this.adoptedTicket),this.postHostInit())}reset(){this.documentHost.reset(),this.requestGeneration+=1,this.pendingRequests.clear(),this.bridgePort?.close(),this.bridgePort=null,this.adoptedTicket=``,this.offeredTicket=``}dispose(){this.active=!1,this.reset(),this.documentHost.dispose(),this.bridgeController=null,this.bridgeClient=void 0}accepts(e){return e.source===this.options.frame.contentWindow&&e.origin===this.options.sandboxOrigin}handleFrameError(){this.documentHost.handleFrameError()}handleMessage(e){if(this.accepts(e)&&(this.documentHost.handleMessage(e),e.data?.method!==`ui/notifications/sandbox-proxy-ready`&&this.documentHost.ready)){if(e.data?.type===`openclaw:widget-prompt-offer`){e.ports[0]?.close();return}if(e.data?.type===`openclaw:widget-bridge-port-offer`){let t=e.ports[0];if(this.options.bridgeEnabled===!1||!t||this.bridgePort){t?.close();return}this.bridgePort=t,t.addEventListener(`message`,e=>{this.handleBridgeMessage(e.data)}),t.start(),this.postHostInit();return}e.data?.type===`openclaw:widget-bridge-ready`&&this.postHostInit()}}handleBridgeMessage(e){if(this.options.bridgeEnabled!==!1){if(e&&typeof e==`object`&&Reflect.get(e,`type`)===`openclaw:widget-host-init-ack`&&typeof Reflect.get(e,`ticket`)==`string`){let t=Reflect.get(e,`ticket`);if(t!==this.offeredTicket)return;this.offeredTicket=``,this.adoptedTicket=t,this.bridgeController?.updateIdentity(this.options.frame,t),this.postHostInit();return}if(!this.active){_t(e)&&this.postResponse(e.id,!1,void 0,`Widget inactive`);return}this.handleBridgeRequest(e)}}handleBridgeRequest(e){if(!this.documentHost.ready||!_t(e))return;let t=this.options.client,n=this.adoptedTicket;if(!t||!n){this.postResponse(e.id,!1,void 0,`Gateway unavailable`);return}!this.bridgeController||this.bridgeClient!==t?(this.bridgeClient=t,this.bridgeController=new St({frame:this.options.frame,ticket:n,client:t,rateKey:this.documentKey(),confirmPrompt:this.options.confirmPrompt})):this.bridgeController.updateIdentity(this.options.frame,n);let r=this.requestGeneration,i=this.options.frame;this.pendingRequests.set(e.id,r),this.bridgeController.handle(e,{promptUserActivated:e.method===`prompt.send`,isCurrent:()=>r===this.requestGeneration&&i===this.options.frame}).then(t=>{this.completeRequest(e.id,r,!0,t)}).catch(t=>{this.completeRequest(e.id,r,!1,void 0,c(t))})}completeRequest(e,t,n,r,i){t===this.requestGeneration&&this.pendingRequests.get(e)===t&&(this.pendingRequests.delete(e),this.postResponse(e,n,r,i))}cancelPendingRequests(e){for(let[t,n]of this.pendingRequests)n===this.requestGeneration&&this.postResponse(t,!1,void 0,e);this.pendingRequests.clear()}documentKey(){let e=this.options.resolveFrameUrl(this.options.widget.name,this.options.widget.revision).split(/[?#]/u,1)[0],t=this.options.widget.viewGeneration??this.options.widget.viewTicket??``,n=this.options.bridgeEnabled===!1?`passive`:`interactive`;return`${e}\0${this.options.widget.revision}\0${t}\0${n}`}postHostInit(){let e=this.options.widget.viewTicket;if(this.options.bridgeEnabled===!1||!this.documentHost.ready||!this.active||!this.bridgePort||!e||!this.documentHost.loaded||e===this.adoptedTicket||this.offeredTicket!==``)return;this.offeredTicket=e;let t=this.options.controlUiBaseUrl?.trim();this.bridgePort.postMessage({type:`openclaw:widget-host-init`,ticket:e,...t?{controlUiBaseUrl:t}:{}},[])}documentOptions(){let e=this.options;return{frame:e.frame,sandboxOrigin:e.sandboxOrigin,sandboxUrl:e.sandboxUrl,documentKey:this.documentKey(),loadDocument:t=>this.fetchDocument(e,t),onLoaded:()=>{this.options.onLoaded(),this.postHostInit()},onError:e=>{if(e instanceof W){e.kind===`unauthorized`?this.options.onUnauthorized(this.options.widget):this.options.onError(e);return}this.options.onLoadFailed(this.options.widget)},onReadyTimeout:()=>{this.reset(),this.options.onReadyTimeout()}}}async fetchDocument(e,t){let{widget:n,resolveFrameUrl:r,sourceOrigin:i}=e,a;try{a=new URL(r(n.name,n.revision),i)}catch(e){throw new W(`invalid-url`,c(e))}if(a.origin!==i)throw new W(`invalid-url`,`widget content URL is outside the active Gateway`);e.onFrameUrl(a.href);let o=await fetch(a.href,{cache:`no-store`,signal:t});if(o.status===401)throw new W(`unauthorized`,`widget content request failed (401)`);if(!o.ok)throw Error(`widget content request failed (${o.status})`);return await o.text()}postResponse(e,t,n,r){this.bridgePort?.postMessage({type:`openclaw:widget-bridge-response`,id:e,ok:t,...t?{result:n}:{error:r??`widget host request failed`}})}}})))()}function Tt(){return typeof document<`u`&&document.visibilityState===`hidden`}function Et(e,t){if(!e.sandboxOrigin&&t)try{if(!f(new URL(t).hostname))return x(`board.widget.sandboxOriginRequired`)}catch{}return x(`board.widget.frameAuthorizationFailed`)}var Dt,Ot,kt,K,At,jt,Mt,q,Nt,Pt;function Ft(){return(Ft=e((()=>{h(),b(),wt(),be(),u(),l(),Oe(),Dt=`openclaw:widget-size`,Ot=`openclaw:widget-board-host`,kt=`openclaw:widget-scroll`,K=3,At=15e3,jt=1e3,Mt=1e3,q=3e4,Nt=class{constructor(e,t){this.currentTicket=e,this.canRefresh=t,this.timer=null,this.attempts=0,this.scheduledTicket=``}clearTimer(){this.timer!==null&&(window.clearTimeout(this.timer),this.timer=null)}reset(){this.clearTimer(),this.attempts=0,this.scheduledTicket=``}schedule(e,t){let n=e?.viewTicket,r=e?ye(e):void 0;if(!this.canRefresh()||!e||!t||!n||r===void 0){this.reset();return}if(this.scheduledTicket===n)return;this.clearTimer(),this.attempts=0,this.scheduledTicket=n;let i=Math.max(jt,r-At);this.timer=window.setTimeout(()=>{this.timer=null,this.refresh(e.name,n,t)},i)}refresh(e,t,n){if(!this.canRefresh()){this.reset();return}if(this.currentTicket()!==t||this.scheduledTicket!==t)return;this.attempts+=1;let r=()=>{this.currentTicket()===t&&this.scheduledTicket===t&&(this.clearTimer(),this.timer=window.setTimeout(()=>{this.timer=null,this.refresh(e,t,n)},Math.min(Mt*this.attempts,q)))};n(e).then(r,r)}},Pt=class{constructor(e){this.host=e,this.error=``,this.frameFailureKey=``,this.frameRefreshAttempts=0,this.frameProbeGeneration=0,this.boardHostNonce=``,this.lastFrameUrl=``,this.messageListening=!1,this.visibilityListening=!1,this.sandboxOrigin=``,this.sandboxHost=null,this.ticketRefresh=new Nt(()=>this.host.widget()?.viewTicket,()=>this.host.active()&&!Tt()),this.handleVisibilityChange=()=>{if(Tt()){this.ticketRefresh.reset();return}this.ticketRefresh.schedule(this.host.widget(),this.host.refreshFrame())},this.handleWindowMessage=e=>{if(!this.host.connected())return;let t=this.host.root().querySelector(`.board-widget__frame`),n=this.host.widget();if(!this.host.active()){t&&e.source===t.contentWindow&&e.origin===this.sandboxOrigin&&this.sandboxHost?.handleMessage(e);return}let r=e.data;if(t&&n&&e.source===t.contentWindow&&r?.type===Dt&&typeof r.height==`number`&&Number.isFinite(r.height)&&r.height>0&&this.host.reportContentHeight(n.name,r.height),t&&n&&e.source===t.contentWindow&&r?.type===kt&&r.nonce===this.boardHostNonce&&typeof r.deltaY==`number`&&Number.isFinite(r.deltaY)&&r.deltaY!==0&&this.host.scrollBy(r.deltaY),!t||!n?.viewTicket||e.source!==t.contentWindow||e.origin!==this.sandboxOrigin)return;let i=this.sandboxHostOptions(t,n);i&&(!this.sandboxHost||this.sandboxHost.frame!==t?(this.sandboxHost?.dispose(),this.sandboxHost=new G(i)):this.sandboxHost.update(i),this.sandboxHost.handleMessage(e),e.data?.type===`openclaw:widget-bridge-ready`&&this.postBoardHostState(t))}}connect(){this.messageListening||=(window.addEventListener(`message`,this.handleWindowMessage),!0),this.host.active()&&!this.visibilityListening&&(document.addEventListener(`visibilitychange`,this.handleVisibilityChange),this.visibilityListening=!0),ke()}disconnect(){this.stopWork(),this.messageListening&&=(window.removeEventListener(`message`,this.handleWindowMessage),!1),this.sandboxHost?.dispose(),this.sandboxHost=null}suspend(){this.stopWork(),this.sandboxHost?.setActive(!1)}stopWork(){this.visibilityListening&&=(document.removeEventListener(`visibilitychange`,this.handleVisibilityChange),!1),this.ticketRefresh.reset()}activityChanged(){this.host.active()?(this.connect(),this.sandboxHost?.setActive(!0)):this.suspend()}widgetChanged(e,t){if(e.name!==t?.name||e.revision!==t?.revision){this.resetFailures(!1);return}if(!t||!this.error)return;let n=this.host.resolveFrameUrl()?.(t.name,t.revision)??``;n&&n!==this.lastFrameUrl&&this.setError(``,!1)}update(){if(!this.host.active()){this.suspend();return}this.resume()}resume(){this.connect(),this.ticketRefresh.schedule(this.host.widget(),this.host.refreshFrame()),this.updateSandboxHost(),this.sandboxHost?.setActive(!0)}render(e){let t=this.host.resolveFrameUrl();if(!t)throw Error(x(`board.widget.frameResolverMissing`));let n=t(e.name,e.revision);this.lastFrameUrl=n;let r=this.resolveSandboxFrameUrl(e);if(r)return g`
<iframe
class="board-widget__frame"
sandbox="allow-scripts allow-same-origin allow-forms"
referrerpolicy="origin"
loading="eager"
title=${e.title||e.name}
src=${r}
@error=${()=>{this.sandboxHost?this.sandboxHost.handleFrameError():this.refreshFailedFrame(e)}}
@load=${e=>this.notifyBoardHost(e)}
></iframe>
`;if(e.sandboxUrl||e.sandboxPort||e.viewTicket)throw Error(x(`board.widget.sandboxUnavailable`));return g`
<iframe
class="board-widget__frame"
sandbox="allow-scripts"
referrerpolicy="no-referrer"
loading="lazy"
title=${e.title||e.name}
src=${n}
@error=${()=>this.refreshFailedFrame(e)}
@load=${t=>{this.notifyBoardHost(t),this.verifyAuthorization(t,e)}}
></iframe>
`}setError(e,t=!0){this.error!==e&&(this.error=e,t&&this.host.requestUpdate())}resetFailures(e=!0){this.frameProbeGeneration+=1,this.frameFailureKey=``,this.frameRefreshAttempts=0,this.setError(``,e),this.sandboxHost?.reset()}refreshFailedFrame(e){if(!this.host.active())return;this.frameProbeGeneration+=1;let t=`${e.name}:${e.revision}`;if(this.frameFailureKey!==t&&(this.resetFailures(!1),this.frameFailureKey=t),this.frameRefreshAttempts>=K){this.setError(Et(e,this.sandboxOrigin));return}let n=this.host.refreshFrame();if(!n){this.setError(x(`board.widget.frameResolverMissing`));return}this.frameRefreshAttempts+=1,n(e.name).catch(e=>{this.setError(c(e))}),this.frameRefreshAttempts>=K&&this.setError(Et(e,this.sandboxOrigin))}verifyAuthorization(e,t){let n=e.currentTarget,r=n instanceof HTMLIFrameElement?n.getAttribute(`src`)??``:``;if(!r.startsWith(`/__openclaw__/board/`))return;let i=this.frameProbeGeneration+1;this.frameProbeGeneration=i;let a=()=>n instanceof HTMLIFrameElement&&n.isConnected&&n.getAttribute(`src`)===r&&this.frameProbeGeneration===i&&this.host.active()&&this.host.widget()?.name===t.name&&this.host.widget()?.revision===t.revision;fetch(r,{cache:`no-store`}).then(e=>{a()&&(e.status===401?this.refreshFailedFrame(t):e.ok&&this.resetFailures())}).catch(()=>{a()&&this.refreshFailedFrame(t)})}notifyBoardHost(e){let t=e.currentTarget;t instanceof HTMLIFrameElement&&this.postBoardHostState(t)}postBoardHostState(e){this.boardHostNonce=ee(),De(e,this.sandboxOrigin||`*`),e.contentWindow?.postMessage({type:Ot,nonce:this.boardHostNonce},this.sandboxOrigin||`*`)}resolveSandboxFrameUrl(e){let t=this.host.context()?.gateway.connection.gatewayUrl;if(!e.sandboxUrl||!e.sandboxPort||!e.viewTicket||t===void 0)return;let n=we(e.sandboxUrl,e.sandboxPort,e.sandboxOrigin,t,window.location.origin);return this.sandboxOrigin=new URL(n).origin,n}sandboxHostOptions(e,t){let n=this.host.resolveFrameUrl();if(n)return{frame:e,widget:t,bridgeEnabled:this.host.bridgeEnabled?.()??!0,sandboxOrigin:this.sandboxOrigin,sandboxUrl:e.src,sourceOrigin:Ce(this.host.context()?.gateway.connection.gatewayUrl??``,window.location.origin),controlUiBaseUrl:`${window.location.origin}${this.host.context()?.basePath??``}`,client:this.host.context()?.gateway.snapshot.client??void 0,resolveFrameUrl:n,confirmPrompt:e=>window.confirm(`${x(`common.confirm`)}:\n\n${e}`),onFrameUrl:e=>{this.lastFrameUrl=e},onLoadFailed:e=>this.refreshFailedFrame(e),onUnauthorized:e=>this.refreshFailedFrame(e),onReadyTimeout:()=>this.refreshFailedFrame(t),onLoaded:()=>{this.frameFailureKey=``,this.frameRefreshAttempts=0,this.setError(``)},onError:e=>{this.setError(c(e))}}}updateSandboxHost(){let e=this.host.root().querySelector(`.board-widget__frame`),t=this.host.widget();if(!e?.isConnected||!t||!t.sandboxUrl||!t.sandboxPort||!t.viewTicket){this.sandboxHost?.dispose(),this.sandboxHost=null;return}let n=this.sandboxHostOptions(e,t);n&&(!this.sandboxHost||this.sandboxHost.frame!==e?(this.sandboxHost?.dispose(),this.sandboxHost=new G(n)):this.sandboxHost.update(n))}}})))()}var It,J;function Y(){return(Y=e((()=>{o(),h(),m(),de(),pe(),b(),P(),tt(),u(),ne(),d(),s(),je(),te(),it(),st(),R(),ht(),Ft(),he(),_e(),r(),It=()=>i(()=>import(`./mcp-app-view-registration-BuAQbPJ2.js`),__vite__mapDeps([21,1,2,3,4,5,6,7,8,10,11,12,13,20,9,14,15,16,17,18,19]),import.meta.url),J=class extends p{constructor(...e){super(...e),this.fitAutoContent=!1,this.tabs=[],this.session={sessionKey:``},this.sessionKey=``,this.active=!0,this.bridgeEnabled=!0,this.dragging=!1,this.focusTabIndex=-1,this.positionInSet=1,this.setSize=1,this.busy=!1,this.canMutate=!0,this.canGrant=!0,this.actionError=``,this.actionPending=!1,this.pluginRenderer=null,this.pluginRendererError=``,this.pluginRendererLabel=``,this.pluginRendererKind=``,this.pluginRendererLoadToken=null,this.pluginSubscriptions=new ae(this).watch(()=>this.context?.plugins,(e,t)=>e.subscribe(t)),this.appView=new ot({active:()=>this.active,connected:()=>this.isConnected,requestUpdate:()=>this.requestUpdate(),sessionKey:()=>this.sessionKey,widget:()=>this.widget}),this.frame=new Pt({active:()=>this.active,bridgeEnabled:()=>this.bridgeEnabled,connected:()=>this.isConnected,context:()=>this.context,refreshFrame:()=>this.callbacks?.frameLoadFailed,reportContentHeight:(e,t)=>this.callbacks?.reportContentHeight(e,t),scrollBy:e=>{this.closest(`openclaw-board-view`)?.scrollBy({top:e,behavior:`auto`})},requestUpdate:()=>this.requestUpdate(),resolveFrameUrl:()=>this.widgetFrameUrl,root:()=>this,widget:()=>this.widget})}connectedCallback(){super.connectedCallback(),this.frame.connect(),this.requestUpdate()}willUpdate(e){let t=e.get(`widget`);t&&t!==this.widget&&(this.actionError=``,this.frame.widgetChanged(t,this.widget)),this.appView.update(this.widget,this.callbacks),e.has(`active`)&&(this.appView.activityChanged(),this.frame.activityChanged(),this.active&&this.appView.observe(this.querySelector(`.board-widget`),this.widget?.contentKind===`mcp-app`)),this.syncPluginRenderer()}updated(){if(!this.isConnected){this.appView.observe(null,!1);return}this.appView.observe(this.querySelector(`.board-widget`),this.active&&this.widget?.contentKind===`mcp-app`),queueMicrotask(()=>{this.isConnected&&this.appView.sync()}),this.frame.update()}disconnectedCallback(){this.pluginSubscriptions.clear(),this.resetPluginRenderer(),this.frame.disconnect(),this.appView.disconnect(),super.disconnectedCallback()}async runAction(e,t){if(!(this.actionPending||this.busy)){this.actionPending=!0,this.actionError=``,ut(this);try{await e()}catch(e){this.actionError=c(e),t&&ie({message:t})}finally{this.actionPending=!1}}}runGrantDecision(e,t,n){let r=x(n===`granted`?`board.widget.allowFailed`:`board.widget.rejectFailed`);this.runAction(()=>t.grant(e.name,n),r)}handleMenuSelect(e,t,n){if(!this.canMutate)return;let r=e.detail.item.value;if(r===`remove`){this.runAction(()=>n.remove(t));return}if(r?.startsWith(`move:`)){this.runAction(()=>n.moveToTab(t,r.slice(5)));return}if(r?.startsWith(`resize:`)){let e=r.slice(7),i=V[e];i&&this.runAction(()=>n.resizeTo(t,i.w,i.h));return}if(r===`height:auto`){let e=t.heightMode===`fixed`?`auto`:`fixed`;this.runAction(()=>n.setHeightMode(t,e))}}renderMcpApp(e,t){return ue(`mcp-app-view`,It).catch(()=>void 0),nt({accessNotice:e.grantState===`pending`?ft({widget:e,disabled:this.busy||this.actionPending||!this.canGrant,onGrant:n=>this.runGrantDecision(e,t,n),...this.actionError?{error:B(this.actionError,!0)}:{}}):e.grantState===`rejected`?pt({widget:e,disabled:this.busy||this.actionPending||!this.canMutate,onRemove:()=>void this.runAction(()=>t.remove(e))}):v,appView:this.appView.state,busy:this.busy||this.actionPending||!this.canMutate,active:this.active,loading:this.appView.loading,nearVisible:this.appView.nearVisible,rectHeight:this.rect?.h??4,sessionKey:this.sessionKey,widget:e,expired:()=>this.appView.expire(),remove:()=>void this.runAction(()=>t.remove(e)),retry:()=>this.appView.retry()})}renderBody(e,t){if(e.contentKind===`mcp-app`)return this.renderMcpApp(e,t);if(e.grantState===`pending`)return ft({widget:e,disabled:this.busy||this.actionPending||!this.canGrant,onGrant:n=>this.runGrantDecision(e,t,n),...this.actionError?{error:B(this.actionError,!0)}:{}});if(e.grantState===`rejected`)return pt({widget:e,disabled:this.busy||this.actionPending||!this.canMutate,onRemove:()=>void this.runAction(()=>t.remove(e))});if(e.contentKind===`plugin`&&e.frameUrl)return this.frame.render(e);if(e.contentKind===`plugin`){let n=Ze(e.pluginKind),r=this.context?.gateway.snapshot.hello?.controlUiWidgetKinds??[],i=this.context?.plugins,a=`${n}/${e.pluginKind?.slice(n.length+1)}`,o=r.some(t=>t.kind===e.pluginKind&&t.pluginId===n);if(o&&i?.registrations(`widgets`).find(e=>e.key===a))return re(`widgets`,a,{...this.session,widget:{name:e.name,props:e.props},canMutate:this.canMutate,canGrant:this.canGrant},v,this.active);if(this.pluginRendererError)return z(this.pluginRendererError,()=>this.retryPluginRenderer());if(this.pluginRenderer)return this.pluginRenderer({widget:e,sessionKey:this.sessionKey,active:this.active,canMutate:this.canMutate,requestUpdate:()=>this.requestUpdate()});if(Qe(e.pluginKind,r)||this.context&&this.context.gateway.snapshot.phase!==`connected`||i?.isLoading(n))return g`<p class="board-widget__plugin-loading">${x(`board.widget.pluginLoading`)}</p>`;let s=Ae(this.context,n);if(!s&&o&&i){let e=i.errors.find(e=>e.pluginId===n||e.pluginId===`host`);if(e)return z(e.message,()=>void i.refresh())}return mt({pluginId:n,content:s,disabled:this.busy||this.actionPending||!this.canMutate,onRemove:()=>void this.runAction(()=>t.remove(e))})}return this.frame.render(e)}syncPluginRenderer(){let e=this.widget,t=this.context?.gateway.snapshot.hello?.controlUiWidgetKinds??[],n=e?.contentKind===`plugin`&&!e.frameUrl?Qe(e.pluginKind,t):null;if(!n){(this.pluginRendererKind||this.pluginRenderer||this.pluginRendererError)&&this.resetPluginRenderer();return}if(this.pluginRendererKind===n.kind)return;let r={};this.pluginRendererKind=n.kind,this.pluginRendererLabel=n.label,this.pluginRenderer=null,this.pluginRendererError=``,this.pluginRendererLoadToken=r,$e(n).then(e=>{this.pluginRendererLoadToken===r&&(this.pluginRenderer=e,this.requestUpdate())}).catch(e=>{this.pluginRendererLoadToken===r&&(this.pluginRendererError=c(e),this.requestUpdate())})}resetPluginRenderer(){this.pluginRendererLoadToken=null,this.pluginRendererKind=``,this.pluginRendererLabel=``,this.pluginRenderer=null,this.pluginRendererError=``}retryPluginRenderer(){this.resetPluginRenderer(),this.requestUpdate()}handleKeyDown(e,t,n){if(e.target!==e.currentTarget||!this.canMutate)return;let r=e.key===`ArrowLeft`?`left`:e.key===`ArrowRight`?`right`:e.key===`ArrowUp`?`up`:e.key===`ArrowDown`?`down`:null;r&&(e.preventDefault(),e.altKey?this.runAction(()=>n.nudge(t,r)):n.focus(t,r))}render(){let e=this.widget,t=this.rect,n=this.callbacks;if(!e||!t||!n)return v;let r,i;try{r=this.frame.error?z(this.frame.error):this.renderBody(e,n),i=!!this.frame.error}catch(e){r=z(e),i=!0}let a=e.title||e.name,o=!this.canMutate,s=i||this.actionError!==``||e.grantState===`pending`||e.grantState===`rejected`||e.contentKind===`mcp-app`||e.contentKind===`plugin`&&!e.frameUrl,c=e.contentKind===`html`||e.frameUrl?e.presentation??`card`:void 0,l=this.dragging?void 0:We(e,this.contentHeightPx,D(),this.fitAutoContent?240:void 0),u=l===void 0?``:` height: ${l}px; align-self: start;`;return g`
<section
class=${`board-widget ${this.dragging?`board-widget--dragging`:``} ${c?`board-widget--${c}`:``}`}
style=${`${He(t)} --board-widget-rows: ${t.h}; --board-widget-order: ${this.positionInSet};${u}`}
role="listitem"
tabindex=${this.focusTabIndex}
aria-posinset=${this.positionInSet}
aria-setsize=${this.setSize}
aria-label=${o?a:x(`board.widget.cellLabel`,{title:a})}
data-widget-name=${e.name}
data-test-id="board-widget"
@focus=${()=>n.focusChanged(e.name)}
@keydown=${t=>this.handleKeyDown(t,e,n)}
>
<header class="board-widget__bar">
${o?v:g`<span
class="board-widget__drag-handle"
aria-hidden="true"
title=${x(`board.widget.moveHandle`,{title:a})}
@pointerdown=${t=>n.movePointerDown(e,t)}
>
<span aria-hidden="true">⠿</span>
</span>`}
<span class="board-widget__title" title=${a}>${a}</span>
<span class="board-widget__kind"
>${e.contentKind===`mcp-app`?x(`board.widget.kindMcp`):e.contentKind===`plugin`?e.kindLabel||this.pluginRendererLabel||x(`board.widget.kindPlugin`):x(`board.widget.kindHtml`)}</span
>
${lt(e)}
${o?v:dt({widget:e,tabs:this.tabs,disabled:this.busy||this.actionPending,onSelect:t=>this.handleMenuSelect(t,e,n)})}
</header>
<div
class=${`board-widget__body ${s?`board-widget__body--scrollable`:``} ${c===`card`?`board-widget__body--card`:``}`}
>
${r}
${this.actionError&&e.grantState!==`pending`?g`<div class="board-widget__error-overlay">
${B(this.actionError)}
</div>`:v}
</div>
${o?v:g`<span
class="board-widget__resize-handle"
aria-hidden="true"
title=${x(`board.widget.resizeHandle`,{title:a})}
@pointerdown=${t=>n.resizePointerDown(e,t)}
></span>`}
${e.grantState===`granted`?g`<span class="board-widget__grant-dot" aria-hidden="true"></span>`:v}
</section>
`}},a([n({context:fe,subscribe:!0})],J.prototype,`context`,void 0),a([y({attribute:!1})],J.prototype,`widget`,void 0),a([y({attribute:!1})],J.prototype,`rect`,void 0),a([y({attribute:!1})],J.prototype,`contentHeightPx`,void 0),a([y({type:Boolean})],J.prototype,`fitAutoContent`,void 0),a([y({attribute:!1})],J.prototype,`tabs`,void 0),a([y({attribute:!1})],J.prototype,`session`,void 0),a([y({attribute:!1})],J.prototype,`sessionKey`,void 0),a([y({attribute:!1})],J.prototype,`widgetFrameUrl`,void 0),a([y({attribute:!1})],J.prototype,`callbacks`,void 0),a([y({type:Boolean})],J.prototype,`active`,void 0),a([y({type:Boolean})],J.prototype,`bridgeEnabled`,void 0),a([y({type:Boolean})],J.prototype,`dragging`,void 0),a([y({type:Number})],J.prototype,`focusTabIndex`,void 0),a([y({type:Number})],J.prototype,`positionInSet`,void 0),a([y({type:Number})],J.prototype,`setSize`,void 0),a([y({type:Boolean})],J.prototype,`busy`,void 0),a([y({type:Boolean})],J.prototype,`canMutate`,void 0),a([y({type:Boolean})],J.prototype,`canGrant`,void 0),a([_()],J.prototype,`actionError`,void 0),a([_()],J.prototype,`actionPending`,void 0),a([_()],J.prototype,`pluginRenderer`,void 0),a([_()],J.prototype,`pluginRendererError`,void 0),a([_()],J.prototype,`pluginRendererLabel`,void 0),customElements.get(`openclaw-board-widget-cell`)||customElements.define(`openclaw-board-widget-cell`,J)})))()}function X(e){return e.tabs.toSorted((e,t)=>e.position-t.position||e.tabId.localeCompare(t.tabId))}function Z(e,t){return e.widgets.filter(e=>e.tabId===t).toSorted((e,t)=>e.position-t.position||e.name.localeCompare(t.name))}function Q(e,t,n=!1){let r=D();return e.map(e=>({name:e.name,w:e.sizeW,h:k(e,t.get(e.name),r,n?240:void 0),order:e.position}))}var $;function Lt(){return(Lt=e((()=>{h(),m(),oe(),ce(),b(),P(),d(),ve(),_e(),Xe(),Y(),$=class extends p{constructor(...e){super(...e),this.session={sessionKey:``},this.activeTabId=``,this.active=!0,this.bridgeEnabled=!0,this.canMutate=!0,this.canGrant=!0,this.fitAutoContent=!1,this.previewItems=null,this.gestureName=``,this.hoverTabId=``,this.announcement=``,this.announcementRevision=0,this.actionError=``,this.focusName=``,this.mutationPending=!1,this.gesture=null,this.mutationRequestId=0,this.stableCellOrder=new Map,this.stableCellOrderSequence=0,this.contentHeights=new Map,this.finePointerQuery=typeof window.matchMedia==`function`?window.matchMedia(Ge):null,this.handlePointerModeChange=()=>this.requestUpdate(),this.cellCallbacks={appViewGeneration:()=>this.callbacks?.appViewGeneration??0,grant:async(e,t)=>{if(!this.callbacks)return;let n=this.snapshot?.sessionKey;await this.callbacks.grant(e,t),n===this.snapshot?.sessionKey&&this.announce(x(t===`granted`?`board.announcement.granted`:`board.announcement.rejected`))},movePointerDown:(e,t)=>this.beginGesture(`move`,e,t),resizePointerDown:(e,t)=>this.beginGesture(`resize`,e,t),moveToTab:async(e,t)=>this.applyOps([{kind:`widget_move`,name:e.name,tabId:t,position:this.nextPosition(t)}],x(`board.announcement.moved`,{title:e.title||e.name})),resizeTo:async(e,t,n)=>this.applyOps([{kind:`widget_resize`,name:e.name,sizeW:t,sizeH:n,heightMode:`fixed`}],x(`board.announcement.resized`,{title:e.title||e.name})),setHeightMode:async(e,t)=>{let n=t===`fixed`?k(e,this.contentHeights.get(e.name),D()):e.sizeH;await this.applyOps([{kind:`widget_resize`,name:e.name,sizeW:e.sizeW,sizeH:n,heightMode:t}],x(`board.announcement.resized`,{title:e.title||e.name}))},reportContentHeight:(e,t)=>{let n=this.snapshot?.widgets.find(t=>t.name===e);!n||n.contentKind!==`html`||this.contentHeights.get(e)!==t&&(this.contentHeights.set(e,t),this.requestUpdate())},remove:async e=>this.applyOps([{kind:`widget_remove`,name:e.name}],x(`board.announcement.removed`,{title:e.title||e.name})),nudge:async(e,t)=>this.nudgeWidget(e,t),focus:(e,t)=>this.focusWidget(e,t),focusChanged:e=>{this.focusName=e},frameLoadFailed:async e=>this.callbacks?.frameLoadFailed?.(e),widgetAppView:async(e,t)=>await this.callbacks?.widgetAppView?.(e,t)??{status:`stale`,error:`MCP App view unavailable`},refreshWidgetAppView:async(e,t)=>await this.callbacks?.refreshWidgetAppView?.(e,t)??{status:`stale`,error:`MCP App view unavailable`}},this.handlePointerMove=e=>{let t=this.gesture;if(!t||e.pointerId!==t.pointerId)return;if(t.mode===`move`){let n=document.elementFromPoint(e.clientX,e.clientY)?.closest(`[data-board-tab-id]`),r=n?.closest(`openclaw-board-view`)===this?n.dataset.boardTabId??``:``,i=r!==``&&(this.snapshot?.tabs.some(e=>e.tabId===r)??!1),a=this.snapshot?this.activeTab(X(this.snapshot))?.tabId:this.activeTabId;if(this.hoverTabId=i&&r!==a?r:``,n){this.previewItems=t.items,t.dropValid=this.hoverTabId!==``;return}let o=this.querySelector(`.board-grid`),s=document.elementFromPoint(e.clientX,e.clientY);if(!o||s?.closest(`.board-grid`)!==o){this.hoverTabId=``,this.previewItems=t.items,t.dropValid=!1;return}t.dropValid=!0;let c=o.getBoundingClientRect(),l=Math.max(1,(c.width-132)/12),u=this.previewItems??t.items,d=s?.closest(`openclaw-board-widget-cell`)?.widget?.name,f=T(u).find(e=>e.name===d)??{x:Math.floor((e.clientX-c.left)/(l+12)),y:Math.floor((e.clientY-c.top)/68)};this.previewItems=ze(u,t.name,f).items;return}let n=this.querySelector(`.board-grid`)?.getBoundingClientRect(),r=n?Math.max(1,(n.width-132)/12):56,i=Math.round((e.clientX-t.originClientX)/(r+12)),a=Math.round((e.clientY-t.originClientY)/68);this.previewItems=Be(t.items,t.name,t.originW+i,t.originH+a)},this.handlePointerUp=e=>{let t=this.gesture;if(!t||e.pointerId!==t.pointerId)return;this.handlePointerMove(e);let n=this.previewItems,r=this.hoverTabId;this.cancelGesture();let i=this.snapshot?.widgets.find(e=>e.name===t.name);if(!i)return;if(t.mode===`move`){if(!t.dropValid)return;let e=r?this.nextPosition(r):n?.find(e=>e.name===t.name)?.order??i.position;if(!r&&e===i.position)return;this.applyOps([{kind:`widget_move`,name:t.name,...r?{tabId:r}:{},position:e}],x(`board.announcement.moved`,{title:i.title||i.name})).catch(()=>void 0);return}let a=n?.find(e=>e.name===t.name);a&&(a.w!==t.originW||a.h!==t.originH)&&this.applyOps([{kind:`widget_resize`,name:t.name,sizeW:a.w,sizeH:a.h,heightMode:`fixed`}],x(`board.announcement.resized`,{title:i.title||i.name})).catch(()=>void 0)},this.handlePointerCancel=e=>{this.gesture&&e.pointerId===this.gesture.pointerId&&this.cancelGesture()},this.handleTabShow=e=>{let t=this.snapshot?X(this.snapshot):[],n=this.activeTab(t)?.tabId??this.activeTabId;e.detail.name!==n&&t.some(t=>t.tabId===e.detail.name)&&this.callbacks?.selectTab(e.detail.name)},this.handleOverflowSelect=e=>{let t=e.detail.item.value;t&&this.snapshot?.tabs.some(e=>e.tabId===t)&&this.callbacks?.selectTab(t)}}connectedCallback(){super.connectedCallback(),this.finePointerQuery?.addEventListener(`change`,this.handlePointerModeChange)}willUpdate(e){if(e.has(`snapshot`)){this.actionError=``;let t=e.get(`snapshot`);if(t?.sessionKey!==this.snapshot?.sessionKey)this.mutationRequestId+=1,this.mutationPending=!1,this.focusName=``,this.stableCellOrder.clear(),this.stableCellOrderSequence=0,this.contentHeights.clear();else if(t&&this.snapshot){let e=new Map(t.widgets.map(e=>[e.name,e]));for(let t of this.contentHeights.keys()){let n=e.get(t),r=this.snapshot.widgets.find(e=>e.name===t);(!r||r.contentKind!==`html`||n?.revision!==r.revision)&&this.contentHeights.delete(t)}}}e.has(`activeTabId`)&&(this.focusName=``),this.gesture&&(e.has(`snapshot`)||e.has(`activeTabId`)||e.has(`active`)&&!this.active)&&this.cancelGesture()}disconnectedCallback(){this.finePointerQuery?.removeEventListener(`change`,this.handlePointerModeChange),this.cancelGesture(),super.disconnectedCallback()}activeTab(e){return e.find(e=>e.tabId===this.activeTabId)??e[0]}announce(e){this.announcement=e,this.announcementRevision+=1}async applyOps(e,t){if(!this.callbacks)return;if(this.mutationPending)throw Error(x(`board.actionInProgress`));let n=this.snapshot?.sessionKey,r=this.mutationRequestId+1;this.mutationRequestId=r,this.mutationPending=!0,this.actionError=``;try{await this.callbacks.applyOps(e),r===this.mutationRequestId&&n===this.snapshot?.sessionKey&&this.announce(t)}catch(e){throw r===this.mutationRequestId&&n===this.snapshot?.sessionKey&&(this.actionError=x(`board.actionFailed`),this.announce(this.actionError)),e}finally{r===this.mutationRequestId&&(this.mutationPending=!1)}}nextPosition(e){let t=this.snapshot?.widgets.filter(t=>t.tabId===e).map(e=>e.position)??[0];return Math.max(-1,...t)+1}beginGesture(e,t,n){if(!this.active||!this.canMutate||n.button!==0||this.gesture||this.mutationPending)return;let r=this.snapshot,i=r?X(r):[],a=this.activeTab(i);if(!r||!a)return;n.preventDefault(),n.stopPropagation();try{n.currentTarget?.setPointerCapture?.(n.pointerId)}catch{}let o=Q(Z(r,a.tabId),this.contentHeights);this.gesture={dropValid:!1,mode:e,name:t.name,originClientX:n.clientX,originClientY:n.clientY,originW:t.sizeW,originH:k(t,this.contentHeights.get(t.name),D()),pointerId:n.pointerId,items:o},this.previewItems=o,this.gestureName=t.name,window.addEventListener(`pointermove`,this.handlePointerMove),window.addEventListener(`pointerup`,this.handlePointerUp),window.addEventListener(`pointercancel`,this.handlePointerCancel)}cancelGesture(){window.removeEventListener(`pointermove`,this.handlePointerMove),window.removeEventListener(`pointerup`,this.handlePointerUp),window.removeEventListener(`pointercancel`,this.handlePointerCancel),this.gesture=null,this.previewItems=null,this.gestureName=``,this.hoverTabId=``}async nudgeWidget(e,t){let n=this.snapshot;if(!n)return;let r=Ve(Q(Z(n,e.tabId),this.contentHeights),e.name,t).find(t=>t.name===e.name);!r||r.order===e.position||await this.applyOps([{kind:`widget_move`,name:e.name,position:r.order}],x(`board.announcement.moved`,{title:e.title||e.name}))}focusWidget(e,t){let n=this.snapshot;if(!n)return;let r=Z(n,e.tabId),i=r.findIndex(t=>t.name===e.name);if(i<0)return;let a=r[Math.max(0,Math.min(i+(t===`left`||t===`up`?-1:1),r.length-1))];!a||a.name===e.name||(this.focusName=a.name,this.updateComplete.then(()=>{[...this.querySelectorAll(`openclaw-board-widget-cell`)].find(e=>e.widget?.name===a.name)?.querySelector(`.board-widget`)?.focus()}))}renderGrid(e,t,n){if(e.length===0)return g`
<div class="board-empty" data-test-id="board-empty">
<span class="board-empty__mark" aria-hidden="true">+</span>
<strong>${x(`board.emptyTitle`)}</strong>
<span>${x(`board.emptyHint`)}</span>
</div>
`;let r=T(this.previewItems??Q(e,this.contentHeights,this.fitAutoContent),this.fitAutoContent?240:void 0);for(let e of r)this.stableCellOrder.has(e.name)||(this.stableCellOrder.set(e.name,this.stableCellOrderSequence),this.stableCellOrderSequence+=1);let i=r.toSorted((e,t)=>(this.stableCellOrder.get(e.name)??0)-(this.stableCellOrder.get(t.name)??0)||e.name.localeCompare(t.name)),a=new Map(r.map((e,t)=>[e.name,t])),o=r.some(e=>e.name===this.focusName)?this.focusName:r[0]?.name??``,s=new Map(e.map(e=>[e.name,e]));return g`
<div class="board-grid" role="list" aria-label=${x(`board.gridLabel`)}>
${se(i,e=>`${n}\u0000${e.name}`,e=>{let i=s.get(e.name);return i?g`
<openclaw-board-widget-cell
.widget=${i}
.rect=${e}
.contentHeightPx=${this.contentHeights.get(i.name)}
.fitAutoContent=${this.fitAutoContent}
.tabs=${t}
.session=${this.session}
.sessionKey=${n}
.widgetFrameUrl=${this.widgetFrameUrl}
.callbacks=${this.cellCallbacks}
.active=${this.active}
.bridgeEnabled=${this.bridgeEnabled}
.dragging=${i.name===this.gestureName}
.focusTabIndex=${i.name===o?0:-1}
.positionInSet=${(a.get(i.name)??0)+1}
.setSize=${r.length}
.busy=${this.mutationPending}
.canMutate=${this.canMutate}
.canGrant=${this.canGrant}
></openclaw-board-widget-cell>
`:v})}
${this.gesture?.mode===`move`?g`<div class="board-grid__append-zone" aria-hidden="true"></div>`:v}
</div>
`}render(){let e=this.snapshot;if(!e)return v;let t=X(e),n=this.activeTab(t),r=n?.tabId??this.activeTabId,i=n?Z(e,n.tabId):[];return g`
<section class="board-view" aria-label=${x(`board.label`)}>
${Ye({tabs:t,activeTabId:r,hoverTabId:this.hoverTabId,onTabShow:this.handleTabShow,onOverflowSelect:this.handleOverflowSelect})}
${this.renderGrid(i,t,e.sessionKey)}
${this.actionError?g`<div class="board-view__error" role="alert">${this.actionError}</div>`:v}
<div class="board-announcer" aria-live="polite" aria-atomic="true">
${this.announcement?le(this.announcementRevision,g`<span data-announcement-revision=${this.announcementRevision}
>${this.announcement}</span
>`):v}
</div>
</section>
`}},a([y({attribute:!1})],$.prototype,`session`,void 0),a([y({attribute:!1})],$.prototype,`snapshot`,void 0),a([y({attribute:!1})],$.prototype,`activeTabId`,void 0),a([y({attribute:!1})],$.prototype,`widgetFrameUrl`,void 0),a([y({attribute:!1})],$.prototype,`callbacks`,void 0),a([y({type:Boolean})],$.prototype,`active`,void 0),a([y({type:Boolean})],$.prototype,`bridgeEnabled`,void 0),a([y({type:Boolean})],$.prototype,`canMutate`,void 0),a([y({type:Boolean})],$.prototype,`canGrant`,void 0),a([y({type:Boolean})],$.prototype,`fitAutoContent`,void 0),a([_()],$.prototype,`previewItems`,void 0),a([_()],$.prototype,`gestureName`,void 0),a([_()],$.prototype,`hoverTabId`,void 0),a([_()],$.prototype,`announcement`,void 0),a([_()],$.prototype,`announcementRevision`,void 0),a([_()],$.prototype,`actionError`,void 0),a([_()],$.prototype,`focusName`,void 0),a([_()],$.prototype,`mutationPending`,void 0),customElements.get(`openclaw-board-view`)||customElements.define(`openclaw-board-view`,$)})))()}export{Y as n,Ke as r,Lt as t};
//# sourceMappingURL=board-view-MrEmUNnS.js.map