openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
76 lines (75 loc) • 3.7 kB
JavaScript
import { t as retainCliRegistryHarnesses } from "./runtime-cleanup-scope-cCKdH8QO.js";
import { t as createSubsystemLogger } from "./subsystem-Dy2tqXOS.js";
import { c as isPluginRegistryRetired } from "./registry-lifecycle-BozndFXl.js";
import { _ as getPluginRegistryForContext } from "./runtime-BL4wZfTq.js";
import { f as withPluginRuntimeRegistryScope } from "./gateway-request-scope-BCMYlsDI.js";
//#region src/agents/harness/registry.ts
/**
* Registry for native agent harness implementations and lifecycle cleanup.
*/
const log = createSubsystemLogger("agents/harness");
const CODEX_NATIVE_COMPACTION_OWNER_ID = "codex";
function getAgentHarnesses() {
const registry = getPluginRegistryForContext();
if (!registry || isPluginRegistryRetired(registry)) return [];
retainCliRegistryHarnesses(registry, (harness) => withPluginRuntimeRegistryScope(registry, () => disposeAgentHarness(harness)));
return registry.agentHarnesses;
}
/** Returns the harness plus plugin ownership metadata for registry diagnostics. */
function getRegisteredAgentHarness(id) {
const registration = getAgentHarnesses().find((entry) => entry.harness.id === id.trim());
return registration ? {
harness: registration.harness,
ownerPluginId: registration.pluginId === "core" ? void 0 : registration.pluginId
} : void 0;
}
/** Resolves the registry-owned approval identity for the exact registered harness object. */
function resolveAgentHarnessOwnerPluginId(harness) {
const registration = getRegisteredAgentHarness(harness.id);
if (registration?.harness !== harness) throw new Error(`Agent harness ${harness.id} changed during owner resolution.`);
return registration.ownerPluginId ?? "core";
}
/** Resolves the private Codex compaction bridge from exact registry-owned capability state. */
function resolveCodexAgentHarnessNativeCompaction(harness) {
if (harness.id !== CODEX_NATIVE_COMPACTION_OWNER_ID) return;
const registration = getAgentHarnesses().find((entry) => entry.harness.id === CODEX_NATIVE_COMPACTION_OWNER_ID);
if (registration?.harness !== harness) throw new Error(`Agent harness ${harness.id} changed during native compaction resolution.`);
return registration.pluginId === CODEX_NATIVE_COMPACTION_OWNER_ID ? registration.nativeCompaction : void 0;
}
/** Lists registered harness records for selection and lifecycle fan-out. */
function listRegisteredAgentHarnesses() {
return getAgentHarnesses().map((entry) => ({
harness: entry.harness,
ownerPluginId: entry.pluginId === "core" ? void 0 : entry.pluginId
}));
}
/** Calls each registered harness session-reset hook without letting one failure stop the fan-out. */
async function resetRegisteredAgentHarnessSessions(params) {
await Promise.all(listRegisteredAgentHarnesses().map(async (entry) => {
if (!entry.harness.reset) return;
try {
await entry.harness.reset(params);
} catch (error) {
log.warn(`${entry.harness.label} session reset hook failed`, {
harnessId: entry.harness.id,
error
});
}
}));
}
async function disposeAgentHarness(harness) {
try {
await harness.dispose?.();
} catch (error) {
log.warn(`${harness.label} dispose hook failed`, {
harnessId: harness.id,
error
});
}
}
/** Calls each registered harness dispose hook during registry shutdown or reload. */
async function disposeRegisteredAgentHarnesses() {
await Promise.all(listRegisteredAgentHarnesses().map(({ harness }) => disposeAgentHarness(harness)));
}
//#endregion
export { resolveAgentHarnessOwnerPluginId as a, resetRegisteredAgentHarnessSessions as i, getRegisteredAgentHarness as n, resolveCodexAgentHarnessNativeCompaction as o, listRegisteredAgentHarnesses as r, disposeRegisteredAgentHarnesses as t };