mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 09:50:21 +00:00
refactor(plugins): share activation context for provider runtimes
This commit is contained in:
95
src/plugins/activation-context.ts
Normal file
95
src/plugins/activation-context.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { applyPluginAutoEnable } from "../config/plugin-auto-enable.js";
|
||||
import {
|
||||
withBundledPluginAllowlistCompat,
|
||||
withBundledPluginEnablementCompat,
|
||||
withBundledPluginVitestCompat,
|
||||
} from "./bundled-compat.js";
|
||||
import {
|
||||
createPluginActivationSource,
|
||||
normalizePluginsConfig,
|
||||
type NormalizedPluginsConfig,
|
||||
type PluginActivationConfigSource,
|
||||
} from "./config-state.js";
|
||||
|
||||
export type PluginActivationCompatConfig = {
|
||||
allowlistPluginIds?: readonly string[];
|
||||
enablementPluginIds?: readonly string[];
|
||||
vitestPluginIds?: readonly string[];
|
||||
};
|
||||
|
||||
export type PluginActivationInputs = {
|
||||
rawConfig?: OpenClawConfig;
|
||||
config?: OpenClawConfig;
|
||||
normalized: NormalizedPluginsConfig;
|
||||
activationSourceConfig?: OpenClawConfig;
|
||||
activationSource: PluginActivationConfigSource;
|
||||
autoEnabledReasons: Record<string, string[]>;
|
||||
};
|
||||
|
||||
function applyPluginActivationCompat(params: {
|
||||
config?: OpenClawConfig;
|
||||
compat?: PluginActivationCompatConfig;
|
||||
env: NodeJS.ProcessEnv;
|
||||
}): OpenClawConfig | undefined {
|
||||
const allowlistCompat = params.compat?.allowlistPluginIds?.length
|
||||
? withBundledPluginAllowlistCompat({
|
||||
config: params.config,
|
||||
pluginIds: params.compat.allowlistPluginIds,
|
||||
})
|
||||
: params.config;
|
||||
const enablementCompat = params.compat?.enablementPluginIds?.length
|
||||
? withBundledPluginEnablementCompat({
|
||||
config: allowlistCompat,
|
||||
pluginIds: params.compat.enablementPluginIds,
|
||||
})
|
||||
: allowlistCompat;
|
||||
const vitestCompat = params.compat?.vitestPluginIds?.length
|
||||
? withBundledPluginVitestCompat({
|
||||
config: enablementCompat,
|
||||
pluginIds: params.compat.vitestPluginIds,
|
||||
env: params.env,
|
||||
})
|
||||
: enablementCompat;
|
||||
return vitestCompat;
|
||||
}
|
||||
|
||||
export function resolvePluginActivationInputs(params: {
|
||||
rawConfig?: OpenClawConfig;
|
||||
resolvedConfig?: OpenClawConfig;
|
||||
autoEnabledReasons?: Record<string, string[]>;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
compat?: PluginActivationCompatConfig;
|
||||
applyAutoEnable?: boolean;
|
||||
}): PluginActivationInputs {
|
||||
const env = params.env ?? process.env;
|
||||
const rawConfig = params.rawConfig ?? params.resolvedConfig;
|
||||
let resolvedConfig = params.resolvedConfig ?? params.rawConfig;
|
||||
let autoEnabledReasons = params.autoEnabledReasons;
|
||||
|
||||
if (params.applyAutoEnable && rawConfig !== undefined) {
|
||||
const autoEnabled = applyPluginAutoEnable({
|
||||
config: rawConfig,
|
||||
env,
|
||||
});
|
||||
resolvedConfig = autoEnabled.config;
|
||||
autoEnabledReasons = autoEnabled.autoEnabledReasons;
|
||||
}
|
||||
|
||||
const config = applyPluginActivationCompat({
|
||||
config: resolvedConfig,
|
||||
compat: params.compat,
|
||||
env,
|
||||
});
|
||||
|
||||
return {
|
||||
rawConfig,
|
||||
config,
|
||||
normalized: normalizePluginsConfig(config?.plugins),
|
||||
activationSourceConfig: rawConfig,
|
||||
activationSource: createPluginActivationSource({
|
||||
config: rawConfig,
|
||||
}),
|
||||
autoEnabledReasons: autoEnabledReasons ?? {},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user