@mastra/core 1.0.0-beta.7 → 1.0.0-beta.9
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 +77 -0
- package/dist/agent/agent.d.ts +1 -1
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/index.cjs +9 -9
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/index.cjs +3 -3
- package/dist/agent/message-list/index.js +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +2 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts +2 -1
- package/dist/agent/workflows/prepare-stream/stream-step.d.ts.map +1 -1
- package/dist/{chunk-PJ7AYWAX.cjs → chunk-3DRGAKUH.cjs} +382 -13
- package/dist/chunk-3DRGAKUH.cjs.map +1 -0
- package/dist/{chunk-EE5NIGJ4.js → chunk-4GLDYGNN.js} +3 -3
- package/dist/{chunk-EE5NIGJ4.js.map → chunk-4GLDYGNN.js.map} +1 -1
- package/dist/{chunk-4GTU7MB2.js → chunk-7IMDJAYQ.js} +5 -5
- package/dist/{chunk-4GTU7MB2.js.map → chunk-7IMDJAYQ.js.map} +1 -1
- package/dist/{chunk-M7CQULF7.cjs → chunk-7S7TLMTS.cjs} +287 -10
- package/dist/chunk-7S7TLMTS.cjs.map +1 -0
- package/dist/{chunk-NAKPEQEQ.js → chunk-A4C3AGVS.js} +5 -5
- package/dist/{chunk-NAKPEQEQ.js.map → chunk-A4C3AGVS.js.map} +1 -1
- package/dist/{chunk-DMPHPHMU.js → chunk-APMPOYPI.js} +3 -3
- package/dist/{chunk-DMPHPHMU.js.map → chunk-APMPOYPI.js.map} +1 -1
- package/dist/{chunk-POM7FCH5.js → chunk-ARSSSQQP.js} +141 -48
- package/dist/chunk-ARSSSQQP.js.map +1 -0
- package/dist/{chunk-HJNEZRI4.cjs → chunk-CKRWR5DS.cjs} +15 -15
- package/dist/{chunk-HJNEZRI4.cjs.map → chunk-CKRWR5DS.cjs.map} +1 -1
- package/dist/{chunk-26YAGTXK.cjs → chunk-DWB7SBVC.cjs} +28 -32
- package/dist/chunk-DWB7SBVC.cjs.map +1 -0
- package/dist/{chunk-URMN7TTH.cjs → chunk-EGXQVF75.cjs} +380 -6
- package/dist/chunk-EGXQVF75.cjs.map +1 -0
- package/dist/{chunk-4AP234N6.cjs → chunk-F77YTHXI.cjs} +4 -4
- package/dist/{chunk-4AP234N6.cjs.map → chunk-F77YTHXI.cjs.map} +1 -1
- package/dist/{chunk-6C2PU6J4.cjs → chunk-HSRQXO6F.cjs} +6 -6
- package/dist/{chunk-6C2PU6J4.cjs.map → chunk-HSRQXO6F.cjs.map} +1 -1
- package/dist/{chunk-YUXTDKYN.cjs → chunk-IISGCZJ4.cjs} +15 -15
- package/dist/{chunk-YUXTDKYN.cjs.map → chunk-IISGCZJ4.cjs.map} +1 -1
- package/dist/{chunk-EPMSC67U.js → chunk-LB7UOP2X.js} +376 -7
- package/dist/chunk-LB7UOP2X.js.map +1 -0
- package/dist/{chunk-URBPEE67.js → chunk-MCRIVYUB.js} +3 -3
- package/dist/{chunk-URBPEE67.js.map → chunk-MCRIVYUB.js.map} +1 -1
- package/dist/{chunk-AZQMPE7G.cjs → chunk-MRFUISXC.cjs} +3 -3
- package/dist/{chunk-AZQMPE7G.cjs.map → chunk-MRFUISXC.cjs.map} +1 -1
- package/dist/{chunk-TLLXRG2Z.js → chunk-OEIVMCWX.js} +3 -3
- package/dist/{chunk-TLLXRG2Z.js.map → chunk-OEIVMCWX.js.map} +1 -1
- package/dist/{chunk-FNSFXWDN.js → chunk-PIHOAJTA.js} +2 -2
- package/dist/chunk-PIHOAJTA.js.map +1 -0
- package/dist/{chunk-ZUWJCGLM.js → chunk-QM5SRDJX.js} +4 -5
- package/dist/chunk-QM5SRDJX.js.map +1 -0
- package/dist/{chunk-Z4Y554NX.js → chunk-QTEIZ2XG.js} +8 -12
- package/dist/chunk-QTEIZ2XG.js.map +1 -0
- package/dist/{chunk-VBKMNIWK.cjs → chunk-RIG4JP3V.cjs} +11 -11
- package/dist/{chunk-VBKMNIWK.cjs.map → chunk-RIG4JP3V.cjs.map} +1 -1
- package/dist/{chunk-5T53HHNP.js → chunk-SLX3NVAC.js} +4 -4
- package/dist/{chunk-5T53HHNP.js.map → chunk-SLX3NVAC.js.map} +1 -1
- package/dist/{chunk-TQB2HMEC.cjs → chunk-SVLMF4UZ.cjs} +44 -45
- package/dist/chunk-SVLMF4UZ.cjs.map +1 -0
- package/dist/{chunk-3EYBRHB2.cjs → chunk-UVM27J4A.cjs} +2 -2
- package/dist/chunk-UVM27J4A.cjs.map +1 -0
- package/dist/{chunk-GZ6MCDK2.js → chunk-VQ3FTSRC.js} +379 -5
- package/dist/chunk-VQ3FTSRC.js.map +1 -0
- package/dist/{chunk-YBEW5YWC.cjs → chunk-VRFSEZBA.cjs} +6 -6
- package/dist/{chunk-YBEW5YWC.cjs.map → chunk-VRFSEZBA.cjs.map} +1 -1
- package/dist/{chunk-RBBEMTMA.cjs → chunk-XMT5T4F2.cjs} +184 -89
- package/dist/chunk-XMT5T4F2.cjs.map +1 -0
- package/dist/{chunk-G32WDDGV.js → chunk-ZINZHEXZ.js} +282 -9
- package/dist/chunk-ZINZHEXZ.js.map +1 -0
- package/dist/evals/index.cjs +9 -9
- package/dist/evals/index.js +2 -2
- package/dist/evals/scoreTraces/index.cjs +5 -5
- package/dist/evals/scoreTraces/index.js +2 -2
- package/dist/evals/types.d.ts +21 -20
- package/dist/evals/types.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/llm/index.cjs +11 -11
- package/dist/llm/index.js +3 -3
- 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-types.generated.d.ts +180 -1
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/network/index.d.ts +2 -2
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/types.d.ts +1 -0
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +191 -5
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +6 -6
- package/dist/memory/index.js +1 -1
- package/dist/memory/memory.d.ts +6 -0
- package/dist/memory/memory.d.ts.map +1 -1
- package/dist/models-dev-23RN2WHG.js +3 -0
- package/dist/{models-dev-6GD3644V.js.map → models-dev-23RN2WHG.js.map} +1 -1
- package/dist/models-dev-EO3SUIY2.cjs +12 -0
- package/dist/{models-dev-IUQBXJSS.cjs.map → models-dev-EO3SUIY2.cjs.map} +1 -1
- package/dist/observability/index.cjs +10 -10
- package/dist/observability/index.js +1 -1
- package/dist/observability/types/tracing.d.ts +4 -0
- package/dist/observability/types/tracing.d.ts.map +1 -1
- package/dist/processors/index.cjs +17 -17
- package/dist/processors/index.js +1 -1
- package/dist/provider-registry-FM3IVY6C.js +3 -0
- package/dist/{provider-registry-ZTMZMTVV.js.map → provider-registry-FM3IVY6C.js.map} +1 -1
- package/dist/provider-registry-Q6T32VC5.cjs +40 -0
- package/dist/{provider-registry-7IFOXWPR.cjs.map → provider-registry-Q6T32VC5.cjs.map} +1 -1
- package/dist/provider-registry.json +376 -2
- package/dist/relevance/index.cjs +2 -2
- package/dist/relevance/index.js +1 -1
- package/dist/storage/base.d.ts +50 -2
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/constants.d.ts +3 -1
- package/dist/storage/constants.d.ts.map +1 -1
- package/dist/storage/domains/agents/base.d.ts +49 -0
- package/dist/storage/domains/agents/base.d.ts.map +1 -0
- package/dist/storage/domains/agents/index.d.ts +3 -0
- package/dist/storage/domains/agents/index.d.ts.map +1 -0
- package/dist/storage/domains/agents/inmemory.d.ts +22 -0
- package/dist/storage/domains/agents/inmemory.d.ts.map +1 -0
- package/dist/storage/domains/index.d.ts +1 -0
- package/dist/storage/domains/index.d.ts.map +1 -1
- package/dist/storage/domains/operations/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/scores/base.d.ts +2 -2
- package/dist/storage/domains/scores/base.d.ts.map +1 -1
- package/dist/storage/domains/scores/inmemory.d.ts +2 -2
- package/dist/storage/domains/scores/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +50 -34
- package/dist/storage/index.js +1 -1
- package/dist/storage/mock.d.ts +3 -2
- package/dist/storage/mock.d.ts.map +1 -1
- package/dist/storage/types.d.ts +82 -0
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/stream/base/output-format-handlers.d.ts +13 -0
- package/dist/stream/base/output-format-handlers.d.ts.map +1 -1
- package/dist/stream/index.cjs +15 -11
- package/dist/stream/index.d.ts +1 -1
- package/dist/stream/index.d.ts.map +1 -1
- package/dist/stream/index.js +2 -2
- package/dist/test-utils/llm-mock.cjs +10 -10
- package/dist/test-utils/llm-mock.js +3 -3
- package/dist/utils.cjs +22 -22
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/vector/index.cjs +2 -2
- package/dist/vector/index.js +1 -1
- package/dist/workflows/default.d.ts +2 -2
- 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.map +1 -1
- package/dist/workflows/handlers/control-flow.d.ts.map +1 -1
- package/dist/workflows/handlers/step.d.ts.map +1 -1
- package/dist/workflows/index.cjs +24 -20
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/step.d.ts +4 -3
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workflows/utils.d.ts +10 -1
- package/dist/workflows/utils.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +3 -3
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/llm/model/provider-types.generated.d.ts +180 -1
- package/dist/chunk-26YAGTXK.cjs.map +0 -1
- package/dist/chunk-3EYBRHB2.cjs.map +0 -1
- package/dist/chunk-EPMSC67U.js.map +0 -1
- package/dist/chunk-FNSFXWDN.js.map +0 -1
- package/dist/chunk-G32WDDGV.js.map +0 -1
- package/dist/chunk-GZ6MCDK2.js.map +0 -1
- package/dist/chunk-M7CQULF7.cjs.map +0 -1
- package/dist/chunk-PJ7AYWAX.cjs.map +0 -1
- package/dist/chunk-POM7FCH5.js.map +0 -1
- package/dist/chunk-RBBEMTMA.cjs.map +0 -1
- package/dist/chunk-TQB2HMEC.cjs.map +0 -1
- package/dist/chunk-URMN7TTH.cjs.map +0 -1
- package/dist/chunk-Z4Y554NX.js.map +0 -1
- package/dist/chunk-ZUWJCGLM.js.map +0 -1
- package/dist/models-dev-6GD3644V.js +0 -3
- package/dist/models-dev-IUQBXJSS.cjs +0 -12
- package/dist/provider-registry-7IFOXWPR.cjs +0 -40
- package/dist/provider-registry-ZTMZMTVV.js +0 -3
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkDWB7SBVC_cjs = require('./chunk-DWB7SBVC.cjs');
|
|
4
|
+
var chunkF77YTHXI_cjs = require('./chunk-F77YTHXI.cjs');
|
|
5
5
|
var chunk4D4KB75Y_cjs = require('./chunk-4D4KB75Y.cjs');
|
|
6
|
-
var
|
|
6
|
+
var chunkXMT5T4F2_cjs = require('./chunk-XMT5T4F2.cjs');
|
|
7
7
|
var chunk6BJ7XHRH_cjs = require('./chunk-6BJ7XHRH.cjs');
|
|
8
8
|
var chunkMR7ZWBL6_cjs = require('./chunk-MR7ZWBL6.cjs');
|
|
9
|
-
var
|
|
9
|
+
var chunkUVM27J4A_cjs = require('./chunk-UVM27J4A.cjs');
|
|
10
10
|
var chunkTWH4PTDG_cjs = require('./chunk-TWH4PTDG.cjs');
|
|
11
11
|
var chunkUIGRFDO6_cjs = require('./chunk-UIGRFDO6.cjs');
|
|
12
12
|
var chunkAF74UXR5_cjs = require('./chunk-AF74UXR5.cjs');
|
|
@@ -139,7 +139,7 @@ function createOnScorerHook(mastra) {
|
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
141
|
async function validateAndSaveScore(storage, payload) {
|
|
142
|
-
const payloadToSave =
|
|
142
|
+
const payloadToSave = chunkF77YTHXI_cjs.saveScorePayloadSchema.parse(payload);
|
|
143
143
|
await storage?.saveScore(payloadToSave);
|
|
144
144
|
}
|
|
145
145
|
async function findScorer(mastra, entityId, entityType, scorerId) {
|
|
@@ -193,6 +193,7 @@ var Mastra = class {
|
|
|
193
193
|
#scorers;
|
|
194
194
|
#tools;
|
|
195
195
|
#processors;
|
|
196
|
+
#memory;
|
|
196
197
|
#server;
|
|
197
198
|
#serverAdapter;
|
|
198
199
|
#mcpServers;
|
|
@@ -312,7 +313,7 @@ var Mastra = class {
|
|
|
312
313
|
this.#events[topic] = config?.events?.[topic] ?? [];
|
|
313
314
|
}
|
|
314
315
|
}
|
|
315
|
-
const workflowEventProcessor = new
|
|
316
|
+
const workflowEventProcessor = new chunkDWB7SBVC_cjs.WorkflowEventProcessor({ mastra: this });
|
|
316
317
|
const workflowEventCb = async (event, cb) => {
|
|
317
318
|
try {
|
|
318
319
|
await workflowEventProcessor.process(event, cb);
|
|
@@ -340,7 +341,7 @@ var Mastra = class {
|
|
|
340
341
|
this.#idGenerator = config?.idGenerator;
|
|
341
342
|
let storage = config?.storage;
|
|
342
343
|
if (storage) {
|
|
343
|
-
storage =
|
|
344
|
+
storage = chunkXMT5T4F2_cjs.augmentWithInit(storage);
|
|
344
345
|
}
|
|
345
346
|
if (config?.observability) {
|
|
346
347
|
if (typeof config.observability.getDefaultInstance === "function") {
|
|
@@ -350,10 +351,10 @@ var Mastra = class {
|
|
|
350
351
|
this.#logger?.warn(
|
|
351
352
|
'Observability configuration error: Expected an Observability instance, but received a config object. Import and instantiate: import { Observability } from "@mastra/observability"; then pass: observability: new Observability({ default: { enabled: true } }). Observability has been disabled.'
|
|
352
353
|
);
|
|
353
|
-
this.#observability = new
|
|
354
|
+
this.#observability = new chunkUVM27J4A_cjs.NoOpObservability();
|
|
354
355
|
}
|
|
355
356
|
} else {
|
|
356
|
-
this.#observability = new
|
|
357
|
+
this.#observability = new chunkUVM27J4A_cjs.NoOpObservability();
|
|
357
358
|
}
|
|
358
359
|
this.#storage = storage;
|
|
359
360
|
this.#vectors = {};
|
|
@@ -363,6 +364,7 @@ var Mastra = class {
|
|
|
363
364
|
this.#scorers = {};
|
|
364
365
|
this.#tools = {};
|
|
365
366
|
this.#processors = {};
|
|
367
|
+
this.#memory = {};
|
|
366
368
|
this.#workflows = {};
|
|
367
369
|
this.#gateways = {};
|
|
368
370
|
if (config?.tools) {
|
|
@@ -379,6 +381,13 @@ var Mastra = class {
|
|
|
379
381
|
}
|
|
380
382
|
});
|
|
381
383
|
}
|
|
384
|
+
if (config?.memory) {
|
|
385
|
+
Object.entries(config.memory).forEach(([key, memory]) => {
|
|
386
|
+
if (memory != null) {
|
|
387
|
+
this.addMemory(memory, key);
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
}
|
|
382
391
|
if (config?.vectors) {
|
|
383
392
|
Object.entries(config.vectors).forEach(([key, vector]) => {
|
|
384
393
|
if (vector != null) {
|
|
@@ -549,6 +558,241 @@ var Mastra = class {
|
|
|
549
558
|
listAgents() {
|
|
550
559
|
return this.#agents;
|
|
551
560
|
}
|
|
561
|
+
async getStoredAgentById(id, options) {
|
|
562
|
+
const storage = this.#storage;
|
|
563
|
+
if (!storage) {
|
|
564
|
+
const error = new chunkTWH4PTDG_cjs.MastraError({
|
|
565
|
+
id: "MASTRA_GET_STORED_AGENT_STORAGE_NOT_CONFIGURED",
|
|
566
|
+
domain: "MASTRA" /* MASTRA */,
|
|
567
|
+
category: "USER" /* USER */,
|
|
568
|
+
text: "Storage is not configured",
|
|
569
|
+
details: { status: 400 }
|
|
570
|
+
});
|
|
571
|
+
this.#logger?.trackException(error);
|
|
572
|
+
throw error;
|
|
573
|
+
}
|
|
574
|
+
if (!storage.supports.agents) {
|
|
575
|
+
const error = new chunkTWH4PTDG_cjs.MastraError({
|
|
576
|
+
id: "MASTRA_GET_STORED_AGENT_NOT_SUPPORTED",
|
|
577
|
+
domain: "MASTRA" /* MASTRA */,
|
|
578
|
+
category: "USER" /* USER */,
|
|
579
|
+
text: "Storage does not support agents",
|
|
580
|
+
details: { status: 400 }
|
|
581
|
+
});
|
|
582
|
+
this.#logger?.trackException(error);
|
|
583
|
+
throw error;
|
|
584
|
+
}
|
|
585
|
+
const storedAgent = await storage.getAgentById({ id });
|
|
586
|
+
if (!storedAgent) {
|
|
587
|
+
return null;
|
|
588
|
+
}
|
|
589
|
+
if (options?.raw) {
|
|
590
|
+
return storedAgent;
|
|
591
|
+
}
|
|
592
|
+
return this.#createAgentFromStoredConfig(storedAgent);
|
|
593
|
+
}
|
|
594
|
+
async listStoredAgents(args) {
|
|
595
|
+
const storage = this.#storage;
|
|
596
|
+
if (!storage) {
|
|
597
|
+
const error = new chunkTWH4PTDG_cjs.MastraError({
|
|
598
|
+
id: "MASTRA_LIST_STORED_AGENTS_STORAGE_NOT_CONFIGURED",
|
|
599
|
+
domain: "MASTRA" /* MASTRA */,
|
|
600
|
+
category: "USER" /* USER */,
|
|
601
|
+
text: "Storage is not configured",
|
|
602
|
+
details: { status: 400 }
|
|
603
|
+
});
|
|
604
|
+
this.#logger?.trackException(error);
|
|
605
|
+
throw error;
|
|
606
|
+
}
|
|
607
|
+
if (!storage.supports.agents) {
|
|
608
|
+
const error = new chunkTWH4PTDG_cjs.MastraError({
|
|
609
|
+
id: "MASTRA_LIST_STORED_AGENTS_NOT_SUPPORTED",
|
|
610
|
+
domain: "MASTRA" /* MASTRA */,
|
|
611
|
+
category: "USER" /* USER */,
|
|
612
|
+
text: "Storage does not support agents",
|
|
613
|
+
details: { status: 400 }
|
|
614
|
+
});
|
|
615
|
+
this.#logger?.trackException(error);
|
|
616
|
+
throw error;
|
|
617
|
+
}
|
|
618
|
+
const result = await storage.listAgents({
|
|
619
|
+
page: args?.page,
|
|
620
|
+
perPage: args?.perPage,
|
|
621
|
+
orderBy: args?.orderBy
|
|
622
|
+
});
|
|
623
|
+
if (args?.raw) {
|
|
624
|
+
return result;
|
|
625
|
+
}
|
|
626
|
+
const agents = result.agents.map((storedAgent) => this.#createAgentFromStoredConfig(storedAgent));
|
|
627
|
+
return {
|
|
628
|
+
agents,
|
|
629
|
+
total: result.total,
|
|
630
|
+
page: result.page,
|
|
631
|
+
perPage: result.perPage,
|
|
632
|
+
hasMore: result.hasMore
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Creates an Agent instance from a stored agent configuration.
|
|
637
|
+
* @private
|
|
638
|
+
*/
|
|
639
|
+
#createAgentFromStoredConfig(storedAgent) {
|
|
640
|
+
const modelConfig = storedAgent.model;
|
|
641
|
+
if (!modelConfig.provider || !modelConfig.name) {
|
|
642
|
+
throw new chunkTWH4PTDG_cjs.MastraError({
|
|
643
|
+
id: "MASTRA_STORED_AGENT_INVALID_MODEL",
|
|
644
|
+
domain: "MASTRA" /* MASTRA */,
|
|
645
|
+
category: "USER" /* USER */,
|
|
646
|
+
text: `Stored agent "${storedAgent.id}" has invalid model configuration. Both provider and name are required.`,
|
|
647
|
+
details: { agentId: storedAgent.id, model: JSON.stringify(storedAgent.model) }
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
const model = `${modelConfig.provider}/${modelConfig.name}`;
|
|
651
|
+
const tools = this.#resolveStoredTools(storedAgent.tools);
|
|
652
|
+
const workflows = this.#resolveStoredWorkflows(storedAgent.workflows);
|
|
653
|
+
const agents = this.#resolveStoredAgents(storedAgent.agents);
|
|
654
|
+
const memory = this.#resolveStoredMemory(storedAgent.memory);
|
|
655
|
+
const scorers = this.#resolveStoredScorers(storedAgent.scorers);
|
|
656
|
+
const agent = new chunkXMT5T4F2_cjs.Agent({
|
|
657
|
+
id: storedAgent.id,
|
|
658
|
+
name: storedAgent.name,
|
|
659
|
+
description: storedAgent.description,
|
|
660
|
+
instructions: storedAgent.instructions,
|
|
661
|
+
model,
|
|
662
|
+
tools,
|
|
663
|
+
workflows,
|
|
664
|
+
agents,
|
|
665
|
+
memory,
|
|
666
|
+
scorers,
|
|
667
|
+
defaultOptions: storedAgent.defaultOptions
|
|
668
|
+
});
|
|
669
|
+
agent.__setLogger(this.#logger);
|
|
670
|
+
agent.__registerMastra(this);
|
|
671
|
+
agent.__registerPrimitives({
|
|
672
|
+
logger: this.getLogger(),
|
|
673
|
+
storage: this.getStorage(),
|
|
674
|
+
agents: this.#agents,
|
|
675
|
+
tts: this.#tts,
|
|
676
|
+
vectors: this.#vectors
|
|
677
|
+
});
|
|
678
|
+
return agent;
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Resolves tool references from stored configuration to actual tool instances.
|
|
682
|
+
* @private
|
|
683
|
+
*/
|
|
684
|
+
#resolveStoredTools(storedTools) {
|
|
685
|
+
if (!storedTools || storedTools.length === 0) {
|
|
686
|
+
return {};
|
|
687
|
+
}
|
|
688
|
+
const resolvedTools = {};
|
|
689
|
+
const registeredTools = this.#tools;
|
|
690
|
+
for (const toolKey of storedTools) {
|
|
691
|
+
if (registeredTools && registeredTools[toolKey]) {
|
|
692
|
+
resolvedTools[toolKey] = registeredTools[toolKey];
|
|
693
|
+
} else {
|
|
694
|
+
this.#logger?.warn(`Tool "${toolKey}" referenced in stored agent but not registered in Mastra`);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
return resolvedTools;
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Resolves workflow references from stored configuration to actual workflow instances.
|
|
701
|
+
* @private
|
|
702
|
+
*/
|
|
703
|
+
#resolveStoredWorkflows(storedWorkflows) {
|
|
704
|
+
if (!storedWorkflows || storedWorkflows.length === 0) {
|
|
705
|
+
return {};
|
|
706
|
+
}
|
|
707
|
+
const resolvedWorkflows = {};
|
|
708
|
+
for (const workflowKey of storedWorkflows) {
|
|
709
|
+
try {
|
|
710
|
+
const workflow = this.getWorkflow(workflowKey);
|
|
711
|
+
resolvedWorkflows[workflowKey] = workflow;
|
|
712
|
+
} catch {
|
|
713
|
+
try {
|
|
714
|
+
const workflow = this.getWorkflowById(workflowKey);
|
|
715
|
+
resolvedWorkflows[workflowKey] = workflow;
|
|
716
|
+
} catch {
|
|
717
|
+
this.#logger?.warn(`Workflow "${workflowKey}" referenced in stored agent but not registered in Mastra`);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
return resolvedWorkflows;
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Resolves agent references from stored configuration to actual agent instances.
|
|
725
|
+
* @private
|
|
726
|
+
*/
|
|
727
|
+
#resolveStoredAgents(storedAgents) {
|
|
728
|
+
if (!storedAgents || storedAgents.length === 0) {
|
|
729
|
+
return {};
|
|
730
|
+
}
|
|
731
|
+
const resolvedAgents = {};
|
|
732
|
+
for (const agentKey of storedAgents) {
|
|
733
|
+
try {
|
|
734
|
+
const agent = this.getAgent(agentKey);
|
|
735
|
+
resolvedAgents[agentKey] = agent;
|
|
736
|
+
} catch {
|
|
737
|
+
try {
|
|
738
|
+
const agent = this.getAgentById(agentKey);
|
|
739
|
+
resolvedAgents[agentKey] = agent;
|
|
740
|
+
} catch {
|
|
741
|
+
this.#logger?.warn(`Agent "${agentKey}" referenced in stored agent but not registered in Mastra`);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
return resolvedAgents;
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Resolves memory reference from stored configuration to actual memory instance.
|
|
749
|
+
* @private
|
|
750
|
+
*/
|
|
751
|
+
#resolveStoredMemory(storedMemory) {
|
|
752
|
+
if (!storedMemory) {
|
|
753
|
+
return void 0;
|
|
754
|
+
}
|
|
755
|
+
try {
|
|
756
|
+
return this.getMemory(storedMemory);
|
|
757
|
+
} catch {
|
|
758
|
+
try {
|
|
759
|
+
return this.getMemoryById(storedMemory);
|
|
760
|
+
} catch {
|
|
761
|
+
this.#logger?.warn(`Memory "${storedMemory}" referenced in stored agent but not registered in Mastra`);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
return void 0;
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Resolves scorer references from stored configuration to actual scorer instances.
|
|
768
|
+
* @private
|
|
769
|
+
*/
|
|
770
|
+
#resolveStoredScorers(storedScorers) {
|
|
771
|
+
if (!storedScorers) {
|
|
772
|
+
return void 0;
|
|
773
|
+
}
|
|
774
|
+
const resolvedScorers = {};
|
|
775
|
+
for (const [scorerKey, scorerConfig] of Object.entries(storedScorers)) {
|
|
776
|
+
try {
|
|
777
|
+
const scorer = this.getScorer(scorerKey);
|
|
778
|
+
resolvedScorers[scorerKey] = {
|
|
779
|
+
scorer,
|
|
780
|
+
sampling: scorerConfig.sampling
|
|
781
|
+
};
|
|
782
|
+
} catch {
|
|
783
|
+
try {
|
|
784
|
+
const scorer = this.getScorerById(scorerKey);
|
|
785
|
+
resolvedScorers[scorerKey] = {
|
|
786
|
+
scorer,
|
|
787
|
+
sampling: scorerConfig.sampling
|
|
788
|
+
};
|
|
789
|
+
} catch {
|
|
790
|
+
this.#logger?.warn(`Scorer "${scorerKey}" referenced in stored agent but not registered in Mastra`);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
return Object.keys(resolvedScorers).length > 0 ? resolvedScorers : void 0;
|
|
795
|
+
}
|
|
552
796
|
/**
|
|
553
797
|
* Adds a new agent to the Mastra instance.
|
|
554
798
|
*
|
|
@@ -1376,6 +1620,131 @@ var Mastra = class {
|
|
|
1376
1620
|
}
|
|
1377
1621
|
processors[processorKey] = processor;
|
|
1378
1622
|
}
|
|
1623
|
+
/**
|
|
1624
|
+
* Retrieves a registered memory instance by its registration key.
|
|
1625
|
+
*
|
|
1626
|
+
* @throws {MastraError} When the memory instance with the specified key is not found
|
|
1627
|
+
*
|
|
1628
|
+
* @example
|
|
1629
|
+
* ```typescript
|
|
1630
|
+
* const mastra = new Mastra({
|
|
1631
|
+
* memory: {
|
|
1632
|
+
* chat: new Memory({ storage })
|
|
1633
|
+
* }
|
|
1634
|
+
* });
|
|
1635
|
+
*
|
|
1636
|
+
* const chatMemory = mastra.getMemory('chat');
|
|
1637
|
+
* ```
|
|
1638
|
+
*/
|
|
1639
|
+
getMemory(name) {
|
|
1640
|
+
if (!this.#memory || !this.#memory[name]) {
|
|
1641
|
+
const error = new chunkTWH4PTDG_cjs.MastraError({
|
|
1642
|
+
id: "MASTRA_GET_MEMORY_BY_KEY_NOT_FOUND",
|
|
1643
|
+
domain: "MASTRA" /* MASTRA */,
|
|
1644
|
+
category: "USER" /* USER */,
|
|
1645
|
+
text: `Memory with key ${String(name)} not found`,
|
|
1646
|
+
details: {
|
|
1647
|
+
status: 404,
|
|
1648
|
+
memoryKey: String(name),
|
|
1649
|
+
memory: Object.keys(this.#memory ?? {}).join(", ")
|
|
1650
|
+
}
|
|
1651
|
+
});
|
|
1652
|
+
this.#logger?.trackException(error);
|
|
1653
|
+
throw error;
|
|
1654
|
+
}
|
|
1655
|
+
return this.#memory[name];
|
|
1656
|
+
}
|
|
1657
|
+
/**
|
|
1658
|
+
* Retrieves a registered memory instance by its ID.
|
|
1659
|
+
*
|
|
1660
|
+
* Searches through all registered memory instances and returns the one whose ID matches.
|
|
1661
|
+
*
|
|
1662
|
+
* @throws {MastraError} When no memory instance with the specified ID is found
|
|
1663
|
+
*
|
|
1664
|
+
* @example
|
|
1665
|
+
* ```typescript
|
|
1666
|
+
* const mastra = new Mastra({
|
|
1667
|
+
* memory: {
|
|
1668
|
+
* chat: new Memory({ id: 'chat-memory', storage })
|
|
1669
|
+
* }
|
|
1670
|
+
* });
|
|
1671
|
+
*
|
|
1672
|
+
* const memory = mastra.getMemoryById('chat-memory');
|
|
1673
|
+
* ```
|
|
1674
|
+
*/
|
|
1675
|
+
getMemoryById(id) {
|
|
1676
|
+
const allMemory = this.#memory;
|
|
1677
|
+
if (allMemory) {
|
|
1678
|
+
for (const [, memory] of Object.entries(allMemory)) {
|
|
1679
|
+
if (memory.id === id) {
|
|
1680
|
+
return memory;
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
const error = new chunkTWH4PTDG_cjs.MastraError({
|
|
1685
|
+
id: "MASTRA_GET_MEMORY_BY_ID_NOT_FOUND",
|
|
1686
|
+
domain: "MASTRA" /* MASTRA */,
|
|
1687
|
+
category: "USER" /* USER */,
|
|
1688
|
+
text: `Memory with id ${id} not found`,
|
|
1689
|
+
details: {
|
|
1690
|
+
status: 404,
|
|
1691
|
+
memoryId: id,
|
|
1692
|
+
availableIds: Object.values(allMemory ?? {}).map((m) => m.id).join(", ")
|
|
1693
|
+
}
|
|
1694
|
+
});
|
|
1695
|
+
this.#logger?.trackException(error);
|
|
1696
|
+
throw error;
|
|
1697
|
+
}
|
|
1698
|
+
/**
|
|
1699
|
+
* Returns all registered memory instances as a record keyed by their names.
|
|
1700
|
+
*
|
|
1701
|
+
* @example
|
|
1702
|
+
* ```typescript
|
|
1703
|
+
* const mastra = new Mastra({
|
|
1704
|
+
* memory: {
|
|
1705
|
+
* chat: new Memory({ storage }),
|
|
1706
|
+
* longTerm: new Memory({ storage })
|
|
1707
|
+
* }
|
|
1708
|
+
* });
|
|
1709
|
+
*
|
|
1710
|
+
* const allMemory = mastra.listMemory();
|
|
1711
|
+
* console.log(Object.keys(allMemory)); // ['chat', 'longTerm']
|
|
1712
|
+
* ```
|
|
1713
|
+
*/
|
|
1714
|
+
listMemory() {
|
|
1715
|
+
return this.#memory;
|
|
1716
|
+
}
|
|
1717
|
+
/**
|
|
1718
|
+
* Adds a new memory instance to the Mastra instance.
|
|
1719
|
+
*
|
|
1720
|
+
* This method allows dynamic registration of memory instances after the Mastra instance
|
|
1721
|
+
* has been created.
|
|
1722
|
+
*
|
|
1723
|
+
* @example
|
|
1724
|
+
* ```typescript
|
|
1725
|
+
* const mastra = new Mastra();
|
|
1726
|
+
* const chatMemory = new Memory({
|
|
1727
|
+
* id: 'chat-memory',
|
|
1728
|
+
* storage: mastra.getStorage()
|
|
1729
|
+
* });
|
|
1730
|
+
* mastra.addMemory(chatMemory); // Uses memory.id as key
|
|
1731
|
+
* // or
|
|
1732
|
+
* mastra.addMemory(chatMemory, 'customKey'); // Uses custom key
|
|
1733
|
+
* ```
|
|
1734
|
+
*/
|
|
1735
|
+
addMemory(memory, key) {
|
|
1736
|
+
if (!memory) {
|
|
1737
|
+
throw createUndefinedPrimitiveError("memory", memory, key);
|
|
1738
|
+
}
|
|
1739
|
+
const memoryKey = key || memory.id;
|
|
1740
|
+
const memoryRegistry = this.#memory;
|
|
1741
|
+
if (memoryRegistry[memoryKey]) {
|
|
1742
|
+
const logger = this.getLogger();
|
|
1743
|
+
logger.debug(`Memory with key ${memoryKey} already exists. Skipping addition.`);
|
|
1744
|
+
return;
|
|
1745
|
+
}
|
|
1746
|
+
memoryRegistry[memoryKey] = memory;
|
|
1747
|
+
}
|
|
1379
1748
|
/**
|
|
1380
1749
|
* Returns all registered workflows as a record keyed by their IDs.
|
|
1381
1750
|
*
|
|
@@ -1472,7 +1841,7 @@ var Mastra = class {
|
|
|
1472
1841
|
* ```
|
|
1473
1842
|
*/
|
|
1474
1843
|
setStorage(storage) {
|
|
1475
|
-
this.#storage =
|
|
1844
|
+
this.#storage = chunkXMT5T4F2_cjs.augmentWithInit(storage);
|
|
1476
1845
|
}
|
|
1477
1846
|
setLogger({ logger }) {
|
|
1478
1847
|
this.#logger = logger;
|
|
@@ -2134,7 +2503,7 @@ var Mastra = class {
|
|
|
2134
2503
|
if (process.env.MASTRA_DEV !== "true" && process.env.MASTRA_DEV !== "1") {
|
|
2135
2504
|
return;
|
|
2136
2505
|
}
|
|
2137
|
-
import('./provider-registry-
|
|
2506
|
+
import('./provider-registry-Q6T32VC5.cjs').then(async ({ GatewayRegistry }) => {
|
|
2138
2507
|
const registry = GatewayRegistry.getInstance();
|
|
2139
2508
|
const customGateways = Object.values(this.#gateways || {});
|
|
2140
2509
|
registry.registerCustomGateways(customGateways);
|
|
@@ -2188,5 +2557,5 @@ var Mastra = class {
|
|
|
2188
2557
|
};
|
|
2189
2558
|
|
|
2190
2559
|
exports.Mastra = Mastra;
|
|
2191
|
-
//# sourceMappingURL=chunk-
|
|
2192
|
-
//# sourceMappingURL=chunk-
|
|
2560
|
+
//# sourceMappingURL=chunk-3DRGAKUH.cjs.map
|
|
2561
|
+
//# sourceMappingURL=chunk-3DRGAKUH.cjs.map
|