UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

24 lines • 6.4 kB
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{Br as t,Ji as n,qr as r,zr as i}from"./control-ui-foundation-ZY_Flbbd.js";import{hu as a,lu as o,su as s,uu as c}from"./control-ui-core-3P365fbR.js";import{vi as l,yi as u}from"./control-ui-core-CFW9Qtjn.js";import{$ as d,X as f,Y as p,ct as m,nt as h,ut as g}from"./lit-runtime-P5vbNq6b.js";import{$o as _,Go as v,Jo as y,Ko as b,Qo as x,Xo as S,Yo as C,es as w,qo as T,ts as E}from"./control-ui-boot-shared-CG9HtEG-.js";import{Jn as D,Xn as O,Yn as k}from"./control-ui-boot-shared-CcmBeh0v.js";import"./css-question-Ct0OXZAc.js";import"./approval-BhCMRUNv.js";var A;function j(){return(j=e((()=>{t(),p(),h(),u(),w(),C(),c(),o(),k(),A=class extends s{constructor(...e){super(...e),this.questionId=``,this.loading=!0,this.requestError=null,this.questionState=b(()=>this.requestUpdate()),this.client=null,this.operationGeneration=0,this.questionPanelHadFocus=!1}connectedCallback(){super.connectedCallback(),this.previousDocumentTitle=document.title,this.boundQuestionId=this.questionId,this.stopGateway=this.context.gateway.subscribe(e=>this.applyGatewaySnapshot(e)),this.stopGatewayEvents=this.context.gateway.subscribeEvents(e=>{n(e.payload)&&e.payload.id===this.questionId&&y(this.questionState,e)}),this.applyGatewaySnapshot(this.context.gateway.snapshot)}disconnectedCallback(){this.stopGateway?.(),this.stopGateway=void 0,this.stopGatewayEvents?.(),this.stopGatewayEvents=void 0,this.operationGeneration+=1,this.client=null,T(this.questionState),this.previousDocumentTitle!==void 0&&(!this.activeDocumentTitle||document.title===this.activeDocumentTitle)&&(document.title=this.previousDocumentTitle),this.previousDocumentTitle=void 0,this.activeDocumentTitle=void 0,super.disconnectedCallback()}willUpdate(){let e=this.querySelector(`openclaw-chat-question-panel`);this.questionPanelHadFocus=e!==null&&(e.contains(document.activeElement)||this.questionPanelHadFocus&&document.activeElement===document.body)}updated(e){e.has(`questionId`)&&this.boundQuestionId!==this.questionId&&(this.boundQuestionId=this.questionId,this.operationGeneration+=1,this.requestError=this.questionId?null:`unavailable`,this.loading=!!this.questionId,this.questionId&&this.client&&this.loadQuestion(this.client));let t=S(this.questionState).find(e=>e.id===this.questionId),n=`${this.pageTitle(t)} — ${a(`approvalPage.brandName`)}`;document.title=n,this.activeDocumentTitle=n,this.questionPanelHadFocus&&!this.querySelector(`openclaw-chat-question-panel`)&&this.querySelector(`#question-page-title`)?.focus({preventScroll:!0})}applyGatewaySnapshot(e){let t=e.phase===`connected`?e.client:null;if(this.client===t){!t&&(e.lastError||e.phase===`offline`||e.phase===`reload-required`||e.phase===`stopped`)&&(this.loading=!1,this.requestError=`connection`);return}if(this.operationGeneration+=1,this.client=t,x(this.questionState,t),!t){S(this.questionState).some(e=>e.id===this.questionId)&&(this.loading=!1,this.requestError=`connection`);return}if(!this.questionId){this.loading=!1,this.requestError=`unavailable`;return}this.loadQuestion(t)}async loadQuestion(e){let t=this.questionId,r=++this.operationGeneration;this.loading=!0,this.requestError=null;try{let i=await E(e,`question.get`,{id:t});if(this.client!==e||this.operationGeneration!==r||this.questionId!==t)return;if(!n(i)||!n(i.question)||i.question.id!==t){this.requestError=`unavailable`;return}let a=i.question;if(a.status!==`pending`&&a.status!==`answered`&&a.status!==`cancelled`&&a.status!==`expired`||!y(this.questionState,{event:`question.requested`,payload:{...a,status:`pending`}})){this.requestError=`unavailable`;return}a.status===`answered`?y(this.questionState,{event:`question.resolved`,payload:{id:t,status:`answered`,answers:a.answers}})||(this.requestError=`unavailable`):(a.status===`cancelled`||a.status===`expired`)&&y(this.questionState,{event:`question.resolved`,payload:{id:t,status:a.status}})}catch{this.client===e&&this.operationGeneration===r&&(this.requestError=`unavailable`)}finally{this.client===e&&this.operationGeneration===r&&(this.loading=!1)}}renderQuestion(e){if(e.status!==`pending`)return d` <div class="approval-page__state" data-question-status=${e.status} role="status"> <h1 id="question-page-title" tabindex="-1">${this.questionStatusLabel(e)}</h1> ${O(e)} </div> `;let t=D(e,{onChange:()=>this.requestUpdate(),onSubmit:t=>_(this.questionState,e.id,t),onSkip:()=>v(this.questionState,e.id)});return d`<openclaw-chat-question-panel .props=${t}></openclaw-chat-question-panel>`}questionStatusLabel(e){return e.status===`answered`?a(`chat.questions.answered`):e.status===`cancelled`?a(`chat.questions.skipped`):e.status===`expired`?a(`chat.questions.expired`):a(`chat.questions.unavailable`)}pageTitle(e){return this.loading?a(`common.loading`):this.requestError?a(this.requestError===`connection`?`chat.questions.disconnected`:`chat.questions.unavailable`):e&&e.status!==`pending`?this.questionStatusLabel(e):a(`chat.questions.eyebrow`)}render(){let e=S(this.questionState).find(e=>e.id===this.questionId),t=this.loading?d`<div class="approval-page__state" role="status">${a(`common.loading`)}</div>`:this.requestError?d`<div class="approval-page__state" role="status"> ${this.requestError===`connection`?a(`chat.questions.disconnected`):a(`chat.questions.unavailable`)} </div>`:e?this.renderQuestion(e):f;return d` <main class="approval-page question-page" aria-labelledby="question-page-title" aria-busy=${this.loading?`true`:`false`} data-state=${e?.status??this.requestError??`loading`} > <div class="approval-page__card approval-page__card--severity-info"> <div class="approval-page__content"> ${this.loading||this.requestError||!e||e.status===`pending`?d`<h1 id="question-page-title" class="sr-only" tabindex="-1"> ${this.pageTitle(e)} </h1>`:f} ${t} </div> </div> </main> `}},r([i({context:l,subscribe:!1})],A.prototype,`context`,void 0),r([g({attribute:`question-id`})],A.prototype,`questionId`,void 0),r([m()],A.prototype,`loading`,void 0),r([m()],A.prototype,`requestError`,void 0)})))()}function M(){return(M=e((()=>{j(),customElements.get(`openclaw-question-page`)||customElements.define(`openclaw-question-page`,A)})))()}M();