@mastra/server 0.0.0-cloud-transporter-20250513033346 → 0.0.0-cloud-deployer-for-core-0.19.1-20251001164939
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/CHANGELOG.md +3867 -0
- package/LICENSE.md +11 -42
- package/README.md +0 -5
- package/dist/{chunk-H5PTF3Y4.js → chunk-4QCXUEAT.js} +11 -2
- package/dist/chunk-4QCXUEAT.js.map +1 -0
- package/dist/chunk-4RRMWXQ2.js +3522 -0
- package/dist/chunk-4RRMWXQ2.js.map +1 -0
- package/dist/chunk-4VJG7FZK.cjs +18023 -0
- package/dist/chunk-4VJG7FZK.cjs.map +1 -0
- package/dist/chunk-52UP7DFT.cjs +130 -0
- package/dist/chunk-52UP7DFT.cjs.map +1 -0
- package/dist/chunk-6GMFZ5LK.js +2774 -0
- package/dist/chunk-6GMFZ5LK.js.map +1 -0
- package/dist/{chunk-P6SCPDYW.js → chunk-6IJWRJZE.js} +114 -137
- package/dist/chunk-6IJWRJZE.js.map +1 -0
- package/dist/{chunk-OCWPVYNI.cjs → chunk-7NADHFD2.cjs} +3 -0
- package/dist/chunk-7NADHFD2.cjs.map +1 -0
- package/dist/chunk-A3AL7EWJ.js +83 -0
- package/dist/chunk-A3AL7EWJ.js.map +1 -0
- package/dist/chunk-BKCWZLEL.cjs +197 -0
- package/dist/chunk-BKCWZLEL.cjs.map +1 -0
- package/dist/chunk-BX5XPVO2.cjs +676 -0
- package/dist/chunk-BX5XPVO2.cjs.map +1 -0
- package/dist/chunk-CY4TP3FK.js +16 -0
- package/dist/chunk-CY4TP3FK.js.map +1 -0
- package/dist/chunk-EMMSS5I5.cjs +37 -0
- package/dist/chunk-EMMSS5I5.cjs.map +1 -0
- package/dist/chunk-FALVL2VV.cjs +3525 -0
- package/dist/chunk-FALVL2VV.cjs.map +1 -0
- package/dist/chunk-G3PMV62Z.js +33 -0
- package/dist/chunk-G3PMV62Z.js.map +1 -0
- package/dist/chunk-G4PUALCE.cjs +28 -0
- package/dist/chunk-G4PUALCE.cjs.map +1 -0
- package/dist/chunk-GU4EWMZB.cjs +769 -0
- package/dist/chunk-GU4EWMZB.cjs.map +1 -0
- package/dist/chunk-HCFCPUTA.cjs +601 -0
- package/dist/chunk-HCFCPUTA.cjs.map +1 -0
- package/dist/chunk-HFEPCQAR.js +655 -0
- package/dist/chunk-HFEPCQAR.js.map +1 -0
- package/dist/{chunk-YWLUOY3D.cjs → chunk-HVBBFCDH.cjs} +1110 -793
- package/dist/chunk-HVBBFCDH.cjs.map +1 -0
- package/dist/chunk-JLPZWKPR.js +582 -0
- package/dist/chunk-JLPZWKPR.js.map +1 -0
- package/dist/{chunk-HFWCEP5S.js → chunk-JRDEOHAJ.js} +47 -14
- package/dist/chunk-JRDEOHAJ.js.map +1 -0
- package/dist/{chunk-TJKLBTFB.js → chunk-KM7EJKXV.js} +55 -27
- package/dist/chunk-KM7EJKXV.js.map +1 -0
- package/dist/chunk-KNGXRN26.cjs +335 -0
- package/dist/chunk-KNGXRN26.cjs.map +1 -0
- package/dist/{chunk-OR3CIE2H.js → chunk-KV6VHX4V.js} +29 -7
- package/dist/chunk-KV6VHX4V.js.map +1 -0
- package/dist/chunk-LF2ZLOFP.js +767 -0
- package/dist/chunk-LF2ZLOFP.js.map +1 -0
- package/dist/chunk-LJFAAEU7.cjs +167 -0
- package/dist/chunk-LJFAAEU7.cjs.map +1 -0
- package/dist/{chunk-NYN7KFXL.js → chunk-MMROOK5J.js} +3 -0
- package/dist/chunk-MMROOK5J.js.map +1 -0
- package/dist/{chunk-LIVAK2DM.js → chunk-N7F33WAD.js} +1083 -794
- package/dist/chunk-N7F33WAD.js.map +1 -0
- package/dist/chunk-NG5IVLEZ.js +1012 -0
- package/dist/chunk-NG5IVLEZ.js.map +1 -0
- package/dist/chunk-NLWACBE7.cjs +128 -0
- package/dist/chunk-NLWACBE7.cjs.map +1 -0
- package/dist/{chunk-5SN4U5AC.cjs → chunk-OPI3FZYH.cjs} +115 -138
- package/dist/chunk-OPI3FZYH.cjs.map +1 -0
- package/dist/chunk-OZLRIVC4.cjs +588 -0
- package/dist/chunk-OZLRIVC4.cjs.map +1 -0
- package/dist/chunk-PPYGWINI.cjs +2777 -0
- package/dist/chunk-PPYGWINI.cjs.map +1 -0
- package/dist/{chunk-MHKNLNAN.cjs → chunk-PWTXZZTR.cjs} +33 -10
- package/dist/chunk-PWTXZZTR.cjs.map +1 -0
- package/dist/chunk-RE4RPXT2.cjs +18 -0
- package/dist/chunk-RE4RPXT2.cjs.map +1 -0
- package/dist/chunk-SIGXR3JT.cjs +1043 -0
- package/dist/chunk-SIGXR3JT.cjs.map +1 -0
- package/dist/chunk-SPLSYTYW.cjs +88 -0
- package/dist/chunk-SPLSYTYW.cjs.map +1 -0
- package/dist/chunk-SQY4T6EJ.js +571 -0
- package/dist/chunk-SQY4T6EJ.js.map +1 -0
- package/dist/{chunk-4YZ3U35L.cjs → chunk-T3TIA3O6.cjs} +22 -20
- package/dist/chunk-T3TIA3O6.cjs.map +1 -0
- package/dist/{chunk-EJO45KYT.js → chunk-TTHEEIZ3.js} +53 -50
- package/dist/chunk-TTHEEIZ3.js.map +1 -0
- package/dist/chunk-VY4ENABS.cjs +135 -0
- package/dist/chunk-VY4ENABS.cjs.map +1 -0
- package/dist/{chunk-IU5VO2I2.js → chunk-WHN4VX55.js} +7 -5
- package/dist/chunk-WHN4VX55.js.map +1 -0
- package/dist/chunk-WUJLVNLU.js +124 -0
- package/dist/chunk-WUJLVNLU.js.map +1 -0
- package/dist/chunk-XJOYGRTN.js +189 -0
- package/dist/chunk-XJOYGRTN.js.map +1 -0
- package/dist/chunk-YGQ5F6E6.js +17987 -0
- package/dist/chunk-YGQ5F6E6.js.map +1 -0
- package/dist/chunk-YWOK4F5A.js +131 -0
- package/dist/chunk-YWOK4F5A.js.map +1 -0
- package/dist/dist-26HWEQY6.js +3 -0
- package/dist/dist-26HWEQY6.js.map +1 -0
- package/dist/dist-3DRD6USP.cjs +1411 -0
- package/dist/dist-3DRD6USP.cjs.map +1 -0
- package/dist/dist-7GVM5ZCS.js +845 -0
- package/dist/dist-7GVM5ZCS.js.map +1 -0
- package/dist/dist-CCDXEZDR.js +1408 -0
- package/dist/dist-CCDXEZDR.js.map +1 -0
- package/dist/dist-COC6WFAX.js +761 -0
- package/dist/dist-COC6WFAX.js.map +1 -0
- package/dist/dist-EZZMMMNT.cjs +16 -0
- package/dist/dist-EZZMMMNT.cjs.map +1 -0
- package/dist/dist-H64VX6DE.js +3 -0
- package/dist/dist-H64VX6DE.js.map +1 -0
- package/dist/dist-H7RR3EXL.js +2006 -0
- package/dist/dist-H7RR3EXL.js.map +1 -0
- package/dist/dist-JNIWWFE5.js +1147 -0
- package/dist/dist-JNIWWFE5.js.map +1 -0
- package/dist/dist-L76NFIWM.cjs +934 -0
- package/dist/dist-L76NFIWM.cjs.map +1 -0
- package/dist/dist-LKU3RRT2.js +937 -0
- package/dist/dist-LKU3RRT2.js.map +1 -0
- package/dist/dist-MQUZENT7.js +931 -0
- package/dist/dist-MQUZENT7.js.map +1 -0
- package/dist/dist-N6P7NYGX.cjs +928 -0
- package/dist/dist-N6P7NYGX.cjs.map +1 -0
- package/dist/dist-OC4J73ML.cjs +940 -0
- package/dist/dist-OC4J73ML.cjs.map +1 -0
- package/dist/dist-QI7RYOYQ.cjs +764 -0
- package/dist/dist-QI7RYOYQ.cjs.map +1 -0
- package/dist/dist-R3L5J3LL.cjs +1150 -0
- package/dist/dist-R3L5J3LL.cjs.map +1 -0
- package/dist/dist-S3ILRJUH.cjs +2013 -0
- package/dist/dist-S3ILRJUH.cjs.map +1 -0
- package/dist/dist-WKYB3LTJ.cjs +16 -0
- package/dist/dist-WKYB3LTJ.cjs.map +1 -0
- package/dist/dist-WY4WSW7C.cjs +849 -0
- package/dist/dist-WY4WSW7C.cjs.map +1 -0
- package/dist/dist-ZHCN47XA.js +925 -0
- package/dist/dist-ZHCN47XA.js.map +1 -0
- package/dist/index.cjs +6 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/server/a2a/protocol.d.ts +8 -0
- package/dist/server/a2a/protocol.d.ts.map +1 -0
- package/dist/server/a2a/store.cjs +25 -0
- package/dist/server/a2a/store.cjs.map +1 -0
- package/dist/server/a2a/store.d.ts +14 -0
- package/dist/server/a2a/store.d.ts.map +1 -0
- package/dist/server/a2a/store.js +23 -0
- package/dist/server/a2a/store.js.map +1 -0
- package/dist/server/a2a/tasks.d.ts +20 -0
- package/dist/server/a2a/tasks.d.ts.map +1 -0
- package/dist/server/handlers/a2a.cjs +13 -11
- package/dist/server/handlers/a2a.cjs.map +1 -0
- package/dist/server/handlers/a2a.d.ts +68 -6
- package/dist/server/handlers/a2a.d.ts.map +1 -0
- package/dist/server/handlers/a2a.js +3 -1
- package/dist/server/handlers/a2a.js.map +1 -0
- package/dist/server/handlers/agent-builder.cjs +68 -0
- package/dist/server/handlers/agent-builder.cjs.map +1 -0
- package/dist/server/handlers/agent-builder.d.ts +94 -0
- package/dist/server/handlers/agent-builder.d.ts.map +1 -0
- package/dist/server/handlers/agent-builder.js +3 -0
- package/dist/server/handlers/agent-builder.js.map +1 -0
- package/dist/server/handlers/agents.cjs +61 -7
- package/dist/server/handlers/agents.cjs.map +1 -0
- package/dist/server/handlers/agents.d.ts +216 -6
- package/dist/server/handlers/agents.d.ts.map +1 -0
- package/dist/server/handlers/agents.js +3 -1
- package/dist/server/handlers/agents.js.map +1 -0
- package/dist/server/handlers/error.cjs +4 -2
- package/dist/server/handlers/error.cjs.map +1 -0
- package/dist/server/handlers/error.d.ts +2 -1
- package/dist/server/handlers/error.d.ts.map +1 -0
- package/dist/server/handlers/error.js +3 -1
- package/dist/server/handlers/error.js.map +1 -0
- package/dist/server/handlers/legacyWorkflows.cjs +48 -0
- package/dist/server/handlers/legacyWorkflows.cjs.map +1 -0
- package/dist/server/handlers/legacyWorkflows.d.ts +59 -0
- package/dist/server/handlers/legacyWorkflows.d.ts.map +1 -0
- package/dist/server/handlers/legacyWorkflows.js +3 -0
- package/dist/server/handlers/legacyWorkflows.js.map +1 -0
- package/dist/server/handlers/logs.cjs +6 -4
- package/dist/server/handlers/logs.cjs.map +1 -0
- package/dist/server/handlers/logs.d.ts +34 -3
- package/dist/server/handlers/logs.d.ts.map +1 -0
- package/dist/server/handlers/logs.js +3 -1
- package/dist/server/handlers/logs.js.map +1 -0
- package/dist/server/handlers/memory.cjs +39 -9
- package/dist/server/handlers/memory.cjs.map +1 -0
- package/dist/server/handlers/memory.d.ts +118 -8
- package/dist/server/handlers/memory.d.ts.map +1 -0
- package/dist/server/handlers/memory.js +3 -1
- package/dist/server/handlers/memory.js.map +1 -0
- package/dist/server/handlers/observability.cjs +24 -0
- package/dist/server/handlers/observability.cjs.map +1 -0
- package/dist/server/handlers/observability.d.ts +49 -0
- package/dist/server/handlers/observability.d.ts.map +1 -0
- package/dist/server/handlers/observability.js +3 -0
- package/dist/server/handlers/observability.js.map +1 -0
- package/dist/server/handlers/scores.cjs +32 -0
- package/dist/server/handlers/scores.cjs.map +1 -0
- package/dist/server/handlers/scores.d.ts +251 -0
- package/dist/server/handlers/scores.d.ts.map +1 -0
- package/dist/server/handlers/scores.js +3 -0
- package/dist/server/handlers/scores.js.map +1 -0
- package/dist/server/handlers/telemetry.cjs +9 -3
- package/dist/server/handlers/telemetry.cjs.map +1 -0
- package/dist/server/handlers/telemetry.d.ts +33 -2
- package/dist/server/handlers/telemetry.d.ts.map +1 -0
- package/dist/server/handlers/telemetry.js +3 -1
- package/dist/server/handlers/telemetry.js.map +1 -0
- package/dist/server/handlers/tools.cjs +11 -5
- package/dist/server/handlers/tools.cjs.map +1 -0
- package/dist/server/handlers/tools.d.ts +25 -4
- package/dist/server/handlers/tools.d.ts.map +1 -0
- package/dist/server/handlers/tools.js +3 -1
- package/dist/server/handlers/tools.js.map +1 -0
- package/dist/server/handlers/utils.cjs +8 -2
- package/dist/server/handlers/utils.cjs.map +1 -0
- package/dist/server/handlers/utils.d.ts +8 -1
- package/dist/server/handlers/utils.d.ts.map +1 -0
- package/dist/server/handlers/utils.js +3 -1
- package/dist/server/handlers/utils.js.map +1 -0
- package/dist/server/handlers/vNextNetwork.cjs +220 -0
- package/dist/server/handlers/vNextNetwork.cjs.map +1 -0
- package/dist/server/handlers/vNextNetwork.d.ts +246 -0
- package/dist/server/handlers/vNextNetwork.d.ts.map +1 -0
- package/dist/server/handlers/vNextNetwork.js +213 -0
- package/dist/server/handlers/vNextNetwork.js.map +1 -0
- package/dist/server/handlers/vector.cjs +9 -7
- package/dist/server/handlers/vector.cjs.map +1 -0
- package/dist/server/handlers/vector.d.ts +51 -6
- package/dist/server/handlers/vector.d.ts.map +1 -0
- package/dist/server/handlers/vector.js +3 -1
- package/dist/server/handlers/vector.js.map +1 -0
- package/dist/server/handlers/voice.cjs +10 -4
- package/dist/server/handlers/voice.cjs.map +1 -0
- package/dist/server/handlers/voice.d.ts +41 -3
- package/dist/server/handlers/voice.d.ts.map +1 -0
- package/dist/server/handlers/voice.js +3 -1
- package/dist/server/handlers/voice.js.map +1 -0
- package/dist/server/handlers/workflows.cjs +43 -13
- package/dist/server/handlers/workflows.cjs.map +1 -0
- package/dist/server/handlers/workflows.d.ts +90 -10
- package/dist/server/handlers/workflows.d.ts.map +1 -0
- package/dist/server/handlers/workflows.js +3 -1
- package/dist/server/handlers/workflows.js.map +1 -0
- package/dist/server/handlers.cjs +44 -32
- package/dist/server/handlers.cjs.map +1 -0
- package/dist/server/handlers.d.ts +14 -11
- package/dist/server/handlers.d.ts.map +1 -0
- package/dist/server/handlers.js +15 -11
- package/dist/server/handlers.js.map +1 -0
- package/dist/server/http-exception.d.ts +87 -0
- package/dist/server/http-exception.d.ts.map +1 -0
- package/dist/server/types.d.ts +10 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server/utils.d.ts +44 -0
- package/dist/server/utils.d.ts.map +1 -0
- package/package.json +43 -21
- package/dist/_tsup-dts-rollup.d.cts +0 -815
- package/dist/_tsup-dts-rollup.d.ts +0 -815
- package/dist/chunk-57CJTIPW.cjs +0 -18
- package/dist/chunk-64U3UDTH.cjs +0 -13
- package/dist/chunk-75ZPJI57.cjs +0 -9
- package/dist/chunk-C7564HUT.js +0 -142
- package/dist/chunk-D4IRYCUI.cjs +0 -235
- package/dist/chunk-DJJIUEL2.js +0 -211
- package/dist/chunk-HWZVAG3H.js +0 -49
- package/dist/chunk-I2B73Y4I.cjs +0 -332
- package/dist/chunk-M5ABIP7D.js +0 -11
- package/dist/chunk-MIQYDLLM.js +0 -329
- package/dist/chunk-MLKGABMK.js +0 -7
- package/dist/chunk-OGCNNUHF.cjs +0 -54
- package/dist/chunk-UCTEMO2Q.cjs +0 -341
- package/dist/chunk-VPNDC2DI.cjs +0 -148
- package/dist/chunk-WUC6LSTW.js +0 -227
- package/dist/chunk-Y7UWRW5X.cjs +0 -221
- package/dist/chunk-YBVOQN4M.cjs +0 -94
- package/dist/chunk-ZE5AAC4I.cjs +0 -138
- package/dist/index.d.cts +0 -1
- package/dist/server/handlers/a2a.d.cts +0 -6
- package/dist/server/handlers/agents.d.cts +0 -6
- package/dist/server/handlers/error.d.cts +0 -1
- package/dist/server/handlers/logs.d.cts +0 -3
- package/dist/server/handlers/memory.d.cts +0 -8
- package/dist/server/handlers/network.cjs +0 -22
- package/dist/server/handlers/network.d.cts +0 -4
- package/dist/server/handlers/network.d.ts +0 -4
- package/dist/server/handlers/network.js +0 -1
- package/dist/server/handlers/telemetry.d.cts +0 -2
- package/dist/server/handlers/tools.d.cts +0 -4
- package/dist/server/handlers/utils.d.cts +0 -1
- 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
- package/dist/server/handlers/vector.d.cts +0 -6
- package/dist/server/handlers/voice.d.cts +0 -3
- package/dist/server/handlers/workflows.d.cts +0 -10
- package/dist/server/handlers.d.cts +0 -11
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { validateBody } from './chunk-
|
|
2
|
-
import { handleError } from './chunk-
|
|
3
|
-
import { HTTPException } from './chunk-
|
|
4
|
-
import { __export } from './chunk-
|
|
1
|
+
import { validateBody } from './chunk-4QCXUEAT.js';
|
|
2
|
+
import { handleError } from './chunk-CY4TP3FK.js';
|
|
3
|
+
import { HTTPException } from './chunk-MMROOK5J.js';
|
|
4
|
+
import { __export } from './chunk-G3PMV62Z.js';
|
|
5
5
|
import { Readable } from 'stream';
|
|
6
|
+
import { MastraError } from '@mastra/core/error';
|
|
6
7
|
|
|
7
8
|
// src/server/handlers/voice.ts
|
|
8
9
|
var voice_exports = {};
|
|
9
10
|
__export(voice_exports, {
|
|
10
11
|
generateSpeechHandler: () => generateSpeechHandler,
|
|
12
|
+
getListenerHandler: () => getListenerHandler,
|
|
11
13
|
getSpeakersHandler: () => getSpeakersHandler,
|
|
12
14
|
transcribeSpeechHandler: () => transcribeSpeechHandler
|
|
13
15
|
});
|
|
14
|
-
async function getSpeakersHandler({ mastra, agentId }) {
|
|
16
|
+
async function getSpeakersHandler({ mastra, agentId, runtimeContext }) {
|
|
15
17
|
try {
|
|
16
18
|
if (!agentId) {
|
|
17
19
|
throw new HTTPException(400, { message: "Agent ID is required" });
|
|
@@ -20,10 +22,11 @@ async function getSpeakersHandler({ mastra, agentId }) {
|
|
|
20
22
|
if (!agent) {
|
|
21
23
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
22
24
|
}
|
|
23
|
-
|
|
25
|
+
const voice = await agent.getVoice({ runtimeContext });
|
|
26
|
+
if (!voice) {
|
|
24
27
|
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
25
28
|
}
|
|
26
|
-
const speakers = await
|
|
29
|
+
const speakers = await voice.getSpeakers();
|
|
27
30
|
return speakers;
|
|
28
31
|
} catch (error) {
|
|
29
32
|
return handleError(error, "Error getting speakers");
|
|
@@ -32,7 +35,8 @@ async function getSpeakersHandler({ mastra, agentId }) {
|
|
|
32
35
|
async function generateSpeechHandler({
|
|
33
36
|
mastra,
|
|
34
37
|
agentId,
|
|
35
|
-
body
|
|
38
|
+
body,
|
|
39
|
+
runtimeContext
|
|
36
40
|
}) {
|
|
37
41
|
try {
|
|
38
42
|
if (!agentId) {
|
|
@@ -45,10 +49,16 @@ async function generateSpeechHandler({
|
|
|
45
49
|
if (!agent) {
|
|
46
50
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
47
51
|
}
|
|
48
|
-
|
|
52
|
+
const voice = await agent.getVoice({ runtimeContext });
|
|
53
|
+
if (!voice) {
|
|
49
54
|
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
50
55
|
}
|
|
51
|
-
const audioStream = await
|
|
56
|
+
const audioStream = await Promise.resolve().then(() => voice.speak(body.text, { speaker: body.speakerId })).catch((err) => {
|
|
57
|
+
if (err instanceof MastraError) {
|
|
58
|
+
throw new HTTPException(400, { message: err.message });
|
|
59
|
+
}
|
|
60
|
+
throw err;
|
|
61
|
+
});
|
|
52
62
|
if (!audioStream) {
|
|
53
63
|
throw new HTTPException(500, { message: "Failed to generate speech" });
|
|
54
64
|
}
|
|
@@ -60,7 +70,8 @@ async function generateSpeechHandler({
|
|
|
60
70
|
async function transcribeSpeechHandler({
|
|
61
71
|
mastra,
|
|
62
72
|
agentId,
|
|
63
|
-
body
|
|
73
|
+
body,
|
|
74
|
+
runtimeContext
|
|
64
75
|
}) {
|
|
65
76
|
try {
|
|
66
77
|
if (!agentId) {
|
|
@@ -73,17 +84,39 @@ async function transcribeSpeechHandler({
|
|
|
73
84
|
if (!agent) {
|
|
74
85
|
throw new HTTPException(404, { message: "Agent not found" });
|
|
75
86
|
}
|
|
76
|
-
|
|
87
|
+
const voice = await agent.getVoice({ runtimeContext });
|
|
88
|
+
if (!voice) {
|
|
77
89
|
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
78
90
|
}
|
|
79
91
|
const audioStream = new Readable();
|
|
80
92
|
audioStream.push(body.audioData);
|
|
81
93
|
audioStream.push(null);
|
|
82
|
-
const text = await
|
|
94
|
+
const text = await voice.listen(audioStream, body.options);
|
|
83
95
|
return { text };
|
|
84
96
|
} catch (error) {
|
|
85
97
|
return handleError(error, "Error transcribing speech");
|
|
86
98
|
}
|
|
87
99
|
}
|
|
100
|
+
async function getListenerHandler({ mastra, agentId, runtimeContext }) {
|
|
101
|
+
try {
|
|
102
|
+
if (!agentId) {
|
|
103
|
+
throw new HTTPException(400, { message: "Agent ID is required" });
|
|
104
|
+
}
|
|
105
|
+
const agent = mastra.getAgent(agentId);
|
|
106
|
+
if (!agent) {
|
|
107
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
108
|
+
}
|
|
109
|
+
const voice = await agent.getVoice({ runtimeContext });
|
|
110
|
+
if (!voice) {
|
|
111
|
+
throw new HTTPException(400, { message: "Agent does not have voice capabilities" });
|
|
112
|
+
}
|
|
113
|
+
const listeners = await voice.getListener();
|
|
114
|
+
return listeners;
|
|
115
|
+
} catch (error) {
|
|
116
|
+
return handleError(error, "Error getting listeners");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
88
119
|
|
|
89
|
-
export { generateSpeechHandler, getSpeakersHandler, transcribeSpeechHandler, voice_exports };
|
|
120
|
+
export { generateSpeechHandler, getListenerHandler, getSpeakersHandler, transcribeSpeechHandler, voice_exports };
|
|
121
|
+
//# sourceMappingURL=chunk-JRDEOHAJ.js.map
|
|
122
|
+
//# sourceMappingURL=chunk-JRDEOHAJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/handlers/voice.ts"],"names":[],"mappings":";;;;;;;;AAAA,IAAA,aAAA,GAAA;AAAA,QAAA,CAAA,aAAA,EAAA;AAAA,EAAA,qBAAA,EAAA,MAAA,qBAAA;AAAA,EAAA,kBAAA,EAAA,MAAA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AAI,CAAC,KAAA,EAAO;AACV,MAAA,MAAM,IAAI,aAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,mBAAmB,CAAA;AAAA,IAC7D;AAEA,IAAA,MAAM,QAAQ,MAAM,KAAA,CAAM,QAAA,CAAS,EAAE,gBAAgB,CAAA;AAErD,IAAA,IAAI,CAAC,KAAA,EAAO;AACV,MAAA,MAAM,IAAI,aAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,0CAA0C,CAAA;AAAA,IACpF;AAEA,IAAA,MAAM,SAAA,GAAY,MAAM,KAAA,CAAM,WAAA,EAAY;AAC1C,IAAA,OAAO,SAAA;AAAA,EACT,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,WAAA,CAAY,OAAO,yBAAyB,CAAA;AAAA,EACrD;AACF","file":"chunk-JRDEOHAJ.js","sourcesContent":["import { Readable } from 'stream';\nimport type { Agent } from '@mastra/core/agent';\nimport { MastraError } from '@mastra/core/error';\nimport type { RuntimeContext } from '@mastra/core/runtime-context';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\n\nimport { handleError } from './error';\nimport { validateBody } from './utils';\n\ninterface VoiceContext extends Context {\n agentId?: string;\n runtimeContext?: RuntimeContext;\n}\n\n/**\n * Get available speakers for an agent\n */\nexport async function getSpeakersHandler({ mastra, agentId, runtimeContext }: VoiceContext) {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const voice = await agent.getVoice({ runtimeContext });\n\n if (!voice) {\n throw new HTTPException(400, { message: 'Agent does not have voice capabilities' });\n }\n\n const speakers = await voice.getSpeakers();\n return speakers;\n } catch (error) {\n return handleError(error, 'Error getting speakers');\n }\n}\n\n/**\n * Generate speech from text\n */\nexport async function generateSpeechHandler({\n mastra,\n agentId,\n body,\n runtimeContext,\n}: VoiceContext & {\n body?: {\n text?: string;\n speakerId?: string;\n };\n}) {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n validateBody({\n text: body?.text,\n });\n\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const voice = await agent.getVoice({ runtimeContext });\n\n if (!voice) {\n throw new HTTPException(400, { message: 'Agent does not have voice capabilities' });\n }\n\n const audioStream = await Promise.resolve()\n .then(() => voice.speak(body!.text!, { speaker: body!.speakerId! }))\n .catch(err => {\n if (err instanceof MastraError) {\n throw new HTTPException(400, { message: err.message });\n }\n\n throw err;\n });\n\n if (!audioStream) {\n throw new HTTPException(500, { message: 'Failed to generate speech' });\n }\n\n return audioStream;\n } catch (error) {\n return handleError(error, 'Error generating speech');\n }\n}\n\n/**\n * Transcribe speech to text\n */\nexport async function transcribeSpeechHandler({\n mastra,\n agentId,\n body,\n runtimeContext,\n}: VoiceContext & {\n body?: {\n audioData?: Buffer;\n options?: Parameters<NonNullable<Agent['voice']>['listen']>[1];\n };\n}) {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n if (!body?.audioData) {\n throw new HTTPException(400, { message: 'Audio data is required' });\n }\n\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const voice = await agent.getVoice({ runtimeContext });\n\n if (!voice) {\n throw new HTTPException(400, { message: 'Agent does not have voice capabilities' });\n }\n\n const audioStream = new Readable();\n audioStream.push(body.audioData);\n audioStream.push(null);\n\n const text = await voice.listen(audioStream, body.options);\n return { text };\n } catch (error) {\n return handleError(error, 'Error transcribing speech');\n }\n}\n\n/**\n * Get available listeners for an agent\n */\nexport async function getListenerHandler({ mastra, agentId, runtimeContext }: VoiceContext) {\n try {\n if (!agentId) {\n throw new HTTPException(400, { message: 'Agent ID is required' });\n }\n\n const agent = mastra.getAgent(agentId);\n\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const voice = await agent.getVoice({ runtimeContext });\n\n if (!voice) {\n throw new HTTPException(400, { message: 'Agent does not have voice capabilities' });\n }\n\n const listeners = await voice.getListener();\n return listeners;\n } catch (error) {\n return handleError(error, 'Error getting listeners');\n }\n}\n"]}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { handleError } from './chunk-
|
|
4
|
-
import { HTTPException } from './chunk-
|
|
5
|
-
import { __export } from './chunk-
|
|
6
|
-
import { RuntimeContext } from '@mastra/core/di';
|
|
1
|
+
import { validateBody } from './chunk-4QCXUEAT.js';
|
|
2
|
+
import { stringify } from './chunk-LF2ZLOFP.js';
|
|
3
|
+
import { handleError } from './chunk-CY4TP3FK.js';
|
|
4
|
+
import { HTTPException } from './chunk-MMROOK5J.js';
|
|
5
|
+
import { __export } from './chunk-G3PMV62Z.js';
|
|
7
6
|
import { isVercelTool } from '@mastra/core/tools';
|
|
7
|
+
import { zodToJsonSchema } from '@mastra/core/utils/zod-to-json';
|
|
8
8
|
|
|
9
9
|
// src/server/handlers/tools.ts
|
|
10
10
|
var tools_exports = {};
|
|
11
11
|
__export(tools_exports, {
|
|
12
12
|
executeAgentToolHandler: () => executeAgentToolHandler,
|
|
13
13
|
executeToolHandler: () => executeToolHandler,
|
|
14
|
+
getAgentToolHandler: () => getAgentToolHandler,
|
|
14
15
|
getToolByIdHandler: () => getToolByIdHandler,
|
|
15
16
|
getToolsHandler: () => getToolsHandler
|
|
16
17
|
});
|
|
@@ -24,8 +25,8 @@ async function getToolsHandler({ tools }) {
|
|
|
24
25
|
const tool = _tool;
|
|
25
26
|
acc[id] = {
|
|
26
27
|
...tool,
|
|
27
|
-
inputSchema: tool.inputSchema ? stringify(
|
|
28
|
-
outputSchema: tool.outputSchema ? stringify(
|
|
28
|
+
inputSchema: tool.inputSchema ? stringify(zodToJsonSchema(tool.inputSchema)) : void 0,
|
|
29
|
+
outputSchema: tool.outputSchema ? stringify(zodToJsonSchema(tool.outputSchema)) : void 0
|
|
29
30
|
};
|
|
30
31
|
return acc;
|
|
31
32
|
},
|
|
@@ -44,8 +45,8 @@ async function getToolByIdHandler({ tools, toolId }) {
|
|
|
44
45
|
}
|
|
45
46
|
const serializedTool = {
|
|
46
47
|
...tool,
|
|
47
|
-
inputSchema: tool.inputSchema ? stringify(
|
|
48
|
-
outputSchema: tool.outputSchema ? stringify(
|
|
48
|
+
inputSchema: tool.inputSchema ? stringify(zodToJsonSchema(tool.inputSchema)) : void 0,
|
|
49
|
+
outputSchema: tool.outputSchema ? stringify(zodToJsonSchema(tool.outputSchema)) : void 0
|
|
49
50
|
};
|
|
50
51
|
return serializedTool;
|
|
51
52
|
} catch (error) {
|
|
@@ -58,8 +59,7 @@ function executeToolHandler(tools) {
|
|
|
58
59
|
runId,
|
|
59
60
|
toolId,
|
|
60
61
|
data,
|
|
61
|
-
runtimeContext
|
|
62
|
-
runtimeContextFromRequest
|
|
62
|
+
runtimeContext
|
|
63
63
|
}) => {
|
|
64
64
|
try {
|
|
65
65
|
if (!toolId) {
|
|
@@ -77,15 +77,15 @@ function executeToolHandler(tools) {
|
|
|
77
77
|
const result2 = await tool.execute(data);
|
|
78
78
|
return result2;
|
|
79
79
|
}
|
|
80
|
-
const finalRuntimeContext = new RuntimeContext([
|
|
81
|
-
...Array.from(runtimeContext.entries()),
|
|
82
|
-
...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
|
|
83
|
-
]);
|
|
84
80
|
const result = await tool.execute({
|
|
85
81
|
context: data,
|
|
86
82
|
mastra,
|
|
87
83
|
runId,
|
|
88
|
-
runtimeContext
|
|
84
|
+
runtimeContext,
|
|
85
|
+
// TODO: Pass proper tracing context when server API supports tracing
|
|
86
|
+
tracingContext: { currentSpan: void 0 },
|
|
87
|
+
suspend: async () => {
|
|
88
|
+
}
|
|
89
89
|
});
|
|
90
90
|
return result;
|
|
91
91
|
} catch (error) {
|
|
@@ -93,35 +93,61 @@ function executeToolHandler(tools) {
|
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
|
+
async function getAgentToolHandler({
|
|
97
|
+
mastra,
|
|
98
|
+
agentId,
|
|
99
|
+
toolId,
|
|
100
|
+
runtimeContext
|
|
101
|
+
}) {
|
|
102
|
+
try {
|
|
103
|
+
const agent = agentId ? mastra.getAgent(agentId) : null;
|
|
104
|
+
if (!agent) {
|
|
105
|
+
throw new HTTPException(404, { message: "Agent not found" });
|
|
106
|
+
}
|
|
107
|
+
const agentTools = await agent.getTools({ runtimeContext });
|
|
108
|
+
const tool = Object.values(agentTools || {}).find((tool2) => tool2.id === toolId);
|
|
109
|
+
if (!tool) {
|
|
110
|
+
throw new HTTPException(404, { message: "Tool not found" });
|
|
111
|
+
}
|
|
112
|
+
const serializedTool = {
|
|
113
|
+
...tool,
|
|
114
|
+
inputSchema: tool.inputSchema ? stringify(zodToJsonSchema(tool.inputSchema)) : void 0,
|
|
115
|
+
outputSchema: tool.outputSchema ? stringify(zodToJsonSchema(tool.outputSchema)) : void 0
|
|
116
|
+
};
|
|
117
|
+
return serializedTool;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
return handleError(error, "Error getting agent tool");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
96
122
|
async function executeAgentToolHandler({
|
|
97
123
|
mastra,
|
|
98
124
|
agentId,
|
|
99
125
|
toolId,
|
|
100
126
|
data,
|
|
101
|
-
runtimeContext
|
|
102
|
-
runtimeContextFromRequest
|
|
127
|
+
runtimeContext
|
|
103
128
|
}) {
|
|
104
129
|
try {
|
|
105
130
|
const agent = agentId ? mastra.getAgent(agentId) : null;
|
|
106
131
|
if (!agent) {
|
|
107
132
|
throw new HTTPException(404, { message: "Tool not found" });
|
|
108
133
|
}
|
|
109
|
-
const
|
|
134
|
+
const agentTools = await agent.getTools({ runtimeContext });
|
|
135
|
+
const tool = Object.values(agentTools || {}).find((tool2) => tool2.id === toolId);
|
|
110
136
|
if (!tool) {
|
|
111
137
|
throw new HTTPException(404, { message: "Tool not found" });
|
|
112
138
|
}
|
|
113
139
|
if (!tool?.execute) {
|
|
114
140
|
throw new HTTPException(400, { message: "Tool is not executable" });
|
|
115
141
|
}
|
|
116
|
-
const finalRuntimeContext = new RuntimeContext([
|
|
117
|
-
...Array.from(runtimeContext.entries()),
|
|
118
|
-
...Array.from(Object.entries(runtimeContextFromRequest ?? {}))
|
|
119
|
-
]);
|
|
120
142
|
const result = await tool.execute({
|
|
121
143
|
context: data,
|
|
122
|
-
runtimeContext
|
|
144
|
+
runtimeContext,
|
|
123
145
|
mastra,
|
|
124
|
-
runId: agentId
|
|
146
|
+
runId: agentId,
|
|
147
|
+
// TODO: Pass proper tracing context when server API supports tracing
|
|
148
|
+
tracingContext: { currentSpan: void 0 },
|
|
149
|
+
suspend: async () => {
|
|
150
|
+
}
|
|
125
151
|
});
|
|
126
152
|
return result;
|
|
127
153
|
} catch (error) {
|
|
@@ -129,4 +155,6 @@ async function executeAgentToolHandler({
|
|
|
129
155
|
}
|
|
130
156
|
}
|
|
131
157
|
|
|
132
|
-
export { executeAgentToolHandler, executeToolHandler, getToolByIdHandler, getToolsHandler, tools_exports };
|
|
158
|
+
export { executeAgentToolHandler, executeToolHandler, getAgentToolHandler, getToolByIdHandler, getToolsHandler, tools_exports };
|
|
159
|
+
//# sourceMappingURL=chunk-KM7EJKXV.js.map
|
|
160
|
+
//# sourceMappingURL=chunk-KM7EJKXV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/handlers/tools.ts"],"names":["tool","result"],"mappings":";;;;;;;;;AAAA,IAAA,aAAA,GAAA;AAAA,QAAA,CAAA,aAAA,EAAA;AAAA,EAAA,uBAAA,EAAA,MAAA,uBAAA;AAAA,EAAA,kBAAA,EAAA,MAAA,kBAAA;AAAA,EAAA,mBAAA,EAAA,MAAA,mBAAA;AAAA,EAAA,kBAAA,EAAA,MAAA,kBAAA;AAAA,EAAA,eAAA,EAAA,MAAA;AAAA,C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,MACA,MAAA;AAAA,MACA,KAAA,EAAO,OAAA;AAAA;AAAA,MAEP,cAAA,EAAgB,EAAE,WAAA,EAAa,MAAA,EAAU;AAAA,MACzC,SAAS,YAAY;AAAA,MAAC;AAAA,KACvB,CAAA;AAED,IAAA,OAAO,MAAA;AAAA,EACT,SAAS,KAAA,EAAO;AACd,IAAA,OAAO,WAAA,CAAY,OAAO,sBAAsB,CAAA;AAAA,EAClD;AACF","file":"chunk-KM7EJKXV.js","sourcesContent":["import type { RuntimeContext } from '@mastra/core/di';\nimport type { ToolAction, VercelTool } from '@mastra/core/tools';\nimport { isVercelTool } from '@mastra/core/tools';\nimport { zodToJsonSchema } from '@mastra/core/utils/zod-to-json';\nimport { stringify } from 'superjson';\nimport { HTTPException } from '../http-exception';\nimport type { Context } from '../types';\n\nimport { handleError } from './error';\nimport { validateBody } from './utils';\n\ninterface ToolsContext extends Context {\n tools?: Record<string, ToolAction | VercelTool>;\n toolId?: string;\n runId?: string;\n}\n\n// Tool handlers\nexport async function getToolsHandler({ tools }: Pick<ToolsContext, 'tools'>) {\n try {\n if (!tools) {\n return {};\n }\n\n const serializedTools = Object.entries(tools).reduce(\n (acc, [id, _tool]) => {\n const tool = _tool as any;\n acc[id] = {\n ...tool,\n inputSchema: tool.inputSchema ? stringify(zodToJsonSchema(tool.inputSchema)) : undefined,\n outputSchema: tool.outputSchema ? stringify(zodToJsonSchema(tool.outputSchema)) : undefined,\n };\n return acc;\n },\n {} as Record<string, any>,\n );\n\n return serializedTools;\n } catch (error) {\n return handleError(error, 'Error getting tools');\n }\n}\n\nexport async function getToolByIdHandler({ tools, toolId }: Pick<ToolsContext, 'tools' | 'toolId'>) {\n try {\n const tool = Object.values(tools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n const serializedTool = {\n ...tool,\n inputSchema: tool.inputSchema ? stringify(zodToJsonSchema(tool.inputSchema)) : undefined,\n outputSchema: tool.outputSchema ? stringify(zodToJsonSchema(tool.outputSchema)) : undefined,\n };\n\n return serializedTool;\n } catch (error) {\n return handleError(error, 'Error getting tool');\n }\n}\n\nexport function executeToolHandler(tools: ToolsContext['tools']) {\n return async ({\n mastra,\n runId,\n toolId,\n data,\n runtimeContext,\n }: Pick<ToolsContext, 'mastra' | 'toolId' | 'runId'> & {\n data?: unknown;\n runtimeContext: RuntimeContext;\n }) => {\n try {\n if (!toolId) {\n throw new HTTPException(400, { message: 'Tool ID is required' });\n }\n\n const tool = Object.values(tools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n if (!tool?.execute) {\n throw new HTTPException(400, { message: 'Tool is not executable' });\n }\n\n validateBody({ data });\n\n if (isVercelTool(tool)) {\n const result = await (tool as any).execute(data);\n return result;\n }\n\n const result = await tool.execute({\n context: data!,\n mastra,\n runId,\n runtimeContext,\n // TODO: Pass proper tracing context when server API supports tracing\n tracingContext: { currentSpan: undefined },\n suspend: async () => {},\n });\n return result;\n } catch (error) {\n return handleError(error, 'Error executing tool');\n }\n };\n}\n\nexport async function getAgentToolHandler({\n mastra,\n agentId,\n toolId,\n runtimeContext,\n}: Pick<ToolsContext, 'mastra' | 'toolId'> & {\n agentId?: string;\n runtimeContext: RuntimeContext;\n}) {\n try {\n const agent = agentId ? mastra.getAgent(agentId) : null;\n if (!agent) {\n throw new HTTPException(404, { message: 'Agent not found' });\n }\n\n const agentTools = await agent.getTools({ runtimeContext });\n\n const tool = Object.values(agentTools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n const serializedTool = {\n ...tool,\n inputSchema: tool.inputSchema ? stringify(zodToJsonSchema(tool.inputSchema)) : undefined,\n outputSchema: tool.outputSchema ? stringify(zodToJsonSchema(tool.outputSchema)) : undefined,\n };\n\n return serializedTool;\n } catch (error) {\n return handleError(error, 'Error getting agent tool');\n }\n}\n\nexport async function executeAgentToolHandler({\n mastra,\n agentId,\n toolId,\n data,\n runtimeContext,\n}: Pick<ToolsContext, 'mastra' | 'toolId'> & {\n agentId?: string;\n data: any;\n runtimeContext: RuntimeContext;\n}) {\n try {\n const agent = agentId ? mastra.getAgent(agentId) : null;\n if (!agent) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n const agentTools = await agent.getTools({ runtimeContext });\n\n const tool = Object.values(agentTools || {}).find((tool: any) => tool.id === toolId) as any;\n\n if (!tool) {\n throw new HTTPException(404, { message: 'Tool not found' });\n }\n\n if (!tool?.execute) {\n throw new HTTPException(400, { message: 'Tool is not executable' });\n }\n\n // if (isVercelTool(tool)) {\n // const result = await (tool as any).execute(data);\n // return result;\n // }\n\n const result = await tool.execute({\n context: data,\n runtimeContext,\n mastra,\n runId: agentId,\n // TODO: Pass proper tracing context when server API supports tracing\n tracingContext: { currentSpan: undefined },\n suspend: async () => {},\n });\n\n return result;\n } catch (error) {\n return handleError(error, 'Error executing tool');\n }\n}\n"]}
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkGU4EWMZB_cjs = require('./chunk-GU4EWMZB.cjs');
|
|
4
|
+
var chunkRE4RPXT2_cjs = require('./chunk-RE4RPXT2.cjs');
|
|
5
|
+
var chunk7NADHFD2_cjs = require('./chunk-7NADHFD2.cjs');
|
|
6
|
+
var chunkEMMSS5I5_cjs = require('./chunk-EMMSS5I5.cjs');
|
|
7
|
+
var web = require('stream/web');
|
|
8
|
+
var zodToJson = require('@mastra/core/utils/zod-to-json');
|
|
9
|
+
|
|
10
|
+
// src/server/handlers/legacyWorkflows.ts
|
|
11
|
+
var legacyWorkflows_exports = {};
|
|
12
|
+
chunkEMMSS5I5_cjs.__export(legacyWorkflows_exports, {
|
|
13
|
+
createLegacyWorkflowRunHandler: () => createLegacyWorkflowRunHandler,
|
|
14
|
+
getLegacyWorkflowByIdHandler: () => getLegacyWorkflowByIdHandler,
|
|
15
|
+
getLegacyWorkflowRunHandler: () => getLegacyWorkflowRunHandler,
|
|
16
|
+
getLegacyWorkflowRunsHandler: () => getLegacyWorkflowRunsHandler,
|
|
17
|
+
getLegacyWorkflowsHandler: () => getLegacyWorkflowsHandler,
|
|
18
|
+
resumeAsyncLegacyWorkflowHandler: () => resumeAsyncLegacyWorkflowHandler,
|
|
19
|
+
resumeLegacyWorkflowHandler: () => resumeLegacyWorkflowHandler,
|
|
20
|
+
startAsyncLegacyWorkflowHandler: () => startAsyncLegacyWorkflowHandler,
|
|
21
|
+
startLegacyWorkflowRunHandler: () => startLegacyWorkflowRunHandler,
|
|
22
|
+
watchLegacyWorkflowHandler: () => watchLegacyWorkflowHandler
|
|
23
|
+
});
|
|
24
|
+
async function getLegacyWorkflowsHandler({ mastra }) {
|
|
25
|
+
try {
|
|
26
|
+
const workflows = mastra.legacy_getWorkflows({ serialized: false });
|
|
27
|
+
const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
|
|
28
|
+
if (workflow.isNested) return acc;
|
|
29
|
+
acc[key] = {
|
|
30
|
+
stepGraph: workflow.stepGraph,
|
|
31
|
+
stepSubscriberGraph: workflow.stepSubscriberGraph,
|
|
32
|
+
serializedStepGraph: workflow.serializedStepGraph,
|
|
33
|
+
serializedStepSubscriberGraph: workflow.serializedStepSubscriberGraph,
|
|
34
|
+
name: workflow.name,
|
|
35
|
+
triggerSchema: workflow.triggerSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(workflow.triggerSchema)) : void 0,
|
|
36
|
+
steps: Object.entries(workflow.steps).reduce((acc2, [key2, step]) => {
|
|
37
|
+
const _step = step;
|
|
38
|
+
acc2[key2] = {
|
|
39
|
+
id: _step.id,
|
|
40
|
+
description: _step.description,
|
|
41
|
+
workflowId: _step.workflowId,
|
|
42
|
+
inputSchema: _step.inputSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(_step.inputSchema)) : void 0,
|
|
43
|
+
outputSchema: _step.outputSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(_step.outputSchema)) : void 0
|
|
44
|
+
};
|
|
45
|
+
return acc2;
|
|
46
|
+
}, {})
|
|
47
|
+
};
|
|
48
|
+
return acc;
|
|
49
|
+
}, {});
|
|
50
|
+
return _workflows;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
return chunkRE4RPXT2_cjs.handleError(error, "error getting workflows");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async function getLegacyWorkflowByIdHandler({ mastra, workflowId }) {
|
|
56
|
+
try {
|
|
57
|
+
if (!workflowId) {
|
|
58
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
59
|
+
}
|
|
60
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
61
|
+
if (!workflow) {
|
|
62
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
stepGraph: workflow.stepGraph,
|
|
66
|
+
stepSubscriberGraph: workflow.stepSubscriberGraph,
|
|
67
|
+
serializedStepGraph: workflow.serializedStepGraph,
|
|
68
|
+
serializedStepSubscriberGraph: workflow.serializedStepSubscriberGraph,
|
|
69
|
+
name: workflow.name,
|
|
70
|
+
triggerSchema: workflow.triggerSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(workflow.triggerSchema)) : void 0,
|
|
71
|
+
steps: Object.entries(workflow.steps).reduce((acc, [key, step]) => {
|
|
72
|
+
const _step = step;
|
|
73
|
+
acc[key] = {
|
|
74
|
+
id: _step.id,
|
|
75
|
+
description: _step.description,
|
|
76
|
+
workflowId: _step.workflowId,
|
|
77
|
+
inputSchema: _step.inputSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(_step.inputSchema)) : void 0,
|
|
78
|
+
outputSchema: _step.outputSchema ? chunkGU4EWMZB_cjs.stringify(zodToJson.zodToJsonSchema(_step.outputSchema)) : void 0
|
|
79
|
+
};
|
|
80
|
+
return acc;
|
|
81
|
+
}, {})
|
|
82
|
+
};
|
|
83
|
+
} catch (error) {
|
|
84
|
+
return chunkRE4RPXT2_cjs.handleError(error, "error getting workflow by id");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function startAsyncLegacyWorkflowHandler({
|
|
88
|
+
mastra,
|
|
89
|
+
runtimeContext,
|
|
90
|
+
workflowId,
|
|
91
|
+
runId,
|
|
92
|
+
triggerData
|
|
93
|
+
}) {
|
|
94
|
+
try {
|
|
95
|
+
if (!workflowId) {
|
|
96
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
97
|
+
}
|
|
98
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
99
|
+
if (!workflow) {
|
|
100
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
101
|
+
}
|
|
102
|
+
if (!runId) {
|
|
103
|
+
const newRun = workflow.createRun();
|
|
104
|
+
const result2 = await newRun.start({
|
|
105
|
+
triggerData,
|
|
106
|
+
runtimeContext
|
|
107
|
+
});
|
|
108
|
+
return result2;
|
|
109
|
+
}
|
|
110
|
+
const run = workflow.getMemoryRun(runId);
|
|
111
|
+
if (!run) {
|
|
112
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
113
|
+
}
|
|
114
|
+
const result = await run.start({
|
|
115
|
+
triggerData,
|
|
116
|
+
runtimeContext
|
|
117
|
+
});
|
|
118
|
+
return result;
|
|
119
|
+
} catch (error) {
|
|
120
|
+
return chunkRE4RPXT2_cjs.handleError(error, "error starting workflow");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function getLegacyWorkflowRunHandler({
|
|
124
|
+
mastra,
|
|
125
|
+
workflowId,
|
|
126
|
+
runId
|
|
127
|
+
}) {
|
|
128
|
+
try {
|
|
129
|
+
if (!workflowId) {
|
|
130
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
131
|
+
}
|
|
132
|
+
if (!runId) {
|
|
133
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Run ID is required" });
|
|
134
|
+
}
|
|
135
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
136
|
+
if (!workflow) {
|
|
137
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
138
|
+
}
|
|
139
|
+
const run = await workflow.getRun(runId);
|
|
140
|
+
if (!run) {
|
|
141
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
142
|
+
}
|
|
143
|
+
return run;
|
|
144
|
+
} catch (error) {
|
|
145
|
+
return chunkRE4RPXT2_cjs.handleError(error, "error getting workflow run");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async function createLegacyWorkflowRunHandler({
|
|
149
|
+
mastra,
|
|
150
|
+
workflowId,
|
|
151
|
+
runId: prevRunId
|
|
152
|
+
}) {
|
|
153
|
+
try {
|
|
154
|
+
if (!workflowId) {
|
|
155
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
156
|
+
}
|
|
157
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
158
|
+
if (!workflow) {
|
|
159
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow not found" });
|
|
160
|
+
}
|
|
161
|
+
const newRun = workflow.createRun({ runId: prevRunId });
|
|
162
|
+
return { runId: newRun.runId };
|
|
163
|
+
} catch (error) {
|
|
164
|
+
return chunkRE4RPXT2_cjs.handleError(error, "error creating workflow run");
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async function startLegacyWorkflowRunHandler({
|
|
168
|
+
mastra,
|
|
169
|
+
runtimeContext,
|
|
170
|
+
workflowId,
|
|
171
|
+
runId,
|
|
172
|
+
triggerData
|
|
173
|
+
}) {
|
|
174
|
+
try {
|
|
175
|
+
if (!workflowId) {
|
|
176
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
177
|
+
}
|
|
178
|
+
if (!runId) {
|
|
179
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "runId required to start run" });
|
|
180
|
+
}
|
|
181
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
182
|
+
const run = workflow.getMemoryRun(runId);
|
|
183
|
+
if (!run) {
|
|
184
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
185
|
+
}
|
|
186
|
+
void run.start({
|
|
187
|
+
triggerData,
|
|
188
|
+
runtimeContext
|
|
189
|
+
});
|
|
190
|
+
return { message: "Workflow run started" };
|
|
191
|
+
} catch (e) {
|
|
192
|
+
return chunkRE4RPXT2_cjs.handleError(e, "Error starting workflow run");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async function watchLegacyWorkflowHandler({
|
|
196
|
+
mastra,
|
|
197
|
+
workflowId,
|
|
198
|
+
runId
|
|
199
|
+
}) {
|
|
200
|
+
try {
|
|
201
|
+
if (!workflowId) {
|
|
202
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
203
|
+
}
|
|
204
|
+
if (!runId) {
|
|
205
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "runId required to watch workflow" });
|
|
206
|
+
}
|
|
207
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
208
|
+
const run = workflow.getMemoryRun(runId);
|
|
209
|
+
if (!run) {
|
|
210
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
211
|
+
}
|
|
212
|
+
let unwatch;
|
|
213
|
+
let asyncRef = null;
|
|
214
|
+
const stream = new web.ReadableStream({
|
|
215
|
+
start(controller) {
|
|
216
|
+
unwatch = run.watch(({ activePaths, runId: runId2, timestamp, results }) => {
|
|
217
|
+
const activePathsObj = Object.fromEntries(activePaths);
|
|
218
|
+
controller.enqueue(JSON.stringify({ activePaths: activePathsObj, runId: runId2, timestamp, results }));
|
|
219
|
+
if (asyncRef) {
|
|
220
|
+
clearImmediate(asyncRef);
|
|
221
|
+
asyncRef = null;
|
|
222
|
+
}
|
|
223
|
+
asyncRef = setImmediate(() => {
|
|
224
|
+
const runDone = Object.values(activePathsObj).every((value) => value.status !== "executing");
|
|
225
|
+
if (runDone) {
|
|
226
|
+
controller.close();
|
|
227
|
+
unwatch?.();
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
},
|
|
232
|
+
cancel() {
|
|
233
|
+
unwatch?.();
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
return stream;
|
|
237
|
+
} catch (error) {
|
|
238
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error watching workflow");
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
async function resumeAsyncLegacyWorkflowHandler({
|
|
242
|
+
mastra,
|
|
243
|
+
workflowId,
|
|
244
|
+
runId,
|
|
245
|
+
body,
|
|
246
|
+
runtimeContext
|
|
247
|
+
}) {
|
|
248
|
+
try {
|
|
249
|
+
if (!workflowId) {
|
|
250
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
251
|
+
}
|
|
252
|
+
if (!runId) {
|
|
253
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "runId required to resume workflow" });
|
|
254
|
+
}
|
|
255
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
256
|
+
const run = workflow.getMemoryRun(runId);
|
|
257
|
+
if (!run) {
|
|
258
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
259
|
+
}
|
|
260
|
+
const result = await run.resume({
|
|
261
|
+
stepId: body.stepId,
|
|
262
|
+
context: body.context,
|
|
263
|
+
runtimeContext
|
|
264
|
+
});
|
|
265
|
+
return result;
|
|
266
|
+
} catch (error) {
|
|
267
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error resuming workflow step");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
async function resumeLegacyWorkflowHandler({
|
|
271
|
+
mastra,
|
|
272
|
+
workflowId,
|
|
273
|
+
runId,
|
|
274
|
+
body,
|
|
275
|
+
runtimeContext
|
|
276
|
+
}) {
|
|
277
|
+
try {
|
|
278
|
+
if (!workflowId) {
|
|
279
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
280
|
+
}
|
|
281
|
+
if (!runId) {
|
|
282
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "runId required to resume workflow" });
|
|
283
|
+
}
|
|
284
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
285
|
+
const run = workflow.getMemoryRun(runId);
|
|
286
|
+
if (!run) {
|
|
287
|
+
throw new chunk7NADHFD2_cjs.HTTPException(404, { message: "Workflow run not found" });
|
|
288
|
+
}
|
|
289
|
+
void run.resume({
|
|
290
|
+
stepId: body.stepId,
|
|
291
|
+
context: body.context,
|
|
292
|
+
runtimeContext
|
|
293
|
+
});
|
|
294
|
+
return { message: "Workflow run resumed" };
|
|
295
|
+
} catch (error) {
|
|
296
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error resuming workflow");
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
async function getLegacyWorkflowRunsHandler({
|
|
300
|
+
mastra,
|
|
301
|
+
workflowId,
|
|
302
|
+
fromDate,
|
|
303
|
+
toDate,
|
|
304
|
+
limit,
|
|
305
|
+
offset,
|
|
306
|
+
resourceId
|
|
307
|
+
}) {
|
|
308
|
+
try {
|
|
309
|
+
if (!workflowId) {
|
|
310
|
+
throw new chunk7NADHFD2_cjs.HTTPException(400, { message: "Workflow ID is required" });
|
|
311
|
+
}
|
|
312
|
+
const workflow = mastra.legacy_getWorkflow(workflowId);
|
|
313
|
+
const workflowRuns = await workflow.getWorkflowRuns({ fromDate, toDate, limit, offset, resourceId }) || {
|
|
314
|
+
runs: [],
|
|
315
|
+
total: 0
|
|
316
|
+
};
|
|
317
|
+
return workflowRuns;
|
|
318
|
+
} catch (error) {
|
|
319
|
+
return chunkRE4RPXT2_cjs.handleError(error, "Error getting workflow runs");
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
exports.createLegacyWorkflowRunHandler = createLegacyWorkflowRunHandler;
|
|
324
|
+
exports.getLegacyWorkflowByIdHandler = getLegacyWorkflowByIdHandler;
|
|
325
|
+
exports.getLegacyWorkflowRunHandler = getLegacyWorkflowRunHandler;
|
|
326
|
+
exports.getLegacyWorkflowRunsHandler = getLegacyWorkflowRunsHandler;
|
|
327
|
+
exports.getLegacyWorkflowsHandler = getLegacyWorkflowsHandler;
|
|
328
|
+
exports.legacyWorkflows_exports = legacyWorkflows_exports;
|
|
329
|
+
exports.resumeAsyncLegacyWorkflowHandler = resumeAsyncLegacyWorkflowHandler;
|
|
330
|
+
exports.resumeLegacyWorkflowHandler = resumeLegacyWorkflowHandler;
|
|
331
|
+
exports.startAsyncLegacyWorkflowHandler = startAsyncLegacyWorkflowHandler;
|
|
332
|
+
exports.startLegacyWorkflowRunHandler = startLegacyWorkflowRunHandler;
|
|
333
|
+
exports.watchLegacyWorkflowHandler = watchLegacyWorkflowHandler;
|
|
334
|
+
//# sourceMappingURL=chunk-KNGXRN26.cjs.map
|
|
335
|
+
//# sourceMappingURL=chunk-KNGXRN26.cjs.map
|