@mastra/inngest 0.0.0-just-snapshot-20251014192224 → 0.0.0-main-test-20251105183450
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 +207 -3
- package/dist/index.cjs +378 -376
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +72 -64
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +379 -377
- package/dist/index.js.map +1 -1
- package/package.json +13 -10
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
|
+
import { ReadableStream } from 'stream/web';
|
|
2
3
|
import { subscribe } from '@inngest/realtime';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
4
|
+
import { RequestContext } from '@mastra/core/di';
|
|
5
|
+
import { wrapMastra, SpanType } from '@mastra/core/observability';
|
|
6
|
+
import { ChunkFrom, WorkflowRunOutput } from '@mastra/core/stream';
|
|
5
7
|
import { ToolStream, Tool } from '@mastra/core/tools';
|
|
6
|
-
import { Run, Workflow, DefaultExecutionEngine, getStepResult, validateStepInput } from '@mastra/core/workflows';
|
|
8
|
+
import { Run, Workflow, DefaultExecutionEngine, createDeprecationProxy, getStepResult, runCountDeprecationMessage, validateStepInput } from '@mastra/core/workflows';
|
|
7
9
|
import { EMITTER_SYMBOL, STREAM_FORMAT_SYMBOL } from '@mastra/core/workflows/_constants';
|
|
8
10
|
import { NonRetriableError, RetryAfterError } from 'inngest';
|
|
9
11
|
import { serve as serve$1 } from 'inngest/hono';
|
|
@@ -16,7 +18,7 @@ function serve({
|
|
|
16
18
|
functions: userFunctions = [],
|
|
17
19
|
registerOptions
|
|
18
20
|
}) {
|
|
19
|
-
const wfs = mastra.
|
|
21
|
+
const wfs = mastra.listWorkflows();
|
|
20
22
|
const workflowFunctions = Array.from(
|
|
21
23
|
new Set(
|
|
22
24
|
Object.values(wfs).flatMap((wf) => {
|
|
@@ -55,11 +57,12 @@ var InngestRun = class extends Run {
|
|
|
55
57
|
}
|
|
56
58
|
async getRunOutput(eventId) {
|
|
57
59
|
let runs = await this.getRuns(eventId);
|
|
60
|
+
const storage = this.#mastra?.getStorage();
|
|
58
61
|
while (runs?.[0]?.status !== "Completed" || runs?.[0]?.event_id !== eventId) {
|
|
59
62
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
60
63
|
runs = await this.getRuns(eventId);
|
|
61
64
|
if (runs?.[0]?.status === "Failed") {
|
|
62
|
-
const snapshot = await
|
|
65
|
+
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
63
66
|
workflowName: this.workflowId,
|
|
64
67
|
runId: this.runId
|
|
65
68
|
});
|
|
@@ -68,7 +71,7 @@ var InngestRun = class extends Run {
|
|
|
68
71
|
};
|
|
69
72
|
}
|
|
70
73
|
if (runs?.[0]?.status === "Cancelled") {
|
|
71
|
-
const snapshot = await
|
|
74
|
+
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
72
75
|
workflowName: this.workflowId,
|
|
73
76
|
runId: this.runId
|
|
74
77
|
});
|
|
@@ -84,18 +87,19 @@ var InngestRun = class extends Run {
|
|
|
84
87
|
});
|
|
85
88
|
}
|
|
86
89
|
async cancel() {
|
|
90
|
+
const storage = this.#mastra?.getStorage();
|
|
87
91
|
await this.inngest.send({
|
|
88
92
|
name: `cancel.workflow.${this.workflowId}`,
|
|
89
93
|
data: {
|
|
90
94
|
runId: this.runId
|
|
91
95
|
}
|
|
92
96
|
});
|
|
93
|
-
const snapshot = await
|
|
97
|
+
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
94
98
|
workflowName: this.workflowId,
|
|
95
99
|
runId: this.runId
|
|
96
100
|
});
|
|
97
101
|
if (snapshot) {
|
|
98
|
-
await
|
|
102
|
+
await storage?.persistWorkflowSnapshot({
|
|
99
103
|
workflowName: this.workflowId,
|
|
100
104
|
runId: this.runId,
|
|
101
105
|
resourceId: this.resourceId,
|
|
@@ -106,9 +110,15 @@ var InngestRun = class extends Run {
|
|
|
106
110
|
});
|
|
107
111
|
}
|
|
108
112
|
}
|
|
109
|
-
async start({
|
|
113
|
+
async start(params) {
|
|
114
|
+
return this._start(params);
|
|
115
|
+
}
|
|
116
|
+
async _start({
|
|
110
117
|
inputData,
|
|
111
|
-
initialState
|
|
118
|
+
initialState,
|
|
119
|
+
outputOptions,
|
|
120
|
+
tracingOptions,
|
|
121
|
+
format
|
|
112
122
|
}) {
|
|
113
123
|
await this.#mastra.getStorage()?.persistWorkflowSnapshot({
|
|
114
124
|
workflowName: this.workflowId,
|
|
@@ -121,6 +131,7 @@ var InngestRun = class extends Run {
|
|
|
121
131
|
context: {},
|
|
122
132
|
activePaths: [],
|
|
123
133
|
suspendedPaths: {},
|
|
134
|
+
resumeLabels: {},
|
|
124
135
|
waitingPaths: {},
|
|
125
136
|
timestamp: Date.now(),
|
|
126
137
|
status: "running"
|
|
@@ -134,7 +145,10 @@ var InngestRun = class extends Run {
|
|
|
134
145
|
inputData: inputDataToUse,
|
|
135
146
|
initialState: initialStateToUse,
|
|
136
147
|
runId: this.runId,
|
|
137
|
-
resourceId: this.resourceId
|
|
148
|
+
resourceId: this.resourceId,
|
|
149
|
+
outputOptions,
|
|
150
|
+
tracingOptions,
|
|
151
|
+
format
|
|
138
152
|
}
|
|
139
153
|
});
|
|
140
154
|
const eventId = eventOutput.ids[0];
|
|
@@ -163,10 +177,11 @@ var InngestRun = class extends Run {
|
|
|
163
177
|
return p;
|
|
164
178
|
}
|
|
165
179
|
async _resume(params) {
|
|
180
|
+
const storage = this.#mastra?.getStorage();
|
|
166
181
|
const steps = (Array.isArray(params.step) ? params.step : [params.step]).map(
|
|
167
182
|
(step) => typeof step === "string" ? step : step?.id
|
|
168
183
|
);
|
|
169
|
-
const snapshot = await
|
|
184
|
+
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
170
185
|
workflowName: this.workflowId,
|
|
171
186
|
runId: this.runId
|
|
172
187
|
});
|
|
@@ -200,12 +215,12 @@ var InngestRun = class extends Run {
|
|
|
200
215
|
}
|
|
201
216
|
return result;
|
|
202
217
|
}
|
|
203
|
-
watch(cb
|
|
218
|
+
watch(cb) {
|
|
204
219
|
let active = true;
|
|
205
220
|
const streamPromise = subscribe(
|
|
206
221
|
{
|
|
207
222
|
channel: `workflow:${this.workflowId}:${this.runId}`,
|
|
208
|
-
topics: [
|
|
223
|
+
topics: ["watch"],
|
|
209
224
|
app: this.inngest
|
|
210
225
|
},
|
|
211
226
|
(message) => {
|
|
@@ -223,20 +238,35 @@ var InngestRun = class extends Run {
|
|
|
223
238
|
});
|
|
224
239
|
};
|
|
225
240
|
}
|
|
226
|
-
|
|
241
|
+
streamLegacy({ inputData, requestContext } = {}) {
|
|
227
242
|
const { readable, writable } = new TransformStream();
|
|
228
243
|
const writer = writable.getWriter();
|
|
229
244
|
const unwatch = this.watch(async (event) => {
|
|
230
245
|
try {
|
|
246
|
+
await writer.write({
|
|
247
|
+
// @ts-ignore
|
|
248
|
+
type: "start",
|
|
249
|
+
// @ts-ignore
|
|
250
|
+
payload: { runId: this.runId }
|
|
251
|
+
});
|
|
231
252
|
const e = {
|
|
232
253
|
...event,
|
|
233
254
|
type: event.type.replace("workflow-", "")
|
|
234
255
|
};
|
|
256
|
+
if (e.type === "step-output") {
|
|
257
|
+
e.type = e.payload.output.type;
|
|
258
|
+
e.payload = e.payload.output.payload;
|
|
259
|
+
}
|
|
235
260
|
await writer.write(e);
|
|
236
261
|
} catch {
|
|
237
262
|
}
|
|
238
|
-
}
|
|
263
|
+
});
|
|
239
264
|
this.closeStreamAction = async () => {
|
|
265
|
+
await writer.write({
|
|
266
|
+
type: "finish",
|
|
267
|
+
// @ts-ignore
|
|
268
|
+
payload: { runId: this.runId }
|
|
269
|
+
});
|
|
240
270
|
unwatch();
|
|
241
271
|
try {
|
|
242
272
|
await writer.close();
|
|
@@ -246,7 +276,7 @@ var InngestRun = class extends Run {
|
|
|
246
276
|
writer.releaseLock();
|
|
247
277
|
}
|
|
248
278
|
};
|
|
249
|
-
this.executionResults = this.
|
|
279
|
+
this.executionResults = this._start({ inputData, requestContext, format: "legacy" }).then((result) => {
|
|
250
280
|
if (result.status !== "suspended") {
|
|
251
281
|
this.closeStreamAction?.().catch(() => {
|
|
252
282
|
});
|
|
@@ -258,6 +288,82 @@ var InngestRun = class extends Run {
|
|
|
258
288
|
getWorkflowState: () => this.executionResults
|
|
259
289
|
};
|
|
260
290
|
}
|
|
291
|
+
stream({
|
|
292
|
+
inputData,
|
|
293
|
+
requestContext,
|
|
294
|
+
tracingOptions,
|
|
295
|
+
closeOnSuspend = true,
|
|
296
|
+
initialState,
|
|
297
|
+
outputOptions
|
|
298
|
+
} = {}) {
|
|
299
|
+
if (this.closeStreamAction && this.streamOutput) {
|
|
300
|
+
return this.streamOutput;
|
|
301
|
+
}
|
|
302
|
+
this.closeStreamAction = async () => {
|
|
303
|
+
};
|
|
304
|
+
const self = this;
|
|
305
|
+
const stream = new ReadableStream({
|
|
306
|
+
async start(controller) {
|
|
307
|
+
const unwatch = self.watch(async ({ type, from = ChunkFrom.WORKFLOW, payload }) => {
|
|
308
|
+
controller.enqueue({
|
|
309
|
+
type,
|
|
310
|
+
runId: self.runId,
|
|
311
|
+
from,
|
|
312
|
+
payload: {
|
|
313
|
+
stepName: payload?.id,
|
|
314
|
+
...payload
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
self.closeStreamAction = async () => {
|
|
319
|
+
unwatch();
|
|
320
|
+
try {
|
|
321
|
+
await controller.close();
|
|
322
|
+
} catch (err) {
|
|
323
|
+
console.error("Error closing stream:", err);
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
const executionResultsPromise = self._start({
|
|
327
|
+
inputData,
|
|
328
|
+
requestContext,
|
|
329
|
+
// tracingContext, // We are not able to pass a reference to a span here, what to do?
|
|
330
|
+
initialState,
|
|
331
|
+
tracingOptions,
|
|
332
|
+
outputOptions,
|
|
333
|
+
format: "vnext"
|
|
334
|
+
});
|
|
335
|
+
let executionResults;
|
|
336
|
+
try {
|
|
337
|
+
executionResults = await executionResultsPromise;
|
|
338
|
+
if (closeOnSuspend) {
|
|
339
|
+
self.closeStreamAction?.().catch(() => {
|
|
340
|
+
});
|
|
341
|
+
} else if (executionResults.status !== "suspended") {
|
|
342
|
+
self.closeStreamAction?.().catch(() => {
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
if (self.streamOutput) {
|
|
346
|
+
self.streamOutput.updateResults(
|
|
347
|
+
executionResults
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
} catch (err) {
|
|
351
|
+
self.streamOutput?.rejectResults(err);
|
|
352
|
+
self.closeStreamAction?.().catch(() => {
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
this.streamOutput = new WorkflowRunOutput({
|
|
358
|
+
runId: this.runId,
|
|
359
|
+
workflowId: this.workflowId,
|
|
360
|
+
stream
|
|
361
|
+
});
|
|
362
|
+
return this.streamOutput;
|
|
363
|
+
}
|
|
364
|
+
streamVNext(args = {}) {
|
|
365
|
+
return this.stream(args);
|
|
366
|
+
}
|
|
261
367
|
};
|
|
262
368
|
var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
263
369
|
#mastra;
|
|
@@ -274,13 +380,13 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
274
380
|
this.#mastra = params.mastra;
|
|
275
381
|
this.inngest = inngest;
|
|
276
382
|
}
|
|
277
|
-
async
|
|
383
|
+
async listWorkflowRuns(args) {
|
|
278
384
|
const storage = this.#mastra?.getStorage();
|
|
279
385
|
if (!storage) {
|
|
280
386
|
this.logger.debug("Cannot get workflow runs. Mastra engine is not initialized");
|
|
281
387
|
return { runs: [], total: 0 };
|
|
282
388
|
}
|
|
283
|
-
return storage.
|
|
389
|
+
return storage.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
|
|
284
390
|
}
|
|
285
391
|
async getWorkflowRunById(runId) {
|
|
286
392
|
const storage = this.#mastra?.getStorage();
|
|
@@ -309,16 +415,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
309
415
|
}
|
|
310
416
|
}
|
|
311
417
|
}
|
|
312
|
-
|
|
313
|
-
* @deprecated Use createRunAsync() instead.
|
|
314
|
-
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
315
|
-
*/
|
|
316
|
-
createRun(_options) {
|
|
317
|
-
throw new Error(
|
|
318
|
-
"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."
|
|
319
|
-
);
|
|
320
|
-
}
|
|
321
|
-
async createRunAsync(options) {
|
|
418
|
+
async createRun(options) {
|
|
322
419
|
const runIdToUse = options?.runId || randomUUID();
|
|
323
420
|
const run = this.runs.get(runIdToUse) ?? new InngestRun(
|
|
324
421
|
{
|
|
@@ -355,6 +452,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
355
452
|
waitingPaths: {},
|
|
356
453
|
serializedStepGraph: this.serializedStepGraph,
|
|
357
454
|
suspendedPaths: {},
|
|
455
|
+
resumeLabels: {},
|
|
358
456
|
result: void 0,
|
|
359
457
|
error: void 0,
|
|
360
458
|
// @ts-ignore
|
|
@@ -379,7 +477,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
379
477
|
},
|
|
380
478
|
{ event: `workflow.${this.id}` },
|
|
381
479
|
async ({ event, step, attempt, publish }) => {
|
|
382
|
-
let { inputData, initialState, runId, resourceId, resume, outputOptions } = event.data;
|
|
480
|
+
let { inputData, initialState, runId, resourceId, resume, outputOptions, format } = event.data;
|
|
383
481
|
if (!runId) {
|
|
384
482
|
runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
|
|
385
483
|
return randomUUID();
|
|
@@ -418,13 +516,19 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
418
516
|
initialState,
|
|
419
517
|
emitter,
|
|
420
518
|
retryConfig: this.retryConfig,
|
|
421
|
-
|
|
519
|
+
requestContext: new RequestContext(),
|
|
422
520
|
// TODO
|
|
423
521
|
resume,
|
|
522
|
+
format,
|
|
424
523
|
abortController: new AbortController(),
|
|
425
|
-
currentSpan:
|
|
426
|
-
|
|
427
|
-
|
|
524
|
+
// currentSpan: undefined, // TODO: Pass actual parent Span from workflow execution context
|
|
525
|
+
outputOptions,
|
|
526
|
+
writableStream: new WritableStream({
|
|
527
|
+
write(chunk) {
|
|
528
|
+
void emitter.emit("watch", chunk).catch(() => {
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
})
|
|
428
532
|
});
|
|
429
533
|
await step.run(`workflow.${this.id}.finalize`, async () => {
|
|
430
534
|
if (result.status === "failed") {
|
|
@@ -462,7 +566,7 @@ function isAgent(params) {
|
|
|
462
566
|
function isTool(params) {
|
|
463
567
|
return params instanceof Tool;
|
|
464
568
|
}
|
|
465
|
-
function createStep(params) {
|
|
569
|
+
function createStep(params, agentOptions) {
|
|
466
570
|
if (isAgent(params)) {
|
|
467
571
|
return {
|
|
468
572
|
id: params.name,
|
|
@@ -470,12 +574,23 @@ function createStep(params) {
|
|
|
470
574
|
// @ts-ignore
|
|
471
575
|
inputSchema: z.object({
|
|
472
576
|
prompt: z.string()
|
|
577
|
+
// resourceId: z.string().optional(),
|
|
578
|
+
// threadId: z.string().optional(),
|
|
473
579
|
}),
|
|
474
580
|
// @ts-ignore
|
|
475
581
|
outputSchema: z.object({
|
|
476
582
|
text: z.string()
|
|
477
583
|
}),
|
|
478
|
-
execute: async ({
|
|
584
|
+
execute: async ({
|
|
585
|
+
inputData,
|
|
586
|
+
[EMITTER_SYMBOL]: emitter,
|
|
587
|
+
[STREAM_FORMAT_SYMBOL]: streamFormat,
|
|
588
|
+
requestContext,
|
|
589
|
+
tracingContext,
|
|
590
|
+
abortSignal,
|
|
591
|
+
abort,
|
|
592
|
+
writer
|
|
593
|
+
}) => {
|
|
479
594
|
let streamPromise = {};
|
|
480
595
|
streamPromise.promise = new Promise((resolve, reject) => {
|
|
481
596
|
streamPromise.resolve = resolve;
|
|
@@ -485,61 +600,60 @@ function createStep(params) {
|
|
|
485
600
|
name: params.name,
|
|
486
601
|
args: inputData
|
|
487
602
|
};
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
603
|
+
let stream;
|
|
604
|
+
if ((await params.getModel()).specificationVersion === "v1") {
|
|
605
|
+
const { fullStream } = await params.streamLegacy(inputData.prompt, {
|
|
606
|
+
...agentOptions ?? {},
|
|
607
|
+
// resourceId: inputData.resourceId,
|
|
608
|
+
// threadId: inputData.threadId,
|
|
609
|
+
requestContext,
|
|
491
610
|
tracingContext,
|
|
492
611
|
onFinish: (result) => {
|
|
493
612
|
streamPromise.resolve(result.text);
|
|
613
|
+
void agentOptions?.onFinish?.(result);
|
|
494
614
|
},
|
|
495
615
|
abortSignal
|
|
496
616
|
});
|
|
497
|
-
|
|
498
|
-
return abort();
|
|
499
|
-
}
|
|
500
|
-
await emitter.emit("watch-v2", {
|
|
501
|
-
type: "tool-call-streaming-start",
|
|
502
|
-
...toolData ?? {}
|
|
503
|
-
});
|
|
504
|
-
for await (const chunk of fullStream) {
|
|
505
|
-
if (chunk.type === "text-delta") {
|
|
506
|
-
await emitter.emit("watch-v2", {
|
|
507
|
-
type: "tool-call-delta",
|
|
508
|
-
...toolData ?? {},
|
|
509
|
-
argsTextDelta: chunk.payload.text
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
}
|
|
617
|
+
stream = fullStream;
|
|
513
618
|
} else {
|
|
514
|
-
const
|
|
515
|
-
|
|
619
|
+
const modelOutput = await params.stream(inputData.prompt, {
|
|
620
|
+
...agentOptions ?? {},
|
|
621
|
+
requestContext,
|
|
516
622
|
tracingContext,
|
|
517
623
|
onFinish: (result) => {
|
|
518
624
|
streamPromise.resolve(result.text);
|
|
625
|
+
void agentOptions?.onFinish?.(result);
|
|
519
626
|
},
|
|
520
627
|
abortSignal
|
|
521
628
|
});
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
await emitter.emit("watch
|
|
629
|
+
stream = modelOutput.fullStream;
|
|
630
|
+
}
|
|
631
|
+
if (streamFormat === "legacy") {
|
|
632
|
+
await emitter.emit("watch", {
|
|
526
633
|
type: "tool-call-streaming-start",
|
|
527
634
|
...toolData ?? {}
|
|
528
635
|
});
|
|
529
|
-
for await (const chunk of
|
|
636
|
+
for await (const chunk of stream) {
|
|
530
637
|
if (chunk.type === "text-delta") {
|
|
531
|
-
await emitter.emit("watch
|
|
638
|
+
await emitter.emit("watch", {
|
|
532
639
|
type: "tool-call-delta",
|
|
533
640
|
...toolData ?? {},
|
|
534
641
|
argsTextDelta: chunk.textDelta
|
|
535
642
|
});
|
|
536
643
|
}
|
|
537
644
|
}
|
|
645
|
+
await emitter.emit("watch", {
|
|
646
|
+
type: "tool-call-streaming-finish",
|
|
647
|
+
...toolData ?? {}
|
|
648
|
+
});
|
|
649
|
+
} else {
|
|
650
|
+
for await (const chunk of stream) {
|
|
651
|
+
await writer.write(chunk);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
if (abortSignal.aborted) {
|
|
655
|
+
return abort();
|
|
538
656
|
}
|
|
539
|
-
await emitter.emit("watch-v2", {
|
|
540
|
-
type: "tool-call-streaming-finish",
|
|
541
|
-
...toolData ?? {}
|
|
542
|
-
});
|
|
543
657
|
return {
|
|
544
658
|
text: await streamPromise.promise
|
|
545
659
|
};
|
|
@@ -558,11 +672,11 @@ function createStep(params) {
|
|
|
558
672
|
description: params.description,
|
|
559
673
|
inputSchema: params.inputSchema,
|
|
560
674
|
outputSchema: params.outputSchema,
|
|
561
|
-
execute: async ({ inputData, mastra,
|
|
675
|
+
execute: async ({ inputData, mastra, requestContext, tracingContext, suspend, resumeData }) => {
|
|
562
676
|
return params.execute({
|
|
563
677
|
context: inputData,
|
|
564
678
|
mastra: wrapMastra(mastra, tracingContext),
|
|
565
|
-
|
|
679
|
+
requestContext,
|
|
566
680
|
tracingContext,
|
|
567
681
|
suspend,
|
|
568
682
|
resumeData
|
|
@@ -625,63 +739,16 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
625
739
|
this.inngestStep = inngestStep;
|
|
626
740
|
this.inngestAttempts = inngestAttempts;
|
|
627
741
|
}
|
|
628
|
-
async
|
|
629
|
-
await params.emitter.emit("watch-v2", {
|
|
630
|
-
type: "workflow-start",
|
|
631
|
-
payload: { runId: params.runId }
|
|
632
|
-
});
|
|
633
|
-
const result = await super.execute(params);
|
|
634
|
-
await params.emitter.emit("watch-v2", {
|
|
635
|
-
type: "workflow-finish",
|
|
636
|
-
payload: { runId: params.runId }
|
|
637
|
-
});
|
|
638
|
-
return result;
|
|
639
|
-
}
|
|
640
|
-
async fmtReturnValue(executionSpan, emitter, stepResults, lastOutput, error) {
|
|
742
|
+
async fmtReturnValue(emitter, stepResults, lastOutput, error) {
|
|
641
743
|
const base = {
|
|
642
744
|
status: lastOutput.status,
|
|
643
745
|
steps: stepResults
|
|
644
746
|
};
|
|
645
747
|
if (lastOutput.status === "success") {
|
|
646
|
-
await emitter.emit("watch", {
|
|
647
|
-
type: "watch",
|
|
648
|
-
payload: {
|
|
649
|
-
workflowState: {
|
|
650
|
-
status: lastOutput.status,
|
|
651
|
-
steps: stepResults,
|
|
652
|
-
result: lastOutput.output
|
|
653
|
-
}
|
|
654
|
-
},
|
|
655
|
-
eventTimestamp: Date.now()
|
|
656
|
-
});
|
|
657
748
|
base.result = lastOutput.output;
|
|
658
749
|
} else if (lastOutput.status === "failed") {
|
|
659
750
|
base.error = error instanceof Error ? error?.stack ?? error.message : lastOutput?.error instanceof Error ? lastOutput.error.message : lastOutput.error ?? error ?? "Unknown error";
|
|
660
|
-
await emitter.emit("watch", {
|
|
661
|
-
type: "watch",
|
|
662
|
-
payload: {
|
|
663
|
-
workflowState: {
|
|
664
|
-
status: lastOutput.status,
|
|
665
|
-
steps: stepResults,
|
|
666
|
-
result: null,
|
|
667
|
-
error: base.error
|
|
668
|
-
}
|
|
669
|
-
},
|
|
670
|
-
eventTimestamp: Date.now()
|
|
671
|
-
});
|
|
672
751
|
} else if (lastOutput.status === "suspended") {
|
|
673
|
-
await emitter.emit("watch", {
|
|
674
|
-
type: "watch",
|
|
675
|
-
payload: {
|
|
676
|
-
workflowState: {
|
|
677
|
-
status: lastOutput.status,
|
|
678
|
-
steps: stepResults,
|
|
679
|
-
result: null,
|
|
680
|
-
error: null
|
|
681
|
-
}
|
|
682
|
-
},
|
|
683
|
-
eventTimestamp: Date.now()
|
|
684
|
-
});
|
|
685
752
|
const suspendedStepIds = Object.entries(stepResults).flatMap(([stepId, stepResult]) => {
|
|
686
753
|
if (stepResult?.status === "suspended") {
|
|
687
754
|
const nestedPath = stepResult?.suspendPayload?.__workflow_meta?.path;
|
|
@@ -691,7 +758,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
691
758
|
});
|
|
692
759
|
base.suspended = suspendedStepIds;
|
|
693
760
|
}
|
|
694
|
-
executionSpan?.end();
|
|
695
761
|
return base;
|
|
696
762
|
}
|
|
697
763
|
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
@@ -705,14 +771,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
705
771
|
stepResults,
|
|
706
772
|
emitter,
|
|
707
773
|
abortController,
|
|
708
|
-
|
|
774
|
+
requestContext,
|
|
709
775
|
executionContext,
|
|
710
776
|
writableStream,
|
|
711
777
|
tracingContext
|
|
712
778
|
}) {
|
|
713
779
|
let { duration, fn } = entry;
|
|
714
780
|
const sleepSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
715
|
-
type:
|
|
781
|
+
type: SpanType.WORKFLOW_SLEEP,
|
|
716
782
|
name: `sleep: ${duration ? `${duration}ms` : "dynamic"}`,
|
|
717
783
|
attributes: {
|
|
718
784
|
durationMs: duration,
|
|
@@ -723,45 +789,53 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
723
789
|
if (fn) {
|
|
724
790
|
const stepCallId = randomUUID();
|
|
725
791
|
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
726
|
-
return await fn(
|
|
727
|
-
|
|
728
|
-
workflowId,
|
|
729
|
-
mastra: this.mastra,
|
|
730
|
-
runtimeContext,
|
|
731
|
-
inputData: prevOutput,
|
|
732
|
-
state: executionContext.state,
|
|
733
|
-
setState: (state) => {
|
|
734
|
-
executionContext.state = state;
|
|
735
|
-
},
|
|
736
|
-
runCount: -1,
|
|
737
|
-
tracingContext: {
|
|
738
|
-
currentSpan: sleepSpan
|
|
739
|
-
},
|
|
740
|
-
getInitData: () => stepResults?.input,
|
|
741
|
-
getStepResult: getStepResult.bind(this, stepResults),
|
|
742
|
-
// TODO: this function shouldn't have suspend probably?
|
|
743
|
-
suspend: async (_suspendPayload) => {
|
|
744
|
-
},
|
|
745
|
-
bail: () => {
|
|
746
|
-
},
|
|
747
|
-
abort: () => {
|
|
748
|
-
abortController?.abort();
|
|
749
|
-
},
|
|
750
|
-
[EMITTER_SYMBOL]: emitter,
|
|
751
|
-
// TODO: add streamVNext support
|
|
752
|
-
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
753
|
-
engine: { step: this.inngestStep },
|
|
754
|
-
abortSignal: abortController?.signal,
|
|
755
|
-
writer: new ToolStream(
|
|
792
|
+
return await fn(
|
|
793
|
+
createDeprecationProxy(
|
|
756
794
|
{
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
795
|
+
runId,
|
|
796
|
+
workflowId,
|
|
797
|
+
mastra: this.mastra,
|
|
798
|
+
requestContext,
|
|
799
|
+
inputData: prevOutput,
|
|
800
|
+
state: executionContext.state,
|
|
801
|
+
setState: (state) => {
|
|
802
|
+
executionContext.state = state;
|
|
803
|
+
},
|
|
804
|
+
retryCount: -1,
|
|
805
|
+
tracingContext: {
|
|
806
|
+
currentSpan: sleepSpan
|
|
807
|
+
},
|
|
808
|
+
getInitData: () => stepResults?.input,
|
|
809
|
+
getStepResult: getStepResult.bind(this, stepResults),
|
|
810
|
+
// TODO: this function shouldn't have suspend probably?
|
|
811
|
+
suspend: async (_suspendPayload) => {
|
|
812
|
+
},
|
|
813
|
+
bail: () => {
|
|
814
|
+
},
|
|
815
|
+
abort: () => {
|
|
816
|
+
abortController?.abort();
|
|
817
|
+
},
|
|
818
|
+
[EMITTER_SYMBOL]: emitter,
|
|
819
|
+
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
820
|
+
engine: { step: this.inngestStep },
|
|
821
|
+
abortSignal: abortController?.signal,
|
|
822
|
+
writer: new ToolStream(
|
|
823
|
+
{
|
|
824
|
+
prefix: "workflow-step",
|
|
825
|
+
callId: stepCallId,
|
|
826
|
+
name: "sleep",
|
|
827
|
+
runId
|
|
828
|
+
},
|
|
829
|
+
writableStream
|
|
830
|
+
)
|
|
761
831
|
},
|
|
762
|
-
|
|
832
|
+
{
|
|
833
|
+
paramName: "runCount",
|
|
834
|
+
deprecationMessage: runCountDeprecationMessage,
|
|
835
|
+
logger: this.logger
|
|
836
|
+
}
|
|
763
837
|
)
|
|
764
|
-
|
|
838
|
+
);
|
|
765
839
|
});
|
|
766
840
|
sleepSpan?.update({
|
|
767
841
|
attributes: {
|
|
@@ -785,14 +859,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
785
859
|
stepResults,
|
|
786
860
|
emitter,
|
|
787
861
|
abortController,
|
|
788
|
-
|
|
862
|
+
requestContext,
|
|
789
863
|
executionContext,
|
|
790
864
|
writableStream,
|
|
791
865
|
tracingContext
|
|
792
866
|
}) {
|
|
793
867
|
let { date, fn } = entry;
|
|
794
868
|
const sleepUntilSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
795
|
-
type:
|
|
869
|
+
type: SpanType.WORKFLOW_SLEEP,
|
|
796
870
|
name: `sleepUntil: ${date ? date.toISOString() : "dynamic"}`,
|
|
797
871
|
attributes: {
|
|
798
872
|
untilDate: date,
|
|
@@ -804,45 +878,53 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
804
878
|
if (fn) {
|
|
805
879
|
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
806
880
|
const stepCallId = randomUUID();
|
|
807
|
-
return await fn(
|
|
808
|
-
|
|
809
|
-
workflowId,
|
|
810
|
-
mastra: this.mastra,
|
|
811
|
-
runtimeContext,
|
|
812
|
-
inputData: prevOutput,
|
|
813
|
-
state: executionContext.state,
|
|
814
|
-
setState: (state) => {
|
|
815
|
-
executionContext.state = state;
|
|
816
|
-
},
|
|
817
|
-
runCount: -1,
|
|
818
|
-
tracingContext: {
|
|
819
|
-
currentSpan: sleepUntilSpan
|
|
820
|
-
},
|
|
821
|
-
getInitData: () => stepResults?.input,
|
|
822
|
-
getStepResult: getStepResult.bind(this, stepResults),
|
|
823
|
-
// TODO: this function shouldn't have suspend probably?
|
|
824
|
-
suspend: async (_suspendPayload) => {
|
|
825
|
-
},
|
|
826
|
-
bail: () => {
|
|
827
|
-
},
|
|
828
|
-
abort: () => {
|
|
829
|
-
abortController?.abort();
|
|
830
|
-
},
|
|
831
|
-
[EMITTER_SYMBOL]: emitter,
|
|
832
|
-
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
833
|
-
// TODO: add streamVNext support
|
|
834
|
-
engine: { step: this.inngestStep },
|
|
835
|
-
abortSignal: abortController?.signal,
|
|
836
|
-
writer: new ToolStream(
|
|
881
|
+
return await fn(
|
|
882
|
+
createDeprecationProxy(
|
|
837
883
|
{
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
884
|
+
runId,
|
|
885
|
+
workflowId,
|
|
886
|
+
mastra: this.mastra,
|
|
887
|
+
requestContext,
|
|
888
|
+
inputData: prevOutput,
|
|
889
|
+
state: executionContext.state,
|
|
890
|
+
setState: (state) => {
|
|
891
|
+
executionContext.state = state;
|
|
892
|
+
},
|
|
893
|
+
retryCount: -1,
|
|
894
|
+
tracingContext: {
|
|
895
|
+
currentSpan: sleepUntilSpan
|
|
896
|
+
},
|
|
897
|
+
getInitData: () => stepResults?.input,
|
|
898
|
+
getStepResult: getStepResult.bind(this, stepResults),
|
|
899
|
+
// TODO: this function shouldn't have suspend probably?
|
|
900
|
+
suspend: async (_suspendPayload) => {
|
|
901
|
+
},
|
|
902
|
+
bail: () => {
|
|
903
|
+
},
|
|
904
|
+
abort: () => {
|
|
905
|
+
abortController?.abort();
|
|
906
|
+
},
|
|
907
|
+
[EMITTER_SYMBOL]: emitter,
|
|
908
|
+
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
909
|
+
engine: { step: this.inngestStep },
|
|
910
|
+
abortSignal: abortController?.signal,
|
|
911
|
+
writer: new ToolStream(
|
|
912
|
+
{
|
|
913
|
+
prefix: "workflow-step",
|
|
914
|
+
callId: stepCallId,
|
|
915
|
+
name: "sleep",
|
|
916
|
+
runId
|
|
917
|
+
},
|
|
918
|
+
writableStream
|
|
919
|
+
)
|
|
842
920
|
},
|
|
843
|
-
|
|
921
|
+
{
|
|
922
|
+
paramName: "runCount",
|
|
923
|
+
deprecationMessage: runCountDeprecationMessage,
|
|
924
|
+
logger: this.logger
|
|
925
|
+
}
|
|
844
926
|
)
|
|
845
|
-
|
|
927
|
+
);
|
|
846
928
|
});
|
|
847
929
|
if (date && !(date instanceof Date)) {
|
|
848
930
|
date = new Date(date);
|
|
@@ -884,14 +966,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
884
966
|
prevOutput,
|
|
885
967
|
emitter,
|
|
886
968
|
abortController,
|
|
887
|
-
|
|
969
|
+
requestContext,
|
|
888
970
|
tracingContext,
|
|
889
971
|
writableStream,
|
|
890
972
|
disableScorers
|
|
891
973
|
}) {
|
|
892
|
-
const
|
|
974
|
+
const stepSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
893
975
|
name: `workflow step: '${step.id}'`,
|
|
894
|
-
type:
|
|
976
|
+
type: SpanType.WORKFLOW_STEP,
|
|
895
977
|
input: prevOutput,
|
|
896
978
|
attributes: {
|
|
897
979
|
stepId: step.id
|
|
@@ -908,27 +990,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
908
990
|
async () => {
|
|
909
991
|
const startedAt2 = Date.now();
|
|
910
992
|
await emitter.emit("watch", {
|
|
911
|
-
type: "watch",
|
|
912
|
-
payload: {
|
|
913
|
-
currentStep: {
|
|
914
|
-
id: step.id,
|
|
915
|
-
status: "running"
|
|
916
|
-
},
|
|
917
|
-
workflowState: {
|
|
918
|
-
status: "running",
|
|
919
|
-
steps: {
|
|
920
|
-
...stepResults,
|
|
921
|
-
[step.id]: {
|
|
922
|
-
status: "running"
|
|
923
|
-
}
|
|
924
|
-
},
|
|
925
|
-
result: null,
|
|
926
|
-
error: null
|
|
927
|
-
}
|
|
928
|
-
},
|
|
929
|
-
eventTimestamp: Date.now()
|
|
930
|
-
});
|
|
931
|
-
await emitter.emit("watch-v2", {
|
|
932
993
|
type: "workflow-step-start",
|
|
933
994
|
payload: {
|
|
934
995
|
id: step.id,
|
|
@@ -1004,23 +1065,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1004
1065
|
async () => {
|
|
1005
1066
|
if (result.status === "failed") {
|
|
1006
1067
|
await emitter.emit("watch", {
|
|
1007
|
-
type: "watch",
|
|
1008
|
-
payload: {
|
|
1009
|
-
currentStep: {
|
|
1010
|
-
id: step.id,
|
|
1011
|
-
status: "failed",
|
|
1012
|
-
error: result?.error
|
|
1013
|
-
},
|
|
1014
|
-
workflowState: {
|
|
1015
|
-
status: "running",
|
|
1016
|
-
steps: stepResults,
|
|
1017
|
-
result: null,
|
|
1018
|
-
error: null
|
|
1019
|
-
}
|
|
1020
|
-
},
|
|
1021
|
-
eventTimestamp: Date.now()
|
|
1022
|
-
});
|
|
1023
|
-
await emitter.emit("watch-v2", {
|
|
1024
1068
|
type: "workflow-step-result",
|
|
1025
1069
|
payload: {
|
|
1026
1070
|
id: step.id,
|
|
@@ -1039,27 +1083,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1039
1083
|
const suspendPath = [stepName, ...stepResult?.suspendPayload?.__workflow_meta?.path ?? []];
|
|
1040
1084
|
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
1041
1085
|
await emitter.emit("watch", {
|
|
1042
|
-
type: "watch",
|
|
1043
|
-
payload: {
|
|
1044
|
-
currentStep: {
|
|
1045
|
-
id: step.id,
|
|
1046
|
-
status: "suspended",
|
|
1047
|
-
payload: stepResult.payload,
|
|
1048
|
-
suspendPayload: {
|
|
1049
|
-
...stepResult?.suspendPayload,
|
|
1050
|
-
__workflow_meta: { runId, path: suspendPath }
|
|
1051
|
-
}
|
|
1052
|
-
},
|
|
1053
|
-
workflowState: {
|
|
1054
|
-
status: "running",
|
|
1055
|
-
steps: stepResults,
|
|
1056
|
-
result: null,
|
|
1057
|
-
error: null
|
|
1058
|
-
}
|
|
1059
|
-
},
|
|
1060
|
-
eventTimestamp: Date.now()
|
|
1061
|
-
});
|
|
1062
|
-
await emitter.emit("watch-v2", {
|
|
1063
1086
|
type: "workflow-step-suspended",
|
|
1064
1087
|
payload: {
|
|
1065
1088
|
id: step.id,
|
|
@@ -1078,23 +1101,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1078
1101
|
}
|
|
1079
1102
|
};
|
|
1080
1103
|
}
|
|
1081
|
-
await emitter.emit("watch", {
|
|
1082
|
-
type: "watch",
|
|
1083
|
-
payload: {
|
|
1084
|
-
currentStep: {
|
|
1085
|
-
id: step.id,
|
|
1086
|
-
status: "suspended",
|
|
1087
|
-
payload: {}
|
|
1088
|
-
},
|
|
1089
|
-
workflowState: {
|
|
1090
|
-
status: "running",
|
|
1091
|
-
steps: stepResults,
|
|
1092
|
-
result: null,
|
|
1093
|
-
error: null
|
|
1094
|
-
}
|
|
1095
|
-
},
|
|
1096
|
-
eventTimestamp: Date.now()
|
|
1097
|
-
});
|
|
1098
1104
|
return {
|
|
1099
1105
|
executionContext,
|
|
1100
1106
|
result: {
|
|
@@ -1104,23 +1110,6 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1104
1110
|
};
|
|
1105
1111
|
}
|
|
1106
1112
|
await emitter.emit("watch", {
|
|
1107
|
-
type: "watch",
|
|
1108
|
-
payload: {
|
|
1109
|
-
currentStep: {
|
|
1110
|
-
id: step.id,
|
|
1111
|
-
status: "success",
|
|
1112
|
-
output: result?.result
|
|
1113
|
-
},
|
|
1114
|
-
workflowState: {
|
|
1115
|
-
status: "running",
|
|
1116
|
-
steps: stepResults,
|
|
1117
|
-
result: null,
|
|
1118
|
-
error: null
|
|
1119
|
-
}
|
|
1120
|
-
},
|
|
1121
|
-
eventTimestamp: Date.now()
|
|
1122
|
-
});
|
|
1123
|
-
await emitter.emit("watch-v2", {
|
|
1124
1113
|
type: "workflow-step-result",
|
|
1125
1114
|
payload: {
|
|
1126
1115
|
id: step.id,
|
|
@@ -1128,7 +1117,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1128
1117
|
output: result?.result
|
|
1129
1118
|
}
|
|
1130
1119
|
});
|
|
1131
|
-
await emitter.emit("watch
|
|
1120
|
+
await emitter.emit("watch", {
|
|
1132
1121
|
type: "workflow-step-finish",
|
|
1133
1122
|
payload: {
|
|
1134
1123
|
id: step.id,
|
|
@@ -1148,6 +1137,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1148
1137
|
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1149
1138
|
};
|
|
1150
1139
|
}
|
|
1140
|
+
const stepCallId = randomUUID();
|
|
1151
1141
|
let stepRes;
|
|
1152
1142
|
try {
|
|
1153
1143
|
stepRes = await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}`, async () => {
|
|
@@ -1161,8 +1151,16 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1161
1151
|
const result = await step.execute({
|
|
1162
1152
|
runId: executionContext.runId,
|
|
1163
1153
|
mastra: this.mastra,
|
|
1164
|
-
|
|
1165
|
-
|
|
1154
|
+
requestContext,
|
|
1155
|
+
writer: new ToolStream(
|
|
1156
|
+
{
|
|
1157
|
+
prefix: "workflow-step",
|
|
1158
|
+
callId: stepCallId,
|
|
1159
|
+
name: step.id,
|
|
1160
|
+
runId: executionContext.runId
|
|
1161
|
+
},
|
|
1162
|
+
writableStream
|
|
1163
|
+
),
|
|
1166
1164
|
state: executionContext?.state ?? {},
|
|
1167
1165
|
setState: (state) => {
|
|
1168
1166
|
executionContext.state = state;
|
|
@@ -1170,12 +1168,21 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1170
1168
|
inputData,
|
|
1171
1169
|
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1172
1170
|
tracingContext: {
|
|
1173
|
-
currentSpan:
|
|
1171
|
+
currentSpan: stepSpan
|
|
1174
1172
|
},
|
|
1175
1173
|
getInitData: () => stepResults?.input,
|
|
1176
1174
|
getStepResult: getStepResult.bind(this, stepResults),
|
|
1177
|
-
suspend: async (suspendPayload) => {
|
|
1175
|
+
suspend: async (suspendPayload, suspendOptions) => {
|
|
1178
1176
|
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
1177
|
+
if (suspendOptions?.resumeLabel) {
|
|
1178
|
+
const resumeLabel = Array.isArray(suspendOptions.resumeLabel) ? suspendOptions.resumeLabel : [suspendOptions.resumeLabel];
|
|
1179
|
+
for (const label of resumeLabel) {
|
|
1180
|
+
executionContext.resumeLabels[label] = {
|
|
1181
|
+
stepId: step.id,
|
|
1182
|
+
foreachIndex: executionContext.foreachIndex
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1179
1186
|
suspended = { payload: suspendPayload };
|
|
1180
1187
|
},
|
|
1181
1188
|
bail: (result2) => {
|
|
@@ -1188,6 +1195,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1188
1195
|
runId: stepResults[step.id]?.suspendPayload?.__workflow_meta?.runId
|
|
1189
1196
|
},
|
|
1190
1197
|
[EMITTER_SYMBOL]: emitter,
|
|
1198
|
+
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1191
1199
|
engine: {
|
|
1192
1200
|
step: this.inngestStep
|
|
1193
1201
|
},
|
|
@@ -1215,7 +1223,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1215
1223
|
};
|
|
1216
1224
|
execResults = stepFailure;
|
|
1217
1225
|
const fallbackErrorMessage = `Step ${step.id} failed`;
|
|
1218
|
-
|
|
1226
|
+
stepSpan?.error({ error: new Error(execResults.error ?? fallbackErrorMessage) });
|
|
1219
1227
|
throw new RetryAfterError(execResults.error ?? fallbackErrorMessage, executionContext.retryConfig.delay, {
|
|
1220
1228
|
cause: execResults
|
|
1221
1229
|
});
|
|
@@ -1239,24 +1247,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1239
1247
|
startedAt
|
|
1240
1248
|
};
|
|
1241
1249
|
}
|
|
1242
|
-
await emitter.emit("watch", {
|
|
1243
|
-
type: "watch",
|
|
1244
|
-
payload: {
|
|
1245
|
-
currentStep: {
|
|
1246
|
-
id: step.id,
|
|
1247
|
-
...execResults
|
|
1248
|
-
},
|
|
1249
|
-
workflowState: {
|
|
1250
|
-
status: "running",
|
|
1251
|
-
steps: { ...stepResults, [step.id]: execResults },
|
|
1252
|
-
result: null,
|
|
1253
|
-
error: null
|
|
1254
|
-
}
|
|
1255
|
-
},
|
|
1256
|
-
eventTimestamp: Date.now()
|
|
1257
|
-
});
|
|
1258
1250
|
if (execResults.status === "suspended") {
|
|
1259
|
-
await emitter.emit("watch
|
|
1251
|
+
await emitter.emit("watch", {
|
|
1260
1252
|
type: "workflow-step-suspended",
|
|
1261
1253
|
payload: {
|
|
1262
1254
|
id: step.id,
|
|
@@ -1264,14 +1256,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1264
1256
|
}
|
|
1265
1257
|
});
|
|
1266
1258
|
} else {
|
|
1267
|
-
await emitter.emit("watch
|
|
1259
|
+
await emitter.emit("watch", {
|
|
1268
1260
|
type: "workflow-step-result",
|
|
1269
1261
|
payload: {
|
|
1270
1262
|
id: step.id,
|
|
1271
1263
|
...execResults
|
|
1272
1264
|
}
|
|
1273
1265
|
});
|
|
1274
|
-
await emitter.emit("watch
|
|
1266
|
+
await emitter.emit("watch", {
|
|
1275
1267
|
type: "workflow-step-finish",
|
|
1276
1268
|
payload: {
|
|
1277
1269
|
id: step.id,
|
|
@@ -1279,7 +1271,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1279
1271
|
}
|
|
1280
1272
|
});
|
|
1281
1273
|
}
|
|
1282
|
-
|
|
1274
|
+
stepSpan?.end({ output: execResults });
|
|
1283
1275
|
return { result: execResults, executionContext, stepResults };
|
|
1284
1276
|
});
|
|
1285
1277
|
} catch (e) {
|
|
@@ -1309,9 +1301,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1309
1301
|
output: stepRes.result,
|
|
1310
1302
|
workflowId: executionContext.workflowId,
|
|
1311
1303
|
stepId: step.id,
|
|
1312
|
-
|
|
1304
|
+
requestContext,
|
|
1313
1305
|
disableScorers,
|
|
1314
|
-
tracingContext: { currentSpan:
|
|
1306
|
+
tracingContext: { currentSpan: stepSpan }
|
|
1315
1307
|
});
|
|
1316
1308
|
}
|
|
1317
1309
|
});
|
|
@@ -1349,6 +1341,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1349
1341
|
context: stepResults,
|
|
1350
1342
|
activePaths: [],
|
|
1351
1343
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1344
|
+
resumeLabels: executionContext.resumeLabels,
|
|
1352
1345
|
waitingPaths: {},
|
|
1353
1346
|
serializedStepGraph,
|
|
1354
1347
|
status: workflowStatus,
|
|
@@ -1366,20 +1359,18 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1366
1359
|
runId,
|
|
1367
1360
|
entry,
|
|
1368
1361
|
prevOutput,
|
|
1369
|
-
prevStep,
|
|
1370
1362
|
stepResults,
|
|
1371
|
-
serializedStepGraph,
|
|
1372
1363
|
resume,
|
|
1373
1364
|
executionContext,
|
|
1374
1365
|
emitter,
|
|
1375
1366
|
abortController,
|
|
1376
|
-
|
|
1367
|
+
requestContext,
|
|
1377
1368
|
writableStream,
|
|
1378
1369
|
disableScorers,
|
|
1379
1370
|
tracingContext
|
|
1380
1371
|
}) {
|
|
1381
1372
|
const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
1382
|
-
type:
|
|
1373
|
+
type: SpanType.WORKFLOW_CONDITIONAL,
|
|
1383
1374
|
name: `conditional: '${entry.conditions.length} conditions'`,
|
|
1384
1375
|
input: prevOutput,
|
|
1385
1376
|
attributes: {
|
|
@@ -1392,7 +1383,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1392
1383
|
entry.conditions.map(
|
|
1393
1384
|
(cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
|
|
1394
1385
|
const evalSpan = conditionalSpan?.createChildSpan({
|
|
1395
|
-
type:
|
|
1386
|
+
type: SpanType.WORKFLOW_CONDITIONAL_EVAL,
|
|
1396
1387
|
name: `condition: '${index}'`,
|
|
1397
1388
|
input: prevOutput,
|
|
1398
1389
|
attributes: {
|
|
@@ -1401,47 +1392,55 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1401
1392
|
tracingPolicy: this.options?.tracingPolicy
|
|
1402
1393
|
});
|
|
1403
1394
|
try {
|
|
1404
|
-
const result = await cond(
|
|
1405
|
-
|
|
1406
|
-
workflowId,
|
|
1407
|
-
mastra: this.mastra,
|
|
1408
|
-
runtimeContext,
|
|
1409
|
-
runCount: -1,
|
|
1410
|
-
inputData: prevOutput,
|
|
1411
|
-
state: executionContext.state,
|
|
1412
|
-
setState: (state) => {
|
|
1413
|
-
executionContext.state = state;
|
|
1414
|
-
},
|
|
1415
|
-
tracingContext: {
|
|
1416
|
-
currentSpan: evalSpan
|
|
1417
|
-
},
|
|
1418
|
-
getInitData: () => stepResults?.input,
|
|
1419
|
-
getStepResult: getStepResult.bind(this, stepResults),
|
|
1420
|
-
// TODO: this function shouldn't have suspend probably?
|
|
1421
|
-
suspend: async (_suspendPayload) => {
|
|
1422
|
-
},
|
|
1423
|
-
bail: () => {
|
|
1424
|
-
},
|
|
1425
|
-
abort: () => {
|
|
1426
|
-
abortController.abort();
|
|
1427
|
-
},
|
|
1428
|
-
[EMITTER_SYMBOL]: emitter,
|
|
1429
|
-
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1430
|
-
// TODO: add streamVNext support
|
|
1431
|
-
engine: {
|
|
1432
|
-
step: this.inngestStep
|
|
1433
|
-
},
|
|
1434
|
-
abortSignal: abortController.signal,
|
|
1435
|
-
writer: new ToolStream(
|
|
1395
|
+
const result = await cond(
|
|
1396
|
+
createDeprecationProxy(
|
|
1436
1397
|
{
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1398
|
+
runId,
|
|
1399
|
+
workflowId,
|
|
1400
|
+
mastra: this.mastra,
|
|
1401
|
+
requestContext,
|
|
1402
|
+
retryCount: -1,
|
|
1403
|
+
inputData: prevOutput,
|
|
1404
|
+
state: executionContext.state,
|
|
1405
|
+
setState: (state) => {
|
|
1406
|
+
executionContext.state = state;
|
|
1407
|
+
},
|
|
1408
|
+
tracingContext: {
|
|
1409
|
+
currentSpan: evalSpan
|
|
1410
|
+
},
|
|
1411
|
+
getInitData: () => stepResults?.input,
|
|
1412
|
+
getStepResult: getStepResult.bind(this, stepResults),
|
|
1413
|
+
// TODO: this function shouldn't have suspend probably?
|
|
1414
|
+
suspend: async (_suspendPayload) => {
|
|
1415
|
+
},
|
|
1416
|
+
bail: () => {
|
|
1417
|
+
},
|
|
1418
|
+
abort: () => {
|
|
1419
|
+
abortController.abort();
|
|
1420
|
+
},
|
|
1421
|
+
[EMITTER_SYMBOL]: emitter,
|
|
1422
|
+
[STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1423
|
+
engine: {
|
|
1424
|
+
step: this.inngestStep
|
|
1425
|
+
},
|
|
1426
|
+
abortSignal: abortController.signal,
|
|
1427
|
+
writer: new ToolStream(
|
|
1428
|
+
{
|
|
1429
|
+
prefix: "workflow-step",
|
|
1430
|
+
callId: randomUUID(),
|
|
1431
|
+
name: "conditional",
|
|
1432
|
+
runId
|
|
1433
|
+
},
|
|
1434
|
+
writableStream
|
|
1435
|
+
)
|
|
1441
1436
|
},
|
|
1442
|
-
|
|
1437
|
+
{
|
|
1438
|
+
paramName: "runCount",
|
|
1439
|
+
deprecationMessage: runCountDeprecationMessage,
|
|
1440
|
+
logger: this.logger
|
|
1441
|
+
}
|
|
1443
1442
|
)
|
|
1444
|
-
|
|
1443
|
+
);
|
|
1445
1444
|
evalSpan?.end({
|
|
1446
1445
|
output: result,
|
|
1447
1446
|
attributes: {
|
|
@@ -1469,13 +1468,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1469
1468
|
}
|
|
1470
1469
|
});
|
|
1471
1470
|
const results = await Promise.all(
|
|
1472
|
-
stepsToRun.map(
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1471
|
+
stepsToRun.map(async (step, index) => {
|
|
1472
|
+
const currStepResult = stepResults[step.step.id];
|
|
1473
|
+
if (currStepResult && currStepResult.status === "success") {
|
|
1474
|
+
return currStepResult;
|
|
1475
|
+
}
|
|
1476
|
+
const result = await this.executeStep({
|
|
1477
|
+
step: step.step,
|
|
1478
|
+
prevOutput,
|
|
1479
1479
|
stepResults,
|
|
1480
1480
|
resume,
|
|
1481
1481
|
executionContext: {
|
|
@@ -1483,32 +1483,34 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1483
1483
|
runId,
|
|
1484
1484
|
executionPath: [...executionContext.executionPath, index],
|
|
1485
1485
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1486
|
+
resumeLabels: executionContext.resumeLabels,
|
|
1486
1487
|
retryConfig: executionContext.retryConfig,
|
|
1487
|
-
executionSpan: executionContext.executionSpan,
|
|
1488
1488
|
state: executionContext.state
|
|
1489
1489
|
},
|
|
1490
1490
|
emitter,
|
|
1491
1491
|
abortController,
|
|
1492
|
-
|
|
1492
|
+
requestContext,
|
|
1493
1493
|
writableStream,
|
|
1494
1494
|
disableScorers,
|
|
1495
1495
|
tracingContext: {
|
|
1496
1496
|
currentSpan: conditionalSpan
|
|
1497
1497
|
}
|
|
1498
|
-
})
|
|
1499
|
-
|
|
1498
|
+
});
|
|
1499
|
+
stepResults[step.step.id] = result;
|
|
1500
|
+
return result;
|
|
1501
|
+
})
|
|
1500
1502
|
);
|
|
1501
|
-
const hasFailed = results.find((result) => result.
|
|
1502
|
-
const hasSuspended = results.find((result) => result.
|
|
1503
|
+
const hasFailed = results.find((result) => result.status === "failed");
|
|
1504
|
+
const hasSuspended = results.find((result) => result.status === "suspended");
|
|
1503
1505
|
if (hasFailed) {
|
|
1504
|
-
execResults = { status: "failed", error: hasFailed.
|
|
1506
|
+
execResults = { status: "failed", error: hasFailed.error };
|
|
1505
1507
|
} else if (hasSuspended) {
|
|
1506
|
-
execResults = { status: "suspended", suspendPayload: hasSuspended.
|
|
1508
|
+
execResults = { status: "suspended", suspendPayload: hasSuspended.suspendPayload };
|
|
1507
1509
|
} else {
|
|
1508
1510
|
execResults = {
|
|
1509
1511
|
status: "success",
|
|
1510
1512
|
output: results.reduce((acc, result, index) => {
|
|
1511
|
-
if (result.
|
|
1513
|
+
if (result.status === "success") {
|
|
1512
1514
|
acc[stepsToRun[index].step.id] = result.output;
|
|
1513
1515
|
}
|
|
1514
1516
|
return acc;
|