mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 01:31:08 +00:00
fix(plugins): split hook runner registry types
This commit is contained in:
22
src/plugins/hook-registry.types.ts
Normal file
22
src/plugins/hook-registry.types.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import type { HookEntry } from "../hooks/types.js";
|
||||
import type { PluginHookRegistration as TypedPluginHookRegistration } from "./types.js";
|
||||
|
||||
export type PluginLegacyHookRegistration = {
|
||||
pluginId: string;
|
||||
entry: HookEntry;
|
||||
events: string[];
|
||||
source: string;
|
||||
rootDir?: string;
|
||||
};
|
||||
|
||||
export type HookRunnerRegistry = {
|
||||
hooks: PluginLegacyHookRegistration[];
|
||||
typedHooks: TypedPluginHookRegistration[];
|
||||
};
|
||||
|
||||
export type GlobalHookRunnerRegistry = HookRunnerRegistry & {
|
||||
plugins: Array<{
|
||||
id: string;
|
||||
status: "loaded" | "disabled" | "error";
|
||||
}>;
|
||||
};
|
||||
@@ -7,13 +7,13 @@
|
||||
|
||||
import { createSubsystemLogger } from "../logging/subsystem.js";
|
||||
import { resolveGlobalSingleton } from "../shared/global-singleton.js";
|
||||
import type { GlobalHookRunnerRegistry } from "./hook-registry.types.js";
|
||||
import { createHookRunner, type HookRunner } from "./hooks.js";
|
||||
import type { PluginRegistry } from "./registry-types.js";
|
||||
import type { PluginHookGatewayContext, PluginHookGatewayStopEvent } from "./types.js";
|
||||
|
||||
type HookRunnerGlobalState = {
|
||||
hookRunner: HookRunner | null;
|
||||
registry: PluginRegistry | null;
|
||||
registry: GlobalHookRunnerRegistry | null;
|
||||
};
|
||||
|
||||
const hookRunnerGlobalStateKey = Symbol.for("openclaw.plugins.hook-runner-global-state");
|
||||
@@ -29,7 +29,7 @@ const getLog = () => createSubsystemLogger("plugins");
|
||||
* Initialize the global hook runner with a plugin registry.
|
||||
* Called once when plugins are loaded during gateway startup.
|
||||
*/
|
||||
export function initializeGlobalHookRunner(registry: PluginRegistry): void {
|
||||
export function initializeGlobalHookRunner(registry: GlobalHookRunnerRegistry): void {
|
||||
const state = getState();
|
||||
const log = getLog();
|
||||
state.registry = registry;
|
||||
@@ -63,7 +63,7 @@ export function getGlobalHookRunner(): HookRunner | null {
|
||||
* Get the global plugin registry.
|
||||
* Returns null if plugins haven't been loaded yet.
|
||||
*/
|
||||
export function getGlobalPluginRegistry(): PluginRegistry | null {
|
||||
export function getGlobalPluginRegistry(): GlobalHookRunnerRegistry | null {
|
||||
return getState().registry;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
import { formatErrorMessage } from "../infra/errors.js";
|
||||
import { concatOptionalTextSegments } from "../shared/text/join-segments.js";
|
||||
import type { PluginRegistry } from "./registry.js";
|
||||
import type { GlobalHookRunnerRegistry, HookRunnerRegistry } from "./hook-registry.types.js";
|
||||
import type {
|
||||
PluginHookAfterCompactionEvent,
|
||||
PluginHookAfterToolCallEvent,
|
||||
@@ -184,7 +184,7 @@ type SyncHookResult<K extends SyncHookName> = ReturnType<SyncHookHandler<K>>;
|
||||
* Get hooks for a specific hook name, sorted by priority (higher first).
|
||||
*/
|
||||
function getHooksForName<K extends PluginHookName>(
|
||||
registry: PluginRegistry,
|
||||
registry: HookRunnerRegistry,
|
||||
hookName: K,
|
||||
): PluginHookRegistration<K>[] {
|
||||
return (registry.typedHooks as PluginHookRegistration<K>[])
|
||||
@@ -193,7 +193,7 @@ function getHooksForName<K extends PluginHookName>(
|
||||
}
|
||||
|
||||
function getHooksForNameAndPlugin<K extends PluginHookName>(
|
||||
registry: PluginRegistry,
|
||||
registry: HookRunnerRegistry,
|
||||
hookName: K,
|
||||
pluginId: string,
|
||||
): PluginHookRegistration<K>[] {
|
||||
@@ -203,7 +203,10 @@ function getHooksForNameAndPlugin<K extends PluginHookName>(
|
||||
/**
|
||||
* Create a hook runner for a specific registry.
|
||||
*/
|
||||
export function createHookRunner(registry: PluginRegistry, options: HookRunnerOptions = {}) {
|
||||
export function createHookRunner(
|
||||
registry: GlobalHookRunnerRegistry,
|
||||
options: HookRunnerOptions = {},
|
||||
) {
|
||||
const logger = options.logger;
|
||||
const catchErrors = options.catchErrors ?? true;
|
||||
const failurePolicyByHook = options.failurePolicyByHook ?? {};
|
||||
|
||||
Reference in New Issue
Block a user