@mastra/server 0.0.0-pg-pool-options-20250428183821 → 0.0.0-redis-cloud-transporter-20250508191651
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 +35 -13
- package/dist/_tsup-dts-rollup.d.ts +35 -13
- package/dist/{chunk-LFOBHRFO.js → chunk-3XTEV33Q.js} +16 -4
- package/dist/{chunk-FPIWDH5Y.cjs → chunk-5YGDYMRB.cjs} +48 -27
- package/dist/{chunk-HCOPJZ4A.cjs → chunk-6Q7UXAYJ.cjs} +67 -33
- package/dist/{chunk-7IWQE76Z.cjs → chunk-AMVOS7YB.cjs} +4 -2
- package/dist/{chunk-WTHDCRMY.js → chunk-BPL2CBLV.js} +4 -2
- package/dist/{chunk-TZK63M5N.cjs → chunk-CHFORQ7J.cjs} +16 -4
- package/dist/{chunk-R4J7XQYU.js → chunk-GVBJ5I2S.js} +65 -31
- package/dist/{chunk-YN63BKGG.cjs → chunk-M2RXDCPV.cjs} +28 -16
- package/dist/{chunk-L5JIIJGO.js → chunk-OWNA6I2H.js} +28 -16
- package/dist/{chunk-RE6YL32K.js → chunk-QJ3AHN64.js} +48 -27
- package/dist/server/handlers/agents.cjs +7 -7
- package/dist/server/handlers/agents.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/vNextWorkflows.cjs +12 -12
- package/dist/server/handlers/vNextWorkflows.d.cts +1 -1
- package/dist/server/handlers/vNextWorkflows.d.ts +1 -1
- package/dist/server/handlers/vNextWorkflows.js +1 -1
- package/dist/server/handlers/workflows.cjs +11 -11
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +10 -10
- package/dist/server/handlers.js +5 -5
- package/package.json +6 -6
|
@@ -4,6 +4,7 @@ var chunk5SWCVTNL_cjs = require('./chunk-5SWCVTNL.cjs');
|
|
|
4
4
|
var chunkQN4KF3BH_cjs = require('./chunk-QN4KF3BH.cjs');
|
|
5
5
|
var chunkZLBRQFDD_cjs = require('./chunk-ZLBRQFDD.cjs');
|
|
6
6
|
var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
|
|
7
|
+
var runtimeContext = require('@mastra/core/runtime-context');
|
|
7
8
|
|
|
8
9
|
// src/server/handlers/agents.ts
|
|
9
10
|
var agents_exports = {};
|
|
@@ -15,27 +16,35 @@ chunkFV45V6WC_cjs.__export(agents_exports, {
|
|
|
15
16
|
getLiveEvalsByAgentIdHandler: () => getLiveEvalsByAgentIdHandler,
|
|
16
17
|
streamGenerateHandler: () => streamGenerateHandler
|
|
17
18
|
});
|
|
18
|
-
async function getAgentsHandler({ mastra }) {
|
|
19
|
+
async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
19
20
|
try {
|
|
20
21
|
const agents = mastra.getAgents();
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
const serializedAgentsMap = await Promise.all(
|
|
23
|
+
Object.entries(agents).map(async ([id, agent]) => {
|
|
24
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
25
|
+
const tools = await agent.getTools({ runtimeContext });
|
|
26
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
27
|
+
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
28
|
+
const _tool = tool;
|
|
29
|
+
acc[key] = {
|
|
30
|
+
..._tool,
|
|
31
|
+
inputSchema: _tool.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_tool.inputSchema)) : void 0,
|
|
32
|
+
outputSchema: _tool.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_tool.outputSchema)) : void 0
|
|
33
|
+
};
|
|
34
|
+
return acc;
|
|
35
|
+
}, {});
|
|
36
|
+
return {
|
|
37
|
+
id,
|
|
38
|
+
name: agent.name,
|
|
39
|
+
instructions,
|
|
40
|
+
tools: serializedAgentTools,
|
|
41
|
+
provider: llm?.getProvider(),
|
|
42
|
+
modelId: llm?.getModelId()
|
|
29
43
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
instructions: agent.instructions,
|
|
35
|
-
tools: serializedAgentTools,
|
|
36
|
-
provider: agent.llm?.getProvider(),
|
|
37
|
-
modelId: agent.llm?.getModelId()
|
|
38
|
-
};
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
const serializedAgents = serializedAgentsMap.reduce((acc, { id, ...rest }) => {
|
|
47
|
+
acc[id] = rest;
|
|
39
48
|
return acc;
|
|
40
49
|
}, {});
|
|
41
50
|
return serializedAgents;
|
|
@@ -43,13 +52,18 @@ async function getAgentsHandler({ mastra }) {
|
|
|
43
52
|
return chunkZLBRQFDD_cjs.handleError(error, "Error getting agents");
|
|
44
53
|
}
|
|
45
54
|
}
|
|
46
|
-
async function getAgentByIdHandler({
|
|
55
|
+
async function getAgentByIdHandler({
|
|
56
|
+
mastra,
|
|
57
|
+
runtimeContext,
|
|
58
|
+
agentId
|
|
59
|
+
}) {
|
|
47
60
|
try {
|
|
48
61
|
const agent = mastra.getAgent(agentId);
|
|
49
62
|
if (!agent) {
|
|
50
63
|
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Agent not found" });
|
|
51
64
|
}
|
|
52
|
-
const
|
|
65
|
+
const tools = await agent.getTools({ runtimeContext });
|
|
66
|
+
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
53
67
|
const _tool = tool;
|
|
54
68
|
acc[key] = {
|
|
55
69
|
..._tool,
|
|
@@ -58,39 +72,51 @@ async function getAgentByIdHandler({ mastra, agentId }) {
|
|
|
58
72
|
};
|
|
59
73
|
return acc;
|
|
60
74
|
}, {});
|
|
75
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
76
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
61
77
|
return {
|
|
62
78
|
name: agent.name,
|
|
63
|
-
instructions
|
|
79
|
+
instructions,
|
|
64
80
|
tools: serializedAgentTools,
|
|
65
|
-
provider:
|
|
66
|
-
modelId:
|
|
81
|
+
provider: llm?.getProvider(),
|
|
82
|
+
modelId: llm?.getModelId()
|
|
67
83
|
};
|
|
68
84
|
} catch (error) {
|
|
69
85
|
return chunkZLBRQFDD_cjs.handleError(error, "Error getting agent");
|
|
70
86
|
}
|
|
71
87
|
}
|
|
72
|
-
async function getEvalsByAgentIdHandler({
|
|
88
|
+
async function getEvalsByAgentIdHandler({
|
|
89
|
+
mastra,
|
|
90
|
+
runtimeContext,
|
|
91
|
+
agentId
|
|
92
|
+
}) {
|
|
73
93
|
try {
|
|
74
94
|
const agent = mastra.getAgent(agentId);
|
|
75
95
|
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
|
|
96
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
76
97
|
return {
|
|
77
98
|
id: agentId,
|
|
78
99
|
name: agent.name,
|
|
79
|
-
instructions
|
|
100
|
+
instructions,
|
|
80
101
|
evals
|
|
81
102
|
};
|
|
82
103
|
} catch (error) {
|
|
83
104
|
return chunkZLBRQFDD_cjs.handleError(error, "Error getting test evals");
|
|
84
105
|
}
|
|
85
106
|
}
|
|
86
|
-
async function getLiveEvalsByAgentIdHandler({
|
|
107
|
+
async function getLiveEvalsByAgentIdHandler({
|
|
108
|
+
mastra,
|
|
109
|
+
runtimeContext,
|
|
110
|
+
agentId
|
|
111
|
+
}) {
|
|
87
112
|
try {
|
|
88
113
|
const agent = mastra.getAgent(agentId);
|
|
89
114
|
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
|
|
115
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
90
116
|
return {
|
|
91
117
|
id: agentId,
|
|
92
118
|
name: agent.name,
|
|
93
|
-
instructions
|
|
119
|
+
instructions,
|
|
94
120
|
evals
|
|
95
121
|
};
|
|
96
122
|
} catch (error) {
|
|
@@ -99,7 +125,7 @@ async function getLiveEvalsByAgentIdHandler({ mastra, agentId }) {
|
|
|
99
125
|
}
|
|
100
126
|
async function generateHandler({
|
|
101
127
|
mastra,
|
|
102
|
-
runtimeContext,
|
|
128
|
+
runtimeContext: runtimeContext$1,
|
|
103
129
|
agentId,
|
|
104
130
|
body
|
|
105
131
|
}) {
|
|
@@ -108,14 +134,18 @@ async function generateHandler({
|
|
|
108
134
|
if (!agent) {
|
|
109
135
|
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Agent not found" });
|
|
110
136
|
}
|
|
111
|
-
const { messages, resourceId, resourceid, ...rest } = body;
|
|
137
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
112
138
|
const finalResourceId = resourceId ?? resourceid;
|
|
139
|
+
const finalRuntimeContext = new runtimeContext.RuntimeContext([
|
|
140
|
+
...Array.from(runtimeContext$1.entries()),
|
|
141
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
142
|
+
]);
|
|
113
143
|
chunkQN4KF3BH_cjs.validateBody({ messages });
|
|
114
144
|
const result = await agent.generate(messages, {
|
|
115
145
|
...rest,
|
|
116
146
|
// @ts-expect-error TODO fix types
|
|
117
147
|
resourceId: finalResourceId,
|
|
118
|
-
runtimeContext
|
|
148
|
+
runtimeContext: finalRuntimeContext
|
|
119
149
|
});
|
|
120
150
|
return result;
|
|
121
151
|
} catch (error) {
|
|
@@ -124,7 +154,7 @@ async function generateHandler({
|
|
|
124
154
|
}
|
|
125
155
|
async function streamGenerateHandler({
|
|
126
156
|
mastra,
|
|
127
|
-
runtimeContext,
|
|
157
|
+
runtimeContext: runtimeContext$1,
|
|
128
158
|
agentId,
|
|
129
159
|
body
|
|
130
160
|
}) {
|
|
@@ -133,14 +163,18 @@ async function streamGenerateHandler({
|
|
|
133
163
|
if (!agent) {
|
|
134
164
|
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Agent not found" });
|
|
135
165
|
}
|
|
136
|
-
const { messages, resourceId, resourceid, ...rest } = body;
|
|
166
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
137
167
|
const finalResourceId = resourceId ?? resourceid;
|
|
168
|
+
const finalRuntimeContext = new runtimeContext.RuntimeContext([
|
|
169
|
+
...Array.from(runtimeContext$1.entries()),
|
|
170
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
171
|
+
]);
|
|
138
172
|
chunkQN4KF3BH_cjs.validateBody({ messages });
|
|
139
173
|
const streamResult = await agent.stream(messages, {
|
|
140
174
|
...rest,
|
|
141
175
|
// @ts-expect-error TODO fix types
|
|
142
176
|
resourceId: finalResourceId,
|
|
143
|
-
runtimeContext
|
|
177
|
+
runtimeContext: finalRuntimeContext
|
|
144
178
|
});
|
|
145
179
|
const streamResponse = rest.output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
|
|
146
180
|
sendUsage: true,
|
|
@@ -22,7 +22,7 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
22
22
|
if (!body) {
|
|
23
23
|
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Body is required" });
|
|
24
24
|
}
|
|
25
|
-
const { name, scope, page, perPage, attribute } = body;
|
|
25
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = body;
|
|
26
26
|
const attributes = attribute ? Object.fromEntries(
|
|
27
27
|
(Array.isArray(attribute) ? attribute : [attribute]).map((attr) => {
|
|
28
28
|
const [key, value] = attr.split(":");
|
|
@@ -34,7 +34,9 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
34
34
|
scope,
|
|
35
35
|
page: Number(page ?? 0),
|
|
36
36
|
perPage: Number(perPage ?? 100),
|
|
37
|
-
attributes
|
|
37
|
+
attributes,
|
|
38
|
+
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
39
|
+
toDate: toDate ? new Date(toDate) : void 0
|
|
38
40
|
});
|
|
39
41
|
return traces;
|
|
40
42
|
} catch (error2) {
|
|
@@ -20,7 +20,7 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
20
20
|
if (!body) {
|
|
21
21
|
throw new HTTPException(400, { message: "Body is required" });
|
|
22
22
|
}
|
|
23
|
-
const { name, scope, page, perPage, attribute } = body;
|
|
23
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = body;
|
|
24
24
|
const attributes = attribute ? Object.fromEntries(
|
|
25
25
|
(Array.isArray(attribute) ? attribute : [attribute]).map((attr) => {
|
|
26
26
|
const [key, value] = attr.split(":");
|
|
@@ -32,7 +32,9 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
32
32
|
scope,
|
|
33
33
|
page: Number(page ?? 0),
|
|
34
34
|
perPage: Number(perPage ?? 100),
|
|
35
|
-
attributes
|
|
35
|
+
attributes,
|
|
36
|
+
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
37
|
+
toDate: toDate ? new Date(toDate) : void 0
|
|
36
38
|
});
|
|
37
39
|
return traces;
|
|
38
40
|
} catch (error2) {
|
|
@@ -34,7 +34,9 @@ async function getWorkflowsHandler({ mastra }) {
|
|
|
34
34
|
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
35
35
|
const _step = step;
|
|
36
36
|
acc2[key2] = {
|
|
37
|
-
|
|
37
|
+
id: _step.id,
|
|
38
|
+
description: _step.description,
|
|
39
|
+
workflowId: _step.workflowId,
|
|
38
40
|
inputSchema: _step.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_step.inputSchema)) : void 0,
|
|
39
41
|
outputSchema: _step.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_step.outputSchema)) : void 0
|
|
40
42
|
};
|
|
@@ -67,7 +69,9 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
|
67
69
|
steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
|
|
68
70
|
const _step = step;
|
|
69
71
|
acc[key] = {
|
|
70
|
-
|
|
72
|
+
id: _step.id,
|
|
73
|
+
description: _step.description,
|
|
74
|
+
workflowId: _step.workflowId,
|
|
71
75
|
inputSchema: _step.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_step.inputSchema)) : void 0,
|
|
72
76
|
outputSchema: _step.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(_step.outputSchema)) : void 0
|
|
73
77
|
};
|
|
@@ -288,13 +292,21 @@ async function resumeWorkflowHandler({
|
|
|
288
292
|
return chunkZLBRQFDD_cjs.handleError(error, "Error resuming workflow");
|
|
289
293
|
}
|
|
290
294
|
}
|
|
291
|
-
async function getWorkflowRunsHandler({
|
|
295
|
+
async function getWorkflowRunsHandler({
|
|
296
|
+
mastra,
|
|
297
|
+
workflowId,
|
|
298
|
+
fromDate,
|
|
299
|
+
toDate,
|
|
300
|
+
limit,
|
|
301
|
+
offset,
|
|
302
|
+
resourceId
|
|
303
|
+
}) {
|
|
292
304
|
try {
|
|
293
305
|
if (!workflowId) {
|
|
294
306
|
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
295
307
|
}
|
|
296
308
|
const workflow = mastra.getWorkflow(workflowId);
|
|
297
|
-
const workflowRuns = await workflow.getWorkflowRuns() || {
|
|
309
|
+
const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
|
|
298
310
|
runs: [],
|
|
299
311
|
total: 0
|
|
300
312
|
};
|
|
@@ -2,6 +2,7 @@ import { stringify, esm_default } from './chunk-OMN3UI6X.js';
|
|
|
2
2
|
import { validateBody } from './chunk-L7XE5QTW.js';
|
|
3
3
|
import { handleError } from './chunk-3AHQ5RGN.js';
|
|
4
4
|
import { __export, HTTPException } from './chunk-TRDNDNGQ.js';
|
|
5
|
+
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
5
6
|
|
|
6
7
|
// src/server/handlers/agents.ts
|
|
7
8
|
var agents_exports = {};
|
|
@@ -13,27 +14,35 @@ __export(agents_exports, {
|
|
|
13
14
|
getLiveEvalsByAgentIdHandler: () => getLiveEvalsByAgentIdHandler,
|
|
14
15
|
streamGenerateHandler: () => streamGenerateHandler
|
|
15
16
|
});
|
|
16
|
-
async function getAgentsHandler({ mastra }) {
|
|
17
|
+
async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
17
18
|
try {
|
|
18
19
|
const agents = mastra.getAgents();
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
const serializedAgentsMap = await Promise.all(
|
|
21
|
+
Object.entries(agents).map(async ([id, agent]) => {
|
|
22
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
23
|
+
const tools = await agent.getTools({ runtimeContext });
|
|
24
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
25
|
+
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
26
|
+
const _tool = tool;
|
|
27
|
+
acc[key] = {
|
|
28
|
+
..._tool,
|
|
29
|
+
inputSchema: _tool.inputSchema ? stringify(esm_default(_tool.inputSchema)) : void 0,
|
|
30
|
+
outputSchema: _tool.outputSchema ? stringify(esm_default(_tool.outputSchema)) : void 0
|
|
31
|
+
};
|
|
32
|
+
return acc;
|
|
33
|
+
}, {});
|
|
34
|
+
return {
|
|
35
|
+
id,
|
|
36
|
+
name: agent.name,
|
|
37
|
+
instructions,
|
|
38
|
+
tools: serializedAgentTools,
|
|
39
|
+
provider: llm?.getProvider(),
|
|
40
|
+
modelId: llm?.getModelId()
|
|
27
41
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
instructions: agent.instructions,
|
|
33
|
-
tools: serializedAgentTools,
|
|
34
|
-
provider: agent.llm?.getProvider(),
|
|
35
|
-
modelId: agent.llm?.getModelId()
|
|
36
|
-
};
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
const serializedAgents = serializedAgentsMap.reduce((acc, { id, ...rest }) => {
|
|
45
|
+
acc[id] = rest;
|
|
37
46
|
return acc;
|
|
38
47
|
}, {});
|
|
39
48
|
return serializedAgents;
|
|
@@ -41,13 +50,18 @@ async function getAgentsHandler({ mastra }) {
|
|
|
41
50
|
return handleError(error, "Error getting agents");
|
|
42
51
|
}
|
|
43
52
|
}
|
|
44
|
-
async function getAgentByIdHandler({
|
|
53
|
+
async function getAgentByIdHandler({
|
|
54
|
+
mastra,
|
|
55
|
+
runtimeContext,
|
|
56
|
+
agentId
|
|
57
|
+
}) {
|
|
45
58
|
try {
|
|
46
59
|
const agent = mastra.getAgent(agentId);
|
|
47
60
|
if (!agent) {
|
|
48
61
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
49
62
|
}
|
|
50
|
-
const
|
|
63
|
+
const tools = await agent.getTools({ runtimeContext });
|
|
64
|
+
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
51
65
|
const _tool = tool;
|
|
52
66
|
acc[key] = {
|
|
53
67
|
..._tool,
|
|
@@ -56,39 +70,51 @@ async function getAgentByIdHandler({ mastra, agentId }) {
|
|
|
56
70
|
};
|
|
57
71
|
return acc;
|
|
58
72
|
}, {});
|
|
73
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
74
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
59
75
|
return {
|
|
60
76
|
name: agent.name,
|
|
61
|
-
instructions
|
|
77
|
+
instructions,
|
|
62
78
|
tools: serializedAgentTools,
|
|
63
|
-
provider:
|
|
64
|
-
modelId:
|
|
79
|
+
provider: llm?.getProvider(),
|
|
80
|
+
modelId: llm?.getModelId()
|
|
65
81
|
};
|
|
66
82
|
} catch (error) {
|
|
67
83
|
return handleError(error, "Error getting agent");
|
|
68
84
|
}
|
|
69
85
|
}
|
|
70
|
-
async function getEvalsByAgentIdHandler({
|
|
86
|
+
async function getEvalsByAgentIdHandler({
|
|
87
|
+
mastra,
|
|
88
|
+
runtimeContext,
|
|
89
|
+
agentId
|
|
90
|
+
}) {
|
|
71
91
|
try {
|
|
72
92
|
const agent = mastra.getAgent(agentId);
|
|
73
93
|
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
|
|
94
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
74
95
|
return {
|
|
75
96
|
id: agentId,
|
|
76
97
|
name: agent.name,
|
|
77
|
-
instructions
|
|
98
|
+
instructions,
|
|
78
99
|
evals
|
|
79
100
|
};
|
|
80
101
|
} catch (error) {
|
|
81
102
|
return handleError(error, "Error getting test evals");
|
|
82
103
|
}
|
|
83
104
|
}
|
|
84
|
-
async function getLiveEvalsByAgentIdHandler({
|
|
105
|
+
async function getLiveEvalsByAgentIdHandler({
|
|
106
|
+
mastra,
|
|
107
|
+
runtimeContext,
|
|
108
|
+
agentId
|
|
109
|
+
}) {
|
|
85
110
|
try {
|
|
86
111
|
const agent = mastra.getAgent(agentId);
|
|
87
112
|
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
|
|
113
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
88
114
|
return {
|
|
89
115
|
id: agentId,
|
|
90
116
|
name: agent.name,
|
|
91
|
-
instructions
|
|
117
|
+
instructions,
|
|
92
118
|
evals
|
|
93
119
|
};
|
|
94
120
|
} catch (error) {
|
|
@@ -106,14 +132,18 @@ async function generateHandler({
|
|
|
106
132
|
if (!agent) {
|
|
107
133
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
108
134
|
}
|
|
109
|
-
const { messages, resourceId, resourceid, ...rest } = body;
|
|
135
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
110
136
|
const finalResourceId = resourceId ?? resourceid;
|
|
137
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
138
|
+
...Array.from(runtimeContext.entries()),
|
|
139
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
140
|
+
]);
|
|
111
141
|
validateBody({ messages });
|
|
112
142
|
const result = await agent.generate(messages, {
|
|
113
143
|
...rest,
|
|
114
144
|
// @ts-expect-error TODO fix types
|
|
115
145
|
resourceId: finalResourceId,
|
|
116
|
-
runtimeContext
|
|
146
|
+
runtimeContext: finalRuntimeContext
|
|
117
147
|
});
|
|
118
148
|
return result;
|
|
119
149
|
} catch (error) {
|
|
@@ -131,14 +161,18 @@ async function streamGenerateHandler({
|
|
|
131
161
|
if (!agent) {
|
|
132
162
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
133
163
|
}
|
|
134
|
-
const { messages, resourceId, resourceid, ...rest } = body;
|
|
164
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
135
165
|
const finalResourceId = resourceId ?? resourceid;
|
|
166
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
167
|
+
...Array.from(runtimeContext.entries()),
|
|
168
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
169
|
+
]);
|
|
136
170
|
validateBody({ messages });
|
|
137
171
|
const streamResult = await agent.stream(messages, {
|
|
138
172
|
...rest,
|
|
139
173
|
// @ts-expect-error TODO fix types
|
|
140
174
|
resourceId: finalResourceId,
|
|
141
|
-
runtimeContext
|
|
175
|
+
runtimeContext: finalRuntimeContext
|
|
142
176
|
});
|
|
143
177
|
const streamResponse = rest.output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
|
|
144
178
|
sendUsage: true,
|
|
@@ -10,7 +10,7 @@ var vNextWorkflows_exports = {};
|
|
|
10
10
|
chunkFV45V6WC_cjs.__export(vNextWorkflows_exports, {
|
|
11
11
|
createVNextWorkflowRunHandler: () => createVNextWorkflowRunHandler,
|
|
12
12
|
getVNextWorkflowByIdHandler: () => getVNextWorkflowByIdHandler,
|
|
13
|
-
|
|
13
|
+
getVNextWorkflowRunByIdHandler: () => getVNextWorkflowRunByIdHandler,
|
|
14
14
|
getVNextWorkflowRunsHandler: () => getVNextWorkflowRunsHandler,
|
|
15
15
|
getVNextWorkflowsHandler: () => getVNextWorkflowsHandler,
|
|
16
16
|
resumeAsyncVNextWorkflowHandler: () => resumeAsyncVNextWorkflowHandler,
|
|
@@ -27,14 +27,16 @@ async function getVNextWorkflowsHandler({ mastra }) {
|
|
|
27
27
|
name: workflow.name,
|
|
28
28
|
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
29
29
|
acc2[key2] = {
|
|
30
|
-
|
|
30
|
+
id: step.id,
|
|
31
|
+
description: step.description,
|
|
31
32
|
inputSchema: step.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(step.inputSchema)) : void 0,
|
|
32
33
|
outputSchema: step.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(step.outputSchema)) : void 0,
|
|
33
|
-
resumeSchema: step.resumeSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(step.resumeSchema)) : void 0
|
|
34
|
+
resumeSchema: step.resumeSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(step.resumeSchema)) : void 0,
|
|
35
|
+
suspendSchema: step.suspendSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(step.suspendSchema)) : void 0
|
|
34
36
|
};
|
|
35
37
|
return acc2;
|
|
36
38
|
}, {}),
|
|
37
|
-
stepGraph: workflow.
|
|
39
|
+
stepGraph: workflow.serializedStepGraph,
|
|
38
40
|
inputSchema: workflow.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(workflow.inputSchema)) : void 0,
|
|
39
41
|
outputSchema: workflow.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(workflow.outputSchema)) : void 0
|
|
40
42
|
};
|
|
@@ -57,15 +59,17 @@ async function getVNextWorkflowByIdHandler({ mastra, workflowId }) {
|
|
|
57
59
|
return {
|
|
58
60
|
steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
|
|
59
61
|
acc[key] = {
|
|
60
|
-
|
|
62
|
+
id: step.id,
|
|
63
|
+
description: step.description,
|
|
61
64
|
inputSchema: step.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(step.inputSchema)) : void 0,
|
|
62
65
|
outputSchema: step.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(step.outputSchema)) : void 0,
|
|
63
|
-
resumeSchema: step.resumeSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(step.resumeSchema)) : void 0
|
|
66
|
+
resumeSchema: step.resumeSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(step.resumeSchema)) : void 0,
|
|
67
|
+
suspendSchema: step.suspendSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(step.suspendSchema)) : void 0
|
|
64
68
|
};
|
|
65
69
|
return acc;
|
|
66
70
|
}, {}),
|
|
67
71
|
name: workflow.name,
|
|
68
|
-
stepGraph: workflow.
|
|
72
|
+
stepGraph: workflow.serializedStepGraph,
|
|
69
73
|
inputSchema: workflow.inputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(workflow.inputSchema)) : void 0,
|
|
70
74
|
outputSchema: workflow.outputSchema ? chunk5SWCVTNL_cjs.stringify(chunk5SWCVTNL_cjs.esm_default(workflow.outputSchema)) : void 0
|
|
71
75
|
};
|
|
@@ -73,7 +77,7 @@ async function getVNextWorkflowByIdHandler({ mastra, workflowId }) {
|
|
|
73
77
|
throw new chunkFV45V6WC_cjs.HTTPException(500, { message: error?.message || "Error getting workflow" });
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
|
-
async function
|
|
80
|
+
async function getVNextWorkflowRunByIdHandler({
|
|
77
81
|
mastra,
|
|
78
82
|
workflowId,
|
|
79
83
|
runId
|
|
@@ -89,7 +93,7 @@ async function getVNextWorkflowRunHandler({
|
|
|
89
93
|
if (!workflow) {
|
|
90
94
|
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
91
95
|
}
|
|
92
|
-
const run = await workflow.
|
|
96
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
93
97
|
if (!run) {
|
|
94
98
|
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
95
99
|
}
|
|
@@ -157,7 +161,7 @@ async function startVNextWorkflowRunHandler({
|
|
|
157
161
|
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "runId required to start run" });
|
|
158
162
|
}
|
|
159
163
|
const workflow = mastra.vnext_getWorkflow(workflowId);
|
|
160
|
-
const run = await workflow.
|
|
164
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
161
165
|
if (!run) {
|
|
162
166
|
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
163
167
|
}
|
|
@@ -184,7 +188,7 @@ async function watchVNextWorkflowHandler({
|
|
|
184
188
|
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "runId required to watch workflow" });
|
|
185
189
|
}
|
|
186
190
|
const workflow = mastra.vnext_getWorkflow(workflowId);
|
|
187
|
-
const run = await workflow.
|
|
191
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
188
192
|
if (!run) {
|
|
189
193
|
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
190
194
|
}
|
|
@@ -235,7 +239,7 @@ async function resumeAsyncVNextWorkflowHandler({
|
|
|
235
239
|
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "step required to resume workflow" });
|
|
236
240
|
}
|
|
237
241
|
const workflow = mastra.vnext_getWorkflow(workflowId);
|
|
238
|
-
const run = await workflow.
|
|
242
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
239
243
|
if (!run) {
|
|
240
244
|
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
241
245
|
}
|
|
@@ -268,7 +272,7 @@ async function resumeVNextWorkflowHandler({
|
|
|
268
272
|
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "step required to resume workflow" });
|
|
269
273
|
}
|
|
270
274
|
const workflow = mastra.vnext_getWorkflow(workflowId);
|
|
271
|
-
const run = await workflow.
|
|
275
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
272
276
|
if (!run) {
|
|
273
277
|
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
274
278
|
}
|
|
@@ -283,13 +287,21 @@ async function resumeVNextWorkflowHandler({
|
|
|
283
287
|
return chunkZLBRQFDD_cjs.handleError(error, "Error resuming workflow");
|
|
284
288
|
}
|
|
285
289
|
}
|
|
286
|
-
async function getVNextWorkflowRunsHandler({
|
|
290
|
+
async function getVNextWorkflowRunsHandler({
|
|
291
|
+
mastra,
|
|
292
|
+
workflowId,
|
|
293
|
+
fromDate,
|
|
294
|
+
toDate,
|
|
295
|
+
limit,
|
|
296
|
+
offset,
|
|
297
|
+
resourceId
|
|
298
|
+
}) {
|
|
287
299
|
try {
|
|
288
300
|
if (!workflowId) {
|
|
289
301
|
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
290
302
|
}
|
|
291
303
|
const workflow = mastra.vnext_getWorkflow(workflowId);
|
|
292
|
-
const workflowRuns = await workflow.getWorkflowRuns() || {
|
|
304
|
+
const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
|
|
293
305
|
runs: [],
|
|
294
306
|
total: 0
|
|
295
307
|
};
|
|
@@ -301,7 +313,7 @@ async function getVNextWorkflowRunsHandler({ mastra, workflowId }) {
|
|
|
301
313
|
|
|
302
314
|
exports.createVNextWorkflowRunHandler = createVNextWorkflowRunHandler;
|
|
303
315
|
exports.getVNextWorkflowByIdHandler = getVNextWorkflowByIdHandler;
|
|
304
|
-
exports.
|
|
316
|
+
exports.getVNextWorkflowRunByIdHandler = getVNextWorkflowRunByIdHandler;
|
|
305
317
|
exports.getVNextWorkflowRunsHandler = getVNextWorkflowRunsHandler;
|
|
306
318
|
exports.getVNextWorkflowsHandler = getVNextWorkflowsHandler;
|
|
307
319
|
exports.resumeAsyncVNextWorkflowHandler = resumeAsyncVNextWorkflowHandler;
|