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