Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

4.9 KB
Raw Blame
import {
  Archive,
  ArrowDown,
  ArrowLeft,
  ArrowUp,
  BookOpen,
  Bot,
  Box,
  Brain,
  Calendar,
  CalendarClock,
  CalendarPlus,
  Check,
  ChevronDown,
  ChevronLeft,
  ChevronRight,
  ChevronsUpDown,
  CircleAlert,
  CircleCheck,
  CircleX,
  Clock,
  Code2,
  Copy,
  Cpu,
  DollarSign,
  Download,
  Ellipsis,
  EllipsisVertical,
  ExternalLink,
  File,
  FileCode2,
  FileSpreadsheet,
  FileText,
  Github,
  GripVertical,
  History,
  Info,
  LibraryBig,
  Lightbulb,
  LineChart,
  Link2,
  ListChecks,
  ListFilter,
  ListOrdered,
  Loader2,
  Lock,
  LogOut,
  Maximize2,
  Menu,
  MessageSquareText,
  Minimize2,
  Monitor,
  Moon,
  PanelLeft,
  PanelLeftClose,
  PanelLeftOpen,
  Paperclip,
  Pause,
  Pencil,
  Play,
  Plug,
  Plus,
  RefreshCw,
  RotateCw,
  Save,
  Search,
  Settings,
  Share,
  Shield,
  ShieldCheck,
  SlidersHorizontal,
  Sparkle,
  SquareArrowOutUpRight,
  SquarePen,
  Sun,
  Tag,
  Terminal,
  Trash2,
  TriangleAlert,
  UserCog,
  Users,
  Wrench,
  X,
} from 'lucide-react';
import type { SVGProps } from 'react';

import type { IconEntry, IconMap } from '../theme/types.js';

/** Lucide `broom` (https://lucide.dev/icons/broom) — not in lucide-react 0.x. */
function Broom({ size = 24, ...props }: SVGProps<SVGSVGElement> & { size?: string | number }) {
  return (
    <svg
      xmlns="http://www.w3.org/2000/svg"
      width={size}
      height={size}
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      strokeWidth="2"
      strokeLinecap="round"
      strokeLinejoin="round"
      {...props}
    >
      <path d="M13.5 10.5 22 2" />
      <path d="M14.734 13.841a2 2 0 00-.314-2.42L12.58 9.58a2 2 0 00-2.421-.314l-7.657 4.461A1 1 0 002.3 15.3l6.403 6.403a1 1 0 001.571-.204z" />
      <path d="m5 18 2-2" />
      <path d="m7.699 10.7 5.602 5.601" />
    </svg>
  );
}

const registry = new Map<string, IconEntry>();

export function registerIcon(name: string, icon: IconEntry): void {
  registry.set(name, icon);
}

export function registerIcons(icons: IconMap): void {
  for (const [name, icon] of Object.entries(icons)) {
    registry.set(name, icon);
  }
}

export function getIcon(name: string): IconEntry | undefined {
  return registry.get(name);
}

export function resolveIconName(icon: string | readonly string[]): string {
  if (typeof icon === 'string') return icon;
  // e.g. ["far", "clone"] → "clone"
  return icon[icon.length - 1] ?? '';
}

const defaults: Record<string, IconEntry> = {
  paperclip: Paperclip,
  'arrow-up': ArrowUp,
  'arrow-down': ArrowDown,
  'arrow-left': ArrowLeft,
  xmark: X,
  check: Check,
  pencil: Pencil,
  play: Play,
  pause: Pause,
  calendar: Calendar,
  'calendar-clock': CalendarClock,
  'calendar-plus': CalendarPlus,
  'grip-vertical': GripVertical,
  'square-pen': SquarePen,
  'rotate-right': RotateCw,
  'refresh-cw': RefreshCw,
  broom: Broom,
  ellipsis: Ellipsis,
  'ellipsis-vertical': EllipsisVertical,
  trash: Trash2,
  'box-archive': Archive,
  'clock-rotate-left': History,
  'circle-exclamation': CircleAlert,
  info: Info,
  'triangle-exclamation': TriangleAlert,
  'chevron-down': ChevronDown,
  'chevron-left': ChevronLeft,
  'chevron-right': ChevronRight,
  'chevrons-up-down': ChevronsUpDown,
  loader: Loader2,
  file: File,
  'file-code': FileCode2,
  'file-spreadsheet': FileSpreadsheet,
  'file-text': FileText,
  clone: Copy,
  copy: Copy,
  'dollar-sign': DollarSign,
  bars: Menu,
  'panel-left': PanelLeft,
  'panel-left-close': PanelLeftClose,
  'panel-left-open': PanelLeftOpen,
  plus: Plus,
  sun: Sun,
  moon: Moon,
  settings: Settings,
  share: Share,
  shield: Shield,
  'shield-check': ShieldCheck,
  sliders: SlidersHorizontal,
  'log-out': LogOut,
  search: Search,
  clock: Clock,
  'circle-check': CircleCheck,
  'circle-xmark': CircleX,
  'oauth-success': CircleCheck,
  'oauth-error': CircleX,
  'oauth-loading': Loader2,
  'welcome-sparkle': Sparkle,
  robot: Bot,
  bot: Bot,
  'library-big': LibraryBig,
  'message-square-text': MessageSquareText,
  'book-open': BookOpen,
  funnel: ListFilter,
  plug: Plug,
  'list-check': ListChecks,
  lock: Lock,
  'user-cog': UserCog,
  users: Users,
  lightbulb: Lightbulb,
  tag: Tag,
  link: Link2,
  wrench: Wrench,
  cpu: Cpu,
  cube: Box,
  'list-ol': ListOrdered,
  download: Download,
  save: Save,
  brain: Brain,
  terminal: Terminal,
  code: Code2,
  chart: LineChart,
  expand: Maximize2,
  'expand-alt': Maximize2,
  compress: Minimize2,
  'external-link': ExternalLink,
  'square-arrow-out-up-right': SquareArrowOutUpRight,
  github: Github,
  monitor: Monitor,
};

for (const [name, icon] of Object.entries(defaults)) {
  registry.set(name, icon);
}

/** Merge host `theme.icons` over the registry for a single lookup (does not mutate). */
export function lookupIcon(name: string, themeIcons?: IconMap): IconEntry | undefined {
  if (themeIcons && name in themeIcons) {
    return themeIcons[name];
  }
  return registry.get(name);
}