@mastra/server 0.0.0-agui-20250501182100 → 0.0.0-ai-v5-20250625014956
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/README.md +48 -135
- package/dist/_tsup-dts-rollup.d.cts +303 -94
- package/dist/_tsup-dts-rollup.d.ts +303 -94
- package/dist/{chunk-5JNVY6DU.js → chunk-2HXKRRNS.js} +7 -5
- package/dist/{chunk-JPB6RPGB.js → chunk-3CSC35VL.js} +163 -46
- package/dist/{chunk-4JINXASC.js → chunk-55DOQLP6.js} +5 -4
- package/dist/{chunk-QN4KF3BH.cjs → chunk-57CJTIPW.cjs} +2 -2
- package/dist/{chunk-ZLBRQFDD.cjs → chunk-64U3UDTH.cjs} +2 -2
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/chunk-ASKESBJW.cjs +2004 -0
- package/dist/chunk-B36R2PHA.js +504 -0
- package/dist/{chunk-7IWQE76Z.cjs → chunk-B4MQFJ7G.cjs} +16 -10
- package/dist/{chunk-WTHDCRMY.js → chunk-BFOA2QQY.js} +12 -6
- package/dist/{chunk-M56ECCHK.cjs → chunk-BNEY4P4P.cjs} +20 -19
- package/dist/{chunk-M3YJLWTU.js → chunk-CLYX4KLH.js} +63 -52
- package/dist/{chunk-RBQASTUP.js → chunk-EKDOJJMG.js} +26 -6
- package/dist/{chunk-L7XE5QTW.js → chunk-H5PTF3Y4.js} +1 -1
- package/dist/chunk-IMBY5XUG.cjs +86 -0
- package/dist/chunk-LFA7KZS6.cjs +276 -0
- package/dist/{chunk-3AHQ5RGN.js → chunk-M5ABIP7D.js} +1 -1
- package/dist/chunk-MLKGABMK.js +7 -0
- package/dist/{chunk-2FJURXCL.cjs → chunk-NDAWJCUJ.cjs} +56 -36
- package/dist/{chunk-D3G23FP3.cjs → chunk-NGURCFEJ.cjs} +24 -22
- package/dist/{chunk-TRDNDNGQ.js → chunk-NYN7KFXL.js} +1 -7
- package/dist/{chunk-FV45V6WC.cjs → chunk-OCWPVYNI.cjs} +0 -7
- package/dist/chunk-QLG2PFHE.js +81 -0
- package/dist/{chunk-5YGDYMRB.cjs → chunk-QOHBG2JI.cjs} +22 -19
- package/dist/{chunk-Q6SHQECN.js → chunk-R5VGYBV6.js} +34 -10
- package/dist/{chunk-QJ3AHN64.js → chunk-SAR3AYOK.js} +12 -9
- package/dist/chunk-T7WA465P.cjs +512 -0
- package/dist/chunk-TGJMNUYJ.js +2001 -0
- package/dist/{chunk-Y3SV5XK4.js → chunk-WC7U7A6Y.js} +104 -17
- package/dist/chunk-WE32JG64.cjs +332 -0
- package/dist/chunk-WJY57THV.cjs +118 -0
- package/dist/chunk-XUTX4CAB.cjs +435 -0
- 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 +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 +21 -13
- package/dist/server/handlers/workflows.d.cts +4 -2
- package/dist/server/handlers/workflows.d.ts +4 -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 +13 -12
- 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-OMN3UI6X.js +0 -5576
- package/dist/chunk-SKBVVI24.cjs +0 -54
- 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
|
@@ -1,7 +1,10 @@
|
|
|
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-TGJMNUYJ.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 { createV4CompatibleResponse } from '@mastra/core/agent';
|
|
7
|
+
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
5
8
|
|
|
6
9
|
// src/server/handlers/agents.ts
|
|
7
10
|
var agents_exports = {};
|
|
@@ -21,6 +24,8 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
|
21
24
|
const instructions = await agent.getInstructions({ runtimeContext });
|
|
22
25
|
const tools = await agent.getTools({ runtimeContext });
|
|
23
26
|
const llm = await agent.getLLM({ runtimeContext });
|
|
27
|
+
const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext });
|
|
28
|
+
const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext });
|
|
24
29
|
const serializedAgentTools = Object.entries(tools || {}).reduce((acc, [key, tool]) => {
|
|
25
30
|
const _tool = tool;
|
|
26
31
|
acc[key] = {
|
|
@@ -30,13 +35,33 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
|
30
35
|
};
|
|
31
36
|
return acc;
|
|
32
37
|
}, {});
|
|
38
|
+
let serializedAgentWorkflows = {};
|
|
39
|
+
if ("getWorkflows" in agent) {
|
|
40
|
+
const logger = mastra.getLogger();
|
|
41
|
+
try {
|
|
42
|
+
const workflows = await agent.getWorkflows({ runtimeContext });
|
|
43
|
+
serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
|
|
44
|
+
return {
|
|
45
|
+
...acc,
|
|
46
|
+
[key]: {
|
|
47
|
+
name: workflow.name
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}, {});
|
|
51
|
+
} catch (error) {
|
|
52
|
+
logger.error("Error getting workflows for agent", { agentName: agent.name, error });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
33
55
|
return {
|
|
34
56
|
id,
|
|
35
57
|
name: agent.name,
|
|
36
58
|
instructions,
|
|
37
59
|
tools: serializedAgentTools,
|
|
60
|
+
workflows: serializedAgentWorkflows,
|
|
38
61
|
provider: llm?.getProvider(),
|
|
39
|
-
modelId: llm?.getModelId()
|
|
62
|
+
modelId: llm?.getModelId(),
|
|
63
|
+
defaultGenerateOptions,
|
|
64
|
+
defaultStreamOptions
|
|
40
65
|
};
|
|
41
66
|
})
|
|
42
67
|
);
|
|
@@ -52,7 +77,8 @@ async function getAgentsHandler({ mastra, runtimeContext }) {
|
|
|
52
77
|
async function getAgentByIdHandler({
|
|
53
78
|
mastra,
|
|
54
79
|
runtimeContext,
|
|
55
|
-
agentId
|
|
80
|
+
agentId,
|
|
81
|
+
isPlayground = false
|
|
56
82
|
}) {
|
|
57
83
|
try {
|
|
58
84
|
const agent = mastra.getAgent(agentId);
|
|
@@ -69,14 +95,59 @@ async function getAgentByIdHandler({
|
|
|
69
95
|
};
|
|
70
96
|
return acc;
|
|
71
97
|
}, {});
|
|
72
|
-
|
|
98
|
+
let serializedAgentWorkflows = {};
|
|
99
|
+
if ("getWorkflows" in agent) {
|
|
100
|
+
const logger = mastra.getLogger();
|
|
101
|
+
try {
|
|
102
|
+
const workflows = await agent.getWorkflows({ runtimeContext });
|
|
103
|
+
serializedAgentWorkflows = Object.entries(workflows || {}).reduce((acc, [key, workflow]) => {
|
|
104
|
+
return {
|
|
105
|
+
...acc,
|
|
106
|
+
[key]: {
|
|
107
|
+
name: workflow.name,
|
|
108
|
+
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
109
|
+
return {
|
|
110
|
+
...acc2,
|
|
111
|
+
[key2]: {
|
|
112
|
+
id: step.id,
|
|
113
|
+
description: step.description
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}, {})
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}, {});
|
|
120
|
+
} catch (error) {
|
|
121
|
+
logger.error("Error getting workflows for agent", { agentName: agent.name, error });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
let proxyRuntimeContext = runtimeContext;
|
|
125
|
+
if (isPlayground) {
|
|
126
|
+
proxyRuntimeContext = new Proxy(runtimeContext, {
|
|
127
|
+
get(target, prop) {
|
|
128
|
+
if (prop === "get") {
|
|
129
|
+
return function(key) {
|
|
130
|
+
const value = target.get(key);
|
|
131
|
+
return value ?? `<${key}>`;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return Reflect.get(target, prop);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
const instructions = await agent.getInstructions({ runtimeContext: proxyRuntimeContext });
|
|
73
139
|
const llm = await agent.getLLM({ runtimeContext });
|
|
140
|
+
const defaultGenerateOptions = await agent.getDefaultGenerateOptions({ runtimeContext: proxyRuntimeContext });
|
|
141
|
+
const defaultStreamOptions = await agent.getDefaultStreamOptions({ runtimeContext: proxyRuntimeContext });
|
|
74
142
|
return {
|
|
75
143
|
name: agent.name,
|
|
76
144
|
instructions,
|
|
77
145
|
tools: serializedAgentTools,
|
|
146
|
+
workflows: serializedAgentWorkflows,
|
|
78
147
|
provider: llm?.getProvider(),
|
|
79
|
-
modelId: llm?.getModelId()
|
|
148
|
+
modelId: llm?.getModelId(),
|
|
149
|
+
defaultGenerateOptions,
|
|
150
|
+
defaultStreamOptions
|
|
80
151
|
};
|
|
81
152
|
} catch (error) {
|
|
82
153
|
return handleError(error, "Error getting agent");
|
|
@@ -131,14 +202,18 @@ async function generateHandler({
|
|
|
131
202
|
if (!agent) {
|
|
132
203
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
133
204
|
}
|
|
134
|
-
const { messages, resourceId, resourceid, ...rest } = body;
|
|
205
|
+
const { messages, resourceId, resourceid, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
135
206
|
const finalResourceId = resourceId ?? resourceid;
|
|
207
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
208
|
+
...Array.from(runtimeContext.entries()),
|
|
209
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
210
|
+
]);
|
|
136
211
|
validateBody({ messages });
|
|
137
212
|
const result = await agent.generate(messages, {
|
|
138
213
|
...rest,
|
|
139
214
|
// @ts-expect-error TODO fix types
|
|
140
215
|
resourceId: finalResourceId,
|
|
141
|
-
runtimeContext
|
|
216
|
+
runtimeContext: finalRuntimeContext
|
|
142
217
|
});
|
|
143
218
|
return result;
|
|
144
219
|
} catch (error) {
|
|
@@ -156,22 +231,34 @@ async function streamGenerateHandler({
|
|
|
156
231
|
if (!agent) {
|
|
157
232
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
158
233
|
}
|
|
159
|
-
const { messages, resourceId,
|
|
160
|
-
const
|
|
234
|
+
const { messages, resourceId, runtimeContext: agentRuntimeContext, ...rest } = body;
|
|
235
|
+
const finalRuntimeContext = new RuntimeContext([
|
|
236
|
+
...Array.from(runtimeContext.entries()),
|
|
237
|
+
...Array.from(Object.entries(agentRuntimeContext ?? {}))
|
|
238
|
+
]);
|
|
161
239
|
validateBody({ messages });
|
|
162
240
|
const streamResult = await agent.stream(messages, {
|
|
163
241
|
...rest,
|
|
164
242
|
// @ts-expect-error TODO fix types
|
|
165
|
-
resourceId
|
|
166
|
-
runtimeContext
|
|
243
|
+
resourceId,
|
|
244
|
+
runtimeContext: finalRuntimeContext
|
|
167
245
|
});
|
|
168
|
-
const
|
|
169
|
-
|
|
246
|
+
const headers = {
|
|
247
|
+
"Transfer-Encoding": "chunked"
|
|
248
|
+
};
|
|
249
|
+
if (rest.output) {
|
|
250
|
+
return streamResult.toTextStreamResponse({ headers });
|
|
251
|
+
}
|
|
252
|
+
const useV4Compat = mastra.getAiSdkCompatMode() === "v4";
|
|
253
|
+
const uiMessageStream = streamResult.toUIMessageStreamResponse({
|
|
254
|
+
headers,
|
|
170
255
|
sendReasoning: true,
|
|
171
|
-
|
|
256
|
+
sendSources: true,
|
|
257
|
+
onError: (error) => {
|
|
172
258
|
return `An error occurred while processing your request. ${error instanceof Error ? error.message : JSON.stringify(error)}`;
|
|
173
259
|
}
|
|
174
260
|
});
|
|
261
|
+
const streamResponse = useV4Compat ? createV4CompatibleResponse(uiMessageStream.body) : uiMessageStream;
|
|
175
262
|
return streamResponse;
|
|
176
263
|
} catch (error) {
|
|
177
264
|
throw new HTTPException(error?.status ?? 500, { message: error?.message ?? "Error streaming from agent" });
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkASKESBJW_cjs = require('./chunk-ASKESBJW.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 ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_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 ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(_step.inputSchema)) : void 0,
|
|
42
|
+
outputSchema: _step.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_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 ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_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 ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_cjs.esm_default(_step.inputSchema)) : void 0,
|
|
77
|
+
outputSchema: _step.outputSchema ? chunkASKESBJW_cjs.stringify(chunkASKESBJW_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;
|
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
var stream = require('stream');
|
|
8
|
+
|
|
9
|
+
// src/server/handlers/voice.ts
|
|
10
|
+
var voice_exports = {};
|
|
11
|
+
chunk75ZPJI57_cjs.__export(voice_exports, {
|
|
12
|
+
generateSpeechHandler: () => generateSpeechHandler,
|
|
13
|
+
getListenerHandler: () => getListenerHandler,
|
|
14
|
+
getSpeakersHandler: () => getSpeakersHandler,
|
|
15
|
+
transcribeSpeechHandler: () => transcribeSpeechHandler
|
|
16
|
+
});
|
|
17
|
+
async function getSpeakersHandler({ mastra, agentId }) {
|
|
18
|
+
try {
|
|
19
|
+
if (!agentId) {
|
|
20
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent ID is required" });
|
|
21
|
+
}
|
|
22
|
+
const agent = mastra.getAgent(agentId);
|
|
23
|
+
if (!agent) {
|
|
24
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
25
|
+
}
|
|
26
|
+
const voice = await agent.getVoice();
|
|
27
|
+
if (!voice) {
|
|
28
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
29
|
+
}
|
|
30
|
+
const speakers = await voice.getSpeakers();
|
|
31
|
+
return speakers;
|
|
32
|
+
} catch (error) {
|
|
33
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting speakers");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function generateSpeechHandler({
|
|
37
|
+
mastra,
|
|
38
|
+
agentId,
|
|
39
|
+
body
|
|
40
|
+
}) {
|
|
41
|
+
try {
|
|
42
|
+
if (!agentId) {
|
|
43
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent ID is required" });
|
|
44
|
+
}
|
|
45
|
+
chunk57CJTIPW_cjs.validateBody({
|
|
46
|
+
text: body?.text
|
|
47
|
+
});
|
|
48
|
+
const agent = mastra.getAgent(agentId);
|
|
49
|
+
if (!agent) {
|
|
50
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
51
|
+
}
|
|
52
|
+
const voice = await agent.getVoice();
|
|
53
|
+
if (!voice) {
|
|
54
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
55
|
+
}
|
|
56
|
+
const audioStream = await voice.speak(body.text, { speaker: body.speakerId });
|
|
57
|
+
if (!audioStream) {
|
|
58
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(500, { message: "Failed to generate speech" });
|
|
59
|
+
}
|
|
60
|
+
return audioStream;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error generating speech");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function transcribeSpeechHandler({
|
|
66
|
+
mastra,
|
|
67
|
+
agentId,
|
|
68
|
+
body
|
|
69
|
+
}) {
|
|
70
|
+
try {
|
|
71
|
+
if (!agentId) {
|
|
72
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent ID is required" });
|
|
73
|
+
}
|
|
74
|
+
if (!body?.audioData) {
|
|
75
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Audio data is required" });
|
|
76
|
+
}
|
|
77
|
+
const agent = mastra.getAgent(agentId);
|
|
78
|
+
if (!agent) {
|
|
79
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
80
|
+
}
|
|
81
|
+
const voice = await agent.getVoice();
|
|
82
|
+
if (!voice) {
|
|
83
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
84
|
+
}
|
|
85
|
+
const audioStream = new stream.Readable();
|
|
86
|
+
audioStream.push(body.audioData);
|
|
87
|
+
audioStream.push(null);
|
|
88
|
+
const text = await voice.listen(audioStream, body.options);
|
|
89
|
+
return { text };
|
|
90
|
+
} catch (error) {
|
|
91
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error transcribing speech");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function getListenerHandler({ mastra, agentId }) {
|
|
95
|
+
try {
|
|
96
|
+
if (!agentId) {
|
|
97
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent ID is required" });
|
|
98
|
+
}
|
|
99
|
+
const agent = mastra.getAgent(agentId);
|
|
100
|
+
if (!agent) {
|
|
101
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(404, { message: "Agent not found" });
|
|
102
|
+
}
|
|
103
|
+
const voice = await agent.getVoice();
|
|
104
|
+
if (!voice) {
|
|
105
|
+
throw new chunkOCWPVYNI_cjs.HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
106
|
+
}
|
|
107
|
+
const listeners = await voice.getListener();
|
|
108
|
+
return listeners;
|
|
109
|
+
} catch (error) {
|
|
110
|
+
return chunk64U3UDTH_cjs.handleError(error, "Error getting listeners");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
exports.generateSpeechHandler = generateSpeechHandler;
|
|
115
|
+
exports.getListenerHandler = getListenerHandler;
|
|
116
|
+
exports.getSpeakersHandler = getSpeakersHandler;
|
|
117
|
+
exports.transcribeSpeechHandler = transcribeSpeechHandler;
|
|
118
|
+
exports.voice_exports = voice_exports;
|