1import type { OrchestrationV2ThreadShell } from "@t3tools/contracts";
2
3export function isManagedWorkspaceArchiveCandidate(
4 thread: OrchestrationV2ThreadShell,
5): thread is OrchestrationV2ThreadShell & {
6 readonly settledAt: NonNullable<OrchestrationV2ThreadShell["settledAt"]>;
7} {
8 return (
9 thread.settledOverride === "settled" &&
10 thread.settledAt !== null &&
11 thread.archivedAt === null &&
12 thread.deletedAt === null &&
13 thread.activeRunId === null &&
14 ["idle", "completed", "interrupted", "failed", "cancelled", "rolled_back"].includes(
15 thread.status,
16 ) &&
17 thread.pendingRuntimeRequest === null &&
18 (thread.pendingBackgroundTasks?.length ?? 0) === 0
19 );
20}