From afb74a8ff18be8867f90dd35038ec48a76f883b2 Mon Sep 17 00:00:00 2001 From: abhi1992002 Date: Mon, 2 Feb 2026 09:47:36 +0530 Subject: [PATCH] fix session changing issue --- .../components/EmptySession/EmptySession.tsx | 27 +++------- .../src/app/(platform)/copilot-2/page.tsx | 50 +++++++++++-------- 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot-2/components/EmptySession/EmptySession.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot-2/components/EmptySession/EmptySession.tsx index 33eafc2110..c1ebe51641 100644 --- a/autogpt_platform/frontend/src/app/(platform)/copilot-2/components/EmptySession/EmptySession.tsx +++ b/autogpt_platform/frontend/src/app/(platform)/copilot-2/components/EmptySession/EmptySession.tsx @@ -1,34 +1,23 @@ -import { ChatSidebar } from "../ChatSidebar/ChatSidebar"; - -interface EmptySessionProps { +interface Props { isCreating: boolean; - handleSubmit: (e: React.FormEvent) => void; - input: string; - setInput: (input: string) => void; + onCreateSession: (e: React.FormEvent) => void; } -export const EmptySession = ({ isCreating, handleSubmit, input, setInput }: EmptySessionProps) => { +export function EmptySession({ isCreating, onCreateSession }: Props) { return (

Start a new conversation

-
- setInput(e.target.value)} - disabled={isCreating} - placeholder="Type your message to start..." - className="w-full rounded-md border border-zinc-300 px-4 py-2" - /> +
); -}; \ No newline at end of file +} \ No newline at end of file diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot-2/page.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot-2/page.tsx index 1a561aa0ea..6c275c6b8e 100644 --- a/autogpt_platform/frontend/src/app/(platform)/copilot-2/page.tsx +++ b/autogpt_platform/frontend/src/app/(platform)/copilot-2/page.tsx @@ -4,7 +4,6 @@ import { useChat } from "@ai-sdk/react"; import { DefaultChatTransport } from "ai"; import { useState, useMemo } from "react"; import { parseAsString, useQueryState } from "nuqs"; -import { MessageSquare } from "lucide-react"; import { ChatSidebar } from "./components/ChatSidebar/ChatSidebar"; import { EmptySession } from "./components/EmptySession/EmptySession"; import { ChatMessagesContainer } from "./components/ChatMessagesContainer/ChatMessagesContainer"; @@ -35,40 +34,51 @@ export default function Page() { }, [sessionId]); const { messages, sendMessage, status, error } = useChat({ + id: sessionId ?? undefined, transport: transport ?? undefined, }); - async function handleSubmit(e: React.FormEvent) { + async function createSession(e: React.FormEvent) { e.preventDefault(); - if(!sessionId) { - const newSessionId = await postV2CreateSession({ + if (isCreating) return; + setIsCreating(true); + try { + const response = await postV2CreateSession({ body: JSON.stringify({}), }); - if (newSessionId.status === 200 && newSessionId.data?.id) { - setSessionId(newSessionId.data.id); + if (response.status === 200 && response.data?.id) { + setSessionId(response.data.id); } - console.log("newSessionId", newSessionId); - } - if (input.trim()) { - sendMessage({ text: input }); - setInput(""); + } finally { + setIsCreating(false); } } + function handleMessageSubmit(e: React.FormEvent) { + e.preventDefault(); + if (!input.trim() || !sessionId) return; + + sendMessage({ text: input }); + setInput(""); + } + return (
- { - sessionId ? ( - - ) : ( - - ) - } - - + {sessionId ? ( + + ) : ( + + )}
); }