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{Nu as t,Pu as n,ju as r,zu as i}from"./control-ui-core-CBJ5efDh.js";import{Ai as a,ki as o}from"./control-ui-core-DtLivg_r.js";import{G as s,J as c,W as l,Z as u,at as d,rt as f}from"./lit-runtime-IOnANfcZ.js";import{Ur as p,Wr as m,Zr as h,wa as g}from"./ui-CmSP4d14.js";import{Aa as _,Ca as v,Da as y,Ea as b,Ma as x,Sa as S,Ta as C,ja as w,ka as T,wa as E}from"./control-ui-boot-shared-XreXSF7h.js";import{er as D,nr as O,tr as k}from"./control-ui-boot-chat-B-b-JQel.js";import"./control-ui-boot-chat-styles-BcslGtWC.js";import"./approval-t2xr4qDL.js";var A;function j(){return(j=e((()=>{m(),l(),u(),a(),w(),b(),n(),t(),k(),A=class extends r{constructor(...e){super(...e),this.questionId=``,this.loading=!0,this.requestError=null,this.questionState=v(()=>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=>{g(e.payload)&&e.payload.id===this.questionId&&C(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,E(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=y(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,T(this.questionState,t),!t){y(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 x(e,`question.get`,{id:t});if(this.client!==e||this.operationGeneration!==n||this.questionId!==t)return;if(!g(r)||!g(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`||!C(this.questionState,{event:`question.requested`,payload:{...i,status:`pending`}})){this.requestError=`unavailable`;return}i.status===`answered`?C(this.questionState,{event:`question.resolved`,payload:{id:t,status:`answered`,answers:i.answers}})||(this.requestError=`unavailable`):(i.status===`cancelled`||i.status===`expired`)&&C(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 c` <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:()=>S(this.questionState,e.id)});return c`<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=y(this.questionState).find(e=>e.id===this.questionId),t=this.loading||this.requestError?c`<div class="approval-page__state" role="status">${this.pageTitle(e)}</div>`:e?this.renderQuestion(e):s;return c` <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`?c`<h1 id="question-page-title" class="sr-only" tabindex="-1"> ${this.pageTitle(e)} </h1>`:s} ${t} </div> </div> </main> `}},h([p({context:o,subscribe:!1})],A.prototype,`context`,void 0),h([d({attribute:`question-id`})],A.prototype,`questionId`,void 0),h([f()],A.prototype,`loading`,void 0),h([f()],A.prototype,`requestError`,void 0)})))()}function M(){return(M=e((()=>{j(),customElements.get(`openclaw-question-page`)||customElements.define(`openclaw-question-page`,A)})))()}M();