import { createDedupeCache, resolveGlobalDedupeCache } from "../infra/dedupe.js"; import { resolveGlobalSingleton } from "../shared/global-singleton.js"; import type { PluginInteractiveHandlerRegistration } from "./types.js"; export type RegisteredInteractiveHandler = PluginInteractiveHandlerRegistration & { pluginId: string; pluginName?: string; pluginRoot?: string; }; type InteractiveState = { interactiveHandlers: Map; callbackDedupe: ReturnType; }; const PLUGIN_INTERACTIVE_STATE_KEY = Symbol.for("openclaw.pluginInteractiveState"); function getState() { return resolveGlobalSingleton(PLUGIN_INTERACTIVE_STATE_KEY, () => ({ interactiveHandlers: new Map(), callbackDedupe: resolveGlobalDedupeCache( Symbol.for("openclaw.pluginInteractiveCallbackDedupe"), { ttlMs: 5 * 60_000, maxSize: 4096, }, ), })); } export function getPluginInteractiveHandlersState() { return getState().interactiveHandlers; } export function getPluginInteractiveCallbackDedupeState() { return getState().callbackDedupe; } export function clearPluginInteractiveHandlersState(): void { getPluginInteractiveHandlersState().clear(); getPluginInteractiveCallbackDedupeState().clear(); }