@mastra/server 0.0.0-playground-studio-cloud-20251031080052 → 0.0.0-playground-studio-again-20251114102707
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 +685 -3
- package/README.md +1 -1
- package/dist/{chunk-7HCPO76Z.js → chunk-2IS5WICF.js} +4505 -1017
- 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-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-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-KSFLUEWV.js → chunk-D7T74TVR.js} +4 -5
- package/dist/chunk-D7T74TVR.js.map +1 -0
- package/dist/{chunk-YSHNCC6F.cjs → chunk-EHACNWDL.cjs} +169 -201
- package/dist/chunk-EHACNWDL.cjs.map +1 -0
- package/dist/{chunk-MN2TZQ7I.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-KDUHLUK4.cjs → chunk-ID6JYDNL.cjs} +4387 -896
- 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-K5T5A3AL.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-EP3JQDPD.cjs → chunk-S54HNARD.cjs} +18 -18
- package/dist/{chunk-EP3JQDPD.cjs.map → chunk-S54HNARD.cjs.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-Y7SH5ZKM.cjs → chunk-U7GLIXYO.cjs} +157 -172
- package/dist/chunk-U7GLIXYO.cjs.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-OGK26QPW.js → chunk-V6JYJS7O.js} +109 -123
- package/dist/chunk-V6JYJS7O.js.map +1 -0
- package/dist/{chunk-CJFKRVED.cjs → chunk-W2KMU354.cjs} +4 -5
- package/dist/chunk-W2KMU354.cjs.map +1 -0
- package/dist/{chunk-B7QWVGQQ.cjs → chunk-X3MICMI2.cjs} +140 -249
- package/dist/chunk-X3MICMI2.cjs.map +1 -0
- package/dist/{chunk-6VPAV4ZV.js → chunk-Z2O5YVHY.js} +134 -165
- package/dist/chunk-Z2O5YVHY.js.map +1 -0
- package/dist/{chunk-ZLBL4NQC.js → chunk-ZJ6KEY6H.js} +67 -174
- 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 +25 -29
- package/dist/server/handlers/agents.d.ts +41 -55
- 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 +19 -23
- package/dist/server/handlers/memory.d.ts +30 -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 +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 +21 -29
- package/dist/server/handlers/workflows.d.ts +27 -36
- package/dist/server/handlers/workflows.d.ts.map +1 -1
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +23 -28
- package/dist/server/handlers.d.ts +0 -1
- 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 +3 -2
- package/dist/server/utils.d.ts.map +1 -1
- package/package.json +13 -8
- package/dist/chunk-2S4IMB6E.cjs.map +0 -1
- package/dist/chunk-3SNGNFUJ.cjs.map +0 -1
- package/dist/chunk-6VPAV4ZV.js.map +0 -1
- package/dist/chunk-7HCPO76Z.js.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-B7QWVGQQ.cjs.map +0 -1
- package/dist/chunk-BATEJLED.js.map +0 -1
- package/dist/chunk-CJFKRVED.cjs.map +0 -1
- package/dist/chunk-I3C4ODGV.cjs +0 -335
- package/dist/chunk-I3C4ODGV.cjs.map +0 -1
- package/dist/chunk-K5T5A3AL.cjs.map +0 -1
- package/dist/chunk-KDUHLUK4.cjs.map +0 -1
- package/dist/chunk-KSFLUEWV.js.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-MN2TZQ7I.js.map +0 -1
- package/dist/chunk-OGK26QPW.js.map +0 -1
- package/dist/chunk-QQXMIP6C.js.map +0 -1
- package/dist/chunk-SPRRK3P7.cjs.map +0 -1
- package/dist/chunk-TRGAMKHX.cjs.map +0 -1
- package/dist/chunk-XN74I6VW.cjs.map +0 -1
- package/dist/chunk-Y7SH5ZKM.cjs.map +0 -1
- package/dist/chunk-YSHNCC6F.cjs.map +0 -1
- package/dist/chunk-ZLBL4NQC.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
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunkBTWIR2B7_cjs = require('./chunk-BTWIR2B7.cjs');
|
|
4
|
+
var chunkV5WWQN7P_cjs = require('./chunk-V5WWQN7P.cjs');
|
|
5
|
+
var chunk64ITUOXI_cjs = require('./chunk-64ITUOXI.cjs');
|
|
6
6
|
var chunkO7I5CWRX_cjs = require('./chunk-O7I5CWRX.cjs');
|
|
7
|
-
var
|
|
7
|
+
var di = require('@mastra/core/di');
|
|
8
8
|
var utils = require('@mastra/core/utils');
|
|
9
9
|
|
|
10
10
|
// src/server/handlers/memory.ts
|
|
@@ -15,34 +15,43 @@ chunkO7I5CWRX_cjs.__export(memory_exports, {
|
|
|
15
15
|
deleteThreadHandler: () => deleteThreadHandler,
|
|
16
16
|
getMemoryConfigHandler: () => getMemoryConfigHandler,
|
|
17
17
|
getMemoryStatusHandler: () => getMemoryStatusHandler,
|
|
18
|
-
|
|
19
|
-
getMessagesPaginatedHandler: () => getMessagesPaginatedHandler,
|
|
18
|
+
getTextContent: () => getTextContent,
|
|
20
19
|
getThreadByIdHandler: () => getThreadByIdHandler,
|
|
21
|
-
getThreadsHandler: () => getThreadsHandler,
|
|
22
|
-
getThreadsPaginatedHandler: () => getThreadsPaginatedHandler,
|
|
23
20
|
getWorkingMemoryHandler: () => getWorkingMemoryHandler,
|
|
21
|
+
listMessagesHandler: () => listMessagesHandler,
|
|
22
|
+
listThreadsHandler: () => listThreadsHandler,
|
|
24
23
|
saveMessagesHandler: () => saveMessagesHandler,
|
|
25
24
|
searchMemoryHandler: () => searchMemoryHandler,
|
|
26
25
|
updateThreadHandler: () => updateThreadHandler,
|
|
27
26
|
updateWorkingMemoryHandler: () => updateWorkingMemoryHandler
|
|
28
27
|
});
|
|
28
|
+
function getTextContent(message) {
|
|
29
|
+
if (typeof message.content === "string") {
|
|
30
|
+
return message.content;
|
|
31
|
+
}
|
|
32
|
+
if (message.content && typeof message.content === "object" && "parts" in message.content) {
|
|
33
|
+
const textPart = message.content.parts.find((p) => p.type === "text");
|
|
34
|
+
return textPart?.text || "";
|
|
35
|
+
}
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
29
38
|
async function getMemoryFromContext({
|
|
30
39
|
mastra,
|
|
31
40
|
agentId,
|
|
32
|
-
|
|
41
|
+
requestContext
|
|
33
42
|
}) {
|
|
34
43
|
const logger = mastra.getLogger();
|
|
35
44
|
let agent;
|
|
36
45
|
if (agentId) {
|
|
37
46
|
try {
|
|
38
|
-
agent = mastra.
|
|
47
|
+
agent = mastra.getAgentById(agentId);
|
|
39
48
|
} catch (error) {
|
|
40
49
|
logger.debug("Error getting agent from mastra, searching agents for agent", error);
|
|
41
50
|
}
|
|
42
51
|
}
|
|
43
52
|
if (agentId && !agent) {
|
|
44
53
|
logger.debug("Agent not found, searching agents for agent", { agentId });
|
|
45
|
-
const agents = mastra.
|
|
54
|
+
const agents = mastra.listAgents();
|
|
46
55
|
if (Object.keys(agents || {}).length) {
|
|
47
56
|
for (const [_, ag] of Object.entries(agents)) {
|
|
48
57
|
try {
|
|
@@ -57,140 +66,113 @@ async function getMemoryFromContext({
|
|
|
57
66
|
}
|
|
58
67
|
}
|
|
59
68
|
if (!agent) {
|
|
60
|
-
throw new
|
|
69
|
+
throw new chunk64ITUOXI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
61
70
|
}
|
|
62
71
|
}
|
|
63
72
|
if (agent) {
|
|
64
73
|
return await agent?.getMemory({
|
|
65
|
-
|
|
66
|
-
})
|
|
74
|
+
requestContext: requestContext ?? new di.RequestContext()
|
|
75
|
+
});
|
|
67
76
|
}
|
|
68
|
-
return mastra.getMemory();
|
|
69
77
|
}
|
|
70
78
|
async function getMemoryStatusHandler({
|
|
71
79
|
mastra,
|
|
72
80
|
agentId,
|
|
73
|
-
|
|
81
|
+
requestContext
|
|
74
82
|
}) {
|
|
75
83
|
try {
|
|
76
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
84
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
77
85
|
if (!memory) {
|
|
78
86
|
return { result: false };
|
|
79
87
|
}
|
|
80
88
|
return { result: true };
|
|
81
89
|
} catch (error) {
|
|
82
|
-
return
|
|
90
|
+
return chunkV5WWQN7P_cjs.handleError(error, "Error getting memory status");
|
|
83
91
|
}
|
|
84
92
|
}
|
|
85
93
|
async function getMemoryConfigHandler({
|
|
86
94
|
mastra,
|
|
87
95
|
agentId,
|
|
88
|
-
|
|
96
|
+
requestContext
|
|
89
97
|
}) {
|
|
90
98
|
try {
|
|
91
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
99
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
92
100
|
if (!memory) {
|
|
93
|
-
throw new
|
|
101
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
94
102
|
}
|
|
95
103
|
const config = memory.getMergedThreadConfig({});
|
|
96
104
|
return { config };
|
|
97
105
|
} catch (error) {
|
|
98
|
-
return
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
async function getThreadsHandler({
|
|
102
|
-
mastra,
|
|
103
|
-
agentId,
|
|
104
|
-
resourceId,
|
|
105
|
-
runtimeContext,
|
|
106
|
-
orderBy,
|
|
107
|
-
sortDirection
|
|
108
|
-
}) {
|
|
109
|
-
try {
|
|
110
|
-
const memory = await getMemoryFromContext({ mastra, agentId, runtimeContext });
|
|
111
|
-
if (!memory) {
|
|
112
|
-
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
113
|
-
}
|
|
114
|
-
chunkG4PUALCE_cjs.validateBody({ resourceId });
|
|
115
|
-
const threads = await memory.getThreadsByResourceId({
|
|
116
|
-
resourceId,
|
|
117
|
-
orderBy,
|
|
118
|
-
sortDirection
|
|
119
|
-
});
|
|
120
|
-
return threads;
|
|
121
|
-
} catch (error) {
|
|
122
|
-
return chunkRE4RPXT2_cjs.handleError(error, "Error getting threads");
|
|
106
|
+
return chunkV5WWQN7P_cjs.handleError(error, "Error getting memory configuration");
|
|
123
107
|
}
|
|
124
108
|
}
|
|
125
|
-
async function
|
|
109
|
+
async function listThreadsHandler({
|
|
126
110
|
mastra,
|
|
127
111
|
agentId,
|
|
128
112
|
resourceId,
|
|
129
|
-
|
|
113
|
+
requestContext,
|
|
130
114
|
page,
|
|
131
115
|
perPage,
|
|
132
|
-
orderBy
|
|
133
|
-
sortDirection
|
|
116
|
+
orderBy
|
|
134
117
|
}) {
|
|
135
118
|
try {
|
|
136
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
119
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
137
120
|
if (!memory) {
|
|
138
|
-
throw new
|
|
121
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
139
122
|
}
|
|
140
|
-
|
|
141
|
-
const result = await memory.
|
|
123
|
+
chunkBTWIR2B7_cjs.validateBody({ resourceId });
|
|
124
|
+
const result = await memory.listThreadsByResourceId({
|
|
142
125
|
resourceId,
|
|
143
126
|
page,
|
|
144
127
|
perPage,
|
|
145
|
-
orderBy
|
|
146
|
-
sortDirection
|
|
128
|
+
orderBy
|
|
147
129
|
});
|
|
148
130
|
return result;
|
|
149
131
|
} catch (error) {
|
|
150
|
-
return
|
|
132
|
+
return chunkV5WWQN7P_cjs.handleError(error, "Error listing threads");
|
|
151
133
|
}
|
|
152
134
|
}
|
|
153
135
|
async function getThreadByIdHandler({
|
|
154
136
|
mastra,
|
|
155
137
|
agentId,
|
|
156
138
|
threadId,
|
|
157
|
-
|
|
139
|
+
requestContext
|
|
158
140
|
}) {
|
|
159
141
|
try {
|
|
160
|
-
|
|
161
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
142
|
+
chunkBTWIR2B7_cjs.validateBody({ threadId });
|
|
143
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
162
144
|
if (!memory) {
|
|
163
|
-
throw new
|
|
145
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
164
146
|
}
|
|
165
147
|
const thread = await memory.getThreadById({ threadId });
|
|
166
148
|
if (!thread) {
|
|
167
|
-
throw new
|
|
149
|
+
throw new chunk64ITUOXI_cjs.HTTPException(404, { message: "Thread not found" });
|
|
168
150
|
}
|
|
169
151
|
return thread;
|
|
170
152
|
} catch (error) {
|
|
171
|
-
return
|
|
153
|
+
return chunkV5WWQN7P_cjs.handleError(error, "Error getting thread");
|
|
172
154
|
}
|
|
173
155
|
}
|
|
174
156
|
async function saveMessagesHandler({
|
|
175
157
|
mastra,
|
|
176
158
|
agentId,
|
|
177
159
|
body,
|
|
178
|
-
|
|
160
|
+
requestContext
|
|
179
161
|
}) {
|
|
180
162
|
try {
|
|
181
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
163
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
182
164
|
if (!memory) {
|
|
183
|
-
throw new
|
|
165
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
184
166
|
}
|
|
185
167
|
if (!body?.messages) {
|
|
186
|
-
throw new
|
|
168
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Messages are required" });
|
|
187
169
|
}
|
|
188
170
|
if (!Array.isArray(body.messages)) {
|
|
189
|
-
throw new
|
|
171
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Messages should be an array" });
|
|
190
172
|
}
|
|
191
173
|
const invalidMessages = body.messages.filter((message) => !message.threadId || !message.resourceId);
|
|
192
174
|
if (invalidMessages.length > 0) {
|
|
193
|
-
throw new
|
|
175
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, {
|
|
194
176
|
message: `All messages must have threadId and resourceId fields. Found ${invalidMessages.length} invalid message(s).`
|
|
195
177
|
});
|
|
196
178
|
}
|
|
@@ -202,21 +184,21 @@ async function saveMessagesHandler({
|
|
|
202
184
|
const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
|
|
203
185
|
return result;
|
|
204
186
|
} catch (error) {
|
|
205
|
-
return
|
|
187
|
+
return chunkV5WWQN7P_cjs.handleError(error, "Error saving messages");
|
|
206
188
|
}
|
|
207
189
|
}
|
|
208
190
|
async function createThreadHandler({
|
|
209
191
|
mastra,
|
|
210
192
|
agentId,
|
|
211
193
|
body,
|
|
212
|
-
|
|
194
|
+
requestContext
|
|
213
195
|
}) {
|
|
214
196
|
try {
|
|
215
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
197
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
216
198
|
if (!memory) {
|
|
217
|
-
throw new
|
|
199
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
218
200
|
}
|
|
219
|
-
|
|
201
|
+
chunkBTWIR2B7_cjs.validateBody({ resourceId: body?.resourceId });
|
|
220
202
|
const result = await memory.createThread({
|
|
221
203
|
resourceId: body?.resourceId,
|
|
222
204
|
title: body?.title,
|
|
@@ -225,7 +207,7 @@ async function createThreadHandler({
|
|
|
225
207
|
});
|
|
226
208
|
return result;
|
|
227
209
|
} catch (error) {
|
|
228
|
-
return
|
|
210
|
+
return chunkV5WWQN7P_cjs.handleError(error, "Error saving thread to memory");
|
|
229
211
|
}
|
|
230
212
|
}
|
|
231
213
|
async function updateThreadHandler({
|
|
@@ -233,22 +215,22 @@ async function updateThreadHandler({
|
|
|
233
215
|
agentId,
|
|
234
216
|
threadId,
|
|
235
217
|
body,
|
|
236
|
-
|
|
218
|
+
requestContext
|
|
237
219
|
}) {
|
|
238
220
|
try {
|
|
239
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
221
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
240
222
|
if (!body) {
|
|
241
|
-
throw new
|
|
223
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Body is required" });
|
|
242
224
|
}
|
|
243
225
|
const { title, metadata, resourceId } = body;
|
|
244
226
|
const updatedAt = /* @__PURE__ */ new Date();
|
|
245
|
-
|
|
227
|
+
chunkBTWIR2B7_cjs.validateBody({ threadId });
|
|
246
228
|
if (!memory) {
|
|
247
|
-
throw new
|
|
229
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
248
230
|
}
|
|
249
231
|
const thread = await memory.getThreadById({ threadId });
|
|
250
232
|
if (!thread) {
|
|
251
|
-
throw new
|
|
233
|
+
throw new chunk64ITUOXI_cjs.HTTPException(404, { message: "Thread not found" });
|
|
252
234
|
}
|
|
253
235
|
const updatedThread = {
|
|
254
236
|
...thread,
|
|
@@ -261,82 +243,68 @@ async function updateThreadHandler({
|
|
|
261
243
|
const result = await memory.saveThread({ thread: updatedThread });
|
|
262
244
|
return result;
|
|
263
245
|
} catch (error) {
|
|
264
|
-
return
|
|
246
|
+
return chunkV5WWQN7P_cjs.handleError(error, "Error updating thread");
|
|
265
247
|
}
|
|
266
248
|
}
|
|
267
249
|
async function deleteThreadHandler({
|
|
268
250
|
mastra,
|
|
269
251
|
agentId,
|
|
270
252
|
threadId,
|
|
271
|
-
|
|
253
|
+
requestContext
|
|
272
254
|
}) {
|
|
273
255
|
try {
|
|
274
|
-
|
|
275
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
256
|
+
chunkBTWIR2B7_cjs.validateBody({ threadId });
|
|
257
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
276
258
|
if (!memory) {
|
|
277
|
-
throw new
|
|
259
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
278
260
|
}
|
|
279
261
|
const thread = await memory.getThreadById({ threadId });
|
|
280
262
|
if (!thread) {
|
|
281
|
-
throw new
|
|
263
|
+
throw new chunk64ITUOXI_cjs.HTTPException(404, { message: "Thread not found" });
|
|
282
264
|
}
|
|
283
265
|
await memory.deleteThread(threadId);
|
|
284
266
|
return { result: "Thread deleted" };
|
|
285
267
|
} catch (error) {
|
|
286
|
-
return
|
|
268
|
+
return chunkV5WWQN7P_cjs.handleError(error, "Error deleting thread");
|
|
287
269
|
}
|
|
288
270
|
}
|
|
289
|
-
async function
|
|
290
|
-
mastra,
|
|
291
|
-
threadId,
|
|
292
|
-
resourceId,
|
|
293
|
-
selectBy,
|
|
294
|
-
format
|
|
295
|
-
}) {
|
|
296
|
-
try {
|
|
297
|
-
chunkG4PUALCE_cjs.validateBody({ threadId });
|
|
298
|
-
const storage = mastra.getStorage();
|
|
299
|
-
if (!storage) {
|
|
300
|
-
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Storage is not initialized" });
|
|
301
|
-
}
|
|
302
|
-
const thread = await storage.getThreadById({ threadId });
|
|
303
|
-
if (!thread) {
|
|
304
|
-
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Thread not found" });
|
|
305
|
-
}
|
|
306
|
-
const result = await storage.getMessagesPaginated({ threadId, resourceId, selectBy, format });
|
|
307
|
-
return result;
|
|
308
|
-
} catch (error) {
|
|
309
|
-
return chunkRE4RPXT2_cjs.handleError(error, "Error getting messages");
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
async function getMessagesHandler({
|
|
271
|
+
async function listMessagesHandler({
|
|
313
272
|
mastra,
|
|
314
273
|
agentId,
|
|
315
274
|
threadId,
|
|
316
|
-
|
|
317
|
-
|
|
275
|
+
resourceId,
|
|
276
|
+
perPage,
|
|
277
|
+
page,
|
|
278
|
+
orderBy,
|
|
279
|
+
include,
|
|
280
|
+
filter,
|
|
281
|
+
requestContext
|
|
318
282
|
}) {
|
|
319
|
-
if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
|
|
320
|
-
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Invalid limit: must be a positive integer" });
|
|
321
|
-
}
|
|
322
283
|
try {
|
|
323
|
-
|
|
324
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
284
|
+
chunkBTWIR2B7_cjs.validateBody({ threadId });
|
|
285
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
325
286
|
if (!memory) {
|
|
326
|
-
throw new
|
|
287
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
288
|
+
}
|
|
289
|
+
if (!threadId) {
|
|
290
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "No threadId found" });
|
|
327
291
|
}
|
|
328
292
|
const thread = await memory.getThreadById({ threadId });
|
|
329
293
|
if (!thread) {
|
|
330
|
-
throw new
|
|
294
|
+
throw new chunk64ITUOXI_cjs.HTTPException(404, { message: "Thread not found" });
|
|
331
295
|
}
|
|
332
|
-
const result = await memory.
|
|
296
|
+
const result = await memory.recall({
|
|
333
297
|
threadId,
|
|
334
|
-
|
|
298
|
+
resourceId,
|
|
299
|
+
perPage,
|
|
300
|
+
page,
|
|
301
|
+
orderBy,
|
|
302
|
+
include,
|
|
303
|
+
filter
|
|
335
304
|
});
|
|
336
|
-
|
|
337
|
-
return { messages: result.messages, uiMessages, legacyMessages: result.uiMessages };
|
|
305
|
+
return result;
|
|
338
306
|
} catch (error) {
|
|
339
|
-
return
|
|
307
|
+
return chunkV5WWQN7P_cjs.handleError(error, "Error getting messages");
|
|
340
308
|
}
|
|
341
309
|
}
|
|
342
310
|
async function getWorkingMemoryHandler({
|
|
@@ -344,14 +312,14 @@ async function getWorkingMemoryHandler({
|
|
|
344
312
|
agentId,
|
|
345
313
|
threadId,
|
|
346
314
|
resourceId,
|
|
347
|
-
|
|
315
|
+
requestContext,
|
|
348
316
|
memoryConfig
|
|
349
317
|
}) {
|
|
350
318
|
try {
|
|
351
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
352
|
-
|
|
319
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
320
|
+
chunkBTWIR2B7_cjs.validateBody({ threadId });
|
|
353
321
|
if (!memory) {
|
|
354
|
-
throw new
|
|
322
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
355
323
|
}
|
|
356
324
|
const thread = await memory.getThreadById({ threadId });
|
|
357
325
|
const threadExists = !!thread;
|
|
@@ -362,7 +330,7 @@ async function getWorkingMemoryHandler({
|
|
|
362
330
|
const source = config.workingMemory?.scope !== "thread" && resourceId ? "resource" : "thread";
|
|
363
331
|
return { workingMemory, source, workingMemoryTemplate, threadExists };
|
|
364
332
|
} catch (error) {
|
|
365
|
-
return
|
|
333
|
+
return chunkV5WWQN7P_cjs.handleError(error, "Error getting working memory");
|
|
366
334
|
}
|
|
367
335
|
}
|
|
368
336
|
async function updateWorkingMemoryHandler({
|
|
@@ -370,47 +338,52 @@ async function updateWorkingMemoryHandler({
|
|
|
370
338
|
agentId,
|
|
371
339
|
threadId,
|
|
372
340
|
body,
|
|
373
|
-
|
|
341
|
+
requestContext
|
|
374
342
|
}) {
|
|
375
343
|
try {
|
|
376
|
-
|
|
377
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
344
|
+
chunkBTWIR2B7_cjs.validateBody({ threadId });
|
|
345
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
378
346
|
const { resourceId, memoryConfig, workingMemory } = body;
|
|
379
347
|
if (!memory) {
|
|
380
|
-
throw new
|
|
348
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
381
349
|
}
|
|
382
350
|
const thread = await memory.getThreadById({ threadId });
|
|
383
351
|
if (!thread) {
|
|
384
|
-
throw new
|
|
352
|
+
throw new chunk64ITUOXI_cjs.HTTPException(404, { message: "Thread not found" });
|
|
385
353
|
}
|
|
386
354
|
await memory.updateWorkingMemory({ threadId, resourceId, workingMemory, memoryConfig });
|
|
387
355
|
return { success: true };
|
|
388
356
|
} catch (error) {
|
|
389
|
-
return
|
|
357
|
+
return chunkV5WWQN7P_cjs.handleError(error, "Error updating working memory");
|
|
390
358
|
}
|
|
391
359
|
}
|
|
392
360
|
async function deleteMessagesHandler({
|
|
393
361
|
mastra,
|
|
394
362
|
agentId,
|
|
395
363
|
messageIds,
|
|
396
|
-
|
|
364
|
+
requestContext
|
|
397
365
|
}) {
|
|
398
366
|
try {
|
|
399
367
|
if (messageIds === void 0 || messageIds === null) {
|
|
400
|
-
throw new
|
|
368
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "messageIds is required" });
|
|
401
369
|
}
|
|
402
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
370
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
403
371
|
if (!memory) {
|
|
404
|
-
throw new
|
|
372
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
405
373
|
}
|
|
406
|
-
|
|
407
|
-
let count = 1;
|
|
374
|
+
let normalizedIds;
|
|
408
375
|
if (Array.isArray(messageIds)) {
|
|
409
|
-
|
|
410
|
-
}
|
|
376
|
+
normalizedIds = messageIds;
|
|
377
|
+
} else if (typeof messageIds === "string") {
|
|
378
|
+
normalizedIds = [messageIds];
|
|
379
|
+
} else {
|
|
380
|
+
normalizedIds = [messageIds];
|
|
381
|
+
}
|
|
382
|
+
await memory.deleteMessages(normalizedIds);
|
|
383
|
+
const count = Array.isArray(messageIds) ? messageIds.length : 1;
|
|
411
384
|
return { success: true, message: `${count} message${count === 1 ? "" : "s"} deleted successfully` };
|
|
412
385
|
} catch (error) {
|
|
413
|
-
return
|
|
386
|
+
return chunkV5WWQN7P_cjs.handleError(error, "Error deleting messages");
|
|
414
387
|
}
|
|
415
388
|
}
|
|
416
389
|
async function searchMemoryHandler({
|
|
@@ -420,14 +393,14 @@ async function searchMemoryHandler({
|
|
|
420
393
|
resourceId,
|
|
421
394
|
threadId,
|
|
422
395
|
limit = 20,
|
|
423
|
-
|
|
396
|
+
requestContext,
|
|
424
397
|
memoryConfig
|
|
425
398
|
}) {
|
|
426
399
|
try {
|
|
427
|
-
|
|
428
|
-
const memory = await getMemoryFromContext({ mastra, agentId,
|
|
400
|
+
chunkBTWIR2B7_cjs.validateBody({ searchQuery, resourceId });
|
|
401
|
+
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
|
|
429
402
|
if (!memory) {
|
|
430
|
-
throw new
|
|
403
|
+
throw new chunk64ITUOXI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
431
404
|
}
|
|
432
405
|
const config = memory.getMergedThreadConfig(memoryConfig || {});
|
|
433
406
|
const hasSemanticRecall = !!config?.semanticRecall;
|
|
@@ -435,10 +408,10 @@ async function searchMemoryHandler({
|
|
|
435
408
|
if (threadId && !resourceScope) {
|
|
436
409
|
const thread = await memory.getThreadById({ threadId });
|
|
437
410
|
if (!thread) {
|
|
438
|
-
throw new
|
|
411
|
+
throw new chunk64ITUOXI_cjs.HTTPException(404, { message: "Thread not found" });
|
|
439
412
|
}
|
|
440
413
|
if (thread.resourceId !== resourceId) {
|
|
441
|
-
throw new
|
|
414
|
+
throw new chunk64ITUOXI_cjs.HTTPException(403, { message: "Thread does not belong to the specified resource" });
|
|
442
415
|
}
|
|
443
416
|
}
|
|
444
417
|
const searchResults = [];
|
|
@@ -455,8 +428,13 @@ async function searchMemoryHandler({
|
|
|
455
428
|
}
|
|
456
429
|
}
|
|
457
430
|
if (!threadId) {
|
|
458
|
-
const
|
|
459
|
-
|
|
431
|
+
const { threads } = await memory.listThreadsByResourceId({
|
|
432
|
+
resourceId,
|
|
433
|
+
page: 0,
|
|
434
|
+
perPage: 1,
|
|
435
|
+
orderBy: { field: "updatedAt", direction: "DESC" }
|
|
436
|
+
});
|
|
437
|
+
if (threads.length === 0) {
|
|
460
438
|
return {
|
|
461
439
|
results: [],
|
|
462
440
|
count: 0,
|
|
@@ -465,7 +443,7 @@ async function searchMemoryHandler({
|
|
|
465
443
|
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
466
444
|
};
|
|
467
445
|
}
|
|
468
|
-
threadId =
|
|
446
|
+
threadId = threads[0].id;
|
|
469
447
|
}
|
|
470
448
|
const beforeRange = typeof config.semanticRecall === `boolean` ? 2 : typeof config.semanticRecall?.messageRange === `number` ? config.semanticRecall.messageRange : config.semanticRecall?.messageRange.before || 2;
|
|
471
449
|
const afterRange = typeof config.semanticRecall === `boolean` ? 2 : typeof config.semanticRecall?.messageRange === `number` ? config.semanticRecall.messageRange : config.semanticRecall?.messageRange.after || 2;
|
|
@@ -476,19 +454,27 @@ async function searchMemoryHandler({
|
|
|
476
454
|
{ messageRange: 0, topK: 2, scope: "resource" }
|
|
477
455
|
) : { ...config.semanticRecall, messageRange: 0 };
|
|
478
456
|
}
|
|
479
|
-
const
|
|
457
|
+
const threadConfig = memory.getMergedThreadConfig(config || {});
|
|
458
|
+
if (!threadConfig.lastMessages && !threadConfig.semanticRecall) {
|
|
459
|
+
return { results: [], count: 0, query: searchQuery };
|
|
460
|
+
}
|
|
461
|
+
const result = await memory.recall({
|
|
480
462
|
threadId,
|
|
481
463
|
resourceId,
|
|
482
|
-
|
|
483
|
-
config
|
|
464
|
+
perPage: threadConfig.lastMessages,
|
|
465
|
+
threadConfig: config,
|
|
466
|
+
vectorSearchString: threadConfig.semanticRecall && searchQuery ? searchQuery : void 0
|
|
484
467
|
});
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
468
|
+
const threadIds = Array.from(
|
|
469
|
+
new Set(result.messages.map((m) => m.threadId || threadId).filter(Boolean))
|
|
470
|
+
);
|
|
471
|
+
const fetched = await Promise.all(threadIds.map((id) => memory.getThreadById({ threadId: id })));
|
|
472
|
+
const threadMap = new Map(fetched.filter(Boolean).map((t) => [t.id, t]));
|
|
473
|
+
for (const msg of result.messages) {
|
|
474
|
+
const content = getTextContent(msg);
|
|
489
475
|
const msgThreadId = msg.threadId || threadId;
|
|
490
476
|
const thread = threadMap.get(msgThreadId);
|
|
491
|
-
const threadMessages = (await memory.
|
|
477
|
+
const threadMessages = (await memory.recall({ threadId: msgThreadId })).messages;
|
|
492
478
|
const messageIndex = threadMessages.findIndex((m) => m.id === msg.id);
|
|
493
479
|
const searchResult = {
|
|
494
480
|
id: msg.id,
|
|
@@ -503,13 +489,13 @@ async function searchMemoryHandler({
|
|
|
503
489
|
before: threadMessages.slice(Math.max(0, messageIndex - beforeRange), messageIndex).map((m) => ({
|
|
504
490
|
id: m.id,
|
|
505
491
|
role: m.role,
|
|
506
|
-
content: m
|
|
492
|
+
content: getTextContent(m),
|
|
507
493
|
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
508
494
|
})),
|
|
509
495
|
after: threadMessages.slice(messageIndex + 1, messageIndex + afterRange + 1).map((m) => ({
|
|
510
496
|
id: m.id,
|
|
511
497
|
role: m.role,
|
|
512
|
-
content: m
|
|
498
|
+
content: getTextContent(m),
|
|
513
499
|
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
514
500
|
}))
|
|
515
501
|
};
|
|
@@ -525,7 +511,7 @@ async function searchMemoryHandler({
|
|
|
525
511
|
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
526
512
|
};
|
|
527
513
|
} catch (error) {
|
|
528
|
-
return
|
|
514
|
+
return chunkV5WWQN7P_cjs.handleError(error, "Error searching memory");
|
|
529
515
|
}
|
|
530
516
|
}
|
|
531
517
|
|
|
@@ -534,16 +520,15 @@ exports.deleteMessagesHandler = deleteMessagesHandler;
|
|
|
534
520
|
exports.deleteThreadHandler = deleteThreadHandler;
|
|
535
521
|
exports.getMemoryConfigHandler = getMemoryConfigHandler;
|
|
536
522
|
exports.getMemoryStatusHandler = getMemoryStatusHandler;
|
|
537
|
-
exports.
|
|
538
|
-
exports.getMessagesPaginatedHandler = getMessagesPaginatedHandler;
|
|
523
|
+
exports.getTextContent = getTextContent;
|
|
539
524
|
exports.getThreadByIdHandler = getThreadByIdHandler;
|
|
540
|
-
exports.getThreadsHandler = getThreadsHandler;
|
|
541
|
-
exports.getThreadsPaginatedHandler = getThreadsPaginatedHandler;
|
|
542
525
|
exports.getWorkingMemoryHandler = getWorkingMemoryHandler;
|
|
526
|
+
exports.listMessagesHandler = listMessagesHandler;
|
|
527
|
+
exports.listThreadsHandler = listThreadsHandler;
|
|
543
528
|
exports.memory_exports = memory_exports;
|
|
544
529
|
exports.saveMessagesHandler = saveMessagesHandler;
|
|
545
530
|
exports.searchMemoryHandler = searchMemoryHandler;
|
|
546
531
|
exports.updateThreadHandler = updateThreadHandler;
|
|
547
532
|
exports.updateWorkingMemoryHandler = updateWorkingMemoryHandler;
|
|
548
|
-
//# sourceMappingURL=chunk-
|
|
549
|
-
//# sourceMappingURL=chunk-
|
|
533
|
+
//# sourceMappingURL=chunk-U7GLIXYO.cjs.map
|
|
534
|
+
//# sourceMappingURL=chunk-U7GLIXYO.cjs.map
|