src / tools / parallelTools.ts
import { getState } from '../stateRegistry';
interface ParallelTask {
id: string;
tasks: Array<{ task_id: string; agent_role: string; task: string; status: 'pending' | 'running' | 'completed' | 'failed'; result?: string }>;
status: 'active' | 'completed' | 'failed';
created_at: number;
}
const parallelExecutions = new Map<string, ParallelTask>();
export async function parallel_execute(tasks: Array<{ agent_role: string; task: string }>): Promise<{ success: boolean; execution_id?: string }> {
const id = `par_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
parallelExecutions.set(id, {
id,
tasks: tasks.map((t, i) => ({ ...t, status: 'pending', task_id: `${id}_task_${i}` })),
status: 'active',
created_at: Date.now()
});
for (const task of parallelExecutions.get(id)!.tasks) {
task.status = 'running';
task.result = `Parallel result: ${task.task}`;
task.status = 'completed';
}
parallelExecutions.get(id)!.status = 'completed';
getState().lastConfigChange = new Date();
return { success: true, execution_id: id };
}
export async function parallel_status(executionId?: string): Promise<{ executions: ParallelTask[] }> {
if (executionId) {
const ex = parallelExecutions.get(executionId);
return { executions: ex ? [ex] : [] };
}
return { executions: Array.from(parallelExecutions.values()) };
}
export async function parallel_cancel(executionId: string): Promise<{ success: boolean }> {
const ex = parallelExecutions.get(executionId);
if (ex) {
ex.status = 'failed';
for (const t of ex.tasks) t.status = 'failed';
}
return { success: true };
}
src / tools / parallelTools.ts
import { getState } from '../stateRegistry';
interface ParallelTask {
id: string;
tasks: Array<{ task_id: string; agent_role: string; task: string; status: 'pending' | 'running' | 'completed' | 'failed'; result?: string }>;
status: 'active' | 'completed' | 'failed';
created_at: number;
}
const parallelExecutions = new Map<string, ParallelTask>();
export async function parallel_execute(tasks: Array<{ agent_role: string; task: string }>): Promise<{ success: boolean; execution_id?: string }> {
const id = `par_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
parallelExecutions.set(id, {
id,
tasks: tasks.map((t, i) => ({ ...t, status: 'pending', task_id: `${id}_task_${i}` })),
status: 'active',
created_at: Date.now()
});
for (const task of parallelExecutions.get(id)!.tasks) {
task.status = 'running';
task.result = `Parallel result: ${task.task}`;
task.status = 'completed';
}
parallelExecutions.get(id)!.status = 'completed';
getState().lastConfigChange = new Date();
return { success: true, execution_id: id };
}
export async function parallel_status(executionId?: string): Promise<{ executions: ParallelTask[] }> {
if (executionId) {
const ex = parallelExecutions.get(executionId);
return { executions: ex ? [ex] : [] };
}
return { executions: Array.from(parallelExecutions.values()) };
}
export async function parallel_cancel(executionId: string): Promise<{ success: boolean }> {
const ex = parallelExecutions.get(executionId);
if (ex) {
ex.status = 'failed';
for (const t of ex.tasks) t.status = 'failed';
}
return { success: true };
}