UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

68 lines (67 loc) • 2.05 kB
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { t as parseJsonWithJson5Fallback } from "./parse-json-compat-DoWUfD79.mjs"; import { a as createConfigIncludeResolutionSession, c as readConfigIncludeFileWithGuards, i as INCLUDE_KEY } from "./includes-wjVi5Ymt.mjs"; import { x as resolveIncludeRoots } from "./paths-DAcAg5aV.mjs"; import { n as visitConfigValueTree } from "./value-tree-Deh4eoFD.mjs"; import fs from "node:fs"; import path from "node:path"; //#region 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; } /** Collects recursively referenced config include files without requiring a valid full config. */ 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]; } //#endregion export { collectIncludePathsRecursive as t };