UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

55 lines (54 loc) • 1.87 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { t as compareOpenClawVersions } from "./version-DkjdPwZ3.mjs"; import { valid } from "semver"; //#region src/plugins/min-host-version.ts /** Validation message for plugin minHostVersion manifest fields. */ const MIN_HOST_VERSION_FORMAT = "openclaw.install.minHostVersion must use a semver floor in the form \">=x.y.z[-prerelease][+build]\""; const SEMVER_LABEL_RE = String.raw`\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?`; const MIN_HOST_VERSION_RE = new RegExp(`^>=(${SEMVER_LABEL_RE})$`); const LEGACY_MIN_HOST_VERSION_RE = new RegExp(`^(${SEMVER_LABEL_RE})$`); /** Parses a plugin minHostVersion manifest field. */ function parseMinHostVersionRequirement(e, t = {}) { const n = normalizeOptionalString(e); if (!n) return null; const r = n.match(MIN_HOST_VERSION_RE) ?? (t.allowLegacyBareSemver ? n.match(LEGACY_MIN_HOST_VERSION_RE) : null); if (!r) return null; const i = r[1] ?? ""; if (!valid(i)) return null; return { raw: n, minimumLabel: i }; } /** Checks whether the current host satisfies a plugin minHostVersion requirement. */ function checkMinHostVersion(e) { if (e.minHostVersion === void 0) return { ok: true, requirement: null }; const t = parseMinHostVersionRequirement(e.minHostVersion, { allowLegacyBareSemver: e.allowLegacyBareSemver }); if (!t) return { ok: false, kind: "invalid", error: MIN_HOST_VERSION_FORMAT }; const n = normalizeOptionalString(e.currentVersion) || "unknown"; const r = compareOpenClawVersions(n, t.minimumLabel); if (r === null) return { ok: false, kind: "unknown_host_version", requirement: t }; if (r < 0) return { ok: false, kind: "incompatible", requirement: t, currentVersion: n }; return { ok: true, requirement: t }; } //#endregion export { checkMinHostVersion as t };