Gateway: unify plugin interactive callback state (#50722)

Merged via squash.

Prepared head SHA: 7a2740b18a
Co-authored-by: huntharo <5617868+huntharo@users.noreply.github.com>
Co-authored-by: huntharo <5617868+huntharo@users.noreply.github.com>
Reviewed-by: @huntharo
This commit is contained in:
Harold Hunt
2026-03-19 22:09:38 -04:00
committed by GitHub
parent 61ae7e033b
commit 65594f972c
6 changed files with 227 additions and 26 deletions

View File

@@ -1,4 +1,5 @@
import { createDedupeCache } from "../infra/dedupe.js";
import { resolveGlobalSingleton } from "../shared/global-singleton.js";
import {
dispatchDiscordInteractiveHandler,
dispatchSlackInteractiveHandler,
@@ -33,11 +34,23 @@ type InteractiveDispatchResult =
| { matched: false; handled: false; duplicate: false }
| { matched: true; handled: boolean; duplicate: boolean };
const interactiveHandlers = new Map<string, RegisteredInteractiveHandler>();
const callbackDedupe = createDedupeCache({
ttlMs: 5 * 60_000,
maxSize: 4096,
});
type InteractiveState = {
interactiveHandlers: Map<string, RegisteredInteractiveHandler>;
callbackDedupe: ReturnType<typeof createDedupeCache>;
};
const PLUGIN_INTERACTIVE_STATE_KEY = Symbol.for("openclaw.pluginInteractiveState");
const state = resolveGlobalSingleton<InteractiveState>(PLUGIN_INTERACTIVE_STATE_KEY, () => ({
interactiveHandlers: new Map<string, RegisteredInteractiveHandler>(),
callbackDedupe: createDedupeCache({
ttlMs: 5 * 60_000,
maxSize: 4096,
}),
}));
const interactiveHandlers = state.interactiveHandlers;
const callbackDedupe = state.callbackDedupe;
function toRegistryKey(channel: string, namespace: string): string {
return `${channel.trim().toLowerCase()}:${namespace.trim()}`;