@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
@@ -1,11 +1,11 @@
1
- import { WorkflowEventProcessor } from './chunk-6R46VE63.js';
2
- import { saveScorePayloadSchema } from './chunk-WP2KQXPV.js';
1
+ import { WorkflowEventProcessor } from './chunk-OPHFW56S.js';
2
+ import { saveScorePayloadSchema } from './chunk-RMMGYPXG.js';
3
3
  import { augmentWithInit } from './chunk-436FFEF6.js';
4
4
  import { PubSub } from './chunk-BVUMKER5.js';
5
5
  import { InstrumentClass, Telemetry } from './chunk-2DVGQK2L.js';
6
6
  import { InMemoryServerCache } from './chunk-EQV2PPN2.js';
7
7
  import { registerHook } from './chunk-TTELJD4F.js';
8
- import { setupAITracing, getAllAITracing, shutdownAITracingRegistry } from './chunk-CJDOU6WP.js';
8
+ import { setupAITracing, getAllAITracing, shutdownAITracingRegistry } from './chunk-3KBXOXG6.js';
9
9
  import { noopLogger } from './chunk-PFXXH2RP.js';
10
10
  import { MastraError } from './chunk-T3JFFQH2.js';
11
11
  import { ConsoleLogger, LogLevel } from './chunk-BN2M4UK5.js';
@@ -176,12 +176,35 @@ var Mastra = class {
176
176
  get pubsub() {
177
177
  return this.#pubsub;
178
178
  }
179
+ /**
180
+ * Gets the currently configured ID generator function.
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * const mastra = new Mastra({
185
+ * idGenerator: () => `custom-${Date.now()}`
186
+ * });
187
+ * const generator = mastra.getIdGenerator();
188
+ * console.log(generator?.()); // "custom-1234567890"
189
+ * ```
190
+ */
179
191
  getIdGenerator() {
180
192
  return this.#idGenerator;
181
193
  }
182
194
  /**
183
- * Generate a unique identifier using the configured generator or default to crypto.randomUUID()
184
- * @returns A unique string ID
195
+ * Generates a unique identifier using the configured generator or defaults to `crypto.randomUUID()`.
196
+ *
197
+ * This method is used internally by Mastra for creating unique IDs for various entities
198
+ * like workflow runs, agent conversations, and other resources that need unique identification.
199
+ *
200
+ * @throws {MastraError} When the custom ID generator returns an empty string
201
+ *
202
+ * @example
203
+ * ```typescript
204
+ * const mastra = new Mastra();
205
+ * const id = mastra.generateId();
206
+ * console.log(id); // "550e8400-e29b-41d4-a716-446655440000"
207
+ * ```
185
208
  */
186
209
  generateId() {
187
210
  if (this.#idGenerator) {
@@ -200,9 +223,47 @@ var Mastra = class {
200
223
  }
201
224
  return randomUUID();
202
225
  }
226
+ /**
227
+ * Sets a custom ID generator function for creating unique identifiers.
228
+ *
229
+ * The ID generator function will be used by `generateId()` instead of the default
230
+ * `crypto.randomUUID()`. This is useful for creating application-specific ID formats
231
+ * or integrating with existing ID generation systems.
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * const mastra = new Mastra();
236
+ * mastra.setIdGenerator(() => `custom-${Date.now()}`);
237
+ * const id = mastra.generateId();
238
+ * console.log(id); // "custom-1234567890"
239
+ * ```
240
+ */
203
241
  setIdGenerator(idGenerator) {
204
242
  this.#idGenerator = idGenerator;
205
243
  }
244
+ /**
245
+ * Creates a new Mastra instance with the provided configuration.
246
+ *
247
+ * The constructor initializes all the components specified in the config, sets up
248
+ * internal systems like logging and telemetry, and registers components with each other.
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * const mastra = new Mastra({
253
+ * agents: {
254
+ * assistant: new Agent({
255
+ * name: 'assistant',
256
+ * instructions: 'You are a helpful assistant',
257
+ * model: 'openai/gpt-5'
258
+ * })
259
+ * },
260
+ * storage: new PostgresStore({
261
+ * connectionString: process.env.DATABASE_URL
262
+ * }),
263
+ * logger: new PinoLogger({ name: 'MyApp' })
264
+ * });
265
+ * ```
266
+ */
206
267
  constructor(config) {
207
268
  if (config?.serverMiddleware) {
208
269
  this.#serverMiddleware = config.serverMiddleware.map(m => ({
@@ -453,6 +514,27 @@ do:
453
514
  });
454
515
  });
455
516
  }
517
+ /**
518
+ * Retrieves a registered agent by its name.
519
+ *
520
+ * @template TAgentName - The specific agent name type from the registered agents
521
+ * @throws {MastraError} When the agent with the specified name is not found
522
+ *
523
+ * @example
524
+ * ```typescript
525
+ * const mastra = new Mastra({
526
+ * agents: {
527
+ * weatherAgent: new Agent({
528
+ * name: 'weather-agent',
529
+ * instructions: 'You provide weather information',
530
+ * model: 'openai/gpt-5'
531
+ * })
532
+ * }
533
+ * });
534
+ * const agent = mastra.getAgent('weatherAgent');
535
+ * const response = await agent.generate('What is the weather?');
536
+ * ```
537
+ */
456
538
  getAgent(name) {
457
539
  const agent = this.#agents?.[name];
458
540
  if (!agent) {
@@ -472,6 +554,31 @@ do:
472
554
  }
473
555
  return this.#agents[name];
474
556
  }
557
+ /**
558
+ * Retrieves a registered agent by its unique ID.
559
+ *
560
+ * This method searches for an agent using its internal ID property. If no agent
561
+ * is found with the given ID, it also attempts to find an agent using the ID as
562
+ * a name (for backward compatibility).
563
+ *
564
+ * @throws {MastraError} When no agent is found with the specified ID
565
+ *
566
+ * @example
567
+ * ```typescript
568
+ * const mastra = new Mastra({
569
+ * agents: {
570
+ * assistant: new Agent({
571
+ * name: 'assistant',
572
+ * instructions: 'You are a helpful assistant',
573
+ * model: 'openai/gpt-5'
574
+ * })
575
+ * }
576
+ * });
577
+ *
578
+ * const assistant = mastra.getAgent('assistant');
579
+ * const sameAgent = mastra.getAgentById(assistant.id);
580
+ * ```
581
+ */
475
582
  getAgentById(id) {
476
583
  let agent = Object.values(this.#agents).find(a => a.id === id);
477
584
  if (!agent) {
@@ -496,9 +603,66 @@ do:
496
603
  }
497
604
  return agent;
498
605
  }
606
+ /**
607
+ * Returns all registered agents as a record keyed by their names.
608
+ *
609
+ * This method provides access to the complete registry of agents, allowing you to
610
+ * iterate over them, check what agents are available, or perform bulk operations.
611
+ *
612
+ * @example
613
+ * ```typescript
614
+ * const mastra = new Mastra({
615
+ * agents: {
616
+ * weatherAgent: new Agent({ name: 'weather', model: openai('gpt-4o') }),
617
+ * supportAgent: new Agent({ name: 'support', model: openai('gpt-4o') })
618
+ * }
619
+ * });
620
+ *
621
+ * const allAgents = mastra.getAgents();
622
+ * console.log(Object.keys(allAgents)); // ['weatherAgent', 'supportAgent']
623
+ * ```
624
+ */
499
625
  getAgents() {
500
626
  return this.#agents;
501
627
  }
628
+ /**
629
+ * Retrieves a registered vector store by its name.
630
+ *
631
+ * @template TVectorName - The specific vector store name type from the registered vectors
632
+ * @throws {MastraError} When the vector store with the specified name is not found
633
+ *
634
+ * @example Using a vector store for semantic search
635
+ * ```typescript
636
+ * import { PineconeVector } from '@mastra/pinecone';
637
+ * import { OpenAIEmbedder } from '@mastra/embedders';
638
+ *
639
+ * const mastra = new Mastra({
640
+ * vectors: {
641
+ * knowledge: new PineconeVector({
642
+ * apiKey: process.env.PINECONE_API_KEY,
643
+ * indexName: 'knowledge-base',
644
+ * embedder: new OpenAIEmbedder({
645
+ * apiKey: process.env.OPENAI_API_KEY,
646
+ * model: 'text-embedding-3-small'
647
+ * })
648
+ * }),
649
+ * products: new PineconeVector({
650
+ * apiKey: process.env.PINECONE_API_KEY,
651
+ * indexName: 'product-catalog'
652
+ * })
653
+ * }
654
+ * });
655
+ *
656
+ * // Get a vector store and perform semantic search
657
+ * const knowledgeBase = mastra.getVector('knowledge');
658
+ * const results = await knowledgeBase.query({
659
+ * query: 'How to reset password?',
660
+ * topK: 5
661
+ * });
662
+ *
663
+ * console.log('Relevant documents:', results);
664
+ * ```
665
+ */
502
666
  getVector(name) {
503
667
  const vector = this.#vectors?.[name];
504
668
  if (!vector) {
@@ -518,12 +682,78 @@ do:
518
682
  }
519
683
  return vector;
520
684
  }
685
+ /**
686
+ * Returns all registered vector stores as a record keyed by their names.
687
+ *
688
+ * @example Listing all vector stores
689
+ * ```typescript
690
+ * const mastra = new Mastra({
691
+ * vectors: {
692
+ * documents: new PineconeVector({ indexName: 'docs' }),
693
+ * images: new PineconeVector({ indexName: 'images' }),
694
+ * products: new ChromaVector({ collectionName: 'products' })
695
+ * }
696
+ * });
697
+ *
698
+ * const allVectors = mastra.getVectors();
699
+ * console.log(Object.keys(allVectors)); // ['documents', 'images', 'products']
700
+ *
701
+ * // Check vector store types and configurations
702
+ * for (const [name, vectorStore] of Object.entries(allVectors)) {
703
+ * console.log(`Vector store ${name}:`, vectorStore.constructor.name);
704
+ * }
705
+ * ```
706
+ */
521
707
  getVectors() {
522
708
  return this.#vectors;
523
709
  }
710
+ /**
711
+ * Gets the currently configured deployment provider.
712
+ *
713
+ * @example
714
+ * ```typescript
715
+ * const mastra = new Mastra({
716
+ * deployer: new VercelDeployer({
717
+ * token: process.env.VERCEL_TOKEN,
718
+ * projectId: process.env.VERCEL_PROJECT_ID
719
+ * })
720
+ * });
721
+ *
722
+ * const deployer = mastra.getDeployer();
723
+ * if (deployer) {
724
+ * await deployer.deploy({
725
+ * name: 'my-mastra-app',
726
+ * environment: 'production'
727
+ * });
728
+ * }
729
+ * ```
730
+ */
524
731
  getDeployer() {
525
732
  return this.#deployer;
526
733
  }
734
+ /**
735
+ * Retrieves a registered legacy workflow by its ID.
736
+ *
737
+ * Legacy workflows are the previous generation of workflow system in Mastra,
738
+ * maintained for backward compatibility. For new implementations, use the
739
+ * modern workflow system accessed via `getWorkflow()`.
740
+ *
741
+ * @template TWorkflowId - The specific workflow ID type from the registered legacy workflows
742
+ * @throws {MastraError} When the legacy workflow with the specified ID is not found
743
+ * @deprecated Use `getWorkflow()` for new implementations
744
+ *
745
+ * @example Getting a legacy workflow
746
+ * ```typescript
747
+ * const mastra = new Mastra({
748
+ * legacy_workflows: {
749
+ * oldDataFlow: legacyWorkflowInstance
750
+ * }
751
+ * });
752
+ *
753
+ * const workflow = mastra.legacy_getWorkflow('oldDataFlow');
754
+ * const result = await workflow.execute({ input: 'data' });
755
+ * ```
756
+ */
527
757
  legacy_getWorkflow(id, {
528
758
  serialized
529
759
  } = {}) {
@@ -550,6 +780,33 @@ do:
550
780
  }
551
781
  return workflow;
552
782
  }
783
+ /**
784
+ * Retrieves a registered workflow by its ID.
785
+ *
786
+ * @template TWorkflowId - The specific workflow ID type from the registered workflows
787
+ * @throws {MastraError} When the workflow with the specified ID is not found
788
+ *
789
+ * @example Getting and executing a workflow
790
+ * ```typescript
791
+ * import { createWorkflow, createStep } from '@mastra/core/workflows';
792
+ * import { z } from 'zod';
793
+ *
794
+ * const processDataWorkflow = createWorkflow({
795
+ * name: 'process-data',
796
+ * triggerSchema: z.object({ input: z.string() })
797
+ * })
798
+ * .then(validateStep)
799
+ * .then(transformStep)
800
+ * .then(saveStep)
801
+ * .commit();
802
+ *
803
+ * const mastra = new Mastra({
804
+ * workflows: {
805
+ * dataProcessor: processDataWorkflow
806
+ * }
807
+ * });
808
+ * ```
809
+ */
553
810
  getWorkflow(id, {
554
811
  serialized
555
812
  } = {}) {
@@ -603,6 +860,35 @@ do:
603
860
  }
604
861
  return workflow;
605
862
  }
863
+ /**
864
+ * Retrieves a registered workflow by its unique ID.
865
+ *
866
+ * This method searches for a workflow using its internal ID property. If no workflow
867
+ * is found with the given ID, it also attempts to find a workflow using the ID as
868
+ * a name (for backward compatibility).
869
+ *
870
+ * @throws {MastraError} When no workflow is found with the specified ID
871
+ *
872
+ * @example Finding a workflow by ID
873
+ * ```typescript
874
+ * const mastra = new Mastra({
875
+ * workflows: {
876
+ * dataProcessor: createWorkflow({
877
+ * name: 'process-data',
878
+ * triggerSchema: z.object({ input: z.string() })
879
+ * }).commit()
880
+ * }
881
+ * });
882
+ *
883
+ * // Get the workflow's ID
884
+ * const workflow = mastra.getWorkflow('dataProcessor');
885
+ * const workflowId = workflow.id;
886
+ *
887
+ * // Later, retrieve the workflow by ID
888
+ * const sameWorkflow = mastra.getWorkflowById(workflowId);
889
+ * console.log(sameWorkflow.name); // "process-data"
890
+ * ```
891
+ */
606
892
  getWorkflowById(id) {
607
893
  let workflow = Object.values(this.#workflows).find(a => a.id === id);
608
894
  if (!workflow) {
@@ -627,6 +913,32 @@ do:
627
913
  }
628
914
  return workflow;
629
915
  }
916
+ /**
917
+ * Returns all registered legacy workflows as a record keyed by their IDs.
918
+ *
919
+ * Legacy workflows are the previous generation of workflow system in Mastra,
920
+ * maintained for backward compatibility. For new implementations, use `getWorkflows()`.
921
+ *
922
+ * @deprecated Use `getWorkflows()` for new implementations
923
+ *
924
+ * @example Listing all legacy workflows
925
+ * ```typescript
926
+ * const mastra = new Mastra({
927
+ * legacy_workflows: {
928
+ * oldFlow1: legacyWorkflow1,
929
+ * oldFlow2: legacyWorkflow2
930
+ * }
931
+ * });
932
+ *
933
+ * const allLegacyWorkflows = mastra.legacy_getWorkflows();
934
+ * console.log(Object.keys(allLegacyWorkflows)); // ['oldFlow1', 'oldFlow2']
935
+ *
936
+ * // Execute all legacy workflows
937
+ * for (const [id, workflow] of Object.entries(allLegacyWorkflows)) {
938
+ * console.log(`Legacy workflow ${id}:`, workflow.name);
939
+ * }
940
+ * ```
941
+ */
630
942
  legacy_getWorkflows(props = {}) {
631
943
  if (props.serialized) {
632
944
  return Object.entries(this.#legacy_workflows).reduce((acc, [k, v]) => {
@@ -640,9 +952,66 @@ do:
640
952
  }
641
953
  return this.#legacy_workflows;
642
954
  }
955
+ /**
956
+ * Returns all registered scorers as a record keyed by their IDs.
957
+ *
958
+ * @example Listing all scorers
959
+ * ```typescript
960
+ * import { HelpfulnessScorer, AccuracyScorer, RelevanceScorer } from '@mastra/scorers';
961
+ *
962
+ * const mastra = new Mastra({
963
+ * scorers: {
964
+ * helpfulness: new HelpfulnessScorer(),
965
+ * accuracy: new AccuracyScorer(),
966
+ * relevance: new RelevanceScorer()
967
+ * }
968
+ * });
969
+ *
970
+ * const allScorers = mastra.getScorers();
971
+ * console.log(Object.keys(allScorers)); // ['helpfulness', 'accuracy', 'relevance']
972
+ *
973
+ * // Check scorer configurations
974
+ * for (const [id, scorer] of Object.entries(allScorers)) {
975
+ * console.log(`Scorer ${id}:`, scorer.name, scorer.description);
976
+ * }
977
+ * ```
978
+ */
643
979
  getScorers() {
644
980
  return this.#scorers;
645
981
  }
982
+ /**
983
+ * Retrieves a registered scorer by its key.
984
+ *
985
+ * @template TScorerKey - The specific scorer key type from the registered scorers
986
+ * @throws {MastraError} When the scorer with the specified key is not found
987
+ *
988
+ * @example Getting and using a scorer
989
+ * ```typescript
990
+ * import { HelpfulnessScorer, AccuracyScorer } from '@mastra/scorers';
991
+ *
992
+ * const mastra = new Mastra({
993
+ * scorers: {
994
+ * helpfulness: new HelpfulnessScorer({
995
+ * model: openai('gpt-4o'),
996
+ * criteria: 'Rate how helpful this response is'
997
+ * }),
998
+ * accuracy: new AccuracyScorer({
999
+ * model: 'openai/gpt-5'
1000
+ * })
1001
+ * }
1002
+ * });
1003
+ *
1004
+ * // Get a specific scorer
1005
+ * const helpfulnessScorer = mastra.getScorer('helpfulness');
1006
+ * const score = await helpfulnessScorer.score({
1007
+ * input: 'How do I reset my password?',
1008
+ * output: 'You can reset your password by clicking the forgot password link.',
1009
+ * expected: 'Detailed password reset instructions'
1010
+ * });
1011
+ *
1012
+ * console.log('Helpfulness score:', score);
1013
+ * ```
1014
+ */
646
1015
  getScorer(key) {
647
1016
  const scorer = this.#scorers?.[key];
648
1017
  if (!scorer) {
@@ -657,6 +1026,36 @@ do:
657
1026
  }
658
1027
  return scorer;
659
1028
  }
1029
+ /**
1030
+ * Retrieves a registered scorer by its name.
1031
+ *
1032
+ * This method searches through all registered scorers to find one with the specified name.
1033
+ * Unlike `getScorer()` which uses the registration key, this method uses the scorer's
1034
+ * internal name property.
1035
+ *
1036
+ * @throws {MastraError} When no scorer is found with the specified name
1037
+ *
1038
+ * @example Finding a scorer by name
1039
+ * ```typescript
1040
+ * import { HelpfulnessScorer } from '@mastra/scorers';
1041
+ *
1042
+ * const mastra = new Mastra({
1043
+ * scorers: {
1044
+ * myHelpfulnessScorer: new HelpfulnessScorer({
1045
+ * name: 'helpfulness-evaluator',
1046
+ * model: 'openai/gpt-5'
1047
+ * })
1048
+ * }
1049
+ * });
1050
+ *
1051
+ * // Find scorer by its internal name, not the registration key
1052
+ * const scorer = mastra.getScorerByName('helpfulness-evaluator');
1053
+ * const score = await scorer.score({
1054
+ * input: 'question',
1055
+ * output: 'answer'
1056
+ * });
1057
+ * ```
1058
+ */
660
1059
  getScorerByName(name) {
661
1060
  for (const [_key, value] of Object.entries(this.#scorers ?? {})) {
662
1061
  if (value.name === name) {
@@ -672,6 +1071,29 @@ do:
672
1071
  this.#logger?.trackException(error);
673
1072
  throw error;
674
1073
  }
1074
+ /**
1075
+ * Returns all registered workflows as a record keyed by their IDs.
1076
+ *
1077
+ * @example Listing all workflows
1078
+ * ```typescript
1079
+ * const mastra = new Mastra({
1080
+ * workflows: {
1081
+ * dataProcessor: createWorkflow({...}).commit(),
1082
+ * emailSender: createWorkflow({...}).commit(),
1083
+ * reportGenerator: createWorkflow({...}).commit()
1084
+ * }
1085
+ * });
1086
+ *
1087
+ * const allWorkflows = mastra.getWorkflows();
1088
+ * console.log(Object.keys(allWorkflows)); // ['dataProcessor', 'emailSender', 'reportGenerator']
1089
+ *
1090
+ * // Execute all workflows with sample data
1091
+ * for (const [id, workflow] of Object.entries(allWorkflows)) {
1092
+ * console.log(`Workflow ${id}:`, workflow.name);
1093
+ * // const result = await workflow.execute(sampleData);
1094
+ * }
1095
+ * ```
1096
+ */
675
1097
  getWorkflows(props = {}) {
676
1098
  if (props.serialized) {
677
1099
  return Object.entries(this.#workflows).reduce((acc, [k, v]) => {
@@ -685,6 +1107,25 @@ do:
685
1107
  }
686
1108
  return this.#workflows;
687
1109
  }
1110
+ /**
1111
+ * Sets the storage provider for the Mastra instance.
1112
+ *
1113
+ * @example
1114
+ * ```typescript
1115
+ * const mastra = new Mastra();
1116
+ *
1117
+ * // Set PostgreSQL storage
1118
+ * mastra.setStorage(new PostgresStore({
1119
+ * connectionString: process.env.DATABASE_URL
1120
+ * }));
1121
+ *
1122
+ * // Now agents can use memory with the storage
1123
+ * const agent = new Agent({
1124
+ * name: 'assistant',
1125
+ * memory: new Memory({ storage: mastra.getStorage() })
1126
+ * });
1127
+ * ```
1128
+ */
688
1129
  setStorage(storage) {
689
1130
  this.#storage = augmentWithInit(storage);
690
1131
  }
@@ -778,18 +1219,116 @@ do:
778
1219
  this.#vectors = vectors;
779
1220
  }
780
1221
  }
1222
+ /**
1223
+ * Gets all registered text-to-speech (TTS) providers.
1224
+ *
1225
+ * @example
1226
+ * ```typescript
1227
+ * const mastra = new Mastra({
1228
+ * tts: {
1229
+ * openai: new OpenAITTS({
1230
+ * apiKey: process.env.OPENAI_API_KEY,
1231
+ * voice: 'alloy'
1232
+ * })
1233
+ * }
1234
+ * });
1235
+ *
1236
+ * const ttsProviders = mastra.getTTS();
1237
+ * const openaiTTS = ttsProviders?.openai;
1238
+ * if (openaiTTS) {
1239
+ * const audioBuffer = await openaiTTS.synthesize('Hello, world!');
1240
+ * }
1241
+ * ```
1242
+ */
781
1243
  getTTS() {
782
1244
  return this.#tts;
783
1245
  }
1246
+ /**
1247
+ * Gets the currently configured logger instance.
1248
+ *
1249
+ * @example
1250
+ * ```typescript
1251
+ * const mastra = new Mastra({
1252
+ * logger: new PinoLogger({
1253
+ * name: 'MyApp',
1254
+ * level: 'info'
1255
+ * })
1256
+ * });
1257
+ *
1258
+ * const logger = mastra.getLogger();
1259
+ * logger.info('Application started');
1260
+ * logger.error('An error occurred', { error: 'details' });
1261
+ * ```
1262
+ */
784
1263
  getLogger() {
785
1264
  return this.#logger;
786
1265
  }
1266
+ /**
1267
+ * Gets the currently configured telemetry instance.
1268
+ *
1269
+ * @example
1270
+ * ```typescript
1271
+ * const mastra = new Mastra({
1272
+ * telemetry: {
1273
+ * enabled: true,
1274
+ * serviceName: 'my-mastra-app'
1275
+ * }
1276
+ * });
1277
+ *
1278
+ * const telemetry = mastra.getTelemetry();
1279
+ * if (telemetry) {
1280
+ * const span = telemetry.startSpan('custom-operation');
1281
+ * span.setAttributes({ operation: 'data-processing' });
1282
+ * span.end();
1283
+ * }
1284
+ * ```
1285
+ */
787
1286
  getTelemetry() {
788
1287
  return this.#telemetry;
789
1288
  }
1289
+ /**
1290
+ * Gets the currently configured memory instance.
1291
+ *
1292
+ * @deprecated Memory should be configured directly on agents instead of on the Mastra instance.
1293
+ * Use `new Agent({ memory: new Memory() })` instead.
1294
+ *
1295
+ * @example Legacy memory usage (deprecated)
1296
+ * ```typescript
1297
+ * // This approach is deprecated
1298
+ * const mastra = new Mastra({
1299
+ * // memory: new Memory() // This is no longer supported
1300
+ * });
1301
+ *
1302
+ * // Use this instead:
1303
+ * const agent = new Agent({
1304
+ * name: 'assistant',
1305
+ * memory: new Memory({
1306
+ * storage: new LibSQLStore({ url: ':memory:' })
1307
+ * })
1308
+ * });
1309
+ * ```
1310
+ */
790
1311
  getMemory() {
791
1312
  return this.#memory;
792
1313
  }
1314
+ /**
1315
+ * Gets the currently configured storage provider.
1316
+ *
1317
+ * @example
1318
+ * ```typescript
1319
+ * const mastra = new Mastra({
1320
+ * storage: new LibSQLStore({ url: 'file:./data.db' })
1321
+ * });
1322
+ *
1323
+ * // Use the storage in agent memory
1324
+ * const agent = new Agent({
1325
+ * name: 'assistant',
1326
+ * memory: new Memory({
1327
+ * storage: mastra.getStorage()
1328
+ * })
1329
+ * });
1330
+ * ```
1331
+ */
793
1332
  getStorage() {
794
1333
  return this.#storage;
795
1334
  }
@@ -914,20 +1453,52 @@ do:
914
1453
  return await this.#logger.getLogs(transportId, params);
915
1454
  }
916
1455
  /**
917
- * Get all registered MCP server instances.
918
- * @returns A record of MCP server ID to MCPServerBase instance, or undefined if none are registered.
1456
+ * Gets all registered Model Context Protocol (MCP) server instances.
1457
+ *
1458
+ * @example
1459
+ * ```typescript
1460
+ * const mastra = new Mastra({
1461
+ * mcpServers: {
1462
+ * filesystem: new FileSystemMCPServer({
1463
+ * rootPath: '/app/data'
1464
+ * })
1465
+ * }
1466
+ * });
1467
+ *
1468
+ * const mcpServers = mastra.getMCPServers();
1469
+ * if (mcpServers) {
1470
+ * const fsServer = mcpServers.filesystem;
1471
+ * const tools = await fsServer.getTools();
1472
+ * }
1473
+ * ```
919
1474
  */
920
1475
  getMCPServers() {
921
1476
  return this.#mcpServers;
922
1477
  }
923
1478
  /**
924
- * Get a specific MCP server instance.
925
- * If a version is provided, it attempts to find the server with that exact logical ID and version.
926
- * If no version is provided, it returns the server with the specified logical ID that has the most recent releaseDate.
927
- * The logical ID should match the `id` property of the MCPServer instance (typically set via MCPServerConfig.id).
928
- * @param serverId - The logical ID of the MCP server to retrieve.
929
- * @param version - Optional specific version of the MCP server to retrieve.
930
- * @returns The MCP server instance, or undefined if not found or if the specific version is not found.
1479
+ * Retrieves a specific Model Context Protocol (MCP) server instance by its logical ID.
1480
+ *
1481
+ * This method searches for an MCP server using its logical ID. If a version is specified,
1482
+ * it returns the exact version match. If no version is provided, it returns the server
1483
+ * with the most recent release date.
1484
+ *
1485
+ * @example
1486
+ * ```typescript
1487
+ * const mastra = new Mastra({
1488
+ * mcpServers: {
1489
+ * filesystem: new FileSystemMCPServer({
1490
+ * id: 'fs-server',
1491
+ * version: '1.0.0',
1492
+ * rootPath: '/app/data'
1493
+ * })
1494
+ * }
1495
+ * });
1496
+ *
1497
+ * const fsServer = mastra.getMCPServer('fs-server');
1498
+ * if (fsServer) {
1499
+ * const tools = await fsServer.getTools();
1500
+ * }
1501
+ * ```
931
1502
  */
932
1503
  getMCPServer(serverId, version) {
933
1504
  if (!this.#mcpServers) {
@@ -997,7 +1568,29 @@ do:
997
1568
  await this.#pubsub.flush();
998
1569
  }
999
1570
  /**
1000
- * Shutdown Mastra and clean up all resources
1571
+ * Gracefully shuts down the Mastra instance and cleans up all resources.
1572
+ *
1573
+ * This method performs a clean shutdown of all Mastra components, including:
1574
+ * - AI tracing registry and all tracing instances
1575
+ * - Event engine and pub/sub system
1576
+ * - All registered components and their resources
1577
+ *
1578
+ * It's important to call this method when your application is shutting down
1579
+ * to ensure proper cleanup and prevent resource leaks.
1580
+ *
1581
+ * @example
1582
+ * ```typescript
1583
+ * const mastra = new Mastra({
1584
+ * agents: { myAgent },
1585
+ * workflows: { myWorkflow }
1586
+ * });
1587
+ *
1588
+ * // Graceful shutdown on SIGINT
1589
+ * process.on('SIGINT', async () => {
1590
+ * await mastra.shutdown();
1591
+ * process.exit(0);
1592
+ * });
1593
+ * ```
1001
1594
  */
1002
1595
  async shutdown() {
1003
1596
  await shutdownAITracingRegistry();
@@ -1017,5 +1610,5 @@ Mastra = /*@__PURE__*/(_ => {
1017
1610
  })();
1018
1611
 
1019
1612
  export { Mastra };
1020
- //# sourceMappingURL=chunk-COYTVUIL.js.map
1021
- //# sourceMappingURL=chunk-COYTVUIL.js.map
1613
+ //# sourceMappingURL=chunk-EKFF7JLS.js.map
1614
+ //# sourceMappingURL=chunk-EKFF7JLS.js.map