UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

44 lines (43 loc) 2.17 kB
import { c as isRecord } from "./record-coerce-DItp3I4t.js"; import { n as createMergePatch, t as applyMergePatch } from "./merge-patch-DCMj2JVh.js"; import { l as getRuntimeConfigSourceSnapshot, o as getRuntimeConfigSnapshot } from "./runtime-snapshot-BaQikjTR.js"; //#region src/config/runtime-source-projection.ts function projectSourceOntoRuntimeShape(source, runtime) { if (!isRecord(source) || !isRecord(runtime)) return structuredClone(source); const next = {}; for (const [key, sourceValue] of Object.entries(source)) { if (!(key in runtime)) { next[key] = structuredClone(sourceValue); continue; } next[key] = projectSourceOntoRuntimeShape(sourceValue, runtime[key]); } return next; } function isCompatibleTopLevelRuntimeProjectionShape(params) { const runtime = params.runtimeSnapshot; const candidate = params.candidate; for (const key of Object.keys(runtime)) { if (!Object.hasOwn(candidate, key)) return false; const runtimeValue = runtime[key]; const candidateValue = candidate[key]; if ((Array.isArray(runtimeValue) ? "array" : runtimeValue === null ? "null" : typeof runtimeValue) !== (Array.isArray(candidateValue) ? "array" : candidateValue === null ? "null" : typeof candidateValue)) return false; } return true; } /** Projects a runtime-derived config back onto the active authored source snapshot. */ function projectConfigOntoRuntimeSourceSnapshot(config) { const runtimeConfigSnapshot = getRuntimeConfigSnapshot(); const runtimeConfigSourceSnapshot = getRuntimeConfigSourceSnapshot(); if (!runtimeConfigSnapshot || !runtimeConfigSourceSnapshot) return config; if (config === runtimeConfigSnapshot) return runtimeConfigSourceSnapshot; if (!isCompatibleTopLevelRuntimeProjectionShape({ runtimeSnapshot: runtimeConfigSnapshot, candidate: config })) return config; const projectedSource = projectSourceOntoRuntimeShape(runtimeConfigSourceSnapshot, runtimeConfigSnapshot); const runtimePatch = createMergePatch(runtimeConfigSnapshot, config); return applyMergePatch(projectedSource, runtimePatch); } //#endregion export { projectSourceOntoRuntimeShape as n, projectConfigOntoRuntimeSourceSnapshot as t };