Files
t3code/apps/web/src/lib/terminalStateCleanup.ts
T
Julius Marminge b9e529e0b5 Preserve draft terminal state during snapshot cleanup
- add `collectActiveTerminalThreadIds` to keep non-deleted server threads plus local draft threads
- use helper in root event router before orphan terminal state removal
- add unit tests for retained and deleted thread behavior
2026-03-05 23:41:23 -08:00

26 lines
699 B
TypeScript

import type { ThreadId } from "@t3tools/contracts";
interface TerminalRetentionThread {
id: ThreadId;
deletedAt: string | null;
}
interface CollectActiveTerminalThreadIdsInput {
snapshotThreads: readonly TerminalRetentionThread[];
draftThreadIds: Iterable<ThreadId>;
}
export function collectActiveTerminalThreadIds(
input: CollectActiveTerminalThreadIdsInput,
): Set<ThreadId> {
const activeThreadIds = new Set<ThreadId>();
for (const thread of input.snapshotThreads) {
if (thread.deletedAt !== null) continue;
activeThreadIds.add(thread.id);
}
for (const draftThreadId of input.draftThreadIds) {
activeThreadIds.add(draftThreadId);
}
return activeThreadIds;
}