@mastra/core 0.6.4 → 0.7.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/agent/index.cjs +2 -2
  2. package/dist/agent/index.d.cts +6 -6
  3. package/dist/agent/index.d.ts +6 -6
  4. package/dist/agent/index.js +1 -1
  5. package/dist/{base-DbCjWM67.d.cts → base-6TZjD_gW.d.cts} +560 -516
  6. package/dist/{base-CMQiCwHG.d.ts → base-DYeWJ7uK.d.ts} +560 -516
  7. package/dist/{chunk-B7OACOMS.js → chunk-3PWZCDYW.js} +1 -1
  8. package/dist/{chunk-4OM3F6KZ.cjs → chunk-5T43A3YE.cjs} +7 -0
  9. package/dist/{chunk-3OXCRLRW.js → chunk-5YT3KIH3.js} +7 -0
  10. package/dist/{chunk-YTP2MMIM.cjs → chunk-6ZCLYB53.cjs} +2 -2
  11. package/dist/{chunk-2DKUBXLZ.cjs → chunk-G5HHCEH3.cjs} +2 -2
  12. package/dist/{chunk-YLLXAKL2.cjs → chunk-LOPB4SHX.cjs} +91 -15
  13. package/dist/{chunk-PRNJCD6I.js → chunk-MLWSGLXY.js} +81 -5
  14. package/dist/{chunk-34GSMLRD.js → chunk-QMSSRQVR.js} +1 -1
  15. package/dist/{chunk-ZG35KSBA.js → chunk-X4JHAQSU.js} +242 -23
  16. package/dist/{chunk-33QB276D.cjs → chunk-ZLSEJA42.cjs} +245 -23
  17. package/dist/eval/index.d.cts +5 -5
  18. package/dist/eval/index.d.ts +5 -5
  19. package/dist/index.cjs +49 -37
  20. package/dist/index.d.cts +5 -5
  21. package/dist/index.d.ts +5 -5
  22. package/dist/index.js +6 -6
  23. package/dist/integration/index.d.cts +6 -6
  24. package/dist/integration/index.d.ts +6 -6
  25. package/dist/llm/index.d.cts +8 -8
  26. package/dist/llm/index.d.ts +8 -8
  27. package/dist/mastra/index.d.cts +7 -7
  28. package/dist/mastra/index.d.ts +7 -7
  29. package/dist/memory/index.cjs +2 -2
  30. package/dist/memory/index.d.cts +6 -6
  31. package/dist/memory/index.d.ts +6 -6
  32. package/dist/memory/index.js +1 -1
  33. package/dist/network/index.cjs +12 -12
  34. package/dist/network/index.d.cts +6 -6
  35. package/dist/network/index.d.ts +6 -6
  36. package/dist/network/index.js +11 -11
  37. package/dist/relevance/index.cjs +4 -4
  38. package/dist/relevance/index.d.cts +11 -11
  39. package/dist/relevance/index.d.ts +11 -11
  40. package/dist/relevance/index.js +1 -1
  41. package/dist/storage/index.d.cts +6 -6
  42. package/dist/storage/index.d.ts +6 -6
  43. package/dist/storage/libsql/index.d.cts +6 -6
  44. package/dist/storage/libsql/index.d.ts +6 -6
  45. package/dist/telemetry/index.d.cts +6 -6
  46. package/dist/telemetry/index.d.ts +6 -6
  47. package/dist/tools/index.d.cts +6 -6
  48. package/dist/tools/index.d.ts +6 -6
  49. package/dist/utils.cjs +12 -12
  50. package/dist/utils.d.cts +5 -5
  51. package/dist/utils.d.ts +5 -5
  52. package/dist/utils.js +1 -1
  53. package/dist/voice/index.d.cts +6 -6
  54. package/dist/voice/index.d.ts +6 -6
  55. package/dist/workflows/index.cjs +29 -17
  56. package/dist/workflows/index.d.cts +24 -14
  57. package/dist/workflows/index.d.ts +24 -14
  58. package/dist/workflows/index.js +1 -1
  59. package/package.json +4 -4
@@ -1,18 +1,18 @@
1
1
  import * as ai from 'ai';
2
- import { Tool as Tool$1, ToolExecutionOptions, EmbeddingModel, CoreMessage as CoreMessage$1, Message, UserContent, AssistantContent, LanguageModelV1, GenerateTextResult, GenerateObjectResult, StreamTextResult, StreamObjectResult, TelemetrySettings, generateText, generateObject, streamText, streamObject, CoreSystemMessage as CoreSystemMessage$1, CoreAssistantMessage as CoreAssistantMessage$1, CoreUserMessage as CoreUserMessage$1, CoreToolMessage as CoreToolMessage$1, EmbedResult as EmbedResult$1, EmbedManyResult as EmbedManyResult$1, LanguageModel as LanguageModel$1, DeepPartial, ToolContent } from 'ai';
2
+ import { Tool as Tool$1, ToolExecutionOptions, CoreMessage as CoreMessage$1, TelemetrySettings, generateText, generateObject, streamText, GenerateTextResult, GenerateObjectResult, streamObject, StreamTextResult, StreamObjectResult, CoreSystemMessage as CoreSystemMessage$1, CoreAssistantMessage as CoreAssistantMessage$1, CoreUserMessage as CoreUserMessage$1, CoreToolMessage as CoreToolMessage$1, EmbedResult as EmbedResult$1, EmbedManyResult as EmbedManyResult$1, EmbeddingModel, Message, UserContent, AssistantContent, LanguageModelV1, LanguageModel as LanguageModel$1, DeepPartial, ToolContent } from 'ai';
3
3
  import { M as MastraBase, T as Telemetry, O as OtelConfig } from './base-ObPJ-w8K.cjs';
4
+ import { M as Metric, a as MetricResult, T as TestInfo } from './types-CwTG2XyQ.cjs';
4
5
  import { Query } from 'sift';
5
6
  import { z, ZodSchema } from 'zod';
6
7
  import { JSONSchema7 } from 'json-schema';
7
- import { M as Metric, a as MetricResult, T as TestInfo } from './types-CwTG2XyQ.cjs';
8
- import { B as BaseLogMessage, R as RegisteredLogger, L as Logger, d as Run } from './index-CquI0inB.cjs';
9
- import { MastraDeployer } from './deployer/index.cjs';
10
- import { MastraVector } from './vector/index.cjs';
8
+ import { d as Run, B as BaseLogMessage, R as RegisteredLogger, L as Logger } from './index-CquI0inB.cjs';
11
9
  import { Span } from '@opentelemetry/api';
12
10
  import * as xstate from 'xstate';
13
11
  import { Snapshot } from 'xstate';
14
12
  import EventEmitter from 'node:events';
13
+ import { MastraVector } from './vector/index.cjs';
15
14
  import { MastraTTS } from './tts/index.cjs';
15
+ import { MastraDeployer } from './deployer/index.cjs';
16
16
 
17
17
  type VercelTool = Tool$1;
18
18
  type CoreTool = {
@@ -48,6 +48,72 @@ declare class Tool<TSchemaIn extends z.ZodSchema | undefined = undefined, TSchem
48
48
  }
49
49
  declare function createTool<TSchemaIn extends z.ZodSchema | undefined = undefined, TSchemaOut extends z.ZodSchema | undefined = undefined, TContext extends ToolExecutionContext<TSchemaIn> = ToolExecutionContext<TSchemaIn>>(opts: ToolAction<TSchemaIn, TSchemaOut, TContext>): Tool<TSchemaIn, TSchemaOut, TContext>;
50
50
 
51
+ type LanguageModel = MastraLanguageModel;
52
+ type CoreMessage = CoreMessage$1;
53
+ type CoreSystemMessage = CoreSystemMessage$1;
54
+ type CoreAssistantMessage = CoreAssistantMessage$1;
55
+ type CoreUserMessage = CoreUserMessage$1;
56
+ type CoreToolMessage = CoreToolMessage$1;
57
+ type EmbedResult<T> = EmbedResult$1<T>;
58
+ type EmbedManyResult<T> = EmbedManyResult$1<T>;
59
+ type BaseStructuredOutputType = 'string' | 'number' | 'boolean' | 'date';
60
+ type StructuredOutputType = 'array' | 'string' | 'number' | 'object' | 'boolean' | 'date';
61
+ type StructuredOutputArrayItem = {
62
+ type: BaseStructuredOutputType;
63
+ } | {
64
+ type: 'object';
65
+ items: StructuredOutput;
66
+ };
67
+ type StructuredOutput = {
68
+ [key: string]: {
69
+ type: BaseStructuredOutputType;
70
+ } | {
71
+ type: 'object';
72
+ items: StructuredOutput;
73
+ } | {
74
+ type: 'array';
75
+ items: StructuredOutputArrayItem;
76
+ };
77
+ };
78
+ 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>;
79
+ 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>;
80
+ type OutputType = StructuredOutput | ZodSchema | JSONSchema7 | undefined;
81
+ type GenerateTextOptions = Parameters<typeof generateText>[0];
82
+ type StreamTextOptions = Parameters<typeof streamText>[0];
83
+ type GenerateObjectOptions = Parameters<typeof generateObject>[0];
84
+ type StreamObjectOptions = Parameters<typeof streamObject>[0];
85
+ type MastraCustomLLMOptionsKeys = 'messages' | 'tools' | 'model' | 'onStepFinish' | 'experimental_output' | 'experimental_telemetry' | 'messages' | 'onFinish' | 'output';
86
+ type DefaultLLMTextOptions = Omit<GenerateTextOptions, MastraCustomLLMOptionsKeys>;
87
+ type DefaultLLMTextObjectOptions = Omit<GenerateObjectOptions, MastraCustomLLMOptionsKeys>;
88
+ type DefaultLLMStreamOptions = Omit<StreamTextOptions, MastraCustomLLMOptionsKeys>;
89
+ type DefaultLLMStreamObjectOptions = Omit<StreamObjectOptions, MastraCustomLLMOptionsKeys>;
90
+ type MastraCustomLLMOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
91
+ tools?: ToolsInput;
92
+ convertedTools?: Record<string, CoreTool>;
93
+ onStepFinish?: (step: string) => void;
94
+ experimental_output?: Z;
95
+ telemetry?: TelemetrySettings;
96
+ threadId?: string;
97
+ resourceId?: string;
98
+ } & Run;
99
+ type LLMTextOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
100
+ messages: CoreMessage[];
101
+ } & MastraCustomLLMOptions<Z> & DefaultLLMTextOptions;
102
+ type LLMTextObjectOptions<T extends ZodSchema | JSONSchema7 | undefined = undefined> = LLMTextOptions<T> & DefaultLLMTextObjectOptions & {
103
+ structuredOutput: JSONSchema7 | z.ZodType<T> | StructuredOutput;
104
+ };
105
+ type LLMStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
106
+ output?: OutputType | Z;
107
+ onFinish?: (result: string) => Promise<void> | void;
108
+ } & MastraCustomLLMOptions<Z> & DefaultLLMStreamOptions;
109
+ type LLMInnerStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
110
+ messages: CoreMessage[];
111
+ onFinish?: (result: string) => Promise<void> | void;
112
+ } & MastraCustomLLMOptions<Z> & DefaultLLMStreamOptions;
113
+ type LLMStreamObjectOptions<T extends ZodSchema | JSONSchema7 | undefined = undefined> = {
114
+ structuredOutput: JSONSchema7 | z.ZodType<T> | StructuredOutput;
115
+ } & LLMInnerStreamOptions<T> & DefaultLLMStreamObjectOptions;
116
+
51
117
  /**
52
118
  * Abstract Memory class that defines the interface for storing and retrieving
53
119
  * conversation threads and messages.
@@ -180,173 +246,291 @@ declare abstract class MastraMemory extends MastraBase {
180
246
  generateId(): string;
181
247
  }
182
248
 
183
- type AgentNetworkConfig = {
184
- name: string;
185
- agents: Agent[];
186
- model: LanguageModelV1;
187
- instructions: string;
188
- };
189
-
190
- declare class AgentNetwork extends MastraBase {
191
- #private;
192
- constructor(config: AgentNetworkConfig);
193
- formatAgentId(name: string): string;
194
- getTools(): {
195
- transmit: Tool<z.ZodObject<{
196
- actions: z.ZodArray<z.ZodObject<{
197
- agent: z.ZodString;
198
- input: z.ZodString;
199
- includeHistory: z.ZodOptional<z.ZodBoolean>;
200
- }, "strip", z.ZodTypeAny, {
201
- input: string;
202
- agent: string;
203
- includeHistory?: boolean | undefined;
204
- }, {
205
- input: string;
206
- agent: string;
207
- includeHistory?: boolean | undefined;
208
- }>, "many">;
209
- }, "strip", z.ZodTypeAny, {
210
- actions: {
211
- input: string;
212
- agent: string;
213
- includeHistory?: boolean | undefined;
214
- }[];
215
- }, {
216
- actions: {
217
- input: string;
218
- agent: string;
219
- includeHistory?: boolean | undefined;
220
- }[];
221
- }>, undefined, ToolExecutionContext<z.ZodObject<{
222
- actions: z.ZodArray<z.ZodObject<{
223
- agent: z.ZodString;
224
- input: z.ZodString;
225
- includeHistory: z.ZodOptional<z.ZodBoolean>;
226
- }, "strip", z.ZodTypeAny, {
227
- input: string;
228
- agent: string;
229
- includeHistory?: boolean | undefined;
230
- }, {
231
- input: string;
232
- agent: string;
233
- includeHistory?: boolean | undefined;
234
- }>, "many">;
235
- }, "strip", z.ZodTypeAny, {
236
- actions: {
237
- input: string;
238
- agent: string;
239
- includeHistory?: boolean | undefined;
240
- }[];
241
- }, {
242
- actions: {
243
- input: string;
244
- agent: string;
245
- includeHistory?: boolean | undefined;
246
- }[];
247
- }>>>;
249
+ type VoiceEventType = 'speaking' | 'writing' | 'error' | string;
250
+ interface VoiceEventMap {
251
+ speaking: {
252
+ audio?: NodeJS.ReadableStream;
248
253
  };
249
- getAgentHistory(agentId: string): {
250
- input: string;
251
- output: string;
252
- timestamp: string;
253
- }[];
254
- /**
255
- * Get the history of all agent interactions that have occurred in this network
256
- * @returns A record of agent interactions, keyed by agent ID
257
- */
258
- getAgentInteractionHistory(): {
259
- [x: string]: {
260
- input: string;
261
- output: string;
262
- timestamp: string;
263
- }[];
254
+ writing: {
255
+ text: string;
256
+ role: 'assistant' | 'user';
264
257
  };
265
- /**
266
- * Get a summary of agent interactions in a more readable format, displayed chronologically
267
- * @returns A formatted string with all agent interactions in chronological order
268
- */
269
- getAgentInteractionSummary(): string;
270
- executeAgent(agentId: string, input: CoreMessage$1[], includeHistory?: boolean): Promise<string>;
271
- getInstructions(): string;
272
- getRoutingAgent(): Agent<ToolsInput, Record<string, Metric>>;
273
- getAgents(): Agent<ToolsInput, Record<string, Metric>>[];
274
- generate<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentGenerateOptions<Z> & {
275
- output?: never;
276
- experimental_output?: never;
277
- }): Promise<GenerateTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown>>;
278
- generate<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentGenerateOptions<Z> & ({
279
- output: Z;
280
- experimental_output?: never;
281
- } | {
282
- experimental_output: Z;
283
- output?: never;
284
- })): Promise<GenerateObjectResult<Z extends ZodSchema ? z.infer<Z> : unknown>>;
285
- stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentStreamOptions<Z> & {
286
- output?: never;
287
- experimental_output?: never;
288
- }): Promise<StreamTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown>>;
289
- stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentStreamOptions<Z> & ({
290
- output: Z;
291
- experimental_output?: never;
292
- } | {
293
- experimental_output: Z;
294
- output?: never;
295
- })): Promise<StreamObjectResult<any, Z extends ZodSchema ? z.infer<Z> : unknown, any>>;
296
- __registerMastra(p: Mastra): void;
297
- }
298
-
299
- declare class Step<TStepId extends string = any, TSchemaIn extends z.ZodSchema | undefined = undefined, TSchemaOut extends z.ZodSchema | undefined = undefined, TContext extends StepExecutionContext<TSchemaIn> = StepExecutionContext<TSchemaIn>> implements StepAction<TStepId, TSchemaIn, TSchemaOut, TContext> {
300
- id: TStepId;
301
- description?: string;
302
- inputSchema?: TSchemaIn;
303
- outputSchema?: TSchemaOut;
304
- payload?: TSchemaIn extends z.ZodSchema ? Partial<z.infer<TSchemaIn>> : unknown;
305
- execute: (context: TContext) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
306
- retryConfig?: RetryConfig;
307
- mastra?: Mastra;
308
- constructor({ id, description, execute, payload, outputSchema, inputSchema, retryConfig, }: StepAction<TStepId, TSchemaIn, TSchemaOut, TContext>);
258
+ error: {
259
+ message: string;
260
+ code?: string;
261
+ details?: unknown;
262
+ };
263
+ [key: string]: unknown;
309
264
  }
310
- declare function createStep<TId extends string, TSchemaIn extends z.ZodSchema | undefined, TSchemaOut extends z.ZodSchema | undefined, TContext extends StepExecutionContext<TSchemaIn>>(opts: StepAction<TId, TSchemaIn, TSchemaOut, TContext>): Step<TId, TSchemaIn, TSchemaOut, TContext>;
311
-
312
- interface WorkflowOptions<TTriggerSchema extends z.ZodObject<any> = any> {
265
+ interface BuiltInModelConfig {
313
266
  name: string;
314
- triggerSchema?: TTriggerSchema;
315
- events?: Record<string, {
316
- schema: z.ZodObject<any>;
317
- }>;
318
- retryConfig?: RetryConfig;
319
- mastra?: Mastra;
320
- }
321
- interface StepExecutionContext<TSchemaIn extends z.ZodSchema | undefined = undefined, TContext extends WorkflowContext = WorkflowContext> extends IExecutionContext<TSchemaIn> {
322
- context: TSchemaIn extends z.ZodSchema ? {
323
- inputData: z.infer<TSchemaIn>;
324
- } & TContext : TContext;
325
- suspend: (payload?: unknown) => Promise<void>;
326
- runId: string;
327
- mastra?: MastraUnion;
328
- }
329
- 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> {
330
- mastra?: Mastra;
331
- payload?: TSchemaIn extends z.ZodSchema ? Partial<z.infer<TSchemaIn>> : unknown;
332
- execute: (context: TContext) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
333
- retryConfig?: RetryConfig;
267
+ apiKey?: string;
334
268
  }
335
- interface SimpleConditionalType {
336
- [key: `${string}.${string}`]: string | Query<any>;
269
+ interface VoiceConfig<T = unknown> {
270
+ listeningModel?: BuiltInModelConfig;
271
+ speechModel?: BuiltInModelConfig;
272
+ speaker?: string;
273
+ name?: string;
274
+ realtimeConfig?: {
275
+ model?: string;
276
+ apiKey?: string;
277
+ options?: T;
278
+ };
337
279
  }
338
- 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' | {
339
- id: string;
340
- };
341
- type StepNode = {
342
- step: StepAction<any, any, any, any>;
343
- config: StepDef<any, any, any, any>[any];
344
- };
345
- type StepGraph = {
346
- initial: StepNode[];
347
- [key: string]: StepNode[];
348
- };
349
- type RetryConfig = {
280
+ declare abstract class MastraVoice<TOptions = unknown, TSpeakOptions = unknown, TListenOptions = unknown, TTools extends ToolsInput = ToolsInput, TEventArgs extends VoiceEventMap = VoiceEventMap, TSpeakerMetadata = unknown> extends MastraBase {
281
+ protected listeningModel?: BuiltInModelConfig;
282
+ protected speechModel?: BuiltInModelConfig;
283
+ protected speaker?: string;
284
+ protected realtimeConfig?: {
285
+ model?: string;
286
+ apiKey?: string;
287
+ options?: TOptions;
288
+ };
289
+ constructor({ listeningModel, speechModel, speaker, realtimeConfig, name }?: VoiceConfig<TOptions>);
290
+ traced<T extends Function>(method: T, methodName: string): T;
291
+ /**
292
+ * Convert text to speech
293
+ * @param input Text or text stream to convert to speech
294
+ * @param options Speech options including speaker and provider-specific options
295
+ * @returns Audio stream
296
+ */
297
+ /**
298
+ * Convert text to speech
299
+ * @param input Text or text stream to convert to speech
300
+ * @param options Speech options including speaker and provider-specific options
301
+ * @returns Audio stream or void if in chat mode
302
+ */
303
+ abstract speak(input: string | NodeJS.ReadableStream, options?: {
304
+ speaker?: string;
305
+ } & TSpeakOptions): Promise<NodeJS.ReadableStream | void>;
306
+ /**
307
+ * Convert speech to text
308
+ * @param audioStream Audio stream to transcribe
309
+ * @param options Provider-specific transcription options
310
+ * @returns Text or text stream
311
+ */
312
+ /**
313
+ * Convert speech to text
314
+ * @param audioStream Audio stream to transcribe
315
+ * @param options Provider-specific transcription options
316
+ * @returns Text, text stream, or void if in chat mode
317
+ */
318
+ abstract listen(audioStream: NodeJS.ReadableStream | unknown, // Allow other audio input types for OpenAI realtime API
319
+ options?: TListenOptions): Promise<string | NodeJS.ReadableStream | void>;
320
+ updateConfig(_options: Record<string, unknown>): void;
321
+ /**
322
+ * Initializes a WebSocket or WebRTC connection for real-time communication
323
+ * @returns Promise that resolves when the connection is established
324
+ */
325
+ connect(_options?: Record<string, unknown>): Promise<void>;
326
+ /**
327
+ * Relay audio data to the voice provider for real-time processing
328
+ * @param audioData Audio data to relay
329
+ */
330
+ send(_audioData: NodeJS.ReadableStream | Int16Array): Promise<void>;
331
+ /**
332
+ * Trigger voice providers to respond
333
+ */
334
+ answer(_options?: Record<string, unknown>): Promise<void>;
335
+ /**
336
+ * Equip the voice provider with tools
337
+ * @param tools Array of tools to add
338
+ */
339
+ addTools(_tools: TTools): void;
340
+ /**
341
+ * Disconnect from the WebSocket or WebRTC connection
342
+ */
343
+ close(): void;
344
+ /**
345
+ * Register an event listener
346
+ * @param event Event name (e.g., 'speaking', 'writing', 'error')
347
+ * @param callback Callback function that receives event data
348
+ */
349
+ on<E extends VoiceEventType>(_event: E, _callback: (data: E extends keyof TEventArgs ? TEventArgs[E] : unknown) => void): void;
350
+ /**
351
+ * Remove an event listener
352
+ * @param event Event name (e.g., 'speaking', 'writing', 'error')
353
+ * @param callback Callback function to remove
354
+ */
355
+ off<E extends VoiceEventType>(_event: E, _callback: (data: E extends keyof TEventArgs ? TEventArgs[E] : unknown) => void): void;
356
+ /**
357
+ * Get available speakers/voices
358
+ * @returns Array of available voice IDs and their metadata
359
+ */
360
+ getSpeakers(): Promise<Array<{
361
+ voiceId: string;
362
+ } & TSpeakerMetadata>>;
363
+ }
364
+
365
+ declare class CompositeVoice extends MastraVoice<unknown, unknown, unknown, ToolsInput, VoiceEventMap> {
366
+ protected speakProvider?: MastraVoice;
367
+ protected listenProvider?: MastraVoice;
368
+ protected realtimeProvider?: MastraVoice;
369
+ constructor({ speakProvider, listenProvider, realtimeProvider, }: {
370
+ speakProvider?: MastraVoice;
371
+ listenProvider?: MastraVoice;
372
+ realtimeProvider?: MastraVoice;
373
+ });
374
+ /**
375
+ * Convert text to speech using the configured provider
376
+ * @param input Text or text stream to convert to speech
377
+ * @param options Speech options including speaker and provider-specific options
378
+ * @returns Audio stream or void if in realtime mode
379
+ */
380
+ speak(input: string | NodeJS.ReadableStream, options?: {
381
+ speaker?: string;
382
+ } & any): Promise<NodeJS.ReadableStream | void>;
383
+ listen(audioStream: NodeJS.ReadableStream, options?: any): Promise<string | void | NodeJS.ReadableStream>;
384
+ getSpeakers(): Promise<{
385
+ voiceId: string;
386
+ }[]>;
387
+ updateConfig(options: Record<string, unknown>): void;
388
+ /**
389
+ * Initializes a WebSocket or WebRTC connection for real-time communication
390
+ * @returns Promise that resolves when the connection is established
391
+ */
392
+ connect(options?: Record<string, unknown>): Promise<void>;
393
+ /**
394
+ * Relay audio data to the voice provider for real-time processing
395
+ * @param audioData Audio data to send
396
+ */
397
+ send(audioData: NodeJS.ReadableStream | Int16Array): Promise<void>;
398
+ /**
399
+ * Trigger voice providers to respond
400
+ */
401
+ answer(options?: Record<string, unknown>): Promise<void>;
402
+ /**
403
+ * Equip the voice provider with tools
404
+ * @param tools Array of tools to add
405
+ */
406
+ addTools(tools: ToolsInput): void;
407
+ /**
408
+ * Disconnect from the WebSocket or WebRTC connection
409
+ */
410
+ close(): void;
411
+ /**
412
+ * Register an event listener
413
+ * @param event Event name (e.g., 'speaking', 'writing', 'error')
414
+ * @param callback Callback function that receives event data
415
+ */
416
+ on<E extends VoiceEventType>(event: E, callback: (data: E extends keyof VoiceEventMap ? VoiceEventMap[E] : unknown) => void): void;
417
+ /**
418
+ * Remove an event listener
419
+ * @param event Event name (e.g., 'speaking', 'writing', 'error')
420
+ * @param callback Callback function to remove
421
+ */
422
+ off<E extends VoiceEventType>(event: E, callback: (data: E extends keyof VoiceEventMap ? VoiceEventMap[E] : unknown) => void): void;
423
+ }
424
+
425
+ type ToolsInput = Record<string, ToolAction<any, any, any> | VercelTool>;
426
+ type ToolsetsInput = Record<string, ToolsInput>;
427
+ type MastraLanguageModel = LanguageModelV1;
428
+ interface AgentConfig<TTools extends ToolsInput = ToolsInput, TMetrics extends Record<string, Metric> = Record<string, Metric>> {
429
+ name: string;
430
+ instructions: string;
431
+ model: MastraLanguageModel;
432
+ tools?: TTools;
433
+ mastra?: Mastra;
434
+ /** @deprecated This property is deprecated. Use evals instead to add evaluation metrics. */
435
+ metrics?: TMetrics;
436
+ evals?: TMetrics;
437
+ memory?: MastraMemory;
438
+ voice?: CompositeVoice;
439
+ }
440
+ type AgentGenerateOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
441
+ instructions?: string;
442
+ toolsets?: ToolsetsInput;
443
+ context?: CoreMessage[];
444
+ memoryOptions?: MemoryConfig;
445
+ runId?: string;
446
+ onStepFinish?: (step: string) => void;
447
+ maxSteps?: number;
448
+ output?: OutputType | Z;
449
+ experimental_output?: Z;
450
+ toolChoice?: 'auto' | 'none' | 'required' | {
451
+ type: 'tool';
452
+ toolName: string;
453
+ };
454
+ telemetry?: TelemetrySettings;
455
+ } & ({
456
+ resourceId?: undefined;
457
+ threadId?: undefined;
458
+ } | {
459
+ resourceId: string;
460
+ threadId: string;
461
+ }) & (Z extends undefined ? DefaultLLMTextOptions : DefaultLLMTextObjectOptions);
462
+ type AgentStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
463
+ instructions?: string;
464
+ toolsets?: ToolsetsInput;
465
+ context?: CoreMessage[];
466
+ memoryOptions?: MemoryConfig;
467
+ runId?: string;
468
+ onFinish?: (result: string) => unknown;
469
+ onStepFinish?: (step: string) => unknown;
470
+ maxSteps?: number;
471
+ output?: OutputType | Z;
472
+ temperature?: number;
473
+ toolChoice?: 'auto' | 'none' | 'required' | {
474
+ type: 'tool';
475
+ toolName: string;
476
+ };
477
+ experimental_output?: Z;
478
+ telemetry?: TelemetrySettings;
479
+ } & ({
480
+ resourceId?: undefined;
481
+ threadId?: undefined;
482
+ } | {
483
+ resourceId: string;
484
+ threadId: string;
485
+ }) & (Z extends undefined ? DefaultLLMStreamOptions : DefaultLLMStreamObjectOptions);
486
+
487
+ interface WorkflowOptions<TWorkflowName extends string = string, TSteps extends Step<string, any, any, any>[] = Step<string, any, any, any>[], TTriggerSchema extends z.ZodObject<any> = any, TResultSchema extends z.ZodObject<any> = any> {
488
+ steps?: TSteps;
489
+ name: TWorkflowName;
490
+ triggerSchema?: TTriggerSchema;
491
+ result?: {
492
+ schema: TResultSchema;
493
+ mapping?: {
494
+ [K in keyof z.infer<TResultSchema>]?: any;
495
+ };
496
+ };
497
+ events?: Record<string, {
498
+ schema: z.ZodObject<any>;
499
+ }>;
500
+ retryConfig?: RetryConfig;
501
+ mastra?: Mastra;
502
+ }
503
+ interface StepExecutionContext<TSchemaIn extends z.ZodSchema | undefined = undefined, TContext extends WorkflowContext = WorkflowContext> extends IExecutionContext<TSchemaIn> {
504
+ context: TSchemaIn extends z.ZodSchema ? {
505
+ inputData: z.infer<TSchemaIn>;
506
+ } & TContext : TContext;
507
+ suspend: (payload?: unknown, softSuspend?: any) => Promise<void>;
508
+ runId: string;
509
+ emit: (event: string, data: any) => void;
510
+ mastra?: MastraUnion;
511
+ }
512
+ 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> {
513
+ mastra?: Mastra;
514
+ payload?: TSchemaIn extends z.ZodSchema ? Partial<z.infer<TSchemaIn>> : unknown;
515
+ execute: (context: TContext) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
516
+ retryConfig?: RetryConfig;
517
+ workflow?: Workflow;
518
+ }
519
+ interface SimpleConditionalType {
520
+ [key: `${string}.${string}`]: string | Query<any>;
521
+ }
522
+ 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' | {
523
+ id: string;
524
+ };
525
+ type StepNode = {
526
+ step: StepAction<any, any, any, any>;
527
+ config: StepDef<any, any, any, any>[any];
528
+ };
529
+ type StepGraph = {
530
+ initial: StepNode[];
531
+ [key: string]: StepNode[];
532
+ };
533
+ type RetryConfig = {
350
534
  attempts?: number;
351
535
  delay?: number;
352
536
  };
@@ -391,7 +575,7 @@ type StepDef<TStepId extends TSteps[number]['id'], TSteps extends StepAction<any
391
575
  }) => Promise<boolean | WhenConditionReturnValue>);
392
576
  serializedWhen?: Condition<any, any> | string;
393
577
  loopLabel?: string;
394
- loopType?: 'when' | 'until';
578
+ loopType?: 'while' | 'until';
395
579
  data: TSchemaIn;
396
580
  handler: (args: ActionContext<TSchemaIn>) => Promise<z.infer<TSchemaOut>>;
397
581
  }>;
@@ -423,16 +607,17 @@ interface StepConfig<TStep extends StepAction<any, any, any, any>, CondStep exte
423
607
  mastra?: Mastra;
424
608
  }) => Promise<boolean | WhenConditionReturnValue>);
425
609
  loopLabel?: string;
426
- loopType?: 'when' | 'until';
610
+ loopType?: 'while' | 'until' | undefined;
427
611
  };
428
612
  }
429
613
  type StepSuccess<T> = {
430
614
  status: 'success';
431
615
  output: T;
432
616
  };
433
- type StepSuspended = {
617
+ type StepSuspended<T> = {
434
618
  status: 'suspended';
435
619
  suspendPayload?: any;
620
+ output?: T;
436
621
  };
437
622
  type StepWaiting = {
438
623
  status: 'waiting';
@@ -444,14 +629,15 @@ type StepFailure = {
444
629
  type StepSkipped = {
445
630
  status: 'skipped';
446
631
  };
447
- type StepResult<T> = StepSuccess<T> | StepFailure | StepSuspended | StepWaiting | StepSkipped;
632
+ type StepResult<T> = StepSuccess<T> | StepFailure | StepSuspended<T> | StepWaiting | StepSkipped;
448
633
  type StepsRecord<T extends readonly Step<any, any, z.ZodType<any> | undefined>[]> = {
449
634
  [K in T[number]['id']]: Extract<T[number], {
450
635
  id: K;
451
636
  }>;
452
637
  };
453
- interface WorkflowRunResult<T extends z.ZodType<any>, TSteps extends Step<string, any, z.ZodType<any> | undefined>[]> {
638
+ interface WorkflowRunResult<T extends z.ZodObject<any>, TSteps extends Step<string, any, z.ZodType<any> | undefined>[], TResult extends z.ZodObject<any>> {
454
639
  triggerData?: z.infer<T>;
640
+ result?: z.infer<TResult>;
455
641
  results: {
456
642
  [K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]['outputSchema'] extends undefined ? StepResult<unknown> : StepResult<z.infer<NonNullable<StepsRecord<TSteps>[K]['outputSchema']>>>;
457
643
  };
@@ -462,6 +648,10 @@ interface WorkflowRunResult<T extends z.ZodType<any>, TSteps extends Step<string
462
648
  }>;
463
649
  }
464
650
  interface WorkflowContext<TTrigger extends z.ZodObject<any> = any, TSteps extends Step<string, any, any, any>[] = Step<string, any, any, any>[], TInputData extends Record<string, any> = Record<string, any>> {
651
+ isResume?: {
652
+ runId: string;
653
+ stepId: string;
654
+ };
465
655
  mastra?: MastraUnion;
466
656
  steps: {
467
657
  [K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]['outputSchema'] extends undefined ? StepResult<unknown> : StepResult<z.infer<NonNullable<StepsRecord<TSteps>[K]['outputSchema']>>>;
@@ -494,6 +684,7 @@ type WorkflowEvent = {
494
684
  type: 'SUSPENDED';
495
685
  stepId: string;
496
686
  suspendPayload?: any;
687
+ softSuspend?: any;
497
688
  } | {
498
689
  type: 'WAITING';
499
690
  stepId: string;
@@ -668,16 +859,29 @@ type WorkflowResumeResult<TTriggerSchema extends z.ZodObject<any>> = {
668
859
  results: Record<string, StepResult<any>>;
669
860
  };
670
861
 
671
- declare class Machine<TSteps extends Step<any, any, any>[] = any, TTriggerSchema extends z.ZodObject<any> = any> extends EventEmitter {
672
- #private;
673
- logger: Logger;
674
- name: string;
675
- constructor({ logger, mastra, workflowInstance, executionSpan, name, runId, steps, stepGraph, retryConfig, startStepId, }: {
676
- logger: Logger;
677
- mastra?: Mastra;
678
- workflowInstance: WorkflowInstance;
679
- executionSpan?: Span;
680
- name: string;
862
+ declare class Step<TStepId extends string = any, TSchemaIn extends z.ZodSchema | undefined = undefined, TSchemaOut extends z.ZodSchema | undefined = undefined, TContext extends StepExecutionContext<TSchemaIn> = StepExecutionContext<TSchemaIn>> implements StepAction<TStepId, TSchemaIn, TSchemaOut, TContext> {
863
+ id: TStepId;
864
+ description?: string;
865
+ inputSchema?: TSchemaIn;
866
+ outputSchema?: TSchemaOut;
867
+ payload?: TSchemaIn extends z.ZodSchema ? Partial<z.infer<TSchemaIn>> : unknown;
868
+ execute: (context: TContext) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
869
+ retryConfig?: RetryConfig;
870
+ mastra?: Mastra;
871
+ constructor({ id, description, execute, payload, outputSchema, inputSchema, retryConfig, }: StepAction<TStepId, TSchemaIn, TSchemaOut, TContext>);
872
+ }
873
+ declare function createStep<TId extends string, TSchemaIn extends z.ZodSchema | undefined, TSchemaOut extends z.ZodSchema | undefined, TContext extends StepExecutionContext<TSchemaIn>>(opts: StepAction<TId, TSchemaIn, TSchemaOut, TContext>): Step<TId, TSchemaIn, TSchemaOut, TContext>;
874
+
875
+ declare class Machine<TSteps extends Step<any, any, any>[] = any, TTriggerSchema extends z.ZodObject<any> = any, TResultSchema extends z.ZodObject<any> = any> extends EventEmitter {
876
+ #private;
877
+ logger: Logger;
878
+ name: string;
879
+ constructor({ logger, mastra, workflowInstance, executionSpan, name, runId, steps, stepGraph, retryConfig, startStepId, }: {
880
+ logger: Logger;
881
+ mastra?: Mastra;
882
+ workflowInstance: WorkflowInstance;
883
+ executionSpan?: Span;
884
+ name: string;
681
885
  runId: string;
682
886
  steps: Record<string, TSteps[0]>;
683
887
  stepGraph: StepGraph;
@@ -690,7 +894,7 @@ declare class Machine<TSteps extends Step<any, any, any>[] = any, TTriggerSchema
690
894
  input?: any;
691
895
  snapshot?: Snapshot<any>;
692
896
  resumeData?: any;
693
- }): Promise<Pick<WorkflowRunResult<TTriggerSchema, TSteps>, 'results' | 'activePaths'>>;
897
+ }): Promise<Pick<WorkflowRunResult<TTriggerSchema, TSteps, TResultSchema>, 'results' | 'activePaths'>>;
694
898
  private initializeMachine;
695
899
  getSnapshot(): xstate.MachineSnapshot<Omit<WorkflowContext<any, Step<string, any, any, any>[], Record<string, any>>, "getStepResult">, {
696
900
  type: "RESET_TO_PENDING";
@@ -706,6 +910,7 @@ declare class Machine<TSteps extends Step<any, any, any>[] = any, TTriggerSchema
706
910
  type: "SUSPENDED";
707
911
  stepId: string;
708
912
  suspendPayload?: any;
913
+ softSuspend?: any;
709
914
  } | {
710
915
  type: "WAITING";
711
916
  stepId: string;
@@ -968,6 +1173,7 @@ declare class Machine<TSteps extends Step<any, any, any>[] = any, TTriggerSchema
968
1173
  type: "SUSPENDED";
969
1174
  stepId: string;
970
1175
  suspendPayload?: any;
1176
+ softSuspend?: any;
971
1177
  } | {
972
1178
  type: "WAITING";
973
1179
  stepId: string;
@@ -991,6 +1197,7 @@ declare class Machine<TSteps extends Step<any, any, any>[] = any, TTriggerSchema
991
1197
  type: "SUSPENDED";
992
1198
  stepId: string;
993
1199
  suspendPayload?: any;
1200
+ softSuspend?: any;
994
1201
  } | {
995
1202
  type: "WAITING";
996
1203
  stepId: string;
@@ -1003,13 +1210,14 @@ declare class Machine<TSteps extends Step<any, any, any>[] = any, TTriggerSchema
1003
1210
  }, xstate.AnyEventObject>;
1004
1211
  }) => {
1005
1212
  mastra?: MastraUnion | undefined;
1213
+ isResume?: {
1214
+ runId: string;
1215
+ stepId: string;
1216
+ } | undefined;
1006
1217
  steps: {
1007
1218
  [x: string]: {
1008
1219
  status: "failed";
1009
1220
  error: string;
1010
- } | {
1011
- status: "suspended";
1012
- suspendPayload?: any;
1013
1221
  } | {
1014
1222
  status: "waiting";
1015
1223
  } | {
@@ -1017,9 +1225,17 @@ declare class Machine<TSteps extends Step<any, any, any>[] = any, TTriggerSchema
1017
1225
  } | {
1018
1226
  status: "success";
1019
1227
  output: unknown;
1228
+ } | {
1229
+ status: "suspended";
1230
+ suspendPayload?: any;
1231
+ output?: unknown;
1020
1232
  } | {
1021
1233
  status: "success";
1022
1234
  output: any;
1235
+ } | {
1236
+ status: "suspended";
1237
+ suspendPayload?: any;
1238
+ output?: any;
1023
1239
  };
1024
1240
  };
1025
1241
  triggerData: any;
@@ -1030,26 +1246,26 @@ declare class Machine<TSteps extends Step<any, any, any>[] = any, TTriggerSchema
1030
1246
  }> | undefined;
1031
1247
  }
1032
1248
 
1033
- interface WorkflowResultReturn<T extends z.ZodType<any>, TSteps extends Step<any, any, any>[]> {
1249
+ interface WorkflowResultReturn<TResult extends z.ZodObject<any>, T extends z.ZodObject<any>, TSteps extends Step<any, any, any>[]> {
1034
1250
  runId: string;
1035
1251
  start: (props?: {
1036
1252
  triggerData?: z.infer<T>;
1037
- } | undefined) => Promise<WorkflowRunResult<T, TSteps>>;
1253
+ } | undefined) => Promise<WorkflowRunResult<T, TSteps, TResult>>;
1038
1254
  watch: (onTransition: (state: WorkflowRunState) => void) => () => void;
1039
1255
  resume: (props: {
1040
1256
  stepId: string;
1041
1257
  context?: Record<string, any>;
1042
- }) => Promise<Omit<WorkflowRunResult<T, TSteps>, 'runId'> | undefined>;
1043
- resumeWithEvent: (eventName: string, data: any) => Promise<Omit<WorkflowRunResult<T, TSteps>, 'runId'> | undefined>;
1258
+ }) => Promise<Omit<WorkflowRunResult<T, TSteps, TResult>, 'runId'> | undefined>;
1259
+ resumeWithEvent: (eventName: string, data: any) => Promise<Omit<WorkflowRunResult<T, TSteps, TResult>, 'runId'> | undefined>;
1044
1260
  }
1045
- declare class WorkflowInstance<TSteps extends Step<any, any, any>[] = any, TTriggerSchema extends z.ZodObject<any> = any> implements WorkflowResultReturn<TTriggerSchema, TSteps> {
1261
+ declare class WorkflowInstance<TSteps extends Step<any, any, any>[] = any, TTriggerSchema extends z.ZodObject<any> = any, TResult extends z.ZodObject<any> = any> implements WorkflowResultReturn<TResult, TTriggerSchema, TSteps> {
1046
1262
  #private;
1047
1263
  name: string;
1048
1264
  logger: Logger;
1049
1265
  events?: Record<string, {
1050
1266
  schema: z.ZodObject<any>;
1051
1267
  }>;
1052
- constructor({ name, logger, steps, runId, retryConfig, mastra, stepGraph, stepSubscriberGraph, onFinish, onStepTransition, events, }: {
1268
+ constructor({ name, logger, steps, runId, retryConfig, mastra, stepGraph, stepSubscriberGraph, onFinish, onStepTransition, resultMapping, events, }: {
1053
1269
  name: string;
1054
1270
  logger: Logger;
1055
1271
  steps: Record<string, StepAction<any, any, any, any>>;
@@ -1060,6 +1276,10 @@ declare class WorkflowInstance<TSteps extends Step<any, any, any>[] = any, TTrig
1060
1276
  stepSubscriberGraph: Record<string, StepGraph>;
1061
1277
  onFinish?: () => void;
1062
1278
  onStepTransition?: Set<(state: WorkflowRunState) => void | Promise<void>>;
1279
+ resultMapping?: Record<string, {
1280
+ step: StepAction<any, any, any, any>;
1281
+ path: string;
1282
+ }>;
1063
1283
  events?: Record<string, {
1064
1284
  schema: z.ZodObject<any>;
1065
1285
  }>;
@@ -1072,8 +1292,9 @@ declare class WorkflowInstance<TSteps extends Step<any, any, any>[] = any, TTrig
1072
1292
  triggerData?: z.infer<TTriggerSchema>;
1073
1293
  }): Promise<{
1074
1294
  runId: string;
1075
- triggerData?: z.TypeOf<TTriggerSchema> | undefined;
1295
+ result?: z.TypeOf<TResult> | undefined;
1076
1296
  results: { [K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]["outputSchema"] extends undefined ? StepResult<unknown> : StepResult<z.TypeOf<NonNullable<StepsRecord<TSteps>[K]["outputSchema"]>>>; };
1297
+ triggerData?: z.TypeOf<TTriggerSchema> | undefined;
1077
1298
  activePaths: Map<TSteps[number]["id"], {
1078
1299
  status: string;
1079
1300
  suspendPayload?: any;
@@ -1085,30 +1306,35 @@ declare class WorkflowInstance<TSteps extends Step<any, any, any>[] = any, TTrig
1085
1306
  triggerData?: z.infer<TTriggerSchema>;
1086
1307
  snapshot?: Snapshot<any>;
1087
1308
  resumeData?: any;
1088
- }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps>, 'runId'>>;
1309
+ }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, TResult>, 'runId'>>;
1089
1310
  hasSubscribers(stepId: string): boolean;
1090
- runMachine(parentStepId: string, input: any): Promise<(Pick<WorkflowRunResult<any, any>, "results" | "activePaths"> | undefined)[]>;
1311
+ runMachine(parentStepId: string, input: any): Promise<(Pick<WorkflowRunResult<any, any, any>, "results" | "activePaths"> | undefined)[]>;
1091
1312
  suspend(stepId: string, machine: Machine<TSteps, TTriggerSchema>): Promise<void>;
1092
1313
  /**
1093
1314
  * Persists the workflow state to the database
1094
1315
  */
1095
1316
  persistWorkflowSnapshot(): Promise<void>;
1096
1317
  getState(): Promise<WorkflowRunState | null>;
1097
- resumeWithEvent(eventName: string, data: any): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps>, "runId"> | undefined>;
1318
+ resumeWithEvent(eventName: string, data: any): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, TResult>, "runId"> | undefined>;
1098
1319
  resume({ stepId, context: resumeContext }: {
1099
1320
  stepId: string;
1100
1321
  context?: Record<string, any>;
1101
- }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps>, "runId"> | undefined>;
1322
+ }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, TResult>, "runId"> | undefined>;
1102
1323
  _resume({ stepId, context: resumeContext }: {
1103
1324
  stepId: string;
1104
1325
  context?: Record<string, any>;
1105
- }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps>, "runId"> | undefined>;
1326
+ }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, TResult>, "runId"> | undefined>;
1106
1327
  }
1107
1328
 
1108
- declare class Workflow<TSteps extends Step<string, any, any>[] = Step<string, any, any>[], TTriggerSchema extends z.ZodObject<any> = any> extends MastraBase {
1329
+ declare class Workflow<TSteps extends Step<string, any, any>[] = Step<string, any, any>[], TStepId extends string = string, TTriggerSchema extends z.ZodObject<any> = any, TResultSchema extends z.ZodObject<any> = any> extends MastraBase {
1109
1330
  #private;
1110
- name: string;
1331
+ name: TStepId;
1111
1332
  triggerSchema?: TTriggerSchema;
1333
+ resultSchema?: TResultSchema;
1334
+ resultMapping?: Record<string, {
1335
+ step: StepAction<string, any, any, any>;
1336
+ path: string;
1337
+ }>;
1112
1338
  events?: Record<string, {
1113
1339
  schema: z.ZodObject<any>;
1114
1340
  }>;
@@ -1117,15 +1343,18 @@ declare class Workflow<TSteps extends Step<string, any, any>[] = Step<string, an
1117
1343
  * @param name - Identifier for the workflow (not necessarily unique)
1118
1344
  * @param logger - Optional logger instance
1119
1345
  */
1120
- constructor({ name, triggerSchema, retryConfig, mastra, events }: WorkflowOptions<TTriggerSchema>);
1121
- step<TStep extends StepAction<any, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>>(step: TStep, config?: StepConfig<TStep, CondStep, VarStep, TTriggerSchema>): this;
1122
- then<TStep extends StepAction<any, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>>(step: TStep, config?: StepConfig<TStep, CondStep, VarStep, TTriggerSchema>): this;
1346
+ constructor({ name, triggerSchema, result, retryConfig, mastra, events, }: WorkflowOptions<TStepId, TSteps, TTriggerSchema, TResultSchema>);
1347
+ step<TWorkflow extends Workflow<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>): this;
1348
+ 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>): this;
1349
+ 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;
1350
+ then<TWorkflow extends Workflow<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;
1123
1351
  private loop;
1124
- while<FallbackStep extends StepAction<any, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>>(condition: StepConfig<FallbackStep, CondStep, VarStep, TTriggerSchema>['when'], fallbackStep: FallbackStep): this;
1125
- until<FallbackStep extends StepAction<any, 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): this;
1126
- if<TStep extends StepAction<any, any, any, any>>(condition: StepConfig<TStep, any, any, TTriggerSchema>['when']): this;
1352
+ 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>['when'], fallbackStep: FallbackStep): this;
1353
+ 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): this;
1354
+ if<TStep extends StepAction<string, any, any, any>>(condition: StepConfig<TStep, any, any, TTriggerSchema>['when'], ifStep?: TStep | Workflow, elseStep?: TStep | Workflow): this;
1127
1355
  else(): this;
1128
- after<TStep extends StepAction<any, any, any, any>>(steps: TStep | TStep[]): Omit<typeof this, "then" | "after">;
1356
+ after<TStep extends StepAction<string, any, any, any>>(steps: TStep | TStep[]): Omit<typeof this, 'then' | 'after'>;
1357
+ after<TWorkflow extends Workflow<any, any, any, any>>(steps: TWorkflow | TWorkflow[]): Omit<typeof this, 'then' | 'after'>;
1129
1358
  afterEvent(eventName: string): this;
1130
1359
  /**
1131
1360
  * Executes the workflow with the given trigger data
@@ -1138,13 +1367,13 @@ declare class Workflow<TSteps extends Step<string, any, any>[] = Step<string, an
1138
1367
  events?: Record<string, {
1139
1368
  schema: z.ZodObject<any>;
1140
1369
  }>;
1141
- }): WorkflowResultReturn<TTriggerSchema, TSteps>;
1370
+ }): WorkflowResultReturn<TResultSchema, TTriggerSchema, TSteps>;
1142
1371
  /**
1143
1372
  * Gets a workflow run instance by ID
1144
1373
  * @param runId - ID of the run to retrieve
1145
1374
  * @returns The workflow run instance if found, undefined otherwise
1146
1375
  */
1147
- getRun(runId: string): WorkflowInstance<TSteps, TTriggerSchema> | undefined;
1376
+ getRun(runId: string): WorkflowInstance<TSteps, TTriggerSchema, any> | undefined;
1148
1377
  /**
1149
1378
  * Rebuilds the machine with the current steps configuration and validates the workflow
1150
1379
  *
@@ -1160,16 +1389,135 @@ declare class Workflow<TSteps extends Step<string, any, any>[] = Step<string, an
1160
1389
  runId: string;
1161
1390
  stepId: string;
1162
1391
  context?: Record<string, any>;
1163
- }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps>, "runId"> | undefined>;
1392
+ }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, any>, "runId"> | undefined>;
1164
1393
  watch(onTransition: (state: WorkflowRunState) => void): () => void;
1165
- resumeWithEvent(runId: string, eventName: string, data: any): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps>, "runId"> | undefined>;
1394
+ resumeWithEvent(runId: string, eventName: string, data: any): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, any>, "runId"> | undefined>;
1166
1395
  __registerMastra(mastra: Mastra): void;
1167
1396
  __registerPrimitives(p: MastraPrimitives): void;
1168
1397
  get stepGraph(): StepGraph;
1169
1398
  get stepSubscriberGraph(): Record<string, StepGraph>;
1170
1399
  get serializedStepGraph(): StepGraph;
1171
1400
  get serializedStepSubscriberGraph(): Record<string, StepGraph>;
1172
- get steps(): Record<string, StepAction<any, any, any, any>>;
1401
+ get steps(): Record<string, StepAction<string, any, any, any>>;
1402
+ setNested(isNested: boolean): void;
1403
+ get isNested(): boolean;
1404
+ toStep(): Step<TStepId, TTriggerSchema, z.ZodType<WorkflowRunResult<TTriggerSchema, TSteps, TResultSchema>>, any>;
1405
+ }
1406
+
1407
+ type AgentNetworkConfig = {
1408
+ name: string;
1409
+ agents: Agent[];
1410
+ model: LanguageModelV1;
1411
+ instructions: string;
1412
+ };
1413
+
1414
+ declare class AgentNetwork extends MastraBase {
1415
+ #private;
1416
+ constructor(config: AgentNetworkConfig);
1417
+ formatAgentId(name: string): string;
1418
+ getTools(): {
1419
+ transmit: Tool<z.ZodObject<{
1420
+ actions: z.ZodArray<z.ZodObject<{
1421
+ agent: z.ZodString;
1422
+ input: z.ZodString;
1423
+ includeHistory: z.ZodOptional<z.ZodBoolean>;
1424
+ }, "strip", z.ZodTypeAny, {
1425
+ input: string;
1426
+ agent: string;
1427
+ includeHistory?: boolean | undefined;
1428
+ }, {
1429
+ input: string;
1430
+ agent: string;
1431
+ includeHistory?: boolean | undefined;
1432
+ }>, "many">;
1433
+ }, "strip", z.ZodTypeAny, {
1434
+ actions: {
1435
+ input: string;
1436
+ agent: string;
1437
+ includeHistory?: boolean | undefined;
1438
+ }[];
1439
+ }, {
1440
+ actions: {
1441
+ input: string;
1442
+ agent: string;
1443
+ includeHistory?: boolean | undefined;
1444
+ }[];
1445
+ }>, undefined, ToolExecutionContext<z.ZodObject<{
1446
+ actions: z.ZodArray<z.ZodObject<{
1447
+ agent: z.ZodString;
1448
+ input: z.ZodString;
1449
+ includeHistory: z.ZodOptional<z.ZodBoolean>;
1450
+ }, "strip", z.ZodTypeAny, {
1451
+ input: string;
1452
+ agent: string;
1453
+ includeHistory?: boolean | undefined;
1454
+ }, {
1455
+ input: string;
1456
+ agent: string;
1457
+ includeHistory?: boolean | undefined;
1458
+ }>, "many">;
1459
+ }, "strip", z.ZodTypeAny, {
1460
+ actions: {
1461
+ input: string;
1462
+ agent: string;
1463
+ includeHistory?: boolean | undefined;
1464
+ }[];
1465
+ }, {
1466
+ actions: {
1467
+ input: string;
1468
+ agent: string;
1469
+ includeHistory?: boolean | undefined;
1470
+ }[];
1471
+ }>>>;
1472
+ };
1473
+ getAgentHistory(agentId: string): {
1474
+ input: string;
1475
+ output: string;
1476
+ timestamp: string;
1477
+ }[];
1478
+ /**
1479
+ * Get the history of all agent interactions that have occurred in this network
1480
+ * @returns A record of agent interactions, keyed by agent ID
1481
+ */
1482
+ getAgentInteractionHistory(): {
1483
+ [x: string]: {
1484
+ input: string;
1485
+ output: string;
1486
+ timestamp: string;
1487
+ }[];
1488
+ };
1489
+ /**
1490
+ * Get a summary of agent interactions in a more readable format, displayed chronologically
1491
+ * @returns A formatted string with all agent interactions in chronological order
1492
+ */
1493
+ getAgentInteractionSummary(): string;
1494
+ executeAgent(agentId: string, input: CoreMessage$1[], includeHistory?: boolean): Promise<string>;
1495
+ getInstructions(): string;
1496
+ getRoutingAgent(): Agent<ToolsInput, Record<string, Metric>>;
1497
+ getAgents(): Agent<ToolsInput, Record<string, Metric>>[];
1498
+ generate<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentGenerateOptions<Z> & {
1499
+ output?: never;
1500
+ experimental_output?: never;
1501
+ }): Promise<GenerateTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown>>;
1502
+ generate<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentGenerateOptions<Z> & ({
1503
+ output: Z;
1504
+ experimental_output?: never;
1505
+ } | {
1506
+ experimental_output: Z;
1507
+ output?: never;
1508
+ })): Promise<GenerateObjectResult<Z extends ZodSchema ? z.infer<Z> : unknown>>;
1509
+ stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentStreamOptions<Z> & {
1510
+ output?: never;
1511
+ experimental_output?: never;
1512
+ }): Promise<StreamTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown>>;
1513
+ stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentStreamOptions<Z> & ({
1514
+ output: Z;
1515
+ experimental_output?: never;
1516
+ } | {
1517
+ experimental_output: Z;
1518
+ output?: never;
1519
+ })): Promise<StreamObjectResult<any, Z extends ZodSchema ? z.infer<Z> : unknown, any>>;
1520
+ __registerMastra(p: Mastra): void;
1173
1521
  }
1174
1522
 
1175
1523
  interface Config<TAgents extends Record<string, Agent<any>> = Record<string, Agent<any>>, TWorkflows extends Record<string, Workflow> = Record<string, Workflow>, TVectors extends Record<string, MastraVector> = Record<string, MastraVector>, TTTS extends Record<string, MastraTTS> = Record<string, MastraTTS>, TLogger extends Logger = Logger, TNetworks extends Record<string, AgentNetwork> = Record<string, AgentNetwork>> {
@@ -1272,310 +1620,6 @@ interface IAction<TId extends string, TSchemaIn extends z.ZodSchema | undefined,
1272
1620
  execute?: (context: TContext, options?: TOptions) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
1273
1621
  }
1274
1622
 
1275
- type VoiceEventType = 'speaking' | 'writing' | 'error' | string;
1276
- interface VoiceEventMap {
1277
- speaking: {
1278
- audio?: NodeJS.ReadableStream;
1279
- };
1280
- writing: {
1281
- text: string;
1282
- role: 'assistant' | 'user';
1283
- };
1284
- error: {
1285
- message: string;
1286
- code?: string;
1287
- details?: unknown;
1288
- };
1289
- [key: string]: unknown;
1290
- }
1291
- interface BuiltInModelConfig {
1292
- name: string;
1293
- apiKey?: string;
1294
- }
1295
- interface VoiceConfig<T = unknown> {
1296
- listeningModel?: BuiltInModelConfig;
1297
- speechModel?: BuiltInModelConfig;
1298
- speaker?: string;
1299
- name?: string;
1300
- realtimeConfig?: {
1301
- model?: string;
1302
- apiKey?: string;
1303
- options?: T;
1304
- };
1305
- }
1306
- declare abstract class MastraVoice<TOptions = unknown, TSpeakOptions = unknown, TListenOptions = unknown, TTools extends ToolsInput = ToolsInput, TEventArgs extends VoiceEventMap = VoiceEventMap, TSpeakerMetadata = unknown> extends MastraBase {
1307
- protected listeningModel?: BuiltInModelConfig;
1308
- protected speechModel?: BuiltInModelConfig;
1309
- protected speaker?: string;
1310
- protected realtimeConfig?: {
1311
- model?: string;
1312
- apiKey?: string;
1313
- options?: TOptions;
1314
- };
1315
- constructor({ listeningModel, speechModel, speaker, realtimeConfig, name }?: VoiceConfig<TOptions>);
1316
- traced<T extends Function>(method: T, methodName: string): T;
1317
- /**
1318
- * Convert text to speech
1319
- * @param input Text or text stream to convert to speech
1320
- * @param options Speech options including speaker and provider-specific options
1321
- * @returns Audio stream
1322
- */
1323
- /**
1324
- * Convert text to speech
1325
- * @param input Text or text stream to convert to speech
1326
- * @param options Speech options including speaker and provider-specific options
1327
- * @returns Audio stream or void if in chat mode
1328
- */
1329
- abstract speak(input: string | NodeJS.ReadableStream, options?: {
1330
- speaker?: string;
1331
- } & TSpeakOptions): Promise<NodeJS.ReadableStream | void>;
1332
- /**
1333
- * Convert speech to text
1334
- * @param audioStream Audio stream to transcribe
1335
- * @param options Provider-specific transcription options
1336
- * @returns Text or text stream
1337
- */
1338
- /**
1339
- * Convert speech to text
1340
- * @param audioStream Audio stream to transcribe
1341
- * @param options Provider-specific transcription options
1342
- * @returns Text, text stream, or void if in chat mode
1343
- */
1344
- abstract listen(audioStream: NodeJS.ReadableStream | unknown, // Allow other audio input types for OpenAI realtime API
1345
- options?: TListenOptions): Promise<string | NodeJS.ReadableStream | void>;
1346
- updateConfig(_options: Record<string, unknown>): void;
1347
- /**
1348
- * Initializes a WebSocket or WebRTC connection for real-time communication
1349
- * @returns Promise that resolves when the connection is established
1350
- */
1351
- connect(_options?: Record<string, unknown>): Promise<void>;
1352
- /**
1353
- * Relay audio data to the voice provider for real-time processing
1354
- * @param audioData Audio data to relay
1355
- */
1356
- send(_audioData: NodeJS.ReadableStream | Int16Array): Promise<void>;
1357
- /**
1358
- * Trigger voice providers to respond
1359
- */
1360
- answer(_options?: Record<string, unknown>): Promise<void>;
1361
- /**
1362
- * Equip the voice provider with tools
1363
- * @param tools Array of tools to add
1364
- */
1365
- addTools(_tools: TTools): void;
1366
- /**
1367
- * Disconnect from the WebSocket or WebRTC connection
1368
- */
1369
- close(): void;
1370
- /**
1371
- * Register an event listener
1372
- * @param event Event name (e.g., 'speaking', 'writing', 'error')
1373
- * @param callback Callback function that receives event data
1374
- */
1375
- on<E extends VoiceEventType>(_event: E, _callback: (data: E extends keyof TEventArgs ? TEventArgs[E] : unknown) => void): void;
1376
- /**
1377
- * Remove an event listener
1378
- * @param event Event name (e.g., 'speaking', 'writing', 'error')
1379
- * @param callback Callback function to remove
1380
- */
1381
- off<E extends VoiceEventType>(_event: E, _callback: (data: E extends keyof TEventArgs ? TEventArgs[E] : unknown) => void): void;
1382
- /**
1383
- * Get available speakers/voices
1384
- * @returns Array of available voice IDs and their metadata
1385
- */
1386
- getSpeakers(): Promise<Array<{
1387
- voiceId: string;
1388
- } & TSpeakerMetadata>>;
1389
- }
1390
-
1391
- declare class CompositeVoice extends MastraVoice<unknown, unknown, unknown, ToolsInput, VoiceEventMap> {
1392
- protected speakProvider?: MastraVoice;
1393
- protected listenProvider?: MastraVoice;
1394
- protected realtimeProvider?: MastraVoice;
1395
- constructor({ speakProvider, listenProvider, realtimeProvider, }: {
1396
- speakProvider?: MastraVoice;
1397
- listenProvider?: MastraVoice;
1398
- realtimeProvider?: MastraVoice;
1399
- });
1400
- /**
1401
- * Convert text to speech using the configured provider
1402
- * @param input Text or text stream to convert to speech
1403
- * @param options Speech options including speaker and provider-specific options
1404
- * @returns Audio stream or void if in realtime mode
1405
- */
1406
- speak(input: string | NodeJS.ReadableStream, options?: {
1407
- speaker?: string;
1408
- } & any): Promise<NodeJS.ReadableStream | void>;
1409
- listen(audioStream: NodeJS.ReadableStream, options?: any): Promise<string | void | NodeJS.ReadableStream>;
1410
- getSpeakers(): Promise<{
1411
- voiceId: string;
1412
- }[]>;
1413
- updateConfig(options: Record<string, unknown>): void;
1414
- /**
1415
- * Initializes a WebSocket or WebRTC connection for real-time communication
1416
- * @returns Promise that resolves when the connection is established
1417
- */
1418
- connect(options?: Record<string, unknown>): Promise<void>;
1419
- /**
1420
- * Relay audio data to the voice provider for real-time processing
1421
- * @param audioData Audio data to send
1422
- */
1423
- send(audioData: NodeJS.ReadableStream | Int16Array): Promise<void>;
1424
- /**
1425
- * Trigger voice providers to respond
1426
- */
1427
- answer(options?: Record<string, unknown>): Promise<void>;
1428
- /**
1429
- * Equip the voice provider with tools
1430
- * @param tools Array of tools to add
1431
- */
1432
- addTools(tools: ToolsInput): void;
1433
- /**
1434
- * Disconnect from the WebSocket or WebRTC connection
1435
- */
1436
- close(): void;
1437
- /**
1438
- * Register an event listener
1439
- * @param event Event name (e.g., 'speaking', 'writing', 'error')
1440
- * @param callback Callback function that receives event data
1441
- */
1442
- on<E extends VoiceEventType>(event: E, callback: (data: E extends keyof VoiceEventMap ? VoiceEventMap[E] : unknown) => void): void;
1443
- /**
1444
- * Remove an event listener
1445
- * @param event Event name (e.g., 'speaking', 'writing', 'error')
1446
- * @param callback Callback function to remove
1447
- */
1448
- off<E extends VoiceEventType>(event: E, callback: (data: E extends keyof VoiceEventMap ? VoiceEventMap[E] : unknown) => void): void;
1449
- }
1450
-
1451
- type ToolsInput = Record<string, ToolAction<any, any, any> | VercelTool>;
1452
- type ToolsetsInput = Record<string, ToolsInput>;
1453
- type MastraLanguageModel = LanguageModelV1;
1454
- interface AgentConfig<TTools extends ToolsInput = ToolsInput, TMetrics extends Record<string, Metric> = Record<string, Metric>> {
1455
- name: string;
1456
- instructions: string;
1457
- model: MastraLanguageModel;
1458
- tools?: TTools;
1459
- mastra?: Mastra;
1460
- /** @deprecated This property is deprecated. Use evals instead to add evaluation metrics. */
1461
- metrics?: TMetrics;
1462
- evals?: TMetrics;
1463
- memory?: MastraMemory;
1464
- voice?: CompositeVoice;
1465
- }
1466
- type AgentGenerateOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
1467
- instructions?: string;
1468
- toolsets?: ToolsetsInput;
1469
- context?: CoreMessage[];
1470
- memoryOptions?: MemoryConfig;
1471
- runId?: string;
1472
- onStepFinish?: (step: string) => void;
1473
- maxSteps?: number;
1474
- output?: OutputType | Z;
1475
- experimental_output?: Z;
1476
- toolChoice?: 'auto' | 'none' | 'required' | {
1477
- type: 'tool';
1478
- toolName: string;
1479
- };
1480
- telemetry?: TelemetrySettings;
1481
- } & ({
1482
- resourceId?: undefined;
1483
- threadId?: undefined;
1484
- } | {
1485
- resourceId: string;
1486
- threadId: string;
1487
- }) & (Z extends undefined ? DefaultLLMTextOptions : DefaultLLMTextObjectOptions);
1488
- type AgentStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
1489
- instructions?: string;
1490
- toolsets?: ToolsetsInput;
1491
- context?: CoreMessage[];
1492
- memoryOptions?: MemoryConfig;
1493
- runId?: string;
1494
- onFinish?: (result: string) => unknown;
1495
- onStepFinish?: (step: string) => unknown;
1496
- maxSteps?: number;
1497
- output?: OutputType | Z;
1498
- temperature?: number;
1499
- toolChoice?: 'auto' | 'none' | 'required' | {
1500
- type: 'tool';
1501
- toolName: string;
1502
- };
1503
- experimental_output?: Z;
1504
- telemetry?: TelemetrySettings;
1505
- } & ({
1506
- resourceId?: undefined;
1507
- threadId?: undefined;
1508
- } | {
1509
- resourceId: string;
1510
- threadId: string;
1511
- }) & (Z extends undefined ? DefaultLLMStreamOptions : DefaultLLMStreamObjectOptions);
1512
-
1513
- type LanguageModel = MastraLanguageModel;
1514
- type CoreMessage = CoreMessage$1;
1515
- type CoreSystemMessage = CoreSystemMessage$1;
1516
- type CoreAssistantMessage = CoreAssistantMessage$1;
1517
- type CoreUserMessage = CoreUserMessage$1;
1518
- type CoreToolMessage = CoreToolMessage$1;
1519
- type EmbedResult<T> = EmbedResult$1<T>;
1520
- type EmbedManyResult<T> = EmbedManyResult$1<T>;
1521
- type BaseStructuredOutputType = 'string' | 'number' | 'boolean' | 'date';
1522
- type StructuredOutputType = 'array' | 'string' | 'number' | 'object' | 'boolean' | 'date';
1523
- type StructuredOutputArrayItem = {
1524
- type: BaseStructuredOutputType;
1525
- } | {
1526
- type: 'object';
1527
- items: StructuredOutput;
1528
- };
1529
- type StructuredOutput = {
1530
- [key: string]: {
1531
- type: BaseStructuredOutputType;
1532
- } | {
1533
- type: 'object';
1534
- items: StructuredOutput;
1535
- } | {
1536
- type: 'array';
1537
- items: StructuredOutputArrayItem;
1538
- };
1539
- };
1540
- 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>;
1541
- 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>;
1542
- type OutputType = StructuredOutput | ZodSchema | JSONSchema7 | undefined;
1543
- type GenerateTextOptions = Parameters<typeof generateText>[0];
1544
- type StreamTextOptions = Parameters<typeof streamText>[0];
1545
- type GenerateObjectOptions = Parameters<typeof generateObject>[0];
1546
- type StreamObjectOptions = Parameters<typeof streamObject>[0];
1547
- type MastraCustomLLMOptionsKeys = 'messages' | 'tools' | 'model' | 'onStepFinish' | 'experimental_output' | 'experimental_telemetry' | 'messages' | 'onFinish' | 'output';
1548
- type DefaultLLMTextOptions = Omit<GenerateTextOptions, MastraCustomLLMOptionsKeys>;
1549
- type DefaultLLMTextObjectOptions = Omit<GenerateObjectOptions, MastraCustomLLMOptionsKeys>;
1550
- type DefaultLLMStreamOptions = Omit<StreamTextOptions, MastraCustomLLMOptionsKeys>;
1551
- type DefaultLLMStreamObjectOptions = Omit<StreamObjectOptions, MastraCustomLLMOptionsKeys>;
1552
- type MastraCustomLLMOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
1553
- tools?: ToolsInput;
1554
- convertedTools?: Record<string, CoreTool>;
1555
- onStepFinish?: (step: string) => void;
1556
- experimental_output?: Z;
1557
- telemetry?: TelemetrySettings;
1558
- threadId?: string;
1559
- resourceId?: string;
1560
- } & Run;
1561
- type LLMTextOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
1562
- messages: CoreMessage[];
1563
- } & MastraCustomLLMOptions<Z> & DefaultLLMTextOptions;
1564
- type LLMTextObjectOptions<T extends ZodSchema | JSONSchema7 | undefined = undefined> = LLMTextOptions<T> & DefaultLLMTextObjectOptions & {
1565
- structuredOutput: JSONSchema7 | z.ZodType<T> | StructuredOutput;
1566
- };
1567
- type LLMStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
1568
- output?: OutputType | Z;
1569
- onFinish?: (result: string) => Promise<void> | void;
1570
- } & MastraCustomLLMOptions<Z> & DefaultLLMStreamOptions;
1571
- type LLMInnerStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
1572
- messages: CoreMessage[];
1573
- onFinish?: (result: string) => Promise<void> | void;
1574
- } & MastraCustomLLMOptions<Z> & DefaultLLMStreamOptions;
1575
- type LLMStreamObjectOptions<T extends ZodSchema | JSONSchema7 | undefined = undefined> = {
1576
- structuredOutput: JSONSchema7 | z.ZodType<T> | StructuredOutput;
1577
- } & LLMInnerStreamOptions<T> & DefaultLLMStreamObjectOptions;
1578
-
1579
1623
  declare class MastraLLMBase extends MastraBase {
1580
1624
  #private;
1581
1625
  constructor({ name, model }: {
@@ -1942,4 +1986,4 @@ declare abstract class MastraStorage extends MastraBase {
1942
1986
  __getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
1943
1987
  }
1944
1988
 
1945
- export { createTool as $, Agent as A, type BaseStructuredOutputType as B, type CoreTool as C, type StructuredOutput as D, type EvalRow as E, type StreamReturn as F, type GenerateReturn as G, type DefaultLLMTextOptions as H, type DefaultLLMTextObjectOptions as I, type DefaultLLMStreamOptions as J, type DefaultLLMStreamObjectOptions as K, type LanguageModel as L, Mastra as M, type LLMTextOptions as N, type OutputType as O, type LLMTextObjectOptions as P, type LLMStreamOptions as Q, type LLMInnerStreamOptions as R, Step as S, type ToolAction as T, type LLMStreamObjectOptions as U, type VercelTool as V, Workflow as W, type Config as X, type MessageResponse as Y, type MemoryConfig as Z, type SharedMemoryConfig as _, type ToolsInput as a, type StepAction as a0, type StepVariableType as a1, type StepNode as a2, type StepGraph as a3, type RetryConfig as a4, type VariableReference as a5, type BaseCondition as a6, type ActionContext as a7, WhenConditionReturnValue as a8, type StepDef as a9, type AgentNetworkConfig as aA, type VoiceEventType as aB, type VoiceEventMap as aC, type VoiceConfig as aD, MastraVoice as aE, CompositeVoice as aF, type ToolsetsInput as aG, type AgentGenerateOptions as aH, type AgentStreamOptions as aI, TABLE_WORKFLOW_SNAPSHOT as aJ, TABLE_EVALS as aK, TABLE_MESSAGES as aL, TABLE_THREADS as aM, TABLE_TRACES as aN, type StepCondition as aa, type StepConfig as ab, type StepResult as ac, type StepsRecord as ad, type WorkflowRunResult as ae, type WorkflowLogMessage as af, type WorkflowEvent as ag, type ResolverFunctionInput as ah, type ResolverFunctionOutput as ai, type SubscriberFunctionOutput as aj, type DependencyCheckOutput as ak, type StepResolverOutput as al, type WorkflowActors as am, type WorkflowActionParams as an, type WorkflowActions as ao, type WorkflowState as ap, type StepId as aq, type ExtractSchemaFromStep as ar, type ExtractStepResult as as, type StepInputType as at, type ExtractSchemaType as au, type PathsToStringProps as av, type WorkflowRunState as aw, type WorkflowResumeResult as ax, createStep as ay, type MastraLanguageModel as az, type MastraPrimitives as b, MastraMemory as c, type StepExecutionContext as d, type WorkflowContext as e, AgentNetwork as f, MastraStorage as g, type TABLE_NAMES as h, type StorageColumn as i, type StorageThreadType as j, type MessageType as k, type StorageGetMessagesArg as l, type AgentConfig as m, type ToolExecutionContext as n, Tool as o, type WorkflowOptions as p, type WorkflowRow as q, type CoreMessage as r, type CoreSystemMessage as s, type CoreAssistantMessage as t, type CoreUserMessage as u, type CoreToolMessage as v, type EmbedResult as w, type EmbedManyResult as x, type StructuredOutputType as y, type StructuredOutputArrayItem as z };
1989
+ export { createTool as $, Agent as A, type BaseStructuredOutputType as B, type CoreTool as C, type StructuredOutput as D, type EvalRow as E, type StreamReturn as F, type GenerateReturn as G, type DefaultLLMTextOptions as H, type DefaultLLMTextObjectOptions as I, type DefaultLLMStreamOptions as J, type DefaultLLMStreamObjectOptions as K, type LanguageModel as L, Mastra as M, type LLMTextOptions as N, type OutputType as O, type LLMTextObjectOptions as P, type LLMStreamOptions as Q, type LLMInnerStreamOptions as R, Step as S, type ToolAction as T, type LLMStreamObjectOptions as U, type VercelTool as V, Workflow as W, type Config as X, type MessageResponse as Y, type MemoryConfig as Z, type SharedMemoryConfig as _, type ToolsInput as a, type StepAction as a0, type StepVariableType as a1, type StepNode as a2, type StepGraph as a3, type RetryConfig as a4, type VariableReference as a5, type BaseCondition as a6, type ActionContext as a7, WhenConditionReturnValue as a8, type StepDef as a9, type VoiceEventType as aA, type VoiceEventMap as aB, type VoiceConfig as aC, MastraVoice as aD, CompositeVoice as aE, type AgentNetworkConfig as aF, type ToolsetsInput as aG, type AgentGenerateOptions as aH, type AgentStreamOptions as aI, TABLE_WORKFLOW_SNAPSHOT as aJ, TABLE_EVALS as aK, TABLE_MESSAGES as aL, TABLE_THREADS as aM, TABLE_TRACES as aN, type StepCondition as aa, type StepConfig as ab, type StepResult as ac, type StepsRecord as ad, type WorkflowRunResult as ae, type WorkflowLogMessage as af, type WorkflowEvent as ag, type ResolverFunctionInput as ah, type ResolverFunctionOutput as ai, type SubscriberFunctionOutput as aj, type DependencyCheckOutput as ak, type StepResolverOutput as al, type WorkflowActors as am, type WorkflowActionParams as an, type WorkflowActions as ao, type WorkflowState as ap, type StepId as aq, type ExtractSchemaFromStep as ar, type ExtractStepResult as as, type StepInputType as at, type ExtractSchemaType as au, type PathsToStringProps as av, type WorkflowRunState as aw, type WorkflowResumeResult as ax, createStep as ay, type MastraLanguageModel as az, type MastraPrimitives as b, MastraMemory as c, type StepExecutionContext as d, type WorkflowContext as e, AgentNetwork as f, MastraStorage as g, type TABLE_NAMES as h, type StorageColumn as i, type StorageThreadType as j, type MessageType as k, type StorageGetMessagesArg as l, type AgentConfig as m, type ToolExecutionContext as n, Tool as o, type WorkflowOptions as p, type WorkflowRow as q, type CoreMessage as r, type CoreSystemMessage as s, type CoreAssistantMessage as t, type CoreUserMessage as u, type CoreToolMessage as v, type EmbedResult as w, type EmbedManyResult as x, type StructuredOutputType as y, type StructuredOutputArrayItem as z };