@mastra/server 1.79.0-alpha.10 → 1.79.0-alpha.11
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/dist/{a2a-CHBSYHxu.js → a2a-BqLB3McP.js} +17 -16
- package/dist/a2a-BqLB3McP.js.map +1 -0
- package/dist/{a2a-B465DD1u.cjs → a2a-Uood_0DN.cjs} +19 -18
- package/dist/a2a-Uood_0DN.cjs.map +1 -0
- package/dist/agent-builder-CuBD1tpv.cjs +728 -0
- package/dist/agent-builder-CuBD1tpv.cjs.map +1 -0
- package/dist/agent-builder-VhM8ADW-.js +627 -0
- package/dist/agent-builder-VhM8ADW-.js.map +1 -0
- package/dist/{agents-X1E7fW3p.js → agents-BHLTMBff.js} +2 -2
- package/dist/{agents-X1E7fW3p.js.map → agents-BHLTMBff.js.map} +1 -1
- package/dist/agents-BOWEUKyV.cjs +3127 -0
- package/dist/agents-BOWEUKyV.cjs.map +1 -0
- package/dist/agents-DRQ3ScbX.js +2828 -0
- package/dist/agents-DRQ3ScbX.js.map +1 -0
- package/dist/{agents-DoNMSCMt.cjs → agents-T-OIM9IK.cjs} +2 -2
- package/dist/{agents-DoNMSCMt.cjs.map → agents-T-OIM9IK.cjs.map} +1 -1
- package/dist/{api-schema-manifest-DUseI2VG.cjs → api-schema-manifest-A2qfi54Y.cjs} +4 -4
- package/dist/{api-schema-manifest-DUseI2VG.cjs.map → api-schema-manifest-A2qfi54Y.cjs.map} +1 -1
- package/dist/{api-schema-manifest-CWRIJP-B.js → api-schema-manifest-Dun5VMRT.js} +3 -3
- package/dist/{api-schema-manifest-CWRIJP-B.js.map → api-schema-manifest-Dun5VMRT.js.map} +1 -1
- package/dist/{background-tasks-CabImVak.cjs → background-tasks-B3VAKTJh.cjs} +3 -3
- package/dist/{background-tasks-CabImVak.cjs.map → background-tasks-B3VAKTJh.cjs.map} +1 -1
- package/dist/{background-tasks-oBaLtnCn.js → background-tasks-Du2zYOPl.js} +2 -2
- package/dist/{background-tasks-oBaLtnCn.js.map → background-tasks-Du2zYOPl.js.map} +1 -1
- package/dist/{builder-registry-DOkLe8ES.js → builder-registry-DLdu9bWH.js} +3 -3
- package/dist/{builder-registry-DOkLe8ES.js.map → builder-registry-DLdu9bWH.js.map} +1 -1
- package/dist/{builder-registry-D0frV8lQ.cjs → builder-registry-DaFAaMTf.cjs} +3 -3
- package/dist/{builder-registry-D0frV8lQ.cjs.map → builder-registry-DaFAaMTf.cjs.map} +1 -1
- package/dist/{channels-CBIopVWd.cjs → channels-BnVRmnzK.cjs} +6 -3
- package/dist/{channels-CBIopVWd.cjs.map → channels-BnVRmnzK.cjs.map} +1 -1
- package/dist/{channels-BOxgHvzI.js → channels-Db-4pXVZ.js} +6 -3
- package/dist/{channels-BOxgHvzI.js.map → channels-Db-4pXVZ.js.map} +1 -1
- package/dist/conversations-8BWryNlF.js +165 -0
- package/dist/conversations-8BWryNlF.js.map +1 -0
- package/dist/conversations-C5MkQBB8.cjs +194 -0
- package/dist/conversations-C5MkQBB8.cjs.map +1 -0
- package/dist/{conversations-Bj5TLNqF.cjs → conversations-DasqEDCF.cjs} +3 -3
- package/dist/{conversations-Bj5TLNqF.cjs.map → conversations-DasqEDCF.cjs.map} +1 -1
- package/dist/{dist-9c3PXXpk.cjs → dist-B-bEVWlJ.cjs} +4733 -1251
- package/dist/dist-B-bEVWlJ.cjs.map +1 -0
- package/dist/dist-B3kC8Yd0.cjs +3 -0
- package/dist/{dist-CQ3FSKT-.cjs → dist-B9ery9Zw.cjs} +38 -35
- package/dist/{dist-CQ3FSKT-.cjs.map → dist-B9ery9Zw.cjs.map} +1 -1
- package/dist/{dist-BxMmGD3n.js → dist-BBOnrL_A.js} +10 -12
- package/dist/{dist-BxMmGD3n.js.map → dist-BBOnrL_A.js.map} +1 -1
- package/dist/{dist-DOWsEmo6.js → dist-BIrQLUV9.js} +20 -20
- package/dist/{dist-DOWsEmo6.js.map → dist-BIrQLUV9.js.map} +1 -1
- package/dist/dist-BM9J-PTK.js +1 -0
- package/dist/{dist-DC1Pewf5.cjs → dist-Bo3GdQwf.cjs} +21 -21
- package/dist/{dist-DC1Pewf5.cjs.map → dist-Bo3GdQwf.cjs.map} +1 -1
- package/dist/{dist-BwYL7Ykb.js → dist-CREG82cy.js} +37 -34
- package/dist/{dist-BwYL7Ykb.js.map → dist-CREG82cy.js.map} +1 -1
- package/dist/{dist-rDRetJVY.cjs → dist-CeTLA-e5.cjs} +2 -3
- package/dist/{dist-rDRetJVY.cjs.map → dist-CeTLA-e5.cjs.map} +1 -1
- package/dist/{dist-CBRJax5e.js → dist-DLld1qjf.js} +25 -31
- package/dist/{dist-CBRJax5e.js.map → dist-DLld1qjf.js.map} +1 -1
- package/dist/{dist-B_bet8uz.js → dist-DjkPkAzV.js} +2 -3
- package/dist/{dist-B_bet8uz.js.map → dist-DjkPkAzV.js.map} +1 -1
- package/dist/{dist-UKEksCGq.cjs → dist-DsrJXwic.cjs} +11 -13
- package/dist/{dist-UKEksCGq.cjs.map → dist-DsrJXwic.cjs.map} +1 -1
- package/dist/{dist-DGCnbhNe.js → dist-k77XQGUn.js} +4493 -1043
- package/dist/dist-k77XQGUn.js.map +1 -0
- package/dist/{dist-3FPW9nVj.cjs → dist-lT2rqyY9.cjs} +26 -32
- package/dist/{dist-3FPW9nVj.cjs.map → dist-lT2rqyY9.cjs.map} +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/{dynamic-workflows-Rr_6ac1y.js → dynamic-workflows-CTUO0SFu.js} +3 -3
- package/dist/{dynamic-workflows-Rr_6ac1y.js.map → dynamic-workflows-CTUO0SFu.js.map} +1 -1
- package/dist/{dynamic-workflows-DXlkr-jK.cjs → dynamic-workflows-HwPX3mcf.cjs} +3 -3
- package/dist/{dynamic-workflows-DXlkr-jK.cjs.map → dynamic-workflows-HwPX3mcf.cjs.map} +1 -1
- package/dist/{editor-builder-BclcHxN6.cjs → editor-builder-BDtiWw0f.cjs} +2 -2
- package/dist/{editor-builder-BclcHxN6.cjs.map → editor-builder-BDtiWw0f.cjs.map} +1 -1
- package/dist/{editor-builder-D16kc1P6.js → editor-builder-ClFlGXoX.js} +4 -4
- package/dist/{editor-builder-D16kc1P6.js.map → editor-builder-ClFlGXoX.js.map} +1 -1
- package/dist/{editor-builder-s9WqPJgA.js → editor-builder-DnLCfqnY.js} +2 -2
- package/dist/{editor-builder-s9WqPJgA.js.map → editor-builder-DnLCfqnY.js.map} +1 -1
- package/dist/{editor-builder-DXHiPX1A.cjs → editor-builder-DtpP1FtW.cjs} +5 -5
- package/dist/{editor-builder-DXHiPX1A.cjs.map → editor-builder-DtpP1FtW.cjs.map} +1 -1
- package/dist/{helpers-ElhPeCSK.cjs → helpers-CAcEhq38.cjs} +21 -17
- package/dist/{helpers-ElhPeCSK.cjs.map → helpers-CAcEhq38.cjs.map} +1 -1
- package/dist/{helpers-DLhX1fqc.js → helpers-vrqddDd5.js} +21 -17
- package/dist/{helpers-DLhX1fqc.js.map → helpers-vrqddDd5.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/logs-CiSw7r0s.cjs +119 -0
- package/dist/logs-CiSw7r0s.cjs.map +1 -0
- package/dist/logs-CxfPk-iL.js +96 -0
- package/dist/logs-CxfPk-iL.js.map +1 -0
- package/dist/mcp-BTdLh6E_.js +274 -0
- package/dist/mcp-BTdLh6E_.js.map +1 -0
- package/dist/mcp-BYqFR5q-.cjs +339 -0
- package/dist/mcp-BYqFR5q-.cjs.map +1 -0
- package/dist/memory-BHtTSzvJ.js +1739 -0
- package/dist/memory-BHtTSzvJ.js.map +1 -0
- package/dist/memory-CwwkVDh1.cjs +1906 -0
- package/dist/memory-CwwkVDh1.cjs.map +1 -0
- package/dist/observability-BBMCMeT-.cjs +502 -0
- package/dist/observability-BBMCMeT-.cjs.map +1 -0
- package/dist/observability-ZRgRcvoX.js +431 -0
- package/dist/observability-ZRgRcvoX.js.map +1 -0
- package/dist/{observability-new-endpoints-BU8JYPfh.js → observability-new-endpoints-fjoZzEtk.js} +10 -9
- package/dist/{observability-new-endpoints-BU8JYPfh.js.map → observability-new-endpoints-fjoZzEtk.js.map} +1 -1
- package/dist/{observability-new-endpoints-AMp9bnMV.cjs → observability-new-endpoints-tG3-odLa.cjs} +11 -10
- package/dist/observability-new-endpoints-tG3-odLa.cjs.map +1 -0
- package/dist/plans-CiPgWBhO.cjs +68 -0
- package/dist/plans-CiPgWBhO.cjs.map +1 -0
- package/dist/plans-DCepEY7n.js +57 -0
- package/dist/plans-DCepEY7n.js.map +1 -0
- package/dist/{probe-image-size-DBGjhUtJ.cjs → probe-image-size-Alv3gwKl.cjs} +194 -184
- package/dist/probe-image-size-Alv3gwKl.cjs.map +1 -0
- package/dist/{probe-image-size-Dmoxv93t.js → probe-image-size-BdfbUHxx.js} +158 -148
- package/dist/probe-image-size-BdfbUHxx.js.map +1 -0
- package/dist/responses-4FwMNxoJ.js +628 -0
- package/dist/responses-4FwMNxoJ.js.map +1 -0
- package/dist/responses-CCRijwDF.cjs +651 -0
- package/dist/responses-CCRijwDF.cjs.map +1 -0
- package/dist/{responses-CKNdSRkS.cjs → responses-CfcIc53b.cjs} +2 -2
- package/dist/{responses-CKNdSRkS.cjs.map → responses-CfcIc53b.cjs.map} +1 -1
- package/dist/{rolldown-runtime-Bd6kNlEP.cjs → rolldown-runtime-BwC_XMyb.cjs} +2 -2
- package/dist/{rolldown-runtime-maW3aOIk.js → rolldown-runtime-D3Hj5m0v.js} +2 -2
- package/dist/{route-builder-BNZs643f.cjs → route-builder-B2Qhhd7C.cjs} +52 -66
- package/dist/route-builder-B2Qhhd7C.cjs.map +1 -0
- package/dist/{route-builder-BfQYtclb.js → route-builder-CjkWxv4E.js} +51 -65
- package/dist/route-builder-CjkWxv4E.js.map +1 -0
- package/dist/{routes-Dl6_kWm7.js → routes-CKfXiwRc.js} +5 -3
- package/dist/routes-CKfXiwRc.js.map +1 -0
- package/dist/{routes-rwufkyUe.js → routes-D1cP2OeF.js} +26 -26
- package/dist/{routes-rwufkyUe.js.map → routes-D1cP2OeF.js.map} +1 -1
- package/dist/{routes-DPojsNf1.cjs → routes-bxG4x1MV.cjs} +199 -199
- package/dist/{routes-DPojsNf1.cjs.map → routes-bxG4x1MV.cjs.map} +1 -1
- package/dist/{routes-BULZI-PU.cjs → routes-jXksmX9G.cjs} +5 -3
- package/dist/routes-jXksmX9G.cjs.map +1 -0
- package/dist/{schedules-Bj-giFbc.cjs → schedules-CTTTCgbk.cjs} +3 -3
- package/dist/{schedules-Bj-giFbc.cjs.map → schedules-CTTTCgbk.cjs.map} +1 -1
- package/dist/{schedules-BQYgaz66.js → schedules-DXh37n6-.js} +2 -2
- package/dist/{schedules-BQYgaz66.js.map → schedules-DXh37n6-.js.map} +1 -1
- package/dist/{schema-e0VHpMt0-C0452jOk.cjs → schema-CzbEIyhE-20gGIWkz.cjs} +83 -88
- package/dist/schema-CzbEIyhE-20gGIWkz.cjs.map +1 -0
- package/dist/{schema-e0VHpMt0-CVP5Hnxy.js → schema-CzbEIyhE-BsMcj9Ws.js} +82 -87
- package/dist/schema-CzbEIyhE-BsMcj9Ws.js.map +1 -0
- package/dist/scores-D9UgETt_.js +288 -0
- package/dist/scores-D9UgETt_.js.map +1 -0
- package/dist/scores-DRdtS7NT.cjs +329 -0
- package/dist/scores-DRdtS7NT.cjs.map +1 -0
- package/dist/server/a2a/store.cjs +1 -1
- package/dist/server/auth/index.cjs +2 -2
- package/dist/server/auth/index.js +1 -1
- package/dist/server/browser-stream/index.cjs +9 -11
- package/dist/server/browser-stream/index.cjs.map +1 -1
- package/dist/server/browser-stream/index.js +8 -10
- package/dist/server/browser-stream/index.js.map +1 -1
- package/dist/server/handlers/a2a.cjs +2 -2
- package/dist/server/handlers/a2a.js +1 -2
- package/dist/server/handlers/agent-builder.cjs +18 -648
- package/dist/server/handlers/agent-builder.js +1 -627
- package/dist/server/handlers/agent-controller.cjs +5 -5
- package/dist/server/handlers/agent-controller.cjs.map +1 -1
- package/dist/server/handlers/agent-controller.js +11 -9
- package/dist/server/handlers/agent-controller.js.map +1 -1
- package/dist/server/handlers/agent-versions.cjs +15 -8
- package/dist/server/handlers/agent-versions.cjs.map +1 -1
- package/dist/server/handlers/agent-versions.js +14 -7
- package/dist/server/handlers/agent-versions.js.map +1 -1
- package/dist/server/handlers/agents.cjs +51 -2860
- package/dist/server/handlers/agents.js +1 -2806
- package/dist/server/handlers/auth.cjs +14 -12
- package/dist/server/handlers/auth.cjs.map +1 -1
- package/dist/server/handlers/auth.js +20 -16
- package/dist/server/handlers/auth.js.map +1 -1
- package/dist/server/handlers/author-enrichment.cjs +1 -1
- package/dist/server/handlers/authorship.cjs +1 -1
- package/dist/server/handlers/authorship.cjs.map +1 -1
- package/dist/server/handlers/background-tasks.cjs +2 -2
- package/dist/server/handlers/background-tasks.js +1 -2
- package/dist/server/handlers/builder-registry.cjs +2 -2
- package/dist/server/handlers/builder-registry.js +1 -2
- package/dist/server/handlers/channels.cjs +2 -2
- package/dist/server/handlers/channels.js +1 -2
- package/dist/server/handlers/conversations.cjs +6 -171
- package/dist/server/handlers/conversations.js +1 -162
- package/dist/server/handlers/datasets.cjs +2 -2
- package/dist/server/handlers/datasets.cjs.map +1 -1
- package/dist/server/handlers/datasets.js +1 -1
- package/dist/server/handlers/dynamic-workflows.cjs +2 -2
- package/dist/server/handlers/dynamic-workflows.js +1 -2
- package/dist/server/handlers/editor-builder.cjs +2 -2
- package/dist/server/handlers/editor-builder.js +1 -2
- package/dist/server/handlers/error.cjs +18 -13
- package/dist/server/handlers/error.cjs.map +1 -1
- package/dist/server/handlers/error.js +17 -12
- package/dist/server/handlers/error.js.map +1 -1
- package/dist/server/handlers/favorites-enrichment.cjs +2 -2
- package/dist/server/handlers/favorites-enrichment.js +1 -1
- package/dist/server/handlers/gateway-memory-client.cjs +1 -1
- package/dist/server/handlers/logs.cjs +5 -104
- package/dist/server/handlers/logs.js +1 -96
- package/dist/server/handlers/mcp-client-versions.cjs +15 -8
- package/dist/server/handlers/mcp-client-versions.cjs.map +1 -1
- package/dist/server/handlers/mcp-client-versions.js +14 -7
- package/dist/server/handlers/mcp-client-versions.js.map +1 -1
- package/dist/server/handlers/mcp.cjs +12 -289
- package/dist/server/handlers/mcp.js +1 -274
- package/dist/server/handlers/memory.cjs +29 -1763
- package/dist/server/handlers/memory.js +1 -1731
- package/dist/server/handlers/observability-list-query-schemas.cjs +1 -1
- package/dist/server/handlers/observability-new-endpoints.cjs +2 -2
- package/dist/server/handlers/observability-new-endpoints.js +1 -2
- package/dist/server/handlers/observability-shared.cjs +2 -2
- package/dist/server/handlers/observability-shared.js +1 -1
- package/dist/server/handlers/observability-storage-schemas.cjs +1 -1
- package/dist/server/handlers/observability.cjs +14 -445
- package/dist/server/handlers/observability.js +3 -429
- package/dist/server/handlers/plans.cjs +3 -63
- package/dist/server/handlers/plans.js +1 -57
- package/dist/server/handlers/processor-providers.cjs +2 -2
- package/dist/server/handlers/processor-providers.cjs.map +1 -1
- package/dist/server/handlers/processor-providers.js +1 -1
- package/dist/server/handlers/processors.cjs +13 -15
- package/dist/server/handlers/processors.cjs.map +1 -1
- package/dist/server/handlers/processors.js +12 -14
- package/dist/server/handlers/processors.js.map +1 -1
- package/dist/server/handlers/prompt-block-versions.cjs +15 -8
- package/dist/server/handlers/prompt-block-versions.cjs.map +1 -1
- package/dist/server/handlers/prompt-block-versions.js +14 -7
- package/dist/server/handlers/prompt-block-versions.js.map +1 -1
- package/dist/server/handlers/responses.adapter.cjs +1 -1
- package/dist/server/handlers/responses.adapter.cjs.map +1 -1
- package/dist/server/handlers/responses.cjs +5 -632
- package/dist/server/handlers/responses.js +1 -624
- package/dist/server/handlers/responses.storage.cjs +2 -2
- package/dist/server/handlers/schedules-workflows-shim.cjs +1 -1
- package/dist/server/handlers/schedules.cjs +2 -2
- package/dist/server/handlers/schedules.js +1 -2
- package/dist/server/handlers/scorer-versions.cjs +15 -8
- package/dist/server/handlers/scorer-versions.cjs.map +1 -1
- package/dist/server/handlers/scorer-versions.js +14 -7
- package/dist/server/handlers/scorer-versions.js.map +1 -1
- package/dist/server/handlers/scores.cjs +8 -299
- package/dist/server/handlers/scores.js +1 -288
- package/dist/server/handlers/skills-sh-shared.cjs +1 -1
- package/dist/server/handlers/stored-agent-favorites.cjs +4 -4
- package/dist/server/handlers/stored-agent-favorites.js +3 -3
- package/dist/server/handlers/stored-agents.cjs +19 -13
- package/dist/server/handlers/stored-agents.cjs.map +1 -1
- package/dist/server/handlers/stored-agents.js +18 -12
- package/dist/server/handlers/stored-agents.js.map +1 -1
- package/dist/server/handlers/stored-mcp-clients.cjs +8 -6
- package/dist/server/handlers/stored-mcp-clients.cjs.map +1 -1
- package/dist/server/handlers/stored-mcp-clients.js +7 -5
- package/dist/server/handlers/stored-mcp-clients.js.map +1 -1
- package/dist/server/handlers/stored-prompt-blocks.cjs +3 -3
- package/dist/server/handlers/stored-prompt-blocks.js +2 -2
- package/dist/server/handlers/stored-scorers.cjs +3 -3
- package/dist/server/handlers/stored-scorers.js +2 -2
- package/dist/server/handlers/stored-skill-favorites.cjs +4 -4
- package/dist/server/handlers/stored-skill-favorites.js +3 -3
- package/dist/server/handlers/stored-skills.cjs +6 -5
- package/dist/server/handlers/stored-skills.cjs.map +1 -1
- package/dist/server/handlers/stored-skills.js +5 -4
- package/dist/server/handlers/stored-skills.js.map +1 -1
- package/dist/server/handlers/stored-workspaces.cjs +3 -3
- package/dist/server/handlers/stored-workspaces.js +2 -2
- package/dist/server/handlers/system.cjs +3 -3
- package/dist/server/handlers/system.cjs.map +1 -1
- package/dist/server/handlers/system.js +2 -2
- package/dist/server/handlers/test-utils.cjs +1 -1
- package/dist/server/handlers/tool-providers.cjs +2 -2
- package/dist/server/handlers/tool-providers.js +1 -1
- package/dist/server/handlers/tool-schema-overrides.cjs +1 -1
- package/dist/server/handlers/tools.cjs +7 -267
- package/dist/server/handlers/tools.js +1 -257
- package/dist/server/handlers/utils.cjs +2 -2
- package/dist/server/handlers/utils.js +1 -2
- package/dist/server/handlers/validate-agent-instructions.cjs +2 -2
- package/dist/server/handlers/validate-agent-instructions.js +1 -1
- package/dist/server/handlers/validate-avatar.cjs +2 -2
- package/dist/server/handlers/validate-avatar.cjs.map +1 -1
- package/dist/server/handlers/validate-avatar.js +1 -1
- package/dist/server/handlers/validate-avatar.js.map +1 -1
- package/dist/server/handlers/vector.cjs +17 -334
- package/dist/server/handlers/vector.js +1 -314
- package/dist/server/handlers/version-helpers.cjs +1 -1
- package/dist/server/handlers/voice.cjs +9 -35
- package/dist/server/handlers/voice.js +1 -23
- package/dist/server/handlers/workflow-builder.cjs +2 -2
- package/dist/server/handlers/workflow-builder.js +1 -2
- package/dist/server/handlers/workflows.cjs +30 -1293
- package/dist/server/handlers/workflows.js +1 -1257
- package/dist/server/handlers/workspace.cjs +27 -1176
- package/dist/server/handlers/workspace.js +1 -1146
- package/dist/server/handlers.cjs +33 -33
- package/dist/server/handlers.js +17 -17
- package/dist/server/schemas/index.cjs +6 -6
- package/dist/server/schemas/index.js +3 -3
- package/dist/server/server-adapter/index.cjs +5 -5
- package/dist/server/server-adapter/index.cjs.map +1 -1
- package/dist/server/server-adapter/index.js +4 -4
- package/dist/server/server-adapter/index.js.map +1 -1
- package/dist/tools-CmFSfDMn.js +256 -0
- package/dist/tools-CmFSfDMn.js.map +1 -0
- package/dist/tools-SPJtxG9N.cjs +291 -0
- package/dist/tools-SPJtxG9N.cjs.map +1 -0
- package/dist/{utils-DCgeTrq2.cjs → utils-CF76qzZR.cjs} +12 -17
- package/dist/{utils-DCgeTrq2.cjs.map → utils-CF76qzZR.cjs.map} +1 -1
- package/dist/{utils-DCAUeb6M.js → utils-aoLN3Wfi.js} +11 -16
- package/dist/{utils-DCAUeb6M.js.map → utils-aoLN3Wfi.js.map} +1 -1
- package/dist/{utils-Du-EpvDs.cjs → utils-dDLIDg8O.cjs} +2 -2
- package/dist/{utils-Du-EpvDs.cjs.map → utils-dDLIDg8O.cjs.map} +1 -1
- package/dist/vector-BKDD1kwc.cjs +409 -0
- package/dist/vector-BKDD1kwc.cjs.map +1 -0
- package/dist/vector-TWv4t-4g.js +314 -0
- package/dist/vector-TWv4t-4g.js.map +1 -0
- package/dist/voice-BnGwlZ75.cjs +70 -0
- package/dist/voice-BnGwlZ75.cjs.map +1 -0
- package/dist/voice-DjG8tBAD.js +23 -0
- package/dist/voice-DjG8tBAD.js.map +1 -0
- package/dist/{workflow-builder-Brj3IArM.cjs → workflow-builder-C9-8ZOWF.cjs} +5 -5
- package/dist/{workflow-builder-Brj3IArM.cjs.map → workflow-builder-C9-8ZOWF.cjs.map} +1 -1
- package/dist/{workflow-builder-DOa1Vx6w.js → workflow-builder-CjlLoQvo.js} +10 -8
- package/dist/{workflow-builder-DOa1Vx6w.js.map → workflow-builder-CjlLoQvo.js.map} +1 -1
- package/dist/workflows-DjqeJcdJ.cjs +1446 -0
- package/dist/workflows-DjqeJcdJ.cjs.map +1 -0
- package/dist/workflows-bb-otd2o.js +1273 -0
- package/dist/workflows-bb-otd2o.js.map +1 -0
- package/dist/workspace-B6kzp-bo.js +1154 -0
- package/dist/workspace-B6kzp-bo.js.map +1 -0
- package/dist/workspace-COKR1SxH.cjs +1309 -0
- package/dist/workspace-COKR1SxH.cjs.map +1 -0
- package/package.json +4 -4
- package/dist/a2a-B465DD1u.cjs.map +0 -1
- package/dist/a2a-CHBSYHxu.js.map +0 -1
- package/dist/dist-9c3PXXpk.cjs.map +0 -1
- package/dist/dist-B5OwHWTo.cjs +0 -2294
- package/dist/dist-B5OwHWTo.cjs.map +0 -1
- package/dist/dist-DGCnbhNe.js.map +0 -1
- package/dist/dist-DcoIg_tp.js +0 -2293
- package/dist/dist-DcoIg_tp.js.map +0 -1
- package/dist/observability-new-endpoints-AMp9bnMV.cjs.map +0 -1
- package/dist/probe-image-size-DBGjhUtJ.cjs.map +0 -1
- package/dist/probe-image-size-Dmoxv93t.js.map +0 -1
- package/dist/route-builder-BNZs643f.cjs.map +0 -1
- package/dist/route-builder-BfQYtclb.js.map +0 -1
- package/dist/routes-BULZI-PU.cjs.map +0 -1
- package/dist/routes-Dl6_kWm7.js.map +0 -1
- package/dist/schema-Drf2W04o.js +0 -2
- package/dist/schema-EQanefYq.cjs +0 -1
- package/dist/schema-e0VHpMt0-C0452jOk.cjs.map +0 -1
- package/dist/schema-e0VHpMt0-CVP5Hnxy.js.map +0 -1
- package/dist/server/handlers/agent-builder.cjs.map +0 -1
- package/dist/server/handlers/agent-builder.js.map +0 -1
- package/dist/server/handlers/agents.cjs.map +0 -1
- package/dist/server/handlers/agents.js.map +0 -1
- package/dist/server/handlers/conversations.cjs.map +0 -1
- package/dist/server/handlers/conversations.js.map +0 -1
- package/dist/server/handlers/logs.cjs.map +0 -1
- package/dist/server/handlers/logs.js.map +0 -1
- package/dist/server/handlers/mcp.cjs.map +0 -1
- package/dist/server/handlers/mcp.js.map +0 -1
- package/dist/server/handlers/memory.cjs.map +0 -1
- package/dist/server/handlers/memory.js.map +0 -1
- package/dist/server/handlers/observability.cjs.map +0 -1
- package/dist/server/handlers/observability.js.map +0 -1
- package/dist/server/handlers/plans.cjs.map +0 -1
- package/dist/server/handlers/plans.js.map +0 -1
- package/dist/server/handlers/responses.cjs.map +0 -1
- package/dist/server/handlers/responses.js.map +0 -1
- package/dist/server/handlers/scores.cjs.map +0 -1
- package/dist/server/handlers/scores.js.map +0 -1
- package/dist/server/handlers/tools.cjs.map +0 -1
- package/dist/server/handlers/tools.js.map +0 -1
- package/dist/server/handlers/vector.cjs.map +0 -1
- package/dist/server/handlers/vector.js.map +0 -1
- package/dist/server/handlers/voice.cjs.map +0 -1
- package/dist/server/handlers/voice.js.map +0 -1
- package/dist/server/handlers/workflows.cjs.map +0 -1
- package/dist/server/handlers/workflows.js.map +0 -1
- package/dist/server/handlers/workspace.cjs.map +0 -1
- package/dist/server/handlers/workspace.js.map +0 -1
- package/dist/sync-Ai_ZDz7U.js +0 -1700
- package/dist/sync-Ai_ZDz7U.js.map +0 -1
- package/dist/sync-BrO5MtSe.cjs +0 -1729
- package/dist/sync-BrO5MtSe.cjs.map +0 -1
|
@@ -0,0 +1,1273 @@
|
|
|
1
|
+
import { r as __exportAll } from "./rolldown-runtime-D3Hj5m0v.js";
|
|
2
|
+
import { t as HTTPException } from "./http-exception-CyfxZB6W.js";
|
|
3
|
+
import { o as optionalRunIdSchema, u as runIdSchema } from "./common-Y30XtCyr.js";
|
|
4
|
+
import { _ as workflowRunCountsResponseSchema, a as observeWorkflowQuerySchema, b as workflowRunResultSchema, d as streamWorkflowBodySchema, f as timeTravelBodySchema, g as workflowInfoSchema, h as workflowIdPathParams, i as listWorkflowsResponseSchema, l as startAsyncWorkflowBodySchema, m as workflowExecutionResultSchema, n as createWorkflowRunResponseSchema, o as restartBodySchema, p as workflowControlResponseSchema, r as listWorkflowRunsQuerySchema, s as resumeBodySchema, t as createWorkflowRunBodySchema, v as workflowRunPathParams, x as workflowRunsResponseSchema, y as workflowRunResultQuerySchema } from "./workflows-Dcx4Ib0t.js";
|
|
5
|
+
import { Y as streamResponseSchema } from "./agents-BHLTMBff.js";
|
|
6
|
+
import { n as createRoute } from "./route-builder-CjkWxv4E.js";
|
|
7
|
+
import { a as getWorkflowInfo, t as WorkflowRegistry } from "./utils-aoLN3Wfi.js";
|
|
8
|
+
import { handleError } from "./server/handlers/error.js";
|
|
9
|
+
import { g as MastraFGAPermissions, i as getEffectiveResourceId, m as validateRunOwnership, o as getPublicWorkflowById } from "./utils-BBJlS81s.js";
|
|
10
|
+
import { z } from "zod/v4";
|
|
11
|
+
import { createReplayStream } from "@mastra/core/stream";
|
|
12
|
+
//#region src/server/handlers/workflows.ts
|
|
13
|
+
var workflows_exports = /* @__PURE__ */ __exportAll({
|
|
14
|
+
CANCEL_WORKFLOW_RUN_ROUTE: () => CANCEL_WORKFLOW_RUN_ROUTE,
|
|
15
|
+
CREATE_WORKFLOW_RUN_ROUTE: () => CREATE_WORKFLOW_RUN_ROUTE,
|
|
16
|
+
DELETE_WORKFLOW_RUN_BY_ID_ROUTE: () => DELETE_WORKFLOW_RUN_BY_ID_ROUTE,
|
|
17
|
+
EXECUTE_WORKFLOW_STEP_ROUTE: () => EXECUTE_WORKFLOW_STEP_ROUTE,
|
|
18
|
+
GET_WORKFLOW_BY_ID_ROUTE: () => GET_WORKFLOW_BY_ID_ROUTE,
|
|
19
|
+
GET_WORKFLOW_RUN_BY_ID_ROUTE: () => GET_WORKFLOW_RUN_BY_ID_ROUTE,
|
|
20
|
+
LIST_WORKFLOWS_ROUTE: () => LIST_WORKFLOWS_ROUTE,
|
|
21
|
+
LIST_WORKFLOW_RUNS_ROUTE: () => LIST_WORKFLOW_RUNS_ROUTE,
|
|
22
|
+
LIST_WORKFLOW_RUN_COUNTS_ROUTE: () => LIST_WORKFLOW_RUN_COUNTS_ROUTE,
|
|
23
|
+
OBSERVE_STREAM_LEGACY_WORKFLOW_ROUTE: () => OBSERVE_STREAM_LEGACY_WORKFLOW_ROUTE,
|
|
24
|
+
OBSERVE_STREAM_WORKFLOW_ROUTE: () => OBSERVE_STREAM_WORKFLOW_ROUTE,
|
|
25
|
+
RECEIVE_WORKFLOW_EVENT_ROUTE: () => RECEIVE_WORKFLOW_EVENT_ROUTE,
|
|
26
|
+
RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ASYNC_ROUTE: () => RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ASYNC_ROUTE,
|
|
27
|
+
RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ROUTE: () => RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ROUTE,
|
|
28
|
+
RESTART_ASYNC_WORKFLOW_ROUTE: () => RESTART_ASYNC_WORKFLOW_ROUTE,
|
|
29
|
+
RESTART_WORKFLOW_ROUTE: () => RESTART_WORKFLOW_ROUTE,
|
|
30
|
+
RESUME_ASYNC_WORKFLOW_ROUTE: () => RESUME_ASYNC_WORKFLOW_ROUTE,
|
|
31
|
+
RESUME_NO_WAIT_WORKFLOW_ROUTE: () => RESUME_NO_WAIT_WORKFLOW_ROUTE,
|
|
32
|
+
RESUME_STREAM_WORKFLOW_ROUTE: () => RESUME_STREAM_WORKFLOW_ROUTE,
|
|
33
|
+
RESUME_WORKFLOW_ROUTE: () => RESUME_WORKFLOW_ROUTE,
|
|
34
|
+
START_ASYNC_WORKFLOW_ROUTE: () => START_ASYNC_WORKFLOW_ROUTE,
|
|
35
|
+
START_WORKFLOW_RUN_ROUTE: () => START_WORKFLOW_RUN_ROUTE,
|
|
36
|
+
STREAM_LEGACY_WORKFLOW_ROUTE: () => STREAM_LEGACY_WORKFLOW_ROUTE,
|
|
37
|
+
STREAM_WORKFLOW_ROUTE: () => STREAM_WORKFLOW_ROUTE,
|
|
38
|
+
TIME_TRAVEL_ASYNC_WORKFLOW_ROUTE: () => TIME_TRAVEL_ASYNC_WORKFLOW_ROUTE,
|
|
39
|
+
TIME_TRAVEL_STREAM_WORKFLOW_ROUTE: () => TIME_TRAVEL_STREAM_WORKFLOW_ROUTE,
|
|
40
|
+
TIME_TRAVEL_WORKFLOW_ROUTE: () => TIME_TRAVEL_WORKFLOW_ROUTE,
|
|
41
|
+
__setWorkflowRunCountsNow: () => __setWorkflowRunCountsNow
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* Statuses a run cannot come back from. Streaming one of these runIds again would
|
|
45
|
+
* start a fresh execution under the same runId and overwrite its stored snapshot —
|
|
46
|
+
* the in-memory de-dupe that protects concurrent streams only covers runs still held
|
|
47
|
+
* in the workflow's run map, and a finished run has already been dropped from it.
|
|
48
|
+
*/
|
|
49
|
+
const TERMINAL_RUN_STATUSES = [
|
|
50
|
+
"success",
|
|
51
|
+
"failed",
|
|
52
|
+
"canceled",
|
|
53
|
+
"tripwire"
|
|
54
|
+
];
|
|
55
|
+
/**
|
|
56
|
+
* Runs whose chunks are already being written to the cache in this process,
|
|
57
|
+
* keyed by runId. A run has exactly one writer: without this, two concurrent
|
|
58
|
+
* requests for the same runId each cache every chunk and the replayed history
|
|
59
|
+
* comes back duplicated.
|
|
60
|
+
*/
|
|
61
|
+
const activeRunStreamCachers = /* @__PURE__ */ new Set();
|
|
62
|
+
/**
|
|
63
|
+
* Cache a run's chunks for later replay and return the stream to hand the client.
|
|
64
|
+
*
|
|
65
|
+
* The cached history belongs to the run, not to whoever happens to be watching,
|
|
66
|
+
* so the caching side is driven by its own reader rather than by the client's
|
|
67
|
+
* consumption. If the client disconnects mid-run its branch is cancelled while
|
|
68
|
+
* this reader keeps draining, so `/observe` still replays a complete history —
|
|
69
|
+
* the failure that makes reconnection necessary is exactly the one the cache has
|
|
70
|
+
* to survive. Chunks buffer in the tee while a client lags, bounded by the run's
|
|
71
|
+
* own length.
|
|
72
|
+
*/
|
|
73
|
+
function cacheRunStream({ cache, runId, source }) {
|
|
74
|
+
if (activeRunStreamCachers.has(runId)) return source;
|
|
75
|
+
const [toCache, toClient] = source.tee();
|
|
76
|
+
activeRunStreamCachers.add(runId);
|
|
77
|
+
(async () => {
|
|
78
|
+
const reader = toCache.getReader();
|
|
79
|
+
try {
|
|
80
|
+
while (true) {
|
|
81
|
+
const { done, value } = await reader.read();
|
|
82
|
+
if (done) break;
|
|
83
|
+
await cache.listPush(runId, value).catch(() => {});
|
|
84
|
+
}
|
|
85
|
+
} catch {} finally {
|
|
86
|
+
reader.releaseLock();
|
|
87
|
+
activeRunStreamCachers.delete(runId);
|
|
88
|
+
}
|
|
89
|
+
})();
|
|
90
|
+
return toClient;
|
|
91
|
+
}
|
|
92
|
+
async function listWorkflowsFromSystem({ mastra, workflowId }) {
|
|
93
|
+
const logger = mastra.getLogger();
|
|
94
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
95
|
+
let workflow;
|
|
96
|
+
workflow = WorkflowRegistry.getWorkflow(workflowId);
|
|
97
|
+
if (!workflow) workflow = getPublicWorkflowById(mastra, workflowId);
|
|
98
|
+
if (!workflow) {
|
|
99
|
+
logger.debug("Workflow not found, searching agents for workflow", { workflowId });
|
|
100
|
+
const agents = mastra.listAgents();
|
|
101
|
+
if (Object.keys(agents || {}).length) for (const [_, agent] of Object.entries(agents)) try {
|
|
102
|
+
const workflows = await agent.listWorkflows();
|
|
103
|
+
if (workflows[workflowId]) {
|
|
104
|
+
workflow = workflows[workflowId];
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
logger.debug("Error getting workflow from agent", error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
112
|
+
return { workflow };
|
|
113
|
+
}
|
|
114
|
+
const LIST_WORKFLOWS_ROUTE = createRoute({
|
|
115
|
+
method: "GET",
|
|
116
|
+
path: "/workflows",
|
|
117
|
+
responseType: "json",
|
|
118
|
+
queryParamSchema: z.object({ partial: z.string().optional() }),
|
|
119
|
+
responseSchema: listWorkflowsResponseSchema,
|
|
120
|
+
summary: "List all workflows",
|
|
121
|
+
description: "Returns a list of all available workflows in the system",
|
|
122
|
+
tags: ["Workflows"],
|
|
123
|
+
requiresAuth: true,
|
|
124
|
+
handler: (async ({ mastra, partial, requestContext }) => {
|
|
125
|
+
try {
|
|
126
|
+
const workflows = mastra.listWorkflows({ serialized: false });
|
|
127
|
+
const isPartial = partial === "true";
|
|
128
|
+
const _workflows = Object.entries(workflows).reduce((acc, [key, workflow]) => {
|
|
129
|
+
acc[key] = getWorkflowInfo(workflow, isPartial);
|
|
130
|
+
return acc;
|
|
131
|
+
}, {});
|
|
132
|
+
const fgaProvider = mastra.getServer?.()?.fga;
|
|
133
|
+
const user = requestContext?.get("user");
|
|
134
|
+
if (fgaProvider) {
|
|
135
|
+
if (!user) return {};
|
|
136
|
+
const workflowList = Object.entries(_workflows).map(([id, w]) => ({
|
|
137
|
+
id,
|
|
138
|
+
...w
|
|
139
|
+
}));
|
|
140
|
+
const accessible = await fgaProvider.filterAccessible(user, workflowList, "workflow", MastraFGAPermissions.WORKFLOWS_READ);
|
|
141
|
+
const accessibleSet = new Set(accessible.map((w) => w.id));
|
|
142
|
+
for (const id of Object.keys(_workflows)) if (!accessibleSet.has(id)) delete _workflows[id];
|
|
143
|
+
}
|
|
144
|
+
return _workflows;
|
|
145
|
+
} catch (error) {
|
|
146
|
+
return handleError(error, "Error getting workflows");
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
});
|
|
150
|
+
const RUN_COUNTS_CACHE_TTL_MS = 5e3;
|
|
151
|
+
const runCountsCache = /* @__PURE__ */ new WeakMap();
|
|
152
|
+
let runCountsNow = () => Date.now();
|
|
153
|
+
/** Test seam — lets TTL expiry be tested without wall-clock waits. */
|
|
154
|
+
function __setWorkflowRunCountsNow(now) {
|
|
155
|
+
runCountsNow = now ?? (() => Date.now());
|
|
156
|
+
}
|
|
157
|
+
const LIST_WORKFLOW_RUN_COUNTS_ROUTE = createRoute({
|
|
158
|
+
method: "GET",
|
|
159
|
+
path: "/workflows/run-counts",
|
|
160
|
+
responseType: "json",
|
|
161
|
+
responseSchema: workflowRunCountsResponseSchema,
|
|
162
|
+
summary: "List workflow run counts",
|
|
163
|
+
description: "Returns per-workflow counts of currently running and suspended (awaiting resume) runs, keyed by the workflow registry key used in the Mastra config",
|
|
164
|
+
tags: ["Workflows"],
|
|
165
|
+
requiresAuth: true,
|
|
166
|
+
handler: (async ({ mastra, requestContext }) => {
|
|
167
|
+
try {
|
|
168
|
+
const fgaProvider = mastra.getServer?.()?.fga;
|
|
169
|
+
const user = requestContext?.get("user");
|
|
170
|
+
if (fgaProvider && !user) return {};
|
|
171
|
+
const workflows = mastra.listWorkflows({ serialized: false });
|
|
172
|
+
const counts = {};
|
|
173
|
+
const workflowIdToRegistryKey = /* @__PURE__ */ new Map();
|
|
174
|
+
for (const [registryKey, workflow] of Object.entries(workflows)) {
|
|
175
|
+
counts[registryKey] = {
|
|
176
|
+
running: 0,
|
|
177
|
+
suspended: 0
|
|
178
|
+
};
|
|
179
|
+
workflowIdToRegistryKey.set(workflow.id, registryKey);
|
|
180
|
+
}
|
|
181
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
|
|
182
|
+
const cacheable = !fgaProvider && !effectiveResourceId;
|
|
183
|
+
if (cacheable) {
|
|
184
|
+
const cached = runCountsCache.get(mastra);
|
|
185
|
+
if (cached && runCountsNow() - cached.at < RUN_COUNTS_CACHE_TTL_MS) return cached.value;
|
|
186
|
+
}
|
|
187
|
+
const storage = mastra.getStorage();
|
|
188
|
+
const workflowsStore = storage ? await storage.getStore("workflows") : void 0;
|
|
189
|
+
if (workflowsStore) {
|
|
190
|
+
const [running, suspended] = await Promise.all([workflowsStore.listWorkflowRuns({
|
|
191
|
+
status: "running",
|
|
192
|
+
resourceId: effectiveResourceId
|
|
193
|
+
}), workflowsStore.listWorkflowRuns({
|
|
194
|
+
status: "suspended",
|
|
195
|
+
resourceId: effectiveResourceId
|
|
196
|
+
})]);
|
|
197
|
+
for (const run of running.runs) {
|
|
198
|
+
const registryKey = workflowIdToRegistryKey.get(run.workflowName);
|
|
199
|
+
const entry = registryKey ? counts[registryKey] : void 0;
|
|
200
|
+
if (entry) entry.running++;
|
|
201
|
+
}
|
|
202
|
+
for (const run of suspended.runs) {
|
|
203
|
+
const registryKey = workflowIdToRegistryKey.get(run.workflowName);
|
|
204
|
+
const entry = registryKey ? counts[registryKey] : void 0;
|
|
205
|
+
if (entry) entry.suspended++;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (fgaProvider) {
|
|
209
|
+
const workflowList = Object.keys(counts).map((id) => ({ id }));
|
|
210
|
+
const accessible = await fgaProvider.filterAccessible(user, workflowList, "workflow", MastraFGAPermissions.WORKFLOWS_READ);
|
|
211
|
+
const accessibleSet = new Set(accessible.map((w) => w.id));
|
|
212
|
+
for (const id of Object.keys(counts)) if (!accessibleSet.has(id)) delete counts[id];
|
|
213
|
+
return counts;
|
|
214
|
+
}
|
|
215
|
+
if (cacheable) runCountsCache.set(mastra, {
|
|
216
|
+
at: runCountsNow(),
|
|
217
|
+
value: counts
|
|
218
|
+
});
|
|
219
|
+
return counts;
|
|
220
|
+
} catch (error) {
|
|
221
|
+
return handleError(error, "Error getting workflow run counts");
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
});
|
|
225
|
+
const GET_WORKFLOW_BY_ID_ROUTE = createRoute({
|
|
226
|
+
method: "GET",
|
|
227
|
+
path: "/workflows/:workflowId",
|
|
228
|
+
responseType: "json",
|
|
229
|
+
pathParamSchema: workflowIdPathParams,
|
|
230
|
+
responseSchema: workflowInfoSchema,
|
|
231
|
+
summary: "Get workflow by ID",
|
|
232
|
+
description: "Returns details for a specific workflow",
|
|
233
|
+
tags: ["Workflows"],
|
|
234
|
+
requiresAuth: true,
|
|
235
|
+
handler: (async ({ mastra, workflowId }) => {
|
|
236
|
+
try {
|
|
237
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
238
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
239
|
+
mastra,
|
|
240
|
+
workflowId
|
|
241
|
+
});
|
|
242
|
+
return getWorkflowInfo(workflow, false);
|
|
243
|
+
} catch (error) {
|
|
244
|
+
return handleError(error, "Error getting workflow");
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
});
|
|
248
|
+
const LIST_WORKFLOW_RUNS_ROUTE = createRoute({
|
|
249
|
+
method: "GET",
|
|
250
|
+
path: "/workflows/:workflowId/runs",
|
|
251
|
+
responseType: "json",
|
|
252
|
+
pathParamSchema: workflowIdPathParams,
|
|
253
|
+
queryParamSchema: listWorkflowRunsQuerySchema,
|
|
254
|
+
responseSchema: workflowRunsResponseSchema,
|
|
255
|
+
summary: "List workflow runs",
|
|
256
|
+
description: "Returns a paginated list of execution runs for the specified workflow",
|
|
257
|
+
tags: ["Workflows"],
|
|
258
|
+
requiresAuth: true,
|
|
259
|
+
handler: async ({ mastra, workflowId, fromDate, toDate, page, perPage, limit, offset, resourceId, status, summary, requestContext }) => {
|
|
260
|
+
try {
|
|
261
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
|
|
262
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
263
|
+
let finalPage = page;
|
|
264
|
+
let finalPerPage = perPage;
|
|
265
|
+
if (finalPerPage === void 0 && limit !== void 0) finalPerPage = limit;
|
|
266
|
+
if (finalPage === void 0 && offset !== void 0 && finalPerPage !== void 0 && finalPerPage > 0) finalPage = Math.floor(offset / finalPerPage);
|
|
267
|
+
if (finalPerPage !== void 0 && (typeof finalPerPage !== "number" || !Number.isInteger(finalPerPage) || finalPerPage <= 0)) throw new HTTPException(400, { message: "perPage must be a positive integer" });
|
|
268
|
+
if (finalPage !== void 0 && (!Number.isInteger(finalPage) || finalPage < 0)) throw new HTTPException(400, { message: "page must be a non-negative integer" });
|
|
269
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
270
|
+
mastra,
|
|
271
|
+
workflowId
|
|
272
|
+
});
|
|
273
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
274
|
+
const workflowRuns = await workflow.listWorkflowRuns({
|
|
275
|
+
fromDate: fromDate ? typeof fromDate === "string" ? new Date(fromDate) : fromDate : void 0,
|
|
276
|
+
toDate: toDate ? typeof toDate === "string" ? new Date(toDate) : toDate : void 0,
|
|
277
|
+
perPage: finalPerPage,
|
|
278
|
+
page: finalPage,
|
|
279
|
+
resourceId: effectiveResourceId,
|
|
280
|
+
status,
|
|
281
|
+
...summary ? { summary: true } : {}
|
|
282
|
+
}) || {
|
|
283
|
+
runs: [],
|
|
284
|
+
total: 0
|
|
285
|
+
};
|
|
286
|
+
if (summary) return {
|
|
287
|
+
...workflowRuns,
|
|
288
|
+
runs: workflowRuns.runs.map((run) => ({
|
|
289
|
+
...run,
|
|
290
|
+
snapshot: toSummarySnapshot(run.snapshot)
|
|
291
|
+
}))
|
|
292
|
+
};
|
|
293
|
+
return workflowRuns;
|
|
294
|
+
} catch (error) {
|
|
295
|
+
return handleError(error, "Error getting workflow runs");
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
function toSummarySnapshot(snapshot) {
|
|
300
|
+
let parsed;
|
|
301
|
+
if (typeof snapshot === "string") try {
|
|
302
|
+
parsed = JSON.parse(snapshot);
|
|
303
|
+
} catch {
|
|
304
|
+
return "";
|
|
305
|
+
}
|
|
306
|
+
else parsed = snapshot;
|
|
307
|
+
if (!parsed || typeof parsed !== "object") return "";
|
|
308
|
+
const { status, timestamp } = parsed;
|
|
309
|
+
return {
|
|
310
|
+
status,
|
|
311
|
+
timestamp
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
const GET_WORKFLOW_RUN_BY_ID_ROUTE = createRoute({
|
|
315
|
+
method: "GET",
|
|
316
|
+
path: "/workflows/:workflowId/runs/:runId",
|
|
317
|
+
responseType: "json",
|
|
318
|
+
pathParamSchema: workflowRunPathParams,
|
|
319
|
+
queryParamSchema: workflowRunResultQuerySchema,
|
|
320
|
+
responseSchema: workflowRunResultSchema,
|
|
321
|
+
summary: "Get workflow run by ID",
|
|
322
|
+
description: "Returns a workflow run with metadata and processed execution state. Use the fields query parameter to reduce payload size by requesting only specific fields (e.g., ?fields=result,steps). Available fields: result, error, payload, steps, activeStepsPath, serializedStepGraph. Metadata fields (runId, workflowName, resourceId, createdAt, updatedAt) and status are always included.",
|
|
323
|
+
tags: ["Workflows"],
|
|
324
|
+
requiresAuth: true,
|
|
325
|
+
handler: async ({ mastra, workflowId, runId, fields, withNestedWorkflows, requestContext }) => {
|
|
326
|
+
try {
|
|
327
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
|
|
328
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
329
|
+
if (!runId) throw new HTTPException(400, { message: "Run ID is required" });
|
|
330
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
331
|
+
mastra,
|
|
332
|
+
workflowId
|
|
333
|
+
});
|
|
334
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
335
|
+
const fieldList = fields ? fields.split(",").map((f) => f.trim()) : void 0;
|
|
336
|
+
const run = await workflow.getWorkflowRunById(runId, {
|
|
337
|
+
withNestedWorkflows: withNestedWorkflows !== "false",
|
|
338
|
+
fields: fieldList
|
|
339
|
+
});
|
|
340
|
+
if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
|
|
341
|
+
await validateRunOwnership(run, effectiveResourceId, mastra);
|
|
342
|
+
return run;
|
|
343
|
+
} catch (error) {
|
|
344
|
+
return handleError(error, "Error getting workflow run");
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
const DELETE_WORKFLOW_RUN_BY_ID_ROUTE = createRoute({
|
|
349
|
+
method: "DELETE",
|
|
350
|
+
path: "/workflows/:workflowId/runs/:runId",
|
|
351
|
+
responseType: "json",
|
|
352
|
+
pathParamSchema: workflowRunPathParams,
|
|
353
|
+
responseSchema: workflowControlResponseSchema,
|
|
354
|
+
summary: "Delete workflow run by ID",
|
|
355
|
+
description: "Deletes a specific workflow run by ID",
|
|
356
|
+
tags: ["Workflows"],
|
|
357
|
+
requiresAuth: true,
|
|
358
|
+
handler: async ({ mastra, workflowId, runId, requestContext }) => {
|
|
359
|
+
try {
|
|
360
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
|
|
361
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
362
|
+
if (!runId) throw new HTTPException(400, { message: "Run ID is required" });
|
|
363
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
364
|
+
mastra,
|
|
365
|
+
workflowId
|
|
366
|
+
});
|
|
367
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
368
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
369
|
+
if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
|
|
370
|
+
await validateRunOwnership(run, effectiveResourceId, mastra);
|
|
371
|
+
await workflow.deleteWorkflowRunById(runId);
|
|
372
|
+
return { message: "Workflow run deleted" };
|
|
373
|
+
} catch (error) {
|
|
374
|
+
return handleError(error, "Error deleting workflow run");
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
const CREATE_WORKFLOW_RUN_ROUTE = createRoute({
|
|
379
|
+
method: "POST",
|
|
380
|
+
path: "/workflows/:workflowId/create-run",
|
|
381
|
+
responseType: "json",
|
|
382
|
+
pathParamSchema: workflowIdPathParams,
|
|
383
|
+
queryParamSchema: optionalRunIdSchema,
|
|
384
|
+
bodySchema: createWorkflowRunBodySchema,
|
|
385
|
+
responseSchema: createWorkflowRunResponseSchema,
|
|
386
|
+
summary: "Create workflow run",
|
|
387
|
+
description: "Creates a new workflow execution instance with an optional custom run ID",
|
|
388
|
+
tags: ["Workflows"],
|
|
389
|
+
requiresAuth: true,
|
|
390
|
+
requiresPermission: ["workflows:write", "workflows:execute"],
|
|
391
|
+
handler: async ({ mastra, workflowId, runId, resourceId, disableScorers, requestContext }) => {
|
|
392
|
+
try {
|
|
393
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
|
|
394
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
395
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
396
|
+
mastra,
|
|
397
|
+
workflowId
|
|
398
|
+
});
|
|
399
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
400
|
+
if (runId) {
|
|
401
|
+
const existingRun = await workflow.getWorkflowRunById(runId, { withNestedWorkflows: false });
|
|
402
|
+
await validateRunOwnership(existingRun, getEffectiveResourceId(requestContext, void 0), mastra);
|
|
403
|
+
}
|
|
404
|
+
return { runId: (await workflow.createRun({
|
|
405
|
+
runId,
|
|
406
|
+
resourceId: effectiveResourceId,
|
|
407
|
+
disableScorers
|
|
408
|
+
})).runId };
|
|
409
|
+
} catch (error) {
|
|
410
|
+
return handleError(error, "Error creating workflow run");
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
const STREAM_WORKFLOW_ROUTE = createRoute({
|
|
415
|
+
method: "POST",
|
|
416
|
+
path: "/workflows/:workflowId/stream",
|
|
417
|
+
responseType: "stream",
|
|
418
|
+
pathParamSchema: workflowIdPathParams,
|
|
419
|
+
queryParamSchema: runIdSchema,
|
|
420
|
+
bodySchema: streamWorkflowBodySchema,
|
|
421
|
+
summary: "Stream workflow execution",
|
|
422
|
+
description: "Executes a workflow and streams the results in real-time",
|
|
423
|
+
tags: ["Workflows"],
|
|
424
|
+
requiresAuth: true,
|
|
425
|
+
handler: async ({ mastra, workflowId, runId, resourceId, requestContext, ...params }) => {
|
|
426
|
+
try {
|
|
427
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
|
|
428
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
429
|
+
if (!runId) throw new HTTPException(400, { message: "runId required to stream workflow" });
|
|
430
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
431
|
+
mastra,
|
|
432
|
+
workflowId
|
|
433
|
+
});
|
|
434
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
435
|
+
const existingRun = await workflow.getWorkflowRunById(runId, { withNestedWorkflows: false });
|
|
436
|
+
await validateRunOwnership(existingRun, getEffectiveResourceId(requestContext, void 0), mastra);
|
|
437
|
+
if (existingRun && TERMINAL_RUN_STATUSES.includes(existingRun.status)) throw new HTTPException(409, { message: `Workflow run ${runId} already finished with status "${existingRun.status}". Use /observe to read its stream back, or stream a new runId.` });
|
|
438
|
+
const serverCache = mastra.getServerCache();
|
|
439
|
+
const result = (await workflow.createRun({
|
|
440
|
+
runId,
|
|
441
|
+
resourceId: effectiveResourceId
|
|
442
|
+
})).stream({
|
|
443
|
+
...params,
|
|
444
|
+
requestContext
|
|
445
|
+
});
|
|
446
|
+
if (serverCache) return cacheRunStream({
|
|
447
|
+
cache: serverCache,
|
|
448
|
+
runId,
|
|
449
|
+
source: result.fullStream
|
|
450
|
+
});
|
|
451
|
+
return result.fullStream;
|
|
452
|
+
} catch (error) {
|
|
453
|
+
return handleError(error, "Error streaming workflow");
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
const RESUME_STREAM_WORKFLOW_ROUTE = createRoute({
|
|
458
|
+
method: "POST",
|
|
459
|
+
path: "/workflows/:workflowId/resume-stream",
|
|
460
|
+
responseType: "stream",
|
|
461
|
+
pathParamSchema: workflowIdPathParams,
|
|
462
|
+
queryParamSchema: runIdSchema,
|
|
463
|
+
bodySchema: resumeBodySchema,
|
|
464
|
+
responseSchema: streamResponseSchema,
|
|
465
|
+
summary: "Resume workflow stream",
|
|
466
|
+
description: "Resumes a suspended workflow execution and continues streaming results",
|
|
467
|
+
tags: ["Workflows"],
|
|
468
|
+
requiresAuth: true,
|
|
469
|
+
handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
|
|
470
|
+
try {
|
|
471
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
|
|
472
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
473
|
+
if (!runId) throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
474
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
475
|
+
mastra,
|
|
476
|
+
workflowId
|
|
477
|
+
});
|
|
478
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
479
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
480
|
+
if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
|
|
481
|
+
await validateRunOwnership(run, effectiveResourceId, mastra);
|
|
482
|
+
const _run = await workflow.createRun({
|
|
483
|
+
runId,
|
|
484
|
+
resourceId: run.resourceId
|
|
485
|
+
});
|
|
486
|
+
const serverCache = mastra.getServerCache();
|
|
487
|
+
const resumeResult = _run.resumeStream({
|
|
488
|
+
...params,
|
|
489
|
+
requestContext
|
|
490
|
+
});
|
|
491
|
+
if (serverCache) return cacheRunStream({
|
|
492
|
+
cache: serverCache,
|
|
493
|
+
runId,
|
|
494
|
+
source: resumeResult.fullStream
|
|
495
|
+
});
|
|
496
|
+
return resumeResult.fullStream;
|
|
497
|
+
} catch (error) {
|
|
498
|
+
return handleError(error, "Error resuming workflow");
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
const START_ASYNC_WORKFLOW_ROUTE = createRoute({
|
|
503
|
+
method: "POST",
|
|
504
|
+
path: "/workflows/:workflowId/start-async",
|
|
505
|
+
responseType: "json",
|
|
506
|
+
pathParamSchema: workflowIdPathParams,
|
|
507
|
+
queryParamSchema: optionalRunIdSchema,
|
|
508
|
+
bodySchema: startAsyncWorkflowBodySchema,
|
|
509
|
+
responseSchema: workflowExecutionResultSchema,
|
|
510
|
+
summary: "Start workflow asynchronously",
|
|
511
|
+
description: "Starts a workflow execution asynchronously without streaming results",
|
|
512
|
+
tags: ["Workflows"],
|
|
513
|
+
requiresAuth: true,
|
|
514
|
+
handler: async ({ mastra, workflowId, runId, resourceId, requestContext, ...params }) => {
|
|
515
|
+
try {
|
|
516
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
|
|
517
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
518
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
519
|
+
mastra,
|
|
520
|
+
workflowId
|
|
521
|
+
});
|
|
522
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
523
|
+
if (runId) {
|
|
524
|
+
const existingRun = await workflow.getWorkflowRunById(runId, { withNestedWorkflows: false });
|
|
525
|
+
await validateRunOwnership(existingRun, getEffectiveResourceId(requestContext, void 0), mastra);
|
|
526
|
+
}
|
|
527
|
+
return await (await workflow.createRun({
|
|
528
|
+
runId,
|
|
529
|
+
resourceId: effectiveResourceId
|
|
530
|
+
})).start({
|
|
531
|
+
...params,
|
|
532
|
+
requestContext
|
|
533
|
+
});
|
|
534
|
+
} catch (error) {
|
|
535
|
+
return handleError(error, "Error starting async workflow");
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
const START_WORKFLOW_RUN_ROUTE = createRoute({
|
|
540
|
+
method: "POST",
|
|
541
|
+
path: "/workflows/:workflowId/start",
|
|
542
|
+
responseType: "json",
|
|
543
|
+
pathParamSchema: workflowIdPathParams,
|
|
544
|
+
queryParamSchema: runIdSchema,
|
|
545
|
+
bodySchema: startAsyncWorkflowBodySchema,
|
|
546
|
+
responseSchema: workflowControlResponseSchema,
|
|
547
|
+
summary: "Start specific workflow run",
|
|
548
|
+
description: "Starts execution of a specific workflow run by ID",
|
|
549
|
+
tags: ["Workflows"],
|
|
550
|
+
requiresAuth: true,
|
|
551
|
+
handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
|
|
552
|
+
try {
|
|
553
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
|
|
554
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
555
|
+
if (!runId) throw new HTTPException(400, { message: "runId required to start run" });
|
|
556
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
557
|
+
mastra,
|
|
558
|
+
workflowId
|
|
559
|
+
});
|
|
560
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
561
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
562
|
+
if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
|
|
563
|
+
await validateRunOwnership(run, effectiveResourceId, mastra);
|
|
564
|
+
(await workflow.createRun({
|
|
565
|
+
runId,
|
|
566
|
+
resourceId: run.resourceId
|
|
567
|
+
})).start({
|
|
568
|
+
...params,
|
|
569
|
+
requestContext
|
|
570
|
+
}).catch((error) => {
|
|
571
|
+
mastra.getLogger().error("Failed to start workflow run", {
|
|
572
|
+
error,
|
|
573
|
+
workflowId,
|
|
574
|
+
runId
|
|
575
|
+
});
|
|
576
|
+
});
|
|
577
|
+
return { message: "Workflow run started" };
|
|
578
|
+
} catch (e) {
|
|
579
|
+
return handleError(e, "Error starting workflow run");
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
const OBSERVE_STREAM_WORKFLOW_ROUTE = createRoute({
|
|
584
|
+
method: "POST",
|
|
585
|
+
path: "/workflows/:workflowId/observe",
|
|
586
|
+
responseType: "stream",
|
|
587
|
+
pathParamSchema: workflowIdPathParams,
|
|
588
|
+
queryParamSchema: observeWorkflowQuerySchema,
|
|
589
|
+
responseSchema: streamResponseSchema,
|
|
590
|
+
summary: "Observe workflow stream",
|
|
591
|
+
description: "Observes and streams updates from an already running workflow execution. Supports position-based resume with offset for efficient reconnection.",
|
|
592
|
+
tags: ["Workflows"],
|
|
593
|
+
requiresAuth: true,
|
|
594
|
+
handler: async ({ mastra, workflowId, runId, offset, requestContext }) => {
|
|
595
|
+
try {
|
|
596
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
|
|
597
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
598
|
+
if (!runId) throw new HTTPException(400, { message: "runId required to observe workflow stream" });
|
|
599
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
600
|
+
mastra,
|
|
601
|
+
workflowId
|
|
602
|
+
});
|
|
603
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
604
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
605
|
+
if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
|
|
606
|
+
await validateRunOwnership(run, effectiveResourceId, mastra);
|
|
607
|
+
const _run = await workflow.createRun({
|
|
608
|
+
runId,
|
|
609
|
+
resourceId: run.resourceId
|
|
610
|
+
});
|
|
611
|
+
const serverCache = mastra.getServerCache();
|
|
612
|
+
if (!serverCache) throw new HTTPException(500, { message: "Server cache not found" });
|
|
613
|
+
const startIndex = offset ?? 0;
|
|
614
|
+
const cachedRunChunks = await serverCache.listFromTo(runId, startIndex);
|
|
615
|
+
const liveStream = _run.observeStream();
|
|
616
|
+
return createReplayStream({
|
|
617
|
+
history: cachedRunChunks,
|
|
618
|
+
liveSource: liveStream
|
|
619
|
+
});
|
|
620
|
+
} catch (error) {
|
|
621
|
+
return handleError(error, "Error observing workflow stream");
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
const RESUME_ASYNC_WORKFLOW_ROUTE = createRoute({
|
|
626
|
+
method: "POST",
|
|
627
|
+
path: "/workflows/:workflowId/resume-async",
|
|
628
|
+
responseType: "json",
|
|
629
|
+
pathParamSchema: workflowIdPathParams,
|
|
630
|
+
queryParamSchema: runIdSchema,
|
|
631
|
+
bodySchema: resumeBodySchema,
|
|
632
|
+
responseSchema: workflowExecutionResultSchema,
|
|
633
|
+
summary: "Resume workflow asynchronously",
|
|
634
|
+
description: "Resumes a suspended workflow execution asynchronously without streaming",
|
|
635
|
+
tags: ["Workflows"],
|
|
636
|
+
requiresAuth: true,
|
|
637
|
+
handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
|
|
638
|
+
try {
|
|
639
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
|
|
640
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
641
|
+
if (!runId) throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
642
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
643
|
+
mastra,
|
|
644
|
+
workflowId
|
|
645
|
+
});
|
|
646
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
647
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
648
|
+
if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
|
|
649
|
+
await validateRunOwnership(run, effectiveResourceId, mastra);
|
|
650
|
+
return await (await workflow.createRun({
|
|
651
|
+
runId,
|
|
652
|
+
resourceId: run.resourceId
|
|
653
|
+
})).resume({
|
|
654
|
+
...params,
|
|
655
|
+
requestContext
|
|
656
|
+
});
|
|
657
|
+
} catch (error) {
|
|
658
|
+
return handleError(error, "Error resuming workflow step");
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
/**
|
|
663
|
+
* Fire-and-forget resume: dispatches the resume and returns immediately with the runId,
|
|
664
|
+
* without waiting for the workflow to complete. For Inngest-backed workflows this avoids
|
|
665
|
+
* the `getRunOutput()` polling race that the awaiting `resume-async` route can hit.
|
|
666
|
+
*
|
|
667
|
+
* TODO(v2): in Mastra v2 this fire-and-forget behavior should become the behavior of the
|
|
668
|
+
* `resume-async` route (and `Run.resumeAsync()`), and this route should be removed. It is
|
|
669
|
+
* kept separate in v1 to avoid a breaking change to the existing `resume-async` response
|
|
670
|
+
* contract (which returns the full workflow result).
|
|
671
|
+
*/
|
|
672
|
+
const RESUME_NO_WAIT_WORKFLOW_ROUTE = createRoute({
|
|
673
|
+
method: "POST",
|
|
674
|
+
path: "/workflows/:workflowId/resume-no-wait",
|
|
675
|
+
responseType: "json",
|
|
676
|
+
pathParamSchema: workflowIdPathParams,
|
|
677
|
+
queryParamSchema: runIdSchema,
|
|
678
|
+
bodySchema: resumeBodySchema,
|
|
679
|
+
responseSchema: createWorkflowRunResponseSchema,
|
|
680
|
+
summary: "Resume workflow without waiting",
|
|
681
|
+
description: "Resumes a suspended workflow execution without waiting (fire-and-forget) and returns immediately with the runId. The workflow continues executing in the background.",
|
|
682
|
+
tags: ["Workflows"],
|
|
683
|
+
requiresAuth: true,
|
|
684
|
+
handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
|
|
685
|
+
try {
|
|
686
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
|
|
687
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
688
|
+
if (!runId) throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
689
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
690
|
+
mastra,
|
|
691
|
+
workflowId
|
|
692
|
+
});
|
|
693
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
694
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
695
|
+
if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
|
|
696
|
+
await validateRunOwnership(run, effectiveResourceId, mastra);
|
|
697
|
+
return await (await workflow.createRun({
|
|
698
|
+
runId,
|
|
699
|
+
resourceId: run.resourceId
|
|
700
|
+
})).resumeAsync({
|
|
701
|
+
...params,
|
|
702
|
+
requestContext
|
|
703
|
+
});
|
|
704
|
+
} catch (error) {
|
|
705
|
+
return handleError(error, "Error resuming workflow step");
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
const RESUME_WORKFLOW_ROUTE = createRoute({
|
|
710
|
+
method: "POST",
|
|
711
|
+
path: "/workflows/:workflowId/resume",
|
|
712
|
+
responseType: "json",
|
|
713
|
+
pathParamSchema: workflowIdPathParams,
|
|
714
|
+
queryParamSchema: runIdSchema,
|
|
715
|
+
bodySchema: resumeBodySchema,
|
|
716
|
+
responseSchema: workflowControlResponseSchema,
|
|
717
|
+
summary: "Resume workflow",
|
|
718
|
+
description: "Resumes a suspended workflow execution from a specific step",
|
|
719
|
+
tags: ["Workflows"],
|
|
720
|
+
requiresAuth: true,
|
|
721
|
+
handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
|
|
722
|
+
try {
|
|
723
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
|
|
724
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
725
|
+
if (!runId) throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
726
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
727
|
+
mastra,
|
|
728
|
+
workflowId
|
|
729
|
+
});
|
|
730
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
731
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
732
|
+
if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
|
|
733
|
+
await validateRunOwnership(run, effectiveResourceId, mastra);
|
|
734
|
+
(await workflow.createRun({
|
|
735
|
+
runId,
|
|
736
|
+
resourceId: run.resourceId
|
|
737
|
+
})).resume({
|
|
738
|
+
...params,
|
|
739
|
+
requestContext
|
|
740
|
+
}).catch((error) => {
|
|
741
|
+
mastra.getLogger().error("Failed to resume workflow run", {
|
|
742
|
+
error,
|
|
743
|
+
workflowId,
|
|
744
|
+
runId
|
|
745
|
+
});
|
|
746
|
+
});
|
|
747
|
+
return { message: "Workflow run resumed" };
|
|
748
|
+
} catch (error) {
|
|
749
|
+
return handleError(error, "Error resuming workflow");
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
const RESTART_ASYNC_WORKFLOW_ROUTE = createRoute({
|
|
754
|
+
method: "POST",
|
|
755
|
+
path: "/workflows/:workflowId/restart-async",
|
|
756
|
+
responseType: "json",
|
|
757
|
+
pathParamSchema: workflowIdPathParams,
|
|
758
|
+
queryParamSchema: runIdSchema,
|
|
759
|
+
bodySchema: restartBodySchema,
|
|
760
|
+
responseSchema: workflowExecutionResultSchema,
|
|
761
|
+
summary: "Restart workflow asynchronously",
|
|
762
|
+
description: "Restarts an active workflow execution asynchronously",
|
|
763
|
+
tags: ["Workflows"],
|
|
764
|
+
requiresAuth: true,
|
|
765
|
+
handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
|
|
766
|
+
try {
|
|
767
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
|
|
768
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
769
|
+
if (!runId) throw new HTTPException(400, { message: "runId required to restart workflow" });
|
|
770
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
771
|
+
mastra,
|
|
772
|
+
workflowId
|
|
773
|
+
});
|
|
774
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
775
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
776
|
+
if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
|
|
777
|
+
await validateRunOwnership(run, effectiveResourceId, mastra);
|
|
778
|
+
return await (await workflow.createRun({
|
|
779
|
+
runId,
|
|
780
|
+
resourceId: run.resourceId
|
|
781
|
+
})).restart({
|
|
782
|
+
...params,
|
|
783
|
+
requestContext
|
|
784
|
+
});
|
|
785
|
+
} catch (error) {
|
|
786
|
+
return handleError(error, "Error restarting workflow");
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
const RESTART_WORKFLOW_ROUTE = createRoute({
|
|
791
|
+
method: "POST",
|
|
792
|
+
path: "/workflows/:workflowId/restart",
|
|
793
|
+
responseType: "json",
|
|
794
|
+
pathParamSchema: workflowIdPathParams,
|
|
795
|
+
queryParamSchema: runIdSchema,
|
|
796
|
+
bodySchema: restartBodySchema,
|
|
797
|
+
responseSchema: workflowControlResponseSchema,
|
|
798
|
+
summary: "Restart workflow",
|
|
799
|
+
description: "Restarts an active workflow execution",
|
|
800
|
+
tags: ["Workflows"],
|
|
801
|
+
requiresAuth: true,
|
|
802
|
+
handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
|
|
803
|
+
try {
|
|
804
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
|
|
805
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
806
|
+
if (!runId) throw new HTTPException(400, { message: "runId required to restart workflow" });
|
|
807
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
808
|
+
mastra,
|
|
809
|
+
workflowId
|
|
810
|
+
});
|
|
811
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
812
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
813
|
+
if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
|
|
814
|
+
await validateRunOwnership(run, effectiveResourceId, mastra);
|
|
815
|
+
(await workflow.createRun({
|
|
816
|
+
runId,
|
|
817
|
+
resourceId: run.resourceId
|
|
818
|
+
})).restart({
|
|
819
|
+
...params,
|
|
820
|
+
requestContext
|
|
821
|
+
}).catch((error) => {
|
|
822
|
+
mastra.getLogger().error("Failed to restart workflow run in background", {
|
|
823
|
+
error,
|
|
824
|
+
workflowId,
|
|
825
|
+
runId
|
|
826
|
+
});
|
|
827
|
+
});
|
|
828
|
+
return { message: "Workflow run restarted" };
|
|
829
|
+
} catch (error) {
|
|
830
|
+
return handleError(error, "Error restarting workflow");
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
});
|
|
834
|
+
const RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ASYNC_ROUTE = createRoute({
|
|
835
|
+
method: "POST",
|
|
836
|
+
path: "/workflows/:workflowId/restart-all-active-workflow-runs-async",
|
|
837
|
+
responseType: "json",
|
|
838
|
+
pathParamSchema: workflowIdPathParams,
|
|
839
|
+
responseSchema: workflowControlResponseSchema,
|
|
840
|
+
summary: "Restart all active workflow runs asynchronously",
|
|
841
|
+
description: "Restarts all active workflow runs asynchronously",
|
|
842
|
+
tags: ["Workflows"],
|
|
843
|
+
requiresAuth: true,
|
|
844
|
+
handler: async ({ mastra, workflowId, requestContext }) => {
|
|
845
|
+
try {
|
|
846
|
+
await validateRunOwnership({ resourceId: null }, getEffectiveResourceId(requestContext, void 0), mastra);
|
|
847
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
848
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
849
|
+
mastra,
|
|
850
|
+
workflowId
|
|
851
|
+
});
|
|
852
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
853
|
+
await workflow.restartAllActiveWorkflowRuns();
|
|
854
|
+
return { message: "All active workflow runs restarted" };
|
|
855
|
+
} catch (error) {
|
|
856
|
+
return handleError(error, "Error restarting workflow");
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
});
|
|
860
|
+
const RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ROUTE = createRoute({
|
|
861
|
+
method: "POST",
|
|
862
|
+
path: "/workflows/:workflowId/restart-all-active-workflow-runs",
|
|
863
|
+
responseType: "json",
|
|
864
|
+
pathParamSchema: workflowIdPathParams,
|
|
865
|
+
responseSchema: workflowControlResponseSchema,
|
|
866
|
+
summary: "Restart all active workflow runs",
|
|
867
|
+
description: "Restarts all active workflow runs",
|
|
868
|
+
tags: ["Workflows"],
|
|
869
|
+
requiresAuth: true,
|
|
870
|
+
handler: async ({ mastra, workflowId, requestContext }) => {
|
|
871
|
+
try {
|
|
872
|
+
await validateRunOwnership({ resourceId: null }, getEffectiveResourceId(requestContext, void 0), mastra);
|
|
873
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
874
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
875
|
+
mastra,
|
|
876
|
+
workflowId
|
|
877
|
+
});
|
|
878
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
879
|
+
workflow.restartAllActiveWorkflowRuns().catch((error) => {
|
|
880
|
+
mastra.getLogger().error("Failed to restart active workflow runs", {
|
|
881
|
+
error,
|
|
882
|
+
workflowId
|
|
883
|
+
});
|
|
884
|
+
});
|
|
885
|
+
return { message: "All active workflow runs restarted" };
|
|
886
|
+
} catch (error) {
|
|
887
|
+
return handleError(error, "Error restarting workflow");
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
const TIME_TRAVEL_ASYNC_WORKFLOW_ROUTE = createRoute({
|
|
892
|
+
method: "POST",
|
|
893
|
+
path: "/workflows/:workflowId/time-travel-async",
|
|
894
|
+
responseType: "json",
|
|
895
|
+
pathParamSchema: workflowIdPathParams,
|
|
896
|
+
queryParamSchema: runIdSchema,
|
|
897
|
+
bodySchema: timeTravelBodySchema,
|
|
898
|
+
responseSchema: workflowExecutionResultSchema,
|
|
899
|
+
summary: "Time travel workflow asynchronously",
|
|
900
|
+
description: "Time travels a workflow run asynchronously without streaming",
|
|
901
|
+
tags: ["Workflows"],
|
|
902
|
+
requiresAuth: true,
|
|
903
|
+
handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
|
|
904
|
+
try {
|
|
905
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
|
|
906
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
907
|
+
if (!runId) throw new HTTPException(400, { message: "runId required to time travel workflow" });
|
|
908
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
909
|
+
mastra,
|
|
910
|
+
workflowId
|
|
911
|
+
});
|
|
912
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
913
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
914
|
+
if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
|
|
915
|
+
await validateRunOwnership(run, effectiveResourceId, mastra);
|
|
916
|
+
return await (await workflow.createRun({
|
|
917
|
+
runId,
|
|
918
|
+
resourceId: run.resourceId
|
|
919
|
+
})).timeTravel({
|
|
920
|
+
...params,
|
|
921
|
+
requestContext
|
|
922
|
+
});
|
|
923
|
+
} catch (error) {
|
|
924
|
+
return handleError(error, "Error time traveling workflow");
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
});
|
|
928
|
+
const TIME_TRAVEL_WORKFLOW_ROUTE = createRoute({
|
|
929
|
+
method: "POST",
|
|
930
|
+
path: "/workflows/:workflowId/time-travel",
|
|
931
|
+
responseType: "json",
|
|
932
|
+
pathParamSchema: workflowIdPathParams,
|
|
933
|
+
queryParamSchema: runIdSchema,
|
|
934
|
+
bodySchema: timeTravelBodySchema,
|
|
935
|
+
responseSchema: workflowControlResponseSchema,
|
|
936
|
+
summary: "Time travel workflow",
|
|
937
|
+
description: "Time travels a workflow run, starting from a specific step",
|
|
938
|
+
tags: ["Workflows"],
|
|
939
|
+
requiresAuth: true,
|
|
940
|
+
handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
|
|
941
|
+
try {
|
|
942
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
|
|
943
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
944
|
+
if (!runId) throw new HTTPException(400, { message: "runId required to time travel workflow" });
|
|
945
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
946
|
+
mastra,
|
|
947
|
+
workflowId
|
|
948
|
+
});
|
|
949
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
950
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
951
|
+
if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
|
|
952
|
+
await validateRunOwnership(run, effectiveResourceId, mastra);
|
|
953
|
+
(await workflow.createRun({
|
|
954
|
+
runId,
|
|
955
|
+
resourceId: run.resourceId
|
|
956
|
+
})).timeTravel({
|
|
957
|
+
...params,
|
|
958
|
+
requestContext
|
|
959
|
+
}).catch((error) => {
|
|
960
|
+
mastra.getLogger().error("Failed to time travel workflow run", {
|
|
961
|
+
error,
|
|
962
|
+
workflowId,
|
|
963
|
+
runId
|
|
964
|
+
});
|
|
965
|
+
});
|
|
966
|
+
return { message: "Workflow run time travel started" };
|
|
967
|
+
} catch (error) {
|
|
968
|
+
return handleError(error, "Error time traveling workflow");
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
});
|
|
972
|
+
const TIME_TRAVEL_STREAM_WORKFLOW_ROUTE = createRoute({
|
|
973
|
+
method: "POST",
|
|
974
|
+
path: "/workflows/:workflowId/time-travel-stream",
|
|
975
|
+
responseType: "stream",
|
|
976
|
+
pathParamSchema: workflowIdPathParams,
|
|
977
|
+
queryParamSchema: runIdSchema,
|
|
978
|
+
bodySchema: timeTravelBodySchema,
|
|
979
|
+
summary: "Time travel workflow stream",
|
|
980
|
+
description: "Time travels a workflow run, starting from a specific step, and streams the results in real-time",
|
|
981
|
+
tags: ["Workflows"],
|
|
982
|
+
requiresAuth: true,
|
|
983
|
+
handler: async ({ mastra, workflowId, runId, requestContext, ...params }) => {
|
|
984
|
+
try {
|
|
985
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
|
|
986
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
987
|
+
if (!runId) throw new HTTPException(400, { message: "runId required to time travel workflow stream" });
|
|
988
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
989
|
+
mastra,
|
|
990
|
+
workflowId
|
|
991
|
+
});
|
|
992
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
993
|
+
const existingRun = await workflow.getWorkflowRunById(runId);
|
|
994
|
+
if (!existingRun) throw new HTTPException(404, { message: "Workflow run not found" });
|
|
995
|
+
await validateRunOwnership(existingRun, effectiveResourceId, mastra);
|
|
996
|
+
const serverCache = mastra.getServerCache();
|
|
997
|
+
const result = (await workflow.createRun({
|
|
998
|
+
runId,
|
|
999
|
+
resourceId: existingRun.resourceId
|
|
1000
|
+
})).timeTravelStream({
|
|
1001
|
+
...params,
|
|
1002
|
+
requestContext
|
|
1003
|
+
});
|
|
1004
|
+
if (serverCache) return cacheRunStream({
|
|
1005
|
+
cache: serverCache,
|
|
1006
|
+
runId,
|
|
1007
|
+
source: result.fullStream
|
|
1008
|
+
});
|
|
1009
|
+
return result.fullStream;
|
|
1010
|
+
} catch (error) {
|
|
1011
|
+
return handleError(error, "Error time traveling workflow stream");
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
});
|
|
1015
|
+
const CANCEL_WORKFLOW_RUN_ROUTE = createRoute({
|
|
1016
|
+
method: "POST",
|
|
1017
|
+
path: "/workflows/:workflowId/runs/:runId/cancel",
|
|
1018
|
+
responseType: "json",
|
|
1019
|
+
pathParamSchema: workflowRunPathParams,
|
|
1020
|
+
responseSchema: workflowControlResponseSchema,
|
|
1021
|
+
summary: "Cancel workflow run",
|
|
1022
|
+
description: "Cancels an in-progress workflow execution",
|
|
1023
|
+
tags: ["Workflows"],
|
|
1024
|
+
requiresAuth: true,
|
|
1025
|
+
handler: async ({ mastra, workflowId, runId, requestContext }) => {
|
|
1026
|
+
try {
|
|
1027
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
|
|
1028
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
1029
|
+
if (!runId) throw new HTTPException(400, { message: "runId required to cancel workflow run" });
|
|
1030
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
1031
|
+
mastra,
|
|
1032
|
+
workflowId
|
|
1033
|
+
});
|
|
1034
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
1035
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
1036
|
+
if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
|
|
1037
|
+
await validateRunOwnership(run, effectiveResourceId, mastra);
|
|
1038
|
+
await (await workflow.createRun({
|
|
1039
|
+
runId,
|
|
1040
|
+
resourceId: run.resourceId
|
|
1041
|
+
})).cancel();
|
|
1042
|
+
return { message: "Workflow run cancelled" };
|
|
1043
|
+
} catch (error) {
|
|
1044
|
+
return handleError(error, "Error canceling workflow run");
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
const STREAM_LEGACY_WORKFLOW_ROUTE = createRoute({
|
|
1049
|
+
method: "POST",
|
|
1050
|
+
path: "/workflows/:workflowId/stream-legacy",
|
|
1051
|
+
responseType: "stream",
|
|
1052
|
+
pathParamSchema: workflowIdPathParams,
|
|
1053
|
+
queryParamSchema: runIdSchema,
|
|
1054
|
+
bodySchema: streamWorkflowBodySchema,
|
|
1055
|
+
responseSchema: streamResponseSchema,
|
|
1056
|
+
summary: "[DEPRECATED] Stream workflow with legacy format",
|
|
1057
|
+
description: "Legacy endpoint for streaming workflow execution. Use /workflows/:workflowId/stream instead.",
|
|
1058
|
+
tags: ["Workflows", "Legacy"],
|
|
1059
|
+
requiresAuth: true,
|
|
1060
|
+
handler: async ({ mastra, workflowId, runId, resourceId, requestContext, ...params }) => {
|
|
1061
|
+
try {
|
|
1062
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, resourceId);
|
|
1063
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
1064
|
+
if (!runId) throw new HTTPException(400, { message: "runId required to resume workflow" });
|
|
1065
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
1066
|
+
mastra,
|
|
1067
|
+
workflowId
|
|
1068
|
+
});
|
|
1069
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
1070
|
+
const serverCache = mastra.getServerCache();
|
|
1071
|
+
if (runId) {
|
|
1072
|
+
const existingRun = await workflow.getWorkflowRunById(runId, { withNestedWorkflows: false });
|
|
1073
|
+
await validateRunOwnership(existingRun, getEffectiveResourceId(requestContext, void 0), mastra);
|
|
1074
|
+
}
|
|
1075
|
+
return (await workflow.createRun({
|
|
1076
|
+
runId,
|
|
1077
|
+
resourceId: effectiveResourceId
|
|
1078
|
+
})).streamLegacy({
|
|
1079
|
+
...params,
|
|
1080
|
+
requestContext,
|
|
1081
|
+
onChunk: async (chunk) => {
|
|
1082
|
+
if (serverCache) {
|
|
1083
|
+
const cacheKey = runId;
|
|
1084
|
+
await serverCache.listPush(cacheKey, chunk);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
}).stream;
|
|
1088
|
+
} catch (error) {
|
|
1089
|
+
return handleError(error, "Error executing workflow");
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
});
|
|
1093
|
+
const OBSERVE_STREAM_LEGACY_WORKFLOW_ROUTE = createRoute({
|
|
1094
|
+
method: "POST",
|
|
1095
|
+
path: "/workflows/:workflowId/observe-stream-legacy",
|
|
1096
|
+
responseType: "stream",
|
|
1097
|
+
pathParamSchema: workflowIdPathParams,
|
|
1098
|
+
queryParamSchema: runIdSchema,
|
|
1099
|
+
responseSchema: streamResponseSchema,
|
|
1100
|
+
summary: "[DEPRECATED] Observe workflow stream with legacy format",
|
|
1101
|
+
description: "Legacy endpoint for observing workflow stream. Use /workflows/:workflowId/observe instead.",
|
|
1102
|
+
tags: ["Workflows", "Legacy"],
|
|
1103
|
+
requiresAuth: true,
|
|
1104
|
+
handler: async ({ mastra, workflowId, runId, requestContext }) => {
|
|
1105
|
+
try {
|
|
1106
|
+
const effectiveResourceId = getEffectiveResourceId(requestContext, void 0);
|
|
1107
|
+
if (!workflowId) throw new HTTPException(400, { message: "Workflow ID is required" });
|
|
1108
|
+
if (!runId) throw new HTTPException(400, { message: "runId required to observe workflow stream" });
|
|
1109
|
+
const { workflow } = await listWorkflowsFromSystem({
|
|
1110
|
+
mastra,
|
|
1111
|
+
workflowId
|
|
1112
|
+
});
|
|
1113
|
+
if (!workflow) throw new HTTPException(404, { message: "Workflow not found" });
|
|
1114
|
+
const run = await workflow.getWorkflowRunById(runId);
|
|
1115
|
+
if (!run) throw new HTTPException(404, { message: "Workflow run not found" });
|
|
1116
|
+
await validateRunOwnership(run, effectiveResourceId, mastra);
|
|
1117
|
+
const _run = await workflow.createRun({
|
|
1118
|
+
runId,
|
|
1119
|
+
resourceId: run.resourceId
|
|
1120
|
+
});
|
|
1121
|
+
const serverCache = mastra.getServerCache();
|
|
1122
|
+
if (!serverCache) throw new HTTPException(500, { message: "Server cache not found" });
|
|
1123
|
+
const cachedRunChunks = await serverCache.listFromTo(runId, 0);
|
|
1124
|
+
const result = _run.observeStreamLegacy();
|
|
1125
|
+
if (!result.stream) throw new HTTPException(500, { message: "Failed to create observe stream" });
|
|
1126
|
+
return createReplayStream({
|
|
1127
|
+
history: cachedRunChunks,
|
|
1128
|
+
liveSource: result.stream
|
|
1129
|
+
});
|
|
1130
|
+
} catch (error) {
|
|
1131
|
+
return handleError(error, "Error observing workflow stream");
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
});
|
|
1135
|
+
const stepExecutionParentWorkflowSchema = z.lazy(() => z.object({
|
|
1136
|
+
workflowId: z.string(),
|
|
1137
|
+
runId: z.string(),
|
|
1138
|
+
executionPath: z.array(z.number().int().nonnegative()),
|
|
1139
|
+
parentWorkflow: stepExecutionParentWorkflowSchema.optional()
|
|
1140
|
+
}));
|
|
1141
|
+
const stepExecutionBodySchema = z.object({
|
|
1142
|
+
stepId: z.string(),
|
|
1143
|
+
executionPath: z.array(z.number().int().nonnegative()),
|
|
1144
|
+
parentWorkflow: stepExecutionParentWorkflowSchema.optional(),
|
|
1145
|
+
stepResults: z.record(z.string(), z.unknown()),
|
|
1146
|
+
state: z.record(z.string(), z.unknown()),
|
|
1147
|
+
requestContext: z.record(z.string(), z.unknown()),
|
|
1148
|
+
input: z.unknown().optional(),
|
|
1149
|
+
resumeData: z.unknown().optional(),
|
|
1150
|
+
retryCount: z.number().int().nonnegative().optional(),
|
|
1151
|
+
foreachIdx: z.number().int().nonnegative().optional(),
|
|
1152
|
+
format: z.enum(["legacy", "vnext"]).optional(),
|
|
1153
|
+
perStep: z.boolean().optional(),
|
|
1154
|
+
validateInputs: z.boolean().optional()
|
|
1155
|
+
});
|
|
1156
|
+
const strategyByMastra = /* @__PURE__ */ new WeakMap();
|
|
1157
|
+
async function getStepStrategy(mastra) {
|
|
1158
|
+
let cached = strategyByMastra.get(mastra);
|
|
1159
|
+
if (!cached) {
|
|
1160
|
+
const { InProcessStrategy } = await import("@mastra/core/worker");
|
|
1161
|
+
cached = new InProcessStrategy({ mastra });
|
|
1162
|
+
strategyByMastra.set(mastra, cached);
|
|
1163
|
+
}
|
|
1164
|
+
return cached;
|
|
1165
|
+
}
|
|
1166
|
+
const stepExecutionResponseSchema = z.unknown();
|
|
1167
|
+
const EXECUTE_WORKFLOW_STEP_ROUTE = createRoute({
|
|
1168
|
+
method: "POST",
|
|
1169
|
+
path: "/workflows/:workflowId/runs/:runId/steps/execute",
|
|
1170
|
+
responseType: "json",
|
|
1171
|
+
pathParamSchema: workflowRunPathParams,
|
|
1172
|
+
bodySchema: stepExecutionBodySchema,
|
|
1173
|
+
responseSchema: stepExecutionResponseSchema,
|
|
1174
|
+
summary: "Execute a workflow step",
|
|
1175
|
+
description: "Internal endpoint used by standalone OrchestrationWorker instances to execute workflow steps remotely via HttpRemoteStrategy.",
|
|
1176
|
+
tags: ["Workflows", "Worker"],
|
|
1177
|
+
requiresAuth: true,
|
|
1178
|
+
handler: (async ({ mastra, workflowId, runId, ...body }) => {
|
|
1179
|
+
try {
|
|
1180
|
+
const candidate = body.requestContext;
|
|
1181
|
+
const serverRequestContext = typeof candidate?.get === "function" ? candidate : void 0;
|
|
1182
|
+
const existingRun = await (await mastra.getStorage()?.getStore("workflows"))?.getWorkflowRunById({
|
|
1183
|
+
runId,
|
|
1184
|
+
workflowName: workflowId
|
|
1185
|
+
});
|
|
1186
|
+
await validateRunOwnership(existingRun, getEffectiveResourceId(serverRequestContext, void 0), mastra);
|
|
1187
|
+
return await (await getStepStrategy(mastra)).executeStep({
|
|
1188
|
+
workflowId,
|
|
1189
|
+
runId,
|
|
1190
|
+
stepId: body.stepId,
|
|
1191
|
+
executionPath: body.executionPath,
|
|
1192
|
+
parentWorkflow: body.parentWorkflow,
|
|
1193
|
+
stepResults: body.stepResults,
|
|
1194
|
+
state: body.state,
|
|
1195
|
+
requestContext: body.requestContext,
|
|
1196
|
+
input: body.input,
|
|
1197
|
+
resumeData: body.resumeData,
|
|
1198
|
+
retryCount: body.retryCount,
|
|
1199
|
+
foreachIdx: body.foreachIdx,
|
|
1200
|
+
format: body.format,
|
|
1201
|
+
perStep: body.perStep,
|
|
1202
|
+
validateInputs: body.validateInputs
|
|
1203
|
+
});
|
|
1204
|
+
} catch (error) {
|
|
1205
|
+
return handleError(error, "Error executing workflow step");
|
|
1206
|
+
}
|
|
1207
|
+
})
|
|
1208
|
+
});
|
|
1209
|
+
const workflowEventSchema = z.object({
|
|
1210
|
+
id: z.string(),
|
|
1211
|
+
type: z.string(),
|
|
1212
|
+
data: z.unknown(),
|
|
1213
|
+
runId: z.string(),
|
|
1214
|
+
createdAt: z.string(),
|
|
1215
|
+
index: z.number().optional(),
|
|
1216
|
+
deliveryAttempt: z.number().optional()
|
|
1217
|
+
});
|
|
1218
|
+
const receiveWorkflowEventBodySchema = z.object({ event: workflowEventSchema.passthrough() });
|
|
1219
|
+
const receiveWorkflowEventResponseSchema = z.object({
|
|
1220
|
+
ok: z.boolean(),
|
|
1221
|
+
retry: z.boolean().optional()
|
|
1222
|
+
});
|
|
1223
|
+
/**
|
|
1224
|
+
* Generic push receive endpoint for workflow events. A push-mode broker
|
|
1225
|
+
* (GCP Pub/Sub push subscription, SNS, EventBridge) — or a per-broker adapter
|
|
1226
|
+
* that decodes the broker's envelope first — POSTs each event here and the
|
|
1227
|
+
* response code tells the broker whether to retry:
|
|
1228
|
+
*
|
|
1229
|
+
* - 200/204 → ack
|
|
1230
|
+
* - 5xx → transient, retry with backoff
|
|
1231
|
+
* - 4xx → poison, drop / send to DLQ
|
|
1232
|
+
*
|
|
1233
|
+
* Auth is enforced through the framework's standard `requiresAuth` flow.
|
|
1234
|
+
* Operators MUST configure an `authenticateToken` provider that recognizes
|
|
1235
|
+
* whatever credential the broker attaches (e.g. a Google-signed OIDC token
|
|
1236
|
+
* for GCP Pub/Sub push). Without an auth provider the endpoint is effectively
|
|
1237
|
+
* public — same caveat as `EXECUTE_WORKFLOW_STEP_ROUTE`.
|
|
1238
|
+
*/
|
|
1239
|
+
const RECEIVE_WORKFLOW_EVENT_ROUTE = createRoute({
|
|
1240
|
+
method: "POST",
|
|
1241
|
+
path: "/workflows/events",
|
|
1242
|
+
responseType: "json",
|
|
1243
|
+
bodySchema: receiveWorkflowEventBodySchema,
|
|
1244
|
+
responseSchema: receiveWorkflowEventResponseSchema,
|
|
1245
|
+
summary: "Receive a workflow event from a push-mode broker",
|
|
1246
|
+
description: "Push-mode entry point for workflow events. Brokers (GCP Pub/Sub push, SNS, EventBridge) POST each event here; Mastra processes it through the same pipeline as pull-mode workers.",
|
|
1247
|
+
tags: ["Workflows", "Worker"],
|
|
1248
|
+
requiresAuth: true,
|
|
1249
|
+
requiresPermission: ["workflows:write", "workflows:execute"],
|
|
1250
|
+
handler: (async ({ mastra, event, requestContext }) => {
|
|
1251
|
+
try {
|
|
1252
|
+
const workflowName = event.data?.workflowId;
|
|
1253
|
+
const existingRun = await (await mastra.getStorage()?.getStore("workflows"))?.getWorkflowRunById({
|
|
1254
|
+
runId: event.runId,
|
|
1255
|
+
...typeof workflowName === "string" ? { workflowName } : {}
|
|
1256
|
+
});
|
|
1257
|
+
await validateRunOwnership(existingRun, getEffectiveResourceId(requestContext, void 0), mastra);
|
|
1258
|
+
const rawCreatedAt = event.createdAt;
|
|
1259
|
+
const createdAt = rawCreatedAt instanceof Date ? rawCreatedAt : new Date(rawCreatedAt);
|
|
1260
|
+
if (Number.isNaN(createdAt.getTime())) throw new HTTPException(400, { message: "Invalid createdAt" });
|
|
1261
|
+
return await mastra.handleWorkflowEvent({
|
|
1262
|
+
...event,
|
|
1263
|
+
createdAt
|
|
1264
|
+
});
|
|
1265
|
+
} catch (error) {
|
|
1266
|
+
return handleError(error, "Error receiving workflow event");
|
|
1267
|
+
}
|
|
1268
|
+
})
|
|
1269
|
+
});
|
|
1270
|
+
//#endregion
|
|
1271
|
+
export { STREAM_LEGACY_WORKFLOW_ROUTE as C, TIME_TRAVEL_WORKFLOW_ROUTE as D, TIME_TRAVEL_STREAM_WORKFLOW_ROUTE as E, __setWorkflowRunCountsNow as O, START_WORKFLOW_RUN_ROUTE as S, TIME_TRAVEL_ASYNC_WORKFLOW_ROUTE as T, RESUME_ASYNC_WORKFLOW_ROUTE as _, GET_WORKFLOW_BY_ID_ROUTE as a, RESUME_WORKFLOW_ROUTE as b, LIST_WORKFLOW_RUNS_ROUTE as c, OBSERVE_STREAM_WORKFLOW_ROUTE as d, RECEIVE_WORKFLOW_EVENT_ROUTE as f, RESTART_WORKFLOW_ROUTE as g, RESTART_ASYNC_WORKFLOW_ROUTE as h, EXECUTE_WORKFLOW_STEP_ROUTE as i, workflows_exports as k, LIST_WORKFLOW_RUN_COUNTS_ROUTE as l, RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ROUTE as m, CREATE_WORKFLOW_RUN_ROUTE as n, GET_WORKFLOW_RUN_BY_ID_ROUTE as o, RESTART_ALL_ACTIVE_WORKFLOW_RUNS_ASYNC_ROUTE as p, DELETE_WORKFLOW_RUN_BY_ID_ROUTE as r, LIST_WORKFLOWS_ROUTE as s, CANCEL_WORKFLOW_RUN_ROUTE as t, OBSERVE_STREAM_LEGACY_WORKFLOW_ROUTE as u, RESUME_NO_WAIT_WORKFLOW_ROUTE as v, STREAM_WORKFLOW_ROUTE as w, START_ASYNC_WORKFLOW_ROUTE as x, RESUME_STREAM_WORKFLOW_ROUTE as y };
|
|
1272
|
+
|
|
1273
|
+
//# sourceMappingURL=workflows-bb-otd2o.js.map
|