UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.69 kB
import{l as trackAsyncWork}from"./async-work-scope-DBcxYU4O.mjs";import{O as runWithRetainedGatewayRootWork}from"./gateway-work-admission-CnMW3_qr.mjs";import{i as buildRequestedApprovalEvent,s as handlePendingApprovalRequest}from"./approval-shared-D5K52j8A.mjs"; //!src/gateway/server-methods/approval-request-delivery.ts function handlePendingApprovalRequestWithDelivery(e){const{approvalKind:t,source:n,forwardRequest:r,getIosPushDelivery:i,afterDecision:a,afterDecisionErrorLabel:o,...s}=e;const c=buildRequestedApprovalEvent(s.record,t);const l=i();const u=l?.handleRequested?.bind(l);const d=n===`node-policy`?`node policy `:``;const f=`${t} approvals:`;return handlePendingApprovalRequest({...s,approvalKind:t,requestEventName:`${t}.approval.requested`,requestEvent:c,deliverRequest:()=>{const e=[];const startDelivery=(t,n)=>{e.push(trackAsyncWork(()=>runWithRetainedGatewayRootWork(t)).catch(e=>{s.context.logGateway?.error?.(`${n}: ${String(e)}`);return false}))};if(r)startDelivery(()=>r(c),`${f} forward ${d}request failed`);if(u)startDelivery(()=>u(s.record),`${f} iOS push ${d}request failed`);try{const e=s.context.approvalWebPushDelivery?.handleRequested(s.record);if(e!==false&&e!==void 0)startDelivery(()=>Promise.resolve(e),`approval Web Push request failed`)}catch(e){s.context.logGateway?.error?.(`approval Web Push request failed: ${String(e)}`)}if(e.length===0)return false;return new Promise(t=>{let n=e.length;for(const r of e)r.then(e=>{n-=1;if(e||n===0)t(e)})})},afterDecision:async e=>{if(e===null)await i()?.handleExpired?.(c);await a?.(e,c)},afterDecisionErrorLabel:o??`${f} iOS push ${d}expire failed`})}export{handlePendingApprovalRequestWithDelivery as t};