@mastra/inngest 0.15.1-alpha.0 → 0.15.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 +20 -0
- package/dist/index.cjs +68 -17
- 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 +68 -17
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @mastra/inngest
|
|
2
2
|
|
|
3
|
+
## 0.15.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Mutable shared workflow run state ([#8545](https://github.com/mastra-ai/mastra/pull/8545))
|
|
8
|
+
|
|
9
|
+
- Handle workflow run failures (fix #8130) ([#8370](https://github.com/mastra-ai/mastra/pull/8370))
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`c621613`](https://github.com/mastra-ai/mastra/commit/c621613069173c69eb2c3ef19a5308894c6549f0), [`12b1189`](https://github.com/mastra-ai/mastra/commit/12b118942445e4de0dd916c593e33ec78dc3bc73), [`4783b30`](https://github.com/mastra-ai/mastra/commit/4783b3063efea887825514b783ba27f67912c26d), [`076b092`](https://github.com/mastra-ai/mastra/commit/076b0924902ff0f49d5712d2df24c4cca683713f), [`2aee9e7`](https://github.com/mastra-ai/mastra/commit/2aee9e7d188b8b256a4ddc203ccefb366b4867fa), [`c582906`](https://github.com/mastra-ai/mastra/commit/c5829065a346260f96c4beb8af131b94804ae3ad), [`fa2eb96`](https://github.com/mastra-ai/mastra/commit/fa2eb96af16c7d433891a73932764960d3235c1d), [`ee9108f`](https://github.com/mastra-ai/mastra/commit/ee9108fa29bb8368fc23df158c9f0645b2d7b65c), [`4783b30`](https://github.com/mastra-ai/mastra/commit/4783b3063efea887825514b783ba27f67912c26d), [`a739d0c`](https://github.com/mastra-ai/mastra/commit/a739d0c8b37cd89569e04a6ca0827083c6167e19), [`603e927`](https://github.com/mastra-ai/mastra/commit/603e9279db8bf8a46caf83881c6b7389ccffff7e), [`cd45982`](https://github.com/mastra-ai/mastra/commit/cd4598291cda128a88738734ae6cbef076ebdebd), [`874f74d`](https://github.com/mastra-ai/mastra/commit/874f74da4b1acf6517f18132d035612c3ecc394a), [`b728a45`](https://github.com/mastra-ai/mastra/commit/b728a45ab3dba59da0f5ee36b81fe246659f305d), [`0baf2ba`](https://github.com/mastra-ai/mastra/commit/0baf2bab8420277072ef1f95df5ea7b0a2f61fe7), [`10e633a`](https://github.com/mastra-ai/mastra/commit/10e633a07d333466d9734c97acfc3dbf757ad2d0), [`a6d69c5`](https://github.com/mastra-ai/mastra/commit/a6d69c5fb50c0875b46275811fece5862f03c6a0), [`84199af`](https://github.com/mastra-ai/mastra/commit/84199af8673f6f9cb59286ffb5477a41932775de), [`7f431af`](https://github.com/mastra-ai/mastra/commit/7f431afd586b7d3265075e73106eb73167edbb86), [`26e968d`](https://github.com/mastra-ai/mastra/commit/26e968db2171ded9e4d47aa1b4f19e1e771158d0), [`cbd3fb6`](https://github.com/mastra-ai/mastra/commit/cbd3fb65adb03a7c0df193cb998aed5ac56675ee)]:
|
|
12
|
+
- @mastra/core@0.20.1
|
|
13
|
+
|
|
14
|
+
## 0.15.1-alpha.1
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Mutable shared workflow run state ([#8545](https://github.com/mastra-ai/mastra/pull/8545))
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [[`c621613`](https://github.com/mastra-ai/mastra/commit/c621613069173c69eb2c3ef19a5308894c6549f0), [`12b1189`](https://github.com/mastra-ai/mastra/commit/12b118942445e4de0dd916c593e33ec78dc3bc73), [`4783b30`](https://github.com/mastra-ai/mastra/commit/4783b3063efea887825514b783ba27f67912c26d), [`076b092`](https://github.com/mastra-ai/mastra/commit/076b0924902ff0f49d5712d2df24c4cca683713f), [`2aee9e7`](https://github.com/mastra-ai/mastra/commit/2aee9e7d188b8b256a4ddc203ccefb366b4867fa), [`c582906`](https://github.com/mastra-ai/mastra/commit/c5829065a346260f96c4beb8af131b94804ae3ad), [`fa2eb96`](https://github.com/mastra-ai/mastra/commit/fa2eb96af16c7d433891a73932764960d3235c1d), [`4783b30`](https://github.com/mastra-ai/mastra/commit/4783b3063efea887825514b783ba27f67912c26d), [`a739d0c`](https://github.com/mastra-ai/mastra/commit/a739d0c8b37cd89569e04a6ca0827083c6167e19), [`603e927`](https://github.com/mastra-ai/mastra/commit/603e9279db8bf8a46caf83881c6b7389ccffff7e), [`cd45982`](https://github.com/mastra-ai/mastra/commit/cd4598291cda128a88738734ae6cbef076ebdebd), [`874f74d`](https://github.com/mastra-ai/mastra/commit/874f74da4b1acf6517f18132d035612c3ecc394a), [`0baf2ba`](https://github.com/mastra-ai/mastra/commit/0baf2bab8420277072ef1f95df5ea7b0a2f61fe7), [`26e968d`](https://github.com/mastra-ai/mastra/commit/26e968db2171ded9e4d47aa1b4f19e1e771158d0), [`cbd3fb6`](https://github.com/mastra-ai/mastra/commit/cbd3fb65adb03a7c0df193cb998aed5ac56675ee)]:
|
|
21
|
+
- @mastra/core@0.20.1-alpha.1
|
|
22
|
+
|
|
3
23
|
## 0.15.1-alpha.0
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -109,7 +109,8 @@ var InngestRun = class extends workflows.Run {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
async start({
|
|
112
|
-
inputData
|
|
112
|
+
inputData,
|
|
113
|
+
initialState
|
|
113
114
|
}) {
|
|
114
115
|
await this.#mastra.getStorage()?.persistWorkflowSnapshot({
|
|
115
116
|
workflowName: this.workflowId,
|
|
@@ -128,10 +129,12 @@ var InngestRun = class extends workflows.Run {
|
|
|
128
129
|
}
|
|
129
130
|
});
|
|
130
131
|
const inputDataToUse = await this._validateInput(inputData);
|
|
132
|
+
const initialStateToUse = await this._validateInitialState(initialState ?? {});
|
|
131
133
|
const eventOutput = await this.inngest.send({
|
|
132
134
|
name: `workflow.${this.workflowId}`,
|
|
133
135
|
data: {
|
|
134
136
|
inputData: inputDataToUse,
|
|
137
|
+
initialState: initialStateToUse,
|
|
135
138
|
runId: this.runId,
|
|
136
139
|
resourceId: this.resourceId
|
|
137
140
|
}
|
|
@@ -175,6 +178,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
175
178
|
name: `workflow.${this.workflowId}`,
|
|
176
179
|
data: {
|
|
177
180
|
inputData: resumeDataToUse,
|
|
181
|
+
initialState: snapshot?.value ?? {},
|
|
178
182
|
runId: this.runId,
|
|
179
183
|
workflowId: this.workflowId,
|
|
180
184
|
stepResults: snapshot?.context,
|
|
@@ -373,7 +377,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
373
377
|
},
|
|
374
378
|
{ event: `workflow.${this.id}` },
|
|
375
379
|
async ({ event, step, attempt, publish }) => {
|
|
376
|
-
let { inputData, runId, resourceId, resume } = event.data;
|
|
380
|
+
let { inputData, initialState, runId, resourceId, resume, outputOptions } = event.data;
|
|
377
381
|
if (!runId) {
|
|
378
382
|
runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
|
|
379
383
|
return crypto.randomUUID();
|
|
@@ -409,14 +413,16 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
409
413
|
graph: this.executionGraph,
|
|
410
414
|
serializedStepGraph: this.serializedStepGraph,
|
|
411
415
|
input: inputData,
|
|
416
|
+
initialState,
|
|
412
417
|
emitter,
|
|
413
418
|
retryConfig: this.retryConfig,
|
|
414
419
|
runtimeContext: new di.RuntimeContext(),
|
|
415
420
|
// TODO
|
|
416
421
|
resume,
|
|
417
422
|
abortController: new AbortController(),
|
|
418
|
-
currentSpan: void 0
|
|
423
|
+
currentSpan: void 0,
|
|
419
424
|
// TODO: Pass actual parent AI span from workflow execution context
|
|
425
|
+
outputOptions
|
|
420
426
|
});
|
|
421
427
|
await step.run(`workflow.${this.id}.finalize`, async () => {
|
|
422
428
|
if (result.status === "failed") {
|
|
@@ -576,7 +582,10 @@ function createStep(params) {
|
|
|
576
582
|
function init(inngest) {
|
|
577
583
|
return {
|
|
578
584
|
createWorkflow(params) {
|
|
579
|
-
return new InngestWorkflow(
|
|
585
|
+
return new InngestWorkflow(
|
|
586
|
+
params,
|
|
587
|
+
inngest
|
|
588
|
+
);
|
|
580
589
|
},
|
|
581
590
|
createStep,
|
|
582
591
|
cloneStep(step, opts) {
|
|
@@ -585,6 +594,9 @@ function init(inngest) {
|
|
|
585
594
|
description: step.description,
|
|
586
595
|
inputSchema: step.inputSchema,
|
|
587
596
|
outputSchema: step.outputSchema,
|
|
597
|
+
resumeSchema: step.resumeSchema,
|
|
598
|
+
suspendSchema: step.suspendSchema,
|
|
599
|
+
stateSchema: step.stateSchema,
|
|
588
600
|
execute: step.execute,
|
|
589
601
|
component: step.component
|
|
590
602
|
};
|
|
@@ -670,7 +682,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
670
682
|
});
|
|
671
683
|
const suspendedStepIds = Object.entries(stepResults).flatMap(([stepId, stepResult]) => {
|
|
672
684
|
if (stepResult?.status === "suspended") {
|
|
673
|
-
const nestedPath = stepResult?.
|
|
685
|
+
const nestedPath = stepResult?.suspendPayload?.__workflow_meta?.path;
|
|
674
686
|
return nestedPath ? [[stepId, ...nestedPath]] : [[stepId]];
|
|
675
687
|
}
|
|
676
688
|
return [];
|
|
@@ -715,6 +727,10 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
715
727
|
mastra: this.mastra,
|
|
716
728
|
runtimeContext,
|
|
717
729
|
inputData: prevOutput,
|
|
730
|
+
state: executionContext.state,
|
|
731
|
+
setState: (state) => {
|
|
732
|
+
executionContext.state = state;
|
|
733
|
+
},
|
|
718
734
|
runCount: -1,
|
|
719
735
|
tracingContext: {
|
|
720
736
|
currentSpan: sleepSpan
|
|
@@ -792,6 +808,10 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
792
808
|
mastra: this.mastra,
|
|
793
809
|
runtimeContext,
|
|
794
810
|
inputData: prevOutput,
|
|
811
|
+
state: executionContext.state,
|
|
812
|
+
setState: (state) => {
|
|
813
|
+
executionContext.state = state;
|
|
814
|
+
},
|
|
795
815
|
runCount: -1,
|
|
796
816
|
tracingContext: {
|
|
797
817
|
currentSpan: sleepUntilSpan
|
|
@@ -924,7 +944,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
924
944
|
let runId;
|
|
925
945
|
try {
|
|
926
946
|
if (isResume) {
|
|
927
|
-
runId = stepResults[resume?.steps?.[0]]?.
|
|
947
|
+
runId = stepResults[resume?.steps?.[0]]?.suspendPayload?.__workflow_meta?.runId ?? crypto.randomUUID();
|
|
928
948
|
const snapshot = await this.mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
929
949
|
workflowName: step.id,
|
|
930
950
|
runId
|
|
@@ -933,6 +953,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
933
953
|
function: step.getFunction(),
|
|
934
954
|
data: {
|
|
935
955
|
inputData,
|
|
956
|
+
initialState: executionContext.state ?? snapshot?.value ?? {},
|
|
936
957
|
runId,
|
|
937
958
|
resume: {
|
|
938
959
|
runId,
|
|
@@ -941,20 +962,25 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
941
962
|
resumePayload: resume.resumePayload,
|
|
942
963
|
// @ts-ignore
|
|
943
964
|
resumePath: snapshot?.suspendedPaths?.[resume.steps?.[1]]
|
|
944
|
-
}
|
|
965
|
+
},
|
|
966
|
+
outputOptions: { includeState: true }
|
|
945
967
|
}
|
|
946
968
|
});
|
|
947
969
|
result = invokeResp.result;
|
|
948
970
|
runId = invokeResp.runId;
|
|
971
|
+
executionContext.state = invokeResp.result.state;
|
|
949
972
|
} else {
|
|
950
973
|
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
951
974
|
function: step.getFunction(),
|
|
952
975
|
data: {
|
|
953
|
-
inputData
|
|
976
|
+
inputData,
|
|
977
|
+
initialState: executionContext.state ?? {},
|
|
978
|
+
outputOptions: { includeState: true }
|
|
954
979
|
}
|
|
955
980
|
});
|
|
956
981
|
result = invokeResp.result;
|
|
957
982
|
runId = invokeResp.runId;
|
|
983
|
+
executionContext.state = invokeResp.result.state;
|
|
958
984
|
}
|
|
959
985
|
} catch (e) {
|
|
960
986
|
const errorCause = e?.cause;
|
|
@@ -1008,7 +1034,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1008
1034
|
return stepRes2?.status === "suspended";
|
|
1009
1035
|
});
|
|
1010
1036
|
for (const [stepName, stepResult] of suspendedSteps) {
|
|
1011
|
-
const suspendPath = [stepName, ...stepResult?.
|
|
1037
|
+
const suspendPath = [stepName, ...stepResult?.suspendPayload?.__workflow_meta?.path ?? []];
|
|
1012
1038
|
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
1013
1039
|
await emitter.emit("watch", {
|
|
1014
1040
|
type: "watch",
|
|
@@ -1016,7 +1042,11 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1016
1042
|
currentStep: {
|
|
1017
1043
|
id: step.id,
|
|
1018
1044
|
status: "suspended",
|
|
1019
|
-
payload:
|
|
1045
|
+
payload: stepResult.payload,
|
|
1046
|
+
suspendPayload: {
|
|
1047
|
+
...stepResult?.suspendPayload,
|
|
1048
|
+
__workflow_meta: { runId, path: suspendPath }
|
|
1049
|
+
}
|
|
1020
1050
|
},
|
|
1021
1051
|
workflowState: {
|
|
1022
1052
|
status: "running",
|
|
@@ -1038,7 +1068,11 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1038
1068
|
executionContext,
|
|
1039
1069
|
result: {
|
|
1040
1070
|
status: "suspended",
|
|
1041
|
-
payload:
|
|
1071
|
+
payload: stepResult.payload,
|
|
1072
|
+
suspendPayload: {
|
|
1073
|
+
...stepResult?.suspendPayload,
|
|
1074
|
+
__workflow_meta: { runId, path: suspendPath }
|
|
1075
|
+
}
|
|
1042
1076
|
}
|
|
1043
1077
|
};
|
|
1044
1078
|
}
|
|
@@ -1103,7 +1137,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1103
1137
|
}
|
|
1104
1138
|
);
|
|
1105
1139
|
Object.assign(executionContext, res.executionContext);
|
|
1106
|
-
return
|
|
1140
|
+
return {
|
|
1141
|
+
...res.result,
|
|
1142
|
+
startedAt,
|
|
1143
|
+
endedAt: Date.now(),
|
|
1144
|
+
payload: inputData,
|
|
1145
|
+
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1146
|
+
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1147
|
+
};
|
|
1107
1148
|
}
|
|
1108
1149
|
let stepRes;
|
|
1109
1150
|
try {
|
|
@@ -1120,6 +1161,10 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1120
1161
|
mastra: this.mastra,
|
|
1121
1162
|
runtimeContext,
|
|
1122
1163
|
writableStream,
|
|
1164
|
+
state: executionContext?.state ?? {},
|
|
1165
|
+
setState: (state) => {
|
|
1166
|
+
executionContext.state = state;
|
|
1167
|
+
},
|
|
1123
1168
|
inputData,
|
|
1124
1169
|
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1125
1170
|
tracingContext: {
|
|
@@ -1138,7 +1183,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1138
1183
|
steps: resume?.steps?.slice(1) || [],
|
|
1139
1184
|
resumePayload: resume?.resumePayload,
|
|
1140
1185
|
// @ts-ignore
|
|
1141
|
-
runId: stepResults[step.id]?.
|
|
1186
|
+
runId: stepResults[step.id]?.suspendPayload?.__workflow_meta?.runId
|
|
1142
1187
|
},
|
|
1143
1188
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1144
1189
|
engine: {
|
|
@@ -1176,7 +1221,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1176
1221
|
if (suspended) {
|
|
1177
1222
|
execResults = {
|
|
1178
1223
|
status: "suspended",
|
|
1179
|
-
|
|
1224
|
+
suspendPayload: suspended.payload,
|
|
1180
1225
|
payload: inputData,
|
|
1181
1226
|
suspendedAt: Date.now(),
|
|
1182
1227
|
startedAt,
|
|
@@ -1271,6 +1316,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1271
1316
|
}
|
|
1272
1317
|
Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
|
|
1273
1318
|
Object.assign(stepResults, stepRes.stepResults);
|
|
1319
|
+
executionContext.state = stepRes.executionContext.state;
|
|
1274
1320
|
return stepRes.result;
|
|
1275
1321
|
}
|
|
1276
1322
|
async persistStepUpdate({
|
|
@@ -1293,7 +1339,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1293
1339
|
resourceId,
|
|
1294
1340
|
snapshot: {
|
|
1295
1341
|
runId,
|
|
1296
|
-
value:
|
|
1342
|
+
value: executionContext.state,
|
|
1297
1343
|
context: stepResults,
|
|
1298
1344
|
activePaths: [],
|
|
1299
1345
|
suspendedPaths: executionContext.suspendedPaths,
|
|
@@ -1356,6 +1402,10 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1356
1402
|
runtimeContext,
|
|
1357
1403
|
runCount: -1,
|
|
1358
1404
|
inputData: prevOutput,
|
|
1405
|
+
state: executionContext.state,
|
|
1406
|
+
setState: (state) => {
|
|
1407
|
+
executionContext.state = state;
|
|
1408
|
+
},
|
|
1359
1409
|
tracingContext: {
|
|
1360
1410
|
currentSpan: evalSpan
|
|
1361
1411
|
},
|
|
@@ -1428,7 +1478,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1428
1478
|
executionPath: [...executionContext.executionPath, index],
|
|
1429
1479
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1430
1480
|
retryConfig: executionContext.retryConfig,
|
|
1431
|
-
executionSpan: executionContext.executionSpan
|
|
1481
|
+
executionSpan: executionContext.executionSpan,
|
|
1482
|
+
state: executionContext.state
|
|
1432
1483
|
},
|
|
1433
1484
|
emitter,
|
|
1434
1485
|
abortController,
|
|
@@ -1446,7 +1497,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1446
1497
|
if (hasFailed) {
|
|
1447
1498
|
execResults = { status: "failed", error: hasFailed.result.error };
|
|
1448
1499
|
} else if (hasSuspended) {
|
|
1449
|
-
execResults = { status: "suspended",
|
|
1500
|
+
execResults = { status: "suspended", suspendPayload: hasSuspended.result.suspendPayload };
|
|
1450
1501
|
} else {
|
|
1451
1502
|
execResults = {
|
|
1452
1503
|
status: "success",
|