refactor: route channel runtime via plugin api

This commit is contained in:
Peter Steinberger
2026-01-18 11:00:19 +00:00
parent 676d41d415
commit ee6e534ccb
82 changed files with 1253 additions and 3167 deletions

View File

@@ -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;
}