@mastra/inngest 0.0.0-http-transporter-20250702160118 → 0.0.0-issue-7498-20250905233741
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 +529 -2
- package/LICENSE.md +11 -42
- package/dist/index.cjs +347 -88
- 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 +349 -90
- package/dist/index.js.map +1 -0
- package/package.json +29 -15
- package/dist/_tsup-dts-rollup.d.cts +0 -265
- package/dist/_tsup-dts-rollup.d.ts +0 -265
- 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 -7130
- package/src/index.ts +0 -1586
- 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,33 +646,182 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
640
646
|
executionSpan?.end();
|
|
641
647
|
return base;
|
|
642
648
|
}
|
|
643
|
-
async
|
|
649
|
+
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
650
|
+
// await this.inngestStep.sleep(id, duration);
|
|
651
|
+
// }
|
|
652
|
+
async executeSleep({
|
|
644
653
|
workflowId,
|
|
645
654
|
runId,
|
|
646
|
-
|
|
655
|
+
entry,
|
|
656
|
+
prevOutput,
|
|
647
657
|
stepResults,
|
|
658
|
+
emitter,
|
|
659
|
+
abortController,
|
|
660
|
+
runtimeContext,
|
|
648
661
|
executionContext,
|
|
649
|
-
|
|
662
|
+
writableStream,
|
|
663
|
+
tracingContext
|
|
664
|
+
}) {
|
|
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
|
+
});
|
|
674
|
+
if (fn) {
|
|
675
|
+
const stepCallId = crypto.randomUUID();
|
|
676
|
+
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
677
|
+
return await fn({
|
|
678
|
+
runId,
|
|
679
|
+
workflowId,
|
|
680
|
+
mastra: this.mastra,
|
|
681
|
+
runtimeContext,
|
|
682
|
+
inputData: prevOutput,
|
|
683
|
+
runCount: -1,
|
|
684
|
+
tracingContext: {
|
|
685
|
+
currentSpan: sleepSpan
|
|
686
|
+
},
|
|
687
|
+
getInitData: () => stepResults?.input,
|
|
688
|
+
getStepResult: (step) => {
|
|
689
|
+
if (!step?.id) {
|
|
690
|
+
return null;
|
|
691
|
+
}
|
|
692
|
+
const result = stepResults[step.id];
|
|
693
|
+
if (result?.status === "success") {
|
|
694
|
+
return result.output;
|
|
695
|
+
}
|
|
696
|
+
return null;
|
|
697
|
+
},
|
|
698
|
+
// TODO: this function shouldn't have suspend probably?
|
|
699
|
+
suspend: async (_suspendPayload) => {
|
|
700
|
+
},
|
|
701
|
+
bail: () => {
|
|
702
|
+
},
|
|
703
|
+
abort: () => {
|
|
704
|
+
abortController?.abort();
|
|
705
|
+
},
|
|
706
|
+
[_constants.EMITTER_SYMBOL]: emitter,
|
|
707
|
+
// TODO: add streamVNext support
|
|
708
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
709
|
+
engine: { step: this.inngestStep },
|
|
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
|
+
)
|
|
720
|
+
});
|
|
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;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
async executeSleepUntil({
|
|
737
|
+
workflowId,
|
|
738
|
+
runId,
|
|
739
|
+
entry,
|
|
650
740
|
prevOutput,
|
|
741
|
+
stepResults,
|
|
651
742
|
emitter,
|
|
652
743
|
abortController,
|
|
653
|
-
runtimeContext
|
|
744
|
+
runtimeContext,
|
|
745
|
+
executionContext,
|
|
746
|
+
writableStream,
|
|
747
|
+
tracingContext
|
|
654
748
|
}) {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
abortController,
|
|
665
|
-
runtimeContext
|
|
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
|
+
}
|
|
666
758
|
});
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
759
|
+
if (fn) {
|
|
760
|
+
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
761
|
+
const stepCallId = crypto.randomUUID();
|
|
762
|
+
return await fn({
|
|
763
|
+
runId,
|
|
764
|
+
workflowId,
|
|
765
|
+
mastra: this.mastra,
|
|
766
|
+
runtimeContext,
|
|
767
|
+
inputData: prevOutput,
|
|
768
|
+
runCount: -1,
|
|
769
|
+
tracingContext: {
|
|
770
|
+
currentSpan: sleepUntilSpan
|
|
771
|
+
},
|
|
772
|
+
getInitData: () => stepResults?.input,
|
|
773
|
+
getStepResult: (step) => {
|
|
774
|
+
if (!step?.id) {
|
|
775
|
+
return null;
|
|
776
|
+
}
|
|
777
|
+
const result = stepResults[step.id];
|
|
778
|
+
if (result?.status === "success") {
|
|
779
|
+
return result.output;
|
|
780
|
+
}
|
|
781
|
+
return null;
|
|
782
|
+
},
|
|
783
|
+
// TODO: this function shouldn't have suspend probably?
|
|
784
|
+
suspend: async (_suspendPayload) => {
|
|
785
|
+
},
|
|
786
|
+
bail: () => {
|
|
787
|
+
},
|
|
788
|
+
abort: () => {
|
|
789
|
+
abortController?.abort();
|
|
790
|
+
},
|
|
791
|
+
[_constants.EMITTER_SYMBOL]: emitter,
|
|
792
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
793
|
+
// TODO: add streamVNext support
|
|
794
|
+
engine: { step: this.inngestStep },
|
|
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
|
+
)
|
|
805
|
+
});
|
|
806
|
+
});
|
|
807
|
+
const time = !date ? 0 : date.getTime() - Date.now();
|
|
808
|
+
sleepUntilSpan?.update({
|
|
809
|
+
attributes: {
|
|
810
|
+
durationMs: Math.max(0, time)
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
if (!(date instanceof Date)) {
|
|
815
|
+
sleepUntilSpan?.end();
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
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
|
+
}
|
|
670
825
|
}
|
|
671
826
|
async executeWaitForEvent({ event, timeout }) {
|
|
672
827
|
const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
|
|
@@ -686,8 +841,19 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
686
841
|
prevOutput,
|
|
687
842
|
emitter,
|
|
688
843
|
abortController,
|
|
689
|
-
runtimeContext
|
|
844
|
+
runtimeContext,
|
|
845
|
+
tracingContext,
|
|
846
|
+
writableStream,
|
|
847
|
+
disableScorers
|
|
690
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
|
+
});
|
|
691
857
|
const startedAt = await this.inngestStep.run(
|
|
692
858
|
`workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
|
|
693
859
|
async () => {
|
|
@@ -714,7 +880,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
714
880
|
eventTimestamp: Date.now()
|
|
715
881
|
});
|
|
716
882
|
await emitter.emit("watch-v2", {
|
|
717
|
-
type: "step-start",
|
|
883
|
+
type: "workflow-step-start",
|
|
718
884
|
payload: {
|
|
719
885
|
id: step.id,
|
|
720
886
|
status: "running",
|
|
@@ -784,7 +950,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
784
950
|
eventTimestamp: Date.now()
|
|
785
951
|
});
|
|
786
952
|
await emitter.emit("watch-v2", {
|
|
787
|
-
type: "step-result",
|
|
953
|
+
type: "workflow-step-result",
|
|
788
954
|
payload: {
|
|
789
955
|
id: step.id,
|
|
790
956
|
status: "failed",
|
|
@@ -819,7 +985,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
819
985
|
eventTimestamp: Date.now()
|
|
820
986
|
});
|
|
821
987
|
await emitter.emit("watch-v2", {
|
|
822
|
-
type: "step-suspended",
|
|
988
|
+
type: "workflow-step-suspended",
|
|
823
989
|
payload: {
|
|
824
990
|
id: step.id,
|
|
825
991
|
status: "suspended"
|
|
@@ -876,7 +1042,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
876
1042
|
eventTimestamp: Date.now()
|
|
877
1043
|
});
|
|
878
1044
|
await emitter.emit("watch-v2", {
|
|
879
|
-
type: "step-result",
|
|
1045
|
+
type: "workflow-step-result",
|
|
880
1046
|
payload: {
|
|
881
1047
|
id: step.id,
|
|
882
1048
|
status: "success",
|
|
@@ -884,7 +1050,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
884
1050
|
}
|
|
885
1051
|
});
|
|
886
1052
|
await emitter.emit("watch-v2", {
|
|
887
|
-
type: "step-finish",
|
|
1053
|
+
type: "workflow-step-finish",
|
|
888
1054
|
payload: {
|
|
889
1055
|
id: step.id,
|
|
890
1056
|
metadata: {}
|
|
@@ -905,8 +1071,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
905
1071
|
runId: executionContext.runId,
|
|
906
1072
|
mastra: this.mastra,
|
|
907
1073
|
runtimeContext,
|
|
1074
|
+
writableStream,
|
|
908
1075
|
inputData: prevOutput,
|
|
909
1076
|
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1077
|
+
tracingContext: {
|
|
1078
|
+
currentSpan: stepAISpan
|
|
1079
|
+
},
|
|
910
1080
|
getInitData: () => stepResults?.input,
|
|
911
1081
|
getStepResult: (step2) => {
|
|
912
1082
|
const result2 = stepResults[step2.id];
|
|
@@ -970,7 +1140,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
970
1140
|
}
|
|
971
1141
|
if (execResults.status === "failed") {
|
|
972
1142
|
if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
|
|
973
|
-
|
|
1143
|
+
const error = new Error(execResults.error);
|
|
1144
|
+
stepAISpan?.error({ error });
|
|
1145
|
+
throw error;
|
|
974
1146
|
}
|
|
975
1147
|
}
|
|
976
1148
|
await emitter.emit("watch", {
|
|
@@ -991,7 +1163,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
991
1163
|
});
|
|
992
1164
|
if (execResults.status === "suspended") {
|
|
993
1165
|
await emitter.emit("watch-v2", {
|
|
994
|
-
type: "step-suspended",
|
|
1166
|
+
type: "workflow-step-suspended",
|
|
995
1167
|
payload: {
|
|
996
1168
|
id: step.id,
|
|
997
1169
|
...execResults
|
|
@@ -999,22 +1171,40 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
999
1171
|
});
|
|
1000
1172
|
} else {
|
|
1001
1173
|
await emitter.emit("watch-v2", {
|
|
1002
|
-
type: "step-result",
|
|
1174
|
+
type: "workflow-step-result",
|
|
1003
1175
|
payload: {
|
|
1004
1176
|
id: step.id,
|
|
1005
1177
|
...execResults
|
|
1006
1178
|
}
|
|
1007
1179
|
});
|
|
1008
1180
|
await emitter.emit("watch-v2", {
|
|
1009
|
-
type: "step-finish",
|
|
1181
|
+
type: "workflow-step-finish",
|
|
1010
1182
|
payload: {
|
|
1011
1183
|
id: step.id,
|
|
1012
1184
|
metadata: {}
|
|
1013
1185
|
}
|
|
1014
1186
|
});
|
|
1015
1187
|
}
|
|
1188
|
+
stepAISpan?.end({ output: execResults });
|
|
1016
1189
|
return { result: execResults, executionContext, stepResults };
|
|
1017
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
|
+
}
|
|
1018
1208
|
Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
|
|
1019
1209
|
Object.assign(stepResults, stepRes.stepResults);
|
|
1020
1210
|
return stepRes.result;
|
|
@@ -1041,6 +1231,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1041
1231
|
context: stepResults,
|
|
1042
1232
|
activePaths: [],
|
|
1043
1233
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1234
|
+
waitingPaths: {},
|
|
1044
1235
|
serializedStepGraph,
|
|
1045
1236
|
status: workflowStatus,
|
|
1046
1237
|
result,
|
|
@@ -1064,19 +1255,42 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1064
1255
|
executionContext,
|
|
1065
1256
|
emitter,
|
|
1066
1257
|
abortController,
|
|
1067
|
-
runtimeContext
|
|
1258
|
+
runtimeContext,
|
|
1259
|
+
writableStream,
|
|
1260
|
+
disableScorers,
|
|
1261
|
+
tracingContext
|
|
1068
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
|
+
});
|
|
1069
1271
|
let execResults;
|
|
1070
1272
|
const truthyIndexes = (await Promise.all(
|
|
1071
1273
|
entry.conditions.map(
|
|
1072
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
|
+
});
|
|
1073
1283
|
try {
|
|
1074
1284
|
const result = await cond({
|
|
1075
1285
|
runId,
|
|
1286
|
+
workflowId,
|
|
1076
1287
|
mastra: this.mastra,
|
|
1077
1288
|
runtimeContext,
|
|
1078
1289
|
runCount: -1,
|
|
1079
1290
|
inputData: prevOutput,
|
|
1291
|
+
tracingContext: {
|
|
1292
|
+
currentSpan: evalSpan
|
|
1293
|
+
},
|
|
1080
1294
|
getInitData: () => stepResults?.input,
|
|
1081
1295
|
getStepResult: (step) => {
|
|
1082
1296
|
if (!step?.id) {
|
|
@@ -1097,29 +1311,58 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1097
1311
|
abortController.abort();
|
|
1098
1312
|
},
|
|
1099
1313
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1314
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1315
|
+
// TODO: add streamVNext support
|
|
1100
1316
|
engine: {
|
|
1101
1317
|
step: this.inngestStep
|
|
1102
1318
|
},
|
|
1103
|
-
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
|
+
}
|
|
1104
1335
|
});
|
|
1105
1336
|
return result ? index : null;
|
|
1106
1337
|
} catch (e) {
|
|
1338
|
+
evalSpan?.error({
|
|
1339
|
+
error: e instanceof Error ? e : new Error(String(e)),
|
|
1340
|
+
attributes: {
|
|
1341
|
+
result: false
|
|
1342
|
+
}
|
|
1343
|
+
});
|
|
1107
1344
|
return null;
|
|
1108
1345
|
}
|
|
1109
1346
|
})
|
|
1110
1347
|
)
|
|
1111
1348
|
)).filter((index) => index !== null);
|
|
1112
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
|
+
});
|
|
1113
1356
|
const results = await Promise.all(
|
|
1114
1357
|
stepsToRun.map(
|
|
1115
1358
|
(step, index) => this.executeEntry({
|
|
1116
1359
|
workflowId,
|
|
1117
1360
|
runId,
|
|
1118
1361
|
entry: step,
|
|
1362
|
+
serializedStepGraph,
|
|
1119
1363
|
prevStep,
|
|
1120
1364
|
stepResults,
|
|
1121
1365
|
resume,
|
|
1122
|
-
serializedStepGraph,
|
|
1123
1366
|
executionContext: {
|
|
1124
1367
|
workflowId,
|
|
1125
1368
|
runId,
|
|
@@ -1130,7 +1373,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1130
1373
|
},
|
|
1131
1374
|
emitter,
|
|
1132
1375
|
abortController,
|
|
1133
|
-
runtimeContext
|
|
1376
|
+
runtimeContext,
|
|
1377
|
+
writableStream,
|
|
1378
|
+
disableScorers,
|
|
1379
|
+
tracingContext: {
|
|
1380
|
+
currentSpan: conditionalSpan
|
|
1381
|
+
}
|
|
1134
1382
|
})
|
|
1135
1383
|
)
|
|
1136
1384
|
);
|
|
@@ -1151,6 +1399,15 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1151
1399
|
}, {})
|
|
1152
1400
|
};
|
|
1153
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
|
+
}
|
|
1154
1411
|
return execResults;
|
|
1155
1412
|
}
|
|
1156
1413
|
};
|
|
@@ -1161,3 +1418,5 @@ exports.InngestWorkflow = InngestWorkflow;
|
|
|
1161
1418
|
exports.createStep = createStep;
|
|
1162
1419
|
exports.init = init;
|
|
1163
1420
|
exports.serve = serve;
|
|
1421
|
+
//# sourceMappingURL=index.cjs.map
|
|
1422
|
+
//# sourceMappingURL=index.cjs.map
|