@mastra/inngest 0.0.0-consolidate-changesets-20250904042643 → 0.0.0-createToolOptions-20250926094418
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 +216 -20
- package/dist/index.cjs +107 -122
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +31 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +109 -124
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/dist/index.cjs
CHANGED
|
@@ -11,9 +11,14 @@ var hono = require('inngest/hono');
|
|
|
11
11
|
var zod = require('zod');
|
|
12
12
|
|
|
13
13
|
// src/index.ts
|
|
14
|
-
function serve({
|
|
14
|
+
function serve({
|
|
15
|
+
mastra,
|
|
16
|
+
inngest,
|
|
17
|
+
functions: userFunctions = [],
|
|
18
|
+
registerOptions
|
|
19
|
+
}) {
|
|
15
20
|
const wfs = mastra.getWorkflows();
|
|
16
|
-
const
|
|
21
|
+
const workflowFunctions = Array.from(
|
|
17
22
|
new Set(
|
|
18
23
|
Object.values(wfs).flatMap((wf) => {
|
|
19
24
|
if (wf instanceof InngestWorkflow) {
|
|
@@ -25,8 +30,9 @@ function serve({ mastra, inngest }) {
|
|
|
25
30
|
)
|
|
26
31
|
);
|
|
27
32
|
return hono.serve({
|
|
33
|
+
...registerOptions,
|
|
28
34
|
client: inngest,
|
|
29
|
-
functions
|
|
35
|
+
functions: [...workflowFunctions, ...userFunctions]
|
|
30
36
|
});
|
|
31
37
|
}
|
|
32
38
|
var InngestRun = class extends workflows.Run {
|
|
@@ -54,7 +60,6 @@ var InngestRun = class extends workflows.Run {
|
|
|
54
60
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
55
61
|
runs = await this.getRuns(eventId);
|
|
56
62
|
if (runs?.[0]?.status === "Failed") {
|
|
57
|
-
console.log("run", runs?.[0]);
|
|
58
63
|
throw new Error(`Function run ${runs?.[0]?.status}`);
|
|
59
64
|
} else if (runs?.[0]?.status === "Cancelled") {
|
|
60
65
|
const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
|
|
@@ -87,6 +92,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
87
92
|
await this.#mastra?.storage?.persistWorkflowSnapshot({
|
|
88
93
|
workflowName: this.workflowId,
|
|
89
94
|
runId: this.runId,
|
|
95
|
+
resourceId: this.resourceId,
|
|
90
96
|
snapshot: {
|
|
91
97
|
...snapshot,
|
|
92
98
|
status: "canceled"
|
|
@@ -100,6 +106,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
100
106
|
await this.#mastra.getStorage()?.persistWorkflowSnapshot({
|
|
101
107
|
workflowName: this.workflowId,
|
|
102
108
|
runId: this.runId,
|
|
109
|
+
resourceId: this.resourceId,
|
|
103
110
|
snapshot: {
|
|
104
111
|
runId: this.runId,
|
|
105
112
|
serializedStepGraph: this.serializedStepGraph,
|
|
@@ -112,11 +119,13 @@ var InngestRun = class extends workflows.Run {
|
|
|
112
119
|
status: "running"
|
|
113
120
|
}
|
|
114
121
|
});
|
|
122
|
+
const inputDataToUse = await this._validateInput(inputData);
|
|
115
123
|
const eventOutput = await this.inngest.send({
|
|
116
124
|
name: `workflow.${this.workflowId}`,
|
|
117
125
|
data: {
|
|
118
|
-
inputData,
|
|
119
|
-
runId: this.runId
|
|
126
|
+
inputData: inputDataToUse,
|
|
127
|
+
runId: this.runId,
|
|
128
|
+
resourceId: this.resourceId
|
|
120
129
|
}
|
|
121
130
|
});
|
|
122
131
|
const eventId = eventOutput.ids[0];
|
|
@@ -152,17 +161,19 @@ var InngestRun = class extends workflows.Run {
|
|
|
152
161
|
workflowName: this.workflowId,
|
|
153
162
|
runId: this.runId
|
|
154
163
|
});
|
|
164
|
+
const suspendedStep = this.workflowSteps[steps?.[0] ?? ""];
|
|
165
|
+
const resumeDataToUse = await this._validateResumeData(params.resumeData, suspendedStep);
|
|
155
166
|
const eventOutput = await this.inngest.send({
|
|
156
167
|
name: `workflow.${this.workflowId}`,
|
|
157
168
|
data: {
|
|
158
|
-
inputData:
|
|
169
|
+
inputData: resumeDataToUse,
|
|
159
170
|
runId: this.runId,
|
|
160
171
|
workflowId: this.workflowId,
|
|
161
172
|
stepResults: snapshot?.context,
|
|
162
173
|
resume: {
|
|
163
174
|
steps,
|
|
164
175
|
stepResults: snapshot?.context,
|
|
165
|
-
resumePayload:
|
|
176
|
+
resumePayload: resumeDataToUse,
|
|
166
177
|
// @ts-ignore
|
|
167
178
|
resumePath: snapshot?.suspendedPaths?.[steps?.[0]]
|
|
168
179
|
}
|
|
@@ -204,33 +215,9 @@ var InngestRun = class extends workflows.Run {
|
|
|
204
215
|
}
|
|
205
216
|
stream({ inputData, runtimeContext } = {}) {
|
|
206
217
|
const { readable, writable } = new TransformStream();
|
|
207
|
-
let currentToolData = void 0;
|
|
208
218
|
const writer = writable.getWriter();
|
|
209
219
|
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
|
-
}
|
|
221
220
|
try {
|
|
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
221
|
const e = {
|
|
235
222
|
...event,
|
|
236
223
|
type: event.type.replace("workflow-", "")
|
|
@@ -312,23 +299,14 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
312
299
|
}
|
|
313
300
|
}
|
|
314
301
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
executionGraph: this.executionGraph,
|
|
323
|
-
serializedStepGraph: this.serializedStepGraph,
|
|
324
|
-
mastra: this.#mastra,
|
|
325
|
-
retryConfig: this.retryConfig,
|
|
326
|
-
cleanup: () => this.runs.delete(runIdToUse)
|
|
327
|
-
},
|
|
328
|
-
this.inngest
|
|
302
|
+
/**
|
|
303
|
+
* @deprecated Use createRunAsync() instead.
|
|
304
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
305
|
+
*/
|
|
306
|
+
createRun(_options) {
|
|
307
|
+
throw new Error(
|
|
308
|
+
"createRun() has been deprecated. Please use createRunAsync() instead.\n\nMigration guide:\n Before: const run = workflow.createRun();\n After: const run = await workflow.createRunAsync();\n\nNote: createRunAsync() is an async method, so make sure your calling function is async."
|
|
329
309
|
);
|
|
330
|
-
this.runs.set(runIdToUse, run);
|
|
331
|
-
return run;
|
|
332
310
|
}
|
|
333
311
|
async createRunAsync(options) {
|
|
334
312
|
const runIdToUse = options?.runId || crypto.randomUUID();
|
|
@@ -336,12 +314,14 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
336
314
|
{
|
|
337
315
|
workflowId: this.id,
|
|
338
316
|
runId: runIdToUse,
|
|
317
|
+
resourceId: options?.resourceId,
|
|
339
318
|
executionEngine: this.executionEngine,
|
|
340
319
|
executionGraph: this.executionGraph,
|
|
341
320
|
serializedStepGraph: this.serializedStepGraph,
|
|
342
321
|
mastra: this.#mastra,
|
|
343
322
|
retryConfig: this.retryConfig,
|
|
344
|
-
cleanup: () => this.runs.delete(runIdToUse)
|
|
323
|
+
cleanup: () => this.runs.delete(runIdToUse),
|
|
324
|
+
workflowSteps: this.steps
|
|
345
325
|
},
|
|
346
326
|
this.inngest
|
|
347
327
|
);
|
|
@@ -351,6 +331,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
351
331
|
await this.mastra?.getStorage()?.persistWorkflowSnapshot({
|
|
352
332
|
workflowName: this.id,
|
|
353
333
|
runId: runIdToUse,
|
|
334
|
+
resourceId: options?.resourceId,
|
|
354
335
|
snapshot: {
|
|
355
336
|
runId: runIdToUse,
|
|
356
337
|
status: "pending",
|
|
@@ -384,7 +365,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
384
365
|
},
|
|
385
366
|
{ event: `workflow.${this.id}` },
|
|
386
367
|
async ({ event, step, attempt, publish }) => {
|
|
387
|
-
let { inputData, runId, resume } = event.data;
|
|
368
|
+
let { inputData, runId, resourceId, resume } = event.data;
|
|
388
369
|
if (!runId) {
|
|
389
370
|
runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
|
|
390
371
|
return crypto.randomUUID();
|
|
@@ -416,6 +397,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
416
397
|
const result = await engine.execute({
|
|
417
398
|
workflowId: this.id,
|
|
418
399
|
runId,
|
|
400
|
+
resourceId,
|
|
419
401
|
graph: this.executionGraph,
|
|
420
402
|
serializedStepGraph: this.serializedStepGraph,
|
|
421
403
|
input: inputData,
|
|
@@ -460,11 +442,10 @@ function createStep(params) {
|
|
|
460
442
|
if (isAgent(params)) {
|
|
461
443
|
return {
|
|
462
444
|
id: params.name,
|
|
445
|
+
description: params.getDescription(),
|
|
463
446
|
// @ts-ignore
|
|
464
447
|
inputSchema: zod.z.object({
|
|
465
448
|
prompt: zod.z.string()
|
|
466
|
-
// resourceId: z.string().optional(),
|
|
467
|
-
// threadId: z.string().optional(),
|
|
468
449
|
}),
|
|
469
450
|
// @ts-ignore
|
|
470
451
|
outputSchema: zod.z.object({
|
|
@@ -480,13 +461,7 @@ function createStep(params) {
|
|
|
480
461
|
name: params.name,
|
|
481
462
|
args: inputData
|
|
482
463
|
};
|
|
483
|
-
await emitter.emit("watch-v2", {
|
|
484
|
-
type: "workflow-agent-call-start",
|
|
485
|
-
payload: toolData
|
|
486
|
-
});
|
|
487
464
|
const { fullStream } = await params.stream(inputData.prompt, {
|
|
488
|
-
// resourceId: inputData.resourceId,
|
|
489
|
-
// threadId: inputData.threadId,
|
|
490
465
|
runtimeContext,
|
|
491
466
|
tracingContext,
|
|
492
467
|
onFinish: (result) => {
|
|
@@ -497,17 +472,28 @@ function createStep(params) {
|
|
|
497
472
|
if (abortSignal.aborted) {
|
|
498
473
|
return abort();
|
|
499
474
|
}
|
|
475
|
+
await emitter.emit("watch-v2", {
|
|
476
|
+
type: "tool-call-streaming-start",
|
|
477
|
+
...toolData ?? {}
|
|
478
|
+
});
|
|
500
479
|
for await (const chunk of fullStream) {
|
|
501
|
-
|
|
480
|
+
if (chunk.type === "text-delta") {
|
|
481
|
+
await emitter.emit("watch-v2", {
|
|
482
|
+
type: "tool-call-delta",
|
|
483
|
+
...toolData ?? {},
|
|
484
|
+
argsTextDelta: chunk.textDelta
|
|
485
|
+
});
|
|
486
|
+
}
|
|
502
487
|
}
|
|
503
488
|
await emitter.emit("watch-v2", {
|
|
504
|
-
type: "
|
|
505
|
-
|
|
489
|
+
type: "tool-call-streaming-finish",
|
|
490
|
+
...toolData ?? {}
|
|
506
491
|
});
|
|
507
492
|
return {
|
|
508
493
|
text: await streamPromise.promise
|
|
509
494
|
};
|
|
510
|
-
}
|
|
495
|
+
},
|
|
496
|
+
component: params.component
|
|
511
497
|
};
|
|
512
498
|
}
|
|
513
499
|
if (isTool(params)) {
|
|
@@ -518,16 +504,20 @@ function createStep(params) {
|
|
|
518
504
|
// TODO: tool probably should have strong id type
|
|
519
505
|
// @ts-ignore
|
|
520
506
|
id: params.id,
|
|
507
|
+
description: params.description,
|
|
521
508
|
inputSchema: params.inputSchema,
|
|
522
509
|
outputSchema: params.outputSchema,
|
|
523
|
-
execute: async ({ inputData, mastra, runtimeContext, tracingContext }) => {
|
|
510
|
+
execute: async ({ inputData, mastra, runtimeContext, tracingContext, suspend, resumeData }) => {
|
|
524
511
|
return params.execute({
|
|
525
512
|
context: inputData,
|
|
526
513
|
mastra: aiTracing.wrapMastra(mastra, tracingContext),
|
|
527
514
|
runtimeContext,
|
|
528
|
-
tracingContext
|
|
515
|
+
tracingContext,
|
|
516
|
+
suspend,
|
|
517
|
+
resumeData
|
|
529
518
|
});
|
|
530
|
-
}
|
|
519
|
+
},
|
|
520
|
+
component: "TOOL"
|
|
531
521
|
};
|
|
532
522
|
}
|
|
533
523
|
return {
|
|
@@ -552,7 +542,8 @@ function init(inngest) {
|
|
|
552
542
|
description: step.description,
|
|
553
543
|
inputSchema: step.inputSchema,
|
|
554
544
|
outputSchema: step.outputSchema,
|
|
555
|
-
execute: step.execute
|
|
545
|
+
execute: step.execute,
|
|
546
|
+
component: step.component
|
|
556
547
|
};
|
|
557
548
|
},
|
|
558
549
|
cloneWorkflow(workflow, opts) {
|
|
@@ -572,8 +563,8 @@ function init(inngest) {
|
|
|
572
563
|
var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
573
564
|
inngestStep;
|
|
574
565
|
inngestAttempts;
|
|
575
|
-
constructor(mastra, inngestStep, inngestAttempts = 0) {
|
|
576
|
-
super({ mastra });
|
|
566
|
+
constructor(mastra, inngestStep, inngestAttempts = 0, options) {
|
|
567
|
+
super({ mastra, options });
|
|
577
568
|
this.inngestStep = inngestStep;
|
|
578
569
|
this.inngestAttempts = inngestAttempts;
|
|
579
570
|
}
|
|
@@ -658,6 +649,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
658
649
|
emitter,
|
|
659
650
|
abortController,
|
|
660
651
|
runtimeContext,
|
|
652
|
+
executionContext,
|
|
661
653
|
writableStream,
|
|
662
654
|
tracingContext
|
|
663
655
|
}) {
|
|
@@ -668,7 +660,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
668
660
|
attributes: {
|
|
669
661
|
durationMs: duration,
|
|
670
662
|
sleepType: fn ? "dynamic" : "fixed"
|
|
671
|
-
}
|
|
663
|
+
},
|
|
664
|
+
tracingPolicy: this.options?.tracingPolicy
|
|
672
665
|
});
|
|
673
666
|
if (fn) {
|
|
674
667
|
const stepCallId = crypto.randomUUID();
|
|
@@ -684,16 +677,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
684
677
|
currentSpan: sleepSpan
|
|
685
678
|
},
|
|
686
679
|
getInitData: () => stepResults?.input,
|
|
687
|
-
getStepResult: (
|
|
688
|
-
if (!step?.id) {
|
|
689
|
-
return null;
|
|
690
|
-
}
|
|
691
|
-
const result = stepResults[step.id];
|
|
692
|
-
if (result?.status === "success") {
|
|
693
|
-
return result.output;
|
|
694
|
-
}
|
|
695
|
-
return null;
|
|
696
|
-
},
|
|
680
|
+
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
697
681
|
// TODO: this function shouldn't have suspend probably?
|
|
698
682
|
suspend: async (_suspendPayload) => {
|
|
699
683
|
},
|
|
@@ -703,6 +687,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
703
687
|
abortController?.abort();
|
|
704
688
|
},
|
|
705
689
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
690
|
+
// TODO: add streamVNext support
|
|
691
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
706
692
|
engine: { step: this.inngestStep },
|
|
707
693
|
abortSignal: abortController?.signal,
|
|
708
694
|
writer: new tools.ToolStream(
|
|
@@ -739,6 +725,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
739
725
|
emitter,
|
|
740
726
|
abortController,
|
|
741
727
|
runtimeContext,
|
|
728
|
+
executionContext,
|
|
742
729
|
writableStream,
|
|
743
730
|
tracingContext
|
|
744
731
|
}) {
|
|
@@ -750,7 +737,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
750
737
|
untilDate: date,
|
|
751
738
|
durationMs: date ? Math.max(0, date.getTime() - Date.now()) : void 0,
|
|
752
739
|
sleepType: fn ? "dynamic" : "fixed"
|
|
753
|
-
}
|
|
740
|
+
},
|
|
741
|
+
tracingPolicy: this.options?.tracingPolicy
|
|
754
742
|
});
|
|
755
743
|
if (fn) {
|
|
756
744
|
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
@@ -766,16 +754,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
766
754
|
currentSpan: sleepUntilSpan
|
|
767
755
|
},
|
|
768
756
|
getInitData: () => stepResults?.input,
|
|
769
|
-
getStepResult: (
|
|
770
|
-
if (!step?.id) {
|
|
771
|
-
return null;
|
|
772
|
-
}
|
|
773
|
-
const result = stepResults[step.id];
|
|
774
|
-
if (result?.status === "success") {
|
|
775
|
-
return result.output;
|
|
776
|
-
}
|
|
777
|
-
return null;
|
|
778
|
-
},
|
|
757
|
+
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
779
758
|
// TODO: this function shouldn't have suspend probably?
|
|
780
759
|
suspend: async (_suspendPayload) => {
|
|
781
760
|
},
|
|
@@ -785,6 +764,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
785
764
|
abortController?.abort();
|
|
786
765
|
},
|
|
787
766
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
767
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
768
|
+
// TODO: add streamVNext support
|
|
788
769
|
engine: { step: this.inngestStep },
|
|
789
770
|
abortSignal: abortController?.signal,
|
|
790
771
|
writer: new tools.ToolStream(
|
|
@@ -798,6 +779,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
798
779
|
)
|
|
799
780
|
});
|
|
800
781
|
});
|
|
782
|
+
if (date && !(date instanceof Date)) {
|
|
783
|
+
date = new Date(date);
|
|
784
|
+
}
|
|
801
785
|
const time = !date ? 0 : date.getTime() - Date.now();
|
|
802
786
|
sleepUntilSpan?.update({
|
|
803
787
|
attributes: {
|
|
@@ -846,7 +830,13 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
846
830
|
input: prevOutput,
|
|
847
831
|
attributes: {
|
|
848
832
|
stepId: step.id
|
|
849
|
-
}
|
|
833
|
+
},
|
|
834
|
+
tracingPolicy: this.options?.tracingPolicy
|
|
835
|
+
});
|
|
836
|
+
const { inputData, validationError } = await workflows.validateStepInput({
|
|
837
|
+
prevOutput,
|
|
838
|
+
step,
|
|
839
|
+
validateInputs: this.options?.validateInputs ?? false
|
|
850
840
|
});
|
|
851
841
|
const startedAt = await this.inngestStep.run(
|
|
852
842
|
`workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
|
|
@@ -878,7 +868,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
878
868
|
payload: {
|
|
879
869
|
id: step.id,
|
|
880
870
|
status: "running",
|
|
881
|
-
payload:
|
|
871
|
+
payload: inputData,
|
|
882
872
|
startedAt: startedAt2
|
|
883
873
|
}
|
|
884
874
|
});
|
|
@@ -898,7 +888,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
898
888
|
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
899
889
|
function: step.getFunction(),
|
|
900
890
|
data: {
|
|
901
|
-
inputData
|
|
891
|
+
inputData,
|
|
902
892
|
runId,
|
|
903
893
|
resume: {
|
|
904
894
|
runId,
|
|
@@ -916,7 +906,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
916
906
|
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
917
907
|
function: step.getFunction(),
|
|
918
908
|
data: {
|
|
919
|
-
inputData
|
|
909
|
+
inputData
|
|
920
910
|
}
|
|
921
911
|
});
|
|
922
912
|
result = invokeResp.result;
|
|
@@ -1061,24 +1051,21 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1061
1051
|
let suspended;
|
|
1062
1052
|
let bailed;
|
|
1063
1053
|
try {
|
|
1054
|
+
if (validationError) {
|
|
1055
|
+
throw validationError;
|
|
1056
|
+
}
|
|
1064
1057
|
const result = await step.execute({
|
|
1065
1058
|
runId: executionContext.runId,
|
|
1066
1059
|
mastra: this.mastra,
|
|
1067
1060
|
runtimeContext,
|
|
1068
1061
|
writableStream,
|
|
1069
|
-
inputData
|
|
1062
|
+
inputData,
|
|
1070
1063
|
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1071
1064
|
tracingContext: {
|
|
1072
1065
|
currentSpan: stepAISpan
|
|
1073
1066
|
},
|
|
1074
1067
|
getInitData: () => stepResults?.input,
|
|
1075
|
-
getStepResult: (
|
|
1076
|
-
const result2 = stepResults[step2.id];
|
|
1077
|
-
if (result2?.status === "success") {
|
|
1078
|
-
return result2.output;
|
|
1079
|
-
}
|
|
1080
|
-
return null;
|
|
1081
|
-
},
|
|
1068
|
+
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
1082
1069
|
suspend: async (suspendPayload) => {
|
|
1083
1070
|
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
1084
1071
|
suspended = { payload: suspendPayload };
|
|
@@ -1104,14 +1091,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1104
1091
|
output: result,
|
|
1105
1092
|
startedAt,
|
|
1106
1093
|
endedAt,
|
|
1107
|
-
payload:
|
|
1094
|
+
payload: inputData,
|
|
1108
1095
|
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1109
1096
|
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1110
1097
|
};
|
|
1111
1098
|
} catch (e) {
|
|
1112
1099
|
execResults = {
|
|
1113
1100
|
status: "failed",
|
|
1114
|
-
payload:
|
|
1101
|
+
payload: inputData,
|
|
1115
1102
|
error: e instanceof Error ? e.message : String(e),
|
|
1116
1103
|
endedAt: Date.now(),
|
|
1117
1104
|
startedAt,
|
|
@@ -1123,14 +1110,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1123
1110
|
execResults = {
|
|
1124
1111
|
status: "suspended",
|
|
1125
1112
|
suspendedPayload: suspended.payload,
|
|
1126
|
-
payload:
|
|
1113
|
+
payload: inputData,
|
|
1127
1114
|
suspendedAt: Date.now(),
|
|
1128
1115
|
startedAt,
|
|
1129
1116
|
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1130
1117
|
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1131
1118
|
};
|
|
1132
1119
|
} else if (bailed) {
|
|
1133
|
-
execResults = { status: "bailed", output: bailed.payload, payload:
|
|
1120
|
+
execResults = { status: "bailed", output: bailed.payload, payload: inputData, endedAt: Date.now(), startedAt };
|
|
1134
1121
|
}
|
|
1135
1122
|
if (execResults.status === "failed") {
|
|
1136
1123
|
if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
|
|
@@ -1188,12 +1175,13 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1188
1175
|
await this.runScorers({
|
|
1189
1176
|
scorers: step.scorers,
|
|
1190
1177
|
runId: executionContext.runId,
|
|
1191
|
-
input:
|
|
1178
|
+
input: inputData,
|
|
1192
1179
|
output: stepRes.result,
|
|
1193
1180
|
workflowId: executionContext.workflowId,
|
|
1194
1181
|
stepId: step.id,
|
|
1195
1182
|
runtimeContext,
|
|
1196
|
-
disableScorers
|
|
1183
|
+
disableScorers,
|
|
1184
|
+
tracingContext: { currentSpan: stepAISpan }
|
|
1197
1185
|
});
|
|
1198
1186
|
}
|
|
1199
1187
|
});
|
|
@@ -1206,6 +1194,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1206
1194
|
workflowId,
|
|
1207
1195
|
runId,
|
|
1208
1196
|
stepResults,
|
|
1197
|
+
resourceId,
|
|
1209
1198
|
executionContext,
|
|
1210
1199
|
serializedStepGraph,
|
|
1211
1200
|
workflowStatus,
|
|
@@ -1218,6 +1207,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1218
1207
|
await this.mastra?.getStorage()?.persistWorkflowSnapshot({
|
|
1219
1208
|
workflowName: workflowId,
|
|
1220
1209
|
runId,
|
|
1210
|
+
resourceId,
|
|
1221
1211
|
snapshot: {
|
|
1222
1212
|
runId,
|
|
1223
1213
|
value: {},
|
|
@@ -1255,11 +1245,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1255
1245
|
}) {
|
|
1256
1246
|
const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
1257
1247
|
type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL,
|
|
1258
|
-
name: `conditional: ${entry.conditions.length} conditions`,
|
|
1248
|
+
name: `conditional: '${entry.conditions.length} conditions'`,
|
|
1259
1249
|
input: prevOutput,
|
|
1260
1250
|
attributes: {
|
|
1261
1251
|
conditionCount: entry.conditions.length
|
|
1262
|
-
}
|
|
1252
|
+
},
|
|
1253
|
+
tracingPolicy: this.options?.tracingPolicy
|
|
1263
1254
|
});
|
|
1264
1255
|
let execResults;
|
|
1265
1256
|
const truthyIndexes = (await Promise.all(
|
|
@@ -1267,11 +1258,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1267
1258
|
(cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
|
|
1268
1259
|
const evalSpan = conditionalSpan?.createChildSpan({
|
|
1269
1260
|
type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL_EVAL,
|
|
1270
|
-
name: `condition ${index}`,
|
|
1261
|
+
name: `condition: '${index}'`,
|
|
1271
1262
|
input: prevOutput,
|
|
1272
1263
|
attributes: {
|
|
1273
1264
|
conditionIndex: index
|
|
1274
|
-
}
|
|
1265
|
+
},
|
|
1266
|
+
tracingPolicy: this.options?.tracingPolicy
|
|
1275
1267
|
});
|
|
1276
1268
|
try {
|
|
1277
1269
|
const result = await cond({
|
|
@@ -1285,16 +1277,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1285
1277
|
currentSpan: evalSpan
|
|
1286
1278
|
},
|
|
1287
1279
|
getInitData: () => stepResults?.input,
|
|
1288
|
-
getStepResult: (
|
|
1289
|
-
if (!step?.id) {
|
|
1290
|
-
return null;
|
|
1291
|
-
}
|
|
1292
|
-
const result2 = stepResults[step.id];
|
|
1293
|
-
if (result2?.status === "success") {
|
|
1294
|
-
return result2.output;
|
|
1295
|
-
}
|
|
1296
|
-
return null;
|
|
1297
|
-
},
|
|
1280
|
+
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
1298
1281
|
// TODO: this function shouldn't have suspend probably?
|
|
1299
1282
|
suspend: async (_suspendPayload) => {
|
|
1300
1283
|
},
|
|
@@ -1304,6 +1287,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1304
1287
|
abortController.abort();
|
|
1305
1288
|
},
|
|
1306
1289
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1290
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1291
|
+
// TODO: add streamVNext support
|
|
1307
1292
|
engine: {
|
|
1308
1293
|
step: this.inngestStep
|
|
1309
1294
|
},
|