UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

18 lines 5.35 kB
import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{wr as t}from"./control-ui-foundation-Cydpkyqa.js";import{Eo as n,Oo as r,Sc as i,bc as a}from"./control-ui-core-Rwzhj6nO.js";import{$ as o,K as s,X as c,at as l,q as u,st as d}from"./lit-runtime-CV_MH99K.js";import{Gt as f,Wt as p,Yt as m,en as h}from"./control-ui-core-vvcQQV2m.js";import{B as g,U as _,V as v,z as y}from"./control-ui-boot-shared-BYq7Cchl.js";import{cn as b,ln as x,sn as S,un as C}from"./control-ui-boot-chat-_QSl8fbH.js";import{i as w,n as T,t as E}from"./control-ui-boot-chat-CazDfK3O.js";function D(e){if(!e?.trim())return null;try{let t=new URL(e);return t.protocol===`https:`||t.protocol===`http:`?t.href:null}catch{return 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=E().tokens;return Object.keys(r).length>0&&n.searchParams.set(`themeTokens`,JSON.stringify(r)),n.href}var k;function A(){return(A=e((()=>{y(),s(),o(),f(),x(),S(),m(),r(),T(),i(),k=class extends a{constructor(...e){super(...e),this.sessionKey=``,this.loadInfo=null,this.openDiscussion=null,this.onStateChange=null,this.canOpen=!0,this.sourceGeneration=0,this.openingDiscussion=null,this.themeObserver=null,this.discussionTask=new g(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={sessionKey:e,loader:t,opener:n,sourceGeneration:r,canOpen:i};if(!this.isOpeningCurrent(s))return v;let c=o;if(o.state===`available`&&i&&n){if(this.openingDiscussion=s,this.publish(e,o),!this.isOpeningCurrent(s))return v;c=await n(e)??o}return a.throwIfAborted(),this.isOpeningCurrent(s)?{sessionKey:e,info:c}:v},onComplete:e=>{this.openingDiscussion=null,e&&this.publish(e.sessionKey,e.info)},onError:()=>{this.openingDiscussion=null}}),this.handleDiscussionFrameLoad=e=>{let t=e.currentTarget;t instanceof HTMLIFrameElement&&this.postDiscussionTheme(t)}}isOpeningCurrent(e){return e.sessionKey===this.sessionKey.trim()&&e.loader===this.loadInfo&&e.opener===this.openDiscussion&&e.sourceGeneration===this.sourceGeneration&&e.canOpen===this.canOpen}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&&w(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 c` <div class="session-discussion__open"> ${t?c` <iframe class="session-discussion__frame" src=${t} title=${h(`chat.sessionDiscussion.frameTitle`)} sandbox="allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts" @load=${this.handleDiscussionFrameLoad} ></iframe> `:C({icon:p.messageSquare,heading:h(`chat.sidePanel.discussion`),description:h(`chat.sessionDiscussion.unavailable`),action:n?c`<a class="session-link" href=${n} target="_blank" rel="noopener"> ${h(`chat.sessionDiscussion.openExternal`)} </a>`:u})} </div> `}render(){if(this.discussionTask.status===_.ERROR){let e=this.discussionTask.error;return c`<div class="session-discussion__empty"> <div class="callout danger">${n(e)}</div> </div>`}let e=this.discussionTask.value,t=!!(this.loadInfo&&this.sessionKey.trim())&&this.discussionTask.status===_.PENDING;if(t&&this.openingDiscussion&&this.isOpeningCurrent(this.openingDiscussion))return b(`discussion`,h(`chat.sessionDiscussion.opening`));if(t)return b(`discussion`,h(`chat.sessionDiscussion.loading`));if(this.discussionTask.status!==_.COMPLETE||!e)return u;let{info:r}=e;return r.state===`none`?u:r.state===`available`?this.canOpen?C({icon:p.messageSquare,heading:h(`chat.sidePanel.discussion`),description:h(`chat.sessionDiscussion.unavailable`)}):C({icon:p.messageSquare,heading:h(`chat.sidePanel.discussion`),description:h(`chat.sessionDiscussion.requiresWriteAccess`)}):this.renderOpen(r)}},t([d()],k.prototype,`sessionKey`,void 0),t([d({attribute:!1})],k.prototype,`loadInfo`,void 0),t([d({attribute:!1})],k.prototype,`openDiscussion`,void 0),t([d({attribute:!1})],k.prototype,`onStateChange`,void 0),t([d({type:Boolean})],k.prototype,`canOpen`,void 0),t([d({type:Number})],k.prototype,`sourceGeneration`,void 0),t([l()],k.prototype,`openingDiscussion`,void 0),customElements.get(`openclaw-session-discussion`)||customElements.define(`openclaw-session-discussion`,k)})))()}A(); //# sourceMappingURL=session-discussion-panel-D4Q_eWbX.js.map