mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 23:40:44 +00:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { createRequire } from "node:module";
|
|
import type { CliBackendPlugin } from "./cli-backend.types.js";
|
|
|
|
export type PluginCliBackendEntry = CliBackendPlugin & {
|
|
pluginId: string;
|
|
};
|
|
|
|
type PluginRuntimeModule = Pick<typeof import("./runtime.js"), "getActivePluginRegistry">;
|
|
|
|
const require = createRequire(import.meta.url);
|
|
const RUNTIME_MODULE_CANDIDATES = ["./runtime.js", "./runtime.ts"] as const;
|
|
|
|
let pluginRuntimeModule: PluginRuntimeModule | undefined;
|
|
|
|
function loadPluginRuntime(): PluginRuntimeModule | null {
|
|
if (pluginRuntimeModule) {
|
|
return pluginRuntimeModule;
|
|
}
|
|
for (const candidate of RUNTIME_MODULE_CANDIDATES) {
|
|
try {
|
|
pluginRuntimeModule = require(candidate) as PluginRuntimeModule;
|
|
return pluginRuntimeModule;
|
|
} catch {
|
|
// Try source/runtime candidates in order.
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function resolveRuntimeCliBackends(): PluginCliBackendEntry[] {
|
|
return (loadPluginRuntime()?.getActivePluginRegistry()?.cliBackends ?? []).map((entry) =>
|
|
Object.assign({}, entry.backend, { pluginId: entry.pluginId }),
|
|
);
|
|
}
|