UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

22 lines • 6.22 kB
import{n as e}from"./rolldown-runtime-8BhlS34s.js";import{Cu as t,Eu as n,Tu as r,ju as i}from"./control-ui-core-BncvAZjR.js";import{Ti as a,wi as o}from"./control-ui-core-9qYjK5B2.js";import{$ as s,X as c,Y as l,ct as u,nt as d,ut as f}from"./lit-runtime-B8uOr6OX.js";import{Xr as p,Zr as m,_a as h,ii as g}from"./ui-DuRgK6kL.js";import{ca as _,da as v,ga as y,ha as b,la as x,ma as S,oa as C,pa as w,sa as T,ua as E}from"./control-ui-boot-shared-xfDhIVun.js";import{Qn as D,Xn as O,Zn as k}from"./control-ui-boot-chat-XcDaYmck.js";import"./control-ui-boot-chat-styles-BRrYkFSc.js";import"./approval-BhCMRUNv.js";var A;function j(){return(j=e((()=>{m(),l(),d(),a(),b(),E(),n(),r(),k(),A=class extends t{constructor(...e){super(...e),this.questionId=``,this.loading=!0,this.requestError=null,this.questionState=T(()=>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=>{h(e.payload)&&e.payload.id===this.questionId&&x(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,_(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-card`);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=v(this.questionState).find(e=>e.id===this.questionId),n=`${this.pageTitle(t)} — ${i(`approvalPage.brandName`)}`;document.title=n,this.activeDocumentTitle=n,this.questionPanelHadFocus&&!this.querySelector(`openclaw-chat-question-card`)&&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,w(this.questionState,t),!t){v(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,n=++this.operationGeneration;this.loading=!0,this.requestError=null;try{let r=await y(e,`question.get`,{id:t});if(this.client!==e||this.operationGeneration!==n||this.questionId!==t)return;if(!h(r)||!h(r.question)||r.question.id!==t){this.requestError=`unavailable`;return}let i=r.question;if(i.status!==`pending`&&i.status!==`answered`&&i.status!==`cancelled`&&i.status!==`expired`||!x(this.questionState,{event:`question.requested`,payload:{...i,status:`pending`}})){this.requestError=`unavailable`;return}i.status===`answered`?x(this.questionState,{event:`question.resolved`,payload:{id:t,status:`answered`,answers:i.answers}})||(this.requestError=`unavailable`):(i.status===`cancelled`||i.status===`expired`)&&x(this.questionState,{event:`question.resolved`,payload:{id:t,status:i.status}})}catch{this.client===e&&this.operationGeneration===n&&(this.requestError=`unavailable`)}finally{this.client===e&&this.operationGeneration===n&&(this.loading=!1)}}renderQuestion(e){if(e.status!==`pending`)return s` <div class="approval-page__state" data-question-status=${e.status} role="status"> <h1 id="question-page-title" tabindex="-1">${this.questionStatusLabel(e)}</h1> ${D(e)} </div> `;let t=O(e,{onChange:()=>this.requestUpdate(),onSubmit:t=>S(this.questionState,e.id,t),onSkip:()=>C(this.questionState,e.id)});return s`<openclaw-chat-question-card .props=${t}></openclaw-chat-question-card>`}questionStatusLabel(e){return i({answered:`chat.questions.answered`,cancelled:`chat.questions.skipped`,expired:`chat.questions.expired`,pending:`chat.questions.unavailable`,unavailable:`chat.questions.unavailable`}[e.status])}pageTitle(e){return this.loading?i(`common.loading`):this.requestError?i(this.requestError===`connection`?`chat.questions.disconnected`:`chat.questions.unavailable`):e&&e.status!==`pending`?this.questionStatusLabel(e):i(`chat.questions.eyebrow`)}render(){let e=v(this.questionState).find(e=>e.id===this.questionId),t=this.loading||this.requestError?s`<div class="approval-page__state" role="status">${this.pageTitle(e)}</div>`:e?this.renderQuestion(e):c;return s` <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`?s`<h1 id="question-page-title" class="sr-only" tabindex="-1"> ${this.pageTitle(e)} </h1>`:c} ${t} </div> </div> </main> `}},g([p({context:o,subscribe:!1})],A.prototype,`context`,void 0),g([f({attribute:`question-id`})],A.prototype,`questionId`,void 0),g([u()],A.prototype,`loading`,void 0),g([u()],A.prototype,`requestError`,void 0)})))()}function M(){return(M=e((()=>{j(),customElements.get(`openclaw-question-page`)||customElements.define(`openclaw-question-page`,A)})))()}M();