@mastra/server 0.0.0-a2a-20250421213654
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/LICENSE.md +46 -0
- package/README.md +159 -0
- package/dist/_tsup-dts-rollup.d.cts +897 -0
- package/dist/_tsup-dts-rollup.d.ts +897 -0
- package/dist/chunk-3KWAWPRU.cjs +127 -0
- package/dist/chunk-4VNS5WPM.js +37 -0
- package/dist/chunk-57CJTIPW.cjs +18 -0
- package/dist/chunk-5SWCVTNL.cjs +5579 -0
- package/dist/chunk-64U3UDTH.cjs +13 -0
- package/dist/chunk-6QEBCWQG.js +136 -0
- package/dist/chunk-75KYFUMD.cjs +165 -0
- package/dist/chunk-B2TWGIVC.cjs +101 -0
- package/dist/chunk-CVPOREIE.cjs +42 -0
- package/dist/chunk-CZOSYERC.js +312 -0
- package/dist/chunk-FFRES7WX.js +157 -0
- package/dist/chunk-H5PTF3Y4.js +16 -0
- package/dist/chunk-IDPBXKRV.js +121 -0
- package/dist/chunk-J2MCTUD4.js +121 -0
- package/dist/chunk-JQCFFVSK.cjs +127 -0
- package/dist/chunk-LGJ46RCS.js +96 -0
- package/dist/chunk-LTP7PHVE.cjs +321 -0
- package/dist/chunk-M5ABIP7D.js +11 -0
- package/dist/chunk-NJF275KR.js +49 -0
- package/dist/chunk-NYN7KFXL.js +34 -0
- package/dist/chunk-O7X557PN.cjs +140 -0
- package/dist/chunk-OCWPVYNI.cjs +36 -0
- package/dist/chunk-OMN3UI6X.js +5576 -0
- package/dist/chunk-P7UZNROR.js +306 -0
- package/dist/chunk-PJHJORJL.js +204 -0
- package/dist/chunk-RXH2S65Z.cjs +54 -0
- package/dist/chunk-UVVUDJBW.cjs +214 -0
- package/dist/chunk-Y7WN2UYV.cjs +318 -0
- package/dist/chunk-YB2FGKQ5.js +121 -0
- package/dist/chunk-ZCRMOXNW.cjs +129 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/magic-string.es-5UDOWOAZ.js +1294 -0
- package/dist/magic-string.es-IL2775P6.cjs +1300 -0
- package/dist/server/handlers/a2a.cjs +34 -0
- package/dist/server/handlers/a2a.d.cts +7 -0
- package/dist/server/handlers/a2a.d.ts +7 -0
- package/dist/server/handlers/a2a.js +1 -0
- package/dist/server/handlers/agents.cjs +30 -0
- package/dist/server/handlers/agents.d.cts +6 -0
- package/dist/server/handlers/agents.d.ts +6 -0
- package/dist/server/handlers/agents.js +1 -0
- package/dist/server/handlers/error.cjs +10 -0
- package/dist/server/handlers/error.d.cts +1 -0
- package/dist/server/handlers/error.d.ts +1 -0
- package/dist/server/handlers/error.js +1 -0
- package/dist/server/handlers/logs.cjs +18 -0
- package/dist/server/handlers/logs.d.cts +3 -0
- package/dist/server/handlers/logs.d.ts +3 -0
- package/dist/server/handlers/logs.js +1 -0
- package/dist/server/handlers/memory.cjs +38 -0
- package/dist/server/handlers/memory.d.cts +8 -0
- package/dist/server/handlers/memory.d.ts +8 -0
- package/dist/server/handlers/memory.js +1 -0
- package/dist/server/handlers/network.cjs +22 -0
- package/dist/server/handlers/network.d.cts +4 -0
- package/dist/server/handlers/network.d.ts +4 -0
- package/dist/server/handlers/network.js +1 -0
- package/dist/server/handlers/telemetry.cjs +14 -0
- package/dist/server/handlers/telemetry.d.cts +2 -0
- package/dist/server/handlers/telemetry.d.ts +2 -0
- package/dist/server/handlers/telemetry.js +1 -0
- package/dist/server/handlers/test-utils.cjs +16209 -0
- package/dist/server/handlers/test-utils.d.cts +1 -0
- package/dist/server/handlers/test-utils.d.ts +1 -0
- package/dist/server/handlers/test-utils.js +16207 -0
- package/dist/server/handlers/tools.cjs +22 -0
- package/dist/server/handlers/tools.d.cts +4 -0
- package/dist/server/handlers/tools.d.ts +4 -0
- package/dist/server/handlers/tools.js +1 -0
- package/dist/server/handlers/utils.cjs +10 -0
- package/dist/server/handlers/utils.d.cts +1 -0
- package/dist/server/handlers/utils.d.ts +1 -0
- package/dist/server/handlers/utils.js +1 -0
- package/dist/server/handlers/vector.cjs +30 -0
- package/dist/server/handlers/vector.d.cts +6 -0
- package/dist/server/handlers/vector.d.ts +6 -0
- package/dist/server/handlers/vector.js +1 -0
- package/dist/server/handlers/voice.cjs +18 -0
- package/dist/server/handlers/voice.d.cts +3 -0
- package/dist/server/handlers/voice.d.ts +3 -0
- package/dist/server/handlers/voice.js +1 -0
- package/dist/server/handlers/workflows.cjs +46 -0
- package/dist/server/handlers/workflows.d.cts +10 -0
- package/dist/server/handlers/workflows.d.ts +10 -0
- package/dist/server/handlers/workflows.js +1 -0
- package/dist/server/handlers.cjs +55 -0
- package/dist/server/handlers.d.cts +10 -0
- package/dist/server/handlers.d.ts +10 -0
- package/dist/server/handlers.js +10 -0
- package/package.json +71 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { validateBody } from './chunk-H5PTF3Y4.js';
|
|
2
|
+
import { handleError } from './chunk-M5ABIP7D.js';
|
|
3
|
+
import { __export } from './chunk-4VNS5WPM.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
|
+
}) {
|
|
16
|
+
try {
|
|
17
|
+
validateBody({ transportId });
|
|
18
|
+
const logs = await mastra.getLogs(transportId);
|
|
19
|
+
return logs;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return handleError(error, "Error getting logs");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function getLogsByRunIdHandler({
|
|
25
|
+
mastra,
|
|
26
|
+
runId,
|
|
27
|
+
transportId
|
|
28
|
+
}) {
|
|
29
|
+
try {
|
|
30
|
+
validateBody({ runId, transportId });
|
|
31
|
+
const logs = await mastra.getLogsByRunId({ runId, transportId });
|
|
32
|
+
return logs;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return handleError(error, "Error getting logs by run ID");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function getLogTransports({ mastra }) {
|
|
38
|
+
try {
|
|
39
|
+
const logger = mastra.getLogger();
|
|
40
|
+
const transports = logger.transports;
|
|
41
|
+
return {
|
|
42
|
+
transports: transports ? Object.keys(transports) : []
|
|
43
|
+
};
|
|
44
|
+
} catch (error) {
|
|
45
|
+
return handleError(error, "Error getting log Transports");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { getLogTransports, getLogsByRunIdHandler, getLogsHandler, logs_exports };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/server/http-exception.ts
|
|
2
|
+
var HTTPException = class extends Error {
|
|
3
|
+
res;
|
|
4
|
+
status;
|
|
5
|
+
/**
|
|
6
|
+
* Creates an instance of `HTTPException`.
|
|
7
|
+
* @param status - HTTP status code for the exception. Defaults to 500.
|
|
8
|
+
* @param options - Additional options for the exception.
|
|
9
|
+
*/
|
|
10
|
+
constructor(status = 500, options) {
|
|
11
|
+
super(options?.message, { cause: options?.cause });
|
|
12
|
+
this.res = options?.res;
|
|
13
|
+
this.status = status;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns the response object associated with the exception.
|
|
17
|
+
* If a response object is not provided, a new response is created with the error message and status code.
|
|
18
|
+
* @returns The response object.
|
|
19
|
+
*/
|
|
20
|
+
getResponse() {
|
|
21
|
+
if (this.res) {
|
|
22
|
+
const newResponse = new Response(this.res.body, {
|
|
23
|
+
status: this.status,
|
|
24
|
+
headers: this.res.headers
|
|
25
|
+
});
|
|
26
|
+
return newResponse;
|
|
27
|
+
}
|
|
28
|
+
return new Response(this.message, {
|
|
29
|
+
status: this.status
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export { HTTPException };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
|
|
4
|
+
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
|
|
5
|
+
var chunkCVPOREIE_cjs = require('./chunk-CVPOREIE.cjs');
|
|
6
|
+
|
|
7
|
+
// src/server/handlers/telemetry.ts
|
|
8
|
+
var telemetry_exports = {};
|
|
9
|
+
chunkCVPOREIE_cjs.__export(telemetry_exports, {
|
|
10
|
+
getTelemetryHandler: () => getTelemetryHandler,
|
|
11
|
+
storeTelemetryHandler: () => storeTelemetryHandler
|
|
12
|
+
});
|
|
13
|
+
async function getTelemetryHandler({ mastra, body }) {
|
|
14
|
+
try {
|
|
15
|
+
const telemetry = mastra.getTelemetry();
|
|
16
|
+
const storage = mastra.getStorage();
|
|
17
|
+
if (!telemetry) {
|
|
18
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Telemetry is not initialized" });
|
|
19
|
+
}
|
|
20
|
+
if (!storage) {
|
|
21
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Storage is not initialized" });
|
|
22
|
+
}
|
|
23
|
+
if (!body) {
|
|
24
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Body is required" });
|
|
25
|
+
}
|
|
26
|
+
const { name, scope, page, perPage, attribute } = body;
|
|
27
|
+
const attributes = attribute ? Object.fromEntries(
|
|
28
|
+
(Array.isArray(attribute) ? attribute : [attribute]).map((attr) => {
|
|
29
|
+
const [key, value] = attr.split(":");
|
|
30
|
+
return [key, value];
|
|
31
|
+
})
|
|
32
|
+
) : void 0;
|
|
33
|
+
const traces = await storage.getTraces({
|
|
34
|
+
name,
|
|
35
|
+
scope,
|
|
36
|
+
page: Number(page ?? 0),
|
|
37
|
+
perPage: Number(perPage ?? 100),
|
|
38
|
+
attributes
|
|
39
|
+
});
|
|
40
|
+
return traces;
|
|
41
|
+
} catch (error2) {
|
|
42
|
+
return chunk64U3UDTH_cjs.handleError(error2, "Error getting telemetry");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function storeTelemetryHandler({ mastra, body }) {
|
|
46
|
+
try {
|
|
47
|
+
const storage = mastra.getStorage();
|
|
48
|
+
const logger = mastra.getLogger();
|
|
49
|
+
if (!storage) {
|
|
50
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Storage is not initialized" });
|
|
51
|
+
}
|
|
52
|
+
const now = /* @__PURE__ */ new Date();
|
|
53
|
+
const items = body?.resourceSpans?.[0]?.scopeSpans;
|
|
54
|
+
logger.debug("[Telemetry Handler] Received spans:", {
|
|
55
|
+
totalSpans: items?.reduce((acc, scope) => acc + scope.spans.length, 0) || 0,
|
|
56
|
+
timestamp: now.toISOString()
|
|
57
|
+
});
|
|
58
|
+
if (!items?.length) {
|
|
59
|
+
return {
|
|
60
|
+
status: "success",
|
|
61
|
+
message: "No spans to process",
|
|
62
|
+
traceCount: 0
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const allSpans = items.reduce((acc, scopedSpans) => {
|
|
66
|
+
const { scope, spans } = scopedSpans;
|
|
67
|
+
for (const span of spans) {
|
|
68
|
+
const {
|
|
69
|
+
spanId,
|
|
70
|
+
parentSpanId,
|
|
71
|
+
traceId,
|
|
72
|
+
name,
|
|
73
|
+
kind,
|
|
74
|
+
attributes,
|
|
75
|
+
status,
|
|
76
|
+
events,
|
|
77
|
+
links,
|
|
78
|
+
startTimeUnixNano,
|
|
79
|
+
endTimeUnixNano,
|
|
80
|
+
...rest
|
|
81
|
+
} = span;
|
|
82
|
+
const startTime = Number(BigInt(startTimeUnixNano) / 1000n);
|
|
83
|
+
const endTime = Number(BigInt(endTimeUnixNano) / 1000n);
|
|
84
|
+
acc.push({
|
|
85
|
+
id: spanId,
|
|
86
|
+
parentSpanId,
|
|
87
|
+
traceId,
|
|
88
|
+
name,
|
|
89
|
+
scope: scope.name,
|
|
90
|
+
kind,
|
|
91
|
+
status: JSON.stringify(status),
|
|
92
|
+
events: JSON.stringify(events),
|
|
93
|
+
links: JSON.stringify(links),
|
|
94
|
+
attributes: JSON.stringify(
|
|
95
|
+
attributes.reduce((acc2, attr) => {
|
|
96
|
+
const valueKey = Object.keys(attr.value)[0];
|
|
97
|
+
if (valueKey) {
|
|
98
|
+
acc2[attr.key] = attr.value[valueKey];
|
|
99
|
+
}
|
|
100
|
+
return acc2;
|
|
101
|
+
}, {})
|
|
102
|
+
),
|
|
103
|
+
startTime,
|
|
104
|
+
endTime,
|
|
105
|
+
other: JSON.stringify(rest),
|
|
106
|
+
createdAt: now
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return acc;
|
|
110
|
+
}, []);
|
|
111
|
+
return storage.batchTraceInsert({
|
|
112
|
+
records: allSpans
|
|
113
|
+
}).then(() => {
|
|
114
|
+
return {
|
|
115
|
+
status: "success",
|
|
116
|
+
message: "Traces received and processed successfully",
|
|
117
|
+
traceCount: body.resourceSpans?.length || 0
|
|
118
|
+
};
|
|
119
|
+
}).catch(() => {
|
|
120
|
+
return {
|
|
121
|
+
status: "error",
|
|
122
|
+
message: "Failed to process traces",
|
|
123
|
+
// @ts-ignore
|
|
124
|
+
error: error.message
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
} catch (error2) {
|
|
128
|
+
console.error("Error processing traces:", error2);
|
|
129
|
+
return {
|
|
130
|
+
status: "error",
|
|
131
|
+
message: "Failed to process traces",
|
|
132
|
+
// @ts-ignore
|
|
133
|
+
error: error2.message
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
exports.getTelemetryHandler = getTelemetryHandler;
|
|
139
|
+
exports.storeTelemetryHandler = storeTelemetryHandler;
|
|
140
|
+
exports.telemetry_exports = telemetry_exports;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/server/http-exception.ts
|
|
4
|
+
var HTTPException = class extends Error {
|
|
5
|
+
res;
|
|
6
|
+
status;
|
|
7
|
+
/**
|
|
8
|
+
* Creates an instance of `HTTPException`.
|
|
9
|
+
* @param status - HTTP status code for the exception. Defaults to 500.
|
|
10
|
+
* @param options - Additional options for the exception.
|
|
11
|
+
*/
|
|
12
|
+
constructor(status = 500, options) {
|
|
13
|
+
super(options?.message, { cause: options?.cause });
|
|
14
|
+
this.res = options?.res;
|
|
15
|
+
this.status = status;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Returns the response object associated with the exception.
|
|
19
|
+
* If a response object is not provided, a new response is created with the error message and status code.
|
|
20
|
+
* @returns The response object.
|
|
21
|
+
*/
|
|
22
|
+
getResponse() {
|
|
23
|
+
if (this.res) {
|
|
24
|
+
const newResponse = new Response(this.res.body, {
|
|
25
|
+
status: this.status,
|
|
26
|
+
headers: this.res.headers
|
|
27
|
+
});
|
|
28
|
+
return newResponse;
|
|
29
|
+
}
|
|
30
|
+
return new Response(this.message, {
|
|
31
|
+
status: this.status
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.HTTPException = HTTPException;
|