Skip to content

Commit ac5028c

Browse files
authored
fix: task shown 2 times in the frontend (#311)
2 parents 16821d1 + 2d24b81 commit ac5028c

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/store/chatStore.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ const chatStore = create<ChatStore>()(
604604

605605
// The following logic is for when the task actually starts executing (running)
606606
if (taskAssigning && taskAssigning[assigneeAgentIndex]) {
607-
// const exist = taskAssigning[assigneeAgentIndex].tasks.find(item => item.id === task_id);
607+
const exist = taskAssigning[assigneeAgentIndex].tasks.find(item => item.id === task_id);
608608
let taskTemp = null
609609
if (task) {
610610
taskTemp = JSON.parse(JSON.stringify(task))
@@ -613,12 +613,21 @@ const chatStore = create<ChatStore>()(
613613
taskTemp.toolkits = []
614614
taskTemp.report = ""
615615
}
616-
taskAssigning[assigneeAgentIndex].tasks.push(taskTemp ?? { id: task_id, content, status: "running", });
617-
// if (exist) {
618-
// exist.status = "running";
619-
// } else {
620-
// taskAssigning[assigneeAgentIndex].tasks.push(taskTemp ?? { id: task_id, content, status: "running", });
621-
// }
616+
if (exist) {
617+
// Update existing task instead of adding duplicate
618+
const existingIndex = taskAssigning[assigneeAgentIndex].tasks.findIndex(item => item.id === task_id);
619+
if (existingIndex !== -1) {
620+
taskAssigning[assigneeAgentIndex].tasks[existingIndex] = {
621+
...exist,
622+
status: "running",
623+
failure_count: 0,
624+
toolkits: [],
625+
report: ""
626+
};
627+
}
628+
} else {
629+
taskAssigning[assigneeAgentIndex].tasks.push(taskTemp ?? { id: task_id, content, status: "running", });
630+
}
622631
}
623632
if (taskRunningIndex === -1) {
624633
taskRunning!.push(

0 commit comments

Comments
 (0)