@mastra/core 0.10.1 → 0.10.2-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/dist/agent/index.cjs +7 -2
- package/dist/agent/index.d.cts +9 -9
- package/dist/agent/index.d.ts +9 -9
- package/dist/agent/index.js +2 -1
- package/dist/{base-QP4OC4dB.d.ts → base-CAqn5W09.d.ts} +1454 -1361
- package/dist/{base-B96VvaWm.d.cts → base-D9eDBAGU.d.cts} +1454 -1361
- package/dist/{chunk-SFZZYGKB.cjs → chunk-45KYIT4M.cjs} +2 -2
- package/dist/{chunk-VRACJIAE.js → chunk-4E23D2OW.js} +2 -2
- package/dist/{chunk-STLR3SIQ.cjs → chunk-4I6LG5EO.cjs} +6 -92
- package/dist/{chunk-2YYOF7DO.js → chunk-5UFUPI3G.js} +5 -91
- package/dist/{chunk-U3L3NEOM.cjs → chunk-DXLVS7ML.cjs} +1 -19
- package/dist/{chunk-2PW6UJMW.js → chunk-EQTIDVPN.js} +2 -19
- package/dist/{chunk-MAFHTHTJ.cjs → chunk-F36FCB7W.cjs} +4 -4
- package/dist/{chunk-5JRD3NDP.cjs → chunk-I5OLBJ26.cjs} +6 -77
- package/dist/chunk-LCCQWUQP.js +962 -0
- package/dist/{chunk-SLKAWVQR.cjs → chunk-MRZIV2XD.cjs} +192 -378
- package/dist/{chunk-SKG2NIZW.cjs → chunk-RK6DHZUA.cjs} +2 -2
- package/dist/{chunk-OCT2762Q.js → chunk-RMTG7VWR.js} +1 -1
- package/dist/{chunk-RARKB3F2.js → chunk-UNWU2RJV.js} +1 -1
- package/dist/chunk-XAO67QBR.cjs +964 -0
- package/dist/{chunk-RFERFI6B.js → chunk-YA4JI2CB.js} +183 -369
- package/dist/{chunk-BPTSLJHA.js → chunk-ZJYHZO6Y.js} +2 -73
- package/dist/eval/index.d.cts +8 -8
- package/dist/eval/index.d.ts +8 -8
- package/dist/index.cjs +46 -50
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +10 -10
- package/dist/integration/index.cjs +3 -3
- package/dist/integration/index.d.cts +9 -9
- package/dist/integration/index.d.ts +9 -9
- package/dist/integration/index.js +1 -1
- package/dist/llm/index.d.cts +8 -8
- package/dist/llm/index.d.ts +8 -8
- package/dist/mastra/index.d.cts +6 -6
- package/dist/mastra/index.d.ts +6 -6
- package/dist/mcp/index.d.cts +11 -11
- package/dist/mcp/index.d.ts +11 -11
- package/dist/memory/index.cjs +4 -4
- package/dist/memory/index.d.cts +9 -9
- package/dist/memory/index.d.ts +9 -9
- package/dist/memory/index.js +1 -1
- package/dist/network/index.cjs +4 -4
- package/dist/network/index.d.cts +9 -9
- package/dist/network/index.d.ts +9 -9
- package/dist/network/index.js +2 -2
- package/dist/relevance/index.cjs +4 -4
- package/dist/relevance/index.d.cts +11 -11
- package/dist/relevance/index.d.ts +11 -11
- package/dist/relevance/index.js +1 -1
- package/dist/server/index.d.cts +9 -9
- package/dist/server/index.d.ts +9 -9
- package/dist/storage/index.d.cts +18 -18
- package/dist/storage/index.d.ts +18 -18
- package/dist/telemetry/index.d.cts +9 -9
- package/dist/telemetry/index.d.ts +9 -9
- package/dist/tools/index.cjs +4 -4
- package/dist/tools/index.d.cts +9 -9
- package/dist/tools/index.d.ts +9 -9
- package/dist/tools/index.js +1 -1
- package/dist/utils.cjs +15 -19
- package/dist/utils.d.cts +10 -11
- package/dist/utils.d.ts +10 -11
- package/dist/utils.js +1 -1
- package/dist/voice/index.d.cts +9 -9
- package/dist/voice/index.d.ts +9 -9
- package/dist/workflows/index.cjs +9 -9
- package/dist/workflows/index.d.cts +9 -9
- package/dist/workflows/index.d.ts +9 -9
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/legacy/index.cjs +22 -22
- package/dist/workflows/legacy/index.d.cts +9 -9
- package/dist/workflows/legacy/index.d.ts +9 -9
- package/dist/workflows/legacy/index.js +1 -1
- package/package.json +5 -2
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import * as ai from 'ai';
|
|
2
|
-
import { Tool as Tool$1, Schema, ToolExecutionOptions, EmbeddingModel, CoreMessage as CoreMessage$1,
|
|
2
|
+
import { Tool as Tool$1, Schema, ToolExecutionOptions, UserContent, AssistantContent, ToolContent, EmbeddingModel, CoreMessage as CoreMessage$1, UIMessage, IDGenerator as IDGenerator$1, Message, CoreSystemMessage as CoreSystemMessage$1, LanguageModel as LanguageModel$1, GenerateTextResult, GenerateObjectResult, StreamTextResult, StreamObjectResult, DeepPartial, generateText, generateObject, streamText, streamObject, TelemetrySettings, CoreAssistantMessage as CoreAssistantMessage$1, CoreUserMessage as CoreUserMessage$1, CoreToolMessage as CoreToolMessage$1, EmbedResult as EmbedResult$1, EmbedManyResult as EmbedManyResult$1, LanguageModelV1, GenerateTextOnStepFinishCallback, StreamTextOnFinishCallback, StreamObjectOnFinishCallback, StreamTextOnStepFinishCallback } from 'ai';
|
|
3
3
|
import { M as MastraBase, T as Telemetry, O as OtelConfig } from './base-tc5kgDTD.js';
|
|
4
|
-
import { M as Metric, a as MetricResult, T as TestInfo } from './types-Bo1uigWx.js';
|
|
5
|
-
import { Query } from 'sift';
|
|
6
4
|
import { z, ZodSchema } from 'zod';
|
|
7
5
|
import { JSONSchema7Type, JSONSchema7 } from 'json-schema';
|
|
8
|
-
import { MastraDeployer } from './deployer/index.js';
|
|
9
6
|
import { B as BaseLogMessage, R as RegisteredLogger, I as IMastraLogger } from './logger-EhZkzZOr.js';
|
|
10
|
-
import * as http from 'node:http';
|
|
11
|
-
import { Context, Handler, MiddlewareHandler, HonoRequest } from 'hono';
|
|
12
|
-
import { RuntimeContext } from './runtime-context/index.js';
|
|
13
7
|
import { MastraTTS } from './tts/index.js';
|
|
14
8
|
import { MastraVector } from './vector/index.js';
|
|
9
|
+
import { M as Metric, a as MetricResult, T as TestInfo } from './types-Bo1uigWx.js';
|
|
10
|
+
import { Query } from 'sift';
|
|
11
|
+
import { RuntimeContext } from './runtime-context/index.js';
|
|
15
12
|
import { Span } from '@opentelemetry/api';
|
|
16
13
|
import * as xstate from 'xstate';
|
|
17
14
|
import { Snapshot } from 'xstate';
|
|
18
15
|
import EventEmitter from 'node:events';
|
|
16
|
+
import * as http from 'node:http';
|
|
17
|
+
import { Context, Handler, MiddlewareHandler, HonoRequest } from 'hono';
|
|
19
18
|
import EventEmitter$1 from 'events';
|
|
20
19
|
import { EMITTER_SYMBOL } from './workflows/constants.js';
|
|
20
|
+
import { MockLanguageModelV1 } from 'ai/test';
|
|
21
|
+
import { MastraDeployer } from './deployer/index.js';
|
|
21
22
|
import { cors } from 'hono/cors';
|
|
22
23
|
import { DescribeRouteOptions } from 'hono-openapi';
|
|
23
|
-
import { MockLanguageModelV1 } from 'ai/test';
|
|
24
24
|
|
|
25
25
|
type BundlerConfig = {
|
|
26
26
|
externals?: string[];
|
|
@@ -86,645 +86,174 @@ type Run$1 = {
|
|
|
86
86
|
runStatus?: RunStatus;
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
interface WorkflowOptions<TWorkflowName extends string = string, TSteps extends LegacyStep<string, any, any, any>[] = LegacyStep<string, any, any, any>[], TTriggerSchema extends z.ZodObject<any> = any, TResultSchema extends z.ZodObject<any> = any> {
|
|
90
|
+
steps?: TSteps;
|
|
91
|
+
name: TWorkflowName;
|
|
92
|
+
triggerSchema?: TTriggerSchema;
|
|
93
|
+
result?: {
|
|
94
|
+
schema: TResultSchema;
|
|
95
|
+
mapping?: {
|
|
96
|
+
[K in keyof z.infer<TResultSchema>]?: any;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
events?: Record<string, {
|
|
100
|
+
schema: z.ZodObject<any>;
|
|
101
|
+
}>;
|
|
102
|
+
retryConfig?: RetryConfig;
|
|
103
|
+
mastra?: Mastra;
|
|
104
|
+
}
|
|
105
|
+
interface StepExecutionContext<TSchemaIn extends z.ZodSchema | undefined = undefined, TContext extends WorkflowContext = WorkflowContext> extends IExecutionContext<TSchemaIn> {
|
|
106
|
+
context: TSchemaIn extends z.ZodSchema ? {
|
|
107
|
+
inputData: z.infer<TSchemaIn>;
|
|
108
|
+
} & TContext : TContext;
|
|
109
|
+
suspend: (payload?: unknown, softSuspend?: any) => Promise<void>;
|
|
110
|
+
runId: string;
|
|
111
|
+
emit: (event: string, data: any) => void;
|
|
112
|
+
mastra?: MastraUnion;
|
|
113
|
+
runtimeContext: RuntimeContext;
|
|
114
|
+
}
|
|
115
|
+
interface StepAction<TId extends string, TSchemaIn extends z.ZodSchema | undefined, TSchemaOut extends z.ZodSchema | undefined, TContext extends StepExecutionContext<TSchemaIn>> extends IAction<TId, TSchemaIn, TSchemaOut, TContext> {
|
|
116
|
+
mastra?: Mastra;
|
|
117
|
+
payload?: TSchemaIn extends z.ZodSchema ? Partial<z.infer<TSchemaIn>> : unknown;
|
|
118
|
+
execute: (context: TContext) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
|
|
119
|
+
retryConfig?: RetryConfig;
|
|
120
|
+
workflow?: LegacyWorkflow;
|
|
121
|
+
workflowId?: string;
|
|
122
|
+
}
|
|
123
|
+
interface SimpleConditionalType {
|
|
124
|
+
[key: `${string}.${string}`]: string | Query<any>;
|
|
125
|
+
}
|
|
126
|
+
type StepVariableType<TId extends string, TSchemaIn extends z.ZodSchema | undefined, TSchemaOut extends z.ZodSchema | undefined, TContext extends StepExecutionContext<TSchemaIn>> = StepAction<TId, TSchemaIn, TSchemaOut, TContext> | 'trigger' | {
|
|
127
|
+
id: string;
|
|
93
128
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
129
|
+
type StepNode = {
|
|
130
|
+
id: string;
|
|
131
|
+
step: StepAction<any, any, any, any>;
|
|
132
|
+
config: StepDef<any, any, any, any>[any];
|
|
133
|
+
};
|
|
134
|
+
type StepGraph = {
|
|
135
|
+
initial: StepNode[];
|
|
136
|
+
[key: string]: StepNode[];
|
|
137
|
+
};
|
|
138
|
+
type RetryConfig = {
|
|
139
|
+
attempts?: number;
|
|
140
|
+
delay?: number;
|
|
141
|
+
};
|
|
142
|
+
type VariableReference$1<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>> = TStep extends StepAction<any, any, any, any> ? {
|
|
143
|
+
step: TStep;
|
|
144
|
+
path: PathsToStringProps$1<ExtractSchemaType$1<ExtractSchemaFromStep$1<TStep, 'outputSchema'>>> | '' | '.';
|
|
145
|
+
} : TStep extends 'trigger' ? {
|
|
146
|
+
step: 'trigger';
|
|
147
|
+
path: PathsToStringProps$1<ExtractSchemaType$1<TTriggerSchema>> | '.' | '';
|
|
148
|
+
} : {
|
|
149
|
+
step: {
|
|
150
|
+
id: string;
|
|
151
|
+
};
|
|
152
|
+
path: string;
|
|
153
|
+
};
|
|
154
|
+
interface BaseCondition<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>> {
|
|
155
|
+
ref: TStep extends StepAction<any, any, any, any> ? {
|
|
156
|
+
step: TStep;
|
|
157
|
+
path: PathsToStringProps$1<ExtractSchemaType$1<ExtractSchemaFromStep$1<TStep, 'outputSchema'>>> | '' | '.' | 'status';
|
|
158
|
+
} : TStep extends 'trigger' ? {
|
|
159
|
+
step: 'trigger';
|
|
160
|
+
path: PathsToStringProps$1<ExtractSchemaType$1<TTriggerSchema>> | '.' | '';
|
|
161
|
+
} : {
|
|
162
|
+
step: {
|
|
163
|
+
id: string;
|
|
164
|
+
};
|
|
165
|
+
path: string;
|
|
166
|
+
};
|
|
167
|
+
query: Query<any>;
|
|
105
168
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
169
|
+
type ActionContext<TSchemaIn extends z.ZodType<any>> = StepExecutionContext<z.infer<TSchemaIn>, WorkflowContext>;
|
|
170
|
+
declare enum WhenConditionReturnValue {
|
|
171
|
+
CONTINUE = "continue",
|
|
172
|
+
CONTINUE_FAILED = "continue_failed",
|
|
173
|
+
ABORT = "abort",
|
|
174
|
+
LIMBO = "limbo"
|
|
175
|
+
}
|
|
176
|
+
type StepDef<TStepId extends TSteps[number]['id'], TSteps extends StepAction<any, any, any, any>[], TSchemaIn extends z.ZodType<any>, TSchemaOut extends z.ZodType<any>> = Record<TStepId, {
|
|
177
|
+
id?: string;
|
|
178
|
+
when?: Condition<any, any> | ((args: {
|
|
179
|
+
context: WorkflowContext;
|
|
180
|
+
mastra?: Mastra;
|
|
181
|
+
}) => Promise<boolean | WhenConditionReturnValue>);
|
|
182
|
+
serializedWhen?: Condition<any, any> | string;
|
|
183
|
+
loopLabel?: string;
|
|
184
|
+
loopType?: 'while' | 'until';
|
|
185
|
+
data: TSchemaIn;
|
|
186
|
+
handler: (args: ActionContext<TSchemaIn>) => Promise<z.infer<TSchemaOut>>;
|
|
187
|
+
}>;
|
|
188
|
+
type StepCondition<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>> = BaseCondition<TStep, TTriggerSchema> | SimpleConditionalType | {
|
|
189
|
+
and: StepCondition<TStep, TTriggerSchema>[];
|
|
190
|
+
} | {
|
|
191
|
+
or: StepCondition<TStep, TTriggerSchema>[];
|
|
192
|
+
} | {
|
|
193
|
+
not: StepCondition<TStep, TTriggerSchema>;
|
|
194
|
+
};
|
|
195
|
+
type Condition<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>> = BaseCondition<TStep, TTriggerSchema> | SimpleConditionalType | {
|
|
196
|
+
and: Condition<TStep, TTriggerSchema>[];
|
|
197
|
+
} | {
|
|
198
|
+
or: Condition<TStep, TTriggerSchema>[];
|
|
199
|
+
} | {
|
|
200
|
+
not: Condition<TStep, TTriggerSchema>;
|
|
201
|
+
};
|
|
202
|
+
interface StepConfig<TStep extends StepAction<any, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>, TSteps extends LegacyStep<string, any, any, any>[] = LegacyStep<string, any, any, any>[]> {
|
|
203
|
+
when?: Condition<CondStep, TTriggerSchema> | ((args: {
|
|
204
|
+
context: WorkflowContext<TTriggerSchema, TSteps>;
|
|
205
|
+
mastra?: Mastra;
|
|
206
|
+
}) => Promise<boolean | WhenConditionReturnValue>);
|
|
207
|
+
variables?: StepInputType<TStep, 'inputSchema'> extends never ? Record<string, VariableReference$1<VarStep, TTriggerSchema>> : {
|
|
208
|
+
[K in keyof StepInputType<TStep, 'inputSchema'>]?: VariableReference$1<VarStep, TTriggerSchema>;
|
|
111
209
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
210
|
+
'#internal'?: {
|
|
211
|
+
when?: Condition<CondStep, TTriggerSchema> | ((args: {
|
|
212
|
+
context: WorkflowContext<TTriggerSchema, TSteps>;
|
|
213
|
+
mastra?: Mastra;
|
|
214
|
+
}) => Promise<boolean | WhenConditionReturnValue>);
|
|
215
|
+
loopLabel?: string;
|
|
216
|
+
loopType?: 'while' | 'until' | undefined;
|
|
115
217
|
};
|
|
218
|
+
id?: string;
|
|
219
|
+
}
|
|
220
|
+
type StepSuccess$1<T> = {
|
|
221
|
+
status: 'success';
|
|
222
|
+
output: T;
|
|
116
223
|
};
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
setEmbedder(embedder: EmbeddingModel<string>): void;
|
|
137
|
-
/**
|
|
138
|
-
* Get a system message to inject into the conversation.
|
|
139
|
-
* This will be called before each conversation turn.
|
|
140
|
-
* Implementations can override this to inject custom system messages.
|
|
141
|
-
*/
|
|
142
|
-
getSystemMessage(_input: {
|
|
143
|
-
threadId: string;
|
|
144
|
-
memoryConfig?: MemoryConfig;
|
|
145
|
-
}): Promise<string | null>;
|
|
146
|
-
/**
|
|
147
|
-
* Get tools that should be available to the agent.
|
|
148
|
-
* This will be called when converting tools for the agent.
|
|
149
|
-
* Implementations can override this to provide additional tools.
|
|
150
|
-
*/
|
|
151
|
-
getTools(_config?: MemoryConfig): Record<string, CoreTool>;
|
|
152
|
-
protected createEmbeddingIndex(dimensions?: number): Promise<{
|
|
153
|
-
indexName: string;
|
|
224
|
+
type StepSuspended$1<T> = {
|
|
225
|
+
status: 'suspended';
|
|
226
|
+
suspendPayload?: any;
|
|
227
|
+
output?: T;
|
|
228
|
+
};
|
|
229
|
+
type StepWaiting = {
|
|
230
|
+
status: 'waiting';
|
|
231
|
+
};
|
|
232
|
+
type StepFailure$1 = {
|
|
233
|
+
status: 'failed';
|
|
234
|
+
error: string;
|
|
235
|
+
};
|
|
236
|
+
type StepSkipped = {
|
|
237
|
+
status: 'skipped';
|
|
238
|
+
};
|
|
239
|
+
type StepResult$1<T> = StepSuccess$1<T> | StepFailure$1 | StepSuspended$1<T> | StepWaiting | StepSkipped;
|
|
240
|
+
type StepsRecord$1<T extends readonly LegacyStep<any, any, z.ZodType<any> | undefined>[]> = {
|
|
241
|
+
[K in T[number]['id']]: Extract<T[number], {
|
|
242
|
+
id: K;
|
|
154
243
|
}>;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
resourceId?: string;
|
|
169
|
-
vectorMessageSearch?: string;
|
|
170
|
-
systemMessage?: CoreMessage$1;
|
|
171
|
-
config?: MemoryConfig;
|
|
172
|
-
}): Promise<{
|
|
173
|
-
threadId: string;
|
|
174
|
-
messages: CoreMessage$1[];
|
|
175
|
-
uiMessages: Message[];
|
|
176
|
-
}>;
|
|
177
|
-
estimateTokens(text: string): number;
|
|
178
|
-
protected parseMessages(messages: MessageType[]): CoreMessage$1[];
|
|
179
|
-
protected convertToUIMessages(messages: MessageType[]): Message[];
|
|
180
|
-
/**
|
|
181
|
-
* Retrieves a specific thread by its ID
|
|
182
|
-
* @param threadId - The unique identifier of the thread
|
|
183
|
-
* @returns Promise resolving to the thread or null if not found
|
|
184
|
-
*/
|
|
185
|
-
abstract getThreadById({ threadId }: {
|
|
186
|
-
threadId: string;
|
|
187
|
-
}): Promise<StorageThreadType | null>;
|
|
188
|
-
abstract getThreadsByResourceId({ resourceId }: {
|
|
189
|
-
resourceId: string;
|
|
190
|
-
}): Promise<StorageThreadType[]>;
|
|
191
|
-
/**
|
|
192
|
-
* Saves or updates a thread
|
|
193
|
-
* @param thread - The thread data to save
|
|
194
|
-
* @returns Promise resolving to the saved thread
|
|
195
|
-
*/
|
|
196
|
-
abstract saveThread({ thread, memoryConfig, }: {
|
|
197
|
-
thread: StorageThreadType;
|
|
198
|
-
memoryConfig?: MemoryConfig;
|
|
199
|
-
}): Promise<StorageThreadType>;
|
|
200
|
-
/**
|
|
201
|
-
* Saves messages to a thread
|
|
202
|
-
* @param messages - Array of messages to save
|
|
203
|
-
* @returns Promise resolving to the saved messages
|
|
204
|
-
*/
|
|
205
|
-
abstract saveMessages({ messages, memoryConfig, }: {
|
|
206
|
-
messages: MessageType[];
|
|
207
|
-
memoryConfig: MemoryConfig | undefined;
|
|
208
|
-
}): Promise<MessageType[]>;
|
|
209
|
-
/**
|
|
210
|
-
* Retrieves all messages for a specific thread
|
|
211
|
-
* @param threadId - The unique identifier of the thread
|
|
212
|
-
* @returns Promise resolving to array of messages and uiMessages
|
|
213
|
-
*/
|
|
214
|
-
abstract query({ threadId, resourceId, selectBy, }: StorageGetMessagesArg): Promise<{
|
|
215
|
-
messages: CoreMessage$1[];
|
|
216
|
-
uiMessages: Message[];
|
|
217
|
-
}>;
|
|
218
|
-
/**
|
|
219
|
-
* Helper method to create a new thread
|
|
220
|
-
* @param title - Optional title for the thread
|
|
221
|
-
* @param metadata - Optional metadata for the thread
|
|
222
|
-
* @returns Promise resolving to the created thread
|
|
223
|
-
*/
|
|
224
|
-
createThread({ threadId, resourceId, title, metadata, memoryConfig, }: {
|
|
225
|
-
resourceId: string;
|
|
226
|
-
threadId?: string;
|
|
227
|
-
title?: string;
|
|
228
|
-
metadata?: Record<string, unknown>;
|
|
229
|
-
memoryConfig?: MemoryConfig;
|
|
230
|
-
}): Promise<StorageThreadType>;
|
|
231
|
-
/**
|
|
232
|
-
* Helper method to delete a thread
|
|
233
|
-
* @param threadId - the id of the thread to delete
|
|
234
|
-
*/
|
|
235
|
-
abstract deleteThread(threadId: string): Promise<void>;
|
|
236
|
-
/**
|
|
237
|
-
* Helper method to add a single message to a thread
|
|
238
|
-
* @param threadId - The thread to add the message to
|
|
239
|
-
* @param content - The message content
|
|
240
|
-
* @param role - The role of the message sender
|
|
241
|
-
* @param type - The type of the message
|
|
242
|
-
* @param toolNames - Optional array of tool names that were called
|
|
243
|
-
* @param toolCallArgs - Optional array of tool call arguments
|
|
244
|
-
* @param toolCallIds - Optional array of tool call ids
|
|
245
|
-
* @returns Promise resolving to the saved message
|
|
246
|
-
*/
|
|
247
|
-
addMessage({ threadId, resourceId, config, content, role, type, toolNames, toolCallArgs, toolCallIds, }: {
|
|
248
|
-
threadId: string;
|
|
249
|
-
resourceId: string;
|
|
250
|
-
config?: MemoryConfig;
|
|
251
|
-
content: UserContent | AssistantContent;
|
|
252
|
-
role: 'user' | 'assistant';
|
|
253
|
-
type: 'text' | 'tool-call' | 'tool-result';
|
|
254
|
-
toolNames?: string[];
|
|
255
|
-
toolCallArgs?: Record<string, unknown>[];
|
|
256
|
-
toolCallIds?: string[];
|
|
257
|
-
}): Promise<MessageType>;
|
|
258
|
-
/**
|
|
259
|
-
* Generates a unique identifier
|
|
260
|
-
* @returns A unique string ID
|
|
261
|
-
*/
|
|
262
|
-
generateId(): string;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
declare class MastraLLMBase extends MastraBase {
|
|
266
|
-
#private;
|
|
267
|
-
constructor({ name, model }: {
|
|
268
|
-
name: string;
|
|
269
|
-
model: LanguageModel$1;
|
|
270
|
-
});
|
|
271
|
-
getProvider(): string;
|
|
272
|
-
getModelId(): string;
|
|
273
|
-
getModel(): ai.LanguageModelV1;
|
|
274
|
-
convertToMessages(messages: string | string[] | CoreMessage$1[]): CoreMessage$1[];
|
|
275
|
-
__registerPrimitives(p: MastraPrimitives): void;
|
|
276
|
-
__registerMastra(p: Mastra): void;
|
|
277
|
-
__text<Z extends ZodSchema | JSONSchema7 | undefined>(input: LLMTextOptions<Z>): Promise<GenerateTextResult<any, any>>;
|
|
278
|
-
__textObject<T extends ZodSchema | JSONSchema7 | undefined>(input: LLMTextObjectOptions<T>): Promise<GenerateObjectResult<T>>;
|
|
279
|
-
generate<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], options: LLMStreamOptions<Z>): Promise<GenerateReturn<Z>>;
|
|
280
|
-
__stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(input: LLMInnerStreamOptions<Z>): Promise<StreamTextResult<any, any>>;
|
|
281
|
-
__streamObject<T extends ZodSchema | JSONSchema7 | undefined>(input: LLMStreamObjectOptions<T>): Promise<StreamObjectResult<DeepPartial<T>, T, never>>;
|
|
282
|
-
stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], options: LLMStreamOptions<Z>): Promise<StreamReturn<Z>>;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
declare function createMockModel({ objectGenerationMode, mockText, spyGenerate, spyStream, }: {
|
|
286
|
-
objectGenerationMode?: 'json';
|
|
287
|
-
mockText: string | Record<string, any>;
|
|
288
|
-
spyGenerate?: (props: any) => void;
|
|
289
|
-
spyStream?: (props: any) => void;
|
|
290
|
-
}): MockLanguageModelV1;
|
|
291
|
-
|
|
292
|
-
type LanguageModel = MastraLanguageModel;
|
|
293
|
-
type CoreMessage = CoreMessage$1;
|
|
294
|
-
type CoreSystemMessage = CoreSystemMessage$1;
|
|
295
|
-
type CoreAssistantMessage = CoreAssistantMessage$1;
|
|
296
|
-
type CoreUserMessage = CoreUserMessage$1;
|
|
297
|
-
type CoreToolMessage = CoreToolMessage$1;
|
|
298
|
-
type EmbedResult<T> = EmbedResult$1<T>;
|
|
299
|
-
type EmbedManyResult<T> = EmbedManyResult$1<T>;
|
|
300
|
-
type BaseStructuredOutputType = 'string' | 'number' | 'boolean' | 'date';
|
|
301
|
-
type StructuredOutputType = 'array' | 'string' | 'number' | 'object' | 'boolean' | 'date';
|
|
302
|
-
type StructuredOutputArrayItem = {
|
|
303
|
-
type: BaseStructuredOutputType;
|
|
304
|
-
} | {
|
|
305
|
-
type: 'object';
|
|
306
|
-
items: StructuredOutput;
|
|
307
|
-
};
|
|
308
|
-
type StructuredOutput = {
|
|
309
|
-
[key: string]: {
|
|
310
|
-
type: BaseStructuredOutputType;
|
|
311
|
-
} | {
|
|
312
|
-
type: 'object';
|
|
313
|
-
items: StructuredOutput;
|
|
314
|
-
} | {
|
|
315
|
-
type: 'array';
|
|
316
|
-
items: StructuredOutputArrayItem;
|
|
317
|
-
};
|
|
318
|
-
};
|
|
319
|
-
type GenerateReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? GenerateTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown> : GenerateObjectResult<Z extends ZodSchema ? z.infer<Z> : unknown>;
|
|
320
|
-
type StreamReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? StreamTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown> : StreamObjectResult<any, Z extends ZodSchema ? z.infer<Z> : unknown, any>;
|
|
321
|
-
type OutputType = StructuredOutput | ZodSchema | JSONSchema7 | undefined;
|
|
322
|
-
type GenerateTextOptions = Parameters<typeof generateText>[0];
|
|
323
|
-
type StreamTextOptions = Parameters<typeof streamText>[0];
|
|
324
|
-
type GenerateObjectOptions = Parameters<typeof generateObject>[0];
|
|
325
|
-
type StreamObjectOptions = Parameters<typeof streamObject>[0];
|
|
326
|
-
type MastraCustomLLMOptionsKeys = 'messages' | 'tools' | 'model' | 'onStepFinish' | 'experimental_output' | 'experimental_telemetry' | 'messages' | 'onFinish' | 'output';
|
|
327
|
-
type DefaultLLMTextOptions = Omit<GenerateTextOptions, MastraCustomLLMOptionsKeys>;
|
|
328
|
-
type DefaultLLMTextObjectOptions = Omit<GenerateObjectOptions, MastraCustomLLMOptionsKeys>;
|
|
329
|
-
type DefaultLLMStreamOptions = Omit<StreamTextOptions, MastraCustomLLMOptionsKeys>;
|
|
330
|
-
type DefaultLLMStreamObjectOptions = Omit<StreamObjectOptions, MastraCustomLLMOptionsKeys>;
|
|
331
|
-
type MastraCustomLLMOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
|
|
332
|
-
tools?: Record<string, CoreTool>;
|
|
333
|
-
onStepFinish?: (step: unknown) => Promise<void> | void;
|
|
334
|
-
experimental_output?: Z;
|
|
335
|
-
telemetry?: TelemetrySettings;
|
|
336
|
-
threadId?: string;
|
|
337
|
-
resourceId?: string;
|
|
338
|
-
runtimeContext: RuntimeContext;
|
|
339
|
-
} & Run$1;
|
|
340
|
-
type LLMTextOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
|
|
341
|
-
messages: CoreMessage[];
|
|
342
|
-
} & MastraCustomLLMOptions<Z> & DefaultLLMTextOptions;
|
|
343
|
-
type LLMTextObjectOptions<T extends ZodSchema | JSONSchema7 | undefined = undefined> = LLMTextOptions<T> & DefaultLLMTextObjectOptions & {
|
|
344
|
-
structuredOutput: JSONSchema7 | z.ZodType<T> | StructuredOutput;
|
|
345
|
-
};
|
|
346
|
-
type LLMStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
|
|
347
|
-
output?: OutputType | Z;
|
|
348
|
-
onFinish?: (result: string) => Promise<void> | void;
|
|
349
|
-
} & MastraCustomLLMOptions<Z> & DefaultLLMStreamOptions;
|
|
350
|
-
type LLMInnerStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
|
|
351
|
-
messages: CoreMessage[];
|
|
352
|
-
onFinish?: (result: string) => Promise<void> | void;
|
|
353
|
-
} & MastraCustomLLMOptions<Z> & DefaultLLMStreamOptions;
|
|
354
|
-
type LLMStreamObjectOptions<T extends ZodSchema | JSONSchema7 | undefined = undefined> = {
|
|
355
|
-
structuredOutput: JSONSchema7 | z.ZodType<T> | StructuredOutput;
|
|
356
|
-
} & LLMInnerStreamOptions<T> & DefaultLLMStreamObjectOptions;
|
|
357
|
-
|
|
358
|
-
type VoiceEventType = 'speaking' | 'writing' | 'error' | string;
|
|
359
|
-
interface VoiceEventMap {
|
|
360
|
-
speaker: NodeJS.ReadableStream;
|
|
361
|
-
speaking: {
|
|
362
|
-
audio?: string;
|
|
363
|
-
};
|
|
364
|
-
writing: {
|
|
365
|
-
text: string;
|
|
366
|
-
role: 'assistant' | 'user';
|
|
367
|
-
};
|
|
368
|
-
error: {
|
|
369
|
-
message: string;
|
|
370
|
-
code?: string;
|
|
371
|
-
details?: unknown;
|
|
372
|
-
};
|
|
373
|
-
[key: string]: unknown;
|
|
374
|
-
}
|
|
375
|
-
interface BuiltInModelConfig {
|
|
376
|
-
name: string;
|
|
377
|
-
apiKey?: string;
|
|
378
|
-
}
|
|
379
|
-
interface VoiceConfig<T = unknown> {
|
|
380
|
-
listeningModel?: BuiltInModelConfig;
|
|
381
|
-
speechModel?: BuiltInModelConfig;
|
|
382
|
-
speaker?: string;
|
|
383
|
-
name?: string;
|
|
384
|
-
realtimeConfig?: {
|
|
385
|
-
model?: string;
|
|
386
|
-
apiKey?: string;
|
|
387
|
-
options?: T;
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
declare abstract class MastraVoice<TOptions = unknown, TSpeakOptions = unknown, TListenOptions = unknown, TTools extends ToolsInput = ToolsInput, TEventArgs extends VoiceEventMap = VoiceEventMap, TSpeakerMetadata = unknown> extends MastraBase {
|
|
391
|
-
protected listeningModel?: BuiltInModelConfig;
|
|
392
|
-
protected speechModel?: BuiltInModelConfig;
|
|
393
|
-
protected speaker?: string;
|
|
394
|
-
protected realtimeConfig?: {
|
|
395
|
-
model?: string;
|
|
396
|
-
apiKey?: string;
|
|
397
|
-
options?: TOptions;
|
|
398
|
-
};
|
|
399
|
-
constructor({ listeningModel, speechModel, speaker, realtimeConfig, name }?: VoiceConfig<TOptions>);
|
|
400
|
-
traced<T extends Function>(method: T, methodName: string): T;
|
|
401
|
-
/**
|
|
402
|
-
* Convert text to speech
|
|
403
|
-
* @param input Text or text stream to convert to speech
|
|
404
|
-
* @param options Speech options including speaker and provider-specific options
|
|
405
|
-
* @returns Audio stream
|
|
406
|
-
*/
|
|
407
|
-
/**
|
|
408
|
-
* Convert text to speech
|
|
409
|
-
* @param input Text or text stream to convert to speech
|
|
410
|
-
* @param options Speech options including speaker and provider-specific options
|
|
411
|
-
* @returns Audio stream or void if in chat mode
|
|
412
|
-
*/
|
|
413
|
-
abstract speak(input: string | NodeJS.ReadableStream, options?: {
|
|
414
|
-
speaker?: string;
|
|
415
|
-
} & TSpeakOptions): Promise<NodeJS.ReadableStream | void>;
|
|
416
|
-
/**
|
|
417
|
-
* Convert speech to text
|
|
418
|
-
* @param audioStream Audio stream to transcribe
|
|
419
|
-
* @param options Provider-specific transcription options
|
|
420
|
-
* @returns Text or text stream
|
|
421
|
-
*/
|
|
422
|
-
/**
|
|
423
|
-
* Convert speech to text
|
|
424
|
-
* @param audioStream Audio stream to transcribe
|
|
425
|
-
* @param options Provider-specific transcription options
|
|
426
|
-
* @returns Text, text stream, or void if in chat mode
|
|
427
|
-
*/
|
|
428
|
-
abstract listen(audioStream: NodeJS.ReadableStream | unknown, // Allow other audio input types for OpenAI realtime API
|
|
429
|
-
options?: TListenOptions): Promise<string | NodeJS.ReadableStream | void>;
|
|
430
|
-
updateConfig(_options: Record<string, unknown>): void;
|
|
431
|
-
/**
|
|
432
|
-
* Initializes a WebSocket or WebRTC connection for real-time communication
|
|
433
|
-
* @returns Promise that resolves when the connection is established
|
|
434
|
-
*/
|
|
435
|
-
connect(_options?: Record<string, unknown>): Promise<void>;
|
|
436
|
-
/**
|
|
437
|
-
* Relay audio data to the voice provider for real-time processing
|
|
438
|
-
* @param audioData Audio data to relay
|
|
439
|
-
*/
|
|
440
|
-
send(_audioData: NodeJS.ReadableStream | Int16Array): Promise<void>;
|
|
441
|
-
/**
|
|
442
|
-
* Trigger voice providers to respond
|
|
443
|
-
*/
|
|
444
|
-
answer(_options?: Record<string, unknown>): Promise<void>;
|
|
445
|
-
/**
|
|
446
|
-
* Equip the voice provider with instructions
|
|
447
|
-
* @param instructions Instructions to add
|
|
448
|
-
*/
|
|
449
|
-
addInstructions(_instructions?: string): void;
|
|
450
|
-
/**
|
|
451
|
-
* Equip the voice provider with tools
|
|
452
|
-
* @param tools Array of tools to add
|
|
453
|
-
*/
|
|
454
|
-
addTools(_tools: TTools): void;
|
|
455
|
-
/**
|
|
456
|
-
* Disconnect from the WebSocket or WebRTC connection
|
|
457
|
-
*/
|
|
458
|
-
close(): void;
|
|
459
|
-
/**
|
|
460
|
-
* Register an event listener
|
|
461
|
-
* @param event Event name (e.g., 'speaking', 'writing', 'error')
|
|
462
|
-
* @param callback Callback function that receives event data
|
|
463
|
-
*/
|
|
464
|
-
on<E extends VoiceEventType>(_event: E, _callback: (data: E extends keyof TEventArgs ? TEventArgs[E] : unknown) => void): void;
|
|
465
|
-
/**
|
|
466
|
-
* Remove an event listener
|
|
467
|
-
* @param event Event name (e.g., 'speaking', 'writing', 'error')
|
|
468
|
-
* @param callback Callback function to remove
|
|
469
|
-
*/
|
|
470
|
-
off<E extends VoiceEventType>(_event: E, _callback: (data: E extends keyof TEventArgs ? TEventArgs[E] : unknown) => void): void;
|
|
471
|
-
/**
|
|
472
|
-
* Get available speakers/voices
|
|
473
|
-
* @returns Array of available voice IDs and their metadata
|
|
474
|
-
*/
|
|
475
|
-
getSpeakers(): Promise<Array<{
|
|
476
|
-
voiceId: string;
|
|
477
|
-
} & TSpeakerMetadata>>;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
declare class CompositeVoice extends MastraVoice<unknown, unknown, unknown, ToolsInput, VoiceEventMap> {
|
|
481
|
-
protected speakProvider?: MastraVoice;
|
|
482
|
-
protected listenProvider?: MastraVoice;
|
|
483
|
-
protected realtimeProvider?: MastraVoice;
|
|
484
|
-
constructor({ input, output, realtime, speakProvider, listenProvider, realtimeProvider, }: {
|
|
485
|
-
/** @deprecated use output instead */
|
|
486
|
-
speakProvider?: MastraVoice;
|
|
487
|
-
/** @deprecated use input instead */
|
|
488
|
-
listenProvider?: MastraVoice;
|
|
489
|
-
/** @deprecated use realtime instead */
|
|
490
|
-
realtimeProvider?: MastraVoice;
|
|
491
|
-
input?: MastraVoice;
|
|
492
|
-
output?: MastraVoice;
|
|
493
|
-
realtime?: MastraVoice;
|
|
494
|
-
});
|
|
495
|
-
/**
|
|
496
|
-
* Convert text to speech using the configured provider
|
|
497
|
-
* @param input Text or text stream to convert to speech
|
|
498
|
-
* @param options Speech options including speaker and provider-specific options
|
|
499
|
-
* @returns Audio stream or void if in realtime mode
|
|
500
|
-
*/
|
|
501
|
-
speak(input: string | NodeJS.ReadableStream, options?: {
|
|
502
|
-
speaker?: string;
|
|
503
|
-
} & any): Promise<NodeJS.ReadableStream | void>;
|
|
504
|
-
listen(audioStream: NodeJS.ReadableStream, options?: any): Promise<string | void | NodeJS.ReadableStream>;
|
|
505
|
-
getSpeakers(): Promise<{
|
|
506
|
-
voiceId: string;
|
|
507
|
-
}[]>;
|
|
508
|
-
updateConfig(options: Record<string, unknown>): void;
|
|
509
|
-
/**
|
|
510
|
-
* Initializes a WebSocket or WebRTC connection for real-time communication
|
|
511
|
-
* @returns Promise that resolves when the connection is established
|
|
512
|
-
*/
|
|
513
|
-
connect(options?: Record<string, unknown>): Promise<void>;
|
|
514
|
-
/**
|
|
515
|
-
* Relay audio data to the voice provider for real-time processing
|
|
516
|
-
* @param audioData Audio data to send
|
|
517
|
-
*/
|
|
518
|
-
send(audioData: NodeJS.ReadableStream | Int16Array): Promise<void>;
|
|
519
|
-
/**
|
|
520
|
-
* Trigger voice providers to respond
|
|
521
|
-
*/
|
|
522
|
-
answer(options?: Record<string, unknown>): Promise<void>;
|
|
523
|
-
/**
|
|
524
|
-
* Equip the voice provider with instructions
|
|
525
|
-
* @param instructions Instructions to add
|
|
526
|
-
*/
|
|
527
|
-
addInstructions(instructions: string): void;
|
|
528
|
-
/**
|
|
529
|
-
* Equip the voice provider with tools
|
|
530
|
-
* @param tools Array of tools to add
|
|
531
|
-
*/
|
|
532
|
-
addTools(tools: ToolsInput): void;
|
|
533
|
-
/**
|
|
534
|
-
* Disconnect from the WebSocket or WebRTC connection
|
|
535
|
-
*/
|
|
536
|
-
close(): void;
|
|
537
|
-
/**
|
|
538
|
-
* Register an event listener
|
|
539
|
-
* @param event Event name (e.g., 'speaking', 'writing', 'error')
|
|
540
|
-
* @param callback Callback function that receives event data
|
|
541
|
-
*/
|
|
542
|
-
on<E extends VoiceEventType>(event: E, callback: (data: E extends keyof VoiceEventMap ? VoiceEventMap[E] : unknown) => void): void;
|
|
543
|
-
/**
|
|
544
|
-
* Remove an event listener
|
|
545
|
-
* @param event Event name (e.g., 'speaking', 'writing', 'error')
|
|
546
|
-
* @param callback Callback function to remove
|
|
547
|
-
*/
|
|
548
|
-
off<E extends VoiceEventType>(event: E, callback: (data: E extends keyof VoiceEventMap ? VoiceEventMap[E] : unknown) => void): void;
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
declare class DefaultVoice extends MastraVoice {
|
|
552
|
-
constructor();
|
|
553
|
-
speak(_input: string | NodeJS.ReadableStream): Promise<NodeJS.ReadableStream>;
|
|
554
|
-
listen(_input: string | NodeJS.ReadableStream): Promise<string>;
|
|
555
|
-
getSpeakers(): Promise<{
|
|
556
|
-
voiceId: string;
|
|
557
|
-
}[]>;
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
interface WorkflowOptions<TWorkflowName extends string = string, TSteps extends LegacyStep<string, any, any, any>[] = LegacyStep<string, any, any, any>[], TTriggerSchema extends z.ZodObject<any> = any, TResultSchema extends z.ZodObject<any> = any> {
|
|
561
|
-
steps?: TSteps;
|
|
562
|
-
name: TWorkflowName;
|
|
563
|
-
triggerSchema?: TTriggerSchema;
|
|
564
|
-
result?: {
|
|
565
|
-
schema: TResultSchema;
|
|
566
|
-
mapping?: {
|
|
567
|
-
[K in keyof z.infer<TResultSchema>]?: any;
|
|
568
|
-
};
|
|
569
|
-
};
|
|
570
|
-
events?: Record<string, {
|
|
571
|
-
schema: z.ZodObject<any>;
|
|
572
|
-
}>;
|
|
573
|
-
retryConfig?: RetryConfig;
|
|
574
|
-
mastra?: Mastra;
|
|
575
|
-
}
|
|
576
|
-
interface StepExecutionContext<TSchemaIn extends z.ZodSchema | undefined = undefined, TContext extends WorkflowContext = WorkflowContext> extends IExecutionContext<TSchemaIn> {
|
|
577
|
-
context: TSchemaIn extends z.ZodSchema ? {
|
|
578
|
-
inputData: z.infer<TSchemaIn>;
|
|
579
|
-
} & TContext : TContext;
|
|
580
|
-
suspend: (payload?: unknown, softSuspend?: any) => Promise<void>;
|
|
581
|
-
runId: string;
|
|
582
|
-
emit: (event: string, data: any) => void;
|
|
583
|
-
mastra?: MastraUnion;
|
|
584
|
-
runtimeContext: RuntimeContext;
|
|
585
|
-
}
|
|
586
|
-
interface StepAction<TId extends string, TSchemaIn extends z.ZodSchema | undefined, TSchemaOut extends z.ZodSchema | undefined, TContext extends StepExecutionContext<TSchemaIn>> extends IAction<TId, TSchemaIn, TSchemaOut, TContext> {
|
|
587
|
-
mastra?: Mastra;
|
|
588
|
-
payload?: TSchemaIn extends z.ZodSchema ? Partial<z.infer<TSchemaIn>> : unknown;
|
|
589
|
-
execute: (context: TContext) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
|
|
590
|
-
retryConfig?: RetryConfig;
|
|
591
|
-
workflow?: LegacyWorkflow;
|
|
592
|
-
workflowId?: string;
|
|
593
|
-
}
|
|
594
|
-
interface SimpleConditionalType {
|
|
595
|
-
[key: `${string}.${string}`]: string | Query<any>;
|
|
596
|
-
}
|
|
597
|
-
type StepVariableType<TId extends string, TSchemaIn extends z.ZodSchema | undefined, TSchemaOut extends z.ZodSchema | undefined, TContext extends StepExecutionContext<TSchemaIn>> = StepAction<TId, TSchemaIn, TSchemaOut, TContext> | 'trigger' | {
|
|
598
|
-
id: string;
|
|
599
|
-
};
|
|
600
|
-
type StepNode = {
|
|
601
|
-
id: string;
|
|
602
|
-
step: StepAction<any, any, any, any>;
|
|
603
|
-
config: StepDef<any, any, any, any>[any];
|
|
604
|
-
};
|
|
605
|
-
type StepGraph = {
|
|
606
|
-
initial: StepNode[];
|
|
607
|
-
[key: string]: StepNode[];
|
|
608
|
-
};
|
|
609
|
-
type RetryConfig = {
|
|
610
|
-
attempts?: number;
|
|
611
|
-
delay?: number;
|
|
612
|
-
};
|
|
613
|
-
type VariableReference$1<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>> = TStep extends StepAction<any, any, any, any> ? {
|
|
614
|
-
step: TStep;
|
|
615
|
-
path: PathsToStringProps$1<ExtractSchemaType$1<ExtractSchemaFromStep$1<TStep, 'outputSchema'>>> | '' | '.';
|
|
616
|
-
} : TStep extends 'trigger' ? {
|
|
617
|
-
step: 'trigger';
|
|
618
|
-
path: PathsToStringProps$1<ExtractSchemaType$1<TTriggerSchema>> | '.' | '';
|
|
619
|
-
} : {
|
|
620
|
-
step: {
|
|
621
|
-
id: string;
|
|
622
|
-
};
|
|
623
|
-
path: string;
|
|
624
|
-
};
|
|
625
|
-
interface BaseCondition<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>> {
|
|
626
|
-
ref: TStep extends StepAction<any, any, any, any> ? {
|
|
627
|
-
step: TStep;
|
|
628
|
-
path: PathsToStringProps$1<ExtractSchemaType$1<ExtractSchemaFromStep$1<TStep, 'outputSchema'>>> | '' | '.' | 'status';
|
|
629
|
-
} : TStep extends 'trigger' ? {
|
|
630
|
-
step: 'trigger';
|
|
631
|
-
path: PathsToStringProps$1<ExtractSchemaType$1<TTriggerSchema>> | '.' | '';
|
|
632
|
-
} : {
|
|
633
|
-
step: {
|
|
634
|
-
id: string;
|
|
635
|
-
};
|
|
636
|
-
path: string;
|
|
637
|
-
};
|
|
638
|
-
query: Query<any>;
|
|
639
|
-
}
|
|
640
|
-
type ActionContext<TSchemaIn extends z.ZodType<any>> = StepExecutionContext<z.infer<TSchemaIn>, WorkflowContext>;
|
|
641
|
-
declare enum WhenConditionReturnValue {
|
|
642
|
-
CONTINUE = "continue",
|
|
643
|
-
CONTINUE_FAILED = "continue_failed",
|
|
644
|
-
ABORT = "abort",
|
|
645
|
-
LIMBO = "limbo"
|
|
646
|
-
}
|
|
647
|
-
type StepDef<TStepId extends TSteps[number]['id'], TSteps extends StepAction<any, any, any, any>[], TSchemaIn extends z.ZodType<any>, TSchemaOut extends z.ZodType<any>> = Record<TStepId, {
|
|
648
|
-
id?: string;
|
|
649
|
-
when?: Condition<any, any> | ((args: {
|
|
650
|
-
context: WorkflowContext;
|
|
651
|
-
mastra?: Mastra;
|
|
652
|
-
}) => Promise<boolean | WhenConditionReturnValue>);
|
|
653
|
-
serializedWhen?: Condition<any, any> | string;
|
|
654
|
-
loopLabel?: string;
|
|
655
|
-
loopType?: 'while' | 'until';
|
|
656
|
-
data: TSchemaIn;
|
|
657
|
-
handler: (args: ActionContext<TSchemaIn>) => Promise<z.infer<TSchemaOut>>;
|
|
658
|
-
}>;
|
|
659
|
-
type StepCondition<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>> = BaseCondition<TStep, TTriggerSchema> | SimpleConditionalType | {
|
|
660
|
-
and: StepCondition<TStep, TTriggerSchema>[];
|
|
661
|
-
} | {
|
|
662
|
-
or: StepCondition<TStep, TTriggerSchema>[];
|
|
663
|
-
} | {
|
|
664
|
-
not: StepCondition<TStep, TTriggerSchema>;
|
|
665
|
-
};
|
|
666
|
-
type Condition<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>> = BaseCondition<TStep, TTriggerSchema> | SimpleConditionalType | {
|
|
667
|
-
and: Condition<TStep, TTriggerSchema>[];
|
|
668
|
-
} | {
|
|
669
|
-
or: Condition<TStep, TTriggerSchema>[];
|
|
670
|
-
} | {
|
|
671
|
-
not: Condition<TStep, TTriggerSchema>;
|
|
672
|
-
};
|
|
673
|
-
interface StepConfig<TStep extends StepAction<any, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>, TSteps extends LegacyStep<string, any, any, any>[] = LegacyStep<string, any, any, any>[]> {
|
|
674
|
-
when?: Condition<CondStep, TTriggerSchema> | ((args: {
|
|
675
|
-
context: WorkflowContext<TTriggerSchema, TSteps>;
|
|
676
|
-
mastra?: Mastra;
|
|
677
|
-
}) => Promise<boolean | WhenConditionReturnValue>);
|
|
678
|
-
variables?: StepInputType<TStep, 'inputSchema'> extends never ? Record<string, VariableReference$1<VarStep, TTriggerSchema>> : {
|
|
679
|
-
[K in keyof StepInputType<TStep, 'inputSchema'>]?: VariableReference$1<VarStep, TTriggerSchema>;
|
|
680
|
-
};
|
|
681
|
-
'#internal'?: {
|
|
682
|
-
when?: Condition<CondStep, TTriggerSchema> | ((args: {
|
|
683
|
-
context: WorkflowContext<TTriggerSchema, TSteps>;
|
|
684
|
-
mastra?: Mastra;
|
|
685
|
-
}) => Promise<boolean | WhenConditionReturnValue>);
|
|
686
|
-
loopLabel?: string;
|
|
687
|
-
loopType?: 'while' | 'until' | undefined;
|
|
688
|
-
};
|
|
689
|
-
id?: string;
|
|
690
|
-
}
|
|
691
|
-
type StepSuccess$1<T> = {
|
|
692
|
-
status: 'success';
|
|
693
|
-
output: T;
|
|
694
|
-
};
|
|
695
|
-
type StepSuspended$1<T> = {
|
|
696
|
-
status: 'suspended';
|
|
697
|
-
suspendPayload?: any;
|
|
698
|
-
output?: T;
|
|
699
|
-
};
|
|
700
|
-
type StepWaiting = {
|
|
701
|
-
status: 'waiting';
|
|
702
|
-
};
|
|
703
|
-
type StepFailure$1 = {
|
|
704
|
-
status: 'failed';
|
|
705
|
-
error: string;
|
|
706
|
-
};
|
|
707
|
-
type StepSkipped = {
|
|
708
|
-
status: 'skipped';
|
|
709
|
-
};
|
|
710
|
-
type StepResult$1<T> = StepSuccess$1<T> | StepFailure$1 | StepSuspended$1<T> | StepWaiting | StepSkipped;
|
|
711
|
-
type StepsRecord$1<T extends readonly LegacyStep<any, any, z.ZodType<any> | undefined>[]> = {
|
|
712
|
-
[K in T[number]['id']]: Extract<T[number], {
|
|
713
|
-
id: K;
|
|
714
|
-
}>;
|
|
715
|
-
};
|
|
716
|
-
interface LegacyWorkflowRunResult<T extends z.ZodObject<any>, TSteps extends LegacyStep<string, any, z.ZodType<any> | undefined>[], TResult extends z.ZodObject<any>> {
|
|
717
|
-
triggerData?: z.infer<T>;
|
|
718
|
-
result?: z.infer<TResult>;
|
|
719
|
-
results: {
|
|
720
|
-
[K in keyof StepsRecord$1<TSteps>]: StepsRecord$1<TSteps>[K]['outputSchema'] extends undefined ? StepResult$1<unknown> : StepResult$1<z.infer<NonNullable<StepsRecord$1<TSteps>[K]['outputSchema']>>>;
|
|
721
|
-
};
|
|
722
|
-
runId: string;
|
|
723
|
-
timestamp: number;
|
|
724
|
-
activePaths: Map<keyof StepsRecord$1<TSteps>, {
|
|
725
|
-
status: string;
|
|
726
|
-
suspendPayload?: any;
|
|
727
|
-
stepPath: string[];
|
|
244
|
+
};
|
|
245
|
+
interface LegacyWorkflowRunResult<T extends z.ZodObject<any>, TSteps extends LegacyStep<string, any, z.ZodType<any> | undefined>[], TResult extends z.ZodObject<any>> {
|
|
246
|
+
triggerData?: z.infer<T>;
|
|
247
|
+
result?: z.infer<TResult>;
|
|
248
|
+
results: {
|
|
249
|
+
[K in keyof StepsRecord$1<TSteps>]: StepsRecord$1<TSteps>[K]['outputSchema'] extends undefined ? StepResult$1<unknown> : StepResult$1<z.infer<NonNullable<StepsRecord$1<TSteps>[K]['outputSchema']>>>;
|
|
250
|
+
};
|
|
251
|
+
runId: string;
|
|
252
|
+
timestamp: number;
|
|
253
|
+
activePaths: Map<keyof StepsRecord$1<TSteps>, {
|
|
254
|
+
status: string;
|
|
255
|
+
suspendPayload?: any;
|
|
256
|
+
stepPath: string[];
|
|
728
257
|
}>;
|
|
729
258
|
}
|
|
730
259
|
interface WorkflowContext<TTrigger extends z.ZodObject<any> = any, TSteps extends LegacyStep<string, any, any, any>[] = LegacyStep<string, any, any, any>[], TInputData extends Record<string, any> = Record<string, any>> {
|
|
@@ -1341,658 +870,1343 @@ interface WorkflowResultReturn<TResult extends z.ZodObject<any>, T extends z.Zod
|
|
|
1341
870
|
}) => Promise<Omit<LegacyWorkflowRunResult<T, TSteps, TResult>, 'runId'> | undefined>;
|
|
1342
871
|
resumeWithEvent: (eventName: string, data: any, runtimeContext?: RuntimeContext) => Promise<Omit<LegacyWorkflowRunResult<T, TSteps, TResult>, 'runId'> | undefined>;
|
|
1343
872
|
}
|
|
1344
|
-
declare class WorkflowInstance<TSteps extends LegacyStep<any, any, any, any>[] = LegacyStep<any, any, any, any>[], TTriggerSchema extends z.ZodObject<any> = any, TResult extends z.ZodObject<any> = any> implements WorkflowResultReturn<TResult, TTriggerSchema, TSteps> {
|
|
873
|
+
declare class WorkflowInstance<TSteps extends LegacyStep<any, any, any, any>[] = LegacyStep<any, any, any, any>[], TTriggerSchema extends z.ZodObject<any> = any, TResult extends z.ZodObject<any> = any> implements WorkflowResultReturn<TResult, TTriggerSchema, TSteps> {
|
|
874
|
+
#private;
|
|
875
|
+
name: string;
|
|
876
|
+
logger: IMastraLogger;
|
|
877
|
+
events?: Record<string, {
|
|
878
|
+
schema: z.ZodObject<any>;
|
|
879
|
+
}>;
|
|
880
|
+
constructor({ name, logger, steps, runId, retryConfig, mastra, stepGraph, stepSubscriberGraph, onFinish, onStepTransition, resultMapping, events, }: {
|
|
881
|
+
name: string;
|
|
882
|
+
logger: IMastraLogger;
|
|
883
|
+
steps: Record<string, StepNode>;
|
|
884
|
+
mastra?: Mastra;
|
|
885
|
+
retryConfig?: RetryConfig;
|
|
886
|
+
runId?: string;
|
|
887
|
+
stepGraph: StepGraph;
|
|
888
|
+
stepSubscriberGraph: Record<string, StepGraph>;
|
|
889
|
+
onFinish?: () => void;
|
|
890
|
+
onStepTransition?: Set<(state: Pick<LegacyWorkflowRunResult<TTriggerSchema, TSteps, TResult>, 'results' | 'activePaths' | 'runId' | 'timestamp'>) => void | Promise<void>>;
|
|
891
|
+
resultMapping?: Record<string, {
|
|
892
|
+
step: StepAction<any, any, any, any>;
|
|
893
|
+
path: string;
|
|
894
|
+
}>;
|
|
895
|
+
events?: Record<string, {
|
|
896
|
+
schema: z.ZodObject<any>;
|
|
897
|
+
}>;
|
|
898
|
+
});
|
|
899
|
+
setState(state: any): void;
|
|
900
|
+
get runId(): string;
|
|
901
|
+
get executionSpan(): Span | undefined;
|
|
902
|
+
watch(onTransition: (state: Pick<LegacyWorkflowRunResult<TTriggerSchema, TSteps, TResult>, 'results' | 'activePaths' | 'runId' | 'timestamp'>) => void): () => void;
|
|
903
|
+
start({ triggerData, runtimeContext, }?: {
|
|
904
|
+
triggerData?: z.infer<TTriggerSchema>;
|
|
905
|
+
runtimeContext?: RuntimeContext;
|
|
906
|
+
}): Promise<{
|
|
907
|
+
runId: string;
|
|
908
|
+
result?: z.TypeOf<TResult> | undefined;
|
|
909
|
+
triggerData?: z.TypeOf<TTriggerSchema> | undefined;
|
|
910
|
+
results: { [K in keyof StepsRecord$1<TSteps>]: StepsRecord$1<TSteps>[K]["outputSchema"] extends undefined ? StepResult$1<unknown> : StepResult$1<z.TypeOf<NonNullable<StepsRecord$1<TSteps>[K]["outputSchema"]>>>; };
|
|
911
|
+
timestamp: number;
|
|
912
|
+
activePaths: Map<TSteps[number]["id"], {
|
|
913
|
+
status: string;
|
|
914
|
+
suspendPayload?: any;
|
|
915
|
+
stepPath: string[];
|
|
916
|
+
}>;
|
|
917
|
+
}>;
|
|
918
|
+
private isCompoundDependencyMet;
|
|
919
|
+
execute({ triggerData, snapshot, stepId, resumeData, runtimeContext, }?: {
|
|
920
|
+
stepId?: string;
|
|
921
|
+
triggerData?: z.infer<TTriggerSchema>;
|
|
922
|
+
snapshot?: Snapshot<any>;
|
|
923
|
+
resumeData?: any;
|
|
924
|
+
runtimeContext: RuntimeContext;
|
|
925
|
+
}): Promise<Omit<LegacyWorkflowRunResult<TTriggerSchema, TSteps, TResult>, 'runId'>>;
|
|
926
|
+
hasSubscribers(stepId: string): boolean;
|
|
927
|
+
runMachine(parentStepId: string, input: any, runtimeContext?: RuntimeContext): Promise<(Pick<LegacyWorkflowRunResult<TTriggerSchema, TSteps, TResult>, "runId" | "results" | "timestamp" | "activePaths"> | undefined)[]>;
|
|
928
|
+
suspend(stepId: string, machine: Machine<TSteps, TTriggerSchema>): Promise<void>;
|
|
929
|
+
/**
|
|
930
|
+
* Persists the workflow state to the database
|
|
931
|
+
*/
|
|
932
|
+
persistWorkflowSnapshot(): Promise<void>;
|
|
933
|
+
getState(): Promise<LegacyWorkflowRunState | null>;
|
|
934
|
+
resumeWithEvent(eventName: string, data: any, runtimeContext?: RuntimeContext): Promise<Omit<LegacyWorkflowRunResult<TTriggerSchema, TSteps, TResult>, "runId"> | undefined>;
|
|
935
|
+
resume({ stepId, context: resumeContext, runtimeContext, }: {
|
|
936
|
+
stepId: string;
|
|
937
|
+
context?: Record<string, any>;
|
|
938
|
+
runtimeContext?: RuntimeContext;
|
|
939
|
+
}): Promise<Omit<LegacyWorkflowRunResult<TTriggerSchema, TSteps, TResult>, "runId"> | undefined>;
|
|
940
|
+
_resume({ stepId, context: resumeContext, runtimeContext, }: {
|
|
941
|
+
stepId: string;
|
|
942
|
+
context?: Record<string, any>;
|
|
943
|
+
runtimeContext: RuntimeContext;
|
|
944
|
+
}): Promise<Omit<LegacyWorkflowRunResult<TTriggerSchema, TSteps, TResult>, "runId"> | undefined>;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
type WorkflowBuilder<T extends LegacyWorkflow<any, any>> = Pick<T, 'step' | 'then' | 'after' | 'while' | 'until' | 'if' | 'else' | 'afterEvent' | 'commit'>;
|
|
948
|
+
declare class LegacyWorkflow<TSteps extends LegacyStep<string, any, any>[] = LegacyStep<string, any, any>[], TStepId extends string = string, TTriggerSchema extends z.ZodObject<any> = any, TResultSchema extends z.ZodObject<any> = any> extends MastraBase {
|
|
1345
949
|
#private;
|
|
1346
|
-
name:
|
|
1347
|
-
|
|
950
|
+
name: TStepId;
|
|
951
|
+
triggerSchema?: TTriggerSchema;
|
|
952
|
+
resultSchema?: TResultSchema;
|
|
953
|
+
resultMapping?: Record<string, {
|
|
954
|
+
step: StepAction<string, any, any, any>;
|
|
955
|
+
path: string;
|
|
956
|
+
}>;
|
|
1348
957
|
events?: Record<string, {
|
|
1349
958
|
schema: z.ZodObject<any>;
|
|
1350
959
|
}>;
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
960
|
+
isNested: boolean;
|
|
961
|
+
/**
|
|
962
|
+
* Creates a new LegacyWorkflow instance
|
|
963
|
+
* @param name - Identifier for the workflow (not necessarily unique)
|
|
964
|
+
* @param logger - Optional logger instance
|
|
965
|
+
*/
|
|
966
|
+
constructor({ name, triggerSchema, result, retryConfig, mastra, events, }: WorkflowOptions<TStepId, TSteps, TTriggerSchema, TResultSchema>);
|
|
967
|
+
step<TWorkflow extends LegacyWorkflow<any, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>, Steps extends StepAction<any, any, any, any>[] = TSteps>(next: TWorkflow, config?: StepConfig<ReturnType<TWorkflow['toStep']>, CondStep, VarStep, TTriggerSchema, Steps>): WorkflowBuilder<this>;
|
|
968
|
+
step<TAgent extends Agent<any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>, Steps extends StepAction<any, any, any, any>[] = TSteps>(next: TAgent, config?: StepConfig<ReturnType<TAgent['toStep']>, CondStep, VarStep, TTriggerSchema, Steps>): WorkflowBuilder<this>;
|
|
969
|
+
step<TStep extends StepAction<any, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>, Steps extends StepAction<any, any, any, any>[] = TSteps>(step: TStep, config?: StepConfig<TStep, CondStep, VarStep, TTriggerSchema, Steps>): WorkflowBuilder<this>;
|
|
970
|
+
then<TStep extends StepAction<string, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>>(next: TStep | TStep[], config?: StepConfig<TStep, CondStep, VarStep, TTriggerSchema>): this;
|
|
971
|
+
then<TWorkflow extends LegacyWorkflow<any, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>>(next: TWorkflow | TWorkflow[], config?: StepConfig<StepAction<string, any, any, any>, CondStep, VarStep, TTriggerSchema>): this;
|
|
972
|
+
then<TAgent extends Agent<any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>>(next: TAgent | TAgent[], config?: StepConfig<StepAction<string, any, any, any>, CondStep, VarStep, TTriggerSchema>): this;
|
|
973
|
+
private loop;
|
|
974
|
+
while<FallbackStep extends StepAction<string, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>>(condition: StepConfig<FallbackStep, CondStep, VarStep, TTriggerSchema, TSteps>['when'], fallbackStep: FallbackStep, variables?: StepConfig<FallbackStep, CondStep, VarStep, TTriggerSchema, TSteps>['variables']): Pick<WorkflowBuilder<this>, "then" | "commit">;
|
|
975
|
+
until<FallbackStep extends StepAction<string, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>>(condition: StepConfig<FallbackStep, CondStep, VarStep, TTriggerSchema, TSteps>['when'], fallbackStep: FallbackStep, variables?: StepConfig<FallbackStep, CondStep, VarStep, TTriggerSchema, TSteps>['variables']): Pick<WorkflowBuilder<this>, "then" | "commit">;
|
|
976
|
+
if<TStep extends StepAction<string, any, any, any>>(condition: StepConfig<TStep, any, any, TTriggerSchema>['when'], ifStep?: TStep | LegacyWorkflow, elseStep?: TStep | LegacyWorkflow): this | WorkflowBuilder<this>;
|
|
977
|
+
else(): WorkflowBuilder<this>;
|
|
978
|
+
after<TStep extends StepAction<string, any, any, any>>(steps: string | TStep | TStep[] | (TStep | string)[]): Omit<WorkflowBuilder<this>, 'then' | 'after'>;
|
|
979
|
+
after<TWorkflow extends LegacyWorkflow<any, any, any, any>>(steps: TWorkflow | TWorkflow[]): Omit<WorkflowBuilder<this>, 'then' | 'after'>;
|
|
980
|
+
after<TAgent extends Agent<any, any, any>>(steps: TAgent | TAgent[]): Omit<WorkflowBuilder<this>, 'then' | 'after'>;
|
|
981
|
+
afterEvent(eventName: string): WorkflowBuilder<this>;
|
|
982
|
+
/**
|
|
983
|
+
* Executes the workflow with the given trigger data
|
|
984
|
+
* @param triggerData - Initial data to start the workflow with
|
|
985
|
+
* @returns Promise resolving to workflow results or rejecting with error
|
|
986
|
+
* @throws Error if trigger schema validation fails
|
|
987
|
+
*/
|
|
988
|
+
createRun({ runId, events, }?: {
|
|
1357
989
|
runId?: string;
|
|
1358
|
-
stepGraph: StepGraph;
|
|
1359
|
-
stepSubscriberGraph: Record<string, StepGraph>;
|
|
1360
|
-
onFinish?: () => void;
|
|
1361
|
-
onStepTransition?: Set<(state: Pick<LegacyWorkflowRunResult<TTriggerSchema, TSteps, TResult>, 'results' | 'activePaths' | 'runId' | 'timestamp'>) => void | Promise<void>>;
|
|
1362
|
-
resultMapping?: Record<string, {
|
|
1363
|
-
step: StepAction<any, any, any, any>;
|
|
1364
|
-
path: string;
|
|
1365
|
-
}>;
|
|
1366
990
|
events?: Record<string, {
|
|
1367
991
|
schema: z.ZodObject<any>;
|
|
1368
992
|
}>;
|
|
993
|
+
}): WorkflowResultReturn<TResultSchema, TTriggerSchema, TSteps>;
|
|
994
|
+
/**
|
|
995
|
+
* Gets a workflow run instance by ID
|
|
996
|
+
* @param runId - ID of the run to retrieve
|
|
997
|
+
* @returns The workflow run instance if found, undefined otherwise
|
|
998
|
+
*/
|
|
999
|
+
getRun(runId: string): Promise<WorkflowRun | WorkflowInstance<TSteps, TTriggerSchema, any> | null>;
|
|
1000
|
+
/**
|
|
1001
|
+
* Gets a workflow run instance by ID, from memory
|
|
1002
|
+
* @param runId - ID of the run to retrieve
|
|
1003
|
+
* @returns The workflow run instance if found, undefined otherwise
|
|
1004
|
+
*/
|
|
1005
|
+
getMemoryRun(runId: string): WorkflowInstance<TSteps, TTriggerSchema, any> | undefined;
|
|
1006
|
+
/**
|
|
1007
|
+
* Rebuilds the machine with the current steps configuration and validates the workflow
|
|
1008
|
+
*
|
|
1009
|
+
* This is the last step of a workflow builder method chain
|
|
1010
|
+
* @throws Error if validation fails
|
|
1011
|
+
*
|
|
1012
|
+
* @returns this instance for method chaining
|
|
1013
|
+
*/
|
|
1014
|
+
commit(): this;
|
|
1015
|
+
getWorkflowRuns(args?: {
|
|
1016
|
+
fromDate?: Date;
|
|
1017
|
+
toDate?: Date;
|
|
1018
|
+
limit?: number;
|
|
1019
|
+
offset?: number;
|
|
1020
|
+
resourceId?: string;
|
|
1021
|
+
}): Promise<LegacyWorkflowRuns>;
|
|
1022
|
+
getExecutionSpan(runId: string): Span | undefined;
|
|
1023
|
+
getState(runId: string): Promise<LegacyWorkflowRunState | null>;
|
|
1024
|
+
resume({ runId, stepId, context: resumeContext, runtimeContext, }: {
|
|
1025
|
+
runId: string;
|
|
1026
|
+
stepId: string;
|
|
1027
|
+
context?: Record<string, any>;
|
|
1028
|
+
runtimeContext: RuntimeContext;
|
|
1029
|
+
}): Promise<Omit<LegacyWorkflowRunResult<TTriggerSchema, TSteps, any>, "runId"> | undefined>;
|
|
1030
|
+
watch(onTransition: (state: Pick<LegacyWorkflowRunResult<TTriggerSchema, TSteps, TResultSchema>, 'results' | 'activePaths' | 'runId' | 'timestamp'>) => void): () => void;
|
|
1031
|
+
resumeWithEvent(runId: string, eventName: string, data: any): Promise<Omit<LegacyWorkflowRunResult<TTriggerSchema, TSteps, any>, "runId"> | undefined>;
|
|
1032
|
+
__registerMastra(mastra: Mastra): void;
|
|
1033
|
+
__registerPrimitives(p: MastraPrimitives): void;
|
|
1034
|
+
get stepGraph(): StepGraph;
|
|
1035
|
+
get stepSubscriberGraph(): Record<string, StepGraph>;
|
|
1036
|
+
get serializedStepGraph(): StepGraph;
|
|
1037
|
+
get serializedStepSubscriberGraph(): Record<string, StepGraph>;
|
|
1038
|
+
get steps(): Record<string, StepAction<string, any, any, any>>;
|
|
1039
|
+
setNested(isNested: boolean): void;
|
|
1040
|
+
toStep(): LegacyStep<TStepId, TTriggerSchema, z.ZodType<LegacyWorkflowRunResult<TTriggerSchema, TSteps, TResultSchema>>, any>;
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
type ExecuteFunction<TStepInput, TStepOutput, TResumeSchema, TSuspendSchema> = (params: {
|
|
1044
|
+
mastra: Mastra;
|
|
1045
|
+
runtimeContext: RuntimeContext;
|
|
1046
|
+
inputData: TStepInput;
|
|
1047
|
+
resumeData?: TResumeSchema;
|
|
1048
|
+
getInitData<T extends z.ZodType<any>>(): z.infer<T>;
|
|
1049
|
+
getInitData<T extends Workflow<any, any, any, any, any>>(): T extends undefined ? unknown : z.infer<NonNullable<T['inputSchema']>>;
|
|
1050
|
+
getStepResult<T extends Step<any, any, any>>(stepId: T): T['outputSchema'] extends undefined ? unknown : z.infer<NonNullable<T['outputSchema']>>;
|
|
1051
|
+
suspend(suspendPayload: TSuspendSchema): Promise<void>;
|
|
1052
|
+
resume?: {
|
|
1053
|
+
steps: string[];
|
|
1054
|
+
resumePayload: any;
|
|
1055
|
+
};
|
|
1056
|
+
[EMITTER_SYMBOL]: {
|
|
1057
|
+
emit: (event: string, data: any) => Promise<void>;
|
|
1058
|
+
};
|
|
1059
|
+
}) => Promise<TStepOutput>;
|
|
1060
|
+
interface Step<TStepId extends string = string, TSchemaIn extends z.ZodType<any> = z.ZodType<any>, TSchemaOut extends z.ZodType<any> = z.ZodType<any>, TResumeSchema extends z.ZodType<any> = z.ZodType<any>, TSuspendSchema extends z.ZodType<any> = z.ZodType<any>> {
|
|
1061
|
+
id: TStepId;
|
|
1062
|
+
description?: string;
|
|
1063
|
+
inputSchema: TSchemaIn;
|
|
1064
|
+
outputSchema: TSchemaOut;
|
|
1065
|
+
resumeSchema?: TResumeSchema;
|
|
1066
|
+
suspendSchema?: TSuspendSchema;
|
|
1067
|
+
execute: ExecuteFunction<z.infer<TSchemaIn>, z.infer<TSchemaOut>, z.infer<TResumeSchema>, z.infer<TSuspendSchema>>;
|
|
1068
|
+
retries?: number;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
type StepSuccess<P, R, S, T> = {
|
|
1072
|
+
status: 'success';
|
|
1073
|
+
output: T;
|
|
1074
|
+
payload: P;
|
|
1075
|
+
resumePayload?: R;
|
|
1076
|
+
suspendPayload?: S;
|
|
1077
|
+
startedAt: number;
|
|
1078
|
+
endedAt: number;
|
|
1079
|
+
suspendedAt?: number;
|
|
1080
|
+
resumedAt?: number;
|
|
1081
|
+
};
|
|
1082
|
+
type StepFailure<P, R, S> = {
|
|
1083
|
+
status: 'failed';
|
|
1084
|
+
error: string | Error;
|
|
1085
|
+
payload: P;
|
|
1086
|
+
resumePayload?: R;
|
|
1087
|
+
suspendPayload?: S;
|
|
1088
|
+
startedAt: number;
|
|
1089
|
+
endedAt: number;
|
|
1090
|
+
suspendedAt?: number;
|
|
1091
|
+
resumedAt?: number;
|
|
1092
|
+
};
|
|
1093
|
+
type StepSuspended<P, S> = {
|
|
1094
|
+
status: 'suspended';
|
|
1095
|
+
payload: P;
|
|
1096
|
+
suspendPayload?: S;
|
|
1097
|
+
startedAt: number;
|
|
1098
|
+
suspendedAt: number;
|
|
1099
|
+
};
|
|
1100
|
+
type StepRunning<P, R, S> = {
|
|
1101
|
+
status: 'running';
|
|
1102
|
+
payload: P;
|
|
1103
|
+
resumePayload?: R;
|
|
1104
|
+
suspendPayload?: S;
|
|
1105
|
+
startedAt: number;
|
|
1106
|
+
suspendedAt?: number;
|
|
1107
|
+
resumedAt?: number;
|
|
1108
|
+
};
|
|
1109
|
+
type StepResult<P, R, S, T> = StepSuccess<P, R, S, T> | StepFailure<P, R, S> | StepSuspended<P, S> | StepRunning<P, R, S>;
|
|
1110
|
+
type StepsRecord<T extends readonly Step<any, any, any>[]> = {
|
|
1111
|
+
[K in T[number]['id']]: Extract<T[number], {
|
|
1112
|
+
id: K;
|
|
1113
|
+
}>;
|
|
1114
|
+
};
|
|
1115
|
+
type DynamicMapping<TPrevSchema extends z.ZodTypeAny, TSchemaOut extends z.ZodTypeAny> = {
|
|
1116
|
+
fn: ExecuteFunction<z.infer<TPrevSchema>, z.infer<TSchemaOut>, any, any>;
|
|
1117
|
+
schema: TSchemaOut;
|
|
1118
|
+
};
|
|
1119
|
+
type PathsToStringProps<T> = T extends object ? {
|
|
1120
|
+
[K in keyof T]: T[K] extends object ? K extends string ? K | `${K}.${PathsToStringProps<T[K]>}` : never : K extends string ? K : never;
|
|
1121
|
+
}[keyof T] : never;
|
|
1122
|
+
type ExtractSchemaType<T extends z.ZodType<any>> = T extends z.ZodObject<infer V> ? V : never;
|
|
1123
|
+
type ExtractSchemaFromStep<TStep extends Step<any, any, any>, TKey extends 'inputSchema' | 'outputSchema'> = TStep[TKey];
|
|
1124
|
+
type VariableReference<TStep extends Step<string, any, any> = Step<string, any, any>, TVarPath extends PathsToStringProps<ExtractSchemaType<ExtractSchemaFromStep<TStep, 'outputSchema'>>> | '' | '.' = PathsToStringProps<ExtractSchemaType<ExtractSchemaFromStep<TStep, 'outputSchema'>>> | '' | '.'> = {
|
|
1125
|
+
step: TStep;
|
|
1126
|
+
path: TVarPath;
|
|
1127
|
+
} | {
|
|
1128
|
+
value: any;
|
|
1129
|
+
schema: z.ZodTypeAny;
|
|
1130
|
+
};
|
|
1131
|
+
type WatchEvent = {
|
|
1132
|
+
type: 'watch';
|
|
1133
|
+
payload: {
|
|
1134
|
+
currentStep?: {
|
|
1135
|
+
id: string;
|
|
1136
|
+
status: 'running' | 'success' | 'failed' | 'suspended';
|
|
1137
|
+
output?: Record<string, any>;
|
|
1138
|
+
resumePayload?: Record<string, any>;
|
|
1139
|
+
payload?: Record<string, any>;
|
|
1140
|
+
error?: string | Error;
|
|
1141
|
+
};
|
|
1142
|
+
workflowState: {
|
|
1143
|
+
status: 'running' | 'success' | 'failed' | 'suspended';
|
|
1144
|
+
steps: Record<string, {
|
|
1145
|
+
status: 'running' | 'success' | 'failed' | 'suspended';
|
|
1146
|
+
output?: Record<string, any>;
|
|
1147
|
+
payload?: Record<string, any>;
|
|
1148
|
+
resumePayload?: Record<string, any>;
|
|
1149
|
+
error?: string | Error;
|
|
1150
|
+
startedAt: number;
|
|
1151
|
+
endedAt: number;
|
|
1152
|
+
suspendedAt?: number;
|
|
1153
|
+
resumedAt?: number;
|
|
1154
|
+
}>;
|
|
1155
|
+
output?: Record<string, any>;
|
|
1156
|
+
payload?: Record<string, any>;
|
|
1157
|
+
error?: string | Error;
|
|
1158
|
+
};
|
|
1159
|
+
};
|
|
1160
|
+
eventTimestamp: Date;
|
|
1161
|
+
};
|
|
1162
|
+
type ZodPathType<T extends z.ZodTypeAny, P extends string> = T extends z.ZodObject<infer Shape> ? P extends `${infer Key}.${infer Rest}` ? Key extends keyof Shape ? Shape[Key] extends z.ZodTypeAny ? ZodPathType<Shape[Key], Rest> : never : never : P extends keyof Shape ? Shape[P] : never : never;
|
|
1163
|
+
interface WorkflowRunState {
|
|
1164
|
+
runId: string;
|
|
1165
|
+
value: Record<string, string>;
|
|
1166
|
+
context: {
|
|
1167
|
+
input?: Record<string, any>;
|
|
1168
|
+
} & Record<string, StepResult<any, any, any, any>>;
|
|
1169
|
+
activePaths: Array<unknown>;
|
|
1170
|
+
suspendedPaths: Record<string, number[]>;
|
|
1171
|
+
timestamp: number;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
/**
|
|
1175
|
+
* Represents an execution graph for a workflow
|
|
1176
|
+
*/
|
|
1177
|
+
interface ExecutionGraph {
|
|
1178
|
+
id: string;
|
|
1179
|
+
steps: StepFlowEntry[];
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* Execution engine abstract class for building and executing workflow graphs
|
|
1183
|
+
* Providers will implement this class to provide their own execution logic
|
|
1184
|
+
*/
|
|
1185
|
+
declare abstract class ExecutionEngine extends MastraBase {
|
|
1186
|
+
protected mastra?: Mastra;
|
|
1187
|
+
constructor({ mastra }: {
|
|
1188
|
+
mastra?: Mastra;
|
|
1369
1189
|
});
|
|
1370
|
-
|
|
1371
|
-
get runId(): string;
|
|
1372
|
-
get executionSpan(): Span | undefined;
|
|
1373
|
-
watch(onTransition: (state: Pick<LegacyWorkflowRunResult<TTriggerSchema, TSteps, TResult>, 'results' | 'activePaths' | 'runId' | 'timestamp'>) => void): () => void;
|
|
1374
|
-
start({ triggerData, runtimeContext, }?: {
|
|
1375
|
-
triggerData?: z.infer<TTriggerSchema>;
|
|
1376
|
-
runtimeContext?: RuntimeContext;
|
|
1377
|
-
}): Promise<{
|
|
1378
|
-
runId: string;
|
|
1379
|
-
result?: z.TypeOf<TResult> | undefined;
|
|
1380
|
-
triggerData?: z.TypeOf<TTriggerSchema> | undefined;
|
|
1381
|
-
results: { [K in keyof StepsRecord$1<TSteps>]: StepsRecord$1<TSteps>[K]["outputSchema"] extends undefined ? StepResult$1<unknown> : StepResult$1<z.TypeOf<NonNullable<StepsRecord$1<TSteps>[K]["outputSchema"]>>>; };
|
|
1382
|
-
timestamp: number;
|
|
1383
|
-
activePaths: Map<TSteps[number]["id"], {
|
|
1384
|
-
status: string;
|
|
1385
|
-
suspendPayload?: any;
|
|
1386
|
-
stepPath: string[];
|
|
1387
|
-
}>;
|
|
1388
|
-
}>;
|
|
1389
|
-
private isCompoundDependencyMet;
|
|
1390
|
-
execute({ triggerData, snapshot, stepId, resumeData, runtimeContext, }?: {
|
|
1391
|
-
stepId?: string;
|
|
1392
|
-
triggerData?: z.infer<TTriggerSchema>;
|
|
1393
|
-
snapshot?: Snapshot<any>;
|
|
1394
|
-
resumeData?: any;
|
|
1395
|
-
runtimeContext: RuntimeContext;
|
|
1396
|
-
}): Promise<Omit<LegacyWorkflowRunResult<TTriggerSchema, TSteps, TResult>, 'runId'>>;
|
|
1397
|
-
hasSubscribers(stepId: string): boolean;
|
|
1398
|
-
runMachine(parentStepId: string, input: any, runtimeContext?: RuntimeContext): Promise<(Pick<LegacyWorkflowRunResult<TTriggerSchema, TSteps, TResult>, "runId" | "results" | "timestamp" | "activePaths"> | undefined)[]>;
|
|
1399
|
-
suspend(stepId: string, machine: Machine<TSteps, TTriggerSchema>): Promise<void>;
|
|
1190
|
+
__registerMastra(mastra: Mastra): void;
|
|
1400
1191
|
/**
|
|
1401
|
-
*
|
|
1192
|
+
* Executes a workflow run with the provided execution graph and input
|
|
1193
|
+
* @param graph The execution graph to execute
|
|
1194
|
+
* @param input The input data for the workflow
|
|
1195
|
+
* @returns A promise that resolves to the workflow output
|
|
1402
1196
|
*/
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1197
|
+
abstract execute<TInput, TOutput>(params: {
|
|
1198
|
+
workflowId: string;
|
|
1199
|
+
runId: string;
|
|
1200
|
+
graph: ExecutionGraph;
|
|
1201
|
+
input?: TInput;
|
|
1202
|
+
resume?: {
|
|
1203
|
+
steps: string[];
|
|
1204
|
+
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
1205
|
+
resumePayload: any;
|
|
1206
|
+
resumePath: number[];
|
|
1207
|
+
};
|
|
1208
|
+
emitter: {
|
|
1209
|
+
emit: (event: string, data: any) => Promise<void>;
|
|
1210
|
+
};
|
|
1414
1211
|
runtimeContext: RuntimeContext;
|
|
1415
|
-
|
|
1212
|
+
retryConfig?: {
|
|
1213
|
+
attempts?: number;
|
|
1214
|
+
delay?: number;
|
|
1215
|
+
};
|
|
1216
|
+
}): Promise<TOutput>;
|
|
1416
1217
|
}
|
|
1417
1218
|
|
|
1418
|
-
type
|
|
1419
|
-
|
|
1219
|
+
type StepFlowEntry = {
|
|
1220
|
+
type: 'step';
|
|
1221
|
+
step: Step;
|
|
1222
|
+
} | {
|
|
1223
|
+
type: 'parallel';
|
|
1224
|
+
steps: StepFlowEntry[];
|
|
1225
|
+
} | {
|
|
1226
|
+
type: 'conditional';
|
|
1227
|
+
steps: StepFlowEntry[];
|
|
1228
|
+
conditions: ExecuteFunction<any, any, any, any>[];
|
|
1229
|
+
serializedConditions: {
|
|
1230
|
+
id: string;
|
|
1231
|
+
fn: string;
|
|
1232
|
+
}[];
|
|
1233
|
+
} | {
|
|
1234
|
+
type: 'loop';
|
|
1235
|
+
step: Step;
|
|
1236
|
+
condition: ExecuteFunction<any, any, any, any>;
|
|
1237
|
+
serializedCondition: {
|
|
1238
|
+
id: string;
|
|
1239
|
+
fn: string;
|
|
1240
|
+
};
|
|
1241
|
+
loopType: 'dowhile' | 'dountil';
|
|
1242
|
+
} | {
|
|
1243
|
+
type: 'foreach';
|
|
1244
|
+
step: Step;
|
|
1245
|
+
opts: {
|
|
1246
|
+
concurrency: number;
|
|
1247
|
+
};
|
|
1248
|
+
};
|
|
1249
|
+
type SerializedStep = Pick<Step, 'id' | 'description'> & {
|
|
1250
|
+
component?: string;
|
|
1251
|
+
serializedStepFlow?: SerializedStepFlowEntry[];
|
|
1252
|
+
mapConfig?: string;
|
|
1253
|
+
};
|
|
1254
|
+
type SerializedStepFlowEntry = {
|
|
1255
|
+
type: 'step';
|
|
1256
|
+
step: SerializedStep;
|
|
1257
|
+
} | {
|
|
1258
|
+
type: 'parallel';
|
|
1259
|
+
steps: SerializedStepFlowEntry[];
|
|
1260
|
+
} | {
|
|
1261
|
+
type: 'conditional';
|
|
1262
|
+
steps: SerializedStepFlowEntry[];
|
|
1263
|
+
serializedConditions: {
|
|
1264
|
+
id: string;
|
|
1265
|
+
fn: string;
|
|
1266
|
+
}[];
|
|
1267
|
+
} | {
|
|
1268
|
+
type: 'loop';
|
|
1269
|
+
step: SerializedStep;
|
|
1270
|
+
serializedCondition: {
|
|
1271
|
+
id: string;
|
|
1272
|
+
fn: string;
|
|
1273
|
+
};
|
|
1274
|
+
loopType: 'dowhile' | 'dountil';
|
|
1275
|
+
} | {
|
|
1276
|
+
type: 'foreach';
|
|
1277
|
+
step: SerializedStep;
|
|
1278
|
+
opts: {
|
|
1279
|
+
concurrency: number;
|
|
1280
|
+
};
|
|
1281
|
+
};
|
|
1282
|
+
/**
|
|
1283
|
+
* Creates a new workflow step
|
|
1284
|
+
* @param params Configuration parameters for the step
|
|
1285
|
+
* @param params.id Unique identifier for the step
|
|
1286
|
+
* @param params.description Optional description of what the step does
|
|
1287
|
+
* @param params.inputSchema Zod schema defining the input structure
|
|
1288
|
+
* @param params.outputSchema Zod schema defining the output structure
|
|
1289
|
+
* @param params.execute Function that performs the step's operations
|
|
1290
|
+
* @returns A Step object that can be added to the workflow
|
|
1291
|
+
*/
|
|
1292
|
+
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: {
|
|
1293
|
+
id: TStepId;
|
|
1294
|
+
description?: string;
|
|
1295
|
+
inputSchema: TStepInput;
|
|
1296
|
+
outputSchema: TStepOutput;
|
|
1297
|
+
resumeSchema?: TResumeSchema;
|
|
1298
|
+
suspendSchema?: TSuspendSchema;
|
|
1299
|
+
execute: ExecuteFunction<z.infer<TStepInput>, z.infer<TStepOutput>, z.infer<TResumeSchema>, z.infer<TSuspendSchema>>;
|
|
1300
|
+
}): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema>;
|
|
1301
|
+
declare function createStep<TStepId extends string, TStepInput extends z.ZodObject<{
|
|
1302
|
+
prompt: z.ZodString;
|
|
1303
|
+
}>, TStepOutput extends z.ZodObject<{
|
|
1304
|
+
text: z.ZodString;
|
|
1305
|
+
}>, TResumeSchema extends z.ZodType<any>, TSuspendSchema extends z.ZodType<any>>(agent: Agent<TStepId, any, any>): Step<TStepId, TStepInput, TStepOutput, TResumeSchema, TSuspendSchema>;
|
|
1306
|
+
declare function createStep<TSchemaIn extends z.ZodType<any>, TSchemaOut extends z.ZodType<any>, TContext extends ToolExecutionContext<TSchemaIn>>(tool: Tool<TSchemaIn, TSchemaOut, TContext> & {
|
|
1307
|
+
inputSchema: TSchemaIn;
|
|
1308
|
+
outputSchema: TSchemaOut;
|
|
1309
|
+
execute: (context: TContext) => Promise<any>;
|
|
1310
|
+
}): Step<string, TSchemaIn, TSchemaOut, z.ZodType<any>, z.ZodType<any>>;
|
|
1311
|
+
declare function cloneStep<TStepId extends string>(step: Step<string, any, any>, opts: {
|
|
1312
|
+
id: TStepId;
|
|
1313
|
+
}): Step<TStepId, any, any>;
|
|
1314
|
+
declare function createWorkflow<TWorkflowId extends string = string, TInput extends z.ZodType<any> = z.ZodType<any>, TOutput extends z.ZodType<any> = z.ZodType<any>, TSteps extends Step<string, any, any, any, any>[] = Step<string, any, any, any, any>[]>(params: WorkflowConfig<TWorkflowId, TInput, TOutput, TSteps>): Workflow<TSteps, TWorkflowId, TInput, TOutput, TInput>;
|
|
1315
|
+
declare function cloneWorkflow<TWorkflowId extends string = string, TInput extends z.ZodType<any> = z.ZodType<any>, TOutput extends z.ZodType<any> = z.ZodType<any>, TSteps extends Step<string, any, any, any, any>[] = Step<string, any, any, any, any>[]>(workflow: Workflow<TSteps, string, TInput, TOutput>, opts: {
|
|
1316
|
+
id: TWorkflowId;
|
|
1317
|
+
}): Workflow<TSteps, TWorkflowId, TInput, TOutput>;
|
|
1318
|
+
type WorkflowResult<TOutput extends z.ZodType<any>, TSteps extends Step<string, any, any>[]> = {
|
|
1319
|
+
status: 'success';
|
|
1320
|
+
result: z.infer<TOutput>;
|
|
1321
|
+
steps: {
|
|
1322
|
+
[K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]['outputSchema'] extends undefined ? StepResult<unknown, unknown, unknown, unknown> : StepResult<z.infer<NonNullable<StepsRecord<TSteps>[K]['inputSchema']>>, z.infer<NonNullable<StepsRecord<TSteps>[K]['resumeSchema']>>, z.infer<NonNullable<StepsRecord<TSteps>[K]['suspendSchema']>>, z.infer<NonNullable<StepsRecord<TSteps>[K]['outputSchema']>>>;
|
|
1323
|
+
};
|
|
1324
|
+
} | {
|
|
1325
|
+
status: 'failed';
|
|
1326
|
+
steps: {
|
|
1327
|
+
[K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]['outputSchema'] extends undefined ? StepResult<unknown, unknown, unknown, unknown> : StepResult<z.infer<NonNullable<StepsRecord<TSteps>[K]['inputSchema']>>, z.infer<NonNullable<StepsRecord<TSteps>[K]['resumeSchema']>>, z.infer<NonNullable<StepsRecord<TSteps>[K]['suspendSchema']>>, z.infer<NonNullable<StepsRecord<TSteps>[K]['outputSchema']>>>;
|
|
1328
|
+
};
|
|
1329
|
+
error: Error;
|
|
1330
|
+
} | {
|
|
1331
|
+
status: 'suspended';
|
|
1332
|
+
steps: {
|
|
1333
|
+
[K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]['outputSchema'] extends undefined ? StepResult<unknown, unknown, unknown, unknown> : StepResult<z.infer<NonNullable<StepsRecord<TSteps>[K]['inputSchema']>>, z.infer<NonNullable<StepsRecord<TSteps>[K]['resumeSchema']>>, z.infer<NonNullable<StepsRecord<TSteps>[K]['suspendSchema']>>, z.infer<NonNullable<StepsRecord<TSteps>[K]['outputSchema']>>>;
|
|
1334
|
+
};
|
|
1335
|
+
suspended: [string[], ...string[][]];
|
|
1336
|
+
};
|
|
1337
|
+
type WorkflowConfig<TWorkflowId extends string = string, TInput extends z.ZodType<any> = z.ZodType<any>, TOutput extends z.ZodType<any> = z.ZodType<any>, TSteps extends Step<string, any, any, any, any>[] = Step<string, any, any, any, any>[]> = {
|
|
1338
|
+
mastra?: Mastra;
|
|
1339
|
+
id: TWorkflowId;
|
|
1340
|
+
description?: string | undefined;
|
|
1341
|
+
inputSchema: TInput;
|
|
1342
|
+
outputSchema: TOutput;
|
|
1343
|
+
executionEngine?: ExecutionEngine;
|
|
1344
|
+
steps?: TSteps;
|
|
1345
|
+
retryConfig?: {
|
|
1346
|
+
attempts?: number;
|
|
1347
|
+
delay?: number;
|
|
1348
|
+
};
|
|
1349
|
+
};
|
|
1350
|
+
declare class Workflow<TSteps extends Step<string, any, any, any, any>[] = Step<string, any, any, 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 MastraBase implements Step<TWorkflowId, TInput, TOutput> {
|
|
1420
1351
|
#private;
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
while<FallbackStep extends StepAction<string, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>>(condition: StepConfig<FallbackStep, CondStep, VarStep, TTriggerSchema, TSteps>['when'], fallbackStep: FallbackStep, variables?: StepConfig<FallbackStep, CondStep, VarStep, TTriggerSchema, TSteps>['variables']): Pick<WorkflowBuilder<this>, "then" | "commit">;
|
|
1446
|
-
until<FallbackStep extends StepAction<string, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>>(condition: StepConfig<FallbackStep, CondStep, VarStep, TTriggerSchema, TSteps>['when'], fallbackStep: FallbackStep, variables?: StepConfig<FallbackStep, CondStep, VarStep, TTriggerSchema, TSteps>['variables']): Pick<WorkflowBuilder<this>, "then" | "commit">;
|
|
1447
|
-
if<TStep extends StepAction<string, any, any, any>>(condition: StepConfig<TStep, any, any, TTriggerSchema>['when'], ifStep?: TStep | LegacyWorkflow, elseStep?: TStep | LegacyWorkflow): this | WorkflowBuilder<this>;
|
|
1448
|
-
else(): WorkflowBuilder<this>;
|
|
1449
|
-
after<TStep extends StepAction<string, any, any, any>>(steps: string | TStep | TStep[] | (TStep | string)[]): Omit<WorkflowBuilder<this>, 'then' | 'after'>;
|
|
1450
|
-
after<TWorkflow extends LegacyWorkflow<any, any, any, any>>(steps: TWorkflow | TWorkflow[]): Omit<WorkflowBuilder<this>, 'then' | 'after'>;
|
|
1451
|
-
after<TAgent extends Agent<any, any, any>>(steps: TAgent | TAgent[]): Omit<WorkflowBuilder<this>, 'then' | 'after'>;
|
|
1452
|
-
afterEvent(eventName: string): WorkflowBuilder<this>;
|
|
1453
|
-
/**
|
|
1454
|
-
* Executes the workflow with the given trigger data
|
|
1455
|
-
* @param triggerData - Initial data to start the workflow with
|
|
1456
|
-
* @returns Promise resolving to workflow results or rejecting with error
|
|
1457
|
-
* @throws Error if trigger schema validation fails
|
|
1352
|
+
id: TWorkflowId;
|
|
1353
|
+
description?: string | undefined;
|
|
1354
|
+
inputSchema: TInput;
|
|
1355
|
+
outputSchema: TOutput;
|
|
1356
|
+
steps: Record<string, Step<string, any, any, any, any>>;
|
|
1357
|
+
stepDefs?: TSteps;
|
|
1358
|
+
protected stepFlow: StepFlowEntry[];
|
|
1359
|
+
protected serializedStepFlow: SerializedStepFlowEntry[];
|
|
1360
|
+
protected executionEngine: ExecutionEngine;
|
|
1361
|
+
protected executionGraph: ExecutionGraph;
|
|
1362
|
+
protected retryConfig: {
|
|
1363
|
+
attempts?: number;
|
|
1364
|
+
delay?: number;
|
|
1365
|
+
};
|
|
1366
|
+
constructor({ mastra, id, inputSchema, outputSchema, description, executionEngine, retryConfig, steps, }: WorkflowConfig<TWorkflowId, TInput, TOutput, TSteps>);
|
|
1367
|
+
get runs(): Map<string, Run<TSteps, TInput, TOutput>>;
|
|
1368
|
+
get mastra(): Mastra<Record<string, Agent<any, ToolsInput, Record<string, Metric>>>, Record<string, LegacyWorkflow<LegacyStep<string, any, any, StepExecutionContext<any, WorkflowContext<any, LegacyStep<string, any, any, any>[], Record<string, any>>>>[], string, any, any>>, Record<string, Workflow<Step<string, any, any, any, any>[], string, z.ZodType<any, z.ZodTypeDef, any>, z.ZodType<any, z.ZodTypeDef, any>, z.ZodType<any, z.ZodTypeDef, any>>>, Record<string, MastraVector>, Record<string, MastraTTS>, IMastraLogger, Record<string, AgentNetwork>, Record<string, MCPServerBase>> | undefined;
|
|
1369
|
+
__registerMastra(mastra: Mastra): void;
|
|
1370
|
+
__registerPrimitives(p: MastraPrimitives): void;
|
|
1371
|
+
setStepFlow(stepFlow: StepFlowEntry[]): void;
|
|
1372
|
+
/**
|
|
1373
|
+
* Adds a step to the workflow
|
|
1374
|
+
* @param step The step to add to the workflow
|
|
1375
|
+
* @returns The workflow instance for chaining
|
|
1458
1376
|
*/
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1377
|
+
then<TStepInputSchema extends TPrevSchema, TStepId extends string, TSchemaOut extends z.ZodType<any>>(step: Step<TStepId, TStepInputSchema, TSchemaOut, any, any>): Workflow<TSteps, TWorkflowId, TInput, TOutput, TSchemaOut>;
|
|
1378
|
+
map<TSteps extends Step<string, any, any>[], TMapping extends {
|
|
1379
|
+
[K in keyof TMapping]: {
|
|
1380
|
+
step: TSteps[number] | TSteps[number][];
|
|
1381
|
+
path: PathsToStringProps<ExtractSchemaType<ExtractSchemaFromStep<TSteps[number], 'outputSchema'>>> | '.';
|
|
1382
|
+
} | {
|
|
1383
|
+
value: any;
|
|
1384
|
+
schema: z.ZodTypeAny;
|
|
1385
|
+
} | {
|
|
1386
|
+
initData: TSteps[number];
|
|
1387
|
+
path: PathsToStringProps<ExtractSchemaType<ExtractSchemaFromStep<TSteps[number], 'inputSchema'>>> | '.';
|
|
1388
|
+
} | {
|
|
1389
|
+
runtimeContextPath: string;
|
|
1390
|
+
schema: z.ZodTypeAny;
|
|
1391
|
+
} | DynamicMapping<TPrevSchema, z.ZodTypeAny>;
|
|
1392
|
+
}>(mappingConfig: TMapping | ExecuteFunction<z.infer<TPrevSchema>, any, any, any>): Workflow<TSteps, TWorkflowId, TInput, TOutput, any>;
|
|
1393
|
+
parallel<TParallelSteps extends Step<string, TPrevSchema, any, any, any>[]>(steps: TParallelSteps): Workflow<TSteps, TWorkflowId, TInput, TOutput, z.ZodObject<{ [K in keyof StepsRecord<TParallelSteps>]: StepsRecord<TParallelSteps>[K]["outputSchema"]["path"]; }, any, z.ZodTypeAny>>;
|
|
1394
|
+
branch<TBranchSteps extends Array<[
|
|
1395
|
+
ExecuteFunction<z.infer<TPrevSchema>, any, any, any>,
|
|
1396
|
+
Step<string, TPrevSchema, any, any, any>
|
|
1397
|
+
]>>(steps: TBranchSteps): Workflow<TSteps, TWorkflowId, TInput, TOutput, z.ZodObject<{ [K in keyof StepsRecord<{ [K_1 in keyof TBranchSteps]: TBranchSteps[K_1][1]; }[number][]>]: StepsRecord<{ [K_1 in keyof TBranchSteps]: TBranchSteps[K_1][1]; }[number][]>[K]["outputSchema"]; }, any, z.ZodTypeAny>>;
|
|
1398
|
+
dowhile<TStepInputSchema extends TPrevSchema, TStepId extends string, TSchemaOut extends z.ZodType<any>>(step: Step<TStepId, TStepInputSchema, TSchemaOut, any, any>, condition: ExecuteFunction<z.infer<TSchemaOut>, any, any, any>): Workflow<TSteps, TWorkflowId, TInput, TOutput, TSchemaOut>;
|
|
1399
|
+
dountil<TStepInputSchema extends TPrevSchema, TStepId extends string, TSchemaOut extends z.ZodType<any>>(step: Step<TStepId, TStepInputSchema, TSchemaOut, any, any>, condition: ExecuteFunction<z.infer<TSchemaOut>, any, any, any>): Workflow<TSteps, TWorkflowId, TInput, TOutput, TSchemaOut>;
|
|
1400
|
+
foreach<TPrevIsArray extends TPrevSchema extends z.ZodArray<any> ? true : false, TStepInputSchema extends TPrevSchema extends z.ZodArray<infer TElement> ? TElement : never, TStepId extends string, TSchemaOut extends z.ZodType<any>>(step: TPrevIsArray extends true ? Step<TStepId, TStepInputSchema, TSchemaOut, any, any> : 'Previous step must return an array type', opts?: {
|
|
1401
|
+
concurrency: number;
|
|
1402
|
+
}): Workflow<TSteps, TWorkflowId, TInput, TOutput, z.ZodArray<TSchemaOut>>;
|
|
1465
1403
|
/**
|
|
1466
|
-
*
|
|
1467
|
-
* @
|
|
1468
|
-
* @returns The workflow run instance if found, undefined otherwise
|
|
1404
|
+
* Builds the execution graph for this workflow
|
|
1405
|
+
* @returns The execution graph that can be used to execute the workflow
|
|
1469
1406
|
*/
|
|
1470
|
-
|
|
1407
|
+
buildExecutionGraph(): ExecutionGraph;
|
|
1471
1408
|
/**
|
|
1472
|
-
*
|
|
1473
|
-
*
|
|
1474
|
-
* @returns
|
|
1409
|
+
* Finalizes the workflow definition and prepares it for execution
|
|
1410
|
+
* This method should be called after all steps have been added to the workflow
|
|
1411
|
+
* @returns A built workflow instance ready for execution
|
|
1475
1412
|
*/
|
|
1476
|
-
|
|
1413
|
+
commit(): Workflow<TSteps, TWorkflowId, TInput, TOutput, TOutput>;
|
|
1414
|
+
get stepGraph(): StepFlowEntry[];
|
|
1415
|
+
get serializedStepGraph(): SerializedStepFlowEntry[];
|
|
1477
1416
|
/**
|
|
1478
|
-
*
|
|
1479
|
-
*
|
|
1480
|
-
*
|
|
1481
|
-
* @throws Error if validation fails
|
|
1482
|
-
*
|
|
1483
|
-
* @returns this instance for method chaining
|
|
1417
|
+
* Creates a new workflow run instance
|
|
1418
|
+
* @param options Optional configuration for the run
|
|
1419
|
+
* @returns A Run instance that can be used to execute the workflow
|
|
1484
1420
|
*/
|
|
1485
|
-
|
|
1421
|
+
createRun(options?: {
|
|
1422
|
+
runId?: string;
|
|
1423
|
+
}): Run<TSteps, TInput, TOutput>;
|
|
1424
|
+
execute({ inputData, resumeData, suspend, resume, [EMITTER_SYMBOL]: emitter, mastra, runtimeContext, }: {
|
|
1425
|
+
inputData: z.infer<TInput>;
|
|
1426
|
+
resumeData?: any;
|
|
1427
|
+
getStepResult<T extends Step<any, any, any>>(stepId: T): T['outputSchema'] extends undefined ? unknown : z.infer<NonNullable<T['outputSchema']>>;
|
|
1428
|
+
suspend: (suspendPayload: any) => Promise<void>;
|
|
1429
|
+
resume?: {
|
|
1430
|
+
steps: string[];
|
|
1431
|
+
resumePayload: any;
|
|
1432
|
+
runId?: string;
|
|
1433
|
+
};
|
|
1434
|
+
[EMITTER_SYMBOL]: {
|
|
1435
|
+
emit: (event: string, data: any) => void;
|
|
1436
|
+
};
|
|
1437
|
+
mastra: Mastra;
|
|
1438
|
+
runtimeContext?: RuntimeContext;
|
|
1439
|
+
}): Promise<z.infer<TOutput>>;
|
|
1486
1440
|
getWorkflowRuns(args?: {
|
|
1487
1441
|
fromDate?: Date;
|
|
1488
1442
|
toDate?: Date;
|
|
1489
1443
|
limit?: number;
|
|
1490
1444
|
offset?: number;
|
|
1491
1445
|
resourceId?: string;
|
|
1492
|
-
}): Promise<
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1446
|
+
}): Promise<WorkflowRuns>;
|
|
1447
|
+
getWorkflowRunById(runId: string): Promise<WorkflowRun | null>;
|
|
1448
|
+
}
|
|
1449
|
+
/**
|
|
1450
|
+
* Represents a workflow run that can be executed
|
|
1451
|
+
*/
|
|
1452
|
+
declare class Run<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>> {
|
|
1453
|
+
#private;
|
|
1454
|
+
protected emitter: EventEmitter$1;
|
|
1455
|
+
/**
|
|
1456
|
+
* Unique identifier for this workflow
|
|
1457
|
+
*/
|
|
1458
|
+
readonly workflowId: string;
|
|
1459
|
+
/**
|
|
1460
|
+
* Unique identifier for this run
|
|
1461
|
+
*/
|
|
1462
|
+
readonly runId: string;
|
|
1463
|
+
/**
|
|
1464
|
+
* Internal state of the workflow run
|
|
1465
|
+
*/
|
|
1466
|
+
protected state: Record<string, any>;
|
|
1467
|
+
/**
|
|
1468
|
+
* The execution engine for this run
|
|
1469
|
+
*/
|
|
1470
|
+
executionEngine: ExecutionEngine;
|
|
1471
|
+
/**
|
|
1472
|
+
* The execution graph for this run
|
|
1473
|
+
*/
|
|
1474
|
+
executionGraph: ExecutionGraph;
|
|
1475
|
+
protected cleanup?: () => void;
|
|
1476
|
+
protected retryConfig?: {
|
|
1477
|
+
attempts?: number;
|
|
1478
|
+
delay?: number;
|
|
1479
|
+
};
|
|
1480
|
+
constructor(params: {
|
|
1481
|
+
workflowId: string;
|
|
1496
1482
|
runId: string;
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1483
|
+
executionEngine: ExecutionEngine;
|
|
1484
|
+
executionGraph: ExecutionGraph;
|
|
1485
|
+
mastra?: Mastra;
|
|
1486
|
+
retryConfig?: {
|
|
1487
|
+
attempts?: number;
|
|
1488
|
+
delay?: number;
|
|
1489
|
+
};
|
|
1490
|
+
cleanup?: () => void;
|
|
1491
|
+
});
|
|
1492
|
+
/**
|
|
1493
|
+
* Starts the workflow execution with the provided input
|
|
1494
|
+
* @param input The input data for the workflow
|
|
1495
|
+
* @returns A promise that resolves to the workflow output
|
|
1496
|
+
*/
|
|
1497
|
+
start({ inputData, runtimeContext, }: {
|
|
1498
|
+
inputData?: z.infer<TInput>;
|
|
1499
|
+
runtimeContext?: RuntimeContext;
|
|
1500
|
+
}): Promise<WorkflowResult<TOutput, TSteps>>;
|
|
1501
|
+
/**
|
|
1502
|
+
* Starts the workflow execution with the provided input as a stream
|
|
1503
|
+
* @param input The input data for the workflow
|
|
1504
|
+
* @returns A promise that resolves to the workflow output
|
|
1505
|
+
*/
|
|
1506
|
+
stream({ inputData, runtimeContext }?: {
|
|
1507
|
+
inputData?: z.infer<TInput>;
|
|
1508
|
+
runtimeContext?: RuntimeContext;
|
|
1509
|
+
}): {
|
|
1510
|
+
stream: ReadableStream<WatchEvent>;
|
|
1511
|
+
getWorkflowState: () => Promise<WorkflowResult<TOutput, TSteps>>;
|
|
1512
|
+
};
|
|
1513
|
+
watch(cb: (event: WatchEvent) => void, type?: 'watch' | 'watch-v2'): () => void;
|
|
1514
|
+
resume<TResumeSchema extends z.ZodType<any>>(params: {
|
|
1515
|
+
resumeData?: z.infer<TResumeSchema>;
|
|
1516
|
+
step: Step<string, any, any, TResumeSchema, any> | [...Step<string, any, any, any, any>[], Step<string, any, any, TResumeSchema, any>] | string | string[];
|
|
1517
|
+
runtimeContext?: RuntimeContext;
|
|
1518
|
+
}): Promise<WorkflowResult<TOutput, TSteps>>;
|
|
1519
|
+
/**
|
|
1520
|
+
* Returns the current state of the workflow run
|
|
1521
|
+
* @returns The current state of the workflow run
|
|
1522
|
+
*/
|
|
1523
|
+
getState(): Record<string, any>;
|
|
1524
|
+
updateState(state: Record<string, any>): void;
|
|
1512
1525
|
}
|
|
1513
1526
|
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
getStepResult<T extends Step<any, any, any>>(stepId: T): T['outputSchema'] extends undefined ? unknown : z.infer<NonNullable<T['outputSchema']>>;
|
|
1522
|
-
suspend(suspendPayload: TSuspendSchema): Promise<void>;
|
|
1523
|
-
resume?: {
|
|
1524
|
-
steps: string[];
|
|
1525
|
-
resumePayload: any;
|
|
1526
|
-
};
|
|
1527
|
-
[EMITTER_SYMBOL]: {
|
|
1528
|
-
emit: (event: string, data: any) => Promise<void>;
|
|
1527
|
+
interface StorageColumn {
|
|
1528
|
+
type: 'text' | 'timestamp' | 'uuid' | 'jsonb' | 'integer' | 'bigint';
|
|
1529
|
+
primaryKey?: boolean;
|
|
1530
|
+
nullable?: boolean;
|
|
1531
|
+
references?: {
|
|
1532
|
+
table: string;
|
|
1533
|
+
column: string;
|
|
1529
1534
|
};
|
|
1530
|
-
}) => Promise<TStepOutput>;
|
|
1531
|
-
interface Step<TStepId extends string = string, TSchemaIn extends z.ZodType<any> = z.ZodType<any>, TSchemaOut extends z.ZodType<any> = z.ZodType<any>, TResumeSchema extends z.ZodType<any> = z.ZodType<any>, TSuspendSchema extends z.ZodType<any> = z.ZodType<any>> {
|
|
1532
|
-
id: TStepId;
|
|
1533
|
-
description?: string;
|
|
1534
|
-
inputSchema: TSchemaIn;
|
|
1535
|
-
outputSchema: TSchemaOut;
|
|
1536
|
-
resumeSchema?: TResumeSchema;
|
|
1537
|
-
suspendSchema?: TSuspendSchema;
|
|
1538
|
-
execute: ExecuteFunction<z.infer<TSchemaIn>, z.infer<TSchemaOut>, z.infer<TResumeSchema>, z.infer<TSuspendSchema>>;
|
|
1539
|
-
retries?: number;
|
|
1540
1535
|
}
|
|
1536
|
+
interface LegacyWorkflowRuns {
|
|
1537
|
+
runs: LegacyWorkflowRun[];
|
|
1538
|
+
total: number;
|
|
1539
|
+
}
|
|
1540
|
+
interface LegacyWorkflowRun {
|
|
1541
|
+
workflowName: string;
|
|
1542
|
+
runId: string;
|
|
1543
|
+
snapshot: LegacyWorkflowRunState | string;
|
|
1544
|
+
createdAt: Date;
|
|
1545
|
+
updatedAt: Date;
|
|
1546
|
+
resourceId?: string;
|
|
1547
|
+
}
|
|
1548
|
+
interface WorkflowRuns {
|
|
1549
|
+
runs: WorkflowRun[];
|
|
1550
|
+
total: number;
|
|
1551
|
+
}
|
|
1552
|
+
interface WorkflowRun {
|
|
1553
|
+
workflowName: string;
|
|
1554
|
+
runId: string;
|
|
1555
|
+
snapshot: WorkflowRunState | string;
|
|
1556
|
+
createdAt: Date;
|
|
1557
|
+
updatedAt: Date;
|
|
1558
|
+
resourceId?: string;
|
|
1559
|
+
}
|
|
1560
|
+
type StorageGetMessagesArg = {
|
|
1561
|
+
threadId: string;
|
|
1562
|
+
resourceId?: string;
|
|
1563
|
+
selectBy?: {
|
|
1564
|
+
vectorSearchString?: string;
|
|
1565
|
+
last?: number | false;
|
|
1566
|
+
include?: {
|
|
1567
|
+
id: string;
|
|
1568
|
+
withPreviousMessages?: number;
|
|
1569
|
+
withNextMessages?: number;
|
|
1570
|
+
}[];
|
|
1571
|
+
};
|
|
1572
|
+
threadConfig?: MemoryConfig;
|
|
1573
|
+
};
|
|
1574
|
+
type EvalRow = {
|
|
1575
|
+
input: string;
|
|
1576
|
+
output: string;
|
|
1577
|
+
result: MetricResult;
|
|
1578
|
+
agentName: string;
|
|
1579
|
+
createdAt: string;
|
|
1580
|
+
metricName: string;
|
|
1581
|
+
instructions: string;
|
|
1582
|
+
runId: string;
|
|
1583
|
+
globalRunId: string;
|
|
1584
|
+
testInfo?: TestInfo;
|
|
1585
|
+
};
|
|
1541
1586
|
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1587
|
+
declare const TABLE_WORKFLOW_SNAPSHOT = "mastra_workflow_snapshot";
|
|
1588
|
+
declare const TABLE_EVALS = "mastra_evals";
|
|
1589
|
+
declare const TABLE_MESSAGES = "mastra_messages";
|
|
1590
|
+
declare const TABLE_THREADS = "mastra_threads";
|
|
1591
|
+
declare const TABLE_TRACES = "mastra_traces";
|
|
1592
|
+
type TABLE_NAMES = typeof TABLE_WORKFLOW_SNAPSHOT | typeof TABLE_EVALS | typeof TABLE_MESSAGES | typeof TABLE_THREADS | typeof TABLE_TRACES;
|
|
1593
|
+
declare const TABLE_SCHEMAS: Record<TABLE_NAMES, Record<string, StorageColumn>>;
|
|
1594
|
+
|
|
1595
|
+
type MastraMessageV1 = {
|
|
1596
|
+
id: string;
|
|
1597
|
+
content: string | UserContent | AssistantContent | ToolContent;
|
|
1598
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
1599
|
+
createdAt: Date;
|
|
1600
|
+
threadId: string;
|
|
1601
|
+
resourceId: string;
|
|
1602
|
+
toolCallIds?: string[];
|
|
1603
|
+
toolCallArgs?: Record<string, unknown>[];
|
|
1604
|
+
toolNames?: string[];
|
|
1605
|
+
type: 'text' | 'tool-call' | 'tool-result';
|
|
1552
1606
|
};
|
|
1553
|
-
type
|
|
1554
|
-
|
|
1555
|
-
error: string | Error;
|
|
1556
|
-
payload: P;
|
|
1557
|
-
resumePayload?: R;
|
|
1558
|
-
suspendPayload?: S;
|
|
1559
|
-
startedAt: number;
|
|
1560
|
-
endedAt: number;
|
|
1561
|
-
suspendedAt?: number;
|
|
1562
|
-
resumedAt?: number;
|
|
1607
|
+
type MessageType = MastraMessageV2 & {
|
|
1608
|
+
threadId: string;
|
|
1563
1609
|
};
|
|
1564
|
-
type
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1610
|
+
type StorageThreadType = {
|
|
1611
|
+
id: string;
|
|
1612
|
+
title?: string;
|
|
1613
|
+
resourceId: string;
|
|
1614
|
+
createdAt: Date;
|
|
1615
|
+
updatedAt: Date;
|
|
1616
|
+
metadata?: Record<string, unknown>;
|
|
1570
1617
|
};
|
|
1571
|
-
type
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1618
|
+
type MessageResponse<T extends 'raw' | 'core_message'> = {
|
|
1619
|
+
raw: MastraMessageV1[];
|
|
1620
|
+
core_message: CoreMessage$1[];
|
|
1621
|
+
}[T];
|
|
1622
|
+
type MemoryConfig = {
|
|
1623
|
+
lastMessages?: number | false;
|
|
1624
|
+
semanticRecall?: boolean | {
|
|
1625
|
+
topK: number;
|
|
1626
|
+
messageRange: number | {
|
|
1627
|
+
before: number;
|
|
1628
|
+
after: number;
|
|
1629
|
+
};
|
|
1630
|
+
};
|
|
1631
|
+
workingMemory?: {
|
|
1632
|
+
enabled: boolean;
|
|
1633
|
+
template?: string;
|
|
1634
|
+
/** @deprecated The `use` option has been removed. Working memory always uses tool-call mode. */
|
|
1635
|
+
use?: never;
|
|
1636
|
+
};
|
|
1637
|
+
threads?: {
|
|
1638
|
+
generateTitle?: boolean;
|
|
1639
|
+
};
|
|
1579
1640
|
};
|
|
1580
|
-
type
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1641
|
+
type SharedMemoryConfig = {
|
|
1642
|
+
storage?: MastraStorage;
|
|
1643
|
+
options?: MemoryConfig;
|
|
1644
|
+
vector?: MastraVector | false;
|
|
1645
|
+
embedder?: EmbeddingModel<string>;
|
|
1646
|
+
processors?: MemoryProcessor[];
|
|
1585
1647
|
};
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1648
|
+
|
|
1649
|
+
type MastraMessageContentV2 = {
|
|
1650
|
+
format: 2;
|
|
1651
|
+
parts: UIMessage['parts'];
|
|
1652
|
+
experimental_attachments?: UIMessage['experimental_attachments'];
|
|
1653
|
+
content?: UIMessage['content'];
|
|
1654
|
+
toolInvocations?: UIMessage['toolInvocations'];
|
|
1655
|
+
reasoning?: UIMessage['reasoning'];
|
|
1656
|
+
annotations?: UIMessage['annotations'];
|
|
1589
1657
|
};
|
|
1590
|
-
type
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
} | {
|
|
1599
|
-
value: any;
|
|
1600
|
-
schema: z.ZodTypeAny;
|
|
1658
|
+
type MastraMessageV2 = {
|
|
1659
|
+
id: string;
|
|
1660
|
+
content: MastraMessageContentV2;
|
|
1661
|
+
role: 'user' | 'assistant';
|
|
1662
|
+
createdAt: Date;
|
|
1663
|
+
threadId?: string;
|
|
1664
|
+
resourceId?: string;
|
|
1665
|
+
type?: string;
|
|
1601
1666
|
};
|
|
1602
|
-
type
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1667
|
+
type MessageInput = UIMessage | Message | MastraMessageV1 | CoreMessage$1 | MastraMessageV2;
|
|
1668
|
+
type MessageSource = 'memory' | 'response' | 'user' | 'system';
|
|
1669
|
+
declare class MessageList {
|
|
1670
|
+
private messages;
|
|
1671
|
+
private systemMessages;
|
|
1672
|
+
private taggedSystemMessages;
|
|
1673
|
+
private memoryInfo;
|
|
1674
|
+
private memoryMessages;
|
|
1675
|
+
private newMessages;
|
|
1676
|
+
private responseMessages;
|
|
1677
|
+
private generateMessageId?;
|
|
1678
|
+
constructor({ threadId, resourceId, generateMessageId, }?: {
|
|
1679
|
+
threadId?: string;
|
|
1680
|
+
resourceId?: string;
|
|
1681
|
+
generateMessageId?: IDGenerator$1;
|
|
1682
|
+
});
|
|
1683
|
+
add(messages: string | string[] | MessageInput | MessageInput[], messageSource: MessageSource): this;
|
|
1684
|
+
getLatestUserContent(): string | null;
|
|
1685
|
+
get get(): {
|
|
1686
|
+
all: {
|
|
1687
|
+
mastra: () => MastraMessageV2[];
|
|
1688
|
+
v1: () => MastraMessageV1[];
|
|
1689
|
+
ui: () => UIMessage[];
|
|
1690
|
+
core: () => CoreMessage$1[];
|
|
1691
|
+
prompt: () => CoreMessage$1[];
|
|
1612
1692
|
};
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
payload?: Record<string, any>;
|
|
1628
|
-
error?: string | Error;
|
|
1693
|
+
remembered: {
|
|
1694
|
+
mastra: () => MastraMessageV2[];
|
|
1695
|
+
v1: () => MastraMessageV1[];
|
|
1696
|
+
ui: () => UIMessage[];
|
|
1697
|
+
core: () => CoreMessage$1[];
|
|
1698
|
+
};
|
|
1699
|
+
input: {
|
|
1700
|
+
mastra: () => MastraMessageV2[];
|
|
1701
|
+
v1: () => MastraMessageV1[];
|
|
1702
|
+
ui: () => UIMessage[];
|
|
1703
|
+
core: () => CoreMessage$1[];
|
|
1704
|
+
};
|
|
1705
|
+
response: {
|
|
1706
|
+
mastra: () => MastraMessageV2[];
|
|
1629
1707
|
};
|
|
1630
1708
|
};
|
|
1631
|
-
|
|
1709
|
+
private all;
|
|
1710
|
+
private remembered;
|
|
1711
|
+
private input;
|
|
1712
|
+
private response;
|
|
1713
|
+
drainUnsavedMessages(): MastraMessageV2[];
|
|
1714
|
+
getSystemMessages(tag?: string): CoreMessage$1[];
|
|
1715
|
+
addSystem(messages: CoreSystemMessage$1 | CoreSystemMessage$1[] | string | string[] | null, tag?: string): this;
|
|
1716
|
+
private convertToCoreMessages;
|
|
1717
|
+
private sanitizeUIMessages;
|
|
1718
|
+
private addOneSystem;
|
|
1719
|
+
private isDuplicateSystem;
|
|
1720
|
+
private static toUIMessage;
|
|
1721
|
+
private getMessageById;
|
|
1722
|
+
private shouldReplaceMessage;
|
|
1723
|
+
private addOne;
|
|
1724
|
+
private inputToMastraMessageV2;
|
|
1725
|
+
private lastCreatedAt?;
|
|
1726
|
+
private generateCreatedAt;
|
|
1727
|
+
private newMessageId;
|
|
1728
|
+
private mastraMessageV1ToMastraMessageV2;
|
|
1729
|
+
private hydrateMastraMessageV2Fields;
|
|
1730
|
+
private vercelUIMessageToMastraMessageV2;
|
|
1731
|
+
private vercelCoreMessageToMastraMessageV2;
|
|
1732
|
+
static isVercelUIMessage(msg: MessageInput): msg is UIMessage;
|
|
1733
|
+
static isVercelCoreMessage(msg: MessageInput): msg is CoreMessage$1;
|
|
1734
|
+
static isMastraMessage(msg: MessageInput): msg is MastraMessageV2 | MastraMessageV1;
|
|
1735
|
+
static isMastraMessageV1(msg: MessageInput): msg is MastraMessageV1;
|
|
1736
|
+
static isMastraMessageV2(msg: MessageInput): msg is MastraMessageV2;
|
|
1737
|
+
private static getRole;
|
|
1738
|
+
private static cacheKeyFromParts;
|
|
1739
|
+
private static coreContentToString;
|
|
1740
|
+
private static cacheKeyFromContent;
|
|
1741
|
+
private static messagesAreEqual;
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
type MemoryProcessorOpts = {
|
|
1745
|
+
systemMessage?: string;
|
|
1746
|
+
memorySystemMessage?: string;
|
|
1747
|
+
newMessages?: CoreMessage$1[];
|
|
1632
1748
|
};
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1749
|
+
/**
|
|
1750
|
+
* Interface for message processors that can filter or transform messages
|
|
1751
|
+
* before they're sent to the LLM.
|
|
1752
|
+
*/
|
|
1753
|
+
declare abstract class MemoryProcessor extends MastraBase {
|
|
1754
|
+
/**
|
|
1755
|
+
* Process a list of messages and return a filtered or transformed list.
|
|
1756
|
+
* @param messages The messages to process
|
|
1757
|
+
* @returns The processed messages
|
|
1758
|
+
*/
|
|
1759
|
+
process(messages: CoreMessage$1[], _opts: MemoryProcessorOpts): CoreMessage$1[];
|
|
1760
|
+
}
|
|
1761
|
+
declare const memoryDefaultOptions: {
|
|
1762
|
+
lastMessages: number;
|
|
1763
|
+
semanticRecall: false;
|
|
1764
|
+
threads: {
|
|
1765
|
+
generateTitle: false;
|
|
1766
|
+
};
|
|
1767
|
+
workingMemory: {
|
|
1768
|
+
enabled: false;
|
|
1769
|
+
template: string;
|
|
1770
|
+
};
|
|
1771
|
+
};
|
|
1772
|
+
/**
|
|
1773
|
+
* Abstract Memory class that defines the interface for storing and retrieving
|
|
1774
|
+
* conversation threads and messages.
|
|
1775
|
+
*/
|
|
1776
|
+
declare abstract class MastraMemory extends MastraBase {
|
|
1777
|
+
MAX_CONTEXT_TOKENS?: number;
|
|
1778
|
+
protected _storage?: MastraStorage;
|
|
1779
|
+
vector?: MastraVector;
|
|
1780
|
+
embedder?: EmbeddingModel<string>;
|
|
1781
|
+
private processors;
|
|
1782
|
+
protected threadConfig: MemoryConfig;
|
|
1783
|
+
constructor(config: {
|
|
1784
|
+
name: string;
|
|
1785
|
+
} & SharedMemoryConfig);
|
|
1786
|
+
protected _hasOwnStorage: boolean;
|
|
1787
|
+
get hasOwnStorage(): boolean;
|
|
1788
|
+
get storage(): MastraStorage;
|
|
1789
|
+
setStorage(storage: MastraStorage): void;
|
|
1790
|
+
setVector(vector: MastraVector): void;
|
|
1791
|
+
setEmbedder(embedder: EmbeddingModel<string>): void;
|
|
1792
|
+
/**
|
|
1793
|
+
* Get a system message to inject into the conversation.
|
|
1794
|
+
* This will be called before each conversation turn.
|
|
1795
|
+
* Implementations can override this to inject custom system messages.
|
|
1796
|
+
*/
|
|
1797
|
+
getSystemMessage(_input: {
|
|
1798
|
+
threadId: string;
|
|
1799
|
+
memoryConfig?: MemoryConfig;
|
|
1800
|
+
}): Promise<string | null>;
|
|
1801
|
+
/**
|
|
1802
|
+
* Get tools that should be available to the agent.
|
|
1803
|
+
* This will be called when converting tools for the agent.
|
|
1804
|
+
* Implementations can override this to provide additional tools.
|
|
1805
|
+
*/
|
|
1806
|
+
getTools(_config?: MemoryConfig): Record<string, CoreTool>;
|
|
1807
|
+
protected createEmbeddingIndex(dimensions?: number): Promise<{
|
|
1808
|
+
indexName: string;
|
|
1809
|
+
}>;
|
|
1810
|
+
getMergedThreadConfig(config?: MemoryConfig): MemoryConfig;
|
|
1811
|
+
/**
|
|
1812
|
+
* Apply all configured message processors to a list of messages.
|
|
1813
|
+
* @param messages The messages to process
|
|
1814
|
+
* @returns The processed messages
|
|
1815
|
+
*/
|
|
1816
|
+
private applyProcessors;
|
|
1817
|
+
processMessages({ messages, processors, ...opts }: {
|
|
1818
|
+
messages: CoreMessage$1[];
|
|
1819
|
+
processors?: MemoryProcessor[];
|
|
1820
|
+
} & MemoryProcessorOpts): CoreMessage$1[];
|
|
1821
|
+
abstract rememberMessages({ threadId, resourceId, vectorMessageSearch, config, }: {
|
|
1822
|
+
threadId: string;
|
|
1823
|
+
resourceId?: string;
|
|
1824
|
+
vectorMessageSearch?: string;
|
|
1825
|
+
config?: MemoryConfig;
|
|
1826
|
+
}): Promise<{
|
|
1827
|
+
messages: MastraMessageV1[];
|
|
1828
|
+
messagesV2: MastraMessageV2[];
|
|
1829
|
+
}>;
|
|
1830
|
+
estimateTokens(text: string): number;
|
|
1831
|
+
/**
|
|
1832
|
+
* Retrieves a specific thread by its ID
|
|
1833
|
+
* @param threadId - The unique identifier of the thread
|
|
1834
|
+
* @returns Promise resolving to the thread or null if not found
|
|
1835
|
+
*/
|
|
1836
|
+
abstract getThreadById({ threadId }: {
|
|
1837
|
+
threadId: string;
|
|
1838
|
+
}): Promise<StorageThreadType | null>;
|
|
1839
|
+
abstract getThreadsByResourceId({ resourceId }: {
|
|
1840
|
+
resourceId: string;
|
|
1841
|
+
}): Promise<StorageThreadType[]>;
|
|
1842
|
+
/**
|
|
1843
|
+
* Saves or updates a thread
|
|
1844
|
+
* @param thread - The thread data to save
|
|
1845
|
+
* @returns Promise resolving to the saved thread
|
|
1846
|
+
*/
|
|
1847
|
+
abstract saveThread({ thread, memoryConfig, }: {
|
|
1848
|
+
thread: StorageThreadType;
|
|
1849
|
+
memoryConfig?: MemoryConfig;
|
|
1850
|
+
}): Promise<StorageThreadType>;
|
|
1851
|
+
/**
|
|
1852
|
+
* Saves messages to a thread
|
|
1853
|
+
* @param messages - Array of messages to save
|
|
1854
|
+
* @returns Promise resolving to the saved messages
|
|
1855
|
+
*/
|
|
1856
|
+
abstract saveMessages({ messages, memoryConfig, }: {
|
|
1857
|
+
messages: (MastraMessageV1 | MastraMessageV2)[];
|
|
1858
|
+
memoryConfig: MemoryConfig | undefined;
|
|
1859
|
+
}): Promise<MastraMessageV2[]>;
|
|
1860
|
+
/**
|
|
1861
|
+
* Retrieves all messages for a specific thread
|
|
1862
|
+
* @param threadId - The unique identifier of the thread
|
|
1863
|
+
* @returns Promise resolving to array of messages and uiMessages
|
|
1864
|
+
*/
|
|
1865
|
+
abstract query({ threadId, resourceId, selectBy, }: StorageGetMessagesArg): Promise<{
|
|
1866
|
+
messages: MastraMessageV1[];
|
|
1867
|
+
uiMessages: UIMessage[];
|
|
1868
|
+
}>;
|
|
1869
|
+
/**
|
|
1870
|
+
* Helper method to create a new thread
|
|
1871
|
+
* @param title - Optional title for the thread
|
|
1872
|
+
* @param metadata - Optional metadata for the thread
|
|
1873
|
+
* @returns Promise resolving to the created thread
|
|
1874
|
+
*/
|
|
1875
|
+
createThread({ threadId, resourceId, title, metadata, memoryConfig, }: {
|
|
1876
|
+
resourceId: string;
|
|
1877
|
+
threadId?: string;
|
|
1878
|
+
title?: string;
|
|
1879
|
+
metadata?: Record<string, unknown>;
|
|
1880
|
+
memoryConfig?: MemoryConfig;
|
|
1881
|
+
}): Promise<StorageThreadType>;
|
|
1882
|
+
/**
|
|
1883
|
+
* Helper method to delete a thread
|
|
1884
|
+
* @param threadId - the id of the thread to delete
|
|
1885
|
+
*/
|
|
1886
|
+
abstract deleteThread(threadId: string): Promise<void>;
|
|
1887
|
+
/**
|
|
1888
|
+
* Helper method to add a single message to a thread
|
|
1889
|
+
* @param threadId - The thread to add the message to
|
|
1890
|
+
* @param content - The message content
|
|
1891
|
+
* @param role - The role of the message sender
|
|
1892
|
+
* @param type - The type of the message
|
|
1893
|
+
* @param toolNames - Optional array of tool names that were called
|
|
1894
|
+
* @param toolCallArgs - Optional array of tool call arguments
|
|
1895
|
+
* @param toolCallIds - Optional array of tool call ids
|
|
1896
|
+
* @returns Promise resolving to the saved message
|
|
1897
|
+
* @deprecated use saveMessages instead
|
|
1898
|
+
*/
|
|
1899
|
+
addMessage({ threadId, resourceId, config, content, role, type, toolNames, toolCallArgs, toolCallIds, }: {
|
|
1900
|
+
threadId: string;
|
|
1901
|
+
resourceId: string;
|
|
1902
|
+
config?: MemoryConfig;
|
|
1903
|
+
content: UserContent | AssistantContent;
|
|
1904
|
+
role: 'user' | 'assistant';
|
|
1905
|
+
type: 'text' | 'tool-call' | 'tool-result';
|
|
1906
|
+
toolNames?: string[];
|
|
1907
|
+
toolCallArgs?: Record<string, unknown>[];
|
|
1908
|
+
toolCallIds?: string[];
|
|
1909
|
+
}): Promise<MastraMessageV1>;
|
|
1910
|
+
/**
|
|
1911
|
+
* Generates a unique identifier
|
|
1912
|
+
* @returns A unique string ID
|
|
1913
|
+
*/
|
|
1914
|
+
generateId(): string;
|
|
1643
1915
|
}
|
|
1644
1916
|
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
steps: StepFlowEntry[];
|
|
1651
|
-
}
|
|
1652
|
-
/**
|
|
1653
|
-
* Execution engine abstract class for building and executing workflow graphs
|
|
1654
|
-
* Providers will implement this class to provide their own execution logic
|
|
1655
|
-
*/
|
|
1656
|
-
declare abstract class ExecutionEngine extends MastraBase {
|
|
1657
|
-
protected mastra?: Mastra;
|
|
1658
|
-
constructor({ mastra }: {
|
|
1659
|
-
mastra?: Mastra;
|
|
1917
|
+
declare class MastraLLMBase extends MastraBase {
|
|
1918
|
+
#private;
|
|
1919
|
+
constructor({ name, model }: {
|
|
1920
|
+
name: string;
|
|
1921
|
+
model: LanguageModel$1;
|
|
1660
1922
|
});
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
resume?: {
|
|
1674
|
-
steps: string[];
|
|
1675
|
-
stepResults: Record<string, StepResult<any, any, any, any>>;
|
|
1676
|
-
resumePayload: any;
|
|
1677
|
-
resumePath: number[];
|
|
1678
|
-
};
|
|
1679
|
-
emitter: {
|
|
1680
|
-
emit: (event: string, data: any) => Promise<void>;
|
|
1681
|
-
};
|
|
1682
|
-
runtimeContext: RuntimeContext;
|
|
1683
|
-
retryConfig?: {
|
|
1684
|
-
attempts?: number;
|
|
1685
|
-
delay?: number;
|
|
1686
|
-
};
|
|
1687
|
-
}): Promise<TOutput>;
|
|
1923
|
+
getProvider(): string;
|
|
1924
|
+
getModelId(): string;
|
|
1925
|
+
getModel(): ai.LanguageModelV1;
|
|
1926
|
+
convertToMessages(messages: string | string[] | CoreMessage$1[]): CoreMessage$1[];
|
|
1927
|
+
__registerPrimitives(p: MastraPrimitives): void;
|
|
1928
|
+
__registerMastra(p: Mastra): void;
|
|
1929
|
+
__text<Z extends ZodSchema | JSONSchema7 | undefined>(input: LLMTextOptions<Z>): Promise<GenerateTextResult<any, any>>;
|
|
1930
|
+
__textObject<T extends ZodSchema | JSONSchema7 | undefined>(input: LLMTextObjectOptions<T>): Promise<GenerateObjectResult<T>>;
|
|
1931
|
+
generate<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], options: LLMStreamOptions<Z>): Promise<GenerateReturn<Z>>;
|
|
1932
|
+
__stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(input: LLMInnerStreamOptions<Z>): Promise<StreamTextResult<any, any>>;
|
|
1933
|
+
__streamObject<T extends ZodSchema | JSONSchema7 | undefined>(input: LLMStreamObjectOptions<T>): Promise<StreamObjectResult<DeepPartial<T>, T, never>>;
|
|
1934
|
+
stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], options: LLMStreamOptions<Z>): Promise<StreamReturn<Z>>;
|
|
1688
1935
|
}
|
|
1689
1936
|
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
id: string;
|
|
1710
|
-
fn: string;
|
|
1711
|
-
};
|
|
1712
|
-
loopType: 'dowhile' | 'dountil';
|
|
1937
|
+
declare function createMockModel({ objectGenerationMode, mockText, spyGenerate, spyStream, }: {
|
|
1938
|
+
objectGenerationMode?: 'json';
|
|
1939
|
+
mockText: string | Record<string, any>;
|
|
1940
|
+
spyGenerate?: (props: any) => void;
|
|
1941
|
+
spyStream?: (props: any) => void;
|
|
1942
|
+
}): MockLanguageModelV1;
|
|
1943
|
+
|
|
1944
|
+
type LanguageModel = MastraLanguageModel;
|
|
1945
|
+
type CoreMessage = CoreMessage$1;
|
|
1946
|
+
type CoreSystemMessage = CoreSystemMessage$1;
|
|
1947
|
+
type CoreAssistantMessage = CoreAssistantMessage$1;
|
|
1948
|
+
type CoreUserMessage = CoreUserMessage$1;
|
|
1949
|
+
type CoreToolMessage = CoreToolMessage$1;
|
|
1950
|
+
type EmbedResult<T> = EmbedResult$1<T>;
|
|
1951
|
+
type EmbedManyResult<T> = EmbedManyResult$1<T>;
|
|
1952
|
+
type BaseStructuredOutputType = 'string' | 'number' | 'boolean' | 'date';
|
|
1953
|
+
type StructuredOutputType = 'array' | 'string' | 'number' | 'object' | 'boolean' | 'date';
|
|
1954
|
+
type StructuredOutputArrayItem = {
|
|
1955
|
+
type: BaseStructuredOutputType;
|
|
1713
1956
|
} | {
|
|
1714
|
-
type: '
|
|
1715
|
-
|
|
1716
|
-
opts: {
|
|
1717
|
-
concurrency: number;
|
|
1718
|
-
};
|
|
1719
|
-
};
|
|
1720
|
-
type SerializedStep = Pick<Step, 'id' | 'description'> & {
|
|
1721
|
-
component?: string;
|
|
1722
|
-
serializedStepFlow?: SerializedStepFlowEntry[];
|
|
1723
|
-
mapConfig?: string;
|
|
1957
|
+
type: 'object';
|
|
1958
|
+
items: StructuredOutput;
|
|
1724
1959
|
};
|
|
1725
|
-
type
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
} | {
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
} | {
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
serializedConditions: {
|
|
1735
|
-
id: string;
|
|
1736
|
-
fn: string;
|
|
1737
|
-
}[];
|
|
1738
|
-
} | {
|
|
1739
|
-
type: 'loop';
|
|
1740
|
-
step: SerializedStep;
|
|
1741
|
-
serializedCondition: {
|
|
1742
|
-
id: string;
|
|
1743
|
-
fn: string;
|
|
1744
|
-
};
|
|
1745
|
-
loopType: 'dowhile' | 'dountil';
|
|
1746
|
-
} | {
|
|
1747
|
-
type: 'foreach';
|
|
1748
|
-
step: SerializedStep;
|
|
1749
|
-
opts: {
|
|
1750
|
-
concurrency: number;
|
|
1960
|
+
type StructuredOutput = {
|
|
1961
|
+
[key: string]: {
|
|
1962
|
+
type: BaseStructuredOutputType;
|
|
1963
|
+
} | {
|
|
1964
|
+
type: 'object';
|
|
1965
|
+
items: StructuredOutput;
|
|
1966
|
+
} | {
|
|
1967
|
+
type: 'array';
|
|
1968
|
+
items: StructuredOutputArrayItem;
|
|
1751
1969
|
};
|
|
1752
1970
|
};
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
}
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1971
|
+
type GenerateReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? GenerateTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown> : GenerateObjectResult<Z extends ZodSchema ? z.infer<Z> : unknown>;
|
|
1972
|
+
type StreamReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? StreamTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown> : StreamObjectResult<any, Z extends ZodSchema ? z.infer<Z> : unknown, any>;
|
|
1973
|
+
type OutputType = StructuredOutput | ZodSchema | JSONSchema7 | undefined;
|
|
1974
|
+
type GenerateTextOptions = Parameters<typeof generateText>[0];
|
|
1975
|
+
type StreamTextOptions = Parameters<typeof streamText>[0];
|
|
1976
|
+
type GenerateObjectOptions = Parameters<typeof generateObject>[0];
|
|
1977
|
+
type StreamObjectOptions = Parameters<typeof streamObject>[0];
|
|
1978
|
+
type MastraCustomLLMOptionsKeys = 'messages' | 'tools' | 'model' | 'onStepFinish' | 'experimental_output' | 'experimental_telemetry' | 'messages' | 'onFinish' | 'output';
|
|
1979
|
+
type DefaultLLMTextOptions = Omit<GenerateTextOptions, MastraCustomLLMOptionsKeys>;
|
|
1980
|
+
type DefaultLLMTextObjectOptions = Omit<GenerateObjectOptions, MastraCustomLLMOptionsKeys>;
|
|
1981
|
+
type DefaultLLMStreamOptions = Omit<StreamTextOptions, MastraCustomLLMOptionsKeys>;
|
|
1982
|
+
type DefaultLLMStreamObjectOptions = Omit<StreamObjectOptions, MastraCustomLLMOptionsKeys>;
|
|
1983
|
+
type MastraCustomLLMOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
|
|
1984
|
+
tools?: Record<string, CoreTool>;
|
|
1985
|
+
onStepFinish?: (step: unknown) => Promise<void> | void;
|
|
1986
|
+
experimental_output?: Z;
|
|
1987
|
+
telemetry?: TelemetrySettings;
|
|
1988
|
+
threadId?: string;
|
|
1989
|
+
resourceId?: string;
|
|
1990
|
+
runtimeContext: RuntimeContext;
|
|
1991
|
+
} & Run$1;
|
|
1992
|
+
type LLMTextOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
|
|
1993
|
+
messages: UIMessage[] | CoreMessage[];
|
|
1994
|
+
} & MastraCustomLLMOptions<Z> & DefaultLLMTextOptions;
|
|
1995
|
+
type LLMTextObjectOptions<T extends ZodSchema | JSONSchema7 | undefined = undefined> = LLMTextOptions<T> & DefaultLLMTextObjectOptions & {
|
|
1996
|
+
structuredOutput: JSONSchema7 | z.ZodType<T> | StructuredOutput;
|
|
1997
|
+
};
|
|
1998
|
+
type LLMStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
|
|
1999
|
+
output?: OutputType | Z;
|
|
2000
|
+
onFinish?: (result: string) => Promise<void> | void;
|
|
2001
|
+
} & MastraCustomLLMOptions<Z> & DefaultLLMStreamOptions;
|
|
2002
|
+
type LLMInnerStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
|
|
2003
|
+
messages: UIMessage[] | CoreMessage[];
|
|
2004
|
+
onFinish?: (result: string) => Promise<void> | void;
|
|
2005
|
+
} & MastraCustomLLMOptions<Z> & DefaultLLMStreamOptions;
|
|
2006
|
+
type LLMStreamObjectOptions<T extends ZodSchema | JSONSchema7 | undefined = undefined> = {
|
|
2007
|
+
structuredOutput: JSONSchema7 | z.ZodType<T> | StructuredOutput;
|
|
2008
|
+
} & LLMInnerStreamOptions<T> & DefaultLLMStreamObjectOptions;
|
|
2009
|
+
|
|
2010
|
+
type VoiceEventType = 'speaking' | 'writing' | 'error' | string;
|
|
2011
|
+
interface VoiceEventMap {
|
|
2012
|
+
speaker: NodeJS.ReadableStream;
|
|
2013
|
+
speaking: {
|
|
2014
|
+
audio?: string;
|
|
1794
2015
|
};
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
[K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]['outputSchema'] extends undefined ? StepResult<unknown, unknown, unknown, unknown> : StepResult<z.infer<NonNullable<StepsRecord<TSteps>[K]['inputSchema']>>, z.infer<NonNullable<StepsRecord<TSteps>[K]['resumeSchema']>>, z.infer<NonNullable<StepsRecord<TSteps>[K]['suspendSchema']>>, z.infer<NonNullable<StepsRecord<TSteps>[K]['outputSchema']>>>;
|
|
2016
|
+
writing: {
|
|
2017
|
+
text: string;
|
|
2018
|
+
role: 'assistant' | 'user';
|
|
1799
2019
|
};
|
|
1800
|
-
error:
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
[K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]['outputSchema'] extends undefined ? StepResult<unknown, unknown, unknown, unknown> : StepResult<z.infer<NonNullable<StepsRecord<TSteps>[K]['inputSchema']>>, z.infer<NonNullable<StepsRecord<TSteps>[K]['resumeSchema']>>, z.infer<NonNullable<StepsRecord<TSteps>[K]['suspendSchema']>>, z.infer<NonNullable<StepsRecord<TSteps>[K]['outputSchema']>>>;
|
|
2020
|
+
error: {
|
|
2021
|
+
message: string;
|
|
2022
|
+
code?: string;
|
|
2023
|
+
details?: unknown;
|
|
1805
2024
|
};
|
|
1806
|
-
|
|
1807
|
-
}
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
2025
|
+
[key: string]: unknown;
|
|
2026
|
+
}
|
|
2027
|
+
interface BuiltInModelConfig {
|
|
2028
|
+
name: string;
|
|
2029
|
+
apiKey?: string;
|
|
2030
|
+
}
|
|
2031
|
+
interface VoiceConfig<T = unknown> {
|
|
2032
|
+
listeningModel?: BuiltInModelConfig;
|
|
2033
|
+
speechModel?: BuiltInModelConfig;
|
|
2034
|
+
speaker?: string;
|
|
2035
|
+
name?: string;
|
|
2036
|
+
realtimeConfig?: {
|
|
2037
|
+
model?: string;
|
|
2038
|
+
apiKey?: string;
|
|
2039
|
+
options?: T;
|
|
1819
2040
|
};
|
|
1820
|
-
}
|
|
1821
|
-
declare class
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
protected stepFlow: StepFlowEntry[];
|
|
1830
|
-
protected serializedStepFlow: SerializedStepFlowEntry[];
|
|
1831
|
-
protected executionEngine: ExecutionEngine;
|
|
1832
|
-
protected executionGraph: ExecutionGraph;
|
|
1833
|
-
protected retryConfig: {
|
|
1834
|
-
attempts?: number;
|
|
1835
|
-
delay?: number;
|
|
2041
|
+
}
|
|
2042
|
+
declare abstract class MastraVoice<TOptions = unknown, TSpeakOptions = unknown, TListenOptions = unknown, TTools extends ToolsInput = ToolsInput, TEventArgs extends VoiceEventMap = VoiceEventMap, TSpeakerMetadata = unknown> extends MastraBase {
|
|
2043
|
+
protected listeningModel?: BuiltInModelConfig;
|
|
2044
|
+
protected speechModel?: BuiltInModelConfig;
|
|
2045
|
+
protected speaker?: string;
|
|
2046
|
+
protected realtimeConfig?: {
|
|
2047
|
+
model?: string;
|
|
2048
|
+
apiKey?: string;
|
|
2049
|
+
options?: TOptions;
|
|
1836
2050
|
};
|
|
1837
|
-
constructor({
|
|
1838
|
-
|
|
1839
|
-
get mastra(): Mastra<Record<string, Agent<any, ToolsInput, Record<string, Metric>>>, Record<string, LegacyWorkflow<LegacyStep<string, any, any, StepExecutionContext<any, WorkflowContext<any, LegacyStep<string, any, any, any>[], Record<string, any>>>>[], string, any, any>>, Record<string, Workflow<Step<string, any, any, any, any>[], string, z.ZodType<any, z.ZodTypeDef, any>, z.ZodType<any, z.ZodTypeDef, any>, z.ZodType<any, z.ZodTypeDef, any>>>, Record<string, MastraVector>, Record<string, MastraTTS>, IMastraLogger, Record<string, AgentNetwork>, Record<string, MCPServerBase>> | undefined;
|
|
1840
|
-
__registerMastra(mastra: Mastra): void;
|
|
1841
|
-
__registerPrimitives(p: MastraPrimitives): void;
|
|
1842
|
-
setStepFlow(stepFlow: StepFlowEntry[]): void;
|
|
2051
|
+
constructor({ listeningModel, speechModel, speaker, realtimeConfig, name }?: VoiceConfig<TOptions>);
|
|
2052
|
+
traced<T extends Function>(method: T, methodName: string): T;
|
|
1843
2053
|
/**
|
|
1844
|
-
*
|
|
1845
|
-
* @param
|
|
1846
|
-
* @
|
|
2054
|
+
* Convert text to speech
|
|
2055
|
+
* @param input Text or text stream to convert to speech
|
|
2056
|
+
* @param options Speech options including speaker and provider-specific options
|
|
2057
|
+
* @returns Audio stream
|
|
1847
2058
|
*/
|
|
1848
|
-
then<TStepInputSchema extends TPrevSchema, TStepId extends string, TSchemaOut extends z.ZodType<any>>(step: Step<TStepId, TStepInputSchema, TSchemaOut, any, any>): Workflow<TSteps, TWorkflowId, TInput, TOutput, TSchemaOut>;
|
|
1849
|
-
map<TSteps extends Step<string, any, any>[], TMapping extends {
|
|
1850
|
-
[K in keyof TMapping]: {
|
|
1851
|
-
step: TSteps[number] | TSteps[number][];
|
|
1852
|
-
path: PathsToStringProps<ExtractSchemaType<ExtractSchemaFromStep<TSteps[number], 'outputSchema'>>> | '.';
|
|
1853
|
-
} | {
|
|
1854
|
-
value: any;
|
|
1855
|
-
schema: z.ZodTypeAny;
|
|
1856
|
-
} | {
|
|
1857
|
-
initData: TSteps[number];
|
|
1858
|
-
path: PathsToStringProps<ExtractSchemaType<ExtractSchemaFromStep<TSteps[number], 'inputSchema'>>> | '.';
|
|
1859
|
-
} | {
|
|
1860
|
-
runtimeContextPath: string;
|
|
1861
|
-
schema: z.ZodTypeAny;
|
|
1862
|
-
} | DynamicMapping<TPrevSchema, z.ZodTypeAny>;
|
|
1863
|
-
}>(mappingConfig: TMapping | ExecuteFunction<z.infer<TPrevSchema>, any, any, any>): Workflow<TSteps, TWorkflowId, TInput, TOutput, any>;
|
|
1864
|
-
parallel<TParallelSteps extends Step<string, TPrevSchema, any, any, any>[]>(steps: TParallelSteps): Workflow<TSteps, TWorkflowId, TInput, TOutput, z.ZodObject<{ [K in keyof StepsRecord<TParallelSteps>]: StepsRecord<TParallelSteps>[K]["outputSchema"]["path"]; }, any, z.ZodTypeAny>>;
|
|
1865
|
-
branch<TBranchSteps extends Array<[
|
|
1866
|
-
ExecuteFunction<z.infer<TPrevSchema>, any, any, any>,
|
|
1867
|
-
Step<string, TPrevSchema, any, any, any>
|
|
1868
|
-
]>>(steps: TBranchSteps): Workflow<TSteps, TWorkflowId, TInput, TOutput, z.ZodObject<{ [K in keyof StepsRecord<{ [K_1 in keyof TBranchSteps]: TBranchSteps[K_1][1]; }[number][]>]: StepsRecord<{ [K_1 in keyof TBranchSteps]: TBranchSteps[K_1][1]; }[number][]>[K]["outputSchema"]; }, any, z.ZodTypeAny>>;
|
|
1869
|
-
dowhile<TStepInputSchema extends TPrevSchema, TStepId extends string, TSchemaOut extends z.ZodType<any>>(step: Step<TStepId, TStepInputSchema, TSchemaOut, any, any>, condition: ExecuteFunction<z.infer<TSchemaOut>, any, any, any>): Workflow<TSteps, TWorkflowId, TInput, TOutput, TSchemaOut>;
|
|
1870
|
-
dountil<TStepInputSchema extends TPrevSchema, TStepId extends string, TSchemaOut extends z.ZodType<any>>(step: Step<TStepId, TStepInputSchema, TSchemaOut, any, any>, condition: ExecuteFunction<z.infer<TSchemaOut>, any, any, any>): Workflow<TSteps, TWorkflowId, TInput, TOutput, TSchemaOut>;
|
|
1871
|
-
foreach<TPrevIsArray extends TPrevSchema extends z.ZodArray<any> ? true : false, TStepInputSchema extends TPrevSchema extends z.ZodArray<infer TElement> ? TElement : never, TStepId extends string, TSchemaOut extends z.ZodType<any>>(step: TPrevIsArray extends true ? Step<TStepId, TStepInputSchema, TSchemaOut, any, any> : 'Previous step must return an array type', opts?: {
|
|
1872
|
-
concurrency: number;
|
|
1873
|
-
}): Workflow<TSteps, TWorkflowId, TInput, TOutput, z.ZodArray<TSchemaOut>>;
|
|
1874
2059
|
/**
|
|
1875
|
-
*
|
|
1876
|
-
* @
|
|
2060
|
+
* Convert text to speech
|
|
2061
|
+
* @param input Text or text stream to convert to speech
|
|
2062
|
+
* @param options Speech options including speaker and provider-specific options
|
|
2063
|
+
* @returns Audio stream or void if in chat mode
|
|
1877
2064
|
*/
|
|
1878
|
-
|
|
2065
|
+
abstract speak(input: string | NodeJS.ReadableStream, options?: {
|
|
2066
|
+
speaker?: string;
|
|
2067
|
+
} & TSpeakOptions): Promise<NodeJS.ReadableStream | void>;
|
|
1879
2068
|
/**
|
|
1880
|
-
*
|
|
1881
|
-
*
|
|
1882
|
-
* @
|
|
2069
|
+
* Convert speech to text
|
|
2070
|
+
* @param audioStream Audio stream to transcribe
|
|
2071
|
+
* @param options Provider-specific transcription options
|
|
2072
|
+
* @returns Text or text stream
|
|
1883
2073
|
*/
|
|
1884
|
-
commit(): Workflow<TSteps, TWorkflowId, TInput, TOutput, TOutput>;
|
|
1885
|
-
get stepGraph(): StepFlowEntry[];
|
|
1886
|
-
get serializedStepGraph(): SerializedStepFlowEntry[];
|
|
1887
2074
|
/**
|
|
1888
|
-
*
|
|
1889
|
-
* @param
|
|
1890
|
-
* @
|
|
2075
|
+
* Convert speech to text
|
|
2076
|
+
* @param audioStream Audio stream to transcribe
|
|
2077
|
+
* @param options Provider-specific transcription options
|
|
2078
|
+
* @returns Text, text stream, or void if in chat mode
|
|
1891
2079
|
*/
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
2080
|
+
abstract listen(audioStream: NodeJS.ReadableStream | unknown, // Allow other audio input types for OpenAI realtime API
|
|
2081
|
+
options?: TListenOptions): Promise<string | NodeJS.ReadableStream | void>;
|
|
2082
|
+
updateConfig(_options: Record<string, unknown>): void;
|
|
2083
|
+
/**
|
|
2084
|
+
* Initializes a WebSocket or WebRTC connection for real-time communication
|
|
2085
|
+
* @returns Promise that resolves when the connection is established
|
|
2086
|
+
*/
|
|
2087
|
+
connect(_options?: Record<string, unknown>): Promise<void>;
|
|
2088
|
+
/**
|
|
2089
|
+
* Relay audio data to the voice provider for real-time processing
|
|
2090
|
+
* @param audioData Audio data to relay
|
|
2091
|
+
*/
|
|
2092
|
+
send(_audioData: NodeJS.ReadableStream | Int16Array): Promise<void>;
|
|
2093
|
+
/**
|
|
2094
|
+
* Trigger voice providers to respond
|
|
2095
|
+
*/
|
|
2096
|
+
answer(_options?: Record<string, unknown>): Promise<void>;
|
|
2097
|
+
/**
|
|
2098
|
+
* Equip the voice provider with instructions
|
|
2099
|
+
* @param instructions Instructions to add
|
|
2100
|
+
*/
|
|
2101
|
+
addInstructions(_instructions?: string): void;
|
|
2102
|
+
/**
|
|
2103
|
+
* Equip the voice provider with tools
|
|
2104
|
+
* @param tools Array of tools to add
|
|
2105
|
+
*/
|
|
2106
|
+
addTools(_tools: TTools): void;
|
|
2107
|
+
/**
|
|
2108
|
+
* Disconnect from the WebSocket or WebRTC connection
|
|
2109
|
+
*/
|
|
2110
|
+
close(): void;
|
|
2111
|
+
/**
|
|
2112
|
+
* Register an event listener
|
|
2113
|
+
* @param event Event name (e.g., 'speaking', 'writing', 'error')
|
|
2114
|
+
* @param callback Callback function that receives event data
|
|
2115
|
+
*/
|
|
2116
|
+
on<E extends VoiceEventType>(_event: E, _callback: (data: E extends keyof TEventArgs ? TEventArgs[E] : unknown) => void): void;
|
|
2117
|
+
/**
|
|
2118
|
+
* Remove an event listener
|
|
2119
|
+
* @param event Event name (e.g., 'speaking', 'writing', 'error')
|
|
2120
|
+
* @param callback Callback function to remove
|
|
2121
|
+
*/
|
|
2122
|
+
off<E extends VoiceEventType>(_event: E, _callback: (data: E extends keyof TEventArgs ? TEventArgs[E] : unknown) => void): void;
|
|
2123
|
+
/**
|
|
2124
|
+
* Get available speakers/voices
|
|
2125
|
+
* @returns Array of available voice IDs and their metadata
|
|
2126
|
+
*/
|
|
2127
|
+
getSpeakers(): Promise<Array<{
|
|
2128
|
+
voiceId: string;
|
|
2129
|
+
} & TSpeakerMetadata>>;
|
|
1919
2130
|
}
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
2131
|
+
|
|
2132
|
+
declare class CompositeVoice extends MastraVoice<unknown, unknown, unknown, ToolsInput, VoiceEventMap> {
|
|
2133
|
+
protected speakProvider?: MastraVoice;
|
|
2134
|
+
protected listenProvider?: MastraVoice;
|
|
2135
|
+
protected realtimeProvider?: MastraVoice;
|
|
2136
|
+
constructor({ input, output, realtime, speakProvider, listenProvider, realtimeProvider, }: {
|
|
2137
|
+
/** @deprecated use output instead */
|
|
2138
|
+
speakProvider?: MastraVoice;
|
|
2139
|
+
/** @deprecated use input instead */
|
|
2140
|
+
listenProvider?: MastraVoice;
|
|
2141
|
+
/** @deprecated use realtime instead */
|
|
2142
|
+
realtimeProvider?: MastraVoice;
|
|
2143
|
+
input?: MastraVoice;
|
|
2144
|
+
output?: MastraVoice;
|
|
2145
|
+
realtime?: MastraVoice;
|
|
2146
|
+
});
|
|
1926
2147
|
/**
|
|
1927
|
-
*
|
|
2148
|
+
* Convert text to speech using the configured provider
|
|
2149
|
+
* @param input Text or text stream to convert to speech
|
|
2150
|
+
* @param options Speech options including speaker and provider-specific options
|
|
2151
|
+
* @returns Audio stream or void if in realtime mode
|
|
1928
2152
|
*/
|
|
1929
|
-
|
|
2153
|
+
speak(input: string | NodeJS.ReadableStream, options?: {
|
|
2154
|
+
speaker?: string;
|
|
2155
|
+
} & any): Promise<NodeJS.ReadableStream | void>;
|
|
2156
|
+
listen(audioStream: NodeJS.ReadableStream, options?: any): Promise<string | void | NodeJS.ReadableStream>;
|
|
2157
|
+
getSpeakers(): Promise<{
|
|
2158
|
+
voiceId: string;
|
|
2159
|
+
}[]>;
|
|
2160
|
+
updateConfig(options: Record<string, unknown>): void;
|
|
1930
2161
|
/**
|
|
1931
|
-
*
|
|
2162
|
+
* Initializes a WebSocket or WebRTC connection for real-time communication
|
|
2163
|
+
* @returns Promise that resolves when the connection is established
|
|
1932
2164
|
*/
|
|
1933
|
-
|
|
2165
|
+
connect(options?: Record<string, unknown>): Promise<void>;
|
|
1934
2166
|
/**
|
|
1935
|
-
*
|
|
2167
|
+
* Relay audio data to the voice provider for real-time processing
|
|
2168
|
+
* @param audioData Audio data to send
|
|
1936
2169
|
*/
|
|
1937
|
-
|
|
2170
|
+
send(audioData: NodeJS.ReadableStream | Int16Array): Promise<void>;
|
|
1938
2171
|
/**
|
|
1939
|
-
*
|
|
2172
|
+
* Trigger voice providers to respond
|
|
1940
2173
|
*/
|
|
1941
|
-
|
|
2174
|
+
answer(options?: Record<string, unknown>): Promise<void>;
|
|
1942
2175
|
/**
|
|
1943
|
-
*
|
|
2176
|
+
* Equip the voice provider with instructions
|
|
2177
|
+
* @param instructions Instructions to add
|
|
1944
2178
|
*/
|
|
1945
|
-
|
|
1946
|
-
protected cleanup?: () => void;
|
|
1947
|
-
protected retryConfig?: {
|
|
1948
|
-
attempts?: number;
|
|
1949
|
-
delay?: number;
|
|
1950
|
-
};
|
|
1951
|
-
constructor(params: {
|
|
1952
|
-
workflowId: string;
|
|
1953
|
-
runId: string;
|
|
1954
|
-
executionEngine: ExecutionEngine;
|
|
1955
|
-
executionGraph: ExecutionGraph;
|
|
1956
|
-
mastra?: Mastra;
|
|
1957
|
-
retryConfig?: {
|
|
1958
|
-
attempts?: number;
|
|
1959
|
-
delay?: number;
|
|
1960
|
-
};
|
|
1961
|
-
cleanup?: () => void;
|
|
1962
|
-
});
|
|
2179
|
+
addInstructions(instructions: string): void;
|
|
1963
2180
|
/**
|
|
1964
|
-
*
|
|
1965
|
-
* @param
|
|
1966
|
-
* @returns A promise that resolves to the workflow output
|
|
2181
|
+
* Equip the voice provider with tools
|
|
2182
|
+
* @param tools Array of tools to add
|
|
1967
2183
|
*/
|
|
1968
|
-
|
|
1969
|
-
inputData?: z.infer<TInput>;
|
|
1970
|
-
runtimeContext?: RuntimeContext;
|
|
1971
|
-
}): Promise<WorkflowResult<TOutput, TSteps>>;
|
|
2184
|
+
addTools(tools: ToolsInput): void;
|
|
1972
2185
|
/**
|
|
1973
|
-
*
|
|
1974
|
-
* @param input The input data for the workflow
|
|
1975
|
-
* @returns A promise that resolves to the workflow output
|
|
2186
|
+
* Disconnect from the WebSocket or WebRTC connection
|
|
1976
2187
|
*/
|
|
1977
|
-
|
|
1978
|
-
inputData?: z.infer<TInput>;
|
|
1979
|
-
runtimeContext?: RuntimeContext;
|
|
1980
|
-
}): {
|
|
1981
|
-
stream: ReadableStream<WatchEvent>;
|
|
1982
|
-
getWorkflowState: () => Promise<WorkflowResult<TOutput, TSteps>>;
|
|
1983
|
-
};
|
|
1984
|
-
watch(cb: (event: WatchEvent) => void, type?: 'watch' | 'watch-v2'): () => void;
|
|
1985
|
-
resume<TResumeSchema extends z.ZodType<any>>(params: {
|
|
1986
|
-
resumeData?: z.infer<TResumeSchema>;
|
|
1987
|
-
step: Step<string, any, any, TResumeSchema, any> | [...Step<string, any, any, any, any>[], Step<string, any, any, TResumeSchema, any>] | string | string[];
|
|
1988
|
-
runtimeContext?: RuntimeContext;
|
|
1989
|
-
}): Promise<WorkflowResult<TOutput, TSteps>>;
|
|
2188
|
+
close(): void;
|
|
1990
2189
|
/**
|
|
1991
|
-
*
|
|
1992
|
-
* @
|
|
2190
|
+
* Register an event listener
|
|
2191
|
+
* @param event Event name (e.g., 'speaking', 'writing', 'error')
|
|
2192
|
+
* @param callback Callback function that receives event data
|
|
1993
2193
|
*/
|
|
1994
|
-
|
|
1995
|
-
|
|
2194
|
+
on<E extends VoiceEventType>(event: E, callback: (data: E extends keyof VoiceEventMap ? VoiceEventMap[E] : unknown) => void): void;
|
|
2195
|
+
/**
|
|
2196
|
+
* Remove an event listener
|
|
2197
|
+
* @param event Event name (e.g., 'speaking', 'writing', 'error')
|
|
2198
|
+
* @param callback Callback function to remove
|
|
2199
|
+
*/
|
|
2200
|
+
off<E extends VoiceEventType>(event: E, callback: (data: E extends keyof VoiceEventMap ? VoiceEventMap[E] : unknown) => void): void;
|
|
2201
|
+
}
|
|
2202
|
+
|
|
2203
|
+
declare class DefaultVoice extends MastraVoice {
|
|
2204
|
+
constructor();
|
|
2205
|
+
speak(_input: string | NodeJS.ReadableStream): Promise<NodeJS.ReadableStream>;
|
|
2206
|
+
listen(_input: string | NodeJS.ReadableStream): Promise<string>;
|
|
2207
|
+
getSpeakers(): Promise<{
|
|
2208
|
+
voiceId: string;
|
|
2209
|
+
}[]>;
|
|
1996
2210
|
}
|
|
1997
2211
|
|
|
1998
2212
|
type ToolsInput = Record<string, ToolAction<any, any, any> | VercelTool>;
|
|
@@ -2223,6 +2437,7 @@ type ConvertedTool = {
|
|
|
2223
2437
|
description?: string;
|
|
2224
2438
|
parameters: InternalCoreTool['parameters'];
|
|
2225
2439
|
execute: InternalCoreTool['execute'];
|
|
2440
|
+
toolType?: MCPToolType;
|
|
2226
2441
|
};
|
|
2227
2442
|
interface MCPServerSSEOptionsBase {
|
|
2228
2443
|
/**
|
|
@@ -2458,6 +2673,12 @@ interface ServerDetailInfo extends ServerInfo {
|
|
|
2458
2673
|
/** Information about remote access points for this server. */
|
|
2459
2674
|
remotes?: RemoteInfo[];
|
|
2460
2675
|
}
|
|
2676
|
+
/**
|
|
2677
|
+
* The type of tool registered with the MCP server.
|
|
2678
|
+
* This is used to categorize tools in the MCP Server playground.
|
|
2679
|
+
* If not specified, it defaults to a regular tool.
|
|
2680
|
+
*/
|
|
2681
|
+
type MCPToolType = 'agent' | 'workflow';
|
|
2461
2682
|
|
|
2462
2683
|
/**
|
|
2463
2684
|
* Abstract base class for MCP server implementations.
|
|
@@ -2854,6 +3075,7 @@ interface IAction<TId extends string, TSchemaIn extends z.ZodSchema | undefined,
|
|
|
2854
3075
|
execute?: (context: TContext, options?: TOptions) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
|
|
2855
3076
|
}
|
|
2856
3077
|
|
|
3078
|
+
type IDGenerator = () => string;
|
|
2857
3079
|
declare class Agent<TAgentId extends string = string, TTools extends ToolsInput = ToolsInput, TMetrics extends Record<string, Metric> = Record<string, Metric>> extends MastraBase {
|
|
2858
3080
|
#private;
|
|
2859
3081
|
id: TAgentId;
|
|
@@ -2909,46 +3131,28 @@ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput
|
|
|
2909
3131
|
*/
|
|
2910
3132
|
__setTools(tools: TTools): void;
|
|
2911
3133
|
generateTitleFromUserMessage({ message, runtimeContext, }: {
|
|
2912
|
-
message:
|
|
3134
|
+
message: UIMessage;
|
|
2913
3135
|
runtimeContext?: RuntimeContext;
|
|
2914
3136
|
}): Promise<string>;
|
|
2915
|
-
getMostRecentUserMessage(messages: Array<
|
|
2916
|
-
genTitle(userMessage:
|
|
2917
|
-
fetchMemory({ threadId, thread: passedThread, memoryConfig, resourceId,
|
|
3137
|
+
getMostRecentUserMessage(messages: Array<UIMessage>): UIMessage | undefined;
|
|
3138
|
+
genTitle(userMessage: UIMessage | undefined): Promise<string>;
|
|
3139
|
+
fetchMemory({ threadId, thread: passedThread, memoryConfig, resourceId, runId, messageList, }: {
|
|
2918
3140
|
resourceId: string;
|
|
2919
3141
|
threadId: string;
|
|
2920
3142
|
thread?: StorageThreadType;
|
|
2921
3143
|
memoryConfig?: MemoryConfig;
|
|
2922
|
-
userMessages: CoreMessage$1[];
|
|
2923
|
-
systemMessage: CoreMessage$1;
|
|
2924
|
-
time?: Date;
|
|
2925
|
-
keyword?: string;
|
|
2926
3144
|
runId?: string;
|
|
3145
|
+
messageList: MessageList;
|
|
2927
3146
|
}): Promise<{
|
|
2928
3147
|
threadId: string;
|
|
2929
|
-
messages: CoreMessage$1[];
|
|
2930
3148
|
}>;
|
|
2931
|
-
private getResponseMessages;
|
|
2932
|
-
sanitizeResponseMessages(messages: Array<CoreMessage$1>): Array<CoreMessage$1>;
|
|
2933
3149
|
private getMemoryTools;
|
|
2934
3150
|
private getAssignedTools;
|
|
2935
3151
|
private getToolsets;
|
|
2936
3152
|
private getClientTools;
|
|
2937
3153
|
private getWorkflowTools;
|
|
2938
3154
|
private convertTools;
|
|
2939
|
-
|
|
2940
|
-
runId?: string;
|
|
2941
|
-
threadId: string;
|
|
2942
|
-
thread?: StorageThreadType;
|
|
2943
|
-
memoryConfig?: MemoryConfig;
|
|
2944
|
-
messages: CoreMessage$1[];
|
|
2945
|
-
resourceId: string;
|
|
2946
|
-
systemMessage: CoreMessage$1;
|
|
2947
|
-
}): Promise<{
|
|
2948
|
-
coreMessages: CoreMessage$1[];
|
|
2949
|
-
threadIdToUse: string;
|
|
2950
|
-
}>;
|
|
2951
|
-
__primitive({ instructions, messages, context, threadId, memoryConfig, resourceId, runId, toolsets, clientTools, runtimeContext, }: {
|
|
3155
|
+
__primitive({ instructions, messages, context, threadId, memoryConfig, resourceId, runId, toolsets, clientTools, runtimeContext, generateMessageId, }: {
|
|
2952
3156
|
instructions?: string;
|
|
2953
3157
|
toolsets?: ToolsetsInput;
|
|
2954
3158
|
clientTools?: ToolsInput;
|
|
@@ -2957,23 +3161,31 @@ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput
|
|
|
2957
3161
|
memoryConfig?: MemoryConfig;
|
|
2958
3162
|
context?: CoreMessage$1[];
|
|
2959
3163
|
runId?: string;
|
|
2960
|
-
messages: CoreMessage$1[];
|
|
3164
|
+
messages: string | string[] | CoreMessage$1[] | Message[];
|
|
2961
3165
|
runtimeContext: RuntimeContext;
|
|
3166
|
+
generateMessageId: undefined | IDGenerator;
|
|
2962
3167
|
}): {
|
|
2963
3168
|
before: () => Promise<{
|
|
2964
3169
|
messageObjects: CoreMessage$1[];
|
|
3170
|
+
convertedTools: Record<string, CoreTool>;
|
|
3171
|
+
messageList: MessageList;
|
|
3172
|
+
threadId?: undefined;
|
|
3173
|
+
thread?: undefined;
|
|
3174
|
+
} | {
|
|
2965
3175
|
convertedTools: Record<string, CoreTool>;
|
|
2966
3176
|
threadId: string;
|
|
2967
|
-
thread: StorageThreadType
|
|
3177
|
+
thread: StorageThreadType;
|
|
3178
|
+
messageList: MessageList;
|
|
3179
|
+
messageObjects: CoreMessage$1[];
|
|
2968
3180
|
}>;
|
|
2969
|
-
after: ({ result, thread: threadAfter, threadId, memoryConfig, outputText, runId,
|
|
3181
|
+
after: ({ result, thread: threadAfter, threadId, memoryConfig, outputText, runId, messageList, }: {
|
|
2970
3182
|
runId: string;
|
|
2971
3183
|
result: Record<string, any>;
|
|
2972
3184
|
thread: StorageThreadType | null | undefined;
|
|
2973
|
-
threadId
|
|
3185
|
+
threadId?: string;
|
|
2974
3186
|
memoryConfig: MemoryConfig | undefined;
|
|
2975
3187
|
outputText: string;
|
|
2976
|
-
|
|
3188
|
+
messageList: MessageList;
|
|
2977
3189
|
}) => Promise<void>;
|
|
2978
3190
|
};
|
|
2979
3191
|
generate<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[] | Message[], args?: AgentGenerateOptions<Z> & {
|
|
@@ -3041,125 +3253,6 @@ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput
|
|
|
3041
3253
|
}>, any>;
|
|
3042
3254
|
}
|
|
3043
3255
|
|
|
3044
|
-
interface StorageColumn {
|
|
3045
|
-
type: 'text' | 'timestamp' | 'uuid' | 'jsonb' | 'integer' | 'bigint';
|
|
3046
|
-
primaryKey?: boolean;
|
|
3047
|
-
nullable?: boolean;
|
|
3048
|
-
references?: {
|
|
3049
|
-
table: string;
|
|
3050
|
-
column: string;
|
|
3051
|
-
};
|
|
3052
|
-
}
|
|
3053
|
-
interface LegacyWorkflowRuns {
|
|
3054
|
-
runs: LegacyWorkflowRun[];
|
|
3055
|
-
total: number;
|
|
3056
|
-
}
|
|
3057
|
-
interface LegacyWorkflowRun {
|
|
3058
|
-
workflowName: string;
|
|
3059
|
-
runId: string;
|
|
3060
|
-
snapshot: LegacyWorkflowRunState | string;
|
|
3061
|
-
createdAt: Date;
|
|
3062
|
-
updatedAt: Date;
|
|
3063
|
-
resourceId?: string;
|
|
3064
|
-
}
|
|
3065
|
-
interface WorkflowRuns {
|
|
3066
|
-
runs: WorkflowRun[];
|
|
3067
|
-
total: number;
|
|
3068
|
-
}
|
|
3069
|
-
interface WorkflowRun {
|
|
3070
|
-
workflowName: string;
|
|
3071
|
-
runId: string;
|
|
3072
|
-
snapshot: WorkflowRunState | string;
|
|
3073
|
-
createdAt: Date;
|
|
3074
|
-
updatedAt: Date;
|
|
3075
|
-
resourceId?: string;
|
|
3076
|
-
}
|
|
3077
|
-
type StorageGetMessagesArg = {
|
|
3078
|
-
threadId: string;
|
|
3079
|
-
resourceId?: string;
|
|
3080
|
-
selectBy?: {
|
|
3081
|
-
vectorSearchString?: string;
|
|
3082
|
-
last?: number | false;
|
|
3083
|
-
include?: {
|
|
3084
|
-
id: string;
|
|
3085
|
-
withPreviousMessages?: number;
|
|
3086
|
-
withNextMessages?: number;
|
|
3087
|
-
}[];
|
|
3088
|
-
};
|
|
3089
|
-
threadConfig?: MemoryConfig;
|
|
3090
|
-
};
|
|
3091
|
-
type EvalRow = {
|
|
3092
|
-
input: string;
|
|
3093
|
-
output: string;
|
|
3094
|
-
result: MetricResult;
|
|
3095
|
-
agentName: string;
|
|
3096
|
-
createdAt: string;
|
|
3097
|
-
metricName: string;
|
|
3098
|
-
instructions: string;
|
|
3099
|
-
runId: string;
|
|
3100
|
-
globalRunId: string;
|
|
3101
|
-
testInfo?: TestInfo;
|
|
3102
|
-
};
|
|
3103
|
-
|
|
3104
|
-
declare const TABLE_WORKFLOW_SNAPSHOT = "mastra_workflow_snapshot";
|
|
3105
|
-
declare const TABLE_EVALS = "mastra_evals";
|
|
3106
|
-
declare const TABLE_MESSAGES = "mastra_messages";
|
|
3107
|
-
declare const TABLE_THREADS = "mastra_threads";
|
|
3108
|
-
declare const TABLE_TRACES = "mastra_traces";
|
|
3109
|
-
type TABLE_NAMES = typeof TABLE_WORKFLOW_SNAPSHOT | typeof TABLE_EVALS | typeof TABLE_MESSAGES | typeof TABLE_THREADS | typeof TABLE_TRACES;
|
|
3110
|
-
declare const TABLE_SCHEMAS: Record<TABLE_NAMES, Record<string, StorageColumn>>;
|
|
3111
|
-
|
|
3112
|
-
type MessageType = {
|
|
3113
|
-
id: string;
|
|
3114
|
-
content: UserContent | AssistantContent | ToolContent;
|
|
3115
|
-
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
3116
|
-
createdAt: Date;
|
|
3117
|
-
threadId: string;
|
|
3118
|
-
resourceId: string;
|
|
3119
|
-
toolCallIds?: string[];
|
|
3120
|
-
toolCallArgs?: Record<string, unknown>[];
|
|
3121
|
-
toolNames?: string[];
|
|
3122
|
-
type: 'text' | 'tool-call' | 'tool-result';
|
|
3123
|
-
};
|
|
3124
|
-
type StorageThreadType = {
|
|
3125
|
-
id: string;
|
|
3126
|
-
title?: string;
|
|
3127
|
-
resourceId: string;
|
|
3128
|
-
createdAt: Date;
|
|
3129
|
-
updatedAt: Date;
|
|
3130
|
-
metadata?: Record<string, unknown>;
|
|
3131
|
-
};
|
|
3132
|
-
type MessageResponse<T extends 'raw' | 'core_message'> = {
|
|
3133
|
-
raw: MessageType[];
|
|
3134
|
-
core_message: CoreMessage$1[];
|
|
3135
|
-
}[T];
|
|
3136
|
-
type MemoryConfig = {
|
|
3137
|
-
lastMessages?: number | false;
|
|
3138
|
-
semanticRecall?: boolean | {
|
|
3139
|
-
topK: number;
|
|
3140
|
-
messageRange: number | {
|
|
3141
|
-
before: number;
|
|
3142
|
-
after: number;
|
|
3143
|
-
};
|
|
3144
|
-
};
|
|
3145
|
-
workingMemory?: {
|
|
3146
|
-
enabled: boolean;
|
|
3147
|
-
template?: string;
|
|
3148
|
-
/** @deprecated The `use` option has been removed. Working memory always uses tool-call mode. */
|
|
3149
|
-
use?: never;
|
|
3150
|
-
};
|
|
3151
|
-
threads?: {
|
|
3152
|
-
generateTitle?: boolean;
|
|
3153
|
-
};
|
|
3154
|
-
};
|
|
3155
|
-
type SharedMemoryConfig = {
|
|
3156
|
-
storage?: MastraStorage;
|
|
3157
|
-
options?: MemoryConfig;
|
|
3158
|
-
vector?: MastraVector | false;
|
|
3159
|
-
embedder?: EmbeddingModel<string>;
|
|
3160
|
-
processors?: MemoryProcessor[];
|
|
3161
|
-
};
|
|
3162
|
-
|
|
3163
3256
|
declare abstract class MastraStorage extends MastraBase {
|
|
3164
3257
|
/** @deprecated import from { TABLE_WORKFLOW_SNAPSHOT } '@mastra/core/storage' instead */
|
|
3165
3258
|
static readonly TABLE_WORKFLOW_SNAPSHOT = "mastra_workflow_snapshot";
|
|
@@ -3215,10 +3308,10 @@ declare abstract class MastraStorage extends MastraBase {
|
|
|
3215
3308
|
abstract deleteThread({ threadId }: {
|
|
3216
3309
|
threadId: string;
|
|
3217
3310
|
}): Promise<void>;
|
|
3218
|
-
abstract getMessages({ threadId, selectBy, threadConfig }: StorageGetMessagesArg): Promise<
|
|
3311
|
+
abstract getMessages({ threadId, selectBy, threadConfig }: StorageGetMessagesArg): Promise<MastraMessageV2[]>;
|
|
3219
3312
|
abstract saveMessages({ messages }: {
|
|
3220
|
-
messages:
|
|
3221
|
-
}): Promise<
|
|
3313
|
+
messages: (MastraMessageV1 | MastraMessageV2)[];
|
|
3314
|
+
}): Promise<MastraMessageV2[]>;
|
|
3222
3315
|
abstract getTraces({ name, scope, page, perPage, attributes, filters, }: {
|
|
3223
3316
|
name?: string;
|
|
3224
3317
|
scope?: string;
|
|
@@ -3254,4 +3347,4 @@ declare abstract class MastraStorage extends MastraBase {
|
|
|
3254
3347
|
}): Promise<WorkflowRun | null>;
|
|
3255
3348
|
}
|
|
3256
3349
|
|
|
3257
|
-
export { type WorkflowActions as $, type ApiRoute as A, type StepGraph as B, type ContextWithMastra as C, type BaseCondition as D, type EvalRow as E, type ActionContext as F, WhenConditionReturnValue as G, type StepDef as H, type StepCondition as I, type StepConfig as J, type StepsRecord$1 as K, type LegacyWorkflowRuns as L, type Methods as M, type WorkflowLogMessage as N, type WorkflowEvent as O, type ResolverFunctionInput as P, type ResolverFunctionOutput as Q, type RetryConfig as R, type StorageColumn as S, type TABLE_NAMES as T, type SubscriberFunctionOutput as U, type VariableReference$1 as V, type WorkflowRuns as W, type DependencyCheckOutput as X, type StepResolverOutput as Y, type WorkflowActors as Z, type WorkflowActionParams as _, Mastra as a,
|
|
3350
|
+
export { type WorkflowActions as $, type ApiRoute as A, type StepGraph as B, type ContextWithMastra as C, type BaseCondition as D, type EvalRow as E, type ActionContext as F, WhenConditionReturnValue as G, type StepDef as H, type StepCondition as I, type StepConfig as J, type StepsRecord$1 as K, type LegacyWorkflowRuns as L, type Methods as M, type WorkflowLogMessage as N, type WorkflowEvent as O, type ResolverFunctionInput as P, type ResolverFunctionOutput as Q, type RetryConfig as R, type StorageColumn as S, type TABLE_NAMES as T, type SubscriberFunctionOutput as U, type VariableReference$1 as V, type WorkflowRuns as W, type DependencyCheckOutput as X, type StepResolverOutput as Y, type WorkflowActors as Z, type WorkflowActionParams as _, Mastra as a, Run as a$, type LegacyWorkflowState as a0, type StepId as a1, type ExtractSchemaFromStep$1 as a2, type ExtractStepResult as a3, type StepInputType as a4, type ExtractSchemaType$1 as a5, type PathsToStringProps$1 as a6, type LegacyWorkflowRunState as a7, type WorkflowResumeResult as a8, type ToolAction as a9, type LLMTextOptions as aA, type LLMTextObjectOptions as aB, type LLMStreamOptions as aC, type LLMInnerStreamOptions as aD, type LLMStreamObjectOptions as aE, createMockModel as aF, type Config as aG, type MastraMessageV1 as aH, type MessageType as aI, type MessageResponse as aJ, type MemoryConfig as aK, type SharedMemoryConfig as aL, type MemoryProcessorOpts as aM, MemoryProcessor as aN, memoryDefaultOptions as aO, createTool as aP, type VercelTool as aQ, type CoreTool as aR, type InternalCoreTool as aS, type StepFlowEntry as aT, type SerializedStep as aU, type SerializedStepFlowEntry as aV, createStep as aW, cloneStep as aX, createWorkflow as aY, cloneWorkflow as aZ, type WorkflowResult as a_, type AgentConfig as aa, MastraMemory as ab, type ToolExecutionContext as ac, Tool as ad, type Step as ae, Workflow as af, type WorkflowConfig as ag, type LanguageModel as ah, type CoreMessage as ai, type CoreSystemMessage as aj, type CoreAssistantMessage as ak, type CoreUserMessage as al, type CoreToolMessage as am, type EmbedResult as an, type EmbedManyResult as ao, type BaseStructuredOutputType as ap, type StructuredOutputType as aq, type StructuredOutputArrayItem as ar, type StructuredOutput as as, type GenerateReturn as at, type StreamReturn as au, type OutputType as av, type DefaultLLMTextOptions as aw, type DefaultLLMTextObjectOptions as ax, type DefaultLLMStreamOptions as ay, type DefaultLLMStreamObjectOptions as az, type MastraAuthConfig as b, type ExecutionGraph as b0, ExecutionEngine as b1, type ExecuteFunction as b2, type StepSuccess as b3, type StepFailure as b4, type StepSuspended as b5, type StepRunning as b6, type StepResult as b7, type StepsRecord as b8, type DynamicMapping as b9, type NamedArgumentInfo as bA, type SubcommandInfo as bB, type CommandInfo as bC, type EnvironmentVariableInfo as bD, type PackageInfo as bE, type RemoteInfo as bF, type MCPServerConfig as bG, type ServerInfo as bH, type ServerDetailInfo as bI, type MCPToolType as bJ, MessageList as bK, type ToolsetsInput as bL, type DynamicArgument as bM, type AgentGenerateOptions as bN, type AgentStreamOptions as bO, type MastraMessageContentV2 as bP, type PathsToStringProps as ba, type ExtractSchemaType as bb, type ExtractSchemaFromStep as bc, type VariableReference as bd, type WatchEvent as be, type ZodPathType as bf, type WorkflowRunState as bg, type MastraLanguageModel as bh, type MastraPrimitives as bi, AgentNetwork as bj, MCPServerBase as bk, type VoiceEventType as bl, type VoiceEventMap as bm, type VoiceConfig as bn, MastraVoice as bo, CompositeVoice as bp, DefaultVoice as bq, type AgentNetworkConfig as br, type ConvertedTool as bs, type MCPServerSSEOptions as bt, type MCPServerHonoSSEOptions as bu, type MCPServerHTTPOptions as bv, type Repository as bw, type VersionDetail as bx, type ArgumentInfo as by, type PositionalArgumentInfo as bz, MastraStorage as c, type StorageThreadType as d, type MastraMessageV2 as e, type StorageGetMessagesArg as f, type WorkflowRun as g, type LegacyWorkflowRun as h, TABLE_WORKFLOW_SNAPSHOT as i, TABLE_EVALS as j, TABLE_MESSAGES as k, TABLE_THREADS as l, TABLE_TRACES as m, TABLE_SCHEMAS as n, type StepResult$1 as o, LegacyStep as p, LegacyWorkflow as q, Agent as r, type WorkflowContext as s, type ToolsInput as t, type StepAction as u, type LegacyWorkflowRunResult as v, type WorkflowOptions as w, type StepExecutionContext as x, type StepVariableType as y, type StepNode as z };
|