@mastra/core 0.20.0 → 0.20.1-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 (200) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/agent/agent.d.ts +375 -9
  3. package/dist/agent/agent.d.ts.map +1 -1
  4. package/dist/agent/index.cjs +11 -11
  5. package/dist/agent/index.js +2 -2
  6. package/dist/agent/input-processor/index.cjs +6 -6
  7. package/dist/agent/input-processor/index.js +1 -1
  8. package/dist/agent/types.d.ts +66 -0
  9. package/dist/agent/types.d.ts.map +1 -1
  10. package/dist/agent/workflows/prepare-stream/index.d.ts +19 -3
  11. package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
  12. package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +5 -1
  13. package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts.map +1 -1
  14. package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts +5 -1
  15. package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts.map +1 -1
  16. package/dist/agent/workflows/prepare-stream/stream-step.d.ts +5 -1
  17. package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
  18. package/dist/ai-tracing/index.cjs +32 -32
  19. package/dist/ai-tracing/index.js +1 -1
  20. package/dist/{chunk-3NNB72OL.cjs → chunk-33DTPWTJ.cjs} +7 -7
  21. package/dist/{chunk-3NNB72OL.cjs.map → chunk-33DTPWTJ.cjs.map} +1 -1
  22. package/dist/{chunk-CJDOU6WP.js → chunk-3KBXOXG6.js} +3 -3
  23. package/dist/{chunk-CJDOU6WP.js.map → chunk-3KBXOXG6.js.map} +1 -1
  24. package/dist/{chunk-ZNK5RN5D.cjs → chunk-3Z3DP6S2.cjs} +6 -6
  25. package/dist/{chunk-ZNK5RN5D.cjs.map → chunk-3Z3DP6S2.cjs.map} +1 -1
  26. package/dist/{chunk-KGBDRSMX.js → chunk-5I6DXBUR.js} +4 -4
  27. package/dist/{chunk-KGBDRSMX.js.map → chunk-5I6DXBUR.js.map} +1 -1
  28. package/dist/{chunk-7EUC32F3.cjs → chunk-6K7IMZVR.cjs} +617 -24
  29. package/dist/chunk-6K7IMZVR.cjs.map +1 -0
  30. package/dist/{chunk-FV4QVXO4.js → chunk-6OLRLZJ3.js} +37 -2
  31. package/dist/chunk-6OLRLZJ3.js.map +1 -0
  32. package/dist/{chunk-OXLN4CWA.js → chunk-B5GBHE4E.js} +3 -3
  33. package/dist/{chunk-OXLN4CWA.js.map → chunk-B5GBHE4E.js.map} +1 -1
  34. package/dist/{chunk-2SH5WPUA.cjs → chunk-BG5FC6ZZ.cjs} +407 -803
  35. package/dist/chunk-BG5FC6ZZ.cjs.map +1 -0
  36. package/dist/{chunk-COYTVUIL.js → chunk-EKFF7JLS.js} +610 -17
  37. package/dist/chunk-EKFF7JLS.js.map +1 -0
  38. package/dist/{chunk-BOJNXNRV.js → chunk-FJIABZVI.js} +3 -3
  39. package/dist/{chunk-BOJNXNRV.js.map → chunk-FJIABZVI.js.map} +1 -1
  40. package/dist/{chunk-RYFQKXXS.js → chunk-H4KO46HZ.js} +3 -3
  41. package/dist/{chunk-RYFQKXXS.js.map → chunk-H4KO46HZ.js.map} +1 -1
  42. package/dist/{chunk-T4H33PBR.cjs → chunk-IKLSJCMT.cjs} +360 -69
  43. package/dist/chunk-IKLSJCMT.cjs.map +1 -0
  44. package/dist/{chunk-K4AYIXVH.cjs → chunk-L5A4MRCK.cjs} +4 -4
  45. package/dist/{chunk-K4AYIXVH.cjs.map → chunk-L5A4MRCK.cjs.map} +1 -1
  46. package/dist/{chunk-DVHBWEYY.cjs → chunk-LCJHFYJS.cjs} +7 -7
  47. package/dist/{chunk-DVHBWEYY.cjs.map → chunk-LCJHFYJS.cjs.map} +1 -1
  48. package/dist/{chunk-I6TOPBP6.cjs → chunk-MHHMY2K4.cjs} +49 -18
  49. package/dist/chunk-MHHMY2K4.cjs.map +1 -0
  50. package/dist/{chunk-DQISKQDE.js → chunk-OBAFLVGD.js} +342 -51
  51. package/dist/chunk-OBAFLVGD.js.map +1 -0
  52. package/dist/{chunk-6R46VE63.js → chunk-OPHFW56S.js} +39 -8
  53. package/dist/chunk-OPHFW56S.js.map +1 -0
  54. package/dist/{chunk-LCJP7LWN.cjs → chunk-P4ZPZKZY.cjs} +6 -6
  55. package/dist/{chunk-LCJP7LWN.cjs.map → chunk-P4ZPZKZY.cjs.map} +1 -1
  56. package/dist/{chunk-QR5VZWWT.js → chunk-P7WEYMRS.js} +3 -3
  57. package/dist/{chunk-QR5VZWWT.js.map → chunk-P7WEYMRS.js.map} +1 -1
  58. package/dist/{chunk-YEEAHLAK.cjs → chunk-PWPESTZZ.cjs} +4 -4
  59. package/dist/{chunk-YEEAHLAK.cjs.map → chunk-PWPESTZZ.cjs.map} +1 -1
  60. package/dist/{chunk-7HUKQ6SZ.cjs → chunk-Q3S3BXHO.cjs} +4 -4
  61. package/dist/{chunk-7HUKQ6SZ.cjs.map → chunk-Q3S3BXHO.cjs.map} +1 -1
  62. package/dist/{chunk-WP2KQXPV.js → chunk-RMMGYPXG.js} +3 -3
  63. package/dist/{chunk-WP2KQXPV.js.map → chunk-RMMGYPXG.js.map} +1 -1
  64. package/dist/{chunk-A4RAEU6X.cjs → chunk-SE4PA467.cjs} +37 -2
  65. package/dist/chunk-SE4PA467.cjs.map +1 -0
  66. package/dist/{chunk-AND6J5LG.js → chunk-W2WXYTYI.js} +407 -803
  67. package/dist/chunk-W2WXYTYI.js.map +1 -0
  68. package/dist/{chunk-OKIHIKXV.cjs → chunk-WE6ILDQY.cjs} +4 -4
  69. package/dist/{chunk-OKIHIKXV.cjs.map → chunk-WE6ILDQY.cjs.map} +1 -1
  70. package/dist/{chunk-ZJ2UFCTS.js → chunk-Y2TIJVKC.js} +3 -3
  71. package/dist/{chunk-ZJ2UFCTS.js.map → chunk-Y2TIJVKC.js.map} +1 -1
  72. package/dist/index.cjs +52 -52
  73. package/dist/index.cjs.map +1 -1
  74. package/dist/index.js +11 -11
  75. package/dist/index.js.map +1 -1
  76. package/dist/integration/index.cjs +3 -3
  77. package/dist/integration/index.js +1 -1
  78. package/dist/llm/index.cjs +6 -6
  79. package/dist/llm/index.d.ts +1 -1
  80. package/dist/llm/index.d.ts.map +1 -1
  81. package/dist/llm/index.js +1 -1
  82. package/dist/llm/model/gateway-resolver.d.ts +7 -5
  83. package/dist/llm/model/gateway-resolver.d.ts.map +1 -1
  84. package/dist/llm/model/gateways/base.d.ts +8 -6
  85. package/dist/llm/model/gateways/base.d.ts.map +1 -1
  86. package/dist/llm/model/gateways/constants.d.ts +3 -0
  87. package/dist/llm/model/gateways/constants.d.ts.map +1 -0
  88. package/dist/llm/model/gateways/index.d.ts +5 -0
  89. package/dist/llm/model/gateways/index.d.ts.map +1 -1
  90. package/dist/llm/model/gateways/models-dev.d.ts +8 -2
  91. package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
  92. package/dist/llm/model/gateways/netlify.d.ts +11 -2
  93. package/dist/llm/model/gateways/netlify.d.ts.map +1 -1
  94. package/dist/llm/model/index.d.ts +1 -1
  95. package/dist/llm/model/index.d.ts.map +1 -1
  96. package/dist/llm/model/model.loop.d.ts +1 -1
  97. package/dist/llm/model/model.loop.d.ts.map +1 -1
  98. package/dist/llm/model/provider-registry.generated.d.ts +6 -7
  99. package/dist/llm/model/provider-registry.generated.d.ts.map +1 -1
  100. package/dist/llm/model/router.d.ts +23 -0
  101. package/dist/llm/model/router.d.ts.map +1 -0
  102. package/dist/loop/index.cjs +2 -2
  103. package/dist/loop/index.js +1 -1
  104. package/dist/loop/network/index.d.ts +5 -1
  105. package/dist/loop/network/index.d.ts.map +1 -1
  106. package/dist/loop/workflows/agentic-execution/index.d.ts +5 -1
  107. package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
  108. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +5 -1
  109. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
  110. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +5 -1
  111. package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
  112. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +5 -1
  113. package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
  114. package/dist/loop/workflows/agentic-loop/index.d.ts +5 -1
  115. package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
  116. package/dist/mastra/index.cjs +2 -2
  117. package/dist/mastra/index.d.ts +695 -12
  118. package/dist/mastra/index.d.ts.map +1 -1
  119. package/dist/mastra/index.js +1 -1
  120. package/dist/memory/index.cjs +4 -4
  121. package/dist/memory/index.js +1 -1
  122. package/dist/processors/index.cjs +11 -11
  123. package/dist/processors/index.js +1 -1
  124. package/dist/relevance/index.cjs +4 -4
  125. package/dist/relevance/index.js +1 -1
  126. package/dist/scores/index.cjs +9 -9
  127. package/dist/scores/index.js +2 -2
  128. package/dist/scores/run-experiment/index.d.ts +2 -2
  129. package/dist/scores/run-experiment/index.d.ts.map +1 -1
  130. package/dist/scores/scoreTraces/index.cjs +8 -8
  131. package/dist/scores/scoreTraces/index.js +3 -3
  132. package/dist/scores/scoreTraces/scoreTracesWorkflow.d.ts +10 -2
  133. package/dist/scores/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -1
  134. package/dist/storage/domains/operations/base.d.ts +6 -0
  135. package/dist/storage/domains/operations/base.d.ts.map +1 -1
  136. package/dist/storage/index.cjs +11 -3
  137. package/dist/storage/index.cjs.map +1 -1
  138. package/dist/storage/index.js +9 -1
  139. package/dist/storage/index.js.map +1 -1
  140. package/dist/stream/MastraAgentNetworkStream.d.ts +5 -1
  141. package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -1
  142. package/dist/stream/MastraWorkflowStream.d.ts +3 -3
  143. package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
  144. package/dist/stream/index.cjs +4 -4
  145. package/dist/stream/index.js +1 -1
  146. package/dist/test-utils/llm-mock.cjs +2 -2
  147. package/dist/test-utils/llm-mock.js +1 -1
  148. package/dist/tools/index.cjs +4 -4
  149. package/dist/tools/index.js +1 -1
  150. package/dist/tools/is-vercel-tool.cjs +2 -2
  151. package/dist/tools/is-vercel-tool.js +1 -1
  152. package/dist/tools/tool.d.ts +163 -0
  153. package/dist/tools/tool.d.ts.map +1 -1
  154. package/dist/utils.cjs +17 -17
  155. package/dist/utils.d.ts +1 -1
  156. package/dist/utils.d.ts.map +1 -1
  157. package/dist/utils.js +1 -1
  158. package/dist/workflows/default.d.ts +13 -7
  159. package/dist/workflows/default.d.ts.map +1 -1
  160. package/dist/workflows/evented/index.cjs +10 -10
  161. package/dist/workflows/evented/index.js +1 -1
  162. package/dist/workflows/evented/step-executor.d.ts +7 -3
  163. package/dist/workflows/evented/step-executor.d.ts.map +1 -1
  164. package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
  165. package/dist/workflows/evented/workflow-event-processor/loop.d.ts.map +1 -1
  166. package/dist/workflows/evented/workflow-event-processor/parallel.d.ts.map +1 -1
  167. package/dist/workflows/evented/workflow-event-processor/utils.d.ts +1 -1
  168. package/dist/workflows/evented/workflow.d.ts +23 -19
  169. package/dist/workflows/evented/workflow.d.ts.map +1 -1
  170. package/dist/workflows/execution-engine.d.ts +5 -1
  171. package/dist/workflows/execution-engine.d.ts.map +1 -1
  172. package/dist/workflows/index.cjs +12 -12
  173. package/dist/workflows/index.js +1 -1
  174. package/dist/workflows/legacy/index.cjs +22 -22
  175. package/dist/workflows/legacy/index.js +1 -1
  176. package/dist/workflows/step.d.ts +11 -4
  177. package/dist/workflows/step.d.ts.map +1 -1
  178. package/dist/workflows/types.d.ts +33 -9
  179. package/dist/workflows/types.d.ts.map +1 -1
  180. package/dist/workflows/workflow.d.ts +85 -56
  181. package/dist/workflows/workflow.d.ts.map +1 -1
  182. package/dist/workflows/workflow.warning.d.ts +2 -2
  183. package/dist/workflows/workflow.warning.d.ts.map +1 -1
  184. package/package.json +9 -4
  185. package/dist/chunk-2SH5WPUA.cjs.map +0 -1
  186. package/dist/chunk-45CV4JYJ.cjs +0 -4
  187. package/dist/chunk-45CV4JYJ.cjs.map +0 -1
  188. package/dist/chunk-6R46VE63.js.map +0 -1
  189. package/dist/chunk-7EUC32F3.cjs.map +0 -1
  190. package/dist/chunk-A4RAEU6X.cjs.map +0 -1
  191. package/dist/chunk-AND6J5LG.js.map +0 -1
  192. package/dist/chunk-COYTVUIL.js.map +0 -1
  193. package/dist/chunk-DQISKQDE.js.map +0 -1
  194. package/dist/chunk-FV4QVXO4.js.map +0 -1
  195. package/dist/chunk-I6TOPBP6.cjs.map +0 -1
  196. package/dist/chunk-RFGQ3EQV.js +0 -3
  197. package/dist/chunk-RFGQ3EQV.js.map +0 -1
  198. package/dist/chunk-T4H33PBR.cjs.map +0 -1
  199. package/dist/llm/model/openai-compatible.d.ts +0 -37
  200. package/dist/llm/model/openai-compatible.d.ts.map +0 -1
@@ -19,22 +19,108 @@ import type { MastraIdGenerator } from '../types/index.js';
19
19
  import type { MastraVector } from '../vector/index.js';
20
20
  import type { Workflow } from '../workflows/index.js';
21
21
  import type { LegacyWorkflow } from '../workflows/legacy/index.js';
22
+ /**
23
+ * Configuration interface for initializing a Mastra instance.
24
+ *
25
+ * The Config interface defines all the optional components that can be registered
26
+ * with a Mastra instance, including agents, workflows, storage, logging, and more.
27
+ *
28
+ * @template TAgents - Record of agent instances keyed by their names
29
+ * @template TLegacyWorkflows - Record of legacy workflow instances
30
+ * @template TWorkflows - Record of workflow instances
31
+ * @template TVectors - Record of vector store instances
32
+ * @template TTTS - Record of text-to-speech instances
33
+ * @template TLogger - Logger implementation type
34
+ * @template TVNextNetworks - Record of agent network instances
35
+ * @template TMCPServers - Record of MCP server instances
36
+ * @template TScorers - Record of scorer instances
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const mastra = new Mastra({
41
+ * agents: {
42
+ * weatherAgent: new Agent({
43
+ * name: 'weather-agent',
44
+ * instructions: 'You help with weather information',
45
+ * model: 'openai/gpt-5'
46
+ * })
47
+ * },
48
+ * storage: new LibSQLStore({ url: ':memory:' }),
49
+ * logger: new PinoLogger({ name: 'MyApp' })
50
+ * });
51
+ * ```
52
+ */
22
53
  export interface Config<TAgents extends Record<string, Agent<any>> = Record<string, Agent<any>>, TLegacyWorkflows extends Record<string, LegacyWorkflow> = Record<string, LegacyWorkflow>, TWorkflows extends Record<string, Workflow<any, any, any, any, any, any>> = Record<string, Workflow<any, any, any, any, any, any>>, TVectors extends Record<string, MastraVector> = Record<string, MastraVector>, TTTS extends Record<string, MastraTTS> = Record<string, MastraTTS>, TLogger extends IMastraLogger = IMastraLogger, TMCPServers extends Record<string, MCPServerBase> = Record<string, MCPServerBase>, TScorers extends Record<string, MastraScorer<any, any, any, any>> = Record<string, MastraScorer<any, any, any, any>>> {
54
+ /**
55
+ * Agents are autonomous systems that can make decisions and take actions.
56
+ */
23
57
  agents?: TAgents;
58
+ /**
59
+ * Storage provider for persisting data, conversation history, and workflow state.
60
+ * Required for agent memory and workflow persistence.
61
+ */
24
62
  storage?: MastraStorage;
63
+ /**
64
+ * Vector stores for semantic search and retrieval-augmented generation (RAG).
65
+ * Used for storing and querying embeddings.
66
+ */
25
67
  vectors?: TVectors;
68
+ /**
69
+ * Logger implementation for application logging and debugging.
70
+ * Set to `false` to disable logging entirely.
71
+ * @default `INFO` level in development, `WARN` in production.
72
+ */
26
73
  logger?: TLogger | false;
74
+ /**
75
+ * Legacy workflow definitions for backward compatibility.
76
+ * @deprecated Use `workflows` instead.
77
+ */
27
78
  legacy_workflows?: TLegacyWorkflows;
79
+ /**
80
+ * Workflows provide type-safe, composable task execution with built-in error handling.
81
+ */
28
82
  workflows?: TWorkflows;
83
+ /**
84
+ * Text-to-speech providers for voice synthesis capabilities.
85
+ */
29
86
  tts?: TTTS;
87
+ /**
88
+ * OpenTelemetry configuration for distributed tracing and observability.
89
+ */
30
90
  telemetry?: OtelConfig;
91
+ /**
92
+ * AI-specific observability configuration for tracking model interactions.
93
+ */
31
94
  observability?: ObservabilityRegistryConfig;
95
+ /**
96
+ * Custom ID generator function for creating unique identifiers.
97
+ * @default `crypto.randomUUID()`
98
+ */
32
99
  idGenerator?: MastraIdGenerator;
100
+ /**
101
+ * Deployment provider for publishing applications to cloud platforms.
102
+ */
33
103
  deployer?: MastraDeployer;
104
+ /**
105
+ * Server configuration for HTTP endpoints and middleware.
106
+ */
34
107
  server?: ServerConfig;
108
+ /**
109
+ * MCP servers provide tools and resources that agents can use.
110
+ */
35
111
  mcpServers?: TMCPServers;
112
+ /**
113
+ * Bundler configuration for packaging and deployment.
114
+ */
36
115
  bundler?: BundlerConfig;
116
+ /**
117
+ * Pub/sub system for event-driven communication between components.
118
+ * @default EventEmitterPubSub
119
+ */
37
120
  pubsub?: PubSub;
121
+ /**
122
+ * Scorers help assess the quality of agent responses and workflow outputs.
123
+ */
38
124
  scorers?: TScorers;
39
125
  /**
40
126
  * Server middleware functions to be applied to API routes
@@ -46,6 +132,10 @@ export interface Config<TAgents extends Record<string, Agent<any>> = Record<stri
46
132
  path?: string;
47
133
  }>;
48
134
  memory?: never;
135
+ /**
136
+ * Event handlers for custom application events.
137
+ * Maps event topics to handler functions for event-driven architectures.
138
+ */
49
139
  events?: {
50
140
  [topic: string]: (event: Event, cb?: () => Promise<void>) => Promise<void> | ((event: Event, cb?: () => Promise<void>) => Promise<void>)[];
51
141
  };
@@ -65,13 +155,74 @@ export declare class Mastra<TAgents extends Record<string, Agent<any>> = Record<
65
155
  */
66
156
  get memory(): MastraMemory | undefined;
67
157
  get pubsub(): PubSub;
158
+ /**
159
+ * Gets the currently configured ID generator function.
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * const mastra = new Mastra({
164
+ * idGenerator: () => `custom-${Date.now()}`
165
+ * });
166
+ * const generator = mastra.getIdGenerator();
167
+ * console.log(generator?.()); // "custom-1234567890"
168
+ * ```
169
+ */
68
170
  getIdGenerator(): MastraIdGenerator | undefined;
69
171
  /**
70
- * Generate a unique identifier using the configured generator or default to crypto.randomUUID()
71
- * @returns A unique string ID
172
+ * Generates a unique identifier using the configured generator or defaults to `crypto.randomUUID()`.
173
+ *
174
+ * This method is used internally by Mastra for creating unique IDs for various entities
175
+ * like workflow runs, agent conversations, and other resources that need unique identification.
176
+ *
177
+ * @throws {MastraError} When the custom ID generator returns an empty string
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * const mastra = new Mastra();
182
+ * const id = mastra.generateId();
183
+ * console.log(id); // "550e8400-e29b-41d4-a716-446655440000"
184
+ * ```
72
185
  */
73
186
  generateId(): string;
187
+ /**
188
+ * Sets a custom ID generator function for creating unique identifiers.
189
+ *
190
+ * The ID generator function will be used by `generateId()` instead of the default
191
+ * `crypto.randomUUID()`. This is useful for creating application-specific ID formats
192
+ * or integrating with existing ID generation systems.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const mastra = new Mastra();
197
+ * mastra.setIdGenerator(() => `custom-${Date.now()}`);
198
+ * const id = mastra.generateId();
199
+ * console.log(id); // "custom-1234567890"
200
+ * ```
201
+ */
74
202
  setIdGenerator(idGenerator: MastraIdGenerator): void;
203
+ /**
204
+ * Creates a new Mastra instance with the provided configuration.
205
+ *
206
+ * The constructor initializes all the components specified in the config, sets up
207
+ * internal systems like logging and telemetry, and registers components with each other.
208
+ *
209
+ * @example
210
+ * ```typescript
211
+ * const mastra = new Mastra({
212
+ * agents: {
213
+ * assistant: new Agent({
214
+ * name: 'assistant',
215
+ * instructions: 'You are a helpful assistant',
216
+ * model: 'openai/gpt-5'
217
+ * })
218
+ * },
219
+ * storage: new PostgresStore({
220
+ * connectionString: process.env.DATABASE_URL
221
+ * }),
222
+ * logger: new PinoLogger({ name: 'MyApp' })
223
+ * });
224
+ * ```
225
+ */
75
226
  constructor(config?: Config<TAgents, TLegacyWorkflows, TWorkflows, TVectors, TTTS, TLogger, TMCPServers, TScorers>);
76
227
  /**
77
228
  * Register this Mastra instance with AI tracing exporters that need it
@@ -81,40 +232,518 @@ export declare class Mastra<TAgents extends Record<string, Agent<any>> = Record<
81
232
  * Initialize all AI tracing exporters after registration is complete
82
233
  */
83
234
  private initAITracingExporters;
235
+ /**
236
+ * Retrieves a registered agent by its name.
237
+ *
238
+ * @template TAgentName - The specific agent name type from the registered agents
239
+ * @throws {MastraError} When the agent with the specified name is not found
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * const mastra = new Mastra({
244
+ * agents: {
245
+ * weatherAgent: new Agent({
246
+ * name: 'weather-agent',
247
+ * instructions: 'You provide weather information',
248
+ * model: 'openai/gpt-5'
249
+ * })
250
+ * }
251
+ * });
252
+ * const agent = mastra.getAgent('weatherAgent');
253
+ * const response = await agent.generate('What is the weather?');
254
+ * ```
255
+ */
84
256
  getAgent<TAgentName extends keyof TAgents>(name: TAgentName): TAgents[TAgentName];
257
+ /**
258
+ * Retrieves a registered agent by its unique ID.
259
+ *
260
+ * This method searches for an agent using its internal ID property. If no agent
261
+ * is found with the given ID, it also attempts to find an agent using the ID as
262
+ * a name (for backward compatibility).
263
+ *
264
+ * @throws {MastraError} When no agent is found with the specified ID
265
+ *
266
+ * @example
267
+ * ```typescript
268
+ * const mastra = new Mastra({
269
+ * agents: {
270
+ * assistant: new Agent({
271
+ * name: 'assistant',
272
+ * instructions: 'You are a helpful assistant',
273
+ * model: 'openai/gpt-5'
274
+ * })
275
+ * }
276
+ * });
277
+ *
278
+ * const assistant = mastra.getAgent('assistant');
279
+ * const sameAgent = mastra.getAgentById(assistant.id);
280
+ * ```
281
+ */
85
282
  getAgentById(id: string): Agent;
283
+ /**
284
+ * Returns all registered agents as a record keyed by their names.
285
+ *
286
+ * This method provides access to the complete registry of agents, allowing you to
287
+ * iterate over them, check what agents are available, or perform bulk operations.
288
+ *
289
+ * @example
290
+ * ```typescript
291
+ * const mastra = new Mastra({
292
+ * agents: {
293
+ * weatherAgent: new Agent({ name: 'weather', model: openai('gpt-4o') }),
294
+ * supportAgent: new Agent({ name: 'support', model: openai('gpt-4o') })
295
+ * }
296
+ * });
297
+ *
298
+ * const allAgents = mastra.getAgents();
299
+ * console.log(Object.keys(allAgents)); // ['weatherAgent', 'supportAgent']
300
+ * ```
301
+ */
86
302
  getAgents(): TAgents;
303
+ /**
304
+ * Retrieves a registered vector store by its name.
305
+ *
306
+ * @template TVectorName - The specific vector store name type from the registered vectors
307
+ * @throws {MastraError} When the vector store with the specified name is not found
308
+ *
309
+ * @example Using a vector store for semantic search
310
+ * ```typescript
311
+ * import { PineconeVector } from '@mastra/pinecone';
312
+ * import { OpenAIEmbedder } from '@mastra/embedders';
313
+ *
314
+ * const mastra = new Mastra({
315
+ * vectors: {
316
+ * knowledge: new PineconeVector({
317
+ * apiKey: process.env.PINECONE_API_KEY,
318
+ * indexName: 'knowledge-base',
319
+ * embedder: new OpenAIEmbedder({
320
+ * apiKey: process.env.OPENAI_API_KEY,
321
+ * model: 'text-embedding-3-small'
322
+ * })
323
+ * }),
324
+ * products: new PineconeVector({
325
+ * apiKey: process.env.PINECONE_API_KEY,
326
+ * indexName: 'product-catalog'
327
+ * })
328
+ * }
329
+ * });
330
+ *
331
+ * // Get a vector store and perform semantic search
332
+ * const knowledgeBase = mastra.getVector('knowledge');
333
+ * const results = await knowledgeBase.query({
334
+ * query: 'How to reset password?',
335
+ * topK: 5
336
+ * });
337
+ *
338
+ * console.log('Relevant documents:', results);
339
+ * ```
340
+ */
87
341
  getVector<TVectorName extends keyof TVectors>(name: TVectorName): TVectors[TVectorName];
342
+ /**
343
+ * Returns all registered vector stores as a record keyed by their names.
344
+ *
345
+ * @example Listing all vector stores
346
+ * ```typescript
347
+ * const mastra = new Mastra({
348
+ * vectors: {
349
+ * documents: new PineconeVector({ indexName: 'docs' }),
350
+ * images: new PineconeVector({ indexName: 'images' }),
351
+ * products: new ChromaVector({ collectionName: 'products' })
352
+ * }
353
+ * });
354
+ *
355
+ * const allVectors = mastra.getVectors();
356
+ * console.log(Object.keys(allVectors)); // ['documents', 'images', 'products']
357
+ *
358
+ * // Check vector store types and configurations
359
+ * for (const [name, vectorStore] of Object.entries(allVectors)) {
360
+ * console.log(`Vector store ${name}:`, vectorStore.constructor.name);
361
+ * }
362
+ * ```
363
+ */
88
364
  getVectors(): TVectors | undefined;
365
+ /**
366
+ * Gets the currently configured deployment provider.
367
+ *
368
+ * @example
369
+ * ```typescript
370
+ * const mastra = new Mastra({
371
+ * deployer: new VercelDeployer({
372
+ * token: process.env.VERCEL_TOKEN,
373
+ * projectId: process.env.VERCEL_PROJECT_ID
374
+ * })
375
+ * });
376
+ *
377
+ * const deployer = mastra.getDeployer();
378
+ * if (deployer) {
379
+ * await deployer.deploy({
380
+ * name: 'my-mastra-app',
381
+ * environment: 'production'
382
+ * });
383
+ * }
384
+ * ```
385
+ */
89
386
  getDeployer(): MastraDeployer | undefined;
387
+ /**
388
+ * Retrieves a registered legacy workflow by its ID.
389
+ *
390
+ * Legacy workflows are the previous generation of workflow system in Mastra,
391
+ * maintained for backward compatibility. For new implementations, use the
392
+ * modern workflow system accessed via `getWorkflow()`.
393
+ *
394
+ * @template TWorkflowId - The specific workflow ID type from the registered legacy workflows
395
+ * @throws {MastraError} When the legacy workflow with the specified ID is not found
396
+ * @deprecated Use `getWorkflow()` for new implementations
397
+ *
398
+ * @example Getting a legacy workflow
399
+ * ```typescript
400
+ * const mastra = new Mastra({
401
+ * legacy_workflows: {
402
+ * oldDataFlow: legacyWorkflowInstance
403
+ * }
404
+ * });
405
+ *
406
+ * const workflow = mastra.legacy_getWorkflow('oldDataFlow');
407
+ * const result = await workflow.execute({ input: 'data' });
408
+ * ```
409
+ */
90
410
  legacy_getWorkflow<TWorkflowId extends keyof TLegacyWorkflows>(id: TWorkflowId, { serialized }?: {
91
411
  serialized?: boolean;
92
412
  }): TLegacyWorkflows[TWorkflowId];
413
+ /**
414
+ * Retrieves a registered workflow by its ID.
415
+ *
416
+ * @template TWorkflowId - The specific workflow ID type from the registered workflows
417
+ * @throws {MastraError} When the workflow with the specified ID is not found
418
+ *
419
+ * @example Getting and executing a workflow
420
+ * ```typescript
421
+ * import { createWorkflow, createStep } from '@mastra/core/workflows';
422
+ * import { z } from 'zod';
423
+ *
424
+ * const processDataWorkflow = createWorkflow({
425
+ * name: 'process-data',
426
+ * triggerSchema: z.object({ input: z.string() })
427
+ * })
428
+ * .then(validateStep)
429
+ * .then(transformStep)
430
+ * .then(saveStep)
431
+ * .commit();
432
+ *
433
+ * const mastra = new Mastra({
434
+ * workflows: {
435
+ * dataProcessor: processDataWorkflow
436
+ * }
437
+ * });
438
+ * ```
439
+ */
93
440
  getWorkflow<TWorkflowId extends keyof TWorkflows>(id: TWorkflowId, { serialized }?: {
94
441
  serialized?: boolean;
95
442
  }): TWorkflows[TWorkflowId];
96
443
  __registerInternalWorkflow(workflow: Workflow): void;
97
444
  __hasInternalWorkflow(id: string): boolean;
98
445
  __getInternalWorkflow(id: string): Workflow;
446
+ /**
447
+ * Retrieves a registered workflow by its unique ID.
448
+ *
449
+ * This method searches for a workflow using its internal ID property. If no workflow
450
+ * is found with the given ID, it also attempts to find a workflow using the ID as
451
+ * a name (for backward compatibility).
452
+ *
453
+ * @throws {MastraError} When no workflow is found with the specified ID
454
+ *
455
+ * @example Finding a workflow by ID
456
+ * ```typescript
457
+ * const mastra = new Mastra({
458
+ * workflows: {
459
+ * dataProcessor: createWorkflow({
460
+ * name: 'process-data',
461
+ * triggerSchema: z.object({ input: z.string() })
462
+ * }).commit()
463
+ * }
464
+ * });
465
+ *
466
+ * // Get the workflow's ID
467
+ * const workflow = mastra.getWorkflow('dataProcessor');
468
+ * const workflowId = workflow.id;
469
+ *
470
+ * // Later, retrieve the workflow by ID
471
+ * const sameWorkflow = mastra.getWorkflowById(workflowId);
472
+ * console.log(sameWorkflow.name); // "process-data"
473
+ * ```
474
+ */
99
475
  getWorkflowById(id: string): Workflow;
476
+ /**
477
+ * Returns all registered legacy workflows as a record keyed by their IDs.
478
+ *
479
+ * Legacy workflows are the previous generation of workflow system in Mastra,
480
+ * maintained for backward compatibility. For new implementations, use `getWorkflows()`.
481
+ *
482
+ * @deprecated Use `getWorkflows()` for new implementations
483
+ *
484
+ * @example Listing all legacy workflows
485
+ * ```typescript
486
+ * const mastra = new Mastra({
487
+ * legacy_workflows: {
488
+ * oldFlow1: legacyWorkflow1,
489
+ * oldFlow2: legacyWorkflow2
490
+ * }
491
+ * });
492
+ *
493
+ * const allLegacyWorkflows = mastra.legacy_getWorkflows();
494
+ * console.log(Object.keys(allLegacyWorkflows)); // ['oldFlow1', 'oldFlow2']
495
+ *
496
+ * // Execute all legacy workflows
497
+ * for (const [id, workflow] of Object.entries(allLegacyWorkflows)) {
498
+ * console.log(`Legacy workflow ${id}:`, workflow.name);
499
+ * }
500
+ * ```
501
+ */
100
502
  legacy_getWorkflows(props?: {
101
503
  serialized?: boolean;
102
504
  }): Record<string, LegacyWorkflow>;
505
+ /**
506
+ * Returns all registered scorers as a record keyed by their IDs.
507
+ *
508
+ * @example Listing all scorers
509
+ * ```typescript
510
+ * import { HelpfulnessScorer, AccuracyScorer, RelevanceScorer } from '@mastra/scorers';
511
+ *
512
+ * const mastra = new Mastra({
513
+ * scorers: {
514
+ * helpfulness: new HelpfulnessScorer(),
515
+ * accuracy: new AccuracyScorer(),
516
+ * relevance: new RelevanceScorer()
517
+ * }
518
+ * });
519
+ *
520
+ * const allScorers = mastra.getScorers();
521
+ * console.log(Object.keys(allScorers)); // ['helpfulness', 'accuracy', 'relevance']
522
+ *
523
+ * // Check scorer configurations
524
+ * for (const [id, scorer] of Object.entries(allScorers)) {
525
+ * console.log(`Scorer ${id}:`, scorer.name, scorer.description);
526
+ * }
527
+ * ```
528
+ */
103
529
  getScorers(): TScorers | undefined;
530
+ /**
531
+ * Retrieves a registered scorer by its key.
532
+ *
533
+ * @template TScorerKey - The specific scorer key type from the registered scorers
534
+ * @throws {MastraError} When the scorer with the specified key is not found
535
+ *
536
+ * @example Getting and using a scorer
537
+ * ```typescript
538
+ * import { HelpfulnessScorer, AccuracyScorer } from '@mastra/scorers';
539
+ *
540
+ * const mastra = new Mastra({
541
+ * scorers: {
542
+ * helpfulness: new HelpfulnessScorer({
543
+ * model: openai('gpt-4o'),
544
+ * criteria: 'Rate how helpful this response is'
545
+ * }),
546
+ * accuracy: new AccuracyScorer({
547
+ * model: 'openai/gpt-5'
548
+ * })
549
+ * }
550
+ * });
551
+ *
552
+ * // Get a specific scorer
553
+ * const helpfulnessScorer = mastra.getScorer('helpfulness');
554
+ * const score = await helpfulnessScorer.score({
555
+ * input: 'How do I reset my password?',
556
+ * output: 'You can reset your password by clicking the forgot password link.',
557
+ * expected: 'Detailed password reset instructions'
558
+ * });
559
+ *
560
+ * console.log('Helpfulness score:', score);
561
+ * ```
562
+ */
104
563
  getScorer<TScorerKey extends keyof TScorers>(key: TScorerKey): TScorers[TScorerKey];
564
+ /**
565
+ * Retrieves a registered scorer by its name.
566
+ *
567
+ * This method searches through all registered scorers to find one with the specified name.
568
+ * Unlike `getScorer()` which uses the registration key, this method uses the scorer's
569
+ * internal name property.
570
+ *
571
+ * @throws {MastraError} When no scorer is found with the specified name
572
+ *
573
+ * @example Finding a scorer by name
574
+ * ```typescript
575
+ * import { HelpfulnessScorer } from '@mastra/scorers';
576
+ *
577
+ * const mastra = new Mastra({
578
+ * scorers: {
579
+ * myHelpfulnessScorer: new HelpfulnessScorer({
580
+ * name: 'helpfulness-evaluator',
581
+ * model: 'openai/gpt-5'
582
+ * })
583
+ * }
584
+ * });
585
+ *
586
+ * // Find scorer by its internal name, not the registration key
587
+ * const scorer = mastra.getScorerByName('helpfulness-evaluator');
588
+ * const score = await scorer.score({
589
+ * input: 'question',
590
+ * output: 'answer'
591
+ * });
592
+ * ```
593
+ */
105
594
  getScorerByName(name: string): MastraScorer<any, any, any, any>;
595
+ /**
596
+ * Returns all registered workflows as a record keyed by their IDs.
597
+ *
598
+ * @example Listing all workflows
599
+ * ```typescript
600
+ * const mastra = new Mastra({
601
+ * workflows: {
602
+ * dataProcessor: createWorkflow({...}).commit(),
603
+ * emailSender: createWorkflow({...}).commit(),
604
+ * reportGenerator: createWorkflow({...}).commit()
605
+ * }
606
+ * });
607
+ *
608
+ * const allWorkflows = mastra.getWorkflows();
609
+ * console.log(Object.keys(allWorkflows)); // ['dataProcessor', 'emailSender', 'reportGenerator']
610
+ *
611
+ * // Execute all workflows with sample data
612
+ * for (const [id, workflow] of Object.entries(allWorkflows)) {
613
+ * console.log(`Workflow ${id}:`, workflow.name);
614
+ * // const result = await workflow.execute(sampleData);
615
+ * }
616
+ * ```
617
+ */
106
618
  getWorkflows(props?: {
107
619
  serialized?: boolean;
108
620
  }): Record<string, Workflow>;
621
+ /**
622
+ * Sets the storage provider for the Mastra instance.
623
+ *
624
+ * @example
625
+ * ```typescript
626
+ * const mastra = new Mastra();
627
+ *
628
+ * // Set PostgreSQL storage
629
+ * mastra.setStorage(new PostgresStore({
630
+ * connectionString: process.env.DATABASE_URL
631
+ * }));
632
+ *
633
+ * // Now agents can use memory with the storage
634
+ * const agent = new Agent({
635
+ * name: 'assistant',
636
+ * memory: new Memory({ storage: mastra.getStorage() })
637
+ * });
638
+ * ```
639
+ */
109
640
  setStorage(storage: MastraStorage): void;
110
641
  setLogger({ logger }: {
111
642
  logger: TLogger;
112
643
  }): void;
113
644
  setTelemetry(telemetry: OtelConfig): void;
645
+ /**
646
+ * Gets all registered text-to-speech (TTS) providers.
647
+ *
648
+ * @example
649
+ * ```typescript
650
+ * const mastra = new Mastra({
651
+ * tts: {
652
+ * openai: new OpenAITTS({
653
+ * apiKey: process.env.OPENAI_API_KEY,
654
+ * voice: 'alloy'
655
+ * })
656
+ * }
657
+ * });
658
+ *
659
+ * const ttsProviders = mastra.getTTS();
660
+ * const openaiTTS = ttsProviders?.openai;
661
+ * if (openaiTTS) {
662
+ * const audioBuffer = await openaiTTS.synthesize('Hello, world!');
663
+ * }
664
+ * ```
665
+ */
114
666
  getTTS(): TTTS | undefined;
667
+ /**
668
+ * Gets the currently configured logger instance.
669
+ *
670
+ * @example
671
+ * ```typescript
672
+ * const mastra = new Mastra({
673
+ * logger: new PinoLogger({
674
+ * name: 'MyApp',
675
+ * level: 'info'
676
+ * })
677
+ * });
678
+ *
679
+ * const logger = mastra.getLogger();
680
+ * logger.info('Application started');
681
+ * logger.error('An error occurred', { error: 'details' });
682
+ * ```
683
+ */
115
684
  getLogger(): TLogger;
685
+ /**
686
+ * Gets the currently configured telemetry instance.
687
+ *
688
+ * @example
689
+ * ```typescript
690
+ * const mastra = new Mastra({
691
+ * telemetry: {
692
+ * enabled: true,
693
+ * serviceName: 'my-mastra-app'
694
+ * }
695
+ * });
696
+ *
697
+ * const telemetry = mastra.getTelemetry();
698
+ * if (telemetry) {
699
+ * const span = telemetry.startSpan('custom-operation');
700
+ * span.setAttributes({ operation: 'data-processing' });
701
+ * span.end();
702
+ * }
703
+ * ```
704
+ */
116
705
  getTelemetry(): Telemetry | undefined;
706
+ /**
707
+ * Gets the currently configured memory instance.
708
+ *
709
+ * @deprecated Memory should be configured directly on agents instead of on the Mastra instance.
710
+ * Use `new Agent({ memory: new Memory() })` instead.
711
+ *
712
+ * @example Legacy memory usage (deprecated)
713
+ * ```typescript
714
+ * // This approach is deprecated
715
+ * const mastra = new Mastra({
716
+ * // memory: new Memory() // This is no longer supported
717
+ * });
718
+ *
719
+ * // Use this instead:
720
+ * const agent = new Agent({
721
+ * name: 'assistant',
722
+ * memory: new Memory({
723
+ * storage: new LibSQLStore({ url: ':memory:' })
724
+ * })
725
+ * });
726
+ * ```
727
+ */
117
728
  getMemory(): MastraMemory | undefined;
729
+ /**
730
+ * Gets the currently configured storage provider.
731
+ *
732
+ * @example
733
+ * ```typescript
734
+ * const mastra = new Mastra({
735
+ * storage: new LibSQLStore({ url: 'file:./data.db' })
736
+ * });
737
+ *
738
+ * // Use the storage in agent memory
739
+ * const agent = new Agent({
740
+ * name: 'assistant',
741
+ * memory: new Memory({
742
+ * storage: mastra.getStorage()
743
+ * })
744
+ * });
745
+ * ```
746
+ */
118
747
  getStorage(): MastraStorage | undefined;
119
748
  getServerMiddleware(): {
120
749
  handler: (c: any, next: () => Promise<void>) => Promise<Response | void>;
@@ -155,18 +784,50 @@ export declare class Mastra<TAgents extends Record<string, Agent<any>> = Record<
155
784
  hasMore: boolean;
156
785
  }>;
157
786
  /**
158
- * Get all registered MCP server instances.
159
- * @returns A record of MCP server ID to MCPServerBase instance, or undefined if none are registered.
787
+ * Gets all registered Model Context Protocol (MCP) server instances.
788
+ *
789
+ * @example
790
+ * ```typescript
791
+ * const mastra = new Mastra({
792
+ * mcpServers: {
793
+ * filesystem: new FileSystemMCPServer({
794
+ * rootPath: '/app/data'
795
+ * })
796
+ * }
797
+ * });
798
+ *
799
+ * const mcpServers = mastra.getMCPServers();
800
+ * if (mcpServers) {
801
+ * const fsServer = mcpServers.filesystem;
802
+ * const tools = await fsServer.getTools();
803
+ * }
804
+ * ```
160
805
  */
161
806
  getMCPServers(): Record<string, MCPServerBase> | undefined;
162
807
  /**
163
- * Get a specific MCP server instance.
164
- * If a version is provided, it attempts to find the server with that exact logical ID and version.
165
- * If no version is provided, it returns the server with the specified logical ID that has the most recent releaseDate.
166
- * The logical ID should match the `id` property of the MCPServer instance (typically set via MCPServerConfig.id).
167
- * @param serverId - The logical ID of the MCP server to retrieve.
168
- * @param version - Optional specific version of the MCP server to retrieve.
169
- * @returns The MCP server instance, or undefined if not found or if the specific version is not found.
808
+ * Retrieves a specific Model Context Protocol (MCP) server instance by its logical ID.
809
+ *
810
+ * This method searches for an MCP server using its logical ID. If a version is specified,
811
+ * it returns the exact version match. If no version is provided, it returns the server
812
+ * with the most recent release date.
813
+ *
814
+ * @example
815
+ * ```typescript
816
+ * const mastra = new Mastra({
817
+ * mcpServers: {
818
+ * filesystem: new FileSystemMCPServer({
819
+ * id: 'fs-server',
820
+ * version: '1.0.0',
821
+ * rootPath: '/app/data'
822
+ * })
823
+ * }
824
+ * });
825
+ *
826
+ * const fsServer = mastra.getMCPServer('fs-server');
827
+ * if (fsServer) {
828
+ * const tools = await fsServer.getTools();
829
+ * }
830
+ * ```
170
831
  */
171
832
  getMCPServer(serverId: string, version?: string): MCPServerBase | undefined;
172
833
  addTopicListener(topic: string, listener: (event: any) => Promise<void>): Promise<void>;
@@ -174,7 +835,29 @@ export declare class Mastra<TAgents extends Record<string, Agent<any>> = Record<
174
835
  startEventEngine(): Promise<void>;
175
836
  stopEventEngine(): Promise<void>;
176
837
  /**
177
- * Shutdown Mastra and clean up all resources
838
+ * Gracefully shuts down the Mastra instance and cleans up all resources.
839
+ *
840
+ * This method performs a clean shutdown of all Mastra components, including:
841
+ * - AI tracing registry and all tracing instances
842
+ * - Event engine and pub/sub system
843
+ * - All registered components and their resources
844
+ *
845
+ * It's important to call this method when your application is shutting down
846
+ * to ensure proper cleanup and prevent resource leaks.
847
+ *
848
+ * @example
849
+ * ```typescript
850
+ * const mastra = new Mastra({
851
+ * agents: { myAgent },
852
+ * workflows: { myWorkflow }
853
+ * });
854
+ *
855
+ * // Graceful shutdown on SIGINT
856
+ * process.on('SIGINT', async () => {
857
+ * await mastra.shutdown();
858
+ * process.exit(0);
859
+ * });
860
+ * ```
178
861
  */
179
862
  shutdown(): Promise<void>;
180
863
  get serverCache(): MastraServerCache;