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 { ScrollArea } from "../ui/scroll-area";
23import { cn } from "../../lib/utils";
24import { OpenInPicker } from "./OpenInPicker";
25import { ThreadAutomationsPanel } from "./ThreadAutomationsPanel";
26import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl";
27
28interface VersionMismatchIssue {
29 readonly clientVersion: string;
30 readonly serverVersion: string;
31 readonly serverLabel: string;
32}
33
34export interface ThreadDetailsPanelProps {
35 mode: "inline" | "popover";
36 onClose?: () => void;
37 environmentId: EnvironmentId;
38 environmentConnection: EnvironmentConnectionPresentation | null;
39 threadId: ThreadId;
40 draftId?: DraftId;
41 activeProjectName: string | undefined;
42 activeProjectScripts: ReadonlyArray<ProjectScript> | undefined;
43 preferredScriptId: string | null;
44 keybindings: ResolvedKeybindingsConfig;
45 availableEditors: ReadonlyArray<EditorId>;
46 showOpenInPicker: boolean;
47 gitCwd: string | null;
48 isGitRepo: boolean;
49 envLocked: boolean;
50 availableEnvironments: readonly EnvironmentOption[];
51 onEnvironmentChange: (environmentId: EnvironmentId) => void;
52 onEnvModeChange: (mode: EnvMode) => void;
53 effectiveEnvModeOverride?: EnvMode;
54 activeThreadBranchOverride?: string | null;
55 onActiveThreadBranchOverrideChange?: (branch: string | null) => void;
56 startFromOrigin: boolean;
57 onStartFromOriginChange: (startFromOrigin: boolean) => void;
58 onCheckoutPullRequestRequest?: (reference: string) => void;
59 onComposerFocusRequest: () => void;
60 onOpenChanges?: () => void;
61 onReconnectEnvironment: () => void;
62 onOpenConnectionSettings: () => void;
63 versionMismatch: VersionMismatchIssue | null;
64 onDismissVersionMismatch: () => void;
65 onRunProjectScript: (script: ProjectScript) => void;
66 onAddProjectScript: (input: NewProjectScriptInput) => Promise<ProjectScriptActionResult>;
67 onUpdateProjectScript: (
68 scriptId: string,
69 input: NewProjectScriptInput,
70 ) => Promise<ProjectScriptActionResult>;
71 onDeleteProjectScript: (scriptId: string) => Promise<ProjectScriptActionResult>;
72}
73
74export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
75 const fileScripts = useT3ProjectFileScripts(
76 props.environmentId,
77 props.activeProjectScripts ? props.gitCwd : null,
78 );
79 const connectionIssue =
80 props.environmentConnection !== null &&
81 props.environmentConnection.phase !== "connected" &&
82 props.environmentConnection.phase !== "available";
83 const isReconnecting =
84 props.environmentConnection?.phase === "connecting" ||
85 props.environmentConnection?.phase === "reconnecting";
86 const branchToolbarProps = {
87 showGitControls: props.isGitRepo,
88 environmentId: props.environmentId,
89 threadId: props.threadId,
90 ...(props.draftId ? { draftId: props.draftId } : {}),
91 onEnvModeChange: props.onEnvModeChange,
92 startFromOrigin: props.startFromOrigin,
93 onStartFromOriginChange: props.onStartFromOriginChange,
94 ...(props.effectiveEnvModeOverride
95 ? { effectiveEnvModeOverride: props.effectiveEnvModeOverride }
96 : {}),
97 ...(props.activeThreadBranchOverride !== undefined
98 ? { activeThreadBranchOverride: props.activeThreadBranchOverride }
99 : {}),
100 ...(props.onActiveThreadBranchOverrideChange
101 ? { onActiveThreadBranchOverrideChange: props.onActiveThreadBranchOverrideChange }
102 : {}),
103 envLocked: props.envLocked,
104 onComposerFocusRequest: props.onComposerFocusRequest,
105 ...(props.onCheckoutPullRequestRequest
106 ? { onCheckoutPullRequestRequest: props.onCheckoutPullRequestRequest }
107 : {}),
108 };
109
110 const card = (
111 <div
112 className={cn(
113 // A single-track grid, because a grid area is a definite containing block: the card's own
114 // height is "content, clamped by max-height", which percentages treat as indefinite — as
115 // a plain block (or even a flex column) every `h-full`/`max-h-full` down the chain
116 // resolved to nothing, the scroll area's viewport stayed at its content height, and the
117 // card's overflow-hidden clipped the content instead of scrolling it. `minmax(0,1fr)`
118 // still shrink-wraps short content while letting the clamp bite on tall content.
119 "dropdown-glass isolate contain-paint grid max-h-full grid-rows-[minmax(0,1fr)] overflow-hidden rounded-[20px]",
120 // The popup's real ceiling is what base-ui measured for it — the anchor's clipping
121 // ancestors, which is how an open terminal drawer shrinks it — less the popover
122 // viewport's own p-2. The dvh term is the fallback's fallback, from before.
123 props.mode === "popover" &&
124 "max-h-[min(calc(100dvh-6.5rem),calc(var(--available-height,100dvh)-1rem))]",
125 )}
126 data-thread-details-card
127 >
128 <ScrollArea scrollFade className="min-h-0">
129 <section aria-labelledby="thread-details-workspace-heading">
130 <div className="flex min-h-10 items-center justify-between gap-3 px-3.5 pb-1 pt-3">
131 <h3
132 id="thread-details-workspace-heading"
133 className="text-[11px] font-medium text-muted-foreground"
134 >
135 Workspace
136 </h3>
137 </div>
138
139 {connectionIssue ? (
140 <div className="mx-3 mb-2 rounded-xl border border-warning/30 bg-warning/6 p-3">
141 <div className="flex gap-2">
142 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0 text-warning" />
143 <div className="min-w-0 flex-1">
144 <p className="text-xs font-medium">Environment unavailable</p>
145 <p className="mt-1 text-[11px] leading-relaxed text-muted-foreground">
146 {props.environmentConnection?.error ??
147 "Reconnect this environment before sending messages or running actions."}
148 </p>
149 <div className="mt-2 flex items-center gap-1.5">
150 <Button
151 size="xs"
152 disabled={isReconnecting}
153 onClick={props.onReconnectEnvironment}
154 >
155 {isReconnecting ? "Reconnecting..." : "Reconnect"}
156 </Button>
157 <Button size="xs" variant="ghost" onClick={props.onOpenConnectionSettings}>
158 Connections
159 </Button>
160 </div>
161 </div>
162 </div>
163 </div>
164 ) : null}
165
166 {props.versionMismatch ? (
167 <div className="mx-3 mb-2 flex gap-2 rounded-xl border border-warning/30 bg-warning/6 p-3">
168 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0 text-warning" />
169 <div className="min-w-0 flex-1">
170 <p className="text-xs font-medium">Client and server versions differ</p>
171 <p className="mt-1 text-[11px] leading-relaxed text-muted-foreground">
172 Client {props.versionMismatch.clientVersion} · {props.versionMismatch.serverLabel}{" "}
173 {props.versionMismatch.serverVersion}
174 </p>
175 </div>
176 <Button
177 size="icon-xs"
178 variant="ghost"
179 aria-label="Dismiss version mismatch warning"
180 onClick={props.onDismissVersionMismatch}
181 >
182 <XIcon className="size-3.5" />
183 </Button>
184 </div>
185 ) : null}
186
187 <div className="flex flex-col px-2 pb-2.5">
188 {props.availableEnvironments.length > 1 ? (
189 <BranchToolbarEnvironmentSelector
190 displayMode="panel"
191 envLocked={props.envLocked}
192 environmentId={props.environmentId}
193 availableEnvironments={props.availableEnvironments}
194 onEnvironmentChange={props.onEnvironmentChange}
195 />
196 ) : null}
197
198 <BranchToolbar layout="panel" panelSection="workspace" {...branchToolbarProps} />
199
200 {props.showOpenInPicker ? (
201 <OpenInPicker
202 environmentId={props.environmentId}
203 keybindings={props.keybindings}
204 availableEditors={props.availableEditors}
205 openInCwd={props.gitCwd}
206 displayMode="panel"
207 />
208 ) : null}
209
210 {props.activeProjectScripts ? (
211 <ProjectScriptsControl
212 displayMode="panel"
213 scripts={props.activeProjectScripts}
214 fileScripts={fileScripts}
215 keybindings={props.keybindings}
216 preferredScriptId={props.preferredScriptId}
217 onRunScript={props.onRunProjectScript}
218 onAddScript={props.onAddProjectScript}
219 onUpdateScript={props.onUpdateProjectScript}
220 onDeleteScript={props.onDeleteProjectScript}
221 />
222 ) : null}
223 </div>
224 </section>
225
226 {props.gitCwd ? (
227 <section
228 aria-labelledby="thread-details-version-control-heading"
229 className="border-t border-border/65"
230 >
231 <div className="px-3.5 pb-1 pt-3">
232 <h3
233 id="thread-details-version-control-heading"
234 className="text-[11px] font-medium text-muted-foreground"
235 >
236 Version Control
237 </h3>
238 </div>
239 <div className="flex flex-col px-2 pb-2.5">
240 {props.isGitRepo ? (
241 <BranchToolbar layout="panel" panelSection="branch" {...branchToolbarProps} />
242 ) : null}
243 {props.activeProjectName ? (
244 <GitActionsControl
245 displayMode="panel"
246 gitCwd={props.gitCwd}
247 activeThreadRef={{ environmentId: props.environmentId, threadId: props.threadId }}
248 {...(props.draftId ? { draftId: props.draftId } : {})}
249 {...(props.onOpenChanges ? { onOpenChanges: props.onOpenChanges } : {})}
250 />
251 ) : null}
252 </div>
253 </section>
254 ) : null}
255
256 {!props.draftId ? (
257 <ThreadAutomationsPanel environmentId={props.environmentId} threadId={props.threadId} />
258 ) : null}
259
260 {!props.draftId ? (
261 <ThreadRelationshipsPanel environmentId={props.environmentId} threadId={props.threadId} />
262 ) : null}
263 </ScrollArea>
264 </div>
265 );
266
267 if (props.mode === "popover") {
268 return <div data-thread-details-panel="popover">{card}</div>;
269 }
270
271 return (
272 <aside
273 aria-label="Thread details"
274 className="absolute inset-y-0 right-[var(--app-scrollbar-width)] z-20 w-[var(--thread-details-panel-width)] p-3"
275 data-thread-details-panel="inline"
276 >
277 {card}
278 </aside>
279 );
280}