@mastra/server 0.0.0-fix-memory-xxhash-20250409202110 → 0.0.0-generate-message-id-20250512171942
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 +282 -34
- package/dist/_tsup-dts-rollup.d.ts +282 -34
- package/dist/{chunk-2FJURXCL.cjs → chunk-24EGIVT7.cjs} +34 -33
- package/dist/chunk-3HQNCTZ2.cjs +199 -0
- package/dist/{chunk-M56ECCHK.cjs → chunk-4YZ3U35L.cjs} +18 -17
- 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-75ZPJI57.cjs +9 -0
- package/dist/{chunk-2YONKUWB.js → chunk-C7564HUT.js} +58 -33
- package/dist/{chunk-ILW7XYNJ.js → chunk-EJO45KYT.js} +51 -27
- package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
- package/dist/{chunk-3RVHWGWO.js → chunk-HFWCEP5S.js} +6 -12
- package/dist/{chunk-2JQC6JWP.js → chunk-HWZVAG3H.js} +7 -4
- package/dist/{chunk-X37I6GZT.cjs → chunk-I2B73Y4I.cjs} +92 -68
- package/dist/{chunk-4JINXASC.js → chunk-IU5VO2I2.js} +3 -2
- 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-MIQYDLLM.js +329 -0
- 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-VB7KH62D.cjs → chunk-OGCNNUHF.cjs} +13 -10
- package/dist/{chunk-DVPP5S6I.js → chunk-OR3CIE2H.js} +9 -6
- package/dist/chunk-P6SCPDYW.js +500 -0
- package/dist/{chunk-BMA2ORRT.js → chunk-Q6KMBIAN.js} +76 -37
- package/dist/{chunk-YNSGUC2O.js → chunk-TJKLBTFB.js} +23 -7
- package/dist/chunk-UCTEMO2Q.cjs +341 -0
- package/dist/chunk-VPNDC2DI.cjs +148 -0
- package/dist/{chunk-RBQASTUP.js → chunk-X3ZDCS52.js} +4 -3
- package/dist/{chunk-A7DF4ETD.cjs → chunk-YBVOQN4M.cjs} +22 -28
- 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/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/vNextWorkflows.cjs +46 -0
- package/dist/server/handlers/vNextWorkflows.d.cts +10 -0
- package/dist/server/handlers/vNextWorkflows.d.ts +10 -0
- package/dist/server/handlers/vNextWorkflows.js +1 -0
- 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 +11 -11
- package/dist/server/handlers/workflows.js +1 -1
- package/dist/server/handlers.cjs +31 -21
- 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-GV52BII2.cjs +0 -160
- package/dist/chunk-QH6XWSXP.cjs +0 -5579
- package/dist/chunk-VK6FX47H.js +0 -5576
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { stringify, esm_default } from './chunk-
|
|
2
|
-
import { validateBody } from './chunk-
|
|
3
|
-
import { handleError } from './chunk-
|
|
4
|
-
import {
|
|
1
|
+
import { stringify, esm_default } from './chunk-LIVAK2DM.js';
|
|
2
|
+
import { validateBody } from './chunk-H5PTF3Y4.js';
|
|
3
|
+
import { handleError } from './chunk-M5ABIP7D.js';
|
|
4
|
+
import { HTTPException } from './chunk-NYN7KFXL.js';
|
|
5
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
6
|
+
import { RuntimeContext } from '@mastra/core/di';
|
|
5
7
|
import { isVercelTool } from '@mastra/core/tools';
|
|
6
8
|
|
|
7
9
|
// src/server/handlers/tools.ts
|
|
@@ -55,7 +57,9 @@ function executeToolHandler(tools) {
|
|
|
55
57
|
mastra,
|
|
56
58
|
runId,
|
|
57
59
|
toolId,
|
|
58
|
-
data
|
|
60
|
+
data,
|
|
61
|
+
runtimeContext,
|
|
62
|
+
runtimeContextFromRequest
|
|
59
63
|
}) => {
|
|
60
64
|
try {
|
|
61
65
|
if (!toolId) {
|
|
@@ -73,10 +77,15 @@ function executeToolHandler(tools) {
|
|
|
73
77
|
const result2 = await tool.execute(data);
|
|
74
78
|
return result2;
|
|
75
79
|
}
|
|
80
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
81
|
+
...Array.from(runtimeContext.entries()),
|
|
82
|
+
...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
|
|
83
|
+
]);
|
|
76
84
|
const result = await tool.execute({
|
|
77
85
|
context: data,
|
|
78
86
|
mastra,
|
|
79
|
-
runId
|
|
87
|
+
runId,
|
|
88
|
+
runtimeContext: finalRuntimeContext
|
|
80
89
|
});
|
|
81
90
|
return result;
|
|
82
91
|
} catch (error) {
|
|
@@ -88,7 +97,9 @@ async function executeAgentToolHandler({
|
|
|
88
97
|
mastra,
|
|
89
98
|
agentId,
|
|
90
99
|
toolId,
|
|
91
|
-
data
|
|
100
|
+
data,
|
|
101
|
+
runtimeContext,
|
|
102
|
+
runtimeContextFromRequest
|
|
92
103
|
}) {
|
|
93
104
|
try {
|
|
94
105
|
const agent = agentId ? mastra.getAgent(agentId) : null;
|
|
@@ -102,8 +113,13 @@ async function executeAgentToolHandler({
|
|
|
102
113
|
if (!tool?.execute) {
|
|
103
114
|
throw new HTTPException(400, { message: "Tool is not executable" });
|
|
104
115
|
}
|
|
116
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
117
|
+
...Array.from(runtimeContext.entries()),
|
|
118
|
+
...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
|
|
119
|
+
]);
|
|
105
120
|
const result = await tool.execute({
|
|
106
121
|
context: data,
|
|
122
|
+
runtimeContext: finalRuntimeContext,
|
|
107
123
|
mastra,
|
|
108
124
|
runId: agentId
|
|
109
125
|
});
|
|
@@ -0,0 +1,341 @@
|
|
|
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
|
+
var di = require('@mastra/core/di');
|
|
9
|
+
|
|
10
|
+
// src/server/handlers/vNextWorkflows.ts
|
|
11
|
+
var vNextWorkflows_exports = {};
|
|
12
|
+
chunk75ZPJI57_cjs.__export(vNextWorkflows_exports, {
|
|
13
|
+
createVNextWorkflowRunHandler: () => createVNextWorkflowRunHandler,
|
|
14
|
+
getVNextWorkflowByIdHandler: () => getVNextWorkflowByIdHandler,
|
|
15
|
+
getVNextWorkflowRunByIdHandler: () => getVNextWorkflowRunByIdHandler,
|
|
16
|
+
getVNextWorkflowRunsHandler: () => getVNextWorkflowRunsHandler,
|
|
17
|
+
getVNextWorkflowsHandler: () => getVNextWorkflowsHandler,
|
|
18
|
+
resumeAsyncVNextWorkflowHandler: () => resumeAsyncVNextWorkflowHandler,
|
|
19
|
+
resumeVNextWorkflowHandler: () => resumeVNextWorkflowHandler,
|
|
20
|
+
startAsyncVNextWorkflowHandler: () => startAsyncVNextWorkflowHandler,
|
|
21
|
+
startVNextWorkflowRunHandler: () => startVNextWorkflowRunHandler,
|
|
22
|
+
watchVNextWorkflowHandler: () => watchVNextWorkflowHandler
|
|
23
|
+
});
|
|
24
|
+
async function getVNextWorkflowsHandler({ mastra }) {
|
|
25
|
+
try {
|
|
26
|
+
const workflows = mastra.vnext_getWorkflows({ serialized: false });
|
|
27
|
+
const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
|
|
28
|
+
acc[key] = {
|
|
29
|
+
name: workflow.name,
|
|
30
|
+
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
31
|
+
acc2[key2] = {
|
|
32
|
+
id: step.id,
|
|
33
|
+
description: step.description,
|
|
34
|
+
inputSchema: step.inputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(step.inputSchema)) : void 0,
|
|
35
|
+
outputSchema: step.outputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(step.outputSchema)) : void 0,
|
|
36
|
+
resumeSchema: step.resumeSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(step.resumeSchema)) : void 0,
|
|
37
|
+
suspendSchema: step.suspendSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(step.suspendSchema)) : void 0
|
|
38
|
+
};
|
|
39
|
+
return acc2;
|
|
40
|
+
}, {}),
|
|
41
|
+
stepGraph: workflow.serializedStepGraph,
|
|
42
|
+
inputSchema: workflow.inputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(workflow.inputSchema)) : void 0,
|
|
43
|
+
outputSchema: workflow.outputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(workflow.outputSchema)) : void 0
|
|
44
|
+
};
|
|
45
|
+
return acc;
|
|
46
|
+
}, {});
|
|
47
|
+
return _workflows;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflows" });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function getVNextWorkflowByIdHandler({ mastra, workflowId }) {
|
|
53
|
+
try {
|
|
54
|
+
if (!workflowId) {
|
|
55
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
56
|
+
}
|
|
57
|
+
const workflow = mastra.vnext_getWorkflow(workflowId);
|
|
58
|
+
if (!workflow) {
|
|
59
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
|
|
63
|
+
acc[key] = {
|
|
64
|
+
id: step.id,
|
|
65
|
+
description: step.description,
|
|
66
|
+
inputSchema: step.inputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(step.inputSchema)) : void 0,
|
|
67
|
+
outputSchema: step.outputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(step.outputSchema)) : void 0,
|
|
68
|
+
resumeSchema: step.resumeSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(step.resumeSchema)) : void 0,
|
|
69
|
+
suspendSchema: step.suspendSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(step.suspendSchema)) : void 0
|
|
70
|
+
};
|
|
71
|
+
return acc;
|
|
72
|
+
}, {}),
|
|
73
|
+
name: workflow.name,
|
|
74
|
+
stepGraph: workflow.serializedStepGraph,
|
|
75
|
+
inputSchema: workflow.inputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(workflow.inputSchema)) : void 0,
|
|
76
|
+
outputSchema: workflow.outputSchema ? chunkYWLUOY3D_cjs.stringify(chunkYWLUOY3D_cjs.esm_default(workflow.outputSchema)) : void 0
|
|
77
|
+
};
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflow" });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function getVNextWorkflowRunByIdHandler({
|
|
83
|
+
mastra,
|
|
84
|
+
workflowId,
|
|
85
|
+
runId
|
|
86
|
+
}) {
|
|
87
|
+
try {
|
|
88
|
+
if (!workflowId) {
|
|
89
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
90
|
+
}
|
|
91
|
+
if (!runId) {
|
|
92
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Run ID is required" });
|
|
93
|
+
}
|
|
94
|
+
const workflow = mastra.vnext_getWorkflow(workflowId);
|
|
95
|
+
if (!workflow) {
|
|
96
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
97
|
+
}
|
|
98
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
99
|
+
if (!run) {
|
|
100
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
101
|
+
}
|
|
102
|
+
return run;
|
|
103
|
+
} catch (error) {
|
|
104
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error getting workflow run" });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function createVNextWorkflowRunHandler({
|
|
108
|
+
mastra,
|
|
109
|
+
workflowId,
|
|
110
|
+
runId: prevRunId
|
|
111
|
+
}) {
|
|
112
|
+
try {
|
|
113
|
+
if (!workflowId) {
|
|
114
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
115
|
+
}
|
|
116
|
+
const workflow = mastra.vnext_getWorkflow(workflowId);
|
|
117
|
+
if (!workflow) {
|
|
118
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
119
|
+
}
|
|
120
|
+
const run = workflow.createRun({ runId: prevRunId });
|
|
121
|
+
return { runId: run.runId };
|
|
122
|
+
} catch (error) {
|
|
123
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error creating workflow run" });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async function startAsyncVNextWorkflowHandler({
|
|
127
|
+
mastra,
|
|
128
|
+
runtimeContext,
|
|
129
|
+
workflowId,
|
|
130
|
+
runId,
|
|
131
|
+
inputData,
|
|
132
|
+
runtimeContextFromRequest
|
|
133
|
+
}) {
|
|
134
|
+
try {
|
|
135
|
+
if (!workflowId) {
|
|
136
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
137
|
+
}
|
|
138
|
+
const workflow = mastra.vnext_getWorkflow(workflowId);
|
|
139
|
+
if (!workflow) {
|
|
140
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
141
|
+
}
|
|
142
|
+
const finalRuntimeContext = new di.RuntimeContext([
|
|
143
|
+
...Array.from(runtimeContext?.entries() ?? []),
|
|
144
|
+
...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
|
|
145
|
+
]);
|
|
146
|
+
const _run = workflow.createRun({ runId });
|
|
147
|
+
const result = await _run.start({
|
|
148
|
+
inputData,
|
|
149
|
+
runtimeContext: finalRuntimeContext
|
|
150
|
+
});
|
|
151
|
+
return result;
|
|
152
|
+
} catch (error) {
|
|
153
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: error?.message || "Error executing workflow" });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async function startVNextWorkflowRunHandler({
|
|
157
|
+
mastra,
|
|
158
|
+
runtimeContext,
|
|
159
|
+
workflowId,
|
|
160
|
+
runId,
|
|
161
|
+
inputData,
|
|
162
|
+
runtimeContextFromRequest
|
|
163
|
+
}) {
|
|
164
|
+
try {
|
|
165
|
+
if (!workflowId) {
|
|
166
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
167
|
+
}
|
|
168
|
+
if (!runId) {
|
|
169
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to start run" });
|
|
170
|
+
}
|
|
171
|
+
const workflow = mastra.vnext_getWorkflow(workflowId);
|
|
172
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
173
|
+
if (!run) {
|
|
174
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
175
|
+
}
|
|
176
|
+
const finalRuntimeContext = new di.RuntimeContext([
|
|
177
|
+
...Array.from(runtimeContext?.entries() ?? []),
|
|
178
|
+
...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
|
|
179
|
+
]);
|
|
180
|
+
const _run = workflow.createRun({ runId });
|
|
181
|
+
void _run.start({
|
|
182
|
+
inputData,
|
|
183
|
+
runtimeContext: finalRuntimeContext
|
|
184
|
+
});
|
|
185
|
+
return { message: "Workflow run started" };
|
|
186
|
+
} catch (e) {
|
|
187
|
+
return chunk64U3UDTH_cjs.handleError(e, "Error starting workflow run");
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
async function watchVNextWorkflowHandler({
|
|
191
|
+
mastra,
|
|
192
|
+
workflowId,
|
|
193
|
+
runId
|
|
194
|
+
}) {
|
|
195
|
+
try {
|
|
196
|
+
if (!workflowId) {
|
|
197
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
198
|
+
}
|
|
199
|
+
if (!runId) {
|
|
200
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to watch workflow" });
|
|
201
|
+
}
|
|
202
|
+
const workflow = mastra.vnext_getWorkflow(workflowId);
|
|
203
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
204
|
+
if (!run) {
|
|
205
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
206
|
+
}
|
|
207
|
+
const _run = workflow.createRun({ runId });
|
|
208
|
+
let unwatch;
|
|
209
|
+
let asyncRef = null;
|
|
210
|
+
const stream = new web.ReadableStream({
|
|
211
|
+
start(controller) {
|
|
212
|
+
unwatch = _run.watch(({ type, payload, eventTimestamp }) => {
|
|
213
|
+
controller.enqueue(JSON.stringify({ type, payload, eventTimestamp, runId }));
|
|
214
|
+
if (asyncRef) {
|
|
215
|
+
clearImmediate(asyncRef);
|
|
216
|
+
asyncRef = null;
|
|
217
|
+
}
|
|
218
|
+
asyncRef = setImmediate(async () => {
|
|
219
|
+
const runDone = payload.workflowState.status !== "running";
|
|
220
|
+
if (runDone) {
|
|
221
|
+
controller.close();
|
|
222
|
+
unwatch?.();
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
cancel() {
|
|
228
|
+
unwatch?.();
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
return stream;
|
|
232
|
+
} catch (error) {
|
|
233
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error watching workflow");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
async function resumeAsyncVNextWorkflowHandler({
|
|
237
|
+
mastra,
|
|
238
|
+
workflowId,
|
|
239
|
+
runId,
|
|
240
|
+
body,
|
|
241
|
+
runtimeContext,
|
|
242
|
+
runtimeContextFromRequest
|
|
243
|
+
}) {
|
|
244
|
+
try {
|
|
245
|
+
if (!workflowId) {
|
|
246
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
247
|
+
}
|
|
248
|
+
if (!runId) {
|
|
249
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to resume workflow" });
|
|
250
|
+
}
|
|
251
|
+
if (!body.step) {
|
|
252
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "step required to resume workflow" });
|
|
253
|
+
}
|
|
254
|
+
const workflow = mastra.vnext_getWorkflow(workflowId);
|
|
255
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
256
|
+
if (!run) {
|
|
257
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
258
|
+
}
|
|
259
|
+
const finalRuntimeContext = new di.RuntimeContext([
|
|
260
|
+
...Array.from(runtimeContext?.entries() ?? []),
|
|
261
|
+
...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
|
|
262
|
+
]);
|
|
263
|
+
const _run = workflow.createRun({ runId });
|
|
264
|
+
const result = await _run.resume({
|
|
265
|
+
step: body.step,
|
|
266
|
+
resumeData: body.resumeData,
|
|
267
|
+
runtimeContext: finalRuntimeContext
|
|
268
|
+
});
|
|
269
|
+
return result;
|
|
270
|
+
} catch (error) {
|
|
271
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error resuming workflow step");
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
async function resumeVNextWorkflowHandler({
|
|
275
|
+
mastra,
|
|
276
|
+
workflowId,
|
|
277
|
+
runId,
|
|
278
|
+
body,
|
|
279
|
+
runtimeContext
|
|
280
|
+
}) {
|
|
281
|
+
try {
|
|
282
|
+
if (!workflowId) {
|
|
283
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
284
|
+
}
|
|
285
|
+
if (!runId) {
|
|
286
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "runId required to resume workflow" });
|
|
287
|
+
}
|
|
288
|
+
if (!body.step) {
|
|
289
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "step required to resume workflow" });
|
|
290
|
+
}
|
|
291
|
+
const workflow = mastra.vnext_getWorkflow(workflowId);
|
|
292
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
293
|
+
if (!run) {
|
|
294
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
295
|
+
}
|
|
296
|
+
const _run = workflow.createRun({ runId });
|
|
297
|
+
void _run.resume({
|
|
298
|
+
step: body.step,
|
|
299
|
+
resumeData: body.resumeData,
|
|
300
|
+
runtimeContext
|
|
301
|
+
});
|
|
302
|
+
return { message: "Workflow run resumed" };
|
|
303
|
+
} catch (error) {
|
|
304
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error resuming workflow");
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
async function getVNextWorkflowRunsHandler({
|
|
308
|
+
mastra,
|
|
309
|
+
workflowId,
|
|
310
|
+
fromDate,
|
|
311
|
+
toDate,
|
|
312
|
+
limit,
|
|
313
|
+
offset,
|
|
314
|
+
resourceId
|
|
315
|
+
}) {
|
|
316
|
+
try {
|
|
317
|
+
if (!workflowId) {
|
|
318
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
319
|
+
}
|
|
320
|
+
const workflow = mastra.vnext_getWorkflow(workflowId);
|
|
321
|
+
const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
|
|
322
|
+
runs: [],
|
|
323
|
+
total: 0
|
|
324
|
+
};
|
|
325
|
+
return workflowRuns;
|
|
326
|
+
} catch (error) {
|
|
327
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting workflow runs");
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
exports.createVNextWorkflowRunHandler = createVNextWorkflowRunHandler;
|
|
332
|
+
exports.getVNextWorkflowByIdHandler = getVNextWorkflowByIdHandler;
|
|
333
|
+
exports.getVNextWorkflowRunByIdHandler = getVNextWorkflowRunByIdHandler;
|
|
334
|
+
exports.getVNextWorkflowRunsHandler = getVNextWorkflowRunsHandler;
|
|
335
|
+
exports.getVNextWorkflowsHandler = getVNextWorkflowsHandler;
|
|
336
|
+
exports.resumeAsyncVNextWorkflowHandler = resumeAsyncVNextWorkflowHandler;
|
|
337
|
+
exports.resumeVNextWorkflowHandler = resumeVNextWorkflowHandler;
|
|
338
|
+
exports.startAsyncVNextWorkflowHandler = startAsyncVNextWorkflowHandler;
|
|
339
|
+
exports.startVNextWorkflowRunHandler = startVNextWorkflowRunHandler;
|
|
340
|
+
exports.vNextWorkflows_exports = vNextWorkflows_exports;
|
|
341
|
+
exports.watchVNextWorkflowHandler = watchVNextWorkflowHandler;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
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');
|
|
7
|
+
|
|
8
|
+
// src/server/handlers/network.ts
|
|
9
|
+
var network_exports = {};
|
|
10
|
+
chunk75ZPJI57_cjs.__export(network_exports, {
|
|
11
|
+
generateHandler: () => generateHandler,
|
|
12
|
+
getNetworkByIdHandler: () => getNetworkByIdHandler,
|
|
13
|
+
getNetworksHandler: () => getNetworksHandler,
|
|
14
|
+
streamGenerateHandler: () => streamGenerateHandler
|
|
15
|
+
});
|
|
16
|
+
async function getNetworksHandler({
|
|
17
|
+
mastra,
|
|
18
|
+
runtimeContext
|
|
19
|
+
}) {
|
|
20
|
+
try {
|
|
21
|
+
const networks = mastra.getNetworks();
|
|
22
|
+
const serializedNetworks = await Promise.all(
|
|
23
|
+
networks.map(async (network) => {
|
|
24
|
+
const routingAgent = network.getRoutingAgent();
|
|
25
|
+
const routingLLM = await routingAgent.getLLM({ runtimeContext });
|
|
26
|
+
const agents = network.getAgents();
|
|
27
|
+
return {
|
|
28
|
+
id: network.formatAgentId(routingAgent.name),
|
|
29
|
+
name: routingAgent.name,
|
|
30
|
+
instructions: routingAgent.instructions,
|
|
31
|
+
agents: await Promise.all(
|
|
32
|
+
agents.map(async (agent) => {
|
|
33
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
34
|
+
return {
|
|
35
|
+
name: agent.name,
|
|
36
|
+
provider: llm?.getProvider(),
|
|
37
|
+
modelId: llm?.getModelId()
|
|
38
|
+
};
|
|
39
|
+
})
|
|
40
|
+
),
|
|
41
|
+
routingModel: {
|
|
42
|
+
provider: routingLLM?.getProvider(),
|
|
43
|
+
modelId: routingLLM?.getModelId()
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
return serializedNetworks;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting networks");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async function getNetworkByIdHandler({
|
|
54
|
+
mastra,
|
|
55
|
+
networkId,
|
|
56
|
+
runtimeContext
|
|
57
|
+
}) {
|
|
58
|
+
try {
|
|
59
|
+
const networks = mastra.getNetworks();
|
|
60
|
+
const network = networks.find((network2) => {
|
|
61
|
+
const routingAgent2 = network2.getRoutingAgent();
|
|
62
|
+
return network2.formatAgentId(routingAgent2.name) === networkId;
|
|
63
|
+
});
|
|
64
|
+
if (!network) {
|
|
65
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Network not found" });
|
|
66
|
+
}
|
|
67
|
+
const routingAgent = network.getRoutingAgent();
|
|
68
|
+
const routingLLM = await routingAgent.getLLM({ runtimeContext });
|
|
69
|
+
const agents = network.getAgents();
|
|
70
|
+
const serializedNetwork = {
|
|
71
|
+
id: network.formatAgentId(routingAgent.name),
|
|
72
|
+
name: routingAgent.name,
|
|
73
|
+
instructions: routingAgent.instructions,
|
|
74
|
+
agents: await Promise.all(
|
|
75
|
+
agents.map(async (agent) => {
|
|
76
|
+
const llm = await agent.getLLM({ runtimeContext });
|
|
77
|
+
return {
|
|
78
|
+
name: agent.name,
|
|
79
|
+
provider: llm?.getProvider(),
|
|
80
|
+
modelId: llm?.getModelId()
|
|
81
|
+
};
|
|
82
|
+
})
|
|
83
|
+
),
|
|
84
|
+
routingModel: {
|
|
85
|
+
provider: routingLLM?.getProvider(),
|
|
86
|
+
modelId: routingLLM?.getModelId()
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
return serializedNetwork;
|
|
90
|
+
} catch (error) {
|
|
91
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting network by ID");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function generateHandler({
|
|
95
|
+
mastra,
|
|
96
|
+
runtimeContext,
|
|
97
|
+
networkId,
|
|
98
|
+
body
|
|
99
|
+
}) {
|
|
100
|
+
try {
|
|
101
|
+
const network = mastra.getNetwork(networkId);
|
|
102
|
+
if (!network) {
|
|
103
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Network not found" });
|
|
104
|
+
}
|
|
105
|
+
chunk57CJTIPW_cjs.validateBody({ messages: body.messages });
|
|
106
|
+
const { messages, ...rest } = body;
|
|
107
|
+
const result = await network.generate(messages, { ...rest, runtimeContext });
|
|
108
|
+
return result;
|
|
109
|
+
} catch (error) {
|
|
110
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error generating from network");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async function streamGenerateHandler({
|
|
114
|
+
mastra,
|
|
115
|
+
networkId,
|
|
116
|
+
body,
|
|
117
|
+
runtimeContext
|
|
118
|
+
}) {
|
|
119
|
+
try {
|
|
120
|
+
const network = mastra.getNetwork(networkId);
|
|
121
|
+
if (!network) {
|
|
122
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Network not found" });
|
|
123
|
+
}
|
|
124
|
+
chunk57CJTIPW_cjs.validateBody({ messages: body.messages });
|
|
125
|
+
const { messages, output, ...rest } = body;
|
|
126
|
+
const streamResult = await network.stream(messages, {
|
|
127
|
+
output,
|
|
128
|
+
...rest,
|
|
129
|
+
runtimeContext
|
|
130
|
+
});
|
|
131
|
+
const streamResponse = output ? streamResult.toTextStreamResponse() : streamResult.toDataStreamResponse({
|
|
132
|
+
sendUsage: true,
|
|
133
|
+
sendReasoning: true,
|
|
134
|
+
getErrorMessage: (error) => {
|
|
135
|
+
return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
return streamResponse;
|
|
139
|
+
} catch (error) {
|
|
140
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error streaming from network");
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
exports.generateHandler = generateHandler;
|
|
145
|
+
exports.getNetworkByIdHandler = getNetworkByIdHandler;
|
|
146
|
+
exports.getNetworksHandler = getNetworksHandler;
|
|
147
|
+
exports.network_exports = network_exports;
|
|
148
|
+
exports.streamGenerateHandler = streamGenerateHandler;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { validateBody } from './chunk-
|
|
2
|
-
import { handleError } from './chunk-
|
|
3
|
-
import {
|
|
1
|
+
import { validateBody } from './chunk-H5PTF3Y4.js';
|
|
2
|
+
import { handleError } from './chunk-M5ABIP7D.js';
|
|
3
|
+
import { HTTPException } from './chunk-NYN7KFXL.js';
|
|
4
|
+
import { __export } from './chunk-MLKGABMK.js';
|
|
4
5
|
|
|
5
6
|
// src/server/handlers/memory.ts
|
|
6
7
|
var memory_exports = {};
|
|
@@ -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
|
|