UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

76 lines (75 loc) • 2.8 kB
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { o as openRootFileSync, r as isRootFileMissingFailure } from "./boundary-file-read-BfaFLDqt.mjs"; import { i as INCLUDE_KEY, s as isInternalIncludeWriteTarget } from "./includes-wjVi5Ymt.mjs"; import "./utils-C8YECn2Q.mjs"; import { r as resolveIncludeWriteBoundary } from "./include-write-boundary-Dpj_7ftL.mjs"; import fs from "node:fs"; import path from "node:path"; //#region src/commands/doctor/shared/include-migration-ownership.ts function containsAuthoredInclude(e) { if (Array.isArray(e)) return e.some(containsAuthoredInclude); if (!isRecord(e)) return false; return Object.hasOwn(e, "$include") || Object.values(e).some(containsAuthoredInclude); } /** Classify whether Doctor can safely persist a migration at one resolved config path. */ function classifyConfigPathMigrationOwnership(e) { const t = (e.snapshot.includeProvenance ?? []).filter((t) => t.path.length <= e.configPath.length && t.path.every((t, n) => t === e.configPath[n])); if (t.length === 0) return { kind: "direct" }; const n = [...new Set(t.flatMap((e) => e.targetPaths ?? (e.targetPath ? [e.targetPath] : [])))].toSorted(); const r = resolveIncludeWriteBoundary({ provenance: e.snapshot.includeProvenance, changed: { paths: [e.configPath], rootChanged: false } }); if (r && isInternalIncludeWriteTarget({ configPath: e.snapshot.path, includePath: r.includePath })) return { kind: "single-include", targetPath: r.includePath }; return { kind: "manual", targetPaths: n }; } function readOtelProtocol(e) { const t = isRecord(e) ? e : null; const n = isRecord(t?.diagnostics) ? t.diagnostics : null; return (isRecord(n?.otel) ? n.otel : null)?.protocol; } /** Classify ownership for the sole legacy migration that consults resolved config values. */ function classifyOtelGrpcMigrationOwnership(e) { if (readOtelProtocol(e.resolvedConfig) !== "grpc") return null; const t = classifyConfigPathMigrationOwnership({ snapshot: e.snapshot, configPath: [ "diagnostics", "otel", "protocol" ] }); if (t.kind !== "direct") return t; return readOtelProtocol(e.authoredConfig) === "grpc" ? t : { kind: "resolved-only" }; } /** Read historical config evidence without following a backup outside its directory. */ function readDoctorConfigBackup(e) { const t = openRootFileSync({ absolutePath: e, rootPath: path.dirname(e), boundaryLabel: "config backup directory" }); if (!t.ok) { if (isRootFileMissingFailure(t)) return; throw new Error("Config backup could not be read safely"); } try { return fs.readFileSync(t.fd, "utf8"); } finally { fs.closeSync(t.fd); } } //#endregion export { containsAuthoredInclude as n, readDoctorConfigBackup as r, classifyOtelGrpcMigrationOwnership as t };