@mastra/inngest 0.0.0-course-20250527170450 → 0.0.0-custom-instrumentation-20250626084921

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.
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import { randomUUID } from 'crypto';
2
2
  import { subscribe } from '@inngest/realtime';
3
3
  import { RuntimeContext } from '@mastra/core/di';
4
- import { Run, Workflow, cloneStep, createStep, DefaultExecutionEngine } from '@mastra/core/workflows';
4
+ import { Tool } from '@mastra/core/tools';
5
+ import { Run, Workflow, DefaultExecutionEngine } from '@mastra/core/workflows';
5
6
  import { EMITTER_SYMBOL } from '@mastra/core/workflows/_constants';
6
7
  import { serve as serve$1 } from 'inngest/hono';
8
+ import { z } from 'zod';
7
9
 
8
10
  // src/index.ts
9
11
  function serve({ mastra, inngest }) {
@@ -22,14 +24,16 @@ function serve({ mastra, inngest }) {
22
24
  }
23
25
  var InngestRun = class extends Run {
24
26
  inngest;
27
+ serializedStepGraph;
25
28
  #mastra;
26
29
  constructor(params, inngest) {
27
30
  super(params);
28
31
  this.inngest = inngest;
32
+ this.serializedStepGraph = params.serializedStepGraph;
29
33
  this.#mastra = params.mastra;
30
34
  }
31
35
  async getRuns(eventId) {
32
- const response = await fetch(`${this.inngest.apiBaseUrl}/v1/events/${eventId}/runs`, {
36
+ const response = await fetch(`${this.inngest.apiBaseUrl ?? "https://api.inngest.com"}/v1/events/${eventId}/runs`, {
33
37
  headers: {
34
38
  Authorization: `Bearer ${process.env.INNGEST_SIGNING_KEY}`
35
39
  }
@@ -39,7 +43,7 @@ var InngestRun = class extends Run {
39
43
  }
40
44
  async getRunOutput(eventId) {
41
45
  let runs = await this.getRuns(eventId);
42
- while (runs?.[0]?.status !== "Completed") {
46
+ while (runs?.[0]?.status !== "Completed" || runs?.[0]?.event_id !== eventId) {
43
47
  await new Promise((resolve) => setTimeout(resolve, 1e3));
44
48
  runs = await this.getRuns(eventId);
45
49
  if (runs?.[0]?.status === "Failed" || runs?.[0]?.status === "Cancelled") {
@@ -48,6 +52,12 @@ var InngestRun = class extends Run {
48
52
  }
49
53
  return runs?.[0];
50
54
  }
55
+ async sendEvent(event, data) {
56
+ await this.inngest.send({
57
+ name: `user-event-${event}`,
58
+ data
59
+ });
60
+ }
51
61
  async start({
52
62
  inputData
53
63
  }) {
@@ -56,11 +66,13 @@ var InngestRun = class extends Run {
56
66
  runId: this.runId,
57
67
  snapshot: {
58
68
  runId: this.runId,
69
+ serializedStepGraph: this.serializedStepGraph,
59
70
  value: {},
60
71
  context: {},
61
72
  activePaths: [],
62
73
  suspendedPaths: {},
63
- timestamp: Date.now()
74
+ timestamp: Date.now(),
75
+ status: "running"
64
76
  }
65
77
  });
66
78
  const eventOutput = await this.inngest.send({
@@ -83,6 +95,17 @@ var InngestRun = class extends Run {
83
95
  return result;
84
96
  }
85
97
  async resume(params) {
98
+ const p = this._resume(params).then((result) => {
99
+ if (result.status !== "suspended") {
100
+ this.closeStreamAction?.().catch(() => {
101
+ });
102
+ }
103
+ return result;
104
+ });
105
+ this.executionResults = p;
106
+ return p;
107
+ }
108
+ async _resume(params) {
86
109
  const steps = (Array.isArray(params.step) ? params.step : [params.step]).map(
87
110
  (step) => typeof step === "string" ? step : step?.id
88
111
  );
@@ -116,25 +139,60 @@ var InngestRun = class extends Run {
116
139
  }
117
140
  return result;
118
141
  }
119
- watch(cb) {
142
+ watch(cb, type = "watch") {
143
+ let active = true;
120
144
  const streamPromise = subscribe(
121
145
  {
122
146
  channel: `workflow:${this.workflowId}:${this.runId}`,
123
- topics: ["watch"],
147
+ topics: [type],
124
148
  app: this.inngest
125
149
  },
126
150
  (message) => {
127
- cb(message.data);
151
+ if (active) {
152
+ cb(message.data);
153
+ }
128
154
  }
129
155
  );
130
156
  return () => {
131
- streamPromise.then((stream) => {
132
- stream.cancel();
157
+ active = false;
158
+ streamPromise.then(async (stream) => {
159
+ return stream.cancel();
133
160
  }).catch((err) => {
134
161
  console.error(err);
135
162
  });
136
163
  };
137
164
  }
165
+ stream({ inputData, runtimeContext } = {}) {
166
+ const { readable, writable } = new TransformStream();
167
+ const writer = writable.getWriter();
168
+ const unwatch = this.watch(async (event) => {
169
+ try {
170
+ await writer.write(event);
171
+ } catch {
172
+ }
173
+ }, "watch-v2");
174
+ this.closeStreamAction = async () => {
175
+ unwatch();
176
+ try {
177
+ await writer.close();
178
+ } catch (err) {
179
+ console.error("Error closing stream:", err);
180
+ } finally {
181
+ writer.releaseLock();
182
+ }
183
+ };
184
+ this.executionResults = this.start({ inputData, runtimeContext }).then((result) => {
185
+ if (result.status !== "suspended") {
186
+ this.closeStreamAction?.().catch(() => {
187
+ });
188
+ }
189
+ return result;
190
+ });
191
+ return {
192
+ stream: readable,
193
+ getWorkflowState: () => this.executionResults
194
+ };
195
+ }
138
196
  };
139
197
  var InngestWorkflow = class _InngestWorkflow extends Workflow {
140
198
  #mastra;
@@ -157,11 +215,32 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
157
215
  const storage = this.#mastra?.getStorage();
158
216
  if (!storage) {
159
217
  this.logger.debug("Cannot get workflow runs. Mastra engine is not initialized");
160
- return null;
218
+ return this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null;
161
219
  }
162
220
  const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
163
221
  return run ?? (this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null);
164
222
  }
223
+ async getWorkflowRunExecutionResult(runId) {
224
+ const storage = this.#mastra?.getStorage();
225
+ if (!storage) {
226
+ this.logger.debug("Cannot get workflow run execution result. Mastra storage is not initialized");
227
+ return null;
228
+ }
229
+ const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
230
+ if (!run?.snapshot) {
231
+ return null;
232
+ }
233
+ if (typeof run.snapshot === "string") {
234
+ return null;
235
+ }
236
+ return {
237
+ status: run.snapshot.status,
238
+ result: run.snapshot.result,
239
+ error: run.snapshot.error,
240
+ payload: run.snapshot.context?.input,
241
+ steps: run.snapshot.context
242
+ };
243
+ }
165
244
  __registerMastra(mastra) {
166
245
  this.#mastra = mastra;
167
246
  this.executionEngine.__registerMastra(mastra);
@@ -188,6 +267,25 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
188
267
  runId: runIdToUse,
189
268
  executionEngine: this.executionEngine,
190
269
  executionGraph: this.executionGraph,
270
+ serializedStepGraph: this.serializedStepGraph,
271
+ mastra: this.#mastra,
272
+ retryConfig: this.retryConfig,
273
+ cleanup: () => this.runs.delete(runIdToUse)
274
+ },
275
+ this.inngest
276
+ );
277
+ this.runs.set(runIdToUse, run);
278
+ return run;
279
+ }
280
+ async createRunAsync(options) {
281
+ const runIdToUse = options?.runId || randomUUID();
282
+ const run = this.runs.get(runIdToUse) ?? new InngestRun(
283
+ {
284
+ workflowId: this.id,
285
+ runId: runIdToUse,
286
+ executionEngine: this.executionEngine,
287
+ executionGraph: this.executionGraph,
288
+ serializedStepGraph: this.serializedStepGraph,
191
289
  mastra: this.#mastra,
192
290
  retryConfig: this.retryConfig,
193
291
  cleanup: () => this.runs.delete(runIdToUse)
@@ -195,6 +293,23 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
195
293
  this.inngest
196
294
  );
197
295
  this.runs.set(runIdToUse, run);
296
+ await this.mastra?.getStorage()?.persistWorkflowSnapshot({
297
+ workflowName: this.id,
298
+ runId: runIdToUse,
299
+ snapshot: {
300
+ runId: runIdToUse,
301
+ status: "pending",
302
+ value: {},
303
+ context: {},
304
+ activePaths: [],
305
+ serializedStepGraph: this.serializedStepGraph,
306
+ suspendedPaths: {},
307
+ result: void 0,
308
+ error: void 0,
309
+ // @ts-ignore
310
+ timestamp: Date.now()
311
+ }
312
+ });
198
313
  return run;
199
314
  }
200
315
  getFunction() {
@@ -220,12 +335,18 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
220
335
  try {
221
336
  await publish({
222
337
  channel: `workflow:${this.id}:${runId}`,
223
- topic: "watch",
338
+ topic: event2,
224
339
  data
225
340
  });
226
341
  } catch (err) {
227
342
  this.logger.error("Error emitting event: " + (err?.stack ?? err?.message ?? err));
228
343
  }
344
+ },
345
+ on: (_event, _callback) => {
346
+ },
347
+ off: (_event, _callback) => {
348
+ },
349
+ once: (_event, _callback) => {
229
350
  }
230
351
  };
231
352
  const engine = new InngestExecutionEngine(this.#mastra, step, attempt);
@@ -233,6 +354,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
233
354
  workflowId: this.id,
234
355
  runId,
235
356
  graph: this.executionGraph,
357
+ serializedStepGraph: this.serializedStepGraph,
236
358
  input: inputData,
237
359
  emitter,
238
360
  retryConfig: this.retryConfig,
@@ -262,20 +384,106 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
262
384
  return [this.getFunction(), ...this.getNestedFunctions(this.executionGraph.steps)];
263
385
  }
264
386
  };
265
- function cloneWorkflow(workflow, opts) {
266
- const wf = new InngestWorkflow(
267
- {
268
- id: opts.id,
269
- inputSchema: workflow.inputSchema,
270
- outputSchema: workflow.outputSchema,
271
- steps: workflow.stepDefs,
272
- mastra: workflow.mastra
273
- },
274
- workflow.inngest
275
- );
276
- wf.setStepFlow(workflow.stepGraph);
277
- wf.commit();
278
- return wf;
387
+ function isAgent(params) {
388
+ return params?.component === "AGENT";
389
+ }
390
+ function isTool(params) {
391
+ return params instanceof Tool;
392
+ }
393
+ function createStep(params) {
394
+ if (isAgent(params)) {
395
+ return {
396
+ id: params.name,
397
+ // @ts-ignore
398
+ inputSchema: z.object({
399
+ prompt: z.string()
400
+ // resourceId: z.string().optional(),
401
+ // threadId: z.string().optional(),
402
+ }),
403
+ // @ts-ignore
404
+ outputSchema: z.object({
405
+ text: z.string()
406
+ }),
407
+ execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext }) => {
408
+ let streamPromise = {};
409
+ streamPromise.promise = new Promise((resolve, reject) => {
410
+ streamPromise.resolve = resolve;
411
+ streamPromise.reject = reject;
412
+ });
413
+ const toolData = {
414
+ name: params.name,
415
+ args: inputData
416
+ };
417
+ await emitter.emit("watch-v2", {
418
+ type: "tool-call-streaming-start",
419
+ ...toolData
420
+ });
421
+ const { fullStream } = await params.stream(inputData.prompt, {
422
+ // resourceId: inputData.resourceId,
423
+ // threadId: inputData.threadId,
424
+ runtimeContext,
425
+ onFinish: (result) => {
426
+ streamPromise.resolve(result.text);
427
+ }
428
+ });
429
+ for await (const chunk of fullStream) {
430
+ switch (chunk.type) {
431
+ case "text-delta":
432
+ await emitter.emit("watch-v2", {
433
+ type: "tool-call-delta",
434
+ ...toolData,
435
+ argsTextDelta: chunk.textDelta
436
+ });
437
+ break;
438
+ case "step-start":
439
+ case "step-finish":
440
+ case "finish":
441
+ break;
442
+ case "tool-call":
443
+ case "tool-result":
444
+ case "tool-call-streaming-start":
445
+ case "tool-call-delta":
446
+ case "source":
447
+ case "file":
448
+ default:
449
+ await emitter.emit("watch-v2", chunk);
450
+ break;
451
+ }
452
+ }
453
+ return {
454
+ text: await streamPromise.promise
455
+ };
456
+ }
457
+ };
458
+ }
459
+ if (isTool(params)) {
460
+ if (!params.inputSchema || !params.outputSchema) {
461
+ throw new Error("Tool must have input and output schemas defined");
462
+ }
463
+ return {
464
+ // TODO: tool probably should have strong id type
465
+ // @ts-ignore
466
+ id: params.id,
467
+ inputSchema: params.inputSchema,
468
+ outputSchema: params.outputSchema,
469
+ execute: async ({ inputData, mastra, runtimeContext }) => {
470
+ return params.execute({
471
+ context: inputData,
472
+ mastra,
473
+ runtimeContext
474
+ });
475
+ }
476
+ };
477
+ }
478
+ return {
479
+ id: params.id,
480
+ description: params.description,
481
+ inputSchema: params.inputSchema,
482
+ outputSchema: params.outputSchema,
483
+ resumeSchema: params.resumeSchema,
484
+ suspendSchema: params.suspendSchema,
485
+ execute: params.execute
486
+ };
279
487
  }
280
488
  function init(inngest) {
281
489
  return {
@@ -283,8 +491,27 @@ function init(inngest) {
283
491
  return new InngestWorkflow(params, inngest);
284
492
  },
285
493
  createStep,
286
- cloneStep,
287
- cloneWorkflow
494
+ cloneStep(step, opts) {
495
+ return {
496
+ id: opts.id,
497
+ description: step.description,
498
+ inputSchema: step.inputSchema,
499
+ outputSchema: step.outputSchema,
500
+ execute: step.execute
501
+ };
502
+ },
503
+ cloneWorkflow(workflow, opts) {
504
+ const wf = new Workflow({
505
+ id: opts.id,
506
+ inputSchema: workflow.inputSchema,
507
+ outputSchema: workflow.outputSchema,
508
+ steps: workflow.stepDefs,
509
+ mastra: workflow.mastra
510
+ });
511
+ wf.setStepFlow(workflow.stepGraph);
512
+ wf.commit();
513
+ return wf;
514
+ }
288
515
  };
289
516
  }
290
517
  var InngestExecutionEngine = class extends DefaultExecutionEngine {
@@ -295,6 +522,18 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
295
522
  this.inngestStep = inngestStep;
296
523
  this.inngestAttempts = inngestAttempts;
297
524
  }
525
+ async execute(params) {
526
+ await params.emitter.emit("watch-v2", {
527
+ type: "start",
528
+ payload: { runId: params.runId }
529
+ });
530
+ const result = await super.execute(params);
531
+ await params.emitter.emit("watch-v2", {
532
+ type: "finish",
533
+ payload: { runId: params.runId }
534
+ });
535
+ return result;
536
+ }
298
537
  async fmtReturnValue(executionSpan, emitter, stepResults, lastOutput, error) {
299
538
  const base = {
300
539
  status: lastOutput.status,
@@ -375,6 +614,19 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
375
614
  runtimeContext
376
615
  });
377
616
  }
617
+ async executeSleep({ id, duration }) {
618
+ await this.inngestStep.sleep(id, duration);
619
+ }
620
+ async executeWaitForEvent({ event, timeout }) {
621
+ const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
622
+ event: `user-event-${event}`,
623
+ timeout: timeout ?? 5e3
624
+ });
625
+ if (eventData === null) {
626
+ throw "Timeout waiting for event";
627
+ }
628
+ return eventData?.data;
629
+ }
378
630
  async executeStep({
379
631
  step,
380
632
  stepResults,
@@ -384,9 +636,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
384
636
  emitter,
385
637
  runtimeContext
386
638
  }) {
387
- await this.inngestStep.run(
639
+ const startedAt = await this.inngestStep.run(
388
640
  `workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
389
641
  async () => {
642
+ const startedAt2 = Date.now();
390
643
  await emitter.emit("watch", {
391
644
  type: "watch",
392
645
  payload: {
@@ -408,6 +661,13 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
408
661
  },
409
662
  eventTimestamp: Date.now()
410
663
  });
664
+ await emitter.emit("watch-v2", {
665
+ type: "step-start",
666
+ payload: {
667
+ id: step.id
668
+ }
669
+ });
670
+ return startedAt2;
411
671
  }
412
672
  );
413
673
  if (step instanceof InngestWorkflow) {
@@ -468,6 +728,13 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
468
728
  },
469
729
  eventTimestamp: Date.now()
470
730
  });
731
+ await emitter.emit("watch-v2", {
732
+ type: "step-result",
733
+ payload: {
734
+ id: step.id,
735
+ status: "failed"
736
+ }
737
+ });
471
738
  return { executionContext, result: { status: "failed", error: result?.error } };
472
739
  } else if (result.status === "suspended") {
473
740
  const suspendedSteps = Object.entries(result.steps).filter(([_stepName, stepResult]) => {
@@ -494,6 +761,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
494
761
  },
495
762
  eventTimestamp: Date.now()
496
763
  });
764
+ await emitter.emit("watch-v2", {
765
+ type: "step-suspended",
766
+ payload: {
767
+ id: step.id
768
+ }
769
+ });
497
770
  return {
498
771
  executionContext,
499
772
  result: {
@@ -544,6 +817,13 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
544
817
  },
545
818
  eventTimestamp: Date.now()
546
819
  });
820
+ await emitter.emit("watch-v2", {
821
+ type: "step-finish",
822
+ payload: {
823
+ id: step.id,
824
+ metadata: {}
825
+ }
826
+ });
547
827
  return { executionContext, result: { status: "success", output: result?.result } };
548
828
  }
549
829
  );
@@ -553,8 +833,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
553
833
  const stepRes = await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}`, async () => {
554
834
  let execResults;
555
835
  let suspended;
836
+ let bailed;
556
837
  try {
557
838
  const result = await step.execute({
839
+ runId: executionContext.runId,
558
840
  mastra: this.mastra,
559
841
  runtimeContext,
560
842
  inputData: prevOutput,
@@ -571,20 +853,53 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
571
853
  executionContext.suspendedPaths[step.id] = executionContext.executionPath;
572
854
  suspended = { payload: suspendPayload };
573
855
  },
856
+ bail: (result2) => {
857
+ bailed = { payload: result2 };
858
+ },
574
859
  resume: {
575
860
  steps: resume?.steps?.slice(1) || [],
576
861
  resumePayload: resume?.resumePayload,
577
862
  // @ts-ignore
578
863
  runId: stepResults[step.id]?.payload?.__workflow_meta?.runId
579
864
  },
580
- emitter
865
+ [EMITTER_SYMBOL]: emitter,
866
+ engine: {
867
+ step: this.inngestStep
868
+ }
581
869
  });
582
- execResults = { status: "success", output: result };
870
+ const endedAt = Date.now();
871
+ execResults = {
872
+ status: "success",
873
+ output: result,
874
+ startedAt,
875
+ endedAt,
876
+ payload: prevOutput,
877
+ resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
878
+ resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
879
+ };
583
880
  } catch (e) {
584
- execResults = { status: "failed", error: e instanceof Error ? e.message : String(e) };
881
+ execResults = {
882
+ status: "failed",
883
+ payload: prevOutput,
884
+ error: e instanceof Error ? e.message : String(e),
885
+ endedAt: Date.now(),
886
+ startedAt,
887
+ resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
888
+ resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
889
+ };
585
890
  }
586
891
  if (suspended) {
587
- execResults = { status: "suspended", payload: suspended.payload };
892
+ execResults = {
893
+ status: "suspended",
894
+ suspendedPayload: suspended.payload,
895
+ payload: prevOutput,
896
+ suspendedAt: Date.now(),
897
+ startedAt,
898
+ resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
899
+ resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
900
+ };
901
+ } else if (bailed) {
902
+ execResults = { status: "bailed", output: bailed.payload, payload: prevOutput, endedAt: Date.now(), startedAt };
588
903
  }
589
904
  if (execResults.status === "failed") {
590
905
  if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
@@ -596,18 +911,43 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
596
911
  payload: {
597
912
  currentStep: {
598
913
  id: step.id,
599
- status: execResults.status,
600
- output: execResults.output
914
+ ...execResults
601
915
  },
602
916
  workflowState: {
603
917
  status: "running",
604
- steps: stepResults,
918
+ steps: { ...stepResults, [step.id]: execResults },
605
919
  result: null,
606
920
  error: null
607
921
  }
608
922
  },
609
923
  eventTimestamp: Date.now()
610
924
  });
925
+ if (execResults.status === "suspended") {
926
+ await emitter.emit("watch-v2", {
927
+ type: "step-suspended",
928
+ payload: {
929
+ id: step.id,
930
+ status: execResults.status,
931
+ output: execResults.status === "success" ? execResults?.output : void 0
932
+ }
933
+ });
934
+ } else {
935
+ await emitter.emit("watch-v2", {
936
+ type: "step-result",
937
+ payload: {
938
+ id: step.id,
939
+ status: execResults.status,
940
+ output: execResults.status === "success" ? execResults?.output : void 0
941
+ }
942
+ });
943
+ await emitter.emit("watch-v2", {
944
+ type: "step-finish",
945
+ payload: {
946
+ id: step.id,
947
+ metadata: {}
948
+ }
949
+ });
950
+ }
611
951
  return { result: execResults, executionContext, stepResults };
612
952
  });
613
953
  Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
@@ -618,7 +958,11 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
618
958
  workflowId,
619
959
  runId,
620
960
  stepResults,
621
- executionContext
961
+ executionContext,
962
+ serializedStepGraph,
963
+ workflowStatus,
964
+ result,
965
+ error
622
966
  }) {
623
967
  await this.inngestStep.run(
624
968
  `workflow.${workflowId}.run.${runId}.path.${JSON.stringify(executionContext.executionPath)}.stepUpdate`,
@@ -632,6 +976,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
632
976
  context: stepResults,
633
977
  activePaths: [],
634
978
  suspendedPaths: executionContext.suspendedPaths,
979
+ serializedStepGraph,
980
+ status: workflowStatus,
981
+ result,
982
+ error,
635
983
  // @ts-ignore
636
984
  timestamp: Date.now()
637
985
  }
@@ -646,6 +994,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
646
994
  prevOutput,
647
995
  prevStep,
648
996
  stepResults,
997
+ serializedStepGraph,
649
998
  resume,
650
999
  executionContext,
651
1000
  emitter,
@@ -657,6 +1006,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
657
1006
  (cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
658
1007
  try {
659
1008
  const result = await cond({
1009
+ runId,
660
1010
  mastra: this.mastra,
661
1011
  runtimeContext,
662
1012
  inputData: prevOutput,
@@ -674,7 +1024,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
674
1024
  // TODO: this function shouldn't have suspend probably?
675
1025
  suspend: async (_suspendPayload) => {
676
1026
  },
677
- [EMITTER_SYMBOL]: emitter
1027
+ bail: () => {
1028
+ },
1029
+ [EMITTER_SYMBOL]: emitter,
1030
+ engine: {
1031
+ step: this.inngestStep
1032
+ }
678
1033
  });
679
1034
  return result ? index : null;
680
1035
  } catch (e) {
@@ -693,6 +1048,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
693
1048
  prevStep,
694
1049
  stepResults,
695
1050
  resume,
1051
+ serializedStepGraph,
696
1052
  executionContext: {
697
1053
  workflowId,
698
1054
  runId,
@@ -706,17 +1062,17 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
706
1062
  })
707
1063
  )
708
1064
  );
709
- const hasFailed = results.find((result) => result.status === "failed");
710
- const hasSuspended = results.find((result) => result.status === "suspended");
1065
+ const hasFailed = results.find((result) => result.result.status === "failed");
1066
+ const hasSuspended = results.find((result) => result.result.status === "suspended");
711
1067
  if (hasFailed) {
712
- execResults = { status: "failed", error: hasFailed.error };
1068
+ execResults = { status: "failed", error: hasFailed.result.error };
713
1069
  } else if (hasSuspended) {
714
- execResults = { status: "suspended", payload: hasSuspended.payload };
1070
+ execResults = { status: "suspended", payload: hasSuspended.result.suspendPayload };
715
1071
  } else {
716
1072
  execResults = {
717
1073
  status: "success",
718
1074
  output: results.reduce((acc, result, index) => {
719
- if (result.status === "success") {
1075
+ if (result.result.status === "success") {
720
1076
  acc[stepsToRun[index].step.id] = result.output;
721
1077
  }
722
1078
  return acc;
@@ -727,4 +1083,4 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
727
1083
  }
728
1084
  };
729
1085
 
730
- export { InngestExecutionEngine, InngestRun, InngestWorkflow, init, serve };
1086
+ export { InngestExecutionEngine, InngestRun, InngestWorkflow, createStep, init, serve };