@mastra/server 0.0.0-commonjs-20250414101718
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 +571 -0
- package/dist/_tsup-dts-rollup.d.ts +571 -0
- package/dist/chunk-2FJURXCL.cjs +213 -0
- package/dist/chunk-3AHQ5RGN.js +11 -0
- package/dist/chunk-3EJZQ6TQ.js +49 -0
- package/dist/chunk-3RVHWGWO.js +95 -0
- package/dist/chunk-4C3EPMMF.cjs +122 -0
- package/dist/chunk-4JINXASC.js +120 -0
- package/dist/chunk-67WTHYAV.js +156 -0
- package/dist/chunk-A7DF4ETD.cjs +100 -0
- package/dist/chunk-B64YROKU.cjs +317 -0
- package/dist/chunk-CWSDZEZG.cjs +139 -0
- package/dist/chunk-DVPP5S6I.js +135 -0
- package/dist/chunk-FV45V6WC.cjs +43 -0
- package/dist/chunk-JLDXUWK7.cjs +126 -0
- package/dist/chunk-L7XE5QTW.js +16 -0
- package/dist/chunk-M56ECCHK.cjs +128 -0
- package/dist/chunk-OPP7H5TW.js +305 -0
- package/dist/chunk-QH6XWSXP.cjs +5579 -0
- package/dist/chunk-QN4KF3BH.cjs +18 -0
- package/dist/chunk-RBQASTUP.js +203 -0
- package/dist/chunk-SKBVVI24.cjs +54 -0
- package/dist/chunk-TRDNDNGQ.js +40 -0
- package/dist/chunk-VK6FX47H.js +5576 -0
- package/dist/chunk-YANVFOYA.js +120 -0
- package/dist/chunk-YNSGUC2O.js +116 -0
- package/dist/chunk-Z46X3YCB.cjs +164 -0
- package/dist/chunk-ZLBRQFDD.cjs +13 -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/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/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 +50 -0
- package/dist/server/handlers.d.cts +9 -0
- package/dist/server/handlers.d.ts +9 -0
- package/dist/server/handlers.js +9 -0
- package/package.json +71 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkQN4KF3BH_cjs = require('./chunk-QN4KF3BH.cjs');
|
|
4
|
+
var chunkZLBRQFDD_cjs = require('./chunk-ZLBRQFDD.cjs');
|
|
5
|
+
var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
|
|
6
|
+
|
|
7
|
+
// src/server/handlers/memory.ts
|
|
8
|
+
var memory_exports = {};
|
|
9
|
+
chunkFV45V6WC_cjs.__export(memory_exports, {
|
|
10
|
+
createThreadHandler: () => createThreadHandler,
|
|
11
|
+
deleteThreadHandler: () => deleteThreadHandler,
|
|
12
|
+
getMemoryStatusHandler: () => getMemoryStatusHandler,
|
|
13
|
+
getMessagesHandler: () => getMessagesHandler,
|
|
14
|
+
getThreadByIdHandler: () => getThreadByIdHandler,
|
|
15
|
+
getThreadsHandler: () => getThreadsHandler,
|
|
16
|
+
saveMessagesHandler: () => saveMessagesHandler,
|
|
17
|
+
updateThreadHandler: () => updateThreadHandler
|
|
18
|
+
});
|
|
19
|
+
function getMemoryFromContext({
|
|
20
|
+
mastra,
|
|
21
|
+
agentId
|
|
22
|
+
}) {
|
|
23
|
+
const agent = agentId ? mastra.getAgent(agentId) : null;
|
|
24
|
+
if (agentId && !agent) {
|
|
25
|
+
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Agent not found" });
|
|
26
|
+
}
|
|
27
|
+
const memory = agent?.getMemory?.() || mastra.getMemory();
|
|
28
|
+
return memory;
|
|
29
|
+
}
|
|
30
|
+
async function getMemoryStatusHandler({ mastra, agentId }) {
|
|
31
|
+
try {
|
|
32
|
+
const memory = getMemoryFromContext({ mastra, agentId });
|
|
33
|
+
if (!memory) {
|
|
34
|
+
return { result: false };
|
|
35
|
+
}
|
|
36
|
+
return { result: true };
|
|
37
|
+
} catch (error) {
|
|
38
|
+
return chunkZLBRQFDD_cjs.handleError(error, "Error getting memory status");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function getThreadsHandler({
|
|
42
|
+
mastra,
|
|
43
|
+
agentId,
|
|
44
|
+
resourceId
|
|
45
|
+
}) {
|
|
46
|
+
try {
|
|
47
|
+
const memory = getMemoryFromContext({ mastra, agentId });
|
|
48
|
+
if (!memory) {
|
|
49
|
+
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
50
|
+
}
|
|
51
|
+
chunkQN4KF3BH_cjs.validateBody({ resourceId });
|
|
52
|
+
const threads = await memory.getThreadsByResourceId({ resourceId });
|
|
53
|
+
return threads;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
return chunkZLBRQFDD_cjs.handleError(error, "Error getting threads");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function getThreadByIdHandler({
|
|
59
|
+
mastra,
|
|
60
|
+
agentId,
|
|
61
|
+
threadId
|
|
62
|
+
}) {
|
|
63
|
+
try {
|
|
64
|
+
chunkQN4KF3BH_cjs.validateBody({ threadId });
|
|
65
|
+
const memory = getMemoryFromContext({ mastra, agentId });
|
|
66
|
+
if (!memory) {
|
|
67
|
+
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
68
|
+
}
|
|
69
|
+
const thread = await memory.getThreadById({ threadId });
|
|
70
|
+
if (!thread) {
|
|
71
|
+
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Thread not found" });
|
|
72
|
+
}
|
|
73
|
+
return thread;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
return chunkZLBRQFDD_cjs.handleError(error, "Error getting thread");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function saveMessagesHandler({
|
|
79
|
+
mastra,
|
|
80
|
+
agentId,
|
|
81
|
+
body
|
|
82
|
+
}) {
|
|
83
|
+
try {
|
|
84
|
+
const memory = getMemoryFromContext({ mastra, agentId });
|
|
85
|
+
if (!memory) {
|
|
86
|
+
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
87
|
+
}
|
|
88
|
+
if (!body?.messages) {
|
|
89
|
+
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Messages are required" });
|
|
90
|
+
}
|
|
91
|
+
if (!Array.isArray(body.messages)) {
|
|
92
|
+
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Messages should be an array" });
|
|
93
|
+
}
|
|
94
|
+
const processedMessages = body.messages.map((message) => ({
|
|
95
|
+
...message,
|
|
96
|
+
id: memory.generateId(),
|
|
97
|
+
createdAt: message.createdAt ? new Date(message.createdAt) : /* @__PURE__ */ new Date()
|
|
98
|
+
}));
|
|
99
|
+
const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
|
|
100
|
+
return result;
|
|
101
|
+
} catch (error) {
|
|
102
|
+
return chunkZLBRQFDD_cjs.handleError(error, "Error saving messages");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async function createThreadHandler({
|
|
106
|
+
mastra,
|
|
107
|
+
agentId,
|
|
108
|
+
body
|
|
109
|
+
}) {
|
|
110
|
+
try {
|
|
111
|
+
const memory = getMemoryFromContext({ mastra, agentId });
|
|
112
|
+
if (!memory) {
|
|
113
|
+
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
114
|
+
}
|
|
115
|
+
chunkQN4KF3BH_cjs.validateBody({ resourceId: body?.resourceId });
|
|
116
|
+
const result = await memory.createThread({
|
|
117
|
+
resourceId: body?.resourceId,
|
|
118
|
+
title: body?.title,
|
|
119
|
+
metadata: body?.metadata,
|
|
120
|
+
threadId: body?.threadId
|
|
121
|
+
});
|
|
122
|
+
return result;
|
|
123
|
+
} catch (error) {
|
|
124
|
+
return chunkZLBRQFDD_cjs.handleError(error, "Error saving thread to memory");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async function updateThreadHandler({
|
|
128
|
+
mastra,
|
|
129
|
+
agentId,
|
|
130
|
+
threadId,
|
|
131
|
+
body
|
|
132
|
+
}) {
|
|
133
|
+
try {
|
|
134
|
+
const memory = getMemoryFromContext({ mastra, agentId });
|
|
135
|
+
if (!body) {
|
|
136
|
+
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Body is required" });
|
|
137
|
+
}
|
|
138
|
+
const { title, metadata, resourceId } = body;
|
|
139
|
+
const updatedAt = /* @__PURE__ */ new Date();
|
|
140
|
+
chunkQN4KF3BH_cjs.validateBody({ threadId });
|
|
141
|
+
if (!memory) {
|
|
142
|
+
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
143
|
+
}
|
|
144
|
+
const thread = await memory.getThreadById({ threadId });
|
|
145
|
+
if (!thread) {
|
|
146
|
+
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Thread not found" });
|
|
147
|
+
}
|
|
148
|
+
const updatedThread = {
|
|
149
|
+
...thread,
|
|
150
|
+
title: title || thread.title,
|
|
151
|
+
metadata: metadata || thread.metadata,
|
|
152
|
+
resourceId: resourceId || thread.resourceId,
|
|
153
|
+
createdAt: thread.createdAt,
|
|
154
|
+
updatedAt
|
|
155
|
+
};
|
|
156
|
+
const result = await memory.saveThread({ thread: updatedThread });
|
|
157
|
+
return result;
|
|
158
|
+
} catch (error) {
|
|
159
|
+
return chunkZLBRQFDD_cjs.handleError(error, "Error updating thread");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async function deleteThreadHandler({
|
|
163
|
+
mastra,
|
|
164
|
+
agentId,
|
|
165
|
+
threadId
|
|
166
|
+
}) {
|
|
167
|
+
try {
|
|
168
|
+
chunkQN4KF3BH_cjs.validateBody({ threadId });
|
|
169
|
+
const memory = getMemoryFromContext({ mastra, agentId });
|
|
170
|
+
if (!memory) {
|
|
171
|
+
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
172
|
+
}
|
|
173
|
+
const thread = await memory.getThreadById({ threadId });
|
|
174
|
+
if (!thread) {
|
|
175
|
+
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Thread not found" });
|
|
176
|
+
}
|
|
177
|
+
await memory.deleteThread(threadId);
|
|
178
|
+
return { result: "Thread deleted" };
|
|
179
|
+
} catch (error) {
|
|
180
|
+
return chunkZLBRQFDD_cjs.handleError(error, "Error deleting thread");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async function getMessagesHandler({
|
|
184
|
+
mastra,
|
|
185
|
+
agentId,
|
|
186
|
+
threadId
|
|
187
|
+
}) {
|
|
188
|
+
try {
|
|
189
|
+
chunkQN4KF3BH_cjs.validateBody({ threadId });
|
|
190
|
+
const memory = getMemoryFromContext({ mastra, agentId });
|
|
191
|
+
if (!memory) {
|
|
192
|
+
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
193
|
+
}
|
|
194
|
+
const thread = await memory.getThreadById({ threadId });
|
|
195
|
+
if (!thread) {
|
|
196
|
+
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Thread not found" });
|
|
197
|
+
}
|
|
198
|
+
const result = await memory.query({ threadId });
|
|
199
|
+
return result;
|
|
200
|
+
} catch (error) {
|
|
201
|
+
return chunkZLBRQFDD_cjs.handleError(error, "Error getting messages");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
exports.createThreadHandler = createThreadHandler;
|
|
206
|
+
exports.deleteThreadHandler = deleteThreadHandler;
|
|
207
|
+
exports.getMemoryStatusHandler = getMemoryStatusHandler;
|
|
208
|
+
exports.getMessagesHandler = getMessagesHandler;
|
|
209
|
+
exports.getThreadByIdHandler = getThreadByIdHandler;
|
|
210
|
+
exports.getThreadsHandler = getThreadsHandler;
|
|
211
|
+
exports.memory_exports = memory_exports;
|
|
212
|
+
exports.saveMessagesHandler = saveMessagesHandler;
|
|
213
|
+
exports.updateThreadHandler = updateThreadHandler;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HTTPException } from './chunk-TRDNDNGQ.js';
|
|
2
|
+
|
|
3
|
+
// src/server/handlers/error.ts
|
|
4
|
+
function handleError(error, defaultMessage) {
|
|
5
|
+
const apiError = error;
|
|
6
|
+
throw new HTTPException(apiError.status || 500, {
|
|
7
|
+
message: apiError.message || defaultMessage
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { handleError };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { validateBody } from './chunk-L7XE5QTW.js';
|
|
2
|
+
import { handleError } from './chunk-3AHQ5RGN.js';
|
|
3
|
+
import { __export } from './chunk-TRDNDNGQ.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,95 @@
|
|
|
1
|
+
import { validateBody } from './chunk-L7XE5QTW.js';
|
|
2
|
+
import { handleError } from './chunk-3AHQ5RGN.js';
|
|
3
|
+
import { __export, HTTPException } from './chunk-TRDNDNGQ.js';
|
|
4
|
+
import { Readable } from 'stream';
|
|
5
|
+
|
|
6
|
+
// src/server/handlers/voice.ts
|
|
7
|
+
var voice_exports = {};
|
|
8
|
+
__export(voice_exports, {
|
|
9
|
+
generateSpeechHandler: () => generateSpeechHandler,
|
|
10
|
+
getSpeakersHandler: () => getSpeakersHandler,
|
|
11
|
+
transcribeSpeechHandler: () => transcribeSpeechHandler
|
|
12
|
+
});
|
|
13
|
+
async function getSpeakersHandler({ mastra, agentId }) {
|
|
14
|
+
try {
|
|
15
|
+
if (!agentId) {
|
|
16
|
+
throw new HTTPException(400, { message: "Agent ID is required" });
|
|
17
|
+
}
|
|
18
|
+
const agent = mastra.getAgent(agentId);
|
|
19
|
+
if (!agent) {
|
|
20
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
21
|
+
}
|
|
22
|
+
if (!agent.voice) {
|
|
23
|
+
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
24
|
+
}
|
|
25
|
+
const speakers = await agent.voice.getSpeakers();
|
|
26
|
+
return speakers;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
return handleError(error, "Error getting speakers");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function generateSpeechHandler({
|
|
32
|
+
mastra,
|
|
33
|
+
agentId,
|
|
34
|
+
body
|
|
35
|
+
}) {
|
|
36
|
+
try {
|
|
37
|
+
if (!agentId) {
|
|
38
|
+
throw new HTTPException(400, { message: "Agent ID is required" });
|
|
39
|
+
}
|
|
40
|
+
validateBody({
|
|
41
|
+
text: void 0,
|
|
42
|
+
speakerId: void 0,
|
|
43
|
+
...body
|
|
44
|
+
});
|
|
45
|
+
const agent = mastra.getAgent(agentId);
|
|
46
|
+
if (!agent) {
|
|
47
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
48
|
+
}
|
|
49
|
+
if (!agent.voice) {
|
|
50
|
+
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
51
|
+
}
|
|
52
|
+
const audioStream = await agent.voice.speak(body.text, { speaker: body.speakerId });
|
|
53
|
+
if (!audioStream) {
|
|
54
|
+
throw new HTTPException(500, { message: "Failed to generate speech" });
|
|
55
|
+
}
|
|
56
|
+
const chunks = [];
|
|
57
|
+
for await (const chunk of audioStream) {
|
|
58
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
59
|
+
}
|
|
60
|
+
const audioData = Buffer.concat(chunks);
|
|
61
|
+
return { audioData };
|
|
62
|
+
} catch (error) {
|
|
63
|
+
return handleError(error, "Error generating speech");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function transcribeSpeechHandler({
|
|
67
|
+
mastra,
|
|
68
|
+
agentId,
|
|
69
|
+
body
|
|
70
|
+
}) {
|
|
71
|
+
try {
|
|
72
|
+
if (!agentId) {
|
|
73
|
+
throw new HTTPException(400, { message: "Agent ID is required" });
|
|
74
|
+
}
|
|
75
|
+
if (!body?.audioData) {
|
|
76
|
+
throw new HTTPException(400, { message: "Audio data is required" });
|
|
77
|
+
}
|
|
78
|
+
const agent = mastra.getAgent(agentId);
|
|
79
|
+
if (!agent) {
|
|
80
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
81
|
+
}
|
|
82
|
+
if (!agent.voice) {
|
|
83
|
+
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
84
|
+
}
|
|
85
|
+
const audioStream = new Readable();
|
|
86
|
+
audioStream.push(body.audioData);
|
|
87
|
+
audioStream.push(null);
|
|
88
|
+
const text = await agent.voice.listen(audioStream, body.options);
|
|
89
|
+
return { text };
|
|
90
|
+
} catch (error) {
|
|
91
|
+
return handleError(error, "Error transcribing speech");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { generateSpeechHandler, getSpeakersHandler, transcribeSpeechHandler, voice_exports };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkQH6XWSXP_cjs = require('./chunk-QH6XWSXP.cjs');
|
|
4
|
+
var chunkQN4KF3BH_cjs = require('./chunk-QN4KF3BH.cjs');
|
|
5
|
+
var chunkZLBRQFDD_cjs = require('./chunk-ZLBRQFDD.cjs');
|
|
6
|
+
var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
|
|
7
|
+
var tools = require('@mastra/core/tools');
|
|
8
|
+
|
|
9
|
+
// src/server/handlers/tools.ts
|
|
10
|
+
var tools_exports = {};
|
|
11
|
+
chunkFV45V6WC_cjs.__export(tools_exports, {
|
|
12
|
+
executeAgentToolHandler: () => executeAgentToolHandler,
|
|
13
|
+
executeToolHandler: () => executeToolHandler,
|
|
14
|
+
getToolByIdHandler: () => getToolByIdHandler,
|
|
15
|
+
getToolsHandler: () => getToolsHandler
|
|
16
|
+
});
|
|
17
|
+
async function getToolsHandler({ tools }) {
|
|
18
|
+
try {
|
|
19
|
+
if (!tools) {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
const serializedTools = Object.entries(tools).reduce(
|
|
23
|
+
(acc, [id, _tool]) => {
|
|
24
|
+
const tool = _tool;
|
|
25
|
+
acc[id] = {
|
|
26
|
+
...tool,
|
|
27
|
+
inputSchema: tool.inputSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(tool.inputSchema)) : void 0,
|
|
28
|
+
outputSchema: tool.outputSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(tool.outputSchema)) : void 0
|
|
29
|
+
};
|
|
30
|
+
return acc;
|
|
31
|
+
},
|
|
32
|
+
{}
|
|
33
|
+
);
|
|
34
|
+
return serializedTools;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
return chunkZLBRQFDD_cjs.handleError(error, "Error getting tools");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function getToolByIdHandler({ tools, toolId }) {
|
|
40
|
+
try {
|
|
41
|
+
const tool = Object.values(tools || {}).find((tool2) => tool2.id === toolId);
|
|
42
|
+
if (!tool) {
|
|
43
|
+
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Tool not found" });
|
|
44
|
+
}
|
|
45
|
+
const serializedTool = {
|
|
46
|
+
...tool,
|
|
47
|
+
inputSchema: tool.inputSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(tool.inputSchema)) : void 0,
|
|
48
|
+
outputSchema: tool.outputSchema ? chunkQH6XWSXP_cjs.stringify(chunkQH6XWSXP_cjs.esm_default(tool.outputSchema)) : void 0
|
|
49
|
+
};
|
|
50
|
+
return serializedTool;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
return chunkZLBRQFDD_cjs.handleError(error, "Error getting tool");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function executeToolHandler(tools$1) {
|
|
56
|
+
return async ({
|
|
57
|
+
mastra,
|
|
58
|
+
runId,
|
|
59
|
+
toolId,
|
|
60
|
+
data
|
|
61
|
+
}) => {
|
|
62
|
+
try {
|
|
63
|
+
if (!toolId) {
|
|
64
|
+
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Tool ID is required" });
|
|
65
|
+
}
|
|
66
|
+
const tool = Object.values(tools$1 || {}).find((tool2) => tool2.id === toolId);
|
|
67
|
+
if (!tool) {
|
|
68
|
+
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Tool not found" });
|
|
69
|
+
}
|
|
70
|
+
if (!tool?.execute) {
|
|
71
|
+
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Tool is not executable" });
|
|
72
|
+
}
|
|
73
|
+
chunkQN4KF3BH_cjs.validateBody({ data });
|
|
74
|
+
if (tools.isVercelTool(tool)) {
|
|
75
|
+
const result2 = await tool.execute(data);
|
|
76
|
+
return result2;
|
|
77
|
+
}
|
|
78
|
+
const result = await tool.execute({
|
|
79
|
+
context: data,
|
|
80
|
+
mastra,
|
|
81
|
+
runId
|
|
82
|
+
});
|
|
83
|
+
return result;
|
|
84
|
+
} catch (error) {
|
|
85
|
+
return chunkZLBRQFDD_cjs.handleError(error, "Error executing tool");
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
async function executeAgentToolHandler({
|
|
90
|
+
mastra,
|
|
91
|
+
agentId,
|
|
92
|
+
toolId,
|
|
93
|
+
data
|
|
94
|
+
}) {
|
|
95
|
+
try {
|
|
96
|
+
const agent = agentId ? mastra.getAgent(agentId) : null;
|
|
97
|
+
if (!agent) {
|
|
98
|
+
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Tool not found" });
|
|
99
|
+
}
|
|
100
|
+
const tool = Object.values(agent?.tools || {}).find((tool2) => tool2.id === toolId);
|
|
101
|
+
if (!tool) {
|
|
102
|
+
throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Tool not found" });
|
|
103
|
+
}
|
|
104
|
+
if (!tool?.execute) {
|
|
105
|
+
throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Tool is not executable" });
|
|
106
|
+
}
|
|
107
|
+
const result = await tool.execute({
|
|
108
|
+
context: data,
|
|
109
|
+
mastra,
|
|
110
|
+
runId: agentId
|
|
111
|
+
});
|
|
112
|
+
return result;
|
|
113
|
+
} catch (error) {
|
|
114
|
+
return chunkZLBRQFDD_cjs.handleError(error, "Error executing tool");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
exports.executeAgentToolHandler = executeAgentToolHandler;
|
|
119
|
+
exports.executeToolHandler = executeToolHandler;
|
|
120
|
+
exports.getToolByIdHandler = getToolByIdHandler;
|
|
121
|
+
exports.getToolsHandler = getToolsHandler;
|
|
122
|
+
exports.tools_exports = tools_exports;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { handleError } from './chunk-3AHQ5RGN.js';
|
|
2
|
+
import { __export, HTTPException } from './chunk-TRDNDNGQ.js';
|
|
3
|
+
|
|
4
|
+
// src/server/handlers/vector.ts
|
|
5
|
+
var vector_exports = {};
|
|
6
|
+
__export(vector_exports, {
|
|
7
|
+
createIndex: () => createIndex,
|
|
8
|
+
deleteIndex: () => deleteIndex,
|
|
9
|
+
describeIndex: () => describeIndex,
|
|
10
|
+
listIndexes: () => listIndexes,
|
|
11
|
+
queryVectors: () => queryVectors,
|
|
12
|
+
upsertVectors: () => upsertVectors
|
|
13
|
+
});
|
|
14
|
+
function getVector(mastra, vectorName) {
|
|
15
|
+
if (!vectorName) {
|
|
16
|
+
throw new HTTPException(400, { message: "Vector name is required" });
|
|
17
|
+
}
|
|
18
|
+
const vector = mastra.getVector(vectorName);
|
|
19
|
+
if (!vector) {
|
|
20
|
+
throw new HTTPException(404, { message: `Vector store ${vectorName} not found` });
|
|
21
|
+
}
|
|
22
|
+
return vector;
|
|
23
|
+
}
|
|
24
|
+
async function upsertVectors({ mastra, vectorName, index }) {
|
|
25
|
+
try {
|
|
26
|
+
if (!index?.indexName || !index?.vectors || !Array.isArray(index.vectors)) {
|
|
27
|
+
throw new HTTPException(400, { message: "Invalid request index. indexName and vectors array are required." });
|
|
28
|
+
}
|
|
29
|
+
const vector = getVector(mastra, vectorName);
|
|
30
|
+
const result = await vector.upsert(index);
|
|
31
|
+
return { ids: result };
|
|
32
|
+
} catch (error) {
|
|
33
|
+
return handleError(error, "Error upserting vectors");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function createIndex({
|
|
37
|
+
mastra,
|
|
38
|
+
vectorName,
|
|
39
|
+
index
|
|
40
|
+
}) {
|
|
41
|
+
try {
|
|
42
|
+
const { indexName, dimension, metric } = index;
|
|
43
|
+
if (!indexName || typeof dimension !== "number" || dimension <= 0) {
|
|
44
|
+
throw new HTTPException(400, {
|
|
45
|
+
message: "Invalid request index, indexName and positive dimension number are required."
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (metric && !["cosine", "euclidean", "dotproduct"].includes(metric)) {
|
|
49
|
+
throw new HTTPException(400, { message: "Invalid metric. Must be one of: cosine, euclidean, dotproduct" });
|
|
50
|
+
}
|
|
51
|
+
const vector = getVector(mastra, vectorName);
|
|
52
|
+
await vector.createIndex({ indexName, dimension, metric });
|
|
53
|
+
return { success: true };
|
|
54
|
+
} catch (error) {
|
|
55
|
+
return handleError(error, "Error creating index");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function queryVectors({
|
|
59
|
+
mastra,
|
|
60
|
+
vectorName,
|
|
61
|
+
query
|
|
62
|
+
}) {
|
|
63
|
+
try {
|
|
64
|
+
if (!query?.indexName || !query?.queryVector || !Array.isArray(query.queryVector)) {
|
|
65
|
+
throw new HTTPException(400, { message: "Invalid request query. indexName and queryVector array are required." });
|
|
66
|
+
}
|
|
67
|
+
const vector = getVector(mastra, vectorName);
|
|
68
|
+
const results = await vector.query(query);
|
|
69
|
+
return results;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
return handleError(error, "Error querying vectors");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function listIndexes({ mastra, vectorName }) {
|
|
75
|
+
try {
|
|
76
|
+
const vector = getVector(mastra, vectorName);
|
|
77
|
+
const indexes = await vector.listIndexes();
|
|
78
|
+
return indexes.filter(Boolean);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
return handleError(error, "Error listing indexes");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async function describeIndex({
|
|
84
|
+
mastra,
|
|
85
|
+
vectorName,
|
|
86
|
+
indexName
|
|
87
|
+
}) {
|
|
88
|
+
try {
|
|
89
|
+
if (!indexName) {
|
|
90
|
+
throw new HTTPException(400, { message: "Index name is required" });
|
|
91
|
+
}
|
|
92
|
+
const vector = getVector(mastra, vectorName);
|
|
93
|
+
const stats = await vector.describeIndex(indexName);
|
|
94
|
+
return {
|
|
95
|
+
dimension: stats.dimension,
|
|
96
|
+
count: stats.count,
|
|
97
|
+
metric: stats.metric?.toLowerCase()
|
|
98
|
+
};
|
|
99
|
+
} catch (error) {
|
|
100
|
+
return handleError(error, "Error describing index");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async function deleteIndex({
|
|
104
|
+
mastra,
|
|
105
|
+
vectorName,
|
|
106
|
+
indexName
|
|
107
|
+
}) {
|
|
108
|
+
try {
|
|
109
|
+
if (!indexName) {
|
|
110
|
+
throw new HTTPException(400, { message: "Index name is required" });
|
|
111
|
+
}
|
|
112
|
+
const vector = getVector(mastra, vectorName);
|
|
113
|
+
await vector.deleteIndex(indexName);
|
|
114
|
+
return { success: true };
|
|
115
|
+
} catch (error) {
|
|
116
|
+
return handleError(error, "Error deleting index");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export { createIndex, deleteIndex, describeIndex, listIndexes, queryVectors, upsertVectors, vector_exports };
|