@mastra/inngest 0.0.0-sidebar-window-undefined-fix-20251029233656 → 0.0.0-span-scorring-test-20251124132129

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,8 +3,8 @@
3
3
  var crypto = require('crypto');
4
4
  var web = require('stream/web');
5
5
  var realtime = require('@inngest/realtime');
6
- var aiTracing = require('@mastra/core/ai-tracing');
7
6
  var di = require('@mastra/core/di');
7
+ var observability = require('@mastra/core/observability');
8
8
  var stream = require('@mastra/core/stream');
9
9
  var tools = require('@mastra/core/tools');
10
10
  var workflows = require('@mastra/core/workflows');
@@ -20,7 +20,7 @@ function serve({
20
20
  functions: userFunctions = [],
21
21
  registerOptions
22
22
  }) {
23
- const wfs = mastra.getWorkflows();
23
+ const wfs = mastra.listWorkflows();
24
24
  const workflowFunctions = Array.from(
25
25
  new Set(
26
26
  Object.values(wfs).flatMap((wf) => {
@@ -59,11 +59,12 @@ var InngestRun = class extends workflows.Run {
59
59
  }
60
60
  async getRunOutput(eventId) {
61
61
  let runs = await this.getRuns(eventId);
62
+ const storage = this.#mastra?.getStorage();
62
63
  while (runs?.[0]?.status !== "Completed" || runs?.[0]?.event_id !== eventId) {
63
64
  await new Promise((resolve) => setTimeout(resolve, 1e3));
64
65
  runs = await this.getRuns(eventId);
65
66
  if (runs?.[0]?.status === "Failed") {
66
- const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
67
+ const snapshot = await storage?.loadWorkflowSnapshot({
67
68
  workflowName: this.workflowId,
68
69
  runId: this.runId
69
70
  });
@@ -72,7 +73,7 @@ var InngestRun = class extends workflows.Run {
72
73
  };
73
74
  }
74
75
  if (runs?.[0]?.status === "Cancelled") {
75
- const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
76
+ const snapshot = await storage?.loadWorkflowSnapshot({
76
77
  workflowName: this.workflowId,
77
78
  runId: this.runId
78
79
  });
@@ -81,38 +82,40 @@ var InngestRun = class extends workflows.Run {
81
82
  }
82
83
  return runs?.[0];
83
84
  }
84
- async sendEvent(event, data) {
85
- await this.inngest.send({
86
- name: `user-event-${event}`,
87
- data
88
- });
89
- }
90
85
  async cancel() {
86
+ const storage = this.#mastra?.getStorage();
91
87
  await this.inngest.send({
92
88
  name: `cancel.workflow.${this.workflowId}`,
93
89
  data: {
94
90
  runId: this.runId
95
91
  }
96
92
  });
97
- const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
93
+ const snapshot = await storage?.loadWorkflowSnapshot({
98
94
  workflowName: this.workflowId,
99
95
  runId: this.runId
100
96
  });
101
97
  if (snapshot) {
102
- await this.#mastra?.storage?.persistWorkflowSnapshot({
98
+ await storage?.persistWorkflowSnapshot({
103
99
  workflowName: this.workflowId,
104
100
  runId: this.runId,
105
101
  resourceId: this.resourceId,
106
102
  snapshot: {
107
103
  ...snapshot,
108
- status: "canceled"
104
+ status: "canceled",
105
+ value: snapshot.value
109
106
  }
110
107
  });
111
108
  }
112
109
  }
113
- async start({
110
+ async start(params) {
111
+ return this._start(params);
112
+ }
113
+ async _start({
114
114
  inputData,
115
- initialState
115
+ initialState,
116
+ outputOptions,
117
+ tracingOptions,
118
+ format
116
119
  }) {
117
120
  await this.#mastra.getStorage()?.persistWorkflowSnapshot({
118
121
  workflowName: this.workflowId,
@@ -121,14 +124,15 @@ var InngestRun = class extends workflows.Run {
121
124
  snapshot: {
122
125
  runId: this.runId,
123
126
  serializedStepGraph: this.serializedStepGraph,
127
+ status: "running",
124
128
  value: {},
125
129
  context: {},
126
130
  activePaths: [],
127
131
  suspendedPaths: {},
132
+ activeStepsPath: {},
128
133
  resumeLabels: {},
129
134
  waitingPaths: {},
130
- timestamp: Date.now(),
131
- status: "running"
135
+ timestamp: Date.now()
132
136
  }
133
137
  });
134
138
  const inputDataToUse = await this._validateInput(inputData);
@@ -139,7 +143,10 @@ var InngestRun = class extends workflows.Run {
139
143
  inputData: inputDataToUse,
140
144
  initialState: initialStateToUse,
141
145
  runId: this.runId,
142
- resourceId: this.resourceId
146
+ resourceId: this.resourceId,
147
+ outputOptions,
148
+ tracingOptions,
149
+ format
143
150
  }
144
151
  });
145
152
  const eventId = eventOutput.ids[0];
@@ -168,10 +175,16 @@ var InngestRun = class extends workflows.Run {
168
175
  return p;
169
176
  }
170
177
  async _resume(params) {
171
- const steps = (Array.isArray(params.step) ? params.step : [params.step]).map(
172
- (step) => typeof step === "string" ? step : step?.id
173
- );
174
- const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
178
+ const storage = this.#mastra?.getStorage();
179
+ let steps = [];
180
+ if (typeof params.step === "string") {
181
+ steps = params.step.split(".");
182
+ } else {
183
+ steps = (Array.isArray(params.step) ? params.step : [params.step]).map(
184
+ (step) => typeof step === "string" ? step : step?.id
185
+ );
186
+ }
187
+ const snapshot = await storage?.loadWorkflowSnapshot({
175
188
  workflowName: this.workflowId,
176
189
  runId: this.runId
177
190
  });
@@ -189,9 +202,99 @@ var InngestRun = class extends workflows.Run {
189
202
  steps,
190
203
  stepResults: snapshot?.context,
191
204
  resumePayload: resumeDataToUse,
192
- // @ts-ignore
193
- resumePath: snapshot?.suspendedPaths?.[steps?.[0]]
205
+ resumePath: steps?.[0] ? snapshot?.suspendedPaths?.[steps?.[0]] : void 0
206
+ }
207
+ }
208
+ });
209
+ const eventId = eventOutput.ids[0];
210
+ if (!eventId) {
211
+ throw new Error("Event ID is not set");
212
+ }
213
+ const runOutput = await this.getRunOutput(eventId);
214
+ const result = runOutput?.output?.result;
215
+ if (result.status === "failed") {
216
+ result.error = new Error(result.error);
217
+ }
218
+ return result;
219
+ }
220
+ async timeTravel(params) {
221
+ const p = this._timeTravel(params).then((result) => {
222
+ if (result.status !== "suspended") {
223
+ this.closeStreamAction?.().catch(() => {
224
+ });
225
+ }
226
+ return result;
227
+ });
228
+ this.executionResults = p;
229
+ return p;
230
+ }
231
+ async _timeTravel(params) {
232
+ if (!params.step || Array.isArray(params.step) && params.step?.length === 0) {
233
+ throw new Error("Step is required and must be a valid step or array of steps");
234
+ }
235
+ let steps = [];
236
+ if (typeof params.step === "string") {
237
+ steps = params.step.split(".");
238
+ } else {
239
+ steps = (Array.isArray(params.step) ? params.step : [params.step]).map(
240
+ (step) => typeof step === "string" ? step : step?.id
241
+ );
242
+ }
243
+ if (steps.length === 0) {
244
+ throw new Error("No steps provided to timeTravel");
245
+ }
246
+ const storage = this.#mastra?.getStorage();
247
+ const snapshot = await storage?.loadWorkflowSnapshot({
248
+ workflowName: this.workflowId,
249
+ runId: this.runId
250
+ });
251
+ if (!snapshot) {
252
+ await storage?.persistWorkflowSnapshot({
253
+ workflowName: this.workflowId,
254
+ runId: this.runId,
255
+ resourceId: this.resourceId,
256
+ snapshot: {
257
+ runId: this.runId,
258
+ serializedStepGraph: this.serializedStepGraph,
259
+ status: "pending",
260
+ value: {},
261
+ context: {},
262
+ activePaths: [],
263
+ suspendedPaths: {},
264
+ activeStepsPath: {},
265
+ resumeLabels: {},
266
+ waitingPaths: {},
267
+ timestamp: Date.now()
194
268
  }
269
+ });
270
+ }
271
+ if (snapshot?.status === "running") {
272
+ throw new Error("This workflow run is still running, cannot time travel");
273
+ }
274
+ let inputDataToUse = params.inputData;
275
+ if (inputDataToUse && steps.length === 1) {
276
+ inputDataToUse = await this._validateTimetravelInputData(params.inputData, this.workflowSteps[steps[0]]);
277
+ }
278
+ const timeTravelData = workflows.createTimeTravelExecutionParams({
279
+ steps,
280
+ inputData: inputDataToUse,
281
+ resumeData: params.resumeData,
282
+ context: params.context,
283
+ nestedStepsContext: params.nestedStepsContext,
284
+ snapshot: snapshot ?? { context: {} },
285
+ graph: this.executionGraph,
286
+ initialState: params.initialState
287
+ });
288
+ const eventOutput = await this.inngest.send({
289
+ name: `workflow.${this.workflowId}`,
290
+ data: {
291
+ initialState: timeTravelData.state,
292
+ runId: this.runId,
293
+ workflowId: this.workflowId,
294
+ stepResults: timeTravelData.stepResults,
295
+ timeTravel: timeTravelData,
296
+ tracingOptions: params.tracingOptions,
297
+ outputOptions: params.outputOptions
195
298
  }
196
299
  });
197
300
  const eventId = eventOutput.ids[0];
@@ -205,12 +308,12 @@ var InngestRun = class extends workflows.Run {
205
308
  }
206
309
  return result;
207
310
  }
208
- watch(cb, type = "watch") {
311
+ watch(cb) {
209
312
  let active = true;
210
313
  const streamPromise = realtime.subscribe(
211
314
  {
212
315
  channel: `workflow:${this.workflowId}:${this.runId}`,
213
- topics: [type],
316
+ topics: ["watch"],
214
317
  app: this.inngest
215
318
  },
216
319
  (message) => {
@@ -228,20 +331,35 @@ var InngestRun = class extends workflows.Run {
228
331
  });
229
332
  };
230
333
  }
231
- streamLegacy({ inputData, runtimeContext } = {}) {
334
+ streamLegacy({ inputData, requestContext } = {}) {
232
335
  const { readable, writable } = new TransformStream();
233
336
  const writer = writable.getWriter();
234
337
  const unwatch = this.watch(async (event) => {
235
338
  try {
339
+ await writer.write({
340
+ // @ts-ignore
341
+ type: "start",
342
+ // @ts-ignore
343
+ payload: { runId: this.runId }
344
+ });
236
345
  const e = {
237
346
  ...event,
238
347
  type: event.type.replace("workflow-", "")
239
348
  };
349
+ if (e.type === "step-output") {
350
+ e.type = e.payload.output.type;
351
+ e.payload = e.payload.output.payload;
352
+ }
240
353
  await writer.write(e);
241
354
  } catch {
242
355
  }
243
- }, "watch-v2");
356
+ });
244
357
  this.closeStreamAction = async () => {
358
+ await writer.write({
359
+ type: "finish",
360
+ // @ts-ignore
361
+ payload: { runId: this.runId }
362
+ });
245
363
  unwatch();
246
364
  try {
247
365
  await writer.close();
@@ -251,7 +369,7 @@ var InngestRun = class extends workflows.Run {
251
369
  writer.releaseLock();
252
370
  }
253
371
  };
254
- this.executionResults = this.start({ inputData, runtimeContext }).then((result) => {
372
+ this.executionResults = this._start({ inputData, requestContext, format: "legacy" }).then((result) => {
255
373
  if (result.status !== "suspended") {
256
374
  this.closeStreamAction?.().catch(() => {
257
375
  });
@@ -265,11 +383,18 @@ var InngestRun = class extends workflows.Run {
265
383
  }
266
384
  stream({
267
385
  inputData,
268
- runtimeContext,
269
- closeOnSuspend = true
386
+ requestContext,
387
+ tracingOptions,
388
+ closeOnSuspend = true,
389
+ initialState,
390
+ outputOptions
270
391
  } = {}) {
392
+ if (this.closeStreamAction && this.streamOutput) {
393
+ return this.streamOutput;
394
+ }
395
+ this.closeStreamAction = async () => {
396
+ };
271
397
  const self = this;
272
- let streamOutput;
273
398
  const stream$1 = new web.ReadableStream({
274
399
  async start(controller) {
275
400
  const unwatch = self.watch(async ({ type, from = stream.ChunkFrom.WORKFLOW, payload }) => {
@@ -278,11 +403,11 @@ var InngestRun = class extends workflows.Run {
278
403
  runId: self.runId,
279
404
  from,
280
405
  payload: {
281
- stepName: payload.id,
406
+ stepName: payload?.id,
282
407
  ...payload
283
408
  }
284
409
  });
285
- }, "watch-v2");
410
+ });
286
411
  self.closeStreamAction = async () => {
287
412
  unwatch();
288
413
  try {
@@ -291,29 +416,115 @@ var InngestRun = class extends workflows.Run {
291
416
  console.error("Error closing stream:", err);
292
417
  }
293
418
  };
294
- const executionResultsPromise = self.start({
419
+ const executionResultsPromise = self._start({
295
420
  inputData,
296
- runtimeContext
421
+ requestContext,
422
+ // tracingContext, // We are not able to pass a reference to a span here, what to do?
423
+ initialState,
424
+ tracingOptions,
425
+ outputOptions,
426
+ format: "vnext"
297
427
  });
298
- const executionResults = await executionResultsPromise;
299
- if (closeOnSuspend) {
428
+ let executionResults;
429
+ try {
430
+ executionResults = await executionResultsPromise;
431
+ if (closeOnSuspend) {
432
+ self.closeStreamAction?.().catch(() => {
433
+ });
434
+ } else if (executionResults.status !== "suspended") {
435
+ self.closeStreamAction?.().catch(() => {
436
+ });
437
+ }
438
+ if (self.streamOutput) {
439
+ self.streamOutput.updateResults(
440
+ executionResults
441
+ );
442
+ }
443
+ } catch (err) {
444
+ self.streamOutput?.rejectResults(err);
300
445
  self.closeStreamAction?.().catch(() => {
301
446
  });
302
- } else if (executionResults.status !== "suspended") {
447
+ }
448
+ }
449
+ });
450
+ this.streamOutput = new stream.WorkflowRunOutput({
451
+ runId: this.runId,
452
+ workflowId: this.workflowId,
453
+ stream: stream$1
454
+ });
455
+ return this.streamOutput;
456
+ }
457
+ streamVNext(args = {}) {
458
+ return this.stream(args);
459
+ }
460
+ timeTravelStream({
461
+ inputData,
462
+ resumeData,
463
+ initialState,
464
+ step,
465
+ context,
466
+ nestedStepsContext,
467
+ requestContext,
468
+ tracingOptions,
469
+ outputOptions
470
+ }) {
471
+ this.closeStreamAction = async () => {
472
+ };
473
+ const self = this;
474
+ const stream$1 = new web.ReadableStream({
475
+ async start(controller) {
476
+ const unwatch = self.watch(async ({ type, from = stream.ChunkFrom.WORKFLOW, payload }) => {
477
+ controller.enqueue({
478
+ type,
479
+ runId: self.runId,
480
+ from,
481
+ payload: {
482
+ stepName: payload?.id,
483
+ ...payload
484
+ }
485
+ });
486
+ });
487
+ self.closeStreamAction = async () => {
488
+ unwatch();
489
+ try {
490
+ await controller.close();
491
+ } catch (err) {
492
+ console.error("Error closing stream:", err);
493
+ }
494
+ };
495
+ const executionResultsPromise = self._timeTravel({
496
+ inputData,
497
+ step,
498
+ context,
499
+ nestedStepsContext,
500
+ resumeData,
501
+ initialState,
502
+ requestContext,
503
+ tracingOptions,
504
+ outputOptions
505
+ });
506
+ self.executionResults = executionResultsPromise;
507
+ let executionResults;
508
+ try {
509
+ executionResults = await executionResultsPromise;
510
+ self.closeStreamAction?.().catch(() => {
511
+ });
512
+ if (self.streamOutput) {
513
+ self.streamOutput.updateResults(executionResults);
514
+ }
515
+ } catch (err) {
516
+ self.streamOutput?.rejectResults(err);
303
517
  self.closeStreamAction?.().catch(() => {
304
518
  });
305
- }
306
- if (streamOutput) {
307
- streamOutput.updateResults(executionResults);
308
519
  }
309
520
  }
310
521
  });
311
- streamOutput = new stream.WorkflowRunOutput({
522
+ this.streamOutput = new stream.WorkflowRunOutput({
312
523
  runId: this.runId,
313
524
  workflowId: this.workflowId,
314
525
  stream: stream$1
315
526
  });
316
- return streamOutput;
527
+ return this.streamOutput;
317
528
  }
318
529
  };
319
530
  var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
@@ -324,6 +535,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
324
535
  constructor(params, inngest) {
325
536
  const { concurrency, rateLimit, throttle, debounce, priority, ...workflowParams } = params;
326
537
  super(workflowParams);
538
+ this.engineType = "inngest";
327
539
  const flowControlEntries = Object.entries({ concurrency, rateLimit, throttle, debounce, priority }).filter(
328
540
  ([_, value]) => value !== void 0
329
541
  );
@@ -331,13 +543,13 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
331
543
  this.#mastra = params.mastra;
332
544
  this.inngest = inngest;
333
545
  }
334
- async getWorkflowRuns(args) {
546
+ async listWorkflowRuns(args) {
335
547
  const storage = this.#mastra?.getStorage();
336
548
  if (!storage) {
337
549
  this.logger.debug("Cannot get workflow runs. Mastra engine is not initialized");
338
550
  return { runs: [], total: 0 };
339
551
  }
340
- return storage.getWorkflowRuns({ workflowName: this.id, ...args ?? {} });
552
+ return storage.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
341
553
  }
342
554
  async getWorkflowRunById(runId) {
343
555
  const storage = this.#mastra?.getStorage();
@@ -366,16 +578,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
366
578
  }
367
579
  }
368
580
  }
369
- /**
370
- * @deprecated Use createRunAsync() instead.
371
- * @throws {Error} Always throws an error directing users to use createRunAsync()
372
- */
373
- createRun(_options) {
374
- throw new Error(
375
- "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."
376
- );
377
- }
378
- async createRunAsync(options) {
581
+ async createRun(options) {
379
582
  const runIdToUse = options?.runId || crypto.randomUUID();
380
583
  const run = this.runs.get(runIdToUse) ?? new InngestRun(
381
584
  {
@@ -388,7 +591,9 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
388
591
  mastra: this.#mastra,
389
592
  retryConfig: this.retryConfig,
390
593
  cleanup: () => this.runs.delete(runIdToUse),
391
- workflowSteps: this.steps
594
+ workflowSteps: this.steps,
595
+ workflowEngineType: this.engineType,
596
+ validateInputs: this.options.validateInputs
392
597
  },
393
598
  this.inngest
394
599
  );
@@ -409,13 +614,13 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
409
614
  value: {},
410
615
  context: {},
411
616
  activePaths: [],
617
+ activeStepsPath: {},
412
618
  waitingPaths: {},
413
619
  serializedStepGraph: this.serializedStepGraph,
414
620
  suspendedPaths: {},
415
621
  resumeLabels: {},
416
622
  result: void 0,
417
623
  error: void 0,
418
- // @ts-ignore
419
624
  timestamp: Date.now()
420
625
  }
421
626
  });
@@ -429,15 +634,14 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
429
634
  this.function = this.inngest.createFunction(
430
635
  {
431
636
  id: `workflow.${this.id}`,
432
- // @ts-ignore
433
- retries: this.retryConfig?.attempts ?? 0,
637
+ retries: Math.min(this.retryConfig?.attempts ?? 0, 20),
434
638
  cancelOn: [{ event: `cancel.workflow.${this.id}` }],
435
639
  // Spread flow control configuration
436
640
  ...this.flowControlConfig
437
641
  },
438
642
  { event: `workflow.${this.id}` },
439
643
  async ({ event, step, attempt, publish }) => {
440
- let { inputData, initialState, runId, resourceId, resume, outputOptions } = event.data;
644
+ let { inputData, initialState, runId, resourceId, resume, outputOptions, format, timeTravel } = event.data;
441
645
  if (!runId) {
442
646
  runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
443
647
  return crypto.randomUUID();
@@ -476,13 +680,20 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
476
680
  initialState,
477
681
  emitter,
478
682
  retryConfig: this.retryConfig,
479
- runtimeContext: new di.RuntimeContext(),
683
+ requestContext: new di.RequestContext(),
480
684
  // TODO
481
685
  resume,
686
+ timeTravel,
687
+ format,
482
688
  abortController: new AbortController(),
483
- currentSpan: void 0,
484
- // TODO: Pass actual parent AI span from workflow execution context
485
- outputOptions
689
+ // currentSpan: undefined, // TODO: Pass actual parent Span from workflow execution context
690
+ outputOptions,
691
+ writableStream: new web.WritableStream({
692
+ write(chunk) {
693
+ void emitter.emit("watch", chunk).catch(() => {
694
+ });
695
+ }
696
+ })
486
697
  });
487
698
  await step.run(`workflow.${this.id}.finalize`, async () => {
488
699
  if (result.status === "failed") {
@@ -520,20 +731,29 @@ function isAgent(params) {
520
731
  function isTool(params) {
521
732
  return params instanceof tools.Tool;
522
733
  }
523
- function createStep(params) {
734
+ function createStep(params, agentOptions) {
524
735
  if (isAgent(params)) {
525
736
  return {
526
737
  id: params.name,
527
738
  description: params.getDescription(),
528
- // @ts-ignore
529
739
  inputSchema: zod.z.object({
530
740
  prompt: zod.z.string()
741
+ // resourceId: z.string().optional(),
742
+ // threadId: z.string().optional(),
531
743
  }),
532
- // @ts-ignore
533
744
  outputSchema: zod.z.object({
534
745
  text: zod.z.string()
535
746
  }),
536
- execute: async ({ inputData, [_constants.EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort, tracingContext }) => {
747
+ execute: async ({
748
+ inputData,
749
+ [_constants.EMITTER_SYMBOL]: emitter,
750
+ [_constants.STREAM_FORMAT_SYMBOL]: streamFormat,
751
+ requestContext,
752
+ tracingContext,
753
+ abortSignal,
754
+ abort,
755
+ writer
756
+ }) => {
537
757
  let streamPromise = {};
538
758
  streamPromise.promise = new Promise((resolve, reject) => {
539
759
  streamPromise.resolve = resolve;
@@ -543,61 +763,60 @@ function createStep(params) {
543
763
  name: params.name,
544
764
  args: inputData
545
765
  };
546
- if ((await params.getLLM()).getModel().specificationVersion === `v2`) {
547
- const { fullStream } = await params.stream(inputData.prompt, {
548
- runtimeContext,
766
+ let stream;
767
+ if ((await params.getModel()).specificationVersion === "v1") {
768
+ const { fullStream } = await params.streamLegacy(inputData.prompt, {
769
+ ...agentOptions ?? {},
770
+ // resourceId: inputData.resourceId,
771
+ // threadId: inputData.threadId,
772
+ requestContext,
549
773
  tracingContext,
550
774
  onFinish: (result) => {
551
775
  streamPromise.resolve(result.text);
776
+ void agentOptions?.onFinish?.(result);
552
777
  },
553
778
  abortSignal
554
779
  });
555
- if (abortSignal.aborted) {
556
- return abort();
557
- }
558
- await emitter.emit("watch-v2", {
559
- type: "tool-call-streaming-start",
560
- ...toolData ?? {}
561
- });
562
- for await (const chunk of fullStream) {
563
- if (chunk.type === "text-delta") {
564
- await emitter.emit("watch-v2", {
565
- type: "tool-call-delta",
566
- ...toolData ?? {},
567
- argsTextDelta: chunk.payload.text
568
- });
569
- }
570
- }
780
+ stream = fullStream;
571
781
  } else {
572
- const { fullStream } = await params.streamLegacy(inputData.prompt, {
573
- runtimeContext,
782
+ const modelOutput = await params.stream(inputData.prompt, {
783
+ ...agentOptions ?? {},
784
+ requestContext,
574
785
  tracingContext,
575
786
  onFinish: (result) => {
576
787
  streamPromise.resolve(result.text);
788
+ void agentOptions?.onFinish?.(result);
577
789
  },
578
790
  abortSignal
579
791
  });
580
- if (abortSignal.aborted) {
581
- return abort();
582
- }
583
- await emitter.emit("watch-v2", {
792
+ stream = modelOutput.fullStream;
793
+ }
794
+ if (streamFormat === "legacy") {
795
+ await emitter.emit("watch", {
584
796
  type: "tool-call-streaming-start",
585
797
  ...toolData ?? {}
586
798
  });
587
- for await (const chunk of fullStream) {
799
+ for await (const chunk of stream) {
588
800
  if (chunk.type === "text-delta") {
589
- await emitter.emit("watch-v2", {
801
+ await emitter.emit("watch", {
590
802
  type: "tool-call-delta",
591
803
  ...toolData ?? {},
592
804
  argsTextDelta: chunk.textDelta
593
805
  });
594
806
  }
595
807
  }
808
+ await emitter.emit("watch", {
809
+ type: "tool-call-streaming-finish",
810
+ ...toolData ?? {}
811
+ });
812
+ } else {
813
+ for await (const chunk of stream) {
814
+ await writer.write(chunk);
815
+ }
816
+ }
817
+ if (abortSignal.aborted) {
818
+ return abort();
596
819
  }
597
- await emitter.emit("watch-v2", {
598
- type: "tool-call-streaming-finish",
599
- ...toolData ?? {}
600
- });
601
820
  return {
602
821
  text: await streamPromise.promise
603
822
  };
@@ -611,20 +830,36 @@ function createStep(params) {
611
830
  }
612
831
  return {
613
832
  // TODO: tool probably should have strong id type
614
- // @ts-ignore
615
833
  id: params.id,
616
834
  description: params.description,
617
835
  inputSchema: params.inputSchema,
618
836
  outputSchema: params.outputSchema,
619
- execute: async ({ inputData, mastra, runtimeContext, tracingContext, suspend, resumeData }) => {
620
- return params.execute({
621
- context: inputData,
622
- mastra: aiTracing.wrapMastra(mastra, tracingContext),
623
- runtimeContext,
837
+ execute: async ({
838
+ inputData,
839
+ mastra,
840
+ requestContext,
841
+ tracingContext,
842
+ suspend,
843
+ resumeData,
844
+ runId,
845
+ workflowId,
846
+ state,
847
+ setState
848
+ }) => {
849
+ const toolContext = {
850
+ mastra,
851
+ requestContext,
624
852
  tracingContext,
625
- suspend,
626
- resumeData
627
- });
853
+ resumeData,
854
+ workflow: {
855
+ runId,
856
+ suspend,
857
+ workflowId,
858
+ state,
859
+ setState
860
+ }
861
+ };
862
+ return params.execute(inputData, toolContext);
628
863
  },
629
864
  component: "TOOL"
630
865
  };
@@ -658,6 +893,8 @@ function init(inngest) {
658
893
  suspendSchema: step.suspendSchema,
659
894
  stateSchema: step.stateSchema,
660
895
  execute: step.execute,
896
+ retries: step.retries,
897
+ scorers: step.scorers,
661
898
  component: step.component
662
899
  };
663
900
  },
@@ -683,63 +920,16 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
683
920
  this.inngestStep = inngestStep;
684
921
  this.inngestAttempts = inngestAttempts;
685
922
  }
686
- async execute(params) {
687
- await params.emitter.emit("watch-v2", {
688
- type: "workflow-start",
689
- payload: { runId: params.runId }
690
- });
691
- const result = await super.execute(params);
692
- await params.emitter.emit("watch-v2", {
693
- type: "workflow-finish",
694
- payload: { runId: params.runId }
695
- });
696
- return result;
697
- }
698
923
  async fmtReturnValue(emitter, stepResults, lastOutput, error) {
699
924
  const base = {
700
925
  status: lastOutput.status,
701
926
  steps: stepResults
702
927
  };
703
928
  if (lastOutput.status === "success") {
704
- await emitter.emit("watch", {
705
- type: "watch",
706
- payload: {
707
- workflowState: {
708
- status: lastOutput.status,
709
- steps: stepResults,
710
- result: lastOutput.output
711
- }
712
- },
713
- eventTimestamp: Date.now()
714
- });
715
929
  base.result = lastOutput.output;
716
930
  } else if (lastOutput.status === "failed") {
717
931
  base.error = error instanceof Error ? error?.stack ?? error.message : lastOutput?.error instanceof Error ? lastOutput.error.message : lastOutput.error ?? error ?? "Unknown error";
718
- await emitter.emit("watch", {
719
- type: "watch",
720
- payload: {
721
- workflowState: {
722
- status: lastOutput.status,
723
- steps: stepResults,
724
- result: null,
725
- error: base.error
726
- }
727
- },
728
- eventTimestamp: Date.now()
729
- });
730
932
  } else if (lastOutput.status === "suspended") {
731
- await emitter.emit("watch", {
732
- type: "watch",
733
- payload: {
734
- workflowState: {
735
- status: lastOutput.status,
736
- steps: stepResults,
737
- result: null,
738
- error: null
739
- }
740
- },
741
- eventTimestamp: Date.now()
742
- });
743
933
  const suspendedStepIds = Object.entries(stepResults).flatMap(([stepId, stepResult]) => {
744
934
  if (stepResult?.status === "suspended") {
745
935
  const nestedPath = stepResult?.suspendPayload?.__workflow_meta?.path;
@@ -762,14 +952,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
762
952
  stepResults,
763
953
  emitter,
764
954
  abortController,
765
- runtimeContext,
955
+ requestContext,
766
956
  executionContext,
767
957
  writableStream,
768
958
  tracingContext
769
959
  }) {
770
960
  let { duration, fn } = entry;
771
961
  const sleepSpan = tracingContext?.currentSpan?.createChildSpan({
772
- type: aiTracing.AISpanType.WORKFLOW_SLEEP,
962
+ type: observability.SpanType.WORKFLOW_SLEEP,
773
963
  name: `sleep: ${duration ? `${duration}ms` : "dynamic"}`,
774
964
  attributes: {
775
965
  durationMs: duration,
@@ -786,13 +976,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
786
976
  runId,
787
977
  workflowId,
788
978
  mastra: this.mastra,
789
- runtimeContext,
979
+ requestContext,
790
980
  inputData: prevOutput,
791
981
  state: executionContext.state,
792
982
  setState: (state) => {
793
983
  executionContext.state = state;
794
984
  },
795
- runCount: -1,
796
985
  retryCount: -1,
797
986
  tracingContext: {
798
987
  currentSpan: sleepSpan
@@ -808,7 +997,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
808
997
  abortController?.abort();
809
998
  },
810
999
  [_constants.EMITTER_SYMBOL]: emitter,
811
- // TODO: add streamVNext support
812
1000
  [_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
813
1001
  engine: { step: this.inngestStep },
814
1002
  abortSignal: abortController?.signal,
@@ -852,14 +1040,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
852
1040
  stepResults,
853
1041
  emitter,
854
1042
  abortController,
855
- runtimeContext,
1043
+ requestContext,
856
1044
  executionContext,
857
1045
  writableStream,
858
1046
  tracingContext
859
1047
  }) {
860
1048
  let { date, fn } = entry;
861
1049
  const sleepUntilSpan = tracingContext?.currentSpan?.createChildSpan({
862
- type: aiTracing.AISpanType.WORKFLOW_SLEEP,
1050
+ type: observability.SpanType.WORKFLOW_SLEEP,
863
1051
  name: `sleepUntil: ${date ? date.toISOString() : "dynamic"}`,
864
1052
  attributes: {
865
1053
  untilDate: date,
@@ -877,13 +1065,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
877
1065
  runId,
878
1066
  workflowId,
879
1067
  mastra: this.mastra,
880
- runtimeContext,
1068
+ requestContext,
881
1069
  inputData: prevOutput,
882
1070
  state: executionContext.state,
883
1071
  setState: (state) => {
884
1072
  executionContext.state = state;
885
1073
  },
886
- runCount: -1,
887
1074
  retryCount: -1,
888
1075
  tracingContext: {
889
1076
  currentSpan: sleepUntilSpan
@@ -900,7 +1087,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
900
1087
  },
901
1088
  [_constants.EMITTER_SYMBOL]: emitter,
902
1089
  [_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
903
- // TODO: add streamVNext support
904
1090
  engine: { step: this.inngestStep },
905
1091
  abortSignal: abortController?.signal,
906
1092
  writer: new tools.ToolStream(
@@ -943,32 +1129,23 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
943
1129
  throw e;
944
1130
  }
945
1131
  }
946
- async executeWaitForEvent({ event, timeout }) {
947
- const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
948
- event: `user-event-${event}`,
949
- timeout: timeout ?? 5e3
950
- });
951
- if (eventData === null) {
952
- throw "Timeout waiting for event";
953
- }
954
- return eventData?.data;
955
- }
956
1132
  async executeStep({
957
1133
  step,
958
1134
  stepResults,
959
1135
  executionContext,
960
1136
  resume,
1137
+ timeTravel,
961
1138
  prevOutput,
962
1139
  emitter,
963
1140
  abortController,
964
- runtimeContext,
1141
+ requestContext,
965
1142
  tracingContext,
966
1143
  writableStream,
967
1144
  disableScorers
968
1145
  }) {
969
- const stepAISpan = tracingContext?.currentSpan?.createChildSpan({
1146
+ const stepSpan = tracingContext?.currentSpan?.createChildSpan({
970
1147
  name: `workflow step: '${step.id}'`,
971
- type: aiTracing.AISpanType.WORKFLOW_STEP,
1148
+ type: observability.SpanType.WORKFLOW_STEP,
972
1149
  input: prevOutput,
973
1150
  attributes: {
974
1151
  stepId: step.id
@@ -978,34 +1155,13 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
978
1155
  const { inputData, validationError } = await workflows.validateStepInput({
979
1156
  prevOutput,
980
1157
  step,
981
- validateInputs: this.options?.validateInputs ?? false
1158
+ validateInputs: this.options?.validateInputs ?? true
982
1159
  });
983
1160
  const startedAt = await this.inngestStep.run(
984
1161
  `workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
985
1162
  async () => {
986
1163
  const startedAt2 = Date.now();
987
1164
  await emitter.emit("watch", {
988
- type: "watch",
989
- payload: {
990
- currentStep: {
991
- id: step.id,
992
- status: "running"
993
- },
994
- workflowState: {
995
- status: "running",
996
- steps: {
997
- ...stepResults,
998
- [step.id]: {
999
- status: "running"
1000
- }
1001
- },
1002
- result: null,
1003
- error: null
1004
- }
1005
- },
1006
- eventTimestamp: Date.now()
1007
- });
1008
- await emitter.emit("watch-v2", {
1009
1165
  type: "workflow-step-start",
1010
1166
  payload: {
1011
1167
  id: step.id,
@@ -1021,9 +1177,10 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1021
1177
  const isResume = !!resume?.steps?.length;
1022
1178
  let result;
1023
1179
  let runId;
1180
+ const isTimeTravel = !!(timeTravel && timeTravel.steps?.length > 1 && timeTravel.steps[0] === step.id);
1024
1181
  try {
1025
1182
  if (isResume) {
1026
- runId = stepResults[resume?.steps?.[0]]?.suspendPayload?.__workflow_meta?.runId ?? crypto.randomUUID();
1183
+ runId = stepResults[resume?.steps?.[0] ?? ""]?.suspendPayload?.__workflow_meta?.runId ?? crypto.randomUUID();
1027
1184
  const snapshot = await this.mastra?.getStorage()?.loadWorkflowSnapshot({
1028
1185
  workflowName: step.id,
1029
1186
  runId
@@ -1039,8 +1196,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1039
1196
  steps: resume.steps.slice(1),
1040
1197
  stepResults: snapshot?.context,
1041
1198
  resumePayload: resume.resumePayload,
1042
- // @ts-ignore
1043
- resumePath: snapshot?.suspendedPaths?.[resume.steps?.[1]]
1199
+ resumePath: resume.steps?.[1] ? snapshot?.suspendedPaths?.[resume.steps?.[1]] : void 0
1044
1200
  },
1045
1201
  outputOptions: { includeState: true }
1046
1202
  }
@@ -1048,6 +1204,32 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1048
1204
  result = invokeResp.result;
1049
1205
  runId = invokeResp.runId;
1050
1206
  executionContext.state = invokeResp.result.state;
1207
+ } else if (isTimeTravel) {
1208
+ const snapshot = await this.mastra?.getStorage()?.loadWorkflowSnapshot({
1209
+ workflowName: step.id,
1210
+ runId: executionContext.runId
1211
+ }) ?? { context: {} };
1212
+ const timeTravelParams = workflows.createTimeTravelExecutionParams({
1213
+ steps: timeTravel.steps.slice(1),
1214
+ inputData: timeTravel.inputData,
1215
+ resumeData: timeTravel.resumeData,
1216
+ context: timeTravel.nestedStepResults?.[step.id] ?? {},
1217
+ nestedStepsContext: timeTravel.nestedStepResults ?? {},
1218
+ snapshot,
1219
+ graph: step.buildExecutionGraph()
1220
+ });
1221
+ const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
1222
+ function: step.getFunction(),
1223
+ data: {
1224
+ timeTravel: timeTravelParams,
1225
+ initialState: executionContext.state ?? {},
1226
+ runId: executionContext.runId,
1227
+ outputOptions: { includeState: true }
1228
+ }
1229
+ });
1230
+ result = invokeResp.result;
1231
+ runId = invokeResp.runId;
1232
+ executionContext.state = invokeResp.result.state;
1051
1233
  } else {
1052
1234
  const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
1053
1235
  function: step.getFunction(),
@@ -1081,23 +1263,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1081
1263
  async () => {
1082
1264
  if (result.status === "failed") {
1083
1265
  await emitter.emit("watch", {
1084
- type: "watch",
1085
- payload: {
1086
- currentStep: {
1087
- id: step.id,
1088
- status: "failed",
1089
- error: result?.error
1090
- },
1091
- workflowState: {
1092
- status: "running",
1093
- steps: stepResults,
1094
- result: null,
1095
- error: null
1096
- }
1097
- },
1098
- eventTimestamp: Date.now()
1099
- });
1100
- await emitter.emit("watch-v2", {
1101
1266
  type: "workflow-step-result",
1102
1267
  payload: {
1103
1268
  id: step.id,
@@ -1116,27 +1281,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1116
1281
  const suspendPath = [stepName, ...stepResult?.suspendPayload?.__workflow_meta?.path ?? []];
1117
1282
  executionContext.suspendedPaths[step.id] = executionContext.executionPath;
1118
1283
  await emitter.emit("watch", {
1119
- type: "watch",
1120
- payload: {
1121
- currentStep: {
1122
- id: step.id,
1123
- status: "suspended",
1124
- payload: stepResult.payload,
1125
- suspendPayload: {
1126
- ...stepResult?.suspendPayload,
1127
- __workflow_meta: { runId, path: suspendPath }
1128
- }
1129
- },
1130
- workflowState: {
1131
- status: "running",
1132
- steps: stepResults,
1133
- result: null,
1134
- error: null
1135
- }
1136
- },
1137
- eventTimestamp: Date.now()
1138
- });
1139
- await emitter.emit("watch-v2", {
1140
1284
  type: "workflow-step-suspended",
1141
1285
  payload: {
1142
1286
  id: step.id,
@@ -1155,23 +1299,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1155
1299
  }
1156
1300
  };
1157
1301
  }
1158
- await emitter.emit("watch", {
1159
- type: "watch",
1160
- payload: {
1161
- currentStep: {
1162
- id: step.id,
1163
- status: "suspended",
1164
- payload: {}
1165
- },
1166
- workflowState: {
1167
- status: "running",
1168
- steps: stepResults,
1169
- result: null,
1170
- error: null
1171
- }
1172
- },
1173
- eventTimestamp: Date.now()
1174
- });
1175
1302
  return {
1176
1303
  executionContext,
1177
1304
  result: {
@@ -1181,23 +1308,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1181
1308
  };
1182
1309
  }
1183
1310
  await emitter.emit("watch", {
1184
- type: "watch",
1185
- payload: {
1186
- currentStep: {
1187
- id: step.id,
1188
- status: "success",
1189
- output: result?.result
1190
- },
1191
- workflowState: {
1192
- status: "running",
1193
- steps: stepResults,
1194
- result: null,
1195
- error: null
1196
- }
1197
- },
1198
- eventTimestamp: Date.now()
1199
- });
1200
- await emitter.emit("watch-v2", {
1201
1311
  type: "workflow-step-result",
1202
1312
  payload: {
1203
1313
  id: step.id,
@@ -1205,7 +1315,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1205
1315
  output: result?.result
1206
1316
  }
1207
1317
  });
1208
- await emitter.emit("watch-v2", {
1318
+ await emitter.emit("watch", {
1209
1319
  type: "workflow-step-finish",
1210
1320
  payload: {
1211
1321
  id: step.id,
@@ -1225,29 +1335,56 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1225
1335
  resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
1226
1336
  };
1227
1337
  }
1338
+ const stepCallId = crypto.randomUUID();
1228
1339
  let stepRes;
1229
1340
  try {
1230
1341
  stepRes = await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}`, async () => {
1231
1342
  let execResults;
1232
1343
  let suspended;
1233
1344
  let bailed;
1345
+ const { resumeData: timeTravelResumeData, validationError: timeTravelResumeValidationError } = await workflows.validateStepResumeData({
1346
+ resumeData: timeTravel?.stepResults[step.id]?.status === "suspended" ? timeTravel?.resumeData : void 0,
1347
+ step
1348
+ });
1349
+ let resumeDataToUse;
1350
+ if (timeTravelResumeData && !timeTravelResumeValidationError) {
1351
+ resumeDataToUse = timeTravelResumeData;
1352
+ } else if (timeTravelResumeData && timeTravelResumeValidationError) {
1353
+ this.logger.warn("Time travel resume data validation failed", {
1354
+ stepId: step.id,
1355
+ error: timeTravelResumeValidationError.message
1356
+ });
1357
+ } else if (resume?.steps[0] === step.id) {
1358
+ resumeDataToUse = resume?.resumePayload;
1359
+ }
1234
1360
  try {
1235
1361
  if (validationError) {
1236
1362
  throw validationError;
1237
1363
  }
1364
+ const retryCount = this.getOrGenerateRetryCount(step.id);
1238
1365
  const result = await step.execute({
1239
1366
  runId: executionContext.runId,
1367
+ workflowId: executionContext.workflowId,
1240
1368
  mastra: this.mastra,
1241
- runtimeContext,
1242
- writableStream,
1369
+ requestContext,
1370
+ retryCount,
1371
+ writer: new tools.ToolStream(
1372
+ {
1373
+ prefix: "workflow-step",
1374
+ callId: stepCallId,
1375
+ name: step.id,
1376
+ runId: executionContext.runId
1377
+ },
1378
+ writableStream
1379
+ ),
1243
1380
  state: executionContext?.state ?? {},
1244
1381
  setState: (state) => {
1245
1382
  executionContext.state = state;
1246
1383
  },
1247
1384
  inputData,
1248
- resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
1385
+ resumeData: resumeDataToUse,
1249
1386
  tracingContext: {
1250
- currentSpan: stepAISpan
1387
+ currentSpan: stepSpan
1251
1388
  },
1252
1389
  getInitData: () => stepResults?.input,
1253
1390
  getStepResult: workflows.getStepResult.bind(this, stepResults),
@@ -1267,13 +1404,11 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1267
1404
  bail: (result2) => {
1268
1405
  bailed = { payload: result2 };
1269
1406
  },
1270
- resume: {
1271
- steps: resume?.steps?.slice(1) || [],
1272
- resumePayload: resume?.resumePayload,
1273
- // @ts-ignore
1274
- runId: stepResults[step.id]?.suspendPayload?.__workflow_meta?.runId
1407
+ abort: () => {
1408
+ abortController?.abort();
1275
1409
  },
1276
1410
  [_constants.EMITTER_SYMBOL]: emitter,
1411
+ [_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
1277
1412
  engine: {
1278
1413
  step: this.inngestStep
1279
1414
  },
@@ -1286,8 +1421,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1286
1421
  startedAt,
1287
1422
  endedAt,
1288
1423
  payload: inputData,
1289
- resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
1290
- resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
1424
+ resumedAt: resumeDataToUse ? startedAt : void 0,
1425
+ resumePayload: resumeDataToUse
1291
1426
  };
1292
1427
  } catch (e) {
1293
1428
  const stepFailure = {
@@ -1296,12 +1431,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1296
1431
  error: e instanceof Error ? e.message : String(e),
1297
1432
  endedAt: Date.now(),
1298
1433
  startedAt,
1299
- resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
1300
- resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
1434
+ resumedAt: resumeDataToUse ? startedAt : void 0,
1435
+ resumePayload: resumeDataToUse
1301
1436
  };
1302
1437
  execResults = stepFailure;
1303
1438
  const fallbackErrorMessage = `Step ${step.id} failed`;
1304
- stepAISpan?.error({ error: new Error(execResults.error ?? fallbackErrorMessage) });
1439
+ stepSpan?.error({ error: new Error(execResults.error ?? fallbackErrorMessage) });
1305
1440
  throw new inngest.RetryAfterError(execResults.error ?? fallbackErrorMessage, executionContext.retryConfig.delay, {
1306
1441
  cause: execResults
1307
1442
  });
@@ -1310,11 +1445,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1310
1445
  execResults = {
1311
1446
  status: "suspended",
1312
1447
  suspendPayload: suspended.payload,
1448
+ ...execResults.output ? { suspendOutput: execResults.output } : {},
1313
1449
  payload: inputData,
1314
1450
  suspendedAt: Date.now(),
1315
1451
  startedAt,
1316
- resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
1317
- resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
1452
+ resumedAt: resumeDataToUse ? startedAt : void 0,
1453
+ resumePayload: resumeDataToUse
1318
1454
  };
1319
1455
  } else if (bailed) {
1320
1456
  execResults = {
@@ -1325,24 +1461,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1325
1461
  startedAt
1326
1462
  };
1327
1463
  }
1328
- await emitter.emit("watch", {
1329
- type: "watch",
1330
- payload: {
1331
- currentStep: {
1332
- id: step.id,
1333
- ...execResults
1334
- },
1335
- workflowState: {
1336
- status: "running",
1337
- steps: { ...stepResults, [step.id]: execResults },
1338
- result: null,
1339
- error: null
1340
- }
1341
- },
1342
- eventTimestamp: Date.now()
1343
- });
1344
1464
  if (execResults.status === "suspended") {
1345
- await emitter.emit("watch-v2", {
1465
+ await emitter.emit("watch", {
1346
1466
  type: "workflow-step-suspended",
1347
1467
  payload: {
1348
1468
  id: step.id,
@@ -1350,14 +1470,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1350
1470
  }
1351
1471
  });
1352
1472
  } else {
1353
- await emitter.emit("watch-v2", {
1473
+ await emitter.emit("watch", {
1354
1474
  type: "workflow-step-result",
1355
1475
  payload: {
1356
1476
  id: step.id,
1357
1477
  ...execResults
1358
1478
  }
1359
1479
  });
1360
- await emitter.emit("watch-v2", {
1480
+ await emitter.emit("watch", {
1361
1481
  type: "workflow-step-finish",
1362
1482
  payload: {
1363
1483
  id: step.id,
@@ -1365,7 +1485,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1365
1485
  }
1366
1486
  });
1367
1487
  }
1368
- stepAISpan?.end({ output: execResults });
1488
+ stepSpan?.end({ output: execResults });
1369
1489
  return { result: execResults, executionContext, stepResults };
1370
1490
  });
1371
1491
  } catch (e) {
@@ -1395,15 +1515,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1395
1515
  output: stepRes.result,
1396
1516
  workflowId: executionContext.workflowId,
1397
1517
  stepId: step.id,
1398
- runtimeContext,
1518
+ requestContext,
1399
1519
  disableScorers,
1400
- tracingContext: { currentSpan: stepAISpan }
1520
+ tracingContext: { currentSpan: stepSpan }
1401
1521
  });
1402
1522
  }
1403
1523
  });
1404
1524
  }
1405
1525
  Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
1406
- Object.assign(stepResults, stepRes.stepResults);
1407
1526
  executionContext.state = stepRes.executionContext.state;
1408
1527
  return stepRes.result;
1409
1528
  }
@@ -1431,17 +1550,17 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1431
1550
  resourceId,
1432
1551
  snapshot: {
1433
1552
  runId,
1553
+ status: workflowStatus,
1434
1554
  value: executionContext.state,
1435
1555
  context: stepResults,
1436
- activePaths: [],
1556
+ activePaths: executionContext.executionPath,
1557
+ activeStepsPath: executionContext.activeStepsPath,
1437
1558
  suspendedPaths: executionContext.suspendedPaths,
1438
1559
  resumeLabels: executionContext.resumeLabels,
1439
1560
  waitingPaths: {},
1440
1561
  serializedStepGraph,
1441
- status: workflowStatus,
1442
1562
  result,
1443
1563
  error,
1444
- // @ts-ignore
1445
1564
  timestamp: Date.now()
1446
1565
  }
1447
1566
  });
@@ -1454,17 +1573,18 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1454
1573
  entry,
1455
1574
  prevOutput,
1456
1575
  stepResults,
1576
+ timeTravel,
1457
1577
  resume,
1458
1578
  executionContext,
1459
1579
  emitter,
1460
1580
  abortController,
1461
- runtimeContext,
1581
+ requestContext,
1462
1582
  writableStream,
1463
1583
  disableScorers,
1464
1584
  tracingContext
1465
1585
  }) {
1466
1586
  const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
1467
- type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL,
1587
+ type: observability.SpanType.WORKFLOW_CONDITIONAL,
1468
1588
  name: `conditional: '${entry.conditions.length} conditions'`,
1469
1589
  input: prevOutput,
1470
1590
  attributes: {
@@ -1477,7 +1597,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1477
1597
  entry.conditions.map(
1478
1598
  (cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
1479
1599
  const evalSpan = conditionalSpan?.createChildSpan({
1480
- type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL_EVAL,
1600
+ type: observability.SpanType.WORKFLOW_CONDITIONAL_EVAL,
1481
1601
  name: `condition: '${index}'`,
1482
1602
  input: prevOutput,
1483
1603
  attributes: {
@@ -1492,8 +1612,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1492
1612
  runId,
1493
1613
  workflowId,
1494
1614
  mastra: this.mastra,
1495
- runtimeContext,
1496
- runCount: -1,
1615
+ requestContext,
1497
1616
  retryCount: -1,
1498
1617
  inputData: prevOutput,
1499
1618
  state: executionContext.state,
@@ -1515,7 +1634,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1515
1634
  },
1516
1635
  [_constants.EMITTER_SYMBOL]: emitter,
1517
1636
  [_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
1518
- // TODO: add streamVNext support
1519
1637
  engine: {
1520
1638
  step: this.inngestStep
1521
1639
  },
@@ -1574,10 +1692,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1574
1692
  prevOutput,
1575
1693
  stepResults,
1576
1694
  resume,
1695
+ timeTravel,
1577
1696
  executionContext: {
1578
1697
  workflowId,
1579
1698
  runId,
1580
1699
  executionPath: [...executionContext.executionPath, index],
1700
+ activeStepsPath: executionContext.activeStepsPath,
1581
1701
  suspendedPaths: executionContext.suspendedPaths,
1582
1702
  resumeLabels: executionContext.resumeLabels,
1583
1703
  retryConfig: executionContext.retryConfig,
@@ -1585,7 +1705,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1585
1705
  },
1586
1706
  emitter,
1587
1707
  abortController,
1588
- runtimeContext,
1708
+ requestContext,
1589
1709
  writableStream,
1590
1710
  disableScorers,
1591
1711
  tracingContext: {
@@ -1601,13 +1721,19 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1601
1721
  if (hasFailed) {
1602
1722
  execResults = { status: "failed", error: hasFailed.error };
1603
1723
  } else if (hasSuspended) {
1604
- execResults = { status: "suspended", suspendPayload: hasSuspended.suspendPayload };
1724
+ execResults = {
1725
+ status: "suspended",
1726
+ suspendPayload: hasSuspended.suspendPayload,
1727
+ ...hasSuspended.suspendOutput ? { suspendOutput: hasSuspended.suspendOutput } : {}
1728
+ };
1605
1729
  } else {
1606
1730
  execResults = {
1607
1731
  status: "success",
1608
1732
  output: results.reduce((acc, result, index) => {
1609
1733
  if (result.status === "success") {
1610
- acc[stepsToRun[index].step.id] = result.output;
1734
+ if ("step" in stepsToRun[index]) {
1735
+ acc[stepsToRun[index].step.id] = result.output;
1736
+ }
1611
1737
  }
1612
1738
  return acc;
1613
1739
  }, {})