UNPKG

@convo-lang/convo-lang

Version:
33 lines 1.07 kB
import { ConvoMemoryGraphStore } from "./ConvoMemoryGraphStore"; const defaultStoreKey = 'convo-graph-store'; export class ConvoLocalStorageGraphStore extends ConvoMemoryGraphStore { storeKey; constructor({ storeKey, ...options }) { super(options); if (!storeKey) { storeKey = defaultStoreKey + '::' + options.graphId; } this.storeKey = storeKey; const json = globalThis.localStorage?.getItem(storeKey); if (json) { try { this.db = JSON.parse(json); if (!this.db.inputs) { this.db.inputs = []; } } catch (ex) { console.error('Invalid convo graph json', ex); } } this.onDbChange.subscribe(() => this.save()); } save() { globalThis.localStorage.setItem(this.storeKey, JSON.stringify(this.db)); } saveChangesAsync() { this.save(); return Promise.resolve(); } } //# sourceMappingURL=ConvoLocalStorageGraphStore.js.map