Skip to content

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

1.7 KB
Raw Blame
import type { SidebarGrouping } from '@shared/view-state';

/**
 * What the sidebar says in place of its tree, if anything.
 *
 * Agent filters narrowing everything away is only an empty *agent* list: the
 * room view lists rooms, which are still there, and reports its own filters
 * being too narrow itself. A server with nothing on it yet otherwise left the
 * panel blank, which reads as the list having failed to load rather than as
 * there being nothing to list; its managed agents are listed below the tree,
 * so a server that has them is not empty.
 */
export function sidebarEmptyState(input: {
  grouping: SidebarGrouping;
  hasActiveFilters: boolean;
  filteredLocationCount: number;
  activeServerId: string | null;
  locationCount: number;
  roomCount: number;
  /** Agents listed from the server rather than Console rows: the managed ones. */
  serverListedAgentCount: number;
}): 'no-filter-match' | 'empty' | null {
  if (input.grouping !== 'room' && input.hasActiveFilters && input.filteredLocationCount === 0)
    return 'no-filter-match';
  if (
    !input.hasActiveFilters &&
    input.activeServerId !== null &&
    input.locationCount === 0 &&
    input.roomCount === 0 &&
    input.serverListedAgentCount === 0
  )
    return 'empty';
  return null;
}

/**
 * Whether the sidebar shows Agents / Rooms under agent management: once
 * anything is managed, while switch-buddy waits on a provider (its row is the
 * way back to its page), or with no agents at all, where there is nothing
 * legacy to show instead.
 */
export function showsAgentsAndRooms(input: {
  managedAgentCount: number;
  buddyPending: boolean;
  legacyAgentCount: number;
}): boolean {
  return input.managedAgentCount > 0 || input.buddyPending || input.legacyAgentCount === 0;
}