refactor: share plugin capability provider resolution

This commit is contained in:
Peter Steinberger
2026-03-27 13:59:25 +00:00
parent f1503bd5c7
commit 07df59287a
4 changed files with 46 additions and 25 deletions

View File

@@ -0,0 +1,27 @@
import type { OpenClawConfig } from "../config/config.js";
import { loadOpenClawPlugins } from "./loader.js";
import type { PluginRegistry } from "./registry.js";
import { getActivePluginRegistry } from "./runtime.js";
type CapabilityProviderRegistryKey =
| "speechProviders"
| "mediaUnderstandingProviders"
| "imageGenerationProviders";
type CapabilityProviderForKey<K extends CapabilityProviderRegistryKey> =
PluginRegistry[K][number] extends { provider: infer T } ? T : never;
export function resolvePluginCapabilityProviders<K extends CapabilityProviderRegistryKey>(params: {
key: K;
cfg?: OpenClawConfig;
useActiveRegistryWhen?: (active: PluginRegistry | undefined) => boolean;
}): CapabilityProviderForKey<K>[] {
const active = getActivePluginRegistry();
const shouldUseActive =
params.useActiveRegistryWhen?.(active) ?? (active?.[params.key].length ?? 0) > 0;
const registry =
shouldUseActive || !params.cfg ? active : loadOpenClawPlugins({ config: params.cfg });
return (registry?.[params.key] ?? []).map(
(entry) => entry.provider,
) as CapabilityProviderForKey<K>[];
}