mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 03:00:42 +00:00
feat: add plugin text transforms
This commit is contained in:
33
src/plugins/text-transforms.runtime.ts
Normal file
33
src/plugins/text-transforms.runtime.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { createRequire } from "node:module";
|
||||
import { mergePluginTextTransforms } from "../agents/plugin-text-transforms.js";
|
||||
import type { PluginTextTransforms } from "./types.js";
|
||||
|
||||
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 resolveRuntimeTextTransforms(): PluginTextTransforms | undefined {
|
||||
return mergePluginTextTransforms(
|
||||
...(loadPluginRuntime()
|
||||
?.getActivePluginRegistry()
|
||||
?.textTransforms.map((entry) => entry.transforms) ?? []),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user