@mastra/inngest 0.0.0-course-20250527170450 → 0.0.0-fix-generate-title-20250616171351
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 +155 -2
- package/dist/_tsup-dts-rollup.d.cts +56 -15
- package/dist/_tsup-dts-rollup.d.ts +56 -15
- package/dist/index.cjs +178 -28
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +178 -29
- package/package.json +18 -17
- package/src/index.test.ts +229 -145
- package/src/index.ts +322 -42
package/src/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
2
|
import { subscribe } from '@inngest/realtime';
|
|
3
|
-
import
|
|
3
|
+
import { Agent, Tool } from '@mastra/core';
|
|
4
|
+
import type { Mastra, ToolExecutionContext, WorkflowRun, WorkflowRuns } from '@mastra/core';
|
|
4
5
|
import { RuntimeContext } from '@mastra/core/di';
|
|
5
|
-
import { Workflow,
|
|
6
|
+
import { Workflow, Run, DefaultExecutionEngine } from '@mastra/core/workflows';
|
|
6
7
|
import type {
|
|
7
8
|
ExecuteFunction,
|
|
8
9
|
ExecutionContext,
|
|
@@ -13,12 +14,19 @@ import type {
|
|
|
13
14
|
StepFlowEntry,
|
|
14
15
|
StepResult,
|
|
15
16
|
WorkflowResult,
|
|
17
|
+
SerializedStepFlowEntry,
|
|
18
|
+
StepFailure,
|
|
19
|
+
WatchEvent,
|
|
16
20
|
} from '@mastra/core/workflows';
|
|
17
21
|
import { EMITTER_SYMBOL } from '@mastra/core/workflows/_constants';
|
|
18
22
|
import type { Span } from '@opentelemetry/api';
|
|
19
23
|
import type { Inngest, BaseContext } from 'inngest';
|
|
20
24
|
import { serve as inngestServe } from 'inngest/hono';
|
|
21
|
-
import
|
|
25
|
+
import { z } from 'zod';
|
|
26
|
+
|
|
27
|
+
export type InngestEngineType = {
|
|
28
|
+
step: any;
|
|
29
|
+
};
|
|
22
30
|
|
|
23
31
|
export function serve({ mastra, inngest }: { mastra: Mastra; inngest: Inngest }): ReturnType<typeof inngestServe> {
|
|
24
32
|
const wfs = mastra.getWorkflows();
|
|
@@ -36,11 +44,13 @@ export function serve({ mastra, inngest }: { mastra: Mastra; inngest: Inngest })
|
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
export class InngestRun<
|
|
47
|
+
TEngineType = InngestEngineType,
|
|
39
48
|
TSteps extends Step<string, any, any>[] = Step<string, any, any>[],
|
|
40
49
|
TInput extends z.ZodType<any> = z.ZodType<any>,
|
|
41
50
|
TOutput extends z.ZodType<any> = z.ZodType<any>,
|
|
42
|
-
> extends Run<TSteps, TInput, TOutput> {
|
|
51
|
+
> extends Run<TEngineType, TSteps, TInput, TOutput> {
|
|
43
52
|
private inngest: Inngest;
|
|
53
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
44
54
|
#mastra: Mastra;
|
|
45
55
|
|
|
46
56
|
constructor(
|
|
@@ -49,6 +59,7 @@ export class InngestRun<
|
|
|
49
59
|
runId: string;
|
|
50
60
|
executionEngine: ExecutionEngine;
|
|
51
61
|
executionGraph: ExecutionGraph;
|
|
62
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
52
63
|
mastra?: Mastra;
|
|
53
64
|
retryConfig?: {
|
|
54
65
|
attempts?: number;
|
|
@@ -60,11 +71,12 @@ export class InngestRun<
|
|
|
60
71
|
) {
|
|
61
72
|
super(params);
|
|
62
73
|
this.inngest = inngest;
|
|
74
|
+
this.serializedStepGraph = params.serializedStepGraph;
|
|
63
75
|
this.#mastra = params.mastra!;
|
|
64
76
|
}
|
|
65
77
|
|
|
66
78
|
async getRuns(eventId: string) {
|
|
67
|
-
const response = await fetch(`${this.inngest.apiBaseUrl}/v1/events/${eventId}/runs`, {
|
|
79
|
+
const response = await fetch(`${this.inngest.apiBaseUrl ?? 'https://api.inngest.com'}/v1/events/${eventId}/runs`, {
|
|
68
80
|
headers: {
|
|
69
81
|
Authorization: `Bearer ${process.env.INNGEST_SIGNING_KEY}`,
|
|
70
82
|
},
|
|
@@ -96,11 +108,13 @@ export class InngestRun<
|
|
|
96
108
|
runId: this.runId,
|
|
97
109
|
snapshot: {
|
|
98
110
|
runId: this.runId,
|
|
111
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
99
112
|
value: {},
|
|
100
113
|
context: {} as any,
|
|
101
114
|
activePaths: [],
|
|
102
115
|
suspendedPaths: {},
|
|
103
116
|
timestamp: Date.now(),
|
|
117
|
+
status: 'running',
|
|
104
118
|
},
|
|
105
119
|
});
|
|
106
120
|
|
|
@@ -196,12 +210,13 @@ export class InngestRun<
|
|
|
196
210
|
}
|
|
197
211
|
|
|
198
212
|
export class InngestWorkflow<
|
|
213
|
+
TEngineType = InngestEngineType,
|
|
199
214
|
TSteps extends Step<string, any, any>[] = Step<string, any, any>[],
|
|
200
215
|
TWorkflowId extends string = string,
|
|
201
216
|
TInput extends z.ZodType<any> = z.ZodType<any>,
|
|
202
217
|
TOutput extends z.ZodType<any> = z.ZodType<any>,
|
|
203
218
|
TPrevSchema extends z.ZodType<any> = TInput,
|
|
204
|
-
> extends Workflow<TSteps, TWorkflowId, TInput, TOutput, TPrevSchema> {
|
|
219
|
+
> extends Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TPrevSchema> {
|
|
205
220
|
#mastra: Mastra;
|
|
206
221
|
public inngest: Inngest;
|
|
207
222
|
|
|
@@ -233,7 +248,10 @@ export class InngestWorkflow<
|
|
|
233
248
|
const storage = this.#mastra?.getStorage();
|
|
234
249
|
if (!storage) {
|
|
235
250
|
this.logger.debug('Cannot get workflow runs. Mastra engine is not initialized');
|
|
236
|
-
|
|
251
|
+
//returning in memory run if no storage is initialized
|
|
252
|
+
return this.runs.get(runId)
|
|
253
|
+
? ({ ...this.runs.get(runId), workflowName: this.id } as unknown as WorkflowRun)
|
|
254
|
+
: null;
|
|
237
255
|
}
|
|
238
256
|
const run = (await storage.getWorkflowRunById({ runId, workflowName: this.id })) as unknown as WorkflowRun;
|
|
239
257
|
|
|
@@ -243,6 +261,32 @@ export class InngestWorkflow<
|
|
|
243
261
|
);
|
|
244
262
|
}
|
|
245
263
|
|
|
264
|
+
async getWorkflowRunExecutionResult(runId: string): Promise<WatchEvent['payload']['workflowState'] | null> {
|
|
265
|
+
const storage = this.#mastra?.getStorage();
|
|
266
|
+
if (!storage) {
|
|
267
|
+
this.logger.debug('Cannot get workflow run execution result. Mastra storage is not initialized');
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
|
|
272
|
+
|
|
273
|
+
if (!run?.snapshot) {
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (typeof run.snapshot === 'string') {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return {
|
|
282
|
+
status: run.snapshot.status,
|
|
283
|
+
result: run.snapshot.result,
|
|
284
|
+
error: run.snapshot.error,
|
|
285
|
+
payload: run.snapshot.context?.input,
|
|
286
|
+
steps: run.snapshot.context as any,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
246
290
|
__registerMastra(mastra: Mastra) {
|
|
247
291
|
this.#mastra = mastra;
|
|
248
292
|
this.executionEngine.__registerMastra(mastra);
|
|
@@ -266,11 +310,11 @@ export class InngestWorkflow<
|
|
|
266
310
|
}
|
|
267
311
|
}
|
|
268
312
|
|
|
269
|
-
createRun(options?: { runId?: string }): Run<TSteps, TInput, TOutput> {
|
|
313
|
+
createRun(options?: { runId?: string }): Run<TEngineType, TSteps, TInput, TOutput> {
|
|
270
314
|
const runIdToUse = options?.runId || randomUUID();
|
|
271
315
|
|
|
272
316
|
// Return a new Run instance with object parameters
|
|
273
|
-
const run: Run<TSteps, TInput, TOutput> =
|
|
317
|
+
const run: Run<TEngineType, TSteps, TInput, TOutput> =
|
|
274
318
|
this.runs.get(runIdToUse) ??
|
|
275
319
|
new InngestRun(
|
|
276
320
|
{
|
|
@@ -278,6 +322,7 @@ export class InngestWorkflow<
|
|
|
278
322
|
runId: runIdToUse,
|
|
279
323
|
executionEngine: this.executionEngine,
|
|
280
324
|
executionGraph: this.executionGraph,
|
|
325
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
281
326
|
mastra: this.#mastra,
|
|
282
327
|
retryConfig: this.retryConfig,
|
|
283
328
|
cleanup: () => this.runs.delete(runIdToUse),
|
|
@@ -329,6 +374,7 @@ export class InngestWorkflow<
|
|
|
329
374
|
workflowId: this.id,
|
|
330
375
|
runId,
|
|
331
376
|
graph: this.executionGraph,
|
|
377
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
332
378
|
input: inputData,
|
|
333
379
|
emitter,
|
|
334
380
|
retryConfig: this.retryConfig,
|
|
@@ -362,29 +408,185 @@ export class InngestWorkflow<
|
|
|
362
408
|
}
|
|
363
409
|
}
|
|
364
410
|
|
|
365
|
-
function
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
411
|
+
export function createStep<
|
|
412
|
+
TStepId extends string,
|
|
413
|
+
TStepInput extends z.ZodType<any>,
|
|
414
|
+
TStepOutput extends z.ZodType<any>,
|
|
415
|
+
TResumeSchema extends z.ZodType<any>,
|
|
416
|
+
TSuspendSchema extends z.ZodType<any>,
|
|
417
|
+
>(params: {
|
|
418
|
+
id: TStepId;
|
|
419
|
+
description?: string;
|
|
420
|
+
inputSchema: TStepInput;
|
|
421
|
+
outputSchema: TStepOutput;
|
|
422
|
+
resumeSchema?: TResumeSchema;
|
|
423
|
+
suspendSchema?: TSuspendSchema;
|
|
424
|
+
execute: ExecuteFunction<
|
|
425
|
+
z.infer<TStepInput>,
|
|
426
|
+
z.infer<TStepOutput>,
|
|
427
|
+
z.infer<TResumeSchema>,
|
|
428
|
+
z.infer<TSuspendSchema>,
|
|
429
|
+
InngestEngineType
|
|
430
|
+
>;
|
|
431
|
+
}): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
432
|
+
|
|
433
|
+
export function createStep<
|
|
434
|
+
TStepId extends string,
|
|
435
|
+
TStepInput extends z.ZodObject<{ prompt: z.ZodString }>,
|
|
436
|
+
TStepOutput extends z.ZodObject<{ text: z.ZodString }>,
|
|
437
|
+
TResumeSchema extends z.ZodType<any>,
|
|
438
|
+
TSuspendSchema extends z.ZodType<any>,
|
|
370
439
|
>(
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
440
|
+
agent: Agent<TStepId, any, any>,
|
|
441
|
+
): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
442
|
+
|
|
443
|
+
export function createStep<
|
|
444
|
+
TSchemaIn extends z.ZodType<any>,
|
|
445
|
+
TSchemaOut extends z.ZodType<any>,
|
|
446
|
+
TContext extends ToolExecutionContext<TSchemaIn>,
|
|
447
|
+
>(
|
|
448
|
+
tool: Tool<TSchemaIn, TSchemaOut, TContext> & {
|
|
449
|
+
inputSchema: TSchemaIn;
|
|
450
|
+
outputSchema: TSchemaOut;
|
|
451
|
+
execute: (context: TContext) => Promise<any>;
|
|
452
|
+
},
|
|
453
|
+
): Step<string, TSchemaIn, TSchemaOut, z.ZodType<any>, z.ZodType<any>, InngestEngineType>;
|
|
454
|
+
|
|
455
|
+
export function createStep<
|
|
456
|
+
TStepId extends string,
|
|
457
|
+
TStepInput extends z.ZodType<any>,
|
|
458
|
+
TStepOutput extends z.ZodType<any>,
|
|
459
|
+
TResumeSchema extends z.ZodType<any>,
|
|
460
|
+
TSuspendSchema extends z.ZodType<any>,
|
|
461
|
+
>(
|
|
462
|
+
params:
|
|
463
|
+
| {
|
|
464
|
+
id: TStepId;
|
|
465
|
+
description?: string;
|
|
466
|
+
inputSchema: TStepInput;
|
|
467
|
+
outputSchema: TStepOutput;
|
|
468
|
+
resumeSchema?: TResumeSchema;
|
|
469
|
+
suspendSchema?: TSuspendSchema;
|
|
470
|
+
execute: ExecuteFunction<
|
|
471
|
+
z.infer<TStepInput>,
|
|
472
|
+
z.infer<TStepOutput>,
|
|
473
|
+
z.infer<TResumeSchema>,
|
|
474
|
+
z.infer<TSuspendSchema>,
|
|
475
|
+
InngestEngineType
|
|
476
|
+
>;
|
|
477
|
+
}
|
|
478
|
+
| Agent<any, any, any>
|
|
479
|
+
| (Tool<TStepInput, TStepOutput, any> & {
|
|
480
|
+
inputSchema: TStepInput;
|
|
481
|
+
outputSchema: TStepOutput;
|
|
482
|
+
execute: (context: ToolExecutionContext<TStepInput>) => Promise<any>;
|
|
483
|
+
}),
|
|
484
|
+
): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType> {
|
|
485
|
+
if (params instanceof Agent) {
|
|
486
|
+
return {
|
|
487
|
+
id: params.name,
|
|
488
|
+
// @ts-ignore
|
|
489
|
+
inputSchema: z.object({
|
|
490
|
+
prompt: z.string(),
|
|
491
|
+
// resourceId: z.string().optional(),
|
|
492
|
+
// threadId: z.string().optional(),
|
|
493
|
+
}),
|
|
494
|
+
// @ts-ignore
|
|
495
|
+
outputSchema: z.object({
|
|
496
|
+
text: z.string(),
|
|
497
|
+
}),
|
|
498
|
+
execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext }) => {
|
|
499
|
+
let streamPromise = {} as {
|
|
500
|
+
promise: Promise<string>;
|
|
501
|
+
resolve: (value: string) => void;
|
|
502
|
+
reject: (reason?: any) => void;
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
streamPromise.promise = new Promise((resolve, reject) => {
|
|
506
|
+
streamPromise.resolve = resolve;
|
|
507
|
+
streamPromise.reject = reject;
|
|
508
|
+
});
|
|
509
|
+
const toolData = {
|
|
510
|
+
name: params.name,
|
|
511
|
+
args: inputData,
|
|
512
|
+
};
|
|
513
|
+
await emitter.emit('watch-v2', {
|
|
514
|
+
type: 'tool-call-streaming-start',
|
|
515
|
+
...toolData,
|
|
516
|
+
});
|
|
517
|
+
const { fullStream } = await params.stream(inputData.prompt, {
|
|
518
|
+
// resourceId: inputData.resourceId,
|
|
519
|
+
// threadId: inputData.threadId,
|
|
520
|
+
runtimeContext,
|
|
521
|
+
onFinish: result => {
|
|
522
|
+
streamPromise.resolve(result.text);
|
|
523
|
+
},
|
|
524
|
+
});
|
|
384
525
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
526
|
+
for await (const chunk of fullStream) {
|
|
527
|
+
switch (chunk.type) {
|
|
528
|
+
case 'text-delta':
|
|
529
|
+
await emitter.emit('watch-v2', {
|
|
530
|
+
type: 'tool-call-delta',
|
|
531
|
+
...toolData,
|
|
532
|
+
argsTextDelta: chunk.textDelta,
|
|
533
|
+
});
|
|
534
|
+
break;
|
|
535
|
+
|
|
536
|
+
case 'step-start':
|
|
537
|
+
case 'step-finish':
|
|
538
|
+
case 'finish':
|
|
539
|
+
break;
|
|
540
|
+
|
|
541
|
+
case 'tool-call':
|
|
542
|
+
case 'tool-result':
|
|
543
|
+
case 'tool-call-streaming-start':
|
|
544
|
+
case 'tool-call-delta':
|
|
545
|
+
case 'source':
|
|
546
|
+
case 'file':
|
|
547
|
+
default:
|
|
548
|
+
await emitter.emit('watch-v2', chunk);
|
|
549
|
+
break;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
return {
|
|
554
|
+
text: await streamPromise.promise,
|
|
555
|
+
};
|
|
556
|
+
},
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
if (params instanceof Tool) {
|
|
561
|
+
if (!params.inputSchema || !params.outputSchema) {
|
|
562
|
+
throw new Error('Tool must have input and output schemas defined');
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
return {
|
|
566
|
+
// TODO: tool probably should have strong id type
|
|
567
|
+
// @ts-ignore
|
|
568
|
+
id: params.id,
|
|
569
|
+
inputSchema: params.inputSchema,
|
|
570
|
+
outputSchema: params.outputSchema,
|
|
571
|
+
execute: async ({ inputData, mastra, runtimeContext }) => {
|
|
572
|
+
return params.execute({
|
|
573
|
+
context: inputData,
|
|
574
|
+
mastra,
|
|
575
|
+
runtimeContext,
|
|
576
|
+
});
|
|
577
|
+
},
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
return {
|
|
582
|
+
id: params.id,
|
|
583
|
+
description: params.description,
|
|
584
|
+
inputSchema: params.inputSchema,
|
|
585
|
+
outputSchema: params.outputSchema,
|
|
586
|
+
resumeSchema: params.resumeSchema,
|
|
587
|
+
suspendSchema: params.suspendSchema,
|
|
588
|
+
execute: params.execute,
|
|
589
|
+
};
|
|
388
590
|
}
|
|
389
591
|
|
|
390
592
|
export function init(inngest: Inngest) {
|
|
@@ -393,13 +595,58 @@ export function init(inngest: Inngest) {
|
|
|
393
595
|
TWorkflowId extends string = string,
|
|
394
596
|
TInput extends z.ZodType<any> = z.ZodType<any>,
|
|
395
597
|
TOutput extends z.ZodType<any> = z.ZodType<any>,
|
|
396
|
-
TSteps extends Step<string, any, any
|
|
598
|
+
TSteps extends Step<string, any, any, any, any, InngestEngineType>[] = Step<
|
|
599
|
+
string,
|
|
600
|
+
any,
|
|
601
|
+
any,
|
|
602
|
+
any,
|
|
603
|
+
any,
|
|
604
|
+
InngestEngineType
|
|
605
|
+
>[],
|
|
397
606
|
>(params: WorkflowConfig<TWorkflowId, TInput, TOutput, TSteps>) {
|
|
398
|
-
return new InngestWorkflow(params, inngest);
|
|
607
|
+
return new InngestWorkflow<InngestEngineType, TSteps, TWorkflowId, TInput, TOutput, TInput>(params, inngest);
|
|
399
608
|
},
|
|
400
609
|
createStep,
|
|
401
|
-
cloneStep
|
|
402
|
-
|
|
610
|
+
cloneStep<TStepId extends string>(
|
|
611
|
+
step: Step<string, any, any, any, any, InngestEngineType>,
|
|
612
|
+
opts: { id: TStepId },
|
|
613
|
+
): Step<TStepId, any, any, any, any, InngestEngineType> {
|
|
614
|
+
return {
|
|
615
|
+
id: opts.id,
|
|
616
|
+
description: step.description,
|
|
617
|
+
inputSchema: step.inputSchema,
|
|
618
|
+
outputSchema: step.outputSchema,
|
|
619
|
+
execute: step.execute,
|
|
620
|
+
};
|
|
621
|
+
},
|
|
622
|
+
cloneWorkflow<
|
|
623
|
+
TWorkflowId extends string = string,
|
|
624
|
+
TInput extends z.ZodType<any> = z.ZodType<any>,
|
|
625
|
+
TOutput extends z.ZodType<any> = z.ZodType<any>,
|
|
626
|
+
TSteps extends Step<string, any, any, any, any, InngestEngineType>[] = Step<
|
|
627
|
+
string,
|
|
628
|
+
any,
|
|
629
|
+
any,
|
|
630
|
+
any,
|
|
631
|
+
any,
|
|
632
|
+
InngestEngineType
|
|
633
|
+
>[],
|
|
634
|
+
>(
|
|
635
|
+
workflow: Workflow<InngestEngineType, TSteps, string, TInput, TOutput, TInput>,
|
|
636
|
+
opts: { id: TWorkflowId },
|
|
637
|
+
): Workflow<InngestEngineType, TSteps, TWorkflowId, TInput, TOutput, TInput> {
|
|
638
|
+
const wf = new Workflow({
|
|
639
|
+
id: opts.id,
|
|
640
|
+
inputSchema: workflow.inputSchema,
|
|
641
|
+
outputSchema: workflow.outputSchema,
|
|
642
|
+
steps: workflow.stepDefs,
|
|
643
|
+
mastra: workflow.mastra,
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
wf.setStepFlow(workflow.stepGraph);
|
|
647
|
+
wf.commit();
|
|
648
|
+
return wf;
|
|
649
|
+
},
|
|
403
650
|
};
|
|
404
651
|
}
|
|
405
652
|
|
|
@@ -524,6 +771,10 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
524
771
|
});
|
|
525
772
|
}
|
|
526
773
|
|
|
774
|
+
async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
775
|
+
await this.inngestStep.sleep(id, duration);
|
|
776
|
+
}
|
|
777
|
+
|
|
527
778
|
async executeStep({
|
|
528
779
|
step,
|
|
529
780
|
stepResults,
|
|
@@ -740,6 +991,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
740
991
|
let suspended: { payload: any } | undefined;
|
|
741
992
|
try {
|
|
742
993
|
const result = await step.execute({
|
|
994
|
+
runId: executionContext.runId,
|
|
743
995
|
mastra: this.mastra!,
|
|
744
996
|
runtimeContext,
|
|
745
997
|
inputData: prevOutput,
|
|
@@ -763,7 +1015,10 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
763
1015
|
// @ts-ignore
|
|
764
1016
|
runId: stepResults[step.id]?.payload?.__workflow_meta?.runId,
|
|
765
1017
|
},
|
|
766
|
-
emitter,
|
|
1018
|
+
[EMITTER_SYMBOL]: emitter,
|
|
1019
|
+
engine: {
|
|
1020
|
+
step: this.inngestStep,
|
|
1021
|
+
},
|
|
767
1022
|
});
|
|
768
1023
|
|
|
769
1024
|
execResults = { status: 'success', output: result };
|
|
@@ -816,11 +1071,19 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
816
1071
|
runId,
|
|
817
1072
|
stepResults,
|
|
818
1073
|
executionContext,
|
|
1074
|
+
serializedStepGraph,
|
|
1075
|
+
workflowStatus,
|
|
1076
|
+
result,
|
|
1077
|
+
error,
|
|
819
1078
|
}: {
|
|
820
1079
|
workflowId: string;
|
|
821
1080
|
runId: string;
|
|
822
1081
|
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
1082
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
823
1083
|
executionContext: ExecutionContext;
|
|
1084
|
+
workflowStatus: 'success' | 'failed' | 'suspended' | 'running';
|
|
1085
|
+
result?: Record<string, any>;
|
|
1086
|
+
error?: string | Error;
|
|
824
1087
|
}) {
|
|
825
1088
|
await this.inngestStep.run(
|
|
826
1089
|
`workflow.${workflowId}.run.${runId}.path.${JSON.stringify(executionContext.executionPath)}.stepUpdate`,
|
|
@@ -834,6 +1097,10 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
834
1097
|
context: stepResults as any,
|
|
835
1098
|
activePaths: [],
|
|
836
1099
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1100
|
+
serializedStepGraph,
|
|
1101
|
+
status: workflowStatus,
|
|
1102
|
+
result,
|
|
1103
|
+
error,
|
|
837
1104
|
// @ts-ignore
|
|
838
1105
|
timestamp: Date.now(),
|
|
839
1106
|
},
|
|
@@ -849,6 +1116,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
849
1116
|
prevOutput,
|
|
850
1117
|
prevStep,
|
|
851
1118
|
stepResults,
|
|
1119
|
+
serializedStepGraph,
|
|
852
1120
|
resume,
|
|
853
1121
|
executionContext,
|
|
854
1122
|
emitter,
|
|
@@ -856,8 +1124,13 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
856
1124
|
}: {
|
|
857
1125
|
workflowId: string;
|
|
858
1126
|
runId: string;
|
|
859
|
-
entry: {
|
|
1127
|
+
entry: {
|
|
1128
|
+
type: 'conditional';
|
|
1129
|
+
steps: StepFlowEntry[];
|
|
1130
|
+
conditions: ExecuteFunction<any, any, any, any, InngestEngineType>[];
|
|
1131
|
+
};
|
|
860
1132
|
prevStep: StepFlowEntry;
|
|
1133
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
861
1134
|
prevOutput: any;
|
|
862
1135
|
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
863
1136
|
resume?: {
|
|
@@ -877,6 +1150,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
877
1150
|
this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
|
|
878
1151
|
try {
|
|
879
1152
|
const result = await cond({
|
|
1153
|
+
runId,
|
|
880
1154
|
mastra: this.mastra!,
|
|
881
1155
|
runtimeContext,
|
|
882
1156
|
inputData: prevOutput,
|
|
@@ -897,6 +1171,9 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
897
1171
|
// TODO: this function shouldn't have suspend probably?
|
|
898
1172
|
suspend: async (_suspendPayload: any) => {},
|
|
899
1173
|
[EMITTER_SYMBOL]: emitter,
|
|
1174
|
+
engine: {
|
|
1175
|
+
step: this.inngestStep,
|
|
1176
|
+
},
|
|
900
1177
|
});
|
|
901
1178
|
return result ? index : null;
|
|
902
1179
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -909,7 +1186,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
909
1186
|
).filter((index: any): index is number => index !== null);
|
|
910
1187
|
|
|
911
1188
|
const stepsToRun = entry.steps.filter((_, index) => truthyIndexes.includes(index));
|
|
912
|
-
const results: StepResult<any, any, any, any>[] = await Promise.all(
|
|
1189
|
+
const results: { result: StepResult<any, any, any, any> }[] = await Promise.all(
|
|
913
1190
|
stepsToRun.map((step, index) =>
|
|
914
1191
|
this.executeEntry({
|
|
915
1192
|
workflowId,
|
|
@@ -918,6 +1195,7 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
918
1195
|
prevStep,
|
|
919
1196
|
stepResults,
|
|
920
1197
|
resume,
|
|
1198
|
+
serializedStepGraph,
|
|
921
1199
|
executionContext: {
|
|
922
1200
|
workflowId,
|
|
923
1201
|
runId,
|
|
@@ -931,17 +1209,19 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
931
1209
|
}),
|
|
932
1210
|
),
|
|
933
1211
|
);
|
|
934
|
-
const hasFailed = results.find(result => result.status === 'failed')
|
|
935
|
-
|
|
1212
|
+
const hasFailed = results.find(result => result.result.status === 'failed') as {
|
|
1213
|
+
result: StepFailure<any, any, any>;
|
|
1214
|
+
};
|
|
1215
|
+
const hasSuspended = results.find(result => result.result.status === 'suspended');
|
|
936
1216
|
if (hasFailed) {
|
|
937
|
-
execResults = { status: 'failed', error: hasFailed.error };
|
|
1217
|
+
execResults = { status: 'failed', error: hasFailed.result.error };
|
|
938
1218
|
} else if (hasSuspended) {
|
|
939
|
-
execResults = { status: 'suspended', payload: hasSuspended.payload };
|
|
1219
|
+
execResults = { status: 'suspended', payload: hasSuspended.result.payload };
|
|
940
1220
|
} else {
|
|
941
1221
|
execResults = {
|
|
942
1222
|
status: 'success',
|
|
943
1223
|
output: results.reduce((acc: Record<string, any>, result, index) => {
|
|
944
|
-
if (result.status === 'success') {
|
|
1224
|
+
if (result.result.status === 'success') {
|
|
945
1225
|
// @ts-ignore
|
|
946
1226
|
acc[stepsToRun[index]!.step.id] = result.output;
|
|
947
1227
|
}
|