@mastra/inngest 0.0.0-playground-studio-cloud-20251031080052 → 0.0.0-playground-studio-again-20251114102707
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 +275 -3
- package/dist/index.cjs +213 -310
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +70 -71
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +214 -311
- package/dist/index.js.map +1 -1
- package/package.json +16 -11
package/dist/index.cjs
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
var crypto = require('crypto');
|
|
4
4
|
var web = require('stream/web');
|
|
5
5
|
var realtime = require('@inngest/realtime');
|
|
6
|
-
var aiTracing = require('@mastra/core/ai-tracing');
|
|
7
6
|
var di = require('@mastra/core/di');
|
|
7
|
+
var observability = require('@mastra/core/observability');
|
|
8
8
|
var stream = require('@mastra/core/stream');
|
|
9
9
|
var tools = require('@mastra/core/tools');
|
|
10
10
|
var workflows = require('@mastra/core/workflows');
|
|
@@ -20,7 +20,7 @@ function serve({
|
|
|
20
20
|
functions: userFunctions = [],
|
|
21
21
|
registerOptions
|
|
22
22
|
}) {
|
|
23
|
-
const wfs = mastra.
|
|
23
|
+
const wfs = mastra.listWorkflows();
|
|
24
24
|
const workflowFunctions = Array.from(
|
|
25
25
|
new Set(
|
|
26
26
|
Object.values(wfs).flatMap((wf) => {
|
|
@@ -59,11 +59,12 @@ var InngestRun = class extends workflows.Run {
|
|
|
59
59
|
}
|
|
60
60
|
async getRunOutput(eventId) {
|
|
61
61
|
let runs = await this.getRuns(eventId);
|
|
62
|
+
const storage = this.#mastra?.getStorage();
|
|
62
63
|
while (runs?.[0]?.status !== "Completed" || runs?.[0]?.event_id !== eventId) {
|
|
63
64
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
64
65
|
runs = await this.getRuns(eventId);
|
|
65
66
|
if (runs?.[0]?.status === "Failed") {
|
|
66
|
-
const snapshot = await
|
|
67
|
+
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
67
68
|
workflowName: this.workflowId,
|
|
68
69
|
runId: this.runId
|
|
69
70
|
});
|
|
@@ -72,7 +73,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
72
73
|
};
|
|
73
74
|
}
|
|
74
75
|
if (runs?.[0]?.status === "Cancelled") {
|
|
75
|
-
const snapshot = await
|
|
76
|
+
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
76
77
|
workflowName: this.workflowId,
|
|
77
78
|
runId: this.runId
|
|
78
79
|
});
|
|
@@ -81,38 +82,40 @@ var InngestRun = class extends workflows.Run {
|
|
|
81
82
|
}
|
|
82
83
|
return runs?.[0];
|
|
83
84
|
}
|
|
84
|
-
async sendEvent(event, data) {
|
|
85
|
-
await this.inngest.send({
|
|
86
|
-
name: `user-event-${event}`,
|
|
87
|
-
data
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
85
|
async cancel() {
|
|
86
|
+
const storage = this.#mastra?.getStorage();
|
|
91
87
|
await this.inngest.send({
|
|
92
88
|
name: `cancel.workflow.${this.workflowId}`,
|
|
93
89
|
data: {
|
|
94
90
|
runId: this.runId
|
|
95
91
|
}
|
|
96
92
|
});
|
|
97
|
-
const snapshot = await
|
|
93
|
+
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
98
94
|
workflowName: this.workflowId,
|
|
99
95
|
runId: this.runId
|
|
100
96
|
});
|
|
101
97
|
if (snapshot) {
|
|
102
|
-
await
|
|
98
|
+
await storage?.persistWorkflowSnapshot({
|
|
103
99
|
workflowName: this.workflowId,
|
|
104
100
|
runId: this.runId,
|
|
105
101
|
resourceId: this.resourceId,
|
|
106
102
|
snapshot: {
|
|
107
103
|
...snapshot,
|
|
108
|
-
status: "canceled"
|
|
104
|
+
status: "canceled",
|
|
105
|
+
value: snapshot.value
|
|
109
106
|
}
|
|
110
107
|
});
|
|
111
108
|
}
|
|
112
109
|
}
|
|
113
|
-
async start({
|
|
110
|
+
async start(params) {
|
|
111
|
+
return this._start(params);
|
|
112
|
+
}
|
|
113
|
+
async _start({
|
|
114
114
|
inputData,
|
|
115
|
-
initialState
|
|
115
|
+
initialState,
|
|
116
|
+
outputOptions,
|
|
117
|
+
tracingOptions,
|
|
118
|
+
format
|
|
116
119
|
}) {
|
|
117
120
|
await this.#mastra.getStorage()?.persistWorkflowSnapshot({
|
|
118
121
|
workflowName: this.workflowId,
|
|
@@ -121,14 +124,15 @@ var InngestRun = class extends workflows.Run {
|
|
|
121
124
|
snapshot: {
|
|
122
125
|
runId: this.runId,
|
|
123
126
|
serializedStepGraph: this.serializedStepGraph,
|
|
127
|
+
status: "running",
|
|
124
128
|
value: {},
|
|
125
129
|
context: {},
|
|
126
130
|
activePaths: [],
|
|
127
131
|
suspendedPaths: {},
|
|
132
|
+
activeStepsPath: {},
|
|
128
133
|
resumeLabels: {},
|
|
129
134
|
waitingPaths: {},
|
|
130
|
-
timestamp: Date.now()
|
|
131
|
-
status: "running"
|
|
135
|
+
timestamp: Date.now()
|
|
132
136
|
}
|
|
133
137
|
});
|
|
134
138
|
const inputDataToUse = await this._validateInput(inputData);
|
|
@@ -139,7 +143,10 @@ var InngestRun = class extends workflows.Run {
|
|
|
139
143
|
inputData: inputDataToUse,
|
|
140
144
|
initialState: initialStateToUse,
|
|
141
145
|
runId: this.runId,
|
|
142
|
-
resourceId: this.resourceId
|
|
146
|
+
resourceId: this.resourceId,
|
|
147
|
+
outputOptions,
|
|
148
|
+
tracingOptions,
|
|
149
|
+
format
|
|
143
150
|
}
|
|
144
151
|
});
|
|
145
152
|
const eventId = eventOutput.ids[0];
|
|
@@ -168,10 +175,11 @@ var InngestRun = class extends workflows.Run {
|
|
|
168
175
|
return p;
|
|
169
176
|
}
|
|
170
177
|
async _resume(params) {
|
|
178
|
+
const storage = this.#mastra?.getStorage();
|
|
171
179
|
const steps = (Array.isArray(params.step) ? params.step : [params.step]).map(
|
|
172
180
|
(step) => typeof step === "string" ? step : step?.id
|
|
173
181
|
);
|
|
174
|
-
const snapshot = await
|
|
182
|
+
const snapshot = await storage?.loadWorkflowSnapshot({
|
|
175
183
|
workflowName: this.workflowId,
|
|
176
184
|
runId: this.runId
|
|
177
185
|
});
|
|
@@ -205,12 +213,12 @@ var InngestRun = class extends workflows.Run {
|
|
|
205
213
|
}
|
|
206
214
|
return result;
|
|
207
215
|
}
|
|
208
|
-
watch(cb
|
|
216
|
+
watch(cb) {
|
|
209
217
|
let active = true;
|
|
210
218
|
const streamPromise = realtime.subscribe(
|
|
211
219
|
{
|
|
212
220
|
channel: `workflow:${this.workflowId}:${this.runId}`,
|
|
213
|
-
topics: [
|
|
221
|
+
topics: ["watch"],
|
|
214
222
|
app: this.inngest
|
|
215
223
|
},
|
|
216
224
|
(message) => {
|
|
@@ -228,20 +236,35 @@ var InngestRun = class extends workflows.Run {
|
|
|
228
236
|
});
|
|
229
237
|
};
|
|
230
238
|
}
|
|
231
|
-
streamLegacy({ inputData,
|
|
239
|
+
streamLegacy({ inputData, requestContext } = {}) {
|
|
232
240
|
const { readable, writable } = new TransformStream();
|
|
233
241
|
const writer = writable.getWriter();
|
|
234
242
|
const unwatch = this.watch(async (event) => {
|
|
235
243
|
try {
|
|
244
|
+
await writer.write({
|
|
245
|
+
// @ts-ignore
|
|
246
|
+
type: "start",
|
|
247
|
+
// @ts-ignore
|
|
248
|
+
payload: { runId: this.runId }
|
|
249
|
+
});
|
|
236
250
|
const e = {
|
|
237
251
|
...event,
|
|
238
252
|
type: event.type.replace("workflow-", "")
|
|
239
253
|
};
|
|
254
|
+
if (e.type === "step-output") {
|
|
255
|
+
e.type = e.payload.output.type;
|
|
256
|
+
e.payload = e.payload.output.payload;
|
|
257
|
+
}
|
|
240
258
|
await writer.write(e);
|
|
241
259
|
} catch {
|
|
242
260
|
}
|
|
243
|
-
}
|
|
261
|
+
});
|
|
244
262
|
this.closeStreamAction = async () => {
|
|
263
|
+
await writer.write({
|
|
264
|
+
type: "finish",
|
|
265
|
+
// @ts-ignore
|
|
266
|
+
payload: { runId: this.runId }
|
|
267
|
+
});
|
|
245
268
|
unwatch();
|
|
246
269
|
try {
|
|
247
270
|
await writer.close();
|
|
@@ -251,7 +274,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
251
274
|
writer.releaseLock();
|
|
252
275
|
}
|
|
253
276
|
};
|
|
254
|
-
this.executionResults = this.
|
|
277
|
+
this.executionResults = this._start({ inputData, requestContext, format: "legacy" }).then((result) => {
|
|
255
278
|
if (result.status !== "suspended") {
|
|
256
279
|
this.closeStreamAction?.().catch(() => {
|
|
257
280
|
});
|
|
@@ -265,11 +288,18 @@ var InngestRun = class extends workflows.Run {
|
|
|
265
288
|
}
|
|
266
289
|
stream({
|
|
267
290
|
inputData,
|
|
268
|
-
|
|
269
|
-
|
|
291
|
+
requestContext,
|
|
292
|
+
tracingOptions,
|
|
293
|
+
closeOnSuspend = true,
|
|
294
|
+
initialState,
|
|
295
|
+
outputOptions
|
|
270
296
|
} = {}) {
|
|
297
|
+
if (this.closeStreamAction && this.streamOutput) {
|
|
298
|
+
return this.streamOutput;
|
|
299
|
+
}
|
|
300
|
+
this.closeStreamAction = async () => {
|
|
301
|
+
};
|
|
271
302
|
const self = this;
|
|
272
|
-
let streamOutput;
|
|
273
303
|
const stream$1 = new web.ReadableStream({
|
|
274
304
|
async start(controller) {
|
|
275
305
|
const unwatch = self.watch(async ({ type, from = stream.ChunkFrom.WORKFLOW, payload }) => {
|
|
@@ -278,11 +308,11 @@ var InngestRun = class extends workflows.Run {
|
|
|
278
308
|
runId: self.runId,
|
|
279
309
|
from,
|
|
280
310
|
payload: {
|
|
281
|
-
stepName: payload
|
|
311
|
+
stepName: payload?.id,
|
|
282
312
|
...payload
|
|
283
313
|
}
|
|
284
314
|
});
|
|
285
|
-
}
|
|
315
|
+
});
|
|
286
316
|
self.closeStreamAction = async () => {
|
|
287
317
|
unwatch();
|
|
288
318
|
try {
|
|
@@ -291,29 +321,46 @@ var InngestRun = class extends workflows.Run {
|
|
|
291
321
|
console.error("Error closing stream:", err);
|
|
292
322
|
}
|
|
293
323
|
};
|
|
294
|
-
const executionResultsPromise = self.
|
|
324
|
+
const executionResultsPromise = self._start({
|
|
295
325
|
inputData,
|
|
296
|
-
|
|
326
|
+
requestContext,
|
|
327
|
+
// tracingContext, // We are not able to pass a reference to a span here, what to do?
|
|
328
|
+
initialState,
|
|
329
|
+
tracingOptions,
|
|
330
|
+
outputOptions,
|
|
331
|
+
format: "vnext"
|
|
297
332
|
});
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
333
|
+
let executionResults;
|
|
334
|
+
try {
|
|
335
|
+
executionResults = await executionResultsPromise;
|
|
336
|
+
if (closeOnSuspend) {
|
|
337
|
+
self.closeStreamAction?.().catch(() => {
|
|
338
|
+
});
|
|
339
|
+
} else if (executionResults.status !== "suspended") {
|
|
340
|
+
self.closeStreamAction?.().catch(() => {
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
if (self.streamOutput) {
|
|
344
|
+
self.streamOutput.updateResults(
|
|
345
|
+
executionResults
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
} catch (err) {
|
|
349
|
+
self.streamOutput?.rejectResults(err);
|
|
303
350
|
self.closeStreamAction?.().catch(() => {
|
|
304
351
|
});
|
|
305
352
|
}
|
|
306
|
-
if (streamOutput) {
|
|
307
|
-
streamOutput.updateResults(executionResults);
|
|
308
|
-
}
|
|
309
353
|
}
|
|
310
354
|
});
|
|
311
|
-
streamOutput = new stream.WorkflowRunOutput({
|
|
355
|
+
this.streamOutput = new stream.WorkflowRunOutput({
|
|
312
356
|
runId: this.runId,
|
|
313
357
|
workflowId: this.workflowId,
|
|
314
358
|
stream: stream$1
|
|
315
359
|
});
|
|
316
|
-
return streamOutput;
|
|
360
|
+
return this.streamOutput;
|
|
361
|
+
}
|
|
362
|
+
streamVNext(args = {}) {
|
|
363
|
+
return this.stream(args);
|
|
317
364
|
}
|
|
318
365
|
};
|
|
319
366
|
var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
@@ -324,6 +371,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
324
371
|
constructor(params, inngest) {
|
|
325
372
|
const { concurrency, rateLimit, throttle, debounce, priority, ...workflowParams } = params;
|
|
326
373
|
super(workflowParams);
|
|
374
|
+
this.engineType = "inngest";
|
|
327
375
|
const flowControlEntries = Object.entries({ concurrency, rateLimit, throttle, debounce, priority }).filter(
|
|
328
376
|
([_, value]) => value !== void 0
|
|
329
377
|
);
|
|
@@ -331,13 +379,13 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
331
379
|
this.#mastra = params.mastra;
|
|
332
380
|
this.inngest = inngest;
|
|
333
381
|
}
|
|
334
|
-
async
|
|
382
|
+
async listWorkflowRuns(args) {
|
|
335
383
|
const storage = this.#mastra?.getStorage();
|
|
336
384
|
if (!storage) {
|
|
337
385
|
this.logger.debug("Cannot get workflow runs. Mastra engine is not initialized");
|
|
338
386
|
return { runs: [], total: 0 };
|
|
339
387
|
}
|
|
340
|
-
return storage.
|
|
388
|
+
return storage.listWorkflowRuns({ workflowName: this.id, ...args ?? {} });
|
|
341
389
|
}
|
|
342
390
|
async getWorkflowRunById(runId) {
|
|
343
391
|
const storage = this.#mastra?.getStorage();
|
|
@@ -366,16 +414,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
366
414
|
}
|
|
367
415
|
}
|
|
368
416
|
}
|
|
369
|
-
|
|
370
|
-
* @deprecated Use createRunAsync() instead.
|
|
371
|
-
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
372
|
-
*/
|
|
373
|
-
createRun(_options) {
|
|
374
|
-
throw new Error(
|
|
375
|
-
"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."
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
async createRunAsync(options) {
|
|
417
|
+
async createRun(options) {
|
|
379
418
|
const runIdToUse = options?.runId || crypto.randomUUID();
|
|
380
419
|
const run = this.runs.get(runIdToUse) ?? new InngestRun(
|
|
381
420
|
{
|
|
@@ -388,7 +427,8 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
388
427
|
mastra: this.#mastra,
|
|
389
428
|
retryConfig: this.retryConfig,
|
|
390
429
|
cleanup: () => this.runs.delete(runIdToUse),
|
|
391
|
-
workflowSteps: this.steps
|
|
430
|
+
workflowSteps: this.steps,
|
|
431
|
+
workflowEngineType: this.engineType
|
|
392
432
|
},
|
|
393
433
|
this.inngest
|
|
394
434
|
);
|
|
@@ -409,6 +449,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
409
449
|
value: {},
|
|
410
450
|
context: {},
|
|
411
451
|
activePaths: [],
|
|
452
|
+
activeStepsPath: {},
|
|
412
453
|
waitingPaths: {},
|
|
413
454
|
serializedStepGraph: this.serializedStepGraph,
|
|
414
455
|
suspendedPaths: {},
|
|
@@ -437,7 +478,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
437
478
|
},
|
|
438
479
|
{ event: `workflow.${this.id}` },
|
|
439
480
|
async ({ event, step, attempt, publish }) => {
|
|
440
|
-
let { inputData, initialState, runId, resourceId, resume, outputOptions } = event.data;
|
|
481
|
+
let { inputData, initialState, runId, resourceId, resume, outputOptions, format } = event.data;
|
|
441
482
|
if (!runId) {
|
|
442
483
|
runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
|
|
443
484
|
return crypto.randomUUID();
|
|
@@ -476,13 +517,19 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
476
517
|
initialState,
|
|
477
518
|
emitter,
|
|
478
519
|
retryConfig: this.retryConfig,
|
|
479
|
-
|
|
520
|
+
requestContext: new di.RequestContext(),
|
|
480
521
|
// TODO
|
|
481
522
|
resume,
|
|
523
|
+
format,
|
|
482
524
|
abortController: new AbortController(),
|
|
483
|
-
currentSpan:
|
|
484
|
-
|
|
485
|
-
|
|
525
|
+
// currentSpan: undefined, // TODO: Pass actual parent Span from workflow execution context
|
|
526
|
+
outputOptions,
|
|
527
|
+
writableStream: new web.WritableStream({
|
|
528
|
+
write(chunk) {
|
|
529
|
+
void emitter.emit("watch", chunk).catch(() => {
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
})
|
|
486
533
|
});
|
|
487
534
|
await step.run(`workflow.${this.id}.finalize`, async () => {
|
|
488
535
|
if (result.status === "failed") {
|
|
@@ -520,7 +567,7 @@ function isAgent(params) {
|
|
|
520
567
|
function isTool(params) {
|
|
521
568
|
return params instanceof tools.Tool;
|
|
522
569
|
}
|
|
523
|
-
function createStep(params) {
|
|
570
|
+
function createStep(params, agentOptions) {
|
|
524
571
|
if (isAgent(params)) {
|
|
525
572
|
return {
|
|
526
573
|
id: params.name,
|
|
@@ -528,12 +575,23 @@ function createStep(params) {
|
|
|
528
575
|
// @ts-ignore
|
|
529
576
|
inputSchema: zod.z.object({
|
|
530
577
|
prompt: zod.z.string()
|
|
578
|
+
// resourceId: z.string().optional(),
|
|
579
|
+
// threadId: z.string().optional(),
|
|
531
580
|
}),
|
|
532
581
|
// @ts-ignore
|
|
533
582
|
outputSchema: zod.z.object({
|
|
534
583
|
text: zod.z.string()
|
|
535
584
|
}),
|
|
536
|
-
execute: async ({
|
|
585
|
+
execute: async ({
|
|
586
|
+
inputData,
|
|
587
|
+
[_constants.EMITTER_SYMBOL]: emitter,
|
|
588
|
+
[_constants.STREAM_FORMAT_SYMBOL]: streamFormat,
|
|
589
|
+
requestContext,
|
|
590
|
+
tracingContext,
|
|
591
|
+
abortSignal,
|
|
592
|
+
abort,
|
|
593
|
+
writer
|
|
594
|
+
}) => {
|
|
537
595
|
let streamPromise = {};
|
|
538
596
|
streamPromise.promise = new Promise((resolve, reject) => {
|
|
539
597
|
streamPromise.resolve = resolve;
|
|
@@ -543,61 +601,60 @@ function createStep(params) {
|
|
|
543
601
|
name: params.name,
|
|
544
602
|
args: inputData
|
|
545
603
|
};
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
604
|
+
let stream;
|
|
605
|
+
if ((await params.getModel()).specificationVersion === "v1") {
|
|
606
|
+
const { fullStream } = await params.streamLegacy(inputData.prompt, {
|
|
607
|
+
...agentOptions ?? {},
|
|
608
|
+
// resourceId: inputData.resourceId,
|
|
609
|
+
// threadId: inputData.threadId,
|
|
610
|
+
requestContext,
|
|
549
611
|
tracingContext,
|
|
550
612
|
onFinish: (result) => {
|
|
551
613
|
streamPromise.resolve(result.text);
|
|
614
|
+
void agentOptions?.onFinish?.(result);
|
|
552
615
|
},
|
|
553
616
|
abortSignal
|
|
554
617
|
});
|
|
555
|
-
|
|
556
|
-
return abort();
|
|
557
|
-
}
|
|
558
|
-
await emitter.emit("watch-v2", {
|
|
559
|
-
type: "tool-call-streaming-start",
|
|
560
|
-
...toolData ?? {}
|
|
561
|
-
});
|
|
562
|
-
for await (const chunk of fullStream) {
|
|
563
|
-
if (chunk.type === "text-delta") {
|
|
564
|
-
await emitter.emit("watch-v2", {
|
|
565
|
-
type: "tool-call-delta",
|
|
566
|
-
...toolData ?? {},
|
|
567
|
-
argsTextDelta: chunk.payload.text
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
}
|
|
618
|
+
stream = fullStream;
|
|
571
619
|
} else {
|
|
572
|
-
const
|
|
573
|
-
|
|
620
|
+
const modelOutput = await params.stream(inputData.prompt, {
|
|
621
|
+
...agentOptions ?? {},
|
|
622
|
+
requestContext,
|
|
574
623
|
tracingContext,
|
|
575
624
|
onFinish: (result) => {
|
|
576
625
|
streamPromise.resolve(result.text);
|
|
626
|
+
void agentOptions?.onFinish?.(result);
|
|
577
627
|
},
|
|
578
628
|
abortSignal
|
|
579
629
|
});
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
await emitter.emit("watch
|
|
630
|
+
stream = modelOutput.fullStream;
|
|
631
|
+
}
|
|
632
|
+
if (streamFormat === "legacy") {
|
|
633
|
+
await emitter.emit("watch", {
|
|
584
634
|
type: "tool-call-streaming-start",
|
|
585
635
|
...toolData ?? {}
|
|
586
636
|
});
|
|
587
|
-
for await (const chunk of
|
|
637
|
+
for await (const chunk of stream) {
|
|
588
638
|
if (chunk.type === "text-delta") {
|
|
589
|
-
await emitter.emit("watch
|
|
639
|
+
await emitter.emit("watch", {
|
|
590
640
|
type: "tool-call-delta",
|
|
591
641
|
...toolData ?? {},
|
|
592
642
|
argsTextDelta: chunk.textDelta
|
|
593
643
|
});
|
|
594
644
|
}
|
|
595
645
|
}
|
|
646
|
+
await emitter.emit("watch", {
|
|
647
|
+
type: "tool-call-streaming-finish",
|
|
648
|
+
...toolData ?? {}
|
|
649
|
+
});
|
|
650
|
+
} else {
|
|
651
|
+
for await (const chunk of stream) {
|
|
652
|
+
await writer.write(chunk);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
if (abortSignal.aborted) {
|
|
656
|
+
return abort();
|
|
596
657
|
}
|
|
597
|
-
await emitter.emit("watch-v2", {
|
|
598
|
-
type: "tool-call-streaming-finish",
|
|
599
|
-
...toolData ?? {}
|
|
600
|
-
});
|
|
601
658
|
return {
|
|
602
659
|
text: await streamPromise.promise
|
|
603
660
|
};
|
|
@@ -616,11 +673,11 @@ function createStep(params) {
|
|
|
616
673
|
description: params.description,
|
|
617
674
|
inputSchema: params.inputSchema,
|
|
618
675
|
outputSchema: params.outputSchema,
|
|
619
|
-
execute: async ({ inputData, mastra,
|
|
676
|
+
execute: async ({ inputData, mastra, requestContext, tracingContext, suspend, resumeData }) => {
|
|
620
677
|
return params.execute({
|
|
621
678
|
context: inputData,
|
|
622
|
-
mastra:
|
|
623
|
-
|
|
679
|
+
mastra: observability.wrapMastra(mastra, tracingContext),
|
|
680
|
+
requestContext,
|
|
624
681
|
tracingContext,
|
|
625
682
|
suspend,
|
|
626
683
|
resumeData
|
|
@@ -683,63 +740,16 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
683
740
|
this.inngestStep = inngestStep;
|
|
684
741
|
this.inngestAttempts = inngestAttempts;
|
|
685
742
|
}
|
|
686
|
-
async execute(params) {
|
|
687
|
-
await params.emitter.emit("watch-v2", {
|
|
688
|
-
type: "workflow-start",
|
|
689
|
-
payload: { runId: params.runId }
|
|
690
|
-
});
|
|
691
|
-
const result = await super.execute(params);
|
|
692
|
-
await params.emitter.emit("watch-v2", {
|
|
693
|
-
type: "workflow-finish",
|
|
694
|
-
payload: { runId: params.runId }
|
|
695
|
-
});
|
|
696
|
-
return result;
|
|
697
|
-
}
|
|
698
743
|
async fmtReturnValue(emitter, stepResults, lastOutput, error) {
|
|
699
744
|
const base = {
|
|
700
745
|
status: lastOutput.status,
|
|
701
746
|
steps: stepResults
|
|
702
747
|
};
|
|
703
748
|
if (lastOutput.status === "success") {
|
|
704
|
-
await emitter.emit("watch", {
|
|
705
|
-
type: "watch",
|
|
706
|
-
payload: {
|
|
707
|
-
workflowState: {
|
|
708
|
-
status: lastOutput.status,
|
|
709
|
-
steps: stepResults,
|
|
710
|
-
result: lastOutput.output
|
|
711
|
-
}
|
|
712
|
-
},
|
|
713
|
-
eventTimestamp: Date.now()
|
|
714
|
-
});
|
|
715
749
|
base.result = lastOutput.output;
|
|
716
750
|
} else if (lastOutput.status === "failed") {
|
|
717
751
|
base.error = error instanceof Error ? error?.stack ?? error.message : lastOutput?.error instanceof Error ? lastOutput.error.message : lastOutput.error ?? error ?? "Unknown error";
|
|
718
|
-
await emitter.emit("watch", {
|
|
719
|
-
type: "watch",
|
|
720
|
-
payload: {
|
|
721
|
-
workflowState: {
|
|
722
|
-
status: lastOutput.status,
|
|
723
|
-
steps: stepResults,
|
|
724
|
-
result: null,
|
|
725
|
-
error: base.error
|
|
726
|
-
}
|
|
727
|
-
},
|
|
728
|
-
eventTimestamp: Date.now()
|
|
729
|
-
});
|
|
730
752
|
} else if (lastOutput.status === "suspended") {
|
|
731
|
-
await emitter.emit("watch", {
|
|
732
|
-
type: "watch",
|
|
733
|
-
payload: {
|
|
734
|
-
workflowState: {
|
|
735
|
-
status: lastOutput.status,
|
|
736
|
-
steps: stepResults,
|
|
737
|
-
result: null,
|
|
738
|
-
error: null
|
|
739
|
-
}
|
|
740
|
-
},
|
|
741
|
-
eventTimestamp: Date.now()
|
|
742
|
-
});
|
|
743
753
|
const suspendedStepIds = Object.entries(stepResults).flatMap(([stepId, stepResult]) => {
|
|
744
754
|
if (stepResult?.status === "suspended") {
|
|
745
755
|
const nestedPath = stepResult?.suspendPayload?.__workflow_meta?.path;
|
|
@@ -762,14 +772,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
762
772
|
stepResults,
|
|
763
773
|
emitter,
|
|
764
774
|
abortController,
|
|
765
|
-
|
|
775
|
+
requestContext,
|
|
766
776
|
executionContext,
|
|
767
777
|
writableStream,
|
|
768
778
|
tracingContext
|
|
769
779
|
}) {
|
|
770
780
|
let { duration, fn } = entry;
|
|
771
781
|
const sleepSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
772
|
-
type:
|
|
782
|
+
type: observability.SpanType.WORKFLOW_SLEEP,
|
|
773
783
|
name: `sleep: ${duration ? `${duration}ms` : "dynamic"}`,
|
|
774
784
|
attributes: {
|
|
775
785
|
durationMs: duration,
|
|
@@ -786,13 +796,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
786
796
|
runId,
|
|
787
797
|
workflowId,
|
|
788
798
|
mastra: this.mastra,
|
|
789
|
-
|
|
799
|
+
requestContext,
|
|
790
800
|
inputData: prevOutput,
|
|
791
801
|
state: executionContext.state,
|
|
792
802
|
setState: (state) => {
|
|
793
803
|
executionContext.state = state;
|
|
794
804
|
},
|
|
795
|
-
runCount: -1,
|
|
796
805
|
retryCount: -1,
|
|
797
806
|
tracingContext: {
|
|
798
807
|
currentSpan: sleepSpan
|
|
@@ -808,7 +817,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
808
817
|
abortController?.abort();
|
|
809
818
|
},
|
|
810
819
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
811
|
-
// TODO: add streamVNext support
|
|
812
820
|
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
813
821
|
engine: { step: this.inngestStep },
|
|
814
822
|
abortSignal: abortController?.signal,
|
|
@@ -852,14 +860,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
852
860
|
stepResults,
|
|
853
861
|
emitter,
|
|
854
862
|
abortController,
|
|
855
|
-
|
|
863
|
+
requestContext,
|
|
856
864
|
executionContext,
|
|
857
865
|
writableStream,
|
|
858
866
|
tracingContext
|
|
859
867
|
}) {
|
|
860
868
|
let { date, fn } = entry;
|
|
861
869
|
const sleepUntilSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
862
|
-
type:
|
|
870
|
+
type: observability.SpanType.WORKFLOW_SLEEP,
|
|
863
871
|
name: `sleepUntil: ${date ? date.toISOString() : "dynamic"}`,
|
|
864
872
|
attributes: {
|
|
865
873
|
untilDate: date,
|
|
@@ -877,13 +885,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
877
885
|
runId,
|
|
878
886
|
workflowId,
|
|
879
887
|
mastra: this.mastra,
|
|
880
|
-
|
|
888
|
+
requestContext,
|
|
881
889
|
inputData: prevOutput,
|
|
882
890
|
state: executionContext.state,
|
|
883
891
|
setState: (state) => {
|
|
884
892
|
executionContext.state = state;
|
|
885
893
|
},
|
|
886
|
-
runCount: -1,
|
|
887
894
|
retryCount: -1,
|
|
888
895
|
tracingContext: {
|
|
889
896
|
currentSpan: sleepUntilSpan
|
|
@@ -900,7 +907,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
900
907
|
},
|
|
901
908
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
902
909
|
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
903
|
-
// TODO: add streamVNext support
|
|
904
910
|
engine: { step: this.inngestStep },
|
|
905
911
|
abortSignal: abortController?.signal,
|
|
906
912
|
writer: new tools.ToolStream(
|
|
@@ -943,16 +949,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
943
949
|
throw e;
|
|
944
950
|
}
|
|
945
951
|
}
|
|
946
|
-
async executeWaitForEvent({ event, timeout }) {
|
|
947
|
-
const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
|
|
948
|
-
event: `user-event-${event}`,
|
|
949
|
-
timeout: timeout ?? 5e3
|
|
950
|
-
});
|
|
951
|
-
if (eventData === null) {
|
|
952
|
-
throw "Timeout waiting for event";
|
|
953
|
-
}
|
|
954
|
-
return eventData?.data;
|
|
955
|
-
}
|
|
956
952
|
async executeStep({
|
|
957
953
|
step,
|
|
958
954
|
stepResults,
|
|
@@ -961,14 +957,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
961
957
|
prevOutput,
|
|
962
958
|
emitter,
|
|
963
959
|
abortController,
|
|
964
|
-
|
|
960
|
+
requestContext,
|
|
965
961
|
tracingContext,
|
|
966
962
|
writableStream,
|
|
967
963
|
disableScorers
|
|
968
964
|
}) {
|
|
969
|
-
const
|
|
965
|
+
const stepSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
970
966
|
name: `workflow step: '${step.id}'`,
|
|
971
|
-
type:
|
|
967
|
+
type: observability.SpanType.WORKFLOW_STEP,
|
|
972
968
|
input: prevOutput,
|
|
973
969
|
attributes: {
|
|
974
970
|
stepId: step.id
|
|
@@ -985,27 +981,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
985
981
|
async () => {
|
|
986
982
|
const startedAt2 = Date.now();
|
|
987
983
|
await emitter.emit("watch", {
|
|
988
|
-
type: "watch",
|
|
989
|
-
payload: {
|
|
990
|
-
currentStep: {
|
|
991
|
-
id: step.id,
|
|
992
|
-
status: "running"
|
|
993
|
-
},
|
|
994
|
-
workflowState: {
|
|
995
|
-
status: "running",
|
|
996
|
-
steps: {
|
|
997
|
-
...stepResults,
|
|
998
|
-
[step.id]: {
|
|
999
|
-
status: "running"
|
|
1000
|
-
}
|
|
1001
|
-
},
|
|
1002
|
-
result: null,
|
|
1003
|
-
error: null
|
|
1004
|
-
}
|
|
1005
|
-
},
|
|
1006
|
-
eventTimestamp: Date.now()
|
|
1007
|
-
});
|
|
1008
|
-
await emitter.emit("watch-v2", {
|
|
1009
984
|
type: "workflow-step-start",
|
|
1010
985
|
payload: {
|
|
1011
986
|
id: step.id,
|
|
@@ -1081,23 +1056,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1081
1056
|
async () => {
|
|
1082
1057
|
if (result.status === "failed") {
|
|
1083
1058
|
await emitter.emit("watch", {
|
|
1084
|
-
type: "watch",
|
|
1085
|
-
payload: {
|
|
1086
|
-
currentStep: {
|
|
1087
|
-
id: step.id,
|
|
1088
|
-
status: "failed",
|
|
1089
|
-
error: result?.error
|
|
1090
|
-
},
|
|
1091
|
-
workflowState: {
|
|
1092
|
-
status: "running",
|
|
1093
|
-
steps: stepResults,
|
|
1094
|
-
result: null,
|
|
1095
|
-
error: null
|
|
1096
|
-
}
|
|
1097
|
-
},
|
|
1098
|
-
eventTimestamp: Date.now()
|
|
1099
|
-
});
|
|
1100
|
-
await emitter.emit("watch-v2", {
|
|
1101
1059
|
type: "workflow-step-result",
|
|
1102
1060
|
payload: {
|
|
1103
1061
|
id: step.id,
|
|
@@ -1116,27 +1074,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1116
1074
|
const suspendPath = [stepName, ...stepResult?.suspendPayload?.__workflow_meta?.path ?? []];
|
|
1117
1075
|
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
1118
1076
|
await emitter.emit("watch", {
|
|
1119
|
-
type: "watch",
|
|
1120
|
-
payload: {
|
|
1121
|
-
currentStep: {
|
|
1122
|
-
id: step.id,
|
|
1123
|
-
status: "suspended",
|
|
1124
|
-
payload: stepResult.payload,
|
|
1125
|
-
suspendPayload: {
|
|
1126
|
-
...stepResult?.suspendPayload,
|
|
1127
|
-
__workflow_meta: { runId, path: suspendPath }
|
|
1128
|
-
}
|
|
1129
|
-
},
|
|
1130
|
-
workflowState: {
|
|
1131
|
-
status: "running",
|
|
1132
|
-
steps: stepResults,
|
|
1133
|
-
result: null,
|
|
1134
|
-
error: null
|
|
1135
|
-
}
|
|
1136
|
-
},
|
|
1137
|
-
eventTimestamp: Date.now()
|
|
1138
|
-
});
|
|
1139
|
-
await emitter.emit("watch-v2", {
|
|
1140
1077
|
type: "workflow-step-suspended",
|
|
1141
1078
|
payload: {
|
|
1142
1079
|
id: step.id,
|
|
@@ -1155,23 +1092,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1155
1092
|
}
|
|
1156
1093
|
};
|
|
1157
1094
|
}
|
|
1158
|
-
await emitter.emit("watch", {
|
|
1159
|
-
type: "watch",
|
|
1160
|
-
payload: {
|
|
1161
|
-
currentStep: {
|
|
1162
|
-
id: step.id,
|
|
1163
|
-
status: "suspended",
|
|
1164
|
-
payload: {}
|
|
1165
|
-
},
|
|
1166
|
-
workflowState: {
|
|
1167
|
-
status: "running",
|
|
1168
|
-
steps: stepResults,
|
|
1169
|
-
result: null,
|
|
1170
|
-
error: null
|
|
1171
|
-
}
|
|
1172
|
-
},
|
|
1173
|
-
eventTimestamp: Date.now()
|
|
1174
|
-
});
|
|
1175
1095
|
return {
|
|
1176
1096
|
executionContext,
|
|
1177
1097
|
result: {
|
|
@@ -1181,23 +1101,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1181
1101
|
};
|
|
1182
1102
|
}
|
|
1183
1103
|
await emitter.emit("watch", {
|
|
1184
|
-
type: "watch",
|
|
1185
|
-
payload: {
|
|
1186
|
-
currentStep: {
|
|
1187
|
-
id: step.id,
|
|
1188
|
-
status: "success",
|
|
1189
|
-
output: result?.result
|
|
1190
|
-
},
|
|
1191
|
-
workflowState: {
|
|
1192
|
-
status: "running",
|
|
1193
|
-
steps: stepResults,
|
|
1194
|
-
result: null,
|
|
1195
|
-
error: null
|
|
1196
|
-
}
|
|
1197
|
-
},
|
|
1198
|
-
eventTimestamp: Date.now()
|
|
1199
|
-
});
|
|
1200
|
-
await emitter.emit("watch-v2", {
|
|
1201
1104
|
type: "workflow-step-result",
|
|
1202
1105
|
payload: {
|
|
1203
1106
|
id: step.id,
|
|
@@ -1205,7 +1108,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1205
1108
|
output: result?.result
|
|
1206
1109
|
}
|
|
1207
1110
|
});
|
|
1208
|
-
await emitter.emit("watch
|
|
1111
|
+
await emitter.emit("watch", {
|
|
1209
1112
|
type: "workflow-step-finish",
|
|
1210
1113
|
payload: {
|
|
1211
1114
|
id: step.id,
|
|
@@ -1225,6 +1128,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1225
1128
|
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1226
1129
|
};
|
|
1227
1130
|
}
|
|
1131
|
+
const stepCallId = crypto.randomUUID();
|
|
1228
1132
|
let stepRes;
|
|
1229
1133
|
try {
|
|
1230
1134
|
stepRes = await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}`, async () => {
|
|
@@ -1238,8 +1142,16 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1238
1142
|
const result = await step.execute({
|
|
1239
1143
|
runId: executionContext.runId,
|
|
1240
1144
|
mastra: this.mastra,
|
|
1241
|
-
|
|
1242
|
-
|
|
1145
|
+
requestContext,
|
|
1146
|
+
writer: new tools.ToolStream(
|
|
1147
|
+
{
|
|
1148
|
+
prefix: "workflow-step",
|
|
1149
|
+
callId: stepCallId,
|
|
1150
|
+
name: step.id,
|
|
1151
|
+
runId: executionContext.runId
|
|
1152
|
+
},
|
|
1153
|
+
writableStream
|
|
1154
|
+
),
|
|
1243
1155
|
state: executionContext?.state ?? {},
|
|
1244
1156
|
setState: (state) => {
|
|
1245
1157
|
executionContext.state = state;
|
|
@@ -1247,7 +1159,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1247
1159
|
inputData,
|
|
1248
1160
|
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1249
1161
|
tracingContext: {
|
|
1250
|
-
currentSpan:
|
|
1162
|
+
currentSpan: stepSpan
|
|
1251
1163
|
},
|
|
1252
1164
|
getInitData: () => stepResults?.input,
|
|
1253
1165
|
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
@@ -1274,6 +1186,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1274
1186
|
runId: stepResults[step.id]?.suspendPayload?.__workflow_meta?.runId
|
|
1275
1187
|
},
|
|
1276
1188
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1189
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1277
1190
|
engine: {
|
|
1278
1191
|
step: this.inngestStep
|
|
1279
1192
|
},
|
|
@@ -1301,7 +1214,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1301
1214
|
};
|
|
1302
1215
|
execResults = stepFailure;
|
|
1303
1216
|
const fallbackErrorMessage = `Step ${step.id} failed`;
|
|
1304
|
-
|
|
1217
|
+
stepSpan?.error({ error: new Error(execResults.error ?? fallbackErrorMessage) });
|
|
1305
1218
|
throw new inngest.RetryAfterError(execResults.error ?? fallbackErrorMessage, executionContext.retryConfig.delay, {
|
|
1306
1219
|
cause: execResults
|
|
1307
1220
|
});
|
|
@@ -1310,6 +1223,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1310
1223
|
execResults = {
|
|
1311
1224
|
status: "suspended",
|
|
1312
1225
|
suspendPayload: suspended.payload,
|
|
1226
|
+
...execResults.output ? { suspendOutput: execResults.output } : {},
|
|
1313
1227
|
payload: inputData,
|
|
1314
1228
|
suspendedAt: Date.now(),
|
|
1315
1229
|
startedAt,
|
|
@@ -1325,24 +1239,8 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1325
1239
|
startedAt
|
|
1326
1240
|
};
|
|
1327
1241
|
}
|
|
1328
|
-
await emitter.emit("watch", {
|
|
1329
|
-
type: "watch",
|
|
1330
|
-
payload: {
|
|
1331
|
-
currentStep: {
|
|
1332
|
-
id: step.id,
|
|
1333
|
-
...execResults
|
|
1334
|
-
},
|
|
1335
|
-
workflowState: {
|
|
1336
|
-
status: "running",
|
|
1337
|
-
steps: { ...stepResults, [step.id]: execResults },
|
|
1338
|
-
result: null,
|
|
1339
|
-
error: null
|
|
1340
|
-
}
|
|
1341
|
-
},
|
|
1342
|
-
eventTimestamp: Date.now()
|
|
1343
|
-
});
|
|
1344
1242
|
if (execResults.status === "suspended") {
|
|
1345
|
-
await emitter.emit("watch
|
|
1243
|
+
await emitter.emit("watch", {
|
|
1346
1244
|
type: "workflow-step-suspended",
|
|
1347
1245
|
payload: {
|
|
1348
1246
|
id: step.id,
|
|
@@ -1350,14 +1248,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1350
1248
|
}
|
|
1351
1249
|
});
|
|
1352
1250
|
} else {
|
|
1353
|
-
await emitter.emit("watch
|
|
1251
|
+
await emitter.emit("watch", {
|
|
1354
1252
|
type: "workflow-step-result",
|
|
1355
1253
|
payload: {
|
|
1356
1254
|
id: step.id,
|
|
1357
1255
|
...execResults
|
|
1358
1256
|
}
|
|
1359
1257
|
});
|
|
1360
|
-
await emitter.emit("watch
|
|
1258
|
+
await emitter.emit("watch", {
|
|
1361
1259
|
type: "workflow-step-finish",
|
|
1362
1260
|
payload: {
|
|
1363
1261
|
id: step.id,
|
|
@@ -1365,7 +1263,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1365
1263
|
}
|
|
1366
1264
|
});
|
|
1367
1265
|
}
|
|
1368
|
-
|
|
1266
|
+
stepSpan?.end({ output: execResults });
|
|
1369
1267
|
return { result: execResults, executionContext, stepResults };
|
|
1370
1268
|
});
|
|
1371
1269
|
} catch (e) {
|
|
@@ -1395,9 +1293,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1395
1293
|
output: stepRes.result,
|
|
1396
1294
|
workflowId: executionContext.workflowId,
|
|
1397
1295
|
stepId: step.id,
|
|
1398
|
-
|
|
1296
|
+
requestContext,
|
|
1399
1297
|
disableScorers,
|
|
1400
|
-
tracingContext: { currentSpan:
|
|
1298
|
+
tracingContext: { currentSpan: stepSpan }
|
|
1401
1299
|
});
|
|
1402
1300
|
}
|
|
1403
1301
|
});
|
|
@@ -1431,14 +1329,15 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1431
1329
|
resourceId,
|
|
1432
1330
|
snapshot: {
|
|
1433
1331
|
runId,
|
|
1332
|
+
status: workflowStatus,
|
|
1434
1333
|
value: executionContext.state,
|
|
1435
1334
|
context: stepResults,
|
|
1436
|
-
activePaths:
|
|
1335
|
+
activePaths: executionContext.executionPath,
|
|
1336
|
+
activeStepsPath: executionContext.activeStepsPath,
|
|
1437
1337
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1438
1338
|
resumeLabels: executionContext.resumeLabels,
|
|
1439
1339
|
waitingPaths: {},
|
|
1440
1340
|
serializedStepGraph,
|
|
1441
|
-
status: workflowStatus,
|
|
1442
1341
|
result,
|
|
1443
1342
|
error,
|
|
1444
1343
|
// @ts-ignore
|
|
@@ -1453,20 +1352,18 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1453
1352
|
runId,
|
|
1454
1353
|
entry,
|
|
1455
1354
|
prevOutput,
|
|
1456
|
-
prevStep,
|
|
1457
1355
|
stepResults,
|
|
1458
|
-
serializedStepGraph,
|
|
1459
1356
|
resume,
|
|
1460
1357
|
executionContext,
|
|
1461
1358
|
emitter,
|
|
1462
1359
|
abortController,
|
|
1463
|
-
|
|
1360
|
+
requestContext,
|
|
1464
1361
|
writableStream,
|
|
1465
1362
|
disableScorers,
|
|
1466
1363
|
tracingContext
|
|
1467
1364
|
}) {
|
|
1468
1365
|
const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
1469
|
-
type:
|
|
1366
|
+
type: observability.SpanType.WORKFLOW_CONDITIONAL,
|
|
1470
1367
|
name: `conditional: '${entry.conditions.length} conditions'`,
|
|
1471
1368
|
input: prevOutput,
|
|
1472
1369
|
attributes: {
|
|
@@ -1479,7 +1376,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1479
1376
|
entry.conditions.map(
|
|
1480
1377
|
(cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
|
|
1481
1378
|
const evalSpan = conditionalSpan?.createChildSpan({
|
|
1482
|
-
type:
|
|
1379
|
+
type: observability.SpanType.WORKFLOW_CONDITIONAL_EVAL,
|
|
1483
1380
|
name: `condition: '${index}'`,
|
|
1484
1381
|
input: prevOutput,
|
|
1485
1382
|
attributes: {
|
|
@@ -1494,8 +1391,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1494
1391
|
runId,
|
|
1495
1392
|
workflowId,
|
|
1496
1393
|
mastra: this.mastra,
|
|
1497
|
-
|
|
1498
|
-
runCount: -1,
|
|
1394
|
+
requestContext,
|
|
1499
1395
|
retryCount: -1,
|
|
1500
1396
|
inputData: prevOutput,
|
|
1501
1397
|
state: executionContext.state,
|
|
@@ -1517,7 +1413,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1517
1413
|
},
|
|
1518
1414
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1519
1415
|
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1520
|
-
// TODO: add streamVNext support
|
|
1521
1416
|
engine: {
|
|
1522
1417
|
step: this.inngestStep
|
|
1523
1418
|
},
|
|
@@ -1566,19 +1461,21 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1566
1461
|
}
|
|
1567
1462
|
});
|
|
1568
1463
|
const results = await Promise.all(
|
|
1569
|
-
stepsToRun.map(
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1464
|
+
stepsToRun.map(async (step, index) => {
|
|
1465
|
+
const currStepResult = stepResults[step.step.id];
|
|
1466
|
+
if (currStepResult && currStepResult.status === "success") {
|
|
1467
|
+
return currStepResult;
|
|
1468
|
+
}
|
|
1469
|
+
const result = await this.executeStep({
|
|
1470
|
+
step: step.step,
|
|
1471
|
+
prevOutput,
|
|
1576
1472
|
stepResults,
|
|
1577
1473
|
resume,
|
|
1578
1474
|
executionContext: {
|
|
1579
1475
|
workflowId,
|
|
1580
1476
|
runId,
|
|
1581
1477
|
executionPath: [...executionContext.executionPath, index],
|
|
1478
|
+
activeStepsPath: executionContext.activeStepsPath,
|
|
1582
1479
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1583
1480
|
resumeLabels: executionContext.resumeLabels,
|
|
1584
1481
|
retryConfig: executionContext.retryConfig,
|
|
@@ -1586,26 +1483,32 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1586
1483
|
},
|
|
1587
1484
|
emitter,
|
|
1588
1485
|
abortController,
|
|
1589
|
-
|
|
1486
|
+
requestContext,
|
|
1590
1487
|
writableStream,
|
|
1591
1488
|
disableScorers,
|
|
1592
1489
|
tracingContext: {
|
|
1593
1490
|
currentSpan: conditionalSpan
|
|
1594
1491
|
}
|
|
1595
|
-
})
|
|
1596
|
-
|
|
1492
|
+
});
|
|
1493
|
+
stepResults[step.step.id] = result;
|
|
1494
|
+
return result;
|
|
1495
|
+
})
|
|
1597
1496
|
);
|
|
1598
|
-
const hasFailed = results.find((result) => result.
|
|
1599
|
-
const hasSuspended = results.find((result) => result.
|
|
1497
|
+
const hasFailed = results.find((result) => result.status === "failed");
|
|
1498
|
+
const hasSuspended = results.find((result) => result.status === "suspended");
|
|
1600
1499
|
if (hasFailed) {
|
|
1601
|
-
execResults = { status: "failed", error: hasFailed.
|
|
1500
|
+
execResults = { status: "failed", error: hasFailed.error };
|
|
1602
1501
|
} else if (hasSuspended) {
|
|
1603
|
-
execResults = {
|
|
1502
|
+
execResults = {
|
|
1503
|
+
status: "suspended",
|
|
1504
|
+
suspendPayload: hasSuspended.suspendPayload,
|
|
1505
|
+
...hasSuspended.suspendOutput ? { suspendOutput: hasSuspended.suspendOutput } : {}
|
|
1506
|
+
};
|
|
1604
1507
|
} else {
|
|
1605
1508
|
execResults = {
|
|
1606
1509
|
status: "success",
|
|
1607
1510
|
output: results.reduce((acc, result, index) => {
|
|
1608
|
-
if (result.
|
|
1511
|
+
if (result.status === "success") {
|
|
1609
1512
|
acc[stepsToRun[index].step.id] = result.output;
|
|
1610
1513
|
}
|
|
1611
1514
|
return acc;
|