@mastra/server 0.0.0-separate-trace-data-from-component-20250501042644 → 0.0.0-share-agent-metadata-with-cloud-20250718110128
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 +11 -42
- package/README.md +48 -135
- package/dist/_tsup-dts-rollup.d.cts +556 -103
- package/dist/_tsup-dts-rollup.d.ts +556 -103
- package/dist/{chunk-FV45V6WC.cjs → chunk-2KZFMI6P.cjs} +1 -7
- package/dist/{chunk-5YGDYMRB.cjs → chunk-2SLFAFTR.cjs} +14 -13
- package/dist/chunk-3CNDE7QY.cjs +308 -0
- package/dist/chunk-4D66QEKC.js +81 -0
- package/dist/{chunk-M3YJLWTU.js → chunk-5PQQ42EZ.js} +68 -57
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/{chunk-M56ECCHK.cjs → chunk-7TP2LX5L.cjs} +20 -19
- package/dist/chunk-B2PAS2IB.cjs +514 -0
- package/dist/{chunk-Y3SV5XK4.js → chunk-BK4XT6EG.js} +105 -16
- package/dist/{chunk-QN4KF3BH.cjs → chunk-CCGRCYWJ.cjs} +2 -2
- package/dist/{chunk-QJ3AHN64.js → chunk-CRCR3ZUK.js} +4 -3
- package/dist/{chunk-D3G23FP3.cjs → chunk-FRVBFMO2.cjs} +24 -22
- package/dist/{chunk-7IWQE76Z.cjs → chunk-G7KH752Y.cjs} +16 -10
- package/dist/chunk-GHC4YV6R.js +504 -0
- package/dist/chunk-H7DMHBKY.js +498 -0
- package/dist/chunk-JMLYCXMK.cjs +332 -0
- package/dist/{chunk-Q6SHQECN.js → chunk-KHZKYUNR.js} +34 -10
- package/dist/{chunk-RBQASTUP.js → chunk-KOHWJYJT.js} +120 -27
- package/dist/{chunk-TRDNDNGQ.js → chunk-LCM566I4.js} +2 -7
- package/dist/chunk-LF7P5PLR.js +14 -0
- package/dist/chunk-LI436ITD.cjs +2042 -0
- package/dist/{chunk-5JNVY6DU.js → chunk-LRCAAFUA.js} +7 -5
- package/dist/chunk-LZ3VJXSO.cjs +278 -0
- package/dist/chunk-MEGCYGBU.js +2039 -0
- package/dist/chunk-MLKGABMK.js +7 -0
- package/dist/chunk-PZQDCRPV.cjs +16 -0
- package/dist/chunk-QGX47B5D.cjs +86 -0
- package/dist/{chunk-WTHDCRMY.js → chunk-RG473F6Y.js} +12 -6
- package/dist/chunk-RHSWAXKB.cjs +118 -0
- package/dist/{chunk-L7XE5QTW.js → chunk-RSEO4XPX.js} +1 -1
- package/dist/chunk-SDPGVWQJ.cjs +512 -0
- package/dist/{chunk-4JINXASC.js → chunk-WNVFNNWN.js} +5 -4
- 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 +17 -9
- package/dist/server/handlers/memory.d.cts +2 -0
- package/dist/server/handlers/memory.d.ts +2 -0
- 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/vNextNetwork.cjs +218 -0
- package/dist/server/handlers/vNextNetwork.d.cts +6 -0
- package/dist/server/handlers/vNextNetwork.d.ts +6 -0
- package/dist/server/handlers/vNextNetwork.js +211 -0
- package/dist/server/handlers/vector.cjs +7 -7
- package/dist/server/handlers/vector.js +1 -1
- package/dist/server/handlers/voice.cjs +8 -4
- package/dist/server/handlers/voice.d.cts +1 -0
- package/dist/server/handlers/voice.d.ts +1 -0
- package/dist/server/handlers/voice.js +1 -1
- package/dist/server/handlers/workflows.cjs +29 -13
- package/dist/server/handlers/workflows.d.cts +6 -2
- package/dist/server/handlers/workflows.d.ts +6 -2
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +32 -27
- package/dist/server/handlers.d.cts +2 -1
- package/dist/server/handlers.d.ts +2 -1
- package/dist/server/handlers.js +11 -10
- package/package.json +15 -14
- package/dist/chunk-2FJURXCL.cjs +0 -213
- package/dist/chunk-3AHQ5RGN.js +0 -11
- package/dist/chunk-3EJZQ6TQ.js +0 -49
- package/dist/chunk-4BIX6GMY.cjs +0 -189
- package/dist/chunk-55HTWX4C.cjs +0 -93
- package/dist/chunk-5SWCVTNL.cjs +0 -5579
- package/dist/chunk-AELYAUEE.cjs +0 -316
- package/dist/chunk-EVCC233P.cjs +0 -321
- package/dist/chunk-JPB6RPGB.js +0 -304
- package/dist/chunk-OMN3UI6X.js +0 -5576
- package/dist/chunk-SKBVVI24.cjs +0 -54
- package/dist/chunk-ZLBRQFDD.cjs +0 -13
- package/dist/server/handlers/vNextWorkflows.cjs +0 -46
- package/dist/server/handlers/vNextWorkflows.d.cts +0 -10
- package/dist/server/handlers/vNextWorkflows.d.ts +0 -10
- package/dist/server/handlers/vNextWorkflows.js +0 -1
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkLI436ITD_cjs = require('./chunk-LI436ITD.cjs');
|
|
4
|
+
var chunkPZQDCRPV_cjs = require('./chunk-PZQDCRPV.cjs');
|
|
5
|
+
var chunk2KZFMI6P_cjs = require('./chunk-2KZFMI6P.cjs');
|
|
6
|
+
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
7
|
+
var 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 ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_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 ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(_step.inputSchema)) : void 0,
|
|
42
|
+
outputSchema: _step.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(_step.outputSchema)) : void 0
|
|
43
|
+
};
|
|
44
|
+
return acc2;
|
|
45
|
+
}, {})
|
|
46
|
+
};
|
|
47
|
+
return acc;
|
|
48
|
+
}, {});
|
|
49
|
+
return _workflows;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
return chunkPZQDCRPV_cjs.handleError(error, "error getting workflows");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function getLegacyWorkflowByIdHandler({ mastra, workflowId }) {
|
|
55
|
+
try {
|
|
56
|
+
if (!workflowId) {
|
|
57
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
58
|
+
}
|
|
59
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
60
|
+
if (!workflow) {
|
|
61
|
+
throw new chunk2KZFMI6P_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 ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_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 ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(_step.inputSchema)) : void 0,
|
|
77
|
+
outputSchema: _step.outputSchema ? chunkLI436ITD_cjs.stringify(chunkLI436ITD_cjs.esm_default(_step.outputSchema)) : void 0
|
|
78
|
+
};
|
|
79
|
+
return acc;
|
|
80
|
+
}, {})
|
|
81
|
+
};
|
|
82
|
+
} catch (error) {
|
|
83
|
+
return chunkPZQDCRPV_cjs.handleError(error, "error getting workflow by id");
|
|
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 chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
96
|
+
}
|
|
97
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
98
|
+
if (!workflow) {
|
|
99
|
+
throw new chunk2KZFMI6P_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 chunk2KZFMI6P_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
|
+
return chunkPZQDCRPV_cjs.handleError(error, "error starting workflow");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async function getLegacyWorkflowRunHandler({
|
|
123
|
+
mastra,
|
|
124
|
+
workflowId,
|
|
125
|
+
runId
|
|
126
|
+
}) {
|
|
127
|
+
try {
|
|
128
|
+
if (!workflowId) {
|
|
129
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
130
|
+
}
|
|
131
|
+
if (!runId) {
|
|
132
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(400, { message: "Run ID is required" });
|
|
133
|
+
}
|
|
134
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
135
|
+
if (!workflow) {
|
|
136
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
137
|
+
}
|
|
138
|
+
const run = await workflow.getRun(runId);
|
|
139
|
+
if (!run) {
|
|
140
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
141
|
+
}
|
|
142
|
+
return run;
|
|
143
|
+
} catch (error) {
|
|
144
|
+
return chunkPZQDCRPV_cjs.handleError(error, "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 chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
155
|
+
}
|
|
156
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
157
|
+
if (!workflow) {
|
|
158
|
+
throw new chunk2KZFMI6P_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
159
|
+
}
|
|
160
|
+
const newRun = workflow.createRun({ runId: prevRunId });
|
|
161
|
+
return { runId: newRun.runId };
|
|
162
|
+
} catch (error) {
|
|
163
|
+
return chunkPZQDCRPV_cjs.handleError(error, "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 chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
176
|
+
}
|
|
177
|
+
if (!runId) {
|
|
178
|
+
throw new chunk2KZFMI6P_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 chunk2KZFMI6P_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 chunkPZQDCRPV_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 chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
202
|
+
}
|
|
203
|
+
if (!runId) {
|
|
204
|
+
throw new chunk2KZFMI6P_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 chunk2KZFMI6P_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 chunkPZQDCRPV_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 chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
250
|
+
}
|
|
251
|
+
if (!runId) {
|
|
252
|
+
throw new chunk2KZFMI6P_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 chunk2KZFMI6P_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 chunkPZQDCRPV_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 chunk2KZFMI6P_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
279
|
+
}
|
|
280
|
+
if (!runId) {
|
|
281
|
+
throw new chunk2KZFMI6P_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 chunk2KZFMI6P_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 chunkPZQDCRPV_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 chunk2KZFMI6P_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 chunkPZQDCRPV_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;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { validateBody } from './chunk-
|
|
2
|
-
import { handleError } from './chunk-
|
|
3
|
-
import {
|
|
1
|
+
import { validateBody } from './chunk-RSEO4XPX.js';
|
|
2
|
+
import { handleError } from './chunk-LF7P5PLR.js';
|
|
3
|
+
import { HTTPException } from './chunk-LCM566I4.js';
|
|
4
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
4
5
|
import { Readable } from 'stream';
|
|
5
6
|
|
|
6
7
|
// src/server/handlers/voice.ts
|
|
7
8
|
var voice_exports = {};
|
|
8
9
|
__export(voice_exports, {
|
|
9
10
|
generateSpeechHandler: () => generateSpeechHandler,
|
|
11
|
+
getListenerHandler: () => getListenerHandler,
|
|
10
12
|
getSpeakersHandler: () => getSpeakersHandler,
|
|
11
13
|
transcribeSpeechHandler: () => transcribeSpeechHandler
|
|
12
14
|
});
|
|
@@ -19,10 +21,11 @@ async function getSpeakersHandler({ mastra, agentId }) {
|
|
|
19
21
|
if (!agent) {
|
|
20
22
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
21
23
|
}
|
|
22
|
-
|
|
24
|
+
const voice = await agent.getVoice();
|
|
25
|
+
if (!voice) {
|
|
23
26
|
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
24
27
|
}
|
|
25
|
-
const speakers = await
|
|
28
|
+
const speakers = await voice.getSpeakers();
|
|
26
29
|
return speakers;
|
|
27
30
|
} catch (error) {
|
|
28
31
|
return handleError(error, "Error getting speakers");
|
|
@@ -44,10 +47,11 @@ async function generateSpeechHandler({
|
|
|
44
47
|
if (!agent) {
|
|
45
48
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
46
49
|
}
|
|
47
|
-
|
|
50
|
+
const voice = await agent.getVoice();
|
|
51
|
+
if (!voice) {
|
|
48
52
|
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
49
53
|
}
|
|
50
|
-
const audioStream = await
|
|
54
|
+
const audioStream = await voice.speak(body.text, { speaker: body.speakerId });
|
|
51
55
|
if (!audioStream) {
|
|
52
56
|
throw new HTTPException(500, { message: "Failed to generate speech" });
|
|
53
57
|
}
|
|
@@ -72,17 +76,37 @@ async function transcribeSpeechHandler({
|
|
|
72
76
|
if (!agent) {
|
|
73
77
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
74
78
|
}
|
|
75
|
-
|
|
79
|
+
const voice = await agent.getVoice();
|
|
80
|
+
if (!voice) {
|
|
76
81
|
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
77
82
|
}
|
|
78
83
|
const audioStream = new Readable();
|
|
79
84
|
audioStream.push(body.audioData);
|
|
80
85
|
audioStream.push(null);
|
|
81
|
-
const text = await
|
|
86
|
+
const text = await voice.listen(audioStream, body.options);
|
|
82
87
|
return { text };
|
|
83
88
|
} catch (error) {
|
|
84
89
|
return handleError(error, "Error transcribing speech");
|
|
85
90
|
}
|
|
86
91
|
}
|
|
92
|
+
async function getListenerHandler({ mastra, agentId }) {
|
|
93
|
+
try {
|
|
94
|
+
if (!agentId) {
|
|
95
|
+
throw new HTTPException(400, { message: "Agent ID is required" });
|
|
96
|
+
}
|
|
97
|
+
const agent = mastra.getAgent(agentId);
|
|
98
|
+
if (!agent) {
|
|
99
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
100
|
+
}
|
|
101
|
+
const voice = await agent.getVoice();
|
|
102
|
+
if (!voice) {
|
|
103
|
+
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
104
|
+
}
|
|
105
|
+
const listeners = await voice.getListener();
|
|
106
|
+
return listeners;
|
|
107
|
+
} catch (error) {
|
|
108
|
+
return handleError(error, "Error getting listeners");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
87
111
|
|
|
88
|
-
export { generateSpeechHandler, getSpeakersHandler, transcribeSpeechHandler, voice_exports };
|
|
112
|
+
export { generateSpeechHandler, getListenerHandler, getSpeakersHandler, transcribeSpeechHandler, voice_exports };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { validateBody } from './chunk-
|
|
2
|
-
import { handleError } from './chunk-
|
|
3
|
-
import {
|
|
1
|
+
import { validateBody } from './chunk-RSEO4XPX.js';
|
|
2
|
+
import { handleError } from './chunk-LF7P5PLR.js';
|
|
3
|
+
import { HTTPException } from './chunk-LCM566I4.js';
|
|
4
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
5
|
+
import { generateEmptyFromSchema } from '@mastra/core';
|
|
4
6
|
|
|
5
7
|
// src/server/handlers/memory.ts
|
|
6
8
|
var memory_exports = {};
|
|
@@ -11,23 +13,41 @@ __export(memory_exports, {
|
|
|
11
13
|
getMessagesHandler: () => getMessagesHandler,
|
|
12
14
|
getThreadByIdHandler: () => getThreadByIdHandler,
|
|
13
15
|
getThreadsHandler: () => getThreadsHandler,
|
|
16
|
+
getWorkingMemoryHandler: () => getWorkingMemoryHandler,
|
|
14
17
|
saveMessagesHandler: () => saveMessagesHandler,
|
|
15
|
-
updateThreadHandler: () => updateThreadHandler
|
|
18
|
+
updateThreadHandler: () => updateThreadHandler,
|
|
19
|
+
updateWorkingMemoryHandler: () => updateWorkingMemoryHandler
|
|
16
20
|
});
|
|
17
|
-
function getMemoryFromContext({
|
|
21
|
+
async function getMemoryFromContext({
|
|
18
22
|
mastra,
|
|
19
|
-
agentId
|
|
23
|
+
agentId,
|
|
24
|
+
networkId,
|
|
25
|
+
runtimeContext
|
|
20
26
|
}) {
|
|
21
27
|
const agent = agentId ? mastra.getAgent(agentId) : null;
|
|
22
28
|
if (agentId && !agent) {
|
|
23
29
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
24
30
|
}
|
|
25
|
-
const
|
|
26
|
-
|
|
31
|
+
const network = networkId ? mastra.vnext_getNetwork(networkId) : null;
|
|
32
|
+
if (networkId && !network) {
|
|
33
|
+
throw new HTTPException(404, { message: "Network not found" });
|
|
34
|
+
}
|
|
35
|
+
if (agent) {
|
|
36
|
+
return agent?.getMemory() || mastra.getMemory();
|
|
37
|
+
}
|
|
38
|
+
if (network) {
|
|
39
|
+
return await network?.getMemory({ runtimeContext }) || mastra.getMemory();
|
|
40
|
+
}
|
|
41
|
+
return mastra.getMemory();
|
|
27
42
|
}
|
|
28
|
-
async function getMemoryStatusHandler({
|
|
43
|
+
async function getMemoryStatusHandler({
|
|
44
|
+
mastra,
|
|
45
|
+
agentId,
|
|
46
|
+
networkId,
|
|
47
|
+
runtimeContext
|
|
48
|
+
}) {
|
|
29
49
|
try {
|
|
30
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
50
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
31
51
|
if (!memory) {
|
|
32
52
|
return { result: false };
|
|
33
53
|
}
|
|
@@ -39,10 +59,12 @@ async function getMemoryStatusHandler({ mastra, agentId }) {
|
|
|
39
59
|
async function getThreadsHandler({
|
|
40
60
|
mastra,
|
|
41
61
|
agentId,
|
|
42
|
-
resourceId
|
|
62
|
+
resourceId,
|
|
63
|
+
networkId,
|
|
64
|
+
runtimeContext
|
|
43
65
|
}) {
|
|
44
66
|
try {
|
|
45
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
67
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
46
68
|
if (!memory) {
|
|
47
69
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
48
70
|
}
|
|
@@ -56,11 +78,13 @@ async function getThreadsHandler({
|
|
|
56
78
|
async function getThreadByIdHandler({
|
|
57
79
|
mastra,
|
|
58
80
|
agentId,
|
|
59
|
-
threadId
|
|
81
|
+
threadId,
|
|
82
|
+
networkId,
|
|
83
|
+
runtimeContext
|
|
60
84
|
}) {
|
|
61
85
|
try {
|
|
62
86
|
validateBody({ threadId });
|
|
63
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
87
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
64
88
|
if (!memory) {
|
|
65
89
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
66
90
|
}
|
|
@@ -76,10 +100,12 @@ async function getThreadByIdHandler({
|
|
|
76
100
|
async function saveMessagesHandler({
|
|
77
101
|
mastra,
|
|
78
102
|
agentId,
|
|
79
|
-
body
|
|
103
|
+
body,
|
|
104
|
+
networkId,
|
|
105
|
+
runtimeContext
|
|
80
106
|
}) {
|
|
81
107
|
try {
|
|
82
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
108
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
83
109
|
if (!memory) {
|
|
84
110
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
85
111
|
}
|
|
@@ -103,10 +129,12 @@ async function saveMessagesHandler({
|
|
|
103
129
|
async function createThreadHandler({
|
|
104
130
|
mastra,
|
|
105
131
|
agentId,
|
|
106
|
-
body
|
|
132
|
+
body,
|
|
133
|
+
networkId,
|
|
134
|
+
runtimeContext
|
|
107
135
|
}) {
|
|
108
136
|
try {
|
|
109
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
137
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
110
138
|
if (!memory) {
|
|
111
139
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
112
140
|
}
|
|
@@ -126,10 +154,12 @@ async function updateThreadHandler({
|
|
|
126
154
|
mastra,
|
|
127
155
|
agentId,
|
|
128
156
|
threadId,
|
|
129
|
-
body
|
|
157
|
+
body,
|
|
158
|
+
networkId,
|
|
159
|
+
runtimeContext
|
|
130
160
|
}) {
|
|
131
161
|
try {
|
|
132
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
162
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
133
163
|
if (!body) {
|
|
134
164
|
throw new HTTPException(400, { message: "Body is required" });
|
|
135
165
|
}
|
|
@@ -160,11 +190,13 @@ async function updateThreadHandler({
|
|
|
160
190
|
async function deleteThreadHandler({
|
|
161
191
|
mastra,
|
|
162
192
|
agentId,
|
|
163
|
-
threadId
|
|
193
|
+
threadId,
|
|
194
|
+
networkId,
|
|
195
|
+
runtimeContext
|
|
164
196
|
}) {
|
|
165
197
|
try {
|
|
166
198
|
validateBody({ threadId });
|
|
167
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
199
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
168
200
|
if (!memory) {
|
|
169
201
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
170
202
|
}
|
|
@@ -181,11 +213,17 @@ async function deleteThreadHandler({
|
|
|
181
213
|
async function getMessagesHandler({
|
|
182
214
|
mastra,
|
|
183
215
|
agentId,
|
|
184
|
-
threadId
|
|
216
|
+
threadId,
|
|
217
|
+
limit,
|
|
218
|
+
networkId,
|
|
219
|
+
runtimeContext
|
|
185
220
|
}) {
|
|
221
|
+
if (limit !== void 0 && (!Number.isInteger(limit) || limit <= 0)) {
|
|
222
|
+
throw new HTTPException(400, { message: "Invalid limit: must be a positive integer" });
|
|
223
|
+
}
|
|
186
224
|
try {
|
|
187
225
|
validateBody({ threadId });
|
|
188
|
-
const memory = getMemoryFromContext({ mastra, agentId });
|
|
226
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
189
227
|
if (!memory) {
|
|
190
228
|
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
191
229
|
}
|
|
@@ -193,11 +231,66 @@ async function getMessagesHandler({
|
|
|
193
231
|
if (!thread) {
|
|
194
232
|
throw new HTTPException(404, { message: "Thread not found" });
|
|
195
233
|
}
|
|
196
|
-
const result = await memory.query({
|
|
197
|
-
|
|
234
|
+
const result = await memory.query({
|
|
235
|
+
threadId,
|
|
236
|
+
...limit && { selectBy: { last: limit } }
|
|
237
|
+
});
|
|
238
|
+
return { messages: result.messages, uiMessages: result.uiMessages };
|
|
198
239
|
} catch (error) {
|
|
199
240
|
return handleError(error, "Error getting messages");
|
|
200
241
|
}
|
|
201
242
|
}
|
|
243
|
+
async function getWorkingMemoryHandler({
|
|
244
|
+
mastra,
|
|
245
|
+
agentId,
|
|
246
|
+
threadId,
|
|
247
|
+
resourceId,
|
|
248
|
+
networkId,
|
|
249
|
+
runtimeContext,
|
|
250
|
+
memoryConfig
|
|
251
|
+
}) {
|
|
252
|
+
try {
|
|
253
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
254
|
+
validateBody({ threadId });
|
|
255
|
+
if (!memory) {
|
|
256
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
257
|
+
}
|
|
258
|
+
const thread = await memory.getThreadById({ threadId });
|
|
259
|
+
const threadExists = !!thread;
|
|
260
|
+
const template = await memory.getWorkingMemoryTemplate({ memoryConfig });
|
|
261
|
+
const workingMemoryTemplate = template?.format === "json" ? { ...template, content: JSON.stringify(generateEmptyFromSchema(template.content)) } : template;
|
|
262
|
+
const workingMemory = await memory.getWorkingMemory({ threadId, resourceId, memoryConfig });
|
|
263
|
+
const config = memory.getMergedThreadConfig(memoryConfig || {});
|
|
264
|
+
const source = config.workingMemory?.scope === "resource" && resourceId ? "resource" : "thread";
|
|
265
|
+
return { workingMemory, source, workingMemoryTemplate, threadExists };
|
|
266
|
+
} catch (error) {
|
|
267
|
+
return handleError(error, "Error getting working memory");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
async function updateWorkingMemoryHandler({
|
|
271
|
+
mastra,
|
|
272
|
+
agentId,
|
|
273
|
+
threadId,
|
|
274
|
+
body,
|
|
275
|
+
networkId,
|
|
276
|
+
runtimeContext
|
|
277
|
+
}) {
|
|
278
|
+
try {
|
|
279
|
+
validateBody({ threadId });
|
|
280
|
+
const memory = await getMemoryFromContext({ mastra, agentId, networkId, runtimeContext });
|
|
281
|
+
const { resourceId, memoryConfig, workingMemory } = body;
|
|
282
|
+
if (!memory) {
|
|
283
|
+
throw new HTTPException(400, { message: "Memory is not initialized" });
|
|
284
|
+
}
|
|
285
|
+
const thread = await memory.getThreadById({ threadId });
|
|
286
|
+
if (!thread) {
|
|
287
|
+
throw new HTTPException(404, { message: "Thread not found" });
|
|
288
|
+
}
|
|
289
|
+
await memory.updateWorkingMemory({ threadId, resourceId, workingMemory, memoryConfig });
|
|
290
|
+
return { success: true };
|
|
291
|
+
} catch (error) {
|
|
292
|
+
return handleError(error, "Error updating working memory");
|
|
293
|
+
}
|
|
294
|
+
}
|
|
202
295
|
|
|
203
|
-
export { createThreadHandler, deleteThreadHandler, getMemoryStatusHandler, getMessagesHandler, getThreadByIdHandler, getThreadsHandler, memory_exports, saveMessagesHandler, updateThreadHandler };
|
|
296
|
+
export { createThreadHandler, deleteThreadHandler, getMemoryStatusHandler, getMessagesHandler, getThreadByIdHandler, getThreadsHandler, getWorkingMemoryHandler, memory_exports, saveMessagesHandler, updateThreadHandler, updateWorkingMemoryHandler };
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __export = (target, all) => {
|
|
3
|
-
for (var name in all)
|
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
-
};
|
|
6
|
-
|
|
7
1
|
// src/server/http-exception.ts
|
|
8
2
|
var HTTPException = class extends Error {
|
|
9
3
|
res;
|
|
@@ -17,6 +11,7 @@ var HTTPException = class extends Error {
|
|
|
17
11
|
super(options?.message, { cause: options?.cause });
|
|
18
12
|
this.res = options?.res;
|
|
19
13
|
this.status = status;
|
|
14
|
+
this.stack = options?.stack || this.stack;
|
|
20
15
|
}
|
|
21
16
|
/**
|
|
22
17
|
* Returns the response object associated with the exception.
|
|
@@ -37,4 +32,4 @@ var HTTPException = class extends Error {
|
|
|
37
32
|
}
|
|
38
33
|
};
|
|
39
34
|
|
|
40
|
-
export { HTTPException
|
|
35
|
+
export { HTTPException };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HTTPException } from './chunk-LCM566I4.js';
|
|
2
|
+
|
|
3
|
+
// src/server/handlers/error.ts
|
|
4
|
+
function handleError(error, defaultMessage) {
|
|
5
|
+
const apiError = error;
|
|
6
|
+
const apiErrorStatus = apiError.status || apiError.details?.status || 500;
|
|
7
|
+
throw new HTTPException(apiErrorStatus, {
|
|
8
|
+
message: apiError.message || defaultMessage,
|
|
9
|
+
stack: apiError.stack,
|
|
10
|
+
cause: apiError.cause
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { handleError };
|