From 28cee3200fd97f3563bcaf533ce283c8deb8908c Mon Sep 17 00:00:00 2001 From: starmorph Date: Mon, 19 May 2025 13:59:20 -0700 Subject: [PATCH] fix thread index --- src/components/thread/index.tsx | 346 +++++++++++++------------------- 1 file changed, 144 insertions(+), 202 deletions(-) diff --git a/src/components/thread/index.tsx b/src/components/thread/index.tsx index 14c5975..192b0d1 100644 --- a/src/components/thread/index.tsx +++ b/src/components/thread/index.tsx @@ -22,7 +22,6 @@ import { SquarePen, Plus, CircleX, - XIcon, } from "lucide-react"; import { useQueryState, parseAsBoolean } from "nuqs"; import { StickToBottom, useStickToBottomContext } from "use-stick-to-bottom"; @@ -40,13 +39,6 @@ import { } from "../ui/tooltip"; import { fileToImageBlock, fileToPDFBlock } from "@/lib/multimodal-utils"; import type { Base64ContentBlock } from "@langchain/core/messages"; -import { - useArtifactOpen, - ArtifactContent, - ArtifactTitle, - useArtifactContext, -} from "./artifact"; - function StickyToBottomContent(props: { content: ReactNode; @@ -114,10 +106,7 @@ function OpenGitHubRepo() { } export function Thread() { - const [artifactContext, setArtifactContext] = useArtifactContext(); - const [artifactOpen, closeArtifact] = useArtifactOpen(); - - const [threadId, _setThreadId] = useQueryState("threadId"); + const [threadId, setThreadId] = useQueryState("threadId"); const [chatHistoryOpen, setChatHistoryOpen] = useQueryState( "chatHistoryOpen", parseAsBoolean.withDefault(false), @@ -138,17 +127,8 @@ export function Thread() { const lastError = useRef(undefined); - const dropRef = useRef(null); - const setThreadId = (id: string | null) => { - _setThreadId(id); - - // close artifact and reset artifact context - closeArtifact(); - setArtifactContext({}); - }; - useEffect(() => { if (!stream.error) { lastError.current = undefined; @@ -218,17 +198,12 @@ export function Thread() { console.log("Message content:", newHumanMessage.content); const toolMessages = ensureToolCallsHaveResponses(stream.messages); - - const context = - Object.keys(artifactContext).length > 0 ? artifactContext : undefined; - stream.submit( - { messages: [...toolMessages, newHumanMessage], context }, + { messages: [...toolMessages, newHumanMessage] }, { streamMode: ["values"], optimisticValues: (prev) => ({ ...prev, - context, messages: [ ...(prev.messages ?? []), ...toolMessages, @@ -387,36 +362,52 @@ export function Thread() { - -
- - {!chatStarted && ( -
-
+ {!chatStarted && ( +
+
+ {(!chatHistoryOpen || !isLargeScreen) && ( + + )} +
+
+ +
+
+ )} + {chatStarted && ( +
+
+
{(!chatHistoryOpen || !isLargeScreen) && (
-
+ setThreadId(null)} + animate={{ + marginLeft: !chatHistoryOpen ? 48 : 0, + }} + transition={{ + type: "spring", + stiffness: 300, + damping: 30, + }} + > + + + Agent Chat + + +
+ +
+
+ setThreadId(null)} + > + +
- )} - {chatStarted && ( -
-
-
- {(!chatHistoryOpen || !isLargeScreen) && ( - + +
+
+ )} + + + + {messages + .filter((m) => !m.id?.startsWith(DO_NOT_RENDER_ID_PREFIX)) + .map((message, index) => + message.type === "human" ? ( + + ) : ( + + ), )} -
- setThreadId(null)} - animate={{ - marginLeft: !chatHistoryOpen ? 48 : 0, - }} - transition={{ - type: "spring", - stiffness: 300, - damping: 30, - }} - > - - - Agent Chat - - -
- -
-
- -
- setThreadId(null)} - > - - -
- - -
-
- )} - - - - {messages - .filter((m) => !m.id?.startsWith(DO_NOT_RENDER_ID_PREFIX)) - .map((message, index) => - message.type === "human" ? ( - - ) : ( - - ), - )} - {/* Special rendering case where there are no AI/tool messages, but there is an interrupt. + {/* Special rendering case where there are no AI/tool messages, but there is an interrupt. We need to render it outside of the messages list, since there are no messages to render */} - {hasNoAIOrToolMessages && !!stream.interrupt && ( - - )} - {isLoading && !firstTokenReceived && ( - - )} - - } - footer={ - + {hasNoAIOrToolMessages && !!stream.interrupt && ( + + )} + {isLoading && !firstTokenReceived && ( + + )} + + } + footer={ +
+ {!chatStarted && ( +
+ +

+ Agent Chat +

+
+ )} + + +
@@ -654,27 +631,8 @@ export function Thread() { > Hide Tool Calls -
- {stream.isLoading ? ( - - ) : ( - - )}
- {stream.isLoading ? (
- } - /> - - -
-
-
- - -
- -
-
-
+
+ } + /> + +
); -} +} \ No newline at end of file