@mastra/inngest 0.0.0-scorers-api-v2-20250801171841 → 0.0.0-scorers-ui-refactored-20250916094952

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
  }
@@ -203,7 +205,11 @@ var InngestRun = class extends Run {
203
205
  const writer = writable.getWriter();
204
206
  const unwatch = this.watch(async (event) => {
205
207
  try {
206
- await writer.write(event);
208
+ const e = {
209
+ ...event,
210
+ type: event.type.replace("workflow-", "")
211
+ };
212
+ await writer.write(e);
207
213
  } catch {
208
214
  }
209
215
  }, "watch-v2");
@@ -234,8 +240,14 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
234
240
  #mastra;
235
241
  inngest;
236
242
  function;
243
+ flowControlConfig;
237
244
  constructor(params, inngest) {
238
- super(params);
245
+ const { concurrency, rateLimit, throttle, debounce, priority, ...workflowParams } = params;
246
+ super(workflowParams);
247
+ const flowControlEntries = Object.entries({ concurrency, rateLimit, throttle, debounce, priority }).filter(
248
+ ([_, value]) => value !== void 0
249
+ );
250
+ this.flowControlConfig = flowControlEntries.length > 0 ? Object.fromEntries(flowControlEntries) : void 0;
239
251
  this.#mastra = params.mastra;
240
252
  this.inngest = inngest;
241
253
  }
@@ -256,27 +268,6 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
256
268
  const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
257
269
  return run ?? (this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null);
258
270
  }
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
271
  __registerMastra(mastra) {
281
272
  this.#mastra = mastra;
282
273
  this.executionEngine.__registerMastra(mastra);
@@ -329,7 +320,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
329
320
  this.inngest
330
321
  );
331
322
  this.runs.set(runIdToUse, run);
332
- const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse);
323
+ const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, false);
333
324
  if (!workflowSnapshotInStorage) {
334
325
  await this.mastra?.getStorage()?.persistWorkflowSnapshot({
335
326
  workflowName: this.id,
@@ -340,6 +331,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
340
331
  value: {},
341
332
  context: {},
342
333
  activePaths: [],
334
+ waitingPaths: {},
343
335
  serializedStepGraph: this.serializedStepGraph,
344
336
  suspendedPaths: {},
345
337
  result: void 0,
@@ -360,7 +352,9 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
360
352
  id: `workflow.${this.id}`,
361
353
  // @ts-ignore
362
354
  retries: this.retryConfig?.attempts ?? 0,
363
- cancelOn: [{ event: `cancel.workflow.${this.id}` }]
355
+ cancelOn: [{ event: `cancel.workflow.${this.id}` }],
356
+ // Spread flow control configuration
357
+ ...this.flowControlConfig
364
358
  },
365
359
  { event: `workflow.${this.id}` },
366
360
  async ({ event, step, attempt, publish }) => {
@@ -404,7 +398,9 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
404
398
  runtimeContext: new RuntimeContext(),
405
399
  // TODO
406
400
  resume,
407
- abortController: new AbortController()
401
+ abortController: new AbortController(),
402
+ currentSpan: void 0
403
+ // TODO: Pass actual parent AI span from workflow execution context
408
404
  });
409
405
  return { result, runId };
410
406
  }
@@ -448,7 +444,7 @@ function createStep(params) {
448
444
  outputSchema: z.object({
449
445
  text: z.string()
450
446
  }),
451
- execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort }) => {
447
+ execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort, tracingContext }) => {
452
448
  let streamPromise = {};
453
449
  streamPromise.promise = new Promise((resolve, reject) => {
454
450
  streamPromise.resolve = resolve;
@@ -458,14 +454,11 @@ function createStep(params) {
458
454
  name: params.name,
459
455
  args: inputData
460
456
  };
461
- await emitter.emit("watch-v2", {
462
- type: "tool-call-streaming-start",
463
- ...toolData
464
- });
465
457
  const { fullStream } = await params.stream(inputData.prompt, {
466
458
  // resourceId: inputData.resourceId,
467
459
  // threadId: inputData.threadId,
468
460
  runtimeContext,
461
+ tracingContext,
469
462
  onFinish: (result) => {
470
463
  streamPromise.resolve(result.text);
471
464
  },
@@ -474,30 +467,23 @@ function createStep(params) {
474
467
  if (abortSignal.aborted) {
475
468
  return abort();
476
469
  }
470
+ await emitter.emit("watch-v2", {
471
+ type: "tool-call-streaming-start",
472
+ ...toolData ?? {}
473
+ });
477
474
  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;
475
+ if (chunk.type === "text-delta") {
476
+ await emitter.emit("watch-v2", {
477
+ type: "tool-call-delta",
478
+ ...toolData ?? {},
479
+ argsTextDelta: chunk.textDelta
480
+ });
499
481
  }
500
482
  }
483
+ await emitter.emit("watch-v2", {
484
+ type: "tool-call-streaming-finish",
485
+ ...toolData ?? {}
486
+ });
501
487
  return {
502
488
  text: await streamPromise.promise
503
489
  };
@@ -514,11 +500,12 @@ function createStep(params) {
514
500
  id: params.id,
515
501
  inputSchema: params.inputSchema,
516
502
  outputSchema: params.outputSchema,
517
- execute: async ({ inputData, mastra, runtimeContext }) => {
503
+ execute: async ({ inputData, mastra, runtimeContext, tracingContext }) => {
518
504
  return params.execute({
519
505
  context: inputData,
520
- mastra,
521
- runtimeContext
506
+ mastra: wrapMastra(mastra, tracingContext),
507
+ runtimeContext,
508
+ tracingContext
522
509
  });
523
510
  }
524
511
  };
@@ -572,12 +559,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
572
559
  }
573
560
  async execute(params) {
574
561
  await params.emitter.emit("watch-v2", {
575
- type: "start",
562
+ type: "workflow-start",
576
563
  payload: { runId: params.runId }
577
564
  });
578
565
  const result = await super.execute(params);
579
566
  await params.emitter.emit("watch-v2", {
580
- type: "finish",
567
+ type: "workflow-finish",
581
568
  payload: { runId: params.runId }
582
569
  });
583
570
  return result;
@@ -639,33 +626,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
639
626
  executionSpan?.end();
640
627
  return base;
641
628
  }
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
629
  // async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
670
630
  // await this.inngestStep.sleep(id, duration);
671
631
  // }
@@ -678,9 +638,20 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
678
638
  emitter,
679
639
  abortController,
680
640
  runtimeContext,
681
- writableStream
641
+ executionContext,
642
+ writableStream,
643
+ tracingContext
682
644
  }) {
683
645
  let { duration, fn } = entry;
646
+ const sleepSpan = tracingContext?.currentSpan?.createChildSpan({
647
+ type: AISpanType.WORKFLOW_SLEEP,
648
+ name: `sleep: ${duration ? `${duration}ms` : "dynamic"}`,
649
+ attributes: {
650
+ durationMs: duration,
651
+ sleepType: fn ? "dynamic" : "fixed"
652
+ },
653
+ isInternal: tracingContext?.isInternal
654
+ });
684
655
  if (fn) {
685
656
  const stepCallId = randomUUID();
686
657
  duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
@@ -691,6 +662,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
691
662
  runtimeContext,
692
663
  inputData: prevOutput,
693
664
  runCount: -1,
665
+ tracingContext: {
666
+ currentSpan: sleepSpan,
667
+ isInternal: sleepSpan?.isInternal
668
+ },
694
669
  getInitData: () => stepResults?.input,
695
670
  getStepResult: (step) => {
696
671
  if (!step?.id) {
@@ -711,11 +686,13 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
711
686
  abortController?.abort();
712
687
  },
713
688
  [EMITTER_SYMBOL]: emitter,
689
+ // TODO: add streamVNext support
690
+ [STREAM_FORMAT_SYMBOL]: executionContext.format,
714
691
  engine: { step: this.inngestStep },
715
692
  abortSignal: abortController?.signal,
716
693
  writer: new ToolStream(
717
694
  {
718
- prefix: "step",
695
+ prefix: "workflow-step",
719
696
  callId: stepCallId,
720
697
  name: "sleep",
721
698
  runId
@@ -724,8 +701,19 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
724
701
  )
725
702
  });
726
703
  });
704
+ sleepSpan?.update({
705
+ attributes: {
706
+ durationMs: duration
707
+ }
708
+ });
709
+ }
710
+ try {
711
+ await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
712
+ sleepSpan?.end();
713
+ } catch (e) {
714
+ sleepSpan?.error({ error: e });
715
+ throw e;
727
716
  }
728
- await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
729
717
  }
730
718
  async executeSleepUntil({
731
719
  workflowId,
@@ -736,9 +724,21 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
736
724
  emitter,
737
725
  abortController,
738
726
  runtimeContext,
739
- writableStream
727
+ executionContext,
728
+ writableStream,
729
+ tracingContext
740
730
  }) {
741
731
  let { date, fn } = entry;
732
+ const sleepUntilSpan = tracingContext?.currentSpan?.createChildSpan({
733
+ type: AISpanType.WORKFLOW_SLEEP,
734
+ name: `sleepUntil: ${date ? date.toISOString() : "dynamic"}`,
735
+ attributes: {
736
+ untilDate: date,
737
+ durationMs: date ? Math.max(0, date.getTime() - Date.now()) : void 0,
738
+ sleepType: fn ? "dynamic" : "fixed"
739
+ },
740
+ isInternal: tracingContext?.isInternal
741
+ });
742
742
  if (fn) {
743
743
  date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
744
744
  const stepCallId = randomUUID();
@@ -749,6 +749,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
749
749
  runtimeContext,
750
750
  inputData: prevOutput,
751
751
  runCount: -1,
752
+ tracingContext: {
753
+ currentSpan: sleepUntilSpan,
754
+ isInternal: sleepUntilSpan?.isInternal
755
+ },
752
756
  getInitData: () => stepResults?.input,
753
757
  getStepResult: (step) => {
754
758
  if (!step?.id) {
@@ -769,11 +773,13 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
769
773
  abortController?.abort();
770
774
  },
771
775
  [EMITTER_SYMBOL]: emitter,
776
+ [STREAM_FORMAT_SYMBOL]: executionContext.format,
777
+ // TODO: add streamVNext support
772
778
  engine: { step: this.inngestStep },
773
779
  abortSignal: abortController?.signal,
774
780
  writer: new ToolStream(
775
781
  {
776
- prefix: "step",
782
+ prefix: "workflow-step",
777
783
  callId: stepCallId,
778
784
  name: "sleep",
779
785
  runId
@@ -782,11 +788,24 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
782
788
  )
783
789
  });
784
790
  });
791
+ const time = !date ? 0 : date.getTime() - Date.now();
792
+ sleepUntilSpan?.update({
793
+ attributes: {
794
+ durationMs: Math.max(0, time)
795
+ }
796
+ });
785
797
  }
786
798
  if (!(date instanceof Date)) {
799
+ sleepUntilSpan?.end();
787
800
  return;
788
801
  }
789
- await this.inngestStep.sleepUntil(entry.id, date);
802
+ try {
803
+ await this.inngestStep.sleepUntil(entry.id, date);
804
+ sleepUntilSpan?.end();
805
+ } catch (e) {
806
+ sleepUntilSpan?.error({ error: e });
807
+ throw e;
808
+ }
790
809
  }
791
810
  async executeWaitForEvent({ event, timeout }) {
792
811
  const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
@@ -807,8 +826,19 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
807
826
  emitter,
808
827
  abortController,
809
828
  runtimeContext,
810
- writableStream
829
+ tracingContext,
830
+ writableStream,
831
+ disableScorers
811
832
  }) {
833
+ const stepAISpan = tracingContext?.currentSpan?.createChildSpan({
834
+ name: `workflow step: '${step.id}'`,
835
+ type: AISpanType.WORKFLOW_STEP,
836
+ input: prevOutput,
837
+ attributes: {
838
+ stepId: step.id
839
+ },
840
+ isInternal: tracingContext?.isInternal
841
+ });
812
842
  const startedAt = await this.inngestStep.run(
813
843
  `workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
814
844
  async () => {
@@ -835,7 +865,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
835
865
  eventTimestamp: Date.now()
836
866
  });
837
867
  await emitter.emit("watch-v2", {
838
- type: "step-start",
868
+ type: "workflow-step-start",
839
869
  payload: {
840
870
  id: step.id,
841
871
  status: "running",
@@ -905,7 +935,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
905
935
  eventTimestamp: Date.now()
906
936
  });
907
937
  await emitter.emit("watch-v2", {
908
- type: "step-result",
938
+ type: "workflow-step-result",
909
939
  payload: {
910
940
  id: step.id,
911
941
  status: "failed",
@@ -940,7 +970,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
940
970
  eventTimestamp: Date.now()
941
971
  });
942
972
  await emitter.emit("watch-v2", {
943
- type: "step-suspended",
973
+ type: "workflow-step-suspended",
944
974
  payload: {
945
975
  id: step.id,
946
976
  status: "suspended"
@@ -997,7 +1027,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
997
1027
  eventTimestamp: Date.now()
998
1028
  });
999
1029
  await emitter.emit("watch-v2", {
1000
- type: "step-result",
1030
+ type: "workflow-step-result",
1001
1031
  payload: {
1002
1032
  id: step.id,
1003
1033
  status: "success",
@@ -1005,7 +1035,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1005
1035
  }
1006
1036
  });
1007
1037
  await emitter.emit("watch-v2", {
1008
- type: "step-finish",
1038
+ type: "workflow-step-finish",
1009
1039
  payload: {
1010
1040
  id: step.id,
1011
1041
  metadata: {}
@@ -1029,6 +1059,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1029
1059
  writableStream,
1030
1060
  inputData: prevOutput,
1031
1061
  resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
1062
+ tracingContext: {
1063
+ currentSpan: stepAISpan,
1064
+ isInternal: stepAISpan?.isInternal
1065
+ },
1032
1066
  getInitData: () => stepResults?.input,
1033
1067
  getStepResult: (step2) => {
1034
1068
  const result2 = stepResults[step2.id];
@@ -1092,7 +1126,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1092
1126
  }
1093
1127
  if (execResults.status === "failed") {
1094
1128
  if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
1095
- throw execResults.error;
1129
+ const error = new Error(execResults.error);
1130
+ stepAISpan?.error({ error });
1131
+ throw error;
1096
1132
  }
1097
1133
  }
1098
1134
  await emitter.emit("watch", {
@@ -1113,7 +1149,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1113
1149
  });
1114
1150
  if (execResults.status === "suspended") {
1115
1151
  await emitter.emit("watch-v2", {
1116
- type: "step-suspended",
1152
+ type: "workflow-step-suspended",
1117
1153
  payload: {
1118
1154
  id: step.id,
1119
1155
  ...execResults
@@ -1121,22 +1157,40 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1121
1157
  });
1122
1158
  } else {
1123
1159
  await emitter.emit("watch-v2", {
1124
- type: "step-result",
1160
+ type: "workflow-step-result",
1125
1161
  payload: {
1126
1162
  id: step.id,
1127
1163
  ...execResults
1128
1164
  }
1129
1165
  });
1130
1166
  await emitter.emit("watch-v2", {
1131
- type: "step-finish",
1167
+ type: "workflow-step-finish",
1132
1168
  payload: {
1133
1169
  id: step.id,
1134
1170
  metadata: {}
1135
1171
  }
1136
1172
  });
1137
1173
  }
1174
+ stepAISpan?.end({ output: execResults });
1138
1175
  return { result: execResults, executionContext, stepResults };
1139
1176
  });
1177
+ if (disableScorers !== false) {
1178
+ await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}.score`, async () => {
1179
+ if (step.scorers) {
1180
+ await this.runScorers({
1181
+ scorers: step.scorers,
1182
+ runId: executionContext.runId,
1183
+ input: prevOutput,
1184
+ output: stepRes.result,
1185
+ workflowId: executionContext.workflowId,
1186
+ stepId: step.id,
1187
+ runtimeContext,
1188
+ disableScorers,
1189
+ tracingContext: { currentSpan: stepAISpan, isInternal: true }
1190
+ });
1191
+ }
1192
+ });
1193
+ }
1140
1194
  Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
1141
1195
  Object.assign(stepResults, stepRes.stepResults);
1142
1196
  return stepRes.result;
@@ -1163,6 +1217,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1163
1217
  context: stepResults,
1164
1218
  activePaths: [],
1165
1219
  suspendedPaths: executionContext.suspendedPaths,
1220
+ waitingPaths: {},
1166
1221
  serializedStepGraph,
1167
1222
  status: workflowStatus,
1168
1223
  result,
@@ -1187,12 +1242,32 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1187
1242
  emitter,
1188
1243
  abortController,
1189
1244
  runtimeContext,
1190
- writableStream
1245
+ writableStream,
1246
+ disableScorers,
1247
+ tracingContext
1191
1248
  }) {
1249
+ const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
1250
+ type: AISpanType.WORKFLOW_CONDITIONAL,
1251
+ name: `conditional: '${entry.conditions.length} conditions'`,
1252
+ input: prevOutput,
1253
+ attributes: {
1254
+ conditionCount: entry.conditions.length
1255
+ },
1256
+ isInternal: tracingContext?.isInternal
1257
+ });
1192
1258
  let execResults;
1193
1259
  const truthyIndexes = (await Promise.all(
1194
1260
  entry.conditions.map(
1195
1261
  (cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
1262
+ const evalSpan = conditionalSpan?.createChildSpan({
1263
+ type: AISpanType.WORKFLOW_CONDITIONAL_EVAL,
1264
+ name: `condition: '${index}'`,
1265
+ input: prevOutput,
1266
+ attributes: {
1267
+ conditionIndex: index
1268
+ },
1269
+ isInternal: tracingContext?.isInternal
1270
+ });
1196
1271
  try {
1197
1272
  const result = await cond({
1198
1273
  runId,
@@ -1201,6 +1276,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1201
1276
  runtimeContext,
1202
1277
  runCount: -1,
1203
1278
  inputData: prevOutput,
1279
+ tracingContext: {
1280
+ currentSpan: evalSpan,
1281
+ isInternal: evalSpan?.isInternal
1282
+ },
1204
1283
  getInitData: () => stepResults?.input,
1205
1284
  getStepResult: (step) => {
1206
1285
  if (!step?.id) {
@@ -1221,13 +1300,15 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1221
1300
  abortController.abort();
1222
1301
  },
1223
1302
  [EMITTER_SYMBOL]: emitter,
1303
+ [STREAM_FORMAT_SYMBOL]: executionContext.format,
1304
+ // TODO: add streamVNext support
1224
1305
  engine: {
1225
1306
  step: this.inngestStep
1226
1307
  },
1227
1308
  abortSignal: abortController.signal,
1228
1309
  writer: new ToolStream(
1229
1310
  {
1230
- prefix: "step",
1311
+ prefix: "workflow-step",
1231
1312
  callId: randomUUID(),
1232
1313
  name: "conditional",
1233
1314
  runId
@@ -1235,24 +1316,42 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1235
1316
  writableStream
1236
1317
  )
1237
1318
  });
1319
+ evalSpan?.end({
1320
+ output: result,
1321
+ attributes: {
1322
+ result: !!result
1323
+ }
1324
+ });
1238
1325
  return result ? index : null;
1239
1326
  } catch (e) {
1327
+ evalSpan?.error({
1328
+ error: e instanceof Error ? e : new Error(String(e)),
1329
+ attributes: {
1330
+ result: false
1331
+ }
1332
+ });
1240
1333
  return null;
1241
1334
  }
1242
1335
  })
1243
1336
  )
1244
1337
  )).filter((index) => index !== null);
1245
1338
  const stepsToRun = entry.steps.filter((_, index) => truthyIndexes.includes(index));
1339
+ conditionalSpan?.update({
1340
+ attributes: {
1341
+ truthyIndexes,
1342
+ selectedSteps: stepsToRun.map((s) => s.type === "step" ? s.step.id : `control-${s.type}`)
1343
+ }
1344
+ });
1246
1345
  const results = await Promise.all(
1247
1346
  stepsToRun.map(
1248
1347
  (step, index) => this.executeEntry({
1249
1348
  workflowId,
1250
1349
  runId,
1251
1350
  entry: step,
1351
+ serializedStepGraph,
1252
1352
  prevStep,
1253
1353
  stepResults,
1254
1354
  resume,
1255
- serializedStepGraph,
1256
1355
  executionContext: {
1257
1356
  workflowId,
1258
1357
  runId,
@@ -1264,7 +1363,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1264
1363
  emitter,
1265
1364
  abortController,
1266
1365
  runtimeContext,
1267
- writableStream
1366
+ writableStream,
1367
+ disableScorers,
1368
+ tracingContext: {
1369
+ currentSpan: conditionalSpan,
1370
+ isInternal: conditionalSpan?.isInternal
1371
+ }
1268
1372
  })
1269
1373
  )
1270
1374
  );
@@ -1285,6 +1389,15 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1285
1389
  }, {})
1286
1390
  };
1287
1391
  }
1392
+ if (execResults.status === "failed") {
1393
+ conditionalSpan?.error({
1394
+ error: new Error(execResults.error)
1395
+ });
1396
+ } else {
1397
+ conditionalSpan?.end({
1398
+ output: execResults.output || execResults
1399
+ });
1400
+ }
1288
1401
  return execResults;
1289
1402
  }
1290
1403
  };