From 54e5978f9d5c259c9fc84014a211b61fb15071fd Mon Sep 17 00:00:00 2001 From: Claudia Date: Tue, 17 Feb 2026 18:17:20 +0100 Subject: [PATCH] fix: deployment fixes (openclaw.id, configSchema, resolveConfig) --- index.ts | 59 ++++++++++++++++++++++---------------------- openclaw.plugin.json | 6 ++--- package.json | 7 ++++-- src/config.ts | 9 ++++--- 4 files changed, 43 insertions(+), 38 deletions(-) diff --git a/index.ts b/index.ts index fbbd8c5..ef94539 100644 --- a/index.ts +++ b/index.ts @@ -1,38 +1,39 @@ -// index.ts +// index.ts — OpenClaw Plugin Entry Point import { resolveConfig } from './src/config.js'; import { HookManager } from './src/hooks.js'; import type { OpenClawPluginApi } from './src/types.js'; -// The main entry point for the OpenClaw plugin. -// This function is called by the OpenClaw host during plugin loading. -export default (api: OpenClawPluginApi, context: { workspace: string }): void => { - const { pluginConfig, logger } = api; - const { workspace: openClawWorkspace } = context; +const plugin = { + id: 'openclaw-knowledge-engine', + name: 'OpenClaw Knowledge Engine', + description: 'Real-time knowledge extraction — entities, facts, and relationships from conversations', + version: '0.1.2', - // 1. Resolve and validate the configuration - const config = resolveConfig(pluginConfig, logger, openClawWorkspace); + register(api: OpenClawPluginApi): void { + const { pluginConfig, logger } = api; - if (!config) { - logger.error('Failed to initialize Knowledge Engine: Invalid configuration. The plugin will be disabled.'); - return; - } + // 1. Resolve and validate the configuration + const config = resolveConfig(pluginConfig, logger); + if (!config) { + logger.error('Knowledge Engine: Invalid configuration — plugin disabled.'); + return; + } + if (!config.enabled) { + logger.info('[knowledge-engine] Disabled via config'); + return; + } - if (!config.enabled) { - logger.info('Knowledge Engine is disabled in the configuration.'); - return; - } - - // 2. Initialize the Hook Manager with the resolved config - try { - const hookManager = new HookManager(api, config); - - // 3. Register all the event hooks - hookManager.registerHooks(); - - logger.info('Knowledge Engine plugin initialized successfully.'); - - } catch (err) { - logger.error('An unexpected error occurred during Knowledge Engine initialization.', err as Error); - } + // 2. Initialize the Hook Manager and register hooks + try { + logger.info('[knowledge-engine] Registering hooks...'); + const hookManager = new HookManager(api, config); + hookManager.registerHooks(); + logger.info('[knowledge-engine] Ready'); + } catch (err) { + logger.error('[knowledge-engine] Failed to initialize', err as Error); + } + }, }; + +export default plugin; diff --git a/openclaw.plugin.json b/openclaw.plugin.json index 9fb1c78..79fe5b4 100644 --- a/openclaw.plugin.json +++ b/openclaw.plugin.json @@ -1,6 +1,6 @@ { - "id": "@vainplex/openclaw-knowledge-engine", - "config": { + "id": "openclaw-knowledge-engine", + "configSchema": { "enabled": { "type": "boolean", "default": true, @@ -122,4 +122,4 @@ } } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index 17e4763..25049c8 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,10 @@ "url": "https://github.com/alberthild/openclaw-knowledge-engine.git" }, "openclaw": { - "id": "@vainplex/openclaw-knowledge-engine" + "id": "openclaw-knowledge-engine", + "extensions": [ + "./dist/index.js" + ] }, "devDependencies": { "@types/node": "^20.11.24", @@ -33,4 +36,4 @@ "tsx": "^4.7.1" }, "type": "module" -} +} \ No newline at end of file diff --git a/src/config.ts b/src/config.ts index 5648faf..af11f3c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -95,12 +95,13 @@ function resolveTilde(ws: string, logger: Logger, fallback: string): string { * @returns A fully resolved KnowledgeConfig, or null if validation fails. */ export function resolveConfig( - userConfig: Record, + userConfig: Record | undefined | null, logger: Logger, - openClawWorkspace: string + openClawWorkspace?: string ): KnowledgeConfig | null { - const config = mergeConfigDefaults(userConfig, openClawWorkspace); - const fallbackWs = path.join(openClawWorkspace, 'knowledge-engine'); + const ws = openClawWorkspace ?? process.cwd(); + const config = mergeConfigDefaults(userConfig ?? {}, ws); + const fallbackWs = path.join(ws, 'knowledge-engine'); config.workspace = resolveTilde(config.workspace, logger, fallbackWs); const errors = validateConfig(config);