feat(plugins): share capability capture helpers

This commit is contained in:
Peter Steinberger
2026-03-16 22:20:52 -07:00
parent 6cbff9e7d3
commit d2445b5fcd
7 changed files with 75 additions and 88 deletions

View File

@@ -1,13 +1,3 @@
import { anthropicMediaUnderstandingProvider } from "../../../extensions/anthropic/media-understanding-provider.js";
import { googleMediaUnderstandingProvider } from "../../../extensions/google/media-understanding-provider.js";
import {
minimaxMediaUnderstandingProvider,
minimaxPortalMediaUnderstandingProvider,
} from "../../../extensions/minimax/media-understanding-provider.js";
import { mistralMediaUnderstandingProvider } from "../../../extensions/mistral/media-understanding-provider.js";
import { moonshotMediaUnderstandingProvider } from "../../../extensions/moonshot/media-understanding-provider.js";
import { openaiMediaUnderstandingProvider } from "../../../extensions/openai/media-understanding-provider.js";
import { zaiMediaUnderstandingProvider } from "../../../extensions/zai/media-understanding-provider.js";
import { normalizeProviderId } from "../../agents/model-selection.js";
import type { OpenClawConfig } from "../../config/config.js";
import { loadOpenClawPlugins } from "../../plugins/loader.js";
@@ -16,18 +6,7 @@ import type { MediaUnderstandingProvider } from "../types.js";
import { deepgramProvider } from "./deepgram/index.js";
import { groqProvider } from "./groq/index.js";
const PROVIDERS: MediaUnderstandingProvider[] = [
groqProvider,
deepgramProvider,
anthropicMediaUnderstandingProvider,
googleMediaUnderstandingProvider,
minimaxMediaUnderstandingProvider,
minimaxPortalMediaUnderstandingProvider,
mistralMediaUnderstandingProvider,
moonshotMediaUnderstandingProvider,
openaiMediaUnderstandingProvider,
zaiMediaUnderstandingProvider,
];
const PROVIDERS: MediaUnderstandingProvider[] = [groqProvider, deepgramProvider];
function mergeProviderIntoRegistry(
registry: Map<string, MediaUnderstandingProvider>,
@@ -63,7 +42,7 @@ export function buildMediaUnderstandingRegistry(
}
const active = getActivePluginRegistry();
const pluginRegistry =
(active?.mediaUnderstandingProviders?.length ?? 0) > 0 || !cfg
(active?.mediaUnderstandingProviders?.length ?? 0) > 0
? active
: loadOpenClawPlugins({ config: cfg });
for (const entry of pluginRegistry?.mediaUnderstandingProviders ?? []) {

View File

@@ -183,14 +183,17 @@ export type { OpenClawConfig } from "../config/config.js";
/** @deprecated Use OpenClawConfig instead */
export type { OpenClawConfig as ClawdbotConfig } from "../config/config.js";
export { isDangerousNameMatchingEnabled } from "../config/dangerous-name-matching.js";
export * from "./speech.js";
export type { FileLockHandle, FileLockOptions } from "./file-lock.js";
export { acquireFileLock, withFileLock } from "./file-lock.js";
export * from "./media-understanding.js";
export {
mapAllowlistResolutionInputs,
mapBasicAllowlistResolutionEntries,
type BasicAllowlistResolutionEntry,
} from "./allowlist-resolution.js";
export * from "./provider-web-search.js";
export { resolveRequestUrl } from "./request-url.js";
export {
buildDiscordSendMediaOptions,

View File

@@ -13,7 +13,10 @@ export type {
VideoDescriptionResult,
} from "../media-understanding/types.js";
export { describeImageWithModel, describeImagesWithModel } from "../media-understanding/providers/image.js";
export {
describeImageWithModel,
describeImagesWithModel,
} from "../media-understanding/providers/image.js";
export { transcribeOpenAiCompatibleAudio } from "../media-understanding/providers/openai-compatible-audio.js";
export {
assertOkOrThrowHttpError,

View 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;
}

View File

@@ -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,

View File

@@ -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,

View File

@@ -1,53 +1,7 @@
import type {
AnyAgentTool,
MediaUnderstandingProviderPlugin,
OpenClawPluginApi,
ProviderPlugin,
SpeechProviderPlugin,
WebSearchProviderPlugin,
} from "../plugins/types.js";
import { createCapturedPluginRegistration } from "../plugins/captured-registration.js";
import type { OpenClawPluginApi, ProviderPlugin } from "../plugins/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 { createCapturedPluginRegistration };
export function registerSingleProviderPlugin(params: {
register(api: OpenClawPluginApi): void;