@mastra/inngest 0.0.0-tool-call-parts-20250630193309 → 0.0.0-tsconfig-compile-20250703214351
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 +63 -3
- package/dist/_tsup-dts-rollup.d.cts +56 -16
- package/dist/_tsup-dts-rollup.d.ts +56 -16
- package/dist/index.cjs +167 -18
- package/dist/index.js +167 -18
- package/docker-compose.yaml +3 -3
- package/package.json +9 -8
- package/src/index.test.ts +839 -187
- package/src/index.ts +225 -20
- package/vitest.config.ts +6 -0
package/dist/index.js
CHANGED
|
@@ -10,13 +10,17 @@ import { z } from 'zod';
|
|
|
10
10
|
// src/index.ts
|
|
11
11
|
function serve({ mastra, inngest }) {
|
|
12
12
|
const wfs = mastra.getWorkflows();
|
|
13
|
-
const functions =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
const functions = Array.from(
|
|
14
|
+
new Set(
|
|
15
|
+
Object.values(wfs).flatMap((wf) => {
|
|
16
|
+
if (wf instanceof InngestWorkflow) {
|
|
17
|
+
wf.__registerMastra(mastra);
|
|
18
|
+
return wf.getFunctions();
|
|
19
|
+
}
|
|
20
|
+
return [];
|
|
21
|
+
})
|
|
22
|
+
)
|
|
23
|
+
);
|
|
20
24
|
return serve$1({
|
|
21
25
|
client: inngest,
|
|
22
26
|
functions
|
|
@@ -46,8 +50,15 @@ var InngestRun = class extends Run {
|
|
|
46
50
|
while (runs?.[0]?.status !== "Completed" || runs?.[0]?.event_id !== eventId) {
|
|
47
51
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
48
52
|
runs = await this.getRuns(eventId);
|
|
49
|
-
if (runs?.[0]?.status === "Failed"
|
|
53
|
+
if (runs?.[0]?.status === "Failed") {
|
|
54
|
+
console.log("run", runs?.[0]);
|
|
50
55
|
throw new Error(`Function run ${runs?.[0]?.status}`);
|
|
56
|
+
} else if (runs?.[0]?.status === "Cancelled") {
|
|
57
|
+
const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
|
|
58
|
+
workflowName: this.workflowId,
|
|
59
|
+
runId: this.runId
|
|
60
|
+
});
|
|
61
|
+
return { output: { result: { steps: snapshot?.context, status: "canceled" } } };
|
|
51
62
|
}
|
|
52
63
|
}
|
|
53
64
|
return runs?.[0];
|
|
@@ -58,6 +69,28 @@ var InngestRun = class extends Run {
|
|
|
58
69
|
data
|
|
59
70
|
});
|
|
60
71
|
}
|
|
72
|
+
async cancel() {
|
|
73
|
+
await this.inngest.send({
|
|
74
|
+
name: `cancel.workflow.${this.workflowId}`,
|
|
75
|
+
data: {
|
|
76
|
+
runId: this.runId
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
const snapshot = await this.#mastra?.storage?.loadWorkflowSnapshot({
|
|
80
|
+
workflowName: this.workflowId,
|
|
81
|
+
runId: this.runId
|
|
82
|
+
});
|
|
83
|
+
if (snapshot) {
|
|
84
|
+
await this.#mastra?.storage?.persistWorkflowSnapshot({
|
|
85
|
+
workflowName: this.workflowId,
|
|
86
|
+
runId: this.runId,
|
|
87
|
+
snapshot: {
|
|
88
|
+
...snapshot,
|
|
89
|
+
status: "canceled"
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
61
94
|
async start({
|
|
62
95
|
inputData
|
|
63
96
|
}) {
|
|
@@ -322,8 +355,12 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
322
355
|
return this.function;
|
|
323
356
|
}
|
|
324
357
|
this.function = this.inngest.createFunction(
|
|
325
|
-
|
|
326
|
-
|
|
358
|
+
{
|
|
359
|
+
id: `workflow.${this.id}`,
|
|
360
|
+
// @ts-ignore
|
|
361
|
+
retries: this.retryConfig?.attempts ?? 0,
|
|
362
|
+
cancelOn: [{ event: `cancel.workflow.${this.id}` }]
|
|
363
|
+
},
|
|
327
364
|
{ event: `workflow.${this.id}` },
|
|
328
365
|
async ({ event, step, attempt, publish }) => {
|
|
329
366
|
let { inputData, runId, resume } = event.data;
|
|
@@ -365,7 +402,8 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
365
402
|
retryConfig: this.retryConfig,
|
|
366
403
|
runtimeContext: new RuntimeContext(),
|
|
367
404
|
// TODO
|
|
368
|
-
resume
|
|
405
|
+
resume,
|
|
406
|
+
abortController: new AbortController()
|
|
369
407
|
});
|
|
370
408
|
return { result, runId };
|
|
371
409
|
}
|
|
@@ -409,7 +447,7 @@ function createStep(params) {
|
|
|
409
447
|
outputSchema: z.object({
|
|
410
448
|
text: z.string()
|
|
411
449
|
}),
|
|
412
|
-
execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext }) => {
|
|
450
|
+
execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext, abortSignal, abort }) => {
|
|
413
451
|
let streamPromise = {};
|
|
414
452
|
streamPromise.promise = new Promise((resolve, reject) => {
|
|
415
453
|
streamPromise.resolve = resolve;
|
|
@@ -429,8 +467,12 @@ function createStep(params) {
|
|
|
429
467
|
runtimeContext,
|
|
430
468
|
onFinish: (result) => {
|
|
431
469
|
streamPromise.resolve(result.text);
|
|
432
|
-
}
|
|
470
|
+
},
|
|
471
|
+
abortSignal
|
|
433
472
|
});
|
|
473
|
+
if (abortSignal.aborted) {
|
|
474
|
+
return abort();
|
|
475
|
+
}
|
|
434
476
|
for await (const chunk of fullStream) {
|
|
435
477
|
switch (chunk.type) {
|
|
436
478
|
case "text-delta":
|
|
@@ -605,6 +647,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
605
647
|
resume,
|
|
606
648
|
prevOutput,
|
|
607
649
|
emitter,
|
|
650
|
+
abortController,
|
|
608
651
|
runtimeContext
|
|
609
652
|
}) {
|
|
610
653
|
return super.executeStep({
|
|
@@ -616,11 +659,107 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
616
659
|
resume,
|
|
617
660
|
prevOutput,
|
|
618
661
|
emitter,
|
|
662
|
+
abortController,
|
|
619
663
|
runtimeContext
|
|
620
664
|
});
|
|
621
665
|
}
|
|
622
|
-
async executeSleep({ id, duration }) {
|
|
623
|
-
|
|
666
|
+
// async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
667
|
+
// await this.inngestStep.sleep(id, duration);
|
|
668
|
+
// }
|
|
669
|
+
async executeSleep({
|
|
670
|
+
workflowId,
|
|
671
|
+
runId,
|
|
672
|
+
entry,
|
|
673
|
+
prevOutput,
|
|
674
|
+
stepResults,
|
|
675
|
+
emitter,
|
|
676
|
+
abortController,
|
|
677
|
+
runtimeContext
|
|
678
|
+
}) {
|
|
679
|
+
let { duration, fn } = entry;
|
|
680
|
+
if (fn) {
|
|
681
|
+
duration = await this.inngestStep.run(`workflow.${workflowId}.sleep.${entry.id}`, async () => {
|
|
682
|
+
return await fn({
|
|
683
|
+
runId,
|
|
684
|
+
mastra: this.mastra,
|
|
685
|
+
runtimeContext,
|
|
686
|
+
inputData: prevOutput,
|
|
687
|
+
runCount: -1,
|
|
688
|
+
getInitData: () => stepResults?.input,
|
|
689
|
+
getStepResult: (step) => {
|
|
690
|
+
if (!step?.id) {
|
|
691
|
+
return null;
|
|
692
|
+
}
|
|
693
|
+
const result = stepResults[step.id];
|
|
694
|
+
if (result?.status === "success") {
|
|
695
|
+
return result.output;
|
|
696
|
+
}
|
|
697
|
+
return null;
|
|
698
|
+
},
|
|
699
|
+
// TODO: this function shouldn't have suspend probably?
|
|
700
|
+
suspend: async (_suspendPayload) => {
|
|
701
|
+
},
|
|
702
|
+
bail: () => {
|
|
703
|
+
},
|
|
704
|
+
abort: () => {
|
|
705
|
+
abortController?.abort();
|
|
706
|
+
},
|
|
707
|
+
[EMITTER_SYMBOL]: emitter,
|
|
708
|
+
engine: { step: this.inngestStep },
|
|
709
|
+
abortSignal: abortController?.signal
|
|
710
|
+
});
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
await this.inngestStep.sleep(entry.id, !duration || duration < 0 ? 0 : duration);
|
|
714
|
+
}
|
|
715
|
+
async executeSleepUntil({
|
|
716
|
+
workflowId,
|
|
717
|
+
runId,
|
|
718
|
+
entry,
|
|
719
|
+
prevOutput,
|
|
720
|
+
stepResults,
|
|
721
|
+
emitter,
|
|
722
|
+
abortController,
|
|
723
|
+
runtimeContext
|
|
724
|
+
}) {
|
|
725
|
+
let { date, fn } = entry;
|
|
726
|
+
if (fn) {
|
|
727
|
+
date = await this.inngestStep.run(`workflow.${workflowId}.sleepUntil.${entry.id}`, async () => {
|
|
728
|
+
return await fn({
|
|
729
|
+
runId,
|
|
730
|
+
mastra: this.mastra,
|
|
731
|
+
runtimeContext,
|
|
732
|
+
inputData: prevOutput,
|
|
733
|
+
runCount: -1,
|
|
734
|
+
getInitData: () => stepResults?.input,
|
|
735
|
+
getStepResult: (step) => {
|
|
736
|
+
if (!step?.id) {
|
|
737
|
+
return null;
|
|
738
|
+
}
|
|
739
|
+
const result = stepResults[step.id];
|
|
740
|
+
if (result?.status === "success") {
|
|
741
|
+
return result.output;
|
|
742
|
+
}
|
|
743
|
+
return null;
|
|
744
|
+
},
|
|
745
|
+
// TODO: this function shouldn't have suspend probably?
|
|
746
|
+
suspend: async (_suspendPayload) => {
|
|
747
|
+
},
|
|
748
|
+
bail: () => {
|
|
749
|
+
},
|
|
750
|
+
abort: () => {
|
|
751
|
+
abortController?.abort();
|
|
752
|
+
},
|
|
753
|
+
[EMITTER_SYMBOL]: emitter,
|
|
754
|
+
engine: { step: this.inngestStep },
|
|
755
|
+
abortSignal: abortController?.signal
|
|
756
|
+
});
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
if (!(date instanceof Date)) {
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
await this.inngestStep.sleepUntil(entry.id, date);
|
|
624
763
|
}
|
|
625
764
|
async executeWaitForEvent({ event, timeout }) {
|
|
626
765
|
const eventData = await this.inngestStep.waitForEvent(`user-event-${event}`, {
|
|
@@ -639,6 +778,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
639
778
|
resume,
|
|
640
779
|
prevOutput,
|
|
641
780
|
emitter,
|
|
781
|
+
abortController,
|
|
642
782
|
runtimeContext
|
|
643
783
|
}) {
|
|
644
784
|
const startedAt = await this.inngestStep.run(
|
|
@@ -670,7 +810,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
670
810
|
type: "step-start",
|
|
671
811
|
payload: {
|
|
672
812
|
id: step.id,
|
|
673
|
-
status: "running"
|
|
813
|
+
status: "running",
|
|
814
|
+
payload: prevOutput,
|
|
815
|
+
startedAt: startedAt2
|
|
674
816
|
}
|
|
675
817
|
});
|
|
676
818
|
return startedAt2;
|
|
@@ -882,7 +1024,8 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
882
1024
|
[EMITTER_SYMBOL]: emitter,
|
|
883
1025
|
engine: {
|
|
884
1026
|
step: this.inngestStep
|
|
885
|
-
}
|
|
1027
|
+
},
|
|
1028
|
+
abortSignal: abortController.signal
|
|
886
1029
|
});
|
|
887
1030
|
const endedAt = Date.now();
|
|
888
1031
|
execResults = {
|
|
@@ -1013,6 +1156,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1013
1156
|
resume,
|
|
1014
1157
|
executionContext,
|
|
1015
1158
|
emitter,
|
|
1159
|
+
abortController,
|
|
1016
1160
|
runtimeContext
|
|
1017
1161
|
}) {
|
|
1018
1162
|
let execResults;
|
|
@@ -1042,10 +1186,14 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1042
1186
|
},
|
|
1043
1187
|
bail: () => {
|
|
1044
1188
|
},
|
|
1189
|
+
abort: () => {
|
|
1190
|
+
abortController.abort();
|
|
1191
|
+
},
|
|
1045
1192
|
[EMITTER_SYMBOL]: emitter,
|
|
1046
1193
|
engine: {
|
|
1047
1194
|
step: this.inngestStep
|
|
1048
|
-
}
|
|
1195
|
+
},
|
|
1196
|
+
abortSignal: abortController.signal
|
|
1049
1197
|
});
|
|
1050
1198
|
return result ? index : null;
|
|
1051
1199
|
} catch (e) {
|
|
@@ -1074,6 +1222,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
1074
1222
|
executionSpan: executionContext.executionSpan
|
|
1075
1223
|
},
|
|
1076
1224
|
emitter,
|
|
1225
|
+
abortController,
|
|
1077
1226
|
runtimeContext
|
|
1078
1227
|
})
|
|
1079
1228
|
)
|
package/docker-compose.yaml
CHANGED
|
@@ -2,9 +2,9 @@ version: '3'
|
|
|
2
2
|
|
|
3
3
|
services:
|
|
4
4
|
inngest:
|
|
5
|
-
image: inngest/inngest
|
|
6
|
-
command: inngest dev -u http://host.docker.internal:
|
|
5
|
+
image: inngest/inngest:v1.5.10
|
|
6
|
+
command: inngest dev -p 4000 -u http://host.docker.internal:4001/inngest/api --poll-interval=1
|
|
7
7
|
ports:
|
|
8
|
-
- '
|
|
8
|
+
- '4000:4000'
|
|
9
9
|
extra_hosts:
|
|
10
10
|
- 'host.docker.internal:host-gateway'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/inngest",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-tsconfig-compile-20250703214351",
|
|
4
4
|
"description": "Mastra Inngest integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"zod": "^3.25.67"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
+
"inngest-cli": "1.8.2",
|
|
28
29
|
"@ai-sdk/openai": "^1.3.22",
|
|
29
30
|
"@hono/node-server": "^1.14.4",
|
|
30
31
|
"@microsoft/api-extractor": "^7.52.8",
|
|
@@ -36,19 +37,19 @@
|
|
|
36
37
|
"hono": "^4.8.3",
|
|
37
38
|
"tsup": "^8.5.0",
|
|
38
39
|
"typescript": "^5.8.3",
|
|
39
|
-
"vitest": "^2.
|
|
40
|
-
"@mastra/core": "0.0.0-
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"@mastra/deployer": "0.0.0-
|
|
40
|
+
"vitest": "^3.2.4",
|
|
41
|
+
"@mastra/core": "0.0.0-tsconfig-compile-20250703214351",
|
|
42
|
+
"@internal/lint": "0.0.0-tsconfig-compile-20250703214351",
|
|
43
|
+
"@mastra/libsql": "0.0.0-tsconfig-compile-20250703214351",
|
|
44
|
+
"@mastra/deployer": "0.0.0-tsconfig-compile-20250703214351"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
|
-
"@mastra/core": "0.0.0-
|
|
47
|
+
"@mastra/core": "0.0.0-tsconfig-compile-20250703214351"
|
|
47
48
|
},
|
|
48
49
|
"scripts": {
|
|
49
50
|
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|
|
50
51
|
"build:watch": "pnpm build --watch",
|
|
51
|
-
"test": "vitest run",
|
|
52
|
+
"test": "docker-compose up -d && vitest run --no-isolate --bail=1 --retry=1 && docker-compose down",
|
|
52
53
|
"lint": "eslint ."
|
|
53
54
|
}
|
|
54
55
|
}
|