Files
t3code/apps/web/src/lib/terminalStateCleanup.ts
T
b96308fc5a Prepare datamodel for multi-environment (#1765)
Co-authored-by: justsomelegs <[email protected]>
Co-authored-by: codex <[email protected]>
Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: cursor[bot] <206951365+cursor[bot]@users.noreply.github.com>
2026-04-09 02:05:20 +00:00

34 lines
1.0 KiB
TypeScript

interface TerminalRetentionThread {
key: string;
deletedAt: string | null;
archivedAt: string | null;
}
interface CollectActiveTerminalThreadIdsInput {
snapshotThreads: readonly TerminalRetentionThread[];
draftThreadKeys: Iterable<string>;
}
export function collectActiveTerminalThreadIds(
input: CollectActiveTerminalThreadIdsInput,
): Set<string> {
const activeThreadIds = new Set<string>();
const snapshotThreadById = new Map(input.snapshotThreads.map((thread) => [thread.key, thread]));
for (const thread of input.snapshotThreads) {
if (thread.deletedAt !== null) continue;
if (thread.archivedAt !== null) continue;
activeThreadIds.add(thread.key);
}
for (const draftThreadKey of input.draftThreadKeys) {
const snapshotThread = snapshotThreadById.get(draftThreadKey);
if (
snapshotThread &&
(snapshotThread.deletedAt !== null || snapshotThread.archivedAt !== null)
) {
continue;
}
activeThreadIds.add(draftThreadKey);
}
return activeThreadIds;
}