diff --git a/src/components/ChatBox/BottomInput.tsx b/src/components/ChatBox/BottomInput.tsx
index 8498f463b..df47096fe 100644
--- a/src/components/ChatBox/BottomInput.tsx
+++ b/src/components/ChatBox/BottomInput.tsx
@@ -58,7 +58,7 @@ export const BottomInput = ({
useCloudModelInDev: boolean;
}) => {
//Get Chatstore for the active project's task
- const { chatStore } = useChatStoreAdapter();
+ const { chatStore, projectStore } = useChatStoreAdapter();
if (!chatStore) {
return
Loading...
;
}
@@ -212,7 +212,10 @@ export const BottomInput = ({
chatStore.tasks[chatStore.activeTaskId as string].messages[
messageIndex - 2
].content;
- let id = chatStore.create();
+ //Create new chat in same project
+ if(!projectStore.activeProjectId) return
+ let id = projectStore.createChatStore(projectStore.activeProjectId);
+
chatStore.setHasMessages(id, true);
chatStore.removeTask(tempTaskId as string);
proxyFetchDelete(`/api/chat/history/${tempTaskId}`);
diff --git a/src/components/HistorySidebar/index.tsx b/src/components/HistorySidebar/index.tsx
index 37539014b..31c628c9b 100644
--- a/src/components/HistorySidebar/index.tsx
+++ b/src/components/HistorySidebar/index.tsx
@@ -44,7 +44,7 @@ export default function HistorySidebar() {
const { isOpen, close } = useSidebarStore();
const navigate = useNavigate();
//Get Chatstore for the active project's task
- const { chatStore } = useChatStoreAdapter();
+ const { chatStore, projectStore } = useChatStoreAdapter();
if (!chatStore) {
return Loading...
;
}
@@ -87,7 +87,8 @@ export default function HistorySidebar() {
chatStore.tasks[chatStore.activeTaskId as string].messages.length === 0
) {
}
- chatStore.create();
+ //Create a new project
+ projectStore.createProject("new project");
navigate("/");
};
diff --git a/src/components/SearchAgentWrokSpace/index.tsx b/src/components/SearchAgentWrokSpace/index.tsx
index e9ab51260..fc58f7537 100644
--- a/src/components/SearchAgentWrokSpace/index.tsx
+++ b/src/components/SearchAgentWrokSpace/index.tsx
@@ -21,7 +21,7 @@ import useChatStoreAdapter from "@/hooks/useChatStoreAdapter";
export default function Home() {
//Get Chatstore for the active project's task
- const { chatStore } = useChatStoreAdapter();
+ const { chatStore, projectStore } = useChatStoreAdapter();
if (!chatStore) {
return Loading...
;
}
@@ -115,8 +115,9 @@ export default function Home() {
// listen to webview container size
useEffect(() => {
- if (!chatStore.activeTaskId) {
- chatStore.create();
+ if (!projectStore.activeProjectId) {
+ projectStore.createProject("new project");
+ console.warn("No active projectId found in WorkSpace, creating a new project");
}
const webviewContainer = document.getElementById("webview-container");
diff --git a/src/components/TopBar/index.tsx b/src/components/TopBar/index.tsx
index e5286d4fa..1cbca8388 100644
--- a/src/components/TopBar/index.tsx
+++ b/src/components/TopBar/index.tsx
@@ -29,7 +29,7 @@ function HeaderWin() {
const navigate = useNavigate();
const location = useLocation();
//Get Chatstore for the active project's task
- const { chatStore } = useChatStoreAdapter();
+ const { chatStore, projectStore } = useChatStoreAdapter();
if (!chatStore) {
return Loading...
;
}
@@ -99,7 +99,7 @@ function HeaderWin() {
navigate("/");
return;
}
- chatStore.create();
+ projectStore.createProject("new project");
navigate("/");
};
diff --git a/src/pages/History.tsx b/src/pages/History.tsx
index 72a555ed5..f080eb787 100644
--- a/src/pages/History.tsx
+++ b/src/pages/History.tsx
@@ -51,7 +51,7 @@ export default function Home() {
const {t} = useTranslation()
const navigate = useNavigate();
//Get Chatstore for the active project's task
- const { chatStore } = useChatStoreAdapter();
+ const { chatStore, projectStore } = useChatStoreAdapter();
if (!chatStore) {
return Loading...
;
}
@@ -224,7 +224,7 @@ export default function Home() {
navigate(`/`);
return;
}
- chatStore.create();
+ projectStore.createProject("new project");
navigate("/");
};
diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx
index acec941dc..05a88d0da 100644
--- a/src/pages/Home.tsx
+++ b/src/pages/Home.tsx
@@ -21,7 +21,7 @@ import useChatStoreAdapter from "@/hooks/useChatStoreAdapter";
export default function Home() {
const { toggle } = useSidebarStore();
//Get Chatstore for the active project's task
- const { chatStore } = useChatStoreAdapter();
+ const { chatStore, projectStore } = useChatStoreAdapter();
if (!chatStore) {
return Loading...
;
}
@@ -144,7 +144,7 @@ export default function Home() {
useEffect(() => {
if (!chatStore.activeTaskId) {
- chatStore.create();
+ projectStore.createProject("new project");
}
const webviewContainer = document.getElementById("webview-container");
diff --git a/src/store/projectStore.ts b/src/store/projectStore.ts
index 2696128fd..0c8eafa69 100644
--- a/src/store/projectStore.ts
+++ b/src/store/projectStore.ts
@@ -1,6 +1,7 @@
import { create } from 'zustand';
import { generateUniqueId } from "@/lib";
import { useChatStore, VanillaChatStore } from './chatStore';
+import { devtools } from 'zustand/middleware';
interface Project {
id: string;
@@ -54,6 +55,9 @@ const projectStore = create()((set, get) => ({
const initialChatId = generateUniqueId();
const initialChatStore = useChatStore();
+ // Initialize the chat store with a task using the create() function
+ initialChatStore.getState().create();
+
// Create new project with default chat store
const newProject: Project = {
id: projectId,
@@ -70,6 +74,8 @@ const projectStore = create()((set, get) => ({
}
};
+ console.log("[store] Creating a new project");
+
set((state) => ({
projects: {
...state.projects,
@@ -114,6 +120,9 @@ const projectStore = create()((set, get) => ({
const chatId = generateUniqueId();
const newChatStore = useChatStore();
+ // Initialize the chat store with a task using the create() function
+ newChatStore.getState().create();
+
set((state) => ({
projects: {
...state.projects,