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