@mastra/inngest 0.0.0-cloudflare-deployer-dont-install-deps-20250714111754 → 0.0.0-configure-project-root-for-private-packages-20250919100548

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,16 +1,21 @@
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
- import { Tool } from '@mastra/core/tools';
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
 
10
11
  // src/index.ts
11
- function serve({ mastra, inngest }) {
12
+ function serve({
13
+ mastra,
14
+ inngest,
15
+ functions: userFunctions = []
16
+ }) {
12
17
  const wfs = mastra.getWorkflows();
13
- const functions = Array.from(
18
+ const workflowFunctions = Array.from(
14
19
  new Set(
15
20
  Object.values(wfs).flatMap((wf) => {
16
21
  if (wf instanceof InngestWorkflow) {
@@ -23,7 +28,7 @@ function serve({ mastra, inngest }) {
23
28
  );
24
29
  return serve$1({
25
30
  client: inngest,
26
- functions
31
+ functions: [...workflowFunctions, ...userFunctions]
27
32
  });
28
33
  }
29
34
  var InngestRun = class extends Run {
@@ -51,7 +56,6 @@ var InngestRun = class extends Run {
51
56
  await new Promise((resolve) => setTimeout(resolve, 1e3));
52
57
  runs = await this.getRuns(eventId);
53
58
  if (runs?.[0]?.status === "Failed") {
54
- console.log("run", runs?.[0]);
55
59
  throw new Error(`Function run ${runs?.[0]?.status}`);
56
60
  } else if (runs?.[0]?.status === "Cancelled") {
57
61
  const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
@@ -84,6 +88,7 @@ var InngestRun = class extends Run {
84
88
  await this.#mastra?.storage?.persistWorkflowSnapshot({
85
89
  workflowName: this.workflowId,
86
90
  runId: this.runId,
91
+ resourceId: this.resourceId,
87
92
  snapshot: {
88
93
  ...snapshot,
89
94
  status: "canceled"
@@ -97,6 +102,7 @@ var InngestRun = class extends Run {
97
102
  await this.#mastra.getStorage()?.persistWorkflowSnapshot({
98
103
  workflowName: this.workflowId,
99
104
  runId: this.runId,
105
+ resourceId: this.resourceId,
100
106
  snapshot: {
101
107
  runId: this.runId,
102
108
  serializedStepGraph: this.serializedStepGraph,
@@ -104,6 +110,7 @@ var InngestRun = class extends Run {
104
110
  context: {},
105
111
  activePaths: [],
106
112
  suspendedPaths: {},
113
+ waitingPaths: {},
107
114
  timestamp: Date.now(),
108
115
  status: "running"
109
116
  }
@@ -112,7 +119,8 @@ var InngestRun = class extends Run {
112
119
  name: `workflow.${this.workflowId}`,
113
120
  data: {
114
121
  inputData,
115
- runId: this.runId
122
+ runId: this.runId,
123
+ resourceId: this.resourceId
116
124
  }
117
125
  });
118
126
  const eventId = eventOutput.ids[0];
@@ -153,6 +161,7 @@ var InngestRun = class extends Run {
153
161
  data: {
154
162
  inputData: params.resumeData,
155
163
  runId: this.runId,
164
+ workflowId: this.workflowId,
156
165
  stepResults: snapshot?.context,
157
166
  resume: {
158
167
  steps,
@@ -202,7 +211,11 @@ var InngestRun = class extends Run {
202
211
  const writer = writable.getWriter();
203
212
  const unwatch = this.watch(async (event) => {
204
213
  try {
205
- await writer.write(event);
214
+ const e = {
215
+ ...event,
216
+ type: event.type.replace("workflow-", "")
217
+ };
218
+ await writer.write(e);
206
219
  } catch {
207
220
  }
208
221
  }, "watch-v2");
@@ -233,8 +246,14 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
233
246
  #mastra;
234
247
  inngest;
235
248
  function;
249
+ flowControlConfig;
236
250
  constructor(params, inngest) {
237
- super(params);
251
+ const { concurrency, rateLimit, throttle, debounce, priority, ...workflowParams } = params;
252
+ super(workflowParams);
253
+ const flowControlEntries = Object.entries({ concurrency, rateLimit, throttle, debounce, priority }).filter(
254
+ ([_, value]) => value !== void 0
255
+ );
256
+ this.flowControlConfig = flowControlEntries.length > 0 ? Object.fromEntries(flowControlEntries) : void 0;
238
257
  this.#mastra = params.mastra;
239
258
  this.inngest = inngest;
240
259
  }
@@ -255,27 +274,6 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
255
274
  const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
256
275
  return run ?? (this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null);
257
276
  }
258
- async getWorkflowRunExecutionResult(runId) {
259
- const storage = this.#mastra?.getStorage();
260
- if (!storage) {
261
- this.logger.debug("Cannot get workflow run execution result. Mastra storage is not initialized");
262
- return null;
263
- }
264
- const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
265
- if (!run?.snapshot) {
266
- return null;
267
- }
268
- if (typeof run.snapshot === "string") {
269
- return null;
270
- }
271
- return {
272
- status: run.snapshot.status,
273
- result: run.snapshot.result,
274
- error: run.snapshot.error,
275
- payload: run.snapshot.context?.input,
276
- steps: run.snapshot.context
277
- };
278
- }
279
277
  __registerMastra(mastra) {
280
278
  this.#mastra = mastra;
281
279
  this.executionEngine.__registerMastra(mastra);
@@ -294,23 +292,14 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
294
292
  }
295
293
  }
296
294
  }
297
- createRun(options) {
298
- const runIdToUse = options?.runId || randomUUID();
299
- const run = this.runs.get(runIdToUse) ?? new InngestRun(
300
- {
301
- workflowId: this.id,
302
- runId: runIdToUse,
303
- executionEngine: this.executionEngine,
304
- executionGraph: this.executionGraph,
305
- serializedStepGraph: this.serializedStepGraph,
306
- mastra: this.#mastra,
307
- retryConfig: this.retryConfig,
308
- cleanup: () => this.runs.delete(runIdToUse)
309
- },
310
- this.inngest
295
+ /**
296
+ * @deprecated Use createRunAsync() instead.
297
+ * @throws {Error} Always throws an error directing users to use createRunAsync()
298
+ */
299
+ createRun(_options) {
300
+ throw new Error(
301
+ "createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = workflow.createRun();\n After: const run = await workflow.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
311
302
  );
312
- this.runs.set(runIdToUse, run);
313
- return run;
314
303
  }
315
304
  async createRunAsync(options) {
316
305
  const runIdToUse = options?.runId || randomUUID();
@@ -318,6 +307,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
318
307
  {
319
308
  workflowId: this.id,
320
309
  runId: runIdToUse,
310
+ resourceId: options?.resourceId,
321
311
  executionEngine: this.executionEngine,
322
312
  executionGraph: this.executionGraph,
323
313
  serializedStepGraph: this.serializedStepGraph,
@@ -328,17 +318,19 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
328
318
  this.inngest
329
319
  );
330
320
  this.runs.set(runIdToUse, run);
331
- const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse);
321
+ const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, false);
332
322
  if (!workflowSnapshotInStorage) {
333
323
  await this.mastra?.getStorage()?.persistWorkflowSnapshot({
334
324
  workflowName: this.id,
335
325
  runId: runIdToUse,
326
+ resourceId: options?.resourceId,
336
327
  snapshot: {
337
328
  runId: runIdToUse,
338
329
  status: "pending",
339
330
  value: {},
340
331
  context: {},
341
332
  activePaths: [],
333
+ waitingPaths: {},
342
334
  serializedStepGraph: this.serializedStepGraph,
343
335
  suspendedPaths: {},
344
336
  result: void 0,
@@ -359,11 +351,13 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
359
351
  id: `workflow.${this.id}`,
360
352
  // @ts-ignore
361
353
  retries: this.retryConfig?.attempts ?? 0,
362
- cancelOn: [{ event: `cancel.workflow.${this.id}` }]
354
+ cancelOn: [{ event: `cancel.workflow.${this.id}` }],
355
+ // Spread flow control configuration
356
+ ...this.flowControlConfig
363
357
  },
364
358
  { event: `workflow.${this.id}` },
365
359
  async ({ event, step, attempt, publish }) => {
366
- let { inputData, runId, resume } = event.data;
360
+ let { inputData, runId, resourceId, resume } = event.data;
367
361
  if (!runId) {
368
362
  runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
369
363
  return randomUUID();
@@ -395,6 +389,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
395
389
  const result = await engine.execute({
396
390
  workflowId: this.id,
397
391
  runId,
392
+ resourceId,
398
393
  graph: this.executionGraph,
399
394
  serializedStepGraph: this.serializedStepGraph,
400
395
  input: inputData,
@@ -403,7 +398,9 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
403
398
  runtimeContext: new RuntimeContext(),
404
399
  // TODO
405
400
  resume,
406
- abortController: new AbortController()
401
+ abortController: new AbortController(),
402
+ currentSpan: void 0
403
+ // TODO: Pass actual parent AI span from workflow execution context
407
404
  });
408
405
  return { result, runId };
409
406
  }
@@ -440,14 +437,12 @@ function createStep(params) {
440
437
  // @ts-ignore
441
438
  inputSchema: z.object({
442
439
  prompt: z.string()
443
- // resourceId: z.string().optional(),
444
- // threadId: z.string().optional(),
445
440
  }),
446
441
  // @ts-ignore
447
442
  outputSchema: z.object({
448
443
  text: z.string()
449
444
  }),
450
- execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort }) => {
445
+ execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort, tracingContext }) => {
451
446
  let streamPromise = {};
452
447
  streamPromise.promise = new Promise((resolve, reject) => {
453
448
  streamPromise.resolve = resolve;
@@ -457,14 +452,9 @@ function createStep(params) {
457
452
  name: params.name,
458
453
  args: inputData
459
454
  };
460
- await emitter.emit("watch-v2", {
461
- type: "tool-call-streaming-start",
462
- ...toolData
463
- });
464
455
  const { fullStream } = await params.stream(inputData.prompt, {
465
- // resourceId: inputData.resourceId,
466
- // threadId: inputData.threadId,
467
456
  runtimeContext,
457
+ tracingContext,
468
458
  onFinish: (result) => {
469
459
  streamPromise.resolve(result.text);
470
460
  },
@@ -473,30 +463,23 @@ function createStep(params) {
473
463
  if (abortSignal.aborted) {
474
464
  return abort();
475
465
  }
466
+ await emitter.emit("watch-v2", {
467
+ type: "tool-call-streaming-start",
468
+ ...toolData ?? {}
469
+ });
476
470
  for await (const chunk of fullStream) {
477
- switch (chunk.type) {
478
- case "text-delta":
479
- await emitter.emit("watch-v2", {
480
- type: "tool-call-delta",
481
- ...toolData,
482
- argsTextDelta: chunk.textDelta
483
- });
484
- break;
485
- case "step-start":
486
- case "step-finish":
487
- case "finish":
488
- break;
489
- case "tool-call":
490
- case "tool-result":
491
- case "tool-call-streaming-start":
492
- case "tool-call-delta":
493
- case "source":
494
- case "file":
495
- default:
496
- await emitter.emit("watch-v2", chunk);
497
- break;
471
+ if (chunk.type === "text-delta") {
472
+ await emitter.emit("watch-v2", {
473
+ type: "tool-call-delta",
474
+ ...toolData ?? {},
475
+ argsTextDelta: chunk.textDelta
476
+ });
498
477
  }
499
478
  }
479
+ await emitter.emit("watch-v2", {
480
+ type: "tool-call-streaming-finish",
481
+ ...toolData ?? {}
482
+ });
500
483
  return {
501
484
  text: await streamPromise.promise
502
485
  };
@@ -513,11 +496,12 @@ function createStep(params) {
513
496
  id: params.id,
514
497
  inputSchema: params.inputSchema,
515
498
  outputSchema: params.outputSchema,
516
- execute: async ({ inputData, mastra, runtimeContext }) => {
499
+ execute: async ({ inputData, mastra, runtimeContext, tracingContext }) => {
517
500
  return params.execute({
518
501
  context: inputData,
519
- mastra,
520
- runtimeContext
502
+ mastra: wrapMastra(mastra, tracingContext),
503
+ runtimeContext,
504
+ tracingContext
521
505
  });
522
506
  }
523
507
  };
@@ -564,19 +548,19 @@ function init(inngest) {
564
548
  var InngestExecutionEngine = class extends DefaultExecutionEngine {
565
549
  inngestStep;
566
550
  inngestAttempts;
567
- constructor(mastra, inngestStep, inngestAttempts = 0) {
568
- super({ mastra });
551
+ constructor(mastra, inngestStep, inngestAttempts = 0, options) {
552
+ super({ mastra, options });
569
553
  this.inngestStep = inngestStep;
570
554
  this.inngestAttempts = inngestAttempts;
571
555
  }
572
556
  async execute(params) {
573
557
  await params.emitter.emit("watch-v2", {
574
- type: "start",
558
+ type: "workflow-start",
575
559
  payload: { runId: params.runId }
576
560
  });
577
561
  const result = await super.execute(params);
578
562
  await params.emitter.emit("watch-v2", {
579
- type: "finish",
563
+ type: "workflow-finish",
580
564
  payload: { runId: params.runId }
581
565
  });
582
566
  return result;
@@ -638,31 +622,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
638
622
  executionSpan?.end();
639
623
  return base;
640
624
  }
641
- async superExecuteStep({
642
- workflowId,
643
- runId,
644
- step,
645
- stepResults,
646
- executionContext,
647
- resume,
648
- prevOutput,
649
- emitter,
650
- abortController,
651
- runtimeContext
652
- }) {
653
- return super.executeStep({
654
- workflowId,
655
- runId,
656
- step,
657
- stepResults,
658
- executionContext,
659
- resume,
660
- prevOutput,
661
- emitter,
662
- abortController,
663
- runtimeContext
664
- });
665
- }
666
625
  // async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
667
626
  // await this.inngestStep.sleep(id, duration);
668
627
  // }
@@ -674,17 +633,34 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
674
633
  stepResults,
675
634
  emitter,
676
635
  abortController,
677
- runtimeContext
636
+ runtimeContext,
637
+ executionContext,
638
+ writableStream,
639
+ tracingContext
678
640
  }) {
679
641
  let { duration, fn } = entry;
642
+ const sleepSpan = tracingContext?.currentSpan?.createChildSpan({
643
+ type: AISpanType.WORKFLOW_SLEEP,
644
+ name: `sleep: ${duration ? `${duration}ms` : "dynamic"}`,
645
+ attributes: {
646
+ durationMs: duration,
647
+ sleepType: fn ? "dynamic" : "fixed"
648
+ },
649
+ tracingPolicy: this.options?.tracingPolicy
650
+ });
680
651
  if (fn) {
652
+ const stepCallId = randomUUID();
681
653
  duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
682
654
  return await fn({
683
655
  runId,
656
+ workflowId,
684
657
  mastra: this.mastra,
685
658
  runtimeContext,
686
659
  inputData: prevOutput,
687
660
  runCount: -1,
661
+ tracingContext: {
662
+ currentSpan: sleepSpan
663
+ },
688
664
  getInitData: () => stepResults?.input,
689
665
  getStepResult: (step) => {
690
666
  if (!step?.id) {
@@ -705,12 +681,34 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
705
681
  abortController?.abort();
706
682
  },
707
683
  [EMITTER_SYMBOL]: emitter,
684
+ // TODO: add streamVNext support
685
+ [STREAM_FORMAT_SYMBOL]: executionContext.format,
708
686
  engine: { step: this.inngestStep },
709
- abortSignal: abortController?.signal
687
+ abortSignal: abortController?.signal,
688
+ writer: new ToolStream(
689
+ {
690
+ prefix: "workflow-step",
691
+ callId: stepCallId,
692
+ name: "sleep",
693
+ runId
694
+ },
695
+ writableStream
696
+ )
710
697
  });
711
698
  });
699
+ sleepSpan?.update({
700
+ attributes: {
701
+ durationMs: duration
702
+ }
703
+ });
704
+ }
705
+ try {
706
+ await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
707
+ sleepSpan?.end();
708
+ } catch (e) {
709
+ sleepSpan?.error({ error: e });
710
+ throw e;
712
711
  }
713
- await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
714
712
  }
715
713
  async executeSleepUntil({
716
714
  workflowId,
@@ -720,17 +718,35 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
720
718
  stepResults,
721
719
  emitter,
722
720
  abortController,
723
- runtimeContext
721
+ runtimeContext,
722
+ executionContext,
723
+ writableStream,
724
+ tracingContext
724
725
  }) {
725
726
  let { date, fn } = entry;
727
+ const sleepUntilSpan = tracingContext?.currentSpan?.createChildSpan({
728
+ type: AISpanType.WORKFLOW_SLEEP,
729
+ name: `sleepUntil: ${date ? date.toISOString() : "dynamic"}`,
730
+ attributes: {
731
+ untilDate: date,
732
+ durationMs: date ? Math.max(0, date.getTime() - Date.now()) : void 0,
733
+ sleepType: fn ? "dynamic" : "fixed"
734
+ },
735
+ tracingPolicy: this.options?.tracingPolicy
736
+ });
726
737
  if (fn) {
727
738
  date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
739
+ const stepCallId = randomUUID();
728
740
  return await fn({
729
741
  runId,
742
+ workflowId,
730
743
  mastra: this.mastra,
731
744
  runtimeContext,
732
745
  inputData: prevOutput,
733
746
  runCount: -1,
747
+ tracingContext: {
748
+ currentSpan: sleepUntilSpan
749
+ },
734
750
  getInitData: () => stepResults?.input,
735
751
  getStepResult: (step) => {
736
752
  if (!step?.id) {
@@ -751,15 +767,42 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
751
767
  abortController?.abort();
752
768
  },
753
769
  [EMITTER_SYMBOL]: emitter,
770
+ [STREAM_FORMAT_SYMBOL]: executionContext.format,
771
+ // TODO: add streamVNext support
754
772
  engine: { step: this.inngestStep },
755
- abortSignal: abortController?.signal
773
+ abortSignal: abortController?.signal,
774
+ writer: new ToolStream(
775
+ {
776
+ prefix: "workflow-step",
777
+ callId: stepCallId,
778
+ name: "sleep",
779
+ runId
780
+ },
781
+ writableStream
782
+ )
756
783
  });
757
784
  });
785
+ if (date && !(date instanceof Date)) {
786
+ date = new Date(date);
787
+ }
788
+ const time = !date ? 0 : date.getTime() - Date.now();
789
+ sleepUntilSpan?.update({
790
+ attributes: {
791
+ durationMs: Math.max(0, time)
792
+ }
793
+ });
758
794
  }
759
795
  if (!(date instanceof Date)) {
796
+ sleepUntilSpan?.end();
760
797
  return;
761
798
  }
762
- await this.inngestStep.sleepUntil(entry.id, date);
799
+ try {
800
+ await this.inngestStep.sleepUntil(entry.id, date);
801
+ sleepUntilSpan?.end();
802
+ } catch (e) {
803
+ sleepUntilSpan?.error({ error: e });
804
+ throw e;
805
+ }
763
806
  }
764
807
  async executeWaitForEvent({ event, timeout }) {
765
808
  const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
@@ -779,8 +822,20 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
779
822
  prevOutput,
780
823
  emitter,
781
824
  abortController,
782
- runtimeContext
825
+ runtimeContext,
826
+ tracingContext,
827
+ writableStream,
828
+ disableScorers
783
829
  }) {
830
+ const stepAISpan = tracingContext?.currentSpan?.createChildSpan({
831
+ name: `workflow step: '${step.id}'`,
832
+ type: AISpanType.WORKFLOW_STEP,
833
+ input: prevOutput,
834
+ attributes: {
835
+ stepId: step.id
836
+ },
837
+ tracingPolicy: this.options?.tracingPolicy
838
+ });
784
839
  const startedAt = await this.inngestStep.run(
785
840
  `workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
786
841
  async () => {
@@ -807,7 +862,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
807
862
  eventTimestamp: Date.now()
808
863
  });
809
864
  await emitter.emit("watch-v2", {
810
- type: "step-start",
865
+ type: "workflow-step-start",
811
866
  payload: {
812
867
  id: step.id,
813
868
  status: "running",
@@ -877,7 +932,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
877
932
  eventTimestamp: Date.now()
878
933
  });
879
934
  await emitter.emit("watch-v2", {
880
- type: "step-result",
935
+ type: "workflow-step-result",
881
936
  payload: {
882
937
  id: step.id,
883
938
  status: "failed",
@@ -912,7 +967,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
912
967
  eventTimestamp: Date.now()
913
968
  });
914
969
  await emitter.emit("watch-v2", {
915
- type: "step-suspended",
970
+ type: "workflow-step-suspended",
916
971
  payload: {
917
972
  id: step.id,
918
973
  status: "suspended"
@@ -969,7 +1024,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
969
1024
  eventTimestamp: Date.now()
970
1025
  });
971
1026
  await emitter.emit("watch-v2", {
972
- type: "step-result",
1027
+ type: "workflow-step-result",
973
1028
  payload: {
974
1029
  id: step.id,
975
1030
  status: "success",
@@ -977,7 +1032,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
977
1032
  }
978
1033
  });
979
1034
  await emitter.emit("watch-v2", {
980
- type: "step-finish",
1035
+ type: "workflow-step-finish",
981
1036
  payload: {
982
1037
  id: step.id,
983
1038
  metadata: {}
@@ -998,8 +1053,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
998
1053
  runId: executionContext.runId,
999
1054
  mastra: this.mastra,
1000
1055
  runtimeContext,
1056
+ writableStream,
1001
1057
  inputData: prevOutput,
1002
1058
  resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
1059
+ tracingContext: {
1060
+ currentSpan: stepAISpan
1061
+ },
1003
1062
  getInitData: () => stepResults?.input,
1004
1063
  getStepResult: (step2) => {
1005
1064
  const result2 = stepResults[step2.id];
@@ -1063,7 +1122,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1063
1122
  }
1064
1123
  if (execResults.status === "failed") {
1065
1124
  if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
1066
- throw execResults.error;
1125
+ const error = new Error(execResults.error);
1126
+ stepAISpan?.error({ error });
1127
+ throw error;
1067
1128
  }
1068
1129
  }
1069
1130
  await emitter.emit("watch", {
@@ -1084,7 +1145,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1084
1145
  });
1085
1146
  if (execResults.status === "suspended") {
1086
1147
  await emitter.emit("watch-v2", {
1087
- type: "step-suspended",
1148
+ type: "workflow-step-suspended",
1088
1149
  payload: {
1089
1150
  id: step.id,
1090
1151
  ...execResults
@@ -1092,22 +1153,40 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1092
1153
  });
1093
1154
  } else {
1094
1155
  await emitter.emit("watch-v2", {
1095
- type: "step-result",
1156
+ type: "workflow-step-result",
1096
1157
  payload: {
1097
1158
  id: step.id,
1098
1159
  ...execResults
1099
1160
  }
1100
1161
  });
1101
1162
  await emitter.emit("watch-v2", {
1102
- type: "step-finish",
1163
+ type: "workflow-step-finish",
1103
1164
  payload: {
1104
1165
  id: step.id,
1105
1166
  metadata: {}
1106
1167
  }
1107
1168
  });
1108
1169
  }
1170
+ stepAISpan?.end({ output: execResults });
1109
1171
  return { result: execResults, executionContext, stepResults };
1110
1172
  });
1173
+ if (disableScorers !== false) {
1174
+ await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}.score`, async () => {
1175
+ if (step.scorers) {
1176
+ await this.runScorers({
1177
+ scorers: step.scorers,
1178
+ runId: executionContext.runId,
1179
+ input: prevOutput,
1180
+ output: stepRes.result,
1181
+ workflowId: executionContext.workflowId,
1182
+ stepId: step.id,
1183
+ runtimeContext,
1184
+ disableScorers,
1185
+ tracingContext: { currentSpan: stepAISpan }
1186
+ });
1187
+ }
1188
+ });
1189
+ }
1111
1190
  Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
1112
1191
  Object.assign(stepResults, stepRes.stepResults);
1113
1192
  return stepRes.result;
@@ -1116,6 +1195,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1116
1195
  workflowId,
1117
1196
  runId,
1118
1197
  stepResults,
1198
+ resourceId,
1119
1199
  executionContext,
1120
1200
  serializedStepGraph,
1121
1201
  workflowStatus,
@@ -1128,12 +1208,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1128
1208
  await this.mastra?.getStorage()?.persistWorkflowSnapshot({
1129
1209
  workflowName: workflowId,
1130
1210
  runId,
1211
+ resourceId,
1131
1212
  snapshot: {
1132
1213
  runId,
1133
1214
  value: {},
1134
1215
  context: stepResults,
1135
1216
  activePaths: [],
1136
1217
  suspendedPaths: executionContext.suspendedPaths,
1218
+ waitingPaths: {},
1137
1219
  serializedStepGraph,
1138
1220
  status: workflowStatus,
1139
1221
  result,
@@ -1157,19 +1239,44 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1157
1239
  executionContext,
1158
1240
  emitter,
1159
1241
  abortController,
1160
- runtimeContext
1242
+ runtimeContext,
1243
+ writableStream,
1244
+ disableScorers,
1245
+ tracingContext
1161
1246
  }) {
1247
+ const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
1248
+ type: AISpanType.WORKFLOW_CONDITIONAL,
1249
+ name: `conditional: '${entry.conditions.length} conditions'`,
1250
+ input: prevOutput,
1251
+ attributes: {
1252
+ conditionCount: entry.conditions.length
1253
+ },
1254
+ tracingPolicy: this.options?.tracingPolicy
1255
+ });
1162
1256
  let execResults;
1163
1257
  const truthyIndexes = (await Promise.all(
1164
1258
  entry.conditions.map(
1165
1259
  (cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
1260
+ const evalSpan = conditionalSpan?.createChildSpan({
1261
+ type: AISpanType.WORKFLOW_CONDITIONAL_EVAL,
1262
+ name: `condition: '${index}'`,
1263
+ input: prevOutput,
1264
+ attributes: {
1265
+ conditionIndex: index
1266
+ },
1267
+ tracingPolicy: this.options?.tracingPolicy
1268
+ });
1166
1269
  try {
1167
1270
  const result = await cond({
1168
1271
  runId,
1272
+ workflowId,
1169
1273
  mastra: this.mastra,
1170
1274
  runtimeContext,
1171
1275
  runCount: -1,
1172
1276
  inputData: prevOutput,
1277
+ tracingContext: {
1278
+ currentSpan: evalSpan
1279
+ },
1173
1280
  getInitData: () => stepResults?.input,
1174
1281
  getStepResult: (step) => {
1175
1282
  if (!step?.id) {
@@ -1190,29 +1297,58 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1190
1297
  abortController.abort();
1191
1298
  },
1192
1299
  [EMITTER_SYMBOL]: emitter,
1300
+ [STREAM_FORMAT_SYMBOL]: executionContext.format,
1301
+ // TODO: add streamVNext support
1193
1302
  engine: {
1194
1303
  step: this.inngestStep
1195
1304
  },
1196
- abortSignal: abortController.signal
1305
+ abortSignal: abortController.signal,
1306
+ writer: new ToolStream(
1307
+ {
1308
+ prefix: "workflow-step",
1309
+ callId: randomUUID(),
1310
+ name: "conditional",
1311
+ runId
1312
+ },
1313
+ writableStream
1314
+ )
1315
+ });
1316
+ evalSpan?.end({
1317
+ output: result,
1318
+ attributes: {
1319
+ result: !!result
1320
+ }
1197
1321
  });
1198
1322
  return result ? index : null;
1199
1323
  } catch (e) {
1324
+ evalSpan?.error({
1325
+ error: e instanceof Error ? e : new Error(String(e)),
1326
+ attributes: {
1327
+ result: false
1328
+ }
1329
+ });
1200
1330
  return null;
1201
1331
  }
1202
1332
  })
1203
1333
  )
1204
1334
  )).filter((index) => index !== null);
1205
1335
  const stepsToRun = entry.steps.filter((_, index) => truthyIndexes.includes(index));
1336
+ conditionalSpan?.update({
1337
+ attributes: {
1338
+ truthyIndexes,
1339
+ selectedSteps: stepsToRun.map((s) => s.type === "step" ? s.step.id : `control-${s.type}`)
1340
+ }
1341
+ });
1206
1342
  const results = await Promise.all(
1207
1343
  stepsToRun.map(
1208
1344
  (step, index) => this.executeEntry({
1209
1345
  workflowId,
1210
1346
  runId,
1211
1347
  entry: step,
1348
+ serializedStepGraph,
1212
1349
  prevStep,
1213
1350
  stepResults,
1214
1351
  resume,
1215
- serializedStepGraph,
1216
1352
  executionContext: {
1217
1353
  workflowId,
1218
1354
  runId,
@@ -1223,7 +1359,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1223
1359
  },
1224
1360
  emitter,
1225
1361
  abortController,
1226
- runtimeContext
1362
+ runtimeContext,
1363
+ writableStream,
1364
+ disableScorers,
1365
+ tracingContext: {
1366
+ currentSpan: conditionalSpan
1367
+ }
1227
1368
  })
1228
1369
  )
1229
1370
  );
@@ -1244,8 +1385,19 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
1244
1385
  }, {})
1245
1386
  };
1246
1387
  }
1388
+ if (execResults.status === "failed") {
1389
+ conditionalSpan?.error({
1390
+ error: new Error(execResults.error)
1391
+ });
1392
+ } else {
1393
+ conditionalSpan?.end({
1394
+ output: execResults.output || execResults
1395
+ });
1396
+ }
1247
1397
  return execResults;
1248
1398
  }
1249
1399
  };
1250
1400
 
1251
1401
  export { InngestExecutionEngine, InngestRun, InngestWorkflow, createStep, init, serve };
1402
+ //# sourceMappingURL=index.js.map
1403
+ //# sourceMappingURL=index.js.map