@mastra/server 0.0.1-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 (83) hide show
  1. package/LICENSE +44 -0
  2. package/README.md +159 -0
  3. package/dist/_tsup-dts-rollup.d.cts +592 -0
  4. package/dist/_tsup-dts-rollup.d.ts +592 -0
  5. package/dist/chunk-2FJURXCL.cjs +213 -0
  6. package/dist/chunk-2JQC6JWP.js +46 -0
  7. package/dist/chunk-2YONKUWB.js +117 -0
  8. package/dist/chunk-3AHQ5RGN.js +11 -0
  9. package/dist/chunk-3RVHWGWO.js +95 -0
  10. package/dist/chunk-4C3EPMMF.cjs +122 -0
  11. package/dist/chunk-4JINXASC.js +120 -0
  12. package/dist/chunk-5JOF627H.cjs +123 -0
  13. package/dist/chunk-5MCUD7TP.js +142 -0
  14. package/dist/chunk-5WF7YIIE.cjs +150 -0
  15. package/dist/chunk-A4DCRMIV.js +125 -0
  16. package/dist/chunk-A7DF4ETD.cjs +100 -0
  17. package/dist/chunk-FV45V6WC.cjs +43 -0
  18. package/dist/chunk-L7XE5QTW.js +16 -0
  19. package/dist/chunk-M56ECCHK.cjs +128 -0
  20. package/dist/chunk-QH6XWSXP.cjs +5579 -0
  21. package/dist/chunk-QN4KF3BH.cjs +18 -0
  22. package/dist/chunk-RBQASTUP.js +203 -0
  23. package/dist/chunk-S6GTZWMY.js +275 -0
  24. package/dist/chunk-SKKC3EDG.cjs +286 -0
  25. package/dist/chunk-TRDNDNGQ.js +40 -0
  26. package/dist/chunk-VB7KH62D.cjs +51 -0
  27. package/dist/chunk-VK6FX47H.js +5576 -0
  28. package/dist/chunk-YCJ2OJTL.cjs +129 -0
  29. package/dist/chunk-YNSGUC2O.js +116 -0
  30. package/dist/chunk-ZLBRQFDD.cjs +13 -0
  31. package/dist/index.cjs +2 -0
  32. package/dist/index.d.cts +1 -0
  33. package/dist/index.d.ts +1 -0
  34. package/dist/index.js +1 -0
  35. package/dist/server/handlers/agents.cjs +30 -0
  36. package/dist/server/handlers/agents.d.cts +6 -0
  37. package/dist/server/handlers/agents.d.ts +6 -0
  38. package/dist/server/handlers/agents.js +1 -0
  39. package/dist/server/handlers/error.cjs +10 -0
  40. package/dist/server/handlers/error.d.cts +1 -0
  41. package/dist/server/handlers/error.d.ts +1 -0
  42. package/dist/server/handlers/error.js +1 -0
  43. package/dist/server/handlers/logs.cjs +18 -0
  44. package/dist/server/handlers/logs.d.cts +3 -0
  45. package/dist/server/handlers/logs.d.ts +3 -0
  46. package/dist/server/handlers/logs.js +1 -0
  47. package/dist/server/handlers/memory.cjs +38 -0
  48. package/dist/server/handlers/memory.d.cts +8 -0
  49. package/dist/server/handlers/memory.d.ts +8 -0
  50. package/dist/server/handlers/memory.js +1 -0
  51. package/dist/server/handlers/network.cjs +22 -0
  52. package/dist/server/handlers/network.d.cts +4 -0
  53. package/dist/server/handlers/network.d.ts +4 -0
  54. package/dist/server/handlers/network.js +1 -0
  55. package/dist/server/handlers/telemetry.cjs +14 -0
  56. package/dist/server/handlers/telemetry.d.cts +2 -0
  57. package/dist/server/handlers/telemetry.d.ts +2 -0
  58. package/dist/server/handlers/telemetry.js +1 -0
  59. package/dist/server/handlers/tools.cjs +22 -0
  60. package/dist/server/handlers/tools.d.cts +4 -0
  61. package/dist/server/handlers/tools.d.ts +4 -0
  62. package/dist/server/handlers/tools.js +1 -0
  63. package/dist/server/handlers/utils.cjs +10 -0
  64. package/dist/server/handlers/utils.d.cts +1 -0
  65. package/dist/server/handlers/utils.d.ts +1 -0
  66. package/dist/server/handlers/utils.js +1 -0
  67. package/dist/server/handlers/vector.cjs +30 -0
  68. package/dist/server/handlers/vector.d.cts +6 -0
  69. package/dist/server/handlers/vector.d.ts +6 -0
  70. package/dist/server/handlers/vector.js +1 -0
  71. package/dist/server/handlers/voice.cjs +18 -0
  72. package/dist/server/handlers/voice.d.cts +3 -0
  73. package/dist/server/handlers/voice.d.ts +3 -0
  74. package/dist/server/handlers/voice.js +1 -0
  75. package/dist/server/handlers/workflows.cjs +42 -0
  76. package/dist/server/handlers/workflows.d.cts +9 -0
  77. package/dist/server/handlers/workflows.d.ts +9 -0
  78. package/dist/server/handlers/workflows.js +1 -0
  79. package/dist/server/handlers.cjs +50 -0
  80. package/dist/server/handlers.d.cts +9 -0
  81. package/dist/server/handlers.d.ts +9 -0
  82. package/dist/server/handlers.js +9 -0
  83. 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,46 @@
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({ mastra, transportId }) {
13
+ try {
14
+ validateBody({ transportId });
15
+ const logs = await mastra.getLogs(transportId);
16
+ return logs;
17
+ } catch (error) {
18
+ return handleError(error, "Error getting logs");
19
+ }
20
+ }
21
+ async function getLogsByRunIdHandler({
22
+ mastra,
23
+ runId,
24
+ transportId
25
+ }) {
26
+ try {
27
+ validateBody({ runId, transportId });
28
+ const logs = await mastra.getLogsByRunId({ runId, transportId });
29
+ return logs;
30
+ } catch (error) {
31
+ return handleError(error, "Error getting logs by run ID");
32
+ }
33
+ }
34
+ async function getLogTransports({ mastra }) {
35
+ try {
36
+ const logger = mastra.getLogger();
37
+ const transports = logger.transports;
38
+ return {
39
+ transports: transports ? Object.keys(transports) : []
40
+ };
41
+ } catch (error) {
42
+ return handleError(error, "Error getting log Transports");
43
+ }
44
+ }
45
+
46
+ export { getLogTransports, getLogsByRunIdHandler, getLogsHandler, logs_exports };
@@ -0,0 +1,117 @@
1
+ import { validateBody } from './chunk-L7XE5QTW.js';
2
+ import { handleError } from './chunk-3AHQ5RGN.js';
3
+ import { __export, HTTPException } from './chunk-TRDNDNGQ.js';
4
+
5
+ // src/server/handlers/network.ts
6
+ var network_exports = {};
7
+ __export(network_exports, {
8
+ generateHandler: () => generateHandler,
9
+ getNetworkByIdHandler: () => getNetworkByIdHandler,
10
+ getNetworksHandler: () => getNetworksHandler,
11
+ streamGenerateHandler: () => streamGenerateHandler
12
+ });
13
+ async function getNetworksHandler({ mastra }) {
14
+ try {
15
+ const networks = mastra.getNetworks();
16
+ const serializedNetworks = networks.map((network) => {
17
+ const routingAgent = network.getRoutingAgent();
18
+ const agents = network.getAgents();
19
+ return {
20
+ id: network.formatAgentId(routingAgent.name),
21
+ name: routingAgent.name,
22
+ instructions: routingAgent.instructions,
23
+ agents: agents.map((agent) => ({
24
+ name: agent.name,
25
+ provider: agent.llm?.getProvider(),
26
+ modelId: agent.llm?.getModelId()
27
+ })),
28
+ routingModel: {
29
+ provider: routingAgent.llm?.getProvider(),
30
+ modelId: routingAgent.llm?.getModelId()
31
+ }
32
+ };
33
+ });
34
+ return serializedNetworks;
35
+ } catch (error) {
36
+ return handleError(error, "Error getting networks");
37
+ }
38
+ }
39
+ async function getNetworkByIdHandler({ mastra, networkId }) {
40
+ try {
41
+ const networks = mastra.getNetworks();
42
+ const network = networks.find((network2) => {
43
+ const routingAgent2 = network2.getRoutingAgent();
44
+ return network2.formatAgentId(routingAgent2.name) === networkId;
45
+ });
46
+ if (!network) {
47
+ throw new HTTPException(404, { message: "Network not found" });
48
+ }
49
+ const routingAgent = network.getRoutingAgent();
50
+ const agents = network.getAgents();
51
+ const serializedNetwork = {
52
+ id: network.formatAgentId(routingAgent.name),
53
+ name: routingAgent.name,
54
+ instructions: routingAgent.instructions,
55
+ agents: agents.map((agent) => ({
56
+ name: agent.name,
57
+ provider: agent.llm?.getProvider(),
58
+ modelId: agent.llm?.getModelId()
59
+ })),
60
+ routingModel: {
61
+ provider: routingAgent.llm?.getProvider(),
62
+ modelId: routingAgent.llm?.getModelId()
63
+ }
64
+ };
65
+ return serializedNetwork;
66
+ } catch (error) {
67
+ return handleError(error, "Error getting network by ID");
68
+ }
69
+ }
70
+ async function generateHandler({
71
+ mastra,
72
+ networkId,
73
+ body
74
+ }) {
75
+ try {
76
+ const network = mastra.getNetwork(networkId);
77
+ if (!network) {
78
+ throw new HTTPException(404, { message: "Network not found" });
79
+ }
80
+ validateBody({ messages: body.messages });
81
+ const { messages, ...rest } = body;
82
+ const result = await network.generate(messages, rest);
83
+ return result;
84
+ } catch (error) {
85
+ return handleError(error, "Error generating from network");
86
+ }
87
+ }
88
+ async function streamGenerateHandler({
89
+ mastra,
90
+ networkId,
91
+ body
92
+ }) {
93
+ try {
94
+ const network = mastra.getNetwork(networkId);
95
+ if (!network) {
96
+ throw new HTTPException(404, { message: "Network not found" });
97
+ }
98
+ validateBody({ messages: body.messages });
99
+ const { messages, output, ...rest } = body;
100
+ const streamResult = await network.stream(messages, {
101
+ output,
102
+ ...rest
103
+ });
104
+ const streamResponse = output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
105
+ sendUsage: true,
106
+ sendReasoning: true,
107
+ getErrorMessage: (error) => {
108
+ return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
109
+ }
110
+ });
111
+ return streamResponse;
112
+ } catch (error) {
113
+ return handleError(error, "Error streaming from network");
114
+ }
115
+ }
116
+
117
+ export { generateHandler, getNetworkByIdHandler, getNetworksHandler, network_exports, streamGenerateHandler };
@@ -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,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;