openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 55.5 kB
JavaScript
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{$c as t,$s as n,Aa as r,Ho as i,It as a,Lt as o,Pi as s,Pt as c,Qc as l,Qs as u,Qt as d,Rt as f,Vo as p,Wl as m,Xt as h,Zt as g,au as _,et as v,eu as y,nc as ee,ss as b,tt as x,vi as S,wa as C,xa as w,zs as T}from"./control-ui-connection-Bfj9beF_.js";import{$O as E,A_ as te,Ay as ne,BA as D,Bs as re,Fs as ie,Ib as O,J_ as ae,K_ as oe,LO as se,Lb as ce,Ls as k,MD as le,NO as ue,N_ as de,Nj as fe,Ns as pe,QA as me,RO as he,Rs as ge,XO as _e,ZA as ve,_j as A,af as ye,aw as be,cf as xe,cj as Se,cl as Ce,dj as j,dk as we,ej as Te,fc as Ee,hj as De,if as Oe,iw as ke,jy as Ae,kD as je,mj as M,nk as Me,of as Ne,pj as Pe,rw as Fe,sf as Ie,sj as Le,sl as Re,tj as ze,uk as Be,wj as Ve,zA as N,zO as He,zs as Ue}from"./control-ui-boot-shared-DFTSUQQ0.js";import{B as We,C as P,Ct as Ge,F,I,O as L,P as Ke,Rt as R,S as qe,U as z,d as B,f as V,g as H,gt as Je,j as U,l as W,m as G,r as K,s as q,u as J,w as Ye,x as Y,yt as Xe}from"./solid-runtime-C416s-HC.js";import"./control-ui-boot-shared-styles-CTDFATjh.js";import{Ql as Ze,Zl as Qe,au as $e,bo as et,bu as tt,cu as nt,du as rt,lu as it,ru as at,su as ot,yo as st,yu as ct}from"./control-ui-boot-chat-DewxEbIm.js";import{_r as lt,vr as ut}from"./deferred-ui-support-D-VedBtc.js";import{n as dt,t as ft}from"./en-update-actions-BWDrrQf2.js";import{$ as pt,Q as mt,lt as ht,ot as gt}from"./markdown-runtime-DmM7zNej.js";import{r as _t,t as vt}from"./custodian-alert-store-BWcohw2R.js";import{c as yt,s as bt}from"./state-DiRAAGiU.js";import{n as xt,t as St}from"./wizard-runner-XWO_ePgE.js";import{i as Ct,n as wt,o as Tt,r as Et,t as Dt}from"./plugin-help-D3T2T2CY.js";import{n as Ot,t as kt}from"./en-plugin-management-BoZM4tY6.js";import{n as At,t as jt}from"./pending-focus-BoBumoUz.js";import{n as Mt,r as Nt}from"./wizard-step-controls-DyqGnMlL.js";import"./control-ui-boot-chat-styles-CEPkk0Pv.js";var Pt,Ft;function It(){return(It=e((()=>{w(),d(),a(),S(),bt(),xt(),Pt=`openclaw.custodian.setup-dismissed.v1:`,Ft=class{constructor(e){this.changed=e,this.result=null,this.pending=!1,this.error=null,this.dismissed=!1,this.supported=!1,this.wizardSecretVisible=!1,this.context=null,this.client=null,this.ownerKey=null,this.dismissalKey=``,this.epoch=0,this.started=!1,this.synchronizing=!1,this.wizardStepId=null,this.wizard=new St({getClient:()=>this.client,getAgentId:()=>null,onChange:e=>{e.phase===`step`&&e.step.id!==this.wizardStepId&&(this.wizardStepId=e.step.id,this.wizardValue=yt(e.step)),this.synchronizing||this.changed()},onBackgroundCompletion:e=>this.finishSignIn(e),requestFailedMessage:()=>C(`custodian.autoSetup.failed`),cancelledMessage:()=>C(`modelSetup.wizard.cancelled`),sessionExpiredMessage:()=>C(`modelSetup.wizard.sessionExpired`),gatewayNotRespondingMessage:()=>C(`modelSetup.wizard.gatewayNotResponding`)})}get operationEpoch(){return this.epoch}get ready(){return this.result?.status===`configured`||this.result?.status===`activated`}get configuredInferenceState(){if(this.blocksGreeting)return`unresolved`;if(this.supported&&this.ready)return`ready`;let e=this.context;if(!e||e.gateway.snapshot.phase!==`connected`)return`unresolved`;let t=e.agents.state.agentsList;if(!t)return`unresolved`;let n=ee(e.gateway.snapshot.assistantAgentId??t.defaultId??``),r=t.agents.find(e=>ee(e.id)===n);return r?r.model?.primary?.trim()?`ready`:r.utilityModel?.trim()?`utility`:`required`:`unresolved`}get blocksGreeting(){return this.supported&&(!this.ready||this.pending)}synchronize(e,t,n){let i=e.gateway.snapshot,a=t&&f(i,`openclaw.setup.auto`)===!0,o=a&&i.phase===`connected`?i.client:null,s=n!==this.ownerKey;if(s||o!==this.client||a!==this.supported){if(this.epoch+=1,this.pending=!1,this.synchronizing=!0,this.wizard.close({retireOwner:!0}),this.wizardStepId=null,this.synchronizing=!1,s){this.result=null,this.error=null,this.started=!1,this.dismissalKey=Pt+e.gateway.connection.gatewayUrl;try{this.dismissed=r()?.getItem(this.dismissalKey)===`1`}catch{this.dismissed=!1}}else this.result||(this.started=!1)}this.context=e,this.ownerKey=n,this.client=o,this.supported=a,o&&!this.started&&(this.started=!0,this.retry())}async run(e){let t=this.client;if(!t||this.pending)return;let n=++this.epoch;this.pending=!0,this.error=null,this.changed();try{let r=await e(t);if(n!==this.epoch||t!==this.client)return;this.result=r,this.ready&&this.context?.agents.refreshList()}catch(e){n===this.epoch&&t===this.client&&(this.error=h(e,C(`custodian.autoSetup.failed`)))}finally{n===this.epoch&&t===this.client&&(this.pending=!1,this.changed())}}retry(){return this.run(e=>e.request(`openclaw.setup.auto`,{},{timeoutMs:null}))}async activate(e){let t=this.result;t&&await this.run(async n=>{let r=await n.request(`openclaw.setup.activate`,{kind:e.kind},{timeoutMs:null});if(!r.ok)throw Error(r.error||C(`custodian.autoSetup.failed`));return{...t,status:`activated`,selected:{...e,modelRef:r.modelRef??e.modelRef},alternatives:[...t.selected?[t.selected]:[],...t.alternatives.filter(t=>t!==e)]}})}async signIn(){let e=this.result?.selected?.shared?this.result.separateSignIn:this.result?.signIn;if(!this.client||!e||this.pending)return;this.wizard.close(),this.wizardStepId=null,this.wizard.prepareSignIn(`oauth`,e.label);let t=this.epoch,n=await this.wizard.start(e.authOptionId);t===this.epoch&&n&&await this.finishSignIn(n)}async finishSignIn(e){e.isCurrent?.()!==!1&&this.client&&(this.wizard.close(),await this.retry())}async answerWizard(e){let t=this.epoch,n=await this.wizard.answer(e,e!==void 0);t===this.epoch&&n&&await this.finishSignIn(n)}async cancelWizard(){let e=this.epoch;try{await this.wizard.requestCancellation()}catch(t){e===this.epoch&&this.reportError(t)}}reportError(e){this.error=h(e,C(`custodian.autoSetup.failed`)),this.changed()}setWizardValue(e){this.wizardValue=e,this.changed()}toggleWizardSecretVisibility(){this.wizardSecretVisible=!this.wizardSecretVisible,this.changed()}dismiss(){this.dismissed=!0;try{r()?.setItem(this.dismissalKey,`1`)}catch{}this.changed()}}})))()}var Lt;function Rt(){return(Rt=e((()=>{ue(),Et(),Lt=class{constructor(){this.ordinary={value:``},this.sensitive={value:``},this.context=null,this.cleanup=null}connect(e,t){this.cleanup?.(),this.context=e,this.cleanup=se(e,t)}resetPrompt(e,t){this.sensitive={value:``},[e.wizardValue,e.wizardSecretVisible]=[void 0,!1],e.sensitive=t}get pluginReference(){return this.context?wt(this.context):void 0}reconcile(e){if(!this.context||e.sensitive||e.wizardInputPending||e.hasUnresolvedQuestion())return;let t=Tt(this.context);t&&(this.ordinary={value:[this.ordinary.value,t].filter(Boolean).join(`
`)})}}})))()}function zt(e,t,n){t===`chat`&&n===`utility`?e?.navigate(`model-setup`,{search:`?firstRun=1`}):e?.navigate(t)}async function Bt(e){let{context:t}=e,n=t.gateway.snapshot.sessionKey?.trim();if(e.agentId){let r=await t.agents.refreshList();if(!e.isCurrent())return`stale`;n=T({agentId:e.agentId,mainKey:r?.mainKey}),we({selection:t.agentSelection,gateway:t.gateway,sessionKey:n,agentId:e.agentId})}if(!n)return`exit-setup`;let r=Me({face:`chat`,sessionKey:n,fallbackAgentId:E(t),basePath:t.basePath,mainKey:s({agentsList:t.agents.state.agentsList,hello:t.gateway.snapshot.hello}),focusComposer:!e.hatchDraft});return t.navigate(`chat`,{pathname:r.options.pathname,...e.hatchDraft?{search:`?draft=${encodeURIComponent(C(`custodian.hatchDraft`))}`}:r.options.search?{search:r.options.search}:{}}),window.dispatchEvent(new CustomEvent(Ve,{detail:{open:!1}})),`navigated`}function Vt(){return(Vt=e((()=>{Be(),fe(),w(),_e(),S()})))()}function Ht(){return`control-ui-onboarding-${u()}`}function Ut(e){try{r()?.setItem(Gt,e)}catch{}}function Wt(){let e=null;try{e=r()?.getItem(Gt)??null}catch{}if(e!==null&&e.length<=512&&e.trim().length>0)return e;let t=Ht();return Ut(t),t}var Gt;function Kt(){return(Kt=e((()=>{n(),Gt=`openclaw.custodian.session.v1`})))()}function qt(e,t){if(e.type===`note`||e.type===`action`||e.type===`progress`)return{answer:{stepId:e.id},display:C(`common.continue`)};let n={stepId:e.id,value:t};if(e.type===`text`)return typeof t==`string`?{answer:n,display:t}:null;if(e.type===`confirm`)return typeof t==`boolean`?{answer:n,display:C(t?`common.yes`:`common.no`)}:null;let r=t=>e.options?.find(e=>Object.is(e.value,t));if(e.type===`select`){let e=r(t);return e?{answer:n,display:e.label}:null}if(!Array.isArray(t))return null;let i=t.map(e=>r(e)?.label);return i.every(e=>e!==void 0)?{answer:t.length?n:{...n,value:[]},display:i.length?i.join(`, `):C(`common.none`)}:null}function Jt(e){return o(e?.gateway.snapshot??{},l.SYSTEM_AGENT_WIZARD_CANCEL)??!1}function Yt(){return(Yt=e((()=>{t(),w(),a()})))()}function Xt(e,t,n){let r=e.activeVariant===`caretaker`&&!e.eventNudgeClosed?e.activeClient:null;if(!r){e.healthNudgeSource=null;return}let i=t();if(e.healthNudgeSource?.client===r&&e.healthNudgeSource.ownershipKey===i)return;let a=e.healthNudgeSource={client:r,ownershipKey:i,pending:!0};r.request(`health`,{}).then(r=>{e.healthNudgeSource===a&&a.pending&&!e.eventNudgeClosed&&t()===i&&(e.eventNudge=tn(r),n())}).catch(()=>{e.healthNudgeSource===a&&a.pending&&(e.healthNudgeSource=null)})}async function Zt(e,t){let n=e.eventNudge;if(!n||e.sensitive||e.hasUnresolvedQuestion())return;e.eventNudgePending=n,t();let r=await e.send(n.message);if(e.eventNudgePending===n){e.eventNudgePending=null;let i=r!==`rejected`&&e.eventNudge!==null&&e.eventNudge.severity===n.severity&&e.eventNudge.message===n.message;[e.eventNudgeClosed,e.eventNudge]=[i,i?null:e.eventNudge],t()}}function Qt(e,t){return t===`received`?`sent`:e instanceof v||t===`unsent`?`rejected`:`unknown`}function $t(e,t){return t===`sent`?!1:t===`unknown`||e}function en(e,t,n){if(n.configured===!1||n.enabled===!1)return null;let r=e.toLowerCase();if(rn.some(e=>n[e]===`configured_unavailable`))return{severity:3,kind:`channel-auth`,channelLabel:t,message:`what happened with ${r} authentication?`};let i={severity:3,kind:`channel-degraded`,channelLabel:t,message:`what happened with ${r}?`},a=typeof n.healthState==`string`?n.healthState.trim().toLowerCase():void 0;if(a===`terminal-disconnect`||y(n.probe)?.ok===!1)return i;if(a===`not-running`&&n.running===!1){let e=typeof n.reconnectAttempts==`number`?n.reconnectAttempts:0,t=typeof n.lastStartAt==`number`?n.lastStartAt:void 0,r=typeof n.lastStopAt==`number`?n.lastStopAt:void 0;if(n.restartPending===!1&&r!==void 0&&(t===void 0||r>=t)&&e<10)return null}return n.connected!==!0&&a!==`healthy`&&typeof n.lastError==`string`&&n.lastError.trim()?i:n.connected===!1&&n.running===!0?{...i,severity:2,kind:`channel-disconnected`}:a&&nn.has(a)?{...i,severity:1}:null}function tn(e){let t=y(e);if(!t)return null;if(y(t.configReload)?.hotReloadStatus===`disabled`)return{severity:3,kind:`config-reload`,message:`what happened with configuration reload?`};let n=y(t.channels);if(!n)return null;let r=y(t.channelLabels),i=null;for(let[e,t]of Object.entries(n)){let n=y(t);if(!n)continue;let a=typeof r?.[e]==`string`?r[e]:e,o=y(n.accounts),s=o?Object.values(o).map(y).filter(e=>e!==null):[],c=s.length>0?s:[n];for(let t of c){let n=en(e,a,t);n&&(!i||n.severity>i.severity)&&(i=n)}}return i}var nn,rn;function an(){return(an=e((()=>{x(),nn=new Set([`disconnected`,`stale-socket`,`stuck`,`terminal-disconnect`]),rn=[`tokenStatus`,`botTokenStatus`,`appTokenStatus`,`signingSecretStatus`,`userTokenStatus`]})))()}function on(e){if(!_(e))return;let t=e.code;return t===cn.INFERENCE_UNAVAILABLE?{code:t}:void 0}function sn(e){if(!_(e))return;let t=e.code;return t===cn.SESSION_INVALIDATED?{code:t}:void 0}var cn;function ln(){return(ln=e((()=>{cn={INFERENCE_UNAVAILABLE:`system_agent_inference_unavailable`,SESSION_INVALIDATED:`system_agent_session_invalidated`}})))()}function un(e,t){return e?`onboarding`:t?`new-agent`:`caretaker`}function dn(e,t,n){let r=e===`caretaker`?{}:{welcomeVariant:e};if(t===void 0)return r;let i=window.location.pathname,a=b(i,p(i));return{...r,message:t,...a?{context:{page:a,...n?{plugin:n}:{}}}:{}}}function X(e){return e.message!==void 0||e.wizardAnswer!==void 0||e.wizardCancel!==void 0}function fn(e){let t=e&&typeof e==`object`?e.details:void 0;return{inferenceUnavailable:on(t)!==void 0,sessionInvalidated:sn(t)!==void 0}}function pn(){return(pn=e((()=>{ln(),i()})))()}function mn(e){if(!e)return null;let[t,n,r]=[e.id,e.header,e.question].map(m);if(!t||!n||!r)return null;let i=[];for(let t of e.options){let e=m(t.label);if(!e)return null;let[n,r]=[t.description,t.reply].map(m);i.push({label:e,...n?{description:n}:{},...t.recommended===!0?{recommended:!0}:{},...r?{reply:r}:{}})}return{id:t,header:n,question:r,options:i,isOther:e.isOther===!0,...e.skipAction===`exit`?{skipAction:`exit`}:{}}}function hn(){return(hn=e((()=>{})))()}function gn(e,t,n,r=null,i=null){return{id:e,role:t,text:n,at:Date.now(),question:r,step:i}}function _n(e,t){let n=t.step??null,r=n?null:mn(t.question);return{...gn(e,`assistant`,t.reply,r,n),optionalWelcome:t.optionalWelcome===!0}}function vn(e,t,n,r,i){return r||i||e.some(e=>e.question!==null&&e.question.id!==`system-agent-quick-actions`&&!t.has(`${e.id}:${e.question.id}`)&&!n.has(`${e.id}:${e.question.id}`))}function yn(e,t){let n=new Set(t);for(let t of e)t.question&&n.add(`${t.id}:${t.question.id}`);return n}function Z(e){return h(e,C(`custodian.requestFailed`))}async function bn(e){try{return{ok:!0,turns:(await e.request(`openclaw.chat.history`,{},{timeoutMs:xn})).turns}}catch(e){return{ok:!1,error:e}}}var xn,Sn,Cn;function wn(){return(wn=e((()=>{xe(),w(),d(),je(),hn(),xn=15e3,Sn=class{constructor(e,t){this.onStatusChange=e,this.getGatewaySnapshot=t,this.status=Ne(),this.generation=0,this.recoveryPending=!1,this.inFlight=null}get refreshing(){return this.inFlight!==null}get completion(){return this.inFlight?.completion??null}deferRecovery(){this.recoveryPending=!0}clearRecovery(){this.recoveryPending=!1}settleRecovery(e,t){this.recoveryPending&&!e&&(this.clearRecovery(),t())}watchAvailability(e){let t=this.getGatewaySnapshot();return()=>{let n=this.getGatewaySnapshot(),r=n&&le(n)&&(!t||!le(t));t=n,r&&this.recover(e)}}async recover(e){let t=this.generation;await this.inFlight?.promise;let n=this.getGatewaySnapshot();t===this.generation&&n&&le(n)&&(this.status.awaitingGateway||this.status.error!==null)&&e()}invalidate(){this.generation+=1,this.inFlight?.settle(),this.inFlight=null}reset(){this.clearRecovery(),this.invalidate(),this.status=Ne()}async read(e,t,n){let r=this.inFlight;if(r&&r.client===e&&r.epoch===t)return await r.promise,null;let i=++this.generation;this.status=Oe(this.status,{clearError:!1});let a=bn(e),{promise:o,resolve:s}=Promise.withResolvers(),c={client:e,epoch:t,promise:a,completion:o,settle:()=>s(this.status)};this.inFlight=c,this.onStatusChange();try{let e=await a;return!n()||i!==this.generation?null:(this.status=e.ok?ye():Ie(this.status,e.error,this.getGatewaySnapshot()),e)}finally{c.settle(),this.inFlight?.promise===a&&(this.inFlight=null,this.onStatusChange())}}async loadMessages(e,t,n,r){this.clearRecovery();let i=await this.read(e,t,r);if(!i?.ok||!r())return null;let a=n;return{messages:i.turns.map(e=>({id:a++,role:e.role,text:e.role===`user`&&e.text===Cn?C(`custodian.sensitiveReply`):e.text,at:e.at,question:null,step:null})),nextMessageId:a}}},Cn=`<redacted secret>`})))()}var Tn,En,Dn;function On(){return(On=e((()=>{w(),a(),bt(),It(),Rt(),Vt(),Kt(),He(),Yt(),an(),pn(),wn(),Tn=19e4,En=class{constructor(){this.messages=[],this.sending=!1,this.sensitive=!1,this.wizardInputPending=!1,this.wizardSecretVisible=!1,this.questionReplyUncertain=!1,this.error=null,this.transcript=new Sn(()=>this.emit(),()=>this.context?.gateway.snapshot),this.dismissedQuestions=new Set,this.answeredQuestions=new Set,this.activeClient=null,this.chatAvailable=!1,this.eventNudge=null,this.eventNudgePending=null,this.eventNudgeClosed=!1,this.healthNudgeSource=null,this.channelOnboardingNudgeClosed=!1,this.earlierBoundaryAfterId=null,this.abandonedTurnOutcomeUnknown=!1,this.autoSetup=new Ft(()=>{this.synchronizeClient(),this.emit()}),this.inferenceState=`unverified`,this.inputDrafts=new Lt,this.context=null,this.variant=`caretaker`,this.sessionVariant=null,this.sessionId=Wt(),this.requestEpoch=0,this.requestAbort=null,this.nextMessageId=1,this.retryParams=null,this.sessionClient=null,this.sessionOwnershipKey=null,this.sessionOwner=new he,this.sessionStarted=!1,this.configuredInferenceState=`unresolved`,this.gatewayCleanup=null,this.agentCleanup=null,this.eventCleanup=null,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}connect(e,t){let n=this.context!==e;if(n||this.variant!==t){if(this.variant=t,n){this.gatewayCleanup?.(),this.agentCleanup?.(),this.eventCleanup?.(),this.context=e,this.inputDrafts.connect(e,()=>this.emit());let t=this.transcript.watchAvailability(()=>void this.refreshTranscriptIfIdle());this.gatewayCleanup=e.gateway.subscribe(()=>{t(),this.synchronizeClient(),this.synchronizeHealthNudge(),this.emit()}),this.agentCleanup=e.agents.subscribe(()=>{this.synchronizeClient(),this.synchronizeHealthNudge(),this.emit()}),this.eventCleanup=e.gateway.subscribeEvents(e=>{this.variant!==`caretaker`||this.eventNudgeClosed||(e.event===`health`?(this.healthNudgeSource&&(this.healthNudgeSource.pending=!1),this.eventNudge=tn(e.payload)):e.event===`tick`&&this.synchronizeHealthNudge(),this.emit())})}this.synchronizeClient(),this.synchronizeHealthNudge(),this.emit()}}synchronizeHealthNudge(){Xt(this,()=>this.sessionOwner.key(this.context?.gateway??null),()=>this.emit())}get input(){return this.inputDrafts[this.sensitive?`sensitive`:`ordinary`].value}set input(e){this.inputDrafts[this.sensitive?`sensitive`:`ordinary`]={value:e}}setInput(e){this.input=e,this.emit()}setWizardValue(e){this.wizardValue=e,this.emit()}toggleWizardSecretVisibility(){this.wizardSecretVisible=!this.wizardSecretVisible,this.emit()}hasRealUserTurn(){return this.messages.some(e=>e.role===`user`)}get activeVariant(){return this.variant}get operationEpoch(){return this.requestEpoch}reportError(e){this.error=Z(e),this.emit()}hasUnresolvedQuestion(){return vn(this.messages,this.dismissedQuestions,this.answeredQuestions,this.wizardInputPending,this.questionReplyUncertain)}get transcriptBlocked(){return this.sending||this.hasUnresolvedQuestion()||this.transcript.refreshing}async refreshTranscriptIfIdle(){let e=this.activeClient;e&&this.sessionStarted&&this.chatAvailable&&(this.transcriptBlocked?(this.transcript.status.awaitingGateway||this.transcript.status.error!==null)&&this.transcript.deferRecovery():await this.refreshTranscriptHistory(e,this.requestEpoch)&&this.abandonedTurnOutcomeUnknown&&(this.abandonedTurnOutcomeUnknown=!1,this.emit()))}canRetry(){return this.retryParams!==null&&!X(this.retryParams)}get setupRequired(){return this.configuredInferenceState===`required`}get canSend(){return this.activeClient!==null&&this.chatAvailable&&!this.sending&&(this.configuredInferenceState===`ready`||this.configuredInferenceState===`utility`)&&this.inferenceState===`ready`}get wizardCancelAvailable(){return Jt(this.context)}retry(){let e=this.activeClient,t=this.retryParams;return e&&t&&!X(t)&&this.chatAvailable&&!this.sending?this.initializeSession(e,t,!1):Promise.resolve()}async send(e,t,n=this.hasUnresolvedQuestion(),r){let i=e??this.input,a=this.sensitive?i:i.trim(),o=this.activeClient;if(!a.trim()||!o||!this.canSend)return this.emit(),`rejected`;let s=this.sensitive?C(`custodian.sensitiveReply`):t??a,c={sessionId:this.sessionId,...dn(this.variant,a,this.inputDrafts.pluginReference)};return await this.sendUserTurn(o,c,s,n,()=>r&&(!r.isCurrent()||!r.admit())?!1:(e===void 0&&(this.input=``),!0))}async sendUserTurn(e,t,n,r,i){let a=[this.answeredQuestions,this.questionReplyUncertain],o,s=await this.requestReply(e,t,()=>{let e=this.inputDrafts.ordinary;if(i&&!i())return!1;let t=this.inputDrafts.ordinary;this.inputDrafts.resetPrompt(this,this.sensitive),o=this.requestEpoch,r&&(this.questionReplyUncertain=!0),this.abandonedTurnOutcomeUnknown=!1,this.answeredQuestions=yn(this.messages,this.answeredQuestions);let s=gn(this.nextMessageId++,`user`,n);return this.messages=[...this.messages,s],()=>{this.messages=this.messages.filter(e=>e!==s),this.answeredQuestions=a[0],e!==t&&this.inputDrafts.ordinary===t&&(this.inputDrafts.ordinary=e)}});return r&&this.requestEpoch===o&&(this.questionReplyUncertain=$t(a[1],s),s===`rejected`&&(this.answeredQuestions=a[0]),this.emit()),s}sendEventNudge(){return Zt(this,()=>this.emit())}dismissEventNudge(){[this.eventNudge,this.eventNudgeClosed]=[null,!0],this.emit()}dismissChannelOnboardingNudge(){this.channelOnboardingNudgeClosed=!0,this.emit(),this.context?.replace(`custodian`)}openChannelsFromOnboarding(){this.channelOnboardingNudgeClosed=!0,this.revokeNavigationAuthority(),this.emit(),this.context?.navigate(`channels`)}async dismissQuestion(e){let t=e.question;t&&(t.skipAction===`exit`?this.exitSetup():await this.send(t.isOther?C(`optionCard.skip`):`cancel`,C(`optionCard.skip`),!0)!==`rejected`&&this.messages.includes(e)&&(this.dismissedQuestions=new Set(this.dismissedQuestions).add(`${e.id}:${t.id}`),this.emit()))}answerQuestion(e,t){let n=e.question;if(!n)return Promise.resolve(`rejected`);let r=n.options.find(e=>e.label===t);return this.send(r?.reply??t,t,!0)}answerWizardStep(e,t){if(!e.step||!this.wizardInputPending)return Promise.resolve(`rejected`);let n=qt(e.step,t),r=this.activeClient;if(!n||!r||!this.canSend)return this.emit(),Promise.resolve(`rejected`);let i=e.step.sensitive?C(`custodian.sensitiveReply`):n.display;return this.sendUserTurn(r,{sessionId:this.sessionId,wizardAnswer:n.answer},i,!0)}cancelWizardStep(e){let t=e.step,n=this.canSend?this.activeClient:null;return!t||!this.wizardInputPending||!n||!this.wizardCancelAvailable?(this.emit(),Promise.resolve(`rejected`)):this.sendUserTurn(n,{sessionId:this.sessionId,wizardCancel:{stepId:t.id}},C(`custodian.cancel`),!0)}exitSetup(e=`chat`){this.revokeNavigationAuthority(),zt(this.context,e,this.configuredInferenceState)}revokeNavigationAuthority(){this.requestAbort?.abort(),this.requestAbort=null,this.transcript.clearRecovery(),this.advanceRequestEpoch(),this.sending=!1,this.questionReplyUncertain=!1,this.retryParams=null,this.error=null}advanceRequestEpoch(){return this.transcript.invalidate(),++this.requestEpoch}emit(){this.inputDrafts.reconcile(this),this.transcript.settleRecovery(this.transcriptBlocked,()=>void this.refreshTranscriptIfIdle());for(let e of this.listeners)e()}startSession(e,t){this.sessionVariant=this.variant,this.sessionClient=e,this.sessionOwnershipKey=this.sessionOwner.key(this.context?.gateway??null),this.sessionStarted=!0,this.initializeSession(e,this.initialChatParams(),t)}initialChatParams(){return{sessionId:this.sessionId,...dn(this.variant)}}replaceSessionId(e){this.sessionId=e??Ht(),Ut(this.sessionId)}abandonPendingUserTurn(e){e&&X(e)&&(this.retryParams=null,this.abandonedTurnOutcomeUnknown=!0)}restartVolatileSession(e){this.replaceSessionId(),this.answeredQuestions=yn(this.messages,this.answeredQuestions),this.inputDrafts.resetPrompt(this,!1),this.wizardInputPending=this.questionReplyUncertain=!1,this.earlierBoundaryAfterId=this.messages.at(-1)?.id??null,this.startSession(e,!1)}synchronizeClient(){let e=this.context;if(!e)return;let t=e.gateway.snapshot,n=t.phase===`connected`?t.client:null,r=n!==null&&c(t,`openclaw.chat`,`operator.admin`,{requireAdvertisement:!1}),i=this.sessionOwner.key(e.gateway);this.autoSetup.synchronize(e,this.variant===`onboarding`,i);let a=this.autoSetup.configuredInferenceState,o=a!==this.configuredInferenceState;this.configuredInferenceState=a;let s=this.sessionStarted&&this.sessionVariant!==this.variant,l=this.sessionStarted&&n!==null&&this.activeClient===null,u=this.sessionStarted&&n!==null&&n!==this.sessionClient,d=this.sessionOwnershipKey!==null&&i!==this.sessionOwnershipKey;if(n===this.activeClient&&!s&&!u&&!d&&this.chatAvailable===(r&&a!==`unresolved`)&&!o)return;let f=this.sending&&this.retryParams!==null,p=f?this.retryParams:null;if((n!==this.activeClient||d)&&this.transcript.clearRecovery(),this.activeClient=n,this.advanceRequestEpoch(),this.sending=!1,this.chatAvailable=!1,s||d)d&&this.replaceSessionId(),[this.eventNudge,this.eventNudgePending]=[null,null],this.eventNudgeClosed=!1,this.abandonedTurnOutcomeUnknown=!1,this.sessionStarted=!1,this.clearConversation();else if(n&&(u||l)){if(!r){this.sessionStarted=!1,this.abandonPendingUserTurn(p),this.error=C(`custodian.accessRequired`);return}this.chatAvailable=!0,this.abandonPendingUserTurn(p),this.requestAbort?.abort(),this.requestAbort=null,this.sessionClient=n,this.sessionOwnershipKey=i,this.questionReplyUncertain||this.abandonedTurnOutcomeUnknown?(this.questionReplyUncertain=!1,this.wizardInputPending=!1,this.abandonedTurnOutcomeUnknown=!1,this.initializeSession(n,this.initialChatParams())):this.refreshTranscriptIfIdle();return}else f&&(p?.message===void 0&&(this.error=C(`custodian.connectionChanged`)),this.abandonPendingUserTurn(p));n&&(r?a!==`unresolved`&&(this.chatAvailable=!0,a===`required`?(this.sessionStarted=!1,this.clearConversation()):this.sessionStarted?this.retryParams||(this.error=f?this.error:null):(this.clearConversation(!0),this.startSession(n,!0))):this.error=C(`custodian.accessRequired`))}async initializeSession(e,t,n=!0){let r=this.advanceRequestEpoch();this.sending=!0,this.inferenceState=`unverified`,this.error=null,this.retryParams=t,this.emit(),n&&await this.refreshTranscriptHistory(e,r),r===this.requestEpoch&&e===this.activeClient&&await this.requestReply(e,t)}async refreshTranscriptHistory(e,t){let n=await this.transcript.loadMessages(e,t,this.nextMessageId,()=>t===this.requestEpoch&&e===this.activeClient);return n?([this.messages,this.nextMessageId]=[n.messages,n.nextMessageId],this.earlierBoundaryAfterId=this.messages.at(-1)?.id??null,this.emit(),!0):!1}clearConversation(e=!1){this.messages=[],this.dismissedQuestions=new Set,this.answeredQuestions=new Set,this.retryParams=null,this.error=null,this.transcript.reset(),this.inferenceState=`unverified`,e||(this.inputDrafts.ordinary={value:``}),this.inputDrafts.resetPrompt(this,!1),this.wizardInputPending=this.questionReplyUncertain=!1,this.earlierBoundaryAfterId=null}async requestReply(e,t,n){let r=this.context;if(!r)return`rejected`;let i=()=>e===this.activeClient&&r.gateway.snapshot.client===e&&c(r.gateway.snapshot,`openclaw.chat`,`operator.admin`,{requireAdvertisement:!1});if(!i())return`rejected`;this.requestAbort?.abort();let a=new AbortController;this.requestAbort=a;let o=this.advanceRequestEpoch(),s=`unsent`,l;this.sending=!0,this.error=null,this.retryParams=t,this.emit();try{if(o!==this.requestEpoch||!i()||(l=n?.())===!1)return this.retryParams===t&&(this.retryParams=null),`rejected`;let c=e.request(`openclaw.chat`,t,{timeoutMs:Tn,onSent:()=>{s=`sent`},signal:a.signal});this.emit();let u=await c;if(s=`received`,o!==this.requestEpoch||e!==this.activeClient)return`sent`;this.replaceSessionId(u.sessionId),this.inputDrafts.resetPrompt(this,u.sensitive===!0),this.wizardInputPending=u.wizardInputPending===!0,this.retryParams=null,this.inferenceState=`ready`,this.wizardValue=u.step?yt(u.step):void 0;let d=_n(this.nextMessageId,u);return this.nextMessageId+=1,this.messages=[...this.messages,d],u.handoff?.kind===`model-accounts`?this.exitSetup(`profile`):u.action===`open-agent`?await Bt({context:r,...u.agentId?{agentId:u.agentId}:{},hatchDraft:u.agentDraft===`hatch`,isCurrent:()=>o===this.requestEpoch&&e===this.activeClient})===`exit-setup`&&this.exitSetup():u.action===`exit`&&this.exitSetup(),`sent`}catch(n){if(o===this.requestEpoch&&e===this.activeClient){s===`unsent`&&l&&l(),this.error=Z(n);let{inferenceUnavailable:r,sessionInvalidated:i}=fn(n);r&&(this.inferenceState=`unverified`,this.retryParams=this.initialChatParams()),i&&X(t)?(this.restartVolatileSession(e),this.error=C(`custodian.sessionRestarted`,{error:Z(n)})):i&&(this.replaceSessionId(),this.retryParams={...t,sessionId:this.sessionId},this.error=C(`custodian.sessionRestarted`,{error:Z(n)}))}return X(t)&&this.retryParams===t&&(this.retryParams=null),Qt(n,s)}finally{this.requestAbort===a&&(this.requestAbort=null),o===this.requestEpoch&&(this.sending=!1),this.emit()}}},Dn=new En})))()}function kn(e){let t,n=F(()=>e.props.options.slice(0,4)),r=F(()=>n().findIndex(e=>e.recommended)),i=F(()=>({key:JSON.stringify([e.props.header??``,e.props.question,e.props.options.map(e=>[e.value,e.label,e.recommended===!0])]),recommended:n().find(e=>e.recommended)?.value??``}),{equals:(e,t)=>e.key===t.key}),[a,o]=We(()=>i().recommended),s=F(()=>Math.max(0,n().findIndex(e=>e.value===a()))),c=new Set;jt(()=>({request:i(),disabled:e.props.disabled,selected:a()}),{requested:(e,t)=>e.request.key===t?.request.key?void 0:!!e.request.recommended,ready:e=>!e.disabled,focus:e=>{let n=t.ownerDocument.activeElement;(!n||n===t.ownerDocument.body||t.contains(n))&&[...c].find(t=>t.dataset.optionValue===e.selected)?.focus({preventScroll:!0})}});let l=t=>{e.props.disabled||(o(t),e.props.onSelect?.(t))},u=t=>{let r=n().map(e=>e.value),i=[...c].find(e=>e===t.target),a=i?r.indexOf(i.dataset.optionValue??``):-1,s=Fn[t.key],l=t.key===`Home`?0:t.key===`End`?r.length-1:s===void 0?-1:(a+s+r.length)%r.length;e.props.disabled||a<0||l<0||(t.preventDefault(),o(r[l]),[...c].find(e=>e.dataset.optionValue===r[l])?.focus())};var d=jn(),f=d.firstChild,p=f.firstChild,m=p.nextSibling,h=m.nextSibling;return G(()=>e=>t=e,d),d._$owner=R(),B(f,U(L,{get when(){return e.props.header},get children(){var t=An();return B(t,()=>e.props.header),t}}),p),B(p,()=>e.props.question),m._$$keydown=u,B(m,U(P,{get each(){return n()},keyed:e=>e.value,children:(t,n)=>{var i=Pn(),o=i.firstChild,u=o.firstChild;i._$$click=()=>l(t().value);var d=Le(e=>(c.add(e),()=>c.delete(e)));return(typeof d==`function`||Array.isArray(d))&&G(()=>d,i),B(u,()=>t().label),B(o,U(L,{get when(){return t().description},get children(){var e=Mn();return B(e,()=>t().description),e}}),null),B(i,U(L,{get when(){return n()===r()},get children(){var e=Nn();return B(e,()=>M(`optionCard.recommended`)),e}}),null),W(()=>({e:n()===r(),t:t().value===a(),a:t().value===a()?`true`:`false`,o:n()===s()?0:-1,i:t().value,n:e.props.disabled}),({e,t,a:n,o:r,i:a,n:o},s)=>{e!==s?.e&&i.classList.toggle(`option-card__choice--recommended`,e),t!==s?.t&&i.classList.toggle(`option-card__choice--selected`,t),n!==s?.a&&H(i,`aria-checked`,n),r!==s?.o&&H(i,`tabindex`,r),a!==s?.i&&H(i,`data-option-value`,a),o!==s?.n&&H(i,`disabled`,o)}),i}})),h._$$click=()=>!e.props.disabled&&e.props.onSkip?.(),B(h,()=>M(`optionCard.skip`)),W(()=>({e:e.props.question,t:e.props.disabled}),({e,t},n)=>{e!==n?.e&&H(f,`aria-label`,e),t!==n?.t&&H(h,`disabled`,t)}),d}var An,jn,Mn,Nn,Pn,Fn;function In(){return(In=e((()=>{J(),z(),Se(),j(),At(),An=Y(`<div class=option-card__chip>`),jn=Y(`<openclaw-option-card><section class=option-card role=group><div class=option-card__question></div><div class=option-card__choices role=radiogroup></div><button class=option-card__skip type=button>`,1),Mn=Y(`<span class=option-card__description>`),Nn=Y(`<span class=option-card__recommended>`),Pn=Y(`<button class=option-card__choice type=button role=radio><span class=option-card__choice-copy><strong>`),Fn={ArrowDown:1,ArrowRight:1,ArrowUp:-1,ArrowLeft:-1},q([`keydown`,`click`])})))()}function Ln(){return(Ln=e((()=>{})))()}function Rn(e){let[t,n]=I(!1),[r,i]=I(!1),[a,o]=I(!1),[s,c]=I(!1),l=new Set,u=()=>l.forEach(e=>e());Je(()=>u);let d=Xe(function*(e,t,r){e===`verification`?n(!0):e===`wizard`?i(!0):e===`cancellation`?o(!0):c(!0),yield Promise.race([t,r])});async function f(t,n){let r=e(),i=r.autoSetup,a=n(r),o=()=>t===`session`?r.operationEpoch:i.operationEpoch,s=o(),c=Promise.withResolvers(),u=()=>e()===r&&o()===s&&(t===`session`||!i.dismissed),f=()=>{if(t===`session`)return r.sending;let e=i.wizard.state;return t===`verification`?i.pending:t===`cancellation`?e.phase!==`idle`:i.pending||e.phase===`starting`||e.phase===`step`&&e.busy},p=()=>{(!u()||!f())&&c.resolve()};l.add(c.resolve);let m=r.subscribe(p);p(),await(t===`session`?new Promise(e=>{Je(e)}):Promise.resolve());try{u()&&f()?await d(t,a,c.promise):await Promise.race([a,c.promise])}catch(e){u()&&(t===`session`?r.reportError(e):i.reportError(e))}finally{m(),l.delete(c.resolve)}}return{actions:{setup:{get verifying(){return t()},get answering(){return r()},get cancelling(){return a()},activate:e=>void f(`verification`,t=>t.autoSetup.activate(e)),retry:()=>void f(`verification`,e=>e.autoSetup.retry()),signIn:()=>void f(`wizard`,e=>e.autoSetup.signIn()),answer:e=>void f(`wizard`,t=>t.autoSetup.answerWizard(e)),cancel:()=>void f(`cancellation`,e=>e.autoSetup.cancelWizard())},session:{get sending(){return s()},send:()=>void f(`session`,e=>e.send()),retry:()=>void f(`session`,e=>e.retry()),sendEventNudge:()=>void f(`session`,e=>e.sendEventNudge()),answerQuestion:(e,t)=>void f(`session`,n=>n.answerQuestion(e,t)),dismissQuestion:e=>void f(`session`,t=>t.dismissQuestion(e)),answerWizardStep:(e,t)=>void f(`session`,n=>n.answerWizardStep(e,t)),cancelWizardStep:e=>void f(`session`,t=>t.cancelWizardStep(e))}},retire:u}}function zn(){return(zn=e((()=>{z()})))()}function Bn(e){let t=F(()=>de(e.context.gateway)),n=()=>c(t().read().snapshot,`update.run`,`operator.admin`),r=()=>e.alert.action?.target.kind===`update`&&!n();var i=Vn(),a=i.firstChild,o=a.firstChild,s=o.nextSibling,l=a.nextSibling;return B(o,()=>e.alert.title),s._$$click=()=>e.onDismiss(),B(s,U(N,{name:`x`})),B(l,U(P,{get each(){return e.alert.facts},children:e=>(()=>{var t=Hn();return B(t,e),t})()})),B(i,U(L,{get when(){return e.alert.action},children:t=>(()=>{var i=Un();return i._$$click=()=>{let r=t().target,i=e.context;r.kind===`navigate`?i.navigate(r.routeId):n()&&Fe({isCurrentTarget:i.overlays.captureUpdateTarget(),canStartNativeUpdate:()=>c(i.gateway.snapshot,`update.run`,`operator.admin`),startGatewayUpdate:()=>void i.overlays.runUpdate(),watchUpdateProgress:ke(i),onAcknowledge:()=>i.overlays.acknowledgeUpdateRun(),onCheckStatus:()=>i.overlays.refreshUpdateStatus(),onReviewUpdate:()=>i.navigate(`updates`),updateAvailable:i.overlays.snapshot.updateAvailable,updateSchedule:i.overlays.snapshot.updateSchedule,viaNativeApp:O()})},B(i,()=>t().label),W(()=>({e:r()?M(`updates.adminRequired`):void 0,t:r()}),({e,t},n)=>{e!==n?.e&&H(i,`title`,e),t!==n?.t&&H(i,`disabled`,t)}),i})()}),null),W(()=>M(`common.dismiss`),e=>{H(s,`aria-label`,e)}),i}var Vn,Hn,Un;function Wn(){return(Wn=e((()=>{J(),z(),ce(),be(),D(),ft(),a(),te(),j(),Vn=Y(`<article class="custodian__nudge custodian__alert-card"role=status><div class=custodian__alert-heading><strong></strong><button class=custodian__nudge-dismiss type=button></button></div><ul class=custodian__alert-facts>`),Hn=Y(`<li>`),Un=Y(`<button class="btn btn--sm primary custodian__alert-action"type=button>`),Pe(dt),q([`click`])})))()}function Gn(e){if(e.kind===`config-reload`)return M(`custodian.nudge.configReload`);let t=e.channelLabel??M(`custodian.nudge.channelFallback`);return e.kind===`channel-auth`?M(`custodian.nudge.channelAuth`,{channel:t}):e.kind===`channel-disconnected`?M(`custodian.nudge.channelDisconnected`,{channel:t}):M(`custodian.nudge.channelDegraded`,{channel:t})}function Kn(e){var t=Yn();return t._$$click=()=>e.onDismiss(),B(t,U(N,{name:`x`})),W(()=>M(e.label),e=>{H(t,`aria-label`,e)}),t}function qn(e){var t=Xn(),n=t.firstChild;return n._$$click=()=>e.onSend(),B(n,()=>Gn(e.nudge)),B(t,U(Kn,{label:`custodian.nudge.dismiss`,get onDismiss(){return e.onDismiss}}),null),W(()=>e.disabled,e=>{H(n,`disabled`,e)}),t}function Jn(e){var t=Zn(),n=t.firstChild,r=n.firstChild,i=r.nextSibling,a=n.nextSibling;return B(r,()=>M(e.error?`custodian.nudge.channelStatusErrorTitle`:`custodian.nudge.channelSetupTitle`)),B(i,()=>M(e.error?`custodian.nudge.channelStatusErrorBody`:`custodian.nudge.channelSetupBody`)),a._$$click=()=>e.onAction(),B(a,()=>M(e.error?e.retrying?`common.loading`:`common.retry`:`custodian.nudge.channelSetupAction`)),B(t,U(Kn,{label:`custodian.nudge.channelSetupDismiss`,get onDismiss(){return e.onDismiss}}),null),W(()=>({e:e.error?`alert`:`status`,t:e.error&&e.retrying}),({e,t:n},r)=>{e!==r?.e&&H(t,`role`,e),n!==r?.t&&H(a,`disabled`,n)}),t}var Yn,Xn,Zn;function Qn(){return(Qn=e((()=>{J(),D(),j(),Yn=Y(`<button class=custodian__nudge-dismiss type=button>`),Xn=Y(`<div class=custodian__nudge role=status><button class=custodian__nudge-action type=button>`),Zn=Y(`<div class="custodian__nudge custodian__nudge--channel-onboarding"><div class=custodian__nudge-copy><strong></strong><span></span></div><button class="btn btn--sm primary custodian__nudge-cta"type=button>`),q([`click`])})))()}function $n(e){let t=typeof window>`u`?void 0:window.__OPENCLAW_NATIVE_SETUP__;if(t)return t;let n=e.nativeDeviceSettings,r=ut();if(!n&&!r)return null;let i=r?.snapshot,a=i?.gateways.find(e=>e.id===i.currentId);return{currentGateway:a?{name:a.kind===`local`?a.name||C(`custodian.autoSetup.thisComputer`):a.name,kind:a.kind}:void 0,openAiSetup:n?.snapshot?.capabilities?.aiSetupAvailable===!0?()=>n.openPanel(`ai-setup`):void 0,openGateways:r?()=>r.openSettings():void 0,reviewPermissions:n?()=>e.navigate(`device-permissions`):void 0}}function er(){return(er=e((()=>{w(),lt()})))()}function tr(e){let t=()=>e.setup().wizard.state,n=()=>{let e=t();return e.phase===`step`?e:void 0},r=()=>{let e=t();return e.phase===`error`||e.phase===`cancelled`?e.message:null};return[U(L,{get when(){return t().phase===`starting`},get children(){var e=rr();return B(e,()=>M(`custodian.autoSetup.startingSignIn`)),e}}),U(L,{get when(){return r()},children:e=>(()=>{var t=ir();return B(t,e),t})()}),U(L,{get when(){return n()},children:t=>(()=>{var n=ar(),r=n.firstChild,i=r.nextSibling,a=i.nextSibling;return B(n,U(L,{get when(){return t().step.title},children:e=>(()=>{var t=or();return B(t,()=>g(e())),t})()}),r),B(n,U(L,{get when(){return t().validationError},children:e=>(()=>{var t=sr();return B(t,e),t})()}),i),B(n,U(Mt,{get step(){return t().step},get value(){return e.setup().wizardValue},get busy(){return e.actions.answering||t().busy},get externalAuthInput(){return t().externalAuthInput},inputId:`custodian-setup-sign-in`,get validationErrorId(){return t().validationError?`custodian-setup-validation`:void 0},get sensitiveRevealed(){return e.setup().wizardSecretVisible},onValueChange:t=>e.setup().setWizardValue(t),onAnswer:t=>e.actions.answer(t),onToggleSensitiveVisibility:()=>e.setup().toggleWizardSecretVisibility()}),a),a._$$click=()=>e.actions.cancel(),B(a,()=>M(`custodian.cancel`)),W(()=>e.actions.cancelling,e=>{H(a,`disabled`,e)}),n})()})]}function nr(e){let t=ze(),n=F(()=>e.store),r=F(()=>A(n(),e=>e.autoSetup)),i=()=>r().read(),a=()=>i().result,o=t.nativeDeviceSettings?A(t.nativeDeviceSettings,()=>$n(t)).read:()=>$n(t),s=()=>{let t=i();return e.actions.verifying||e.actions.answering||t.pending||t.wizard.state.phase===`starting`||t.wizard.state.phase===`step`},c=()=>{let e=o()?.currentGateway;if(e)return e.name;try{return new URL(t.gateway.connection.gatewayUrl).hostname}catch{return M(`custodian.autoSetup.thisGateway`)}},l=()=>{let t=i();if(e.actions.verifying||t.pending)return M(`custodian.autoSetup.connecting`);let n=t.result?.selected;return n?M(`custodian.autoSetup.using`,{label:n.label,modelRef:n.modelRef,gateway:c()}):M(t.result?.status===`needs-sign-in`?`custodian.autoSetup.signInTitle`:`custodian.autoSetup.unavailableTitle`)};var u=hr();return u._$owner=R(),B(u,U(L,{get when(){return V(()=>!!i().supported)()?!i().dismissed:i().supported},get children(){var t=mr(),n=t.firstChild,r=n.firstChild,c=r.nextSibling,u=n.nextSibling,d=u.nextSibling,f=d.nextSibling,p=f.nextSibling,m=p.nextSibling,h=m.nextSibling,g=h.nextSibling,_=g.nextSibling;return B(r,l),c._$$click=()=>i().dismiss(),B(c,U(N,{name:`x`})),B(t,U(L,{get when(){return e.actions.verifying||i().pending},get children(){var e=cr();return e.firstChild,B(e,()=>M(`custodian.autoSetup.verifying`),null),e}}),u),B(t,U(L,{get when(){return V(()=>!i().pending)()&&a()?.selected?.shared},get children(){return[(()=>{var e=Q();return B(e,()=>M(`custodian.autoSetup.sharedCodexLogin`)),e})(),U(L,{get when(){return a()?.separateSignIn},get children(){var t=$();return t._$$click=()=>e.actions.signIn(),B(t,()=>M(`custodian.autoSetup.separateLogin`)),W(()=>s(),e=>{H(t,`disabled`,e)}),t}})]}}),d),B(t,U(L,{get when(){return V(()=>!i().pending)()&&a()?.status===`needs-sign-in`},get children(){return[(()=>{var e=Q();return B(e,()=>M(`custodian.autoSetup.signInBody`)),e})(),U(L,{get when(){return!s()},get children(){var t=lr();return t._$$click=()=>e.actions.signIn(),B(t,()=>M(`custodian.autoSetup.signIn`)),t}})]}}),f),B(t,U(L,{get when(){return V(()=>!i().pending)()&&a()?.status===`unavailable`},get children(){return[(()=>{var e=Q();return B(e,()=>M(`custodian.autoSetup.unavailableBody`)),e})(),U(L,{get when(){return a()?.attempts.length},get children(){var e=ur();return B(e,U(P,{get each(){return a()?.attempts},children:e=>(()=>{var t=gr(),n=t.firstChild,r=n.firstChild;return n.nextSibling,B(n,()=>e.label,r),B(t,()=>e.error,null),t})()})),e}}),U(L,{get when(){return o()?.openAiSetup},get fallback(){var e=_r(),t=e.firstChild;return B(e,()=>M(`custodian.autoSetup.commandHint`),t),e},get children(){var e=$();return e._$$click=()=>o()?.openAiSetup?.(),B(e,()=>M(`custodian.autoSetup.nativeSetup`)),e}})]}}),p),B(t,U(L,{get when(){return a()?.alternatives.length},get children(){var t=dr(),n=t.firstChild,r=n.nextSibling;return B(n,()=>M(`custodian.autoSetup.alternatives`)),B(r,U(P,{get each(){return a()?.alternatives},children:t=>(()=>{var n=$();return n._$$click=()=>e.actions.activate(t),B(n,()=>t.label),W(()=>({e:t.detail,t:s()}),({e,t},r)=>{e!==r?.e&&H(n,`title`,e),t!==r?.t&&H(n,`disabled`,t)}),n})()})),t}}),m),B(t,U(tr,{setup:i,get actions(){return e.actions}}),h),B(t,U(L,{get when(){return i().error},children:t=>(()=>{var n=vr(),r=n.firstChild,i=r.nextSibling;return B(r,t),i._$$click=()=>e.actions.retry(),B(i,()=>M(`common.retry`)),W(()=>s(),e=>{H(i,`disabled`,e)}),n})()}),g),B(t,U(L,{get when(){return o()?.openGateways||o()?.reviewPermissions},get children(){var e=pr(),t=e.firstChild,n=t.nextSibling;return B(e,U(L,{get when(){return o()?.openGateways},get children(){var e=fr();return e._$$click=()=>o()?.openGateways?.(),B(e,()=>M(`custodian.autoSetup.differentGateway`)),e}}),t),B(e,U(L,{get when(){return o()?.reviewPermissions},get children(){var e=fr();return e._$$click=()=>o()?.reviewPermissions?.(),B(e,()=>M(`custodian.autoSetup.reviewPermissions`)),e}}),n),e}}),_),B(_,()=>M(`custodian.autoSetup.safety`)),W(()=>({e:M(`custodian.autoSetup.title`),t:M(`common.dismiss`)}),({e,t:n},r)=>{e!==r?.e&&H(t,`aria-label`,e),n!==r?.t&&H(c,`aria-label`,n)}),t}})),u}var rr,ir,ar,or,sr,cr,Q,$,lr,ur,dr,fr,pr,mr,hr,gr,_r,vr;function yr(){return(yr=e((()=>{J(),z(),er(),D(),Nt(),d(),Te(),j(),De(),rr=Y(`<p role=status>`),ir=Y(`<p class=custodian-setup__error role=alert>`),ar=Y(`<div class=custodian-setup__wizard><!><!><button class="btn btn--ghost"type=button>`),or=Y(`<h3>`),sr=Y(`<p id=custodian-setup-validation class=custodian-setup__error role=alert>`),cr=Y(`<p class=custodian-setup__progress role=status><span class=btn__spinner aria-hidden=true>`),Q=Y(`<p>`),$=Y(`<button class=btn type=button>`),lr=Y(`<button class="btn primary"type=button>`),ur=Y(`<ul class=custodian-setup__attempts>`),dr=Y(`<div class=custodian-setup__alternatives><h3></h3><div class=custodian-setup__actions>`),fr=Y(`<button class="btn btn--ghost"type=button>`),pr=Y(`<div class="custodian-setup__actions custodian-setup__native-actions"><!><!>`),mr=Y(`<section class=custodian-setup><div class=custodian-setup__heading><h2></h2><button class=custodian__nudge-dismiss type=button></button></div><!><!><!><!><!><!><!><p class=custodian-setup__safety>`),hr=Y(`<openclaw-custodian-setup-card>`,1),gr=Y(`<li><strong>:</strong> `),_r=Y(`<p> <code>openclaw onboard`),vr=Y(`<div class=custodian-setup__error role=alert><p></p><button class=btn type=button>`),q([`click`])})))()}function br(e){let t=`msg-${e.id}`,n={role:e.role,content:e.text},r=rt(n),i=$e(n,r);return{kind:`group`,key:t,role:e.role,messages:[{message:n,key:t,hasVisibleContent:i===`non-text`||!!nt(n,r).trim()}],visibleContent:i,timestamp:e.at,isStreaming:!1}}function xr(e){let t=()=>e.message.question,n=()=>`${e.message.id}:${t()?.id}`;return[U(L,{get when(){return e.message.text},get children(){return U(st,{get group(){return br(e.message)},get options(){return{showReasoning:!1,showToolCalls:!1,assistantName:M(`custodian.title`),agentId:ne}}})}}),U(L,{get when(){return e.message.id===e.store().earlierBoundaryAfterId},get children(){return U(Qe,{get item(){return{kind:`divider`,key:`custodian-earlier`,label:M(`custodian.earlier`),timestamp:e.message.at}}})}}),U(L,{get when(){return V(()=>!!t())()?!e.store().dismissedQuestions.has(n()):t()},get children(){var r=Cr();return B(r,U(kn,{get props(){return{header:t().header,question:t().question,options:t().options.map(e=>({value:e.label,label:e.label,description:e.description,recommended:e.recommended})),disabled:e.actions.sending||!e.store().canSend||e.store().answeredQuestions.has(n()),onSelect:t=>e.actions.answerQuestion(e.message,t),onSkip:()=>e.actions.dismissQuestion(e.message)}}})),r}}),U(L,{get when(){return V(()=>e.message===e.activeWizardMessage)()?e.message.step:null},children:t=>(()=>{var n=Tr(),r=n.firstChild,i=r.nextSibling;return B(n,U(L,{get when(){return t().title},get children(){var e=wr();return B(e,()=>g(t().title)),e}}),r),B(n,U(Mt,{get step(){return t()},get value(){return e.store().wizardValue},get busy(){return e.actions.sending||!e.store().canSend},get inputId(){return`custodian-wizard-input-${e.message.id}`},get sensitiveRevealed(){return e.store().wizardSecretVisible},onValueChange:t=>e.store().setWizardValue(t),onAnswer:t=>e.actions.answerWizardStep(e.message,t),onToggleSensitiveVisibility:()=>e.store().toggleWizardSecretVisibility(),get leadingAction(){return V(()=>!!e.store().wizardCancelAvailable)()?(()=>{var t=Er();return t._$$click=()=>e.actions.cancelWizardStep(e.message),B(t,()=>M(`custodian.cancel`)),W(()=>e.actions.sending||!e.store().canSend,e=>{H(t,`disabled`,e)}),t})():void 0}}),i),W(()=>g(t().title??t().message,`Setup`),e=>{H(n,`aria-label`,e)}),n})()})]}function Sr(e,t){let n=ze(),r=Rn(()=>t.store),i=F(()=>A(e.store,e=>e)),a=A(vt,e=>e.alert),o=()=>i().read(),s=()=>e.actions??r.actions,c=F(()=>o().sending),l=()=>s().session.sending||c(),u=F(()=>{let e=o();return e.eventNudgePending?null:e.eventNudge}),d=F(()=>{let e=o().transcript;return(e.completion??Promise.resolve(e.status)).then(e=>{if(e.error)throw Error(e.error);return e})}),f=F(()=>(i().revision(),a.read())),p=!1;function m(){p=!1;let{store:e,onboarding:r,newAgentIntent:i}=t;e.connect(n,un(r,i))}Je(()=>(Rr.set(t,()=>{r.retire(),p||(p=!0,queueMicrotask(()=>{p&&m()}))}),m(),()=>{Rr.delete(t),p=!1,b&&ie(b),w?.dispose()}));let h=()=>(o(),wt(n)),g=()=>h()?M(`custodian.pluginPlaceholder`,{plugin:h().name}):M(`custodian.placeholder`),_=()=>o().wizardInputPending?o().messages.findLast(e=>e.step!==null):void 0,v=()=>!(!h()||o().activeVariant!==`caretaker`||o().sensitive||o().hasUnresolvedQuestion()),y=()=>v()&&!o().hasRealUserTurn(),ee=F(()=>o().messages.filter(e=>!v()||!e.optionalWelcome)),b=null,x=null,S=null,C=null,w,T=0;Ke(()=>({source:o(),alert:a.read()}),({source:e})=>{let n=t.contains(S)?S:null;b&&b!==n&&ie(b),b=n,b&&(re(b),pe(b));let r=t.contains(C)?C:null;x!==r&&(w?.dispose(),x=r,w=x?new ct(x):void 0),w?.update(!0),e.canSend&&!e.sensitive&&!e.hasUnresolvedQuestion()&&vt.askIfReady((t,n,r)=>void e.send(t,r,!1,n))}),jt(()=>({source:o(),request:Ct(n)}),{requested:({request:e})=>e>0&&e!==T,ready:({source:e})=>!e.sensitive&&!e.wizardInputPending&&e.chatAvailable,focus:({request:e})=>{T=e,t.contains(S)&&S?.focus()}});let E=!1;oe(()=>{let e=o().messages.at(-1)?.id??null;return{reveal:{identity:[e],target:()=>{if(e===null&&!E)return;E=!0;let n=t.contains(C)?C?.lastElementChild:void 0;return n instanceof HTMLElement?n:void 0}}}});let te=e=>{e.key!==`Enter`||e.shiftKey||e.isComposing||(e.preventDefault(),s().session.send())},ne=()=>U(L,{get when(){return f()},children:e=>U(Bn,{get alert(){return e()},context:n,onDismiss:()=>vt.dismiss()})}),D=()=>U(L,{get when(){return e.onboarding},get children(){return U(nr,{get store(){return o()},get actions(){return s().setup}})}}),O=e=>U(Re,{status:e,className:`custodian__transcript-status`});return U(L,{get when(){return V(()=>!o().setupRequired)()&&!o().autoSetup.blocksGreeting},get fallback(){var t=Fr(),n=t.firstChild,r=n.nextSibling,i=r.nextSibling;return B(t,D,n),B(t,ne,r),B(t,U(L,{get when(){return!o().autoSetup.blocksGreeting||o().autoSetup.dismissed},get children(){var t=Pr(),n=t.firstChild,r=n.nextSibling,i=r.nextSibling,a=i.nextSibling.firstChild;return n._$owner=R(),B(r,()=>M(`modelSetup.required.title`)),B(i,()=>M(`modelSetup.required.body`)),a._$$click=()=>o().exitSetup(`model-setup`),B(a,()=>M(`modelSetup.required.action`)),W(()=>e.compact?72:96,e=>{n.size=e}),t}}),i),W(()=>!!e.compact,e=>{t.classList.toggle(`custodian-surface--panel`,e)}),t},get children(){var t=Nr(),r=t.firstChild,i=r.firstChild,a=i.nextSibling,f=a.nextSibling,p=f.nextSibling,m=p.nextSibling,v=m.nextSibling,b=v.nextSibling,x=b.nextSibling,w=x.nextSibling,T=w.nextSibling,E=r.nextSibling,re=E.nextSibling;return r._$$click=e=>{gt(e),mt(e)},G(()=>e=>C=e,r),B(r,D,i),B(r,ne,a),B(r,()=>e.channelOnboardingContent,f),B(r,U(L,{get when(){return V(()=>!e.onboarding)()?Ge(u):null},children:e=>U(qn,{get nudge(){return e()},get disabled(){return!o().canSend||o().sensitive||o().hasUnresolvedQuestion()},onSend:()=>s().session.sendEventNudge(),onDismiss:()=>o().dismissEventNudge()})}),p),B(r,U(L,{get when(){return y()},get children(){var e=Dr(),t=e.firstChild,r=t.nextSibling;return B(t,()=>M(`custodian.pluginIntroTitle`,{plugin:h().name})),B(r,U(P,{each:[[`custodian.pluginStarterPurpose`,`custodian.pluginPromptPurpose`],[`custodian.pluginStarterTools`,`custodian.pluginPromptTools`],[`custodian.pluginStarterSetup`,`custodian.pluginPromptSetup`]],children:e=>(()=>{var t=Ir();return t._$$click=()=>{let t=h();t&&Dt(n,t)({question:M(e[1],{plugin:t.name})})},B(t,()=>M(e[0])),t})()})),e}}),m),B(r,U(P,{get each(){return ee()},keyed:e=>e.id,children:e=>U(xr,{store:o,get actions(){return s().session},get message(){return e()},get activeWizardMessage(){return _()}})}),v),B(r,U(L,{get when(){return c()},get children(){var e=Or(),t=e.firstChild,n=t.firstChild,r=t.nextSibling.firstChild.nextSibling.nextSibling.nextSibling;return n.size=26,n._$owner=R(),B(r,()=>M(`custodian.thinking`)),e}}),b),B(r,U(L,{get when(){return o().abandonedTurnOutcomeUnknown},get children(){var e=kr(),t=e.firstChild;return B(t,()=>M(`custodian.connectionChanged`)),e}}),x),B(r,U(Ye,{get on(){return o().transcript.completion},get fallback(){return O(o().transcript.status)},get children(){return U(qe,{fallback:e=>O(o().transcript.status),get children(){return O(d())}})}}),w),B(r,U(L,{get when(){return V(()=>!!o().error)()?!(o().abandonedTurnOutcomeUnknown&&o().error===M(`custodian.connectionChanged`)):o().error},get children(){var e=kr(),t=e.firstChild;return B(t,()=>o().error),B(e,U(L,{get when(){return V(()=>!!(o().activeClient&&o().chatAvailable))()?o().canRetry():o().activeClient&&o().chatAvailable},get children(){var e=Ar();return e._$$click=()=>s().session.retry(),B(e,()=>M(`common.retry`)),e}}),null),e}}),T),B(t,()=>e.historyContent,E),B(t,U(L,{get when(){return!_()},get children(){var e=Mr(),t=e.firstChild.firstChild.firstChild,n=t.firstChild,r=t.nextSibling.firstChild,i=r.firstChild;return B(t,U(L,{get when(){return o().sensitive},get fallback(){var e=Lr();return K(e,`scroll`,ge),K(e,`pointerdown`,k,!0),K(e,`wheel`,k),K(e,`blur`,k),K(e,`compositionstart`,k),K(e,`beforeinput`,k,!0),e._$$keydown=e=>{k(e),te(e)},e._$$input=e=>{k(e),o().setInput(e.currentTarget.value)},G(()=>e=>S=e,e),W(()=>({e:o().input,t:g(),a:g(),o:!o().chatAvailable}),({e:t,t:n,a:r,o:i},a)=>{e.value=t??``,n!==a?.t&&H(e,`placeholder`,n),r!==a?.a&&H(e,`aria-label`,r),i!==a?.o&&H(e,`disabled`,i)}),e},get children(){var e=jr();return e._$$keydown=te,e._$$input=e=>o().setInput(e.currentTarget.value),W(()=>({e:o().input,t:M(`custodian.sensitivePlaceholder`),a:M(`custodian.sensitivePlaceholder`),o:l()||!o().canSend}),({e:t,t:n,a:r,o:i},a)=>{e.value=t??``,n!==a?.t&&H(e,`placeholder`,n),r!==a?.a&&H(e,`aria-label`,r),i!==a?.o&&H(e,`disabled`,i)}),e}}),n),B(n,(()=>{var e=V(()=>!!o().sensitive);return()=>e()?M(`custodian.sensitivePlaceholder`):g()})()),r._$$click=()=>s().session.send(),B(r,U(N,{name:`arrowUp`}),i),B(i,()=>M(`custodian.send`)),W(()=>({e:M(`custodian.send`),t:l()||!o().input.trim()||!o().canSend}),({e,t},n)=>{e!==n?.e&&H(r,`aria-label`,e),t!==n?.t&&H(r,`disabled`,t)}),e}}),re),W(()=>({e:!!e.compact,t:!(o().messages.length!==0||o().error===null||l())}),({e,t:n},r)=>{e!==r?.e&&t.classList.toggle(`custodian-surface--panel`,e),n!==r?.t&&t.classList.toggle(`custodian-surface--empty-error`,n)}),t}})}var Cr,wr,Tr,Er,Dr,Or,kr,Ar,jr,Mr,Nr,Pr,Fr,Ir,Lr,Rr,zr;function Br(){return(Br=e((()=>{J(),z(),Ae(),tt(),ht(),pt(),In(),D(),Ce(),Nt(),Ee(),kt(),ot(),it(),at(),d(),Te(),j(),At(),De(),ae(),me(),Ue(),Ze(),et(),zn(),Wn(),_t(),Qn(),On(),yr(),Et(),pn(),Cr=Y(`<div class=custodian__option-card>`),wr=Y(`<strong class=custodian__wizard-title>`),Tr=Y(`<section class=custodian__wizard-step><!><!>`),Er=Y(`<button class="btn btn--ghost custodian__wizard-cancel"type=button>`),Dr=Y(`<div class=custodian__plugin-intro><h2></h2><div class=custodian__plugin-starters>`),Or=Y(`<div class="chat-group assistant custodian__thinking-row"role=status><div class="chat-avatar assistant custodian__mascot-avatar"aria-hidden=true><openclaw-mascot mood=thinking></openclaw-mascot></div><div class="chat-group-messages custodian__thinking"><span></span><span></span><span></span><span class=sr-only>`,1),kr=Y(`<div class=custodian__error role=alert><span>`),Ar=Y(`<button class="btn btn--sm"type=button>`),jr=Y(`<input type=password autocomplete=off>`),Mr=Y(`<div class=agent-chat__composer-shell><div class=agent-chat__input><div class=agent-chat__composer-input-row><div class=agent-chat__composer-combobox><span class=agent-chat__composer-placeholder aria-hidden=true></span></div><div class=agent-chat__composer-actions><button class=chat-send-btn type=button><span class=agent-chat__control-label>`),Nr=Y(`<section class=custodian-surface><div class=custodian__messages aria-live=polite><!><!><!><!><!><!><!><!><!><!></div><!><!>`),Pr=Y(`<div class=custodian__setup-state role=alert><openclaw-mascot mood=idle></openclaw-mascot><h2></h2><p></p><div class=custodian__setup-actions><button class="btn primary"type=button>`,1),Fr=Y(`<section class="custodian-surface custodian-surface--setup-required"><!><!><!>`),Ir=Y(`<button class=btn type=button>`),Lr=Y(`<textarea rows=1 autocomplete=on>`),Ot(),Rr=new WeakMap,zr=ve(`openclaw-custodian-surface`,Sr,{propertyChanged:(e,t)=>{(t===`store`||t===`onboarding`||t===`newAgentIntent`)&&Rr.get(e)?.()},properties:{store:{default:Dn,attribute:!1},actions:{default:void 0,attribute:!1},onboarding:{default:!1,attribute:!1},newAgentIntent:{default:!1,attribute:!1},channelOnboardingContent:{default:void 0,attribute:!1},compact:{default:!1,attribute:!1},historyContent:{default:void 0,attribute:!1}}}),q([`click`,`input`,`keydown`,`beforeinput`,`pointerdown`])})))()}export{Rn as a,Dn as c,Qn as i,On as l,Br as n,zn as o,Jn as r,Ln as s,zr as t};