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 { resolveConfig } from './src/config.js';
|
||||||
import { HookManager } from './src/hooks.js';
|
import { HookManager } from './src/hooks.js';
|
||||||
import type { OpenClawPluginApi } from './src/types.js';
|
import type { OpenClawPluginApi } from './src/types.js';
|
||||||
|
|
||||||
// The main entry point for the OpenClaw plugin.
|
const plugin = {
|
||||||
// This function is called by the OpenClaw host during plugin loading.
|
id: 'openclaw-knowledge-engine',
|
||||||
export default (api: OpenClawPluginApi, context: { workspace: string }): void => {
|
name: 'OpenClaw Knowledge Engine',
|
||||||
const { pluginConfig, logger } = api;
|
description: 'Real-time knowledge extraction — entities, facts, and relationships from conversations',
|
||||||
const { workspace: openClawWorkspace } = context;
|
version: '0.1.2',
|
||||||
|
|
||||||
// 1. Resolve and validate the configuration
|
register(api: OpenClawPluginApi): void {
|
||||||
const config = resolveConfig(pluginConfig, logger, openClawWorkspace);
|
const { pluginConfig, logger } = api;
|
||||||
|
|
||||||
if (!config) {
|
// 1. Resolve and validate the configuration
|
||||||
logger.error('Failed to initialize Knowledge Engine: Invalid configuration. The plugin will be disabled.');
|
const config = resolveConfig(pluginConfig, logger);
|
||||||
return;
|
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) {
|
// 2. Initialize the Hook Manager and register hooks
|
||||||
logger.info('Knowledge Engine is disabled in the configuration.');
|
try {
|
||||||
return;
|
logger.info('[knowledge-engine] Registering hooks...');
|
||||||
}
|
const hookManager = new HookManager(api, config);
|
||||||
|
hookManager.registerHooks();
|
||||||
// 2. Initialize the Hook Manager with the resolved config
|
logger.info('[knowledge-engine] Ready');
|
||||||
try {
|
} catch (err) {
|
||||||
const hookManager = new HookManager(api, config);
|
logger.error('[knowledge-engine] Failed to initialize', err as Error);
|
||||||
|
}
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default plugin;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"id": "@vainplex/openclaw-knowledge-engine",
|
"id": "openclaw-knowledge-engine",
|
||||||
"config": {
|
"configSchema": {
|
||||||
"enabled": {
|
"enabled": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": true,
|
"default": true,
|
||||||
|
|
@ -122,4 +122,4 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -24,7 +24,10 @@
|
||||||
"url": "https://github.com/alberthild/openclaw-knowledge-engine.git"
|
"url": "https://github.com/alberthild/openclaw-knowledge-engine.git"
|
||||||
},
|
},
|
||||||
"openclaw": {
|
"openclaw": {
|
||||||
"id": "@vainplex/openclaw-knowledge-engine"
|
"id": "openclaw-knowledge-engine",
|
||||||
|
"extensions": [
|
||||||
|
"./dist/index.js"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.11.24",
|
"@types/node": "^20.11.24",
|
||||||
|
|
@ -33,4 +36,4 @@
|
||||||
"tsx": "^4.7.1"
|
"tsx": "^4.7.1"
|
||||||
},
|
},
|
||||||
"type": "module"
|
"type": "module"
|
||||||
}
|
}
|
||||||
|
|
@ -95,12 +95,13 @@ function resolveTilde(ws: string, logger: Logger, fallback: string): string {
|
||||||
* @returns A fully resolved KnowledgeConfig, or null if validation fails.
|
* @returns A fully resolved KnowledgeConfig, or null if validation fails.
|
||||||
*/
|
*/
|
||||||
export function resolveConfig(
|
export function resolveConfig(
|
||||||
userConfig: Record<string, unknown>,
|
userConfig: Record<string, unknown> | undefined | null,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
openClawWorkspace: string
|
openClawWorkspace?: string
|
||||||
): KnowledgeConfig | null {
|
): KnowledgeConfig | null {
|
||||||
const config = mergeConfigDefaults(userConfig, openClawWorkspace);
|
const ws = openClawWorkspace ?? process.cwd();
|
||||||
const fallbackWs = path.join(openClawWorkspace, 'knowledge-engine');
|
const config = mergeConfigDefaults(userConfig ?? {}, ws);
|
||||||
|
const fallbackWs = path.join(ws, 'knowledge-engine');
|
||||||
config.workspace = resolveTilde(config.workspace, logger, fallbackWs);
|
config.workspace = resolveTilde(config.workspace, logger, fallbackWs);
|
||||||
|
|
||||||
const errors = validateConfig(config);
|
const errors = validateConfig(config);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue