@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.cjs
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
var crypto = require('crypto');
|
|
4
4
|
var realtime = require('@inngest/realtime');
|
|
5
|
+
var core = require('@mastra/core');
|
|
5
6
|
var di = require('@mastra/core/di');
|
|
6
7
|
var workflows = require('@mastra/core/workflows');
|
|
7
8
|
var _constants = require('@mastra/core/workflows/_constants');
|
|
8
9
|
var hono = require('inngest/hono');
|
|
10
|
+
var zod = require('zod');
|
|
9
11
|
|
|
10
12
|
// src/index.ts
|
|
11
13
|
function serve({ mastra, inngest }) {
|
|
@@ -24,14 +26,16 @@ function serve({ mastra, inngest }) {
|
|
|
24
26
|
}
|
|
25
27
|
var InngestRun = class extends workflows.Run {
|
|
26
28
|
inngest;
|
|
29
|
+
serializedStepGraph;
|
|
27
30
|
#mastra;
|
|
28
31
|
constructor(params, inngest) {
|
|
29
32
|
super(params);
|
|
30
33
|
this.inngest = inngest;
|
|
34
|
+
this.serializedStepGraph = params.serializedStepGraph;
|
|
31
35
|
this.#mastra = params.mastra;
|
|
32
36
|
}
|
|
33
37
|
async getRuns(eventId) {
|
|
34
|
-
const response = await fetch(`${this.inngest.apiBaseUrl}/v1/events/${eventId}/runs`, {
|
|
38
|
+
const response = await fetch(`${this.inngest.apiBaseUrl ?? "https://api.inngest.com"}/v1/events/${eventId}/runs`, {
|
|
35
39
|
headers: {
|
|
36
40
|
Authorization: `Bearer ${process.env.INNGEST_SIGNING_KEY}`
|
|
37
41
|
}
|
|
@@ -58,11 +62,13 @@ var InngestRun = class extends workflows.Run {
|
|
|
58
62
|
runId: this.runId,
|
|
59
63
|
snapshot: {
|
|
60
64
|
runId: this.runId,
|
|
65
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
61
66
|
value: {},
|
|
62
67
|
context: {},
|
|
63
68
|
activePaths: [],
|
|
64
69
|
suspendedPaths: {},
|
|
65
|
-
timestamp: Date.now()
|
|
70
|
+
timestamp: Date.now(),
|
|
71
|
+
status: "running"
|
|
66
72
|
}
|
|
67
73
|
});
|
|
68
74
|
const eventOutput = await this.inngest.send({
|
|
@@ -159,11 +165,32 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
159
165
|
const storage = this.#mastra?.getStorage();
|
|
160
166
|
if (!storage) {
|
|
161
167
|
this.logger.debug("Cannot get workflow runs. Mastra engine is not initialized");
|
|
162
|
-
return null;
|
|
168
|
+
return this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null;
|
|
163
169
|
}
|
|
164
170
|
const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
|
|
165
171
|
return run ?? (this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null);
|
|
166
172
|
}
|
|
173
|
+
async getWorkflowRunExecutionResult(runId) {
|
|
174
|
+
const storage = this.#mastra?.getStorage();
|
|
175
|
+
if (!storage) {
|
|
176
|
+
this.logger.debug("Cannot get workflow run execution result. Mastra storage is not initialized");
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
|
|
180
|
+
if (!run?.snapshot) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
if (typeof run.snapshot === "string") {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
status: run.snapshot.status,
|
|
188
|
+
result: run.snapshot.result,
|
|
189
|
+
error: run.snapshot.error,
|
|
190
|
+
payload: run.snapshot.context?.input,
|
|
191
|
+
steps: run.snapshot.context
|
|
192
|
+
};
|
|
193
|
+
}
|
|
167
194
|
__registerMastra(mastra) {
|
|
168
195
|
this.#mastra = mastra;
|
|
169
196
|
this.executionEngine.__registerMastra(mastra);
|
|
@@ -190,6 +217,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
190
217
|
runId: runIdToUse,
|
|
191
218
|
executionEngine: this.executionEngine,
|
|
192
219
|
executionGraph: this.executionGraph,
|
|
220
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
193
221
|
mastra: this.#mastra,
|
|
194
222
|
retryConfig: this.retryConfig,
|
|
195
223
|
cleanup: () => this.runs.delete(runIdToUse)
|
|
@@ -235,6 +263,7 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
235
263
|
workflowId: this.id,
|
|
236
264
|
runId,
|
|
237
265
|
graph: this.executionGraph,
|
|
266
|
+
serializedStepGraph: this.serializedStepGraph,
|
|
238
267
|
input: inputData,
|
|
239
268
|
emitter,
|
|
240
269
|
retryConfig: this.retryConfig,
|
|
@@ -264,29 +293,128 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
264
293
|
return [this.getFunction(), ...this.getNestedFunctions(this.executionGraph.steps)];
|
|
265
294
|
}
|
|
266
295
|
};
|
|
267
|
-
function
|
|
268
|
-
|
|
269
|
-
{
|
|
270
|
-
id:
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
296
|
+
function createStep(params) {
|
|
297
|
+
if (params instanceof core.Agent) {
|
|
298
|
+
return {
|
|
299
|
+
id: params.name,
|
|
300
|
+
// @ts-ignore
|
|
301
|
+
inputSchema: zod.z.object({
|
|
302
|
+
prompt: zod.z.string()
|
|
303
|
+
// resourceId: z.string().optional(),
|
|
304
|
+
// threadId: z.string().optional(),
|
|
305
|
+
}),
|
|
306
|
+
// @ts-ignore
|
|
307
|
+
outputSchema: zod.z.object({
|
|
308
|
+
text: zod.z.string()
|
|
309
|
+
}),
|
|
310
|
+
execute: async ({ inputData, [_constants.EMITTER_SYMBOL]: emitter, runtimeContext }) => {
|
|
311
|
+
let streamPromise = {};
|
|
312
|
+
streamPromise.promise = new Promise((resolve, reject) => {
|
|
313
|
+
streamPromise.resolve = resolve;
|
|
314
|
+
streamPromise.reject = reject;
|
|
315
|
+
});
|
|
316
|
+
const toolData = {
|
|
317
|
+
name: params.name,
|
|
318
|
+
args: inputData
|
|
319
|
+
};
|
|
320
|
+
await emitter.emit("watch-v2", {
|
|
321
|
+
type: "tool-call-streaming-start",
|
|
322
|
+
...toolData
|
|
323
|
+
});
|
|
324
|
+
const { fullStream } = await params.stream(inputData.prompt, {
|
|
325
|
+
// resourceId: inputData.resourceId,
|
|
326
|
+
// threadId: inputData.threadId,
|
|
327
|
+
runtimeContext,
|
|
328
|
+
onFinish: (result) => {
|
|
329
|
+
streamPromise.resolve(result.text);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
for await (const chunk of fullStream) {
|
|
333
|
+
switch (chunk.type) {
|
|
334
|
+
case "text-delta":
|
|
335
|
+
await emitter.emit("watch-v2", {
|
|
336
|
+
type: "tool-call-delta",
|
|
337
|
+
...toolData,
|
|
338
|
+
argsTextDelta: chunk.textDelta
|
|
339
|
+
});
|
|
340
|
+
break;
|
|
341
|
+
case "step-start":
|
|
342
|
+
case "step-finish":
|
|
343
|
+
case "finish":
|
|
344
|
+
break;
|
|
345
|
+
case "tool-call":
|
|
346
|
+
case "tool-result":
|
|
347
|
+
case "tool-call-streaming-start":
|
|
348
|
+
case "tool-call-delta":
|
|
349
|
+
case "source":
|
|
350
|
+
case "file":
|
|
351
|
+
default:
|
|
352
|
+
await emitter.emit("watch-v2", chunk);
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return {
|
|
357
|
+
text: await streamPromise.promise
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
if (params instanceof core.Tool) {
|
|
363
|
+
if (!params.inputSchema || !params.outputSchema) {
|
|
364
|
+
throw new Error("Tool must have input and output schemas defined");
|
|
365
|
+
}
|
|
366
|
+
return {
|
|
367
|
+
// TODO: tool probably should have strong id type
|
|
368
|
+
// @ts-ignore
|
|
369
|
+
id: params.id,
|
|
370
|
+
inputSchema: params.inputSchema,
|
|
371
|
+
outputSchema: params.outputSchema,
|
|
372
|
+
execute: async ({ inputData, mastra, runtimeContext }) => {
|
|
373
|
+
return params.execute({
|
|
374
|
+
context: inputData,
|
|
375
|
+
mastra,
|
|
376
|
+
runtimeContext
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
return {
|
|
382
|
+
id: params.id,
|
|
383
|
+
description: params.description,
|
|
384
|
+
inputSchema: params.inputSchema,
|
|
385
|
+
outputSchema: params.outputSchema,
|
|
386
|
+
resumeSchema: params.resumeSchema,
|
|
387
|
+
suspendSchema: params.suspendSchema,
|
|
388
|
+
execute: params.execute
|
|
389
|
+
};
|
|
281
390
|
}
|
|
282
391
|
function init(inngest) {
|
|
283
392
|
return {
|
|
284
393
|
createWorkflow(params) {
|
|
285
394
|
return new InngestWorkflow(params, inngest);
|
|
286
395
|
},
|
|
287
|
-
createStep
|
|
288
|
-
cloneStep
|
|
289
|
-
|
|
396
|
+
createStep,
|
|
397
|
+
cloneStep(step, opts) {
|
|
398
|
+
return {
|
|
399
|
+
id: opts.id,
|
|
400
|
+
description: step.description,
|
|
401
|
+
inputSchema: step.inputSchema,
|
|
402
|
+
outputSchema: step.outputSchema,
|
|
403
|
+
execute: step.execute
|
|
404
|
+
};
|
|
405
|
+
},
|
|
406
|
+
cloneWorkflow(workflow, opts) {
|
|
407
|
+
const wf = new workflows.Workflow({
|
|
408
|
+
id: opts.id,
|
|
409
|
+
inputSchema: workflow.inputSchema,
|
|
410
|
+
outputSchema: workflow.outputSchema,
|
|
411
|
+
steps: workflow.stepDefs,
|
|
412
|
+
mastra: workflow.mastra
|
|
413
|
+
});
|
|
414
|
+
wf.setStepFlow(workflow.stepGraph);
|
|
415
|
+
wf.commit();
|
|
416
|
+
return wf;
|
|
417
|
+
}
|
|
290
418
|
};
|
|
291
419
|
}
|
|
292
420
|
var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
@@ -377,6 +505,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
377
505
|
runtimeContext
|
|
378
506
|
});
|
|
379
507
|
}
|
|
508
|
+
async executeSleep({ id, duration }) {
|
|
509
|
+
await this.inngestStep.sleep(id, duration);
|
|
510
|
+
}
|
|
380
511
|
async executeStep({
|
|
381
512
|
step,
|
|
382
513
|
stepResults,
|
|
@@ -557,6 +688,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
557
688
|
let suspended;
|
|
558
689
|
try {
|
|
559
690
|
const result = await step.execute({
|
|
691
|
+
runId: executionContext.runId,
|
|
560
692
|
mastra: this.mastra,
|
|
561
693
|
runtimeContext,
|
|
562
694
|
inputData: prevOutput,
|
|
@@ -579,7 +711,10 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
579
711
|
// @ts-ignore
|
|
580
712
|
runId: stepResults[step.id]?.payload?.__workflow_meta?.runId
|
|
581
713
|
},
|
|
582
|
-
emitter
|
|
714
|
+
[_constants.EMITTER_SYMBOL]: emitter,
|
|
715
|
+
engine: {
|
|
716
|
+
step: this.inngestStep
|
|
717
|
+
}
|
|
583
718
|
});
|
|
584
719
|
execResults = { status: "success", output: result };
|
|
585
720
|
} catch (e) {
|
|
@@ -620,7 +755,11 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
620
755
|
workflowId,
|
|
621
756
|
runId,
|
|
622
757
|
stepResults,
|
|
623
|
-
executionContext
|
|
758
|
+
executionContext,
|
|
759
|
+
serializedStepGraph,
|
|
760
|
+
workflowStatus,
|
|
761
|
+
result,
|
|
762
|
+
error
|
|
624
763
|
}) {
|
|
625
764
|
await this.inngestStep.run(
|
|
626
765
|
`workflow.${workflowId}.run.${runId}.path.${JSON.stringify(executionContext.executionPath)}.stepUpdate`,
|
|
@@ -634,6 +773,10 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
634
773
|
context: stepResults,
|
|
635
774
|
activePaths: [],
|
|
636
775
|
suspendedPaths: executionContext.suspendedPaths,
|
|
776
|
+
serializedStepGraph,
|
|
777
|
+
status: workflowStatus,
|
|
778
|
+
result,
|
|
779
|
+
error,
|
|
637
780
|
// @ts-ignore
|
|
638
781
|
timestamp: Date.now()
|
|
639
782
|
}
|
|
@@ -648,6 +791,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
648
791
|
prevOutput,
|
|
649
792
|
prevStep,
|
|
650
793
|
stepResults,
|
|
794
|
+
serializedStepGraph,
|
|
651
795
|
resume,
|
|
652
796
|
executionContext,
|
|
653
797
|
emitter,
|
|
@@ -659,6 +803,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
659
803
|
(cond, index) => this.inngestStep.run(`workflow.${workflowId}.conditional.${index}`, async () => {
|
|
660
804
|
try {
|
|
661
805
|
const result = await cond({
|
|
806
|
+
runId,
|
|
662
807
|
mastra: this.mastra,
|
|
663
808
|
runtimeContext,
|
|
664
809
|
inputData: prevOutput,
|
|
@@ -676,7 +821,10 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
676
821
|
// TODO: this function shouldn't have suspend probably?
|
|
677
822
|
suspend: async (_suspendPayload) => {
|
|
678
823
|
},
|
|
679
|
-
[_constants.EMITTER_SYMBOL]: emitter
|
|
824
|
+
[_constants.EMITTER_SYMBOL]: emitter,
|
|
825
|
+
engine: {
|
|
826
|
+
step: this.inngestStep
|
|
827
|
+
}
|
|
680
828
|
});
|
|
681
829
|
return result ? index : null;
|
|
682
830
|
} catch (e) {
|
|
@@ -695,6 +843,7 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
695
843
|
prevStep,
|
|
696
844
|
stepResults,
|
|
697
845
|
resume,
|
|
846
|
+
serializedStepGraph,
|
|
698
847
|
executionContext: {
|
|
699
848
|
workflowId,
|
|
700
849
|
runId,
|
|
@@ -708,17 +857,17 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
708
857
|
})
|
|
709
858
|
)
|
|
710
859
|
);
|
|
711
|
-
const hasFailed = results.find((result) => result.status === "failed");
|
|
712
|
-
const hasSuspended = results.find((result) => result.status === "suspended");
|
|
860
|
+
const hasFailed = results.find((result) => result.result.status === "failed");
|
|
861
|
+
const hasSuspended = results.find((result) => result.result.status === "suspended");
|
|
713
862
|
if (hasFailed) {
|
|
714
|
-
execResults = { status: "failed", error: hasFailed.error };
|
|
863
|
+
execResults = { status: "failed", error: hasFailed.result.error };
|
|
715
864
|
} else if (hasSuspended) {
|
|
716
|
-
execResults = { status: "suspended", payload: hasSuspended.payload };
|
|
865
|
+
execResults = { status: "suspended", payload: hasSuspended.result.payload };
|
|
717
866
|
} else {
|
|
718
867
|
execResults = {
|
|
719
868
|
status: "success",
|
|
720
869
|
output: results.reduce((acc, result, index) => {
|
|
721
|
-
if (result.status === "success") {
|
|
870
|
+
if (result.result.status === "success") {
|
|
722
871
|
acc[stepsToRun[index].step.id] = result.output;
|
|
723
872
|
}
|
|
724
873
|
return acc;
|
|
@@ -732,5 +881,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
732
881
|
exports.InngestExecutionEngine = InngestExecutionEngine;
|
|
733
882
|
exports.InngestRun = InngestRun;
|
|
734
883
|
exports.InngestWorkflow = InngestWorkflow;
|
|
884
|
+
exports.createStep = createStep;
|
|
735
885
|
exports.init = init;
|
|
736
886
|
exports.serve = serve;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { serve } from './_tsup-dts-rollup.cjs';
|
|
2
|
+
export { createStep } from './_tsup-dts-rollup.cjs';
|
|
2
3
|
export { init } from './_tsup-dts-rollup.cjs';
|
|
4
|
+
export { InngestEngineType } from './_tsup-dts-rollup.cjs';
|
|
3
5
|
export { InngestRun } from './_tsup-dts-rollup.cjs';
|
|
4
6
|
export { InngestWorkflow } from './_tsup-dts-rollup.cjs';
|
|
5
7
|
export { InngestExecutionEngine } from './_tsup-dts-rollup.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { serve } from './_tsup-dts-rollup.js';
|
|
2
|
+
export { createStep } from './_tsup-dts-rollup.js';
|
|
2
3
|
export { init } from './_tsup-dts-rollup.js';
|
|
4
|
+
export { InngestEngineType } from './_tsup-dts-rollup.js';
|
|
3
5
|
export { InngestRun } from './_tsup-dts-rollup.js';
|
|
4
6
|
export { InngestWorkflow } from './_tsup-dts-rollup.js';
|
|
5
7
|
export { InngestExecutionEngine } from './_tsup-dts-rollup.js';
|