@mastra/server 0.0.0-llamaindex-switch-core-20250424001624 → 0.0.0-main-test-20251105183450
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/CHANGELOG.md +4494 -0
- package/LICENSE.md +11 -42
- package/README.md +45 -137
- package/dist/chunk-2PLXW4ZX.cjs +2777 -0
- package/dist/chunk-2PLXW4ZX.cjs.map +1 -0
- package/dist/chunk-46Z2KDQL.js +124 -0
- package/dist/chunk-46Z2KDQL.js.map +1 -0
- package/dist/{chunk-FV45V6WC.cjs → chunk-64ITUOXI.cjs} +3 -7
- package/dist/chunk-64ITUOXI.cjs.map +1 -0
- package/dist/{chunk-TRDNDNGQ.js → chunk-6QWQZI4Q.js} +4 -7
- package/dist/chunk-6QWQZI4Q.js.map +1 -0
- package/dist/chunk-73PAWDM5.js +83 -0
- package/dist/chunk-73PAWDM5.js.map +1 -0
- package/dist/chunk-A5SOZY5R.js +502 -0
- package/dist/chunk-A5SOZY5R.js.map +1 -0
- package/dist/chunk-AEVI2HIU.cjs +651 -0
- package/dist/chunk-AEVI2HIU.cjs.map +1 -0
- package/dist/chunk-ALOLTNSO.js +477 -0
- package/dist/chunk-ALOLTNSO.js.map +1 -0
- package/dist/chunk-B6NK4KI5.cjs +128 -0
- package/dist/chunk-B6NK4KI5.cjs.map +1 -0
- package/dist/chunk-BANGX6SC.cjs +200 -0
- package/dist/chunk-BANGX6SC.cjs.map +1 -0
- package/dist/chunk-BHQH5QXD.cjs +172 -0
- package/dist/chunk-BHQH5QXD.cjs.map +1 -0
- package/dist/chunk-BTWIR2B7.cjs +28 -0
- package/dist/chunk-BTWIR2B7.cjs.map +1 -0
- package/dist/chunk-DNUO33HF.js +129 -0
- package/dist/chunk-DNUO33HF.js.map +1 -0
- package/dist/chunk-GTZOYEAU.cjs +130 -0
- package/dist/chunk-GTZOYEAU.cjs.map +1 -0
- package/dist/chunk-GU4EWMZB.cjs +769 -0
- package/dist/chunk-GU4EWMZB.cjs.map +1 -0
- package/dist/chunk-IGOWG5V5.js +192 -0
- package/dist/chunk-IGOWG5V5.js.map +1 -0
- package/dist/chunk-JO2AZFJN.js +165 -0
- package/dist/chunk-JO2AZFJN.js.map +1 -0
- package/dist/chunk-JZ65BJ6H.cjs +678 -0
- package/dist/chunk-JZ65BJ6H.cjs.map +1 -0
- package/dist/{chunk-4JINXASC.js → chunk-KWH5QBXP.js} +7 -4
- package/dist/chunk-KWH5QBXP.js.map +1 -0
- package/dist/chunk-LF2ZLOFP.js +767 -0
- package/dist/chunk-LF2ZLOFP.js.map +1 -0
- package/dist/{chunk-Q6SHQECN.js → chunk-LPCK5MAF.js} +47 -13
- package/dist/chunk-LPCK5MAF.js.map +1 -0
- package/dist/chunk-LPM6BBAX.cjs +1043 -0
- package/dist/chunk-LPM6BBAX.cjs.map +1 -0
- package/dist/chunk-LWLSQ2W4.cjs +133 -0
- package/dist/chunk-LWLSQ2W4.cjs.map +1 -0
- package/dist/chunk-MMQIJZ2Q.cjs +23079 -0
- package/dist/chunk-MMQIJZ2Q.cjs.map +1 -0
- package/dist/chunk-O7I5CWRX.cjs +44 -0
- package/dist/chunk-O7I5CWRX.cjs.map +1 -0
- package/dist/chunk-PPMIB3FQ.cjs +88 -0
- package/dist/chunk-PPMIB3FQ.cjs.map +1 -0
- package/dist/chunk-PR4QN5HX.js +39 -0
- package/dist/chunk-PR4QN5HX.js.map +1 -0
- package/dist/chunk-QU6N55W6.cjs +256 -0
- package/dist/chunk-QU6N55W6.cjs.map +1 -0
- package/dist/chunk-R6OQFR47.js +630 -0
- package/dist/chunk-R6OQFR47.js.map +1 -0
- package/dist/chunk-RQK4FQUD.js +1012 -0
- package/dist/chunk-RQK4FQUD.js.map +1 -0
- package/dist/{chunk-M56ECCHK.cjs → chunk-S54HNARD.cjs} +22 -19
- package/dist/chunk-S54HNARD.cjs.map +1 -0
- package/dist/chunk-SHWNNZBL.js +254 -0
- package/dist/chunk-SHWNNZBL.js.map +1 -0
- package/dist/chunk-SIPNICB3.cjs +517 -0
- package/dist/chunk-SIPNICB3.cjs.map +1 -0
- package/dist/{chunk-L7XE5QTW.js → chunk-SZIFSF4T.js} +11 -2
- package/dist/chunk-SZIFSF4T.js.map +1 -0
- package/dist/chunk-TOCYBDP2.js +46 -0
- package/dist/chunk-TOCYBDP2.js.map +1 -0
- package/dist/chunk-UU7MMOP5.js +23039 -0
- package/dist/chunk-UU7MMOP5.js.map +1 -0
- package/dist/chunk-UXGQZUYZ.js +16 -0
- package/dist/chunk-UXGQZUYZ.js.map +1 -0
- package/dist/chunk-V5WWQN7P.cjs +18 -0
- package/dist/chunk-V5WWQN7P.cjs.map +1 -0
- package/dist/chunk-VYR3SAFM.js +658 -0
- package/dist/chunk-VYR3SAFM.js.map +1 -0
- package/dist/chunk-X6C7BUWN.cjs +48 -0
- package/dist/chunk-X6C7BUWN.cjs.map +1 -0
- package/dist/chunk-XXGID4PQ.cjs +485 -0
- package/dist/chunk-XXGID4PQ.cjs.map +1 -0
- package/dist/chunk-ZULZ2752.js +2774 -0
- package/dist/chunk-ZULZ2752.js.map +1 -0
- package/dist/dist-4MVGNSRL.cjs +1150 -0
- package/dist/dist-4MVGNSRL.cjs.map +1 -0
- package/dist/dist-FZYCV3VB.cjs +940 -0
- package/dist/dist-FZYCV3VB.cjs.map +1 -0
- package/dist/dist-G2BYZJOC.cjs +928 -0
- package/dist/dist-G2BYZJOC.cjs.map +1 -0
- package/dist/dist-P4MXBQ3U.cjs +16 -0
- package/dist/dist-P4MXBQ3U.cjs.map +1 -0
- package/dist/dist-PQZUVLPC.js +937 -0
- package/dist/dist-PQZUVLPC.js.map +1 -0
- package/dist/dist-R7WYX6LC.js +925 -0
- package/dist/dist-R7WYX6LC.js.map +1 -0
- package/dist/dist-RFMYFILX.cjs +764 -0
- package/dist/dist-RFMYFILX.cjs.map +1 -0
- package/dist/dist-X7XR3M3Z.js +1147 -0
- package/dist/dist-X7XR3M3Z.js.map +1 -0
- package/dist/dist-XVBSOGFK.js +761 -0
- package/dist/dist-XVBSOGFK.js.map +1 -0
- package/dist/dist-YREX2TJT.js +3 -0
- package/dist/dist-YREX2TJT.js.map +1 -0
- package/dist/index.cjs +6 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/server/a2a/protocol.d.ts +8 -0
- package/dist/server/a2a/protocol.d.ts.map +1 -0
- package/dist/server/a2a/store.cjs +25 -0
- package/dist/server/a2a/store.cjs.map +1 -0
- package/dist/server/a2a/store.d.ts +14 -0
- package/dist/server/a2a/store.d.ts.map +1 -0
- package/dist/server/a2a/store.js +23 -0
- package/dist/server/a2a/store.js.map +1 -0
- package/dist/server/a2a/tasks.d.ts +20 -0
- package/dist/server/a2a/tasks.d.ts.map +1 -0
- package/dist/server/handlers/a2a.cjs +32 -0
- package/dist/server/handlers/a2a.cjs.map +1 -0
- package/dist/server/handlers/a2a.d.ts +68 -0
- package/dist/server/handlers/a2a.d.ts.map +1 -0
- package/dist/server/handlers/a2a.js +3 -0
- package/dist/server/handlers/a2a.js.map +1 -0
- package/dist/server/handlers/agent-builder.cjs +84 -0
- package/dist/server/handlers/agent-builder.cjs.map +1 -0
- package/dist/server/handlers/agent-builder.d.ts +91 -0
- package/dist/server/handlers/agent-builder.d.ts.map +1 -0
- package/dist/server/handlers/agent-builder.js +3 -0
- package/dist/server/handlers/agent-builder.js.map +1 -0
- package/dist/server/handlers/agents.cjs +60 -10
- package/dist/server/handlers/agents.cjs.map +1 -0
- package/dist/server/handlers/agents.d.ts +194 -6
- package/dist/server/handlers/agents.d.ts.map +1 -0
- package/dist/server/handlers/agents.js +3 -1
- package/dist/server/handlers/agents.js.map +1 -0
- package/dist/server/handlers/error.cjs +4 -2
- package/dist/server/handlers/error.cjs.map +1 -0
- package/dist/server/handlers/error.d.ts +2 -1
- package/dist/server/handlers/error.d.ts.map +1 -0
- package/dist/server/handlers/error.js +3 -1
- package/dist/server/handlers/error.js.map +1 -0
- package/dist/server/handlers/logs.cjs +9 -7
- package/dist/server/handlers/logs.cjs.map +1 -0
- package/dist/server/handlers/logs.d.ts +34 -3
- package/dist/server/handlers/logs.d.ts.map +1 -0
- package/dist/server/handlers/logs.js +3 -1
- package/dist/server/handlers/logs.js.map +1 -0
- package/dist/server/handlers/memory.cjs +34 -12
- package/dist/server/handlers/memory.cjs.map +1 -0
- package/dist/server/handlers/memory.d.ts +112 -8
- package/dist/server/handlers/memory.d.ts.map +1 -0
- package/dist/server/handlers/memory.js +3 -1
- package/dist/server/handlers/memory.js.map +1 -0
- package/dist/server/handlers/observability.cjs +24 -0
- package/dist/server/handlers/observability.cjs.map +1 -0
- package/dist/server/handlers/observability.d.ts +49 -0
- package/dist/server/handlers/observability.d.ts.map +1 -0
- package/dist/server/handlers/observability.js +3 -0
- package/dist/server/handlers/observability.js.map +1 -0
- package/dist/server/handlers/scores.cjs +32 -0
- package/dist/server/handlers/scores.cjs.map +1 -0
- package/dist/server/handlers/scores.d.ts +152 -0
- package/dist/server/handlers/scores.d.ts.map +1 -0
- package/dist/server/handlers/scores.js +3 -0
- package/dist/server/handlers/scores.js.map +1 -0
- package/dist/server/handlers/tools.cjs +12 -6
- package/dist/server/handlers/tools.cjs.map +1 -0
- package/dist/server/handlers/tools.d.ts +25 -4
- package/dist/server/handlers/tools.d.ts.map +1 -0
- package/dist/server/handlers/tools.js +3 -1
- package/dist/server/handlers/tools.js.map +1 -0
- package/dist/server/handlers/utils.cjs +8 -2
- package/dist/server/handlers/utils.cjs.map +1 -0
- package/dist/server/handlers/utils.d.ts +8 -1
- package/dist/server/handlers/utils.d.ts.map +1 -0
- package/dist/server/handlers/utils.js +3 -1
- package/dist/server/handlers/utils.js.map +1 -0
- package/dist/server/handlers/vector.cjs +9 -7
- package/dist/server/handlers/vector.cjs.map +1 -0
- package/dist/server/handlers/vector.d.ts +51 -6
- package/dist/server/handlers/vector.d.ts.map +1 -0
- package/dist/server/handlers/vector.js +3 -1
- package/dist/server/handlers/vector.js.map +1 -0
- package/dist/server/handlers/voice.cjs +10 -4
- package/dist/server/handlers/voice.cjs.map +1 -0
- package/dist/server/handlers/voice.d.ts +41 -3
- package/dist/server/handlers/voice.d.ts.map +1 -0
- package/dist/server/handlers/voice.js +3 -1
- package/dist/server/handlers/voice.js.map +1 -0
- package/dist/server/handlers/workflows.cjs +54 -16
- package/dist/server/handlers/workflows.cjs.map +1 -0
- package/dist/server/handlers/workflows.d.ts +94 -10
- package/dist/server/handlers/workflows.d.ts.map +1 -0
- package/dist/server/handlers/workflows.js +3 -1
- package/dist/server/handlers/workflows.js.map +1 -0
- package/dist/server/handlers.cjs +38 -26
- package/dist/server/handlers.cjs.map +1 -0
- package/dist/server/handlers.d.ts +12 -9
- package/dist/server/handlers.d.ts.map +1 -0
- package/dist/server/handlers.js +13 -9
- package/dist/server/handlers.js.map +1 -0
- package/dist/server/http-exception.d.ts +82 -0
- package/dist/server/http-exception.d.ts.map +1 -0
- package/dist/server/types.d.ts +10 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server/utils.d.ts +44 -0
- package/dist/server/utils.d.ts.map +1 -0
- package/dist/token-375W3LEI.cjs +64 -0
- package/dist/token-375W3LEI.cjs.map +1 -0
- package/dist/token-C3IMNCC4.js +62 -0
- package/dist/token-C3IMNCC4.js.map +1 -0
- package/dist/token-util-CV3RRG6K.cjs +9 -0
- package/dist/token-util-CV3RRG6K.cjs.map +1 -0
- package/dist/token-util-E5QO2RCL.js +7 -0
- package/dist/token-util-E5QO2RCL.js.map +1 -0
- package/package.json +46 -19
- package/dist/_tsup-dts-rollup.d.cts +0 -571
- package/dist/_tsup-dts-rollup.d.ts +0 -571
- package/dist/chunk-2FJURXCL.cjs +0 -213
- package/dist/chunk-3AHQ5RGN.js +0 -11
- package/dist/chunk-3EJZQ6TQ.js +0 -49
- package/dist/chunk-55HTWX4C.cjs +0 -93
- package/dist/chunk-5JNVY6DU.js +0 -120
- package/dist/chunk-5SWCVTNL.cjs +0 -5579
- package/dist/chunk-7IWQE76Z.cjs +0 -139
- package/dist/chunk-D3G23FP3.cjs +0 -126
- package/dist/chunk-FPIWDH5Y.cjs +0 -126
- package/dist/chunk-HCOPJZ4A.cjs +0 -164
- package/dist/chunk-LFOBHRFO.js +0 -305
- package/dist/chunk-OMN3UI6X.js +0 -5576
- package/dist/chunk-QN4KF3BH.cjs +0 -18
- package/dist/chunk-R4J7XQYU.js +0 -156
- package/dist/chunk-RBQASTUP.js +0 -203
- package/dist/chunk-RE6YL32K.js +0 -120
- package/dist/chunk-SKBVVI24.cjs +0 -54
- package/dist/chunk-TZK63M5N.cjs +0 -317
- package/dist/chunk-WTHDCRMY.js +0 -135
- package/dist/chunk-ZLBRQFDD.cjs +0 -13
- package/dist/index.d.cts +0 -1
- package/dist/server/handlers/agents.d.cts +0 -6
- package/dist/server/handlers/error.d.cts +0 -1
- package/dist/server/handlers/logs.d.cts +0 -3
- package/dist/server/handlers/memory.d.cts +0 -8
- package/dist/server/handlers/network.cjs +0 -22
- package/dist/server/handlers/network.d.cts +0 -4
- package/dist/server/handlers/network.d.ts +0 -4
- package/dist/server/handlers/network.js +0 -1
- package/dist/server/handlers/telemetry.cjs +0 -14
- package/dist/server/handlers/telemetry.d.cts +0 -2
- package/dist/server/handlers/telemetry.d.ts +0 -2
- package/dist/server/handlers/telemetry.js +0 -1
- package/dist/server/handlers/tools.d.cts +0 -4
- package/dist/server/handlers/utils.d.cts +0 -1
- package/dist/server/handlers/vector.d.cts +0 -6
- package/dist/server/handlers/voice.d.cts +0 -3
- package/dist/server/handlers/workflows.d.cts +0 -10
- package/dist/server/handlers.d.cts +0 -9
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { handleError } from './chunk-UXGQZUYZ.js';
|
|
2
|
+
import { HTTPException } from './chunk-6QWQZI4Q.js';
|
|
3
|
+
import { __export } from './chunk-PR4QN5HX.js';
|
|
4
|
+
import { scoreTraces } from '@mastra/core/evals/scoreTraces';
|
|
5
|
+
|
|
6
|
+
// src/server/handlers/observability.ts
|
|
7
|
+
var observability_exports = {};
|
|
8
|
+
__export(observability_exports, {
|
|
9
|
+
getAITraceHandler: () => getAITraceHandler,
|
|
10
|
+
getAITracesPaginatedHandler: () => getAITracesPaginatedHandler,
|
|
11
|
+
listScoresBySpan: () => listScoresBySpan,
|
|
12
|
+
scoreTracesHandler: () => scoreTracesHandler
|
|
13
|
+
});
|
|
14
|
+
async function getAITraceHandler({ mastra, traceId }) {
|
|
15
|
+
try {
|
|
16
|
+
if (!traceId) {
|
|
17
|
+
throw new HTTPException(400, { message: "Trace ID is required" });
|
|
18
|
+
}
|
|
19
|
+
const storage = mastra.getStorage();
|
|
20
|
+
if (!storage) {
|
|
21
|
+
throw new HTTPException(500, { message: "Storage is not available" });
|
|
22
|
+
}
|
|
23
|
+
const trace = await storage.getAITrace(traceId);
|
|
24
|
+
if (!trace) {
|
|
25
|
+
throw new HTTPException(404, { message: `Trace with ID '${traceId}' not found` });
|
|
26
|
+
}
|
|
27
|
+
return trace;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
handleError(error, "Error getting AI trace");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function getAITracesPaginatedHandler({ mastra, body }) {
|
|
33
|
+
try {
|
|
34
|
+
const storage = mastra.getStorage();
|
|
35
|
+
if (!storage) {
|
|
36
|
+
throw new HTTPException(500, { message: "Storage is not available" });
|
|
37
|
+
}
|
|
38
|
+
if (!body) {
|
|
39
|
+
throw new HTTPException(400, { message: "Request body is required" });
|
|
40
|
+
}
|
|
41
|
+
const { filters, pagination } = body;
|
|
42
|
+
if (pagination?.page && pagination.page < 0) {
|
|
43
|
+
throw new HTTPException(400, { message: "Page must be a non-negative integer" });
|
|
44
|
+
}
|
|
45
|
+
if (pagination?.perPage && pagination.perPage < 0) {
|
|
46
|
+
throw new HTTPException(400, { message: "Per page must be a non-negative integer" });
|
|
47
|
+
}
|
|
48
|
+
if (pagination?.dateRange) {
|
|
49
|
+
const { start, end } = pagination.dateRange;
|
|
50
|
+
if (start && !(start instanceof Date)) {
|
|
51
|
+
throw new HTTPException(400, { message: "Invalid date format in date range" });
|
|
52
|
+
}
|
|
53
|
+
if (end && !(end instanceof Date)) {
|
|
54
|
+
throw new HTTPException(400, { message: "Invalid date format in date range" });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return storage.getAITracesPaginated({
|
|
58
|
+
pagination,
|
|
59
|
+
filters
|
|
60
|
+
});
|
|
61
|
+
} catch (error) {
|
|
62
|
+
handleError(error, "Error getting AI traces paginated");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function scoreTracesHandler({ mastra, body }) {
|
|
66
|
+
try {
|
|
67
|
+
if (!body) {
|
|
68
|
+
throw new HTTPException(400, { message: "Request body is required" });
|
|
69
|
+
}
|
|
70
|
+
const { scorerName, targets } = body;
|
|
71
|
+
if (!scorerName) {
|
|
72
|
+
throw new HTTPException(400, { message: "Scorer ID is required" });
|
|
73
|
+
}
|
|
74
|
+
if (!targets || targets.length === 0) {
|
|
75
|
+
throw new HTTPException(400, { message: "At least one target is required" });
|
|
76
|
+
}
|
|
77
|
+
const storage = mastra.getStorage();
|
|
78
|
+
if (!storage) {
|
|
79
|
+
throw new HTTPException(500, { message: "Storage is not available" });
|
|
80
|
+
}
|
|
81
|
+
const scorer = mastra.getScorerById(scorerName);
|
|
82
|
+
if (!scorer) {
|
|
83
|
+
throw new HTTPException(404, { message: `Scorer '${scorerName}' not found` });
|
|
84
|
+
}
|
|
85
|
+
const logger = mastra.getLogger();
|
|
86
|
+
scoreTraces({
|
|
87
|
+
scorerId: scorer.config.id || scorer.config.name,
|
|
88
|
+
targets,
|
|
89
|
+
mastra
|
|
90
|
+
}).catch((error) => {
|
|
91
|
+
logger?.error(`Background trace scoring failed: ${error.message}`, error);
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
status: "success",
|
|
95
|
+
message: `Scoring started for ${targets.length} ${targets.length === 1 ? "trace" : "traces"}`,
|
|
96
|
+
traceCount: targets.length
|
|
97
|
+
};
|
|
98
|
+
} catch (error) {
|
|
99
|
+
handleError(error, "Error processing trace scoring");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function listScoresBySpan({
|
|
103
|
+
mastra,
|
|
104
|
+
traceId,
|
|
105
|
+
spanId,
|
|
106
|
+
pagination
|
|
107
|
+
}) {
|
|
108
|
+
try {
|
|
109
|
+
const storage = mastra.getStorage();
|
|
110
|
+
if (!storage) {
|
|
111
|
+
throw new HTTPException(500, { message: "Storage is not available" });
|
|
112
|
+
}
|
|
113
|
+
if (!traceId || !spanId) {
|
|
114
|
+
throw new HTTPException(400, { message: "Trace ID and span ID are required" });
|
|
115
|
+
}
|
|
116
|
+
return await storage.listScoresBySpan({ traceId, spanId, pagination });
|
|
117
|
+
} catch (error) {
|
|
118
|
+
return handleError(error, "Error getting scores by span");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { getAITraceHandler, getAITracesPaginatedHandler, listScoresBySpan, observability_exports, scoreTracesHandler };
|
|
123
|
+
//# sourceMappingURL=chunk-46Z2KDQL.js.map
|
|
124
|
+
//# sourceMappingURL=chunk-46Z2KDQL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/handlers/observability.ts"],"names":[],"mappings":";;;;;;AAAA,IAAA,qBAAA,GAAA;AAAA,QAAA,CAAA,qBAAA,EAAA;AAAA,EAAA,iBAAA,EAAA,MAAA,iBAAA;AAAA,EAAA,2BAAA,EAAA,MAAA,2BAAA;AAAA,EAAA,gBAAA,EAAA,MAAA,gBAAA;AAAA,EAAA,kBAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AA0BA,eAAsB,iBAAA,CAAkB,EAAE,MAAA,EAAQ,OAAA,EAAQ,EAA+C;AACvG,EAAA,IAAI;AACF,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAA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AA,EACA;AACF,CAAA,EAAiF;AAC/E,EAAA,IAAI;AACF,IAAA,MAAM,OAAA,GAAU,OAAO,UAAA,EAAW;AAClC,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,IAAI,aAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,4BAA4B,CAAA;AAAA,IACtE;AAEA,IAAA,IAAI,CAAC,OAAA,IAAW,CAAC,MAAA,EAAQ;AACvB,MAAA,MAAM,IAAI,aAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,qCAAqC,CAAA;AAAA,IAC/E;AAEA,IAAA,OAAO,MAAM,OAAA,CAAQ,gBAAA,CAAiB,EAAE,OAAA,EAAS,MAAA,EAAQ,YAAY,CAAA;AAAA,EACvE,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,WAAA,CAAY,OAAO,8BAA8B,CAAA;AAAA,EAC1D;AACF","file":"chunk-46Z2KDQL.js","sourcesContent":["import { scoreTraces } from '@mastra/core/evals/scoreTraces';\nimport type { AITracesPaginatedArg, StoragePagination } from '@mastra/core/storage';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\nimport { handleError } from './error';\n\ninterface ObservabilityContext extends Context {\n traceId?: string;\n body?: AITracesPaginatedArg;\n}\n\ninterface ScoreTracesContext extends Context {\n body?: {\n // scorer.id\n scorerName: string;\n targets: Array<{\n traceId: string;\n spanId?: string;\n }>;\n };\n}\n\n/**\n * Get a complete AI trace by trace ID\n * Returns all spans in the trace with their parent-child relationships\n */\nexport async function getAITraceHandler({ mastra, traceId }: ObservabilityContext & { traceId: string }) {\n try {\n if (!traceId) {\n throw new HTTPException(400, { message: 'Trace ID is required' });\n }\n\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not available' });\n }\n\n const trace = await storage.getAITrace(traceId);\n\n if (!trace) {\n throw new HTTPException(404, { message: `Trace with ID '${traceId}' not found` });\n }\n\n return trace;\n } catch (error) {\n handleError(error, 'Error getting AI trace');\n }\n}\n\n/**\n * Get paginated AI traces with filtering and pagination\n * Returns only root spans (parent spans) for pagination, not child spans\n */\nexport async function getAITracesPaginatedHandler({ mastra, body }: ObservabilityContext) {\n try {\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not available' });\n }\n\n if (!body) {\n throw new HTTPException(400, { message: 'Request body is required' });\n }\n\n const { filters, pagination } = body;\n\n if (pagination?.page && pagination.page < 0) {\n throw new HTTPException(400, { message: 'Page must be a non-negative integer' });\n }\n\n if (pagination?.perPage && pagination.perPage < 0) {\n throw new HTTPException(400, { message: 'Per page must be a non-negative integer' });\n }\n\n if (pagination?.dateRange) {\n const { start, end } = pagination.dateRange;\n\n if (start && !(start instanceof Date)) {\n throw new HTTPException(400, { message: 'Invalid date format in date range' });\n }\n\n if (end && !(end instanceof Date)) {\n throw new HTTPException(400, { message: 'Invalid date format in date range' });\n }\n }\n\n return storage.getAITracesPaginated({\n pagination,\n filters,\n });\n } catch (error) {\n handleError(error, 'Error getting AI traces paginated');\n }\n}\n\n/**\n * Score traces using a specified scorer\n * Fire-and-forget approach - returns immediately while scoring runs in background\n */\nexport async function scoreTracesHandler({ mastra, body }: ScoreTracesContext) {\n try {\n if (!body) {\n throw new HTTPException(400, { message: 'Request body is required' });\n }\n\n const { scorerName, targets } = body;\n\n if (!scorerName) {\n throw new HTTPException(400, { message: 'Scorer ID is required' });\n }\n\n if (!targets || targets.length === 0) {\n throw new HTTPException(400, { message: 'At least one target is required' });\n }\n\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not available' });\n }\n\n const scorer = mastra.getScorerById(scorerName);\n if (!scorer) {\n throw new HTTPException(404, { message: `Scorer '${scorerName}' not found` });\n }\n\n const logger = mastra.getLogger();\n\n scoreTraces({\n scorerId: scorer.config.id || scorer.config.name,\n targets,\n mastra,\n }).catch(error => {\n logger?.error(`Background trace scoring failed: ${error.message}`, error);\n });\n\n // Return immediate response\n return {\n status: 'success',\n message: `Scoring started for ${targets.length} ${targets.length === 1 ? 'trace' : 'traces'}`,\n traceCount: targets.length,\n };\n } catch (error) {\n handleError(error, 'Error processing trace scoring');\n }\n}\n\nexport async function listScoresBySpan({\n mastra,\n traceId,\n spanId,\n pagination,\n}: Context & { traceId: string; spanId: string; pagination: StoragePagination }) {\n try {\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not available' });\n }\n\n if (!traceId || !spanId) {\n throw new HTTPException(400, { message: 'Trace ID and span ID are required' });\n }\n\n return await storage.listScoresBySpan({ traceId, spanId, pagination });\n } catch (error) {\n return handleError(error, 'Error getting scores by span');\n }\n}\n"]}
|
|
@@ -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;
|
|
@@ -19,6 +13,7 @@ var HTTPException = class extends Error {
|
|
|
19
13
|
super(options?.message, { cause: options?.cause });
|
|
20
14
|
this.res = options?.res;
|
|
21
15
|
this.status = status;
|
|
16
|
+
this.stack = options?.stack || this.stack;
|
|
22
17
|
}
|
|
23
18
|
/**
|
|
24
19
|
* Returns the response object associated with the exception.
|
|
@@ -40,4 +35,5 @@ var HTTPException = class extends Error {
|
|
|
40
35
|
};
|
|
41
36
|
|
|
42
37
|
exports.HTTPException = HTTPException;
|
|
43
|
-
|
|
38
|
+
//# sourceMappingURL=chunk-64ITUOXI.cjs.map
|
|
39
|
+
//# sourceMappingURL=chunk-64ITUOXI.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/http-exception.ts"],"names":[],"mappings":";;;AA0GO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA,EAC9B,GAAA;AAAA,EACA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CAAY,MAAA,GAAqB,GAAA,EAAK,OAAA,EAAgC;AACpE,IAAA,KAAA,CAAM,SAAS,OAAA,EAAS,EAAE,KAAA,EAAO,OAAA,EAAS,OAAO,CAAA;AACjD,IAAA,IAAA,CAAK,MAAM,OAAA,EAAS,GAAA;AACpB,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,KAAA,GAAQ,OAAA,EAAS,KAAA,IAAS,IAAA,CAAK,KAAA;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAA,GAAwB;AACtB,IAAA,IAAI,KAAK,GAAA,EAAK;AACZ,MAAA,MAAM,WAAA,GAAc,IAAI,QAAA,CAAS,IAAA,CAAK,IAAI,IAAA,EAAM;AAAA,QAC9C,QAAQ,IAAA,CAAK,MAAA;AAAA,QACb,OAAA,EAAS,KAAK,GAAA,CAAI;AAAA,OACnB,CAAA;AACD,MAAA,OAAO,WAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAI,QAAA,CAAS,IAAA,CAAK,OAAA,EAAS;AAAA,MAChC,QAAQ,IAAA,CAAK;AAAA,KACd,CAAA;AAAA,EACH;AACF","file":"chunk-64ITUOXI.cjs","sourcesContent":["// Copied from https://github.com/honojs/hono/blob/main/packages/hono/src/http-exception.ts\n\n/**\n * @module\n * This module provides the `HTTPException` class.\n */\n\ntype InfoStatusCode = 100 | 101 | 102 | 103;\ntype SuccessStatusCode = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;\ntype DeprecatedStatusCode = 305 | 306;\ntype RedirectStatusCode = 300 | 301 | 302 | 303 | 304 | DeprecatedStatusCode | 307 | 308;\ntype ClientErrorStatusCode =\n | 400\n | 401\n | 402\n | 403\n | 404\n | 405\n | 406\n | 407\n | 408\n | 409\n | 410\n | 411\n | 412\n | 413\n | 414\n | 415\n | 416\n | 417\n | 418\n | 421\n | 422\n | 423\n | 424\n | 425\n | 426\n | 428\n | 429\n | 431\n | 451;\ntype ServerErrorStatusCode = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;\n\n/**\n * `UnofficialStatusCode` can be used to specify an unofficial status code.\n * @example\n *\n * ```ts\n * app.get('/unknown', (c) => {\n * return c.text(\"Unknown Error\", 520 as UnofficialStatusCode)\n * })\n * ```\n */\nexport type UnofficialStatusCode = -1;\n\n/**\n * If you want to use an unofficial status, use `UnofficialStatusCode`.\n */\nexport type StatusCode =\n | InfoStatusCode\n | SuccessStatusCode\n | RedirectStatusCode\n | ClientErrorStatusCode\n | ServerErrorStatusCode\n | UnofficialStatusCode;\n\n/**\n * Options for creating an `HTTPException`.\n * @property res - Optional response object to use.\n * @property message - Optional custom error message.\n * @property cause - Optional cause of the error.\n * @property stack - Optional stack trace for the error.\n */\ntype HTTPExceptionOptions = {\n res?: Response;\n message?: string;\n cause?: unknown;\n stack?: string;\n};\n\n/**\n * `HTTPException` must be used when a fatal error such as authentication failure occurs.\n *\n * @see {@link https://hono.dev/docs/api/exception}\n *\n * @param {StatusCode} status - status code of HTTPException\n * @param {HTTPExceptionOptions} options - options of HTTPException\n * @param {HTTPExceptionOptions[\"res\"]} options.res - response of options of HTTPException\n * @param {HTTPExceptionOptions[\"message\"]} options.message - message of options of HTTPException\n * @param {HTTPExceptionOptions[\"cause\"]} options.cause - cause of options of HTTPException\n *\n * @example\n * ```ts\n * import { HTTPException } from 'hono/http-exception'\n *\n * // ...\n *\n * app.post('/auth', async (c, next) => {\n * // authentication\n * if (authorized === false) {\n * throw new HTTPException(401, { message: 'Custom error message' })\n * }\n * await next()\n * })\n * ```\n */\nexport class HTTPException extends Error {\n readonly res?: Response;\n readonly status: StatusCode;\n\n /**\n * Creates an instance of `HTTPException`.\n * @param status - HTTP status code for the exception. Defaults to 500.\n * @param options - Additional options for the exception.\n */\n constructor(status: StatusCode = 500, options?: HTTPExceptionOptions) {\n super(options?.message, { cause: options?.cause });\n this.res = options?.res;\n this.status = status;\n this.stack = options?.stack || this.stack;\n }\n\n /**\n * Returns the response object associated with the exception.\n * If a response object is not provided, a new response is created with the error message and status code.\n * @returns The response object.\n */\n getResponse(): Response {\n if (this.res) {\n const newResponse = new Response(this.res.body, {\n status: this.status,\n headers: this.res.headers,\n });\n return newResponse;\n }\n return new Response(this.message, {\n status: this.status,\n });\n }\n}\n"]}
|
|
@@ -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;
|
|
@@ -17,6 +11,7 @@ var HTTPException = class extends Error {
|
|
|
17
11
|
super(options?.message, { cause: options?.cause });
|
|
18
12
|
this.res = options?.res;
|
|
19
13
|
this.status = status;
|
|
14
|
+
this.stack = options?.stack || this.stack;
|
|
20
15
|
}
|
|
21
16
|
/**
|
|
22
17
|
* Returns the response object associated with the exception.
|
|
@@ -37,4 +32,6 @@ var HTTPException = class extends Error {
|
|
|
37
32
|
}
|
|
38
33
|
};
|
|
39
34
|
|
|
40
|
-
export { HTTPException
|
|
35
|
+
export { HTTPException };
|
|
36
|
+
//# sourceMappingURL=chunk-6QWQZI4Q.js.map
|
|
37
|
+
//# sourceMappingURL=chunk-6QWQZI4Q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/http-exception.ts"],"names":[],"mappings":";AA0GO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA,EAC9B,GAAA;AAAA,EACA,MAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CAAY,MAAA,GAAqB,GAAA,EAAK,OAAA,EAAgC;AACpE,IAAA,KAAA,CAAM,SAAS,OAAA,EAAS,EAAE,KAAA,EAAO,OAAA,EAAS,OAAO,CAAA;AACjD,IAAA,IAAA,CAAK,MAAM,OAAA,EAAS,GAAA;AACpB,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,KAAA,GAAQ,OAAA,EAAS,KAAA,IAAS,IAAA,CAAK,KAAA;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAA,GAAwB;AACtB,IAAA,IAAI,KAAK,GAAA,EAAK;AACZ,MAAA,MAAM,WAAA,GAAc,IAAI,QAAA,CAAS,IAAA,CAAK,IAAI,IAAA,EAAM;AAAA,QAC9C,QAAQ,IAAA,CAAK,MAAA;AAAA,QACb,OAAA,EAAS,KAAK,GAAA,CAAI;AAAA,OACnB,CAAA;AACD,MAAA,OAAO,WAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAI,QAAA,CAAS,IAAA,CAAK,OAAA,EAAS;AAAA,MAChC,QAAQ,IAAA,CAAK;AAAA,KACd,CAAA;AAAA,EACH;AACF","file":"chunk-6QWQZI4Q.js","sourcesContent":["// Copied from https://github.com/honojs/hono/blob/main/packages/hono/src/http-exception.ts\n\n/**\n * @module\n * This module provides the `HTTPException` class.\n */\n\ntype InfoStatusCode = 100 | 101 | 102 | 103;\ntype SuccessStatusCode = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;\ntype DeprecatedStatusCode = 305 | 306;\ntype RedirectStatusCode = 300 | 301 | 302 | 303 | 304 | DeprecatedStatusCode | 307 | 308;\ntype ClientErrorStatusCode =\n | 400\n | 401\n | 402\n | 403\n | 404\n | 405\n | 406\n | 407\n | 408\n | 409\n | 410\n | 411\n | 412\n | 413\n | 414\n | 415\n | 416\n | 417\n | 418\n | 421\n | 422\n | 423\n | 424\n | 425\n | 426\n | 428\n | 429\n | 431\n | 451;\ntype ServerErrorStatusCode = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;\n\n/**\n * `UnofficialStatusCode` can be used to specify an unofficial status code.\n * @example\n *\n * ```ts\n * app.get('/unknown', (c) => {\n * return c.text(\"Unknown Error\", 520 as UnofficialStatusCode)\n * })\n * ```\n */\nexport type UnofficialStatusCode = -1;\n\n/**\n * If you want to use an unofficial status, use `UnofficialStatusCode`.\n */\nexport type StatusCode =\n | InfoStatusCode\n | SuccessStatusCode\n | RedirectStatusCode\n | ClientErrorStatusCode\n | ServerErrorStatusCode\n | UnofficialStatusCode;\n\n/**\n * Options for creating an `HTTPException`.\n * @property res - Optional response object to use.\n * @property message - Optional custom error message.\n * @property cause - Optional cause of the error.\n * @property stack - Optional stack trace for the error.\n */\ntype HTTPExceptionOptions = {\n res?: Response;\n message?: string;\n cause?: unknown;\n stack?: string;\n};\n\n/**\n * `HTTPException` must be used when a fatal error such as authentication failure occurs.\n *\n * @see {@link https://hono.dev/docs/api/exception}\n *\n * @param {StatusCode} status - status code of HTTPException\n * @param {HTTPExceptionOptions} options - options of HTTPException\n * @param {HTTPExceptionOptions[\"res\"]} options.res - response of options of HTTPException\n * @param {HTTPExceptionOptions[\"message\"]} options.message - message of options of HTTPException\n * @param {HTTPExceptionOptions[\"cause\"]} options.cause - cause of options of HTTPException\n *\n * @example\n * ```ts\n * import { HTTPException } from 'hono/http-exception'\n *\n * // ...\n *\n * app.post('/auth', async (c, next) => {\n * // authentication\n * if (authorized === false) {\n * throw new HTTPException(401, { message: 'Custom error message' })\n * }\n * await next()\n * })\n * ```\n */\nexport class HTTPException extends Error {\n readonly res?: Response;\n readonly status: StatusCode;\n\n /**\n * Creates an instance of `HTTPException`.\n * @param status - HTTP status code for the exception. Defaults to 500.\n * @param options - Additional options for the exception.\n */\n constructor(status: StatusCode = 500, options?: HTTPExceptionOptions) {\n super(options?.message, { cause: options?.cause });\n this.res = options?.res;\n this.status = status;\n this.stack = options?.stack || this.stack;\n }\n\n /**\n * Returns the response object associated with the exception.\n * If a response object is not provided, a new response is created with the error message and status code.\n * @returns The response object.\n */\n getResponse(): Response {\n if (this.res) {\n const newResponse = new Response(this.res.body, {\n status: this.status,\n headers: this.res.headers,\n });\n return newResponse;\n }\n return new Response(this.message, {\n status: this.status,\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { validateBody } from './chunk-SZIFSF4T.js';
|
|
2
|
+
import { handleError } from './chunk-UXGQZUYZ.js';
|
|
3
|
+
import { __export } from './chunk-PR4QN5HX.js';
|
|
4
|
+
|
|
5
|
+
// src/server/handlers/logs.ts
|
|
6
|
+
var logs_exports = {};
|
|
7
|
+
__export(logs_exports, {
|
|
8
|
+
listLogTransports: () => listLogTransports,
|
|
9
|
+
listLogsByRunIdHandler: () => listLogsByRunIdHandler,
|
|
10
|
+
listLogsHandler: () => listLogsHandler
|
|
11
|
+
});
|
|
12
|
+
async function listLogsHandler({
|
|
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.listLogs(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 listLogsByRunIdHandler({
|
|
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.listLogsByRunId({
|
|
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 listLogTransports({ 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 { listLogTransports, listLogsByRunIdHandler, listLogsHandler, logs_exports };
|
|
82
|
+
//# sourceMappingURL=chunk-73PAWDM5.js.map
|
|
83
|
+
//# sourceMappingURL=chunk-73PAWDM5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/handlers/logs.ts"],"names":[],"mappings":";;;;;AAAA,IAAA,YAAA,GAAA;AAAA,QAAA,CAAA,YAAA,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AAA,EAAY,aAAa,CAAC,GAAG,WAAW,IAAA,EAAM,IAAI;AAAC,KACrD;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,WAAA,CAAY,OAAO,8BAA8B,CAAA;AAAA,EAC1D;AACF","file":"chunk-73PAWDM5.js","sourcesContent":["import type { BaseLogMessage, LogLevel } from '@mastra/core/logger';\nimport type { Mastra } from '@mastra/core/mastra';\nimport { handleError } from './error';\nimport { validateBody } from './utils';\n\ntype LogsContext = {\n mastra: Mastra;\n transportId?: string;\n runId?: string;\n params?: {\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: string | string[];\n page?: number;\n perPage?: number;\n };\n};\n\nexport async function listLogsHandler({\n mastra,\n transportId,\n params,\n}: Pick<LogsContext, 'mastra' | 'transportId' | 'params'>): Promise<{\n logs: BaseLogMessage[];\n total: number;\n page: number;\n perPage: number;\n hasMore: boolean;\n}> {\n try {\n validateBody({ transportId });\n\n const { fromDate, toDate, logLevel, filters: _filters, page, perPage } = params || {};\n\n // Parse filter query parameter if present\n const filters = _filters\n ? Object.fromEntries(\n (Array.isArray(_filters) ? _filters : [_filters]).map(attr => {\n const [key, value] = attr.split(':');\n return [key, value];\n }),\n )\n : undefined;\n\n const logs = await mastra.listLogs(transportId!, {\n fromDate,\n toDate,\n logLevel,\n filters,\n page: page ? Number(page) : undefined,\n perPage: perPage ? Number(perPage) : undefined,\n });\n return logs;\n } catch (error) {\n return handleError(error, 'Error getting logs');\n }\n}\n\nexport async function listLogsByRunIdHandler({\n mastra,\n runId,\n transportId,\n params,\n}: Pick<LogsContext, 'mastra' | 'runId' | 'transportId' | 'params'>) {\n try {\n validateBody({ runId, transportId });\n\n const { fromDate, toDate, logLevel, filters: _filters, page, perPage } = params || {};\n\n // Parse filter query parameter if present\n const filters = _filters\n ? Object.fromEntries(\n (Array.isArray(_filters) ? _filters : [_filters]).map(attr => {\n const [key, value] = attr.split(':');\n return [key, value];\n }),\n )\n : undefined;\n\n const logs = await mastra.listLogsByRunId({\n runId: runId!,\n transportId: transportId!,\n fromDate,\n toDate,\n logLevel,\n filters,\n page: page ? Number(page) : undefined,\n perPage: perPage ? Number(perPage) : undefined,\n });\n return logs;\n } catch (error) {\n return handleError(error, 'Error getting logs by run ID');\n }\n}\n\nexport async function listLogTransports({ mastra }: Pick<LogsContext, 'mastra'>) {\n try {\n const logger = mastra.getLogger();\n const transports = logger.getTransports();\n\n return {\n transports: transports ? [...transports.keys()] : [],\n };\n } catch (error) {\n return handleError(error, 'Error getting log Transports');\n }\n}\n"]}
|