diff --git a/src/pages/Setting/components/MCPList.tsx b/src/pages/Setting/components/MCPList.tsx
index 498109e62..a2fa73ca9 100644
--- a/src/pages/Setting/components/MCPList.tsx
+++ b/src/pages/Setting/components/MCPList.tsx
@@ -12,9 +12,9 @@ interface MCPListProps {
export default function MCPList({ items, onSetting, onDelete, onSwitch, switchLoading }: MCPListProps) {
return (
- {items.map(item => (
+ {items.map((item) => (
arg.trim()).filter(arg => arg !== '');
+ }
+ }
+
+ // If not JSON, treat as comma-separated string
+ if (args.trim()) {
+ return args.split(',').map(arg => arg.trim()).filter(arg => arg !== '');
+ }
+
return [];
}
export function arrayToArgsJson(arr: string[]): string {
- return JSON.stringify(arr.filter(v => v.trim() !== ''));
+ const filtered = arr.filter(v => v.trim() !== '');
+ if (filtered.length === 0) return '';
+
+ // Return as JSON stringified array
+ return JSON.stringify(filtered);
}
\ No newline at end of file
diff --git a/src/store/chatStore.ts b/src/store/chatStore.ts
index 7069fa406..00dfcbbb5 100644
--- a/src/store/chatStore.ts
+++ b/src/store/chatStore.ts
@@ -450,7 +450,7 @@ const chatStore = create()(
let taskRunning = [...tasks[taskId].taskRunning]
let taskAssigning = [...tasks[taskId].taskAssigning]
const targetTaskIndex = taskRunning.findIndex((task) => task.id === task_id)
- const targetTaskAssigningIndex = taskAssigning.findIndex((agent) => agent.tasks.find((task: TaskInfo) => task.id === task_id && (task.failure_count == 0 || !task.failure_count)))
+ const targetTaskAssigningIndex = taskAssigning.findIndex((agent) => agent.tasks.find((task: TaskInfo) => task.id === task_id && !task.reAssignTo))
if (targetTaskAssigningIndex !== -1) {
const taskIndex = taskAssigning[targetTaskAssigningIndex].tasks.findIndex((task: TaskInfo) => task.id === task_id)
taskAssigning[targetTaskAssigningIndex].tasks[taskIndex].status = state === "DONE" ? "completed" : "failed";
@@ -484,20 +484,19 @@ const chatStore = create()(
content: targetResult,
step: "failed",
})
- setStatus(taskId, 'pause')
}
}
}
if (targetTaskIndex !== -1) {
-
+ console.log("targetTaskIndex", targetTaskIndex,state)
taskRunning[targetTaskIndex].status = state === "DONE" ? "completed" : "failed";
}
setTaskRunning(taskId, taskRunning)
setTaskAssigning(taskId, taskAssigning)
return;
}
-
+
// Activate agent
if (agentMessages.step === "activate_agent" || agentMessages.step === "deactivate_agent") {
let taskAssigning = [...tasks[taskId].taskAssigning]
@@ -540,7 +539,6 @@ const chatStore = create()(
setTaskAssigning(taskId, [...taskAssigning]);
}
if (agentMessages.step === "deactivate_agent") {
- taskAssigning[agentIndex].status = "completed";
if (message) {
const index = taskAssigning[agentIndex].log.findLastIndex((log) => log.data.method_name === agentMessages.data.method_name && log.data.toolkit_name === agentMessages.data.toolkit_name)
if (index != -1) {
@@ -549,12 +547,11 @@ const chatStore = create()(
}
}
- // const taskIndex = taskRunning!.findLastIndex((task) => task.agent?.agent_id === agent_id && task.status !== 'completed' && task.status !== 'failed');
- const taskIndex = taskRunning.findIndex((task) => task.id === process_task_id);
- if (taskIndex !== -1) {
- taskRunning![taskIndex].agent!.status = "completed";
- taskRunning![taskIndex]!.status = "completed";
- }
+ // const taskIndex = taskRunning.findIndex((task) => task.id === process_task_id);
+ // if (taskIndex !== -1) {
+ // taskRunning![taskIndex].agent!.status = "completed";
+ // taskRunning![taskIndex]!.status = "completed";
+ // }
if (!type && historyId) {
@@ -580,11 +577,12 @@ const chatStore = create()(
if (agentMessages.step === "assign_task") {
if (!agentMessages.data?.assignee_id || !agentMessages.data?.task_id) return;
- const { assignee_id, task_id, content = "", state: taskState } = agentMessages.data as any;
+ const { assignee_id, task_id, content = "", state: taskState, failure_count } = agentMessages.data as any;
let taskAssigning = [...tasks[taskId].taskAssigning]
let taskRunning = [...tasks[taskId].taskRunning]
let taskInfo = [...tasks[taskId].taskInfo]
+ // Find the index of the agent corresponding to assignee_id
const assigneeAgentIndex = taskAssigning!.findIndex((agent: Agent) => agent.agent_id === assignee_id);
// Find task corresponding to task_id
const task = taskInfo!.find((task: TaskInfo) => task.id === task_id);
@@ -594,6 +592,26 @@ const chatStore = create()(
if (assigneeAgentIndex === -1) return;
const taskAgent = taskAssigning![assigneeAgentIndex];
+ // Find the agent to reassign the task to
+ const target = taskAssigning
+ .map((agent, agentIndex) => {
+ if (agent.agent_id === assignee_id) return null
+
+ const taskIndex = agent.tasks.findIndex(
+ (task: TaskInfo) => task.id === task_id && !task.reAssignTo
+ )
+
+ return taskIndex !== -1 ? { agentIndex, taskIndex } : null
+ })
+ .find(Boolean)
+
+ if (target) {
+ const { agentIndex, taskIndex } = target
+ const agentName = taskAssigning.find((agent: Agent) => agent.agent_id === assignee_id)?.name
+ taskAssigning[agentIndex].tasks[taskIndex].reAssignTo = agentName
+ }
+
+
// If the state is "waiting", only mark it in the agent's task list and do not add it to taskRunning
if (taskState === "waiting") {
if (!taskAssigning[assigneeAgentIndex].tasks.find(item => item.id === task_id)) {
@@ -607,10 +625,13 @@ const chatStore = create()(
if (taskAssigning && taskAssigning[assigneeAgentIndex]) {
// Check if task already exists in the agent's task list
const existingTaskIndex = taskAssigning[assigneeAgentIndex].tasks.findIndex(item => item.id === task_id);
-
+
if (existingTaskIndex !== -1) {
// Task already exists, update its status
taskAssigning[assigneeAgentIndex].tasks[existingTaskIndex].status = "running";
+ if (failure_count !== 0) {
+ taskAssigning[assigneeAgentIndex].tasks[existingTaskIndex].failure_count = failure_count;
+ }
} else {
// Task doesn't exist, add it
let taskTemp = null
@@ -624,7 +645,7 @@ const chatStore = create()(
taskAssigning[assigneeAgentIndex].tasks.push(taskTemp ?? { id: task_id, content, status: "running", });
}
}
-
+
// Only update or add to taskRunning, never duplicate
if (taskRunningIndex === -1) {
// Task not in taskRunning, add it
@@ -640,7 +661,6 @@ const chatStore = create()(
// Task already in taskRunning, update it
taskRunning![taskRunningIndex] = {
...taskRunning![taskRunningIndex],
- content,
status: "",
agent: JSON.parse(JSON.stringify(taskAgent)),
};
@@ -1638,7 +1658,17 @@ const chatStore = create()(
clearTasks: () => {
const { create } = get()
console.log('clearTasks')
- fetchDelete('/task/stop-all')
+
+ window.ipcRenderer.invoke('restart-backend')
+ .then((res) => {
+ console.log('restart-backend', res)
+ })
+ .catch((error) => {
+ console.error('Error in clearTasks cleanup:', error)
+ })
+
+
+ // Immediately create new task to maintain UI responsiveness
const newTaskId = create()
set((state) => ({
...state,
diff --git a/src/types/chatbox.d.ts b/src/types/chatbox.d.ts
index f7067427d..a56026fdf 100644
--- a/src/types/chatbox.d.ts
+++ b/src/types/chatbox.d.ts
@@ -16,6 +16,7 @@ declare global {
toolkitStatus?: AgentStatus;
}[];
failure_count?: number;
+ reAssignTo?:string;
}
interface FileInfo {
name: string;
diff --git a/test/unit/components/Setting/utils.test.ts b/test/unit/components/Setting/utils.test.ts
new file mode 100644
index 000000000..63eb4169d
--- /dev/null
+++ b/test/unit/components/Setting/utils.test.ts
@@ -0,0 +1,201 @@
+import { describe, it, expect } from 'vitest';
+import { parseArgsToArray, arrayToArgsJson } from '../../../../src/pages/Setting/components/utils';
+
+describe('parseArgsToArray', () => {
+ it('should parse JSON array string to array', () => {
+ const input = '["arg1", "arg2", "arg3"]';
+ const expected = ['arg1', 'arg2', 'arg3'];
+ const result = parseArgsToArray(input);
+ expect(result).toEqual(expected);
+ });
+
+ it('should parse JSON array string with special characters', () => {
+ const input = '["-y", "@modelcontextprotocol/server-sequential-thinking"]';
+ const expected = ['-y', '@modelcontextprotocol/server-sequential-thinking'];
+ const result = parseArgsToArray(input);
+ expect(result).toEqual(expected);
+ });
+
+ it('should parse JSON array string with file paths containing backslashes', () => {
+ const input = '["--directory", "C:\\\\Users\\\\ASUS\\\\Desktop\\\\project", "run", "main.py"]';
+ const expected = ['--directory', 'C:\\Users\\ASUS\\Desktop\\project', 'run', 'main.py'];
+ const result = parseArgsToArray(input);
+ expect(result).toEqual(expected);
+ });
+
+ it('should parse JSON array string with file paths containing forward slashes', () => {
+ const input = '["--directory", "C:/Users/ASUS/Desktop/project", "run", "main.py"]';
+ const expected = ['--directory', 'C:/Users/ASUS/Desktop/project', 'run', 'main.py'];
+ const result = parseArgsToArray(input);
+ expect(result).toEqual(expected);
+ });
+
+ it('should parse comma-separated string to array', () => {
+ const input = '-y,@modelcontextprotocol/server-filesystem,.';
+ const expected = ['-y', '@modelcontextprotocol/server-filesystem', '.'];
+ const result = parseArgsToArray(input);
+ expect(result).toEqual(expected);
+ });
+
+ it('should parse comma-separated string with spaces', () => {
+ const input = '-y, @modelcontextprotocol/server-filesystem, .';
+ const expected = ['-y', '@modelcontextprotocol/server-filesystem', '.'];
+ const result = parseArgsToArray(input);
+ expect(result).toEqual(expected);
+ });
+
+ it('should parse comma-separated string with file paths containing slashes', () => {
+ const input = '--directory,C:/Users/ASUS/Desktop/project,run,main.py';
+ const expected = ['--directory', 'C:/Users/ASUS/Desktop/project', 'run', 'main.py'];
+ const result = parseArgsToArray(input);
+ expect(result).toEqual(expected);
+ });
+
+ it('should handle empty string', () => {
+ const input = '';
+ const expected: string[] = [];
+ const result = parseArgsToArray(input);
+ expect(result).toEqual(expected);
+ });
+
+ it('should handle whitespace-only string', () => {
+ const input = ' ';
+ const expected: string[] = [];
+ const result = parseArgsToArray(input);
+ expect(result).toEqual(expected);
+ });
+
+ it('should filter out empty args from comma-separated string', () => {
+ const input = '-y,,@modelcontextprotocol/server-filesystem,.';
+ const expected = ['-y', '@modelcontextprotocol/server-filesystem', '.'];
+ const result = parseArgsToArray(input);
+ expect(result).toEqual(expected);
+ });
+
+ it('should handle invalid JSON gracefully by treating as comma-separated', () => {
+ const input = '[invalid json';
+ const expected: string[] = ['[invalid json'];
+ const result = parseArgsToArray(input);
+ expect(result).toEqual(expected);
+ });
+
+ it('should handle non-array JSON by treating as comma-separated', () => {
+ const input = '{"key": "value"}';
+ //Trim the curly braces
+ const expected: string[] = ['"key": "value"'];
+ const result = parseArgsToArray(input);
+ expect(result).toEqual(expected);
+ });
+
+ it('should convert array elements to strings', () => {
+ const input = '[123, true, "string", null]';
+ const expected = ['123', 'true', 'string', 'null'];
+ const result = parseArgsToArray(input);
+ expect(result).toEqual(expected);
+ });
+});
+
+describe('arrayToArgsJson', () => {
+ it('should convert array to JSON string', () => {
+ const input = ['arg1', 'arg2', 'arg3'];
+ const expected = '["arg1","arg2","arg3"]';
+ const result = arrayToArgsJson(input);
+ expect(result).toBe(expected);
+ });
+
+ it('should convert array with special characters to JSON string', () => {
+ const input = ['-y', '@modelcontextprotocol/server-sequential-thinking'];
+ const expected = '["-y","@modelcontextprotocol/server-sequential-thinking"]';
+ const result = arrayToArgsJson(input);
+ expect(result).toBe(expected);
+ });
+
+ it('should convert array with file paths containing backslashes', () => {
+ const input = ['--directory', 'C:\\Users\\ASUS\\Desktop\\project', 'run', 'main.py'];
+ const expected = '["--directory","C:\\\\Users\\\\ASUS\\\\Desktop\\\\project","run","main.py"]';
+ const result = arrayToArgsJson(input);
+ expect(result).toBe(expected);
+ });
+
+ it('should convert array with file paths containing forward slashes', () => {
+ const input = ['--directory', 'C:/Users/ASUS/Desktop/project', 'run', 'main.py'];
+ const expected = '["--directory","C:/Users/ASUS/Desktop/project","run","main.py"]';
+ const result = arrayToArgsJson(input);
+ expect(result).toBe(expected);
+ });
+
+ it('should handle empty array', () => {
+ const input: string[] = [];
+ const expected = '';
+ const result = arrayToArgsJson(input);
+ expect(result).toBe(expected);
+ });
+
+ it('should filter out empty strings and whitespace-only strings', () => {
+ const input = ['arg1', '', ' ', 'arg2'];
+ const expected = '["arg1","arg2"]';
+ const result = arrayToArgsJson(input);
+ expect(result).toBe(expected);
+ });
+
+ it('should return empty string for array with only empty/whitespace strings', () => {
+ const input = ['', ' ', '\t', '\n'];
+ const expected = '';
+ const result = arrayToArgsJson(input);
+ expect(result).toBe(expected);
+ });
+
+ it('should preserve strings with meaningful whitespace', () => {
+ const input = ['arg with spaces', 'another arg'];
+ const expected = '["arg with spaces","another arg"]';
+ const result = arrayToArgsJson(input);
+ expect(result).toBe(expected);
+ });
+});
+
+describe('bidirectional conversion', () => {
+ it('should correctly convert from comma-separated string to JSON and back', () => {
+ const original = '-y,@modelcontextprotocol/server-filesystem,.';
+ const array = parseArgsToArray(original);
+ const jsonString = arrayToArgsJson(array);
+ const finalArray = parseArgsToArray(jsonString);
+
+ expect(array).toEqual(['-y', '@modelcontextprotocol/server-filesystem', '.']);
+ expect(jsonString).toBe('["-y","@modelcontextprotocol/server-filesystem","."]');
+ expect(finalArray).toEqual(array);
+ });
+
+ it('should correctly convert from JSON string to array and back', () => {
+ const original = '["-y","@modelcontextprotocol/server-sequential-thinking"]';
+ const array = parseArgsToArray(original);
+ const jsonString = arrayToArgsJson(array);
+
+ expect(array).toEqual(['-y', '@modelcontextprotocol/server-sequential-thinking']);
+ expect(jsonString).toBe(original);
+ });
+
+ it('should handle file paths with various slash types bidirectionally', () => {
+ const windowsPath = '["--directory","C:\\\\Users\\\\ASUS\\\\Desktop\\\\project","run"]';
+ const unixPath = '["--directory","/home/user/project","run"]';
+
+ // Test Windows paths
+ const windowsArray = parseArgsToArray(windowsPath);
+ const windowsJson = arrayToArgsJson(windowsArray);
+ expect(parseArgsToArray(windowsJson)).toEqual(windowsArray);
+
+ // Test Unix paths
+ const unixArray = parseArgsToArray(unixPath);
+ const unixJson = arrayToArgsJson(unixArray);
+ expect(parseArgsToArray(unixJson)).toEqual(unixArray);
+ });
+
+ it('should handle mixed path separators in comma-separated format', () => {
+ const mixed = '--directory,C:/Users/ASUS\\Desktop/project,run,main.py';
+ const array = parseArgsToArray(mixed);
+ const jsonString = arrayToArgsJson(array);
+ const finalArray = parseArgsToArray(jsonString);
+
+ expect(array).toEqual(['--directory', 'C:/Users/ASUS\\Desktop/project', 'run', 'main.py']);
+ expect(finalArray).toEqual(array);
+ });
+});