openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.57 kB
JavaScript
import"./src-0ci69Prg.mjs";import{t as expectDefined}from"./expect-DkJCbmLj.mjs";import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import"./utils-Dlk0IYAa.mjs";import{t as resolvePathViaExistingAncestorSync}from"./boundary-path-BeuXNL_4.mjs";import{i as INCLUDE_KEY,s as isInternalIncludeWriteTarget}from"./includes-gwK90iIZ.mjs";import path from"node:path";import{isDeepStrictEqual}from"node:util";
//!src/config/include-write-boundary.ts
function collectInto(e,t,n,r){if(isDeepStrictEqual(e,t))return;if(!isRecord(e)||!isRecord(t)){r.push([...n]);return}for(const i of/* @__PURE__ */ new Set([...Object.keys(e),...Object.keys(t)]))collectInto(Object.hasOwn(e,i)?e[i]:void 0,Object.hasOwn(t,i)?t[i]:void 0,[...n,i],r)}function collectChangedConfigPaths(e,t){const n=[];collectInto(e,t,[],n);const r=n.some(e=>e.length===0);return{paths:r?[]:n,rootChanged:r}}function getLegacyTopLevelIncludeBoundary(e){if(!isRecord(e.snapshot.parsed)||e.changed.rootChanged)return null;const t=new Set(e.changed.paths.map(e=>e[0]).filter(e=>e!==void 0));if(t.size!==1)return null;const n=expectDefined([...t][0],`changed top-level key at 0`);const r=e.snapshot.parsed[n];if(!isRecord(r))return null;const i=r[INCLUDE_KEY];if(Object.keys(r).length!==1||typeof i!==`string`)return null;const a=path.dirname(e.snapshot.path);return{boundaryPath:[n],includePath:path.normalize(path.isAbsolute(i)?i:path.resolve(a,i))}}function isPathPrefix(e,t){return e.length<=t.length&&e.every((e,n)=>e===t[n])}function pathsEqual(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function pathTouchesAgentRoster(e){return[[`agents`,`entries`],[`agents`,`list`]].some(t=>isPathPrefix(e,t)||isPathPrefix(t,e))}function isKeyedAgentEntryPath(e){return e.length===3&&e[0]===`agents`&&e[1]===`entries`}function isSoleOwner(e){return e.kind===`single`&&!e.hasSiblingOverrides}function resolveIncludeWriteBoundary(e){const t=e.provenance;if(!t||e.changed.rootChanged||e.changed.paths.length===0)return null;if(t.some(e=>e.path.length===0))return null;const n=t.flatMap(e=>e.targetPaths??(e.targetPath?[e.targetPath]:[]));const r=new Map([...new Set(n)].map(e=>[e,resolvePathViaExistingAncestorSync(e)]));let i=null;for(const n of t){if(!isSoleOwner(n)||!n.targetPath||n.hasArrayAncestor)continue;if(t.some(e=>e!==n&&e.path.length<=n.path.length&&isPathPrefix(e.path,n.path)&&!isSoleOwner(e)))continue;if(t.some(e=>e!==n&&e.path.length>n.path.length&&isPathPrefix(n.path,e.path)))continue;if(!e.changed.paths.every(e=>isPathPrefix(n.path,e)))continue;const a=r.get(n.targetPath);if(t.some(e=>!pathsEqual(e.path,n.path)&&(e.targetPaths??(e.targetPath?[e.targetPath]:[])).some(e=>r.get(e)===a)))continue;if(n.path.length>(i?.boundaryPath.length??0))i={boundaryPath:n.path,includePath:n.targetPath}}return i}function resolveKeyedAgentEntryIncludePreservation(e){const t=e.provenance;if(!t)return null;const n=t.filter(e=>pathTouchesAgentRoster(e.path));if(n.length===0||n.some(e=>!isKeyedAgentEntryPath(e.path)))return null;const r=[];for(const i of n){if(n.filter(e=>pathsEqual(e.path,i.path)).length!==1)return null;const a=resolveIncludeWriteBoundary({provenance:t,changed:{paths:[[...i.path,`$value`]],rootChanged:false}});if(!a||!pathsEqual(a.boundaryPath,i.path)||a.includePath!==i.targetPath||!isInternalIncludeWriteTarget({configPath:e.configPath,includePath:a.includePath}))return null;r.push([...i.path])}return{includePaths:r}}export{resolveKeyedAgentEntryIncludePreservation as i,getLegacyTopLevelIncludeBoundary as n,resolveIncludeWriteBoundary as r,collectChangedConfigPaths as t};