UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

181 lines (180 loc) • 6.34 kB
import { c as isRecord } from "./record-coerce-TIsquoVR.mjs"; import { Fn as object, Jn as string, Lt as boolean, Nt as array, Pn as number, or as union, qn as strictObject, xn as literal } from "./schemas-BOYIvvln.mjs"; import { Buffer } from "node:buffer"; //#region src/config/zod-schema.installs.ts const InstallSourceSchema = union([ literal("npm"), literal("archive"), literal("path"), literal("clawhub"), literal("git") ]); const InstallRecordShape = { source: InstallSourceSchema, spec: string().optional(), sourcePath: string().optional(), installPath: string().optional(), version: string().optional(), resolvedName: string().optional(), resolvedVersion: string().optional(), resolvedSpec: string().optional(), integrity: string().optional(), shasum: string().optional(), resolvedAt: string().optional(), installedAt: string().optional(), clawhubUrl: string().optional(), clawhubPackage: string().optional(), clawhubFamily: union([literal("code-plugin"), literal("bundle-plugin")]).optional(), clawhubChannel: union([ literal("official"), literal("community"), literal("private") ]).optional(), clawhubTrustDisposition: union([ literal("clean"), literal("review-recommended"), literal("review-required"), literal("blocked") ]).optional(), clawhubTrustScanStatus: string().optional(), clawhubTrustModerationState: string().optional(), clawhubTrustReasons: array(string()).optional(), clawhubTrustPending: boolean().optional(), clawhubTrustStale: boolean().optional(), clawhubTrustCheckedAt: string().optional(), clawhubTrustAcknowledgedAt: string().optional(), artifactKind: union([literal("legacy-zip"), literal("npm-pack")]).optional(), artifactFormat: union([literal("zip"), literal("tgz")]).optional(), npmIntegrity: string().optional(), npmShasum: string().optional(), npmTarballName: string().optional(), clawpackSha256: string().optional(), clawpackSpecVersion: number().int().nonnegative().optional(), clawpackManifestSha256: string().optional(), clawpackSize: number().int().nonnegative().optional(), gitUrl: string().optional(), gitRef: string().optional(), gitCommit: string().optional() }; object(InstallRecordShape); //#endregion //#region src/config/plugin-install-record-map.ts const PluginInstallRecordSchema = object({ ...InstallRecordShape, source: union([InstallSourceSchema, literal("marketplace")]), marketplaceName: string().optional(), marketplaceSource: string().optional(), marketplacePlugin: string().optional(), acceptedSurface: strictObject({ channels: array(string().min(1)), providers: array(string().min(1)), tools: array(string().min(1)), contracts: array(string().min(1)), hooks: array(string().min(1)), mcpServers: array(string().min(1)), cliCommands: array(string().min(1)), cliBackends: array(string().min(1)), skills: array(string().min(1)), dangerousConfigFlags: array(string().min(1)) }).optional(), acceptedSurfaceHash: string().optional(), acceptedSurfaceAt: string().optional(), acceptedSurfaceIntegrity: string().optional() }).passthrough(); const NORMALIZED_STRING_FIELDS = [ "spec", "sourcePath", "installPath", "version", "resolvedName", "resolvedVersion", "resolvedSpec", "integrity", "shasum", "resolvedAt", "installedAt", "clawhubUrl", "clawhubPackage", "clawhubTrustScanStatus", "clawhubTrustModerationState", "clawhubTrustCheckedAt", "clawhubTrustAcknowledgedAt", "npmIntegrity", "npmShasum", "npmTarballName", "clawpackSha256", "clawpackManifestSha256", "gitUrl", "gitRef", "gitCommit", "marketplaceName", "marketplaceSource", "marketplacePlugin", "acceptedSurfaceHash", "acceptedSurfaceAt", "acceptedSurfaceIntegrity" ]; function createPluginInstallRecordMap() { return Object.create(null); } function setPluginInstallRecordMapEntry(records, pluginId, record) { Object.defineProperty(records, pluginId, { configurable: true, enumerable: true, value: record, writable: true }); } function getPluginInstallRecordMapEntry(records, pluginId) { return records && Object.hasOwn(records, pluginId) ? records[pluginId] : void 0; } function copyPluginInstallRecordMap(records) { const copied = createPluginInstallRecordMap(); for (const [pluginId, record] of Object.entries(records ?? {})) setPluginInstallRecordMapEntry(copied, pluginId, record); return copied; } function parsePluginInstallRecord(value) { const parsed = PluginInstallRecordSchema.safeParse(value); if (!parsed.success) return null; const record = parsed.data; for (const field of NORMALIZED_STRING_FIELDS) { const fieldValue = record[field]; if (fieldValue === void 0) continue; const normalized = fieldValue.trim(); if (normalized) record[field] = normalized; else delete record[field]; } if (record.clawhubTrustReasons) { const reasons = record.clawhubTrustReasons.map((entry) => entry.trim()).filter(Boolean); if (reasons.length > 0) record.clawhubTrustReasons = reasons; else delete record.clawhubTrustReasons; } return record; } function parsePluginInstallRecordMap(value) { if (!isRecord(value)) return null; const records = createPluginInstallRecordMap(); for (const [pluginId, rawRecord] of Object.entries(value)) { const record = parsePluginInstallRecord(rawRecord); if (!record) return null; setPluginInstallRecordMapEntry(records, pluginId, record); } return records; } function inspectPluginInstallRecordMap(value) { if (value === void 0) return { status: "missing" }; const records = parsePluginInstallRecordMap(value); return records ? { status: "valid", records } : { status: "invalid" }; } /** * Object enumeration reorders integer-index keys, so persisted bytes must be * assembled from sorted entries instead of relying on object insertion order. */ function serializePluginInstallRecordMap(records) { return `{${Object.entries(records).toSorted(([left], [right]) => Buffer.compare(Buffer.from(left), Buffer.from(right))).map(([pluginId, record]) => `${JSON.stringify(pluginId)}:${JSON.stringify(record)}`).join(",")}}`; } //#endregion export { parsePluginInstallRecord as a, setPluginInstallRecordMapEntry as c, inspectPluginInstallRecordMap as i, createPluginInstallRecordMap as n, parsePluginInstallRecordMap as o, getPluginInstallRecordMapEntry as r, serializePluginInstallRecordMap as s, copyPluginInstallRecordMap as t };