@mastra/core 0.5.0-alpha.9 → 0.5.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.
Files changed (91) hide show
  1. package/dist/agent/index.cjs +3 -2140
  2. package/dist/agent/index.d.cts +1 -1
  3. package/dist/agent/index.d.ts +1 -1
  4. package/dist/agent/index.js +1 -1
  5. package/dist/{base-CMEKtEnE.d.cts → base-CIPKleAU.d.cts} +97 -60
  6. package/dist/{base-B78F6w8S.d.ts → base-C_Oq53qk.d.ts} +97 -60
  7. package/dist/base.cjs +5 -140
  8. package/dist/bundler/index.cjs +5 -160
  9. package/dist/chunk-2W2GYEYQ.cjs +25 -0
  10. package/dist/chunk-3ASEZT7U.cjs +1586 -0
  11. package/dist/chunk-43Y7WG5W.cjs +335 -0
  12. package/dist/{chunk-IM7CM3DU.js → chunk-4Y74D74B.js} +1 -1
  13. package/dist/chunk-ENT7U27Y.cjs +37 -0
  14. package/dist/chunk-F5UYWPV4.cjs +14 -0
  15. package/dist/chunk-FL3GQXQ2.cjs +218 -0
  16. package/dist/chunk-FRQFWZDN.cjs +2 -0
  17. package/dist/chunk-GXQRMKSN.cjs +367 -0
  18. package/dist/chunk-HJPMYDWO.cjs +37 -0
  19. package/dist/chunk-IIWRJFLQ.cjs +51 -0
  20. package/dist/chunk-KFQ7Z3PO.cjs +347 -0
  21. package/dist/{chunk-TWAIC2XA.js → chunk-KP5UAFLN.js} +1 -1
  22. package/dist/chunk-KPKFLQFR.cjs +12 -0
  23. package/dist/{chunk-NR5T72G7.js → chunk-MLFXOST6.js} +1 -1
  24. package/dist/{chunk-6V737PR2.js → chunk-OD7ZMKHY.js} +166 -58
  25. package/dist/chunk-OTFLHXHZ.cjs +65 -0
  26. package/dist/chunk-RWTSGWWL.cjs +81 -0
  27. package/dist/chunk-ST5RMVLG.cjs +87 -0
  28. package/dist/chunk-SYQ7NK2E.cjs +24 -0
  29. package/dist/chunk-UZNQG7QO.cjs +1868 -0
  30. package/dist/chunk-V5ORZPFW.cjs +38 -0
  31. package/dist/chunk-VA4P7QJT.cjs +443 -0
  32. package/dist/chunk-WB2HREXE.cjs +166 -0
  33. package/dist/chunk-WOMOGDGR.cjs +691 -0
  34. package/dist/chunk-XB2TJ7LX.cjs +408 -0
  35. package/dist/{chunk-4AQBRUR2.js → chunk-XF2FMJYK.js} +1 -1
  36. package/dist/chunk-XLSROQ26.cjs +91 -0
  37. package/dist/chunk-YK3XJ52U.cjs +192 -0
  38. package/dist/{chunk-EWB556GS.js → chunk-YPD6BQIM.js} +29 -1
  39. package/dist/deployer/index.cjs +5 -167
  40. package/dist/eval/index.cjs +9 -105
  41. package/dist/eval/index.d.cts +1 -1
  42. package/dist/eval/index.d.ts +1 -1
  43. package/dist/hooks/index.cjs +14 -83
  44. package/dist/index.cjs +253 -7516
  45. package/dist/index.d.cts +3 -3
  46. package/dist/index.d.ts +3 -3
  47. package/dist/index.js +7 -7
  48. package/dist/integration/index.cjs +9 -108
  49. package/dist/integration/index.d.cts +1 -1
  50. package/dist/integration/index.d.ts +1 -1
  51. package/dist/llm/index.d.cts +1 -1
  52. package/dist/llm/index.d.ts +1 -1
  53. package/dist/logger/index.cjs +33 -161
  54. package/dist/mastra/index.cjs +3 -1755
  55. package/dist/mastra/index.d.cts +1 -1
  56. package/dist/mastra/index.d.ts +1 -1
  57. package/dist/mastra/index.js +1 -1
  58. package/dist/memory/index.cjs +4 -2050
  59. package/dist/memory/index.d.cts +1 -1
  60. package/dist/memory/index.d.ts +1 -1
  61. package/dist/memory/index.js +1 -1
  62. package/dist/relevance/index.cjs +10 -2201
  63. package/dist/relevance/index.d.cts +19 -2
  64. package/dist/relevance/index.d.ts +19 -2
  65. package/dist/relevance/index.js +1 -1
  66. package/dist/storage/index.cjs +29 -367
  67. package/dist/storage/index.d.cts +1 -1
  68. package/dist/storage/index.d.ts +1 -1
  69. package/dist/storage/libsql/index.cjs +9 -798
  70. package/dist/storage/libsql/index.d.cts +1 -1
  71. package/dist/storage/libsql/index.d.ts +1 -1
  72. package/dist/telemetry/index.cjs +21 -408
  73. package/dist/telemetry/index.d.cts +1 -1
  74. package/dist/telemetry/index.d.ts +1 -1
  75. package/dist/tools/index.cjs +11 -22
  76. package/dist/tools/index.d.cts +3 -3
  77. package/dist/tools/index.d.ts +3 -3
  78. package/dist/tts/index.cjs +3 -328
  79. package/dist/utils.cjs +41 -350
  80. package/dist/utils.d.cts +3 -3
  81. package/dist/utils.d.ts +3 -3
  82. package/dist/utils.js +1 -1
  83. package/dist/vector/filter/index.cjs +7 -189
  84. package/dist/vector/index.cjs +5 -172
  85. package/dist/vector/libsql/index.cjs +9 -1047
  86. package/dist/voice/index.cjs +8 -306
  87. package/dist/workflows/index.cjs +65 -1936
  88. package/dist/workflows/index.d.cts +4 -3
  89. package/dist/workflows/index.d.ts +4 -3
  90. package/dist/workflows/index.js +1 -1
  91. package/package.json +27 -27
@@ -0,0 +1,347 @@
1
+ 'use strict';
2
+
3
+ var chunkWOMOGDGR_cjs = require('./chunk-WOMOGDGR.cjs');
4
+ var chunkVA4P7QJT_cjs = require('./chunk-VA4P7QJT.cjs');
5
+ var chunk43Y7WG5W_cjs = require('./chunk-43Y7WG5W.cjs');
6
+ var chunkIIWRJFLQ_cjs = require('./chunk-IIWRJFLQ.cjs');
7
+ var fs = require('fs');
8
+ var path = require('path');
9
+ var ai = require('ai');
10
+ var node_modulesPath = require('node_modules-path');
11
+
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
+
14
+ var path__default = /*#__PURE__*/_interopDefault(path);
15
+ var node_modulesPath__default = /*#__PURE__*/_interopDefault(node_modulesPath);
16
+
17
+ var cachedPath = false;
18
+ function getModelCachePath() {
19
+ if (cachedPath) return cachedPath;
20
+ const firstNodeModules = node_modulesPath__default.default().split("node_modules")[0];
21
+ cachedPath = path__default.default.join(firstNodeModules, "node_modules", ".fastembed-model-cache");
22
+ return cachedPath;
23
+ }
24
+ function unbundleableImport(name) {
25
+ const nonStaticallyAnalyzableName = `${name}?d=${Date.now()}`;
26
+ return import(nonStaticallyAnalyzableName.split(`?`)[0]);
27
+ }
28
+ async function generateEmbeddings(values, modelType) {
29
+ try {
30
+ let mod;
31
+ const importErrors = [];
32
+ {
33
+ try {
34
+ mod = await unbundleableImport("fastembed");
35
+ } catch (e) {
36
+ if (e instanceof Error) {
37
+ importErrors.push(e);
38
+ } else {
39
+ throw e;
40
+ }
41
+ }
42
+ }
43
+ if (!mod) {
44
+ throw new Error(`${importErrors.map((e) => e.message).join(`
45
+ `)}
46
+
47
+ This runtime does not support fastembed-js, which is the default embedder in Mastra.
48
+ Scroll up to read import errors. These errors mean you can't use the default Mastra embedder on this hosting platform.
49
+ You can either use Mastra Cloud which supports the default embedder, or you can configure an alternate provider.
50
+
51
+ For example if you're using Memory:
52
+
53
+ import { openai } from "@ai-sdk/openai";
54
+
55
+ const memory = new Memory({
56
+ embedder: openai.embedding("text-embedding-3-small"), // <- doesn't have to be openai
57
+ })
58
+
59
+ Visit https://sdk.vercel.ai/docs/foundations/overview#embedding-models to find an alternate embedding provider
60
+
61
+ If you do not want to use the Memory semantic recall feature, you can disable it entirely and this error will go away.
62
+
63
+ const memory = new Memory({
64
+ options: {
65
+ semanticRecall: false // <- an embedder will not be required with this set to false
66
+ }
67
+ })
68
+ `);
69
+ }
70
+ const { FlagEmbedding, EmbeddingModel } = mod;
71
+ const model = await FlagEmbedding.init({
72
+ model: EmbeddingModel[modelType],
73
+ cacheDir: getModelCachePath()
74
+ });
75
+ const embeddings = await model.embed(values);
76
+ const allResults = [];
77
+ for await (const result of embeddings) {
78
+ allResults.push(...result.map((embedding) => Array.from(embedding)));
79
+ }
80
+ if (allResults.length === 0) throw new Error("No embeddings generated");
81
+ return {
82
+ embeddings: allResults
83
+ };
84
+ } catch (error) {
85
+ console.error("Error generating embeddings:", error);
86
+ throw error;
87
+ }
88
+ }
89
+ var fastEmbedProvider = ai.experimental_customProvider({
90
+ textEmbeddingModels: {
91
+ "bge-small-en-v1.5": {
92
+ specificationVersion: "v1",
93
+ provider: "fastembed",
94
+ modelId: "bge-small-en-v1.5",
95
+ maxEmbeddingsPerCall: 256,
96
+ supportsParallelCalls: true,
97
+ async doEmbed({ values }) {
98
+ return generateEmbeddings(values, "BGESmallENV15");
99
+ }
100
+ },
101
+ "bge-base-en-v1.5": {
102
+ specificationVersion: "v1",
103
+ provider: "fastembed",
104
+ modelId: "bge-base-en-v1.5",
105
+ maxEmbeddingsPerCall: 256,
106
+ supportsParallelCalls: true,
107
+ async doEmbed({ values }) {
108
+ return generateEmbeddings(values, "BGEBaseENV15");
109
+ }
110
+ }
111
+ }
112
+ });
113
+ var defaultEmbedder = fastEmbedProvider.textEmbeddingModel;
114
+
115
+ // src/memory/memory.ts
116
+ var MastraMemory = class extends chunkIIWRJFLQ_cjs.MastraBase {
117
+ MAX_CONTEXT_TOKENS;
118
+ storage;
119
+ vector;
120
+ embedder;
121
+ threadConfig = {
122
+ lastMessages: 40,
123
+ semanticRecall: true,
124
+ threads: {
125
+ generateTitle: true
126
+ // TODO: should we disable this by default to reduce latency?
127
+ }
128
+ };
129
+ constructor(config) {
130
+ super({ component: "MEMORY", name: config.name });
131
+ this.storage = config.storage || new chunkVA4P7QJT_cjs.LibSQLStore({
132
+ config: {
133
+ url: "file:memory.db"
134
+ }
135
+ });
136
+ if (config.vector) {
137
+ this.vector = config.vector;
138
+ } else {
139
+ const oldDb = "memory-vector.db";
140
+ const hasOldDb = fs.existsSync(path.join(process.cwd(), oldDb)) || fs.existsSync(path.join(process.cwd(), ".mastra", oldDb));
141
+ const newDb = "memory.db";
142
+ if (hasOldDb) {
143
+ this.logger.warn(
144
+ `Found deprecated Memory vector db file ${oldDb} this db is now merged with the default ${newDb} file. Delete the old one to use the new one. You will need to migrate any data if that's important to you. For now the deprecated path will be used but in a future breaking change we will only use the new db file path.`
145
+ );
146
+ }
147
+ this.vector = new chunkWOMOGDGR_cjs.LibSQLVector({
148
+ connectionUrl: hasOldDb ? `file:${oldDb}` : `file:${newDb}`
149
+ });
150
+ }
151
+ if (config.embedder) {
152
+ this.embedder = config.embedder;
153
+ } else {
154
+ this.embedder = defaultEmbedder("bge-small-en-v1.5");
155
+ }
156
+ if (config.options) {
157
+ this.threadConfig = this.getMergedThreadConfig(config.options);
158
+ }
159
+ }
160
+ setStorage(storage) {
161
+ this.storage = storage;
162
+ }
163
+ setVector(vector) {
164
+ this.vector = vector;
165
+ }
166
+ setEmbedder(embedder) {
167
+ this.embedder = embedder;
168
+ }
169
+ /**
170
+ * Get a system message to inject into the conversation.
171
+ * This will be called before each conversation turn.
172
+ * Implementations can override this to inject custom system messages.
173
+ */
174
+ async getSystemMessage(_input) {
175
+ return null;
176
+ }
177
+ /**
178
+ * Get tools that should be available to the agent.
179
+ * This will be called when converting tools for the agent.
180
+ * Implementations can override this to provide additional tools.
181
+ */
182
+ getTools(_config) {
183
+ return {};
184
+ }
185
+ async createEmbeddingIndex() {
186
+ const defaultDimensions = 1536;
187
+ const dimensionsByModelId = {
188
+ "bge-small-en-v1.5": 384,
189
+ "bge-base-en-v1.5": 768
190
+ };
191
+ const dimensions = dimensionsByModelId[this.embedder.modelId] || defaultDimensions;
192
+ const isDefault = dimensions === defaultDimensions;
193
+ const indexName = isDefault ? "memory_messages" : `memory_messages_${dimensions}`;
194
+ await this.vector.createIndex({ indexName, dimension: dimensions });
195
+ return { indexName };
196
+ }
197
+ getMergedThreadConfig(config) {
198
+ return chunk43Y7WG5W_cjs.deepMerge(this.threadConfig, config || {});
199
+ }
200
+ estimateTokens(text) {
201
+ return Math.ceil(text.split(" ").length * 1.3);
202
+ }
203
+ parseMessages(messages) {
204
+ return messages.map((msg) => ({
205
+ ...msg,
206
+ content: typeof msg.content === "string" && (msg.content.startsWith("[") || msg.content.startsWith("{")) ? JSON.parse(msg.content) : typeof msg.content === "number" ? String(msg.content) : msg.content
207
+ }));
208
+ }
209
+ convertToUIMessages(messages) {
210
+ function addToolMessageToChat({
211
+ toolMessage,
212
+ messages: messages2,
213
+ toolResultContents
214
+ }) {
215
+ const chatMessages2 = messages2.map((message) => {
216
+ if (message.toolInvocations) {
217
+ return {
218
+ ...message,
219
+ toolInvocations: message.toolInvocations.map((toolInvocation) => {
220
+ const toolResult = toolMessage.content.find((tool) => tool.toolCallId === toolInvocation.toolCallId);
221
+ if (toolResult) {
222
+ return {
223
+ ...toolInvocation,
224
+ state: "result",
225
+ result: toolResult.result
226
+ };
227
+ }
228
+ return toolInvocation;
229
+ })
230
+ };
231
+ }
232
+ return message;
233
+ });
234
+ const resultContents = [...toolResultContents, ...toolMessage.content];
235
+ return { chatMessages: chatMessages2, toolResultContents: resultContents };
236
+ }
237
+ const { chatMessages } = messages.reduce(
238
+ (obj, message) => {
239
+ if (message.role === "tool") {
240
+ return addToolMessageToChat({
241
+ toolMessage: message,
242
+ messages: obj.chatMessages,
243
+ toolResultContents: obj.toolResultContents
244
+ });
245
+ }
246
+ let textContent = "";
247
+ let toolInvocations = [];
248
+ if (typeof message.content === "string") {
249
+ textContent = message.content;
250
+ } else if (typeof message.content === "number") {
251
+ textContent = String(message.content);
252
+ } else if (Array.isArray(message.content)) {
253
+ for (const content of message.content) {
254
+ if (content.type === "text") {
255
+ textContent += content.text;
256
+ } else if (content.type === "tool-call") {
257
+ const toolResult = obj.toolResultContents.find((tool) => tool.toolCallId === content.toolCallId);
258
+ toolInvocations.push({
259
+ state: toolResult ? "result" : "call",
260
+ toolCallId: content.toolCallId,
261
+ toolName: content.toolName,
262
+ args: content.args,
263
+ result: toolResult?.result
264
+ });
265
+ }
266
+ }
267
+ }
268
+ obj.chatMessages.push({
269
+ id: message.id,
270
+ role: message.role,
271
+ content: textContent,
272
+ toolInvocations
273
+ });
274
+ return obj;
275
+ },
276
+ { chatMessages: [], toolResultContents: [] }
277
+ );
278
+ return chatMessages;
279
+ }
280
+ /**
281
+ * Helper method to create a new thread
282
+ * @param title - Optional title for the thread
283
+ * @param metadata - Optional metadata for the thread
284
+ * @returns Promise resolving to the created thread
285
+ */
286
+ async createThread({
287
+ threadId,
288
+ resourceId,
289
+ title,
290
+ metadata,
291
+ memoryConfig
292
+ }) {
293
+ const thread = {
294
+ id: threadId || this.generateId(),
295
+ title: title || `New Thread ${(/* @__PURE__ */ new Date()).toISOString()}`,
296
+ resourceId,
297
+ createdAt: /* @__PURE__ */ new Date(),
298
+ updatedAt: /* @__PURE__ */ new Date(),
299
+ metadata
300
+ };
301
+ return this.saveThread({ thread, memoryConfig });
302
+ }
303
+ /**
304
+ * Helper method to add a single message to a thread
305
+ * @param threadId - The thread to add the message to
306
+ * @param content - The message content
307
+ * @param role - The role of the message sender
308
+ * @param type - The type of the message
309
+ * @param toolNames - Optional array of tool names that were called
310
+ * @param toolCallArgs - Optional array of tool call arguments
311
+ * @param toolCallIds - Optional array of tool call ids
312
+ * @returns Promise resolving to the saved message
313
+ */
314
+ async addMessage({
315
+ threadId,
316
+ config,
317
+ content,
318
+ role,
319
+ type,
320
+ toolNames,
321
+ toolCallArgs,
322
+ toolCallIds
323
+ }) {
324
+ const message = {
325
+ id: this.generateId(),
326
+ content,
327
+ role,
328
+ createdAt: /* @__PURE__ */ new Date(),
329
+ threadId,
330
+ type,
331
+ toolNames,
332
+ toolCallArgs,
333
+ toolCallIds
334
+ };
335
+ const savedMessages = await this.saveMessages({ messages: [message], memoryConfig: config });
336
+ return savedMessages[0];
337
+ }
338
+ /**
339
+ * Generates a unique identifier
340
+ * @returns A unique string ID
341
+ */
342
+ generateId() {
343
+ return crypto.randomUUID();
344
+ }
345
+ };
346
+
347
+ exports.MastraMemory = MastraMemory;
@@ -1,5 +1,5 @@
1
1
  import { InstrumentClass } from './chunk-W5HVJX45.js';
2
- import { ensureToolProperties, createMastraProxy, makeCoreTool, delay } from './chunk-IM7CM3DU.js';
2
+ import { ensureToolProperties, createMastraProxy, makeCoreTool, delay } from './chunk-4Y74D74B.js';
3
3
  import { MastraBase } from './chunk-4VHCCQ7P.js';
4
4
  import { RegisteredLogger } from './chunk-3JSTLSIP.js';
5
5
  import { executeHook } from './chunk-BB4KXGBU.js';
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ var chunkSYQ7NK2E_cjs = require('./chunk-SYQ7NK2E.cjs');
4
+
5
+ // src/deployer/index.ts
6
+ var MastraDeployer = class extends chunkSYQ7NK2E_cjs.MastraBundler {
7
+ constructor({ name }) {
8
+ super({ component: "DEPLOYER", name });
9
+ }
10
+ };
11
+
12
+ exports.MastraDeployer = MastraDeployer;
@@ -1,6 +1,6 @@
1
1
  import { LibSQLVector } from './chunk-4DD2PP2R.js';
2
2
  import { LibSQLStore } from './chunk-QAZ2ONKM.js';
3
- import { deepMerge } from './chunk-IM7CM3DU.js';
3
+ import { deepMerge } from './chunk-4Y74D74B.js';
4
4
  import { MastraBase } from './chunk-4VHCCQ7P.js';
5
5
  import { existsSync } from 'fs';
6
6
  import path, { join } from 'path';