@mastra/core 0.10.13 → 0.10.15-alpha.0
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/a2a.d.ts +1 -0
- package/agent.d.ts +1 -0
- package/base.d.ts +1 -0
- package/bundler.d.ts +1 -0
- package/deployer.d.ts +1 -0
- package/di.d.ts +1 -0
- package/dist/a2a/index.cjs +79 -0
- package/dist/a2a/index.d.cts +780 -0
- package/dist/a2a/index.d.ts +780 -0
- package/dist/a2a/index.js +68 -0
- package/dist/agent/index.cjs +15 -0
- package/dist/agent/index.d.cts +29 -0
- package/dist/agent/index.d.ts +29 -0
- package/dist/agent/index.js +2 -0
- package/dist/base-B_y9sMg0.d.cts +162 -0
- package/dist/base-CTj7ESwt.d.cts +4132 -0
- package/dist/base-ClrXcCRx.d.ts +162 -0
- package/dist/base-qVqAnB-c.d.ts +4132 -0
- package/dist/base.cjs +10 -0
- package/dist/base.d.cts +6 -0
- package/dist/base.d.ts +6 -0
- package/dist/base.js +1 -0
- package/dist/bundler/index.cjs +10 -0
- package/dist/bundler/index.d.cts +30 -0
- package/dist/bundler/index.d.ts +30 -0
- package/dist/bundler/index.js +1 -0
- package/dist/chunk-32C7JDIZ.js +1 -0
- package/dist/chunk-4UWPFBC6.js +88 -0
- package/dist/chunk-4Z3OU5RY.cjs +31 -0
- package/dist/chunk-5HTMDAXP.js +359 -0
- package/dist/chunk-5IEKR756.js +53 -0
- package/dist/chunk-5YDTZN2X.js +114 -0
- package/dist/chunk-6UNGH46J.js +75 -0
- package/dist/chunk-6Y4UL5Z6.cjs +94 -0
- package/dist/chunk-7H2GET5Z.cjs +668 -0
- package/dist/chunk-7HZ6NIAF.cjs +2 -0
- package/dist/chunk-7XQIPES3.js +668 -0
- package/dist/chunk-AKYTYALY.js +70 -0
- package/dist/chunk-AOWJUV2N.js +2415 -0
- package/dist/chunk-ATXBSEFT.js +22 -0
- package/dist/chunk-B6TOBUS6.cjs +80 -0
- package/dist/chunk-B7SQOKEC.cjs +91 -0
- package/dist/chunk-BB4KXGBU.js +83 -0
- package/dist/chunk-BB6DPGIV.cjs +6 -0
- package/dist/chunk-BVD7NVAR.cjs +244 -0
- package/dist/chunk-C4LMN2IR.js +27 -0
- package/dist/chunk-DR4JS662.js +989 -0
- package/dist/chunk-F2WMR75C.cjs +183 -0
- package/dist/chunk-FEYYOBBG.cjs +24 -0
- package/dist/chunk-FL5SZ2XU.js +181 -0
- package/dist/chunk-GH2KM66J.js +37 -0
- package/dist/chunk-GWFS5DAR.cjs +37 -0
- package/dist/chunk-HNEE7IF4.js +60 -0
- package/dist/chunk-HSVOEWAM.cjs +2 -0
- package/dist/chunk-IBKM5CLQ.js +428 -0
- package/dist/chunk-ID5LG5CQ.cjs +659 -0
- package/dist/chunk-J52TXHZV.cjs +73 -0
- package/dist/chunk-J62R4M7K.js +240 -0
- package/dist/chunk-JNMQKJH4.js +10 -0
- package/dist/chunk-JQOMTERC.js +89 -0
- package/dist/chunk-LABUWBKX.cjs +71 -0
- package/dist/chunk-LBUQ6YNU.cjs +447 -0
- package/dist/chunk-LXFZUKP3.cjs +34 -0
- package/dist/chunk-MP2QBLUJ.cjs +70 -0
- package/dist/chunk-MUNFCOMB.cjs +62 -0
- package/dist/chunk-MVCHTRVB.js +5038 -0
- package/dist/chunk-NH5WJNNS.js +1 -0
- package/dist/chunk-P3Q73CAW.cjs +55 -0
- package/dist/chunk-Q33INUG2.cjs +81 -0
- package/dist/chunk-QFTBW7ZZ.cjs +2 -0
- package/dist/chunk-QQ5K5TZE.cjs +619 -0
- package/dist/chunk-R4V75T7J.js +1 -0
- package/dist/chunk-RVFWMGGR.js +77 -0
- package/dist/chunk-SGGPJWRQ.js +69 -0
- package/dist/chunk-ST5RMVLG.cjs +87 -0
- package/dist/chunk-TC2SCOTE.js +605 -0
- package/dist/chunk-TTMYHBQM.js +657 -0
- package/dist/chunk-U64IJDC5.cjs +109 -0
- package/dist/chunk-ULZ6MRTN.cjs +5065 -0
- package/dist/chunk-V5D2LIF5.js +68 -0
- package/dist/chunk-WQNOATKB.js +103 -0
- package/dist/chunk-Y7D2JLKS.js +4 -0
- package/dist/chunk-YOQP5T77.js +32 -0
- package/dist/chunk-ZCU3PLIL.cjs +2429 -0
- package/dist/chunk-ZIZ3CVHN.cjs +120 -0
- package/dist/chunk-ZPOUMTTH.cjs +362 -0
- package/dist/chunk-ZTPPDHQK.cjs +991 -0
- package/dist/chunk-ZZLBNB3U.cjs +12 -0
- package/dist/deployer/index.cjs +10 -0
- package/dist/deployer/index.d.cts +19 -0
- package/dist/deployer/index.d.ts +19 -0
- package/dist/deployer/index.js +1 -0
- package/dist/di/index.cjs +10 -0
- package/dist/di/index.d.cts +1 -0
- package/dist/di/index.d.ts +1 -0
- package/dist/di/index.js +1 -0
- package/dist/error/index.cjs +22 -0
- package/dist/error/index.d.cts +86 -0
- package/dist/error/index.d.ts +86 -0
- package/dist/error/index.js +1 -0
- package/dist/eval/index.cjs +14 -0
- package/dist/eval/index.d.cts +43 -0
- package/dist/eval/index.d.ts +43 -0
- package/dist/eval/index.js +1 -0
- package/dist/hooks/index.cjs +18 -0
- package/dist/hooks/index.d.cts +33 -0
- package/dist/hooks/index.d.ts +33 -0
- package/dist/hooks/index.js +1 -0
- package/dist/index.cjs +285 -0
- package/dist/index.d.cts +92 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.js +112 -0
- package/dist/integration/index.cjs +14 -0
- package/dist/integration/index.d.cts +65 -0
- package/dist/integration/index.d.ts +65 -0
- package/dist/integration/index.js +1 -0
- package/dist/llm/index.cjs +10 -0
- package/dist/llm/index.d.cts +29 -0
- package/dist/llm/index.d.ts +29 -0
- package/dist/llm/index.js +1 -0
- package/dist/logger/index.cjs +43 -0
- package/dist/logger/index.d.cts +96 -0
- package/dist/logger/index.d.ts +96 -0
- package/dist/logger/index.js +2 -0
- package/dist/logger-B8XXh6ya.d.cts +159 -0
- package/dist/logger-Bpa2oLL4.d.ts +159 -0
- package/dist/mastra/index.cjs +10 -0
- package/dist/mastra/index.d.cts +29 -0
- package/dist/mastra/index.d.ts +29 -0
- package/dist/mastra/index.js +1 -0
- package/dist/mcp/index.cjs +106 -0
- package/dist/mcp/index.d.cts +29 -0
- package/dist/mcp/index.d.ts +29 -0
- package/dist/mcp/index.js +100 -0
- package/dist/memory/index.cjs +18 -0
- package/dist/memory/index.d.cts +29 -0
- package/dist/memory/index.d.ts +29 -0
- package/dist/memory/index.js +1 -0
- package/dist/network/index.cjs +311 -0
- package/dist/network/index.d.cts +29 -0
- package/dist/network/index.d.ts +29 -0
- package/dist/network/index.js +309 -0
- package/dist/network/vNext/index.cjs +880 -0
- package/dist/network/vNext/index.d.cts +29 -0
- package/dist/network/vNext/index.d.ts +29 -0
- package/dist/network/vNext/index.js +878 -0
- package/dist/relevance/index.cjs +18 -0
- package/dist/relevance/index.d.cts +50 -0
- package/dist/relevance/index.d.ts +50 -0
- package/dist/relevance/index.js +1 -0
- package/dist/runtime-context/index.cjs +10 -0
- package/dist/runtime-context/index.d.cts +52 -0
- package/dist/runtime-context/index.d.ts +52 -0
- package/dist/runtime-context/index.js +1 -0
- package/dist/server/index.cjs +62 -0
- package/dist/server/index.d.cts +52 -0
- package/dist/server/index.d.ts +52 -0
- package/dist/server/index.js +59 -0
- package/dist/storage/index.cjs +336 -0
- package/dist/storage/index.d.cts +149 -0
- package/dist/storage/index.d.ts +149 -0
- package/dist/storage/index.js +303 -0
- package/dist/telemetry/index.cjs +30 -0
- package/dist/telemetry/index.d.cts +75 -0
- package/dist/telemetry/index.d.ts +75 -0
- package/dist/telemetry/index.js +1 -0
- package/dist/telemetry/otel-vendor.cjs +103 -0
- package/dist/telemetry/otel-vendor.d.cts +20 -0
- package/dist/telemetry/otel-vendor.d.ts +20 -0
- package/dist/telemetry/otel-vendor.js +57 -0
- package/dist/tools/index.cjs +18 -0
- package/dist/tools/index.d.cts +41 -0
- package/dist/tools/index.d.ts +41 -0
- package/dist/tools/index.js +1 -0
- package/dist/tts/index.cjs +10 -0
- package/dist/tts/index.d.cts +28 -0
- package/dist/tts/index.d.ts +28 -0
- package/dist/tts/index.js +1 -0
- package/dist/types-Bo1uigWx.d.cts +17 -0
- package/dist/types-Bo1uigWx.d.ts +17 -0
- package/dist/utils.cjs +62 -0
- package/dist/utils.d.cts +150 -0
- package/dist/utils.d.ts +150 -0
- package/dist/utils.js +1 -0
- package/dist/vector/filter/index.cjs +192 -0
- package/dist/vector/filter/index.d.cts +128 -0
- package/dist/vector/filter/index.d.ts +128 -0
- package/dist/vector/filter/index.js +190 -0
- package/dist/vector/index.cjs +10 -0
- package/dist/vector/index.d.cts +77 -0
- package/dist/vector/index.d.ts +77 -0
- package/dist/vector/index.js +1 -0
- package/dist/voice/index.cjs +18 -0
- package/dist/voice/index.d.cts +29 -0
- package/dist/voice/index.d.ts +29 -0
- package/dist/voice/index.js +1 -0
- package/dist/workflows/constants.cjs +10 -0
- package/dist/workflows/constants.d.cts +3 -0
- package/dist/workflows/constants.d.ts +3 -0
- package/dist/workflows/constants.js +1 -0
- package/dist/workflows/index.cjs +42 -0
- package/dist/workflows/index.d.cts +285 -0
- package/dist/workflows/index.d.ts +285 -0
- package/dist/workflows/index.js +1 -0
- package/dist/workflows/legacy/index.cjs +90 -0
- package/dist/workflows/legacy/index.d.cts +91 -0
- package/dist/workflows/legacy/index.d.ts +91 -0
- package/dist/workflows/legacy/index.js +1 -0
- package/error.d.ts +1 -0
- package/eval.d.ts +1 -0
- package/hooks.d.ts +1 -0
- package/integration.d.ts +1 -0
- package/llm.d.ts +1 -0
- package/logger.d.ts +1 -0
- package/mastra.d.ts +1 -0
- package/mcp.d.ts +1 -0
- package/memory.d.ts +1 -0
- package/network/vNext.d.ts +1 -0
- package/network.d.ts +1 -0
- package/package.json +2 -3
- package/relevance.d.ts +1 -0
- package/runtime-context.d.ts +1 -0
- package/server.d.ts +1 -0
- package/storage.d.ts +1 -0
- package/telemetry/otel-vendor.d.ts +1 -0
- package/telemetry.d.ts +1 -0
- package/tools.d.ts +1 -0
- package/tts.d.ts +1 -0
- package/utils.d.ts +1 -0
- package/vector/filter.d.ts +1 -0
- package/vector.d.ts +1 -0
- package/voice.d.ts +1 -0
- package/workflows/_constants.d.ts +1 -0
- package/workflows/legacy.d.ts +1 -0
- package/workflows.d.ts +1 -0
|
@@ -0,0 +1,668 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkLXFZUKP3_cjs = require('./chunk-LXFZUKP3.cjs');
|
|
4
|
+
var chunkQQ5K5TZE_cjs = require('./chunk-QQ5K5TZE.cjs');
|
|
5
|
+
var chunk6Y4UL5Z6_cjs = require('./chunk-6Y4UL5Z6.cjs');
|
|
6
|
+
var chunkB6TOBUS6_cjs = require('./chunk-B6TOBUS6.cjs');
|
|
7
|
+
var chunkZIZ3CVHN_cjs = require('./chunk-ZIZ3CVHN.cjs');
|
|
8
|
+
var chunkU64IJDC5_cjs = require('./chunk-U64IJDC5.cjs');
|
|
9
|
+
|
|
10
|
+
// src/mastra/index.ts
|
|
11
|
+
var _Mastra_decorators, _init;
|
|
12
|
+
_Mastra_decorators = [chunkQQ5K5TZE_cjs.InstrumentClass({
|
|
13
|
+
prefix: "mastra",
|
|
14
|
+
excludeMethods: ["getLogger", "getTelemetry"]
|
|
15
|
+
})];
|
|
16
|
+
exports.Mastra = class Mastra {
|
|
17
|
+
#vectors;
|
|
18
|
+
#agents;
|
|
19
|
+
#logger;
|
|
20
|
+
#legacy_workflows;
|
|
21
|
+
#workflows;
|
|
22
|
+
#tts;
|
|
23
|
+
#deployer;
|
|
24
|
+
#serverMiddleware = [];
|
|
25
|
+
#telemetry;
|
|
26
|
+
#storage;
|
|
27
|
+
#memory;
|
|
28
|
+
#networks;
|
|
29
|
+
#vnext_networks;
|
|
30
|
+
#server;
|
|
31
|
+
#mcpServers;
|
|
32
|
+
#bundler;
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated use getTelemetry() instead
|
|
35
|
+
*/
|
|
36
|
+
get telemetry() {
|
|
37
|
+
return this.#telemetry;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated use getStorage() instead
|
|
41
|
+
*/
|
|
42
|
+
get storage() {
|
|
43
|
+
return this.#storage;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated use getMemory() instead
|
|
47
|
+
*/
|
|
48
|
+
get memory() {
|
|
49
|
+
return this.#memory;
|
|
50
|
+
}
|
|
51
|
+
constructor(config) {
|
|
52
|
+
if (config?.serverMiddleware) {
|
|
53
|
+
this.#serverMiddleware = config.serverMiddleware.map(m => ({
|
|
54
|
+
handler: m.handler,
|
|
55
|
+
path: m.path || "/api/*"
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
let logger;
|
|
59
|
+
if (config?.logger === false) {
|
|
60
|
+
logger = chunk6Y4UL5Z6_cjs.noopLogger;
|
|
61
|
+
} else {
|
|
62
|
+
if (config?.logger) {
|
|
63
|
+
logger = config.logger;
|
|
64
|
+
} else {
|
|
65
|
+
const levelOnEnv = process.env.NODE_ENV === "production" && process.env.MASTRA_DEV !== "true" ? chunkZIZ3CVHN_cjs.LogLevel.WARN : chunkZIZ3CVHN_cjs.LogLevel.INFO;
|
|
66
|
+
logger = new chunkZIZ3CVHN_cjs.ConsoleLogger({
|
|
67
|
+
name: "Mastra",
|
|
68
|
+
level: levelOnEnv
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
this.#logger = logger;
|
|
73
|
+
let storage = config?.storage;
|
|
74
|
+
if (storage) {
|
|
75
|
+
storage = chunkLXFZUKP3_cjs.augmentWithInit(storage);
|
|
76
|
+
}
|
|
77
|
+
this.#telemetry = chunkQQ5K5TZE_cjs.Telemetry.init(config?.telemetry);
|
|
78
|
+
if (this.#telemetry && storage) {
|
|
79
|
+
this.#storage = this.#telemetry.traceClass(storage, {
|
|
80
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry", "batchTraceInsert", "getTraces", "getEvalsByAgentName"]
|
|
81
|
+
});
|
|
82
|
+
this.#storage.__setTelemetry(this.#telemetry);
|
|
83
|
+
} else {
|
|
84
|
+
this.#storage = storage;
|
|
85
|
+
}
|
|
86
|
+
if (config?.vectors) {
|
|
87
|
+
let vectors = {};
|
|
88
|
+
Object.entries(config.vectors).forEach(([key, vector]) => {
|
|
89
|
+
if (this.#telemetry) {
|
|
90
|
+
vectors[key] = this.#telemetry.traceClass(vector, {
|
|
91
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
92
|
+
});
|
|
93
|
+
vectors[key].__setTelemetry(this.#telemetry);
|
|
94
|
+
} else {
|
|
95
|
+
vectors[key] = vector;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
this.#vectors = vectors;
|
|
99
|
+
}
|
|
100
|
+
if (config?.vectors) {
|
|
101
|
+
this.#vectors = config.vectors;
|
|
102
|
+
}
|
|
103
|
+
if (config?.networks) {
|
|
104
|
+
this.#networks = config.networks;
|
|
105
|
+
}
|
|
106
|
+
if (config?.vnext_networks) {
|
|
107
|
+
this.#vnext_networks = config.vnext_networks;
|
|
108
|
+
}
|
|
109
|
+
if (config?.mcpServers) {
|
|
110
|
+
this.#mcpServers = config.mcpServers;
|
|
111
|
+
Object.entries(this.#mcpServers).forEach(([key, server]) => {
|
|
112
|
+
server.setId(key);
|
|
113
|
+
if (this.#telemetry) {
|
|
114
|
+
server.__setTelemetry(this.#telemetry);
|
|
115
|
+
}
|
|
116
|
+
server.__registerMastra(this);
|
|
117
|
+
server.__setLogger(this.getLogger());
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (config && `memory` in config) {
|
|
121
|
+
const error = new chunkB6TOBUS6_cjs.MastraError({
|
|
122
|
+
id: "MASTRA_CONSTRUCTOR_INVALID_MEMORY_CONFIG",
|
|
123
|
+
domain: "MASTRA" /* MASTRA */,
|
|
124
|
+
category: "USER" /* USER */,
|
|
125
|
+
text: `
|
|
126
|
+
Memory should be added to Agents, not to Mastra.
|
|
127
|
+
|
|
128
|
+
Instead of:
|
|
129
|
+
new Mastra({ memory: new Memory() })
|
|
130
|
+
|
|
131
|
+
do:
|
|
132
|
+
new Agent({ memory: new Memory() })
|
|
133
|
+
`
|
|
134
|
+
});
|
|
135
|
+
this.#logger?.trackException(error);
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
if (config?.tts) {
|
|
139
|
+
this.#tts = config.tts;
|
|
140
|
+
Object.entries(this.#tts).forEach(([key, ttsCl]) => {
|
|
141
|
+
if (this.#tts?.[key]) {
|
|
142
|
+
if (this.#telemetry) {
|
|
143
|
+
this.#tts[key] = this.#telemetry.traceClass(ttsCl, {
|
|
144
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
145
|
+
});
|
|
146
|
+
this.#tts[key].__setTelemetry(this.#telemetry);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
const agents = {};
|
|
152
|
+
if (config?.agents) {
|
|
153
|
+
Object.entries(config.agents).forEach(([key, agent]) => {
|
|
154
|
+
if (agents[key]) {
|
|
155
|
+
const error = new chunkB6TOBUS6_cjs.MastraError({
|
|
156
|
+
id: "MASTRA_AGENT_REGISTRATION_DUPLICATE_ID",
|
|
157
|
+
domain: "MASTRA" /* MASTRA */,
|
|
158
|
+
category: "USER" /* USER */,
|
|
159
|
+
text: `Agent with name ID:${key} already exists`,
|
|
160
|
+
details: {
|
|
161
|
+
agentId: key
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
this.#logger?.trackException(error);
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
agent.__registerMastra(this);
|
|
168
|
+
agent.__registerPrimitives({
|
|
169
|
+
logger: this.getLogger(),
|
|
170
|
+
telemetry: this.#telemetry,
|
|
171
|
+
storage: this.storage,
|
|
172
|
+
memory: this.memory,
|
|
173
|
+
agents,
|
|
174
|
+
tts: this.#tts,
|
|
175
|
+
vectors: this.#vectors
|
|
176
|
+
});
|
|
177
|
+
agents[key] = agent;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
this.#agents = agents;
|
|
181
|
+
this.#networks = {};
|
|
182
|
+
this.#vnext_networks = {};
|
|
183
|
+
if (config?.networks) {
|
|
184
|
+
Object.entries(config.networks).forEach(([key, network]) => {
|
|
185
|
+
network.__registerMastra(this);
|
|
186
|
+
this.#networks[key] = network;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
if (config?.vnext_networks) {
|
|
190
|
+
Object.entries(config.vnext_networks).forEach(([key, network]) => {
|
|
191
|
+
network.__registerMastra(this);
|
|
192
|
+
this.#vnext_networks[key] = network;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
this.#legacy_workflows = {};
|
|
196
|
+
if (config?.legacy_workflows) {
|
|
197
|
+
Object.entries(config.legacy_workflows).forEach(([key, workflow]) => {
|
|
198
|
+
workflow.__registerMastra(this);
|
|
199
|
+
workflow.__registerPrimitives({
|
|
200
|
+
logger: this.getLogger(),
|
|
201
|
+
telemetry: this.#telemetry,
|
|
202
|
+
storage: this.storage,
|
|
203
|
+
memory: this.memory,
|
|
204
|
+
agents,
|
|
205
|
+
tts: this.#tts,
|
|
206
|
+
vectors: this.#vectors
|
|
207
|
+
});
|
|
208
|
+
this.#legacy_workflows[key] = workflow;
|
|
209
|
+
const workflowSteps = Object.values(workflow.steps).filter(step => !!step.workflowId && !!step.workflow);
|
|
210
|
+
if (workflowSteps.length > 0) {
|
|
211
|
+
workflowSteps.forEach(step => {
|
|
212
|
+
this.#legacy_workflows[step.workflowId] = step.workflow;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
this.#workflows = {};
|
|
218
|
+
if (config?.workflows) {
|
|
219
|
+
Object.entries(config.workflows).forEach(([key, workflow]) => {
|
|
220
|
+
workflow.__registerMastra(this);
|
|
221
|
+
workflow.__registerPrimitives({
|
|
222
|
+
logger: this.getLogger(),
|
|
223
|
+
telemetry: this.#telemetry,
|
|
224
|
+
storage: this.storage,
|
|
225
|
+
memory: this.memory,
|
|
226
|
+
agents,
|
|
227
|
+
tts: this.#tts,
|
|
228
|
+
vectors: this.#vectors
|
|
229
|
+
});
|
|
230
|
+
this.#workflows[key] = workflow;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
if (config?.server) {
|
|
234
|
+
this.#server = config.server;
|
|
235
|
+
}
|
|
236
|
+
this.setLogger({
|
|
237
|
+
logger
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
getAgent(name) {
|
|
241
|
+
const agent = this.#agents?.[name];
|
|
242
|
+
if (!agent) {
|
|
243
|
+
const error = new chunkB6TOBUS6_cjs.MastraError({
|
|
244
|
+
id: "MASTRA_GET_AGENT_BY_NAME_NOT_FOUND",
|
|
245
|
+
domain: "MASTRA" /* MASTRA */,
|
|
246
|
+
category: "USER" /* USER */,
|
|
247
|
+
text: `Agent with name ${String(name)} not found`,
|
|
248
|
+
details: {
|
|
249
|
+
status: 404,
|
|
250
|
+
agentName: String(name),
|
|
251
|
+
agents: Object.keys(this.#agents ?? {}).join(", ")
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
this.#logger?.trackException(error);
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
257
|
+
return this.#agents[name];
|
|
258
|
+
}
|
|
259
|
+
getAgents() {
|
|
260
|
+
return this.#agents;
|
|
261
|
+
}
|
|
262
|
+
getVector(name) {
|
|
263
|
+
const vector = this.#vectors?.[name];
|
|
264
|
+
if (!vector) {
|
|
265
|
+
const error = new chunkB6TOBUS6_cjs.MastraError({
|
|
266
|
+
id: "MASTRA_GET_VECTOR_BY_NAME_NOT_FOUND",
|
|
267
|
+
domain: "MASTRA" /* MASTRA */,
|
|
268
|
+
category: "USER" /* USER */,
|
|
269
|
+
text: `Vector with name ${String(name)} not found`,
|
|
270
|
+
details: {
|
|
271
|
+
status: 404,
|
|
272
|
+
vectorName: String(name),
|
|
273
|
+
vectors: Object.keys(this.#vectors ?? {}).join(", ")
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
this.#logger?.trackException(error);
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
return vector;
|
|
280
|
+
}
|
|
281
|
+
getVectors() {
|
|
282
|
+
return this.#vectors;
|
|
283
|
+
}
|
|
284
|
+
getDeployer() {
|
|
285
|
+
return this.#deployer;
|
|
286
|
+
}
|
|
287
|
+
legacy_getWorkflow(id, {
|
|
288
|
+
serialized
|
|
289
|
+
} = {}) {
|
|
290
|
+
const workflow = this.#legacy_workflows?.[id];
|
|
291
|
+
if (!workflow) {
|
|
292
|
+
const error = new chunkB6TOBUS6_cjs.MastraError({
|
|
293
|
+
id: "MASTRA_GET_LEGACY_WORKFLOW_BY_ID_NOT_FOUND",
|
|
294
|
+
domain: "MASTRA" /* MASTRA */,
|
|
295
|
+
category: "USER" /* USER */,
|
|
296
|
+
text: `Workflow with ID ${String(id)} not found`,
|
|
297
|
+
details: {
|
|
298
|
+
status: 404,
|
|
299
|
+
workflowId: String(id),
|
|
300
|
+
workflows: Object.keys(this.#legacy_workflows ?? {}).join(", ")
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
this.#logger?.trackException(error);
|
|
304
|
+
throw error;
|
|
305
|
+
}
|
|
306
|
+
if (serialized) {
|
|
307
|
+
return {
|
|
308
|
+
name: workflow.name
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
return workflow;
|
|
312
|
+
}
|
|
313
|
+
getWorkflow(id, {
|
|
314
|
+
serialized
|
|
315
|
+
} = {}) {
|
|
316
|
+
const workflow = this.#workflows?.[id];
|
|
317
|
+
if (!workflow) {
|
|
318
|
+
const error = new chunkB6TOBUS6_cjs.MastraError({
|
|
319
|
+
id: "MASTRA_GET_WORKFLOW_BY_ID_NOT_FOUND",
|
|
320
|
+
domain: "MASTRA" /* MASTRA */,
|
|
321
|
+
category: "USER" /* USER */,
|
|
322
|
+
text: `Workflow with ID ${String(id)} not found`,
|
|
323
|
+
details: {
|
|
324
|
+
status: 404,
|
|
325
|
+
workflowId: String(id),
|
|
326
|
+
workflows: Object.keys(this.#workflows ?? {}).join(", ")
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
this.#logger?.trackException(error);
|
|
330
|
+
throw error;
|
|
331
|
+
}
|
|
332
|
+
if (serialized) {
|
|
333
|
+
return {
|
|
334
|
+
name: workflow.name
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
return workflow;
|
|
338
|
+
}
|
|
339
|
+
legacy_getWorkflows(props = {}) {
|
|
340
|
+
if (props.serialized) {
|
|
341
|
+
return Object.entries(this.#legacy_workflows).reduce((acc, [k, v]) => {
|
|
342
|
+
return {
|
|
343
|
+
...acc,
|
|
344
|
+
[k]: {
|
|
345
|
+
name: v.name
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
}, {});
|
|
349
|
+
}
|
|
350
|
+
return this.#legacy_workflows;
|
|
351
|
+
}
|
|
352
|
+
getWorkflows(props = {}) {
|
|
353
|
+
if (props.serialized) {
|
|
354
|
+
return Object.entries(this.#workflows).reduce((acc, [k, v]) => {
|
|
355
|
+
return {
|
|
356
|
+
...acc,
|
|
357
|
+
[k]: {
|
|
358
|
+
name: v.name
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
}, {});
|
|
362
|
+
}
|
|
363
|
+
return this.#workflows;
|
|
364
|
+
}
|
|
365
|
+
setStorage(storage) {
|
|
366
|
+
this.#storage = chunkLXFZUKP3_cjs.augmentWithInit(storage);
|
|
367
|
+
}
|
|
368
|
+
setLogger({
|
|
369
|
+
logger
|
|
370
|
+
}) {
|
|
371
|
+
this.#logger = logger;
|
|
372
|
+
if (this.#agents) {
|
|
373
|
+
Object.keys(this.#agents).forEach(key => {
|
|
374
|
+
this.#agents?.[key]?.__setLogger(this.#logger);
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
if (this.#memory) {
|
|
378
|
+
this.#memory.__setLogger(this.#logger);
|
|
379
|
+
}
|
|
380
|
+
if (this.#deployer) {
|
|
381
|
+
this.#deployer.__setLogger(this.#logger);
|
|
382
|
+
}
|
|
383
|
+
if (this.#tts) {
|
|
384
|
+
Object.keys(this.#tts).forEach(key => {
|
|
385
|
+
this.#tts?.[key]?.__setLogger(this.#logger);
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
if (this.#storage) {
|
|
389
|
+
this.#storage.__setLogger(this.#logger);
|
|
390
|
+
}
|
|
391
|
+
if (this.#vectors) {
|
|
392
|
+
Object.keys(this.#vectors).forEach(key => {
|
|
393
|
+
this.#vectors?.[key]?.__setLogger(this.#logger);
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
if (this.#mcpServers) {
|
|
397
|
+
Object.keys(this.#mcpServers).forEach(key => {
|
|
398
|
+
this.#mcpServers?.[key]?.__setLogger(this.#logger);
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
setTelemetry(telemetry) {
|
|
403
|
+
this.#telemetry = chunkQQ5K5TZE_cjs.Telemetry.init(telemetry);
|
|
404
|
+
if (this.#agents) {
|
|
405
|
+
Object.keys(this.#agents).forEach(key => {
|
|
406
|
+
if (this.#telemetry) {
|
|
407
|
+
this.#agents?.[key]?.__setTelemetry(this.#telemetry);
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
if (this.#memory) {
|
|
412
|
+
this.#memory = this.#telemetry.traceClass(this.#memory, {
|
|
413
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
414
|
+
});
|
|
415
|
+
this.#memory.__setTelemetry(this.#telemetry);
|
|
416
|
+
}
|
|
417
|
+
if (this.#deployer) {
|
|
418
|
+
this.#deployer = this.#telemetry.traceClass(this.#deployer, {
|
|
419
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
420
|
+
});
|
|
421
|
+
this.#deployer.__setTelemetry(this.#telemetry);
|
|
422
|
+
}
|
|
423
|
+
if (this.#tts) {
|
|
424
|
+
let tts = {};
|
|
425
|
+
Object.entries(this.#tts).forEach(([key, ttsCl]) => {
|
|
426
|
+
if (this.#telemetry) {
|
|
427
|
+
tts[key] = this.#telemetry.traceClass(ttsCl, {
|
|
428
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
429
|
+
});
|
|
430
|
+
tts[key].__setTelemetry(this.#telemetry);
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
this.#tts = tts;
|
|
434
|
+
}
|
|
435
|
+
if (this.#storage) {
|
|
436
|
+
this.#storage = this.#telemetry.traceClass(this.#storage, {
|
|
437
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
438
|
+
});
|
|
439
|
+
this.#storage.__setTelemetry(this.#telemetry);
|
|
440
|
+
}
|
|
441
|
+
if (this.#vectors) {
|
|
442
|
+
let vectors = {};
|
|
443
|
+
Object.entries(this.#vectors).forEach(([key, vector]) => {
|
|
444
|
+
if (this.#telemetry) {
|
|
445
|
+
vectors[key] = this.#telemetry.traceClass(vector, {
|
|
446
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
447
|
+
});
|
|
448
|
+
vectors[key].__setTelemetry(this.#telemetry);
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
this.#vectors = vectors;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
getTTS() {
|
|
455
|
+
return this.#tts;
|
|
456
|
+
}
|
|
457
|
+
getLogger() {
|
|
458
|
+
return this.#logger;
|
|
459
|
+
}
|
|
460
|
+
getTelemetry() {
|
|
461
|
+
return this.#telemetry;
|
|
462
|
+
}
|
|
463
|
+
getMemory() {
|
|
464
|
+
return this.#memory;
|
|
465
|
+
}
|
|
466
|
+
getStorage() {
|
|
467
|
+
return this.#storage;
|
|
468
|
+
}
|
|
469
|
+
getServerMiddleware() {
|
|
470
|
+
return this.#serverMiddleware;
|
|
471
|
+
}
|
|
472
|
+
setServerMiddleware(serverMiddleware) {
|
|
473
|
+
if (typeof serverMiddleware === "function") {
|
|
474
|
+
this.#serverMiddleware = [{
|
|
475
|
+
handler: serverMiddleware,
|
|
476
|
+
path: "/api/*"
|
|
477
|
+
}];
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
if (!Array.isArray(serverMiddleware)) {
|
|
481
|
+
const error = new chunkB6TOBUS6_cjs.MastraError({
|
|
482
|
+
id: "MASTRA_SET_SERVER_MIDDLEWARE_INVALID_TYPE",
|
|
483
|
+
domain: "MASTRA" /* MASTRA */,
|
|
484
|
+
category: "USER" /* USER */,
|
|
485
|
+
text: `Invalid middleware: expected a function or array, received ${typeof serverMiddleware}`
|
|
486
|
+
});
|
|
487
|
+
this.#logger?.trackException(error);
|
|
488
|
+
throw error;
|
|
489
|
+
}
|
|
490
|
+
this.#serverMiddleware = serverMiddleware.map(m => {
|
|
491
|
+
if (typeof m === "function") {
|
|
492
|
+
return {
|
|
493
|
+
handler: m,
|
|
494
|
+
path: "/api/*"
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
return {
|
|
498
|
+
handler: m.handler,
|
|
499
|
+
path: m.path || "/api/*"
|
|
500
|
+
};
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
getNetworks() {
|
|
504
|
+
return Object.values(this.#networks || {});
|
|
505
|
+
}
|
|
506
|
+
vnext_getNetworks() {
|
|
507
|
+
return Object.values(this.#vnext_networks || {});
|
|
508
|
+
}
|
|
509
|
+
getServer() {
|
|
510
|
+
return this.#server;
|
|
511
|
+
}
|
|
512
|
+
getBundlerConfig() {
|
|
513
|
+
return this.#bundler;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Get a specific network by ID
|
|
517
|
+
* @param networkId - The ID of the network to retrieve
|
|
518
|
+
* @returns The network with the specified ID, or undefined if not found
|
|
519
|
+
*/
|
|
520
|
+
getNetwork(networkId) {
|
|
521
|
+
const networks = this.getNetworks();
|
|
522
|
+
return networks.find(network => {
|
|
523
|
+
const routingAgent = network.getRoutingAgent();
|
|
524
|
+
return network.formatAgentId(routingAgent.name) === networkId;
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
vnext_getNetwork(networkId) {
|
|
528
|
+
const networks = this.vnext_getNetworks();
|
|
529
|
+
return networks.find(network => network.id === networkId);
|
|
530
|
+
}
|
|
531
|
+
async getLogsByRunId({
|
|
532
|
+
runId,
|
|
533
|
+
transportId,
|
|
534
|
+
fromDate,
|
|
535
|
+
toDate,
|
|
536
|
+
logLevel,
|
|
537
|
+
filters,
|
|
538
|
+
page,
|
|
539
|
+
perPage
|
|
540
|
+
}) {
|
|
541
|
+
if (!transportId) {
|
|
542
|
+
const error = new chunkB6TOBUS6_cjs.MastraError({
|
|
543
|
+
id: "MASTRA_GET_LOGS_BY_RUN_ID_MISSING_TRANSPORT",
|
|
544
|
+
domain: "MASTRA" /* MASTRA */,
|
|
545
|
+
category: "USER" /* USER */,
|
|
546
|
+
text: "Transport ID is required",
|
|
547
|
+
details: {
|
|
548
|
+
runId,
|
|
549
|
+
transportId
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
this.#logger?.trackException(error);
|
|
553
|
+
throw error;
|
|
554
|
+
}
|
|
555
|
+
if (!this.#logger?.getLogsByRunId) {
|
|
556
|
+
const error = new chunkB6TOBUS6_cjs.MastraError({
|
|
557
|
+
id: "MASTRA_GET_LOGS_BY_RUN_ID_LOGGER_NOT_CONFIGURED",
|
|
558
|
+
domain: "MASTRA" /* MASTRA */,
|
|
559
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
560
|
+
text: "Logger is not configured or does not support getLogsByRunId operation",
|
|
561
|
+
details: {
|
|
562
|
+
runId,
|
|
563
|
+
transportId
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
this.#logger?.trackException(error);
|
|
567
|
+
throw error;
|
|
568
|
+
}
|
|
569
|
+
return await this.#logger.getLogsByRunId({
|
|
570
|
+
runId,
|
|
571
|
+
transportId,
|
|
572
|
+
fromDate,
|
|
573
|
+
toDate,
|
|
574
|
+
logLevel,
|
|
575
|
+
filters,
|
|
576
|
+
page,
|
|
577
|
+
perPage
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
async getLogs(transportId, params) {
|
|
581
|
+
if (!transportId) {
|
|
582
|
+
const error = new chunkB6TOBUS6_cjs.MastraError({
|
|
583
|
+
id: "MASTRA_GET_LOGS_MISSING_TRANSPORT",
|
|
584
|
+
domain: "MASTRA" /* MASTRA */,
|
|
585
|
+
category: "USER" /* USER */,
|
|
586
|
+
text: "Transport ID is required",
|
|
587
|
+
details: {
|
|
588
|
+
transportId
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
this.#logger?.trackException(error);
|
|
592
|
+
throw error;
|
|
593
|
+
}
|
|
594
|
+
if (!this.#logger) {
|
|
595
|
+
const error = new chunkB6TOBUS6_cjs.MastraError({
|
|
596
|
+
id: "MASTRA_GET_LOGS_LOGGER_NOT_CONFIGURED",
|
|
597
|
+
domain: "MASTRA" /* MASTRA */,
|
|
598
|
+
category: "SYSTEM" /* SYSTEM */,
|
|
599
|
+
text: "Logger is not set",
|
|
600
|
+
details: {
|
|
601
|
+
transportId
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
throw error;
|
|
605
|
+
}
|
|
606
|
+
return await this.#logger.getLogs(transportId, params);
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Get all registered MCP server instances.
|
|
610
|
+
* @returns A record of MCP server ID to MCPServerBase instance, or undefined if none are registered.
|
|
611
|
+
*/
|
|
612
|
+
getMCPServers() {
|
|
613
|
+
return this.#mcpServers;
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Get a specific MCP server instance.
|
|
617
|
+
* If a version is provided, it attempts to find the server with that exact logical ID and version.
|
|
618
|
+
* If no version is provided, it returns the server with the specified logical ID that has the most recent releaseDate.
|
|
619
|
+
* The logical ID should match the `id` property of the MCPServer instance (typically set via MCPServerConfig.id).
|
|
620
|
+
* @param serverId - The logical ID of the MCP server to retrieve.
|
|
621
|
+
* @param version - Optional specific version of the MCP server to retrieve.
|
|
622
|
+
* @returns The MCP server instance, or undefined if not found or if the specific version is not found.
|
|
623
|
+
*/
|
|
624
|
+
getMCPServer(serverId, version) {
|
|
625
|
+
if (!this.#mcpServers) {
|
|
626
|
+
return void 0;
|
|
627
|
+
}
|
|
628
|
+
const allRegisteredServers = Object.values(this.#mcpServers || {});
|
|
629
|
+
const matchingLogicalIdServers = allRegisteredServers.filter(server => server.id === serverId);
|
|
630
|
+
if (matchingLogicalIdServers.length === 0) {
|
|
631
|
+
this.#logger?.debug(`No MCP servers found with logical ID: ${serverId}`);
|
|
632
|
+
return void 0;
|
|
633
|
+
}
|
|
634
|
+
if (version) {
|
|
635
|
+
const specificVersionServer = matchingLogicalIdServers.find(server => server.version === version);
|
|
636
|
+
if (!specificVersionServer) {
|
|
637
|
+
this.#logger?.debug(`MCP server with logical ID '${serverId}' found, but not version '${version}'.`);
|
|
638
|
+
}
|
|
639
|
+
return specificVersionServer;
|
|
640
|
+
} else {
|
|
641
|
+
if (matchingLogicalIdServers.length === 1) {
|
|
642
|
+
return matchingLogicalIdServers[0];
|
|
643
|
+
}
|
|
644
|
+
matchingLogicalIdServers.sort((a, b) => {
|
|
645
|
+
const dateAVal = a.releaseDate && typeof a.releaseDate === "string" ? new Date(a.releaseDate).getTime() : NaN;
|
|
646
|
+
const dateBVal = b.releaseDate && typeof b.releaseDate === "string" ? new Date(b.releaseDate).getTime() : NaN;
|
|
647
|
+
if (isNaN(dateAVal) && isNaN(dateBVal)) return 0;
|
|
648
|
+
if (isNaN(dateAVal)) return 1;
|
|
649
|
+
if (isNaN(dateBVal)) return -1;
|
|
650
|
+
return dateBVal - dateAVal;
|
|
651
|
+
});
|
|
652
|
+
if (matchingLogicalIdServers.length > 0) {
|
|
653
|
+
const latestServer = matchingLogicalIdServers[0];
|
|
654
|
+
if (latestServer && latestServer.releaseDate && typeof latestServer.releaseDate === "string" && !isNaN(new Date(latestServer.releaseDate).getTime())) {
|
|
655
|
+
return latestServer;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
this.#logger?.warn(`Could not determine the latest server for logical ID '${serverId}' due to invalid or missing release dates, or no servers left after filtering.`);
|
|
659
|
+
return void 0;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
exports.Mastra = /*@__PURE__*/(_ => {
|
|
664
|
+
_init = chunkU64IJDC5_cjs.__decoratorStart(null);
|
|
665
|
+
exports.Mastra = chunkU64IJDC5_cjs.__decorateElement(_init, 0, "Mastra", _Mastra_decorators, exports.Mastra);
|
|
666
|
+
chunkU64IJDC5_cjs.__runInitializers(_init, 1, exports.Mastra);
|
|
667
|
+
return exports.Mastra;
|
|
668
|
+
})();
|