UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

106 lines (105 loc) • 4.88 kB
import { n as getPluginRuntimeLoadContextState, t as bindPluginRuntimeLoadContextState } from "./load-context-state-Cj2HcQlf.mjs"; import { r as isDeeplyFrozenPlainData } from "./immutable-data-Y7xVjZoy.mjs"; import { t as createSubsystemLogger } from "./subsystem-BHJiy01V.mjs"; import { u as normalizePluginsConfig } from "./config-state-B1JlHgba.mjs"; import { n as hashStableJson } from "./installed-plugin-index-hash-BfBbMPjv.mjs"; import { t as resolvePluginControlPlaneFingerprint } from "./plugin-control-plane-context-BmY6xICT.mjs"; import { t as buildDeclaredProviderOwnerIndex } from "./provider-owner-index-6ny9zfJF.mjs"; import "./logging-FPYEZPak.mjs"; import { createHash } from "node:crypto"; //#region src/plugins/loader-registration-config.ts /** Configuration consumed during registration, independent of activation and load scope. */ function resolvePluginRegistrationConfigKey(e) { const { runtimeEntries: t, sourceEntries: n } = e; const r = [.../* @__PURE__ */ new Set([...Object.keys(t), ...Object.keys(n)])].toSorted().flatMap((e) => { const { enabled: r, ...i } = t[e] ?? {}; const a = n[e]?.config; const o = { ...i, sourceConfig: a }; return Object.values(o).some((e) => e !== void 0) ? [[e, o]] : []; }); return createHash("sha256").update(JSON.stringify(r)).digest("hex"); } //#endregion //#region src/plugins/runtime/load-context.ts const log = createSubsystemLogger("plugins"); const immutableActivationValueHashes = /* @__PURE__ */ new WeakMap(); function activationValueFingerprint(e) { const t = e !== null && typeof e === "object" && isDeeplyFrozenPlainData(e); const n = t ? immutableActivationValueHashes.get(e) : void 0; if (n !== void 0) return n; const r = hashStableJson(e); if (t) immutableActivationValueHashes.set(e, r); return r; } function activationConfigFingerprint(e) { return hashStableJson(Object.fromEntries(Object.entries(e).map(([e, t]) => [e, activationValueFingerprint(t)]))); } function activationInputFingerprint(e, t) { return hashStableJson({ config: activationConfigFingerprint(e), env: t }); } function setPluginRuntimeLoadContext(e, t, n, r) { const i = getPluginRuntimeLoadContextState(e); const a = i?.loaderCacheIdentity ?? r; const o = { ...t, normalizePluginId: i ? i.normalizePluginId : t.normalizePluginId, activationInputFingerprint: activationInputFingerprint(t.rawConfig, t.env), ...a ? { loaderCacheIdentity: a } : {}, selectedContextEngine: i ? i.selectedContextEngine : t.selectedContextEngine, registrationConfigKey: i?.registrationConfigKey ?? n ?? resolvePluginRegistrationConfigKey({ runtimeEntries: normalizePluginsConfig(t.config.plugins).entries, sourceEntries: normalizePluginsConfig(t.activationSourceConfig.plugins).entries }), declaredProviderOwners: t.metadataSnapshot && t.metadataSnapshot.manifestRegistry === t.manifestRegistry ? t.metadataSnapshot.declaredProviderOwners : buildDeclaredProviderOwnerIndex(t.manifestRegistry?.plugins ?? []), controlPlaneFingerprint: resolvePluginControlPlaneFingerprint({ config: t.rawConfig, env: t.env, workspaceDir: t.workspaceDir }) }; bindPluginRuntimeLoadContextState(e, o); } /** Reads load facts carried by an exact lifecycle-owned registry. */ const getPluginRuntimeLoadContext = (e) => getPluginRuntimeLoadContextState(e); /** Reuses captured activation decisions for matching metadata and requested inputs. */ function getReusablePluginRuntimeActivation(e, t) { const n = getPluginRuntimeLoadContext(e); if (!n || n.metadataSnapshot !== t.metadataSnapshot || n.workspaceDir !== t.workspaceDir) return; const r = activationInputFingerprint(t.config, t.env); if (r !== n.activationInputFingerprint && r !== activationInputFingerprint(n.config, n.env) && r !== activationInputFingerprint(n.activationSourceConfig, n.env)) return; return { config: n.config, activationSourceConfig: n.activationSourceConfig, autoEnabledReasons: n.autoEnabledReasons }; } const pluginRuntimeLoaderLogger = { info: (e) => log.info(e), warn: (e) => log.warn(e), error: (e) => log.error(e), debug: (e) => log.debug(e) }; function buildPluginRuntimeLoadOptions(e, t) { return { config: e.config, activationSourceConfig: e.activationSourceConfig, autoEnabledReasons: e.autoEnabledReasons, workspaceDir: e.workspaceDir, env: e.env, logger: e.logger, manifestRegistry: e.manifestRegistry, metadataSnapshot: e.metadataSnapshot, installRecords: e.installRecords, preferBuiltPluginArtifacts: e.preferBuiltPluginArtifacts, expectedSourceDigests: e.expectedSourceDigests, ...t }; } //#endregion export { pluginRuntimeLoaderLogger as a, getReusablePluginRuntimeActivation as i, buildPluginRuntimeLoadOptions as n, setPluginRuntimeLoadContext as o, getPluginRuntimeLoadContext as r, resolvePluginRegistrationConfigKey as s, activationConfigFingerprint as t };