@mastra/inngest 0.0.0-cloudflare-deployer-dont-install-deps-20250714111754 → 0.0.0-consolidate-changesets-20250904042643
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 +395 -2
- package/dist/index.cjs +256 -101
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +281 -7
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +257 -102
- package/dist/index.js.map +1 -0
- package/package.json +28 -14
- package/dist/_tsup-dts-rollup.d.cts +0 -309
- package/dist/_tsup-dts-rollup.d.ts +0 -309
- package/dist/index.d.cts +0 -7
- package/docker-compose.yaml +0 -10
- package/eslint.config.js +0 -6
- package/src/index.test.ts +0 -7527
- package/src/index.ts +0 -1736
- package/tsconfig.json +0 -5
- 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
|
}
|
|
@@ -155,6 +157,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
155
157
|
data: {
|
|
156
158
|
inputData: params.resumeData,
|
|
157
159
|
runId: this.runId,
|
|
160
|
+
workflowId: this.workflowId,
|
|
158
161
|
stepResults: snapshot?.context,
|
|
159
162
|
resume: {
|
|
160
163
|
steps,
|
|
@@ -201,10 +204,38 @@ var InngestRun = class extends workflows.Run {
|
|
|
201
204
|
}
|
|
202
205
|
stream({ inputData, runtimeContext } = {}) {
|
|
203
206
|
const { readable, writable } = new TransformStream();
|
|
207
|
+
let currentToolData = void 0;
|
|
204
208
|
const writer = writable.getWriter();
|
|
205
209
|
const unwatch = this.watch(async (event) => {
|
|
210
|
+
if (event.type === "workflow-agent-call-start") {
|
|
211
|
+
currentToolData = {
|
|
212
|
+
name: event.payload.name,
|
|
213
|
+
args: event.payload.args
|
|
214
|
+
};
|
|
215
|
+
await writer.write({
|
|
216
|
+
...event.payload,
|
|
217
|
+
type: "tool-call-streaming-start"
|
|
218
|
+
});
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
206
221
|
try {
|
|
207
|
-
|
|
222
|
+
if (event.type === "workflow-agent-call-finish") {
|
|
223
|
+
return;
|
|
224
|
+
} else if (!event.type.startsWith("workflow-")) {
|
|
225
|
+
if (event.type === "text-delta") {
|
|
226
|
+
await writer.write({
|
|
227
|
+
type: "tool-call-delta",
|
|
228
|
+
...currentToolData ?? {},
|
|
229
|
+
argsTextDelta: event.textDelta
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const e = {
|
|
235
|
+
...event,
|
|
236
|
+
type: event.type.replace("workflow-", "")
|
|
237
|
+
};
|
|
238
|
+
await writer.write(e);
|
|
208
239
|
} catch {
|
|
209
240
|
}
|
|
210
241
|
}, "watch-v2");
|
|
@@ -235,8 +266,14 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
235
266
|
#mastra;
|
|
236
267
|
inngest;
|
|
237
268
|
function;
|
|
269
|
+
flowControlConfig;
|
|
238
270
|
constructor(params, inngest) {
|
|
239
|
-
|
|
271
|
+
const { concurrency, rateLimit, throttle, debounce, priority, ...workflowParams } = params;
|
|
272
|
+
super(workflowParams);
|
|
273
|
+
const flowControlEntries = Object.entries({ concurrency, rateLimit, throttle, debounce, priority }).filter(
|
|
274
|
+
([_, value]) => value !== void 0
|
|
275
|
+
);
|
|
276
|
+
this.flowControlConfig = flowControlEntries.length > 0 ? Object.fromEntries(flowControlEntries) : void 0;
|
|
240
277
|
this.#mastra = params.mastra;
|
|
241
278
|
this.inngest = inngest;
|
|
242
279
|
}
|
|
@@ -257,27 +294,6 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
257
294
|
const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
|
|
258
295
|
return run ?? (this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null);
|
|
259
296
|
}
|
|
260
|
-
async getWorkflowRunExecutionResult(runId) {
|
|
261
|
-
const storage = this.#mastra?.getStorage();
|
|
262
|
-
if (!storage) {
|
|
263
|
-
this.logger.debug("Cannot get workflow run execution result. Mastra storage is not initialized");
|
|
264
|
-
return null;
|
|
265
|
-
}
|
|
266
|
-
const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
|
|
267
|
-
if (!run?.snapshot) {
|
|
268
|
-
return null;
|
|
269
|
-
}
|
|
270
|
-
if (typeof run.snapshot === "string") {
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
return {
|
|
274
|
-
status: run.snapshot.status,
|
|
275
|
-
result: run.snapshot.result,
|
|
276
|
-
error: run.snapshot.error,
|
|
277
|
-
payload: run.snapshot.context?.input,
|
|
278
|
-
steps: run.snapshot.context
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
297
|
__registerMastra(mastra) {
|
|
282
298
|
this.#mastra = mastra;
|
|
283
299
|
this.executionEngine.__registerMastra(mastra);
|
|
@@ -330,7 +346,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
330
346
|
this.inngest
|
|
331
347
|
);
|
|
332
348
|
this.runs.set(runIdToUse, run);
|
|
333
|
-
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse);
|
|
349
|
+
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, false);
|
|
334
350
|
if (!workflowSnapshotInStorage) {
|
|
335
351
|
await this.mastra?.getStorage()?.persistWorkflowSnapshot({
|
|
336
352
|
workflowName: this.id,
|
|
@@ -341,6 +357,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
341
357
|
value: {},
|
|
342
358
|
context: {},
|
|
343
359
|
activePaths: [],
|
|
360
|
+
waitingPaths: {},
|
|
344
361
|
serializedStepGraph: this.serializedStepGraph,
|
|
345
362
|
suspendedPaths: {},
|
|
346
363
|
result: void 0,
|
|
@@ -361,7 +378,9 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
361
378
|
id: `workflow.${this.id}`,
|
|
362
379
|
// @ts-ignore
|
|
363
380
|
retries: this.retryConfig?.attempts ?? 0,
|
|
364
|
-
cancelOn: [{ event: `cancel.workflow.${this.id}` }]
|
|
381
|
+
cancelOn: [{ event: `cancel.workflow.${this.id}` }],
|
|
382
|
+
// Spread flow control configuration
|
|
383
|
+
...this.flowControlConfig
|
|
365
384
|
},
|
|
366
385
|
{ event: `workflow.${this.id}` },
|
|
367
386
|
async ({ event, step, attempt, publish }) => {
|
|
@@ -405,7 +424,9 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
405
424
|
runtimeContext: new di.RuntimeContext(),
|
|
406
425
|
// TODO
|
|
407
426
|
resume,
|
|
408
|
-
abortController: new AbortController()
|
|
427
|
+
abortController: new AbortController(),
|
|
428
|
+
currentSpan: void 0
|
|
429
|
+
// TODO: Pass actual parent AI span from workflow execution context
|
|
409
430
|
});
|
|
410
431
|
return { result, runId };
|
|
411
432
|
}
|
|
@@ -449,7 +470,7 @@ function createStep(params) {
|
|
|
449
470
|
outputSchema: zod.z.object({
|
|
450
471
|
text: zod.z.string()
|
|
451
472
|
}),
|
|
452
|
-
execute: async ({ inputData, [_constants.EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort }) => {
|
|
473
|
+
execute: async ({ inputData, [_constants.EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort, tracingContext }) => {
|
|
453
474
|
let streamPromise = {};
|
|
454
475
|
streamPromise.promise = new Promise((resolve, reject) => {
|
|
455
476
|
streamPromise.resolve = resolve;
|
|
@@ -460,13 +481,14 @@ function createStep(params) {
|
|
|
460
481
|
args: inputData
|
|
461
482
|
};
|
|
462
483
|
await emitter.emit("watch-v2", {
|
|
463
|
-
type: "
|
|
464
|
-
|
|
484
|
+
type: "workflow-agent-call-start",
|
|
485
|
+
payload: toolData
|
|
465
486
|
});
|
|
466
487
|
const { fullStream } = await params.stream(inputData.prompt, {
|
|
467
488
|
// resourceId: inputData.resourceId,
|
|
468
489
|
// threadId: inputData.threadId,
|
|
469
490
|
runtimeContext,
|
|
491
|
+
tracingContext,
|
|
470
492
|
onFinish: (result) => {
|
|
471
493
|
streamPromise.resolve(result.text);
|
|
472
494
|
},
|
|
@@ -476,29 +498,12 @@ function createStep(params) {
|
|
|
476
498
|
return abort();
|
|
477
499
|
}
|
|
478
500
|
for await (const chunk of fullStream) {
|
|
479
|
-
|
|
480
|
-
case "text-delta":
|
|
481
|
-
await emitter.emit("watch-v2", {
|
|
482
|
-
type: "tool-call-delta",
|
|
483
|
-
...toolData,
|
|
484
|
-
argsTextDelta: chunk.textDelta
|
|
485
|
-
});
|
|
486
|
-
break;
|
|
487
|
-
case "step-start":
|
|
488
|
-
case "step-finish":
|
|
489
|
-
case "finish":
|
|
490
|
-
break;
|
|
491
|
-
case "tool-call":
|
|
492
|
-
case "tool-result":
|
|
493
|
-
case "tool-call-streaming-start":
|
|
494
|
-
case "tool-call-delta":
|
|
495
|
-
case "source":
|
|
496
|
-
case "file":
|
|
497
|
-
default:
|
|
498
|
-
await emitter.emit("watch-v2", chunk);
|
|
499
|
-
break;
|
|
500
|
-
}
|
|
501
|
+
await emitter.emit("watch-v2", chunk);
|
|
501
502
|
}
|
|
503
|
+
await emitter.emit("watch-v2", {
|
|
504
|
+
type: "workflow-agent-call-finish",
|
|
505
|
+
payload: toolData
|
|
506
|
+
});
|
|
502
507
|
return {
|
|
503
508
|
text: await streamPromise.promise
|
|
504
509
|
};
|
|
@@ -515,11 +520,12 @@ function createStep(params) {
|
|
|
515
520
|
id: params.id,
|
|
516
521
|
inputSchema: params.inputSchema,
|
|
517
522
|
outputSchema: params.outputSchema,
|
|
518
|
-
execute: async ({ inputData, mastra, runtimeContext }) => {
|
|
523
|
+
execute: async ({ inputData, mastra, runtimeContext, tracingContext }) => {
|
|
519
524
|
return params.execute({
|
|
520
525
|
context: inputData,
|
|
521
|
-
mastra,
|
|
522
|
-
runtimeContext
|
|
526
|
+
mastra: aiTracing.wrapMastra(mastra, tracingContext),
|
|
527
|
+
runtimeContext,
|
|
528
|
+
tracingContext
|
|
523
529
|
});
|
|
524
530
|
}
|
|
525
531
|
};
|
|
@@ -573,12 +579,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
573
579
|
}
|
|
574
580
|
async execute(params) {
|
|
575
581
|
await params.emitter.emit("watch-v2", {
|
|
576
|
-
type: "start",
|
|
582
|
+
type: "workflow-start",
|
|
577
583
|
payload: { runId: params.runId }
|
|
578
584
|
});
|
|
579
585
|
const result = await super.execute(params);
|
|
580
586
|
await params.emitter.emit("watch-v2", {
|
|
581
|
-
type: "finish",
|
|
587
|
+
type: "workflow-finish",
|
|
582
588
|
payload: { runId: params.runId }
|
|
583
589
|
});
|
|
584
590
|
return result;
|
|
@@ -640,31 +646,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
640
646
|
executionSpan?.end();
|
|
641
647
|
return base;
|
|
642
648
|
}
|
|
643
|
-
async superExecuteStep({
|
|
644
|
-
workflowId,
|
|
645
|
-
runId,
|
|
646
|
-
step,
|
|
647
|
-
stepResults,
|
|
648
|
-
executionContext,
|
|
649
|
-
resume,
|
|
650
|
-
prevOutput,
|
|
651
|
-
emitter,
|
|
652
|
-
abortController,
|
|
653
|
-
runtimeContext
|
|
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
|
-
});
|
|
667
|
-
}
|
|
668
649
|
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
669
650
|
// await this.inngestStep.sleep(id, duration);
|
|
670
651
|
// }
|
|
@@ -676,17 +657,32 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
676
657
|
stepResults,
|
|
677
658
|
emitter,
|
|
678
659
|
abortController,
|
|
679
|
-
runtimeContext
|
|
660
|
+
runtimeContext,
|
|
661
|
+
writableStream,
|
|
662
|
+
tracingContext
|
|
680
663
|
}) {
|
|
681
664
|
let { duration, fn } = entry;
|
|
665
|
+
const sleepSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
666
|
+
type: aiTracing.AISpanType.WORKFLOW_SLEEP,
|
|
667
|
+
name: `sleep: ${duration ? `${duration}ms` : "dynamic"}`,
|
|
668
|
+
attributes: {
|
|
669
|
+
durationMs: duration,
|
|
670
|
+
sleepType: fn ? "dynamic" : "fixed"
|
|
671
|
+
}
|
|
672
|
+
});
|
|
682
673
|
if (fn) {
|
|
674
|
+
const stepCallId = crypto.randomUUID();
|
|
683
675
|
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
684
676
|
return await fn({
|
|
685
677
|
runId,
|
|
678
|
+
workflowId,
|
|
686
679
|
mastra: this.mastra,
|
|
687
680
|
runtimeContext,
|
|
688
681
|
inputData: prevOutput,
|
|
689
682
|
runCount: -1,
|
|
683
|
+
tracingContext: {
|
|
684
|
+
currentSpan: sleepSpan
|
|
685
|
+
},
|
|
690
686
|
getInitData: () => stepResults?.input,
|
|
691
687
|
getStepResult: (step) => {
|
|
692
688
|
if (!step?.id) {
|
|
@@ -708,11 +704,31 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
708
704
|
},
|
|
709
705
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
710
706
|
engine: { step: this.inngestStep },
|
|
711
|
-
abortSignal: abortController?.signal
|
|
707
|
+
abortSignal: abortController?.signal,
|
|
708
|
+
writer: new tools.ToolStream(
|
|
709
|
+
{
|
|
710
|
+
prefix: "workflow-step",
|
|
711
|
+
callId: stepCallId,
|
|
712
|
+
name: "sleep",
|
|
713
|
+
runId
|
|
714
|
+
},
|
|
715
|
+
writableStream
|
|
716
|
+
)
|
|
712
717
|
});
|
|
713
718
|
});
|
|
719
|
+
sleepSpan?.update({
|
|
720
|
+
attributes: {
|
|
721
|
+
durationMs: duration
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
try {
|
|
726
|
+
await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
|
|
727
|
+
sleepSpan?.end();
|
|
728
|
+
} catch (e) {
|
|
729
|
+
sleepSpan?.error({ error: e });
|
|
730
|
+
throw e;
|
|
714
731
|
}
|
|
715
|
-
await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
|
|
716
732
|
}
|
|
717
733
|
async executeSleepUntil({
|
|
718
734
|
workflowId,
|
|
@@ -722,17 +738,33 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
722
738
|
stepResults,
|
|
723
739
|
emitter,
|
|
724
740
|
abortController,
|
|
725
|
-
runtimeContext
|
|
741
|
+
runtimeContext,
|
|
742
|
+
writableStream,
|
|
743
|
+
tracingContext
|
|
726
744
|
}) {
|
|
727
745
|
let { date, fn } = entry;
|
|
746
|
+
const sleepUntilSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
747
|
+
type: aiTracing.AISpanType.WORKFLOW_SLEEP,
|
|
748
|
+
name: `sleepUntil: ${date ? date.toISOString() : "dynamic"}`,
|
|
749
|
+
attributes: {
|
|
750
|
+
untilDate: date,
|
|
751
|
+
durationMs: date ? Math.max(0, date.getTime() - Date.now()) : void 0,
|
|
752
|
+
sleepType: fn ? "dynamic" : "fixed"
|
|
753
|
+
}
|
|
754
|
+
});
|
|
728
755
|
if (fn) {
|
|
729
756
|
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
757
|
+
const stepCallId = crypto.randomUUID();
|
|
730
758
|
return await fn({
|
|
731
759
|
runId,
|
|
760
|
+
workflowId,
|
|
732
761
|
mastra: this.mastra,
|
|
733
762
|
runtimeContext,
|
|
734
763
|
inputData: prevOutput,
|
|
735
764
|
runCount: -1,
|
|
765
|
+
tracingContext: {
|
|
766
|
+
currentSpan: sleepUntilSpan
|
|
767
|
+
},
|
|
736
768
|
getInitData: () => stepResults?.input,
|
|
737
769
|
getStepResult: (step) => {
|
|
738
770
|
if (!step?.id) {
|
|
@@ -754,14 +786,36 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
754
786
|
},
|
|
755
787
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
756
788
|
engine: { step: this.inngestStep },
|
|
757
|
-
abortSignal: abortController?.signal
|
|
789
|
+
abortSignal: abortController?.signal,
|
|
790
|
+
writer: new tools.ToolStream(
|
|
791
|
+
{
|
|
792
|
+
prefix: "workflow-step",
|
|
793
|
+
callId: stepCallId,
|
|
794
|
+
name: "sleep",
|
|
795
|
+
runId
|
|
796
|
+
},
|
|
797
|
+
writableStream
|
|
798
|
+
)
|
|
758
799
|
});
|
|
759
800
|
});
|
|
801
|
+
const time = !date ? 0 : date.getTime() - Date.now();
|
|
802
|
+
sleepUntilSpan?.update({
|
|
803
|
+
attributes: {
|
|
804
|
+
durationMs: Math.max(0, time)
|
|
805
|
+
}
|
|
806
|
+
});
|
|
760
807
|
}
|
|
761
808
|
if (!(date instanceof Date)) {
|
|
809
|
+
sleepUntilSpan?.end();
|
|
762
810
|
return;
|
|
763
811
|
}
|
|
764
|
-
|
|
812
|
+
try {
|
|
813
|
+
await this.inngestStep.sleepUntil(entry.id, date);
|
|
814
|
+
sleepUntilSpan?.end();
|
|
815
|
+
} catch (e) {
|
|
816
|
+
sleepUntilSpan?.error({ error: e });
|
|
817
|
+
throw e;
|
|
818
|
+
}
|
|
765
819
|
}
|
|
766
820
|
async executeWaitForEvent({ event, timeout }) {
|
|
767
821
|
const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
|
|
@@ -781,8 +835,19 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
781
835
|
prevOutput,
|
|
782
836
|
emitter,
|
|
783
837
|
abortController,
|
|
784
|
-
runtimeContext
|
|
838
|
+
runtimeContext,
|
|
839
|
+
tracingContext,
|
|
840
|
+
writableStream,
|
|
841
|
+
disableScorers
|
|
785
842
|
}) {
|
|
843
|
+
const stepAISpan = tracingContext?.currentSpan?.createChildSpan({
|
|
844
|
+
name: `workflow step: '${step.id}'`,
|
|
845
|
+
type: aiTracing.AISpanType.WORKFLOW_STEP,
|
|
846
|
+
input: prevOutput,
|
|
847
|
+
attributes: {
|
|
848
|
+
stepId: step.id
|
|
849
|
+
}
|
|
850
|
+
});
|
|
786
851
|
const startedAt = await this.inngestStep.run(
|
|
787
852
|
`workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
|
|
788
853
|
async () => {
|
|
@@ -809,7 +874,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
809
874
|
eventTimestamp: Date.now()
|
|
810
875
|
});
|
|
811
876
|
await emitter.emit("watch-v2", {
|
|
812
|
-
type: "step-start",
|
|
877
|
+
type: "workflow-step-start",
|
|
813
878
|
payload: {
|
|
814
879
|
id: step.id,
|
|
815
880
|
status: "running",
|
|
@@ -879,7 +944,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
879
944
|
eventTimestamp: Date.now()
|
|
880
945
|
});
|
|
881
946
|
await emitter.emit("watch-v2", {
|
|
882
|
-
type: "step-result",
|
|
947
|
+
type: "workflow-step-result",
|
|
883
948
|
payload: {
|
|
884
949
|
id: step.id,
|
|
885
950
|
status: "failed",
|
|
@@ -914,7 +979,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
914
979
|
eventTimestamp: Date.now()
|
|
915
980
|
});
|
|
916
981
|
await emitter.emit("watch-v2", {
|
|
917
|
-
type: "step-suspended",
|
|
982
|
+
type: "workflow-step-suspended",
|
|
918
983
|
payload: {
|
|
919
984
|
id: step.id,
|
|
920
985
|
status: "suspended"
|
|
@@ -971,7 +1036,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
971
1036
|
eventTimestamp: Date.now()
|
|
972
1037
|
});
|
|
973
1038
|
await emitter.emit("watch-v2", {
|
|
974
|
-
type: "step-result",
|
|
1039
|
+
type: "workflow-step-result",
|
|
975
1040
|
payload: {
|
|
976
1041
|
id: step.id,
|
|
977
1042
|
status: "success",
|
|
@@ -979,7 +1044,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
979
1044
|
}
|
|
980
1045
|
});
|
|
981
1046
|
await emitter.emit("watch-v2", {
|
|
982
|
-
type: "step-finish",
|
|
1047
|
+
type: "workflow-step-finish",
|
|
983
1048
|
payload: {
|
|
984
1049
|
id: step.id,
|
|
985
1050
|
metadata: {}
|
|
@@ -1000,8 +1065,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1000
1065
|
runId: executionContext.runId,
|
|
1001
1066
|
mastra: this.mastra,
|
|
1002
1067
|
runtimeContext,
|
|
1068
|
+
writableStream,
|
|
1003
1069
|
inputData: prevOutput,
|
|
1004
1070
|
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1071
|
+
tracingContext: {
|
|
1072
|
+
currentSpan: stepAISpan
|
|
1073
|
+
},
|
|
1005
1074
|
getInitData: () => stepResults?.input,
|
|
1006
1075
|
getStepResult: (step2) => {
|
|
1007
1076
|
const result2 = stepResults[step2.id];
|
|
@@ -1065,7 +1134,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1065
1134
|
}
|
|
1066
1135
|
if (execResults.status === "failed") {
|
|
1067
1136
|
if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
|
|
1068
|
-
|
|
1137
|
+
const error = new Error(execResults.error);
|
|
1138
|
+
stepAISpan?.error({ error });
|
|
1139
|
+
throw error;
|
|
1069
1140
|
}
|
|
1070
1141
|
}
|
|
1071
1142
|
await emitter.emit("watch", {
|
|
@@ -1086,7 +1157,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1086
1157
|
});
|
|
1087
1158
|
if (execResults.status === "suspended") {
|
|
1088
1159
|
await emitter.emit("watch-v2", {
|
|
1089
|
-
type: "step-suspended",
|
|
1160
|
+
type: "workflow-step-suspended",
|
|
1090
1161
|
payload: {
|
|
1091
1162
|
id: step.id,
|
|
1092
1163
|
...execResults
|
|
@@ -1094,22 +1165,39 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1094
1165
|
});
|
|
1095
1166
|
} else {
|
|
1096
1167
|
await emitter.emit("watch-v2", {
|
|
1097
|
-
type: "step-result",
|
|
1168
|
+
type: "workflow-step-result",
|
|
1098
1169
|
payload: {
|
|
1099
1170
|
id: step.id,
|
|
1100
1171
|
...execResults
|
|
1101
1172
|
}
|
|
1102
1173
|
});
|
|
1103
1174
|
await emitter.emit("watch-v2", {
|
|
1104
|
-
type: "step-finish",
|
|
1175
|
+
type: "workflow-step-finish",
|
|
1105
1176
|
payload: {
|
|
1106
1177
|
id: step.id,
|
|
1107
1178
|
metadata: {}
|
|
1108
1179
|
}
|
|
1109
1180
|
});
|
|
1110
1181
|
}
|
|
1182
|
+
stepAISpan?.end({ output: execResults });
|
|
1111
1183
|
return { result: execResults, executionContext, stepResults };
|
|
1112
1184
|
});
|
|
1185
|
+
if (disableScorers !== false) {
|
|
1186
|
+
await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}.score`, async () => {
|
|
1187
|
+
if (step.scorers) {
|
|
1188
|
+
await this.runScorers({
|
|
1189
|
+
scorers: step.scorers,
|
|
1190
|
+
runId: executionContext.runId,
|
|
1191
|
+
input: prevOutput,
|
|
1192
|
+
output: stepRes.result,
|
|
1193
|
+
workflowId: executionContext.workflowId,
|
|
1194
|
+
stepId: step.id,
|
|
1195
|
+
runtimeContext,
|
|
1196
|
+
disableScorers
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
});
|
|
1200
|
+
}
|
|
1113
1201
|
Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
|
|
1114
1202
|
Object.assign(stepResults, stepRes.stepResults);
|
|
1115
1203
|
return stepRes.result;
|
|
@@ -1136,6 +1224,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1136
1224
|
context: stepResults,
|
|
1137
1225
|
activePaths: [],
|
|
1138
1226
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1227
|
+
waitingPaths: {},
|
|
1139
1228
|
serializedStepGraph,
|
|
1140
1229
|
status: workflowStatus,
|
|
1141
1230
|
result,
|
|
@@ -1159,19 +1248,42 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1159
1248
|
executionContext,
|
|
1160
1249
|
emitter,
|
|
1161
1250
|
abortController,
|
|
1162
|
-
runtimeContext
|
|
1251
|
+
runtimeContext,
|
|
1252
|
+
writableStream,
|
|
1253
|
+
disableScorers,
|
|
1254
|
+
tracingContext
|
|
1163
1255
|
}) {
|
|
1256
|
+
const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
1257
|
+
type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL,
|
|
1258
|
+
name: `conditional: ${entry.conditions.length} conditions`,
|
|
1259
|
+
input: prevOutput,
|
|
1260
|
+
attributes: {
|
|
1261
|
+
conditionCount: entry.conditions.length
|
|
1262
|
+
}
|
|
1263
|
+
});
|
|
1164
1264
|
let execResults;
|
|
1165
1265
|
const truthyIndexes = (await Promise.all(
|
|
1166
1266
|
entry.conditions.map(
|
|
1167
1267
|
(cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
|
|
1268
|
+
const evalSpan = conditionalSpan?.createChildSpan({
|
|
1269
|
+
type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL_EVAL,
|
|
1270
|
+
name: `condition ${index}`,
|
|
1271
|
+
input: prevOutput,
|
|
1272
|
+
attributes: {
|
|
1273
|
+
conditionIndex: index
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1168
1276
|
try {
|
|
1169
1277
|
const result = await cond({
|
|
1170
1278
|
runId,
|
|
1279
|
+
workflowId,
|
|
1171
1280
|
mastra: this.mastra,
|
|
1172
1281
|
runtimeContext,
|
|
1173
1282
|
runCount: -1,
|
|
1174
1283
|
inputData: prevOutput,
|
|
1284
|
+
tracingContext: {
|
|
1285
|
+
currentSpan: evalSpan
|
|
1286
|
+
},
|
|
1175
1287
|
getInitData: () => stepResults?.input,
|
|
1176
1288
|
getStepResult: (step) => {
|
|
1177
1289
|
if (!step?.id) {
|
|
@@ -1195,26 +1307,53 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1195
1307
|
engine: {
|
|
1196
1308
|
step: this.inngestStep
|
|
1197
1309
|
},
|
|
1198
|
-
abortSignal: abortController.signal
|
|
1310
|
+
abortSignal: abortController.signal,
|
|
1311
|
+
writer: new tools.ToolStream(
|
|
1312
|
+
{
|
|
1313
|
+
prefix: "workflow-step",
|
|
1314
|
+
callId: crypto.randomUUID(),
|
|
1315
|
+
name: "conditional",
|
|
1316
|
+
runId
|
|
1317
|
+
},
|
|
1318
|
+
writableStream
|
|
1319
|
+
)
|
|
1320
|
+
});
|
|
1321
|
+
evalSpan?.end({
|
|
1322
|
+
output: result,
|
|
1323
|
+
attributes: {
|
|
1324
|
+
result: !!result
|
|
1325
|
+
}
|
|
1199
1326
|
});
|
|
1200
1327
|
return result ? index : null;
|
|
1201
1328
|
} catch (e) {
|
|
1329
|
+
evalSpan?.error({
|
|
1330
|
+
error: e instanceof Error ? e : new Error(String(e)),
|
|
1331
|
+
attributes: {
|
|
1332
|
+
result: false
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1202
1335
|
return null;
|
|
1203
1336
|
}
|
|
1204
1337
|
})
|
|
1205
1338
|
)
|
|
1206
1339
|
)).filter((index) => index !== null);
|
|
1207
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
|
+
});
|
|
1208
1347
|
const results = await Promise.all(
|
|
1209
1348
|
stepsToRun.map(
|
|
1210
1349
|
(step, index) => this.executeEntry({
|
|
1211
1350
|
workflowId,
|
|
1212
1351
|
runId,
|
|
1213
1352
|
entry: step,
|
|
1353
|
+
serializedStepGraph,
|
|
1214
1354
|
prevStep,
|
|
1215
1355
|
stepResults,
|
|
1216
1356
|
resume,
|
|
1217
|
-
serializedStepGraph,
|
|
1218
1357
|
executionContext: {
|
|
1219
1358
|
workflowId,
|
|
1220
1359
|
runId,
|
|
@@ -1225,7 +1364,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1225
1364
|
},
|
|
1226
1365
|
emitter,
|
|
1227
1366
|
abortController,
|
|
1228
|
-
runtimeContext
|
|
1367
|
+
runtimeContext,
|
|
1368
|
+
writableStream,
|
|
1369
|
+
disableScorers,
|
|
1370
|
+
tracingContext: {
|
|
1371
|
+
currentSpan: conditionalSpan
|
|
1372
|
+
}
|
|
1229
1373
|
})
|
|
1230
1374
|
)
|
|
1231
1375
|
);
|
|
@@ -1246,6 +1390,15 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1246
1390
|
}, {})
|
|
1247
1391
|
};
|
|
1248
1392
|
}
|
|
1393
|
+
if (execResults.status === "failed") {
|
|
1394
|
+
conditionalSpan?.error({
|
|
1395
|
+
error: new Error(execResults.error)
|
|
1396
|
+
});
|
|
1397
|
+
} else {
|
|
1398
|
+
conditionalSpan?.end({
|
|
1399
|
+
output: execResults.output || execResults
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1249
1402
|
return execResults;
|
|
1250
1403
|
}
|
|
1251
1404
|
};
|
|
@@ -1256,3 +1409,5 @@ exports.InngestWorkflow = InngestWorkflow;
|
|
|
1256
1409
|
exports.createStep = createStep;
|
|
1257
1410
|
exports.init = init;
|
|
1258
1411
|
exports.serve = serve;
|
|
1412
|
+
//# sourceMappingURL=index.cjs.map
|
|
1413
|
+
//# sourceMappingURL=index.cjs.map
|