import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{er as t}from"./control-ui-foundation-CeFMP1Ly.js";import{Gn as n,Hn as r,b as i,fl as a,ml as o,vr as s,w as c,yr as l}from"./control-ui-core-pH6nakZ-.js";import{G as u,J as d,W as f,Z as p,at as m,rt as h}from"./lit-runtime-BEtFSUCp.js";import{m as g,p as _}from"./control-ui-core-DGVkFhVB.js";import{Ht as v,kt as y,qt as b}from"./control-ui-core-Br5DB0Zj.js";import{In as x,Ln as S}from"./control-ui-boot-wpHCbPL9.js";import{a as C,r as w}from"./gateway-runtime-DUNO4Mi1.js";import{i as T,r as E,t as D}from"./custodian-surface-BijreBg_.js";function O(e){switch(e){case`system-agent`:return b(`custodian.history.sources.systemAgent`);case`doctor`:return b(`custodian.history.sources.doctor`);case`config-rpc`:return b(`custodian.history.sources.settings`);case`external`:return b(`custodian.history.sources.manualEdit`);case`cli`:return b(`custodian.history.sources.cli`);case`plugin-install`:return b(`custodian.history.sources.pluginInstall`);case`unknown`:return b(`custodian.history.sources.unknown`)}return e}function k(e){return d`
${O(e.source)}
${e.summary}
${e.invalid?d`
${b(`custodian.history.invalidEdit`)}
`:u} ${e.opaqueChange?d`
${b(`custodian.history.opaqueChange`)}
`:u} ${e.changedPaths?.length?d`
${b(`custodian.history.changedPaths`,{count:String(e.changedPaths.length)})}
`:u}
`}function A(e){return d`
${b(`custodian.history.title`)} ${b(`custodian.history.description`)}
${e.error?d``:u}
${e.entries.map(k)} ${e.loading?d`
${b(`custodian.history.loading`)}
`:e.loaded&&e.entries.length===0&&!e.error?d`
${b(`custodian.history.empty`)}
`:u}
${e.nextCursor?d``:u}
`}function j(){return(j=e((()=>{f(),v(),c()})))()}var M,N;function P(){return(P=e((()=>{S(),f(),p(),g(),y(),v(),n(),w(),o(),l(),j(),T(),D(),M=50,N=class extends a{constructor(...e){super(...e),this.onboarding=!1,this.newAgentIntent=!1,this.store=E,this.historyAvailable=!1,this.historyOpen=!1,this.historyEntries=[],this.historyNextCursor=null,this.historyLoading=!1,this.historyLoadingMore=!1,this.historyError=null,this.historyLoaded=!1,this.historyClient=null,this.historyRequestEpoch=0,this.subscribedStore=null,this.storeCleanup=null,this.channelsSource=null,this.subscriptions=new s(this).effect(()=>this.context?.channels,e=>{this.channelsSource=e;let t=e.subscribe(()=>{this.ensureOnboardingChannelStatus(),this.requestUpdate()});return this.ensureOnboardingChannelStatus(),()=>{t(),this.channelsSource===e&&(this.channelsSource=null)}})}connectedCallback(){super.connectedCallback(),this.subscribeToStore()}disconnectedCallback(){this.storeCleanup?.(),this.storeCleanup=null,this.subscribedStore=null,this.subscriptions.clear(),super.disconnectedCallback()}async getUpdateComplete(){let e=await super.getUpdateComplete();return await this.querySelector(`openclaw-custodian-surface`)?.updateComplete,e}willUpdate(e){e.has(`store`)&&this.subscribeToStore(),this.synchronizeHistoryClient(),this.ensureOnboardingChannelStatus()}ensureOnboardingChannelStatus(){let e=this.channelsSource;if(!this.onboarding||this.store.channelOnboardingNudgeClosed||!e)return;let t=e.state;!t.connected||t.channelsSnapshot||t.channelsLoading||t.channelsError||e.refresh(!1)}subscribeToStore(){!this.isConnected||this.subscribedStore===this.store||(this.storeCleanup?.(),this.subscribedStore=this.store,this.storeCleanup=this.store.subscribe(()=>this.requestUpdate()),this.store.refreshTranscriptIfIdle())}synchronizeHistoryClient(){let e=this.context.gateway.snapshot,t=e.phase===`connected`?e.client:null,n=t!==null&&C(e,`openclaw.changes.list`)===!0;(t!==this.historyClient||n!==this.historyAvailable)&&(this.historyClient=t,this.historyAvailable=n,this.historyOpen=!1,this.resetHistory())}resetHistory(){this.historyRequestEpoch+=1,this.historyEntries=[],this.historyNextCursor=null,this.historyLoading=!1,this.historyLoadingMore=!1,this.historyError=null,this.historyLoaded=!1}toggleHistory(){this.historyOpen=!this.historyOpen,this.historyOpen&&!this.historyLoading&&!this.historyLoadingMore&&this.loadHistory(!0)}async loadHistory(e){let t=this.historyClient,n=e?void 0:this.historyNextCursor??void 0;if(!t||!this.historyAvailable||this.historyLoading||this.historyLoadingMore||!e&&!n)return;let r=++this.historyRequestEpoch;e?this.historyLoading=!0:this.historyLoadingMore=!0,this.historyError=null;let i=()=>this.isConnected&&this.historyClient===t&&this.historyRequestEpoch===r&&this.historyAvailable;try{let r=await t.request(`openclaw.changes.list`,{limit:M,...n?{beforeCursor:n}:{}});if(!i())return;this.historyEntries=e?r.entries:[...this.historyEntries,...r.entries],this.historyNextCursor=r.nextCursor??null,this.historyLoaded=!0}catch{i()&&(this.historyError=b(`custodian.history.requestFailed`),this.historyLoaded=!0)}finally{i()&&(this.historyLoading=!1,this.historyLoadingMore=!1)}}render(){let e=this.channelsSource?.state,t=e?.channelsSnapshot??null,n=this.onboarding&&!this.store.channelOnboardingNudgeClosed&&e?.connected?e?.channelsError??null:null,i=this.onboarding&&!this.store.channelOnboardingNudgeClosed&&e?.connected&&!e.channelsLoading&&n===null&&t!==null&&t.partial!==!0&&!r(t),a=this.historyOpen&&this.historyAvailable?A({entries:this.historyEntries,error:this.historyError,loaded:this.historyLoaded,loading:this.historyLoading,loadingMore:this.historyLoadingMore,nextCursor:this.historyNextCursor,onLoad:e=>void this.loadHistory(e)}):u;return d`
${this.onboarding?u:d`

${b(`custodian.title`)}

${b(`custodian.subtitleCaretaker`)}

`}
${this.historyAvailable?d``:u} ${this.onboarding?d``:u}
void this.channelsSource?.refresh(!1)} .historyContent=${a} >
`}},t([x({context:_,subscribe:!0})],N.prototype,`context`,void 0),t([m({attribute:!1})],N.prototype,`onboarding`,void 0),t([m({attribute:!1})],N.prototype,`newAgentIntent`,void 0),t([m({attribute:!1})],N.prototype,`store`,void 0),t([h()],N.prototype,`historyAvailable`,void 0),t([h()],N.prototype,`historyOpen`,void 0),t([h()],N.prototype,`historyEntries`,void 0),t([h()],N.prototype,`historyNextCursor`,void 0),t([h()],N.prototype,`historyLoading`,void 0),t([h()],N.prototype,`historyLoadingMore`,void 0),t([h()],N.prototype,`historyError`,void 0),customElements.get(`openclaw-custodian-page`)||customElements.define(`openclaw-custodian-page`,N)})))()}P(); //# sourceMappingURL=custodian-page-CTJKnlcU.js.map