@mastra/inngest 0.0.0-http-transporter-20250702160118 → 0.0.0-message-list-update-20250715150321
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 +89 -2
- package/LICENSE.md +11 -42
- package/dist/_tsup-dts-rollup.d.cts +48 -3
- package/dist/_tsup-dts-rollup.d.ts +48 -3
- package/dist/index.cjs +97 -2
- package/dist/index.js +97 -2
- package/docker-compose.yaml +1 -1
- package/package.json +9 -9
- package/src/index.test.ts +568 -1
- package/src/index.ts +153 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,99 @@
|
|
|
1
1
|
# @mastra/inngest
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-message-list-update-20250715150321
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0b56518: Ensure removed runtimeContext values are not saved in snapshot
|
|
8
|
+
- Updated dependencies [0b56518]
|
|
9
|
+
- Updated dependencies [db5cc15]
|
|
10
|
+
- Updated dependencies [2ba5b76]
|
|
11
|
+
- Updated dependencies [5237998]
|
|
12
|
+
- Updated dependencies [37c1acd]
|
|
13
|
+
- Updated dependencies [1aa60b1]
|
|
14
|
+
- Updated dependencies [89ec9d4]
|
|
15
|
+
- Updated dependencies [cf3a184]
|
|
16
|
+
- Updated dependencies [3759392]
|
|
17
|
+
- Updated dependencies [626b0f4]
|
|
18
|
+
- Updated dependencies [c22a91f]
|
|
19
|
+
- Updated dependencies [f7403ab]
|
|
20
|
+
- Updated dependencies [6c89d7f]
|
|
21
|
+
- @mastra/core@0.0.0-message-list-update-20250715150321
|
|
22
|
+
|
|
23
|
+
## 0.11.3
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 515488a: dependencies updates:
|
|
28
|
+
- Updated dependency [`inngest@^3.39.2` ↗︎](https://www.npmjs.com/package/inngest/v/3.39.2) (from `^3.39.1`, in `dependencies`)
|
|
29
|
+
- defb5ae: dependencies updates:
|
|
30
|
+
- Updated dependency [`inngest@^3.40.0` ↗︎](https://www.npmjs.com/package/inngest/v/3.40.0) (from `^3.39.2`, in `dependencies`)
|
|
31
|
+
- b790fd1: Ability to pass a function to .sleep()/.sleepUntil()
|
|
32
|
+
- c1cceea: Bump peerdeps of @matra/core
|
|
33
|
+
- Updated dependencies [2873c7f]
|
|
34
|
+
- Updated dependencies [1c1c6a1]
|
|
35
|
+
- Updated dependencies [f8ce2cc]
|
|
36
|
+
- Updated dependencies [8c846b6]
|
|
37
|
+
- Updated dependencies [c7bbf1e]
|
|
38
|
+
- Updated dependencies [8722d53]
|
|
39
|
+
- Updated dependencies [565cc0c]
|
|
40
|
+
- Updated dependencies [b790fd1]
|
|
41
|
+
- Updated dependencies [132027f]
|
|
42
|
+
- Updated dependencies [0c85311]
|
|
43
|
+
- Updated dependencies [d7ed04d]
|
|
44
|
+
- Updated dependencies [cb16baf]
|
|
45
|
+
- Updated dependencies [f36e4f1]
|
|
46
|
+
- Updated dependencies [7f6e403]
|
|
47
|
+
- @mastra/core@0.10.11
|
|
48
|
+
|
|
49
|
+
## 0.11.3-alpha.3
|
|
50
|
+
|
|
51
|
+
### Patch Changes
|
|
52
|
+
|
|
53
|
+
- c1cceea: Bump peerdeps of @matra/core
|
|
54
|
+
- @mastra/core@0.10.11-alpha.4
|
|
55
|
+
|
|
56
|
+
## 0.11.3-alpha.2
|
|
57
|
+
|
|
58
|
+
### Patch Changes
|
|
59
|
+
|
|
60
|
+
- defb5ae: dependencies updates:
|
|
61
|
+
- Updated dependency [`inngest@^3.40.0` ↗︎](https://www.npmjs.com/package/inngest/v/3.40.0) (from `^3.39.2`, in `dependencies`)
|
|
62
|
+
- Updated dependencies [c7bbf1e]
|
|
63
|
+
- Updated dependencies [8722d53]
|
|
64
|
+
- Updated dependencies [132027f]
|
|
65
|
+
- Updated dependencies [0c85311]
|
|
66
|
+
- Updated dependencies [cb16baf]
|
|
67
|
+
- @mastra/core@0.10.11-alpha.3
|
|
68
|
+
|
|
69
|
+
## 0.11.3-alpha.1
|
|
70
|
+
|
|
71
|
+
### Patch Changes
|
|
72
|
+
|
|
73
|
+
- 515488a: dependencies updates:
|
|
74
|
+
- Updated dependency [`inngest@^3.39.2` ↗︎](https://www.npmjs.com/package/inngest/v/3.39.2) (from `^3.39.1`, in `dependencies`)
|
|
75
|
+
- Updated dependencies [7f6e403]
|
|
76
|
+
- @mastra/core@0.10.11-alpha.1
|
|
77
|
+
|
|
78
|
+
## 0.11.3-alpha.0
|
|
79
|
+
|
|
80
|
+
### Patch Changes
|
|
81
|
+
|
|
82
|
+
- b790fd1: Ability to pass a function to .sleep()/.sleepUntil()
|
|
83
|
+
- Updated dependencies [f8ce2cc]
|
|
84
|
+
- Updated dependencies [8c846b6]
|
|
85
|
+
- Updated dependencies [b790fd1]
|
|
86
|
+
- Updated dependencies [d7ed04d]
|
|
87
|
+
- Updated dependencies [f36e4f1]
|
|
88
|
+
- @mastra/core@0.10.11-alpha.0
|
|
89
|
+
|
|
90
|
+
## 0.11.2
|
|
4
91
|
|
|
5
92
|
### Patch Changes
|
|
6
93
|
|
|
7
94
|
- 48d9738: Fix inngest sleep stream events
|
|
8
95
|
- Updated dependencies [4d3fbdf]
|
|
9
|
-
- @mastra/core@0.
|
|
96
|
+
- @mastra/core@0.10.10
|
|
10
97
|
|
|
11
98
|
## 0.11.2-alpha.0
|
|
12
99
|
|
package/LICENSE.md
CHANGED
|
@@ -1,46 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Apache License 2.0
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2025
|
|
3
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
|
|
17
|
-
|
|
18
|
-
**Patents**
|
|
19
|
-
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
20
|
-
|
|
21
|
-
**Notices**
|
|
22
|
-
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
|
|
23
|
-
|
|
24
|
-
If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
|
|
25
|
-
|
|
26
|
-
**No Other Rights**
|
|
27
|
-
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
28
|
-
|
|
29
|
-
**Termination**
|
|
30
|
-
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
|
|
31
|
-
|
|
32
|
-
**No Liability**
|
|
33
|
-
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
34
|
-
|
|
35
|
-
**Definitions**
|
|
36
|
-
The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
|
|
37
|
-
|
|
38
|
-
_you_ refers to the individual or entity agreeing to these terms.
|
|
39
|
-
|
|
40
|
-
_your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
41
|
-
|
|
42
|
-
_your licenses_ are all the licenses granted to you for the software under these terms.
|
|
43
|
-
|
|
44
|
-
_use_ means anything you do with the software requiring one of your licenses.
|
|
45
|
-
|
|
46
|
-
_trademark_ means trademarks, service marks, and similar rights.
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
@@ -109,9 +109,53 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
109
109
|
abortController: AbortController;
|
|
110
110
|
runtimeContext: RuntimeContext;
|
|
111
111
|
}): Promise<StepResult<any, any, any, any>>;
|
|
112
|
-
executeSleep({
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
executeSleep({ workflowId, runId, entry, prevOutput, stepResults, emitter, abortController, runtimeContext, }: {
|
|
113
|
+
workflowId: string;
|
|
114
|
+
runId: string;
|
|
115
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
116
|
+
entry: {
|
|
117
|
+
type: 'sleep';
|
|
118
|
+
id: string;
|
|
119
|
+
duration?: number;
|
|
120
|
+
fn?: ExecuteFunction<any, any, any, any, InngestEngineType>;
|
|
121
|
+
};
|
|
122
|
+
prevStep: StepFlowEntry;
|
|
123
|
+
prevOutput: any;
|
|
124
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
125
|
+
resume?: {
|
|
126
|
+
steps: string[];
|
|
127
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
128
|
+
resumePayload: any;
|
|
129
|
+
resumePath: number[];
|
|
130
|
+
};
|
|
131
|
+
executionContext: ExecutionContext;
|
|
132
|
+
emitter: Emitter;
|
|
133
|
+
abortController: AbortController;
|
|
134
|
+
runtimeContext: RuntimeContext;
|
|
135
|
+
}): Promise<void>;
|
|
136
|
+
executeSleepUntil({ workflowId, runId, entry, prevOutput, stepResults, emitter, abortController, runtimeContext, }: {
|
|
137
|
+
workflowId: string;
|
|
138
|
+
runId: string;
|
|
139
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
140
|
+
entry: {
|
|
141
|
+
type: 'sleepUntil';
|
|
142
|
+
id: string;
|
|
143
|
+
date?: Date;
|
|
144
|
+
fn?: ExecuteFunction<any, any, any, any, InngestEngineType>;
|
|
145
|
+
};
|
|
146
|
+
prevStep: StepFlowEntry;
|
|
147
|
+
prevOutput: any;
|
|
148
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
149
|
+
resume?: {
|
|
150
|
+
steps: string[];
|
|
151
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
152
|
+
resumePayload: any;
|
|
153
|
+
resumePath: number[];
|
|
154
|
+
};
|
|
155
|
+
executionContext: ExecutionContext;
|
|
156
|
+
emitter: Emitter;
|
|
157
|
+
abortController: AbortController;
|
|
158
|
+
runtimeContext: RuntimeContext;
|
|
115
159
|
}): Promise<void>;
|
|
116
160
|
executeWaitForEvent({ event, timeout }: {
|
|
117
161
|
event: string;
|
|
@@ -140,6 +184,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
140
184
|
workflowStatus: 'success' | 'failed' | 'suspended' | 'running';
|
|
141
185
|
result?: Record<string, any>;
|
|
142
186
|
error?: string | Error;
|
|
187
|
+
runtimeContext: RuntimeContext;
|
|
143
188
|
}): Promise<void>;
|
|
144
189
|
executeConditional({ workflowId, runId, entry, prevOutput, prevStep, stepResults, serializedStepGraph, resume, executionContext, emitter, abortController, runtimeContext, }: {
|
|
145
190
|
workflowId: string;
|
|
@@ -109,9 +109,53 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
109
109
|
abortController: AbortController;
|
|
110
110
|
runtimeContext: RuntimeContext;
|
|
111
111
|
}): Promise<StepResult<any, any, any, any>>;
|
|
112
|
-
executeSleep({
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
executeSleep({ workflowId, runId, entry, prevOutput, stepResults, emitter, abortController, runtimeContext, }: {
|
|
113
|
+
workflowId: string;
|
|
114
|
+
runId: string;
|
|
115
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
116
|
+
entry: {
|
|
117
|
+
type: 'sleep';
|
|
118
|
+
id: string;
|
|
119
|
+
duration?: number;
|
|
120
|
+
fn?: ExecuteFunction<any, any, any, any, InngestEngineType>;
|
|
121
|
+
};
|
|
122
|
+
prevStep: StepFlowEntry;
|
|
123
|
+
prevOutput: any;
|
|
124
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
125
|
+
resume?: {
|
|
126
|
+
steps: string[];
|
|
127
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
128
|
+
resumePayload: any;
|
|
129
|
+
resumePath: number[];
|
|
130
|
+
};
|
|
131
|
+
executionContext: ExecutionContext;
|
|
132
|
+
emitter: Emitter;
|
|
133
|
+
abortController: AbortController;
|
|
134
|
+
runtimeContext: RuntimeContext;
|
|
135
|
+
}): Promise<void>;
|
|
136
|
+
executeSleepUntil({ workflowId, runId, entry, prevOutput, stepResults, emitter, abortController, runtimeContext, }: {
|
|
137
|
+
workflowId: string;
|
|
138
|
+
runId: string;
|
|
139
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
140
|
+
entry: {
|
|
141
|
+
type: 'sleepUntil';
|
|
142
|
+
id: string;
|
|
143
|
+
date?: Date;
|
|
144
|
+
fn?: ExecuteFunction<any, any, any, any, InngestEngineType>;
|
|
145
|
+
};
|
|
146
|
+
prevStep: StepFlowEntry;
|
|
147
|
+
prevOutput: any;
|
|
148
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
149
|
+
resume?: {
|
|
150
|
+
steps: string[];
|
|
151
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
152
|
+
resumePayload: any;
|
|
153
|
+
resumePath: number[];
|
|
154
|
+
};
|
|
155
|
+
executionContext: ExecutionContext;
|
|
156
|
+
emitter: Emitter;
|
|
157
|
+
abortController: AbortController;
|
|
158
|
+
runtimeContext: RuntimeContext;
|
|
115
159
|
}): Promise<void>;
|
|
116
160
|
executeWaitForEvent({ event, timeout }: {
|
|
117
161
|
event: string;
|
|
@@ -140,6 +184,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
140
184
|
workflowStatus: 'success' | 'failed' | 'suspended' | 'running';
|
|
141
185
|
result?: Record<string, any>;
|
|
142
186
|
error?: string | Error;
|
|
187
|
+
runtimeContext: RuntimeContext;
|
|
143
188
|
}): Promise<void>;
|
|
144
189
|
executeConditional({ workflowId, runId, entry, prevOutput, prevStep, stepResults, serializedStepGraph, resume, executionContext, emitter, abortController, runtimeContext, }: {
|
|
145
190
|
workflowId: string;
|
package/dist/index.cjs
CHANGED
|
@@ -665,8 +665,103 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
665
665
|
runtimeContext
|
|
666
666
|
});
|
|
667
667
|
}
|
|
668
|
-
async executeSleep({ id, duration }) {
|
|
669
|
-
|
|
668
|
+
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
669
|
+
// await this.inngestStep.sleep(id, duration);
|
|
670
|
+
// }
|
|
671
|
+
async executeSleep({
|
|
672
|
+
workflowId,
|
|
673
|
+
runId,
|
|
674
|
+
entry,
|
|
675
|
+
prevOutput,
|
|
676
|
+
stepResults,
|
|
677
|
+
emitter,
|
|
678
|
+
abortController,
|
|
679
|
+
runtimeContext
|
|
680
|
+
}) {
|
|
681
|
+
let { duration, fn } = entry;
|
|
682
|
+
if (fn) {
|
|
683
|
+
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
684
|
+
return await fn({
|
|
685
|
+
runId,
|
|
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
|
+
[_constants.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
|
+
mastra: this.mastra,
|
|
733
|
+
runtimeContext,
|
|
734
|
+
inputData: prevOutput,
|
|
735
|
+
runCount: -1,
|
|
736
|
+
getInitData: () => stepResults?.input,
|
|
737
|
+
getStepResult: (step) => {
|
|
738
|
+
if (!step?.id) {
|
|
739
|
+
return null;
|
|
740
|
+
}
|
|
741
|
+
const result = stepResults[step.id];
|
|
742
|
+
if (result?.status === "success") {
|
|
743
|
+
return result.output;
|
|
744
|
+
}
|
|
745
|
+
return null;
|
|
746
|
+
},
|
|
747
|
+
// TODO: this function shouldn't have suspend probably?
|
|
748
|
+
suspend: async (_suspendPayload) => {
|
|
749
|
+
},
|
|
750
|
+
bail: () => {
|
|
751
|
+
},
|
|
752
|
+
abort: () => {
|
|
753
|
+
abortController?.abort();
|
|
754
|
+
},
|
|
755
|
+
[_constants.EMITTER_SYMBOL]: emitter,
|
|
756
|
+
engine: { step: this.inngestStep },
|
|
757
|
+
abortSignal: abortController?.signal
|
|
758
|
+
});
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
if (!(date instanceof Date)) {
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
await this.inngestStep.sleepUntil(entry.id, date);
|
|
670
765
|
}
|
|
671
766
|
async executeWaitForEvent({ event, timeout }) {
|
|
672
767
|
const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
|
package/dist/index.js
CHANGED
|
@@ -663,8 +663,103 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
663
663
|
runtimeContext
|
|
664
664
|
});
|
|
665
665
|
}
|
|
666
|
-
async executeSleep({ id, duration }) {
|
|
667
|
-
|
|
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);
|
|
668
763
|
}
|
|
669
764
|
async executeWaitForEvent({ event, timeout }) {
|
|
670
765
|
const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
|
package/docker-compose.yaml
CHANGED
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-message-list-update-20250715150321",
|
|
4
4
|
"description": "Mastra Inngest integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
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": {
|
|
@@ -31,20 +31,20 @@
|
|
|
31
31
|
"@microsoft/api-extractor": "^7.52.8",
|
|
32
32
|
"@types/node": "^20.19.0",
|
|
33
33
|
"ai": "^4.3.16",
|
|
34
|
-
"eslint": "^9.
|
|
34
|
+
"eslint": "^9.30.1",
|
|
35
35
|
"execa": "^9.6.0",
|
|
36
36
|
"get-port": "7.1.0",
|
|
37
|
-
"hono": "^4.8.
|
|
37
|
+
"hono": "^4.8.4",
|
|
38
38
|
"tsup": "^8.5.0",
|
|
39
39
|
"typescript": "^5.8.3",
|
|
40
40
|
"vitest": "^3.2.4",
|
|
41
|
-
"@internal/lint": "0.0.0-
|
|
42
|
-
"@mastra/core": "0.0.0-
|
|
43
|
-
"@mastra/
|
|
44
|
-
"@mastra/
|
|
41
|
+
"@internal/lint": "0.0.0-message-list-update-20250715150321",
|
|
42
|
+
"@mastra/core": "0.0.0-message-list-update-20250715150321",
|
|
43
|
+
"@mastra/libsql": "0.0.0-message-list-update-20250715150321",
|
|
44
|
+
"@mastra/deployer": "0.0.0-message-list-update-20250715150321"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@mastra/core": "0.0.0-
|
|
47
|
+
"@mastra/core": "0.0.0-message-list-update-20250715150321"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|
package/src/index.test.ts
CHANGED
|
@@ -367,7 +367,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
367
367
|
srv.close();
|
|
368
368
|
});
|
|
369
369
|
|
|
370
|
-
it('should execute a
|
|
370
|
+
it('should execute a sleep step', async ctx => {
|
|
371
371
|
const inngest = new Inngest({
|
|
372
372
|
id: 'mastra',
|
|
373
373
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -455,6 +455,100 @@ describe('MastraInngestWorkflow', () => {
|
|
|
455
455
|
srv.close();
|
|
456
456
|
});
|
|
457
457
|
|
|
458
|
+
it('should execute a sleep step with fn parameter', async ctx => {
|
|
459
|
+
const inngest = new Inngest({
|
|
460
|
+
id: 'mastra',
|
|
461
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
465
|
+
|
|
466
|
+
const execute = vi.fn<any>().mockResolvedValue({ value: 1000 });
|
|
467
|
+
const step1 = createStep({
|
|
468
|
+
id: 'step1',
|
|
469
|
+
execute,
|
|
470
|
+
inputSchema: z.object({}),
|
|
471
|
+
outputSchema: z.object({ value: z.number() }),
|
|
472
|
+
});
|
|
473
|
+
const step2 = createStep({
|
|
474
|
+
id: 'step2',
|
|
475
|
+
execute: async ({ inputData }) => {
|
|
476
|
+
return { value: inputData.value + 1000 };
|
|
477
|
+
},
|
|
478
|
+
inputSchema: z.object({ value: z.number() }),
|
|
479
|
+
outputSchema: z.object({ value: z.number() }),
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
const workflow = createWorkflow({
|
|
483
|
+
id: 'test-workflow',
|
|
484
|
+
inputSchema: z.object({}),
|
|
485
|
+
outputSchema: z.object({
|
|
486
|
+
value: z.number(),
|
|
487
|
+
}),
|
|
488
|
+
steps: [step1],
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
workflow
|
|
492
|
+
.then(step1)
|
|
493
|
+
.sleep(async ({ inputData }) => {
|
|
494
|
+
return inputData.value;
|
|
495
|
+
})
|
|
496
|
+
.then(step2)
|
|
497
|
+
.commit();
|
|
498
|
+
|
|
499
|
+
const mastra = new Mastra({
|
|
500
|
+
storage: new DefaultStorage({
|
|
501
|
+
url: ':memory:',
|
|
502
|
+
}),
|
|
503
|
+
workflows: {
|
|
504
|
+
'test-workflow': workflow,
|
|
505
|
+
},
|
|
506
|
+
server: {
|
|
507
|
+
apiRoutes: [
|
|
508
|
+
{
|
|
509
|
+
path: '/inngest/api',
|
|
510
|
+
method: 'ALL',
|
|
511
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
512
|
+
},
|
|
513
|
+
],
|
|
514
|
+
},
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
const app = await createHonoServer(mastra);
|
|
518
|
+
|
|
519
|
+
const srv = (globServer = serve({
|
|
520
|
+
fetch: app.fetch,
|
|
521
|
+
port: (ctx as any).handlerPort,
|
|
522
|
+
}));
|
|
523
|
+
await resetInngest();
|
|
524
|
+
|
|
525
|
+
const run = await workflow.createRunAsync();
|
|
526
|
+
const startTime = Date.now();
|
|
527
|
+
const result = await run.start({ inputData: {} });
|
|
528
|
+
const endTime = Date.now();
|
|
529
|
+
|
|
530
|
+
expect(execute).toHaveBeenCalled();
|
|
531
|
+
expect(result.steps['step1']).toMatchObject({
|
|
532
|
+
status: 'success',
|
|
533
|
+
output: { value: 1000 },
|
|
534
|
+
// payload: {},
|
|
535
|
+
// startedAt: expect.any(Number),
|
|
536
|
+
// endedAt: expect.any(Number),
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
expect(result.steps['step2']).toMatchObject({
|
|
540
|
+
status: 'success',
|
|
541
|
+
output: { value: 2000 },
|
|
542
|
+
// payload: { result: 'success' },
|
|
543
|
+
// startedAt: expect.any(Number),
|
|
544
|
+
// endedAt: expect.any(Number),
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
expect(endTime - startTime).toBeGreaterThan(1000);
|
|
548
|
+
|
|
549
|
+
srv.close();
|
|
550
|
+
});
|
|
551
|
+
|
|
458
552
|
it('should execute a a sleep until step', async ctx => {
|
|
459
553
|
const inngest = new Inngest({
|
|
460
554
|
id: 'mastra',
|
|
@@ -547,6 +641,100 @@ describe('MastraInngestWorkflow', () => {
|
|
|
547
641
|
srv.close();
|
|
548
642
|
});
|
|
549
643
|
|
|
644
|
+
it('should execute a sleep until step with fn parameter', async ctx => {
|
|
645
|
+
const inngest = new Inngest({
|
|
646
|
+
id: 'mastra',
|
|
647
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
651
|
+
|
|
652
|
+
const execute = vi.fn<any>().mockResolvedValue({ value: 1000 });
|
|
653
|
+
const step1 = createStep({
|
|
654
|
+
id: 'step1',
|
|
655
|
+
execute,
|
|
656
|
+
inputSchema: z.object({}),
|
|
657
|
+
outputSchema: z.object({ value: z.number() }),
|
|
658
|
+
});
|
|
659
|
+
const step2 = createStep({
|
|
660
|
+
id: 'step2',
|
|
661
|
+
execute: async ({ inputData }) => {
|
|
662
|
+
return { value: inputData.value + 1000 };
|
|
663
|
+
},
|
|
664
|
+
inputSchema: z.object({ value: z.number() }),
|
|
665
|
+
outputSchema: z.object({ value: z.number() }),
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
const workflow = createWorkflow({
|
|
669
|
+
id: 'test-workflow',
|
|
670
|
+
inputSchema: z.object({}),
|
|
671
|
+
outputSchema: z.object({
|
|
672
|
+
value: z.number(),
|
|
673
|
+
}),
|
|
674
|
+
steps: [step1],
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
workflow
|
|
678
|
+
.then(step1)
|
|
679
|
+
.sleepUntil(async ({ inputData }) => {
|
|
680
|
+
return new Date(Date.now() + inputData.value);
|
|
681
|
+
})
|
|
682
|
+
.then(step2)
|
|
683
|
+
.commit();
|
|
684
|
+
|
|
685
|
+
const mastra = new Mastra({
|
|
686
|
+
storage: new DefaultStorage({
|
|
687
|
+
url: ':memory:',
|
|
688
|
+
}),
|
|
689
|
+
workflows: {
|
|
690
|
+
'test-workflow': workflow,
|
|
691
|
+
},
|
|
692
|
+
server: {
|
|
693
|
+
apiRoutes: [
|
|
694
|
+
{
|
|
695
|
+
path: '/inngest/api',
|
|
696
|
+
method: 'ALL',
|
|
697
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
698
|
+
},
|
|
699
|
+
],
|
|
700
|
+
},
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
const app = await createHonoServer(mastra);
|
|
704
|
+
|
|
705
|
+
const srv = (globServer = serve({
|
|
706
|
+
fetch: app.fetch,
|
|
707
|
+
port: (ctx as any).handlerPort,
|
|
708
|
+
}));
|
|
709
|
+
await resetInngest();
|
|
710
|
+
|
|
711
|
+
const run = await workflow.createRunAsync();
|
|
712
|
+
const startTime = Date.now();
|
|
713
|
+
const result = await run.start({ inputData: {} });
|
|
714
|
+
const endTime = Date.now();
|
|
715
|
+
|
|
716
|
+
expect(execute).toHaveBeenCalled();
|
|
717
|
+
expect(result.steps['step1']).toMatchObject({
|
|
718
|
+
status: 'success',
|
|
719
|
+
output: { value: 1000 },
|
|
720
|
+
// payload: {},
|
|
721
|
+
// startedAt: expect.any(Number),
|
|
722
|
+
// endedAt: expect.any(Number),
|
|
723
|
+
});
|
|
724
|
+
|
|
725
|
+
expect(result.steps['step2']).toMatchObject({
|
|
726
|
+
status: 'success',
|
|
727
|
+
output: { value: 2000 },
|
|
728
|
+
// payload: { result: 'success' },
|
|
729
|
+
// startedAt: expect.any(Number),
|
|
730
|
+
// endedAt: expect.any(Number),
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
expect(endTime - startTime).toBeGreaterThan(1000);
|
|
734
|
+
|
|
735
|
+
srv.close();
|
|
736
|
+
});
|
|
737
|
+
|
|
550
738
|
it('should execute a a waitForEvent step', async ctx => {
|
|
551
739
|
const inngest = new Inngest({
|
|
552
740
|
id: 'mastra',
|
|
@@ -6031,6 +6219,176 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6031
6219
|
// @ts-ignore
|
|
6032
6220
|
expect(result?.steps.step1.output.injectedValue).toBe(testValue + '2');
|
|
6033
6221
|
});
|
|
6222
|
+
|
|
6223
|
+
it('should have access to runtimeContext from before suspension during workflow resume', async ctx => {
|
|
6224
|
+
const inngest = new Inngest({
|
|
6225
|
+
id: 'mastra',
|
|
6226
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
6227
|
+
});
|
|
6228
|
+
|
|
6229
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
6230
|
+
|
|
6231
|
+
const testValue = 'test-dependency';
|
|
6232
|
+
const resumeStep = createStep({
|
|
6233
|
+
id: 'resume',
|
|
6234
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6235
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6236
|
+
resumeSchema: z.object({ value: z.number() }),
|
|
6237
|
+
suspendSchema: z.object({ message: z.string() }),
|
|
6238
|
+
execute: async ({ inputData, resumeData, suspend }) => {
|
|
6239
|
+
const finalValue = (resumeData?.value ?? 0) + inputData.value;
|
|
6240
|
+
|
|
6241
|
+
if (!resumeData?.value || finalValue < 10) {
|
|
6242
|
+
return await suspend({
|
|
6243
|
+
message: `Please provide additional information. now value is ${inputData.value}`,
|
|
6244
|
+
});
|
|
6245
|
+
}
|
|
6246
|
+
|
|
6247
|
+
return { value: finalValue };
|
|
6248
|
+
},
|
|
6249
|
+
});
|
|
6250
|
+
|
|
6251
|
+
const incrementStep = createStep({
|
|
6252
|
+
id: 'increment',
|
|
6253
|
+
inputSchema: z.object({
|
|
6254
|
+
value: z.number(),
|
|
6255
|
+
}),
|
|
6256
|
+
outputSchema: z.object({
|
|
6257
|
+
value: z.number(),
|
|
6258
|
+
}),
|
|
6259
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
6260
|
+
runtimeContext.set('testKey', testValue);
|
|
6261
|
+
return {
|
|
6262
|
+
value: inputData.value + 1,
|
|
6263
|
+
};
|
|
6264
|
+
},
|
|
6265
|
+
});
|
|
6266
|
+
|
|
6267
|
+
const incrementWorkflow = createWorkflow({
|
|
6268
|
+
id: 'increment-workflow',
|
|
6269
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6270
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6271
|
+
})
|
|
6272
|
+
.then(incrementStep)
|
|
6273
|
+
.then(resumeStep)
|
|
6274
|
+
.then(
|
|
6275
|
+
createStep({
|
|
6276
|
+
id: 'final',
|
|
6277
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6278
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6279
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
6280
|
+
const testKey = runtimeContext.get('testKey');
|
|
6281
|
+
expect(testKey).toBe(testValue);
|
|
6282
|
+
return { value: inputData.value };
|
|
6283
|
+
},
|
|
6284
|
+
}),
|
|
6285
|
+
)
|
|
6286
|
+
.commit();
|
|
6287
|
+
|
|
6288
|
+
new Mastra({
|
|
6289
|
+
logger: false,
|
|
6290
|
+
storage: testStorage,
|
|
6291
|
+
workflows: { incrementWorkflow },
|
|
6292
|
+
});
|
|
6293
|
+
|
|
6294
|
+
const run = await incrementWorkflow.createRunAsync();
|
|
6295
|
+
const result = await run.start({ inputData: { value: 0 } });
|
|
6296
|
+
expect(result.status).toBe('suspended');
|
|
6297
|
+
|
|
6298
|
+
const resumeResult = await run.resume({
|
|
6299
|
+
resumeData: { value: 21 },
|
|
6300
|
+
step: ['resume'],
|
|
6301
|
+
});
|
|
6302
|
+
|
|
6303
|
+
expect(resumeResult.status).toBe('success');
|
|
6304
|
+
});
|
|
6305
|
+
|
|
6306
|
+
it('should not show removed runtimeContext values in subsequent steps', async ctx => {
|
|
6307
|
+
const inngest = new Inngest({
|
|
6308
|
+
id: 'mastra',
|
|
6309
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
6310
|
+
});
|
|
6311
|
+
|
|
6312
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
6313
|
+
const testValue = 'test-dependency';
|
|
6314
|
+
const resumeStep = createStep({
|
|
6315
|
+
id: 'resume',
|
|
6316
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6317
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6318
|
+
resumeSchema: z.object({ value: z.number() }),
|
|
6319
|
+
suspendSchema: z.object({ message: z.string() }),
|
|
6320
|
+
execute: async ({ inputData, resumeData, suspend, runtimeContext }) => {
|
|
6321
|
+
const finalValue = (resumeData?.value ?? 0) + inputData.value;
|
|
6322
|
+
|
|
6323
|
+
if (!resumeData?.value || finalValue < 10) {
|
|
6324
|
+
return await suspend({
|
|
6325
|
+
message: `Please provide additional information. now value is ${inputData.value}`,
|
|
6326
|
+
});
|
|
6327
|
+
}
|
|
6328
|
+
|
|
6329
|
+
const testKey = runtimeContext.get('testKey');
|
|
6330
|
+
expect(testKey).toBe(testValue);
|
|
6331
|
+
|
|
6332
|
+
runtimeContext.delete('testKey');
|
|
6333
|
+
|
|
6334
|
+
return { value: finalValue };
|
|
6335
|
+
},
|
|
6336
|
+
});
|
|
6337
|
+
|
|
6338
|
+
const incrementStep = createStep({
|
|
6339
|
+
id: 'increment',
|
|
6340
|
+
inputSchema: z.object({
|
|
6341
|
+
value: z.number(),
|
|
6342
|
+
}),
|
|
6343
|
+
outputSchema: z.object({
|
|
6344
|
+
value: z.number(),
|
|
6345
|
+
}),
|
|
6346
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
6347
|
+
runtimeContext.set('testKey', testValue);
|
|
6348
|
+
return {
|
|
6349
|
+
value: inputData.value + 1,
|
|
6350
|
+
};
|
|
6351
|
+
},
|
|
6352
|
+
});
|
|
6353
|
+
|
|
6354
|
+
const incrementWorkflow = createWorkflow({
|
|
6355
|
+
id: 'increment-workflow',
|
|
6356
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6357
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6358
|
+
})
|
|
6359
|
+
.then(incrementStep)
|
|
6360
|
+
.then(resumeStep)
|
|
6361
|
+
.then(
|
|
6362
|
+
createStep({
|
|
6363
|
+
id: 'final',
|
|
6364
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6365
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6366
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
6367
|
+
const testKey = runtimeContext.get('testKey');
|
|
6368
|
+
expect(testKey).toBeUndefined();
|
|
6369
|
+
return { value: inputData.value };
|
|
6370
|
+
},
|
|
6371
|
+
}),
|
|
6372
|
+
)
|
|
6373
|
+
.commit();
|
|
6374
|
+
|
|
6375
|
+
new Mastra({
|
|
6376
|
+
logger: false,
|
|
6377
|
+
storage: testStorage,
|
|
6378
|
+
workflows: { incrementWorkflow },
|
|
6379
|
+
});
|
|
6380
|
+
|
|
6381
|
+
const run = await incrementWorkflow.createRunAsync();
|
|
6382
|
+
const result = await run.start({ inputData: { value: 0 } });
|
|
6383
|
+
expect(result.status).toBe('suspended');
|
|
6384
|
+
|
|
6385
|
+
const resumeResult = await run.resume({
|
|
6386
|
+
resumeData: { value: 21 },
|
|
6387
|
+
step: ['resume'],
|
|
6388
|
+
});
|
|
6389
|
+
|
|
6390
|
+
expect(resumeResult.status).toBe('success');
|
|
6391
|
+
});
|
|
6034
6392
|
});
|
|
6035
6393
|
|
|
6036
6394
|
describe('Access to inngest step primitives', () => {
|
|
@@ -6473,6 +6831,215 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6473
6831
|
});
|
|
6474
6832
|
});
|
|
6475
6833
|
|
|
6834
|
+
it('should handle basic sleep waiting flow with fn parameter', async ctx => {
|
|
6835
|
+
const inngest = new Inngest({
|
|
6836
|
+
id: 'mastra',
|
|
6837
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
6838
|
+
middleware: [realtimeMiddleware()],
|
|
6839
|
+
});
|
|
6840
|
+
|
|
6841
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
6842
|
+
|
|
6843
|
+
const step1Action = vi.fn<any>().mockResolvedValue({ value: 1000 });
|
|
6844
|
+
const step2Action = vi.fn<any>().mockResolvedValue({ value: 2000 });
|
|
6845
|
+
|
|
6846
|
+
const step1 = createStep({
|
|
6847
|
+
id: 'step1',
|
|
6848
|
+
execute: step1Action,
|
|
6849
|
+
inputSchema: z.object({}),
|
|
6850
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6851
|
+
});
|
|
6852
|
+
const step2 = createStep({
|
|
6853
|
+
id: 'step2',
|
|
6854
|
+
execute: step2Action,
|
|
6855
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6856
|
+
outputSchema: z.object({}),
|
|
6857
|
+
});
|
|
6858
|
+
|
|
6859
|
+
const workflow = createWorkflow({
|
|
6860
|
+
id: 'test-workflow',
|
|
6861
|
+
inputSchema: z.object({}),
|
|
6862
|
+
outputSchema: z.object({}),
|
|
6863
|
+
steps: [step1, step2],
|
|
6864
|
+
});
|
|
6865
|
+
workflow
|
|
6866
|
+
.then(step1)
|
|
6867
|
+
.sleep(async ({ inputData }) => {
|
|
6868
|
+
return inputData.value;
|
|
6869
|
+
})
|
|
6870
|
+
.then(step2)
|
|
6871
|
+
.commit();
|
|
6872
|
+
|
|
6873
|
+
const mastra = new Mastra({
|
|
6874
|
+
storage: new DefaultStorage({
|
|
6875
|
+
url: ':memory:',
|
|
6876
|
+
}),
|
|
6877
|
+
workflows: {
|
|
6878
|
+
'test-workflow': workflow,
|
|
6879
|
+
},
|
|
6880
|
+
server: {
|
|
6881
|
+
apiRoutes: [
|
|
6882
|
+
{
|
|
6883
|
+
path: '/inngest/api',
|
|
6884
|
+
method: 'ALL',
|
|
6885
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
6886
|
+
},
|
|
6887
|
+
],
|
|
6888
|
+
},
|
|
6889
|
+
});
|
|
6890
|
+
|
|
6891
|
+
const app = await createHonoServer(mastra);
|
|
6892
|
+
|
|
6893
|
+
const srv = (globServer = serve({
|
|
6894
|
+
fetch: app.fetch,
|
|
6895
|
+
port: (ctx as any).handlerPort,
|
|
6896
|
+
}));
|
|
6897
|
+
await resetInngest();
|
|
6898
|
+
|
|
6899
|
+
const runId = 'test-run-id';
|
|
6900
|
+
let watchData: StreamEvent[] = [];
|
|
6901
|
+
const run = await workflow.createRunAsync({
|
|
6902
|
+
runId,
|
|
6903
|
+
});
|
|
6904
|
+
|
|
6905
|
+
await resetInngest();
|
|
6906
|
+
|
|
6907
|
+
const { stream, getWorkflowState } = run.stream({ inputData: {} });
|
|
6908
|
+
|
|
6909
|
+
// Start watching the workflow
|
|
6910
|
+
const collectedStreamData: StreamEvent[] = [];
|
|
6911
|
+
for await (const data of stream) {
|
|
6912
|
+
collectedStreamData.push(JSON.parse(JSON.stringify(data)));
|
|
6913
|
+
}
|
|
6914
|
+
watchData = collectedStreamData;
|
|
6915
|
+
|
|
6916
|
+
const executionResult = await getWorkflowState();
|
|
6917
|
+
|
|
6918
|
+
await resetInngest();
|
|
6919
|
+
|
|
6920
|
+
srv.close();
|
|
6921
|
+
|
|
6922
|
+
expect(watchData.length).toBe(11);
|
|
6923
|
+
expect(watchData).toMatchObject([
|
|
6924
|
+
{
|
|
6925
|
+
payload: {
|
|
6926
|
+
runId: 'test-run-id',
|
|
6927
|
+
},
|
|
6928
|
+
type: 'start',
|
|
6929
|
+
},
|
|
6930
|
+
{
|
|
6931
|
+
payload: {
|
|
6932
|
+
id: 'step1',
|
|
6933
|
+
startedAt: expect.any(Number),
|
|
6934
|
+
status: 'running',
|
|
6935
|
+
payload: {},
|
|
6936
|
+
},
|
|
6937
|
+
type: 'step-start',
|
|
6938
|
+
},
|
|
6939
|
+
{
|
|
6940
|
+
payload: {
|
|
6941
|
+
id: 'step1',
|
|
6942
|
+
output: {
|
|
6943
|
+
value: 1000,
|
|
6944
|
+
},
|
|
6945
|
+
endedAt: expect.any(Number),
|
|
6946
|
+
status: 'success',
|
|
6947
|
+
},
|
|
6948
|
+
type: 'step-result',
|
|
6949
|
+
},
|
|
6950
|
+
{
|
|
6951
|
+
payload: {
|
|
6952
|
+
id: 'step1',
|
|
6953
|
+
metadata: {},
|
|
6954
|
+
},
|
|
6955
|
+
type: 'step-finish',
|
|
6956
|
+
},
|
|
6957
|
+
{
|
|
6958
|
+
payload: {
|
|
6959
|
+
id: expect.any(String),
|
|
6960
|
+
startedAt: expect.any(Number),
|
|
6961
|
+
status: 'waiting',
|
|
6962
|
+
payload: {
|
|
6963
|
+
value: 1000,
|
|
6964
|
+
},
|
|
6965
|
+
},
|
|
6966
|
+
type: 'step-waiting',
|
|
6967
|
+
},
|
|
6968
|
+
{
|
|
6969
|
+
payload: {
|
|
6970
|
+
id: expect.any(String),
|
|
6971
|
+
endedAt: expect.any(Number),
|
|
6972
|
+
startedAt: expect.any(Number),
|
|
6973
|
+
status: 'success',
|
|
6974
|
+
output: {
|
|
6975
|
+
value: 1000,
|
|
6976
|
+
},
|
|
6977
|
+
},
|
|
6978
|
+
type: 'step-result',
|
|
6979
|
+
},
|
|
6980
|
+
{
|
|
6981
|
+
type: 'step-finish',
|
|
6982
|
+
payload: {
|
|
6983
|
+
id: expect.any(String),
|
|
6984
|
+
metadata: {},
|
|
6985
|
+
},
|
|
6986
|
+
},
|
|
6987
|
+
{
|
|
6988
|
+
payload: {
|
|
6989
|
+
id: 'step2',
|
|
6990
|
+
payload: {
|
|
6991
|
+
value: 1000,
|
|
6992
|
+
},
|
|
6993
|
+
startedAt: expect.any(Number),
|
|
6994
|
+
status: 'running',
|
|
6995
|
+
},
|
|
6996
|
+
type: 'step-start',
|
|
6997
|
+
},
|
|
6998
|
+
{
|
|
6999
|
+
payload: {
|
|
7000
|
+
id: 'step2',
|
|
7001
|
+
output: {
|
|
7002
|
+
value: 2000,
|
|
7003
|
+
},
|
|
7004
|
+
endedAt: expect.any(Number),
|
|
7005
|
+
status: 'success',
|
|
7006
|
+
},
|
|
7007
|
+
type: 'step-result',
|
|
7008
|
+
},
|
|
7009
|
+
{
|
|
7010
|
+
payload: {
|
|
7011
|
+
id: 'step2',
|
|
7012
|
+
metadata: {},
|
|
7013
|
+
},
|
|
7014
|
+
type: 'step-finish',
|
|
7015
|
+
},
|
|
7016
|
+
{
|
|
7017
|
+
payload: {
|
|
7018
|
+
runId: 'test-run-id',
|
|
7019
|
+
},
|
|
7020
|
+
type: 'finish',
|
|
7021
|
+
},
|
|
7022
|
+
]);
|
|
7023
|
+
|
|
7024
|
+
// Verify execution completed successfully
|
|
7025
|
+
expect(executionResult.steps.step1).toMatchObject({
|
|
7026
|
+
status: 'success',
|
|
7027
|
+
output: { value: 1000 },
|
|
7028
|
+
payload: {},
|
|
7029
|
+
startedAt: expect.any(Number),
|
|
7030
|
+
endedAt: expect.any(Number),
|
|
7031
|
+
});
|
|
7032
|
+
expect(executionResult.steps.step2).toMatchObject({
|
|
7033
|
+
status: 'success',
|
|
7034
|
+
output: { value: 2000 },
|
|
7035
|
+
payload: {
|
|
7036
|
+
value: 1000,
|
|
7037
|
+
},
|
|
7038
|
+
startedAt: expect.any(Number),
|
|
7039
|
+
endedAt: expect.any(Number),
|
|
7040
|
+
});
|
|
7041
|
+
});
|
|
7042
|
+
|
|
6476
7043
|
it('should handle waitForEvent waiting flow', async ctx => {
|
|
6477
7044
|
const inngest = new Inngest({
|
|
6478
7045
|
id: 'mastra',
|
package/src/index.ts
CHANGED
|
@@ -997,8 +997,158 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
997
997
|
});
|
|
998
998
|
}
|
|
999
999
|
|
|
1000
|
-
async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
1001
|
-
|
|
1000
|
+
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
1001
|
+
// await this.inngestStep.sleep(id, duration);
|
|
1002
|
+
// }
|
|
1003
|
+
|
|
1004
|
+
async executeSleep({
|
|
1005
|
+
workflowId,
|
|
1006
|
+
runId,
|
|
1007
|
+
entry,
|
|
1008
|
+
prevOutput,
|
|
1009
|
+
stepResults,
|
|
1010
|
+
emitter,
|
|
1011
|
+
abortController,
|
|
1012
|
+
runtimeContext,
|
|
1013
|
+
}: {
|
|
1014
|
+
workflowId: string;
|
|
1015
|
+
runId: string;
|
|
1016
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
1017
|
+
entry: {
|
|
1018
|
+
type: 'sleep';
|
|
1019
|
+
id: string;
|
|
1020
|
+
duration?: number;
|
|
1021
|
+
fn?: ExecuteFunction<any, any, any, any, InngestEngineType>;
|
|
1022
|
+
};
|
|
1023
|
+
prevStep: StepFlowEntry;
|
|
1024
|
+
prevOutput: any;
|
|
1025
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
1026
|
+
resume?: {
|
|
1027
|
+
steps: string[];
|
|
1028
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
1029
|
+
resumePayload: any;
|
|
1030
|
+
resumePath: number[];
|
|
1031
|
+
};
|
|
1032
|
+
executionContext: ExecutionContext;
|
|
1033
|
+
emitter: Emitter;
|
|
1034
|
+
abortController: AbortController;
|
|
1035
|
+
runtimeContext: RuntimeContext;
|
|
1036
|
+
}): Promise<void> {
|
|
1037
|
+
let { duration, fn } = entry;
|
|
1038
|
+
|
|
1039
|
+
if (fn) {
|
|
1040
|
+
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
1041
|
+
return await fn({
|
|
1042
|
+
runId,
|
|
1043
|
+
mastra: this.mastra!,
|
|
1044
|
+
runtimeContext,
|
|
1045
|
+
inputData: prevOutput,
|
|
1046
|
+
runCount: -1,
|
|
1047
|
+
getInitData: () => stepResults?.input as any,
|
|
1048
|
+
getStepResult: (step: any) => {
|
|
1049
|
+
if (!step?.id) {
|
|
1050
|
+
return null;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
const result = stepResults[step.id];
|
|
1054
|
+
if (result?.status === 'success') {
|
|
1055
|
+
return result.output;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
return null;
|
|
1059
|
+
},
|
|
1060
|
+
|
|
1061
|
+
// TODO: this function shouldn't have suspend probably?
|
|
1062
|
+
suspend: async (_suspendPayload: any): Promise<any> => {},
|
|
1063
|
+
bail: () => {},
|
|
1064
|
+
abort: () => {
|
|
1065
|
+
abortController?.abort();
|
|
1066
|
+
},
|
|
1067
|
+
[EMITTER_SYMBOL]: emitter,
|
|
1068
|
+
engine: { step: this.inngestStep },
|
|
1069
|
+
abortSignal: abortController?.signal,
|
|
1070
|
+
});
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
async executeSleepUntil({
|
|
1078
|
+
workflowId,
|
|
1079
|
+
runId,
|
|
1080
|
+
entry,
|
|
1081
|
+
prevOutput,
|
|
1082
|
+
stepResults,
|
|
1083
|
+
emitter,
|
|
1084
|
+
abortController,
|
|
1085
|
+
runtimeContext,
|
|
1086
|
+
}: {
|
|
1087
|
+
workflowId: string;
|
|
1088
|
+
runId: string;
|
|
1089
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
1090
|
+
entry: {
|
|
1091
|
+
type: 'sleepUntil';
|
|
1092
|
+
id: string;
|
|
1093
|
+
date?: Date;
|
|
1094
|
+
fn?: ExecuteFunction<any, any, any, any, InngestEngineType>;
|
|
1095
|
+
};
|
|
1096
|
+
prevStep: StepFlowEntry;
|
|
1097
|
+
prevOutput: any;
|
|
1098
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
1099
|
+
resume?: {
|
|
1100
|
+
steps: string[];
|
|
1101
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
1102
|
+
resumePayload: any;
|
|
1103
|
+
resumePath: number[];
|
|
1104
|
+
};
|
|
1105
|
+
executionContext: ExecutionContext;
|
|
1106
|
+
emitter: Emitter;
|
|
1107
|
+
abortController: AbortController;
|
|
1108
|
+
runtimeContext: RuntimeContext;
|
|
1109
|
+
}): Promise<void> {
|
|
1110
|
+
let { date, fn } = entry;
|
|
1111
|
+
|
|
1112
|
+
if (fn) {
|
|
1113
|
+
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
1114
|
+
return await fn({
|
|
1115
|
+
runId,
|
|
1116
|
+
mastra: this.mastra!,
|
|
1117
|
+
runtimeContext,
|
|
1118
|
+
inputData: prevOutput,
|
|
1119
|
+
runCount: -1,
|
|
1120
|
+
getInitData: () => stepResults?.input as any,
|
|
1121
|
+
getStepResult: (step: any) => {
|
|
1122
|
+
if (!step?.id) {
|
|
1123
|
+
return null;
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
const result = stepResults[step.id];
|
|
1127
|
+
if (result?.status === 'success') {
|
|
1128
|
+
return result.output;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
return null;
|
|
1132
|
+
},
|
|
1133
|
+
|
|
1134
|
+
// TODO: this function shouldn't have suspend probably?
|
|
1135
|
+
suspend: async (_suspendPayload: any): Promise<any> => {},
|
|
1136
|
+
bail: () => {},
|
|
1137
|
+
abort: () => {
|
|
1138
|
+
abortController?.abort();
|
|
1139
|
+
},
|
|
1140
|
+
[EMITTER_SYMBOL]: emitter,
|
|
1141
|
+
engine: { step: this.inngestStep },
|
|
1142
|
+
abortSignal: abortController?.signal,
|
|
1143
|
+
});
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
if (!(date instanceof Date)) {
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
await this.inngestStep.sleepUntil(entry.id, date);
|
|
1002
1152
|
}
|
|
1003
1153
|
|
|
1004
1154
|
async executeWaitForEvent({ event, timeout }: { event: string; timeout?: number }): Promise<any> {
|
|
@@ -1425,6 +1575,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1425
1575
|
workflowStatus: 'success' | 'failed' | 'suspended' | 'running';
|
|
1426
1576
|
result?: Record<string, any>;
|
|
1427
1577
|
error?: string | Error;
|
|
1578
|
+
runtimeContext: RuntimeContext;
|
|
1428
1579
|
}) {
|
|
1429
1580
|
await this.inngestStep.run(
|
|
1430
1581
|
`workflow.${workflowId}.run.${runId}.path.${JSON.stringify(executionContext.executionPath)}.stepUpdate`,
|