@mastra/server 0.0.0-separate-trace-data-from-component-20250501141108 → 0.0.0-support-d1-client-20250701191943
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 +517 -103
- package/dist/_tsup-dts-rollup.d.ts +517 -103
- package/dist/{chunk-2FJURXCL.cjs → chunk-3DKDT264.cjs} +93 -55
- package/dist/{chunk-Y3SV5XK4.js → chunk-4QBIUKVY.js} +105 -16
- package/dist/{chunk-QN4KF3BH.cjs → chunk-57CJTIPW.cjs} +2 -2
- package/dist/chunk-7524QH7G.cjs +483 -0
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/{chunk-M3YJLWTU.js → chunk-7GQJAMTA.js} +68 -57
- package/dist/chunk-BOXE6WSV.js +81 -0
- package/dist/{chunk-WTHDCRMY.js → chunk-BP24Z4WG.js} +12 -6
- package/dist/chunk-BWHGBV3K.cjs +278 -0
- package/dist/chunk-CNVDCLSY.cjs +86 -0
- package/dist/{chunk-5JNVY6DU.js → chunk-DFJUGWNU.js} +7 -5
- package/dist/{chunk-5YGDYMRB.cjs → chunk-DPRB3R7Y.cjs} +14 -13
- package/dist/{chunk-D3G23FP3.cjs → chunk-FGGMQCPP.cjs} +24 -22
- package/dist/{chunk-4JINXASC.js → chunk-FVMGZKFD.js} +5 -4
- package/dist/{chunk-Q6SHQECN.js → chunk-G37NVEDX.js} +34 -10
- package/dist/chunk-GHC4YV6R.js +504 -0
- package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
- package/dist/chunk-L3N7ST2Z.cjs +118 -0
- package/dist/chunk-LI436ITD.cjs +2042 -0
- package/dist/{chunk-RBQASTUP.js → chunk-LTJNMM2Y.js} +63 -25
- package/dist/chunk-MEGCYGBU.js +2039 -0
- package/dist/chunk-MLKGABMK.js +7 -0
- package/dist/{chunk-ZLBRQFDD.cjs → chunk-MTR2B27E.cjs} +3 -2
- package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
- package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
- package/dist/{chunk-3AHQ5RGN.js → chunk-QDOJJCS4.js} +3 -2
- package/dist/chunk-SDPGVWQJ.cjs +512 -0
- package/dist/chunk-TGZIR6AK.cjs +332 -0
- package/dist/{chunk-M56ECCHK.cjs → chunk-TVBPFPTN.cjs} +20 -19
- package/dist/{chunk-7IWQE76Z.cjs → chunk-ULFULEW4.cjs} +16 -10
- package/dist/{chunk-QJ3AHN64.js → chunk-VMXLEF54.js} +4 -3
- package/dist/chunk-Z5TH5F35.js +468 -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/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 +25 -13
- package/dist/server/handlers/workflows.d.cts +5 -2
- package/dist/server/handlers/workflows.d.ts +5 -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-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/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,25 +1,26 @@
|
|
|
1
|
-
import { stringify, esm_default } from './chunk-
|
|
2
|
-
import { handleError } from './chunk-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { stringify, esm_default } from './chunk-MEGCYGBU.js';
|
|
2
|
+
import { handleError } from './chunk-QDOJJCS4.js';
|
|
3
|
+
import { HTTPException } from './chunk-NYN7KFXL.js';
|
|
4
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
5
|
+
import { ReadableStream } from 'stream/web';
|
|
5
6
|
|
|
6
|
-
// src/server/handlers/
|
|
7
|
-
var
|
|
8
|
-
__export(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
// src/server/handlers/legacyWorkflows.ts
|
|
8
|
+
var legacyWorkflows_exports = {};
|
|
9
|
+
__export(legacyWorkflows_exports, {
|
|
10
|
+
createLegacyWorkflowRunHandler: () => createLegacyWorkflowRunHandler,
|
|
11
|
+
getLegacyWorkflowByIdHandler: () => getLegacyWorkflowByIdHandler,
|
|
12
|
+
getLegacyWorkflowRunHandler: () => getLegacyWorkflowRunHandler,
|
|
13
|
+
getLegacyWorkflowRunsHandler: () => getLegacyWorkflowRunsHandler,
|
|
14
|
+
getLegacyWorkflowsHandler: () => getLegacyWorkflowsHandler,
|
|
15
|
+
resumeAsyncLegacyWorkflowHandler: () => resumeAsyncLegacyWorkflowHandler,
|
|
16
|
+
resumeLegacyWorkflowHandler: () => resumeLegacyWorkflowHandler,
|
|
17
|
+
startAsyncLegacyWorkflowHandler: () => startAsyncLegacyWorkflowHandler,
|
|
18
|
+
startLegacyWorkflowRunHandler: () => startLegacyWorkflowRunHandler,
|
|
19
|
+
watchLegacyWorkflowHandler: () => watchLegacyWorkflowHandler
|
|
19
20
|
});
|
|
20
|
-
async function
|
|
21
|
+
async function getLegacyWorkflowsHandler({ mastra }) {
|
|
21
22
|
try {
|
|
22
|
-
const workflows = mastra.
|
|
23
|
+
const workflows = mastra.legacy_getWorkflows({ serialized: false });
|
|
23
24
|
const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
|
|
24
25
|
if (workflow.isNested) return acc;
|
|
25
26
|
acc[key] = {
|
|
@@ -45,15 +46,15 @@ async function getWorkflowsHandler({ mastra }) {
|
|
|
45
46
|
}, {});
|
|
46
47
|
return _workflows;
|
|
47
48
|
} catch (error) {
|
|
48
|
-
|
|
49
|
+
return handleError(error, "error getting workflows");
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
|
-
async function
|
|
52
|
+
async function getLegacyWorkflowByIdHandler({ mastra, workflowId }) {
|
|
52
53
|
try {
|
|
53
54
|
if (!workflowId) {
|
|
54
55
|
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
55
56
|
}
|
|
56
|
-
const workflow = mastra.
|
|
57
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
57
58
|
if (!workflow) {
|
|
58
59
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
59
60
|
}
|
|
@@ -77,10 +78,10 @@ async function getWorkflowByIdHandler({ mastra, workflowId }) {
|
|
|
77
78
|
}, {})
|
|
78
79
|
};
|
|
79
80
|
} catch (error) {
|
|
80
|
-
|
|
81
|
+
return handleError(error, "error getting workflow by id");
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
|
-
async function
|
|
84
|
+
async function startAsyncLegacyWorkflowHandler({
|
|
84
85
|
mastra,
|
|
85
86
|
runtimeContext,
|
|
86
87
|
workflowId,
|
|
@@ -91,19 +92,19 @@ async function startAsyncWorkflowHandler({
|
|
|
91
92
|
if (!workflowId) {
|
|
92
93
|
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
93
94
|
}
|
|
94
|
-
const workflow = mastra.
|
|
95
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
95
96
|
if (!workflow) {
|
|
96
97
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
97
98
|
}
|
|
98
99
|
if (!runId) {
|
|
99
|
-
const
|
|
100
|
-
const result2 = await start({
|
|
100
|
+
const newRun = workflow.createRun();
|
|
101
|
+
const result2 = await newRun.start({
|
|
101
102
|
triggerData,
|
|
102
103
|
runtimeContext
|
|
103
104
|
});
|
|
104
105
|
return result2;
|
|
105
106
|
}
|
|
106
|
-
const run = workflow.
|
|
107
|
+
const run = workflow.getMemoryRun(runId);
|
|
107
108
|
if (!run) {
|
|
108
109
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
109
110
|
}
|
|
@@ -113,10 +114,10 @@ async function startAsyncWorkflowHandler({
|
|
|
113
114
|
});
|
|
114
115
|
return result;
|
|
115
116
|
} catch (error) {
|
|
116
|
-
|
|
117
|
+
return handleError(error, "error starting workflow");
|
|
117
118
|
}
|
|
118
119
|
}
|
|
119
|
-
async function
|
|
120
|
+
async function getLegacyWorkflowRunHandler({
|
|
120
121
|
mastra,
|
|
121
122
|
workflowId,
|
|
122
123
|
runId
|
|
@@ -128,20 +129,20 @@ async function getWorkflowRunHandler({
|
|
|
128
129
|
if (!runId) {
|
|
129
130
|
throw new HTTPException(400, { message: "Run ID is required" });
|
|
130
131
|
}
|
|
131
|
-
const workflow = mastra.
|
|
132
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
132
133
|
if (!workflow) {
|
|
133
134
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
134
135
|
}
|
|
135
|
-
const run = workflow.getRun(runId);
|
|
136
|
+
const run = await workflow.getRun(runId);
|
|
136
137
|
if (!run) {
|
|
137
138
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
138
139
|
}
|
|
139
140
|
return run;
|
|
140
141
|
} catch (error) {
|
|
141
|
-
|
|
142
|
+
return handleError(error, "error getting workflow run");
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
|
-
async function
|
|
145
|
+
async function createLegacyWorkflowRunHandler({
|
|
145
146
|
mastra,
|
|
146
147
|
workflowId,
|
|
147
148
|
runId: prevRunId
|
|
@@ -150,17 +151,17 @@ async function createRunHandler({
|
|
|
150
151
|
if (!workflowId) {
|
|
151
152
|
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
152
153
|
}
|
|
153
|
-
const workflow = mastra.
|
|
154
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
154
155
|
if (!workflow) {
|
|
155
156
|
throw new HTTPException(404, { message: "Workflow not found" });
|
|
156
157
|
}
|
|
157
|
-
const
|
|
158
|
-
return { runId };
|
|
158
|
+
const newRun = workflow.createRun({ runId: prevRunId });
|
|
159
|
+
return { runId: newRun.runId };
|
|
159
160
|
} catch (error) {
|
|
160
|
-
|
|
161
|
+
return handleError(error, "error creating workflow run");
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
|
-
async function
|
|
164
|
+
async function startLegacyWorkflowRunHandler({
|
|
164
165
|
mastra,
|
|
165
166
|
runtimeContext,
|
|
166
167
|
workflowId,
|
|
@@ -174,12 +175,12 @@ async function startWorkflowRunHandler({
|
|
|
174
175
|
if (!runId) {
|
|
175
176
|
throw new HTTPException(400, { message: "runId required to start run" });
|
|
176
177
|
}
|
|
177
|
-
const workflow = mastra.
|
|
178
|
-
const run = workflow.
|
|
178
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
179
|
+
const run = workflow.getMemoryRun(runId);
|
|
179
180
|
if (!run) {
|
|
180
181
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
181
182
|
}
|
|
182
|
-
|
|
183
|
+
void run.start({
|
|
183
184
|
triggerData,
|
|
184
185
|
runtimeContext
|
|
185
186
|
});
|
|
@@ -188,7 +189,7 @@ async function startWorkflowRunHandler({
|
|
|
188
189
|
return handleError(e, "Error starting workflow run");
|
|
189
190
|
}
|
|
190
191
|
}
|
|
191
|
-
async function
|
|
192
|
+
async function watchLegacyWorkflowHandler({
|
|
192
193
|
mastra,
|
|
193
194
|
workflowId,
|
|
194
195
|
runId
|
|
@@ -200,8 +201,8 @@ async function watchWorkflowHandler({
|
|
|
200
201
|
if (!runId) {
|
|
201
202
|
throw new HTTPException(400, { message: "runId required to watch workflow" });
|
|
202
203
|
}
|
|
203
|
-
const workflow = mastra.
|
|
204
|
-
const run = workflow.
|
|
204
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
205
|
+
const run = workflow.getMemoryRun(runId);
|
|
205
206
|
if (!run) {
|
|
206
207
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
207
208
|
}
|
|
@@ -217,8 +218,10 @@ async function watchWorkflowHandler({
|
|
|
217
218
|
asyncRef = null;
|
|
218
219
|
}
|
|
219
220
|
asyncRef = setImmediate(() => {
|
|
220
|
-
|
|
221
|
+
const runDone = Object.values(activePathsObj).every((value) => value.status !== "executing");
|
|
222
|
+
if (runDone) {
|
|
221
223
|
controller.close();
|
|
224
|
+
unwatch?.();
|
|
222
225
|
}
|
|
223
226
|
});
|
|
224
227
|
});
|
|
@@ -232,7 +235,7 @@ async function watchWorkflowHandler({
|
|
|
232
235
|
return handleError(error, "Error watching workflow");
|
|
233
236
|
}
|
|
234
237
|
}
|
|
235
|
-
async function
|
|
238
|
+
async function resumeAsyncLegacyWorkflowHandler({
|
|
236
239
|
mastra,
|
|
237
240
|
workflowId,
|
|
238
241
|
runId,
|
|
@@ -246,8 +249,8 @@ async function resumeAsyncWorkflowHandler({
|
|
|
246
249
|
if (!runId) {
|
|
247
250
|
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
248
251
|
}
|
|
249
|
-
const workflow = mastra.
|
|
250
|
-
const run = workflow.
|
|
252
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
253
|
+
const run = workflow.getMemoryRun(runId);
|
|
251
254
|
if (!run) {
|
|
252
255
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
253
256
|
}
|
|
@@ -261,7 +264,7 @@ async function resumeAsyncWorkflowHandler({
|
|
|
261
264
|
return handleError(error, "Error resuming workflow step");
|
|
262
265
|
}
|
|
263
266
|
}
|
|
264
|
-
async function
|
|
267
|
+
async function resumeLegacyWorkflowHandler({
|
|
265
268
|
mastra,
|
|
266
269
|
workflowId,
|
|
267
270
|
runId,
|
|
@@ -275,12 +278,12 @@ async function resumeWorkflowHandler({
|
|
|
275
278
|
if (!runId) {
|
|
276
279
|
throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
277
280
|
}
|
|
278
|
-
const workflow = mastra.
|
|
279
|
-
const run = workflow.
|
|
281
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
282
|
+
const run = workflow.getMemoryRun(runId);
|
|
280
283
|
if (!run) {
|
|
281
284
|
throw new HTTPException(404, { message: "Workflow run not found" });
|
|
282
285
|
}
|
|
283
|
-
|
|
286
|
+
void run.resume({
|
|
284
287
|
stepId: body.stepId,
|
|
285
288
|
context: body.context,
|
|
286
289
|
runtimeContext
|
|
@@ -290,13 +293,21 @@ async function resumeWorkflowHandler({
|
|
|
290
293
|
return handleError(error, "Error resuming workflow");
|
|
291
294
|
}
|
|
292
295
|
}
|
|
293
|
-
async function
|
|
296
|
+
async function getLegacyWorkflowRunsHandler({
|
|
297
|
+
mastra,
|
|
298
|
+
workflowId,
|
|
299
|
+
fromDate,
|
|
300
|
+
toDate,
|
|
301
|
+
limit,
|
|
302
|
+
offset,
|
|
303
|
+
resourceId
|
|
304
|
+
}) {
|
|
294
305
|
try {
|
|
295
306
|
if (!workflowId) {
|
|
296
307
|
throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
297
308
|
}
|
|
298
|
-
const workflow = mastra.
|
|
299
|
-
const workflowRuns = await workflow.getWorkflowRuns() || {
|
|
309
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
310
|
+
const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
|
|
300
311
|
runs: [],
|
|
301
312
|
total: 0
|
|
302
313
|
};
|
|
@@ -306,4 +317,4 @@ async function getWorkflowRunsHandler({ mastra, workflowId }) {
|
|
|
306
317
|
}
|
|
307
318
|
}
|
|
308
319
|
|
|
309
|
-
export {
|
|
320
|
+
export { createLegacyWorkflowRunHandler, getLegacyWorkflowByIdHandler, getLegacyWorkflowRunHandler, getLegacyWorkflowRunsHandler, getLegacyWorkflowsHandler, legacyWorkflows_exports, resumeAsyncLegacyWorkflowHandler, resumeLegacyWorkflowHandler, startAsyncLegacyWorkflowHandler, startLegacyWorkflowRunHandler, watchLegacyWorkflowHandler };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { validateBody } from './chunk-H5PTF3Y4.js';
|
|
2
|
+
import { handleError } from './chunk-QDOJJCS4.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 };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { handleError } from './chunk-
|
|
2
|
-
import {
|
|
1
|
+
import { handleError } from './chunk-QDOJJCS4.js';
|
|
2
|
+
import { HTTPException } from './chunk-NYN7KFXL.js';
|
|
3
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
3
4
|
|
|
4
5
|
// src/server/handlers/telemetry.ts
|
|
5
6
|
var telemetry_exports = {};
|
|
@@ -15,12 +16,12 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
15
16
|
throw new HTTPException(400, { message: "Telemetry is not initialized" });
|
|
16
17
|
}
|
|
17
18
|
if (!storage) {
|
|
18
|
-
|
|
19
|
+
return [];
|
|
19
20
|
}
|
|
20
21
|
if (!body) {
|
|
21
22
|
throw new HTTPException(400, { message: "Body is required" });
|
|
22
23
|
}
|
|
23
|
-
const { name, scope, page, perPage, attribute } = body;
|
|
24
|
+
const { name, scope, page, perPage, attribute, fromDate, toDate } = body;
|
|
24
25
|
const attributes = attribute ? Object.fromEntries(
|
|
25
26
|
(Array.isArray(attribute) ? attribute : [attribute]).map((attr) => {
|
|
26
27
|
const [key, value] = attr.split(":");
|
|
@@ -32,7 +33,9 @@ async function getTelemetryHandler({ mastra, body }) {
|
|
|
32
33
|
scope,
|
|
33
34
|
page: Number(page ?? 0),
|
|
34
35
|
perPage: Number(perPage ?? 100),
|
|
35
|
-
attributes
|
|
36
|
+
attributes,
|
|
37
|
+
fromDate: fromDate ? new Date(fromDate) : void 0,
|
|
38
|
+
toDate: toDate ? new Date(toDate) : void 0
|
|
36
39
|
});
|
|
37
40
|
return traces;
|
|
38
41
|
} catch (error2) {
|
|
@@ -44,7 +47,10 @@ async function storeTelemetryHandler({ mastra, body }) {
|
|
|
44
47
|
const storage = mastra.getStorage();
|
|
45
48
|
const logger = mastra.getLogger();
|
|
46
49
|
if (!storage) {
|
|
47
|
-
|
|
50
|
+
return {
|
|
51
|
+
status: "error",
|
|
52
|
+
message: "Storage is not initialized"
|
|
53
|
+
};
|
|
48
54
|
}
|
|
49
55
|
const now = /* @__PURE__ */ new Date();
|
|
50
56
|
const items = body?.resourceSpans?.[0]?.scopeSpans;
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkLI436ITD_cjs = require('./chunk-LI436ITD.cjs');
|
|
4
|
+
var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
|
|
5
|
+
var chunkMTR2B27E_cjs = require('./chunk-MTR2B27E.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 defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext });
|
|
29
|
+
const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext });
|
|
30
|
+
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
31
|
+
const _tool = tool;
|
|
32
|
+
acc[key] = {
|
|
33
|
+
..._tool,
|
|
34
|
+
inputSchema: _tool.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(_tool.inputSchema)) : void 0,
|
|
35
|
+
outputSchema: _tool.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(_tool.outputSchema)) : void 0
|
|
36
|
+
};
|
|
37
|
+
return acc;
|
|
38
|
+
}, {});
|
|
39
|
+
let serializedAgentWorkflows = {};
|
|
40
|
+
if ("getWorkflows" in agent) {
|
|
41
|
+
const logger = mastra.getLogger();
|
|
42
|
+
try {
|
|
43
|
+
const workflows = await agent.getWorkflows({ runtimeContext });
|
|
44
|
+
serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
|
|
45
|
+
return {
|
|
46
|
+
...acc,
|
|
47
|
+
[key]: {
|
|
48
|
+
name: workflow.name
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}, {});
|
|
52
|
+
} catch (error) {
|
|
53
|
+
logger.error("Error getting workflows for agent", { agentName: agent.name, error });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
id,
|
|
58
|
+
name: agent.name,
|
|
59
|
+
instructions,
|
|
60
|
+
tools: serializedAgentTools,
|
|
61
|
+
workflows: serializedAgentWorkflows,
|
|
62
|
+
provider: llm?.getProvider(),
|
|
63
|
+
modelId: llm?.getModelId(),
|
|
64
|
+
defaultGenerateOptions,
|
|
65
|
+
defaultStreamOptions
|
|
66
|
+
};
|
|
67
|
+
})
|
|
68
|
+
);
|
|
69
|
+
const serializedAgents = serializedAgentsMap.reduce((acc, { id, ...rest }) => {
|
|
70
|
+
acc[id] = rest;
|
|
71
|
+
return acc;
|
|
72
|
+
}, {});
|
|
73
|
+
return serializedAgents;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
return chunkMTR2B27E_cjs.handleError(error, "Error getting agents");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function getAgentByIdHandler({
|
|
79
|
+
mastra,
|
|
80
|
+
runtimeContext,
|
|
81
|
+
agentId,
|
|
82
|
+
isPlayground = false
|
|
83
|
+
}) {
|
|
84
|
+
try {
|
|
85
|
+
const agent = mastra.getAgent(agentId);
|
|
86
|
+
if (!agent) {
|
|
87
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
88
|
+
}
|
|
89
|
+
const tools = await agent.getTools({ runtimeContext });
|
|
90
|
+
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
91
|
+
const _tool = tool;
|
|
92
|
+
acc[key] = {
|
|
93
|
+
..._tool,
|
|
94
|
+
inputSchema: _tool.inputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(_tool.inputSchema)) : void 0,
|
|
95
|
+
outputSchema: _tool.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(_tool.outputSchema)) : void 0
|
|
96
|
+
};
|
|
97
|
+
return acc;
|
|
98
|
+
}, {});
|
|
99
|
+
let serializedAgentWorkflows = {};
|
|
100
|
+
if ("getWorkflows" in agent) {
|
|
101
|
+
const logger = mastra.getLogger();
|
|
102
|
+
try {
|
|
103
|
+
const workflows = await agent.getWorkflows({ runtimeContext });
|
|
104
|
+
serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
|
|
105
|
+
return {
|
|
106
|
+
...acc,
|
|
107
|
+
[key]: {
|
|
108
|
+
name: workflow.name,
|
|
109
|
+
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
110
|
+
return {
|
|
111
|
+
...acc2,
|
|
112
|
+
[key2]: {
|
|
113
|
+
id: step.id,
|
|
114
|
+
description: step.description
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}, {})
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}, {});
|
|
121
|
+
} catch (error) {
|
|
122
|
+
logger.error("Error getting workflows for agent", { agentName: agent.name, error });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
let proxyRuntimeContext = runtimeContext;
|
|
126
|
+
if (isPlayground) {
|
|
127
|
+
proxyRuntimeContext = new Proxy(runtimeContext, {
|
|
128
|
+
get(target, prop) {
|
|
129
|
+
if (prop === "get") {
|
|
130
|
+
return function(key) {
|
|
131
|
+
const value = target.get(key);
|
|
132
|
+
return value ?? `<${key}>`;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return Reflect.get(target, prop);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
const instructions = await agent.getInstructions({ runtimeContext: proxyRuntimeContext });
|
|
140
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
141
|
+
const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext: proxyRuntimeContext });
|
|
142
|
+
const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext: proxyRuntimeContext });
|
|
143
|
+
return {
|
|
144
|
+
name: agent.name,
|
|
145
|
+
instructions,
|
|
146
|
+
tools: serializedAgentTools,
|
|
147
|
+
workflows: serializedAgentWorkflows,
|
|
148
|
+
provider: llm?.getProvider(),
|
|
149
|
+
modelId: llm?.getModelId(),
|
|
150
|
+
defaultGenerateOptions,
|
|
151
|
+
defaultStreamOptions
|
|
152
|
+
};
|
|
153
|
+
} catch (error) {
|
|
154
|
+
return chunkMTR2B27E_cjs.handleError(error, "Error getting agent");
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async function getEvalsByAgentIdHandler({
|
|
158
|
+
mastra,
|
|
159
|
+
runtimeContext,
|
|
160
|
+
agentId
|
|
161
|
+
}) {
|
|
162
|
+
try {
|
|
163
|
+
const agent = mastra.getAgent(agentId);
|
|
164
|
+
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "test") || [];
|
|
165
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
166
|
+
return {
|
|
167
|
+
id: agentId,
|
|
168
|
+
name: agent.name,
|
|
169
|
+
instructions,
|
|
170
|
+
evals
|
|
171
|
+
};
|
|
172
|
+
} catch (error) {
|
|
173
|
+
return chunkMTR2B27E_cjs.handleError(error, "Error getting test evals");
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async function getLiveEvalsByAgentIdHandler({
|
|
177
|
+
mastra,
|
|
178
|
+
runtimeContext,
|
|
179
|
+
agentId
|
|
180
|
+
}) {
|
|
181
|
+
try {
|
|
182
|
+
const agent = mastra.getAgent(agentId);
|
|
183
|
+
const evals = await mastra.getStorage()?.getEvalsByAgentName?.(agent.name, "live") || [];
|
|
184
|
+
const instructions = await agent.getInstructions({ runtimeContext });
|
|
185
|
+
return {
|
|
186
|
+
id: agentId,
|
|
187
|
+
name: agent.name,
|
|
188
|
+
instructions,
|
|
189
|
+
evals
|
|
190
|
+
};
|
|
191
|
+
} catch (error) {
|
|
192
|
+
return chunkMTR2B27E_cjs.handleError(error, "Error getting live evals");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async function generateHandler({
|
|
196
|
+
mastra,
|
|
197
|
+
runtimeContext: runtimeContext$1,
|
|
198
|
+
agentId,
|
|
199
|
+
body,
|
|
200
|
+
abortSignal
|
|
201
|
+
}) {
|
|
202
|
+
try {
|
|
203
|
+
const agent = mastra.getAgent(agentId);
|
|
204
|
+
if (!agent) {
|
|
205
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
206
|
+
}
|
|
207
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
208
|
+
const finalResourceId = resourceId ?? resourceid;
|
|
209
|
+
const finalRuntimeContext = new runtimeContext.RuntimeContext([
|
|
210
|
+
...Array.from(runtimeContext$1.entries()),
|
|
211
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
212
|
+
]);
|
|
213
|
+
chunk57CJTIPW_cjs.validateBody({ messages });
|
|
214
|
+
const result = await agent.generate(messages, {
|
|
215
|
+
...rest,
|
|
216
|
+
// @ts-expect-error TODO fix types
|
|
217
|
+
resourceId: finalResourceId,
|
|
218
|
+
runtimeContext: finalRuntimeContext,
|
|
219
|
+
signal: abortSignal
|
|
220
|
+
});
|
|
221
|
+
return result;
|
|
222
|
+
} catch (error) {
|
|
223
|
+
return chunkMTR2B27E_cjs.handleError(error, "Error generating from agent");
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
async function streamGenerateHandler({
|
|
227
|
+
mastra,
|
|
228
|
+
runtimeContext: runtimeContext$1,
|
|
229
|
+
agentId,
|
|
230
|
+
body,
|
|
231
|
+
abortSignal
|
|
232
|
+
}) {
|
|
233
|
+
try {
|
|
234
|
+
const agent = mastra.getAgent(agentId);
|
|
235
|
+
if (!agent) {
|
|
236
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
237
|
+
}
|
|
238
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
239
|
+
const finalResourceId = resourceId ?? resourceid;
|
|
240
|
+
const finalRuntimeContext = new runtimeContext.RuntimeContext([
|
|
241
|
+
...Array.from(runtimeContext$1.entries()),
|
|
242
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
243
|
+
]);
|
|
244
|
+
chunk57CJTIPW_cjs.validateBody({ messages });
|
|
245
|
+
const streamResult = await agent.stream(messages, {
|
|
246
|
+
...rest,
|
|
247
|
+
// @ts-expect-error TODO fix types
|
|
248
|
+
resourceId: finalResourceId,
|
|
249
|
+
runtimeContext: finalRuntimeContext,
|
|
250
|
+
signal: abortSignal
|
|
251
|
+
});
|
|
252
|
+
const streamResponse = rest.output ? streamResult.toTextStreamResponse({
|
|
253
|
+
headers: {
|
|
254
|
+
"Transfer-Encoding": "chunked"
|
|
255
|
+
}
|
|
256
|
+
}) : streamResult.toDataStreamResponse({
|
|
257
|
+
sendUsage: true,
|
|
258
|
+
sendReasoning: true,
|
|
259
|
+
getErrorMessage: (error) => {
|
|
260
|
+
return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
|
|
261
|
+
},
|
|
262
|
+
headers: {
|
|
263
|
+
"Transfer-Encoding": "chunked"
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
return streamResponse;
|
|
267
|
+
} catch (error) {
|
|
268
|
+
return chunkMTR2B27E_cjs.handleError(error, "error streaming agent response");
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
exports.agents_exports = agents_exports;
|
|
273
|
+
exports.generateHandler = generateHandler;
|
|
274
|
+
exports.getAgentByIdHandler = getAgentByIdHandler;
|
|
275
|
+
exports.getAgentsHandler = getAgentsHandler;
|
|
276
|
+
exports.getEvalsByAgentIdHandler = getEvalsByAgentIdHandler;
|
|
277
|
+
exports.getLiveEvalsByAgentIdHandler = getLiveEvalsByAgentIdHandler;
|
|
278
|
+
exports.streamGenerateHandler = streamGenerateHandler;
|