@mastra/server 0.0.1-alpha.6 → 0.10.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.
- package/{LICENSE → LICENSE.md} +3 -1
- package/README.md +48 -135
- package/dist/_tsup-dts-rollup.d.cts +305 -52
- package/dist/_tsup-dts-rollup.d.ts +305 -52
- package/dist/{chunk-4JINXASC.js → chunk-55DOQLP6.js} +5 -4
- package/dist/{chunk-QN4KF3BH.cjs → chunk-57CJTIPW.cjs} +2 -2
- package/dist/chunk-5SN4U5AC.cjs +508 -0
- package/dist/{chunk-ZLBRQFDD.cjs → chunk-64U3UDTH.cjs} +2 -2
- package/dist/chunk-6B4OMWT6.cjs +343 -0
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/{chunk-VB7KH62D.cjs → chunk-7DLZLWJV.cjs} +16 -12
- package/dist/{chunk-M56ECCHK.cjs → chunk-BNEY4P4P.cjs} +20 -19
- package/dist/{chunk-2YONKUWB.js → chunk-C7564HUT.js} +58 -33
- package/dist/chunk-D4IRYCUI.cjs +235 -0
- package/dist/{chunk-RBQASTUP.js → chunk-DJJIUEL2.js} +13 -5
- package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
- package/dist/{chunk-3RVHWGWO.js → chunk-HFWCEP5S.js} +6 -12
- package/dist/chunk-LIVAK2DM.js +2001 -0
- package/dist/{chunk-3AHQ5RGN.js → chunk-M5ABIP7D.js} +1 -1
- package/dist/{chunk-CWSDZEZG.cjs → chunk-MHKNLNAN.cjs} +15 -12
- package/dist/chunk-MLKGABMK.js +7 -0
- package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
- package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
- package/dist/{chunk-DVPP5S6I.js → chunk-OR3CIE2H.js} +9 -6
- package/dist/chunk-P6SCPDYW.js +500 -0
- package/dist/chunk-QY36IPTP.js +331 -0
- package/dist/{chunk-YNSGUC2O.js → chunk-TJKLBTFB.js} +23 -7
- package/dist/chunk-VPNDC2DI.cjs +148 -0
- package/dist/{chunk-ILW7XYNJ.js → chunk-W7VCKPAD.js} +84 -60
- package/dist/{chunk-2JQC6JWP.js → chunk-WFBJJNCK.js} +10 -6
- package/dist/chunk-WUC6LSTW.js +227 -0
- package/dist/{chunk-2FJURXCL.cjs → chunk-Y7UWRW5X.cjs} +43 -35
- package/dist/{chunk-A7DF4ETD.cjs → chunk-YBVOQN4M.cjs} +22 -28
- package/dist/chunk-YIOVBYZH.cjs +332 -0
- package/dist/chunk-YWLUOY3D.cjs +2004 -0
- package/dist/{chunk-4C3EPMMF.cjs → chunk-ZE5AAC4I.cjs} +40 -24
- package/dist/server/handlers/a2a.cjs +30 -0
- package/dist/server/handlers/a2a.d.cts +6 -0
- package/dist/server/handlers/a2a.d.ts +6 -0
- package/dist/server/handlers/a2a.js +1 -0
- package/dist/server/handlers/agents.cjs +7 -7
- package/dist/server/handlers/agents.js +1 -1
- package/dist/server/handlers/error.cjs +2 -2
- package/dist/server/handlers/error.js +1 -1
- package/dist/server/handlers/legacyWorkflows.cjs +46 -0
- package/dist/server/handlers/legacyWorkflows.d.cts +10 -0
- package/dist/server/handlers/legacyWorkflows.d.ts +10 -0
- package/dist/server/handlers/legacyWorkflows.js +1 -0
- package/dist/server/handlers/logs.cjs +4 -4
- package/dist/server/handlers/logs.js +1 -1
- package/dist/server/handlers/memory.cjs +9 -9
- package/dist/server/handlers/memory.js +1 -1
- package/dist/server/handlers/network.cjs +5 -5
- package/dist/server/handlers/network.js +1 -1
- package/dist/server/handlers/telemetry.cjs +3 -3
- package/dist/server/handlers/telemetry.js +1 -1
- package/dist/server/handlers/tools.cjs +5 -5
- package/dist/server/handlers/tools.js +1 -1
- package/dist/server/handlers/utils.cjs +2 -2
- package/dist/server/handlers/utils.js +1 -1
- package/dist/server/handlers/vector.cjs +7 -7
- package/dist/server/handlers/vector.js +1 -1
- package/dist/server/handlers/voice.cjs +4 -4
- package/dist/server/handlers/voice.js +1 -1
- package/dist/server/handlers/workflows.cjs +13 -13
- package/dist/server/handlers/workflows.d.cts +2 -2
- package/dist/server/handlers/workflows.d.ts +2 -2
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +33 -23
- package/dist/server/handlers.d.cts +2 -0
- package/dist/server/handlers.d.ts +2 -0
- package/dist/server/handlers.js +11 -9
- package/package.json +9 -7
- package/dist/chunk-5JOF627H.cjs +0 -123
- package/dist/chunk-BMA2ORRT.js +0 -152
- package/dist/chunk-GV52BII2.cjs +0 -160
- package/dist/chunk-QH6XWSXP.cjs +0 -5579
- package/dist/chunk-VK6FX47H.js +0 -5576
- package/dist/chunk-X37I6GZT.cjs +0 -308
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
|
|
4
|
+
var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
|
|
5
|
+
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
|
|
6
|
+
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
6
7
|
|
|
7
8
|
// src/server/handlers/memory.ts
|
|
8
9
|
var memory_exports = {};
|
|
9
|
-
|
|
10
|
+
chunk75ZPJI57_cjs.__export(memory_exports, {
|
|
10
11
|
createThreadHandler: () => createThreadHandler,
|
|
11
12
|
deleteThreadHandler: () => deleteThreadHandler,
|
|
12
13
|
getMemoryStatusHandler: () => getMemoryStatusHandler,
|
|
@@ -22,7 +23,7 @@ function getMemoryFromContext({
|
|
|
22
23
|
}) {
|
|
23
24
|
const agent = agentId ? mastra.getAgent(agentId) : null;
|
|
24
25
|
if (agentId && !agent) {
|
|
25
|
-
throw new
|
|
26
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
26
27
|
}
|
|
27
28
|
const memory = agent?.getMemory?.() || mastra.getMemory();
|
|
28
29
|
return memory;
|
|
@@ -35,7 +36,7 @@ async function getMemoryStatusHandler({ mastra, agentId }) {
|
|
|
35
36
|
}
|
|
36
37
|
return { result: true };
|
|
37
38
|
} catch (error) {
|
|
38
|
-
return
|
|
39
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting memory status");
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
async function getThreadsHandler({
|
|
@@ -46,13 +47,13 @@ async function getThreadsHandler({
|
|
|
46
47
|
try {
|
|
47
48
|
const memory = getMemoryFromContext({ mastra, agentId });
|
|
48
49
|
if (!memory) {
|
|
49
|
-
throw new
|
|
50
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
50
51
|
}
|
|
51
|
-
|
|
52
|
+
chunk57CJTIPW_cjs.validateBody({ resourceId });
|
|
52
53
|
const threads = await memory.getThreadsByResourceId({ resourceId });
|
|
53
54
|
return threads;
|
|
54
55
|
} catch (error) {
|
|
55
|
-
return
|
|
56
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting threads");
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
async function getThreadByIdHandler({
|
|
@@ -61,18 +62,18 @@ async function getThreadByIdHandler({
|
|
|
61
62
|
threadId
|
|
62
63
|
}) {
|
|
63
64
|
try {
|
|
64
|
-
|
|
65
|
+
chunk57CJTIPW_cjs.validateBody({ threadId });
|
|
65
66
|
const memory = getMemoryFromContext({ mastra, agentId });
|
|
66
67
|
if (!memory) {
|
|
67
|
-
throw new
|
|
68
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
68
69
|
}
|
|
69
70
|
const thread = await memory.getThreadById({ threadId });
|
|
70
71
|
if (!thread) {
|
|
71
|
-
throw new
|
|
72
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
|
|
72
73
|
}
|
|
73
74
|
return thread;
|
|
74
75
|
} catch (error) {
|
|
75
|
-
return
|
|
76
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting thread");
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
async function saveMessagesHandler({
|
|
@@ -83,13 +84,13 @@ async function saveMessagesHandler({
|
|
|
83
84
|
try {
|
|
84
85
|
const memory = getMemoryFromContext({ mastra, agentId });
|
|
85
86
|
if (!memory) {
|
|
86
|
-
throw new
|
|
87
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
87
88
|
}
|
|
88
89
|
if (!body?.messages) {
|
|
89
|
-
throw new
|
|
90
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Messages are required" });
|
|
90
91
|
}
|
|
91
92
|
if (!Array.isArray(body.messages)) {
|
|
92
|
-
throw new
|
|
93
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Messages should be an array" });
|
|
93
94
|
}
|
|
94
95
|
const processedMessages = body.messages.map((message) => ({
|
|
95
96
|
...message,
|
|
@@ -99,7 +100,7 @@ async function saveMessagesHandler({
|
|
|
99
100
|
const result = await memory.saveMessages({ messages: processedMessages, memoryConfig: {} });
|
|
100
101
|
return result;
|
|
101
102
|
} catch (error) {
|
|
102
|
-
return
|
|
103
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error saving messages");
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
async function createThreadHandler({
|
|
@@ -110,9 +111,9 @@ async function createThreadHandler({
|
|
|
110
111
|
try {
|
|
111
112
|
const memory = getMemoryFromContext({ mastra, agentId });
|
|
112
113
|
if (!memory) {
|
|
113
|
-
throw new
|
|
114
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
114
115
|
}
|
|
115
|
-
|
|
116
|
+
chunk57CJTIPW_cjs.validateBody({ resourceId: body?.resourceId });
|
|
116
117
|
const result = await memory.createThread({
|
|
117
118
|
resourceId: body?.resourceId,
|
|
118
119
|
title: body?.title,
|
|
@@ -121,7 +122,7 @@ async function createThreadHandler({
|
|
|
121
122
|
});
|
|
122
123
|
return result;
|
|
123
124
|
} catch (error) {
|
|
124
|
-
return
|
|
125
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error saving thread to memory");
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
async function updateThreadHandler({
|
|
@@ -133,17 +134,17 @@ async function updateThreadHandler({
|
|
|
133
134
|
try {
|
|
134
135
|
const memory = getMemoryFromContext({ mastra, agentId });
|
|
135
136
|
if (!body) {
|
|
136
|
-
throw new
|
|
137
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Body is required" });
|
|
137
138
|
}
|
|
138
139
|
const { title, metadata, resourceId } = body;
|
|
139
140
|
const updatedAt = /* @__PURE__ */ new Date();
|
|
140
|
-
|
|
141
|
+
chunk57CJTIPW_cjs.validateBody({ threadId });
|
|
141
142
|
if (!memory) {
|
|
142
|
-
throw new
|
|
143
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
143
144
|
}
|
|
144
145
|
const thread = await memory.getThreadById({ threadId });
|
|
145
146
|
if (!thread) {
|
|
146
|
-
throw new
|
|
147
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
|
|
147
148
|
}
|
|
148
149
|
const updatedThread = {
|
|
149
150
|
...thread,
|
|
@@ -156,7 +157,7 @@ async function updateThreadHandler({
|
|
|
156
157
|
const result = await memory.saveThread({ thread: updatedThread });
|
|
157
158
|
return result;
|
|
158
159
|
} catch (error) {
|
|
159
|
-
return
|
|
160
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error updating thread");
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
async function deleteThreadHandler({
|
|
@@ -165,40 +166,47 @@ async function deleteThreadHandler({
|
|
|
165
166
|
threadId
|
|
166
167
|
}) {
|
|
167
168
|
try {
|
|
168
|
-
|
|
169
|
+
chunk57CJTIPW_cjs.validateBody({ threadId });
|
|
169
170
|
const memory = getMemoryFromContext({ mastra, agentId });
|
|
170
171
|
if (!memory) {
|
|
171
|
-
throw new
|
|
172
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
172
173
|
}
|
|
173
174
|
const thread = await memory.getThreadById({ threadId });
|
|
174
175
|
if (!thread) {
|
|
175
|
-
throw new
|
|
176
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
|
|
176
177
|
}
|
|
177
178
|
await memory.deleteThread(threadId);
|
|
178
179
|
return { result: "Thread deleted" };
|
|
179
180
|
} catch (error) {
|
|
180
|
-
return
|
|
181
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error deleting thread");
|
|
181
182
|
}
|
|
182
183
|
}
|
|
183
184
|
async function getMessagesHandler({
|
|
184
185
|
mastra,
|
|
185
186
|
agentId,
|
|
186
|
-
threadId
|
|
187
|
+
threadId,
|
|
188
|
+
limit
|
|
187
189
|
}) {
|
|
190
|
+
if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
|
|
191
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Invalid limit: must be a positive integer" });
|
|
192
|
+
}
|
|
188
193
|
try {
|
|
189
|
-
|
|
194
|
+
chunk57CJTIPW_cjs.validateBody({ threadId });
|
|
190
195
|
const memory = getMemoryFromContext({ mastra, agentId });
|
|
191
196
|
if (!memory) {
|
|
192
|
-
throw new
|
|
197
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Memory is not initialized" });
|
|
193
198
|
}
|
|
194
199
|
const thread = await memory.getThreadById({ threadId });
|
|
195
200
|
if (!thread) {
|
|
196
|
-
throw new
|
|
201
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Thread not found" });
|
|
197
202
|
}
|
|
198
|
-
const result = await memory.query({
|
|
203
|
+
const result = await memory.query({
|
|
204
|
+
threadId,
|
|
205
|
+
...limit && { selectBy: { last: limit } }
|
|
206
|
+
});
|
|
199
207
|
return result;
|
|
200
208
|
} catch (error) {
|
|
201
|
-
return
|
|
209
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting messages");
|
|
202
210
|
}
|
|
203
211
|
}
|
|
204
212
|
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunk57CJTIPW_cjs = require('./chunk-57CJTIPW.cjs');
|
|
4
|
+
var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
|
|
5
|
+
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
|
|
6
|
+
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
6
7
|
var stream = require('stream');
|
|
7
8
|
|
|
8
9
|
// src/server/handlers/voice.ts
|
|
9
10
|
var voice_exports = {};
|
|
10
|
-
|
|
11
|
+
chunk75ZPJI57_cjs.__export(voice_exports, {
|
|
11
12
|
generateSpeechHandler: () => generateSpeechHandler,
|
|
12
13
|
getSpeakersHandler: () => getSpeakersHandler,
|
|
13
14
|
transcribeSpeechHandler: () => transcribeSpeechHandler
|
|
@@ -15,19 +16,19 @@ chunkFV45V6WC_cjs.__export(voice_exports, {
|
|
|
15
16
|
async function getSpeakersHandler({ mastra, agentId }) {
|
|
16
17
|
try {
|
|
17
18
|
if (!agentId) {
|
|
18
|
-
throw new
|
|
19
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent ID is required" });
|
|
19
20
|
}
|
|
20
21
|
const agent = mastra.getAgent(agentId);
|
|
21
22
|
if (!agent) {
|
|
22
|
-
throw new
|
|
23
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
23
24
|
}
|
|
24
25
|
if (!agent.voice) {
|
|
25
|
-
throw new
|
|
26
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
26
27
|
}
|
|
27
28
|
const speakers = await agent.voice.getSpeakers();
|
|
28
29
|
return speakers;
|
|
29
30
|
} catch (error) {
|
|
30
|
-
return
|
|
31
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting speakers");
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
async function generateSpeechHandler({
|
|
@@ -37,32 +38,25 @@ async function generateSpeechHandler({
|
|
|
37
38
|
}) {
|
|
38
39
|
try {
|
|
39
40
|
if (!agentId) {
|
|
40
|
-
throw new
|
|
41
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent ID is required" });
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
-
text:
|
|
44
|
-
speakerId: void 0,
|
|
45
|
-
...body
|
|
43
|
+
chunk57CJTIPW_cjs.validateBody({
|
|
44
|
+
text: body?.text
|
|
46
45
|
});
|
|
47
46
|
const agent = mastra.getAgent(agentId);
|
|
48
47
|
if (!agent) {
|
|
49
|
-
throw new
|
|
48
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
50
49
|
}
|
|
51
50
|
if (!agent.voice) {
|
|
52
|
-
throw new
|
|
51
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
53
52
|
}
|
|
54
53
|
const audioStream = await agent.voice.speak(body.text, { speaker: body.speakerId });
|
|
55
54
|
if (!audioStream) {
|
|
56
|
-
throw new
|
|
55
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: "Failed to generate speech" });
|
|
57
56
|
}
|
|
58
|
-
|
|
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 };
|
|
57
|
+
return audioStream;
|
|
64
58
|
} catch (error) {
|
|
65
|
-
return
|
|
59
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error generating speech");
|
|
66
60
|
}
|
|
67
61
|
}
|
|
68
62
|
async function transcribeSpeechHandler({
|
|
@@ -72,17 +66,17 @@ async function transcribeSpeechHandler({
|
|
|
72
66
|
}) {
|
|
73
67
|
try {
|
|
74
68
|
if (!agentId) {
|
|
75
|
-
throw new
|
|
69
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent ID is required" });
|
|
76
70
|
}
|
|
77
71
|
if (!body?.audioData) {
|
|
78
|
-
throw new
|
|
72
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Audio data is required" });
|
|
79
73
|
}
|
|
80
74
|
const agent = mastra.getAgent(agentId);
|
|
81
75
|
if (!agent) {
|
|
82
|
-
throw new
|
|
76
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
83
77
|
}
|
|
84
78
|
if (!agent.voice) {
|
|
85
|
-
throw new
|
|
79
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
86
80
|
}
|
|
87
81
|
const audioStream = new stream.Readable();
|
|
88
82
|
audioStream.push(body.audioData);
|
|
@@ -90,7 +84,7 @@ async function transcribeSpeechHandler({
|
|
|
90
84
|
const text = await agent.voice.listen(audioStream, body.options);
|
|
91
85
|
return { text };
|
|
92
86
|
} catch (error) {
|
|
93
|
-
return
|
|
87
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error transcribing speech");
|
|
94
88
|
}
|
|
95
89
|
}
|
|
96
90
|
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkYWLUOY3D_cjs = require('./chunk-YWLUOY3D.cjs');
|
|
4
|
+
var chunk64U3UDTH_cjs = require('./chunk-64U3UDTH.cjs');
|
|
5
|
+
var chunkOCWPVYNI_cjs = require('./chunk-OCWPVYNI.cjs');
|
|
6
|
+
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
7
|
+
var web = require('stream/web');
|
|
8
|
+
|
|
9
|
+
// src/server/handlers/legacyWorkflows.ts
|
|
10
|
+
var legacyWorkflows_exports = {};
|
|
11
|
+
chunk75ZPJI57_cjs.__export(legacyWorkflows_exports, {
|
|
12
|
+
createLegacyWorkflowRunHandler: () => createLegacyWorkflowRunHandler,
|
|
13
|
+
getLegacyWorkflowByIdHandler: () => getLegacyWorkflowByIdHandler,
|
|
14
|
+
getLegacyWorkflowRunHandler: () => getLegacyWorkflowRunHandler,
|
|
15
|
+
getLegacyWorkflowRunsHandler: () => getLegacyWorkflowRunsHandler,
|
|
16
|
+
getLegacyWorkflowsHandler: () => getLegacyWorkflowsHandler,
|
|
17
|
+
resumeAsyncLegacyWorkflowHandler: () => resumeAsyncLegacyWorkflowHandler,
|
|
18
|
+
resumeLegacyWorkflowHandler: () => resumeLegacyWorkflowHandler,
|
|
19
|
+
startAsyncLegacyWorkflowHandler: () => startAsyncLegacyWorkflowHandler,
|
|
20
|
+
startLegacyWorkflowRunHandler: () => startLegacyWorkflowRunHandler,
|
|
21
|
+
watchLegacyWorkflowHandler: () => watchLegacyWorkflowHandler
|
|
22
|
+
});
|
|
23
|
+
async function getLegacyWorkflowsHandler({ mastra }) {
|
|
24
|
+
try {
|
|
25
|
+
const workflows = mastra.legacy_getWorkflows({ serialized: false });
|
|
26
|
+
const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
|
|
27
|
+
if (workflow.isNested) return acc;
|
|
28
|
+
acc[key] = {
|
|
29
|
+
stepGraph: workflow.stepGraph,
|
|
30
|
+
stepSubscriberGraph: workflow.stepSubscriberGraph,
|
|
31
|
+
serializedStepGraph: workflow.serializedStepGraph,
|
|
32
|
+
serializedStepSubscriberGraph: workflow.serializedStepSubscriberGraph,
|
|
33
|
+
name: workflow.name,
|
|
34
|
+
triggerSchema: workflow.triggerSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(workflow.triggerSchema)) : void 0,
|
|
35
|
+
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
36
|
+
const _step = step;
|
|
37
|
+
acc2[key2] = {
|
|
38
|
+
id: _step.id,
|
|
39
|
+
description: _step.description,
|
|
40
|
+
workflowId: _step.workflowId,
|
|
41
|
+
inputSchema: _step.inputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(_step.inputSchema)) : void 0,
|
|
42
|
+
outputSchema: _step.outputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(_step.outputSchema)) : void 0
|
|
43
|
+
};
|
|
44
|
+
return acc2;
|
|
45
|
+
}, {})
|
|
46
|
+
};
|
|
47
|
+
return acc;
|
|
48
|
+
}, {});
|
|
49
|
+
return _workflows;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflows" });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function getLegacyWorkflowByIdHandler({ mastra, workflowId }) {
|
|
55
|
+
try {
|
|
56
|
+
if (!workflowId) {
|
|
57
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
58
|
+
}
|
|
59
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
60
|
+
if (!workflow) {
|
|
61
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
stepGraph: workflow.stepGraph,
|
|
65
|
+
stepSubscriberGraph: workflow.stepSubscriberGraph,
|
|
66
|
+
serializedStepGraph: workflow.serializedStepGraph,
|
|
67
|
+
serializedStepSubscriberGraph: workflow.serializedStepSubscriberGraph,
|
|
68
|
+
name: workflow.name,
|
|
69
|
+
triggerSchema: workflow.triggerSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(workflow.triggerSchema)) : void 0,
|
|
70
|
+
steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
|
|
71
|
+
const _step = step;
|
|
72
|
+
acc[key] = {
|
|
73
|
+
id: _step.id,
|
|
74
|
+
description: _step.description,
|
|
75
|
+
workflowId: _step.workflowId,
|
|
76
|
+
inputSchema: _step.inputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(_step.inputSchema)) : void 0,
|
|
77
|
+
outputSchema: _step.outputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(_step.outputSchema)) : void 0
|
|
78
|
+
};
|
|
79
|
+
return acc;
|
|
80
|
+
}, {})
|
|
81
|
+
};
|
|
82
|
+
} catch (error) {
|
|
83
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflow" });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function startAsyncLegacyWorkflowHandler({
|
|
87
|
+
mastra,
|
|
88
|
+
runtimeContext,
|
|
89
|
+
workflowId,
|
|
90
|
+
runId,
|
|
91
|
+
triggerData
|
|
92
|
+
}) {
|
|
93
|
+
try {
|
|
94
|
+
if (!workflowId) {
|
|
95
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
96
|
+
}
|
|
97
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
98
|
+
if (!workflow) {
|
|
99
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
100
|
+
}
|
|
101
|
+
if (!runId) {
|
|
102
|
+
const newRun = workflow.createRun();
|
|
103
|
+
const result2 = await newRun.start({
|
|
104
|
+
triggerData,
|
|
105
|
+
runtimeContext
|
|
106
|
+
});
|
|
107
|
+
return result2;
|
|
108
|
+
}
|
|
109
|
+
const run = workflow.getMemoryRun(runId);
|
|
110
|
+
if (!run) {
|
|
111
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
112
|
+
}
|
|
113
|
+
const result = await run.start({
|
|
114
|
+
triggerData,
|
|
115
|
+
runtimeContext
|
|
116
|
+
});
|
|
117
|
+
return result;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error executing workflow" });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async function getLegacyWorkflowRunHandler({
|
|
123
|
+
mastra,
|
|
124
|
+
workflowId,
|
|
125
|
+
runId
|
|
126
|
+
}) {
|
|
127
|
+
try {
|
|
128
|
+
if (!workflowId) {
|
|
129
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
130
|
+
}
|
|
131
|
+
if (!runId) {
|
|
132
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Run ID is required" });
|
|
133
|
+
}
|
|
134
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
135
|
+
if (!workflow) {
|
|
136
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
137
|
+
}
|
|
138
|
+
const run = await workflow.getRun(runId);
|
|
139
|
+
if (!run) {
|
|
140
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
141
|
+
}
|
|
142
|
+
return run;
|
|
143
|
+
} catch (error) {
|
|
144
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflow run" });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async function createLegacyWorkflowRunHandler({
|
|
148
|
+
mastra,
|
|
149
|
+
workflowId,
|
|
150
|
+
runId: prevRunId
|
|
151
|
+
}) {
|
|
152
|
+
try {
|
|
153
|
+
if (!workflowId) {
|
|
154
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
155
|
+
}
|
|
156
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
157
|
+
if (!workflow) {
|
|
158
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
159
|
+
}
|
|
160
|
+
const newRun = workflow.createRun({ runId: prevRunId });
|
|
161
|
+
return { runId: newRun.runId };
|
|
162
|
+
} catch (error) {
|
|
163
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error creating workflow run" });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async function startLegacyWorkflowRunHandler({
|
|
167
|
+
mastra,
|
|
168
|
+
runtimeContext,
|
|
169
|
+
workflowId,
|
|
170
|
+
runId,
|
|
171
|
+
triggerData
|
|
172
|
+
}) {
|
|
173
|
+
try {
|
|
174
|
+
if (!workflowId) {
|
|
175
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
176
|
+
}
|
|
177
|
+
if (!runId) {
|
|
178
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to start run" });
|
|
179
|
+
}
|
|
180
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
181
|
+
const run = workflow.getMemoryRun(runId);
|
|
182
|
+
if (!run) {
|
|
183
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
184
|
+
}
|
|
185
|
+
void run.start({
|
|
186
|
+
triggerData,
|
|
187
|
+
runtimeContext
|
|
188
|
+
});
|
|
189
|
+
return { message: "Workflow run started" };
|
|
190
|
+
} catch (e) {
|
|
191
|
+
return chunk64U3UDTH_cjs.handleError(e, "Error starting workflow run");
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
async function watchLegacyWorkflowHandler({
|
|
195
|
+
mastra,
|
|
196
|
+
workflowId,
|
|
197
|
+
runId
|
|
198
|
+
}) {
|
|
199
|
+
try {
|
|
200
|
+
if (!workflowId) {
|
|
201
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
202
|
+
}
|
|
203
|
+
if (!runId) {
|
|
204
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to watch workflow" });
|
|
205
|
+
}
|
|
206
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
207
|
+
const run = workflow.getMemoryRun(runId);
|
|
208
|
+
if (!run) {
|
|
209
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
210
|
+
}
|
|
211
|
+
let unwatch;
|
|
212
|
+
let asyncRef = null;
|
|
213
|
+
const stream = new web.ReadableStream({
|
|
214
|
+
start(controller) {
|
|
215
|
+
unwatch = run.watch(({ activePaths, runId: runId2, timestamp, results }) => {
|
|
216
|
+
const activePathsObj = Object.fromEntries(activePaths);
|
|
217
|
+
controller.enqueue(JSON.stringify({ activePaths: activePathsObj, runId: runId2, timestamp, results }));
|
|
218
|
+
if (asyncRef) {
|
|
219
|
+
clearImmediate(asyncRef);
|
|
220
|
+
asyncRef = null;
|
|
221
|
+
}
|
|
222
|
+
asyncRef = setImmediate(() => {
|
|
223
|
+
const runDone = Object.values(activePathsObj).every((value) => value.status !== "executing");
|
|
224
|
+
if (runDone) {
|
|
225
|
+
controller.close();
|
|
226
|
+
unwatch?.();
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
},
|
|
231
|
+
cancel() {
|
|
232
|
+
unwatch?.();
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
return stream;
|
|
236
|
+
} catch (error) {
|
|
237
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error watching workflow");
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
async function resumeAsyncLegacyWorkflowHandler({
|
|
241
|
+
mastra,
|
|
242
|
+
workflowId,
|
|
243
|
+
runId,
|
|
244
|
+
body,
|
|
245
|
+
runtimeContext
|
|
246
|
+
}) {
|
|
247
|
+
try {
|
|
248
|
+
if (!workflowId) {
|
|
249
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
250
|
+
}
|
|
251
|
+
if (!runId) {
|
|
252
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to resume workflow" });
|
|
253
|
+
}
|
|
254
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
255
|
+
const run = workflow.getMemoryRun(runId);
|
|
256
|
+
if (!run) {
|
|
257
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
258
|
+
}
|
|
259
|
+
const result = await run.resume({
|
|
260
|
+
stepId: body.stepId,
|
|
261
|
+
context: body.context,
|
|
262
|
+
runtimeContext
|
|
263
|
+
});
|
|
264
|
+
return result;
|
|
265
|
+
} catch (error) {
|
|
266
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error resuming workflow step");
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
async function resumeLegacyWorkflowHandler({
|
|
270
|
+
mastra,
|
|
271
|
+
workflowId,
|
|
272
|
+
runId,
|
|
273
|
+
body,
|
|
274
|
+
runtimeContext
|
|
275
|
+
}) {
|
|
276
|
+
try {
|
|
277
|
+
if (!workflowId) {
|
|
278
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
279
|
+
}
|
|
280
|
+
if (!runId) {
|
|
281
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to resume workflow" });
|
|
282
|
+
}
|
|
283
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
284
|
+
const run = workflow.getMemoryRun(runId);
|
|
285
|
+
if (!run) {
|
|
286
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
287
|
+
}
|
|
288
|
+
void run.resume({
|
|
289
|
+
stepId: body.stepId,
|
|
290
|
+
context: body.context,
|
|
291
|
+
runtimeContext
|
|
292
|
+
});
|
|
293
|
+
return { message: "Workflow run resumed" };
|
|
294
|
+
} catch (error) {
|
|
295
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error resuming workflow");
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
async function getLegacyWorkflowRunsHandler({
|
|
299
|
+
mastra,
|
|
300
|
+
workflowId,
|
|
301
|
+
fromDate,
|
|
302
|
+
toDate,
|
|
303
|
+
limit,
|
|
304
|
+
offset,
|
|
305
|
+
resourceId
|
|
306
|
+
}) {
|
|
307
|
+
try {
|
|
308
|
+
if (!workflowId) {
|
|
309
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
310
|
+
}
|
|
311
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
312
|
+
const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
|
|
313
|
+
runs: [],
|
|
314
|
+
total: 0
|
|
315
|
+
};
|
|
316
|
+
return workflowRuns;
|
|
317
|
+
} catch (error) {
|
|
318
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting workflow runs");
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
exports.createLegacyWorkflowRunHandler = createLegacyWorkflowRunHandler;
|
|
323
|
+
exports.getLegacyWorkflowByIdHandler = getLegacyWorkflowByIdHandler;
|
|
324
|
+
exports.getLegacyWorkflowRunHandler = getLegacyWorkflowRunHandler;
|
|
325
|
+
exports.getLegacyWorkflowRunsHandler = getLegacyWorkflowRunsHandler;
|
|
326
|
+
exports.getLegacyWorkflowsHandler = getLegacyWorkflowsHandler;
|
|
327
|
+
exports.legacyWorkflows_exports = legacyWorkflows_exports;
|
|
328
|
+
exports.resumeAsyncLegacyWorkflowHandler = resumeAsyncLegacyWorkflowHandler;
|
|
329
|
+
exports.resumeLegacyWorkflowHandler = resumeLegacyWorkflowHandler;
|
|
330
|
+
exports.startAsyncLegacyWorkflowHandler = startAsyncLegacyWorkflowHandler;
|
|
331
|
+
exports.startLegacyWorkflowRunHandler = startLegacyWorkflowRunHandler;
|
|
332
|
+
exports.watchLegacyWorkflowHandler = watchLegacyWorkflowHandler;
|