refactor: remove memory-core engine barrel

This commit is contained in:
Peter Steinberger 2026-03-27 03:33:27 +00:00
parent 3e121edf20
commit a9b982c954
No known key found for this signature in database
30 changed files with 114 additions and 72 deletions

View File

@ -1,4 +0,0 @@
export * from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
export * from "openclaw/plugin-sdk/memory-core-host-engine-storage";
export * from "openclaw/plugin-sdk/memory-core-host-engine-embeddings";
export * from "openclaw/plugin-sdk/memory-core-host-engine-qmd";

View File

@ -1 +1 @@
export { resolveMemoryBackendConfig } from "../engine-host-api.js";
export { resolveMemoryBackendConfig } from "openclaw/plugin-sdk/memory-core-host-engine-storage";

View File

@ -1,8 +1,8 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import type { OpenClawConfig } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import { afterAll, beforeAll, beforeEach, expect, vi, type Mock } from "vitest";
import type { OpenClawConfig } from "../engine-host-api.js";
import type { MemoryIndexManager, MemorySearchManager } from "./index.js";
type EmbeddingTestMocksModule = typeof import("./embedding.test-mocks.js");

View File

@ -11,7 +11,7 @@ import {
type MemoryEmbeddingProviderAdapter,
type MemoryEmbeddingProviderCreateOptions,
type MemoryEmbeddingProviderRuntime,
} from "../engine-host-api.js";
} from "openclaw/plugin-sdk/memory-core-host-engine-embeddings";
import {
canAutoSelectLocal,
getBuiltinMemoryEmbeddingProviderAdapter,
@ -24,7 +24,7 @@ export {
DEFAULT_OLLAMA_EMBEDDING_MODEL,
DEFAULT_OPENAI_EMBEDDING_MODEL,
DEFAULT_VOYAGE_EMBEDDING_MODEL,
} from "../engine-host-api.js";
} from "openclaw/plugin-sdk/memory-core-host-engine-embeddings";
export type EmbeddingProvider = MemoryEmbeddingProvider;
export type EmbeddingProviderId = string;

View File

@ -4,13 +4,18 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import "./test-runtime-mocks.js";
import type { MemoryIndexManager } from "./index.js";
import "./test-runtime-mocks.js";
import { registerBuiltInMemoryEmbeddingProviders } from "./provider-adapters.js";
type MemoryIndexModule = typeof import("./index.js");
type MemoryEmbeddingProvidersModule =
typeof import("../../../../src/plugins/memory-embedding-providers.js");
let getMemorySearchManager: MemoryIndexModule["getMemorySearchManager"];
let closeAllMemorySearchManagers: MemoryIndexModule["closeAllMemorySearchManagers"];
let clearRegistry: MemoryEmbeddingProvidersModule["clearMemoryEmbeddingProviders"];
let registerAdapter: MemoryEmbeddingProvidersModule["registerMemoryEmbeddingProvider"];
let embedBatchCalls = 0;
let embedBatchInputCalls = 0;
@ -134,6 +139,10 @@ describe("memory index", () => {
vi.resetModules();
await import("./test-runtime-mocks.js");
({ getMemorySearchManager, closeAllMemorySearchManagers } = await import("./index.js"));
({
clearMemoryEmbeddingProviders: clearRegistry,
registerMemoryEmbeddingProvider: registerAdapter,
} = await import("../../../../src/plugins/memory-embedding-providers.js"));
fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-mem-fixtures-"));
workspaceDir = path.join(fixtureRoot, "workspace");
memoryDir = path.join(workspaceDir, "memory");
@ -161,6 +170,7 @@ describe("memory index", () => {
afterEach(async () => {
await closeAllMemorySearchManagers();
clearRegistry();
managersForCleanup.clear();
});
@ -168,6 +178,8 @@ describe("memory index", () => {
// Perf: most suites don't need atomic swap behavior for full reindexes.
// Keep atomic reindex tests on the safe path.
vi.stubEnv("OPENCLAW_TEST_MEMORY_UNSAFE_REINDEX", "1");
clearRegistry();
registerBuiltInMemoryEmbeddingProviders({ registerMemoryEmbeddingProvider: registerAdapter });
embedBatchCalls = 0;
embedBatchInputCalls = 0;
providerCalls = [];

View File

@ -3,7 +3,7 @@ export type {
MemoryEmbeddingProbeResult,
MemorySearchManager,
MemorySearchResult,
} from "../engine-host-api.js";
} from "openclaw/plugin-sdk/memory-core-host-engine-storage";
export {
closeAllMemorySearchManagers,
getMemorySearchManager,

View File

@ -1 +1 @@
export { buildFileEntry } from "../engine-host-api.js";
export { buildFileEntry } from "openclaw/plugin-sdk/memory-core-host-engine-storage";

View File

@ -1,21 +1,23 @@
import fs from "node:fs/promises";
import {
buildMultimodalChunkForIndexing,
chunkMarkdown,
createSubsystemLogger,
enforceEmbeddingMaxInputTokens,
estimateStructuredEmbeddingInputBytes,
estimateUtf8Bytes,
hasNonTextEmbeddingParts,
type EmbeddingInput,
} from "openclaw/plugin-sdk/memory-core-host-engine-embeddings";
import { createSubsystemLogger } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import { type SessionFileEntry } from "openclaw/plugin-sdk/memory-core-host-engine-qmd";
import {
buildMultimodalChunkForIndexing,
chunkMarkdown,
hashText,
parseEmbedding,
remapChunkLines,
type EmbeddingInput,
type MemoryChunk,
type MemoryFileEntry,
type MemorySource,
type SessionFileEntry,
} from "../engine-host-api.js";
} from "openclaw/plugin-sdk/memory-core-host-engine-storage";
import { MemoryManagerSyncOps } from "./manager-sync-ops.js";
const VECTOR_TABLE = "chunks_vec";

View File

@ -1,5 +1,9 @@
import type { DatabaseSync } from "node:sqlite";
import { cosineSimilarity, parseEmbedding, truncateUtf16Safe } from "../engine-host-api.js";
import { truncateUtf16Safe } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import {
cosineSimilarity,
parseEmbedding,
} from "openclaw/plugin-sdk/memory-core-host-engine-storage";
const vectorToBlob = (embedding: number[]): Buffer =>
Buffer.from(new Float32Array(embedding).buffer);

View File

@ -7,29 +7,35 @@ import chokidar, { FSWatcher } from "chokidar";
import {
buildCaseInsensitiveExtensionGlob,
classifyMemoryMultimodalPath,
createSubsystemLogger,
ensureDir,
ensureMemoryIndexSchema,
getMemoryMultimodalExtensions,
hashText,
isFileMissingError,
listMemoryFiles,
listSessionFilesForAgent,
normalizeExtraMemoryPaths,
} from "openclaw/plugin-sdk/memory-core-host-engine-embeddings";
import {
createSubsystemLogger,
onSessionTranscriptUpdate,
resolveAgentDir,
resolveSessionTranscriptsDirForAgent,
resolveUserPath,
runWithConcurrency,
type OpenClawConfig,
type ResolvedMemorySearchConfig,
} from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import {
buildSessionEntry,
listSessionFilesForAgent,
sessionPathForFile,
type SessionFileEntry,
} from "openclaw/plugin-sdk/memory-core-host-engine-qmd";
import {
ensureDir,
ensureMemoryIndexSchema,
hashText,
isFileMissingError,
listMemoryFiles,
normalizeExtraMemoryPaths,
runWithConcurrency,
type MemoryFileEntry,
type MemorySource,
type MemorySyncProgressUpdate,
type OpenClawConfig,
type ResolvedMemorySearchConfig,
type SessionFileEntry,
buildSessionEntry,
} from "../engine-host-api.js";
} from "openclaw/plugin-sdk/memory-core-host-engine-storage";
import {
createEmbeddingProvider,
type EmbeddingProvider,

View File

@ -1,8 +1,8 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import type { OpenClawConfig } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../engine-host-api.js";
import type { MemoryIndexManager } from "./index.js";
import { closeAllMemorySearchManagers } from "./index.js";
import { createOpenAIEmbeddingProviderMock } from "./test-embeddings-mock.js";

View File

@ -1,8 +1,8 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import type { OpenClawConfig } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../engine-host-api.js";
import type { MemoryIndexManager } from "./index.js";
let shouldFail = false;

View File

@ -1,9 +1,9 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import type { OpenClawConfig } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { useFastShortTimeouts } from "../../../../test/helpers/fast-short-timeouts.js";
import type { OpenClawConfig } from "../engine-host-api.js";
import { createOpenAIEmbeddingProviderMock } from "./test-embeddings-mock.js";
import { mockPublicPinnedHostname } from "./test-helpers/ssrf.js";

View File

@ -2,8 +2,8 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { setTimeout as sleep } from "node:timers/promises";
import type { OpenClawConfig } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../engine-host-api.js";
import "./test-runtime-mocks.js";
import type { MemoryIndexManager } from "./index.js";

View File

@ -1,8 +1,8 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import type { OpenClawConfig } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../engine-host-api.js";
import { DEFAULT_OLLAMA_EMBEDDING_MODEL } from "./embeddings-ollama.js";
import type {
EmbeddingProvider,

View File

@ -1,8 +1,8 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import type { OpenClawConfig } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../engine-host-api.js";
import { resetEmbeddingMocks } from "./embedding.test-mocks.js";
import type { MemoryIndexManager } from "./index.js";
import { getRequiredMemoryIndexManager } from "./test-manager-helpers.js";

View File

@ -2,8 +2,8 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import type { DatabaseSync } from "node:sqlite";
import type { OpenClawConfig } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../engine-host-api.js";
import { resetEmbeddingMocks } from "./embedding.test-mocks.js";
import { MemoryIndexManager } from "./manager.js";
import { getRequiredMemoryIndexManager } from "./test-manager-helpers.js";

View File

@ -1,22 +1,24 @@
import type { DatabaseSync } from "node:sqlite";
import { type FSWatcher } from "chokidar";
import {
extractKeywords,
readMemoryFile,
resolveAgentDir,
resolveAgentWorkspaceDir,
resolveGlobalSingleton,
resolveMemorySearchConfig,
createSubsystemLogger,
type OpenClawConfig,
type ResolvedMemorySearchConfig,
} from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import { extractKeywords } from "openclaw/plugin-sdk/memory-core-host-engine-qmd";
import {
readMemoryFile,
type MemoryEmbeddingProbeResult,
type MemoryProviderStatus,
type MemorySearchManager,
type MemorySearchResult,
type MemorySource,
type MemorySyncProgressUpdate,
type OpenClawConfig,
type ResolvedMemorySearchConfig,
createSubsystemLogger,
} from "../engine-host-api.js";
} from "openclaw/plugin-sdk/memory-core-host-engine-storage";
import {
createEmbeddingProvider,
type EmbeddingProvider,

View File

@ -1,8 +1,8 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import type { OpenClawConfig } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../engine-host-api.js";
import type { MemoryIndexManager } from "./index.js";
vi.mock("./embeddings.js", () => {

View File

@ -1,10 +1,13 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import type {
MemorySearchConfig,
OpenClawConfig,
} from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../engine-host-api.js";
import type { MemorySearchConfig } from "../engine-host-api.js";
import type { MemoryIndexManager } from "./index.js";
import { registerBuiltInMemoryEmbeddingProviders } from "./provider-adapters.js";
const { watchMock } = vi.hoisted(() => ({
watchMock: vi.fn(() => ({
@ -35,9 +38,13 @@ vi.mock("./embeddings.js", () => ({
}));
type MemoryIndexModule = typeof import("./index.js");
type MemoryEmbeddingProvidersModule =
typeof import("../../../../src/plugins/memory-embedding-providers.js");
let getMemorySearchManager: MemoryIndexModule["getMemorySearchManager"];
let closeAllMemorySearchManagers: MemoryIndexModule["closeAllMemorySearchManagers"];
let clearRegistry: MemoryEmbeddingProvidersModule["clearMemoryEmbeddingProviders"];
let registerAdapter: MemoryEmbeddingProvidersModule["registerMemoryEmbeddingProvider"];
describe("memory watcher config", () => {
let manager: MemoryIndexManager | null = null;
@ -47,7 +54,13 @@ describe("memory watcher config", () => {
beforeEach(async () => {
vi.resetModules();
({ getMemorySearchManager, closeAllMemorySearchManagers } = await import("./index.js"));
({
clearMemoryEmbeddingProviders: clearRegistry,
registerMemoryEmbeddingProvider: registerAdapter,
} = await import("../../../../src/plugins/memory-embedding-providers.js"));
vi.clearAllMocks();
clearRegistry();
registerBuiltInMemoryEmbeddingProviders({ registerMemoryEmbeddingProvider: registerAdapter });
});
afterEach(async () => {
@ -57,6 +70,7 @@ describe("memory watcher config", () => {
manager = null;
}
await closeAllMemorySearchManagers();
clearRegistry();
if (workspaceDir) {
await fs.rm(workspaceDir, { recursive: true, force: true });
workspaceDir = "";

View File

@ -16,12 +16,12 @@ import {
createVoyageEmbeddingProvider,
hasNonTextEmbeddingParts,
listMemoryEmbeddingProviders,
resolveUserPath,
runGeminiEmbeddingBatches,
runOpenAiEmbeddingBatches,
runVoyageEmbeddingBatches,
type MemoryEmbeddingProviderAdapter,
} from "../engine-host-api.js";
} from "openclaw/plugin-sdk/memory-core-host-engine-embeddings";
import { resolveUserPath } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
function formatErrorMessage(err: unknown): string {
return err instanceof Error ? err.message : String(err);

View File

@ -94,11 +94,11 @@ vi.mock("node:child_process", async (importOriginal) => {
});
import { spawn as mockedSpawn } from "node:child_process";
import type { OpenClawConfig } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import {
requireNodeSqlite,
resolveMemoryBackendConfig,
type OpenClawConfig,
} from "../engine-host-api.js";
} from "openclaw/plugin-sdk/memory-core-host-engine-storage";
import { QmdMemoryManager } from "./qmd-manager.js";
const spawnMock = mockedSpawn as unknown as Mock;

View File

@ -3,20 +3,28 @@ import os from "node:os";
import path from "node:path";
import readline from "node:readline";
import {
buildSessionEntry,
createSubsystemLogger,
resolveAgentWorkspaceDir,
resolveGlobalSingleton,
resolveStateDir,
writeFileWithinRoot,
type OpenClawConfig,
} from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import {
buildSessionEntry,
deriveQmdScopeChannel,
deriveQmdScopeChatType,
extractKeywords,
isFileMissingError,
isQmdScopeAllowed,
listSessionFilesForAgent,
parseQmdQueryJson,
resolveAgentWorkspaceDir,
resolveCliSpawnInvocation,
resolveGlobalSingleton,
resolveStateDir,
runCliCommand,
type QmdQueryResult,
type SessionFileEntry,
} from "openclaw/plugin-sdk/memory-core-host-engine-qmd";
import {
isFileMissingError,
statRegularFile,
type MemoryEmbeddingProbeResult,
type MemoryProviderStatus,
@ -24,14 +32,10 @@ import {
type MemorySearchResult,
type MemorySource,
type MemorySyncProgressUpdate,
type OpenClawConfig,
type QmdQueryResult,
type ResolvedMemoryBackendConfig,
type ResolvedQmdConfig,
type ResolvedQmdMcporterConfig,
type SessionFileEntry,
writeFileWithinRoot,
} from "../engine-host-api.js";
} from "openclaw/plugin-sdk/memory-core-host-engine-storage";
import { requireNodeSqlite } from "./sqlite.js";
type SqliteDatabase = import("node:sqlite").DatabaseSync;

View File

@ -1,5 +1,5 @@
import type { OpenClawConfig } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../engine-host-api.js";
function createManagerStatus(params: {
backend: "qmd" | "builtin";
@ -102,7 +102,7 @@ vi.mock("./qmd-manager.js", () => ({
},
}));
vi.mock("../../extensions/memory-core/src/memory/manager-runtime.js", () => ({
vi.mock("./manager-runtime.js", () => ({
MemoryIndexManager: {
get: mockMemoryIndexGet,
},

View File

@ -1,13 +1,15 @@
import {
createSubsystemLogger,
resolveGlobalSingleton,
type OpenClawConfig,
} from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import {
resolveMemoryBackendConfig,
type MemoryEmbeddingProbeResult,
type MemorySearchManager,
type MemorySyncProgressUpdate,
type OpenClawConfig,
type ResolvedQmdConfig,
} from "../engine-host-api.js";
} from "openclaw/plugin-sdk/memory-core-host-engine-storage";
const MEMORY_SEARCH_MANAGER_CACHE_KEY = Symbol.for("openclaw.memorySearchManagerCache");
type MemorySearchManagerCacheStore = {

View File

@ -1 +1 @@
export { loadSqliteVecExtension } from "../engine-host-api.js";
export { loadSqliteVecExtension } from "openclaw/plugin-sdk/memory-core-host-engine-storage";

View File

@ -1 +1 @@
export { requireNodeSqlite } from "../engine-host-api.js";
export { requireNodeSqlite } from "openclaw/plugin-sdk/memory-core-host-engine-storage";

View File

@ -1,8 +1,8 @@
import {
OPENAI_BATCH_ENDPOINT,
runOpenAiEmbeddingBatches,
type MemoryChunk,
} from "../engine-host-api.js";
} from "openclaw/plugin-sdk/memory-core-host-engine-embeddings";
import type { MemoryChunk } from "openclaw/plugin-sdk/memory-core-host-engine-storage";
export function createOpenAIEmbeddingProviderMock(params: {
embedQuery: (input: string) => Promise<number[]>;

View File

@ -1,4 +1,4 @@
import type { OpenClawConfig } from "../engine-host-api.js";
import type { OpenClawConfig } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import type { MemoryIndexManager } from "./index.js";
export async function getRequiredMemoryIndexManager(params: {

View File

@ -1,4 +1,4 @@
import type { OpenClawConfig } from "../engine-host-api.js";
import type { OpenClawConfig } from "openclaw/plugin-sdk/memory-core-host-engine-foundation";
import { getMemorySearchManager, type MemoryIndexManager } from "./index.js";
export async function createMemoryManagerOrThrow(