UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

58 lines (57 loc) 2.65 kB
import { o as getPluginCacheRoot } from "./plugin-cache-DGWspMEc.js"; import { a as pluginCacheRealpathSync, r as pluginCacheExistsSync } from "./plugin-cache-files-DLPF_Tw2.js"; import { C as requireActivePluginRegistry, u as getActivePluginRegistry } from "./runtime-BL4wZfTq.js"; import { r as resolvePreferredBuiltRuntimeArtifact } from "./plugin-runtime-artifact-selection-OSt151GX.js"; import path from "node:path"; //#region src/plugins/plugin-runtime-artifact-resolution.ts /** Resolves the exact root and entry selected by the plugin runtime loader. */ function clearPluginRuntimeArtifactResolutionMemo() { getActivePluginRegistry()?.pluginRuntimeArtifacts.clear(); } /** Canonical packaged runtime replaces staging-only dist-runtime artifacts. */ function resolveCanonicalDistRuntimeSource(source) { const marker = `${path.sep}dist-runtime${path.sep}extensions${path.sep}`; const index = source.indexOf(marker); if (index === -1) return source; const candidate = `${source.slice(0, index)}${path.sep}dist${path.sep}extensions${path.sep}${source.slice(index + marker.length)}`; return pluginCacheExistsSync(candidate) ? candidate : source; } /** Applies both loader selection phases in their runtime order. */ function resolvePluginRuntimeArtifact(params) { const rootDir = resolveCanonicalDistRuntimeSource(pluginCacheRealpathSync(params.rootDir) ?? path.resolve(params.rootDir)); const memoKey = JSON.stringify([ params.pluginId, rootDir, params.entryKind ]); const targetRegistry = params.registry ?? requireActivePluginRegistry(); const cached = targetRegistry.pluginRuntimeArtifacts.get(memoKey); if (cached) return { ...cached }; const artifacts = getPluginCacheRoot(rootDir).runtimeArtifacts; const selectionKey = JSON.stringify([ params.source, params.entryKind, params.origin, params.preferBuiltPluginArtifacts, params.sourcePreferred, params.packageManifest?.build?.bundledDist ]); let resolved = artifacts.get(selectionKey); if (!resolved) { const source = resolveCanonicalDistRuntimeSource(pluginCacheRealpathSync(params.source) ?? path.resolve(params.source)); const preferred = resolvePreferredBuiltRuntimeArtifact({ ...params, source, rootDir }); resolved = { source: resolveCanonicalDistRuntimeSource(preferred.source), rootDir: resolveCanonicalDistRuntimeSource(preferred.rootDir) }; artifacts.set(selectionKey, resolved); } targetRegistry.pluginRuntimeArtifacts.set(memoKey, resolved); return { ...resolved }; } //#endregion export { resolveCanonicalDistRuntimeSource as n, resolvePluginRuntimeArtifact as r, clearPluginRuntimeArtifactResolutionMemo as t };