@mastra/inngest 0.0.0-break-rename-vnext-legacy-20251002212351 → 0.0.0-chore-core-swap-aiv5-ai-package-naming-20251009203931
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 +88 -4
- package/dist/index.cjs +280 -165
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +40 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +280 -165
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -7,6 +7,7 @@ var di = require('@mastra/core/di');
|
|
|
7
7
|
var tools = require('@mastra/core/tools');
|
|
8
8
|
var workflows = require('@mastra/core/workflows');
|
|
9
9
|
var _constants = require('@mastra/core/workflows/_constants');
|
|
10
|
+
var inngest = require('inngest');
|
|
10
11
|
var hono = require('inngest/hono');
|
|
11
12
|
var zod = require('zod');
|
|
12
13
|
|
|
@@ -60,8 +61,15 @@ var InngestRun = class extends workflows.Run {
|
|
|
60
61
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
61
62
|
runs = await this.getRuns(eventId);
|
|
62
63
|
if (runs?.[0]?.status === "Failed") {
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
|
|
65
|
+
workflowName: this.workflowId,
|
|
66
|
+
runId: this.runId
|
|
67
|
+
});
|
|
68
|
+
return {
|
|
69
|
+
output: { result: { steps: snapshot?.context, status: "failed", error: runs?.[0]?.output?.message } }
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (runs?.[0]?.status === "Cancelled") {
|
|
65
73
|
const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
|
|
66
74
|
workflowName: this.workflowId,
|
|
67
75
|
runId: this.runId
|
|
@@ -101,7 +109,8 @@ var InngestRun = class extends workflows.Run {
|
|
|
101
109
|
}
|
|
102
110
|
}
|
|
103
111
|
async start({
|
|
104
|
-
inputData
|
|
112
|
+
inputData,
|
|
113
|
+
initialState
|
|
105
114
|
}) {
|
|
106
115
|
await this.#mastra.getStorage()?.persistWorkflowSnapshot({
|
|
107
116
|
workflowName: this.workflowId,
|
|
@@ -120,10 +129,12 @@ var InngestRun = class extends workflows.Run {
|
|
|
120
129
|
}
|
|
121
130
|
});
|
|
122
131
|
const inputDataToUse = await this._validateInput(inputData);
|
|
132
|
+
const initialStateToUse = await this._validateInitialState(initialState ?? {});
|
|
123
133
|
const eventOutput = await this.inngest.send({
|
|
124
134
|
name: `workflow.${this.workflowId}`,
|
|
125
135
|
data: {
|
|
126
136
|
inputData: inputDataToUse,
|
|
137
|
+
initialState: initialStateToUse,
|
|
127
138
|
runId: this.runId,
|
|
128
139
|
resourceId: this.resourceId
|
|
129
140
|
}
|
|
@@ -167,6 +178,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
167
178
|
name: `workflow.${this.workflowId}`,
|
|
168
179
|
data: {
|
|
169
180
|
inputData: resumeDataToUse,
|
|
181
|
+
initialState: snapshot?.value ?? {},
|
|
170
182
|
runId: this.runId,
|
|
171
183
|
workflowId: this.workflowId,
|
|
172
184
|
stepResults: snapshot?.context,
|
|
@@ -326,8 +338,12 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
326
338
|
this.inngest
|
|
327
339
|
);
|
|
328
340
|
this.runs.set(runIdToUse, run);
|
|
341
|
+
const shouldPersistSnapshot = this.options.shouldPersistSnapshot({
|
|
342
|
+
workflowStatus: run.workflowRunStatus,
|
|
343
|
+
stepResults: {}
|
|
344
|
+
});
|
|
329
345
|
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, false);
|
|
330
|
-
if (!workflowSnapshotInStorage) {
|
|
346
|
+
if (!workflowSnapshotInStorage && shouldPersistSnapshot) {
|
|
331
347
|
await this.mastra?.getStorage()?.persistWorkflowSnapshot({
|
|
332
348
|
workflowName: this.id,
|
|
333
349
|
runId: runIdToUse,
|
|
@@ -365,7 +381,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
365
381
|
},
|
|
366
382
|
{ event: `workflow.${this.id}` },
|
|
367
383
|
async ({ event, step, attempt, publish }) => {
|
|
368
|
-
let { inputData, runId, resourceId, resume } = event.data;
|
|
384
|
+
let { inputData, initialState, runId, resourceId, resume, outputOptions } = event.data;
|
|
369
385
|
if (!runId) {
|
|
370
386
|
runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
|
|
371
387
|
return crypto.randomUUID();
|
|
@@ -393,7 +409,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
393
409
|
once: (_event, _callback) => {
|
|
394
410
|
}
|
|
395
411
|
};
|
|
396
|
-
const engine = new InngestExecutionEngine(this.#mastra, step, attempt);
|
|
412
|
+
const engine = new InngestExecutionEngine(this.#mastra, step, attempt, this.options);
|
|
397
413
|
const result = await engine.execute({
|
|
398
414
|
workflowId: this.id,
|
|
399
415
|
runId,
|
|
@@ -401,14 +417,24 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
401
417
|
graph: this.executionGraph,
|
|
402
418
|
serializedStepGraph: this.serializedStepGraph,
|
|
403
419
|
input: inputData,
|
|
420
|
+
initialState,
|
|
404
421
|
emitter,
|
|
405
422
|
retryConfig: this.retryConfig,
|
|
406
423
|
runtimeContext: new di.RuntimeContext(),
|
|
407
424
|
// TODO
|
|
408
425
|
resume,
|
|
409
426
|
abortController: new AbortController(),
|
|
410
|
-
currentSpan: void 0
|
|
427
|
+
currentSpan: void 0,
|
|
411
428
|
// TODO: Pass actual parent AI span from workflow execution context
|
|
429
|
+
outputOptions
|
|
430
|
+
});
|
|
431
|
+
await step.run(`workflow.${this.id}.finalize`, async () => {
|
|
432
|
+
if (result.status === "failed") {
|
|
433
|
+
throw new inngest.NonRetriableError(`Workflow failed`, {
|
|
434
|
+
cause: result
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
return result;
|
|
412
438
|
});
|
|
413
439
|
return { result, runId };
|
|
414
440
|
}
|
|
@@ -560,7 +586,10 @@ function createStep(params) {
|
|
|
560
586
|
function init(inngest) {
|
|
561
587
|
return {
|
|
562
588
|
createWorkflow(params) {
|
|
563
|
-
return new InngestWorkflow(
|
|
589
|
+
return new InngestWorkflow(
|
|
590
|
+
params,
|
|
591
|
+
inngest
|
|
592
|
+
);
|
|
564
593
|
},
|
|
565
594
|
createStep,
|
|
566
595
|
cloneStep(step, opts) {
|
|
@@ -569,6 +598,9 @@ function init(inngest) {
|
|
|
569
598
|
description: step.description,
|
|
570
599
|
inputSchema: step.inputSchema,
|
|
571
600
|
outputSchema: step.outputSchema,
|
|
601
|
+
resumeSchema: step.resumeSchema,
|
|
602
|
+
suspendSchema: step.suspendSchema,
|
|
603
|
+
stateSchema: step.stateSchema,
|
|
572
604
|
execute: step.execute,
|
|
573
605
|
component: step.component
|
|
574
606
|
};
|
|
@@ -654,7 +686,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
654
686
|
});
|
|
655
687
|
const suspendedStepIds = Object.entries(stepResults).flatMap(([stepId, stepResult]) => {
|
|
656
688
|
if (stepResult?.status === "suspended") {
|
|
657
|
-
const nestedPath = stepResult?.
|
|
689
|
+
const nestedPath = stepResult?.suspendPayload?.__workflow_meta?.path;
|
|
658
690
|
return nestedPath ? [[stepId, ...nestedPath]] : [[stepId]];
|
|
659
691
|
}
|
|
660
692
|
return [];
|
|
@@ -699,6 +731,10 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
699
731
|
mastra: this.mastra,
|
|
700
732
|
runtimeContext,
|
|
701
733
|
inputData: prevOutput,
|
|
734
|
+
state: executionContext.state,
|
|
735
|
+
setState: (state) => {
|
|
736
|
+
executionContext.state = state;
|
|
737
|
+
},
|
|
702
738
|
runCount: -1,
|
|
703
739
|
tracingContext: {
|
|
704
740
|
currentSpan: sleepSpan
|
|
@@ -776,6 +812,10 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
776
812
|
mastra: this.mastra,
|
|
777
813
|
runtimeContext,
|
|
778
814
|
inputData: prevOutput,
|
|
815
|
+
state: executionContext.state,
|
|
816
|
+
setState: (state) => {
|
|
817
|
+
executionContext.state = state;
|
|
818
|
+
},
|
|
779
819
|
runCount: -1,
|
|
780
820
|
tracingContext: {
|
|
781
821
|
currentSpan: sleepUntilSpan
|
|
@@ -906,38 +946,60 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
906
946
|
const isResume = !!resume?.steps?.length;
|
|
907
947
|
let result;
|
|
908
948
|
let runId;
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
949
|
+
try {
|
|
950
|
+
if (isResume) {
|
|
951
|
+
runId = stepResults[resume?.steps?.[0]]?.suspendPayload?.__workflow_meta?.runId ?? crypto.randomUUID();
|
|
952
|
+
const snapshot = await this.mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
953
|
+
workflowName: step.id,
|
|
954
|
+
runId
|
|
955
|
+
});
|
|
956
|
+
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
957
|
+
function: step.getFunction(),
|
|
958
|
+
data: {
|
|
959
|
+
inputData,
|
|
960
|
+
initialState: executionContext.state ?? snapshot?.value ?? {},
|
|
921
961
|
runId,
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
962
|
+
resume: {
|
|
963
|
+
runId,
|
|
964
|
+
steps: resume.steps.slice(1),
|
|
965
|
+
stepResults: snapshot?.context,
|
|
966
|
+
resumePayload: resume.resumePayload,
|
|
967
|
+
// @ts-ignore
|
|
968
|
+
resumePath: snapshot?.suspendedPaths?.[resume.steps?.[1]]
|
|
969
|
+
},
|
|
970
|
+
outputOptions: { includeState: true }
|
|
927
971
|
}
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
972
|
+
});
|
|
973
|
+
result = invokeResp.result;
|
|
974
|
+
runId = invokeResp.runId;
|
|
975
|
+
executionContext.state = invokeResp.result.state;
|
|
976
|
+
} else {
|
|
977
|
+
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
978
|
+
function: step.getFunction(),
|
|
979
|
+
data: {
|
|
980
|
+
inputData,
|
|
981
|
+
initialState: executionContext.state ?? {},
|
|
982
|
+
outputOptions: { includeState: true }
|
|
983
|
+
}
|
|
984
|
+
});
|
|
985
|
+
result = invokeResp.result;
|
|
986
|
+
runId = invokeResp.runId;
|
|
987
|
+
executionContext.state = invokeResp.result.state;
|
|
988
|
+
}
|
|
989
|
+
} catch (e) {
|
|
990
|
+
const errorCause = e?.cause;
|
|
991
|
+
if (errorCause && typeof errorCause === "object") {
|
|
992
|
+
result = errorCause;
|
|
993
|
+
runId = errorCause.runId || crypto.randomUUID();
|
|
994
|
+
} else {
|
|
995
|
+
runId = crypto.randomUUID();
|
|
996
|
+
result = {
|
|
997
|
+
status: "failed",
|
|
998
|
+
error: e instanceof Error ? e : new Error(String(e)),
|
|
999
|
+
steps: {},
|
|
1000
|
+
input: inputData
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
941
1003
|
}
|
|
942
1004
|
const res = await this.inngestStep.run(
|
|
943
1005
|
`workflow.${executionContext.workflowId}.step.${step.id}.nestedwf-results`,
|
|
@@ -976,7 +1038,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
976
1038
|
return stepRes2?.status === "suspended";
|
|
977
1039
|
});
|
|
978
1040
|
for (const [stepName, stepResult] of suspendedSteps) {
|
|
979
|
-
const suspendPath = [stepName, ...stepResult?.
|
|
1041
|
+
const suspendPath = [stepName, ...stepResult?.suspendPayload?.__workflow_meta?.path ?? []];
|
|
980
1042
|
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
981
1043
|
await emitter.emit("watch", {
|
|
982
1044
|
type: "watch",
|
|
@@ -984,7 +1046,11 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
984
1046
|
currentStep: {
|
|
985
1047
|
id: step.id,
|
|
986
1048
|
status: "suspended",
|
|
987
|
-
payload:
|
|
1049
|
+
payload: stepResult.payload,
|
|
1050
|
+
suspendPayload: {
|
|
1051
|
+
...stepResult?.suspendPayload,
|
|
1052
|
+
__workflow_meta: { runId, path: suspendPath }
|
|
1053
|
+
}
|
|
988
1054
|
},
|
|
989
1055
|
workflowState: {
|
|
990
1056
|
status: "running",
|
|
@@ -1006,7 +1072,11 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1006
1072
|
executionContext,
|
|
1007
1073
|
result: {
|
|
1008
1074
|
status: "suspended",
|
|
1009
|
-
payload:
|
|
1075
|
+
payload: stepResult.payload,
|
|
1076
|
+
suspendPayload: {
|
|
1077
|
+
...stepResult?.suspendPayload,
|
|
1078
|
+
__workflow_meta: { runId, path: suspendPath }
|
|
1079
|
+
}
|
|
1010
1080
|
}
|
|
1011
1081
|
};
|
|
1012
1082
|
}
|
|
@@ -1071,132 +1141,167 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1071
1141
|
}
|
|
1072
1142
|
);
|
|
1073
1143
|
Object.assign(executionContext, res.executionContext);
|
|
1074
|
-
return
|
|
1144
|
+
return {
|
|
1145
|
+
...res.result,
|
|
1146
|
+
startedAt,
|
|
1147
|
+
endedAt: Date.now(),
|
|
1148
|
+
payload: inputData,
|
|
1149
|
+
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1150
|
+
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1151
|
+
};
|
|
1075
1152
|
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1153
|
+
let stepRes;
|
|
1154
|
+
try {
|
|
1155
|
+
stepRes = await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}`, async () => {
|
|
1156
|
+
let execResults;
|
|
1157
|
+
let suspended;
|
|
1158
|
+
let bailed;
|
|
1159
|
+
try {
|
|
1160
|
+
if (validationError) {
|
|
1161
|
+
throw validationError;
|
|
1162
|
+
}
|
|
1163
|
+
const result = await step.execute({
|
|
1164
|
+
runId: executionContext.runId,
|
|
1165
|
+
mastra: this.mastra,
|
|
1166
|
+
runtimeContext,
|
|
1167
|
+
writableStream,
|
|
1168
|
+
state: executionContext?.state ?? {},
|
|
1169
|
+
setState: (state) => {
|
|
1170
|
+
executionContext.state = state;
|
|
1171
|
+
},
|
|
1172
|
+
inputData,
|
|
1173
|
+
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1174
|
+
tracingContext: {
|
|
1175
|
+
currentSpan: stepAISpan
|
|
1176
|
+
},
|
|
1177
|
+
getInitData: () => stepResults?.input,
|
|
1178
|
+
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
1179
|
+
suspend: async (suspendPayload) => {
|
|
1180
|
+
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
1181
|
+
suspended = { payload: suspendPayload };
|
|
1182
|
+
},
|
|
1183
|
+
bail: (result2) => {
|
|
1184
|
+
bailed = { payload: result2 };
|
|
1185
|
+
},
|
|
1186
|
+
resume: {
|
|
1187
|
+
steps: resume?.steps?.slice(1) || [],
|
|
1188
|
+
resumePayload: resume?.resumePayload,
|
|
1189
|
+
// @ts-ignore
|
|
1190
|
+
runId: stepResults[step.id]?.suspendPayload?.__workflow_meta?.runId
|
|
1191
|
+
},
|
|
1192
|
+
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1193
|
+
engine: {
|
|
1194
|
+
step: this.inngestStep
|
|
1195
|
+
},
|
|
1196
|
+
abortSignal: abortController.signal
|
|
1197
|
+
});
|
|
1198
|
+
const endedAt = Date.now();
|
|
1199
|
+
execResults = {
|
|
1200
|
+
status: "success",
|
|
1201
|
+
output: result,
|
|
1202
|
+
startedAt,
|
|
1203
|
+
endedAt,
|
|
1204
|
+
payload: inputData,
|
|
1205
|
+
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1206
|
+
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1207
|
+
};
|
|
1208
|
+
} catch (e) {
|
|
1209
|
+
const stepFailure = {
|
|
1210
|
+
status: "failed",
|
|
1211
|
+
payload: inputData,
|
|
1212
|
+
error: e instanceof Error ? e.message : String(e),
|
|
1213
|
+
endedAt: Date.now(),
|
|
1214
|
+
startedAt,
|
|
1215
|
+
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1216
|
+
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1217
|
+
};
|
|
1218
|
+
execResults = stepFailure;
|
|
1219
|
+
const fallbackErrorMessage = `Step ${step.id} failed`;
|
|
1220
|
+
stepAISpan?.error({ error: new Error(execResults.error ?? fallbackErrorMessage) });
|
|
1221
|
+
throw new inngest.RetryAfterError(execResults.error ?? fallbackErrorMessage, executionContext.retryConfig.delay, {
|
|
1222
|
+
cause: execResults
|
|
1223
|
+
});
|
|
1083
1224
|
}
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1225
|
+
if (suspended) {
|
|
1226
|
+
execResults = {
|
|
1227
|
+
status: "suspended",
|
|
1228
|
+
suspendPayload: suspended.payload,
|
|
1229
|
+
payload: inputData,
|
|
1230
|
+
suspendedAt: Date.now(),
|
|
1231
|
+
startedAt,
|
|
1232
|
+
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1233
|
+
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1234
|
+
};
|
|
1235
|
+
} else if (bailed) {
|
|
1236
|
+
execResults = {
|
|
1237
|
+
status: "bailed",
|
|
1238
|
+
output: bailed.payload,
|
|
1239
|
+
payload: inputData,
|
|
1240
|
+
endedAt: Date.now(),
|
|
1241
|
+
startedAt
|
|
1242
|
+
};
|
|
1243
|
+
}
|
|
1244
|
+
await emitter.emit("watch", {
|
|
1245
|
+
type: "watch",
|
|
1246
|
+
payload: {
|
|
1247
|
+
currentStep: {
|
|
1248
|
+
id: step.id,
|
|
1249
|
+
...execResults
|
|
1250
|
+
},
|
|
1251
|
+
workflowState: {
|
|
1252
|
+
status: "running",
|
|
1253
|
+
steps: { ...stepResults, [step.id]: execResults },
|
|
1254
|
+
result: null,
|
|
1255
|
+
error: null
|
|
1256
|
+
}
|
|
1112
1257
|
},
|
|
1113
|
-
|
|
1258
|
+
eventTimestamp: Date.now()
|
|
1114
1259
|
});
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
status: "suspended",
|
|
1139
|
-
suspendedPayload: suspended.payload,
|
|
1140
|
-
payload: inputData,
|
|
1141
|
-
suspendedAt: Date.now(),
|
|
1142
|
-
startedAt,
|
|
1143
|
-
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1144
|
-
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1145
|
-
};
|
|
1146
|
-
} else if (bailed) {
|
|
1147
|
-
execResults = { status: "bailed", output: bailed.payload, payload: inputData, endedAt: Date.now(), startedAt };
|
|
1148
|
-
}
|
|
1149
|
-
if (execResults.status === "failed") {
|
|
1150
|
-
if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
|
|
1151
|
-
const error = new Error(execResults.error);
|
|
1152
|
-
stepAISpan?.error({ error });
|
|
1153
|
-
throw error;
|
|
1260
|
+
if (execResults.status === "suspended") {
|
|
1261
|
+
await emitter.emit("watch-v2", {
|
|
1262
|
+
type: "workflow-step-suspended",
|
|
1263
|
+
payload: {
|
|
1264
|
+
id: step.id,
|
|
1265
|
+
...execResults
|
|
1266
|
+
}
|
|
1267
|
+
});
|
|
1268
|
+
} else {
|
|
1269
|
+
await emitter.emit("watch-v2", {
|
|
1270
|
+
type: "workflow-step-result",
|
|
1271
|
+
payload: {
|
|
1272
|
+
id: step.id,
|
|
1273
|
+
...execResults
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
await emitter.emit("watch-v2", {
|
|
1277
|
+
type: "workflow-step-finish",
|
|
1278
|
+
payload: {
|
|
1279
|
+
id: step.id,
|
|
1280
|
+
metadata: {}
|
|
1281
|
+
}
|
|
1282
|
+
});
|
|
1154
1283
|
}
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
type: "watch",
|
|
1158
|
-
payload: {
|
|
1159
|
-
currentStep: {
|
|
1160
|
-
id: step.id,
|
|
1161
|
-
...execResults
|
|
1162
|
-
},
|
|
1163
|
-
workflowState: {
|
|
1164
|
-
status: "running",
|
|
1165
|
-
steps: { ...stepResults, [step.id]: execResults },
|
|
1166
|
-
result: null,
|
|
1167
|
-
error: null
|
|
1168
|
-
}
|
|
1169
|
-
},
|
|
1170
|
-
eventTimestamp: Date.now()
|
|
1284
|
+
stepAISpan?.end({ output: execResults });
|
|
1285
|
+
return { result: execResults, executionContext, stepResults };
|
|
1171
1286
|
});
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
payload: {
|
|
1191
|
-
id: step.id,
|
|
1192
|
-
metadata: {}
|
|
1193
|
-
}
|
|
1194
|
-
});
|
|
1195
|
-
}
|
|
1196
|
-
stepAISpan?.end({ output: execResults });
|
|
1197
|
-
return { result: execResults, executionContext, stepResults };
|
|
1198
|
-
});
|
|
1199
|
-
if (disableScorers !== false) {
|
|
1287
|
+
} catch (e) {
|
|
1288
|
+
const stepFailure = e instanceof Error ? e?.cause : {
|
|
1289
|
+
status: "failed",
|
|
1290
|
+
error: e instanceof Error ? e.message : String(e),
|
|
1291
|
+
payload: inputData,
|
|
1292
|
+
startedAt,
|
|
1293
|
+
endedAt: Date.now()
|
|
1294
|
+
};
|
|
1295
|
+
stepRes = {
|
|
1296
|
+
result: stepFailure,
|
|
1297
|
+
executionContext,
|
|
1298
|
+
stepResults: {
|
|
1299
|
+
...stepResults,
|
|
1300
|
+
[step.id]: stepFailure
|
|
1301
|
+
}
|
|
1302
|
+
};
|
|
1303
|
+
}
|
|
1304
|
+
if (disableScorers !== false && stepRes.result.status === "success") {
|
|
1200
1305
|
await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}.score`, async () => {
|
|
1201
1306
|
if (step.scorers) {
|
|
1202
1307
|
await this.runScorers({
|
|
@@ -1215,6 +1320,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1215
1320
|
}
|
|
1216
1321
|
Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
|
|
1217
1322
|
Object.assign(stepResults, stepRes.stepResults);
|
|
1323
|
+
executionContext.state = stepRes.executionContext.state;
|
|
1218
1324
|
return stepRes.result;
|
|
1219
1325
|
}
|
|
1220
1326
|
async persistStepUpdate({
|
|
@@ -1231,13 +1337,17 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1231
1337
|
await this.inngestStep.run(
|
|
1232
1338
|
`workflow.${workflowId}.run.${runId}.path.${JSON.stringify(executionContext.executionPath)}.stepUpdate`,
|
|
1233
1339
|
async () => {
|
|
1340
|
+
const shouldPersistSnapshot = this.options.shouldPersistSnapshot({ stepResults, workflowStatus });
|
|
1341
|
+
if (!shouldPersistSnapshot) {
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1234
1344
|
await this.mastra?.getStorage()?.persistWorkflowSnapshot({
|
|
1235
1345
|
workflowName: workflowId,
|
|
1236
1346
|
runId,
|
|
1237
1347
|
resourceId,
|
|
1238
1348
|
snapshot: {
|
|
1239
1349
|
runId,
|
|
1240
|
-
value:
|
|
1350
|
+
value: executionContext.state,
|
|
1241
1351
|
context: stepResults,
|
|
1242
1352
|
activePaths: [],
|
|
1243
1353
|
suspendedPaths: executionContext.suspendedPaths,
|
|
@@ -1300,6 +1410,10 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1300
1410
|
runtimeContext,
|
|
1301
1411
|
runCount: -1,
|
|
1302
1412
|
inputData: prevOutput,
|
|
1413
|
+
state: executionContext.state,
|
|
1414
|
+
setState: (state) => {
|
|
1415
|
+
executionContext.state = state;
|
|
1416
|
+
},
|
|
1303
1417
|
tracingContext: {
|
|
1304
1418
|
currentSpan: evalSpan
|
|
1305
1419
|
},
|
|
@@ -1372,7 +1486,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1372
1486
|
executionPath: [...executionContext.executionPath, index],
|
|
1373
1487
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1374
1488
|
retryConfig: executionContext.retryConfig,
|
|
1375
|
-
executionSpan: executionContext.executionSpan
|
|
1489
|
+
executionSpan: executionContext.executionSpan,
|
|
1490
|
+
state: executionContext.state
|
|
1376
1491
|
},
|
|
1377
1492
|
emitter,
|
|
1378
1493
|
abortController,
|
|
@@ -1390,7 +1505,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1390
1505
|
if (hasFailed) {
|
|
1391
1506
|
execResults = { status: "failed", error: hasFailed.result.error };
|
|
1392
1507
|
} else if (hasSuspended) {
|
|
1393
|
-
execResults = { status: "suspended",
|
|
1508
|
+
execResults = { status: "suspended", suspendPayload: hasSuspended.result.suspendPayload };
|
|
1394
1509
|
} else {
|
|
1395
1510
|
execResults = {
|
|
1396
1511
|
status: "success",
|