diff --git a/src/components/thread/index.tsx b/src/components/thread/index.tsx index e6d84a3..b246fc1 100644 --- a/src/components/thread/index.tsx +++ b/src/components/thread/index.tsx @@ -18,23 +18,6 @@ import { SquarePen } from "lucide-react"; import { StringParam, useQueryParam } from "use-query-params"; import { StickToBottom, useStickToBottomContext } from "use-stick-to-bottom"; -function NewThread() { - const [threadId, setThreadId] = useQueryParam("threadId", StringParam); - if (!threadId) return null; - - return ( - setThreadId(null)} - > - - - ); -} - function StickyToBottomContent(props: { content: ReactNode; footer?: ReactNode; @@ -58,17 +41,16 @@ function StickyToBottomContent(props: { } export function Thread() { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const [_, setThreadId] = useQueryParam("threadId", StringParam); + const [threadId, setThreadId] = useQueryParam("threadId", StringParam); const [input, setInput] = useState(""); const [firstTokenReceived, setFirstTokenReceived] = useState(false); + const stream = useStreamContext(); const messages = stream.messages; const isLoading = stream.isLoading; - const prevMessageLength = useRef(0); - // TODO: this should be part of the useStream hook + const prevMessageLength = useRef(0); useEffect(() => { if ( messages.length !== prevMessageLength.current && @@ -123,20 +105,15 @@ export function Thread() { }); }; - const chatStarted = isLoading || messages.length > 0; - const renderMessages = messages.filter( - (m) => !m.id?.startsWith(DO_NOT_RENDER_ID_PREFIX), - ); - return (
- {chatStarted && ( + {threadId && (
- + setThreadId(null)} + > + +
@@ -156,36 +141,30 @@ export function Thread() { - {renderMessages.map((message, index) => - message.type === "human" ? ( - - ) : ( - - ), - )} + {messages + .filter((m) => !m.id?.startsWith(DO_NOT_RENDER_ID_PREFIX)) + .map((message, index) => + message.type === "human" ? ( + + ) : ( + + ), + )} {isLoading && !firstTokenReceived && ( )} @@ -193,7 +172,7 @@ export function Thread() { } footer={
- {!chatStarted && ( + {!threadId && (

LangGraph Chat