Plugins: capture tool registrations in test registry
This commit is contained in:
parent
36f0f216ce
commit
6644783052
@ -52,6 +52,13 @@ type WebSearchProviderContractEntry = {
|
||||
credentialValue: unknown;
|
||||
};
|
||||
|
||||
type PluginRegistrationContractEntry = {
|
||||
pluginId: string;
|
||||
providerIds: string[];
|
||||
webSearchProviderIds: string[];
|
||||
toolNames: string[];
|
||||
};
|
||||
|
||||
const bundledProviderPlugins: RegistrablePlugin[] = [
|
||||
anthropicPlugin,
|
||||
byteplusPlugin,
|
||||
@ -97,11 +104,7 @@ const bundledWebSearchPlugins: Array<RegistrablePlugin & { credentialValue: unkn
|
||||
|
||||
function captureRegistrations(plugin: RegistrablePlugin) {
|
||||
const captured = createCapturedPluginRegistration();
|
||||
const api = {
|
||||
...captured.api,
|
||||
registerTool() {},
|
||||
} satisfies Partial<OpenClawPluginApi>;
|
||||
plugin.register(api as OpenClawPluginApi);
|
||||
plugin.register(captured.api);
|
||||
return captured;
|
||||
}
|
||||
|
||||
@ -124,3 +127,20 @@ export const webSearchProviderContractRegistry: WebSearchProviderContractEntry[]
|
||||
credentialValue: plugin.credentialValue,
|
||||
}));
|
||||
});
|
||||
|
||||
const bundledPluginRegistrationList = [
|
||||
...new Map(
|
||||
[...bundledProviderPlugins, ...bundledWebSearchPlugins].map((plugin) => [plugin.id, plugin]),
|
||||
).values(),
|
||||
];
|
||||
|
||||
export const pluginRegistrationContractRegistry: PluginRegistrationContractEntry[] =
|
||||
bundledPluginRegistrationList.map((plugin) => {
|
||||
const captured = captureRegistrations(plugin);
|
||||
return {
|
||||
pluginId: plugin.id,
|
||||
providerIds: captured.providers.map((provider) => provider.id),
|
||||
webSearchProviderIds: captured.webSearchProviders.map((provider) => provider.id),
|
||||
toolNames: captured.tools.map((tool) => tool.name),
|
||||
};
|
||||
});
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import type {
|
||||
AnyAgentTool,
|
||||
OpenClawPluginApi,
|
||||
ProviderPlugin,
|
||||
WebSearchProviderPlugin,
|
||||
@ -8,15 +9,18 @@ export type CapturedPluginRegistration = {
|
||||
api: OpenClawPluginApi;
|
||||
providers: ProviderPlugin[];
|
||||
webSearchProviders: WebSearchProviderPlugin[];
|
||||
tools: AnyAgentTool[];
|
||||
};
|
||||
|
||||
export function createCapturedPluginRegistration(): CapturedPluginRegistration {
|
||||
const providers: ProviderPlugin[] = [];
|
||||
const webSearchProviders: WebSearchProviderPlugin[] = [];
|
||||
const tools: AnyAgentTool[] = [];
|
||||
|
||||
return {
|
||||
providers,
|
||||
webSearchProviders,
|
||||
tools,
|
||||
api: {
|
||||
registerProvider(provider: ProviderPlugin) {
|
||||
providers.push(provider);
|
||||
@ -24,6 +28,9 @@ export function createCapturedPluginRegistration(): CapturedPluginRegistration {
|
||||
registerWebSearchProvider(provider: WebSearchProviderPlugin) {
|
||||
webSearchProviders.push(provider);
|
||||
},
|
||||
registerTool(tool: AnyAgentTool) {
|
||||
tools.push(tool);
|
||||
},
|
||||
} as OpenClawPluginApi,
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user