UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

46 lines (45 loc) • 1.9 kB
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; //#region src/cron/store/delivery-codec.ts /** JSON codec for cron delivery configuration and explicit destination clears. */ const FAILURE_DESTINATION_FIELDS = [ "channel", "to", "accountId", "mode" ]; const CRON_DELIVERY_REPAIR_REQUIRED_MESSAGE = "cron delivery requires an explicit mode: \"none\", \"announce\", or \"webhook\"; run openclaw doctor --fix for legacy settings or explicitly edit delivery.mode"; function hasCanonicalCronDeliveryMode(e) { return e === void 0 || isRecord(e) && (e.mode === "none" || e.mode === "announce" || e.mode === "webhook"); } /** Unrepaired definitions remain readable; execution and authored writes require a mode. */ function assertCanonicalCronDeliveryMode(e) { if (!hasCanonicalCronDeliveryMode(e)) throw new Error(CRON_DELIVERY_REPAIR_REQUIRED_MESSAGE); } /** Encodes explicitly undefined failure overrides as durable JSON null values. */ function deliveryToJson(e) { const t = e.failureDestination; if (!t) return { ...e }; return { ...e, failureDestination: Object.fromEntries(FAILURE_DESTINATION_FIELDS.filter((e) => Object.hasOwn(t, e)).map((e) => [e, t[e] ?? null])) }; } /** Restores JSON null overrides as present-but-undefined runtime properties. */ function deliveryFromJson(e) { if (!isRecord(e) || !hasCanonicalCronDeliveryMode(e)) return; const t = e.failureDestination; if (!isRecord(t)) return e; return { ...e, failureDestination: Object.fromEntries(FAILURE_DESTINATION_FIELDS.filter((e) => Object.hasOwn(t, e)).map((e) => [e, t[e] ?? void 0])) }; } function decodeCronJobConfig(e) { const t = deliveryFromJson(e.delivery); return t ? { ...e, delivery: t } : e; } //#endregion export { hasCanonicalCronDeliveryMode as a, deliveryToJson as i, assertCanonicalCronDeliveryMode as n, decodeCronJobConfig as r, CRON_DELIVERY_REPAIR_REQUIRED_MESSAGE as t };