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