Merge f5bedd1736 into 4583f88626
This commit is contained in:
commit
2b40d6c639
@ -29,9 +29,9 @@ export function initializeGlobalHookRunner(registry: PluginRegistry): void {
|
|||||||
catchErrors: true,
|
catchErrors: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const hookCount = registry.hooks.length;
|
const typedHookCount = registry.typedHooks.length;
|
||||||
if (hookCount > 0) {
|
if (typedHookCount > 0) {
|
||||||
log.info(`hook runner initialized with ${hookCount} registered hooks`);
|
log.info(`hook runner initialized with ${typedHookCount} registered hooks`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,26 +7,27 @@ import type {
|
|||||||
} from "../gateway/server-methods/types.js";
|
} from "../gateway/server-methods/types.js";
|
||||||
import { registerInternalHook } from "../hooks/internal-hooks.js";
|
import { registerInternalHook } from "../hooks/internal-hooks.js";
|
||||||
import { resolveUserPath } from "../utils.js";
|
import { resolveUserPath } from "../utils.js";
|
||||||
import type {
|
import {
|
||||||
MoltbotPluginApi,
|
TYPED_HOOK_NAMES,
|
||||||
MoltbotPluginChannelRegistration,
|
type MoltbotPluginApi,
|
||||||
MoltbotPluginCliRegistrar,
|
type MoltbotPluginChannelRegistration,
|
||||||
MoltbotPluginCommandDefinition,
|
type MoltbotPluginCliRegistrar,
|
||||||
MoltbotPluginHttpHandler,
|
type MoltbotPluginCommandDefinition,
|
||||||
MoltbotPluginHttpRouteHandler,
|
type MoltbotPluginHttpHandler,
|
||||||
MoltbotPluginHookOptions,
|
type MoltbotPluginHttpRouteHandler,
|
||||||
ProviderPlugin,
|
type MoltbotPluginHookOptions,
|
||||||
MoltbotPluginService,
|
type ProviderPlugin,
|
||||||
MoltbotPluginToolContext,
|
type MoltbotPluginService,
|
||||||
MoltbotPluginToolFactory,
|
type MoltbotPluginToolContext,
|
||||||
PluginConfigUiHint,
|
type MoltbotPluginToolFactory,
|
||||||
PluginDiagnostic,
|
type PluginConfigUiHint,
|
||||||
PluginLogger,
|
type PluginDiagnostic,
|
||||||
PluginOrigin,
|
type PluginLogger,
|
||||||
PluginKind,
|
type PluginOrigin,
|
||||||
PluginHookName,
|
type PluginKind,
|
||||||
PluginHookHandlerMap,
|
type PluginHookName,
|
||||||
PluginHookRegistration as TypedPluginHookRegistration,
|
type PluginHookHandlerMap,
|
||||||
|
type PluginHookRegistration as TypedPluginHookRegistration,
|
||||||
} from "./types.js";
|
} from "./types.js";
|
||||||
import { registerPluginCommand } from "./commands.js";
|
import { registerPluginCommand } from "./commands.js";
|
||||||
import type { PluginRuntime } from "./runtime/types.js";
|
import type { PluginRuntime } from "./runtime/types.js";
|
||||||
@ -252,6 +253,22 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
|
|||||||
source: record.source,
|
source: record.source,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Bridge to typed hooks: if any event matches a PluginHookName, also register
|
||||||
|
// in typedHooks so the hook runner can find it. This allows plugins to use
|
||||||
|
// either api.registerHook() or api.on() for typed hooks like message_received.
|
||||||
|
for (const event of normalizedEvents) {
|
||||||
|
if (TYPED_HOOK_NAMES.has(event as PluginHookName)) {
|
||||||
|
registry.typedHooks.push({
|
||||||
|
pluginId: record.id,
|
||||||
|
hookName: event as PluginHookName,
|
||||||
|
handler: handler as unknown as PluginHookHandlerMap[PluginHookName],
|
||||||
|
priority: opts?.priority,
|
||||||
|
source: record.source,
|
||||||
|
} as TypedPluginHookRegistration);
|
||||||
|
record.hookCount += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const hookSystemEnabled = config?.hooks?.internal?.enabled === true;
|
const hookSystemEnabled = config?.hooks?.internal?.enabled === true;
|
||||||
if (!hookSystemEnabled || opts?.register === false) {
|
if (!hookSystemEnabled || opts?.register === false) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -81,6 +81,7 @@ export type MoltbotPluginHookOptions = {
|
|||||||
name?: string;
|
name?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
register?: boolean;
|
register?: boolean;
|
||||||
|
priority?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ProviderAuthKind = "oauth" | "api_key" | "token" | "device_code" | "custom";
|
export type ProviderAuthKind = "oauth" | "api_key" | "token" | "device_code" | "custom";
|
||||||
@ -302,6 +303,23 @@ export type PluginHookName =
|
|||||||
| "gateway_start"
|
| "gateway_start"
|
||||||
| "gateway_stop";
|
| "gateway_stop";
|
||||||
|
|
||||||
|
export const TYPED_HOOK_NAMES: Set<PluginHookName> = new Set<PluginHookName>([
|
||||||
|
"before_agent_start",
|
||||||
|
"agent_end",
|
||||||
|
"before_compaction",
|
||||||
|
"after_compaction",
|
||||||
|
"message_received",
|
||||||
|
"message_sending",
|
||||||
|
"message_sent",
|
||||||
|
"before_tool_call",
|
||||||
|
"after_tool_call",
|
||||||
|
"tool_result_persist",
|
||||||
|
"session_start",
|
||||||
|
"session_end",
|
||||||
|
"gateway_start",
|
||||||
|
"gateway_stop",
|
||||||
|
]);
|
||||||
|
|
||||||
// Agent context shared across agent hooks
|
// Agent context shared across agent hooks
|
||||||
export type PluginHookAgentContext = {
|
export type PluginHookAgentContext = {
|
||||||
agentId?: string;
|
agentId?: string;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user