UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

17 lines • 5.26 kB
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{qr as t}from"./control-ui-foundation-ZY_Flbbd.js";import{Gl as n,hu as r,lu as i,ql as a,su as o,uu as s}from"./control-ui-core-3P365fbR.js";import{Xi as c,Zi as l}from"./control-ui-core-CFW9Qtjn.js";import{$ as u,X as d,Y as f,ct as p,nt as m,ut as h}from"./lit-runtime-P5vbNq6b.js";import{Jn as g,Yn as _,Zn as v}from"./control-ui-boot-shared-DoKu-5Ju.js";import{L as y,R as b,V as x,z as S}from"./control-ui-boot-shared-DBJri5ri.js";import{nn as C,rn as w}from"./control-ui-boot-shared-CG9HtEG-.js";import{n as T,t as E}from"./panel-empty-state-BO6bnLg_.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=g().tokens;return Object.keys(r).length>0&&n.searchParams.set(`themeTokens`,JSON.stringify(r)),n.href}var k;function A(){return(A=e((()=>{y(),f(),m(),l(),E(),C(),s(),a(),_(),i(),k=class extends o{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 b(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 S;let c=o;if(o.state===`available`&&i&&n){if(this.openingDiscussion=s,this.publish(e,o),!this.isOpeningCurrent(s))return S;c=await n(e)??o}return a.throwIfAborted(),this.isOpeningCurrent(s)?{sessionKey:e,info:c}:S},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&&v(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=${r(`chat.sessionDiscussion.frameTitle`)} sandbox="allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts" @load=${this.handleDiscussionFrameLoad} ></iframe> `:T({icon:c.messageSquare,heading:r(`chat.sidePanel.discussion`),description:r(`chat.sessionDiscussion.unavailable`),action:n?u`<a class="session-link" href=${n} target="_blank" rel="noopener"> ${r(`chat.sessionDiscussion.openExternal`)} </a>`:d})} </div> `}render(){if(this.discussionTask.status===x.ERROR){let e=this.discussionTask.error;return u`<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===x.PENDING;if(t&&this.openingDiscussion&&this.isOpeningCurrent(this.openingDiscussion))return w(`discussion`,r(`chat.sessionDiscussion.opening`));if(t)return w(`discussion`,r(`chat.sessionDiscussion.loading`));if(this.discussionTask.status!==x.COMPLETE||!e)return d;let{info:i}=e;return i.state===`none`?d:i.state===`available`?T({icon:c.messageSquare,heading:r(`chat.sidePanel.discussion`),description:r(this.canOpen?`chat.sessionDiscussion.unavailable`:`chat.sessionDiscussion.requiresWriteAccess`)}):this.renderOpen(i)}},t([h()],k.prototype,`sessionKey`,void 0),t([h({attribute:!1})],k.prototype,`loadInfo`,void 0),t([h({attribute:!1})],k.prototype,`openDiscussion`,void 0),t([h({attribute:!1})],k.prototype,`onStateChange`,void 0),t([h({type:Boolean})],k.prototype,`canOpen`,void 0),t([h({type:Number})],k.prototype,`sourceGeneration`,void 0),t([p()],k.prototype,`openingDiscussion`,void 0),customElements.get(`openclaw-session-discussion`)||customElements.define(`openclaw-session-discussion`,k)})))()}A();