mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-25 23:47:20 +00:00
feat(plugins): share capability capture helpers
This commit is contained in:
58
src/plugins/captured-registration.ts
Normal file
58
src/plugins/captured-registration.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import type {
|
||||
AnyAgentTool,
|
||||
MediaUnderstandingProviderPlugin,
|
||||
OpenClawPluginApi,
|
||||
ProviderPlugin,
|
||||
SpeechProviderPlugin,
|
||||
WebSearchProviderPlugin,
|
||||
} from "./types.js";
|
||||
|
||||
export type CapturedPluginRegistration = {
|
||||
api: OpenClawPluginApi;
|
||||
providers: ProviderPlugin[];
|
||||
speechProviders: SpeechProviderPlugin[];
|
||||
mediaUnderstandingProviders: MediaUnderstandingProviderPlugin[];
|
||||
webSearchProviders: WebSearchProviderPlugin[];
|
||||
tools: AnyAgentTool[];
|
||||
};
|
||||
|
||||
export function createCapturedPluginRegistration(): CapturedPluginRegistration {
|
||||
const providers: ProviderPlugin[] = [];
|
||||
const speechProviders: SpeechProviderPlugin[] = [];
|
||||
const mediaUnderstandingProviders: MediaUnderstandingProviderPlugin[] = [];
|
||||
const webSearchProviders: WebSearchProviderPlugin[] = [];
|
||||
const tools: AnyAgentTool[] = [];
|
||||
|
||||
return {
|
||||
providers,
|
||||
speechProviders,
|
||||
mediaUnderstandingProviders,
|
||||
webSearchProviders,
|
||||
tools,
|
||||
api: {
|
||||
registerProvider(provider: ProviderPlugin) {
|
||||
providers.push(provider);
|
||||
},
|
||||
registerSpeechProvider(provider: SpeechProviderPlugin) {
|
||||
speechProviders.push(provider);
|
||||
},
|
||||
registerMediaUnderstandingProvider(provider: MediaUnderstandingProviderPlugin) {
|
||||
mediaUnderstandingProviders.push(provider);
|
||||
},
|
||||
registerWebSearchProvider(provider: WebSearchProviderPlugin) {
|
||||
webSearchProviders.push(provider);
|
||||
},
|
||||
registerTool(tool: AnyAgentTool) {
|
||||
tools.push(tool);
|
||||
},
|
||||
} as OpenClawPluginApi,
|
||||
};
|
||||
}
|
||||
|
||||
export function capturePluginRegistration(params: {
|
||||
register(api: OpenClawPluginApi): void;
|
||||
}): CapturedPluginRegistration {
|
||||
const captured = createCapturedPluginRegistration();
|
||||
params.register(captured.api);
|
||||
return captured;
|
||||
}
|
||||
@@ -34,7 +34,7 @@ import volcenginePlugin from "../../../extensions/volcengine/index.js";
|
||||
import xaiPlugin from "../../../extensions/xai/index.js";
|
||||
import xiaomiPlugin from "../../../extensions/xiaomi/index.js";
|
||||
import zaiPlugin from "../../../extensions/zai/index.js";
|
||||
import { createCapturedPluginRegistration } from "../../test-utils/plugin-registration.js";
|
||||
import { createCapturedPluginRegistration } from "../captured-registration.js";
|
||||
import type {
|
||||
MediaUnderstandingProviderPlugin,
|
||||
ProviderPlugin,
|
||||
|
||||
@@ -8,11 +8,11 @@ import {
|
||||
withBundledPluginAllowlistCompat,
|
||||
withBundledPluginEnablementCompat,
|
||||
} from "./bundled-compat.js";
|
||||
import { capturePluginRegistration } from "./captured-registration.js";
|
||||
import type { PluginLoadOptions } from "./loader.js";
|
||||
import type { PluginWebSearchProviderRegistration } from "./registry.js";
|
||||
import { getActivePluginRegistry } from "./runtime.js";
|
||||
import type { OpenClawPluginApi, WebSearchProviderPlugin } from "./types.js";
|
||||
import type { PluginWebSearchProviderEntry } from "./types.js";
|
||||
import type { OpenClawPluginApi, PluginWebSearchProviderEntry } from "./types.js";
|
||||
|
||||
type RegistrablePlugin = {
|
||||
id: string;
|
||||
@@ -76,18 +76,8 @@ function normalizeWebSearchPluginConfig(params: {
|
||||
function captureBundledWebSearchProviders(
|
||||
plugin: RegistrablePlugin,
|
||||
): PluginWebSearchProviderRegistration[] {
|
||||
const providers: WebSearchProviderPlugin[] = [];
|
||||
const api = {
|
||||
registerProvider() {},
|
||||
registerSpeechProvider() {},
|
||||
registerMediaUnderstandingProvider() {},
|
||||
registerWebSearchProvider(provider: WebSearchProviderPlugin) {
|
||||
providers.push(provider);
|
||||
},
|
||||
registerTool() {},
|
||||
};
|
||||
plugin.register(api as unknown as OpenClawPluginApi);
|
||||
return providers.map((provider) => ({
|
||||
const captured = capturePluginRegistration(plugin);
|
||||
return captured.webSearchProviders.map((provider) => ({
|
||||
pluginId: plugin.id,
|
||||
pluginName: plugin.name,
|
||||
provider,
|
||||
|
||||
Reference in New Issue
Block a user