@mastra/inngest 0.0.0-new-scorer-api-20250801075530 → 0.0.0-pgvector-index-fix-20250905222058

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/dist/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { randomUUID } from 'crypto';
2
2
  import { subscribe } from '@inngest/realtime';
3
+ import { wrapMastra, AISpanType } from '@mastra/core/ai-tracing';
3
4
  import { RuntimeContext } from '@mastra/core/di';
4
5
  import { ToolStream, Tool } from '@mastra/core/tools';
5
6
  import { Run, Workflow, DefaultExecutionEngine } from '@mastra/core/workflows';
6
- import { EMITTER_SYMBOL } from '@mastra/core/workflows/_constants';
7
+ import { EMITTER_SYMBOL, STREAM_FORMAT_SYMBOL } from '@mastra/core/workflows/_constants';
7
8
  import { serve as serve$1 } from 'inngest/hono';
8
9
  import { z } from 'zod';
9
10
 
@@ -104,6 +105,7 @@ var InngestRun = class extends Run {
104
105
  context: {},
105
106
  activePaths: [],
106
107
  suspendedPaths: {},
108
+ waitingPaths: {},
107
109
  timestamp: Date.now(),
108
110
  status: "running"
109
111
  }
@@ -200,10 +202,38 @@ var InngestRun = class extends Run {
200
202
  }
201
203
  stream({ inputData, runtimeContext } = {}) {
202
204
  const { readable, writable } = new TransformStream();
205
+ let currentToolData = void 0;
203
206
  const writer = writable.getWriter();
204
207
  const unwatch = this.watch(async (event) => {
208
+ if (event.type === "workflow-agent-call-start") {
209
+ currentToolData = {
210
+ name: event.payload.name,
211
+ args: event.payload.args
212
+ };
213
+ await writer.write({
214
+ ...event.payload,
215
+ type: "tool-call-streaming-start"
216
+ });
217
+ return;
218
+ }
205
219
  try {
206
- await writer.write(event);
220
+ if (event.type === "workflow-agent-call-finish") {
221
+ return;
222
+ } else if (!event.type.startsWith("workflow-")) {
223
+ if (event.type === "text-delta") {
224
+ await writer.write({
225
+ type: "tool-call-delta",
226
+ ...currentToolData ?? {},
227
+ argsTextDelta: event.textDelta
228
+ });
229
+ }
230
+ return;
231
+ }
232
+ const e = {
233
+ ...event,
234
+ type: event.type.replace("workflow-", "")
235
+ };
236
+ await writer.write(e);
207
237
  } catch {
208
238
  }
209
239
  }, "watch-v2");
@@ -234,8 +264,14 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
234
264
  #mastra;
235
265
  inngest;
236
266
  function;
267
+ flowControlConfig;
237
268
  constructor(params, inngest) {
238
- super(params);
269
+ const { concurrency, rateLimit, throttle, debounce, priority, ...workflowParams } = params;
270
+ super(workflowParams);
271
+ const flowControlEntries = Object.entries({ concurrency, rateLimit, throttle, debounce, priority }).filter(
272
+ ([_, value]) => value !== void 0
273
+ );
274
+ this.flowControlConfig = flowControlEntries.length > 0 ? Object.fromEntries(flowControlEntries) : void 0;
239
275
  this.#mastra = params.mastra;
240
276
  this.inngest = inngest;
241
277
  }
@@ -256,27 +292,6 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
256
292
  const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
257
293
  return run ?? (this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null);
258
294
  }
259
- async getWorkflowRunExecutionResult(runId) {
260
- const storage = this.#mastra?.getStorage();
261
- if (!storage) {
262
- this.logger.debug("Cannot get workflow run execution result. Mastra storage is not initialized");
263
- return null;
264
- }
265
- const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
266
- if (!run?.snapshot) {
267
- return null;
268
- }
269
- if (typeof run.snapshot === "string") {
270
- return null;
271
- }
272
- return {
273
- status: run.snapshot.status,
274
- result: run.snapshot.result,
275
- error: run.snapshot.error,
276
- payload: run.snapshot.context?.input,
277
- steps: run.snapshot.context
278
- };
279
- }
280
295
  __registerMastra(mastra) {
281
296
  this.#mastra = mastra;
282
297
  this.executionEngine.__registerMastra(mastra);
@@ -329,7 +344,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
329
344
  this.inngest
330
345
  );
331
346
  this.runs.set(runIdToUse, run);
332
- const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse);
347
+ const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, false);
333
348
  if (!workflowSnapshotInStorage) {
334
349
  await this.mastra?.getStorage()?.persistWorkflowSnapshot({
335
350
  workflowName: this.id,
@@ -340,6 +355,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
340
355
  value: {},
341
356
  context: {},
342
357
  activePaths: [],
358
+ waitingPaths: {},
343
359
  serializedStepGraph: this.serializedStepGraph,
344
360
  suspendedPaths: {},
345
361
  result: void 0,
@@ -360,7 +376,9 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
360
376
  id: `workflow.${this.id}`,
361
377
  // @ts-ignore
362
378
  retries: this.retryConfig?.attempts ?? 0,
363
- cancelOn: [{ event: `cancel.workflow.${this.id}` }]
379
+ cancelOn: [{ event: `cancel.workflow.${this.id}` }],
380
+ // Spread flow control configuration
381
+ ...this.flowControlConfig
364
382
  },
365
383
  { event: `workflow.${this.id}` },
366
384
  async ({ event, step, attempt, publish }) => {
@@ -404,7 +422,9 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
404
422
  runtimeContext: new RuntimeContext(),
405
423
  // TODO
406
424
  resume,
407
- abortController: new AbortController()
425
+ abortController: new AbortController(),
426
+ currentSpan: void 0
427
+ // TODO: Pass actual parent AI span from workflow execution context
408
428
  });
409
429
  return { result, runId };
410
430
  }
@@ -448,7 +468,7 @@ function createStep(params) {
448
468
  outputSchema: z.object({
449
469
  text: z.string()
450
470
  }),
451
- execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort }) => {
471
+ execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort, tracingContext }) => {
452
472
  let streamPromise = {};
453
473
  streamPromise.promise = new Promise((resolve, reject) => {
454
474
  streamPromise.resolve = resolve;
@@ -459,13 +479,14 @@ function createStep(params) {
459
479
  args: inputData
460
480
  };
461
481
  await emitter.emit("watch-v2", {
462
- type: "tool-call-streaming-start",
463
- ...toolData
482
+ type: "workflow-agent-call-start",
483
+ payload: toolData
464
484
  });
465
485
  const { fullStream } = await params.stream(inputData.prompt, {
466
486
  // resourceId: inputData.resourceId,
467
487
  // threadId: inputData.threadId,
468
488
  runtimeContext,
489
+ tracingContext,
469
490
  onFinish: (result) => {
470
491
  streamPromise.resolve(result.text);
471
492
  },
@@ -475,29 +496,12 @@ function createStep(params) {
475
496
  return abort();
476
497
  }
477
498
  for await (const chunk of fullStream) {
478
- switch (chunk.type) {
479
- case "text-delta":
480
- await emitter.emit("watch-v2", {
481
- type: "tool-call-delta",
482
- ...toolData,
483
- argsTextDelta: chunk.textDelta
484
- });
485
- break;
486
- case "step-start":
487
- case "step-finish":
488
- case "finish":
489
- break;
490
- case "tool-call":
491
- case "tool-result":
492
- case "tool-call-streaming-start":
493
- case "tool-call-delta":
494
- case "source":
495
- case "file":
496
- default:
497
- await emitter.emit("watch-v2", chunk);
498
- break;
499
- }
499
+ await emitter.emit("watch-v2", chunk);
500
500
  }
501
+ await emitter.emit("watch-v2", {
502
+ type: "workflow-agent-call-finish",
503
+ payload: toolData
504
+ });
501
505
  return {
502
506
  text: await streamPromise.promise
503
507
  };
@@ -514,11 +518,12 @@ function createStep(params) {
514
518
  id: params.id,
515
519
  inputSchema: params.inputSchema,
516
520
  outputSchema: params.outputSchema,
517
- execute: async ({ inputData, mastra, runtimeContext }) => {
521
+ execute: async ({ inputData, mastra, runtimeContext, tracingContext }) => {
518
522
  return params.execute({
519
523
  context: inputData,
520
- mastra,
521
- runtimeContext
524
+ mastra: wrapMastra(mastra, tracingContext),
525
+ runtimeContext,
526
+ tracingContext
522
527
  });
523
528
  }
524
529
  };
@@ -572,12 +577,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
572
577
  }
573
578
  async execute(params) {
574
579
  await params.emitter.emit("watch-v2", {
575
- type: "start",
580
+ type: "workflow-start",
576
581
  payload: { runId: params.runId }
577
582
  });
578
583
  const result = await super.execute(params);
579
584
  await params.emitter.emit("watch-v2", {
580
- type: "finish",
585
+ type: "workflow-finish",
581
586
  payload: { runId: params.runId }
582
587
  });
583
588
  return result;
@@ -639,33 +644,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
639
644
  executionSpan?.end();
640
645
  return base;
641
646
  }
642
- async superExecuteStep({
643
- workflowId,
644
- runId,
645
- step,
646
- stepResults,
647
- executionContext,
648
- resume,
649
- prevOutput,
650
- emitter,
651
- abortController,
652
- runtimeContext,
653
- writableStream
654
- }) {
655
- return super.executeStep({
656
- workflowId,
657
- runId,
658
- step,
659
- stepResults,
660
- executionContext,
661
- resume,
662
- prevOutput,
663
- emitter,
664
- abortController,
665
- runtimeContext,
666
- writableStream
667
- });
668
- }
669
647
  // async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
670
648
  // await this.inngestStep.sleep(id, duration);
671
649
  // }
@@ -678,9 +656,19 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
678
656
  emitter,
679
657
  abortController,
680
658
  runtimeContext,
681
- writableStream
659
+ executionContext,
660
+ writableStream,
661
+ tracingContext
682
662
  }) {
683
663
  let { duration, fn } = entry;
664
+ const sleepSpan = tracingContext?.currentSpan?.createChildSpan({
665
+ type: AISpanType.WORKFLOW_SLEEP,
666
+ name: `sleep: ${duration ? `${duration}ms` : "dynamic"}`,
667
+ attributes: {
668
+ durationMs: duration,
669
+ sleepType: fn ? "dynamic" : "fixed"
670
+ }
671
+ });
684
672
  if (fn) {
685
673
  const stepCallId = randomUUID();
686
674
  duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
@@ -691,6 +679,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
691
679
  runtimeContext,
692
680
  inputData: prevOutput,
693
681
  runCount: -1,
682
+ tracingContext: {
683
+ currentSpan: sleepSpan
684
+ },
694
685
  getInitData: () => stepResults?.input,
695
686
  getStepResult: (step) => {
696
687
  if (!step?.id) {
@@ -711,11 +702,13 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
711
702
  abortController?.abort();
712
703
  },
713
704
  [EMITTER_SYMBOL]: emitter,
705
+ // TODO: add streamVNext support
706
+ [STREAM_FORMAT_SYMBOL]: executionContext.format,
714
707
  engine: { step: this.inngestStep },
715
708
  abortSignal: abortController?.signal,
716
709
  writer: new ToolStream(
717
710
  {
718
- prefix: "step",
711
+ prefix: "workflow-step",
719
712
  callId: stepCallId,
720
713
  name: "sleep",
721
714
  runId
@@ -724,8 +717,19 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
724
717
  )
725
718
  });
726
719
  });
720
+ sleepSpan?.update({
721
+ attributes: {
722
+ durationMs: duration
723
+ }
724
+ });
725
+ }
726
+ try {
727
+ await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
728
+ sleepSpan?.end();
729
+ } catch (e) {
730
+ sleepSpan?.error({ error: e });
731
+ throw e;
727
732
  }
728
- await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
729
733
  }
730
734
  async executeSleepUntil({
731
735
  workflowId,
@@ -736,9 +740,20 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
736
740
  emitter,
737
741
  abortController,
738
742
  runtimeContext,
739
- writableStream
743
+ executionContext,
744
+ writableStream,
745
+ tracingContext
740
746
  }) {
741
747
  let { date, fn } = entry;
748
+ const sleepUntilSpan = tracingContext?.currentSpan?.createChildSpan({
749
+ type: 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
+ });
742
757
  if (fn) {
743
758
  date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
744
759
  const stepCallId = randomUUID();
@@ -749,6 +764,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
749
764
  runtimeContext,
750
765
  inputData: prevOutput,
751
766
  runCount: -1,
767
+ tracingContext: {
768
+ currentSpan: sleepUntilSpan
769
+ },
752
770
  getInitData: () => stepResults?.input,
753
771
  getStepResult: (step) => {
754
772
  if (!step?.id) {
@@ -769,11 +787,13 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
769
787
  abortController?.abort();
770
788
  },
771
789
  [EMITTER_SYMBOL]: emitter,
790
+ [STREAM_FORMAT_SYMBOL]: executionContext.format,
791
+ // TODO: add streamVNext support
772
792
  engine: { step: this.inngestStep },
773
793
  abortSignal: abortController?.signal,
774
794
  writer: new ToolStream(
775
795
  {
776
- prefix: "step",
796
+ prefix: "workflow-step",
777
797
  callId: stepCallId,
778
798
  name: "sleep",
779
799
  runId
@@ -782,11 +802,24 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
782
802
  )
783
803
  });
784
804
  });
805
+ const time = !date ? 0 : date.getTime() - Date.now();
806
+ sleepUntilSpan?.update({
807
+ attributes: {
808
+ durationMs: Math.max(0, time)
809
+ }
810
+ });
785
811
  }
786
812
  if (!(date instanceof Date)) {
813
+ sleepUntilSpan?.end();
787
814
  return;
788
815
  }
789
- await this.inngestStep.sleepUntil(entry.id, date);
816
+ try {
817
+ await this.inngestStep.sleepUntil(entry.id, date);
818
+ sleepUntilSpan?.end();
819
+ } catch (e) {
820
+ sleepUntilSpan?.error({ error: e });
821
+ throw e;
822
+ }
790
823
  }
791
824
  async executeWaitForEvent({ event, timeout }) {
792
825
  const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
@@ -807,8 +840,18 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
807
840
  emitter,
808
841
  abortController,
809
842
  runtimeContext,
810
- writableStream
843
+ tracingContext,
844
+ writableStream,
845
+ disableScorers
811
846
  }) {
847
+ const stepAISpan = tracingContext?.currentSpan?.createChildSpan({
848
+ name: `workflow step: '${step.id}'`,
849
+ type: AISpanType.WORKFLOW_STEP,
850
+ input: prevOutput,
851
+ attributes: {
852
+ stepId: step.id
853
+ }
854
+ });
812
855
  const startedAt = await this.inngestStep.run(
813
856
  `workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
814
857
  async () => {
@@ -835,7 +878,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
835
878
  eventTimestamp: Date.now()
836
879
  });
837
880
  await emitter.emit("watch-v2", {
838
- type: "step-start",
881
+ type: "workflow-step-start",
839
882
  payload: {
840
883
  id: step.id,
841
884
  status: "running",
@@ -905,7 +948,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
905
948
  eventTimestamp: Date.now()
906
949
  });
907
950
  await emitter.emit("watch-v2", {
908
- type: "step-result",
951
+ type: "workflow-step-result",
909
952
  payload: {
910
953
  id: step.id,
911
954
  status: "failed",
@@ -940,7 +983,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
940
983
  eventTimestamp: Date.now()
941
984
  });
942
985
  await emitter.emit("watch-v2", {
943
- type: "step-suspended",
986
+ type: "workflow-step-suspended",
944
987
  payload: {
945
988
  id: step.id,
946
989
  status: "suspended"
@@ -997,7 +1040,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
997
1040
  eventTimestamp: Date.now()
998
1041
  });
999
1042
  await emitter.emit("watch-v2", {
1000
- type: "step-result",
1043
+ type: "workflow-step-result",
1001
1044
  payload: {
1002
1045
  id: step.id,
1003
1046
  status: "success",
@@ -1005,7 +1048,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1005
1048
  }
1006
1049
  });
1007
1050
  await emitter.emit("watch-v2", {
1008
- type: "step-finish",
1051
+ type: "workflow-step-finish",
1009
1052
  payload: {
1010
1053
  id: step.id,
1011
1054
  metadata: {}
@@ -1029,6 +1072,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1029
1072
  writableStream,
1030
1073
  inputData: prevOutput,
1031
1074
  resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
1075
+ tracingContext: {
1076
+ currentSpan: stepAISpan
1077
+ },
1032
1078
  getInitData: () => stepResults?.input,
1033
1079
  getStepResult: (step2) => {
1034
1080
  const result2 = stepResults[step2.id];
@@ -1092,7 +1138,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1092
1138
  }
1093
1139
  if (execResults.status === "failed") {
1094
1140
  if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
1095
- throw execResults.error;
1141
+ const error = new Error(execResults.error);
1142
+ stepAISpan?.error({ error });
1143
+ throw error;
1096
1144
  }
1097
1145
  }
1098
1146
  await emitter.emit("watch", {
@@ -1113,7 +1161,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1113
1161
  });
1114
1162
  if (execResults.status === "suspended") {
1115
1163
  await emitter.emit("watch-v2", {
1116
- type: "step-suspended",
1164
+ type: "workflow-step-suspended",
1117
1165
  payload: {
1118
1166
  id: step.id,
1119
1167
  ...execResults
@@ -1121,22 +1169,40 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1121
1169
  });
1122
1170
  } else {
1123
1171
  await emitter.emit("watch-v2", {
1124
- type: "step-result",
1172
+ type: "workflow-step-result",
1125
1173
  payload: {
1126
1174
  id: step.id,
1127
1175
  ...execResults
1128
1176
  }
1129
1177
  });
1130
1178
  await emitter.emit("watch-v2", {
1131
- type: "step-finish",
1179
+ type: "workflow-step-finish",
1132
1180
  payload: {
1133
1181
  id: step.id,
1134
1182
  metadata: {}
1135
1183
  }
1136
1184
  });
1137
1185
  }
1186
+ stepAISpan?.end({ output: execResults });
1138
1187
  return { result: execResults, executionContext, stepResults };
1139
1188
  });
1189
+ if (disableScorers !== false) {
1190
+ await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}.score`, async () => {
1191
+ if (step.scorers) {
1192
+ await this.runScorers({
1193
+ scorers: step.scorers,
1194
+ runId: executionContext.runId,
1195
+ input: prevOutput,
1196
+ output: stepRes.result,
1197
+ workflowId: executionContext.workflowId,
1198
+ stepId: step.id,
1199
+ runtimeContext,
1200
+ disableScorers,
1201
+ tracingContext: { currentSpan: stepAISpan }
1202
+ });
1203
+ }
1204
+ });
1205
+ }
1140
1206
  Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
1141
1207
  Object.assign(stepResults, stepRes.stepResults);
1142
1208
  return stepRes.result;
@@ -1163,6 +1229,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1163
1229
  context: stepResults,
1164
1230
  activePaths: [],
1165
1231
  suspendedPaths: executionContext.suspendedPaths,
1232
+ waitingPaths: {},
1166
1233
  serializedStepGraph,
1167
1234
  status: workflowStatus,
1168
1235
  result,
@@ -1187,12 +1254,30 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1187
1254
  emitter,
1188
1255
  abortController,
1189
1256
  runtimeContext,
1190
- writableStream
1257
+ writableStream,
1258
+ disableScorers,
1259
+ tracingContext
1191
1260
  }) {
1261
+ const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
1262
+ type: AISpanType.WORKFLOW_CONDITIONAL,
1263
+ name: `conditional: ${entry.conditions.length} conditions`,
1264
+ input: prevOutput,
1265
+ attributes: {
1266
+ conditionCount: entry.conditions.length
1267
+ }
1268
+ });
1192
1269
  let execResults;
1193
1270
  const truthyIndexes = (await Promise.all(
1194
1271
  entry.conditions.map(
1195
1272
  (cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
1273
+ const evalSpan = conditionalSpan?.createChildSpan({
1274
+ type: AISpanType.WORKFLOW_CONDITIONAL_EVAL,
1275
+ name: `condition ${index}`,
1276
+ input: prevOutput,
1277
+ attributes: {
1278
+ conditionIndex: index
1279
+ }
1280
+ });
1196
1281
  try {
1197
1282
  const result = await cond({
1198
1283
  runId,
@@ -1201,6 +1286,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1201
1286
  runtimeContext,
1202
1287
  runCount: -1,
1203
1288
  inputData: prevOutput,
1289
+ tracingContext: {
1290
+ currentSpan: evalSpan
1291
+ },
1204
1292
  getInitData: () => stepResults?.input,
1205
1293
  getStepResult: (step) => {
1206
1294
  if (!step?.id) {
@@ -1221,13 +1309,15 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1221
1309
  abortController.abort();
1222
1310
  },
1223
1311
  [EMITTER_SYMBOL]: emitter,
1312
+ [STREAM_FORMAT_SYMBOL]: executionContext.format,
1313
+ // TODO: add streamVNext support
1224
1314
  engine: {
1225
1315
  step: this.inngestStep
1226
1316
  },
1227
1317
  abortSignal: abortController.signal,
1228
1318
  writer: new ToolStream(
1229
1319
  {
1230
- prefix: "step",
1320
+ prefix: "workflow-step",
1231
1321
  callId: randomUUID(),
1232
1322
  name: "conditional",
1233
1323
  runId
@@ -1235,24 +1325,42 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1235
1325
  writableStream
1236
1326
  )
1237
1327
  });
1328
+ evalSpan?.end({
1329
+ output: result,
1330
+ attributes: {
1331
+ result: !!result
1332
+ }
1333
+ });
1238
1334
  return result ? index : null;
1239
1335
  } catch (e) {
1336
+ evalSpan?.error({
1337
+ error: e instanceof Error ? e : new Error(String(e)),
1338
+ attributes: {
1339
+ result: false
1340
+ }
1341
+ });
1240
1342
  return null;
1241
1343
  }
1242
1344
  })
1243
1345
  )
1244
1346
  )).filter((index) => index !== null);
1245
1347
  const stepsToRun = entry.steps.filter((_, index) => truthyIndexes.includes(index));
1348
+ conditionalSpan?.update({
1349
+ attributes: {
1350
+ truthyIndexes,
1351
+ selectedSteps: stepsToRun.map((s) => s.type === "step" ? s.step.id : `control-${s.type}`)
1352
+ }
1353
+ });
1246
1354
  const results = await Promise.all(
1247
1355
  stepsToRun.map(
1248
1356
  (step, index) => this.executeEntry({
1249
1357
  workflowId,
1250
1358
  runId,
1251
1359
  entry: step,
1360
+ serializedStepGraph,
1252
1361
  prevStep,
1253
1362
  stepResults,
1254
1363
  resume,
1255
- serializedStepGraph,
1256
1364
  executionContext: {
1257
1365
  workflowId,
1258
1366
  runId,
@@ -1264,7 +1372,11 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1264
1372
  emitter,
1265
1373
  abortController,
1266
1374
  runtimeContext,
1267
- writableStream
1375
+ writableStream,
1376
+ disableScorers,
1377
+ tracingContext: {
1378
+ currentSpan: conditionalSpan
1379
+ }
1268
1380
  })
1269
1381
  )
1270
1382
  );
@@ -1285,6 +1397,15 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1285
1397
  }, {})
1286
1398
  };
1287
1399
  }
1400
+ if (execResults.status === "failed") {
1401
+ conditionalSpan?.error({
1402
+ error: new Error(execResults.error)
1403
+ });
1404
+ } else {
1405
+ conditionalSpan?.end({
1406
+ output: execResults.output || execResults
1407
+ });
1408
+ }
1288
1409
  return execResults;
1289
1410
  }
1290
1411
  };