diff --git a/src/media-understanding/providers/index.ts b/src/media-understanding/providers/index.ts index 32d1d6bcf9a..521d55caee1 100644 --- a/src/media-understanding/providers/index.ts +++ b/src/media-understanding/providers/index.ts @@ -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, @@ -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 ?? []) { diff --git a/src/plugin-sdk/index.ts b/src/plugin-sdk/index.ts index acfca49d6ab..1e926c098ab 100644 --- a/src/plugin-sdk/index.ts +++ b/src/plugin-sdk/index.ts @@ -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, diff --git a/src/plugin-sdk/media-understanding.ts b/src/plugin-sdk/media-understanding.ts index 0d14685dbdf..a9f10cd8d58 100644 --- a/src/plugin-sdk/media-understanding.ts +++ b/src/plugin-sdk/media-understanding.ts @@ -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, diff --git a/src/plugins/captured-registration.ts b/src/plugins/captured-registration.ts new file mode 100644 index 00000000000..dd5ba78a9c4 --- /dev/null +++ b/src/plugins/captured-registration.ts @@ -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; +} diff --git a/src/plugins/contracts/registry.ts b/src/plugins/contracts/registry.ts index 3c5cc8935c9..cd58bf41de2 100644 --- a/src/plugins/contracts/registry.ts +++ b/src/plugins/contracts/registry.ts @@ -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, diff --git a/src/plugins/web-search-providers.ts b/src/plugins/web-search-providers.ts index 9ecdef1fd3c..585ed0bd36c 100644 --- a/src/plugins/web-search-providers.ts +++ b/src/plugins/web-search-providers.ts @@ -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, diff --git a/src/test-utils/plugin-registration.ts b/src/test-utils/plugin-registration.ts index de8e5422ccf..5251f82c051 100644 --- a/src/test-utils/plugin-registration.ts +++ b/src/test-utils/plugin-registration.ts @@ -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;