@mastra/server 0.10.13 → 0.10.15-alpha.0

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.
Files changed (99) hide show
  1. package/dist/_tsup-dts-rollup.d.cts +1107 -0
  2. package/dist/_tsup-dts-rollup.d.ts +1107 -0
  3. package/dist/chunk-2KZFMI6P.cjs +37 -0
  4. package/dist/chunk-2SLFAFTR.cjs +148 -0
  5. package/dist/chunk-3CNDE7QY.cjs +308 -0
  6. package/dist/chunk-4D66QEKC.js +81 -0
  7. package/dist/chunk-5PQQ42EZ.js +320 -0
  8. package/dist/chunk-75ZPJI57.cjs +9 -0
  9. package/dist/chunk-7TP2LX5L.cjs +129 -0
  10. package/dist/chunk-B2PAS2IB.cjs +514 -0
  11. package/dist/chunk-BK4XT6EG.js +270 -0
  12. package/dist/chunk-CCGRCYWJ.cjs +18 -0
  13. package/dist/chunk-CRCR3ZUK.js +142 -0
  14. package/dist/chunk-FRVBFMO2.cjs +128 -0
  15. package/dist/chunk-G7KH752Y.cjs +145 -0
  16. package/dist/chunk-GHC4YV6R.js +504 -0
  17. package/dist/chunk-H7DMHBKY.js +498 -0
  18. package/dist/chunk-JMLYCXMK.cjs +332 -0
  19. package/dist/chunk-KHZKYUNR.js +112 -0
  20. package/dist/chunk-KOHWJYJT.js +296 -0
  21. package/dist/chunk-LCM566I4.js +35 -0
  22. package/dist/chunk-LF7P5PLR.js +14 -0
  23. package/dist/chunk-LI436ITD.cjs +2042 -0
  24. package/dist/chunk-LRCAAFUA.js +122 -0
  25. package/dist/chunk-LZ3VJXSO.cjs +278 -0
  26. package/dist/chunk-MEGCYGBU.js +2039 -0
  27. package/dist/chunk-MLKGABMK.js +7 -0
  28. package/dist/chunk-PZQDCRPV.cjs +16 -0
  29. package/dist/chunk-QGX47B5D.cjs +86 -0
  30. package/dist/chunk-RG473F6Y.js +141 -0
  31. package/dist/chunk-RHSWAXKB.cjs +118 -0
  32. package/dist/chunk-RSEO4XPX.js +16 -0
  33. package/dist/chunk-SDPGVWQJ.cjs +512 -0
  34. package/dist/chunk-WNVFNNWN.js +121 -0
  35. package/dist/index.cjs +2 -0
  36. package/dist/index.d.cts +1 -0
  37. package/dist/index.d.ts +1 -0
  38. package/dist/index.js +1 -0
  39. package/dist/server/handlers/a2a.cjs +30 -0
  40. package/dist/server/handlers/a2a.d.cts +6 -0
  41. package/dist/server/handlers/a2a.d.ts +6 -0
  42. package/dist/server/handlers/a2a.js +1 -0
  43. package/dist/server/handlers/agents.cjs +30 -0
  44. package/dist/server/handlers/agents.d.cts +6 -0
  45. package/dist/server/handlers/agents.d.ts +6 -0
  46. package/dist/server/handlers/agents.js +1 -0
  47. package/dist/server/handlers/error.cjs +10 -0
  48. package/dist/server/handlers/error.d.cts +1 -0
  49. package/dist/server/handlers/error.d.ts +1 -0
  50. package/dist/server/handlers/error.js +1 -0
  51. package/dist/server/handlers/legacyWorkflows.cjs +46 -0
  52. package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
  53. package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
  54. package/dist/server/handlers/legacyWorkflows.js +1 -0
  55. package/dist/server/handlers/logs.cjs +18 -0
  56. package/dist/server/handlers/logs.d.cts +3 -0
  57. package/dist/server/handlers/logs.d.ts +3 -0
  58. package/dist/server/handlers/logs.js +1 -0
  59. package/dist/server/handlers/memory.cjs +46 -0
  60. package/dist/server/handlers/memory.d.cts +10 -0
  61. package/dist/server/handlers/memory.d.ts +10 -0
  62. package/dist/server/handlers/memory.js +1 -0
  63. package/dist/server/handlers/network.cjs +22 -0
  64. package/dist/server/handlers/network.d.cts +4 -0
  65. package/dist/server/handlers/network.d.ts +4 -0
  66. package/dist/server/handlers/network.js +1 -0
  67. package/dist/server/handlers/telemetry.cjs +14 -0
  68. package/dist/server/handlers/telemetry.d.cts +2 -0
  69. package/dist/server/handlers/telemetry.d.ts +2 -0
  70. package/dist/server/handlers/telemetry.js +1 -0
  71. package/dist/server/handlers/tools.cjs +22 -0
  72. package/dist/server/handlers/tools.d.cts +4 -0
  73. package/dist/server/handlers/tools.d.ts +4 -0
  74. package/dist/server/handlers/tools.js +1 -0
  75. package/dist/server/handlers/utils.cjs +10 -0
  76. package/dist/server/handlers/utils.d.cts +1 -0
  77. package/dist/server/handlers/utils.d.ts +1 -0
  78. package/dist/server/handlers/utils.js +1 -0
  79. package/dist/server/handlers/vNextNetwork.cjs +218 -0
  80. package/dist/server/handlers/vNextNetwork.d.cts +6 -0
  81. package/dist/server/handlers/vNextNetwork.d.ts +6 -0
  82. package/dist/server/handlers/vNextNetwork.js +211 -0
  83. package/dist/server/handlers/vector.cjs +30 -0
  84. package/dist/server/handlers/vector.d.cts +6 -0
  85. package/dist/server/handlers/vector.d.ts +6 -0
  86. package/dist/server/handlers/vector.js +1 -0
  87. package/dist/server/handlers/voice.cjs +22 -0
  88. package/dist/server/handlers/voice.d.cts +4 -0
  89. package/dist/server/handlers/voice.d.ts +4 -0
  90. package/dist/server/handlers/voice.js +1 -0
  91. package/dist/server/handlers/workflows.cjs +62 -0
  92. package/dist/server/handlers/workflows.d.cts +14 -0
  93. package/dist/server/handlers/workflows.d.ts +14 -0
  94. package/dist/server/handlers/workflows.js +1 -0
  95. package/dist/server/handlers.cjs +60 -0
  96. package/dist/server/handlers.d.cts +11 -0
  97. package/dist/server/handlers.d.ts +11 -0
  98. package/dist/server/handlers.js +11 -0
  99. package/package.json +3 -3
@@ -0,0 +1,7 @@
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
+ export { __export };
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
4
+
5
+ // src/server/handlers/error.ts
6
+ function handleError(error, defaultMessage) {
7
+ const apiError = error;
8
+ const apiErrorStatus = apiError.status || apiError.details?.status || 500;
9
+ throw new chunk2KZFMI6P_cjs.HTTPException(apiErrorStatus, {
10
+ message: apiError.message || defaultMessage,
11
+ stack: apiError.stack,
12
+ cause: apiError.cause
13
+ });
14
+ }
15
+
16
+ exports.handleError = handleError;
@@ -0,0 +1,86 @@
1
+ 'use strict';
2
+
3
+ var chunkCCGRCYWJ_cjs = require('./chunk-CCGRCYWJ.cjs');
4
+ var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
5
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
6
+
7
+ // src/server/handlers/logs.ts
8
+ var logs_exports = {};
9
+ chunk75ZPJI57_cjs.__export(logs_exports, {
10
+ getLogTransports: () => getLogTransports,
11
+ getLogsByRunIdHandler: () => getLogsByRunIdHandler,
12
+ getLogsHandler: () => getLogsHandler
13
+ });
14
+ async function getLogsHandler({
15
+ mastra,
16
+ transportId,
17
+ params
18
+ }) {
19
+ try {
20
+ chunkCCGRCYWJ_cjs.validateBody({ transportId });
21
+ const { fromDate, toDate, logLevel, filters: _filters, page, perPage } = params || {};
22
+ const filters = _filters ? Object.fromEntries(
23
+ (Array.isArray(_filters) ? _filters : [_filters]).map((attr) => {
24
+ const [key, value] = attr.split(":");
25
+ return [key, value];
26
+ })
27
+ ) : void 0;
28
+ const logs = await mastra.getLogs(transportId, {
29
+ fromDate,
30
+ toDate,
31
+ logLevel,
32
+ filters,
33
+ page: page ? Number(page) : void 0,
34
+ perPage: perPage ? Number(perPage) : void 0
35
+ });
36
+ return logs;
37
+ } catch (error) {
38
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting logs");
39
+ }
40
+ }
41
+ async function getLogsByRunIdHandler({
42
+ mastra,
43
+ runId,
44
+ transportId,
45
+ params
46
+ }) {
47
+ try {
48
+ chunkCCGRCYWJ_cjs.validateBody({ runId, transportId });
49
+ const { fromDate, toDate, logLevel, filters: _filters, page, perPage } = params || {};
50
+ const filters = _filters ? Object.fromEntries(
51
+ (Array.isArray(_filters) ? _filters : [_filters]).map((attr) => {
52
+ const [key, value] = attr.split(":");
53
+ return [key, value];
54
+ })
55
+ ) : void 0;
56
+ const logs = await mastra.getLogsByRunId({
57
+ runId,
58
+ transportId,
59
+ fromDate,
60
+ toDate,
61
+ logLevel,
62
+ filters,
63
+ page: page ? Number(page) : void 0,
64
+ perPage: perPage ? Number(perPage) : void 0
65
+ });
66
+ return logs;
67
+ } catch (error) {
68
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting logs by run ID");
69
+ }
70
+ }
71
+ async function getLogTransports({ mastra }) {
72
+ try {
73
+ const logger = mastra.getLogger();
74
+ const transports = logger.getTransports();
75
+ return {
76
+ transports: transports ? [...transports.keys()] : []
77
+ };
78
+ } catch (error) {
79
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting log Transports");
80
+ }
81
+ }
82
+
83
+ exports.getLogTransports = getLogTransports;
84
+ exports.getLogsByRunIdHandler = getLogsByRunIdHandler;
85
+ exports.getLogsHandler = getLogsHandler;
86
+ exports.logs_exports = logs_exports;
@@ -0,0 +1,141 @@
1
+ import { handleError } from './chunk-LF7P5PLR.js';
2
+ import { HTTPException } from './chunk-LCM566I4.js';
3
+ import { __export } from './chunk-MLKGABMK.js';
4
+
5
+ // src/server/handlers/telemetry.ts
6
+ var telemetry_exports = {};
7
+ __export(telemetry_exports, {
8
+ getTelemetryHandler: () => getTelemetryHandler,
9
+ storeTelemetryHandler: () => storeTelemetryHandler
10
+ });
11
+ async function getTelemetryHandler({ mastra, body }) {
12
+ try {
13
+ const telemetry = mastra.getTelemetry();
14
+ const storage = mastra.getStorage();
15
+ if (!telemetry) {
16
+ throw new HTTPException(400, { message: "Telemetry is not initialized" });
17
+ }
18
+ if (!storage) {
19
+ return [];
20
+ }
21
+ if (!body) {
22
+ throw new HTTPException(400, { message: "Body is required" });
23
+ }
24
+ const { name, scope, page, perPage, attribute, fromDate, toDate } = body;
25
+ const attributes = attribute ? Object.fromEntries(
26
+ (Array.isArray(attribute) ? attribute : [attribute]).map((attr) => {
27
+ const [key, value] = attr.split(":");
28
+ return [key, value];
29
+ })
30
+ ) : void 0;
31
+ const traces = await storage.getTraces({
32
+ name,
33
+ scope,
34
+ page: Number(page ?? 0),
35
+ perPage: Number(perPage ?? 100),
36
+ attributes,
37
+ fromDate: fromDate ? new Date(fromDate) : void 0,
38
+ toDate: toDate ? new Date(toDate) : void 0
39
+ });
40
+ return traces;
41
+ } catch (error2) {
42
+ return 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
+ return {
51
+ status: "error",
52
+ message: "Storage is not initialized"
53
+ };
54
+ }
55
+ const now = /* @__PURE__ */ new Date();
56
+ const items = body?.resourceSpans?.[0]?.scopeSpans;
57
+ logger.debug("[Telemetry Handler] Received spans:", {
58
+ totalSpans: items?.reduce((acc, scope) => acc + scope.spans.length, 0) || 0,
59
+ timestamp: now.toISOString()
60
+ });
61
+ if (!items?.length) {
62
+ return {
63
+ status: "success",
64
+ message: "No spans to process",
65
+ traceCount: 0
66
+ };
67
+ }
68
+ const allSpans = items.reduce((acc, scopedSpans) => {
69
+ const { scope, spans } = scopedSpans;
70
+ for (const span of spans) {
71
+ const {
72
+ spanId,
73
+ parentSpanId,
74
+ traceId,
75
+ name,
76
+ kind,
77
+ attributes,
78
+ status,
79
+ events,
80
+ links,
81
+ startTimeUnixNano,
82
+ endTimeUnixNano,
83
+ ...rest
84
+ } = span;
85
+ const startTime = Number(BigInt(startTimeUnixNano) / 1000n);
86
+ const endTime = Number(BigInt(endTimeUnixNano) / 1000n);
87
+ acc.push({
88
+ id: spanId,
89
+ parentSpanId,
90
+ traceId,
91
+ name,
92
+ scope: scope.name,
93
+ kind,
94
+ status: JSON.stringify(status),
95
+ events: JSON.stringify(events),
96
+ links: JSON.stringify(links),
97
+ attributes: JSON.stringify(
98
+ attributes.reduce((acc2, attr) => {
99
+ const valueKey = Object.keys(attr.value)[0];
100
+ if (valueKey) {
101
+ acc2[attr.key] = attr.value[valueKey];
102
+ }
103
+ return acc2;
104
+ }, {})
105
+ ),
106
+ startTime,
107
+ endTime,
108
+ other: JSON.stringify(rest),
109
+ createdAt: now
110
+ });
111
+ }
112
+ return acc;
113
+ }, []);
114
+ return storage.batchTraceInsert({
115
+ records: allSpans
116
+ }).then(() => {
117
+ return {
118
+ status: "success",
119
+ message: "Traces received and processed successfully",
120
+ traceCount: body.resourceSpans?.length || 0
121
+ };
122
+ }).catch(() => {
123
+ return {
124
+ status: "error",
125
+ message: "Failed to process traces",
126
+ // @ts-ignore
127
+ error: error.message
128
+ };
129
+ });
130
+ } catch (error2) {
131
+ console.error("Error processing traces:", error2);
132
+ return {
133
+ status: "error",
134
+ message: "Failed to process traces",
135
+ // @ts-ignore
136
+ error: error2.message
137
+ };
138
+ }
139
+ }
140
+
141
+ export { getTelemetryHandler, storeTelemetryHandler, telemetry_exports };
@@ -0,0 +1,118 @@
1
+ 'use strict';
2
+
3
+ var chunkCCGRCYWJ_cjs = require('./chunk-CCGRCYWJ.cjs');
4
+ var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
5
+ var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
6
+ var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
7
+ var stream = require('stream');
8
+
9
+ // src/server/handlers/voice.ts
10
+ var voice_exports = {};
11
+ chunk75ZPJI57_cjs.__export(voice_exports, {
12
+ generateSpeechHandler: () => generateSpeechHandler,
13
+ getListenerHandler: () => getListenerHandler,
14
+ getSpeakersHandler: () => getSpeakersHandler,
15
+ transcribeSpeechHandler: () => transcribeSpeechHandler
16
+ });
17
+ async function getSpeakersHandler({ mastra, agentId }) {
18
+ try {
19
+ if (!agentId) {
20
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Agent ID is required" });
21
+ }
22
+ const agent = mastra.getAgent(agentId);
23
+ if (!agent) {
24
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Agent not found" });
25
+ }
26
+ const voice = await agent.getVoice();
27
+ if (!voice) {
28
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
29
+ }
30
+ const speakers = await voice.getSpeakers();
31
+ return speakers;
32
+ } catch (error) {
33
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting speakers");
34
+ }
35
+ }
36
+ async function generateSpeechHandler({
37
+ mastra,
38
+ agentId,
39
+ body
40
+ }) {
41
+ try {
42
+ if (!agentId) {
43
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Agent ID is required" });
44
+ }
45
+ chunkCCGRCYWJ_cjs.validateBody({
46
+ text: body?.text
47
+ });
48
+ const agent = mastra.getAgent(agentId);
49
+ if (!agent) {
50
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Agent not found" });
51
+ }
52
+ const voice = await agent.getVoice();
53
+ if (!voice) {
54
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
55
+ }
56
+ const audioStream = await voice.speak(body.text, { speaker: body.speakerId });
57
+ if (!audioStream) {
58
+ throw new chunk2KZFMI6P_cjs.HTTPException(500, { message: "Failed to generate speech" });
59
+ }
60
+ return audioStream;
61
+ } catch (error) {
62
+ return chunkPZQDCRPV_cjs.handleError(error, "Error generating speech");
63
+ }
64
+ }
65
+ async function transcribeSpeechHandler({
66
+ mastra,
67
+ agentId,
68
+ body
69
+ }) {
70
+ try {
71
+ if (!agentId) {
72
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Agent ID is required" });
73
+ }
74
+ if (!body?.audioData) {
75
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Audio data is required" });
76
+ }
77
+ const agent = mastra.getAgent(agentId);
78
+ if (!agent) {
79
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Agent not found" });
80
+ }
81
+ const voice = await agent.getVoice();
82
+ if (!voice) {
83
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
84
+ }
85
+ const audioStream = new stream.Readable();
86
+ audioStream.push(body.audioData);
87
+ audioStream.push(null);
88
+ const text = await voice.listen(audioStream, body.options);
89
+ return { text };
90
+ } catch (error) {
91
+ return chunkPZQDCRPV_cjs.handleError(error, "Error transcribing speech");
92
+ }
93
+ }
94
+ async function getListenerHandler({ mastra, agentId }) {
95
+ try {
96
+ if (!agentId) {
97
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Agent ID is required" });
98
+ }
99
+ const agent = mastra.getAgent(agentId);
100
+ if (!agent) {
101
+ throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Agent not found" });
102
+ }
103
+ const voice = await agent.getVoice();
104
+ if (!voice) {
105
+ throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
106
+ }
107
+ const listeners = await voice.getListener();
108
+ return listeners;
109
+ } catch (error) {
110
+ return chunkPZQDCRPV_cjs.handleError(error, "Error getting listeners");
111
+ }
112
+ }
113
+
114
+ exports.generateSpeechHandler = generateSpeechHandler;
115
+ exports.getListenerHandler = getListenerHandler;
116
+ exports.getSpeakersHandler = getSpeakersHandler;
117
+ exports.transcribeSpeechHandler = transcribeSpeechHandler;
118
+ exports.voice_exports = voice_exports;
@@ -0,0 +1,16 @@
1
+ import { HTTPException } from './chunk-LCM566I4.js';
2
+
3
+ // src/server/handlers/utils.ts
4
+ function validateBody(body) {
5
+ const errorResponse = Object.entries(body).reduce((acc, [key, value]) => {
6
+ if (!value) {
7
+ acc[key] = `Argument "${key}" is required`;
8
+ }
9
+ return acc;
10
+ }, {});
11
+ if (Object.keys(errorResponse).length > 0) {
12
+ throw new HTTPException(400, { message: Object.values(errorResponse)[0] });
13
+ }
14
+ }
15
+
16
+ export { validateBody };