src / tools / workflowTools.ts
import { getState } from '../stateRegistry';
interface WorkflowStep {
id: string;
agent_role: string;
task: string;
status: 'pending' | 'running' | 'completed' | 'failed';
result?: string;
}
interface Workflow {
id: string;
name: string;
steps: WorkflowStep[];
status: 'active' | 'completed' | 'failed';
created_at: number;
}
const workflows = new Map<string, Workflow>();
export async function workflow_create(name: string, steps: Array<{ agent_role: string; task: string }>): Promise<{ success: boolean; workflow_id?: string }> {
const id = `wf_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
workflows.set(id, {
id,
name,
steps: steps.map((s, i) => ({ ...s, status: 'pending', id: `${id}_step_${i}` })),
status: 'active',
created_at: Date.now()
});
getState().lastConfigChange = new Date();
return { success: true, workflow_id: id };
}
export async function workflow_execute(workflowId: string): Promise<{ success: boolean; completed_steps: number }> {
const wf = workflows.get(workflowId);
if (!wf) return { success: false, completed_steps: 0 };
let completed = 0;
for (const step of wf.steps) {
if (step.status !== 'pending') continue;
step.status = 'running';
step.result = `Executed: ${step.task}`;
step.status = 'completed';
completed++;
}
wf.status = completed === wf.steps.length ? 'completed' : 'failed';
return { success: true, completed_steps: completed };
}
export async function workflow_status(workflowId?: string): Promise<{ workflows: Workflow[] }> {
if (workflowId) {
const wf = workflows.get(workflowId);
return { workflows: wf ? [wf] : [] };
}
return { workflows: Array.from(workflows.values()) };
}
export async function workflow_delete(workflowId: string): Promise<{ success: boolean }> {
workflows.delete(workflowId);
return { success: true };
}
src / tools / workflowTools.ts
import { getState } from '../stateRegistry';
interface WorkflowStep {
id: string;
agent_role: string;
task: string;
status: 'pending' | 'running' | 'completed' | 'failed';
result?: string;
}
interface Workflow {
id: string;
name: string;
steps: WorkflowStep[];
status: 'active' | 'completed' | 'failed';
created_at: number;
}
const workflows = new Map<string, Workflow>();
export async function workflow_create(name: string, steps: Array<{ agent_role: string; task: string }>): Promise<{ success: boolean; workflow_id?: string }> {
const id = `wf_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
workflows.set(id, {
id,
name,
steps: steps.map((s, i) => ({ ...s, status: 'pending', id: `${id}_step_${i}` })),
status: 'active',
created_at: Date.now()
});
getState().lastConfigChange = new Date();
return { success: true, workflow_id: id };
}
export async function workflow_execute(workflowId: string): Promise<{ success: boolean; completed_steps: number }> {
const wf = workflows.get(workflowId);
if (!wf) return { success: false, completed_steps: 0 };
let completed = 0;
for (const step of wf.steps) {
if (step.status !== 'pending') continue;
step.status = 'running';
step.result = `Executed: ${step.task}`;
step.status = 'completed';
completed++;
}
wf.status = completed === wf.steps.length ? 'completed' : 'failed';
return { success: true, completed_steps: completed };
}
export async function workflow_status(workflowId?: string): Promise<{ workflows: Workflow[] }> {
if (workflowId) {
const wf = workflows.get(workflowId);
return { workflows: wf ? [wf] : [] };
}
return { workflows: Array.from(workflows.values()) };
}
export async function workflow_delete(workflowId: string): Promise<{ success: boolean }> {
workflows.delete(workflowId);
return { success: true };
}