openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 4.08 kB
JavaScript
import{c as normalizeOptionalLowercaseString,d as normalizeOptionalThreadValue,l as normalizeOptionalString,u as normalizeOptionalStringifiedId}from"./string-coerce-CpTFcSwY.mjs";import{n as normalizeMessageChannel}from"./message-channel-core-D_hPOadj.mjs";import{t as resolveTargetPrefixedChannel}from"./channel-target-prefix-CDxsZqXF.mjs";import{a as hasCanonicalCronDeliveryMode}from"./delivery-codec-rJfKfjDT.mjs";import{i as resolveCronDeliveryMode,n as resolveCronDefaultDeliveryDestination,t as cronDeliveryUsesDefaultDestination}from"./delivery-defaults-V0xnKB36.mjs";
//!src/cron/delivery-plan.ts
function resolveAnnounceChannel(e){if(e.channel&&e.channel!==`last`)return e.channel;return resolveTargetPrefixedChannel(e.to)??e.channel??`last`}function resolveCronDeliveryPlan(e,t){const n=e.delivery;const r=resolveCronDeliveryMode(e);const i=resolveCronDefaultDeliveryDestination(t);if(i&&cronDeliveryUsesDefaultDestination(e,r)){const e=normalizeOptionalString(i.to);return{mode:`announce`,directPolicy:n?.directPolicy,channel:resolveAnnounceChannel({channel:normalizeMessageChannel(i.channel),to:e}),to:e,threadId:normalizeOptionalThreadValue(i.threadId),accountId:normalizeOptionalString(i.accountId),source:`delivery`,requested:true}}const a=normalizeMessageChannel(n?.channel);const o=normalizeOptionalString(n?.to);const s=normalizeOptionalThreadValue(n?.threadId);const c=normalizeOptionalString(n?.accountId);if(n){const e=r===`announce`?resolveAnnounceChannel({channel:a,to:o}):a;return{mode:r,target:n.target,directPolicy:n.directPolicy,channel:r===`webhook`?void 0:e,to:o,threadId:r===`webhook`?void 0:s,accountId:c,source:`delivery`,requested:r===`announce`}}return{mode:r,channel:r===`announce`?`last`:void 0,to:void 0,threadId:void 0,source:`delivery`,requested:r===`announce`}}function normalizeFailureMode(e){const t=normalizeOptionalLowercaseString(e);if(t===`announce`||t===`webhook`)return t}function resolveFailureDestination(e,t,n){const r=e.delivery;const i=r?.failureDestination;let a;let o;let s;let c;let l;if(t){a=normalizeMessageChannel(t.channel);o=normalizeOptionalString(t.to);l=normalizeOptionalThreadValue(t.threadId);s=normalizeOptionalString(t.accountId);c=normalizeFailureMode(t.mode)}for(const e of[i,n]){if(!e||typeof e!==`object`)continue;const t=normalizeOptionalString(e.to);const n=normalizeMessageChannel(e.channel)??(t?resolveTargetPrefixedChannel(t):void 0);const r=normalizeOptionalString(e.accountId);const i=normalizeFailureMode(e.mode);const u=Object.hasOwn(e,`channel`);const d=Object.hasOwn(e,`to`);const f=Object.hasOwn(e,`accountId`);const p=Object.hasOwn(e,`mode`);const m=Object.hasOwn(e,`threadId`);const h=f&&r!==s||d&&t!==o||n!==void 0&&n!==resolveAnnounceChannel({channel:a,to:o});if(m)l=normalizeOptionalThreadValue(e.threadId);else if(h)l=void 0;const g=d&&t!==void 0;const _=resolveAnnounceChannel({channel:a,to:o});if(u||n&&t){a=n;if(n&&n!==_){if(!d)o=void 0;if(!f)s=void 0}}if(d)o=t;if(f)s=r;const v=!p&&n!==void 0;if(p||v){const e=v?`announce`:i;if((c??`announce`)!==(e??`announce`)){if(!m)l=void 0;if(!u)a=void 0;if(!g)o=void 0;if(!f)s=void 0}c=e}}const u=n?.mode!==void 0&&n.channel===void 0&&n.to===void 0&&n.accountId===void 0&&n.threadId===void 0;if(!a&&!o&&!s&&l===void 0&&(!c||u))return null;const d=c??`announce`;if(d===`webhook`&&!o)return null;const f={mode:d,channel:d===`announce`?resolveAnnounceChannel({channel:a,to:o}):void 0,...d===`announce`&&l!==void 0?{threadId:l}:{},to:o,accountId:s};if(r&&isSameDeliveryTarget(r,f))return null;return f}function isSameDeliveryTarget(e,t){const n=e.mode;if(!hasCanonicalCronDeliveryMode(e)||n===`none`)return false;const r=normalizeOptionalString(e.to);const i=normalizeOptionalString(e.accountId);const a=normalizeOptionalStringifiedId(e.threadId);if(t.mode===`webhook`)return n===`webhook`&&r===t.to;const o=resolveAnnounceChannel({channel:normalizeMessageChannel(e.channel),to:r});return(t.channel??`last`)===o&&t.to===r&&t.accountId===i&&normalizeOptionalStringifiedId(t.threadId)===a}export{resolveFailureDestination as n,resolveCronDeliveryPlan as t};