- 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
26 lines
699 B
TypeScript
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;
|
|
}
|