From 416d7f8acfcc8f03399646af5f004e282d47e6cb Mon Sep 17 00:00:00 2001 From: Wendong-Fan Date: Thu, 20 Nov 2025 14:01:34 +0800 Subject: [PATCH] bug fix wendong --- src/components/TopBar/index.tsx | 7 +++---- src/hooks/useChatStoreAdapter.tsx | 2 +- src/store/chatStore.ts | 8 ++++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/components/TopBar/index.tsx b/src/components/TopBar/index.tsx index 501f0948d..71ada4413 100644 --- a/src/components/TopBar/index.tsx +++ b/src/components/TopBar/index.tsx @@ -148,14 +148,13 @@ function HeaderWin() { //TODO: Mark ChatStore details as completed const handleEndProject = async () => { const taskId = chatStore.activeTaskId; - const currentProjectId = projectStore.activeProjectId; - + const projectId = projectStore.activeProjectId; + if (!taskId) { toast.error(t("layout.no-active-project-to-end")); return; } - const projectId = projectStore.activeProjectId; const historyId = projectId ? projectStore.getHistoryId(projectId) : null; try { @@ -170,7 +169,7 @@ function HeaderWin() { // Stop Workforce try { - await fetchDelete(`/chat/${currentProjectId}`); + await fetchDelete(`/chat/${projectId}`); } catch (error) { console.log("Task may not exist on backend:", error); } diff --git a/src/hooks/useChatStoreAdapter.tsx b/src/hooks/useChatStoreAdapter.tsx index fb219dfa1..6a3a1a71a 100644 --- a/src/hooks/useChatStoreAdapter.tsx +++ b/src/hooks/useChatStoreAdapter.tsx @@ -24,7 +24,7 @@ const useChatStoreAdapter = ():{ } // Subscribe to store changes - const unsubscribe = activeChatStore.subscribe((state) => { + const unsubscribe = activeChatStore.subscribe((state: ChatStore) => { setChatState(state); }); // Set initial state diff --git a/src/store/chatStore.ts b/src/store/chatStore.ts index b593886a0..157ba10a6 100644 --- a/src/store/chatStore.ts +++ b/src/store/chatStore.ts @@ -105,6 +105,7 @@ export interface ChatStore { export type VanillaChatStore = { getState: () => ChatStore; + subscribe: (listener: (state: ChatStore) => void) => () => void; }; @@ -1085,7 +1086,7 @@ const chatStore = (initial?: Partial) => createStore()( return toolkit.toolkitName === agentMessages.data.toolkit_name && toolkit.toolkitMethods === agentMessages.data.method_name && toolkit.toolkitStatus === 'running' }) - if (task.toolkits && index !== -1) { + if (task.toolkits && index !== -1 && index !== undefined) { task.toolkits[index].message += '\n' + message.data.message as string task.toolkits[index].toolkitStatus = "completed" } @@ -1223,10 +1224,9 @@ const chatStore = (initial?: Partial) => createStore()( // Complete the current task with error status setStatus(currentTaskId, 'finished'); setIsPending(currentTaskId, false); - setHasWaitComfirm(newTaskId, true); - // Add error message to the new clean task - addMessages(newTaskId, { + // Add error message to the current task + addMessages(currentTaskId, { id: generateUniqueId(), role: "agent", content: `❌ **Error**: ${errorMessage}`,