/* eslint-disable @typescript-eslint/no-explicit-any */ import { Activity, FolderTree, History, MessageSquare, Palette, PanelLeft, PanelRight, X, Zap } from 'lucide-react'; import { SystemManagerSidePanel } from '../systemManager/SystemManagerSidePanel'; import React, { memo, useCallback, useState } from 'react'; import { useActiveTabId } from '../../application/state/activeTabStore'; import { terminalLayoutSuppressStore } from '../../application/state/terminalLayoutSuppressStore'; import { AI_PANEL_FORCE_HIDE_SHELL } from '../ai/aiPanelDiagnostics'; import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip'; import type { SidePanelTab } from './TerminalLayerSupport'; import { terminalLayerSidePanelCtxEqual } from './terminalLayerViewMemo'; type SidePanelContext = Record; export function getTerminalSidePanelShellWidth({ activeSidePanelTab, forceHideAiShell, isSidePanelOpenForCurrentTab, resizePreviewWidth, sidePanelWidth, }: { activeSidePanelTab: SidePanelTab | null; forceHideAiShell: boolean; isSidePanelOpenForCurrentTab: boolean; resizePreviewWidth: number | null; sidePanelWidth: number; }): number { if (forceHideAiShell && activeSidePanelTab === 'ai') return 0; return isSidePanelOpenForCurrentTab ? (resizePreviewWidth ?? sidePanelWidth) : 0; } function TerminalLayerSidePanelShell({ ctx }: { ctx: SidePanelContext }) { const { mountedAiTabIds, mountedSftpTabIds, scriptsMountedTabIds, systemMountedTabIds, themeMountedTabIds, sidePanelOpenTabs, } = ctx; const anyHistoryOpen = sidePanelOpenTabs instanceof Map && Array.from((sidePanelOpenTabs as Map).values()).includes('history'); if ( mountedSftpTabIds.length === 0 && mountedAiTabIds.length === 0 && scriptsMountedTabIds.length === 0 && systemMountedTabIds.length === 0 && themeMountedTabIds.length === 0 && !anyHistoryOpen ) { return null; } return ; } function TerminalLayerSidePanelTabBody({ ctx }: { ctx: SidePanelContext }) { const activeTabId = useActiveTabId(); const sidePanelOpenTabs = ctx.sidePanelOpenTabs as Map; const isSidePanelOpenForCurrentTab = activeTabId ? sidePanelOpenTabs.has(activeTabId) : false; const activeSidePanelTab = activeTabId ? sidePanelOpenTabs.get(activeTabId) ?? null : null; const { activeTerminalCwd, activeTerminalSessionIdForSftp, activeWorkspace, AIChatPanelsHost, AISidePanelStateRoot, aiContextsByTabId, Button: Btn, cn, editorWordWrap, effectiveHosts, focusedFontFamilyId, focusedFontFamilyOverridden, focusedFontSize, focusedFontSizeOverridden, focusedFontWeight, focusedFontWeightOverridden, focusedHost, focusedThemeOverridden, followAppTerminalTheme, getTerminalCwd, handleCloseSidePanel, handleHistoryPaste, handleHistoryRun, handleOpenHistory, handleFontFamilyChangeForFocusedSession, handleFontFamilyResetForFocusedSession, handleFontSizeChangeForFocusedSession, handleFontSizeResetForFocusedSession, handleFontWeightChangeForFocusedSession, handleFontWeightResetForFocusedSession, handleOpenAI, handleOpenScripts, handleOpenSystem, handleOpenTheme, activeTerminalSessionForSystem, activeSystemSessionHost, handlePendingTerminalSelectionConsumed, handleSftpInitialLocationApplied, handleSnippetFromPanel, handleThemeChangeForFocusedSession, handleThemeResetForFocusedSession, handleToggleSftpFromBar, handlePendingUploadHandled, historySessionId, HistorySidePanel, hosts, hotkeyScheme, identities, keyBindings, keys, mountedAiTabIds, mountedSftpTabIds, scriptsMountedTabIds, systemMountedTabIds, themeMountedTabIds, pendingTerminalSelectionForAI, previewedOrVisibleThemeId, refocusActiveTerminalSession, remoteHistory, shellHistory, resolveAIExecutorContext, resolvedPreviewTheme, ScriptsSidePanel, setEditorWordWrap, setSidePanelPosition, setSidePanelWidth, setSftpFollowTerminalCwd, persistSidePanelWidth, sftpActiveHost, sftpHostForTab, sftpAutoSync, sftpDefaultViewMode, sftpDoubleClickBehavior, sftpFollowTerminalCwd, sftpInitialLocationForTab, sftpPendingUploadsForTab, sftpShowHiddenFiles, SftpSidePanel, sftpUseCompressedUpload, sidePanelPosition, sidePanelWidth, snippetPackages, snippets, t, terminalFontFamilyId, terminalSettings, terminalTheme, ThemeSidePanel, updateHosts, updateSnippetPackages, updateSnippets, validAIScopeTargetIds, } = ctx; const [resizePreviewWidth, setResizePreviewWidth] = useState(null); const isAiShellForceHidden = AI_PANEL_FORCE_HIDE_SHELL && activeSidePanelTab === 'ai'; const shouldRenderAiPanels = mountedAiTabIds.length > 0 && !isAiShellForceHidden; const shellWidth = getTerminalSidePanelShellWidth({ activeSidePanelTab, forceHideAiShell: AI_PANEL_FORCE_HIDE_SHELL, isSidePanelOpenForCurrentTab, resizePreviewWidth, sidePanelWidth, }); const handleSidePanelResizeStart = useCallback((event: React.MouseEvent) => { if (!isSidePanelOpenForCurrentTab) return; event.preventDefault(); terminalLayoutSuppressStore.begin(); const startX = event.clientX; const startWidth = sidePanelWidth; let lastWidth = startWidth; let rafId: number | null = null; const onMouseMove = (moveEvent: MouseEvent) => { const delta = moveEvent.clientX - startX; lastWidth = Math.max( 280, Math.min(800, startWidth + (sidePanelPosition === 'left' ? delta : -delta)), ); if (rafId !== null) return; rafId = requestAnimationFrame(() => { rafId = null; setResizePreviewWidth(lastWidth); }); }; const onMouseUp = () => { if (rafId !== null) cancelAnimationFrame(rafId); setSidePanelWidth(lastWidth); persistSidePanelWidth(lastWidth); setResizePreviewWidth(null); terminalLayoutSuppressStore.end(); window.removeEventListener('mousemove', onMouseMove); window.removeEventListener('mouseup', onMouseUp); }; window.addEventListener('mousemove', onMouseMove); window.addEventListener('mouseup', onMouseUp); }, [ isSidePanelOpenForCurrentTab, persistSidePanelWidth, setSidePanelWidth, sidePanelPosition, sidePanelWidth, ]); return ( <>
{isSidePanelOpenForCurrentTab && !isAiShellForceHidden && (
)}
{isSidePanelOpenForCurrentTab && !isAiShellForceHidden && (
{t('terminal.layer.sftp')} {t('terminal.layer.scripts')} {t('terminal.layer.history')} {t('terminal.layer.theme')} {t('terminal.layer.system')} {t('terminal.layer.aiChat')}
setSidePanelPosition((p: 'left' | 'right') => (p === 'left' ? 'right' : 'left'))} > {sidePanelPosition === 'left' ? : } {sidePanelPosition === 'left' ? t('terminal.layer.movePanelRight') : t('terminal.layer.movePanelLeft')} {t('terminal.layer.closePanel')}
)}
{mountedSftpTabIds.map((tabId: string) => { const isVisibleSftpPanel = activeTabId === tabId && activeSidePanelTab === 'sftp'; const storedSftpHost = sftpHostForTab.get(tabId) ?? null; const panelActiveHost = isVisibleSftpPanel ? (sftpActiveHost ?? storedSftpHost) : storedSftpHost; return (
handleSftpInitialLocationApplied(tabId, location)} showWorkspaceHostHeader={isVisibleSftpPanel && !!activeWorkspace} isVisible={isVisibleSftpPanel} renderOverlays={isVisibleSftpPanel} pendingUpload={sftpPendingUploadsForTab.get(tabId) ?? null} onPendingUploadHandled={(requestId) => handlePendingUploadHandled(tabId, requestId)} sftpDoubleClickBehavior={sftpDoubleClickBehavior} sftpAutoSync={isVisibleSftpPanel ? sftpAutoSync : false} sftpShowHiddenFiles={sftpShowHiddenFiles} sftpUseCompressedUpload={sftpUseCompressedUpload} hotkeyScheme={hotkeyScheme} keyBindings={keyBindings} editorWordWrap={editorWordWrap} setEditorWordWrap={setEditorWordWrap} onGetTerminalCwd={getTerminalCwd} activeTerminalCwd={isVisibleSftpPanel && sftpFollowTerminalCwd ? activeTerminalCwd : null} sftpFollowTerminalCwd={sftpFollowTerminalCwd} onSftpFollowTerminalCwdChange={setSftpFollowTerminalCwd} onRequestTerminalFocus={refocusActiveTerminalSession} terminalSettings={terminalSettings} />
); })} {systemMountedTabIds.map((tabId: string) => { const isVisibleSystemPanel = activeTabId === tabId && activeSidePanelTab === 'system'; return (
); })} {scriptsMountedTabIds.map((tabId: string) => { const isVisibleScriptsPanel = activeTabId === tabId && activeSidePanelTab === 'scripts'; return (
); })} {activeSidePanelTab === 'history' && (
)} {themeMountedTabIds.map((tabId: string) => { const isVisibleThemePanel = activeTabId === tabId && activeSidePanelTab === 'theme'; return (
); })} {shouldRenderAiPanels && ( )}
); } export const TerminalLayerSidePanelSection = memo( TerminalLayerSidePanelShell, (prev, next) => terminalLayerSidePanelCtxEqual(prev.ctx, next.ctx), ); TerminalLayerSidePanelSection.displayName = 'TerminalLayerSidePanelSection';