import { Info, Loader2, Minimize } from "lucide-react"; import { useTranslation } from "react-i18next"; import { I18nKey } from "#/i18n/declaration"; import { BrandButton } from "#/components/features/settings/brand-button"; import { StyledTooltip } from "#/components/shared/buttons/styled-tooltip"; import { useCompactContextAction } from "#/hooks/use-compact-context-action"; import { CONTEXT_FILL_WARNING_PERCENT } from "./context-meter"; interface CompactContextButtonProps { /** Current context fill percentage; past the warning threshold the button becomes a prominent CTA. */ fillPercent: number; /** Optional live per-turn token count used as a fallback snapshot before compaction. */ perTurnToken?: number; } /** * "Compact context" action: POSTs `/api/conversations/{id}/condense` with a * spinner while in flight and toasts for start, completion (with tokens * freed), and failure. Disabled while the agent is actively running (the * server would race the active step) and promoted to a primary * call-to-action once the context fill passes * {@link CONTEXT_FILL_WARNING_PERCENT}. */ export function CompactContextButton({ fillPercent, perTurnToken = 0, }: CompactContextButtonProps) { const { t } = useTranslation("openhands"); const { handleCompact, isCompacting, isDisabled, description } = useCompactContextAction(perTurnToken); const isHighFill = fillPercent > CONTEXT_FILL_WARNING_PERCENT; return (
{isHighFill && ( {t(I18nKey.CONVERSATION$CONTEXT_FILLING_UP)} )}
) : ( ) } className="w-fit" > {t(I18nKey.CONVERSATION$COMPACT_CONTEXT)}
); }