feat: remove storageKeyPrefix and getDefaultHistoryStorage, simplifying history storage initialization to default to localStorage

This commit is contained in:
Danish Arora 2025-11-20 16:26:27 -05:00
parent 322240b2d0
commit 15f1a22f2e
No known key found for this signature in database
GPG Key ID: 1C6EF37CDAE1426E

View File

@ -12,7 +12,6 @@ export interface HistoryStorage {
export interface PersistentHistoryOptions {
channelId: ChannelId;
storage?: HistoryStorage;
storageKeyPrefix?: string;
}
type StoredHistoryEntry = {
@ -45,8 +44,8 @@ export class PersistentHistory implements ILocalHistory {
public constructor(options: PersistentHistoryOptions) {
this.memory = new MemLocalHistory();
this.storage = options.storage ?? getDefaultHistoryStorage();
this.storageKey = `${HISTORY_STORAGE_PREFIX}${options.storageKeyPrefix}:${options.channelId}`;
this.storage = options.storage || localStorage;
this.storageKey = `${HISTORY_STORAGE_PREFIX}${options.channelId}`;
this.load();
}
@ -132,21 +131,6 @@ export class PersistentHistory implements ILocalHistory {
}
}
export const getDefaultHistoryStorage = (): HistoryStorage | undefined => {
try {
if (typeof localStorage === "undefined") {
return undefined;
}
const probeKey = `${HISTORY_STORAGE_PREFIX}__probe__`;
localStorage.setItem(probeKey, probeKey);
localStorage.removeItem(probeKey);
return localStorage;
} catch {
return undefined;
}
};
const serializeHistoryEntry = (entry: HistoryEntry): StoredHistoryEntry => ({
messageId: entry.messageId,
retrievalHint: entry.retrievalHint