ui / src / components / agent-chat / full-text-snapshot.tsxmain at d68d7e1
// The "View full text" sheet a long live stream offers once the feed only paints its tail.
import { memo, useState } from "react";
import { CopyIcon } from "lucide-react";
import { toast } from "sonner";
import { sliceText, type StreamText } from "./chunked-text.ts";
import { Button } from "#/components/ui/button.tsx";
import {
Sheet,
SheetContent,
SheetDescription,
SheetHeader,
SheetTitle,
SheetTrigger,
} from "#/components/ui/sheet.tsx";
export function FullTextSnapshot({ text }: { text: StreamText }) {
const [snapshot, setSnapshot] = useState<string>();
return (
<span className="mb-2 flex flex-wrap items-center gap-2 whitespace-normal font-sans text-xs not-italic text-muted-foreground">
Latest ~32K characters
<Sheet
open={!!snapshot}
onOpenChange={(open) => setSnapshot(open ? sliceText(text) : undefined)}
>
<SheetTrigger render={<Button variant="outline" size="xs" />}>View full text</SheetTrigger>
<SheetContent className="data-[side=right]:w-full sm:max-w-3xl">
<SheetHeader>
<SheetTitle>Available response text</SheetTitle>
<SheetDescription>Captured when opened. Reopen for newer text.</SheetDescription>
</SheetHeader>
<Button
className="mx-4 self-start"
variant="outline"
size="sm"
onClick={() => {
void navigator.clipboard.writeText(snapshot || "").then(
() => toast.success("Copied"),
() => toast.error("Failed to copy to clipboard"),
);
}}
>
<CopyIcon data-icon="inline-start" />
Copy text
</Button>
<SnapshotBody text={snapshot || ""} />
</SheetContent>
</Sheet>
</span>
);
}
const SnapshotBody = memo(function SnapshotBody({ text }: { text: string }) {
return (
<pre className="min-h-0 flex-1 overflow-auto whitespace-pre-wrap break-words px-4 pb-4 text-sm">
{text}
</pre>
);
});