openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
107 lines (106 loc) • 4.44 kB
JavaScript
import { g as readStringValue, h as readNonEmptyStringPreservingWhitespace, l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { o as normalizeCsvOrLooseStringList } from "./string-normalization-DLmfYZXI.mjs";
import { u as validateRegistryNpmSpec } from "./npm-registry-spec-HKkAvl6N.mjs";
import { r as parseFrontmatterBlockResult } from "./frontmatter-CLR6jwh6.mjs";
import { a as resolveOpenClawManifestBlock, c as resolveOpenClawManifestRequires, i as parseOpenClawManifestInstallBase, n as getFrontmatterString, o as resolveOpenClawManifestInstall, r as parseFrontmatterBool, s as resolveOpenClawManifestOs, t as applyOpenClawManifestInstallCommonFields } from "./frontmatter-DZeA7qC4.mjs";
//#region src/skills/loading/frontmatter.ts
function parseSkillFrontmatter(e) {
const t = parseFrontmatterBlockResult(e);
const n = t.issues[0];
if (n) throw new Error(`invalid frontmatter: ${n.code}: ${n.message}`);
return structuredClone(t.frontmatter);
}
const BREW_FORMULA_PATTERN = /^[A-Za-z0-9][A-Za-z0-9@+._/-]*$/;
const GO_MODULE_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._~+\-/]*(?:@[A-Za-z0-9][A-Za-z0-9._~+\-/]*)?$/;
const UV_PACKAGE_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._\-[\]=<>!~+,]*$/;
function normalizeSafeBrewFormula(e) {
const t = normalizeOptionalString(e);
return t && BREW_FORMULA_PATTERN.test(t) && !t.includes("..") ? t : void 0;
}
function normalizeSafeNpmSpec(e) {
const t = normalizeOptionalString(e);
if (!t || t.startsWith("-")) return;
if (validateRegistryNpmSpec(t) !== null) return;
return t;
}
function normalizeSafePackageSpec(e, t) {
const n = normalizeOptionalString(e);
return n && t.test(n) ? n : void 0;
}
function normalizeSafeDownloadUrl(e) {
const t = normalizeOptionalString(e);
if (!t || /\s/.test(t)) return;
const n = URL.parse(t);
return n?.protocol === "http:" || n?.protocol === "https:" ? n.toString() : void 0;
}
function parseInstallSpec(e) {
const t = parseOpenClawManifestInstallBase(e, [
"brew",
"node",
"go",
"uv",
"download"
]);
if (!t) return;
const { raw: n } = t;
const r = applyOpenClawManifestInstallCommonFields({ kind: t.kind }, t);
const i = normalizeCsvOrLooseStringList(n.os);
const a = normalizeSafeBrewFormula(n.formula) ?? normalizeSafeBrewFormula(n.cask);
const o = r.kind === "node" ? normalizeSafeNpmSpec(n.package) : r.kind === "uv" ? normalizeSafePackageSpec(n.package, UV_PACKAGE_PATTERN) : void 0;
const s = normalizeSafePackageSpec(n.module, GO_MODULE_PATTERN);
const c = normalizeSafeDownloadUrl(n.url);
let l;
if (r.kind === "download" && n.sha256 !== void 0) {
if (typeof n.sha256 !== "string") return;
l = n.sha256.trim().toLowerCase();
if (!/^[a-f0-9]{64}$/u.test(l)) return;
}
const u = {
...r,
...i.length > 0 ? { os: i } : {},
...a ? { formula: a } : {},
...o ? { package: o } : {},
...s ? { module: s } : {},
...c ? { url: c } : {},
...l ? { sha256: l } : {},
...typeof n.archive === "string" ? { archive: n.archive } : {},
...typeof n.extract === "boolean" ? { extract: n.extract } : {},
...typeof n.stripComponents === "number" ? { stripComponents: n.stripComponents } : {},
...typeof n.targetDir === "string" ? { targetDir: n.targetDir } : {}
};
return {
brew: u.formula,
node: u.package,
go: u.module,
uv: u.package,
download: u.url
}[u.kind] ? u : void 0;
}
function resolveSkillManifestMetadata(e) {
const t = resolveOpenClawManifestBlock({ frontmatter: e });
if (!t) return;
const n = resolveOpenClawManifestRequires(t);
const r = resolveOpenClawManifestInstall(t, parseInstallSpec);
const i = resolveOpenClawManifestOs(t);
return {
always: typeof t.always === "boolean" ? t.always : void 0,
emoji: readStringValue(t.emoji),
homepage: readStringValue(t.homepage),
skillKey: readNonEmptyStringPreservingWhitespace(t.skillKey),
primaryEnv: readStringValue(t.primaryEnv),
os: i.length > 0 ? i : void 0,
requires: n,
install: r.length > 0 ? r : void 0
};
}
function resolveSkillInvocationPolicy(e) {
return {
userInvocable: parseFrontmatterBool(getFrontmatterString(e, "user-invocable"), true),
disableModelInvocation: parseFrontmatterBool(getFrontmatterString(e, "disable-model-invocation"), false)
};
}
function resolveSkillKey(e) {
return e.metadata?.skillKey ?? e.skill.name;
}
//#endregion
export { resolveSkillManifestMetadata as i, resolveSkillInvocationPolicy as n, resolveSkillKey as r, parseSkillFrontmatter as t };