UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

121 lines (120 loc) • 4.35 kB
import { c as resolveUserPath } from "./home-dir-EKmgmdPG.mjs"; import "./utils-C8YECn2Q.mjs"; import { i as copyPluginInstallRecordMap, o as getPluginInstallRecordMapEntry, u as setPluginInstallRecordMapEntry } from "./installed-plugin-index-row-CdwQuK63.mjs"; import { s as parseRegistryNpmSpec } from "./npm-registry-spec-HKkAvl6N.mjs"; import "./installed-plugin-index-record-reader-B-7uGQZ9.mjs"; import { i as refreshPersistedInstalledPluginIndexWithReceipt } from "./installed-plugin-index-store-write-D9fWnpon.mjs"; //#region src/plugins/installs.ts function configReferencesNpmInstallPath(e) { const t = e.install?.installPath; if (e.install?.source !== "npm" || !t) return false; const n = resolveUserPath(t, e.env); return Boolean(e.config.plugins?.load?.paths?.some((t) => resolveUserPath(t, e.env) === n)); } function reconcileNpmPluginLoadPath(e) { const t = e.previousInstall?.installPath; const n = e.nextInstall.installPath; if (e.previousInstall?.source !== "npm" || e.nextInstall.source !== "npm" || !t || !n) return e.config; const r = resolveUserPath(t); const i = resolveUserPath(n); const a = e.config.plugins?.load?.paths; if (r === i || !a?.length) return e.config; const o = a.findIndex((e) => resolveUserPath(e) === r); if (o < 0) return e.config; const s = a.findIndex((e) => resolveUserPath(e) === i); const c = a.flatMap((e, t) => { const a = resolveUserPath(e); if (s >= 0) { if (a === r || a === i && t !== s) return []; return [e]; } if (t === o) return [n]; return a === r ? [] : [e]; }); return { ...e.config, plugins: { ...e.config.plugins, load: { ...e.config.plugins?.load, paths: c } } }; } function resolveNpmInstallRecordSpec(e) { const t = e.resolution?.resolvedSpec; return e.pinResolvedRegistrySpec && t && parseRegistryNpmSpec(t)?.selectorKind === "exact-version" ? t : e.requestedSpec; } function recordPluginInstallInRecords(e, t) { const { pluginId: n, ...r } = t; const i = copyPluginInstallRecordMap(e); setPluginInstallRecordMapEntry(i, n, { ...r, installedAt: r.installedAt ?? (/* @__PURE__ */ new Date()).toISOString() }); return i; } /** Replaces a plugin install record with the authoritative completed install. */ function recordPluginInstall(e, t) { return reconcileNpmPluginLoadPath({ config: { ...e, plugins: { ...e.plugins, installs: recordPluginInstallInRecords(e.plugins?.installs, t) } }, previousInstall: getPluginInstallRecordMapEntry(e.plugins?.installs, t.pluginId), nextInstall: t }); } //#endregion //#region src/plugins/installed-plugin-index-records.ts /** Builds and compares installed plugin index records for refresh decisions. */ /** Config path for legacy plugin install records kept for migration/doctor flows. */ const PLUGIN_INSTALLS_CONFIG_PATH = ["plugins", "installs"]; /** Refresh persisted install records while holding the plugin lifecycle lease. */ async function writePersistedInstalledPluginIndexInstallRecordsWithLease(e, t) { const { index: n, ...r } = await refreshPersistedInstalledPluginIndexWithReceipt({ ...t, reason: "source-changed", installRecords: e }); return r; } /** Returns config with plugin install records attached at the canonical config path. */ function withPluginInstallRecords(e, t) { return { ...e, plugins: { ...e.plugins, installs: t } }; } /** Returns config with legacy plugin install records removed. */ function withoutPluginInstallRecords(e, t = {}) { if (!e.plugins?.installs) return e; const { installs: n, ...r } = e.plugins; if (Object.keys(r).length === 0) { if (t.preserveEmptyPlugins) return { ...e, plugins: {} }; const { plugins: n, ...r } = e; return r; } return { ...e, plugins: r }; } /** Removes one plugin install record from an in-memory record map. */ function removePluginInstallRecordFromRecords(e, t) { const n = copyPluginInstallRecordMap(e); delete n[t]; return n; } //#endregion export { writePersistedInstalledPluginIndexInstallRecordsWithLease as a, recordPluginInstall as c, withoutPluginInstallRecords as i, recordPluginInstallInRecords as l, removePluginInstallRecordFromRecords as n, configReferencesNpmInstallPath as o, withPluginInstallRecords as r, reconcileNpmPluginLoadPath as s, PLUGIN_INSTALLS_CONFIG_PATH as t, resolveNpmInstallRecordSpec as u };