openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.8 kB
JavaScript
import{t as isBlockedObjectKey}from"./prototype-keys-Dc7Yq32J.mjs";import"./utils-Dlk0IYAa.mjs";import{t as isPlainObject}from"./plain-object-CHrMoU5Q.mjs";import{t as normalizeConfigModelSelectionParent}from"./model-input-normalization-CChsFZq0.mjs";
//!src/config/config-paths.ts
function setOwnConfigProperty(e,t,n){if(Object.hasOwn(e,t)){e[t]=n;return}Object.defineProperty(e,t,{configurable:true,enumerable:true,value:n,writable:true})}function parseConfigPath(e){const t=e.trim().split(`.`).map(e=>e.trim());if(t.some(e=>!e))return{ok:false,error:`Invalid path. Use dot notation (e.g. foo.bar).`};if(t.some(e=>isBlockedObjectKey(e)))return{ok:false,error:`Invalid path segment.`};return{ok:true,path:t}}function setConfigValueAtPath(e,t,n){const r=t.at(-1);if(r===void 0)throw new Error(`Config path must contain at least one segment`);let i=e;for(const[e,n]of t.slice(0,-1).entries()){const r=Object.hasOwn(i,n)?i[n]:void 0;const a=isPlainObject(r)?r:normalizeConfigModelSelectionParent(r,t,e)??{};if(a!==r)setOwnConfigProperty(i,n,a);i=a}setOwnConfigProperty(i,r,n)}function unsetConfigValueAtPath(e,t,n){const r=t.at(-1);if(r===void 0)return false;const i=[];let a=e;for(const e of t.slice(0,-1)){if(!Object.hasOwn(a,e))return false;const t=a[e];if(!isPlainObject(t))return false;i.push({node:a,key:e});a=t}if(!Object.hasOwn(a,r))return false;delete a[r];for(const{node:e,key:r}of i.toReversed()){const a=e[r];if(isPlainObject(a)&&Object.keys(a).length===0&&(!n||getConfigValueAtPath(n,t.slice(0,i.length))===void 0)){delete e[r];i.pop()}else break}return true}function getConfigValueAtPath(e,t){let n=e;for(const e of t){if(!isPlainObject(n)||!Object.hasOwn(n,e))return;n=n[e]}return n}export{unsetConfigValueAtPath as i,parseConfigPath as n,setConfigValueAtPath as r,getConfigValueAtPath as t};