openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.52 kB
JavaScript
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{t as parseJsonWithJson5Fallback}from"./parse-json-compat-BEbcOl-a.mjs";import{a as createConfigIncludeResolutionSession,c as readConfigIncludeFileWithGuards,i as INCLUDE_KEY}from"./includes-gwK90iIZ.mjs";import{x as resolveIncludeRoots}from"./paths-D_FOvGon.mjs";import{n as visitConfigValueTree}from"./value-tree-BXoqoxTN.mjs";import fs from"node:fs";import path from"node:path";
//!src/config/includes-scan.ts
function listDirectIncludes(e){const t=[];visitConfigValueTree(e,e=>{const n=isRecord(e)?e[INCLUDE_KEY]:void 0;if(typeof n===`string`)t.push(n);else if(Array.isArray(n)){for(const e of n)if(typeof e===`string`)t.push(e)}return true});return t}async function collectIncludePathsRecursive(e){const t=/* @__PURE__ */ new Set;const n=/* @__PURE__ */ new Map;const r=resolveIncludeRoots(e.env);const i=createConfigIncludeResolutionSession(e.configPath,r);const walk=(e,r,a)=>{if(a>=10)return;for(const o of listDirectIncludes(r)){let r;let s;const c={readFile:e=>fs.readFileSync(e,`utf-8`),readFileWithGuards:e=>{return readConfigIncludeFileWithGuards({...e,onResolvedPath:i=>{t.add(i);const o=path.normalize(e.resolvedPath);const s=a+1;const c=n.get(o);if(c!==void 0&&c<=s)return;n.set(o,s);r=o}})},parseJson:e=>{const t=parseJsonWithJson5Fallback(e);if(r)s={basePath:r,parsed:t};return{}}};try{i({[INCLUDE_KEY]:o},e,c)}catch{}if(s)walk(s.basePath,s.parsed,a+1)}};walk(e.configPath,e.parsed,0);return[...t]}export{collectIncludePathsRecursive as t};