fix: restore missing runtime persistence helpers

This commit is contained in:
Youzini-afk
2026-04-14 12:40:53 +08:00
parent 4d026cd132
commit d39c16d8ff
3 changed files with 1119 additions and 0 deletions

1060
index.js

File diff suppressed because it is too large Load Diff

View File

@@ -883,6 +883,64 @@ async function createGraphPersistenceHarness({
buildSnapshotFromGraph, buildSnapshotFromGraph,
evaluatePersistNativeDeltaGate, evaluatePersistNativeDeltaGate,
buildBmeDbName, buildBmeDbName,
BME_GRAPH_LOCAL_STORAGE_MODE_INDEXEDDB: "indexeddb",
BME_GRAPH_LOCAL_STORAGE_MODE_OPFS_SHADOW: "opfs-shadow",
detectOpfsSupport: async () => ({
available: false,
reason: "opfs-unsupported-in-test",
}),
isGraphLocalStorageModeOpfs: (mode = "") =>
/^opfs-/.test(String(mode || "").trim().toLowerCase()),
normalizeGraphLocalStorageMode: (mode = "", fallback = "indexeddb") => {
const normalized = String(mode || "").trim().toLowerCase();
if (
normalized === "indexeddb" ||
normalized === "opfs-shadow" ||
normalized === "opfs-primary"
) {
return normalized;
}
return String(fallback || "indexeddb").trim().toLowerCase() || "indexeddb";
},
OpfsGraphStore: class {
constructor(dbChatId = "") {
this.chatId = String(dbChatId || "");
this.storeKind = "opfs";
this.storeMode = "opfs-shadow";
}
async open() {}
async close() {}
async exportSnapshot() {
return getIndexedDbSnapshotForChat(this.chatId);
}
async commitDelta(delta, options = {}) {
return commitIndexedDbDelta(this.chatId, delta, options);
}
async importSnapshot(snapshot) {
setIndexedDbSnapshotForChat(this.chatId, snapshot);
return {
revision: Number(snapshot?.meta?.revision) || 0,
};
}
async isEmpty() {
const snapshot = getIndexedDbSnapshotForChat(this.chatId);
return {
empty:
!snapshot ||
(!snapshot.nodes?.length && !snapshot.edges?.length && !snapshot.tombstones?.length),
};
}
async getRevision() {
return Number(getIndexedDbSnapshotForChat(this.chatId)?.meta?.revision || 0);
}
async getMeta(key, fallbackValue = 0) {
const snapshot = getIndexedDbSnapshotForChat(this.chatId) || {};
if (!snapshot?.meta || !(key in snapshot.meta)) {
return fallbackValue;
}
return snapshot.meta[key];
}
},
scheduleUpload() { scheduleUpload() {
if (runtimeContext.__scheduleUploadShouldThrow) { if (runtimeContext.__scheduleUploadShouldThrow) {
throw new Error("schedule-upload-failed"); throw new Error("schedule-upload-failed");

View File

@@ -122,6 +122,7 @@ export function createGenerationRecallHarness(options = {}) {
}, },
isRecalling: false, isRecalling: false,
getCurrentChatId: () => "chat-main", getCurrentChatId: () => "chat-main",
normalizeChatIdCandidate: (value = "") => String(value ?? "").trim(),
normalizeRecallInputText: (text = "") => String(text || "").trim(), normalizeRecallInputText: (text = "") => String(text || "").trim(),
isTrivialUserInput, isTrivialUserInput,
getAssistantTurns: (chat = []) => getAssistantTurns: (chat = []) =>