@mastra/inngest 0.10.3 → 0.10.5-alpha.0
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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +21 -0
- package/dist/_tsup-dts-rollup.d.cts +48 -14
- package/dist/_tsup-dts-rollup.d.ts +48 -14
- package/dist/index.cjs +144 -26
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +144 -27
- package/package.json +13 -12
- package/src/index.test.ts +228 -137
- package/src/index.ts +275 -40
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 }) {
|
|
@@ -63,7 +65,8 @@ var InngestRun = class extends Run {
|
|
|
63
65
|
context: {},
|
|
64
66
|
activePaths: [],
|
|
65
67
|
suspendedPaths: {},
|
|
66
|
-
timestamp: Date.now()
|
|
68
|
+
timestamp: Date.now(),
|
|
69
|
+
status: "running"
|
|
67
70
|
}
|
|
68
71
|
});
|
|
69
72
|
const eventOutput = await this.inngest.send({
|
|
@@ -267,20 +270,100 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
267
270
|
return [this.getFunction(), ...this.getNestedFunctions(this.executionGraph.steps)];
|
|
268
271
|
}
|
|
269
272
|
};
|
|
270
|
-
function
|
|
271
|
-
|
|
272
|
-
{
|
|
273
|
-
id:
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
273
|
+
function createStep(params) {
|
|
274
|
+
if (params instanceof Agent) {
|
|
275
|
+
return {
|
|
276
|
+
id: params.name,
|
|
277
|
+
// @ts-ignore
|
|
278
|
+
inputSchema: z.object({
|
|
279
|
+
prompt: z.string()
|
|
280
|
+
// resourceId: z.string().optional(),
|
|
281
|
+
// threadId: z.string().optional(),
|
|
282
|
+
}),
|
|
283
|
+
// @ts-ignore
|
|
284
|
+
outputSchema: z.object({
|
|
285
|
+
text: z.string()
|
|
286
|
+
}),
|
|
287
|
+
execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext }) => {
|
|
288
|
+
let streamPromise = {};
|
|
289
|
+
streamPromise.promise = new Promise((resolve, reject) => {
|
|
290
|
+
streamPromise.resolve = resolve;
|
|
291
|
+
streamPromise.reject = reject;
|
|
292
|
+
});
|
|
293
|
+
const toolData = {
|
|
294
|
+
name: params.name,
|
|
295
|
+
args: inputData
|
|
296
|
+
};
|
|
297
|
+
await emitter.emit("watch-v2", {
|
|
298
|
+
type: "tool-call-streaming-start",
|
|
299
|
+
...toolData
|
|
300
|
+
});
|
|
301
|
+
const { fullStream } = await params.stream(inputData.prompt, {
|
|
302
|
+
// resourceId: inputData.resourceId,
|
|
303
|
+
// threadId: inputData.threadId,
|
|
304
|
+
runtimeContext,
|
|
305
|
+
onFinish: (result) => {
|
|
306
|
+
streamPromise.resolve(result.text);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
for await (const chunk of fullStream) {
|
|
310
|
+
switch (chunk.type) {
|
|
311
|
+
case "text-delta":
|
|
312
|
+
await emitter.emit("watch-v2", {
|
|
313
|
+
type: "tool-call-delta",
|
|
314
|
+
...toolData,
|
|
315
|
+
argsTextDelta: chunk.textDelta
|
|
316
|
+
});
|
|
317
|
+
break;
|
|
318
|
+
case "step-start":
|
|
319
|
+
case "step-finish":
|
|
320
|
+
case "finish":
|
|
321
|
+
break;
|
|
322
|
+
case "tool-call":
|
|
323
|
+
case "tool-result":
|
|
324
|
+
case "tool-call-streaming-start":
|
|
325
|
+
case "tool-call-delta":
|
|
326
|
+
case "source":
|
|
327
|
+
case "file":
|
|
328
|
+
default:
|
|
329
|
+
await emitter.emit("watch-v2", chunk);
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return {
|
|
334
|
+
text: await streamPromise.promise
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
if (params instanceof Tool) {
|
|
340
|
+
if (!params.inputSchema || !params.outputSchema) {
|
|
341
|
+
throw new Error("Tool must have input and output schemas defined");
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
// TODO: tool probably should have strong id type
|
|
345
|
+
// @ts-ignore
|
|
346
|
+
id: params.id,
|
|
347
|
+
inputSchema: params.inputSchema,
|
|
348
|
+
outputSchema: params.outputSchema,
|
|
349
|
+
execute: async ({ inputData, mastra, runtimeContext }) => {
|
|
350
|
+
return params.execute({
|
|
351
|
+
context: inputData,
|
|
352
|
+
mastra,
|
|
353
|
+
runtimeContext
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
return {
|
|
359
|
+
id: params.id,
|
|
360
|
+
description: params.description,
|
|
361
|
+
inputSchema: params.inputSchema,
|
|
362
|
+
outputSchema: params.outputSchema,
|
|
363
|
+
resumeSchema: params.resumeSchema,
|
|
364
|
+
suspendSchema: params.suspendSchema,
|
|
365
|
+
execute: params.execute
|
|
366
|
+
};
|
|
284
367
|
}
|
|
285
368
|
function init(inngest) {
|
|
286
369
|
return {
|
|
@@ -288,8 +371,27 @@ function init(inngest) {
|
|
|
288
371
|
return new InngestWorkflow(params, inngest);
|
|
289
372
|
},
|
|
290
373
|
createStep,
|
|
291
|
-
cloneStep,
|
|
292
|
-
|
|
374
|
+
cloneStep(step, opts) {
|
|
375
|
+
return {
|
|
376
|
+
id: opts.id,
|
|
377
|
+
description: step.description,
|
|
378
|
+
inputSchema: step.inputSchema,
|
|
379
|
+
outputSchema: step.outputSchema,
|
|
380
|
+
execute: step.execute
|
|
381
|
+
};
|
|
382
|
+
},
|
|
383
|
+
cloneWorkflow(workflow, opts) {
|
|
384
|
+
const wf = new Workflow({
|
|
385
|
+
id: opts.id,
|
|
386
|
+
inputSchema: workflow.inputSchema,
|
|
387
|
+
outputSchema: workflow.outputSchema,
|
|
388
|
+
steps: workflow.stepDefs,
|
|
389
|
+
mastra: workflow.mastra
|
|
390
|
+
});
|
|
391
|
+
wf.setStepFlow(workflow.stepGraph);
|
|
392
|
+
wf.commit();
|
|
393
|
+
return wf;
|
|
394
|
+
}
|
|
293
395
|
};
|
|
294
396
|
}
|
|
295
397
|
var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
@@ -380,6 +482,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
380
482
|
runtimeContext
|
|
381
483
|
});
|
|
382
484
|
}
|
|
485
|
+
async executeSleep({ id, duration }) {
|
|
486
|
+
await this.inngestStep.sleep(id, duration);
|
|
487
|
+
}
|
|
383
488
|
async executeStep({
|
|
384
489
|
step,
|
|
385
490
|
stepResults,
|
|
@@ -583,7 +688,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
583
688
|
// @ts-ignore
|
|
584
689
|
runId: stepResults[step.id]?.payload?.__workflow_meta?.runId
|
|
585
690
|
},
|
|
586
|
-
emitter
|
|
691
|
+
[EMITTER_SYMBOL]: emitter,
|
|
692
|
+
engine: {
|
|
693
|
+
step: this.inngestStep
|
|
694
|
+
}
|
|
587
695
|
});
|
|
588
696
|
execResults = { status: "success", output: result };
|
|
589
697
|
} catch (e) {
|
|
@@ -625,7 +733,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
625
733
|
runId,
|
|
626
734
|
stepResults,
|
|
627
735
|
executionContext,
|
|
628
|
-
serializedStepGraph
|
|
736
|
+
serializedStepGraph,
|
|
737
|
+
workflowStatus,
|
|
738
|
+
result,
|
|
739
|
+
error
|
|
629
740
|
}) {
|
|
630
741
|
await this.inngestStep.run(
|
|
631
742
|
`workflow.${workflowId}.run.${runId}.path.${JSON.stringify(executionContext.executionPath)}.stepUpdate`,
|
|
@@ -640,6 +751,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
640
751
|
activePaths: [],
|
|
641
752
|
suspendedPaths: executionContext.suspendedPaths,
|
|
642
753
|
serializedStepGraph,
|
|
754
|
+
status: workflowStatus,
|
|
755
|
+
result,
|
|
756
|
+
error,
|
|
643
757
|
// @ts-ignore
|
|
644
758
|
timestamp: Date.now()
|
|
645
759
|
}
|
|
@@ -684,7 +798,10 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
684
798
|
// TODO: this function shouldn't have suspend probably?
|
|
685
799
|
suspend: async (_suspendPayload) => {
|
|
686
800
|
},
|
|
687
|
-
[EMITTER_SYMBOL]: emitter
|
|
801
|
+
[EMITTER_SYMBOL]: emitter,
|
|
802
|
+
engine: {
|
|
803
|
+
step: this.inngestStep
|
|
804
|
+
}
|
|
688
805
|
});
|
|
689
806
|
return result ? index : null;
|
|
690
807
|
} catch (e) {
|
|
@@ -717,17 +834,17 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
717
834
|
})
|
|
718
835
|
)
|
|
719
836
|
);
|
|
720
|
-
const hasFailed = results.find((result) => result.status === "failed");
|
|
721
|
-
const hasSuspended = results.find((result) => result.status === "suspended");
|
|
837
|
+
const hasFailed = results.find((result) => result.result.status === "failed");
|
|
838
|
+
const hasSuspended = results.find((result) => result.result.status === "suspended");
|
|
722
839
|
if (hasFailed) {
|
|
723
|
-
execResults = { status: "failed", error: hasFailed.error };
|
|
840
|
+
execResults = { status: "failed", error: hasFailed.result.error };
|
|
724
841
|
} else if (hasSuspended) {
|
|
725
|
-
execResults = { status: "suspended", payload: hasSuspended.payload };
|
|
842
|
+
execResults = { status: "suspended", payload: hasSuspended.result.payload };
|
|
726
843
|
} else {
|
|
727
844
|
execResults = {
|
|
728
845
|
status: "success",
|
|
729
846
|
output: results.reduce((acc, result, index) => {
|
|
730
|
-
if (result.status === "success") {
|
|
847
|
+
if (result.result.status === "success") {
|
|
731
848
|
acc[stepsToRun[index].step.id] = result.output;
|
|
732
849
|
}
|
|
733
850
|
return acc;
|
|
@@ -738,4 +855,4 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
738
855
|
}
|
|
739
856
|
};
|
|
740
857
|
|
|
741
|
-
export { InngestExecutionEngine, InngestRun, InngestWorkflow, init, serve };
|
|
858
|
+
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.10.
|
|
3
|
+
"version": "0.10.5-alpha.0",
|
|
4
4
|
"description": "Mastra Inngest integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,26 +20,27 @@
|
|
|
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.
|
|
29
|
+
"@hono/node-server": "^1.14.4",
|
|
30
30
|
"@microsoft/api-extractor": "^7.52.8",
|
|
31
|
-
"@types/node": "^20.
|
|
32
|
-
"ai": "^4.3.
|
|
31
|
+
"@types/node": "^20.19.0",
|
|
32
|
+
"ai": "^4.3.16",
|
|
33
33
|
"eslint": "^9.28.0",
|
|
34
34
|
"execa": "^9.6.0",
|
|
35
35
|
"get-port": "7.1.0",
|
|
36
|
-
"hono": "^4.7.
|
|
36
|
+
"hono": "^4.7.11",
|
|
37
37
|
"tsup": "^8.5.0",
|
|
38
|
-
"typescript": "^5.8.
|
|
38
|
+
"typescript": "^5.8.3",
|
|
39
39
|
"vitest": "^2.1.9",
|
|
40
|
-
"@internal/lint": "0.0.
|
|
41
|
-
"@mastra/core": "0.10.
|
|
42
|
-
"@mastra/
|
|
40
|
+
"@internal/lint": "0.0.12",
|
|
41
|
+
"@mastra/core": "0.10.6-alpha.0",
|
|
42
|
+
"@mastra/libsql": "0.10.3-alpha.0",
|
|
43
|
+
"@mastra/deployer": "0.10.6-alpha.0"
|
|
43
44
|
},
|
|
44
45
|
"peerDependencies": {
|
|
45
46
|
"@mastra/core": "^0.10.2-alpha.0"
|