@mastra/core 1.0.0-beta.8 → 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 +57 -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-Y7YCQDML.cjs → chunk-3DRGAKUH.cjs} +382 -13
- package/dist/chunk-3DRGAKUH.cjs.map +1 -0
- package/dist/{chunk-RWT3XPKO.js → chunk-4GLDYGNN.js} +3 -3
- package/dist/{chunk-RWT3XPKO.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-KBXFAF37.cjs → chunk-7S7TLMTS.cjs} +287 -10
- package/dist/chunk-7S7TLMTS.cjs.map +1 -0
- package/dist/{chunk-QHJ7YVNX.js → chunk-A4C3AGVS.js} +5 -5
- package/dist/{chunk-QHJ7YVNX.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-EDNHZZUP.js → chunk-ARSSSQQP.js} +69 -11
- package/dist/chunk-ARSSSQQP.js.map +1 -0
- package/dist/{chunk-6BYHQ52F.cjs → chunk-CKRWR5DS.cjs} +15 -15
- package/dist/{chunk-6BYHQ52F.cjs.map → chunk-CKRWR5DS.cjs.map} +1 -1
- package/dist/{chunk-SD2BDUJ6.cjs → chunk-DWB7SBVC.cjs} +23 -23
- package/dist/{chunk-SD2BDUJ6.cjs.map → chunk-DWB7SBVC.cjs.map} +1 -1
- package/dist/{chunk-VWC5AUOQ.cjs → chunk-EGXQVF75.cjs} +372 -6
- package/dist/chunk-EGXQVF75.cjs.map +1 -0
- package/dist/{chunk-QYNZAPFE.cjs → chunk-F77YTHXI.cjs} +4 -4
- package/dist/{chunk-QYNZAPFE.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-SPIUKQDK.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-7PXCGGMO.js → chunk-QTEIZ2XG.js} +3 -3
- package/dist/{chunk-7PXCGGMO.js.map → chunk-QTEIZ2XG.js.map} +1 -1
- package/dist/{chunk-Y5SFNZUK.cjs → chunk-RIG4JP3V.cjs} +11 -11
- package/dist/{chunk-Y5SFNZUK.cjs.map → chunk-RIG4JP3V.cjs.map} +1 -1
- package/dist/{chunk-GW7BNMGA.js → chunk-SLX3NVAC.js} +4 -4
- package/dist/{chunk-GW7BNMGA.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-QDIYYAA4.js → chunk-VQ3FTSRC.js} +371 -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-HP6TRJ2Q.cjs → chunk-XMT5T4F2.cjs} +111 -52
- package/dist/chunk-XMT5T4F2.cjs.map +1 -0
- package/dist/{chunk-HDMH5IDV.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 +2 -2
- 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 +176 -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-A5QZFI2X.js.map → provider-registry-FM3IVY6C.js.map} +1 -1
- package/dist/provider-registry-Q6T32VC5.cjs +40 -0
- package/dist/{provider-registry-V32PGH6F.cjs.map → provider-registry-Q6T32VC5.cjs.map} +1 -1
- package/dist/provider-registry.json +368 -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/index.cjs +50 -34
- package/dist/storage/index.js +1 -1
- package/dist/storage/mock.d.ts +1 -0
- 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/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/index.cjs +21 -21
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/workflow.d.ts +2 -2
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/llm/model/provider-types.generated.d.ts +176 -1
- package/dist/chunk-3EYBRHB2.cjs.map +0 -1
- package/dist/chunk-EDNHZZUP.js.map +0 -1
- package/dist/chunk-FNSFXWDN.js.map +0 -1
- package/dist/chunk-HDMH5IDV.js.map +0 -1
- package/dist/chunk-HP6TRJ2Q.cjs.map +0 -1
- package/dist/chunk-KBXFAF37.cjs.map +0 -1
- package/dist/chunk-QDIYYAA4.js.map +0 -1
- package/dist/chunk-SPIUKQDK.js.map +0 -1
- package/dist/chunk-TQB2HMEC.cjs.map +0 -1
- package/dist/chunk-VWC5AUOQ.cjs.map +0 -1
- package/dist/chunk-Y7YCQDML.cjs.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-A5QZFI2X.js +0 -3
- package/dist/provider-registry-V32PGH6F.cjs +0 -40
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { WorkflowEventProcessor } from './chunk-
|
|
2
|
-
import { saveScorePayloadSchema } from './chunk-
|
|
1
|
+
import { WorkflowEventProcessor } from './chunk-QTEIZ2XG.js';
|
|
2
|
+
import { saveScorePayloadSchema } from './chunk-4GLDYGNN.js';
|
|
3
3
|
import { PubSub } from './chunk-BVUMKER5.js';
|
|
4
|
-
import { augmentWithInit } from './chunk-
|
|
4
|
+
import { augmentWithInit, Agent } from './chunk-ARSSSQQP.js';
|
|
5
5
|
import { noopLogger } from './chunk-PSCMWPLC.js';
|
|
6
6
|
import { registerHook } from './chunk-L54GIUCB.js';
|
|
7
|
-
import { NoOpObservability } from './chunk-
|
|
7
|
+
import { NoOpObservability } from './chunk-PIHOAJTA.js';
|
|
8
8
|
import { MastraError } from './chunk-JJ5O45LH.js';
|
|
9
9
|
import { InMemoryServerCache } from './chunk-3CKZSDTQ.js';
|
|
10
10
|
import { ConsoleLogger, LogLevel } from './chunk-NRUZYMHE.js';
|
|
@@ -186,6 +186,7 @@ var Mastra = class {
|
|
|
186
186
|
#scorers;
|
|
187
187
|
#tools;
|
|
188
188
|
#processors;
|
|
189
|
+
#memory;
|
|
189
190
|
#server;
|
|
190
191
|
#serverAdapter;
|
|
191
192
|
#mcpServers;
|
|
@@ -356,6 +357,7 @@ var Mastra = class {
|
|
|
356
357
|
this.#scorers = {};
|
|
357
358
|
this.#tools = {};
|
|
358
359
|
this.#processors = {};
|
|
360
|
+
this.#memory = {};
|
|
359
361
|
this.#workflows = {};
|
|
360
362
|
this.#gateways = {};
|
|
361
363
|
if (config?.tools) {
|
|
@@ -372,6 +374,13 @@ var Mastra = class {
|
|
|
372
374
|
}
|
|
373
375
|
});
|
|
374
376
|
}
|
|
377
|
+
if (config?.memory) {
|
|
378
|
+
Object.entries(config.memory).forEach(([key, memory]) => {
|
|
379
|
+
if (memory != null) {
|
|
380
|
+
this.addMemory(memory, key);
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
}
|
|
375
384
|
if (config?.vectors) {
|
|
376
385
|
Object.entries(config.vectors).forEach(([key, vector]) => {
|
|
377
386
|
if (vector != null) {
|
|
@@ -542,6 +551,241 @@ var Mastra = class {
|
|
|
542
551
|
listAgents() {
|
|
543
552
|
return this.#agents;
|
|
544
553
|
}
|
|
554
|
+
async getStoredAgentById(id, options) {
|
|
555
|
+
const storage = this.#storage;
|
|
556
|
+
if (!storage) {
|
|
557
|
+
const error = new MastraError({
|
|
558
|
+
id: "MASTRA_GET_STORED_AGENT_STORAGE_NOT_CONFIGURED",
|
|
559
|
+
domain: "MASTRA" /* MASTRA */,
|
|
560
|
+
category: "USER" /* USER */,
|
|
561
|
+
text: "Storage is not configured",
|
|
562
|
+
details: { status: 400 }
|
|
563
|
+
});
|
|
564
|
+
this.#logger?.trackException(error);
|
|
565
|
+
throw error;
|
|
566
|
+
}
|
|
567
|
+
if (!storage.supports.agents) {
|
|
568
|
+
const error = new MastraError({
|
|
569
|
+
id: "MASTRA_GET_STORED_AGENT_NOT_SUPPORTED",
|
|
570
|
+
domain: "MASTRA" /* MASTRA */,
|
|
571
|
+
category: "USER" /* USER */,
|
|
572
|
+
text: "Storage does not support agents",
|
|
573
|
+
details: { status: 400 }
|
|
574
|
+
});
|
|
575
|
+
this.#logger?.trackException(error);
|
|
576
|
+
throw error;
|
|
577
|
+
}
|
|
578
|
+
const storedAgent = await storage.getAgentById({ id });
|
|
579
|
+
if (!storedAgent) {
|
|
580
|
+
return null;
|
|
581
|
+
}
|
|
582
|
+
if (options?.raw) {
|
|
583
|
+
return storedAgent;
|
|
584
|
+
}
|
|
585
|
+
return this.#createAgentFromStoredConfig(storedAgent);
|
|
586
|
+
}
|
|
587
|
+
async listStoredAgents(args) {
|
|
588
|
+
const storage = this.#storage;
|
|
589
|
+
if (!storage) {
|
|
590
|
+
const error = new MastraError({
|
|
591
|
+
id: "MASTRA_LIST_STORED_AGENTS_STORAGE_NOT_CONFIGURED",
|
|
592
|
+
domain: "MASTRA" /* MASTRA */,
|
|
593
|
+
category: "USER" /* USER */,
|
|
594
|
+
text: "Storage is not configured",
|
|
595
|
+
details: { status: 400 }
|
|
596
|
+
});
|
|
597
|
+
this.#logger?.trackException(error);
|
|
598
|
+
throw error;
|
|
599
|
+
}
|
|
600
|
+
if (!storage.supports.agents) {
|
|
601
|
+
const error = new MastraError({
|
|
602
|
+
id: "MASTRA_LIST_STORED_AGENTS_NOT_SUPPORTED",
|
|
603
|
+
domain: "MASTRA" /* MASTRA */,
|
|
604
|
+
category: "USER" /* USER */,
|
|
605
|
+
text: "Storage does not support agents",
|
|
606
|
+
details: { status: 400 }
|
|
607
|
+
});
|
|
608
|
+
this.#logger?.trackException(error);
|
|
609
|
+
throw error;
|
|
610
|
+
}
|
|
611
|
+
const result = await storage.listAgents({
|
|
612
|
+
page: args?.page,
|
|
613
|
+
perPage: args?.perPage,
|
|
614
|
+
orderBy: args?.orderBy
|
|
615
|
+
});
|
|
616
|
+
if (args?.raw) {
|
|
617
|
+
return result;
|
|
618
|
+
}
|
|
619
|
+
const agents = result.agents.map((storedAgent) => this.#createAgentFromStoredConfig(storedAgent));
|
|
620
|
+
return {
|
|
621
|
+
agents,
|
|
622
|
+
total: result.total,
|
|
623
|
+
page: result.page,
|
|
624
|
+
perPage: result.perPage,
|
|
625
|
+
hasMore: result.hasMore
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Creates an Agent instance from a stored agent configuration.
|
|
630
|
+
* @private
|
|
631
|
+
*/
|
|
632
|
+
#createAgentFromStoredConfig(storedAgent) {
|
|
633
|
+
const modelConfig = storedAgent.model;
|
|
634
|
+
if (!modelConfig.provider || !modelConfig.name) {
|
|
635
|
+
throw new MastraError({
|
|
636
|
+
id: "MASTRA_STORED_AGENT_INVALID_MODEL",
|
|
637
|
+
domain: "MASTRA" /* MASTRA */,
|
|
638
|
+
category: "USER" /* USER */,
|
|
639
|
+
text: `Stored agent "${storedAgent.id}" has invalid model configuration. Both provider and name are required.`,
|
|
640
|
+
details: { agentId: storedAgent.id, model: JSON.stringify(storedAgent.model) }
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
const model = `${modelConfig.provider}/${modelConfig.name}`;
|
|
644
|
+
const tools = this.#resolveStoredTools(storedAgent.tools);
|
|
645
|
+
const workflows = this.#resolveStoredWorkflows(storedAgent.workflows);
|
|
646
|
+
const agents = this.#resolveStoredAgents(storedAgent.agents);
|
|
647
|
+
const memory = this.#resolveStoredMemory(storedAgent.memory);
|
|
648
|
+
const scorers = this.#resolveStoredScorers(storedAgent.scorers);
|
|
649
|
+
const agent = new Agent({
|
|
650
|
+
id: storedAgent.id,
|
|
651
|
+
name: storedAgent.name,
|
|
652
|
+
description: storedAgent.description,
|
|
653
|
+
instructions: storedAgent.instructions,
|
|
654
|
+
model,
|
|
655
|
+
tools,
|
|
656
|
+
workflows,
|
|
657
|
+
agents,
|
|
658
|
+
memory,
|
|
659
|
+
scorers,
|
|
660
|
+
defaultOptions: storedAgent.defaultOptions
|
|
661
|
+
});
|
|
662
|
+
agent.__setLogger(this.#logger);
|
|
663
|
+
agent.__registerMastra(this);
|
|
664
|
+
agent.__registerPrimitives({
|
|
665
|
+
logger: this.getLogger(),
|
|
666
|
+
storage: this.getStorage(),
|
|
667
|
+
agents: this.#agents,
|
|
668
|
+
tts: this.#tts,
|
|
669
|
+
vectors: this.#vectors
|
|
670
|
+
});
|
|
671
|
+
return agent;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Resolves tool references from stored configuration to actual tool instances.
|
|
675
|
+
* @private
|
|
676
|
+
*/
|
|
677
|
+
#resolveStoredTools(storedTools) {
|
|
678
|
+
if (!storedTools || storedTools.length === 0) {
|
|
679
|
+
return {};
|
|
680
|
+
}
|
|
681
|
+
const resolvedTools = {};
|
|
682
|
+
const registeredTools = this.#tools;
|
|
683
|
+
for (const toolKey of storedTools) {
|
|
684
|
+
if (registeredTools && registeredTools[toolKey]) {
|
|
685
|
+
resolvedTools[toolKey] = registeredTools[toolKey];
|
|
686
|
+
} else {
|
|
687
|
+
this.#logger?.warn(`Tool "${toolKey}" referenced in stored agent but not registered in Mastra`);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
return resolvedTools;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Resolves workflow references from stored configuration to actual workflow instances.
|
|
694
|
+
* @private
|
|
695
|
+
*/
|
|
696
|
+
#resolveStoredWorkflows(storedWorkflows) {
|
|
697
|
+
if (!storedWorkflows || storedWorkflows.length === 0) {
|
|
698
|
+
return {};
|
|
699
|
+
}
|
|
700
|
+
const resolvedWorkflows = {};
|
|
701
|
+
for (const workflowKey of storedWorkflows) {
|
|
702
|
+
try {
|
|
703
|
+
const workflow = this.getWorkflow(workflowKey);
|
|
704
|
+
resolvedWorkflows[workflowKey] = workflow;
|
|
705
|
+
} catch {
|
|
706
|
+
try {
|
|
707
|
+
const workflow = this.getWorkflowById(workflowKey);
|
|
708
|
+
resolvedWorkflows[workflowKey] = workflow;
|
|
709
|
+
} catch {
|
|
710
|
+
this.#logger?.warn(`Workflow "${workflowKey}" referenced in stored agent but not registered in Mastra`);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
return resolvedWorkflows;
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Resolves agent references from stored configuration to actual agent instances.
|
|
718
|
+
* @private
|
|
719
|
+
*/
|
|
720
|
+
#resolveStoredAgents(storedAgents) {
|
|
721
|
+
if (!storedAgents || storedAgents.length === 0) {
|
|
722
|
+
return {};
|
|
723
|
+
}
|
|
724
|
+
const resolvedAgents = {};
|
|
725
|
+
for (const agentKey of storedAgents) {
|
|
726
|
+
try {
|
|
727
|
+
const agent = this.getAgent(agentKey);
|
|
728
|
+
resolvedAgents[agentKey] = agent;
|
|
729
|
+
} catch {
|
|
730
|
+
try {
|
|
731
|
+
const agent = this.getAgentById(agentKey);
|
|
732
|
+
resolvedAgents[agentKey] = agent;
|
|
733
|
+
} catch {
|
|
734
|
+
this.#logger?.warn(`Agent "${agentKey}" referenced in stored agent but not registered in Mastra`);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return resolvedAgents;
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Resolves memory reference from stored configuration to actual memory instance.
|
|
742
|
+
* @private
|
|
743
|
+
*/
|
|
744
|
+
#resolveStoredMemory(storedMemory) {
|
|
745
|
+
if (!storedMemory) {
|
|
746
|
+
return void 0;
|
|
747
|
+
}
|
|
748
|
+
try {
|
|
749
|
+
return this.getMemory(storedMemory);
|
|
750
|
+
} catch {
|
|
751
|
+
try {
|
|
752
|
+
return this.getMemoryById(storedMemory);
|
|
753
|
+
} catch {
|
|
754
|
+
this.#logger?.warn(`Memory "${storedMemory}" referenced in stored agent but not registered in Mastra`);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
return void 0;
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Resolves scorer references from stored configuration to actual scorer instances.
|
|
761
|
+
* @private
|
|
762
|
+
*/
|
|
763
|
+
#resolveStoredScorers(storedScorers) {
|
|
764
|
+
if (!storedScorers) {
|
|
765
|
+
return void 0;
|
|
766
|
+
}
|
|
767
|
+
const resolvedScorers = {};
|
|
768
|
+
for (const [scorerKey, scorerConfig] of Object.entries(storedScorers)) {
|
|
769
|
+
try {
|
|
770
|
+
const scorer = this.getScorer(scorerKey);
|
|
771
|
+
resolvedScorers[scorerKey] = {
|
|
772
|
+
scorer,
|
|
773
|
+
sampling: scorerConfig.sampling
|
|
774
|
+
};
|
|
775
|
+
} catch {
|
|
776
|
+
try {
|
|
777
|
+
const scorer = this.getScorerById(scorerKey);
|
|
778
|
+
resolvedScorers[scorerKey] = {
|
|
779
|
+
scorer,
|
|
780
|
+
sampling: scorerConfig.sampling
|
|
781
|
+
};
|
|
782
|
+
} catch {
|
|
783
|
+
this.#logger?.warn(`Scorer "${scorerKey}" referenced in stored agent but not registered in Mastra`);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
return Object.keys(resolvedScorers).length > 0 ? resolvedScorers : void 0;
|
|
788
|
+
}
|
|
545
789
|
/**
|
|
546
790
|
* Adds a new agent to the Mastra instance.
|
|
547
791
|
*
|
|
@@ -1369,6 +1613,131 @@ var Mastra = class {
|
|
|
1369
1613
|
}
|
|
1370
1614
|
processors[processorKey] = processor;
|
|
1371
1615
|
}
|
|
1616
|
+
/**
|
|
1617
|
+
* Retrieves a registered memory instance by its registration key.
|
|
1618
|
+
*
|
|
1619
|
+
* @throws {MastraError} When the memory instance with the specified key is not found
|
|
1620
|
+
*
|
|
1621
|
+
* @example
|
|
1622
|
+
* ```typescript
|
|
1623
|
+
* const mastra = new Mastra({
|
|
1624
|
+
* memory: {
|
|
1625
|
+
* chat: new Memory({ storage })
|
|
1626
|
+
* }
|
|
1627
|
+
* });
|
|
1628
|
+
*
|
|
1629
|
+
* const chatMemory = mastra.getMemory('chat');
|
|
1630
|
+
* ```
|
|
1631
|
+
*/
|
|
1632
|
+
getMemory(name) {
|
|
1633
|
+
if (!this.#memory || !this.#memory[name]) {
|
|
1634
|
+
const error = new MastraError({
|
|
1635
|
+
id: "MASTRA_GET_MEMORY_BY_KEY_NOT_FOUND",
|
|
1636
|
+
domain: "MASTRA" /* MASTRA */,
|
|
1637
|
+
category: "USER" /* USER */,
|
|
1638
|
+
text: `Memory with key ${String(name)} not found`,
|
|
1639
|
+
details: {
|
|
1640
|
+
status: 404,
|
|
1641
|
+
memoryKey: String(name),
|
|
1642
|
+
memory: Object.keys(this.#memory ?? {}).join(", ")
|
|
1643
|
+
}
|
|
1644
|
+
});
|
|
1645
|
+
this.#logger?.trackException(error);
|
|
1646
|
+
throw error;
|
|
1647
|
+
}
|
|
1648
|
+
return this.#memory[name];
|
|
1649
|
+
}
|
|
1650
|
+
/**
|
|
1651
|
+
* Retrieves a registered memory instance by its ID.
|
|
1652
|
+
*
|
|
1653
|
+
* Searches through all registered memory instances and returns the one whose ID matches.
|
|
1654
|
+
*
|
|
1655
|
+
* @throws {MastraError} When no memory instance with the specified ID is found
|
|
1656
|
+
*
|
|
1657
|
+
* @example
|
|
1658
|
+
* ```typescript
|
|
1659
|
+
* const mastra = new Mastra({
|
|
1660
|
+
* memory: {
|
|
1661
|
+
* chat: new Memory({ id: 'chat-memory', storage })
|
|
1662
|
+
* }
|
|
1663
|
+
* });
|
|
1664
|
+
*
|
|
1665
|
+
* const memory = mastra.getMemoryById('chat-memory');
|
|
1666
|
+
* ```
|
|
1667
|
+
*/
|
|
1668
|
+
getMemoryById(id) {
|
|
1669
|
+
const allMemory = this.#memory;
|
|
1670
|
+
if (allMemory) {
|
|
1671
|
+
for (const [, memory] of Object.entries(allMemory)) {
|
|
1672
|
+
if (memory.id === id) {
|
|
1673
|
+
return memory;
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
const error = new MastraError({
|
|
1678
|
+
id: "MASTRA_GET_MEMORY_BY_ID_NOT_FOUND",
|
|
1679
|
+
domain: "MASTRA" /* MASTRA */,
|
|
1680
|
+
category: "USER" /* USER */,
|
|
1681
|
+
text: `Memory with id ${id} not found`,
|
|
1682
|
+
details: {
|
|
1683
|
+
status: 404,
|
|
1684
|
+
memoryId: id,
|
|
1685
|
+
availableIds: Object.values(allMemory ?? {}).map((m) => m.id).join(", ")
|
|
1686
|
+
}
|
|
1687
|
+
});
|
|
1688
|
+
this.#logger?.trackException(error);
|
|
1689
|
+
throw error;
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1692
|
+
* Returns all registered memory instances as a record keyed by their names.
|
|
1693
|
+
*
|
|
1694
|
+
* @example
|
|
1695
|
+
* ```typescript
|
|
1696
|
+
* const mastra = new Mastra({
|
|
1697
|
+
* memory: {
|
|
1698
|
+
* chat: new Memory({ storage }),
|
|
1699
|
+
* longTerm: new Memory({ storage })
|
|
1700
|
+
* }
|
|
1701
|
+
* });
|
|
1702
|
+
*
|
|
1703
|
+
* const allMemory = mastra.listMemory();
|
|
1704
|
+
* console.log(Object.keys(allMemory)); // ['chat', 'longTerm']
|
|
1705
|
+
* ```
|
|
1706
|
+
*/
|
|
1707
|
+
listMemory() {
|
|
1708
|
+
return this.#memory;
|
|
1709
|
+
}
|
|
1710
|
+
/**
|
|
1711
|
+
* Adds a new memory instance to the Mastra instance.
|
|
1712
|
+
*
|
|
1713
|
+
* This method allows dynamic registration of memory instances after the Mastra instance
|
|
1714
|
+
* has been created.
|
|
1715
|
+
*
|
|
1716
|
+
* @example
|
|
1717
|
+
* ```typescript
|
|
1718
|
+
* const mastra = new Mastra();
|
|
1719
|
+
* const chatMemory = new Memory({
|
|
1720
|
+
* id: 'chat-memory',
|
|
1721
|
+
* storage: mastra.getStorage()
|
|
1722
|
+
* });
|
|
1723
|
+
* mastra.addMemory(chatMemory); // Uses memory.id as key
|
|
1724
|
+
* // or
|
|
1725
|
+
* mastra.addMemory(chatMemory, 'customKey'); // Uses custom key
|
|
1726
|
+
* ```
|
|
1727
|
+
*/
|
|
1728
|
+
addMemory(memory, key) {
|
|
1729
|
+
if (!memory) {
|
|
1730
|
+
throw createUndefinedPrimitiveError("memory", memory, key);
|
|
1731
|
+
}
|
|
1732
|
+
const memoryKey = key || memory.id;
|
|
1733
|
+
const memoryRegistry = this.#memory;
|
|
1734
|
+
if (memoryRegistry[memoryKey]) {
|
|
1735
|
+
const logger = this.getLogger();
|
|
1736
|
+
logger.debug(`Memory with key ${memoryKey} already exists. Skipping addition.`);
|
|
1737
|
+
return;
|
|
1738
|
+
}
|
|
1739
|
+
memoryRegistry[memoryKey] = memory;
|
|
1740
|
+
}
|
|
1372
1741
|
/**
|
|
1373
1742
|
* Returns all registered workflows as a record keyed by their IDs.
|
|
1374
1743
|
*
|
|
@@ -2127,7 +2496,7 @@ var Mastra = class {
|
|
|
2127
2496
|
if (process.env.MASTRA_DEV !== "true" && process.env.MASTRA_DEV !== "1") {
|
|
2128
2497
|
return;
|
|
2129
2498
|
}
|
|
2130
|
-
import('./provider-registry-
|
|
2499
|
+
import('./provider-registry-FM3IVY6C.js').then(async ({ GatewayRegistry }) => {
|
|
2131
2500
|
const registry = GatewayRegistry.getInstance();
|
|
2132
2501
|
const customGateways = Object.values(this.#gateways || {});
|
|
2133
2502
|
registry.registerCustomGateways(customGateways);
|
|
@@ -2181,5 +2550,5 @@ var Mastra = class {
|
|
|
2181
2550
|
};
|
|
2182
2551
|
|
|
2183
2552
|
export { Mastra };
|
|
2184
|
-
//# sourceMappingURL=chunk-
|
|
2185
|
-
//# sourceMappingURL=chunk-
|
|
2553
|
+
//# sourceMappingURL=chunk-LB7UOP2X.js.map
|
|
2554
|
+
//# sourceMappingURL=chunk-LB7UOP2X.js.map
|