UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

30 lines (29 loc) • 1.18 kB
import { t as isPlainObject } from "./plain-object-CGY5w7fM.mjs"; import { t as isBlockedObjectKey } from "./prototype-keys-CLGi5xDj.mjs"; //#region src/infra/deep-merge.ts function sanitizePlainObject(e) { const t = {}; for (const [n, r] of Object.entries(e)) { if (isBlockedObjectKey(n)) continue; t[n] = isPlainObject(r) ? sanitizePlainObject(r) : r; } return t; } /** Merge plain objects while preserving OpenClaw's null, undefined, and array policies. */ function mergeDeep(e, t, n = {}) { const r = n.arrays ?? "replace"; const i = n.undefinedValues ?? "skip"; if (Array.isArray(e) && Array.isArray(t)) return r === "concat" ? [...e, ...t] : t; if (!isPlainObject(e) || !isPlainObject(t)) return t === void 0 && i === "skip" ? e : t; const a = sanitizePlainObject(e); for (const [e, o] of Object.entries(t)) { if (isBlockedObjectKey(e) || o === void 0 && i === "skip") continue; const t = a[e]; if (isPlainObject(o)) a[e] = isPlainObject(t) ? mergeDeep(t, o, n) : sanitizePlainObject(o); else if (r === "concat" && Array.isArray(t) && Array.isArray(o)) a[e] = [...t, ...o]; else a[e] = o; } return a; } //#endregion export { mergeDeep as t };