import { i as resolveGlobalSingleton } from "./global-singleton-Dc_stLtU.js";
import { d as resetPluginCache } from "./plugin-cache-DMPn6vOK.js";
import { o as isGatewayPluginMetadataSnapshotActive, t as clearCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-state-C9do4nKP.js";
//#region src/plugins/plugin-metadata-lifecycle.ts
/** Coordinates plugin metadata snapshot and process memo cache lifecycle resets. */
const pluginMetadataProcessMemoClears = /* @__PURE__ */ new Set();
const gatewayMetadataOwners = resolveGlobalSingleton(Symbol.for("openclaw.gatewayPluginMetadataOwners"), () => /* @__PURE__ */ new Set());
/** Keeps shared boot metadata alive through every kernel's startup and shutdown. */
function retainGatewayPluginMetadata() {
	const owner = Symbol("gateway-plugin-metadata-owner");
	gatewayMetadataOwners.add(owner);
	return () => {
		if (gatewayMetadataOwners.delete(owner) && gatewayMetadataOwners.size === 0) clearPluginMetadataLifecycleCaches();
	};
}
/** Registers a process-local plugin metadata memo clear hook. */
function registerPluginMetadataProcessMemoLifecycleClear(clearProcessMemo) {
	pluginMetadataProcessMemoClears.add(clearProcessMemo);
}
/** Clears plugin metadata snapshots and registered process memo caches. */
function clearPluginMetadataLifecycleCaches() {
	if (gatewayMetadataOwners.size > 0 && isGatewayPluginMetadataSnapshotActive()) return;
	clearCurrentPluginMetadataSnapshot();
	resetPluginCache();
	for (const clearProcessMemo of pluginMetadataProcessMemoClears) clearProcessMemo();
}
//#endregion
export { registerPluginMetadataProcessMemoLifecycleClear as n, retainGatewayPluginMetadata as r, clearPluginMetadataLifecycleCaches as t };
