openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
37 lines (36 loc) • 1.41 kB
JavaScript
import { g as readRegularFile } from "./fs-safe-BbWvmdVn.mjs";
import crypto from "node:crypto";
//#region src/plugin-sdk/memory-migration-source.ts
const MAX_MEMORY_MIGRATION_FILE_BYTES = 67108864;
/** Bind copyable memory items to the exact source bytes reviewed by an embedded migration UI. */
async function bindMemoryMigrationPlanSources(e, t = {}) {
const n = [];
for (const r of e.items) {
if (r.kind !== "memory" || r.action !== "copy" || r.status !== "planned" && !(t.includeConflicts && r.status === "conflict") || !r.source) {
n.push(r);
continue;
}
const { buffer: e } = await readRegularFile({
filePath: r.source,
maxBytes: MAX_MEMORY_MIGRATION_FILE_BYTES
});
n.push({
...r,
sourceRevision: {
algorithm: "sha256",
digest: crypto.createHash("sha256").update(e).digest("hex")
}
});
}
return {
...e,
items: n
};
}
/** Reject source bytes that differ from an embedded migration's reviewed plan. */
function assertMemoryMigrationSourceRevision(e, t) {
const n = e.sourceRevision?.digest;
if (e.sourceRevision?.algorithm === "sha256" && typeof n === "string" && crypto.createHash("sha256").update(t).digest("hex") !== n) throw new Error("memory migration source changed; refresh the plan before importing");
}
//#endregion
export { assertMemoryMigrationSourceRevision as n, bindMemoryMigrationPlanSources as r, MAX_MEMORY_MIGRATION_FILE_BYTES as t };