@mastra/inngest 0.11.10 → 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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @mastra/inngest@0.11.10-alpha.0 build /home/runner/work/mastra/mastra/workflows/inngest
2
+ > @mastra/inngest@0.12.0-alpha.1 build /home/runner/work/mastra/mastra/workflows/inngest
3
3
  > tsup --silent --config tsup.config.ts
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
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
+
18
+ ## 0.11.11-alpha.0
19
+
20
+ ### Patch Changes
21
+
22
+ - [#6943](https://github.com/mastra-ai/mastra/pull/6943) [`9613558`](https://github.com/mastra-ai/mastra/commit/9613558e6475f4710e05d1be7553a32ee7bddc20) Thanks [@taofeeq-deru](https://github.com/taofeeq-deru)! - Persist to snapshot when step starts
23
+
24
+ - Updated dependencies [[`0778757`](https://github.com/mastra-ai/mastra/commit/07787570e4addbd501522037bd2542c3d9e26822), [`bf504a8`](https://github.com/mastra-ai/mastra/commit/bf504a833051f6f321d832cc7d631f3cb86d657b), [`e6f5046`](https://github.com/mastra-ai/mastra/commit/e6f50467aff317e67e8bd74c485c3fbe2a5a6db1), [`9613558`](https://github.com/mastra-ai/mastra/commit/9613558e6475f4710e05d1be7553a32ee7bddc20)]:
25
+ - @mastra/core@0.14.2-alpha.0
26
+
3
27
  ## 0.11.10
4
28
 
5
29
  ### 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,33 +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
- }) {
657
- return super.executeStep({
658
- workflowId,
659
- runId,
660
- step,
661
- stepResults,
662
- executionContext,
663
- resume,
664
- prevOutput,
665
- emitter,
666
- abortController,
667
- runtimeContext,
668
- writableStream
669
- });
670
- }
671
651
  // async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
672
652
  // await this.inngestStep.sleep(id, duration);
673
653
  // }
@@ -680,9 +660,18 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
680
660
  emitter,
681
661
  abortController,
682
662
  runtimeContext,
683
- writableStream
663
+ writableStream,
664
+ tracingContext
684
665
  }) {
685
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
+ });
686
675
  if (fn) {
687
676
  const stepCallId = crypto.randomUUID();
688
677
  duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
@@ -693,6 +682,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
693
682
  runtimeContext,
694
683
  inputData: prevOutput,
695
684
  runCount: -1,
685
+ tracingContext: {
686
+ currentSpan: sleepSpan
687
+ },
696
688
  getInitData: () => stepResults?.input,
697
689
  getStepResult: (step) => {
698
690
  if (!step?.id) {
@@ -726,8 +718,19 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
726
718
  )
727
719
  });
728
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;
729
733
  }
730
- await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
731
734
  }
732
735
  async executeSleepUntil({
733
736
  workflowId,
@@ -738,9 +741,19 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
738
741
  emitter,
739
742
  abortController,
740
743
  runtimeContext,
741
- writableStream
744
+ writableStream,
745
+ tracingContext
742
746
  }) {
743
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
+ });
744
757
  if (fn) {
745
758
  date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
746
759
  const stepCallId = crypto.randomUUID();
@@ -751,6 +764,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
751
764
  runtimeContext,
752
765
  inputData: prevOutput,
753
766
  runCount: -1,
767
+ tracingContext: {
768
+ currentSpan: sleepUntilSpan
769
+ },
754
770
  getInitData: () => stepResults?.input,
755
771
  getStepResult: (step) => {
756
772
  if (!step?.id) {
@@ -784,11 +800,24 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
784
800
  )
785
801
  });
786
802
  });
803
+ const time = !date ? 0 : date.getTime() - Date.now();
804
+ sleepUntilSpan?.update({
805
+ attributes: {
806
+ durationMs: Math.max(0, time)
807
+ }
808
+ });
787
809
  }
788
810
  if (!(date instanceof Date)) {
811
+ sleepUntilSpan?.end();
789
812
  return;
790
813
  }
791
- await this.inngestStep.sleepUntil(entry.id, date);
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
+ }
792
821
  }
793
822
  async executeWaitForEvent({ event, timeout }) {
794
823
  const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
@@ -809,8 +838,17 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
809
838
  emitter,
810
839
  abortController,
811
840
  runtimeContext,
812
- writableStream
841
+ writableStream,
842
+ tracingContext
813
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
+ });
814
852
  const startedAt = await this.inngestStep.run(
815
853
  `workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
816
854
  async () => {
@@ -1031,6 +1069,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1031
1069
  writableStream,
1032
1070
  inputData: prevOutput,
1033
1071
  resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
1072
+ tracingContext: {
1073
+ currentSpan: stepAISpan
1074
+ },
1034
1075
  getInitData: () => stepResults?.input,
1035
1076
  getStepResult: (step2) => {
1036
1077
  const result2 = stepResults[step2.id];
@@ -1094,7 +1135,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1094
1135
  }
1095
1136
  if (execResults.status === "failed") {
1096
1137
  if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
1097
- throw execResults.error;
1138
+ const error = new Error(execResults.error);
1139
+ stepAISpan?.error({ error });
1140
+ throw error;
1098
1141
  }
1099
1142
  }
1100
1143
  await emitter.emit("watch", {
@@ -1137,6 +1180,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1137
1180
  }
1138
1181
  });
1139
1182
  }
1183
+ stepAISpan?.end({ output: execResults });
1140
1184
  return { result: execResults, executionContext, stepResults };
1141
1185
  });
1142
1186
  Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
@@ -1165,6 +1209,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1165
1209
  context: stepResults,
1166
1210
  activePaths: [],
1167
1211
  suspendedPaths: executionContext.suspendedPaths,
1212
+ waitingPaths: {},
1168
1213
  serializedStepGraph,
1169
1214
  status: workflowStatus,
1170
1215
  result,
@@ -1189,12 +1234,29 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1189
1234
  emitter,
1190
1235
  abortController,
1191
1236
  runtimeContext,
1192
- writableStream
1237
+ writableStream,
1238
+ tracingContext
1193
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
+ });
1194
1248
  let execResults;
1195
1249
  const truthyIndexes = (await Promise.all(
1196
1250
  entry.conditions.map(
1197
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
+ });
1198
1260
  try {
1199
1261
  const result = await cond({
1200
1262
  runId,
@@ -1203,6 +1265,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1203
1265
  runtimeContext,
1204
1266
  runCount: -1,
1205
1267
  inputData: prevOutput,
1268
+ tracingContext: {
1269
+ currentSpan: evalSpan
1270
+ },
1206
1271
  getInitData: () => stepResults?.input,
1207
1272
  getStepResult: (step) => {
1208
1273
  if (!step?.id) {
@@ -1237,24 +1302,42 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1237
1302
  writableStream
1238
1303
  )
1239
1304
  });
1305
+ evalSpan?.end({
1306
+ output: result,
1307
+ attributes: {
1308
+ result: !!result
1309
+ }
1310
+ });
1240
1311
  return result ? index : null;
1241
1312
  } catch (e) {
1313
+ evalSpan?.error({
1314
+ error: e instanceof Error ? e : new Error(String(e)),
1315
+ attributes: {
1316
+ result: false
1317
+ }
1318
+ });
1242
1319
  return null;
1243
1320
  }
1244
1321
  })
1245
1322
  )
1246
1323
  )).filter((index) => index !== null);
1247
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
+ });
1248
1331
  const results = await Promise.all(
1249
1332
  stepsToRun.map(
1250
1333
  (step, index) => this.executeEntry({
1251
1334
  workflowId,
1252
1335
  runId,
1253
1336
  entry: step,
1337
+ serializedStepGraph,
1254
1338
  prevStep,
1255
1339
  stepResults,
1256
1340
  resume,
1257
- serializedStepGraph,
1258
1341
  executionContext: {
1259
1342
  workflowId,
1260
1343
  runId,
@@ -1266,7 +1349,10 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1266
1349
  emitter,
1267
1350
  abortController,
1268
1351
  runtimeContext,
1269
- writableStream
1352
+ writableStream,
1353
+ tracingContext: {
1354
+ currentSpan: conditionalSpan
1355
+ }
1270
1356
  })
1271
1357
  )
1272
1358
  );
@@ -1287,6 +1373,15 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
1287
1373
  }, {})
1288
1374
  };
1289
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
+ }
1290
1385
  return execResults;
1291
1386
  }
1292
1387
  };