openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
47 lines (46 loc) • 1.87 kB
JavaScript
//#region src/flows/health-check-registry.ts
const REGISTRY = /* @__PURE__ */ new Map();
/** Raised when two checks claim the same stable health-check id. */
var HealthCheckRegistrationError = class extends Error {
constructor(checkId) {
super(`health check already registered: ${checkId}`);
this.checkId = checkId;
this.code = "OC_DOCTOR_DUPLICATE_CHECK";
this.name = "HealthCheckRegistrationError";
}
};
/** Registers one health check for doctor lint/fix execution. */
function registerHealthCheck(check) {
if (REGISTRY.has(check.id)) throw new HealthCheckRegistrationError(check.id);
REGISTRY.set(check.id, check);
}
/** Returns registered checks in insertion order for deterministic doctor output. */
function listHealthChecks() {
return [...REGISTRY.values()];
}
/** Returns registered extension checks after rejecting any reserved core doctor id claims. */
function listExtensionHealthChecksForDoctor(coreChecks, unavailablePlugins = []) {
const coreIds = new Set(coreChecks.map((check) => check.id));
const registeredChecks = listHealthChecks();
for (const check of registeredChecks) if (check.id.startsWith("core/doctor/") || coreIds.has(check.id)) throw new HealthCheckRegistrationError(check.id);
const checks = [];
for (const check of registeredChecks) {
if (check.kind === "core") continue;
const unavailable = unavailablePlugins.find((finding) => finding.source !== void 0 && finding.source === check.source);
checks.push(unavailable ? {
...check,
detect: async () => [{
...unavailable,
checkId: check.id
}],
repair: void 0
} : check);
}
return checks;
}
/** Looks up a registered health check by its stable id. */
function getHealthCheck(id) {
return REGISTRY.get(id);
}
//#endregion
export { registerHealthCheck as i, listExtensionHealthChecksForDoctor as n, listHealthChecks as r, getHealthCheck as t };