import type { EditorId, EnvironmentId, ProjectScript, ResolvedKeybindingsConfig, ThreadId, } from "@t3tools/contracts"; import type { EnvironmentConnectionPresentation } from "@t3tools/client-runtime/connection"; import { AlertTriangleIcon, XIcon } from "lucide-react"; import type { DraftId } from "../../composerDraftStore"; import { useT3ProjectFileScripts } from "../../hooks/useT3ProjectFileScripts"; import type { EnvMode, EnvironmentOption } from "../BranchToolbar.logic"; import { BranchToolbar } from "../BranchToolbar"; import { BranchToolbarEnvironmentSelector } from "../BranchToolbarEnvironmentSelector"; import GitActionsControl from "../GitActionsControl"; import ProjectScriptsControl, { type NewProjectScriptInput, type ProjectScriptActionResult, } from "../ProjectScriptsControl"; import { Button } from "../ui/button"; import { ScrollArea } from "../ui/scroll-area"; import { cn } from "../../lib/utils"; import { OpenInPicker } from "./OpenInPicker"; import { ThreadAutomationsPanel } from "./ThreadAutomationsPanel"; import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl"; interface VersionMismatchIssue { readonly clientVersion: string; readonly serverVersion: string; readonly serverLabel: string; } export interface ThreadDetailsPanelProps { mode: "inline" | "popover"; onClose?: () => void; environmentId: EnvironmentId; environmentConnection: EnvironmentConnectionPresentation | null; threadId: ThreadId; draftId?: DraftId; activeProjectName: string | undefined; activeProjectScripts: ReadonlyArray | undefined; preferredScriptId: string | null; keybindings: ResolvedKeybindingsConfig; availableEditors: ReadonlyArray; showOpenInPicker: boolean; gitCwd: string | null; isGitRepo: boolean; envLocked: boolean; availableEnvironments: readonly EnvironmentOption[]; onEnvironmentChange: (environmentId: EnvironmentId) => void; onEnvModeChange: (mode: EnvMode) => void; effectiveEnvModeOverride?: EnvMode; activeThreadBranchOverride?: string | null; onActiveThreadBranchOverrideChange?: (branch: string | null) => void; startFromOrigin: boolean; onStartFromOriginChange: (startFromOrigin: boolean) => void; onCheckoutPullRequestRequest?: (reference: string) => void; onComposerFocusRequest: () => void; onOpenChanges?: () => void; onReconnectEnvironment: () => void; onOpenConnectionSettings: () => void; versionMismatch: VersionMismatchIssue | null; onDismissVersionMismatch: () => void; onRunProjectScript: (script: ProjectScript) => void; onAddProjectScript: (input: NewProjectScriptInput) => Promise; onUpdateProjectScript: ( scriptId: string, input: NewProjectScriptInput, ) => Promise; onDeleteProjectScript: (scriptId: string) => Promise; } export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) { const fileScripts = useT3ProjectFileScripts( props.environmentId, props.activeProjectScripts ? props.gitCwd : null, ); const connectionIssue = props.environmentConnection !== null && props.environmentConnection.phase !== "connected" && props.environmentConnection.phase !== "available"; const isReconnecting = props.environmentConnection?.phase === "connecting" || props.environmentConnection?.phase === "reconnecting"; const branchToolbarProps = { showGitControls: props.isGitRepo, environmentId: props.environmentId, threadId: props.threadId, ...(props.draftId ? { draftId: props.draftId } : {}), onEnvModeChange: props.onEnvModeChange, startFromOrigin: props.startFromOrigin, onStartFromOriginChange: props.onStartFromOriginChange, ...(props.effectiveEnvModeOverride ? { effectiveEnvModeOverride: props.effectiveEnvModeOverride } : {}), ...(props.activeThreadBranchOverride !== undefined ? { activeThreadBranchOverride: props.activeThreadBranchOverride } : {}), ...(props.onActiveThreadBranchOverrideChange ? { onActiveThreadBranchOverrideChange: props.onActiveThreadBranchOverrideChange } : {}), envLocked: props.envLocked, onComposerFocusRequest: props.onComposerFocusRequest, ...(props.onCheckoutPullRequestRequest ? { onCheckoutPullRequestRequest: props.onCheckoutPullRequestRequest } : {}), }; const card = (

Workspace

{connectionIssue ? (

Environment unavailable

{props.environmentConnection?.error ?? "Reconnect this environment before sending messages or running actions."}

) : null} {props.versionMismatch ? (

Client and server versions differ

Client {props.versionMismatch.clientVersion} ยท {props.versionMismatch.serverLabel}{" "} {props.versionMismatch.serverVersion}

) : null}
{props.availableEnvironments.length > 1 ? ( ) : null} {props.showOpenInPicker ? ( ) : null} {props.activeProjectScripts ? ( ) : null}
{props.gitCwd ? (

Version Control

{props.isGitRepo ? ( ) : null} {props.activeProjectName ? ( ) : null}
) : null} {!props.draftId ? ( ) : null} {!props.draftId ? ( ) : null}
); if (props.mode === "popover") { return
{card}
; } return ( ); }