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
-
);
-};
\ 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 ? (
+
+ ) : (
+
+ )}
);
}