@mastra/inngest 0.0.0-add-runtime-context-to-openai-realtime-20250516201052 → 0.0.0-ai-v5-20250625173645
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 +290 -2
- package/dist/_tsup-dts-rollup.d.cts +127 -56
- package/dist/_tsup-dts-rollup.d.ts +127 -56
- package/dist/index.cjs +362 -47
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +359 -45
- package/package.json +20 -16
- package/src/index.test.ts +4576 -3254
- package/src/index.ts +593 -89
|
@@ -1,68 +1,122 @@
|
|
|
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
|
|
16
|
-
import { NewWorkflow } from '@mastra/core/workflows/vNext';
|
|
17
|
-
import type { NewWorkflowConfig } from '@mastra/core/workflows/vNext';
|
|
18
|
-
import { Run } from '@mastra/core/workflows/vNext';
|
|
15
|
+
import { Run } from '@mastra/core/workflows';
|
|
19
16
|
import { RuntimeContext } from '@mastra/core/di';
|
|
17
|
+
import type { SerializedStepFlowEntry } from '@mastra/core/workflows';
|
|
20
18
|
import { serve as serve_2 } from 'inngest/hono';
|
|
21
19
|
import type { Span } from '@opentelemetry/api';
|
|
22
|
-
import type {
|
|
23
|
-
import type {
|
|
24
|
-
import type {
|
|
25
|
-
import type {
|
|
26
|
-
import
|
|
27
|
-
import type {
|
|
20
|
+
import type { Step } from '@mastra/core/workflows';
|
|
21
|
+
import type { StepFlowEntry } from '@mastra/core/workflows';
|
|
22
|
+
import type { StepResult } from '@mastra/core/workflows';
|
|
23
|
+
import type { StreamEvent } from '@mastra/core/workflows';
|
|
24
|
+
import { Tool } from '@mastra/core/tools';
|
|
25
|
+
import type { ToolExecutionContext } from '@mastra/core';
|
|
26
|
+
import type { WatchEvent } from '@mastra/core/workflows';
|
|
27
|
+
import { Workflow } from '@mastra/core/workflows';
|
|
28
|
+
import type { WorkflowConfig } from '@mastra/core/workflows';
|
|
29
|
+
import type { WorkflowResult } from '@mastra/core/workflows';
|
|
30
|
+
import type { WorkflowRun } from '@mastra/core';
|
|
31
|
+
import type { WorkflowRuns } from '@mastra/core';
|
|
32
|
+
import { z } from 'zod';
|
|
28
33
|
|
|
29
|
-
declare function
|
|
30
|
-
id:
|
|
31
|
-
|
|
34
|
+
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: {
|
|
35
|
+
id: TStepId;
|
|
36
|
+
description?: string;
|
|
37
|
+
inputSchema: TStepInput;
|
|
38
|
+
outputSchema: TStepOutput;
|
|
39
|
+
resumeSchema?: TResumeSchema;
|
|
40
|
+
suspendSchema?: TSuspendSchema;
|
|
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
|
+
|
|
44
|
+
export declare function createStep<TStepId extends string, TStepInput extends z.ZodObject<{
|
|
45
|
+
prompt: z.ZodString;
|
|
46
|
+
}>, TStepOutput extends z.ZodObject<{
|
|
47
|
+
text: z.ZodString;
|
|
48
|
+
}>, TResumeSchema extends z.ZodType<any>, TSuspendSchema extends z.ZodType<any>>(agent: Agent<TStepId, any, any>): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema, InngestEngineType>;
|
|
49
|
+
|
|
50
|
+
export declare function createStep<TSchemaIn extends z.ZodType<any>, TSchemaOut extends z.ZodType<any>, TContext extends ToolExecutionContext<TSchemaIn>>(tool: Tool<TSchemaIn, TSchemaOut, TContext> & {
|
|
51
|
+
inputSchema: TSchemaIn;
|
|
52
|
+
outputSchema: TSchemaOut;
|
|
53
|
+
execute: (context: TContext) => Promise<any>;
|
|
54
|
+
}): Step<string, TSchemaIn, TSchemaOut, z.ZodType<any>, z.ZodType<any>, InngestEngineType>;
|
|
32
55
|
|
|
33
56
|
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
|
|
57
|
+
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
58
|
createStep: typeof createStep;
|
|
36
|
-
cloneStep:
|
|
37
|
-
|
|
59
|
+
cloneStep<TStepId extends string>(step: Step<string, any, any, any, any, InngestEngineType>, opts: {
|
|
60
|
+
id: TStepId;
|
|
61
|
+
}): Step<TStepId, any, any, any, any, InngestEngineType>;
|
|
62
|
+
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: {
|
|
63
|
+
id: TWorkflowId;
|
|
64
|
+
}): Workflow<InngestEngineType, TSteps, TWorkflowId, TInput, TOutput, TPrevSchema>;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export declare type InngestEngineType = {
|
|
68
|
+
step: any;
|
|
38
69
|
};
|
|
39
70
|
|
|
40
71
|
export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
41
72
|
private inngestStep;
|
|
42
73
|
private inngestAttempts;
|
|
43
74
|
constructor(mastra: Mastra, inngestStep: BaseContext<Inngest>['step'], inngestAttempts?: number);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
75
|
+
execute<TInput, TOutput>(params: {
|
|
76
|
+
workflowId: string;
|
|
77
|
+
runId: string;
|
|
78
|
+
graph: ExecutionGraph;
|
|
79
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
80
|
+
input?: TInput;
|
|
81
|
+
resume?: {
|
|
82
|
+
steps: string[];
|
|
83
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
84
|
+
resumePayload: any;
|
|
85
|
+
resumePath: number[];
|
|
86
|
+
};
|
|
87
|
+
emitter: Emitter;
|
|
88
|
+
retryConfig?: {
|
|
89
|
+
attempts?: number;
|
|
90
|
+
delay?: number;
|
|
91
|
+
};
|
|
92
|
+
runtimeContext: RuntimeContext;
|
|
93
|
+
}): Promise<TOutput>;
|
|
94
|
+
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>;
|
|
47
95
|
superExecuteStep({ workflowId, runId, step, stepResults, executionContext, resume, prevOutput, emitter, runtimeContext, }: {
|
|
48
96
|
workflowId: string;
|
|
49
97
|
runId: string;
|
|
50
|
-
step:
|
|
51
|
-
stepResults: Record<string, StepResult<any>>;
|
|
98
|
+
step: Step<string, any, any>;
|
|
99
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
52
100
|
executionContext: ExecutionContext;
|
|
53
101
|
resume?: {
|
|
54
102
|
steps: string[];
|
|
55
103
|
resumePayload: any;
|
|
56
104
|
};
|
|
57
105
|
prevOutput: any;
|
|
58
|
-
emitter:
|
|
59
|
-
emit: (event: string, data: any) => Promise<void>;
|
|
60
|
-
};
|
|
106
|
+
emitter: Emitter;
|
|
61
107
|
runtimeContext: RuntimeContext;
|
|
62
|
-
}): Promise<StepResult<any>>;
|
|
108
|
+
}): Promise<StepResult<any, any, any, any>>;
|
|
109
|
+
executeSleep({ id, duration }: {
|
|
110
|
+
id: string;
|
|
111
|
+
duration: number;
|
|
112
|
+
}): Promise<void>;
|
|
113
|
+
executeWaitForEvent({ event, timeout }: {
|
|
114
|
+
event: string;
|
|
115
|
+
timeout?: number;
|
|
116
|
+
}): Promise<any>;
|
|
63
117
|
executeStep({ step, stepResults, executionContext, resume, prevOutput, emitter, runtimeContext, }: {
|
|
64
|
-
step:
|
|
65
|
-
stepResults: Record<string, StepResult<any>>;
|
|
118
|
+
step: Step<string, any, any>;
|
|
119
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
66
120
|
executionContext: {
|
|
67
121
|
workflowId: string;
|
|
68
122
|
runId: string;
|
|
@@ -79,50 +133,53 @@ export declare class InngestExecutionEngine extends DefaultExecutionEngine {
|
|
|
79
133
|
runId?: string;
|
|
80
134
|
};
|
|
81
135
|
prevOutput: any;
|
|
82
|
-
emitter:
|
|
83
|
-
emit: (event: string, data: any) => Promise<void>;
|
|
84
|
-
};
|
|
136
|
+
emitter: Emitter;
|
|
85
137
|
runtimeContext: RuntimeContext;
|
|
86
|
-
}): Promise<StepResult<any>>;
|
|
87
|
-
persistStepUpdate({ workflowId, runId, stepResults, executionContext, }: {
|
|
138
|
+
}): Promise<StepResult<any, any, any, any>>;
|
|
139
|
+
persistStepUpdate({ workflowId, runId, stepResults, executionContext, serializedStepGraph, workflowStatus, result, error, }: {
|
|
88
140
|
workflowId: string;
|
|
89
141
|
runId: string;
|
|
90
|
-
stepResults: Record<string, StepResult<any>>;
|
|
142
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
143
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
91
144
|
executionContext: ExecutionContext;
|
|
145
|
+
workflowStatus: 'success' | 'failed' | 'suspended' | 'running';
|
|
146
|
+
result?: Record<string, any>;
|
|
147
|
+
error?: string | Error;
|
|
92
148
|
}): Promise<void>;
|
|
93
|
-
executeConditional({ workflowId, runId, entry, prevOutput, prevStep, stepResults, resume, executionContext, emitter, runtimeContext, }: {
|
|
149
|
+
executeConditional({ workflowId, runId, entry, prevOutput, prevStep, stepResults, serializedStepGraph, resume, executionContext, emitter, runtimeContext, }: {
|
|
94
150
|
workflowId: string;
|
|
95
151
|
runId: string;
|
|
96
152
|
entry: {
|
|
97
153
|
type: 'conditional';
|
|
98
154
|
steps: StepFlowEntry[];
|
|
99
|
-
conditions: ExecuteFunction<any, any, any, any>[];
|
|
155
|
+
conditions: ExecuteFunction<any, any, any, any, InngestEngineType>[];
|
|
100
156
|
};
|
|
101
157
|
prevStep: StepFlowEntry;
|
|
158
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
102
159
|
prevOutput: any;
|
|
103
|
-
stepResults: Record<string, StepResult<any>>;
|
|
160
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
104
161
|
resume?: {
|
|
105
162
|
steps: string[];
|
|
106
|
-
stepResults: Record<string, StepResult<any>>;
|
|
163
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
107
164
|
resumePayload: any;
|
|
108
165
|
resumePath: number[];
|
|
109
166
|
};
|
|
110
167
|
executionContext: ExecutionContext;
|
|
111
|
-
emitter:
|
|
112
|
-
emit: (event: string, data: any) => Promise<void>;
|
|
113
|
-
};
|
|
168
|
+
emitter: Emitter;
|
|
114
169
|
runtimeContext: RuntimeContext;
|
|
115
|
-
}): Promise<StepResult<any>>;
|
|
170
|
+
}): Promise<StepResult<any, any, any, any>>;
|
|
116
171
|
}
|
|
117
172
|
|
|
118
|
-
export declare class InngestRun<TSteps extends
|
|
173
|
+
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
174
|
#private;
|
|
120
175
|
private inngest;
|
|
176
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
121
177
|
constructor(params: {
|
|
122
178
|
workflowId: string;
|
|
123
179
|
runId: string;
|
|
124
180
|
executionEngine: ExecutionEngine;
|
|
125
181
|
executionGraph: ExecutionGraph;
|
|
182
|
+
serializedStepGraph: SerializedStepFlowEntry[];
|
|
126
183
|
mastra?: Mastra;
|
|
127
184
|
retryConfig?: {
|
|
128
185
|
attempts?: number;
|
|
@@ -132,35 +189,49 @@ export declare class InngestRun<TSteps extends NewStep<string, any, any>[] = New
|
|
|
132
189
|
}, inngest: Inngest);
|
|
133
190
|
getRuns(eventId: string): Promise<any>;
|
|
134
191
|
getRunOutput(eventId: string): Promise<any>;
|
|
192
|
+
sendEvent(event: string, data: any): Promise<void>;
|
|
135
193
|
start({ inputData, }: {
|
|
136
194
|
inputData?: z.infer<TInput>;
|
|
137
195
|
runtimeContext?: RuntimeContext;
|
|
138
196
|
}): Promise<WorkflowResult<TOutput, TSteps>>;
|
|
139
197
|
resume<TResumeSchema extends z.ZodType<any>>(params: {
|
|
140
198
|
resumeData?: z.infer<TResumeSchema>;
|
|
141
|
-
step:
|
|
199
|
+
step: Step<string, any, any, TResumeSchema, any> | [...Step<string, any, any, any, any>[], Step<string, any, any, TResumeSchema, any>] | string | string[];
|
|
200
|
+
runtimeContext?: RuntimeContext;
|
|
201
|
+
}): Promise<WorkflowResult<TOutput, TSteps>>;
|
|
202
|
+
_resume<TResumeSchema extends z.ZodType<any>>(params: {
|
|
203
|
+
resumeData?: z.infer<TResumeSchema>;
|
|
204
|
+
step: Step<string, any, any, TResumeSchema, any> | [...Step<string, any, any, any, any>[], Step<string, any, any, TResumeSchema, any>] | string | string[];
|
|
142
205
|
runtimeContext?: RuntimeContext;
|
|
143
206
|
}): Promise<WorkflowResult<TOutput, TSteps>>;
|
|
144
|
-
watch(cb: (event:
|
|
207
|
+
watch(cb: (event: WatchEvent) => void, type?: 'watch' | 'watch-v2'): () => void;
|
|
208
|
+
stream({ inputData, runtimeContext }?: {
|
|
209
|
+
inputData?: z.infer<TInput>;
|
|
210
|
+
runtimeContext?: RuntimeContext;
|
|
211
|
+
}): {
|
|
212
|
+
stream: ReadableStream<StreamEvent>;
|
|
213
|
+
getWorkflowState: () => Promise<WorkflowResult<TOutput, TSteps>>;
|
|
214
|
+
};
|
|
145
215
|
}
|
|
146
216
|
|
|
147
|
-
export declare class InngestWorkflow<TSteps extends
|
|
217
|
+
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
218
|
#private;
|
|
149
219
|
inngest: Inngest;
|
|
150
220
|
private function;
|
|
151
|
-
constructor(params:
|
|
221
|
+
constructor(params: WorkflowConfig<TWorkflowId, TInput, TOutput, TSteps>, inngest: Inngest);
|
|
152
222
|
getWorkflowRuns(args?: {
|
|
153
223
|
fromDate?: Date;
|
|
154
224
|
toDate?: Date;
|
|
155
225
|
limit?: number;
|
|
156
226
|
offset?: number;
|
|
157
227
|
resourceId?: string;
|
|
158
|
-
}): Promise<
|
|
159
|
-
getWorkflowRunById(runId: string): Promise<
|
|
228
|
+
}): Promise<WorkflowRuns>;
|
|
229
|
+
getWorkflowRunById(runId: string): Promise<WorkflowRun | null>;
|
|
230
|
+
getWorkflowRunExecutionResult(runId: string): Promise<WatchEvent['payload']['workflowState'] | null>;
|
|
160
231
|
__registerMastra(mastra: Mastra): void;
|
|
161
232
|
createRun(options?: {
|
|
162
233
|
runId?: string;
|
|
163
|
-
}): Run<TSteps, TInput, TOutput>;
|
|
234
|
+
}): Run<TEngineType, TSteps, TInput, TOutput>;
|
|
164
235
|
getFunction(): InngestFunction<Omit<InngestFunction.Options<Inngest<ClientOptions>, InngestMiddleware.Stack, InngestFunction.Trigger<string>[] | [{
|
|
165
236
|
cron: string;
|
|
166
237
|
} & Partial<Record<"event" | "if", never>>] | [{
|