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