2026-02-15 19:05:00 +00:00
|
|
|
import { createEmptyPluginRegistry, type PluginRegistry } from "./registry.js";
|
2026-01-18 11:00:19 +00:00
|
|
|
|
2026-01-30 03:15:10 +01:00
|
|
|
const REGISTRY_STATE = Symbol.for("openclaw.pluginRegistryState");
|
2026-01-18 11:00:19 +00:00
|
|
|
|
|
|
|
|
type RegistryState = {
|
|
|
|
|
registry: PluginRegistry | null;
|
|
|
|
|
key: string | null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const state: RegistryState = (() => {
|
|
|
|
|
const globalState = globalThis as typeof globalThis & {
|
|
|
|
|
[REGISTRY_STATE]?: RegistryState;
|
|
|
|
|
};
|
|
|
|
|
if (!globalState[REGISTRY_STATE]) {
|
|
|
|
|
globalState[REGISTRY_STATE] = {
|
2026-02-15 19:05:00 +00:00
|
|
|
registry: createEmptyPluginRegistry(),
|
2026-01-18 11:00:19 +00:00
|
|
|
key: null,
|
|
|
|
|
};
|
|
|
|
|
}
|
2026-01-31 16:03:28 +09:00
|
|
|
return globalState[REGISTRY_STATE];
|
2026-01-18 11:00:19 +00:00
|
|
|
})();
|
2026-01-15 02:44:45 +00:00
|
|
|
|
|
|
|
|
export function setActivePluginRegistry(registry: PluginRegistry, cacheKey?: string) {
|
2026-01-18 11:00:19 +00:00
|
|
|
state.registry = registry;
|
|
|
|
|
state.key = cacheKey ?? null;
|
2026-01-15 02:44:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getActivePluginRegistry(): PluginRegistry | null {
|
2026-01-18 11:00:19 +00:00
|
|
|
return state.registry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function requireActivePluginRegistry(): PluginRegistry {
|
|
|
|
|
if (!state.registry) {
|
2026-02-15 19:05:00 +00:00
|
|
|
state.registry = createEmptyPluginRegistry();
|
2026-01-18 11:00:19 +00:00
|
|
|
}
|
|
|
|
|
return state.registry;
|
2026-01-15 02:44:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getActivePluginRegistryKey(): string | null {
|
2026-01-18 11:00:19 +00:00
|
|
|
return state.key;
|
2026-01-15 02:44:45 +00:00
|
|
|
}
|