openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
77 lines (76 loc) • 3.29 kB
JavaScript
import { c as normalizeOptionalLowercaseString, g as readStringValue } from "./string-coerce-CCIiB4H7.mjs";
import { n as parseBooleanValue } from "./boolean-2vRuVafy.mjs";
import { i as asOptionalObjectRecord } from "./record-coerce-CVPuDqcc.mjs";
import { o as normalizeCsvOrLooseStringList } from "./string-normalization-DLmfYZXI.mjs";
import { t as parseJsonWithJson5Fallback } from "./parse-json-compat-DoWUfD79.mjs";
import { t as MANIFEST_KEY } from "./legacy-names-Cq8ruaO5.mjs";
import JSON5 from "json5";
//#region src/shared/frontmatter.ts
/** Reads a frontmatter field only when it is represented as a string value. */
function getFrontmatterString(e, t) {
return readStringValue(e[t]);
}
/** Parses boolean frontmatter strings while preserving the caller's default for missing values. */
function parseFrontmatterBool(e, t) {
const n = parseBooleanValue(e);
return n === void 0 ? t : n;
}
/** Parses the JSON5 OpenClaw manifest block embedded inside a string frontmatter field. */
function resolveOpenClawManifestBlock(e) {
const t = getFrontmatterString(e.frontmatter, "metadata");
if (!t) return;
try {
const e = asOptionalObjectRecord(parseJsonWithJson5Fallback(t, JSON5));
if (!e) return;
return asOptionalObjectRecord(e[MANIFEST_KEY]);
} catch {
return;
}
}
/** Extracts normalized runtime requirement lists from an OpenClaw manifest block. */
function resolveOpenClawManifestRequires(e) {
const t = asOptionalObjectRecord(e.requires);
if (!t) return;
return {
bins: normalizeCsvOrLooseStringList(t.bins),
anyBins: normalizeCsvOrLooseStringList(t.anyBins),
env: normalizeCsvOrLooseStringList(t.env),
config: normalizeCsvOrLooseStringList(t.config)
};
}
/** Parses manifest install entries with a caller-owned parser and drops unsupported specs. */
function resolveOpenClawManifestInstall(e, t) {
return (Array.isArray(e.install) ? e.install : []).map((e) => t(e)).filter((e) => Boolean(e));
}
/** Extracts normalized OS allowlist entries from an OpenClaw manifest block. */
function resolveOpenClawManifestOs(e) {
return normalizeCsvOrLooseStringList(e.os);
}
/** Parses kind/type plus common install fields shared by package-manager install specs. */
function parseOpenClawManifestInstallBase(e, t) {
const n = asOptionalObjectRecord(e);
if (!n) return;
const r = typeof n.kind === "string" ? n.kind : typeof n.type === "string" ? n.type : "";
const i = normalizeOptionalLowercaseString(r) ?? "";
if (!t.includes(i)) return;
const a = {
...typeof n.id === "string" ? { id: n.id } : {},
...typeof n.label === "string" ? { label: n.label } : {}
};
const o = normalizeCsvOrLooseStringList(n.bins);
return {
raw: n,
kind: i,
...a,
...o.length > 0 ? { bins: o } : {}
};
}
/** Copies optional common install fields onto a caller-specific install spec object. */
function applyOpenClawManifestInstallCommonFields(e, t) {
if (t.id) e.id = t.id;
if (t.label) e.label = t.label;
if (t.bins) e.bins = t.bins;
return e;
}
//#endregion
export { resolveOpenClawManifestBlock as a, resolveOpenClawManifestRequires as c, parseOpenClawManifestInstallBase as i, getFrontmatterString as n, resolveOpenClawManifestInstall as o, parseFrontmatterBool as r, resolveOpenClawManifestOs as s, applyOpenClawManifestInstallCommonFields as t };