refactor(core): dedupe shared config and runtime helpers

This commit is contained in:
Peter Steinberger
2026-02-16 14:52:03 +00:00
parent 544ffbcf7b
commit 04892ee230
68 changed files with 1966 additions and 2018 deletions

View File

@@ -97,3 +97,43 @@ export function resolveOpenClawManifestInstall<T>(
export function resolveOpenClawManifestOs(metadataObj: Record<string, unknown>): string[] {
return normalizeStringList(metadataObj.os);
}
export type ParsedOpenClawManifestInstallBase = {
raw: Record<string, unknown>;
kind: string;
id?: string;
label?: string;
bins?: string[];
};
export function parseOpenClawManifestInstallBase(
input: unknown,
allowedKinds: readonly string[],
): ParsedOpenClawManifestInstallBase | undefined {
if (!input || typeof input !== "object") {
return undefined;
}
const raw = input as Record<string, unknown>;
const kindRaw =
typeof raw.kind === "string" ? raw.kind : typeof raw.type === "string" ? raw.type : "";
const kind = kindRaw.trim().toLowerCase();
if (!allowedKinds.includes(kind)) {
return undefined;
}
const spec: ParsedOpenClawManifestInstallBase = {
raw,
kind,
};
if (typeof raw.id === "string") {
spec.id = raw.id;
}
if (typeof raw.label === "string") {
spec.label = raw.label;
}
const bins = normalizeStringList(raw.bins);
if (bins.length > 0) {
spec.bins = bins;
}
return spec;
}