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 { formatContextTokens } from "./format.js"; import { fallbackContextTranslate, type ContextSegmentViewData, type ContextTranslate, } from "./types.js"; function statusLabel( segment: ContextSegmentViewData, translate: ContextTranslate, ): string { if (segment.protected) return translate("agentChat.contextXray.status.protected", { defaultValue: "Protected", }); if (segment.status === "pinned") return translate("agentChat.contextXray.status.pinned", { defaultValue: "Pinned", }); if (segment.status === "evicted") return translate("agentChat.contextXray.status.evicted", { defaultValue: "Evicted", }); if (segment.status === "summarized") return translate("agentChat.contextXray.status.summarized", { defaultValue: "Summarized", }); return translate("agentChat.contextXray.status.active", { defaultValue: "Active", }); } export function SegmentProvenancePopoverView({ segment, children, translate = fallbackContextTranslate, }: { segment: ContextSegmentViewData; children: ReactNode; translate?: ContextTranslate; }) { return ( {children}
{translate("agentChat.contextXray.segment", { defaultValue: "Segment", })}
{segment.label}
{formatContextTokens(segment.tokenCount)} {translate("agentChat.contextXray.tokens", { defaultValue: "tokens", })} {segment.tokenMethod === "estimate" ? translate("agentChat.contextXray.estimatedPrefix", { defaultValue: " estimated", }) : ""}
{statusLabel(segment, translate)} {translate("agentChat.contextXray.currentStatus", { defaultValue: "current status", })}
{segment.msgIndex ?? "-"} {translate("agentChat.contextXray.messageIndex", { defaultValue: "message index", })}
{segment.partIndex ?? "-"} {translate("agentChat.contextXray.partIndex", { defaultValue: "part index", })}
{segment.protected ? (
{translate("agentChat.contextXray.protectedDescription", { defaultValue: "This segment is part of the active turn and cannot be evicted yet.", })}
) : null}
); } export function ContextSegmentRowView({ segment, advisory, onPin, onEvict, onRestore, translate = fallbackContextTranslate, }: { segment: ContextSegmentViewData; advisory: boolean; onPin: () => void; onEvict: () => void; onRestore: () => void; translate?: ContextTranslate; }) { 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 ? ( {translate("agentChat.contextXray.protectedDuringTurn", { defaultValue: "Protected during active turn", })} ) : segment.status === "evicted" || segment.status === "summarized" || segment.status === "pinned" ? ( {segment.status === "pinned" ? translate("agentChat.contextXray.unpin", { defaultValue: "Unpin", }) : translate("agentChat.contextXray.restore", { defaultValue: "Restore", })} ) : ( <> {translate("agentChat.contextXray.pin", { defaultValue: "Pin", })} {advisory ? translate("agentChat.contextXray.recordEvictionIntent", { defaultValue: "Record eviction intent", }) : translate("agentChat.contextXray.evict", { defaultValue: "Evict", })} )}
); }