Open History to see the last commit
1import type {
2 EditorId,
3 EnvironmentId,
4 ProjectScript,
5 ResolvedKeybindingsConfig,
6 ThreadId,
7} from "@t3tools/contracts";
8import type { EnvironmentConnectionPresentation } from "@t3tools/client-runtime/connection";
9import { AlertTriangleIcon, XIcon } from "lucide-react";
10
11import type { DraftId } from "../../composerDraftStore";
12import { useT3ProjectFileScripts } from "../../hooks/useT3ProjectFileScripts";
13import type { EnvMode, EnvironmentOption } from "../BranchToolbar.logic";
14import { BranchToolbar } from "../BranchToolbar";
15import { BranchToolbarEnvironmentSelector } from "../BranchToolbarEnvironmentSelector";
16import GitActionsControl from "../GitActionsControl";
17import ProjectScriptsControl, {
18 type NewProjectScriptInput,
19 type ProjectScriptActionResult,
20} from "../ProjectScriptsControl";
21import { Button } from "../ui/button";
22import { cn } from "../../lib/utils";
23import { OpenInPicker } from "./OpenInPicker";
24import { ThreadAutomationsPanel } from "./ThreadAutomationsPanel";
25import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl";
26
27interface VersionMismatchIssue {
28 readonly clientVersion: string;
29 readonly serverVersion: string;
30 readonly serverLabel: string;
31}
32
33export interface ThreadDetailsPanelProps {
34 mode: "inline" | "popover";
35 onClose?: () => void;
36 environmentId: EnvironmentId;
37 environmentConnection: EnvironmentConnectionPresentation | null;
38 threadId: ThreadId;
39 draftId?: DraftId;
40 activeProjectName: string | undefined;
41 activeProjectScripts: ReadonlyArray<ProjectScript> | undefined;
42 preferredScriptId: string | null;
43 keybindings: ResolvedKeybindingsConfig;
44 availableEditors: ReadonlyArray<EditorId>;
45 showOpenInPicker: boolean;
46 gitCwd: string | null;
47 isGitRepo: boolean;
48 envLocked: boolean;
49 availableEnvironments: readonly EnvironmentOption[];
50 onEnvironmentChange: (environmentId: EnvironmentId) => void;
51 onEnvModeChange: (mode: EnvMode) => void;
52 effectiveEnvModeOverride?: EnvMode;
53 activeThreadBranchOverride?: string | null;
54 onActiveThreadBranchOverrideChange?: (branch: string | null) => void;
55 startFromOrigin: boolean;
56 onStartFromOriginChange: (startFromOrigin: boolean) => void;
57 onCheckoutPullRequestRequest?: (reference: string) => void;
58 onComposerFocusRequest: () => void;
59 onOpenChanges?: () => void;
60 onReconnectEnvironment: () => void;
61 onOpenConnectionSettings: () => void;
62 versionMismatch: VersionMismatchIssue | null;
63 onDismissVersionMismatch: () => void;
64 onRunProjectScript: (script: ProjectScript) => void;
65 onAddProjectScript: (input: NewProjectScriptInput) => Promise<ProjectScriptActionResult>;
66 onUpdateProjectScript: (
67 scriptId: string,
68 input: NewProjectScriptInput,
69 ) => Promise<ProjectScriptActionResult>;
70 onDeleteProjectScript: (scriptId: string) => Promise<ProjectScriptActionResult>;
71}
72
73export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
74 const fileScripts = useT3ProjectFileScripts(
75 props.environmentId,
76 props.activeProjectScripts ? props.gitCwd : null,
77 );
78 const connectionIssue =
79 props.environmentConnection !== null &&
80 props.environmentConnection.phase !== "connected" &&
81 props.environmentConnection.phase !== "available";
82 const isReconnecting =
83 props.environmentConnection?.phase === "connecting" ||
84 props.environmentConnection?.phase === "reconnecting";
85 const branchToolbarProps = {
86 environmentId: props.environmentId,
87 threadId: props.threadId,
88 ...(props.draftId ? { draftId: props.draftId } : {}),
89 onEnvModeChange: props.onEnvModeChange,
90 startFromOrigin: props.startFromOrigin,
91 onStartFromOriginChange: props.onStartFromOriginChange,
92 ...(props.effectiveEnvModeOverride
93 ? { effectiveEnvModeOverride: props.effectiveEnvModeOverride }
94 : {}),
95 ...(props.activeThreadBranchOverride !== undefined
96 ? { activeThreadBranchOverride: props.activeThreadBranchOverride }
97 : {}),
98 ...(props.onActiveThreadBranchOverrideChange
99 ? { onActiveThreadBranchOverrideChange: props.onActiveThreadBranchOverrideChange }
100 : {}),
101 envLocked: props.envLocked,
102 onComposerFocusRequest: props.onComposerFocusRequest,
103 ...(props.onCheckoutPullRequestRequest
104 ? { onCheckoutPullRequestRequest: props.onCheckoutPullRequestRequest }
105 : {}),
106 };
107
108 const card = (
109 <div
110 className={cn(
111 "panel-glass overflow-hidden rounded-[20px]",
112 props.mode === "inline" ? "max-h-full" : "max-h-[calc(100dvh-6.5rem)]",
113 )}
114 data-thread-details-card
115 >
116 <div
117 className={cn(
118 "overflow-x-hidden overflow-y-auto overscroll-contain [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
119 props.mode === "inline" ? "max-h-full" : "max-h-[calc(100dvh-6.5rem)]",
120 )}
121 >
122 <section aria-labelledby="thread-details-workspace-heading">
123 <div className="flex min-h-10 items-center justify-between gap-3 px-3.5 pb-1 pt-3">
124 <h3
125 id="thread-details-workspace-heading"
126 className="text-[11px] font-medium text-muted-foreground"
127 >
128 Workspace
129 </h3>
130 </div>
131
132 {connectionIssue ? (
133 <div className="mx-3 mb-2 rounded-xl border border-warning/30 bg-warning/6 p-3">
134 <div className="flex gap-2">
135 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0 text-warning" />
136 <div className="min-w-0 flex-1">
137 <p className="text-xs font-medium">Environment unavailable</p>
138 <p className="mt-1 text-[11px] leading-relaxed text-muted-foreground">
139 {props.environmentConnection?.error ??
140 "Reconnect this environment before sending messages or running actions."}
141 </p>
142 <div className="mt-2 flex items-center gap-1.5">
143 <Button
144 size="xs"
145 disabled={isReconnecting}
146 onClick={props.onReconnectEnvironment}
147 >
148 {isReconnecting ? "Reconnecting..." : "Reconnect"}
149 </Button>
150 <Button size="xs" variant="ghost" onClick={props.onOpenConnectionSettings}>
151 Connections
152 </Button>
153 </div>
154 </div>
155 </div>
156 </div>
157 ) : null}
158
159 {props.versionMismatch ? (
160 <div className="mx-3 mb-2 flex gap-2 rounded-xl border border-warning/30 bg-warning/6 p-3">
161 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0 text-warning" />
162 <div className="min-w-0 flex-1">
163 <p className="text-xs font-medium">Client and server versions differ</p>
164 <p className="mt-1 text-[11px] leading-relaxed text-muted-foreground">
165 Client {props.versionMismatch.clientVersion} · {props.versionMismatch.serverLabel}{" "}
166 {props.versionMismatch.serverVersion}
167 </p>
168 </div>
169 <Button
170 size="icon-xs"
171 variant="ghost"
172 aria-label="Dismiss version mismatch warning"
173 onClick={props.onDismissVersionMismatch}
174 >
175 <XIcon className="size-3.5" />
176 </Button>
177 </div>
178 ) : null}
179
180 <div className="flex flex-col px-2 pb-2.5">
181 {props.availableEnvironments.length > 1 ? (
182 <BranchToolbarEnvironmentSelector
183 displayMode="panel"
184 envLocked={props.envLocked}
185 environmentId={props.environmentId}
186 availableEnvironments={props.availableEnvironments}
187 onEnvironmentChange={props.onEnvironmentChange}
188 />
189 ) : null}
190
191 <BranchToolbar layout="panel" panelSection="workspace" {...branchToolbarProps} />
192
193 {props.showOpenInPicker ? (
194 <OpenInPicker
195 environmentId={props.environmentId}
196 keybindings={props.keybindings}
197 availableEditors={props.availableEditors}
198 openInCwd={props.gitCwd}
199 displayMode="panel"
200 />
201 ) : null}
202
203 {props.activeProjectScripts ? (
204 <ProjectScriptsControl
205 displayMode="panel"
206 scripts={props.activeProjectScripts}
207 fileScripts={fileScripts}
208 keybindings={props.keybindings}
209 preferredScriptId={props.preferredScriptId}
210 onRunScript={props.onRunProjectScript}
211 onAddScript={props.onAddProjectScript}
212 onUpdateScript={props.onUpdateProjectScript}
213 onDeleteScript={props.onDeleteProjectScript}
214 />
215 ) : null}
216 </div>
217 </section>
218
219 {props.gitCwd ? (
220 <section
221 aria-labelledby="thread-details-version-control-heading"
222 className="border-t border-border/65"
223 >
224 <div className="px-3.5 pb-1 pt-3">
225 <h3
226 id="thread-details-version-control-heading"
227 className="text-[11px] font-medium text-muted-foreground"
228 >
229 Version Control
230 </h3>
231 </div>
232 <div className="flex flex-col px-2 pb-2.5">
233 {props.isGitRepo ? (
234 <BranchToolbar layout="panel" panelSection="branch" {...branchToolbarProps} />
235 ) : null}
236 {props.activeProjectName ? (
237 <GitActionsControl
238 displayMode="panel"
239 gitCwd={props.gitCwd}
240 activeThreadRef={{ environmentId: props.environmentId, threadId: props.threadId }}
241 {...(props.draftId ? { draftId: props.draftId } : {})}
242 {...(props.onOpenChanges ? { onOpenChanges: props.onOpenChanges } : {})}
243 />
244 ) : null}
245 </div>
246 </section>
247 ) : null}
248
249 {!props.draftId ? (
250 <ThreadAutomationsPanel environmentId={props.environmentId} threadId={props.threadId} />
251 ) : null}
252
253 {!props.draftId ? (
254 <ThreadRelationshipsPanel environmentId={props.environmentId} threadId={props.threadId} />
255 ) : null}
256 </div>
257 </div>
258 );
259
260 if (props.mode === "popover") {
261 return (
262 <div className="max-h-[calc(100dvh-6.5rem)]" data-thread-details-panel="popover">
263 {card}
264 </div>
265 );
266 }
267
268 return (
269 <aside
270 aria-label="Thread details"
271 className="absolute inset-y-0 right-[var(--app-scrollbar-width)] z-20 w-[var(--thread-details-panel-width)] p-3"
272 data-thread-details-panel="inline"
273 >
274 {card}
275 </aside>
276 );
277}