openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
209 lines (208 loc) • 9.36 kB
JavaScript
import { i as asOptionalObjectRecord } from "./record-coerce-CVPuDqcc.mjs";
import { c as normalizePluginId, u as normalizePluginsConfig } from "./config-state-B1JlHgba.mjs";
import { p as describePluginAvailabilityFailure } from "./discovery-availability-DtlJ7XvT.mjs";
import { n as loadBundledPluginManifestRegistry } from "./manifest-registry-build-BbYTyBDW.mjs";
import { i as passesManifestOwnerBasePolicy } from "./manifest-owner-policy-B8Brw4Zo.mjs";
import { n as loadPluginManifestRegistryForPluginRegistry } from "./plugin-registry-contributions-iAw3gSDD.mjs";
import { n as loadBundledPluginPublicArtifactModuleSync, r as loadPluginPublicArtifactModuleSync, t as loadBundledPluginPublicArtifactModuleFromCandidatesSync } from "./public-surface-loader-DENdCm5a.mjs";
import { r as resolveProviderPolicySurface } from "./provider-public-artifacts-CzxPvvri.mjs";
import "./plugin-registry-BrQav-kR.mjs";
import { t as collectConfiguredAgentHarnessRuntimes } from "./harness-runtimes-BJ7G_AOQ.mjs";
import { t as collectConfiguredWorkerProviderIds } from "./worker-provider-config-DBBZKbtq.mjs";
import { t as listBundledWorkerProviderOwners } from "./worker-provider-manifest-Be6h0bIw.mjs";
import { i as registerHealthCheck, t as getHealthCheck } from "./health-check-registry-Cl2vTx8K.mjs";
//#region src/flows/bundled-health-checks.ts
function defineHealthCheckRegistration(e, t) {
const n = t ? (e) => registerHealthCheck(Object.assign(e, { updateReadiness: t })) : registerHealthCheck;
return {
updateReadiness: t,
register: (t) => e(t, n)
};
}
const HEALTH_CHECK_REGISTRATIONS = [
defineHealthCheckRegistration(registerMemoryCoreHealthChecks, "post-plugin"),
defineHealthCheckRegistration(registerCodexHealthChecks),
defineHealthCheckRegistration(registerPolicyHealthChecks),
defineHealthCheckRegistration(registerOpenAIHealthChecks),
defineHealthCheckRegistration(registerCuaHealthChecks),
defineHealthCheckRegistration(registerBundledWorkerProviderHealthChecks)
];
function loadMemoryCoreHealthApi() {
return loadBundledPluginPublicArtifactModuleSync({
dirName: "memory-core",
artifactBasename: "doctor-health-api.js"
});
}
function resolveBundledHealthCheckPluginStateMode(e) {
if (e.updateReadiness !== void 0) return "isolated";
if (e.includeAllChecks !== true && (e.onlyIds === void 0 || e.onlyIds.length === 0)) return "direct";
const t = new Set(loadMemoryCoreHealthApi().pluginStateIsolatedDoctorCheckIds ?? []);
const n = new Set(e.skipIds ?? []);
const r = [...new Set(e.onlyIds ?? [])].filter((e) => !n.has(e));
if ((r.length > 0 ? r.filter((e) => t.has(e)) : [...t].filter((e) => !n.has(e))).length === 0) return "direct";
if (r.length > 0 && r.every((e) => t.has(e))) return "deferred";
return "isolated";
}
/** Registers bundled health checks that are explicitly enabled by config and owner policy. */
function registerBundledHealthChecks(e) {
const t = [];
for (const n of HEALTH_CHECK_REGISTRATIONS) {
if (e.updateReadiness !== void 0 && n.updateReadiness !== e.updateReadiness) continue;
t.push(...n.register(e) ?? []);
}
return t;
}
function registerMemoryCoreHealthChecks(e, t) {
const n = e.env ?? process.env;
loadMemoryCoreHealthApi().registerMemoryCoreDoctorChecks?.({
getHealthCheck,
registerHealthCheck: t,
async inspectEmbeddingProviderSetup(t) {
const inspect = async (n) => {
const r = loadPluginManifestRegistryForPluginRegistry({
config: e.cfg,
workspaceDir: e.cwd,
env: n
});
const i = resolveProviderPolicySurface(t.provider, { manifestRegistry: r })?.inspectEmbeddingProviderSetup;
return i ? await i({
...t,
env: n
}) : void 0;
};
return e.runWithPluginStateSnapshot ? await e.runWithPluginStateSnapshot(inspect) : await inspect(n);
},
memoryCoreActive: isMemoryCoreActive(e.cfg)
});
}
function resolveCodexHealthApi(e) {
if (!shouldRegisterCodexManagedHealth(e.cfg)) return { status: "not-configured" };
const unavailable = (e, t = true) => ({
status: "unavailable",
reason: e,
reportAvailability: t
});
const t = e.env ?? process.env;
const n = loadPluginManifestRegistryForPluginRegistry({
config: e.cfg,
workspaceDir: e.cwd,
env: t,
pluginIds: ["codex"]
}).plugins.find((e) => e.id === "codex");
if (!n) {
if (!collectConfiguredAgentHarnessRuntimes(e.cfg, { includeImplicitRuntimePreferences: false }).includes("codex")) return { status: "not-configured" };
return unavailable("The configured Codex plugin was not found. Install it with openclaw plugins install @openclaw/codex.");
}
if (n.origin !== "bundled" && n.trustedOfficialInstall !== true) return unavailable("The selected Codex plugin is not a bundled or verified official installation. Run openclaw plugins inspect codex --runtime --json to inspect its source; install the official plugin with openclaw plugins install @openclaw/codex.");
if (n.doctorHealthChecks !== true) return unavailable("The selected Codex plugin does not advertise Doctor health checks.", false);
try {
return {
status: "available",
api: loadPluginPublicArtifactModuleSync({
pluginRoot: n.rootDir,
artifactBasename: "api.js",
origin: n.origin === "bundled" ? "bundled" : "global"
})
};
} catch {
return unavailable("The selected Codex plugin declares Doctor health checks but its health API could not be loaded. Run openclaw plugins inspect codex --runtime --json for details, or openclaw triage for repair help.");
}
}
function registerCodexHealthChecks(e, t) {
const unavailable = (e) => [{
checkId: "core/doctor/codex-session-routes",
...describePluginAvailabilityFailure("codex", e)
}];
const n = resolveCodexHealthApi(e);
if (n.status === "not-configured") return [];
if (n.status === "unavailable") return n.reportAvailability ? unavailable(n.reason) : [];
if (typeof n.api.registerCodexManagedAppServerDoctorChecks !== "function") return unavailable("The selected Codex plugin's Doctor health checks are incomplete. Run openclaw plugins inspect codex --runtime --json for details, or openclaw triage for repair help.");
n.api.registerCodexManagedAppServerDoctorChecks({
getHealthCheck,
registerHealthCheck: t
});
return [];
}
function registerPolicyHealthChecks(e, t) {
if (shouldRegisterPolicyHealth(e.cfg)) loadBundledPluginPublicArtifactModuleSync({
dirName: "policy",
artifactBasename: "api.js"
}).registerPolicyDoctorChecks?.({ registerHealthCheck: t });
}
function registerOpenAIHealthChecks(e, t) {
loadBundledPluginPublicArtifactModuleSync({
dirName: "openai",
artifactBasename: "doctor-health-api.js"
}).registerOpenAIDoctorChecks?.({
getHealthCheck,
registerHealthCheck: t
});
}
function registerCuaHealthChecks(e, t) {
if (shouldRegisterPluginHealth(e.cfg, "cua-computer")) loadBundledPluginPublicArtifactModuleSync({
dirName: "cua-computer",
artifactBasename: "api.js"
}).registerCuaDriverDoctorChecks?.({ registerHealthCheck: t });
}
function registerBundledWorkerProviderHealthChecks(e, t) {
const n = e.env ?? process.env;
const r = collectConfiguredWorkerProviderIds(e.cfg);
if (r.length === 0) return;
const i = loadBundledPluginManifestRegistry({ env: n });
const a = new Set(listBundledWorkerProviderOwners(i, r).map((e) => e.pluginId));
for (const e of a) loadBundledPluginPublicArtifactModuleFromCandidatesSync({
dirName: e,
artifactCandidates: ["doctor-health-api.js"]
})?.registerWorkerProviderDoctorChecks?.({
getHealthCheck,
registerHealthCheck: t,
async inspectSetupSecrets(e, t) {
const { inspectSetupSecretMigration: r } = await import("./setup-secret-migration-CPnxVdjj.mjs");
return r({
names: e,
env: t ?? n
});
},
async listPluginStateEntries(t) {
const { createPluginStateKeyedStore: n } = await import("./plugin-state-store-IvBZXpzM.mjs");
return n(e, t).entries();
}
});
}
function shouldRegisterCodexManagedHealth(e) {
if (e.plugins?.entries?.codex?.enabled !== true && !collectConfiguredAgentHarnessRuntimes(e).includes("codex")) return false;
return passesManifestOwnerBasePolicy({
plugin: { id: "codex" },
normalizedConfig: normalizePluginsConfig(e.plugins)
});
}
function isMemoryCoreActive(e) {
const t = normalizePluginsConfig(e.plugins);
const n = typeof t.slots.memory === "string" ? normalizePluginId(t.slots.memory) : t.slots.memory;
const r = e.plugins?.slots?.memory;
const i = typeof r === "string" && normalizePluginId(r) === "memory-core";
return n === "memory-core" && passesManifestOwnerBasePolicy({
plugin: { id: "memory-core" },
normalizedConfig: t,
allowRestrictiveAllowlistBypass: i
});
}
function shouldRegisterPluginHealth(e, t) {
if ((e.plugins?.entries?.[t])?.enabled !== true) return false;
return passesManifestOwnerBasePolicy({
plugin: { id: t },
normalizedConfig: normalizePluginsConfig(e.plugins)
});
}
function shouldRegisterPolicyHealth(e) {
const t = e.plugins?.entries?.policy;
const n = asOptionalObjectRecord(t?.config) ?? {};
if (t === void 0 || t.enabled === false || n.enabled === false) return false;
if (!passesManifestOwnerBasePolicy({
plugin: { id: "policy" },
normalizedConfig: normalizePluginsConfig(e.plugins)
})) return false;
return t.enabled === true || n.enabled === true;
}
//#endregion
export { registerBundledHealthChecks, resolveBundledHealthCheckPluginStateMode, resolveCodexHealthApi };