mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 03:50:43 +00:00
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import type { PluginManifestRegistry } from "../plugins/manifest-registry.js";
|
|
import { detectPluginAutoEnableCandidates } from "./plugin-auto-enable.detect.js";
|
|
import {
|
|
materializePluginAutoEnableCandidatesInternal,
|
|
resolvePluginAutoEnableManifestRegistry,
|
|
} from "./plugin-auto-enable.shared.js";
|
|
import type {
|
|
PluginAutoEnableCandidate,
|
|
PluginAutoEnableResult,
|
|
} from "./plugin-auto-enable.types.js";
|
|
import type { OpenClawConfig } from "./types.openclaw.js";
|
|
|
|
export function materializePluginAutoEnableCandidates(params: {
|
|
config?: OpenClawConfig;
|
|
candidates: readonly PluginAutoEnableCandidate[];
|
|
env?: NodeJS.ProcessEnv;
|
|
manifestRegistry?: PluginManifestRegistry;
|
|
}): PluginAutoEnableResult {
|
|
const env = params.env ?? process.env;
|
|
const config = params.config ?? {};
|
|
const entries = config.plugins?.entries;
|
|
const hasRestrictiveAllowlistWithEntries =
|
|
Array.isArray(config.plugins?.allow) &&
|
|
config.plugins.allow.length > 0 &&
|
|
entries !== undefined &&
|
|
typeof entries === "object";
|
|
if (params.candidates.length === 0 && !hasRestrictiveAllowlistWithEntries) {
|
|
return { config, changes: [], autoEnabledReasons: {} };
|
|
}
|
|
const manifestRegistry = resolvePluginAutoEnableManifestRegistry({
|
|
config,
|
|
env,
|
|
manifestRegistry: params.manifestRegistry,
|
|
});
|
|
return materializePluginAutoEnableCandidatesInternal({
|
|
config,
|
|
candidates: params.candidates,
|
|
env,
|
|
manifestRegistry,
|
|
});
|
|
}
|
|
|
|
export function applyPluginAutoEnable(params: {
|
|
config?: OpenClawConfig;
|
|
env?: NodeJS.ProcessEnv;
|
|
manifestRegistry?: PluginManifestRegistry;
|
|
}): PluginAutoEnableResult {
|
|
const candidates = detectPluginAutoEnableCandidates(params);
|
|
return materializePluginAutoEnableCandidates({
|
|
config: params.config,
|
|
candidates,
|
|
env: params.env,
|
|
manifestRegistry: params.manifestRegistry,
|
|
});
|
|
}
|