Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

threadPresentation.ts

118 lines3.4 KB

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 /** Foreground color for the leading status icon. */
16 readonly iconColor: string;
17 /** Background color for the leading status icon circle. */
18 readonly iconBackground: string;
19 /** Whether the indicator represents in-flight activity. */
20 readonly pulse: boolean;
22​
23function isLatestTurnSettled(
24 latestTurn: OrchestrationLatestTurn | null,
25 session: OrchestrationSession | null,
26): boolean {
27 if (!latestTurn?.startedAt) return false;
28 if (!latestTurn.completedAt) return false;
29 if (!session) return true;
30 return session.status !== "running";
32​
33/**
34 * Resolves the user-facing status of a thread, in priority order. Returns
35 * `null` for quiescent threads so rows stay free of "Idle"-style noise.
36 * Mirrors `resolveThreadStatusPill` in apps/web/src/components/Sidebar.logic.ts.
37 */
38export function resolveThreadStatus(
39 thread: EnvironmentThreadShell,
40): ThreadStatusPresentation | null {
41 if (thread.hasPendingApprovals) {
42 return {
43 kind: "pending-approval",
44 label: "Needs Approval",
45 pillClassName: "bg-adaptive-amber-500-a12-a16",
46 textClassName: "text-adaptive-amber-700-300",
47 iconColor: "#ff9f0a",
48 iconBackground: "rgba(255,159,10,0.22)",
49 pulse: false,
50 };
51 }
52​
53 if (thread.hasPendingUserInput) {
54 return {
55 kind: "awaiting-input",
56 label: "Awaiting Input",
57 pillClassName: "bg-adaptive-indigo-500-a12-a16",
58 textClassName: "text-adaptive-indigo-700-300",
59 iconColor: "#5e5ce6",
60 iconBackground: "rgba(94,92,230,0.22)",
61 pulse: false,
62 };
63 }
64​
65 if (thread.session?.status === "running") {
66 return {
67 kind: "working",
68 label: "Working",
69 pillClassName: "bg-adaptive-sky-500-a12-a16",
70 textClassName: "text-adaptive-sky-700-300",
71 iconColor: "#0a84ff",
72 iconBackground: "rgba(10,132,255,0.22)",
73 pulse: true,
74 };
75 }
76​
77 if (thread.session?.status === "starting") {
78 return {
79 kind: "connecting",
80 label: "Connecting",
81 pillClassName: "bg-adaptive-sky-500-a12-a16",
82 textClassName: "text-adaptive-sky-700-300",
83 iconColor: "#0a84ff",
84 iconBackground: "rgba(10,132,255,0.22)",
85 pulse: true,
86 };
87 }
88​
89 if (thread.session?.status === "error" || thread.latestTurn?.state === "error") {
90 return {
91 kind: "error",
92 label: "Error",
93 pillClassName: "bg-adaptive-rose-500-a12-a16",
94 textClassName: "text-adaptive-rose-700-300",
95 iconColor: "#ff453a",
96 iconBackground: "rgba(255,69,58,0.22)",
97 pulse: false,
98 };
99 }
100​
101 const hasPlanReadyPrompt =
102 thread.interactionMode === "plan" &&
103 isLatestTurnSettled(thread.latestTurn, thread.session) &&
104 thread.hasActionableProposedPlan;
105 if (hasPlanReadyPrompt) {
106 return {
107 kind: "plan-ready",
108 label: "Plan Ready",
109 pillClassName: "bg-adaptive-violet-500-a12-a16",
110 textClassName: "text-adaptive-violet-700-300",
111 iconColor: "#bf5af2",
112 iconBackground: "rgba(191,90,242,0.22)",
113 pulse: false,
114 };
115 }
116​
117 return null;