@mastra/inngest 0.10.4 → 0.10.5-alpha.1
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 +24 -0
- package/dist/_tsup-dts-rollup.d.cts +41 -18
- package/dist/_tsup-dts-rollup.d.ts +41 -18
- package/dist/index.cjs +143 -19
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +144 -21
- package/package.json +12 -12
- package/src/index.test.ts +180 -1
- package/src/index.ts +270 -53
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/inngest@0.10.
|
|
2
|
+
> @mastra/inngest@0.10.5-alpha.1 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 8408ms
|
|
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 6159ms
|
|
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[32m26.65 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 178ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m26.84 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 236ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @mastra/inngest
|
|
2
2
|
|
|
3
|
+
## 0.10.5-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ee9af57: Add api for polling run execution result and get run by id
|
|
8
|
+
- Updated dependencies [ee9af57]
|
|
9
|
+
- Updated dependencies [751c894]
|
|
10
|
+
- Updated dependencies [577ce3a]
|
|
11
|
+
- Updated dependencies [9260b3a]
|
|
12
|
+
- @mastra/core@0.10.6-alpha.1
|
|
13
|
+
|
|
14
|
+
## 0.10.5-alpha.0
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 63f6b7d: dependencies updates:
|
|
19
|
+
- Updated dependency [`inngest@^3.39.1` ↗︎](https://www.npmjs.com/package/inngest/v/3.39.1) (from `^3.35.1`, in `dependencies`)
|
|
20
|
+
- Updated dependency [`zod@^3.25.57` ↗︎](https://www.npmjs.com/package/zod/v/3.25.57) (from `^3.25.56`, in `dependencies`)
|
|
21
|
+
- Updated dependencies [63f6b7d]
|
|
22
|
+
- Updated dependencies [36f1c36]
|
|
23
|
+
- Updated dependencies [10d352e]
|
|
24
|
+
- Updated dependencies [53d3c37]
|
|
25
|
+
- @mastra/core@0.10.6-alpha.0
|
|
26
|
+
|
|
3
27
|
## 0.10.4
|
|
4
28
|
|
|
5
29
|
### 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,47 @@ 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';
|
|
24
|
+
import type { WatchEvent } from '@mastra/core/workflows';
|
|
22
25
|
import { Workflow } from '@mastra/core/workflows';
|
|
23
26
|
import type { WorkflowConfig } from '@mastra/core/workflows';
|
|
24
27
|
import type { WorkflowResult } from '@mastra/core/workflows';
|
|
25
28
|
import type { WorkflowRun } from '@mastra/core';
|
|
26
29
|
import type { WorkflowRuns } from '@mastra/core';
|
|
27
|
-
import
|
|
30
|
+
import { z } from 'zod';
|
|
28
31
|
|
|
29
|
-
declare function
|
|
30
|
-
id:
|
|
31
|
-
|
|
32
|
+
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: {
|
|
33
|
+
id: TStepId;
|
|
34
|
+
description?: string;
|
|
35
|
+
inputSchema: TStepInput;
|
|
36
|
+
outputSchema: TStepOutput;
|
|
37
|
+
resumeSchema?: TResumeSchema;
|
|
38
|
+
suspendSchema?: TSuspendSchema;
|
|
39
|
+
execute: ExecuteFunction<z.infer<TStepInput>, z.infer<TStepOutput>, z.infer<TResumeSchema>, z.infer<TSuspendSchema>, InngestEngineType>;
|
|
40
|
+
}): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
41
|
+
|
|
42
|
+
export declare function createStep<TStepId extends string, TStepInput extends z.ZodObject<{
|
|
43
|
+
prompt: z.ZodString;
|
|
44
|
+
}>, TStepOutput extends z.ZodObject<{
|
|
45
|
+
text: z.ZodString;
|
|
46
|
+
}>, TResumeSchema extends z.ZodType<any>, TSuspendSchema extends z.ZodType<any>>(agent: Agent<TStepId, any, any>): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
47
|
+
|
|
48
|
+
export declare function createStep<TSchemaIn extends z.ZodType<any>, TSchemaOut extends z.ZodType<any>, TContext extends ToolExecutionContext<TSchemaIn>>(tool: Tool<TSchemaIn, TSchemaOut, TContext> & {
|
|
49
|
+
inputSchema: TSchemaIn;
|
|
50
|
+
outputSchema: TSchemaOut;
|
|
51
|
+
execute: (context: TContext) => Promise<any>;
|
|
52
|
+
}): Step<string, TSchemaIn, TSchemaOut, z.ZodType<any>, z.ZodType<any>, InngestEngineType>;
|
|
32
53
|
|
|
33
54
|
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
|
|
55
|
+
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>;
|
|
56
|
+
createStep: typeof createStep;
|
|
57
|
+
cloneStep<TStepId extends string>(step: Step<string, any, any, any, any, InngestEngineType>, opts: {
|
|
36
58
|
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;
|
|
59
|
+
}): Step<TStepId, any, any, any, any, InngestEngineType>;
|
|
60
|
+
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: {
|
|
61
|
+
id: TWorkflowId;
|
|
62
|
+
}): Workflow<InngestEngineType, TSteps, TWorkflowId, TInput, TOutput, TInput>;
|
|
45
63
|
};
|
|
46
64
|
|
|
47
65
|
export declare type InngestEngineType = {
|
|
@@ -71,6 +89,10 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
71
89
|
};
|
|
72
90
|
runtimeContext: RuntimeContext;
|
|
73
91
|
}): Promise<StepResult<any, any, any, any>>;
|
|
92
|
+
executeSleep({ id, duration }: {
|
|
93
|
+
id: string;
|
|
94
|
+
duration: number;
|
|
95
|
+
}): Promise<void>;
|
|
74
96
|
executeStep({ step, stepResults, executionContext, resume, prevOutput, emitter, runtimeContext, }: {
|
|
75
97
|
step: Step<string, any, any>;
|
|
76
98
|
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
@@ -131,7 +153,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
131
153
|
}): Promise<StepResult<any, any, any, any>>;
|
|
132
154
|
}
|
|
133
155
|
|
|
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> {
|
|
156
|
+
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
157
|
#private;
|
|
136
158
|
private inngest;
|
|
137
159
|
serializedStepGraph: SerializedStepFlowEntry[];
|
|
@@ -162,7 +184,7 @@ export declare class InngestRun<TSteps extends Step<string, any, any>[] = Step<s
|
|
|
162
184
|
watch(cb: (event: any) => void): () => void;
|
|
163
185
|
}
|
|
164
186
|
|
|
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,
|
|
187
|
+
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
188
|
#private;
|
|
167
189
|
inngest: Inngest;
|
|
168
190
|
private function;
|
|
@@ -175,10 +197,11 @@ export declare class InngestWorkflow<TSteps extends Step<string, any, any>[] = S
|
|
|
175
197
|
resourceId?: string;
|
|
176
198
|
}): Promise<WorkflowRuns>;
|
|
177
199
|
getWorkflowRunById(runId: string): Promise<WorkflowRun | null>;
|
|
200
|
+
getWorkflowRunExecutionResult(runId: string): Promise<WatchEvent['payload']['workflowState'] | null>;
|
|
178
201
|
__registerMastra(mastra: Mastra): void;
|
|
179
202
|
createRun(options?: {
|
|
180
203
|
runId?: string;
|
|
181
|
-
}): Run<TSteps, TInput, TOutput>;
|
|
204
|
+
}): Run<TEngineType, TSteps, TInput, TOutput>;
|
|
182
205
|
getFunction(): InngestFunction<Omit<InngestFunction.Options<Inngest<ClientOptions>, InngestMiddleware.Stack, InngestFunction.Trigger<string>[] | [{
|
|
183
206
|
cron: string;
|
|
184
207
|
} & 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,47 @@ 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';
|
|
24
|
+
import type { WatchEvent } from '@mastra/core/workflows';
|
|
22
25
|
import { Workflow } from '@mastra/core/workflows';
|
|
23
26
|
import type { WorkflowConfig } from '@mastra/core/workflows';
|
|
24
27
|
import type { WorkflowResult } from '@mastra/core/workflows';
|
|
25
28
|
import type { WorkflowRun } from '@mastra/core';
|
|
26
29
|
import type { WorkflowRuns } from '@mastra/core';
|
|
27
|
-
import
|
|
30
|
+
import { z } from 'zod';
|
|
28
31
|
|
|
29
|
-
declare function
|
|
30
|
-
id:
|
|
31
|
-
|
|
32
|
+
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: {
|
|
33
|
+
id: TStepId;
|
|
34
|
+
description?: string;
|
|
35
|
+
inputSchema: TStepInput;
|
|
36
|
+
outputSchema: TStepOutput;
|
|
37
|
+
resumeSchema?: TResumeSchema;
|
|
38
|
+
suspendSchema?: TSuspendSchema;
|
|
39
|
+
execute: ExecuteFunction<z.infer<TStepInput>, z.infer<TStepOutput>, z.infer<TResumeSchema>, z.infer<TSuspendSchema>, InngestEngineType>;
|
|
40
|
+
}): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
41
|
+
|
|
42
|
+
export declare function createStep<TStepId extends string, TStepInput extends z.ZodObject<{
|
|
43
|
+
prompt: z.ZodString;
|
|
44
|
+
}>, TStepOutput extends z.ZodObject<{
|
|
45
|
+
text: z.ZodString;
|
|
46
|
+
}>, TResumeSchema extends z.ZodType<any>, TSuspendSchema extends z.ZodType<any>>(agent: Agent<TStepId, any, any>): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
47
|
+
|
|
48
|
+
export declare function createStep<TSchemaIn extends z.ZodType<any>, TSchemaOut extends z.ZodType<any>, TContext extends ToolExecutionContext<TSchemaIn>>(tool: Tool<TSchemaIn, TSchemaOut, TContext> & {
|
|
49
|
+
inputSchema: TSchemaIn;
|
|
50
|
+
outputSchema: TSchemaOut;
|
|
51
|
+
execute: (context: TContext) => Promise<any>;
|
|
52
|
+
}): Step<string, TSchemaIn, TSchemaOut, z.ZodType<any>, z.ZodType<any>, InngestEngineType>;
|
|
32
53
|
|
|
33
54
|
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
|
|
55
|
+
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>;
|
|
56
|
+
createStep: typeof createStep;
|
|
57
|
+
cloneStep<TStepId extends string>(step: Step<string, any, any, any, any, InngestEngineType>, opts: {
|
|
36
58
|
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;
|
|
59
|
+
}): Step<TStepId, any, any, any, any, InngestEngineType>;
|
|
60
|
+
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: {
|
|
61
|
+
id: TWorkflowId;
|
|
62
|
+
}): Workflow<InngestEngineType, TSteps, TWorkflowId, TInput, TOutput, TInput>;
|
|
45
63
|
};
|
|
46
64
|
|
|
47
65
|
export declare type InngestEngineType = {
|
|
@@ -71,6 +89,10 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
71
89
|
};
|
|
72
90
|
runtimeContext: RuntimeContext;
|
|
73
91
|
}): Promise<StepResult<any, any, any, any>>;
|
|
92
|
+
executeSleep({ id, duration }: {
|
|
93
|
+
id: string;
|
|
94
|
+
duration: number;
|
|
95
|
+
}): Promise<void>;
|
|
74
96
|
executeStep({ step, stepResults, executionContext, resume, prevOutput, emitter, runtimeContext, }: {
|
|
75
97
|
step: Step<string, any, any>;
|
|
76
98
|
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
@@ -131,7 +153,7 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
131
153
|
}): Promise<StepResult<any, any, any, any>>;
|
|
132
154
|
}
|
|
133
155
|
|
|
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> {
|
|
156
|
+
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
157
|
#private;
|
|
136
158
|
private inngest;
|
|
137
159
|
serializedStepGraph: SerializedStepFlowEntry[];
|
|
@@ -162,7 +184,7 @@ export declare class InngestRun<TSteps extends Step<string, any, any>[] = Step<s
|
|
|
162
184
|
watch(cb: (event: any) => void): () => void;
|
|
163
185
|
}
|
|
164
186
|
|
|
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,
|
|
187
|
+
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
188
|
#private;
|
|
167
189
|
inngest: Inngest;
|
|
168
190
|
private function;
|
|
@@ -175,10 +197,11 @@ export declare class InngestWorkflow<TSteps extends Step<string, any, any>[] = S
|
|
|
175
197
|
resourceId?: string;
|
|
176
198
|
}): Promise<WorkflowRuns>;
|
|
177
199
|
getWorkflowRunById(runId: string): Promise<WorkflowRun | null>;
|
|
200
|
+
getWorkflowRunExecutionResult(runId: string): Promise<WatchEvent['payload']['workflowState'] | null>;
|
|
178
201
|
__registerMastra(mastra: Mastra): void;
|
|
179
202
|
createRun(options?: {
|
|
180
203
|
runId?: string;
|
|
181
|
-
}): Run<TSteps, TInput, TOutput>;
|
|
204
|
+
}): Run<TEngineType, TSteps, TInput, TOutput>;
|
|
182
205
|
getFunction(): InngestFunction<Omit<InngestFunction.Options<Inngest<ClientOptions>, InngestMiddleware.Stack, InngestFunction.Trigger<string>[] | [{
|
|
183
206
|
cron: string;
|
|
184
207
|
} & 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 }) {
|
|
@@ -163,11 +165,32 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
163
165
|
const storage = this.#mastra?.getStorage();
|
|
164
166
|
if (!storage) {
|
|
165
167
|
this.logger.debug("Cannot get workflow runs. Mastra engine is not initialized");
|
|
166
|
-
return null;
|
|
168
|
+
return this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null;
|
|
167
169
|
}
|
|
168
170
|
const run = await storage.getWorkflowRunById({ runId, workflowName: this.id });
|
|
169
171
|
return run ?? (this.runs.get(runId) ? { ...this.runs.get(runId), workflowName: this.id } : null);
|
|
170
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
|
+
}
|
|
171
194
|
__registerMastra(mastra) {
|
|
172
195
|
this.#mastra = mastra;
|
|
173
196
|
this.executionEngine.__registerMastra(mastra);
|
|
@@ -270,31 +293,128 @@ var InngestWorkflow = class _InngestWorkflow extends workflows.Workflow {
|
|
|
270
293
|
return [this.getFunction(), ...this.getNestedFunctions(this.executionGraph.steps)];
|
|
271
294
|
}
|
|
272
295
|
};
|
|
273
|
-
function
|
|
274
|
-
|
|
275
|
-
{
|
|
276
|
-
id:
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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
|
+
};
|
|
287
390
|
}
|
|
288
391
|
function init(inngest) {
|
|
289
392
|
return {
|
|
290
393
|
createWorkflow(params) {
|
|
291
394
|
return new InngestWorkflow(params, inngest);
|
|
292
395
|
},
|
|
293
|
-
createStep
|
|
294
|
-
|
|
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
|
+
};
|
|
295
405
|
},
|
|
296
|
-
|
|
297
|
-
|
|
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
|
+
}
|
|
298
418
|
};
|
|
299
419
|
}
|
|
300
420
|
var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
@@ -385,6 +505,9 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
385
505
|
runtimeContext
|
|
386
506
|
});
|
|
387
507
|
}
|
|
508
|
+
async executeSleep({ id, duration }) {
|
|
509
|
+
await this.inngestStep.sleep(id, duration);
|
|
510
|
+
}
|
|
388
511
|
async executeStep({
|
|
389
512
|
step,
|
|
390
513
|
stepResults,
|
|
@@ -758,5 +881,6 @@ var InngestExecutionEngine = class extends workflows.DefaultExecutionEngine {
|
|
|
758
881
|
exports.InngestExecutionEngine = InngestExecutionEngine;
|
|
759
882
|
exports.InngestRun = InngestRun;
|
|
760
883
|
exports.InngestWorkflow = InngestWorkflow;
|
|
884
|
+
exports.createStep = createStep;
|
|
761
885
|
exports.init = init;
|
|
762
886
|
exports.serve = serve;
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED