mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 21:21:10 +00:00
refactor: dedupe plugin enable-state adapters
This commit is contained in:
@@ -11,6 +11,13 @@ export function toEnableStateResult<TState extends EnableStateLike>(
|
||||
return state.enabled ? { enabled: true } : { enabled: false, reason: state.reason };
|
||||
}
|
||||
|
||||
export function resolveEnableStateResult<TParams, TState extends EnableStateLike>(
|
||||
params: TParams,
|
||||
resolveState: (params: TParams) => TState,
|
||||
): { enabled: boolean; reason?: string } {
|
||||
return toEnableStateResult(resolveState(params));
|
||||
}
|
||||
|
||||
function hasKind(kind: PluginKindLike, target: string): boolean {
|
||||
if (!kind) {
|
||||
return false;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import {
|
||||
resolveMemorySlotDecisionShared,
|
||||
toEnableStateResult,
|
||||
resolveEnableStateResult,
|
||||
} from "./config-activation-shared.js";
|
||||
import {
|
||||
hasExplicitPluginConfig as hasExplicitPluginConfigShared,
|
||||
@@ -202,13 +202,14 @@ export function resolveEnableState(
|
||||
config: NormalizedPluginsConfig,
|
||||
enabledByDefault?: boolean,
|
||||
): { enabled: boolean; reason?: string } {
|
||||
return toEnableStateResult(
|
||||
resolvePluginActivationState({
|
||||
return resolveEnableStateResult(
|
||||
{
|
||||
id,
|
||||
origin,
|
||||
config,
|
||||
enabledByDefault,
|
||||
}),
|
||||
},
|
||||
resolvePluginActivationState,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -229,7 +230,7 @@ export function resolveEffectiveEnableState(params: {
|
||||
sourceRootConfig?: OpenClawConfig;
|
||||
autoEnabledReason?: string;
|
||||
}): { enabled: boolean; reason?: string } {
|
||||
return toEnableStateResult(resolveEffectivePluginActivationState(params));
|
||||
return resolveEnableStateResult(params, resolveEffectivePluginActivationState);
|
||||
}
|
||||
|
||||
export function resolveEffectivePluginActivationState(params: {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import {
|
||||
resolveMemorySlotDecisionShared,
|
||||
toEnableStateResult,
|
||||
resolveEnableStateResult,
|
||||
} from "./config-activation-shared.js";
|
||||
import {
|
||||
hasExplicitPluginConfig as hasExplicitPluginConfigShared,
|
||||
@@ -380,13 +380,14 @@ export function resolveEnableState(
|
||||
config: NormalizedPluginsConfig,
|
||||
enabledByDefault?: boolean,
|
||||
): { enabled: boolean; reason?: string } {
|
||||
return toEnableStateResult(
|
||||
resolvePluginActivationState({
|
||||
return resolveEnableStateResult(
|
||||
{
|
||||
id,
|
||||
origin,
|
||||
config,
|
||||
enabledByDefault,
|
||||
}),
|
||||
},
|
||||
resolvePluginActivationState,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -405,7 +406,7 @@ export function resolveEffectiveEnableState(params: {
|
||||
enabledByDefault?: boolean;
|
||||
activationSource?: PluginActivationConfigSource;
|
||||
}): { enabled: boolean; reason?: string } {
|
||||
return toEnableStateResult(resolveEffectivePluginActivationState(params));
|
||||
return resolveEnableStateResult(params, resolveEffectivePluginActivationState);
|
||||
}
|
||||
|
||||
export function resolveEffectivePluginActivationState(params: {
|
||||
|
||||
Reference in New Issue
Block a user