import { IconLock, IconPin, IconRotate2, IconX } from "@tabler/icons-react"; import type { ReactNode } from "react"; import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover.js"; import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip.js"; import { cn } from "../utils.js"; import { contextStatusLabel, formatContextTokens } from "./format.js"; import type { ContextSegmentViewData } from "./types.js"; export function SegmentProvenancePopoverView({ segment, children, }: { segment: ContextSegmentViewData; children: ReactNode; }) { return ( {children}
Segment
{segment.label}
{formatContextTokens(segment.tokenCount)} tokens{segment.tokenMethod === "estimate" ? " estimated" : ""}
{contextStatusLabel(segment)} current status
{segment.msgIndex ?? "-"} message index
{segment.partIndex ?? "-"} part index
{segment.protected ? (
This segment is part of the active turn and cannot be evicted yet.
) : null}
); } export function ContextSegmentRowView({ segment, advisory, onPin, onEvict, onRestore, }: { segment: ContextSegmentViewData; advisory: boolean; onPin: () => void; onEvict: () => void; onRestore: () => void; }) { const disabled = segment.protected || segment.status === "evicted"; return (
{ if (event.key === "p") onPin(); if (event.key === "e" && !disabled) onEvict(); if (event.key === "u" && segment.status !== "active") onRestore(); }} className={cn( "group flex min-h-11 items-center gap-2 rounded-sm px-2 py-1.5 outline-none transition-colors hover:bg-accent/35 focus-visible:bg-accent/35 focus-visible:ring-1 focus-visible:ring-ring", segment.status === "evicted" && "opacity-60", )} >
{segment.protected ? ( Protected during active turn ) : segment.status === "evicted" || segment.status === "summarized" || segment.status === "pinned" ? ( {segment.status === "pinned" ? "Unpin" : "Restore"} ) : ( <> Pin {advisory ? "Record eviction intent" : "Evict"} )}
); }