@mastra/inngest 0.11.11-alpha.0 → 0.12.0-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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +15 -0
- package/dist/index.cjs +135 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +14 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +135 -42
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/index.test.ts +4 -2
- package/src/index.ts +166 -55
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @mastra/inngest
|
|
2
2
|
|
|
3
|
+
## 0.12.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#6971](https://github.com/mastra-ai/mastra/pull/6971) [`727f7e5`](https://github.com/mastra-ai/mastra/commit/727f7e5086e62e0dfe3356fb6dcd8bcb420af246) Thanks [@epinzur](https://github.com/epinzur)! - "updated ai tracing in workflows"
|
|
8
|
+
|
|
9
|
+
- [#7011](https://github.com/mastra-ai/mastra/pull/7011) [`4189486`](https://github.com/mastra-ai/mastra/commit/4189486c6718fda78347bdf4ce4d3fc33b2236e1) Thanks [@epinzur](https://github.com/epinzur)! - Wrapped mastra objects in workflow steps to automatically pass on tracing context
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#6996](https://github.com/mastra-ai/mastra/pull/6996) [`24d9ee3`](https://github.com/mastra-ai/mastra/commit/24d9ee3db1c09d15f27a5d0971b102abcfcf7dfd) Thanks [@wardpeet](https://github.com/wardpeet)! - Improve type resolving
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`943a7f3`](https://github.com/mastra-ai/mastra/commit/943a7f3dbc6a8ab3f9b7bc7c8a1c5b319c3d7f56), [`be49354`](https://github.com/mastra-ai/mastra/commit/be493546dca540101923ec700feb31f9a13939f2), [`d591ab3`](https://github.com/mastra-ai/mastra/commit/d591ab3ecc985c1870c0db347f8d7a20f7360536), [`ba82abe`](https://github.com/mastra-ai/mastra/commit/ba82abe76e869316bb5a9c95e8ea3946f3436fae), [`727f7e5`](https://github.com/mastra-ai/mastra/commit/727f7e5086e62e0dfe3356fb6dcd8bcb420af246), [`82d9f64`](https://github.com/mastra-ai/mastra/commit/82d9f647fbe4f0177320e7c05073fce88599aa95), [`4189486`](https://github.com/mastra-ai/mastra/commit/4189486c6718fda78347bdf4ce4d3fc33b2236e1), [`ca8ec2f`](https://github.com/mastra-ai/mastra/commit/ca8ec2f61884b9dfec5fc0d5f4f29d281ad13c01)]:
|
|
16
|
+
- @mastra/core@0.14.2-alpha.1
|
|
17
|
+
|
|
3
18
|
## 0.11.11-alpha.0
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var crypto = require('crypto');
|
|
4
4
|
var realtime = require('@inngest/realtime');
|
|
5
|
+
var aiTracing = require('@mastra/core/ai-tracing');
|
|
5
6
|
var di = require('@mastra/core/di');
|
|
6
7
|
var tools = require('@mastra/core/tools');
|
|
7
8
|
var workflows = require('@mastra/core/workflows');
|
|
@@ -106,6 +107,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
106
107
|
context: {},
|
|
107
108
|
activePaths: [],
|
|
108
109
|
suspendedPaths: {},
|
|
110
|
+
waitingPaths: {},
|
|
109
111
|
timestamp: Date.now(),
|
|
110
112
|
status: "running"
|
|
111
113
|
}
|
|
@@ -342,6 +344,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
342
344
|
value: {},
|
|
343
345
|
context: {},
|
|
344
346
|
activePaths: [],
|
|
347
|
+
waitingPaths: {},
|
|
345
348
|
serializedStepGraph: this.serializedStepGraph,
|
|
346
349
|
suspendedPaths: {},
|
|
347
350
|
result: void 0,
|
|
@@ -406,7 +409,9 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
406
409
|
runtimeContext: new di.RuntimeContext(),
|
|
407
410
|
// TODO
|
|
408
411
|
resume,
|
|
409
|
-
abortController: new AbortController()
|
|
412
|
+
abortController: new AbortController(),
|
|
413
|
+
currentSpan: void 0
|
|
414
|
+
// TODO: Pass actual parent AI span from workflow execution context
|
|
410
415
|
});
|
|
411
416
|
return { result, runId };
|
|
412
417
|
}
|
|
@@ -450,7 +455,7 @@ function createStep(params) {
|
|
|
450
455
|
outputSchema: zod.z.object({
|
|
451
456
|
text: zod.z.string()
|
|
452
457
|
}),
|
|
453
|
-
execute: async ({ inputData, [_constants.EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort }) => {
|
|
458
|
+
execute: async ({ inputData, [_constants.EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort, tracingContext }) => {
|
|
454
459
|
let streamPromise = {};
|
|
455
460
|
streamPromise.promise = new Promise((resolve, reject) => {
|
|
456
461
|
streamPromise.resolve = resolve;
|
|
@@ -468,6 +473,7 @@ function createStep(params) {
|
|
|
468
473
|
// resourceId: inputData.resourceId,
|
|
469
474
|
// threadId: inputData.threadId,
|
|
470
475
|
runtimeContext,
|
|
476
|
+
tracingContext,
|
|
471
477
|
onFinish: (result) => {
|
|
472
478
|
streamPromise.resolve(result.text);
|
|
473
479
|
},
|
|
@@ -516,11 +522,12 @@ function createStep(params) {
|
|
|
516
522
|
id: params.id,
|
|
517
523
|
inputSchema: params.inputSchema,
|
|
518
524
|
outputSchema: params.outputSchema,
|
|
519
|
-
execute: async ({ inputData, mastra, runtimeContext }) => {
|
|
525
|
+
execute: async ({ inputData, mastra, runtimeContext, tracingContext }) => {
|
|
520
526
|
return params.execute({
|
|
521
527
|
context: inputData,
|
|
522
|
-
mastra,
|
|
523
|
-
runtimeContext
|
|
528
|
+
mastra: aiTracing.wrapMastra(mastra, tracingContext),
|
|
529
|
+
runtimeContext,
|
|
530
|
+
tracingContext
|
|
524
531
|
});
|
|
525
532
|
}
|
|
526
533
|
};
|
|
@@ -641,35 +648,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
641
648
|
executionSpan?.end();
|
|
642
649
|
return base;
|
|
643
650
|
}
|
|
644
|
-
async superExecuteStep({
|
|
645
|
-
workflowId,
|
|
646
|
-
runId,
|
|
647
|
-
step,
|
|
648
|
-
stepResults,
|
|
649
|
-
executionContext,
|
|
650
|
-
resume,
|
|
651
|
-
prevOutput,
|
|
652
|
-
emitter,
|
|
653
|
-
abortController,
|
|
654
|
-
runtimeContext,
|
|
655
|
-
writableStream,
|
|
656
|
-
serializedStepGraph
|
|
657
|
-
}) {
|
|
658
|
-
return super.executeStep({
|
|
659
|
-
workflowId,
|
|
660
|
-
runId,
|
|
661
|
-
step,
|
|
662
|
-
stepResults,
|
|
663
|
-
executionContext,
|
|
664
|
-
resume,
|
|
665
|
-
prevOutput,
|
|
666
|
-
emitter,
|
|
667
|
-
abortController,
|
|
668
|
-
runtimeContext,
|
|
669
|
-
writableStream,
|
|
670
|
-
serializedStepGraph
|
|
671
|
-
});
|
|
672
|
-
}
|
|
673
651
|
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
674
652
|
// await this.inngestStep.sleep(id, duration);
|
|
675
653
|
// }
|
|
@@ -682,9 +660,18 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
682
660
|
emitter,
|
|
683
661
|
abortController,
|
|
684
662
|
runtimeContext,
|
|
685
|
-
writableStream
|
|
663
|
+
writableStream,
|
|
664
|
+
tracingContext
|
|
686
665
|
}) {
|
|
687
666
|
let { duration, fn } = entry;
|
|
667
|
+
const sleepSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
668
|
+
type: aiTracing.AISpanType.WORKFLOW_SLEEP,
|
|
669
|
+
name: `sleep: ${duration ? `${duration}ms` : "dynamic"}`,
|
|
670
|
+
attributes: {
|
|
671
|
+
durationMs: duration,
|
|
672
|
+
sleepType: fn ? "dynamic" : "fixed"
|
|
673
|
+
}
|
|
674
|
+
});
|
|
688
675
|
if (fn) {
|
|
689
676
|
const stepCallId = crypto.randomUUID();
|
|
690
677
|
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
@@ -695,6 +682,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
695
682
|
runtimeContext,
|
|
696
683
|
inputData: prevOutput,
|
|
697
684
|
runCount: -1,
|
|
685
|
+
tracingContext: {
|
|
686
|
+
currentSpan: sleepSpan
|
|
687
|
+
},
|
|
698
688
|
getInitData: () => stepResults?.input,
|
|
699
689
|
getStepResult: (step) => {
|
|
700
690
|
if (!step?.id) {
|
|
@@ -728,8 +718,19 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
728
718
|
)
|
|
729
719
|
});
|
|
730
720
|
});
|
|
721
|
+
sleepSpan?.update({
|
|
722
|
+
attributes: {
|
|
723
|
+
durationMs: duration
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
try {
|
|
728
|
+
await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
|
|
729
|
+
sleepSpan?.end();
|
|
730
|
+
} catch (e) {
|
|
731
|
+
sleepSpan?.error({ error: e });
|
|
732
|
+
throw e;
|
|
731
733
|
}
|
|
732
|
-
await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
|
|
733
734
|
}
|
|
734
735
|
async executeSleepUntil({
|
|
735
736
|
workflowId,
|
|
@@ -740,9 +741,19 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
740
741
|
emitter,
|
|
741
742
|
abortController,
|
|
742
743
|
runtimeContext,
|
|
743
|
-
writableStream
|
|
744
|
+
writableStream,
|
|
745
|
+
tracingContext
|
|
744
746
|
}) {
|
|
745
747
|
let { date, fn } = entry;
|
|
748
|
+
const sleepUntilSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
749
|
+
type: aiTracing.AISpanType.WORKFLOW_SLEEP,
|
|
750
|
+
name: `sleepUntil: ${date ? date.toISOString() : "dynamic"}`,
|
|
751
|
+
attributes: {
|
|
752
|
+
untilDate: date,
|
|
753
|
+
durationMs: date ? Math.max(0, date.getTime() - Date.now()) : void 0,
|
|
754
|
+
sleepType: fn ? "dynamic" : "fixed"
|
|
755
|
+
}
|
|
756
|
+
});
|
|
746
757
|
if (fn) {
|
|
747
758
|
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
748
759
|
const stepCallId = crypto.randomUUID();
|
|
@@ -753,6 +764,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
753
764
|
runtimeContext,
|
|
754
765
|
inputData: prevOutput,
|
|
755
766
|
runCount: -1,
|
|
767
|
+
tracingContext: {
|
|
768
|
+
currentSpan: sleepUntilSpan
|
|
769
|
+
},
|
|
756
770
|
getInitData: () => stepResults?.input,
|
|
757
771
|
getStepResult: (step) => {
|
|
758
772
|
if (!step?.id) {
|
|
@@ -786,11 +800,24 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
786
800
|
)
|
|
787
801
|
});
|
|
788
802
|
});
|
|
803
|
+
const time = !date ? 0 : date.getTime() - Date.now();
|
|
804
|
+
sleepUntilSpan?.update({
|
|
805
|
+
attributes: {
|
|
806
|
+
durationMs: Math.max(0, time)
|
|
807
|
+
}
|
|
808
|
+
});
|
|
789
809
|
}
|
|
790
810
|
if (!(date instanceof Date)) {
|
|
811
|
+
sleepUntilSpan?.end();
|
|
791
812
|
return;
|
|
792
813
|
}
|
|
793
|
-
|
|
814
|
+
try {
|
|
815
|
+
await this.inngestStep.sleepUntil(entry.id, date);
|
|
816
|
+
sleepUntilSpan?.end();
|
|
817
|
+
} catch (e) {
|
|
818
|
+
sleepUntilSpan?.error({ error: e });
|
|
819
|
+
throw e;
|
|
820
|
+
}
|
|
794
821
|
}
|
|
795
822
|
async executeWaitForEvent({ event, timeout }) {
|
|
796
823
|
const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
|
|
@@ -811,8 +838,17 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
811
838
|
emitter,
|
|
812
839
|
abortController,
|
|
813
840
|
runtimeContext,
|
|
814
|
-
writableStream
|
|
841
|
+
writableStream,
|
|
842
|
+
tracingContext
|
|
815
843
|
}) {
|
|
844
|
+
const stepAISpan = tracingContext?.currentSpan?.createChildSpan({
|
|
845
|
+
name: `workflow step: '${step.id}'`,
|
|
846
|
+
type: aiTracing.AISpanType.WORKFLOW_STEP,
|
|
847
|
+
input: prevOutput,
|
|
848
|
+
attributes: {
|
|
849
|
+
stepId: step.id
|
|
850
|
+
}
|
|
851
|
+
});
|
|
816
852
|
const startedAt = await this.inngestStep.run(
|
|
817
853
|
`workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
|
|
818
854
|
async () => {
|
|
@@ -1033,6 +1069,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1033
1069
|
writableStream,
|
|
1034
1070
|
inputData: prevOutput,
|
|
1035
1071
|
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1072
|
+
tracingContext: {
|
|
1073
|
+
currentSpan: stepAISpan
|
|
1074
|
+
},
|
|
1036
1075
|
getInitData: () => stepResults?.input,
|
|
1037
1076
|
getStepResult: (step2) => {
|
|
1038
1077
|
const result2 = stepResults[step2.id];
|
|
@@ -1096,7 +1135,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1096
1135
|
}
|
|
1097
1136
|
if (execResults.status === "failed") {
|
|
1098
1137
|
if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
|
|
1099
|
-
|
|
1138
|
+
const error = new Error(execResults.error);
|
|
1139
|
+
stepAISpan?.error({ error });
|
|
1140
|
+
throw error;
|
|
1100
1141
|
}
|
|
1101
1142
|
}
|
|
1102
1143
|
await emitter.emit("watch", {
|
|
@@ -1139,6 +1180,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1139
1180
|
}
|
|
1140
1181
|
});
|
|
1141
1182
|
}
|
|
1183
|
+
stepAISpan?.end({ output: execResults });
|
|
1142
1184
|
return { result: execResults, executionContext, stepResults };
|
|
1143
1185
|
});
|
|
1144
1186
|
Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
|
|
@@ -1167,6 +1209,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1167
1209
|
context: stepResults,
|
|
1168
1210
|
activePaths: [],
|
|
1169
1211
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1212
|
+
waitingPaths: {},
|
|
1170
1213
|
serializedStepGraph,
|
|
1171
1214
|
status: workflowStatus,
|
|
1172
1215
|
result,
|
|
@@ -1191,12 +1234,29 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1191
1234
|
emitter,
|
|
1192
1235
|
abortController,
|
|
1193
1236
|
runtimeContext,
|
|
1194
|
-
writableStream
|
|
1237
|
+
writableStream,
|
|
1238
|
+
tracingContext
|
|
1195
1239
|
}) {
|
|
1240
|
+
const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
1241
|
+
type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL,
|
|
1242
|
+
name: `conditional: ${entry.conditions.length} conditions`,
|
|
1243
|
+
input: prevOutput,
|
|
1244
|
+
attributes: {
|
|
1245
|
+
conditionCount: entry.conditions.length
|
|
1246
|
+
}
|
|
1247
|
+
});
|
|
1196
1248
|
let execResults;
|
|
1197
1249
|
const truthyIndexes = (await Promise.all(
|
|
1198
1250
|
entry.conditions.map(
|
|
1199
1251
|
(cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
|
|
1252
|
+
const evalSpan = conditionalSpan?.createChildSpan({
|
|
1253
|
+
type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL_EVAL,
|
|
1254
|
+
name: `condition ${index}`,
|
|
1255
|
+
input: prevOutput,
|
|
1256
|
+
attributes: {
|
|
1257
|
+
conditionIndex: index
|
|
1258
|
+
}
|
|
1259
|
+
});
|
|
1200
1260
|
try {
|
|
1201
1261
|
const result = await cond({
|
|
1202
1262
|
runId,
|
|
@@ -1205,6 +1265,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1205
1265
|
runtimeContext,
|
|
1206
1266
|
runCount: -1,
|
|
1207
1267
|
inputData: prevOutput,
|
|
1268
|
+
tracingContext: {
|
|
1269
|
+
currentSpan: evalSpan
|
|
1270
|
+
},
|
|
1208
1271
|
getInitData: () => stepResults?.input,
|
|
1209
1272
|
getStepResult: (step) => {
|
|
1210
1273
|
if (!step?.id) {
|
|
@@ -1239,14 +1302,32 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1239
1302
|
writableStream
|
|
1240
1303
|
)
|
|
1241
1304
|
});
|
|
1305
|
+
evalSpan?.end({
|
|
1306
|
+
output: result,
|
|
1307
|
+
attributes: {
|
|
1308
|
+
result: !!result
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1242
1311
|
return result ? index : null;
|
|
1243
1312
|
} catch (e) {
|
|
1313
|
+
evalSpan?.error({
|
|
1314
|
+
error: e instanceof Error ? e : new Error(String(e)),
|
|
1315
|
+
attributes: {
|
|
1316
|
+
result: false
|
|
1317
|
+
}
|
|
1318
|
+
});
|
|
1244
1319
|
return null;
|
|
1245
1320
|
}
|
|
1246
1321
|
})
|
|
1247
1322
|
)
|
|
1248
1323
|
)).filter((index) => index !== null);
|
|
1249
1324
|
const stepsToRun = entry.steps.filter((_, index) => truthyIndexes.includes(index));
|
|
1325
|
+
conditionalSpan?.update({
|
|
1326
|
+
attributes: {
|
|
1327
|
+
truthyIndexes,
|
|
1328
|
+
selectedSteps: stepsToRun.map((s) => s.type === "step" ? s.step.id : `control-${s.type}`)
|
|
1329
|
+
}
|
|
1330
|
+
});
|
|
1250
1331
|
const results = await Promise.all(
|
|
1251
1332
|
stepsToRun.map(
|
|
1252
1333
|
(step, index) => this.executeEntry({
|
|
@@ -1268,7 +1349,10 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1268
1349
|
emitter,
|
|
1269
1350
|
abortController,
|
|
1270
1351
|
runtimeContext,
|
|
1271
|
-
writableStream
|
|
1352
|
+
writableStream,
|
|
1353
|
+
tracingContext: {
|
|
1354
|
+
currentSpan: conditionalSpan
|
|
1355
|
+
}
|
|
1272
1356
|
})
|
|
1273
1357
|
)
|
|
1274
1358
|
);
|
|
@@ -1289,6 +1373,15 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1289
1373
|
}, {})
|
|
1290
1374
|
};
|
|
1291
1375
|
}
|
|
1376
|
+
if (execResults.status === "failed") {
|
|
1377
|
+
conditionalSpan?.error({
|
|
1378
|
+
error: new Error(execResults.error)
|
|
1379
|
+
});
|
|
1380
|
+
} else {
|
|
1381
|
+
conditionalSpan?.end({
|
|
1382
|
+
output: execResults.output || execResults
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1292
1385
|
return execResults;
|
|
1293
1386
|
}
|
|
1294
1387
|
};
|