@mastra/server 0.0.0-error-handler-fix-20251020202607 → 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 +802 -3
- package/README.md +1 -1
- package/dist/{chunk-FWO7VQDC.js → chunk-2IS5WICF.js} +7079 -1524
- package/dist/chunk-2IS5WICF.js.map +1 -0
- package/dist/{chunk-SPRRK3P7.cjs → chunk-2YZH5PH6.cjs} +47 -47
- package/dist/chunk-2YZH5PH6.cjs.map +1 -0
- package/dist/{chunk-BATEJLED.js → chunk-3AMNUUZF.js} +20 -20
- package/dist/chunk-3AMNUUZF.js.map +1 -0
- package/dist/{chunk-AW5BU3RQ.js → chunk-3F52QCI4.js} +40 -40
- package/dist/chunk-3F52QCI4.js.map +1 -0
- package/dist/{chunk-OEOGYAQC.js → chunk-4JF5WXPL.js} +155 -206
- 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-ABRFV4XP.js → chunk-73PAWDM5.js} +13 -13
- package/dist/chunk-73PAWDM5.js.map +1 -0
- package/dist/{chunk-2S4IMB6E.cjs → chunk-A24TSVEZ.cjs} +39 -39
- 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-QQXMIP6C.js → chunk-B3Z6J745.js} +17 -17
- package/dist/chunk-B3Z6J745.js.map +1 -0
- package/dist/{chunk-G4PUALCE.cjs → chunk-BTWIR2B7.cjs} +4 -4
- package/dist/{chunk-G4PUALCE.cjs.map → chunk-BTWIR2B7.cjs.map} +1 -1
- package/dist/{chunk-YWOK4F5A.js → chunk-D7T74TVR.js} +4 -6
- package/dist/chunk-D7T74TVR.js.map +1 -0
- package/dist/{chunk-FHSOPERI.cjs → chunk-EHACNWDL.cjs} +221 -242
- package/dist/chunk-EHACNWDL.cjs.map +1 -0
- package/dist/{chunk-HPXAM2PG.js → chunk-FPBYKMIS.js} +13 -13
- package/dist/chunk-FPBYKMIS.js.map +1 -0
- package/dist/{chunk-3SNGNFUJ.cjs → chunk-GLAZTMX3.cjs} +37 -37
- package/dist/chunk-GLAZTMX3.cjs.map +1 -0
- package/dist/{chunk-7HDOBOGG.cjs → chunk-ID6JYDNL.cjs} +7102 -1544
- package/dist/chunk-ID6JYDNL.cjs.map +1 -0
- package/dist/{chunk-TRGAMKHX.cjs → chunk-KF3RI45U.cjs} +46 -41
- package/dist/chunk-KF3RI45U.cjs.map +1 -0
- package/dist/{chunk-TOP25AIO.cjs → chunk-KJIDZQRA.cjs} +14 -14
- package/dist/chunk-KJIDZQRA.cjs.map +1 -0
- package/dist/{chunk-MYR4PVGN.js → chunk-KWH5QBXP.js} +4 -4
- package/dist/{chunk-MYR4PVGN.js.map → chunk-KWH5QBXP.js.map} +1 -1
- package/dist/{chunk-AHB4JCIQ.js → chunk-ND5OKOMT.js} +31 -26
- package/dist/chunk-ND5OKOMT.js.map +1 -0
- package/dist/{chunk-XN74I6VW.cjs → chunk-PPMIB3FQ.cjs} +20 -20
- package/dist/chunk-PPMIB3FQ.cjs.map +1 -0
- package/dist/{chunk-XVPBGW6Y.cjs → chunk-QU6N55W6.cjs} +9 -9
- package/dist/{chunk-XVPBGW6Y.cjs.map → chunk-QU6N55W6.cjs.map} +1 -1
- package/dist/{chunk-EP3JQDPD.cjs → chunk-S54HNARD.cjs} +18 -18
- package/dist/{chunk-EP3JQDPD.cjs.map → chunk-S54HNARD.cjs.map} +1 -1
- package/dist/{chunk-SIW6CYO3.js → chunk-SHWNNZBL.js} +7 -7
- package/dist/{chunk-SIW6CYO3.js.map → chunk-SHWNNZBL.js.map} +1 -1
- package/dist/{chunk-4QCXUEAT.js → chunk-SZIFSF4T.js} +3 -3
- package/dist/{chunk-4QCXUEAT.js.map → chunk-SZIFSF4T.js.map} +1 -1
- package/dist/{chunk-FZNS32WJ.js → chunk-TOCYBDP2.js} +4 -4
- package/dist/{chunk-FZNS32WJ.js.map → chunk-TOCYBDP2.js.map} +1 -1
- 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-VY4ENABS.cjs → chunk-W2KMU354.cjs} +4 -6
- 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-OYL5TBJW.cjs → chunk-X6C7BUWN.cjs} +4 -4
- package/dist/{chunk-OYL5TBJW.cjs.map → chunk-X6C7BUWN.cjs.map} +1 -1
- package/dist/{chunk-XDAYZS6N.js → chunk-Z2O5YVHY.js} +190 -211
- package/dist/chunk-Z2O5YVHY.js.map +1 -0
- package/dist/{chunk-DB63UMTV.js → chunk-ZJ6KEY6H.js} +110 -170
- package/dist/chunk-ZJ6KEY6H.js.map +1 -0
- 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 +31 -19
- package/dist/server/handlers/agent-builder.d.ts +38 -47
- package/dist/server/handlers/agent-builder.d.ts.map +1 -1
- package/dist/server/handlers/agent-builder.js +1 -1
- package/dist/server/handlers/agents.cjs +26 -26
- package/dist/server/handlers/agents.d.ts +44 -54
- 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 -34
- package/dist/server/handlers/memory.d.ts.map +1 -1
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/observability.cjs +8 -8
- package/dist/server/handlers/observability.d.ts +12 -12
- package/dist/server/handlers/observability.d.ts.map +1 -1
- package/dist/server/handlers/observability.js +1 -1
- package/dist/server/handlers/scores.cjs +11 -11
- package/dist/server/handlers/scores.d.ts +24 -24
- package/dist/server/handlers/scores.d.ts.map +1 -1
- package/dist/server/handlers/scores.js +1 -1
- package/dist/server/handlers/tools.cjs +7 -7
- package/dist/server/handlers/tools.d.ts +8 -8
- package/dist/server/handlers/tools.d.ts.map +1 -1
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/utils.cjs +3 -3
- 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 -6
- package/dist/server/handlers/voice.js +1 -1
- package/dist/server/handlers/workflows.cjs +27 -27
- package/dist/server/handlers/workflows.d.ts +34 -37
- package/dist/server/handlers/workflows.d.ts.map +1 -1
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +26 -36
- package/dist/server/handlers.d.ts +0 -2
- package/dist/server/handlers.d.ts.map +1 -1
- package/dist/server/handlers.js +11 -13
- 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 +3 -2
- package/dist/server/utils.d.ts.map +1 -1
- package/dist/{token-53CFGXUO.cjs → token-375W3LEI.cjs} +10 -10
- package/dist/{token-53CFGXUO.cjs.map → token-375W3LEI.cjs.map} +1 -1
- package/dist/{token-WAEKDUVY.js → token-C3IMNCC4.js} +8 -8
- package/dist/{token-WAEKDUVY.js.map → token-C3IMNCC4.js.map} +1 -1
- package/dist/token-util-CV3RRG6K.cjs +9 -0
- package/dist/{token-util-S4A355II.cjs.map → token-util-CV3RRG6K.cjs.map} +1 -1
- package/dist/token-util-E5QO2RCL.js +7 -0
- package/dist/{token-util-LY37VCIN.js.map → token-util-E5QO2RCL.js.map} +1 -1
- package/package.json +11 -8
- package/dist/chunk-2S4IMB6E.cjs.map +0 -1
- package/dist/chunk-3LTO44EP.cjs +0 -570
- package/dist/chunk-3LTO44EP.cjs.map +0 -1
- package/dist/chunk-3SNGNFUJ.cjs.map +0 -1
- package/dist/chunk-67GYDFSB.js +0 -160
- package/dist/chunk-67GYDFSB.js.map +0 -1
- package/dist/chunk-6ZR275MD.cjs +0 -165
- package/dist/chunk-6ZR275MD.cjs.map +0 -1
- package/dist/chunk-7HDOBOGG.cjs.map +0 -1
- package/dist/chunk-ABRFV4XP.js.map +0 -1
- package/dist/chunk-AHB4JCIQ.js.map +0 -1
- package/dist/chunk-AW5BU3RQ.js.map +0 -1
- package/dist/chunk-BATEJLED.js.map +0 -1
- package/dist/chunk-DB63UMTV.js.map +0 -1
- package/dist/chunk-FHSOPERI.cjs.map +0 -1
- package/dist/chunk-FWO7VQDC.js.map +0 -1
- package/dist/chunk-HPXAM2PG.js.map +0 -1
- package/dist/chunk-I3C4ODGV.cjs +0 -335
- package/dist/chunk-I3C4ODGV.cjs.map +0 -1
- package/dist/chunk-LLUOPR3J.js +0 -323
- package/dist/chunk-LLUOPR3J.js.map +0 -1
- package/dist/chunk-MMROOK5J.js.map +0 -1
- package/dist/chunk-MQDBNHBT.cjs +0 -680
- package/dist/chunk-MQDBNHBT.cjs.map +0 -1
- package/dist/chunk-OEOGYAQC.js.map +0 -1
- package/dist/chunk-QQXMIP6C.js.map +0 -1
- package/dist/chunk-SPRRK3P7.cjs.map +0 -1
- package/dist/chunk-TOP25AIO.cjs.map +0 -1
- package/dist/chunk-TRGAMKHX.cjs.map +0 -1
- package/dist/chunk-VY4ENABS.cjs.map +0 -1
- package/dist/chunk-XDAYZS6N.js.map +0 -1
- package/dist/chunk-XN74I6VW.cjs.map +0 -1
- package/dist/chunk-YWOK4F5A.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/telemetry.cjs +0 -20
- package/dist/server/handlers/telemetry.cjs.map +0 -1
- package/dist/server/handlers/telemetry.d.ts +0 -33
- 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/token-util-LY37VCIN.js +0 -7
- package/dist/token-util-S4A355II.cjs +0 -9
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { validateBody } from './chunk-
|
|
2
|
-
import { handleError } from './chunk-
|
|
3
|
-
import { HTTPException } from './chunk-
|
|
1
|
+
import { validateBody } from './chunk-SZIFSF4T.js';
|
|
2
|
+
import { handleError } from './chunk-UXGQZUYZ.js';
|
|
3
|
+
import { HTTPException } from './chunk-6QWQZI4Q.js';
|
|
4
4
|
import { __export } from './chunk-PR4QN5HX.js';
|
|
5
|
-
import {
|
|
5
|
+
import { RequestContext } from '@mastra/core/di';
|
|
6
6
|
import { generateEmptyFromSchema } from '@mastra/core/utils';
|
|
7
7
|
|
|
8
8
|
// src/server/handlers/memory.ts
|
|
@@ -13,12 +13,10 @@ __export(memory_exports, {
|
|
|
13
13
|
deleteThreadHandler: () => deleteThreadHandler,
|
|
14
14
|
getMemoryConfigHandler: () => getMemoryConfigHandler,
|
|
15
15
|
getMemoryStatusHandler: () => getMemoryStatusHandler,
|
|
16
|
-
getMessagesHandler: () => getMessagesHandler,
|
|
17
|
-
getMessagesPaginatedHandler: () => getMessagesPaginatedHandler,
|
|
18
16
|
getThreadByIdHandler: () => getThreadByIdHandler,
|
|
19
|
-
getThreadsHandler: () => getThreadsHandler,
|
|
20
|
-
getThreadsPaginatedHandler: () => getThreadsPaginatedHandler,
|
|
21
17
|
getWorkingMemoryHandler: () => getWorkingMemoryHandler,
|
|
18
|
+
listMessagesHandler: () => listMessagesHandler,
|
|
19
|
+
listThreadsHandler: () => listThreadsHandler,
|
|
22
20
|
saveMessagesHandler: () => saveMessagesHandler,
|
|
23
21
|
searchMemoryHandler: () => searchMemoryHandler,
|
|
24
22
|
updateThreadHandler: () => updateThreadHandler,
|
|
@@ -27,26 +25,50 @@ __export(memory_exports, {
|
|
|
27
25
|
async function getMemoryFromContext({
|
|
28
26
|
mastra,
|
|
29
27
|
agentId,
|
|
30
|
-
|
|
28
|
+
requestContext
|
|
31
29
|
}) {
|
|
32
|
-
const
|
|
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
|
+
}
|
|
38
|
+
}
|
|
33
39
|
if (agentId && !agent) {
|
|
34
|
-
|
|
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
|
+
}
|
|
35
58
|
}
|
|
36
59
|
if (agent) {
|
|
37
60
|
return await agent?.getMemory({
|
|
38
|
-
|
|
39
|
-
})
|
|
61
|
+
requestContext: requestContext ?? new RequestContext()
|
|
62
|
+
});
|
|
40
63
|
}
|
|
41
|
-
return mastra.getMemory();
|
|
42
64
|
}
|
|
43
65
|
async function getMemoryStatusHandler({
|
|
44
66
|
mastra,
|
|
45
67
|
agentId,
|
|
46
|
-
|
|
68
|
+
requestContext
|
|
47
69
|
}) {
|
|
48
70
|
try {
|
|
49
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
71
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
50
72
|
if (!memory) {
|
|
51
73
|
return { result: false };
|
|
52
74
|
}
|
|
@@ -58,10 +80,10 @@ async function getMemoryStatusHandler({
|
|
|
58
80
|
async function getMemoryConfigHandler({
|
|
59
81
|
mastra,
|
|
60
82
|
agentId,
|
|
61
|
-
|
|
83
|
+
requestContext
|
|
62
84
|
}) {
|
|
63
85
|
try {
|
|
64
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
86
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
65
87
|
if (!memory) {
|
|
66
88
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
67
89
|
}
|
|
@@ -71,67 +93,41 @@ async function getMemoryConfigHandler({
|
|
|
71
93
|
return handleError(error, "Error getting memory configuration");
|
|
72
94
|
}
|
|
73
95
|
}
|
|
74
|
-
async function
|
|
75
|
-
mastra,
|
|
76
|
-
agentId,
|
|
77
|
-
resourceId,
|
|
78
|
-
runtimeContext,
|
|
79
|
-
orderBy,
|
|
80
|
-
sortDirection
|
|
81
|
-
}) {
|
|
82
|
-
try {
|
|
83
|
-
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
84
|
-
if (!memory) {
|
|
85
|
-
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
86
|
-
}
|
|
87
|
-
validateBody({ resourceId });
|
|
88
|
-
const threads = await memory.getThreadsByResourceId({
|
|
89
|
-
resourceId,
|
|
90
|
-
orderBy,
|
|
91
|
-
sortDirection
|
|
92
|
-
});
|
|
93
|
-
return threads;
|
|
94
|
-
} catch (error) {
|
|
95
|
-
return handleError(error, "Error getting threads");
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
async function getThreadsPaginatedHandler({
|
|
96
|
+
async function listThreadsHandler({
|
|
99
97
|
mastra,
|
|
100
98
|
agentId,
|
|
101
99
|
resourceId,
|
|
102
|
-
|
|
100
|
+
requestContext,
|
|
103
101
|
page,
|
|
104
102
|
perPage,
|
|
105
|
-
orderBy
|
|
106
|
-
sortDirection
|
|
103
|
+
orderBy
|
|
107
104
|
}) {
|
|
108
105
|
try {
|
|
109
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
106
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
110
107
|
if (!memory) {
|
|
111
108
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
112
109
|
}
|
|
113
110
|
validateBody({ resourceId });
|
|
114
|
-
const result = await memory.
|
|
111
|
+
const result = await memory.listThreadsByResourceId({
|
|
115
112
|
resourceId,
|
|
116
113
|
page,
|
|
117
114
|
perPage,
|
|
118
|
-
orderBy
|
|
119
|
-
sortDirection
|
|
115
|
+
orderBy
|
|
120
116
|
});
|
|
121
117
|
return result;
|
|
122
118
|
} catch (error) {
|
|
123
|
-
return handleError(error, "Error
|
|
119
|
+
return handleError(error, "Error listing threads");
|
|
124
120
|
}
|
|
125
121
|
}
|
|
126
122
|
async function getThreadByIdHandler({
|
|
127
123
|
mastra,
|
|
128
124
|
agentId,
|
|
129
125
|
threadId,
|
|
130
|
-
|
|
126
|
+
requestContext
|
|
131
127
|
}) {
|
|
132
128
|
try {
|
|
133
129
|
validateBody({ threadId });
|
|
134
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
130
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
135
131
|
if (!memory) {
|
|
136
132
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
137
133
|
}
|
|
@@ -148,10 +144,10 @@ async function saveMessagesHandler({
|
|
|
148
144
|
mastra,
|
|
149
145
|
agentId,
|
|
150
146
|
body,
|
|
151
|
-
|
|
147
|
+
requestContext
|
|
152
148
|
}) {
|
|
153
149
|
try {
|
|
154
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
150
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
155
151
|
if (!memory) {
|
|
156
152
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
157
153
|
}
|
|
@@ -182,10 +178,10 @@ async function createThreadHandler({
|
|
|
182
178
|
mastra,
|
|
183
179
|
agentId,
|
|
184
180
|
body,
|
|
185
|
-
|
|
181
|
+
requestContext
|
|
186
182
|
}) {
|
|
187
183
|
try {
|
|
188
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
184
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
189
185
|
if (!memory) {
|
|
190
186
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
191
187
|
}
|
|
@@ -206,10 +202,10 @@ async function updateThreadHandler({
|
|
|
206
202
|
agentId,
|
|
207
203
|
threadId,
|
|
208
204
|
body,
|
|
209
|
-
|
|
205
|
+
requestContext
|
|
210
206
|
}) {
|
|
211
207
|
try {
|
|
212
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
208
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
213
209
|
if (!body) {
|
|
214
210
|
throw new HTTPException(400, { message: "Body is required" });
|
|
215
211
|
}
|
|
@@ -241,11 +237,11 @@ async function deleteThreadHandler({
|
|
|
241
237
|
mastra,
|
|
242
238
|
agentId,
|
|
243
239
|
threadId,
|
|
244
|
-
|
|
240
|
+
requestContext
|
|
245
241
|
}) {
|
|
246
242
|
try {
|
|
247
243
|
validateBody({ threadId });
|
|
248
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
244
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
249
245
|
if (!memory) {
|
|
250
246
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
251
247
|
}
|
|
@@ -259,55 +255,41 @@ async function deleteThreadHandler({
|
|
|
259
255
|
return handleError(error, "Error deleting thread");
|
|
260
256
|
}
|
|
261
257
|
}
|
|
262
|
-
async function
|
|
263
|
-
mastra,
|
|
264
|
-
threadId,
|
|
265
|
-
resourceId,
|
|
266
|
-
selectBy,
|
|
267
|
-
format
|
|
268
|
-
}) {
|
|
269
|
-
try {
|
|
270
|
-
validateBody({ threadId });
|
|
271
|
-
const storage = mastra.getStorage();
|
|
272
|
-
if (!storage) {
|
|
273
|
-
throw new HTTPException(400, { message: "Storage is not initialized" });
|
|
274
|
-
}
|
|
275
|
-
const thread = await storage.getThreadById({ threadId });
|
|
276
|
-
if (!thread) {
|
|
277
|
-
throw new HTTPException(404, { message: "Thread not found" });
|
|
278
|
-
}
|
|
279
|
-
const result = await storage.getMessagesPaginated({ threadId, resourceId, selectBy, format });
|
|
280
|
-
return result;
|
|
281
|
-
} catch (error) {
|
|
282
|
-
return handleError(error, "Error getting messages");
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
async function getMessagesHandler({
|
|
258
|
+
async function listMessagesHandler({
|
|
286
259
|
mastra,
|
|
287
260
|
agentId,
|
|
288
261
|
threadId,
|
|
289
|
-
|
|
290
|
-
|
|
262
|
+
resourceId,
|
|
263
|
+
perPage,
|
|
264
|
+
page,
|
|
265
|
+
orderBy,
|
|
266
|
+
include,
|
|
267
|
+
filter,
|
|
268
|
+
requestContext
|
|
291
269
|
}) {
|
|
292
|
-
if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
|
|
293
|
-
throw new HTTPException(400, { message: "Invalid limit: must be a positive integer" });
|
|
294
|
-
}
|
|
295
270
|
try {
|
|
296
271
|
validateBody({ threadId });
|
|
297
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
272
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
298
273
|
if (!memory) {
|
|
299
274
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
300
275
|
}
|
|
276
|
+
if (!threadId) {
|
|
277
|
+
throw new HTTPException(400, { message: "No threadId found" });
|
|
278
|
+
}
|
|
301
279
|
const thread = await memory.getThreadById({ threadId });
|
|
302
280
|
if (!thread) {
|
|
303
281
|
throw new HTTPException(404, { message: "Thread not found" });
|
|
304
282
|
}
|
|
305
|
-
const result = await memory.
|
|
283
|
+
const result = await memory.recall({
|
|
306
284
|
threadId,
|
|
307
|
-
|
|
285
|
+
resourceId,
|
|
286
|
+
perPage,
|
|
287
|
+
page,
|
|
288
|
+
orderBy,
|
|
289
|
+
include,
|
|
290
|
+
filter
|
|
308
291
|
});
|
|
309
|
-
|
|
310
|
-
return { messages: result.messages, uiMessages, legacyMessages: result.uiMessages };
|
|
292
|
+
return result;
|
|
311
293
|
} catch (error) {
|
|
312
294
|
return handleError(error, "Error getting messages");
|
|
313
295
|
}
|
|
@@ -317,11 +299,11 @@ async function getWorkingMemoryHandler({
|
|
|
317
299
|
agentId,
|
|
318
300
|
threadId,
|
|
319
301
|
resourceId,
|
|
320
|
-
|
|
302
|
+
requestContext,
|
|
321
303
|
memoryConfig
|
|
322
304
|
}) {
|
|
323
305
|
try {
|
|
324
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
306
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
325
307
|
validateBody({ threadId });
|
|
326
308
|
if (!memory) {
|
|
327
309
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
@@ -332,7 +314,7 @@ async function getWorkingMemoryHandler({
|
|
|
332
314
|
const workingMemoryTemplate = template?.format === "json" ? { ...template, content: JSON.stringify(generateEmptyFromSchema(template.content)) } : template;
|
|
333
315
|
const workingMemory = await memory.getWorkingMemory({ threadId, resourceId, memoryConfig });
|
|
334
316
|
const config = memory.getMergedThreadConfig(memoryConfig || {});
|
|
335
|
-
const source = config.workingMemory?.scope
|
|
317
|
+
const source = config.workingMemory?.scope !== "thread" && resourceId ? "resource" : "thread";
|
|
336
318
|
return { workingMemory, source, workingMemoryTemplate, threadExists };
|
|
337
319
|
} catch (error) {
|
|
338
320
|
return handleError(error, "Error getting working memory");
|
|
@@ -343,11 +325,11 @@ async function updateWorkingMemoryHandler({
|
|
|
343
325
|
agentId,
|
|
344
326
|
threadId,
|
|
345
327
|
body,
|
|
346
|
-
|
|
328
|
+
requestContext
|
|
347
329
|
}) {
|
|
348
330
|
try {
|
|
349
331
|
validateBody({ threadId });
|
|
350
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
332
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
351
333
|
const { resourceId, memoryConfig, workingMemory } = body;
|
|
352
334
|
if (!memory) {
|
|
353
335
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
@@ -366,13 +348,13 @@ async function deleteMessagesHandler({
|
|
|
366
348
|
mastra,
|
|
367
349
|
agentId,
|
|
368
350
|
messageIds,
|
|
369
|
-
|
|
351
|
+
requestContext
|
|
370
352
|
}) {
|
|
371
353
|
try {
|
|
372
354
|
if (messageIds === void 0 || messageIds === null) {
|
|
373
355
|
throw new HTTPException(400, { message: "messageIds is required" });
|
|
374
356
|
}
|
|
375
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
357
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
376
358
|
if (!memory) {
|
|
377
359
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
378
360
|
}
|
|
@@ -393,18 +375,18 @@ async function searchMemoryHandler({
|
|
|
393
375
|
resourceId,
|
|
394
376
|
threadId,
|
|
395
377
|
limit = 20,
|
|
396
|
-
|
|
378
|
+
requestContext,
|
|
397
379
|
memoryConfig
|
|
398
380
|
}) {
|
|
399
381
|
try {
|
|
400
382
|
validateBody({ searchQuery, resourceId });
|
|
401
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
383
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
402
384
|
if (!memory) {
|
|
403
385
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
404
386
|
}
|
|
405
387
|
const config = memory.getMergedThreadConfig(memoryConfig || {});
|
|
406
388
|
const hasSemanticRecall = !!config?.semanticRecall;
|
|
407
|
-
const resourceScope = typeof config?.semanticRecall === "object"
|
|
389
|
+
const resourceScope = typeof config?.semanticRecall === "object" ? config?.semanticRecall?.scope !== "thread" : true;
|
|
408
390
|
if (threadId && !resourceScope) {
|
|
409
391
|
const thread = await memory.getThreadById({ threadId });
|
|
410
392
|
if (!thread) {
|
|
@@ -415,7 +397,6 @@ async function searchMemoryHandler({
|
|
|
415
397
|
}
|
|
416
398
|
}
|
|
417
399
|
const searchResults = [];
|
|
418
|
-
const messageMap = /* @__PURE__ */ new Map();
|
|
419
400
|
if (threadId && !resourceScope) {
|
|
420
401
|
const thread = await memory.getThreadById({ threadId });
|
|
421
402
|
if (!thread) {
|
|
@@ -423,117 +404,85 @@ async function searchMemoryHandler({
|
|
|
423
404
|
results: [],
|
|
424
405
|
count: 0,
|
|
425
406
|
query: searchQuery,
|
|
426
|
-
searchScope: "thread",
|
|
407
|
+
searchScope: resourceScope ? "resource" : "thread",
|
|
427
408
|
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
428
409
|
};
|
|
429
410
|
}
|
|
430
411
|
}
|
|
431
|
-
if (!threadId
|
|
432
|
-
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
|
+
});
|
|
433
419
|
if (threads.length === 0) {
|
|
434
420
|
return {
|
|
435
421
|
results: [],
|
|
436
422
|
count: 0,
|
|
437
423
|
query: searchQuery,
|
|
438
|
-
searchScope: "resource",
|
|
424
|
+
searchScope: resourceScope ? "resource" : "thread",
|
|
439
425
|
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
440
426
|
};
|
|
441
427
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
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
|
-
|
|
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
|
+
}))
|
|
494
483
|
};
|
|
495
484
|
}
|
|
496
|
-
|
|
497
|
-
threadId,
|
|
498
|
-
resourceId,
|
|
499
|
-
vectorMessageSearch: searchQuery,
|
|
500
|
-
config
|
|
501
|
-
});
|
|
502
|
-
const threadMessages = (await memory.query({ threadId })).uiMessages;
|
|
503
|
-
result.messagesV2.forEach((msg) => {
|
|
504
|
-
if (messageMap.has(msg.id)) return;
|
|
505
|
-
messageMap.set(msg.id, true);
|
|
506
|
-
const content = msg.content.content || msg.content.parts?.map((p) => p.type === "text" ? p.text : "").join(" ") || "";
|
|
507
|
-
if (!hasSemanticRecall && !content.toLowerCase().includes(searchQuery.toLowerCase())) {
|
|
508
|
-
return;
|
|
509
|
-
}
|
|
510
|
-
const messageIndex = threadMessages.findIndex((m) => m.id === msg.id);
|
|
511
|
-
const searchResult = {
|
|
512
|
-
id: msg.id,
|
|
513
|
-
role: msg.role,
|
|
514
|
-
content,
|
|
515
|
-
createdAt: msg.createdAt,
|
|
516
|
-
threadId,
|
|
517
|
-
threadTitle: thread?.title || threadId
|
|
518
|
-
};
|
|
519
|
-
if (messageIndex !== -1) {
|
|
520
|
-
searchResult.context = {
|
|
521
|
-
before: threadMessages.slice(Math.max(0, messageIndex - 2), messageIndex).map((m) => ({
|
|
522
|
-
id: m.id,
|
|
523
|
-
role: m.role,
|
|
524
|
-
content: m.content,
|
|
525
|
-
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
526
|
-
})),
|
|
527
|
-
after: threadMessages.slice(messageIndex + 1, messageIndex + 3).map((m) => ({
|
|
528
|
-
id: m.id,
|
|
529
|
-
role: m.role,
|
|
530
|
-
content: m.content,
|
|
531
|
-
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
532
|
-
}))
|
|
533
|
-
};
|
|
534
|
-
}
|
|
535
|
-
searchResults.push(searchResult);
|
|
536
|
-
});
|
|
485
|
+
searchResults.push(searchResult);
|
|
537
486
|
}
|
|
538
487
|
const sortedResults = searchResults.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()).slice(0, limit);
|
|
539
488
|
return {
|
|
@@ -548,6 +497,6 @@ async function searchMemoryHandler({
|
|
|
548
497
|
}
|
|
549
498
|
}
|
|
550
499
|
|
|
551
|
-
export { createThreadHandler, deleteMessagesHandler, deleteThreadHandler, getMemoryConfigHandler, getMemoryStatusHandler,
|
|
552
|
-
//# sourceMappingURL=chunk-
|
|
553
|
-
//# 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
|