@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.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,31 +644,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
638
644
|
executionSpan?.end();
|
|
639
645
|
return base;
|
|
640
646
|
}
|
|
641
|
-
async superExecuteStep({
|
|
642
|
-
workflowId,
|
|
643
|
-
runId,
|
|
644
|
-
step,
|
|
645
|
-
stepResults,
|
|
646
|
-
executionContext,
|
|
647
|
-
resume,
|
|
648
|
-
prevOutput,
|
|
649
|
-
emitter,
|
|
650
|
-
abortController,
|
|
651
|
-
runtimeContext
|
|
652
|
-
}) {
|
|
653
|
-
return super.executeStep({
|
|
654
|
-
workflowId,
|
|
655
|
-
runId,
|
|
656
|
-
step,
|
|
657
|
-
stepResults,
|
|
658
|
-
executionContext,
|
|
659
|
-
resume,
|
|
660
|
-
prevOutput,
|
|
661
|
-
emitter,
|
|
662
|
-
abortController,
|
|
663
|
-
runtimeContext
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
647
|
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
667
648
|
// await this.inngestStep.sleep(id, duration);
|
|
668
649
|
// }
|
|
@@ -674,17 +655,33 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
674
655
|
stepResults,
|
|
675
656
|
emitter,
|
|
676
657
|
abortController,
|
|
677
|
-
runtimeContext
|
|
658
|
+
runtimeContext,
|
|
659
|
+
executionContext,
|
|
660
|
+
writableStream,
|
|
661
|
+
tracingContext
|
|
678
662
|
}) {
|
|
679
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
|
+
});
|
|
680
672
|
if (fn) {
|
|
673
|
+
const stepCallId = randomUUID();
|
|
681
674
|
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
682
675
|
return await fn({
|
|
683
676
|
runId,
|
|
677
|
+
workflowId,
|
|
684
678
|
mastra: this.mastra,
|
|
685
679
|
runtimeContext,
|
|
686
680
|
inputData: prevOutput,
|
|
687
681
|
runCount: -1,
|
|
682
|
+
tracingContext: {
|
|
683
|
+
currentSpan: sleepSpan
|
|
684
|
+
},
|
|
688
685
|
getInitData: () => stepResults?.input,
|
|
689
686
|
getStepResult: (step) => {
|
|
690
687
|
if (!step?.id) {
|
|
@@ -705,12 +702,34 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
705
702
|
abortController?.abort();
|
|
706
703
|
},
|
|
707
704
|
[EMITTER_SYMBOL]: emitter,
|
|
705
|
+
// TODO: add streamVNext support
|
|
706
|
+
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
708
707
|
engine: { step: this.inngestStep },
|
|
709
|
-
abortSignal: abortController?.signal
|
|
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
|
+
)
|
|
710
718
|
});
|
|
711
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;
|
|
712
732
|
}
|
|
713
|
-
await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
|
|
714
733
|
}
|
|
715
734
|
async executeSleepUntil({
|
|
716
735
|
workflowId,
|
|
@@ -720,17 +739,34 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
720
739
|
stepResults,
|
|
721
740
|
emitter,
|
|
722
741
|
abortController,
|
|
723
|
-
runtimeContext
|
|
742
|
+
runtimeContext,
|
|
743
|
+
executionContext,
|
|
744
|
+
writableStream,
|
|
745
|
+
tracingContext
|
|
724
746
|
}) {
|
|
725
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
|
+
}
|
|
756
|
+
});
|
|
726
757
|
if (fn) {
|
|
727
758
|
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
759
|
+
const stepCallId = randomUUID();
|
|
728
760
|
return await fn({
|
|
729
761
|
runId,
|
|
762
|
+
workflowId,
|
|
730
763
|
mastra: this.mastra,
|
|
731
764
|
runtimeContext,
|
|
732
765
|
inputData: prevOutput,
|
|
733
766
|
runCount: -1,
|
|
767
|
+
tracingContext: {
|
|
768
|
+
currentSpan: sleepUntilSpan
|
|
769
|
+
},
|
|
734
770
|
getInitData: () => stepResults?.input,
|
|
735
771
|
getStepResult: (step) => {
|
|
736
772
|
if (!step?.id) {
|
|
@@ -751,15 +787,39 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
751
787
|
abortController?.abort();
|
|
752
788
|
},
|
|
753
789
|
[EMITTER_SYMBOL]: emitter,
|
|
790
|
+
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
791
|
+
// TODO: add streamVNext support
|
|
754
792
|
engine: { step: this.inngestStep },
|
|
755
|
-
abortSignal: abortController?.signal
|
|
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
|
+
)
|
|
756
803
|
});
|
|
757
804
|
});
|
|
805
|
+
const time = !date ? 0 : date.getTime() - Date.now();
|
|
806
|
+
sleepUntilSpan?.update({
|
|
807
|
+
attributes: {
|
|
808
|
+
durationMs: Math.max(0, time)
|
|
809
|
+
}
|
|
810
|
+
});
|
|
758
811
|
}
|
|
759
812
|
if (!(date instanceof Date)) {
|
|
813
|
+
sleepUntilSpan?.end();
|
|
760
814
|
return;
|
|
761
815
|
}
|
|
762
|
-
|
|
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
|
+
}
|
|
763
823
|
}
|
|
764
824
|
async executeWaitForEvent({ event, timeout }) {
|
|
765
825
|
const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
|
|
@@ -779,8 +839,19 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
779
839
|
prevOutput,
|
|
780
840
|
emitter,
|
|
781
841
|
abortController,
|
|
782
|
-
runtimeContext
|
|
842
|
+
runtimeContext,
|
|
843
|
+
tracingContext,
|
|
844
|
+
writableStream,
|
|
845
|
+
disableScorers
|
|
783
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
|
+
});
|
|
784
855
|
const startedAt = await this.inngestStep.run(
|
|
785
856
|
`workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
|
|
786
857
|
async () => {
|
|
@@ -807,7 +878,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
807
878
|
eventTimestamp: Date.now()
|
|
808
879
|
});
|
|
809
880
|
await emitter.emit("watch-v2", {
|
|
810
|
-
type: "step-start",
|
|
881
|
+
type: "workflow-step-start",
|
|
811
882
|
payload: {
|
|
812
883
|
id: step.id,
|
|
813
884
|
status: "running",
|
|
@@ -877,7 +948,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
877
948
|
eventTimestamp: Date.now()
|
|
878
949
|
});
|
|
879
950
|
await emitter.emit("watch-v2", {
|
|
880
|
-
type: "step-result",
|
|
951
|
+
type: "workflow-step-result",
|
|
881
952
|
payload: {
|
|
882
953
|
id: step.id,
|
|
883
954
|
status: "failed",
|
|
@@ -912,7 +983,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
912
983
|
eventTimestamp: Date.now()
|
|
913
984
|
});
|
|
914
985
|
await emitter.emit("watch-v2", {
|
|
915
|
-
type: "step-suspended",
|
|
986
|
+
type: "workflow-step-suspended",
|
|
916
987
|
payload: {
|
|
917
988
|
id: step.id,
|
|
918
989
|
status: "suspended"
|
|
@@ -969,7 +1040,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
969
1040
|
eventTimestamp: Date.now()
|
|
970
1041
|
});
|
|
971
1042
|
await emitter.emit("watch-v2", {
|
|
972
|
-
type: "step-result",
|
|
1043
|
+
type: "workflow-step-result",
|
|
973
1044
|
payload: {
|
|
974
1045
|
id: step.id,
|
|
975
1046
|
status: "success",
|
|
@@ -977,7 +1048,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
977
1048
|
}
|
|
978
1049
|
});
|
|
979
1050
|
await emitter.emit("watch-v2", {
|
|
980
|
-
type: "step-finish",
|
|
1051
|
+
type: "workflow-step-finish",
|
|
981
1052
|
payload: {
|
|
982
1053
|
id: step.id,
|
|
983
1054
|
metadata: {}
|
|
@@ -998,8 +1069,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
998
1069
|
runId: executionContext.runId,
|
|
999
1070
|
mastra: this.mastra,
|
|
1000
1071
|
runtimeContext,
|
|
1072
|
+
writableStream,
|
|
1001
1073
|
inputData: prevOutput,
|
|
1002
1074
|
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1075
|
+
tracingContext: {
|
|
1076
|
+
currentSpan: stepAISpan
|
|
1077
|
+
},
|
|
1003
1078
|
getInitData: () => stepResults?.input,
|
|
1004
1079
|
getStepResult: (step2) => {
|
|
1005
1080
|
const result2 = stepResults[step2.id];
|
|
@@ -1063,7 +1138,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1063
1138
|
}
|
|
1064
1139
|
if (execResults.status === "failed") {
|
|
1065
1140
|
if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
|
|
1066
|
-
|
|
1141
|
+
const error = new Error(execResults.error);
|
|
1142
|
+
stepAISpan?.error({ error });
|
|
1143
|
+
throw error;
|
|
1067
1144
|
}
|
|
1068
1145
|
}
|
|
1069
1146
|
await emitter.emit("watch", {
|
|
@@ -1084,7 +1161,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1084
1161
|
});
|
|
1085
1162
|
if (execResults.status === "suspended") {
|
|
1086
1163
|
await emitter.emit("watch-v2", {
|
|
1087
|
-
type: "step-suspended",
|
|
1164
|
+
type: "workflow-step-suspended",
|
|
1088
1165
|
payload: {
|
|
1089
1166
|
id: step.id,
|
|
1090
1167
|
...execResults
|
|
@@ -1092,22 +1169,40 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1092
1169
|
});
|
|
1093
1170
|
} else {
|
|
1094
1171
|
await emitter.emit("watch-v2", {
|
|
1095
|
-
type: "step-result",
|
|
1172
|
+
type: "workflow-step-result",
|
|
1096
1173
|
payload: {
|
|
1097
1174
|
id: step.id,
|
|
1098
1175
|
...execResults
|
|
1099
1176
|
}
|
|
1100
1177
|
});
|
|
1101
1178
|
await emitter.emit("watch-v2", {
|
|
1102
|
-
type: "step-finish",
|
|
1179
|
+
type: "workflow-step-finish",
|
|
1103
1180
|
payload: {
|
|
1104
1181
|
id: step.id,
|
|
1105
1182
|
metadata: {}
|
|
1106
1183
|
}
|
|
1107
1184
|
});
|
|
1108
1185
|
}
|
|
1186
|
+
stepAISpan?.end({ output: execResults });
|
|
1109
1187
|
return { result: execResults, executionContext, stepResults };
|
|
1110
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
|
+
}
|
|
1111
1206
|
Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
|
|
1112
1207
|
Object.assign(stepResults, stepRes.stepResults);
|
|
1113
1208
|
return stepRes.result;
|
|
@@ -1134,6 +1229,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1134
1229
|
context: stepResults,
|
|
1135
1230
|
activePaths: [],
|
|
1136
1231
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1232
|
+
waitingPaths: {},
|
|
1137
1233
|
serializedStepGraph,
|
|
1138
1234
|
status: workflowStatus,
|
|
1139
1235
|
result,
|
|
@@ -1157,19 +1253,42 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1157
1253
|
executionContext,
|
|
1158
1254
|
emitter,
|
|
1159
1255
|
abortController,
|
|
1160
|
-
runtimeContext
|
|
1256
|
+
runtimeContext,
|
|
1257
|
+
writableStream,
|
|
1258
|
+
disableScorers,
|
|
1259
|
+
tracingContext
|
|
1161
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
|
+
});
|
|
1162
1269
|
let execResults;
|
|
1163
1270
|
const truthyIndexes = (await Promise.all(
|
|
1164
1271
|
entry.conditions.map(
|
|
1165
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
|
+
});
|
|
1166
1281
|
try {
|
|
1167
1282
|
const result = await cond({
|
|
1168
1283
|
runId,
|
|
1284
|
+
workflowId,
|
|
1169
1285
|
mastra: this.mastra,
|
|
1170
1286
|
runtimeContext,
|
|
1171
1287
|
runCount: -1,
|
|
1172
1288
|
inputData: prevOutput,
|
|
1289
|
+
tracingContext: {
|
|
1290
|
+
currentSpan: evalSpan
|
|
1291
|
+
},
|
|
1173
1292
|
getInitData: () => stepResults?.input,
|
|
1174
1293
|
getStepResult: (step) => {
|
|
1175
1294
|
if (!step?.id) {
|
|
@@ -1190,29 +1309,58 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1190
1309
|
abortController.abort();
|
|
1191
1310
|
},
|
|
1192
1311
|
[EMITTER_SYMBOL]: emitter,
|
|
1312
|
+
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1313
|
+
// TODO: add streamVNext support
|
|
1193
1314
|
engine: {
|
|
1194
1315
|
step: this.inngestStep
|
|
1195
1316
|
},
|
|
1196
|
-
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
|
+
}
|
|
1197
1333
|
});
|
|
1198
1334
|
return result ? index : null;
|
|
1199
1335
|
} catch (e) {
|
|
1336
|
+
evalSpan?.error({
|
|
1337
|
+
error: e instanceof Error ? e : new Error(String(e)),
|
|
1338
|
+
attributes: {
|
|
1339
|
+
result: false
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1200
1342
|
return null;
|
|
1201
1343
|
}
|
|
1202
1344
|
})
|
|
1203
1345
|
)
|
|
1204
1346
|
)).filter((index) => index !== null);
|
|
1205
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
|
+
});
|
|
1206
1354
|
const results = await Promise.all(
|
|
1207
1355
|
stepsToRun.map(
|
|
1208
1356
|
(step, index) => this.executeEntry({
|
|
1209
1357
|
workflowId,
|
|
1210
1358
|
runId,
|
|
1211
1359
|
entry: step,
|
|
1360
|
+
serializedStepGraph,
|
|
1212
1361
|
prevStep,
|
|
1213
1362
|
stepResults,
|
|
1214
1363
|
resume,
|
|
1215
|
-
serializedStepGraph,
|
|
1216
1364
|
executionContext: {
|
|
1217
1365
|
workflowId,
|
|
1218
1366
|
runId,
|
|
@@ -1223,7 +1371,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1223
1371
|
},
|
|
1224
1372
|
emitter,
|
|
1225
1373
|
abortController,
|
|
1226
|
-
runtimeContext
|
|
1374
|
+
runtimeContext,
|
|
1375
|
+
writableStream,
|
|
1376
|
+
disableScorers,
|
|
1377
|
+
tracingContext: {
|
|
1378
|
+
currentSpan: conditionalSpan
|
|
1379
|
+
}
|
|
1227
1380
|
})
|
|
1228
1381
|
)
|
|
1229
1382
|
);
|
|
@@ -1244,8 +1397,19 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1244
1397
|
}, {})
|
|
1245
1398
|
};
|
|
1246
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
|
+
}
|
|
1247
1409
|
return execResults;
|
|
1248
1410
|
}
|
|
1249
1411
|
};
|
|
1250
1412
|
|
|
1251
1413
|
export { InngestExecutionEngine, InngestRun, InngestWorkflow, createStep, init, serve };
|
|
1414
|
+
//# sourceMappingURL=index.js.map
|
|
1415
|
+
//# sourceMappingURL=index.js.map
|