@mastra/inngest 0.10.4 → 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 +13 -0
- package/dist/_tsup-dts-rollup.d.cts +39 -18
- package/dist/_tsup-dts-rollup.d.ts +39 -18
- package/dist/index.cjs +121 -18
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +122 -20
- package/package.json +12 -12
- package/src/index.test.ts +180 -1
- package/src/index.ts +239 -52
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/inngest@0.10.
|
|
2
|
+
> @mastra/inngest@0.10.5-alpha.0 build /home/runner/work/mastra/mastra/workflows/inngest
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.5.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 8463ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/workflows/inngest/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/workflows/inngest/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 6163ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
21
|
-
[32mESM[39m ⚡️ Build success in
|
|
22
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
23
|
-
[32mCJS[39m ⚡️ Build success in
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m25.94 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 270ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m26.13 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 271ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @mastra/inngest
|
|
2
2
|
|
|
3
|
+
## 0.10.5-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 63f6b7d: dependencies updates:
|
|
8
|
+
- Updated dependency [`inngest@^3.39.1` ↗︎](https://www.npmjs.com/package/inngest/v/3.39.1) (from `^3.35.1`, in `dependencies`)
|
|
9
|
+
- Updated dependency [`zod@^3.25.57` ↗︎](https://www.npmjs.com/package/zod/v/3.25.57) (from `^3.25.56`, in `dependencies`)
|
|
10
|
+
- Updated dependencies [63f6b7d]
|
|
11
|
+
- Updated dependencies [36f1c36]
|
|
12
|
+
- Updated dependencies [10d352e]
|
|
13
|
+
- Updated dependencies [53d3c37]
|
|
14
|
+
- @mastra/core@0.10.6-alpha.0
|
|
15
|
+
|
|
3
16
|
## 0.10.4
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Agent } from '@mastra/core';
|
|
1
2
|
import type { BaseContext } from 'inngest';
|
|
2
3
|
import { ClientOptions } from 'inngest';
|
|
3
|
-
import { cloneStep } from '@mastra/core/workflows';
|
|
4
4
|
import { DefaultExecutionEngine } from '@mastra/core/workflows';
|
|
5
5
|
import type { ExecuteFunction } from '@mastra/core/workflows';
|
|
6
6
|
import type { ExecutionContext } from '@mastra/core/workflows';
|
|
@@ -19,29 +19,46 @@ import type { Span } from '@opentelemetry/api';
|
|
|
19
19
|
import type { Step } from '@mastra/core/workflows';
|
|
20
20
|
import type { StepFlowEntry } from '@mastra/core/workflows';
|
|
21
21
|
import type { StepResult } from '@mastra/core/workflows';
|
|
22
|
+
import { Tool } from '@mastra/core';
|
|
23
|
+
import type { ToolExecutionContext } from '@mastra/core';
|
|
22
24
|
import { Workflow } from '@mastra/core/workflows';
|
|
23
25
|
import type { WorkflowConfig } from '@mastra/core/workflows';
|
|
24
26
|
import type { WorkflowResult } from '@mastra/core/workflows';
|
|
25
27
|
import type { WorkflowRun } from '@mastra/core';
|
|
26
28
|
import type { WorkflowRuns } from '@mastra/core';
|
|
27
|
-
import
|
|
29
|
+
import { z } from 'zod';
|
|
28
30
|
|
|
29
|
-
declare function
|
|
30
|
-
id:
|
|
31
|
-
|
|
31
|
+
export declare function createStep<TStepId extends string, TStepInput extends z.ZodType<any>, TStepOutput extends z.ZodType<any>, TResumeSchema extends z.ZodType<any>, TSuspendSchema extends z.ZodType<any>>(params: {
|
|
32
|
+
id: TStepId;
|
|
33
|
+
description?: string;
|
|
34
|
+
inputSchema: TStepInput;
|
|
35
|
+
outputSchema: TStepOutput;
|
|
36
|
+
resumeSchema?: TResumeSchema;
|
|
37
|
+
suspendSchema?: TSuspendSchema;
|
|
38
|
+
execute: ExecuteFunction<z.infer<TStepInput>, z.infer<TStepOutput>, z.infer<TResumeSchema>, z.infer<TSuspendSchema>, InngestEngineType>;
|
|
39
|
+
}): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
40
|
+
|
|
41
|
+
export declare function createStep<TStepId extends string, TStepInput extends z.ZodObject<{
|
|
42
|
+
prompt: z.ZodString;
|
|
43
|
+
}>, TStepOutput extends z.ZodObject<{
|
|
44
|
+
text: z.ZodString;
|
|
45
|
+
}>, TResumeSchema extends z.ZodType<any>, TSuspendSchema extends z.ZodType<any>>(agent: Agent<TStepId, any, any>): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
46
|
+
|
|
47
|
+
export declare function createStep<TSchemaIn extends z.ZodType<any>, TSchemaOut extends z.ZodType<any>, TContext extends ToolExecutionContext<TSchemaIn>>(tool: Tool<TSchemaIn, TSchemaOut, TContext> & {
|
|
48
|
+
inputSchema: TSchemaIn;
|
|
49
|
+
outputSchema: TSchemaOut;
|
|
50
|
+
execute: (context: TContext) => Promise<any>;
|
|
51
|
+
}): Step<string, TSchemaIn, TSchemaOut, z.ZodType<any>, z.ZodType<any>, InngestEngineType>;
|
|
32
52
|
|
|
33
53
|
export declare function init(inngest: Inngest): {
|
|
34
|
-
createWorkflow<TWorkflowId extends string = string, TInput extends z.ZodType<any> = z.ZodType<any, z.ZodTypeDef, any>, TOutput extends z.ZodType<any> = z.ZodType<any, z.ZodTypeDef, any>, TSteps extends Step<string, any, any>[] = Step<string, any, any,
|
|
35
|
-
createStep
|
|
54
|
+
createWorkflow<TWorkflowId extends string = string, TInput extends z.ZodType<any> = z.ZodType<any, z.ZodTypeDef, any>, TOutput extends z.ZodType<any> = z.ZodType<any, z.ZodTypeDef, any>, TSteps extends Step<string, any, any, any, any, InngestEngineType>[] = Step<string, any, any, any, any, InngestEngineType>[]>(params: WorkflowConfig<TWorkflowId, TInput, TOutput, TSteps>): InngestWorkflow<InngestEngineType, TSteps, TWorkflowId, TInput, TOutput, TInput>;
|
|
55
|
+
createStep: typeof createStep;
|
|
56
|
+
cloneStep<TStepId extends string>(step: Step<string, any, any, any, any, InngestEngineType>, opts: {
|
|
36
57
|
id: TStepId;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
execute: ExecuteFunction<z.infer<TStepInput>, z.infer<TStepOutput>, z.infer<TResumeSchema>, z.infer<TSuspendSchema>, InngestEngineType>;
|
|
42
|
-
}): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
43
|
-
cloneStep: typeof cloneStep;
|
|
44
|
-
cloneWorkflow: typeof cloneWorkflow;
|
|
58
|
+
}): Step<TStepId, any, any, any, any, InngestEngineType>;
|
|
59
|
+
cloneWorkflow<TWorkflowId extends string = string, TInput extends z.ZodType<any> = z.ZodType<any, z.ZodTypeDef, any>, TOutput extends z.ZodType<any> = z.ZodType<any, z.ZodTypeDef, any>, TSteps extends Step<string, any, any, any, any, InngestEngineType>[] = Step<string, any, any, any, any, InngestEngineType>[]>(workflow: Workflow<InngestEngineType, TSteps, string, TInput, TOutput, TInput>, opts: {
|
|
60
|
+
id: TWorkflowId;
|
|
61
|
+
}): Workflow<InngestEngineType, TSteps, TWorkflowId, TInput, TOutput, TInput>;
|
|
45
62
|
};
|
|
46
63
|
|
|
47
64
|
export declare type InngestEngineType = {
|
|
@@ -71,6 +88,10 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
71
88
|
};
|
|
72
89
|
runtimeContext: RuntimeContext;
|
|
73
90
|
}): Promise<StepResult<any, any, any, any>>;
|
|
91
|
+
executeSleep({ id, duration }: {
|
|
92
|
+
id: string;
|
|
93
|
+
duration: number;
|
|
94
|
+
}): Promise<void>;
|
|
74
95
|
executeStep({ step, stepResults, executionContext, resume, prevOutput, emitter, runtimeContext, }: {
|
|
75
96
|
step: Step<string, any, any>;
|
|
76
97
|
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
@@ -131,7 +152,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
131
152
|
}): Promise<StepResult<any, any, any, any>>;
|
|
132
153
|
}
|
|
133
154
|
|
|
134
|
-
export declare class InngestRun<TSteps extends Step<string, any, any>[] = Step<string, any, any>[], TInput extends z.ZodType<any> = z.ZodType<any>, TOutput extends z.ZodType<any> = z.ZodType<any>> extends Run<TSteps, TInput, TOutput> {
|
|
155
|
+
export declare class InngestRun<TEngineType = InngestEngineType, TSteps extends Step<string, any, any>[] = Step<string, any, any>[], TInput extends z.ZodType<any> = z.ZodType<any>, TOutput extends z.ZodType<any> = z.ZodType<any>> extends Run<TEngineType, TSteps, TInput, TOutput> {
|
|
135
156
|
#private;
|
|
136
157
|
private inngest;
|
|
137
158
|
serializedStepGraph: SerializedStepFlowEntry[];
|
|
@@ -162,7 +183,7 @@ export declare class InngestRun<TSteps extends Step<string, any, any>[] = Step<s
|
|
|
162
183
|
watch(cb: (event: any) => void): () => void;
|
|
163
184
|
}
|
|
164
185
|
|
|
165
|
-
export declare class InngestWorkflow<TSteps extends Step<string, any, any>[] = Step<string, any, any>[], TWorkflowId extends string = string, TInput extends z.ZodType<any> = z.ZodType<any>, TOutput extends z.ZodType<any> = z.ZodType<any>, TPrevSchema extends z.ZodType<any> = TInput> extends Workflow<TSteps, TWorkflowId, TInput, TOutput,
|
|
186
|
+
export declare class InngestWorkflow<TEngineType = InngestEngineType, TSteps extends Step<string, any, any>[] = Step<string, any, any>[], TWorkflowId extends string = string, TInput extends z.ZodType<any> = z.ZodType<any>, TOutput extends z.ZodType<any> = z.ZodType<any>, TPrevSchema extends z.ZodType<any> = TInput> extends Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TPrevSchema> {
|
|
166
187
|
#private;
|
|
167
188
|
inngest: Inngest;
|
|
168
189
|
private function;
|
|
@@ -178,7 +199,7 @@ export declare class InngestWorkflow<TSteps extends Step<string, any, any>[] = S
|
|
|
178
199
|
__registerMastra(mastra: Mastra): void;
|
|
179
200
|
createRun(options?: {
|
|
180
201
|
runId?: string;
|
|
181
|
-
}): Run<TSteps, TInput, TOutput>;
|
|
202
|
+
}): Run<TEngineType, TSteps, TInput, TOutput>;
|
|
182
203
|
getFunction(): InngestFunction<Omit<InngestFunction.Options<Inngest<ClientOptions>, InngestMiddleware.Stack, InngestFunction.Trigger<string>[] | [{
|
|
183
204
|
cron: string;
|
|
184
205
|
} & Partial<Record<"event" | "if", never>>] | [{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Agent } from '@mastra/core';
|
|
1
2
|
import type { BaseContext } from 'inngest';
|
|
2
3
|
import { ClientOptions } from 'inngest';
|
|
3
|
-
import { cloneStep } from '@mastra/core/workflows';
|
|
4
4
|
import { DefaultExecutionEngine } from '@mastra/core/workflows';
|
|
5
5
|
import type { ExecuteFunction } from '@mastra/core/workflows';
|
|
6
6
|
import type { ExecutionContext } from '@mastra/core/workflows';
|
|
@@ -19,29 +19,46 @@ import type { Span } from '@opentelemetry/api';
|
|
|
19
19
|
import type { Step } from '@mastra/core/workflows';
|
|
20
20
|
import type { StepFlowEntry } from '@mastra/core/workflows';
|
|
21
21
|
import type { StepResult } from '@mastra/core/workflows';
|
|
22
|
+
import { Tool } from '@mastra/core';
|
|
23
|
+
import type { ToolExecutionContext } from '@mastra/core';
|
|
22
24
|
import { Workflow } from '@mastra/core/workflows';
|
|
23
25
|
import type { WorkflowConfig } from '@mastra/core/workflows';
|
|
24
26
|
import type { WorkflowResult } from '@mastra/core/workflows';
|
|
25
27
|
import type { WorkflowRun } from '@mastra/core';
|
|
26
28
|
import type { WorkflowRuns } from '@mastra/core';
|
|
27
|
-
import
|
|
29
|
+
import { z } from 'zod';
|
|
28
30
|
|
|
29
|
-
declare function
|
|
30
|
-
id:
|
|
31
|
-
|
|
31
|
+
export declare function createStep<TStepId extends string, TStepInput extends z.ZodType<any>, TStepOutput extends z.ZodType<any>, TResumeSchema extends z.ZodType<any>, TSuspendSchema extends z.ZodType<any>>(params: {
|
|
32
|
+
id: TStepId;
|
|
33
|
+
description?: string;
|
|
34
|
+
inputSchema: TStepInput;
|
|
35
|
+
outputSchema: TStepOutput;
|
|
36
|
+
resumeSchema?: TResumeSchema;
|
|
37
|
+
suspendSchema?: TSuspendSchema;
|
|
38
|
+
execute: ExecuteFunction<z.infer<TStepInput>, z.infer<TStepOutput>, z.infer<TResumeSchema>, z.infer<TSuspendSchema>, InngestEngineType>;
|
|
39
|
+
}): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
40
|
+
|
|
41
|
+
export declare function createStep<TStepId extends string, TStepInput extends z.ZodObject<{
|
|
42
|
+
prompt: z.ZodString;
|
|
43
|
+
}>, TStepOutput extends z.ZodObject<{
|
|
44
|
+
text: z.ZodString;
|
|
45
|
+
}>, TResumeSchema extends z.ZodType<any>, TSuspendSchema extends z.ZodType<any>>(agent: Agent<TStepId, any, any>): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
46
|
+
|
|
47
|
+
export declare function createStep<TSchemaIn extends z.ZodType<any>, TSchemaOut extends z.ZodType<any>, TContext extends ToolExecutionContext<TSchemaIn>>(tool: Tool<TSchemaIn, TSchemaOut, TContext> & {
|
|
48
|
+
inputSchema: TSchemaIn;
|
|
49
|
+
outputSchema: TSchemaOut;
|
|
50
|
+
execute: (context: TContext) => Promise<any>;
|
|
51
|
+
}): Step<string, TSchemaIn, TSchemaOut, z.ZodType<any>, z.ZodType<any>, InngestEngineType>;
|
|
32
52
|
|
|
33
53
|
export declare function init(inngest: Inngest): {
|
|
34
|
-
createWorkflow<TWorkflowId extends string = string, TInput extends z.ZodType<any> = z.ZodType<any, z.ZodTypeDef, any>, TOutput extends z.ZodType<any> = z.ZodType<any, z.ZodTypeDef, any>, TSteps extends Step<string, any, any>[] = Step<string, any, any,
|
|
35
|
-
createStep
|
|
54
|
+
createWorkflow<TWorkflowId extends string = string, TInput extends z.ZodType<any> = z.ZodType<any, z.ZodTypeDef, any>, TOutput extends z.ZodType<any> = z.ZodType<any, z.ZodTypeDef, any>, TSteps extends Step<string, any, any, any, any, InngestEngineType>[] = Step<string, any, any, any, any, InngestEngineType>[]>(params: WorkflowConfig<TWorkflowId, TInput, TOutput, TSteps>): InngestWorkflow<InngestEngineType, TSteps, TWorkflowId, TInput, TOutput, TInput>;
|
|
55
|
+
createStep: typeof createStep;
|
|
56
|
+
cloneStep<TStepId extends string>(step: Step<string, any, any, any, any, InngestEngineType>, opts: {
|
|
36
57
|
id: TStepId;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
execute: ExecuteFunction<z.infer<TStepInput>, z.infer<TStepOutput>, z.infer<TResumeSchema>, z.infer<TSuspendSchema>, InngestEngineType>;
|
|
42
|
-
}): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
43
|
-
cloneStep: typeof cloneStep;
|
|
44
|
-
cloneWorkflow: typeof cloneWorkflow;
|
|
58
|
+
}): Step<TStepId, any, any, any, any, InngestEngineType>;
|
|
59
|
+
cloneWorkflow<TWorkflowId extends string = string, TInput extends z.ZodType<any> = z.ZodType<any, z.ZodTypeDef, any>, TOutput extends z.ZodType<any> = z.ZodType<any, z.ZodTypeDef, any>, TSteps extends Step<string, any, any, any, any, InngestEngineType>[] = Step<string, any, any, any, any, InngestEngineType>[]>(workflow: Workflow<InngestEngineType, TSteps, string, TInput, TOutput, TInput>, opts: {
|
|
60
|
+
id: TWorkflowId;
|
|
61
|
+
}): Workflow<InngestEngineType, TSteps, TWorkflowId, TInput, TOutput, TInput>;
|
|
45
62
|
};
|
|
46
63
|
|
|
47
64
|
export declare type InngestEngineType = {
|
|
@@ -71,6 +88,10 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
71
88
|
};
|
|
72
89
|
runtimeContext: RuntimeContext;
|
|
73
90
|
}): Promise<StepResult<any, any, any, any>>;
|
|
91
|
+
executeSleep({ id, duration }: {
|
|
92
|
+
id: string;
|
|
93
|
+
duration: number;
|
|
94
|
+
}): Promise<void>;
|
|
74
95
|
executeStep({ step, stepResults, executionContext, resume, prevOutput, emitter, runtimeContext, }: {
|
|
75
96
|
step: Step<string, any, any>;
|
|
76
97
|
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
@@ -131,7 +152,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
131
152
|
}): Promise<StepResult<any, any, any, any>>;
|
|
132
153
|
}
|
|
133
154
|
|
|
134
|
-
export declare class InngestRun<TSteps extends Step<string, any, any>[] = Step<string, any, any>[], TInput extends z.ZodType<any> = z.ZodType<any>, TOutput extends z.ZodType<any> = z.ZodType<any>> extends Run<TSteps, TInput, TOutput> {
|
|
155
|
+
export declare class InngestRun<TEngineType = InngestEngineType, TSteps extends Step<string, any, any>[] = Step<string, any, any>[], TInput extends z.ZodType<any> = z.ZodType<any>, TOutput extends z.ZodType<any> = z.ZodType<any>> extends Run<TEngineType, TSteps, TInput, TOutput> {
|
|
135
156
|
#private;
|
|
136
157
|
private inngest;
|
|
137
158
|
serializedStepGraph: SerializedStepFlowEntry[];
|
|
@@ -162,7 +183,7 @@ export declare class InngestRun<TSteps extends Step<string, any, any>[] = Step<s
|
|
|
162
183
|
watch(cb: (event: any) => void): () => void;
|
|
163
184
|
}
|
|
164
185
|
|
|
165
|
-
export declare class InngestWorkflow<TSteps extends Step<string, any, any>[] = Step<string, any, any>[], TWorkflowId extends string = string, TInput extends z.ZodType<any> = z.ZodType<any>, TOutput extends z.ZodType<any> = z.ZodType<any>, TPrevSchema extends z.ZodType<any> = TInput> extends Workflow<TSteps, TWorkflowId, TInput, TOutput,
|
|
186
|
+
export declare class InngestWorkflow<TEngineType = InngestEngineType, TSteps extends Step<string, any, any>[] = Step<string, any, any>[], TWorkflowId extends string = string, TInput extends z.ZodType<any> = z.ZodType<any>, TOutput extends z.ZodType<any> = z.ZodType<any>, TPrevSchema extends z.ZodType<any> = TInput> extends Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TPrevSchema> {
|
|
166
187
|
#private;
|
|
167
188
|
inngest: Inngest;
|
|
168
189
|
private function;
|
|
@@ -178,7 +199,7 @@ export declare class InngestWorkflow<TSteps extends Step<string, any, any>[] = S
|
|
|
178
199
|
__registerMastra(mastra: Mastra): void;
|
|
179
200
|
createRun(options?: {
|
|
180
201
|
runId?: string;
|
|
181
|
-
}): Run<TSteps, TInput, TOutput>;
|
|
202
|
+
}): Run<TEngineType, TSteps, TInput, TOutput>;
|
|
182
203
|
getFunction(): InngestFunction<Omit<InngestFunction.Options<Inngest<ClientOptions>, InngestMiddleware.Stack, InngestFunction.Trigger<string>[] | [{
|
|
183
204
|
cron: string;
|
|
184
205
|
} & Partial<Record<"event" | "if", never>>] | [{
|
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 }) {
|
|
@@ -270,31 +272,128 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
270
272
|
return [this.getFunction(), ...this.getNestedFunctions(this.executionGraph.steps)];
|
|
271
273
|
}
|
|
272
274
|
};
|
|
273
|
-
function
|
|
274
|
-
|
|
275
|
-
{
|
|
276
|
-
id:
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
275
|
+
function createStep(params) {
|
|
276
|
+
if (params instanceof core.Agent) {
|
|
277
|
+
return {
|
|
278
|
+
id: params.name,
|
|
279
|
+
// @ts-ignore
|
|
280
|
+
inputSchema: zod.z.object({
|
|
281
|
+
prompt: zod.z.string()
|
|
282
|
+
// resourceId: z.string().optional(),
|
|
283
|
+
// threadId: z.string().optional(),
|
|
284
|
+
}),
|
|
285
|
+
// @ts-ignore
|
|
286
|
+
outputSchema: zod.z.object({
|
|
287
|
+
text: zod.z.string()
|
|
288
|
+
}),
|
|
289
|
+
execute: async ({ inputData, [_constants.EMITTER_SYMBOL]: emitter, runtimeContext }) => {
|
|
290
|
+
let streamPromise = {};
|
|
291
|
+
streamPromise.promise = new Promise((resolve, reject) => {
|
|
292
|
+
streamPromise.resolve = resolve;
|
|
293
|
+
streamPromise.reject = reject;
|
|
294
|
+
});
|
|
295
|
+
const toolData = {
|
|
296
|
+
name: params.name,
|
|
297
|
+
args: inputData
|
|
298
|
+
};
|
|
299
|
+
await emitter.emit("watch-v2", {
|
|
300
|
+
type: "tool-call-streaming-start",
|
|
301
|
+
...toolData
|
|
302
|
+
});
|
|
303
|
+
const { fullStream } = await params.stream(inputData.prompt, {
|
|
304
|
+
// resourceId: inputData.resourceId,
|
|
305
|
+
// threadId: inputData.threadId,
|
|
306
|
+
runtimeContext,
|
|
307
|
+
onFinish: (result) => {
|
|
308
|
+
streamPromise.resolve(result.text);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
for await (const chunk of fullStream) {
|
|
312
|
+
switch (chunk.type) {
|
|
313
|
+
case "text-delta":
|
|
314
|
+
await emitter.emit("watch-v2", {
|
|
315
|
+
type: "tool-call-delta",
|
|
316
|
+
...toolData,
|
|
317
|
+
argsTextDelta: chunk.textDelta
|
|
318
|
+
});
|
|
319
|
+
break;
|
|
320
|
+
case "step-start":
|
|
321
|
+
case "step-finish":
|
|
322
|
+
case "finish":
|
|
323
|
+
break;
|
|
324
|
+
case "tool-call":
|
|
325
|
+
case "tool-result":
|
|
326
|
+
case "tool-call-streaming-start":
|
|
327
|
+
case "tool-call-delta":
|
|
328
|
+
case "source":
|
|
329
|
+
case "file":
|
|
330
|
+
default:
|
|
331
|
+
await emitter.emit("watch-v2", chunk);
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
text: await streamPromise.promise
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
if (params instanceof core.Tool) {
|
|
342
|
+
if (!params.inputSchema || !params.outputSchema) {
|
|
343
|
+
throw new Error("Tool must have input and output schemas defined");
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
// TODO: tool probably should have strong id type
|
|
347
|
+
// @ts-ignore
|
|
348
|
+
id: params.id,
|
|
349
|
+
inputSchema: params.inputSchema,
|
|
350
|
+
outputSchema: params.outputSchema,
|
|
351
|
+
execute: async ({ inputData, mastra, runtimeContext }) => {
|
|
352
|
+
return params.execute({
|
|
353
|
+
context: inputData,
|
|
354
|
+
mastra,
|
|
355
|
+
runtimeContext
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
return {
|
|
361
|
+
id: params.id,
|
|
362
|
+
description: params.description,
|
|
363
|
+
inputSchema: params.inputSchema,
|
|
364
|
+
outputSchema: params.outputSchema,
|
|
365
|
+
resumeSchema: params.resumeSchema,
|
|
366
|
+
suspendSchema: params.suspendSchema,
|
|
367
|
+
execute: params.execute
|
|
368
|
+
};
|
|
287
369
|
}
|
|
288
370
|
function init(inngest) {
|
|
289
371
|
return {
|
|
290
372
|
createWorkflow(params) {
|
|
291
373
|
return new InngestWorkflow(params, inngest);
|
|
292
374
|
},
|
|
293
|
-
createStep
|
|
294
|
-
|
|
375
|
+
createStep,
|
|
376
|
+
cloneStep(step, opts) {
|
|
377
|
+
return {
|
|
378
|
+
id: opts.id,
|
|
379
|
+
description: step.description,
|
|
380
|
+
inputSchema: step.inputSchema,
|
|
381
|
+
outputSchema: step.outputSchema,
|
|
382
|
+
execute: step.execute
|
|
383
|
+
};
|
|
295
384
|
},
|
|
296
|
-
|
|
297
|
-
|
|
385
|
+
cloneWorkflow(workflow, opts) {
|
|
386
|
+
const wf = new workflows.Workflow({
|
|
387
|
+
id: opts.id,
|
|
388
|
+
inputSchema: workflow.inputSchema,
|
|
389
|
+
outputSchema: workflow.outputSchema,
|
|
390
|
+
steps: workflow.stepDefs,
|
|
391
|
+
mastra: workflow.mastra
|
|
392
|
+
});
|
|
393
|
+
wf.setStepFlow(workflow.stepGraph);
|
|
394
|
+
wf.commit();
|
|
395
|
+
return wf;
|
|
396
|
+
}
|
|
298
397
|
};
|
|
299
398
|
}
|
|
300
399
|
var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
@@ -385,6 +484,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
385
484
|
runtimeContext
|
|
386
485
|
});
|
|
387
486
|
}
|
|
487
|
+
async executeSleep({ id, duration }) {
|
|
488
|
+
await this.inngestStep.sleep(id, duration);
|
|
489
|
+
}
|
|
388
490
|
async executeStep({
|
|
389
491
|
step,
|
|
390
492
|
stepResults,
|
|
@@ -758,5 +860,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
758
860
|
exports.InngestExecutionEngine = InngestExecutionEngine;
|
|
759
861
|
exports.InngestRun = InngestRun;
|
|
760
862
|
exports.InngestWorkflow = InngestWorkflow;
|
|
863
|
+
exports.createStep = createStep;
|
|
761
864
|
exports.init = init;
|
|
762
865
|
exports.serve = serve;
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
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 }) {
|
|
@@ -268,31 +270,128 @@ var InngestWorkflow = class _InngestWorkflow extends Workflow {
|
|
|
268
270
|
return [this.getFunction(), ...this.getNestedFunctions(this.executionGraph.steps)];
|
|
269
271
|
}
|
|
270
272
|
};
|
|
271
|
-
function
|
|
272
|
-
|
|
273
|
-
{
|
|
274
|
-
id:
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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
|
+
};
|
|
285
367
|
}
|
|
286
368
|
function init(inngest) {
|
|
287
369
|
return {
|
|
288
370
|
createWorkflow(params) {
|
|
289
371
|
return new InngestWorkflow(params, inngest);
|
|
290
372
|
},
|
|
291
|
-
createStep
|
|
292
|
-
|
|
373
|
+
createStep,
|
|
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
|
+
};
|
|
293
382
|
},
|
|
294
|
-
|
|
295
|
-
|
|
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
|
+
}
|
|
296
395
|
};
|
|
297
396
|
}
|
|
298
397
|
var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
@@ -383,6 +482,9 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
383
482
|
runtimeContext
|
|
384
483
|
});
|
|
385
484
|
}
|
|
485
|
+
async executeSleep({ id, duration }) {
|
|
486
|
+
await this.inngestStep.sleep(id, duration);
|
|
487
|
+
}
|
|
386
488
|
async executeStep({
|
|
387
489
|
step,
|
|
388
490
|
stepResults,
|
|
@@ -753,4 +855,4 @@ var InngestExecutionEngine = class extends DefaultExecutionEngine {
|
|
|
753
855
|
}
|
|
754
856
|
};
|
|
755
857
|
|
|
756
|
-
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,27 +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
40
|
"@internal/lint": "0.0.12",
|
|
41
|
-
"@mastra/
|
|
42
|
-
"@mastra/
|
|
43
|
-
"@mastra/
|
|
41
|
+
"@mastra/core": "0.10.6-alpha.0",
|
|
42
|
+
"@mastra/libsql": "0.10.3-alpha.0",
|
|
43
|
+
"@mastra/deployer": "0.10.6-alpha.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@mastra/core": "^0.10.2-alpha.0"
|
package/src/index.test.ts
CHANGED
|
@@ -259,6 +259,186 @@ describe('MastraInngestWorkflow', () => {
|
|
|
259
259
|
|
|
260
260
|
srv.close();
|
|
261
261
|
});
|
|
262
|
+
|
|
263
|
+
it('should execute a a sleep step', async ctx => {
|
|
264
|
+
const inngest = new Inngest({
|
|
265
|
+
id: 'mastra',
|
|
266
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
270
|
+
|
|
271
|
+
const execute = vi.fn<any>().mockResolvedValue({ result: 'success' });
|
|
272
|
+
const step1 = createStep({
|
|
273
|
+
id: 'step1',
|
|
274
|
+
execute,
|
|
275
|
+
inputSchema: z.object({}),
|
|
276
|
+
outputSchema: z.object({ result: z.string() }),
|
|
277
|
+
});
|
|
278
|
+
const step2 = createStep({
|
|
279
|
+
id: 'step2',
|
|
280
|
+
execute: async ({ inputData }) => {
|
|
281
|
+
return { result: 'slept successfully: ' + inputData.result };
|
|
282
|
+
},
|
|
283
|
+
inputSchema: z.object({ result: z.string() }),
|
|
284
|
+
outputSchema: z.object({ result: z.string() }),
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
const workflow = createWorkflow({
|
|
288
|
+
id: 'test-workflow',
|
|
289
|
+
inputSchema: z.object({}),
|
|
290
|
+
outputSchema: z.object({
|
|
291
|
+
result: z.string(),
|
|
292
|
+
}),
|
|
293
|
+
steps: [step1],
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
workflow.then(step1).sleep(1000).then(step2).commit();
|
|
297
|
+
|
|
298
|
+
const mastra = new Mastra({
|
|
299
|
+
storage: new DefaultStorage({
|
|
300
|
+
url: ':memory:',
|
|
301
|
+
}),
|
|
302
|
+
workflows: {
|
|
303
|
+
'test-workflow': workflow,
|
|
304
|
+
},
|
|
305
|
+
server: {
|
|
306
|
+
apiRoutes: [
|
|
307
|
+
{
|
|
308
|
+
path: '/inngest/api',
|
|
309
|
+
method: 'ALL',
|
|
310
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
311
|
+
},
|
|
312
|
+
],
|
|
313
|
+
},
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
const app = await createHonoServer(mastra);
|
|
317
|
+
|
|
318
|
+
const srv = serve({
|
|
319
|
+
fetch: app.fetch,
|
|
320
|
+
port: (ctx as any).handlerPort,
|
|
321
|
+
});
|
|
322
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
323
|
+
|
|
324
|
+
const run = workflow.createRun();
|
|
325
|
+
const startTime = Date.now();
|
|
326
|
+
const result = await run.start({ inputData: {} });
|
|
327
|
+
const endTime = Date.now();
|
|
328
|
+
|
|
329
|
+
expect(execute).toHaveBeenCalled();
|
|
330
|
+
expect(result.steps['step1']).toEqual({
|
|
331
|
+
status: 'success',
|
|
332
|
+
output: { result: 'success' },
|
|
333
|
+
// payload: {},
|
|
334
|
+
// startedAt: expect.any(Number),
|
|
335
|
+
// endedAt: expect.any(Number),
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
expect(result.steps['step2']).toEqual({
|
|
339
|
+
status: 'success',
|
|
340
|
+
output: { result: 'slept successfully: success' },
|
|
341
|
+
// payload: { result: 'success' },
|
|
342
|
+
// startedAt: expect.any(Number),
|
|
343
|
+
// endedAt: expect.any(Number),
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
expect(endTime - startTime).toBeGreaterThan(1000);
|
|
347
|
+
|
|
348
|
+
srv.close();
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it('should execute a a sleep until step', async ctx => {
|
|
352
|
+
const inngest = new Inngest({
|
|
353
|
+
id: 'mastra',
|
|
354
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
358
|
+
|
|
359
|
+
const execute = vi.fn<any>().mockResolvedValue({ result: 'success' });
|
|
360
|
+
const step1 = createStep({
|
|
361
|
+
id: 'step1',
|
|
362
|
+
execute,
|
|
363
|
+
inputSchema: z.object({}),
|
|
364
|
+
outputSchema: z.object({ result: z.string() }),
|
|
365
|
+
});
|
|
366
|
+
const step2 = createStep({
|
|
367
|
+
id: 'step2',
|
|
368
|
+
execute: async ({ inputData }) => {
|
|
369
|
+
return { result: 'slept successfully: ' + inputData.result };
|
|
370
|
+
},
|
|
371
|
+
inputSchema: z.object({ result: z.string() }),
|
|
372
|
+
outputSchema: z.object({ result: z.string() }),
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
const workflow = createWorkflow({
|
|
376
|
+
id: 'test-workflow',
|
|
377
|
+
inputSchema: z.object({}),
|
|
378
|
+
outputSchema: z.object({
|
|
379
|
+
result: z.string(),
|
|
380
|
+
}),
|
|
381
|
+
steps: [step1],
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
workflow
|
|
385
|
+
.then(step1)
|
|
386
|
+
.sleepUntil(new Date(Date.now() + 1000))
|
|
387
|
+
.then(step2)
|
|
388
|
+
.commit();
|
|
389
|
+
|
|
390
|
+
const mastra = new Mastra({
|
|
391
|
+
storage: new DefaultStorage({
|
|
392
|
+
url: ':memory:',
|
|
393
|
+
}),
|
|
394
|
+
workflows: {
|
|
395
|
+
'test-workflow': workflow,
|
|
396
|
+
},
|
|
397
|
+
server: {
|
|
398
|
+
apiRoutes: [
|
|
399
|
+
{
|
|
400
|
+
path: '/inngest/api',
|
|
401
|
+
method: 'ALL',
|
|
402
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
403
|
+
},
|
|
404
|
+
],
|
|
405
|
+
},
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
const app = await createHonoServer(mastra);
|
|
409
|
+
|
|
410
|
+
const srv = serve({
|
|
411
|
+
fetch: app.fetch,
|
|
412
|
+
port: (ctx as any).handlerPort,
|
|
413
|
+
});
|
|
414
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
415
|
+
|
|
416
|
+
const run = workflow.createRun();
|
|
417
|
+
const startTime = Date.now();
|
|
418
|
+
const result = await run.start({ inputData: {} });
|
|
419
|
+
const endTime = Date.now();
|
|
420
|
+
|
|
421
|
+
expect(execute).toHaveBeenCalled();
|
|
422
|
+
expect(result.steps['step1']).toEqual({
|
|
423
|
+
status: 'success',
|
|
424
|
+
output: { result: 'success' },
|
|
425
|
+
// payload: {},
|
|
426
|
+
// startedAt: expect.any(Number),
|
|
427
|
+
// endedAt: expect.any(Number),
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
expect(result.steps['step2']).toEqual({
|
|
431
|
+
status: 'success',
|
|
432
|
+
output: { result: 'slept successfully: success' },
|
|
433
|
+
// payload: { result: 'success' },
|
|
434
|
+
// startedAt: expect.any(Number),
|
|
435
|
+
// endedAt: expect.any(Number),
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
expect(endTime - startTime).toBeGreaterThan(1000);
|
|
439
|
+
|
|
440
|
+
srv.close();
|
|
441
|
+
});
|
|
262
442
|
});
|
|
263
443
|
|
|
264
444
|
describe('Variable Resolution', () => {
|
|
@@ -4781,7 +4961,6 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4781
4961
|
|
|
4782
4962
|
const app = await createHonoServer(mastra);
|
|
4783
4963
|
app.use('*', async (ctx, next) => {
|
|
4784
|
-
'middleware', ctx.req.method, ctx.req.url;
|
|
4785
4964
|
await next();
|
|
4786
4965
|
});
|
|
4787
4966
|
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
2
|
import { subscribe } from '@inngest/realtime';
|
|
3
|
-
import
|
|
3
|
+
import { Agent, Tool } from '@mastra/core';
|
|
4
|
+
import type { Mastra, ToolExecutionContext, WorkflowRun, WorkflowRuns } from '@mastra/core';
|
|
4
5
|
import { RuntimeContext } from '@mastra/core/di';
|
|
5
|
-
import { Workflow,
|
|
6
|
+
import { Workflow, Run, DefaultExecutionEngine } from '@mastra/core/workflows';
|
|
6
7
|
import type {
|
|
7
8
|
ExecuteFunction,
|
|
8
9
|
ExecutionContext,
|
|
@@ -20,7 +21,7 @@ import { EMITTER_SYMBOL } from '@mastra/core/workflows/_constants';
|
|
|
20
21
|
import type { Span } from '@opentelemetry/api';
|
|
21
22
|
import type { Inngest, BaseContext } from 'inngest';
|
|
22
23
|
import { serve as inngestServe } from 'inngest/hono';
|
|
23
|
-
import
|
|
24
|
+
import { z } from 'zod';
|
|
24
25
|
|
|
25
26
|
export type InngestEngineType = {
|
|
26
27
|
step: any;
|
|
@@ -42,10 +43,11 @@ export function serve({ mastra, inngest }: { mastra: Mastra; inngest: Inngest })
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
export class InngestRun<
|
|
46
|
+
TEngineType = InngestEngineType,
|
|
45
47
|
TSteps extends Step<string, any, any>[] = Step<string, any, any>[],
|
|
46
48
|
TInput extends z.ZodType<any> = z.ZodType<any>,
|
|
47
49
|
TOutput extends z.ZodType<any> = z.ZodType<any>,
|
|
48
|
-
> extends Run<TSteps, TInput, TOutput> {
|
|
50
|
+
> extends Run<TEngineType, TSteps, TInput, TOutput> {
|
|
49
51
|
private inngest: Inngest;
|
|
50
52
|
serializedStepGraph: SerializedStepFlowEntry[];
|
|
51
53
|
#mastra: Mastra;
|
|
@@ -207,12 +209,13 @@ export class InngestRun<
|
|
|
207
209
|
}
|
|
208
210
|
|
|
209
211
|
export class InngestWorkflow<
|
|
212
|
+
TEngineType = InngestEngineType,
|
|
210
213
|
TSteps extends Step<string, any, any>[] = Step<string, any, any>[],
|
|
211
214
|
TWorkflowId extends string = string,
|
|
212
215
|
TInput extends z.ZodType<any> = z.ZodType<any>,
|
|
213
216
|
TOutput extends z.ZodType<any> = z.ZodType<any>,
|
|
214
217
|
TPrevSchema extends z.ZodType<any> = TInput,
|
|
215
|
-
> extends Workflow<TSteps, TWorkflowId, TInput, TOutput,
|
|
218
|
+
> extends Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TPrevSchema> {
|
|
216
219
|
#mastra: Mastra;
|
|
217
220
|
public inngest: Inngest;
|
|
218
221
|
|
|
@@ -277,11 +280,11 @@ export class InngestWorkflow<
|
|
|
277
280
|
}
|
|
278
281
|
}
|
|
279
282
|
|
|
280
|
-
createRun(options?: { runId?: string }): Run<TSteps, TInput, TOutput> {
|
|
283
|
+
createRun(options?: { runId?: string }): Run<TEngineType, TSteps, TInput, TOutput> {
|
|
281
284
|
const runIdToUse = options?.runId || randomUUID();
|
|
282
285
|
|
|
283
286
|
// Return a new Run instance with object parameters
|
|
284
|
-
const run: Run<TSteps, TInput, TOutput> =
|
|
287
|
+
const run: Run<TEngineType, TSteps, TInput, TOutput> =
|
|
285
288
|
this.runs.get(runIdToUse) ??
|
|
286
289
|
new InngestRun(
|
|
287
290
|
{
|
|
@@ -375,29 +378,185 @@ export class InngestWorkflow<
|
|
|
375
378
|
}
|
|
376
379
|
}
|
|
377
380
|
|
|
378
|
-
function
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
381
|
+
export function createStep<
|
|
382
|
+
TStepId extends string,
|
|
383
|
+
TStepInput extends z.ZodType<any>,
|
|
384
|
+
TStepOutput extends z.ZodType<any>,
|
|
385
|
+
TResumeSchema extends z.ZodType<any>,
|
|
386
|
+
TSuspendSchema extends z.ZodType<any>,
|
|
387
|
+
>(params: {
|
|
388
|
+
id: TStepId;
|
|
389
|
+
description?: string;
|
|
390
|
+
inputSchema: TStepInput;
|
|
391
|
+
outputSchema: TStepOutput;
|
|
392
|
+
resumeSchema?: TResumeSchema;
|
|
393
|
+
suspendSchema?: TSuspendSchema;
|
|
394
|
+
execute: ExecuteFunction<
|
|
395
|
+
z.infer<TStepInput>,
|
|
396
|
+
z.infer<TStepOutput>,
|
|
397
|
+
z.infer<TResumeSchema>,
|
|
398
|
+
z.infer<TSuspendSchema>,
|
|
399
|
+
InngestEngineType
|
|
400
|
+
>;
|
|
401
|
+
}): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
402
|
+
|
|
403
|
+
export function createStep<
|
|
404
|
+
TStepId extends string,
|
|
405
|
+
TStepInput extends z.ZodObject<{ prompt: z.ZodString }>,
|
|
406
|
+
TStepOutput extends z.ZodObject<{ text: z.ZodString }>,
|
|
407
|
+
TResumeSchema extends z.ZodType<any>,
|
|
408
|
+
TSuspendSchema extends z.ZodType<any>,
|
|
383
409
|
>(
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
410
|
+
agent: Agent<TStepId, any, any>,
|
|
411
|
+
): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
412
|
+
|
|
413
|
+
export function createStep<
|
|
414
|
+
TSchemaIn extends z.ZodType<any>,
|
|
415
|
+
TSchemaOut extends z.ZodType<any>,
|
|
416
|
+
TContext extends ToolExecutionContext<TSchemaIn>,
|
|
417
|
+
>(
|
|
418
|
+
tool: Tool<TSchemaIn, TSchemaOut, TContext> & {
|
|
419
|
+
inputSchema: TSchemaIn;
|
|
420
|
+
outputSchema: TSchemaOut;
|
|
421
|
+
execute: (context: TContext) => Promise<any>;
|
|
422
|
+
},
|
|
423
|
+
): Step<string, TSchemaIn, TSchemaOut, z.ZodType<any>, z.ZodType<any>, InngestEngineType>;
|
|
424
|
+
|
|
425
|
+
export function createStep<
|
|
426
|
+
TStepId extends string,
|
|
427
|
+
TStepInput extends z.ZodType<any>,
|
|
428
|
+
TStepOutput extends z.ZodType<any>,
|
|
429
|
+
TResumeSchema extends z.ZodType<any>,
|
|
430
|
+
TSuspendSchema extends z.ZodType<any>,
|
|
431
|
+
>(
|
|
432
|
+
params:
|
|
433
|
+
| {
|
|
434
|
+
id: TStepId;
|
|
435
|
+
description?: string;
|
|
436
|
+
inputSchema: TStepInput;
|
|
437
|
+
outputSchema: TStepOutput;
|
|
438
|
+
resumeSchema?: TResumeSchema;
|
|
439
|
+
suspendSchema?: TSuspendSchema;
|
|
440
|
+
execute: ExecuteFunction<
|
|
441
|
+
z.infer<TStepInput>,
|
|
442
|
+
z.infer<TStepOutput>,
|
|
443
|
+
z.infer<TResumeSchema>,
|
|
444
|
+
z.infer<TSuspendSchema>,
|
|
445
|
+
InngestEngineType
|
|
446
|
+
>;
|
|
447
|
+
}
|
|
448
|
+
| Agent<any, any, any>
|
|
449
|
+
| (Tool<TStepInput, TStepOutput, any> & {
|
|
450
|
+
inputSchema: TStepInput;
|
|
451
|
+
outputSchema: TStepOutput;
|
|
452
|
+
execute: (context: ToolExecutionContext<TStepInput>) => Promise<any>;
|
|
453
|
+
}),
|
|
454
|
+
): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType> {
|
|
455
|
+
if (params instanceof Agent) {
|
|
456
|
+
return {
|
|
457
|
+
id: params.name,
|
|
458
|
+
// @ts-ignore
|
|
459
|
+
inputSchema: z.object({
|
|
460
|
+
prompt: z.string(),
|
|
461
|
+
// resourceId: z.string().optional(),
|
|
462
|
+
// threadId: z.string().optional(),
|
|
463
|
+
}),
|
|
464
|
+
// @ts-ignore
|
|
465
|
+
outputSchema: z.object({
|
|
466
|
+
text: z.string(),
|
|
467
|
+
}),
|
|
468
|
+
execute: async ({ inputData, [EMITTER_SYMBOL]: emitter, runtimeContext }) => {
|
|
469
|
+
let streamPromise = {} as {
|
|
470
|
+
promise: Promise<string>;
|
|
471
|
+
resolve: (value: string) => void;
|
|
472
|
+
reject: (reason?: any) => void;
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
streamPromise.promise = new Promise((resolve, reject) => {
|
|
476
|
+
streamPromise.resolve = resolve;
|
|
477
|
+
streamPromise.reject = reject;
|
|
478
|
+
});
|
|
479
|
+
const toolData = {
|
|
480
|
+
name: params.name,
|
|
481
|
+
args: inputData,
|
|
482
|
+
};
|
|
483
|
+
await emitter.emit('watch-v2', {
|
|
484
|
+
type: 'tool-call-streaming-start',
|
|
485
|
+
...toolData,
|
|
486
|
+
});
|
|
487
|
+
const { fullStream } = await params.stream(inputData.prompt, {
|
|
488
|
+
// resourceId: inputData.resourceId,
|
|
489
|
+
// threadId: inputData.threadId,
|
|
490
|
+
runtimeContext,
|
|
491
|
+
onFinish: result => {
|
|
492
|
+
streamPromise.resolve(result.text);
|
|
493
|
+
},
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
for await (const chunk of fullStream) {
|
|
497
|
+
switch (chunk.type) {
|
|
498
|
+
case 'text-delta':
|
|
499
|
+
await emitter.emit('watch-v2', {
|
|
500
|
+
type: 'tool-call-delta',
|
|
501
|
+
...toolData,
|
|
502
|
+
argsTextDelta: chunk.textDelta,
|
|
503
|
+
});
|
|
504
|
+
break;
|
|
505
|
+
|
|
506
|
+
case 'step-start':
|
|
507
|
+
case 'step-finish':
|
|
508
|
+
case 'finish':
|
|
509
|
+
break;
|
|
510
|
+
|
|
511
|
+
case 'tool-call':
|
|
512
|
+
case 'tool-result':
|
|
513
|
+
case 'tool-call-streaming-start':
|
|
514
|
+
case 'tool-call-delta':
|
|
515
|
+
case 'source':
|
|
516
|
+
case 'file':
|
|
517
|
+
default:
|
|
518
|
+
await emitter.emit('watch-v2', chunk);
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
return {
|
|
524
|
+
text: await streamPromise.promise,
|
|
525
|
+
};
|
|
526
|
+
},
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
if (params instanceof Tool) {
|
|
531
|
+
if (!params.inputSchema || !params.outputSchema) {
|
|
532
|
+
throw new Error('Tool must have input and output schemas defined');
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
return {
|
|
536
|
+
// TODO: tool probably should have strong id type
|
|
537
|
+
// @ts-ignore
|
|
538
|
+
id: params.id,
|
|
539
|
+
inputSchema: params.inputSchema,
|
|
540
|
+
outputSchema: params.outputSchema,
|
|
541
|
+
execute: async ({ inputData, mastra, runtimeContext }) => {
|
|
542
|
+
return params.execute({
|
|
543
|
+
context: inputData,
|
|
544
|
+
mastra,
|
|
545
|
+
runtimeContext,
|
|
546
|
+
});
|
|
547
|
+
},
|
|
548
|
+
};
|
|
549
|
+
}
|
|
397
550
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
551
|
+
return {
|
|
552
|
+
id: params.id,
|
|
553
|
+
description: params.description,
|
|
554
|
+
inputSchema: params.inputSchema,
|
|
555
|
+
outputSchema: params.outputSchema,
|
|
556
|
+
resumeSchema: params.resumeSchema,
|
|
557
|
+
suspendSchema: params.suspendSchema,
|
|
558
|
+
execute: params.execute,
|
|
559
|
+
};
|
|
401
560
|
}
|
|
402
561
|
|
|
403
562
|
export function init(inngest: Inngest) {
|
|
@@ -406,34 +565,58 @@ export function init(inngest: Inngest) {
|
|
|
406
565
|
TWorkflowId extends string = string,
|
|
407
566
|
TInput extends z.ZodType<any> = z.ZodType<any>,
|
|
408
567
|
TOutput extends z.ZodType<any> = z.ZodType<any>,
|
|
409
|
-
TSteps extends Step<string, any, any
|
|
568
|
+
TSteps extends Step<string, any, any, any, any, InngestEngineType>[] = Step<
|
|
569
|
+
string,
|
|
570
|
+
any,
|
|
571
|
+
any,
|
|
572
|
+
any,
|
|
573
|
+
any,
|
|
574
|
+
InngestEngineType
|
|
575
|
+
>[],
|
|
410
576
|
>(params: WorkflowConfig<TWorkflowId, TInput, TOutput, TSteps>) {
|
|
411
|
-
return new InngestWorkflow(params, inngest);
|
|
577
|
+
return new InngestWorkflow<InngestEngineType, TSteps, TWorkflowId, TInput, TOutput, TInput>(params, inngest);
|
|
412
578
|
},
|
|
413
|
-
createStep
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
579
|
+
createStep,
|
|
580
|
+
cloneStep<TStepId extends string>(
|
|
581
|
+
step: Step<string, any, any, any, any, InngestEngineType>,
|
|
582
|
+
opts: { id: TStepId },
|
|
583
|
+
): Step<TStepId, any, any, any, any, InngestEngineType> {
|
|
584
|
+
return {
|
|
585
|
+
id: opts.id,
|
|
586
|
+
description: step.description,
|
|
587
|
+
inputSchema: step.inputSchema,
|
|
588
|
+
outputSchema: step.outputSchema,
|
|
589
|
+
execute: step.execute,
|
|
590
|
+
};
|
|
591
|
+
},
|
|
592
|
+
cloneWorkflow<
|
|
593
|
+
TWorkflowId extends string = string,
|
|
594
|
+
TInput extends z.ZodType<any> = z.ZodType<any>,
|
|
595
|
+
TOutput extends z.ZodType<any> = z.ZodType<any>,
|
|
596
|
+
TSteps extends Step<string, any, any, any, any, InngestEngineType>[] = Step<
|
|
597
|
+
string,
|
|
598
|
+
any,
|
|
599
|
+
any,
|
|
600
|
+
any,
|
|
601
|
+
any,
|
|
430
602
|
InngestEngineType
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
603
|
+
>[],
|
|
604
|
+
>(
|
|
605
|
+
workflow: Workflow<InngestEngineType, TSteps, string, TInput, TOutput, TInput>,
|
|
606
|
+
opts: { id: TWorkflowId },
|
|
607
|
+
): Workflow<InngestEngineType, TSteps, TWorkflowId, TInput, TOutput, TInput> {
|
|
608
|
+
const wf = new Workflow({
|
|
609
|
+
id: opts.id,
|
|
610
|
+
inputSchema: workflow.inputSchema,
|
|
611
|
+
outputSchema: workflow.outputSchema,
|
|
612
|
+
steps: workflow.stepDefs,
|
|
613
|
+
mastra: workflow.mastra,
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
wf.setStepFlow(workflow.stepGraph);
|
|
617
|
+
wf.commit();
|
|
618
|
+
return wf;
|
|
434
619
|
},
|
|
435
|
-
cloneStep,
|
|
436
|
-
cloneWorkflow,
|
|
437
620
|
};
|
|
438
621
|
}
|
|
439
622
|
|
|
@@ -558,6 +741,10 @@ export class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
558
741
|
});
|
|
559
742
|
}
|
|
560
743
|
|
|
744
|
+
async executeSleep({ id, duration }: { id: string; duration: number }): Promise<void> {
|
|
745
|
+
await this.inngestStep.sleep(id, duration);
|
|
746
|
+
}
|
|
747
|
+
|
|
561
748
|
async executeStep({
|
|
562
749
|
step,
|
|
563
750
|
stepResults,
|