From c7b6d6a14e83ab8ce0ae71eeb22622d259ec72c6 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 19:05:00 +0000 Subject: [PATCH] refactor(plugins): reuse createEmptyPluginRegistry --- src/gateway/server.impl.ts | 18 ++---------------- src/plugins/runtime.ts | 22 +++------------------- 2 files changed, 5 insertions(+), 35 deletions(-) diff --git a/src/gateway/server.impl.ts b/src/gateway/server.impl.ts index 553131377ec..0e70546467b 100644 --- a/src/gateway/server.impl.ts +++ b/src/gateway/server.impl.ts @@ -1,6 +1,5 @@ import path from "node:path"; import type { CanvasHostServer } from "../canvas-host/server.js"; -import type { PluginRegistry } from "../plugins/registry.js"; import type { PluginServicesHandle } from "../plugins/services.js"; import type { RuntimeEnv } from "../runtime.js"; import type { ControlUiRootState } from "./control-ui.js"; @@ -45,6 +44,7 @@ import { scheduleGatewayUpdateCheck } from "../infra/update-startup.js"; import { startDiagnosticHeartbeat, stopDiagnosticHeartbeat } from "../logging/diagnostic.js"; import { createSubsystemLogger, runtimeForLogger } from "../logging/subsystem.js"; import { getGlobalHookRunner, runGlobalGatewayStopSafely } from "../plugins/hook-runner-global.js"; +import { createEmptyPluginRegistry } from "../plugins/registry.js"; import { getTotalQueueSize } from "../process/command-queue.js"; import { runOnboardingWizard } from "../wizard/onboarding.js"; import { createAuthRateLimiter, type AuthRateLimiter } from "./auth-rate-limit.js"; @@ -239,21 +239,7 @@ export async function startGatewayServer( const defaultAgentId = resolveDefaultAgentId(cfgAtStart); const defaultWorkspaceDir = resolveAgentWorkspaceDir(cfgAtStart, defaultAgentId); const baseMethods = listGatewayMethods(); - const emptyPluginRegistry: PluginRegistry = { - plugins: [], - tools: [], - hooks: [], - typedHooks: [], - channels: [], - providers: [], - gatewayHandlers: {}, - httpHandlers: [], - httpRoutes: [], - cliRegistrars: [], - services: [], - commands: [], - diagnostics: [], - }; + const emptyPluginRegistry = createEmptyPluginRegistry(); const { pluginRegistry, gatewayMethods: baseGatewayMethods } = minimalTestGateway ? { pluginRegistry: emptyPluginRegistry, gatewayMethods: baseMethods } : loadGatewayPlugins({ diff --git a/src/plugins/runtime.ts b/src/plugins/runtime.ts index cebd88d415e..10177d74f46 100644 --- a/src/plugins/runtime.ts +++ b/src/plugins/runtime.ts @@ -1,20 +1,4 @@ -import type { PluginRegistry } from "./registry.js"; - -const createEmptyRegistry = (): PluginRegistry => ({ - plugins: [], - tools: [], - hooks: [], - typedHooks: [], - channels: [], - providers: [], - gatewayHandlers: {}, - httpHandlers: [], - httpRoutes: [], - cliRegistrars: [], - services: [], - commands: [], - diagnostics: [], -}); +import { createEmptyPluginRegistry, type PluginRegistry } from "./registry.js"; const REGISTRY_STATE = Symbol.for("openclaw.pluginRegistryState"); @@ -29,7 +13,7 @@ const state: RegistryState = (() => { }; if (!globalState[REGISTRY_STATE]) { globalState[REGISTRY_STATE] = { - registry: createEmptyRegistry(), + registry: createEmptyPluginRegistry(), key: null, }; } @@ -47,7 +31,7 @@ export function getActivePluginRegistry(): PluginRegistry | null { export function requireActivePluginRegistry(): PluginRegistry { if (!state.registry) { - state.registry = createEmptyRegistry(); + state.registry = createEmptyPluginRegistry(); } return state.registry; }