@mastra/server 0.0.0-vnextWorkflows-20250422081019 → 0.0.0-workflow-deno-20250616115451
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
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
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');
|
|
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 ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(tool.inputSchema)) : void 0,
|
|
29
|
+
outputSchema: tool.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_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 chunk64U3UDTH_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 chunkOCWPVYNI_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 ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(tool.inputSchema)) : void 0,
|
|
49
|
+
outputSchema: tool.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(tool.outputSchema)) : void 0
|
|
49
50
|
};
|
|
50
51
|
return serializedTool;
|
|
51
52
|
} catch (error) {
|
|
52
|
-
return
|
|
53
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting tool");
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
function executeToolHandler(tools$1) {
|
|
@@ -58,20 +59,20 @@ function executeToolHandler(tools$1) {
|
|
|
58
59
|
runId,
|
|
59
60
|
toolId,
|
|
60
61
|
data,
|
|
61
|
-
|
|
62
|
+
runtimeContext
|
|
62
63
|
}) => {
|
|
63
64
|
try {
|
|
64
65
|
if (!toolId) {
|
|
65
|
-
throw new
|
|
66
|
+
throw new chunkOCWPVYNI_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 chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
|
|
70
71
|
}
|
|
71
72
|
if (!tool?.execute) {
|
|
72
|
-
throw new
|
|
73
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Tool is not executable" });
|
|
73
74
|
}
|
|
74
|
-
|
|
75
|
+
chunk57CJTIPW_cjs.validateBody({ data });
|
|
75
76
|
if (tools.isVercelTool(tool)) {
|
|
76
77
|
const result2 = await tool.execute(data);
|
|
77
78
|
return result2;
|
|
@@ -80,11 +81,11 @@ function executeToolHandler(tools$1) {
|
|
|
80
81
|
context: data,
|
|
81
82
|
mastra,
|
|
82
83
|
runId,
|
|
83
|
-
|
|
84
|
+
runtimeContext
|
|
84
85
|
});
|
|
85
86
|
return result;
|
|
86
87
|
} catch (error) {
|
|
87
|
-
return
|
|
88
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error executing tool");
|
|
88
89
|
}
|
|
89
90
|
};
|
|
90
91
|
}
|
|
@@ -93,29 +94,30 @@ async function executeAgentToolHandler({
|
|
|
93
94
|
agentId,
|
|
94
95
|
toolId,
|
|
95
96
|
data,
|
|
96
|
-
|
|
97
|
+
runtimeContext
|
|
97
98
|
}) {
|
|
98
99
|
try {
|
|
99
100
|
const agent = agentId ? mastra.getAgent(agentId) : null;
|
|
100
101
|
if (!agent) {
|
|
101
|
-
throw new
|
|
102
|
+
throw new chunkOCWPVYNI_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 chunkOCWPVYNI_cjs.HTTPException(404, { message: "Tool not found" });
|
|
106
108
|
}
|
|
107
109
|
if (!tool?.execute) {
|
|
108
|
-
throw new
|
|
110
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Tool is not executable" });
|
|
109
111
|
}
|
|
110
112
|
const result = await tool.execute({
|
|
111
113
|
context: data,
|
|
112
|
-
|
|
114
|
+
runtimeContext,
|
|
113
115
|
mastra,
|
|
114
116
|
runId: agentId
|
|
115
117
|
});
|
|
116
118
|
return result;
|
|
117
119
|
} catch (error) {
|
|
118
|
-
return
|
|
120
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error executing tool");
|
|
119
121
|
}
|
|
120
122
|
}
|
|
121
123
|
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __export = (target, all) => {
|
|
3
|
-
for (var name in all)
|
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
-
};
|
|
6
|
-
|
|
7
1
|
// src/server/http-exception.ts
|
|
8
2
|
var HTTPException = class extends Error {
|
|
9
3
|
res;
|
|
@@ -37,4 +31,4 @@ var HTTPException = class extends Error {
|
|
|
37
31
|
}
|
|
38
32
|
};
|
|
39
33
|
|
|
40
|
-
export { HTTPException
|
|
34
|
+
export { HTTPException };
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { stringify, esm_default } from './chunk-TGJMNUYJ.js';
|
|
2
|
+
import { validateBody } from './chunk-H5PTF3Y4.js';
|
|
3
|
+
import { handleError } from './chunk-M5ABIP7D.js';
|
|
4
|
+
import { HTTPException } from './chunk-NYN7KFXL.js';
|
|
5
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
6
|
+
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
7
|
+
|
|
8
|
+
// src/server/handlers/agents.ts
|
|
9
|
+
var agents_exports = {};
|
|
10
|
+
__export(agents_exports, {
|
|
11
|
+
generateHandler: () => generateHandler,
|
|
12
|
+
getAgentByIdHandler: () => getAgentByIdHandler,
|
|
13
|
+
getAgentsHandler: () => getAgentsHandler,
|
|
14
|
+
getEvalsByAgentIdHandler: () => getEvalsByAgentIdHandler,
|
|
15
|
+
getLiveEvalsByAgentIdHandler: () => getLiveEvalsByAgentIdHandler,
|
|
16
|
+
streamGenerateHandler: () => streamGenerateHandler
|
|
17
|
+
});
|
|
18
|
+
async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
19
|
+
try {
|
|
20
|
+
const agents = mastra.getAgents();
|
|
21
|
+
const serializedAgentsMap = await Promise.all(
|
|
22
|
+
Object.entries(agents).map(async ([id, agent]) => {
|
|
23
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
24
|
+
const tools = await agent.getTools({ runtimeContext });
|
|
25
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
26
|
+
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
27
|
+
const _tool = tool;
|
|
28
|
+
acc[key] = {
|
|
29
|
+
..._tool,
|
|
30
|
+
inputSchema: _tool.inputSchema ? stringify(esm_default(_tool.inputSchema)) : void 0,
|
|
31
|
+
outputSchema: _tool.outputSchema ? stringify(esm_default(_tool.outputSchema)) : void 0
|
|
32
|
+
};
|
|
33
|
+
return acc;
|
|
34
|
+
}, {});
|
|
35
|
+
let serializedAgentWorkflows = {};
|
|
36
|
+
if ("getWorkflows" in agent) {
|
|
37
|
+
const logger = mastra.getLogger();
|
|
38
|
+
try {
|
|
39
|
+
const workflows = await agent.getWorkflows({ runtimeContext });
|
|
40
|
+
serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
|
|
41
|
+
return {
|
|
42
|
+
...acc,
|
|
43
|
+
[key]: {
|
|
44
|
+
name: workflow.name
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}, {});
|
|
48
|
+
} catch (error) {
|
|
49
|
+
logger.error("Error getting workflows for agent", { agentName: agent.name, error });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
id,
|
|
54
|
+
name: agent.name,
|
|
55
|
+
instructions,
|
|
56
|
+
tools: serializedAgentTools,
|
|
57
|
+
workflows: serializedAgentWorkflows,
|
|
58
|
+
provider: llm?.getProvider(),
|
|
59
|
+
modelId: llm?.getModelId(),
|
|
60
|
+
defaultGenerateOptions: agent.getDefaultGenerateOptions(),
|
|
61
|
+
defaultStreamOptions: agent.getDefaultStreamOptions()
|
|
62
|
+
};
|
|
63
|
+
})
|
|
64
|
+
);
|
|
65
|
+
const serializedAgents = serializedAgentsMap.reduce((acc, { id, ...rest }) => {
|
|
66
|
+
acc[id] = rest;
|
|
67
|
+
return acc;
|
|
68
|
+
}, {});
|
|
69
|
+
return serializedAgents;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
return handleError(error, "Error getting agents");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function getAgentByIdHandler({
|
|
75
|
+
mastra,
|
|
76
|
+
runtimeContext,
|
|
77
|
+
agentId,
|
|
78
|
+
isPlayground = false
|
|
79
|
+
}) {
|
|
80
|
+
try {
|
|
81
|
+
const agent = mastra.getAgent(agentId);
|
|
82
|
+
if (!agent) {
|
|
83
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
84
|
+
}
|
|
85
|
+
const tools = await agent.getTools({ runtimeContext });
|
|
86
|
+
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
87
|
+
const _tool = tool;
|
|
88
|
+
acc[key] = {
|
|
89
|
+
..._tool,
|
|
90
|
+
inputSchema: _tool.inputSchema ? stringify(esm_default(_tool.inputSchema)) : void 0,
|
|
91
|
+
outputSchema: _tool.outputSchema ? stringify(esm_default(_tool.outputSchema)) : void 0
|
|
92
|
+
};
|
|
93
|
+
return acc;
|
|
94
|
+
}, {});
|
|
95
|
+
let serializedAgentWorkflows = {};
|
|
96
|
+
if ("getWorkflows" in agent) {
|
|
97
|
+
const logger = mastra.getLogger();
|
|
98
|
+
try {
|
|
99
|
+
const workflows = await agent.getWorkflows({ runtimeContext });
|
|
100
|
+
serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
|
|
101
|
+
return {
|
|
102
|
+
...acc,
|
|
103
|
+
[key]: {
|
|
104
|
+
name: workflow.name,
|
|
105
|
+
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
106
|
+
return {
|
|
107
|
+
...acc2,
|
|
108
|
+
[key2]: {
|
|
109
|
+
id: step.id,
|
|
110
|
+
description: step.description
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}, {})
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}, {});
|
|
117
|
+
} catch (error) {
|
|
118
|
+
logger.error("Error getting workflows for agent", { agentName: agent.name, error });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
let proxyRuntimeContext = runtimeContext;
|
|
122
|
+
if (isPlayground) {
|
|
123
|
+
proxyRuntimeContext = new Proxy(runtimeContext, {
|
|
124
|
+
get(target, prop) {
|
|
125
|
+
if (prop === "get") {
|
|
126
|
+
return function(key) {
|
|
127
|
+
const value = target.get(key);
|
|
128
|
+
return value ?? `<${key}>`;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return Reflect.get(target, prop);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
const instructions = await agent.getInstructions({ runtimeContext: proxyRuntimeContext });
|
|
136
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
137
|
+
return {
|
|
138
|
+
name: agent.name,
|
|
139
|
+
instructions,
|
|
140
|
+
tools: serializedAgentTools,
|
|
141
|
+
workflows: serializedAgentWorkflows,
|
|
142
|
+
provider: llm?.getProvider(),
|
|
143
|
+
modelId: llm?.getModelId(),
|
|
144
|
+
defaultGenerateOptions: agent.getDefaultGenerateOptions(),
|
|
145
|
+
defaultStreamOptions: agent.getDefaultStreamOptions()
|
|
146
|
+
};
|
|
147
|
+
} catch (error) {
|
|
148
|
+
return handleError(error, "Error getting agent");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async function getEvalsByAgentIdHandler({
|
|
152
|
+
mastra,
|
|
153
|
+
runtimeContext,
|
|
154
|
+
agentId
|
|
155
|
+
}) {
|
|
156
|
+
try {
|
|
157
|
+
const agent = mastra.getAgent(agentId);
|
|
158
|
+
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
|
|
159
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
160
|
+
return {
|
|
161
|
+
id: agentId,
|
|
162
|
+
name: agent.name,
|
|
163
|
+
instructions,
|
|
164
|
+
evals
|
|
165
|
+
};
|
|
166
|
+
} catch (error) {
|
|
167
|
+
return handleError(error, "Error getting test evals");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
async function getLiveEvalsByAgentIdHandler({
|
|
171
|
+
mastra,
|
|
172
|
+
runtimeContext,
|
|
173
|
+
agentId
|
|
174
|
+
}) {
|
|
175
|
+
try {
|
|
176
|
+
const agent = mastra.getAgent(agentId);
|
|
177
|
+
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
|
|
178
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
179
|
+
return {
|
|
180
|
+
id: agentId,
|
|
181
|
+
name: agent.name,
|
|
182
|
+
instructions,
|
|
183
|
+
evals
|
|
184
|
+
};
|
|
185
|
+
} catch (error) {
|
|
186
|
+
return handleError(error, "Error getting live evals");
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async function generateHandler({
|
|
190
|
+
mastra,
|
|
191
|
+
runtimeContext,
|
|
192
|
+
agentId,
|
|
193
|
+
body
|
|
194
|
+
}) {
|
|
195
|
+
try {
|
|
196
|
+
const agent = mastra.getAgent(agentId);
|
|
197
|
+
if (!agent) {
|
|
198
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
199
|
+
}
|
|
200
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
201
|
+
const finalResourceId = resourceId ?? resourceid;
|
|
202
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
203
|
+
...Array.from(runtimeContext.entries()),
|
|
204
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
205
|
+
]);
|
|
206
|
+
validateBody({ messages });
|
|
207
|
+
const result = await agent.generate(messages, {
|
|
208
|
+
...rest,
|
|
209
|
+
// @ts-expect-error TODO fix types
|
|
210
|
+
resourceId: finalResourceId,
|
|
211
|
+
runtimeContext: finalRuntimeContext
|
|
212
|
+
});
|
|
213
|
+
return result;
|
|
214
|
+
} catch (error) {
|
|
215
|
+
return handleError(error, "Error generating from agent");
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
async function streamGenerateHandler({
|
|
219
|
+
mastra,
|
|
220
|
+
runtimeContext,
|
|
221
|
+
agentId,
|
|
222
|
+
body
|
|
223
|
+
}) {
|
|
224
|
+
try {
|
|
225
|
+
const agent = mastra.getAgent(agentId);
|
|
226
|
+
if (!agent) {
|
|
227
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
228
|
+
}
|
|
229
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
230
|
+
const finalResourceId = resourceId ?? resourceid;
|
|
231
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
232
|
+
...Array.from(runtimeContext.entries()),
|
|
233
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
234
|
+
]);
|
|
235
|
+
validateBody({ messages });
|
|
236
|
+
const streamResult = await agent.stream(messages, {
|
|
237
|
+
...rest,
|
|
238
|
+
// @ts-expect-error TODO fix types
|
|
239
|
+
resourceId: finalResourceId,
|
|
240
|
+
runtimeContext: finalRuntimeContext
|
|
241
|
+
});
|
|
242
|
+
const streamResponse = rest.output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
|
|
243
|
+
sendUsage: true,
|
|
244
|
+
sendReasoning: true,
|
|
245
|
+
getErrorMessage: (error) => {
|
|
246
|
+
return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
return streamResponse;
|
|
250
|
+
} catch (error) {
|
|
251
|
+
throw new HTTPException(error?.status ?? 500, { message: error?.message ?? "Error streaming from agent" });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export { agents_exports, generateHandler, getAgentByIdHandler, getAgentsHandler, getEvalsByAgentIdHandler, getLiveEvalsByAgentIdHandler, streamGenerateHandler };
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __export = (target, all) => {
|
|
5
|
-
for (var name in all)
|
|
6
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
7
|
-
};
|
|
8
|
-
|
|
9
3
|
// src/server/http-exception.ts
|
|
10
4
|
var HTTPException = class extends Error {
|
|
11
5
|
res;
|
|
@@ -40,4 +34,3 @@ var HTTPException = class extends Error {
|
|
|
40
34
|
};
|
|
41
35
|
|
|
42
36
|
exports.HTTPException = HTTPException;
|
|
43
|
-
exports.__export = __export;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { validateBody } from './chunk-H5PTF3Y4.js';
|
|
2
|
+
import { handleError } from './chunk-M5ABIP7D.js';
|
|
3
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
4
|
+
|
|
5
|
+
// src/server/handlers/logs.ts
|
|
6
|
+
var logs_exports = {};
|
|
7
|
+
__export(logs_exports, {
|
|
8
|
+
getLogTransports: () => getLogTransports,
|
|
9
|
+
getLogsByRunIdHandler: () => getLogsByRunIdHandler,
|
|
10
|
+
getLogsHandler: () => getLogsHandler
|
|
11
|
+
});
|
|
12
|
+
async function getLogsHandler({
|
|
13
|
+
mastra,
|
|
14
|
+
transportId,
|
|
15
|
+
params
|
|
16
|
+
}) {
|
|
17
|
+
try {
|
|
18
|
+
validateBody({ transportId });
|
|
19
|
+
const { fromDate, toDate, logLevel, filters: _filters, page, perPage } = params || {};
|
|
20
|
+
const filters = _filters ? Object.fromEntries(
|
|
21
|
+
(Array.isArray(_filters) ? _filters : [_filters]).map((attr) => {
|
|
22
|
+
const [key, value] = attr.split(":");
|
|
23
|
+
return [key, value];
|
|
24
|
+
})
|
|
25
|
+
) : void 0;
|
|
26
|
+
const logs = await mastra.getLogs(transportId, {
|
|
27
|
+
fromDate,
|
|
28
|
+
toDate,
|
|
29
|
+
logLevel,
|
|
30
|
+
filters,
|
|
31
|
+
page: page ? Number(page) : void 0,
|
|
32
|
+
perPage: perPage ? Number(perPage) : void 0
|
|
33
|
+
});
|
|
34
|
+
return logs;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
return handleError(error, "Error getting logs");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function getLogsByRunIdHandler({
|
|
40
|
+
mastra,
|
|
41
|
+
runId,
|
|
42
|
+
transportId,
|
|
43
|
+
params
|
|
44
|
+
}) {
|
|
45
|
+
try {
|
|
46
|
+
validateBody({ runId, transportId });
|
|
47
|
+
const { fromDate, toDate, logLevel, filters: _filters, page, perPage } = params || {};
|
|
48
|
+
const filters = _filters ? Object.fromEntries(
|
|
49
|
+
(Array.isArray(_filters) ? _filters : [_filters]).map((attr) => {
|
|
50
|
+
const [key, value] = attr.split(":");
|
|
51
|
+
return [key, value];
|
|
52
|
+
})
|
|
53
|
+
) : void 0;
|
|
54
|
+
const logs = await mastra.getLogsByRunId({
|
|
55
|
+
runId,
|
|
56
|
+
transportId,
|
|
57
|
+
fromDate,
|
|
58
|
+
toDate,
|
|
59
|
+
logLevel,
|
|
60
|
+
filters,
|
|
61
|
+
page: page ? Number(page) : void 0,
|
|
62
|
+
perPage: perPage ? Number(perPage) : void 0
|
|
63
|
+
});
|
|
64
|
+
return logs;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
return handleError(error, "Error getting logs by run ID");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function getLogTransports({ mastra }) {
|
|
70
|
+
try {
|
|
71
|
+
const logger = mastra.getLogger();
|
|
72
|
+
const transports = logger.getTransports();
|
|
73
|
+
return {
|
|
74
|
+
transports: transports ? [...transports.keys()] : []
|
|
75
|
+
};
|
|
76
|
+
} catch (error) {
|
|
77
|
+
return handleError(error, "Error getting log Transports");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { getLogTransports, getLogsByRunIdHandler, getLogsHandler, logs_exports };
|