@mastra/inngest 0.18.4 → 1.0.0-beta.1
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 +114 -46
- package/dist/index.cjs +316 -393
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +65 -70
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +317 -394
- package/dist/index.js.map +1 -1
- package/package.json +10 -14
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
2
|
import { ReadableStream } from 'stream/web';
|
|
3
3
|
import { subscribe } from '@inngest/realtime';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { RequestContext } from '@mastra/core/di';
|
|
5
|
+
import { wrapMastra, SpanType } from '@mastra/core/observability';
|
|
6
6
|
import { ChunkFrom, WorkflowRunOutput } from '@mastra/core/stream';
|
|
7
7
|
import { ToolStream, Tool } from '@mastra/core/tools';
|
|
8
|
-
import { Run, Workflow, DefaultExecutionEngine, getStepResult, validateStepInput } from '@mastra/core/workflows';
|
|
8
|
+
import { Run, Workflow, DefaultExecutionEngine, createDeprecationProxy, getStepResult, runCountDeprecationMessage, validateStepInput } 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.listWorkflows();
|
|
22
22
|
const workflowFunctions = Array.from(
|
|
23
23
|
new Set(
|
|
24
24
|
Object.values(wfs).flatMap((wf) => {
|
|
@@ -57,11 +57,12 @@ 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();
|
|
60
61
|
while (runs?.[0]?.status !== "Completed" || runs?.[0]?.event_id !== eventId) {
|
|
61
62
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
62
63
|
runs = await this.getRuns(eventId);
|
|
63
64
|
if (runs?.[0]?.status === "Failed") {
|
|
64
|
-
const snapshot = await
|
|
65
|
+
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
65
66
|
workflowName: this.workflowId,
|
|
66
67
|
runId: this.runId
|
|
67
68
|
});
|
|
@@ -70,7 +71,7 @@ var InngestRun = class extends Run {
|
|
|
70
71
|
};
|
|
71
72
|
}
|
|
72
73
|
if (runs?.[0]?.status === "Cancelled") {
|
|
73
|
-
const snapshot = await
|
|
74
|
+
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
74
75
|
workflowName: this.workflowId,
|
|
75
76
|
runId: this.runId
|
|
76
77
|
});
|
|
@@ -79,25 +80,20 @@ var InngestRun = class extends Run {
|
|
|
79
80
|
}
|
|
80
81
|
return runs?.[0];
|
|
81
82
|
}
|
|
82
|
-
async sendEvent(event, data) {
|
|
83
|
-
await this.inngest.send({
|
|
84
|
-
name: `user-event-${event}`,
|
|
85
|
-
data
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
83
|
async cancel() {
|
|
84
|
+
const storage = this.#mastra?.getStorage();
|
|
89
85
|
await this.inngest.send({
|
|
90
86
|
name: `cancel.workflow.${this.workflowId}`,
|
|
91
87
|
data: {
|
|
92
88
|
runId: this.runId
|
|
93
89
|
}
|
|
94
90
|
});
|
|
95
|
-
const snapshot = await
|
|
91
|
+
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
96
92
|
workflowName: this.workflowId,
|
|
97
93
|
runId: this.runId
|
|
98
94
|
});
|
|
99
95
|
if (snapshot) {
|
|
100
|
-
await
|
|
96
|
+
await storage?.persistWorkflowSnapshot({
|
|
101
97
|
workflowName: this.workflowId,
|
|
102
98
|
runId: this.runId,
|
|
103
99
|
resourceId: this.resourceId,
|
|
@@ -108,9 +104,15 @@ var InngestRun = class extends Run {
|
|
|
108
104
|
});
|
|
109
105
|
}
|
|
110
106
|
}
|
|
111
|
-
async start({
|
|
107
|
+
async start(params) {
|
|
108
|
+
return this._start(params);
|
|
109
|
+
}
|
|
110
|
+
async _start({
|
|
112
111
|
inputData,
|
|
113
|
-
initialState
|
|
112
|
+
initialState,
|
|
113
|
+
outputOptions,
|
|
114
|
+
tracingOptions,
|
|
115
|
+
format
|
|
114
116
|
}) {
|
|
115
117
|
await this.#mastra.getStorage()?.persistWorkflowSnapshot({
|
|
116
118
|
workflowName: this.workflowId,
|
|
@@ -137,7 +139,10 @@ var InngestRun = class extends Run {
|
|
|
137
139
|
inputData: inputDataToUse,
|
|
138
140
|
initialState: initialStateToUse,
|
|
139
141
|
runId: this.runId,
|
|
140
|
-
resourceId: this.resourceId
|
|
142
|
+
resourceId: this.resourceId,
|
|
143
|
+
outputOptions,
|
|
144
|
+
tracingOptions,
|
|
145
|
+
format
|
|
141
146
|
}
|
|
142
147
|
});
|
|
143
148
|
const eventId = eventOutput.ids[0];
|
|
@@ -166,10 +171,11 @@ var InngestRun = class extends Run {
|
|
|
166
171
|
return p;
|
|
167
172
|
}
|
|
168
173
|
async _resume(params) {
|
|
174
|
+
const storage = this.#mastra?.getStorage();
|
|
169
175
|
const steps = (Array.isArray(params.step) ? params.step : [params.step]).map(
|
|
170
176
|
(step) => typeof step === "string" ? step : step?.id
|
|
171
177
|
);
|
|
172
|
-
const snapshot = await
|
|
178
|
+
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
173
179
|
workflowName: this.workflowId,
|
|
174
180
|
runId: this.runId
|
|
175
181
|
});
|
|
@@ -203,12 +209,12 @@ var InngestRun = class extends Run {
|
|
|
203
209
|
}
|
|
204
210
|
return result;
|
|
205
211
|
}
|
|
206
|
-
watch(cb
|
|
212
|
+
watch(cb) {
|
|
207
213
|
let active = true;
|
|
208
214
|
const streamPromise = subscribe(
|
|
209
215
|
{
|
|
210
216
|
channel: `workflow:${this.workflowId}:${this.runId}`,
|
|
211
|
-
topics: [
|
|
217
|
+
topics: ["watch"],
|
|
212
218
|
app: this.inngest
|
|
213
219
|
},
|
|
214
220
|
(message) => {
|
|
@@ -226,20 +232,35 @@ var InngestRun = class extends Run {
|
|
|
226
232
|
});
|
|
227
233
|
};
|
|
228
234
|
}
|
|
229
|
-
streamLegacy({ inputData,
|
|
235
|
+
streamLegacy({ inputData, requestContext } = {}) {
|
|
230
236
|
const { readable, writable } = new TransformStream();
|
|
231
237
|
const writer = writable.getWriter();
|
|
232
238
|
const unwatch = this.watch(async (event) => {
|
|
233
239
|
try {
|
|
240
|
+
await writer.write({
|
|
241
|
+
// @ts-ignore
|
|
242
|
+
type: "start",
|
|
243
|
+
// @ts-ignore
|
|
244
|
+
payload: { runId: this.runId }
|
|
245
|
+
});
|
|
234
246
|
const e = {
|
|
235
247
|
...event,
|
|
236
248
|
type: event.type.replace("workflow-", "")
|
|
237
249
|
};
|
|
250
|
+
if (e.type === "step-output") {
|
|
251
|
+
e.type = e.payload.output.type;
|
|
252
|
+
e.payload = e.payload.output.payload;
|
|
253
|
+
}
|
|
238
254
|
await writer.write(e);
|
|
239
255
|
} catch {
|
|
240
256
|
}
|
|
241
|
-
}
|
|
257
|
+
});
|
|
242
258
|
this.closeStreamAction = async () => {
|
|
259
|
+
await writer.write({
|
|
260
|
+
type: "finish",
|
|
261
|
+
// @ts-ignore
|
|
262
|
+
payload: { runId: this.runId }
|
|
263
|
+
});
|
|
243
264
|
unwatch();
|
|
244
265
|
try {
|
|
245
266
|
await writer.close();
|
|
@@ -249,7 +270,7 @@ var InngestRun = class extends Run {
|
|
|
249
270
|
writer.releaseLock();
|
|
250
271
|
}
|
|
251
272
|
};
|
|
252
|
-
this.executionResults = this.
|
|
273
|
+
this.executionResults = this._start({ inputData, requestContext, format: "legacy" }).then((result) => {
|
|
253
274
|
if (result.status !== "suspended") {
|
|
254
275
|
this.closeStreamAction?.().catch(() => {
|
|
255
276
|
});
|
|
@@ -263,11 +284,18 @@ var InngestRun = class extends Run {
|
|
|
263
284
|
}
|
|
264
285
|
stream({
|
|
265
286
|
inputData,
|
|
266
|
-
|
|
267
|
-
|
|
287
|
+
requestContext,
|
|
288
|
+
tracingOptions,
|
|
289
|
+
closeOnSuspend = true,
|
|
290
|
+
initialState,
|
|
291
|
+
outputOptions
|
|
268
292
|
} = {}) {
|
|
293
|
+
if (this.closeStreamAction && this.streamOutput) {
|
|
294
|
+
return this.streamOutput;
|
|
295
|
+
}
|
|
296
|
+
this.closeStreamAction = async () => {
|
|
297
|
+
};
|
|
269
298
|
const self = this;
|
|
270
|
-
let streamOutput;
|
|
271
299
|
const stream = new ReadableStream({
|
|
272
300
|
async start(controller) {
|
|
273
301
|
const unwatch = self.watch(async ({ type, from = ChunkFrom.WORKFLOW, payload }) => {
|
|
@@ -276,11 +304,11 @@ var InngestRun = class extends Run {
|
|
|
276
304
|
runId: self.runId,
|
|
277
305
|
from,
|
|
278
306
|
payload: {
|
|
279
|
-
stepName: payload
|
|
307
|
+
stepName: payload?.id,
|
|
280
308
|
...payload
|
|
281
309
|
}
|
|
282
310
|
});
|
|
283
|
-
}
|
|
311
|
+
});
|
|
284
312
|
self.closeStreamAction = async () => {
|
|
285
313
|
unwatch();
|
|
286
314
|
try {
|
|
@@ -289,29 +317,46 @@ var InngestRun = class extends Run {
|
|
|
289
317
|
console.error("Error closing stream:", err);
|
|
290
318
|
}
|
|
291
319
|
};
|
|
292
|
-
const executionResultsPromise = self.
|
|
320
|
+
const executionResultsPromise = self._start({
|
|
293
321
|
inputData,
|
|
294
|
-
|
|
322
|
+
requestContext,
|
|
323
|
+
// tracingContext, // We are not able to pass a reference to a span here, what to do?
|
|
324
|
+
initialState,
|
|
325
|
+
tracingOptions,
|
|
326
|
+
outputOptions,
|
|
327
|
+
format: "vnext"
|
|
295
328
|
});
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
329
|
+
let executionResults;
|
|
330
|
+
try {
|
|
331
|
+
executionResults = await executionResultsPromise;
|
|
332
|
+
if (closeOnSuspend) {
|
|
333
|
+
self.closeStreamAction?.().catch(() => {
|
|
334
|
+
});
|
|
335
|
+
} else if (executionResults.status !== "suspended") {
|
|
336
|
+
self.closeStreamAction?.().catch(() => {
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
if (self.streamOutput) {
|
|
340
|
+
self.streamOutput.updateResults(
|
|
341
|
+
executionResults
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
} catch (err) {
|
|
345
|
+
self.streamOutput?.rejectResults(err);
|
|
301
346
|
self.closeStreamAction?.().catch(() => {
|
|
302
347
|
});
|
|
303
348
|
}
|
|
304
|
-
if (streamOutput) {
|
|
305
|
-
streamOutput.updateResults(executionResults);
|
|
306
|
-
}
|
|
307
349
|
}
|
|
308
350
|
});
|
|
309
|
-
streamOutput = new WorkflowRunOutput({
|
|
351
|
+
this.streamOutput = new WorkflowRunOutput({
|
|
310
352
|
runId: this.runId,
|
|
311
353
|
workflowId: this.workflowId,
|
|
312
354
|
stream
|
|
313
355
|
});
|
|
314
|
-
return streamOutput;
|
|
356
|
+
return this.streamOutput;
|
|
357
|
+
}
|
|
358
|
+
streamVNext(args = {}) {
|
|
359
|
+
return this.stream(args);
|
|
315
360
|
}
|
|
316
361
|
};
|
|
317
362
|
var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
@@ -329,13 +374,13 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
329
374
|
this.#mastra = params.mastra;
|
|
330
375
|
this.inngest = inngest;
|
|
331
376
|
}
|
|
332
|
-
async
|
|
377
|
+
async listWorkflowRuns(args) {
|
|
333
378
|
const storage = this.#mastra?.getStorage();
|
|
334
379
|
if (!storage) {
|
|
335
380
|
this.logger.debug("Cannot get workflow runs. Mastra engine is not initialized");
|
|
336
381
|
return { runs: [], total: 0 };
|
|
337
382
|
}
|
|
338
|
-
return storage.
|
|
383
|
+
return storage.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
|
|
339
384
|
}
|
|
340
385
|
async getWorkflowRunById(runId) {
|
|
341
386
|
const storage = this.#mastra?.getStorage();
|
|
@@ -364,16 +409,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
364
409
|
}
|
|
365
410
|
}
|
|
366
411
|
}
|
|
367
|
-
|
|
368
|
-
* @deprecated Use createRunAsync() instead.
|
|
369
|
-
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
370
|
-
*/
|
|
371
|
-
createRun(_options) {
|
|
372
|
-
throw new Error(
|
|
373
|
-
"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."
|
|
374
|
-
);
|
|
375
|
-
}
|
|
376
|
-
async createRunAsync(options) {
|
|
412
|
+
async createRun(options) {
|
|
377
413
|
const runIdToUse = options?.runId || randomUUID();
|
|
378
414
|
const run = this.runs.get(runIdToUse) ?? new InngestRun(
|
|
379
415
|
{
|
|
@@ -435,7 +471,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
435
471
|
},
|
|
436
472
|
{ event: `workflow.${this.id}` },
|
|
437
473
|
async ({ event, step, attempt, publish }) => {
|
|
438
|
-
let { inputData, initialState, runId, resourceId, resume, outputOptions } = event.data;
|
|
474
|
+
let { inputData, initialState, runId, resourceId, resume, outputOptions, format } = event.data;
|
|
439
475
|
if (!runId) {
|
|
440
476
|
runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
|
|
441
477
|
return randomUUID();
|
|
@@ -474,13 +510,19 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
474
510
|
initialState,
|
|
475
511
|
emitter,
|
|
476
512
|
retryConfig: this.retryConfig,
|
|
477
|
-
|
|
513
|
+
requestContext: new RequestContext(),
|
|
478
514
|
// TODO
|
|
479
515
|
resume,
|
|
516
|
+
format,
|
|
480
517
|
abortController: new AbortController(),
|
|
481
|
-
currentSpan:
|
|
482
|
-
|
|
483
|
-
|
|
518
|
+
// currentSpan: undefined, // TODO: Pass actual parent Span from workflow execution context
|
|
519
|
+
outputOptions,
|
|
520
|
+
writableStream: new WritableStream({
|
|
521
|
+
write(chunk) {
|
|
522
|
+
void emitter.emit("watch", chunk).catch(() => {
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
})
|
|
484
526
|
});
|
|
485
527
|
await step.run(`workflow.${this.id}.finalize`, async () => {
|
|
486
528
|
if (result.status === "failed") {
|
|
@@ -518,7 +560,7 @@ function isAgent(params) {
|
|
|
518
560
|
function isTool(params) {
|
|
519
561
|
return params instanceof Tool;
|
|
520
562
|
}
|
|
521
|
-
function createStep(params) {
|
|
563
|
+
function createStep(params, agentOptions) {
|
|
522
564
|
if (isAgent(params)) {
|
|
523
565
|
return {
|
|
524
566
|
id: params.name,
|
|
@@ -526,12 +568,23 @@ function createStep(params) {
|
|
|
526
568
|
// @ts-ignore
|
|
527
569
|
inputSchema: z.object({
|
|
528
570
|
prompt: z.string()
|
|
571
|
+
// resourceId: z.string().optional(),
|
|
572
|
+
// threadId: z.string().optional(),
|
|
529
573
|
}),
|
|
530
574
|
// @ts-ignore
|
|
531
575
|
outputSchema: z.object({
|
|
532
576
|
text: z.string()
|
|
533
577
|
}),
|
|
534
|
-
execute: async ({
|
|
578
|
+
execute: async ({
|
|
579
|
+
inputData,
|
|
580
|
+
[EMITTER_SYMBOL]: emitter,
|
|
581
|
+
[STREAM_FORMAT_SYMBOL]: streamFormat,
|
|
582
|
+
requestContext,
|
|
583
|
+
tracingContext,
|
|
584
|
+
abortSignal,
|
|
585
|
+
abort,
|
|
586
|
+
writer
|
|
587
|
+
}) => {
|
|
535
588
|
let streamPromise = {};
|
|
536
589
|
streamPromise.promise = new Promise((resolve, reject) => {
|
|
537
590
|
streamPromise.resolve = resolve;
|
|
@@ -541,61 +594,60 @@ function createStep(params) {
|
|
|
541
594
|
name: params.name,
|
|
542
595
|
args: inputData
|
|
543
596
|
};
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
597
|
+
let stream;
|
|
598
|
+
if ((await params.getModel()).specificationVersion === "v1") {
|
|
599
|
+
const { fullStream } = await params.streamLegacy(inputData.prompt, {
|
|
600
|
+
...agentOptions ?? {},
|
|
601
|
+
// resourceId: inputData.resourceId,
|
|
602
|
+
// threadId: inputData.threadId,
|
|
603
|
+
requestContext,
|
|
547
604
|
tracingContext,
|
|
548
605
|
onFinish: (result) => {
|
|
549
606
|
streamPromise.resolve(result.text);
|
|
607
|
+
void agentOptions?.onFinish?.(result);
|
|
550
608
|
},
|
|
551
609
|
abortSignal
|
|
552
610
|
});
|
|
553
|
-
|
|
554
|
-
return abort();
|
|
555
|
-
}
|
|
556
|
-
await emitter.emit("watch-v2", {
|
|
557
|
-
type: "tool-call-streaming-start",
|
|
558
|
-
...toolData ?? {}
|
|
559
|
-
});
|
|
560
|
-
for await (const chunk of fullStream) {
|
|
561
|
-
if (chunk.type === "text-delta") {
|
|
562
|
-
await emitter.emit("watch-v2", {
|
|
563
|
-
type: "tool-call-delta",
|
|
564
|
-
...toolData ?? {},
|
|
565
|
-
argsTextDelta: chunk.payload.text
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
}
|
|
611
|
+
stream = fullStream;
|
|
569
612
|
} else {
|
|
570
|
-
const
|
|
571
|
-
|
|
613
|
+
const modelOutput = await params.stream(inputData.prompt, {
|
|
614
|
+
...agentOptions ?? {},
|
|
615
|
+
requestContext,
|
|
572
616
|
tracingContext,
|
|
573
617
|
onFinish: (result) => {
|
|
574
618
|
streamPromise.resolve(result.text);
|
|
619
|
+
void agentOptions?.onFinish?.(result);
|
|
575
620
|
},
|
|
576
621
|
abortSignal
|
|
577
622
|
});
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
await emitter.emit("watch
|
|
623
|
+
stream = modelOutput.fullStream;
|
|
624
|
+
}
|
|
625
|
+
if (streamFormat === "legacy") {
|
|
626
|
+
await emitter.emit("watch", {
|
|
582
627
|
type: "tool-call-streaming-start",
|
|
583
628
|
...toolData ?? {}
|
|
584
629
|
});
|
|
585
|
-
for await (const chunk of
|
|
630
|
+
for await (const chunk of stream) {
|
|
586
631
|
if (chunk.type === "text-delta") {
|
|
587
|
-
await emitter.emit("watch
|
|
632
|
+
await emitter.emit("watch", {
|
|
588
633
|
type: "tool-call-delta",
|
|
589
634
|
...toolData ?? {},
|
|
590
635
|
argsTextDelta: chunk.textDelta
|
|
591
636
|
});
|
|
592
637
|
}
|
|
593
638
|
}
|
|
639
|
+
await emitter.emit("watch", {
|
|
640
|
+
type: "tool-call-streaming-finish",
|
|
641
|
+
...toolData ?? {}
|
|
642
|
+
});
|
|
643
|
+
} else {
|
|
644
|
+
for await (const chunk of stream) {
|
|
645
|
+
await writer.write(chunk);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
if (abortSignal.aborted) {
|
|
649
|
+
return abort();
|
|
594
650
|
}
|
|
595
|
-
await emitter.emit("watch-v2", {
|
|
596
|
-
type: "tool-call-streaming-finish",
|
|
597
|
-
...toolData ?? {}
|
|
598
|
-
});
|
|
599
651
|
return {
|
|
600
652
|
text: await streamPromise.promise
|
|
601
653
|
};
|
|
@@ -614,11 +666,11 @@ function createStep(params) {
|
|
|
614
666
|
description: params.description,
|
|
615
667
|
inputSchema: params.inputSchema,
|
|
616
668
|
outputSchema: params.outputSchema,
|
|
617
|
-
execute: async ({ inputData, mastra,
|
|
669
|
+
execute: async ({ inputData, mastra, requestContext, tracingContext, suspend, resumeData }) => {
|
|
618
670
|
return params.execute({
|
|
619
671
|
context: inputData,
|
|
620
672
|
mastra: wrapMastra(mastra, tracingContext),
|
|
621
|
-
|
|
673
|
+
requestContext,
|
|
622
674
|
tracingContext,
|
|
623
675
|
suspend,
|
|
624
676
|
resumeData
|
|
@@ -681,63 +733,16 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
681
733
|
this.inngestStep = inngestStep;
|
|
682
734
|
this.inngestAttempts = inngestAttempts;
|
|
683
735
|
}
|
|
684
|
-
async
|
|
685
|
-
await params.emitter.emit("watch-v2", {
|
|
686
|
-
type: "workflow-start",
|
|
687
|
-
payload: { runId: params.runId }
|
|
688
|
-
});
|
|
689
|
-
const result = await super.execute(params);
|
|
690
|
-
await params.emitter.emit("watch-v2", {
|
|
691
|
-
type: "workflow-finish",
|
|
692
|
-
payload: { runId: params.runId }
|
|
693
|
-
});
|
|
694
|
-
return result;
|
|
695
|
-
}
|
|
696
|
-
async fmtReturnValue(executionSpan, emitter, stepResults, lastOutput, error) {
|
|
736
|
+
async fmtReturnValue(emitter, stepResults, lastOutput, error) {
|
|
697
737
|
const base = {
|
|
698
738
|
status: lastOutput.status,
|
|
699
739
|
steps: stepResults
|
|
700
740
|
};
|
|
701
741
|
if (lastOutput.status === "success") {
|
|
702
|
-
await emitter.emit("watch", {
|
|
703
|
-
type: "watch",
|
|
704
|
-
payload: {
|
|
705
|
-
workflowState: {
|
|
706
|
-
status: lastOutput.status,
|
|
707
|
-
steps: stepResults,
|
|
708
|
-
result: lastOutput.output
|
|
709
|
-
}
|
|
710
|
-
},
|
|
711
|
-
eventTimestamp: Date.now()
|
|
712
|
-
});
|
|
713
742
|
base.result = lastOutput.output;
|
|
714
743
|
} else if (lastOutput.status === "failed") {
|
|
715
744
|
base.error = error instanceof Error ? error?.stack ?? error.message : lastOutput?.error instanceof Error ? lastOutput.error.message : lastOutput.error ?? error ?? "Unknown error";
|
|
716
|
-
await emitter.emit("watch", {
|
|
717
|
-
type: "watch",
|
|
718
|
-
payload: {
|
|
719
|
-
workflowState: {
|
|
720
|
-
status: lastOutput.status,
|
|
721
|
-
steps: stepResults,
|
|
722
|
-
result: null,
|
|
723
|
-
error: base.error
|
|
724
|
-
}
|
|
725
|
-
},
|
|
726
|
-
eventTimestamp: Date.now()
|
|
727
|
-
});
|
|
728
745
|
} else if (lastOutput.status === "suspended") {
|
|
729
|
-
await emitter.emit("watch", {
|
|
730
|
-
type: "watch",
|
|
731
|
-
payload: {
|
|
732
|
-
workflowState: {
|
|
733
|
-
status: lastOutput.status,
|
|
734
|
-
steps: stepResults,
|
|
735
|
-
result: null,
|
|
736
|
-
error: null
|
|
737
|
-
}
|
|
738
|
-
},
|
|
739
|
-
eventTimestamp: Date.now()
|
|
740
|
-
});
|
|
741
746
|
const suspendedStepIds = Object.entries(stepResults).flatMap(([stepId, stepResult]) => {
|
|
742
747
|
if (stepResult?.status === "suspended") {
|
|
743
748
|
const nestedPath = stepResult?.suspendPayload?.__workflow_meta?.path;
|
|
@@ -747,7 +752,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
747
752
|
});
|
|
748
753
|
base.suspended = suspendedStepIds;
|
|
749
754
|
}
|
|
750
|
-
executionSpan?.end();
|
|
751
755
|
return base;
|
|
752
756
|
}
|
|
753
757
|
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
@@ -761,14 +765,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
761
765
|
stepResults,
|
|
762
766
|
emitter,
|
|
763
767
|
abortController,
|
|
764
|
-
|
|
768
|
+
requestContext,
|
|
765
769
|
executionContext,
|
|
766
770
|
writableStream,
|
|
767
771
|
tracingContext
|
|
768
772
|
}) {
|
|
769
773
|
let { duration, fn } = entry;
|
|
770
774
|
const sleepSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
771
|
-
type:
|
|
775
|
+
type: SpanType.WORKFLOW_SLEEP,
|
|
772
776
|
name: `sleep: ${duration ? `${duration}ms` : "dynamic"}`,
|
|
773
777
|
attributes: {
|
|
774
778
|
durationMs: duration,
|
|
@@ -779,45 +783,53 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
779
783
|
if (fn) {
|
|
780
784
|
const stepCallId = randomUUID();
|
|
781
785
|
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
782
|
-
return await fn(
|
|
783
|
-
|
|
784
|
-
workflowId,
|
|
785
|
-
mastra: this.mastra,
|
|
786
|
-
runtimeContext,
|
|
787
|
-
inputData: prevOutput,
|
|
788
|
-
state: executionContext.state,
|
|
789
|
-
setState: (state) => {
|
|
790
|
-
executionContext.state = state;
|
|
791
|
-
},
|
|
792
|
-
runCount: -1,
|
|
793
|
-
tracingContext: {
|
|
794
|
-
currentSpan: sleepSpan
|
|
795
|
-
},
|
|
796
|
-
getInitData: () => stepResults?.input,
|
|
797
|
-
getStepResult: getStepResult.bind(this, stepResults),
|
|
798
|
-
// TODO: this function shouldn't have suspend probably?
|
|
799
|
-
suspend: async (_suspendPayload) => {
|
|
800
|
-
},
|
|
801
|
-
bail: () => {
|
|
802
|
-
},
|
|
803
|
-
abort: () => {
|
|
804
|
-
abortController?.abort();
|
|
805
|
-
},
|
|
806
|
-
[EMITTER_SYMBOL]: emitter,
|
|
807
|
-
// TODO: add streamVNext support
|
|
808
|
-
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
809
|
-
engine: { step: this.inngestStep },
|
|
810
|
-
abortSignal: abortController?.signal,
|
|
811
|
-
writer: new ToolStream(
|
|
786
|
+
return await fn(
|
|
787
|
+
createDeprecationProxy(
|
|
812
788
|
{
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
789
|
+
runId,
|
|
790
|
+
workflowId,
|
|
791
|
+
mastra: this.mastra,
|
|
792
|
+
requestContext,
|
|
793
|
+
inputData: prevOutput,
|
|
794
|
+
state: executionContext.state,
|
|
795
|
+
setState: (state) => {
|
|
796
|
+
executionContext.state = state;
|
|
797
|
+
},
|
|
798
|
+
retryCount: -1,
|
|
799
|
+
tracingContext: {
|
|
800
|
+
currentSpan: sleepSpan
|
|
801
|
+
},
|
|
802
|
+
getInitData: () => stepResults?.input,
|
|
803
|
+
getStepResult: getStepResult.bind(this, stepResults),
|
|
804
|
+
// TODO: this function shouldn't have suspend probably?
|
|
805
|
+
suspend: async (_suspendPayload) => {
|
|
806
|
+
},
|
|
807
|
+
bail: () => {
|
|
808
|
+
},
|
|
809
|
+
abort: () => {
|
|
810
|
+
abortController?.abort();
|
|
811
|
+
},
|
|
812
|
+
[EMITTER_SYMBOL]: emitter,
|
|
813
|
+
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
814
|
+
engine: { step: this.inngestStep },
|
|
815
|
+
abortSignal: abortController?.signal,
|
|
816
|
+
writer: new ToolStream(
|
|
817
|
+
{
|
|
818
|
+
prefix: "workflow-step",
|
|
819
|
+
callId: stepCallId,
|
|
820
|
+
name: "sleep",
|
|
821
|
+
runId
|
|
822
|
+
},
|
|
823
|
+
writableStream
|
|
824
|
+
)
|
|
817
825
|
},
|
|
818
|
-
|
|
826
|
+
{
|
|
827
|
+
paramName: "runCount",
|
|
828
|
+
deprecationMessage: runCountDeprecationMessage,
|
|
829
|
+
logger: this.logger
|
|
830
|
+
}
|
|
819
831
|
)
|
|
820
|
-
|
|
832
|
+
);
|
|
821
833
|
});
|
|
822
834
|
sleepSpan?.update({
|
|
823
835
|
attributes: {
|
|
@@ -841,14 +853,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
841
853
|
stepResults,
|
|
842
854
|
emitter,
|
|
843
855
|
abortController,
|
|
844
|
-
|
|
856
|
+
requestContext,
|
|
845
857
|
executionContext,
|
|
846
858
|
writableStream,
|
|
847
859
|
tracingContext
|
|
848
860
|
}) {
|
|
849
861
|
let { date, fn } = entry;
|
|
850
862
|
const sleepUntilSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
851
|
-
type:
|
|
863
|
+
type: SpanType.WORKFLOW_SLEEP,
|
|
852
864
|
name: `sleepUntil: ${date ? date.toISOString() : "dynamic"}`,
|
|
853
865
|
attributes: {
|
|
854
866
|
untilDate: date,
|
|
@@ -860,45 +872,53 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
860
872
|
if (fn) {
|
|
861
873
|
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
862
874
|
const stepCallId = randomUUID();
|
|
863
|
-
return await fn(
|
|
864
|
-
|
|
865
|
-
workflowId,
|
|
866
|
-
mastra: this.mastra,
|
|
867
|
-
runtimeContext,
|
|
868
|
-
inputData: prevOutput,
|
|
869
|
-
state: executionContext.state,
|
|
870
|
-
setState: (state) => {
|
|
871
|
-
executionContext.state = state;
|
|
872
|
-
},
|
|
873
|
-
runCount: -1,
|
|
874
|
-
tracingContext: {
|
|
875
|
-
currentSpan: sleepUntilSpan
|
|
876
|
-
},
|
|
877
|
-
getInitData: () => stepResults?.input,
|
|
878
|
-
getStepResult: getStepResult.bind(this, stepResults),
|
|
879
|
-
// TODO: this function shouldn't have suspend probably?
|
|
880
|
-
suspend: async (_suspendPayload) => {
|
|
881
|
-
},
|
|
882
|
-
bail: () => {
|
|
883
|
-
},
|
|
884
|
-
abort: () => {
|
|
885
|
-
abortController?.abort();
|
|
886
|
-
},
|
|
887
|
-
[EMITTER_SYMBOL]: emitter,
|
|
888
|
-
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
889
|
-
// TODO: add streamVNext support
|
|
890
|
-
engine: { step: this.inngestStep },
|
|
891
|
-
abortSignal: abortController?.signal,
|
|
892
|
-
writer: new ToolStream(
|
|
875
|
+
return await fn(
|
|
876
|
+
createDeprecationProxy(
|
|
893
877
|
{
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
878
|
+
runId,
|
|
879
|
+
workflowId,
|
|
880
|
+
mastra: this.mastra,
|
|
881
|
+
requestContext,
|
|
882
|
+
inputData: prevOutput,
|
|
883
|
+
state: executionContext.state,
|
|
884
|
+
setState: (state) => {
|
|
885
|
+
executionContext.state = state;
|
|
886
|
+
},
|
|
887
|
+
retryCount: -1,
|
|
888
|
+
tracingContext: {
|
|
889
|
+
currentSpan: sleepUntilSpan
|
|
890
|
+
},
|
|
891
|
+
getInitData: () => stepResults?.input,
|
|
892
|
+
getStepResult: getStepResult.bind(this, stepResults),
|
|
893
|
+
// TODO: this function shouldn't have suspend probably?
|
|
894
|
+
suspend: async (_suspendPayload) => {
|
|
895
|
+
},
|
|
896
|
+
bail: () => {
|
|
897
|
+
},
|
|
898
|
+
abort: () => {
|
|
899
|
+
abortController?.abort();
|
|
900
|
+
},
|
|
901
|
+
[EMITTER_SYMBOL]: emitter,
|
|
902
|
+
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
903
|
+
engine: { step: this.inngestStep },
|
|
904
|
+
abortSignal: abortController?.signal,
|
|
905
|
+
writer: new ToolStream(
|
|
906
|
+
{
|
|
907
|
+
prefix: "workflow-step",
|
|
908
|
+
callId: stepCallId,
|
|
909
|
+
name: "sleep",
|
|
910
|
+
runId
|
|
911
|
+
},
|
|
912
|
+
writableStream
|
|
913
|
+
)
|
|
898
914
|
},
|
|
899
|
-
|
|
915
|
+
{
|
|
916
|
+
paramName: "runCount",
|
|
917
|
+
deprecationMessage: runCountDeprecationMessage,
|
|
918
|
+
logger: this.logger
|
|
919
|
+
}
|
|
900
920
|
)
|
|
901
|
-
|
|
921
|
+
);
|
|
902
922
|
});
|
|
903
923
|
if (date && !(date instanceof Date)) {
|
|
904
924
|
date = new Date(date);
|
|
@@ -922,16 +942,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
922
942
|
throw e;
|
|
923
943
|
}
|
|
924
944
|
}
|
|
925
|
-
async executeWaitForEvent({ event, timeout }) {
|
|
926
|
-
const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
|
|
927
|
-
event: `user-event-${event}`,
|
|
928
|
-
timeout: timeout ?? 5e3
|
|
929
|
-
});
|
|
930
|
-
if (eventData === null) {
|
|
931
|
-
throw "Timeout waiting for event";
|
|
932
|
-
}
|
|
933
|
-
return eventData?.data;
|
|
934
|
-
}
|
|
935
945
|
async executeStep({
|
|
936
946
|
step,
|
|
937
947
|
stepResults,
|
|
@@ -940,14 +950,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
940
950
|
prevOutput,
|
|
941
951
|
emitter,
|
|
942
952
|
abortController,
|
|
943
|
-
|
|
953
|
+
requestContext,
|
|
944
954
|
tracingContext,
|
|
945
955
|
writableStream,
|
|
946
956
|
disableScorers
|
|
947
957
|
}) {
|
|
948
|
-
const
|
|
958
|
+
const stepSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
949
959
|
name: `workflow step: '${step.id}'`,
|
|
950
|
-
type:
|
|
960
|
+
type: SpanType.WORKFLOW_STEP,
|
|
951
961
|
input: prevOutput,
|
|
952
962
|
attributes: {
|
|
953
963
|
stepId: step.id
|
|
@@ -964,27 +974,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
964
974
|
async () => {
|
|
965
975
|
const startedAt2 = Date.now();
|
|
966
976
|
await emitter.emit("watch", {
|
|
967
|
-
type: "watch",
|
|
968
|
-
payload: {
|
|
969
|
-
currentStep: {
|
|
970
|
-
id: step.id,
|
|
971
|
-
status: "running"
|
|
972
|
-
},
|
|
973
|
-
workflowState: {
|
|
974
|
-
status: "running",
|
|
975
|
-
steps: {
|
|
976
|
-
...stepResults,
|
|
977
|
-
[step.id]: {
|
|
978
|
-
status: "running"
|
|
979
|
-
}
|
|
980
|
-
},
|
|
981
|
-
result: null,
|
|
982
|
-
error: null
|
|
983
|
-
}
|
|
984
|
-
},
|
|
985
|
-
eventTimestamp: Date.now()
|
|
986
|
-
});
|
|
987
|
-
await emitter.emit("watch-v2", {
|
|
988
977
|
type: "workflow-step-start",
|
|
989
978
|
payload: {
|
|
990
979
|
id: step.id,
|
|
@@ -1060,23 +1049,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1060
1049
|
async () => {
|
|
1061
1050
|
if (result.status === "failed") {
|
|
1062
1051
|
await emitter.emit("watch", {
|
|
1063
|
-
type: "watch",
|
|
1064
|
-
payload: {
|
|
1065
|
-
currentStep: {
|
|
1066
|
-
id: step.id,
|
|
1067
|
-
status: "failed",
|
|
1068
|
-
error: result?.error
|
|
1069
|
-
},
|
|
1070
|
-
workflowState: {
|
|
1071
|
-
status: "running",
|
|
1072
|
-
steps: stepResults,
|
|
1073
|
-
result: null,
|
|
1074
|
-
error: null
|
|
1075
|
-
}
|
|
1076
|
-
},
|
|
1077
|
-
eventTimestamp: Date.now()
|
|
1078
|
-
});
|
|
1079
|
-
await emitter.emit("watch-v2", {
|
|
1080
1052
|
type: "workflow-step-result",
|
|
1081
1053
|
payload: {
|
|
1082
1054
|
id: step.id,
|
|
@@ -1095,27 +1067,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1095
1067
|
const suspendPath = [stepName, ...stepResult?.suspendPayload?.__workflow_meta?.path ?? []];
|
|
1096
1068
|
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
1097
1069
|
await emitter.emit("watch", {
|
|
1098
|
-
type: "watch",
|
|
1099
|
-
payload: {
|
|
1100
|
-
currentStep: {
|
|
1101
|
-
id: step.id,
|
|
1102
|
-
status: "suspended",
|
|
1103
|
-
payload: stepResult.payload,
|
|
1104
|
-
suspendPayload: {
|
|
1105
|
-
...stepResult?.suspendPayload,
|
|
1106
|
-
__workflow_meta: { runId, path: suspendPath }
|
|
1107
|
-
}
|
|
1108
|
-
},
|
|
1109
|
-
workflowState: {
|
|
1110
|
-
status: "running",
|
|
1111
|
-
steps: stepResults,
|
|
1112
|
-
result: null,
|
|
1113
|
-
error: null
|
|
1114
|
-
}
|
|
1115
|
-
},
|
|
1116
|
-
eventTimestamp: Date.now()
|
|
1117
|
-
});
|
|
1118
|
-
await emitter.emit("watch-v2", {
|
|
1119
1070
|
type: "workflow-step-suspended",
|
|
1120
1071
|
payload: {
|
|
1121
1072
|
id: step.id,
|
|
@@ -1134,23 +1085,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1134
1085
|
}
|
|
1135
1086
|
};
|
|
1136
1087
|
}
|
|
1137
|
-
await emitter.emit("watch", {
|
|
1138
|
-
type: "watch",
|
|
1139
|
-
payload: {
|
|
1140
|
-
currentStep: {
|
|
1141
|
-
id: step.id,
|
|
1142
|
-
status: "suspended",
|
|
1143
|
-
payload: {}
|
|
1144
|
-
},
|
|
1145
|
-
workflowState: {
|
|
1146
|
-
status: "running",
|
|
1147
|
-
steps: stepResults,
|
|
1148
|
-
result: null,
|
|
1149
|
-
error: null
|
|
1150
|
-
}
|
|
1151
|
-
},
|
|
1152
|
-
eventTimestamp: Date.now()
|
|
1153
|
-
});
|
|
1154
1088
|
return {
|
|
1155
1089
|
executionContext,
|
|
1156
1090
|
result: {
|
|
@@ -1160,23 +1094,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1160
1094
|
};
|
|
1161
1095
|
}
|
|
1162
1096
|
await emitter.emit("watch", {
|
|
1163
|
-
type: "watch",
|
|
1164
|
-
payload: {
|
|
1165
|
-
currentStep: {
|
|
1166
|
-
id: step.id,
|
|
1167
|
-
status: "success",
|
|
1168
|
-
output: result?.result
|
|
1169
|
-
},
|
|
1170
|
-
workflowState: {
|
|
1171
|
-
status: "running",
|
|
1172
|
-
steps: stepResults,
|
|
1173
|
-
result: null,
|
|
1174
|
-
error: null
|
|
1175
|
-
}
|
|
1176
|
-
},
|
|
1177
|
-
eventTimestamp: Date.now()
|
|
1178
|
-
});
|
|
1179
|
-
await emitter.emit("watch-v2", {
|
|
1180
1097
|
type: "workflow-step-result",
|
|
1181
1098
|
payload: {
|
|
1182
1099
|
id: step.id,
|
|
@@ -1184,7 +1101,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1184
1101
|
output: result?.result
|
|
1185
1102
|
}
|
|
1186
1103
|
});
|
|
1187
|
-
await emitter.emit("watch
|
|
1104
|
+
await emitter.emit("watch", {
|
|
1188
1105
|
type: "workflow-step-finish",
|
|
1189
1106
|
payload: {
|
|
1190
1107
|
id: step.id,
|
|
@@ -1204,6 +1121,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1204
1121
|
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1205
1122
|
};
|
|
1206
1123
|
}
|
|
1124
|
+
const stepCallId = randomUUID();
|
|
1207
1125
|
let stepRes;
|
|
1208
1126
|
try {
|
|
1209
1127
|
stepRes = await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}`, async () => {
|
|
@@ -1217,8 +1135,16 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1217
1135
|
const result = await step.execute({
|
|
1218
1136
|
runId: executionContext.runId,
|
|
1219
1137
|
mastra: this.mastra,
|
|
1220
|
-
|
|
1221
|
-
|
|
1138
|
+
requestContext,
|
|
1139
|
+
writer: new ToolStream(
|
|
1140
|
+
{
|
|
1141
|
+
prefix: "workflow-step",
|
|
1142
|
+
callId: stepCallId,
|
|
1143
|
+
name: step.id,
|
|
1144
|
+
runId: executionContext.runId
|
|
1145
|
+
},
|
|
1146
|
+
writableStream
|
|
1147
|
+
),
|
|
1222
1148
|
state: executionContext?.state ?? {},
|
|
1223
1149
|
setState: (state) => {
|
|
1224
1150
|
executionContext.state = state;
|
|
@@ -1226,7 +1152,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1226
1152
|
inputData,
|
|
1227
1153
|
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1228
1154
|
tracingContext: {
|
|
1229
|
-
currentSpan:
|
|
1155
|
+
currentSpan: stepSpan
|
|
1230
1156
|
},
|
|
1231
1157
|
getInitData: () => stepResults?.input,
|
|
1232
1158
|
getStepResult: getStepResult.bind(this, stepResults),
|
|
@@ -1253,6 +1179,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1253
1179
|
runId: stepResults[step.id]?.suspendPayload?.__workflow_meta?.runId
|
|
1254
1180
|
},
|
|
1255
1181
|
[EMITTER_SYMBOL]: emitter,
|
|
1182
|
+
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1256
1183
|
engine: {
|
|
1257
1184
|
step: this.inngestStep
|
|
1258
1185
|
},
|
|
@@ -1280,7 +1207,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1280
1207
|
};
|
|
1281
1208
|
execResults = stepFailure;
|
|
1282
1209
|
const fallbackErrorMessage = `Step ${step.id} failed`;
|
|
1283
|
-
|
|
1210
|
+
stepSpan?.error({ error: new Error(execResults.error ?? fallbackErrorMessage) });
|
|
1284
1211
|
throw new RetryAfterError(execResults.error ?? fallbackErrorMessage, executionContext.retryConfig.delay, {
|
|
1285
1212
|
cause: execResults
|
|
1286
1213
|
});
|
|
@@ -1289,6 +1216,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1289
1216
|
execResults = {
|
|
1290
1217
|
status: "suspended",
|
|
1291
1218
|
suspendPayload: suspended.payload,
|
|
1219
|
+
...execResults.output ? { suspendOutput: execResults.output } : {},
|
|
1292
1220
|
payload: inputData,
|
|
1293
1221
|
suspendedAt: Date.now(),
|
|
1294
1222
|
startedAt,
|
|
@@ -1304,24 +1232,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1304
1232
|
startedAt
|
|
1305
1233
|
};
|
|
1306
1234
|
}
|
|
1307
|
-
await emitter.emit("watch", {
|
|
1308
|
-
type: "watch",
|
|
1309
|
-
payload: {
|
|
1310
|
-
currentStep: {
|
|
1311
|
-
id: step.id,
|
|
1312
|
-
...execResults
|
|
1313
|
-
},
|
|
1314
|
-
workflowState: {
|
|
1315
|
-
status: "running",
|
|
1316
|
-
steps: { ...stepResults, [step.id]: execResults },
|
|
1317
|
-
result: null,
|
|
1318
|
-
error: null
|
|
1319
|
-
}
|
|
1320
|
-
},
|
|
1321
|
-
eventTimestamp: Date.now()
|
|
1322
|
-
});
|
|
1323
1235
|
if (execResults.status === "suspended") {
|
|
1324
|
-
await emitter.emit("watch
|
|
1236
|
+
await emitter.emit("watch", {
|
|
1325
1237
|
type: "workflow-step-suspended",
|
|
1326
1238
|
payload: {
|
|
1327
1239
|
id: step.id,
|
|
@@ -1329,14 +1241,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1329
1241
|
}
|
|
1330
1242
|
});
|
|
1331
1243
|
} else {
|
|
1332
|
-
await emitter.emit("watch
|
|
1244
|
+
await emitter.emit("watch", {
|
|
1333
1245
|
type: "workflow-step-result",
|
|
1334
1246
|
payload: {
|
|
1335
1247
|
id: step.id,
|
|
1336
1248
|
...execResults
|
|
1337
1249
|
}
|
|
1338
1250
|
});
|
|
1339
|
-
await emitter.emit("watch
|
|
1251
|
+
await emitter.emit("watch", {
|
|
1340
1252
|
type: "workflow-step-finish",
|
|
1341
1253
|
payload: {
|
|
1342
1254
|
id: step.id,
|
|
@@ -1344,7 +1256,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1344
1256
|
}
|
|
1345
1257
|
});
|
|
1346
1258
|
}
|
|
1347
|
-
|
|
1259
|
+
stepSpan?.end({ output: execResults });
|
|
1348
1260
|
return { result: execResults, executionContext, stepResults };
|
|
1349
1261
|
});
|
|
1350
1262
|
} catch (e) {
|
|
@@ -1374,9 +1286,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1374
1286
|
output: stepRes.result,
|
|
1375
1287
|
workflowId: executionContext.workflowId,
|
|
1376
1288
|
stepId: step.id,
|
|
1377
|
-
|
|
1289
|
+
requestContext,
|
|
1378
1290
|
disableScorers,
|
|
1379
|
-
tracingContext: { currentSpan:
|
|
1291
|
+
tracingContext: { currentSpan: stepSpan }
|
|
1380
1292
|
});
|
|
1381
1293
|
}
|
|
1382
1294
|
});
|
|
@@ -1437,13 +1349,13 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1437
1349
|
executionContext,
|
|
1438
1350
|
emitter,
|
|
1439
1351
|
abortController,
|
|
1440
|
-
|
|
1352
|
+
requestContext,
|
|
1441
1353
|
writableStream,
|
|
1442
1354
|
disableScorers,
|
|
1443
1355
|
tracingContext
|
|
1444
1356
|
}) {
|
|
1445
1357
|
const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
1446
|
-
type:
|
|
1358
|
+
type: SpanType.WORKFLOW_CONDITIONAL,
|
|
1447
1359
|
name: `conditional: '${entry.conditions.length} conditions'`,
|
|
1448
1360
|
input: prevOutput,
|
|
1449
1361
|
attributes: {
|
|
@@ -1456,7 +1368,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1456
1368
|
entry.conditions.map(
|
|
1457
1369
|
(cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
|
|
1458
1370
|
const evalSpan = conditionalSpan?.createChildSpan({
|
|
1459
|
-
type:
|
|
1371
|
+
type: SpanType.WORKFLOW_CONDITIONAL_EVAL,
|
|
1460
1372
|
name: `condition: '${index}'`,
|
|
1461
1373
|
input: prevOutput,
|
|
1462
1374
|
attributes: {
|
|
@@ -1465,47 +1377,55 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1465
1377
|
tracingPolicy: this.options?.tracingPolicy
|
|
1466
1378
|
});
|
|
1467
1379
|
try {
|
|
1468
|
-
const result = await cond(
|
|
1469
|
-
|
|
1470
|
-
workflowId,
|
|
1471
|
-
mastra: this.mastra,
|
|
1472
|
-
runtimeContext,
|
|
1473
|
-
runCount: -1,
|
|
1474
|
-
inputData: prevOutput,
|
|
1475
|
-
state: executionContext.state,
|
|
1476
|
-
setState: (state) => {
|
|
1477
|
-
executionContext.state = state;
|
|
1478
|
-
},
|
|
1479
|
-
tracingContext: {
|
|
1480
|
-
currentSpan: evalSpan
|
|
1481
|
-
},
|
|
1482
|
-
getInitData: () => stepResults?.input,
|
|
1483
|
-
getStepResult: getStepResult.bind(this, stepResults),
|
|
1484
|
-
// TODO: this function shouldn't have suspend probably?
|
|
1485
|
-
suspend: async (_suspendPayload) => {
|
|
1486
|
-
},
|
|
1487
|
-
bail: () => {
|
|
1488
|
-
},
|
|
1489
|
-
abort: () => {
|
|
1490
|
-
abortController.abort();
|
|
1491
|
-
},
|
|
1492
|
-
[EMITTER_SYMBOL]: emitter,
|
|
1493
|
-
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1494
|
-
// TODO: add streamVNext support
|
|
1495
|
-
engine: {
|
|
1496
|
-
step: this.inngestStep
|
|
1497
|
-
},
|
|
1498
|
-
abortSignal: abortController.signal,
|
|
1499
|
-
writer: new ToolStream(
|
|
1380
|
+
const result = await cond(
|
|
1381
|
+
createDeprecationProxy(
|
|
1500
1382
|
{
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1383
|
+
runId,
|
|
1384
|
+
workflowId,
|
|
1385
|
+
mastra: this.mastra,
|
|
1386
|
+
requestContext,
|
|
1387
|
+
retryCount: -1,
|
|
1388
|
+
inputData: prevOutput,
|
|
1389
|
+
state: executionContext.state,
|
|
1390
|
+
setState: (state) => {
|
|
1391
|
+
executionContext.state = state;
|
|
1392
|
+
},
|
|
1393
|
+
tracingContext: {
|
|
1394
|
+
currentSpan: evalSpan
|
|
1395
|
+
},
|
|
1396
|
+
getInitData: () => stepResults?.input,
|
|
1397
|
+
getStepResult: getStepResult.bind(this, stepResults),
|
|
1398
|
+
// TODO: this function shouldn't have suspend probably?
|
|
1399
|
+
suspend: async (_suspendPayload) => {
|
|
1400
|
+
},
|
|
1401
|
+
bail: () => {
|
|
1402
|
+
},
|
|
1403
|
+
abort: () => {
|
|
1404
|
+
abortController.abort();
|
|
1405
|
+
},
|
|
1406
|
+
[EMITTER_SYMBOL]: emitter,
|
|
1407
|
+
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1408
|
+
engine: {
|
|
1409
|
+
step: this.inngestStep
|
|
1410
|
+
},
|
|
1411
|
+
abortSignal: abortController.signal,
|
|
1412
|
+
writer: new ToolStream(
|
|
1413
|
+
{
|
|
1414
|
+
prefix: "workflow-step",
|
|
1415
|
+
callId: randomUUID(),
|
|
1416
|
+
name: "conditional",
|
|
1417
|
+
runId
|
|
1418
|
+
},
|
|
1419
|
+
writableStream
|
|
1420
|
+
)
|
|
1505
1421
|
},
|
|
1506
|
-
|
|
1422
|
+
{
|
|
1423
|
+
paramName: "runCount",
|
|
1424
|
+
deprecationMessage: runCountDeprecationMessage,
|
|
1425
|
+
logger: this.logger
|
|
1426
|
+
}
|
|
1507
1427
|
)
|
|
1508
|
-
|
|
1428
|
+
);
|
|
1509
1429
|
evalSpan?.end({
|
|
1510
1430
|
output: result,
|
|
1511
1431
|
attributes: {
|
|
@@ -1550,12 +1470,11 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1550
1470
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1551
1471
|
resumeLabels: executionContext.resumeLabels,
|
|
1552
1472
|
retryConfig: executionContext.retryConfig,
|
|
1553
|
-
executionSpan: executionContext.executionSpan,
|
|
1554
1473
|
state: executionContext.state
|
|
1555
1474
|
},
|
|
1556
1475
|
emitter,
|
|
1557
1476
|
abortController,
|
|
1558
|
-
|
|
1477
|
+
requestContext,
|
|
1559
1478
|
writableStream,
|
|
1560
1479
|
disableScorers,
|
|
1561
1480
|
tracingContext: {
|
|
@@ -1571,7 +1490,11 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1571
1490
|
if (hasFailed) {
|
|
1572
1491
|
execResults = { status: "failed", error: hasFailed.error };
|
|
1573
1492
|
} else if (hasSuspended) {
|
|
1574
|
-
execResults = {
|
|
1493
|
+
execResults = {
|
|
1494
|
+
status: "suspended",
|
|
1495
|
+
suspendPayload: hasSuspended.suspendPayload,
|
|
1496
|
+
...hasSuspended.suspendOutput ? { suspendOutput: hasSuspended.suspendOutput } : {}
|
|
1497
|
+
};
|
|
1575
1498
|
} else {
|
|
1576
1499
|
execResults = {
|
|
1577
1500
|
status: "success",
|