@mastra/inngest 0.0.0-fix-fetching-workflow-snapshots-20250625000954 → 0.0.0-http-transporter-20250702160118

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) {
@@ -293,23 +328,26 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
293
328
  this.inngest
294
329
  );
295
330
  this.runs.set(runIdToUse, run);
296
- await this.mastra?.getStorage()?.persistWorkflowSnapshot({
297
- workflowName: this.id,
298
- runId: runIdToUse,
299
- snapshot: {
331
+ const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse);
332
+ if (!workflowSnapshotInStorage) {
333
+ await this.mastra?.getStorage()?.persistWorkflowSnapshot({
334
+ workflowName: this.id,
300
335
  runId: runIdToUse,
301
- status: "pending",
302
- value: {},
303
- context: {},
304
- activePaths: [],
305
- serializedStepGraph: this.serializedStepGraph,
306
- suspendedPaths: {},
307
- result: void 0,
308
- error: void 0,
309
- // @ts-ignore
310
- timestamp: Date.now()
311
- }
312
- });
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
+ }
313
351
  return run;
314
352
  }
315
353
  getFunction() {
@@ -317,8 +355,12 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
317
355
  return this.function;
318
356
  }
319
357
  this.function = this.inngest.createFunction(
320
- // @ts-ignore
321
- { 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
+ },
322
364
  { event: `workflow.${this.id}` },
323
365
  async ({ event, step, attempt, publish }) => {
324
366
  let { inputData, runId, resume } = event.data;
@@ -360,7 +402,8 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
360
402
  retryConfig: this.retryConfig,
361
403
  runtimeContext: new RuntimeContext(),
362
404
  // TODO
363
- resume
405
+ resume,
406
+ abortController: new AbortController()
364
407
  });
365
408
  return { result, runId };
366
409
  }
@@ -404,7 +447,7 @@ function createStep(params) {
404
447
  outputSchema: z.object({
405
448
  text: z.string()
406
449
  }),
407
- execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext }) => {
450
+ execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort }) => {
408
451
  let streamPromise = {};
409
452
  streamPromise.promise = new Promise((resolve, reject) => {
410
453
  streamPromise.resolve = resolve;
@@ -424,8 +467,12 @@ function createStep(params) {
424
467
  runtimeContext,
425
468
  onFinish: (result) => {
426
469
  streamPromise.resolve(result.text);
427
- }
470
+ },
471
+ abortSignal
428
472
  });
473
+ if (abortSignal.aborted) {
474
+ return abort();
475
+ }
429
476
  for await (const chunk of fullStream) {
430
477
  switch (chunk.type) {
431
478
  case "text-delta":
@@ -600,6 +647,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
600
647
  resume,
601
648
  prevOutput,
602
649
  emitter,
650
+ abortController,
603
651
  runtimeContext
604
652
  }) {
605
653
  return super.executeStep({
@@ -611,6 +659,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
611
659
  resume,
612
660
  prevOutput,
613
661
  emitter,
662
+ abortController,
614
663
  runtimeContext
615
664
  });
616
665
  }
@@ -634,6 +683,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
634
683
  resume,
635
684
  prevOutput,
636
685
  emitter,
686
+ abortController,
637
687
  runtimeContext
638
688
  }) {
639
689
  const startedAt = await this.inngestStep.run(
@@ -664,7 +714,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
664
714
  await emitter.emit("watch-v2", {
665
715
  type: "step-start",
666
716
  payload: {
667
- id: step.id
717
+ id: step.id,
718
+ status: "running",
719
+ payload: prevOutput,
720
+ startedAt: startedAt2
668
721
  }
669
722
  });
670
723
  return startedAt2;
@@ -732,7 +785,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
732
785
  type: "step-result",
733
786
  payload: {
734
787
  id: step.id,
735
- status: "failed"
788
+ status: "failed",
789
+ error: result?.error,
790
+ payload: prevOutput
736
791
  }
737
792
  });
738
793
  return { executionContext, result: { status: "failed", error: result?.error } };
@@ -764,7 +819,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
764
819
  await emitter.emit("watch-v2", {
765
820
  type: "step-suspended",
766
821
  payload: {
767
- id: step.id
822
+ id: step.id,
823
+ status: "suspended"
768
824
  }
769
825
  });
770
826
  return {
@@ -817,6 +873,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
817
873
  },
818
874
  eventTimestamp: Date.now()
819
875
  });
876
+ await emitter.emit("watch-v2", {
877
+ type: "step-result",
878
+ payload: {
879
+ id: step.id,
880
+ status: "success",
881
+ output: result?.result
882
+ }
883
+ });
820
884
  await emitter.emit("watch-v2", {
821
885
  type: "step-finish",
822
886
  payload: {
@@ -865,7 +929,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
865
929
  [EMITTER_SYMBOL]: emitter,
866
930
  engine: {
867
931
  step: this.inngestStep
868
- }
932
+ },
933
+ abortSignal: abortController.signal
869
934
  });
870
935
  const endedAt = Date.now();
871
936
  execResults = {
@@ -927,8 +992,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
927
992
  type: "step-suspended",
928
993
  payload: {
929
994
  id: step.id,
930
- status: execResults.status,
931
- output: execResults.status === "success" ? execResults?.output : void 0
995
+ ...execResults
932
996
  }
933
997
  });
934
998
  } else {
@@ -936,8 +1000,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
936
1000
  type: "step-result",
937
1001
  payload: {
938
1002
  id: step.id,
939
- status: execResults.status,
940
- output: execResults.status === "success" ? execResults?.output : void 0
1003
+ ...execResults
941
1004
  }
942
1005
  });
943
1006
  await emitter.emit("watch-v2", {
@@ -998,6 +1061,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
998
1061
  resume,
999
1062
  executionContext,
1000
1063
  emitter,
1064
+ abortController,
1001
1065
  runtimeContext
1002
1066
  }) {
1003
1067
  let execResults;
@@ -1009,6 +1073,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1009
1073
  runId,
1010
1074
  mastra: this.mastra,
1011
1075
  runtimeContext,
1076
+ runCount: -1,
1012
1077
  inputData: prevOutput,
1013
1078
  getInitData: () => stepResults?.input,
1014
1079
  getStepResult: (step) => {
@@ -1026,10 +1091,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1026
1091
  },
1027
1092
  bail: () => {
1028
1093
  },
1094
+ abort: () => {
1095
+ abortController.abort();
1096
+ },
1029
1097
  [EMITTER_SYMBOL]: emitter,
1030
1098
  engine: {
1031
1099
  step: this.inngestStep
1032
- }
1100
+ },
1101
+ abortSignal: abortController.signal
1033
1102
  });
1034
1103
  return result ? index : null;
1035
1104
  } catch (e) {
@@ -1058,6 +1127,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1058
1127
  executionSpan: executionContext.executionSpan
1059
1128
  },
1060
1129
  emitter,
1130
+ abortController,
1061
1131
  runtimeContext
1062
1132
  })
1063
1133
  )
@@ -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.5.10
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-fix-fetching-workflow-snapshots-20250625000954",
3
+ "version": "0.0.0-http-transporter-20250702160118",
4
4
  "description": "Mastra Inngest integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -25,6 +25,7 @@
25
25
  "zod": "^3.25.67"
26
26
  },
27
27
  "devDependencies": {
28
+ "inngest-cli": "1.8.2",
28
29
  "@ai-sdk/openai": "^1.3.22",
29
30
  "@hono/node-server": "^1.14.4",
30
31
  "@microsoft/api-extractor": "^7.52.8",
@@ -33,22 +34,22 @@
33
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.3",
37
38
  "tsup": "^8.5.0",
38
39
  "typescript": "^5.8.3",
39
- "vitest": "^2.1.9",
40
- "@internal/lint": "0.0.0-fix-fetching-workflow-snapshots-20250625000954",
41
- "@mastra/libsql": "0.0.0-fix-fetching-workflow-snapshots-20250625000954",
42
- "@mastra/deployer": "0.0.0-fix-fetching-workflow-snapshots-20250625000954",
43
- "@mastra/core": "0.0.0-fix-fetching-workflow-snapshots-20250625000954"
40
+ "vitest": "^3.2.4",
41
+ "@internal/lint": "0.0.0-http-transporter-20250702160118",
42
+ "@mastra/core": "0.0.0-http-transporter-20250702160118",
43
+ "@mastra/deployer": "0.0.0-http-transporter-20250702160118",
44
+ "@mastra/libsql": "0.0.0-http-transporter-20250702160118"
44
45
  },
45
46
  "peerDependencies": {
46
- "@mastra/core": "0.0.0-fix-fetching-workflow-snapshots-20250625000954"
47
+ "@mastra/core": "0.0.0-http-transporter-20250702160118"
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
  }