@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.
- package/CHANGELOG.md +46 -0
- package/dist/agent/agent.d.ts +375 -9
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/index.cjs +11 -11
- package/dist/agent/index.js +2 -2
- package/dist/agent/input-processor/index.cjs +6 -6
- package/dist/agent/input-processor/index.js +1 -1
- package/dist/agent/types.d.ts +66 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +19 -3
- package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +5 -1
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts +5 -1
- package/dist/agent/workflows/prepare-stream/prepare-tools-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts +5 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
- package/dist/ai-tracing/index.cjs +32 -32
- package/dist/ai-tracing/index.js +1 -1
- package/dist/{chunk-3NNB72OL.cjs → chunk-33DTPWTJ.cjs} +7 -7
- package/dist/{chunk-3NNB72OL.cjs.map → chunk-33DTPWTJ.cjs.map} +1 -1
- package/dist/{chunk-CJDOU6WP.js → chunk-3KBXOXG6.js} +3 -3
- package/dist/{chunk-CJDOU6WP.js.map → chunk-3KBXOXG6.js.map} +1 -1
- package/dist/{chunk-ZNK5RN5D.cjs → chunk-3Z3DP6S2.cjs} +6 -6
- package/dist/{chunk-ZNK5RN5D.cjs.map → chunk-3Z3DP6S2.cjs.map} +1 -1
- package/dist/{chunk-KGBDRSMX.js → chunk-5I6DXBUR.js} +4 -4
- package/dist/{chunk-KGBDRSMX.js.map → chunk-5I6DXBUR.js.map} +1 -1
- package/dist/{chunk-7EUC32F3.cjs → chunk-6K7IMZVR.cjs} +617 -24
- package/dist/chunk-6K7IMZVR.cjs.map +1 -0
- package/dist/{chunk-FV4QVXO4.js → chunk-6OLRLZJ3.js} +37 -2
- package/dist/chunk-6OLRLZJ3.js.map +1 -0
- package/dist/{chunk-OXLN4CWA.js → chunk-B5GBHE4E.js} +3 -3
- package/dist/{chunk-OXLN4CWA.js.map → chunk-B5GBHE4E.js.map} +1 -1
- package/dist/{chunk-2SH5WPUA.cjs → chunk-BG5FC6ZZ.cjs} +407 -803
- package/dist/chunk-BG5FC6ZZ.cjs.map +1 -0
- package/dist/{chunk-COYTVUIL.js → chunk-EKFF7JLS.js} +610 -17
- package/dist/chunk-EKFF7JLS.js.map +1 -0
- package/dist/{chunk-BOJNXNRV.js → chunk-FJIABZVI.js} +3 -3
- package/dist/{chunk-BOJNXNRV.js.map → chunk-FJIABZVI.js.map} +1 -1
- package/dist/{chunk-RYFQKXXS.js → chunk-H4KO46HZ.js} +3 -3
- package/dist/{chunk-RYFQKXXS.js.map → chunk-H4KO46HZ.js.map} +1 -1
- package/dist/{chunk-T4H33PBR.cjs → chunk-IKLSJCMT.cjs} +360 -69
- package/dist/chunk-IKLSJCMT.cjs.map +1 -0
- package/dist/{chunk-K4AYIXVH.cjs → chunk-L5A4MRCK.cjs} +4 -4
- package/dist/{chunk-K4AYIXVH.cjs.map → chunk-L5A4MRCK.cjs.map} +1 -1
- package/dist/{chunk-DVHBWEYY.cjs → chunk-LCJHFYJS.cjs} +7 -7
- package/dist/{chunk-DVHBWEYY.cjs.map → chunk-LCJHFYJS.cjs.map} +1 -1
- package/dist/{chunk-I6TOPBP6.cjs → chunk-MHHMY2K4.cjs} +49 -18
- package/dist/chunk-MHHMY2K4.cjs.map +1 -0
- package/dist/{chunk-DQISKQDE.js → chunk-OBAFLVGD.js} +342 -51
- package/dist/chunk-OBAFLVGD.js.map +1 -0
- package/dist/{chunk-6R46VE63.js → chunk-OPHFW56S.js} +39 -8
- package/dist/chunk-OPHFW56S.js.map +1 -0
- package/dist/{chunk-LCJP7LWN.cjs → chunk-P4ZPZKZY.cjs} +6 -6
- package/dist/{chunk-LCJP7LWN.cjs.map → chunk-P4ZPZKZY.cjs.map} +1 -1
- package/dist/{chunk-QR5VZWWT.js → chunk-P7WEYMRS.js} +3 -3
- package/dist/{chunk-QR5VZWWT.js.map → chunk-P7WEYMRS.js.map} +1 -1
- package/dist/{chunk-YEEAHLAK.cjs → chunk-PWPESTZZ.cjs} +4 -4
- package/dist/{chunk-YEEAHLAK.cjs.map → chunk-PWPESTZZ.cjs.map} +1 -1
- package/dist/{chunk-7HUKQ6SZ.cjs → chunk-Q3S3BXHO.cjs} +4 -4
- package/dist/{chunk-7HUKQ6SZ.cjs.map → chunk-Q3S3BXHO.cjs.map} +1 -1
- package/dist/{chunk-WP2KQXPV.js → chunk-RMMGYPXG.js} +3 -3
- package/dist/{chunk-WP2KQXPV.js.map → chunk-RMMGYPXG.js.map} +1 -1
- package/dist/{chunk-A4RAEU6X.cjs → chunk-SE4PA467.cjs} +37 -2
- package/dist/chunk-SE4PA467.cjs.map +1 -0
- package/dist/{chunk-AND6J5LG.js → chunk-W2WXYTYI.js} +407 -803
- package/dist/chunk-W2WXYTYI.js.map +1 -0
- package/dist/{chunk-OKIHIKXV.cjs → chunk-WE6ILDQY.cjs} +4 -4
- package/dist/{chunk-OKIHIKXV.cjs.map → chunk-WE6ILDQY.cjs.map} +1 -1
- package/dist/{chunk-ZJ2UFCTS.js → chunk-Y2TIJVKC.js} +3 -3
- package/dist/{chunk-ZJ2UFCTS.js.map → chunk-Y2TIJVKC.js.map} +1 -1
- package/dist/index.cjs +52 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/integration/index.cjs +3 -3
- package/dist/integration/index.js +1 -1
- package/dist/llm/index.cjs +6 -6
- package/dist/llm/index.d.ts +1 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +1 -1
- package/dist/llm/model/gateway-resolver.d.ts +7 -5
- package/dist/llm/model/gateway-resolver.d.ts.map +1 -1
- package/dist/llm/model/gateways/base.d.ts +8 -6
- package/dist/llm/model/gateways/base.d.ts.map +1 -1
- package/dist/llm/model/gateways/constants.d.ts +3 -0
- package/dist/llm/model/gateways/constants.d.ts.map +1 -0
- package/dist/llm/model/gateways/index.d.ts +5 -0
- package/dist/llm/model/gateways/index.d.ts.map +1 -1
- package/dist/llm/model/gateways/models-dev.d.ts +8 -2
- package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
- package/dist/llm/model/gateways/netlify.d.ts +11 -2
- package/dist/llm/model/gateways/netlify.d.ts.map +1 -1
- package/dist/llm/model/index.d.ts +1 -1
- package/dist/llm/model/index.d.ts.map +1 -1
- package/dist/llm/model/model.loop.d.ts +1 -1
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/provider-registry.generated.d.ts +6 -7
- package/dist/llm/model/provider-registry.generated.d.ts.map +1 -1
- package/dist/llm/model/router.d.ts +23 -0
- package/dist/llm/model/router.d.ts.map +1 -0
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/network/index.d.ts +5 -1
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +5 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +5 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +5 -1
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts +5 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +5 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +695 -12
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +4 -4
- package/dist/memory/index.js +1 -1
- package/dist/processors/index.cjs +11 -11
- package/dist/processors/index.js +1 -1
- package/dist/relevance/index.cjs +4 -4
- package/dist/relevance/index.js +1 -1
- package/dist/scores/index.cjs +9 -9
- package/dist/scores/index.js +2 -2
- package/dist/scores/run-experiment/index.d.ts +2 -2
- package/dist/scores/run-experiment/index.d.ts.map +1 -1
- package/dist/scores/scoreTraces/index.cjs +8 -8
- package/dist/scores/scoreTraces/index.js +3 -3
- package/dist/scores/scoreTraces/scoreTracesWorkflow.d.ts +10 -2
- package/dist/scores/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -1
- package/dist/storage/domains/operations/base.d.ts +6 -0
- package/dist/storage/domains/operations/base.d.ts.map +1 -1
- package/dist/storage/index.cjs +11 -3
- package/dist/storage/index.cjs.map +1 -1
- package/dist/storage/index.js +9 -1
- package/dist/storage/index.js.map +1 -1
- package/dist/stream/MastraAgentNetworkStream.d.ts +5 -1
- package/dist/stream/MastraAgentNetworkStream.d.ts.map +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts +3 -3
- package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
- package/dist/stream/index.cjs +4 -4
- package/dist/stream/index.js +1 -1
- package/dist/test-utils/llm-mock.cjs +2 -2
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/tools/index.cjs +4 -4
- package/dist/tools/index.js +1 -1
- package/dist/tools/is-vercel-tool.cjs +2 -2
- package/dist/tools/is-vercel-tool.js +1 -1
- package/dist/tools/tool.d.ts +163 -0
- package/dist/tools/tool.d.ts.map +1 -1
- package/dist/utils.cjs +17 -17
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/workflows/default.d.ts +13 -7
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/evented/step-executor.d.ts +7 -3
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/loop.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/parallel.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/utils.d.ts +1 -1
- package/dist/workflows/evented/workflow.d.ts +23 -19
- package/dist/workflows/evented/workflow.d.ts.map +1 -1
- package/dist/workflows/execution-engine.d.ts +5 -1
- package/dist/workflows/execution-engine.d.ts.map +1 -1
- package/dist/workflows/index.cjs +12 -12
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/legacy/index.cjs +22 -22
- package/dist/workflows/legacy/index.js +1 -1
- package/dist/workflows/step.d.ts +11 -4
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workflows/types.d.ts +33 -9
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +85 -56
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/dist/workflows/workflow.warning.d.ts +2 -2
- package/dist/workflows/workflow.warning.d.ts.map +1 -1
- package/package.json +9 -4
- package/dist/chunk-2SH5WPUA.cjs.map +0 -1
- package/dist/chunk-45CV4JYJ.cjs +0 -4
- package/dist/chunk-45CV4JYJ.cjs.map +0 -1
- package/dist/chunk-6R46VE63.js.map +0 -1
- package/dist/chunk-7EUC32F3.cjs.map +0 -1
- package/dist/chunk-A4RAEU6X.cjs.map +0 -1
- package/dist/chunk-AND6J5LG.js.map +0 -1
- package/dist/chunk-COYTVUIL.js.map +0 -1
- package/dist/chunk-DQISKQDE.js.map +0 -1
- package/dist/chunk-FV4QVXO4.js.map +0 -1
- package/dist/chunk-I6TOPBP6.cjs.map +0 -1
- package/dist/chunk-RFGQ3EQV.js +0 -3
- package/dist/chunk-RFGQ3EQV.js.map +0 -1
- package/dist/chunk-T4H33PBR.cjs.map +0 -1
- package/dist/llm/model/openai-compatible.d.ts +0 -37
- package/dist/llm/model/openai-compatible.d.ts.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkMHHMY2K4_cjs = require('./chunk-MHHMY2K4.cjs');
|
|
4
|
+
var chunkPWPESTZZ_cjs = require('./chunk-PWPESTZZ.cjs');
|
|
5
5
|
var chunkV3VLOOSW_cjs = require('./chunk-V3VLOOSW.cjs');
|
|
6
6
|
var chunk4D4KB75Y_cjs = require('./chunk-4D4KB75Y.cjs');
|
|
7
7
|
var chunk2JUDZXVI_cjs = require('./chunk-2JUDZXVI.cjs');
|
|
8
8
|
var chunkUU5L5GDY_cjs = require('./chunk-UU5L5GDY.cjs');
|
|
9
9
|
var chunkTSNDVBUU_cjs = require('./chunk-TSNDVBUU.cjs');
|
|
10
|
-
var
|
|
10
|
+
var chunkLCJHFYJS_cjs = require('./chunk-LCJHFYJS.cjs');
|
|
11
11
|
var chunk6TEQIYXV_cjs = require('./chunk-6TEQIYXV.cjs');
|
|
12
12
|
var chunkWM4VQWOZ_cjs = require('./chunk-WM4VQWOZ.cjs');
|
|
13
13
|
var chunkWVCEJBDR_cjs = require('./chunk-WVCEJBDR.cjs');
|
|
@@ -102,7 +102,7 @@ function createOnScorerHook(mastra) {
|
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
async function validateAndSaveScore(storage, payload) {
|
|
105
|
-
const payloadToSave =
|
|
105
|
+
const payloadToSave = chunkPWPESTZZ_cjs.saveScorePayloadSchema.parse(payload);
|
|
106
106
|
await storage?.saveScore(payloadToSave);
|
|
107
107
|
}
|
|
108
108
|
async function findScorer(mastra, entityId, entityType, scorerName) {
|
|
@@ -182,12 +182,35 @@ exports.Mastra = class Mastra {
|
|
|
182
182
|
get pubsub() {
|
|
183
183
|
return this.#pubsub;
|
|
184
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Gets the currently configured ID generator function.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* const mastra = new Mastra({
|
|
191
|
+
* idGenerator: () => `custom-${Date.now()}`
|
|
192
|
+
* });
|
|
193
|
+
* const generator = mastra.getIdGenerator();
|
|
194
|
+
* console.log(generator?.()); // "custom-1234567890"
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
185
197
|
getIdGenerator() {
|
|
186
198
|
return this.#idGenerator;
|
|
187
199
|
}
|
|
188
200
|
/**
|
|
189
|
-
*
|
|
190
|
-
*
|
|
201
|
+
* Generates a unique identifier using the configured generator or defaults to `crypto.randomUUID()`.
|
|
202
|
+
*
|
|
203
|
+
* This method is used internally by Mastra for creating unique IDs for various entities
|
|
204
|
+
* like workflow runs, agent conversations, and other resources that need unique identification.
|
|
205
|
+
*
|
|
206
|
+
* @throws {MastraError} When the custom ID generator returns an empty string
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* const mastra = new Mastra();
|
|
211
|
+
* const id = mastra.generateId();
|
|
212
|
+
* console.log(id); // "550e8400-e29b-41d4-a716-446655440000"
|
|
213
|
+
* ```
|
|
191
214
|
*/
|
|
192
215
|
generateId() {
|
|
193
216
|
if (this.#idGenerator) {
|
|
@@ -206,9 +229,47 @@ exports.Mastra = class Mastra {
|
|
|
206
229
|
}
|
|
207
230
|
return crypto$1.randomUUID();
|
|
208
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Sets a custom ID generator function for creating unique identifiers.
|
|
234
|
+
*
|
|
235
|
+
* The ID generator function will be used by `generateId()` instead of the default
|
|
236
|
+
* `crypto.randomUUID()`. This is useful for creating application-specific ID formats
|
|
237
|
+
* or integrating with existing ID generation systems.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const mastra = new Mastra();
|
|
242
|
+
* mastra.setIdGenerator(() => `custom-${Date.now()}`);
|
|
243
|
+
* const id = mastra.generateId();
|
|
244
|
+
* console.log(id); // "custom-1234567890"
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
209
247
|
setIdGenerator(idGenerator) {
|
|
210
248
|
this.#idGenerator = idGenerator;
|
|
211
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* Creates a new Mastra instance with the provided configuration.
|
|
252
|
+
*
|
|
253
|
+
* The constructor initializes all the components specified in the config, sets up
|
|
254
|
+
* internal systems like logging and telemetry, and registers components with each other.
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* const mastra = new Mastra({
|
|
259
|
+
* agents: {
|
|
260
|
+
* assistant: new Agent({
|
|
261
|
+
* name: 'assistant',
|
|
262
|
+
* instructions: 'You are a helpful assistant',
|
|
263
|
+
* model: 'openai/gpt-5'
|
|
264
|
+
* })
|
|
265
|
+
* },
|
|
266
|
+
* storage: new PostgresStore({
|
|
267
|
+
* connectionString: process.env.DATABASE_URL
|
|
268
|
+
* }),
|
|
269
|
+
* logger: new PinoLogger({ name: 'MyApp' })
|
|
270
|
+
* });
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
212
273
|
constructor(config) {
|
|
213
274
|
if (config?.serverMiddleware) {
|
|
214
275
|
this.#serverMiddleware = config.serverMiddleware.map(m => ({
|
|
@@ -230,7 +291,7 @@ exports.Mastra = class Mastra {
|
|
|
230
291
|
this.#events[topic] = config?.events?.[topic] ?? [];
|
|
231
292
|
}
|
|
232
293
|
}
|
|
233
|
-
const workflowEventProcessor = new
|
|
294
|
+
const workflowEventProcessor = new chunkMHHMY2K4_cjs.WorkflowEventProcessor({
|
|
234
295
|
mastra: this
|
|
235
296
|
});
|
|
236
297
|
const workflowEventCb = async (event, cb) => {
|
|
@@ -270,7 +331,7 @@ exports.Mastra = class Mastra {
|
|
|
270
331
|
this.#logger?.warn(`Mastra telemetry is enabled, but the required instrumentation file was not loaded. If you are using Mastra outside of the mastra server environment, see: https://mastra.ai/en/docs/observability/tracing#tracing-outside-mastra-server-environment`, `If you are using a custom instrumentation file or want to disable this warning, set the globalThis.___MASTRA_TELEMETRY___ variable to true in your instrumentation file.`);
|
|
271
332
|
}
|
|
272
333
|
if (config?.observability) {
|
|
273
|
-
|
|
334
|
+
chunkLCJHFYJS_cjs.setupAITracing(config.observability);
|
|
274
335
|
}
|
|
275
336
|
if (this.#telemetry && storage) {
|
|
276
337
|
this.#storage = this.#telemetry.traceClass(storage, {
|
|
@@ -427,7 +488,7 @@ do:
|
|
|
427
488
|
* Register this Mastra instance with AI tracing exporters that need it
|
|
428
489
|
*/
|
|
429
490
|
registerAITracingExporters() {
|
|
430
|
-
const allTracingInstances =
|
|
491
|
+
const allTracingInstances = chunkLCJHFYJS_cjs.getAllAITracing();
|
|
431
492
|
allTracingInstances.forEach(tracing => {
|
|
432
493
|
const exporters = tracing.getExporters();
|
|
433
494
|
exporters.forEach(exporter => {
|
|
@@ -441,7 +502,7 @@ do:
|
|
|
441
502
|
* Initialize all AI tracing exporters after registration is complete
|
|
442
503
|
*/
|
|
443
504
|
initAITracingExporters() {
|
|
444
|
-
const allTracingInstances =
|
|
505
|
+
const allTracingInstances = chunkLCJHFYJS_cjs.getAllAITracing();
|
|
445
506
|
allTracingInstances.forEach(tracing => {
|
|
446
507
|
const config = tracing.getConfig();
|
|
447
508
|
const exporters = tracing.getExporters();
|
|
@@ -459,6 +520,27 @@ do:
|
|
|
459
520
|
});
|
|
460
521
|
});
|
|
461
522
|
}
|
|
523
|
+
/**
|
|
524
|
+
* Retrieves a registered agent by its name.
|
|
525
|
+
*
|
|
526
|
+
* @template TAgentName - The specific agent name type from the registered agents
|
|
527
|
+
* @throws {MastraError} When the agent with the specified name is not found
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
* ```typescript
|
|
531
|
+
* const mastra = new Mastra({
|
|
532
|
+
* agents: {
|
|
533
|
+
* weatherAgent: new Agent({
|
|
534
|
+
* name: 'weather-agent',
|
|
535
|
+
* instructions: 'You provide weather information',
|
|
536
|
+
* model: 'openai/gpt-5'
|
|
537
|
+
* })
|
|
538
|
+
* }
|
|
539
|
+
* });
|
|
540
|
+
* const agent = mastra.getAgent('weatherAgent');
|
|
541
|
+
* const response = await agent.generate('What is the weather?');
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
462
544
|
getAgent(name) {
|
|
463
545
|
const agent = this.#agents?.[name];
|
|
464
546
|
if (!agent) {
|
|
@@ -478,6 +560,31 @@ do:
|
|
|
478
560
|
}
|
|
479
561
|
return this.#agents[name];
|
|
480
562
|
}
|
|
563
|
+
/**
|
|
564
|
+
* Retrieves a registered agent by its unique ID.
|
|
565
|
+
*
|
|
566
|
+
* This method searches for an agent using its internal ID property. If no agent
|
|
567
|
+
* is found with the given ID, it also attempts to find an agent using the ID as
|
|
568
|
+
* a name (for backward compatibility).
|
|
569
|
+
*
|
|
570
|
+
* @throws {MastraError} When no agent is found with the specified ID
|
|
571
|
+
*
|
|
572
|
+
* @example
|
|
573
|
+
* ```typescript
|
|
574
|
+
* const mastra = new Mastra({
|
|
575
|
+
* agents: {
|
|
576
|
+
* assistant: new Agent({
|
|
577
|
+
* name: 'assistant',
|
|
578
|
+
* instructions: 'You are a helpful assistant',
|
|
579
|
+
* model: 'openai/gpt-5'
|
|
580
|
+
* })
|
|
581
|
+
* }
|
|
582
|
+
* });
|
|
583
|
+
*
|
|
584
|
+
* const assistant = mastra.getAgent('assistant');
|
|
585
|
+
* const sameAgent = mastra.getAgentById(assistant.id);
|
|
586
|
+
* ```
|
|
587
|
+
*/
|
|
481
588
|
getAgentById(id) {
|
|
482
589
|
let agent = Object.values(this.#agents).find(a => a.id === id);
|
|
483
590
|
if (!agent) {
|
|
@@ -502,9 +609,66 @@ do:
|
|
|
502
609
|
}
|
|
503
610
|
return agent;
|
|
504
611
|
}
|
|
612
|
+
/**
|
|
613
|
+
* Returns all registered agents as a record keyed by their names.
|
|
614
|
+
*
|
|
615
|
+
* This method provides access to the complete registry of agents, allowing you to
|
|
616
|
+
* iterate over them, check what agents are available, or perform bulk operations.
|
|
617
|
+
*
|
|
618
|
+
* @example
|
|
619
|
+
* ```typescript
|
|
620
|
+
* const mastra = new Mastra({
|
|
621
|
+
* agents: {
|
|
622
|
+
* weatherAgent: new Agent({ name: 'weather', model: openai('gpt-4o') }),
|
|
623
|
+
* supportAgent: new Agent({ name: 'support', model: openai('gpt-4o') })
|
|
624
|
+
* }
|
|
625
|
+
* });
|
|
626
|
+
*
|
|
627
|
+
* const allAgents = mastra.getAgents();
|
|
628
|
+
* console.log(Object.keys(allAgents)); // ['weatherAgent', 'supportAgent']
|
|
629
|
+
* ```
|
|
630
|
+
*/
|
|
505
631
|
getAgents() {
|
|
506
632
|
return this.#agents;
|
|
507
633
|
}
|
|
634
|
+
/**
|
|
635
|
+
* Retrieves a registered vector store by its name.
|
|
636
|
+
*
|
|
637
|
+
* @template TVectorName - The specific vector store name type from the registered vectors
|
|
638
|
+
* @throws {MastraError} When the vector store with the specified name is not found
|
|
639
|
+
*
|
|
640
|
+
* @example Using a vector store for semantic search
|
|
641
|
+
* ```typescript
|
|
642
|
+
* import { PineconeVector } from '@mastra/pinecone';
|
|
643
|
+
* import { OpenAIEmbedder } from '@mastra/embedders';
|
|
644
|
+
*
|
|
645
|
+
* const mastra = new Mastra({
|
|
646
|
+
* vectors: {
|
|
647
|
+
* knowledge: new PineconeVector({
|
|
648
|
+
* apiKey: process.env.PINECONE_API_KEY,
|
|
649
|
+
* indexName: 'knowledge-base',
|
|
650
|
+
* embedder: new OpenAIEmbedder({
|
|
651
|
+
* apiKey: process.env.OPENAI_API_KEY,
|
|
652
|
+
* model: 'text-embedding-3-small'
|
|
653
|
+
* })
|
|
654
|
+
* }),
|
|
655
|
+
* products: new PineconeVector({
|
|
656
|
+
* apiKey: process.env.PINECONE_API_KEY,
|
|
657
|
+
* indexName: 'product-catalog'
|
|
658
|
+
* })
|
|
659
|
+
* }
|
|
660
|
+
* });
|
|
661
|
+
*
|
|
662
|
+
* // Get a vector store and perform semantic search
|
|
663
|
+
* const knowledgeBase = mastra.getVector('knowledge');
|
|
664
|
+
* const results = await knowledgeBase.query({
|
|
665
|
+
* query: 'How to reset password?',
|
|
666
|
+
* topK: 5
|
|
667
|
+
* });
|
|
668
|
+
*
|
|
669
|
+
* console.log('Relevant documents:', results);
|
|
670
|
+
* ```
|
|
671
|
+
*/
|
|
508
672
|
getVector(name) {
|
|
509
673
|
const vector = this.#vectors?.[name];
|
|
510
674
|
if (!vector) {
|
|
@@ -524,12 +688,78 @@ do:
|
|
|
524
688
|
}
|
|
525
689
|
return vector;
|
|
526
690
|
}
|
|
691
|
+
/**
|
|
692
|
+
* Returns all registered vector stores as a record keyed by their names.
|
|
693
|
+
*
|
|
694
|
+
* @example Listing all vector stores
|
|
695
|
+
* ```typescript
|
|
696
|
+
* const mastra = new Mastra({
|
|
697
|
+
* vectors: {
|
|
698
|
+
* documents: new PineconeVector({ indexName: 'docs' }),
|
|
699
|
+
* images: new PineconeVector({ indexName: 'images' }),
|
|
700
|
+
* products: new ChromaVector({ collectionName: 'products' })
|
|
701
|
+
* }
|
|
702
|
+
* });
|
|
703
|
+
*
|
|
704
|
+
* const allVectors = mastra.getVectors();
|
|
705
|
+
* console.log(Object.keys(allVectors)); // ['documents', 'images', 'products']
|
|
706
|
+
*
|
|
707
|
+
* // Check vector store types and configurations
|
|
708
|
+
* for (const [name, vectorStore] of Object.entries(allVectors)) {
|
|
709
|
+
* console.log(`Vector store ${name}:`, vectorStore.constructor.name);
|
|
710
|
+
* }
|
|
711
|
+
* ```
|
|
712
|
+
*/
|
|
527
713
|
getVectors() {
|
|
528
714
|
return this.#vectors;
|
|
529
715
|
}
|
|
716
|
+
/**
|
|
717
|
+
* Gets the currently configured deployment provider.
|
|
718
|
+
*
|
|
719
|
+
* @example
|
|
720
|
+
* ```typescript
|
|
721
|
+
* const mastra = new Mastra({
|
|
722
|
+
* deployer: new VercelDeployer({
|
|
723
|
+
* token: process.env.VERCEL_TOKEN,
|
|
724
|
+
* projectId: process.env.VERCEL_PROJECT_ID
|
|
725
|
+
* })
|
|
726
|
+
* });
|
|
727
|
+
*
|
|
728
|
+
* const deployer = mastra.getDeployer();
|
|
729
|
+
* if (deployer) {
|
|
730
|
+
* await deployer.deploy({
|
|
731
|
+
* name: 'my-mastra-app',
|
|
732
|
+
* environment: 'production'
|
|
733
|
+
* });
|
|
734
|
+
* }
|
|
735
|
+
* ```
|
|
736
|
+
*/
|
|
530
737
|
getDeployer() {
|
|
531
738
|
return this.#deployer;
|
|
532
739
|
}
|
|
740
|
+
/**
|
|
741
|
+
* Retrieves a registered legacy workflow by its ID.
|
|
742
|
+
*
|
|
743
|
+
* Legacy workflows are the previous generation of workflow system in Mastra,
|
|
744
|
+
* maintained for backward compatibility. For new implementations, use the
|
|
745
|
+
* modern workflow system accessed via `getWorkflow()`.
|
|
746
|
+
*
|
|
747
|
+
* @template TWorkflowId - The specific workflow ID type from the registered legacy workflows
|
|
748
|
+
* @throws {MastraError} When the legacy workflow with the specified ID is not found
|
|
749
|
+
* @deprecated Use `getWorkflow()` for new implementations
|
|
750
|
+
*
|
|
751
|
+
* @example Getting a legacy workflow
|
|
752
|
+
* ```typescript
|
|
753
|
+
* const mastra = new Mastra({
|
|
754
|
+
* legacy_workflows: {
|
|
755
|
+
* oldDataFlow: legacyWorkflowInstance
|
|
756
|
+
* }
|
|
757
|
+
* });
|
|
758
|
+
*
|
|
759
|
+
* const workflow = mastra.legacy_getWorkflow('oldDataFlow');
|
|
760
|
+
* const result = await workflow.execute({ input: 'data' });
|
|
761
|
+
* ```
|
|
762
|
+
*/
|
|
533
763
|
legacy_getWorkflow(id, {
|
|
534
764
|
serialized
|
|
535
765
|
} = {}) {
|
|
@@ -556,6 +786,33 @@ do:
|
|
|
556
786
|
}
|
|
557
787
|
return workflow;
|
|
558
788
|
}
|
|
789
|
+
/**
|
|
790
|
+
* Retrieves a registered workflow by its ID.
|
|
791
|
+
*
|
|
792
|
+
* @template TWorkflowId - The specific workflow ID type from the registered workflows
|
|
793
|
+
* @throws {MastraError} When the workflow with the specified ID is not found
|
|
794
|
+
*
|
|
795
|
+
* @example Getting and executing a workflow
|
|
796
|
+
* ```typescript
|
|
797
|
+
* import { createWorkflow, createStep } from '@mastra/core/workflows';
|
|
798
|
+
* import { z } from 'zod';
|
|
799
|
+
*
|
|
800
|
+
* const processDataWorkflow = createWorkflow({
|
|
801
|
+
* name: 'process-data',
|
|
802
|
+
* triggerSchema: z.object({ input: z.string() })
|
|
803
|
+
* })
|
|
804
|
+
* .then(validateStep)
|
|
805
|
+
* .then(transformStep)
|
|
806
|
+
* .then(saveStep)
|
|
807
|
+
* .commit();
|
|
808
|
+
*
|
|
809
|
+
* const mastra = new Mastra({
|
|
810
|
+
* workflows: {
|
|
811
|
+
* dataProcessor: processDataWorkflow
|
|
812
|
+
* }
|
|
813
|
+
* });
|
|
814
|
+
* ```
|
|
815
|
+
*/
|
|
559
816
|
getWorkflow(id, {
|
|
560
817
|
serialized
|
|
561
818
|
} = {}) {
|
|
@@ -609,6 +866,35 @@ do:
|
|
|
609
866
|
}
|
|
610
867
|
return workflow;
|
|
611
868
|
}
|
|
869
|
+
/**
|
|
870
|
+
* Retrieves a registered workflow by its unique ID.
|
|
871
|
+
*
|
|
872
|
+
* This method searches for a workflow using its internal ID property. If no workflow
|
|
873
|
+
* is found with the given ID, it also attempts to find a workflow using the ID as
|
|
874
|
+
* a name (for backward compatibility).
|
|
875
|
+
*
|
|
876
|
+
* @throws {MastraError} When no workflow is found with the specified ID
|
|
877
|
+
*
|
|
878
|
+
* @example Finding a workflow by ID
|
|
879
|
+
* ```typescript
|
|
880
|
+
* const mastra = new Mastra({
|
|
881
|
+
* workflows: {
|
|
882
|
+
* dataProcessor: createWorkflow({
|
|
883
|
+
* name: 'process-data',
|
|
884
|
+
* triggerSchema: z.object({ input: z.string() })
|
|
885
|
+
* }).commit()
|
|
886
|
+
* }
|
|
887
|
+
* });
|
|
888
|
+
*
|
|
889
|
+
* // Get the workflow's ID
|
|
890
|
+
* const workflow = mastra.getWorkflow('dataProcessor');
|
|
891
|
+
* const workflowId = workflow.id;
|
|
892
|
+
*
|
|
893
|
+
* // Later, retrieve the workflow by ID
|
|
894
|
+
* const sameWorkflow = mastra.getWorkflowById(workflowId);
|
|
895
|
+
* console.log(sameWorkflow.name); // "process-data"
|
|
896
|
+
* ```
|
|
897
|
+
*/
|
|
612
898
|
getWorkflowById(id) {
|
|
613
899
|
let workflow = Object.values(this.#workflows).find(a => a.id === id);
|
|
614
900
|
if (!workflow) {
|
|
@@ -633,6 +919,32 @@ do:
|
|
|
633
919
|
}
|
|
634
920
|
return workflow;
|
|
635
921
|
}
|
|
922
|
+
/**
|
|
923
|
+
* Returns all registered legacy workflows as a record keyed by their IDs.
|
|
924
|
+
*
|
|
925
|
+
* Legacy workflows are the previous generation of workflow system in Mastra,
|
|
926
|
+
* maintained for backward compatibility. For new implementations, use `getWorkflows()`.
|
|
927
|
+
*
|
|
928
|
+
* @deprecated Use `getWorkflows()` for new implementations
|
|
929
|
+
*
|
|
930
|
+
* @example Listing all legacy workflows
|
|
931
|
+
* ```typescript
|
|
932
|
+
* const mastra = new Mastra({
|
|
933
|
+
* legacy_workflows: {
|
|
934
|
+
* oldFlow1: legacyWorkflow1,
|
|
935
|
+
* oldFlow2: legacyWorkflow2
|
|
936
|
+
* }
|
|
937
|
+
* });
|
|
938
|
+
*
|
|
939
|
+
* const allLegacyWorkflows = mastra.legacy_getWorkflows();
|
|
940
|
+
* console.log(Object.keys(allLegacyWorkflows)); // ['oldFlow1', 'oldFlow2']
|
|
941
|
+
*
|
|
942
|
+
* // Execute all legacy workflows
|
|
943
|
+
* for (const [id, workflow] of Object.entries(allLegacyWorkflows)) {
|
|
944
|
+
* console.log(`Legacy workflow ${id}:`, workflow.name);
|
|
945
|
+
* }
|
|
946
|
+
* ```
|
|
947
|
+
*/
|
|
636
948
|
legacy_getWorkflows(props = {}) {
|
|
637
949
|
if (props.serialized) {
|
|
638
950
|
return Object.entries(this.#legacy_workflows).reduce((acc, [k, v]) => {
|
|
@@ -646,9 +958,66 @@ do:
|
|
|
646
958
|
}
|
|
647
959
|
return this.#legacy_workflows;
|
|
648
960
|
}
|
|
961
|
+
/**
|
|
962
|
+
* Returns all registered scorers as a record keyed by their IDs.
|
|
963
|
+
*
|
|
964
|
+
* @example Listing all scorers
|
|
965
|
+
* ```typescript
|
|
966
|
+
* import { HelpfulnessScorer, AccuracyScorer, RelevanceScorer } from '@mastra/scorers';
|
|
967
|
+
*
|
|
968
|
+
* const mastra = new Mastra({
|
|
969
|
+
* scorers: {
|
|
970
|
+
* helpfulness: new HelpfulnessScorer(),
|
|
971
|
+
* accuracy: new AccuracyScorer(),
|
|
972
|
+
* relevance: new RelevanceScorer()
|
|
973
|
+
* }
|
|
974
|
+
* });
|
|
975
|
+
*
|
|
976
|
+
* const allScorers = mastra.getScorers();
|
|
977
|
+
* console.log(Object.keys(allScorers)); // ['helpfulness', 'accuracy', 'relevance']
|
|
978
|
+
*
|
|
979
|
+
* // Check scorer configurations
|
|
980
|
+
* for (const [id, scorer] of Object.entries(allScorers)) {
|
|
981
|
+
* console.log(`Scorer ${id}:`, scorer.name, scorer.description);
|
|
982
|
+
* }
|
|
983
|
+
* ```
|
|
984
|
+
*/
|
|
649
985
|
getScorers() {
|
|
650
986
|
return this.#scorers;
|
|
651
987
|
}
|
|
988
|
+
/**
|
|
989
|
+
* Retrieves a registered scorer by its key.
|
|
990
|
+
*
|
|
991
|
+
* @template TScorerKey - The specific scorer key type from the registered scorers
|
|
992
|
+
* @throws {MastraError} When the scorer with the specified key is not found
|
|
993
|
+
*
|
|
994
|
+
* @example Getting and using a scorer
|
|
995
|
+
* ```typescript
|
|
996
|
+
* import { HelpfulnessScorer, AccuracyScorer } from '@mastra/scorers';
|
|
997
|
+
*
|
|
998
|
+
* const mastra = new Mastra({
|
|
999
|
+
* scorers: {
|
|
1000
|
+
* helpfulness: new HelpfulnessScorer({
|
|
1001
|
+
* model: openai('gpt-4o'),
|
|
1002
|
+
* criteria: 'Rate how helpful this response is'
|
|
1003
|
+
* }),
|
|
1004
|
+
* accuracy: new AccuracyScorer({
|
|
1005
|
+
* model: 'openai/gpt-5'
|
|
1006
|
+
* })
|
|
1007
|
+
* }
|
|
1008
|
+
* });
|
|
1009
|
+
*
|
|
1010
|
+
* // Get a specific scorer
|
|
1011
|
+
* const helpfulnessScorer = mastra.getScorer('helpfulness');
|
|
1012
|
+
* const score = await helpfulnessScorer.score({
|
|
1013
|
+
* input: 'How do I reset my password?',
|
|
1014
|
+
* output: 'You can reset your password by clicking the forgot password link.',
|
|
1015
|
+
* expected: 'Detailed password reset instructions'
|
|
1016
|
+
* });
|
|
1017
|
+
*
|
|
1018
|
+
* console.log('Helpfulness score:', score);
|
|
1019
|
+
* ```
|
|
1020
|
+
*/
|
|
652
1021
|
getScorer(key) {
|
|
653
1022
|
const scorer = this.#scorers?.[key];
|
|
654
1023
|
if (!scorer) {
|
|
@@ -663,6 +1032,36 @@ do:
|
|
|
663
1032
|
}
|
|
664
1033
|
return scorer;
|
|
665
1034
|
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Retrieves a registered scorer by its name.
|
|
1037
|
+
*
|
|
1038
|
+
* This method searches through all registered scorers to find one with the specified name.
|
|
1039
|
+
* Unlike `getScorer()` which uses the registration key, this method uses the scorer's
|
|
1040
|
+
* internal name property.
|
|
1041
|
+
*
|
|
1042
|
+
* @throws {MastraError} When no scorer is found with the specified name
|
|
1043
|
+
*
|
|
1044
|
+
* @example Finding a scorer by name
|
|
1045
|
+
* ```typescript
|
|
1046
|
+
* import { HelpfulnessScorer } from '@mastra/scorers';
|
|
1047
|
+
*
|
|
1048
|
+
* const mastra = new Mastra({
|
|
1049
|
+
* scorers: {
|
|
1050
|
+
* myHelpfulnessScorer: new HelpfulnessScorer({
|
|
1051
|
+
* name: 'helpfulness-evaluator',
|
|
1052
|
+
* model: 'openai/gpt-5'
|
|
1053
|
+
* })
|
|
1054
|
+
* }
|
|
1055
|
+
* });
|
|
1056
|
+
*
|
|
1057
|
+
* // Find scorer by its internal name, not the registration key
|
|
1058
|
+
* const scorer = mastra.getScorerByName('helpfulness-evaluator');
|
|
1059
|
+
* const score = await scorer.score({
|
|
1060
|
+
* input: 'question',
|
|
1061
|
+
* output: 'answer'
|
|
1062
|
+
* });
|
|
1063
|
+
* ```
|
|
1064
|
+
*/
|
|
666
1065
|
getScorerByName(name) {
|
|
667
1066
|
for (const [_key, value] of Object.entries(this.#scorers ?? {})) {
|
|
668
1067
|
if (value.name === name) {
|
|
@@ -678,6 +1077,29 @@ do:
|
|
|
678
1077
|
this.#logger?.trackException(error);
|
|
679
1078
|
throw error;
|
|
680
1079
|
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Returns all registered workflows as a record keyed by their IDs.
|
|
1082
|
+
*
|
|
1083
|
+
* @example Listing all workflows
|
|
1084
|
+
* ```typescript
|
|
1085
|
+
* const mastra = new Mastra({
|
|
1086
|
+
* workflows: {
|
|
1087
|
+
* dataProcessor: createWorkflow({...}).commit(),
|
|
1088
|
+
* emailSender: createWorkflow({...}).commit(),
|
|
1089
|
+
* reportGenerator: createWorkflow({...}).commit()
|
|
1090
|
+
* }
|
|
1091
|
+
* });
|
|
1092
|
+
*
|
|
1093
|
+
* const allWorkflows = mastra.getWorkflows();
|
|
1094
|
+
* console.log(Object.keys(allWorkflows)); // ['dataProcessor', 'emailSender', 'reportGenerator']
|
|
1095
|
+
*
|
|
1096
|
+
* // Execute all workflows with sample data
|
|
1097
|
+
* for (const [id, workflow] of Object.entries(allWorkflows)) {
|
|
1098
|
+
* console.log(`Workflow ${id}:`, workflow.name);
|
|
1099
|
+
* // const result = await workflow.execute(sampleData);
|
|
1100
|
+
* }
|
|
1101
|
+
* ```
|
|
1102
|
+
*/
|
|
681
1103
|
getWorkflows(props = {}) {
|
|
682
1104
|
if (props.serialized) {
|
|
683
1105
|
return Object.entries(this.#workflows).reduce((acc, [k, v]) => {
|
|
@@ -691,6 +1113,25 @@ do:
|
|
|
691
1113
|
}
|
|
692
1114
|
return this.#workflows;
|
|
693
1115
|
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Sets the storage provider for the Mastra instance.
|
|
1118
|
+
*
|
|
1119
|
+
* @example
|
|
1120
|
+
* ```typescript
|
|
1121
|
+
* const mastra = new Mastra();
|
|
1122
|
+
*
|
|
1123
|
+
* // Set PostgreSQL storage
|
|
1124
|
+
* mastra.setStorage(new PostgresStore({
|
|
1125
|
+
* connectionString: process.env.DATABASE_URL
|
|
1126
|
+
* }));
|
|
1127
|
+
*
|
|
1128
|
+
* // Now agents can use memory with the storage
|
|
1129
|
+
* const agent = new Agent({
|
|
1130
|
+
* name: 'assistant',
|
|
1131
|
+
* memory: new Memory({ storage: mastra.getStorage() })
|
|
1132
|
+
* });
|
|
1133
|
+
* ```
|
|
1134
|
+
*/
|
|
694
1135
|
setStorage(storage) {
|
|
695
1136
|
this.#storage = chunkV3VLOOSW_cjs.augmentWithInit(storage);
|
|
696
1137
|
}
|
|
@@ -727,7 +1168,7 @@ do:
|
|
|
727
1168
|
this.#mcpServers?.[key]?.__setLogger(this.#logger);
|
|
728
1169
|
});
|
|
729
1170
|
}
|
|
730
|
-
const allTracingInstances =
|
|
1171
|
+
const allTracingInstances = chunkLCJHFYJS_cjs.getAllAITracing();
|
|
731
1172
|
allTracingInstances.forEach(instance => {
|
|
732
1173
|
instance.__setLogger(this.#logger);
|
|
733
1174
|
});
|
|
@@ -784,18 +1225,116 @@ do:
|
|
|
784
1225
|
this.#vectors = vectors;
|
|
785
1226
|
}
|
|
786
1227
|
}
|
|
1228
|
+
/**
|
|
1229
|
+
* Gets all registered text-to-speech (TTS) providers.
|
|
1230
|
+
*
|
|
1231
|
+
* @example
|
|
1232
|
+
* ```typescript
|
|
1233
|
+
* const mastra = new Mastra({
|
|
1234
|
+
* tts: {
|
|
1235
|
+
* openai: new OpenAITTS({
|
|
1236
|
+
* apiKey: process.env.OPENAI_API_KEY,
|
|
1237
|
+
* voice: 'alloy'
|
|
1238
|
+
* })
|
|
1239
|
+
* }
|
|
1240
|
+
* });
|
|
1241
|
+
*
|
|
1242
|
+
* const ttsProviders = mastra.getTTS();
|
|
1243
|
+
* const openaiTTS = ttsProviders?.openai;
|
|
1244
|
+
* if (openaiTTS) {
|
|
1245
|
+
* const audioBuffer = await openaiTTS.synthesize('Hello, world!');
|
|
1246
|
+
* }
|
|
1247
|
+
* ```
|
|
1248
|
+
*/
|
|
787
1249
|
getTTS() {
|
|
788
1250
|
return this.#tts;
|
|
789
1251
|
}
|
|
1252
|
+
/**
|
|
1253
|
+
* Gets the currently configured logger instance.
|
|
1254
|
+
*
|
|
1255
|
+
* @example
|
|
1256
|
+
* ```typescript
|
|
1257
|
+
* const mastra = new Mastra({
|
|
1258
|
+
* logger: new PinoLogger({
|
|
1259
|
+
* name: 'MyApp',
|
|
1260
|
+
* level: 'info'
|
|
1261
|
+
* })
|
|
1262
|
+
* });
|
|
1263
|
+
*
|
|
1264
|
+
* const logger = mastra.getLogger();
|
|
1265
|
+
* logger.info('Application started');
|
|
1266
|
+
* logger.error('An error occurred', { error: 'details' });
|
|
1267
|
+
* ```
|
|
1268
|
+
*/
|
|
790
1269
|
getLogger() {
|
|
791
1270
|
return this.#logger;
|
|
792
1271
|
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Gets the currently configured telemetry instance.
|
|
1274
|
+
*
|
|
1275
|
+
* @example
|
|
1276
|
+
* ```typescript
|
|
1277
|
+
* const mastra = new Mastra({
|
|
1278
|
+
* telemetry: {
|
|
1279
|
+
* enabled: true,
|
|
1280
|
+
* serviceName: 'my-mastra-app'
|
|
1281
|
+
* }
|
|
1282
|
+
* });
|
|
1283
|
+
*
|
|
1284
|
+
* const telemetry = mastra.getTelemetry();
|
|
1285
|
+
* if (telemetry) {
|
|
1286
|
+
* const span = telemetry.startSpan('custom-operation');
|
|
1287
|
+
* span.setAttributes({ operation: 'data-processing' });
|
|
1288
|
+
* span.end();
|
|
1289
|
+
* }
|
|
1290
|
+
* ```
|
|
1291
|
+
*/
|
|
793
1292
|
getTelemetry() {
|
|
794
1293
|
return this.#telemetry;
|
|
795
1294
|
}
|
|
1295
|
+
/**
|
|
1296
|
+
* Gets the currently configured memory instance.
|
|
1297
|
+
*
|
|
1298
|
+
* @deprecated Memory should be configured directly on agents instead of on the Mastra instance.
|
|
1299
|
+
* Use `new Agent({ memory: new Memory() })` instead.
|
|
1300
|
+
*
|
|
1301
|
+
* @example Legacy memory usage (deprecated)
|
|
1302
|
+
* ```typescript
|
|
1303
|
+
* // This approach is deprecated
|
|
1304
|
+
* const mastra = new Mastra({
|
|
1305
|
+
* // memory: new Memory() // This is no longer supported
|
|
1306
|
+
* });
|
|
1307
|
+
*
|
|
1308
|
+
* // Use this instead:
|
|
1309
|
+
* const agent = new Agent({
|
|
1310
|
+
* name: 'assistant',
|
|
1311
|
+
* memory: new Memory({
|
|
1312
|
+
* storage: new LibSQLStore({ url: ':memory:' })
|
|
1313
|
+
* })
|
|
1314
|
+
* });
|
|
1315
|
+
* ```
|
|
1316
|
+
*/
|
|
796
1317
|
getMemory() {
|
|
797
1318
|
return this.#memory;
|
|
798
1319
|
}
|
|
1320
|
+
/**
|
|
1321
|
+
* Gets the currently configured storage provider.
|
|
1322
|
+
*
|
|
1323
|
+
* @example
|
|
1324
|
+
* ```typescript
|
|
1325
|
+
* const mastra = new Mastra({
|
|
1326
|
+
* storage: new LibSQLStore({ url: 'file:./data.db' })
|
|
1327
|
+
* });
|
|
1328
|
+
*
|
|
1329
|
+
* // Use the storage in agent memory
|
|
1330
|
+
* const agent = new Agent({
|
|
1331
|
+
* name: 'assistant',
|
|
1332
|
+
* memory: new Memory({
|
|
1333
|
+
* storage: mastra.getStorage()
|
|
1334
|
+
* })
|
|
1335
|
+
* });
|
|
1336
|
+
* ```
|
|
1337
|
+
*/
|
|
799
1338
|
getStorage() {
|
|
800
1339
|
return this.#storage;
|
|
801
1340
|
}
|
|
@@ -920,20 +1459,52 @@ do:
|
|
|
920
1459
|
return await this.#logger.getLogs(transportId, params);
|
|
921
1460
|
}
|
|
922
1461
|
/**
|
|
923
|
-
*
|
|
924
|
-
*
|
|
1462
|
+
* Gets all registered Model Context Protocol (MCP) server instances.
|
|
1463
|
+
*
|
|
1464
|
+
* @example
|
|
1465
|
+
* ```typescript
|
|
1466
|
+
* const mastra = new Mastra({
|
|
1467
|
+
* mcpServers: {
|
|
1468
|
+
* filesystem: new FileSystemMCPServer({
|
|
1469
|
+
* rootPath: '/app/data'
|
|
1470
|
+
* })
|
|
1471
|
+
* }
|
|
1472
|
+
* });
|
|
1473
|
+
*
|
|
1474
|
+
* const mcpServers = mastra.getMCPServers();
|
|
1475
|
+
* if (mcpServers) {
|
|
1476
|
+
* const fsServer = mcpServers.filesystem;
|
|
1477
|
+
* const tools = await fsServer.getTools();
|
|
1478
|
+
* }
|
|
1479
|
+
* ```
|
|
925
1480
|
*/
|
|
926
1481
|
getMCPServers() {
|
|
927
1482
|
return this.#mcpServers;
|
|
928
1483
|
}
|
|
929
1484
|
/**
|
|
930
|
-
*
|
|
931
|
-
*
|
|
932
|
-
*
|
|
933
|
-
*
|
|
934
|
-
*
|
|
935
|
-
*
|
|
936
|
-
* @
|
|
1485
|
+
* Retrieves a specific Model Context Protocol (MCP) server instance by its logical ID.
|
|
1486
|
+
*
|
|
1487
|
+
* This method searches for an MCP server using its logical ID. If a version is specified,
|
|
1488
|
+
* it returns the exact version match. If no version is provided, it returns the server
|
|
1489
|
+
* with the most recent release date.
|
|
1490
|
+
*
|
|
1491
|
+
* @example
|
|
1492
|
+
* ```typescript
|
|
1493
|
+
* const mastra = new Mastra({
|
|
1494
|
+
* mcpServers: {
|
|
1495
|
+
* filesystem: new FileSystemMCPServer({
|
|
1496
|
+
* id: 'fs-server',
|
|
1497
|
+
* version: '1.0.0',
|
|
1498
|
+
* rootPath: '/app/data'
|
|
1499
|
+
* })
|
|
1500
|
+
* }
|
|
1501
|
+
* });
|
|
1502
|
+
*
|
|
1503
|
+
* const fsServer = mastra.getMCPServer('fs-server');
|
|
1504
|
+
* if (fsServer) {
|
|
1505
|
+
* const tools = await fsServer.getTools();
|
|
1506
|
+
* }
|
|
1507
|
+
* ```
|
|
937
1508
|
*/
|
|
938
1509
|
getMCPServer(serverId, version) {
|
|
939
1510
|
if (!this.#mcpServers) {
|
|
@@ -1003,10 +1574,32 @@ do:
|
|
|
1003
1574
|
await this.#pubsub.flush();
|
|
1004
1575
|
}
|
|
1005
1576
|
/**
|
|
1006
|
-
*
|
|
1577
|
+
* Gracefully shuts down the Mastra instance and cleans up all resources.
|
|
1578
|
+
*
|
|
1579
|
+
* This method performs a clean shutdown of all Mastra components, including:
|
|
1580
|
+
* - AI tracing registry and all tracing instances
|
|
1581
|
+
* - Event engine and pub/sub system
|
|
1582
|
+
* - All registered components and their resources
|
|
1583
|
+
*
|
|
1584
|
+
* It's important to call this method when your application is shutting down
|
|
1585
|
+
* to ensure proper cleanup and prevent resource leaks.
|
|
1586
|
+
*
|
|
1587
|
+
* @example
|
|
1588
|
+
* ```typescript
|
|
1589
|
+
* const mastra = new Mastra({
|
|
1590
|
+
* agents: { myAgent },
|
|
1591
|
+
* workflows: { myWorkflow }
|
|
1592
|
+
* });
|
|
1593
|
+
*
|
|
1594
|
+
* // Graceful shutdown on SIGINT
|
|
1595
|
+
* process.on('SIGINT', async () => {
|
|
1596
|
+
* await mastra.shutdown();
|
|
1597
|
+
* process.exit(0);
|
|
1598
|
+
* });
|
|
1599
|
+
* ```
|
|
1007
1600
|
*/
|
|
1008
1601
|
async shutdown() {
|
|
1009
|
-
await
|
|
1602
|
+
await chunkLCJHFYJS_cjs.shutdownAITracingRegistry();
|
|
1010
1603
|
await this.stopEventEngine();
|
|
1011
1604
|
this.#logger?.info("Mastra shutdown completed");
|
|
1012
1605
|
}
|
|
@@ -1021,5 +1614,5 @@ exports.Mastra = /*@__PURE__*/(_ => {
|
|
|
1021
1614
|
chunkEBVYYC2Q_cjs.__runInitializers(_init, 1, exports.Mastra);
|
|
1022
1615
|
return exports.Mastra;
|
|
1023
1616
|
})();
|
|
1024
|
-
//# sourceMappingURL=chunk-
|
|
1025
|
-
//# sourceMappingURL=chunk-
|
|
1617
|
+
//# sourceMappingURL=chunk-6K7IMZVR.cjs.map
|
|
1618
|
+
//# sourceMappingURL=chunk-6K7IMZVR.cjs.map
|