2026-01-15 02:44:45 +00:00
|
|
|
import type { PluginRegistry } from "./registry.js";
|
|
|
|
|
|
2026-01-18 11:00:19 +00:00
|
|
|
const createEmptyRegistry = (): PluginRegistry => ({
|
|
|
|
|
plugins: [],
|
|
|
|
|
tools: [],
|
|
|
|
|
hooks: [],
|
|
|
|
|
typedHooks: [],
|
|
|
|
|
channels: [],
|
|
|
|
|
providers: [],
|
|
|
|
|
gatewayHandlers: {},
|
|
|
|
|
httpHandlers: [],
|
2026-01-25 07:22:36 -05:00
|
|
|
httpRoutes: [],
|
2026-01-18 11:00:19 +00:00
|
|
|
cliRegistrars: [],
|
|
|
|
|
services: [],
|
2026-01-23 03:17:10 +00:00
|
|
|
commands: [],
|
2026-01-18 11:00:19 +00:00
|
|
|
diagnostics: [],
|
|
|
|
|
});
|
|
|
|
|
|
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] = {
|
|
|
|
|
registry: createEmptyRegistry(),
|
|
|
|
|
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) {
|
|
|
|
|
state.registry = createEmptyRegistry();
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|