@mastra/inngest 0.0.0-course-20250527170450 → 0.0.0-fix-generate-title-20250616171351
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 +155 -2
- package/dist/_tsup-dts-rollup.d.cts +56 -15
- package/dist/_tsup-dts-rollup.d.ts +56 -15
- package/dist/index.cjs +178 -28
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +178 -29
- package/package.json +18 -17
- package/src/index.test.ts +229 -145
- package/src/index.ts +322 -42
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
2
|
import { subscribe } from '@inngest/realtime';
|
|
3
|
+
import { Agent, Tool } from '@mastra/core';
|
|
3
4
|
import { RuntimeContext } from '@mastra/core/di';
|
|
4
|
-
import { Run, Workflow,
|
|
5
|
+
import { Run, Workflow, DefaultExecutionEngine } from '@mastra/core/workflows';
|
|
5
6
|
import { EMITTER_SYMBOL } from '@mastra/core/workflows/_constants';
|
|
6
7
|
import { serve as serve$1 } from 'inngest/hono';
|
|
8
|
+
import { z } from 'zod';
|
|
7
9
|
|
|
8
10
|
// src/index.ts
|
|
9
11
|
function serve({ mastra, inngest }) {
|
|
@@ -22,14 +24,16 @@ function serve({ mastra, inngest }) {
|
|
|
22
24
|
}
|
|
23
25
|
var InngestRun = class extends Run {
|
|
24
26
|
inngest;
|
|
27
|
+
serializedStepGraph;
|
|
25
28
|
#mastra;
|
|
26
29
|
constructor(params, inngest) {
|
|
27
30
|
super(params);
|
|
28
31
|
this.inngest = inngest;
|
|
32
|
+
this.serializedStepGraph = params.serializedStepGraph;
|
|
29
33
|
this.#mastra = params.mastra;
|
|
30
34
|
}
|
|
31
35
|
async getRuns(eventId) {
|
|
32
|
-
const response = await fetch(`${this.inngest.apiBaseUrl}/v1/events/${eventId}/runs`, {
|
|
36
|
+
const response = await fetch(`${this.inngest.apiBaseUrl ?? "https://api.inngest.com"}/v1/events/${eventId}/runs`, {
|
|
33
37
|
headers: {
|
|
34
38
|
Authorization: `Bearer ${process.env.INNGEST_SIGNING_KEY}`
|
|
35
39
|
}
|
|
@@ -56,11 +60,13 @@ var InngestRun = class extends Run {
|
|
|
56
60
|
runId: this.runId,
|
|
57
61
|
snapshot: {
|
|
58
62
|
runId: this.runId,
|
|
63
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
59
64
|
value: {},
|
|
60
65
|
context: {},
|
|
61
66
|
activePaths: [],
|
|
62
67
|
suspendedPaths: {},
|
|
63
|
-
timestamp: Date.now()
|
|
68
|
+
timestamp: Date.now(),
|
|
69
|
+
status: "running"
|
|
64
70
|
}
|
|
65
71
|
});
|
|
66
72
|
const eventOutput = await this.inngest.send({
|
|
@@ -157,11 +163,32 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
157
163
|
const storage = this.#mastra?.getStorage();
|
|
158
164
|
if (!storage) {
|
|
159
165
|
this.logger.debug("Cannot get workflow runs. Mastra engine is not initialized");
|
|
160
|
-
return null;
|
|
166
|
+
return this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null;
|
|
161
167
|
}
|
|
162
168
|
const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
|
|
163
169
|
return run ?? (this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null);
|
|
164
170
|
}
|
|
171
|
+
async getWorkflowRunExecutionResult(runId) {
|
|
172
|
+
const storage = this.#mastra?.getStorage();
|
|
173
|
+
if (!storage) {
|
|
174
|
+
this.logger.debug("Cannot get workflow run execution result. Mastra storage is not initialized");
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
|
|
178
|
+
if (!run?.snapshot) {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
if (typeof run.snapshot === "string") {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
status: run.snapshot.status,
|
|
186
|
+
result: run.snapshot.result,
|
|
187
|
+
error: run.snapshot.error,
|
|
188
|
+
payload: run.snapshot.context?.input,
|
|
189
|
+
steps: run.snapshot.context
|
|
190
|
+
};
|
|
191
|
+
}
|
|
165
192
|
__registerMastra(mastra) {
|
|
166
193
|
this.#mastra = mastra;
|
|
167
194
|
this.executionEngine.__registerMastra(mastra);
|
|
@@ -188,6 +215,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
188
215
|
runId: runIdToUse,
|
|
189
216
|
executionEngine: this.executionEngine,
|
|
190
217
|
executionGraph: this.executionGraph,
|
|
218
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
191
219
|
mastra: this.#mastra,
|
|
192
220
|
retryConfig: this.retryConfig,
|
|
193
221
|
cleanup: () => this.runs.delete(runIdToUse)
|
|
@@ -233,6 +261,7 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
233
261
|
workflowId: this.id,
|
|
234
262
|
runId,
|
|
235
263
|
graph: this.executionGraph,
|
|
264
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
236
265
|
input: inputData,
|
|
237
266
|
emitter,
|
|
238
267
|
retryConfig: this.retryConfig,
|
|
@@ -262,20 +291,100 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
262
291
|
return [this.getFunction(), ...this.getNestedFunctions(this.executionGraph.steps)];
|
|
263
292
|
}
|
|
264
293
|
};
|
|
265
|
-
function
|
|
266
|
-
|
|
267
|
-
{
|
|
268
|
-
id:
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
294
|
+
function createStep(params) {
|
|
295
|
+
if (params instanceof Agent) {
|
|
296
|
+
return {
|
|
297
|
+
id: params.name,
|
|
298
|
+
// @ts-ignore
|
|
299
|
+
inputSchema: z.object({
|
|
300
|
+
prompt: z.string()
|
|
301
|
+
// resourceId: z.string().optional(),
|
|
302
|
+
// threadId: z.string().optional(),
|
|
303
|
+
}),
|
|
304
|
+
// @ts-ignore
|
|
305
|
+
outputSchema: z.object({
|
|
306
|
+
text: z.string()
|
|
307
|
+
}),
|
|
308
|
+
execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext }) => {
|
|
309
|
+
let streamPromise = {};
|
|
310
|
+
streamPromise.promise = new Promise((resolve, reject) => {
|
|
311
|
+
streamPromise.resolve = resolve;
|
|
312
|
+
streamPromise.reject = reject;
|
|
313
|
+
});
|
|
314
|
+
const toolData = {
|
|
315
|
+
name: params.name,
|
|
316
|
+
args: inputData
|
|
317
|
+
};
|
|
318
|
+
await emitter.emit("watch-v2", {
|
|
319
|
+
type: "tool-call-streaming-start",
|
|
320
|
+
...toolData
|
|
321
|
+
});
|
|
322
|
+
const { fullStream } = await params.stream(inputData.prompt, {
|
|
323
|
+
// resourceId: inputData.resourceId,
|
|
324
|
+
// threadId: inputData.threadId,
|
|
325
|
+
runtimeContext,
|
|
326
|
+
onFinish: (result) => {
|
|
327
|
+
streamPromise.resolve(result.text);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
for await (const chunk of fullStream) {
|
|
331
|
+
switch (chunk.type) {
|
|
332
|
+
case "text-delta":
|
|
333
|
+
await emitter.emit("watch-v2", {
|
|
334
|
+
type: "tool-call-delta",
|
|
335
|
+
...toolData,
|
|
336
|
+
argsTextDelta: chunk.textDelta
|
|
337
|
+
});
|
|
338
|
+
break;
|
|
339
|
+
case "step-start":
|
|
340
|
+
case "step-finish":
|
|
341
|
+
case "finish":
|
|
342
|
+
break;
|
|
343
|
+
case "tool-call":
|
|
344
|
+
case "tool-result":
|
|
345
|
+
case "tool-call-streaming-start":
|
|
346
|
+
case "tool-call-delta":
|
|
347
|
+
case "source":
|
|
348
|
+
case "file":
|
|
349
|
+
default:
|
|
350
|
+
await emitter.emit("watch-v2", chunk);
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return {
|
|
355
|
+
text: await streamPromise.promise
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
if (params instanceof Tool) {
|
|
361
|
+
if (!params.inputSchema || !params.outputSchema) {
|
|
362
|
+
throw new Error("Tool must have input and output schemas defined");
|
|
363
|
+
}
|
|
364
|
+
return {
|
|
365
|
+
// TODO: tool probably should have strong id type
|
|
366
|
+
// @ts-ignore
|
|
367
|
+
id: params.id,
|
|
368
|
+
inputSchema: params.inputSchema,
|
|
369
|
+
outputSchema: params.outputSchema,
|
|
370
|
+
execute: async ({ inputData, mastra, runtimeContext }) => {
|
|
371
|
+
return params.execute({
|
|
372
|
+
context: inputData,
|
|
373
|
+
mastra,
|
|
374
|
+
runtimeContext
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
return {
|
|
380
|
+
id: params.id,
|
|
381
|
+
description: params.description,
|
|
382
|
+
inputSchema: params.inputSchema,
|
|
383
|
+
outputSchema: params.outputSchema,
|
|
384
|
+
resumeSchema: params.resumeSchema,
|
|
385
|
+
suspendSchema: params.suspendSchema,
|
|
386
|
+
execute: params.execute
|
|
387
|
+
};
|
|
279
388
|
}
|
|
280
389
|
function init(inngest) {
|
|
281
390
|
return {
|
|
@@ -283,8 +392,27 @@ function init(inngest) {
|
|
|
283
392
|
return new InngestWorkflow(params, inngest);
|
|
284
393
|
},
|
|
285
394
|
createStep,
|
|
286
|
-
cloneStep,
|
|
287
|
-
|
|
395
|
+
cloneStep(step, opts) {
|
|
396
|
+
return {
|
|
397
|
+
id: opts.id,
|
|
398
|
+
description: step.description,
|
|
399
|
+
inputSchema: step.inputSchema,
|
|
400
|
+
outputSchema: step.outputSchema,
|
|
401
|
+
execute: step.execute
|
|
402
|
+
};
|
|
403
|
+
},
|
|
404
|
+
cloneWorkflow(workflow, opts) {
|
|
405
|
+
const wf = new Workflow({
|
|
406
|
+
id: opts.id,
|
|
407
|
+
inputSchema: workflow.inputSchema,
|
|
408
|
+
outputSchema: workflow.outputSchema,
|
|
409
|
+
steps: workflow.stepDefs,
|
|
410
|
+
mastra: workflow.mastra
|
|
411
|
+
});
|
|
412
|
+
wf.setStepFlow(workflow.stepGraph);
|
|
413
|
+
wf.commit();
|
|
414
|
+
return wf;
|
|
415
|
+
}
|
|
288
416
|
};
|
|
289
417
|
}
|
|
290
418
|
var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
@@ -375,6 +503,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
375
503
|
runtimeContext
|
|
376
504
|
});
|
|
377
505
|
}
|
|
506
|
+
async executeSleep({ id, duration }) {
|
|
507
|
+
await this.inngestStep.sleep(id, duration);
|
|
508
|
+
}
|
|
378
509
|
async executeStep({
|
|
379
510
|
step,
|
|
380
511
|
stepResults,
|
|
@@ -555,6 +686,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
555
686
|
let suspended;
|
|
556
687
|
try {
|
|
557
688
|
const result = await step.execute({
|
|
689
|
+
runId: executionContext.runId,
|
|
558
690
|
mastra: this.mastra,
|
|
559
691
|
runtimeContext,
|
|
560
692
|
inputData: prevOutput,
|
|
@@ -577,7 +709,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
577
709
|
// @ts-ignore
|
|
578
710
|
runId: stepResults[step.id]?.payload?.__workflow_meta?.runId
|
|
579
711
|
},
|
|
580
|
-
emitter
|
|
712
|
+
[EMITTER_SYMBOL]: emitter,
|
|
713
|
+
engine: {
|
|
714
|
+
step: this.inngestStep
|
|
715
|
+
}
|
|
581
716
|
});
|
|
582
717
|
execResults = { status: "success", output: result };
|
|
583
718
|
} catch (e) {
|
|
@@ -618,7 +753,11 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
618
753
|
workflowId,
|
|
619
754
|
runId,
|
|
620
755
|
stepResults,
|
|
621
|
-
executionContext
|
|
756
|
+
executionContext,
|
|
757
|
+
serializedStepGraph,
|
|
758
|
+
workflowStatus,
|
|
759
|
+
result,
|
|
760
|
+
error
|
|
622
761
|
}) {
|
|
623
762
|
await this.inngestStep.run(
|
|
624
763
|
`workflow.${workflowId}.run.${runId}.path.${JSON.stringify(executionContext.executionPath)}.stepUpdate`,
|
|
@@ -632,6 +771,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
632
771
|
context: stepResults,
|
|
633
772
|
activePaths: [],
|
|
634
773
|
suspendedPaths: executionContext.suspendedPaths,
|
|
774
|
+
serializedStepGraph,
|
|
775
|
+
status: workflowStatus,
|
|
776
|
+
result,
|
|
777
|
+
error,
|
|
635
778
|
// @ts-ignore
|
|
636
779
|
timestamp: Date.now()
|
|
637
780
|
}
|
|
@@ -646,6 +789,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
646
789
|
prevOutput,
|
|
647
790
|
prevStep,
|
|
648
791
|
stepResults,
|
|
792
|
+
serializedStepGraph,
|
|
649
793
|
resume,
|
|
650
794
|
executionContext,
|
|
651
795
|
emitter,
|
|
@@ -657,6 +801,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
657
801
|
(cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
|
|
658
802
|
try {
|
|
659
803
|
const result = await cond({
|
|
804
|
+
runId,
|
|
660
805
|
mastra: this.mastra,
|
|
661
806
|
runtimeContext,
|
|
662
807
|
inputData: prevOutput,
|
|
@@ -674,7 +819,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
674
819
|
// TODO: this function shouldn't have suspend probably?
|
|
675
820
|
suspend: async (_suspendPayload) => {
|
|
676
821
|
},
|
|
677
|
-
[EMITTER_SYMBOL]: emitter
|
|
822
|
+
[EMITTER_SYMBOL]: emitter,
|
|
823
|
+
engine: {
|
|
824
|
+
step: this.inngestStep
|
|
825
|
+
}
|
|
678
826
|
});
|
|
679
827
|
return result ? index : null;
|
|
680
828
|
} catch (e) {
|
|
@@ -693,6 +841,7 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
693
841
|
prevStep,
|
|
694
842
|
stepResults,
|
|
695
843
|
resume,
|
|
844
|
+
serializedStepGraph,
|
|
696
845
|
executionContext: {
|
|
697
846
|
workflowId,
|
|
698
847
|
runId,
|
|
@@ -706,17 +855,17 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
706
855
|
})
|
|
707
856
|
)
|
|
708
857
|
);
|
|
709
|
-
const hasFailed = results.find((result) => result.status === "failed");
|
|
710
|
-
const hasSuspended = results.find((result) => result.status === "suspended");
|
|
858
|
+
const hasFailed = results.find((result) => result.result.status === "failed");
|
|
859
|
+
const hasSuspended = results.find((result) => result.result.status === "suspended");
|
|
711
860
|
if (hasFailed) {
|
|
712
|
-
execResults = { status: "failed", error: hasFailed.error };
|
|
861
|
+
execResults = { status: "failed", error: hasFailed.result.error };
|
|
713
862
|
} else if (hasSuspended) {
|
|
714
|
-
execResults = { status: "suspended", payload: hasSuspended.payload };
|
|
863
|
+
execResults = { status: "suspended", payload: hasSuspended.result.payload };
|
|
715
864
|
} else {
|
|
716
865
|
execResults = {
|
|
717
866
|
status: "success",
|
|
718
867
|
output: results.reduce((acc, result, index) => {
|
|
719
|
-
if (result.status === "success") {
|
|
868
|
+
if (result.result.status === "success") {
|
|
720
869
|
acc[stepsToRun[index].step.id] = result.output;
|
|
721
870
|
}
|
|
722
871
|
return acc;
|
|
@@ -727,4 +876,4 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
727
876
|
}
|
|
728
877
|
};
|
|
729
878
|
|
|
730
|
-
export { InngestExecutionEngine, InngestRun, InngestWorkflow, init, serve };
|
|
879
|
+
export { InngestExecutionEngine, InngestRun, InngestWorkflow, createStep, init, serve };
|
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-fix-generate-title-20250616171351",
|
|
4
4
|
"description": "Mastra Inngest integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,29 +20,30 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@inngest/realtime": "^0.3.1",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
23
|
+
"@opentelemetry/api": "^1.9.0",
|
|
24
|
+
"inngest": "^3.39.1",
|
|
25
|
+
"zod": "^3.25.57"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@ai-sdk/openai": "^1.3.22",
|
|
29
|
-
"@hono/node-server": "^1.14.
|
|
30
|
-
"@microsoft/api-extractor": "^7.52.
|
|
31
|
-
"@types/node": "^20.
|
|
32
|
-
"ai": "^4.3.
|
|
33
|
-
"eslint": "^9.
|
|
34
|
-
"execa": "^9.
|
|
29
|
+
"@hono/node-server": "^1.14.4",
|
|
30
|
+
"@microsoft/api-extractor": "^7.52.8",
|
|
31
|
+
"@types/node": "^20.19.0",
|
|
32
|
+
"ai": "^4.3.16",
|
|
33
|
+
"eslint": "^9.28.0",
|
|
34
|
+
"execa": "^9.6.0",
|
|
35
35
|
"get-port": "7.1.0",
|
|
36
|
-
"hono": "^4.7.
|
|
37
|
-
"tsup": "^8.
|
|
38
|
-
"typescript": "^5.8.
|
|
36
|
+
"hono": "^4.7.11",
|
|
37
|
+
"tsup": "^8.5.0",
|
|
38
|
+
"typescript": "^5.8.3",
|
|
39
39
|
"vitest": "^2.1.9",
|
|
40
|
-
"@internal/lint": "0.0.0-
|
|
41
|
-
"@mastra/
|
|
42
|
-
"@mastra/core": "0.0.0-
|
|
40
|
+
"@internal/lint": "0.0.0-fix-generate-title-20250616171351",
|
|
41
|
+
"@mastra/libsql": "0.0.0-fix-generate-title-20250616171351",
|
|
42
|
+
"@mastra/core": "0.0.0-fix-generate-title-20250616171351",
|
|
43
|
+
"@mastra/deployer": "0.0.0-fix-generate-title-20250616171351"
|
|
43
44
|
},
|
|
44
45
|
"peerDependencies": {
|
|
45
|
-
"@mastra/core": "
|
|
46
|
+
"@mastra/core": "0.0.0-fix-generate-title-20250616171351"
|
|
46
47
|
},
|
|
47
48
|
"scripts": {
|
|
48
49
|
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|