@mastra/inngest 0.0.0-netlify-no-bundle-20251127120354 → 0.0.0-partial-response-backport-20251204204441
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 +60 -336
- package/dist/index.cjs +467 -408
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +94 -71
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +470 -411
- package/dist/index.js.map +1 -1
- package/package.json +19 -17
package/dist/index.cjs
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
var crypto = require('crypto');
|
|
4
4
|
var web = require('stream/web');
|
|
5
5
|
var realtime = require('@inngest/realtime');
|
|
6
|
+
var aiTracing = require('@mastra/core/ai-tracing');
|
|
6
7
|
var di = require('@mastra/core/di');
|
|
7
|
-
var observability = require('@mastra/core/observability');
|
|
8
8
|
var stream = require('@mastra/core/stream');
|
|
9
9
|
var tools = require('@mastra/core/tools');
|
|
10
10
|
var workflows = require('@mastra/core/workflows');
|
|
@@ -20,7 +20,7 @@ function serve({
|
|
|
20
20
|
functions: userFunctions = [],
|
|
21
21
|
registerOptions
|
|
22
22
|
}) {
|
|
23
|
-
const wfs = mastra.
|
|
23
|
+
const wfs = mastra.getWorkflows();
|
|
24
24
|
const workflowFunctions = Array.from(
|
|
25
25
|
new Set(
|
|
26
26
|
Object.values(wfs).flatMap((wf) => {
|
|
@@ -59,12 +59,11 @@ var InngestRun = class extends workflows.Run {
|
|
|
59
59
|
}
|
|
60
60
|
async getRunOutput(eventId) {
|
|
61
61
|
let runs = await this.getRuns(eventId);
|
|
62
|
-
const storage = this.#mastra?.getStorage();
|
|
63
62
|
while (runs?.[0]?.status !== "Completed" || runs?.[0]?.event_id !== eventId) {
|
|
64
63
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
65
64
|
runs = await this.getRuns(eventId);
|
|
66
65
|
if (runs?.[0]?.status === "Failed") {
|
|
67
|
-
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
66
|
+
const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
|
|
68
67
|
workflowName: this.workflowId,
|
|
69
68
|
runId: this.runId
|
|
70
69
|
});
|
|
@@ -73,7 +72,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
73
72
|
};
|
|
74
73
|
}
|
|
75
74
|
if (runs?.[0]?.status === "Cancelled") {
|
|
76
|
-
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
75
|
+
const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
|
|
77
76
|
workflowName: this.workflowId,
|
|
78
77
|
runId: this.runId
|
|
79
78
|
});
|
|
@@ -82,20 +81,25 @@ var InngestRun = class extends workflows.Run {
|
|
|
82
81
|
}
|
|
83
82
|
return runs?.[0];
|
|
84
83
|
}
|
|
84
|
+
async sendEvent(event, data) {
|
|
85
|
+
await this.inngest.send({
|
|
86
|
+
name: `user-event-${event}`,
|
|
87
|
+
data
|
|
88
|
+
});
|
|
89
|
+
}
|
|
85
90
|
async cancel() {
|
|
86
|
-
const storage = this.#mastra?.getStorage();
|
|
87
91
|
await this.inngest.send({
|
|
88
92
|
name: `cancel.workflow.${this.workflowId}`,
|
|
89
93
|
data: {
|
|
90
94
|
runId: this.runId
|
|
91
95
|
}
|
|
92
96
|
});
|
|
93
|
-
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
97
|
+
const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
|
|
94
98
|
workflowName: this.workflowId,
|
|
95
99
|
runId: this.runId
|
|
96
100
|
});
|
|
97
101
|
if (snapshot) {
|
|
98
|
-
await storage?.persistWorkflowSnapshot({
|
|
102
|
+
await this.#mastra?.storage?.persistWorkflowSnapshot({
|
|
99
103
|
workflowName: this.workflowId,
|
|
100
104
|
runId: this.runId,
|
|
101
105
|
resourceId: this.resourceId,
|
|
@@ -107,15 +111,9 @@ var InngestRun = class extends workflows.Run {
|
|
|
107
111
|
});
|
|
108
112
|
}
|
|
109
113
|
}
|
|
110
|
-
async start(
|
|
111
|
-
return this._start(params);
|
|
112
|
-
}
|
|
113
|
-
async _start({
|
|
114
|
+
async start({
|
|
114
115
|
inputData,
|
|
115
|
-
initialState
|
|
116
|
-
outputOptions,
|
|
117
|
-
tracingOptions,
|
|
118
|
-
format
|
|
116
|
+
initialState
|
|
119
117
|
}) {
|
|
120
118
|
await this.#mastra.getStorage()?.persistWorkflowSnapshot({
|
|
121
119
|
workflowName: this.workflowId,
|
|
@@ -143,10 +141,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
143
141
|
inputData: inputDataToUse,
|
|
144
142
|
initialState: initialStateToUse,
|
|
145
143
|
runId: this.runId,
|
|
146
|
-
resourceId: this.resourceId
|
|
147
|
-
outputOptions,
|
|
148
|
-
tracingOptions,
|
|
149
|
-
format
|
|
144
|
+
resourceId: this.resourceId
|
|
150
145
|
}
|
|
151
146
|
});
|
|
152
147
|
const eventId = eventOutput.ids[0];
|
|
@@ -202,7 +197,8 @@ var InngestRun = class extends workflows.Run {
|
|
|
202
197
|
steps,
|
|
203
198
|
stepResults: snapshot?.context,
|
|
204
199
|
resumePayload: resumeDataToUse,
|
|
205
|
-
|
|
200
|
+
// @ts-ignore
|
|
201
|
+
resumePath: snapshot?.suspendedPaths?.[steps?.[0]]
|
|
206
202
|
}
|
|
207
203
|
}
|
|
208
204
|
});
|
|
@@ -217,6 +213,29 @@ var InngestRun = class extends workflows.Run {
|
|
|
217
213
|
}
|
|
218
214
|
return result;
|
|
219
215
|
}
|
|
216
|
+
watch(cb, type = "watch") {
|
|
217
|
+
let active = true;
|
|
218
|
+
const streamPromise = realtime.subscribe(
|
|
219
|
+
{
|
|
220
|
+
channel: `workflow:${this.workflowId}:${this.runId}`,
|
|
221
|
+
topics: [type],
|
|
222
|
+
app: this.inngest
|
|
223
|
+
},
|
|
224
|
+
(message) => {
|
|
225
|
+
if (active) {
|
|
226
|
+
cb(message.data);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
);
|
|
230
|
+
return () => {
|
|
231
|
+
active = false;
|
|
232
|
+
streamPromise.then(async (stream) => {
|
|
233
|
+
return stream.cancel();
|
|
234
|
+
}).catch((err) => {
|
|
235
|
+
console.error(err);
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
}
|
|
220
239
|
async timeTravel(params) {
|
|
221
240
|
const p = this._timeTravel(params).then((result) => {
|
|
222
241
|
if (result.status !== "suspended") {
|
|
@@ -308,58 +327,20 @@ var InngestRun = class extends workflows.Run {
|
|
|
308
327
|
}
|
|
309
328
|
return result;
|
|
310
329
|
}
|
|
311
|
-
|
|
312
|
-
let active = true;
|
|
313
|
-
const streamPromise = realtime.subscribe(
|
|
314
|
-
{
|
|
315
|
-
channel: `workflow:${this.workflowId}:${this.runId}`,
|
|
316
|
-
topics: ["watch"],
|
|
317
|
-
app: this.inngest
|
|
318
|
-
},
|
|
319
|
-
(message) => {
|
|
320
|
-
if (active) {
|
|
321
|
-
cb(message.data);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
);
|
|
325
|
-
return () => {
|
|
326
|
-
active = false;
|
|
327
|
-
streamPromise.then(async (stream) => {
|
|
328
|
-
return stream.cancel();
|
|
329
|
-
}).catch((err) => {
|
|
330
|
-
console.error(err);
|
|
331
|
-
});
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
streamLegacy({ inputData, requestContext } = {}) {
|
|
330
|
+
streamLegacy({ inputData, runtimeContext } = {}) {
|
|
335
331
|
const { readable, writable } = new TransformStream();
|
|
336
332
|
const writer = writable.getWriter();
|
|
337
|
-
void writer.write({
|
|
338
|
-
// @ts-ignore
|
|
339
|
-
type: "start",
|
|
340
|
-
// @ts-ignore
|
|
341
|
-
payload: { runId: this.runId }
|
|
342
|
-
});
|
|
343
333
|
const unwatch = this.watch(async (event) => {
|
|
344
334
|
try {
|
|
345
335
|
const e = {
|
|
346
336
|
...event,
|
|
347
337
|
type: event.type.replace("workflow-", "")
|
|
348
338
|
};
|
|
349
|
-
if (e.type === "step-output") {
|
|
350
|
-
e.type = e.payload.output.type;
|
|
351
|
-
e.payload = e.payload.output.payload;
|
|
352
|
-
}
|
|
353
339
|
await writer.write(e);
|
|
354
340
|
} catch {
|
|
355
341
|
}
|
|
356
|
-
});
|
|
342
|
+
}, "watch-v2");
|
|
357
343
|
this.closeStreamAction = async () => {
|
|
358
|
-
await writer.write({
|
|
359
|
-
type: "finish",
|
|
360
|
-
// @ts-ignore
|
|
361
|
-
payload: { runId: this.runId }
|
|
362
|
-
});
|
|
363
344
|
unwatch();
|
|
364
345
|
try {
|
|
365
346
|
await writer.close();
|
|
@@ -369,7 +350,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
369
350
|
writer.releaseLock();
|
|
370
351
|
}
|
|
371
352
|
};
|
|
372
|
-
this.executionResults = this.
|
|
353
|
+
this.executionResults = this.start({ inputData, runtimeContext }).then((result) => {
|
|
373
354
|
if (result.status !== "suspended") {
|
|
374
355
|
this.closeStreamAction?.().catch(() => {
|
|
375
356
|
});
|
|
@@ -383,18 +364,11 @@ var InngestRun = class extends workflows.Run {
|
|
|
383
364
|
}
|
|
384
365
|
stream({
|
|
385
366
|
inputData,
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
closeOnSuspend = true,
|
|
389
|
-
initialState,
|
|
390
|
-
outputOptions
|
|
367
|
+
runtimeContext,
|
|
368
|
+
closeOnSuspend = true
|
|
391
369
|
} = {}) {
|
|
392
|
-
if (this.closeStreamAction && this.streamOutput) {
|
|
393
|
-
return this.streamOutput;
|
|
394
|
-
}
|
|
395
|
-
this.closeStreamAction = async () => {
|
|
396
|
-
};
|
|
397
370
|
const self = this;
|
|
371
|
+
let streamOutput;
|
|
398
372
|
const stream$1 = new web.ReadableStream({
|
|
399
373
|
async start(controller) {
|
|
400
374
|
const unwatch = self.watch(async ({ type, from = stream.ChunkFrom.WORKFLOW, payload }) => {
|
|
@@ -403,11 +377,11 @@ var InngestRun = class extends workflows.Run {
|
|
|
403
377
|
runId: self.runId,
|
|
404
378
|
from,
|
|
405
379
|
payload: {
|
|
406
|
-
stepName: payload
|
|
380
|
+
stepName: payload.id,
|
|
407
381
|
...payload
|
|
408
382
|
}
|
|
409
383
|
});
|
|
410
|
-
});
|
|
384
|
+
}, "watch-v2");
|
|
411
385
|
self.closeStreamAction = async () => {
|
|
412
386
|
unwatch();
|
|
413
387
|
try {
|
|
@@ -416,46 +390,29 @@ var InngestRun = class extends workflows.Run {
|
|
|
416
390
|
console.error("Error closing stream:", err);
|
|
417
391
|
}
|
|
418
392
|
};
|
|
419
|
-
const executionResultsPromise = self.
|
|
393
|
+
const executionResultsPromise = self.start({
|
|
420
394
|
inputData,
|
|
421
|
-
|
|
422
|
-
// tracingContext, // We are not able to pass a reference to a span here, what to do?
|
|
423
|
-
initialState,
|
|
424
|
-
tracingOptions,
|
|
425
|
-
outputOptions,
|
|
426
|
-
format: "vnext"
|
|
395
|
+
runtimeContext
|
|
427
396
|
});
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
executionResults = await executionResultsPromise;
|
|
431
|
-
if (closeOnSuspend) {
|
|
432
|
-
self.closeStreamAction?.().catch(() => {
|
|
433
|
-
});
|
|
434
|
-
} else if (executionResults.status !== "suspended") {
|
|
435
|
-
self.closeStreamAction?.().catch(() => {
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
if (self.streamOutput) {
|
|
439
|
-
self.streamOutput.updateResults(
|
|
440
|
-
executionResults
|
|
441
|
-
);
|
|
442
|
-
}
|
|
443
|
-
} catch (err) {
|
|
444
|
-
self.streamOutput?.rejectResults(err);
|
|
397
|
+
const executionResults = await executionResultsPromise;
|
|
398
|
+
if (closeOnSuspend) {
|
|
445
399
|
self.closeStreamAction?.().catch(() => {
|
|
446
400
|
});
|
|
401
|
+
} else if (executionResults.status !== "suspended") {
|
|
402
|
+
self.closeStreamAction?.().catch(() => {
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
if (streamOutput) {
|
|
406
|
+
streamOutput.updateResults(executionResults);
|
|
447
407
|
}
|
|
448
408
|
}
|
|
449
409
|
});
|
|
450
|
-
|
|
410
|
+
streamOutput = new stream.WorkflowRunOutput({
|
|
451
411
|
runId: this.runId,
|
|
452
412
|
workflowId: this.workflowId,
|
|
453
413
|
stream: stream$1
|
|
454
414
|
});
|
|
455
|
-
return
|
|
456
|
-
}
|
|
457
|
-
streamVNext(args = {}) {
|
|
458
|
-
return this.stream(args);
|
|
415
|
+
return streamOutput;
|
|
459
416
|
}
|
|
460
417
|
timeTravelStream({
|
|
461
418
|
inputData,
|
|
@@ -464,13 +421,12 @@ var InngestRun = class extends workflows.Run {
|
|
|
464
421
|
step,
|
|
465
422
|
context,
|
|
466
423
|
nestedStepsContext,
|
|
467
|
-
|
|
424
|
+
runtimeContext,
|
|
468
425
|
tracingOptions,
|
|
469
426
|
outputOptions
|
|
470
427
|
}) {
|
|
471
|
-
this.closeStreamAction = async () => {
|
|
472
|
-
};
|
|
473
428
|
const self = this;
|
|
429
|
+
let streamOutput;
|
|
474
430
|
const stream$1 = new web.ReadableStream({
|
|
475
431
|
async start(controller) {
|
|
476
432
|
const unwatch = self.watch(async ({ type, from = stream.ChunkFrom.WORKFLOW, payload }) => {
|
|
@@ -483,7 +439,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
483
439
|
...payload
|
|
484
440
|
}
|
|
485
441
|
});
|
|
486
|
-
});
|
|
442
|
+
}, "watch-v2");
|
|
487
443
|
self.closeStreamAction = async () => {
|
|
488
444
|
unwatch();
|
|
489
445
|
try {
|
|
@@ -499,7 +455,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
499
455
|
nestedStepsContext,
|
|
500
456
|
resumeData,
|
|
501
457
|
initialState,
|
|
502
|
-
|
|
458
|
+
runtimeContext,
|
|
503
459
|
tracingOptions,
|
|
504
460
|
outputOptions
|
|
505
461
|
});
|
|
@@ -509,22 +465,22 @@ var InngestRun = class extends workflows.Run {
|
|
|
509
465
|
executionResults = await executionResultsPromise;
|
|
510
466
|
self.closeStreamAction?.().catch(() => {
|
|
511
467
|
});
|
|
512
|
-
if (
|
|
513
|
-
|
|
468
|
+
if (streamOutput) {
|
|
469
|
+
streamOutput.updateResults(executionResults);
|
|
514
470
|
}
|
|
515
471
|
} catch (err) {
|
|
516
|
-
|
|
472
|
+
streamOutput?.rejectResults(err);
|
|
517
473
|
self.closeStreamAction?.().catch(() => {
|
|
518
474
|
});
|
|
519
475
|
}
|
|
520
476
|
}
|
|
521
477
|
});
|
|
522
|
-
|
|
478
|
+
streamOutput = new stream.WorkflowRunOutput({
|
|
523
479
|
runId: this.runId,
|
|
524
480
|
workflowId: this.workflowId,
|
|
525
481
|
stream: stream$1
|
|
526
482
|
});
|
|
527
|
-
return
|
|
483
|
+
return streamOutput;
|
|
528
484
|
}
|
|
529
485
|
};
|
|
530
486
|
var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
@@ -543,13 +499,13 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
543
499
|
this.#mastra = params.mastra;
|
|
544
500
|
this.inngest = inngest;
|
|
545
501
|
}
|
|
546
|
-
async
|
|
502
|
+
async getWorkflowRuns(args) {
|
|
547
503
|
const storage = this.#mastra?.getStorage();
|
|
548
504
|
if (!storage) {
|
|
549
505
|
this.logger.debug("Cannot get workflow runs. Mastra engine is not initialized");
|
|
550
506
|
return { runs: [], total: 0 };
|
|
551
507
|
}
|
|
552
|
-
return storage.
|
|
508
|
+
return storage.getWorkflowRuns({ workflowName: this.id, ...args ?? {} });
|
|
553
509
|
}
|
|
554
510
|
async getWorkflowRunById(runId) {
|
|
555
511
|
const storage = this.#mastra?.getStorage();
|
|
@@ -578,7 +534,16 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
578
534
|
}
|
|
579
535
|
}
|
|
580
536
|
}
|
|
581
|
-
|
|
537
|
+
/**
|
|
538
|
+
* @deprecated Use createRunAsync() instead.
|
|
539
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
540
|
+
*/
|
|
541
|
+
createRun(_options) {
|
|
542
|
+
throw new Error(
|
|
543
|
+
"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."
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
async createRunAsync(options) {
|
|
582
547
|
const runIdToUse = options?.runId || crypto.randomUUID();
|
|
583
548
|
const run = this.runs.get(runIdToUse) ?? new InngestRun(
|
|
584
549
|
{
|
|
@@ -621,6 +586,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
621
586
|
resumeLabels: {},
|
|
622
587
|
result: void 0,
|
|
623
588
|
error: void 0,
|
|
589
|
+
// @ts-ignore
|
|
624
590
|
timestamp: Date.now()
|
|
625
591
|
}
|
|
626
592
|
});
|
|
@@ -634,14 +600,15 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
634
600
|
this.function = this.inngest.createFunction(
|
|
635
601
|
{
|
|
636
602
|
id: `workflow.${this.id}`,
|
|
637
|
-
|
|
603
|
+
// @ts-ignore
|
|
604
|
+
retries: this.retryConfig?.attempts ?? 0,
|
|
638
605
|
cancelOn: [{ event: `cancel.workflow.${this.id}` }],
|
|
639
606
|
// Spread flow control configuration
|
|
640
607
|
...this.flowControlConfig
|
|
641
608
|
},
|
|
642
609
|
{ event: `workflow.${this.id}` },
|
|
643
610
|
async ({ event, step, attempt, publish }) => {
|
|
644
|
-
let { inputData, initialState, runId, resourceId, resume, outputOptions,
|
|
611
|
+
let { inputData, initialState, runId, resourceId, resume, outputOptions, timeTravel } = event.data;
|
|
645
612
|
if (!runId) {
|
|
646
613
|
runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
|
|
647
614
|
return crypto.randomUUID();
|
|
@@ -680,20 +647,14 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
680
647
|
initialState,
|
|
681
648
|
emitter,
|
|
682
649
|
retryConfig: this.retryConfig,
|
|
683
|
-
|
|
650
|
+
runtimeContext: new di.RuntimeContext(),
|
|
684
651
|
// TODO
|
|
685
652
|
resume,
|
|
686
653
|
timeTravel,
|
|
687
|
-
format,
|
|
688
654
|
abortController: new AbortController(),
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
write(chunk) {
|
|
693
|
-
void emitter.emit("watch", chunk).catch(() => {
|
|
694
|
-
});
|
|
695
|
-
}
|
|
696
|
-
})
|
|
655
|
+
currentSpan: void 0,
|
|
656
|
+
// TODO: Pass actual parent AI span from workflow execution context
|
|
657
|
+
outputOptions
|
|
697
658
|
});
|
|
698
659
|
await step.run(`workflow.${this.id}.finalize`, async () => {
|
|
699
660
|
if (result.status === "failed") {
|
|
@@ -731,29 +692,20 @@ function isAgent(params) {
|
|
|
731
692
|
function isTool(params) {
|
|
732
693
|
return params instanceof tools.Tool;
|
|
733
694
|
}
|
|
734
|
-
function createStep(params
|
|
695
|
+
function createStep(params) {
|
|
735
696
|
if (isAgent(params)) {
|
|
736
697
|
return {
|
|
737
698
|
id: params.name,
|
|
738
699
|
description: params.getDescription(),
|
|
700
|
+
// @ts-ignore
|
|
739
701
|
inputSchema: zod.z.object({
|
|
740
702
|
prompt: zod.z.string()
|
|
741
|
-
// resourceId: z.string().optional(),
|
|
742
|
-
// threadId: z.string().optional(),
|
|
743
703
|
}),
|
|
704
|
+
// @ts-ignore
|
|
744
705
|
outputSchema: zod.z.object({
|
|
745
706
|
text: zod.z.string()
|
|
746
707
|
}),
|
|
747
|
-
execute: async ({
|
|
748
|
-
inputData,
|
|
749
|
-
[_constants.EMITTER_SYMBOL]: emitter,
|
|
750
|
-
[_constants.STREAM_FORMAT_SYMBOL]: streamFormat,
|
|
751
|
-
requestContext,
|
|
752
|
-
tracingContext,
|
|
753
|
-
abortSignal,
|
|
754
|
-
abort,
|
|
755
|
-
writer
|
|
756
|
-
}) => {
|
|
708
|
+
execute: async ({ inputData, [_constants.EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort, tracingContext }) => {
|
|
757
709
|
let streamPromise = {};
|
|
758
710
|
streamPromise.promise = new Promise((resolve, reject) => {
|
|
759
711
|
streamPromise.resolve = resolve;
|
|
@@ -763,60 +715,61 @@ function createStep(params, agentOptions) {
|
|
|
763
715
|
name: params.name,
|
|
764
716
|
args: inputData
|
|
765
717
|
};
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
...agentOptions ?? {},
|
|
770
|
-
// resourceId: inputData.resourceId,
|
|
771
|
-
// threadId: inputData.threadId,
|
|
772
|
-
requestContext,
|
|
718
|
+
if ((await params.getLLM()).getModel().specificationVersion === `v2`) {
|
|
719
|
+
const { fullStream } = await params.stream(inputData.prompt, {
|
|
720
|
+
runtimeContext,
|
|
773
721
|
tracingContext,
|
|
774
722
|
onFinish: (result) => {
|
|
775
723
|
streamPromise.resolve(result.text);
|
|
776
|
-
void agentOptions?.onFinish?.(result);
|
|
777
724
|
},
|
|
778
725
|
abortSignal
|
|
779
726
|
});
|
|
780
|
-
|
|
727
|
+
if (abortSignal.aborted) {
|
|
728
|
+
return abort();
|
|
729
|
+
}
|
|
730
|
+
await emitter.emit("watch-v2", {
|
|
731
|
+
type: "tool-call-streaming-start",
|
|
732
|
+
...toolData ?? {}
|
|
733
|
+
});
|
|
734
|
+
for await (const chunk of fullStream) {
|
|
735
|
+
if (chunk.type === "text-delta") {
|
|
736
|
+
await emitter.emit("watch-v2", {
|
|
737
|
+
type: "tool-call-delta",
|
|
738
|
+
...toolData ?? {},
|
|
739
|
+
argsTextDelta: chunk.payload.text
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
}
|
|
781
743
|
} else {
|
|
782
|
-
const
|
|
783
|
-
|
|
784
|
-
requestContext,
|
|
744
|
+
const { fullStream } = await params.streamLegacy(inputData.prompt, {
|
|
745
|
+
runtimeContext,
|
|
785
746
|
tracingContext,
|
|
786
747
|
onFinish: (result) => {
|
|
787
748
|
streamPromise.resolve(result.text);
|
|
788
|
-
void agentOptions?.onFinish?.(result);
|
|
789
749
|
},
|
|
790
750
|
abortSignal
|
|
791
751
|
});
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
await emitter.emit("watch", {
|
|
752
|
+
if (abortSignal.aborted) {
|
|
753
|
+
return abort();
|
|
754
|
+
}
|
|
755
|
+
await emitter.emit("watch-v2", {
|
|
796
756
|
type: "tool-call-streaming-start",
|
|
797
757
|
...toolData ?? {}
|
|
798
758
|
});
|
|
799
|
-
for await (const chunk of
|
|
759
|
+
for await (const chunk of fullStream) {
|
|
800
760
|
if (chunk.type === "text-delta") {
|
|
801
|
-
await emitter.emit("watch", {
|
|
761
|
+
await emitter.emit("watch-v2", {
|
|
802
762
|
type: "tool-call-delta",
|
|
803
763
|
...toolData ?? {},
|
|
804
764
|
argsTextDelta: chunk.textDelta
|
|
805
765
|
});
|
|
806
766
|
}
|
|
807
767
|
}
|
|
808
|
-
await emitter.emit("watch", {
|
|
809
|
-
type: "tool-call-streaming-finish",
|
|
810
|
-
...toolData ?? {}
|
|
811
|
-
});
|
|
812
|
-
} else {
|
|
813
|
-
for await (const chunk of stream) {
|
|
814
|
-
await writer.write(chunk);
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
if (abortSignal.aborted) {
|
|
818
|
-
return abort();
|
|
819
768
|
}
|
|
769
|
+
await emitter.emit("watch-v2", {
|
|
770
|
+
type: "tool-call-streaming-finish",
|
|
771
|
+
...toolData ?? {}
|
|
772
|
+
});
|
|
820
773
|
return {
|
|
821
774
|
text: await streamPromise.promise
|
|
822
775
|
};
|
|
@@ -830,38 +783,20 @@ function createStep(params, agentOptions) {
|
|
|
830
783
|
}
|
|
831
784
|
return {
|
|
832
785
|
// TODO: tool probably should have strong id type
|
|
786
|
+
// @ts-ignore
|
|
833
787
|
id: params.id,
|
|
834
788
|
description: params.description,
|
|
835
789
|
inputSchema: params.inputSchema,
|
|
836
790
|
outputSchema: params.outputSchema,
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
requestContext,
|
|
843
|
-
tracingContext,
|
|
844
|
-
suspend,
|
|
845
|
-
resumeData,
|
|
846
|
-
runId,
|
|
847
|
-
workflowId,
|
|
848
|
-
state,
|
|
849
|
-
setState
|
|
850
|
-
}) => {
|
|
851
|
-
const toolContext = {
|
|
852
|
-
mastra,
|
|
853
|
-
requestContext,
|
|
791
|
+
execute: async ({ inputData, mastra, runtimeContext, tracingContext, suspend, resumeData }) => {
|
|
792
|
+
return params.execute({
|
|
793
|
+
context: inputData,
|
|
794
|
+
mastra: aiTracing.wrapMastra(mastra, tracingContext),
|
|
795
|
+
runtimeContext,
|
|
854
796
|
tracingContext,
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
suspend,
|
|
859
|
-
workflowId,
|
|
860
|
-
state,
|
|
861
|
-
setState
|
|
862
|
-
}
|
|
863
|
-
};
|
|
864
|
-
return params.execute(inputData, toolContext);
|
|
797
|
+
suspend,
|
|
798
|
+
resumeData
|
|
799
|
+
});
|
|
865
800
|
},
|
|
866
801
|
component: "TOOL"
|
|
867
802
|
};
|
|
@@ -895,8 +830,6 @@ function init(inngest) {
|
|
|
895
830
|
suspendSchema: step.suspendSchema,
|
|
896
831
|
stateSchema: step.stateSchema,
|
|
897
832
|
execute: step.execute,
|
|
898
|
-
retries: step.retries,
|
|
899
|
-
scorers: step.scorers,
|
|
900
833
|
component: step.component
|
|
901
834
|
};
|
|
902
835
|
},
|
|
@@ -906,8 +839,7 @@ function init(inngest) {
|
|
|
906
839
|
inputSchema: workflow.inputSchema,
|
|
907
840
|
outputSchema: workflow.outputSchema,
|
|
908
841
|
steps: workflow.stepDefs,
|
|
909
|
-
mastra: workflow.mastra
|
|
910
|
-
options: workflow.options
|
|
842
|
+
mastra: workflow.mastra
|
|
911
843
|
});
|
|
912
844
|
wf.setStepFlow(workflow.stepGraph);
|
|
913
845
|
wf.commit();
|
|
@@ -923,16 +855,63 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
923
855
|
this.inngestStep = inngestStep;
|
|
924
856
|
this.inngestAttempts = inngestAttempts;
|
|
925
857
|
}
|
|
926
|
-
async
|
|
858
|
+
async execute(params) {
|
|
859
|
+
await params.emitter.emit("watch-v2", {
|
|
860
|
+
type: "workflow-start",
|
|
861
|
+
payload: { runId: params.runId }
|
|
862
|
+
});
|
|
863
|
+
const result = await super.execute(params);
|
|
864
|
+
await params.emitter.emit("watch-v2", {
|
|
865
|
+
type: "workflow-finish",
|
|
866
|
+
payload: { runId: params.runId }
|
|
867
|
+
});
|
|
868
|
+
return result;
|
|
869
|
+
}
|
|
870
|
+
async fmtReturnValue(executionSpan, emitter, stepResults, lastOutput, error) {
|
|
927
871
|
const base = {
|
|
928
872
|
status: lastOutput.status,
|
|
929
873
|
steps: stepResults
|
|
930
874
|
};
|
|
931
875
|
if (lastOutput.status === "success") {
|
|
876
|
+
await emitter.emit("watch", {
|
|
877
|
+
type: "watch",
|
|
878
|
+
payload: {
|
|
879
|
+
workflowState: {
|
|
880
|
+
status: lastOutput.status,
|
|
881
|
+
steps: stepResults,
|
|
882
|
+
result: lastOutput.output
|
|
883
|
+
}
|
|
884
|
+
},
|
|
885
|
+
eventTimestamp: Date.now()
|
|
886
|
+
});
|
|
932
887
|
base.result = lastOutput.output;
|
|
933
888
|
} else if (lastOutput.status === "failed") {
|
|
934
889
|
base.error = error instanceof Error ? error?.stack ?? error.message : lastOutput?.error instanceof Error ? lastOutput.error.message : lastOutput.error ?? error ?? "Unknown error";
|
|
890
|
+
await emitter.emit("watch", {
|
|
891
|
+
type: "watch",
|
|
892
|
+
payload: {
|
|
893
|
+
workflowState: {
|
|
894
|
+
status: lastOutput.status,
|
|
895
|
+
steps: stepResults,
|
|
896
|
+
result: null,
|
|
897
|
+
error: base.error
|
|
898
|
+
}
|
|
899
|
+
},
|
|
900
|
+
eventTimestamp: Date.now()
|
|
901
|
+
});
|
|
935
902
|
} else if (lastOutput.status === "suspended") {
|
|
903
|
+
await emitter.emit("watch", {
|
|
904
|
+
type: "watch",
|
|
905
|
+
payload: {
|
|
906
|
+
workflowState: {
|
|
907
|
+
status: lastOutput.status,
|
|
908
|
+
steps: stepResults,
|
|
909
|
+
result: null,
|
|
910
|
+
error: null
|
|
911
|
+
}
|
|
912
|
+
},
|
|
913
|
+
eventTimestamp: Date.now()
|
|
914
|
+
});
|
|
936
915
|
const suspendedStepIds = Object.entries(stepResults).flatMap(([stepId, stepResult]) => {
|
|
937
916
|
if (stepResult?.status === "suspended") {
|
|
938
917
|
const nestedPath = stepResult?.suspendPayload?.__workflow_meta?.path;
|
|
@@ -942,6 +921,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
942
921
|
});
|
|
943
922
|
base.suspended = suspendedStepIds;
|
|
944
923
|
}
|
|
924
|
+
executionSpan?.end();
|
|
945
925
|
return base;
|
|
946
926
|
}
|
|
947
927
|
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
@@ -955,14 +935,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
955
935
|
stepResults,
|
|
956
936
|
emitter,
|
|
957
937
|
abortController,
|
|
958
|
-
|
|
938
|
+
runtimeContext,
|
|
959
939
|
executionContext,
|
|
960
940
|
writableStream,
|
|
961
941
|
tracingContext
|
|
962
942
|
}) {
|
|
963
943
|
let { duration, fn } = entry;
|
|
964
944
|
const sleepSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
965
|
-
type:
|
|
945
|
+
type: aiTracing.AISpanType.WORKFLOW_SLEEP,
|
|
966
946
|
name: `sleep: ${duration ? `${duration}ms` : "dynamic"}`,
|
|
967
947
|
attributes: {
|
|
968
948
|
durationMs: duration,
|
|
@@ -973,53 +953,45 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
973
953
|
if (fn) {
|
|
974
954
|
const stepCallId = crypto.randomUUID();
|
|
975
955
|
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
976
|
-
return await fn(
|
|
977
|
-
|
|
956
|
+
return await fn({
|
|
957
|
+
runId,
|
|
958
|
+
workflowId,
|
|
959
|
+
mastra: this.mastra,
|
|
960
|
+
runtimeContext,
|
|
961
|
+
inputData: prevOutput,
|
|
962
|
+
state: executionContext.state,
|
|
963
|
+
setState: (state) => {
|
|
964
|
+
executionContext.state = state;
|
|
965
|
+
},
|
|
966
|
+
runCount: -1,
|
|
967
|
+
tracingContext: {
|
|
968
|
+
currentSpan: sleepSpan
|
|
969
|
+
},
|
|
970
|
+
getInitData: () => stepResults?.input,
|
|
971
|
+
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
972
|
+
// TODO: this function shouldn't have suspend probably?
|
|
973
|
+
suspend: async (_suspendPayload) => {
|
|
974
|
+
},
|
|
975
|
+
bail: () => {
|
|
976
|
+
},
|
|
977
|
+
abort: () => {
|
|
978
|
+
abortController?.abort();
|
|
979
|
+
},
|
|
980
|
+
[_constants.EMITTER_SYMBOL]: emitter,
|
|
981
|
+
// TODO: add streamVNext support
|
|
982
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
983
|
+
engine: { step: this.inngestStep },
|
|
984
|
+
abortSignal: abortController?.signal,
|
|
985
|
+
writer: new tools.ToolStream(
|
|
978
986
|
{
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
inputData: prevOutput,
|
|
984
|
-
state: executionContext.state,
|
|
985
|
-
setState: (state) => {
|
|
986
|
-
executionContext.state = state;
|
|
987
|
-
},
|
|
988
|
-
retryCount: -1,
|
|
989
|
-
tracingContext: {
|
|
990
|
-
currentSpan: sleepSpan
|
|
991
|
-
},
|
|
992
|
-
getInitData: () => stepResults?.input,
|
|
993
|
-
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
994
|
-
// TODO: this function shouldn't have suspend probably?
|
|
995
|
-
suspend: async (_suspendPayload) => {
|
|
996
|
-
},
|
|
997
|
-
bail: () => {
|
|
998
|
-
},
|
|
999
|
-
abort: () => {
|
|
1000
|
-
abortController?.abort();
|
|
1001
|
-
},
|
|
1002
|
-
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1003
|
-
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1004
|
-
engine: { step: this.inngestStep },
|
|
1005
|
-
abortSignal: abortController?.signal,
|
|
1006
|
-
writer: new tools.ToolStream(
|
|
1007
|
-
{
|
|
1008
|
-
prefix: "workflow-step",
|
|
1009
|
-
callId: stepCallId,
|
|
1010
|
-
name: "sleep",
|
|
1011
|
-
runId
|
|
1012
|
-
},
|
|
1013
|
-
writableStream
|
|
1014
|
-
)
|
|
987
|
+
prefix: "workflow-step",
|
|
988
|
+
callId: stepCallId,
|
|
989
|
+
name: "sleep",
|
|
990
|
+
runId
|
|
1015
991
|
},
|
|
1016
|
-
|
|
1017
|
-
paramName: "runCount",
|
|
1018
|
-
deprecationMessage: workflows.runCountDeprecationMessage,
|
|
1019
|
-
logger: this.logger
|
|
1020
|
-
}
|
|
992
|
+
writableStream
|
|
1021
993
|
)
|
|
1022
|
-
);
|
|
994
|
+
});
|
|
1023
995
|
});
|
|
1024
996
|
sleepSpan?.update({
|
|
1025
997
|
attributes: {
|
|
@@ -1043,14 +1015,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1043
1015
|
stepResults,
|
|
1044
1016
|
emitter,
|
|
1045
1017
|
abortController,
|
|
1046
|
-
|
|
1018
|
+
runtimeContext,
|
|
1047
1019
|
executionContext,
|
|
1048
1020
|
writableStream,
|
|
1049
1021
|
tracingContext
|
|
1050
1022
|
}) {
|
|
1051
1023
|
let { date, fn } = entry;
|
|
1052
1024
|
const sleepUntilSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
1053
|
-
type:
|
|
1025
|
+
type: aiTracing.AISpanType.WORKFLOW_SLEEP,
|
|
1054
1026
|
name: `sleepUntil: ${date ? date.toISOString() : "dynamic"}`,
|
|
1055
1027
|
attributes: {
|
|
1056
1028
|
untilDate: date,
|
|
@@ -1062,53 +1034,45 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1062
1034
|
if (fn) {
|
|
1063
1035
|
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
1064
1036
|
const stepCallId = crypto.randomUUID();
|
|
1065
|
-
return await fn(
|
|
1066
|
-
|
|
1037
|
+
return await fn({
|
|
1038
|
+
runId,
|
|
1039
|
+
workflowId,
|
|
1040
|
+
mastra: this.mastra,
|
|
1041
|
+
runtimeContext,
|
|
1042
|
+
inputData: prevOutput,
|
|
1043
|
+
state: executionContext.state,
|
|
1044
|
+
setState: (state) => {
|
|
1045
|
+
executionContext.state = state;
|
|
1046
|
+
},
|
|
1047
|
+
runCount: -1,
|
|
1048
|
+
tracingContext: {
|
|
1049
|
+
currentSpan: sleepUntilSpan
|
|
1050
|
+
},
|
|
1051
|
+
getInitData: () => stepResults?.input,
|
|
1052
|
+
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
1053
|
+
// TODO: this function shouldn't have suspend probably?
|
|
1054
|
+
suspend: async (_suspendPayload) => {
|
|
1055
|
+
},
|
|
1056
|
+
bail: () => {
|
|
1057
|
+
},
|
|
1058
|
+
abort: () => {
|
|
1059
|
+
abortController?.abort();
|
|
1060
|
+
},
|
|
1061
|
+
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1062
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1063
|
+
// TODO: add streamVNext support
|
|
1064
|
+
engine: { step: this.inngestStep },
|
|
1065
|
+
abortSignal: abortController?.signal,
|
|
1066
|
+
writer: new tools.ToolStream(
|
|
1067
1067
|
{
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
inputData: prevOutput,
|
|
1073
|
-
state: executionContext.state,
|
|
1074
|
-
setState: (state) => {
|
|
1075
|
-
executionContext.state = state;
|
|
1076
|
-
},
|
|
1077
|
-
retryCount: -1,
|
|
1078
|
-
tracingContext: {
|
|
1079
|
-
currentSpan: sleepUntilSpan
|
|
1080
|
-
},
|
|
1081
|
-
getInitData: () => stepResults?.input,
|
|
1082
|
-
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
1083
|
-
// TODO: this function shouldn't have suspend probably?
|
|
1084
|
-
suspend: async (_suspendPayload) => {
|
|
1085
|
-
},
|
|
1086
|
-
bail: () => {
|
|
1087
|
-
},
|
|
1088
|
-
abort: () => {
|
|
1089
|
-
abortController?.abort();
|
|
1090
|
-
},
|
|
1091
|
-
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1092
|
-
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1093
|
-
engine: { step: this.inngestStep },
|
|
1094
|
-
abortSignal: abortController?.signal,
|
|
1095
|
-
writer: new tools.ToolStream(
|
|
1096
|
-
{
|
|
1097
|
-
prefix: "workflow-step",
|
|
1098
|
-
callId: stepCallId,
|
|
1099
|
-
name: "sleep",
|
|
1100
|
-
runId
|
|
1101
|
-
},
|
|
1102
|
-
writableStream
|
|
1103
|
-
)
|
|
1068
|
+
prefix: "workflow-step",
|
|
1069
|
+
callId: stepCallId,
|
|
1070
|
+
name: "sleep",
|
|
1071
|
+
runId
|
|
1104
1072
|
},
|
|
1105
|
-
|
|
1106
|
-
paramName: "runCount",
|
|
1107
|
-
deprecationMessage: workflows.runCountDeprecationMessage,
|
|
1108
|
-
logger: this.logger
|
|
1109
|
-
}
|
|
1073
|
+
writableStream
|
|
1110
1074
|
)
|
|
1111
|
-
);
|
|
1075
|
+
});
|
|
1112
1076
|
});
|
|
1113
1077
|
if (date && !(date instanceof Date)) {
|
|
1114
1078
|
date = new Date(date);
|
|
@@ -1132,6 +1096,16 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1132
1096
|
throw e;
|
|
1133
1097
|
}
|
|
1134
1098
|
}
|
|
1099
|
+
async executeWaitForEvent({ event, timeout }) {
|
|
1100
|
+
const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
|
|
1101
|
+
event: `user-event-${event}`,
|
|
1102
|
+
timeout: timeout ?? 5e3
|
|
1103
|
+
});
|
|
1104
|
+
if (eventData === null) {
|
|
1105
|
+
throw "Timeout waiting for event";
|
|
1106
|
+
}
|
|
1107
|
+
return eventData?.data;
|
|
1108
|
+
}
|
|
1135
1109
|
async executeStep({
|
|
1136
1110
|
step,
|
|
1137
1111
|
stepResults,
|
|
@@ -1141,14 +1115,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1141
1115
|
prevOutput,
|
|
1142
1116
|
emitter,
|
|
1143
1117
|
abortController,
|
|
1144
|
-
|
|
1118
|
+
runtimeContext,
|
|
1145
1119
|
tracingContext,
|
|
1146
1120
|
writableStream,
|
|
1147
1121
|
disableScorers
|
|
1148
1122
|
}) {
|
|
1149
|
-
const
|
|
1123
|
+
const stepAISpan = tracingContext?.currentSpan?.createChildSpan({
|
|
1150
1124
|
name: `workflow step: '${step.id}'`,
|
|
1151
|
-
type:
|
|
1125
|
+
type: aiTracing.AISpanType.WORKFLOW_STEP,
|
|
1152
1126
|
input: prevOutput,
|
|
1153
1127
|
attributes: {
|
|
1154
1128
|
stepId: step.id
|
|
@@ -1158,13 +1132,34 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1158
1132
|
const { inputData, validationError } = await workflows.validateStepInput({
|
|
1159
1133
|
prevOutput,
|
|
1160
1134
|
step,
|
|
1161
|
-
validateInputs: this.options?.validateInputs ??
|
|
1135
|
+
validateInputs: this.options?.validateInputs ?? false
|
|
1162
1136
|
});
|
|
1163
1137
|
const startedAt = await this.inngestStep.run(
|
|
1164
1138
|
`workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
|
|
1165
1139
|
async () => {
|
|
1166
1140
|
const startedAt2 = Date.now();
|
|
1167
1141
|
await emitter.emit("watch", {
|
|
1142
|
+
type: "watch",
|
|
1143
|
+
payload: {
|
|
1144
|
+
currentStep: {
|
|
1145
|
+
id: step.id,
|
|
1146
|
+
status: "running"
|
|
1147
|
+
},
|
|
1148
|
+
workflowState: {
|
|
1149
|
+
status: "running",
|
|
1150
|
+
steps: {
|
|
1151
|
+
...stepResults,
|
|
1152
|
+
[step.id]: {
|
|
1153
|
+
status: "running"
|
|
1154
|
+
}
|
|
1155
|
+
},
|
|
1156
|
+
result: null,
|
|
1157
|
+
error: null
|
|
1158
|
+
}
|
|
1159
|
+
},
|
|
1160
|
+
eventTimestamp: Date.now()
|
|
1161
|
+
});
|
|
1162
|
+
await emitter.emit("watch-v2", {
|
|
1168
1163
|
type: "workflow-step-start",
|
|
1169
1164
|
payload: {
|
|
1170
1165
|
id: step.id,
|
|
@@ -1183,7 +1178,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1183
1178
|
const isTimeTravel = !!(timeTravel && timeTravel.steps?.length > 1 && timeTravel.steps[0] === step.id);
|
|
1184
1179
|
try {
|
|
1185
1180
|
if (isResume) {
|
|
1186
|
-
runId = stepResults[resume?.steps?.[0]
|
|
1181
|
+
runId = stepResults[resume?.steps?.[0]]?.suspendPayload?.__workflow_meta?.runId ?? crypto.randomUUID();
|
|
1187
1182
|
const snapshot = await this.mastra?.getStorage()?.loadWorkflowSnapshot({
|
|
1188
1183
|
workflowName: step.id,
|
|
1189
1184
|
runId
|
|
@@ -1199,7 +1194,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1199
1194
|
steps: resume.steps.slice(1),
|
|
1200
1195
|
stepResults: snapshot?.context,
|
|
1201
1196
|
resumePayload: resume.resumePayload,
|
|
1202
|
-
|
|
1197
|
+
// @ts-ignore
|
|
1198
|
+
resumePath: snapshot?.suspendedPaths?.[resume.steps?.[1]]
|
|
1203
1199
|
},
|
|
1204
1200
|
outputOptions: { includeState: true }
|
|
1205
1201
|
}
|
|
@@ -1266,6 +1262,23 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1266
1262
|
async () => {
|
|
1267
1263
|
if (result.status === "failed") {
|
|
1268
1264
|
await emitter.emit("watch", {
|
|
1265
|
+
type: "watch",
|
|
1266
|
+
payload: {
|
|
1267
|
+
currentStep: {
|
|
1268
|
+
id: step.id,
|
|
1269
|
+
status: "failed",
|
|
1270
|
+
error: result?.error
|
|
1271
|
+
},
|
|
1272
|
+
workflowState: {
|
|
1273
|
+
status: "running",
|
|
1274
|
+
steps: stepResults,
|
|
1275
|
+
result: null,
|
|
1276
|
+
error: null
|
|
1277
|
+
}
|
|
1278
|
+
},
|
|
1279
|
+
eventTimestamp: Date.now()
|
|
1280
|
+
});
|
|
1281
|
+
await emitter.emit("watch-v2", {
|
|
1269
1282
|
type: "workflow-step-result",
|
|
1270
1283
|
payload: {
|
|
1271
1284
|
id: step.id,
|
|
@@ -1276,14 +1289,35 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1276
1289
|
});
|
|
1277
1290
|
return { executionContext, result: { status: "failed", error: result?.error } };
|
|
1278
1291
|
} else if (result.status === "suspended") {
|
|
1279
|
-
const suspendedSteps = Object.entries(result.steps).filter(([_stepName,
|
|
1280
|
-
const stepRes2 =
|
|
1292
|
+
const suspendedSteps = Object.entries(result.steps).filter(([_stepName, stepResult2]) => {
|
|
1293
|
+
const stepRes2 = stepResult2;
|
|
1281
1294
|
return stepRes2?.status === "suspended";
|
|
1282
1295
|
});
|
|
1283
|
-
for (const [stepName,
|
|
1284
|
-
const suspendPath = [stepName, ...
|
|
1296
|
+
for (const [stepName, stepResult2] of suspendedSteps) {
|
|
1297
|
+
const suspendPath = [stepName, ...stepResult2?.suspendPayload?.__workflow_meta?.path ?? []];
|
|
1285
1298
|
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
1286
1299
|
await emitter.emit("watch", {
|
|
1300
|
+
type: "watch",
|
|
1301
|
+
payload: {
|
|
1302
|
+
currentStep: {
|
|
1303
|
+
id: step.id,
|
|
1304
|
+
status: "suspended",
|
|
1305
|
+
payload: stepResult2.payload,
|
|
1306
|
+
suspendPayload: {
|
|
1307
|
+
...stepResult2?.suspendPayload,
|
|
1308
|
+
__workflow_meta: { runId, path: suspendPath }
|
|
1309
|
+
}
|
|
1310
|
+
},
|
|
1311
|
+
workflowState: {
|
|
1312
|
+
status: "running",
|
|
1313
|
+
steps: stepResults,
|
|
1314
|
+
result: null,
|
|
1315
|
+
error: null
|
|
1316
|
+
}
|
|
1317
|
+
},
|
|
1318
|
+
eventTimestamp: Date.now()
|
|
1319
|
+
});
|
|
1320
|
+
await emitter.emit("watch-v2", {
|
|
1287
1321
|
type: "workflow-step-suspended",
|
|
1288
1322
|
payload: {
|
|
1289
1323
|
id: step.id,
|
|
@@ -1294,14 +1328,31 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1294
1328
|
executionContext,
|
|
1295
1329
|
result: {
|
|
1296
1330
|
status: "suspended",
|
|
1297
|
-
payload:
|
|
1331
|
+
payload: stepResult2.payload,
|
|
1298
1332
|
suspendPayload: {
|
|
1299
|
-
...
|
|
1333
|
+
...stepResult2?.suspendPayload,
|
|
1300
1334
|
__workflow_meta: { runId, path: suspendPath }
|
|
1301
1335
|
}
|
|
1302
1336
|
}
|
|
1303
1337
|
};
|
|
1304
1338
|
}
|
|
1339
|
+
await emitter.emit("watch", {
|
|
1340
|
+
type: "watch",
|
|
1341
|
+
payload: {
|
|
1342
|
+
currentStep: {
|
|
1343
|
+
id: step.id,
|
|
1344
|
+
status: "suspended",
|
|
1345
|
+
payload: {}
|
|
1346
|
+
},
|
|
1347
|
+
workflowState: {
|
|
1348
|
+
status: "running",
|
|
1349
|
+
steps: stepResults,
|
|
1350
|
+
result: null,
|
|
1351
|
+
error: null
|
|
1352
|
+
}
|
|
1353
|
+
},
|
|
1354
|
+
eventTimestamp: Date.now()
|
|
1355
|
+
});
|
|
1305
1356
|
return {
|
|
1306
1357
|
executionContext,
|
|
1307
1358
|
result: {
|
|
@@ -1311,6 +1362,23 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1311
1362
|
};
|
|
1312
1363
|
}
|
|
1313
1364
|
await emitter.emit("watch", {
|
|
1365
|
+
type: "watch",
|
|
1366
|
+
payload: {
|
|
1367
|
+
currentStep: {
|
|
1368
|
+
id: step.id,
|
|
1369
|
+
status: "success",
|
|
1370
|
+
output: result?.result
|
|
1371
|
+
},
|
|
1372
|
+
workflowState: {
|
|
1373
|
+
status: "running",
|
|
1374
|
+
steps: stepResults,
|
|
1375
|
+
result: null,
|
|
1376
|
+
error: null
|
|
1377
|
+
}
|
|
1378
|
+
},
|
|
1379
|
+
eventTimestamp: Date.now()
|
|
1380
|
+
});
|
|
1381
|
+
await emitter.emit("watch-v2", {
|
|
1314
1382
|
type: "workflow-step-result",
|
|
1315
1383
|
payload: {
|
|
1316
1384
|
id: step.id,
|
|
@@ -1318,7 +1386,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1318
1386
|
output: result?.result
|
|
1319
1387
|
}
|
|
1320
1388
|
});
|
|
1321
|
-
await emitter.emit("watch", {
|
|
1389
|
+
await emitter.emit("watch-v2", {
|
|
1322
1390
|
type: "workflow-step-finish",
|
|
1323
1391
|
payload: {
|
|
1324
1392
|
id: step.id,
|
|
@@ -1329,7 +1397,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1329
1397
|
}
|
|
1330
1398
|
);
|
|
1331
1399
|
Object.assign(executionContext, res.executionContext);
|
|
1332
|
-
|
|
1400
|
+
const stepResult = {
|
|
1333
1401
|
...res.result,
|
|
1334
1402
|
startedAt,
|
|
1335
1403
|
endedAt: Date.now(),
|
|
@@ -1337,8 +1405,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1337
1405
|
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1338
1406
|
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1339
1407
|
};
|
|
1408
|
+
return { result: stepResult, executionContextState: executionContext.state };
|
|
1340
1409
|
}
|
|
1341
|
-
const stepCallId = crypto.randomUUID();
|
|
1342
1410
|
let stepRes;
|
|
1343
1411
|
try {
|
|
1344
1412
|
stepRes = await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}`, async () => {
|
|
@@ -1364,22 +1432,11 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1364
1432
|
if (validationError) {
|
|
1365
1433
|
throw validationError;
|
|
1366
1434
|
}
|
|
1367
|
-
const retryCount = this.getOrGenerateRetryCount(step.id);
|
|
1368
1435
|
const result = await step.execute({
|
|
1369
1436
|
runId: executionContext.runId,
|
|
1370
|
-
workflowId: executionContext.workflowId,
|
|
1371
1437
|
mastra: this.mastra,
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
writer: new tools.ToolStream(
|
|
1375
|
-
{
|
|
1376
|
-
prefix: "workflow-step",
|
|
1377
|
-
callId: stepCallId,
|
|
1378
|
-
name: step.id,
|
|
1379
|
-
runId: executionContext.runId
|
|
1380
|
-
},
|
|
1381
|
-
writableStream
|
|
1382
|
-
),
|
|
1438
|
+
runtimeContext,
|
|
1439
|
+
writableStream,
|
|
1383
1440
|
state: executionContext?.state ?? {},
|
|
1384
1441
|
setState: (state) => {
|
|
1385
1442
|
executionContext.state = state;
|
|
@@ -1387,18 +1444,11 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1387
1444
|
inputData,
|
|
1388
1445
|
resumeData: resumeDataToUse,
|
|
1389
1446
|
tracingContext: {
|
|
1390
|
-
currentSpan:
|
|
1447
|
+
currentSpan: stepAISpan
|
|
1391
1448
|
},
|
|
1392
1449
|
getInitData: () => stepResults?.input,
|
|
1393
1450
|
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
1394
1451
|
suspend: async (suspendPayload, suspendOptions) => {
|
|
1395
|
-
const { suspendData, validationError: validationError2 } = await workflows.validateStepSuspendData({
|
|
1396
|
-
suspendData: suspendPayload,
|
|
1397
|
-
step
|
|
1398
|
-
});
|
|
1399
|
-
if (validationError2) {
|
|
1400
|
-
throw validationError2;
|
|
1401
|
-
}
|
|
1402
1452
|
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
1403
1453
|
if (suspendOptions?.resumeLabel) {
|
|
1404
1454
|
const resumeLabel = Array.isArray(suspendOptions.resumeLabel) ? suspendOptions.resumeLabel : [suspendOptions.resumeLabel];
|
|
@@ -1409,16 +1459,18 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1409
1459
|
};
|
|
1410
1460
|
}
|
|
1411
1461
|
}
|
|
1412
|
-
suspended = { payload:
|
|
1462
|
+
suspended = { payload: suspendPayload };
|
|
1413
1463
|
},
|
|
1414
1464
|
bail: (result2) => {
|
|
1415
1465
|
bailed = { payload: result2 };
|
|
1416
1466
|
},
|
|
1417
|
-
|
|
1418
|
-
|
|
1467
|
+
resume: {
|
|
1468
|
+
steps: resume?.steps?.slice(1) || [],
|
|
1469
|
+
resumePayload: resume?.resumePayload,
|
|
1470
|
+
// @ts-ignore
|
|
1471
|
+
runId: stepResults[step.id]?.suspendPayload?.__workflow_meta?.runId
|
|
1419
1472
|
},
|
|
1420
1473
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1421
|
-
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1422
1474
|
engine: {
|
|
1423
1475
|
step: this.inngestStep
|
|
1424
1476
|
},
|
|
@@ -1438,7 +1490,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1438
1490
|
const stepFailure = {
|
|
1439
1491
|
status: "failed",
|
|
1440
1492
|
payload: inputData,
|
|
1441
|
-
error: e instanceof Error ? e.message : String(e),
|
|
1493
|
+
error: e instanceof Error ? e.stack ?? e.message : String(e),
|
|
1442
1494
|
endedAt: Date.now(),
|
|
1443
1495
|
startedAt,
|
|
1444
1496
|
resumedAt: resumeDataToUse ? startedAt : void 0,
|
|
@@ -1446,7 +1498,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1446
1498
|
};
|
|
1447
1499
|
execResults = stepFailure;
|
|
1448
1500
|
const fallbackErrorMessage = `Step ${step.id} failed`;
|
|
1449
|
-
|
|
1501
|
+
stepAISpan?.error({ error: new Error(execResults.error ?? fallbackErrorMessage) });
|
|
1450
1502
|
throw new inngest.RetryAfterError(execResults.error ?? fallbackErrorMessage, executionContext.retryConfig.delay, {
|
|
1451
1503
|
cause: execResults
|
|
1452
1504
|
});
|
|
@@ -1455,7 +1507,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1455
1507
|
execResults = {
|
|
1456
1508
|
status: "suspended",
|
|
1457
1509
|
suspendPayload: suspended.payload,
|
|
1458
|
-
...execResults.output ? { suspendOutput: execResults.output } : {},
|
|
1459
1510
|
payload: inputData,
|
|
1460
1511
|
suspendedAt: Date.now(),
|
|
1461
1512
|
startedAt,
|
|
@@ -1471,8 +1522,24 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1471
1522
|
startedAt
|
|
1472
1523
|
};
|
|
1473
1524
|
}
|
|
1525
|
+
await emitter.emit("watch", {
|
|
1526
|
+
type: "watch",
|
|
1527
|
+
payload: {
|
|
1528
|
+
currentStep: {
|
|
1529
|
+
id: step.id,
|
|
1530
|
+
...execResults
|
|
1531
|
+
},
|
|
1532
|
+
workflowState: {
|
|
1533
|
+
status: "running",
|
|
1534
|
+
steps: { ...stepResults, [step.id]: execResults },
|
|
1535
|
+
result: null,
|
|
1536
|
+
error: null
|
|
1537
|
+
}
|
|
1538
|
+
},
|
|
1539
|
+
eventTimestamp: Date.now()
|
|
1540
|
+
});
|
|
1474
1541
|
if (execResults.status === "suspended") {
|
|
1475
|
-
await emitter.emit("watch", {
|
|
1542
|
+
await emitter.emit("watch-v2", {
|
|
1476
1543
|
type: "workflow-step-suspended",
|
|
1477
1544
|
payload: {
|
|
1478
1545
|
id: step.id,
|
|
@@ -1480,14 +1547,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1480
1547
|
}
|
|
1481
1548
|
});
|
|
1482
1549
|
} else {
|
|
1483
|
-
await emitter.emit("watch", {
|
|
1550
|
+
await emitter.emit("watch-v2", {
|
|
1484
1551
|
type: "workflow-step-result",
|
|
1485
1552
|
payload: {
|
|
1486
1553
|
id: step.id,
|
|
1487
1554
|
...execResults
|
|
1488
1555
|
}
|
|
1489
1556
|
});
|
|
1490
|
-
await emitter.emit("watch", {
|
|
1557
|
+
await emitter.emit("watch-v2", {
|
|
1491
1558
|
type: "workflow-step-finish",
|
|
1492
1559
|
payload: {
|
|
1493
1560
|
id: step.id,
|
|
@@ -1495,25 +1562,25 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1495
1562
|
}
|
|
1496
1563
|
});
|
|
1497
1564
|
}
|
|
1498
|
-
|
|
1565
|
+
stepAISpan?.end({ output: execResults });
|
|
1499
1566
|
return { result: execResults, executionContext, stepResults };
|
|
1500
1567
|
});
|
|
1501
1568
|
} catch (e) {
|
|
1502
1569
|
const stepFailure = e instanceof Error ? e?.cause : {
|
|
1503
1570
|
status: "failed",
|
|
1504
|
-
error: e instanceof Error ? e.message : String(e),
|
|
1571
|
+
error: e instanceof Error ? e.stack ?? e.message : String(e),
|
|
1505
1572
|
payload: inputData,
|
|
1506
1573
|
startedAt,
|
|
1507
1574
|
endedAt: Date.now()
|
|
1508
1575
|
};
|
|
1509
|
-
await emitter.emit("watch", {
|
|
1576
|
+
await emitter.emit("watch-v2", {
|
|
1510
1577
|
type: "workflow-step-result",
|
|
1511
1578
|
payload: {
|
|
1512
1579
|
id: step.id,
|
|
1513
1580
|
...stepFailure
|
|
1514
1581
|
}
|
|
1515
1582
|
});
|
|
1516
|
-
await emitter.emit("watch", {
|
|
1583
|
+
await emitter.emit("watch-v2", {
|
|
1517
1584
|
type: "workflow-step-finish",
|
|
1518
1585
|
payload: {
|
|
1519
1586
|
id: step.id,
|
|
@@ -1539,16 +1606,19 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1539
1606
|
output: stepRes.result,
|
|
1540
1607
|
workflowId: executionContext.workflowId,
|
|
1541
1608
|
stepId: step.id,
|
|
1542
|
-
|
|
1609
|
+
runtimeContext,
|
|
1543
1610
|
disableScorers,
|
|
1544
|
-
tracingContext: { currentSpan:
|
|
1611
|
+
tracingContext: { currentSpan: stepAISpan }
|
|
1545
1612
|
});
|
|
1546
1613
|
}
|
|
1547
1614
|
});
|
|
1548
1615
|
}
|
|
1549
1616
|
Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
|
|
1550
1617
|
executionContext.state = stepRes.executionContext.state;
|
|
1551
|
-
return
|
|
1618
|
+
return {
|
|
1619
|
+
result: stepRes.result,
|
|
1620
|
+
executionContextState: stepRes.executionContext.state
|
|
1621
|
+
};
|
|
1552
1622
|
}
|
|
1553
1623
|
async persistStepUpdate({
|
|
1554
1624
|
workflowId,
|
|
@@ -1585,6 +1655,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1585
1655
|
serializedStepGraph,
|
|
1586
1656
|
result,
|
|
1587
1657
|
error,
|
|
1658
|
+
// @ts-ignore
|
|
1588
1659
|
timestamp: Date.now()
|
|
1589
1660
|
}
|
|
1590
1661
|
});
|
|
@@ -1602,13 +1673,13 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1602
1673
|
executionContext,
|
|
1603
1674
|
emitter,
|
|
1604
1675
|
abortController,
|
|
1605
|
-
|
|
1676
|
+
runtimeContext,
|
|
1606
1677
|
writableStream,
|
|
1607
1678
|
disableScorers,
|
|
1608
1679
|
tracingContext
|
|
1609
1680
|
}) {
|
|
1610
1681
|
const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
1611
|
-
type:
|
|
1682
|
+
type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL,
|
|
1612
1683
|
name: `conditional: '${entry.conditions.length} conditions'`,
|
|
1613
1684
|
input: prevOutput,
|
|
1614
1685
|
attributes: {
|
|
@@ -1621,7 +1692,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1621
1692
|
entry.conditions.map(
|
|
1622
1693
|
(cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
|
|
1623
1694
|
const evalSpan = conditionalSpan?.createChildSpan({
|
|
1624
|
-
type:
|
|
1695
|
+
type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL_EVAL,
|
|
1625
1696
|
name: `condition: '${index}'`,
|
|
1626
1697
|
input: prevOutput,
|
|
1627
1698
|
attributes: {
|
|
@@ -1630,55 +1701,47 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1630
1701
|
tracingPolicy: this.options?.tracingPolicy
|
|
1631
1702
|
});
|
|
1632
1703
|
try {
|
|
1633
|
-
const result = await cond(
|
|
1634
|
-
|
|
1704
|
+
const result = await cond({
|
|
1705
|
+
runId,
|
|
1706
|
+
workflowId,
|
|
1707
|
+
mastra: this.mastra,
|
|
1708
|
+
runtimeContext,
|
|
1709
|
+
runCount: -1,
|
|
1710
|
+
inputData: prevOutput,
|
|
1711
|
+
state: executionContext.state,
|
|
1712
|
+
setState: (state) => {
|
|
1713
|
+
executionContext.state = state;
|
|
1714
|
+
},
|
|
1715
|
+
tracingContext: {
|
|
1716
|
+
currentSpan: evalSpan
|
|
1717
|
+
},
|
|
1718
|
+
getInitData: () => stepResults?.input,
|
|
1719
|
+
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
1720
|
+
// TODO: this function shouldn't have suspend probably?
|
|
1721
|
+
suspend: async (_suspendPayload) => {
|
|
1722
|
+
},
|
|
1723
|
+
bail: () => {
|
|
1724
|
+
},
|
|
1725
|
+
abort: () => {
|
|
1726
|
+
abortController.abort();
|
|
1727
|
+
},
|
|
1728
|
+
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1729
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1730
|
+
// TODO: add streamVNext support
|
|
1731
|
+
engine: {
|
|
1732
|
+
step: this.inngestStep
|
|
1733
|
+
},
|
|
1734
|
+
abortSignal: abortController.signal,
|
|
1735
|
+
writer: new tools.ToolStream(
|
|
1635
1736
|
{
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
retryCount: -1,
|
|
1641
|
-
inputData: prevOutput,
|
|
1642
|
-
state: executionContext.state,
|
|
1643
|
-
setState: (state) => {
|
|
1644
|
-
executionContext.state = state;
|
|
1645
|
-
},
|
|
1646
|
-
tracingContext: {
|
|
1647
|
-
currentSpan: evalSpan
|
|
1648
|
-
},
|
|
1649
|
-
getInitData: () => stepResults?.input,
|
|
1650
|
-
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
1651
|
-
// TODO: this function shouldn't have suspend probably?
|
|
1652
|
-
suspend: async (_suspendPayload) => {
|
|
1653
|
-
},
|
|
1654
|
-
bail: () => {
|
|
1655
|
-
},
|
|
1656
|
-
abort: () => {
|
|
1657
|
-
abortController.abort();
|
|
1658
|
-
},
|
|
1659
|
-
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1660
|
-
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1661
|
-
engine: {
|
|
1662
|
-
step: this.inngestStep
|
|
1663
|
-
},
|
|
1664
|
-
abortSignal: abortController.signal,
|
|
1665
|
-
writer: new tools.ToolStream(
|
|
1666
|
-
{
|
|
1667
|
-
prefix: "workflow-step",
|
|
1668
|
-
callId: crypto.randomUUID(),
|
|
1669
|
-
name: "conditional",
|
|
1670
|
-
runId
|
|
1671
|
-
},
|
|
1672
|
-
writableStream
|
|
1673
|
-
)
|
|
1737
|
+
prefix: "workflow-step",
|
|
1738
|
+
callId: crypto.randomUUID(),
|
|
1739
|
+
name: "conditional",
|
|
1740
|
+
runId
|
|
1674
1741
|
},
|
|
1675
|
-
|
|
1676
|
-
paramName: "runCount",
|
|
1677
|
-
deprecationMessage: workflows.runCountDeprecationMessage,
|
|
1678
|
-
logger: this.logger
|
|
1679
|
-
}
|
|
1742
|
+
writableStream
|
|
1680
1743
|
)
|
|
1681
|
-
);
|
|
1744
|
+
});
|
|
1682
1745
|
evalSpan?.end({
|
|
1683
1746
|
output: result,
|
|
1684
1747
|
attributes: {
|
|
@@ -1725,19 +1788,21 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1725
1788
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1726
1789
|
resumeLabels: executionContext.resumeLabels,
|
|
1727
1790
|
retryConfig: executionContext.retryConfig,
|
|
1791
|
+
executionSpan: executionContext.executionSpan,
|
|
1728
1792
|
state: executionContext.state
|
|
1729
1793
|
},
|
|
1730
1794
|
emitter,
|
|
1731
1795
|
abortController,
|
|
1732
|
-
|
|
1796
|
+
runtimeContext,
|
|
1733
1797
|
writableStream,
|
|
1734
1798
|
disableScorers,
|
|
1735
1799
|
tracingContext: {
|
|
1736
1800
|
currentSpan: conditionalSpan
|
|
1737
1801
|
}
|
|
1738
1802
|
});
|
|
1739
|
-
stepResults[step.step.id] = result;
|
|
1740
|
-
|
|
1803
|
+
stepResults[step.step.id] = result.result;
|
|
1804
|
+
executionContext.state = result.executionContextState;
|
|
1805
|
+
return result.result;
|
|
1741
1806
|
})
|
|
1742
1807
|
);
|
|
1743
1808
|
const hasFailed = results.find((result) => result.status === "failed");
|
|
@@ -1745,19 +1810,13 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1745
1810
|
if (hasFailed) {
|
|
1746
1811
|
execResults = { status: "failed", error: hasFailed.error };
|
|
1747
1812
|
} else if (hasSuspended) {
|
|
1748
|
-
execResults = {
|
|
1749
|
-
status: "suspended",
|
|
1750
|
-
suspendPayload: hasSuspended.suspendPayload,
|
|
1751
|
-
...hasSuspended.suspendOutput ? { suspendOutput: hasSuspended.suspendOutput } : {}
|
|
1752
|
-
};
|
|
1813
|
+
execResults = { status: "suspended", suspendPayload: hasSuspended.suspendPayload };
|
|
1753
1814
|
} else {
|
|
1754
1815
|
execResults = {
|
|
1755
1816
|
status: "success",
|
|
1756
1817
|
output: results.reduce((acc, result, index) => {
|
|
1757
1818
|
if (result.status === "success") {
|
|
1758
|
-
|
|
1759
|
-
acc[stepsToRun[index].step.id] = result.output;
|
|
1760
|
-
}
|
|
1819
|
+
acc[stepsToRun[index].step.id] = result.output;
|
|
1761
1820
|
}
|
|
1762
1821
|
return acc;
|
|
1763
1822
|
}, {})
|