openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
158 lines (157 loc) • 8.1 kB
JavaScript
import { i as asOptionalObjectRecord } from "./record-coerce-DItp3I4t.js";
import { l as normalizePluginsConfig, s as normalizePluginId } from "./config-state-BkU1frVq.js";
import { t as loadBundledPluginManifestRegistry } from "./manifest-registry-DCCgYk7q.js";
import { t as MissingPublicSurfaceError } from "./facade-loader-CVT-xVW5.js";
import { n as loadBundledPluginPublicArtifactModuleSync, r as loadPluginPublicArtifactModuleSync, t as loadBundledPluginPublicArtifactModuleFromCandidatesSync } from "./public-surface-loader-i-BsDNoA.js";
import { i as passesManifestOwnerBasePolicy } from "./manifest-owner-policy-D98oU3cV.js";
import { n as loadPluginManifestRegistryForPluginRegistry } from "./plugin-registry-contributions-BwuDvm89.js";
import "./plugin-registry-DD_0nL_t.js";
import { i as resolveProviderPolicySurface } from "./provider-public-artifacts-Bone7gkJ.js";
import { t as collectConfiguredAgentHarnessRuntimes } from "./harness-runtimes-BrMGAsrQ.js";
import { t as collectConfiguredWorkerProviderIds } from "./worker-provider-config-Cq1C8T7E.js";
import { t as listBundledWorkerProviderOwners } from "./worker-provider-manifest-p8jUgDjU.js";
import { o as registerHealthCheck, r as getHealthCheck } from "./health-check-registry-CBs_fO63.js";
//#region src/flows/bundled-health-checks.ts
function defineHealthCheckRegistration(register, updateReadiness) {
const registerCheck = updateReadiness ? (check) => registerHealthCheck(Object.assign(check, { updateReadiness })) : registerHealthCheck;
return {
updateReadiness,
register: (params) => register(params, registerCheck)
};
}
const HEALTH_CHECK_REGISTRATIONS = [
defineHealthCheckRegistration(registerMemoryCoreHealthChecks, "post-plugin"),
defineHealthCheckRegistration(registerCodexHealthChecks),
defineHealthCheckRegistration(registerPolicyHealthChecks),
defineHealthCheckRegistration(registerCuaHealthChecks),
defineHealthCheckRegistration(registerBundledWorkerProviderHealthChecks)
];
function loadMemoryCoreHealthApi() {
return loadBundledPluginPublicArtifactModuleSync({
dirName: "memory-core",
artifactBasename: "doctor-health-api.js"
});
}
function resolveBundledHealthCheckPluginStateMode(selection) {
if (selection.updateReadiness !== void 0) return "isolated";
if (selection.includeAllChecks !== true && (selection.onlyIds === void 0 || selection.onlyIds.length === 0)) return "direct";
const isolatedIds = new Set(loadMemoryCoreHealthApi().pluginStateIsolatedDoctorCheckIds ?? []);
const skippedIds = new Set(selection.skipIds ?? []);
const selectedOnlyIds = [...new Set(selection.onlyIds ?? [])].filter((id) => !skippedIds.has(id));
if ((selectedOnlyIds.length > 0 ? selectedOnlyIds.filter((id) => isolatedIds.has(id)) : [...isolatedIds].filter((id) => !skippedIds.has(id))).length === 0) return "direct";
if (selectedOnlyIds.length > 0 && selectedOnlyIds.every((id) => isolatedIds.has(id))) return "deferred";
return "isolated";
}
/** Registers bundled health checks that are explicitly enabled by config and owner policy. */
function registerBundledHealthChecks(params) {
for (const registration of HEALTH_CHECK_REGISTRATIONS) {
if (params.updateReadiness !== void 0 && registration.updateReadiness !== params.updateReadiness) continue;
registration.register(params);
}
}
function registerMemoryCoreHealthChecks(params, registerCheck) {
const env = params.env ?? process.env;
loadMemoryCoreHealthApi().registerMemoryCoreDoctorChecks?.({
getHealthCheck,
registerHealthCheck: registerCheck,
async inspectEmbeddingProviderSetup(providerParams) {
const inspect = async (pluginMetadataEnv) => {
const manifestRegistry = loadPluginManifestRegistryForPluginRegistry({
config: params.cfg,
workspaceDir: params.cwd,
env: pluginMetadataEnv
});
const inspector = resolveProviderPolicySurface(providerParams.provider, { manifestRegistry })?.inspectEmbeddingProviderSetup;
return inspector ? await inspector({
...providerParams,
env: pluginMetadataEnv
}) : void 0;
};
return params.runWithPluginStateSnapshot ? await params.runWithPluginStateSnapshot(inspect) : await inspect(env);
},
memoryCoreActive: isMemoryCoreActive(params.cfg)
});
}
function registerCodexHealthChecks(params, registerCheck) {
const env = params.env ?? process.env;
if (shouldRegisterCodexManagedHealth(params.cfg)) {
const owner = loadPluginManifestRegistryForPluginRegistry({
config: params.cfg,
workspaceDir: params.cwd,
env,
pluginIds: ["codex"]
}).plugins.find((plugin) => plugin.id === "codex");
if (!owner || owner.origin !== "bundled" && owner.trustedOfficialInstall !== true) throw new MissingPublicSurfaceError("Unable to resolve Codex doctor health API: install the official Codex plugin with openclaw plugins install @openclaw/codex");
if (owner.doctorHealthChecks === true) loadPluginPublicArtifactModuleSync({
pluginRoot: owner.rootDir,
artifactBasename: "api.js",
origin: owner.origin === "bundled" ? "bundled" : "global"
}).registerCodexManagedAppServerDoctorChecks({
getHealthCheck,
registerHealthCheck: registerCheck
});
}
}
function registerPolicyHealthChecks(params, registerCheck) {
if (shouldRegisterPolicyHealth(params)) loadBundledPluginPublicArtifactModuleSync({
dirName: "policy",
artifactBasename: "api.js"
}).registerPolicyDoctorChecks?.({ registerHealthCheck: registerCheck });
}
function registerCuaHealthChecks(params, registerCheck) {
if (shouldRegisterPluginHealth(params.cfg, "cua-computer")) loadBundledPluginPublicArtifactModuleSync({
dirName: "cua-computer",
artifactBasename: "api.js"
}).registerCuaDriverDoctorChecks?.({ registerHealthCheck: registerCheck });
}
function registerBundledWorkerProviderHealthChecks(params, registerCheck) {
const env = params.env ?? process.env;
const providerIds = collectConfiguredWorkerProviderIds(params.cfg);
if (providerIds.length === 0) return;
const manifestRegistry = loadBundledPluginManifestRegistry({ env });
const pluginIds = new Set(listBundledWorkerProviderOwners(manifestRegistry, providerIds).map((owner) => owner.pluginId));
for (const pluginId of pluginIds) loadBundledPluginPublicArtifactModuleFromCandidatesSync({
dirName: pluginId,
artifactCandidates: ["doctor-health-api.js"]
})?.registerWorkerProviderDoctorChecks?.({
getHealthCheck,
registerHealthCheck: registerCheck
});
}
function shouldRegisterCodexManagedHealth(cfg) {
if (!collectConfiguredAgentHarnessRuntimes(cfg).includes("codex")) return false;
return passesManifestOwnerBasePolicy({
plugin: { id: "codex" },
normalizedConfig: normalizePluginsConfig(cfg.plugins)
});
}
function isMemoryCoreActive(cfg) {
const plugins = normalizePluginsConfig(cfg.plugins);
const selectedMemoryPluginId = typeof plugins.slots.memory === "string" ? normalizePluginId(plugins.slots.memory) : plugins.slots.memory;
const configuredMemorySlot = cfg.plugins?.slots?.memory;
const explicitlySelected = typeof configuredMemorySlot === "string" && normalizePluginId(configuredMemorySlot) === "memory-core";
return selectedMemoryPluginId === "memory-core" && passesManifestOwnerBasePolicy({
plugin: { id: "memory-core" },
normalizedConfig: plugins,
allowRestrictiveAllowlistBypass: explicitlySelected
});
}
function shouldRegisterPluginHealth(cfg, pluginId) {
if ((cfg.plugins?.entries?.[pluginId])?.enabled !== true) return false;
return passesManifestOwnerBasePolicy({
plugin: { id: pluginId },
normalizedConfig: normalizePluginsConfig(cfg.plugins)
});
}
function shouldRegisterPolicyHealth(params) {
const entry = params.cfg.plugins?.entries?.policy;
const config = asOptionalObjectRecord(entry?.config) ?? {};
if (entry === void 0 || entry.enabled === false || config.enabled === false) return false;
if (!passesManifestOwnerBasePolicy({
plugin: { id: "policy" },
normalizedConfig: normalizePluginsConfig(params.cfg.plugins)
})) return false;
return entry.enabled === true || config.enabled === true;
}
//#endregion
export { resolveBundledHealthCheckPluginStateMode as n, registerBundledHealthChecks as t };