refactor: unify pending history helpers
This commit is contained in:
1 parent
05e7e06146
commit
521ea4ae5b
13 files changed
+196
-155
No files matched your search
@@ -47,6 +47,22 @@ export function recordPendingHistoryEntry<T extends HistoryEntry>(params: {
|
||||
return appendHistoryEntry(params);
|
||||
}
|
||||
|
||||
export function recordPendingHistoryEntryIfEnabled<T extends HistoryEntry>(params: {
|
||||
historyMap: Map<string, T[]>;
|
||||
historyKey: string;
|
||||
entry?: T | null;
|
||||
limit: number;
|
||||
}): T[] {
|
||||
if (!params.entry) return [];
|
||||
if (params.limit <= 0) return [];
|
||||
return recordPendingHistoryEntry({
|
||||
historyMap: params.historyMap,
|
||||
historyKey: params.historyKey,
|
||||
entry: params.entry,
|
||||
limit: params.limit,
|
||||
});
|
||||
}
|
||||
|
||||
export function buildPendingHistoryContextFromMap(params: {
|
||||
historyMap: Map<string, HistoryEntry[]>;
|
||||
historyKey: string;
|
||||
@@ -101,6 +117,15 @@ export function clearHistoryEntries(params: {
|
||||
params.historyMap.set(params.historyKey, []);
|
||||
}
|
||||
|
||||
export function clearHistoryEntriesIfEnabled(params: {
|
||||
historyMap: Map<string, HistoryEntry[]>;
|
||||
historyKey: string;
|
||||
limit: number;
|
||||
}): void {
|
||||
if (params.limit <= 0) return;
|
||||
clearHistoryEntries({ historyMap: params.historyMap, historyKey: params.historyKey });
|
||||
}
|
||||
|
||||
export function buildHistoryContextFromEntries(params: {
|
||||
entries: HistoryEntry[];
|
||||
currentMessage: string;
|
||||
|
||||
Reference in new issue
Block a user