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