@mastra/inngest 0.0.0-error-handler-fix-20251020202607 → 0.0.0-export-agent-memory-from-local-studio-20251112153946

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
@@ -1,9 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  var crypto = require('crypto');
4
+ var web = require('stream/web');
4
5
  var realtime = require('@inngest/realtime');
5
- var aiTracing = require('@mastra/core/ai-tracing');
6
6
  var di = require('@mastra/core/di');
7
+ var observability = require('@mastra/core/observability');
8
+ var stream = require('@mastra/core/stream');
7
9
  var tools = require('@mastra/core/tools');
8
10
  var workflows = require('@mastra/core/workflows');
9
11
  var _constants = require('@mastra/core/workflows/_constants');
@@ -18,7 +20,7 @@ function serve({
18
20
  functions: userFunctions = [],
19
21
  registerOptions
20
22
  }) {
21
- const wfs = mastra.getWorkflows();
23
+ const wfs = mastra.listWorkflows();
22
24
  const workflowFunctions = Array.from(
23
25
  new Set(
24
26
  Object.values(wfs).flatMap((wf) => {
@@ -57,11 +59,12 @@ var InngestRun = class extends workflows.Run {
57
59
  }
58
60
  async getRunOutput(eventId) {
59
61
  let runs = await this.getRuns(eventId);
62
+ const storage = this.#mastra?.getStorage();
60
63
  while (runs?.[0]?.status !== "Completed" || runs?.[0]?.event_id !== eventId) {
61
64
  await new Promise((resolve) => setTimeout(resolve, 1e3));
62
65
  runs = await this.getRuns(eventId);
63
66
  if (runs?.[0]?.status === "Failed") {
64
- const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
67
+ const snapshot = await storage?.loadWorkflowSnapshot({
65
68
  workflowName: this.workflowId,
66
69
  runId: this.runId
67
70
  });
@@ -70,7 +73,7 @@ var InngestRun = class extends workflows.Run {
70
73
  };
71
74
  }
72
75
  if (runs?.[0]?.status === "Cancelled") {
73
- const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
76
+ const snapshot = await storage?.loadWorkflowSnapshot({
74
77
  workflowName: this.workflowId,
75
78
  runId: this.runId
76
79
  });
@@ -79,38 +82,40 @@ var InngestRun = class extends workflows.Run {
79
82
  }
80
83
  return runs?.[0];
81
84
  }
82
- async sendEvent(event, data) {
83
- await this.inngest.send({
84
- name: `user-event-${event}`,
85
- data
86
- });
87
- }
88
85
  async cancel() {
86
+ const storage = this.#mastra?.getStorage();
89
87
  await this.inngest.send({
90
88
  name: `cancel.workflow.${this.workflowId}`,
91
89
  data: {
92
90
  runId: this.runId
93
91
  }
94
92
  });
95
- const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
93
+ const snapshot = await storage?.loadWorkflowSnapshot({
96
94
  workflowName: this.workflowId,
97
95
  runId: this.runId
98
96
  });
99
97
  if (snapshot) {
100
- await this.#mastra?.storage?.persistWorkflowSnapshot({
98
+ await storage?.persistWorkflowSnapshot({
101
99
  workflowName: this.workflowId,
102
100
  runId: this.runId,
103
101
  resourceId: this.resourceId,
104
102
  snapshot: {
105
103
  ...snapshot,
106
- status: "canceled"
104
+ status: "canceled",
105
+ value: snapshot.value
107
106
  }
108
107
  });
109
108
  }
110
109
  }
111
- async start({
110
+ async start(params) {
111
+ return this._start(params);
112
+ }
113
+ async _start({
112
114
  inputData,
113
- initialState
115
+ initialState,
116
+ outputOptions,
117
+ tracingOptions,
118
+ format
114
119
  }) {
115
120
  await this.#mastra.getStorage()?.persistWorkflowSnapshot({
116
121
  workflowName: this.workflowId,
@@ -119,14 +124,15 @@ var InngestRun = class extends workflows.Run {
119
124
  snapshot: {
120
125
  runId: this.runId,
121
126
  serializedStepGraph: this.serializedStepGraph,
127
+ status: "running",
122
128
  value: {},
123
129
  context: {},
124
130
  activePaths: [],
125
131
  suspendedPaths: {},
132
+ activeStepsPath: {},
126
133
  resumeLabels: {},
127
134
  waitingPaths: {},
128
- timestamp: Date.now(),
129
- status: "running"
135
+ timestamp: Date.now()
130
136
  }
131
137
  });
132
138
  const inputDataToUse = await this._validateInput(inputData);
@@ -137,7 +143,10 @@ var InngestRun = class extends workflows.Run {
137
143
  inputData: inputDataToUse,
138
144
  initialState: initialStateToUse,
139
145
  runId: this.runId,
140
- resourceId: this.resourceId
146
+ resourceId: this.resourceId,
147
+ outputOptions,
148
+ tracingOptions,
149
+ format
141
150
  }
142
151
  });
143
152
  const eventId = eventOutput.ids[0];
@@ -166,10 +175,11 @@ var InngestRun = class extends workflows.Run {
166
175
  return p;
167
176
  }
168
177
  async _resume(params) {
178
+ const storage = this.#mastra?.getStorage();
169
179
  const steps = (Array.isArray(params.step) ? params.step : [params.step]).map(
170
180
  (step) => typeof step === "string" ? step : step?.id
171
181
  );
172
- const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
182
+ const snapshot = await storage?.loadWorkflowSnapshot({
173
183
  workflowName: this.workflowId,
174
184
  runId: this.runId
175
185
  });
@@ -203,12 +213,12 @@ var InngestRun = class extends workflows.Run {
203
213
  }
204
214
  return result;
205
215
  }
206
- watch(cb, type = "watch") {
216
+ watch(cb) {
207
217
  let active = true;
208
218
  const streamPromise = realtime.subscribe(
209
219
  {
210
220
  channel: `workflow:${this.workflowId}:${this.runId}`,
211
- topics: [type],
221
+ topics: ["watch"],
212
222
  app: this.inngest
213
223
  },
214
224
  (message) => {
@@ -226,20 +236,35 @@ var InngestRun = class extends workflows.Run {
226
236
  });
227
237
  };
228
238
  }
229
- stream({ inputData, runtimeContext } = {}) {
239
+ streamLegacy({ inputData, requestContext } = {}) {
230
240
  const { readable, writable } = new TransformStream();
231
241
  const writer = writable.getWriter();
232
242
  const unwatch = this.watch(async (event) => {
233
243
  try {
244
+ await writer.write({
245
+ // @ts-ignore
246
+ type: "start",
247
+ // @ts-ignore
248
+ payload: { runId: this.runId }
249
+ });
234
250
  const e = {
235
251
  ...event,
236
252
  type: event.type.replace("workflow-", "")
237
253
  };
254
+ if (e.type === "step-output") {
255
+ e.type = e.payload.output.type;
256
+ e.payload = e.payload.output.payload;
257
+ }
238
258
  await writer.write(e);
239
259
  } catch {
240
260
  }
241
- }, "watch-v2");
261
+ });
242
262
  this.closeStreamAction = async () => {
263
+ await writer.write({
264
+ type: "finish",
265
+ // @ts-ignore
266
+ payload: { runId: this.runId }
267
+ });
243
268
  unwatch();
244
269
  try {
245
270
  await writer.close();
@@ -249,7 +274,7 @@ var InngestRun = class extends workflows.Run {
249
274
  writer.releaseLock();
250
275
  }
251
276
  };
252
- this.executionResults = this.start({ inputData, runtimeContext }).then((result) => {
277
+ this.executionResults = this._start({ inputData, requestContext, format: "legacy" }).then((result) => {
253
278
  if (result.status !== "suspended") {
254
279
  this.closeStreamAction?.().catch(() => {
255
280
  });
@@ -261,6 +286,82 @@ var InngestRun = class extends workflows.Run {
261
286
  getWorkflowState: () => this.executionResults
262
287
  };
263
288
  }
289
+ stream({
290
+ inputData,
291
+ requestContext,
292
+ tracingOptions,
293
+ closeOnSuspend = true,
294
+ initialState,
295
+ outputOptions
296
+ } = {}) {
297
+ if (this.closeStreamAction && this.streamOutput) {
298
+ return this.streamOutput;
299
+ }
300
+ this.closeStreamAction = async () => {
301
+ };
302
+ const self = this;
303
+ const stream$1 = new web.ReadableStream({
304
+ async start(controller) {
305
+ const unwatch = self.watch(async ({ type, from = stream.ChunkFrom.WORKFLOW, payload }) => {
306
+ controller.enqueue({
307
+ type,
308
+ runId: self.runId,
309
+ from,
310
+ payload: {
311
+ stepName: payload?.id,
312
+ ...payload
313
+ }
314
+ });
315
+ });
316
+ self.closeStreamAction = async () => {
317
+ unwatch();
318
+ try {
319
+ await controller.close();
320
+ } catch (err) {
321
+ console.error("Error closing stream:", err);
322
+ }
323
+ };
324
+ const executionResultsPromise = self._start({
325
+ inputData,
326
+ requestContext,
327
+ // tracingContext, // We are not able to pass a reference to a span here, what to do?
328
+ initialState,
329
+ tracingOptions,
330
+ outputOptions,
331
+ format: "vnext"
332
+ });
333
+ let executionResults;
334
+ try {
335
+ executionResults = await executionResultsPromise;
336
+ if (closeOnSuspend) {
337
+ self.closeStreamAction?.().catch(() => {
338
+ });
339
+ } else if (executionResults.status !== "suspended") {
340
+ self.closeStreamAction?.().catch(() => {
341
+ });
342
+ }
343
+ if (self.streamOutput) {
344
+ self.streamOutput.updateResults(
345
+ executionResults
346
+ );
347
+ }
348
+ } catch (err) {
349
+ self.streamOutput?.rejectResults(err);
350
+ self.closeStreamAction?.().catch(() => {
351
+ });
352
+ }
353
+ }
354
+ });
355
+ this.streamOutput = new stream.WorkflowRunOutput({
356
+ runId: this.runId,
357
+ workflowId: this.workflowId,
358
+ stream: stream$1
359
+ });
360
+ return this.streamOutput;
361
+ }
362
+ streamVNext(args = {}) {
363
+ return this.stream(args);
364
+ }
264
365
  };
265
366
  var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
266
367
  #mastra;
@@ -270,6 +371,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
270
371
  constructor(params, inngest) {
271
372
  const { concurrency, rateLimit, throttle, debounce, priority, ...workflowParams } = params;
272
373
  super(workflowParams);
374
+ this.engineType = "inngest";
273
375
  const flowControlEntries = Object.entries({ concurrency, rateLimit, throttle, debounce, priority }).filter(
274
376
  ([_, value]) => value !== void 0
275
377
  );
@@ -277,13 +379,13 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
277
379
  this.#mastra = params.mastra;
278
380
  this.inngest = inngest;
279
381
  }
280
- async getWorkflowRuns(args) {
382
+ async listWorkflowRuns(args) {
281
383
  const storage = this.#mastra?.getStorage();
282
384
  if (!storage) {
283
385
  this.logger.debug("Cannot get workflow runs. Mastra engine is not initialized");
284
386
  return { runs: [], total: 0 };
285
387
  }
286
- return storage.getWorkflowRuns({ workflowName: this.id, ...args ?? {} });
388
+ return storage.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
287
389
  }
288
390
  async getWorkflowRunById(runId) {
289
391
  const storage = this.#mastra?.getStorage();
@@ -312,16 +414,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
312
414
  }
313
415
  }
314
416
  }
315
- /**
316
- * @deprecated Use createRunAsync() instead.
317
- * @throws {Error} Always throws an error directing users to use createRunAsync()
318
- */
319
- createRun(_options) {
320
- throw new Error(
321
- "createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = workflow.createRun();\n After: const run = await workflow.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
322
- );
323
- }
324
- async createRunAsync(options) {
417
+ async createRun(options) {
325
418
  const runIdToUse = options?.runId || crypto.randomUUID();
326
419
  const run = this.runs.get(runIdToUse) ?? new InngestRun(
327
420
  {
@@ -334,7 +427,8 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
334
427
  mastra: this.#mastra,
335
428
  retryConfig: this.retryConfig,
336
429
  cleanup: () => this.runs.delete(runIdToUse),
337
- workflowSteps: this.steps
430
+ workflowSteps: this.steps,
431
+ workflowEngineType: this.engineType
338
432
  },
339
433
  this.inngest
340
434
  );
@@ -355,6 +449,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
355
449
  value: {},
356
450
  context: {},
357
451
  activePaths: [],
452
+ activeStepsPath: {},
358
453
  waitingPaths: {},
359
454
  serializedStepGraph: this.serializedStepGraph,
360
455
  suspendedPaths: {},
@@ -383,7 +478,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
383
478
  },
384
479
  { event: `workflow.${this.id}` },
385
480
  async ({ event, step, attempt, publish }) => {
386
- let { inputData, initialState, runId, resourceId, resume, outputOptions } = event.data;
481
+ let { inputData, initialState, runId, resourceId, resume, outputOptions, format } = event.data;
387
482
  if (!runId) {
388
483
  runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
389
484
  return crypto.randomUUID();
@@ -422,13 +517,19 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
422
517
  initialState,
423
518
  emitter,
424
519
  retryConfig: this.retryConfig,
425
- runtimeContext: new di.RuntimeContext(),
520
+ requestContext: new di.RequestContext(),
426
521
  // TODO
427
522
  resume,
523
+ format,
428
524
  abortController: new AbortController(),
429
- currentSpan: void 0,
430
- // TODO: Pass actual parent AI span from workflow execution context
431
- outputOptions
525
+ // currentSpan: undefined, // TODO: Pass actual parent Span from workflow execution context
526
+ outputOptions,
527
+ writableStream: new web.WritableStream({
528
+ write(chunk) {
529
+ void emitter.emit("watch", chunk).catch(() => {
530
+ });
531
+ }
532
+ })
432
533
  });
433
534
  await step.run(`workflow.${this.id}.finalize`, async () => {
434
535
  if (result.status === "failed") {
@@ -466,7 +567,7 @@ function isAgent(params) {
466
567
  function isTool(params) {
467
568
  return params instanceof tools.Tool;
468
569
  }
469
- function createStep(params) {
570
+ function createStep(params, agentOptions) {
470
571
  if (isAgent(params)) {
471
572
  return {
472
573
  id: params.name,
@@ -474,12 +575,23 @@ function createStep(params) {
474
575
  // @ts-ignore
475
576
  inputSchema: zod.z.object({
476
577
  prompt: zod.z.string()
578
+ // resourceId: z.string().optional(),
579
+ // threadId: z.string().optional(),
477
580
  }),
478
581
  // @ts-ignore
479
582
  outputSchema: zod.z.object({
480
583
  text: zod.z.string()
481
584
  }),
482
- execute: async ({ inputData, [_constants.EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort, tracingContext }) => {
585
+ execute: async ({
586
+ inputData,
587
+ [_constants.EMITTER_SYMBOL]: emitter,
588
+ [_constants.STREAM_FORMAT_SYMBOL]: streamFormat,
589
+ requestContext,
590
+ tracingContext,
591
+ abortSignal,
592
+ abort,
593
+ writer
594
+ }) => {
483
595
  let streamPromise = {};
484
596
  streamPromise.promise = new Promise((resolve, reject) => {
485
597
  streamPromise.resolve = resolve;
@@ -489,61 +601,60 @@ function createStep(params) {
489
601
  name: params.name,
490
602
  args: inputData
491
603
  };
492
- if ((await params.getLLM()).getModel().specificationVersion === `v2`) {
493
- const { fullStream } = await params.stream(inputData.prompt, {
494
- runtimeContext,
604
+ let stream;
605
+ if ((await params.getModel()).specificationVersion === "v1") {
606
+ const { fullStream } = await params.streamLegacy(inputData.prompt, {
607
+ ...agentOptions ?? {},
608
+ // resourceId: inputData.resourceId,
609
+ // threadId: inputData.threadId,
610
+ requestContext,
495
611
  tracingContext,
496
612
  onFinish: (result) => {
497
613
  streamPromise.resolve(result.text);
614
+ void agentOptions?.onFinish?.(result);
498
615
  },
499
616
  abortSignal
500
617
  });
501
- if (abortSignal.aborted) {
502
- return abort();
503
- }
504
- await emitter.emit("watch-v2", {
505
- type: "tool-call-streaming-start",
506
- ...toolData ?? {}
507
- });
508
- for await (const chunk of fullStream) {
509
- if (chunk.type === "text-delta") {
510
- await emitter.emit("watch-v2", {
511
- type: "tool-call-delta",
512
- ...toolData ?? {},
513
- argsTextDelta: chunk.payload.text
514
- });
515
- }
516
- }
618
+ stream = fullStream;
517
619
  } else {
518
- const { fullStream } = await params.streamLegacy(inputData.prompt, {
519
- runtimeContext,
620
+ const modelOutput = await params.stream(inputData.prompt, {
621
+ ...agentOptions ?? {},
622
+ requestContext,
520
623
  tracingContext,
521
624
  onFinish: (result) => {
522
625
  streamPromise.resolve(result.text);
626
+ void agentOptions?.onFinish?.(result);
523
627
  },
524
628
  abortSignal
525
629
  });
526
- if (abortSignal.aborted) {
527
- return abort();
528
- }
529
- await emitter.emit("watch-v2", {
630
+ stream = modelOutput.fullStream;
631
+ }
632
+ if (streamFormat === "legacy") {
633
+ await emitter.emit("watch", {
530
634
  type: "tool-call-streaming-start",
531
635
  ...toolData ?? {}
532
636
  });
533
- for await (const chunk of fullStream) {
637
+ for await (const chunk of stream) {
534
638
  if (chunk.type === "text-delta") {
535
- await emitter.emit("watch-v2", {
639
+ await emitter.emit("watch", {
536
640
  type: "tool-call-delta",
537
641
  ...toolData ?? {},
538
642
  argsTextDelta: chunk.textDelta
539
643
  });
540
644
  }
541
645
  }
646
+ await emitter.emit("watch", {
647
+ type: "tool-call-streaming-finish",
648
+ ...toolData ?? {}
649
+ });
650
+ } else {
651
+ for await (const chunk of stream) {
652
+ await writer.write(chunk);
653
+ }
654
+ }
655
+ if (abortSignal.aborted) {
656
+ return abort();
542
657
  }
543
- await emitter.emit("watch-v2", {
544
- type: "tool-call-streaming-finish",
545
- ...toolData ?? {}
546
- });
547
658
  return {
548
659
  text: await streamPromise.promise
549
660
  };
@@ -562,11 +673,11 @@ function createStep(params) {
562
673
  description: params.description,
563
674
  inputSchema: params.inputSchema,
564
675
  outputSchema: params.outputSchema,
565
- execute: async ({ inputData, mastra, runtimeContext, tracingContext, suspend, resumeData }) => {
676
+ execute: async ({ inputData, mastra, requestContext, tracingContext, suspend, resumeData }) => {
566
677
  return params.execute({
567
678
  context: inputData,
568
- mastra: aiTracing.wrapMastra(mastra, tracingContext),
569
- runtimeContext,
679
+ mastra: observability.wrapMastra(mastra, tracingContext),
680
+ requestContext,
570
681
  tracingContext,
571
682
  suspend,
572
683
  resumeData
@@ -629,63 +740,16 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
629
740
  this.inngestStep = inngestStep;
630
741
  this.inngestAttempts = inngestAttempts;
631
742
  }
632
- async execute(params) {
633
- await params.emitter.emit("watch-v2", {
634
- type: "workflow-start",
635
- payload: { runId: params.runId }
636
- });
637
- const result = await super.execute(params);
638
- await params.emitter.emit("watch-v2", {
639
- type: "workflow-finish",
640
- payload: { runId: params.runId }
641
- });
642
- return result;
643
- }
644
- async fmtReturnValue(executionSpan, emitter, stepResults, lastOutput, error) {
743
+ async fmtReturnValue(emitter, stepResults, lastOutput, error) {
645
744
  const base = {
646
745
  status: lastOutput.status,
647
746
  steps: stepResults
648
747
  };
649
748
  if (lastOutput.status === "success") {
650
- await emitter.emit("watch", {
651
- type: "watch",
652
- payload: {
653
- workflowState: {
654
- status: lastOutput.status,
655
- steps: stepResults,
656
- result: lastOutput.output
657
- }
658
- },
659
- eventTimestamp: Date.now()
660
- });
661
749
  base.result = lastOutput.output;
662
750
  } else if (lastOutput.status === "failed") {
663
751
  base.error = error instanceof Error ? error?.stack ?? error.message : lastOutput?.error instanceof Error ? lastOutput.error.message : lastOutput.error ?? error ?? "Unknown error";
664
- await emitter.emit("watch", {
665
- type: "watch",
666
- payload: {
667
- workflowState: {
668
- status: lastOutput.status,
669
- steps: stepResults,
670
- result: null,
671
- error: base.error
672
- }
673
- },
674
- eventTimestamp: Date.now()
675
- });
676
752
  } else if (lastOutput.status === "suspended") {
677
- await emitter.emit("watch", {
678
- type: "watch",
679
- payload: {
680
- workflowState: {
681
- status: lastOutput.status,
682
- steps: stepResults,
683
- result: null,
684
- error: null
685
- }
686
- },
687
- eventTimestamp: Date.now()
688
- });
689
753
  const suspendedStepIds = Object.entries(stepResults).flatMap(([stepId, stepResult]) => {
690
754
  if (stepResult?.status === "suspended") {
691
755
  const nestedPath = stepResult?.suspendPayload?.__workflow_meta?.path;
@@ -695,7 +759,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
695
759
  });
696
760
  base.suspended = suspendedStepIds;
697
761
  }
698
- executionSpan?.end();
699
762
  return base;
700
763
  }
701
764
  // async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
@@ -709,14 +772,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
709
772
  stepResults,
710
773
  emitter,
711
774
  abortController,
712
- runtimeContext,
775
+ requestContext,
713
776
  executionContext,
714
777
  writableStream,
715
778
  tracingContext
716
779
  }) {
717
780
  let { duration, fn } = entry;
718
781
  const sleepSpan = tracingContext?.currentSpan?.createChildSpan({
719
- type: aiTracing.AISpanType.WORKFLOW_SLEEP,
782
+ type: observability.SpanType.WORKFLOW_SLEEP,
720
783
  name: `sleep: ${duration ? `${duration}ms` : "dynamic"}`,
721
784
  attributes: {
722
785
  durationMs: duration,
@@ -727,45 +790,53 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
727
790
  if (fn) {
728
791
  const stepCallId = crypto.randomUUID();
729
792
  duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
730
- return await fn({
731
- runId,
732
- workflowId,
733
- mastra: this.mastra,
734
- runtimeContext,
735
- inputData: prevOutput,
736
- state: executionContext.state,
737
- setState: (state) => {
738
- executionContext.state = state;
739
- },
740
- runCount: -1,
741
- tracingContext: {
742
- currentSpan: sleepSpan
743
- },
744
- getInitData: () => stepResults?.input,
745
- getStepResult: workflows.getStepResult.bind(this, stepResults),
746
- // TODO: this function shouldn't have suspend probably?
747
- suspend: async (_suspendPayload) => {
748
- },
749
- bail: () => {
750
- },
751
- abort: () => {
752
- abortController?.abort();
753
- },
754
- [_constants.EMITTER_SYMBOL]: emitter,
755
- // TODO: add streamVNext support
756
- [_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
757
- engine: { step: this.inngestStep },
758
- abortSignal: abortController?.signal,
759
- writer: new tools.ToolStream(
793
+ return await fn(
794
+ workflows.createDeprecationProxy(
760
795
  {
761
- prefix: "workflow-step",
762
- callId: stepCallId,
763
- name: "sleep",
764
- runId
796
+ runId,
797
+ workflowId,
798
+ mastra: this.mastra,
799
+ requestContext,
800
+ inputData: prevOutput,
801
+ state: executionContext.state,
802
+ setState: (state) => {
803
+ executionContext.state = state;
804
+ },
805
+ retryCount: -1,
806
+ tracingContext: {
807
+ currentSpan: sleepSpan
808
+ },
809
+ getInitData: () => stepResults?.input,
810
+ getStepResult: workflows.getStepResult.bind(this, stepResults),
811
+ // TODO: this function shouldn't have suspend probably?
812
+ suspend: async (_suspendPayload) => {
813
+ },
814
+ bail: () => {
815
+ },
816
+ abort: () => {
817
+ abortController?.abort();
818
+ },
819
+ [_constants.EMITTER_SYMBOL]: emitter,
820
+ [_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
821
+ engine: { step: this.inngestStep },
822
+ abortSignal: abortController?.signal,
823
+ writer: new tools.ToolStream(
824
+ {
825
+ prefix: "workflow-step",
826
+ callId: stepCallId,
827
+ name: "sleep",
828
+ runId
829
+ },
830
+ writableStream
831
+ )
765
832
  },
766
- writableStream
833
+ {
834
+ paramName: "runCount",
835
+ deprecationMessage: workflows.runCountDeprecationMessage,
836
+ logger: this.logger
837
+ }
767
838
  )
768
- });
839
+ );
769
840
  });
770
841
  sleepSpan?.update({
771
842
  attributes: {
@@ -789,14 +860,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
789
860
  stepResults,
790
861
  emitter,
791
862
  abortController,
792
- runtimeContext,
863
+ requestContext,
793
864
  executionContext,
794
865
  writableStream,
795
866
  tracingContext
796
867
  }) {
797
868
  let { date, fn } = entry;
798
869
  const sleepUntilSpan = tracingContext?.currentSpan?.createChildSpan({
799
- type: aiTracing.AISpanType.WORKFLOW_SLEEP,
870
+ type: observability.SpanType.WORKFLOW_SLEEP,
800
871
  name: `sleepUntil: ${date ? date.toISOString() : "dynamic"}`,
801
872
  attributes: {
802
873
  untilDate: date,
@@ -808,45 +879,53 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
808
879
  if (fn) {
809
880
  date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
810
881
  const stepCallId = crypto.randomUUID();
811
- return await fn({
812
- runId,
813
- workflowId,
814
- mastra: this.mastra,
815
- runtimeContext,
816
- inputData: prevOutput,
817
- state: executionContext.state,
818
- setState: (state) => {
819
- executionContext.state = state;
820
- },
821
- runCount: -1,
822
- tracingContext: {
823
- currentSpan: sleepUntilSpan
824
- },
825
- getInitData: () => stepResults?.input,
826
- getStepResult: workflows.getStepResult.bind(this, stepResults),
827
- // TODO: this function shouldn't have suspend probably?
828
- suspend: async (_suspendPayload) => {
829
- },
830
- bail: () => {
831
- },
832
- abort: () => {
833
- abortController?.abort();
834
- },
835
- [_constants.EMITTER_SYMBOL]: emitter,
836
- [_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
837
- // TODO: add streamVNext support
838
- engine: { step: this.inngestStep },
839
- abortSignal: abortController?.signal,
840
- writer: new tools.ToolStream(
882
+ return await fn(
883
+ workflows.createDeprecationProxy(
841
884
  {
842
- prefix: "workflow-step",
843
- callId: stepCallId,
844
- name: "sleep",
845
- runId
885
+ runId,
886
+ workflowId,
887
+ mastra: this.mastra,
888
+ requestContext,
889
+ inputData: prevOutput,
890
+ state: executionContext.state,
891
+ setState: (state) => {
892
+ executionContext.state = state;
893
+ },
894
+ retryCount: -1,
895
+ tracingContext: {
896
+ currentSpan: sleepUntilSpan
897
+ },
898
+ getInitData: () => stepResults?.input,
899
+ getStepResult: workflows.getStepResult.bind(this, stepResults),
900
+ // TODO: this function shouldn't have suspend probably?
901
+ suspend: async (_suspendPayload) => {
902
+ },
903
+ bail: () => {
904
+ },
905
+ abort: () => {
906
+ abortController?.abort();
907
+ },
908
+ [_constants.EMITTER_SYMBOL]: emitter,
909
+ [_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
910
+ engine: { step: this.inngestStep },
911
+ abortSignal: abortController?.signal,
912
+ writer: new tools.ToolStream(
913
+ {
914
+ prefix: "workflow-step",
915
+ callId: stepCallId,
916
+ name: "sleep",
917
+ runId
918
+ },
919
+ writableStream
920
+ )
846
921
  },
847
- writableStream
922
+ {
923
+ paramName: "runCount",
924
+ deprecationMessage: workflows.runCountDeprecationMessage,
925
+ logger: this.logger
926
+ }
848
927
  )
849
- });
928
+ );
850
929
  });
851
930
  if (date && !(date instanceof Date)) {
852
931
  date = new Date(date);
@@ -870,16 +949,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
870
949
  throw e;
871
950
  }
872
951
  }
873
- async executeWaitForEvent({ event, timeout }) {
874
- const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
875
- event: `user-event-${event}`,
876
- timeout: timeout ?? 5e3
877
- });
878
- if (eventData === null) {
879
- throw "Timeout waiting for event";
880
- }
881
- return eventData?.data;
882
- }
883
952
  async executeStep({
884
953
  step,
885
954
  stepResults,
@@ -888,14 +957,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
888
957
  prevOutput,
889
958
  emitter,
890
959
  abortController,
891
- runtimeContext,
960
+ requestContext,
892
961
  tracingContext,
893
962
  writableStream,
894
963
  disableScorers
895
964
  }) {
896
- const stepAISpan = tracingContext?.currentSpan?.createChildSpan({
965
+ const stepSpan = tracingContext?.currentSpan?.createChildSpan({
897
966
  name: `workflow step: '${step.id}'`,
898
- type: aiTracing.AISpanType.WORKFLOW_STEP,
967
+ type: observability.SpanType.WORKFLOW_STEP,
899
968
  input: prevOutput,
900
969
  attributes: {
901
970
  stepId: step.id
@@ -912,27 +981,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
912
981
  async () => {
913
982
  const startedAt2 = Date.now();
914
983
  await emitter.emit("watch", {
915
- type: "watch",
916
- payload: {
917
- currentStep: {
918
- id: step.id,
919
- status: "running"
920
- },
921
- workflowState: {
922
- status: "running",
923
- steps: {
924
- ...stepResults,
925
- [step.id]: {
926
- status: "running"
927
- }
928
- },
929
- result: null,
930
- error: null
931
- }
932
- },
933
- eventTimestamp: Date.now()
934
- });
935
- await emitter.emit("watch-v2", {
936
984
  type: "workflow-step-start",
937
985
  payload: {
938
986
  id: step.id,
@@ -1008,23 +1056,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1008
1056
  async () => {
1009
1057
  if (result.status === "failed") {
1010
1058
  await emitter.emit("watch", {
1011
- type: "watch",
1012
- payload: {
1013
- currentStep: {
1014
- id: step.id,
1015
- status: "failed",
1016
- error: result?.error
1017
- },
1018
- workflowState: {
1019
- status: "running",
1020
- steps: stepResults,
1021
- result: null,
1022
- error: null
1023
- }
1024
- },
1025
- eventTimestamp: Date.now()
1026
- });
1027
- await emitter.emit("watch-v2", {
1028
1059
  type: "workflow-step-result",
1029
1060
  payload: {
1030
1061
  id: step.id,
@@ -1043,27 +1074,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1043
1074
  const suspendPath = [stepName, ...stepResult?.suspendPayload?.__workflow_meta?.path ?? []];
1044
1075
  executionContext.suspendedPaths[step.id] = executionContext.executionPath;
1045
1076
  await emitter.emit("watch", {
1046
- type: "watch",
1047
- payload: {
1048
- currentStep: {
1049
- id: step.id,
1050
- status: "suspended",
1051
- payload: stepResult.payload,
1052
- suspendPayload: {
1053
- ...stepResult?.suspendPayload,
1054
- __workflow_meta: { runId, path: suspendPath }
1055
- }
1056
- },
1057
- workflowState: {
1058
- status: "running",
1059
- steps: stepResults,
1060
- result: null,
1061
- error: null
1062
- }
1063
- },
1064
- eventTimestamp: Date.now()
1065
- });
1066
- await emitter.emit("watch-v2", {
1067
1077
  type: "workflow-step-suspended",
1068
1078
  payload: {
1069
1079
  id: step.id,
@@ -1082,23 +1092,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1082
1092
  }
1083
1093
  };
1084
1094
  }
1085
- await emitter.emit("watch", {
1086
- type: "watch",
1087
- payload: {
1088
- currentStep: {
1089
- id: step.id,
1090
- status: "suspended",
1091
- payload: {}
1092
- },
1093
- workflowState: {
1094
- status: "running",
1095
- steps: stepResults,
1096
- result: null,
1097
- error: null
1098
- }
1099
- },
1100
- eventTimestamp: Date.now()
1101
- });
1102
1095
  return {
1103
1096
  executionContext,
1104
1097
  result: {
@@ -1108,23 +1101,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1108
1101
  };
1109
1102
  }
1110
1103
  await emitter.emit("watch", {
1111
- type: "watch",
1112
- payload: {
1113
- currentStep: {
1114
- id: step.id,
1115
- status: "success",
1116
- output: result?.result
1117
- },
1118
- workflowState: {
1119
- status: "running",
1120
- steps: stepResults,
1121
- result: null,
1122
- error: null
1123
- }
1124
- },
1125
- eventTimestamp: Date.now()
1126
- });
1127
- await emitter.emit("watch-v2", {
1128
1104
  type: "workflow-step-result",
1129
1105
  payload: {
1130
1106
  id: step.id,
@@ -1132,7 +1108,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1132
1108
  output: result?.result
1133
1109
  }
1134
1110
  });
1135
- await emitter.emit("watch-v2", {
1111
+ await emitter.emit("watch", {
1136
1112
  type: "workflow-step-finish",
1137
1113
  payload: {
1138
1114
  id: step.id,
@@ -1152,6 +1128,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1152
1128
  resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
1153
1129
  };
1154
1130
  }
1131
+ const stepCallId = crypto.randomUUID();
1155
1132
  let stepRes;
1156
1133
  try {
1157
1134
  stepRes = await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}`, async () => {
@@ -1165,8 +1142,16 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1165
1142
  const result = await step.execute({
1166
1143
  runId: executionContext.runId,
1167
1144
  mastra: this.mastra,
1168
- runtimeContext,
1169
- writableStream,
1145
+ requestContext,
1146
+ writer: new tools.ToolStream(
1147
+ {
1148
+ prefix: "workflow-step",
1149
+ callId: stepCallId,
1150
+ name: step.id,
1151
+ runId: executionContext.runId
1152
+ },
1153
+ writableStream
1154
+ ),
1170
1155
  state: executionContext?.state ?? {},
1171
1156
  setState: (state) => {
1172
1157
  executionContext.state = state;
@@ -1174,14 +1159,20 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1174
1159
  inputData,
1175
1160
  resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
1176
1161
  tracingContext: {
1177
- currentSpan: stepAISpan
1162
+ currentSpan: stepSpan
1178
1163
  },
1179
1164
  getInitData: () => stepResults?.input,
1180
1165
  getStepResult: workflows.getStepResult.bind(this, stepResults),
1181
1166
  suspend: async (suspendPayload, suspendOptions) => {
1182
1167
  executionContext.suspendedPaths[step.id] = executionContext.executionPath;
1183
1168
  if (suspendOptions?.resumeLabel) {
1184
- executionContext.resumeLabels[suspendOptions.resumeLabel] = step.id;
1169
+ const resumeLabel = Array.isArray(suspendOptions.resumeLabel) ? suspendOptions.resumeLabel : [suspendOptions.resumeLabel];
1170
+ for (const label of resumeLabel) {
1171
+ executionContext.resumeLabels[label] = {
1172
+ stepId: step.id,
1173
+ foreachIndex: executionContext.foreachIndex
1174
+ };
1175
+ }
1185
1176
  }
1186
1177
  suspended = { payload: suspendPayload };
1187
1178
  },
@@ -1195,6 +1186,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1195
1186
  runId: stepResults[step.id]?.suspendPayload?.__workflow_meta?.runId
1196
1187
  },
1197
1188
  [_constants.EMITTER_SYMBOL]: emitter,
1189
+ [_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
1198
1190
  engine: {
1199
1191
  step: this.inngestStep
1200
1192
  },
@@ -1222,7 +1214,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1222
1214
  };
1223
1215
  execResults = stepFailure;
1224
1216
  const fallbackErrorMessage = `Step ${step.id} failed`;
1225
- stepAISpan?.error({ error: new Error(execResults.error ?? fallbackErrorMessage) });
1217
+ stepSpan?.error({ error: new Error(execResults.error ?? fallbackErrorMessage) });
1226
1218
  throw new inngest.RetryAfterError(execResults.error ?? fallbackErrorMessage, executionContext.retryConfig.delay, {
1227
1219
  cause: execResults
1228
1220
  });
@@ -1231,6 +1223,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1231
1223
  execResults = {
1232
1224
  status: "suspended",
1233
1225
  suspendPayload: suspended.payload,
1226
+ ...execResults.output ? { suspendOutput: execResults.output } : {},
1234
1227
  payload: inputData,
1235
1228
  suspendedAt: Date.now(),
1236
1229
  startedAt,
@@ -1246,24 +1239,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1246
1239
  startedAt
1247
1240
  };
1248
1241
  }
1249
- await emitter.emit("watch", {
1250
- type: "watch",
1251
- payload: {
1252
- currentStep: {
1253
- id: step.id,
1254
- ...execResults
1255
- },
1256
- workflowState: {
1257
- status: "running",
1258
- steps: { ...stepResults, [step.id]: execResults },
1259
- result: null,
1260
- error: null
1261
- }
1262
- },
1263
- eventTimestamp: Date.now()
1264
- });
1265
1242
  if (execResults.status === "suspended") {
1266
- await emitter.emit("watch-v2", {
1243
+ await emitter.emit("watch", {
1267
1244
  type: "workflow-step-suspended",
1268
1245
  payload: {
1269
1246
  id: step.id,
@@ -1271,14 +1248,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1271
1248
  }
1272
1249
  });
1273
1250
  } else {
1274
- await emitter.emit("watch-v2", {
1251
+ await emitter.emit("watch", {
1275
1252
  type: "workflow-step-result",
1276
1253
  payload: {
1277
1254
  id: step.id,
1278
1255
  ...execResults
1279
1256
  }
1280
1257
  });
1281
- await emitter.emit("watch-v2", {
1258
+ await emitter.emit("watch", {
1282
1259
  type: "workflow-step-finish",
1283
1260
  payload: {
1284
1261
  id: step.id,
@@ -1286,7 +1263,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1286
1263
  }
1287
1264
  });
1288
1265
  }
1289
- stepAISpan?.end({ output: execResults });
1266
+ stepSpan?.end({ output: execResults });
1290
1267
  return { result: execResults, executionContext, stepResults };
1291
1268
  });
1292
1269
  } catch (e) {
@@ -1316,9 +1293,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1316
1293
  output: stepRes.result,
1317
1294
  workflowId: executionContext.workflowId,
1318
1295
  stepId: step.id,
1319
- runtimeContext,
1296
+ requestContext,
1320
1297
  disableScorers,
1321
- tracingContext: { currentSpan: stepAISpan }
1298
+ tracingContext: { currentSpan: stepSpan }
1322
1299
  });
1323
1300
  }
1324
1301
  });
@@ -1352,14 +1329,15 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1352
1329
  resourceId,
1353
1330
  snapshot: {
1354
1331
  runId,
1332
+ status: workflowStatus,
1355
1333
  value: executionContext.state,
1356
1334
  context: stepResults,
1357
- activePaths: [],
1335
+ activePaths: executionContext.executionPath,
1336
+ activeStepsPath: executionContext.activeStepsPath,
1358
1337
  suspendedPaths: executionContext.suspendedPaths,
1359
1338
  resumeLabels: executionContext.resumeLabels,
1360
1339
  waitingPaths: {},
1361
1340
  serializedStepGraph,
1362
- status: workflowStatus,
1363
1341
  result,
1364
1342
  error,
1365
1343
  // @ts-ignore
@@ -1374,20 +1352,18 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1374
1352
  runId,
1375
1353
  entry,
1376
1354
  prevOutput,
1377
- prevStep,
1378
1355
  stepResults,
1379
- serializedStepGraph,
1380
1356
  resume,
1381
1357
  executionContext,
1382
1358
  emitter,
1383
1359
  abortController,
1384
- runtimeContext,
1360
+ requestContext,
1385
1361
  writableStream,
1386
1362
  disableScorers,
1387
1363
  tracingContext
1388
1364
  }) {
1389
1365
  const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
1390
- type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL,
1366
+ type: observability.SpanType.WORKFLOW_CONDITIONAL,
1391
1367
  name: `conditional: '${entry.conditions.length} conditions'`,
1392
1368
  input: prevOutput,
1393
1369
  attributes: {
@@ -1400,7 +1376,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1400
1376
  entry.conditions.map(
1401
1377
  (cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
1402
1378
  const evalSpan = conditionalSpan?.createChildSpan({
1403
- type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL_EVAL,
1379
+ type: observability.SpanType.WORKFLOW_CONDITIONAL_EVAL,
1404
1380
  name: `condition: '${index}'`,
1405
1381
  input: prevOutput,
1406
1382
  attributes: {
@@ -1409,47 +1385,55 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1409
1385
  tracingPolicy: this.options?.tracingPolicy
1410
1386
  });
1411
1387
  try {
1412
- const result = await cond({
1413
- runId,
1414
- workflowId,
1415
- mastra: this.mastra,
1416
- runtimeContext,
1417
- runCount: -1,
1418
- inputData: prevOutput,
1419
- state: executionContext.state,
1420
- setState: (state) => {
1421
- executionContext.state = state;
1422
- },
1423
- tracingContext: {
1424
- currentSpan: evalSpan
1425
- },
1426
- getInitData: () => stepResults?.input,
1427
- getStepResult: workflows.getStepResult.bind(this, stepResults),
1428
- // TODO: this function shouldn't have suspend probably?
1429
- suspend: async (_suspendPayload) => {
1430
- },
1431
- bail: () => {
1432
- },
1433
- abort: () => {
1434
- abortController.abort();
1435
- },
1436
- [_constants.EMITTER_SYMBOL]: emitter,
1437
- [_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
1438
- // TODO: add streamVNext support
1439
- engine: {
1440
- step: this.inngestStep
1441
- },
1442
- abortSignal: abortController.signal,
1443
- writer: new tools.ToolStream(
1388
+ const result = await cond(
1389
+ workflows.createDeprecationProxy(
1444
1390
  {
1445
- prefix: "workflow-step",
1446
- callId: crypto.randomUUID(),
1447
- name: "conditional",
1448
- runId
1391
+ runId,
1392
+ workflowId,
1393
+ mastra: this.mastra,
1394
+ requestContext,
1395
+ retryCount: -1,
1396
+ inputData: prevOutput,
1397
+ state: executionContext.state,
1398
+ setState: (state) => {
1399
+ executionContext.state = state;
1400
+ },
1401
+ tracingContext: {
1402
+ currentSpan: evalSpan
1403
+ },
1404
+ getInitData: () => stepResults?.input,
1405
+ getStepResult: workflows.getStepResult.bind(this, stepResults),
1406
+ // TODO: this function shouldn't have suspend probably?
1407
+ suspend: async (_suspendPayload) => {
1408
+ },
1409
+ bail: () => {
1410
+ },
1411
+ abort: () => {
1412
+ abortController.abort();
1413
+ },
1414
+ [_constants.EMITTER_SYMBOL]: emitter,
1415
+ [_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
1416
+ engine: {
1417
+ step: this.inngestStep
1418
+ },
1419
+ abortSignal: abortController.signal,
1420
+ writer: new tools.ToolStream(
1421
+ {
1422
+ prefix: "workflow-step",
1423
+ callId: crypto.randomUUID(),
1424
+ name: "conditional",
1425
+ runId
1426
+ },
1427
+ writableStream
1428
+ )
1449
1429
  },
1450
- writableStream
1430
+ {
1431
+ paramName: "runCount",
1432
+ deprecationMessage: workflows.runCountDeprecationMessage,
1433
+ logger: this.logger
1434
+ }
1451
1435
  )
1452
- });
1436
+ );
1453
1437
  evalSpan?.end({
1454
1438
  output: result,
1455
1439
  attributes: {
@@ -1477,47 +1461,54 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1477
1461
  }
1478
1462
  });
1479
1463
  const results = await Promise.all(
1480
- stepsToRun.map(
1481
- (step, index) => this.executeEntry({
1482
- workflowId,
1483
- runId,
1484
- entry: step,
1485
- serializedStepGraph,
1486
- prevStep,
1464
+ stepsToRun.map(async (step, index) => {
1465
+ const currStepResult = stepResults[step.step.id];
1466
+ if (currStepResult && currStepResult.status === "success") {
1467
+ return currStepResult;
1468
+ }
1469
+ const result = await this.executeStep({
1470
+ step: step.step,
1471
+ prevOutput,
1487
1472
  stepResults,
1488
1473
  resume,
1489
1474
  executionContext: {
1490
1475
  workflowId,
1491
1476
  runId,
1492
1477
  executionPath: [...executionContext.executionPath, index],
1478
+ activeStepsPath: executionContext.activeStepsPath,
1493
1479
  suspendedPaths: executionContext.suspendedPaths,
1494
1480
  resumeLabels: executionContext.resumeLabels,
1495
1481
  retryConfig: executionContext.retryConfig,
1496
- executionSpan: executionContext.executionSpan,
1497
1482
  state: executionContext.state
1498
1483
  },
1499
1484
  emitter,
1500
1485
  abortController,
1501
- runtimeContext,
1486
+ requestContext,
1502
1487
  writableStream,
1503
1488
  disableScorers,
1504
1489
  tracingContext: {
1505
1490
  currentSpan: conditionalSpan
1506
1491
  }
1507
- })
1508
- )
1492
+ });
1493
+ stepResults[step.step.id] = result;
1494
+ return result;
1495
+ })
1509
1496
  );
1510
- const hasFailed = results.find((result) => result.result.status === "failed");
1511
- const hasSuspended = results.find((result) => result.result.status === "suspended");
1497
+ const hasFailed = results.find((result) => result.status === "failed");
1498
+ const hasSuspended = results.find((result) => result.status === "suspended");
1512
1499
  if (hasFailed) {
1513
- execResults = { status: "failed", error: hasFailed.result.error };
1500
+ execResults = { status: "failed", error: hasFailed.error };
1514
1501
  } else if (hasSuspended) {
1515
- execResults = { status: "suspended", suspendPayload: hasSuspended.result.suspendPayload };
1502
+ execResults = {
1503
+ status: "suspended",
1504
+ suspendPayload: hasSuspended.suspendPayload,
1505
+ ...hasSuspended.suspendOutput ? { suspendOutput: hasSuspended.suspendOutput } : {}
1506
+ };
1516
1507
  } else {
1517
1508
  execResults = {
1518
1509
  status: "success",
1519
1510
  output: results.reduce((acc, result, index) => {
1520
- if (result.result.status === "success") {
1511
+ if (result.status === "success") {
1521
1512
  acc[stepsToRun[index].step.id] = result.output;
1522
1513
  }
1523
1514
  return acc;