mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 15:30:47 +00:00
perf(config): avoid duplicate plugin auto-enable channel probes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { PluginManifestRegistry } from "../plugins/manifest-registry.js";
|
||||
import {
|
||||
configMayNeedPluginAutoEnable,
|
||||
resolveConfiguredPluginAutoEnableCandidates,
|
||||
resolvePluginAutoEnableReadiness,
|
||||
resolvePluginAutoEnableManifestRegistry,
|
||||
} from "./plugin-auto-enable.shared.js";
|
||||
import type { PluginAutoEnableCandidate } from "./plugin-auto-enable.types.js";
|
||||
@@ -14,7 +14,8 @@ export function detectPluginAutoEnableCandidates(params: {
|
||||
}): PluginAutoEnableCandidate[] {
|
||||
const env = params.env ?? process.env;
|
||||
const config = params.config ?? ({} as OpenClawConfig);
|
||||
if (!configMayNeedPluginAutoEnable(config, env)) {
|
||||
const readiness = resolvePluginAutoEnableReadiness(config, env);
|
||||
if (!readiness.mayNeedAutoEnable) {
|
||||
return [];
|
||||
}
|
||||
const registry = resolvePluginAutoEnableManifestRegistry({
|
||||
@@ -26,5 +27,6 @@ export function detectPluginAutoEnableCandidates(params: {
|
||||
config,
|
||||
env,
|
||||
registry,
|
||||
configuredChannelIds: readiness.configuredChannelIds,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -482,38 +482,48 @@ export function configMayNeedPluginAutoEnable(
|
||||
cfg: OpenClawConfig,
|
||||
env: NodeJS.ProcessEnv,
|
||||
): boolean {
|
||||
return resolvePluginAutoEnableReadiness(cfg, env).mayNeedAutoEnable;
|
||||
}
|
||||
|
||||
export function resolvePluginAutoEnableReadiness(
|
||||
cfg: OpenClawConfig,
|
||||
env: NodeJS.ProcessEnv,
|
||||
): { mayNeedAutoEnable: boolean; configuredChannelIds: string[] } {
|
||||
if (arePluginsGloballyDisabled(cfg)) {
|
||||
return false;
|
||||
return { mayNeedAutoEnable: false, configuredChannelIds: [] };
|
||||
}
|
||||
if (hasPluginAllowlistWithMaterialEntries(cfg)) {
|
||||
return true;
|
||||
return { mayNeedAutoEnable: true, configuredChannelIds: [] };
|
||||
}
|
||||
if (hasConfiguredPluginConfigEntry(cfg)) {
|
||||
return true;
|
||||
return { mayNeedAutoEnable: true, configuredChannelIds: [] };
|
||||
}
|
||||
if (collectConfiguredChannelIds(cfg, env).length > 0) {
|
||||
return true;
|
||||
const configuredChannelIds = collectConfiguredChannelIds(cfg, env);
|
||||
if (configuredChannelIds.length > 0) {
|
||||
return { mayNeedAutoEnable: true, configuredChannelIds };
|
||||
}
|
||||
if (hasConfiguredProviderModelOrHarness(cfg, env)) {
|
||||
return true;
|
||||
return { mayNeedAutoEnable: true, configuredChannelIds };
|
||||
}
|
||||
if (
|
||||
hasConfiguredWebSearchProviderSelection(cfg) ||
|
||||
hasConfiguredWebSearchPluginEntry(cfg) ||
|
||||
hasConfiguredWebFetchPluginEntry(cfg)
|
||||
) {
|
||||
return true;
|
||||
return { mayNeedAutoEnable: true, configuredChannelIds };
|
||||
}
|
||||
if (!hasSetupAutoEnableRelevantConfig(cfg)) {
|
||||
return false;
|
||||
return { mayNeedAutoEnable: false, configuredChannelIds };
|
||||
}
|
||||
return (
|
||||
resolvePluginSetupAutoEnableReasons({
|
||||
config: cfg,
|
||||
env,
|
||||
pluginIds: resolveRelevantSetupAutoEnablePluginIds(cfg),
|
||||
}).length > 0
|
||||
);
|
||||
return {
|
||||
mayNeedAutoEnable:
|
||||
resolvePluginSetupAutoEnableReasons({
|
||||
config: cfg,
|
||||
env,
|
||||
pluginIds: resolveRelevantSetupAutoEnablePluginIds(cfg),
|
||||
}).length > 0,
|
||||
configuredChannelIds,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolvePluginAutoEnableCandidateReason(
|
||||
@@ -548,9 +558,11 @@ export function resolveConfiguredPluginAutoEnableCandidates(params: {
|
||||
config: OpenClawConfig;
|
||||
env: NodeJS.ProcessEnv;
|
||||
registry: PluginManifestRegistry;
|
||||
configuredChannelIds?: readonly string[];
|
||||
}): PluginAutoEnableCandidate[] {
|
||||
const changes: PluginAutoEnableCandidate[] = [];
|
||||
for (const channelId of collectConfiguredChannelIds(params.config, params.env)) {
|
||||
for (const channelId of params.configuredChannelIds ??
|
||||
collectConfiguredChannelIds(params.config, params.env)) {
|
||||
for (const pluginId of collectPluginIdsForConfiguredChannel(channelId, params.registry)) {
|
||||
changes.push({ pluginId, kind: "channel-configured", channelId });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user