import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{er as t}from"./control-ui-foundation-CeFMP1Ly.js";import{fl as n,fs as r,ml as i,ms as a,vr as o,yr as s}from"./control-ui-core-pH6nakZ-.js";import{G as c,J as l,W as u,Z as d,rt as f}from"./lit-runtime-BEtFSUCp.js";import{Cn as p,D as m,Jt as h,O as g,Yt as _,ln as v,m as y,p as b}from"./control-ui-core-DGVkFhVB.js";import{Gt as x,Ht as S,qt as C}from"./control-ui-core-Br5DB0Zj.js";import{In as w,Ln as T}from"./control-ui-boot-wpHCbPL9.js";import{cn as E,hn as D,mn as O,on as k}from"./control-ui-boot-Cdpgu1Gm.js";import{r as A,t as j}from"./approval-result-validators-Bwny6Cwa.js";import{n as M,t as N}from"./settings-workspace-Bo4nqRhI.js";function P(e,t){if(e.revokedAtMs!==null)return C(`standingGrants.stateRevoked`);if(e.expiresAtMs!==null&&e.expiresAtMs<=t)return C(`standingGrants.stateExpired`);if(e.expiresAtMs!==null){let n=Math.max(1,Math.ceil((e.expiresAtMs-t)/864e5));return C(`standingGrants.stateExpiresIn`,{count:String(n)})}return C(`standingGrants.stateUntilRevoked`)}function F(e,t){return e.revokedAtMs===null&&(e.expiresAtMs===null||e.expiresAtMs>t)}function I(e){return new Intl.DateTimeFormat(x.getLocale(),{dateStyle:`medium`,timeStyle:`short`}).format(new Date(e))}function L(e){switch(e){case`exec`:return C(`approvalHistory.kinds.exec`);case`plugin`:return C(`approvalHistory.kinds.plugin`);case`system-agent`:return C(`approvalHistory.kinds.systemAgent`)}return e}function R(e){switch(e){case`allowed`:return C(`approvalHistory.statuses.allowed`);case`denied`:return C(`approvalHistory.statuses.denied`);case`expired`:return C(`approvalHistory.statuses.expired`);case`cancelled`:return C(`approvalHistory.statuses.cancelled`)}return e}function z(e){switch(e){case`allow-once`:return C(`approvalHistory.decisions.allowOnce`);case`allow-always`:return C(`approvalHistory.decisions.allowAlways`);case`deny`:return C(`approvalHistory.decisions.deny`);case void 0:return C(`approvalHistory.notApplicable`)}return e}function B(e){switch(e){case`user`:return C(`approvalHistory.reasons.user`);case`timeout`:return C(`approvalHistory.reasons.timeout`);case`malformed-verdict`:return C(`approvalHistory.reasons.malformedVerdict`);case`no-route`:return C(`approvalHistory.reasons.noRoute`);case`run-aborted`:return C(`approvalHistory.reasons.runAborted`);case`gateway-restart`:return C(`approvalHistory.reasons.gatewayRestart`);case`storage-corrupt`:return C(`approvalHistory.reasons.storageCorrupt`)}return e}function V(e){let t=e.presentation;return(t.kind===`exec`?t.commandText:t.title)||C(`approvalHistory.unknown`)}function H(e){let t=[e.source?.agentId,e.source?.sessionKey].filter(e=>!!e);return t.length>0?t.join(` · `):C(`approvalHistory.unknown`)}function U(e){return e.resolver?e.resolver.id?`${e.resolver.kind} · ${e.resolver.id}`:e.resolver.kind:C(`approvalHistory.unknown`)}var W,G,K,q;function J(){return(J=e((()=>{T(),u(),d(),j(),v(),y(),m(),h(),k(),N(),S(),a(),i(),s(),W=50,G=`operator.approvals`,K=`https://docs.openclaw.ai/tools/exec-approvals`,q=class extends n{constructor(...e){super(...e),this.items=[],this.grants=[],this.grantsError=null,this.revokingGrantId=null,this.nextCursor=null,this.loading=!1,this.loadingMore=!1,this.error=null,this.connected=!1,this.approvalsAccess=!0,this.client=null,this.gatewaySource=null,this.requestGeneration=0,this.hasLoaded=!1,this.historyRefreshPending=!1,this.subscriptions=new o(this).effect(()=>this.context?.gateway,e=>{this.gatewaySource!==e&&this.resetHistory(!0),this.gatewaySource=e,this.applyGatewaySnapshot(e.snapshot);let t=e.subscribe(t=>{this.gatewaySource===e&&this.context.gateway===e&&this.applyGatewaySnapshot(t)}),n=e.subscribeEvents(t=>{this.gatewaySource!==e||this.context.gateway!==e||!this.approvalsAccess||!_(e.snapshot).canReviewApprovals||!g(t.event,t.payload)||(this.historyRefreshPending=!0,!this.loading&&!this.loadingMore&&this.loadPage(!0))});return()=>{t(),n()}})}disconnectedCallback(){this.subscriptions.clear(),this.resetHistory(!1),this.gatewaySource=null,super.disconnectedCallback()}resetHistory(e){this.requestGeneration+=1,this.loading=!1,this.loadingMore=!1,this.historyRefreshPending=!1,e&&(this.hasLoaded=!1,this.items=[],this.nextCursor=null,this.error=null)}applyGatewaySnapshot(e){let t=e.client!==this.client,n=e.phase===`connected`!==this.connected,r=_(e).canReviewApprovals,i=r!==this.approvalsAccess;this.connected=e.phase===`connected`,this.approvalsAccess=r,t||i?(this.client=e.client,this.resetHistory(!0)):n&&(this.resetHistory(!1),e.phase===`connected`&&(this.hasLoaded=!1)),e.phase===`connected`&&e.client&&this.approvalsAccess&&!this.hasLoaded&&!this.loading&&this.loadPage(!0)}async loadPage(e){let t=this.client,n=this.gatewaySource;if(!t||!n||!this.connected||!this.approvalsAccess||!_(n.snapshot).canReviewApprovals||this.loading||this.loadingMore)return;let i=this.requestGeneration,a=e?void 0:this.nextCursor??void 0;if(!e&&!a)return;e?(this.historyRefreshPending=!1,this.loading=!0):this.loadingMore=!0,this.error=null;let o=()=>this.isConnected&&this.connected&&this.approvalsAccess&&this.gatewaySource===n&&this.context.gateway===n&&n.snapshot.phase===`connected`&&_(n.snapshot).canReviewApprovals&&this.client===t&&this.requestGeneration===i;try{let n=await t.request(`approval.history`,{...a?{cursor:a}:{},limit:W});if(!A(n))throw Error(C(`approvalHistory.invalidResponse`));if(!o())return;this.items=e?n.items:[...this.items,...n.items],this.nextCursor=n.nextCursor??null,this.hasLoaded=!0,e&&this.loadGrants(t,o)}catch(e){o()&&(this.error=r(e),this.hasLoaded=!0)}finally{o()&&(this.loading=!1,this.loadingMore=!1,this.historyRefreshPending&&this.loadPage(!0))}}async loadGrants(e,t){try{let n=await e.request(`exec.approval.grants.list`,{});if(!t())return;this.grants=Array.isArray(n.grants)?n.grants:[],this.grantsError=null}catch(e){t()&&(this.grantsError=r(e))}}async revokeGrant(e){let t=this.client;if(!(!t||this.revokingGrantId!==null)){this.revokingGrantId=e;try{await t.request(`exec.approval.grants.revoke`,{grantId:e});let n=Date.now();this.grants=this.grants.map(t=>t.grantId===e?{...t,revokedAtMs:n}:t),this.grantsError=null}catch(e){this.grantsError=r(e)}finally{this.revokingGrantId=null}}}renderGrants(){let e=Date.now();return l`

${C(`standingGrants.title`)}

${C(`standingGrants.description`)}

${this.grantsError?l`
${this.grantsError}
`:c}
${this.grants.length===0?l` `:this.grants.map(t=>l` `)}
${C(`standingGrants.columns.automation`)} ${C(`standingGrants.columns.command`)} ${C(`standingGrants.columns.uses`)} ${C(`standingGrants.columns.state`)}
${C(`standingGrants.empty`)}
${t.cronJobName??t.cronJobId} ${t.command} ${t.useCount} ${P(t,e)} ${F(t,e)?l` `:c}
`}renderTable(){return l`
${this.items.length===0?l` `:this.items.map(e=>l` `)}
${C(`approvalHistory.columns.resolved`)} ${C(`approvalHistory.columns.kind`)} ${C(`approvalHistory.columns.request`)} ${C(`approvalHistory.columns.decision`)} ${C(`approvalHistory.columns.reason`)} ${C(`approvalHistory.columns.source`)} ${C(`approvalHistory.columns.resolver`)}
${this.loading?C(`approvalHistory.loading`):this.error||!this.hasLoaded?C(`approvalHistory.unknown`):C(`approvalHistory.empty`)}
${I(e.resolvedAtMs)} ${L(e.presentation.kind)} ${V(e)} ${R(e.status)} · ${z(`decision`in e?e.decision:void 0)} ${B(e.reason)} ${H(e)} ${U(e)}
${C(`approvalHistory.retention`)}
${this.nextCursor?l` `:c}
`}render(){let e=O(l` ${this.connected?c:l`
${C(`approvalHistory.offline`)}
`} ${this.connected&&!this.approvalsAccess?l`
${C(`common.disabled`)} · ${G}
`:c} ${this.approvalsAccess&&this.error?l`
${this.error}
`:c} ${this.approvalsAccess?this.renderGrants():c} ${this.approvalsAccess?l`

${C(`standingGrants.historyTitle`)}

`:c} ${this.approvalsAccess?this.renderTable():c} `,{wide:!0});return l` ${D({title:p(`approvals`),subtitle:l`${C(`approvalHistory.description`)} ${E(K)}`})} ${M(e)} `}},t([w({context:b,subscribe:!0})],q.prototype,`context`,void 0),t([f()],q.prototype,`items`,void 0),t([f()],q.prototype,`grants`,void 0),t([f()],q.prototype,`grantsError`,void 0),t([f()],q.prototype,`revokingGrantId`,void 0),t([f()],q.prototype,`nextCursor`,void 0),t([f()],q.prototype,`loading`,void 0),t([f()],q.prototype,`loadingMore`,void 0),t([f()],q.prototype,`error`,void 0),t([f()],q.prototype,`connected`,void 0),t([f()],q.prototype,`approvalsAccess`,void 0),customElements.get(`openclaw-approvals-page`)||customElements.define(`openclaw-approvals-page`,q)})))()}J(); //# sourceMappingURL=approvals-page-CJH3_AOL.js.map