mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 02:41:24 +00:00
refactor: route channel runtime via plugin api
This commit is contained in:
@@ -1,17 +1,55 @@
|
||||
import type { PluginRegistry } from "./registry.js";
|
||||
|
||||
let activeRegistry: PluginRegistry | null = null;
|
||||
let activeRegistryKey: string | null = null;
|
||||
const createEmptyRegistry = (): PluginRegistry => ({
|
||||
plugins: [],
|
||||
tools: [],
|
||||
hooks: [],
|
||||
typedHooks: [],
|
||||
channels: [],
|
||||
providers: [],
|
||||
gatewayHandlers: {},
|
||||
httpHandlers: [],
|
||||
cliRegistrars: [],
|
||||
services: [],
|
||||
diagnostics: [],
|
||||
});
|
||||
|
||||
const REGISTRY_STATE = Symbol.for("clawdbot.pluginRegistryState");
|
||||
|
||||
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,
|
||||
};
|
||||
}
|
||||
return globalState[REGISTRY_STATE] as RegistryState;
|
||||
})();
|
||||
|
||||
export function setActivePluginRegistry(registry: PluginRegistry, cacheKey?: string) {
|
||||
activeRegistry = registry;
|
||||
activeRegistryKey = cacheKey ?? null;
|
||||
state.registry = registry;
|
||||
state.key = cacheKey ?? null;
|
||||
}
|
||||
|
||||
export function getActivePluginRegistry(): PluginRegistry | null {
|
||||
return activeRegistry;
|
||||
return state.registry;
|
||||
}
|
||||
|
||||
export function requireActivePluginRegistry(): PluginRegistry {
|
||||
if (!state.registry) {
|
||||
state.registry = createEmptyRegistry();
|
||||
}
|
||||
return state.registry;
|
||||
}
|
||||
|
||||
export function getActivePluginRegistryKey(): string | null {
|
||||
return activeRegistryKey;
|
||||
return state.key;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user