@mastra/inngest 0.0.0-message-list-update-20250715150321 → 0.0.0-message-file-url-handling-fix-20250904234524
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 +413 -3
- package/dist/index.cjs +265 -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 +267 -103
- package/dist/index.js.map +1 -0
- package/package.json +28 -14
- package/dist/_tsup-dts-rollup.d.cts +0 -310
- package/dist/_tsup-dts-rollup.d.ts +0 -310
- 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 -7697
- package/src/index.ts +0 -1737
- 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,33 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
676
657
|
stepResults,
|
|
677
658
|
emitter,
|
|
678
659
|
abortController,
|
|
679
|
-
runtimeContext
|
|
660
|
+
runtimeContext,
|
|
661
|
+
executionContext,
|
|
662
|
+
writableStream,
|
|
663
|
+
tracingContext
|
|
680
664
|
}) {
|
|
681
665
|
let { duration, fn } = entry;
|
|
666
|
+
const sleepSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
667
|
+
type: aiTracing.AISpanType.WORKFLOW_SLEEP,
|
|
668
|
+
name: `sleep: ${duration ? `${duration}ms` : "dynamic"}`,
|
|
669
|
+
attributes: {
|
|
670
|
+
durationMs: duration,
|
|
671
|
+
sleepType: fn ? "dynamic" : "fixed"
|
|
672
|
+
}
|
|
673
|
+
});
|
|
682
674
|
if (fn) {
|
|
675
|
+
const stepCallId = crypto.randomUUID();
|
|
683
676
|
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
684
677
|
return await fn({
|
|
685
678
|
runId,
|
|
679
|
+
workflowId,
|
|
686
680
|
mastra: this.mastra,
|
|
687
681
|
runtimeContext,
|
|
688
682
|
inputData: prevOutput,
|
|
689
683
|
runCount: -1,
|
|
684
|
+
tracingContext: {
|
|
685
|
+
currentSpan: sleepSpan
|
|
686
|
+
},
|
|
690
687
|
getInitData: () => stepResults?.input,
|
|
691
688
|
getStepResult: (step) => {
|
|
692
689
|
if (!step?.id) {
|
|
@@ -707,12 +704,34 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
707
704
|
abortController?.abort();
|
|
708
705
|
},
|
|
709
706
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
707
|
+
// TODO: add streamVNext support
|
|
708
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
710
709
|
engine: { step: this.inngestStep },
|
|
711
|
-
abortSignal: abortController?.signal
|
|
710
|
+
abortSignal: abortController?.signal,
|
|
711
|
+
writer: new tools.ToolStream(
|
|
712
|
+
{
|
|
713
|
+
prefix: "workflow-step",
|
|
714
|
+
callId: stepCallId,
|
|
715
|
+
name: "sleep",
|
|
716
|
+
runId
|
|
717
|
+
},
|
|
718
|
+
writableStream
|
|
719
|
+
)
|
|
712
720
|
});
|
|
713
721
|
});
|
|
722
|
+
sleepSpan?.update({
|
|
723
|
+
attributes: {
|
|
724
|
+
durationMs: duration
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
try {
|
|
729
|
+
await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
|
|
730
|
+
sleepSpan?.end();
|
|
731
|
+
} catch (e) {
|
|
732
|
+
sleepSpan?.error({ error: e });
|
|
733
|
+
throw e;
|
|
714
734
|
}
|
|
715
|
-
await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
|
|
716
735
|
}
|
|
717
736
|
async executeSleepUntil({
|
|
718
737
|
workflowId,
|
|
@@ -722,17 +741,34 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
722
741
|
stepResults,
|
|
723
742
|
emitter,
|
|
724
743
|
abortController,
|
|
725
|
-
runtimeContext
|
|
744
|
+
runtimeContext,
|
|
745
|
+
executionContext,
|
|
746
|
+
writableStream,
|
|
747
|
+
tracingContext
|
|
726
748
|
}) {
|
|
727
749
|
let { date, fn } = entry;
|
|
750
|
+
const sleepUntilSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
751
|
+
type: aiTracing.AISpanType.WORKFLOW_SLEEP,
|
|
752
|
+
name: `sleepUntil: ${date ? date.toISOString() : "dynamic"}`,
|
|
753
|
+
attributes: {
|
|
754
|
+
untilDate: date,
|
|
755
|
+
durationMs: date ? Math.max(0, date.getTime() - Date.now()) : void 0,
|
|
756
|
+
sleepType: fn ? "dynamic" : "fixed"
|
|
757
|
+
}
|
|
758
|
+
});
|
|
728
759
|
if (fn) {
|
|
729
760
|
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
761
|
+
const stepCallId = crypto.randomUUID();
|
|
730
762
|
return await fn({
|
|
731
763
|
runId,
|
|
764
|
+
workflowId,
|
|
732
765
|
mastra: this.mastra,
|
|
733
766
|
runtimeContext,
|
|
734
767
|
inputData: prevOutput,
|
|
735
768
|
runCount: -1,
|
|
769
|
+
tracingContext: {
|
|
770
|
+
currentSpan: sleepUntilSpan
|
|
771
|
+
},
|
|
736
772
|
getInitData: () => stepResults?.input,
|
|
737
773
|
getStepResult: (step) => {
|
|
738
774
|
if (!step?.id) {
|
|
@@ -753,15 +789,39 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
753
789
|
abortController?.abort();
|
|
754
790
|
},
|
|
755
791
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
792
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
793
|
+
// TODO: add streamVNext support
|
|
756
794
|
engine: { step: this.inngestStep },
|
|
757
|
-
abortSignal: abortController?.signal
|
|
795
|
+
abortSignal: abortController?.signal,
|
|
796
|
+
writer: new tools.ToolStream(
|
|
797
|
+
{
|
|
798
|
+
prefix: "workflow-step",
|
|
799
|
+
callId: stepCallId,
|
|
800
|
+
name: "sleep",
|
|
801
|
+
runId
|
|
802
|
+
},
|
|
803
|
+
writableStream
|
|
804
|
+
)
|
|
758
805
|
});
|
|
759
806
|
});
|
|
807
|
+
const time = !date ? 0 : date.getTime() - Date.now();
|
|
808
|
+
sleepUntilSpan?.update({
|
|
809
|
+
attributes: {
|
|
810
|
+
durationMs: Math.max(0, time)
|
|
811
|
+
}
|
|
812
|
+
});
|
|
760
813
|
}
|
|
761
814
|
if (!(date instanceof Date)) {
|
|
815
|
+
sleepUntilSpan?.end();
|
|
762
816
|
return;
|
|
763
817
|
}
|
|
764
|
-
|
|
818
|
+
try {
|
|
819
|
+
await this.inngestStep.sleepUntil(entry.id, date);
|
|
820
|
+
sleepUntilSpan?.end();
|
|
821
|
+
} catch (e) {
|
|
822
|
+
sleepUntilSpan?.error({ error: e });
|
|
823
|
+
throw e;
|
|
824
|
+
}
|
|
765
825
|
}
|
|
766
826
|
async executeWaitForEvent({ event, timeout }) {
|
|
767
827
|
const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
|
|
@@ -781,8 +841,19 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
781
841
|
prevOutput,
|
|
782
842
|
emitter,
|
|
783
843
|
abortController,
|
|
784
|
-
runtimeContext
|
|
844
|
+
runtimeContext,
|
|
845
|
+
tracingContext,
|
|
846
|
+
writableStream,
|
|
847
|
+
disableScorers
|
|
785
848
|
}) {
|
|
849
|
+
const stepAISpan = tracingContext?.currentSpan?.createChildSpan({
|
|
850
|
+
name: `workflow step: '${step.id}'`,
|
|
851
|
+
type: aiTracing.AISpanType.WORKFLOW_STEP,
|
|
852
|
+
input: prevOutput,
|
|
853
|
+
attributes: {
|
|
854
|
+
stepId: step.id
|
|
855
|
+
}
|
|
856
|
+
});
|
|
786
857
|
const startedAt = await this.inngestStep.run(
|
|
787
858
|
`workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
|
|
788
859
|
async () => {
|
|
@@ -809,7 +880,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
809
880
|
eventTimestamp: Date.now()
|
|
810
881
|
});
|
|
811
882
|
await emitter.emit("watch-v2", {
|
|
812
|
-
type: "step-start",
|
|
883
|
+
type: "workflow-step-start",
|
|
813
884
|
payload: {
|
|
814
885
|
id: step.id,
|
|
815
886
|
status: "running",
|
|
@@ -879,7 +950,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
879
950
|
eventTimestamp: Date.now()
|
|
880
951
|
});
|
|
881
952
|
await emitter.emit("watch-v2", {
|
|
882
|
-
type: "step-result",
|
|
953
|
+
type: "workflow-step-result",
|
|
883
954
|
payload: {
|
|
884
955
|
id: step.id,
|
|
885
956
|
status: "failed",
|
|
@@ -914,7 +985,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
914
985
|
eventTimestamp: Date.now()
|
|
915
986
|
});
|
|
916
987
|
await emitter.emit("watch-v2", {
|
|
917
|
-
type: "step-suspended",
|
|
988
|
+
type: "workflow-step-suspended",
|
|
918
989
|
payload: {
|
|
919
990
|
id: step.id,
|
|
920
991
|
status: "suspended"
|
|
@@ -971,7 +1042,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
971
1042
|
eventTimestamp: Date.now()
|
|
972
1043
|
});
|
|
973
1044
|
await emitter.emit("watch-v2", {
|
|
974
|
-
type: "step-result",
|
|
1045
|
+
type: "workflow-step-result",
|
|
975
1046
|
payload: {
|
|
976
1047
|
id: step.id,
|
|
977
1048
|
status: "success",
|
|
@@ -979,7 +1050,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
979
1050
|
}
|
|
980
1051
|
});
|
|
981
1052
|
await emitter.emit("watch-v2", {
|
|
982
|
-
type: "step-finish",
|
|
1053
|
+
type: "workflow-step-finish",
|
|
983
1054
|
payload: {
|
|
984
1055
|
id: step.id,
|
|
985
1056
|
metadata: {}
|
|
@@ -1000,8 +1071,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1000
1071
|
runId: executionContext.runId,
|
|
1001
1072
|
mastra: this.mastra,
|
|
1002
1073
|
runtimeContext,
|
|
1074
|
+
writableStream,
|
|
1003
1075
|
inputData: prevOutput,
|
|
1004
1076
|
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1077
|
+
tracingContext: {
|
|
1078
|
+
currentSpan: stepAISpan
|
|
1079
|
+
},
|
|
1005
1080
|
getInitData: () => stepResults?.input,
|
|
1006
1081
|
getStepResult: (step2) => {
|
|
1007
1082
|
const result2 = stepResults[step2.id];
|
|
@@ -1065,7 +1140,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1065
1140
|
}
|
|
1066
1141
|
if (execResults.status === "failed") {
|
|
1067
1142
|
if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
|
|
1068
|
-
|
|
1143
|
+
const error = new Error(execResults.error);
|
|
1144
|
+
stepAISpan?.error({ error });
|
|
1145
|
+
throw error;
|
|
1069
1146
|
}
|
|
1070
1147
|
}
|
|
1071
1148
|
await emitter.emit("watch", {
|
|
@@ -1086,7 +1163,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1086
1163
|
});
|
|
1087
1164
|
if (execResults.status === "suspended") {
|
|
1088
1165
|
await emitter.emit("watch-v2", {
|
|
1089
|
-
type: "step-suspended",
|
|
1166
|
+
type: "workflow-step-suspended",
|
|
1090
1167
|
payload: {
|
|
1091
1168
|
id: step.id,
|
|
1092
1169
|
...execResults
|
|
@@ -1094,22 +1171,40 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1094
1171
|
});
|
|
1095
1172
|
} else {
|
|
1096
1173
|
await emitter.emit("watch-v2", {
|
|
1097
|
-
type: "step-result",
|
|
1174
|
+
type: "workflow-step-result",
|
|
1098
1175
|
payload: {
|
|
1099
1176
|
id: step.id,
|
|
1100
1177
|
...execResults
|
|
1101
1178
|
}
|
|
1102
1179
|
});
|
|
1103
1180
|
await emitter.emit("watch-v2", {
|
|
1104
|
-
type: "step-finish",
|
|
1181
|
+
type: "workflow-step-finish",
|
|
1105
1182
|
payload: {
|
|
1106
1183
|
id: step.id,
|
|
1107
1184
|
metadata: {}
|
|
1108
1185
|
}
|
|
1109
1186
|
});
|
|
1110
1187
|
}
|
|
1188
|
+
stepAISpan?.end({ output: execResults });
|
|
1111
1189
|
return { result: execResults, executionContext, stepResults };
|
|
1112
1190
|
});
|
|
1191
|
+
if (disableScorers !== false) {
|
|
1192
|
+
await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}.score`, async () => {
|
|
1193
|
+
if (step.scorers) {
|
|
1194
|
+
await this.runScorers({
|
|
1195
|
+
scorers: step.scorers,
|
|
1196
|
+
runId: executionContext.runId,
|
|
1197
|
+
input: prevOutput,
|
|
1198
|
+
output: stepRes.result,
|
|
1199
|
+
workflowId: executionContext.workflowId,
|
|
1200
|
+
stepId: step.id,
|
|
1201
|
+
runtimeContext,
|
|
1202
|
+
disableScorers,
|
|
1203
|
+
tracingContext: { currentSpan: stepAISpan }
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1113
1208
|
Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
|
|
1114
1209
|
Object.assign(stepResults, stepRes.stepResults);
|
|
1115
1210
|
return stepRes.result;
|
|
@@ -1136,6 +1231,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1136
1231
|
context: stepResults,
|
|
1137
1232
|
activePaths: [],
|
|
1138
1233
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1234
|
+
waitingPaths: {},
|
|
1139
1235
|
serializedStepGraph,
|
|
1140
1236
|
status: workflowStatus,
|
|
1141
1237
|
result,
|
|
@@ -1159,19 +1255,42 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1159
1255
|
executionContext,
|
|
1160
1256
|
emitter,
|
|
1161
1257
|
abortController,
|
|
1162
|
-
runtimeContext
|
|
1258
|
+
runtimeContext,
|
|
1259
|
+
writableStream,
|
|
1260
|
+
disableScorers,
|
|
1261
|
+
tracingContext
|
|
1163
1262
|
}) {
|
|
1263
|
+
const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
1264
|
+
type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL,
|
|
1265
|
+
name: `conditional: ${entry.conditions.length} conditions`,
|
|
1266
|
+
input: prevOutput,
|
|
1267
|
+
attributes: {
|
|
1268
|
+
conditionCount: entry.conditions.length
|
|
1269
|
+
}
|
|
1270
|
+
});
|
|
1164
1271
|
let execResults;
|
|
1165
1272
|
const truthyIndexes = (await Promise.all(
|
|
1166
1273
|
entry.conditions.map(
|
|
1167
1274
|
(cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
|
|
1275
|
+
const evalSpan = conditionalSpan?.createChildSpan({
|
|
1276
|
+
type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL_EVAL,
|
|
1277
|
+
name: `condition ${index}`,
|
|
1278
|
+
input: prevOutput,
|
|
1279
|
+
attributes: {
|
|
1280
|
+
conditionIndex: index
|
|
1281
|
+
}
|
|
1282
|
+
});
|
|
1168
1283
|
try {
|
|
1169
1284
|
const result = await cond({
|
|
1170
1285
|
runId,
|
|
1286
|
+
workflowId,
|
|
1171
1287
|
mastra: this.mastra,
|
|
1172
1288
|
runtimeContext,
|
|
1173
1289
|
runCount: -1,
|
|
1174
1290
|
inputData: prevOutput,
|
|
1291
|
+
tracingContext: {
|
|
1292
|
+
currentSpan: evalSpan
|
|
1293
|
+
},
|
|
1175
1294
|
getInitData: () => stepResults?.input,
|
|
1176
1295
|
getStepResult: (step) => {
|
|
1177
1296
|
if (!step?.id) {
|
|
@@ -1192,29 +1311,58 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1192
1311
|
abortController.abort();
|
|
1193
1312
|
},
|
|
1194
1313
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1314
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1315
|
+
// TODO: add streamVNext support
|
|
1195
1316
|
engine: {
|
|
1196
1317
|
step: this.inngestStep
|
|
1197
1318
|
},
|
|
1198
|
-
abortSignal: abortController.signal
|
|
1319
|
+
abortSignal: abortController.signal,
|
|
1320
|
+
writer: new tools.ToolStream(
|
|
1321
|
+
{
|
|
1322
|
+
prefix: "workflow-step",
|
|
1323
|
+
callId: crypto.randomUUID(),
|
|
1324
|
+
name: "conditional",
|
|
1325
|
+
runId
|
|
1326
|
+
},
|
|
1327
|
+
writableStream
|
|
1328
|
+
)
|
|
1329
|
+
});
|
|
1330
|
+
evalSpan?.end({
|
|
1331
|
+
output: result,
|
|
1332
|
+
attributes: {
|
|
1333
|
+
result: !!result
|
|
1334
|
+
}
|
|
1199
1335
|
});
|
|
1200
1336
|
return result ? index : null;
|
|
1201
1337
|
} catch (e) {
|
|
1338
|
+
evalSpan?.error({
|
|
1339
|
+
error: e instanceof Error ? e : new Error(String(e)),
|
|
1340
|
+
attributes: {
|
|
1341
|
+
result: false
|
|
1342
|
+
}
|
|
1343
|
+
});
|
|
1202
1344
|
return null;
|
|
1203
1345
|
}
|
|
1204
1346
|
})
|
|
1205
1347
|
)
|
|
1206
1348
|
)).filter((index) => index !== null);
|
|
1207
1349
|
const stepsToRun = entry.steps.filter((_, index) => truthyIndexes.includes(index));
|
|
1350
|
+
conditionalSpan?.update({
|
|
1351
|
+
attributes: {
|
|
1352
|
+
truthyIndexes,
|
|
1353
|
+
selectedSteps: stepsToRun.map((s) => s.type === "step" ? s.step.id : `control-${s.type}`)
|
|
1354
|
+
}
|
|
1355
|
+
});
|
|
1208
1356
|
const results = await Promise.all(
|
|
1209
1357
|
stepsToRun.map(
|
|
1210
1358
|
(step, index) => this.executeEntry({
|
|
1211
1359
|
workflowId,
|
|
1212
1360
|
runId,
|
|
1213
1361
|
entry: step,
|
|
1362
|
+
serializedStepGraph,
|
|
1214
1363
|
prevStep,
|
|
1215
1364
|
stepResults,
|
|
1216
1365
|
resume,
|
|
1217
|
-
serializedStepGraph,
|
|
1218
1366
|
executionContext: {
|
|
1219
1367
|
workflowId,
|
|
1220
1368
|
runId,
|
|
@@ -1225,7 +1373,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1225
1373
|
},
|
|
1226
1374
|
emitter,
|
|
1227
1375
|
abortController,
|
|
1228
|
-
runtimeContext
|
|
1376
|
+
runtimeContext,
|
|
1377
|
+
writableStream,
|
|
1378
|
+
disableScorers,
|
|
1379
|
+
tracingContext: {
|
|
1380
|
+
currentSpan: conditionalSpan
|
|
1381
|
+
}
|
|
1229
1382
|
})
|
|
1230
1383
|
)
|
|
1231
1384
|
);
|
|
@@ -1246,6 +1399,15 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1246
1399
|
}, {})
|
|
1247
1400
|
};
|
|
1248
1401
|
}
|
|
1402
|
+
if (execResults.status === "failed") {
|
|
1403
|
+
conditionalSpan?.error({
|
|
1404
|
+
error: new Error(execResults.error)
|
|
1405
|
+
});
|
|
1406
|
+
} else {
|
|
1407
|
+
conditionalSpan?.end({
|
|
1408
|
+
output: execResults.output || execResults
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1249
1411
|
return execResults;
|
|
1250
1412
|
}
|
|
1251
1413
|
};
|
|
@@ -1256,3 +1418,5 @@ exports.InngestWorkflow = InngestWorkflow;
|
|
|
1256
1418
|
exports.createStep = createStep;
|
|
1257
1419
|
exports.init = init;
|
|
1258
1420
|
exports.serve = serve;
|
|
1421
|
+
//# sourceMappingURL=index.cjs.map
|
|
1422
|
+
//# sourceMappingURL=index.cjs.map
|