@mastra/inngest 0.0.0-ai-telementry-ui-20250908102126 → 0.0.0-break-rename-vnext-legacy-20251002212351
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 +174 -10
- package/dist/index.cjs +136 -133
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +29 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +137 -134
- 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';
|
|
6
|
+
import { Run, Workflow, DefaultExecutionEngine, getStepResult, validateStepInput } from '@mastra/core/workflows';
|
|
7
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,34 +459,66 @@ function createStep(params) {
|
|
|
478
459
|
name: params.name,
|
|
479
460
|
args: inputData
|
|
480
461
|
};
|
|
481
|
-
await
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
462
|
+
if ((await params.getLLM()).getModel().specificationVersion === `v2`) {
|
|
463
|
+
const { fullStream } = await params.stream(inputData.prompt, {
|
|
464
|
+
runtimeContext,
|
|
465
|
+
tracingContext,
|
|
466
|
+
onFinish: (result) => {
|
|
467
|
+
streamPromise.resolve(result.text);
|
|
468
|
+
},
|
|
469
|
+
abortSignal
|
|
470
|
+
});
|
|
471
|
+
if (abortSignal.aborted) {
|
|
472
|
+
return abort();
|
|
473
|
+
}
|
|
474
|
+
await emitter.emit("watch-v2", {
|
|
475
|
+
type: "tool-call-streaming-start",
|
|
476
|
+
...toolData ?? {}
|
|
477
|
+
});
|
|
478
|
+
for await (const chunk of fullStream) {
|
|
479
|
+
if (chunk.type === "text-delta") {
|
|
480
|
+
await emitter.emit("watch-v2", {
|
|
481
|
+
type: "tool-call-delta",
|
|
482
|
+
...toolData ?? {},
|
|
483
|
+
argsTextDelta: chunk.payload.text
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
} else {
|
|
488
|
+
const { fullStream } = await params.streamLegacy(inputData.prompt, {
|
|
489
|
+
runtimeContext,
|
|
490
|
+
tracingContext,
|
|
491
|
+
onFinish: (result) => {
|
|
492
|
+
streamPromise.resolve(result.text);
|
|
493
|
+
},
|
|
494
|
+
abortSignal
|
|
495
|
+
});
|
|
496
|
+
if (abortSignal.aborted) {
|
|
497
|
+
return abort();
|
|
498
|
+
}
|
|
499
|
+
await emitter.emit("watch-v2", {
|
|
500
|
+
type: "tool-call-streaming-start",
|
|
501
|
+
...toolData ?? {}
|
|
502
|
+
});
|
|
503
|
+
for await (const chunk of fullStream) {
|
|
504
|
+
if (chunk.type === "text-delta") {
|
|
505
|
+
await emitter.emit("watch-v2", {
|
|
506
|
+
type: "tool-call-delta",
|
|
507
|
+
...toolData ?? {},
|
|
508
|
+
argsTextDelta: chunk.textDelta
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
}
|
|
500
512
|
}
|
|
501
513
|
await emitter.emit("watch-v2", {
|
|
502
|
-
type: "
|
|
503
|
-
|
|
514
|
+
type: "tool-call-streaming-finish",
|
|
515
|
+
...toolData ?? {}
|
|
504
516
|
});
|
|
505
517
|
return {
|
|
506
518
|
text: await streamPromise.promise
|
|
507
519
|
};
|
|
508
|
-
}
|
|
520
|
+
},
|
|
521
|
+
component: params.component
|
|
509
522
|
};
|
|
510
523
|
}
|
|
511
524
|
if (isTool(params)) {
|
|
@@ -516,16 +529,20 @@ function createStep(params) {
|
|
|
516
529
|
// TODO: tool probably should have strong id type
|
|
517
530
|
// @ts-ignore
|
|
518
531
|
id: params.id,
|
|
532
|
+
description: params.description,
|
|
519
533
|
inputSchema: params.inputSchema,
|
|
520
534
|
outputSchema: params.outputSchema,
|
|
521
|
-
execute: async ({ inputData, mastra, runtimeContext, tracingContext }) => {
|
|
535
|
+
execute: async ({ inputData, mastra, runtimeContext, tracingContext, suspend, resumeData }) => {
|
|
522
536
|
return params.execute({
|
|
523
537
|
context: inputData,
|
|
524
538
|
mastra: wrapMastra(mastra, tracingContext),
|
|
525
539
|
runtimeContext,
|
|
526
|
-
tracingContext
|
|
540
|
+
tracingContext,
|
|
541
|
+
suspend,
|
|
542
|
+
resumeData
|
|
527
543
|
});
|
|
528
|
-
}
|
|
544
|
+
},
|
|
545
|
+
component: "TOOL"
|
|
529
546
|
};
|
|
530
547
|
}
|
|
531
548
|
return {
|
|
@@ -550,7 +567,8 @@ function init(inngest) {
|
|
|
550
567
|
description: step.description,
|
|
551
568
|
inputSchema: step.inputSchema,
|
|
552
569
|
outputSchema: step.outputSchema,
|
|
553
|
-
execute: step.execute
|
|
570
|
+
execute: step.execute,
|
|
571
|
+
component: step.component
|
|
554
572
|
};
|
|
555
573
|
},
|
|
556
574
|
cloneWorkflow(workflow, opts) {
|
|
@@ -570,8 +588,8 @@ function init(inngest) {
|
|
|
570
588
|
var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
571
589
|
inngestStep;
|
|
572
590
|
inngestAttempts;
|
|
573
|
-
constructor(mastra, inngestStep, inngestAttempts = 0) {
|
|
574
|
-
super({ mastra });
|
|
591
|
+
constructor(mastra, inngestStep, inngestAttempts = 0, options) {
|
|
592
|
+
super({ mastra, options });
|
|
575
593
|
this.inngestStep = inngestStep;
|
|
576
594
|
this.inngestAttempts = inngestAttempts;
|
|
577
595
|
}
|
|
@@ -667,7 +685,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
667
685
|
attributes: {
|
|
668
686
|
durationMs: duration,
|
|
669
687
|
sleepType: fn ? "dynamic" : "fixed"
|
|
670
|
-
}
|
|
688
|
+
},
|
|
689
|
+
tracingPolicy: this.options?.tracingPolicy
|
|
671
690
|
});
|
|
672
691
|
if (fn) {
|
|
673
692
|
const stepCallId = randomUUID();
|
|
@@ -683,16 +702,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
683
702
|
currentSpan: sleepSpan
|
|
684
703
|
},
|
|
685
704
|
getInitData: () => stepResults?.input,
|
|
686
|
-
getStepResult: (
|
|
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
|
-
},
|
|
705
|
+
getStepResult: getStepResult.bind(this, stepResults),
|
|
696
706
|
// TODO: this function shouldn't have suspend probably?
|
|
697
707
|
suspend: async (_suspendPayload) => {
|
|
698
708
|
},
|
|
@@ -752,7 +762,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
752
762
|
untilDate: date,
|
|
753
763
|
durationMs: date ? Math.max(0, date.getTime() - Date.now()) : void 0,
|
|
754
764
|
sleepType: fn ? "dynamic" : "fixed"
|
|
755
|
-
}
|
|
765
|
+
},
|
|
766
|
+
tracingPolicy: this.options?.tracingPolicy
|
|
756
767
|
});
|
|
757
768
|
if (fn) {
|
|
758
769
|
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
@@ -768,16 +779,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
768
779
|
currentSpan: sleepUntilSpan
|
|
769
780
|
},
|
|
770
781
|
getInitData: () => stepResults?.input,
|
|
771
|
-
getStepResult: (
|
|
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
|
-
},
|
|
782
|
+
getStepResult: getStepResult.bind(this, stepResults),
|
|
781
783
|
// TODO: this function shouldn't have suspend probably?
|
|
782
784
|
suspend: async (_suspendPayload) => {
|
|
783
785
|
},
|
|
@@ -802,6 +804,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
802
804
|
)
|
|
803
805
|
});
|
|
804
806
|
});
|
|
807
|
+
if (date && !(date instanceof Date)) {
|
|
808
|
+
date = new Date(date);
|
|
809
|
+
}
|
|
805
810
|
const time = !date ? 0 : date.getTime() - Date.now();
|
|
806
811
|
sleepUntilSpan?.update({
|
|
807
812
|
attributes: {
|
|
@@ -850,7 +855,13 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
850
855
|
input: prevOutput,
|
|
851
856
|
attributes: {
|
|
852
857
|
stepId: step.id
|
|
853
|
-
}
|
|
858
|
+
},
|
|
859
|
+
tracingPolicy: this.options?.tracingPolicy
|
|
860
|
+
});
|
|
861
|
+
const { inputData, validationError } = await validateStepInput({
|
|
862
|
+
prevOutput,
|
|
863
|
+
step,
|
|
864
|
+
validateInputs: this.options?.validateInputs ?? false
|
|
854
865
|
});
|
|
855
866
|
const startedAt = await this.inngestStep.run(
|
|
856
867
|
`workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
|
|
@@ -882,7 +893,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
882
893
|
payload: {
|
|
883
894
|
id: step.id,
|
|
884
895
|
status: "running",
|
|
885
|
-
payload:
|
|
896
|
+
payload: inputData,
|
|
886
897
|
startedAt: startedAt2
|
|
887
898
|
}
|
|
888
899
|
});
|
|
@@ -902,7 +913,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
902
913
|
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
903
914
|
function: step.getFunction(),
|
|
904
915
|
data: {
|
|
905
|
-
inputData
|
|
916
|
+
inputData,
|
|
906
917
|
runId,
|
|
907
918
|
resume: {
|
|
908
919
|
runId,
|
|
@@ -920,7 +931,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
920
931
|
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
921
932
|
function: step.getFunction(),
|
|
922
933
|
data: {
|
|
923
|
-
inputData
|
|
934
|
+
inputData
|
|
924
935
|
}
|
|
925
936
|
});
|
|
926
937
|
result = invokeResp.result;
|
|
@@ -1065,24 +1076,21 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1065
1076
|
let suspended;
|
|
1066
1077
|
let bailed;
|
|
1067
1078
|
try {
|
|
1079
|
+
if (validationError) {
|
|
1080
|
+
throw validationError;
|
|
1081
|
+
}
|
|
1068
1082
|
const result = await step.execute({
|
|
1069
1083
|
runId: executionContext.runId,
|
|
1070
1084
|
mastra: this.mastra,
|
|
1071
1085
|
runtimeContext,
|
|
1072
1086
|
writableStream,
|
|
1073
|
-
inputData
|
|
1087
|
+
inputData,
|
|
1074
1088
|
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1075
1089
|
tracingContext: {
|
|
1076
1090
|
currentSpan: stepAISpan
|
|
1077
1091
|
},
|
|
1078
1092
|
getInitData: () => stepResults?.input,
|
|
1079
|
-
getStepResult: (
|
|
1080
|
-
const result2 = stepResults[step2.id];
|
|
1081
|
-
if (result2?.status === "success") {
|
|
1082
|
-
return result2.output;
|
|
1083
|
-
}
|
|
1084
|
-
return null;
|
|
1085
|
-
},
|
|
1093
|
+
getStepResult: getStepResult.bind(this, stepResults),
|
|
1086
1094
|
suspend: async (suspendPayload) => {
|
|
1087
1095
|
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
1088
1096
|
suspended = { payload: suspendPayload };
|
|
@@ -1108,14 +1116,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1108
1116
|
output: result,
|
|
1109
1117
|
startedAt,
|
|
1110
1118
|
endedAt,
|
|
1111
|
-
payload:
|
|
1119
|
+
payload: inputData,
|
|
1112
1120
|
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1113
1121
|
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1114
1122
|
};
|
|
1115
1123
|
} catch (e) {
|
|
1116
1124
|
execResults = {
|
|
1117
1125
|
status: "failed",
|
|
1118
|
-
payload:
|
|
1126
|
+
payload: inputData,
|
|
1119
1127
|
error: e instanceof Error ? e.message : String(e),
|
|
1120
1128
|
endedAt: Date.now(),
|
|
1121
1129
|
startedAt,
|
|
@@ -1127,14 +1135,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1127
1135
|
execResults = {
|
|
1128
1136
|
status: "suspended",
|
|
1129
1137
|
suspendedPayload: suspended.payload,
|
|
1130
|
-
payload:
|
|
1138
|
+
payload: inputData,
|
|
1131
1139
|
suspendedAt: Date.now(),
|
|
1132
1140
|
startedAt,
|
|
1133
1141
|
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1134
1142
|
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1135
1143
|
};
|
|
1136
1144
|
} else if (bailed) {
|
|
1137
|
-
execResults = { status: "bailed", output: bailed.payload, payload:
|
|
1145
|
+
execResults = { status: "bailed", output: bailed.payload, payload: inputData, endedAt: Date.now(), startedAt };
|
|
1138
1146
|
}
|
|
1139
1147
|
if (execResults.status === "failed") {
|
|
1140
1148
|
if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
|
|
@@ -1192,7 +1200,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1192
1200
|
await this.runScorers({
|
|
1193
1201
|
scorers: step.scorers,
|
|
1194
1202
|
runId: executionContext.runId,
|
|
1195
|
-
input:
|
|
1203
|
+
input: inputData,
|
|
1196
1204
|
output: stepRes.result,
|
|
1197
1205
|
workflowId: executionContext.workflowId,
|
|
1198
1206
|
stepId: step.id,
|
|
@@ -1211,6 +1219,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1211
1219
|
workflowId,
|
|
1212
1220
|
runId,
|
|
1213
1221
|
stepResults,
|
|
1222
|
+
resourceId,
|
|
1214
1223
|
executionContext,
|
|
1215
1224
|
serializedStepGraph,
|
|
1216
1225
|
workflowStatus,
|
|
@@ -1223,6 +1232,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1223
1232
|
await this.mastra?.getStorage()?.persistWorkflowSnapshot({
|
|
1224
1233
|
workflowName: workflowId,
|
|
1225
1234
|
runId,
|
|
1235
|
+
resourceId,
|
|
1226
1236
|
snapshot: {
|
|
1227
1237
|
runId,
|
|
1228
1238
|
value: {},
|
|
@@ -1260,11 +1270,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1260
1270
|
}) {
|
|
1261
1271
|
const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
1262
1272
|
type: AISpanType.WORKFLOW_CONDITIONAL,
|
|
1263
|
-
name: `conditional: ${entry.conditions.length} conditions`,
|
|
1273
|
+
name: `conditional: '${entry.conditions.length} conditions'`,
|
|
1264
1274
|
input: prevOutput,
|
|
1265
1275
|
attributes: {
|
|
1266
1276
|
conditionCount: entry.conditions.length
|
|
1267
|
-
}
|
|
1277
|
+
},
|
|
1278
|
+
tracingPolicy: this.options?.tracingPolicy
|
|
1268
1279
|
});
|
|
1269
1280
|
let execResults;
|
|
1270
1281
|
const truthyIndexes = (await Promise.all(
|
|
@@ -1272,11 +1283,12 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1272
1283
|
(cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
|
|
1273
1284
|
const evalSpan = conditionalSpan?.createChildSpan({
|
|
1274
1285
|
type: AISpanType.WORKFLOW_CONDITIONAL_EVAL,
|
|
1275
|
-
name: `condition ${index}`,
|
|
1286
|
+
name: `condition: '${index}'`,
|
|
1276
1287
|
input: prevOutput,
|
|
1277
1288
|
attributes: {
|
|
1278
1289
|
conditionIndex: index
|
|
1279
|
-
}
|
|
1290
|
+
},
|
|
1291
|
+
tracingPolicy: this.options?.tracingPolicy
|
|
1280
1292
|
});
|
|
1281
1293
|
try {
|
|
1282
1294
|
const result = await cond({
|
|
@@ -1290,16 +1302,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1290
1302
|
currentSpan: evalSpan
|
|
1291
1303
|
},
|
|
1292
1304
|
getInitData: () => stepResults?.input,
|
|
1293
|
-
getStepResult: (
|
|
1294
|
-
if (!step?.id) {
|
|
1295
|
-
return null;
|
|
1296
|
-
}
|
|
1297
|
-
const result2 = stepResults[step.id];
|
|
1298
|
-
if (result2?.status === "success") {
|
|
1299
|
-
return result2.output;
|
|
1300
|
-
}
|
|
1301
|
-
return null;
|
|
1302
|
-
},
|
|
1305
|
+
getStepResult: getStepResult.bind(this, stepResults),
|
|
1303
1306
|
// TODO: this function shouldn't have suspend probably?
|
|
1304
1307
|
suspend: async (_suspendPayload) => {
|
|
1305
1308
|
},
|