@mastra/core 0.2.0-alpha.99 → 0.2.1-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/dist/agent/index.d.ts +6 -8
- package/dist/agent/index.js +1 -7
- package/dist/{telemetry-oCUM52DG.d.ts → base-BbtPAA6f.d.ts} +50 -8
- package/dist/{index-Cwb-5AzX.d.ts → base-C7R9FwZ6.d.ts} +450 -403
- package/dist/base.d.ts +3 -43
- package/dist/base.js +1 -3
- package/dist/bundler/index.d.ts +3 -4
- package/dist/bundler/index.js +1 -4
- package/dist/{chunk-MCB4M5W4.js → chunk-22LC46YN.js} +3 -9
- package/dist/chunk-4ZRHVG25.js +402 -0
- package/dist/{chunk-KNPBNSJ7.js → chunk-55GTEVHJ.js} +13 -14
- package/dist/chunk-5HXXWLRX.js +626 -0
- package/dist/chunk-6TCTOQ3G.js +1204 -0
- package/dist/{chunk-ZJOMHCWE.js → chunk-AN562ICT.js} +98 -151
- package/dist/chunk-AWEACB2T.js +66 -0
- package/dist/chunk-BB4KXGBU.js +83 -0
- package/dist/chunk-C6A6W6XS.js +77 -0
- package/dist/{chunk-EO3TIPGQ.js → chunk-CUIUUULJ.js} +375 -254
- package/dist/chunk-HT63PEVD.js +37 -0
- package/dist/chunk-K36NSQWH.js +10 -0
- package/dist/chunk-NUDAZEOG.js +35 -0
- package/dist/{chunk-ICMEXHKD.js → chunk-O2VP5JBC.js} +48 -55
- package/dist/{chunk-42DYOLDV.js → chunk-PNZK456O.js} +13 -21
- package/dist/chunk-RG66XEJT.js +8 -0
- package/dist/chunk-SIFBBGY6.js +190 -0
- package/dist/{chunk-A7SNFYQB.js → chunk-V4WSAQOP.js} +7 -15
- package/dist/chunk-V5UMPUKC.js +218 -0
- package/dist/{chunk-DHCULRJM.js → chunk-VE4JJJSW.js} +126 -78
- package/dist/chunk-ZINPRHAN.js +22 -0
- package/dist/{chunk-C55JWGDU.js → chunk-ZJOXJFJI.js} +42 -15
- package/dist/deployer/index.d.ts +3 -5
- package/dist/deployer/index.js +1 -5
- package/dist/eval/index.d.ts +8 -13
- package/dist/eval/index.js +1 -3
- package/dist/filter/index.js +1 -2
- package/dist/hooks/index.d.ts +13 -18
- package/dist/hooks/index.js +1 -2
- package/dist/{index-CBZ2mk2H.d.ts → index-B2JCcAQt.d.ts} +1 -1
- package/dist/index.d.ts +16 -16
- package/dist/index.js +37 -67
- package/dist/integration/index.d.ts +8 -10
- package/dist/integration/index.js +1 -3
- package/dist/llm/index.d.ts +6 -8
- package/dist/llm/index.js +1 -1
- package/dist/logger/index.d.ts +1 -1
- package/dist/logger/index.js +1 -2
- package/dist/mastra/index.d.ts +23 -25
- package/dist/mastra/index.js +1 -9
- package/dist/memory/index.d.ts +8 -10
- package/dist/memory/index.js +1 -9
- package/dist/relevance/index.js +1 -8
- package/dist/storage/index.d.ts +21 -10
- package/dist/storage/index.js +3 -7
- package/dist/telemetry/index.d.ts +35 -5
- package/dist/telemetry/index.js +1 -2
- package/dist/telemetry/otel-vendor.d.ts +7 -0
- package/dist/telemetry/otel-vendor.js +7 -0
- package/dist/tools/index.d.ts +6 -8
- package/dist/tools/index.js +1 -2
- package/dist/tts/index.d.ts +2 -4
- package/dist/tts/index.js +1 -5
- package/dist/{metric-BWeQNZt6.d.ts → types-m9RryK9a.d.ts} +6 -1
- package/dist/utils.js +1 -2
- package/dist/vector/index.d.ts +4 -6
- package/dist/vector/index.js +1 -4
- package/dist/vector/libsql/index.d.ts +2 -4
- package/dist/vector/libsql/index.js +1 -6
- package/dist/{workflow-DTtv7_Eq.d.ts → workflow-7xHmmFH5.d.ts} +3 -6
- package/dist/workflows/index.d.ts +7 -9
- package/dist/workflows/index.js +1 -4
- package/package.json +22 -18
- package/dist/chunk-4LJFWC2Q.js +0 -216
- package/dist/chunk-4ZUSEHLH.js +0 -285
- package/dist/chunk-AJJZUHB4.js +0 -14
- package/dist/chunk-G4MCO7XF.js +0 -70
- package/dist/chunk-HBTQNIAX.js +0 -90
- package/dist/chunk-HPXWJBQK.js +0 -222
- package/dist/chunk-JJ57BXQR.js +0 -16
- package/dist/chunk-JP37ODNX.js +0 -36
- package/dist/chunk-K3N7KJHH.js +0 -52
- package/dist/chunk-MDM2JS2U.js +0 -1288
- package/dist/chunk-VOUPGVRD.js +0 -27
- package/dist/chunk-Z7JFMQZZ.js +0 -551
- /package/dist/{chunk-AE3H2QEY.js → chunk-ZDWFBE5L.js} +0 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { DefaultStorage } from './chunk-5HXXWLRX.js';
|
|
2
|
+
import { DefaultVectorDB } from './chunk-AN562ICT.js';
|
|
3
|
+
import { defaultEmbedder } from './chunk-ZJOXJFJI.js';
|
|
4
|
+
import { deepMerge } from './chunk-55GTEVHJ.js';
|
|
5
|
+
import { MastraBase } from './chunk-AWEACB2T.js';
|
|
6
|
+
|
|
7
|
+
// src/memory/memory.ts
|
|
8
|
+
var MastraMemory = class extends MastraBase {
|
|
9
|
+
MAX_CONTEXT_TOKENS;
|
|
10
|
+
storage;
|
|
11
|
+
vector;
|
|
12
|
+
embedder;
|
|
13
|
+
threadConfig = {
|
|
14
|
+
lastMessages: 40,
|
|
15
|
+
semanticRecall: true
|
|
16
|
+
};
|
|
17
|
+
constructor(config) {
|
|
18
|
+
super({ component: "MEMORY", name: config.name });
|
|
19
|
+
this.storage = config.storage || new DefaultStorage({
|
|
20
|
+
config: {
|
|
21
|
+
url: "file:memory.db"
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
if (config.vector) {
|
|
25
|
+
this.vector = config.vector;
|
|
26
|
+
} else {
|
|
27
|
+
this.vector = new DefaultVectorDB({
|
|
28
|
+
connectionUrl: "file:memory-vector.db"
|
|
29
|
+
// file name needs to be different than default storage or it wont work properly
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (config.embedder) {
|
|
33
|
+
this.embedder = config.embedder;
|
|
34
|
+
} else {
|
|
35
|
+
this.embedder = defaultEmbedder("bge-small-en-v1.5");
|
|
36
|
+
}
|
|
37
|
+
if (config.options) {
|
|
38
|
+
this.threadConfig = this.getMergedThreadConfig(config.options);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
setStorage(storage) {
|
|
42
|
+
this.storage = storage;
|
|
43
|
+
}
|
|
44
|
+
setVector(vector) {
|
|
45
|
+
this.vector = vector;
|
|
46
|
+
}
|
|
47
|
+
setEmbedder(embedder) {
|
|
48
|
+
this.embedder = embedder;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get a system message to inject into the conversation.
|
|
52
|
+
* This will be called before each conversation turn.
|
|
53
|
+
* Implementations can override this to inject custom system messages.
|
|
54
|
+
*/
|
|
55
|
+
async getSystemMessage(_input) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
async createEmbeddingIndex() {
|
|
59
|
+
const defaultDimensions = 1536;
|
|
60
|
+
const dimensionsByModelId = {
|
|
61
|
+
"bge-small-en-v1.5": 384,
|
|
62
|
+
"bge-base-en-v1.5": 768
|
|
63
|
+
};
|
|
64
|
+
const dimensions = dimensionsByModelId[this.embedder.modelId] || defaultDimensions;
|
|
65
|
+
const isDefault = dimensions === defaultDimensions;
|
|
66
|
+
const indexName = isDefault ? "memory_messages" : `memory_messages_${dimensions}`;
|
|
67
|
+
await this.vector.createIndex(indexName, dimensions);
|
|
68
|
+
return { indexName };
|
|
69
|
+
}
|
|
70
|
+
getMergedThreadConfig(config) {
|
|
71
|
+
return deepMerge(this.threadConfig, config || {});
|
|
72
|
+
}
|
|
73
|
+
estimateTokens(text) {
|
|
74
|
+
return Math.ceil(text.split(" ").length * 1.3);
|
|
75
|
+
}
|
|
76
|
+
parseMessages(messages) {
|
|
77
|
+
return messages.map((msg) => ({
|
|
78
|
+
...msg,
|
|
79
|
+
content: typeof msg.content === "string" && (msg.content.startsWith("[") || msg.content.startsWith("{")) ? JSON.parse(msg.content) : msg.content
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
convertToUIMessages(messages) {
|
|
83
|
+
function addToolMessageToChat({
|
|
84
|
+
toolMessage,
|
|
85
|
+
messages: messages2,
|
|
86
|
+
toolResultContents
|
|
87
|
+
}) {
|
|
88
|
+
const chatMessages2 = messages2.map((message) => {
|
|
89
|
+
if (message.toolInvocations) {
|
|
90
|
+
return {
|
|
91
|
+
...message,
|
|
92
|
+
toolInvocations: message.toolInvocations.map((toolInvocation) => {
|
|
93
|
+
const toolResult = toolMessage.content.find((tool) => tool.toolCallId === toolInvocation.toolCallId);
|
|
94
|
+
if (toolResult) {
|
|
95
|
+
return {
|
|
96
|
+
...toolInvocation,
|
|
97
|
+
state: "result",
|
|
98
|
+
result: toolResult.result
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return toolInvocation;
|
|
102
|
+
})
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return message;
|
|
106
|
+
});
|
|
107
|
+
const resultContents = [...toolResultContents, ...toolMessage.content];
|
|
108
|
+
return { chatMessages: chatMessages2, toolResultContents: resultContents };
|
|
109
|
+
}
|
|
110
|
+
const { chatMessages } = messages.reduce(
|
|
111
|
+
(obj, message) => {
|
|
112
|
+
if (message.role === "tool") {
|
|
113
|
+
return addToolMessageToChat({
|
|
114
|
+
toolMessage: message,
|
|
115
|
+
messages: obj.chatMessages,
|
|
116
|
+
toolResultContents: obj.toolResultContents
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
let textContent = "";
|
|
120
|
+
let toolInvocations = [];
|
|
121
|
+
if (typeof message.content === "string") {
|
|
122
|
+
textContent = message.content;
|
|
123
|
+
} else if (Array.isArray(message.content)) {
|
|
124
|
+
for (const content of message.content) {
|
|
125
|
+
if (content.type === "text") {
|
|
126
|
+
textContent += content.text;
|
|
127
|
+
} else if (content.type === "tool-call") {
|
|
128
|
+
const toolResult = obj.toolResultContents.find((tool) => tool.toolCallId === content.toolCallId);
|
|
129
|
+
toolInvocations.push({
|
|
130
|
+
state: toolResult ? "result" : "call",
|
|
131
|
+
toolCallId: content.toolCallId,
|
|
132
|
+
toolName: content.toolName,
|
|
133
|
+
args: content.args,
|
|
134
|
+
result: toolResult?.result
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
obj.chatMessages.push({
|
|
140
|
+
id: message.id,
|
|
141
|
+
role: message.role,
|
|
142
|
+
content: textContent,
|
|
143
|
+
toolInvocations
|
|
144
|
+
});
|
|
145
|
+
return obj;
|
|
146
|
+
},
|
|
147
|
+
{ chatMessages: [], toolResultContents: [] }
|
|
148
|
+
);
|
|
149
|
+
return chatMessages;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Helper method to create a new thread
|
|
153
|
+
* @param title - Optional title for the thread
|
|
154
|
+
* @param metadata - Optional metadata for the thread
|
|
155
|
+
* @returns Promise resolving to the created thread
|
|
156
|
+
*/
|
|
157
|
+
async createThread({
|
|
158
|
+
threadId,
|
|
159
|
+
resourceId,
|
|
160
|
+
title,
|
|
161
|
+
metadata,
|
|
162
|
+
memoryConfig
|
|
163
|
+
}) {
|
|
164
|
+
const thread = {
|
|
165
|
+
id: threadId || this.generateId(),
|
|
166
|
+
title: title || "New Thread",
|
|
167
|
+
resourceId,
|
|
168
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
169
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
170
|
+
metadata
|
|
171
|
+
};
|
|
172
|
+
return this.saveThread({ thread, memoryConfig });
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Helper method to add a single message to a thread
|
|
176
|
+
* @param threadId - The thread to add the message to
|
|
177
|
+
* @param content - The message content
|
|
178
|
+
* @param role - The role of the message sender
|
|
179
|
+
* @param type - The type of the message
|
|
180
|
+
* @param toolNames - Optional array of tool names that were called
|
|
181
|
+
* @param toolCallArgs - Optional array of tool call arguments
|
|
182
|
+
* @param toolCallIds - Optional array of tool call ids
|
|
183
|
+
* @returns Promise resolving to the saved message
|
|
184
|
+
*/
|
|
185
|
+
async addMessage({
|
|
186
|
+
threadId,
|
|
187
|
+
config,
|
|
188
|
+
content,
|
|
189
|
+
role,
|
|
190
|
+
type,
|
|
191
|
+
toolNames,
|
|
192
|
+
toolCallArgs,
|
|
193
|
+
toolCallIds
|
|
194
|
+
}) {
|
|
195
|
+
const message = {
|
|
196
|
+
id: this.generateId(),
|
|
197
|
+
content,
|
|
198
|
+
role,
|
|
199
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
200
|
+
threadId,
|
|
201
|
+
type,
|
|
202
|
+
toolNames,
|
|
203
|
+
toolCallArgs,
|
|
204
|
+
toolCallIds
|
|
205
|
+
};
|
|
206
|
+
const savedMessages = await this.saveMessages({ messages: [message], memoryConfig: config });
|
|
207
|
+
return savedMessages[0];
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Generates a unique identifier
|
|
211
|
+
* @returns A unique string ID
|
|
212
|
+
*/
|
|
213
|
+
generateId() {
|
|
214
|
+
return crypto.randomUUID();
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export { MastraMemory };
|
|
@@ -1,31 +1,25 @@
|
|
|
1
|
-
import { DefaultStorage } from './chunk-
|
|
2
|
-
import { InstrumentClass, Telemetry } from './chunk-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { DefaultStorage } from './chunk-5HXXWLRX.js';
|
|
2
|
+
import { InstrumentClass, OTLPTraceExporter, Telemetry } from './chunk-4ZRHVG25.js';
|
|
3
|
+
import { createLogger, LogLevel, noopLogger } from './chunk-O2VP5JBC.js';
|
|
4
|
+
import { __decoratorStart, __decorateElement, __runInitializers } from './chunk-C6A6W6XS.js';
|
|
5
5
|
|
|
6
6
|
// src/mastra/index.ts
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
var _Mastra_decorators, _init;
|
|
8
|
+
_Mastra_decorators = [InstrumentClass({
|
|
9
|
+
prefix: "mastra",
|
|
10
|
+
excludeMethods: ["getLogger", "getTelemetry"]
|
|
11
|
+
})];
|
|
12
|
+
var Mastra = class {
|
|
13
|
+
vectors;
|
|
14
|
+
agents;
|
|
15
|
+
logger;
|
|
16
|
+
workflows;
|
|
17
|
+
telemetry;
|
|
18
|
+
tts;
|
|
19
|
+
deployer;
|
|
20
|
+
storage;
|
|
21
|
+
memory;
|
|
19
22
|
constructor(config) {
|
|
20
|
-
__publicField(this, "vectors");
|
|
21
|
-
__publicField(this, "agents");
|
|
22
|
-
__publicField(this, "logger");
|
|
23
|
-
__publicField(this, "workflows");
|
|
24
|
-
__publicField(this, "telemetry");
|
|
25
|
-
__publicField(this, "tts");
|
|
26
|
-
__publicField(this, "deployer");
|
|
27
|
-
__publicField(this, "storage");
|
|
28
|
-
__publicField(this, "memory");
|
|
29
23
|
let logger;
|
|
30
24
|
if (config?.logger === false) {
|
|
31
25
|
logger = noopLogger;
|
|
@@ -41,35 +35,41 @@ var _Mastra = class _Mastra {
|
|
|
41
35
|
}
|
|
42
36
|
}
|
|
43
37
|
this.logger = logger;
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
let storage = config?.storage;
|
|
39
|
+
if (!storage) {
|
|
40
|
+
storage = new DefaultStorage({
|
|
41
|
+
config: {
|
|
42
|
+
url: process.env.MASTRA_DEFAULT_STORAGE_URL || `:memory:`
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (storage instanceof DefaultStorage && config?.telemetry?.export?.type !== "custom") {
|
|
47
|
+
const newTelemetry = {
|
|
48
|
+
...(config?.telemetry || {}),
|
|
49
|
+
export: {
|
|
50
|
+
type: "custom",
|
|
51
|
+
exporter: new OTLPTraceExporter({
|
|
52
|
+
logger: this.getLogger(),
|
|
53
|
+
storage
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
this.telemetry = Telemetry.init(newTelemetry);
|
|
58
|
+
} else if (config?.telemetry) {
|
|
59
|
+
this.telemetry = Telemetry.init(config?.telemetry);
|
|
46
60
|
}
|
|
47
61
|
if (config?.deployer) {
|
|
48
62
|
this.deployer = config.deployer;
|
|
49
63
|
if (this.telemetry) {
|
|
50
64
|
this.deployer = this.telemetry.traceClass(config.deployer, {
|
|
51
|
-
excludeMethods: [
|
|
52
|
-
"__setTelemetry",
|
|
53
|
-
"__getTelemetry"
|
|
54
|
-
]
|
|
65
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
55
66
|
});
|
|
56
67
|
this.deployer.__setTelemetry(this.telemetry);
|
|
57
68
|
}
|
|
58
69
|
}
|
|
59
|
-
let storage = config?.storage;
|
|
60
|
-
if (!storage) {
|
|
61
|
-
storage = new DefaultStorage({
|
|
62
|
-
config: {
|
|
63
|
-
url: ":memory:"
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
70
|
if (this.telemetry) {
|
|
68
71
|
this.storage = this.telemetry.traceClass(storage, {
|
|
69
|
-
excludeMethods: [
|
|
70
|
-
"__setTelemetry",
|
|
71
|
-
"__getTelemetry"
|
|
72
|
-
]
|
|
72
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
73
73
|
});
|
|
74
74
|
this.storage.__setTelemetry(this.telemetry);
|
|
75
75
|
} else {
|
|
@@ -80,10 +80,7 @@ var _Mastra = class _Mastra {
|
|
|
80
80
|
Object.entries(config.vectors).forEach(([key, vector]) => {
|
|
81
81
|
if (this.telemetry) {
|
|
82
82
|
vectors[key] = this.telemetry.traceClass(vector, {
|
|
83
|
-
excludeMethods: [
|
|
84
|
-
"__setTelemetry",
|
|
85
|
-
"__getTelemetry"
|
|
86
|
-
]
|
|
83
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
87
84
|
});
|
|
88
85
|
vectors[key].__setTelemetry(this.telemetry);
|
|
89
86
|
} else {
|
|
@@ -99,10 +96,7 @@ var _Mastra = class _Mastra {
|
|
|
99
96
|
this.memory = config.memory;
|
|
100
97
|
if (this.telemetry) {
|
|
101
98
|
this.memory = this.telemetry.traceClass(config.memory, {
|
|
102
|
-
excludeMethods: [
|
|
103
|
-
"__setTelemetry",
|
|
104
|
-
"__getTelemetry"
|
|
105
|
-
]
|
|
99
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
106
100
|
});
|
|
107
101
|
this.memory.__setTelemetry(this.telemetry);
|
|
108
102
|
}
|
|
@@ -113,10 +107,7 @@ var _Mastra = class _Mastra {
|
|
|
113
107
|
if (this.tts?.[key]) {
|
|
114
108
|
if (this.telemetry) {
|
|
115
109
|
this.tts[key] = this.telemetry.traceClass(ttsCl, {
|
|
116
|
-
excludeMethods: [
|
|
117
|
-
"__setTelemetry",
|
|
118
|
-
"__getTelemetry"
|
|
119
|
-
]
|
|
110
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
120
111
|
});
|
|
121
112
|
this.tts[key].__setTelemetry(this.telemetry);
|
|
122
113
|
}
|
|
@@ -184,7 +175,9 @@ var _Mastra = class _Mastra {
|
|
|
184
175
|
getDeployer() {
|
|
185
176
|
return this.deployer;
|
|
186
177
|
}
|
|
187
|
-
getWorkflow(id, {
|
|
178
|
+
getWorkflow(id, {
|
|
179
|
+
serialized
|
|
180
|
+
} = {}) {
|
|
188
181
|
const workflow = this.workflows?.[id];
|
|
189
182
|
if (!workflow) {
|
|
190
183
|
throw new Error(`Workflow with ID ${String(id)} not found`);
|
|
@@ -209,18 +202,20 @@ var _Mastra = class _Mastra {
|
|
|
209
202
|
}
|
|
210
203
|
return this.workflows;
|
|
211
204
|
}
|
|
212
|
-
setStorage(
|
|
205
|
+
setStorage(storage) {
|
|
213
206
|
this.storage = storage;
|
|
214
207
|
}
|
|
215
|
-
setLogger({
|
|
208
|
+
setLogger({
|
|
209
|
+
logger
|
|
210
|
+
}) {
|
|
216
211
|
this.logger = logger;
|
|
217
212
|
if (this.agents) {
|
|
218
|
-
Object.keys(this.agents).forEach(
|
|
213
|
+
Object.keys(this.agents).forEach(key => {
|
|
219
214
|
this.agents?.[key]?.__setLogger(this.logger);
|
|
220
215
|
});
|
|
221
216
|
}
|
|
222
217
|
if (this.workflows) {
|
|
223
|
-
Object.keys(this.workflows).forEach(
|
|
218
|
+
Object.keys(this.workflows).forEach(key => {
|
|
224
219
|
this.workflows?.[key]?.__setLogger(this.logger);
|
|
225
220
|
});
|
|
226
221
|
}
|
|
@@ -231,7 +226,7 @@ var _Mastra = class _Mastra {
|
|
|
231
226
|
this.deployer.__setLogger(this.logger);
|
|
232
227
|
}
|
|
233
228
|
if (this.tts) {
|
|
234
|
-
Object.keys(this.tts).forEach(
|
|
229
|
+
Object.keys(this.tts).forEach(key => {
|
|
235
230
|
this.tts?.[key]?.__setLogger(this.logger);
|
|
236
231
|
});
|
|
237
232
|
}
|
|
@@ -239,18 +234,80 @@ var _Mastra = class _Mastra {
|
|
|
239
234
|
this.storage.__setLogger(this.logger);
|
|
240
235
|
}
|
|
241
236
|
if (this.vectors) {
|
|
242
|
-
Object.keys(this.vectors).forEach(
|
|
237
|
+
Object.keys(this.vectors).forEach(key => {
|
|
243
238
|
this.vectors?.[key]?.__setLogger(this.logger);
|
|
244
239
|
});
|
|
245
240
|
}
|
|
246
241
|
}
|
|
242
|
+
setTelemetry(telemetry) {
|
|
243
|
+
this.telemetry = Telemetry.init(telemetry);
|
|
244
|
+
if (this.agents) {
|
|
245
|
+
Object.keys(this.agents).forEach(key => {
|
|
246
|
+
if (this.telemetry) {
|
|
247
|
+
this.agents?.[key]?.__setTelemetry(this.telemetry);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
if (this.workflows) {
|
|
252
|
+
Object.keys(this.workflows).forEach(key => {
|
|
253
|
+
if (this.telemetry) {
|
|
254
|
+
this.workflows?.[key]?.__setTelemetry(this.telemetry);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
if (this.memory) {
|
|
259
|
+
this.memory = this.telemetry.traceClass(this.memory, {
|
|
260
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
261
|
+
});
|
|
262
|
+
this.memory.__setTelemetry(this.telemetry);
|
|
263
|
+
}
|
|
264
|
+
if (this.deployer) {
|
|
265
|
+
this.deployer = this.telemetry.traceClass(this.deployer, {
|
|
266
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
267
|
+
});
|
|
268
|
+
this.deployer.__setTelemetry(this.telemetry);
|
|
269
|
+
}
|
|
270
|
+
if (this.tts) {
|
|
271
|
+
let tts = {};
|
|
272
|
+
Object.entries(this.tts).forEach(([key, ttsCl]) => {
|
|
273
|
+
if (this.telemetry) {
|
|
274
|
+
tts[key] = this.telemetry.traceClass(ttsCl, {
|
|
275
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
276
|
+
});
|
|
277
|
+
tts[key].__setTelemetry(this.telemetry);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
this.tts = tts;
|
|
281
|
+
}
|
|
282
|
+
if (this.storage) {
|
|
283
|
+
this.storage = this.telemetry.traceClass(this.storage, {
|
|
284
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
285
|
+
});
|
|
286
|
+
this.storage.__setTelemetry(this.telemetry);
|
|
287
|
+
}
|
|
288
|
+
if (this.vectors) {
|
|
289
|
+
let vectors = {};
|
|
290
|
+
Object.entries(this.vectors).forEach(([key, vector]) => {
|
|
291
|
+
if (this.telemetry) {
|
|
292
|
+
vectors[key] = this.telemetry.traceClass(vector, {
|
|
293
|
+
excludeMethods: ["__setTelemetry", "__getTelemetry"]
|
|
294
|
+
});
|
|
295
|
+
vectors[key].__setTelemetry(this.telemetry);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
this.vectors = vectors;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
247
301
|
getLogger() {
|
|
248
302
|
return this.logger;
|
|
249
303
|
}
|
|
250
304
|
getTelemetry() {
|
|
251
305
|
return this.telemetry;
|
|
252
306
|
}
|
|
253
|
-
async getLogsByRunId({
|
|
307
|
+
async getLogsByRunId({
|
|
308
|
+
runId,
|
|
309
|
+
transportId
|
|
310
|
+
}) {
|
|
254
311
|
if (!transportId) {
|
|
255
312
|
throw new Error("Transport ID is required");
|
|
256
313
|
}
|
|
@@ -266,20 +323,11 @@ var _Mastra = class _Mastra {
|
|
|
266
323
|
return await this.logger.getLogs(transportId);
|
|
267
324
|
}
|
|
268
325
|
};
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
Mastra =
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
"getLogger",
|
|
276
|
-
"getTelemetry"
|
|
277
|
-
]
|
|
278
|
-
}),
|
|
279
|
-
_ts_metadata("design:type", Function),
|
|
280
|
-
_ts_metadata("design:paramtypes", [
|
|
281
|
-
Object
|
|
282
|
-
])
|
|
283
|
-
], Mastra);
|
|
326
|
+
Mastra = /*@__PURE__*/(_ => {
|
|
327
|
+
_init = __decoratorStart(null);
|
|
328
|
+
Mastra = __decorateElement(_init, 0, "Mastra", _Mastra_decorators, Mastra);
|
|
329
|
+
__runInitializers(_init, 1, Mastra);
|
|
330
|
+
return Mastra;
|
|
331
|
+
})();
|
|
284
332
|
|
|
285
333
|
export { Mastra };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/tools/tool.ts
|
|
2
|
+
var Tool = class {
|
|
3
|
+
id;
|
|
4
|
+
description;
|
|
5
|
+
inputSchema;
|
|
6
|
+
outputSchema;
|
|
7
|
+
execute;
|
|
8
|
+
mastra;
|
|
9
|
+
constructor(opts) {
|
|
10
|
+
this.id = opts.id;
|
|
11
|
+
this.description = opts.description;
|
|
12
|
+
this.inputSchema = opts.inputSchema;
|
|
13
|
+
this.outputSchema = opts.outputSchema;
|
|
14
|
+
this.execute = opts.execute;
|
|
15
|
+
this.mastra = opts.mastra;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function createTool(opts) {
|
|
19
|
+
return new Tool(opts);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { Tool, createTool };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { MastraBase } from './chunk-
|
|
2
|
-
import { __name } from './chunk-AJJZUHB4.js';
|
|
1
|
+
import { MastraBase } from './chunk-AWEACB2T.js';
|
|
3
2
|
import { experimental_customProvider } from 'ai';
|
|
4
3
|
import node_modulesPath from 'node_modules-path';
|
|
5
4
|
import path from 'path';
|
|
@@ -11,11 +10,45 @@ function getModelCachePath() {
|
|
|
11
10
|
cachedPath = path.join(firstNodeModules, "node_modules", ".fastembed-model-cache");
|
|
12
11
|
return cachedPath;
|
|
13
12
|
}
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
function unbundleableImport(name) {
|
|
14
|
+
const nonStaticallyAnalyzableName = `${name}?d=${Date.now()}`;
|
|
15
|
+
return import(nonStaticallyAnalyzableName.split(`?`)[0]);
|
|
16
|
+
}
|
|
16
17
|
async function generateEmbeddings(values, modelType) {
|
|
17
18
|
try {
|
|
18
|
-
|
|
19
|
+
let mod;
|
|
20
|
+
const importErrors = [];
|
|
21
|
+
{
|
|
22
|
+
try {
|
|
23
|
+
mod = await unbundleableImport("fastembed");
|
|
24
|
+
} catch (e) {
|
|
25
|
+
if (e instanceof Error) {
|
|
26
|
+
importErrors.push(e);
|
|
27
|
+
} else {
|
|
28
|
+
throw e;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (!mod) {
|
|
33
|
+
throw new Error(`${importErrors.map((e) => e.message).join(`
|
|
34
|
+
`)}
|
|
35
|
+
|
|
36
|
+
This runtime does not support fastembed-js, which is the default embedder in Mastra.
|
|
37
|
+
Scroll up to read import errors. These errors mean you can't use the default Mastra embedder on this hosting platform.
|
|
38
|
+
You can either use Mastra Cloud which supports the default embedder, or you can configure an alternate provider.
|
|
39
|
+
|
|
40
|
+
For example if you're using Memory:
|
|
41
|
+
|
|
42
|
+
import { openai } from "@ai-sdk/openai";
|
|
43
|
+
|
|
44
|
+
const memory = new Memory({
|
|
45
|
+
embedder: openai.embedding("text-embedding-3-small"), // <- doesn't have to be openai
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
Visit https://sdk.vercel.ai/docs/foundations/overview#embedding-models to find an alternate embedding provider
|
|
49
|
+
`);
|
|
50
|
+
}
|
|
51
|
+
const { FlagEmbedding, EmbeddingModel } = mod;
|
|
19
52
|
const model = await FlagEmbedding.init({
|
|
20
53
|
model: EmbeddingModel[modelType],
|
|
21
54
|
cacheDir: getModelCachePath()
|
|
@@ -34,7 +67,6 @@ async function generateEmbeddings(values, modelType) {
|
|
|
34
67
|
throw error;
|
|
35
68
|
}
|
|
36
69
|
}
|
|
37
|
-
__name(generateEmbeddings, "generateEmbeddings");
|
|
38
70
|
var fastEmbedProvider = experimental_customProvider({
|
|
39
71
|
textEmbeddingModels: {
|
|
40
72
|
"bge-small-en-v1.5": {
|
|
@@ -59,18 +91,13 @@ var fastEmbedProvider = experimental_customProvider({
|
|
|
59
91
|
}
|
|
60
92
|
}
|
|
61
93
|
});
|
|
62
|
-
var
|
|
94
|
+
var defaultEmbedder = fastEmbedProvider.textEmbeddingModel;
|
|
63
95
|
|
|
64
96
|
// src/vector/index.ts
|
|
65
|
-
var
|
|
97
|
+
var MastraVector = class extends MastraBase {
|
|
66
98
|
constructor() {
|
|
67
|
-
super({
|
|
68
|
-
name: "MastraVector",
|
|
69
|
-
component: "VECTOR"
|
|
70
|
-
});
|
|
99
|
+
super({ name: "MastraVector", component: "VECTOR" });
|
|
71
100
|
}
|
|
72
101
|
};
|
|
73
|
-
__name(_MastraVector, "MastraVector");
|
|
74
|
-
var MastraVector = _MastraVector;
|
|
75
102
|
|
|
76
|
-
export { MastraVector,
|
|
103
|
+
export { MastraVector, defaultEmbedder };
|
package/dist/deployer/index.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../base.js';
|
|
1
|
+
import { MastraBundler, IBundler } from '../bundler/index.js';
|
|
2
|
+
import '../base-BbtPAA6f.js';
|
|
3
3
|
import '@opentelemetry/api';
|
|
4
|
-
import '../index-
|
|
4
|
+
import '../index-B2JCcAQt.js';
|
|
5
5
|
import 'pino';
|
|
6
6
|
import 'stream';
|
|
7
|
-
import '../telemetry-oCUM52DG.js';
|
|
8
|
-
import '@opentelemetry/sdk-node';
|
|
9
7
|
import '@opentelemetry/sdk-trace-base';
|
|
10
8
|
|
|
11
9
|
interface IDeployer extends IBundler {
|
package/dist/deployer/index.js
CHANGED
package/dist/eval/index.d.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import { a as Metric, M as MetricResult } from '../
|
|
2
|
-
import { A as Agent } from '../
|
|
1
|
+
import { a as Metric, T as TestInfo, M as MetricResult } from '../types-m9RryK9a.js';
|
|
2
|
+
import { A as Agent } from '../base-C7R9FwZ6.js';
|
|
3
3
|
import 'ai';
|
|
4
|
-
import '
|
|
5
|
-
import 'zod';
|
|
6
|
-
import '../base.js';
|
|
4
|
+
import '../base-BbtPAA6f.js';
|
|
7
5
|
import '@opentelemetry/api';
|
|
8
|
-
import '../index-
|
|
6
|
+
import '../index-B2JCcAQt.js';
|
|
9
7
|
import 'pino';
|
|
10
8
|
import 'stream';
|
|
11
|
-
import '../telemetry-oCUM52DG.js';
|
|
12
|
-
import '@opentelemetry/sdk-node';
|
|
13
9
|
import '@opentelemetry/sdk-trace-base';
|
|
14
10
|
import 'sift';
|
|
11
|
+
import 'zod';
|
|
12
|
+
import 'json-schema';
|
|
15
13
|
import '../vector/index.js';
|
|
16
14
|
import '../tts/index.js';
|
|
17
15
|
|
|
@@ -22,11 +20,8 @@ declare function evaluate<T extends Agent>({ agentName, input, metric, output, r
|
|
|
22
20
|
output: string;
|
|
23
21
|
globalRunId: string;
|
|
24
22
|
runId?: string;
|
|
25
|
-
testInfo?:
|
|
26
|
-
testName?: string;
|
|
27
|
-
testPath?: string;
|
|
28
|
-
} | null;
|
|
23
|
+
testInfo?: TestInfo;
|
|
29
24
|
instructions: string;
|
|
30
25
|
}): Promise<MetricResult>;
|
|
31
26
|
|
|
32
|
-
export { Metric, MetricResult, evaluate };
|
|
27
|
+
export { Metric, MetricResult, TestInfo, evaluate };
|
package/dist/eval/index.js
CHANGED