@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,100 @@
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
+ var stream = require('stream');
7
+
8
+ // src/server/handlers/voice.ts
9
+ var voice_exports = {};
10
+ chunkFV45V6WC_cjs.__export(voice_exports, {
11
+ generateSpeechHandler: () => generateSpeechHandler,
12
+ getSpeakersHandler: () => getSpeakersHandler,
13
+ transcribeSpeechHandler: () => transcribeSpeechHandler
14
+ });
15
+ async function getSpeakersHandler({ mastra, agentId }) {
16
+ try {
17
+ if (!agentId) {
18
+ throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Agent ID is required" });
19
+ }
20
+ const agent = mastra.getAgent(agentId);
21
+ if (!agent) {
22
+ throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Agent not found" });
23
+ }
24
+ if (!agent.voice) {
25
+ throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
26
+ }
27
+ const speakers = await agent.voice.getSpeakers();
28
+ return speakers;
29
+ } catch (error) {
30
+ return chunkZLBRQFDD_cjs.handleError(error, "Error getting speakers");
31
+ }
32
+ }
33
+ async function generateSpeechHandler({
34
+ mastra,
35
+ agentId,
36
+ body
37
+ }) {
38
+ try {
39
+ if (!agentId) {
40
+ throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Agent ID is required" });
41
+ }
42
+ chunkQN4KF3BH_cjs.validateBody({
43
+ text: void 0,
44
+ speakerId: void 0,
45
+ ...body
46
+ });
47
+ const agent = mastra.getAgent(agentId);
48
+ if (!agent) {
49
+ throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Agent not found" });
50
+ }
51
+ if (!agent.voice) {
52
+ throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
53
+ }
54
+ const audioStream = await agent.voice.speak(body.text, { speaker: body.speakerId });
55
+ if (!audioStream) {
56
+ throw new chunkFV45V6WC_cjs.HTTPException(500, { message: "Failed to generate speech" });
57
+ }
58
+ const chunks = [];
59
+ for await (const chunk of audioStream) {
60
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
61
+ }
62
+ const audioData = Buffer.concat(chunks);
63
+ return { audioData };
64
+ } catch (error) {
65
+ return chunkZLBRQFDD_cjs.handleError(error, "Error generating speech");
66
+ }
67
+ }
68
+ async function transcribeSpeechHandler({
69
+ mastra,
70
+ agentId,
71
+ body
72
+ }) {
73
+ try {
74
+ if (!agentId) {
75
+ throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Agent ID is required" });
76
+ }
77
+ if (!body?.audioData) {
78
+ throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Audio data is required" });
79
+ }
80
+ const agent = mastra.getAgent(agentId);
81
+ if (!agent) {
82
+ throw new chunkFV45V6WC_cjs.HTTPException(404, { message: "Agent not found" });
83
+ }
84
+ if (!agent.voice) {
85
+ throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
86
+ }
87
+ const audioStream = new stream.Readable();
88
+ audioStream.push(body.audioData);
89
+ audioStream.push(null);
90
+ const text = await agent.voice.listen(audioStream, body.options);
91
+ return { text };
92
+ } catch (error) {
93
+ return chunkZLBRQFDD_cjs.handleError(error, "Error transcribing speech");
94
+ }
95
+ }
96
+
97
+ exports.generateSpeechHandler = generateSpeechHandler;
98
+ exports.getSpeakersHandler = getSpeakersHandler;
99
+ exports.transcribeSpeechHandler = transcribeSpeechHandler;
100
+ exports.voice_exports = voice_exports;
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __export = (target, all) => {
5
+ for (var name in all)
6
+ __defProp(target, name, { get: all[name], enumerable: true });
7
+ };
8
+
9
+ // src/server/http-exception.ts
10
+ var HTTPException = class extends Error {
11
+ res;
12
+ status;
13
+ /**
14
+ * Creates an instance of `HTTPException`.
15
+ * @param status - HTTP status code for the exception. Defaults to 500.
16
+ * @param options - Additional options for the exception.
17
+ */
18
+ constructor(status = 500, options) {
19
+ super(options?.message, { cause: options?.cause });
20
+ this.res = options?.res;
21
+ this.status = status;
22
+ }
23
+ /**
24
+ * Returns the response object associated with the exception.
25
+ * If a response object is not provided, a new response is created with the error message and status code.
26
+ * @returns The response object.
27
+ */
28
+ getResponse() {
29
+ if (this.res) {
30
+ const newResponse = new Response(this.res.body, {
31
+ status: this.status,
32
+ headers: this.res.headers
33
+ });
34
+ return newResponse;
35
+ }
36
+ return new Response(this.message, {
37
+ status: this.status
38
+ });
39
+ }
40
+ };
41
+
42
+ exports.HTTPException = HTTPException;
43
+ exports.__export = __export;
@@ -0,0 +1,16 @@
1
+ import { HTTPException } from './chunk-TRDNDNGQ.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 };
@@ -0,0 +1,128 @@
1
+ 'use strict';
2
+
3
+ var chunkZLBRQFDD_cjs = require('./chunk-ZLBRQFDD.cjs');
4
+ var chunkFV45V6WC_cjs = require('./chunk-FV45V6WC.cjs');
5
+
6
+ // src/server/handlers/vector.ts
7
+ var vector_exports = {};
8
+ chunkFV45V6WC_cjs.__export(vector_exports, {
9
+ createIndex: () => createIndex,
10
+ deleteIndex: () => deleteIndex,
11
+ describeIndex: () => describeIndex,
12
+ listIndexes: () => listIndexes,
13
+ queryVectors: () => queryVectors,
14
+ upsertVectors: () => upsertVectors
15
+ });
16
+ function getVector(mastra, vectorName) {
17
+ if (!vectorName) {
18
+ throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Vector name is required" });
19
+ }
20
+ const vector = mastra.getVector(vectorName);
21
+ if (!vector) {
22
+ throw new chunkFV45V6WC_cjs.HTTPException(404, { message: `Vector store ${vectorName} not found` });
23
+ }
24
+ return vector;
25
+ }
26
+ async function upsertVectors({ mastra, vectorName, index }) {
27
+ try {
28
+ if (!index?.indexName || !index?.vectors || !Array.isArray(index.vectors)) {
29
+ throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Invalid request index. indexName and vectors array are required." });
30
+ }
31
+ const vector = getVector(mastra, vectorName);
32
+ const result = await vector.upsert(index);
33
+ return { ids: result };
34
+ } catch (error) {
35
+ return chunkZLBRQFDD_cjs.handleError(error, "Error upserting vectors");
36
+ }
37
+ }
38
+ async function createIndex({
39
+ mastra,
40
+ vectorName,
41
+ index
42
+ }) {
43
+ try {
44
+ const { indexName, dimension, metric } = index;
45
+ if (!indexName || typeof dimension !== "number" || dimension <= 0) {
46
+ throw new chunkFV45V6WC_cjs.HTTPException(400, {
47
+ message: "Invalid request index, indexName and positive dimension number are required."
48
+ });
49
+ }
50
+ if (metric && !["cosine", "euclidean", "dotproduct"].includes(metric)) {
51
+ throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Invalid metric. Must be one of: cosine, euclidean, dotproduct" });
52
+ }
53
+ const vector = getVector(mastra, vectorName);
54
+ await vector.createIndex({ indexName, dimension, metric });
55
+ return { success: true };
56
+ } catch (error) {
57
+ return chunkZLBRQFDD_cjs.handleError(error, "Error creating index");
58
+ }
59
+ }
60
+ async function queryVectors({
61
+ mastra,
62
+ vectorName,
63
+ query
64
+ }) {
65
+ try {
66
+ if (!query?.indexName || !query?.queryVector || !Array.isArray(query.queryVector)) {
67
+ throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Invalid request query. indexName and queryVector array are required." });
68
+ }
69
+ const vector = getVector(mastra, vectorName);
70
+ const results = await vector.query(query);
71
+ return results;
72
+ } catch (error) {
73
+ return chunkZLBRQFDD_cjs.handleError(error, "Error querying vectors");
74
+ }
75
+ }
76
+ async function listIndexes({ mastra, vectorName }) {
77
+ try {
78
+ const vector = getVector(mastra, vectorName);
79
+ const indexes = await vector.listIndexes();
80
+ return indexes.filter(Boolean);
81
+ } catch (error) {
82
+ return chunkZLBRQFDD_cjs.handleError(error, "Error listing indexes");
83
+ }
84
+ }
85
+ async function describeIndex({
86
+ mastra,
87
+ vectorName,
88
+ indexName
89
+ }) {
90
+ try {
91
+ if (!indexName) {
92
+ throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Index name is required" });
93
+ }
94
+ const vector = getVector(mastra, vectorName);
95
+ const stats = await vector.describeIndex(indexName);
96
+ return {
97
+ dimension: stats.dimension,
98
+ count: stats.count,
99
+ metric: stats.metric?.toLowerCase()
100
+ };
101
+ } catch (error) {
102
+ return chunkZLBRQFDD_cjs.handleError(error, "Error describing index");
103
+ }
104
+ }
105
+ async function deleteIndex({
106
+ mastra,
107
+ vectorName,
108
+ indexName
109
+ }) {
110
+ try {
111
+ if (!indexName) {
112
+ throw new chunkFV45V6WC_cjs.HTTPException(400, { message: "Index name is required" });
113
+ }
114
+ const vector = getVector(mastra, vectorName);
115
+ await vector.deleteIndex(indexName);
116
+ return { success: true };
117
+ } catch (error) {
118
+ return chunkZLBRQFDD_cjs.handleError(error, "Error deleting index");
119
+ }
120
+ }
121
+
122
+ exports.createIndex = createIndex;
123
+ exports.deleteIndex = deleteIndex;
124
+ exports.describeIndex = describeIndex;
125
+ exports.listIndexes = listIndexes;
126
+ exports.queryVectors = queryVectors;
127
+ exports.upsertVectors = upsertVectors;
128
+ exports.vector_exports = vector_exports;