Integrate plugin with local monitor bridge
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
import { hostname, freemem, totalmem, uptime, loadavg, platform } from 'os';
|
||||
import { getLivePluginConfig, type HarborForgeMonitorConfig } from './core/live-config';
|
||||
import { MonitorBridgeClient } from './core/monitor-bridge';
|
||||
|
||||
interface PluginAPI {
|
||||
logger: {
|
||||
@@ -50,6 +51,16 @@ export default {
|
||||
return getLivePluginConfig(api, baseConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the monitor bridge client if monitorPort is configured.
|
||||
*/
|
||||
function getBridgeClient(): MonitorBridgeClient | null {
|
||||
const live = resolveConfig() as any;
|
||||
const port = live.monitorPort;
|
||||
if (!port || port <= 0) return null;
|
||||
return new MonitorBridgeClient(port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect current system telemetry snapshot.
|
||||
* This data is exposed to the Monitor bridge when it queries the plugin.
|
||||
@@ -99,6 +110,16 @@ export default {
|
||||
},
|
||||
async execute() {
|
||||
const live = resolveConfig();
|
||||
const bridgeClient = getBridgeClient();
|
||||
let monitorBridge = null;
|
||||
|
||||
if (bridgeClient) {
|
||||
const health = await bridgeClient.health();
|
||||
monitorBridge = health
|
||||
? { connected: true, ...health }
|
||||
: { connected: false, error: 'Monitor bridge unreachable' };
|
||||
}
|
||||
|
||||
return {
|
||||
enabled: live.enabled !== false,
|
||||
config: {
|
||||
@@ -108,6 +129,7 @@ export default {
|
||||
reportIntervalSec: live.reportIntervalSec,
|
||||
hasApiKey: Boolean(live.apiKey),
|
||||
},
|
||||
monitorBridge,
|
||||
telemetry: collectTelemetry(),
|
||||
};
|
||||
},
|
||||
@@ -126,6 +148,33 @@ export default {
|
||||
},
|
||||
}));
|
||||
|
||||
// Tool: query Monitor bridge for host hardware telemetry
|
||||
api.registerTool(() => ({
|
||||
name: 'harborforge_monitor_telemetry',
|
||||
description: 'Query HarborForge Monitor bridge for host hardware telemetry (CPU, memory, disk, etc.)',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
properties: {},
|
||||
},
|
||||
async execute() {
|
||||
const bridgeClient = getBridgeClient();
|
||||
if (!bridgeClient) {
|
||||
return {
|
||||
error: 'Monitor bridge not configured (monitorPort not set or 0)',
|
||||
};
|
||||
}
|
||||
|
||||
const data = await bridgeClient.telemetry();
|
||||
if (!data) {
|
||||
return {
|
||||
error: 'Monitor bridge unreachable',
|
||||
};
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
}));
|
||||
|
||||
logger.info('HarborForge plugin registered (id: harbor-forge)');
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user