@mastra/inngest 0.0.0-tool-call-parts-20250630193309 → 0.0.0-transpile-packages-20250724123433
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/CHANGELOG.md +177 -3
- package/LICENSE.md +11 -42
- package/dist/_tsup-dts-rollup.d.cts +57 -16
- package/dist/_tsup-dts-rollup.d.ts +57 -16
- package/dist/index.cjs +171 -18
- package/dist/index.js +171 -18
- package/docker-compose.yaml +3 -3
- package/package.json +12 -11
- package/src/index.test.ts +1021 -199
- package/src/index.ts +230 -20
- package/vitest.config.ts +6 -0
package/dist/index.cjs
CHANGED
|
@@ -12,13 +12,17 @@ var zod = require('zod');
|
|
|
12
12
|
// src/index.ts
|
|
13
13
|
function serve({ mastra, inngest }) {
|
|
14
14
|
const wfs = mastra.getWorkflows();
|
|
15
|
-
const functions =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
const functions = Array.from(
|
|
16
|
+
new Set(
|
|
17
|
+
Object.values(wfs).flatMap((wf) => {
|
|
18
|
+
if (wf instanceof InngestWorkflow) {
|
|
19
|
+
wf.__registerMastra(mastra);
|
|
20
|
+
return wf.getFunctions();
|
|
21
|
+
}
|
|
22
|
+
return [];
|
|
23
|
+
})
|
|
24
|
+
)
|
|
25
|
+
);
|
|
22
26
|
return hono.serve({
|
|
23
27
|
client: inngest,
|
|
24
28
|
functions
|
|
@@ -48,8 +52,15 @@ var InngestRun = class extends workflows.Run {
|
|
|
48
52
|
while (runs?.[0]?.status !== "Completed" || runs?.[0]?.event_id !== eventId) {
|
|
49
53
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
50
54
|
runs = await this.getRuns(eventId);
|
|
51
|
-
if (runs?.[0]?.status === "Failed"
|
|
55
|
+
if (runs?.[0]?.status === "Failed") {
|
|
56
|
+
console.log("run", runs?.[0]);
|
|
52
57
|
throw new Error(`Function run ${runs?.[0]?.status}`);
|
|
58
|
+
} else if (runs?.[0]?.status === "Cancelled") {
|
|
59
|
+
const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
|
|
60
|
+
workflowName: this.workflowId,
|
|
61
|
+
runId: this.runId
|
|
62
|
+
});
|
|
63
|
+
return { output: { result: { steps: snapshot?.context, status: "canceled" } } };
|
|
53
64
|
}
|
|
54
65
|
}
|
|
55
66
|
return runs?.[0];
|
|
@@ -60,6 +71,28 @@ var InngestRun = class extends workflows.Run {
|
|
|
60
71
|
data
|
|
61
72
|
});
|
|
62
73
|
}
|
|
74
|
+
async cancel() {
|
|
75
|
+
await this.inngest.send({
|
|
76
|
+
name: `cancel.workflow.${this.workflowId}`,
|
|
77
|
+
data: {
|
|
78
|
+
runId: this.runId
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
|
|
82
|
+
workflowName: this.workflowId,
|
|
83
|
+
runId: this.runId
|
|
84
|
+
});
|
|
85
|
+
if (snapshot) {
|
|
86
|
+
await this.#mastra?.storage?.persistWorkflowSnapshot({
|
|
87
|
+
workflowName: this.workflowId,
|
|
88
|
+
runId: this.runId,
|
|
89
|
+
snapshot: {
|
|
90
|
+
...snapshot,
|
|
91
|
+
status: "canceled"
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
63
96
|
async start({
|
|
64
97
|
inputData
|
|
65
98
|
}) {
|
|
@@ -122,6 +155,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
122
155
|
data: {
|
|
123
156
|
inputData: params.resumeData,
|
|
124
157
|
runId: this.runId,
|
|
158
|
+
workflowId: this.workflowId,
|
|
125
159
|
stepResults: snapshot?.context,
|
|
126
160
|
resume: {
|
|
127
161
|
steps,
|
|
@@ -324,8 +358,12 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
324
358
|
return this.function;
|
|
325
359
|
}
|
|
326
360
|
this.function = this.inngest.createFunction(
|
|
327
|
-
|
|
328
|
-
|
|
361
|
+
{
|
|
362
|
+
id: `workflow.${this.id}`,
|
|
363
|
+
// @ts-ignore
|
|
364
|
+
retries: this.retryConfig?.attempts ?? 0,
|
|
365
|
+
cancelOn: [{ event: `cancel.workflow.${this.id}` }]
|
|
366
|
+
},
|
|
329
367
|
{ event: `workflow.${this.id}` },
|
|
330
368
|
async ({ event, step, attempt, publish }) => {
|
|
331
369
|
let { inputData, runId, resume } = event.data;
|
|
@@ -367,7 +405,8 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
367
405
|
retryConfig: this.retryConfig,
|
|
368
406
|
runtimeContext: new di.RuntimeContext(),
|
|
369
407
|
// TODO
|
|
370
|
-
resume
|
|
408
|
+
resume,
|
|
409
|
+
abortController: new AbortController()
|
|
371
410
|
});
|
|
372
411
|
return { result, runId };
|
|
373
412
|
}
|
|
@@ -411,7 +450,7 @@ function createStep(params) {
|
|
|
411
450
|
outputSchema: zod.z.object({
|
|
412
451
|
text: zod.z.string()
|
|
413
452
|
}),
|
|
414
|
-
execute: async ({ inputData, [_constants.EMITTER_SYMBOL]: emitter, runtimeContext }) => {
|
|
453
|
+
execute: async ({ inputData, [_constants.EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort }) => {
|
|
415
454
|
let streamPromise = {};
|
|
416
455
|
streamPromise.promise = new Promise((resolve, reject) => {
|
|
417
456
|
streamPromise.resolve = resolve;
|
|
@@ -431,8 +470,12 @@ function createStep(params) {
|
|
|
431
470
|
runtimeContext,
|
|
432
471
|
onFinish: (result) => {
|
|
433
472
|
streamPromise.resolve(result.text);
|
|
434
|
-
}
|
|
473
|
+
},
|
|
474
|
+
abortSignal
|
|
435
475
|
});
|
|
476
|
+
if (abortSignal.aborted) {
|
|
477
|
+
return abort();
|
|
478
|
+
}
|
|
436
479
|
for await (const chunk of fullStream) {
|
|
437
480
|
switch (chunk.type) {
|
|
438
481
|
case "text-delta":
|
|
@@ -607,6 +650,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
607
650
|
resume,
|
|
608
651
|
prevOutput,
|
|
609
652
|
emitter,
|
|
653
|
+
abortController,
|
|
610
654
|
runtimeContext
|
|
611
655
|
}) {
|
|
612
656
|
return super.executeStep({
|
|
@@ -618,11 +662,109 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
618
662
|
resume,
|
|
619
663
|
prevOutput,
|
|
620
664
|
emitter,
|
|
665
|
+
abortController,
|
|
621
666
|
runtimeContext
|
|
622
667
|
});
|
|
623
668
|
}
|
|
624
|
-
async executeSleep({ id, duration }) {
|
|
625
|
-
|
|
669
|
+
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
670
|
+
// await this.inngestStep.sleep(id, duration);
|
|
671
|
+
// }
|
|
672
|
+
async executeSleep({
|
|
673
|
+
workflowId,
|
|
674
|
+
runId,
|
|
675
|
+
entry,
|
|
676
|
+
prevOutput,
|
|
677
|
+
stepResults,
|
|
678
|
+
emitter,
|
|
679
|
+
abortController,
|
|
680
|
+
runtimeContext
|
|
681
|
+
}) {
|
|
682
|
+
let { duration, fn } = entry;
|
|
683
|
+
if (fn) {
|
|
684
|
+
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
685
|
+
return await fn({
|
|
686
|
+
runId,
|
|
687
|
+
workflowId,
|
|
688
|
+
mastra: this.mastra,
|
|
689
|
+
runtimeContext,
|
|
690
|
+
inputData: prevOutput,
|
|
691
|
+
runCount: -1,
|
|
692
|
+
getInitData: () => stepResults?.input,
|
|
693
|
+
getStepResult: (step) => {
|
|
694
|
+
if (!step?.id) {
|
|
695
|
+
return null;
|
|
696
|
+
}
|
|
697
|
+
const result = stepResults[step.id];
|
|
698
|
+
if (result?.status === "success") {
|
|
699
|
+
return result.output;
|
|
700
|
+
}
|
|
701
|
+
return null;
|
|
702
|
+
},
|
|
703
|
+
// TODO: this function shouldn't have suspend probably?
|
|
704
|
+
suspend: async (_suspendPayload) => {
|
|
705
|
+
},
|
|
706
|
+
bail: () => {
|
|
707
|
+
},
|
|
708
|
+
abort: () => {
|
|
709
|
+
abortController?.abort();
|
|
710
|
+
},
|
|
711
|
+
[_constants.EMITTER_SYMBOL]: emitter,
|
|
712
|
+
engine: { step: this.inngestStep },
|
|
713
|
+
abortSignal: abortController?.signal
|
|
714
|
+
});
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
|
|
718
|
+
}
|
|
719
|
+
async executeSleepUntil({
|
|
720
|
+
workflowId,
|
|
721
|
+
runId,
|
|
722
|
+
entry,
|
|
723
|
+
prevOutput,
|
|
724
|
+
stepResults,
|
|
725
|
+
emitter,
|
|
726
|
+
abortController,
|
|
727
|
+
runtimeContext
|
|
728
|
+
}) {
|
|
729
|
+
let { date, fn } = entry;
|
|
730
|
+
if (fn) {
|
|
731
|
+
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
732
|
+
return await fn({
|
|
733
|
+
runId,
|
|
734
|
+
workflowId,
|
|
735
|
+
mastra: this.mastra,
|
|
736
|
+
runtimeContext,
|
|
737
|
+
inputData: prevOutput,
|
|
738
|
+
runCount: -1,
|
|
739
|
+
getInitData: () => stepResults?.input,
|
|
740
|
+
getStepResult: (step) => {
|
|
741
|
+
if (!step?.id) {
|
|
742
|
+
return null;
|
|
743
|
+
}
|
|
744
|
+
const result = stepResults[step.id];
|
|
745
|
+
if (result?.status === "success") {
|
|
746
|
+
return result.output;
|
|
747
|
+
}
|
|
748
|
+
return null;
|
|
749
|
+
},
|
|
750
|
+
// TODO: this function shouldn't have suspend probably?
|
|
751
|
+
suspend: async (_suspendPayload) => {
|
|
752
|
+
},
|
|
753
|
+
bail: () => {
|
|
754
|
+
},
|
|
755
|
+
abort: () => {
|
|
756
|
+
abortController?.abort();
|
|
757
|
+
},
|
|
758
|
+
[_constants.EMITTER_SYMBOL]: emitter,
|
|
759
|
+
engine: { step: this.inngestStep },
|
|
760
|
+
abortSignal: abortController?.signal
|
|
761
|
+
});
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
if (!(date instanceof Date)) {
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
await this.inngestStep.sleepUntil(entry.id, date);
|
|
626
768
|
}
|
|
627
769
|
async executeWaitForEvent({ event, timeout }) {
|
|
628
770
|
const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
|
|
@@ -641,6 +783,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
641
783
|
resume,
|
|
642
784
|
prevOutput,
|
|
643
785
|
emitter,
|
|
786
|
+
abortController,
|
|
644
787
|
runtimeContext
|
|
645
788
|
}) {
|
|
646
789
|
const startedAt = await this.inngestStep.run(
|
|
@@ -672,7 +815,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
672
815
|
type: "step-start",
|
|
673
816
|
payload: {
|
|
674
817
|
id: step.id,
|
|
675
|
-
status: "running"
|
|
818
|
+
status: "running",
|
|
819
|
+
payload: prevOutput,
|
|
820
|
+
startedAt: startedAt2
|
|
676
821
|
}
|
|
677
822
|
});
|
|
678
823
|
return startedAt2;
|
|
@@ -884,7 +1029,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
884
1029
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
885
1030
|
engine: {
|
|
886
1031
|
step: this.inngestStep
|
|
887
|
-
}
|
|
1032
|
+
},
|
|
1033
|
+
abortSignal: abortController.signal
|
|
888
1034
|
});
|
|
889
1035
|
const endedAt = Date.now();
|
|
890
1036
|
execResults = {
|
|
@@ -1015,6 +1161,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1015
1161
|
resume,
|
|
1016
1162
|
executionContext,
|
|
1017
1163
|
emitter,
|
|
1164
|
+
abortController,
|
|
1018
1165
|
runtimeContext
|
|
1019
1166
|
}) {
|
|
1020
1167
|
let execResults;
|
|
@@ -1024,6 +1171,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1024
1171
|
try {
|
|
1025
1172
|
const result = await cond({
|
|
1026
1173
|
runId,
|
|
1174
|
+
workflowId,
|
|
1027
1175
|
mastra: this.mastra,
|
|
1028
1176
|
runtimeContext,
|
|
1029
1177
|
runCount: -1,
|
|
@@ -1044,10 +1192,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1044
1192
|
},
|
|
1045
1193
|
bail: () => {
|
|
1046
1194
|
},
|
|
1195
|
+
abort: () => {
|
|
1196
|
+
abortController.abort();
|
|
1197
|
+
},
|
|
1047
1198
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1048
1199
|
engine: {
|
|
1049
1200
|
step: this.inngestStep
|
|
1050
|
-
}
|
|
1201
|
+
},
|
|
1202
|
+
abortSignal: abortController.signal
|
|
1051
1203
|
});
|
|
1052
1204
|
return result ? index : null;
|
|
1053
1205
|
} catch (e) {
|
|
@@ -1076,6 +1228,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1076
1228
|
executionSpan: executionContext.executionSpan
|
|
1077
1229
|
},
|
|
1078
1230
|
emitter,
|
|
1231
|
+
abortController,
|
|
1079
1232
|
runtimeContext
|
|
1080
1233
|
})
|
|
1081
1234
|
)
|
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 =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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"
|
|
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
|
}) {
|
|
@@ -120,6 +153,7 @@ var InngestRun = class extends Run {
|
|
|
120
153
|
data: {
|
|
121
154
|
inputData: params.resumeData,
|
|
122
155
|
runId: this.runId,
|
|
156
|
+
workflowId: this.workflowId,
|
|
123
157
|
stepResults: snapshot?.context,
|
|
124
158
|
resume: {
|
|
125
159
|
steps,
|
|
@@ -322,8 +356,12 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
322
356
|
return this.function;
|
|
323
357
|
}
|
|
324
358
|
this.function = this.inngest.createFunction(
|
|
325
|
-
|
|
326
|
-
|
|
359
|
+
{
|
|
360
|
+
id: `workflow.${this.id}`,
|
|
361
|
+
// @ts-ignore
|
|
362
|
+
retries: this.retryConfig?.attempts ?? 0,
|
|
363
|
+
cancelOn: [{ event: `cancel.workflow.${this.id}` }]
|
|
364
|
+
},
|
|
327
365
|
{ event: `workflow.${this.id}` },
|
|
328
366
|
async ({ event, step, attempt, publish }) => {
|
|
329
367
|
let { inputData, runId, resume } = event.data;
|
|
@@ -365,7 +403,8 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
365
403
|
retryConfig: this.retryConfig,
|
|
366
404
|
runtimeContext: new RuntimeContext(),
|
|
367
405
|
// TODO
|
|
368
|
-
resume
|
|
406
|
+
resume,
|
|
407
|
+
abortController: new AbortController()
|
|
369
408
|
});
|
|
370
409
|
return { result, runId };
|
|
371
410
|
}
|
|
@@ -409,7 +448,7 @@ function createStep(params) {
|
|
|
409
448
|
outputSchema: z.object({
|
|
410
449
|
text: z.string()
|
|
411
450
|
}),
|
|
412
|
-
execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext }) => {
|
|
451
|
+
execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort }) => {
|
|
413
452
|
let streamPromise = {};
|
|
414
453
|
streamPromise.promise = new Promise((resolve, reject) => {
|
|
415
454
|
streamPromise.resolve = resolve;
|
|
@@ -429,8 +468,12 @@ function createStep(params) {
|
|
|
429
468
|
runtimeContext,
|
|
430
469
|
onFinish: (result) => {
|
|
431
470
|
streamPromise.resolve(result.text);
|
|
432
|
-
}
|
|
471
|
+
},
|
|
472
|
+
abortSignal
|
|
433
473
|
});
|
|
474
|
+
if (abortSignal.aborted) {
|
|
475
|
+
return abort();
|
|
476
|
+
}
|
|
434
477
|
for await (const chunk of fullStream) {
|
|
435
478
|
switch (chunk.type) {
|
|
436
479
|
case "text-delta":
|
|
@@ -605,6 +648,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
605
648
|
resume,
|
|
606
649
|
prevOutput,
|
|
607
650
|
emitter,
|
|
651
|
+
abortController,
|
|
608
652
|
runtimeContext
|
|
609
653
|
}) {
|
|
610
654
|
return super.executeStep({
|
|
@@ -616,11 +660,109 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
616
660
|
resume,
|
|
617
661
|
prevOutput,
|
|
618
662
|
emitter,
|
|
663
|
+
abortController,
|
|
619
664
|
runtimeContext
|
|
620
665
|
});
|
|
621
666
|
}
|
|
622
|
-
async executeSleep({ id, duration }) {
|
|
623
|
-
|
|
667
|
+
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
668
|
+
// await this.inngestStep.sleep(id, duration);
|
|
669
|
+
// }
|
|
670
|
+
async executeSleep({
|
|
671
|
+
workflowId,
|
|
672
|
+
runId,
|
|
673
|
+
entry,
|
|
674
|
+
prevOutput,
|
|
675
|
+
stepResults,
|
|
676
|
+
emitter,
|
|
677
|
+
abortController,
|
|
678
|
+
runtimeContext
|
|
679
|
+
}) {
|
|
680
|
+
let { duration, fn } = entry;
|
|
681
|
+
if (fn) {
|
|
682
|
+
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
683
|
+
return await fn({
|
|
684
|
+
runId,
|
|
685
|
+
workflowId,
|
|
686
|
+
mastra: this.mastra,
|
|
687
|
+
runtimeContext,
|
|
688
|
+
inputData: prevOutput,
|
|
689
|
+
runCount: -1,
|
|
690
|
+
getInitData: () => stepResults?.input,
|
|
691
|
+
getStepResult: (step) => {
|
|
692
|
+
if (!step?.id) {
|
|
693
|
+
return null;
|
|
694
|
+
}
|
|
695
|
+
const result = stepResults[step.id];
|
|
696
|
+
if (result?.status === "success") {
|
|
697
|
+
return result.output;
|
|
698
|
+
}
|
|
699
|
+
return null;
|
|
700
|
+
},
|
|
701
|
+
// TODO: this function shouldn't have suspend probably?
|
|
702
|
+
suspend: async (_suspendPayload) => {
|
|
703
|
+
},
|
|
704
|
+
bail: () => {
|
|
705
|
+
},
|
|
706
|
+
abort: () => {
|
|
707
|
+
abortController?.abort();
|
|
708
|
+
},
|
|
709
|
+
[EMITTER_SYMBOL]: emitter,
|
|
710
|
+
engine: { step: this.inngestStep },
|
|
711
|
+
abortSignal: abortController?.signal
|
|
712
|
+
});
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
|
|
716
|
+
}
|
|
717
|
+
async executeSleepUntil({
|
|
718
|
+
workflowId,
|
|
719
|
+
runId,
|
|
720
|
+
entry,
|
|
721
|
+
prevOutput,
|
|
722
|
+
stepResults,
|
|
723
|
+
emitter,
|
|
724
|
+
abortController,
|
|
725
|
+
runtimeContext
|
|
726
|
+
}) {
|
|
727
|
+
let { date, fn } = entry;
|
|
728
|
+
if (fn) {
|
|
729
|
+
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
730
|
+
return await fn({
|
|
731
|
+
runId,
|
|
732
|
+
workflowId,
|
|
733
|
+
mastra: this.mastra,
|
|
734
|
+
runtimeContext,
|
|
735
|
+
inputData: prevOutput,
|
|
736
|
+
runCount: -1,
|
|
737
|
+
getInitData: () => stepResults?.input,
|
|
738
|
+
getStepResult: (step) => {
|
|
739
|
+
if (!step?.id) {
|
|
740
|
+
return null;
|
|
741
|
+
}
|
|
742
|
+
const result = stepResults[step.id];
|
|
743
|
+
if (result?.status === "success") {
|
|
744
|
+
return result.output;
|
|
745
|
+
}
|
|
746
|
+
return null;
|
|
747
|
+
},
|
|
748
|
+
// TODO: this function shouldn't have suspend probably?
|
|
749
|
+
suspend: async (_suspendPayload) => {
|
|
750
|
+
},
|
|
751
|
+
bail: () => {
|
|
752
|
+
},
|
|
753
|
+
abort: () => {
|
|
754
|
+
abortController?.abort();
|
|
755
|
+
},
|
|
756
|
+
[EMITTER_SYMBOL]: emitter,
|
|
757
|
+
engine: { step: this.inngestStep },
|
|
758
|
+
abortSignal: abortController?.signal
|
|
759
|
+
});
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
if (!(date instanceof Date)) {
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
await this.inngestStep.sleepUntil(entry.id, date);
|
|
624
766
|
}
|
|
625
767
|
async executeWaitForEvent({ event, timeout }) {
|
|
626
768
|
const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
|
|
@@ -639,6 +781,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
639
781
|
resume,
|
|
640
782
|
prevOutput,
|
|
641
783
|
emitter,
|
|
784
|
+
abortController,
|
|
642
785
|
runtimeContext
|
|
643
786
|
}) {
|
|
644
787
|
const startedAt = await this.inngestStep.run(
|
|
@@ -670,7 +813,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
670
813
|
type: "step-start",
|
|
671
814
|
payload: {
|
|
672
815
|
id: step.id,
|
|
673
|
-
status: "running"
|
|
816
|
+
status: "running",
|
|
817
|
+
payload: prevOutput,
|
|
818
|
+
startedAt: startedAt2
|
|
674
819
|
}
|
|
675
820
|
});
|
|
676
821
|
return startedAt2;
|
|
@@ -882,7 +1027,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
882
1027
|
[EMITTER_SYMBOL]: emitter,
|
|
883
1028
|
engine: {
|
|
884
1029
|
step: this.inngestStep
|
|
885
|
-
}
|
|
1030
|
+
},
|
|
1031
|
+
abortSignal: abortController.signal
|
|
886
1032
|
});
|
|
887
1033
|
const endedAt = Date.now();
|
|
888
1034
|
execResults = {
|
|
@@ -1013,6 +1159,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1013
1159
|
resume,
|
|
1014
1160
|
executionContext,
|
|
1015
1161
|
emitter,
|
|
1162
|
+
abortController,
|
|
1016
1163
|
runtimeContext
|
|
1017
1164
|
}) {
|
|
1018
1165
|
let execResults;
|
|
@@ -1022,6 +1169,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1022
1169
|
try {
|
|
1023
1170
|
const result = await cond({
|
|
1024
1171
|
runId,
|
|
1172
|
+
workflowId,
|
|
1025
1173
|
mastra: this.mastra,
|
|
1026
1174
|
runtimeContext,
|
|
1027
1175
|
runCount: -1,
|
|
@@ -1042,10 +1190,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1042
1190
|
},
|
|
1043
1191
|
bail: () => {
|
|
1044
1192
|
},
|
|
1193
|
+
abort: () => {
|
|
1194
|
+
abortController.abort();
|
|
1195
|
+
},
|
|
1045
1196
|
[EMITTER_SYMBOL]: emitter,
|
|
1046
1197
|
engine: {
|
|
1047
1198
|
step: this.inngestStep
|
|
1048
|
-
}
|
|
1199
|
+
},
|
|
1200
|
+
abortSignal: abortController.signal
|
|
1049
1201
|
});
|
|
1050
1202
|
return result ? index : null;
|
|
1051
1203
|
} catch (e) {
|
|
@@ -1074,6 +1226,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1074
1226
|
executionSpan: executionContext.executionSpan
|
|
1075
1227
|
},
|
|
1076
1228
|
emitter,
|
|
1229
|
+
abortController,
|
|
1077
1230
|
runtimeContext
|
|
1078
1231
|
})
|
|
1079
1232
|
)
|
package/docker-compose.yaml
CHANGED
|
@@ -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:
|
|
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
|
-
- '
|
|
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-
|
|
3
|
+
"version": "0.0.0-transpile-packages-20250724123433",
|
|
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.
|
|
24
|
+
"inngest": "^3.40.0",
|
|
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",
|
|
31
32
|
"@types/node": "^20.19.0",
|
|
32
33
|
"ai": "^4.3.16",
|
|
33
|
-
"eslint": "^9.
|
|
34
|
+
"eslint": "^9.30.1",
|
|
34
35
|
"execa": "^9.6.0",
|
|
35
36
|
"get-port": "7.1.0",
|
|
36
|
-
"hono": "^4.8.
|
|
37
|
+
"hono": "^4.8.4",
|
|
37
38
|
"tsup": "^8.5.0",
|
|
38
39
|
"typescript": "^5.8.3",
|
|
39
|
-
"vitest": "^2.
|
|
40
|
-
"@mastra/core": "0.0.0-
|
|
41
|
-
"@mastra/libsql": "0.0.0-
|
|
42
|
-
"@internal/lint": "0.0.0-
|
|
43
|
-
"@mastra/deployer": "0.0.0-
|
|
40
|
+
"vitest": "^3.2.4",
|
|
41
|
+
"@mastra/core": "0.0.0-transpile-packages-20250724123433",
|
|
42
|
+
"@mastra/libsql": "0.0.0-transpile-packages-20250724123433",
|
|
43
|
+
"@internal/lint": "0.0.0-transpile-packages-20250724123433",
|
|
44
|
+
"@mastra/deployer": "0.0.0-transpile-packages-20250724123433"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
|
-
"@mastra/core": "0.0.0-
|
|
47
|
+
"@mastra/core": "0.0.0-transpile-packages-20250724123433"
|
|
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
|
}
|