import { Button } from "@/components/ui/button"; import { useThreads } from "@/providers/Thread"; import { Thread } from "@langchain/langgraph-sdk"; import { useEffect } from "react"; import { getContentString } from "../utils"; import { useQueryParam, StringParam, BooleanParam } from "use-query-params"; import { Sheet, SheetContent, SheetHeader, SheetTitle, } from "@/components/ui/sheet"; import { Skeleton } from "@/components/ui/skeleton"; function ThreadList({ threads, onThreadClick, }: { threads: Thread[]; onThreadClick?: (threadId: string) => void; }) { const [threadId, setThreadId] = useQueryParam("threadId", StringParam); return (
{threads.map((t) => { let itemText = t.thread_id; if ( typeof t.values === "object" && t.values && "messages" in t.values && Array.isArray(t.values.messages) && t.values.messages?.length > 0 ) { const firstMessage = t.values.messages[0]; itemText = getContentString(firstMessage.content); } return (
); })}
); } function ThreadHistoryLoading() { return (
{Array.from({ length: 30 }).map((_, i) => ( ))}
); } export default function ThreadHistory() { const [chatHistoryOpen, setChatHistoryOpen] = useQueryParam( "chatHistoryOpen", BooleanParam, ); const { getThreads, threads, setThreads, threadsLoading, setThreadsLoading } = useThreads(); useEffect(() => { if (typeof window === "undefined") return; setThreadsLoading(true); getThreads() .then(setThreads) .catch(console.error) .finally(() => setThreadsLoading(false)); }, []); return ( <>

Thread History

{threadsLoading ? ( ) : ( )}
Thread History setChatHistoryOpen((o) => !o)} /> ); }