@mastra/inngest 0.0.0-ai-v5-20250710191716 → 0.0.0-ai-v5-20250729012312
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 +114 -3
- package/dist/_tsup-dts-rollup.d.cts +12 -5
- package/dist/_tsup-dts-rollup.d.ts +12 -5
- package/dist/index.cjs +51 -10
- package/dist/index.js +52 -11
- package/docker-compose.yaml +1 -1
- package/package.json +8 -8
- package/src/index.test.ts +311 -11
- package/src/index.ts +49 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mastra/inngest
|
|
2
2
|
|
|
3
|
-
## 0.0.0-ai-v5-
|
|
3
|
+
## 0.0.0-ai-v5-20250729012312
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -8,9 +8,120 @@
|
|
|
8
8
|
|
|
9
9
|
### Patch Changes
|
|
10
10
|
|
|
11
|
-
- Updated dependencies [
|
|
11
|
+
- Updated dependencies [f96993c]
|
|
12
|
+
- Updated dependencies [6725b7b]
|
|
13
|
+
- Updated dependencies [5fc97af]
|
|
14
|
+
- Updated dependencies [39fcf57]
|
|
15
|
+
- Updated dependencies [6ab4a1c]
|
|
16
|
+
- Updated dependencies [41daa63]
|
|
17
|
+
- Updated dependencies [254a36b]
|
|
18
|
+
- Updated dependencies [67c55d0]
|
|
19
|
+
- Updated dependencies [731c220]
|
|
20
|
+
- Updated dependencies [c37d890]
|
|
21
|
+
- Updated dependencies [041d2de]
|
|
22
|
+
- Updated dependencies [4de4737]
|
|
23
|
+
- Updated dependencies [679c163]
|
|
24
|
+
- Updated dependencies [0f24e20]
|
|
25
|
+
- Updated dependencies [4cece2f]
|
|
26
|
+
- Updated dependencies [ff9c125]
|
|
12
27
|
- Updated dependencies [66858d4]
|
|
13
|
-
|
|
28
|
+
- Updated dependencies [19bc92c]
|
|
29
|
+
- Updated dependencies [b8efbb9]
|
|
30
|
+
- Updated dependencies [0c99fbe]
|
|
31
|
+
- @mastra/core@0.0.0-ai-v5-20250729012312
|
|
32
|
+
|
|
33
|
+
## 0.11.6
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- ce088f5: Update all peerdeps to latest core
|
|
38
|
+
- @mastra/core@0.11.1
|
|
39
|
+
|
|
40
|
+
## 0.11.5
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- a723d69: Pass workflowId through
|
|
45
|
+
- Updated dependencies [f248d53]
|
|
46
|
+
- Updated dependencies [2affc57]
|
|
47
|
+
- Updated dependencies [66e13e3]
|
|
48
|
+
- Updated dependencies [edd9482]
|
|
49
|
+
- Updated dependencies [18344d7]
|
|
50
|
+
- Updated dependencies [9d372c2]
|
|
51
|
+
- Updated dependencies [40c2525]
|
|
52
|
+
- Updated dependencies [e473f27]
|
|
53
|
+
- Updated dependencies [032cb66]
|
|
54
|
+
- Updated dependencies [703ac71]
|
|
55
|
+
- Updated dependencies [a723d69]
|
|
56
|
+
- Updated dependencies [7827943]
|
|
57
|
+
- Updated dependencies [5889a31]
|
|
58
|
+
- Updated dependencies [bf1e7e7]
|
|
59
|
+
- Updated dependencies [65e3395]
|
|
60
|
+
- Updated dependencies [4933192]
|
|
61
|
+
- Updated dependencies [d1c77a4]
|
|
62
|
+
- Updated dependencies [bea9dd1]
|
|
63
|
+
- Updated dependencies [dcd4802]
|
|
64
|
+
- Updated dependencies [cbddd18]
|
|
65
|
+
- Updated dependencies [7ba91fa]
|
|
66
|
+
- @mastra/core@0.11.0
|
|
67
|
+
|
|
68
|
+
## 0.11.5-alpha.0
|
|
69
|
+
|
|
70
|
+
### Patch Changes
|
|
71
|
+
|
|
72
|
+
- a723d69: Pass workflowId through
|
|
73
|
+
- Updated dependencies [f248d53]
|
|
74
|
+
- Updated dependencies [2affc57]
|
|
75
|
+
- Updated dependencies [66e13e3]
|
|
76
|
+
- Updated dependencies [edd9482]
|
|
77
|
+
- Updated dependencies [18344d7]
|
|
78
|
+
- Updated dependencies [9d372c2]
|
|
79
|
+
- Updated dependencies [40c2525]
|
|
80
|
+
- Updated dependencies [e473f27]
|
|
81
|
+
- Updated dependencies [032cb66]
|
|
82
|
+
- Updated dependencies [703ac71]
|
|
83
|
+
- Updated dependencies [a723d69]
|
|
84
|
+
- Updated dependencies [5889a31]
|
|
85
|
+
- Updated dependencies [65e3395]
|
|
86
|
+
- Updated dependencies [4933192]
|
|
87
|
+
- Updated dependencies [d1c77a4]
|
|
88
|
+
- Updated dependencies [bea9dd1]
|
|
89
|
+
- Updated dependencies [dcd4802]
|
|
90
|
+
- Updated dependencies [7ba91fa]
|
|
91
|
+
- @mastra/core@0.11.0-alpha.2
|
|
92
|
+
|
|
93
|
+
## 0.11.4
|
|
94
|
+
|
|
95
|
+
### Patch Changes
|
|
96
|
+
|
|
97
|
+
- 0b56518: Ensure removed runtimeContext values are not saved in snapshot
|
|
98
|
+
- Updated dependencies [0b56518]
|
|
99
|
+
- Updated dependencies [db5cc15]
|
|
100
|
+
- Updated dependencies [2ba5b76]
|
|
101
|
+
- Updated dependencies [5237998]
|
|
102
|
+
- Updated dependencies [c3a30de]
|
|
103
|
+
- Updated dependencies [37c1acd]
|
|
104
|
+
- Updated dependencies [1aa60b1]
|
|
105
|
+
- Updated dependencies [89ec9d4]
|
|
106
|
+
- Updated dependencies [cf3a184]
|
|
107
|
+
- Updated dependencies [d6bfd60]
|
|
108
|
+
- Updated dependencies [626b0f4]
|
|
109
|
+
- Updated dependencies [c22a91f]
|
|
110
|
+
- Updated dependencies [f7403ab]
|
|
111
|
+
- Updated dependencies [6c89d7f]
|
|
112
|
+
- @mastra/core@0.10.15
|
|
113
|
+
|
|
114
|
+
## 0.11.4-alpha.0
|
|
115
|
+
|
|
116
|
+
### Patch Changes
|
|
117
|
+
|
|
118
|
+
- 0b56518: Ensure removed runtimeContext values are not saved in snapshot
|
|
119
|
+
- Updated dependencies [0b56518]
|
|
120
|
+
- Updated dependencies [2ba5b76]
|
|
121
|
+
- Updated dependencies [c3a30de]
|
|
122
|
+
- Updated dependencies [cf3a184]
|
|
123
|
+
- Updated dependencies [d6bfd60]
|
|
124
|
+
- @mastra/core@0.10.15-alpha.1
|
|
14
125
|
|
|
15
126
|
## 0.11.3
|
|
16
127
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Agent } from '@mastra/core';
|
|
2
2
|
import type { BaseContext } from 'inngest';
|
|
3
|
+
import type { ChunkType } from '@mastra/core/workflows';
|
|
3
4
|
import { ClientOptions } from 'inngest';
|
|
4
5
|
import { DefaultExecutionEngine } from '@mastra/core/workflows';
|
|
5
6
|
import type { Emitter } from '@mastra/core/workflows';
|
|
@@ -94,7 +95,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
94
95
|
abortController: AbortController;
|
|
95
96
|
}): Promise<TOutput>;
|
|
96
97
|
protected fmtReturnValue<TOutput>(executionSpan: Span | undefined, emitter: Emitter, stepResults: Record<string, StepResult<any, any, any, any>>, lastOutput: StepResult<any, any, any, any>, error?: Error | string): Promise<TOutput>;
|
|
97
|
-
superExecuteStep({ workflowId, runId, step, stepResults, executionContext, resume, prevOutput, emitter, abortController, runtimeContext, }: {
|
|
98
|
+
superExecuteStep({ workflowId, runId, step, stepResults, executionContext, resume, prevOutput, emitter, abortController, runtimeContext, writableStream, }: {
|
|
98
99
|
workflowId: string;
|
|
99
100
|
runId: string;
|
|
100
101
|
step: Step<string, any, any>;
|
|
@@ -108,8 +109,9 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
108
109
|
emitter: Emitter;
|
|
109
110
|
abortController: AbortController;
|
|
110
111
|
runtimeContext: RuntimeContext;
|
|
112
|
+
writableStream?: WritableStream<ChunkType>;
|
|
111
113
|
}): Promise<StepResult<any, any, any, any>>;
|
|
112
|
-
executeSleep({ workflowId, runId, entry, prevOutput, stepResults, emitter, abortController, runtimeContext, }: {
|
|
114
|
+
executeSleep({ workflowId, runId, entry, prevOutput, stepResults, emitter, abortController, runtimeContext, writableStream, }: {
|
|
113
115
|
workflowId: string;
|
|
114
116
|
runId: string;
|
|
115
117
|
serializedStepGraph: SerializedStepFlowEntry[];
|
|
@@ -132,8 +134,9 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
132
134
|
emitter: Emitter;
|
|
133
135
|
abortController: AbortController;
|
|
134
136
|
runtimeContext: RuntimeContext;
|
|
137
|
+
writableStream?: WritableStream<ChunkType>;
|
|
135
138
|
}): Promise<void>;
|
|
136
|
-
executeSleepUntil({ workflowId, runId, entry, prevOutput, stepResults, emitter, abortController, runtimeContext, }: {
|
|
139
|
+
executeSleepUntil({ workflowId, runId, entry, prevOutput, stepResults, emitter, abortController, runtimeContext, writableStream, }: {
|
|
137
140
|
workflowId: string;
|
|
138
141
|
runId: string;
|
|
139
142
|
serializedStepGraph: SerializedStepFlowEntry[];
|
|
@@ -156,12 +159,13 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
156
159
|
emitter: Emitter;
|
|
157
160
|
abortController: AbortController;
|
|
158
161
|
runtimeContext: RuntimeContext;
|
|
162
|
+
writableStream?: WritableStream<ChunkType>;
|
|
159
163
|
}): Promise<void>;
|
|
160
164
|
executeWaitForEvent({ event, timeout }: {
|
|
161
165
|
event: string;
|
|
162
166
|
timeout?: number;
|
|
163
167
|
}): Promise<any>;
|
|
164
|
-
executeStep({ step, stepResults, executionContext, resume, prevOutput, emitter, abortController, runtimeContext, }: {
|
|
168
|
+
executeStep({ step, stepResults, executionContext, resume, prevOutput, emitter, abortController, runtimeContext, writableStream, }: {
|
|
165
169
|
step: Step<string, any, any>;
|
|
166
170
|
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
167
171
|
executionContext: ExecutionContext;
|
|
@@ -174,6 +178,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
174
178
|
emitter: Emitter;
|
|
175
179
|
abortController: AbortController;
|
|
176
180
|
runtimeContext: RuntimeContext;
|
|
181
|
+
writableStream?: WritableStream<ChunkType>;
|
|
177
182
|
}): Promise<StepResult<any, any, any, any>>;
|
|
178
183
|
persistStepUpdate({ workflowId, runId, stepResults, executionContext, serializedStepGraph, workflowStatus, result, error, }: {
|
|
179
184
|
workflowId: string;
|
|
@@ -184,8 +189,9 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
184
189
|
workflowStatus: 'success' | 'failed' | 'suspended' | 'running';
|
|
185
190
|
result?: Record<string, any>;
|
|
186
191
|
error?: string | Error;
|
|
192
|
+
runtimeContext: RuntimeContext;
|
|
187
193
|
}): Promise<void>;
|
|
188
|
-
executeConditional({ workflowId, runId, entry, prevOutput, prevStep, stepResults, serializedStepGraph, resume, executionContext, emitter, abortController, runtimeContext, }: {
|
|
194
|
+
executeConditional({ workflowId, runId, entry, prevOutput, prevStep, stepResults, serializedStepGraph, resume, executionContext, emitter, abortController, runtimeContext, writableStream, }: {
|
|
189
195
|
workflowId: string;
|
|
190
196
|
runId: string;
|
|
191
197
|
entry: {
|
|
@@ -207,6 +213,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
207
213
|
emitter: Emitter;
|
|
208
214
|
abortController: AbortController;
|
|
209
215
|
runtimeContext: RuntimeContext;
|
|
216
|
+
writableStream?: WritableStream<ChunkType>;
|
|
210
217
|
}): Promise<StepResult<any, any, any, any>>;
|
|
211
218
|
}
|
|
212
219
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Agent } from '@mastra/core';
|
|
2
2
|
import type { BaseContext } from 'inngest';
|
|
3
|
+
import type { ChunkType } from '@mastra/core/workflows';
|
|
3
4
|
import { ClientOptions } from 'inngest';
|
|
4
5
|
import { DefaultExecutionEngine } from '@mastra/core/workflows';
|
|
5
6
|
import type { Emitter } from '@mastra/core/workflows';
|
|
@@ -94,7 +95,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
94
95
|
abortController: AbortController;
|
|
95
96
|
}): Promise<TOutput>;
|
|
96
97
|
protected fmtReturnValue<TOutput>(executionSpan: Span | undefined, emitter: Emitter, stepResults: Record<string, StepResult<any, any, any, any>>, lastOutput: StepResult<any, any, any, any>, error?: Error | string): Promise<TOutput>;
|
|
97
|
-
superExecuteStep({ workflowId, runId, step, stepResults, executionContext, resume, prevOutput, emitter, abortController, runtimeContext, }: {
|
|
98
|
+
superExecuteStep({ workflowId, runId, step, stepResults, executionContext, resume, prevOutput, emitter, abortController, runtimeContext, writableStream, }: {
|
|
98
99
|
workflowId: string;
|
|
99
100
|
runId: string;
|
|
100
101
|
step: Step<string, any, any>;
|
|
@@ -108,8 +109,9 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
108
109
|
emitter: Emitter;
|
|
109
110
|
abortController: AbortController;
|
|
110
111
|
runtimeContext: RuntimeContext;
|
|
112
|
+
writableStream?: WritableStream<ChunkType>;
|
|
111
113
|
}): Promise<StepResult<any, any, any, any>>;
|
|
112
|
-
executeSleep({ workflowId, runId, entry, prevOutput, stepResults, emitter, abortController, runtimeContext, }: {
|
|
114
|
+
executeSleep({ workflowId, runId, entry, prevOutput, stepResults, emitter, abortController, runtimeContext, writableStream, }: {
|
|
113
115
|
workflowId: string;
|
|
114
116
|
runId: string;
|
|
115
117
|
serializedStepGraph: SerializedStepFlowEntry[];
|
|
@@ -132,8 +134,9 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
132
134
|
emitter: Emitter;
|
|
133
135
|
abortController: AbortController;
|
|
134
136
|
runtimeContext: RuntimeContext;
|
|
137
|
+
writableStream?: WritableStream<ChunkType>;
|
|
135
138
|
}): Promise<void>;
|
|
136
|
-
executeSleepUntil({ workflowId, runId, entry, prevOutput, stepResults, emitter, abortController, runtimeContext, }: {
|
|
139
|
+
executeSleepUntil({ workflowId, runId, entry, prevOutput, stepResults, emitter, abortController, runtimeContext, writableStream, }: {
|
|
137
140
|
workflowId: string;
|
|
138
141
|
runId: string;
|
|
139
142
|
serializedStepGraph: SerializedStepFlowEntry[];
|
|
@@ -156,12 +159,13 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
156
159
|
emitter: Emitter;
|
|
157
160
|
abortController: AbortController;
|
|
158
161
|
runtimeContext: RuntimeContext;
|
|
162
|
+
writableStream?: WritableStream<ChunkType>;
|
|
159
163
|
}): Promise<void>;
|
|
160
164
|
executeWaitForEvent({ event, timeout }: {
|
|
161
165
|
event: string;
|
|
162
166
|
timeout?: number;
|
|
163
167
|
}): Promise<any>;
|
|
164
|
-
executeStep({ step, stepResults, executionContext, resume, prevOutput, emitter, abortController, runtimeContext, }: {
|
|
168
|
+
executeStep({ step, stepResults, executionContext, resume, prevOutput, emitter, abortController, runtimeContext, writableStream, }: {
|
|
165
169
|
step: Step<string, any, any>;
|
|
166
170
|
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
167
171
|
executionContext: ExecutionContext;
|
|
@@ -174,6 +178,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
174
178
|
emitter: Emitter;
|
|
175
179
|
abortController: AbortController;
|
|
176
180
|
runtimeContext: RuntimeContext;
|
|
181
|
+
writableStream?: WritableStream<ChunkType>;
|
|
177
182
|
}): Promise<StepResult<any, any, any, any>>;
|
|
178
183
|
persistStepUpdate({ workflowId, runId, stepResults, executionContext, serializedStepGraph, workflowStatus, result, error, }: {
|
|
179
184
|
workflowId: string;
|
|
@@ -184,8 +189,9 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
184
189
|
workflowStatus: 'success' | 'failed' | 'suspended' | 'running';
|
|
185
190
|
result?: Record<string, any>;
|
|
186
191
|
error?: string | Error;
|
|
192
|
+
runtimeContext: RuntimeContext;
|
|
187
193
|
}): Promise<void>;
|
|
188
|
-
executeConditional({ workflowId, runId, entry, prevOutput, prevStep, stepResults, serializedStepGraph, resume, executionContext, emitter, abortController, runtimeContext, }: {
|
|
194
|
+
executeConditional({ workflowId, runId, entry, prevOutput, prevStep, stepResults, serializedStepGraph, resume, executionContext, emitter, abortController, runtimeContext, writableStream, }: {
|
|
189
195
|
workflowId: string;
|
|
190
196
|
runId: string;
|
|
191
197
|
entry: {
|
|
@@ -207,6 +213,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
207
213
|
emitter: Emitter;
|
|
208
214
|
abortController: AbortController;
|
|
209
215
|
runtimeContext: RuntimeContext;
|
|
216
|
+
writableStream?: WritableStream<ChunkType>;
|
|
210
217
|
}): Promise<StepResult<any, any, any, any>>;
|
|
211
218
|
}
|
|
212
219
|
|
package/dist/index.cjs
CHANGED
|
@@ -155,6 +155,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
155
155
|
data: {
|
|
156
156
|
inputData: params.resumeData,
|
|
157
157
|
runId: this.runId,
|
|
158
|
+
workflowId: this.workflowId,
|
|
158
159
|
stepResults: snapshot?.context,
|
|
159
160
|
resume: {
|
|
160
161
|
steps,
|
|
@@ -650,7 +651,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
650
651
|
prevOutput,
|
|
651
652
|
emitter,
|
|
652
653
|
abortController,
|
|
653
|
-
runtimeContext
|
|
654
|
+
runtimeContext,
|
|
655
|
+
writableStream
|
|
654
656
|
}) {
|
|
655
657
|
return super.executeStep({
|
|
656
658
|
workflowId,
|
|
@@ -662,7 +664,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
662
664
|
prevOutput,
|
|
663
665
|
emitter,
|
|
664
666
|
abortController,
|
|
665
|
-
runtimeContext
|
|
667
|
+
runtimeContext,
|
|
668
|
+
writableStream
|
|
666
669
|
});
|
|
667
670
|
}
|
|
668
671
|
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
@@ -676,13 +679,16 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
676
679
|
stepResults,
|
|
677
680
|
emitter,
|
|
678
681
|
abortController,
|
|
679
|
-
runtimeContext
|
|
682
|
+
runtimeContext,
|
|
683
|
+
writableStream
|
|
680
684
|
}) {
|
|
681
685
|
let { duration, fn } = entry;
|
|
682
686
|
if (fn) {
|
|
687
|
+
const stepCallId = crypto.randomUUID();
|
|
683
688
|
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
684
689
|
return await fn({
|
|
685
690
|
runId,
|
|
691
|
+
workflowId,
|
|
686
692
|
mastra: this.mastra,
|
|
687
693
|
runtimeContext,
|
|
688
694
|
inputData: prevOutput,
|
|
@@ -708,7 +714,16 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
708
714
|
},
|
|
709
715
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
710
716
|
engine: { step: this.inngestStep },
|
|
711
|
-
abortSignal: abortController?.signal
|
|
717
|
+
abortSignal: abortController?.signal,
|
|
718
|
+
writer: new tools.ToolStream(
|
|
719
|
+
{
|
|
720
|
+
prefix: "step",
|
|
721
|
+
callId: stepCallId,
|
|
722
|
+
name: "sleep",
|
|
723
|
+
runId
|
|
724
|
+
},
|
|
725
|
+
writableStream
|
|
726
|
+
)
|
|
712
727
|
});
|
|
713
728
|
});
|
|
714
729
|
}
|
|
@@ -722,13 +737,16 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
722
737
|
stepResults,
|
|
723
738
|
emitter,
|
|
724
739
|
abortController,
|
|
725
|
-
runtimeContext
|
|
740
|
+
runtimeContext,
|
|
741
|
+
writableStream
|
|
726
742
|
}) {
|
|
727
743
|
let { date, fn } = entry;
|
|
728
744
|
if (fn) {
|
|
729
745
|
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
746
|
+
const stepCallId = crypto.randomUUID();
|
|
730
747
|
return await fn({
|
|
731
748
|
runId,
|
|
749
|
+
workflowId,
|
|
732
750
|
mastra: this.mastra,
|
|
733
751
|
runtimeContext,
|
|
734
752
|
inputData: prevOutput,
|
|
@@ -754,7 +772,16 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
754
772
|
},
|
|
755
773
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
756
774
|
engine: { step: this.inngestStep },
|
|
757
|
-
abortSignal: abortController?.signal
|
|
775
|
+
abortSignal: abortController?.signal,
|
|
776
|
+
writer: new tools.ToolStream(
|
|
777
|
+
{
|
|
778
|
+
prefix: "step",
|
|
779
|
+
callId: stepCallId,
|
|
780
|
+
name: "sleep",
|
|
781
|
+
runId
|
|
782
|
+
},
|
|
783
|
+
writableStream
|
|
784
|
+
)
|
|
758
785
|
});
|
|
759
786
|
});
|
|
760
787
|
}
|
|
@@ -781,7 +808,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
781
808
|
prevOutput,
|
|
782
809
|
emitter,
|
|
783
810
|
abortController,
|
|
784
|
-
runtimeContext
|
|
811
|
+
runtimeContext,
|
|
812
|
+
writableStream
|
|
785
813
|
}) {
|
|
786
814
|
const startedAt = await this.inngestStep.run(
|
|
787
815
|
`workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
|
|
@@ -1000,6 +1028,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1000
1028
|
runId: executionContext.runId,
|
|
1001
1029
|
mastra: this.mastra,
|
|
1002
1030
|
runtimeContext,
|
|
1031
|
+
writableStream,
|
|
1003
1032
|
inputData: prevOutput,
|
|
1004
1033
|
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1005
1034
|
getInitData: () => stepResults?.input,
|
|
@@ -1159,7 +1188,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1159
1188
|
executionContext,
|
|
1160
1189
|
emitter,
|
|
1161
1190
|
abortController,
|
|
1162
|
-
runtimeContext
|
|
1191
|
+
runtimeContext,
|
|
1192
|
+
writableStream
|
|
1163
1193
|
}) {
|
|
1164
1194
|
let execResults;
|
|
1165
1195
|
const truthyIndexes = (await Promise.all(
|
|
@@ -1168,6 +1198,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1168
1198
|
try {
|
|
1169
1199
|
const result = await cond({
|
|
1170
1200
|
runId,
|
|
1201
|
+
workflowId,
|
|
1171
1202
|
mastra: this.mastra,
|
|
1172
1203
|
runtimeContext,
|
|
1173
1204
|
runCount: -1,
|
|
@@ -1195,7 +1226,16 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1195
1226
|
engine: {
|
|
1196
1227
|
step: this.inngestStep
|
|
1197
1228
|
},
|
|
1198
|
-
abortSignal: abortController.signal
|
|
1229
|
+
abortSignal: abortController.signal,
|
|
1230
|
+
writer: new tools.ToolStream(
|
|
1231
|
+
{
|
|
1232
|
+
prefix: "step",
|
|
1233
|
+
callId: crypto.randomUUID(),
|
|
1234
|
+
name: "conditional",
|
|
1235
|
+
runId
|
|
1236
|
+
},
|
|
1237
|
+
writableStream
|
|
1238
|
+
)
|
|
1199
1239
|
});
|
|
1200
1240
|
return result ? index : null;
|
|
1201
1241
|
} catch (e) {
|
|
@@ -1225,7 +1265,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1225
1265
|
},
|
|
1226
1266
|
emitter,
|
|
1227
1267
|
abortController,
|
|
1228
|
-
runtimeContext
|
|
1268
|
+
runtimeContext,
|
|
1269
|
+
writableStream
|
|
1229
1270
|
})
|
|
1230
1271
|
)
|
|
1231
1272
|
);
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
2
|
import { subscribe } from '@inngest/realtime';
|
|
3
3
|
import { RuntimeContext } from '@mastra/core/di';
|
|
4
|
-
import { Tool } from '@mastra/core/tools';
|
|
4
|
+
import { ToolStream, Tool } from '@mastra/core/tools';
|
|
5
5
|
import { Run, Workflow, DefaultExecutionEngine } from '@mastra/core/workflows';
|
|
6
6
|
import { EMITTER_SYMBOL } from '@mastra/core/workflows/_constants';
|
|
7
7
|
import { serve as serve$1 } from 'inngest/hono';
|
|
@@ -153,6 +153,7 @@ var InngestRun = class extends Run {
|
|
|
153
153
|
data: {
|
|
154
154
|
inputData: params.resumeData,
|
|
155
155
|
runId: this.runId,
|
|
156
|
+
workflowId: this.workflowId,
|
|
156
157
|
stepResults: snapshot?.context,
|
|
157
158
|
resume: {
|
|
158
159
|
steps,
|
|
@@ -648,7 +649,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
648
649
|
prevOutput,
|
|
649
650
|
emitter,
|
|
650
651
|
abortController,
|
|
651
|
-
runtimeContext
|
|
652
|
+
runtimeContext,
|
|
653
|
+
writableStream
|
|
652
654
|
}) {
|
|
653
655
|
return super.executeStep({
|
|
654
656
|
workflowId,
|
|
@@ -660,7 +662,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
660
662
|
prevOutput,
|
|
661
663
|
emitter,
|
|
662
664
|
abortController,
|
|
663
|
-
runtimeContext
|
|
665
|
+
runtimeContext,
|
|
666
|
+
writableStream
|
|
664
667
|
});
|
|
665
668
|
}
|
|
666
669
|
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
@@ -674,13 +677,16 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
674
677
|
stepResults,
|
|
675
678
|
emitter,
|
|
676
679
|
abortController,
|
|
677
|
-
runtimeContext
|
|
680
|
+
runtimeContext,
|
|
681
|
+
writableStream
|
|
678
682
|
}) {
|
|
679
683
|
let { duration, fn } = entry;
|
|
680
684
|
if (fn) {
|
|
685
|
+
const stepCallId = randomUUID();
|
|
681
686
|
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
682
687
|
return await fn({
|
|
683
688
|
runId,
|
|
689
|
+
workflowId,
|
|
684
690
|
mastra: this.mastra,
|
|
685
691
|
runtimeContext,
|
|
686
692
|
inputData: prevOutput,
|
|
@@ -706,7 +712,16 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
706
712
|
},
|
|
707
713
|
[EMITTER_SYMBOL]: emitter,
|
|
708
714
|
engine: { step: this.inngestStep },
|
|
709
|
-
abortSignal: abortController?.signal
|
|
715
|
+
abortSignal: abortController?.signal,
|
|
716
|
+
writer: new ToolStream(
|
|
717
|
+
{
|
|
718
|
+
prefix: "step",
|
|
719
|
+
callId: stepCallId,
|
|
720
|
+
name: "sleep",
|
|
721
|
+
runId
|
|
722
|
+
},
|
|
723
|
+
writableStream
|
|
724
|
+
)
|
|
710
725
|
});
|
|
711
726
|
});
|
|
712
727
|
}
|
|
@@ -720,13 +735,16 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
720
735
|
stepResults,
|
|
721
736
|
emitter,
|
|
722
737
|
abortController,
|
|
723
|
-
runtimeContext
|
|
738
|
+
runtimeContext,
|
|
739
|
+
writableStream
|
|
724
740
|
}) {
|
|
725
741
|
let { date, fn } = entry;
|
|
726
742
|
if (fn) {
|
|
727
743
|
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
744
|
+
const stepCallId = randomUUID();
|
|
728
745
|
return await fn({
|
|
729
746
|
runId,
|
|
747
|
+
workflowId,
|
|
730
748
|
mastra: this.mastra,
|
|
731
749
|
runtimeContext,
|
|
732
750
|
inputData: prevOutput,
|
|
@@ -752,7 +770,16 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
752
770
|
},
|
|
753
771
|
[EMITTER_SYMBOL]: emitter,
|
|
754
772
|
engine: { step: this.inngestStep },
|
|
755
|
-
abortSignal: abortController?.signal
|
|
773
|
+
abortSignal: abortController?.signal,
|
|
774
|
+
writer: new ToolStream(
|
|
775
|
+
{
|
|
776
|
+
prefix: "step",
|
|
777
|
+
callId: stepCallId,
|
|
778
|
+
name: "sleep",
|
|
779
|
+
runId
|
|
780
|
+
},
|
|
781
|
+
writableStream
|
|
782
|
+
)
|
|
756
783
|
});
|
|
757
784
|
});
|
|
758
785
|
}
|
|
@@ -779,7 +806,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
779
806
|
prevOutput,
|
|
780
807
|
emitter,
|
|
781
808
|
abortController,
|
|
782
|
-
runtimeContext
|
|
809
|
+
runtimeContext,
|
|
810
|
+
writableStream
|
|
783
811
|
}) {
|
|
784
812
|
const startedAt = await this.inngestStep.run(
|
|
785
813
|
`workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
|
|
@@ -998,6 +1026,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
998
1026
|
runId: executionContext.runId,
|
|
999
1027
|
mastra: this.mastra,
|
|
1000
1028
|
runtimeContext,
|
|
1029
|
+
writableStream,
|
|
1001
1030
|
inputData: prevOutput,
|
|
1002
1031
|
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1003
1032
|
getInitData: () => stepResults?.input,
|
|
@@ -1157,7 +1186,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1157
1186
|
executionContext,
|
|
1158
1187
|
emitter,
|
|
1159
1188
|
abortController,
|
|
1160
|
-
runtimeContext
|
|
1189
|
+
runtimeContext,
|
|
1190
|
+
writableStream
|
|
1161
1191
|
}) {
|
|
1162
1192
|
let execResults;
|
|
1163
1193
|
const truthyIndexes = (await Promise.all(
|
|
@@ -1166,6 +1196,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1166
1196
|
try {
|
|
1167
1197
|
const result = await cond({
|
|
1168
1198
|
runId,
|
|
1199
|
+
workflowId,
|
|
1169
1200
|
mastra: this.mastra,
|
|
1170
1201
|
runtimeContext,
|
|
1171
1202
|
runCount: -1,
|
|
@@ -1193,7 +1224,16 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1193
1224
|
engine: {
|
|
1194
1225
|
step: this.inngestStep
|
|
1195
1226
|
},
|
|
1196
|
-
abortSignal: abortController.signal
|
|
1227
|
+
abortSignal: abortController.signal,
|
|
1228
|
+
writer: new ToolStream(
|
|
1229
|
+
{
|
|
1230
|
+
prefix: "step",
|
|
1231
|
+
callId: randomUUID(),
|
|
1232
|
+
name: "conditional",
|
|
1233
|
+
runId
|
|
1234
|
+
},
|
|
1235
|
+
writableStream
|
|
1236
|
+
)
|
|
1197
1237
|
});
|
|
1198
1238
|
return result ? index : null;
|
|
1199
1239
|
} catch (e) {
|
|
@@ -1223,7 +1263,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1223
1263
|
},
|
|
1224
1264
|
emitter,
|
|
1225
1265
|
abortController,
|
|
1226
|
-
runtimeContext
|
|
1266
|
+
runtimeContext,
|
|
1267
|
+
writableStream
|
|
1227
1268
|
})
|
|
1228
1269
|
)
|
|
1229
1270
|
);
|
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-ai-v5-
|
|
3
|
+
"version": "0.0.0-ai-v5-20250729012312",
|
|
4
4
|
"description": "Mastra Inngest integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,24 +27,24 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"inngest-cli": "1.8.2",
|
|
29
29
|
"@ai-sdk/openai": "2.0.0-beta.6",
|
|
30
|
-
"@hono/node-server": "^1.
|
|
30
|
+
"@hono/node-server": "^1.17.1",
|
|
31
31
|
"@microsoft/api-extractor": "^7.52.8",
|
|
32
32
|
"@types/node": "^20.19.0",
|
|
33
33
|
"ai": "5.0.0-beta.14",
|
|
34
|
-
"eslint": "^9.
|
|
34
|
+
"eslint": "^9.30.1",
|
|
35
35
|
"execa": "^9.6.0",
|
|
36
36
|
"get-port": "7.1.0",
|
|
37
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-ai-v5-
|
|
42
|
-
"@mastra/
|
|
43
|
-
"@mastra/
|
|
44
|
-
"@mastra/
|
|
41
|
+
"@internal/lint": "0.0.0-ai-v5-20250729012312",
|
|
42
|
+
"@mastra/core": "0.0.0-ai-v5-20250729012312",
|
|
43
|
+
"@mastra/deployer": "0.0.0-ai-v5-20250729012312",
|
|
44
|
+
"@mastra/libsql": "0.0.0-ai-v5-20250729012312"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@mastra/core": "0.0.0-ai-v5-
|
|
47
|
+
"@mastra/core": "0.0.0-ai-v5-20250729012312"
|
|
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
|
@@ -9,7 +9,7 @@ import { Agent } from '@mastra/core/agent';
|
|
|
9
9
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
10
10
|
import { createHonoServer } from '@mastra/deployer/server';
|
|
11
11
|
import { DefaultStorage } from '@mastra/libsql';
|
|
12
|
-
import {
|
|
12
|
+
import { MockLanguageModelV2, simulateReadableStream } from 'ai/test';
|
|
13
13
|
import { $ } from 'execa';
|
|
14
14
|
import { Inngest } from 'inngest';
|
|
15
15
|
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
@@ -4258,6 +4258,124 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4258
4258
|
|
|
4259
4259
|
expect(promptAgentAction).toHaveBeenCalledTimes(2);
|
|
4260
4260
|
});
|
|
4261
|
+
|
|
4262
|
+
it('should handle consecutive nested workflows with suspend/resume', async ctx => {
|
|
4263
|
+
const inngest = new Inngest({
|
|
4264
|
+
id: 'mastra',
|
|
4265
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
4266
|
+
middleware: [realtimeMiddleware()],
|
|
4267
|
+
});
|
|
4268
|
+
|
|
4269
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
4270
|
+
|
|
4271
|
+
const step1 = vi.fn().mockImplementation(async ({ resumeData, suspend }) => {
|
|
4272
|
+
if (!resumeData?.suspect) {
|
|
4273
|
+
return await suspend({ message: 'What is the suspect?' });
|
|
4274
|
+
}
|
|
4275
|
+
return { suspect: resumeData.suspect };
|
|
4276
|
+
});
|
|
4277
|
+
const step1Definition = createStep({
|
|
4278
|
+
id: 'step-1',
|
|
4279
|
+
inputSchema: z.object({ suspect: z.string() }),
|
|
4280
|
+
outputSchema: z.object({ suspect: z.string() }),
|
|
4281
|
+
suspendSchema: z.object({ message: z.string() }),
|
|
4282
|
+
resumeSchema: z.object({ suspect: z.string() }),
|
|
4283
|
+
execute: step1,
|
|
4284
|
+
});
|
|
4285
|
+
|
|
4286
|
+
const step2 = vi.fn().mockImplementation(async ({ resumeData, suspend }) => {
|
|
4287
|
+
if (!resumeData?.suspect) {
|
|
4288
|
+
return await suspend({ message: 'What is the second suspect?' });
|
|
4289
|
+
}
|
|
4290
|
+
return { suspect: resumeData.suspect };
|
|
4291
|
+
});
|
|
4292
|
+
const step2Definition = createStep({
|
|
4293
|
+
id: 'step-2',
|
|
4294
|
+
inputSchema: z.object({ suspect: z.string() }),
|
|
4295
|
+
outputSchema: z.object({ suspect: z.string() }),
|
|
4296
|
+
suspendSchema: z.object({ message: z.string() }),
|
|
4297
|
+
resumeSchema: z.object({ suspect: z.string() }),
|
|
4298
|
+
execute: step2,
|
|
4299
|
+
});
|
|
4300
|
+
|
|
4301
|
+
const subWorkflow1 = createWorkflow({
|
|
4302
|
+
id: 'sub-workflow-1',
|
|
4303
|
+
inputSchema: z.object({ suspect: z.string() }),
|
|
4304
|
+
outputSchema: z.object({ suspect: z.string() }),
|
|
4305
|
+
})
|
|
4306
|
+
.then(step1Definition)
|
|
4307
|
+
.commit();
|
|
4308
|
+
|
|
4309
|
+
const subWorkflow2 = createWorkflow({
|
|
4310
|
+
id: 'sub-workflow-2',
|
|
4311
|
+
inputSchema: z.object({ suspect: z.string() }),
|
|
4312
|
+
outputSchema: z.object({ suspect: z.string() }),
|
|
4313
|
+
})
|
|
4314
|
+
.then(step2Definition)
|
|
4315
|
+
.commit();
|
|
4316
|
+
|
|
4317
|
+
const mainWorkflow = createWorkflow({
|
|
4318
|
+
id: 'main-workflow',
|
|
4319
|
+
inputSchema: z.object({ suspect: z.string() }),
|
|
4320
|
+
outputSchema: z.object({ suspect: z.string() }),
|
|
4321
|
+
})
|
|
4322
|
+
.then(subWorkflow1)
|
|
4323
|
+
.then(subWorkflow2)
|
|
4324
|
+
.commit();
|
|
4325
|
+
|
|
4326
|
+
const mastra = new Mastra({
|
|
4327
|
+
logger: false,
|
|
4328
|
+
storage: new DefaultStorage({
|
|
4329
|
+
url: ':memory:',
|
|
4330
|
+
}),
|
|
4331
|
+
workflows: { mainWorkflow },
|
|
4332
|
+
server: {
|
|
4333
|
+
apiRoutes: [
|
|
4334
|
+
{
|
|
4335
|
+
path: '/inngest/api',
|
|
4336
|
+
method: 'ALL',
|
|
4337
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
4338
|
+
},
|
|
4339
|
+
],
|
|
4340
|
+
},
|
|
4341
|
+
});
|
|
4342
|
+
|
|
4343
|
+
const app = await createHonoServer(mastra);
|
|
4344
|
+
|
|
4345
|
+
const srv = (globServer = serve({
|
|
4346
|
+
fetch: app.fetch,
|
|
4347
|
+
port: (ctx as any).handlerPort,
|
|
4348
|
+
}));
|
|
4349
|
+
await resetInngest();
|
|
4350
|
+
|
|
4351
|
+
const run = await mainWorkflow.createRunAsync();
|
|
4352
|
+
|
|
4353
|
+
const initialResult = await run.start({ inputData: { suspect: 'initial-suspect' } });
|
|
4354
|
+
expect(initialResult.status).toBe('suspended');
|
|
4355
|
+
|
|
4356
|
+
const firstResumeResult = await run.resume({
|
|
4357
|
+
step: ['sub-workflow-1', 'step-1'],
|
|
4358
|
+
resumeData: { suspect: 'first-suspect' },
|
|
4359
|
+
});
|
|
4360
|
+
expect(firstResumeResult.status).toBe('suspended');
|
|
4361
|
+
|
|
4362
|
+
const secondResumeResult = await run.resume({
|
|
4363
|
+
step: ['sub-workflow-2', 'step-2'],
|
|
4364
|
+
resumeData: { suspect: 'second-suspect' },
|
|
4365
|
+
});
|
|
4366
|
+
|
|
4367
|
+
expect(step1).toHaveBeenCalledTimes(2);
|
|
4368
|
+
expect(step2).toHaveBeenCalledTimes(2);
|
|
4369
|
+
expect(secondResumeResult.status).toBe('success');
|
|
4370
|
+
expect(secondResumeResult.steps['sub-workflow-1']).toMatchObject({
|
|
4371
|
+
status: 'success',
|
|
4372
|
+
});
|
|
4373
|
+
expect(secondResumeResult.steps['sub-workflow-2']).toMatchObject({
|
|
4374
|
+
status: 'success',
|
|
4375
|
+
});
|
|
4376
|
+
|
|
4377
|
+
srv.close();
|
|
4378
|
+
});
|
|
4261
4379
|
});
|
|
4262
4380
|
|
|
4263
4381
|
describe('Accessing Mastra', () => {
|
|
@@ -6219,6 +6337,176 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6219
6337
|
// @ts-ignore
|
|
6220
6338
|
expect(result?.steps.step1.output.injectedValue).toBe(testValue + '2');
|
|
6221
6339
|
});
|
|
6340
|
+
|
|
6341
|
+
it('should have access to runtimeContext from before suspension during workflow resume', async ctx => {
|
|
6342
|
+
const inngest = new Inngest({
|
|
6343
|
+
id: 'mastra',
|
|
6344
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
6345
|
+
});
|
|
6346
|
+
|
|
6347
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
6348
|
+
|
|
6349
|
+
const testValue = 'test-dependency';
|
|
6350
|
+
const resumeStep = createStep({
|
|
6351
|
+
id: 'resume',
|
|
6352
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6353
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6354
|
+
resumeSchema: z.object({ value: z.number() }),
|
|
6355
|
+
suspendSchema: z.object({ message: z.string() }),
|
|
6356
|
+
execute: async ({ inputData, resumeData, suspend }) => {
|
|
6357
|
+
const finalValue = (resumeData?.value ?? 0) + inputData.value;
|
|
6358
|
+
|
|
6359
|
+
if (!resumeData?.value || finalValue < 10) {
|
|
6360
|
+
return await suspend({
|
|
6361
|
+
message: `Please provide additional information. now value is ${inputData.value}`,
|
|
6362
|
+
});
|
|
6363
|
+
}
|
|
6364
|
+
|
|
6365
|
+
return { value: finalValue };
|
|
6366
|
+
},
|
|
6367
|
+
});
|
|
6368
|
+
|
|
6369
|
+
const incrementStep = createStep({
|
|
6370
|
+
id: 'increment',
|
|
6371
|
+
inputSchema: z.object({
|
|
6372
|
+
value: z.number(),
|
|
6373
|
+
}),
|
|
6374
|
+
outputSchema: z.object({
|
|
6375
|
+
value: z.number(),
|
|
6376
|
+
}),
|
|
6377
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
6378
|
+
runtimeContext.set('testKey', testValue);
|
|
6379
|
+
return {
|
|
6380
|
+
value: inputData.value + 1,
|
|
6381
|
+
};
|
|
6382
|
+
},
|
|
6383
|
+
});
|
|
6384
|
+
|
|
6385
|
+
const incrementWorkflow = createWorkflow({
|
|
6386
|
+
id: 'increment-workflow',
|
|
6387
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6388
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6389
|
+
})
|
|
6390
|
+
.then(incrementStep)
|
|
6391
|
+
.then(resumeStep)
|
|
6392
|
+
.then(
|
|
6393
|
+
createStep({
|
|
6394
|
+
id: 'final',
|
|
6395
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6396
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6397
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
6398
|
+
const testKey = runtimeContext.get('testKey');
|
|
6399
|
+
expect(testKey).toBe(testValue);
|
|
6400
|
+
return { value: inputData.value };
|
|
6401
|
+
},
|
|
6402
|
+
}),
|
|
6403
|
+
)
|
|
6404
|
+
.commit();
|
|
6405
|
+
|
|
6406
|
+
new Mastra({
|
|
6407
|
+
logger: false,
|
|
6408
|
+
storage: testStorage,
|
|
6409
|
+
workflows: { incrementWorkflow },
|
|
6410
|
+
});
|
|
6411
|
+
|
|
6412
|
+
const run = await incrementWorkflow.createRunAsync();
|
|
6413
|
+
const result = await run.start({ inputData: { value: 0 } });
|
|
6414
|
+
expect(result.status).toBe('suspended');
|
|
6415
|
+
|
|
6416
|
+
const resumeResult = await run.resume({
|
|
6417
|
+
resumeData: { value: 21 },
|
|
6418
|
+
step: ['resume'],
|
|
6419
|
+
});
|
|
6420
|
+
|
|
6421
|
+
expect(resumeResult.status).toBe('success');
|
|
6422
|
+
});
|
|
6423
|
+
|
|
6424
|
+
it('should not show removed runtimeContext values in subsequent steps', async ctx => {
|
|
6425
|
+
const inngest = new Inngest({
|
|
6426
|
+
id: 'mastra',
|
|
6427
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
6428
|
+
});
|
|
6429
|
+
|
|
6430
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
6431
|
+
const testValue = 'test-dependency';
|
|
6432
|
+
const resumeStep = createStep({
|
|
6433
|
+
id: 'resume',
|
|
6434
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6435
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6436
|
+
resumeSchema: z.object({ value: z.number() }),
|
|
6437
|
+
suspendSchema: z.object({ message: z.string() }),
|
|
6438
|
+
execute: async ({ inputData, resumeData, suspend, runtimeContext }) => {
|
|
6439
|
+
const finalValue = (resumeData?.value ?? 0) + inputData.value;
|
|
6440
|
+
|
|
6441
|
+
if (!resumeData?.value || finalValue < 10) {
|
|
6442
|
+
return await suspend({
|
|
6443
|
+
message: `Please provide additional information. now value is ${inputData.value}`,
|
|
6444
|
+
});
|
|
6445
|
+
}
|
|
6446
|
+
|
|
6447
|
+
const testKey = runtimeContext.get('testKey');
|
|
6448
|
+
expect(testKey).toBe(testValue);
|
|
6449
|
+
|
|
6450
|
+
runtimeContext.delete('testKey');
|
|
6451
|
+
|
|
6452
|
+
return { value: finalValue };
|
|
6453
|
+
},
|
|
6454
|
+
});
|
|
6455
|
+
|
|
6456
|
+
const incrementStep = createStep({
|
|
6457
|
+
id: 'increment',
|
|
6458
|
+
inputSchema: z.object({
|
|
6459
|
+
value: z.number(),
|
|
6460
|
+
}),
|
|
6461
|
+
outputSchema: z.object({
|
|
6462
|
+
value: z.number(),
|
|
6463
|
+
}),
|
|
6464
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
6465
|
+
runtimeContext.set('testKey', testValue);
|
|
6466
|
+
return {
|
|
6467
|
+
value: inputData.value + 1,
|
|
6468
|
+
};
|
|
6469
|
+
},
|
|
6470
|
+
});
|
|
6471
|
+
|
|
6472
|
+
const incrementWorkflow = createWorkflow({
|
|
6473
|
+
id: 'increment-workflow',
|
|
6474
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6475
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6476
|
+
})
|
|
6477
|
+
.then(incrementStep)
|
|
6478
|
+
.then(resumeStep)
|
|
6479
|
+
.then(
|
|
6480
|
+
createStep({
|
|
6481
|
+
id: 'final',
|
|
6482
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6483
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6484
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
6485
|
+
const testKey = runtimeContext.get('testKey');
|
|
6486
|
+
expect(testKey).toBeUndefined();
|
|
6487
|
+
return { value: inputData.value };
|
|
6488
|
+
},
|
|
6489
|
+
}),
|
|
6490
|
+
)
|
|
6491
|
+
.commit();
|
|
6492
|
+
|
|
6493
|
+
new Mastra({
|
|
6494
|
+
logger: false,
|
|
6495
|
+
storage: testStorage,
|
|
6496
|
+
workflows: { incrementWorkflow },
|
|
6497
|
+
});
|
|
6498
|
+
|
|
6499
|
+
const run = await incrementWorkflow.createRunAsync();
|
|
6500
|
+
const result = await run.start({ inputData: { value: 0 } });
|
|
6501
|
+
expect(result.status).toBe('suspended');
|
|
6502
|
+
|
|
6503
|
+
const resumeResult = await run.resume({
|
|
6504
|
+
resumeData: { value: 21 },
|
|
6505
|
+
step: ['resume'],
|
|
6506
|
+
});
|
|
6507
|
+
|
|
6508
|
+
expect(resumeResult.status).toBe('success');
|
|
6509
|
+
});
|
|
6222
6510
|
});
|
|
6223
6511
|
|
|
6224
6512
|
describe('Access to inngest step primitives', () => {
|
|
@@ -7243,20 +7531,26 @@ describe('MastraInngestWorkflow', () => {
|
|
|
7243
7531
|
const agent = new Agent({
|
|
7244
7532
|
name: 'test-agent-1',
|
|
7245
7533
|
instructions: 'test agent instructions"',
|
|
7246
|
-
model: new
|
|
7534
|
+
model: new MockLanguageModelV2({
|
|
7247
7535
|
doStream: async () => ({
|
|
7248
7536
|
stream: simulateReadableStream({
|
|
7249
7537
|
chunks: [
|
|
7250
|
-
{ type: 'text-
|
|
7538
|
+
{ type: 'text-start', id: 'text-1' },
|
|
7539
|
+
{ type: 'text-delta', id: 'text-1', delta: 'Paris' },
|
|
7540
|
+
{ type: 'text-end', id: 'text-1' },
|
|
7251
7541
|
{
|
|
7252
7542
|
type: 'finish',
|
|
7253
7543
|
finishReason: 'stop',
|
|
7254
|
-
|
|
7255
|
-
|
|
7544
|
+
usage: {
|
|
7545
|
+
completionTokens: 10,
|
|
7546
|
+
promptTokens: 3,
|
|
7547
|
+
inputTokens: 3,
|
|
7548
|
+
outputTokens: 10,
|
|
7549
|
+
totalTokens: 13,
|
|
7550
|
+
},
|
|
7256
7551
|
},
|
|
7257
7552
|
],
|
|
7258
7553
|
}),
|
|
7259
|
-
rawCall: { rawPrompt: null, rawSettings: {} },
|
|
7260
7554
|
}),
|
|
7261
7555
|
}),
|
|
7262
7556
|
});
|
|
@@ -7264,20 +7558,26 @@ describe('MastraInngestWorkflow', () => {
|
|
|
7264
7558
|
const agent2 = new Agent({
|
|
7265
7559
|
name: 'test-agent-2',
|
|
7266
7560
|
instructions: 'test agent instructions',
|
|
7267
|
-
model: new
|
|
7561
|
+
model: new MockLanguageModelV2({
|
|
7268
7562
|
doStream: async () => ({
|
|
7269
7563
|
stream: simulateReadableStream({
|
|
7270
7564
|
chunks: [
|
|
7271
|
-
{ type: 'text-
|
|
7565
|
+
{ type: 'text-start', id: 'text-1' },
|
|
7566
|
+
{ type: 'text-delta', id: 'text-1', delta: 'London' },
|
|
7567
|
+
{ type: 'text-end', id: 'text-1' },
|
|
7272
7568
|
{
|
|
7273
7569
|
type: 'finish',
|
|
7274
7570
|
finishReason: 'stop',
|
|
7275
|
-
|
|
7276
|
-
|
|
7571
|
+
usage: {
|
|
7572
|
+
completionTokens: 10,
|
|
7573
|
+
promptTokens: 3,
|
|
7574
|
+
inputTokens: 3,
|
|
7575
|
+
outputTokens: 10,
|
|
7576
|
+
totalTokens: 13,
|
|
7577
|
+
},
|
|
7277
7578
|
},
|
|
7278
7579
|
],
|
|
7279
7580
|
}),
|
|
7280
|
-
rawCall: { rawPrompt: null, rawSettings: {} },
|
|
7281
7581
|
}),
|
|
7282
7582
|
}),
|
|
7283
7583
|
});
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { ReadableStream } from 'node:stream/web';
|
|
|
3
3
|
import { subscribe } from '@inngest/realtime';
|
|
4
4
|
import type { Agent, Mastra, ToolExecutionContext, WorkflowRun, WorkflowRuns } from '@mastra/core';
|
|
5
5
|
import { RuntimeContext } from '@mastra/core/di';
|
|
6
|
-
import { Tool } from '@mastra/core/tools';
|
|
6
|
+
import { Tool, ToolStream } from '@mastra/core/tools';
|
|
7
7
|
import { Workflow, Run, DefaultExecutionEngine } from '@mastra/core/workflows';
|
|
8
8
|
import type {
|
|
9
9
|
ExecuteFunction,
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
Emitter,
|
|
21
21
|
WatchEvent,
|
|
22
22
|
StreamEvent,
|
|
23
|
+
ChunkType,
|
|
23
24
|
} from '@mastra/core/workflows';
|
|
24
25
|
import { EMITTER_SYMBOL } from '@mastra/core/workflows/_constants';
|
|
25
26
|
import type { Span } from '@opentelemetry/api';
|
|
@@ -231,6 +232,7 @@ export class InngestRun<
|
|
|
231
232
|
data: {
|
|
232
233
|
inputData: params.resumeData,
|
|
233
234
|
runId: this.runId,
|
|
235
|
+
workflowId: this.workflowId,
|
|
234
236
|
stepResults: snapshot?.context as any,
|
|
235
237
|
resume: {
|
|
236
238
|
steps,
|
|
@@ -968,6 +970,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
968
970
|
emitter,
|
|
969
971
|
abortController,
|
|
970
972
|
runtimeContext,
|
|
973
|
+
writableStream,
|
|
971
974
|
}: {
|
|
972
975
|
workflowId: string;
|
|
973
976
|
runId: string;
|
|
@@ -982,6 +985,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
982
985
|
emitter: Emitter;
|
|
983
986
|
abortController: AbortController;
|
|
984
987
|
runtimeContext: RuntimeContext;
|
|
988
|
+
writableStream?: WritableStream<ChunkType>;
|
|
985
989
|
}): Promise<StepResult<any, any, any, any>> {
|
|
986
990
|
return super.executeStep({
|
|
987
991
|
workflowId,
|
|
@@ -994,6 +998,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
994
998
|
emitter,
|
|
995
999
|
abortController,
|
|
996
1000
|
runtimeContext,
|
|
1001
|
+
writableStream,
|
|
997
1002
|
});
|
|
998
1003
|
}
|
|
999
1004
|
|
|
@@ -1010,6 +1015,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1010
1015
|
emitter,
|
|
1011
1016
|
abortController,
|
|
1012
1017
|
runtimeContext,
|
|
1018
|
+
writableStream,
|
|
1013
1019
|
}: {
|
|
1014
1020
|
workflowId: string;
|
|
1015
1021
|
runId: string;
|
|
@@ -1033,13 +1039,16 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1033
1039
|
emitter: Emitter;
|
|
1034
1040
|
abortController: AbortController;
|
|
1035
1041
|
runtimeContext: RuntimeContext;
|
|
1042
|
+
writableStream?: WritableStream<ChunkType>;
|
|
1036
1043
|
}): Promise<void> {
|
|
1037
1044
|
let { duration, fn } = entry;
|
|
1038
1045
|
|
|
1039
1046
|
if (fn) {
|
|
1047
|
+
const stepCallId = randomUUID();
|
|
1040
1048
|
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
1041
1049
|
return await fn({
|
|
1042
1050
|
runId,
|
|
1051
|
+
workflowId,
|
|
1043
1052
|
mastra: this.mastra!,
|
|
1044
1053
|
runtimeContext,
|
|
1045
1054
|
inputData: prevOutput,
|
|
@@ -1067,6 +1076,15 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1067
1076
|
[EMITTER_SYMBOL]: emitter,
|
|
1068
1077
|
engine: { step: this.inngestStep },
|
|
1069
1078
|
abortSignal: abortController?.signal,
|
|
1079
|
+
writer: new ToolStream(
|
|
1080
|
+
{
|
|
1081
|
+
prefix: 'step',
|
|
1082
|
+
callId: stepCallId,
|
|
1083
|
+
name: 'sleep',
|
|
1084
|
+
runId,
|
|
1085
|
+
},
|
|
1086
|
+
writableStream,
|
|
1087
|
+
),
|
|
1070
1088
|
});
|
|
1071
1089
|
});
|
|
1072
1090
|
}
|
|
@@ -1083,6 +1101,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1083
1101
|
emitter,
|
|
1084
1102
|
abortController,
|
|
1085
1103
|
runtimeContext,
|
|
1104
|
+
writableStream,
|
|
1086
1105
|
}: {
|
|
1087
1106
|
workflowId: string;
|
|
1088
1107
|
runId: string;
|
|
@@ -1106,13 +1125,16 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1106
1125
|
emitter: Emitter;
|
|
1107
1126
|
abortController: AbortController;
|
|
1108
1127
|
runtimeContext: RuntimeContext;
|
|
1128
|
+
writableStream?: WritableStream<ChunkType>;
|
|
1109
1129
|
}): Promise<void> {
|
|
1110
1130
|
let { date, fn } = entry;
|
|
1111
1131
|
|
|
1112
1132
|
if (fn) {
|
|
1113
1133
|
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
1134
|
+
const stepCallId = randomUUID();
|
|
1114
1135
|
return await fn({
|
|
1115
1136
|
runId,
|
|
1137
|
+
workflowId,
|
|
1116
1138
|
mastra: this.mastra!,
|
|
1117
1139
|
runtimeContext,
|
|
1118
1140
|
inputData: prevOutput,
|
|
@@ -1140,6 +1162,15 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1140
1162
|
[EMITTER_SYMBOL]: emitter,
|
|
1141
1163
|
engine: { step: this.inngestStep },
|
|
1142
1164
|
abortSignal: abortController?.signal,
|
|
1165
|
+
writer: new ToolStream(
|
|
1166
|
+
{
|
|
1167
|
+
prefix: 'step',
|
|
1168
|
+
callId: stepCallId,
|
|
1169
|
+
name: 'sleep',
|
|
1170
|
+
runId,
|
|
1171
|
+
},
|
|
1172
|
+
writableStream,
|
|
1173
|
+
),
|
|
1143
1174
|
});
|
|
1144
1175
|
});
|
|
1145
1176
|
}
|
|
@@ -1173,6 +1204,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1173
1204
|
emitter,
|
|
1174
1205
|
abortController,
|
|
1175
1206
|
runtimeContext,
|
|
1207
|
+
writableStream,
|
|
1176
1208
|
}: {
|
|
1177
1209
|
step: Step<string, any, any>;
|
|
1178
1210
|
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
@@ -1186,6 +1218,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1186
1218
|
emitter: Emitter;
|
|
1187
1219
|
abortController: AbortController;
|
|
1188
1220
|
runtimeContext: RuntimeContext;
|
|
1221
|
+
writableStream?: WritableStream<ChunkType>;
|
|
1189
1222
|
}): Promise<StepResult<any, any, any, any>> {
|
|
1190
1223
|
const startedAt = await this.inngestStep.run(
|
|
1191
1224
|
`workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
|
|
@@ -1429,6 +1462,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1429
1462
|
runId: executionContext.runId,
|
|
1430
1463
|
mastra: this.mastra!,
|
|
1431
1464
|
runtimeContext,
|
|
1465
|
+
writableStream,
|
|
1432
1466
|
inputData: prevOutput,
|
|
1433
1467
|
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : undefined,
|
|
1434
1468
|
getInitData: () => stepResults?.input as any,
|
|
@@ -1575,6 +1609,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1575
1609
|
workflowStatus: 'success' | 'failed' | 'suspended' | 'running';
|
|
1576
1610
|
result?: Record<string, any>;
|
|
1577
1611
|
error?: string | Error;
|
|
1612
|
+
runtimeContext: RuntimeContext;
|
|
1578
1613
|
}) {
|
|
1579
1614
|
await this.inngestStep.run(
|
|
1580
1615
|
`workflow.${workflowId}.run.${runId}.path.${JSON.stringify(executionContext.executionPath)}.stepUpdate`,
|
|
@@ -1613,6 +1648,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1613
1648
|
emitter,
|
|
1614
1649
|
abortController,
|
|
1615
1650
|
runtimeContext,
|
|
1651
|
+
writableStream,
|
|
1616
1652
|
}: {
|
|
1617
1653
|
workflowId: string;
|
|
1618
1654
|
runId: string;
|
|
@@ -1635,6 +1671,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1635
1671
|
emitter: Emitter;
|
|
1636
1672
|
abortController: AbortController;
|
|
1637
1673
|
runtimeContext: RuntimeContext;
|
|
1674
|
+
writableStream?: WritableStream<ChunkType>;
|
|
1638
1675
|
}): Promise<StepResult<any, any, any, any>> {
|
|
1639
1676
|
let execResults: any;
|
|
1640
1677
|
const truthyIndexes = (
|
|
@@ -1644,6 +1681,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1644
1681
|
try {
|
|
1645
1682
|
const result = await cond({
|
|
1646
1683
|
runId,
|
|
1684
|
+
workflowId,
|
|
1647
1685
|
mastra: this.mastra!,
|
|
1648
1686
|
runtimeContext,
|
|
1649
1687
|
runCount: -1,
|
|
@@ -1673,6 +1711,15 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1673
1711
|
step: this.inngestStep,
|
|
1674
1712
|
},
|
|
1675
1713
|
abortSignal: abortController.signal,
|
|
1714
|
+
writer: new ToolStream(
|
|
1715
|
+
{
|
|
1716
|
+
prefix: 'step',
|
|
1717
|
+
callId: randomUUID(),
|
|
1718
|
+
name: 'conditional',
|
|
1719
|
+
runId,
|
|
1720
|
+
},
|
|
1721
|
+
writableStream,
|
|
1722
|
+
),
|
|
1676
1723
|
});
|
|
1677
1724
|
return result ? index : null;
|
|
1678
1725
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -1706,6 +1753,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
1706
1753
|
emitter,
|
|
1707
1754
|
abortController,
|
|
1708
1755
|
runtimeContext,
|
|
1756
|
+
writableStream,
|
|
1709
1757
|
}),
|
|
1710
1758
|
),
|
|
1711
1759
|
);
|