openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
54 lines (53 loc) • 2.52 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { n as formatConcreteConfigPath } from "./dot-path-BJ4tyWKJ.mjs";
import { n as sanitizeTerminalText } from "./safe-text-C80HAQ2e.mjs";
//#region src/config/issue-format.ts
/** Return the public config issue shape with a normalized path and non-empty allowed values. */
function normalizeConfigIssue(e) {
const t = Array.isArray(e.allowedValues) && e.allowedValues.length > 0;
const n = {
path: normalizeOptionalString(e.path) ?? "<root>",
message: e.message,
...t ? { allowedValues: e.allowedValues } : {},
...t && typeof e.allowedValuesHiddenCount === "number" && e.allowedValuesHiddenCount > 0 ? { allowedValuesHiddenCount: e.allowedValuesHiddenCount } : {}
};
if (e.pathSegments) Object.defineProperty(n, "pathSegments", {
value: e.pathSegments,
enumerable: false
});
return n;
}
/** Normalize a batch of config validation issues for display or JSON output. */
function normalizeConfigIssues(e) {
return e.map((e) => normalizeConfigIssue(e));
}
function resolveIssueLocationPrefix(e, t) {
const n = normalizeOptionalString(e.sourceFile) ?? normalizeOptionalString(t?.sourceFile);
if (!n || typeof e.line !== "number" || e.line <= 0) return "";
return `${sanitizeTerminalText(n)}:${e.line} — `;
}
/**
* Format one config issue for terminal output.
* Path and message are sanitized because issues can include user-edited config text.
*/
function formatConfigIssueLine(e, t = "-", n) {
const r = t ? `${t} ` : "";
const i = resolveIssueLocationPrefix(e, n);
const a = e.pathSegments?.length ? formatConcreteConfigPath(e.pathSegments) : e.path;
return `${r}${i}${sanitizeTerminalText(n?.normalizeRoot ? normalizeOptionalString(a) ?? "<root>" : typeof a === "string" ? a : "")}: ${sanitizeTerminalText(e.message)}`;
}
/** Format config issues as terminal-safe lines with a shared marker prefix. */
function formatConfigIssueLines(e, t = "-", n) {
return e.map((e) => formatConfigIssueLine(e, t, n));
}
/** Build a compact, terminal-safe issue summary for logs and recovery diagnostics. */
function formatConfigIssueSummary(e) {
if (e.length === 0) return null;
const t = e.slice(0, 5);
const n = formatConfigIssueLines(t, "", { normalizeRoot: true });
const r = e.length - t.length;
if (r <= 0) return n.join("; ");
return `${n.join("; ")}; and ${r} more`;
}
//#endregion
export { normalizeConfigIssues as i, formatConfigIssueLines as n, formatConfigIssueSummary as r, formatConfigIssueLine as t };