"use client"; import { useRef, useState } from "react"; // A view/edit surface for the context that will be sent to the model — the // replayed conversation + retrieved excerpts, serialized as USER:/ASSISTANT: // blocks. The human can prune it for a leaner, cheaper starting point (mid- // conversation) and "apply" it: the edit becomes the seed the conversation // continues from (the display resets to it). This is also the "forward to a new // session" path after an error. // // The textarea is uncontrolled (seeded via defaultValue + a remount key that // changes only when the underlying context changes) so a human's edits are never // clobbered by a re-render. export function ContextPanel({ contextText, overrideActive, busy, onApply, onClear, }: { contextText: string; overrideActive: boolean; busy: boolean; onApply: (text: string) => void; onClear: () => void; }) { const [open, setOpen] = useState(false); const taRef = useRef(null); // Bump to force the uncontrolled textarea to remount and reseed from the // current context (on open, and on an explicit "Reload"). const [seed, setSeed] = useState(0); const onToggle = (e: React.SyntheticEvent) => { const isOpen = e.currentTarget.open; setOpen(isOpen); if (isOpen) setSeed((n) => n + 1); }; const empty = contextText.trim() === ""; return (
Context {overrideActive && ( edited )} ~{Math.round(contextText.length / 4).toLocaleString()} tokens {open && (

This is what the model receives as prior context on your next question. Prune it for a leaner, cheaper starting point, then apply — the conversation continues from the trimmed context.