mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 17:51:22 +00:00
refactor: move browser runtime seams behind plugin metadata
This commit is contained in:
56
src/node-host/plugin-node-host.ts
Normal file
56
src/node-host/plugin-node-host.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { getActivePluginRegistry } from "../plugins/runtime.js";
|
||||
|
||||
let pluginRegistryLoaderModulePromise:
|
||||
| Promise<typeof import("../plugins/runtime/runtime-registry-loader.js")>
|
||||
| undefined;
|
||||
|
||||
async function loadPluginRegistryLoaderModule() {
|
||||
pluginRegistryLoaderModulePromise ??= import("../plugins/runtime/runtime-registry-loader.js");
|
||||
return await pluginRegistryLoaderModulePromise;
|
||||
}
|
||||
|
||||
export async function ensureNodeHostPluginRegistry(params: {
|
||||
config: OpenClawConfig;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
}): Promise<void> {
|
||||
(await loadPluginRegistryLoaderModule()).ensurePluginRegistryLoaded({
|
||||
scope: "all",
|
||||
config: params.config,
|
||||
activationSourceConfig: params.config,
|
||||
env: params.env,
|
||||
});
|
||||
}
|
||||
|
||||
export function listRegisteredNodeHostCapsAndCommands(): {
|
||||
caps: string[];
|
||||
commands: string[];
|
||||
} {
|
||||
const registry = getActivePluginRegistry();
|
||||
const caps = new Set<string>();
|
||||
const commands = new Set<string>();
|
||||
for (const entry of registry?.nodeHostCommands ?? []) {
|
||||
if (entry.command.cap) {
|
||||
caps.add(entry.command.cap);
|
||||
}
|
||||
commands.add(entry.command.command);
|
||||
}
|
||||
return {
|
||||
caps: [...caps].toSorted((left, right) => left.localeCompare(right)),
|
||||
commands: [...commands].toSorted((left, right) => left.localeCompare(right)),
|
||||
};
|
||||
}
|
||||
|
||||
export async function invokeRegisteredNodeHostCommand(
|
||||
command: string,
|
||||
paramsJSON?: string | null,
|
||||
): Promise<string | null> {
|
||||
const registry = getActivePluginRegistry();
|
||||
const match = (registry?.nodeHostCommands ?? []).find(
|
||||
(entry) => entry.command.command === command,
|
||||
);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
return await match.command.handle(paramsJSON);
|
||||
}
|
||||
Reference in New Issue
Block a user