




























@@ -1,3 +1,4 @@
1+import { fileURLToPath } from "node:url";
12import { resolveAgentWorkspaceDir, resolveDefaultAgentId } from "../../agents/agent-scope.js";
23import type { OpenClawConfig } from "../../config/types.openclaw.js";
34import { isBlockedObjectKey } from "../../infra/prototype-keys.js";
@@ -6,7 +7,11 @@ import {
67listConfiguredChannelIdsForReadOnlyScope,
78resolveDiscoverableScopedChannelPluginIds,
89} from "../../plugins/channel-plugin-ids.js";
9-import { loadOpenClawPlugins } from "../../plugins/loader.js";
10+import {
11+getCachedPluginJitiLoader,
12+type PluginJitiLoaderCache,
13+} from "../../plugins/jiti-loader-cache.js";
14+import type { loadOpenClawPlugins as loadOpenClawPluginsType } from "../../plugins/loader.js";
1015import type { PluginManifestRecord } from "../../plugins/manifest-registry.js";
1116import { loadPluginManifestRegistryForPluginRegistry } from "../../plugins/plugin-registry.js";
1217import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../../routing/session-key.js";
@@ -16,6 +21,40 @@ import { listChannelPlugins } from "./registry.js";
1621import type { ChannelPlugin } from "./types.plugin.js";
17221823const SAFE_MANIFEST_CHANNEL_ID_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/i;
24+const LOADER_MODULE_CANDIDATES = [
25+new URL("../../plugins/loader.js", import.meta.url),
26+new URL("../../plugins/loader.ts", import.meta.url),
27+] as const;
28+const jitiLoaders: PluginJitiLoaderCache = new Map();
29+30+type PluginLoaderModule = {
31+loadOpenClawPlugins: typeof loadOpenClawPluginsType;
32+};
33+34+let pluginLoaderModule: PluginLoaderModule | undefined;
35+36+function loadPluginLoaderModule(): PluginLoaderModule {
37+if (pluginLoaderModule) {
38+return pluginLoaderModule;
39+}
40+for (const candidate of LOADER_MODULE_CANDIDATES) {
41+const modulePath = fileURLToPath(candidate);
42+try {
43+const jiti = getCachedPluginJitiLoader({
44+cache: jitiLoaders,
45+ modulePath,
46+importerUrl: import.meta.url,
47+preferBuiltDist: true,
48+jitiFilename: import.meta.url,
49+});
50+pluginLoaderModule = jiti(modulePath) as PluginLoaderModule;
51+return pluginLoaderModule;
52+} catch {
53+// Try built/runtime source candidates in order.
54+}
55+}
56+throw new Error("Could not load plugin runtime loader for channel setup fallback.");
57+}
19582059type ReadOnlyChannelPluginOptions = {
2160env?: NodeJS.ProcessEnv;
@@ -641,7 +680,7 @@ export function resolveReadOnlyChannelPluginsForConfig(
641680] as const,
642681),
643682);
644-const registry = loadOpenClawPlugins({
683+const registry = loadPluginLoaderModule().loadOpenClawPlugins({
645684config: cfg,
646685activationSourceConfig: options.activationSourceConfig ?? cfg,
647686 env,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。