@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.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
2
|
import { subscribe } from '@inngest/realtime';
|
|
3
|
+
import { wrapMastra, AISpanType } from '@mastra/core/ai-tracing';
|
|
3
4
|
import { RuntimeContext } from '@mastra/core/di';
|
|
4
|
-
import { Tool } from '@mastra/core/tools';
|
|
5
|
+
import { ToolStream, Tool } from '@mastra/core/tools';
|
|
5
6
|
import { Run, Workflow, DefaultExecutionEngine } from '@mastra/core/workflows';
|
|
6
|
-
import { EMITTER_SYMBOL } from '@mastra/core/workflows/_constants';
|
|
7
|
+
import { EMITTER_SYMBOL, STREAM_FORMAT_SYMBOL } from '@mastra/core/workflows/_constants';
|
|
7
8
|
import { serve as serve$1 } from 'inngest/hono';
|
|
8
9
|
import { z } from 'zod';
|
|
9
10
|
|
|
@@ -104,6 +105,7 @@ var InngestRun = class extends Run {
|
|
|
104
105
|
context: {},
|
|
105
106
|
activePaths: [],
|
|
106
107
|
suspendedPaths: {},
|
|
108
|
+
waitingPaths: {},
|
|
107
109
|
timestamp: Date.now(),
|
|
108
110
|
status: "running"
|
|
109
111
|
}
|
|
@@ -153,6 +155,7 @@ var InngestRun = class extends Run {
|
|
|
153
155
|
data: {
|
|
154
156
|
inputData: params.resumeData,
|
|
155
157
|
runId: this.runId,
|
|
158
|
+
workflowId: this.workflowId,
|
|
156
159
|
stepResults: snapshot?.context,
|
|
157
160
|
resume: {
|
|
158
161
|
steps,
|
|
@@ -199,10 +202,38 @@ var InngestRun = class extends Run {
|
|
|
199
202
|
}
|
|
200
203
|
stream({ inputData, runtimeContext } = {}) {
|
|
201
204
|
const { readable, writable } = new TransformStream();
|
|
205
|
+
let currentToolData = void 0;
|
|
202
206
|
const writer = writable.getWriter();
|
|
203
207
|
const unwatch = this.watch(async (event) => {
|
|
208
|
+
if (event.type === "workflow-agent-call-start") {
|
|
209
|
+
currentToolData = {
|
|
210
|
+
name: event.payload.name,
|
|
211
|
+
args: event.payload.args
|
|
212
|
+
};
|
|
213
|
+
await writer.write({
|
|
214
|
+
...event.payload,
|
|
215
|
+
type: "tool-call-streaming-start"
|
|
216
|
+
});
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
204
219
|
try {
|
|
205
|
-
|
|
220
|
+
if (event.type === "workflow-agent-call-finish") {
|
|
221
|
+
return;
|
|
222
|
+
} else if (!event.type.startsWith("workflow-")) {
|
|
223
|
+
if (event.type === "text-delta") {
|
|
224
|
+
await writer.write({
|
|
225
|
+
type: "tool-call-delta",
|
|
226
|
+
...currentToolData ?? {},
|
|
227
|
+
argsTextDelta: event.textDelta
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const e = {
|
|
233
|
+
...event,
|
|
234
|
+
type: event.type.replace("workflow-", "")
|
|
235
|
+
};
|
|
236
|
+
await writer.write(e);
|
|
206
237
|
} catch {
|
|
207
238
|
}
|
|
208
239
|
}, "watch-v2");
|
|
@@ -233,8 +264,14 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
233
264
|
#mastra;
|
|
234
265
|
inngest;
|
|
235
266
|
function;
|
|
267
|
+
flowControlConfig;
|
|
236
268
|
constructor(params, inngest) {
|
|
237
|
-
|
|
269
|
+
const { concurrency, rateLimit, throttle, debounce, priority, ...workflowParams } = params;
|
|
270
|
+
super(workflowParams);
|
|
271
|
+
const flowControlEntries = Object.entries({ concurrency, rateLimit, throttle, debounce, priority }).filter(
|
|
272
|
+
([_, value]) => value !== void 0
|
|
273
|
+
);
|
|
274
|
+
this.flowControlConfig = flowControlEntries.length > 0 ? Object.fromEntries(flowControlEntries) : void 0;
|
|
238
275
|
this.#mastra = params.mastra;
|
|
239
276
|
this.inngest = inngest;
|
|
240
277
|
}
|
|
@@ -255,27 +292,6 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
255
292
|
const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
|
|
256
293
|
return run ?? (this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null);
|
|
257
294
|
}
|
|
258
|
-
async getWorkflowRunExecutionResult(runId) {
|
|
259
|
-
const storage = this.#mastra?.getStorage();
|
|
260
|
-
if (!storage) {
|
|
261
|
-
this.logger.debug("Cannot get workflow run execution result. Mastra storage is not initialized");
|
|
262
|
-
return null;
|
|
263
|
-
}
|
|
264
|
-
const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
|
|
265
|
-
if (!run?.snapshot) {
|
|
266
|
-
return null;
|
|
267
|
-
}
|
|
268
|
-
if (typeof run.snapshot === "string") {
|
|
269
|
-
return null;
|
|
270
|
-
}
|
|
271
|
-
return {
|
|
272
|
-
status: run.snapshot.status,
|
|
273
|
-
result: run.snapshot.result,
|
|
274
|
-
error: run.snapshot.error,
|
|
275
|
-
payload: run.snapshot.context?.input,
|
|
276
|
-
steps: run.snapshot.context
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
295
|
__registerMastra(mastra) {
|
|
280
296
|
this.#mastra = mastra;
|
|
281
297
|
this.executionEngine.__registerMastra(mastra);
|
|
@@ -328,7 +344,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
328
344
|
this.inngest
|
|
329
345
|
);
|
|
330
346
|
this.runs.set(runIdToUse, run);
|
|
331
|
-
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse);
|
|
347
|
+
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, false);
|
|
332
348
|
if (!workflowSnapshotInStorage) {
|
|
333
349
|
await this.mastra?.getStorage()?.persistWorkflowSnapshot({
|
|
334
350
|
workflowName: this.id,
|
|
@@ -339,6 +355,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
339
355
|
value: {},
|
|
340
356
|
context: {},
|
|
341
357
|
activePaths: [],
|
|
358
|
+
waitingPaths: {},
|
|
342
359
|
serializedStepGraph: this.serializedStepGraph,
|
|
343
360
|
suspendedPaths: {},
|
|
344
361
|
result: void 0,
|
|
@@ -359,7 +376,9 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
359
376
|
id: `workflow.${this.id}`,
|
|
360
377
|
// @ts-ignore
|
|
361
378
|
retries: this.retryConfig?.attempts ?? 0,
|
|
362
|
-
cancelOn: [{ event: `cancel.workflow.${this.id}` }]
|
|
379
|
+
cancelOn: [{ event: `cancel.workflow.${this.id}` }],
|
|
380
|
+
// Spread flow control configuration
|
|
381
|
+
...this.flowControlConfig
|
|
363
382
|
},
|
|
364
383
|
{ event: `workflow.${this.id}` },
|
|
365
384
|
async ({ event, step, attempt, publish }) => {
|
|
@@ -403,7 +422,9 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
403
422
|
runtimeContext: new RuntimeContext(),
|
|
404
423
|
// TODO
|
|
405
424
|
resume,
|
|
406
|
-
abortController: new AbortController()
|
|
425
|
+
abortController: new AbortController(),
|
|
426
|
+
currentSpan: void 0
|
|
427
|
+
// TODO: Pass actual parent AI span from workflow execution context
|
|
407
428
|
});
|
|
408
429
|
return { result, runId };
|
|
409
430
|
}
|
|
@@ -447,7 +468,7 @@ function createStep(params) {
|
|
|
447
468
|
outputSchema: z.object({
|
|
448
469
|
text: z.string()
|
|
449
470
|
}),
|
|
450
|
-
execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort }) => {
|
|
471
|
+
execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort, tracingContext }) => {
|
|
451
472
|
let streamPromise = {};
|
|
452
473
|
streamPromise.promise = new Promise((resolve, reject) => {
|
|
453
474
|
streamPromise.resolve = resolve;
|
|
@@ -458,13 +479,14 @@ function createStep(params) {
|
|
|
458
479
|
args: inputData
|
|
459
480
|
};
|
|
460
481
|
await emitter.emit("watch-v2", {
|
|
461
|
-
type: "
|
|
462
|
-
|
|
482
|
+
type: "workflow-agent-call-start",
|
|
483
|
+
payload: toolData
|
|
463
484
|
});
|
|
464
485
|
const { fullStream } = await params.stream(inputData.prompt, {
|
|
465
486
|
// resourceId: inputData.resourceId,
|
|
466
487
|
// threadId: inputData.threadId,
|
|
467
488
|
runtimeContext,
|
|
489
|
+
tracingContext,
|
|
468
490
|
onFinish: (result) => {
|
|
469
491
|
streamPromise.resolve(result.text);
|
|
470
492
|
},
|
|
@@ -474,29 +496,12 @@ function createStep(params) {
|
|
|
474
496
|
return abort();
|
|
475
497
|
}
|
|
476
498
|
for await (const chunk of fullStream) {
|
|
477
|
-
|
|
478
|
-
case "text-delta":
|
|
479
|
-
await emitter.emit("watch-v2", {
|
|
480
|
-
type: "tool-call-delta",
|
|
481
|
-
...toolData,
|
|
482
|
-
argsTextDelta: chunk.textDelta
|
|
483
|
-
});
|
|
484
|
-
break;
|
|
485
|
-
case "step-start":
|
|
486
|
-
case "step-finish":
|
|
487
|
-
case "finish":
|
|
488
|
-
break;
|
|
489
|
-
case "tool-call":
|
|
490
|
-
case "tool-result":
|
|
491
|
-
case "tool-call-streaming-start":
|
|
492
|
-
case "tool-call-delta":
|
|
493
|
-
case "source":
|
|
494
|
-
case "file":
|
|
495
|
-
default:
|
|
496
|
-
await emitter.emit("watch-v2", chunk);
|
|
497
|
-
break;
|
|
498
|
-
}
|
|
499
|
+
await emitter.emit("watch-v2", chunk);
|
|
499
500
|
}
|
|
501
|
+
await emitter.emit("watch-v2", {
|
|
502
|
+
type: "workflow-agent-call-finish",
|
|
503
|
+
payload: toolData
|
|
504
|
+
});
|
|
500
505
|
return {
|
|
501
506
|
text: await streamPromise.promise
|
|
502
507
|
};
|
|
@@ -513,11 +518,12 @@ function createStep(params) {
|
|
|
513
518
|
id: params.id,
|
|
514
519
|
inputSchema: params.inputSchema,
|
|
515
520
|
outputSchema: params.outputSchema,
|
|
516
|
-
execute: async ({ inputData, mastra, runtimeContext }) => {
|
|
521
|
+
execute: async ({ inputData, mastra, runtimeContext, tracingContext }) => {
|
|
517
522
|
return params.execute({
|
|
518
523
|
context: inputData,
|
|
519
|
-
mastra,
|
|
520
|
-
runtimeContext
|
|
524
|
+
mastra: wrapMastra(mastra, tracingContext),
|
|
525
|
+
runtimeContext,
|
|
526
|
+
tracingContext
|
|
521
527
|
});
|
|
522
528
|
}
|
|
523
529
|
};
|
|
@@ -571,12 +577,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
571
577
|
}
|
|
572
578
|
async execute(params) {
|
|
573
579
|
await params.emitter.emit("watch-v2", {
|
|
574
|
-
type: "start",
|
|
580
|
+
type: "workflow-start",
|
|
575
581
|
payload: { runId: params.runId }
|
|
576
582
|
});
|
|
577
583
|
const result = await super.execute(params);
|
|
578
584
|
await params.emitter.emit("watch-v2", {
|
|
579
|
-
type: "finish",
|
|
585
|
+
type: "workflow-finish",
|
|
580
586
|
payload: { runId: params.runId }
|
|
581
587
|
});
|
|
582
588
|
return result;
|
|
@@ -638,33 +644,182 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
638
644
|
executionSpan?.end();
|
|
639
645
|
return base;
|
|
640
646
|
}
|
|
641
|
-
async
|
|
647
|
+
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
648
|
+
// await this.inngestStep.sleep(id, duration);
|
|
649
|
+
// }
|
|
650
|
+
async executeSleep({
|
|
642
651
|
workflowId,
|
|
643
652
|
runId,
|
|
644
|
-
|
|
653
|
+
entry,
|
|
654
|
+
prevOutput,
|
|
645
655
|
stepResults,
|
|
656
|
+
emitter,
|
|
657
|
+
abortController,
|
|
658
|
+
runtimeContext,
|
|
646
659
|
executionContext,
|
|
647
|
-
|
|
660
|
+
writableStream,
|
|
661
|
+
tracingContext
|
|
662
|
+
}) {
|
|
663
|
+
let { duration, fn } = entry;
|
|
664
|
+
const sleepSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
665
|
+
type: AISpanType.WORKFLOW_SLEEP,
|
|
666
|
+
name: `sleep: ${duration ? `${duration}ms` : "dynamic"}`,
|
|
667
|
+
attributes: {
|
|
668
|
+
durationMs: duration,
|
|
669
|
+
sleepType: fn ? "dynamic" : "fixed"
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
if (fn) {
|
|
673
|
+
const stepCallId = randomUUID();
|
|
674
|
+
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
675
|
+
return await fn({
|
|
676
|
+
runId,
|
|
677
|
+
workflowId,
|
|
678
|
+
mastra: this.mastra,
|
|
679
|
+
runtimeContext,
|
|
680
|
+
inputData: prevOutput,
|
|
681
|
+
runCount: -1,
|
|
682
|
+
tracingContext: {
|
|
683
|
+
currentSpan: sleepSpan
|
|
684
|
+
},
|
|
685
|
+
getInitData: () => stepResults?.input,
|
|
686
|
+
getStepResult: (step) => {
|
|
687
|
+
if (!step?.id) {
|
|
688
|
+
return null;
|
|
689
|
+
}
|
|
690
|
+
const result = stepResults[step.id];
|
|
691
|
+
if (result?.status === "success") {
|
|
692
|
+
return result.output;
|
|
693
|
+
}
|
|
694
|
+
return null;
|
|
695
|
+
},
|
|
696
|
+
// TODO: this function shouldn't have suspend probably?
|
|
697
|
+
suspend: async (_suspendPayload) => {
|
|
698
|
+
},
|
|
699
|
+
bail: () => {
|
|
700
|
+
},
|
|
701
|
+
abort: () => {
|
|
702
|
+
abortController?.abort();
|
|
703
|
+
},
|
|
704
|
+
[EMITTER_SYMBOL]: emitter,
|
|
705
|
+
// TODO: add streamVNext support
|
|
706
|
+
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
707
|
+
engine: { step: this.inngestStep },
|
|
708
|
+
abortSignal: abortController?.signal,
|
|
709
|
+
writer: new ToolStream(
|
|
710
|
+
{
|
|
711
|
+
prefix: "workflow-step",
|
|
712
|
+
callId: stepCallId,
|
|
713
|
+
name: "sleep",
|
|
714
|
+
runId
|
|
715
|
+
},
|
|
716
|
+
writableStream
|
|
717
|
+
)
|
|
718
|
+
});
|
|
719
|
+
});
|
|
720
|
+
sleepSpan?.update({
|
|
721
|
+
attributes: {
|
|
722
|
+
durationMs: duration
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
try {
|
|
727
|
+
await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
|
|
728
|
+
sleepSpan?.end();
|
|
729
|
+
} catch (e) {
|
|
730
|
+
sleepSpan?.error({ error: e });
|
|
731
|
+
throw e;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
async executeSleepUntil({
|
|
735
|
+
workflowId,
|
|
736
|
+
runId,
|
|
737
|
+
entry,
|
|
648
738
|
prevOutput,
|
|
739
|
+
stepResults,
|
|
649
740
|
emitter,
|
|
650
741
|
abortController,
|
|
651
|
-
runtimeContext
|
|
742
|
+
runtimeContext,
|
|
743
|
+
executionContext,
|
|
744
|
+
writableStream,
|
|
745
|
+
tracingContext
|
|
652
746
|
}) {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
abortController,
|
|
663
|
-
runtimeContext
|
|
747
|
+
let { date, fn } = entry;
|
|
748
|
+
const sleepUntilSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
749
|
+
type: AISpanType.WORKFLOW_SLEEP,
|
|
750
|
+
name: `sleepUntil: ${date ? date.toISOString() : "dynamic"}`,
|
|
751
|
+
attributes: {
|
|
752
|
+
untilDate: date,
|
|
753
|
+
durationMs: date ? Math.max(0, date.getTime() - Date.now()) : void 0,
|
|
754
|
+
sleepType: fn ? "dynamic" : "fixed"
|
|
755
|
+
}
|
|
664
756
|
});
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
757
|
+
if (fn) {
|
|
758
|
+
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
759
|
+
const stepCallId = randomUUID();
|
|
760
|
+
return await fn({
|
|
761
|
+
runId,
|
|
762
|
+
workflowId,
|
|
763
|
+
mastra: this.mastra,
|
|
764
|
+
runtimeContext,
|
|
765
|
+
inputData: prevOutput,
|
|
766
|
+
runCount: -1,
|
|
767
|
+
tracingContext: {
|
|
768
|
+
currentSpan: sleepUntilSpan
|
|
769
|
+
},
|
|
770
|
+
getInitData: () => stepResults?.input,
|
|
771
|
+
getStepResult: (step) => {
|
|
772
|
+
if (!step?.id) {
|
|
773
|
+
return null;
|
|
774
|
+
}
|
|
775
|
+
const result = stepResults[step.id];
|
|
776
|
+
if (result?.status === "success") {
|
|
777
|
+
return result.output;
|
|
778
|
+
}
|
|
779
|
+
return null;
|
|
780
|
+
},
|
|
781
|
+
// TODO: this function shouldn't have suspend probably?
|
|
782
|
+
suspend: async (_suspendPayload) => {
|
|
783
|
+
},
|
|
784
|
+
bail: () => {
|
|
785
|
+
},
|
|
786
|
+
abort: () => {
|
|
787
|
+
abortController?.abort();
|
|
788
|
+
},
|
|
789
|
+
[EMITTER_SYMBOL]: emitter,
|
|
790
|
+
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
791
|
+
// TODO: add streamVNext support
|
|
792
|
+
engine: { step: this.inngestStep },
|
|
793
|
+
abortSignal: abortController?.signal,
|
|
794
|
+
writer: new ToolStream(
|
|
795
|
+
{
|
|
796
|
+
prefix: "workflow-step",
|
|
797
|
+
callId: stepCallId,
|
|
798
|
+
name: "sleep",
|
|
799
|
+
runId
|
|
800
|
+
},
|
|
801
|
+
writableStream
|
|
802
|
+
)
|
|
803
|
+
});
|
|
804
|
+
});
|
|
805
|
+
const time = !date ? 0 : date.getTime() - Date.now();
|
|
806
|
+
sleepUntilSpan?.update({
|
|
807
|
+
attributes: {
|
|
808
|
+
durationMs: Math.max(0, time)
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
if (!(date instanceof Date)) {
|
|
813
|
+
sleepUntilSpan?.end();
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
try {
|
|
817
|
+
await this.inngestStep.sleepUntil(entry.id, date);
|
|
818
|
+
sleepUntilSpan?.end();
|
|
819
|
+
} catch (e) {
|
|
820
|
+
sleepUntilSpan?.error({ error: e });
|
|
821
|
+
throw e;
|
|
822
|
+
}
|
|
668
823
|
}
|
|
669
824
|
async executeWaitForEvent({ event, timeout }) {
|
|
670
825
|
const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
|
|
@@ -684,8 +839,19 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
684
839
|
prevOutput,
|
|
685
840
|
emitter,
|
|
686
841
|
abortController,
|
|
687
|
-
runtimeContext
|
|
842
|
+
runtimeContext,
|
|
843
|
+
tracingContext,
|
|
844
|
+
writableStream,
|
|
845
|
+
disableScorers
|
|
688
846
|
}) {
|
|
847
|
+
const stepAISpan = tracingContext?.currentSpan?.createChildSpan({
|
|
848
|
+
name: `workflow step: '${step.id}'`,
|
|
849
|
+
type: AISpanType.WORKFLOW_STEP,
|
|
850
|
+
input: prevOutput,
|
|
851
|
+
attributes: {
|
|
852
|
+
stepId: step.id
|
|
853
|
+
}
|
|
854
|
+
});
|
|
689
855
|
const startedAt = await this.inngestStep.run(
|
|
690
856
|
`workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
|
|
691
857
|
async () => {
|
|
@@ -712,7 +878,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
712
878
|
eventTimestamp: Date.now()
|
|
713
879
|
});
|
|
714
880
|
await emitter.emit("watch-v2", {
|
|
715
|
-
type: "step-start",
|
|
881
|
+
type: "workflow-step-start",
|
|
716
882
|
payload: {
|
|
717
883
|
id: step.id,
|
|
718
884
|
status: "running",
|
|
@@ -782,7 +948,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
782
948
|
eventTimestamp: Date.now()
|
|
783
949
|
});
|
|
784
950
|
await emitter.emit("watch-v2", {
|
|
785
|
-
type: "step-result",
|
|
951
|
+
type: "workflow-step-result",
|
|
786
952
|
payload: {
|
|
787
953
|
id: step.id,
|
|
788
954
|
status: "failed",
|
|
@@ -817,7 +983,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
817
983
|
eventTimestamp: Date.now()
|
|
818
984
|
});
|
|
819
985
|
await emitter.emit("watch-v2", {
|
|
820
|
-
type: "step-suspended",
|
|
986
|
+
type: "workflow-step-suspended",
|
|
821
987
|
payload: {
|
|
822
988
|
id: step.id,
|
|
823
989
|
status: "suspended"
|
|
@@ -874,7 +1040,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
874
1040
|
eventTimestamp: Date.now()
|
|
875
1041
|
});
|
|
876
1042
|
await emitter.emit("watch-v2", {
|
|
877
|
-
type: "step-result",
|
|
1043
|
+
type: "workflow-step-result",
|
|
878
1044
|
payload: {
|
|
879
1045
|
id: step.id,
|
|
880
1046
|
status: "success",
|
|
@@ -882,7 +1048,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
882
1048
|
}
|
|
883
1049
|
});
|
|
884
1050
|
await emitter.emit("watch-v2", {
|
|
885
|
-
type: "step-finish",
|
|
1051
|
+
type: "workflow-step-finish",
|
|
886
1052
|
payload: {
|
|
887
1053
|
id: step.id,
|
|
888
1054
|
metadata: {}
|
|
@@ -903,8 +1069,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
903
1069
|
runId: executionContext.runId,
|
|
904
1070
|
mastra: this.mastra,
|
|
905
1071
|
runtimeContext,
|
|
1072
|
+
writableStream,
|
|
906
1073
|
inputData: prevOutput,
|
|
907
1074
|
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1075
|
+
tracingContext: {
|
|
1076
|
+
currentSpan: stepAISpan
|
|
1077
|
+
},
|
|
908
1078
|
getInitData: () => stepResults?.input,
|
|
909
1079
|
getStepResult: (step2) => {
|
|
910
1080
|
const result2 = stepResults[step2.id];
|
|
@@ -968,7 +1138,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
968
1138
|
}
|
|
969
1139
|
if (execResults.status === "failed") {
|
|
970
1140
|
if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
|
|
971
|
-
|
|
1141
|
+
const error = new Error(execResults.error);
|
|
1142
|
+
stepAISpan?.error({ error });
|
|
1143
|
+
throw error;
|
|
972
1144
|
}
|
|
973
1145
|
}
|
|
974
1146
|
await emitter.emit("watch", {
|
|
@@ -989,7 +1161,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
989
1161
|
});
|
|
990
1162
|
if (execResults.status === "suspended") {
|
|
991
1163
|
await emitter.emit("watch-v2", {
|
|
992
|
-
type: "step-suspended",
|
|
1164
|
+
type: "workflow-step-suspended",
|
|
993
1165
|
payload: {
|
|
994
1166
|
id: step.id,
|
|
995
1167
|
...execResults
|
|
@@ -997,22 +1169,40 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
997
1169
|
});
|
|
998
1170
|
} else {
|
|
999
1171
|
await emitter.emit("watch-v2", {
|
|
1000
|
-
type: "step-result",
|
|
1172
|
+
type: "workflow-step-result",
|
|
1001
1173
|
payload: {
|
|
1002
1174
|
id: step.id,
|
|
1003
1175
|
...execResults
|
|
1004
1176
|
}
|
|
1005
1177
|
});
|
|
1006
1178
|
await emitter.emit("watch-v2", {
|
|
1007
|
-
type: "step-finish",
|
|
1179
|
+
type: "workflow-step-finish",
|
|
1008
1180
|
payload: {
|
|
1009
1181
|
id: step.id,
|
|
1010
1182
|
metadata: {}
|
|
1011
1183
|
}
|
|
1012
1184
|
});
|
|
1013
1185
|
}
|
|
1186
|
+
stepAISpan?.end({ output: execResults });
|
|
1014
1187
|
return { result: execResults, executionContext, stepResults };
|
|
1015
1188
|
});
|
|
1189
|
+
if (disableScorers !== false) {
|
|
1190
|
+
await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}.score`, async () => {
|
|
1191
|
+
if (step.scorers) {
|
|
1192
|
+
await this.runScorers({
|
|
1193
|
+
scorers: step.scorers,
|
|
1194
|
+
runId: executionContext.runId,
|
|
1195
|
+
input: prevOutput,
|
|
1196
|
+
output: stepRes.result,
|
|
1197
|
+
workflowId: executionContext.workflowId,
|
|
1198
|
+
stepId: step.id,
|
|
1199
|
+
runtimeContext,
|
|
1200
|
+
disableScorers,
|
|
1201
|
+
tracingContext: { currentSpan: stepAISpan }
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1016
1206
|
Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
|
|
1017
1207
|
Object.assign(stepResults, stepRes.stepResults);
|
|
1018
1208
|
return stepRes.result;
|
|
@@ -1039,6 +1229,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1039
1229
|
context: stepResults,
|
|
1040
1230
|
activePaths: [],
|
|
1041
1231
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1232
|
+
waitingPaths: {},
|
|
1042
1233
|
serializedStepGraph,
|
|
1043
1234
|
status: workflowStatus,
|
|
1044
1235
|
result,
|
|
@@ -1062,19 +1253,42 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1062
1253
|
executionContext,
|
|
1063
1254
|
emitter,
|
|
1064
1255
|
abortController,
|
|
1065
|
-
runtimeContext
|
|
1256
|
+
runtimeContext,
|
|
1257
|
+
writableStream,
|
|
1258
|
+
disableScorers,
|
|
1259
|
+
tracingContext
|
|
1066
1260
|
}) {
|
|
1261
|
+
const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
1262
|
+
type: AISpanType.WORKFLOW_CONDITIONAL,
|
|
1263
|
+
name: `conditional: ${entry.conditions.length} conditions`,
|
|
1264
|
+
input: prevOutput,
|
|
1265
|
+
attributes: {
|
|
1266
|
+
conditionCount: entry.conditions.length
|
|
1267
|
+
}
|
|
1268
|
+
});
|
|
1067
1269
|
let execResults;
|
|
1068
1270
|
const truthyIndexes = (await Promise.all(
|
|
1069
1271
|
entry.conditions.map(
|
|
1070
1272
|
(cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
|
|
1273
|
+
const evalSpan = conditionalSpan?.createChildSpan({
|
|
1274
|
+
type: AISpanType.WORKFLOW_CONDITIONAL_EVAL,
|
|
1275
|
+
name: `condition ${index}`,
|
|
1276
|
+
input: prevOutput,
|
|
1277
|
+
attributes: {
|
|
1278
|
+
conditionIndex: index
|
|
1279
|
+
}
|
|
1280
|
+
});
|
|
1071
1281
|
try {
|
|
1072
1282
|
const result = await cond({
|
|
1073
1283
|
runId,
|
|
1284
|
+
workflowId,
|
|
1074
1285
|
mastra: this.mastra,
|
|
1075
1286
|
runtimeContext,
|
|
1076
1287
|
runCount: -1,
|
|
1077
1288
|
inputData: prevOutput,
|
|
1289
|
+
tracingContext: {
|
|
1290
|
+
currentSpan: evalSpan
|
|
1291
|
+
},
|
|
1078
1292
|
getInitData: () => stepResults?.input,
|
|
1079
1293
|
getStepResult: (step) => {
|
|
1080
1294
|
if (!step?.id) {
|
|
@@ -1095,29 +1309,58 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1095
1309
|
abortController.abort();
|
|
1096
1310
|
},
|
|
1097
1311
|
[EMITTER_SYMBOL]: emitter,
|
|
1312
|
+
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1313
|
+
// TODO: add streamVNext support
|
|
1098
1314
|
engine: {
|
|
1099
1315
|
step: this.inngestStep
|
|
1100
1316
|
},
|
|
1101
|
-
abortSignal: abortController.signal
|
|
1317
|
+
abortSignal: abortController.signal,
|
|
1318
|
+
writer: new ToolStream(
|
|
1319
|
+
{
|
|
1320
|
+
prefix: "workflow-step",
|
|
1321
|
+
callId: randomUUID(),
|
|
1322
|
+
name: "conditional",
|
|
1323
|
+
runId
|
|
1324
|
+
},
|
|
1325
|
+
writableStream
|
|
1326
|
+
)
|
|
1327
|
+
});
|
|
1328
|
+
evalSpan?.end({
|
|
1329
|
+
output: result,
|
|
1330
|
+
attributes: {
|
|
1331
|
+
result: !!result
|
|
1332
|
+
}
|
|
1102
1333
|
});
|
|
1103
1334
|
return result ? index : null;
|
|
1104
1335
|
} catch (e) {
|
|
1336
|
+
evalSpan?.error({
|
|
1337
|
+
error: e instanceof Error ? e : new Error(String(e)),
|
|
1338
|
+
attributes: {
|
|
1339
|
+
result: false
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1105
1342
|
return null;
|
|
1106
1343
|
}
|
|
1107
1344
|
})
|
|
1108
1345
|
)
|
|
1109
1346
|
)).filter((index) => index !== null);
|
|
1110
1347
|
const stepsToRun = entry.steps.filter((_, index) => truthyIndexes.includes(index));
|
|
1348
|
+
conditionalSpan?.update({
|
|
1349
|
+
attributes: {
|
|
1350
|
+
truthyIndexes,
|
|
1351
|
+
selectedSteps: stepsToRun.map((s) => s.type === "step" ? s.step.id : `control-${s.type}`)
|
|
1352
|
+
}
|
|
1353
|
+
});
|
|
1111
1354
|
const results = await Promise.all(
|
|
1112
1355
|
stepsToRun.map(
|
|
1113
1356
|
(step, index) => this.executeEntry({
|
|
1114
1357
|
workflowId,
|
|
1115
1358
|
runId,
|
|
1116
1359
|
entry: step,
|
|
1360
|
+
serializedStepGraph,
|
|
1117
1361
|
prevStep,
|
|
1118
1362
|
stepResults,
|
|
1119
1363
|
resume,
|
|
1120
|
-
serializedStepGraph,
|
|
1121
1364
|
executionContext: {
|
|
1122
1365
|
workflowId,
|
|
1123
1366
|
runId,
|
|
@@ -1128,7 +1371,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1128
1371
|
},
|
|
1129
1372
|
emitter,
|
|
1130
1373
|
abortController,
|
|
1131
|
-
runtimeContext
|
|
1374
|
+
runtimeContext,
|
|
1375
|
+
writableStream,
|
|
1376
|
+
disableScorers,
|
|
1377
|
+
tracingContext: {
|
|
1378
|
+
currentSpan: conditionalSpan
|
|
1379
|
+
}
|
|
1132
1380
|
})
|
|
1133
1381
|
)
|
|
1134
1382
|
);
|
|
@@ -1149,8 +1397,19 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1149
1397
|
}, {})
|
|
1150
1398
|
};
|
|
1151
1399
|
}
|
|
1400
|
+
if (execResults.status === "failed") {
|
|
1401
|
+
conditionalSpan?.error({
|
|
1402
|
+
error: new Error(execResults.error)
|
|
1403
|
+
});
|
|
1404
|
+
} else {
|
|
1405
|
+
conditionalSpan?.end({
|
|
1406
|
+
output: execResults.output || execResults
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1152
1409
|
return execResults;
|
|
1153
1410
|
}
|
|
1154
1411
|
};
|
|
1155
1412
|
|
|
1156
1413
|
export { InngestExecutionEngine, InngestRun, InngestWorkflow, createStep, init, serve };
|
|
1414
|
+
//# sourceMappingURL=index.js.map
|
|
1415
|
+
//# sourceMappingURL=index.js.map
|