@mastra/inngest 0.0.0-generate-message-id-20250512171942 → 0.0.0-mcp-changeset-20250707162621
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 +468 -3
- package/dist/_tsup-dts-rollup.d.cts +178 -63
- package/dist/_tsup-dts-rollup.d.ts +178 -63
- package/dist/index.cjs +582 -59
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +579 -57
- package/docker-compose.yaml +3 -3
- package/package.json +22 -17
- package/src/index.test.ts +5602 -3512
- package/src/index.ts +883 -103
- package/vitest.config.ts +6 -0
|
@@ -1,128 +1,225 @@
|
|
|
1
|
+
import type { Agent } from '@mastra/core';
|
|
1
2
|
import type { BaseContext } from 'inngest';
|
|
2
3
|
import { ClientOptions } from 'inngest';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import type { ExecutionGraph } from '@mastra/core/workflows/vNext';
|
|
4
|
+
import { DefaultExecutionEngine } from '@mastra/core/workflows';
|
|
5
|
+
import type { Emitter } from '@mastra/core/workflows';
|
|
6
|
+
import type { ExecuteFunction } from '@mastra/core/workflows';
|
|
7
|
+
import type { ExecutionContext } from '@mastra/core/workflows';
|
|
8
|
+
import type { ExecutionEngine } from '@mastra/core/workflows';
|
|
9
|
+
import type { ExecutionGraph } from '@mastra/core/workflows';
|
|
10
10
|
import { Handler } from 'inngest';
|
|
11
11
|
import type { Inngest } from 'inngest';
|
|
12
12
|
import { InngestFunction } from 'inngest';
|
|
13
13
|
import { InngestMiddleware } from 'inngest';
|
|
14
14
|
import type { Mastra } from '@mastra/core';
|
|
15
|
-
import type {
|
|
16
|
-
import {
|
|
17
|
-
import type { NewWorkflowConfig } from '@mastra/core/workflows/vNext';
|
|
18
|
-
import { Run } from '@mastra/core/workflows/vNext';
|
|
15
|
+
import type { ReadableStream as ReadableStream_2 } from 'node:stream/web';
|
|
16
|
+
import { Run } from '@mastra/core/workflows';
|
|
19
17
|
import { RuntimeContext } from '@mastra/core/di';
|
|
18
|
+
import type { SerializedStepFlowEntry } from '@mastra/core/workflows';
|
|
20
19
|
import { serve as serve_2 } from 'inngest/hono';
|
|
21
20
|
import type { Span } from '@opentelemetry/api';
|
|
22
|
-
import type {
|
|
23
|
-
import type {
|
|
24
|
-
import type {
|
|
21
|
+
import type { Step } from '@mastra/core/workflows';
|
|
22
|
+
import type { StepFlowEntry } from '@mastra/core/workflows';
|
|
23
|
+
import type { StepResult } from '@mastra/core/workflows';
|
|
24
|
+
import type { StreamEvent } from '@mastra/core/workflows';
|
|
25
|
+
import { Tool } from '@mastra/core/tools';
|
|
26
|
+
import type { ToolExecutionContext } from '@mastra/core';
|
|
27
|
+
import type { WatchEvent } from '@mastra/core/workflows';
|
|
28
|
+
import { Workflow } from '@mastra/core/workflows';
|
|
29
|
+
import type { WorkflowConfig } from '@mastra/core/workflows';
|
|
30
|
+
import type { WorkflowResult } from '@mastra/core/workflows';
|
|
25
31
|
import type { WorkflowRun } from '@mastra/core';
|
|
26
|
-
import { WorkflowRuns } from '@mastra/core';
|
|
27
|
-
import
|
|
32
|
+
import type { WorkflowRuns } from '@mastra/core';
|
|
33
|
+
import { z } from 'zod';
|
|
28
34
|
|
|
29
|
-
declare function
|
|
30
|
-
id:
|
|
31
|
-
|
|
35
|
+
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: {
|
|
36
|
+
id: TStepId;
|
|
37
|
+
description?: string;
|
|
38
|
+
inputSchema: TStepInput;
|
|
39
|
+
outputSchema: TStepOutput;
|
|
40
|
+
resumeSchema?: TResumeSchema;
|
|
41
|
+
suspendSchema?: TSuspendSchema;
|
|
42
|
+
execute: ExecuteFunction<z.infer<TStepInput>, z.infer<TStepOutput>, z.infer<TResumeSchema>, z.infer<TSuspendSchema>, InngestEngineType>;
|
|
43
|
+
}): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
44
|
+
|
|
45
|
+
export declare function createStep<TStepId extends string, TStepInput extends z.ZodObject<{
|
|
46
|
+
prompt: z.ZodString;
|
|
47
|
+
}>, TStepOutput extends z.ZodObject<{
|
|
48
|
+
text: z.ZodString;
|
|
49
|
+
}>, TResumeSchema extends z.ZodType<any>, TSuspendSchema extends z.ZodType<any>>(agent: Agent<TStepId, any, any>): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
50
|
+
|
|
51
|
+
export declare function createStep<TSchemaIn extends z.ZodType<any>, TSchemaOut extends z.ZodType<any>, TContext extends ToolExecutionContext<TSchemaIn>>(tool: Tool<TSchemaIn, TSchemaOut, TContext> & {
|
|
52
|
+
inputSchema: TSchemaIn;
|
|
53
|
+
outputSchema: TSchemaOut;
|
|
54
|
+
execute: (context: TContext) => Promise<any>;
|
|
55
|
+
}): Step<string, TSchemaIn, TSchemaOut, z.ZodType<any>, z.ZodType<any>, InngestEngineType>;
|
|
32
56
|
|
|
33
57
|
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
|
|
58
|
+
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>;
|
|
35
59
|
createStep: typeof createStep;
|
|
36
|
-
cloneStep:
|
|
37
|
-
|
|
60
|
+
cloneStep<TStepId extends string>(step: Step<string, any, any, any, any, InngestEngineType>, opts: {
|
|
61
|
+
id: TStepId;
|
|
62
|
+
}): Step<TStepId, any, any, any, any, InngestEngineType>;
|
|
63
|
+
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>[], TPrevSchema extends z.ZodType<any> = TInput>(workflow: Workflow<InngestEngineType, TSteps, string, TInput, TOutput, TPrevSchema>, opts: {
|
|
64
|
+
id: TWorkflowId;
|
|
65
|
+
}): Workflow<InngestEngineType, TSteps, TWorkflowId, TInput, TOutput, TPrevSchema>;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export declare type InngestEngineType = {
|
|
69
|
+
step: any;
|
|
38
70
|
};
|
|
39
71
|
|
|
40
72
|
export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
41
73
|
private inngestStep;
|
|
42
74
|
private inngestAttempts;
|
|
43
75
|
constructor(mastra: Mastra, inngestStep: BaseContext<Inngest>['step'], inngestAttempts?: number);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
76
|
+
execute<TInput, TOutput>(params: {
|
|
77
|
+
workflowId: string;
|
|
78
|
+
runId: string;
|
|
79
|
+
graph: ExecutionGraph;
|
|
80
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
81
|
+
input?: TInput;
|
|
82
|
+
resume?: {
|
|
83
|
+
steps: string[];
|
|
84
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
85
|
+
resumePayload: any;
|
|
86
|
+
resumePath: number[];
|
|
87
|
+
};
|
|
88
|
+
emitter: Emitter;
|
|
89
|
+
retryConfig?: {
|
|
90
|
+
attempts?: number;
|
|
91
|
+
delay?: number;
|
|
92
|
+
};
|
|
93
|
+
runtimeContext: RuntimeContext;
|
|
94
|
+
abortController: AbortController;
|
|
95
|
+
}): Promise<TOutput>;
|
|
96
|
+
protected fmtReturnValue<TOutput>(executionSpan: Span | undefined, emitter: Emitter, stepResults: Record<string, StepResult<any, any, any, any>>, lastOutput: StepResult<any, any, any, any>, error?: Error | string): Promise<TOutput>;
|
|
97
|
+
superExecuteStep({ workflowId, runId, step, stepResults, executionContext, resume, prevOutput, emitter, abortController, runtimeContext, }: {
|
|
48
98
|
workflowId: string;
|
|
49
99
|
runId: string;
|
|
50
|
-
step:
|
|
51
|
-
stepResults: Record<string, StepResult<any>>;
|
|
100
|
+
step: Step<string, any, any>;
|
|
101
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
52
102
|
executionContext: ExecutionContext;
|
|
53
103
|
resume?: {
|
|
54
104
|
steps: string[];
|
|
55
105
|
resumePayload: any;
|
|
56
106
|
};
|
|
57
107
|
prevOutput: any;
|
|
58
|
-
emitter:
|
|
59
|
-
|
|
108
|
+
emitter: Emitter;
|
|
109
|
+
abortController: AbortController;
|
|
110
|
+
runtimeContext: RuntimeContext;
|
|
111
|
+
}): Promise<StepResult<any, any, any, any>>;
|
|
112
|
+
executeSleep({ workflowId, runId, entry, prevOutput, stepResults, emitter, abortController, runtimeContext, }: {
|
|
113
|
+
workflowId: string;
|
|
114
|
+
runId: string;
|
|
115
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
116
|
+
entry: {
|
|
117
|
+
type: 'sleep';
|
|
118
|
+
id: string;
|
|
119
|
+
duration?: number;
|
|
120
|
+
fn?: ExecuteFunction<any, any, any, any, InngestEngineType>;
|
|
60
121
|
};
|
|
122
|
+
prevStep: StepFlowEntry;
|
|
123
|
+
prevOutput: any;
|
|
124
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
125
|
+
resume?: {
|
|
126
|
+
steps: string[];
|
|
127
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
128
|
+
resumePayload: any;
|
|
129
|
+
resumePath: number[];
|
|
130
|
+
};
|
|
131
|
+
executionContext: ExecutionContext;
|
|
132
|
+
emitter: Emitter;
|
|
133
|
+
abortController: AbortController;
|
|
61
134
|
runtimeContext: RuntimeContext;
|
|
62
|
-
}): Promise<
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
attempts: number;
|
|
73
|
-
delay: number;
|
|
74
|
-
};
|
|
135
|
+
}): Promise<void>;
|
|
136
|
+
executeSleepUntil({ workflowId, runId, entry, prevOutput, stepResults, emitter, abortController, runtimeContext, }: {
|
|
137
|
+
workflowId: string;
|
|
138
|
+
runId: string;
|
|
139
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
140
|
+
entry: {
|
|
141
|
+
type: 'sleepUntil';
|
|
142
|
+
id: string;
|
|
143
|
+
date?: Date;
|
|
144
|
+
fn?: ExecuteFunction<any, any, any, any, InngestEngineType>;
|
|
75
145
|
};
|
|
146
|
+
prevStep: StepFlowEntry;
|
|
147
|
+
prevOutput: any;
|
|
148
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
149
|
+
resume?: {
|
|
150
|
+
steps: string[];
|
|
151
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
152
|
+
resumePayload: any;
|
|
153
|
+
resumePath: number[];
|
|
154
|
+
};
|
|
155
|
+
executionContext: ExecutionContext;
|
|
156
|
+
emitter: Emitter;
|
|
157
|
+
abortController: AbortController;
|
|
158
|
+
runtimeContext: RuntimeContext;
|
|
159
|
+
}): Promise<void>;
|
|
160
|
+
executeWaitForEvent({ event, timeout }: {
|
|
161
|
+
event: string;
|
|
162
|
+
timeout?: number;
|
|
163
|
+
}): Promise<any>;
|
|
164
|
+
executeStep({ step, stepResults, executionContext, resume, prevOutput, emitter, abortController, runtimeContext, }: {
|
|
165
|
+
step: Step<string, any, any>;
|
|
166
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
167
|
+
executionContext: ExecutionContext;
|
|
76
168
|
resume?: {
|
|
77
169
|
steps: string[];
|
|
78
170
|
resumePayload: any;
|
|
79
171
|
runId?: string;
|
|
80
172
|
};
|
|
81
173
|
prevOutput: any;
|
|
82
|
-
emitter:
|
|
83
|
-
|
|
84
|
-
};
|
|
174
|
+
emitter: Emitter;
|
|
175
|
+
abortController: AbortController;
|
|
85
176
|
runtimeContext: RuntimeContext;
|
|
86
|
-
}): Promise<StepResult<any>>;
|
|
87
|
-
persistStepUpdate({ workflowId, runId, stepResults, executionContext, }: {
|
|
177
|
+
}): Promise<StepResult<any, any, any, any>>;
|
|
178
|
+
persistStepUpdate({ workflowId, runId, stepResults, executionContext, serializedStepGraph, workflowStatus, result, error, }: {
|
|
88
179
|
workflowId: string;
|
|
89
180
|
runId: string;
|
|
90
|
-
stepResults: Record<string, StepResult<any>>;
|
|
181
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
182
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
91
183
|
executionContext: ExecutionContext;
|
|
184
|
+
workflowStatus: 'success' | 'failed' | 'suspended' | 'running';
|
|
185
|
+
result?: Record<string, any>;
|
|
186
|
+
error?: string | Error;
|
|
92
187
|
}): Promise<void>;
|
|
93
|
-
executeConditional({ workflowId, runId, entry, prevOutput, prevStep, stepResults, resume, executionContext, emitter, runtimeContext, }: {
|
|
188
|
+
executeConditional({ workflowId, runId, entry, prevOutput, prevStep, stepResults, serializedStepGraph, resume, executionContext, emitter, abortController, runtimeContext, }: {
|
|
94
189
|
workflowId: string;
|
|
95
190
|
runId: string;
|
|
96
191
|
entry: {
|
|
97
192
|
type: 'conditional';
|
|
98
193
|
steps: StepFlowEntry[];
|
|
99
|
-
conditions: ExecuteFunction<any, any, any, any>[];
|
|
194
|
+
conditions: ExecuteFunction<any, any, any, any, InngestEngineType>[];
|
|
100
195
|
};
|
|
101
196
|
prevStep: StepFlowEntry;
|
|
197
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
102
198
|
prevOutput: any;
|
|
103
|
-
stepResults: Record<string, StepResult<any>>;
|
|
199
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
104
200
|
resume?: {
|
|
105
201
|
steps: string[];
|
|
106
|
-
stepResults: Record<string, StepResult<any>>;
|
|
202
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
107
203
|
resumePayload: any;
|
|
108
204
|
resumePath: number[];
|
|
109
205
|
};
|
|
110
206
|
executionContext: ExecutionContext;
|
|
111
|
-
emitter:
|
|
112
|
-
|
|
113
|
-
};
|
|
207
|
+
emitter: Emitter;
|
|
208
|
+
abortController: AbortController;
|
|
114
209
|
runtimeContext: RuntimeContext;
|
|
115
|
-
}): Promise<StepResult<any>>;
|
|
210
|
+
}): Promise<StepResult<any, any, any, any>>;
|
|
116
211
|
}
|
|
117
212
|
|
|
118
|
-
export declare class InngestRun<TSteps extends
|
|
213
|
+
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> {
|
|
119
214
|
#private;
|
|
120
215
|
private inngest;
|
|
216
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
121
217
|
constructor(params: {
|
|
122
218
|
workflowId: string;
|
|
123
219
|
runId: string;
|
|
124
220
|
executionEngine: ExecutionEngine;
|
|
125
221
|
executionGraph: ExecutionGraph;
|
|
222
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
126
223
|
mastra?: Mastra;
|
|
127
224
|
retryConfig?: {
|
|
128
225
|
attempts?: number;
|
|
@@ -132,23 +229,37 @@ export declare class InngestRun<TSteps extends NewStep<string, any, any>[] = New
|
|
|
132
229
|
}, inngest: Inngest);
|
|
133
230
|
getRuns(eventId: string): Promise<any>;
|
|
134
231
|
getRunOutput(eventId: string): Promise<any>;
|
|
232
|
+
sendEvent(event: string, data: any): Promise<void>;
|
|
233
|
+
cancel(): Promise<void>;
|
|
135
234
|
start({ inputData, }: {
|
|
136
235
|
inputData?: z.infer<TInput>;
|
|
137
236
|
runtimeContext?: RuntimeContext;
|
|
138
237
|
}): Promise<WorkflowResult<TOutput, TSteps>>;
|
|
139
238
|
resume<TResumeSchema extends z.ZodType<any>>(params: {
|
|
140
239
|
resumeData?: z.infer<TResumeSchema>;
|
|
141
|
-
step:
|
|
240
|
+
step: Step<string, any, any, TResumeSchema, any> | [...Step<string, any, any, any, any>[], Step<string, any, any, TResumeSchema, any>] | string | string[];
|
|
142
241
|
runtimeContext?: RuntimeContext;
|
|
143
242
|
}): Promise<WorkflowResult<TOutput, TSteps>>;
|
|
144
|
-
|
|
243
|
+
_resume<TResumeSchema extends z.ZodType<any>>(params: {
|
|
244
|
+
resumeData?: z.infer<TResumeSchema>;
|
|
245
|
+
step: Step<string, any, any, TResumeSchema, any> | [...Step<string, any, any, any, any>[], Step<string, any, any, TResumeSchema, any>] | string | string[];
|
|
246
|
+
runtimeContext?: RuntimeContext;
|
|
247
|
+
}): Promise<WorkflowResult<TOutput, TSteps>>;
|
|
248
|
+
watch(cb: (event: WatchEvent) => void, type?: 'watch' | 'watch-v2'): () => void;
|
|
249
|
+
stream({ inputData, runtimeContext }?: {
|
|
250
|
+
inputData?: z.infer<TInput>;
|
|
251
|
+
runtimeContext?: RuntimeContext;
|
|
252
|
+
}): {
|
|
253
|
+
stream: ReadableStream_2<StreamEvent>;
|
|
254
|
+
getWorkflowState: () => Promise<WorkflowResult<TOutput, TSteps>>;
|
|
255
|
+
};
|
|
145
256
|
}
|
|
146
257
|
|
|
147
|
-
export declare class InngestWorkflow<TSteps extends
|
|
258
|
+
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> {
|
|
148
259
|
#private;
|
|
149
260
|
inngest: Inngest;
|
|
150
261
|
private function;
|
|
151
|
-
constructor(params:
|
|
262
|
+
constructor(params: WorkflowConfig<TWorkflowId, TInput, TOutput, TSteps>, inngest: Inngest);
|
|
152
263
|
getWorkflowRuns(args?: {
|
|
153
264
|
fromDate?: Date;
|
|
154
265
|
toDate?: Date;
|
|
@@ -157,10 +268,14 @@ export declare class InngestWorkflow<TSteps extends NewStep<string, any, any>[]
|
|
|
157
268
|
resourceId?: string;
|
|
158
269
|
}): Promise<WorkflowRuns>;
|
|
159
270
|
getWorkflowRunById(runId: string): Promise<WorkflowRun | null>;
|
|
271
|
+
getWorkflowRunExecutionResult(runId: string): Promise<WatchEvent['payload']['workflowState'] | null>;
|
|
160
272
|
__registerMastra(mastra: Mastra): void;
|
|
161
273
|
createRun(options?: {
|
|
162
274
|
runId?: string;
|
|
163
|
-
}): Run<TSteps, TInput, TOutput>;
|
|
275
|
+
}): Run<TEngineType, TSteps, TInput, TOutput>;
|
|
276
|
+
createRunAsync(options?: {
|
|
277
|
+
runId?: string;
|
|
278
|
+
}): Promise<Run<TEngineType, TSteps, TInput, TOutput>>;
|
|
164
279
|
getFunction(): InngestFunction<Omit<InngestFunction.Options<Inngest<ClientOptions>, InngestMiddleware.Stack, InngestFunction.Trigger<string>[] | [{
|
|
165
280
|
cron: string;
|
|
166
281
|
} & Partial<Record<"event" | "if", never>>] | [{
|