fix: deployment fixes (openclaw.id, configSchema, resolveConfig)
This commit is contained in:
parent
53dd147475
commit
54e5978f9d
4 changed files with 43 additions and 38 deletions
59
index.ts
59
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;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"id": "@vainplex/openclaw-knowledge-engine",
|
||||
"config": {
|
||||
"id": "openclaw-knowledge-engine",
|
||||
"configSchema": {
|
||||
"enabled": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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<string, unknown>,
|
||||
userConfig: Record<string, unknown> | 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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue