openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 3.38 kB
JavaScript
import{c as resolveUserPath}from"./home-dir-DEN5DisQ.mjs";import"./utils-Dlk0IYAa.mjs";import{r as getPluginInstallRecordMapEntry,s as setPluginInstallRecordMapEntry,t as copyPluginInstallRecordMap}from"./plugin-install-record-map-BULaY3LO.mjs";import{s as parseRegistryNpmSpec}from"./npm-registry-spec-D06XlvdA.mjs";import"./installed-plugin-index-record-reader-rJXlMUQ8.mjs";import{s as resolveControlPlaneRegistryParams}from"./plugin-registry-snapshot-Dz_L4M3w.mjs";import{o as refreshPersistedInstalledPluginIndexWithReceipt}from"./installed-plugin-index-store-write-DPCvm0PK.mjs";
//!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}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})}
//!src/plugins/installed-plugin-index-records.ts
const PLUGIN_INSTALLS_CONFIG_PATH=[`plugins`,`installs`];async function writePersistedInstalledPluginIndexInstallRecordsWithLease(e,t){const{index:n,...r}=await refreshPersistedInstalledPluginIndexWithReceipt({...resolveControlPlaneRegistryParams(t),reason:`source-changed`,installRecords:e});return r}function withPluginInstallRecords(e,t){return{...e,plugins:{...e.plugins,installs:t}}}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}}function removePluginInstallRecordFromRecords(e,t){const n=copyPluginInstallRecordMap(e);delete n[t];return n}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};