"use client"; import { useCallback, useEffect, useId, useState } from "react"; interface SessionContext { summary: string; last_updated: string | null; } interface ContextPanelProps { isOpen: boolean; onClose: () => void; sessionContext: SessionContext | null; initialContext?: string; onInitialContextChange?: (value: string) => void; isLocked?: boolean; } function formatRelativeTime(isoString: string): string { const date = new Date(isoString); const now = new Date(); const diffMs = now.getTime() - date.getTime(); const diffSec = Math.floor(diffMs / 1000); const diffMin = Math.floor(diffSec / 60); const diffHour = Math.floor(diffMin / 60); if (diffSec < 60) { return "just now"; } if (diffMin < 60) { return `${diffMin} minute${diffMin === 1 ? "" : "s"} ago`; } if (diffHour < 24) { return `${diffHour} hour${diffHour === 1 ? "" : "s"} ago`; } return date.toLocaleDateString(); } function BrainIcon() { return ( ); } export default function ContextPanel({ isOpen, onClose, sessionContext, initialContext = "", onInitialContextChange, isLocked = false, }: ContextPanelProps) { const titleId = useId(); const [localValue, setLocalValue] = useState(initialContext); useEffect(() => { if (isOpen) { setLocalValue(initialContext); } }, [isOpen, initialContext]); const handleKeyDown = useCallback( (e: React.KeyboardEvent) => { if (e.key === "Escape") { onClose(); } }, [onClose], ); const handleSave = useCallback(() => { onInitialContextChange?.(localValue); onClose(); }, [localValue, onInitialContextChange, onClose]); if (!isOpen) { return null; } const hasSessionContext = sessionContext?.summary?.trim(); // Show edit mode when: not locked AND no session context yet const isEditMode = !isLocked && !hasSessionContext; return ( <>
{/* biome-ignore lint/a11y/noStaticElementInteractions: modal content wrapper */}
e.stopPropagation()} onKeyDown={(e) => e.stopPropagation()} >

{isEditMode ? "Initial Context" : "Session Context"}

{isEditMode ? "Set background context to guide the conversation. This will be locked after you send your first message." : "This is what the assistant has learned from your conversation so far. It uses this context to provide more relevant answers."}

{isEditMode ? (