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