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