openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
45 lines (44 loc) • 2.65 kB
JavaScript
import { d as sqliteStringSet, i as executeSqliteQuerySync, o as getNodeSqliteKysely } from "./kysely-sync-DUWzQvCU.mjs";
import { p as listMemoryFiles, u as buildFileEntry } from "./engine-storage-DwRRcchW.mjs";
import "./memory-core-host-engine-storage-D6wIwcVO.mjs";
import { t as runWithConcurrency } from "./concurrency-BvONODc2.mjs";
import "./sqlite-runtime-DP6ZKsOz.mjs";
//#region extensions/memory-core/src/memory/manager-source-state.ts
/** Resolve exactly the entries eligible for indexing, including validated multimodal files. */
async function resolveMemorySourceFileEntries(params) {
const files = await (params.files?.listFiles ?? listMemoryFiles)(params.workspaceDir, params.settings.extraPaths, params.settings.multimodal, params.onSkippedSymlinkRoot);
return (await runWithConcurrency(files.map((file) => async () => await (params.files?.inspectFile ?? buildFileEntry)(file, params.workspaceDir, params.settings.multimodal)), params.concurrency)).filter((entry) => entry !== null);
}
async function inspectMemorySourceState(params) {
const skippedRoots = /* @__PURE__ */ new Set();
const entries = await resolveMemorySourceFileEntries({
...params,
onSkippedSymlinkRoot: (root) => skippedRoots.add(root)
});
const indexedByPath = new Map((await params.readIndexedRows()).map((row) => [row.path, row.hash]));
return {
source: "memory",
dirty: indexedByPath.size !== entries.length || entries.some((entry) => indexedByPath.get(entry.path) !== entry.hash),
eligible: entries.length,
issues: [...entries.length === 0 ? ["no eligible memory files found"] : [], ...Array.from(skippedRoots, (root) => `extra path "${root}" is a symlink root; symlinked roots are not traversed, so configure its canonical absolute directory instead`)]
};
}
function loadMemorySourceFileState(params) {
let query = getNodeSqliteKysely(params.db).selectFrom("memory_index_sources").select([
"path",
"hash",
"mtime",
"size"
]).where("source", "=", params.source);
if (params.paths) query = query.where("path", "in", sqliteStringSet(params.paths));
return executeSqliteQuerySync(params.db, query).rows;
}
function refreshMemorySessionSourceState(db, input) {
return Number(executeSqliteQuerySync(db, getNodeSqliteKysely(db).updateTable("memory_index_sources").set({
hash: input.hash,
mtime: input.mtime,
size: input.size
}).where("path", "=", input.path).where("source", "=", "sessions").where("hash", "=", input.expectedHash)).numAffectedRows) === 1;
}
//#endregion
export { resolveMemorySourceFileEntries as i, loadMemorySourceFileState as n, refreshMemorySessionSourceState as r, inspectMemorySourceState as t };