@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.
- package/dist/agent/index.cjs +7 -2
- package/dist/agent/index.d.cts +9 -9
- package/dist/agent/index.d.ts +9 -9
- package/dist/agent/index.js +2 -1
- package/dist/{base-B96VvaWm.d.cts → base-BIRXTC4Q.d.cts} +1456 -1361
- package/dist/{base-QP4OC4dB.d.ts → base-BUTjc86H.d.ts} +1456 -1361
- package/dist/{chunk-XRF2JEZJ.cjs → chunk-2CK6E5UF.cjs} +24 -0
- package/dist/{chunk-STLR3SIQ.cjs → chunk-4I6LG5EO.cjs} +6 -92
- package/dist/{chunk-2YYOF7DO.js → chunk-5UFUPI3G.js} +5 -91
- package/dist/{chunk-MTIZRZZI.js → chunk-75EMTCUM.js} +24 -0
- package/dist/{chunk-VRACJIAE.js → chunk-A4RQDNP3.js} +2 -2
- package/dist/{chunk-RFERFI6B.js → chunk-D3237VN7.js} +183 -369
- package/dist/{chunk-U3L3NEOM.cjs → chunk-DXLVS7ML.cjs} +1 -19
- package/dist/{chunk-2PW6UJMW.js → chunk-EQTIDVPN.js} +2 -19
- package/dist/{chunk-SFZZYGKB.cjs → chunk-EZYCQBP2.cjs} +2 -2
- package/dist/{chunk-MAFHTHTJ.cjs → chunk-GXEDBJC5.cjs} +4 -4
- package/dist/{chunk-5JRD3NDP.cjs → chunk-I5OLBJ26.cjs} +6 -77
- package/dist/chunk-LCCQWUQP.js +962 -0
- package/dist/{chunk-RARKB3F2.js → chunk-NY4KJJWC.js} +1 -1
- package/dist/{chunk-SLKAWVQR.cjs → chunk-QUCBJ363.cjs} +192 -378
- package/dist/{chunk-SKG2NIZW.cjs → chunk-RK6DHZUA.cjs} +2 -2
- package/dist/{chunk-OCT2762Q.js → chunk-RMTG7VWR.js} +1 -1
- package/dist/chunk-XAO67QBR.cjs +964 -0
- package/dist/{chunk-BPTSLJHA.js → chunk-ZJYHZO6Y.js} +2 -73
- package/dist/eval/index.d.cts +8 -8
- package/dist/eval/index.d.ts +8 -8
- package/dist/index.cjs +41 -45
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +10 -10
- package/dist/integration/index.cjs +3 -3
- package/dist/integration/index.d.cts +9 -9
- package/dist/integration/index.d.ts +9 -9
- package/dist/integration/index.js +1 -1
- package/dist/llm/index.d.cts +8 -8
- package/dist/llm/index.d.ts +8 -8
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.cts +6 -6
- package/dist/mastra/index.d.ts +6 -6
- package/dist/mastra/index.js +1 -1
- package/dist/mcp/index.d.cts +11 -11
- package/dist/mcp/index.d.ts +11 -11
- package/dist/memory/index.cjs +4 -4
- package/dist/memory/index.d.cts +9 -9
- package/dist/memory/index.d.ts +9 -9
- package/dist/memory/index.js +1 -1
- package/dist/network/index.cjs +4 -4
- package/dist/network/index.d.cts +9 -9
- package/dist/network/index.d.ts +9 -9
- package/dist/network/index.js +2 -2
- package/dist/relevance/index.cjs +4 -4
- package/dist/relevance/index.d.cts +11 -11
- package/dist/relevance/index.d.ts +11 -11
- package/dist/relevance/index.js +1 -1
- package/dist/server/index.d.cts +9 -9
- package/dist/server/index.d.ts +9 -9
- package/dist/storage/index.d.cts +18 -18
- package/dist/storage/index.d.ts +18 -18
- package/dist/telemetry/index.d.cts +9 -9
- package/dist/telemetry/index.d.ts +9 -9
- package/dist/tools/index.cjs +4 -4
- package/dist/tools/index.d.cts +9 -9
- package/dist/tools/index.d.ts +9 -9
- package/dist/tools/index.js +1 -1
- package/dist/utils.cjs +15 -19
- package/dist/utils.d.cts +10 -11
- package/dist/utils.d.ts +10 -11
- package/dist/utils.js +1 -1
- package/dist/voice/index.d.cts +9 -9
- package/dist/voice/index.d.ts +9 -9
- package/dist/workflows/index.cjs +9 -9
- package/dist/workflows/index.d.cts +9 -9
- package/dist/workflows/index.d.ts +9 -9
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/legacy/index.cjs +22 -22
- package/dist/workflows/legacy/index.d.cts +9 -9
- package/dist/workflows/legacy/index.d.ts +9 -9
- package/dist/workflows/legacy/index.js +1 -1
- 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
|
|
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
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
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-
|
|
3
|
-
import { Tool } from './chunk-
|
|
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';
|