Skip to content

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

3.7 KB
Raw Blame
'use client';

import { useTrackAnalytics } from '../../analytics/AnalyticsProvider.js';
import { AnalyticsEvents } from '../../analytics/events.js';
import { withSessionProps } from '../../analytics/sessionProps.js';
import { Icon } from '../../icons/Icon.js';
import { shellIsCreateAgent, useOptionalShellMode } from '../../server/ShellModeContext.js';
import { useSlot } from '../../theme/SlotsProvider.js';
import type { ComposerLeftSectionProps, ComposerRightSectionProps } from '../ComposerSections.js';
import { useFallbackMissingSandboxEnvironment } from '../environments/useFallbackMissingSandboxEnvironment.js';
import { auiButtonClass } from '../lib/buttonClasses.js';
import { useCompactLayout } from '../lib/CompactLayoutContext.js';
import { useIsMobile } from '../lib/useIsMobile.js';
import { Tooltip } from '../primitives/Tooltip.js';
import { DraftReasoningEffortSelector } from './DraftReasoningEffortSelector.js';

export function DraftComposerLeftSection({ disabled, isRunning, onAttach }: ComposerLeftSectionProps) {
  useFallbackMissingSandboxEnvironment();
  const shell = useOptionalShellMode();
  const track = useTrackAnalytics();
  const DraftCompositeSelector = useSlot('DraftCompositeSelector');
  const DraftAgentConfigTrigger = useSlot('DraftAgentConfigTrigger');
  const DraftComposerActionsMenu = useSlot('DraftComposerActionsMenu');
  const compact = useCompactLayout();
  const isMobile = useIsMobile();
  const isBuilder = shell != null && shellIsCreateAgent(shell.mode);
  const compactActions = [
    {
      id: 'agent-config',
      label: 'Agent config',
      icon: 'sliders',
      onSelect: () => {
        track(
          AnalyticsEvents.Config.OPENED,
          withSessionProps(undefined, {
            ...(shell?.mode.status === 'active'
              ? { agentId: shell.mode.agentId, agentName: shell.mode.agentName }
              : {}),
          }),
        );
        shell?.setAgentConfigOpen(true);
      },
    },
    ...(onAttach === undefined
      ? []
      : [
          {
            id: 'attach',
            label: 'Attach a file',
            icon: 'paperclip',
            onSelect: onAttach,
          },
        ]),
  ];

  return (
    <div className="flex min-w-0 flex-wrap items-center gap-1.5">
      {!isBuilder ? <DraftCompositeSelector disabled={disabled} isRunning={isRunning} onAttach={onAttach} /> : null}
      {isBuilder && compact ? (
        <DraftComposerActionsMenu actions={compactActions} disabled={disabled || isRunning} />
      ) : null}
      {isBuilder && !compact && isMobile ? <DraftAgentConfigTrigger disabled={disabled} isRunning={isRunning} /> : null}
      {isBuilder && !compact && onAttach != null ? (
        <Tooltip content="Attach a file">
          <button
            type="button"
            disabled={disabled || isRunning}
            aria-label="Attach a file"
            className={auiButtonClass({ variant: 'ghost', size: 'icon' })}
            onClick={onAttach}
          >
            <Icon name="paperclip" />
          </button>
        </Tooltip>
      ) : null}
    </div>
  );
}

export function DraftComposerRightSection({ disabled, isRunning }: ComposerRightSectionProps) {
  const shell = useOptionalShellMode();
  const DraftModelSelector = useSlot('DraftModelSelector');
  const isBuilder = shell != null && shellIsCreateAgent(shell.mode);

  return (
    <div className="flex min-w-0 items-center gap-1">
      {!isBuilder ? <DraftModelSelector disabled={disabled} isRunning={isRunning} /> : null}
      <DraftReasoningEffortSelector disabled={disabled} isRunning={isRunning} />
    </div>
  );
}

declare module '../../theme/SlotsProvider.js' {
  interface AtomSlots {
    DraftComposerLeftSection: typeof DraftComposerLeftSection;
    DraftComposerRightSection: typeof DraftComposerRightSection;
  }
}