refactor(plugin): read config via api.pluginConfig and api.config
- Mirror dirigent plugin registration pattern - Read base config from api.pluginConfig - Read live config from api.config.plugins.entries.harborforge-monitor.config - Support gateway_start/gateway_stop lifecycle only - Compile nested plugin/core files
This commit is contained in:
39
plugin/core/live-config.ts
Normal file
39
plugin/core/live-config.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
export interface HarborForgeMonitorConfig {
|
||||
enabled?: boolean;
|
||||
backendUrl?: string;
|
||||
identifier?: string;
|
||||
apiKey?: string;
|
||||
reportIntervalSec?: number;
|
||||
httpFallbackIntervalSec?: number;
|
||||
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
||||
}
|
||||
|
||||
interface OpenClawPluginApiLike {
|
||||
config?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export function getLivePluginConfig(
|
||||
api: OpenClawPluginApiLike,
|
||||
fallback: HarborForgeMonitorConfig
|
||||
): HarborForgeMonitorConfig {
|
||||
const root = (api.config as Record<string, unknown>) || {};
|
||||
const plugins = (root.plugins as Record<string, unknown>) || {};
|
||||
const entries = (plugins.entries as Record<string, unknown>) || {};
|
||||
const entry = (entries['harborforge-monitor'] as Record<string, unknown>) || {};
|
||||
const cfg = (entry.config as Record<string, unknown>) || {};
|
||||
|
||||
if (Object.keys(cfg).length > 0 || Object.keys(entry).length > 0) {
|
||||
return {
|
||||
...fallback,
|
||||
...cfg,
|
||||
enabled:
|
||||
typeof cfg.enabled === 'boolean'
|
||||
? cfg.enabled
|
||||
: typeof entry.enabled === 'boolean'
|
||||
? entry.enabled
|
||||
: fallback.enabled,
|
||||
} as HarborForgeMonitorConfig;
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
||||
Reference in New Issue
Block a user