Files
HarborForge.OpenclawPlugin/plugin/core/monitor-bridge.js
zhi e7ba982128 feat: push OpenClaw metadata to Monitor bridge periodically
- MonitorBridgeClient gains pushOpenClawMeta() method for POST /openclaw
- OpenClawMeta interface defines version/plugin_version/agents payload
- Plugin pushes metadata on gateway_start (delayed 2s) and periodically
- Interval aligns with reportIntervalSec (default 30s)
- Pushes are non-fatal — plugin continues if Monitor is unreachable
- Interval cleanup on gateway_stop
- Updated monitor-server-connector-plan.md with new architecture
2026-03-22 01:37:21 +00:00

66 lines
2.1 KiB
JavaScript

"use strict";
/**
* Monitor Bridge Client
*
* Queries the local HarborForge.Monitor bridge endpoint on MONITOR_PORT
* to enrich plugin telemetry with host/hardware data.
*
* If the bridge is unreachable, all methods return null gracefully —
* the plugin continues to function without Monitor data.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.MonitorBridgeClient = void 0;
class MonitorBridgeClient {
baseUrl;
timeoutMs;
constructor(port, timeoutMs = 3000) {
this.baseUrl = `http://127.0.0.1:${port}`;
this.timeoutMs = timeoutMs;
}
async health() {
return this.fetchJson('/health');
}
async telemetry() {
return this.fetchJson('/telemetry');
}
/**
* POST OpenClaw metadata to the Monitor bridge so it can enrich
* its heartbeat uploads with OpenClaw version, plugin version,
* and agent information.
*/
async pushOpenClawMeta(meta) {
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
const response = await fetch(`${this.baseUrl}/openclaw`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(meta),
signal: controller.signal,
});
clearTimeout(timeout);
return response.ok;
}
catch {
return false;
}
}
async fetchJson(path) {
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
const response = await fetch(`${this.baseUrl}${path}`, {
signal: controller.signal,
});
clearTimeout(timeout);
if (!response.ok)
return null;
return (await response.json());
}
catch {
return null;
}
}
}
exports.MonitorBridgeClient = MonitorBridgeClient;
//# sourceMappingURL=monitor-bridge.js.map