@mastra/server 0.10.12 → 0.10.13

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/package.json +2 -2
  2. package/dist/_tsup-dts-rollup.d.cts +0 -1078
  3. package/dist/_tsup-dts-rollup.d.ts +0 -1078
  4. package/dist/chunk-2KZFMI6P.cjs +0 -37
  5. package/dist/chunk-2SLFAFTR.cjs +0 -148
  6. package/dist/chunk-4D66QEKC.js +0 -81
  7. package/dist/chunk-5PQQ42EZ.js +0 -320
  8. package/dist/chunk-75ZPJI57.cjs +0 -9
  9. package/dist/chunk-7TP2LX5L.cjs +0 -129
  10. package/dist/chunk-B2PAS2IB.cjs +0 -514
  11. package/dist/chunk-BK4XT6EG.js +0 -270
  12. package/dist/chunk-CCGRCYWJ.cjs +0 -18
  13. package/dist/chunk-CRCR3ZUK.js +0 -142
  14. package/dist/chunk-DN7K6FJK.cjs +0 -251
  15. package/dist/chunk-FRVBFMO2.cjs +0 -128
  16. package/dist/chunk-G7KH752Y.cjs +0 -145
  17. package/dist/chunk-GHC4YV6R.js +0 -504
  18. package/dist/chunk-H7DMHBKY.js +0 -498
  19. package/dist/chunk-JMLYCXMK.cjs +0 -332
  20. package/dist/chunk-KHZKYUNR.js +0 -112
  21. package/dist/chunk-LCM566I4.js +0 -35
  22. package/dist/chunk-LF7P5PLR.js +0 -14
  23. package/dist/chunk-LI436ITD.cjs +0 -2042
  24. package/dist/chunk-LRCAAFUA.js +0 -122
  25. package/dist/chunk-LZ3VJXSO.cjs +0 -278
  26. package/dist/chunk-MEGCYGBU.js +0 -2039
  27. package/dist/chunk-MKLYEKEF.js +0 -241
  28. package/dist/chunk-MLKGABMK.js +0 -7
  29. package/dist/chunk-PZQDCRPV.cjs +0 -16
  30. package/dist/chunk-QGX47B5D.cjs +0 -86
  31. package/dist/chunk-RG473F6Y.js +0 -141
  32. package/dist/chunk-RHSWAXKB.cjs +0 -118
  33. package/dist/chunk-RSEO4XPX.js +0 -16
  34. package/dist/chunk-SDPGVWQJ.cjs +0 -512
  35. package/dist/chunk-WNVFNNWN.js +0 -121
  36. package/dist/index.cjs +0 -2
  37. package/dist/index.d.cts +0 -1
  38. package/dist/index.d.ts +0 -1
  39. package/dist/index.js +0 -1
  40. package/dist/server/handlers/a2a.cjs +0 -30
  41. package/dist/server/handlers/a2a.d.cts +0 -6
  42. package/dist/server/handlers/a2a.d.ts +0 -6
  43. package/dist/server/handlers/a2a.js +0 -1
  44. package/dist/server/handlers/agents.cjs +0 -30
  45. package/dist/server/handlers/agents.d.cts +0 -6
  46. package/dist/server/handlers/agents.d.ts +0 -6
  47. package/dist/server/handlers/agents.js +0 -1
  48. package/dist/server/handlers/error.cjs +0 -10
  49. package/dist/server/handlers/error.d.cts +0 -1
  50. package/dist/server/handlers/error.d.ts +0 -1
  51. package/dist/server/handlers/error.js +0 -1
  52. package/dist/server/handlers/legacyWorkflows.cjs +0 -46
  53. package/dist/server/handlers/legacyWorkflows.d.cts +0 -10
  54. package/dist/server/handlers/legacyWorkflows.d.ts +0 -10
  55. package/dist/server/handlers/legacyWorkflows.js +0 -1
  56. package/dist/server/handlers/logs.cjs +0 -18
  57. package/dist/server/handlers/logs.d.cts +0 -3
  58. package/dist/server/handlers/logs.d.ts +0 -3
  59. package/dist/server/handlers/logs.js +0 -1
  60. package/dist/server/handlers/memory.cjs +0 -38
  61. package/dist/server/handlers/memory.d.cts +0 -8
  62. package/dist/server/handlers/memory.d.ts +0 -8
  63. package/dist/server/handlers/memory.js +0 -1
  64. package/dist/server/handlers/network.cjs +0 -22
  65. package/dist/server/handlers/network.d.cts +0 -4
  66. package/dist/server/handlers/network.d.ts +0 -4
  67. package/dist/server/handlers/network.js +0 -1
  68. package/dist/server/handlers/telemetry.cjs +0 -14
  69. package/dist/server/handlers/telemetry.d.cts +0 -2
  70. package/dist/server/handlers/telemetry.d.ts +0 -2
  71. package/dist/server/handlers/telemetry.js +0 -1
  72. package/dist/server/handlers/tools.cjs +0 -22
  73. package/dist/server/handlers/tools.d.cts +0 -4
  74. package/dist/server/handlers/tools.d.ts +0 -4
  75. package/dist/server/handlers/tools.js +0 -1
  76. package/dist/server/handlers/utils.cjs +0 -10
  77. package/dist/server/handlers/utils.d.cts +0 -1
  78. package/dist/server/handlers/utils.d.ts +0 -1
  79. package/dist/server/handlers/utils.js +0 -1
  80. package/dist/server/handlers/vNextNetwork.cjs +0 -218
  81. package/dist/server/handlers/vNextNetwork.d.cts +0 -6
  82. package/dist/server/handlers/vNextNetwork.d.ts +0 -6
  83. package/dist/server/handlers/vNextNetwork.js +0 -211
  84. package/dist/server/handlers/vector.cjs +0 -30
  85. package/dist/server/handlers/vector.d.cts +0 -6
  86. package/dist/server/handlers/vector.d.ts +0 -6
  87. package/dist/server/handlers/vector.js +0 -1
  88. package/dist/server/handlers/voice.cjs +0 -22
  89. package/dist/server/handlers/voice.d.cts +0 -4
  90. package/dist/server/handlers/voice.d.ts +0 -4
  91. package/dist/server/handlers/voice.js +0 -1
  92. package/dist/server/handlers/workflows.cjs +0 -62
  93. package/dist/server/handlers/workflows.d.cts +0 -14
  94. package/dist/server/handlers/workflows.d.ts +0 -14
  95. package/dist/server/handlers/workflows.js +0 -1
  96. package/dist/server/handlers.cjs +0 -60
  97. package/dist/server/handlers.d.cts +0 -11
  98. package/dist/server/handlers.d.ts +0 -11
  99. package/dist/server/handlers.js +0 -11
@@ -1,241 +0,0 @@
1
- import { validateBody } from './chunk-RSEO4XPX.js';
2
- import { handleError } from './chunk-LF7P5PLR.js';
3
- import { HTTPException } from './chunk-LCM566I4.js';
4
- import { __export } from './chunk-MLKGABMK.js';
5
-
6
- // src/server/handlers/memory.ts
7
- var memory_exports = {};
8
- __export(memory_exports, {
9
- createThreadHandler: () => createThreadHandler,
10
- deleteThreadHandler: () => deleteThreadHandler,
11
- getMemoryStatusHandler: () => getMemoryStatusHandler,
12
- getMessagesHandler: () => getMessagesHandler,
13
- getThreadByIdHandler: () => getThreadByIdHandler,
14
- getThreadsHandler: () => getThreadsHandler,
15
- saveMessagesHandler: () => saveMessagesHandler,
16
- updateThreadHandler: () => updateThreadHandler
17
- });
18
- async function getMemoryFromContext({
19
- mastra,
20
- agentId,
21
- networkId,
22
- runtimeContext
23
- }) {
24
- const agent = agentId ? mastra.getAgent(agentId) : null;
25
- if (agentId && !agent) {
26
- throw new HTTPException(404, { message: "Agent not found" });
27
- }
28
- const network = networkId ? mastra.vnext_getNetwork(networkId) : null;
29
- if (networkId && !network) {
30
- throw new HTTPException(404, { message: "Network not found" });
31
- }
32
- if (agent) {
33
- return agent?.getMemory() || mastra.getMemory();
34
- }
35
- if (network) {
36
- return await network?.getMemory({ runtimeContext }) || mastra.getMemory();
37
- }
38
- return mastra.getMemory();
39
- }
40
- async function getMemoryStatusHandler({
41
- mastra,
42
- agentId,
43
- networkId,
44
- runtimeContext
45
- }) {
46
- try {
47
- const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
48
- if (!memory) {
49
- return { result: false };
50
- }
51
- return { result: true };
52
- } catch (error) {
53
- return handleError(error, "Error getting memory status");
54
- }
55
- }
56
- async function getThreadsHandler({
57
- mastra,
58
- agentId,
59
- resourceId,
60
- networkId,
61
- runtimeContext
62
- }) {
63
- try {
64
- const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
65
- if (!memory) {
66
- throw new HTTPException(400, { message: "Memory is not initialized" });
67
- }
68
- validateBody({ resourceId });
69
- const threads = await memory.getThreadsByResourceId({ resourceId });
70
- return threads;
71
- } catch (error) {
72
- return handleError(error, "Error getting threads");
73
- }
74
- }
75
- async function getThreadByIdHandler({
76
- mastra,
77
- agentId,
78
- threadId,
79
- networkId,
80
- runtimeContext
81
- }) {
82
- try {
83
- validateBody({ threadId });
84
- const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
85
- if (!memory) {
86
- throw new HTTPException(400, { message: "Memory is not initialized" });
87
- }
88
- const thread = await memory.getThreadById({ threadId });
89
- if (!thread) {
90
- throw new HTTPException(404, { message: "Thread not found" });
91
- }
92
- return thread;
93
- } catch (error) {
94
- return handleError(error, "Error getting thread");
95
- }
96
- }
97
- async function saveMessagesHandler({
98
- mastra,
99
- agentId,
100
- body,
101
- networkId,
102
- runtimeContext
103
- }) {
104
- try {
105
- const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
106
- if (!memory) {
107
- throw new HTTPException(400, { message: "Memory is not initialized" });
108
- }
109
- if (!body?.messages) {
110
- throw new HTTPException(400, { message: "Messages are required" });
111
- }
112
- if (!Array.isArray(body.messages)) {
113
- throw new HTTPException(400, { message: "Messages should be an array" });
114
- }
115
- const processedMessages = body.messages.map((message) => ({
116
- ...message,
117
- id: memory.generateId(),
118
- createdAt: message.createdAt ? new Date(message.createdAt) : /* @__PURE__ */ new Date()
119
- }));
120
- const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
121
- return result;
122
- } catch (error) {
123
- return handleError(error, "Error saving messages");
124
- }
125
- }
126
- async function createThreadHandler({
127
- mastra,
128
- agentId,
129
- body,
130
- networkId,
131
- runtimeContext
132
- }) {
133
- try {
134
- const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
135
- if (!memory) {
136
- throw new HTTPException(400, { message: "Memory is not initialized" });
137
- }
138
- validateBody({ resourceId: body?.resourceId });
139
- const result = await memory.createThread({
140
- resourceId: body?.resourceId,
141
- title: body?.title,
142
- metadata: body?.metadata,
143
- threadId: body?.threadId
144
- });
145
- return result;
146
- } catch (error) {
147
- return handleError(error, "Error saving thread to memory");
148
- }
149
- }
150
- async function updateThreadHandler({
151
- mastra,
152
- agentId,
153
- threadId,
154
- body,
155
- networkId,
156
- runtimeContext
157
- }) {
158
- try {
159
- const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
160
- if (!body) {
161
- throw new HTTPException(400, { message: "Body is required" });
162
- }
163
- const { title, metadata, resourceId } = body;
164
- const updatedAt = /* @__PURE__ */ new Date();
165
- validateBody({ threadId });
166
- if (!memory) {
167
- throw new HTTPException(400, { message: "Memory is not initialized" });
168
- }
169
- const thread = await memory.getThreadById({ threadId });
170
- if (!thread) {
171
- throw new HTTPException(404, { message: "Thread not found" });
172
- }
173
- const updatedThread = {
174
- ...thread,
175
- title: title || thread.title,
176
- metadata: metadata || thread.metadata,
177
- resourceId: resourceId || thread.resourceId,
178
- createdAt: thread.createdAt,
179
- updatedAt
180
- };
181
- const result = await memory.saveThread({ thread: updatedThread });
182
- return result;
183
- } catch (error) {
184
- return handleError(error, "Error updating thread");
185
- }
186
- }
187
- async function deleteThreadHandler({
188
- mastra,
189
- agentId,
190
- threadId,
191
- networkId,
192
- runtimeContext
193
- }) {
194
- try {
195
- validateBody({ threadId });
196
- const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
197
- if (!memory) {
198
- throw new HTTPException(400, { message: "Memory is not initialized" });
199
- }
200
- const thread = await memory.getThreadById({ threadId });
201
- if (!thread) {
202
- throw new HTTPException(404, { message: "Thread not found" });
203
- }
204
- await memory.deleteThread(threadId);
205
- return { result: "Thread deleted" };
206
- } catch (error) {
207
- return handleError(error, "Error deleting thread");
208
- }
209
- }
210
- async function getMessagesHandler({
211
- mastra,
212
- agentId,
213
- threadId,
214
- limit,
215
- networkId,
216
- runtimeContext
217
- }) {
218
- if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
219
- throw new HTTPException(400, { message: "Invalid limit: must be a positive integer" });
220
- }
221
- try {
222
- validateBody({ threadId });
223
- const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
224
- if (!memory) {
225
- throw new HTTPException(400, { message: "Memory is not initialized" });
226
- }
227
- const thread = await memory.getThreadById({ threadId });
228
- if (!thread) {
229
- throw new HTTPException(404, { message: "Thread not found" });
230
- }
231
- const result = await memory.query({
232
- threadId,
233
- ...limit && { selectBy: { last: limit } }
234
- });
235
- return { messages: result.messages, uiMessages: result.uiMessages };
236
- } catch (error) {
237
- return handleError(error, "Error getting messages");
238
- }
239
- }
240
-
241
- export { createThreadHandler, deleteThreadHandler, getMemoryStatusHandler, getMessagesHandler, getThreadByIdHandler, getThreadsHandler, memory_exports, saveMessagesHandler, updateThreadHandler };
@@ -1,7 +0,0 @@
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 };
@@ -1,16 +0,0 @@
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;
@@ -1,86 +0,0 @@
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;
@@ -1,141 +0,0 @@
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 };
@@ -1,118 +0,0 @@
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;
@@ -1,16 +0,0 @@
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 };