@mastra/inngest 0.0.0-new-scorer-api-20250801075530 → 0.0.0-rag-chunk-extract-llm-option-20250926183645
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 +444 -3
- package/dist/index.cjs +281 -184
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +52 -39
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +283 -186
- package/dist/index.js.map +1 -1
- package/package.json +28 -14
- package/docker-compose.yaml +0 -10
- package/eslint.config.js +0 -6
- package/src/index.test.ts +0 -7815
- package/src/index.ts +0 -1784
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -5
- package/tsup.config.ts +0 -22
- package/vitest.config.ts +0 -14
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var crypto = require('crypto');
|
|
4
4
|
var realtime = require('@inngest/realtime');
|
|
5
|
+
var aiTracing = require('@mastra/core/ai-tracing');
|
|
5
6
|
var di = require('@mastra/core/di');
|
|
6
7
|
var tools = require('@mastra/core/tools');
|
|
7
8
|
var workflows = require('@mastra/core/workflows');
|
|
@@ -10,9 +11,14 @@ var hono = require('inngest/hono');
|
|
|
10
11
|
var zod = require('zod');
|
|
11
12
|
|
|
12
13
|
// src/index.ts
|
|
13
|
-
function serve({
|
|
14
|
+
function serve({
|
|
15
|
+
mastra,
|
|
16
|
+
inngest,
|
|
17
|
+
functions: userFunctions = [],
|
|
18
|
+
registerOptions
|
|
19
|
+
}) {
|
|
14
20
|
const wfs = mastra.getWorkflows();
|
|
15
|
-
const
|
|
21
|
+
const workflowFunctions = Array.from(
|
|
16
22
|
new Set(
|
|
17
23
|
Object.values(wfs).flatMap((wf) => {
|
|
18
24
|
if (wf instanceof InngestWorkflow) {
|
|
@@ -24,8 +30,9 @@ function serve({ mastra, inngest }) {
|
|
|
24
30
|
)
|
|
25
31
|
);
|
|
26
32
|
return hono.serve({
|
|
33
|
+
...registerOptions,
|
|
27
34
|
client: inngest,
|
|
28
|
-
functions
|
|
35
|
+
functions: [...workflowFunctions, ...userFunctions]
|
|
29
36
|
});
|
|
30
37
|
}
|
|
31
38
|
var InngestRun = class extends workflows.Run {
|
|
@@ -53,7 +60,6 @@ var InngestRun = class extends workflows.Run {
|
|
|
53
60
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
54
61
|
runs = await this.getRuns(eventId);
|
|
55
62
|
if (runs?.[0]?.status === "Failed") {
|
|
56
|
-
console.log("run", runs?.[0]);
|
|
57
63
|
throw new Error(`Function run ${runs?.[0]?.status}`);
|
|
58
64
|
} else if (runs?.[0]?.status === "Cancelled") {
|
|
59
65
|
const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
|
|
@@ -86,6 +92,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
86
92
|
await this.#mastra?.storage?.persistWorkflowSnapshot({
|
|
87
93
|
workflowName: this.workflowId,
|
|
88
94
|
runId: this.runId,
|
|
95
|
+
resourceId: this.resourceId,
|
|
89
96
|
snapshot: {
|
|
90
97
|
...snapshot,
|
|
91
98
|
status: "canceled"
|
|
@@ -99,6 +106,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
99
106
|
await this.#mastra.getStorage()?.persistWorkflowSnapshot({
|
|
100
107
|
workflowName: this.workflowId,
|
|
101
108
|
runId: this.runId,
|
|
109
|
+
resourceId: this.resourceId,
|
|
102
110
|
snapshot: {
|
|
103
111
|
runId: this.runId,
|
|
104
112
|
serializedStepGraph: this.serializedStepGraph,
|
|
@@ -106,15 +114,18 @@ var InngestRun = class extends workflows.Run {
|
|
|
106
114
|
context: {},
|
|
107
115
|
activePaths: [],
|
|
108
116
|
suspendedPaths: {},
|
|
117
|
+
waitingPaths: {},
|
|
109
118
|
timestamp: Date.now(),
|
|
110
119
|
status: "running"
|
|
111
120
|
}
|
|
112
121
|
});
|
|
122
|
+
const inputDataToUse = await this._validateInput(inputData);
|
|
113
123
|
const eventOutput = await this.inngest.send({
|
|
114
124
|
name: `workflow.${this.workflowId}`,
|
|
115
125
|
data: {
|
|
116
|
-
inputData,
|
|
117
|
-
runId: this.runId
|
|
126
|
+
inputData: inputDataToUse,
|
|
127
|
+
runId: this.runId,
|
|
128
|
+
resourceId: this.resourceId
|
|
118
129
|
}
|
|
119
130
|
});
|
|
120
131
|
const eventId = eventOutput.ids[0];
|
|
@@ -150,17 +161,19 @@ var InngestRun = class extends workflows.Run {
|
|
|
150
161
|
workflowName: this.workflowId,
|
|
151
162
|
runId: this.runId
|
|
152
163
|
});
|
|
164
|
+
const suspendedStep = this.workflowSteps[steps?.[0] ?? ""];
|
|
165
|
+
const resumeDataToUse = await this._validateResumeData(params.resumeData, suspendedStep);
|
|
153
166
|
const eventOutput = await this.inngest.send({
|
|
154
167
|
name: `workflow.${this.workflowId}`,
|
|
155
168
|
data: {
|
|
156
|
-
inputData:
|
|
169
|
+
inputData: resumeDataToUse,
|
|
157
170
|
runId: this.runId,
|
|
158
171
|
workflowId: this.workflowId,
|
|
159
172
|
stepResults: snapshot?.context,
|
|
160
173
|
resume: {
|
|
161
174
|
steps,
|
|
162
175
|
stepResults: snapshot?.context,
|
|
163
|
-
resumePayload:
|
|
176
|
+
resumePayload: resumeDataToUse,
|
|
164
177
|
// @ts-ignore
|
|
165
178
|
resumePath: snapshot?.suspendedPaths?.[steps?.[0]]
|
|
166
179
|
}
|
|
@@ -205,7 +218,11 @@ var InngestRun = class extends workflows.Run {
|
|
|
205
218
|
const writer = writable.getWriter();
|
|
206
219
|
const unwatch = this.watch(async (event) => {
|
|
207
220
|
try {
|
|
208
|
-
|
|
221
|
+
const e = {
|
|
222
|
+
...event,
|
|
223
|
+
type: event.type.replace("workflow-", "")
|
|
224
|
+
};
|
|
225
|
+
await writer.write(e);
|
|
209
226
|
} catch {
|
|
210
227
|
}
|
|
211
228
|
}, "watch-v2");
|
|
@@ -236,8 +253,14 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
236
253
|
#mastra;
|
|
237
254
|
inngest;
|
|
238
255
|
function;
|
|
256
|
+
flowControlConfig;
|
|
239
257
|
constructor(params, inngest) {
|
|
240
|
-
|
|
258
|
+
const { concurrency, rateLimit, throttle, debounce, priority, ...workflowParams } = params;
|
|
259
|
+
super(workflowParams);
|
|
260
|
+
const flowControlEntries = Object.entries({ concurrency, rateLimit, throttle, debounce, priority }).filter(
|
|
261
|
+
([_, value]) => value !== void 0
|
|
262
|
+
);
|
|
263
|
+
this.flowControlConfig = flowControlEntries.length > 0 ? Object.fromEntries(flowControlEntries) : void 0;
|
|
241
264
|
this.#mastra = params.mastra;
|
|
242
265
|
this.inngest = inngest;
|
|
243
266
|
}
|
|
@@ -258,27 +281,6 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
258
281
|
const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
|
|
259
282
|
return run ?? (this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null);
|
|
260
283
|
}
|
|
261
|
-
async getWorkflowRunExecutionResult(runId) {
|
|
262
|
-
const storage = this.#mastra?.getStorage();
|
|
263
|
-
if (!storage) {
|
|
264
|
-
this.logger.debug("Cannot get workflow run execution result. Mastra storage is not initialized");
|
|
265
|
-
return null;
|
|
266
|
-
}
|
|
267
|
-
const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
|
|
268
|
-
if (!run?.snapshot) {
|
|
269
|
-
return null;
|
|
270
|
-
}
|
|
271
|
-
if (typeof run.snapshot === "string") {
|
|
272
|
-
return null;
|
|
273
|
-
}
|
|
274
|
-
return {
|
|
275
|
-
status: run.snapshot.status,
|
|
276
|
-
result: run.snapshot.result,
|
|
277
|
-
error: run.snapshot.error,
|
|
278
|
-
payload: run.snapshot.context?.input,
|
|
279
|
-
steps: run.snapshot.context
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
284
|
__registerMastra(mastra) {
|
|
283
285
|
this.#mastra = mastra;
|
|
284
286
|
this.executionEngine.__registerMastra(mastra);
|
|
@@ -297,23 +299,14 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
297
299
|
}
|
|
298
300
|
}
|
|
299
301
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
executionGraph: this.executionGraph,
|
|
308
|
-
serializedStepGraph: this.serializedStepGraph,
|
|
309
|
-
mastra: this.#mastra,
|
|
310
|
-
retryConfig: this.retryConfig,
|
|
311
|
-
cleanup: () => this.runs.delete(runIdToUse)
|
|
312
|
-
},
|
|
313
|
-
this.inngest
|
|
302
|
+
/**
|
|
303
|
+
* @deprecated Use createRunAsync() instead.
|
|
304
|
+
* @throws {Error} Always throws an error directing users to use createRunAsync()
|
|
305
|
+
*/
|
|
306
|
+
createRun(_options) {
|
|
307
|
+
throw new Error(
|
|
308
|
+
"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."
|
|
314
309
|
);
|
|
315
|
-
this.runs.set(runIdToUse, run);
|
|
316
|
-
return run;
|
|
317
310
|
}
|
|
318
311
|
async createRunAsync(options) {
|
|
319
312
|
const runIdToUse = options?.runId || crypto.randomUUID();
|
|
@@ -321,27 +314,31 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
321
314
|
{
|
|
322
315
|
workflowId: this.id,
|
|
323
316
|
runId: runIdToUse,
|
|
317
|
+
resourceId: options?.resourceId,
|
|
324
318
|
executionEngine: this.executionEngine,
|
|
325
319
|
executionGraph: this.executionGraph,
|
|
326
320
|
serializedStepGraph: this.serializedStepGraph,
|
|
327
321
|
mastra: this.#mastra,
|
|
328
322
|
retryConfig: this.retryConfig,
|
|
329
|
-
cleanup: () => this.runs.delete(runIdToUse)
|
|
323
|
+
cleanup: () => this.runs.delete(runIdToUse),
|
|
324
|
+
workflowSteps: this.steps
|
|
330
325
|
},
|
|
331
326
|
this.inngest
|
|
332
327
|
);
|
|
333
328
|
this.runs.set(runIdToUse, run);
|
|
334
|
-
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse);
|
|
329
|
+
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, false);
|
|
335
330
|
if (!workflowSnapshotInStorage) {
|
|
336
331
|
await this.mastra?.getStorage()?.persistWorkflowSnapshot({
|
|
337
332
|
workflowName: this.id,
|
|
338
333
|
runId: runIdToUse,
|
|
334
|
+
resourceId: options?.resourceId,
|
|
339
335
|
snapshot: {
|
|
340
336
|
runId: runIdToUse,
|
|
341
337
|
status: "pending",
|
|
342
338
|
value: {},
|
|
343
339
|
context: {},
|
|
344
340
|
activePaths: [],
|
|
341
|
+
waitingPaths: {},
|
|
345
342
|
serializedStepGraph: this.serializedStepGraph,
|
|
346
343
|
suspendedPaths: {},
|
|
347
344
|
result: void 0,
|
|
@@ -362,11 +359,13 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
362
359
|
id: `workflow.${this.id}`,
|
|
363
360
|
// @ts-ignore
|
|
364
361
|
retries: this.retryConfig?.attempts ?? 0,
|
|
365
|
-
cancelOn: [{ event: `cancel.workflow.${this.id}` }]
|
|
362
|
+
cancelOn: [{ event: `cancel.workflow.${this.id}` }],
|
|
363
|
+
// Spread flow control configuration
|
|
364
|
+
...this.flowControlConfig
|
|
366
365
|
},
|
|
367
366
|
{ event: `workflow.${this.id}` },
|
|
368
367
|
async ({ event, step, attempt, publish }) => {
|
|
369
|
-
let { inputData, runId, resume } = event.data;
|
|
368
|
+
let { inputData, runId, resourceId, resume } = event.data;
|
|
370
369
|
if (!runId) {
|
|
371
370
|
runId = await step.run(`workflow.${this.id}.runIdGen`, async () => {
|
|
372
371
|
return crypto.randomUUID();
|
|
@@ -398,6 +397,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
398
397
|
const result = await engine.execute({
|
|
399
398
|
workflowId: this.id,
|
|
400
399
|
runId,
|
|
400
|
+
resourceId,
|
|
401
401
|
graph: this.executionGraph,
|
|
402
402
|
serializedStepGraph: this.serializedStepGraph,
|
|
403
403
|
input: inputData,
|
|
@@ -406,7 +406,9 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
406
406
|
runtimeContext: new di.RuntimeContext(),
|
|
407
407
|
// TODO
|
|
408
408
|
resume,
|
|
409
|
-
abortController: new AbortController()
|
|
409
|
+
abortController: new AbortController(),
|
|
410
|
+
currentSpan: void 0
|
|
411
|
+
// TODO: Pass actual parent AI span from workflow execution context
|
|
410
412
|
});
|
|
411
413
|
return { result, runId };
|
|
412
414
|
}
|
|
@@ -440,17 +442,16 @@ function createStep(params) {
|
|
|
440
442
|
if (isAgent(params)) {
|
|
441
443
|
return {
|
|
442
444
|
id: params.name,
|
|
445
|
+
description: params.getDescription(),
|
|
443
446
|
// @ts-ignore
|
|
444
447
|
inputSchema: zod.z.object({
|
|
445
448
|
prompt: zod.z.string()
|
|
446
|
-
// resourceId: z.string().optional(),
|
|
447
|
-
// threadId: z.string().optional(),
|
|
448
449
|
}),
|
|
449
450
|
// @ts-ignore
|
|
450
451
|
outputSchema: zod.z.object({
|
|
451
452
|
text: zod.z.string()
|
|
452
453
|
}),
|
|
453
|
-
execute: async ({ inputData, [_constants.EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort }) => {
|
|
454
|
+
execute: async ({ inputData, [_constants.EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort, tracingContext }) => {
|
|
454
455
|
let streamPromise = {};
|
|
455
456
|
streamPromise.promise = new Promise((resolve, reject) => {
|
|
456
457
|
streamPromise.resolve = resolve;
|
|
@@ -460,14 +461,9 @@ function createStep(params) {
|
|
|
460
461
|
name: params.name,
|
|
461
462
|
args: inputData
|
|
462
463
|
};
|
|
463
|
-
await emitter.emit("watch-v2", {
|
|
464
|
-
type: "tool-call-streaming-start",
|
|
465
|
-
...toolData
|
|
466
|
-
});
|
|
467
464
|
const { fullStream } = await params.stream(inputData.prompt, {
|
|
468
|
-
// resourceId: inputData.resourceId,
|
|
469
|
-
// threadId: inputData.threadId,
|
|
470
465
|
runtimeContext,
|
|
466
|
+
tracingContext,
|
|
471
467
|
onFinish: (result) => {
|
|
472
468
|
streamPromise.resolve(result.text);
|
|
473
469
|
},
|
|
@@ -476,34 +472,28 @@ function createStep(params) {
|
|
|
476
472
|
if (abortSignal.aborted) {
|
|
477
473
|
return abort();
|
|
478
474
|
}
|
|
475
|
+
await emitter.emit("watch-v2", {
|
|
476
|
+
type: "tool-call-streaming-start",
|
|
477
|
+
...toolData ?? {}
|
|
478
|
+
});
|
|
479
479
|
for await (const chunk of fullStream) {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
});
|
|
487
|
-
break;
|
|
488
|
-
case "step-start":
|
|
489
|
-
case "step-finish":
|
|
490
|
-
case "finish":
|
|
491
|
-
break;
|
|
492
|
-
case "tool-call":
|
|
493
|
-
case "tool-result":
|
|
494
|
-
case "tool-call-streaming-start":
|
|
495
|
-
case "tool-call-delta":
|
|
496
|
-
case "source":
|
|
497
|
-
case "file":
|
|
498
|
-
default:
|
|
499
|
-
await emitter.emit("watch-v2", chunk);
|
|
500
|
-
break;
|
|
480
|
+
if (chunk.type === "text-delta") {
|
|
481
|
+
await emitter.emit("watch-v2", {
|
|
482
|
+
type: "tool-call-delta",
|
|
483
|
+
...toolData ?? {},
|
|
484
|
+
argsTextDelta: chunk.textDelta
|
|
485
|
+
});
|
|
501
486
|
}
|
|
502
487
|
}
|
|
488
|
+
await emitter.emit("watch-v2", {
|
|
489
|
+
type: "tool-call-streaming-finish",
|
|
490
|
+
...toolData ?? {}
|
|
491
|
+
});
|
|
503
492
|
return {
|
|
504
493
|
text: await streamPromise.promise
|
|
505
494
|
};
|
|
506
|
-
}
|
|
495
|
+
},
|
|
496
|
+
component: params.component
|
|
507
497
|
};
|
|
508
498
|
}
|
|
509
499
|
if (isTool(params)) {
|
|
@@ -514,15 +504,20 @@ function createStep(params) {
|
|
|
514
504
|
// TODO: tool probably should have strong id type
|
|
515
505
|
// @ts-ignore
|
|
516
506
|
id: params.id,
|
|
507
|
+
description: params.description,
|
|
517
508
|
inputSchema: params.inputSchema,
|
|
518
509
|
outputSchema: params.outputSchema,
|
|
519
|
-
execute: async ({ inputData, mastra, runtimeContext }) => {
|
|
510
|
+
execute: async ({ inputData, mastra, runtimeContext, tracingContext, suspend, resumeData }) => {
|
|
520
511
|
return params.execute({
|
|
521
512
|
context: inputData,
|
|
522
|
-
mastra,
|
|
523
|
-
runtimeContext
|
|
513
|
+
mastra: aiTracing.wrapMastra(mastra, tracingContext),
|
|
514
|
+
runtimeContext,
|
|
515
|
+
tracingContext,
|
|
516
|
+
suspend,
|
|
517
|
+
resumeData
|
|
524
518
|
});
|
|
525
|
-
}
|
|
519
|
+
},
|
|
520
|
+
component: "TOOL"
|
|
526
521
|
};
|
|
527
522
|
}
|
|
528
523
|
return {
|
|
@@ -547,7 +542,8 @@ function init(inngest) {
|
|
|
547
542
|
description: step.description,
|
|
548
543
|
inputSchema: step.inputSchema,
|
|
549
544
|
outputSchema: step.outputSchema,
|
|
550
|
-
execute: step.execute
|
|
545
|
+
execute: step.execute,
|
|
546
|
+
component: step.component
|
|
551
547
|
};
|
|
552
548
|
},
|
|
553
549
|
cloneWorkflow(workflow, opts) {
|
|
@@ -567,19 +563,19 @@ function init(inngest) {
|
|
|
567
563
|
var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
568
564
|
inngestStep;
|
|
569
565
|
inngestAttempts;
|
|
570
|
-
constructor(mastra, inngestStep, inngestAttempts = 0) {
|
|
571
|
-
super({ mastra });
|
|
566
|
+
constructor(mastra, inngestStep, inngestAttempts = 0, options) {
|
|
567
|
+
super({ mastra, options });
|
|
572
568
|
this.inngestStep = inngestStep;
|
|
573
569
|
this.inngestAttempts = inngestAttempts;
|
|
574
570
|
}
|
|
575
571
|
async execute(params) {
|
|
576
572
|
await params.emitter.emit("watch-v2", {
|
|
577
|
-
type: "start",
|
|
573
|
+
type: "workflow-start",
|
|
578
574
|
payload: { runId: params.runId }
|
|
579
575
|
});
|
|
580
576
|
const result = await super.execute(params);
|
|
581
577
|
await params.emitter.emit("watch-v2", {
|
|
582
|
-
type: "finish",
|
|
578
|
+
type: "workflow-finish",
|
|
583
579
|
payload: { runId: params.runId }
|
|
584
580
|
});
|
|
585
581
|
return result;
|
|
@@ -641,33 +637,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
641
637
|
executionSpan?.end();
|
|
642
638
|
return base;
|
|
643
639
|
}
|
|
644
|
-
async superExecuteStep({
|
|
645
|
-
workflowId,
|
|
646
|
-
runId,
|
|
647
|
-
step,
|
|
648
|
-
stepResults,
|
|
649
|
-
executionContext,
|
|
650
|
-
resume,
|
|
651
|
-
prevOutput,
|
|
652
|
-
emitter,
|
|
653
|
-
abortController,
|
|
654
|
-
runtimeContext,
|
|
655
|
-
writableStream
|
|
656
|
-
}) {
|
|
657
|
-
return super.executeStep({
|
|
658
|
-
workflowId,
|
|
659
|
-
runId,
|
|
660
|
-
step,
|
|
661
|
-
stepResults,
|
|
662
|
-
executionContext,
|
|
663
|
-
resume,
|
|
664
|
-
prevOutput,
|
|
665
|
-
emitter,
|
|
666
|
-
abortController,
|
|
667
|
-
runtimeContext,
|
|
668
|
-
writableStream
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
640
|
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
672
641
|
// await this.inngestStep.sleep(id, duration);
|
|
673
642
|
// }
|
|
@@ -680,9 +649,20 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
680
649
|
emitter,
|
|
681
650
|
abortController,
|
|
682
651
|
runtimeContext,
|
|
683
|
-
|
|
652
|
+
executionContext,
|
|
653
|
+
writableStream,
|
|
654
|
+
tracingContext
|
|
684
655
|
}) {
|
|
685
656
|
let { duration, fn } = entry;
|
|
657
|
+
const sleepSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
658
|
+
type: aiTracing.AISpanType.WORKFLOW_SLEEP,
|
|
659
|
+
name: `sleep: ${duration ? `${duration}ms` : "dynamic"}`,
|
|
660
|
+
attributes: {
|
|
661
|
+
durationMs: duration,
|
|
662
|
+
sleepType: fn ? "dynamic" : "fixed"
|
|
663
|
+
},
|
|
664
|
+
tracingPolicy: this.options?.tracingPolicy
|
|
665
|
+
});
|
|
686
666
|
if (fn) {
|
|
687
667
|
const stepCallId = crypto.randomUUID();
|
|
688
668
|
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
@@ -693,17 +673,11 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
693
673
|
runtimeContext,
|
|
694
674
|
inputData: prevOutput,
|
|
695
675
|
runCount: -1,
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
if (!step?.id) {
|
|
699
|
-
return null;
|
|
700
|
-
}
|
|
701
|
-
const result = stepResults[step.id];
|
|
702
|
-
if (result?.status === "success") {
|
|
703
|
-
return result.output;
|
|
704
|
-
}
|
|
705
|
-
return null;
|
|
676
|
+
tracingContext: {
|
|
677
|
+
currentSpan: sleepSpan
|
|
706
678
|
},
|
|
679
|
+
getInitData: () => stepResults?.input,
|
|
680
|
+
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
707
681
|
// TODO: this function shouldn't have suspend probably?
|
|
708
682
|
suspend: async (_suspendPayload) => {
|
|
709
683
|
},
|
|
@@ -713,11 +687,13 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
713
687
|
abortController?.abort();
|
|
714
688
|
},
|
|
715
689
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
690
|
+
// TODO: add streamVNext support
|
|
691
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
716
692
|
engine: { step: this.inngestStep },
|
|
717
693
|
abortSignal: abortController?.signal,
|
|
718
694
|
writer: new tools.ToolStream(
|
|
719
695
|
{
|
|
720
|
-
prefix: "step",
|
|
696
|
+
prefix: "workflow-step",
|
|
721
697
|
callId: stepCallId,
|
|
722
698
|
name: "sleep",
|
|
723
699
|
runId
|
|
@@ -726,8 +702,19 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
726
702
|
)
|
|
727
703
|
});
|
|
728
704
|
});
|
|
705
|
+
sleepSpan?.update({
|
|
706
|
+
attributes: {
|
|
707
|
+
durationMs: duration
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
try {
|
|
712
|
+
await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
|
|
713
|
+
sleepSpan?.end();
|
|
714
|
+
} catch (e) {
|
|
715
|
+
sleepSpan?.error({ error: e });
|
|
716
|
+
throw e;
|
|
729
717
|
}
|
|
730
|
-
await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
|
|
731
718
|
}
|
|
732
719
|
async executeSleepUntil({
|
|
733
720
|
workflowId,
|
|
@@ -738,9 +725,21 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
738
725
|
emitter,
|
|
739
726
|
abortController,
|
|
740
727
|
runtimeContext,
|
|
741
|
-
|
|
728
|
+
executionContext,
|
|
729
|
+
writableStream,
|
|
730
|
+
tracingContext
|
|
742
731
|
}) {
|
|
743
732
|
let { date, fn } = entry;
|
|
733
|
+
const sleepUntilSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
734
|
+
type: aiTracing.AISpanType.WORKFLOW_SLEEP,
|
|
735
|
+
name: `sleepUntil: ${date ? date.toISOString() : "dynamic"}`,
|
|
736
|
+
attributes: {
|
|
737
|
+
untilDate: date,
|
|
738
|
+
durationMs: date ? Math.max(0, date.getTime() - Date.now()) : void 0,
|
|
739
|
+
sleepType: fn ? "dynamic" : "fixed"
|
|
740
|
+
},
|
|
741
|
+
tracingPolicy: this.options?.tracingPolicy
|
|
742
|
+
});
|
|
744
743
|
if (fn) {
|
|
745
744
|
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
746
745
|
const stepCallId = crypto.randomUUID();
|
|
@@ -751,17 +750,11 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
751
750
|
runtimeContext,
|
|
752
751
|
inputData: prevOutput,
|
|
753
752
|
runCount: -1,
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
if (!step?.id) {
|
|
757
|
-
return null;
|
|
758
|
-
}
|
|
759
|
-
const result = stepResults[step.id];
|
|
760
|
-
if (result?.status === "success") {
|
|
761
|
-
return result.output;
|
|
762
|
-
}
|
|
763
|
-
return null;
|
|
753
|
+
tracingContext: {
|
|
754
|
+
currentSpan: sleepUntilSpan
|
|
764
755
|
},
|
|
756
|
+
getInitData: () => stepResults?.input,
|
|
757
|
+
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
765
758
|
// TODO: this function shouldn't have suspend probably?
|
|
766
759
|
suspend: async (_suspendPayload) => {
|
|
767
760
|
},
|
|
@@ -771,11 +764,13 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
771
764
|
abortController?.abort();
|
|
772
765
|
},
|
|
773
766
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
767
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
768
|
+
// TODO: add streamVNext support
|
|
774
769
|
engine: { step: this.inngestStep },
|
|
775
770
|
abortSignal: abortController?.signal,
|
|
776
771
|
writer: new tools.ToolStream(
|
|
777
772
|
{
|
|
778
|
-
prefix: "step",
|
|
773
|
+
prefix: "workflow-step",
|
|
779
774
|
callId: stepCallId,
|
|
780
775
|
name: "sleep",
|
|
781
776
|
runId
|
|
@@ -784,11 +779,27 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
784
779
|
)
|
|
785
780
|
});
|
|
786
781
|
});
|
|
782
|
+
if (date && !(date instanceof Date)) {
|
|
783
|
+
date = new Date(date);
|
|
784
|
+
}
|
|
785
|
+
const time = !date ? 0 : date.getTime() - Date.now();
|
|
786
|
+
sleepUntilSpan?.update({
|
|
787
|
+
attributes: {
|
|
788
|
+
durationMs: Math.max(0, time)
|
|
789
|
+
}
|
|
790
|
+
});
|
|
787
791
|
}
|
|
788
792
|
if (!(date instanceof Date)) {
|
|
793
|
+
sleepUntilSpan?.end();
|
|
789
794
|
return;
|
|
790
795
|
}
|
|
791
|
-
|
|
796
|
+
try {
|
|
797
|
+
await this.inngestStep.sleepUntil(entry.id, date);
|
|
798
|
+
sleepUntilSpan?.end();
|
|
799
|
+
} catch (e) {
|
|
800
|
+
sleepUntilSpan?.error({ error: e });
|
|
801
|
+
throw e;
|
|
802
|
+
}
|
|
792
803
|
}
|
|
793
804
|
async executeWaitForEvent({ event, timeout }) {
|
|
794
805
|
const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
|
|
@@ -809,8 +820,24 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
809
820
|
emitter,
|
|
810
821
|
abortController,
|
|
811
822
|
runtimeContext,
|
|
812
|
-
|
|
823
|
+
tracingContext,
|
|
824
|
+
writableStream,
|
|
825
|
+
disableScorers
|
|
813
826
|
}) {
|
|
827
|
+
const stepAISpan = tracingContext?.currentSpan?.createChildSpan({
|
|
828
|
+
name: `workflow step: '${step.id}'`,
|
|
829
|
+
type: aiTracing.AISpanType.WORKFLOW_STEP,
|
|
830
|
+
input: prevOutput,
|
|
831
|
+
attributes: {
|
|
832
|
+
stepId: step.id
|
|
833
|
+
},
|
|
834
|
+
tracingPolicy: this.options?.tracingPolicy
|
|
835
|
+
});
|
|
836
|
+
const { inputData, validationError } = await workflows.validateStepInput({
|
|
837
|
+
prevOutput,
|
|
838
|
+
step,
|
|
839
|
+
validateInputs: this.options?.validateInputs ?? false
|
|
840
|
+
});
|
|
814
841
|
const startedAt = await this.inngestStep.run(
|
|
815
842
|
`workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
|
|
816
843
|
async () => {
|
|
@@ -837,11 +864,11 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
837
864
|
eventTimestamp: Date.now()
|
|
838
865
|
});
|
|
839
866
|
await emitter.emit("watch-v2", {
|
|
840
|
-
type: "step-start",
|
|
867
|
+
type: "workflow-step-start",
|
|
841
868
|
payload: {
|
|
842
869
|
id: step.id,
|
|
843
870
|
status: "running",
|
|
844
|
-
payload:
|
|
871
|
+
payload: inputData,
|
|
845
872
|
startedAt: startedAt2
|
|
846
873
|
}
|
|
847
874
|
});
|
|
@@ -861,7 +888,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
861
888
|
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
862
889
|
function: step.getFunction(),
|
|
863
890
|
data: {
|
|
864
|
-
inputData
|
|
891
|
+
inputData,
|
|
865
892
|
runId,
|
|
866
893
|
resume: {
|
|
867
894
|
runId,
|
|
@@ -879,7 +906,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
879
906
|
const invokeResp = await this.inngestStep.invoke(`workflow.${executionContext.workflowId}.step.${step.id}`, {
|
|
880
907
|
function: step.getFunction(),
|
|
881
908
|
data: {
|
|
882
|
-
inputData
|
|
909
|
+
inputData
|
|
883
910
|
}
|
|
884
911
|
});
|
|
885
912
|
result = invokeResp.result;
|
|
@@ -907,7 +934,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
907
934
|
eventTimestamp: Date.now()
|
|
908
935
|
});
|
|
909
936
|
await emitter.emit("watch-v2", {
|
|
910
|
-
type: "step-result",
|
|
937
|
+
type: "workflow-step-result",
|
|
911
938
|
payload: {
|
|
912
939
|
id: step.id,
|
|
913
940
|
status: "failed",
|
|
@@ -942,7 +969,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
942
969
|
eventTimestamp: Date.now()
|
|
943
970
|
});
|
|
944
971
|
await emitter.emit("watch-v2", {
|
|
945
|
-
type: "step-suspended",
|
|
972
|
+
type: "workflow-step-suspended",
|
|
946
973
|
payload: {
|
|
947
974
|
id: step.id,
|
|
948
975
|
status: "suspended"
|
|
@@ -999,7 +1026,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
999
1026
|
eventTimestamp: Date.now()
|
|
1000
1027
|
});
|
|
1001
1028
|
await emitter.emit("watch-v2", {
|
|
1002
|
-
type: "step-result",
|
|
1029
|
+
type: "workflow-step-result",
|
|
1003
1030
|
payload: {
|
|
1004
1031
|
id: step.id,
|
|
1005
1032
|
status: "success",
|
|
@@ -1007,7 +1034,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1007
1034
|
}
|
|
1008
1035
|
});
|
|
1009
1036
|
await emitter.emit("watch-v2", {
|
|
1010
|
-
type: "step-finish",
|
|
1037
|
+
type: "workflow-step-finish",
|
|
1011
1038
|
payload: {
|
|
1012
1039
|
id: step.id,
|
|
1013
1040
|
metadata: {}
|
|
@@ -1024,21 +1051,21 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1024
1051
|
let suspended;
|
|
1025
1052
|
let bailed;
|
|
1026
1053
|
try {
|
|
1054
|
+
if (validationError) {
|
|
1055
|
+
throw validationError;
|
|
1056
|
+
}
|
|
1027
1057
|
const result = await step.execute({
|
|
1028
1058
|
runId: executionContext.runId,
|
|
1029
1059
|
mastra: this.mastra,
|
|
1030
1060
|
runtimeContext,
|
|
1031
1061
|
writableStream,
|
|
1032
|
-
inputData
|
|
1062
|
+
inputData,
|
|
1033
1063
|
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
const result2 = stepResults[step2.id];
|
|
1037
|
-
if (result2?.status === "success") {
|
|
1038
|
-
return result2.output;
|
|
1039
|
-
}
|
|
1040
|
-
return null;
|
|
1064
|
+
tracingContext: {
|
|
1065
|
+
currentSpan: stepAISpan
|
|
1041
1066
|
},
|
|
1067
|
+
getInitData: () => stepResults?.input,
|
|
1068
|
+
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
1042
1069
|
suspend: async (suspendPayload) => {
|
|
1043
1070
|
executionContext.suspendedPaths[step.id] = executionContext.executionPath;
|
|
1044
1071
|
suspended = { payload: suspendPayload };
|
|
@@ -1064,14 +1091,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1064
1091
|
output: result,
|
|
1065
1092
|
startedAt,
|
|
1066
1093
|
endedAt,
|
|
1067
|
-
payload:
|
|
1094
|
+
payload: inputData,
|
|
1068
1095
|
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1069
1096
|
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1070
1097
|
};
|
|
1071
1098
|
} catch (e) {
|
|
1072
1099
|
execResults = {
|
|
1073
1100
|
status: "failed",
|
|
1074
|
-
payload:
|
|
1101
|
+
payload: inputData,
|
|
1075
1102
|
error: e instanceof Error ? e.message : String(e),
|
|
1076
1103
|
endedAt: Date.now(),
|
|
1077
1104
|
startedAt,
|
|
@@ -1083,18 +1110,20 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1083
1110
|
execResults = {
|
|
1084
1111
|
status: "suspended",
|
|
1085
1112
|
suspendedPayload: suspended.payload,
|
|
1086
|
-
payload:
|
|
1113
|
+
payload: inputData,
|
|
1087
1114
|
suspendedAt: Date.now(),
|
|
1088
1115
|
startedAt,
|
|
1089
1116
|
resumedAt: resume?.steps[0] === step.id ? startedAt : void 0,
|
|
1090
1117
|
resumePayload: resume?.steps[0] === step.id ? resume?.resumePayload : void 0
|
|
1091
1118
|
};
|
|
1092
1119
|
} else if (bailed) {
|
|
1093
|
-
execResults = { status: "bailed", output: bailed.payload, payload:
|
|
1120
|
+
execResults = { status: "bailed", output: bailed.payload, payload: inputData, endedAt: Date.now(), startedAt };
|
|
1094
1121
|
}
|
|
1095
1122
|
if (execResults.status === "failed") {
|
|
1096
1123
|
if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
|
|
1097
|
-
|
|
1124
|
+
const error = new Error(execResults.error);
|
|
1125
|
+
stepAISpan?.error({ error });
|
|
1126
|
+
throw error;
|
|
1098
1127
|
}
|
|
1099
1128
|
}
|
|
1100
1129
|
await emitter.emit("watch", {
|
|
@@ -1115,7 +1144,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1115
1144
|
});
|
|
1116
1145
|
if (execResults.status === "suspended") {
|
|
1117
1146
|
await emitter.emit("watch-v2", {
|
|
1118
|
-
type: "step-suspended",
|
|
1147
|
+
type: "workflow-step-suspended",
|
|
1119
1148
|
payload: {
|
|
1120
1149
|
id: step.id,
|
|
1121
1150
|
...execResults
|
|
@@ -1123,22 +1152,40 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1123
1152
|
});
|
|
1124
1153
|
} else {
|
|
1125
1154
|
await emitter.emit("watch-v2", {
|
|
1126
|
-
type: "step-result",
|
|
1155
|
+
type: "workflow-step-result",
|
|
1127
1156
|
payload: {
|
|
1128
1157
|
id: step.id,
|
|
1129
1158
|
...execResults
|
|
1130
1159
|
}
|
|
1131
1160
|
});
|
|
1132
1161
|
await emitter.emit("watch-v2", {
|
|
1133
|
-
type: "step-finish",
|
|
1162
|
+
type: "workflow-step-finish",
|
|
1134
1163
|
payload: {
|
|
1135
1164
|
id: step.id,
|
|
1136
1165
|
metadata: {}
|
|
1137
1166
|
}
|
|
1138
1167
|
});
|
|
1139
1168
|
}
|
|
1169
|
+
stepAISpan?.end({ output: execResults });
|
|
1140
1170
|
return { result: execResults, executionContext, stepResults };
|
|
1141
1171
|
});
|
|
1172
|
+
if (disableScorers !== false) {
|
|
1173
|
+
await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}.score`, async () => {
|
|
1174
|
+
if (step.scorers) {
|
|
1175
|
+
await this.runScorers({
|
|
1176
|
+
scorers: step.scorers,
|
|
1177
|
+
runId: executionContext.runId,
|
|
1178
|
+
input: inputData,
|
|
1179
|
+
output: stepRes.result,
|
|
1180
|
+
workflowId: executionContext.workflowId,
|
|
1181
|
+
stepId: step.id,
|
|
1182
|
+
runtimeContext,
|
|
1183
|
+
disableScorers,
|
|
1184
|
+
tracingContext: { currentSpan: stepAISpan }
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1142
1189
|
Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
|
|
1143
1190
|
Object.assign(stepResults, stepRes.stepResults);
|
|
1144
1191
|
return stepRes.result;
|
|
@@ -1147,6 +1194,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1147
1194
|
workflowId,
|
|
1148
1195
|
runId,
|
|
1149
1196
|
stepResults,
|
|
1197
|
+
resourceId,
|
|
1150
1198
|
executionContext,
|
|
1151
1199
|
serializedStepGraph,
|
|
1152
1200
|
workflowStatus,
|
|
@@ -1159,12 +1207,14 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1159
1207
|
await this.mastra?.getStorage()?.persistWorkflowSnapshot({
|
|
1160
1208
|
workflowName: workflowId,
|
|
1161
1209
|
runId,
|
|
1210
|
+
resourceId,
|
|
1162
1211
|
snapshot: {
|
|
1163
1212
|
runId,
|
|
1164
1213
|
value: {},
|
|
1165
1214
|
context: stepResults,
|
|
1166
1215
|
activePaths: [],
|
|
1167
1216
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1217
|
+
waitingPaths: {},
|
|
1168
1218
|
serializedStepGraph,
|
|
1169
1219
|
status: workflowStatus,
|
|
1170
1220
|
result,
|
|
@@ -1189,12 +1239,32 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1189
1239
|
emitter,
|
|
1190
1240
|
abortController,
|
|
1191
1241
|
runtimeContext,
|
|
1192
|
-
writableStream
|
|
1242
|
+
writableStream,
|
|
1243
|
+
disableScorers,
|
|
1244
|
+
tracingContext
|
|
1193
1245
|
}) {
|
|
1246
|
+
const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
1247
|
+
type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL,
|
|
1248
|
+
name: `conditional: '${entry.conditions.length} conditions'`,
|
|
1249
|
+
input: prevOutput,
|
|
1250
|
+
attributes: {
|
|
1251
|
+
conditionCount: entry.conditions.length
|
|
1252
|
+
},
|
|
1253
|
+
tracingPolicy: this.options?.tracingPolicy
|
|
1254
|
+
});
|
|
1194
1255
|
let execResults;
|
|
1195
1256
|
const truthyIndexes = (await Promise.all(
|
|
1196
1257
|
entry.conditions.map(
|
|
1197
1258
|
(cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
|
|
1259
|
+
const evalSpan = conditionalSpan?.createChildSpan({
|
|
1260
|
+
type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL_EVAL,
|
|
1261
|
+
name: `condition: '${index}'`,
|
|
1262
|
+
input: prevOutput,
|
|
1263
|
+
attributes: {
|
|
1264
|
+
conditionIndex: index
|
|
1265
|
+
},
|
|
1266
|
+
tracingPolicy: this.options?.tracingPolicy
|
|
1267
|
+
});
|
|
1198
1268
|
try {
|
|
1199
1269
|
const result = await cond({
|
|
1200
1270
|
runId,
|
|
@@ -1203,17 +1273,11 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1203
1273
|
runtimeContext,
|
|
1204
1274
|
runCount: -1,
|
|
1205
1275
|
inputData: prevOutput,
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
if (!step?.id) {
|
|
1209
|
-
return null;
|
|
1210
|
-
}
|
|
1211
|
-
const result2 = stepResults[step.id];
|
|
1212
|
-
if (result2?.status === "success") {
|
|
1213
|
-
return result2.output;
|
|
1214
|
-
}
|
|
1215
|
-
return null;
|
|
1276
|
+
tracingContext: {
|
|
1277
|
+
currentSpan: evalSpan
|
|
1216
1278
|
},
|
|
1279
|
+
getInitData: () => stepResults?.input,
|
|
1280
|
+
getStepResult: workflows.getStepResult.bind(this, stepResults),
|
|
1217
1281
|
// TODO: this function shouldn't have suspend probably?
|
|
1218
1282
|
suspend: async (_suspendPayload) => {
|
|
1219
1283
|
},
|
|
@@ -1223,13 +1287,15 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1223
1287
|
abortController.abort();
|
|
1224
1288
|
},
|
|
1225
1289
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1290
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1291
|
+
// TODO: add streamVNext support
|
|
1226
1292
|
engine: {
|
|
1227
1293
|
step: this.inngestStep
|
|
1228
1294
|
},
|
|
1229
1295
|
abortSignal: abortController.signal,
|
|
1230
1296
|
writer: new tools.ToolStream(
|
|
1231
1297
|
{
|
|
1232
|
-
prefix: "step",
|
|
1298
|
+
prefix: "workflow-step",
|
|
1233
1299
|
callId: crypto.randomUUID(),
|
|
1234
1300
|
name: "conditional",
|
|
1235
1301
|
runId
|
|
@@ -1237,24 +1303,42 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1237
1303
|
writableStream
|
|
1238
1304
|
)
|
|
1239
1305
|
});
|
|
1306
|
+
evalSpan?.end({
|
|
1307
|
+
output: result,
|
|
1308
|
+
attributes: {
|
|
1309
|
+
result: !!result
|
|
1310
|
+
}
|
|
1311
|
+
});
|
|
1240
1312
|
return result ? index : null;
|
|
1241
1313
|
} catch (e) {
|
|
1314
|
+
evalSpan?.error({
|
|
1315
|
+
error: e instanceof Error ? e : new Error(String(e)),
|
|
1316
|
+
attributes: {
|
|
1317
|
+
result: false
|
|
1318
|
+
}
|
|
1319
|
+
});
|
|
1242
1320
|
return null;
|
|
1243
1321
|
}
|
|
1244
1322
|
})
|
|
1245
1323
|
)
|
|
1246
1324
|
)).filter((index) => index !== null);
|
|
1247
1325
|
const stepsToRun = entry.steps.filter((_, index) => truthyIndexes.includes(index));
|
|
1326
|
+
conditionalSpan?.update({
|
|
1327
|
+
attributes: {
|
|
1328
|
+
truthyIndexes,
|
|
1329
|
+
selectedSteps: stepsToRun.map((s) => s.type === "step" ? s.step.id : `control-${s.type}`)
|
|
1330
|
+
}
|
|
1331
|
+
});
|
|
1248
1332
|
const results = await Promise.all(
|
|
1249
1333
|
stepsToRun.map(
|
|
1250
1334
|
(step, index) => this.executeEntry({
|
|
1251
1335
|
workflowId,
|
|
1252
1336
|
runId,
|
|
1253
1337
|
entry: step,
|
|
1338
|
+
serializedStepGraph,
|
|
1254
1339
|
prevStep,
|
|
1255
1340
|
stepResults,
|
|
1256
1341
|
resume,
|
|
1257
|
-
serializedStepGraph,
|
|
1258
1342
|
executionContext: {
|
|
1259
1343
|
workflowId,
|
|
1260
1344
|
runId,
|
|
@@ -1266,7 +1350,11 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1266
1350
|
emitter,
|
|
1267
1351
|
abortController,
|
|
1268
1352
|
runtimeContext,
|
|
1269
|
-
writableStream
|
|
1353
|
+
writableStream,
|
|
1354
|
+
disableScorers,
|
|
1355
|
+
tracingContext: {
|
|
1356
|
+
currentSpan: conditionalSpan
|
|
1357
|
+
}
|
|
1270
1358
|
})
|
|
1271
1359
|
)
|
|
1272
1360
|
);
|
|
@@ -1287,6 +1375,15 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1287
1375
|
}, {})
|
|
1288
1376
|
};
|
|
1289
1377
|
}
|
|
1378
|
+
if (execResults.status === "failed") {
|
|
1379
|
+
conditionalSpan?.error({
|
|
1380
|
+
error: new Error(execResults.error)
|
|
1381
|
+
});
|
|
1382
|
+
} else {
|
|
1383
|
+
conditionalSpan?.end({
|
|
1384
|
+
output: execResults.output || execResults
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1290
1387
|
return execResults;
|
|
1291
1388
|
}
|
|
1292
1389
|
};
|