@mastra/server 0.0.0-mcp-schema-serializer-20250430202337 → 0.0.0-mcp-changeset-20250707162621
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 +524 -100
- package/dist/_tsup-dts-rollup.d.ts +524 -100
- package/dist/{chunk-FV45V6WC.cjs → chunk-2KZFMI6P.cjs} +1 -7
- package/dist/{chunk-5YGDYMRB.cjs → chunk-2SLFAFTR.cjs} +14 -13
- package/dist/chunk-4D66QEKC.js +81 -0
- package/dist/{chunk-M3YJLWTU.js → chunk-5PQQ42EZ.js} +68 -57
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/{chunk-M56ECCHK.cjs → chunk-7TP2LX5L.cjs} +20 -19
- package/dist/chunk-B2PAS2IB.cjs +514 -0
- package/dist/{chunk-Y3SV5XK4.js → chunk-BK4XT6EG.js} +105 -16
- package/dist/{chunk-QN4KF3BH.cjs → chunk-CCGRCYWJ.cjs} +2 -2
- package/dist/{chunk-QJ3AHN64.js → chunk-CRCR3ZUK.js} +4 -3
- package/dist/{chunk-2FJURXCL.cjs → chunk-DN7K6FJK.cjs} +93 -55
- package/dist/{chunk-D3G23FP3.cjs → chunk-FRVBFMO2.cjs} +24 -22
- package/dist/{chunk-7IWQE76Z.cjs → chunk-G7KH752Y.cjs} +16 -10
- package/dist/chunk-GHC4YV6R.js +504 -0
- package/dist/chunk-H7DMHBKY.js +498 -0
- package/dist/chunk-JMLYCXMK.cjs +332 -0
- package/dist/{chunk-Q6SHQECN.js → chunk-KHZKYUNR.js} +34 -10
- package/dist/{chunk-TRDNDNGQ.js → chunk-LCM566I4.js} +2 -7
- package/dist/chunk-LF7P5PLR.js +14 -0
- package/dist/chunk-LI436ITD.cjs +2042 -0
- package/dist/{chunk-5JNVY6DU.js → chunk-LRCAAFUA.js} +7 -5
- package/dist/chunk-LZ3VJXSO.cjs +278 -0
- package/dist/chunk-MEGCYGBU.js +2039 -0
- package/dist/{chunk-RBQASTUP.js → chunk-MKLYEKEF.js} +63 -25
- package/dist/chunk-MLKGABMK.js +7 -0
- package/dist/chunk-PZQDCRPV.cjs +16 -0
- package/dist/chunk-QGX47B5D.cjs +86 -0
- package/dist/{chunk-WTHDCRMY.js → chunk-RG473F6Y.js} +12 -6
- package/dist/chunk-RHSWAXKB.cjs +118 -0
- package/dist/{chunk-L7XE5QTW.js → chunk-RSEO4XPX.js} +1 -1
- package/dist/chunk-SDPGVWQJ.cjs +512 -0
- package/dist/{chunk-4JINXASC.js → chunk-WNVFNNWN.js} +5 -4
- 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/vNextNetwork.cjs +218 -0
- package/dist/server/handlers/vNextNetwork.d.cts +6 -0
- package/dist/server/handlers/vNextNetwork.d.ts +6 -0
- package/dist/server/handlers/vNextNetwork.js +211 -0
- 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 +29 -13
- package/dist/server/handlers/workflows.d.cts +6 -2
- package/dist/server/handlers/workflows.d.ts +6 -2
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +32 -27
- package/dist/server/handlers.d.cts +2 -1
- package/dist/server/handlers.d.ts +2 -1
- package/dist/server/handlers.js +11 -10
- package/package.json +14 -13
- package/dist/chunk-3AHQ5RGN.js +0 -11
- package/dist/chunk-3EJZQ6TQ.js +0 -49
- package/dist/chunk-4BIX6GMY.cjs +0 -189
- package/dist/chunk-55HTWX4C.cjs +0 -93
- package/dist/chunk-5SWCVTNL.cjs +0 -5579
- package/dist/chunk-AELYAUEE.cjs +0 -316
- package/dist/chunk-EVCC233P.cjs +0 -321
- package/dist/chunk-JPB6RPGB.js +0 -304
- package/dist/chunk-OMN3UI6X.js +0 -5576
- package/dist/chunk-SKBVVI24.cjs +0 -54
- package/dist/chunk-ZLBRQFDD.cjs +0 -13
- package/dist/server/handlers/vNextWorkflows.cjs +0 -46
- package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
- package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
- package/dist/server/handlers/vNextWorkflows.js +0 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { stringify, esm_default } from './chunk-
|
|
2
|
-
import { validateBody } from './chunk-
|
|
3
|
-
import { handleError } from './chunk-
|
|
4
|
-
import {
|
|
1
|
+
import { stringify, esm_default } from './chunk-MEGCYGBU.js';
|
|
2
|
+
import { validateBody } from './chunk-RSEO4XPX.js';
|
|
3
|
+
import { handleError } from './chunk-LF7P5PLR.js';
|
|
4
|
+
import { HTTPException } from './chunk-LCM566I4.js';
|
|
5
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
6
|
+
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
5
7
|
|
|
6
8
|
// src/server/handlers/agents.ts
|
|
7
9
|
var agents_exports = {};
|
|
@@ -21,6 +23,8 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
|
21
23
|
const instructions = await agent.getInstructions({ runtimeContext });
|
|
22
24
|
const tools = await agent.getTools({ runtimeContext });
|
|
23
25
|
const llm = await agent.getLLM({ runtimeContext });
|
|
26
|
+
const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext });
|
|
27
|
+
const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext });
|
|
24
28
|
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
25
29
|
const _tool = tool;
|
|
26
30
|
acc[key] = {
|
|
@@ -30,13 +34,33 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
|
30
34
|
};
|
|
31
35
|
return acc;
|
|
32
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
|
+
}
|
|
33
54
|
return {
|
|
34
55
|
id,
|
|
35
56
|
name: agent.name,
|
|
36
57
|
instructions,
|
|
37
58
|
tools: serializedAgentTools,
|
|
59
|
+
workflows: serializedAgentWorkflows,
|
|
38
60
|
provider: llm?.getProvider(),
|
|
39
|
-
modelId: llm?.getModelId()
|
|
61
|
+
modelId: llm?.getModelId(),
|
|
62
|
+
defaultGenerateOptions,
|
|
63
|
+
defaultStreamOptions
|
|
40
64
|
};
|
|
41
65
|
})
|
|
42
66
|
);
|
|
@@ -52,7 +76,8 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
|
52
76
|
async function getAgentByIdHandler({
|
|
53
77
|
mastra,
|
|
54
78
|
runtimeContext,
|
|
55
|
-
agentId
|
|
79
|
+
agentId,
|
|
80
|
+
isPlayground = false
|
|
56
81
|
}) {
|
|
57
82
|
try {
|
|
58
83
|
const agent = mastra.getAgent(agentId);
|
|
@@ -69,14 +94,59 @@ async function getAgentByIdHandler({
|
|
|
69
94
|
};
|
|
70
95
|
return acc;
|
|
71
96
|
}, {});
|
|
72
|
-
|
|
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 });
|
|
73
138
|
const llm = await agent.getLLM({ runtimeContext });
|
|
139
|
+
const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext: proxyRuntimeContext });
|
|
140
|
+
const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext: proxyRuntimeContext });
|
|
74
141
|
return {
|
|
75
142
|
name: agent.name,
|
|
76
143
|
instructions,
|
|
77
144
|
tools: serializedAgentTools,
|
|
145
|
+
workflows: serializedAgentWorkflows,
|
|
78
146
|
provider: llm?.getProvider(),
|
|
79
|
-
modelId: llm?.getModelId()
|
|
147
|
+
modelId: llm?.getModelId(),
|
|
148
|
+
defaultGenerateOptions,
|
|
149
|
+
defaultStreamOptions
|
|
80
150
|
};
|
|
81
151
|
} catch (error) {
|
|
82
152
|
return handleError(error, "Error getting agent");
|
|
@@ -124,21 +194,27 @@ async function generateHandler({
|
|
|
124
194
|
mastra,
|
|
125
195
|
runtimeContext,
|
|
126
196
|
agentId,
|
|
127
|
-
body
|
|
197
|
+
body,
|
|
198
|
+
abortSignal
|
|
128
199
|
}) {
|
|
129
200
|
try {
|
|
130
201
|
const agent = mastra.getAgent(agentId);
|
|
131
202
|
if (!agent) {
|
|
132
203
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
133
204
|
}
|
|
134
|
-
const { messages, resourceId, resourceid, ...rest } = body;
|
|
205
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
135
206
|
const finalResourceId = resourceId ?? resourceid;
|
|
207
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
208
|
+
...Array.from(runtimeContext.entries()),
|
|
209
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
210
|
+
]);
|
|
136
211
|
validateBody({ messages });
|
|
137
212
|
const result = await agent.generate(messages, {
|
|
138
213
|
...rest,
|
|
139
214
|
// @ts-expect-error TODO fix types
|
|
140
215
|
resourceId: finalResourceId,
|
|
141
|
-
runtimeContext
|
|
216
|
+
runtimeContext: finalRuntimeContext,
|
|
217
|
+
signal: abortSignal
|
|
142
218
|
});
|
|
143
219
|
return result;
|
|
144
220
|
} catch (error) {
|
|
@@ -149,32 +225,45 @@ async function streamGenerateHandler({
|
|
|
149
225
|
mastra,
|
|
150
226
|
runtimeContext,
|
|
151
227
|
agentId,
|
|
152
|
-
body
|
|
228
|
+
body,
|
|
229
|
+
abortSignal
|
|
153
230
|
}) {
|
|
154
231
|
try {
|
|
155
232
|
const agent = mastra.getAgent(agentId);
|
|
156
233
|
if (!agent) {
|
|
157
234
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
158
235
|
}
|
|
159
|
-
const { messages, resourceId, resourceid, ...rest } = body;
|
|
236
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
160
237
|
const finalResourceId = resourceId ?? resourceid;
|
|
238
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
239
|
+
...Array.from(runtimeContext.entries()),
|
|
240
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
241
|
+
]);
|
|
161
242
|
validateBody({ messages });
|
|
162
243
|
const streamResult = await agent.stream(messages, {
|
|
163
244
|
...rest,
|
|
164
245
|
// @ts-expect-error TODO fix types
|
|
165
246
|
resourceId: finalResourceId,
|
|
166
|
-
runtimeContext
|
|
247
|
+
runtimeContext: finalRuntimeContext,
|
|
248
|
+
signal: abortSignal
|
|
167
249
|
});
|
|
168
|
-
const streamResponse = rest.output ? streamResult.toTextStreamResponse(
|
|
250
|
+
const streamResponse = rest.output ? streamResult.toTextStreamResponse({
|
|
251
|
+
headers: {
|
|
252
|
+
"Transfer-Encoding": "chunked"
|
|
253
|
+
}
|
|
254
|
+
}) : streamResult.toDataStreamResponse({
|
|
169
255
|
sendUsage: true,
|
|
170
256
|
sendReasoning: true,
|
|
171
257
|
getErrorMessage: (error) => {
|
|
172
258
|
return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
|
|
259
|
+
},
|
|
260
|
+
headers: {
|
|
261
|
+
"Transfer-Encoding": "chunked"
|
|
173
262
|
}
|
|
174
263
|
});
|
|
175
264
|
return streamResponse;
|
|
176
265
|
} catch (error) {
|
|
177
|
-
|
|
266
|
+
return handleError(error, "error streaming agent response");
|
|
178
267
|
}
|
|
179
268
|
}
|
|
180
269
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.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 chunk2KZFMI6P_cjs.HTTPException(400, { message: Object.values(errorResponse)[0] });
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { validateBody } from './chunk-
|
|
2
|
-
import { handleError } from './chunk-
|
|
3
|
-
import {
|
|
1
|
+
import { validateBody } from './chunk-RSEO4XPX.js';
|
|
2
|
+
import { handleError } from './chunk-LF7P5PLR.js';
|
|
3
|
+
import { HTTPException } from './chunk-LCM566I4.js';
|
|
4
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
4
5
|
|
|
5
6
|
// src/server/handlers/network.ts
|
|
6
7
|
var network_exports = {};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunkCCGRCYWJ_cjs = require('./chunk-CCGRCYWJ.cjs');
|
|
4
|
+
var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
|
|
5
|
+
var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.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,
|
|
@@ -16,80 +17,102 @@ chunkFV45V6WC_cjs.__export(memory_exports, {
|
|
|
16
17
|
saveMessagesHandler: () => saveMessagesHandler,
|
|
17
18
|
updateThreadHandler: () => updateThreadHandler
|
|
18
19
|
});
|
|
19
|
-
function getMemoryFromContext({
|
|
20
|
+
async function getMemoryFromContext({
|
|
20
21
|
mastra,
|
|
21
|
-
agentId
|
|
22
|
+
agentId,
|
|
23
|
+
networkId,
|
|
24
|
+
runtimeContext
|
|
22
25
|
}) {
|
|
23
26
|
const agent = agentId ? mastra.getAgent(agentId) : null;
|
|
24
27
|
if (agentId && !agent) {
|
|
25
|
-
throw new
|
|
28
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Agent not found" });
|
|
29
|
+
}
|
|
30
|
+
const network = networkId ? mastra.vnext_getNetwork(networkId) : null;
|
|
31
|
+
if (networkId && !network) {
|
|
32
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Network not found" });
|
|
33
|
+
}
|
|
34
|
+
if (agent) {
|
|
35
|
+
return agent?.getMemory() || mastra.getMemory();
|
|
36
|
+
}
|
|
37
|
+
if (network) {
|
|
38
|
+
return await network?.getMemory({ runtimeContext }) || mastra.getMemory();
|
|
26
39
|
}
|
|
27
|
-
|
|
28
|
-
return memory;
|
|
40
|
+
return mastra.getMemory();
|
|
29
41
|
}
|
|
30
|
-
async function getMemoryStatusHandler({
|
|
42
|
+
async function getMemoryStatusHandler({
|
|
43
|
+
mastra,
|
|
44
|
+
agentId,
|
|
45
|
+
networkId,
|
|
46
|
+
runtimeContext
|
|
47
|
+
}) {
|
|
31
48
|
try {
|
|
32
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
49
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
33
50
|
if (!memory) {
|
|
34
51
|
return { result: false };
|
|
35
52
|
}
|
|
36
53
|
return { result: true };
|
|
37
54
|
} catch (error) {
|
|
38
|
-
return
|
|
55
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error getting memory status");
|
|
39
56
|
}
|
|
40
57
|
}
|
|
41
58
|
async function getThreadsHandler({
|
|
42
59
|
mastra,
|
|
43
60
|
agentId,
|
|
44
|
-
resourceId
|
|
61
|
+
resourceId,
|
|
62
|
+
networkId,
|
|
63
|
+
runtimeContext
|
|
45
64
|
}) {
|
|
46
65
|
try {
|
|
47
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
66
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
48
67
|
if (!memory) {
|
|
49
|
-
throw new
|
|
68
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
50
69
|
}
|
|
51
|
-
|
|
70
|
+
chunkCCGRCYWJ_cjs.validateBody({ resourceId });
|
|
52
71
|
const threads = await memory.getThreadsByResourceId({ resourceId });
|
|
53
72
|
return threads;
|
|
54
73
|
} catch (error) {
|
|
55
|
-
return
|
|
74
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error getting threads");
|
|
56
75
|
}
|
|
57
76
|
}
|
|
58
77
|
async function getThreadByIdHandler({
|
|
59
78
|
mastra,
|
|
60
79
|
agentId,
|
|
61
|
-
threadId
|
|
80
|
+
threadId,
|
|
81
|
+
networkId,
|
|
82
|
+
runtimeContext
|
|
62
83
|
}) {
|
|
63
84
|
try {
|
|
64
|
-
|
|
65
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
85
|
+
chunkCCGRCYWJ_cjs.validateBody({ threadId });
|
|
86
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
66
87
|
if (!memory) {
|
|
67
|
-
throw new
|
|
88
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
68
89
|
}
|
|
69
90
|
const thread = await memory.getThreadById({ threadId });
|
|
70
91
|
if (!thread) {
|
|
71
|
-
throw new
|
|
92
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
|
|
72
93
|
}
|
|
73
94
|
return thread;
|
|
74
95
|
} catch (error) {
|
|
75
|
-
return
|
|
96
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error getting thread");
|
|
76
97
|
}
|
|
77
98
|
}
|
|
78
99
|
async function saveMessagesHandler({
|
|
79
100
|
mastra,
|
|
80
101
|
agentId,
|
|
81
|
-
body
|
|
102
|
+
body,
|
|
103
|
+
networkId,
|
|
104
|
+
runtimeContext
|
|
82
105
|
}) {
|
|
83
106
|
try {
|
|
84
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
107
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
85
108
|
if (!memory) {
|
|
86
|
-
throw new
|
|
109
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
87
110
|
}
|
|
88
111
|
if (!body?.messages) {
|
|
89
|
-
throw new
|
|
112
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Messages are required" });
|
|
90
113
|
}
|
|
91
114
|
if (!Array.isArray(body.messages)) {
|
|
92
|
-
throw new
|
|
115
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Messages should be an array" });
|
|
93
116
|
}
|
|
94
117
|
const processedMessages = body.messages.map((message) => ({
|
|
95
118
|
...message,
|
|
@@ -99,20 +122,22 @@ async function saveMessagesHandler({
|
|
|
99
122
|
const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
|
|
100
123
|
return result;
|
|
101
124
|
} catch (error) {
|
|
102
|
-
return
|
|
125
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error saving messages");
|
|
103
126
|
}
|
|
104
127
|
}
|
|
105
128
|
async function createThreadHandler({
|
|
106
129
|
mastra,
|
|
107
130
|
agentId,
|
|
108
|
-
body
|
|
131
|
+
body,
|
|
132
|
+
networkId,
|
|
133
|
+
runtimeContext
|
|
109
134
|
}) {
|
|
110
135
|
try {
|
|
111
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
136
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
112
137
|
if (!memory) {
|
|
113
|
-
throw new
|
|
138
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
114
139
|
}
|
|
115
|
-
|
|
140
|
+
chunkCCGRCYWJ_cjs.validateBody({ resourceId: body?.resourceId });
|
|
116
141
|
const result = await memory.createThread({
|
|
117
142
|
resourceId: body?.resourceId,
|
|
118
143
|
title: body?.title,
|
|
@@ -121,29 +146,31 @@ async function createThreadHandler({
|
|
|
121
146
|
});
|
|
122
147
|
return result;
|
|
123
148
|
} catch (error) {
|
|
124
|
-
return
|
|
149
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error saving thread to memory");
|
|
125
150
|
}
|
|
126
151
|
}
|
|
127
152
|
async function updateThreadHandler({
|
|
128
153
|
mastra,
|
|
129
154
|
agentId,
|
|
130
155
|
threadId,
|
|
131
|
-
body
|
|
156
|
+
body,
|
|
157
|
+
networkId,
|
|
158
|
+
runtimeContext
|
|
132
159
|
}) {
|
|
133
160
|
try {
|
|
134
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
161
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
135
162
|
if (!body) {
|
|
136
|
-
throw new
|
|
163
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Body is required" });
|
|
137
164
|
}
|
|
138
165
|
const { title, metadata, resourceId } = body;
|
|
139
166
|
const updatedAt = /* @__PURE__ */ new Date();
|
|
140
|
-
|
|
167
|
+
chunkCCGRCYWJ_cjs.validateBody({ threadId });
|
|
141
168
|
if (!memory) {
|
|
142
|
-
throw new
|
|
169
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
143
170
|
}
|
|
144
171
|
const thread = await memory.getThreadById({ threadId });
|
|
145
172
|
if (!thread) {
|
|
146
|
-
throw new
|
|
173
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
|
|
147
174
|
}
|
|
148
175
|
const updatedThread = {
|
|
149
176
|
...thread,
|
|
@@ -156,49 +183,60 @@ async function updateThreadHandler({
|
|
|
156
183
|
const result = await memory.saveThread({ thread: updatedThread });
|
|
157
184
|
return result;
|
|
158
185
|
} catch (error) {
|
|
159
|
-
return
|
|
186
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error updating thread");
|
|
160
187
|
}
|
|
161
188
|
}
|
|
162
189
|
async function deleteThreadHandler({
|
|
163
190
|
mastra,
|
|
164
191
|
agentId,
|
|
165
|
-
threadId
|
|
192
|
+
threadId,
|
|
193
|
+
networkId,
|
|
194
|
+
runtimeContext
|
|
166
195
|
}) {
|
|
167
196
|
try {
|
|
168
|
-
|
|
169
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
197
|
+
chunkCCGRCYWJ_cjs.validateBody({ threadId });
|
|
198
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
170
199
|
if (!memory) {
|
|
171
|
-
throw new
|
|
200
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
172
201
|
}
|
|
173
202
|
const thread = await memory.getThreadById({ threadId });
|
|
174
203
|
if (!thread) {
|
|
175
|
-
throw new
|
|
204
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
|
|
176
205
|
}
|
|
177
206
|
await memory.deleteThread(threadId);
|
|
178
207
|
return { result: "Thread deleted" };
|
|
179
208
|
} catch (error) {
|
|
180
|
-
return
|
|
209
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error deleting thread");
|
|
181
210
|
}
|
|
182
211
|
}
|
|
183
212
|
async function getMessagesHandler({
|
|
184
213
|
mastra,
|
|
185
214
|
agentId,
|
|
186
|
-
threadId
|
|
215
|
+
threadId,
|
|
216
|
+
limit,
|
|
217
|
+
networkId,
|
|
218
|
+
runtimeContext
|
|
187
219
|
}) {
|
|
220
|
+
if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
|
|
221
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Invalid limit: must be a positive integer" });
|
|
222
|
+
}
|
|
188
223
|
try {
|
|
189
|
-
|
|
190
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
224
|
+
chunkCCGRCYWJ_cjs.validateBody({ threadId });
|
|
225
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
191
226
|
if (!memory) {
|
|
192
|
-
throw new
|
|
227
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
193
228
|
}
|
|
194
229
|
const thread = await memory.getThreadById({ threadId });
|
|
195
230
|
if (!thread) {
|
|
196
|
-
throw new
|
|
231
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Thread not found" });
|
|
197
232
|
}
|
|
198
|
-
const result = await memory.query({
|
|
199
|
-
|
|
233
|
+
const result = await memory.query({
|
|
234
|
+
threadId,
|
|
235
|
+
...limit && { selectBy: { last: limit } }
|
|
236
|
+
});
|
|
237
|
+
return { messages: result.messages, uiMessages: result.uiMessages };
|
|
200
238
|
} catch (error) {
|
|
201
|
-
return
|
|
239
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error getting messages");
|
|
202
240
|
}
|
|
203
241
|
}
|
|
204
242
|
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
3
|
+
var chunkLI436ITD_cjs = require('./chunk-LI436ITD.cjs');
|
|
4
|
+
var chunkCCGRCYWJ_cjs = require('./chunk-CCGRCYWJ.cjs');
|
|
5
|
+
var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
|
|
6
|
+
var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
|
|
7
|
+
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
7
8
|
var tools = require('@mastra/core/tools');
|
|
8
9
|
|
|
9
10
|
// src/server/handlers/tools.ts
|
|
10
11
|
var tools_exports = {};
|
|
11
|
-
|
|
12
|
+
chunk75ZPJI57_cjs.__export(tools_exports, {
|
|
12
13
|
executeAgentToolHandler: () => executeAgentToolHandler,
|
|
13
14
|
executeToolHandler: () => executeToolHandler,
|
|
14
15
|
getToolByIdHandler: () => getToolByIdHandler,
|
|
@@ -24,8 +25,8 @@ async function getToolsHandler({ tools }) {
|
|
|
24
25
|
const tool = _tool;
|
|
25
26
|
acc[id] = {
|
|
26
27
|
...tool,
|
|
27
|
-
inputSchema: tool.inputSchema ?
|
|
28
|
-
outputSchema: tool.outputSchema ?
|
|
28
|
+
inputSchema: tool.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(tool.inputSchema)) : void 0,
|
|
29
|
+
outputSchema: tool.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(tool.outputSchema)) : void 0
|
|
29
30
|
};
|
|
30
31
|
return acc;
|
|
31
32
|
},
|
|
@@ -33,23 +34,23 @@ async function getToolsHandler({ tools }) {
|
|
|
33
34
|
);
|
|
34
35
|
return serializedTools;
|
|
35
36
|
} catch (error) {
|
|
36
|
-
return
|
|
37
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error getting tools");
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
async function getToolByIdHandler({ tools, toolId }) {
|
|
40
41
|
try {
|
|
41
42
|
const tool = Object.values(tools || {}).find((tool2) => tool2.id === toolId);
|
|
42
43
|
if (!tool) {
|
|
43
|
-
throw new
|
|
44
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Tool not found" });
|
|
44
45
|
}
|
|
45
46
|
const serializedTool = {
|
|
46
47
|
...tool,
|
|
47
|
-
inputSchema: tool.inputSchema ?
|
|
48
|
-
outputSchema: tool.outputSchema ?
|
|
48
|
+
inputSchema: tool.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(tool.inputSchema)) : void 0,
|
|
49
|
+
outputSchema: tool.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(tool.outputSchema)) : void 0
|
|
49
50
|
};
|
|
50
51
|
return serializedTool;
|
|
51
52
|
} catch (error) {
|
|
52
|
-
return
|
|
53
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error getting tool");
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
function executeToolHandler(tools$1) {
|
|
@@ -62,16 +63,16 @@ function executeToolHandler(tools$1) {
|
|
|
62
63
|
}) => {
|
|
63
64
|
try {
|
|
64
65
|
if (!toolId) {
|
|
65
|
-
throw new
|
|
66
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Tool ID is required" });
|
|
66
67
|
}
|
|
67
68
|
const tool = Object.values(tools$1 || {}).find((tool2) => tool2.id === toolId);
|
|
68
69
|
if (!tool) {
|
|
69
|
-
throw new
|
|
70
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Tool not found" });
|
|
70
71
|
}
|
|
71
72
|
if (!tool?.execute) {
|
|
72
|
-
throw new
|
|
73
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Tool is not executable" });
|
|
73
74
|
}
|
|
74
|
-
|
|
75
|
+
chunkCCGRCYWJ_cjs.validateBody({ data });
|
|
75
76
|
if (tools.isVercelTool(tool)) {
|
|
76
77
|
const result2 = await tool.execute(data);
|
|
77
78
|
return result2;
|
|
@@ -84,7 +85,7 @@ function executeToolHandler(tools$1) {
|
|
|
84
85
|
});
|
|
85
86
|
return result;
|
|
86
87
|
} catch (error) {
|
|
87
|
-
return
|
|
88
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error executing tool");
|
|
88
89
|
}
|
|
89
90
|
};
|
|
90
91
|
}
|
|
@@ -98,14 +99,15 @@ async function executeAgentToolHandler({
|
|
|
98
99
|
try {
|
|
99
100
|
const agent = agentId ? mastra.getAgent(agentId) : null;
|
|
100
101
|
if (!agent) {
|
|
101
|
-
throw new
|
|
102
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Tool not found" });
|
|
102
103
|
}
|
|
103
|
-
const
|
|
104
|
+
const agentTools = await agent.getTools({ runtimeContext });
|
|
105
|
+
const tool = Object.values(agentTools || {}).find((tool2) => tool2.id === toolId);
|
|
104
106
|
if (!tool) {
|
|
105
|
-
throw new
|
|
107
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Tool not found" });
|
|
106
108
|
}
|
|
107
109
|
if (!tool?.execute) {
|
|
108
|
-
throw new
|
|
110
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Tool is not executable" });
|
|
109
111
|
}
|
|
110
112
|
const result = await tool.execute({
|
|
111
113
|
context: data,
|
|
@@ -115,7 +117,7 @@ async function executeAgentToolHandler({
|
|
|
115
117
|
});
|
|
116
118
|
return result;
|
|
117
119
|
} catch (error) {
|
|
118
|
-
return
|
|
120
|
+
return chunkPZQDCRPV_cjs.handleError(error, "Error executing tool");
|
|
119
121
|
}
|
|
120
122
|
}
|
|
121
123
|
|