@mastra/core 0.7.0 → 0.8.0-alpha.2

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 (149) hide show
  1. package/README.md +76 -74
  2. package/dist/agent/index.cjs +2 -2
  3. package/dist/agent/index.d.cts +5 -3
  4. package/dist/agent/index.d.ts +5 -3
  5. package/dist/agent/index.js +1 -1
  6. package/dist/{base-Cmunaaxb.d.ts → base-BA_in99t.d.ts} +4 -1
  7. package/dist/{base-Cyl73WbV.d.ts → base-CQuRWXAH.d.ts} +985 -913
  8. package/dist/{base-ObPJ-w8K.d.cts → base-CvQbEqGB.d.cts} +4 -1
  9. package/dist/{base-C0wILuA9.d.cts → base-Dpt4tO56.d.cts} +985 -913
  10. package/dist/base.cjs +2 -2
  11. package/dist/base.d.cts +1 -1
  12. package/dist/base.d.ts +1 -1
  13. package/dist/base.js +1 -1
  14. package/dist/bundler/index.cjs +2 -2
  15. package/dist/bundler/index.d.cts +1 -1
  16. package/dist/bundler/index.d.ts +1 -1
  17. package/dist/bundler/index.js +1 -1
  18. package/dist/{chunk-L7CR75HA.js → chunk-2BVZNKLX.js} +1 -1
  19. package/dist/{chunk-V5ORZPFW.cjs → chunk-3C6V2FEP.cjs} +1 -1
  20. package/dist/chunk-3HE5CJBG.cjs +4604 -0
  21. package/dist/{chunk-PNZK456O.js → chunk-4RMSGSQN.js} +4 -4
  22. package/dist/{chunk-WESJ2ZY7.cjs → chunk-57LXIDIK.cjs} +2 -2
  23. package/dist/chunk-5RRJEWMA.cjs +107 -0
  24. package/dist/{chunk-3CNO7YB5.js → chunk-5TFGORLG.js} +1 -1
  25. package/dist/{chunk-5FAJ6HUC.cjs → chunk-64VPB7ZD.cjs} +23 -2
  26. package/dist/chunk-6XLV4KSD.js +100 -0
  27. package/dist/{chunk-XLSROQ26.cjs → chunk-7I7AKQH3.cjs} +5 -5
  28. package/dist/{chunk-RUA6BSB6.cjs → chunk-7JBINHJX.cjs} +2 -2
  29. package/dist/chunk-A6MBM56X.js +268 -0
  30. package/dist/{chunk-2YF5JYTJ.js → chunk-BC5B4EGI.js} +21 -2
  31. package/dist/chunk-BF7ZLRGO.cjs +271 -0
  32. package/dist/{chunk-SMBKF6K5.js → chunk-BRBHQ6KS.js} +10 -1
  33. package/dist/{chunk-VN4M67DA.js → chunk-CLJQYXNM.js} +1 -1
  34. package/dist/{chunk-PL7PVTGF.cjs → chunk-D63P5O4Q.cjs} +4 -4
  35. package/dist/chunk-DCGLGWHI.cjs +141 -0
  36. package/dist/{chunk-YXJQFZOW.cjs → chunk-DL4QPJKI.cjs} +24 -10
  37. package/dist/{chunk-ZABXT2MN.js → chunk-FY57LEMC.js} +1 -1
  38. package/dist/{chunk-XLXJUYKH.js → chunk-GHK3HBWN.js} +1 -1
  39. package/dist/{chunk-ONDCHP6G.cjs → chunk-GO2D7FEK.cjs} +2 -2
  40. package/dist/{chunk-7VTZI3YN.js → chunk-H6ZU5N2C.js} +1 -1
  41. package/dist/{chunk-WBE5RTFI.js → chunk-HAWAUEWK.js} +2 -2
  42. package/dist/chunk-HCDXBSMK.js +4577 -0
  43. package/dist/{chunk-RU7CSPAV.js → chunk-JGJMVCJ4.js} +7 -84
  44. package/dist/{chunk-W5HVJX45.js → chunk-N5ZYOQBL.js} +46 -5
  45. package/dist/{chunk-NPOKIPWC.cjs → chunk-O7IW545H.cjs} +1 -1
  46. package/dist/{chunk-XB2TJ7LX.cjs → chunk-PHWEC4VD.cjs} +47 -6
  47. package/dist/{chunk-NUDAZEOG.js → chunk-PK5QRKSG.js} +1 -1
  48. package/dist/{chunk-43SD5CUE.js → chunk-QDHRRKQ5.js} +63 -9
  49. package/dist/{chunk-ZBKJDQPM.js → chunk-RBWBJC6D.js} +17 -3
  50. package/dist/{chunk-4PYORXWM.cjs → chunk-RXDLSCBA.cjs} +4 -4
  51. package/dist/{chunk-IQLRSKED.cjs → chunk-RZCYBC7D.cjs} +2 -2
  52. package/dist/{chunk-ASFUEC75.cjs → chunk-TNNHN4ZY.cjs} +67 -12
  53. package/dist/{chunk-QM6WIIPM.js → chunk-UF4LZV3D.js} +1 -1
  54. package/dist/{chunk-JJ4YQTFT.cjs → chunk-WAW7QBY4.cjs} +2 -2
  55. package/dist/{chunk-U7ONOIBO.cjs → chunk-YZDUZFVZ.cjs} +11 -2
  56. package/dist/deployer/index.cjs +2 -2
  57. package/dist/deployer/index.d.cts +1 -1
  58. package/dist/deployer/index.d.ts +1 -1
  59. package/dist/deployer/index.js +1 -1
  60. package/dist/eval/index.cjs +3 -3
  61. package/dist/eval/index.d.cts +8 -5
  62. package/dist/eval/index.d.ts +8 -5
  63. package/dist/eval/index.js +1 -1
  64. package/dist/hooks/index.d.cts +1 -1
  65. package/dist/hooks/index.d.ts +1 -1
  66. package/dist/index.cjs +102 -92
  67. package/dist/index.d.cts +11 -9
  68. package/dist/index.d.ts +11 -9
  69. package/dist/index.js +18 -19
  70. package/dist/integration/index.cjs +3 -3
  71. package/dist/integration/index.d.cts +5 -3
  72. package/dist/integration/index.d.ts +5 -3
  73. package/dist/integration/index.js +1 -1
  74. package/dist/llm/index.d.cts +5 -3
  75. package/dist/llm/index.d.ts +5 -3
  76. package/dist/logger/index.cjs +9 -9
  77. package/dist/logger/index.js +1 -1
  78. package/dist/mastra/index.cjs +2 -2
  79. package/dist/mastra/index.d.cts +5 -3
  80. package/dist/mastra/index.d.ts +5 -3
  81. package/dist/mastra/index.js +1 -1
  82. package/dist/memory/index.cjs +6 -2
  83. package/dist/memory/index.d.cts +5 -3
  84. package/dist/memory/index.d.ts +5 -3
  85. package/dist/memory/index.js +1 -1
  86. package/dist/network/index.cjs +8 -8
  87. package/dist/network/index.d.cts +5 -3
  88. package/dist/network/index.d.ts +5 -3
  89. package/dist/network/index.js +4 -4
  90. package/dist/relevance/index.cjs +4 -4
  91. package/dist/relevance/index.d.cts +10 -8
  92. package/dist/relevance/index.d.ts +10 -8
  93. package/dist/relevance/index.js +1 -1
  94. package/dist/server/index.cjs +17 -0
  95. package/dist/server/index.d.cts +37 -0
  96. package/dist/server/index.d.ts +37 -0
  97. package/dist/server/index.js +15 -0
  98. package/dist/storage/index.cjs +12 -8
  99. package/dist/storage/index.d.cts +5 -3
  100. package/dist/storage/index.d.ts +5 -3
  101. package/dist/storage/index.js +2 -2
  102. package/dist/storage/libsql/index.cjs +24 -24
  103. package/dist/storage/libsql/index.d.cts +5 -3
  104. package/dist/storage/libsql/index.d.ts +5 -3
  105. package/dist/storage/libsql/index.js +12 -12
  106. package/dist/telemetry/index.cjs +6 -6
  107. package/dist/telemetry/index.d.cts +5 -3
  108. package/dist/telemetry/index.d.ts +5 -3
  109. package/dist/telemetry/index.js +1 -1
  110. package/dist/tools/index.cjs +7 -3
  111. package/dist/tools/index.d.cts +6 -3
  112. package/dist/tools/index.d.ts +6 -3
  113. package/dist/tools/index.js +1 -1
  114. package/dist/tts/index.cjs +2 -2
  115. package/dist/tts/index.d.cts +1 -1
  116. package/dist/tts/index.d.ts +1 -1
  117. package/dist/tts/index.js +1 -1
  118. package/dist/{types-CwTG2XyQ.d.cts → types-BtMyV38I.d.cts} +4 -1
  119. package/dist/{types-CwTG2XyQ.d.ts → types-BtMyV38I.d.ts} +4 -1
  120. package/dist/utils.cjs +13 -13
  121. package/dist/utils.d.cts +7 -5
  122. package/dist/utils.d.ts +7 -5
  123. package/dist/utils.js +1 -1
  124. package/dist/vector/index.cjs +2 -2
  125. package/dist/vector/index.d.cts +1 -1
  126. package/dist/vector/index.d.ts +1 -1
  127. package/dist/vector/index.js +1 -1
  128. package/dist/vector/libsql/index.cjs +3 -3
  129. package/dist/vector/libsql/index.d.cts +1 -1
  130. package/dist/vector/libsql/index.d.ts +1 -1
  131. package/dist/vector/libsql/index.js +1 -1
  132. package/dist/voice/index.cjs +13 -249
  133. package/dist/voice/index.d.cts +22 -8
  134. package/dist/voice/index.d.ts +22 -8
  135. package/dist/voice/index.js +1 -252
  136. package/dist/workflows/index.cjs +28 -20
  137. package/dist/workflows/index.d.cts +18 -7
  138. package/dist/workflows/index.d.ts +18 -7
  139. package/dist/workflows/index.js +1 -1
  140. package/package.json +5 -3
  141. package/dist/chunk-2W2GYEYQ.cjs +0 -25
  142. package/dist/chunk-C6BBAS4I.cjs +0 -1715
  143. package/dist/chunk-F5UYWPV4.cjs +0 -14
  144. package/dist/chunk-GG6TEAMJ.cjs +0 -2289
  145. package/dist/chunk-R2M5CZ5U.js +0 -2264
  146. package/dist/chunk-RG66XEJT.js +0 -8
  147. package/dist/chunk-VNQRLYIA.js +0 -1715
  148. package/dist/chunk-WVVKLIUW.cjs +0 -218
  149. package/dist/chunk-ZINPRHAN.js +0 -22
@@ -1,11 +1,11 @@
1
1
  import * as ai 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, GenerateTextOnStepFinishCallback, StreamTextOnFinishCallback, StreamObjectOnFinishCallback, StreamTextOnStepFinishCallback, LanguageModel as LanguageModel$1, DeepPartial, ToolContent } from 'ai';
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';
2
+ import { Tool as Tool$1, ToolExecutionOptions, LanguageModelV1, CoreMessage as CoreMessage$1, GenerateTextResult, GenerateObjectResult, StreamTextResult, StreamObjectResult, EmbeddingModel, Message, UserContent, AssistantContent, 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, GenerateTextOnStepFinishCallback, StreamTextOnFinishCallback, StreamObjectOnFinishCallback, StreamTextOnStepFinishCallback, LanguageModel as LanguageModel$1, DeepPartial, ToolContent } from 'ai';
3
+ import { M as MastraBase, T as Telemetry, O as OtelConfig } from './base-CvQbEqGB.cjs';
4
+ import { a as Metric, M as MetricResult, T as TestInfo } from './types-BtMyV38I.cjs';
5
5
  import { Query } from 'sift';
6
6
  import { z, ZodSchema } from 'zod';
7
7
  import { JSONSchema7 } from 'json-schema';
8
- import { d as Run, B as BaseLogMessage, R as RegisteredLogger, L as Logger } from './index-CquI0inB.cjs';
8
+ import { B as BaseLogMessage, R as RegisteredLogger, L as Logger, d as Run } from './index-CquI0inB.cjs';
9
9
  import { Span } from '@opentelemetry/api';
10
10
  import * as xstate from 'xstate';
11
11
  import { Snapshot } from 'xstate';
@@ -13,6 +13,8 @@ import EventEmitter from 'node:events';
13
13
  import { MastraVector } from './vector/index.cjs';
14
14
  import { MastraTTS } from './tts/index.cjs';
15
15
  import { MastraDeployer } from './deployer/index.cjs';
16
+ import { Handler, MiddlewareHandler } from 'hono';
17
+ import { DescribeRouteOptions } from 'hono-openapi';
16
18
 
17
19
  type VercelTool = Tool$1;
18
20
  type CoreTool = {
@@ -48,670 +50,309 @@ declare class Tool<TSchemaIn extends z.ZodSchema | undefined = undefined, TSchem
48
50
  }
49
51
  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
52
 
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: unknown) => 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;
53
+ type AgentNetworkConfig = {
54
+ name: string;
55
+ agents: Agent[];
56
+ model: LanguageModelV1;
57
+ instructions: string;
104
58
  };
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
59
 
117
- /**
118
- * Abstract Memory class that defines the interface for storing and retrieving
119
- * conversation threads and messages.
120
- */
121
- declare abstract class MastraMemory extends MastraBase {
122
- MAX_CONTEXT_TOKENS?: number;
123
- storage: MastraStorage;
124
- vector: MastraVector;
125
- embedder: EmbeddingModel<string>;
126
- protected threadConfig: MemoryConfig;
127
- constructor(config: {
128
- name: string;
129
- } & SharedMemoryConfig);
130
- setStorage(storage: MastraStorage): void;
131
- setVector(vector: MastraVector): void;
132
- setEmbedder(embedder: EmbeddingModel<string>): void;
60
+ declare class AgentNetwork extends MastraBase {
61
+ #private;
62
+ constructor(config: AgentNetworkConfig);
63
+ formatAgentId(name: string): string;
64
+ getTools(): {
65
+ readonly transmit: Tool<z.ZodObject<{
66
+ actions: z.ZodArray<z.ZodObject<{
67
+ agent: z.ZodString;
68
+ input: z.ZodString;
69
+ includeHistory: z.ZodOptional<z.ZodBoolean>;
70
+ }, "strip", z.ZodTypeAny, {
71
+ input: string;
72
+ agent: string;
73
+ includeHistory?: boolean | undefined;
74
+ }, {
75
+ input: string;
76
+ agent: string;
77
+ includeHistory?: boolean | undefined;
78
+ }>, "many">;
79
+ }, "strip", z.ZodTypeAny, {
80
+ actions: {
81
+ input: string;
82
+ agent: string;
83
+ includeHistory?: boolean | undefined;
84
+ }[];
85
+ }, {
86
+ actions: {
87
+ input: string;
88
+ agent: string;
89
+ includeHistory?: boolean | undefined;
90
+ }[];
91
+ }>, undefined, ToolExecutionContext<z.ZodObject<{
92
+ actions: z.ZodArray<z.ZodObject<{
93
+ agent: z.ZodString;
94
+ input: z.ZodString;
95
+ includeHistory: z.ZodOptional<z.ZodBoolean>;
96
+ }, "strip", z.ZodTypeAny, {
97
+ input: string;
98
+ agent: string;
99
+ includeHistory?: boolean | undefined;
100
+ }, {
101
+ input: string;
102
+ agent: string;
103
+ includeHistory?: boolean | undefined;
104
+ }>, "many">;
105
+ }, "strip", z.ZodTypeAny, {
106
+ actions: {
107
+ input: string;
108
+ agent: string;
109
+ includeHistory?: boolean | undefined;
110
+ }[];
111
+ }, {
112
+ actions: {
113
+ input: string;
114
+ agent: string;
115
+ includeHistory?: boolean | undefined;
116
+ }[];
117
+ }>>>;
118
+ };
119
+ getAgentHistory(agentId: string): {
120
+ input: string;
121
+ output: string;
122
+ timestamp: string;
123
+ }[];
133
124
  /**
134
- * Get a system message to inject into the conversation.
135
- * This will be called before each conversation turn.
136
- * Implementations can override this to inject custom system messages.
125
+ * Get the history of all agent interactions that have occurred in this network
126
+ * @returns A record of agent interactions, keyed by agent ID
137
127
  */
138
- getSystemMessage(_input: {
139
- threadId: string;
140
- memoryConfig?: MemoryConfig;
141
- }): Promise<string | null>;
128
+ getAgentInteractionHistory(): {
129
+ [x: string]: {
130
+ input: string;
131
+ output: string;
132
+ timestamp: string;
133
+ }[];
134
+ };
142
135
  /**
143
- * Get tools that should be available to the agent.
144
- * This will be called when converting tools for the agent.
145
- * Implementations can override this to provide additional tools.
136
+ * Get a summary of agent interactions in a more readable format, displayed chronologically
137
+ * @returns A formatted string with all agent interactions in chronological order
146
138
  */
147
- getTools(_config?: MemoryConfig): Record<string, CoreTool>;
148
- protected createEmbeddingIndex(): Promise<{
149
- indexName: string;
150
- }>;
151
- getMergedThreadConfig(config?: MemoryConfig): MemoryConfig;
152
- abstract rememberMessages({ threadId, resourceId, vectorMessageSearch, config, }: {
153
- threadId: string;
154
- resourceId?: string;
155
- vectorMessageSearch?: string;
156
- config?: MemoryConfig;
157
- }): Promise<{
158
- threadId: string;
159
- messages: CoreMessage$1[];
160
- uiMessages: Message[];
139
+ getAgentInteractionSummary(): string;
140
+ executeAgent(agentId: string, input: CoreMessage$1[], includeHistory?: boolean): Promise<string>;
141
+ getInstructions(): string;
142
+ getRoutingAgent(): Agent<string, ToolsInput, Record<string, Metric>>;
143
+ getAgents(): Agent<string, ToolsInput, Record<string, Metric>>[];
144
+ generate<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentGenerateOptions<Z> & {
145
+ output?: never;
146
+ experimental_output?: never;
147
+ }): Promise<GenerateTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown>>;
148
+ generate<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentGenerateOptions<Z> & ({
149
+ output: Z;
150
+ experimental_output?: never;
151
+ } | {
152
+ experimental_output: Z;
153
+ output?: never;
154
+ })): Promise<GenerateObjectResult<Z extends ZodSchema ? z.infer<Z> : unknown>>;
155
+ stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentStreamOptions<Z> & {
156
+ output?: never;
157
+ experimental_output?: never;
158
+ }): Promise<StreamTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown>>;
159
+ stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentStreamOptions<Z> & ({
160
+ output: Z;
161
+ experimental_output?: never;
162
+ } | {
163
+ experimental_output: Z;
164
+ output?: never;
165
+ })): Promise<StreamObjectResult<any, Z extends ZodSchema ? z.infer<Z> : unknown, any>>;
166
+ __registerMastra(p: Mastra): void;
167
+ }
168
+
169
+ 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> {
170
+ steps?: TSteps;
171
+ name: TWorkflowName;
172
+ triggerSchema?: TTriggerSchema;
173
+ result?: {
174
+ schema: TResultSchema;
175
+ mapping?: {
176
+ [K in keyof z.infer<TResultSchema>]?: any;
177
+ };
178
+ };
179
+ events?: Record<string, {
180
+ schema: z.ZodObject<any>;
161
181
  }>;
162
- estimateTokens(text: string): number;
163
- protected parseMessages(messages: MessageType[]): CoreMessage$1[];
164
- protected convertToUIMessages(messages: MessageType[]): Message[];
165
- /**
166
- * Retrieves a specific thread by its ID
167
- * @param threadId - The unique identifier of the thread
168
- * @returns Promise resolving to the thread or null if not found
169
- */
170
- abstract getThreadById({ threadId }: {
171
- threadId: string;
172
- }): Promise<StorageThreadType | null>;
173
- abstract getThreadsByResourceId({ resourceId }: {
174
- resourceId: string;
175
- }): Promise<StorageThreadType[]>;
176
- /**
177
- * Saves or updates a thread
178
- * @param thread - The thread data to save
179
- * @returns Promise resolving to the saved thread
180
- */
181
- abstract saveThread({ thread, memoryConfig, }: {
182
- thread: StorageThreadType;
183
- memoryConfig?: MemoryConfig;
184
- }): Promise<StorageThreadType>;
185
- /**
186
- * Saves messages to a thread
187
- * @param messages - Array of messages to save
188
- * @returns Promise resolving to the saved messages
189
- */
190
- abstract saveMessages({ messages, memoryConfig, }: {
191
- messages: MessageType[];
192
- memoryConfig: MemoryConfig | undefined;
193
- }): Promise<MessageType[]>;
194
- /**
195
- * Retrieves all messages for a specific thread
196
- * @param threadId - The unique identifier of the thread
197
- * @returns Promise resolving to array of messages and uiMessages
198
- */
199
- abstract query({ threadId, resourceId, selectBy, }: StorageGetMessagesArg): Promise<{
200
- messages: CoreMessage$1[];
201
- uiMessages: Message[];
202
- }>;
203
- /**
204
- * Helper method to create a new thread
205
- * @param title - Optional title for the thread
206
- * @param metadata - Optional metadata for the thread
207
- * @returns Promise resolving to the created thread
208
- */
209
- createThread({ threadId, resourceId, title, metadata, memoryConfig, }: {
210
- resourceId: string;
211
- threadId?: string;
212
- title?: string;
213
- metadata?: Record<string, unknown>;
214
- memoryConfig?: MemoryConfig;
215
- }): Promise<StorageThreadType>;
216
- /**
217
- * Helper method to delete a thread
218
- * @param threadId - the id of the thread to delete
219
- */
220
- abstract deleteThread(threadId: string): Promise<void>;
221
- /**
222
- * Helper method to add a single message to a thread
223
- * @param threadId - The thread to add the message to
224
- * @param content - The message content
225
- * @param role - The role of the message sender
226
- * @param type - The type of the message
227
- * @param toolNames - Optional array of tool names that were called
228
- * @param toolCallArgs - Optional array of tool call arguments
229
- * @param toolCallIds - Optional array of tool call ids
230
- * @returns Promise resolving to the saved message
231
- */
232
- addMessage({ threadId, config, content, role, type, toolNames, toolCallArgs, toolCallIds, }: {
233
- threadId: string;
234
- config?: MemoryConfig;
235
- content: UserContent | AssistantContent;
236
- role: 'user' | 'assistant';
237
- type: 'text' | 'tool-call' | 'tool-result';
238
- toolNames?: string[];
239
- toolCallArgs?: Record<string, unknown>[];
240
- toolCallIds?: string[];
241
- }): Promise<MessageType>;
242
- /**
243
- * Generates a unique identifier
244
- * @returns A unique string ID
245
- */
246
- generateId(): string;
182
+ retryConfig?: RetryConfig;
183
+ mastra?: Mastra;
247
184
  }
248
-
249
- type VoiceEventType = 'speaking' | 'writing' | 'error' | string;
250
- interface VoiceEventMap {
251
- speaker: NodeJS.ReadableStream;
252
- speaking: {
253
- audio?: string;
254
- };
255
- writing: {
256
- text: string;
257
- role: 'assistant' | 'user';
185
+ interface StepExecutionContext<TSchemaIn extends z.ZodSchema | undefined = undefined, TContext extends WorkflowContext = WorkflowContext> extends IExecutionContext<TSchemaIn> {
186
+ context: TSchemaIn extends z.ZodSchema ? {
187
+ inputData: z.infer<TSchemaIn>;
188
+ } & TContext : TContext;
189
+ suspend: (payload?: unknown, softSuspend?: any) => Promise<void>;
190
+ runId: string;
191
+ emit: (event: string, data: any) => void;
192
+ mastra?: MastraUnion;
193
+ }
194
+ 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> {
195
+ mastra?: Mastra;
196
+ payload?: TSchemaIn extends z.ZodSchema ? Partial<z.infer<TSchemaIn>> : unknown;
197
+ execute: (context: TContext) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
198
+ retryConfig?: RetryConfig;
199
+ workflow?: Workflow;
200
+ }
201
+ interface SimpleConditionalType {
202
+ [key: `${string}.${string}`]: string | Query<any>;
203
+ }
204
+ 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' | {
205
+ id: string;
206
+ };
207
+ type StepNode = {
208
+ step: StepAction<any, any, any, any>;
209
+ config: StepDef<any, any, any, any>[any];
210
+ };
211
+ type StepGraph = {
212
+ initial: StepNode[];
213
+ [key: string]: StepNode[];
214
+ };
215
+ type RetryConfig = {
216
+ attempts?: number;
217
+ delay?: number;
218
+ };
219
+ type VariableReference<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>> = TStep extends StepAction<any, any, any, any> ? {
220
+ step: TStep;
221
+ path: PathsToStringProps<ExtractSchemaType<ExtractSchemaFromStep<TStep, 'outputSchema'>>> | '' | '.';
222
+ } : TStep extends 'trigger' ? {
223
+ step: 'trigger';
224
+ path: PathsToStringProps<ExtractSchemaType<TTriggerSchema>> | '.' | '';
225
+ } : {
226
+ step: {
227
+ id: string;
258
228
  };
259
- error: {
260
- message: string;
261
- code?: string;
262
- details?: unknown;
229
+ path: string;
230
+ };
231
+ interface BaseCondition<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>> {
232
+ ref: TStep extends StepAction<any, any, any, any> ? {
233
+ step: TStep;
234
+ path: PathsToStringProps<ExtractSchemaType<ExtractSchemaFromStep<TStep, 'outputSchema'>>> | '' | '.' | 'status';
235
+ } : TStep extends 'trigger' ? {
236
+ step: 'trigger';
237
+ path: PathsToStringProps<ExtractSchemaType<TTriggerSchema>> | '.' | '';
238
+ } : {
239
+ step: {
240
+ id: string;
241
+ };
242
+ path: string;
263
243
  };
264
- [key: string]: unknown;
244
+ query: Query<any>;
265
245
  }
266
- interface BuiltInModelConfig {
267
- name: string;
268
- apiKey?: string;
246
+ type ActionContext<TSchemaIn extends z.ZodType<any>> = StepExecutionContext<z.infer<TSchemaIn>, WorkflowContext>;
247
+ declare enum WhenConditionReturnValue {
248
+ CONTINUE = "continue",
249
+ CONTINUE_FAILED = "continue_failed",
250
+ ABORT = "abort",
251
+ LIMBO = "limbo"
269
252
  }
270
- interface VoiceConfig<T = unknown> {
271
- listeningModel?: BuiltInModelConfig;
272
- speechModel?: BuiltInModelConfig;
273
- speaker?: string;
274
- name?: string;
275
- realtimeConfig?: {
276
- model?: string;
277
- apiKey?: string;
278
- options?: T;
253
+ 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, {
254
+ when?: Condition<any, any> | ((args: {
255
+ context: WorkflowContext;
256
+ mastra?: Mastra;
257
+ }) => Promise<boolean | WhenConditionReturnValue>);
258
+ serializedWhen?: Condition<any, any> | string;
259
+ loopLabel?: string;
260
+ loopType?: 'while' | 'until';
261
+ data: TSchemaIn;
262
+ handler: (args: ActionContext<TSchemaIn>) => Promise<z.infer<TSchemaOut>>;
263
+ }>;
264
+ type StepCondition<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>> = BaseCondition<TStep, TTriggerSchema> | SimpleConditionalType | {
265
+ and: StepCondition<TStep, TTriggerSchema>[];
266
+ } | {
267
+ or: StepCondition<TStep, TTriggerSchema>[];
268
+ } | {
269
+ not: StepCondition<TStep, TTriggerSchema>;
270
+ };
271
+ type Condition<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>> = BaseCondition<TStep, TTriggerSchema> | SimpleConditionalType | {
272
+ and: Condition<TStep, TTriggerSchema>[];
273
+ } | {
274
+ or: Condition<TStep, TTriggerSchema>[];
275
+ } | {
276
+ not: Condition<TStep, TTriggerSchema>;
277
+ };
278
+ 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 Step<string, any, any, any>[] = Step<string, any, any, any>[]> {
279
+ when?: Condition<CondStep, TTriggerSchema> | ((args: {
280
+ context: WorkflowContext<TTriggerSchema, TSteps>;
281
+ mastra?: Mastra;
282
+ }) => Promise<boolean | WhenConditionReturnValue>);
283
+ variables?: StepInputType<TStep, 'inputSchema'> extends never ? Record<string, VariableReference<VarStep, TTriggerSchema>> : {
284
+ [K in keyof StepInputType<TStep, 'inputSchema'>]?: VariableReference<VarStep, TTriggerSchema>;
285
+ };
286
+ '#internal'?: {
287
+ when?: Condition<CondStep, TTriggerSchema> | ((args: {
288
+ context: WorkflowContext<TTriggerSchema, TSteps>;
289
+ mastra?: Mastra;
290
+ }) => Promise<boolean | WhenConditionReturnValue>);
291
+ loopLabel?: string;
292
+ loopType?: 'while' | 'until' | undefined;
279
293
  };
280
294
  }
281
- declare abstract class MastraVoice<TOptions = unknown, TSpeakOptions = unknown, TListenOptions = unknown, TTools extends ToolsInput = ToolsInput, TEventArgs extends VoiceEventMap = VoiceEventMap, TSpeakerMetadata = unknown> extends MastraBase {
282
- protected listeningModel?: BuiltInModelConfig;
283
- protected speechModel?: BuiltInModelConfig;
284
- protected speaker?: string;
285
- protected realtimeConfig?: {
286
- model?: string;
287
- apiKey?: string;
288
- options?: TOptions;
295
+ type StepSuccess<T> = {
296
+ status: 'success';
297
+ output: T;
298
+ };
299
+ type StepSuspended<T> = {
300
+ status: 'suspended';
301
+ suspendPayload?: any;
302
+ output?: T;
303
+ };
304
+ type StepWaiting = {
305
+ status: 'waiting';
306
+ };
307
+ type StepFailure = {
308
+ status: 'failed';
309
+ error: string;
310
+ };
311
+ type StepSkipped = {
312
+ status: 'skipped';
313
+ };
314
+ type StepResult<T> = StepSuccess<T> | StepFailure | StepSuspended<T> | StepWaiting | StepSkipped;
315
+ type StepsRecord<T extends readonly Step<any, any, z.ZodType<any> | undefined>[]> = {
316
+ [K in T[number]['id']]: Extract<T[number], {
317
+ id: K;
318
+ }>;
319
+ };
320
+ interface WorkflowRunResult<T extends z.ZodObject<any>, TSteps extends Step<string, any, z.ZodType<any> | undefined>[], TResult extends z.ZodObject<any>> {
321
+ triggerData?: z.infer<T>;
322
+ result?: z.infer<TResult>;
323
+ results: {
324
+ [K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]['outputSchema'] extends undefined ? StepResult<unknown> : StepResult<z.infer<NonNullable<StepsRecord<TSteps>[K]['outputSchema']>>>;
289
325
  };
290
- constructor({ listeningModel, speechModel, speaker, realtimeConfig, name }?: VoiceConfig<TOptions>);
291
- traced<T extends Function>(method: T, methodName: string): T;
292
- /**
293
- * Convert text to speech
294
- * @param input Text or text stream to convert to speech
295
- * @param options Speech options including speaker and provider-specific options
296
- * @returns Audio stream
297
- */
298
- /**
299
- * Convert text to speech
300
- * @param input Text or text stream to convert to speech
301
- * @param options Speech options including speaker and provider-specific options
302
- * @returns Audio stream or void if in chat mode
303
- */
304
- abstract speak(input: string | NodeJS.ReadableStream, options?: {
305
- speaker?: string;
306
- } & TSpeakOptions): Promise<NodeJS.ReadableStream | void>;
307
- /**
308
- * Convert speech to text
309
- * @param audioStream Audio stream to transcribe
310
- * @param options Provider-specific transcription options
311
- * @returns Text or text stream
312
- */
313
- /**
314
- * Convert speech to text
315
- * @param audioStream Audio stream to transcribe
316
- * @param options Provider-specific transcription options
317
- * @returns Text, text stream, or void if in chat mode
318
- */
319
- abstract listen(audioStream: NodeJS.ReadableStream | unknown, // Allow other audio input types for OpenAI realtime API
320
- options?: TListenOptions): Promise<string | NodeJS.ReadableStream | void>;
321
- updateConfig(_options: Record<string, unknown>): void;
322
- /**
323
- * Initializes a WebSocket or WebRTC connection for real-time communication
324
- * @returns Promise that resolves when the connection is established
325
- */
326
- connect(_options?: Record<string, unknown>): Promise<void>;
327
- /**
328
- * Relay audio data to the voice provider for real-time processing
329
- * @param audioData Audio data to relay
330
- */
331
- send(_audioData: NodeJS.ReadableStream | Int16Array): Promise<void>;
332
- /**
333
- * Trigger voice providers to respond
334
- */
335
- answer(_options?: Record<string, unknown>): Promise<void>;
336
- /**
337
- * Equip the voice provider with instructions
338
- * @param instructions Instructions to add
339
- */
340
- addInstructions(_instructions?: string): void;
341
- /**
342
- * Equip the voice provider with tools
343
- * @param tools Array of tools to add
344
- */
345
- addTools(_tools: TTools): void;
346
- /**
347
- * Disconnect from the WebSocket or WebRTC connection
348
- */
349
- close(): void;
350
- /**
351
- * Register an event listener
352
- * @param event Event name (e.g., 'speaking', 'writing', 'error')
353
- * @param callback Callback function that receives event data
354
- */
355
- on<E extends VoiceEventType>(_event: E, _callback: (data: E extends keyof TEventArgs ? TEventArgs[E] : unknown) => void): void;
356
- /**
357
- * Remove an event listener
358
- * @param event Event name (e.g., 'speaking', 'writing', 'error')
359
- * @param callback Callback function to remove
360
- */
361
- off<E extends VoiceEventType>(_event: E, _callback: (data: E extends keyof TEventArgs ? TEventArgs[E] : unknown) => void): void;
362
- /**
363
- * Get available speakers/voices
364
- * @returns Array of available voice IDs and their metadata
365
- */
366
- getSpeakers(): Promise<Array<{
367
- voiceId: string;
368
- } & TSpeakerMetadata>>;
369
- }
370
-
371
- declare class CompositeVoice extends MastraVoice<unknown, unknown, unknown, ToolsInput, VoiceEventMap> {
372
- protected speakProvider?: MastraVoice;
373
- protected listenProvider?: MastraVoice;
374
- protected realtimeProvider?: MastraVoice;
375
- constructor({ speakProvider, listenProvider, realtimeProvider, }: {
376
- speakProvider?: MastraVoice;
377
- listenProvider?: MastraVoice;
378
- realtimeProvider?: MastraVoice;
379
- });
380
- /**
381
- * Convert text to speech using the configured provider
382
- * @param input Text or text stream to convert to speech
383
- * @param options Speech options including speaker and provider-specific options
384
- * @returns Audio stream or void if in realtime mode
385
- */
386
- speak(input: string | NodeJS.ReadableStream, options?: {
387
- speaker?: string;
388
- } & any): Promise<NodeJS.ReadableStream | void>;
389
- listen(audioStream: NodeJS.ReadableStream, options?: any): Promise<string | void | NodeJS.ReadableStream>;
390
- getSpeakers(): Promise<{
391
- voiceId: string;
392
- }[]>;
393
- updateConfig(options: Record<string, unknown>): void;
394
- /**
395
- * Initializes a WebSocket or WebRTC connection for real-time communication
396
- * @returns Promise that resolves when the connection is established
397
- */
398
- connect(options?: Record<string, unknown>): Promise<void>;
399
- /**
400
- * Relay audio data to the voice provider for real-time processing
401
- * @param audioData Audio data to send
402
- */
403
- send(audioData: NodeJS.ReadableStream | Int16Array): Promise<void>;
404
- /**
405
- * Trigger voice providers to respond
406
- */
407
- answer(options?: Record<string, unknown>): Promise<void>;
408
- /**
409
- * Equip the voice provider with instructions
410
- * @param instructions Instructions to add
411
- */
412
- addInstructions(instructions: string): void;
413
- /**
414
- * Equip the voice provider with tools
415
- * @param tools Array of tools to add
416
- */
417
- addTools(tools: ToolsInput): void;
418
- /**
419
- * Disconnect from the WebSocket or WebRTC connection
420
- */
421
- close(): void;
422
- /**
423
- * Register an event listener
424
- * @param event Event name (e.g., 'speaking', 'writing', 'error')
425
- * @param callback Callback function that receives event data
426
- */
427
- on<E extends VoiceEventType>(event: E, callback: (data: E extends keyof VoiceEventMap ? VoiceEventMap[E] : unknown) => void): void;
428
- /**
429
- * Remove an event listener
430
- * @param event Event name (e.g., 'speaking', 'writing', 'error')
431
- * @param callback Callback function to remove
432
- */
433
- off<E extends VoiceEventType>(event: E, callback: (data: E extends keyof VoiceEventMap ? VoiceEventMap[E] : unknown) => void): void;
434
- }
435
-
436
- type ToolsInput = Record<string, ToolAction<any, any, any> | VercelTool>;
437
- type ToolsetsInput = Record<string, ToolsInput>;
438
- type MastraLanguageModel = LanguageModelV1;
439
- interface AgentConfig<TTools extends ToolsInput = ToolsInput, TMetrics extends Record<string, Metric> = Record<string, Metric>> {
440
- name: string;
441
- instructions: string;
442
- model: MastraLanguageModel;
443
- tools?: TTools;
444
- mastra?: Mastra;
445
- /** @deprecated This property is deprecated. Use evals instead to add evaluation metrics. */
446
- metrics?: TMetrics;
447
- evals?: TMetrics;
448
- memory?: MastraMemory;
449
- voice?: CompositeVoice;
326
+ runId: string;
327
+ timestamp: number;
328
+ activePaths: Map<keyof StepsRecord<TSteps>, {
329
+ status: string;
330
+ suspendPayload?: any;
331
+ stepPath: string[];
332
+ }>;
450
333
  }
451
- /**
452
- * Options for generating responses with an agent
453
- * @template Z - The schema type for structured output (Zod schema or JSON schema)
454
- */
455
- type AgentGenerateOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
456
- /** Optional instructions to override the agent's default instructions */
457
- instructions?: string;
458
- /** Additional tool sets that can be used for this generation */
459
- toolsets?: ToolsetsInput;
460
- /** Additional context messages to include */
461
- context?: CoreMessage[];
462
- /** Memory configuration options */
463
- memoryOptions?: MemoryConfig;
464
- /** Unique ID for this generation run */
465
- runId?: string;
466
- /** Callback fired after each generation step completes */
467
- onStepFinish?: Z extends undefined ? GenerateTextOnStepFinishCallback<any> : never;
468
- /** Maximum number of steps allowed for generation */
469
- maxSteps?: number;
470
- /** Schema for structured output, does not work with tools, use experimental_output instead */
471
- output?: OutputType | Z;
472
- /** Schema for structured output generation alongside tool calls. */
473
- experimental_output?: Z;
474
- /** Controls how tools are selected during generation */
475
- toolChoice?: 'auto' | 'none' | 'required' | {
476
- type: 'tool';
477
- toolName: string;
478
- };
479
- /** Telemetry settings */
480
- telemetry?: TelemetrySettings;
481
- } & ({
482
- resourceId?: undefined;
483
- threadId?: undefined;
484
- } | {
485
- resourceId: string;
486
- threadId: string;
487
- }) & (Z extends undefined ? DefaultLLMTextOptions : DefaultLLMTextObjectOptions);
488
- /**
489
- * Options for streaming responses with an agent
490
- * @template Z - The schema type for structured output (Zod schema or JSON schema)
491
- */
492
- type AgentStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
493
- /** Optional instructions to override the agent's default instructions */
494
- instructions?: string;
495
- /** Additional tool sets that can be used for this generation */
496
- toolsets?: ToolsetsInput;
497
- /** Additional context messages to include */
498
- context?: CoreMessage[];
499
- /** Memory configuration options */
500
- memoryOptions?: MemoryConfig;
501
- /** Unique ID for this generation run */
502
- runId?: string;
503
- /** Callback fired when streaming completes */
504
- onFinish?: Z extends undefined ? StreamTextOnFinishCallback<any> : Z extends ZodSchema ? StreamObjectOnFinishCallback<z.infer<Z>> : StreamObjectOnFinishCallback<any>;
505
- /** Callback fired after each generation step completes */
506
- onStepFinish?: Z extends undefined ? StreamTextOnStepFinishCallback<any> : never;
507
- /** Maximum number of steps allowed for generation */
508
- maxSteps?: number;
509
- /** Schema for structured output */
510
- output?: OutputType | Z;
511
- /** Temperature parameter for controlling randomness */
512
- temperature?: number;
513
- /** Controls how tools are selected during generation */
514
- toolChoice?: 'auto' | 'none' | 'required' | {
515
- type: 'tool';
516
- toolName: string;
334
+ 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>> {
335
+ isResume?: {
336
+ runId: string;
337
+ stepId: string;
517
338
  };
518
- /** Experimental schema for structured output */
519
- experimental_output?: Z;
520
- /** Telemetry settings */
521
- telemetry?: TelemetrySettings;
522
- } & ({
523
- resourceId?: undefined;
524
- threadId?: undefined;
525
- } | {
526
- resourceId: string;
527
- threadId: string;
528
- }) & (Z extends undefined ? DefaultLLMStreamOptions : DefaultLLMStreamObjectOptions);
529
-
530
- 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> {
531
- steps?: TSteps;
532
- name: TWorkflowName;
533
- triggerSchema?: TTriggerSchema;
534
- result?: {
535
- schema: TResultSchema;
536
- mapping?: {
537
- [K in keyof z.infer<TResultSchema>]?: any;
538
- };
339
+ mastra?: MastraUnion;
340
+ steps: {
341
+ [K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]['outputSchema'] extends undefined ? StepResult<unknown> : StepResult<z.infer<NonNullable<StepsRecord<TSteps>[K]['outputSchema']>>>;
539
342
  };
540
- events?: Record<string, {
541
- schema: z.ZodObject<any>;
542
- }>;
543
- retryConfig?: RetryConfig;
544
- mastra?: Mastra;
343
+ triggerData: z.infer<TTrigger>;
344
+ inputData: TInputData;
345
+ attempts: Record<string, number>;
346
+ getStepResult(stepId: 'trigger'): z.infer<TTrigger>;
347
+ getStepResult<T extends keyof StepsRecord<TSteps> | unknown>(stepId: T extends keyof StepsRecord<TSteps> ? T : string): T extends keyof StepsRecord<TSteps> ? StepsRecord<TSteps>[T]['outputSchema'] extends undefined ? unknown : z.infer<NonNullable<StepsRecord<TSteps>[T]['outputSchema']>> : T;
348
+ getStepResult<T extends Step<any, any, any, any>>(stepId: T): T['outputSchema'] extends undefined ? unknown : z.infer<NonNullable<T['outputSchema']>>;
545
349
  }
546
- interface StepExecutionContext<TSchemaIn extends z.ZodSchema | undefined = undefined, TContext extends WorkflowContext = WorkflowContext> extends IExecutionContext<TSchemaIn> {
547
- context: TSchemaIn extends z.ZodSchema ? {
548
- inputData: z.infer<TSchemaIn>;
549
- } & TContext : TContext;
550
- suspend: (payload?: unknown, softSuspend?: any) => Promise<void>;
551
- runId: string;
552
- emit: (event: string, data: any) => void;
553
- mastra?: MastraUnion;
554
- }
555
- 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> {
556
- mastra?: Mastra;
557
- payload?: TSchemaIn extends z.ZodSchema ? Partial<z.infer<TSchemaIn>> : unknown;
558
- execute: (context: TContext) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
559
- retryConfig?: RetryConfig;
560
- workflow?: Workflow;
561
- }
562
- interface SimpleConditionalType {
563
- [key: `${string}.${string}`]: string | Query<any>;
564
- }
565
- 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' | {
566
- id: string;
567
- };
568
- type StepNode = {
569
- step: StepAction<any, any, any, any>;
570
- config: StepDef<any, any, any, any>[any];
571
- };
572
- type StepGraph = {
573
- initial: StepNode[];
574
- [key: string]: StepNode[];
575
- };
576
- type RetryConfig = {
577
- attempts?: number;
578
- delay?: number;
579
- };
580
- type VariableReference<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>> = TStep extends StepAction<any, any, any, any> ? {
581
- step: TStep;
582
- path: PathsToStringProps<ExtractSchemaType<ExtractSchemaFromStep<TStep, 'outputSchema'>>> | '' | '.';
583
- } : TStep extends 'trigger' ? {
584
- step: 'trigger';
585
- path: PathsToStringProps<ExtractSchemaType<TTriggerSchema>> | '.' | '';
586
- } : {
587
- step: {
588
- id: string;
589
- };
590
- path: string;
591
- };
592
- interface BaseCondition<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>> {
593
- ref: TStep extends StepAction<any, any, any, any> ? {
594
- step: TStep;
595
- path: PathsToStringProps<ExtractSchemaType<ExtractSchemaFromStep<TStep, 'outputSchema'>>> | '' | '.' | 'status';
596
- } : TStep extends 'trigger' ? {
597
- step: 'trigger';
598
- path: PathsToStringProps<ExtractSchemaType<TTriggerSchema>> | '.' | '';
599
- } : {
600
- step: {
601
- id: string;
602
- };
603
- path: string;
604
- };
605
- query: Query<any>;
606
- }
607
- type ActionContext<TSchemaIn extends z.ZodType<any>> = StepExecutionContext<z.infer<TSchemaIn>, WorkflowContext>;
608
- declare enum WhenConditionReturnValue {
609
- CONTINUE = "continue",
610
- CONTINUE_FAILED = "continue_failed",
611
- ABORT = "abort",
612
- LIMBO = "limbo"
613
- }
614
- 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, {
615
- when?: Condition<any, any> | ((args: {
616
- context: WorkflowContext;
617
- mastra?: Mastra;
618
- }) => Promise<boolean | WhenConditionReturnValue>);
619
- serializedWhen?: Condition<any, any> | string;
620
- loopLabel?: string;
621
- loopType?: 'while' | 'until';
622
- data: TSchemaIn;
623
- handler: (args: ActionContext<TSchemaIn>) => Promise<z.infer<TSchemaOut>>;
624
- }>;
625
- type StepCondition<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>> = BaseCondition<TStep, TTriggerSchema> | SimpleConditionalType | {
626
- and: StepCondition<TStep, TTriggerSchema>[];
627
- } | {
628
- or: StepCondition<TStep, TTriggerSchema>[];
629
- } | {
630
- not: StepCondition<TStep, TTriggerSchema>;
631
- };
632
- type Condition<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>> = BaseCondition<TStep, TTriggerSchema> | SimpleConditionalType | {
633
- and: Condition<TStep, TTriggerSchema>[];
634
- } | {
635
- or: Condition<TStep, TTriggerSchema>[];
636
- } | {
637
- not: Condition<TStep, TTriggerSchema>;
638
- };
639
- 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 Step<string, any, any, any>[] = Step<string, any, any, any>[]> {
640
- when?: Condition<CondStep, TTriggerSchema> | ((args: {
641
- context: WorkflowContext<TTriggerSchema, TSteps>;
642
- mastra?: Mastra;
643
- }) => Promise<boolean | WhenConditionReturnValue>);
644
- variables?: StepInputType<TStep, 'inputSchema'> extends never ? Record<string, VariableReference<VarStep, TTriggerSchema>> : {
645
- [K in keyof StepInputType<TStep, 'inputSchema'>]?: VariableReference<VarStep, TTriggerSchema>;
646
- };
647
- '#internal'?: {
648
- when?: Condition<CondStep, TTriggerSchema> | ((args: {
649
- context: WorkflowContext<TTriggerSchema, TSteps>;
650
- mastra?: Mastra;
651
- }) => Promise<boolean | WhenConditionReturnValue>);
652
- loopLabel?: string;
653
- loopType?: 'while' | 'until' | undefined;
654
- };
655
- }
656
- type StepSuccess<T> = {
657
- status: 'success';
658
- output: T;
659
- };
660
- type StepSuspended<T> = {
661
- status: 'suspended';
662
- suspendPayload?: any;
663
- output?: T;
664
- };
665
- type StepWaiting = {
666
- status: 'waiting';
667
- };
668
- type StepFailure = {
669
- status: 'failed';
670
- error: string;
671
- };
672
- type StepSkipped = {
673
- status: 'skipped';
674
- };
675
- type StepResult<T> = StepSuccess<T> | StepFailure | StepSuspended<T> | StepWaiting | StepSkipped;
676
- type StepsRecord<T extends readonly Step<any, any, z.ZodType<any> | undefined>[]> = {
677
- [K in T[number]['id']]: Extract<T[number], {
678
- id: K;
679
- }>;
680
- };
681
- interface WorkflowRunResult<T extends z.ZodObject<any>, TSteps extends Step<string, any, z.ZodType<any> | undefined>[], TResult extends z.ZodObject<any>> {
682
- triggerData?: z.infer<T>;
683
- result?: z.infer<TResult>;
684
- results: {
685
- [K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]['outputSchema'] extends undefined ? StepResult<unknown> : StepResult<z.infer<NonNullable<StepsRecord<TSteps>[K]['outputSchema']>>>;
686
- };
687
- runId: string;
688
- activePaths: Map<keyof StepsRecord<TSteps>, {
689
- status: string;
690
- suspendPayload?: any;
691
- }>;
692
- }
693
- 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>> {
694
- isResume?: {
695
- runId: string;
696
- stepId: string;
697
- };
698
- mastra?: MastraUnion;
699
- steps: {
700
- [K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]['outputSchema'] extends undefined ? StepResult<unknown> : StepResult<z.infer<NonNullable<StepsRecord<TSteps>[K]['outputSchema']>>>;
701
- };
702
- triggerData: z.infer<TTrigger>;
703
- inputData: TInputData;
704
- attempts: Record<string, number>;
705
- getStepResult(stepId: 'trigger'): z.infer<TTrigger>;
706
- getStepResult<T extends keyof StepsRecord<TSteps> | unknown>(stepId: T extends keyof StepsRecord<TSteps> ? T : string): T extends keyof StepsRecord<TSteps> ? StepsRecord<TSteps>[T]['outputSchema'] extends undefined ? unknown : z.infer<NonNullable<StepsRecord<TSteps>[T]['outputSchema']>> : T;
707
- getStepResult<T extends Step<any, any, any, any>>(stepId: T): T['outputSchema'] extends undefined ? unknown : z.infer<NonNullable<T['outputSchema']>>;
708
- }
709
- interface WorkflowLogMessage extends BaseLogMessage {
710
- type: typeof RegisteredLogger.WORKFLOW;
711
- workflowName: string;
712
- stepId?: StepId;
713
- data?: unknown;
714
- runId?: string;
350
+ interface WorkflowLogMessage extends BaseLogMessage {
351
+ type: typeof RegisteredLogger.WORKFLOW;
352
+ workflowName: string;
353
+ stepId?: StepId;
354
+ data?: unknown;
355
+ runId?: string;
715
356
  }
716
357
  type WorkflowEvent = {
717
358
  type: 'RESET_TO_PENDING';
@@ -937,7 +578,7 @@ declare class Machine<TSteps extends Step<any, any, any>[] = any, TTriggerSchema
937
578
  input?: any;
938
579
  snapshot?: Snapshot<any>;
939
580
  resumeData?: any;
940
- }): Promise<Pick<WorkflowRunResult<TTriggerSchema, TSteps, TResultSchema>, 'results' | 'activePaths'>>;
581
+ }): Promise<Pick<WorkflowRunResult<TTriggerSchema, TSteps, TResultSchema>, 'results' | 'activePaths' | 'runId' | 'timestamp'>>;
941
582
  private initializeMachine;
942
583
  getSnapshot(): xstate.MachineSnapshot<Omit<WorkflowContext<any, Step<string, any, any, any>[], Record<string, any>>, "getStepResult">, {
943
584
  type: "RESET_TO_PENDING";
@@ -1253,6 +894,7 @@ declare class Machine<TSteps extends Step<any, any, any>[] = any, TTriggerSchema
1253
894
  }, xstate.AnyEventObject>;
1254
895
  }) => {
1255
896
  mastra?: MastraUnion | undefined;
897
+ triggerData: any;
1256
898
  isResume?: {
1257
899
  runId: string;
1258
900
  stepId: string;
@@ -1281,7 +923,6 @@ declare class Machine<TSteps extends Step<any, any, any>[] = any, TTriggerSchema
1281
923
  output?: any;
1282
924
  };
1283
925
  };
1284
- triggerData: any;
1285
926
  inputData: Record<string, any>;
1286
927
  attempts: Record<string, number>;
1287
928
  };
@@ -1289,279 +930,695 @@ declare class Machine<TSteps extends Step<any, any, any>[] = any, TTriggerSchema
1289
930
  }> | undefined;
1290
931
  }
1291
932
 
1292
- interface WorkflowResultReturn<TResult extends z.ZodObject<any>, T extends z.ZodObject<any>, TSteps extends Step<any, any, any>[]> {
1293
- runId: string;
1294
- start: (props?: {
1295
- triggerData?: z.infer<T>;
1296
- } | undefined) => Promise<WorkflowRunResult<T, TSteps, TResult>>;
1297
- watch: (onTransition: (state: WorkflowRunState) => void) => () => void;
1298
- resume: (props: {
1299
- stepId: string;
1300
- context?: Record<string, any>;
1301
- }) => Promise<Omit<WorkflowRunResult<T, TSteps, TResult>, 'runId'> | undefined>;
1302
- resumeWithEvent: (eventName: string, data: any) => Promise<Omit<WorkflowRunResult<T, TSteps, TResult>, 'runId'> | undefined>;
933
+ interface WorkflowResultReturn<TResult extends z.ZodObject<any>, T extends z.ZodObject<any>, TSteps extends Step<any, any, any>[]> {
934
+ runId: string;
935
+ start: (props?: {
936
+ triggerData?: z.infer<T>;
937
+ } | undefined) => Promise<WorkflowRunResult<T, TSteps, TResult>>;
938
+ watch: (onTransition: (state: Pick<WorkflowRunResult<T, TSteps, TResult>, 'results' | 'activePaths' | 'runId'>) => void) => () => void;
939
+ resume: (props: {
940
+ stepId: string;
941
+ context?: Record<string, any>;
942
+ }) => Promise<Omit<WorkflowRunResult<T, TSteps, TResult>, 'runId'> | undefined>;
943
+ resumeWithEvent: (eventName: string, data: any) => Promise<Omit<WorkflowRunResult<T, TSteps, TResult>, 'runId'> | undefined>;
944
+ }
945
+ 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> {
946
+ #private;
947
+ name: string;
948
+ logger: Logger;
949
+ events?: Record<string, {
950
+ schema: z.ZodObject<any>;
951
+ }>;
952
+ constructor({ name, logger, steps, runId, retryConfig, mastra, stepGraph, stepSubscriberGraph, onFinish, onStepTransition, resultMapping, events, }: {
953
+ name: string;
954
+ logger: Logger;
955
+ steps: Record<string, StepAction<any, any, any, any>>;
956
+ mastra?: Mastra;
957
+ retryConfig?: RetryConfig;
958
+ runId?: string;
959
+ stepGraph: StepGraph;
960
+ stepSubscriberGraph: Record<string, StepGraph>;
961
+ onFinish?: () => void;
962
+ onStepTransition?: Set<(state: Pick<WorkflowRunResult<TTriggerSchema, TSteps, TResult>, 'results' | 'activePaths' | 'runId' | 'timestamp'>) => void | Promise<void>>;
963
+ resultMapping?: Record<string, {
964
+ step: StepAction<any, any, any, any>;
965
+ path: string;
966
+ }>;
967
+ events?: Record<string, {
968
+ schema: z.ZodObject<any>;
969
+ }>;
970
+ });
971
+ setState(state: any): void;
972
+ get runId(): string;
973
+ get executionSpan(): Span | undefined;
974
+ watch(onTransition: (state: Pick<WorkflowRunResult<TTriggerSchema, TSteps, TResult>, 'results' | 'activePaths' | 'runId' | 'timestamp'>) => void): () => void;
975
+ start({ triggerData }?: {
976
+ triggerData?: z.infer<TTriggerSchema>;
977
+ }): Promise<{
978
+ runId: string;
979
+ timestamp: number;
980
+ result?: z.TypeOf<TResult> | undefined;
981
+ results: { [K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]["outputSchema"] extends undefined ? StepResult<unknown> : StepResult<z.TypeOf<NonNullable<StepsRecord<TSteps>[K]["outputSchema"]>>>; };
982
+ triggerData?: z.TypeOf<TTriggerSchema> | undefined;
983
+ activePaths: Map<TSteps[number]["id"], {
984
+ status: string;
985
+ suspendPayload?: any;
986
+ stepPath: string[];
987
+ }>;
988
+ }>;
989
+ private isCompoundDependencyMet;
990
+ execute({ triggerData, snapshot, stepId, resumeData, }?: {
991
+ stepId?: string;
992
+ triggerData?: z.infer<TTriggerSchema>;
993
+ snapshot?: Snapshot<any>;
994
+ resumeData?: any;
995
+ }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, TResult>, 'runId'>>;
996
+ hasSubscribers(stepId: string): boolean;
997
+ runMachine(parentStepId: string, input: any): Promise<(Pick<WorkflowRunResult<any, any, any>, "runId" | "timestamp" | "results" | "activePaths"> | undefined)[]>;
998
+ suspend(stepId: string, machine: Machine<TSteps, TTriggerSchema>): Promise<void>;
999
+ /**
1000
+ * Persists the workflow state to the database
1001
+ */
1002
+ persistWorkflowSnapshot(): Promise<void>;
1003
+ getState(): Promise<WorkflowRunState | null>;
1004
+ resumeWithEvent(eventName: string, data: any): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, TResult>, "runId"> | undefined>;
1005
+ resume({ stepId, context: resumeContext }: {
1006
+ stepId: string;
1007
+ context?: Record<string, any>;
1008
+ }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, TResult>, "runId"> | undefined>;
1009
+ _resume({ stepId, context: resumeContext }: {
1010
+ stepId: string;
1011
+ context?: Record<string, any>;
1012
+ }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, TResult>, "runId"> | undefined>;
1013
+ }
1014
+
1015
+ type WorkflowBuilder<T extends Workflow<any, any>> = Pick<T, 'step' | 'then' | 'after' | 'while' | 'until' | 'if' | 'else' | 'afterEvent' | 'commit'>;
1016
+ 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 {
1017
+ #private;
1018
+ name: TStepId;
1019
+ triggerSchema?: TTriggerSchema;
1020
+ resultSchema?: TResultSchema;
1021
+ resultMapping?: Record<string, {
1022
+ step: StepAction<string, any, any, any>;
1023
+ path: string;
1024
+ }>;
1025
+ events?: Record<string, {
1026
+ schema: z.ZodObject<any>;
1027
+ }>;
1028
+ /**
1029
+ * Creates a new Workflow instance
1030
+ * @param name - Identifier for the workflow (not necessarily unique)
1031
+ * @param logger - Optional logger instance
1032
+ */
1033
+ constructor({ name, triggerSchema, result, retryConfig, mastra, events, }: WorkflowOptions<TStepId, TSteps, TTriggerSchema, TResultSchema>);
1034
+ 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>): WorkflowBuilder<this>;
1035
+ 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>;
1036
+ 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>;
1037
+ 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;
1038
+ 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;
1039
+ 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;
1040
+ private loop;
1041
+ 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): Pick<WorkflowBuilder<this>, "then" | "commit">;
1042
+ 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): Pick<WorkflowBuilder<this>, "then" | "commit">;
1043
+ if<TStep extends StepAction<string, any, any, any>>(condition: StepConfig<TStep, any, any, TTriggerSchema>['when'], ifStep?: TStep | Workflow, elseStep?: TStep | Workflow): this | WorkflowBuilder<this>;
1044
+ else(): WorkflowBuilder<this>;
1045
+ after<TStep extends StepAction<string, any, any, any>>(steps: TStep | TStep[]): Omit<WorkflowBuilder<this>, 'then' | 'after'>;
1046
+ after<TWorkflow extends Workflow<any, any, any, any>>(steps: TWorkflow | TWorkflow[]): Omit<WorkflowBuilder<this>, 'then' | 'after'>;
1047
+ after<TAgent extends Agent<any, any, any>>(steps: TAgent | TAgent[]): Omit<WorkflowBuilder<this>, 'then' | 'after'>;
1048
+ afterEvent(eventName: string): WorkflowBuilder<this>;
1049
+ /**
1050
+ * Executes the workflow with the given trigger data
1051
+ * @param triggerData - Initial data to start the workflow with
1052
+ * @returns Promise resolving to workflow results or rejecting with error
1053
+ * @throws Error if trigger schema validation fails
1054
+ */
1055
+ createRun({ runId, events, }?: {
1056
+ runId?: string;
1057
+ events?: Record<string, {
1058
+ schema: z.ZodObject<any>;
1059
+ }>;
1060
+ }): WorkflowResultReturn<TResultSchema, TTriggerSchema, TSteps>;
1061
+ /**
1062
+ * Gets a workflow run instance by ID
1063
+ * @param runId - ID of the run to retrieve
1064
+ * @returns The workflow run instance if found, undefined otherwise
1065
+ */
1066
+ getRun(runId: string): WorkflowInstance<TSteps, TTriggerSchema, any> | undefined;
1067
+ /**
1068
+ * Rebuilds the machine with the current steps configuration and validates the workflow
1069
+ *
1070
+ * This is the last step of a workflow builder method chain
1071
+ * @throws Error if validation fails
1072
+ *
1073
+ * @returns this instance for method chaining
1074
+ */
1075
+ commit(): this;
1076
+ getExecutionSpan(runId: string): Span | undefined;
1077
+ getState(runId: string): Promise<WorkflowRunState | null>;
1078
+ resume({ runId, stepId, context: resumeContext, }: {
1079
+ runId: string;
1080
+ stepId: string;
1081
+ context?: Record<string, any>;
1082
+ }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, any>, "runId"> | undefined>;
1083
+ watch(onTransition: (state: Pick<WorkflowRunResult<TTriggerSchema, TSteps, TResultSchema>, 'results' | 'activePaths' | 'runId' | 'timestamp'>) => void): () => void;
1084
+ resumeWithEvent(runId: string, eventName: string, data: any): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, any>, "runId"> | undefined>;
1085
+ __registerMastra(mastra: Mastra): void;
1086
+ __registerPrimitives(p: MastraPrimitives): void;
1087
+ get stepGraph(): StepGraph;
1088
+ get stepSubscriberGraph(): Record<string, StepGraph>;
1089
+ get serializedStepGraph(): StepGraph;
1090
+ get serializedStepSubscriberGraph(): Record<string, StepGraph>;
1091
+ get steps(): Record<string, StepAction<string, any, any, any>>;
1092
+ setNested(isNested: boolean): void;
1093
+ get isNested(): boolean;
1094
+ toStep(): Step<TStepId, TTriggerSchema, z.ZodType<WorkflowRunResult<TTriggerSchema, TSteps, TResultSchema>>, any>;
1095
+ }
1096
+
1097
+ type MemoryProcessorOpts = {
1098
+ systemMessage?: string;
1099
+ memorySystemMessage?: string;
1100
+ newMessages?: CoreMessage$1[];
1101
+ };
1102
+ /**
1103
+ * Interface for message processors that can filter or transform messages
1104
+ * before they're sent to the LLM.
1105
+ */
1106
+ declare abstract class MemoryProcessor extends MastraBase {
1107
+ /**
1108
+ * Process a list of messages and return a filtered or transformed list.
1109
+ * @param messages The messages to process
1110
+ * @returns The processed messages
1111
+ */
1112
+ process(messages: CoreMessage$1[], _opts: MemoryProcessorOpts): CoreMessage$1[];
1113
+ }
1114
+ /**
1115
+ * Abstract Memory class that defines the interface for storing and retrieving
1116
+ * conversation threads and messages.
1117
+ */
1118
+ declare abstract class MastraMemory extends MastraBase {
1119
+ MAX_CONTEXT_TOKENS?: number;
1120
+ storage: MastraStorage;
1121
+ vector: MastraVector;
1122
+ embedder: EmbeddingModel<string>;
1123
+ private processors;
1124
+ protected threadConfig: MemoryConfig;
1125
+ constructor(config: {
1126
+ name: string;
1127
+ } & SharedMemoryConfig);
1128
+ setStorage(storage: MastraStorage): void;
1129
+ setVector(vector: MastraVector): void;
1130
+ setEmbedder(embedder: EmbeddingModel<string>): void;
1131
+ /**
1132
+ * Get a system message to inject into the conversation.
1133
+ * This will be called before each conversation turn.
1134
+ * Implementations can override this to inject custom system messages.
1135
+ */
1136
+ getSystemMessage(_input: {
1137
+ threadId: string;
1138
+ memoryConfig?: MemoryConfig;
1139
+ }): Promise<string | null>;
1140
+ /**
1141
+ * Get tools that should be available to the agent.
1142
+ * This will be called when converting tools for the agent.
1143
+ * Implementations can override this to provide additional tools.
1144
+ */
1145
+ getTools(_config?: MemoryConfig): Record<string, CoreTool>;
1146
+ protected createEmbeddingIndex(): Promise<{
1147
+ indexName: string;
1148
+ }>;
1149
+ getMergedThreadConfig(config?: MemoryConfig): MemoryConfig;
1150
+ /**
1151
+ * Apply all configured message processors to a list of messages.
1152
+ * @param messages The messages to process
1153
+ * @returns The processed messages
1154
+ */
1155
+ private applyProcessors;
1156
+ processMessages({ messages, processors, ...opts }: {
1157
+ messages: CoreMessage$1[];
1158
+ processors?: MemoryProcessor[];
1159
+ } & MemoryProcessorOpts): CoreMessage$1[];
1160
+ abstract rememberMessages({ threadId, resourceId, vectorMessageSearch, systemMessage, config, }: {
1161
+ threadId: string;
1162
+ resourceId?: string;
1163
+ vectorMessageSearch?: string;
1164
+ systemMessage?: CoreMessage$1;
1165
+ config?: MemoryConfig;
1166
+ }): Promise<{
1167
+ threadId: string;
1168
+ messages: CoreMessage$1[];
1169
+ uiMessages: Message[];
1170
+ }>;
1171
+ estimateTokens(text: string): number;
1172
+ protected parseMessages(messages: MessageType[]): CoreMessage$1[];
1173
+ protected convertToUIMessages(messages: MessageType[]): Message[];
1174
+ /**
1175
+ * Retrieves a specific thread by its ID
1176
+ * @param threadId - The unique identifier of the thread
1177
+ * @returns Promise resolving to the thread or null if not found
1178
+ */
1179
+ abstract getThreadById({ threadId }: {
1180
+ threadId: string;
1181
+ }): Promise<StorageThreadType | null>;
1182
+ abstract getThreadsByResourceId({ resourceId }: {
1183
+ resourceId: string;
1184
+ }): Promise<StorageThreadType[]>;
1185
+ /**
1186
+ * Saves or updates a thread
1187
+ * @param thread - The thread data to save
1188
+ * @returns Promise resolving to the saved thread
1189
+ */
1190
+ abstract saveThread({ thread, memoryConfig, }: {
1191
+ thread: StorageThreadType;
1192
+ memoryConfig?: MemoryConfig;
1193
+ }): Promise<StorageThreadType>;
1194
+ /**
1195
+ * Saves messages to a thread
1196
+ * @param messages - Array of messages to save
1197
+ * @returns Promise resolving to the saved messages
1198
+ */
1199
+ abstract saveMessages({ messages, memoryConfig, }: {
1200
+ messages: MessageType[];
1201
+ memoryConfig: MemoryConfig | undefined;
1202
+ }): Promise<MessageType[]>;
1203
+ /**
1204
+ * Retrieves all messages for a specific thread
1205
+ * @param threadId - The unique identifier of the thread
1206
+ * @returns Promise resolving to array of messages and uiMessages
1207
+ */
1208
+ abstract query({ threadId, resourceId, selectBy, }: StorageGetMessagesArg): Promise<{
1209
+ messages: CoreMessage$1[];
1210
+ uiMessages: Message[];
1211
+ }>;
1212
+ /**
1213
+ * Helper method to create a new thread
1214
+ * @param title - Optional title for the thread
1215
+ * @param metadata - Optional metadata for the thread
1216
+ * @returns Promise resolving to the created thread
1217
+ */
1218
+ createThread({ threadId, resourceId, title, metadata, memoryConfig, }: {
1219
+ resourceId: string;
1220
+ threadId?: string;
1221
+ title?: string;
1222
+ metadata?: Record<string, unknown>;
1223
+ memoryConfig?: MemoryConfig;
1224
+ }): Promise<StorageThreadType>;
1225
+ /**
1226
+ * Helper method to delete a thread
1227
+ * @param threadId - the id of the thread to delete
1228
+ */
1229
+ abstract deleteThread(threadId: string): Promise<void>;
1230
+ /**
1231
+ * Helper method to add a single message to a thread
1232
+ * @param threadId - The thread to add the message to
1233
+ * @param content - The message content
1234
+ * @param role - The role of the message sender
1235
+ * @param type - The type of the message
1236
+ * @param toolNames - Optional array of tool names that were called
1237
+ * @param toolCallArgs - Optional array of tool call arguments
1238
+ * @param toolCallIds - Optional array of tool call ids
1239
+ * @returns Promise resolving to the saved message
1240
+ */
1241
+ addMessage({ threadId, resourceId, config, content, role, type, toolNames, toolCallArgs, toolCallIds, }: {
1242
+ threadId: string;
1243
+ resourceId: string;
1244
+ config?: MemoryConfig;
1245
+ content: UserContent | AssistantContent;
1246
+ role: 'user' | 'assistant';
1247
+ type: 'text' | 'tool-call' | 'tool-result';
1248
+ toolNames?: string[];
1249
+ toolCallArgs?: Record<string, unknown>[];
1250
+ toolCallIds?: string[];
1251
+ }): Promise<MessageType>;
1252
+ /**
1253
+ * Generates a unique identifier
1254
+ * @returns A unique string ID
1255
+ */
1256
+ generateId(): string;
1257
+ }
1258
+
1259
+ type LanguageModel = MastraLanguageModel;
1260
+ type CoreMessage = CoreMessage$1;
1261
+ type CoreSystemMessage = CoreSystemMessage$1;
1262
+ type CoreAssistantMessage = CoreAssistantMessage$1;
1263
+ type CoreUserMessage = CoreUserMessage$1;
1264
+ type CoreToolMessage = CoreToolMessage$1;
1265
+ type EmbedResult<T> = EmbedResult$1<T>;
1266
+ type EmbedManyResult<T> = EmbedManyResult$1<T>;
1267
+ type BaseStructuredOutputType = 'string' | 'number' | 'boolean' | 'date';
1268
+ type StructuredOutputType = 'array' | 'string' | 'number' | 'object' | 'boolean' | 'date';
1269
+ type StructuredOutputArrayItem = {
1270
+ type: BaseStructuredOutputType;
1271
+ } | {
1272
+ type: 'object';
1273
+ items: StructuredOutput;
1274
+ };
1275
+ type StructuredOutput = {
1276
+ [key: string]: {
1277
+ type: BaseStructuredOutputType;
1278
+ } | {
1279
+ type: 'object';
1280
+ items: StructuredOutput;
1281
+ } | {
1282
+ type: 'array';
1283
+ items: StructuredOutputArrayItem;
1284
+ };
1285
+ };
1286
+ 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>;
1287
+ 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>;
1288
+ type OutputType = StructuredOutput | ZodSchema | JSONSchema7 | undefined;
1289
+ type GenerateTextOptions = Parameters<typeof generateText>[0];
1290
+ type StreamTextOptions = Parameters<typeof streamText>[0];
1291
+ type GenerateObjectOptions = Parameters<typeof generateObject>[0];
1292
+ type StreamObjectOptions = Parameters<typeof streamObject>[0];
1293
+ type MastraCustomLLMOptionsKeys = 'messages' | 'tools' | 'model' | 'onStepFinish' | 'experimental_output' | 'experimental_telemetry' | 'messages' | 'onFinish' | 'output';
1294
+ type DefaultLLMTextOptions = Omit<GenerateTextOptions, MastraCustomLLMOptionsKeys>;
1295
+ type DefaultLLMTextObjectOptions = Omit<GenerateObjectOptions, MastraCustomLLMOptionsKeys>;
1296
+ type DefaultLLMStreamOptions = Omit<StreamTextOptions, MastraCustomLLMOptionsKeys>;
1297
+ type DefaultLLMStreamObjectOptions = Omit<StreamObjectOptions, MastraCustomLLMOptionsKeys>;
1298
+ type MastraCustomLLMOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
1299
+ tools?: ToolsInput;
1300
+ convertedTools?: Record<string, CoreTool>;
1301
+ onStepFinish?: (step: unknown) => void;
1302
+ experimental_output?: Z;
1303
+ telemetry?: TelemetrySettings;
1304
+ threadId?: string;
1305
+ resourceId?: string;
1306
+ } & Run;
1307
+ type LLMTextOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
1308
+ messages: CoreMessage[];
1309
+ } & MastraCustomLLMOptions<Z> & DefaultLLMTextOptions;
1310
+ type LLMTextObjectOptions<T extends ZodSchema | JSONSchema7 | undefined = undefined> = LLMTextOptions<T> & DefaultLLMTextObjectOptions & {
1311
+ structuredOutput: JSONSchema7 | z.ZodType<T> | StructuredOutput;
1312
+ };
1313
+ type LLMStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
1314
+ output?: OutputType | Z;
1315
+ onFinish?: (result: string) => Promise<void> | void;
1316
+ } & MastraCustomLLMOptions<Z> & DefaultLLMStreamOptions;
1317
+ type LLMInnerStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
1318
+ messages: CoreMessage[];
1319
+ onFinish?: (result: string) => Promise<void> | void;
1320
+ } & MastraCustomLLMOptions<Z> & DefaultLLMStreamOptions;
1321
+ type LLMStreamObjectOptions<T extends ZodSchema | JSONSchema7 | undefined = undefined> = {
1322
+ structuredOutput: JSONSchema7 | z.ZodType<T> | StructuredOutput;
1323
+ } & LLMInnerStreamOptions<T> & DefaultLLMStreamObjectOptions;
1324
+
1325
+ type VoiceEventType = 'speaking' | 'writing' | 'error' | string;
1326
+ interface VoiceEventMap {
1327
+ speaker: NodeJS.ReadableStream;
1328
+ speaking: {
1329
+ audio?: string;
1330
+ };
1331
+ writing: {
1332
+ text: string;
1333
+ role: 'assistant' | 'user';
1334
+ };
1335
+ error: {
1336
+ message: string;
1337
+ code?: string;
1338
+ details?: unknown;
1339
+ };
1340
+ [key: string]: unknown;
1303
1341
  }
1304
- 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> {
1305
- #private;
1342
+ interface BuiltInModelConfig {
1306
1343
  name: string;
1307
- logger: Logger;
1308
- events?: Record<string, {
1309
- schema: z.ZodObject<any>;
1310
- }>;
1311
- constructor({ name, logger, steps, runId, retryConfig, mastra, stepGraph, stepSubscriberGraph, onFinish, onStepTransition, resultMapping, events, }: {
1312
- name: string;
1313
- logger: Logger;
1314
- steps: Record<string, StepAction<any, any, any, any>>;
1315
- mastra?: Mastra;
1316
- retryConfig?: RetryConfig;
1317
- runId?: string;
1318
- stepGraph: StepGraph;
1319
- stepSubscriberGraph: Record<string, StepGraph>;
1320
- onFinish?: () => void;
1321
- onStepTransition?: Set<(state: WorkflowRunState) => void | Promise<void>>;
1322
- resultMapping?: Record<string, {
1323
- step: StepAction<any, any, any, any>;
1324
- path: string;
1325
- }>;
1326
- events?: Record<string, {
1327
- schema: z.ZodObject<any>;
1328
- }>;
1329
- });
1330
- setState(state: any): void;
1331
- get runId(): string;
1332
- get executionSpan(): Span | undefined;
1333
- watch(onTransition: (state: WorkflowRunState) => void): () => void;
1334
- start({ triggerData }?: {
1335
- triggerData?: z.infer<TTriggerSchema>;
1336
- }): Promise<{
1337
- runId: string;
1338
- result?: z.TypeOf<TResult> | undefined;
1339
- results: { [K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]["outputSchema"] extends undefined ? StepResult<unknown> : StepResult<z.TypeOf<NonNullable<StepsRecord<TSteps>[K]["outputSchema"]>>>; };
1340
- triggerData?: z.TypeOf<TTriggerSchema> | undefined;
1341
- activePaths: Map<TSteps[number]["id"], {
1342
- status: string;
1343
- suspendPayload?: any;
1344
- }>;
1345
- }>;
1346
- private isCompoundDependencyMet;
1347
- execute({ triggerData, snapshot, stepId, resumeData, }?: {
1348
- stepId?: string;
1349
- triggerData?: z.infer<TTriggerSchema>;
1350
- snapshot?: Snapshot<any>;
1351
- resumeData?: any;
1352
- }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, TResult>, 'runId'>>;
1353
- hasSubscribers(stepId: string): boolean;
1354
- runMachine(parentStepId: string, input: any): Promise<(Pick<WorkflowRunResult<any, any, any>, "results" | "activePaths"> | undefined)[]>;
1355
- suspend(stepId: string, machine: Machine<TSteps, TTriggerSchema>): Promise<void>;
1344
+ apiKey?: string;
1345
+ }
1346
+ interface VoiceConfig<T = unknown> {
1347
+ listeningModel?: BuiltInModelConfig;
1348
+ speechModel?: BuiltInModelConfig;
1349
+ speaker?: string;
1350
+ name?: string;
1351
+ realtimeConfig?: {
1352
+ model?: string;
1353
+ apiKey?: string;
1354
+ options?: T;
1355
+ };
1356
+ }
1357
+ declare abstract class MastraVoice<TOptions = unknown, TSpeakOptions = unknown, TListenOptions = unknown, TTools extends ToolsInput = ToolsInput, TEventArgs extends VoiceEventMap = VoiceEventMap, TSpeakerMetadata = unknown> extends MastraBase {
1358
+ protected listeningModel?: BuiltInModelConfig;
1359
+ protected speechModel?: BuiltInModelConfig;
1360
+ protected speaker?: string;
1361
+ protected realtimeConfig?: {
1362
+ model?: string;
1363
+ apiKey?: string;
1364
+ options?: TOptions;
1365
+ };
1366
+ constructor({ listeningModel, speechModel, speaker, realtimeConfig, name }?: VoiceConfig<TOptions>);
1367
+ traced<T extends Function>(method: T, methodName: string): T;
1356
1368
  /**
1357
- * Persists the workflow state to the database
1369
+ * Convert text to speech
1370
+ * @param input Text or text stream to convert to speech
1371
+ * @param options Speech options including speaker and provider-specific options
1372
+ * @returns Audio stream
1358
1373
  */
1359
- persistWorkflowSnapshot(): Promise<void>;
1360
- getState(): Promise<WorkflowRunState | null>;
1361
- resumeWithEvent(eventName: string, data: any): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, TResult>, "runId"> | undefined>;
1362
- resume({ stepId, context: resumeContext }: {
1363
- stepId: string;
1364
- context?: Record<string, any>;
1365
- }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, TResult>, "runId"> | undefined>;
1366
- _resume({ stepId, context: resumeContext }: {
1367
- stepId: string;
1368
- context?: Record<string, any>;
1369
- }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, TResult>, "runId"> | undefined>;
1374
+ /**
1375
+ * Convert text to speech
1376
+ * @param input Text or text stream to convert to speech
1377
+ * @param options Speech options including speaker and provider-specific options
1378
+ * @returns Audio stream or void if in chat mode
1379
+ */
1380
+ abstract speak(input: string | NodeJS.ReadableStream, options?: {
1381
+ speaker?: string;
1382
+ } & TSpeakOptions): Promise<NodeJS.ReadableStream | void>;
1383
+ /**
1384
+ * Convert speech to text
1385
+ * @param audioStream Audio stream to transcribe
1386
+ * @param options Provider-specific transcription options
1387
+ * @returns Text or text stream
1388
+ */
1389
+ /**
1390
+ * Convert speech to text
1391
+ * @param audioStream Audio stream to transcribe
1392
+ * @param options Provider-specific transcription options
1393
+ * @returns Text, text stream, or void if in chat mode
1394
+ */
1395
+ abstract listen(audioStream: NodeJS.ReadableStream | unknown, // Allow other audio input types for OpenAI realtime API
1396
+ options?: TListenOptions): Promise<string | NodeJS.ReadableStream | void>;
1397
+ updateConfig(_options: Record<string, unknown>): void;
1398
+ /**
1399
+ * Initializes a WebSocket or WebRTC connection for real-time communication
1400
+ * @returns Promise that resolves when the connection is established
1401
+ */
1402
+ connect(_options?: Record<string, unknown>): Promise<void>;
1403
+ /**
1404
+ * Relay audio data to the voice provider for real-time processing
1405
+ * @param audioData Audio data to relay
1406
+ */
1407
+ send(_audioData: NodeJS.ReadableStream | Int16Array): Promise<void>;
1408
+ /**
1409
+ * Trigger voice providers to respond
1410
+ */
1411
+ answer(_options?: Record<string, unknown>): Promise<void>;
1412
+ /**
1413
+ * Equip the voice provider with instructions
1414
+ * @param instructions Instructions to add
1415
+ */
1416
+ addInstructions(_instructions?: string): void;
1417
+ /**
1418
+ * Equip the voice provider with tools
1419
+ * @param tools Array of tools to add
1420
+ */
1421
+ addTools(_tools: TTools): void;
1422
+ /**
1423
+ * Disconnect from the WebSocket or WebRTC connection
1424
+ */
1425
+ close(): void;
1426
+ /**
1427
+ * Register an event listener
1428
+ * @param event Event name (e.g., 'speaking', 'writing', 'error')
1429
+ * @param callback Callback function that receives event data
1430
+ */
1431
+ on<E extends VoiceEventType>(_event: E, _callback: (data: E extends keyof TEventArgs ? TEventArgs[E] : unknown) => void): void;
1432
+ /**
1433
+ * Remove an event listener
1434
+ * @param event Event name (e.g., 'speaking', 'writing', 'error')
1435
+ * @param callback Callback function to remove
1436
+ */
1437
+ off<E extends VoiceEventType>(_event: E, _callback: (data: E extends keyof TEventArgs ? TEventArgs[E] : unknown) => void): void;
1438
+ /**
1439
+ * Get available speakers/voices
1440
+ * @returns Array of available voice IDs and their metadata
1441
+ */
1442
+ getSpeakers(): Promise<Array<{
1443
+ voiceId: string;
1444
+ } & TSpeakerMetadata>>;
1370
1445
  }
1371
1446
 
1372
- 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 {
1373
- #private;
1374
- name: TStepId;
1375
- triggerSchema?: TTriggerSchema;
1376
- resultSchema?: TResultSchema;
1377
- resultMapping?: Record<string, {
1378
- step: StepAction<string, any, any, any>;
1379
- path: string;
1380
- }>;
1381
- events?: Record<string, {
1382
- schema: z.ZodObject<any>;
1383
- }>;
1447
+ declare class CompositeVoice extends MastraVoice<unknown, unknown, unknown, ToolsInput, VoiceEventMap> {
1448
+ protected speakProvider?: MastraVoice;
1449
+ protected listenProvider?: MastraVoice;
1450
+ protected realtimeProvider?: MastraVoice;
1451
+ constructor({ speakProvider, listenProvider, realtimeProvider, }: {
1452
+ speakProvider?: MastraVoice;
1453
+ listenProvider?: MastraVoice;
1454
+ realtimeProvider?: MastraVoice;
1455
+ });
1384
1456
  /**
1385
- * Creates a new Workflow instance
1386
- * @param name - Identifier for the workflow (not necessarily unique)
1387
- * @param logger - Optional logger instance
1457
+ * Convert text to speech using the configured provider
1458
+ * @param input Text or text stream to convert to speech
1459
+ * @param options Speech options including speaker and provider-specific options
1460
+ * @returns Audio stream or void if in realtime mode
1388
1461
  */
1389
- constructor({ name, triggerSchema, result, retryConfig, mastra, events, }: WorkflowOptions<TStepId, TSteps, TTriggerSchema, TResultSchema>);
1390
- 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;
1391
- 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;
1392
- 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;
1393
- 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;
1394
- private loop;
1395
- 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;
1396
- 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;
1397
- if<TStep extends StepAction<string, any, any, any>>(condition: StepConfig<TStep, any, any, TTriggerSchema>['when'], ifStep?: TStep | Workflow, elseStep?: TStep | Workflow): this;
1398
- else(): this;
1399
- after<TStep extends StepAction<string, any, any, any>>(steps: TStep | TStep[]): Omit<typeof this, 'then' | 'after'>;
1400
- after<TWorkflow extends Workflow<any, any, any, any>>(steps: TWorkflow | TWorkflow[]): Omit<typeof this, 'then' | 'after'>;
1401
- afterEvent(eventName: string): this;
1462
+ speak(input: string | NodeJS.ReadableStream, options?: {
1463
+ speaker?: string;
1464
+ } & any): Promise<NodeJS.ReadableStream | void>;
1465
+ listen(audioStream: NodeJS.ReadableStream, options?: any): Promise<string | void | NodeJS.ReadableStream>;
1466
+ getSpeakers(): Promise<{
1467
+ voiceId: string;
1468
+ }[]>;
1469
+ updateConfig(options: Record<string, unknown>): void;
1470
+ /**
1471
+ * Initializes a WebSocket or WebRTC connection for real-time communication
1472
+ * @returns Promise that resolves when the connection is established
1473
+ */
1474
+ connect(options?: Record<string, unknown>): Promise<void>;
1475
+ /**
1476
+ * Relay audio data to the voice provider for real-time processing
1477
+ * @param audioData Audio data to send
1478
+ */
1479
+ send(audioData: NodeJS.ReadableStream | Int16Array): Promise<void>;
1480
+ /**
1481
+ * Trigger voice providers to respond
1482
+ */
1483
+ answer(options?: Record<string, unknown>): Promise<void>;
1484
+ /**
1485
+ * Equip the voice provider with instructions
1486
+ * @param instructions Instructions to add
1487
+ */
1488
+ addInstructions(instructions: string): void;
1489
+ /**
1490
+ * Equip the voice provider with tools
1491
+ * @param tools Array of tools to add
1492
+ */
1493
+ addTools(tools: ToolsInput): void;
1402
1494
  /**
1403
- * Executes the workflow with the given trigger data
1404
- * @param triggerData - Initial data to start the workflow with
1405
- * @returns Promise resolving to workflow results or rejecting with error
1406
- * @throws Error if trigger schema validation fails
1495
+ * Disconnect from the WebSocket or WebRTC connection
1407
1496
  */
1408
- createRun({ runId, events, }?: {
1409
- runId?: string;
1410
- events?: Record<string, {
1411
- schema: z.ZodObject<any>;
1412
- }>;
1413
- }): WorkflowResultReturn<TResultSchema, TTriggerSchema, TSteps>;
1497
+ close(): void;
1414
1498
  /**
1415
- * Gets a workflow run instance by ID
1416
- * @param runId - ID of the run to retrieve
1417
- * @returns The workflow run instance if found, undefined otherwise
1499
+ * Register an event listener
1500
+ * @param event Event name (e.g., 'speaking', 'writing', 'error')
1501
+ * @param callback Callback function that receives event data
1418
1502
  */
1419
- getRun(runId: string): WorkflowInstance<TSteps, TTriggerSchema, any> | undefined;
1503
+ on<E extends VoiceEventType>(event: E, callback: (data: E extends keyof VoiceEventMap ? VoiceEventMap[E] : unknown) => void): void;
1420
1504
  /**
1421
- * Rebuilds the machine with the current steps configuration and validates the workflow
1422
- *
1423
- * This is the last step of a workflow builder method chain
1424
- * @throws Error if validation fails
1425
- *
1426
- * @returns this instance for method chaining
1505
+ * Remove an event listener
1506
+ * @param event Event name (e.g., 'speaking', 'writing', 'error')
1507
+ * @param callback Callback function to remove
1427
1508
  */
1428
- commit(): this;
1429
- getExecutionSpan(runId: string): Span | undefined;
1430
- getState(runId: string): Promise<WorkflowRunState | null>;
1431
- resume({ runId, stepId, context: resumeContext, }: {
1432
- runId: string;
1433
- stepId: string;
1434
- context?: Record<string, any>;
1435
- }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, any>, "runId"> | undefined>;
1436
- watch(onTransition: (state: WorkflowRunState) => void): () => void;
1437
- resumeWithEvent(runId: string, eventName: string, data: any): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps, any>, "runId"> | undefined>;
1438
- __registerMastra(mastra: Mastra): void;
1439
- __registerPrimitives(p: MastraPrimitives): void;
1440
- get stepGraph(): StepGraph;
1441
- get stepSubscriberGraph(): Record<string, StepGraph>;
1442
- get serializedStepGraph(): StepGraph;
1443
- get serializedStepSubscriberGraph(): Record<string, StepGraph>;
1444
- get steps(): Record<string, StepAction<string, any, any, any>>;
1445
- setNested(isNested: boolean): void;
1446
- get isNested(): boolean;
1447
- toStep(): Step<TStepId, TTriggerSchema, z.ZodType<WorkflowRunResult<TTriggerSchema, TSteps, TResultSchema>>, any>;
1509
+ off<E extends VoiceEventType>(event: E, callback: (data: E extends keyof VoiceEventMap ? VoiceEventMap[E] : unknown) => void): void;
1448
1510
  }
1449
1511
 
1450
- type AgentNetworkConfig = {
1451
- name: string;
1452
- agents: Agent[];
1453
- model: LanguageModelV1;
1512
+ type ToolsInput = Record<string, ToolAction<any, any, any> | VercelTool>;
1513
+ type ToolsetsInput = Record<string, ToolsInput>;
1514
+ type MastraLanguageModel = LanguageModelV1;
1515
+ interface AgentConfig<TAgentId extends string = string, TTools extends ToolsInput = ToolsInput, TMetrics extends Record<string, Metric> = Record<string, Metric>> {
1516
+ name: TAgentId;
1454
1517
  instructions: string;
1455
- };
1456
-
1457
- declare class AgentNetwork extends MastraBase {
1458
- #private;
1459
- constructor(config: AgentNetworkConfig);
1460
- formatAgentId(name: string): string;
1461
- getTools(): {
1462
- transmit: Tool<z.ZodObject<{
1463
- actions: z.ZodArray<z.ZodObject<{
1464
- agent: z.ZodString;
1465
- input: z.ZodString;
1466
- includeHistory: z.ZodOptional<z.ZodBoolean>;
1467
- }, "strip", z.ZodTypeAny, {
1468
- input: string;
1469
- agent: string;
1470
- includeHistory?: boolean | undefined;
1471
- }, {
1472
- input: string;
1473
- agent: string;
1474
- includeHistory?: boolean | undefined;
1475
- }>, "many">;
1476
- }, "strip", z.ZodTypeAny, {
1477
- actions: {
1478
- input: string;
1479
- agent: string;
1480
- includeHistory?: boolean | undefined;
1481
- }[];
1482
- }, {
1483
- actions: {
1484
- input: string;
1485
- agent: string;
1486
- includeHistory?: boolean | undefined;
1487
- }[];
1488
- }>, undefined, ToolExecutionContext<z.ZodObject<{
1489
- actions: z.ZodArray<z.ZodObject<{
1490
- agent: z.ZodString;
1491
- input: z.ZodString;
1492
- includeHistory: z.ZodOptional<z.ZodBoolean>;
1493
- }, "strip", z.ZodTypeAny, {
1494
- input: string;
1495
- agent: string;
1496
- includeHistory?: boolean | undefined;
1497
- }, {
1498
- input: string;
1499
- agent: string;
1500
- includeHistory?: boolean | undefined;
1501
- }>, "many">;
1502
- }, "strip", z.ZodTypeAny, {
1503
- actions: {
1504
- input: string;
1505
- agent: string;
1506
- includeHistory?: boolean | undefined;
1507
- }[];
1508
- }, {
1509
- actions: {
1510
- input: string;
1511
- agent: string;
1512
- includeHistory?: boolean | undefined;
1513
- }[];
1514
- }>>>;
1518
+ model: MastraLanguageModel;
1519
+ tools?: TTools;
1520
+ mastra?: Mastra;
1521
+ /** @deprecated This property is deprecated. Use evals instead to add evaluation metrics. */
1522
+ metrics?: TMetrics;
1523
+ evals?: TMetrics;
1524
+ memory?: MastraMemory;
1525
+ voice?: CompositeVoice;
1526
+ }
1527
+ /**
1528
+ * Options for generating responses with an agent
1529
+ * @template Z - The schema type for structured output (Zod schema or JSON schema)
1530
+ */
1531
+ type AgentGenerateOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
1532
+ /** Optional instructions to override the agent's default instructions */
1533
+ instructions?: string;
1534
+ /** Additional tool sets that can be used for this generation */
1535
+ toolsets?: ToolsetsInput;
1536
+ /** Additional context messages to include */
1537
+ context?: CoreMessage[];
1538
+ /** Memory configuration options */
1539
+ memoryOptions?: MemoryConfig;
1540
+ /** Unique ID for this generation run */
1541
+ runId?: string;
1542
+ /** Callback fired after each generation step completes */
1543
+ onStepFinish?: Z extends undefined ? GenerateTextOnStepFinishCallback<any> : never;
1544
+ /** Maximum number of steps allowed for generation */
1545
+ maxSteps?: number;
1546
+ /** Schema for structured output, does not work with tools, use experimental_output instead */
1547
+ output?: OutputType | Z;
1548
+ /** Schema for structured output generation alongside tool calls. */
1549
+ experimental_output?: Z;
1550
+ /** Controls how tools are selected during generation */
1551
+ toolChoice?: 'auto' | 'none' | 'required' | {
1552
+ type: 'tool';
1553
+ toolName: string;
1515
1554
  };
1516
- getAgentHistory(agentId: string): {
1517
- input: string;
1518
- output: string;
1519
- timestamp: string;
1520
- }[];
1521
- /**
1522
- * Get the history of all agent interactions that have occurred in this network
1523
- * @returns A record of agent interactions, keyed by agent ID
1524
- */
1525
- getAgentInteractionHistory(): {
1526
- [x: string]: {
1527
- input: string;
1528
- output: string;
1529
- timestamp: string;
1530
- }[];
1555
+ /** Telemetry settings */
1556
+ telemetry?: TelemetrySettings;
1557
+ } & ({
1558
+ resourceId?: undefined;
1559
+ threadId?: undefined;
1560
+ } | {
1561
+ resourceId: string;
1562
+ threadId: string;
1563
+ }) & (Z extends undefined ? DefaultLLMTextOptions : DefaultLLMTextObjectOptions);
1564
+ /**
1565
+ * Options for streaming responses with an agent
1566
+ * @template Z - The schema type for structured output (Zod schema or JSON schema)
1567
+ */
1568
+ type AgentStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
1569
+ /** Optional instructions to override the agent's default instructions */
1570
+ instructions?: string;
1571
+ /** Additional tool sets that can be used for this generation */
1572
+ toolsets?: ToolsetsInput;
1573
+ /** Additional context messages to include */
1574
+ context?: CoreMessage[];
1575
+ /** Memory configuration options */
1576
+ memoryOptions?: MemoryConfig;
1577
+ /** Unique ID for this generation run */
1578
+ runId?: string;
1579
+ /** Callback fired when streaming completes */
1580
+ onFinish?: Z extends undefined ? StreamTextOnFinishCallback<any> : Z extends ZodSchema ? StreamObjectOnFinishCallback<z.infer<Z>> : StreamObjectOnFinishCallback<any>;
1581
+ /** Callback fired after each generation step completes */
1582
+ onStepFinish?: Z extends undefined ? StreamTextOnStepFinishCallback<any> : never;
1583
+ /** Maximum number of steps allowed for generation */
1584
+ maxSteps?: number;
1585
+ /** Schema for structured output */
1586
+ output?: OutputType | Z;
1587
+ /** Temperature parameter for controlling randomness */
1588
+ temperature?: number;
1589
+ /** Controls how tools are selected during generation */
1590
+ toolChoice?: 'auto' | 'none' | 'required' | {
1591
+ type: 'tool';
1592
+ toolName: string;
1531
1593
  };
1532
- /**
1533
- * Get a summary of agent interactions in a more readable format, displayed chronologically
1534
- * @returns A formatted string with all agent interactions in chronological order
1535
- */
1536
- getAgentInteractionSummary(): string;
1537
- executeAgent(agentId: string, input: CoreMessage$1[], includeHistory?: boolean): Promise<string>;
1538
- getInstructions(): string;
1539
- getRoutingAgent(): Agent<ToolsInput, Record<string, Metric>>;
1540
- getAgents(): Agent<ToolsInput, Record<string, Metric>>[];
1541
- generate<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentGenerateOptions<Z> & {
1542
- output?: never;
1543
- experimental_output?: never;
1544
- }): Promise<GenerateTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown>>;
1545
- generate<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentGenerateOptions<Z> & ({
1546
- output: Z;
1547
- experimental_output?: never;
1548
- } | {
1549
- experimental_output: Z;
1550
- output?: never;
1551
- })): Promise<GenerateObjectResult<Z extends ZodSchema ? z.infer<Z> : unknown>>;
1552
- stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentStreamOptions<Z> & {
1553
- output?: never;
1554
- experimental_output?: never;
1555
- }): Promise<StreamTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown>>;
1556
- stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], args?: AgentStreamOptions<Z> & ({
1557
- output: Z;
1558
- experimental_output?: never;
1559
- } | {
1560
- experimental_output: Z;
1561
- output?: never;
1562
- })): Promise<StreamObjectResult<any, Z extends ZodSchema ? z.infer<Z> : unknown, any>>;
1563
- __registerMastra(p: Mastra): void;
1564
- }
1594
+ /** Experimental schema for structured output */
1595
+ experimental_output?: Z;
1596
+ /** Telemetry settings */
1597
+ telemetry?: TelemetrySettings;
1598
+ } & ({
1599
+ resourceId?: undefined;
1600
+ threadId?: undefined;
1601
+ } | {
1602
+ resourceId: string;
1603
+ threadId: string;
1604
+ }) & (Z extends undefined ? DefaultLLMStreamOptions : DefaultLLMStreamObjectOptions);
1605
+
1606
+ type Methods = 'GET' | 'POST' | 'PUT' | 'DELETE';
1607
+ type ApiRoute = {
1608
+ path: string;
1609
+ method: Methods;
1610
+ handler: Handler;
1611
+ middleware?: MiddlewareHandler | MiddlewareHandler[];
1612
+ openapi?: DescribeRouteOptions;
1613
+ };
1614
+ type Middleware = MiddlewareHandler | {
1615
+ path: string;
1616
+ handler: MiddlewareHandler;
1617
+ };
1618
+ type ServerConfig = {
1619
+ apiRoutes?: ApiRoute[];
1620
+ middleware?: Middleware | Middleware[];
1621
+ };
1565
1622
 
1566
1623
  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>> {
1567
1624
  agents?: TAgents;
@@ -1573,9 +1630,11 @@ interface Config<TAgents extends Record<string, Agent<any>> = Record<string, Age
1573
1630
  tts?: TTTS;
1574
1631
  telemetry?: OtelConfig;
1575
1632
  deployer?: MastraDeployer;
1633
+ server?: ServerConfig;
1576
1634
  /**
1577
1635
  * Server middleware functions to be applied to API routes
1578
1636
  * Each middleware can specify a path pattern (defaults to '/api/*')
1637
+ * @deprecated use server.middleware instead
1579
1638
  */
1580
1639
  serverMiddleware?: Array<{
1581
1640
  handler: (c: any, next: () => Promise<void>) => Promise<Response | void>;
@@ -1624,6 +1683,7 @@ declare class Mastra<TAgents extends Record<string, Agent<any>> = Record<string,
1624
1683
  path: string;
1625
1684
  }[];
1626
1685
  getNetworks(): AgentNetwork[];
1686
+ getServer(): ServerConfig | undefined;
1627
1687
  /**
1628
1688
  * Get a specific network by ID
1629
1689
  * @param networkId - The ID of the network to retrieve
@@ -1683,9 +1743,9 @@ declare class MastraLLMBase extends MastraBase {
1683
1743
  stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], options?: LLMStreamOptions<Z>): Promise<StreamReturn<Z>>;
1684
1744
  }
1685
1745
 
1686
- declare class Agent<TTools extends ToolsInput = ToolsInput, TMetrics extends Record<string, Metric> = Record<string, Metric>> extends MastraBase {
1746
+ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput = ToolsInput, TMetrics extends Record<string, Metric> = Record<string, Metric>> extends MastraBase {
1687
1747
  #private;
1688
- name: string;
1748
+ name: TAgentId;
1689
1749
  readonly llm: MastraLLMBase;
1690
1750
  instructions: string;
1691
1751
  readonly model?: MastraLanguageModel;
@@ -1693,8 +1753,8 @@ declare class Agent<TTools extends ToolsInput = ToolsInput, TMetrics extends Rec
1693
1753
  /** @deprecated This property is deprecated. Use evals instead. */
1694
1754
  metrics: TMetrics;
1695
1755
  evals: TMetrics;
1696
- voice?: CompositeVoice;
1697
- constructor(config: AgentConfig<TTools, TMetrics>);
1756
+ voice: CompositeVoice;
1757
+ constructor(config: AgentConfig<TAgentId, TTools, TMetrics>);
1698
1758
  hasOwnMemory(): boolean;
1699
1759
  getMemory(): MastraMemory | undefined;
1700
1760
  __updateInstructions(newInstructions: string): void;
@@ -1710,11 +1770,12 @@ declare class Agent<TTools extends ToolsInput = ToolsInput, TMetrics extends Rec
1710
1770
  }): Promise<string>;
1711
1771
  getMostRecentUserMessage(messages: Array<CoreMessage$1>): CoreUserMessage$1 | undefined;
1712
1772
  genTitle(userMessage: CoreUserMessage$1 | undefined): Promise<string>;
1713
- fetchMemory({ threadId, memoryConfig, resourceId, userMessages, runId, }: {
1773
+ fetchMemory({ threadId, memoryConfig, resourceId, userMessages, systemMessage, runId, }: {
1714
1774
  resourceId: string;
1715
1775
  threadId: string;
1716
1776
  memoryConfig?: MemoryConfig;
1717
1777
  userMessages: CoreMessage$1[];
1778
+ systemMessage: CoreMessage$1;
1718
1779
  time?: Date;
1719
1780
  keyword?: string;
1720
1781
  runId?: string;
@@ -1736,12 +1797,13 @@ declare class Agent<TTools extends ToolsInput = ToolsInput, TMetrics extends Rec
1736
1797
  resourceId?: string;
1737
1798
  runId?: string;
1738
1799
  }): Record<string, CoreTool>;
1739
- preExecute({ resourceId, runId, threadId, memoryConfig, messages, }: {
1800
+ preExecute({ resourceId, runId, threadId, memoryConfig, messages, systemMessage, }: {
1740
1801
  runId?: string;
1741
1802
  threadId: string;
1742
1803
  memoryConfig?: MemoryConfig;
1743
1804
  messages: CoreMessage$1[];
1744
1805
  resourceId: string;
1806
+ systemMessage: CoreMessage$1;
1745
1807
  }): Promise<{
1746
1808
  coreMessages: CoreMessage$1[];
1747
1809
  threadIdToUse: string;
@@ -1760,10 +1822,12 @@ declare class Agent<TTools extends ToolsInput = ToolsInput, TMetrics extends Rec
1760
1822
  messageObjects: CoreMessage$1[];
1761
1823
  convertedTools: Record<string, CoreTool> | undefined;
1762
1824
  threadId: string;
1825
+ thread: StorageThreadType | null | undefined;
1763
1826
  }>;
1764
- after: ({ result, threadId, memoryConfig, outputText, runId, }: {
1827
+ after: ({ result, thread: threadAfter, threadId, memoryConfig, outputText, runId, }: {
1765
1828
  runId: string;
1766
1829
  result: Record<string, any>;
1830
+ thread: StorageThreadType | null | undefined;
1767
1831
  threadId: string;
1768
1832
  memoryConfig: MemoryConfig | undefined;
1769
1833
  outputText: string;
@@ -1827,6 +1891,11 @@ declare class Agent<TTools extends ToolsInput = ToolsInput, TMetrics extends Rec
1827
1891
  getSpeakers(): Promise<{
1828
1892
  voiceId: string;
1829
1893
  }[]>;
1894
+ toStep(): Step<TAgentId, z.ZodObject<{
1895
+ prompt: z.ZodString;
1896
+ }>, z.ZodObject<{
1897
+ text: z.ZodString;
1898
+ }>, any>;
1830
1899
  }
1831
1900
 
1832
1901
  interface StorageColumn {
@@ -1878,6 +1947,7 @@ declare const TABLE_MESSAGES = "mastra_messages";
1878
1947
  declare const TABLE_THREADS = "mastra_threads";
1879
1948
  declare const TABLE_TRACES = "mastra_traces";
1880
1949
  type TABLE_NAMES = typeof TABLE_WORKFLOW_SNAPSHOT | typeof TABLE_EVALS | typeof TABLE_MESSAGES | typeof TABLE_THREADS | typeof TABLE_TRACES;
1950
+ declare const TABLE_SCHEMAS: Record<TABLE_NAMES, Record<string, StorageColumn>>;
1881
1951
 
1882
1952
  type MessageType = {
1883
1953
  id: string;
@@ -1885,6 +1955,7 @@ type MessageType = {
1885
1955
  role: 'system' | 'user' | 'assistant' | 'tool';
1886
1956
  createdAt: Date;
1887
1957
  threadId: string;
1958
+ resourceId: string;
1888
1959
  toolCallIds?: string[];
1889
1960
  toolCallArgs?: Record<string, unknown>[];
1890
1961
  toolNames?: string[];
@@ -1925,6 +1996,7 @@ type SharedMemoryConfig = {
1925
1996
  options?: MemoryConfig;
1926
1997
  vector?: MastraVector;
1927
1998
  embedder?: EmbeddingModel<string>;
1999
+ processors?: MemoryProcessor[];
1928
2000
  };
1929
2001
 
1930
2002
  declare abstract class MastraStorage extends MastraBase {
@@ -2035,4 +2107,4 @@ declare abstract class MastraStorage extends MastraBase {
2035
2107
  __getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
2036
2108
  }
2037
2109
 
2038
- 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 };
2110
+ export { type MemoryProcessorOpts as $, type ApiRoute as A, type BaseStructuredOutputType as B, CompositeVoice 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, type Methods as M, type LLMTextOptions as N, type OutputType as O, type LLMTextObjectOptions as P, type LLMStreamOptions as Q, type LLMInnerStreamOptions as R, type StorageColumn as S, type TABLE_NAMES as T, type LLMStreamObjectOptions as U, type VoiceEventType as V, Workflow as W, type Config as X, type MessageResponse as Y, type MemoryConfig as Z, type SharedMemoryConfig as _, Mastra as a, MemoryProcessor as a0, createTool as a1, type VercelTool as a2, type CoreTool as a3, type StepExecutionContext as a4, type StepAction as a5, type StepVariableType as a6, type StepNode as a7, type StepGraph as a8, type RetryConfig as a9, type ExtractSchemaType as aA, type PathsToStringProps as aB, type WorkflowRunState as aC, type WorkflowResumeResult as aD, createStep as aE, type MastraLanguageModel as aF, type ToolsInput as aG, type MastraPrimitives as aH, AgentNetwork as aI, type AgentNetworkConfig as aJ, type ToolsetsInput as aK, type AgentGenerateOptions as aL, type AgentStreamOptions as aM, TABLE_WORKFLOW_SNAPSHOT as aN, TABLE_EVALS as aO, TABLE_MESSAGES as aP, TABLE_THREADS as aQ, TABLE_TRACES as aR, TABLE_SCHEMAS as aS, type VariableReference as aa, type BaseCondition as ab, type ActionContext as ac, WhenConditionReturnValue as ad, type StepDef as ae, type StepCondition as af, type StepConfig as ag, type StepResult as ah, type StepsRecord as ai, type WorkflowRunResult as aj, type WorkflowContext as ak, type WorkflowLogMessage as al, type WorkflowEvent as am, type ResolverFunctionInput as an, type ResolverFunctionOutput as ao, type SubscriberFunctionOutput as ap, type DependencyCheckOutput as aq, type StepResolverOutput as ar, type WorkflowActors as as, type WorkflowActionParams as at, type WorkflowActions as au, type WorkflowState as av, type StepId as aw, type ExtractSchemaFromStep as ax, type ExtractStepResult as ay, type StepInputType as az, MastraVoice as b, type VoiceEventMap as c, type VoiceConfig as d, MastraStorage as e, type StorageThreadType as f, type MessageType as g, type StorageGetMessagesArg as h, type ToolAction as i, Agent as j, type AgentConfig as k, MastraMemory as l, type ToolExecutionContext as m, Tool as n, Step 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 };