diff --git a/src/plugins/registry.ts b/src/plugins/registry.ts index ac528582f9a..5b35259fed7 100644 --- a/src/plugins/registry.ts +++ b/src/plugins/registry.ts @@ -422,6 +422,7 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) { handler: Parameters[1], opts: OpenClawPluginHookOptions | undefined, config: OpenClawPluginApi["config"], + pluginConfig: unknown, ) => { const eventList = Array.isArray(events) ? events : [events]; const normalizedEvents = eventList.map((event) => event.trim()).filter(Boolean); @@ -499,8 +500,16 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) { handler: Parameters[1]; }> = []; for (const event of normalizedEvents) { - registerInternalHook(event, handler); - nextRegistrations.push({ event, handler }); + // Wrap handler to inject pluginConfig into event context + // so plugins can access their configured pluginConfig at invocation time + const wrappedHandler: typeof handler = async (evt) => { + if (evt.context && typeof evt.context === "object") { + (evt.context as Record).pluginConfig = pluginConfig; + } + return handler(evt); + }; + registerInternalHook(event, wrappedHandler); + nextRegistrations.push({ event, handler: wrappedHandler }); } activePluginHookRegistrations.set(hookName, nextRegistrations); const rollbackEntries = pluginHookRollback.get(record.id) ?? []; @@ -1466,7 +1475,7 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) { ? { registerTool: (tool, opts) => registerTool(record, tool, opts), registerHook: (events, handler, opts) => - registerHook(record, events, handler, opts, params.config), + registerHook(record, events, handler, opts, params.config, params.pluginConfig), registerHttpRoute: (routeParams) => registerHttpRoute(record, routeParams), registerProvider: (provider) => registerProvider(record, provider), registerAgentHarness: (harness) => registerAgentHarness(record, harness),