Open History to see the last commit
1import type { StatusTone } from "../../components/StatusPill";
2import type { OrchestrationLatestTurn, OrchestrationSession } from "@t3tools/contracts";
3import { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
4
5export type ThreadStatusKind =
6 | "pending-approval"
7 | "awaiting-input"
8 | "working"
9 | "connecting"
10 | "error"
11 | "plan-ready";
12
13export interface ThreadStatusPresentation extends StatusTone {
14 readonly kind: ThreadStatusKind;
15 /** Whether the indicator represents in-flight activity. */
16 readonly pulse: boolean;
17}
18
19function isLatestTurnSettled(
20 latestTurn: OrchestrationLatestTurn | null,
21 session: OrchestrationSession | null,
22): boolean {
23 if (!latestTurn?.startedAt) return false;
24 if (!latestTurn.completedAt) return false;
25 if (!session) return true;
26 return session.status !== "running";
27}
28
29/**
30 * Resolves the user-facing status of a thread, in priority order. Returns
31 * `null` for quiescent threads so rows stay free of "Idle"-style noise.
32 * Mirrors `resolveThreadStatusPill` in apps/web/src/components/Sidebar.logic.ts.
33 */
34export function resolveThreadStatus(
35 thread: EnvironmentThreadShell,
36): ThreadStatusPresentation | null {
37 if (thread.hasPendingApprovals) {
38 return {
39 kind: "pending-approval",
40 label: "Needs Approval",
41 pillClassName: "bg-warning",
42 textClassName: "text-warning-foreground",
43 pulse: false,
44 };
45 }
46
47 if (thread.hasPendingUserInput) {
48 return {
49 kind: "awaiting-input",
50 label: "Awaiting Input",
51 pillClassName: "bg-adaptive-indigo-500-a12-a16",
52 textClassName: "text-adaptive-indigo-600-300",
53 pulse: false,
54 };
55 }
56
57 if (thread.session?.status === "running") {
58 return {
59 kind: "working",
60 label: "Working",
61 pillClassName: "bg-adaptive-sky-500-a12-a16",
62 textClassName: "text-adaptive-sky-600-400",
63 pulse: true,
64 };
65 }
66
67 if (thread.session?.status === "starting") {
68 return {
69 kind: "connecting",
70 label: "Connecting",
71 pillClassName: "bg-adaptive-sky-500-a12-a16",
72 textClassName: "text-adaptive-sky-600-400",
73 pulse: true,
74 };
75 }
76
77 if (thread.session?.status === "error" || thread.latestTurn?.state === "error") {
78 return {
79 kind: "error",
80 label: "Error",
81 pillClassName: "bg-danger",
82 textClassName: "text-danger-foreground",
83 pulse: false,
84 };
85 }
86
87 const hasPlanReadyPrompt =
88 thread.interactionMode === "plan" &&
89 isLatestTurnSettled(thread.latestTurn, thread.session) &&
90 thread.hasActionableProposedPlan;
91 if (hasPlanReadyPrompt) {
92 return {
93 kind: "plan-ready",
94 label: "Plan Ready",
95 pillClassName: "bg-adaptive-violet-500-a12-a16",
96 textClassName: "text-adaptive-violet-600-400",
97 pulse: false,
98 };
99 }
100
101 return null;
102}