@mastra/inngest 0.0.0-fix-zod4-schema-validation-20251212180638 → 0.0.0-fix-local-pkg-cwd-20251224015404

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
@@ -136,6 +136,18 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
136
136
  getEngineContext() {
137
137
  return { step: this.inngestStep };
138
138
  }
139
+ /**
140
+ * For Inngest, lifecycle callbacks are invoked in the workflow's finalize step
141
+ * (wrapped in step.run for durability), not in execute(). Override to skip.
142
+ */
143
+ async invokeLifecycleCallbacks(_result) {
144
+ }
145
+ /**
146
+ * Actually invoke the lifecycle callbacks. Called from workflow.ts finalize step.
147
+ */
148
+ async invokeLifecycleCallbacksInternal(result) {
149
+ return super.invokeLifecycleCallbacks(result);
150
+ }
139
151
  /**
140
152
  * Execute nested InngestWorkflow using inngestStep.invoke() for durability.
141
153
  * This MUST be called directly (not inside step.run()) due to Inngest constraints.
@@ -144,7 +156,18 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
144
156
  if (!(params.step instanceof InngestWorkflow)) {
145
157
  return null;
146
158
  }
147
- const { step, stepResults, executionContext, resume, timeTravel, prevOutput, inputData, pubsub, startedAt } = params;
159
+ const {
160
+ step,
161
+ stepResults,
162
+ executionContext,
163
+ resume,
164
+ timeTravel,
165
+ prevOutput,
166
+ inputData,
167
+ pubsub,
168
+ startedAt,
169
+ perStep
170
+ } = params;
148
171
  const isResume = !!resume?.steps?.length;
149
172
  let result;
150
173
  let runId;
@@ -152,7 +175,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
152
175
  try {
153
176
  if (isResume) {
154
177
  runId = stepResults[resume?.steps?.[0] ?? ""]?.suspendPayload?.__workflow_meta?.runId ?? randomUUID();
155
- const snapshot = await this.mastra?.getStorage()?.loadWorkflowSnapshot({
178
+ const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
179
+ const snapshot = await workflowsStore?.loadWorkflowSnapshot({
156
180
  workflowName: step.id,
157
181
  runId
158
182
  });
@@ -169,14 +193,16 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
169
193
  resumePayload: resume.resumePayload,
170
194
  resumePath: resume.steps?.[1] ? snapshot?.suspendedPaths?.[resume.steps?.[1]] : void 0
171
195
  },
172
- outputOptions: { includeState: true }
196
+ outputOptions: { includeState: true },
197
+ perStep
173
198
  }
174
199
  });
175
200
  result = invokeResp.result;
176
201
  runId = invokeResp.runId;
177
202
  executionContext.state = invokeResp.result.state;
178
203
  } else if (isTimeTravel) {
179
- const snapshot = await this.mastra?.getStorage()?.loadWorkflowSnapshot({
204
+ const workflowsStoreForTimeTravel = await this.mastra?.getStorage()?.getStore("workflows");
205
+ const snapshot = await workflowsStoreForTimeTravel?.loadWorkflowSnapshot({
180
206
  workflowName: step.id,
181
207
  runId: executionContext.runId
182
208
  }) ?? { context: {} };
@@ -195,7 +221,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
195
221
  timeTravel: timeTravelParams,
196
222
  initialState: executionContext.state ?? {},
197
223
  runId: executionContext.runId,
198
- outputOptions: { includeState: true }
224
+ outputOptions: { includeState: true },
225
+ perStep
199
226
  }
200
227
  });
201
228
  result = invokeResp.result;
@@ -207,7 +234,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
207
234
  data: {
208
235
  inputData,
209
236
  initialState: executionContext.state ?? {},
210
- outputOptions: { includeState: true }
237
+ outputOptions: { includeState: true },
238
+ perStep
211
239
  }
212
240
  });
213
241
  result = invokeResp.result;
@@ -246,7 +274,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
246
274
  }
247
275
  }
248
276
  });
249
- return { executionContext, result: { status: "failed", error: result?.error } };
277
+ return { executionContext, result: { status: "failed", error: result?.error, endedAt: Date.now() } };
250
278
  } else if (result.status === "suspended") {
251
279
  const suspendedSteps = Object.entries(result.steps).filter(([_stepName, stepResult]) => {
252
280
  const stepRes = stepResult;
@@ -270,6 +298,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
270
298
  executionContext,
271
299
  result: {
272
300
  status: "suspended",
301
+ suspendedAt: Date.now(),
273
302
  payload: stepResult.payload,
274
303
  suspendPayload: {
275
304
  ...stepResult?.suspendPayload,
@@ -282,6 +311,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
282
311
  executionContext,
283
312
  result: {
284
313
  status: "suspended",
314
+ suspendedAt: Date.now(),
285
315
  payload: {}
286
316
  }
287
317
  };
@@ -303,9 +333,34 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
303
333
  executionContext,
304
334
  result: {
305
335
  status: "tripwire",
306
- tripwire: result?.tripwire
336
+ tripwire: result?.tripwire,
337
+ endedAt: Date.now()
307
338
  }
308
339
  };
340
+ } else if (perStep || result.status === "paused") {
341
+ await pubsub.publish(`workflow.events.v2.${executionContext.runId}`, {
342
+ type: "watch",
343
+ runId: executionContext.runId,
344
+ data: {
345
+ type: "workflow-step-result",
346
+ payload: {
347
+ id: step.id,
348
+ status: "paused"
349
+ }
350
+ }
351
+ });
352
+ await pubsub.publish(`workflow.events.v2.${executionContext.runId}`, {
353
+ type: "watch",
354
+ runId: executionContext.runId,
355
+ data: {
356
+ type: "workflow-step-finish",
357
+ payload: {
358
+ id: step.id,
359
+ metadata: {}
360
+ }
361
+ }
362
+ });
363
+ return { executionContext, result: { status: "paused" } };
309
364
  }
310
365
  await pubsub.publish(`workflow.events.v2.${executionContext.runId}`, {
311
366
  type: "watch",
@@ -330,14 +385,13 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
330
385
  }
331
386
  }
332
387
  });
333
- return { executionContext, result: { status: "success", output: result?.result } };
388
+ return { executionContext, result: { status: "success", output: result?.result, endedAt: Date.now() } };
334
389
  }
335
390
  );
336
391
  Object.assign(executionContext, res.executionContext);
337
392
  return {
338
393
  ...res.result,
339
394
  startedAt,
340
- endedAt: Date.now(),
341
395
  payload: inputData,
342
396
  resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
343
397
  resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
@@ -506,6 +560,7 @@ var InngestRun = class extends Run {
506
560
  async getRunOutput(eventId, maxWaitMs = 3e5) {
507
561
  const startTime = Date.now();
508
562
  const storage = this.#mastra?.getStorage();
563
+ const workflowsStore = await storage?.getStore("workflows");
509
564
  while (Date.now() - startTime < maxWaitMs) {
510
565
  let runs;
511
566
  try {
@@ -522,7 +577,7 @@ var InngestRun = class extends Run {
522
577
  return runs[0];
523
578
  }
524
579
  if (runs?.[0]?.status === "Failed") {
525
- const snapshot = await storage?.loadWorkflowSnapshot({
580
+ const snapshot = await workflowsStore?.loadWorkflowSnapshot({
526
581
  workflowName: this.workflowId,
527
582
  runId: this.runId
528
583
  });
@@ -541,7 +596,7 @@ var InngestRun = class extends Run {
541
596
  };
542
597
  }
543
598
  if (runs?.[0]?.status === "Cancelled") {
544
- const snapshot = await storage?.loadWorkflowSnapshot({
599
+ const snapshot = await workflowsStore?.loadWorkflowSnapshot({
545
600
  workflowName: this.workflowId,
546
601
  runId: this.runId
547
602
  });
@@ -559,12 +614,13 @@ var InngestRun = class extends Run {
559
614
  runId: this.runId
560
615
  }
561
616
  });
562
- const snapshot = await storage?.loadWorkflowSnapshot({
617
+ const workflowsStore = await storage?.getStore("workflows");
618
+ const snapshot = await workflowsStore?.loadWorkflowSnapshot({
563
619
  workflowName: this.workflowId,
564
620
  runId: this.runId
565
621
  });
566
622
  if (snapshot) {
567
- await storage?.persistWorkflowSnapshot({
623
+ await workflowsStore?.persistWorkflowSnapshot({
568
624
  workflowName: this.workflowId,
569
625
  runId: this.runId,
570
626
  resourceId: this.resourceId,
@@ -586,7 +642,8 @@ var InngestRun = class extends Run {
586
642
  * Use this when you don't need to wait for the result or want to avoid polling failures.
587
643
  */
588
644
  async startAsync(params) {
589
- await this.#mastra.getStorage()?.persistWorkflowSnapshot({
645
+ const workflowsStore = await this.#mastra.getStorage()?.getStore("workflows");
646
+ await workflowsStore?.persistWorkflowSnapshot({
590
647
  workflowName: this.workflowId,
591
648
  runId: this.runId,
592
649
  resourceId: this.resourceId,
@@ -615,7 +672,8 @@ var InngestRun = class extends Run {
615
672
  resourceId: this.resourceId,
616
673
  outputOptions: params.outputOptions,
617
674
  tracingOptions: params.tracingOptions,
618
- requestContext: params.requestContext ? Object.fromEntries(params.requestContext.entries()) : {}
675
+ requestContext: params.requestContext ? Object.fromEntries(params.requestContext.entries()) : {},
676
+ perStep: params.perStep
619
677
  }
620
678
  });
621
679
  const eventId = eventOutput.ids[0];
@@ -630,9 +688,11 @@ var InngestRun = class extends Run {
630
688
  outputOptions,
631
689
  tracingOptions,
632
690
  format,
633
- requestContext
691
+ requestContext,
692
+ perStep
634
693
  }) {
635
- await this.#mastra.getStorage()?.persistWorkflowSnapshot({
694
+ const workflowsStore = await this.#mastra.getStorage()?.getStore("workflows");
695
+ await workflowsStore?.persistWorkflowSnapshot({
636
696
  workflowName: this.workflowId,
637
697
  runId: this.runId,
638
698
  resourceId: this.resourceId,
@@ -662,7 +722,8 @@ var InngestRun = class extends Run {
662
722
  outputOptions,
663
723
  tracingOptions,
664
724
  format,
665
- requestContext: requestContext ? Object.fromEntries(requestContext.entries()) : {}
725
+ requestContext: requestContext ? Object.fromEntries(requestContext.entries()) : {},
726
+ perStep
666
727
  }
667
728
  });
668
729
  const eventId = eventOutput.ids[0];
@@ -698,7 +759,8 @@ var InngestRun = class extends Run {
698
759
  (step) => typeof step === "string" ? step : step?.id
699
760
  );
700
761
  }
701
- const snapshot = await storage?.loadWorkflowSnapshot({
762
+ const workflowsStore = await storage?.getStore("workflows");
763
+ const snapshot = await workflowsStore?.loadWorkflowSnapshot({
702
764
  workflowName: this.workflowId,
703
765
  runId: this.runId
704
766
  });
@@ -721,7 +783,8 @@ var InngestRun = class extends Run {
721
783
  resumePayload: resumeDataToUse,
722
784
  resumePath: steps?.[0] ? snapshot?.suspendedPaths?.[steps?.[0]] : void 0
723
785
  },
724
- requestContext: mergedRequestContext
786
+ requestContext: mergedRequestContext,
787
+ perStep: params.perStep
725
788
  }
726
789
  });
727
790
  const eventId = eventOutput.ids[0];
@@ -760,12 +823,13 @@ var InngestRun = class extends Run {
760
823
  throw new Error("No steps provided to timeTravel");
761
824
  }
762
825
  const storage = this.#mastra?.getStorage();
763
- const snapshot = await storage?.loadWorkflowSnapshot({
826
+ const workflowsStore = await storage?.getStore("workflows");
827
+ const snapshot = await workflowsStore?.loadWorkflowSnapshot({
764
828
  workflowName: this.workflowId,
765
829
  runId: this.runId
766
830
  });
767
831
  if (!snapshot) {
768
- await storage?.persistWorkflowSnapshot({
832
+ await workflowsStore?.persistWorkflowSnapshot({
769
833
  workflowName: this.workflowId,
770
834
  runId: this.runId,
771
835
  resourceId: this.resourceId,
@@ -799,7 +863,8 @@ var InngestRun = class extends Run {
799
863
  nestedStepsContext: params.nestedStepsContext,
800
864
  snapshot: snapshot ?? { context: {} },
801
865
  graph: this.executionGraph,
802
- initialState: params.initialState
866
+ initialState: params.initialState,
867
+ perStep: params.perStep
803
868
  });
804
869
  const eventOutput = await this.inngest.send({
805
870
  name: `workflow.${this.workflowId}`,
@@ -811,7 +876,8 @@ var InngestRun = class extends Run {
811
876
  timeTravel: timeTravelData,
812
877
  tracingOptions: params.tracingOptions,
813
878
  outputOptions: params.outputOptions,
814
- requestContext: params.requestContext ? Object.fromEntries(params.requestContext.entries()) : {}
879
+ requestContext: params.requestContext ? Object.fromEntries(params.requestContext.entries()) : {},
880
+ perStep: params.perStep
815
881
  }
816
882
  });
817
883
  const eventId = eventOutput.ids[0];
@@ -902,7 +968,8 @@ var InngestRun = class extends Run {
902
968
  tracingOptions,
903
969
  closeOnSuspend = true,
904
970
  initialState,
905
- outputOptions
971
+ outputOptions,
972
+ perStep
906
973
  } = {}) {
907
974
  if (this.closeStreamAction && this.streamOutput) {
908
975
  return this.streamOutput;
@@ -938,7 +1005,8 @@ var InngestRun = class extends Run {
938
1005
  initialState,
939
1006
  tracingOptions,
940
1007
  outputOptions,
941
- format: "vnext"
1008
+ format: "vnext",
1009
+ perStep
942
1010
  });
943
1011
  let executionResults;
944
1012
  try {
@@ -981,7 +1049,8 @@ var InngestRun = class extends Run {
981
1049
  nestedStepsContext,
982
1050
  requestContext,
983
1051
  tracingOptions,
984
- outputOptions
1052
+ outputOptions,
1053
+ perStep
985
1054
  }) {
986
1055
  this.closeStreamAction = async () => {
987
1056
  };
@@ -1016,7 +1085,8 @@ var InngestRun = class extends Run {
1016
1085
  initialState,
1017
1086
  requestContext,
1018
1087
  tracingOptions,
1019
- outputOptions
1088
+ outputOptions,
1089
+ perStep
1020
1090
  });
1021
1091
  self.executionResults = executionResultsPromise;
1022
1092
  let executionResults;
@@ -1078,7 +1148,11 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
1078
1148
  this.logger.debug("Cannot get workflow runs. Mastra engine is not initialized");
1079
1149
  return { runs: [], total: 0 };
1080
1150
  }
1081
- return storage.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
1151
+ const workflowsStore = await storage.getStore("workflows");
1152
+ if (!workflowsStore) {
1153
+ return { runs: [], total: 0 };
1154
+ }
1155
+ return workflowsStore.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
1082
1156
  }
1083
1157
  async getWorkflowRunById(runId) {
1084
1158
  const storage = this.#mastra?.getStorage();
@@ -1086,7 +1160,11 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
1086
1160
  this.logger.debug("Cannot get workflow runs. Mastra engine is not initialized");
1087
1161
  return this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null;
1088
1162
  }
1089
- const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
1163
+ const workflowsStore = await storage.getStore("workflows");
1164
+ if (!workflowsStore) {
1165
+ return this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null;
1166
+ }
1167
+ const run = await workflowsStore.getWorkflowRunById({ runId, workflowName: this.id });
1090
1168
  return run ?? (this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null);
1091
1169
  }
1092
1170
  __registerMastra(mastra) {
@@ -1132,9 +1210,12 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
1132
1210
  workflowStatus: run.workflowRunStatus,
1133
1211
  stepResults: {}
1134
1212
  });
1135
- const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, false);
1213
+ const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, {
1214
+ withNestedWorkflows: false
1215
+ });
1136
1216
  if (!workflowSnapshotInStorage && shouldPersistSnapshot) {
1137
- await this.mastra?.getStorage()?.persistWorkflowSnapshot({
1217
+ const workflowsStore = await this.mastra?.getStorage()?.getStore("workflows");
1218
+ await workflowsStore?.persistWorkflowSnapshot({
1138
1219
  workflowName: this.id,
1139
1220
  runId: runIdToUse,
1140
1221
  resourceId: options?.resourceId,
@@ -1171,7 +1252,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
1171
1252
  },
1172
1253
  { event: `workflow.${this.id}` },
1173
1254
  async ({ event, step, attempt, publish }) => {
1174
- let { inputData, initialState, runId, resourceId, resume, outputOptions, format, timeTravel } = event.data;
1255
+ let { inputData, initialState, runId, resourceId, resume, outputOptions, format, timeTravel, perStep } = event.data;
1175
1256
  if (!runId) {
1176
1257
  runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
1177
1258
  return randomUUID();
@@ -1192,6 +1273,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
1192
1273
  requestContext: new RequestContext(Object.entries(event.data.requestContext ?? {})),
1193
1274
  resume,
1194
1275
  timeTravel,
1276
+ perStep,
1195
1277
  format,
1196
1278
  abortController: new AbortController(),
1197
1279
  // currentSpan: undefined, // TODO: Pass actual parent Span from workflow execution context
@@ -1209,6 +1291,9 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
1209
1291
  }
1210
1292
  });
1211
1293
  await step.run(`workflow.${this.id}.finalize`, async () => {
1294
+ if (result.status !== "paused") {
1295
+ await engine.invokeLifecycleCallbacksInternal(result);
1296
+ }
1212
1297
  if (result.status === "failed") {
1213
1298
  throw new NonRetriableError(`Workflow failed`, {
1214
1299
  cause: result