@mastra/server 0.0.0-experimental-agent-builder-20250815195917 → 0.0.0-export-agent-memory-from-local-studio-20251112153946
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/CHANGELOG.md +4878 -0
- package/README.md +1 -6
- package/dist/chunk-2IS5WICF.js +23036 -0
- package/dist/chunk-2IS5WICF.js.map +1 -0
- package/dist/chunk-2PLXW4ZX.cjs +2777 -0
- package/dist/chunk-2PLXW4ZX.cjs.map +1 -0
- package/dist/chunk-2YZH5PH6.cjs +200 -0
- package/dist/chunk-2YZH5PH6.cjs.map +1 -0
- package/dist/chunk-3AMNUUZF.js +124 -0
- package/dist/chunk-3AMNUUZF.js.map +1 -0
- package/dist/chunk-3F52QCI4.js +192 -0
- package/dist/chunk-3F52QCI4.js.map +1 -0
- package/dist/{chunk-ZKJZQN24.js → chunk-4JF5WXPL.js} +158 -227
- package/dist/chunk-4JF5WXPL.js.map +1 -0
- package/dist/{chunk-7NADHFD2.cjs → chunk-64ITUOXI.cjs} +2 -2
- package/dist/chunk-64ITUOXI.cjs.map +1 -0
- package/dist/{chunk-MMROOK5J.js → chunk-6QWQZI4Q.js} +2 -2
- package/dist/{chunk-7NADHFD2.cjs.map → chunk-6QWQZI4Q.js.map} +1 -1
- package/dist/{chunk-4MQU6AJN.js → chunk-73PAWDM5.js} +14 -14
- package/dist/chunk-73PAWDM5.js.map +1 -0
- package/dist/chunk-A24TSVEZ.cjs +130 -0
- package/dist/chunk-A24TSVEZ.cjs.map +1 -0
- package/dist/chunk-A2NPD5N6.cjs +517 -0
- package/dist/chunk-A2NPD5N6.cjs.map +1 -0
- package/dist/{chunk-HWHKM67I.js → chunk-B3Z6J745.js} +27 -19
- package/dist/chunk-B3Z6J745.js.map +1 -0
- package/dist/chunk-BTWIR2B7.cjs +28 -0
- package/dist/chunk-BTWIR2B7.cjs.map +1 -0
- package/dist/chunk-D7T74TVR.js +129 -0
- package/dist/chunk-D7T74TVR.js.map +1 -0
- package/dist/chunk-EHACNWDL.cjs +681 -0
- package/dist/chunk-EHACNWDL.cjs.map +1 -0
- package/dist/{chunk-JNWFG7JP.js → chunk-FPBYKMIS.js} +15 -14
- package/dist/chunk-FPBYKMIS.js.map +1 -0
- package/dist/chunk-GLAZTMX3.cjs +128 -0
- package/dist/chunk-GLAZTMX3.cjs.map +1 -0
- package/dist/chunk-GU4EWMZB.cjs +769 -0
- package/dist/chunk-GU4EWMZB.cjs.map +1 -0
- package/dist/chunk-ID6JYDNL.cjs +23075 -0
- package/dist/chunk-ID6JYDNL.cjs.map +1 -0
- package/dist/chunk-KF3RI45U.cjs +172 -0
- package/dist/chunk-KF3RI45U.cjs.map +1 -0
- package/dist/{chunk-KXNFZXLG.cjs → chunk-KJIDZQRA.cjs} +16 -15
- package/dist/chunk-KJIDZQRA.cjs.map +1 -0
- package/dist/{chunk-G7NVCO5M.js → chunk-KWH5QBXP.js} +5 -5
- package/dist/{chunk-G7NVCO5M.js.map → chunk-KWH5QBXP.js.map} +1 -1
- package/dist/chunk-LF2ZLOFP.js +767 -0
- package/dist/chunk-LF2ZLOFP.js.map +1 -0
- package/dist/chunk-LPM6BBAX.cjs +1043 -0
- package/dist/chunk-LPM6BBAX.cjs.map +1 -0
- package/dist/chunk-ND5OKOMT.js +165 -0
- package/dist/chunk-ND5OKOMT.js.map +1 -0
- package/dist/chunk-O7I5CWRX.cjs +44 -0
- package/dist/{chunk-Q7SFCCGT.cjs.map → chunk-O7I5CWRX.cjs.map} +1 -1
- package/dist/{chunk-BED2O446.cjs → chunk-PPMIB3FQ.cjs} +22 -22
- package/dist/chunk-PPMIB3FQ.cjs.map +1 -0
- package/dist/chunk-PR4QN5HX.js +39 -0
- package/dist/{chunk-PZ5AY32C.js.map → chunk-PR4QN5HX.js.map} +1 -1
- package/dist/chunk-QU6N55W6.cjs +256 -0
- package/dist/chunk-QU6N55W6.cjs.map +1 -0
- package/dist/chunk-RQK4FQUD.js +1012 -0
- package/dist/chunk-RQK4FQUD.js.map +1 -0
- package/dist/{chunk-NCS2OXX6.cjs → chunk-S54HNARD.cjs} +20 -20
- package/dist/{chunk-NCS2OXX6.cjs.map → chunk-S54HNARD.cjs.map} +1 -1
- package/dist/chunk-SHWNNZBL.js +254 -0
- package/dist/chunk-SHWNNZBL.js.map +1 -0
- package/dist/{chunk-OW4FX5TS.js → chunk-SZIFSF4T.js} +11 -4
- package/dist/chunk-SZIFSF4T.js.map +1 -0
- package/dist/chunk-TOCYBDP2.js +46 -0
- package/dist/chunk-TOCYBDP2.js.map +1 -0
- package/dist/{chunk-CY4TP3FK.js → chunk-UXGQZUYZ.js} +3 -3
- package/dist/{chunk-CY4TP3FK.js.map → chunk-UXGQZUYZ.js.map} +1 -1
- package/dist/{chunk-RE4RPXT2.cjs → chunk-V5WWQN7P.cjs} +4 -4
- package/dist/{chunk-RE4RPXT2.cjs.map → chunk-V5WWQN7P.cjs.map} +1 -1
- package/dist/chunk-W2KMU354.cjs +133 -0
- package/dist/chunk-W2KMU354.cjs.map +1 -0
- package/dist/chunk-X3MICMI2.cjs +620 -0
- package/dist/chunk-X3MICMI2.cjs.map +1 -0
- package/dist/chunk-X6C7BUWN.cjs +48 -0
- package/dist/chunk-X6C7BUWN.cjs.map +1 -0
- package/dist/chunk-Z2O5YVHY.js +661 -0
- package/dist/chunk-Z2O5YVHY.js.map +1 -0
- package/dist/{chunk-BUOJL3MN.js → chunk-ZJ6KEY6H.js} +264 -193
- package/dist/chunk-ZJ6KEY6H.js.map +1 -0
- package/dist/chunk-ZULZ2752.js +2774 -0
- package/dist/chunk-ZULZ2752.js.map +1 -0
- package/dist/dist-4MVGNSRL.cjs +1150 -0
- package/dist/dist-4MVGNSRL.cjs.map +1 -0
- package/dist/dist-FZYCV3VB.cjs +940 -0
- package/dist/dist-FZYCV3VB.cjs.map +1 -0
- package/dist/dist-G2BYZJOC.cjs +928 -0
- package/dist/dist-G2BYZJOC.cjs.map +1 -0
- package/dist/dist-P4MXBQ3U.cjs +16 -0
- package/dist/dist-P4MXBQ3U.cjs.map +1 -0
- package/dist/dist-PQZUVLPC.js +937 -0
- package/dist/dist-PQZUVLPC.js.map +1 -0
- package/dist/dist-R7WYX6LC.js +925 -0
- package/dist/dist-R7WYX6LC.js.map +1 -0
- package/dist/dist-RFMYFILX.cjs +764 -0
- package/dist/dist-RFMYFILX.cjs.map +1 -0
- package/dist/dist-X7XR3M3Z.js +1147 -0
- package/dist/dist-X7XR3M3Z.js.map +1 -0
- package/dist/dist-XVBSOGFK.js +761 -0
- package/dist/dist-XVBSOGFK.js.map +1 -0
- package/dist/dist-YREX2TJT.js +3 -0
- package/dist/dist-YREX2TJT.js.map +1 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/server/handlers/a2a.cjs +7 -7
- package/dist/server/handlers/a2a.d.ts +10 -10
- package/dist/server/handlers/a2a.d.ts.map +1 -1
- package/dist/server/handlers/a2a.js +1 -1
- package/dist/server/handlers/agent-builder.cjs +80 -0
- package/dist/server/handlers/agent-builder.cjs.map +1 -0
- package/dist/server/handlers/agent-builder.d.ts +85 -0
- package/dist/server/handlers/agent-builder.d.ts.map +1 -0
- package/dist/server/handlers/agent-builder.js +3 -0
- package/dist/server/handlers/agent-builder.js.map +1 -0
- package/dist/server/handlers/agents.cjs +51 -15
- package/dist/server/handlers/agents.d.ts +165 -61
- package/dist/server/handlers/agents.d.ts.map +1 -1
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/error.cjs +2 -2
- package/dist/server/handlers/error.js +1 -1
- package/dist/server/handlers/logs.cjs +7 -7
- package/dist/server/handlers/logs.d.ts +3 -3
- package/dist/server/handlers/logs.d.ts.map +1 -1
- package/dist/server/handlers/logs.js +1 -1
- package/dist/server/handlers/memory.cjs +17 -25
- package/dist/server/handlers/memory.d.ts +28 -35
- package/dist/server/handlers/memory.d.ts.map +1 -1
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/observability.cjs +24 -0
- package/dist/server/handlers/observability.cjs.map +1 -0
- package/dist/server/handlers/observability.d.ts +49 -0
- package/dist/server/handlers/observability.d.ts.map +1 -0
- package/dist/server/handlers/observability.js +3 -0
- package/dist/server/handlers/observability.js.map +1 -0
- package/dist/server/handlers/scores.cjs +11 -11
- package/dist/server/handlers/scores.d.ts +121 -18
- package/dist/server/handlers/scores.d.ts.map +1 -1
- package/dist/server/handlers/scores.js +1 -1
- package/dist/server/handlers/tools.cjs +10 -6
- package/dist/server/handlers/tools.d.ts +10 -6
- package/dist/server/handlers/tools.d.ts.map +1 -1
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/utils.cjs +6 -2
- package/dist/server/handlers/utils.d.ts +6 -0
- package/dist/server/handlers/utils.d.ts.map +1 -1
- package/dist/server/handlers/utils.js +1 -1
- package/dist/server/handlers/vector.cjs +7 -7
- package/dist/server/handlers/vector.js +1 -1
- package/dist/server/handlers/voice.cjs +5 -5
- package/dist/server/handlers/voice.d.ts +6 -4
- package/dist/server/handlers/voice.d.ts.map +1 -1
- package/dist/server/handlers/voice.js +1 -1
- package/dist/server/handlers/workflows.cjs +35 -23
- package/dist/server/handlers/workflows.d.ts +50 -50
- package/dist/server/handlers/workflows.d.ts.map +1 -1
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +31 -36
- package/dist/server/handlers.d.ts +2 -3
- package/dist/server/handlers.d.ts.map +1 -1
- package/dist/server/handlers.js +11 -12
- package/dist/server/http-exception.d.ts +0 -5
- package/dist/server/http-exception.d.ts.map +1 -1
- package/dist/server/utils.d.ts +45 -0
- package/dist/server/utils.d.ts.map +1 -0
- package/dist/token-375W3LEI.cjs +64 -0
- package/dist/token-375W3LEI.cjs.map +1 -0
- package/dist/token-C3IMNCC4.js +62 -0
- package/dist/token-C3IMNCC4.js.map +1 -0
- package/dist/token-util-CV3RRG6K.cjs +9 -0
- package/dist/token-util-CV3RRG6K.cjs.map +1 -0
- package/dist/token-util-E5QO2RCL.js +7 -0
- package/dist/token-util-E5QO2RCL.js.map +1 -0
- package/package.json +27 -13
- package/dist/chunk-4CEZIJWJ.cjs +0 -150
- package/dist/chunk-4CEZIJWJ.cjs.map +0 -1
- package/dist/chunk-4MQU6AJN.js.map +0 -1
- package/dist/chunk-4QSNRCOT.cjs +0 -20
- package/dist/chunk-4QSNRCOT.cjs.map +0 -1
- package/dist/chunk-4US5W7PH.cjs +0 -120
- package/dist/chunk-4US5W7PH.cjs.map +0 -1
- package/dist/chunk-5AKR33BI.js +0 -333
- package/dist/chunk-5AKR33BI.js.map +0 -1
- package/dist/chunk-7FHF55WA.js +0 -2041
- package/dist/chunk-7FHF55WA.js.map +0 -1
- package/dist/chunk-BED2O446.cjs.map +0 -1
- package/dist/chunk-BUOJL3MN.js.map +0 -1
- package/dist/chunk-EBNIUZRY.cjs +0 -344
- package/dist/chunk-EBNIUZRY.cjs.map +0 -1
- package/dist/chunk-GX25CWC7.cjs +0 -588
- package/dist/chunk-GX25CWC7.cjs.map +0 -1
- package/dist/chunk-HWHKM67I.js.map +0 -1
- package/dist/chunk-ILCWPBYQ.cjs +0 -147
- package/dist/chunk-ILCWPBYQ.cjs.map +0 -1
- package/dist/chunk-JGVY3KWV.cjs +0 -334
- package/dist/chunk-JGVY3KWV.cjs.map +0 -1
- package/dist/chunk-JNWFG7JP.js.map +0 -1
- package/dist/chunk-KXNFZXLG.cjs.map +0 -1
- package/dist/chunk-L7YG7WQH.js +0 -151
- package/dist/chunk-L7YG7WQH.js.map +0 -1
- package/dist/chunk-LRUH33B4.cjs +0 -2044
- package/dist/chunk-LRUH33B4.cjs.map +0 -1
- package/dist/chunk-MMROOK5J.js.map +0 -1
- package/dist/chunk-O4I563YW.cjs +0 -130
- package/dist/chunk-O4I563YW.cjs.map +0 -1
- package/dist/chunk-OW4FX5TS.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -9
- package/dist/chunk-Q7SFCCGT.cjs +0 -11
- package/dist/chunk-RQQNZZAI.cjs +0 -159
- package/dist/chunk-RQQNZZAI.cjs.map +0 -1
- package/dist/chunk-S37KCGOR.cjs +0 -546
- package/dist/chunk-S37KCGOR.cjs.map +0 -1
- package/dist/chunk-SQ7KKIH3.js +0 -143
- package/dist/chunk-SQ7KKIH3.js.map +0 -1
- package/dist/chunk-UVOSITKU.js +0 -322
- package/dist/chunk-UVOSITKU.js.map +0 -1
- package/dist/chunk-Y3J45CVZ.js +0 -144
- package/dist/chunk-Y3J45CVZ.js.map +0 -1
- package/dist/chunk-YS66MFDY.js +0 -124
- package/dist/chunk-YS66MFDY.js.map +0 -1
- package/dist/chunk-ZKJZQN24.js.map +0 -1
- package/dist/server/handlers/legacyWorkflows.cjs +0 -48
- package/dist/server/handlers/legacyWorkflows.cjs.map +0 -1
- package/dist/server/handlers/legacyWorkflows.d.ts +0 -59
- package/dist/server/handlers/legacyWorkflows.d.ts.map +0 -1
- package/dist/server/handlers/legacyWorkflows.js +0 -3
- package/dist/server/handlers/legacyWorkflows.js.map +0 -1
- package/dist/server/handlers/network.cjs +0 -24
- package/dist/server/handlers/network.cjs.map +0 -1
- package/dist/server/handlers/network.d.ts +0 -50
- package/dist/server/handlers/network.d.ts.map +0 -1
- package/dist/server/handlers/network.js +0 -3
- package/dist/server/handlers/network.js.map +0 -1
- package/dist/server/handlers/telemetry.cjs +0 -16
- package/dist/server/handlers/telemetry.cjs.map +0 -1
- package/dist/server/handlers/telemetry.d.ts +0 -32
- package/dist/server/handlers/telemetry.d.ts.map +0 -1
- package/dist/server/handlers/telemetry.js +0 -3
- package/dist/server/handlers/telemetry.js.map +0 -1
- package/dist/server/handlers/vNextNetwork.cjs +0 -220
- package/dist/server/handlers/vNextNetwork.cjs.map +0 -1
- package/dist/server/handlers/vNextNetwork.d.ts +0 -179
- package/dist/server/handlers/vNextNetwork.d.ts.map +0 -1
- package/dist/server/handlers/vNextNetwork.js +0 -213
- package/dist/server/handlers/vNextNetwork.js.map +0 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { validateBody } from './chunk-
|
|
2
|
-
import { handleError } from './chunk-
|
|
3
|
-
import { HTTPException } from './chunk-
|
|
4
|
-
import { __export } from './chunk-
|
|
5
|
-
import {
|
|
1
|
+
import { validateBody } from './chunk-SZIFSF4T.js';
|
|
2
|
+
import { handleError } from './chunk-UXGQZUYZ.js';
|
|
3
|
+
import { HTTPException } from './chunk-6QWQZI4Q.js';
|
|
4
|
+
import { __export } from './chunk-PR4QN5HX.js';
|
|
5
|
+
import { RequestContext } from '@mastra/core/di';
|
|
6
|
+
import { generateEmptyFromSchema } from '@mastra/core/utils';
|
|
6
7
|
|
|
7
8
|
// src/server/handlers/memory.ts
|
|
8
9
|
var memory_exports = {};
|
|
@@ -12,12 +13,10 @@ __export(memory_exports, {
|
|
|
12
13
|
deleteThreadHandler: () => deleteThreadHandler,
|
|
13
14
|
getMemoryConfigHandler: () => getMemoryConfigHandler,
|
|
14
15
|
getMemoryStatusHandler: () => getMemoryStatusHandler,
|
|
15
|
-
getMessagesHandler: () => getMessagesHandler,
|
|
16
|
-
getMessagesPaginatedHandler: () => getMessagesPaginatedHandler,
|
|
17
16
|
getThreadByIdHandler: () => getThreadByIdHandler,
|
|
18
|
-
getThreadsHandler: () => getThreadsHandler,
|
|
19
|
-
getThreadsPaginatedHandler: () => getThreadsPaginatedHandler,
|
|
20
17
|
getWorkingMemoryHandler: () => getWorkingMemoryHandler,
|
|
18
|
+
listMessagesHandler: () => listMessagesHandler,
|
|
19
|
+
listThreadsHandler: () => listThreadsHandler,
|
|
21
20
|
saveMessagesHandler: () => saveMessagesHandler,
|
|
22
21
|
searchMemoryHandler: () => searchMemoryHandler,
|
|
23
22
|
updateThreadHandler: () => updateThreadHandler,
|
|
@@ -26,33 +25,50 @@ __export(memory_exports, {
|
|
|
26
25
|
async function getMemoryFromContext({
|
|
27
26
|
mastra,
|
|
28
27
|
agentId,
|
|
29
|
-
|
|
30
|
-
runtimeContext
|
|
28
|
+
requestContext
|
|
31
29
|
}) {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
const logger = mastra.getLogger();
|
|
31
|
+
let agent;
|
|
32
|
+
if (agentId) {
|
|
33
|
+
try {
|
|
34
|
+
agent = mastra.getAgentById(agentId);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
logger.debug("Error getting agent from mastra, searching agents for agent", error);
|
|
37
|
+
}
|
|
35
38
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
if (agentId && !agent) {
|
|
40
|
+
logger.debug("Agent not found, searching agents for agent", { agentId });
|
|
41
|
+
const agents = mastra.listAgents();
|
|
42
|
+
if (Object.keys(agents || {}).length) {
|
|
43
|
+
for (const [_, ag] of Object.entries(agents)) {
|
|
44
|
+
try {
|
|
45
|
+
const agents2 = await ag.listAgents();
|
|
46
|
+
if (agents2[agentId]) {
|
|
47
|
+
agent = agents2[agentId];
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
} catch (error) {
|
|
51
|
+
logger.debug("Error getting agent from agent", error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!agent) {
|
|
56
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
57
|
+
}
|
|
39
58
|
}
|
|
40
59
|
if (agent) {
|
|
41
|
-
return await agent?.getMemory(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return await network?.getMemory({ runtimeContext }) || mastra.getMemory();
|
|
60
|
+
return await agent?.getMemory({
|
|
61
|
+
requestContext: requestContext ?? new RequestContext()
|
|
62
|
+
});
|
|
45
63
|
}
|
|
46
|
-
return mastra.getMemory();
|
|
47
64
|
}
|
|
48
65
|
async function getMemoryStatusHandler({
|
|
49
66
|
mastra,
|
|
50
67
|
agentId,
|
|
51
|
-
|
|
52
|
-
runtimeContext
|
|
68
|
+
requestContext
|
|
53
69
|
}) {
|
|
54
70
|
try {
|
|
55
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
71
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
56
72
|
if (!memory) {
|
|
57
73
|
return { result: false };
|
|
58
74
|
}
|
|
@@ -64,11 +80,10 @@ async function getMemoryStatusHandler({
|
|
|
64
80
|
async function getMemoryConfigHandler({
|
|
65
81
|
mastra,
|
|
66
82
|
agentId,
|
|
67
|
-
|
|
68
|
-
runtimeContext
|
|
83
|
+
requestContext
|
|
69
84
|
}) {
|
|
70
85
|
try {
|
|
71
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
86
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
72
87
|
if (!memory) {
|
|
73
88
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
74
89
|
}
|
|
@@ -78,70 +93,41 @@ async function getMemoryConfigHandler({
|
|
|
78
93
|
return handleError(error, "Error getting memory configuration");
|
|
79
94
|
}
|
|
80
95
|
}
|
|
81
|
-
async function
|
|
96
|
+
async function listThreadsHandler({
|
|
82
97
|
mastra,
|
|
83
98
|
agentId,
|
|
84
99
|
resourceId,
|
|
85
|
-
|
|
86
|
-
runtimeContext,
|
|
87
|
-
orderBy,
|
|
88
|
-
sortDirection
|
|
89
|
-
}) {
|
|
90
|
-
try {
|
|
91
|
-
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
92
|
-
if (!memory) {
|
|
93
|
-
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
94
|
-
}
|
|
95
|
-
validateBody({ resourceId });
|
|
96
|
-
const threads = await memory.getThreadsByResourceId({
|
|
97
|
-
resourceId,
|
|
98
|
-
orderBy,
|
|
99
|
-
sortDirection
|
|
100
|
-
});
|
|
101
|
-
return threads;
|
|
102
|
-
} catch (error) {
|
|
103
|
-
return handleError(error, "Error getting threads");
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
async function getThreadsPaginatedHandler({
|
|
107
|
-
mastra,
|
|
108
|
-
agentId,
|
|
109
|
-
resourceId,
|
|
110
|
-
networkId,
|
|
111
|
-
runtimeContext,
|
|
100
|
+
requestContext,
|
|
112
101
|
page,
|
|
113
102
|
perPage,
|
|
114
|
-
orderBy
|
|
115
|
-
sortDirection
|
|
103
|
+
orderBy
|
|
116
104
|
}) {
|
|
117
105
|
try {
|
|
118
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
106
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
119
107
|
if (!memory) {
|
|
120
108
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
121
109
|
}
|
|
122
110
|
validateBody({ resourceId });
|
|
123
|
-
const result = await memory.
|
|
111
|
+
const result = await memory.listThreadsByResourceId({
|
|
124
112
|
resourceId,
|
|
125
113
|
page,
|
|
126
114
|
perPage,
|
|
127
|
-
orderBy
|
|
128
|
-
sortDirection
|
|
115
|
+
orderBy
|
|
129
116
|
});
|
|
130
117
|
return result;
|
|
131
118
|
} catch (error) {
|
|
132
|
-
return handleError(error, "Error
|
|
119
|
+
return handleError(error, "Error listing threads");
|
|
133
120
|
}
|
|
134
121
|
}
|
|
135
122
|
async function getThreadByIdHandler({
|
|
136
123
|
mastra,
|
|
137
124
|
agentId,
|
|
138
125
|
threadId,
|
|
139
|
-
|
|
140
|
-
runtimeContext
|
|
126
|
+
requestContext
|
|
141
127
|
}) {
|
|
142
128
|
try {
|
|
143
129
|
validateBody({ threadId });
|
|
144
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
130
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
145
131
|
if (!memory) {
|
|
146
132
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
147
133
|
}
|
|
@@ -158,11 +144,10 @@ async function saveMessagesHandler({
|
|
|
158
144
|
mastra,
|
|
159
145
|
agentId,
|
|
160
146
|
body,
|
|
161
|
-
|
|
162
|
-
runtimeContext
|
|
147
|
+
requestContext
|
|
163
148
|
}) {
|
|
164
149
|
try {
|
|
165
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
150
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
166
151
|
if (!memory) {
|
|
167
152
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
168
153
|
}
|
|
@@ -193,11 +178,10 @@ async function createThreadHandler({
|
|
|
193
178
|
mastra,
|
|
194
179
|
agentId,
|
|
195
180
|
body,
|
|
196
|
-
|
|
197
|
-
runtimeContext
|
|
181
|
+
requestContext
|
|
198
182
|
}) {
|
|
199
183
|
try {
|
|
200
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
184
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
201
185
|
if (!memory) {
|
|
202
186
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
203
187
|
}
|
|
@@ -218,11 +202,10 @@ async function updateThreadHandler({
|
|
|
218
202
|
agentId,
|
|
219
203
|
threadId,
|
|
220
204
|
body,
|
|
221
|
-
|
|
222
|
-
runtimeContext
|
|
205
|
+
requestContext
|
|
223
206
|
}) {
|
|
224
207
|
try {
|
|
225
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
208
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
226
209
|
if (!body) {
|
|
227
210
|
throw new HTTPException(400, { message: "Body is required" });
|
|
228
211
|
}
|
|
@@ -254,12 +237,11 @@ async function deleteThreadHandler({
|
|
|
254
237
|
mastra,
|
|
255
238
|
agentId,
|
|
256
239
|
threadId,
|
|
257
|
-
|
|
258
|
-
runtimeContext
|
|
240
|
+
requestContext
|
|
259
241
|
}) {
|
|
260
242
|
try {
|
|
261
243
|
validateBody({ threadId });
|
|
262
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
244
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
263
245
|
if (!memory) {
|
|
264
246
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
265
247
|
}
|
|
@@ -273,55 +255,41 @@ async function deleteThreadHandler({
|
|
|
273
255
|
return handleError(error, "Error deleting thread");
|
|
274
256
|
}
|
|
275
257
|
}
|
|
276
|
-
async function
|
|
277
|
-
mastra,
|
|
278
|
-
threadId,
|
|
279
|
-
resourceId,
|
|
280
|
-
selectBy,
|
|
281
|
-
format
|
|
282
|
-
}) {
|
|
283
|
-
try {
|
|
284
|
-
validateBody({ threadId });
|
|
285
|
-
const storage = mastra.getStorage();
|
|
286
|
-
if (!storage) {
|
|
287
|
-
throw new HTTPException(400, { message: "Storage is not initialized" });
|
|
288
|
-
}
|
|
289
|
-
const thread = await storage.getThreadById({ threadId });
|
|
290
|
-
if (!thread) {
|
|
291
|
-
throw new HTTPException(404, { message: "Thread not found" });
|
|
292
|
-
}
|
|
293
|
-
const result = await storage.getMessagesPaginated({ threadId, resourceId, selectBy, format });
|
|
294
|
-
return result;
|
|
295
|
-
} catch (error) {
|
|
296
|
-
return handleError(error, "Error getting messages");
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
async function getMessagesHandler({
|
|
258
|
+
async function listMessagesHandler({
|
|
300
259
|
mastra,
|
|
301
260
|
agentId,
|
|
302
261
|
threadId,
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
262
|
+
resourceId,
|
|
263
|
+
perPage,
|
|
264
|
+
page,
|
|
265
|
+
orderBy,
|
|
266
|
+
include,
|
|
267
|
+
filter,
|
|
268
|
+
requestContext
|
|
306
269
|
}) {
|
|
307
|
-
if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
|
|
308
|
-
throw new HTTPException(400, { message: "Invalid limit: must be a positive integer" });
|
|
309
|
-
}
|
|
310
270
|
try {
|
|
311
271
|
validateBody({ threadId });
|
|
312
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
272
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
313
273
|
if (!memory) {
|
|
314
274
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
315
275
|
}
|
|
276
|
+
if (!threadId) {
|
|
277
|
+
throw new HTTPException(400, { message: "No threadId found" });
|
|
278
|
+
}
|
|
316
279
|
const thread = await memory.getThreadById({ threadId });
|
|
317
280
|
if (!thread) {
|
|
318
281
|
throw new HTTPException(404, { message: "Thread not found" });
|
|
319
282
|
}
|
|
320
|
-
const result = await memory.
|
|
283
|
+
const result = await memory.recall({
|
|
321
284
|
threadId,
|
|
322
|
-
|
|
285
|
+
resourceId,
|
|
286
|
+
perPage,
|
|
287
|
+
page,
|
|
288
|
+
orderBy,
|
|
289
|
+
include,
|
|
290
|
+
filter
|
|
323
291
|
});
|
|
324
|
-
return
|
|
292
|
+
return result;
|
|
325
293
|
} catch (error) {
|
|
326
294
|
return handleError(error, "Error getting messages");
|
|
327
295
|
}
|
|
@@ -331,12 +299,11 @@ async function getWorkingMemoryHandler({
|
|
|
331
299
|
agentId,
|
|
332
300
|
threadId,
|
|
333
301
|
resourceId,
|
|
334
|
-
|
|
335
|
-
runtimeContext,
|
|
302
|
+
requestContext,
|
|
336
303
|
memoryConfig
|
|
337
304
|
}) {
|
|
338
305
|
try {
|
|
339
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
306
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
340
307
|
validateBody({ threadId });
|
|
341
308
|
if (!memory) {
|
|
342
309
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
@@ -347,7 +314,7 @@ async function getWorkingMemoryHandler({
|
|
|
347
314
|
const workingMemoryTemplate = template?.format === "json" ? { ...template, content: JSON.stringify(generateEmptyFromSchema(template.content)) } : template;
|
|
348
315
|
const workingMemory = await memory.getWorkingMemory({ threadId, resourceId, memoryConfig });
|
|
349
316
|
const config = memory.getMergedThreadConfig(memoryConfig || {});
|
|
350
|
-
const source = config.workingMemory?.scope
|
|
317
|
+
const source = config.workingMemory?.scope !== "thread" && resourceId ? "resource" : "thread";
|
|
351
318
|
return { workingMemory, source, workingMemoryTemplate, threadExists };
|
|
352
319
|
} catch (error) {
|
|
353
320
|
return handleError(error, "Error getting working memory");
|
|
@@ -358,12 +325,11 @@ async function updateWorkingMemoryHandler({
|
|
|
358
325
|
agentId,
|
|
359
326
|
threadId,
|
|
360
327
|
body,
|
|
361
|
-
|
|
362
|
-
runtimeContext
|
|
328
|
+
requestContext
|
|
363
329
|
}) {
|
|
364
330
|
try {
|
|
365
331
|
validateBody({ threadId });
|
|
366
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
332
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
367
333
|
const { resourceId, memoryConfig, workingMemory } = body;
|
|
368
334
|
if (!memory) {
|
|
369
335
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
@@ -382,14 +348,13 @@ async function deleteMessagesHandler({
|
|
|
382
348
|
mastra,
|
|
383
349
|
agentId,
|
|
384
350
|
messageIds,
|
|
385
|
-
|
|
386
|
-
runtimeContext
|
|
351
|
+
requestContext
|
|
387
352
|
}) {
|
|
388
353
|
try {
|
|
389
354
|
if (messageIds === void 0 || messageIds === null) {
|
|
390
355
|
throw new HTTPException(400, { message: "messageIds is required" });
|
|
391
356
|
}
|
|
392
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
357
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
393
358
|
if (!memory) {
|
|
394
359
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
395
360
|
}
|
|
@@ -410,19 +375,18 @@ async function searchMemoryHandler({
|
|
|
410
375
|
resourceId,
|
|
411
376
|
threadId,
|
|
412
377
|
limit = 20,
|
|
413
|
-
|
|
414
|
-
runtimeContext,
|
|
378
|
+
requestContext,
|
|
415
379
|
memoryConfig
|
|
416
380
|
}) {
|
|
417
381
|
try {
|
|
418
382
|
validateBody({ searchQuery, resourceId });
|
|
419
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
383
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
420
384
|
if (!memory) {
|
|
421
385
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
422
386
|
}
|
|
423
387
|
const config = memory.getMergedThreadConfig(memoryConfig || {});
|
|
424
388
|
const hasSemanticRecall = !!config?.semanticRecall;
|
|
425
|
-
const resourceScope = typeof config?.semanticRecall === "object"
|
|
389
|
+
const resourceScope = typeof config?.semanticRecall === "object" ? config?.semanticRecall?.scope !== "thread" : true;
|
|
426
390
|
if (threadId && !resourceScope) {
|
|
427
391
|
const thread = await memory.getThreadById({ threadId });
|
|
428
392
|
if (!thread) {
|
|
@@ -433,7 +397,6 @@ async function searchMemoryHandler({
|
|
|
433
397
|
}
|
|
434
398
|
}
|
|
435
399
|
const searchResults = [];
|
|
436
|
-
const messageMap = /* @__PURE__ */ new Map();
|
|
437
400
|
if (threadId && !resourceScope) {
|
|
438
401
|
const thread = await memory.getThreadById({ threadId });
|
|
439
402
|
if (!thread) {
|
|
@@ -441,117 +404,85 @@ async function searchMemoryHandler({
|
|
|
441
404
|
results: [],
|
|
442
405
|
count: 0,
|
|
443
406
|
query: searchQuery,
|
|
444
|
-
searchScope: "thread",
|
|
407
|
+
searchScope: resourceScope ? "resource" : "thread",
|
|
445
408
|
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
446
409
|
};
|
|
447
410
|
}
|
|
448
411
|
}
|
|
449
|
-
if (!threadId
|
|
450
|
-
const threads = await memory.
|
|
412
|
+
if (!threadId) {
|
|
413
|
+
const { threads } = await memory.listThreadsByResourceId({
|
|
414
|
+
resourceId,
|
|
415
|
+
page: 0,
|
|
416
|
+
perPage: 1,
|
|
417
|
+
orderBy: { field: "updatedAt", direction: "DESC" }
|
|
418
|
+
});
|
|
451
419
|
if (threads.length === 0) {
|
|
452
420
|
return {
|
|
453
421
|
results: [],
|
|
454
422
|
count: 0,
|
|
455
423
|
query: searchQuery,
|
|
456
|
-
searchScope: "resource",
|
|
424
|
+
searchScope: resourceScope ? "resource" : "thread",
|
|
457
425
|
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
458
426
|
};
|
|
459
427
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
428
|
+
threadId = threads[0].id;
|
|
429
|
+
}
|
|
430
|
+
const beforeRange = typeof config.semanticRecall === `boolean` ? 2 : typeof config.semanticRecall?.messageRange === `number` ? config.semanticRecall.messageRange : config.semanticRecall?.messageRange.before || 2;
|
|
431
|
+
const afterRange = typeof config.semanticRecall === `boolean` ? 2 : typeof config.semanticRecall?.messageRange === `number` ? config.semanticRecall.messageRange : config.semanticRecall?.messageRange.after || 2;
|
|
432
|
+
if (resourceScope && config.semanticRecall) {
|
|
433
|
+
config.semanticRecall = typeof config.semanticRecall === `boolean` ? (
|
|
434
|
+
// make message range 0 so we can highlight the matches in search, message range will include other messages, not the matching ones
|
|
435
|
+
// and we add prev/next messages in a special section on each message anyway
|
|
436
|
+
{ messageRange: 0, topK: 2, scope: "resource" }
|
|
437
|
+
) : { ...config.semanticRecall, messageRange: 0 };
|
|
438
|
+
}
|
|
439
|
+
const threadConfig = memory.getMergedThreadConfig(config || {});
|
|
440
|
+
if (!threadConfig.lastMessages && !threadConfig.semanticRecall) {
|
|
441
|
+
return { results: [], count: 0, query: searchQuery };
|
|
442
|
+
}
|
|
443
|
+
const result = await memory.recall({
|
|
444
|
+
threadId,
|
|
445
|
+
resourceId,
|
|
446
|
+
perPage: threadConfig.lastMessages,
|
|
447
|
+
threadConfig: config,
|
|
448
|
+
vectorSearchString: threadConfig.semanticRecall && searchQuery ? searchQuery : void 0
|
|
449
|
+
});
|
|
450
|
+
const threadIds = Array.from(
|
|
451
|
+
new Set(result.messages.map((m) => m.threadId || threadId).filter(Boolean))
|
|
452
|
+
);
|
|
453
|
+
const fetched = await Promise.all(threadIds.map((id) => memory.getThreadById({ threadId: id })));
|
|
454
|
+
const threadMap = new Map(fetched.filter(Boolean).map((t) => [t.id, t]));
|
|
455
|
+
for (const msg of result.messages) {
|
|
456
|
+
const content = typeof msg.content.content === `string` ? msg.content.content : msg.content.parts?.map((p) => p.type === "text" ? p.text : "").join(" ") || "";
|
|
457
|
+
const msgThreadId = msg.threadId || threadId;
|
|
458
|
+
const thread = threadMap.get(msgThreadId);
|
|
459
|
+
const threadMessages = (await memory.recall({ threadId: msgThreadId })).messages;
|
|
460
|
+
const messageIndex = threadMessages.findIndex((m) => m.id === msg.id);
|
|
461
|
+
const searchResult = {
|
|
462
|
+
id: msg.id,
|
|
463
|
+
role: msg.role,
|
|
464
|
+
content,
|
|
465
|
+
createdAt: msg.createdAt,
|
|
466
|
+
threadId: msgThreadId,
|
|
467
|
+
threadTitle: thread?.title || msgThreadId
|
|
468
|
+
};
|
|
469
|
+
if (messageIndex !== -1) {
|
|
470
|
+
searchResult.context = {
|
|
471
|
+
before: threadMessages.slice(Math.max(0, messageIndex - beforeRange), messageIndex).map((m) => ({
|
|
472
|
+
id: m.id,
|
|
473
|
+
role: m.role,
|
|
474
|
+
content: m.content,
|
|
475
|
+
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
476
|
+
})),
|
|
477
|
+
after: threadMessages.slice(messageIndex + 1, messageIndex + afterRange + 1).map((m) => ({
|
|
478
|
+
id: m.id,
|
|
479
|
+
role: m.role,
|
|
480
|
+
content: m.content,
|
|
481
|
+
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
482
|
+
}))
|
|
512
483
|
};
|
|
513
484
|
}
|
|
514
|
-
|
|
515
|
-
threadId,
|
|
516
|
-
resourceId,
|
|
517
|
-
vectorMessageSearch: searchQuery,
|
|
518
|
-
config
|
|
519
|
-
});
|
|
520
|
-
const threadMessages = (await memory.query({ threadId })).uiMessages;
|
|
521
|
-
result.messagesV2.forEach((msg) => {
|
|
522
|
-
if (messageMap.has(msg.id)) return;
|
|
523
|
-
messageMap.set(msg.id, true);
|
|
524
|
-
const content = msg.content.content || msg.content.parts?.map((p) => p.type === "text" ? p.text : "").join(" ") || "";
|
|
525
|
-
if (!hasSemanticRecall && !content.toLowerCase().includes(searchQuery.toLowerCase())) {
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
const messageIndex = threadMessages.findIndex((m) => m.id === msg.id);
|
|
529
|
-
const searchResult = {
|
|
530
|
-
id: msg.id,
|
|
531
|
-
role: msg.role,
|
|
532
|
-
content,
|
|
533
|
-
createdAt: msg.createdAt,
|
|
534
|
-
threadId,
|
|
535
|
-
threadTitle: thread?.title || threadId
|
|
536
|
-
};
|
|
537
|
-
if (messageIndex !== -1) {
|
|
538
|
-
searchResult.context = {
|
|
539
|
-
before: threadMessages.slice(Math.max(0, messageIndex - 2), messageIndex).map((m) => ({
|
|
540
|
-
id: m.id,
|
|
541
|
-
role: m.role,
|
|
542
|
-
content: m.content,
|
|
543
|
-
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
544
|
-
})),
|
|
545
|
-
after: threadMessages.slice(messageIndex + 1, messageIndex + 3).map((m) => ({
|
|
546
|
-
id: m.id,
|
|
547
|
-
role: m.role,
|
|
548
|
-
content: m.content,
|
|
549
|
-
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
550
|
-
}))
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
searchResults.push(searchResult);
|
|
554
|
-
});
|
|
485
|
+
searchResults.push(searchResult);
|
|
555
486
|
}
|
|
556
487
|
const sortedResults = searchResults.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()).slice(0, limit);
|
|
557
488
|
return {
|
|
@@ -566,6 +497,6 @@ async function searchMemoryHandler({
|
|
|
566
497
|
}
|
|
567
498
|
}
|
|
568
499
|
|
|
569
|
-
export { createThreadHandler, deleteMessagesHandler, deleteThreadHandler, getMemoryConfigHandler, getMemoryStatusHandler,
|
|
570
|
-
//# sourceMappingURL=chunk-
|
|
571
|
-
//# sourceMappingURL=chunk-
|
|
500
|
+
export { createThreadHandler, deleteMessagesHandler, deleteThreadHandler, getMemoryConfigHandler, getMemoryStatusHandler, getThreadByIdHandler, getWorkingMemoryHandler, listMessagesHandler, listThreadsHandler, memory_exports, saveMessagesHandler, searchMemoryHandler, updateThreadHandler, updateWorkingMemoryHandler };
|
|
501
|
+
//# sourceMappingURL=chunk-4JF5WXPL.js.map
|
|
502
|
+
//# sourceMappingURL=chunk-4JF5WXPL.js.map
|