mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-07 16:06:19 +00:00
Reuse the startup runtime plugin registry across provider/tool helper paths while preserving standalone CLI/MCP fallback loading. Includes follow-up fixes for migration/provider/tool registry bootstrap and regression coverage for compatible registry reuse. Co-authored-by: DmitryPogodaev <pogodaev.dm@gmail.com>
45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
|
import { getLoadedRuntimePluginRegistry } from "./active-runtime-registry.js";
|
|
import { normalizePluginsConfig } from "./config-state.js";
|
|
import { getMemoryRuntime } from "./memory-state.js";
|
|
|
|
function resolveMemoryRuntimePluginIds(config: OpenClawConfig): string[] {
|
|
const memorySlot = normalizePluginsConfig(config.plugins).slots.memory;
|
|
return typeof memorySlot === "string" && memorySlot.trim().length > 0 ? [memorySlot] : [];
|
|
}
|
|
|
|
function ensureMemoryRuntime(cfg?: OpenClawConfig) {
|
|
const current = getMemoryRuntime();
|
|
if (current || !cfg) {
|
|
return current;
|
|
}
|
|
const onlyPluginIds = resolveMemoryRuntimePluginIds(cfg);
|
|
if (onlyPluginIds.length === 0) {
|
|
return getMemoryRuntime();
|
|
}
|
|
getLoadedRuntimePluginRegistry({ requiredPluginIds: onlyPluginIds });
|
|
return getMemoryRuntime();
|
|
}
|
|
|
|
export async function getActiveMemorySearchManager(params: {
|
|
cfg: OpenClawConfig;
|
|
agentId: string;
|
|
purpose?: "default" | "status" | "cli";
|
|
}) {
|
|
const runtime = ensureMemoryRuntime(params.cfg);
|
|
if (!runtime) {
|
|
return { manager: null, error: "memory plugin unavailable" };
|
|
}
|
|
return await runtime.getMemorySearchManager(params);
|
|
}
|
|
|
|
export function resolveActiveMemoryBackendConfig(params: { cfg: OpenClawConfig; agentId: string }) {
|
|
return ensureMemoryRuntime(params.cfg)?.resolveMemoryBackendConfig(params) ?? null;
|
|
}
|
|
|
|
export async function closeActiveMemorySearchManagers(cfg?: OpenClawConfig): Promise<void> {
|
|
void cfg;
|
|
const runtime = getMemoryRuntime();
|
|
await runtime?.closeAllMemorySearchManagers?.();
|
|
}
|