UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

206 lines (205 loc) • 7.79 kB
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { i as executeSqliteQuerySync, s as getNodeSqliteKysely } from "./kysely-sync-YJo2lmGV.mjs"; import { a as tableExists } from "./openclaw-state-db-schema-helpers-nImZNMq_.mjs"; import { Fn as object, Jn as string, Lt as boolean, Nt as array, Pn as number, Un as record, or as union, qn as strictObject, xn as literal } from "./schemas-Cy6abvsu.mjs"; import { d as withExistingOpenClawStateDatabaseArtifactPreservingReadOnly, m as withExistingOpenClawStateDatabaseReadOnly } from "./openclaw-state-db-readonly-B6YHb1oF.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); const StrictPluginInstallRecordSchema = object({ ...InstallRecordShape, source: union([InstallSourceSchema, literal("marketplace")]), /** Retained package child-plugin engine ownership for uninstall without runtime files. */ contextEngineIdsByPlugin: record(string().min(1), array(string().min(1))).optional(), 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() }); //#endregion //#region src/config/plugin-install-record-map.ts const PluginInstallRecordSchema = StrictPluginInstallRecordSchema.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(e, t, n) { Object.defineProperty(e, t, { configurable: true, enumerable: true, value: n, writable: true }); } function getPluginInstallRecordMapEntry(e, t) { return e && Object.hasOwn(e, t) ? e[t] : void 0; } function copyPluginInstallRecordMap(e) { const t = createPluginInstallRecordMap(); for (const [n, r] of Object.entries(e ?? {})) setPluginInstallRecordMapEntry(t, n, r); return t; } function parsePluginInstallRecord(e) { const t = PluginInstallRecordSchema.safeParse(e); if (!t.success) return null; const n = t.data; for (const e of NORMALIZED_STRING_FIELDS) { const t = n[e]; if (t === void 0) continue; const r = t.trim(); if (r) n[e] = r; else delete n[e]; } if (n.clawhubTrustReasons) { const e = n.clawhubTrustReasons.map((e) => e.trim()).filter(Boolean); if (e.length > 0) n.clawhubTrustReasons = e; else delete n.clawhubTrustReasons; } return n; } function parsePluginInstallRecordMap(e) { if (!isRecord(e)) return null; const t = createPluginInstallRecordMap(); for (const [n, r] of Object.entries(e)) { const e = parsePluginInstallRecord(r); if (!e) return null; setPluginInstallRecordMapEntry(t, n, e); } return t; } function inspectPluginInstallRecordMap(e) { if (e === void 0) return { status: "missing" }; const t = parsePluginInstallRecordMap(e); return t ? { status: "valid", records: t } : { 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(e) { return `{${Object.entries(e).toSorted(([e], [t]) => Buffer.compare(Buffer.from(e), Buffer.from(t))).map(([e, t]) => `${JSON.stringify(e)}:${JSON.stringify(t)}`).join(",")}}`; } //#endregion //#region src/plugins/plugin-metadata-state.kernel.ts const INSTALLED_PLUGIN_INDEX_STATE_KEY = "plugins.installedIndex"; function readPluginMetadataStateRowsInDatabase(e, t) { if (!tableExists(e, "config_machine_state")) return []; return executeSqliteQuerySync(e, getNodeSqliteKysely(e).selectFrom("config_machine_state").select(["state_key", "value_json"]).where("state_key", "in", t)).rows; } //#endregion //#region src/plugins/installed-plugin-index-row.ts /** Shared inspection commands use the same existing-only, artifact-preserving reader. */ function readPluginMetadataStateRowSync(e, t, n = false) { const r = readPluginMetadataStateRowsSync([e === "installed-index" ? INSTALLED_PLUGIN_INDEX_STATE_KEY : "plugins.bundledDiscovery"], t, n)[0]; return r ? { value_json: r.value_json } : void 0; } /** Acquire related metadata facts from the same prepared database bytes. */ function readPluginMetadataStateRowsSync(e, t, n = false) { const read = ({ db: t }) => readPluginMetadataStateRowsInDatabase(t, e); return (n ? withExistingOpenClawStateDatabaseArtifactPreservingReadOnly(read, t) : withExistingOpenClawStateDatabaseReadOnly(read, t)) ?? []; } //#endregion export { createPluginInstallRecordMap as a, parsePluginInstallRecordMap as c, copyPluginInstallRecordMap as i, serializePluginInstallRecordMap as l, readPluginMetadataStateRowsSync as n, getPluginInstallRecordMapEntry as o, INSTALLED_PLUGIN_INDEX_STATE_KEY as r, inspectPluginInstallRecordMap as s, readPluginMetadataStateRowSync as t, setPluginInstallRecordMapEntry as u };