openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
17 lines • 5.01 kB
JavaScript
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{ca as s,sa as c}from"./control-ui-core-DtLivg_r.js";import{G as l,J as u,W as d,Z as f,at as p,rt as m}from"./lit-runtime-IOnANfcZ.js";import{Zr as h}from"./ui-CmSP4d14.js";import{F as g,M as _,N as v,j as y}from"./control-ui-boot-shared-VLPz5vN2.js";import{B as b,L as x,R as S}from"./control-ui-boot-chat-XPUNenUd.js";import{H as C,U as w}from"./control-ui-boot-chat-CmENwCKi.js";import{n as T,t as E}from"./panel-empty-state-Cvj4wChf.js";function D(e){let t=e?URL.parse(e):null;return t&&(t.protocol===`https:`||t.protocol===`http:`)?t.href:null}function O(e){let t=D(e);if(!t)return null;let n=new URL(t);if(n.origin===window.location.origin)return null;if(n.searchParams.get(`openclawHostTheme`)!==`1`||!/^\/embed\/(?:channel|thread)\/[^/]+\/[^/]+\/?$/u.test(n.pathname))return n.href;n.searchParams.set(`theme`,document.documentElement.dataset.themeMode===`light`?`light`:`dark`),n.searchParams.set(`hostOrigin`,window.location.origin);let r=x().tokens;return Object.keys(r).length>0&&n.searchParams.set(`themeTokens`,JSON.stringify(r)),n.href}var k;function A(){return(A=e((()=>{y(),d(),f(),s(),E(),C(),n(),i(),S(),t(),k=class extends r{constructor(...e){super(...e),this.sessionKey=``,this.loadInfo=null,this.openDiscussion=null,this.onStateChange=null,this.canOpen=!0,this.sourceGeneration=0,this.isOpeningDiscussionCurrent=null,this.themeObserver=null,this.discussionTask=new _(this,{args:()=>[this.sessionKey.trim(),this.loadInfo,this.openDiscussion,this.sourceGeneration,this.canOpen],task:async([e,t,n,r,i],{signal:a})=>{if(!t||!e)return null;let o=await t(e);a.throwIfAborted();let s=()=>e===this.sessionKey.trim()&&t===this.loadInfo&&n===this.openDiscussion&&r===this.sourceGeneration&&i===this.canOpen;if(!s())return v;let c=o;if(o.state===`available`&&i&&n){if(this.isOpeningDiscussionCurrent=s,this.publish(e,o),!s())return v;c=await n(e)??o}return a.throwIfAborted(),s()?{sessionKey:e,info:c}:v},onComplete:e=>{this.isOpeningDiscussionCurrent=null,e&&this.publish(e.sessionKey,e.info)},onError:()=>{this.isOpeningDiscussionCurrent=null}}),this.handleDiscussionFrameLoad=e=>{let t=e.currentTarget;t instanceof HTMLIFrameElement&&this.postDiscussionTheme(t)}}connectedCallback(){super.connectedCallback(),typeof MutationObserver<`u`&&(this.themeObserver=new MutationObserver(()=>this.postDiscussionTheme()),this.themeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`,`data-theme-mode`,`style`]}))}disconnectedCallback(){this.themeObserver?.disconnect(),this.themeObserver=null,super.disconnectedCallback()}postDiscussionTheme(e=this.querySelector(`.session-discussion__frame`)){e?.isConnected&&b(e,new URL(e.src).origin)}publish(e,t){e===this.sessionKey.trim()&&this.onStateChange?.(e,t.state,D(t.openUrl))}renderOpen(e){let t=O(e.embedUrl),n=D(e.openUrl);return u`
<div class="session-discussion__open">
${t?u`
<iframe
class="session-discussion__frame"
src=${t}
title=${o(`chat.sessionDiscussion.frameTitle`)}
sandbox="allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"
=${this.handleDiscussionFrameLoad}
></iframe>
`:T({icon:c.messageSquare,heading:o(`chat.sidePanel.discussion`),description:o(`chat.sessionDiscussion.unavailable`),action:n?u`<a class="session-link" href=${n} target="_blank" rel="noopener">
${o(`chat.sessionDiscussion.openExternal`)}
</a>`:l})}
</div>
`}render(){if(this.discussionTask.status===g.ERROR){let e=this.discussionTask.error;return u`<div class="session-discussion__empty">
<div class="callout danger">${a(e)}</div>
</div>`}let e=this.discussionTask.value,t=!!(this.loadInfo&&this.sessionKey.trim())&&this.discussionTask.status===g.PENDING;if(t&&this.isOpeningDiscussionCurrent?.())return w(`discussion`,o(`chat.sessionDiscussion.opening`));if(t)return w(`discussion`,o(`chat.sessionDiscussion.loading`));if(this.discussionTask.status!==g.COMPLETE||!e)return l;let{info:n}=e;return n.state===`none`?l:n.state===`available`?T({icon:c.messageSquare,heading:o(`chat.sidePanel.discussion`),description:o(this.canOpen?`chat.sessionDiscussion.unavailable`:`chat.sessionDiscussion.requiresWriteAccess`)}):this.renderOpen(n)}},h([p()],k.prototype,`sessionKey`,void 0),h([p({attribute:!1})],k.prototype,`loadInfo`,void 0),h([p({attribute:!1})],k.prototype,`openDiscussion`,void 0),h([p({attribute:!1})],k.prototype,`onStateChange`,void 0),h([p({type:Boolean})],k.prototype,`canOpen`,void 0),h([p({type:Number})],k.prototype,`sourceGeneration`,void 0),h([m()],k.prototype,`isOpeningDiscussionCurrent`,void 0),customElements.get(`openclaw-session-discussion`)||customElements.define(`openclaw-session-discussion`,k)})))()}A();