openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
70 lines (69 loc) • 2.72 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { n as normalizeClawHubSha256Integrity } from "./clawhub-integrity-DTNmm7ZL.mjs";
import { M as parseClawHubPluginSpec, j as normalizePluginInstallDefaultChoice } from "./official-external-plugin-catalog-DtkWz1Xo.mjs";
import { i as isExactSemverVersion, s as parseRegistryNpmSpec } from "./npm-registry-spec-HKkAvl6N.mjs";
//#region src/plugins/install-source-info.ts
/** Describes package-authored plugin install source metadata and pinning warnings. */
function normalizeExpectedPackageName(e) {
const t = normalizeOptionalString(e);
if (!t) return;
return parseRegistryNpmSpec(t)?.name ?? t;
}
/** Describes plugin install source metadata and warnings without mutating manifests. */
function describePluginInstallSource(e, t) {
const n = normalizeOptionalString(e.clawhubSpec);
const r = normalizeOptionalString(e.npmSpec);
const i = normalizeOptionalString(e.localPath);
const a = normalizePluginInstallDefaultChoice(e.defaultChoice);
const o = normalizeOptionalString(e.expectedIntegrity);
const s = normalizeExpectedPackageName(t?.expectedPackageName);
const c = [];
let l;
let u;
if (e.defaultChoice !== void 0 && !a) c.push("invalid-default-choice");
if (n) {
const e = parseClawHubPluginSpec(n);
if (e) {
const t = e.version ? isExactSemverVersion(e.version) : false;
if (!t) c.push("clawhub-spec-floating");
l = {
spec: n,
packageName: e.name,
...e.version ? { version: e.version } : {},
exactVersion: t
};
} else c.push("invalid-clawhub-spec");
}
if (r) {
const e = parseRegistryNpmSpec(r);
if (e) {
const t = e.selectorKind === "exact-version";
const n = Boolean(o);
if (!t) c.push("npm-spec-floating");
if (!n) c.push("npm-spec-missing-integrity");
if (s && e.name !== s) c.push("npm-spec-package-name-mismatch");
u = {
spec: e.raw,
packageName: e.name,
...s && e.name !== s ? { expectedPackageName: s } : {},
selectorKind: e.selectorKind,
exactVersion: t,
pinState: `${t ? "exact" : "floating"}-${n ? "with" : "without"}-integrity`,
...e.selector ? { selector: e.selector } : {},
...o ? { expectedIntegrity: o } : {}
};
} else c.push("invalid-npm-spec");
}
if (a === "clawhub" && !l || a === "npm" && !u || a === "local" && !i) c.push("default-choice-missing-source");
const d = !r && l && o && normalizeClawHubSha256Integrity(o);
if (o && !u && !d) c.push("npm-integrity-without-source");
return {
...a ? { defaultChoice: a } : {},
...l ? { clawhub: l } : {},
...u ? { npm: u } : {},
...i ? { local: { path: i } } : {},
warnings: c
};
}
//#endregion
export { describePluginInstallSource as t };