@mastra/server 0.0.0-vnextWorkflows-20250422142014 → 0.0.0-workflow-deno-20250616130925
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/README.md +48 -135
- package/dist/_tsup-dts-rollup.d.cts +351 -60
- package/dist/_tsup-dts-rollup.d.ts +351 -60
- package/dist/{chunk-XISBMH56.js → chunk-2HXKRRNS.js} +11 -9
- package/dist/chunk-42IKSJNO.js +421 -0
- package/dist/chunk-42YJ2YVD.cjs +263 -0
- package/dist/{chunk-4JINXASC.js → chunk-55DOQLP6.js} +5 -4
- package/dist/{chunk-QN4KF3BH.cjs → chunk-57CJTIPW.cjs} +2 -2
- package/dist/{chunk-ZLBRQFDD.cjs → chunk-64U3UDTH.cjs} +2 -2
- package/dist/{chunk-2FJURXCL.cjs → chunk-6TJSHFCJ.cjs} +44 -36
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/chunk-ASKESBJW.cjs +2004 -0
- package/dist/{chunk-7IWQE76Z.cjs → chunk-B4MQFJ7G.cjs} +16 -10
- package/dist/{chunk-WTHDCRMY.js → chunk-BFOA2QQY.js} +12 -6
- package/dist/{chunk-M56ECCHK.cjs → chunk-BNEY4P4P.cjs} +20 -19
- package/dist/{chunk-YANVFOYA.js → chunk-C7564HUT.js} +56 -34
- package/dist/chunk-CK32I2VN.cjs +435 -0
- package/dist/{chunk-4B7OUZXW.js → chunk-CLYX4KLH.js} +78 -63
- package/dist/chunk-CMMOIUFC.cjs +114 -0
- package/dist/{chunk-3RVHWGWO.js → chunk-CP55EVBK.js} +26 -13
- package/dist/chunk-GHC4YV6R.js +504 -0
- package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
- package/dist/{chunk-RBQASTUP.js → chunk-I7KJZNX5.js} +14 -6
- package/dist/chunk-IMBY5XUG.cjs +86 -0
- package/dist/{chunk-3AHQ5RGN.js → chunk-M5ABIP7D.js} +1 -1
- package/dist/chunk-MLKGABMK.js +7 -0
- package/dist/{chunk-HABV7TZK.cjs → chunk-NGURCFEJ.cjs} +28 -26
- package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
- package/dist/chunk-O2YAAFY3.js +255 -0
- package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
- package/dist/chunk-QLG2PFHE.js +81 -0
- package/dist/chunk-SDPGVWQJ.cjs +512 -0
- package/dist/chunk-TGJMNUYJ.js +2001 -0
- package/dist/chunk-VPNDC2DI.cjs +148 -0
- package/dist/chunk-WE32JG64.cjs +332 -0
- package/dist/server/handlers/a2a.cjs +30 -0
- package/dist/server/handlers/a2a.d.cts +6 -0
- package/dist/server/handlers/a2a.d.ts +6 -0
- package/dist/server/handlers/a2a.js +1 -0
- package/dist/server/handlers/agents.cjs +7 -7
- 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/legacyWorkflows.cjs +46 -0
- package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
- package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
- package/dist/server/handlers/legacyWorkflows.js +1 -0
- package/dist/server/handlers/logs.cjs +4 -4
- package/dist/server/handlers/logs.js +1 -1
- package/dist/server/handlers/memory.cjs +9 -9
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/network.cjs +5 -5
- package/dist/server/handlers/network.js +1 -1
- package/dist/server/handlers/telemetry.cjs +3 -3
- package/dist/server/handlers/telemetry.js +1 -1
- package/dist/server/handlers/tools.cjs +5 -5
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/utils.cjs +2 -2
- 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 +8 -4
- package/dist/server/handlers/voice.d.cts +1 -0
- package/dist/server/handlers/voice.d.ts +1 -0
- package/dist/server/handlers/voice.js +1 -1
- package/dist/server/handlers/workflows.cjs +21 -13
- package/dist/server/handlers/workflows.d.cts +4 -2
- package/dist/server/handlers/workflows.d.ts +4 -2
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +33 -23
- package/dist/server/handlers.d.cts +2 -0
- package/dist/server/handlers.d.ts +2 -0
- package/dist/server/handlers.js +11 -9
- package/package.json +13 -12
- package/dist/chunk-3EJZQ6TQ.js +0 -49
- package/dist/chunk-4WJ5GHRG.cjs +0 -164
- package/dist/chunk-5SWCVTNL.cjs +0 -5579
- package/dist/chunk-A7DF4ETD.cjs +0 -100
- package/dist/chunk-JLDXUWK7.cjs +0 -126
- package/dist/chunk-OMN3UI6X.js +0 -5576
- package/dist/chunk-RNU4JMLM.cjs +0 -317
- package/dist/chunk-SKBVVI24.cjs +0 -54
- package/dist/chunk-TFFNX7FI.js +0 -156
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkASKESBJW_cjs = require('./chunk-ASKESBJW.cjs');
|
|
4
|
+
var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
|
|
5
|
+
var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
|
|
6
|
+
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
|
|
7
|
+
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
8
|
+
var runtimeContext = require('@mastra/core/runtime-context');
|
|
9
|
+
|
|
10
|
+
// src/server/handlers/agents.ts
|
|
11
|
+
var agents_exports = {};
|
|
12
|
+
chunk75ZPJI57_cjs.__export(agents_exports, {
|
|
13
|
+
generateHandler: () => generateHandler,
|
|
14
|
+
getAgentByIdHandler: () => getAgentByIdHandler,
|
|
15
|
+
getAgentsHandler: () => getAgentsHandler,
|
|
16
|
+
getEvalsByAgentIdHandler: () => getEvalsByAgentIdHandler,
|
|
17
|
+
getLiveEvalsByAgentIdHandler: () => getLiveEvalsByAgentIdHandler,
|
|
18
|
+
streamGenerateHandler: () => streamGenerateHandler
|
|
19
|
+
});
|
|
20
|
+
async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
21
|
+
try {
|
|
22
|
+
const agents = mastra.getAgents();
|
|
23
|
+
const serializedAgentsMap = await Promise.all(
|
|
24
|
+
Object.entries(agents).map(async ([id, agent]) => {
|
|
25
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
26
|
+
const tools = await agent.getTools({ runtimeContext });
|
|
27
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
28
|
+
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
29
|
+
const _tool = tool;
|
|
30
|
+
acc[key] = {
|
|
31
|
+
..._tool,
|
|
32
|
+
inputSchema: _tool.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(_tool.inputSchema)) : void 0,
|
|
33
|
+
outputSchema: _tool.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(_tool.outputSchema)) : void 0
|
|
34
|
+
};
|
|
35
|
+
return acc;
|
|
36
|
+
}, {});
|
|
37
|
+
let serializedAgentWorkflows = {};
|
|
38
|
+
if ("getWorkflows" in agent) {
|
|
39
|
+
const logger = mastra.getLogger();
|
|
40
|
+
try {
|
|
41
|
+
const workflows = await agent.getWorkflows({ runtimeContext });
|
|
42
|
+
serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
|
|
43
|
+
return {
|
|
44
|
+
...acc,
|
|
45
|
+
[key]: {
|
|
46
|
+
name: workflow.name
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}, {});
|
|
50
|
+
} catch (error) {
|
|
51
|
+
logger.error("Error getting workflows for agent", { agentName: agent.name, error });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
id,
|
|
56
|
+
name: agent.name,
|
|
57
|
+
instructions,
|
|
58
|
+
tools: serializedAgentTools,
|
|
59
|
+
workflows: serializedAgentWorkflows,
|
|
60
|
+
provider: llm?.getProvider(),
|
|
61
|
+
modelId: llm?.getModelId(),
|
|
62
|
+
defaultGenerateOptions: agent.getDefaultGenerateOptions(),
|
|
63
|
+
defaultStreamOptions: agent.getDefaultStreamOptions()
|
|
64
|
+
};
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
const serializedAgents = serializedAgentsMap.reduce((acc, { id, ...rest }) => {
|
|
68
|
+
acc[id] = rest;
|
|
69
|
+
return acc;
|
|
70
|
+
}, {});
|
|
71
|
+
return serializedAgents;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting agents");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async function getAgentByIdHandler({
|
|
77
|
+
mastra,
|
|
78
|
+
runtimeContext,
|
|
79
|
+
agentId,
|
|
80
|
+
isPlayground = false
|
|
81
|
+
}) {
|
|
82
|
+
try {
|
|
83
|
+
const agent = mastra.getAgent(agentId);
|
|
84
|
+
if (!agent) {
|
|
85
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
86
|
+
}
|
|
87
|
+
const tools = await agent.getTools({ runtimeContext });
|
|
88
|
+
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
89
|
+
const _tool = tool;
|
|
90
|
+
acc[key] = {
|
|
91
|
+
..._tool,
|
|
92
|
+
inputSchema: _tool.inputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(_tool.inputSchema)) : void 0,
|
|
93
|
+
outputSchema: _tool.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(_tool.outputSchema)) : void 0
|
|
94
|
+
};
|
|
95
|
+
return acc;
|
|
96
|
+
}, {});
|
|
97
|
+
let serializedAgentWorkflows = {};
|
|
98
|
+
if ("getWorkflows" in agent) {
|
|
99
|
+
const logger = mastra.getLogger();
|
|
100
|
+
try {
|
|
101
|
+
const workflows = await agent.getWorkflows({ runtimeContext });
|
|
102
|
+
serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
|
|
103
|
+
return {
|
|
104
|
+
...acc,
|
|
105
|
+
[key]: {
|
|
106
|
+
name: workflow.name,
|
|
107
|
+
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
108
|
+
return {
|
|
109
|
+
...acc2,
|
|
110
|
+
[key2]: {
|
|
111
|
+
id: step.id,
|
|
112
|
+
description: step.description
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}, {})
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}, {});
|
|
119
|
+
} catch (error) {
|
|
120
|
+
logger.error("Error getting workflows for agent", { agentName: agent.name, error });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
let proxyRuntimeContext = runtimeContext;
|
|
124
|
+
if (isPlayground) {
|
|
125
|
+
proxyRuntimeContext = new Proxy(runtimeContext, {
|
|
126
|
+
get(target, prop) {
|
|
127
|
+
if (prop === "get") {
|
|
128
|
+
return function(key) {
|
|
129
|
+
const value = target.get(key);
|
|
130
|
+
return value ?? `<${key}>`;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return Reflect.get(target, prop);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const instructions = await agent.getInstructions({ runtimeContext: proxyRuntimeContext });
|
|
138
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
139
|
+
return {
|
|
140
|
+
name: agent.name,
|
|
141
|
+
instructions,
|
|
142
|
+
tools: serializedAgentTools,
|
|
143
|
+
workflows: serializedAgentWorkflows,
|
|
144
|
+
provider: llm?.getProvider(),
|
|
145
|
+
modelId: llm?.getModelId(),
|
|
146
|
+
defaultGenerateOptions: agent.getDefaultGenerateOptions(),
|
|
147
|
+
defaultStreamOptions: agent.getDefaultStreamOptions()
|
|
148
|
+
};
|
|
149
|
+
} catch (error) {
|
|
150
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting agent");
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async function getEvalsByAgentIdHandler({
|
|
154
|
+
mastra,
|
|
155
|
+
runtimeContext,
|
|
156
|
+
agentId
|
|
157
|
+
}) {
|
|
158
|
+
try {
|
|
159
|
+
const agent = mastra.getAgent(agentId);
|
|
160
|
+
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
|
|
161
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
162
|
+
return {
|
|
163
|
+
id: agentId,
|
|
164
|
+
name: agent.name,
|
|
165
|
+
instructions,
|
|
166
|
+
evals
|
|
167
|
+
};
|
|
168
|
+
} catch (error) {
|
|
169
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting test evals");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async function getLiveEvalsByAgentIdHandler({
|
|
173
|
+
mastra,
|
|
174
|
+
runtimeContext,
|
|
175
|
+
agentId
|
|
176
|
+
}) {
|
|
177
|
+
try {
|
|
178
|
+
const agent = mastra.getAgent(agentId);
|
|
179
|
+
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
|
|
180
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
181
|
+
return {
|
|
182
|
+
id: agentId,
|
|
183
|
+
name: agent.name,
|
|
184
|
+
instructions,
|
|
185
|
+
evals
|
|
186
|
+
};
|
|
187
|
+
} catch (error) {
|
|
188
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting live evals");
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
async function generateHandler({
|
|
192
|
+
mastra,
|
|
193
|
+
runtimeContext: runtimeContext$1,
|
|
194
|
+
agentId,
|
|
195
|
+
body
|
|
196
|
+
}) {
|
|
197
|
+
try {
|
|
198
|
+
const agent = mastra.getAgent(agentId);
|
|
199
|
+
if (!agent) {
|
|
200
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
201
|
+
}
|
|
202
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
203
|
+
const finalResourceId = resourceId ?? resourceid;
|
|
204
|
+
const finalRuntimeContext = new runtimeContext.RuntimeContext([
|
|
205
|
+
...Array.from(runtimeContext$1.entries()),
|
|
206
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
207
|
+
]);
|
|
208
|
+
chunk57CJTIPW_cjs.validateBody({ messages });
|
|
209
|
+
const result = await agent.generate(messages, {
|
|
210
|
+
...rest,
|
|
211
|
+
// @ts-expect-error TODO fix types
|
|
212
|
+
resourceId: finalResourceId,
|
|
213
|
+
runtimeContext: finalRuntimeContext
|
|
214
|
+
});
|
|
215
|
+
return result;
|
|
216
|
+
} catch (error) {
|
|
217
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error generating from agent");
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
async function streamGenerateHandler({
|
|
221
|
+
mastra,
|
|
222
|
+
runtimeContext: runtimeContext$1,
|
|
223
|
+
agentId,
|
|
224
|
+
body
|
|
225
|
+
}) {
|
|
226
|
+
try {
|
|
227
|
+
const agent = mastra.getAgent(agentId);
|
|
228
|
+
if (!agent) {
|
|
229
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
230
|
+
}
|
|
231
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
232
|
+
const finalResourceId = resourceId ?? resourceid;
|
|
233
|
+
const finalRuntimeContext = new runtimeContext.RuntimeContext([
|
|
234
|
+
...Array.from(runtimeContext$1.entries()),
|
|
235
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
236
|
+
]);
|
|
237
|
+
chunk57CJTIPW_cjs.validateBody({ messages });
|
|
238
|
+
const streamResult = await agent.stream(messages, {
|
|
239
|
+
...rest,
|
|
240
|
+
// @ts-expect-error TODO fix types
|
|
241
|
+
resourceId: finalResourceId,
|
|
242
|
+
runtimeContext: finalRuntimeContext
|
|
243
|
+
});
|
|
244
|
+
const streamResponse = rest.output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
|
|
245
|
+
sendUsage: true,
|
|
246
|
+
sendReasoning: true,
|
|
247
|
+
getErrorMessage: (error) => {
|
|
248
|
+
return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
return streamResponse;
|
|
252
|
+
} catch (error) {
|
|
253
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(error?.status ?? 500, { message: error?.message ?? "Error streaming from agent" });
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
exports.agents_exports = agents_exports;
|
|
258
|
+
exports.generateHandler = generateHandler;
|
|
259
|
+
exports.getAgentByIdHandler = getAgentByIdHandler;
|
|
260
|
+
exports.getAgentsHandler = getAgentsHandler;
|
|
261
|
+
exports.getEvalsByAgentIdHandler = getEvalsByAgentIdHandler;
|
|
262
|
+
exports.getLiveEvalsByAgentIdHandler = getLiveEvalsByAgentIdHandler;
|
|
263
|
+
exports.streamGenerateHandler = streamGenerateHandler;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { handleError } from './chunk-
|
|
2
|
-
import {
|
|
1
|
+
import { handleError } from './chunk-M5ABIP7D.js';
|
|
2
|
+
import { HTTPException } from './chunk-NYN7KFXL.js';
|
|
3
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
3
4
|
|
|
4
5
|
// src/server/handlers/vector.ts
|
|
5
6
|
var vector_exports = {};
|
|
@@ -90,7 +91,7 @@ async function describeIndex({
|
|
|
90
91
|
throw new HTTPException(400, { message: "Index name is required" });
|
|
91
92
|
}
|
|
92
93
|
const vector = getVector(mastra, vectorName);
|
|
93
|
-
const stats = await vector.describeIndex(indexName);
|
|
94
|
+
const stats = await vector.describeIndex({ indexName });
|
|
94
95
|
return {
|
|
95
96
|
dimension: stats.dimension,
|
|
96
97
|
count: stats.count,
|
|
@@ -110,7 +111,7 @@ async function deleteIndex({
|
|
|
110
111
|
throw new HTTPException(400, { message: "Index name is required" });
|
|
111
112
|
}
|
|
112
113
|
const vector = getVector(mastra, vectorName);
|
|
113
|
-
await vector.deleteIndex(indexName);
|
|
114
|
+
await vector.deleteIndex({ indexName });
|
|
114
115
|
return { success: true };
|
|
115
116
|
} catch (error) {
|
|
116
117
|
return handleError(error, "Error deleting index");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
|
|
4
4
|
|
|
5
5
|
// src/server/handlers/utils.ts
|
|
6
6
|
function validateBody(body) {
|
|
@@ -11,7 +11,7 @@ function validateBody(body) {
|
|
|
11
11
|
return acc;
|
|
12
12
|
}, {});
|
|
13
13
|
if (Object.keys(errorResponse).length > 0) {
|
|
14
|
-
throw new
|
|
14
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: Object.values(errorResponse)[0] });
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
|
|
4
4
|
|
|
5
5
|
// src/server/handlers/error.ts
|
|
6
6
|
function handleError(error, defaultMessage) {
|
|
7
7
|
const apiError = error;
|
|
8
|
-
throw new
|
|
8
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(apiError.status || 500, {
|
|
9
9
|
message: apiError.message || defaultMessage
|
|
10
10
|
});
|
|
11
11
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
|
|
4
|
+
var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
|
|
5
|
+
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
|
|
6
|
+
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
6
7
|
|
|
7
8
|
// src/server/handlers/memory.ts
|
|
8
9
|
var memory_exports = {};
|
|
9
|
-
|
|
10
|
+
chunk75ZPJI57_cjs.__export(memory_exports, {
|
|
10
11
|
createThreadHandler: () => createThreadHandler,
|
|
11
12
|
deleteThreadHandler: () => deleteThreadHandler,
|
|
12
13
|
getMemoryStatusHandler: () => getMemoryStatusHandler,
|
|
@@ -22,7 +23,7 @@ function getMemoryFromContext({
|
|
|
22
23
|
}) {
|
|
23
24
|
const agent = agentId ? mastra.getAgent(agentId) : null;
|
|
24
25
|
if (agentId && !agent) {
|
|
25
|
-
throw new
|
|
26
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
26
27
|
}
|
|
27
28
|
const memory = agent?.getMemory?.() || mastra.getMemory();
|
|
28
29
|
return memory;
|
|
@@ -35,7 +36,7 @@ async function getMemoryStatusHandler({ mastra, agentId }) {
|
|
|
35
36
|
}
|
|
36
37
|
return { result: true };
|
|
37
38
|
} catch (error) {
|
|
38
|
-
return
|
|
39
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting memory status");
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
async function getThreadsHandler({
|
|
@@ -46,13 +47,13 @@ async function getThreadsHandler({
|
|
|
46
47
|
try {
|
|
47
48
|
const memory = getMemoryFromContext({ mastra, agentId });
|
|
48
49
|
if (!memory) {
|
|
49
|
-
throw new
|
|
50
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
50
51
|
}
|
|
51
|
-
|
|
52
|
+
chunk57CJTIPW_cjs.validateBody({ resourceId });
|
|
52
53
|
const threads = await memory.getThreadsByResourceId({ resourceId });
|
|
53
54
|
return threads;
|
|
54
55
|
} catch (error) {
|
|
55
|
-
return
|
|
56
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting threads");
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
async function getThreadByIdHandler({
|
|
@@ -61,18 +62,18 @@ async function getThreadByIdHandler({
|
|
|
61
62
|
threadId
|
|
62
63
|
}) {
|
|
63
64
|
try {
|
|
64
|
-
|
|
65
|
+
chunk57CJTIPW_cjs.validateBody({ threadId });
|
|
65
66
|
const memory = getMemoryFromContext({ mastra, agentId });
|
|
66
67
|
if (!memory) {
|
|
67
|
-
throw new
|
|
68
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
68
69
|
}
|
|
69
70
|
const thread = await memory.getThreadById({ threadId });
|
|
70
71
|
if (!thread) {
|
|
71
|
-
throw new
|
|
72
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
|
|
72
73
|
}
|
|
73
74
|
return thread;
|
|
74
75
|
} catch (error) {
|
|
75
|
-
return
|
|
76
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting thread");
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
async function saveMessagesHandler({
|
|
@@ -83,13 +84,13 @@ async function saveMessagesHandler({
|
|
|
83
84
|
try {
|
|
84
85
|
const memory = getMemoryFromContext({ mastra, agentId });
|
|
85
86
|
if (!memory) {
|
|
86
|
-
throw new
|
|
87
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
87
88
|
}
|
|
88
89
|
if (!body?.messages) {
|
|
89
|
-
throw new
|
|
90
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Messages are required" });
|
|
90
91
|
}
|
|
91
92
|
if (!Array.isArray(body.messages)) {
|
|
92
|
-
throw new
|
|
93
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Messages should be an array" });
|
|
93
94
|
}
|
|
94
95
|
const processedMessages = body.messages.map((message) => ({
|
|
95
96
|
...message,
|
|
@@ -99,7 +100,7 @@ async function saveMessagesHandler({
|
|
|
99
100
|
const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
|
|
100
101
|
return result;
|
|
101
102
|
} catch (error) {
|
|
102
|
-
return
|
|
103
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error saving messages");
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
async function createThreadHandler({
|
|
@@ -110,9 +111,9 @@ async function createThreadHandler({
|
|
|
110
111
|
try {
|
|
111
112
|
const memory = getMemoryFromContext({ mastra, agentId });
|
|
112
113
|
if (!memory) {
|
|
113
|
-
throw new
|
|
114
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
114
115
|
}
|
|
115
|
-
|
|
116
|
+
chunk57CJTIPW_cjs.validateBody({ resourceId: body?.resourceId });
|
|
116
117
|
const result = await memory.createThread({
|
|
117
118
|
resourceId: body?.resourceId,
|
|
118
119
|
title: body?.title,
|
|
@@ -121,7 +122,7 @@ async function createThreadHandler({
|
|
|
121
122
|
});
|
|
122
123
|
return result;
|
|
123
124
|
} catch (error) {
|
|
124
|
-
return
|
|
125
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error saving thread to memory");
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
async function updateThreadHandler({
|
|
@@ -133,17 +134,17 @@ async function updateThreadHandler({
|
|
|
133
134
|
try {
|
|
134
135
|
const memory = getMemoryFromContext({ mastra, agentId });
|
|
135
136
|
if (!body) {
|
|
136
|
-
throw new
|
|
137
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Body is required" });
|
|
137
138
|
}
|
|
138
139
|
const { title, metadata, resourceId } = body;
|
|
139
140
|
const updatedAt = /* @__PURE__ */ new Date();
|
|
140
|
-
|
|
141
|
+
chunk57CJTIPW_cjs.validateBody({ threadId });
|
|
141
142
|
if (!memory) {
|
|
142
|
-
throw new
|
|
143
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
143
144
|
}
|
|
144
145
|
const thread = await memory.getThreadById({ threadId });
|
|
145
146
|
if (!thread) {
|
|
146
|
-
throw new
|
|
147
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
|
|
147
148
|
}
|
|
148
149
|
const updatedThread = {
|
|
149
150
|
...thread,
|
|
@@ -156,7 +157,7 @@ async function updateThreadHandler({
|
|
|
156
157
|
const result = await memory.saveThread({ thread: updatedThread });
|
|
157
158
|
return result;
|
|
158
159
|
} catch (error) {
|
|
159
|
-
return
|
|
160
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error updating thread");
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
async function deleteThreadHandler({
|
|
@@ -165,40 +166,47 @@ async function deleteThreadHandler({
|
|
|
165
166
|
threadId
|
|
166
167
|
}) {
|
|
167
168
|
try {
|
|
168
|
-
|
|
169
|
+
chunk57CJTIPW_cjs.validateBody({ threadId });
|
|
169
170
|
const memory = getMemoryFromContext({ mastra, agentId });
|
|
170
171
|
if (!memory) {
|
|
171
|
-
throw new
|
|
172
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
172
173
|
}
|
|
173
174
|
const thread = await memory.getThreadById({ threadId });
|
|
174
175
|
if (!thread) {
|
|
175
|
-
throw new
|
|
176
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
|
|
176
177
|
}
|
|
177
178
|
await memory.deleteThread(threadId);
|
|
178
179
|
return { result: "Thread deleted" };
|
|
179
180
|
} catch (error) {
|
|
180
|
-
return
|
|
181
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error deleting thread");
|
|
181
182
|
}
|
|
182
183
|
}
|
|
183
184
|
async function getMessagesHandler({
|
|
184
185
|
mastra,
|
|
185
186
|
agentId,
|
|
186
|
-
threadId
|
|
187
|
+
threadId,
|
|
188
|
+
limit
|
|
187
189
|
}) {
|
|
190
|
+
if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
|
|
191
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Invalid limit: must be a positive integer" });
|
|
192
|
+
}
|
|
188
193
|
try {
|
|
189
|
-
|
|
194
|
+
chunk57CJTIPW_cjs.validateBody({ threadId });
|
|
190
195
|
const memory = getMemoryFromContext({ mastra, agentId });
|
|
191
196
|
if (!memory) {
|
|
192
|
-
throw new
|
|
197
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
193
198
|
}
|
|
194
199
|
const thread = await memory.getThreadById({ threadId });
|
|
195
200
|
if (!thread) {
|
|
196
|
-
throw new
|
|
201
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
|
|
197
202
|
}
|
|
198
|
-
const result = await memory.query({
|
|
199
|
-
|
|
203
|
+
const result = await memory.query({
|
|
204
|
+
threadId,
|
|
205
|
+
...limit && { selectBy: { last: limit } }
|
|
206
|
+
});
|
|
207
|
+
return { messages: result.messages, uiMessages: result.uiMessages };
|
|
200
208
|
} catch (error) {
|
|
201
|
-
return
|
|
209
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting messages");
|
|
202
210
|
}
|
|
203
211
|
}
|
|
204
212
|
|