openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
18 lines • 5.07 kB
JavaScript
import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{Kn as t,R as n,wr as r,z as i}from"./control-ui-foundation-Cydpkyqa.js";import{Sc as a,bc as o}from"./control-ui-core-Rwzhj6nO.js";import{$ as s,K as c,X as l,at as u,q as d,st as f}from"./lit-runtime-CV_MH99K.js";import{_ as p,g as m}from"./control-ui-core-YphAl4aM.js";import{Yt as h,en as g}from"./control-ui-core-vvcQQV2m.js";import{Ar as _,Br as v,Fr as y,Lr as b,Mr as x,Nr as S,Pr as C,Rr as w,jr as T,zr as E}from"./control-ui-boot-shared-DfZ39Yj9.js";import{g as D,h as O,m as k}from"./control-ui-boot-chat-Bia0O-uD.js";import"./control-ui-boot-chat-BhPddYSI.js";import"./approval-Dpr9VMH2.js";var A;function j(){return(j=e((()=>{i(),c(),s(),p(),E(),C(),h(),a(),O(),A=class extends o{constructor(...e){super(...e),this.questionId=``,this.loading=!0,this.requestError=null,this.questionState=T(()=>this.requestUpdate()),this.client=null,this.operationGeneration=0}connectedCallback(){super.connectedCallback(),this.boundQuestionId=this.questionId,this.stopGateway=this.context.gateway.subscribe(e=>this.applyGatewaySnapshot(e)),this.stopGatewayEvents=this.context.gateway.subscribeEvents(e=>{t(e.payload)&&e.payload.id===this.questionId&&S(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,x(this.questionState),super.disconnectedCallback()}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))}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,b(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 n=this.questionId,r=++this.operationGeneration;this.loading=!0,this.requestError=null;try{let i=await v(e,`question.get`,{id:n});if(this.client!==e||this.operationGeneration!==r||this.questionId!==n)return;if(!t(i)||!t(i.question)||i.question.id!==n){this.requestError=`unavailable`;return}let a=i.question;if(a.id!==n||a.status!==`pending`&&a.status!==`answered`&&a.status!==`cancelled`&&a.status!==`expired`||!S(this.questionState,{event:`question.requested`,payload:{...a,status:`pending`}})){this.requestError=`unavailable`;return}a.status===`answered`?S(this.questionState,{event:`question.resolved`,payload:{id:n,status:`answered`,answers:a.answers}})||(this.requestError=`unavailable`):(a.status===`cancelled`||a.status===`expired`)&&S(this.questionState,{event:`question.resolved`,payload:{id:n,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 l`
<div class="approval-page__state" data-question-status=${e.status}>
<h1>${this.questionStatusLabel(e)}</h1>
${D(e)}
</div>
`;let t=k(e,{onChange:()=>this.requestUpdate(),onSubmit:t=>w(this.questionState,e.id,t),onSkip:()=>_(this.questionState,e.id)});return l`<openclaw-chat-question-panel .props=${t}></openclaw-chat-question-panel>`}questionStatusLabel(e){return e.status===`answered`?g(`chat.questions.answered`):e.status===`cancelled`?g(`chat.questions.skipped`):e.status===`expired`?g(`chat.questions.expired`):g(`chat.questions.unavailable`)}render(){let e=y(this.questionState).find(e=>e.id===this.questionId),t=this.loading?l`<div class="approval-page__state" role="status">${g(`common.loading`)}</div>`:this.requestError?l`<div class="approval-page__state" role="status">
${this.requestError===`connection`?g(`chat.questions.disconnected`):g(`chat.questions.unavailable`)}
</div>`:e?this.renderQuestion(e):d;return l`
<main
class="approval-page question-page"
data-state=${e?.status??this.requestError??`loading`}
>
<div class="approval-page__card approval-page__card--severity-info">
<div class="approval-page__content">${t}</div>
</div>
</main>
`}},r([n({context:m,subscribe:!1})],A.prototype,`context`,void 0),r([f({attribute:`question-id`})],A.prototype,`questionId`,void 0),r([u()],A.prototype,`loading`,void 0),r([u()],A.prototype,`requestError`,void 0)})))()}function M(){return(M=e((()=>{j(),customElements.get(`openclaw-question-page`)||customElements.define(`openclaw-question-page`,A)})))()}M();
//# sourceMappingURL=question-page-registration-D8fm_YUt.js.map