57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
import { createSubsystemLogger } from "../logging/subsystem.js";
|
|
import { loadOpenClawPlugins } from "./loader.js";
|
|
import type { PluginLoadOptions } from "./loader.js";
|
|
import { createPluginLoaderLogger } from "./logger.js";
|
|
import { getActivePluginRegistry } from "./runtime.js";
|
|
import type { PluginWebSearchProviderEntry } from "./types.js";
|
|
import {
|
|
resolveBundledWebSearchResolutionConfig,
|
|
sortWebSearchProviders,
|
|
} from "./web-search-providers.shared.js";
|
|
|
|
const log = createSubsystemLogger("plugins");
|
|
|
|
export function resolvePluginWebSearchProviders(params: {
|
|
config?: PluginLoadOptions["config"];
|
|
workspaceDir?: string;
|
|
env?: PluginLoadOptions["env"];
|
|
bundledAllowlistCompat?: boolean;
|
|
activate?: boolean;
|
|
cache?: boolean;
|
|
}): PluginWebSearchProviderEntry[] {
|
|
const { config } = resolveBundledWebSearchResolutionConfig(params);
|
|
const registry = loadOpenClawPlugins({
|
|
config,
|
|
workspaceDir: params.workspaceDir,
|
|
env: params.env,
|
|
cache: params.cache ?? false,
|
|
activate: params.activate ?? false,
|
|
logger: createPluginLoaderLogger(log),
|
|
});
|
|
|
|
return sortWebSearchProviders(
|
|
registry.webSearchProviders.map((entry) => ({
|
|
...entry.provider,
|
|
pluginId: entry.pluginId,
|
|
})),
|
|
);
|
|
}
|
|
|
|
export function resolveRuntimeWebSearchProviders(params: {
|
|
config?: PluginLoadOptions["config"];
|
|
workspaceDir?: string;
|
|
env?: PluginLoadOptions["env"];
|
|
bundledAllowlistCompat?: boolean;
|
|
}): PluginWebSearchProviderEntry[] {
|
|
const runtimeProviders = getActivePluginRegistry()?.webSearchProviders ?? [];
|
|
if (runtimeProviders.length > 0) {
|
|
return sortWebSearchProviders(
|
|
runtimeProviders.map((entry) => ({
|
|
...entry.provider,
|
|
pluginId: entry.pluginId,
|
|
})),
|
|
);
|
|
}
|
|
return resolvePluginWebSearchProviders(params);
|
|
}
|