openclaw/src/test-utils/plugin-registration.ts
2026-03-16 02:11:18 +00:00

42 lines
1.1 KiB
TypeScript

import type {
OpenClawPluginApi,
ProviderPlugin,
WebSearchProviderPlugin,
} from "../plugins/types.js";
export type CapturedPluginRegistration = {
api: OpenClawPluginApi;
providers: ProviderPlugin[];
webSearchProviders: WebSearchProviderPlugin[];
};
export function createCapturedPluginRegistration(): CapturedPluginRegistration {
const providers: ProviderPlugin[] = [];
const webSearchProviders: WebSearchProviderPlugin[] = [];
return {
providers,
webSearchProviders,
api: {
registerProvider(provider: ProviderPlugin) {
providers.push(provider);
},
registerWebSearchProvider(provider: WebSearchProviderPlugin) {
webSearchProviders.push(provider);
},
} as OpenClawPluginApi,
};
}
export function registerSingleProviderPlugin(params: {
register(api: OpenClawPluginApi): void;
}): ProviderPlugin {
const captured = createCapturedPluginRegistration();
params.register(captured.api);
const provider = captured.providers[0];
if (!provider) {
throw new Error("provider registration missing");
}
return provider;
}