@mastra/inngest 0.10.5 → 0.10.6-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/inngest@0.10.5-alpha.1 build /home/runner/work/mastra/mastra/workflows/inngest
2
+ > @mastra/inngest@0.10.6-alpha.0 build /home/runner/work/mastra/mastra/workflows/inngest
3
3
  > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.5.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 8101ms
9
+ TSC ⚡️ Build success in 8972ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.8.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/workflows/inngest/dist/_tsup-dts-rollup.d.ts
14
14
  Analysis will use the bundled TypeScript version 5.8.3
15
15
  Writing package typings: /home/runner/work/mastra/mastra/workflows/inngest/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 6203ms
16
+ DTS ⚡️ Build success in 6816ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- CJS dist/index.cjs 26.84 KB
21
- CJS ⚡️ Build success in 304ms
22
- ESM dist/index.js 26.65 KB
23
- ESM ⚡️ Build success in 305ms
20
+ ESM dist/index.js 31.23 KB
21
+ ESM ⚡️ Build success in 293ms
22
+ CJS dist/index.cjs 31.43 KB
23
+ CJS ⚡️ Build success in 293ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @mastra/inngest
2
2
 
3
+ ## 0.10.6-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 9d52b17: Fix inngest workflows streaming and add step metadata
8
+ - Updated dependencies [d8f2d19]
9
+ - Updated dependencies [9d52b17]
10
+ - Updated dependencies [8ba1b51]
11
+ - @mastra/core@0.10.7-alpha.0
12
+
3
13
  ## 0.10.5
4
14
 
5
15
  ### Patch Changes
@@ -1,7 +1,8 @@
1
- import { Agent } from '@mastra/core';
1
+ import type { Agent } from '@mastra/core';
2
2
  import type { BaseContext } from 'inngest';
3
3
  import { ClientOptions } from 'inngest';
4
4
  import { DefaultExecutionEngine } from '@mastra/core/workflows';
5
+ import type { Emitter } from '@mastra/core/workflows';
5
6
  import type { ExecuteFunction } from '@mastra/core/workflows';
6
7
  import type { ExecutionContext } from '@mastra/core/workflows';
7
8
  import type { ExecutionEngine } from '@mastra/core/workflows';
@@ -19,7 +20,8 @@ import type { Span } from '@opentelemetry/api';
19
20
  import type { Step } from '@mastra/core/workflows';
20
21
  import type { StepFlowEntry } from '@mastra/core/workflows';
21
22
  import type { StepResult } from '@mastra/core/workflows';
22
- import { Tool } from '@mastra/core';
23
+ import type { StreamEvent } from '@mastra/core/workflows';
24
+ import { Tool } from '@mastra/core/tools';
23
25
  import type { ToolExecutionContext } from '@mastra/core';
24
26
  import type { WatchEvent } from '@mastra/core/workflows';
25
27
  import { Workflow } from '@mastra/core/workflows';
@@ -70,9 +72,26 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
70
72
  private inngestStep;
71
73
  private inngestAttempts;
72
74
  constructor(mastra: Mastra, inngestStep: BaseContext<Inngest>['step'], inngestAttempts?: number);
73
- protected fmtReturnValue<TOutput>(executionSpan: Span | undefined, emitter: {
74
- emit: (event: string, data: any) => Promise<void>;
75
- }, stepResults: Record<string, StepResult<any, any, any, any>>, lastOutput: StepResult<any, any, any, any>, error?: Error | string): Promise<TOutput>;
75
+ execute<TInput, TOutput>(params: {
76
+ workflowId: string;
77
+ runId: string;
78
+ graph: ExecutionGraph;
79
+ serializedStepGraph: SerializedStepFlowEntry[];
80
+ input?: TInput;
81
+ resume?: {
82
+ steps: string[];
83
+ stepResults: Record<string, StepResult<any, any, any, any>>;
84
+ resumePayload: any;
85
+ resumePath: number[];
86
+ };
87
+ emitter: Emitter;
88
+ retryConfig?: {
89
+ attempts?: number;
90
+ delay?: number;
91
+ };
92
+ runtimeContext: RuntimeContext;
93
+ }): Promise<TOutput>;
94
+ protected fmtReturnValue<TOutput>(executionSpan: Span | undefined, emitter: Emitter, stepResults: Record<string, StepResult<any, any, any, any>>, lastOutput: StepResult<any, any, any, any>, error?: Error | string): Promise<TOutput>;
76
95
  superExecuteStep({ workflowId, runId, step, stepResults, executionContext, resume, prevOutput, emitter, runtimeContext, }: {
77
96
  workflowId: string;
78
97
  runId: string;
@@ -84,15 +103,17 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
84
103
  resumePayload: any;
85
104
  };
86
105
  prevOutput: any;
87
- emitter: {
88
- emit: (event: string, data: any) => Promise<void>;
89
- };
106
+ emitter: Emitter;
90
107
  runtimeContext: RuntimeContext;
91
108
  }): Promise<StepResult<any, any, any, any>>;
92
109
  executeSleep({ id, duration }: {
93
110
  id: string;
94
111
  duration: number;
95
112
  }): Promise<void>;
113
+ executeWaitForEvent({ event, timeout }: {
114
+ event: string;
115
+ timeout?: number;
116
+ }): Promise<any>;
96
117
  executeStep({ step, stepResults, executionContext, resume, prevOutput, emitter, runtimeContext, }: {
97
118
  step: Step<string, any, any>;
98
119
  stepResults: Record<string, StepResult<any, any, any, any>>;
@@ -112,9 +133,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
112
133
  runId?: string;
113
134
  };
114
135
  prevOutput: any;
115
- emitter: {
116
- emit: (event: string, data: any) => Promise<void>;
117
- };
136
+ emitter: Emitter;
118
137
  runtimeContext: RuntimeContext;
119
138
  }): Promise<StepResult<any, any, any, any>>;
120
139
  persistStepUpdate({ workflowId, runId, stepResults, executionContext, serializedStepGraph, workflowStatus, result, error, }: {
@@ -146,9 +165,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
146
165
  resumePath: number[];
147
166
  };
148
167
  executionContext: ExecutionContext;
149
- emitter: {
150
- emit: (event: string, data: any) => Promise<void>;
151
- };
168
+ emitter: Emitter;
152
169
  runtimeContext: RuntimeContext;
153
170
  }): Promise<StepResult<any, any, any, any>>;
154
171
  }
@@ -172,6 +189,7 @@ export declare class InngestRun<TEngineType = InngestEngineType, TSteps extends
172
189
  }, inngest: Inngest);
173
190
  getRuns(eventId: string): Promise<any>;
174
191
  getRunOutput(eventId: string): Promise<any>;
192
+ sendEvent(event: string, data: any): Promise<void>;
175
193
  start({ inputData, }: {
176
194
  inputData?: z.infer<TInput>;
177
195
  runtimeContext?: RuntimeContext;
@@ -181,7 +199,19 @@ export declare class InngestRun<TEngineType = InngestEngineType, TSteps extends
181
199
  step: Step<string, any, any, TResumeSchema, any> | [...Step<string, any, any, any, any>[], Step<string, any, any, TResumeSchema, any>] | string | string[];
182
200
  runtimeContext?: RuntimeContext;
183
201
  }): Promise<WorkflowResult<TOutput, TSteps>>;
184
- watch(cb: (event: any) => void): () => void;
202
+ _resume<TResumeSchema extends z.ZodType<any>>(params: {
203
+ resumeData?: z.infer<TResumeSchema>;
204
+ step: Step<string, any, any, TResumeSchema, any> | [...Step<string, any, any, any, any>[], Step<string, any, any, TResumeSchema, any>] | string | string[];
205
+ runtimeContext?: RuntimeContext;
206
+ }): Promise<WorkflowResult<TOutput, TSteps>>;
207
+ watch(cb: (event: WatchEvent) => void, type?: 'watch' | 'watch-v2'): () => void;
208
+ stream({ inputData, runtimeContext }?: {
209
+ inputData?: z.infer<TInput>;
210
+ runtimeContext?: RuntimeContext;
211
+ }): {
212
+ stream: ReadableStream<StreamEvent>;
213
+ getWorkflowState: () => Promise<WorkflowResult<TOutput, TSteps>>;
214
+ };
185
215
  }
186
216
 
187
217
  export declare class InngestWorkflow<TEngineType = InngestEngineType, TSteps extends Step<string, any, any>[] = Step<string, any, any>[], TWorkflowId extends string = string, TInput extends z.ZodType<any> = z.ZodType<any>, TOutput extends z.ZodType<any> = z.ZodType<any>, TPrevSchema extends z.ZodType<any> = TInput> extends Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TPrevSchema> {
@@ -1,7 +1,8 @@
1
- import { Agent } from '@mastra/core';
1
+ import type { Agent } from '@mastra/core';
2
2
  import type { BaseContext } from 'inngest';
3
3
  import { ClientOptions } from 'inngest';
4
4
  import { DefaultExecutionEngine } from '@mastra/core/workflows';
5
+ import type { Emitter } from '@mastra/core/workflows';
5
6
  import type { ExecuteFunction } from '@mastra/core/workflows';
6
7
  import type { ExecutionContext } from '@mastra/core/workflows';
7
8
  import type { ExecutionEngine } from '@mastra/core/workflows';
@@ -19,7 +20,8 @@ import type { Span } from '@opentelemetry/api';
19
20
  import type { Step } from '@mastra/core/workflows';
20
21
  import type { StepFlowEntry } from '@mastra/core/workflows';
21
22
  import type { StepResult } from '@mastra/core/workflows';
22
- import { Tool } from '@mastra/core';
23
+ import type { StreamEvent } from '@mastra/core/workflows';
24
+ import { Tool } from '@mastra/core/tools';
23
25
  import type { ToolExecutionContext } from '@mastra/core';
24
26
  import type { WatchEvent } from '@mastra/core/workflows';
25
27
  import { Workflow } from '@mastra/core/workflows';
@@ -70,9 +72,26 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
70
72
  private inngestStep;
71
73
  private inngestAttempts;
72
74
  constructor(mastra: Mastra, inngestStep: BaseContext<Inngest>['step'], inngestAttempts?: number);
73
- protected fmtReturnValue<TOutput>(executionSpan: Span | undefined, emitter: {
74
- emit: (event: string, data: any) => Promise<void>;
75
- }, stepResults: Record<string, StepResult<any, any, any, any>>, lastOutput: StepResult<any, any, any, any>, error?: Error | string): Promise<TOutput>;
75
+ execute<TInput, TOutput>(params: {
76
+ workflowId: string;
77
+ runId: string;
78
+ graph: ExecutionGraph;
79
+ serializedStepGraph: SerializedStepFlowEntry[];
80
+ input?: TInput;
81
+ resume?: {
82
+ steps: string[];
83
+ stepResults: Record<string, StepResult<any, any, any, any>>;
84
+ resumePayload: any;
85
+ resumePath: number[];
86
+ };
87
+ emitter: Emitter;
88
+ retryConfig?: {
89
+ attempts?: number;
90
+ delay?: number;
91
+ };
92
+ runtimeContext: RuntimeContext;
93
+ }): Promise<TOutput>;
94
+ protected fmtReturnValue<TOutput>(executionSpan: Span | undefined, emitter: Emitter, stepResults: Record<string, StepResult<any, any, any, any>>, lastOutput: StepResult<any, any, any, any>, error?: Error | string): Promise<TOutput>;
76
95
  superExecuteStep({ workflowId, runId, step, stepResults, executionContext, resume, prevOutput, emitter, runtimeContext, }: {
77
96
  workflowId: string;
78
97
  runId: string;
@@ -84,15 +103,17 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
84
103
  resumePayload: any;
85
104
  };
86
105
  prevOutput: any;
87
- emitter: {
88
- emit: (event: string, data: any) => Promise<void>;
89
- };
106
+ emitter: Emitter;
90
107
  runtimeContext: RuntimeContext;
91
108
  }): Promise<StepResult<any, any, any, any>>;
92
109
  executeSleep({ id, duration }: {
93
110
  id: string;
94
111
  duration: number;
95
112
  }): Promise<void>;
113
+ executeWaitForEvent({ event, timeout }: {
114
+ event: string;
115
+ timeout?: number;
116
+ }): Promise<any>;
96
117
  executeStep({ step, stepResults, executionContext, resume, prevOutput, emitter, runtimeContext, }: {
97
118
  step: Step<string, any, any>;
98
119
  stepResults: Record<string, StepResult<any, any, any, any>>;
@@ -112,9 +133,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
112
133
  runId?: string;
113
134
  };
114
135
  prevOutput: any;
115
- emitter: {
116
- emit: (event: string, data: any) => Promise<void>;
117
- };
136
+ emitter: Emitter;
118
137
  runtimeContext: RuntimeContext;
119
138
  }): Promise<StepResult<any, any, any, any>>;
120
139
  persistStepUpdate({ workflowId, runId, stepResults, executionContext, serializedStepGraph, workflowStatus, result, error, }: {
@@ -146,9 +165,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
146
165
  resumePath: number[];
147
166
  };
148
167
  executionContext: ExecutionContext;
149
- emitter: {
150
- emit: (event: string, data: any) => Promise<void>;
151
- };
168
+ emitter: Emitter;
152
169
  runtimeContext: RuntimeContext;
153
170
  }): Promise<StepResult<any, any, any, any>>;
154
171
  }
@@ -172,6 +189,7 @@ export declare class InngestRun<TEngineType = InngestEngineType, TSteps extends
172
189
  }, inngest: Inngest);
173
190
  getRuns(eventId: string): Promise<any>;
174
191
  getRunOutput(eventId: string): Promise<any>;
192
+ sendEvent(event: string, data: any): Promise<void>;
175
193
  start({ inputData, }: {
176
194
  inputData?: z.infer<TInput>;
177
195
  runtimeContext?: RuntimeContext;
@@ -181,7 +199,19 @@ export declare class InngestRun<TEngineType = InngestEngineType, TSteps extends
181
199
  step: Step<string, any, any, TResumeSchema, any> | [...Step<string, any, any, any, any>[], Step<string, any, any, TResumeSchema, any>] | string | string[];
182
200
  runtimeContext?: RuntimeContext;
183
201
  }): Promise<WorkflowResult<TOutput, TSteps>>;
184
- watch(cb: (event: any) => void): () => void;
202
+ _resume<TResumeSchema extends z.ZodType<any>>(params: {
203
+ resumeData?: z.infer<TResumeSchema>;
204
+ step: Step<string, any, any, TResumeSchema, any> | [...Step<string, any, any, any, any>[], Step<string, any, any, TResumeSchema, any>] | string | string[];
205
+ runtimeContext?: RuntimeContext;
206
+ }): Promise<WorkflowResult<TOutput, TSteps>>;
207
+ watch(cb: (event: WatchEvent) => void, type?: 'watch' | 'watch-v2'): () => void;
208
+ stream({ inputData, runtimeContext }?: {
209
+ inputData?: z.infer<TInput>;
210
+ runtimeContext?: RuntimeContext;
211
+ }): {
212
+ stream: ReadableStream<StreamEvent>;
213
+ getWorkflowState: () => Promise<WorkflowResult<TOutput, TSteps>>;
214
+ };
185
215
  }
186
216
 
187
217
  export declare class InngestWorkflow<TEngineType = InngestEngineType, TSteps extends Step<string, any, any>[] = Step<string, any, any>[], TWorkflowId extends string = string, TInput extends z.ZodType<any> = z.ZodType<any>, TOutput extends z.ZodType<any> = z.ZodType<any>, TPrevSchema extends z.ZodType<any> = TInput> extends Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TPrevSchema> {
package/dist/index.cjs CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  var crypto = require('crypto');
4
4
  var realtime = require('@inngest/realtime');
5
- var core = require('@mastra/core');
6
5
  var di = require('@mastra/core/di');
6
+ var tools = require('@mastra/core/tools');
7
7
  var workflows = require('@mastra/core/workflows');
8
8
  var _constants = require('@mastra/core/workflows/_constants');
9
9
  var hono = require('inngest/hono');
@@ -45,7 +45,7 @@ var InngestRun = class extends workflows.Run {
45
45
  }
46
46
  async getRunOutput(eventId) {
47
47
  let runs = await this.getRuns(eventId);
48
- while (runs?.[0]?.status !== "Completed") {
48
+ while (runs?.[0]?.status !== "Completed" || runs?.[0]?.event_id !== eventId) {
49
49
  await new Promise((resolve) => setTimeout(resolve, 1e3));
50
50
  runs = await this.getRuns(eventId);
51
51
  if (runs?.[0]?.status === "Failed" || runs?.[0]?.status === "Cancelled") {
@@ -54,6 +54,12 @@ var InngestRun = class extends workflows.Run {
54
54
  }
55
55
  return runs?.[0];
56
56
  }
57
+ async sendEvent(event, data) {
58
+ await this.inngest.send({
59
+ name: `user-event-${event}`,
60
+ data
61
+ });
62
+ }
57
63
  async start({
58
64
  inputData
59
65
  }) {
@@ -91,6 +97,17 @@ var InngestRun = class extends workflows.Run {
91
97
  return result;
92
98
  }
93
99
  async resume(params) {
100
+ const p = this._resume(params).then((result) => {
101
+ if (result.status !== "suspended") {
102
+ this.closeStreamAction?.().catch(() => {
103
+ });
104
+ }
105
+ return result;
106
+ });
107
+ this.executionResults = p;
108
+ return p;
109
+ }
110
+ async _resume(params) {
94
111
  const steps = (Array.isArray(params.step) ? params.step : [params.step]).map(
95
112
  (step) => typeof step === "string" ? step : step?.id
96
113
  );
@@ -124,25 +141,60 @@ var InngestRun = class extends workflows.Run {
124
141
  }
125
142
  return result;
126
143
  }
127
- watch(cb) {
144
+ watch(cb, type = "watch") {
145
+ let active = true;
128
146
  const streamPromise = realtime.subscribe(
129
147
  {
130
148
  channel: `workflow:${this.workflowId}:${this.runId}`,
131
- topics: ["watch"],
149
+ topics: [type],
132
150
  app: this.inngest
133
151
  },
134
152
  (message) => {
135
- cb(message.data);
153
+ if (active) {
154
+ cb(message.data);
155
+ }
136
156
  }
137
157
  );
138
158
  return () => {
139
- streamPromise.then((stream) => {
140
- stream.cancel();
159
+ active = false;
160
+ streamPromise.then(async (stream) => {
161
+ return stream.cancel();
141
162
  }).catch((err) => {
142
163
  console.error(err);
143
164
  });
144
165
  };
145
166
  }
167
+ stream({ inputData, runtimeContext } = {}) {
168
+ const { readable, writable } = new TransformStream();
169
+ const writer = writable.getWriter();
170
+ const unwatch = this.watch(async (event) => {
171
+ try {
172
+ await writer.write(event);
173
+ } catch {
174
+ }
175
+ }, "watch-v2");
176
+ this.closeStreamAction = async () => {
177
+ unwatch();
178
+ try {
179
+ await writer.close();
180
+ } catch (err) {
181
+ console.error("Error closing stream:", err);
182
+ } finally {
183
+ writer.releaseLock();
184
+ }
185
+ };
186
+ this.executionResults = this.start({ inputData, runtimeContext }).then((result) => {
187
+ if (result.status !== "suspended") {
188
+ this.closeStreamAction?.().catch(() => {
189
+ });
190
+ }
191
+ return result;
192
+ });
193
+ return {
194
+ stream: readable,
195
+ getWorkflowState: () => this.executionResults
196
+ };
197
+ }
146
198
  };
147
199
  var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
148
200
  #mastra;
@@ -250,12 +302,18 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
250
302
  try {
251
303
  await publish({
252
304
  channel: `workflow:${this.id}:${runId}`,
253
- topic: "watch",
305
+ topic: event2,
254
306
  data
255
307
  });
256
308
  } catch (err) {
257
309
  this.logger.error("Error emitting event: " + (err?.stack ?? err?.message ?? err));
258
310
  }
311
+ },
312
+ on: (_event, _callback) => {
313
+ },
314
+ off: (_event, _callback) => {
315
+ },
316
+ once: (_event, _callback) => {
259
317
  }
260
318
  };
261
319
  const engine = new InngestExecutionEngine(this.#mastra, step, attempt);
@@ -293,8 +351,14 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
293
351
  return [this.getFunction(), ...this.getNestedFunctions(this.executionGraph.steps)];
294
352
  }
295
353
  };
354
+ function isAgent(params) {
355
+ return params?.component === "AGENT";
356
+ }
357
+ function isTool(params) {
358
+ return params instanceof tools.Tool;
359
+ }
296
360
  function createStep(params) {
297
- if (params instanceof core.Agent) {
361
+ if (isAgent(params)) {
298
362
  return {
299
363
  id: params.name,
300
364
  // @ts-ignore
@@ -359,7 +423,7 @@ function createStep(params) {
359
423
  }
360
424
  };
361
425
  }
362
- if (params instanceof core.Tool) {
426
+ if (isTool(params)) {
363
427
  if (!params.inputSchema || !params.outputSchema) {
364
428
  throw new Error("Tool must have input and output schemas defined");
365
429
  }
@@ -425,6 +489,18 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
425
489
  this.inngestStep = inngestStep;
426
490
  this.inngestAttempts = inngestAttempts;
427
491
  }
492
+ async execute(params) {
493
+ await params.emitter.emit("watch-v2", {
494
+ type: "start",
495
+ payload: { runId: params.runId }
496
+ });
497
+ const result = await super.execute(params);
498
+ await params.emitter.emit("watch-v2", {
499
+ type: "finish",
500
+ payload: { runId: params.runId }
501
+ });
502
+ return result;
503
+ }
428
504
  async fmtReturnValue(executionSpan, emitter, stepResults, lastOutput, error) {
429
505
  const base = {
430
506
  status: lastOutput.status,
@@ -508,6 +584,16 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
508
584
  async executeSleep({ id, duration }) {
509
585
  await this.inngestStep.sleep(id, duration);
510
586
  }
587
+ async executeWaitForEvent({ event, timeout }) {
588
+ const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
589
+ event: `user-event-${event}`,
590
+ timeout: timeout ?? 5e3
591
+ });
592
+ if (eventData === null) {
593
+ throw "Timeout waiting for event";
594
+ }
595
+ return eventData?.data;
596
+ }
511
597
  async executeStep({
512
598
  step,
513
599
  stepResults,
@@ -517,9 +603,10 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
517
603
  emitter,
518
604
  runtimeContext
519
605
  }) {
520
- await this.inngestStep.run(
606
+ const startedAt = await this.inngestStep.run(
521
607
  `workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
522
608
  async () => {
609
+ const startedAt2 = Date.now();
523
610
  await emitter.emit("watch", {
524
611
  type: "watch",
525
612
  payload: {
@@ -541,6 +628,13 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
541
628
  },
542
629
  eventTimestamp: Date.now()
543
630
  });
631
+ await emitter.emit("watch-v2", {
632
+ type: "step-start",
633
+ payload: {
634
+ id: step.id
635
+ }
636
+ });
637
+ return startedAt2;
544
638
  }
545
639
  );
546
640
  if (step instanceof InngestWorkflow) {
@@ -601,6 +695,13 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
601
695
  },
602
696
  eventTimestamp: Date.now()
603
697
  });
698
+ await emitter.emit("watch-v2", {
699
+ type: "step-result",
700
+ payload: {
701
+ id: step.id,
702
+ status: "failed"
703
+ }
704
+ });
604
705
  return { executionContext, result: { status: "failed", error: result?.error } };
605
706
  } else if (result.status === "suspended") {
606
707
  const suspendedSteps = Object.entries(result.steps).filter(([_stepName, stepResult]) => {
@@ -627,6 +728,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
627
728
  },
628
729
  eventTimestamp: Date.now()
629
730
  });
731
+ await emitter.emit("watch-v2", {
732
+ type: "step-suspended",
733
+ payload: {
734
+ id: step.id
735
+ }
736
+ });
630
737
  return {
631
738
  executionContext,
632
739
  result: {
@@ -677,6 +784,13 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
677
784
  },
678
785
  eventTimestamp: Date.now()
679
786
  });
787
+ await emitter.emit("watch-v2", {
788
+ type: "step-finish",
789
+ payload: {
790
+ id: step.id,
791
+ metadata: {}
792
+ }
793
+ });
680
794
  return { executionContext, result: { status: "success", output: result?.result } };
681
795
  }
682
796
  );
@@ -716,12 +830,37 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
716
830
  step: this.inngestStep
717
831
  }
718
832
  });
719
- execResults = { status: "success", output: result };
833
+ const endedAt = Date.now();
834
+ execResults = {
835
+ status: "success",
836
+ output: result,
837
+ startedAt,
838
+ endedAt,
839
+ payload: prevOutput,
840
+ resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
841
+ resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
842
+ };
720
843
  } catch (e) {
721
- execResults = { status: "failed", error: e instanceof Error ? e.message : String(e) };
844
+ execResults = {
845
+ status: "failed",
846
+ payload: prevOutput,
847
+ error: e instanceof Error ? e.message : String(e),
848
+ endedAt: Date.now(),
849
+ startedAt,
850
+ resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
851
+ resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
852
+ };
722
853
  }
723
854
  if (suspended) {
724
- execResults = { status: "suspended", payload: suspended.payload };
855
+ execResults = {
856
+ status: "suspended",
857
+ suspendedPayload: suspended.payload,
858
+ payload: prevOutput,
859
+ suspendedAt: Date.now(),
860
+ startedAt,
861
+ resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
862
+ resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
863
+ };
725
864
  }
726
865
  if (execResults.status === "failed") {
727
866
  if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
@@ -733,18 +872,43 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
733
872
  payload: {
734
873
  currentStep: {
735
874
  id: step.id,
736
- status: execResults.status,
737
- output: execResults.output
875
+ ...execResults
738
876
  },
739
877
  workflowState: {
740
878
  status: "running",
741
- steps: stepResults,
879
+ steps: { ...stepResults, [step.id]: execResults },
742
880
  result: null,
743
881
  error: null
744
882
  }
745
883
  },
746
884
  eventTimestamp: Date.now()
747
885
  });
886
+ if (execResults.status === "suspended") {
887
+ await emitter.emit("watch-v2", {
888
+ type: "step-suspended",
889
+ payload: {
890
+ id: step.id,
891
+ status: execResults.status,
892
+ output: execResults.status === "success" ? execResults?.output : void 0
893
+ }
894
+ });
895
+ } else {
896
+ await emitter.emit("watch-v2", {
897
+ type: "step-result",
898
+ payload: {
899
+ id: step.id,
900
+ status: execResults.status,
901
+ output: execResults.status === "success" ? execResults?.output : void 0
902
+ }
903
+ });
904
+ await emitter.emit("watch-v2", {
905
+ type: "step-finish",
906
+ payload: {
907
+ id: step.id,
908
+ metadata: {}
909
+ }
910
+ });
911
+ }
748
912
  return { result: execResults, executionContext, stepResults };
749
913
  });
750
914
  Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
@@ -862,7 +1026,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
862
1026
  if (hasFailed) {
863
1027
  execResults = { status: "failed", error: hasFailed.result.error };
864
1028
  } else if (hasSuspended) {
865
- execResults = { status: "suspended", payload: hasSuspended.result.payload };
1029
+ execResults = { status: "suspended", payload: hasSuspended.result.suspendPayload };
866
1030
  } else {
867
1031
  execResults = {
868
1032
  status: "success",