@mastra/core 0.10.1 → 0.10.2-alpha.1

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 (79) hide show
  1. package/dist/agent/index.cjs +7 -2
  2. package/dist/agent/index.d.cts +9 -9
  3. package/dist/agent/index.d.ts +9 -9
  4. package/dist/agent/index.js +2 -1
  5. package/dist/{base-B96VvaWm.d.cts → base-BIRXTC4Q.d.cts} +1456 -1361
  6. package/dist/{base-QP4OC4dB.d.ts → base-BUTjc86H.d.ts} +1456 -1361
  7. package/dist/{chunk-XRF2JEZJ.cjs → chunk-2CK6E5UF.cjs} +24 -0
  8. package/dist/{chunk-STLR3SIQ.cjs → chunk-4I6LG5EO.cjs} +6 -92
  9. package/dist/{chunk-2YYOF7DO.js → chunk-5UFUPI3G.js} +5 -91
  10. package/dist/{chunk-MTIZRZZI.js → chunk-75EMTCUM.js} +24 -0
  11. package/dist/{chunk-VRACJIAE.js → chunk-A4RQDNP3.js} +2 -2
  12. package/dist/{chunk-RFERFI6B.js → chunk-D3237VN7.js} +183 -369
  13. package/dist/{chunk-U3L3NEOM.cjs → chunk-DXLVS7ML.cjs} +1 -19
  14. package/dist/{chunk-2PW6UJMW.js → chunk-EQTIDVPN.js} +2 -19
  15. package/dist/{chunk-SFZZYGKB.cjs → chunk-EZYCQBP2.cjs} +2 -2
  16. package/dist/{chunk-MAFHTHTJ.cjs → chunk-GXEDBJC5.cjs} +4 -4
  17. package/dist/{chunk-5JRD3NDP.cjs → chunk-I5OLBJ26.cjs} +6 -77
  18. package/dist/chunk-LCCQWUQP.js +962 -0
  19. package/dist/{chunk-RARKB3F2.js → chunk-NY4KJJWC.js} +1 -1
  20. package/dist/{chunk-SLKAWVQR.cjs → chunk-QUCBJ363.cjs} +192 -378
  21. package/dist/{chunk-SKG2NIZW.cjs → chunk-RK6DHZUA.cjs} +2 -2
  22. package/dist/{chunk-OCT2762Q.js → chunk-RMTG7VWR.js} +1 -1
  23. package/dist/chunk-XAO67QBR.cjs +964 -0
  24. package/dist/{chunk-BPTSLJHA.js → chunk-ZJYHZO6Y.js} +2 -73
  25. package/dist/eval/index.d.cts +8 -8
  26. package/dist/eval/index.d.ts +8 -8
  27. package/dist/index.cjs +41 -45
  28. package/dist/index.d.cts +7 -7
  29. package/dist/index.d.ts +7 -7
  30. package/dist/index.js +10 -10
  31. package/dist/integration/index.cjs +3 -3
  32. package/dist/integration/index.d.cts +9 -9
  33. package/dist/integration/index.d.ts +9 -9
  34. package/dist/integration/index.js +1 -1
  35. package/dist/llm/index.d.cts +8 -8
  36. package/dist/llm/index.d.ts +8 -8
  37. package/dist/mastra/index.cjs +2 -2
  38. package/dist/mastra/index.d.cts +6 -6
  39. package/dist/mastra/index.d.ts +6 -6
  40. package/dist/mastra/index.js +1 -1
  41. package/dist/mcp/index.d.cts +11 -11
  42. package/dist/mcp/index.d.ts +11 -11
  43. package/dist/memory/index.cjs +4 -4
  44. package/dist/memory/index.d.cts +9 -9
  45. package/dist/memory/index.d.ts +9 -9
  46. package/dist/memory/index.js +1 -1
  47. package/dist/network/index.cjs +4 -4
  48. package/dist/network/index.d.cts +9 -9
  49. package/dist/network/index.d.ts +9 -9
  50. package/dist/network/index.js +2 -2
  51. package/dist/relevance/index.cjs +4 -4
  52. package/dist/relevance/index.d.cts +11 -11
  53. package/dist/relevance/index.d.ts +11 -11
  54. package/dist/relevance/index.js +1 -1
  55. package/dist/server/index.d.cts +9 -9
  56. package/dist/server/index.d.ts +9 -9
  57. package/dist/storage/index.d.cts +18 -18
  58. package/dist/storage/index.d.ts +18 -18
  59. package/dist/telemetry/index.d.cts +9 -9
  60. package/dist/telemetry/index.d.ts +9 -9
  61. package/dist/tools/index.cjs +4 -4
  62. package/dist/tools/index.d.cts +9 -9
  63. package/dist/tools/index.d.ts +9 -9
  64. package/dist/tools/index.js +1 -1
  65. package/dist/utils.cjs +15 -19
  66. package/dist/utils.d.cts +10 -11
  67. package/dist/utils.d.ts +10 -11
  68. package/dist/utils.js +1 -1
  69. package/dist/voice/index.d.cts +9 -9
  70. package/dist/voice/index.d.ts +9 -9
  71. package/dist/workflows/index.cjs +9 -9
  72. package/dist/workflows/index.d.cts +9 -9
  73. package/dist/workflows/index.d.ts +9 -9
  74. package/dist/workflows/index.js +1 -1
  75. package/dist/workflows/legacy/index.cjs +22 -22
  76. package/dist/workflows/legacy/index.d.cts +9 -9
  77. package/dist/workflows/legacy/index.d.ts +9 -9
  78. package/dist/workflows/legacy/index.js +1 -1
  79. package/package.json +5 -2
@@ -391,6 +391,30 @@ do:
391
391
  getServerMiddleware() {
392
392
  return this.#serverMiddleware;
393
393
  }
394
+ setServerMiddleware(serverMiddleware) {
395
+ if (typeof serverMiddleware === "function") {
396
+ this.#serverMiddleware = [{
397
+ handler: serverMiddleware,
398
+ path: "/api/*"
399
+ }];
400
+ return;
401
+ }
402
+ if (!Array.isArray(serverMiddleware)) {
403
+ throw new Error(`Invalid middleware: expected a function or array, received ${typeof serverMiddleware}`);
404
+ }
405
+ this.#serverMiddleware = serverMiddleware.map(m => {
406
+ if (typeof m === "function") {
407
+ return {
408
+ handler: m,
409
+ path: "/api/*"
410
+ };
411
+ }
412
+ return {
413
+ handler: m.handler,
414
+ path: m.path || "/api/*"
415
+ };
416
+ });
417
+ }
394
418
  getNetworks() {
395
419
  return Object.values(this.#networks || {});
396
420
  }
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkLXFZUKP3_cjs = require('./chunk-LXFZUKP3.cjs');
4
- var chunkU3L3NEOM_cjs = require('./chunk-U3L3NEOM.cjs');
4
+ var chunkXAO67QBR_cjs = require('./chunk-XAO67QBR.cjs');
5
+ var chunkDXLVS7ML_cjs = require('./chunk-DXLVS7ML.cjs');
5
6
  var chunkYEULQPUY_cjs = require('./chunk-YEULQPUY.cjs');
6
7
 
7
8
  // src/memory/memory.ts
@@ -129,7 +130,7 @@ https://mastra.ai/en/docs/memory/overview`
129
130
  if (config?.workingMemory && "use" in config.workingMemory) {
130
131
  throw new Error("The workingMemory.use option has been removed. Working memory always uses tool-call mode.");
131
132
  }
132
- return chunkU3L3NEOM_cjs.deepMerge(this.threadConfig, config || {});
133
+ return chunkDXLVS7ML_cjs.deepMerge(this.threadConfig, config || {});
133
134
  }
134
135
  /**
135
136
  * Apply all configured message processors to a list of messages.
@@ -161,95 +162,6 @@ https://mastra.ai/en/docs/memory/overview`
161
162
  estimateTokens(text) {
162
163
  return Math.ceil(text.split(" ").length * 1.3);
163
164
  }
164
- parseMessages(messages) {
165
- return messages.map((msg) => {
166
- let content = msg.content;
167
- if (typeof content === "string" && (content.startsWith("[") || content.startsWith("{"))) {
168
- try {
169
- content = JSON.parse(content);
170
- } catch {
171
- }
172
- } else if (typeof content === "number") {
173
- content = String(content);
174
- }
175
- return {
176
- ...msg,
177
- content
178
- };
179
- });
180
- }
181
- convertToUIMessages(messages) {
182
- function addToolMessageToChat({
183
- toolMessage,
184
- messages: messages2,
185
- toolResultContents
186
- }) {
187
- const chatMessages2 = messages2.map((message) => {
188
- if (message.toolInvocations) {
189
- return {
190
- ...message,
191
- toolInvocations: message.toolInvocations.map((toolInvocation) => {
192
- const toolResult = toolMessage.content.find((tool) => tool.toolCallId === toolInvocation.toolCallId);
193
- if (toolResult) {
194
- return {
195
- ...toolInvocation,
196
- state: "result",
197
- result: toolResult.result
198
- };
199
- }
200
- return toolInvocation;
201
- })
202
- };
203
- }
204
- return message;
205
- });
206
- const resultContents = [...toolResultContents, ...toolMessage.content];
207
- return { chatMessages: chatMessages2, toolResultContents: resultContents };
208
- }
209
- const { chatMessages } = messages.reduce(
210
- (obj, message) => {
211
- if (message.role === "tool") {
212
- return addToolMessageToChat({
213
- toolMessage: message,
214
- messages: obj.chatMessages,
215
- toolResultContents: obj.toolResultContents
216
- });
217
- }
218
- let textContent = "";
219
- let toolInvocations = [];
220
- if (typeof message.content === "string") {
221
- textContent = message.content;
222
- } else if (typeof message.content === "number") {
223
- textContent = String(message.content);
224
- } else if (Array.isArray(message.content)) {
225
- for (const content of message.content) {
226
- if (content.type === "text") {
227
- textContent += content.text;
228
- } else if (content.type === "tool-call") {
229
- const toolResult = obj.toolResultContents.find((tool) => tool.toolCallId === content.toolCallId);
230
- toolInvocations.push({
231
- state: toolResult ? "result" : "call",
232
- toolCallId: content.toolCallId,
233
- toolName: content.toolName,
234
- args: content.args,
235
- result: toolResult?.result
236
- });
237
- }
238
- }
239
- }
240
- obj.chatMessages.push({
241
- id: message.id,
242
- role: message.role,
243
- content: textContent,
244
- toolInvocations,
245
- createdAt: message.createdAt
246
- });
247
- return obj;
248
- },
249
- { chatMessages: [], toolResultContents: [] }
250
- );
251
- return chatMessages;
252
- }
253
165
  /**
254
166
  * Helper method to create a new thread
255
167
  * @param title - Optional title for the thread
@@ -283,6 +195,7 @@ https://mastra.ai/en/docs/memory/overview`
283
195
  * @param toolCallArgs - Optional array of tool call arguments
284
196
  * @param toolCallIds - Optional array of tool call ids
285
197
  * @returns Promise resolving to the saved message
198
+ * @deprecated use saveMessages instead
286
199
  */
287
200
  async addMessage({
288
201
  threadId,
@@ -308,7 +221,8 @@ https://mastra.ai/en/docs/memory/overview`
308
221
  toolCallIds
309
222
  };
310
223
  const savedMessages = await this.saveMessages({ messages: [message], memoryConfig: config });
311
- return savedMessages[0];
224
+ const list = new chunkXAO67QBR_cjs.MessageList({ threadId, resourceId }).add(savedMessages[0], "memory");
225
+ return list.get.all.v1()[0];
312
226
  }
313
227
  /**
314
228
  * Generates a unique identifier
@@ -1,5 +1,6 @@
1
1
  import { augmentWithInit } from './chunk-YOQP5T77.js';
2
- import { deepMerge } from './chunk-2PW6UJMW.js';
2
+ import { MessageList } from './chunk-LCCQWUQP.js';
3
+ import { deepMerge } from './chunk-EQTIDVPN.js';
3
4
  import { MastraBase } from './chunk-FI7R232B.js';
4
5
 
5
6
  // src/memory/memory.ts
@@ -159,95 +160,6 @@ https://mastra.ai/en/docs/memory/overview`
159
160
  estimateTokens(text) {
160
161
  return Math.ceil(text.split(" ").length * 1.3);
161
162
  }
162
- parseMessages(messages) {
163
- return messages.map((msg) => {
164
- let content = msg.content;
165
- if (typeof content === "string" && (content.startsWith("[") || content.startsWith("{"))) {
166
- try {
167
- content = JSON.parse(content);
168
- } catch {
169
- }
170
- } else if (typeof content === "number") {
171
- content = String(content);
172
- }
173
- return {
174
- ...msg,
175
- content
176
- };
177
- });
178
- }
179
- convertToUIMessages(messages) {
180
- function addToolMessageToChat({
181
- toolMessage,
182
- messages: messages2,
183
- toolResultContents
184
- }) {
185
- const chatMessages2 = messages2.map((message) => {
186
- if (message.toolInvocations) {
187
- return {
188
- ...message,
189
- toolInvocations: message.toolInvocations.map((toolInvocation) => {
190
- const toolResult = toolMessage.content.find((tool) => tool.toolCallId === toolInvocation.toolCallId);
191
- if (toolResult) {
192
- return {
193
- ...toolInvocation,
194
- state: "result",
195
- result: toolResult.result
196
- };
197
- }
198
- return toolInvocation;
199
- })
200
- };
201
- }
202
- return message;
203
- });
204
- const resultContents = [...toolResultContents, ...toolMessage.content];
205
- return { chatMessages: chatMessages2, toolResultContents: resultContents };
206
- }
207
- const { chatMessages } = messages.reduce(
208
- (obj, message) => {
209
- if (message.role === "tool") {
210
- return addToolMessageToChat({
211
- toolMessage: message,
212
- messages: obj.chatMessages,
213
- toolResultContents: obj.toolResultContents
214
- });
215
- }
216
- let textContent = "";
217
- let toolInvocations = [];
218
- if (typeof message.content === "string") {
219
- textContent = message.content;
220
- } else if (typeof message.content === "number") {
221
- textContent = String(message.content);
222
- } else if (Array.isArray(message.content)) {
223
- for (const content of message.content) {
224
- if (content.type === "text") {
225
- textContent += content.text;
226
- } else if (content.type === "tool-call") {
227
- const toolResult = obj.toolResultContents.find((tool) => tool.toolCallId === content.toolCallId);
228
- toolInvocations.push({
229
- state: toolResult ? "result" : "call",
230
- toolCallId: content.toolCallId,
231
- toolName: content.toolName,
232
- args: content.args,
233
- result: toolResult?.result
234
- });
235
- }
236
- }
237
- }
238
- obj.chatMessages.push({
239
- id: message.id,
240
- role: message.role,
241
- content: textContent,
242
- toolInvocations,
243
- createdAt: message.createdAt
244
- });
245
- return obj;
246
- },
247
- { chatMessages: [], toolResultContents: [] }
248
- );
249
- return chatMessages;
250
- }
251
163
  /**
252
164
  * Helper method to create a new thread
253
165
  * @param title - Optional title for the thread
@@ -281,6 +193,7 @@ https://mastra.ai/en/docs/memory/overview`
281
193
  * @param toolCallArgs - Optional array of tool call arguments
282
194
  * @param toolCallIds - Optional array of tool call ids
283
195
  * @returns Promise resolving to the saved message
196
+ * @deprecated use saveMessages instead
284
197
  */
285
198
  async addMessage({
286
199
  threadId,
@@ -306,7 +219,8 @@ https://mastra.ai/en/docs/memory/overview`
306
219
  toolCallIds
307
220
  };
308
221
  const savedMessages = await this.saveMessages({ messages: [message], memoryConfig: config });
309
- return savedMessages[0];
222
+ const list = new MessageList({ threadId, resourceId }).add(savedMessages[0], "memory");
223
+ return list.get.all.v1()[0];
310
224
  }
311
225
  /**
312
226
  * Generates a unique identifier
@@ -389,6 +389,30 @@ do:
389
389
  getServerMiddleware() {
390
390
  return this.#serverMiddleware;
391
391
  }
392
+ setServerMiddleware(serverMiddleware) {
393
+ if (typeof serverMiddleware === "function") {
394
+ this.#serverMiddleware = [{
395
+ handler: serverMiddleware,
396
+ path: "/api/*"
397
+ }];
398
+ return;
399
+ }
400
+ if (!Array.isArray(serverMiddleware)) {
401
+ throw new Error(`Invalid middleware: expected a function or array, received ${typeof serverMiddleware}`);
402
+ }
403
+ this.#serverMiddleware = serverMiddleware.map(m => {
404
+ if (typeof m === "function") {
405
+ return {
406
+ handler: m,
407
+ path: "/api/*"
408
+ };
409
+ }
410
+ return {
411
+ handler: m.handler,
412
+ path: m.path || "/api/*"
413
+ };
414
+ });
415
+ }
392
416
  getNetworks() {
393
417
  return Object.values(this.#networks || {});
394
418
  }
@@ -1,6 +1,6 @@
1
1
  import { EMITTER_SYMBOL } from './chunk-Y7D2JLKS.js';
2
- import { Agent } from './chunk-RFERFI6B.js';
3
- import { Tool } from './chunk-2PW6UJMW.js';
2
+ import { Agent } from './chunk-D3237VN7.js';
3
+ import { Tool } from './chunk-EQTIDVPN.js';
4
4
  import { MastraBase } from './chunk-FI7R232B.js';
5
5
  import { RegisteredLogger } from './chunk-VHLL4AZK.js';
6
6
  import { RuntimeContext } from './chunk-SGGPJWRQ.js';