@mastra/server 0.11.0-alpha.0 → 0.11.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_tsup-dts-rollup.d.cts +155 -12
- package/dist/_tsup-dts-rollup.d.ts +155 -12
- package/dist/{chunk-H7DMHBKY.js → chunk-2SPBWAKY.js} +30 -1
- package/dist/chunk-424T5F2J.cjs +157 -0
- package/dist/chunk-6T5JUKOQ.js +149 -0
- package/dist/{chunk-KOHWJYJT.js → chunk-AHXXKSOO.js} +207 -2
- package/dist/{chunk-LZ3VJXSO.cjs → chunk-ENPKI53P.cjs} +31 -1
- package/dist/{chunk-B2PAS2IB.cjs → chunk-G7AFLCTK.cjs} +30 -0
- package/dist/{chunk-LRCAAFUA.js → chunk-RFV6JJFC.js} +1 -1
- package/dist/{chunk-3CNDE7QY.cjs → chunk-SE2BQ536.cjs} +209 -1
- package/dist/{chunk-BK4XT6EG.js → chunk-VRJ2TE5J.js} +31 -2
- package/dist/{chunk-FRVBFMO2.cjs → chunk-WDFLW64N.cjs} +4 -4
- package/dist/server/handlers/agents.cjs +11 -7
- package/dist/server/handlers/agents.d.cts +1 -0
- package/dist/server/handlers/agents.d.ts +1 -0
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/memory.cjs +23 -11
- package/dist/server/handlers/memory.d.cts +3 -0
- package/dist/server/handlers/memory.d.ts +3 -0
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/scores.cjs +30 -0
- package/dist/server/handlers/scores.d.cts +6 -0
- package/dist/server/handlers/scores.d.ts +6 -0
- package/dist/server/handlers/scores.js +1 -0
- package/dist/server/handlers/tools.cjs +5 -5
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/workflows.cjs +19 -15
- package/dist/server/handlers/workflows.d.cts +1 -0
- package/dist/server/handlers/workflows.d.ts +1 -0
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +16 -11
- package/dist/server/handlers.d.cts +3 -2
- package/dist/server/handlers.d.ts +3 -2
- package/dist/server/handlers.js +5 -4
- package/package.json +3 -2
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
|
|
4
|
+
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
5
|
+
|
|
6
|
+
// src/server/handlers/scores.ts
|
|
7
|
+
var scores_exports = {};
|
|
8
|
+
chunk75ZPJI57_cjs.__export(scores_exports, {
|
|
9
|
+
getScorerHandler: () => getScorerHandler,
|
|
10
|
+
getScorersHandler: () => getScorersHandler,
|
|
11
|
+
getScoresByEntityIdHandler: () => getScoresByEntityIdHandler,
|
|
12
|
+
getScoresByRunIdHandler: () => getScoresByRunIdHandler,
|
|
13
|
+
getScoresByScorerIdHandler: () => getScoresByScorerIdHandler,
|
|
14
|
+
saveScoreHandler: () => saveScoreHandler
|
|
15
|
+
});
|
|
16
|
+
async function getScorersFromSystem({
|
|
17
|
+
mastra,
|
|
18
|
+
runtimeContext
|
|
19
|
+
}) {
|
|
20
|
+
const agents = mastra.getAgents();
|
|
21
|
+
const workflows = mastra.getWorkflows();
|
|
22
|
+
const scorersMap = /* @__PURE__ */ new Map();
|
|
23
|
+
for (const [agentId, agent] of Object.entries(agents)) {
|
|
24
|
+
const scorers = await agent.getScorers({
|
|
25
|
+
runtimeContext
|
|
26
|
+
}) || {};
|
|
27
|
+
if (Object.keys(scorers).length > 0) {
|
|
28
|
+
for (const [scorerId, scorer] of Object.entries(scorers)) {
|
|
29
|
+
if (scorersMap.has(scorerId)) {
|
|
30
|
+
scorersMap.get(scorerId)?.agentIds.push(agentId);
|
|
31
|
+
} else {
|
|
32
|
+
scorersMap.set(scorerId, {
|
|
33
|
+
workflowIds: [],
|
|
34
|
+
...scorer,
|
|
35
|
+
agentIds: [agent.name]
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const [workflowId, workflow] of Object.entries(workflows)) {
|
|
42
|
+
const scorers = await workflow.getScorers({
|
|
43
|
+
runtimeContext
|
|
44
|
+
}) || {};
|
|
45
|
+
if (Object.keys(scorers).length > 0) {
|
|
46
|
+
for (const [scorerId, scorer] of Object.entries(scorers)) {
|
|
47
|
+
if (scorersMap.has(scorerId)) {
|
|
48
|
+
scorersMap.get(scorerId)?.workflowIds.push(workflowId);
|
|
49
|
+
} else {
|
|
50
|
+
scorersMap.set(scorerId, {
|
|
51
|
+
agentIds: [],
|
|
52
|
+
...scorer,
|
|
53
|
+
workflowIds: [workflowId]
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return Object.fromEntries(scorersMap.entries());
|
|
60
|
+
}
|
|
61
|
+
async function getScorersHandler({ mastra, runtimeContext }) {
|
|
62
|
+
const scorers = await getScorersFromSystem({
|
|
63
|
+
mastra,
|
|
64
|
+
runtimeContext
|
|
65
|
+
});
|
|
66
|
+
return scorers;
|
|
67
|
+
}
|
|
68
|
+
async function getScorerHandler({
|
|
69
|
+
mastra,
|
|
70
|
+
scorerId,
|
|
71
|
+
runtimeContext
|
|
72
|
+
}) {
|
|
73
|
+
const scorers = await getScorersFromSystem({
|
|
74
|
+
mastra,
|
|
75
|
+
runtimeContext
|
|
76
|
+
});
|
|
77
|
+
const scorer = scorers[scorerId];
|
|
78
|
+
if (!scorer) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return scorer;
|
|
82
|
+
}
|
|
83
|
+
async function getScoresByRunIdHandler({
|
|
84
|
+
mastra,
|
|
85
|
+
runId,
|
|
86
|
+
pagination
|
|
87
|
+
}) {
|
|
88
|
+
try {
|
|
89
|
+
const scores = await mastra.getStorage()?.getScoresByRunId?.({
|
|
90
|
+
runId,
|
|
91
|
+
pagination
|
|
92
|
+
}) || [];
|
|
93
|
+
return scores;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error getting scores by run id");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async function getScoresByScorerIdHandler({
|
|
99
|
+
mastra,
|
|
100
|
+
scorerId,
|
|
101
|
+
pagination,
|
|
102
|
+
entityId,
|
|
103
|
+
entityType
|
|
104
|
+
}) {
|
|
105
|
+
try {
|
|
106
|
+
const scores = await mastra.getStorage()?.getScoresByScorerId?.({
|
|
107
|
+
scorerId,
|
|
108
|
+
pagination,
|
|
109
|
+
entityId,
|
|
110
|
+
entityType
|
|
111
|
+
}) || [];
|
|
112
|
+
return scores;
|
|
113
|
+
} catch (error) {
|
|
114
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error getting scores by scorer id");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function getScoresByEntityIdHandler({
|
|
118
|
+
mastra,
|
|
119
|
+
entityId,
|
|
120
|
+
entityType,
|
|
121
|
+
pagination
|
|
122
|
+
}) {
|
|
123
|
+
try {
|
|
124
|
+
let entityIdToUse = entityId;
|
|
125
|
+
if (entityType === "AGENT") {
|
|
126
|
+
const agent = mastra.getAgentById(entityId);
|
|
127
|
+
entityIdToUse = agent.id;
|
|
128
|
+
} else if (entityType === "WORKFLOW") {
|
|
129
|
+
const workflow = mastra.getWorkflowById(entityId);
|
|
130
|
+
entityIdToUse = workflow.id;
|
|
131
|
+
}
|
|
132
|
+
const scores = await mastra.getStorage()?.getScoresByEntityId?.({
|
|
133
|
+
entityId: entityIdToUse,
|
|
134
|
+
entityType,
|
|
135
|
+
pagination
|
|
136
|
+
}) || [];
|
|
137
|
+
return scores;
|
|
138
|
+
} catch (error) {
|
|
139
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error getting scores by entity id");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async function saveScoreHandler({ mastra, score }) {
|
|
143
|
+
try {
|
|
144
|
+
const scores = await mastra.getStorage()?.saveScore?.(score) || [];
|
|
145
|
+
return scores;
|
|
146
|
+
} catch (error) {
|
|
147
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error saving score");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
exports.getScorerHandler = getScorerHandler;
|
|
152
|
+
exports.getScorersHandler = getScorersHandler;
|
|
153
|
+
exports.getScoresByEntityIdHandler = getScoresByEntityIdHandler;
|
|
154
|
+
exports.getScoresByRunIdHandler = getScoresByRunIdHandler;
|
|
155
|
+
exports.getScoresByScorerIdHandler = getScoresByScorerIdHandler;
|
|
156
|
+
exports.saveScoreHandler = saveScoreHandler;
|
|
157
|
+
exports.scores_exports = scores_exports;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { handleError } from './chunk-LF7P5PLR.js';
|
|
2
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
3
|
+
|
|
4
|
+
// src/server/handlers/scores.ts
|
|
5
|
+
var scores_exports = {};
|
|
6
|
+
__export(scores_exports, {
|
|
7
|
+
getScorerHandler: () => getScorerHandler,
|
|
8
|
+
getScorersHandler: () => getScorersHandler,
|
|
9
|
+
getScoresByEntityIdHandler: () => getScoresByEntityIdHandler,
|
|
10
|
+
getScoresByRunIdHandler: () => getScoresByRunIdHandler,
|
|
11
|
+
getScoresByScorerIdHandler: () => getScoresByScorerIdHandler,
|
|
12
|
+
saveScoreHandler: () => saveScoreHandler
|
|
13
|
+
});
|
|
14
|
+
async function getScorersFromSystem({
|
|
15
|
+
mastra,
|
|
16
|
+
runtimeContext
|
|
17
|
+
}) {
|
|
18
|
+
const agents = mastra.getAgents();
|
|
19
|
+
const workflows = mastra.getWorkflows();
|
|
20
|
+
const scorersMap = /* @__PURE__ */ new Map();
|
|
21
|
+
for (const [agentId, agent] of Object.entries(agents)) {
|
|
22
|
+
const scorers = await agent.getScorers({
|
|
23
|
+
runtimeContext
|
|
24
|
+
}) || {};
|
|
25
|
+
if (Object.keys(scorers).length > 0) {
|
|
26
|
+
for (const [scorerId, scorer] of Object.entries(scorers)) {
|
|
27
|
+
if (scorersMap.has(scorerId)) {
|
|
28
|
+
scorersMap.get(scorerId)?.agentIds.push(agentId);
|
|
29
|
+
} else {
|
|
30
|
+
scorersMap.set(scorerId, {
|
|
31
|
+
workflowIds: [],
|
|
32
|
+
...scorer,
|
|
33
|
+
agentIds: [agent.name]
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const [workflowId, workflow] of Object.entries(workflows)) {
|
|
40
|
+
const scorers = await workflow.getScorers({
|
|
41
|
+
runtimeContext
|
|
42
|
+
}) || {};
|
|
43
|
+
if (Object.keys(scorers).length > 0) {
|
|
44
|
+
for (const [scorerId, scorer] of Object.entries(scorers)) {
|
|
45
|
+
if (scorersMap.has(scorerId)) {
|
|
46
|
+
scorersMap.get(scorerId)?.workflowIds.push(workflowId);
|
|
47
|
+
} else {
|
|
48
|
+
scorersMap.set(scorerId, {
|
|
49
|
+
agentIds: [],
|
|
50
|
+
...scorer,
|
|
51
|
+
workflowIds: [workflowId]
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return Object.fromEntries(scorersMap.entries());
|
|
58
|
+
}
|
|
59
|
+
async function getScorersHandler({ mastra, runtimeContext }) {
|
|
60
|
+
const scorers = await getScorersFromSystem({
|
|
61
|
+
mastra,
|
|
62
|
+
runtimeContext
|
|
63
|
+
});
|
|
64
|
+
return scorers;
|
|
65
|
+
}
|
|
66
|
+
async function getScorerHandler({
|
|
67
|
+
mastra,
|
|
68
|
+
scorerId,
|
|
69
|
+
runtimeContext
|
|
70
|
+
}) {
|
|
71
|
+
const scorers = await getScorersFromSystem({
|
|
72
|
+
mastra,
|
|
73
|
+
runtimeContext
|
|
74
|
+
});
|
|
75
|
+
const scorer = scorers[scorerId];
|
|
76
|
+
if (!scorer) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return scorer;
|
|
80
|
+
}
|
|
81
|
+
async function getScoresByRunIdHandler({
|
|
82
|
+
mastra,
|
|
83
|
+
runId,
|
|
84
|
+
pagination
|
|
85
|
+
}) {
|
|
86
|
+
try {
|
|
87
|
+
const scores = await mastra.getStorage()?.getScoresByRunId?.({
|
|
88
|
+
runId,
|
|
89
|
+
pagination
|
|
90
|
+
}) || [];
|
|
91
|
+
return scores;
|
|
92
|
+
} catch (error) {
|
|
93
|
+
return handleError(error, "Error getting scores by run id");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async function getScoresByScorerIdHandler({
|
|
97
|
+
mastra,
|
|
98
|
+
scorerId,
|
|
99
|
+
pagination,
|
|
100
|
+
entityId,
|
|
101
|
+
entityType
|
|
102
|
+
}) {
|
|
103
|
+
try {
|
|
104
|
+
const scores = await mastra.getStorage()?.getScoresByScorerId?.({
|
|
105
|
+
scorerId,
|
|
106
|
+
pagination,
|
|
107
|
+
entityId,
|
|
108
|
+
entityType
|
|
109
|
+
}) || [];
|
|
110
|
+
return scores;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
return handleError(error, "Error getting scores by scorer id");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async function getScoresByEntityIdHandler({
|
|
116
|
+
mastra,
|
|
117
|
+
entityId,
|
|
118
|
+
entityType,
|
|
119
|
+
pagination
|
|
120
|
+
}) {
|
|
121
|
+
try {
|
|
122
|
+
let entityIdToUse = entityId;
|
|
123
|
+
if (entityType === "AGENT") {
|
|
124
|
+
const agent = mastra.getAgentById(entityId);
|
|
125
|
+
entityIdToUse = agent.id;
|
|
126
|
+
} else if (entityType === "WORKFLOW") {
|
|
127
|
+
const workflow = mastra.getWorkflowById(entityId);
|
|
128
|
+
entityIdToUse = workflow.id;
|
|
129
|
+
}
|
|
130
|
+
const scores = await mastra.getStorage()?.getScoresByEntityId?.({
|
|
131
|
+
entityId: entityIdToUse,
|
|
132
|
+
entityType,
|
|
133
|
+
pagination
|
|
134
|
+
}) || [];
|
|
135
|
+
return scores;
|
|
136
|
+
} catch (error) {
|
|
137
|
+
return handleError(error, "Error getting scores by entity id");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async function saveScoreHandler({ mastra, score }) {
|
|
141
|
+
try {
|
|
142
|
+
const scores = await mastra.getStorage()?.saveScore?.(score) || [];
|
|
143
|
+
return scores;
|
|
144
|
+
} catch (error) {
|
|
145
|
+
return handleError(error, "Error saving score");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export { getScorerHandler, getScorersHandler, getScoresByEntityIdHandler, getScoresByRunIdHandler, getScoresByScorerIdHandler, saveScoreHandler, scores_exports };
|
|
@@ -9,12 +9,15 @@ var memory_exports = {};
|
|
|
9
9
|
__export(memory_exports, {
|
|
10
10
|
createThreadHandler: () => createThreadHandler,
|
|
11
11
|
deleteThreadHandler: () => deleteThreadHandler,
|
|
12
|
+
getMemoryConfigHandler: () => getMemoryConfigHandler,
|
|
12
13
|
getMemoryStatusHandler: () => getMemoryStatusHandler,
|
|
13
14
|
getMessagesHandler: () => getMessagesHandler,
|
|
15
|
+
getMessagesPaginatedHandler: () => getMessagesPaginatedHandler,
|
|
14
16
|
getThreadByIdHandler: () => getThreadByIdHandler,
|
|
15
17
|
getThreadsHandler: () => getThreadsHandler,
|
|
16
18
|
getWorkingMemoryHandler: () => getWorkingMemoryHandler,
|
|
17
19
|
saveMessagesHandler: () => saveMessagesHandler,
|
|
20
|
+
searchMemoryHandler: () => searchMemoryHandler,
|
|
18
21
|
updateThreadHandler: () => updateThreadHandler,
|
|
19
22
|
updateWorkingMemoryHandler: () => updateWorkingMemoryHandler
|
|
20
23
|
});
|
|
@@ -33,7 +36,7 @@ async function getMemoryFromContext({
|
|
|
33
36
|
throw new HTTPException(404, { message: "Network not found" });
|
|
34
37
|
}
|
|
35
38
|
if (agent) {
|
|
36
|
-
return agent?.getMemory() || mastra.getMemory();
|
|
39
|
+
return await agent?.getMemory() || mastra.getMemory();
|
|
37
40
|
}
|
|
38
41
|
if (network) {
|
|
39
42
|
return await network?.getMemory({ runtimeContext }) || mastra.getMemory();
|
|
@@ -56,6 +59,23 @@ async function getMemoryStatusHandler({
|
|
|
56
59
|
return handleError(error, "Error getting memory status");
|
|
57
60
|
}
|
|
58
61
|
}
|
|
62
|
+
async function getMemoryConfigHandler({
|
|
63
|
+
mastra,
|
|
64
|
+
agentId,
|
|
65
|
+
networkId,
|
|
66
|
+
runtimeContext
|
|
67
|
+
}) {
|
|
68
|
+
try {
|
|
69
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
70
|
+
if (!memory) {
|
|
71
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
72
|
+
}
|
|
73
|
+
const config = memory.getMergedThreadConfig({});
|
|
74
|
+
return { config };
|
|
75
|
+
} catch (error) {
|
|
76
|
+
return handleError(error, "Error getting memory configuration");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
59
79
|
async function getThreadsHandler({
|
|
60
80
|
mastra,
|
|
61
81
|
agentId,
|
|
@@ -210,6 +230,29 @@ async function deleteThreadHandler({
|
|
|
210
230
|
return handleError(error, "Error deleting thread");
|
|
211
231
|
}
|
|
212
232
|
}
|
|
233
|
+
async function getMessagesPaginatedHandler({
|
|
234
|
+
mastra,
|
|
235
|
+
threadId,
|
|
236
|
+
resourceId,
|
|
237
|
+
selectBy,
|
|
238
|
+
format
|
|
239
|
+
}) {
|
|
240
|
+
try {
|
|
241
|
+
validateBody({ threadId });
|
|
242
|
+
const storage = mastra.getStorage();
|
|
243
|
+
if (!storage) {
|
|
244
|
+
throw new HTTPException(400, { message: "Storage is not initialized" });
|
|
245
|
+
}
|
|
246
|
+
const thread = await storage.getThreadById({ threadId });
|
|
247
|
+
if (!thread) {
|
|
248
|
+
throw new HTTPException(404, { message: "Thread not found" });
|
|
249
|
+
}
|
|
250
|
+
const result = await storage.getMessagesPaginated({ threadId, resourceId, selectBy, format });
|
|
251
|
+
return result;
|
|
252
|
+
} catch (error) {
|
|
253
|
+
return handleError(error, "Error getting messages");
|
|
254
|
+
}
|
|
255
|
+
}
|
|
213
256
|
async function getMessagesHandler({
|
|
214
257
|
mastra,
|
|
215
258
|
agentId,
|
|
@@ -292,5 +335,167 @@ async function updateWorkingMemoryHandler({
|
|
|
292
335
|
return handleError(error, "Error updating working memory");
|
|
293
336
|
}
|
|
294
337
|
}
|
|
338
|
+
async function searchMemoryHandler({
|
|
339
|
+
mastra,
|
|
340
|
+
agentId,
|
|
341
|
+
searchQuery,
|
|
342
|
+
resourceId,
|
|
343
|
+
threadId,
|
|
344
|
+
limit = 20,
|
|
345
|
+
networkId,
|
|
346
|
+
runtimeContext,
|
|
347
|
+
memoryConfig
|
|
348
|
+
}) {
|
|
349
|
+
try {
|
|
350
|
+
validateBody({ searchQuery, resourceId });
|
|
351
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
352
|
+
if (!memory) {
|
|
353
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
354
|
+
}
|
|
355
|
+
const config = memory.getMergedThreadConfig(memoryConfig || {});
|
|
356
|
+
const hasSemanticRecall = !!config?.semanticRecall;
|
|
357
|
+
const resourceScope = typeof config?.semanticRecall === "object" && config?.semanticRecall?.scope === "resource";
|
|
358
|
+
if (threadId && !resourceScope) {
|
|
359
|
+
const thread = await memory.getThreadById({ threadId });
|
|
360
|
+
if (!thread) {
|
|
361
|
+
throw new HTTPException(404, { message: "Thread not found" });
|
|
362
|
+
}
|
|
363
|
+
if (thread.resourceId !== resourceId) {
|
|
364
|
+
throw new HTTPException(403, { message: "Thread does not belong to the specified resource" });
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
const searchResults = [];
|
|
368
|
+
const messageMap = /* @__PURE__ */ new Map();
|
|
369
|
+
if (threadId && !resourceScope) {
|
|
370
|
+
const thread = await memory.getThreadById({ threadId });
|
|
371
|
+
if (!thread) {
|
|
372
|
+
return {
|
|
373
|
+
results: [],
|
|
374
|
+
count: 0,
|
|
375
|
+
query: searchQuery,
|
|
376
|
+
searchScope: "thread",
|
|
377
|
+
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (!threadId || resourceScope) {
|
|
382
|
+
const threads = await memory.getThreadsByResourceId({ resourceId });
|
|
383
|
+
if (threads.length === 0) {
|
|
384
|
+
return {
|
|
385
|
+
results: [],
|
|
386
|
+
count: 0,
|
|
387
|
+
query: searchQuery,
|
|
388
|
+
searchScope: "resource",
|
|
389
|
+
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
for (const thread of threads) {
|
|
393
|
+
const result = await memory.rememberMessages({
|
|
394
|
+
threadId: thread.id,
|
|
395
|
+
resourceId,
|
|
396
|
+
vectorMessageSearch: searchQuery,
|
|
397
|
+
config
|
|
398
|
+
});
|
|
399
|
+
const threadMessages = (await memory.query({ threadId: thread.id })).uiMessages;
|
|
400
|
+
result.messagesV2.forEach((msg) => {
|
|
401
|
+
if (messageMap.has(msg.id)) return;
|
|
402
|
+
messageMap.set(msg.id, true);
|
|
403
|
+
const content = msg.content.content || msg.content.parts?.map((p) => p.type === "text" ? p.text : "").join(" ") || "";
|
|
404
|
+
if (!hasSemanticRecall && !content.toLowerCase().includes(searchQuery.toLowerCase())) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
const messageIndex = threadMessages.findIndex((m) => m.id === msg.id);
|
|
408
|
+
const searchResult = {
|
|
409
|
+
id: msg.id,
|
|
410
|
+
role: msg.role,
|
|
411
|
+
content,
|
|
412
|
+
createdAt: msg.createdAt,
|
|
413
|
+
threadId: msg.threadId || thread.id,
|
|
414
|
+
threadTitle: thread.title || msg.threadId || thread.id
|
|
415
|
+
};
|
|
416
|
+
if (messageIndex !== -1) {
|
|
417
|
+
searchResult.context = {
|
|
418
|
+
before: threadMessages.slice(Math.max(0, messageIndex - 2), messageIndex).map((m) => ({
|
|
419
|
+
id: m.id,
|
|
420
|
+
role: m.role,
|
|
421
|
+
content: m.content,
|
|
422
|
+
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
423
|
+
})),
|
|
424
|
+
after: threadMessages.slice(messageIndex + 1, messageIndex + 3).map((m) => ({
|
|
425
|
+
id: m.id,
|
|
426
|
+
role: m.role,
|
|
427
|
+
content: m.content,
|
|
428
|
+
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
429
|
+
}))
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
searchResults.push(searchResult);
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
} else if (threadId) {
|
|
436
|
+
const thread = await memory.getThreadById({ threadId });
|
|
437
|
+
if (!thread) {
|
|
438
|
+
return {
|
|
439
|
+
results: [],
|
|
440
|
+
count: 0,
|
|
441
|
+
query: searchQuery,
|
|
442
|
+
searchScope: "thread",
|
|
443
|
+
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
const result = await memory.rememberMessages({
|
|
447
|
+
threadId,
|
|
448
|
+
resourceId,
|
|
449
|
+
vectorMessageSearch: searchQuery,
|
|
450
|
+
config
|
|
451
|
+
});
|
|
452
|
+
const threadMessages = (await memory.query({ threadId })).uiMessages;
|
|
453
|
+
result.messagesV2.forEach((msg) => {
|
|
454
|
+
if (messageMap.has(msg.id)) return;
|
|
455
|
+
messageMap.set(msg.id, true);
|
|
456
|
+
const content = msg.content.content || msg.content.parts?.map((p) => p.type === "text" ? p.text : "").join(" ") || "";
|
|
457
|
+
if (!hasSemanticRecall && !content.toLowerCase().includes(searchQuery.toLowerCase())) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
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,
|
|
467
|
+
threadTitle: thread?.title || threadId
|
|
468
|
+
};
|
|
469
|
+
if (messageIndex !== -1) {
|
|
470
|
+
searchResult.context = {
|
|
471
|
+
before: threadMessages.slice(Math.max(0, messageIndex - 2), 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 + 3).map((m) => ({
|
|
478
|
+
id: m.id,
|
|
479
|
+
role: m.role,
|
|
480
|
+
content: m.content,
|
|
481
|
+
createdAt: m.createdAt || /* @__PURE__ */ new Date()
|
|
482
|
+
}))
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
searchResults.push(searchResult);
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
const sortedResults = searchResults.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()).slice(0, limit);
|
|
489
|
+
return {
|
|
490
|
+
results: sortedResults,
|
|
491
|
+
count: sortedResults.length,
|
|
492
|
+
query: searchQuery,
|
|
493
|
+
searchScope: resourceScope ? "resource" : "thread",
|
|
494
|
+
searchType: hasSemanticRecall ? "semantic" : "text"
|
|
495
|
+
};
|
|
496
|
+
} catch (error) {
|
|
497
|
+
return handleError(error, "Error searching memory");
|
|
498
|
+
}
|
|
499
|
+
}
|
|
295
500
|
|
|
296
|
-
export { createThreadHandler, deleteThreadHandler, getMemoryStatusHandler, getMessagesHandler, getThreadByIdHandler, getThreadsHandler, getWorkingMemoryHandler, memory_exports, saveMessagesHandler, updateThreadHandler, updateWorkingMemoryHandler };
|
|
501
|
+
export { createThreadHandler, deleteThreadHandler, getMemoryConfigHandler, getMemoryStatusHandler, getMessagesHandler, getMessagesPaginatedHandler, getThreadByIdHandler, getThreadsHandler, getWorkingMemoryHandler, memory_exports, saveMessagesHandler, searchMemoryHandler, updateThreadHandler, updateWorkingMemoryHandler };
|
|
@@ -15,7 +15,8 @@ chunk75ZPJI57_cjs.__export(agents_exports, {
|
|
|
15
15
|
getAgentsHandler: () => getAgentsHandler,
|
|
16
16
|
getEvalsByAgentIdHandler: () => getEvalsByAgentIdHandler,
|
|
17
17
|
getLiveEvalsByAgentIdHandler: () => getLiveEvalsByAgentIdHandler,
|
|
18
|
-
streamGenerateHandler: () => streamGenerateHandler
|
|
18
|
+
streamGenerateHandler: () => streamGenerateHandler,
|
|
19
|
+
streamVNextGenerateHandler: () => streamVNextGenerateHandler
|
|
19
20
|
});
|
|
20
21
|
async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
21
22
|
try {
|
|
@@ -268,6 +269,34 @@ async function streamGenerateHandler({
|
|
|
268
269
|
return chunkPZQDCRPV_cjs.handleError(error, "error streaming agent response");
|
|
269
270
|
}
|
|
270
271
|
}
|
|
272
|
+
function streamVNextGenerateHandler({
|
|
273
|
+
mastra,
|
|
274
|
+
runtimeContext: runtimeContext$1,
|
|
275
|
+
agentId,
|
|
276
|
+
body,
|
|
277
|
+
abortSignal
|
|
278
|
+
}) {
|
|
279
|
+
try {
|
|
280
|
+
const agent = mastra.getAgent(agentId);
|
|
281
|
+
if (!agent) {
|
|
282
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Agent not found" });
|
|
283
|
+
}
|
|
284
|
+
const { messages, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
285
|
+
const finalRuntimeContext = new runtimeContext.RuntimeContext([
|
|
286
|
+
...Array.from(runtimeContext$1.entries()),
|
|
287
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
288
|
+
]);
|
|
289
|
+
chunkCCGRCYWJ_cjs.validateBody({ messages });
|
|
290
|
+
const streamResult = agent.streamVNext(messages, {
|
|
291
|
+
...rest,
|
|
292
|
+
runtimeContext: finalRuntimeContext,
|
|
293
|
+
abortSignal
|
|
294
|
+
});
|
|
295
|
+
return streamResult;
|
|
296
|
+
} catch (error) {
|
|
297
|
+
return chunkPZQDCRPV_cjs.handleError(error, "error streaming agent response");
|
|
298
|
+
}
|
|
299
|
+
}
|
|
271
300
|
|
|
272
301
|
exports.agents_exports = agents_exports;
|
|
273
302
|
exports.generateHandler = generateHandler;
|
|
@@ -276,3 +305,4 @@ exports.getAgentsHandler = getAgentsHandler;
|
|
|
276
305
|
exports.getEvalsByAgentIdHandler = getEvalsByAgentIdHandler;
|
|
277
306
|
exports.getLiveEvalsByAgentIdHandler = getLiveEvalsByAgentIdHandler;
|
|
278
307
|
exports.streamGenerateHandler = streamGenerateHandler;
|
|
308
|
+
exports.streamVNextGenerateHandler = streamVNextGenerateHandler;
|
|
@@ -21,6 +21,7 @@ chunk75ZPJI57_cjs.__export(workflows_exports, {
|
|
|
21
21
|
sendWorkflowRunEventHandler: () => sendWorkflowRunEventHandler,
|
|
22
22
|
startAsyncWorkflowHandler: () => startAsyncWorkflowHandler,
|
|
23
23
|
startWorkflowRunHandler: () => startWorkflowRunHandler,
|
|
24
|
+
streamVNextWorkflowHandler: () => streamVNextWorkflowHandler,
|
|
24
25
|
streamWorkflowHandler: () => streamWorkflowHandler,
|
|
25
26
|
watchWorkflowHandler: () => watchWorkflowHandler
|
|
26
27
|
});
|
|
@@ -342,6 +343,34 @@ async function streamWorkflowHandler({
|
|
|
342
343
|
return chunkPZQDCRPV_cjs.handleError(error, "Error executing workflow");
|
|
343
344
|
}
|
|
344
345
|
}
|
|
346
|
+
async function streamVNextWorkflowHandler({
|
|
347
|
+
mastra,
|
|
348
|
+
runtimeContext,
|
|
349
|
+
workflowId,
|
|
350
|
+
runId,
|
|
351
|
+
inputData
|
|
352
|
+
}) {
|
|
353
|
+
try {
|
|
354
|
+
if (!workflowId) {
|
|
355
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
356
|
+
}
|
|
357
|
+
if (!runId) {
|
|
358
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "runId required to stream workflow" });
|
|
359
|
+
}
|
|
360
|
+
const { workflow } = await getWorkflowsFromSystem({ mastra, workflowId });
|
|
361
|
+
if (!workflow) {
|
|
362
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
363
|
+
}
|
|
364
|
+
const run = await workflow.createRunAsync({ runId });
|
|
365
|
+
const result = run.streamVNext({
|
|
366
|
+
inputData,
|
|
367
|
+
runtimeContext
|
|
368
|
+
});
|
|
369
|
+
return result;
|
|
370
|
+
} catch (error) {
|
|
371
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error streaming workflow");
|
|
372
|
+
}
|
|
373
|
+
}
|
|
345
374
|
async function resumeAsyncWorkflowHandler({
|
|
346
375
|
mastra,
|
|
347
376
|
workflowId,
|
|
@@ -509,6 +538,7 @@ exports.resumeWorkflowHandler = resumeWorkflowHandler;
|
|
|
509
538
|
exports.sendWorkflowRunEventHandler = sendWorkflowRunEventHandler;
|
|
510
539
|
exports.startAsyncWorkflowHandler = startAsyncWorkflowHandler;
|
|
511
540
|
exports.startWorkflowRunHandler = startWorkflowRunHandler;
|
|
541
|
+
exports.streamVNextWorkflowHandler = streamVNextWorkflowHandler;
|
|
512
542
|
exports.streamWorkflowHandler = streamWorkflowHandler;
|
|
513
543
|
exports.watchWorkflowHandler = watchWorkflowHandler;
|
|
514
544
|
exports.workflows_exports = workflows_exports;
|
|
@@ -3,7 +3,7 @@ import { validateBody } from './chunk-RSEO4XPX.js';
|
|
|
3
3
|
import { handleError } from './chunk-LF7P5PLR.js';
|
|
4
4
|
import { HTTPException } from './chunk-LCM566I4.js';
|
|
5
5
|
import { __export } from './chunk-MLKGABMK.js';
|
|
6
|
-
import { isVercelTool } from '@mastra/core/tools';
|
|
6
|
+
import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
|
|
7
7
|
|
|
8
8
|
// src/server/handlers/tools.ts
|
|
9
9
|
var tools_exports = {};
|