@mastra/inngest 1.0.0-beta.1 → 1.0.0-beta.2
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 +45 -0
- package/dist/index.cjs +276 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +56 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +278 -47
- package/dist/index.js.map +1 -1
- package/package.json +11 -9
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
|
-
import { ReadableStream } from 'stream/web';
|
|
2
|
+
import { ReadableStream, WritableStream } from 'stream/web';
|
|
3
3
|
import { subscribe } from '@inngest/realtime';
|
|
4
4
|
import { RequestContext } from '@mastra/core/di';
|
|
5
|
-
import {
|
|
5
|
+
import { SpanType } from '@mastra/core/observability';
|
|
6
6
|
import { ChunkFrom, WorkflowRunOutput } from '@mastra/core/stream';
|
|
7
7
|
import { ToolStream, Tool } from '@mastra/core/tools';
|
|
8
|
-
import { Run, Workflow, DefaultExecutionEngine, createDeprecationProxy, getStepResult, runCountDeprecationMessage, validateStepInput } from '@mastra/core/workflows';
|
|
8
|
+
import { Run, createTimeTravelExecutionParams, Workflow, DefaultExecutionEngine, createDeprecationProxy, getStepResult, runCountDeprecationMessage, validateStepInput, validateStepResumeData } from '@mastra/core/workflows';
|
|
9
9
|
import { EMITTER_SYMBOL, STREAM_FORMAT_SYMBOL } from '@mastra/core/workflows/_constants';
|
|
10
10
|
import { NonRetriableError, RetryAfterError } from 'inngest';
|
|
11
11
|
import { serve as serve$1 } from 'inngest/hono';
|
|
@@ -99,7 +99,8 @@ var InngestRun = class extends Run {
|
|
|
99
99
|
resourceId: this.resourceId,
|
|
100
100
|
snapshot: {
|
|
101
101
|
...snapshot,
|
|
102
|
-
status: "canceled"
|
|
102
|
+
status: "canceled",
|
|
103
|
+
value: snapshot.value
|
|
103
104
|
}
|
|
104
105
|
});
|
|
105
106
|
}
|
|
@@ -121,14 +122,15 @@ var InngestRun = class extends Run {
|
|
|
121
122
|
snapshot: {
|
|
122
123
|
runId: this.runId,
|
|
123
124
|
serializedStepGraph: this.serializedStepGraph,
|
|
125
|
+
status: "running",
|
|
124
126
|
value: {},
|
|
125
127
|
context: {},
|
|
126
128
|
activePaths: [],
|
|
127
129
|
suspendedPaths: {},
|
|
130
|
+
activeStepsPath: {},
|
|
128
131
|
resumeLabels: {},
|
|
129
132
|
waitingPaths: {},
|
|
130
|
-
timestamp: Date.now()
|
|
131
|
-
status: "running"
|
|
133
|
+
timestamp: Date.now()
|
|
132
134
|
}
|
|
133
135
|
});
|
|
134
136
|
const inputDataToUse = await this._validateInput(inputData);
|
|
@@ -172,9 +174,14 @@ var InngestRun = class extends Run {
|
|
|
172
174
|
}
|
|
173
175
|
async _resume(params) {
|
|
174
176
|
const storage = this.#mastra?.getStorage();
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
177
|
+
let steps = [];
|
|
178
|
+
if (typeof params.step === "string") {
|
|
179
|
+
steps = params.step.split(".");
|
|
180
|
+
} else {
|
|
181
|
+
steps = (Array.isArray(params.step) ? params.step : [params.step]).map(
|
|
182
|
+
(step) => typeof step === "string" ? step : step?.id
|
|
183
|
+
);
|
|
184
|
+
}
|
|
178
185
|
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
179
186
|
workflowName: this.workflowId,
|
|
180
187
|
runId: this.runId
|
|
@@ -193,9 +200,99 @@ var InngestRun = class extends Run {
|
|
|
193
200
|
steps,
|
|
194
201
|
stepResults: snapshot?.context,
|
|
195
202
|
resumePayload: resumeDataToUse,
|
|
196
|
-
|
|
197
|
-
|
|
203
|
+
resumePath: steps?.[0] ? snapshot?.suspendedPaths?.[steps?.[0]] : void 0
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
const eventId = eventOutput.ids[0];
|
|
208
|
+
if (!eventId) {
|
|
209
|
+
throw new Error("Event ID is not set");
|
|
210
|
+
}
|
|
211
|
+
const runOutput = await this.getRunOutput(eventId);
|
|
212
|
+
const result = runOutput?.output?.result;
|
|
213
|
+
if (result.status === "failed") {
|
|
214
|
+
result.error = new Error(result.error);
|
|
215
|
+
}
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
async timeTravel(params) {
|
|
219
|
+
const p = this._timeTravel(params).then((result) => {
|
|
220
|
+
if (result.status !== "suspended") {
|
|
221
|
+
this.closeStreamAction?.().catch(() => {
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
return result;
|
|
225
|
+
});
|
|
226
|
+
this.executionResults = p;
|
|
227
|
+
return p;
|
|
228
|
+
}
|
|
229
|
+
async _timeTravel(params) {
|
|
230
|
+
if (!params.step || Array.isArray(params.step) && params.step?.length === 0) {
|
|
231
|
+
throw new Error("Step is required and must be a valid step or array of steps");
|
|
232
|
+
}
|
|
233
|
+
let steps = [];
|
|
234
|
+
if (typeof params.step === "string") {
|
|
235
|
+
steps = params.step.split(".");
|
|
236
|
+
} else {
|
|
237
|
+
steps = (Array.isArray(params.step) ? params.step : [params.step]).map(
|
|
238
|
+
(step) => typeof step === "string" ? step : step?.id
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
if (steps.length === 0) {
|
|
242
|
+
throw new Error("No steps provided to timeTravel");
|
|
243
|
+
}
|
|
244
|
+
const storage = this.#mastra?.getStorage();
|
|
245
|
+
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
246
|
+
workflowName: this.workflowId,
|
|
247
|
+
runId: this.runId
|
|
248
|
+
});
|
|
249
|
+
if (!snapshot) {
|
|
250
|
+
await storage?.persistWorkflowSnapshot({
|
|
251
|
+
workflowName: this.workflowId,
|
|
252
|
+
runId: this.runId,
|
|
253
|
+
resourceId: this.resourceId,
|
|
254
|
+
snapshot: {
|
|
255
|
+
runId: this.runId,
|
|
256
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
257
|
+
status: "pending",
|
|
258
|
+
value: {},
|
|
259
|
+
context: {},
|
|
260
|
+
activePaths: [],
|
|
261
|
+
suspendedPaths: {},
|
|
262
|
+
activeStepsPath: {},
|
|
263
|
+
resumeLabels: {},
|
|
264
|
+
waitingPaths: {},
|
|
265
|
+
timestamp: Date.now()
|
|
198
266
|
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
if (snapshot?.status === "running") {
|
|
270
|
+
throw new Error("This workflow run is still running, cannot time travel");
|
|
271
|
+
}
|
|
272
|
+
let inputDataToUse = params.inputData;
|
|
273
|
+
if (inputDataToUse && steps.length === 1) {
|
|
274
|
+
inputDataToUse = await this._validateTimetravelInputData(params.inputData, this.workflowSteps[steps[0]]);
|
|
275
|
+
}
|
|
276
|
+
const timeTravelData = createTimeTravelExecutionParams({
|
|
277
|
+
steps,
|
|
278
|
+
inputData: inputDataToUse,
|
|
279
|
+
resumeData: params.resumeData,
|
|
280
|
+
context: params.context,
|
|
281
|
+
nestedStepsContext: params.nestedStepsContext,
|
|
282
|
+
snapshot: snapshot ?? { context: {} },
|
|
283
|
+
graph: this.executionGraph,
|
|
284
|
+
initialState: params.initialState
|
|
285
|
+
});
|
|
286
|
+
const eventOutput = await this.inngest.send({
|
|
287
|
+
name: `workflow.${this.workflowId}`,
|
|
288
|
+
data: {
|
|
289
|
+
initialState: timeTravelData.state,
|
|
290
|
+
runId: this.runId,
|
|
291
|
+
workflowId: this.workflowId,
|
|
292
|
+
stepResults: timeTravelData.stepResults,
|
|
293
|
+
timeTravel: timeTravelData,
|
|
294
|
+
tracingOptions: params.tracingOptions,
|
|
295
|
+
outputOptions: params.outputOptions
|
|
199
296
|
}
|
|
200
297
|
});
|
|
201
298
|
const eventId = eventOutput.ids[0];
|
|
@@ -358,6 +455,75 @@ var InngestRun = class extends Run {
|
|
|
358
455
|
streamVNext(args = {}) {
|
|
359
456
|
return this.stream(args);
|
|
360
457
|
}
|
|
458
|
+
timeTravelStream({
|
|
459
|
+
inputData,
|
|
460
|
+
resumeData,
|
|
461
|
+
initialState,
|
|
462
|
+
step,
|
|
463
|
+
context,
|
|
464
|
+
nestedStepsContext,
|
|
465
|
+
requestContext,
|
|
466
|
+
tracingOptions,
|
|
467
|
+
outputOptions
|
|
468
|
+
}) {
|
|
469
|
+
this.closeStreamAction = async () => {
|
|
470
|
+
};
|
|
471
|
+
const self = this;
|
|
472
|
+
const stream = new ReadableStream({
|
|
473
|
+
async start(controller) {
|
|
474
|
+
const unwatch = self.watch(async ({ type, from = ChunkFrom.WORKFLOW, payload }) => {
|
|
475
|
+
controller.enqueue({
|
|
476
|
+
type,
|
|
477
|
+
runId: self.runId,
|
|
478
|
+
from,
|
|
479
|
+
payload: {
|
|
480
|
+
stepName: payload?.id,
|
|
481
|
+
...payload
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
self.closeStreamAction = async () => {
|
|
486
|
+
unwatch();
|
|
487
|
+
try {
|
|
488
|
+
await controller.close();
|
|
489
|
+
} catch (err) {
|
|
490
|
+
console.error("Error closing stream:", err);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
const executionResultsPromise = self._timeTravel({
|
|
494
|
+
inputData,
|
|
495
|
+
step,
|
|
496
|
+
context,
|
|
497
|
+
nestedStepsContext,
|
|
498
|
+
resumeData,
|
|
499
|
+
initialState,
|
|
500
|
+
requestContext,
|
|
501
|
+
tracingOptions,
|
|
502
|
+
outputOptions
|
|
503
|
+
});
|
|
504
|
+
self.executionResults = executionResultsPromise;
|
|
505
|
+
let executionResults;
|
|
506
|
+
try {
|
|
507
|
+
executionResults = await executionResultsPromise;
|
|
508
|
+
self.closeStreamAction?.().catch(() => {
|
|
509
|
+
});
|
|
510
|
+
if (self.streamOutput) {
|
|
511
|
+
self.streamOutput.updateResults(executionResults);
|
|
512
|
+
}
|
|
513
|
+
} catch (err) {
|
|
514
|
+
self.streamOutput?.rejectResults(err);
|
|
515
|
+
self.closeStreamAction?.().catch(() => {
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
this.streamOutput = new WorkflowRunOutput({
|
|
521
|
+
runId: this.runId,
|
|
522
|
+
workflowId: this.workflowId,
|
|
523
|
+
stream
|
|
524
|
+
});
|
|
525
|
+
return this.streamOutput;
|
|
526
|
+
}
|
|
361
527
|
};
|
|
362
528
|
var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
363
529
|
#mastra;
|
|
@@ -367,6 +533,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
367
533
|
constructor(params, inngest) {
|
|
368
534
|
const { concurrency, rateLimit, throttle, debounce, priority, ...workflowParams } = params;
|
|
369
535
|
super(workflowParams);
|
|
536
|
+
this.engineType = "inngest";
|
|
370
537
|
const flowControlEntries = Object.entries({ concurrency, rateLimit, throttle, debounce, priority }).filter(
|
|
371
538
|
([_, value]) => value !== void 0
|
|
372
539
|
);
|
|
@@ -422,7 +589,9 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
422
589
|
mastra: this.#mastra,
|
|
423
590
|
retryConfig: this.retryConfig,
|
|
424
591
|
cleanup: () => this.runs.delete(runIdToUse),
|
|
425
|
-
workflowSteps: this.steps
|
|
592
|
+
workflowSteps: this.steps,
|
|
593
|
+
workflowEngineType: this.engineType,
|
|
594
|
+
validateInputs: this.options.validateInputs
|
|
426
595
|
},
|
|
427
596
|
this.inngest
|
|
428
597
|
);
|
|
@@ -443,13 +612,13 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
443
612
|
value: {},
|
|
444
613
|
context: {},
|
|
445
614
|
activePaths: [],
|
|
615
|
+
activeStepsPath: {},
|
|
446
616
|
waitingPaths: {},
|
|
447
617
|
serializedStepGraph: this.serializedStepGraph,
|
|
448
618
|
suspendedPaths: {},
|
|
449
619
|
resumeLabels: {},
|
|
450
620
|
result: void 0,
|
|
451
621
|
error: void 0,
|
|
452
|
-
// @ts-ignore
|
|
453
622
|
timestamp: Date.now()
|
|
454
623
|
}
|
|
455
624
|
});
|
|
@@ -463,15 +632,14 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
463
632
|
this.function = this.inngest.createFunction(
|
|
464
633
|
{
|
|
465
634
|
id: `workflow.${this.id}`,
|
|
466
|
-
|
|
467
|
-
retries: this.retryConfig?.attempts ?? 0,
|
|
635
|
+
retries: Math.min(this.retryConfig?.attempts ?? 0, 20),
|
|
468
636
|
cancelOn: [{ event: `cancel.workflow.${this.id}` }],
|
|
469
637
|
// Spread flow control configuration
|
|
470
638
|
...this.flowControlConfig
|
|
471
639
|
},
|
|
472
640
|
{ event: `workflow.${this.id}` },
|
|
473
641
|
async ({ event, step, attempt, publish }) => {
|
|
474
|
-
let { inputData, initialState, runId, resourceId, resume, outputOptions, format } = event.data;
|
|
642
|
+
let { inputData, initialState, runId, resourceId, resume, outputOptions, format, timeTravel } = event.data;
|
|
475
643
|
if (!runId) {
|
|
476
644
|
runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
|
|
477
645
|
return randomUUID();
|
|
@@ -513,6 +681,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
513
681
|
requestContext: new RequestContext(),
|
|
514
682
|
// TODO
|
|
515
683
|
resume,
|
|
684
|
+
timeTravel,
|
|
516
685
|
format,
|
|
517
686
|
abortController: new AbortController(),
|
|
518
687
|
// currentSpan: undefined, // TODO: Pass actual parent Span from workflow execution context
|
|
@@ -565,13 +734,11 @@ function createStep(params, agentOptions) {
|
|
|
565
734
|
return {
|
|
566
735
|
id: params.name,
|
|
567
736
|
description: params.getDescription(),
|
|
568
|
-
// @ts-ignore
|
|
569
737
|
inputSchema: z.object({
|
|
570
738
|
prompt: z.string()
|
|
571
739
|
// resourceId: z.string().optional(),
|
|
572
740
|
// threadId: z.string().optional(),
|
|
573
741
|
}),
|
|
574
|
-
// @ts-ignore
|
|
575
742
|
outputSchema: z.object({
|
|
576
743
|
text: z.string()
|
|
577
744
|
}),
|
|
@@ -661,20 +828,36 @@ function createStep(params, agentOptions) {
|
|
|
661
828
|
}
|
|
662
829
|
return {
|
|
663
830
|
// TODO: tool probably should have strong id type
|
|
664
|
-
// @ts-ignore
|
|
665
831
|
id: params.id,
|
|
666
832
|
description: params.description,
|
|
667
833
|
inputSchema: params.inputSchema,
|
|
668
834
|
outputSchema: params.outputSchema,
|
|
669
|
-
execute: async ({
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
835
|
+
execute: async ({
|
|
836
|
+
inputData,
|
|
837
|
+
mastra,
|
|
838
|
+
requestContext,
|
|
839
|
+
tracingContext,
|
|
840
|
+
suspend,
|
|
841
|
+
resumeData,
|
|
842
|
+
runId,
|
|
843
|
+
workflowId,
|
|
844
|
+
state,
|
|
845
|
+
setState
|
|
846
|
+
}) => {
|
|
847
|
+
const toolContext = {
|
|
848
|
+
mastra,
|
|
673
849
|
requestContext,
|
|
674
850
|
tracingContext,
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
851
|
+
resumeData,
|
|
852
|
+
workflow: {
|
|
853
|
+
runId,
|
|
854
|
+
suspend,
|
|
855
|
+
workflowId,
|
|
856
|
+
state,
|
|
857
|
+
setState
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
return params.execute(inputData, toolContext);
|
|
678
861
|
},
|
|
679
862
|
component: "TOOL"
|
|
680
863
|
};
|
|
@@ -708,6 +891,8 @@ function init(inngest) {
|
|
|
708
891
|
suspendSchema: step.suspendSchema,
|
|
709
892
|
stateSchema: step.stateSchema,
|
|
710
893
|
execute: step.execute,
|
|
894
|
+
retries: step.retries,
|
|
895
|
+
scorers: step.scorers,
|
|
711
896
|
component: step.component
|
|
712
897
|
};
|
|
713
898
|
},
|
|
@@ -947,6 +1132,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
947
1132
|
stepResults,
|
|
948
1133
|
executionContext,
|
|
949
1134
|
resume,
|
|
1135
|
+
timeTravel,
|
|
950
1136
|
prevOutput,
|
|
951
1137
|
emitter,
|
|
952
1138
|
abortController,
|
|
@@ -967,7 +1153,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
967
1153
|
const { inputData, validationError } = await validateStepInput({
|
|
968
1154
|
prevOutput,
|
|
969
1155
|
step,
|
|
970
|
-
validateInputs: this.options?.validateInputs ??
|
|
1156
|
+
validateInputs: this.options?.validateInputs ?? true
|
|
971
1157
|
});
|
|
972
1158
|
const startedAt = await this.inngestStep.run(
|
|
973
1159
|
`workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
|
|
@@ -989,9 +1175,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
989
1175
|
const isResume = !!resume?.steps?.length;
|
|
990
1176
|
let result;
|
|
991
1177
|
let runId;
|
|
1178
|
+
const isTimeTravel = !!(timeTravel && timeTravel.steps?.length > 1 && timeTravel.steps[0] === step.id);
|
|
992
1179
|
try {
|
|
993
1180
|
if (isResume) {
|
|
994
|
-
runId = stepResults[resume?.steps?.[0]]?.suspendPayload?.__workflow_meta?.runId ?? randomUUID();
|
|
1181
|
+
runId = stepResults[resume?.steps?.[0] ?? ""]?.suspendPayload?.__workflow_meta?.runId ?? randomUUID();
|
|
995
1182
|
const snapshot = await this.mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
996
1183
|
workflowName: step.id,
|
|
997
1184
|
runId
|
|
@@ -1007,8 +1194,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1007
1194
|
steps: resume.steps.slice(1),
|
|
1008
1195
|
stepResults: snapshot?.context,
|
|
1009
1196
|
resumePayload: resume.resumePayload,
|
|
1010
|
-
|
|
1011
|
-
resumePath: snapshot?.suspendedPaths?.[resume.steps?.[1]]
|
|
1197
|
+
resumePath: resume.steps?.[1] ? snapshot?.suspendedPaths?.[resume.steps?.[1]] : void 0
|
|
1012
1198
|
},
|
|
1013
1199
|
outputOptions: { includeState: true }
|
|
1014
1200
|
}
|
|
@@ -1016,6 +1202,32 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1016
1202
|
result = invokeResp.result;
|
|
1017
1203
|
runId = invokeResp.runId;
|
|
1018
1204
|
executionContext.state = invokeResp.result.state;
|
|
1205
|
+
} else if (isTimeTravel) {
|
|
1206
|
+
const snapshot = await this.mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
1207
|
+
workflowName: step.id,
|
|
1208
|
+
runId: executionContext.runId
|
|
1209
|
+
}) ?? { context: {} };
|
|
1210
|
+
const timeTravelParams = createTimeTravelExecutionParams({
|
|
1211
|
+
steps: timeTravel.steps.slice(1),
|
|
1212
|
+
inputData: timeTravel.inputData,
|
|
1213
|
+
resumeData: timeTravel.resumeData,
|
|
1214
|
+
context: timeTravel.nestedStepResults?.[step.id] ?? {},
|
|
1215
|
+
nestedStepsContext: timeTravel.nestedStepResults ?? {},
|
|
1216
|
+
snapshot,
|
|
1217
|
+
graph: step.buildExecutionGraph()
|
|
1218
|
+
});
|
|
1219
|
+
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
1220
|
+
function: step.getFunction(),
|
|
1221
|
+
data: {
|
|
1222
|
+
timeTravel: timeTravelParams,
|
|
1223
|
+
initialState: executionContext.state ?? {},
|
|
1224
|
+
runId: executionContext.runId,
|
|
1225
|
+
outputOptions: { includeState: true }
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
result = invokeResp.result;
|
|
1229
|
+
runId = invokeResp.runId;
|
|
1230
|
+
executionContext.state = invokeResp.result.state;
|
|
1019
1231
|
} else {
|
|
1020
1232
|
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
1021
1233
|
function: step.getFunction(),
|
|
@@ -1128,14 +1340,32 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1128
1340
|
let execResults;
|
|
1129
1341
|
let suspended;
|
|
1130
1342
|
let bailed;
|
|
1343
|
+
const { resumeData: timeTravelResumeData, validationError: timeTravelResumeValidationError } = await validateStepResumeData({
|
|
1344
|
+
resumeData: timeTravel?.stepResults[step.id]?.status === "suspended" ? timeTravel?.resumeData : void 0,
|
|
1345
|
+
step
|
|
1346
|
+
});
|
|
1347
|
+
let resumeDataToUse;
|
|
1348
|
+
if (timeTravelResumeData && !timeTravelResumeValidationError) {
|
|
1349
|
+
resumeDataToUse = timeTravelResumeData;
|
|
1350
|
+
} else if (timeTravelResumeData && timeTravelResumeValidationError) {
|
|
1351
|
+
this.logger.warn("Time travel resume data validation failed", {
|
|
1352
|
+
stepId: step.id,
|
|
1353
|
+
error: timeTravelResumeValidationError.message
|
|
1354
|
+
});
|
|
1355
|
+
} else if (resume?.steps[0] === step.id) {
|
|
1356
|
+
resumeDataToUse = resume?.resumePayload;
|
|
1357
|
+
}
|
|
1131
1358
|
try {
|
|
1132
1359
|
if (validationError) {
|
|
1133
1360
|
throw validationError;
|
|
1134
1361
|
}
|
|
1362
|
+
const retryCount = this.getOrGenerateRetryCount(step.id);
|
|
1135
1363
|
const result = await step.execute({
|
|
1136
1364
|
runId: executionContext.runId,
|
|
1365
|
+
workflowId: executionContext.workflowId,
|
|
1137
1366
|
mastra: this.mastra,
|
|
1138
1367
|
requestContext,
|
|
1368
|
+
retryCount,
|
|
1139
1369
|
writer: new ToolStream(
|
|
1140
1370
|
{
|
|
1141
1371
|
prefix: "workflow-step",
|
|
@@ -1150,7 +1380,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1150
1380
|
executionContext.state = state;
|
|
1151
1381
|
},
|
|
1152
1382
|
inputData,
|
|
1153
|
-
resumeData:
|
|
1383
|
+
resumeData: resumeDataToUse,
|
|
1154
1384
|
tracingContext: {
|
|
1155
1385
|
currentSpan: stepSpan
|
|
1156
1386
|
},
|
|
@@ -1172,11 +1402,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1172
1402
|
bail: (result2) => {
|
|
1173
1403
|
bailed = { payload: result2 };
|
|
1174
1404
|
},
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
resumePayload: resume?.resumePayload,
|
|
1178
|
-
// @ts-ignore
|
|
1179
|
-
runId: stepResults[step.id]?.suspendPayload?.__workflow_meta?.runId
|
|
1405
|
+
abort: () => {
|
|
1406
|
+
abortController?.abort();
|
|
1180
1407
|
},
|
|
1181
1408
|
[EMITTER_SYMBOL]: emitter,
|
|
1182
1409
|
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
@@ -1192,8 +1419,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1192
1419
|
startedAt,
|
|
1193
1420
|
endedAt,
|
|
1194
1421
|
payload: inputData,
|
|
1195
|
-
resumedAt:
|
|
1196
|
-
resumePayload:
|
|
1422
|
+
resumedAt: resumeDataToUse ? startedAt : void 0,
|
|
1423
|
+
resumePayload: resumeDataToUse
|
|
1197
1424
|
};
|
|
1198
1425
|
} catch (e) {
|
|
1199
1426
|
const stepFailure = {
|
|
@@ -1202,8 +1429,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1202
1429
|
error: e instanceof Error ? e.message : String(e),
|
|
1203
1430
|
endedAt: Date.now(),
|
|
1204
1431
|
startedAt,
|
|
1205
|
-
resumedAt:
|
|
1206
|
-
resumePayload:
|
|
1432
|
+
resumedAt: resumeDataToUse ? startedAt : void 0,
|
|
1433
|
+
resumePayload: resumeDataToUse
|
|
1207
1434
|
};
|
|
1208
1435
|
execResults = stepFailure;
|
|
1209
1436
|
const fallbackErrorMessage = `Step ${step.id} failed`;
|
|
@@ -1220,8 +1447,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1220
1447
|
payload: inputData,
|
|
1221
1448
|
suspendedAt: Date.now(),
|
|
1222
1449
|
startedAt,
|
|
1223
|
-
resumedAt:
|
|
1224
|
-
resumePayload:
|
|
1450
|
+
resumedAt: resumeDataToUse ? startedAt : void 0,
|
|
1451
|
+
resumePayload: resumeDataToUse
|
|
1225
1452
|
};
|
|
1226
1453
|
} else if (bailed) {
|
|
1227
1454
|
execResults = {
|
|
@@ -1294,7 +1521,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1294
1521
|
});
|
|
1295
1522
|
}
|
|
1296
1523
|
Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
|
|
1297
|
-
Object.assign(stepResults, stepRes.stepResults);
|
|
1298
1524
|
executionContext.state = stepRes.executionContext.state;
|
|
1299
1525
|
return stepRes.result;
|
|
1300
1526
|
}
|
|
@@ -1322,17 +1548,17 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1322
1548
|
resourceId,
|
|
1323
1549
|
snapshot: {
|
|
1324
1550
|
runId,
|
|
1551
|
+
status: workflowStatus,
|
|
1325
1552
|
value: executionContext.state,
|
|
1326
1553
|
context: stepResults,
|
|
1327
|
-
activePaths:
|
|
1554
|
+
activePaths: executionContext.executionPath,
|
|
1555
|
+
activeStepsPath: executionContext.activeStepsPath,
|
|
1328
1556
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1329
1557
|
resumeLabels: executionContext.resumeLabels,
|
|
1330
1558
|
waitingPaths: {},
|
|
1331
1559
|
serializedStepGraph,
|
|
1332
|
-
status: workflowStatus,
|
|
1333
1560
|
result,
|
|
1334
1561
|
error,
|
|
1335
|
-
// @ts-ignore
|
|
1336
1562
|
timestamp: Date.now()
|
|
1337
1563
|
}
|
|
1338
1564
|
});
|
|
@@ -1345,6 +1571,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1345
1571
|
entry,
|
|
1346
1572
|
prevOutput,
|
|
1347
1573
|
stepResults,
|
|
1574
|
+
timeTravel,
|
|
1348
1575
|
resume,
|
|
1349
1576
|
executionContext,
|
|
1350
1577
|
emitter,
|
|
@@ -1463,10 +1690,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1463
1690
|
prevOutput,
|
|
1464
1691
|
stepResults,
|
|
1465
1692
|
resume,
|
|
1693
|
+
timeTravel,
|
|
1466
1694
|
executionContext: {
|
|
1467
1695
|
workflowId,
|
|
1468
1696
|
runId,
|
|
1469
1697
|
executionPath: [...executionContext.executionPath, index],
|
|
1698
|
+
activeStepsPath: executionContext.activeStepsPath,
|
|
1470
1699
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1471
1700
|
resumeLabels: executionContext.resumeLabels,
|
|
1472
1701
|
retryConfig: executionContext.retryConfig,
|
|
@@ -1500,7 +1729,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1500
1729
|
status: "success",
|
|
1501
1730
|
output: results.reduce((acc, result, index) => {
|
|
1502
1731
|
if (result.status === "success") {
|
|
1503
|
-
|
|
1732
|
+
if ("step" in stepsToRun[index]) {
|
|
1733
|
+
acc[stepsToRun[index].step.id] = result.output;
|
|
1734
|
+
}
|
|
1504
1735
|
}
|
|
1505
1736
|
return acc;
|
|
1506
1737
|
}, {})
|