Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.5 KB
Raw Blame
'use client';

import { HotkeyEnum } from '@lobechat/const/hotkeys';
import { ActionIcon } from '@lobehub/ui';
import { SquareTerminalIcon } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';

import { useTerminalEntry } from '@/features/ChatTerminal/useTerminalEntry';
import { useGlobalStore } from '@/store/global';
import { systemStatusSelectors } from '@/store/global/selectors';
import { useUserStore } from '@/store/user';
import { settingsSelectors } from '@/store/user/selectors';
import { useHeaderActionSize } from '@/styles/density';

const TerminalPanelToggle = memo(() => {
  const { t } = useTranslation('chat');
  const [showTerminalPanel, toggleTerminalPanel] = useGlobalStore((s) => [
    systemStatusSelectors.showTerminalPanel(s),
    s.toggleTerminalPanel,
  ]);
  const hotkey = useUserStore(settingsSelectors.getHotkeyById(HotkeyEnum.ToggleTerminalPanel));
  const headerActionSmallSize = useHeaderActionSize(true);

  // Shown for coding agents only, and only where a shell can run; other agents
  // reach the terminal from the Overview resources (see `useTerminalEntry`).
  const visible = useTerminalEntry('header');

  if (!visible) return null;

  return (
    <ActionIcon
      active={showTerminalPanel}
      icon={SquareTerminalIcon}
      size={headerActionSmallSize}
      title={t('terminalPanel.title')}
      tooltipProps={{ hotkey, placement: 'bottom' }}
      onClick={() => toggleTerminalPanel()}
    />
  );
});

export default TerminalPanelToggle;