@mastra/inngest 0.0.0-ai-v5-20250626003446 → 0.0.0-ai-v5-20250710191716

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
@@ -10,13 +10,17 @@ import { z } from 'zod';
10
10
  // src/index.ts
11
11
  function serve({ mastra, inngest }) {
12
12
  const wfs = mastra.getWorkflows();
13
- const functions = Object.values(wfs).flatMap((wf) => {
14
- if (wf instanceof InngestWorkflow) {
15
- wf.__registerMastra(mastra);
16
- return wf.getFunctions();
17
- }
18
- return [];
19
- });
13
+ const functions = Array.from(
14
+ new Set(
15
+ Object.values(wfs).flatMap((wf) => {
16
+ if (wf instanceof InngestWorkflow) {
17
+ wf.__registerMastra(mastra);
18
+ return wf.getFunctions();
19
+ }
20
+ return [];
21
+ })
22
+ )
23
+ );
20
24
  return serve$1({
21
25
  client: inngest,
22
26
  functions
@@ -46,8 +50,15 @@ var InngestRun = class extends Run {
46
50
  while (runs?.[0]?.status !== "Completed" || runs?.[0]?.event_id !== eventId) {
47
51
  await new Promise((resolve) => setTimeout(resolve, 1e3));
48
52
  runs = await this.getRuns(eventId);
49
- if (runs?.[0]?.status === "Failed" || runs?.[0]?.status === "Cancelled") {
53
+ if (runs?.[0]?.status === "Failed") {
54
+ console.log("run", runs?.[0]);
50
55
  throw new Error(`Function run ${runs?.[0]?.status}`);
56
+ } else if (runs?.[0]?.status === "Cancelled") {
57
+ const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
58
+ workflowName: this.workflowId,
59
+ runId: this.runId
60
+ });
61
+ return { output: { result: { steps: snapshot?.context, status: "canceled" } } };
51
62
  }
52
63
  }
53
64
  return runs?.[0];
@@ -58,6 +69,28 @@ var InngestRun = class extends Run {
58
69
  data
59
70
  });
60
71
  }
72
+ async cancel() {
73
+ await this.inngest.send({
74
+ name: `cancel.workflow.${this.workflowId}`,
75
+ data: {
76
+ runId: this.runId
77
+ }
78
+ });
79
+ const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
80
+ workflowName: this.workflowId,
81
+ runId: this.runId
82
+ });
83
+ if (snapshot) {
84
+ await this.#mastra?.storage?.persistWorkflowSnapshot({
85
+ workflowName: this.workflowId,
86
+ runId: this.runId,
87
+ snapshot: {
88
+ ...snapshot,
89
+ status: "canceled"
90
+ }
91
+ });
92
+ }
93
+ }
61
94
  async start({
62
95
  inputData
63
96
  }) {
@@ -91,7 +124,9 @@ var InngestRun = class extends Run {
91
124
  if (result.status === "failed") {
92
125
  result.error = new Error(result.error);
93
126
  }
94
- this.cleanup?.();
127
+ if (result.status !== "suspended") {
128
+ this.cleanup?.();
129
+ }
95
130
  return result;
96
131
  }
97
132
  async resume(params) {
@@ -277,13 +312,55 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
277
312
  this.runs.set(runIdToUse, run);
278
313
  return run;
279
314
  }
315
+ async createRunAsync(options) {
316
+ const runIdToUse = options?.runId || randomUUID();
317
+ const run = this.runs.get(runIdToUse) ?? new InngestRun(
318
+ {
319
+ workflowId: this.id,
320
+ runId: runIdToUse,
321
+ executionEngine: this.executionEngine,
322
+ executionGraph: this.executionGraph,
323
+ serializedStepGraph: this.serializedStepGraph,
324
+ mastra: this.#mastra,
325
+ retryConfig: this.retryConfig,
326
+ cleanup: () => this.runs.delete(runIdToUse)
327
+ },
328
+ this.inngest
329
+ );
330
+ this.runs.set(runIdToUse, run);
331
+ const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse);
332
+ if (!workflowSnapshotInStorage) {
333
+ await this.mastra?.getStorage()?.persistWorkflowSnapshot({
334
+ workflowName: this.id,
335
+ runId: runIdToUse,
336
+ snapshot: {
337
+ runId: runIdToUse,
338
+ status: "pending",
339
+ value: {},
340
+ context: {},
341
+ activePaths: [],
342
+ serializedStepGraph: this.serializedStepGraph,
343
+ suspendedPaths: {},
344
+ result: void 0,
345
+ error: void 0,
346
+ // @ts-ignore
347
+ timestamp: Date.now()
348
+ }
349
+ });
350
+ }
351
+ return run;
352
+ }
280
353
  getFunction() {
281
354
  if (this.function) {
282
355
  return this.function;
283
356
  }
284
357
  this.function = this.inngest.createFunction(
285
- // @ts-ignore
286
- { id: `workflow.${this.id}`, retries: this.retryConfig?.attempts ?? 0 },
358
+ {
359
+ id: `workflow.${this.id}`,
360
+ // @ts-ignore
361
+ retries: this.retryConfig?.attempts ?? 0,
362
+ cancelOn: [{ event: `cancel.workflow.${this.id}` }]
363
+ },
287
364
  { event: `workflow.${this.id}` },
288
365
  async ({ event, step, attempt, publish }) => {
289
366
  let { inputData, runId, resume } = event.data;
@@ -325,7 +402,8 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
325
402
  retryConfig: this.retryConfig,
326
403
  runtimeContext: new RuntimeContext(),
327
404
  // TODO
328
- resume
405
+ resume,
406
+ abortController: new AbortController()
329
407
  });
330
408
  return { result, runId };
331
409
  }
@@ -369,7 +447,7 @@ function createStep(params) {
369
447
  outputSchema: z.object({
370
448
  text: z.string()
371
449
  }),
372
- execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext }) => {
450
+ execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort }) => {
373
451
  let streamPromise = {};
374
452
  streamPromise.promise = new Promise((resolve, reject) => {
375
453
  streamPromise.resolve = resolve;
@@ -389,8 +467,12 @@ function createStep(params) {
389
467
  runtimeContext,
390
468
  onFinish: (result) => {
391
469
  streamPromise.resolve(result.text);
392
- }
470
+ },
471
+ abortSignal
393
472
  });
473
+ if (abortSignal.aborted) {
474
+ return abort();
475
+ }
394
476
  for await (const chunk of fullStream) {
395
477
  switch (chunk.type) {
396
478
  case "text":
@@ -565,6 +647,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
565
647
  resume,
566
648
  prevOutput,
567
649
  emitter,
650
+ abortController,
568
651
  runtimeContext
569
652
  }) {
570
653
  return super.executeStep({
@@ -576,11 +659,107 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
576
659
  resume,
577
660
  prevOutput,
578
661
  emitter,
662
+ abortController,
579
663
  runtimeContext
580
664
  });
581
665
  }
582
- async executeSleep({ id, duration }) {
583
- await this.inngestStep.sleep(id, duration);
666
+ // async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
667
+ // await this.inngestStep.sleep(id, duration);
668
+ // }
669
+ async executeSleep({
670
+ workflowId,
671
+ runId,
672
+ entry,
673
+ prevOutput,
674
+ stepResults,
675
+ emitter,
676
+ abortController,
677
+ runtimeContext
678
+ }) {
679
+ let { duration, fn } = entry;
680
+ if (fn) {
681
+ duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
682
+ return await fn({
683
+ runId,
684
+ mastra: this.mastra,
685
+ runtimeContext,
686
+ inputData: prevOutput,
687
+ runCount: -1,
688
+ getInitData: () => stepResults?.input,
689
+ getStepResult: (step) => {
690
+ if (!step?.id) {
691
+ return null;
692
+ }
693
+ const result = stepResults[step.id];
694
+ if (result?.status === "success") {
695
+ return result.output;
696
+ }
697
+ return null;
698
+ },
699
+ // TODO: this function shouldn't have suspend probably?
700
+ suspend: async (_suspendPayload) => {
701
+ },
702
+ bail: () => {
703
+ },
704
+ abort: () => {
705
+ abortController?.abort();
706
+ },
707
+ [EMITTER_SYMBOL]: emitter,
708
+ engine: { step: this.inngestStep },
709
+ abortSignal: abortController?.signal
710
+ });
711
+ });
712
+ }
713
+ await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
714
+ }
715
+ async executeSleepUntil({
716
+ workflowId,
717
+ runId,
718
+ entry,
719
+ prevOutput,
720
+ stepResults,
721
+ emitter,
722
+ abortController,
723
+ runtimeContext
724
+ }) {
725
+ let { date, fn } = entry;
726
+ if (fn) {
727
+ date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
728
+ return await fn({
729
+ runId,
730
+ mastra: this.mastra,
731
+ runtimeContext,
732
+ inputData: prevOutput,
733
+ runCount: -1,
734
+ getInitData: () => stepResults?.input,
735
+ getStepResult: (step) => {
736
+ if (!step?.id) {
737
+ return null;
738
+ }
739
+ const result = stepResults[step.id];
740
+ if (result?.status === "success") {
741
+ return result.output;
742
+ }
743
+ return null;
744
+ },
745
+ // TODO: this function shouldn't have suspend probably?
746
+ suspend: async (_suspendPayload) => {
747
+ },
748
+ bail: () => {
749
+ },
750
+ abort: () => {
751
+ abortController?.abort();
752
+ },
753
+ [EMITTER_SYMBOL]: emitter,
754
+ engine: { step: this.inngestStep },
755
+ abortSignal: abortController?.signal
756
+ });
757
+ });
758
+ }
759
+ if (!(date instanceof Date)) {
760
+ return;
761
+ }
762
+ await this.inngestStep.sleepUntil(entry.id, date);
584
763
  }
585
764
  async executeWaitForEvent({ event, timeout }) {
586
765
  const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
@@ -599,6 +778,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
599
778
  resume,
600
779
  prevOutput,
601
780
  emitter,
781
+ abortController,
602
782
  runtimeContext
603
783
  }) {
604
784
  const startedAt = await this.inngestStep.run(
@@ -629,7 +809,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
629
809
  await emitter.emit("watch-v2", {
630
810
  type: "step-start",
631
811
  payload: {
632
- id: step.id
812
+ id: step.id,
813
+ status: "running",
814
+ payload: prevOutput,
815
+ startedAt: startedAt2
633
816
  }
634
817
  });
635
818
  return startedAt2;
@@ -697,7 +880,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
697
880
  type: "step-result",
698
881
  payload: {
699
882
  id: step.id,
700
- status: "failed"
883
+ status: "failed",
884
+ error: result?.error,
885
+ payload: prevOutput
701
886
  }
702
887
  });
703
888
  return { executionContext, result: { status: "failed", error: result?.error } };
@@ -729,7 +914,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
729
914
  await emitter.emit("watch-v2", {
730
915
  type: "step-suspended",
731
916
  payload: {
732
- id: step.id
917
+ id: step.id,
918
+ status: "suspended"
733
919
  }
734
920
  });
735
921
  return {
@@ -782,6 +968,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
782
968
  },
783
969
  eventTimestamp: Date.now()
784
970
  });
971
+ await emitter.emit("watch-v2", {
972
+ type: "step-result",
973
+ payload: {
974
+ id: step.id,
975
+ status: "success",
976
+ output: result?.result
977
+ }
978
+ });
785
979
  await emitter.emit("watch-v2", {
786
980
  type: "step-finish",
787
981
  payload: {
@@ -798,6 +992,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
798
992
  const stepRes = await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}`, async () => {
799
993
  let execResults;
800
994
  let suspended;
995
+ let bailed;
801
996
  try {
802
997
  const result = await step.execute({
803
998
  runId: executionContext.runId,
@@ -817,6 +1012,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
817
1012
  executionContext.suspendedPaths[step.id] = executionContext.executionPath;
818
1013
  suspended = { payload: suspendPayload };
819
1014
  },
1015
+ bail: (result2) => {
1016
+ bailed = { payload: result2 };
1017
+ },
820
1018
  resume: {
821
1019
  steps: resume?.steps?.slice(1) || [],
822
1020
  resumePayload: resume?.resumePayload,
@@ -826,7 +1024,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
826
1024
  [EMITTER_SYMBOL]: emitter,
827
1025
  engine: {
828
1026
  step: this.inngestStep
829
- }
1027
+ },
1028
+ abortSignal: abortController.signal
830
1029
  });
831
1030
  const endedAt = Date.now();
832
1031
  execResults = {
@@ -859,6 +1058,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
859
1058
  resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
860
1059
  resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
861
1060
  };
1061
+ } else if (bailed) {
1062
+ execResults = { status: "bailed", output: bailed.payload, payload: prevOutput, endedAt: Date.now(), startedAt };
862
1063
  }
863
1064
  if (execResults.status === "failed") {
864
1065
  if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
@@ -886,8 +1087,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
886
1087
  type: "step-suspended",
887
1088
  payload: {
888
1089
  id: step.id,
889
- status: execResults.status,
890
- output: execResults.status === "success" ? execResults?.output : void 0
1090
+ ...execResults
891
1091
  }
892
1092
  });
893
1093
  } else {
@@ -895,8 +1095,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
895
1095
  type: "step-result",
896
1096
  payload: {
897
1097
  id: step.id,
898
- status: execResults.status,
899
- output: execResults.status === "success" ? execResults?.output : void 0
1098
+ ...execResults
900
1099
  }
901
1100
  });
902
1101
  await emitter.emit("watch-v2", {
@@ -957,6 +1156,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
957
1156
  resume,
958
1157
  executionContext,
959
1158
  emitter,
1159
+ abortController,
960
1160
  runtimeContext
961
1161
  }) {
962
1162
  let execResults;
@@ -968,6 +1168,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
968
1168
  runId,
969
1169
  mastra: this.mastra,
970
1170
  runtimeContext,
1171
+ runCount: -1,
971
1172
  inputData: prevOutput,
972
1173
  getInitData: () => stepResults?.input,
973
1174
  getStepResult: (step) => {
@@ -983,10 +1184,16 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
983
1184
  // TODO: this function shouldn't have suspend probably?
984
1185
  suspend: async (_suspendPayload) => {
985
1186
  },
1187
+ bail: () => {
1188
+ },
1189
+ abort: () => {
1190
+ abortController.abort();
1191
+ },
986
1192
  [EMITTER_SYMBOL]: emitter,
987
1193
  engine: {
988
1194
  step: this.inngestStep
989
- }
1195
+ },
1196
+ abortSignal: abortController.signal
990
1197
  });
991
1198
  return result ? index : null;
992
1199
  } catch (e) {
@@ -1015,6 +1222,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1015
1222
  executionSpan: executionContext.executionSpan
1016
1223
  },
1017
1224
  emitter,
1225
+ abortController,
1018
1226
  runtimeContext
1019
1227
  })
1020
1228
  )
@@ -2,9 +2,9 @@ version: '3'
2
2
 
3
3
  services:
4
4
  inngest:
5
- image: inngest/inngest
6
- command: inngest dev -u http://host.docker.internal:3000/api/inngest --poll-interval=1
5
+ image: inngest/inngest:v1.8.2
6
+ command: inngest dev -p 4000 -u http://host.docker.internal:4001/inngest/api --poll-interval=1
7
7
  ports:
8
- - '8288:8288'
8
+ - '4000:4000'
9
9
  extra_hosts:
10
10
  - 'host.docker.internal:host-gateway'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/inngest",
3
- "version": "0.0.0-ai-v5-20250626003446",
3
+ "version": "0.0.0-ai-v5-20250710191716",
4
4
  "description": "Mastra Inngest integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -21,34 +21,35 @@
21
21
  "dependencies": {
22
22
  "@inngest/realtime": "^0.3.1",
23
23
  "@opentelemetry/api": "^1.9.0",
24
- "inngest": "^3.39.1",
25
- "zod": "^3.25.57"
24
+ "inngest": "^3.40.0",
25
+ "zod": "^3.25.67"
26
26
  },
27
27
  "devDependencies": {
28
- "@ai-sdk/openai": "2.0.0-beta.1",
28
+ "inngest-cli": "1.8.2",
29
+ "@ai-sdk/openai": "2.0.0-beta.6",
29
30
  "@hono/node-server": "^1.14.4",
30
31
  "@microsoft/api-extractor": "^7.52.8",
31
32
  "@types/node": "^20.19.0",
32
- "ai": "5.0.0-beta.1",
33
- "eslint": "^9.28.0",
33
+ "ai": "5.0.0-beta.14",
34
+ "eslint": "^9.29.0",
34
35
  "execa": "^9.6.0",
35
36
  "get-port": "7.1.0",
36
- "hono": "^4.7.11",
37
+ "hono": "^4.8.4",
37
38
  "tsup": "^8.5.0",
38
39
  "typescript": "^5.8.3",
39
- "vitest": "^2.1.9",
40
- "@internal/lint": "0.0.0-ai-v5-20250626003446",
41
- "@mastra/libsql": "0.0.0-ai-v5-20250626003446",
42
- "@mastra/deployer": "0.0.0-ai-v5-20250626003446",
43
- "@mastra/core": "0.0.0-ai-v5-20250626003446"
40
+ "vitest": "^3.2.4",
41
+ "@internal/lint": "0.0.0-ai-v5-20250710191716",
42
+ "@mastra/libsql": "0.0.0-ai-v5-20250710191716",
43
+ "@mastra/core": "0.0.0-ai-v5-20250710191716",
44
+ "@mastra/deployer": "0.0.0-ai-v5-20250710191716"
44
45
  },
45
46
  "peerDependencies": {
46
- "@mastra/core": "0.0.0-ai-v5-20250626003446"
47
+ "@mastra/core": "0.0.0-ai-v5-20250710191716"
47
48
  },
48
49
  "scripts": {
49
50
  "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
50
51
  "build:watch": "pnpm build --watch",
51
- "test": "vitest run",
52
+ "test": "docker-compose up -d && vitest run --no-isolate --bail=1 --retry=1 && docker-compose down",
52
53
  "lint": "eslint ."
53
54
  }
54
55
  }