Open History to see the last commit
1interface TerminalRetentionThread {
2 key: string;
3 deletedAt: string | null;
4 archivedAt: string | null;
5}
6
7interface CollectActiveTerminalThreadIdsInput {
8 snapshotThreads: readonly TerminalRetentionThread[];
9 draftThreadKeys: Iterable<string>;
10}
11
12export function collectActiveTerminalThreadIds(
13 input: CollectActiveTerminalThreadIdsInput,
14): Set<string> {
15 const activeThreadIds = new Set<string>();
16 const snapshotThreadById = new Map(input.snapshotThreads.map((thread) => [thread.key, thread]));
17 for (const thread of input.snapshotThreads) {
18 if (thread.deletedAt !== null) continue;
19 if (thread.archivedAt !== null) continue;
20 activeThreadIds.add(thread.key);
21 }
22 for (const draftThreadKey of input.draftThreadKeys) {
23 const snapshotThread = snapshotThreadById.get(draftThreadKey);
24 if (
25 snapshotThread &&
26 (snapshotThread.deletedAt !== null || snapshotThread.archivedAt !== null)
27 ) {
28 continue;
29 }
30 activeThreadIds.add(draftThreadKey);
31 }
32 return activeThreadIds;
33}