From 8ff4e80072e604cd4fe560349d6e66f7a05dec68 Mon Sep 17 00:00:00 2001 From: a7m-1st Date: Tue, 7 Oct 2025 15:54:33 +0300 Subject: [PATCH] feat: connect chatStore adapter --- src/components/ChatBox/BottomInput.tsx | 8 +++++++- src/components/ChatBox/NoticeCard.tsx | 8 +++++++- src/components/ChatBox/TaskCard.tsx | 8 +++++++- src/components/ChatBox/index.tsx | 12 +++++++++--- src/components/Folder/index.tsx | 8 +++++++- src/components/HistorySidebar/index.tsx | 8 +++++++- src/components/Layout/index.tsx | 10 +++++++++- src/components/SearchAgentWrokSpace/index.tsx | 8 +++++++- src/components/SearchHistoryDialog.tsx | 8 +++++++- src/components/TaskState/index.tsx | 8 +++++++- src/components/Terminal/index.tsx | 8 +++++++- src/components/TerminalAgentWrokSpace/index.tsx | 8 +++++++- src/components/TopBar/index.tsx | 8 +++++++- src/components/WorkFlow/index.tsx | 8 +++++++- src/components/WorkFlow/node.tsx | 8 +++++++- src/components/WorkSpaceMenu/index.tsx | 8 +++++++- src/pages/History.tsx | 8 +++++++- src/pages/Home.tsx | 8 +++++++- src/pages/Setting/General.tsx | 8 +++++++- 19 files changed, 137 insertions(+), 21 deletions(-) diff --git a/src/components/ChatBox/BottomInput.tsx b/src/components/ChatBox/BottomInput.tsx index 263604d53..8498f463b 100644 --- a/src/components/ChatBox/BottomInput.tsx +++ b/src/components/ChatBox/BottomInput.tsx @@ -26,6 +26,7 @@ import { Tag } from "../ui/tag"; import { useTranslation } from "react-i18next"; import { TooltipSimple } from "../ui/tooltip"; import { toast } from "sonner"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; export const BottomInput = ({ message, @@ -56,7 +57,12 @@ export const BottomInput = ({ setIsTakeControl?: (v: boolean) => void; useCloudModelInDev: boolean; }) => { - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + const {t} = useTranslation(); const [isConfirm, setIsConfirm] = useState(true); const [hasSubTask, setHasSubTask] = useState(false); diff --git a/src/components/ChatBox/NoticeCard.tsx b/src/components/ChatBox/NoticeCard.tsx index a811895c9..6a0b6e5c7 100644 --- a/src/components/ChatBox/NoticeCard.tsx +++ b/src/components/ChatBox/NoticeCard.tsx @@ -8,12 +8,18 @@ import { useChatStore } from "@/store/chatStore"; import { ChevronDown, SquareCode } from "lucide-react"; import { useMemo, useState, useRef, useEffect } from "react"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; export function NoticeCard() { const [isExpanded, setIsExpanded] = useState(false); const contentRef = useRef(null); - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + // when cotList is added, smooth scroll to the bottom useEffect(() => { diff --git a/src/components/ChatBox/TaskCard.tsx b/src/components/ChatBox/TaskCard.tsx index 642abae8a..eb39bf63e 100644 --- a/src/components/ChatBox/TaskCard.tsx +++ b/src/components/ChatBox/TaskCard.tsx @@ -23,6 +23,7 @@ import { } from "lucide-react"; import { useMemo, useState, useRef, useEffect } from "react"; import { TaskState, TaskStateType } from "../TaskState"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; interface TaskCardProps { taskInfo: any[]; @@ -51,7 +52,12 @@ export function TaskCard({ const [isExpanded, setIsExpanded] = useState(true); const contentRef = useRef(null); const [contentHeight, setContentHeight] = useState("auto"); - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + const [selectedState, setSelectedState] = useState("all"); const [filterTasks, setFilterTasks] = useState([]); diff --git a/src/components/ChatBox/index.tsx b/src/components/ChatBox/index.tsx index 45d29ee6a..04ed30827 100644 --- a/src/components/ChatBox/index.tsx +++ b/src/components/ChatBox/index.tsx @@ -1,4 +1,4 @@ -import { useState, useRef, useEffect, useCallback } from "react"; +import { useState, useRef, useEffect, useCallback, useMemo } from "react"; import { fetchPost, proxyFetchPut } from "@/api/http"; import { BottomInput } from "./BottomInput"; import { TaskCard } from "./TaskCard"; @@ -6,17 +6,23 @@ import { MessageCard } from "./MessageCard"; import { TypeCardSkeleton } from "./TypeCardSkeleton"; import { FileText, TriangleAlert } from "lucide-react"; import { generateUniqueId } from "@/lib"; -import { useChatStore } from "@/store/chatStore"; import { proxyFetchGet } from "@/api/http"; import { useNavigate, useSearchParams } from "react-router-dom"; import { NoticeCard } from "./NoticeCard"; import { useAuthStore } from "@/store/authStore"; import { useTranslation } from "react-i18next"; import { TaskStateType } from "../TaskState"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; export default function ChatBox(): JSX.Element { const [message, setMessage] = useState(""); - const chatStore = useChatStore(); + + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + const { t } = useTranslation(); const textareaRef = useRef(null); const scrollContainerRef = useRef(null); diff --git a/src/components/Folder/index.tsx b/src/components/Folder/index.tsx index b670a6dfd..12619e121 100644 --- a/src/components/Folder/index.tsx +++ b/src/components/Folder/index.tsx @@ -18,6 +18,7 @@ import { MarkDown } from "@/components/ChatBox/MarkDown"; import { useAuthStore } from "@/store/authStore"; import { proxyFetchGet } from "@/api/http"; import { useTranslation } from "react-i18next"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; // Type definitions interface FileTreeNode { @@ -154,7 +155,12 @@ function downloadByBrowser(url: string) { } export default function Folder({ data }: { data?: Agent }) { - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + const authStore = useAuthStore(); const { t } = useTranslation(); const [selectedFile, setSelectedFile] = useState(null); diff --git a/src/components/HistorySidebar/index.tsx b/src/components/HistorySidebar/index.tsx index 141b55256..37539014b 100644 --- a/src/components/HistorySidebar/index.tsx +++ b/src/components/HistorySidebar/index.tsx @@ -37,12 +37,18 @@ import { proxyFetchGet, proxyFetchDelete, proxyFetchPost } from "@/api/http"; import { Tag } from "../ui/tag"; import { share } from "@/lib/share"; import { useTranslation } from "react-i18next"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; export default function HistorySidebar() { const { t } = useTranslation(); const { isOpen, close } = useSidebarStore(); const navigate = useNavigate(); - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + const getTokens = chatStore.getTokens; const { history_type, toggleHistoryType } = useGlobalStore(); const [searchValue, setSearchValue] = useState(""); diff --git a/src/components/Layout/index.tsx b/src/components/Layout/index.tsx index 173acdddd..fb3769095 100644 --- a/src/components/Layout/index.tsx +++ b/src/components/Layout/index.tsx @@ -11,10 +11,18 @@ import { useChatStore } from "@/store/chatStore"; import { useInstallationUI } from "@/store/installationStore"; import { useInstallationSetup } from "@/hooks/useInstallationSetup"; import InstallationErrorDialog from "../InstallStep/InstallationErrorDialog/InstallationErrorDialog"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; const Layout = () => { const { initState, isFirstLaunch, setIsFirstLaunch, setInitState } = useAuthStore(); const [noticeOpen, setNoticeOpen] = useState(false); - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + console.log(chatStore); + + return
Loading...
; + } + const { installationState, latestLog, diff --git a/src/components/SearchAgentWrokSpace/index.tsx b/src/components/SearchAgentWrokSpace/index.tsx index 2a5181f08..e9ab51260 100644 --- a/src/components/SearchAgentWrokSpace/index.tsx +++ b/src/components/SearchAgentWrokSpace/index.tsx @@ -17,9 +17,15 @@ import { import { Button } from "../ui/button"; import { fetchPut } from "@/api/http"; import { TaskState } from "../TaskState"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; export default function Home() { - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + const [isSingleMode, setIsSingleMode] = useState(false); const scrollContainerRef = useRef(null); diff --git a/src/components/SearchHistoryDialog.tsx b/src/components/SearchHistoryDialog.tsx index 7808c73f7..c930be549 100644 --- a/src/components/SearchHistoryDialog.tsx +++ b/src/components/SearchHistoryDialog.tsx @@ -30,12 +30,18 @@ import { useChatStore } from "@/store/chatStore"; import { useNavigate } from "react-router-dom"; import { generateUniqueId } from "@/lib"; import { useTranslation } from "react-i18next"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; export function SearchHistoryDialog() { const {t} = useTranslation() const [open, setOpen] = useState(false); const [historyTasks, setHistoryTasks] = useState([]); - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + const navigate = useNavigate(); const handleSetActive = (taskId: string, question: string) => { const task = chatStore.tasks[taskId]; diff --git a/src/components/TaskState/index.tsx b/src/components/TaskState/index.tsx index 4ea57e4fc..e11ce9bb9 100644 --- a/src/components/TaskState/index.tsx +++ b/src/components/TaskState/index.tsx @@ -1,6 +1,7 @@ import { CircleCheckBig, CircleSlash2, LoaderCircle } from "lucide-react"; import { useChatStore } from "@/store/chatStore"; import { useTranslation } from "react-i18next"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; export type TaskStateType = | "all" @@ -35,7 +36,12 @@ export const TaskState = ({ onStateChange, clickable = true, }: TaskStateProps) => { - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + const { t } = useTranslation(); const handleStateClick = (state: TaskStateType) => { if (!clickable || !onStateChange) return; diff --git a/src/components/Terminal/index.tsx b/src/components/Terminal/index.tsx index 5b5a5cbd5..a73133803 100644 --- a/src/components/Terminal/index.tsx +++ b/src/components/Terminal/index.tsx @@ -4,6 +4,7 @@ import { Terminal } from "@xterm/xterm"; import { FitAddon } from "@xterm/addon-fit"; import { WebLinksAddon } from "@xterm/addon-web-links"; import "@xterm/xterm/css/xterm.css"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; // Terminal Component Properties Interface interface TerminalComponentProps { @@ -17,7 +18,12 @@ export default function TerminalComponent({ instanceId = "default", showWelcome = false, }: TerminalComponentProps) { - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + // DOM references const terminalContainerRef = useRef(null); // terminal container reference diff --git a/src/components/TerminalAgentWrokSpace/index.tsx b/src/components/TerminalAgentWrokSpace/index.tsx index cdcb7699f..33c299a95 100644 --- a/src/components/TerminalAgentWrokSpace/index.tsx +++ b/src/components/TerminalAgentWrokSpace/index.tsx @@ -18,9 +18,15 @@ import { Button } from "../ui/button"; import { fetchPut } from "@/api/http"; import Terminal from "@/components/Terminal"; import { useTranslation } from "react-i18next"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; export default function TerminalAgentWrokSpace() { - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + const { t } = useTranslation(); const [isSingleMode, setIsSingleMode] = useState(false); const scrollContainerRef = useRef(null); diff --git a/src/components/TopBar/index.tsx b/src/components/TopBar/index.tsx index c8f8e100d..e5286d4fa 100644 --- a/src/components/TopBar/index.tsx +++ b/src/components/TopBar/index.tsx @@ -20,6 +20,7 @@ import { getAuthStore } from "@/store/authStore"; import { useTranslation } from "react-i18next"; import { proxyFetchGet } from "@/api/http"; import { toast } from "sonner"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; function HeaderWin() { const { t } = useTranslation(); const titlebarRef = useRef(null); @@ -27,7 +28,12 @@ function HeaderWin() { const [platform, setPlatform] = useState(""); const navigate = useNavigate(); const location = useLocation(); - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + const { toggle } = useSidebarStore(); const [isFullscreen, setIsFullscreen] = useState(false); const { token } = getAuthStore(); diff --git a/src/components/WorkFlow/index.tsx b/src/components/WorkFlow/index.tsx index 9f0bdc564..cd05eb870 100644 --- a/src/components/WorkFlow/index.tsx +++ b/src/components/WorkFlow/index.tsx @@ -16,6 +16,7 @@ import { useChatStore } from "@/store/chatStore"; import { useWorkerList } from "@/store/authStore"; import { share } from "@/lib/share"; import { useTranslation } from "react-i18next"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; interface NodeData { agent: Agent; @@ -37,7 +38,12 @@ export default function Workflow({ taskAssigning: Agent[]; }) { const {t} = useTranslation(); - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + const [isEditMode, setIsEditMode] = useState(false); const [lastViewport, setLastViewport] = useState({ x: 0, y: 0, zoom: 1 }); const [nodes, setNodes, onNodesChange] = useNodesState([]); diff --git a/src/components/WorkFlow/node.tsx b/src/components/WorkFlow/node.tsx index f85ea27ba..ba3ef828d 100644 --- a/src/components/WorkFlow/node.tsx +++ b/src/components/WorkFlow/node.tsx @@ -35,6 +35,7 @@ import { PopoverTrigger, } from "../ui/popover"; import { AddWorker } from "@/components/AddWorker"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; interface NodeProps { id: string; @@ -99,7 +100,12 @@ export function Node({ id, data }: NodeProps) { } }, [selectedState, data.agent?.tasks]); - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + const { setCenter, getNode, setViewport, setNodes } = useReactFlow(); const workerList = useWorkerList(); const { setWorkerList } = useAuthStore(); diff --git a/src/components/WorkSpaceMenu/index.tsx b/src/components/WorkSpaceMenu/index.tsx index 85b006b17..7a55d54a3 100644 --- a/src/components/WorkSpaceMenu/index.tsx +++ b/src/components/WorkSpaceMenu/index.tsx @@ -15,9 +15,15 @@ import { motion, AnimatePresence } from "framer-motion"; import { useEffect, useState } from "react"; import { AddWorker } from "@/components/AddWorker"; import { Badge } from "../ui/badge"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; export function WorkSpaceMenu() { - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + const workerList = useWorkerList(); const baseWorker: Agent[] = [ { diff --git a/src/pages/History.tsx b/src/pages/History.tsx index c0e8548e7..72a555ed5 100644 --- a/src/pages/History.tsx +++ b/src/pages/History.tsx @@ -45,11 +45,17 @@ import { SearchHistoryDialog } from "@/components/SearchHistoryDialog"; import { Tag } from "@/components/ui/tag"; import { share } from "@/lib/share"; import { useTranslation } from "react-i18next"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; export default function Home() { const {t} = useTranslation() const navigate = useNavigate(); - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + const { history_type, setHistoryType } = useGlobalStore(); const [historyTasks, setHistoryTasks] = useState([]); const [deleteModalOpen, setDeleteModalOpen] = useState(false); diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index e56a4b806..acec941dc 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -16,10 +16,16 @@ import { ResizablePanel, ResizablePanelGroup, } from "@/components/ui/resizable" +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; export default function Home() { const { toggle } = useSidebarStore(); - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + const [activeWebviewId, setActiveWebviewId] = useState(null); window.ipcRenderer?.on("webview-show", (_event, id: string) => { diff --git a/src/pages/Setting/General.tsx b/src/pages/Setting/General.tsx index 93561c9a2..eebce5e85 100644 --- a/src/pages/Setting/General.tsx +++ b/src/pages/Setting/General.tsx @@ -23,6 +23,7 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select"; +import useChatStoreAdapter from "@/hooks/useChatStoreAdapter"; export default function SettingGeneral() { const { t } = useTranslation(); @@ -36,7 +37,12 @@ export default function SettingGeneral() { const fullNameRef: RefObject = createRef(); const nickNameRef: RefObject = createRef(); const workDescRef: RefObject = createRef(); - const chatStore = useChatStore(); + //Get Chatstore for the active project's task + const { chatStore } = useChatStoreAdapter(); + if (!chatStore) { + return
Loading...
; + } + const [themeList, setThemeList] = useState([ {