Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

4.3 KB
Raw Blame
import { FolderInput } from 'lucide-react';
import { observer } from 'mobx-react-lite';
import React from 'react';
import { SidebarOnboardingChecklist } from '@renderer/features/onboarding/sidebar-onboarding-checklist';
import { useNavigate } from '@renderer/lib/layout/navigation-provider';
import { SwitchConsoleMark } from '@renderer/lib/switch-console-mark';
import { cn } from '@renderer/utils/utils';
import { FROZEN, isFrozenServer } from '../switch-servers/managed-server-state';
import { switchServersStore } from '../switch-servers/switch-servers-store';
import { WorkspaceSwitcher } from '../switch-servers/workspace-switcher';
import { SidebarPinnedSessionList } from './pinned-session-list';
import { SessionDiscoveryStatus } from './session-discovery-status';
import { SessionsSectionHeader } from './sessions-section-header';
import { SidebarGroupedList, useAgentManagementMode } from './sidebar-grouped-list';
import {
  SidebarContainer,
  SidebarContent,
  SidebarGroup,
  SidebarGroupContent,
  SidebarMenu,
} from './sidebar-primitives';
import { SidebarSpace } from './sidebar-space';
import { UpdateSection } from './update-section';
import { useSidebarDrop } from './use-sidebar-drop';
import { WorkspaceNav } from './workspace-nav';

export const LeftSidebar: React.FC = observer(function LeftSidebar() {
  const { navigate } = useNavigate();

  const { isDragOver, onDragOver, onDragEnter, onDragLeave, onDrop } = useSidebarDrop();
  const managementMode = useAgentManagementMode();
  const activeServer = switchServersStore.activeServer;
  const frozen = activeServer !== null && isFrozenServer(activeServer);

  return (
    <div
      className={cn(
        'relative flex flex-col h-full text-foreground-tertiary-muted transition-colors',
        isDragOver && 'bg-accent/10 ring-2 ring-inset ring-accent/50'
      )}
      onDragOver={onDragOver}
      onDragEnter={onDragEnter}
      onDragLeave={onDragLeave}
      onDrop={onDrop}
    >
      {isDragOver && (
        <div className="pointer-events-none absolute inset-0 z-50 flex flex-col items-center justify-center gap-2 bg-background-tertiary/80 backdrop-blur-sm">
          <FolderInput className="size-8 text-foreground" />
          <span className="text-xs font-medium text-foreground">Drop to add agent</span>
        </div>
      )}
      <SidebarSpace />
      <SidebarContainer className="min-h-0 w-full flex-1 border-r-0">
        <SidebarContent className="flex flex-col">
          <div className={cn(frozen && FROZEN)}>
            <SidebarPinnedSessionList />
          </div>
          {/* The sidebar reads as three blocks — which server, that server's
              pages, then its sessions. The switcher and the nav under it are
              one block, 8px apart, which the nav owns as its own top padding;
              the sessions section sets the larger gap that separates it. */}
          <div className="flex flex-col">
            <WorkspaceSwitcher />
            <WorkspaceNav />
          </div>
          <SidebarGroup className={cn('mt-0 mb-0 flex min-h-0 flex-1 flex-col', frozen && FROZEN)}>
            {/* With agent management the sections draw their own headings,
                inside the list, so they scroll with it. */}
            {!managementMode && <SessionsSectionHeader />}
            {!managementMode && <SessionDiscoveryStatus />}
            <SidebarGroupContent className="flex min-h-0 flex-1 flex-col">
              <SidebarMenu className="flex min-h-0 flex-1 flex-col">
                <SidebarGroupedList />
              </SidebarMenu>
            </SidebarGroupContent>
          </SidebarGroup>
        </SidebarContent>
        <SidebarOnboardingChecklist />
        <div className="flex items-center justify-between gap-2 px-3 py-2">
          {/* The mark doubles as the way back to the welcome screen — the one
              view with no other entry point once you have navigated away. */}
          <button
            type="button"
            onClick={() => navigate('home')}
            aria-label="Go to home"
            title="Home"
            className="rounded-md text-[var(--fg-passive)] transition-colors hover:text-foreground"
          >
            <SwitchConsoleMark size={18} />
          </button>
          <UpdateSection />
        </div>
      </SidebarContainer>
    </div>
  );
});