Skip to content

πŸ™Œ OpenHands: AI-Driven Development

4.6 KB
Raw Blame
import React from "react";
import { Tooltip } from "@heroui/react";
import { useTranslation } from "react-i18next";
import type { ACPModelOption } from "#/constants/acp-providers";
import { NavigationLink } from "#/components/shared/navigation-link";
import { ExecutionStatus } from "#/types/agent-server/core/base/common";
import { SandboxStatus } from "#/api/conversation-service/agent-server-conversation-service.types";
import { RepositorySelection } from "#/api/open-hands.types";
import { cn } from "#/utils/utils";
import { ConversationStatusDot } from "./conversation-status-dot";
import { ConversationCardFooter } from "./conversation-card/conversation-card-footer";
import { I18nKey } from "#/i18n/declaration";
import { useBackendScopedPath } from "#/hooks/use-backend-scoped-path";
import { isMissingSandboxStatus } from "#/utils/conversation-archive-status";

interface CompactConversationRowProps {
  conversationId: string;
  title: string;
  selectedRepository: RepositorySelection | null;
  executionStatus?: ExecutionStatus | null;
  sandboxStatus?: SandboxStatus | null;
  lastUpdatedAt: string;
  createdAt?: string;
  workspaceWorkingDir?: string | null;
  isActive?: boolean;
  onClose?: () => void;
  showRepositoryMetadata?: boolean;
  llmModel?: string | null;
  showLlmProfiles?: boolean;
  agentKind?: "openhands" | "acp" | null;
  acpServer?: string | null;
  acpModels?: readonly ACPModelOption[] | null;
  tags?: Record<string, string> | null;
  showTags?: boolean;
  /**
   * The row's effective archived state. Leave undefined to infer it from
   * `sandboxStatus` (a missing, non-resumable runtime); the panel passes the
   * explicit value so the chip and dot agree with the full card.
   */
  isArchived?: boolean;
}

/**
 * Minimal one-row presentation of a conversation used by the collapsed
 * sidebar. The row itself is just the agent status dot; hovering it shows a
 * floating preview with the conversation's title, repo and timestamp.
 */
export function CompactConversationRow({
  conversationId,
  title,
  selectedRepository,
  executionStatus,
  sandboxStatus,
  lastUpdatedAt,
  createdAt,
  workspaceWorkingDir,
  isActive = false,
  onClose,
  showRepositoryMetadata = true,
  llmModel = null,
  showLlmProfiles = false,
  agentKind = null,
  acpServer = null,
  acpModels = null,
  tags = null,
  showTags = false,
  isArchived,
}: CompactConversationRowProps) {
  const { t } = useTranslation("openhands");
  const backendScopedPath = useBackendScopedPath();
  const disableAnimation = import.meta.env.MODE === "test";
  const effectiveArchived = isArchived ?? isMissingSandboxStatus(sandboxStatus);

  const preview = (
    <div className="w-65 p-3">
      <div className="flex items-center gap-2 mb-1">
        <ConversationStatusDot
          executionStatus={executionStatus}
          sandboxStatus={sandboxStatus}
          isArchived={effectiveArchived}
          showTooltip={false}
        />
        <span
          className="text-sm font-medium text-contrast truncate"
          title={title}
        >
          {title || t(I18nKey.CONVERSATION$UNTITLED)}
        </span>
      </div>
      <ConversationCardFooter
        selectedRepository={selectedRepository}
        lastUpdatedAt={lastUpdatedAt}
        createdAt={createdAt}
        executionStatus={executionStatus}
        workspaceWorkingDir={workspaceWorkingDir}
        showRepositoryMetadata={showRepositoryMetadata}
        llmModel={llmModel}
        showAgentChip={showLlmProfiles}
        agentKind={agentKind}
        acpServer={acpServer}
        acpModels={acpModels}
        tags={tags}
        showTags={showTags}
        isArchived={effectiveArchived}
      />
    </div>
  );

  return (
    <Tooltip
      content={preview}
      placement="right"
      closeDelay={100}
      className="bg-surface text-contrast border border-border-subtle shadow-xl p-0"
      disableAnimation={disableAnimation}
    >
      <NavigationLink
        to={backendScopedPath(`/conversations/${conversationId}`)}
        onClick={onClose}
        data-testid="compact-conversation-row"
        data-conversation-id={conversationId}
        aria-label={title || conversationId}
        className={({ isActive: navActive }) =>
          cn(
            "flex items-center justify-center w-10 h-9 mx-auto rounded-md",
            "transition-colors cursor-pointer",
            navActive || isActive ? "bg-tertiary" : "hover:bg-surface-raised",
          )
        }
      >
        <ConversationStatusDot
          executionStatus={executionStatus}
          sandboxStatus={sandboxStatus}
          isArchived={effectiveArchived}
          showTooltip={false}
        />
      </NavigationLink>
    </Tooltip>
  );
}