UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

62 lines (61 loc) • 2.53 kB
import { l as trackAsyncWork } from "./async-work-scope-BXagjUap.mjs"; import { n as GATEWAY_CLIENT_IDS } from "./client-info-Cm1BcrMm.mjs"; import { O as runWithRetainedGatewayRootWork } from "./gateway-work-admission-79pid1hQ.mjs"; import { i as buildRequestedApprovalEvent, s as handlePendingApprovalRequest } from "./approval-shared-C8HrUVTB.mjs"; import { n as isApprovalRecordVisibleToClient } from "./approval-record-lookup-mkMfll81.mjs"; //#region src/gateway/server-methods/approval-request-delivery.ts /** Request producers share delivery and expiry handling while retaining their typed payloads. */ 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 isTargetVisible = (e) => isApprovalRecordVisibleToClient({ record: s.record, client: { connect: { client: { id: GATEWAY_CLIENT_IDS.IOS_APP }, device: { id: e.deviceId }, scopes: [...e.scopes] } } }); 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(c, { isTargetVisible }), `${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` }); } //#endregion export { handlePendingApprovalRequestWithDelivery as t };