/* eslint-disable max-lines -- 远程连接向导的多个步骤暂集中在同一文件,避免拆分时扩大 SSH/Docker/WSL 回归面。 */ import { useState } from "react"; import type { DockerContainerInfo, RemoteAssetInstallMode, RemoteTarget, RemoteWorkspaceSessionEntry, SSHConfigAliasOption, WSLDistro, } from "@zcode/shared"; import { TID_REMOTE_KIND_DOCKER, TID_REMOTE_KIND_SSH, TID_REMOTE_KIND_WSL } from "@zcode/shared"; import type { IMcpSyncService, IPluginSyncService, IServiceAccessor, ISkillSyncService, IZCodeAgentService, } from "@zcode/services"; import { AlertTriangleIcon, ChevronRightIcon, LoaderIcon, MonitorCogIcon, ServerIcon, TerminalIcon, } from "lucide-react"; import { DirectoryBrowser } from "@/DirectoryBrowser.js"; import { RemoteConnectionFields } from "@/RemoteConnectionFields.js"; import type { SSHAuthMethod } from "@/hooks/useRemoteConnectionForm.js"; import { Button } from "@/components/ui/button.js"; import { cn } from "@/components/lib/utils.js"; import { useZCodeIntl } from "@/i18n/IntlProvider.js"; import { RemoteSyncDialogs, RemoteSyncDropdownButton, shouldShowRemoteSyncActions, } from "@/settings/RemoteSyncActions.js"; export { RemoteConnectionConnectingStep } from "@/remote-connection/RemoteConnectionConnectingStep.js"; function getKindIcon(kind: RemoteTarget["kind"]) { switch (kind) { case "ssh": return ServerIcon; case "docker": return MonitorCogIcon; case "wsl": return TerminalIcon; } } export function RemoteConnectionKindStep({ kind, availableKinds, onKindChange, onCancel, onNext, }: { kind: RemoteTarget["kind"]; availableKinds: RemoteTarget["kind"][]; onKindChange: (value: RemoteTarget["kind"]) => void; onCancel: () => void; onNext: () => void; }) { const { intl } = useZCodeIntl(); return (
{availableKinds.map((value) => { const Icon = getKindIcon(value); const selected = kind === value; return ( ); })}
); } export function RemoteConnectionSettingsStep({ kind, host, port, username, sshAuthMethod, assetInstallMode, password, privateKeyPath, privateKeyPassphrase, wslDistro, wslUser = "", wslDistros, dockerContainer, manualDockerContainer, dockerContainers, dockerAvailable, sshConfigAliases, sshConfigAliasesLoading, sshConfigAliasesError, selectedSshConfigAlias, currentRuntimeOptionsLoading, currentRuntimeOptionsError, remoteWorkspaceSessions = [], validationMessage, loading, onBack, onHostChange, onPortChange, onUsernameChange, onSshAuthMethodChange, onAssetInstallModeChange, onPasswordChange, onPrivateKeyPathChange, onPrivateKeyPassphraseChange, onWslDistroChange, onWslUserChange, onDockerContainerChange, onManualDockerContainerChange, onDockerContainersRefresh, onApplySshConfigAlias, onClearSelectedSshConfigAlias, onConnect, }: { kind: RemoteTarget["kind"]; host: string; port: string; username: string; sshAuthMethod: SSHAuthMethod; assetInstallMode: RemoteAssetInstallMode; password: string; privateKeyPath: string; privateKeyPassphrase: string; wslDistro: string; wslUser?: string; wslDistros: WSLDistro[]; dockerContainer: string; manualDockerContainer: string; dockerContainers: DockerContainerInfo[]; dockerAvailable: boolean | null; sshConfigAliases: SSHConfigAliasOption[]; sshConfigAliasesLoading: boolean; sshConfigAliasesError: string; selectedSshConfigAlias: string | null; currentRuntimeOptionsLoading: boolean; currentRuntimeOptionsError: string; remoteWorkspaceSessions?: RemoteWorkspaceSessionEntry[]; validationMessage: string; loading: boolean; onBack: () => void; onHostChange: (value: string) => void; onPortChange: (value: string) => void; onUsernameChange: (value: string) => void; onSshAuthMethodChange: (value: SSHAuthMethod) => void; onAssetInstallModeChange: (value: RemoteAssetInstallMode) => void; onPasswordChange: (value: string) => void; onPrivateKeyPathChange: (value: string) => void; onPrivateKeyPassphraseChange: (value: string) => void; onWslDistroChange: (value: string) => void; onWslUserChange?: (value: string) => void; onDockerContainerChange: (value: string) => void; onManualDockerContainerChange: (value: string) => void; onDockerContainersRefresh?: () => void; onApplySshConfigAlias: (value: SSHConfigAliasOption) => void; onClearSelectedSshConfigAlias: () => void; onConnect: () => void; }) { const { intl } = useZCodeIntl(); return (
{currentRuntimeOptionsError ? (
{intl.formatMessage({ id: "remote.optionsLoadFailed" })}
) : null}
{validationMessage ? (
{validationMessage}
) : null}
); } export function RemoteConnectionDirectoryStep({ services, remoteTarget, localSkillSyncService, remoteSkillSyncService, localMcpSyncService, remoteMcpSyncService, localPluginSyncService, remotePluginSyncService, localZCodeAgentService, remoteZCodeAgentService, localWorkspacePath, selecting = false, onSelect, onBack, onCancel, onSkillsSynced, onMcpSynced, onPluginsSynced, }: { services: IServiceAccessor | null; remoteTarget?: RemoteTarget | null; localSkillSyncService?: ISkillSyncService; remoteSkillSyncService?: ISkillSyncService | null; localMcpSyncService?: IMcpSyncService; remoteMcpSyncService?: IMcpSyncService | null; localPluginSyncService?: IPluginSyncService; remotePluginSyncService?: IPluginSyncService | null; localZCodeAgentService?: IZCodeAgentService; remoteZCodeAgentService?: IZCodeAgentService | null; localWorkspacePath?: string; selecting?: boolean; onSelect: (path: string) => void; onBack: () => void; onCancel: () => void; onSkillsSynced?: () => Promise | void; onMcpSynced?: () => Promise | void; onPluginsSynced?: () => Promise | void; }) { const { intl } = useZCodeIntl(); const [selectedPath, setSelectedPath] = useState(""); const [remoteSkillSyncOpen, setRemoteSkillSyncOpen] = useState(false); const [remoteMcpSyncOpen, setRemoteMcpSyncOpen] = useState(false); const [remotePluginSyncOpen, setRemotePluginSyncOpen] = useState(false); const canShowRemoteSyncActions = shouldShowRemoteSyncActions({ remoteSessionId: remoteTarget ? "directory-step" : null, remoteTarget, clientMode: "desktop-continuous", hasLocalSourceService: Boolean( localSkillSyncService || localMcpSyncService || localPluginSyncService, ), }); const canSyncRemoteSkills = Boolean( canShowRemoteSyncActions && localSkillSyncService && remoteSkillSyncService, ); const canSyncRemoteMcp = Boolean( canShowRemoteSyncActions && localMcpSyncService && remoteMcpSyncService, ); const canSyncRemotePlugins = Boolean( canShowRemoteSyncActions && localPluginSyncService && remotePluginSyncService, ); if (!services) { return (
{intl.formatMessage({ id: "common.loading" })}
); } return (
{intl.formatMessage({ id: "remote.success" })} setRemoteSkillSyncOpen(true)} onOpenMcpSync={() => setRemoteMcpSyncOpen(true)} onOpenPluginSync={() => setRemotePluginSyncOpen(true)} />
{/* 该容器之前不是 flex,导致子级 DirectoryBrowser 的 flex-1 无法拿到有效高度, 目录项变多时 overflow-y-auto 不生效,列表不能垂直滚动。 */}
{ await onSkillsSynced?.(); }} onMcpSynced={async () => { await onMcpSynced?.(); }} onPluginsSynced={async () => { await onPluginsSynced?.(); }} />
); }