@mastra/inngest 0.0.0-fix-tool-call-history-3-20250806004225 → 0.0.0-fix-zod-to-json-schema-ref-strategy-20250910193441
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 +279 -3
- package/dist/index.cjs +224 -103
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +23 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +225 -104
- package/dist/index.js.map +1 -1
- package/package.json +25 -12
- 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 -17
- 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');
|
|
@@ -106,6 +107,7 @@ var InngestRun = class extends workflows.Run {
|
|
|
106
107
|
context: {},
|
|
107
108
|
activePaths: [],
|
|
108
109
|
suspendedPaths: {},
|
|
110
|
+
waitingPaths: {},
|
|
109
111
|
timestamp: Date.now(),
|
|
110
112
|
status: "running"
|
|
111
113
|
}
|
|
@@ -202,10 +204,38 @@ var InngestRun = class extends workflows.Run {
|
|
|
202
204
|
}
|
|
203
205
|
stream({ inputData, runtimeContext } = {}) {
|
|
204
206
|
const { readable, writable } = new TransformStream();
|
|
207
|
+
let currentToolData = void 0;
|
|
205
208
|
const writer = writable.getWriter();
|
|
206
209
|
const unwatch = this.watch(async (event) => {
|
|
210
|
+
if (event.type === "workflow-agent-call-start") {
|
|
211
|
+
currentToolData = {
|
|
212
|
+
name: event.payload.name,
|
|
213
|
+
args: event.payload.args
|
|
214
|
+
};
|
|
215
|
+
await writer.write({
|
|
216
|
+
...event.payload,
|
|
217
|
+
type: "tool-call-streaming-start"
|
|
218
|
+
});
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
207
221
|
try {
|
|
208
|
-
|
|
222
|
+
if (event.type === "workflow-agent-call-finish") {
|
|
223
|
+
return;
|
|
224
|
+
} else if (!event.type.startsWith("workflow-")) {
|
|
225
|
+
if (event.type === "text-delta") {
|
|
226
|
+
await writer.write({
|
|
227
|
+
type: "tool-call-delta",
|
|
228
|
+
...currentToolData ?? {},
|
|
229
|
+
argsTextDelta: event.textDelta
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const e = {
|
|
235
|
+
...event,
|
|
236
|
+
type: event.type.replace("workflow-", "")
|
|
237
|
+
};
|
|
238
|
+
await writer.write(e);
|
|
209
239
|
} catch {
|
|
210
240
|
}
|
|
211
241
|
}, "watch-v2");
|
|
@@ -236,8 +266,14 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
236
266
|
#mastra;
|
|
237
267
|
inngest;
|
|
238
268
|
function;
|
|
269
|
+
flowControlConfig;
|
|
239
270
|
constructor(params, inngest) {
|
|
240
|
-
|
|
271
|
+
const { concurrency, rateLimit, throttle, debounce, priority, ...workflowParams } = params;
|
|
272
|
+
super(workflowParams);
|
|
273
|
+
const flowControlEntries = Object.entries({ concurrency, rateLimit, throttle, debounce, priority }).filter(
|
|
274
|
+
([_, value]) => value !== void 0
|
|
275
|
+
);
|
|
276
|
+
this.flowControlConfig = flowControlEntries.length > 0 ? Object.fromEntries(flowControlEntries) : void 0;
|
|
241
277
|
this.#mastra = params.mastra;
|
|
242
278
|
this.inngest = inngest;
|
|
243
279
|
}
|
|
@@ -258,27 +294,6 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
258
294
|
const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
|
|
259
295
|
return run ?? (this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null);
|
|
260
296
|
}
|
|
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
297
|
__registerMastra(mastra) {
|
|
283
298
|
this.#mastra = mastra;
|
|
284
299
|
this.executionEngine.__registerMastra(mastra);
|
|
@@ -331,7 +346,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
331
346
|
this.inngest
|
|
332
347
|
);
|
|
333
348
|
this.runs.set(runIdToUse, run);
|
|
334
|
-
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse);
|
|
349
|
+
const workflowSnapshotInStorage = await this.getWorkflowRunExecutionResult(runIdToUse, false);
|
|
335
350
|
if (!workflowSnapshotInStorage) {
|
|
336
351
|
await this.mastra?.getStorage()?.persistWorkflowSnapshot({
|
|
337
352
|
workflowName: this.id,
|
|
@@ -342,6 +357,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
342
357
|
value: {},
|
|
343
358
|
context: {},
|
|
344
359
|
activePaths: [],
|
|
360
|
+
waitingPaths: {},
|
|
345
361
|
serializedStepGraph: this.serializedStepGraph,
|
|
346
362
|
suspendedPaths: {},
|
|
347
363
|
result: void 0,
|
|
@@ -362,7 +378,9 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
362
378
|
id: `workflow.${this.id}`,
|
|
363
379
|
// @ts-ignore
|
|
364
380
|
retries: this.retryConfig?.attempts ?? 0,
|
|
365
|
-
cancelOn: [{ event: `cancel.workflow.${this.id}` }]
|
|
381
|
+
cancelOn: [{ event: `cancel.workflow.${this.id}` }],
|
|
382
|
+
// Spread flow control configuration
|
|
383
|
+
...this.flowControlConfig
|
|
366
384
|
},
|
|
367
385
|
{ event: `workflow.${this.id}` },
|
|
368
386
|
async ({ event, step, attempt, publish }) => {
|
|
@@ -406,7 +424,9 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
406
424
|
runtimeContext: new di.RuntimeContext(),
|
|
407
425
|
// TODO
|
|
408
426
|
resume,
|
|
409
|
-
abortController: new AbortController()
|
|
427
|
+
abortController: new AbortController(),
|
|
428
|
+
currentSpan: void 0
|
|
429
|
+
// TODO: Pass actual parent AI span from workflow execution context
|
|
410
430
|
});
|
|
411
431
|
return { result, runId };
|
|
412
432
|
}
|
|
@@ -450,7 +470,7 @@ function createStep(params) {
|
|
|
450
470
|
outputSchema: zod.z.object({
|
|
451
471
|
text: zod.z.string()
|
|
452
472
|
}),
|
|
453
|
-
execute: async ({ inputData, [_constants.EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort }) => {
|
|
473
|
+
execute: async ({ inputData, [_constants.EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort, tracingContext }) => {
|
|
454
474
|
let streamPromise = {};
|
|
455
475
|
streamPromise.promise = new Promise((resolve, reject) => {
|
|
456
476
|
streamPromise.resolve = resolve;
|
|
@@ -461,13 +481,14 @@ function createStep(params) {
|
|
|
461
481
|
args: inputData
|
|
462
482
|
};
|
|
463
483
|
await emitter.emit("watch-v2", {
|
|
464
|
-
type: "
|
|
465
|
-
|
|
484
|
+
type: "workflow-agent-call-start",
|
|
485
|
+
payload: toolData
|
|
466
486
|
});
|
|
467
487
|
const { fullStream } = await params.stream(inputData.prompt, {
|
|
468
488
|
// resourceId: inputData.resourceId,
|
|
469
489
|
// threadId: inputData.threadId,
|
|
470
490
|
runtimeContext,
|
|
491
|
+
tracingContext,
|
|
471
492
|
onFinish: (result) => {
|
|
472
493
|
streamPromise.resolve(result.text);
|
|
473
494
|
},
|
|
@@ -477,29 +498,12 @@ function createStep(params) {
|
|
|
477
498
|
return abort();
|
|
478
499
|
}
|
|
479
500
|
for await (const chunk of fullStream) {
|
|
480
|
-
|
|
481
|
-
case "text-delta":
|
|
482
|
-
await emitter.emit("watch-v2", {
|
|
483
|
-
type: "tool-call-delta",
|
|
484
|
-
...toolData,
|
|
485
|
-
argsTextDelta: chunk.textDelta
|
|
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;
|
|
501
|
-
}
|
|
501
|
+
await emitter.emit("watch-v2", chunk);
|
|
502
502
|
}
|
|
503
|
+
await emitter.emit("watch-v2", {
|
|
504
|
+
type: "workflow-agent-call-finish",
|
|
505
|
+
payload: toolData
|
|
506
|
+
});
|
|
503
507
|
return {
|
|
504
508
|
text: await streamPromise.promise
|
|
505
509
|
};
|
|
@@ -516,11 +520,12 @@ function createStep(params) {
|
|
|
516
520
|
id: params.id,
|
|
517
521
|
inputSchema: params.inputSchema,
|
|
518
522
|
outputSchema: params.outputSchema,
|
|
519
|
-
execute: async ({ inputData, mastra, runtimeContext }) => {
|
|
523
|
+
execute: async ({ inputData, mastra, runtimeContext, tracingContext }) => {
|
|
520
524
|
return params.execute({
|
|
521
525
|
context: inputData,
|
|
522
|
-
mastra,
|
|
523
|
-
runtimeContext
|
|
526
|
+
mastra: aiTracing.wrapMastra(mastra, tracingContext),
|
|
527
|
+
runtimeContext,
|
|
528
|
+
tracingContext
|
|
524
529
|
});
|
|
525
530
|
}
|
|
526
531
|
};
|
|
@@ -574,12 +579,12 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
574
579
|
}
|
|
575
580
|
async execute(params) {
|
|
576
581
|
await params.emitter.emit("watch-v2", {
|
|
577
|
-
type: "start",
|
|
582
|
+
type: "workflow-start",
|
|
578
583
|
payload: { runId: params.runId }
|
|
579
584
|
});
|
|
580
585
|
const result = await super.execute(params);
|
|
581
586
|
await params.emitter.emit("watch-v2", {
|
|
582
|
-
type: "finish",
|
|
587
|
+
type: "workflow-finish",
|
|
583
588
|
payload: { runId: params.runId }
|
|
584
589
|
});
|
|
585
590
|
return result;
|
|
@@ -641,33 +646,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
641
646
|
executionSpan?.end();
|
|
642
647
|
return base;
|
|
643
648
|
}
|
|
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
649
|
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
672
650
|
// await this.inngestStep.sleep(id, duration);
|
|
673
651
|
// }
|
|
@@ -680,9 +658,19 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
680
658
|
emitter,
|
|
681
659
|
abortController,
|
|
682
660
|
runtimeContext,
|
|
683
|
-
|
|
661
|
+
executionContext,
|
|
662
|
+
writableStream,
|
|
663
|
+
tracingContext
|
|
684
664
|
}) {
|
|
685
665
|
let { duration, fn } = entry;
|
|
666
|
+
const sleepSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
667
|
+
type: aiTracing.AISpanType.WORKFLOW_SLEEP,
|
|
668
|
+
name: `sleep: ${duration ? `${duration}ms` : "dynamic"}`,
|
|
669
|
+
attributes: {
|
|
670
|
+
durationMs: duration,
|
|
671
|
+
sleepType: fn ? "dynamic" : "fixed"
|
|
672
|
+
}
|
|
673
|
+
});
|
|
686
674
|
if (fn) {
|
|
687
675
|
const stepCallId = crypto.randomUUID();
|
|
688
676
|
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
@@ -693,6 +681,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
693
681
|
runtimeContext,
|
|
694
682
|
inputData: prevOutput,
|
|
695
683
|
runCount: -1,
|
|
684
|
+
tracingContext: {
|
|
685
|
+
currentSpan: sleepSpan
|
|
686
|
+
},
|
|
696
687
|
getInitData: () => stepResults?.input,
|
|
697
688
|
getStepResult: (step) => {
|
|
698
689
|
if (!step?.id) {
|
|
@@ -713,11 +704,13 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
713
704
|
abortController?.abort();
|
|
714
705
|
},
|
|
715
706
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
707
|
+
// TODO: add streamVNext support
|
|
708
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
716
709
|
engine: { step: this.inngestStep },
|
|
717
710
|
abortSignal: abortController?.signal,
|
|
718
711
|
writer: new tools.ToolStream(
|
|
719
712
|
{
|
|
720
|
-
prefix: "step",
|
|
713
|
+
prefix: "workflow-step",
|
|
721
714
|
callId: stepCallId,
|
|
722
715
|
name: "sleep",
|
|
723
716
|
runId
|
|
@@ -726,8 +719,19 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
726
719
|
)
|
|
727
720
|
});
|
|
728
721
|
});
|
|
722
|
+
sleepSpan?.update({
|
|
723
|
+
attributes: {
|
|
724
|
+
durationMs: duration
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
try {
|
|
729
|
+
await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
|
|
730
|
+
sleepSpan?.end();
|
|
731
|
+
} catch (e) {
|
|
732
|
+
sleepSpan?.error({ error: e });
|
|
733
|
+
throw e;
|
|
729
734
|
}
|
|
730
|
-
await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
|
|
731
735
|
}
|
|
732
736
|
async executeSleepUntil({
|
|
733
737
|
workflowId,
|
|
@@ -738,9 +742,20 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
738
742
|
emitter,
|
|
739
743
|
abortController,
|
|
740
744
|
runtimeContext,
|
|
741
|
-
|
|
745
|
+
executionContext,
|
|
746
|
+
writableStream,
|
|
747
|
+
tracingContext
|
|
742
748
|
}) {
|
|
743
749
|
let { date, fn } = entry;
|
|
750
|
+
const sleepUntilSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
751
|
+
type: aiTracing.AISpanType.WORKFLOW_SLEEP,
|
|
752
|
+
name: `sleepUntil: ${date ? date.toISOString() : "dynamic"}`,
|
|
753
|
+
attributes: {
|
|
754
|
+
untilDate: date,
|
|
755
|
+
durationMs: date ? Math.max(0, date.getTime() - Date.now()) : void 0,
|
|
756
|
+
sleepType: fn ? "dynamic" : "fixed"
|
|
757
|
+
}
|
|
758
|
+
});
|
|
744
759
|
if (fn) {
|
|
745
760
|
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
746
761
|
const stepCallId = crypto.randomUUID();
|
|
@@ -751,6 +766,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
751
766
|
runtimeContext,
|
|
752
767
|
inputData: prevOutput,
|
|
753
768
|
runCount: -1,
|
|
769
|
+
tracingContext: {
|
|
770
|
+
currentSpan: sleepUntilSpan
|
|
771
|
+
},
|
|
754
772
|
getInitData: () => stepResults?.input,
|
|
755
773
|
getStepResult: (step) => {
|
|
756
774
|
if (!step?.id) {
|
|
@@ -771,11 +789,13 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
771
789
|
abortController?.abort();
|
|
772
790
|
},
|
|
773
791
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
792
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
793
|
+
// TODO: add streamVNext support
|
|
774
794
|
engine: { step: this.inngestStep },
|
|
775
795
|
abortSignal: abortController?.signal,
|
|
776
796
|
writer: new tools.ToolStream(
|
|
777
797
|
{
|
|
778
|
-
prefix: "step",
|
|
798
|
+
prefix: "workflow-step",
|
|
779
799
|
callId: stepCallId,
|
|
780
800
|
name: "sleep",
|
|
781
801
|
runId
|
|
@@ -784,11 +804,24 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
784
804
|
)
|
|
785
805
|
});
|
|
786
806
|
});
|
|
807
|
+
const time = !date ? 0 : date.getTime() - Date.now();
|
|
808
|
+
sleepUntilSpan?.update({
|
|
809
|
+
attributes: {
|
|
810
|
+
durationMs: Math.max(0, time)
|
|
811
|
+
}
|
|
812
|
+
});
|
|
787
813
|
}
|
|
788
814
|
if (!(date instanceof Date)) {
|
|
815
|
+
sleepUntilSpan?.end();
|
|
789
816
|
return;
|
|
790
817
|
}
|
|
791
|
-
|
|
818
|
+
try {
|
|
819
|
+
await this.inngestStep.sleepUntil(entry.id, date);
|
|
820
|
+
sleepUntilSpan?.end();
|
|
821
|
+
} catch (e) {
|
|
822
|
+
sleepUntilSpan?.error({ error: e });
|
|
823
|
+
throw e;
|
|
824
|
+
}
|
|
792
825
|
}
|
|
793
826
|
async executeWaitForEvent({ event, timeout }) {
|
|
794
827
|
const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
|
|
@@ -809,8 +842,18 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
809
842
|
emitter,
|
|
810
843
|
abortController,
|
|
811
844
|
runtimeContext,
|
|
812
|
-
|
|
845
|
+
tracingContext,
|
|
846
|
+
writableStream,
|
|
847
|
+
disableScorers
|
|
813
848
|
}) {
|
|
849
|
+
const stepAISpan = tracingContext?.currentSpan?.createChildSpan({
|
|
850
|
+
name: `workflow step: '${step.id}'`,
|
|
851
|
+
type: aiTracing.AISpanType.WORKFLOW_STEP,
|
|
852
|
+
input: prevOutput,
|
|
853
|
+
attributes: {
|
|
854
|
+
stepId: step.id
|
|
855
|
+
}
|
|
856
|
+
});
|
|
814
857
|
const startedAt = await this.inngestStep.run(
|
|
815
858
|
`workflow.${executionContext.workflowId}.run.${executionContext.runId}.step.${step.id}.running_ev`,
|
|
816
859
|
async () => {
|
|
@@ -837,7 +880,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
837
880
|
eventTimestamp: Date.now()
|
|
838
881
|
});
|
|
839
882
|
await emitter.emit("watch-v2", {
|
|
840
|
-
type: "step-start",
|
|
883
|
+
type: "workflow-step-start",
|
|
841
884
|
payload: {
|
|
842
885
|
id: step.id,
|
|
843
886
|
status: "running",
|
|
@@ -907,7 +950,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
907
950
|
eventTimestamp: Date.now()
|
|
908
951
|
});
|
|
909
952
|
await emitter.emit("watch-v2", {
|
|
910
|
-
type: "step-result",
|
|
953
|
+
type: "workflow-step-result",
|
|
911
954
|
payload: {
|
|
912
955
|
id: step.id,
|
|
913
956
|
status: "failed",
|
|
@@ -942,7 +985,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
942
985
|
eventTimestamp: Date.now()
|
|
943
986
|
});
|
|
944
987
|
await emitter.emit("watch-v2", {
|
|
945
|
-
type: "step-suspended",
|
|
988
|
+
type: "workflow-step-suspended",
|
|
946
989
|
payload: {
|
|
947
990
|
id: step.id,
|
|
948
991
|
status: "suspended"
|
|
@@ -999,7 +1042,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
999
1042
|
eventTimestamp: Date.now()
|
|
1000
1043
|
});
|
|
1001
1044
|
await emitter.emit("watch-v2", {
|
|
1002
|
-
type: "step-result",
|
|
1045
|
+
type: "workflow-step-result",
|
|
1003
1046
|
payload: {
|
|
1004
1047
|
id: step.id,
|
|
1005
1048
|
status: "success",
|
|
@@ -1007,7 +1050,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1007
1050
|
}
|
|
1008
1051
|
});
|
|
1009
1052
|
await emitter.emit("watch-v2", {
|
|
1010
|
-
type: "step-finish",
|
|
1053
|
+
type: "workflow-step-finish",
|
|
1011
1054
|
payload: {
|
|
1012
1055
|
id: step.id,
|
|
1013
1056
|
metadata: {}
|
|
@@ -1031,6 +1074,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1031
1074
|
writableStream,
|
|
1032
1075
|
inputData: prevOutput,
|
|
1033
1076
|
resumeData: resume?.steps[0] === step.id ? resume?.resumePayload : void 0,
|
|
1077
|
+
tracingContext: {
|
|
1078
|
+
currentSpan: stepAISpan
|
|
1079
|
+
},
|
|
1034
1080
|
getInitData: () => stepResults?.input,
|
|
1035
1081
|
getStepResult: (step2) => {
|
|
1036
1082
|
const result2 = stepResults[step2.id];
|
|
@@ -1094,7 +1140,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1094
1140
|
}
|
|
1095
1141
|
if (execResults.status === "failed") {
|
|
1096
1142
|
if (executionContext.retryConfig.attempts > 0 && this.inngestAttempts < executionContext.retryConfig.attempts) {
|
|
1097
|
-
|
|
1143
|
+
const error = new Error(execResults.error);
|
|
1144
|
+
stepAISpan?.error({ error });
|
|
1145
|
+
throw error;
|
|
1098
1146
|
}
|
|
1099
1147
|
}
|
|
1100
1148
|
await emitter.emit("watch", {
|
|
@@ -1115,7 +1163,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1115
1163
|
});
|
|
1116
1164
|
if (execResults.status === "suspended") {
|
|
1117
1165
|
await emitter.emit("watch-v2", {
|
|
1118
|
-
type: "step-suspended",
|
|
1166
|
+
type: "workflow-step-suspended",
|
|
1119
1167
|
payload: {
|
|
1120
1168
|
id: step.id,
|
|
1121
1169
|
...execResults
|
|
@@ -1123,22 +1171,40 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1123
1171
|
});
|
|
1124
1172
|
} else {
|
|
1125
1173
|
await emitter.emit("watch-v2", {
|
|
1126
|
-
type: "step-result",
|
|
1174
|
+
type: "workflow-step-result",
|
|
1127
1175
|
payload: {
|
|
1128
1176
|
id: step.id,
|
|
1129
1177
|
...execResults
|
|
1130
1178
|
}
|
|
1131
1179
|
});
|
|
1132
1180
|
await emitter.emit("watch-v2", {
|
|
1133
|
-
type: "step-finish",
|
|
1181
|
+
type: "workflow-step-finish",
|
|
1134
1182
|
payload: {
|
|
1135
1183
|
id: step.id,
|
|
1136
1184
|
metadata: {}
|
|
1137
1185
|
}
|
|
1138
1186
|
});
|
|
1139
1187
|
}
|
|
1188
|
+
stepAISpan?.end({ output: execResults });
|
|
1140
1189
|
return { result: execResults, executionContext, stepResults };
|
|
1141
1190
|
});
|
|
1191
|
+
if (disableScorers !== false) {
|
|
1192
|
+
await this.inngestStep.run(`workflow.${executionContext.workflowId}.step.${step.id}.score`, async () => {
|
|
1193
|
+
if (step.scorers) {
|
|
1194
|
+
await this.runScorers({
|
|
1195
|
+
scorers: step.scorers,
|
|
1196
|
+
runId: executionContext.runId,
|
|
1197
|
+
input: prevOutput,
|
|
1198
|
+
output: stepRes.result,
|
|
1199
|
+
workflowId: executionContext.workflowId,
|
|
1200
|
+
stepId: step.id,
|
|
1201
|
+
runtimeContext,
|
|
1202
|
+
disableScorers,
|
|
1203
|
+
tracingContext: { currentSpan: stepAISpan }
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1142
1208
|
Object.assign(executionContext.suspendedPaths, stepRes.executionContext.suspendedPaths);
|
|
1143
1209
|
Object.assign(stepResults, stepRes.stepResults);
|
|
1144
1210
|
return stepRes.result;
|
|
@@ -1165,6 +1231,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1165
1231
|
context: stepResults,
|
|
1166
1232
|
activePaths: [],
|
|
1167
1233
|
suspendedPaths: executionContext.suspendedPaths,
|
|
1234
|
+
waitingPaths: {},
|
|
1168
1235
|
serializedStepGraph,
|
|
1169
1236
|
status: workflowStatus,
|
|
1170
1237
|
result,
|
|
@@ -1189,12 +1256,30 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1189
1256
|
emitter,
|
|
1190
1257
|
abortController,
|
|
1191
1258
|
runtimeContext,
|
|
1192
|
-
writableStream
|
|
1259
|
+
writableStream,
|
|
1260
|
+
disableScorers,
|
|
1261
|
+
tracingContext
|
|
1193
1262
|
}) {
|
|
1263
|
+
const conditionalSpan = tracingContext?.currentSpan?.createChildSpan({
|
|
1264
|
+
type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL,
|
|
1265
|
+
name: `conditional: '${entry.conditions.length} conditions'`,
|
|
1266
|
+
input: prevOutput,
|
|
1267
|
+
attributes: {
|
|
1268
|
+
conditionCount: entry.conditions.length
|
|
1269
|
+
}
|
|
1270
|
+
});
|
|
1194
1271
|
let execResults;
|
|
1195
1272
|
const truthyIndexes = (await Promise.all(
|
|
1196
1273
|
entry.conditions.map(
|
|
1197
1274
|
(cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
|
|
1275
|
+
const evalSpan = conditionalSpan?.createChildSpan({
|
|
1276
|
+
type: aiTracing.AISpanType.WORKFLOW_CONDITIONAL_EVAL,
|
|
1277
|
+
name: `condition: '${index}'`,
|
|
1278
|
+
input: prevOutput,
|
|
1279
|
+
attributes: {
|
|
1280
|
+
conditionIndex: index
|
|
1281
|
+
}
|
|
1282
|
+
});
|
|
1198
1283
|
try {
|
|
1199
1284
|
const result = await cond({
|
|
1200
1285
|
runId,
|
|
@@ -1203,6 +1288,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1203
1288
|
runtimeContext,
|
|
1204
1289
|
runCount: -1,
|
|
1205
1290
|
inputData: prevOutput,
|
|
1291
|
+
tracingContext: {
|
|
1292
|
+
currentSpan: evalSpan
|
|
1293
|
+
},
|
|
1206
1294
|
getInitData: () => stepResults?.input,
|
|
1207
1295
|
getStepResult: (step) => {
|
|
1208
1296
|
if (!step?.id) {
|
|
@@ -1223,13 +1311,15 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1223
1311
|
abortController.abort();
|
|
1224
1312
|
},
|
|
1225
1313
|
[_constants.EMITTER_SYMBOL]: emitter,
|
|
1314
|
+
[_constants.STREAM_FORMAT_SYMBOL]: executionContext.format,
|
|
1315
|
+
// TODO: add streamVNext support
|
|
1226
1316
|
engine: {
|
|
1227
1317
|
step: this.inngestStep
|
|
1228
1318
|
},
|
|
1229
1319
|
abortSignal: abortController.signal,
|
|
1230
1320
|
writer: new tools.ToolStream(
|
|
1231
1321
|
{
|
|
1232
|
-
prefix: "step",
|
|
1322
|
+
prefix: "workflow-step",
|
|
1233
1323
|
callId: crypto.randomUUID(),
|
|
1234
1324
|
name: "conditional",
|
|
1235
1325
|
runId
|
|
@@ -1237,24 +1327,42 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1237
1327
|
writableStream
|
|
1238
1328
|
)
|
|
1239
1329
|
});
|
|
1330
|
+
evalSpan?.end({
|
|
1331
|
+
output: result,
|
|
1332
|
+
attributes: {
|
|
1333
|
+
result: !!result
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1240
1336
|
return result ? index : null;
|
|
1241
1337
|
} catch (e) {
|
|
1338
|
+
evalSpan?.error({
|
|
1339
|
+
error: e instanceof Error ? e : new Error(String(e)),
|
|
1340
|
+
attributes: {
|
|
1341
|
+
result: false
|
|
1342
|
+
}
|
|
1343
|
+
});
|
|
1242
1344
|
return null;
|
|
1243
1345
|
}
|
|
1244
1346
|
})
|
|
1245
1347
|
)
|
|
1246
1348
|
)).filter((index) => index !== null);
|
|
1247
1349
|
const stepsToRun = entry.steps.filter((_, index) => truthyIndexes.includes(index));
|
|
1350
|
+
conditionalSpan?.update({
|
|
1351
|
+
attributes: {
|
|
1352
|
+
truthyIndexes,
|
|
1353
|
+
selectedSteps: stepsToRun.map((s) => s.type === "step" ? s.step.id : `control-${s.type}`)
|
|
1354
|
+
}
|
|
1355
|
+
});
|
|
1248
1356
|
const results = await Promise.all(
|
|
1249
1357
|
stepsToRun.map(
|
|
1250
1358
|
(step, index) => this.executeEntry({
|
|
1251
1359
|
workflowId,
|
|
1252
1360
|
runId,
|
|
1253
1361
|
entry: step,
|
|
1362
|
+
serializedStepGraph,
|
|
1254
1363
|
prevStep,
|
|
1255
1364
|
stepResults,
|
|
1256
1365
|
resume,
|
|
1257
|
-
serializedStepGraph,
|
|
1258
1366
|
executionContext: {
|
|
1259
1367
|
workflowId,
|
|
1260
1368
|
runId,
|
|
@@ -1266,7 +1374,11 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1266
1374
|
emitter,
|
|
1267
1375
|
abortController,
|
|
1268
1376
|
runtimeContext,
|
|
1269
|
-
writableStream
|
|
1377
|
+
writableStream,
|
|
1378
|
+
disableScorers,
|
|
1379
|
+
tracingContext: {
|
|
1380
|
+
currentSpan: conditionalSpan
|
|
1381
|
+
}
|
|
1270
1382
|
})
|
|
1271
1383
|
)
|
|
1272
1384
|
);
|
|
@@ -1287,6 +1399,15 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
1287
1399
|
}, {})
|
|
1288
1400
|
};
|
|
1289
1401
|
}
|
|
1402
|
+
if (execResults.status === "failed") {
|
|
1403
|
+
conditionalSpan?.error({
|
|
1404
|
+
error: new Error(execResults.error)
|
|
1405
|
+
});
|
|
1406
|
+
} else {
|
|
1407
|
+
conditionalSpan?.end({
|
|
1408
|
+
output: execResults.output || execResults
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1290
1411
|
return execResults;
|
|
1291
1412
|
}
|
|
1292
1413
|
};
|