Skip to content

Commit 22fd5a3

Browse files
committed
feat(workflow): emit step lifecycle events automatically
- Import emit from events module - Emit stepStarted before each step execution - Emit stepCompleted after successful step with duration - Emit stepFailed in catch block with error and duration This enables real-time step progress streaming to MCP clients.
1 parent e9fd66e commit 22fd5a3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

packages/workflow/src/runner.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Workflow, WorkflowContext, Logger, ConsoleLogger, isWorkflowSuccess, isNextStep } from './types';
2+
import { emit } from './events';
23
import { Desktop } from '@mediar-ai/terminator';
34

45
export interface WorkflowRunnerOptions {
@@ -103,6 +104,9 @@ export class WorkflowRunner {
103104
const step = steps[i];
104105

105106
this.logger.info(`\n[${i + 1}/${steps.length}] ${step.config.name}`);
107+
const totalSteps = steps.length;
108+
const stepStartTime = Date.now();
109+
emit.stepStarted(step.config.id, step.config.name, i, totalSteps);
106110

107111
try {
108112
// Check if step has condition
@@ -184,6 +188,7 @@ export class WorkflowRunner {
184188
}
185189

186190
// Save step result
191+
emit.stepCompleted(step.config.id, step.config.name, Date.now() - stepStartTime, i, totalSteps);
187192
this.state.stepResults[step.config.id] = {
188193
status: 'executed_without_error',
189194
result,
@@ -194,6 +199,7 @@ export class WorkflowRunner {
194199

195200
} catch (error: any) {
196201
this.logger.error(`❌ Step failed: ${error.message}`);
202+
emit.stepFailed(step.config.id, step.config.name, error.message, Date.now() - stepStartTime);
197203

198204
// Save step error
199205
this.state.stepResults[step.config.id] = {

0 commit comments

Comments
 (0)