@mastra/inngest 0.15.0 → 0.15.1-alpha.1
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 +18 -0
- package/dist/index.cjs +270 -163
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +39 -25
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +270 -163
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
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,
|
|
@@ -363,7 +375,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
363
375
|
},
|
|
364
376
|
{ event: `workflow.${this.id}` },
|
|
365
377
|
async ({ event, step, attempt, publish }) => {
|
|
366
|
-
let { inputData, runId, resourceId, resume } = event.data;
|
|
378
|
+
let { inputData, initialState, runId, resourceId, resume, outputOptions } = event.data;
|
|
367
379
|
if (!runId) {
|
|
368
380
|
runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
|
|
369
381
|
return randomUUID();
|
|
@@ -399,14 +411,24 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
399
411
|
graph: this.executionGraph,
|
|
400
412
|
serializedStepGraph: this.serializedStepGraph,
|
|
401
413
|
input: inputData,
|
|
414
|
+
initialState,
|
|
402
415
|
emitter,
|
|
403
416
|
retryConfig: this.retryConfig,
|
|
404
417
|
runtimeContext: new RuntimeContext(),
|
|
405
418
|
// TODO
|
|
406
419
|
resume,
|
|
407
420
|
abortController: new AbortController(),
|
|
408
|
-
currentSpan: void 0
|
|
421
|
+
currentSpan: void 0,
|
|
409
422
|
// TODO: Pass actual parent AI span from workflow execution context
|
|
423
|
+
outputOptions
|
|
424
|
+
});
|
|
425
|
+
await step.run(`workflow.${this.id}.finalize`, async () => {
|
|
426
|
+
if (result.status === "failed") {
|
|
427
|
+
throw new NonRetriableError(`Workflow failed`, {
|
|
428
|
+
cause: result
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
return result;
|
|
410
432
|
});
|
|
411
433
|
return { result, runId };
|
|
412
434
|
}
|
|
@@ -558,7 +580,10 @@ function createStep(params) {
|
|
|
558
580
|
function init(inngest) {
|
|
559
581
|
return {
|
|
560
582
|
createWorkflow(params) {
|
|
561
|
-
return new InngestWorkflow(
|
|
583
|
+
return new InngestWorkflow(
|
|
584
|
+
params,
|
|
585
|
+
inngest
|
|
586
|
+
);
|
|
562
587
|
},
|
|
563
588
|
createStep,
|
|
564
589
|
cloneStep(step, opts) {
|
|
@@ -567,6 +592,9 @@ function init(inngest) {
|
|
|
567
592
|
description: step.description,
|
|
568
593
|
inputSchema: step.inputSchema,
|
|
569
594
|
outputSchema: step.outputSchema,
|
|
595
|
+
resumeSchema: step.resumeSchema,
|
|
596
|
+
suspendSchema: step.suspendSchema,
|
|
597
|
+
stateSchema: step.stateSchema,
|
|
570
598
|
execute: step.execute,
|
|
571
599
|
component: step.component
|
|
572
600
|
};
|
|
@@ -652,7 +680,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
652
680
|
});
|
|
653
681
|
const suspendedStepIds = Object.entries(stepResults).flatMap(([stepId, stepResult]) => {
|
|
654
682
|
if (stepResult?.status === "suspended") {
|
|
655
|
-
const nestedPath = stepResult?.
|
|
683
|
+
const nestedPath = stepResult?.suspendPayload?.__workflow_meta?.path;
|
|
656
684
|
return nestedPath ? [[stepId, ...nestedPath]] : [[stepId]];
|
|
657
685
|
}
|
|
658
686
|
return [];
|
|
@@ -697,6 +725,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
697
725
|
mastra: this.mastra,
|
|
698
726
|
runtimeContext,
|
|
699
727
|
inputData: prevOutput,
|
|
728
|
+
state: executionContext.state,
|
|
729
|
+
setState: (state) => {
|
|
730
|
+
executionContext.state = state;
|
|
731
|
+
},
|
|
700
732
|
runCount: -1,
|
|
701
733
|
tracingContext: {
|
|
702
734
|
currentSpan: sleepSpan
|
|
@@ -774,6 +806,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
774
806
|
mastra: this.mastra,
|
|
775
807
|
runtimeContext,
|
|
776
808
|
inputData: prevOutput,
|
|
809
|
+
state: executionContext.state,
|
|
810
|
+
setState: (state) => {
|
|
811
|
+
executionContext.state = state;
|
|
812
|
+
},
|
|
777
813
|
runCount: -1,
|
|
778
814
|
tracingContext: {
|
|
779
815
|
currentSpan: sleepUntilSpan
|
|
@@ -904,38 +940,60 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
904
940
|
const isResume = !!resume?.steps?.length;
|
|
905
941
|
let result;
|
|
906
942
|
let runId;
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
943
|
+
try {
|
|
944
|
+
if (isResume) {
|
|
945
|
+
runId = stepResults[resume?.steps?.[0]]?.suspendPayload?.__workflow_meta?.runId ?? randomUUID();
|
|
946
|
+
const snapshot = await this.mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
947
|
+
workflowName: step.id,
|
|
948
|
+
runId
|
|
949
|
+
});
|
|
950
|
+
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
951
|
+
function: step.getFunction(),
|
|
952
|
+
data: {
|
|
953
|
+
inputData,
|
|
954
|
+
initialState: executionContext.state ?? snapshot?.value ?? {},
|
|
919
955
|
runId,
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
956
|
+
resume: {
|
|
957
|
+
runId,
|
|
958
|
+
steps: resume.steps.slice(1),
|
|
959
|
+
stepResults: snapshot?.context,
|
|
960
|
+
resumePayload: resume.resumePayload,
|
|
961
|
+
// @ts-ignore
|
|
962
|
+
resumePath: snapshot?.suspendedPaths?.[resume.steps?.[1]]
|
|
963
|
+
},
|
|
964
|
+
outputOptions: { includeState: true }
|
|
925
965
|
}
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
966
|
+
});
|
|
967
|
+
result = invokeResp.result;
|
|
968
|
+
runId = invokeResp.runId;
|
|
969
|
+
executionContext.state = invokeResp.result.state;
|
|
970
|
+
} else {
|
|
971
|
+
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
972
|
+
function: step.getFunction(),
|
|
973
|
+
data: {
|
|
974
|
+
inputData,
|
|
975
|
+
initialState: executionContext.state ?? {},
|
|
976
|
+
outputOptions: { includeState: true }
|
|
977
|
+
}
|
|
978
|
+
});
|
|
979
|
+
result = invokeResp.result;
|
|
980
|
+
runId = invokeResp.runId;
|
|
981
|
+
executionContext.state = invokeResp.result.state;
|
|
982
|
+
}
|
|
983
|
+
} catch (e) {
|
|
984
|
+
const errorCause = e?.cause;
|
|
985
|
+
if (errorCause && typeof errorCause === "object") {
|
|
986
|
+
result = errorCause;
|
|
987
|
+
runId = errorCause.runId || randomUUID();
|
|
988
|
+
} else {
|
|
989
|
+
runId = randomUUID();
|
|
990
|
+
result = {
|
|
991
|
+
status: "failed",
|
|
992
|
+
error: e instanceof Error ? e : new Error(String(e)),
|
|
993
|
+
steps: {},
|
|
994
|
+
input: inputData
|
|
995
|
+
};
|
|
996
|
+
}
|
|
939
997
|
}
|
|
940
998
|
const res = await this.inngestStep.run(
|
|
941
999
|
`workflow.${executionContext.workflowId}.step.${step.id}.nestedwf-results`,
|
|
@@ -974,7 +1032,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
974
1032
|
return stepRes2?.status === "suspended";
|
|
975
1033
|
});
|
|
976
1034
|
for (const [stepName, stepResult] of suspendedSteps) {
|
|
977
|
-
const suspendPath = [stepName, ...stepResult?.
|
|
1035
|
+
const suspendPath = [stepName, ...stepResult?.suspendPayload?.__workflow_meta?.path ?? []];
|
|
978
1036
|
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
979
1037
|
await emitter.emit("watch", {
|
|
980
1038
|
type: "watch",
|
|
@@ -982,7 +1040,11 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
982
1040
|
currentStep: {
|
|
983
1041
|
id: step.id,
|
|
984
1042
|
status: "suspended",
|
|
985
|
-
payload:
|
|
1043
|
+
payload: stepResult.payload,
|
|
1044
|
+
suspendPayload: {
|
|
1045
|
+
...stepResult?.suspendPayload,
|
|
1046
|
+
__workflow_meta: { runId, path: suspendPath }
|
|
1047
|
+
}
|
|
986
1048
|
},
|
|
987
1049
|
workflowState: {
|
|
988
1050
|
status: "running",
|
|
@@ -1004,7 +1066,11 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1004
1066
|
executionContext,
|
|
1005
1067
|
result: {
|
|
1006
1068
|
status: "suspended",
|
|
1007
|
-
payload:
|
|
1069
|
+
payload: stepResult.payload,
|
|
1070
|
+
suspendPayload: {
|
|
1071
|
+
...stepResult?.suspendPayload,
|
|
1072
|
+
__workflow_meta: { runId, path: suspendPath }
|
|
1073
|
+
}
|
|
1008
1074
|
}
|
|
1009
1075
|
};
|
|
1010
1076
|
}
|
|
@@ -1069,132 +1135,167 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1069
1135
|
}
|
|
1070
1136
|
);
|
|
1071
1137
|
Object.assign(executionContext, res.executionContext);
|
|
1072
|
-
return
|
|
1138
|
+
return {
|
|
1139
|
+
...res.result,
|
|
1140
|
+
startedAt,
|
|
1141
|
+
endedAt: Date.now(),
|
|
1142
|
+
payload: inputData,
|
|
1143
|
+
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1144
|
+
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1145
|
+
};
|
|
1073
1146
|
}
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1147
|
+
let stepRes;
|
|
1148
|
+
try {
|
|
1149
|
+
stepRes = await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}`, async () => {
|
|
1150
|
+
let execResults;
|
|
1151
|
+
let suspended;
|
|
1152
|
+
let bailed;
|
|
1153
|
+
try {
|
|
1154
|
+
if (validationError) {
|
|
1155
|
+
throw validationError;
|
|
1156
|
+
}
|
|
1157
|
+
const result = await step.execute({
|
|
1158
|
+
runId: executionContext.runId,
|
|
1159
|
+
mastra: this.mastra,
|
|
1160
|
+
runtimeContext,
|
|
1161
|
+
writableStream,
|
|
1162
|
+
state: executionContext?.state ?? {},
|
|
1163
|
+
setState: (state) => {
|
|
1164
|
+
executionContext.state = state;
|
|
1165
|
+
},
|
|
1166
|
+
inputData,
|
|
1167
|
+
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1168
|
+
tracingContext: {
|
|
1169
|
+
currentSpan: stepAISpan
|
|
1170
|
+
},
|
|
1171
|
+
getInitData: () => stepResults?.input,
|
|
1172
|
+
getStepResult: getStepResult.bind(this, stepResults),
|
|
1173
|
+
suspend: async (suspendPayload) => {
|
|
1174
|
+
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
1175
|
+
suspended = { payload: suspendPayload };
|
|
1176
|
+
},
|
|
1177
|
+
bail: (result2) => {
|
|
1178
|
+
bailed = { payload: result2 };
|
|
1179
|
+
},
|
|
1180
|
+
resume: {
|
|
1181
|
+
steps: resume?.steps?.slice(1) || [],
|
|
1182
|
+
resumePayload: resume?.resumePayload,
|
|
1183
|
+
// @ts-ignore
|
|
1184
|
+
runId: stepResults[step.id]?.suspendPayload?.__workflow_meta?.runId
|
|
1185
|
+
},
|
|
1186
|
+
[EMITTER_SYMBOL]: emitter,
|
|
1187
|
+
engine: {
|
|
1188
|
+
step: this.inngestStep
|
|
1189
|
+
},
|
|
1190
|
+
abortSignal: abortController.signal
|
|
1191
|
+
});
|
|
1192
|
+
const endedAt = Date.now();
|
|
1193
|
+
execResults = {
|
|
1194
|
+
status: "success",
|
|
1195
|
+
output: result,
|
|
1196
|
+
startedAt,
|
|
1197
|
+
endedAt,
|
|
1198
|
+
payload: inputData,
|
|
1199
|
+
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1200
|
+
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1201
|
+
};
|
|
1202
|
+
} catch (e) {
|
|
1203
|
+
const stepFailure = {
|
|
1204
|
+
status: "failed",
|
|
1205
|
+
payload: inputData,
|
|
1206
|
+
error: e instanceof Error ? e.message : String(e),
|
|
1207
|
+
endedAt: Date.now(),
|
|
1208
|
+
startedAt,
|
|
1209
|
+
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1210
|
+
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1211
|
+
};
|
|
1212
|
+
execResults = stepFailure;
|
|
1213
|
+
const fallbackErrorMessage = `Step ${step.id} failed`;
|
|
1214
|
+
stepAISpan?.error({ error: new Error(execResults.error ?? fallbackErrorMessage) });
|
|
1215
|
+
throw new RetryAfterError(execResults.error ?? fallbackErrorMessage, executionContext.retryConfig.delay, {
|
|
1216
|
+
cause: execResults
|
|
1217
|
+
});
|
|
1081
1218
|
}
|
|
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
|
-
|
|
1219
|
+
if (suspended) {
|
|
1220
|
+
execResults = {
|
|
1221
|
+
status: "suspended",
|
|
1222
|
+
suspendPayload: suspended.payload,
|
|
1223
|
+
payload: inputData,
|
|
1224
|
+
suspendedAt: Date.now(),
|
|
1225
|
+
startedAt,
|
|
1226
|
+
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1227
|
+
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1228
|
+
};
|
|
1229
|
+
} else if (bailed) {
|
|
1230
|
+
execResults = {
|
|
1231
|
+
status: "bailed",
|
|
1232
|
+
output: bailed.payload,
|
|
1233
|
+
payload: inputData,
|
|
1234
|
+
endedAt: Date.now(),
|
|
1235
|
+
startedAt
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
await emitter.emit("watch", {
|
|
1239
|
+
type: "watch",
|
|
1240
|
+
payload: {
|
|
1241
|
+
currentStep: {
|
|
1242
|
+
id: step.id,
|
|
1243
|
+
...execResults
|
|
1244
|
+
},
|
|
1245
|
+
workflowState: {
|
|
1246
|
+
status: "running",
|
|
1247
|
+
steps: { ...stepResults, [step.id]: execResults },
|
|
1248
|
+
result: null,
|
|
1249
|
+
error: null
|
|
1250
|
+
}
|
|
1110
1251
|
},
|
|
1111
|
-
|
|
1252
|
+
eventTimestamp: Date.now()
|
|
1112
1253
|
});
|
|
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;
|
|
1254
|
+
if (execResults.status === "suspended") {
|
|
1255
|
+
await emitter.emit("watch-v2", {
|
|
1256
|
+
type: "workflow-step-suspended",
|
|
1257
|
+
payload: {
|
|
1258
|
+
id: step.id,
|
|
1259
|
+
...execResults
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
} else {
|
|
1263
|
+
await emitter.emit("watch-v2", {
|
|
1264
|
+
type: "workflow-step-result",
|
|
1265
|
+
payload: {
|
|
1266
|
+
id: step.id,
|
|
1267
|
+
...execResults
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
await emitter.emit("watch-v2", {
|
|
1271
|
+
type: "workflow-step-finish",
|
|
1272
|
+
payload: {
|
|
1273
|
+
id: step.id,
|
|
1274
|
+
metadata: {}
|
|
1275
|
+
}
|
|
1276
|
+
});
|
|
1152
1277
|
}
|
|
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()
|
|
1278
|
+
stepAISpan?.end({ output: execResults });
|
|
1279
|
+
return { result: execResults, executionContext, stepResults };
|
|
1169
1280
|
});
|
|
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) {
|
|
1281
|
+
} catch (e) {
|
|
1282
|
+
const stepFailure = e instanceof Error ? e?.cause : {
|
|
1283
|
+
status: "failed",
|
|
1284
|
+
error: e instanceof Error ? e.message : String(e),
|
|
1285
|
+
payload: inputData,
|
|
1286
|
+
startedAt,
|
|
1287
|
+
endedAt: Date.now()
|
|
1288
|
+
};
|
|
1289
|
+
stepRes = {
|
|
1290
|
+
result: stepFailure,
|
|
1291
|
+
executionContext,
|
|
1292
|
+
stepResults: {
|
|
1293
|
+
...stepResults,
|
|
1294
|
+
[step.id]: stepFailure
|
|
1295
|
+
}
|
|
1296
|
+
};
|
|
1297
|
+
}
|
|
1298
|
+
if (disableScorers !== false && stepRes.result.status === "success") {
|
|
1198
1299
|
await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}.score`, async () => {
|
|
1199
1300
|
if (step.scorers) {
|
|
1200
1301
|
await this.runScorers({
|
|
@@ -1213,6 +1314,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1213
1314
|
}
|
|
1214
1315
|
Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
|
|
1215
1316
|
Object.assign(stepResults, stepRes.stepResults);
|
|
1317
|
+
executionContext.state = stepRes.executionContext.state;
|
|
1216
1318
|
return stepRes.result;
|
|
1217
1319
|
}
|
|
1218
1320
|
async persistStepUpdate({
|
|
@@ -1235,7 +1337,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1235
1337
|
resourceId,
|
|
1236
1338
|
snapshot: {
|
|
1237
1339
|
runId,
|
|
1238
|
-
value:
|
|
1340
|
+
value: executionContext.state,
|
|
1239
1341
|
context: stepResults,
|
|
1240
1342
|
activePaths: [],
|
|
1241
1343
|
suspendedPaths: executionContext.suspendedPaths,
|
|
@@ -1298,6 +1400,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1298
1400
|
runtimeContext,
|
|
1299
1401
|
runCount: -1,
|
|
1300
1402
|
inputData: prevOutput,
|
|
1403
|
+
state: executionContext.state,
|
|
1404
|
+
setState: (state) => {
|
|
1405
|
+
executionContext.state = state;
|
|
1406
|
+
},
|
|
1301
1407
|
tracingContext: {
|
|
1302
1408
|
currentSpan: evalSpan
|
|
1303
1409
|
},
|
|
@@ -1370,7 +1476,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1370
1476
|
executionPath: [...executionContext.executionPath, index],
|
|
1371
1477
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1372
1478
|
retryConfig: executionContext.retryConfig,
|
|
1373
|
-
executionSpan: executionContext.executionSpan
|
|
1479
|
+
executionSpan: executionContext.executionSpan,
|
|
1480
|
+
state: executionContext.state
|
|
1374
1481
|
},
|
|
1375
1482
|
emitter,
|
|
1376
1483
|
abortController,
|
|
@@ -1388,7 +1495,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1388
1495
|
if (hasFailed) {
|
|
1389
1496
|
execResults = { status: "failed", error: hasFailed.result.error };
|
|
1390
1497
|
} else if (hasSuspended) {
|
|
1391
|
-
execResults = { status: "suspended",
|
|
1498
|
+
execResults = { status: "suspended", suspendPayload: hasSuspended.result.suspendPayload };
|
|
1392
1499
|
} else {
|
|
1393
1500
|
execResults = {
|
|
1394
1501
|
status: "success",
|